X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=drivers%2Fi2c%2Fmvtwsi.c;h=14c594d648ba24ee8f6b1d22db4588450432b88f;hb=5a1a8a63be8f7262a300eddafb18020926b12fb6;hp=ab7481a0d4a9ec80e6d3e792715679b893270424;hpb=4711e7f7af839b41a6d78490257a9e7975494dd3;p=platform%2Fkernel%2Fu-boot.git diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c index ab7481a..14c594d 100644 --- a/drivers/i2c/mvtwsi.c +++ b/drivers/i2c/mvtwsi.c @@ -1,17 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * Driver for the TWSI (i2c) controller found on the Marvell * orion5x and kirkwood SoC families. * * Author: Albert Aribaud * Copyright (c) 2010 Albert Aribaud. - * - * SPDX-License-Identifier: GPL-2.0+ */ #include #include -#include +#include +#include +#include #include +#include #include #ifdef CONFIG_DM_I2C #include @@ -25,11 +27,11 @@ DECLARE_GLOBAL_DATA_PTR; */ #ifndef CONFIG_DM_I2C -#if defined(CONFIG_ORION5X) +#if defined(CONFIG_ARCH_ORION5X) #include -#elif (defined(CONFIG_KIRKWOOD) || defined(CONFIG_ARCH_MVEBU)) +#elif (defined(CONFIG_ARCH_KIRKWOOD) || defined(CONFIG_ARCH_MVEBU)) #include -#elif defined(CONFIG_SUNXI) +#elif defined(CONFIG_ARCH_SUNXI) #include #else #error Driver mvtwsi not supported by SoC or board @@ -37,10 +39,18 @@ DECLARE_GLOBAL_DATA_PTR; #endif /* CONFIG_DM_I2C */ /* + * On SUNXI, we get CONFIG_SYS_TCLK from this include, so we want to + * always have it. + */ +#if defined(CONFIG_DM_I2C) && defined(CONFIG_ARCH_SUNXI) +#include +#endif + +/* * TWSI register structure */ -#ifdef CONFIG_SUNXI +#ifdef CONFIG_ARCH_SUNXI struct mvtwsi_registers { u32 slave_address; @@ -50,6 +60,7 @@ struct mvtwsi_registers { u32 status; u32 baudrate; u32 soft_reset; + u32 debug; /* Dummy field for build compatibility with mvebu */ }; #else @@ -63,8 +74,10 @@ struct mvtwsi_registers { u32 baudrate; /* When writing */ }; u32 xtnd_slave_addr; - u32 reserved[2]; + u32 reserved0[2]; u32 soft_reset; + u32 reserved1[27]; + u32 debug; }; #endif @@ -260,6 +273,17 @@ static int twsi_wait(struct mvtwsi_registers *twsi, int expected_status, do { control = readl(&twsi->control); if (control & MVTWSI_CONTROL_IFLG) { + /* + * On Armada 38x it seems that the controller works as + * if it first set the MVTWSI_CONTROL_IFLAG in the + * control register and only after that it changed the + * status register. + * This sometimes caused weird bugs which only appeared + * on selected I2C speeds and even then only sometimes. + * We therefore add here a simple ndealy(100), which + * seems to fix this weird bug. + */ + ndelay(100); status = readl(&twsi->status); if (status == expected_status) return 0; @@ -399,7 +423,7 @@ static int twsi_stop(struct mvtwsi_registers *twsi, uint tick) */ static uint twsi_calc_freq(const int n, const int m) { -#ifdef CONFIG_SUNXI +#ifdef CONFIG_ARCH_SUNXI return CONFIG_SYS_TCLK / (10 * (m + 1) * (1 << n)); #else return CONFIG_SYS_TCLK / (10 * (m + 1) * (2 << n)); @@ -479,10 +503,14 @@ static uint __twsi_i2c_set_bus_speed(struct mvtwsi_registers *twsi, static void __twsi_i2c_init(struct mvtwsi_registers *twsi, int speed, int slaveadd, uint *actual_speed) { + uint tmp_speed; + /* Reset controller */ twsi_reset(twsi); /* Set speed */ - *actual_speed = __twsi_i2c_set_bus_speed(twsi, speed); + tmp_speed = __twsi_i2c_set_bus_speed(twsi, speed); + if (actual_speed) + *actual_speed = tmp_speed; /* Set slave address; even though we don't use it */ writel(slaveadd, &twsi->slave_address); writel(0, &twsi->xtnd_slave_addr); @@ -595,7 +623,7 @@ static int __twsi_i2c_read(struct mvtwsi_registers *twsi, uchar chip, status = i2c_begin(twsi, expected_start, (chip << 1), tick); /* Send address bytes */ while ((status == 0) && alen--) - status = twsi_send(twsi, *(addr++), + status = twsi_send(twsi, addr[alen], MVTWSI_STATUS_DATA_W_ACK, tick); /* Send repeated STARTs after the initial START */ expected_start = MVTWSI_STATUS_REPEATED_START; @@ -642,7 +670,7 @@ static int __twsi_i2c_write(struct mvtwsi_registers *twsi, uchar chip, status = i2c_begin(twsi, MVTWSI_STATUS_START, (chip << 1), tick); /* Send address bytes */ while ((status == 0) && (alen-- > 0)) - status = twsi_send(twsi, *(addr++), MVTWSI_STATUS_DATA_W_ACK, + status = twsi_send(twsi, addr[alen], MVTWSI_STATUS_DATA_W_ACK, tick); /* Send data bytes */ while ((status == 0) && (length-- > 0)) @@ -770,17 +798,36 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus) { struct mvtwsi_i2c_dev *dev = dev_get_priv(bus); - dev->base = dev_get_addr_ptr(bus); + dev->base = dev_read_addr_ptr(bus); if (!dev->base) return -ENOMEM; - dev->index = fdtdec_get_int(gd->fdt_blob, bus->of_offset, + dev->index = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "cell-index", -1); - dev->slaveadd = fdtdec_get_int(gd->fdt_blob, bus->of_offset, + dev->slaveadd = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "u-boot,i2c-slave-addr", 0x0); - dev->speed = fdtdec_get_int(gd->fdt_blob, bus->of_offset, - "clock-frequency", 100000); + dev->speed = dev_read_u32_default(bus, "clock-frequency", + I2C_SPEED_STANDARD_RATE); + + return 0; +} + +static void twsi_disable_i2c_slave(struct mvtwsi_registers *twsi) +{ + clrbits_le32(&twsi->debug, BIT(18)); +} + +static int mvtwsi_i2c_bind(struct udevice *bus) +{ + struct mvtwsi_registers *twsi = dev_read_addr_ptr(bus); + + /* Disable the hidden slave in i2c0 of these platforms */ + if ((IS_ENABLED(CONFIG_ARMADA_38X) || IS_ENABLED(CONFIG_ARCH_KIRKWOOD) + || IS_ENABLED(CONFIG_ARMADA_8K)) + && bus->req_seq == 0) + twsi_disable_i2c_slave(twsi); + return 0; } @@ -830,6 +877,8 @@ static const struct dm_i2c_ops mvtwsi_i2c_ops = { static const struct udevice_id mvtwsi_i2c_ids[] = { { .compatible = "marvell,mv64xxx-i2c", }, + { .compatible = "marvell,mv78230-i2c", }, + { .compatible = "allwinner,sun6i-a31-i2c", }, { /* sentinel */ } }; @@ -837,6 +886,7 @@ U_BOOT_DRIVER(i2c_mvtwsi) = { .name = "i2c_mvtwsi", .id = UCLASS_I2C, .of_match = mvtwsi_i2c_ids, + .bind = mvtwsi_i2c_bind, .probe = mvtwsi_i2c_probe, .ofdata_to_platdata = mvtwsi_i2c_ofdata_to_platdata, .priv_auto_alloc_size = sizeof(struct mvtwsi_i2c_dev),