Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pm2301-charger: Add pm_runtime_resume & pm_runtime_suspend

To optimize the current consumption we use pm_runtime autosuspend
functions which execute the pm_runtime_suspend after a delay of
inactivity on the other hand we use pm_runtime_resume every time
we receive an interruption to wake up the pm2301.

Signed-off-by: M BenZoubeir <mustapha.ben.zoubeir-xsig@stericsson.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Reviewed-by: Philippe LANGLAIS <philippe.langlais@stericsson.com>

Lee Jones aee2b846 f4095a0f

+68
+68
drivers/power/pm2301_charger.c
··· 29 29 #include <linux/mfd/abx500/ux500_chargalg.h> 30 30 #include <linux/pm2301_charger.h> 31 31 #include <linux/gpio.h> 32 + #include <linux/pm_runtime.h> 32 33 33 34 #include "pm2301_charger.h" 34 35 ··· 37 36 struct pm2xxx_charger, ac_chg) 38 37 #define SLEEP_MIN 50 39 38 #define SLEEP_MAX 100 39 + #define PM2XXX_AUTOSUSPEND_DELAY 500 40 40 41 41 static int pm2xxx_interrupt_registers[] = { 42 42 PM2XXX_REG_INT1, ··· 495 493 struct pm2xxx_interrupts *interrupt = pm2->pm2_int; 496 494 int i; 497 495 496 + /* wake up the device */ 497 + pm_runtime_get_sync(pm2->dev); 498 + 498 499 do { 499 500 for (i = 0; i < PM2XXX_NUM_INT_REG; i++) { 500 501 pm2xxx_reg_read(pm2, ··· 508 503 interrupt->handler[i](pm2, interrupt->reg[i]); 509 504 } 510 505 } while (gpio_get_value(pm2->pdata->gpio_irq_number) == 0); 506 + 507 + pm_runtime_mark_last_busy(pm2->dev); 508 + pm_runtime_put_autosuspend(pm2->dev); 511 509 512 510 return IRQ_HANDLED; 513 511 } ··· 954 946 return 0; 955 947 } 956 948 949 + #ifdef CONFIG_PM 950 + static int pm2xxx_runtime_suspend(struct device *dev) 951 + { 952 + struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev); 953 + struct pm2xxx_charger *pm2; 954 + int ret = 0; 955 + 956 + pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client); 957 + if (!pm2) { 958 + dev_err(pm2->dev, "no pm2xxx_charger data supplied\n"); 959 + ret = -EINVAL; 960 + return ret; 961 + } 962 + 963 + clear_lpn_pin(pm2); 964 + 965 + return ret; 966 + } 967 + 968 + static int pm2xxx_runtime_resume(struct device *dev) 969 + { 970 + struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev); 971 + struct pm2xxx_charger *pm2; 972 + int ret = 0; 973 + 974 + pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client); 975 + if (!pm2) { 976 + dev_err(pm2->dev, "no pm2xxx_charger data supplied\n"); 977 + ret = -EINVAL; 978 + return ret; 979 + } 980 + 981 + if (gpio_is_valid(pm2->lpn_pin) && gpio_get_value(pm2->lpn_pin) == 0) 982 + set_lpn_pin(pm2); 983 + 984 + return ret; 985 + } 986 + 987 + static const struct dev_pm_ops pm2xxx_pm_ops = { 988 + .runtime_suspend = pm2xxx_runtime_suspend, 989 + .runtime_resume = pm2xxx_runtime_resume, 990 + }; 991 + #define PM2XXX_PM_OPS (&pm2xxx_pm_ops) 992 + #else 993 + #define PM2XXX_PM_OPS NULL 994 + #endif 995 + 957 996 static int pm2xxx_wall_charger_probe(struct i2c_client *i2c_client, 958 997 const struct i2c_device_id *id) 959 998 { ··· 1132 1077 gpio_to_irq(pm2->pdata->gpio_irq_number), ret); 1133 1078 goto unregister_pm2xxx_charger; 1134 1079 } 1080 + 1081 + ret = pm_runtime_set_active(pm2->dev); 1082 + if (ret) 1083 + dev_err(pm2->dev, "set active Error\n"); 1084 + 1085 + pm_runtime_enable(pm2->dev); 1086 + pm_runtime_set_autosuspend_delay(pm2->dev, PM2XXX_AUTOSUSPEND_DELAY); 1087 + pm_runtime_use_autosuspend(pm2->dev); 1088 + pm_runtime_resume(pm2->dev); 1089 + 1135 1090 /* pm interrupt can wake up system */ 1136 1091 ret = enable_irq_wake(gpio_to_irq(pm2->pdata->gpio_irq_number)); 1137 1092 if (ret) { ··· 1213 1148 { 1214 1149 struct pm2xxx_charger *pm2 = i2c_get_clientdata(i2c_client); 1215 1150 1151 + /* Disable pm_runtime */ 1152 + pm_runtime_disable(pm2->dev); 1216 1153 /* Disable AC charging */ 1217 1154 pm2xxx_charger_ac_en(&pm2->ac_chg, false, 0, 0); 1218 1155 ··· 1256 1189 .driver = { 1257 1190 .name = "pm2xxx-wall_charger", 1258 1191 .owner = THIS_MODULE, 1192 + .pm = PM2XXX_PM_OPS, 1259 1193 }, 1260 1194 .id_table = pm2xxx_id, 1261 1195 };