static void ioexpander_init(void *unused) { printk(BIOS_DEBUG, "Programming TCA6424A I/O expander\n"); /* I/O Expander 1, Port 0 Data */ i2c_writeb(IO_EXPANDER_BUS, IO_EXPANDER_0_ADDR, IO_EXPANDER_P0DOUT, 0xF7); /* Port 0 Configuration */ i2c_writeb(IO_EXPANDER_BUS, IO_EXPANDER_0_ADDR, IO_EXPANDER_P0CONF, 0xE0); /* Port 1 Data */ i2c_writeb(IO_EXPANDER_BUS, IO_EXPANDER_0_ADDR, IO_EXPANDER_P1DOUT, 0x9E); /* Port 1 Configuration */ i2c_writeb(IO_EXPANDER_BUS, IO_EXPANDER_0_ADDR, IO_EXPANDER_P1CONF, 0x8C); /* Port 2 Data */ i2c_writeb(IO_EXPANDER_BUS, IO_EXPANDER_0_ADDR, IO_EXPANDER_P2DOUT, 0xDA); /* Port 2 Configuration */ i2c_writeb(IO_EXPANDER_BUS, IO_EXPANDER_0_ADDR, IO_EXPANDER_P2CONF, 0x08); /* I/O Expander 2, Port 0 Data */ i2c_writeb(IO_EXPANDER_BUS, IO_EXPANDER_1_ADDR, IO_EXPANDER_P0DOUT, 0xFF); /* Port 0 Configuration */ i2c_writeb(IO_EXPANDER_BUS, IO_EXPANDER_1_ADDR, IO_EXPANDER_P0CONF, 0x00); }
int tis_init(void) { int bus = CONFIG_DRIVER_TPM_I2C_BUS; int chip = CONFIG_DRIVER_TPM_I2C_ADDR; /* * Probe TPM twice; the first probing might fail because TPM is asleep, * and the probing can wake up TPM. */ if (i2c_writeb(bus, chip, 0, 0) && i2c_writeb(bus, chip, 0, 0)) return -1; return 0; }
static int setup_power(int is_resume) { int error = 0; int i; power_init(); if (is_resume) { return 0; } /* Initialize I2C bus to configure PMIC. */ exynos_pinmux_i2c4(); i2c_init(PMIC_I2C_BUS, 1000000, 0x00); /* 1MHz */ for (i = 0; i < ARRAY_SIZE(pmic_writes); i++) { uint8_t data = 0; uint8_t reg = pmic_writes[i].reg; if (pmic_writes[i].or_orig) error |= i2c_readb(4, MAX77802_I2C_ADDR, reg, &data); data |= pmic_writes[i].val; error |= i2c_writeb(4, MAX77802_I2C_ADDR, reg, data); } return error; }
static void reg_write(struct reg_script_context *ctx) { int ret_code; const struct reg_script *step; uint8_t value; step = ctx->step; switch (step->id) { default: printk(BIOS_ERR, "ERROR - Unknown register set (0x%08x)!\n", step->id); ctx->display_features = REG_SCRIPT_DISPLAY_NOTHING; break; case GEN1_I2C_GPIO_EXP_0x20: case GEN1_I2C_GPIO_EXP_0x21: case GEN2_I2C_GPIO_EXP0: case GEN2_I2C_GPIO_EXP1: case GEN2_I2C_GPIO_EXP2: case GEN2_I2C_LED_PWM: case RMU_TEMP_REGS: if (ctx->display_features) printk(BIOS_INFO, "I2C chip 0x%02x: ", step->id); value = (uint8_t)step->value; ret_code = i2c_writeb(0, step->id, (uint8_t)step->reg, value); ASSERT(ret_code == 2); break; } }
int ps8640_get_edid(uint8_t bus, uint8_t chip, struct edid *out) { int ret; u8 edid[EDID_LENGTH * 2]; u32 edid_size; i2c_writeb(bus, chip + 2, PAGE2_I2C_BYPASS, EDID_I2C_ADDR | I2C_BYPASS_EN); ret = i2c_read_bytes(bus, EDID_I2C_ADDR, 0, edid, EDID_LENGTH); if (ret != 0) { printk(BIOS_INFO, "Failed to read EDID.\n"); return -1; } /* check if edid have extension flag, and read additional EDID data */ if (edid[EDID_EXTENSION_FLAG]) { edid_size += EDID_LENGTH; ret = i2c_read_bytes(bus, EDID_I2C_ADDR, EDID_LENGTH, &edid[EDID_LENGTH], EDID_LENGTH); if (ret != 0) { printk(BIOS_INFO, "Failed to read EDID ext block.\n"); return -1; } } if (decode_edid(edid, edid_size, out)) { printk(BIOS_INFO, "Failed to decode EDID.\n"); return -1; } return 0; }
static int max77620_set_bit(Max77620Pmic *pmic, uint8_t reg, uint8_t bit) { uint8_t val; if (i2c_readb(pmic->bus, pmic->chip, reg, &val) || i2c_writeb(pmic->bus, pmic->chip, reg, val | bit)) return -1; return 0; }
static int rk808_set_bit(Rk808Pmic *pmic, uint8_t reg, uint8_t bit) { uint8_t val; if (i2c_readb(pmic->bus, pmic->chip, reg, &val) || i2c_writeb(pmic->bus, pmic->chip, reg, val | bit)) return -1; return 0; }
static void rk808_clrsetbits(uint8_t bus, uint8_t reg, uint8_t clr, uint8_t set) { uint8_t value; if (i2c_readb(bus, RK808_ADDR, reg, &value) || i2c_writeb(bus, RK808_ADDR, reg, (value & ~clr) | set)) printk(BIOS_ERR, "ERROR: Cannot set Rk808[%#x]!\n", reg); }
static int rk808_set_bit(I2cOps *bus, uint8_t chip, uint8_t reg, uint8_t bit) { uint8_t val; if (i2c_readb(bus, chip, reg, &val) || i2c_writeb(bus, chip, reg, val | bit)) return -1; return 0; }
int i2c_set_bits(I2cOps *bus, int chip, int reg, int mask_set) { uint8_t tmp; if (i2c_readb(bus, chip, reg, &tmp) < 0) return -1; if (i2c_writeb(bus, chip, reg, tmp | mask_set) < 0) return -1; return 0; }
int i2c_clear_bits(I2cOps *bus, int chip, int reg, int mask_clr) { uint8_t tmp; if (i2c_readb(bus, chip, reg, &tmp) < 0) return -1; if (i2c_writeb(bus, chip, reg, tmp & ~mask_clr) < 0) return -1; return 0; }
void parade_ps8625_bridge_setup(unsigned bus, unsigned chip_base, const struct parade_write *parade_writes, int parade_write_count) { int i; for (i = 0; i < parade_write_count; i++) { const struct parade_write *w = ¶de_writes[i]; i2c_writeb(bus, chip_base + w->offset, w->reg, w->val); } }
static void pmic_write_reg(unsigned bus, uint8_t reg, uint8_t val, int do_delay) { if (i2c_writeb(bus, AS3722_I2C_ADDR, reg, val)) { printk(BIOS_ERR, "%s: reg = 0x%02X, value = 0x%02X failed!\n", __func__, reg, val); /* Reset the SoC on any PMIC write error */ hard_reset(); } else { if (do_delay) udelay(500); } }
void pmic_write_reg(unsigned bus, uint16_t reg, uint8_t val, int delay) { if (i2c_writeb(bus, PAGE_ADDR(reg), PAGE_OFFSET(reg), val)) { printk(BIOS_ERR, "%s: page = 0x%02X, reg = 0x%02X, " "value = 0x%02X failed!\n", __func__, PAGE_ADDR(reg), PAGE_OFFSET(reg), val); /* Reset the SoC on any PMIC write error */ cpu_reset(); } else { if (delay) udelay(500); } }
static void enable_ad4567_spkr_amp(void) { uint8_t reg_byte; if (board_id() >= BOARD_ID_PROTO_3) return; /* * I2C6, device 0x34 is an AD4567 speaker amp on P0/P1. * It needs to have a couple of regs tweaked to turn it on * so it can provide audio output to the mono speaker on P0/P1. */ i2c_readb(I2C6_BUS, AD4567_DEV, PWR_CTL, ®_byte); reg_byte &= ~SPWDN; // power up amp i2c_writeb(I2C6_BUS, AD4567_DEV, PWR_CTL, reg_byte); /* The next 2 settings are defaults, but set them anyway */ i2c_readb(I2C6_BUS, AD4567_DEV, DAC_CTL, ®_byte); reg_byte &= ~DAC_MUTE; // unmute DAC (default) reg_byte &= ~DAC_FS; // mask sample rate bits reg_byte |= SR_32K_48KHZ; // set 32K-48KHz sample rate (default) i2c_writeb(I2C6_BUS, AD4567_DEV, DAC_CTL, reg_byte); }
int ps8640_init(uint8_t bus, uint8_t chip) { u8 set_vdo_done; struct stopwatch sw; stopwatch_init_msecs_expire(&sw, 350); do { i2c_readb(bus, chip + 2, PAGE2_GPIO_H, &set_vdo_done); if (stopwatch_expired(&sw)) { printk(BIOS_INFO, "Failed to init ps8640.\n"); return -1; } } while ((set_vdo_done & PS_GPIO9) != PS_GPIO9); i2c_writeb(bus, chip + 3, PAGE3_SET_ADD, VDO_CTL_ADD); i2c_writeb(bus, chip + 3, PAGE3_SET_VAL, VDO_DIS); i2c_writeb(bus, chip + 3, PAGE3_SET_ADD, VDO_CTL_ADD); i2c_writeb(bus, chip + 3, PAGE3_SET_VAL, VDO_EN); return 0; }
static int rk808_write(uint8_t reg, uint8_t value) { return i2c_writeb(CONFIG_PMIC_BUS, RK808_ADDR, reg, value); }
static inline void tps65913_write(enum TPS65913_RTC_REG reg, uint8_t val) { i2c_writeb(CONFIG_DRIVERS_TI_TPS65913_RTC_BUS, CONFIG_DRIVERS_TI_TPS65913_RTC_ADDR, reg, val); }
static void as3722_write(enum AS3722_RTC_REG reg, uint8_t val) { i2c_writeb(CONFIG_DRIVERS_AS3722_RTC_BUS, CONFIG_DRIVERS_AS3722_RTC_ADDR, reg, val); }
static int max98090_i2c_write(Max98090Codec *codec, uint8_t reg, uint8_t data) { return i2c_writeb(codec->i2c, codec->chip, reg, data); }
/* * Write a value to a register * * @param chip_addr i2c addr for max77686 * @param reg reg number to write * @param val value to be written * */ static inline int max77686_i2c_write(unsigned int bus, unsigned char chip_addr, unsigned int reg, unsigned char val) { return i2c_writeb(bus, chip_addr, reg, val); }
static int max77620_set_reg(Max77620Pmic *pmic, uint8_t reg, uint8_t value) { return i2c_writeb(pmic->bus, pmic->chip, reg, value); }