diff options
author | Heiko Schocher <hs@denx.de> | 2012-07-30 03:21:12 -0400 |
---|---|---|
committer | Wolfram Sang <w.sang@pengutronix.de> | 2012-09-12 05:37:24 -0400 |
commit | 5c3d8a46ac9778d117ca26f4fec18d7b8c8831ed (patch) | |
tree | 1bb21169eddd9cb29c9bcb1ca19b8bcbea43b4b3 | |
parent | 002f002d956e6b01700ab8753c6f268c9aafc34a (diff) |
i2c: davinci: add OF support
add of support for the davinci i2c driver.
Signed-off-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
[wsa: fix indentation in the binding description]
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
-rw-r--r-- | Documentation/devicetree/bindings/i2c/davinci.txt | 28 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-davinci.c | 48 |
2 files changed, 65 insertions, 11 deletions
diff --git a/Documentation/devicetree/bindings/i2c/davinci.txt b/Documentation/devicetree/bindings/i2c/davinci.txt new file mode 100644 index 000000000000..2dc935b4113d --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/davinci.txt | |||
@@ -0,0 +1,28 @@ | |||
1 | * Texas Instruments Davinci I2C | ||
2 | |||
3 | This file provides information, what the device node for the | ||
4 | davinci i2c interface contain. | ||
5 | |||
6 | Required properties: | ||
7 | - compatible: "ti,davinci-i2c"; | ||
8 | - reg : Offset and length of the register set for the device | ||
9 | |||
10 | Recommended properties : | ||
11 | - interrupts : standard interrupt property. | ||
12 | - clock-frequency : desired I2C bus clock frequency in Hz. | ||
13 | |||
14 | Example (enbw_cmc board): | ||
15 | i2c@1c22000 { | ||
16 | compatible = "ti,davinci-i2c"; | ||
17 | reg = <0x22000 0x1000>; | ||
18 | clock-frequency = <100000>; | ||
19 | interrupts = <15>; | ||
20 | interrupt-parent = <&intc>; | ||
21 | #address-cells = <1>; | ||
22 | #size-cells = <0>; | ||
23 | |||
24 | dtt@48 { | ||
25 | compatible = "national,lm75"; | ||
26 | reg = <0x48>; | ||
27 | }; | ||
28 | }; | ||
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 79b4bcb3b85c..b6185dccdf4a 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c | |||
@@ -38,6 +38,8 @@ | |||
38 | #include <linux/slab.h> | 38 | #include <linux/slab.h> |
39 | #include <linux/cpufreq.h> | 39 | #include <linux/cpufreq.h> |
40 | #include <linux/gpio.h> | 40 | #include <linux/gpio.h> |
41 | #include <linux/of_i2c.h> | ||
42 | #include <linux/of_device.h> | ||
41 | 43 | ||
42 | #include <mach/hardware.h> | 44 | #include <mach/hardware.h> |
43 | #include <mach/i2c.h> | 45 | #include <mach/i2c.h> |
@@ -114,6 +116,7 @@ struct davinci_i2c_dev { | |||
114 | struct completion xfr_complete; | 116 | struct completion xfr_complete; |
115 | struct notifier_block freq_transition; | 117 | struct notifier_block freq_transition; |
116 | #endif | 118 | #endif |
119 | struct davinci_i2c_platform_data *pdata; | ||
117 | }; | 120 | }; |
118 | 121 | ||
119 | /* default platform data to use if not supplied in the platform_device */ | 122 | /* default platform data to use if not supplied in the platform_device */ |
@@ -155,7 +158,7 @@ static void generic_i2c_clock_pulse(unsigned int scl_pin) | |||
155 | static void i2c_recover_bus(struct davinci_i2c_dev *dev) | 158 | static void i2c_recover_bus(struct davinci_i2c_dev *dev) |
156 | { | 159 | { |
157 | u32 flag = 0; | 160 | u32 flag = 0; |
158 | struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; | 161 | struct davinci_i2c_platform_data *pdata = dev->pdata; |
159 | 162 | ||
160 | dev_err(dev->dev, "initiating i2c bus recovery\n"); | 163 | dev_err(dev->dev, "initiating i2c bus recovery\n"); |
161 | /* Send NACK to the slave */ | 164 | /* Send NACK to the slave */ |
@@ -163,8 +166,7 @@ static void i2c_recover_bus(struct davinci_i2c_dev *dev) | |||
163 | flag |= DAVINCI_I2C_MDR_NACK; | 166 | flag |= DAVINCI_I2C_MDR_NACK; |
164 | /* write the data into mode register */ | 167 | /* write the data into mode register */ |
165 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); | 168 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); |
166 | if (pdata) | 169 | generic_i2c_clock_pulse(pdata->scl_pin); |
167 | generic_i2c_clock_pulse(pdata->scl_pin); | ||
168 | /* Send STOP */ | 170 | /* Send STOP */ |
169 | flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); | 171 | flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); |
170 | flag |= DAVINCI_I2C_MDR_STP; | 172 | flag |= DAVINCI_I2C_MDR_STP; |
@@ -187,7 +189,7 @@ static inline void davinci_i2c_reset_ctrl(struct davinci_i2c_dev *i2c_dev, | |||
187 | 189 | ||
188 | static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev) | 190 | static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev) |
189 | { | 191 | { |
190 | struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; | 192 | struct davinci_i2c_platform_data *pdata = dev->pdata; |
191 | u16 psc; | 193 | u16 psc; |
192 | u32 clk; | 194 | u32 clk; |
193 | u32 d; | 195 | u32 d; |
@@ -235,10 +237,7 @@ static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev) | |||
235 | */ | 237 | */ |
236 | static int i2c_davinci_init(struct davinci_i2c_dev *dev) | 238 | static int i2c_davinci_init(struct davinci_i2c_dev *dev) |
237 | { | 239 | { |
238 | struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; | 240 | struct davinci_i2c_platform_data *pdata = dev->pdata; |
239 | |||
240 | if (!pdata) | ||
241 | pdata = &davinci_i2c_platform_data_default; | ||
242 | 241 | ||
243 | /* put I2C into reset */ | 242 | /* put I2C into reset */ |
244 | davinci_i2c_reset_ctrl(dev, 0); | 243 | davinci_i2c_reset_ctrl(dev, 0); |
@@ -260,6 +259,7 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev) | |||
260 | dev_dbg(dev->dev, "bus_freq = %dkHz, bus_delay = %d\n", | 259 | dev_dbg(dev->dev, "bus_freq = %dkHz, bus_delay = %d\n", |
261 | pdata->bus_freq, pdata->bus_delay); | 260 | pdata->bus_freq, pdata->bus_delay); |
262 | 261 | ||
262 | |||
263 | /* Take the I2C module out of reset: */ | 263 | /* Take the I2C module out of reset: */ |
264 | davinci_i2c_reset_ctrl(dev, 1); | 264 | davinci_i2c_reset_ctrl(dev, 1); |
265 | 265 | ||
@@ -308,13 +308,11 @@ static int | |||
308 | i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) | 308 | i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) |
309 | { | 309 | { |
310 | struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); | 310 | struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); |
311 | struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; | 311 | struct davinci_i2c_platform_data *pdata = dev->pdata; |
312 | u32 flag; | 312 | u32 flag; |
313 | u16 w; | 313 | u16 w; |
314 | int r; | 314 | int r; |
315 | 315 | ||
316 | if (!pdata) | ||
317 | pdata = &davinci_i2c_platform_data_default; | ||
318 | /* Introduce a delay, required for some boards (e.g Davinci EVM) */ | 316 | /* Introduce a delay, required for some boards (e.g Davinci EVM) */ |
319 | if (pdata->bus_delay) | 317 | if (pdata->bus_delay) |
320 | udelay(pdata->bus_delay); | 318 | udelay(pdata->bus_delay); |
@@ -635,6 +633,12 @@ static struct i2c_algorithm i2c_davinci_algo = { | |||
635 | .functionality = i2c_davinci_func, | 633 | .functionality = i2c_davinci_func, |
636 | }; | 634 | }; |
637 | 635 | ||
636 | static const struct of_device_id davinci_i2c_of_match[] = { | ||
637 | {.compatible = "ti,davinci-i2c", }, | ||
638 | {}, | ||
639 | }; | ||
640 | MODULE_DEVICE_TABLE(of, davinci_i2c_of_match); | ||
641 | |||
638 | static int davinci_i2c_probe(struct platform_device *pdev) | 642 | static int davinci_i2c_probe(struct platform_device *pdev) |
639 | { | 643 | { |
640 | struct davinci_i2c_dev *dev; | 644 | struct davinci_i2c_dev *dev; |
@@ -674,8 +678,27 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
674 | #endif | 678 | #endif |
675 | dev->dev = get_device(&pdev->dev); | 679 | dev->dev = get_device(&pdev->dev); |
676 | dev->irq = irq->start; | 680 | dev->irq = irq->start; |
681 | dev->pdata = dev->dev->platform_data; | ||
677 | platform_set_drvdata(pdev, dev); | 682 | platform_set_drvdata(pdev, dev); |
678 | 683 | ||
684 | if (!dev->pdata && pdev->dev.of_node) { | ||
685 | u32 prop; | ||
686 | |||
687 | dev->pdata = devm_kzalloc(&pdev->dev, | ||
688 | sizeof(struct davinci_i2c_platform_data), GFP_KERNEL); | ||
689 | if (!dev->pdata) { | ||
690 | r = -ENOMEM; | ||
691 | goto err_free_mem; | ||
692 | } | ||
693 | memcpy(dev->pdata, &davinci_i2c_platform_data_default, | ||
694 | sizeof(struct davinci_i2c_platform_data)); | ||
695 | if (!of_property_read_u32(pdev->dev.of_node, "clock-frequency", | ||
696 | &prop)) | ||
697 | dev->pdata->bus_freq = prop / 1000; | ||
698 | } else if (!dev->pdata) { | ||
699 | dev->pdata = &davinci_i2c_platform_data_default; | ||
700 | } | ||
701 | |||
679 | dev->clk = clk_get(&pdev->dev, NULL); | 702 | dev->clk = clk_get(&pdev->dev, NULL); |
680 | if (IS_ERR(dev->clk)) { | 703 | if (IS_ERR(dev->clk)) { |
681 | r = -ENODEV; | 704 | r = -ENODEV; |
@@ -711,6 +734,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
711 | adap->algo = &i2c_davinci_algo; | 734 | adap->algo = &i2c_davinci_algo; |
712 | adap->dev.parent = &pdev->dev; | 735 | adap->dev.parent = &pdev->dev; |
713 | adap->timeout = DAVINCI_I2C_TIMEOUT; | 736 | adap->timeout = DAVINCI_I2C_TIMEOUT; |
737 | adap->dev.of_node = pdev->dev.of_node; | ||
714 | 738 | ||
715 | adap->nr = pdev->id; | 739 | adap->nr = pdev->id; |
716 | r = i2c_add_numbered_adapter(adap); | 740 | r = i2c_add_numbered_adapter(adap); |
@@ -718,6 +742,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
718 | dev_err(&pdev->dev, "failure adding adapter\n"); | 742 | dev_err(&pdev->dev, "failure adding adapter\n"); |
719 | goto err_free_irq; | 743 | goto err_free_irq; |
720 | } | 744 | } |
745 | of_i2c_register_devices(adap); | ||
721 | 746 | ||
722 | return 0; | 747 | return 0; |
723 | 748 | ||
@@ -809,6 +834,7 @@ static struct platform_driver davinci_i2c_driver = { | |||
809 | .name = "i2c_davinci", | 834 | .name = "i2c_davinci", |
810 | .owner = THIS_MODULE, | 835 | .owner = THIS_MODULE, |
811 | .pm = davinci_i2c_pm_ops, | 836 | .pm = davinci_i2c_pm_ops, |
837 | .of_match_table = of_match_ptr(davinci_i2c_of_match), | ||
812 | }, | 838 | }, |
813 | }; | 839 | }; |
814 | 840 | ||