/* * Do I2C/PMU writes to bring up SD card bus power * */ void board_sdmmc_voltage_init(void) { struct udevice *dev; uchar reg, data_buffer[1]; int ret; int i; ret = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, &dev); if (ret) { debug("%s: Cannot find PMIC I2C chip\n", __func__); return; } /* TPS659110: LDO5_REG = 3.3v, ACTIVE to SDMMC1 */ data_buffer[0] = 0x65; reg = 0x32; for (i = 0; i < MAX_I2C_RETRY; ++i) { if (i2c_write(dev, reg, data_buffer, 1)) udelay(100); } /* TPS659110: GPIO7_REG = PDEN, output a 1 to EN_3V3_SYS */ data_buffer[0] = 0x09; reg = 0x67; for (i = 0; i < MAX_I2C_RETRY; ++i) { if (i2c_write(dev, reg, data_buffer, 1)) udelay(100); } }
int as3722_init(struct udevice **devp) { struct udevice *pmic; u8 id, revision; const unsigned int bus = 0; const unsigned int address = 0x40; int err; err = i2c_get_chip_for_busnum(bus, address, &pmic); if (err) return err; err = as3722_read_id(pmic, &id, &revision); if (err < 0) { error("failed to read ID: %d", err); return err; } if (id != AS3722_DEVICE_ID) { error("unknown device"); return -ENOENT; } debug("AS3722 revision %#x found on I2C bus %u, address %#x\n", revision, bus, address); *devp = pmic; return 0; }
static int nand_sw_detect(void) { int rc; uchar data[2]; struct udevice *dev; rc = i2c_get_chip_for_busnum(NAND_PCF8575_I2C_BUS_NUM, NAND_PCF8575_ADDR, 0, &dev); if (rc) return -1; rc = dm_i2c_read(dev, 0, (uint8_t *)&data, sizeof(data)); if (rc) return -1; /* We are only interested in P10 and P11 on PCF8575 which is equal to * bits 8 and 9. */ data[1] = data[1] & 0x3; /* Ensure only P11 is set and P10 is cleared. This ensures only * NAND (P10) is configured and not NOR (P11) which are both low * true signals. NAND and NOR settings should not be enabled at * the same time. */ if (data[1] == 0x2) return 0; return -1; }
/* * Do I2C/PMU writes to bring up SD card bus power * */ void board_sdmmc_voltage_init(void) { struct udevice *dev; uchar reg, data_buffer[1]; int ret; ret = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev); if (ret) { debug("%s: Cannot find PMIC I2C chip\n", __func__); return; } /* TPS65913: LDO9_VOLTAGE = 3.3V */ data_buffer[0] = 0x31; reg = 0x61; ret = dm_i2c_write(dev, reg, data_buffer, 1); if (ret) printf("%s: PMU i2c_write %02X<-%02X returned %d\n", __func__, reg, data_buffer[0], ret); /* TPS65913: LDO9_CTRL = Active */ data_buffer[0] = 0x01; reg = 0x60; ret = dm_i2c_write(dev, reg, data_buffer, 1); if (ret) printf("%s: PMU i2c_write %02X<-%02X returned %d\n", __func__, reg, data_buffer[0], ret); /* TPS65090: FET6_CTRL = enable output auto discharge, enable FET6 */ data_buffer[0] = 0x03; reg = 0x14; ret = i2c_get_chip_for_busnum(0, BAT_I2C_ADDRESS, 1, &dev); if (ret) { debug("%s: Cannot find charger I2C chip\n", __func__); return; } ret = dm_i2c_write(dev, reg, data_buffer, 1); if (ret) printf("%s: BAT i2c_write %02X<-%02X returned %d\n", __func__, reg, data_buffer[0], ret); }
void pmu_write(uchar reg, uchar data) { struct udevice *dev; int ret; ret = i2c_get_chip_for_busnum(4, PMU_I2C_ADDRESS, 1, &dev); if (ret) { debug("%s: Cannot find PMIC I2C chip\n", __func__); return; } dm_i2c_write(dev, reg, &data, 1); }
/* * Set USB VBUS signals (via I2C IO expander/GPIO) as output and set * output value as disabled * * Set USB Current Limit signals (via I2C IO expander/GPIO) as output * and set output value as enabled */ int board_xhci_config(void) { struct udevice *dev; int ret; u8 buf[8]; if (of_machine_is_compatible("marvell,armada7040-db")) { /* Configure IO exander PCA9555: 7bit address 0x21 */ ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev); if (ret) { printf("Cannot find PCA9555: %d\n", ret); return 0; } /* * Read configuration (direction) and set VBUS pin as output * (reset pin = output) */ ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1); if (ret) { printf("Failed to read IO expander value via I2C\n"); return -EIO; } buf[0] &= ~I2C_IO_REG_VBUS; buf[0] &= ~I2C_IO_REG_CL; ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1); if (ret) { printf("Failed to set IO expander via I2C\n"); return -EIO; } /* Read output value and configure it */ ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); if (ret) { printf("Failed to read IO expander value via I2C\n"); return -EIO; } buf[0] &= ~I2C_IO_REG_VBUS; buf[0] |= I2C_IO_REG_CL; ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); if (ret) { printf("Failed to set IO expander via I2C\n"); return -EIO; } mdelay(500); /* required delay to let output value settle */ } return 0; }
static int i2c_compat_get_device(uint chip_addr, int alen, struct udevice **devp) { struct dm_i2c_chip *chip; int ret; ret = i2c_get_chip_for_busnum(cur_busnum, chip_addr, alen, devp); if (ret) return ret; chip = dev_get_parent_platdata(*devp); if (chip->offset_len != alen) { printf("I2C chip %x: requested alen %d does not match chip offset_len %d\n", chip_addr, alen, chip->offset_len); return -EADDRNOTAVAIL; } return 0; }
int tegra_pcie_board_init(void) { struct udevice *dev; u8 addr, data[1]; int err; err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev); if (err) { debug("%s: Cannot find PMIC I2C chip\n", __func__); return err; } /* TPS659110: VDD2_OP_REG = 1.05V */ data[0] = 0x27; addr = 0x25; err = dm_i2c_write(dev, addr, data, 1); if (err) { debug("failed to set VDD supply\n"); return err; } /* TPS659110: VDD2_REG 7.5 mV/us, ACTIVE */ data[0] = 0x0D; addr = 0x24; err = dm_i2c_write(dev, addr, data, 1); if (err) { debug("failed to enable VDD supply\n"); return err; } /* TPS659110: LDO6_REG = 1.1V, ACTIVE */ data[0] = 0x0D; addr = 0x35; err = dm_i2c_write(dev, addr, data, 1); if (err) { debug("failed to set AVDD supply\n"); return err; } return 0; }
void pin_mux_mmc(void) { struct udevice *dev; uchar val; int ret; /* Turn on MAX77620 LDO2 to 3.3V for SD card power */ debug("%s: Set LDO2 for VDDIO_SDMMC_AP power to 3.3V\n", __func__); ret = i2c_get_chip_for_busnum(0, MAX77620_I2C_ADDR_7BIT, 1, &dev); if (ret) { printf("%s: Cannot find MAX77620 I2C chip\n", __func__); return; } /* 0xF2 for 3.3v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */ val = 0xF2; ret = dm_i2c_write(dev, MAX77620_CNFG1_L2_REG, &val, 1); if (ret) printf("i2c_write 0 0x3c 0x27 failed: %d\n", ret); }
int board_xhci_enable(void) { struct udevice *dev; int ret; u8 buf[8]; if (of_machine_is_compatible("marvell,armada7040-db")) { /* * This function enables all USB ports simultaniously, * it only needs to get called once */ if (usb_enabled) return 0; /* Configure IO exander PCA9555: 7bit address 0x21 */ ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev); if (ret) { printf("Cannot find PCA9555: %d\n", ret); return 0; } /* Read VBUS output value */ ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); if (ret) { printf("Failed to read IO expander value via I2C\n"); return -EIO; } /* Enable VBUS power: Set output value of VBUS pin as enabled */ buf[0] |= I2C_IO_REG_VBUS; ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); if (ret) { printf("Failed to set IO expander via I2C\n"); return -EIO; } mdelay(500); /* required delay to let output value settle */ usb_enabled = 1; } return 0; }
int tegra_pcie_board_init(void) { struct udevice *dev; u8 addr, data[1]; int err; err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev); if (err) { debug("failed to find PMU bus\n"); return err; } /* TPS659110: LDO1_REG = 1.05V, ACTIVE */ data[0] = 0x15; addr = 0x30; err = dm_i2c_write(dev, addr, data, 1); if (err) { debug("failed to set VDD supply\n"); return err; } /* GPIO: PEX = 3.3V */ err = gpio_request(TEGRA_GPIO(L, 7), "PEX"); if (err < 0) return err; gpio_direction_output(TEGRA_GPIO(L, 7), 1); /* TPS659110: LDO2_REG = 1.05V, ACTIVE */ data[0] = 0x15; addr = 0x31; err = dm_i2c_write(dev, addr, data, 1); if (err) { debug("failed to set AVDD supply\n"); return err; } return 0; }
int arch_misc_init(void) { /* Disable PMIC sleep mode on low supply voltage */ struct udevice *dev; u8 addr, data[1]; int err; err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev); if (err) { debug("%s: Cannot find PMIC I2C chip\n", __func__); return err; } addr = PMU_SUPPLYENE; err = dm_i2c_read(dev, addr, data, 1); if (err) { debug("failed to get PMU_SUPPLYENE\n"); return err; } data[0] &= ~PMU_SUPPLYENE_SYSINEN; data[0] |= PMU_SUPPLYENE_EXITSLREQ; err = dm_i2c_write(dev, addr, data, 1); if (err) { debug("failed to set PMU_SUPPLYENE\n"); return err; } /* make sure SODIMM pin 87 nRESET_OUT is released properly */ pinmux_set_func(PMUX_PINGRP_ATA, PMUX_FUNC_GMI); if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) == NVBOOTTYPE_RECOVERY) printf("USB recovery mode\n"); return 0; }
void reset_cpu(ulong addr) { struct udevice *dev; const u8 pmic_bus = 6; const u8 pmic_addr = 0x5a; u8 data; int ret; ret = i2c_get_chip_for_busnum(pmic_bus, pmic_addr, 1, &dev); if (ret) hang(); ret = dm_i2c_read(dev, 0x13, &data, 1); if (ret) hang(); data |= BIT(1); ret = dm_i2c_write(dev, 0x13, &data, 1); if (ret) hang(); }
int board_late_init(void) { struct udevice *dev; u8 buf[8]; int ret; /* Configure SMSC USB2513 USB Hub: 7bit address 0x2c */ ret = i2c_get_chip_for_busnum(0, 0x2c, 1, &dev); if (ret) { printf("Cannot find USB2513: %d\n", ret); return 0; } /* * The first access to the USB Hub fails sometimes, so lets read * a dummy byte to be sure here */ dm_i2c_read(dev, 0x00, buf, 1); /* * The SMSC hub is not visible on the I2C bus after the first * configuration at power-up. The following code deliberately * does not report upon failure of these I2C write calls. */ buf[0] = 0x93; dm_i2c_write(dev, 0x06, buf, 1); buf[0] = 0xaa; dm_i2c_write(dev, 0xf8, buf, 1); buf[0] = 0x0f; dm_i2c_write(dev, 0xfa, buf, 1); buf[0] = 0x01; dm_i2c_write(dev, 0xff, buf, 1); return 0; }