void rt5033_dump_reg(void) { int rc; rt5033_fled_info_t *info = g_fled_info; u8 reg0 = 0, reg1a = 0, reg19 = 0, reg21 = 0; u8 reg22 = 0, reg26 = 0, reg28 = 0, reg29 = 0; rc = rt5033_reg_read(info->i2c_client, 0x0); if (rc < 0) pr_err("%s: failed to read reg 0, %d\n", __func__, rc); else reg0 = (u8)rc; rc = rt5033_reg_read(info->i2c_client, 0x1a); if (rc < 0) pr_err("%s: failed to read reg 1a, %d\n", __func__, rc); else reg1a = (u8)rc; rc = rt5033_reg_read(info->i2c_client, 0x19); if (rc < 0) pr_err("%s: failed to read reg 19, %d\n", __func__, rc); else reg19 = (u8)rc; rc = rt5033_reg_read(info->i2c_client, 0x21); if (rc < 0) pr_err("%s: failed to read reg 0x21, %d\n", __func__, rc); else reg21 = (u8)rc; rc = rt5033_reg_read(info->i2c_client, 0x22); if (rc < 0) pr_err("%s: failed to read reg 0x22, %d\n", __func__, rc); else reg22 = (u8)rc; rc = rt5033_reg_read(info->i2c_client, 0x26); if (rc < 0) pr_err("%s: failed to read reg 0x26, %d\n", __func__, rc); else reg26 = (u8)rc; rc = rt5033_reg_read(info->i2c_client, 0x28); if (rc < 0) pr_err("%s: failed to read reg 0x28, %d\n", __func__, rc); else reg28 = (u8)rc; rc = rt5033_reg_read(info->i2c_client, 0x29); if (rc < 0) pr_err("%s: failed to read reg 0x29, %d\n", __func__, rc); else reg29 = (u8)rc; pr_info("rt5033_dump_reg: [0]:0x%02X, [1a]:0x%02X, [19]:0x%02X, [21]:0x%02X" ", [22]:0x%02X, [26]:0x%02X, [28]:0x%02X, [29]=0x%02X\n", reg0, reg1a, reg19, reg21, reg22, reg26, reg28, reg29); }
int rt5033_flash_force_enable(int enable) { int rc; rt5033_fled_info_t *info = g_fled_info; u8 pin_ctrl_bit, strobe_sel_bit; rc = rt5033_reg_read(info->i2c_client, RT5033_FLED_FUNCTION1); if (rc < 0) { pr_err("%s: failed to read FLED_Func1 reg, %d\n", __func__, rc); } else { pin_ctrl_bit = (u8)rc & 0x10; strobe_sel_bit = (u8)rc & 0x04; if (pin_ctrl_bit) { pr_err("############## rt5033 flash ###################\n" "rt5033_flash_force_enable: error, flash not ctrlled by gpio!!\n"); pr_err("rt5033_flash_force_enable: error, flash with I2C (mode %s)\n", strobe_sel_bit ? "flash" : "torch"); } } pr_info("rt5033_flash_force_enable: %s\n", enable ? "on" : "off"); return rt5033_fled_enable((struct rt_fled_info *)g_fled_info, enable); }
/* For GPIO operation */ int32_t rt5033_charger_notification(struct rt_fled_info *fled_info, int32_t attach) { rt5033_fled_info_t *info = (rt5033_fled_info_t *)fled_info; int force_torch_en = 0; int chg_status; int reg0x1a; BUG_ON(info == NULL); rt5033_fled_lock(fled_info); info->ta_exist = attach; reg0x1a = rt5033_reg_read(info->i2c_client, 0x1a); reg0x1a |= 0xa0; rt5033_fled_set_ta_status(info->i2c_client, attach); if (attach == 0 && info->boost == 0) { chg_status = rt5033_reg_read(info->i2c_client, 0x00); /* remove TA, re-start FlashEN, * and then become boost mode => torch enabled */ force_torch_en = (chg_status & 0x08) ? 1 : 0; /* Enable hidden bit (Force boosting) for TA/USB detaching * To fix flicking issue for torch while TA is removing */ if (force_torch_en) rt5033_reg_write(info->i2c_client, 0x1a, reg0x1a); } rt5033_set_uug_status(info->i2c_client, attach ? 0x02 : 0x00); if (attach) { /* GPIO mode, 0x1 means disable * Disable it and then enable it */ rt5033_assign_bits(info->i2c_client, RT5033_FLED_FUNCTION2, 0x81, 0x1); rt5033_assign_bits(info->i2c_client, RT5033_FLED_FUNCTION2, 0x81, 0x0); } rt5033_fled_unlock(fled_info); /* Disable hidden bit (Force boosting) for TA/USB detaching * To fix flicking issue for torch while TA is removing */ if (force_torch_en) { usleep_range(2500, 2500); rt5033_clr_bits(info->i2c_client, 0x1a, 0x80); } RT5033_FLED_INFO("force_torch_en = %d\n", force_torch_en); return 0; }
static int rt5033_regulator_get_voltage_sel(struct regulator_dev *rdev) { struct rt5033_regulator_info *info = rdev_get_drvdata(rdev); int ret; ret = rt5033_reg_read(info->i2c, info->vol_reg); if (ret < 0) return ret; return (ret & info->vol_mask) >> info->vol_shift; }
static int rt5033_fled_get_strobe_timeout_sel(struct rt_fled_info *fled_info) { int rc; rt5033_fled_info_t *info = (rt5033_fled_info_t *)fled_info; rc = rt5033_reg_read(info->i2c_client, RT5033_FLED_STROBE_CONTROL2); if (rc < 0) return rc; return rc & 0x3f; }
static int rt5033_fled_get_lv_protection_sel(struct rt_fled_info *fled_info) { int rc; rt5033_fled_info_t *info = (rt5033_fled_info_t *)fled_info; rc = rt5033_reg_read(info->i2c_client, RT5033_FLED_CONTROL1); if (rc < 0) return rc; return rc & 0x07; }
static int rt5033_fled_get_torch_current_sel(struct rt_fled_info *fled_info) { int rc; rt5033_fled_info_t *info = (rt5033_fled_info_t *)fled_info; rc = rt5033_reg_read(info->i2c_client, RT5033_FLED_CONTROL1); if (rc < 0) return rc; return (rc & 0xf0) >> 4; }
static int rt5033_regulator_is_enabled(struct regulator_dev *rdev) { struct rt5033_regulator_info *info = rdev_get_drvdata(rdev); int ret; ret = rt5033_reg_read(info->i2c, info->enable_reg); if (ret < 0) return ret; return (ret & (info->enable_bit))?1:0; }
static int rt5033_regulator_is_enabled(struct regulator_dev *rdev) { struct rt5033_regulator_info *info = rdev_get_drvdata(rdev); int ret; ret = rt5033_reg_read(info->i2c, info->enable_reg); if (ret < 0) return ret; ret = (ret & (info->enable_bit))?1:0; pr_info("%s %s %s ret (%d)", ALIAS_NAME, rdev->desc->name, __func__, ret); return ret; }
static int rt5033_regulator_init_regs(struct regulator_dev* rdev) { int ret; struct rt5033_regulator_info *info = rdev_get_drvdata(rdev); if (info->desc.id == RT5033_ID_LDO_SAFE) { ret = rt5033_reg_read(info->i2c, 0x00); if (ret < 0) { pr_info("I2C read failed (%d)\n",ret); return ret; } if (ret & (0x01<<2)) //Power Good rt5033_set_bits(info->i2c, RT5033_REGULATOR_REG_OUTPUT_EN, RT5033_REGULATOR_EN_MASK_LDO_SAFE); else rt5033_clr_bits(info->i2c, RT5033_REGULATOR_REG_OUTPUT_EN, RT5033_REGULATOR_EN_MASK_LDO_SAFE); } return 0; }
static int rt5033_regulator_get_status(struct regulator_dev *rdev) { struct rt5033_regulator_info *info = rdev_get_drvdata(rdev); /* REGULATOR_STATUS_OFF, REGULATOR_STATUS_ON, REGULATOR_STATUS_OFF */ int ret = REGULATOR_STATUS_ERROR; /* 2 */ int org_regval, dump_reg; //int sta1, sta2; uint16_t sta1, sta2; #ifndef CONFIG_MFD_RT5033_RESET_GPIO /* if there are no reset solution(MRSTB or I2C), skip reset workaround(always return true) */ if (chip_rev < RT5033A_REV) return REGULATOR_STATUS_ON; #endif rt5033_lock_regulator(info->i2c); /* First time to check it */ msleep(2); org_regval = rt5033_reg_read(info->i2c, 0xf0); rt5033_reg_write(info->i2c, 0xf0, 0x1e); rt5033_assign_bits(info->i2c, 0xf3, 0x03 << 6, 0x2 << 6); sta1 = rt5033_reg_read(info->i2c, 0xf6) & 0x1f; rt5033_assign_bits(info->i2c, 0xf3, 0x03 << 6, 0x3 << 6); sta2 = rt5033_reg_read(info->i2c, 0xf7) & 0x1f; printk("%s status #1[0x%2x]\n", __func__, (sta2 << 8) | sta1); if (check_status_is_vaild(sta1, 0xf6) && check_status_is_vaild(sta2, 0xf7)) goto rt5033_reg_status_ok; /* Failed case, we need to check again */ msleep(2); org_regval = rt5033_reg_read(info->i2c, 0xf0); rt5033_reg_write(info->i2c, 0xf0, 0x1e); rt5033_assign_bits(info->i2c, 0xf3, 0x03 << 6, 0x2 << 6); sta1 = rt5033_reg_read(info->i2c, 0xf6) & 0x1f; rt5033_assign_bits(info->i2c, 0xf3, 0x03 << 6, 0x3 << 6); sta2 = rt5033_reg_read(info->i2c, 0xf7) & 0x1f; printk("%s status #2[0x%2x]\n", __func__, (sta2 << 8) | sta1); if (check_status_is_vaild(sta1, 0xf6) && check_status_is_vaild(sta2, 0xf7)) goto rt5033_reg_status_ok; /* Failed case, dump registers */ dump_reg = rt5033_reg_read(info->i2c, 0x41); printk("%s LDO_CTRL:0x%2X\n", __func__, dump_reg); dump_reg = rt5033_reg_read(info->i2c, 0x47); printk("%s LDO_CTRL:0x%2X\n", __func__, dump_reg); dump_reg = rt5033_reg_read(info->i2c, 0x68); printk("%s PMIC_IRQ_STAT:0x%2X\n", __func__, dump_reg); dump_reg = rt5033_reg_read(info->i2c, 0x69); printk("%s PMIC_IRQ_CTRL:0x%2X\n", __func__, dump_reg); dump_reg = rt5033_reg_read(info->i2c, 0x6A); printk("%s SHDN_CTRL:0x%2X\n", __func__, dump_reg); dump_reg = rt5033_reg_read(info->i2c, 0x6B); printk("%s SHDN_CTRL:0x%2X\n", __func__, dump_reg); goto rt5033_reg_status_exit; rt5033_reg_status_ok: ret = rt5033_regulator_is_enabled(rdev) ? REGULATOR_STATUS_ON : REGULATOR_STATUS_OFF; rt5033_reg_status_exit: rt5033_reg_write(info->i2c, 0xf0, org_regval); rt5033_unlock_regulator(info->i2c); if (ret==REGULATOR_STATUS_ERROR && chip_rev >= RT5033A_REV) ret = REGULATOR_STATUS_UNDEFINED; /* 8 */ pr_err("%s ret:%d\n", __func__, ret); return ret; }