diff options
author | Chris Packham <chris.packham@alliedtelesis.co.nz> | 2017-06-25 20:44:32 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2017-06-27 15:47:54 -0400 |
commit | 0e8ce93bdceb6d36a3c1db2227d3f51168fb796c (patch) | |
tree | 4977a7b5d91256ea7e47635e46aba44c986f7657 | |
parent | 4cc7229daa46d1867e66ba09929d936377ae4837 (diff) |
i2c: pca-platform: add devicetree awareness
Allow devices that use this driver to be registered via a
devicetree.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
[wsa: fixed leakage when registering GPIO failed]
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r-- | drivers/i2c/busses/i2c-pca-platform.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c index 9f995b8ed587..31d7f76ddd94 100644 --- a/drivers/i2c/busses/i2c-pca-platform.c +++ b/drivers/i2c/busses/i2c-pca-platform.c | |||
@@ -24,6 +24,8 @@ | |||
24 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
25 | #include <linux/gpio/consumer.h> | 25 | #include <linux/gpio/consumer.h> |
26 | #include <linux/io.h> | 26 | #include <linux/io.h> |
27 | #include <linux/of.h> | ||
28 | #include <linux/of_device.h> | ||
27 | 29 | ||
28 | #include <asm/irq.h> | 30 | #include <asm/irq.h> |
29 | 31 | ||
@@ -137,12 +139,15 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) | |||
137 | struct resource *res; | 139 | struct resource *res; |
138 | struct i2c_pca9564_pf_platform_data *platform_data = | 140 | struct i2c_pca9564_pf_platform_data *platform_data = |
139 | dev_get_platdata(&pdev->dev); | 141 | dev_get_platdata(&pdev->dev); |
142 | struct device_node *np = pdev->dev.of_node; | ||
140 | int ret = 0; | 143 | int ret = 0; |
141 | int irq; | 144 | int irq; |
142 | 145 | ||
143 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 146 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
144 | irq = platform_get_irq(pdev, 0); | 147 | irq = platform_get_irq(pdev, 0); |
145 | /* If irq is 0, we do polling. */ | 148 | /* If irq is 0, we do polling. */ |
149 | if (irq < 0) | ||
150 | irq = 0; | ||
146 | 151 | ||
147 | if (res == NULL) { | 152 | if (res == NULL) { |
148 | ret = -ENODEV; | 153 | ret = -ENODEV; |
@@ -178,6 +183,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) | |||
178 | (unsigned long) res->start); | 183 | (unsigned long) res->start); |
179 | i2c->adap.algo_data = &i2c->algo_data; | 184 | i2c->adap.algo_data = &i2c->algo_data; |
180 | i2c->adap.dev.parent = &pdev->dev; | 185 | i2c->adap.dev.parent = &pdev->dev; |
186 | i2c->adap.dev.of_node = np; | ||
181 | 187 | ||
182 | if (platform_data) { | 188 | if (platform_data) { |
183 | i2c->adap.timeout = platform_data->timeout; | 189 | i2c->adap.timeout = platform_data->timeout; |
@@ -196,6 +202,15 @@ static int i2c_pca_pf_probe(struct platform_device *pdev) | |||
196 | i2c->gpio = NULL; | 202 | i2c->gpio = NULL; |
197 | } | 203 | } |
198 | } | 204 | } |
205 | } else if (np) { | ||
206 | i2c->adap.timeout = HZ; | ||
207 | i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset-gpios", GPIOD_OUT_LOW); | ||
208 | if (IS_ERR(i2c->gpio)) { | ||
209 | ret = PTR_ERR(i2c->gpio); | ||
210 | goto e_reqirq; | ||
211 | } | ||
212 | of_property_read_u32_index(np, "clock-frequency", 0, | ||
213 | &i2c->algo_data.i2c_clock); | ||
199 | } else { | 214 | } else { |
200 | i2c->adap.timeout = HZ; | 215 | i2c->adap.timeout = HZ; |
201 | i2c->algo_data.i2c_clock = 59000; | 216 | i2c->algo_data.i2c_clock = 59000; |
@@ -270,11 +285,21 @@ static int i2c_pca_pf_remove(struct platform_device *pdev) | |||
270 | return 0; | 285 | return 0; |
271 | } | 286 | } |
272 | 287 | ||
288 | #ifdef CONFIG_OF | ||
289 | static const struct of_device_id i2c_pca_of_match_table[] = { | ||
290 | { .compatible = "nxp,pca9564" }, | ||
291 | { .compatible = "nxp,pca9665" }, | ||
292 | {}, | ||
293 | }; | ||
294 | MODULE_DEVICE_TABLE(of, i2c_pca_of_match_table); | ||
295 | #endif | ||
296 | |||
273 | static struct platform_driver i2c_pca_pf_driver = { | 297 | static struct platform_driver i2c_pca_pf_driver = { |
274 | .probe = i2c_pca_pf_probe, | 298 | .probe = i2c_pca_pf_probe, |
275 | .remove = i2c_pca_pf_remove, | 299 | .remove = i2c_pca_pf_remove, |
276 | .driver = { | 300 | .driver = { |
277 | .name = "i2c-pca-platform", | 301 | .name = "i2c-pca-platform", |
302 | .of_match_table = of_match_ptr(i2c_pca_of_match_table), | ||
278 | }, | 303 | }, |
279 | }; | 304 | }; |
280 | 305 | ||