Lines Matching +full:clock +full:- +full:duration +full:- +full:ns

1 // SPDX-License-Identifier: GPL-2.0
14 #define KI2C "i2c-keba"
77 ret = readb_poll_timeout(ki2c->base + KI2C_STATUS_REG, in ki2c_inuse_lock()
81 dev_err(&ki2c->auxdev->auxdev.dev, "%s err!\n", __func__); in ki2c_inuse_lock()
89 iowrite8(KI2C_STATUS_IN_USE, ki2c->base + KI2C_STATUS_REG); in ki2c_inuse_unlock()
102 return ki2c_wait_for_bit(ki2c->base + KI2C_STATUS_REG, KI2C_STATUS_MCF, in ki2c_wait_for_mcf()
103 ki2c->adapter.timeout); in ki2c_wait_for_mcf()
114 return ki2c_wait_for_bit(ki2c->base + KI2C_STATUS_REG, in ki2c_wait_for_data()
116 ki2c->adapter.timeout); in ki2c_wait_for_data()
129 reg = ioread8(ki2c->base + KI2C_STATUS_REG); in ki2c_wait_for_data_ack()
131 return -EIO; in ki2c_wait_for_data_ack()
138 unsigned int reg = ioread8(ki2c->base + KI2C_CAPABILITY_REG); in ki2c_has_capability()
145 unsigned int reg = ioread8(ki2c->base + KI2C_STATUS_DC_REG); in ki2c_get_scl()
153 unsigned int reg = ioread8(ki2c->base + KI2C_STATUS_DC_REG); in ki2c_get_sda()
164 control_dc = ioread8(ki2c->base + KI2C_CONTROL_DC_REG); in ki2c_set_scl()
169 iowrite8(control_dc, ki2c->base + KI2C_CONTROL_DC_REG); in ki2c_set_scl()
173 * Resetting bus bitwise is done by checking SDA and applying clock cycles as
174 * long as SDA is low. 9 clock cycles are applied at most.
176 * Clock cycles are generated and udelay() determines the duration of clock
177 * cycles. Generated clock rate is 100 KHz and so duration of both clock levels
178 * is: delay in ns = (10^6 / 100) / 2
189 iowrite8(0, ki2c->base + KI2C_CONTROL_REG); in ki2c_reset_bus_bitwise()
191 /* generate clock cycles */ in ki2c_reset_bus_bitwise()
198 dev_err(&ki2c->auxdev->auxdev.dev, in ki2c_reset_bus_bitwise()
200 ret = -EBUSY; in ki2c_reset_bus_bitwise()
215 dev_err(&ki2c->auxdev->auxdev.dev, "SDA is still low!\n"); in ki2c_reset_bus_bitwise()
216 ret = -EBUSY; in ki2c_reset_bus_bitwise()
220 iowrite8(KI2C_CONTROL_MEN, ki2c->base + KI2C_CONTROL_REG); in ki2c_reset_bus_bitwise()
231 * the bus. The reason is, that after the 9 clock cycles the EEPROM will be in
241 /* hold data line high for 9 clock cycles */ in ki2c_reset_bus_bytewise()
242 iowrite8(0xFF, ki2c->base + KI2C_DATA_REG); in ki2c_reset_bus_bytewise()
246 ki2c->base + KI2C_CONTROL_REG); in ki2c_reset_bus_bytewise()
249 dev_err(&ki2c->auxdev->auxdev.dev, "Start condition failed\n"); in ki2c_reset_bus_bytewise()
256 ki2c->base + KI2C_CONTROL_REG); in ki2c_reset_bus_bytewise()
259 dev_err(&ki2c->auxdev->auxdev.dev, "Stop condition failed\n"); in ki2c_reset_bus_bytewise()
290 addr = m->addr << 1; in ki2c_write_target_addr()
292 if (m->flags & I2C_M_RD) in ki2c_write_target_addr()
295 iowrite8(addr, ki2c->base + KI2C_DATA_REG); in ki2c_write_target_addr()
310 ki2c->base + KI2C_CONTROL_REG); in ki2c_start_addr()
314 ki2c->base + KI2C_CONTROL_REG); in ki2c_start_addr()
322 dev_dbg(&ki2c->auxdev->auxdev.dev, in ki2c_start_addr()
323 "%s wait for ACK err at 0x%02x!\n", __func__, m->addr); in ki2c_start_addr()
333 if ((m->flags & I2C_M_RD) == 0) { in ki2c_repstart_addr()
334 dev_err(&ki2c->auxdev->auxdev.dev, in ki2c_repstart_addr()
336 return -EINVAL; in ki2c_repstart_addr()
341 ki2c->base + KI2C_CONTROL_REG); in ki2c_repstart_addr()
345 dev_err(&ki2c->auxdev->auxdev.dev, in ki2c_repstart_addr()
346 "%s wait for MCF err at 0x%02x!\n", __func__, m->addr); in ki2c_repstart_addr()
350 /* write target-address byte */ in ki2c_repstart_addr()
355 dev_err(&ki2c->auxdev->auxdev.dev, in ki2c_repstart_addr()
356 "%s wait for ACK err at 0x%02x!\n", __func__, m->addr); in ki2c_repstart_addr()
363 iowrite8(KI2C_CONTROL_MEN, ki2c->base + KI2C_CONTROL_REG); in ki2c_stop()
374 iowrite8(data[i], ki2c->base + KI2C_DATA_REG); in ki2c_write()
395 /* if just one byte => send tx-nack after transfer */ in ki2c_read()
399 iowrite8(control, ki2c->base + KI2C_CONTROL_REG); in ki2c_read()
402 ioread8(ki2c->base + KI2C_DATA_REG); in ki2c_read()
409 if (i == len - 2) in ki2c_read()
410 /* send tx-nack after transfer of last byte */ in ki2c_read()
412 ki2c->base + KI2C_CONTROL_REG); in ki2c_read()
413 else if (i == len - 1) in ki2c_read()
419 ki2c->base + KI2C_CONTROL_REG); in ki2c_read()
422 data[i] = ioread8(ki2c->base + KI2C_DATA_REG); in ki2c_read()
448 if (m->flags & I2C_M_RD) in ki2c_xfer()
449 ret = ki2c_read(ki2c, m->buf, m->len); in ki2c_xfer()
451 ret = ki2c_write(ki2c, m->buf, m->len); in ki2c_xfer()
467 for (i = 0; i < ki2c->client_size; i++) { in ki2c_unregister_devices()
468 struct i2c_client *client = ki2c->client[i]; in ki2c_unregister_devices()
477 struct i2c_board_info *info = ki2c->auxdev->info; in ki2c_register_devices()
481 for (i = 0; i < ki2c->client_size; i++) { in ki2c_register_devices()
486 client = i2c_new_scanned_device(&ki2c->adapter, &info[i], in ki2c_register_devices()
489 ki2c->client[i] = client; in ki2c_register_devices()
490 } else if (PTR_ERR(client) != -ENODEV) { in ki2c_register_devices()
491 ki2c->client_size = i; in ki2c_register_devices()
514 struct device *dev = &auxdev->dev; in ki2c_probe()
521 return -ENOMEM; in ki2c_probe()
522 ki2c->auxdev = container_of(auxdev, struct keba_i2c_auxdev, auxdev); in ki2c_probe()
523 ki2c->client = devm_kcalloc(dev, ki2c->auxdev->info_size, in ki2c_probe()
524 sizeof(*ki2c->client), GFP_KERNEL); in ki2c_probe()
525 if (!ki2c->client) in ki2c_probe()
526 return -ENOMEM; in ki2c_probe()
527 ki2c->client_size = ki2c->auxdev->info_size; in ki2c_probe()
530 ki2c->base = devm_ioremap_resource(dev, &ki2c->auxdev->io); in ki2c_probe()
531 if (IS_ERR(ki2c->base)) in ki2c_probe()
532 return PTR_ERR(ki2c->base); in ki2c_probe()
534 adap = &ki2c->adapter; in ki2c_probe()
535 strscpy(adap->name, "KEBA I2C adapter", sizeof(adap->name)); in ki2c_probe()
536 adap->owner = THIS_MODULE; in ki2c_probe()
537 adap->class = I2C_CLASS_HWMON; in ki2c_probe()
538 adap->algo = &ki2c_algo; in ki2c_probe()
539 adap->dev.parent = dev; in ki2c_probe()
544 iowrite8(KI2C_CONTROL_MEN, ki2c->base + KI2C_CONTROL_REG); in ki2c_probe()
566 iowrite8(KI2C_CONTROL_DISABLE, ki2c->base + KI2C_CONTROL_REG); in ki2c_probe()
577 iowrite8(KI2C_CONTROL_DISABLE, ki2c->base + KI2C_CONTROL_REG); in ki2c_remove()