diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/clk/uniphier/clk-uniphier-mio.c | 4 | ||||
-rw-r--r-- | drivers/core/device.c | 5 | ||||
-rw-r--r-- | drivers/dfu/dfu_ram.c | 21 | ||||
-rw-r--r-- | drivers/i2c/designware_i2c.c | 448 | ||||
-rw-r--r-- | drivers/i2c/designware_i2c.h | 68 | ||||
-rw-r--r-- | drivers/mmc/pci_mmc.c | 2 | ||||
-rw-r--r-- | drivers/mmc/pic32_sdhci.c | 2 | ||||
-rw-r--r-- | drivers/mmc/zynq_sdhci.c | 2 | ||||
-rw-r--r-- | drivers/mtd/spi/spi_flash.c | 3 | ||||
-rw-r--r-- | drivers/mtd/ubi/wl.c | 2 | ||||
-rw-r--r-- | drivers/pci/pci-uclass.c | 2 | ||||
-rw-r--r-- | drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c | 8 | ||||
-rw-r--r-- | drivers/pinctrl/uniphier/pinctrl-uniphier-ld4.c | 34 | ||||
-rw-r--r-- | drivers/pinctrl/uniphier/pinctrl-uniphier-ld6b.c | 34 | ||||
-rw-r--r-- | drivers/pinctrl/uniphier/pinctrl-uniphier-pro4.c | 34 | ||||
-rw-r--r-- | drivers/pinctrl/uniphier/pinctrl-uniphier-pro5.c | 34 | ||||
-rw-r--r-- | drivers/pinctrl/uniphier/pinctrl-uniphier-pxs2.c | 34 | ||||
-rw-r--r-- | drivers/pinctrl/uniphier/pinctrl-uniphier-sld8.c | 34 | ||||
-rw-r--r-- | drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c | 6 | ||||
-rw-r--r-- | drivers/usb/gadget/f_fastboot.c | 104 |
20 files changed, 559 insertions, 322 deletions
diff --git a/drivers/clk/uniphier/clk-uniphier-mio.c b/drivers/clk/uniphier/clk-uniphier-mio.c index d91ae34..a2b0e80 100644 --- a/drivers/clk/uniphier/clk-uniphier-mio.c +++ b/drivers/clk/uniphier/clk-uniphier-mio.c @@ -164,6 +164,10 @@ static const struct udevice_id uniphier_mio_clk_match[] = { .compatible = "socionext,proxstream2-mioctrl", .data = (ulong)&uniphier_mio_clk_data, }, + { + .compatible = "socionext,ph1-ld20-mioctrl", + .data = (ulong)&uniphier_mio_clk_data, + }, { /* sentinel */ } }; diff --git a/drivers/core/device.c b/drivers/core/device.c index 269087a..1322991 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -673,6 +673,11 @@ fdt_addr_t dev_get_addr(struct udevice *dev) return dev_get_addr_index(dev, 0); } +void *dev_get_addr_ptr(struct udevice *dev) +{ + return (void *)(uintptr_t)dev_get_addr_index(dev, 0); +} + bool device_has_children(struct udevice *dev) { return !list_empty(&dev->child_head); diff --git a/drivers/dfu/dfu_ram.c b/drivers/dfu/dfu_ram.c index e094a94..c1b0021 100644 --- a/drivers/dfu/dfu_ram.c +++ b/drivers/dfu/dfu_ram.c @@ -54,19 +54,26 @@ static int dfu_read_medium_ram(struct dfu_entity *dfu, u64 offset, int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) { - char *st; + const char *argv[3]; + const char **parg = argv; + + for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { + *parg = strsep(&s, " "); + if (*parg == NULL) { + error("Invalid number of arguments.\n"); + return -ENODEV; + } + } dfu->dev_type = DFU_DEV_RAM; - st = strsep(&s, " "); - if (strcmp(st, "ram")) { - error("unsupported device: %s\n", st); + if (strcmp(argv[0], "ram")) { + error("unsupported device: %s\n", argv[0]); return -ENODEV; } dfu->layout = DFU_RAM_ADDR; - dfu->data.ram.start = (void *)simple_strtoul(s, &s, 16); - s++; - dfu->data.ram.size = simple_strtoul(s, &s, 16); + dfu->data.ram.start = (void *)simple_strtoul(argv[1], NULL, 16); + dfu->data.ram.size = simple_strtoul(argv[2], NULL, 16); dfu->write_medium = dfu_write_medium_ram; dfu->get_medium_size = dfu_get_medium_size_ram; diff --git a/drivers/i2c/designware_i2c.c b/drivers/i2c/designware_i2c.c index e768cde..0c7cd0b 100644 --- a/drivers/i2c/designware_i2c.c +++ b/drivers/i2c/designware_i2c.c @@ -6,165 +6,154 @@ */ #include <common.h> +#include <dm.h> #include <i2c.h> +#include <pci.h> #include <asm/io.h> #include "designware_i2c.h" -static struct i2c_regs *i2c_get_base(struct i2c_adapter *adap) -{ - switch (adap->hwadapnr) { -#if CONFIG_SYS_I2C_BUS_MAX >= 4 - case 3: - return (struct i2c_regs *)CONFIG_SYS_I2C_BASE3; +struct dw_scl_sda_cfg { + u32 ss_hcnt; + u32 fs_hcnt; + u32 ss_lcnt; + u32 fs_lcnt; + u32 sda_hold; +}; + +#ifdef CONFIG_X86 +/* BayTrail HCNT/LCNT/SDA hold time */ +static struct dw_scl_sda_cfg byt_config = { + .ss_hcnt = 0x200, + .fs_hcnt = 0x55, + .ss_lcnt = 0x200, + .fs_lcnt = 0x99, + .sda_hold = 0x6, +}; #endif -#if CONFIG_SYS_I2C_BUS_MAX >= 3 - case 2: - return (struct i2c_regs *)CONFIG_SYS_I2C_BASE2; -#endif -#if CONFIG_SYS_I2C_BUS_MAX >= 2 - case 1: - return (struct i2c_regs *)CONFIG_SYS_I2C_BASE1; -#endif - case 0: - return (struct i2c_regs *)CONFIG_SYS_I2C_BASE; - default: - printf("Wrong I2C-adapter number %d\n", adap->hwadapnr); - } - return NULL; +struct dw_i2c { + struct i2c_regs *regs; + struct dw_scl_sda_cfg *scl_sda_cfg; +}; + +static void dw_i2c_enable(struct i2c_regs *i2c_base, bool enable) +{ + u32 ena = enable ? IC_ENABLE_0B : 0; + int timeout = 100; + + do { + writel(ena, &i2c_base->ic_enable); + if ((readl(&i2c_base->ic_enable_status) & IC_ENABLE_0B) == ena) + return; + + /* + * Wait 10 times the signaling period of the highest I2C + * transfer supported by the driver (for 400KHz this is + * 25us) as described in the DesignWare I2C databook. + */ + udelay(25); + } while (timeout--); + + printf("timeout in %sabling I2C adapter\n", enable ? "en" : "dis"); } /* - * set_speed - Set the i2c speed mode (standard, high, fast) - * @i2c_spd: required i2c speed mode + * i2c_set_bus_speed - Set the i2c speed + * @speed: required i2c speed * - * Set the i2c speed mode (standard, high, fast) + * Set the i2c speed. */ -static void set_speed(struct i2c_adapter *adap, int i2c_spd) +static unsigned int __dw_i2c_set_bus_speed(struct i2c_regs *i2c_base, + struct dw_scl_sda_cfg *scl_sda_cfg, + unsigned int speed) { - struct i2c_regs *i2c_base = i2c_get_base(adap); unsigned int cntl; unsigned int hcnt, lcnt; - unsigned int enbl; + int i2c_spd; + + if (speed >= I2C_MAX_SPEED) + i2c_spd = IC_SPEED_MODE_MAX; + else if (speed >= I2C_FAST_SPEED) + i2c_spd = IC_SPEED_MODE_FAST; + else + i2c_spd = IC_SPEED_MODE_STANDARD; /* to set speed cltr must be disabled */ - enbl = readl(&i2c_base->ic_enable); - enbl &= ~IC_ENABLE_0B; - writel(enbl, &i2c_base->ic_enable); + dw_i2c_enable(i2c_base, false); cntl = (readl(&i2c_base->ic_con) & (~IC_CON_SPD_MSK)); switch (i2c_spd) { +#ifndef CONFIG_X86 /* No High-speed for BayTrail yet */ case IC_SPEED_MODE_MAX: - cntl |= IC_CON_SPD_HS; - hcnt = (IC_CLK * MIN_HS_SCL_HIGHTIME) / NANO_TO_MICRO; + cntl |= IC_CON_SPD_SS; + if (scl_sda_cfg) { + hcnt = scl_sda_cfg->fs_hcnt; + lcnt = scl_sda_cfg->fs_lcnt; + } else { + hcnt = (IC_CLK * MIN_HS_SCL_HIGHTIME) / NANO_TO_MICRO; + lcnt = (IC_CLK * MIN_HS_SCL_LOWTIME) / NANO_TO_MICRO; + } writel(hcnt, &i2c_base->ic_hs_scl_hcnt); - lcnt = (IC_CLK * MIN_HS_SCL_LOWTIME) / NANO_TO_MICRO; writel(lcnt, &i2c_base->ic_hs_scl_lcnt); break; +#endif case IC_SPEED_MODE_STANDARD: cntl |= IC_CON_SPD_SS; - hcnt = (IC_CLK * MIN_SS_SCL_HIGHTIME) / NANO_TO_MICRO; + if (scl_sda_cfg) { + hcnt = scl_sda_cfg->ss_hcnt; + lcnt = scl_sda_cfg->ss_lcnt; + } else { + hcnt = (IC_CLK * MIN_SS_SCL_HIGHTIME) / NANO_TO_MICRO; + lcnt = (IC_CLK * MIN_SS_SCL_LOWTIME) / NANO_TO_MICRO; + } writel(hcnt, &i2c_base->ic_ss_scl_hcnt); - lcnt = (IC_CLK * MIN_SS_SCL_LOWTIME) / NANO_TO_MICRO; writel(lcnt, &i2c_base->ic_ss_scl_lcnt); break; case IC_SPEED_MODE_FAST: default: cntl |= IC_CON_SPD_FS; - hcnt = (IC_CLK * MIN_FS_SCL_HIGHTIME) / NANO_TO_MICRO; + if (scl_sda_cfg) { + hcnt = scl_sda_cfg->fs_hcnt; + lcnt = scl_sda_cfg->fs_lcnt; + } else { + hcnt = (IC_CLK * MIN_FS_SCL_HIGHTIME) / NANO_TO_MICRO; + lcnt = (IC_CLK * MIN_FS_SCL_LOWTIME) / NANO_TO_MICRO; + } writel(hcnt, &i2c_base->ic_fs_scl_hcnt); - lcnt = (IC_CLK * MIN_FS_SCL_LOWTIME) / NANO_TO_MICRO; writel(lcnt, &i2c_base->ic_fs_scl_lcnt); break; } writel(cntl, &i2c_base->ic_con); - /* Enable back i2c now speed set */ - enbl |= IC_ENABLE_0B; - writel(enbl, &i2c_base->ic_enable); -} - -/* - * i2c_set_bus_speed - Set the i2c speed - * @speed: required i2c speed - * - * Set the i2c speed. - */ -static unsigned int dw_i2c_set_bus_speed(struct i2c_adapter *adap, - unsigned int speed) -{ - int i2c_spd; - - if (speed >= I2C_MAX_SPEED) - i2c_spd = IC_SPEED_MODE_MAX; - else if (speed >= I2C_FAST_SPEED) - i2c_spd = IC_SPEED_MODE_FAST; - else - i2c_spd = IC_SPEED_MODE_STANDARD; + /* Configure SDA Hold Time if required */ + if (scl_sda_cfg) + writel(scl_sda_cfg->sda_hold, &i2c_base->ic_sda_hold); - set_speed(adap, i2c_spd); - adap->speed = speed; + /* Enable back i2c now speed set */ + dw_i2c_enable(i2c_base, true); return 0; } /* - * i2c_init - Init function - * @speed: required i2c speed - * @slaveaddr: slave address for the device - * - * Initialization function. - */ -static void dw_i2c_init(struct i2c_adapter *adap, int speed, - int slaveaddr) -{ - struct i2c_regs *i2c_base = i2c_get_base(adap); - unsigned int enbl; - - /* Disable i2c */ - enbl = readl(&i2c_base->ic_enable); - enbl &= ~IC_ENABLE_0B; - writel(enbl, &i2c_base->ic_enable); - - writel((IC_CON_SD | IC_CON_SPD_FS | IC_CON_MM), &i2c_base->ic_con); - writel(IC_RX_TL, &i2c_base->ic_rx_tl); - writel(IC_TX_TL, &i2c_base->ic_tx_tl); - dw_i2c_set_bus_speed(adap, speed); - writel(IC_STOP_DET, &i2c_base->ic_intr_mask); - writel(slaveaddr, &i2c_base->ic_sar); - - /* Enable i2c */ - enbl = readl(&i2c_base->ic_enable); - enbl |= IC_ENABLE_0B; - writel(enbl, &i2c_base->ic_enable); -} - -/* * i2c_setaddress - Sets the target slave address * @i2c_addr: target i2c address * * Sets the target slave address. */ -static void i2c_setaddress(struct i2c_adapter *adap, unsigned int i2c_addr) +static void i2c_setaddress(struct i2c_regs *i2c_base, unsigned int i2c_addr) { - struct i2c_regs *i2c_base = i2c_get_base(adap); - unsigned int enbl; - /* Disable i2c */ - enbl = readl(&i2c_base->ic_enable); - enbl &= ~IC_ENABLE_0B; - writel(enbl, &i2c_base->ic_enable); + dw_i2c_enable(i2c_base, false); writel(i2c_addr, &i2c_base->ic_tar); /* Enable i2c */ - enbl = readl(&i2c_base->ic_enable); - enbl |= IC_ENABLE_0B; - writel(enbl, &i2c_base->ic_enable); + dw_i2c_enable(i2c_base, true); } /* @@ -172,10 +161,8 @@ static void i2c_setaddress(struct i2c_adapter *adap, unsigned int i2c_addr) * * Flushes the i2c RX FIFO */ -static void i2c_flush_rxfifo(struct i2c_adapter *adap) +static void i2c_flush_rxfifo(struct i2c_regs *i2c_base) { - struct i2c_regs *i2c_base = i2c_get_base(adap); - while (readl(&i2c_base->ic_status) & IC_STATUS_RFNE) readl(&i2c_base->ic_cmd_data); } @@ -185,9 +172,8 @@ static void i2c_flush_rxfifo(struct i2c_adapter *adap) * * Waits for bus busy */ -static int i2c_wait_for_bb(struct i2c_adapter *adap) +static int i2c_wait_for_bb(struct i2c_regs *i2c_base) { - struct i2c_regs *i2c_base = i2c_get_base(adap); unsigned long start_time_bb = get_timer(0); while ((readl(&i2c_base->ic_status) & IC_STATUS_MA) || @@ -201,15 +187,13 @@ static int i2c_wait_for_bb(struct i2c_adapter *adap) return 0; } -static int i2c_xfer_init(struct i2c_adapter *adap, uchar chip, uint addr, +static int i2c_xfer_init(struct i2c_regs *i2c_base, uchar chip, uint addr, int alen) { - struct i2c_regs *i2c_base = i2c_get_base(adap); - - if (i2c_wait_for_bb(adap)) + if (i2c_wait_for_bb(i2c_base)) return 1; - i2c_setaddress(adap, chip); + i2c_setaddress(i2c_base, chip); while (alen) { alen--; /* high byte address going out first */ @@ -219,9 +203,8 @@ static int i2c_xfer_init(struct i2c_adapter *adap, uchar chip, uint addr, return 0; } -static int i2c_xfer_finish(struct i2c_adapter *adap) +static int i2c_xfer_finish(struct i2c_regs *i2c_base) { - struct i2c_regs *i2c_base = i2c_get_base(adap); ulong start_stop_det = get_timer(0); while (1) { @@ -233,12 +216,12 @@ static int i2c_xfer_finish(struct i2c_adapter *adap) } } - if (i2c_wait_for_bb(adap)) { + if (i2c_wait_for_bb(i2c_base)) { printf("Timed out waiting for bus\n"); return 1; } - i2c_flush_rxfifo(adap); + i2c_flush_rxfifo(i2c_base); return 0; } @@ -253,10 +236,9 @@ static int i2c_xfer_finish(struct i2c_adapter *adap) * * Read from i2c memory. */ -static int dw_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, - int alen, u8 *buffer, int len) +static int __dw_i2c_read(struct i2c_regs *i2c_base, u8 dev, uint addr, + int alen, u8 *buffer, int len) { - struct i2c_regs *i2c_base = i2c_get_base(adap); unsigned long start_time_rx; #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW @@ -278,7 +260,7 @@ static int dw_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, addr); #endif - if (i2c_xfer_init(adap, dev, addr, alen)) + if (i2c_xfer_init(i2c_base, dev, addr, alen)) return 1; start_time_rx = get_timer(0); @@ -298,7 +280,7 @@ static int dw_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, } } - return i2c_xfer_finish(adap); + return i2c_xfer_finish(i2c_base); } /* @@ -311,10 +293,9 @@ static int dw_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, * * Write to i2c memory. */ -static int dw_i2c_write(struct i2c_adapter *adap, u8 dev, uint addr, - int alen, u8 *buffer, int len) +static int __dw_i2c_write(struct i2c_regs *i2c_base, u8 dev, uint addr, + int alen, u8 *buffer, int len) { - struct i2c_regs *i2c_base = i2c_get_base(adap); int nb = len; unsigned long start_time_tx; @@ -337,7 +318,7 @@ static int dw_i2c_write(struct i2c_adapter *adap, u8 dev, uint addr, addr); #endif - if (i2c_xfer_init(adap, dev, addr, alen)) + if (i2c_xfer_init(i2c_base, dev, addr, alen)) return 1; start_time_tx = get_timer(0); @@ -358,21 +339,98 @@ static int dw_i2c_write(struct i2c_adapter *adap, u8 dev, uint addr, } } - return i2c_xfer_finish(adap); + return i2c_xfer_finish(i2c_base); +} + +/* + * __dw_i2c_init - Init function + * @speed: required i2c speed + * @slaveaddr: slave address for the device + * + * Initialization function. + */ +static void __dw_i2c_init(struct i2c_regs *i2c_base, int speed, int slaveaddr) +{ + /* Disable i2c */ + dw_i2c_enable(i2c_base, false); + + writel((IC_CON_SD | IC_CON_SPD_FS | IC_CON_MM), &i2c_base->ic_con); + writel(IC_RX_TL, &i2c_base->ic_rx_tl); + writel(IC_TX_TL, &i2c_base->ic_tx_tl); + writel(IC_STOP_DET, &i2c_base->ic_intr_mask); +#ifndef CONFIG_DM_I2C + __dw_i2c_set_bus_speed(i2c_base, NULL, speed); + writel(slaveaddr, &i2c_base->ic_sar); +#endif + + /* Enable i2c */ + dw_i2c_enable(i2c_base, true); } +#ifndef CONFIG_DM_I2C /* - * i2c_probe - Probe the i2c chip + * The legacy I2C functions. These need to get removed once + * all users of this driver are converted to DM. */ +static struct i2c_regs *i2c_get_base(struct i2c_adapter *adap) +{ + switch (adap->hwadapnr) { +#if CONFIG_SYS_I2C_BUS_MAX >= 4 + case 3: + return (struct i2c_regs *)CONFIG_SYS_I2C_BASE3; +#endif +#if CONFIG_SYS_I2C_BUS_MAX >= 3 + case 2: + return (struct i2c_regs *)CONFIG_SYS_I2C_BASE2; +#endif +#if CONFIG_SYS_I2C_BUS_MAX >= 2 + case 1: + return (struct i2c_regs *)CONFIG_SYS_I2C_BASE1; +#endif + case 0: + return (struct i2c_regs *)CONFIG_SYS_I2C_BASE; + default: + printf("Wrong I2C-adapter number %d\n", adap->hwadapnr); + } + + return NULL; +} + +static unsigned int dw_i2c_set_bus_speed(struct i2c_adapter *adap, + unsigned int speed) +{ + adap->speed = speed; + return __dw_i2c_set_bus_speed(i2c_get_base(adap), NULL, speed); +} + +static void dw_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr) +{ + __dw_i2c_init(i2c_get_base(adap), speed, slaveaddr); +} + +static int dw_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, + int alen, u8 *buffer, int len) +{ + return __dw_i2c_read(i2c_get_base(adap), dev, addr, alen, buffer, len); +} + +static int dw_i2c_write(struct i2c_adapter *adap, u8 dev, uint addr, + int alen, u8 *buffer, int len) +{ + return __dw_i2c_write(i2c_get_base(adap), dev, addr, alen, buffer, len); +} + +/* dw_i2c_probe - Probe the i2c chip */ static int dw_i2c_probe(struct i2c_adapter *adap, u8 dev) { + struct i2c_regs *i2c_base = i2c_get_base(adap); u32 tmp; int ret; /* * Try to read the first location of the chip. */ - ret = dw_i2c_read(adap, dev, 0, 1, (uchar *)&tmp, 1); + ret = __dw_i2c_read(i2c_base, dev, 0, 1, (uchar *)&tmp, 1); if (ret) dw_i2c_init(adap, adap->speed, adap->slaveaddr); @@ -400,3 +458,139 @@ U_BOOT_I2C_ADAP_COMPLETE(dw_3, dw_i2c_init, dw_i2c_probe, dw_i2c_read, dw_i2c_write, dw_i2c_set_bus_speed, CONFIG_SYS_I2C_SPEED3, CONFIG_SYS_I2C_SLAVE3, 3) #endif + +#else /* CONFIG_DM_I2C */ +/* The DM I2C functions */ + +static int designware_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, + int nmsgs) +{ + struct dw_i2c *i2c = dev_get_priv(bus); + int ret; + + debug("i2c_xfer: %d messages\n", nmsgs); + for (; nmsgs > 0; nmsgs--, msg++) { + debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len); + if (msg->flags & I2C_M_RD) { + ret = __dw_i2c_read(i2c->regs, msg->addr, 0, 0, + msg->buf, msg->len); + } else { + ret = __dw_i2c_write(i2c->regs, msg->addr, 0, 0, + msg->buf, msg->len); + } + if (ret) { + debug("i2c_write: error sending\n"); + return -EREMOTEIO; + } + } + + return 0; +} + +static int designware_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) +{ + struct dw_i2c *i2c = dev_get_priv(bus); + + return __dw_i2c_set_bus_speed(i2c->regs, i2c->scl_sda_cfg, speed); +} + +static int designware_i2c_probe_chip(struct udevice *bus, uint chip_addr, + uint chip_flags) +{ + struct dw_i2c *i2c = dev_get_priv(bus); + struct i2c_regs *i2c_base = i2c->regs; + u32 tmp; + int ret; + + /* Try to read the first location of the chip */ + ret = __dw_i2c_read(i2c_base, chip_addr, 0, 1, (uchar *)&tmp, 1); + if (ret) + __dw_i2c_init(i2c_base, 0, 0); + + return ret; +} + +static int designware_i2c_probe(struct udevice *bus) +{ + struct dw_i2c *priv = dev_get_priv(bus); + + if (device_is_on_pci_bus(bus)) { +#ifdef CONFIG_DM_PCI + /* Save base address from PCI BAR */ + priv->regs = (struct i2c_regs *) + dm_pci_map_bar(bus, PCI_BASE_ADDRESS_0, PCI_REGION_MEM); +#ifdef CONFIG_X86 + /* Use BayTrail specific timing values */ + priv->scl_sda_cfg = &byt_config; +#endif +#endif + } else { + priv->regs = (struct i2c_regs *)dev_get_addr_ptr(bus); + } + + __dw_i2c_init(priv->regs, 0, 0); + + return 0; +} + +static int designware_i2c_bind(struct udevice *dev) +{ + static int num_cards; + char name[20]; + + /* Create a unique device name for PCI type devices */ + if (device_is_on_pci_bus(dev)) { + /* + * ToDo: + * Setting req_seq in the driver is probably not recommended. + * But without a DT alias the number is not configured. And + * using this driver is impossible for PCIe I2C devices. + * This can be removed, once a better (correct) way for this + * is found and implemented. + */ + dev->req_seq = num_cards; + sprintf(name, "i2c_designware#%u", num_cards++); + device_set_name(dev, name); + } + + return 0; +} + +static const struct dm_i2c_ops designware_i2c_ops = { + .xfer = designware_i2c_xfer, + .probe_chip = designware_i2c_probe_chip, + .set_bus_speed = designware_i2c_set_bus_speed, +}; + +static const struct udevice_id designware_i2c_ids[] = { + { .compatible = "snps,designware-i2c" }, + { } +}; + +U_BOOT_DRIVER(i2c_designware) = { + .name = "i2c_designware", + .id = UCLASS_I2C, + .of_match = designware_i2c_ids, + .bind = designware_i2c_bind, + .probe = designware_i2c_probe, + .priv_auto_alloc_size = sizeof(struct dw_i2c), + .ops = &designware_i2c_ops, +}; + +#ifdef CONFIG_X86 +static struct pci_device_id designware_pci_supported[] = { + /* Intel BayTrail has 7 I2C controller located on the PCI bus */ + { PCI_VDEVICE(INTEL, 0x0f41) }, + { PCI_VDEVICE(INTEL, 0x0f42) }, + { PCI_VDEVICE(INTEL, 0x0f43) }, + { PCI_VDEVICE(INTEL, 0x0f44) }, + { PCI_VDEVICE(INTEL, 0x0f45) }, + { PCI_VDEVICE(INTEL, 0x0f46) }, + { PCI_VDEVICE(INTEL, 0x0f47) }, + {}, +}; + +U_BOOT_PCI_DEVICE(i2c_designware, designware_pci_supported); +#endif + +#endif /* CONFIG_DM_I2C */ diff --git a/drivers/i2c/designware_i2c.h b/drivers/i2c/designware_i2c.h index 19b09df..270c29c 100644 --- a/drivers/i2c/designware_i2c.h +++ b/drivers/i2c/designware_i2c.h @@ -9,39 +9,41 @@ #define __DW_I2C_H_ struct i2c_regs { - u32 ic_con; - u32 ic_tar; - u32 ic_sar; - u32 ic_hs_maddr; - u32 ic_cmd_data; - u32 ic_ss_scl_hcnt; - u32 ic_ss_scl_lcnt; - u32 ic_fs_scl_hcnt; - u32 ic_fs_scl_lcnt; - u32 ic_hs_scl_hcnt; - u32 ic_hs_scl_lcnt; - u32 ic_intr_stat; - u32 ic_intr_mask; - u32 ic_raw_intr_stat; - u32 ic_rx_tl; - u32 ic_tx_tl; - u32 ic_clr_intr; - u32 ic_clr_rx_under; - u32 ic_clr_rx_over; - u32 ic_clr_tx_over; - u32 ic_clr_rd_req; - u32 ic_clr_tx_abrt; - u32 ic_clr_rx_done; - u32 ic_clr_activity; - u32 ic_clr_stop_det; - u32 ic_clr_start_det; - u32 ic_clr_gen_call; - u32 ic_enable; - u32 ic_status; - u32 ic_txflr; - u32 ix_rxflr; - u32 reserved_1; - u32 ic_tx_abrt_source; + u32 ic_con; /* 0x00 */ + u32 ic_tar; /* 0x04 */ + u32 ic_sar; /* 0x08 */ + u32 ic_hs_maddr; /* 0x0c */ + u32 ic_cmd_data; /* 0x10 */ + u32 ic_ss_scl_hcnt; /* 0x14 */ + u32 ic_ss_scl_lcnt; /* 0x18 */ + u32 ic_fs_scl_hcnt; /* 0x1c */ + u32 ic_fs_scl_lcnt; /* 0x20 */ + u32 ic_hs_scl_hcnt; /* 0x24 */ + u32 ic_hs_scl_lcnt; /* 0x28 */ + u32 ic_intr_stat; /* 0x2c */ + u32 ic_intr_mask; /* 0x30 */ + u32 ic_raw_intr_stat; /* 0x34 */ + u32 ic_rx_tl; /* 0x38 */ + u32 ic_tx_tl; /* 0x3c */ + u32 ic_clr_intr; /* 0x40 */ + u32 ic_clr_rx_under; /* 0x44 */ + u32 ic_clr_rx_over; /* 0x48 */ + u32 ic_clr_tx_over; /* 0x4c */ + u32 ic_clr_rd_req; /* 0x50 */ + u32 ic_clr_tx_abrt; /* 0x54 */ + u32 ic_clr_rx_done; /* 0x58 */ + u32 ic_clr_activity; /* 0x5c */ + u32 ic_clr_stop_det; /* 0x60 */ + u32 ic_clr_start_det; /* 0x64 */ + u32 ic_clr_gen_call; /* 0x68 */ + u32 ic_enable; /* 0x6c */ + u32 ic_status; /* 0x70 */ + u32 ic_txflr; /* 0x74 */ + u32 ic_rxflr; /* 0x78 */ + u32 ic_sda_hold; /* 0x7c */ + u32 ic_tx_abrt_source; /* 0x80 */ + u8 res1[0x18]; /* 0x84 */ + u32 ic_enable_status; /* 0x9c */ }; #if !defined(IC_CLK) diff --git a/drivers/mmc/pci_mmc.c b/drivers/mmc/pci_mmc.c index 5fb7151..340eef6 100644 --- a/drivers/mmc/pci_mmc.c +++ b/drivers/mmc/pci_mmc.c @@ -28,7 +28,7 @@ int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported) if (!mmc_host) return -ENOMEM; - mmc_host->name = (char *)name; + mmc_host->name = name; dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase); mmc_host->ioaddr = (void *)iobase; mmc_host->quirks = 0; diff --git a/drivers/mmc/pic32_sdhci.c b/drivers/mmc/pic32_sdhci.c index 28da55d..e03d6dd 100644 --- a/drivers/mmc/pic32_sdhci.c +++ b/drivers/mmc/pic32_sdhci.c @@ -29,7 +29,7 @@ static int pic32_sdhci_probe(struct udevice *dev) return -EINVAL; host->ioaddr = ioremap(addr, size); - host->name = (char *)dev->name; + host->name = dev->name; host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_NO_CD; host->bus_width = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "bus-width", 4); diff --git a/drivers/mmc/zynq_sdhci.c b/drivers/mmc/zynq_sdhci.c index 039ec16..b59feca 100644 --- a/drivers/mmc/zynq_sdhci.c +++ b/drivers/mmc/zynq_sdhci.c @@ -43,7 +43,7 @@ static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev) { struct sdhci_host *host = dev_get_priv(dev); - host->name = (char *)dev->name; + host->name = dev->name; host->ioaddr = (void *)dev_get_addr(dev); return 0; diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 44d9e9b..5451725 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -265,7 +265,8 @@ static int spi_flash_ready(struct spi_flash *flash) static int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout) { - int timebase, ret; + unsigned long timebase; + int ret; timebase = get_timer(0); diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 507b091..e823ca5 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c @@ -1528,6 +1528,7 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai) INIT_LIST_HEAD(&ubi->pq[i]); ubi->pq_head = 0; + ubi->free_count = 0; list_for_each_entry_safe(aeb, tmp, &ai->erase, u.list) { cond_resched(); @@ -1546,7 +1547,6 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai) found_pebs++; } - ubi->free_count = 0; list_for_each_entry(aeb, &ai->free, u.list) { cond_resched(); diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index c7fbf7b..32590ce 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -682,7 +682,7 @@ int pci_bind_bus_devices(struct udevice *bus) found_multi = false; end = PCI_BDF(bus->seq, PCI_MAX_PCI_DEVICES - 1, PCI_MAX_PCI_FUNCTIONS - 1); - for (bdf = PCI_BDF(bus->seq, 0, 0); bdf < end; + for (bdf = PCI_BDF(bus->seq, 0, 0); bdf <= end; bdf += PCI_BDF(0, 0, 1)) { struct pci_child_platdata *pplat; struct udevice *dev; diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c index 3d5ac5f..fe154b7 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c @@ -22,13 +22,13 @@ static const unsigned i2c3_muxvals[] = {1, 1}; static const unsigned i2c4_pins[] = {61, 62}; static const unsigned i2c4_muxvals[] = {1, 1}; static const unsigned nand_pins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16}; -static const unsigned nand_muxvals[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0}; + 15, 16, 17}; +static const unsigned nand_muxvals[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2}; static const unsigned nand_cs1_pins[] = {}; static const unsigned nand_cs1_muxvals[] = {}; static const unsigned sd_pins[] = {10, 11, 12, 13, 14, 15, 16, 17}; -static const unsigned sd_muxvals[] = {8, 8, 8, 8, 8, 8, 8, 8}; /* No SDVOLC */ +static const unsigned sd_muxvals[] = {3, 3, 3, 3, 3, 3, 3, 3}; /* No SDVOLC */ static const unsigned uart0_pins[] = {54, 55}; static const unsigned uart0_muxvals[] = {0, 0}; static const unsigned uart1_pins[] = {58, 59}; diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld4.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld4.c index 8f7574e..ca66dee 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld4.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld4.c @@ -9,7 +9,7 @@ #include "pinctrl-uniphier.h" -static const struct uniphier_pinctrl_pin ph1_ld4_pins[] = { +static const struct uniphier_pinctrl_pin uniphier_ld4_pins[] = { UNIPHIER_PINCTRL_PIN(53, 0), UNIPHIER_PINCTRL_PIN(54, 0), UNIPHIER_PINCTRL_PIN(55, 0), @@ -62,7 +62,7 @@ static const unsigned usb2_muxvals[] = {4, 4}; static const unsigned usb2b_pins[] = {67, 68}; static const unsigned usb2b_muxvals[] = {23, 23}; -static const struct uniphier_pinctrl_group ph1_ld4_groups[] = { +static const struct uniphier_pinctrl_group uniphier_ld4_groups[] = { UNIPHIER_PINCTRL_GROUP(emmc), UNIPHIER_PINCTRL_GROUP(emmc_dat8), UNIPHIER_PINCTRL_GROUP(i2c0), @@ -83,7 +83,7 @@ static const struct uniphier_pinctrl_group ph1_ld4_groups[] = { UNIPHIER_PINCTRL_GROUP(usb2b), }; -static const char * const ph1_ld4_functions[] = { +static const char * const uniphier_ld4_functions[] = { "emmc", "i2c0", "i2c1", @@ -100,30 +100,30 @@ static const char * const ph1_ld4_functions[] = { "usb2", }; -static struct uniphier_pinctrl_socdata ph1_ld4_pinctrl_socdata = { - .pins = ph1_ld4_pins, - .pins_count = ARRAY_SIZE(ph1_ld4_pins), - .groups = ph1_ld4_groups, - .groups_count = ARRAY_SIZE(ph1_ld4_groups), - .functions = ph1_ld4_functions, - .functions_count = ARRAY_SIZE(ph1_ld4_functions), +static struct uniphier_pinctrl_socdata uniphier_ld4_pinctrl_socdata = { + .pins = uniphier_ld4_pins, + .pins_count = ARRAY_SIZE(uniphier_ld4_pins), + .groups = uniphier_ld4_groups, + .groups_count = ARRAY_SIZE(uniphier_ld4_groups), + .functions = uniphier_ld4_functions, + .functions_count = ARRAY_SIZE(uniphier_ld4_functions), }; -static int ph1_ld4_pinctrl_probe(struct udevice *dev) +static int uniphier_ld4_pinctrl_probe(struct udevice *dev) { - return uniphier_pinctrl_probe(dev, &ph1_ld4_pinctrl_socdata); + return uniphier_pinctrl_probe(dev, &uniphier_ld4_pinctrl_socdata); } -static const struct udevice_id ph1_ld4_pinctrl_match[] = { +static const struct udevice_id uniphier_ld4_pinctrl_match[] = { { .compatible = "socionext,ph1-ld4-pinctrl" }, { /* sentinel */ } }; -U_BOOT_DRIVER(ph1_ld4_pinctrl) = { - .name = "ph1-ld4-pinctrl", +U_BOOT_DRIVER(uniphier_ld4_pinctrl) = { + .name = "uniphier-ld4-pinctrl", .id = UCLASS_PINCTRL, - .of_match = of_match_ptr(ph1_ld4_pinctrl_match), - .probe = ph1_ld4_pinctrl_probe, + .of_match = of_match_ptr(uniphier_ld4_pinctrl_match), + .probe = uniphier_ld4_pinctrl_probe, .remove = uniphier_pinctrl_remove, .priv_auto_alloc_size = sizeof(struct uniphier_pinctrl_priv), .ops = &uniphier_pinctrl_ops, diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld6b.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld6b.c index 2a5d5f3..0fd4dc4 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld6b.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld6b.c @@ -9,7 +9,7 @@ #include "pinctrl-uniphier.h" -static const struct uniphier_pinctrl_pin ph1_ld6b_pins[] = { +static const struct uniphier_pinctrl_pin uniphier_ld6b_pins[] = { UNIPHIER_PINCTRL_PIN(113, 0), UNIPHIER_PINCTRL_PIN(114, 0), UNIPHIER_PINCTRL_PIN(115, 0), @@ -61,7 +61,7 @@ static const unsigned usb2_muxvals[] = {0, 0}; static const unsigned usb3_pins[] = {62, 63}; static const unsigned usb3_muxvals[] = {0, 0}; -static const struct uniphier_pinctrl_group ph1_ld6b_groups[] = { +static const struct uniphier_pinctrl_group uniphier_ld6b_groups[] = { UNIPHIER_PINCTRL_GROUP(emmc), UNIPHIER_PINCTRL_GROUP(emmc_dat8), UNIPHIER_PINCTRL_GROUP(i2c0), @@ -83,7 +83,7 @@ static const struct uniphier_pinctrl_group ph1_ld6b_groups[] = { UNIPHIER_PINCTRL_GROUP(usb3), }; -static const char * const ph1_ld6b_functions[] = { +static const char * const uniphier_ld6b_functions[] = { "emmc", "i2c0", "i2c1", @@ -100,30 +100,30 @@ static const char * const ph1_ld6b_functions[] = { "usb3", }; -static struct uniphier_pinctrl_socdata ph1_ld6b_pinctrl_socdata = { - .pins = ph1_ld6b_pins, - .pins_count = ARRAY_SIZE(ph1_ld6b_pins), - .groups = ph1_ld6b_groups, - .groups_count = ARRAY_SIZE(ph1_ld6b_groups), - .functions = ph1_ld6b_functions, - .functions_count = ARRAY_SIZE(ph1_ld6b_functions), +static struct uniphier_pinctrl_socdata uniphier_ld6b_pinctrl_socdata = { + .pins = uniphier_ld6b_pins, + .pins_count = ARRAY_SIZE(uniphier_ld6b_pins), + .groups = uniphier_ld6b_groups, + .groups_count = ARRAY_SIZE(uniphier_ld6b_groups), + .functions = uniphier_ld6b_functions, + .functions_count = ARRAY_SIZE(uniphier_ld6b_functions), }; -static int ph1_ld6b_pinctrl_probe(struct udevice *dev) +static int uniphier_ld6b_pinctrl_probe(struct udevice *dev) { - return uniphier_pinctrl_probe(dev, &ph1_ld6b_pinctrl_socdata); + return uniphier_pinctrl_probe(dev, &uniphier_ld6b_pinctrl_socdata); } -static const struct udevice_id ph1_ld6b_pinctrl_match[] = { +static const struct udevice_id uniphier_ld6b_pinctrl_match[] = { { .compatible = "socionext,ph1-ld6b-pinctrl" }, { /* sentinel */ } }; -U_BOOT_DRIVER(ph1_ld6b_pinctrl) = { - .name = "ph1-ld6b-pinctrl", +U_BOOT_DRIVER(uniphier_ld6b_pinctrl) = { + .name = "uniphier-ld6b-pinctrl", .id = UCLASS_PINCTRL, - .of_match = of_match_ptr(ph1_ld6b_pinctrl_match), - .probe = ph1_ld6b_pinctrl_probe, + .of_match = of_match_ptr(uniphier_ld6b_pinctrl_match), + .probe = uniphier_ld6b_pinctrl_probe, .remove = uniphier_pinctrl_remove, .priv_auto_alloc_size = sizeof(struct uniphier_pinctrl_priv), .ops = &uniphier_pinctrl_ops, diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-pro4.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-pro4.c index 60fbbaf..9ed7c74 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-pro4.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-pro4.c @@ -9,7 +9,7 @@ #include "pinctrl-uniphier.h" -static const struct uniphier_pinctrl_pin ph1_pro4_pins[] = { +static const struct uniphier_pinctrl_pin uniphier_pro4_pins[] = { }; static const unsigned emmc_pins[] = {40, 41, 42, 43, 51, 52, 53}; @@ -54,7 +54,7 @@ static const unsigned usb2_muxvals[] = {0, 0}; static const unsigned usb3_pins[] = {186, 187}; static const unsigned usb3_muxvals[] = {0, 0}; -static const struct uniphier_pinctrl_group ph1_pro4_groups[] = { +static const struct uniphier_pinctrl_group uniphier_pro4_groups[] = { UNIPHIER_PINCTRL_GROUP(emmc), UNIPHIER_PINCTRL_GROUP(emmc_dat8), UNIPHIER_PINCTRL_GROUP(i2c0), @@ -76,7 +76,7 @@ static const struct uniphier_pinctrl_group ph1_pro4_groups[] = { UNIPHIER_PINCTRL_GROUP(usb3), }; -static const char * const ph1_pro4_functions[] = { +static const char * const uniphier_pro4_functions[] = { "emmc", "i2c0", "i2c1", @@ -96,31 +96,31 @@ static const char * const ph1_pro4_functions[] = { "usb3", }; -static struct uniphier_pinctrl_socdata ph1_pro4_pinctrl_socdata = { - .pins = ph1_pro4_pins, - .pins_count = ARRAY_SIZE(ph1_pro4_pins), - .groups = ph1_pro4_groups, - .groups_count = ARRAY_SIZE(ph1_pro4_groups), - .functions = ph1_pro4_functions, - .functions_count = ARRAY_SIZE(ph1_pro4_functions), +static struct uniphier_pinctrl_socdata uniphier_pro4_pinctrl_socdata = { + .pins = uniphier_pro4_pins, + .pins_count = ARRAY_SIZE(uniphier_pro4_pins), + .groups = uniphier_pro4_groups, + .groups_count = ARRAY_SIZE(uniphier_pro4_groups), + .functions = uniphier_pro4_functions, + .functions_count = ARRAY_SIZE(uniphier_pro4_functions), .caps = UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE, }; -static int ph1_pro4_pinctrl_probe(struct udevice *dev) +static int uniphier_pro4_pinctrl_probe(struct udevice *dev) { - return uniphier_pinctrl_probe(dev, &ph1_pro4_pinctrl_socdata); + return uniphier_pinctrl_probe(dev, &uniphier_pro4_pinctrl_socdata); } -static const struct udevice_id ph1_pro4_pinctrl_match[] = { +static const struct udevice_id uniphier_pro4_pinctrl_match[] = { { .compatible = "socionext,ph1-pro4-pinctrl" }, { /* sentinel */ } }; -U_BOOT_DRIVER(ph1_pro4_pinctrl) = { - .name = "ph1-pro4-pinctrl", +U_BOOT_DRIVER(uniphier_pro4_pinctrl) = { + .name = "uniphier-pro4-pinctrl", .id = UCLASS_PINCTRL, - .of_match = of_match_ptr(ph1_pro4_pinctrl_match), - .probe = ph1_pro4_pinctrl_probe, + .of_match = of_match_ptr(uniphier_pro4_pinctrl_match), + .probe = uniphier_pro4_pinctrl_probe, .remove = uniphier_pinctrl_remove, .priv_auto_alloc_size = sizeof(struct uniphier_pinctrl_priv), .ops = &uniphier_pinctrl_ops, diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-pro5.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-pro5.c index 30c9b4d..6597f1c 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-pro5.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-pro5.c @@ -9,7 +9,7 @@ #include "pinctrl-uniphier.h" -static const struct uniphier_pinctrl_pin ph1_pro5_pins[] = { +static const struct uniphier_pinctrl_pin uniphier_pro5_pins[] = { UNIPHIER_PINCTRL_PIN(47, 0), UNIPHIER_PINCTRL_PIN(48, 0), UNIPHIER_PINCTRL_PIN(49, 0), @@ -67,7 +67,7 @@ static const unsigned usb1_muxvals[] = {0, 0}; static const unsigned usb2_pins[] = {128, 129}; static const unsigned usb2_muxvals[] = {0, 0}; -static const struct uniphier_pinctrl_group ph1_pro5_groups[] = { +static const struct uniphier_pinctrl_group uniphier_pro5_groups[] = { UNIPHIER_PINCTRL_GROUP(emmc), UNIPHIER_PINCTRL_GROUP(emmc_dat8), UNIPHIER_PINCTRL_GROUP(i2c0), @@ -91,7 +91,7 @@ static const struct uniphier_pinctrl_group ph1_pro5_groups[] = { UNIPHIER_PINCTRL_GROUP(usb2), }; -static const char * const ph1_pro5_functions[] = { +static const char * const uniphier_pro5_functions[] = { "emmc", "i2c0", "i2c1", @@ -110,31 +110,31 @@ static const char * const ph1_pro5_functions[] = { "usb2", }; -static struct uniphier_pinctrl_socdata ph1_pro5_pinctrl_socdata = { - .pins = ph1_pro5_pins, - .pins_count = ARRAY_SIZE(ph1_pro5_pins), - .groups = ph1_pro5_groups, - .groups_count = ARRAY_SIZE(ph1_pro5_groups), - .functions = ph1_pro5_functions, - .functions_count = ARRAY_SIZE(ph1_pro5_functions), +static struct uniphier_pinctrl_socdata uniphier_pro5_pinctrl_socdata = { + .pins = uniphier_pro5_pins, + .pins_count = ARRAY_SIZE(uniphier_pro5_pins), + .groups = uniphier_pro5_groups, + .groups_count = ARRAY_SIZE(uniphier_pro5_groups), + .functions = uniphier_pro5_functions, + .functions_count = ARRAY_SIZE(uniphier_pro5_functions), .caps = UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE, }; -static int ph1_pro5_pinctrl_probe(struct udevice *dev) +static int uniphier_pro5_pinctrl_probe(struct udevice *dev) { - return uniphier_pinctrl_probe(dev, &ph1_pro5_pinctrl_socdata); + return uniphier_pinctrl_probe(dev, &uniphier_pro5_pinctrl_socdata); } -static const struct udevice_id ph1_pro5_pinctrl_match[] = { +static const struct udevice_id uniphier_pro5_pinctrl_match[] = { { .compatible = "socionext,ph1-pro5-pinctrl" }, { /* sentinel */ } }; -U_BOOT_DRIVER(ph1_pro5_pinctrl) = { - .name = "ph1-pro5-pinctrl", +U_BOOT_DRIVER(uniphier_pro5_pinctrl) = { + .name = "uniphier-pro5-pinctrl", .id = UCLASS_PINCTRL, - .of_match = of_match_ptr(ph1_pro5_pinctrl_match), - .probe = ph1_pro5_pinctrl_probe, + .of_match = of_match_ptr(uniphier_pro5_pinctrl_match), + .probe = uniphier_pro5_pinctrl_probe, .remove = uniphier_pinctrl_remove, .priv_auto_alloc_size = sizeof(struct uniphier_pinctrl_priv), .ops = &uniphier_pinctrl_ops, diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-pxs2.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-pxs2.c index 976bb2f..cfec877 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-pxs2.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-pxs2.c @@ -9,7 +9,7 @@ #include "pinctrl-uniphier.h" -static const struct uniphier_pinctrl_pin proxstream2_pins[] = { +static const struct uniphier_pinctrl_pin uniphier_pxs2_pins[] = { UNIPHIER_PINCTRL_PIN(113, 0), UNIPHIER_PINCTRL_PIN(114, 0), UNIPHIER_PINCTRL_PIN(115, 0), @@ -61,7 +61,7 @@ static const unsigned usb2_muxvals[] = {8, 8}; static const unsigned usb3_pins[] = {62, 63}; static const unsigned usb3_muxvals[] = {8, 8}; -static const struct uniphier_pinctrl_group proxstream2_groups[] = { +static const struct uniphier_pinctrl_group uniphier_pxs2_groups[] = { UNIPHIER_PINCTRL_GROUP(emmc), UNIPHIER_PINCTRL_GROUP(emmc_dat8), UNIPHIER_PINCTRL_GROUP(i2c0), @@ -85,7 +85,7 @@ static const struct uniphier_pinctrl_group proxstream2_groups[] = { UNIPHIER_PINCTRL_GROUP(usb3), }; -static const char * const proxstream2_functions[] = { +static const char * const uniphier_pxs2_functions[] = { "emmc", "i2c0", "i2c1", @@ -107,30 +107,30 @@ static const char * const proxstream2_functions[] = { "usb3", }; -static struct uniphier_pinctrl_socdata proxstream2_pinctrl_socdata = { - .pins = proxstream2_pins, - .pins_count = ARRAY_SIZE(proxstream2_pins), - .groups = proxstream2_groups, - .groups_count = ARRAY_SIZE(proxstream2_groups), - .functions = proxstream2_functions, - .functions_count = ARRAY_SIZE(proxstream2_functions), +static struct uniphier_pinctrl_socdata uniphier_pxs2_pinctrl_socdata = { + .pins = uniphier_pxs2_pins, + .pins_count = ARRAY_SIZE(uniphier_pxs2_pins), + .groups = uniphier_pxs2_groups, + .groups_count = ARRAY_SIZE(uniphier_pxs2_groups), + .functions = uniphier_pxs2_functions, + .functions_count = ARRAY_SIZE(uniphier_pxs2_functions), }; -static int proxstream2_pinctrl_probe(struct udevice *dev) +static int uniphier_pxs2_pinctrl_probe(struct udevice *dev) { - return uniphier_pinctrl_probe(dev, &proxstream2_pinctrl_socdata); + return uniphier_pinctrl_probe(dev, &uniphier_pxs2_pinctrl_socdata); } -static const struct udevice_id proxstream2_pinctrl_match[] = { +static const struct udevice_id uniphier_pxs2_pinctrl_match[] = { { .compatible = "socionext,proxstream2-pinctrl" }, { /* sentinel */ } }; -U_BOOT_DRIVER(proxstream2_pinctrl) = { - .name = "proxstream2-pinctrl", +U_BOOT_DRIVER(uniphier_pxs2_pinctrl) = { + .name = "uniphier-pxs2-pinctrl", .id = UCLASS_PINCTRL, - .of_match = of_match_ptr(proxstream2_pinctrl_match), - .probe = proxstream2_pinctrl_probe, + .of_match = of_match_ptr(uniphier_pxs2_pinctrl_match), + .probe = uniphier_pxs2_pinctrl_probe, .remove = uniphier_pinctrl_remove, .priv_auto_alloc_size = sizeof(struct uniphier_pinctrl_priv), .ops = &uniphier_pinctrl_ops, diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-sld8.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-sld8.c index 6cbf215..5a733b3 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-sld8.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-sld8.c @@ -9,7 +9,7 @@ #include "pinctrl-uniphier.h" -static const struct uniphier_pinctrl_pin ph1_sld8_pins[] = { +static const struct uniphier_pinctrl_pin uniphier_sld8_pins[] = { UNIPHIER_PINCTRL_PIN(32, 8), UNIPHIER_PINCTRL_PIN(33, 8), UNIPHIER_PINCTRL_PIN(34, 8), @@ -72,7 +72,7 @@ static const unsigned usb1_muxvals[] = {0, 0}; static const unsigned usb2_pins[] = {114, 115}; static const unsigned usb2_muxvals[] = {1, 1}; -static const struct uniphier_pinctrl_group ph1_sld8_groups[] = { +static const struct uniphier_pinctrl_group uniphier_sld8_groups[] = { UNIPHIER_PINCTRL_GROUP(emmc), UNIPHIER_PINCTRL_GROUP(emmc_dat8), UNIPHIER_PINCTRL_GROUP(i2c0), @@ -91,7 +91,7 @@ static const struct uniphier_pinctrl_group ph1_sld8_groups[] = { UNIPHIER_PINCTRL_GROUP(usb2), }; -static const char * const ph1_sld8_functions[] = { +static const char * const uniphier_sld8_functions[] = { "emmc", "i2c0", "i2c1", @@ -108,30 +108,30 @@ static const char * const ph1_sld8_functions[] = { "usb2", }; -static struct uniphier_pinctrl_socdata ph1_sld8_pinctrl_socdata = { - .pins = ph1_sld8_pins, - .pins_count = ARRAY_SIZE(ph1_sld8_pins), - .groups = ph1_sld8_groups, - .groups_count = ARRAY_SIZE(ph1_sld8_groups), - .functions = ph1_sld8_functions, - .functions_count = ARRAY_SIZE(ph1_sld8_functions), +static struct uniphier_pinctrl_socdata uniphier_sld8_pinctrl_socdata = { + .pins = uniphier_sld8_pins, + .pins_count = ARRAY_SIZE(uniphier_sld8_pins), + .groups = uniphier_sld8_groups, + .groups_count = ARRAY_SIZE(uniphier_sld8_groups), + .functions = uniphier_sld8_functions, + .functions_count = ARRAY_SIZE(uniphier_sld8_functions), }; -static int ph1_sld8_pinctrl_probe(struct udevice *dev) +static int uniphier_sld8_pinctrl_probe(struct udevice *dev) { - return uniphier_pinctrl_probe(dev, &ph1_sld8_pinctrl_socdata); + return uniphier_pinctrl_probe(dev, &uniphier_sld8_pinctrl_socdata); } -static const struct udevice_id ph1_sld8_pinctrl_match[] = { +static const struct udevice_id uniphier_sld8_pinctrl_match[] = { { .compatible = "socionext,ph1-sld8-pinctrl" }, { /* sentinel */ } }; -U_BOOT_DRIVER(ph1_sld8_pinctrl) = { - .name = "ph1-sld8-pinctrl", +U_BOOT_DRIVER(uniphier_sld8_pinctrl) = { + .name = "uniphier-sld8-pinctrl", .id = UCLASS_PINCTRL, - .of_match = of_match_ptr(ph1_sld8_pinctrl_match), - .probe = ph1_sld8_pinctrl_probe, + .of_match = of_match_ptr(uniphier_sld8_pinctrl_match), + .probe = uniphier_sld8_pinctrl_probe, .remove = uniphier_pinctrl_remove, .priv_auto_alloc_size = sizeof(struct uniphier_pinctrl_priv), .ops = &uniphier_pinctrl_ops, diff --git a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c index bce9c30..12f5c85 100644 --- a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c +++ b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c @@ -229,13 +229,13 @@ static void complete_rx(struct dwc2_udc *dev, u8 ep_num) ROUND(xfer_size, CONFIG_SYS_CACHELINE_SIZE)); req->req.actual += min(xfer_size, req->req.length - req->req.actual); - is_short = (xfer_size < ep->ep.maxpacket); + is_short = !!(xfer_size % ep->ep.maxpacket); debug_cond(DEBUG_OUT_EP != 0, "%s: RX DMA done : ep = %d, rx bytes = %d/%d, " "is_short = %d, DOEPTSIZ = 0x%x, remained bytes = %d\n", __func__, ep_num, req->req.actual, req->req.length, - is_short, ep_tsr, xfer_size); + is_short, ep_tsr, req->req.length - req->req.actual); if (is_short || req->req.actual == req->req.length) { if (ep_num == EP0_CON && dev->ep0state == DATA_STATE_RECV) { @@ -292,7 +292,7 @@ static void complete_tx(struct dwc2_udc *dev, u8 ep_num) "%s: TX DMA done : ep = %d, tx bytes = %d/%d, " "is_short = %d, DIEPTSIZ = 0x%x, remained bytes = %d\n", __func__, ep_num, req->req.actual, req->req.length, - is_short, ep_tsr, xfer_size); + is_short, ep_tsr, req->req.length - req->req.actual); if (ep_num == 0) { if (dev->ep0state == DATA_STATE_XMIT) { diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 2e87fee..28b244a 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -39,6 +39,11 @@ #define TX_ENDPOINT_MAXIMUM_PACKET_SIZE (0x0040) #define EP_BUFFER_SIZE 4096 +/* + * EP_BUFFER_SIZE must always be an integral multiple of maxpacket size + * (64 or 512 or 1024), else we break on certain controllers like DWC3 + * that expect bulk OUT requests to be divisible by maxpacket size. + */ struct f_fastboot { struct usb_function usb_function; @@ -57,15 +62,13 @@ static struct f_fastboot *fastboot_func; static unsigned int fastboot_flash_session_id; static unsigned int download_size; static unsigned int download_bytes; -static bool is_high_speed; static struct usb_endpoint_descriptor fs_ep_in = { .bLength = USB_DT_ENDPOINT_SIZE, .bDescriptorType = USB_DT_ENDPOINT, .bEndpointAddress = USB_DIR_IN, .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = TX_ENDPOINT_MAXIMUM_PACKET_SIZE, - .bInterval = 0x00, + .wMaxPacketSize = cpu_to_le16(64), }; static struct usb_endpoint_descriptor fs_ep_out = { @@ -73,8 +76,15 @@ static struct usb_endpoint_descriptor fs_ep_out = { .bDescriptorType = USB_DT_ENDPOINT, .bEndpointAddress = USB_DIR_OUT, .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = RX_ENDPOINT_MAXIMUM_PACKET_SIZE_1_1, - .bInterval = 0x00, + .wMaxPacketSize = cpu_to_le16(64), +}; + +static struct usb_endpoint_descriptor hs_ep_in = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(512), }; static struct usb_endpoint_descriptor hs_ep_out = { @@ -82,8 +92,7 @@ static struct usb_endpoint_descriptor hs_ep_out = { .bDescriptorType = USB_DT_ENDPOINT, .bEndpointAddress = USB_DIR_OUT, .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = RX_ENDPOINT_MAXIMUM_PACKET_SIZE_2_0, - .bInterval = 0x00, + .wMaxPacketSize = cpu_to_le16(512), }; static struct usb_interface_descriptor interface_desc = { @@ -97,13 +106,28 @@ static struct usb_interface_descriptor interface_desc = { .bInterfaceProtocol = FASTBOOT_INTERFACE_PROTOCOL, }; -static struct usb_descriptor_header *fb_runtime_descs[] = { +static struct usb_descriptor_header *fb_fs_function[] = { (struct usb_descriptor_header *)&interface_desc, (struct usb_descriptor_header *)&fs_ep_in, + (struct usb_descriptor_header *)&fs_ep_out, +}; + +static struct usb_descriptor_header *fb_hs_function[] = { + (struct usb_descriptor_header *)&interface_desc, + (struct usb_descriptor_header *)&hs_ep_in, (struct usb_descriptor_header *)&hs_ep_out, NULL, }; +static struct usb_endpoint_descriptor * +fb_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, + struct usb_endpoint_descriptor *hs) +{ + if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) + return hs; + return fs; +} + /* * static strings, in UTF-8 */ @@ -177,7 +201,15 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f) return -ENODEV; f_fb->out_ep->driver_data = c->cdev; - hs_ep_out.bEndpointAddress = fs_ep_out.bEndpointAddress; + f->descriptors = fb_fs_function; + + if (gadget_is_dualspeed(gadget)) { + /* Assume endpoint addresses are the same for both speeds */ + hs_ep_in.bEndpointAddress = fs_ep_in.bEndpointAddress; + hs_ep_out.bEndpointAddress = fs_ep_out.bEndpointAddress; + /* copy HS descriptors */ + f->hs_descriptors = fb_hs_function; + } s = getenv("serial#"); if (s) @@ -236,18 +268,13 @@ static int fastboot_set_alt(struct usb_function *f, struct usb_composite_dev *cdev = f->config->cdev; struct usb_gadget *gadget = cdev->gadget; struct f_fastboot *f_fb = func_to_fastboot(f); + const struct usb_endpoint_descriptor *d; debug("%s: func: %s intf: %d alt: %d\n", __func__, f->name, interface, alt); - /* make sure we don't enable the ep twice */ - if (gadget->speed == USB_SPEED_HIGH) { - ret = usb_ep_enable(f_fb->out_ep, &hs_ep_out); - is_high_speed = true; - } else { - ret = usb_ep_enable(f_fb->out_ep, &fs_ep_out); - is_high_speed = false; - } + d = fb_ep_desc(gadget, &fs_ep_out, &hs_ep_out); + ret = usb_ep_enable(f_fb->out_ep, d); if (ret) { puts("failed to enable out ep\n"); return ret; @@ -261,7 +288,8 @@ static int fastboot_set_alt(struct usb_function *f, } f_fb->out_req->complete = rx_handler_command; - ret = usb_ep_enable(f_fb->in_ep, &fs_ep_in); + d = fb_ep_desc(gadget, &fs_ep_in, &hs_ep_in); + ret = usb_ep_enable(f_fb->in_ep, d); if (ret) { puts("failed to enable in ep\n"); goto err; @@ -302,7 +330,6 @@ static int fastboot_add(struct usb_configuration *c) } f_fb->usb_function.name = "f_fastboot"; - f_fb->usb_function.hs_descriptors = fb_runtime_descs; f_fb->usb_function.bind = fastboot_bind; f_fb->usb_function.unbind = fastboot_unbind; f_fb->usb_function.set_alt = fastboot_set_alt; @@ -427,20 +454,27 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req) fastboot_tx_write_str(response); } -static unsigned int rx_bytes_expected(unsigned int maxpacket) +static unsigned int rx_bytes_expected(struct usb_ep *ep) { int rx_remain = download_size - download_bytes; - int rem = 0; - if (rx_remain < 0) + unsigned int rem; + unsigned int maxpacket = ep->maxpacket; + + if (rx_remain <= 0) return 0; - if (rx_remain > EP_BUFFER_SIZE) + else if (rx_remain > EP_BUFFER_SIZE) return EP_BUFFER_SIZE; - if (rx_remain < maxpacket) { - rx_remain = maxpacket; - } else if (rx_remain % maxpacket != 0) { - rem = rx_remain % maxpacket; + + /* + * Some controllers e.g. DWC3 don't like OUT transfers to be + * not ending in maxpacket boundary. So just make them happy by + * always requesting for integral multiple of maxpackets. + * This shouldn't bother controllers that don't care about it. + */ + rem = rx_remain % maxpacket; + if (rem > 0) rx_remain = rx_remain + (maxpacket - rem); - } + return rx_remain; } @@ -452,7 +486,6 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req) const unsigned char *buffer = req->buf; unsigned int buffer_size = req->actual; unsigned int pre_dot_num, now_dot_num; - unsigned int max; if (req->status != 0) { printf("Bad status: %d\n", req->status); @@ -490,11 +523,7 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req) printf("\ndownloading of %d bytes finished\n", download_bytes); } else { - max = is_high_speed ? hs_ep_out.wMaxPacketSize : - fs_ep_out.wMaxPacketSize; - req->length = rx_bytes_expected(max); - if (req->length < ep->maxpacket) - req->length = ep->maxpacket; + req->length = rx_bytes_expected(ep); } req->actual = 0; @@ -505,7 +534,6 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; char response[FASTBOOT_RESPONSE_LEN]; - unsigned int max; strsep(&cmd, ":"); download_size = simple_strtoul(cmd, NULL, 16); @@ -521,11 +549,7 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req) } else { sprintf(response, "DATA%08x", download_size); req->complete = rx_handler_dl_image; - max = is_high_speed ? hs_ep_out.wMaxPacketSize : - fs_ep_out.wMaxPacketSize; - req->length = rx_bytes_expected(max); - if (req->length < ep->maxpacket) - req->length = ep->maxpacket; + req->length = rx_bytes_expected(ep); } fastboot_tx_write_str(response); } |