diff options
author | Roger Quadros <rogerq@ti.com> | 2014-11-07 09:49:16 -0500 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2014-11-17 06:19:26 -0500 |
commit | 15151090579cab7c49d8af54a52f798ce8bda001 (patch) | |
tree | c3462e0d0f8bcd88c9c8580894e24fff4ae5fc55 | |
parent | e7e26bc75ba58ab85f329787cb072cf67dd5407f (diff) |
can: c_can: Introduce c_can_driver_data structure
We want to have more data than just can_dev_id to be present
in the driver data e.g. TI platforms need RAMINIT register
description. Introduce the c_can_driver_data structure and move
the can_dev_id into it.
Tidy up the way it is used on probe().
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | drivers/net/can/c_can/c_can.h | 4 | ||||
-rw-r--r-- | drivers/net/can/c_can/c_can_platform.c | 52 |
2 files changed, 33 insertions, 23 deletions
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h index 99ad1aa576b0..26c975d914e3 100644 --- a/drivers/net/can/c_can/c_can.h +++ b/drivers/net/can/c_can/c_can.h | |||
@@ -169,6 +169,10 @@ enum c_can_dev_id { | |||
169 | BOSCH_D_CAN, | 169 | BOSCH_D_CAN, |
170 | }; | 170 | }; |
171 | 171 | ||
172 | struct c_can_driver_data { | ||
173 | enum c_can_dev_id id; | ||
174 | }; | ||
175 | |||
172 | /* c_can private data structure */ | 176 | /* c_can private data structure */ |
173 | struct c_can_priv { | 177 | struct c_can_priv { |
174 | struct can_priv can; /* must be the first member */ | 178 | struct can_priv can; /* must be the first member */ |
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c index 106c203fc5eb..44c293926f78 100644 --- a/drivers/net/can/c_can/c_can_platform.c +++ b/drivers/net/can/c_can/c_can_platform.c | |||
@@ -168,26 +168,34 @@ static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable) | |||
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
171 | static const struct c_can_driver_data c_can_drvdata = { | ||
172 | .id = BOSCH_C_CAN, | ||
173 | }; | ||
174 | |||
175 | static const struct c_can_driver_data d_can_drvdata = { | ||
176 | .id = BOSCH_D_CAN, | ||
177 | }; | ||
178 | |||
171 | static struct platform_device_id c_can_id_table[] = { | 179 | static struct platform_device_id c_can_id_table[] = { |
172 | [BOSCH_C_CAN_PLATFORM] = { | 180 | { |
173 | .name = KBUILD_MODNAME, | 181 | .name = KBUILD_MODNAME, |
174 | .driver_data = BOSCH_C_CAN, | 182 | .driver_data = (kernel_ulong_t)&c_can_drvdata, |
175 | }, | 183 | }, |
176 | [BOSCH_C_CAN] = { | 184 | { |
177 | .name = "c_can", | 185 | .name = "c_can", |
178 | .driver_data = BOSCH_C_CAN, | 186 | .driver_data = (kernel_ulong_t)&c_can_drvdata, |
179 | }, | 187 | }, |
180 | [BOSCH_D_CAN] = { | 188 | { |
181 | .name = "d_can", | 189 | .name = "d_can", |
182 | .driver_data = BOSCH_D_CAN, | 190 | .driver_data = (kernel_ulong_t)&d_can_drvdata, |
183 | }, { | 191 | }, |
184 | } | 192 | { /* sentinel */ }, |
185 | }; | 193 | }; |
186 | MODULE_DEVICE_TABLE(platform, c_can_id_table); | 194 | MODULE_DEVICE_TABLE(platform, c_can_id_table); |
187 | 195 | ||
188 | static const struct of_device_id c_can_of_table[] = { | 196 | static const struct of_device_id c_can_of_table[] = { |
189 | { .compatible = "bosch,c_can", .data = &c_can_id_table[BOSCH_C_CAN] }, | 197 | { .compatible = "bosch,c_can", .data = &c_can_drvdata }, |
190 | { .compatible = "bosch,d_can", .data = &c_can_id_table[BOSCH_D_CAN] }, | 198 | { .compatible = "bosch,d_can", .data = &d_can_drvdata }, |
191 | { /* sentinel */ }, | 199 | { /* sentinel */ }, |
192 | }; | 200 | }; |
193 | MODULE_DEVICE_TABLE(of, c_can_of_table); | 201 | MODULE_DEVICE_TABLE(of, c_can_of_table); |
@@ -199,21 +207,19 @@ static int c_can_plat_probe(struct platform_device *pdev) | |||
199 | struct net_device *dev; | 207 | struct net_device *dev; |
200 | struct c_can_priv *priv; | 208 | struct c_can_priv *priv; |
201 | const struct of_device_id *match; | 209 | const struct of_device_id *match; |
202 | const struct platform_device_id *id; | ||
203 | struct resource *mem, *res; | 210 | struct resource *mem, *res; |
204 | int irq; | 211 | int irq; |
205 | struct clk *clk; | 212 | struct clk *clk; |
206 | 213 | const struct c_can_driver_data *drvdata; | |
207 | if (pdev->dev.of_node) { | 214 | |
208 | match = of_match_device(c_can_of_table, &pdev->dev); | 215 | match = of_match_device(c_can_of_table, &pdev->dev); |
209 | if (!match) { | 216 | if (match) { |
210 | dev_err(&pdev->dev, "Failed to find matching dt id\n"); | 217 | drvdata = match->data; |
211 | ret = -EINVAL; | 218 | } else if (pdev->id_entry->driver_data) { |
212 | goto exit; | 219 | drvdata = (struct c_can_driver_data *) |
213 | } | 220 | platform_get_device_id(pdev)->driver_data; |
214 | id = match->data; | ||
215 | } else { | 221 | } else { |
216 | id = platform_get_device_id(pdev); | 222 | return -ENODEV; |
217 | } | 223 | } |
218 | 224 | ||
219 | /* get the appropriate clk */ | 225 | /* get the appropriate clk */ |
@@ -245,7 +251,7 @@ static int c_can_plat_probe(struct platform_device *pdev) | |||
245 | } | 251 | } |
246 | 252 | ||
247 | priv = netdev_priv(dev); | 253 | priv = netdev_priv(dev); |
248 | switch (id->driver_data) { | 254 | switch (drvdata->id) { |
249 | case BOSCH_C_CAN: | 255 | case BOSCH_C_CAN: |
250 | priv->regs = reg_map_c_can; | 256 | priv->regs = reg_map_c_can; |
251 | switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) { | 257 | switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) { |
@@ -304,7 +310,7 @@ static int c_can_plat_probe(struct platform_device *pdev) | |||
304 | priv->device = &pdev->dev; | 310 | priv->device = &pdev->dev; |
305 | priv->can.clock.freq = clk_get_rate(clk); | 311 | priv->can.clock.freq = clk_get_rate(clk); |
306 | priv->priv = clk; | 312 | priv->priv = clk; |
307 | priv->type = id->driver_data; | 313 | priv->type = drvdata->id; |
308 | 314 | ||
309 | platform_set_drvdata(pdev, dev); | 315 | platform_set_drvdata(pdev, dev); |
310 | SET_NETDEV_DEV(dev, &pdev->dev); | 316 | SET_NETDEV_DEV(dev, &pdev->dev); |