Skip to content

Commit 5c3d8a4

Browse files
hsdenxWolfram Sang
authored andcommitted
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>
1 parent 002f002 commit 5c3d8a4

File tree

2 files changed

+65
-11
lines changed

2 files changed

+65
-11
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
};

drivers/i2c/busses/i2c-davinci.c

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <linux/slab.h>
3939
#include <linux/cpufreq.h>
4040
#include <linux/gpio.h>
41+
#include <linux/of_i2c.h>
42+
#include <linux/of_device.h>
4143

4244
#include <mach/hardware.h>
4345
#include <mach/i2c.h>
@@ -114,6 +116,7 @@ struct davinci_i2c_dev {
114116
struct completion xfr_complete;
115117
struct notifier_block freq_transition;
116118
#endif
119+
struct davinci_i2c_platform_data *pdata;
117120
};
118121

119122
/* default platform data to use if not supplied in the platform_device */
@@ -155,16 +158,15 @@ static void generic_i2c_clock_pulse(unsigned int scl_pin)
155158
static void i2c_recover_bus(struct davinci_i2c_dev *dev)
156159
{
157160
u32 flag = 0;
158-
struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
161+
struct davinci_i2c_platform_data *pdata = dev->pdata;
159162

160163
dev_err(dev->dev, "initiating i2c bus recovery\n");
161164
/* Send NACK to the slave */
162165
flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
163166
flag |= DAVINCI_I2C_MDR_NACK;
164167
/* write the data into mode register */
165168
davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
166-
if (pdata)
167-
generic_i2c_clock_pulse(pdata->scl_pin);
169+
generic_i2c_clock_pulse(pdata->scl_pin);
168170
/* Send STOP */
169171
flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
170172
flag |= DAVINCI_I2C_MDR_STP;
@@ -187,7 +189,7 @@ static inline void davinci_i2c_reset_ctrl(struct davinci_i2c_dev *i2c_dev,
187189

188190
static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev)
189191
{
190-
struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
192+
struct davinci_i2c_platform_data *pdata = dev->pdata;
191193
u16 psc;
192194
u32 clk;
193195
u32 d;
@@ -235,10 +237,7 @@ static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev)
235237
*/
236238
static int i2c_davinci_init(struct davinci_i2c_dev *dev)
237239
{
238-
struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
239-
240-
if (!pdata)
241-
pdata = &davinci_i2c_platform_data_default;
240+
struct davinci_i2c_platform_data *pdata = dev->pdata;
242241

243242
/* put I2C into reset */
244243
davinci_i2c_reset_ctrl(dev, 0);
@@ -260,6 +259,7 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev)
260259
dev_dbg(dev->dev, "bus_freq = %dkHz, bus_delay = %d\n",
261260
pdata->bus_freq, pdata->bus_delay);
262261

262+
263263
/* Take the I2C module out of reset: */
264264
davinci_i2c_reset_ctrl(dev, 1);
265265

@@ -308,13 +308,11 @@ static int
308308
i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
309309
{
310310
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;
312312
u32 flag;
313313
u16 w;
314314
int r;
315315

316-
if (!pdata)
317-
pdata = &davinci_i2c_platform_data_default;
318316
/* Introduce a delay, required for some boards (e.g Davinci EVM) */
319317
if (pdata->bus_delay)
320318
udelay(pdata->bus_delay);
@@ -635,6 +633,12 @@ static struct i2c_algorithm i2c_davinci_algo = {
635633
.functionality = i2c_davinci_func,
636634
};
637635

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+
638642
static int davinci_i2c_probe(struct platform_device *pdev)
639643
{
640644
struct davinci_i2c_dev *dev;
@@ -674,8 +678,27 @@ static int davinci_i2c_probe(struct platform_device *pdev)
674678
#endif
675679
dev->dev = get_device(&pdev->dev);
676680
dev->irq = irq->start;
681+
dev->pdata = dev->dev->platform_data;
677682
platform_set_drvdata(pdev, dev);
678683

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+
679702
dev->clk = clk_get(&pdev->dev, NULL);
680703
if (IS_ERR(dev->clk)) {
681704
r = -ENODEV;
@@ -711,13 +734,15 @@ static int davinci_i2c_probe(struct platform_device *pdev)
711734
adap->algo = &i2c_davinci_algo;
712735
adap->dev.parent = &pdev->dev;
713736
adap->timeout = DAVINCI_I2C_TIMEOUT;
737+
adap->dev.of_node = pdev->dev.of_node;
714738

715739
adap->nr = pdev->id;
716740
r = i2c_add_numbered_adapter(adap);
717741
if (r) {
718742
dev_err(&pdev->dev, "failure adding adapter\n");
719743
goto err_free_irq;
720744
}
745+
of_i2c_register_devices(adap);
721746

722747
return 0;
723748

@@ -809,6 +834,7 @@ static struct platform_driver davinci_i2c_driver = {
809834
.name = "i2c_davinci",
810835
.owner = THIS_MODULE,
811836
.pm = davinci_i2c_pm_ops,
837+
.of_match_table = of_match_ptr(davinci_i2c_of_match),
812838
},
813839
};
814840

0 commit comments

Comments
 (0)