Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ludovic Desroches and committed by
Wolfram Sang
70d46a24 94e73465

+79
+30
Documentation/devicetree/bindings/i2c/atmel-i2c.txt
··· 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 + }
+49
drivers/i2c/busses/i2c-at91.c
··· 24 24 #include <linux/interrupt.h> 25 25 #include <linux/io.h> 26 26 #include <linux/module.h> 27 + #include <linux/of.h> 28 + #include <linux/of_device.h> 29 + #include <linux/of_i2c.h> 27 30 #include <linux/platform_device.h> 28 31 #include <linux/slab.h> 29 32 ··· 350 347 .has_unre_flag = false, 351 348 }; 352 349 350 + static struct at91_twi_pdata at91sam9x5_config = { 351 + .clk_max_div = 7, 352 + .clk_offset = 4, 353 + .has_unre_flag = false, 354 + }; 355 + 353 356 static const struct platform_device_id at91_twi_devtypes[] = { 354 357 { 355 358 .name = "i2c-at91rm9200", ··· 376 367 /* sentinel */ 377 368 } 378 369 }; 370 + 371 + #if defined(CONFIG_OF) 372 + static const struct of_device_id atmel_twi_dt_ids[] = { 373 + { 374 + .compatible = "atmel,at91sam9260-i2c", 375 + .data = &at91sam9260_config, 376 + } , { 377 + .compatible = "atmel,at91sam9g20-i2c", 378 + .data = &at91sam9g20_config, 379 + } , { 380 + .compatible = "atmel,at91sam9g10-i2c", 381 + .data = &at91sam9g10_config, 382 + }, { 383 + .compatible = "atmel,at91sam9x5-i2c", 384 + .data = &at91sam9x5_config, 385 + }, { 386 + /* sentinel */ 387 + } 388 + }; 389 + MODULE_DEVICE_TABLE(of, atmel_twi_dt_ids); 390 + #else 391 + #define atmel_twi_dt_ids NULL 392 + #endif 393 + 394 + static struct at91_twi_pdata * __devinit at91_twi_get_driver_data( 395 + struct platform_device *pdev) 396 + { 397 + if (pdev->dev.of_node) { 398 + const struct of_device_id *match; 399 + match = of_match_node(atmel_twi_dt_ids, pdev->dev.of_node); 400 + if (!match) 401 + return NULL; 402 + return match->data; 403 + } 404 + return (struct at91_twi_pdata *) platform_get_device_id(pdev)->driver_data; 405 + } 379 406 380 407 static int __devinit at91_twi_probe(struct platform_device *pdev) 381 408 { ··· 468 423 dev->adapter.dev.parent = dev->dev; 469 424 dev->adapter.nr = pdev->id; 470 425 dev->adapter.timeout = AT91_I2C_TIMEOUT; 426 + dev->adapter.dev.of_node = pdev->dev.of_node; 471 427 472 428 rc = i2c_add_numbered_adapter(&dev->adapter); 473 429 if (rc) { ··· 477 431 clk_disable_unprepare(dev->clk); 478 432 return rc; 479 433 } 434 + 435 + of_i2c_register_devices(&dev->adapter); 480 436 481 437 dev_info(dev->dev, "AT91 i2c bus driver.\n"); 482 438 return 0; ··· 530 482 .driver = { 531 483 .name = "at91_i2c", 532 484 .owner = THIS_MODULE, 485 + .of_match_table = atmel_twi_dt_ids, 533 486 .pm = at91_twi_pm_ops, 534 487 }, 535 488 };