@@ -312,17 +312,13 @@ static struct irq_chip mpc8xxx_irq_chip = {
312
312
.irq_unmask = mpc8xxx_irq_unmask ,
313
313
.irq_mask = mpc8xxx_irq_mask ,
314
314
.irq_ack = mpc8xxx_irq_ack ,
315
+ /* this might get overwritten in mpc8xxx_probe() */
315
316
.irq_set_type = mpc8xxx_irq_set_type ,
316
317
};
317
318
318
319
static int mpc8xxx_gpio_irq_map (struct irq_domain * h , unsigned int irq ,
319
320
irq_hw_number_t hwirq )
320
321
{
321
- struct mpc8xxx_gpio_chip * mpc8xxx_gc = h -> host_data ;
322
-
323
- if (mpc8xxx_gc -> of_dev_id_data )
324
- mpc8xxx_irq_chip .irq_set_type = mpc8xxx_gc -> of_dev_id_data ;
325
-
326
322
irq_set_chip_data (irq , h -> host_data );
327
323
irq_set_chip_and_handler (irq , & mpc8xxx_irq_chip , handle_level_irq );
328
324
@@ -334,11 +330,32 @@ static const struct irq_domain_ops mpc8xxx_gpio_irq_ops = {
334
330
.xlate = irq_domain_xlate_twocell ,
335
331
};
336
332
333
+ struct mpc8xxx_gpio_devtype {
334
+ int (* gpio_dir_out )(struct gpio_chip * , unsigned int , int );
335
+ int (* gpio_get )(struct gpio_chip * , unsigned int );
336
+ int (* irq_set_type )(struct irq_data * , unsigned int );
337
+ };
338
+
339
+ static const struct mpc8xxx_gpio_devtype mpc512x_gpio_devtype = {
340
+ .gpio_dir_out = mpc5121_gpio_dir_out ,
341
+ .irq_set_type = mpc512x_irq_set_type ,
342
+ };
343
+
344
+ static const struct mpc8xxx_gpio_devtype mpc8572_gpio_devtype = {
345
+ .gpio_get = mpc8572_gpio_get ,
346
+ };
347
+
348
+ static const struct mpc8xxx_gpio_devtype mpc8xxx_gpio_devtype_default = {
349
+ .gpio_dir_out = mpc8xxx_gpio_dir_out ,
350
+ .gpio_get = mpc8xxx_gpio_get ,
351
+ .irq_set_type = mpc8xxx_irq_set_type ,
352
+ };
353
+
337
354
static const struct of_device_id mpc8xxx_gpio_ids [] = {
338
355
{ .compatible = "fsl,mpc8349-gpio" , },
339
- { .compatible = "fsl,mpc8572-gpio" , },
356
+ { .compatible = "fsl,mpc8572-gpio" , . data = & mpc8572_gpio_devtype , },
340
357
{ .compatible = "fsl,mpc8610-gpio" , },
341
- { .compatible = "fsl,mpc5121-gpio" , .data = mpc512x_irq_set_type , },
358
+ { .compatible = "fsl,mpc5121-gpio" , .data = & mpc512x_gpio_devtype , },
342
359
{ .compatible = "fsl,pq3-gpio" , },
343
360
{ .compatible = "fsl,qoriq-gpio" , },
344
361
{}
@@ -351,6 +368,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)
351
368
struct of_mm_gpio_chip * mm_gc ;
352
369
struct gpio_chip * gc ;
353
370
const struct of_device_id * id ;
371
+ const struct mpc8xxx_gpio_devtype * devtype =
372
+ of_device_get_match_data (& pdev -> dev );
354
373
int ret ;
355
374
356
375
mpc8xxx_gc = devm_kzalloc (& pdev -> dev , sizeof (* mpc8xxx_gc ), GFP_KERNEL );
@@ -367,10 +386,18 @@ static int mpc8xxx_probe(struct platform_device *pdev)
367
386
mm_gc -> save_regs = mpc8xxx_gpio_save_regs ;
368
387
gc -> ngpio = MPC8XXX_GPIO_PINS ;
369
388
gc -> direction_input = mpc8xxx_gpio_dir_in ;
370
- gc -> direction_output = of_device_is_compatible (np , "fsl,mpc5121-gpio" ) ?
371
- mpc5121_gpio_dir_out : mpc8xxx_gpio_dir_out ;
372
- gc -> get = of_device_is_compatible (np , "fsl,mpc8572-gpio" ) ?
373
- mpc8572_gpio_get : mpc8xxx_gpio_get ;
389
+
390
+ if (!devtype )
391
+ devtype = & mpc8xxx_gpio_devtype_default ;
392
+
393
+ /*
394
+ * It's assumed that only a single type of gpio controller is available
395
+ * on the current machine, so overwriting global data is fine.
396
+ */
397
+ mpc8xxx_irq_chip .irq_set_type = devtype -> irq_set_type ;
398
+
399
+ gc -> direction_output = devtype -> gpio_dir_out ?: mpc8xxx_gpio_dir_out ;
400
+ gc -> get = devtype -> gpio_get ?: mpc8xxx_gpio_get ;
374
401
gc -> set = mpc8xxx_gpio_set ;
375
402
gc -> set_multiple = mpc8xxx_gpio_set_multiple ;
376
403
gc -> to_irq = mpc8xxx_gpio_to_irq ;
0 commit comments