Lines Matching +full:mv64xxx +full:- +full:i2c

1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for the TWSI (i2c) controller found on the Marvell
11 #include <i2c.h>
33 #include <asm/arch/i2c.h>
44 #include <asm/arch/i2c.h>
87 /* Number of the device (determined from cell-index property) */
89 /* The I2C slave address for the device */
91 /* The configured I2C speed in Hz */
99 * enum mvtwsi_ctrl_register_fields - Bit masks for flags in the control
111 /* I2C enable */
118 * On sun6i and newer, IFLG is a write-clear bit, which is cleared by writing 1;
129 * enum mvstwsi_status_values - Possible values of I2C controller's status
133 * non-10-bit-address devices are specified.
161 * enum mvstwsi_ack_flags - Determine whether a read byte should be
172 * calc_tick() - Calculate the duration of a clock cycle from the I2C speed
187 * twsi_get_base() - Get controller register base for specified adapter
194 switch (adap->hwadapnr) { in twsi_get_base()
220 printf("Missing mvtwsi controller %d base\n", adap->hwadapnr); in twsi_get_base()
229 * enum mvtwsi_error_class - types of I2C errors
239 * mvtwsi_error() - Build I2C return code from error information
242 * error into a return code. These error codes are returned from I2C API
260 * twsi_wait() - Wait for I2C bus interrupt flag and check status, or time out.
262 * @return Zero if status is as expected, or a non-zero code if either a time
272 control = readl(&twsi->control); in twsi_wait()
274 status = readl(&twsi->status); in twsi_wait()
283 } while (timeout--); in twsi_wait()
284 status = readl(&twsi->status); in twsi_wait()
290 * twsi_start() - Assert a START condition on the bus.
292 * This function is used in both single I2C transactions and inside
293 * back-to-back transactions (repeated starts).
296 * @expected_status: The I2C bus status expected to be asserted after the
298 * @tick: The duration of a clock cycle at the current I2C speed.
299 * @return Zero if status is as expected, or a non-zero code if either a time
307 MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); in twsi_start()
313 * twsi_send() - Send a byte on the I2C bus.
319 * @expected_status: The I2C bus status expected to be asserted after the
321 * @tick: The duration of a clock cycle at the current I2C speed.
322 * @return Zero if status is as expected, or a non-zero code if either a time
329 writel(byte, &twsi->data); in twsi_send()
330 /* Clear any pending interrupt -- that will cause sending */ in twsi_send()
332 &twsi->control); in twsi_send()
338 * twsi_recv() - Receive a byte on the I2C bus.
346 * @tick: The duration of a clock cycle at the current I2C speed.
347 * @return Zero if status is as expected, or a non-zero code if either a time
361 writel(control | MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); in twsi_recv()
366 *byte = readl(&twsi->data); in twsi_recv()
371 * twsi_stop() - Assert a STOP condition on the bus.
377 * @tick: The duration of a clock cycle at the current I2C speed.
378 * @return Zero if the operation succeeded, or a non-zero code if a time out
389 writel(control | MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); in twsi_stop()
392 stop_status = readl(&twsi->status); in twsi_stop()
396 } while (timeout--); in twsi_stop()
397 control = readl(&twsi->control); in twsi_stop()
405 * twsi_calc_freq() - Compute I2C frequency depending on m and n parameters.
409 * @return The I2C frequency corresponding to the passed m and n parameters.
421 * twsi_reset() - Reset the I2C controller.
424 * they must be re-established after the reset.
431 writel(0, &twsi->soft_reset); in twsi_reset()
432 /* Wait 2 ms -- this is what the Marvell LSP does */ in twsi_reset()
437 * __twsi_i2c_set_bus_speed() - Set the speed of the I2C controller.
467 writel(baud, &twsi->baudrate); in __twsi_i2c_set_bus_speed()
479 * __twsi_i2c_init() - Initialize the I2C controller.
484 * @slaveadd: The I2C address to be set for the I2C master.
487 * @return Zero if the operation succeeded, or a non-zero code if a time out
502 writel(slaveadd, &twsi->slave_address); in __twsi_i2c_init()
503 writel(0, &twsi->xtnd_slave_addr); in __twsi_i2c_init()
513 * i2c_begin() - Start a I2C transaction.
515 * Begin a I2C transaction with a given expected start status and chip address.
516 * A START is asserted, and the address byte is sent to the I2C controller. The
521 * @expected_start_status: The I2C status the controller is expected to
525 * I2C speed.
526 * @return Zero if the operation succeeded, or a non-zero code if a time out or
527 * unexpected I2C status occurred.
550 * __twsi_i2c_probe_chip() - Probe the given I2C chip address.
552 * This function begins a I2C read transaction, does a dummy read and NAKs; if
557 * @tick: The duration of a clock cycle at the current I2C speed.
558 * @return Zero if the operation succeeded, or a non-zero code if a time out or
559 * unexpected I2C status occurred.
567 /* Begin i2c read */ in __twsi_i2c_probe_chip()
579 * __twsi_i2c_read() - Read data from a I2C chip.
581 * This function begins a I2C write transaction, and transmits the address
582 * bytes; then begins a I2C read transaction, and receives the data bytes.
596 * @tick: The duration of a clock cycle at the current I2C speed.
597 * @return Zero if the operation succeeded, or a non-zero code if a time out or
598 * unexpected I2C status occurred.
609 /* Begin i2c write to send the address bytes */ in __twsi_i2c_read()
612 while ((status == 0) && alen--) in __twsi_i2c_read()
618 /* Begin i2c read to receive data bytes */ in __twsi_i2c_read()
623 while ((status == 0) && length--) in __twsi_i2c_read()
634 * __twsi_i2c_write() - Send data to a I2C chip.
636 * This function begins a I2C write transaction, and transmits the address
637 * bytes; then begins a new I2C write transaction, and sends the data bytes.
645 * @tick: The duration of a clock cycle at the current I2C speed.
646 * @return Zero if the operation succeeded, or a non-zero code if a time out or
647 * unexpected I2C status occurred.
655 /* Begin i2c write to send first the address bytes, then the in __twsi_i2c_write()
659 while ((status == 0) && (alen-- > 0)) in __twsi_i2c_write()
663 while ((status == 0) && (length-- > 0)) in __twsi_i2c_write()
771 return __twsi_i2c_probe_chip(dev->base, chip_addr, dev->tick);
778 dev->speed = __twsi_i2c_set_bus_speed(dev->base, speed);
779 dev->tick = calc_tick(dev->speed);
788 dev->base = devfdt_get_addr_ptr(bus);
790 if (!dev->base)
791 return -ENOMEM;
793 dev->index = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
794 "cell-index", -1);
795 dev->slaveadd = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
796 "u-boot,i2c-slave-addr", 0x0);
797 dev->speed = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
798 "clock-frequency", 100000);
804 clrbits_le32(&twsi->debug, BIT(18));
813 && bus->req_seq == 0)
824 __twsi_i2c_init(dev->base, dev->speed, dev->slaveadd, &actual_speed);
825 dev->speed = actual_speed;
826 dev->tick = calc_tick(dev->speed);
841 return -1;
847 if (dmsg->flags & I2C_M_RD)
848 return __twsi_i2c_read(dev->base, dmsg->addr, omsg->buf,
849 omsg->len, dmsg->buf, dmsg->len,
850 dev->tick);
852 return __twsi_i2c_write(dev->base, dmsg->addr, omsg->buf,
853 omsg->len, dmsg->buf, dmsg->len,
854 dev->tick);
864 { .compatible = "marvell,mv64xxx-i2c", },
865 { .compatible = "marvell,mv78230-i2c", },
866 { .compatible = "allwinner,sun6i-a31-i2c", },