2121#include <linux/ioport.h>
2222#include <linux/pinctrl/machine.h>
2323
24- static struct sh_pfc * sh_pfc __read_mostly ;
25-
26- static inline bool sh_pfc_initialized (void )
27- {
28- return !!sh_pfc ;
29- }
24+ static struct sh_pfc sh_pfc __read_mostly ;
3025
3126static void pfc_iounmap (struct sh_pfc * pfc )
3227{
3328 int k ;
3429
35- for (k = 0 ; k < pfc -> num_resources ; k ++ )
30+ for (k = 0 ; k < pfc -> pdata -> num_resources ; k ++ )
3631 if (pfc -> window [k ].virt )
3732 iounmap (pfc -> window [k ].virt );
3833
@@ -45,16 +40,16 @@ static int pfc_ioremap(struct sh_pfc *pfc)
4540 struct resource * res ;
4641 int k ;
4742
48- if (!pfc -> num_resources )
43+ if (!pfc -> pdata -> num_resources )
4944 return 0 ;
5045
51- pfc -> window = kzalloc (pfc -> num_resources * sizeof (* pfc -> window ),
46+ pfc -> window = kzalloc (pfc -> pdata -> num_resources * sizeof (* pfc -> window ),
5247 GFP_NOWAIT );
5348 if (!pfc -> window )
5449 goto err1 ;
5550
56- for (k = 0 ; k < pfc -> num_resources ; k ++ ) {
57- res = pfc -> resource + k ;
51+ for (k = 0 ; k < pfc -> pdata -> num_resources ; k ++ ) {
52+ res = pfc -> pdata -> resource + k ;
5853 WARN_ON (resource_type (res ) != IORESOURCE_MEM );
5954 pfc -> window [k ].phys = res -> start ;
6055 pfc -> window [k ].size = resource_size (res );
@@ -79,7 +74,7 @@ static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc,
7974 int k ;
8075
8176 /* scan through physical windows and convert address */
82- for (k = 0 ; k < pfc -> num_resources ; k ++ ) {
77+ for (k = 0 ; k < pfc -> pdata -> num_resources ; k ++ ) {
8378 window = pfc -> window + k ;
8479
8580 if (address < window -> phys )
@@ -232,25 +227,25 @@ static void write_config_reg(struct sh_pfc *pfc,
232227 data &= mask ;
233228 data |= value ;
234229
235- if (pfc -> unlock_reg )
236- gpio_write_raw_reg (pfc_phys_to_virt (pfc , pfc -> unlock_reg ),
230+ if (pfc -> pdata -> unlock_reg )
231+ gpio_write_raw_reg (pfc_phys_to_virt (pfc , pfc -> pdata -> unlock_reg ),
237232 32 , ~data );
238233
239234 gpio_write_raw_reg (mapped_reg , crp -> reg_width , data );
240235}
241236
242237static int setup_data_reg (struct sh_pfc * pfc , unsigned gpio )
243238{
244- struct pinmux_gpio * gpiop = & pfc -> gpios [gpio ];
239+ struct pinmux_gpio * gpiop = & pfc -> pdata -> gpios [gpio ];
245240 struct pinmux_data_reg * data_reg ;
246241 int k , n ;
247242
248- if (!enum_in_range (gpiop -> enum_id , & pfc -> data ))
243+ if (!enum_in_range (gpiop -> enum_id , & pfc -> pdata -> data ))
249244 return -1 ;
250245
251246 k = 0 ;
252247 while (1 ) {
253- data_reg = pfc -> data_regs + k ;
248+ data_reg = pfc -> pdata -> data_regs + k ;
254249
255250 if (!data_reg -> reg_width )
256251 break ;
@@ -279,12 +274,12 @@ static void setup_data_regs(struct sh_pfc *pfc)
279274 struct pinmux_data_reg * drp ;
280275 int k ;
281276
282- for (k = pfc -> first_gpio ; k <= pfc -> last_gpio ; k ++ )
277+ for (k = pfc -> pdata -> first_gpio ; k <= pfc -> pdata -> last_gpio ; k ++ )
283278 setup_data_reg (pfc , k );
284279
285280 k = 0 ;
286281 while (1 ) {
287- drp = pfc -> data_regs + k ;
282+ drp = pfc -> pdata -> data_regs + k ;
288283
289284 if (!drp -> reg_width )
290285 break ;
@@ -298,15 +293,15 @@ static void setup_data_regs(struct sh_pfc *pfc)
298293int sh_pfc_get_data_reg (struct sh_pfc * pfc , unsigned gpio ,
299294 struct pinmux_data_reg * * drp , int * bitp )
300295{
301- struct pinmux_gpio * gpiop = & pfc -> gpios [gpio ];
296+ struct pinmux_gpio * gpiop = & pfc -> pdata -> gpios [gpio ];
302297 int k , n ;
303298
304- if (!enum_in_range (gpiop -> enum_id , & pfc -> data ))
299+ if (!enum_in_range (gpiop -> enum_id , & pfc -> pdata -> data ))
305300 return -1 ;
306301
307302 k = (gpiop -> flags & PINMUX_FLAG_DREG ) >> PINMUX_FLAG_DREG_SHIFT ;
308303 n = (gpiop -> flags & PINMUX_FLAG_DBIT ) >> PINMUX_FLAG_DBIT_SHIFT ;
309- * drp = pfc -> data_regs + k ;
304+ * drp = pfc -> pdata -> data_regs + k ;
310305 * bitp = n ;
311306 return 0 ;
312307}
@@ -323,7 +318,7 @@ static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
323318
324319 k = 0 ;
325320 while (1 ) {
326- config_reg = pfc -> cfg_regs + k ;
321+ config_reg = pfc -> pdata -> cfg_regs + k ;
327322
328323 r_width = config_reg -> reg_width ;
329324 f_width = config_reg -> field_width ;
@@ -361,12 +356,12 @@ static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
361356int sh_pfc_gpio_to_enum (struct sh_pfc * pfc , unsigned gpio , int pos ,
362357 pinmux_enum_t * enum_idp )
363358{
364- pinmux_enum_t enum_id = pfc -> gpios [gpio ].enum_id ;
365- pinmux_enum_t * data = pfc -> gpio_data ;
359+ pinmux_enum_t enum_id = pfc -> pdata -> gpios [gpio ].enum_id ;
360+ pinmux_enum_t * data = pfc -> pdata -> gpio_data ;
366361 int k ;
367362
368- if (!enum_in_range (enum_id , & pfc -> data )) {
369- if (!enum_in_range (enum_id , & pfc -> mark )) {
363+ if (!enum_in_range (enum_id , & pfc -> pdata -> data )) {
364+ if (!enum_in_range (enum_id , & pfc -> pdata -> mark )) {
370365 pr_err ("non data/mark enum_id for gpio %d\n" , gpio );
371366 return -1 ;
372367 }
@@ -377,7 +372,7 @@ int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos,
377372 return pos + 1 ;
378373 }
379374
380- for (k = 0 ; k < pfc -> gpio_data_size ; k ++ ) {
375+ for (k = 0 ; k < pfc -> pdata -> gpio_data_size ; k ++ ) {
381376 if (data [k ] == enum_id ) {
382377 * enum_idp = data [k + 1 ];
383378 return k + 1 ;
@@ -405,19 +400,19 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
405400 break ;
406401
407402 case PINMUX_TYPE_OUTPUT :
408- range = & pfc -> output ;
403+ range = & pfc -> pdata -> output ;
409404 break ;
410405
411406 case PINMUX_TYPE_INPUT :
412- range = & pfc -> input ;
407+ range = & pfc -> pdata -> input ;
413408 break ;
414409
415410 case PINMUX_TYPE_INPUT_PULLUP :
416- range = & pfc -> input_pu ;
411+ range = & pfc -> pdata -> input_pu ;
417412 break ;
418413
419414 case PINMUX_TYPE_INPUT_PULLDOWN :
420- range = & pfc -> input_pd ;
415+ range = & pfc -> pdata -> input_pd ;
421416 break ;
422417
423418 default :
@@ -437,7 +432,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
437432 break ;
438433
439434 /* first check if this is a function enum */
440- in_range = enum_in_range (enum_id , & pfc -> function );
435+ in_range = enum_in_range (enum_id , & pfc -> pdata -> function );
441436 if (!in_range ) {
442437 /* not a function enum */
443438 if (range ) {
@@ -502,7 +497,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
502497}
503498EXPORT_SYMBOL_GPL (sh_pfc_config_gpio );
504499
505- int register_sh_pfc (struct sh_pfc * pfc )
500+ int register_sh_pfc (struct sh_pfc_platform_data * pdata )
506501{
507502 int (* initroutine )(struct sh_pfc * ) = NULL ;
508503 int ret ;
@@ -512,26 +507,28 @@ int register_sh_pfc(struct sh_pfc *pfc)
512507 */
513508 BUILD_BUG_ON (PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT ) - 1 ));
514509
515- if (sh_pfc )
510+ if (sh_pfc . pdata )
516511 return - EBUSY ;
517512
518- ret = pfc_ioremap (pfc );
519- if (unlikely (ret < 0 ))
513+ sh_pfc .pdata = pdata ;
514+
515+ ret = pfc_ioremap (& sh_pfc );
516+ if (unlikely (ret < 0 )) {
517+ sh_pfc .pdata = NULL ;
520518 return ret ;
519+ }
521520
522- spin_lock_init (& pfc -> lock );
521+ spin_lock_init (& sh_pfc . lock );
523522
524523 pinctrl_provide_dummies ();
525- setup_data_regs (pfc );
526-
527- sh_pfc = pfc ;
524+ setup_data_regs (& sh_pfc );
528525
529526 /*
530527 * Initialize pinctrl bindings first
531528 */
532529 initroutine = symbol_request (sh_pfc_register_pinctrl );
533530 if (initroutine ) {
534- ret = (* initroutine )(pfc );
531+ ret = (* initroutine )(& sh_pfc );
535532 symbol_put_addr (initroutine );
536533
537534 if (unlikely (ret != 0 ))
@@ -546,7 +543,7 @@ int register_sh_pfc(struct sh_pfc *pfc)
546543 */
547544 initroutine = symbol_request (sh_pfc_register_gpiochip );
548545 if (initroutine ) {
549- ret = (* initroutine )(pfc );
546+ ret = (* initroutine )(& sh_pfc );
550547 symbol_put_addr (initroutine );
551548
552549 /*
@@ -560,13 +557,13 @@ int register_sh_pfc(struct sh_pfc *pfc)
560557 }
561558 }
562559
563- pr_info ("%s support registered\n" , pfc -> name );
560+ pr_info ("%s support registered\n" , sh_pfc . pdata -> name );
564561
565562 return 0 ;
566563
567564err :
568- pfc_iounmap (pfc );
569- sh_pfc = NULL ;
565+ pfc_iounmap (& sh_pfc );
566+ sh_pfc . pdata = NULL ;
570567
571568 return ret ;
572569}
0 commit comments