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

i2c-imx: add device tree probe support

It adds device tree probe support for i2c-imx driver.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Darius Augulis <augulis.darius@gmail.com>
Cc: Ben Dooks <ben-linux@fluff.org>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>

authored by

Shawn Guo and committed by
Ben Dooks
dfcd04b1 593702c7

+44 -6
+25
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt
··· 1 + * Freescale Inter IC (I2C) and High Speed Inter IC (HS-I2C) for i.MX 2 + 3 + Required properties: 4 + - compatible : Should be "fsl,<chip>-i2c" 5 + - reg : Should contain I2C/HS-I2C registers location and length 6 + - interrupts : Should contain I2C/HS-I2C interrupt 7 + 8 + Optional properties: 9 + - clock-frequency : Constains desired I2C/HS-I2C bus clock frequency in Hz. 10 + The absence of the propoerty indicates the default frequency 100 kHz. 11 + 12 + Examples: 13 + 14 + i2c@83fc4000 { /* I2C2 on i.MX51 */ 15 + compatible = "fsl,imx51-i2c", "fsl,imx1-i2c"; 16 + reg = <0x83fc4000 0x4000>; 17 + interrupts = <63>; 18 + }; 19 + 20 + i2c@70038000 { /* HS-I2C on i.MX51 */ 21 + compatible = "fsl,imx51-i2c", "fsl,imx1-i2c"; 22 + reg = <0x70038000 0x4000>; 23 + interrupts = <64>; 24 + clock-frequency = <400000>; 25 + };
+19 -6
drivers/i2c/busses/i2c-imx.c
··· 48 48 #include <linux/platform_device.h> 49 49 #include <linux/clk.h> 50 50 #include <linux/slab.h> 51 + #include <linux/of.h> 52 + #include <linux/of_device.h> 53 + #include <linux/of_i2c.h> 51 54 52 55 #include <mach/irqs.h> 53 56 #include <mach/hardware.h> ··· 126 123 unsigned int disable_delay; 127 124 int stopped; 128 125 unsigned int ifdr; /* IMX_I2C_IFDR */ 126 + }; 127 + 128 + static const struct of_device_id i2c_imx_dt_ids[] = { 129 + { .compatible = "fsl,imx1-i2c", }, 130 + { /* sentinel */ } 129 131 }; 130 132 131 133 /** Functions for IMX I2C adapter driver *************************************** ··· 477 469 struct imxi2c_platform_data *pdata = pdev->dev.platform_data; 478 470 void __iomem *base; 479 471 resource_size_t res_size; 480 - int irq; 472 + int irq, bitrate; 481 473 int ret; 482 474 483 475 dev_dbg(&pdev->dev, "<%s>\n", __func__); ··· 520 512 i2c_imx->adapter.algo = &i2c_imx_algo; 521 513 i2c_imx->adapter.dev.parent = &pdev->dev; 522 514 i2c_imx->adapter.nr = pdev->id; 515 + i2c_imx->adapter.dev.of_node = pdev->dev.of_node; 523 516 i2c_imx->irq = irq; 524 517 i2c_imx->base = base; 525 518 i2c_imx->res = res; ··· 547 538 i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); 548 539 549 540 /* Set up clock divider */ 550 - if (pdata && pdata->bitrate) 551 - i2c_imx_set_clk(i2c_imx, pdata->bitrate); 552 - else 553 - i2c_imx_set_clk(i2c_imx, IMX_I2C_BIT_RATE); 541 + bitrate = IMX_I2C_BIT_RATE; 542 + ret = of_property_read_u32(pdev->dev.of_node, 543 + "clock-frequency", &bitrate); 544 + if (ret < 0 && pdata && pdata->bitrate) 545 + bitrate = pdata->bitrate; 546 + i2c_imx_set_clk(i2c_imx, bitrate); 554 547 555 548 /* Set up chip registers to defaults */ 556 549 writeb(0, i2c_imx->base + IMX_I2C_I2CR); ··· 564 553 dev_err(&pdev->dev, "registration failed\n"); 565 554 goto fail5; 566 555 } 556 + 557 + of_i2c_register_devices(&i2c_imx->adapter); 567 558 568 559 /* Set up platform driver data */ 569 560 platform_set_drvdata(pdev, i2c_imx); ··· 597 584 static int __exit i2c_imx_remove(struct platform_device *pdev) 598 585 { 599 586 struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); 600 - struct imxi2c_platform_data *pdata = pdev->dev.platform_data; 601 587 602 588 /* remove adapter */ 603 589 dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); ··· 625 613 .driver = { 626 614 .name = DRIVER_NAME, 627 615 .owner = THIS_MODULE, 616 + .of_match_table = i2c_imx_dt_ids, 628 617 } 629 618 }; 630 619