@@ -39,10 +39,6 @@ static ulong mask = GPIO_DEFAULT_MASK;
3939module_param_named (mask , mask , ulong , 0444 );
4040MODULE_PARM_DESC (mask , "GPIO channel mask." );
4141
42- /*
43- * FIXME: convert this singleton driver to use the state container
44- * design pattern, see Documentation/driver-api/driver-model/design-patterns.rst
45- */
4642static struct cs5535_gpio_chip {
4743 struct gpio_chip chip ;
4844 resource_size_t base ;
@@ -285,30 +281,29 @@ static const char * const cs5535_gpio_names[] = {
285281 "GPIO28" , NULL , NULL , NULL ,
286282};
287283
288- static struct cs5535_gpio_chip cs5535_gpio_chip = {
289- .chip = {
290- .owner = THIS_MODULE ,
291- .label = DRV_NAME ,
292-
293- .base = 0 ,
294- .ngpio = 32 ,
295- .names = cs5535_gpio_names ,
296- .request = chip_gpio_request ,
297-
298- .get = chip_gpio_get ,
299- .set = chip_gpio_set ,
300-
301- .direction_input = chip_direction_input ,
302- .direction_output = chip_direction_output ,
303- },
304- };
305-
306284static int cs5535_gpio_probe (struct platform_device * pdev )
307285{
286+ struct cs5535_gpio_chip * priv ;
287+ struct gpio_chip * gc ;
308288 struct resource * res ;
309289 int err = - EIO ;
310290 ulong mask_orig = mask ;
311291
292+ priv = devm_kzalloc (& pdev -> dev , sizeof (* priv ), GFP_KERNEL );
293+ if (!priv )
294+ return - ENOMEM ;
295+
296+ gc = & priv -> chip ;
297+ gc -> owner = THIS_MODULE ;
298+ gc -> label = DRV_NAME ;
299+ gc -> ngpio = 32 ;
300+ gc -> names = cs5535_gpio_names ;
301+ gc -> request = chip_gpio_request ;
302+ gc -> get = chip_gpio_get ;
303+ gc -> set = chip_gpio_set ;
304+ gc -> direction_input = chip_direction_input ;
305+ gc -> direction_output = chip_direction_output ;
306+
312307 /* There are two ways to get the GPIO base address; one is by
313308 * fetching it from MSR_LBAR_GPIO, the other is by reading the
314309 * PCI BAR info. The latter method is easier (especially across
@@ -329,9 +324,9 @@ static int cs5535_gpio_probe(struct platform_device *pdev)
329324 }
330325
331326 /* set up the driver-specific struct */
332- cs5535_gpio_chip . base = res -> start ;
333- cs5535_gpio_chip . pdev = pdev ;
334- spin_lock_init (& cs5535_gpio_chip . lock );
327+ priv -> base = res -> start ;
328+ priv -> pdev = pdev ;
329+ spin_lock_init (& priv -> lock );
335330
336331 dev_info (& pdev -> dev , "reserved resource region %pR\n" , res );
337332
@@ -347,8 +342,7 @@ static int cs5535_gpio_probe(struct platform_device *pdev)
347342 mask_orig , mask );
348343
349344 /* finally, register with the generic GPIO API */
350- return devm_gpiochip_add_data (& pdev -> dev , & cs5535_gpio_chip .chip ,
351- & cs5535_gpio_chip );
345+ return devm_gpiochip_add_data (& pdev -> dev , gc , priv );
352346}
353347
354348static struct platform_driver cs5535_gpio_driver = {
0 commit comments