void pm860x_charger_print_voltage(void *data) { struct pm860x_charger_info *info = data; int ret; unsigned char read_min = 0; unsigned char read_max = 0; unsigned char buf[2]; unsigned int measured_voltage = 0; ret = pm860x_bulk_read(info->i2c, 0x5b, 1, &read_min); if (ret < 0) { pr_info("\n*********** f a i l e d t o r e a d m i n [%d]\n********\n", ret); } ret = pm860x_bulk_read(info->i2c, 0x63, 1, &read_max); if (ret < 0) { pr_info("\n*********** f a i l e d t o r e a d m a x [%d]\n********\n", ret); } ret = pm860x_bulk_read(info->i2c, 0x6d, 2, buf); if (ret < 0) { pr_info("\n*********** f a i l e d t o r e a d m e a s u r e d [%d]\n********\n", ret); } pr_info( \ "\n***********\n min reg: =[0x%x], max reg =[0x%x], measured reg -0x6d =[0x%x], measured reg 0x6e = [0x%x]\n********\n", read_min, read_max, buf[0], buf[1] ); measured_voltage = ((buf[0] & 0xff) << 4) | (buf[1] & 0x0f); /* V_MEAS(mV) = data * 3 * 1.8 * 1000 / (2^12) */ measured_voltage = ((measured_voltage & 0xfff) * 5400) >> 12; pr_info( \ "\n***********\n measured calculated mV, as taken from the spec= [%d]\n********\n", measured_voltage); }
static int measure_vchg(struct pm860x_charger_info *info, int *data) { unsigned char buf[2]; int ret = 0; ret = pm860x_bulk_read(info->i2c, PM8607_VCHG_MEAS1, 2, buf); if (ret < 0) return ret; *data = ((buf[0] & 0xff) << 4) | (buf[1] & 0x0f); /* V_BATT_MEAS(mV) = value * 5 * 1.8 * 1000 / (2^12) */ *data = ((*data & 0xfff) * 9 * 125) >> 9; dev_dbg(info->dev, "%s, vchg: %d mv\n", __func__, *data); return ret; }
static void pm860x_led_work(struct work_struct *work) { struct pm860x_led *led; struct pm860x_chip *chip; unsigned char buf[3]; int mask, ret; led = container_of(work, struct pm860x_led, work); chip = led->chip; mutex_lock(&led->lock); if ((led->current_brightness == 0) && led->brightness) { led_power_set(chip, led->port, 1); if (led->iset) { pm860x_set_bits(led->i2c, __led_off(led->port), LED_CURRENT_MASK, led->iset); } pm860x_set_bits(led->i2c, __blink_off(led->port), LED_BLINK_MASK, LED_ON_CONTINUOUS); mask = __blink_ctl_mask(led->port); pm860x_set_bits(led->i2c, PM8606_WLED3B, mask, mask); } pm860x_set_bits(led->i2c, __led_off(led->port), LED_PWM_MASK, led->brightness); if (led->brightness == 0) { pm860x_bulk_read(led->i2c, __led_off(led->port), 3, buf); ret = buf[0] & LED_PWM_MASK; ret |= buf[1] & LED_PWM_MASK; ret |= buf[2] & LED_PWM_MASK; if (ret == 0) { /* */ pm860x_set_bits(led->i2c, __led_off(led->port), LED_CURRENT_MASK, 0); mask = __blink_ctl_mask(led->port); pm860x_set_bits(led->i2c, PM8606_WLED3B, mask, 0); led_power_set(chip, led->port, 0); } } led->current_brightness = led->brightness; dev_dbg(chip->dev, "Update LED. (reg:%d, brightness:%d)\n", __led_off(led->port), led->brightness); mutex_unlock(&led->lock); }