Lines Matching +full:current +full:- +full:speed
8 * SPDX-License-Identifier: GPL-2.0+
84 /* Number of the device (determined from cell-index property) */
88 /* The configured I2C speed in Hz */
89 uint speed; member
90 /* The current length of a clock period (depending on speed) */
96 * enum mvtwsi_ctrl_register_fields - Bit masks for flags in the control
115 * On sun6i and newer, IFLG is a write-clear bit, which is cleared by writing 1;
126 * enum mvstwsi_status_values - Possible values of I2C controller's status
130 * non-10-bit-address devices are specified.
158 * enum mvstwsi_ack_flags - Determine whether a read byte should be
169 * calc_tick() - Calculate the duration of a clock cycle from the I2C speed
171 * @speed: The speed in Hz to calculate the clock cycle duration for.
174 inline uint calc_tick(uint speed) in calc_tick() argument
176 /* One tick = the duration of a period at the specified speed in ns (we in calc_tick()
178 return (1000000000u / speed) + 100; in calc_tick()
184 * twsi_get_base() - Get controller register base for specified adapter
191 switch (adap->hwadapnr) { in twsi_get_base()
217 printf("Missing mvtwsi controller %d base\n", adap->hwadapnr); in twsi_get_base()
226 * enum mvtwsi_error_class - types of I2C errors
236 * mvtwsi_error() - Build I2C return code from error information
257 * twsi_wait() - Wait for I2C bus interrupt flag and check status, or time out.
259 * @return Zero if status is as expected, or a non-zero code if either a time
269 control = readl(&twsi->control); in twsi_wait()
271 status = readl(&twsi->status); in twsi_wait()
280 } while (timeout--); in twsi_wait()
281 status = readl(&twsi->status); in twsi_wait()
287 * twsi_start() - Assert a START condition on the bus.
290 * back-to-back transactions (repeated starts).
295 * @tick: The duration of a clock cycle at the current I2C speed.
296 * @return Zero if status is as expected, or a non-zero code if either a time
304 MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); in twsi_start()
310 * twsi_send() - Send a byte on the I2C bus.
318 * @tick: The duration of a clock cycle at the current I2C speed.
319 * @return Zero if status is as expected, or a non-zero code if either a time
326 writel(byte, &twsi->data); in twsi_send()
327 /* Clear any pending interrupt -- that will cause sending */ in twsi_send()
329 &twsi->control); in twsi_send()
335 * twsi_recv() - Receive a byte on the I2C bus.
343 * @tick: The duration of a clock cycle at the current I2C speed.
344 * @return Zero if status is as expected, or a non-zero code if either a time
358 writel(control | MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); in twsi_recv()
363 *byte = readl(&twsi->data); in twsi_recv()
368 * twsi_stop() - Assert a STOP condition on the bus.
374 * @tick: The duration of a clock cycle at the current I2C speed.
375 * @return Zero if the operation succeeded, or a non-zero code if a time out
386 writel(control | MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); in twsi_stop()
389 stop_status = readl(&twsi->status); in twsi_stop()
393 } while (timeout--); in twsi_stop()
394 control = readl(&twsi->control); in twsi_stop()
402 * twsi_calc_freq() - Compute I2C frequency depending on m and n parameters.
418 * twsi_reset() - Reset the I2C controller.
421 * they must be re-established after the reset.
428 writel(0, &twsi->soft_reset); in twsi_reset()
429 /* Wait 2 ms -- this is what the Marvell LSP does */ in twsi_reset()
434 * __twsi_i2c_set_bus_speed() - Set the speed of the I2C controller.
452 * resulting in the largest speed that's not above the requested in __twsi_i2c_set_bus_speed()
453 * speed */ in __twsi_i2c_set_bus_speed()
464 writel(baud, &twsi->baudrate); in __twsi_i2c_set_bus_speed()
476 * __twsi_i2c_init() - Initialize the I2C controller.
479 * @speed: The initial frequency the controller should run at
484 * @return Zero if the operation succeeded, or a non-zero code if a time out
487 static void __twsi_i2c_init(struct mvtwsi_registers *twsi, int speed, in __twsi_i2c_init() argument
492 /* Set speed */ in __twsi_i2c_init()
493 *actual_speed = __twsi_i2c_set_bus_speed(twsi, speed); in __twsi_i2c_init()
495 writel(slaveadd, &twsi->slave_address); in __twsi_i2c_init()
496 writel(0, &twsi->xtnd_slave_addr); in __twsi_i2c_init()
506 * i2c_begin() - Start a I2C transaction.
517 * @tick: The duration of a clock cycle at the current
518 * I2C speed.
519 * @return Zero if the operation succeeded, or a non-zero code if a time out or
543 * __twsi_i2c_probe_chip() - Probe the given I2C chip address.
550 * @tick: The duration of a clock cycle at the current I2C speed.
551 * @return Zero if the operation succeeded, or a non-zero code if a time out or
572 * __twsi_i2c_read() - Read data from a I2C chip.
589 * @tick: The duration of a clock cycle at the current I2C speed.
590 * @return Zero if the operation succeeded, or a non-zero code if a time out or
605 while ((status == 0) && alen--) in __twsi_i2c_read()
616 while ((status == 0) && length--) in __twsi_i2c_read()
627 * __twsi_i2c_write() - Send data to a I2C chip.
638 * @tick: The duration of a clock cycle at the current I2C speed.
639 * @return Zero if the operation succeeded, or a non-zero code if a time out or
652 while ((status == 0) && (alen-- > 0)) in __twsi_i2c_write()
656 while ((status == 0) && (length-- > 0)) in __twsi_i2c_write()
666 static void twsi_i2c_init(struct i2c_adapter *adap, int speed, in twsi_i2c_init() argument
670 __twsi_i2c_init(twsi, speed, slaveadd, NULL); in twsi_i2c_init()
764 return __twsi_i2c_probe_chip(dev->base, chip_addr, dev->tick);
767 static int mvtwsi_i2c_set_bus_speed(struct udevice *bus, uint speed)
771 dev->speed = __twsi_i2c_set_bus_speed(dev->base, speed);
772 dev->tick = calc_tick(dev->speed);
781 dev->base = devfdt_get_addr_ptr(bus);
783 if (!dev->base)
784 return -ENOMEM;
786 dev->index = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
787 "cell-index", -1);
788 dev->slaveadd = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
789 "u-boot,i2c-slave-addr", 0x0);
790 dev->speed = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
791 "clock-frequency", 100000);
800 __twsi_i2c_init(dev->base, dev->speed, dev->slaveadd, &actual_speed);
801 dev->speed = actual_speed;
802 dev->tick = calc_tick(dev->speed);
817 return -1;
823 if (dmsg->flags & I2C_M_RD)
824 return __twsi_i2c_read(dev->base, dmsg->addr, omsg->buf,
825 omsg->len, dmsg->buf, dmsg->len,
826 dev->tick);
828 return __twsi_i2c_write(dev->base, dmsg->addr, omsg->buf,
829 omsg->len, dmsg->buf, dmsg->len,
830 dev->tick);
840 { .compatible = "marvell,mv64xxx-i2c", },
841 { .compatible = "marvell,mv78230-i2c", },
842 { .compatible = "allwinner,sun6i-a31-i2c", },