Add device tree support for Samsung's I2C driver
Subsystems (3)
v3 cover Add device tree support for Samsung's I2C driver
This patchset adds device tree support for Samsung's I2C driver.
Changes since v2:
- Addressed all comments from Grant Likely
- Used dev_kzalloc to allocate memory for platform data.
- Removed redundant check while adding i2c adapter.
- Added support to retrieve gpio pin information from dt and request gpio pins (retained Grant's Ack even though this is a new addition in this version of the patch).
Changes since v1:
- Addressed all comments from Grant Likely
- s3c24xx_i2c_is2440 function is simpler now.
- Consolidated all the scatterd dt support code into a single function to make the dt support code non-invasive.
- but the dependency on i2c pinmux handler function passed from the platform data is retained. It would be removed eventually when the new pinmux api is finalized and the i2c driver is modified to support the pinmux settings using the pinmux api.
Thomas Abraham (2):
i2c: s3c2410: Keep a copy of platform data and use it
i2c: s3c2410: Add device tree support
.../devicetree/bindings/i2c/samsung-i2c.txt | 39 ++++++ drivers/i2c/busses/i2c-s3c2410.c | 128 ++++++++++++++++++-- 2 files changed, 159 insertions(+), 8 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/samsung-i2c.txt
PATCH v3 1/2 i2c: s3c2410: Keep a copy of platform data and use it
The platform data is copied into driver's private data and the copy is used for all access to the platform data. This simpifies the addition of device tree support for the i2c-s3c2410 driver.
--- drivers/i2c/busses/i2c-s3c2410.c | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-s3c2410.c +14 -4
@@ -78,6 +78,7 @@ struct s3c24xx_i2c {struct resource *ioarea;struct i2c_adapter adap; +struct s3c2410_platform_i2c *pdata;#ifdef CONFIG_CPU_FREQ struct notifier_block freq_transition;#endif
@@ -625,7 +626,7 @@ static int s3c24xx_i2c_calcdivisor(unsigned long clkin, unsigned int wanted,static int s3c24xx_i2c_clockrate (struct s3c24xx_i2c *i2c,unsigned int *got) { -struct s3c2410_platform_i2c *pdata = i2c->dev->platform_data; +struct s3c2410_platform_i2c *pdata = i2c->pdata;unsigned long clkin =clk_get_rate (i2c->clk);unsigned int divs, div1;unsigned long target_frequency;
@@ -754,7 +755,7 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)/* get the plafrom data */ - pdata = i2c->dev->platform_data; + pdata = i2c->pdata;/* inititalise the gpio */
@@ -793,7 +794,7 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)static int s3c24xx_i2c_probe (struct platform_device *pdev) {struct s3c24xx_i2c *i2c; -struct s3c2410_platform_i2c *pdata; +struct s3c2410_platform_i2c *pdata =NULL ;struct resource *res;int ret;
@@ -809,6 +810,15 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)return -ENOMEM ; } + i2c->pdata =devm_kzalloc (&pdev->dev,sizeof (*pdata),GFP_KERNEL ); +if (!i2c->pdata) { + ret = -ENOMEM ; + goto err_noclk; + } + +if (pdata) +memcpy (i2c->pdata, pdata,sizeof (*pdata)); +strlcpy (i2c->adap.name,"s3c2410-i2c" ,sizeof (i2c->adap.name)); i2c->adap.owner =THIS_MODULE ; i2c->adap.algo = &s3c24xx_i2c_algorithm;
@@ -903,7 +913,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)* being bus 0. */ - i2c->adap.nr = pdata->bus_num; + i2c->adap.nr = i2c->pdata->bus_num; ret =i2c_add_numbered_adapter (&i2c->adap);if (ret <0 ) {
Signature · 1 line
1.6.6.rc2
PATCH v3 2/2 i2c: s3c2410: Add device tree support
Add device tree probe support for Samsung's s3c2410 i2c driver.
--- .../devicetree/bindings/i2c/samsung-i2c.txt | 39 +++++++ drivers/i2c/busses/i2c-s3c2410.c | 110 +++++++++++++++++++- 2 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/samsung-i2c.txt
Documentation/devicetree/bindings/i2c/samsung-i2c.txt new file +39 -0
@@ -0,0 +1,39 @@ +* Samsung's I2C controller + +The Samsung's I2C controller is used to interface with I2C devices. + +Required properties: + - compatible: value should be either of the following. + (a) "samsung, s3c2410-i2c", for i2c compatible with s3c2410 i2c. + (b) "samsung, s3c2440-i2c", for i2c compatible with s3c2440 i2c. + - reg: physical base address of the controller and length of memory mapped + region. + - interrupts: interrupt number to the cpu. + - samsung,i2c-sda-delay: Delay (in ns) applied to data line (SDA) edges. + - gpios: The order of the gpios should be the following: <SDA, SCL>. + The gpio specifier depends on the gpio controller. + +Optional properties: + - samsung,i2c-slave-addr: Slave address in multi-master enviroment. If not + specified, default value is 0. + - samsung,i2c-max-bus-freq: Desired frequency in Hz of the bus. If not + specified, the default value in Hz is 100000. + +Example: + + i2c at 13870000 { + compatible = "samsung,s3c2440-i2c"; + reg = <0x13870000 0x100>; + interrupts = <345>; + samsung,i2c-sda-delay = <100>; + samsung,i2c-max-bus-freq = <100000>; + gpios = <&gpd1 2 0 /* SDA */ + &gpd1 3 0 /* SCL */>; + #address-cells = <1>; + #size-cells = <0>; + + wm8994 at 1a { + compatible = "wlf,wm8994"; + reg = <0x1a>; + }; + };
drivers/i2c/busses/i2c-s3c2410.c +106 -4
188 lines not on this page · raw message
Signature · 1 line
1.6.6.rc2
PATCH v3 1/2 i2c: s3c2410: Keep a copy of platform data and use it
In reply to Thomas Abrahamdrivers/i2c/busses/i2c-s3c2410.c static int s3c24xx_i2c_probe(struct platform_device *pdev) · line 821
Quoted 13 lines · Thomas Abraham
drivers/i2c/busses/i2c-s3c2410.c +9
-0@@ -809,6 +810,15 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)return -ENOMEM ; } + i2c->pdata =devm_kzalloc (&pdev->dev,sizeof (*pdata),GFP_KERNEL ); +if (!i2c->pdata) { + ret = -ENOMEM ; + goto err_noclk; + } + +if (pdata) +memcpy (i2c->pdata, pdata,sizeof (*pdata)); +
Is there a devm_kmemdup()? If not, maybe it would be a good idea to add it.
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
v3 cover Add device tree support for Samsung's I2C driver
In reply to Thomas AbrahamQuoted 1 line · Thomas Abraham
This patchset adds device tree support for Samsung's I2C driver.
I've applied these after a brief review. I'll give them a better review before the weekend.
v3 cover Add device tree support for Samsung's I2C driver
Hi Ben,
Quoted 5 lines · Ben Dooks
Quoted 1 line · Thomas Abraham
This patchset adds device tree support for Samsung's I2C driver.
I've applied these after a brief review. I'll give them a better review before the weekend.
Thanks for your review.
Regards,
Thomas.