#define to_pm2xxx_charger_ac_device_info(x) container_of((x), \
struct pm2xxx_charger, ac_chg)
+#define SLEEP_MIN 50
+#define SLEEP_MAX 100
static int pm2xxx_interrupt_registers[] = {
PM2XXX_REG_INT1,
static void set_lpn_pin(struct pm2xxx_charger *pm2)
{
- if (pm2->ac.charger_connected)
- return;
gpio_set_value(pm2->lpn_pin, 1);
+ usleep_range(SLEEP_MIN, SLEEP_MAX);
return;
}
static void clear_lpn_pin(struct pm2xxx_charger *pm2)
{
- if (pm2->ac.charger_connected)
- return;
gpio_set_value(pm2->lpn_pin, 0);
return;
* and receive I2C "acknowledge" from PM2301.
*/
mutex_lock(&pm2->lock);
- set_lpn_pin(pm2);
ret = i2c_smbus_read_i2c_block_data(pm2->config.pm2xxx_i2c, reg,
1, val);
dev_err(pm2->dev, "Error reading register at 0x%x\n", reg);
else
ret = 0;
- clear_lpn_pin(pm2);
mutex_unlock(&pm2->lock);
return ret;
* and receive I2C "acknowledge" from PM2301.
*/
mutex_lock(&pm2->lock);
- set_lpn_pin(pm2);
ret = i2c_smbus_write_i2c_block_data(pm2->config.pm2xxx_i2c, reg,
1, &val);
dev_err(pm2->dev, "Error writing register at 0x%x\n", reg);
else
ret = 0;
- clear_lpn_pin(pm2);
mutex_unlock(&pm2->lock);
return ret;
struct pm2xxx_charger *pm2 = pm2_data;
int ret = 0;
-
if (val & (PM2XXX_INT6_ITVPWR2DROP | PM2XXX_INT6_ITVPWR1DROP)) {
dev_dbg(pm2->dev, "VMPWR drop to VBAT level\n");
}
static int pm2xxx_wall_charger_resume(struct i2c_client *i2c_client)
{
+ struct pm2xxx_charger *pm2;
+
+ pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(i2c_client);
+ set_lpn_pin(pm2);
+
+ /* If we still have a HW failure, schedule a new check */
+ if (pm2->flags.ovv)
+ queue_delayed_work(pm2->charger_wq,
+ &pm2->check_hw_failure_work, 0);
+
return 0;
}
static int pm2xxx_wall_charger_suspend(struct i2c_client *i2c_client,
pm_message_t state)
{
+ struct pm2xxx_charger *pm2;
+
+ pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(i2c_client);
+ clear_lpn_pin(pm2);
+
+ /* Cancel any pending HW failure check */
+ if (delayed_work_pending(&pm2->check_hw_failure_work))
+ cancel_delayed_work(&pm2->check_hw_failure_work);
+
+ flush_work(&pm2->ac_work);
+ flush_work(&pm2->check_main_thermal_prot_work);
+
return 0;
}
goto free_gpio;
}
+ set_lpn_pin(pm2);
ret = pm2xxx_charger_detection(pm2, &val);
if ((ret == 0) && val) {