Lines Matching +full:i2c +full:- +full:gpio

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>
22 #include <linux/gpio/consumer.h>
32 struct gpio_desc *gpio; member
44 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_readbyte8() local
45 return ioread8(i2c->reg_base + reg); in i2c_pca_pf_readbyte8()
50 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_readbyte16() local
51 return ioread8(i2c->reg_base + reg * 2); in i2c_pca_pf_readbyte16()
56 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_readbyte32() local
57 return ioread8(i2c->reg_base + reg * 4); in i2c_pca_pf_readbyte32()
62 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_writebyte8() local
63 iowrite8(val, i2c->reg_base + reg); in i2c_pca_pf_writebyte8()
68 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_writebyte16() local
69 iowrite8(val, i2c->reg_base + reg * 2); in i2c_pca_pf_writebyte16()
74 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_writebyte32() local
75 iowrite8(val, i2c->reg_base + reg * 4); in i2c_pca_pf_writebyte32()
81 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_waitforcompletion() local
85 if (i2c->irq) { in i2c_pca_pf_waitforcompletion()
86 ret = wait_event_timeout(i2c->wait, in i2c_pca_pf_waitforcompletion()
87 i2c->algo_data.read_byte(i2c, I2C_PCA_CON) in i2c_pca_pf_waitforcompletion()
88 & I2C_PCA_CON_SI, i2c->adap.timeout); in i2c_pca_pf_waitforcompletion()
91 timeout = jiffies + i2c->adap.timeout; in i2c_pca_pf_waitforcompletion()
94 if (i2c->algo_data.read_byte(i2c, I2C_PCA_CON) in i2c_pca_pf_waitforcompletion()
106 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_dummyreset() local
108 dev_warn(&i2c->adap.dev, "No reset-pin found. Chip may get stuck!\n"); in i2c_pca_pf_dummyreset()
113 struct i2c_pca_pf_data *i2c = pd; in i2c_pca_pf_resetchip() local
115 gpiod_set_value(i2c->gpio, 1); in i2c_pca_pf_resetchip()
117 gpiod_set_value(i2c->gpio, 0); in i2c_pca_pf_resetchip()
122 struct i2c_pca_pf_data *i2c = dev_id; in i2c_pca_pf_handler() local
124 if ((i2c->algo_data.read_byte(i2c, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) in i2c_pca_pf_handler()
127 wake_up(&i2c->wait); in i2c_pca_pf_handler()
135 struct i2c_pca_pf_data *i2c; in i2c_pca_pf_probe() local
138 dev_get_platdata(&pdev->dev); in i2c_pca_pf_probe()
139 struct device_node *np = pdev->dev.of_node; in i2c_pca_pf_probe()
148 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); in i2c_pca_pf_probe()
149 if (!i2c) in i2c_pca_pf_probe()
150 return -ENOMEM; in i2c_pca_pf_probe()
152 i2c->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in i2c_pca_pf_probe()
153 if (IS_ERR(i2c->reg_base)) in i2c_pca_pf_probe()
154 return PTR_ERR(i2c->reg_base); in i2c_pca_pf_probe()
157 init_waitqueue_head(&i2c->wait); in i2c_pca_pf_probe()
159 i2c->io_base = res->start; in i2c_pca_pf_probe()
160 i2c->io_size = resource_size(res); in i2c_pca_pf_probe()
161 i2c->irq = irq; in i2c_pca_pf_probe()
163 i2c->adap.nr = pdev->id; in i2c_pca_pf_probe()
164 i2c->adap.owner = THIS_MODULE; in i2c_pca_pf_probe()
165 snprintf(i2c->adap.name, sizeof(i2c->adap.name), in i2c_pca_pf_probe()
167 (unsigned long) res->start); in i2c_pca_pf_probe()
168 i2c->adap.algo_data = &i2c->algo_data; in i2c_pca_pf_probe()
169 i2c->adap.dev.parent = &pdev->dev; in i2c_pca_pf_probe()
170 i2c->adap.dev.of_node = np; in i2c_pca_pf_probe()
172 i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); in i2c_pca_pf_probe()
173 if (IS_ERR(i2c->gpio)) in i2c_pca_pf_probe()
174 return PTR_ERR(i2c->gpio); in i2c_pca_pf_probe()
176 i2c->adap.timeout = HZ; in i2c_pca_pf_probe()
177 ret = device_property_read_u32(&pdev->dev, "clock-frequency", in i2c_pca_pf_probe()
178 &i2c->algo_data.i2c_clock); in i2c_pca_pf_probe()
180 i2c->algo_data.i2c_clock = 59000; in i2c_pca_pf_probe()
183 i2c->adap.timeout = platform_data->timeout; in i2c_pca_pf_probe()
184 i2c->algo_data.i2c_clock = platform_data->i2c_clock_speed; in i2c_pca_pf_probe()
187 i2c->algo_data.data = i2c; in i2c_pca_pf_probe()
188 i2c->algo_data.wait_for_completion = i2c_pca_pf_waitforcompletion; in i2c_pca_pf_probe()
189 if (i2c->gpio) in i2c_pca_pf_probe()
190 i2c->algo_data.reset_chip = i2c_pca_pf_resetchip; in i2c_pca_pf_probe()
192 i2c->algo_data.reset_chip = i2c_pca_pf_dummyreset; in i2c_pca_pf_probe()
194 switch (res->flags & IORESOURCE_MEM_TYPE_MASK) { in i2c_pca_pf_probe()
196 i2c->algo_data.write_byte = i2c_pca_pf_writebyte32; in i2c_pca_pf_probe()
197 i2c->algo_data.read_byte = i2c_pca_pf_readbyte32; in i2c_pca_pf_probe()
200 i2c->algo_data.write_byte = i2c_pca_pf_writebyte16; in i2c_pca_pf_probe()
201 i2c->algo_data.read_byte = i2c_pca_pf_readbyte16; in i2c_pca_pf_probe()
205 i2c->algo_data.write_byte = i2c_pca_pf_writebyte8; in i2c_pca_pf_probe()
206 i2c->algo_data.read_byte = i2c_pca_pf_readbyte8; in i2c_pca_pf_probe()
211 ret = devm_request_irq(&pdev->dev, irq, i2c_pca_pf_handler, in i2c_pca_pf_probe()
212 IRQF_TRIGGER_FALLING, pdev->name, i2c); in i2c_pca_pf_probe()
217 ret = i2c_pca_add_numbered_bus(&i2c->adap); in i2c_pca_pf_probe()
221 platform_set_drvdata(pdev, i2c); in i2c_pca_pf_probe()
223 dev_info(&pdev->dev, "registered.\n"); in i2c_pca_pf_probe()
230 struct i2c_pca_pf_data *i2c = platform_get_drvdata(pdev); in i2c_pca_pf_remove() local
232 i2c_del_adapter(&i2c->adap); in i2c_pca_pf_remove()
250 .name = "i2c-pca-platform",
258 MODULE_DESCRIPTION("I2C-PCA9564/PCA9665 platform driver");