static inline uint8_t tps65913_read(enum TPS65913_RTC_REG reg) { uint8_t val; i2c_readb(CONFIG_DRIVERS_TI_TPS65913_RTC_BUS, CONFIG_DRIVERS_TI_TPS65913_RTC_ADDR, reg, &val); return val; }
static uint64_t reg_read(struct reg_script_context *ctx) { int ret_code; const struct reg_script *step; uint8_t value = 0; 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: if (ctx->display_features) printk(BIOS_INFO, "I2C chip 0x%02x: ", step->id); ret_code = i2c_readb(0, step->id, (uint8_t)step->reg, &value); ASSERT(ret_code == 2); break; } return value; }
static uint8_t as3722_read(enum AS3722_RTC_REG reg) { uint8_t val; i2c_readb(CONFIG_DRIVERS_AS3722_RTC_BUS, CONFIG_DRIVERS_AS3722_RTC_ADDR, reg, &val); return val; }
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 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 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(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 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 pmic_read_reg(unsigned bus, uint16_t reg, uint8_t *data) { if (i2c_readb(bus, PAGE_ADDR(reg), PAGE_OFFSET(reg), data)) { printk(BIOS_ERR, "%s: page = 0x%02X, reg = 0x%02X failed!\n", __func__, PAGE_ADDR(reg), PAGE_OFFSET(reg)); 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; }
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); }
void isp1301_update(struct reg_list *list) { for (; list && list->name; list++) { //TRACE_MSG1(TCD, "list: %s", list->name); memmove(list->values + 1, list->values, sizeof(list->values) - sizeof(u32)); switch(list->size) { case 1: list->values[0] = i2c_readb(list->reg); break; case 2: list->values[0] = i2c_readw(list->reg); break; case 4: list->values[0] = i2c_readl(list->reg); break; } } }
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; }
/* * Read a value from 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_read(unsigned int bus, unsigned char chip_addr, unsigned int reg, unsigned char *val) { return i2c_readb(bus, chip_addr, reg, (uint8_t *)val); }
static int rk808_read(uint8_t reg, uint8_t *value) { return i2c_readb(CONFIG_PMIC_BUS, RK808_ADDR, reg, value); }
int do_cbrand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int pos = 0; uint8_t hdr[4] = { 's', 'e', 'x', 'i' }; uint8_t ftr[4] = { 'p', 'u', 's', '!' }; uint8_t cmp[4]; setenv("brand", "chumby"); i2c_init(0); // Read in the header and verify it. for(pos=0; pos<sizeof(hdr) && pos<768; pos++) { if(i2c_readb(0x50, pos, cmp+pos)) { printf("I2C read error\n"); return 1; } } if(memcmp(hdr, cmp, sizeof(hdr))) { printf("DCID is uninitialized\n"); return 1; } // Continue looking until either (1) we get 'part', or (2) we fall off. while(pos<768) { uint16_t size; uint8_t container; int blk_pos; for(blk_pos=0; blk_pos<sizeof(cmp) && pos<768; blk_pos++) { if(i2c_readb(0x50+((pos>>8)&3), pos&0x00000000ff, cmp+blk_pos)) { printf("I2C read error\n"); return 1; } pos++; } if(cmp[0]=='p' && cmp[1]=='u' && cmp[2]=='s' && cmp[3]=='!') { return 0; } // Since it's not the footer, we have another tag to read. Figure // out the size, then copy the rest of the tag title. container = (cmp[1] & 0x80); ((uint8_t *)&size)[1] = cmp[0]; ((uint8_t *)&size)[0] = cmp[1] & 0x7f; size -= 6; // Strip the header off the size. cmp[0] = cmp[2]; cmp[1] = cmp[3]; if(i2c_readb(0x50+(pos>>8), pos&0xff, cmp+2)) { printf("I2C read error\n"); return 1; } pos++; if(i2c_readb(0x50+(pos>>8), pos&0xff, cmp+3)) { printf("I2C read error\n"); return 1; } pos++; if(!container) { char data[size+1]; data[size]='\0'; for(blk_pos=0; blk_pos<size && pos<768; blk_pos++) { i2c_readb(0x50+(pos>>8), pos&0xff, data+blk_pos); pos++; } if(cmp[0]=='p' && cmp[1]=='a' && cmp[2]=='r' && cmp[3]=='t') { //int partnum = simple_strtoul(data, NULL, 0); uint16_t partnum; char partnum_s[16] = "1001"; // The DCID is stored in a very... special... manner. ((uint8_t *)&partnum)[0] = data[0]; ((uint8_t *)&partnum)[1] = data[1]; sprintf(partnum_s, "%02X%02X", data[0], data[1]); // Set the brand from a hardcoded lookup table. if(partnum==272) setenv("brand", "insignia"); setenv("brandnum", partnum_s); return partnum; } } }
static int max98090_i2c_read(Max98090Codec *codec, uint8_t reg, uint8_t *data) { return i2c_readb(codec->i2c, codec->chip, reg, data); }