diff options
author | Ludovic Desroches <ludovic.desroches@atmel.com> | 2012-09-12 02:42:14 -0400 |
---|---|---|
committer | Wolfram Sang <w.sang@pengutronix.de> | 2012-09-12 08:49:15 -0400 |
commit | 70d46a241ed3bb0d1bb2bc15720b6f7c215c37f5 (patch) | |
tree | fc064aa0b4c24e39ed6f36f5d1ddb5ae5d51e55c | |
parent | 94e734655fbe294c50d304547cae033e87ec229e (diff) |
i2c: at91: add dt support to i2c-at91
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Acked-by: Nikolaus Voss <n.voss@weinmann.de>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
-rw-r--r-- | Documentation/devicetree/bindings/i2c/atmel-i2c.txt | 30 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-at91.c | 49 |
2 files changed, 79 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/i2c/atmel-i2c.txt b/Documentation/devicetree/bindings/i2c/atmel-i2c.txt new file mode 100644 index 000000000000..b689a0d9441c --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/atmel-i2c.txt | |||
@@ -0,0 +1,30 @@ | |||
1 | I2C for Atmel platforms | ||
2 | |||
3 | Required properties : | ||
4 | - compatible : Must be "atmel,at91rm9200-i2c", "atmel,at91sam9261-i2c", | ||
5 | "atmel,at91sam9260-i2c", "atmel,at91sam9g20-i2c", "atmel,at91sam9g10-i2c" | ||
6 | or "atmel,at91sam9x5-i2c" | ||
7 | - reg: physical base address of the controller and length of memory mapped | ||
8 | region. | ||
9 | - interrupts: interrupt number to the cpu. | ||
10 | - #address-cells = <1>; | ||
11 | - #size-cells = <0>; | ||
12 | |||
13 | Optional properties: | ||
14 | - Child nodes conforming to i2c bus binding | ||
15 | |||
16 | Examples : | ||
17 | |||
18 | i2c0: i2c@fff84000 { | ||
19 | compatible = "atmel,at91sam9g20-i2c"; | ||
20 | reg = <0xfff84000 0x100>; | ||
21 | interrupts = <12 4 6>; | ||
22 | #address-cells = <1>; | ||
23 | #size-cells = <0>; | ||
24 | |||
25 | 24c512@50 { | ||
26 | compatible = "24c512"; | ||
27 | reg = <0x50>; | ||
28 | pagesize = <128>; | ||
29 | } | ||
30 | } | ||
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index 78bcad031d6a..aa59a254be2c 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c | |||
@@ -24,6 +24,9 @@ | |||
24 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
25 | #include <linux/io.h> | 25 | #include <linux/io.h> |
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/of.h> | ||
28 | #include <linux/of_device.h> | ||
29 | #include <linux/of_i2c.h> | ||
27 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
28 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
29 | 32 | ||
@@ -347,6 +350,12 @@ static struct at91_twi_pdata at91sam9g10_config = { | |||
347 | .has_unre_flag = false, | 350 | .has_unre_flag = false, |
348 | }; | 351 | }; |
349 | 352 | ||
353 | static struct at91_twi_pdata at91sam9x5_config = { | ||
354 | .clk_max_div = 7, | ||
355 | .clk_offset = 4, | ||
356 | .has_unre_flag = false, | ||
357 | }; | ||
358 | |||
350 | static const struct platform_device_id at91_twi_devtypes[] = { | 359 | static const struct platform_device_id at91_twi_devtypes[] = { |
351 | { | 360 | { |
352 | .name = "i2c-at91rm9200", | 361 | .name = "i2c-at91rm9200", |
@@ -368,6 +377,42 @@ static const struct platform_device_id at91_twi_devtypes[] = { | |||
368 | } | 377 | } |
369 | }; | 378 | }; |
370 | 379 | ||
380 | #if defined(CONFIG_OF) | ||
381 | static const struct of_device_id atmel_twi_dt_ids[] = { | ||
382 | { | ||
383 | .compatible = "atmel,at91sam9260-i2c", | ||
384 | .data = &at91sam9260_config, | ||
385 | } , { | ||
386 | .compatible = "atmel,at91sam9g20-i2c", | ||
387 | .data = &at91sam9g20_config, | ||
388 | } , { | ||
389 | .compatible = "atmel,at91sam9g10-i2c", | ||
390 | .data = &at91sam9g10_config, | ||
391 | }, { | ||
392 | .compatible = "atmel,at91sam9x5-i2c", | ||
393 | .data = &at91sam9x5_config, | ||
394 | }, { | ||
395 | /* sentinel */ | ||
396 | } | ||
397 | }; | ||
398 | MODULE_DEVICE_TABLE(of, atmel_twi_dt_ids); | ||
399 | #else | ||
400 | #define atmel_twi_dt_ids NULL | ||
401 | #endif | ||
402 | |||
403 | static struct at91_twi_pdata * __devinit at91_twi_get_driver_data( | ||
404 | struct platform_device *pdev) | ||
405 | { | ||
406 | if (pdev->dev.of_node) { | ||
407 | const struct of_device_id *match; | ||
408 | match = of_match_node(atmel_twi_dt_ids, pdev->dev.of_node); | ||
409 | if (!match) | ||
410 | return NULL; | ||
411 | return match->data; | ||
412 | } | ||
413 | return (struct at91_twi_pdata *) platform_get_device_id(pdev)->driver_data; | ||
414 | } | ||
415 | |||
371 | static int __devinit at91_twi_probe(struct platform_device *pdev) | 416 | static int __devinit at91_twi_probe(struct platform_device *pdev) |
372 | { | 417 | { |
373 | struct at91_twi_dev *dev; | 418 | struct at91_twi_dev *dev; |
@@ -423,6 +468,7 @@ static int __devinit at91_twi_probe(struct platform_device *pdev) | |||
423 | dev->adapter.dev.parent = dev->dev; | 468 | dev->adapter.dev.parent = dev->dev; |
424 | dev->adapter.nr = pdev->id; | 469 | dev->adapter.nr = pdev->id; |
425 | dev->adapter.timeout = AT91_I2C_TIMEOUT; | 470 | dev->adapter.timeout = AT91_I2C_TIMEOUT; |
471 | dev->adapter.dev.of_node = pdev->dev.of_node; | ||
426 | 472 | ||
427 | rc = i2c_add_numbered_adapter(&dev->adapter); | 473 | rc = i2c_add_numbered_adapter(&dev->adapter); |
428 | if (rc) { | 474 | if (rc) { |
@@ -432,6 +478,8 @@ static int __devinit at91_twi_probe(struct platform_device *pdev) | |||
432 | return rc; | 478 | return rc; |
433 | } | 479 | } |
434 | 480 | ||
481 | of_i2c_register_devices(&dev->adapter); | ||
482 | |||
435 | dev_info(dev->dev, "AT91 i2c bus driver.\n"); | 483 | dev_info(dev->dev, "AT91 i2c bus driver.\n"); |
436 | return 0; | 484 | return 0; |
437 | } | 485 | } |
@@ -482,6 +530,7 @@ static struct platform_driver at91_twi_driver = { | |||
482 | .driver = { | 530 | .driver = { |
483 | .name = "at91_i2c", | 531 | .name = "at91_i2c", |
484 | .owner = THIS_MODULE, | 532 | .owner = THIS_MODULE, |
533 | .of_match_table = atmel_twi_dt_ids, | ||
485 | .pm = at91_twi_pm_ops, | 534 | .pm = at91_twi_pm_ops, |
486 | }, | 535 | }, |
487 | }; | 536 | }; |