4949#define DOVE_SD1_GPIO_SEL BIT(1)
5050#define DOVE_SD0_GPIO_SEL BIT(0)
5151
52- #define MPPS_PER_REG 8
53- #define MPP_BITS 4
54- #define MPP_MASK 0xf
55-
5652#define CONFIG_PMU BIT(4)
5753
58- static int dove_pmu_mpp_ctrl_get (struct mvebu_mpp_ctrl * ctrl ,
59- unsigned long * config )
54+ static void __iomem * mpp_base ;
55+
56+ static int dove_mpp_ctrl_get (unsigned pid , unsigned long * config )
57+ {
58+ return default_mpp_ctrl_get (mpp_base , pid , config );
59+ }
60+
61+ static int dove_mpp_ctrl_set (unsigned pid , unsigned long config )
62+ {
63+ return default_mpp_ctrl_set (mpp_base , pid , config );
64+ }
65+
66+ static int dove_pmu_mpp_ctrl_get (unsigned pid , unsigned long * config )
6067{
61- unsigned off = (ctrl -> pid / MPPS_PER_REG ) * MPP_BITS ;
62- unsigned shift = (ctrl -> pid % MPPS_PER_REG ) * MPP_BITS ;
68+ unsigned off = (pid / MVEBU_MPPS_PER_REG ) * MVEBU_MPP_BITS ;
69+ unsigned shift = (pid % MVEBU_MPPS_PER_REG ) * MVEBU_MPP_BITS ;
6370 unsigned long pmu = readl (DOVE_PMU_MPP_GENERAL_CTRL );
6471 unsigned long func ;
6572
66- if (pmu & (1 << ctrl -> pid )) {
67- func = readl (DOVE_PMU_SIGNAL_SELECT_0 + off );
68- * config = (func >> shift ) & MPP_MASK ;
69- * config |= CONFIG_PMU ;
70- } else {
71- func = readl (DOVE_MPP_VIRT_BASE + off );
72- * config = (func >> shift ) & MPP_MASK ;
73- }
73+ if ((pmu & BIT (pid )) == 0 )
74+ return default_mpp_ctrl_get (mpp_base , pid , config );
75+
76+ func = readl (DOVE_PMU_SIGNAL_SELECT_0 + off );
77+ * config = (func >> shift ) & MVEBU_MPP_MASK ;
78+ * config |= CONFIG_PMU ;
79+
7480 return 0 ;
7581}
7682
77- static int dove_pmu_mpp_ctrl_set (struct mvebu_mpp_ctrl * ctrl ,
78- unsigned long config )
83+ static int dove_pmu_mpp_ctrl_set (unsigned pid , unsigned long config )
7984{
80- unsigned off = (ctrl -> pid / MPPS_PER_REG ) * MPP_BITS ;
81- unsigned shift = (ctrl -> pid % MPPS_PER_REG ) * MPP_BITS ;
85+ unsigned off = (pid / MVEBU_MPPS_PER_REG ) * MVEBU_MPP_BITS ;
86+ unsigned shift = (pid % MVEBU_MPPS_PER_REG ) * MVEBU_MPP_BITS ;
8287 unsigned long pmu = readl (DOVE_PMU_MPP_GENERAL_CTRL );
8388 unsigned long func ;
8489
85- if (config & CONFIG_PMU ) {
86- writel (pmu | (1 << ctrl -> pid ), DOVE_PMU_MPP_GENERAL_CTRL );
87- func = readl (DOVE_PMU_SIGNAL_SELECT_0 + off );
88- func &= ~(MPP_MASK << shift );
89- func |= (config & MPP_MASK ) << shift ;
90- writel (func , DOVE_PMU_SIGNAL_SELECT_0 + off );
91- } else {
92- writel (pmu & ~(1 << ctrl -> pid ), DOVE_PMU_MPP_GENERAL_CTRL );
93- func = readl (DOVE_MPP_VIRT_BASE + off );
94- func &= ~(MPP_MASK << shift );
95- func |= (config & MPP_MASK ) << shift ;
96- writel (func , DOVE_MPP_VIRT_BASE + off );
90+ if ((config & CONFIG_PMU ) == 0 ) {
91+ writel (pmu & ~BIT (pid ), DOVE_PMU_MPP_GENERAL_CTRL );
92+ return default_mpp_ctrl_set (mpp_base , pid , config );
9793 }
94+
95+ writel (pmu | BIT (pid ), DOVE_PMU_MPP_GENERAL_CTRL );
96+ func = readl (DOVE_PMU_SIGNAL_SELECT_0 + off );
97+ func &= ~(MVEBU_MPP_MASK << shift );
98+ func |= (config & MVEBU_MPP_MASK ) << shift ;
99+ writel (func , DOVE_PMU_SIGNAL_SELECT_0 + off );
100+
98101 return 0 ;
99102}
100103
101- static int dove_mpp4_ctrl_get (struct mvebu_mpp_ctrl * ctrl ,
102- unsigned long * config )
104+ static int dove_mpp4_ctrl_get (unsigned pid , unsigned long * config )
103105{
104106 unsigned long mpp4 = readl (DOVE_MPP_CTRL4_VIRT_BASE );
105107 unsigned long mask ;
106108
107- switch (ctrl -> pid ) {
109+ switch (pid ) {
108110 case 24 : /* mpp_camera */
109111 mask = DOVE_CAM_GPIO_SEL ;
110112 break ;
@@ -129,13 +131,12 @@ static int dove_mpp4_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
129131 return 0 ;
130132}
131133
132- static int dove_mpp4_ctrl_set (struct mvebu_mpp_ctrl * ctrl ,
133- unsigned long config )
134+ static int dove_mpp4_ctrl_set (unsigned pid , unsigned long config )
134135{
135136 unsigned long mpp4 = readl (DOVE_MPP_CTRL4_VIRT_BASE );
136137 unsigned long mask ;
137138
138- switch (ctrl -> pid ) {
139+ switch (pid ) {
139140 case 24 : /* mpp_camera */
140141 mask = DOVE_CAM_GPIO_SEL ;
141142 break ;
@@ -164,8 +165,7 @@ static int dove_mpp4_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
164165 return 0 ;
165166}
166167
167- static int dove_nand_ctrl_get (struct mvebu_mpp_ctrl * ctrl ,
168- unsigned long * config )
168+ static int dove_nand_ctrl_get (unsigned pid , unsigned long * config )
169169{
170170 unsigned long gmpp = readl (DOVE_MPP_GENERAL_VIRT_BASE );
171171
@@ -174,8 +174,7 @@ static int dove_nand_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
174174 return 0 ;
175175}
176176
177- static int dove_nand_ctrl_set (struct mvebu_mpp_ctrl * ctrl ,
178- unsigned long config )
177+ static int dove_nand_ctrl_set (unsigned pid , unsigned long config )
179178{
180179 unsigned long gmpp = readl (DOVE_MPP_GENERAL_VIRT_BASE );
181180
@@ -188,8 +187,7 @@ static int dove_nand_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
188187 return 0 ;
189188}
190189
191- static int dove_audio0_ctrl_get (struct mvebu_mpp_ctrl * ctrl ,
192- unsigned long * config )
190+ static int dove_audio0_ctrl_get (unsigned pid , unsigned long * config )
193191{
194192 unsigned long pmu = readl (DOVE_PMU_MPP_GENERAL_CTRL );
195193
@@ -198,8 +196,7 @@ static int dove_audio0_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
198196 return 0 ;
199197}
200198
201- static int dove_audio0_ctrl_set (struct mvebu_mpp_ctrl * ctrl ,
202- unsigned long config )
199+ static int dove_audio0_ctrl_set (unsigned pid , unsigned long config )
203200{
204201 unsigned long pmu = readl (DOVE_PMU_MPP_GENERAL_CTRL );
205202
@@ -211,8 +208,7 @@ static int dove_audio0_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
211208 return 0 ;
212209}
213210
214- static int dove_audio1_ctrl_get (struct mvebu_mpp_ctrl * ctrl ,
215- unsigned long * config )
211+ static int dove_audio1_ctrl_get (unsigned pid , unsigned long * config )
216212{
217213 unsigned long mpp4 = readl (DOVE_MPP_CTRL4_VIRT_BASE );
218214 unsigned long sspc1 = readl (DOVE_SSP_CTRL_STATUS_1 );
@@ -238,8 +234,7 @@ static int dove_audio1_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
238234 return 0 ;
239235}
240236
241- static int dove_audio1_ctrl_set (struct mvebu_mpp_ctrl * ctrl ,
242- unsigned long config )
237+ static int dove_audio1_ctrl_set (unsigned pid , unsigned long config )
243238{
244239 unsigned long mpp4 = readl (DOVE_MPP_CTRL4_VIRT_BASE );
245240 unsigned long sspc1 = readl (DOVE_SSP_CTRL_STATUS_1 );
@@ -276,11 +271,11 @@ static int dove_audio1_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
276271 * break other functions. If you require all mpps as gpio
277272 * enforce gpio setting by pinctrl mapping.
278273 */
279- static int dove_audio1_ctrl_gpio_req (struct mvebu_mpp_ctrl * ctrl , u8 pid )
274+ static int dove_audio1_ctrl_gpio_req (unsigned pid )
280275{
281276 unsigned long config ;
282277
283- dove_audio1_ctrl_get (ctrl , & config );
278+ dove_audio1_ctrl_get (pid , & config );
284279
285280 switch (config ) {
286281 case 0x02 : /* i2s1 : gpio[56:57] */
@@ -303,16 +298,14 @@ static int dove_audio1_ctrl_gpio_req(struct mvebu_mpp_ctrl *ctrl, u8 pid)
303298}
304299
305300/* mpp[52:57] has gpio pins capable of in and out */
306- static int dove_audio1_ctrl_gpio_dir (struct mvebu_mpp_ctrl * ctrl , u8 pid ,
307- bool input )
301+ static int dove_audio1_ctrl_gpio_dir (unsigned pid , bool input )
308302{
309303 if (pid < 52 || pid > 57 )
310304 return - ENOTSUPP ;
311305 return 0 ;
312306}
313307
314- static int dove_twsi_ctrl_get (struct mvebu_mpp_ctrl * ctrl ,
315- unsigned long * config )
308+ static int dove_twsi_ctrl_get (unsigned pid , unsigned long * config )
316309{
317310 unsigned long gcfg1 = readl (DOVE_GLOBAL_CONFIG_1 );
318311 unsigned long gcfg2 = readl (DOVE_GLOBAL_CONFIG_2 );
@@ -328,8 +321,7 @@ static int dove_twsi_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
328321 return 0 ;
329322}
330323
331- static int dove_twsi_ctrl_set (struct mvebu_mpp_ctrl * ctrl ,
332- unsigned long config )
324+ static int dove_twsi_ctrl_set (unsigned pid , unsigned long config )
333325{
334326 unsigned long gcfg1 = readl (DOVE_GLOBAL_CONFIG_1 );
335327 unsigned long gcfg2 = readl (DOVE_GLOBAL_CONFIG_2 );
@@ -356,23 +348,8 @@ static int dove_twsi_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
356348}
357349
358350static struct mvebu_mpp_ctrl dove_mpp_controls [] = {
359- MPP_FUNC_CTRL (0 , 0 , "mpp0" , dove_pmu_mpp_ctrl ),
360- MPP_FUNC_CTRL (1 , 1 , "mpp1" , dove_pmu_mpp_ctrl ),
361- MPP_FUNC_CTRL (2 , 2 , "mpp2" , dove_pmu_mpp_ctrl ),
362- MPP_FUNC_CTRL (3 , 3 , "mpp3" , dove_pmu_mpp_ctrl ),
363- MPP_FUNC_CTRL (4 , 4 , "mpp4" , dove_pmu_mpp_ctrl ),
364- MPP_FUNC_CTRL (5 , 5 , "mpp5" , dove_pmu_mpp_ctrl ),
365- MPP_FUNC_CTRL (6 , 6 , "mpp6" , dove_pmu_mpp_ctrl ),
366- MPP_FUNC_CTRL (7 , 7 , "mpp7" , dove_pmu_mpp_ctrl ),
367- MPP_FUNC_CTRL (8 , 8 , "mpp8" , dove_pmu_mpp_ctrl ),
368- MPP_FUNC_CTRL (9 , 9 , "mpp9" , dove_pmu_mpp_ctrl ),
369- MPP_FUNC_CTRL (10 , 10 , "mpp10" , dove_pmu_mpp_ctrl ),
370- MPP_FUNC_CTRL (11 , 11 , "mpp11" , dove_pmu_mpp_ctrl ),
371- MPP_FUNC_CTRL (12 , 12 , "mpp12" , dove_pmu_mpp_ctrl ),
372- MPP_FUNC_CTRL (13 , 13 , "mpp13" , dove_pmu_mpp_ctrl ),
373- MPP_FUNC_CTRL (14 , 14 , "mpp14" , dove_pmu_mpp_ctrl ),
374- MPP_FUNC_CTRL (15 , 15 , "mpp15" , dove_pmu_mpp_ctrl ),
375- MPP_REG_CTRL (16 , 23 ),
351+ MPP_FUNC_CTRL (0 , 15 , NULL , dove_pmu_mpp_ctrl ),
352+ MPP_FUNC_CTRL (16 , 23 , NULL , dove_mpp_ctrl ),
376353 MPP_FUNC_CTRL (24 , 39 , "mpp_camera" , dove_mpp4_ctrl ),
377354 MPP_FUNC_CTRL (40 , 45 , "mpp_sdio0" , dove_mpp4_ctrl ),
378355 MPP_FUNC_CTRL (46 , 51 , "mpp_sdio1" , dove_mpp4_ctrl ),
@@ -774,6 +751,7 @@ static struct of_device_id dove_pinctrl_of_match[] = {
774751
775752static int dove_pinctrl_probe (struct platform_device * pdev )
776753{
754+ struct resource * res ;
777755 const struct of_device_id * match =
778756 of_match_device (dove_pinctrl_of_match , & pdev -> dev );
779757 pdev -> dev .platform_data = (void * )match -> data ;
@@ -789,6 +767,11 @@ static int dove_pinctrl_probe(struct platform_device *pdev)
789767 }
790768 clk_prepare_enable (clk );
791769
770+ res = platform_get_resource (pdev , IORESOURCE_MEM , 0 );
771+ mpp_base = devm_ioremap_resource (& pdev -> dev , res );
772+ if (IS_ERR (mpp_base ))
773+ return PTR_ERR (mpp_base );
774+
792775 return mvebu_pinctrl_probe (pdev );
793776}
794777
0 commit comments