24
24
#include <linux/of_device.h>
25
25
#include <linux/bug.h>
26
26
27
- enum mxc_gpio_hwtype {
28
- IMX1_GPIO , /* runs on i.mx1 */
29
- IMX21_GPIO , /* runs on i.mx21 and i.mx27 */
30
- IMX31_GPIO , /* runs on i.mx31 */
31
- IMX35_GPIO , /* runs on all other i.mx */
32
- };
33
-
34
27
/* device type dependent stuff */
35
28
struct mxc_gpio_hwdata {
36
29
unsigned dr_reg ;
@@ -68,6 +61,7 @@ struct mxc_gpio_port {
68
61
u32 both_edges ;
69
62
struct mxc_gpio_reg_saved gpio_saved_reg ;
70
63
bool power_off ;
64
+ const struct mxc_gpio_hwdata * hwdata ;
71
65
};
72
66
73
67
static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = {
@@ -115,48 +109,27 @@ static struct mxc_gpio_hwdata imx35_gpio_hwdata = {
115
109
.fall_edge = 0x03 ,
116
110
};
117
111
118
- static enum mxc_gpio_hwtype mxc_gpio_hwtype ;
119
- static struct mxc_gpio_hwdata * mxc_gpio_hwdata ;
120
-
121
- #define GPIO_DR (mxc_gpio_hwdata->dr_reg)
122
- #define GPIO_GDIR (mxc_gpio_hwdata->gdir_reg)
123
- #define GPIO_PSR (mxc_gpio_hwdata->psr_reg)
124
- #define GPIO_ICR1 (mxc_gpio_hwdata->icr1_reg)
125
- #define GPIO_ICR2 (mxc_gpio_hwdata->icr2_reg)
126
- #define GPIO_IMR (mxc_gpio_hwdata->imr_reg)
127
- #define GPIO_ISR (mxc_gpio_hwdata->isr_reg)
128
- #define GPIO_EDGE_SEL (mxc_gpio_hwdata->edge_sel_reg)
129
-
130
- #define GPIO_INT_LOW_LEV (mxc_gpio_hwdata->low_level)
131
- #define GPIO_INT_HIGH_LEV (mxc_gpio_hwdata->high_level)
132
- #define GPIO_INT_RISE_EDGE (mxc_gpio_hwdata->rise_edge)
133
- #define GPIO_INT_FALL_EDGE (mxc_gpio_hwdata->fall_edge)
112
+ #define GPIO_DR (port->hwdata->dr_reg)
113
+ #define GPIO_GDIR (port->hwdata->gdir_reg)
114
+ #define GPIO_PSR (port->hwdata->psr_reg)
115
+ #define GPIO_ICR1 (port->hwdata->icr1_reg)
116
+ #define GPIO_ICR2 (port->hwdata->icr2_reg)
117
+ #define GPIO_IMR (port->hwdata->imr_reg)
118
+ #define GPIO_ISR (port->hwdata->isr_reg)
119
+ #define GPIO_EDGE_SEL (port->hwdata->edge_sel_reg)
120
+
121
+ #define GPIO_INT_LOW_LEV (port->hwdata->low_level)
122
+ #define GPIO_INT_HIGH_LEV (port->hwdata->high_level)
123
+ #define GPIO_INT_RISE_EDGE (port->hwdata->rise_edge)
124
+ #define GPIO_INT_FALL_EDGE (port->hwdata->fall_edge)
134
125
#define GPIO_INT_BOTH_EDGES 0x4
135
126
136
- static const struct platform_device_id mxc_gpio_devtype [] = {
137
- {
138
- .name = "imx1-gpio" ,
139
- .driver_data = IMX1_GPIO ,
140
- }, {
141
- .name = "imx21-gpio" ,
142
- .driver_data = IMX21_GPIO ,
143
- }, {
144
- .name = "imx31-gpio" ,
145
- .driver_data = IMX31_GPIO ,
146
- }, {
147
- .name = "imx35-gpio" ,
148
- .driver_data = IMX35_GPIO ,
149
- }, {
150
- /* sentinel */
151
- }
152
- };
153
-
154
127
static const struct of_device_id mxc_gpio_dt_ids [] = {
155
- { .compatible = "fsl,imx1-gpio" , .data = & mxc_gpio_devtype [ IMX1_GPIO ], },
156
- { .compatible = "fsl,imx21-gpio" , .data = & mxc_gpio_devtype [ IMX21_GPIO ], },
157
- { .compatible = "fsl,imx31-gpio" , .data = & mxc_gpio_devtype [ IMX31_GPIO ], },
158
- { .compatible = "fsl,imx35-gpio" , .data = & mxc_gpio_devtype [ IMX35_GPIO ], },
159
- { .compatible = "fsl,imx7d-gpio" , .data = & mxc_gpio_devtype [ IMX35_GPIO ], },
128
+ { .compatible = "fsl,imx1-gpio" , .data = & imx1_imx21_gpio_hwdata },
129
+ { .compatible = "fsl,imx21-gpio" , .data = & imx1_imx21_gpio_hwdata },
130
+ { .compatible = "fsl,imx31-gpio" , .data = & imx31_gpio_hwdata },
131
+ { .compatible = "fsl,imx35-gpio" , .data = & imx35_gpio_hwdata },
132
+ { .compatible = "fsl,imx7d-gpio" , .data = & imx35_gpio_hwdata },
160
133
{ /* sentinel */ }
161
134
};
162
135
MODULE_DEVICE_TABLE (of , mxc_gpio_dt_ids );
@@ -372,36 +345,6 @@ static int mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base)
372
345
return rv ;
373
346
}
374
347
375
- static void mxc_gpio_get_hw (struct platform_device * pdev )
376
- {
377
- const struct of_device_id * of_id =
378
- of_match_device (mxc_gpio_dt_ids , & pdev -> dev );
379
- enum mxc_gpio_hwtype hwtype ;
380
-
381
- if (of_id )
382
- pdev -> id_entry = of_id -> data ;
383
- hwtype = pdev -> id_entry -> driver_data ;
384
-
385
- if (mxc_gpio_hwtype ) {
386
- /*
387
- * The driver works with a reasonable presupposition,
388
- * that is all gpio ports must be the same type when
389
- * running on one soc.
390
- */
391
- BUG_ON (mxc_gpio_hwtype != hwtype );
392
- return ;
393
- }
394
-
395
- if (hwtype == IMX35_GPIO )
396
- mxc_gpio_hwdata = & imx35_gpio_hwdata ;
397
- else if (hwtype == IMX31_GPIO )
398
- mxc_gpio_hwdata = & imx31_gpio_hwdata ;
399
- else
400
- mxc_gpio_hwdata = & imx1_imx21_gpio_hwdata ;
401
-
402
- mxc_gpio_hwtype = hwtype ;
403
- }
404
-
405
348
static int mxc_gpio_to_irq (struct gpio_chip * gc , unsigned offset )
406
349
{
407
350
struct mxc_gpio_port * port = gpiochip_get_data (gc );
@@ -417,14 +360,14 @@ static int mxc_gpio_probe(struct platform_device *pdev)
417
360
int irq_base ;
418
361
int err ;
419
362
420
- mxc_gpio_get_hw (pdev );
421
-
422
363
port = devm_kzalloc (& pdev -> dev , sizeof (* port ), GFP_KERNEL );
423
364
if (!port )
424
365
return - ENOMEM ;
425
366
426
367
port -> dev = & pdev -> dev ;
427
368
369
+ port -> hwdata = device_get_match_data (& pdev -> dev );
370
+
428
371
port -> base = devm_platform_ioremap_resource (pdev , 0 );
429
372
if (IS_ERR (port -> base ))
430
373
return PTR_ERR (port -> base );
@@ -461,7 +404,7 @@ static int mxc_gpio_probe(struct platform_device *pdev)
461
404
writel (0 , port -> base + GPIO_IMR );
462
405
writel (~0 , port -> base + GPIO_ISR );
463
406
464
- if (mxc_gpio_hwtype == IMX21_GPIO ) {
407
+ if (of_device_is_compatible ( np , "fsl,imx21-gpio" ) ) {
465
408
/*
466
409
* Setup one handler for all GPIO interrupts. Actually setting
467
410
* the handler is needed only once, but doing it for every port
@@ -596,7 +539,6 @@ static struct platform_driver mxc_gpio_driver = {
596
539
.suppress_bind_attrs = true,
597
540
},
598
541
.probe = mxc_gpio_probe ,
599
- .id_table = mxc_gpio_devtype ,
600
542
};
601
543
602
544
static int __init gpio_mxc_init (void )
0 commit comments