Lines Matching full:i2c
3 * I2C bus driver for Kontron COM modules
8 * The driver is based on the i2c-ocores driver by Peter Korsgaard.
13 #include <linux/i2c.h>
68 MODULE_PARM_DESC(bus_frequency, "Set I2C bus frequency in kHz (default="
73 MODULE_PARM_DESC(i2c_bus, "Set I2C bus number (default=-1 for dynamic assignment)");
77 MODULE_PARM_DESC(i2c_gpio_mux, "Enable I2C port on GPIO out (default=false)");
82 static int kempld_i2c_process(struct kempld_i2c_data *i2c) in kempld_i2c_process() argument
84 struct kempld_device_data *pld = i2c->pld; in kempld_i2c_process()
86 struct i2c_msg *msg = i2c->msg; in kempld_i2c_process()
93 if (i2c->state == STATE_DONE || i2c->state == STATE_ERROR) { in kempld_i2c_process()
96 if (i2c->state == STATE_ERROR) in kempld_i2c_process()
103 i2c->state = STATE_ERROR; in kempld_i2c_process()
108 if (i2c->state == STATE_INIT) { in kempld_i2c_process()
112 i2c->state = STATE_ADDR; in kempld_i2c_process()
115 if (i2c->state == STATE_ADDR) { in kempld_i2c_process()
117 if (i2c->msg->flags & I2C_M_TEN) { in kempld_i2c_process()
118 addr = 0xf0 | ((i2c->msg->addr >> 7) & 0x6); in kempld_i2c_process()
120 addr |= (i2c->msg->flags & I2C_M_RD) ? 1 : 0; in kempld_i2c_process()
121 i2c->state = STATE_ADDR10; in kempld_i2c_process()
123 addr = i2c_8bit_addr_from_msg(i2c->msg); in kempld_i2c_process()
124 i2c->state = STATE_START; in kempld_i2c_process()
134 if (i2c->state == STATE_ADDR10) { in kempld_i2c_process()
135 kempld_write8(pld, KEMPLD_I2C_DATA, i2c->msg->addr & 0xff); in kempld_i2c_process()
138 i2c->state = STATE_START; in kempld_i2c_process()
142 if (i2c->state == STATE_START || i2c->state == STATE_WRITE) { in kempld_i2c_process()
143 i2c->state = (msg->flags & I2C_M_RD) ? STATE_READ : STATE_WRITE; in kempld_i2c_process()
146 i2c->state = STATE_ERROR; in kempld_i2c_process()
151 msg->buf[i2c->pos++] = kempld_read8(pld, KEMPLD_I2C_DATA); in kempld_i2c_process()
154 if (i2c->pos >= msg->len) { in kempld_i2c_process()
155 i2c->nmsgs--; in kempld_i2c_process()
156 i2c->msg++; in kempld_i2c_process()
157 i2c->pos = 0; in kempld_i2c_process()
158 msg = i2c->msg; in kempld_i2c_process()
160 if (i2c->nmsgs) { in kempld_i2c_process()
162 i2c->state = STATE_ADDR; in kempld_i2c_process()
165 i2c->state = (msg->flags & I2C_M_RD) in kempld_i2c_process()
169 i2c->state = STATE_DONE; in kempld_i2c_process()
175 if (i2c->state == STATE_READ) { in kempld_i2c_process()
176 kempld_write8(pld, KEMPLD_I2C_CMD, i2c->pos == (msg->len - 1) ? in kempld_i2c_process()
179 kempld_write8(pld, KEMPLD_I2C_DATA, msg->buf[i2c->pos++]); in kempld_i2c_process()
189 struct kempld_i2c_data *i2c = i2c_get_adapdata(adap); in kempld_i2c_xfer() local
190 struct kempld_device_data *pld = i2c->pld; in kempld_i2c_xfer()
194 i2c->msg = msgs; in kempld_i2c_xfer()
195 i2c->pos = 0; in kempld_i2c_xfer()
196 i2c->nmsgs = num; in kempld_i2c_xfer()
197 i2c->state = STATE_INIT; in kempld_i2c_xfer()
202 ret = kempld_i2c_process(i2c); in kempld_i2c_xfer()
205 if (i2c->state == STATE_DONE || i2c->state == STATE_ERROR) in kempld_i2c_xfer()
206 return (i2c->state == STATE_DONE) ? num : ret; in kempld_i2c_xfer()
214 i2c->state = STATE_ERROR; in kempld_i2c_xfer()
222 static void kempld_i2c_device_init(struct kempld_i2c_data *i2c) in kempld_i2c_device_init() argument
224 struct kempld_device_data *pld = i2c->pld; in kempld_i2c_device_init()
255 /* Activate I2C bus output on GPIO pins */ in kempld_i2c_device_init()
285 .name = "i2c-kempld",
293 struct kempld_i2c_data *i2c; in kempld_i2c_probe() local
297 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); in kempld_i2c_probe()
298 if (!i2c) in kempld_i2c_probe()
301 i2c->pld = pld; in kempld_i2c_probe()
302 i2c->dev = &pdev->dev; in kempld_i2c_probe()
303 i2c->adap = kempld_i2c_adapter; in kempld_i2c_probe()
304 i2c->adap.dev.parent = i2c->dev; in kempld_i2c_probe()
305 i2c_set_adapdata(&i2c->adap, i2c); in kempld_i2c_probe()
306 platform_set_drvdata(pdev, i2c); in kempld_i2c_probe()
312 i2c->was_active = true; in kempld_i2c_probe()
314 kempld_i2c_device_init(i2c); in kempld_i2c_probe()
317 /* Add I2C adapter to I2C tree */ in kempld_i2c_probe()
319 i2c->adap.nr = i2c_bus; in kempld_i2c_probe()
320 ret = i2c_add_numbered_adapter(&i2c->adap); in kempld_i2c_probe()
324 dev_info(i2c->dev, "I2C bus initialized at %dkHz\n", in kempld_i2c_probe()
332 struct kempld_i2c_data *i2c = platform_get_drvdata(pdev); in kempld_i2c_remove() local
333 struct kempld_device_data *pld = i2c->pld; in kempld_i2c_remove()
338 * Disable I2C logic if it was not activated before the in kempld_i2c_remove()
341 if (!i2c->was_active) { in kempld_i2c_remove()
348 i2c_del_adapter(&i2c->adap); in kempld_i2c_remove()
356 struct kempld_i2c_data *i2c = platform_get_drvdata(pdev); in kempld_i2c_suspend() local
357 struct kempld_device_data *pld = i2c->pld; in kempld_i2c_suspend()
371 struct kempld_i2c_data *i2c = platform_get_drvdata(pdev); in kempld_i2c_resume() local
372 struct kempld_device_data *pld = i2c->pld; in kempld_i2c_resume()
375 kempld_i2c_device_init(i2c); in kempld_i2c_resume()
387 .name = "kempld-i2c",
397 MODULE_DESCRIPTION("KEM PLD I2C Driver");