Lines Matching +full:mv78230 +full:- +full:i2c
2 * Driver for the TWSI (i2c) controller found on the Marvell
8 * SPDX-License-Identifier: GPL-2.0+
12 #include <i2c.h>
33 #include <asm/arch/i2c.h>
44 #include <asm/arch/i2c.h>
84 /* Number of the device (determined from cell-index property) */
86 /* The I2C slave address for the device */
88 /* The configured I2C speed in Hz */
96 * enum mvtwsi_ctrl_register_fields - Bit masks for flags in the control
108 /* I2C enable */
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
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
239 * error into a return code. These error codes are returned from I2C API
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.
289 * This function is used in both single I2C transactions and inside
290 * back-to-back transactions (repeated starts).
293 * @expected_status: The I2C bus status expected to be asserted after the
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.
316 * @expected_status: The I2C bus status expected to be asserted after the
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.
406 * @return The I2C frequency corresponding to the passed 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.
464 writel(baud, &twsi->baudrate); in __twsi_i2c_set_bus_speed()
476 * __twsi_i2c_init() - Initialize the I2C controller.
481 * @slaveadd: The I2C address to be set for the I2C master.
484 * @return Zero if the operation succeeded, or a non-zero code if a time out
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.
508 * Begin a I2C transaction with a given expected start status and chip address.
509 * A START is asserted, and the address byte is sent to the I2C controller. The
514 * @expected_start_status: The I2C status the controller is expected to
518 * I2C speed.
519 * @return Zero if the operation succeeded, or a non-zero code if a time out or
520 * unexpected I2C status occurred.
543 * __twsi_i2c_probe_chip() - Probe the given I2C chip address.
545 * This function begins a I2C read transaction, does a dummy read and NAKs; if
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
552 * unexpected I2C status occurred.
560 /* Begin i2c read */ in __twsi_i2c_probe_chip()
572 * __twsi_i2c_read() - Read data from a I2C chip.
574 * This function begins a I2C write transaction, and transmits the address
575 * bytes; then begins a I2C read transaction, and receives the data bytes.
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
591 * unexpected I2C status occurred.
602 /* Begin i2c write to send the address bytes */ in __twsi_i2c_read()
605 while ((status == 0) && alen--) in __twsi_i2c_read()
611 /* Begin i2c read to receive data bytes */ in __twsi_i2c_read()
616 while ((status == 0) && length--) in __twsi_i2c_read()
627 * __twsi_i2c_write() - Send data to a I2C chip.
629 * This function begins a I2C write transaction, and transmits the address
630 * bytes; then begins a new I2C write transaction, and sends the data bytes.
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
640 * unexpected I2C status occurred.
648 /* Begin i2c write to send first the address bytes, then the in __twsi_i2c_write()
652 while ((status == 0) && (alen-- > 0)) in __twsi_i2c_write()
656 while ((status == 0) && (length-- > 0)) in __twsi_i2c_write()
764 return __twsi_i2c_probe_chip(dev->base, chip_addr, dev->tick);
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", },