10 #include <linux/i2c.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
28 static void i2c_gpio_setsda_dir(
void *
data,
int state)
43 static void i2c_gpio_setsda_val(
void *data,
int state)
51 static void i2c_gpio_setscl_dir(
void *data,
int state)
67 static void i2c_gpio_setscl_val(
void *data,
int state)
74 static int i2c_gpio_getsda(
void *data)
81 static int i2c_gpio_getscl(
void *data)
93 if (of_gpio_count(np) < 2)
96 pdata->
sda_pin = of_get_gpio(np, 0);
97 pdata->
scl_pin = of_get_gpio(np, 1);
99 if (!gpio_is_valid(pdata->
sda_pin) || !gpio_is_valid(pdata->
scl_pin)) {
100 pr_err(
"%s: invalid GPIO pins, sda=%d/scl=%d\n",
105 of_property_read_u32(np,
"i2c-gpio,delay-us", &pdata->
udelay);
107 if (!of_property_read_u32(np,
"i2c-gpio,timeout-ms", ®))
111 of_property_read_bool(np,
"i2c-gpio,sda-open-drain");
113 of_property_read_bool(np,
"i2c-gpio,scl-open-drain");
115 of_property_read_bool(np,
"i2c-gpio,scl-output-only");
133 pdata = &priv->
pdata;
135 if (pdev->
dev.of_node) {
136 ret = of_i2c_gpio_probe(pdev->
dev.of_node, pdata);
140 if (!pdev->
dev.platform_data)
142 memcpy(pdata, pdev->
dev.platform_data,
sizeof(*pdata));
147 goto err_request_sda;
150 goto err_request_scl;
154 bit_data->
setsda = i2c_gpio_setsda_val;
157 bit_data->
setsda = i2c_gpio_setsda_dir;
162 bit_data->
setscl = i2c_gpio_setscl_val;
165 bit_data->
setscl = i2c_gpio_setscl_dir;
169 bit_data->
getscl = i2c_gpio_getscl;
170 bit_data->
getsda = i2c_gpio_getsda;
190 adap->
dev.parent = &pdev->
dev;
191 adap->
dev.of_node = pdev->
dev.of_node;
200 platform_set_drvdata(pdev, priv);
202 dev_info(&pdev->
dev,
"using pins %u (SDA) and %u (SCL%s)\n",
205 ?
", no clock stretching" :
"");
223 priv = platform_get_drvdata(pdev);
225 pdata = &priv->
pdata;
234 #if defined(CONFIG_OF)
249 .probe = i2c_gpio_probe,
253 static int __init i2c_gpio_init(
void)
265 static void __exit i2c_gpio_exit(
void)