Lines Matching +full:i2c +full:- +full:polling

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Platform driver for the PCA9564 I2C controller.
17 #include <linux/i2c.h>
20 #include <linux/i2c-algo-pca.h>
21 #include <linux/platform_data/i2c-pca-platform.h>
30 int irq; /* if 0, use polling */
41 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_readbyte8() local
42 return ioread8(i2c->reg_base + reg); in i2c_pca_pf_readbyte8()
47 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_readbyte16() local
48 return ioread8(i2c->reg_base + reg * 2); in i2c_pca_pf_readbyte16()
53 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_readbyte32() local
54 return ioread8(i2c->reg_base + reg * 4); in i2c_pca_pf_readbyte32()
59 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_writebyte8() local
60 iowrite8(val, i2c->reg_base + reg); in i2c_pca_pf_writebyte8()
65 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_writebyte16() local
66 iowrite8(val, i2c->reg_base + reg * 2); in i2c_pca_pf_writebyte16()
71 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_writebyte32() local
72 iowrite8(val, i2c->reg_base + reg * 4); in i2c_pca_pf_writebyte32()
78 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_waitforcompletion() local
82 if (i2c->irq) { in i2c_pca_pf_waitforcompletion()
83 ret = wait_event_timeout(i2c->wait, in i2c_pca_pf_waitforcompletion()
84 i2c->algo_data.read_byte(i2c, I2C_PCA_CON) in i2c_pca_pf_waitforcompletion()
85 & I2C_PCA_CON_SI, i2c->adap.timeout); in i2c_pca_pf_waitforcompletion()
87 /* Do polling */ in i2c_pca_pf_waitforcompletion()
88 timeout = jiffies + i2c->adap.timeout; in i2c_pca_pf_waitforcompletion()
91 if (i2c->algo_data.read_byte(i2c, I2C_PCA_CON) in i2c_pca_pf_waitforcompletion()
103 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_dummyreset() local
105 dev_warn(&i2c->adap.dev, "No reset-pin found. Chip may get stuck!\n"); in i2c_pca_pf_dummyreset()
110 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_resetchip() local
112 gpiod_set_value(i2c->gpio, 1); in i2c_pca_pf_resetchip()
114 gpiod_set_value(i2c->gpio, 0); in i2c_pca_pf_resetchip()
119 struct i2c_pca_pf_data *i2c = dev_id; in i2c_pca_pf_handler() local
121 if ((i2c->algo_data.read_byte(i2c, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) in i2c_pca_pf_handler()
124 wake_up(&i2c->wait); in i2c_pca_pf_handler()
132 struct i2c_pca_pf_data *i2c; in i2c_pca_pf_probe() local
135 dev_get_platdata(&pdev->dev); in i2c_pca_pf_probe()
136 struct device_node *np = pdev->dev.of_node; in i2c_pca_pf_probe()
141 /* If irq is 0, we do polling. */ in i2c_pca_pf_probe()
145 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); in i2c_pca_pf_probe()
146 if (!i2c) in i2c_pca_pf_probe()
147 return -ENOMEM; in i2c_pca_pf_probe()
149 i2c->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in i2c_pca_pf_probe()
150 if (IS_ERR(i2c->reg_base)) in i2c_pca_pf_probe()
151 return PTR_ERR(i2c->reg_base); in i2c_pca_pf_probe()
154 init_waitqueue_head(&i2c->wait); in i2c_pca_pf_probe()
156 i2c->irq = irq; in i2c_pca_pf_probe()
158 i2c->adap.nr = pdev->id; in i2c_pca_pf_probe()
159 i2c->adap.owner = THIS_MODULE; in i2c_pca_pf_probe()
160 snprintf(i2c->adap.name, sizeof(i2c->adap.name), in i2c_pca_pf_probe()
162 (unsigned long) res->start); in i2c_pca_pf_probe()
163 i2c->adap.algo_data = &i2c->algo_data; in i2c_pca_pf_probe()
164 i2c->adap.dev.parent = &pdev->dev; in i2c_pca_pf_probe()
165 i2c->adap.dev.of_node = np; in i2c_pca_pf_probe()
167 i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); in i2c_pca_pf_probe()
168 if (IS_ERR(i2c->gpio)) in i2c_pca_pf_probe()
169 return PTR_ERR(i2c->gpio); in i2c_pca_pf_probe()
171 i2c->adap.timeout = HZ; in i2c_pca_pf_probe()
172 ret = device_property_read_u32(&pdev->dev, "clock-frequency", in i2c_pca_pf_probe()
173 &i2c->algo_data.i2c_clock); in i2c_pca_pf_probe()
175 i2c->algo_data.i2c_clock = 59000; in i2c_pca_pf_probe()
178 i2c->adap.timeout = platform_data->timeout; in i2c_pca_pf_probe()
179 i2c->algo_data.i2c_clock = platform_data->i2c_clock_speed; in i2c_pca_pf_probe()
182 i2c->algo_data.data = i2c; in i2c_pca_pf_probe()
183 i2c->algo_data.wait_for_completion = i2c_pca_pf_waitforcompletion; in i2c_pca_pf_probe()
184 if (i2c->gpio) in i2c_pca_pf_probe()
185 i2c->algo_data.reset_chip = i2c_pca_pf_resetchip; in i2c_pca_pf_probe()
187 i2c->algo_data.reset_chip = i2c_pca_pf_dummyreset; in i2c_pca_pf_probe()
189 switch (res->flags & IORESOURCE_MEM_TYPE_MASK) { in i2c_pca_pf_probe()
191 i2c->algo_data.write_byte = i2c_pca_pf_writebyte32; in i2c_pca_pf_probe()
192 i2c->algo_data.read_byte = i2c_pca_pf_readbyte32; in i2c_pca_pf_probe()
195 i2c->algo_data.write_byte = i2c_pca_pf_writebyte16; in i2c_pca_pf_probe()
196 i2c->algo_data.read_byte = i2c_pca_pf_readbyte16; in i2c_pca_pf_probe()
200 i2c->algo_data.write_byte = i2c_pca_pf_writebyte8; in i2c_pca_pf_probe()
201 i2c->algo_data.read_byte = i2c_pca_pf_readbyte8; in i2c_pca_pf_probe()
206 ret = devm_request_irq(&pdev->dev, irq, i2c_pca_pf_handler, in i2c_pca_pf_probe()
207 IRQF_TRIGGER_FALLING, pdev->name, i2c); in i2c_pca_pf_probe()
212 ret = i2c_pca_add_numbered_bus(&i2c->adap); in i2c_pca_pf_probe()
216 platform_set_drvdata(pdev, i2c); in i2c_pca_pf_probe()
218 dev_info(&pdev->dev, "registered.\n"); in i2c_pca_pf_probe()
225 struct i2c_pca_pf_data *i2c = platform_get_drvdata(pdev); in i2c_pca_pf_remove() local
227 i2c_del_adapter(&i2c->adap); in i2c_pca_pf_remove()
243 .name = "i2c-pca-platform",
251 MODULE_DESCRIPTION("I2C-PCA9564/PCA9665 platform driver");