Lines Matching +full:stop +full:- +full:ack

1 // SPDX-License-Identifier: GPL-2.0+
87 /* Number of the device (determined from cell-index property) */
99 * enum mvtwsi_ctrl_register_fields - Bit masks for flags in the control
107 /* Stop bit */
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.
144 /* Address + write bit transmitted, ACK received */
146 /* Data transmitted, ACK received */
148 /* Address + read bit transmitted, ACK received */
150 /* Address + read bit transmitted, ACK not received */
152 /* Data received, ACK transmitted */
154 /* Data received, ACK not transmitted */
161 * enum mvstwsi_ack_flags - Determine whether a read byte should be
167 /* Send ACK after received byte */
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
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.
293 * back-to-back transactions (repeated starts).
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.
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()
333 /* Wait for controller to receive byte, and check ACK */ in twsi_send()
338 * twsi_recv() - Receive a byte on the I2C bus.
340 * The static variable mvtwsi_control_flags controls whether we ack or nak.
345 * be acknowledged by the controller or not (sent ACK/NAK).
347 * @return Zero if status is as expected, or a non-zero code if either a time
355 /* Compute expected status based on passed ACK flag */ in twsi_recv()
361 writel(control | MVTWSI_CONTROL_CLEAR_IFLG, &twsi->control); in twsi_recv()
362 /* Wait for controller to receive byte, and assert ACK or NAK */ in twsi_recv()
366 *byte = readl(&twsi->data); in twsi_recv()
371 * twsi_stop() - Assert a STOP condition on the bus.
378 * @return Zero if the operation succeeded, or a non-zero code if a time out
387 /* Assert STOP */ in twsi_stop()
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.
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.
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()
504 /* Assert STOP, but don't care for the result */ in __twsi_i2c_init()
513 * i2c_begin() - Start a I2C transaction.
526 * @return Zero if the operation succeeded, or a non-zero code if a time out or
550 * __twsi_i2c_probe_chip() - Probe the given I2C chip address.
558 * @return Zero if the operation succeeded, or a non-zero code if a time out or
572 /* Stop transaction */ in __twsi_i2c_probe_chip()
579 * __twsi_i2c_read() - Read data from a I2C chip.
584 * NOTE: Some devices want a stop right before the second start, while some
587 * will be a repeated start without a preceding stop.
597 * @return Zero if the operation succeeded, or a non-zero code if a time out or
612 while ((status == 0) && alen--) in __twsi_i2c_read()
623 while ((status == 0) && length--) in __twsi_i2c_read()
627 /* Stop transaction */ in __twsi_i2c_read()
634 * __twsi_i2c_write() - Send data to a I2C chip.
646 * @return Zero if the operation succeeded, or a non-zero code if a time out or
659 while ((status == 0) && (alen-- > 0)) in __twsi_i2c_write()
663 while ((status == 0) && (length-- > 0)) in __twsi_i2c_write()
666 /* Stop transaction */ 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", },