Lines Matching +full:current +full:- +full:speed

1 // SPDX-License-Identifier: GPL-2.0+
87 /* Number of the device (determined from cell-index property) */
91 /* The configured I2C speed in Hz */
92 uint speed; member
93 /* The current length of a clock period (depending on speed) */
99 * enum mvtwsi_ctrl_register_fields - Bit masks for flags in the control
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
174 * @speed: The speed in Hz to calculate the clock cycle duration for.
177 inline uint calc_tick(uint speed) in calc_tick() argument
179 /* One tick = the duration of a period at the specified speed in ns (we in calc_tick()
181 return (1000000000u / speed) + 100; in calc_tick()
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).
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.
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.
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.
455 * resulting in the largest speed that's not above the requested in __twsi_i2c_set_bus_speed()
456 * speed */ in __twsi_i2c_set_bus_speed()
467 writel(baud, &twsi->baudrate); in __twsi_i2c_set_bus_speed()
479 * __twsi_i2c_init() - Initialize the I2C controller.
482 * @speed: The initial frequency the controller should run at
487 * @return Zero if the operation succeeded, or a non-zero code if a time out
490 static void __twsi_i2c_init(struct mvtwsi_registers *twsi, int speed, in __twsi_i2c_init() argument
497 /* Set speed */ in __twsi_i2c_init()
498 tmp_speed = __twsi_i2c_set_bus_speed(twsi, speed); in __twsi_i2c_init()
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.
524 * @tick: The duration of a clock cycle at the current
525 * I2C speed.
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.
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
579 * __twsi_i2c_read() - Read data from a I2C chip.
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
612 while ((status == 0) && alen--) in __twsi_i2c_read()
623 while ((status == 0) && length--) in __twsi_i2c_read()
634 * __twsi_i2c_write() - Send data to a I2C chip.
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
659 while ((status == 0) && (alen-- > 0)) in __twsi_i2c_write()
663 while ((status == 0) && (length-- > 0)) in __twsi_i2c_write()
673 static void twsi_i2c_init(struct i2c_adapter *adap, int speed, in twsi_i2c_init() argument
677 __twsi_i2c_init(twsi, speed, slaveadd, NULL); in twsi_i2c_init()
771 return __twsi_i2c_probe_chip(dev->base, chip_addr, dev->tick);
774 static int mvtwsi_i2c_set_bus_speed(struct udevice *bus, uint speed)
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", },