int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val) { int ret; mutex_lock(&twl6040->io_mutex); ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, val, reg); mutex_unlock(&twl6040->io_mutex); return ret; }
static void omap4430_keypad_led_store(struct led_classdev *led_cdev, enum led_brightness value) { u8 brightness = 0; if (value > 1) { if (value == LED_FULL) brightness = 0x7f; else brightness = (~(value/2)) & 0x7f; twl_i2c_write_u8(TWL_MODULE_PWM, brightness, KP_LED_PWM1ON); twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x36, KP_LED_TOGGLE3); } else { twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x31, KP_LED_TOGGLE3); twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x37, KP_LED_TOGGLE3); } }
static inline void twl4030_enable_write(void) { int err; err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PWR_PROTECT_KEY); if (err) { printk(KERN_WARNING "I2C error %d while writing TWL4030 PM_MASTER PWR_PROTECT_KEY\n", err); return ; } err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x0C, PWR_PROTECT_KEY); if (err) { printk(KERN_WARNING "I2C error %d while writing TWL4030 PM_MASTER PWR_PROTECT_KEY\n", err); return ; } }
static void twl6030_phy_shutdown(struct otg_transceiver *x) { struct twl6030_usb *twl; struct device *dev; struct twl4030_usb_data *pdata; /* USB_VBUS_CTRL_CLR */ twl_i2c_write_u8(TWL6030_MODULE_ID1, 0xFF, 0x05); /* USB_ID_CRTL_CLR */ twl_i2c_write_u8(TWL6030_MODULE_ID1, 0xFF, 0x07); /* CHARGERUSB_CTRL3 */ twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x21, 0xEA); twl = xceiv_to_twl(x); dev = twl->dev; pdata = dev->platform_data; pdata->phy_power(twl->dev, 0, 0); }
/* * Supports 1 byte write to TWL RTC registers. */ static int twl_rtc_write_u8(u8 data, u8 reg) { int ret; ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); if (ret < 0) pr_err("twl_rtc: Could not write TWL" "register %X - error %d\n", reg, ret); return ret; }
void pwm_free(struct pwm_device *pwm) { u8 val = 0; pwm_disable(pwm); switch (pwm->pwm_id) { case 3: /* Custom PWM2 */ twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, TWL6030_TOGGLE3); twl_i2c_write_u8(TWL6030_MODULE_ID1, (val | TOGGLE3_PWM2_RESET), TWL6030_TOGGLE3); twl_i2c_write_u8(TWL6030_MODULE_ID1, (val | TOGGLE3_PWM2_RESET) & ~TOGGLE3_PWM2_CLK_EN, TWL6030_TOGGLE3); break; case 2: /* Custom PWM1 */ twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, TWL6030_TOGGLE3); twl_i2c_write_u8(TWL6030_MODULE_ID1, (val | TOGGLE3_PWM1_RESET), TWL6030_TOGGLE3); twl_i2c_write_u8(TWL6030_MODULE_ID1, (val | TOGGLE3_PWM1_RESET) & ~TOGGLE3_PWM1_CLK_EN, TWL6030_TOGGLE3); break; default: break; } kfree(pwm); }
int twl6030_mmc_card_detect_config(void) { int ret; u8 reg_val = 0; twl6030_interrupt_unmask(TWL6030_MMCDETECT_INT_MASK, REG_INT_MSK_LINE_B); twl6030_interrupt_unmask(TWL6030_MMCDETECT_INT_MASK, REG_INT_MSK_STS_B); ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, ®_val, TWL6030_MMCCTRL); if (ret < 0) { pr_err("twl6030: Failed to read MMCCTRL, error %d\n", ret); return ret; } reg_val &= ~VMMC_AUTO_OFF; reg_val |= SW_FC; ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, reg_val, TWL6030_MMCCTRL); if (ret < 0) { pr_err("twl6030: Failed to write MMCCTRL, error %d\n", ret); return ret; } ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, ®_val, TWL6030_CFG_INPUT_PUPD3); if (ret < 0) { pr_err("twl6030: Failed to read CFG_INPUT_PUPD3, error %d\n", ret); return ret; } reg_val &= ~(MMC_PU | MMC_PD); ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, reg_val, TWL6030_CFG_INPUT_PUPD3); if (ret < 0) { pr_err("twl6030: Failed to write CFG_INPUT_PUPD3, error %d\n", ret); return ret; } return twl6030_irq_base + MMCDETECT_INTR_OFFSET; }
static void vibra_disable_leds(void) { u8 reg; /* Disable LEDA & LEDB, cannot be used with vibra (PWM) */ twl_i2c_read_u8(TWL4030_MODULE_LED, ®, LEDEN); //reg &= ~0x03; reg &= ~0x33; //twl_i2c_write_u8(TWL4030_MODULE_LED, LEDEN, reg); twl_i2c_write_u8(TWL4030_MODULE_LED, reg, LEDEN); }
int twl6030_interrupt_mask(u8 bit_mask, u8 offset) { int ret; u8 mask_value; ret = twl_i2c_read_u8(TWL_MODULE_PIH, &mask_value, REG_INT_STS_A + offset); mask_value |= (bit_mask); ret |= twl_i2c_write_u8(TWL_MODULE_PIH, mask_value, REG_INT_STS_A + offset); /* mask INT_MSK_A/B/C */ return ret; }
static int __init twl4030_poweroff_init(void) { u8 pwrana2_val = 0; // Unlock PROTECT_KEY reg's KEY_TST flag. twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x0E, R_PROTECT_KEY); twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xE0, R_PROTECT_KEY); // Get the current PWRANA2 value. twl_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &pwrana2_val, R_CFG_PWRANA2); // Make LOJIT1_LOWV (bit 2) and LOJIT0_LOWV (bit 1) 1. pwrana2_val &= 0xFF; twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, pwrana2_val, R_CFG_PWRANA2); // Lock back PROTECT_KEY reg's KEY_TST flag. twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xFF, R_PROTECT_KEY); printk(KERN_WARNING "[kernel: twl4030_poweroff_init] PWRANA2 was set to low jitter mode\n"); pm_power_off = twl4030_poweroff; return 0; }
static inline int twl6030_writeb(struct twl6030_usb *twl, u8 module, u8 data, u8 address) { int ret = 0; ret = twl_i2c_write_u8(module, data, address); if (ret < 0) dev_err(twl->dev, "Write[0x%x] Error %d\n", address, ret); return ret; }
static int omap3evm_bklight_setlevel(struct lcd_panel *panel, unsigned int level) { u8 c; if ((level >= 0) && (level <= 100)) { c = (125 * (100 - level)) / 100 + 2; twl_i2c_write_u8(TWL4030_MODULE_PWMA, c, TWL_PWMA_PWMAOFF); bklight_level = level; } return 0; }
/*----------------------------------------------------------------------*/ int twl6030_interrupt_unmask(u8 bit_mask, u8 offset) { int ret; u8 unmask_value; ret = twl_i2c_read_u8(TWL_MODULE_PIH, &unmask_value, REG_INT_STS_A + offset); unmask_value &= (~(bit_mask)); ret |= twl_i2c_write_u8(TWL_MODULE_PIH, unmask_value, REG_INT_STS_A + offset); /* unmask INT_MSK_A/B/C */ return ret; }
static inline int twl6030_writeb(struct twl6030_pwr_button *twl, u8 module, u8 data, u8 address) { int ret = 0; ret = twl_i2c_write_u8(module, data, address); if (ret < 0) dev_dbg(twl->dev, "TWL6030:Write[0x%x] Error %d\n", address, ret); return ret; }
static inline int twl4030_usb_write(struct twl4030_usb *twl, u8 address, u8 data) { int ret = 0; ret = twl_i2c_write_u8(TWL_MODULE_USB, data, address); if (ret < 0) dev_dbg(twl->dev, "TWL4030:USB:Write[0x%x] Error %d\n", address, ret); return ret; }
static int omapbl_set_intensity(struct backlight_device *bd) { int intensity = bd->props.brightness; int ret; u8 c; if (bd->props.power != FB_BLANK_UNBLANK) intensity = 0; if (bd->props.fb_blank != FB_BLANK_UNBLANK) intensity = 0; if (omapbl_flags & OMAPBL_SUSPENDED) intensity = 0; if (intensity == 0) printk("Backlight turned off\n"); c = ((125 * intensity) / 100) + 2; #if 0 if (intensity > 100) { twl_i2c_read_u8(TWL4030_MODULE_INTBR, &c, 0x0c); c &= ~(1 << 3); twl_i2c_write_u8 (TWL4030_MODULE_INTBR, c, 0x0c); return ret; } #endif /* * Program the OFF register of PWM1 with user values */ ret = twl_i2c_write_u8(TWL4030_MODULE_PWM1, c, TWL_PWM1_PWM1OFF); if (ret) { printk("i2c write failed\n"); return ret; } // printk(KERN_INFO "Backlight altered with value %d.\n", intensity); panel_intensity = intensity; return 0; }
static int twl4030_config_wakeup3_sequence(u8 address) { int err; u8 data; /* Set SLEEP to ACTIVE SEQ address for P3 */ err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_S2A3); if (err) goto out; /* P3 LVL_WAKEUP should be on LEVEL */ err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data, R_P3_SW_EVENTS); if (err) goto out; data |= LVL_WAKEUP; err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data, R_P3_SW_EVENTS); out: if (err) pr_err("TWL4030 wakeup sequence for P3 config error\n"); return err; }
static int twl4030_config_sleep_sequence(u8 address) { int err; /* Set ACTIVE to SLEEP SEQ address in T2 memory*/ err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_A2S); if (err) pr_err("TWL4030 sleep sequence config error\n"); return err; }
static int dsi1_panel_set_backlight(struct omap_dss_device *dssdev, int level) { int r; r = twl_i2c_write_u8(TWL_MODULE_PWM, 0x7F, LED_PWM2OFF); if (r) return r; if (level > 1) { if (level == 255) level = 0x7F; else level = (~(level/2)) & 0x7F; r = twl_i2c_write_u8(TWL_MODULE_PWM, level, LED_PWM2ON); if (r) return r; r = twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x30, TWL6030_TOGGLE3); if (r) return r; } else if (level <= 1) { r = twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x08, TWL6030_TOGGLE3); if (r) return r; r = twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x28, TWL6030_TOGGLE3); if (r) return r; r = twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x00, TWL6030_TOGGLE3); if (r) return r; } return 0; }
static int twl4030_config_warmreset_sequence(u8 address) { int err; u8 rd_data; /* Set WARM RESET SEQ address for P1 */ err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_WARM); if (err) goto out; /* P1/P2/P3 enable WARMRESET */ err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P1_SW_EVENTS); if (err) goto out; rd_data |= ENABLE_WARMRESET; err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P1_SW_EVENTS); if (err) goto out; err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P2_SW_EVENTS); if (err) goto out; rd_data |= ENABLE_WARMRESET; err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P2_SW_EVENTS); if (err) goto out; err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P3_SW_EVENTS); if (err) goto out; rd_data |= ENABLE_WARMRESET; err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P3_SW_EVENTS); out: if (err) pr_err("TWL4030 warmreset seq config error\n"); return err; }
void twl4030_poweroff(void) { u8 uninitialized_var(val); int err; /* Make sure SEQ_OFFSYNC is set so that all the res goes to wait-on */ err = twl_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &val, CFG_P123_TRANSITION); if (err) { pr_warning("I2C error %d while reading TWL4030 PM_MASTER CFG_P123_TRANSITION\n", err); return; } val |= SEQ_OFFSYNC; err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, val, CFG_P123_TRANSITION); if (err) { pr_warning("I2C error %d while writing TWL4030 PM_MASTER CFG_P123_TRANSITION\n", err); return; } err = twl_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &val, PWR_P1_SW_EVENTS); if (err) { pr_warning("I2C error %d while reading TWL4030 PM_MASTER P1_SW_EVENTS\n", err); return; } val |= PWR_STOPON_POWERON | PWR_DEVOFF; err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, val, PWR_P1_SW_EVENTS); if (err) { pr_warning("I2C error %d while writing TWL4030 PM_MASTER P1_SW_EVENTS\n", err); return; } return; }
static int omap3evm_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev) { gpio_request(LCD_PANEL_LR, "LCD lr"); gpio_request(LCD_PANEL_UD, "LCD ud"); gpio_request(LCD_PANEL_INI, "LCD ini"); gpio_request(LCD_PANEL_RESB, "LCD resb"); gpio_request(LCD_PANEL_QVGA, "LCD qvga"); gpio_direction_output(LCD_PANEL_RESB, 1); gpio_direction_output(LCD_PANEL_INI, 1); gpio_direction_output(LCD_PANEL_QVGA, 0); gpio_direction_output(LCD_PANEL_LR, 1); gpio_direction_output(LCD_PANEL_UD, 1); twl_i2c_write_u8(TWL4030_MODULE_LED, 0x11, TWL_LED_LEDEN); twl_i2c_write_u8(TWL4030_MODULE_PWMA, 0x01, TWL_PWMA_PWMAON); twl_i2c_write_u8(TWL4030_MODULE_PWMA, 0x02, TWL_PWMA_PWMAOFF); bklight_level = 100; return 0; }
static int __devinit twl4030_config_sleep_sequence(u8 address) { int err; err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address, R_SEQ_ADD_A2S); if (err) pr_err("TWL4030 sleep sequence config error\n"); return err; }
static void twl6030_config_limit1_reg(struct charger_device_info *di, unsigned int voltagemV) { if ((voltagemV < 3500) || (voltagemV > 4760)) { dev_dbg(di->dev, "invalid max_charger_voltagemV\n"); return; } voltagemV = (voltagemV - 3500) / 20; twl_i2c_write_u8(TWL6030_MODULE_CHARGER, voltagemV, CHARGERUSB_CTRLLIMIT1); return; }
static void twl6030_config_iterm_reg(struct charger_device_info *di, unsigned int term_currentmA) { if ((term_currentmA > 400) || (term_currentmA < 50)) { dev_dbg(di->dev, "invalid termination current\n"); return; } term_currentmA = ((term_currentmA - 50)/50) << 5; twl_i2c_write_u8(TWL6030_MODULE_CHARGER, term_currentmA, CHARGERUSB_CTRL2); return; }
/* Send a word over the powerbus */ static int twl4030_send_pb_msg(unsigned msg) { u8 val; int ret; /* save powerbus configuration */ ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val, TWL4030_PM_MASTER_PB_CFG); if (ret < 0) return ret; /* Enable i2c access to powerbus */ ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val | PB_I2C_BWEN, TWL4030_PM_MASTER_PB_CFG); if (ret < 0) return ret; ret = twl4030_wait_pb_ready(); if (ret < 0) return ret; ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg >> 8, TWL4030_PM_MASTER_PB_WORD_MSB); if (ret < 0) return ret; ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB); if (ret < 0) return ret; ret = twl4030_wait_pb_ready(); if (ret < 0) return ret; /* Restore powerbus configuration */ return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val, TWL4030_PM_MASTER_PB_CFG); }
static void twl6030_bci_battery_update_status(struct twl6030_bci_device_info *di) { if (charger_source == 1) { /* reconfig params for ac charging & reset 32 second timer */ twl_i2c_write_u8(TWL6030_MODULE_BQ, 0xC0, REG_STATUS_CONTROL); twl_i2c_write_u8(TWL6030_MODULE_BQ, 0xC8, REG_CONTROL_REGISTER); twl_i2c_write_u8(TWL6030_MODULE_BQ, 0x7C, REG_CONTROL_BATTERY_VOLTAGE); twl_i2c_write_u8(TWL6030_MODULE_BQ, 0x51, REG_BATTERY_TERMINATION); twl_i2c_write_u8(TWL6030_MODULE_BQ, 0x02, REG_SPECIAL_CHARGER_VOLTAGE); } twl6030_bci_battery_read_status(di); di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; if (power_supply_am_i_supplied(&di->bat)) di->charge_status = POWER_SUPPLY_STATUS_CHARGING; else di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; }
/* * In master mode, start the power off sequence. * After a successful execution, TWL shuts down the power to the SoC * and all peripherals connected to it. */ void twl4030_power_off(void) { int err; /* Disable start on charger or VBUS as it can break poweroff */ err = twl4030_starton_mask_and_set(STARTON_VBUS | STARTON_CHG, 0); if (err) pr_err("TWL4030 Unable to configure start-up\n"); err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, PWR_DEVOFF, TWL4030_PM_MASTER_P1_SW_EVENTS); if (err) pr_err("TWL4030 Unable to power off\n"); }
static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl, u8 module, u8 data, u8 address) { u8 check; if ((twl_i2c_write_u8(module, data, address) >= 0) && (twl_i2c_read_u8(module, &check, address) >= 0) && (check == data)) return 0; dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", 1, module, address, check, data); /* Failed once: Try again */ if ((twl_i2c_write_u8(module, data, address) >= 0) && (twl_i2c_read_u8(module, &check, address) >= 0) && (check == data)) return 0; dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", 2, module, address, check, data); /* Failed again: Return error */ return -EBUSY; }
static int twl6040_i2c_write(u8 reg, u8 value) { int ret = -1; int cnt = 0; // sometimes, twl6040 make error. so, retry more... while( ret < 0 && cnt++ < TWL6040_I2C_RETRY_MAX ){ ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, value, reg); if( ret < 0 ) msleep(5); } return ret; }