diff options
Diffstat (limited to 'drivers/regulator/wm8350-regulator.c')
| -rw-r--r-- | drivers/regulator/wm8350-regulator.c | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index 5056e23e441..771eca1066b 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c | |||
| @@ -24,6 +24,9 @@ | |||
| 24 | #include <linux/regulator/driver.h> | 24 | #include <linux/regulator/driver.h> |
| 25 | #include <linux/regulator/machine.h> | 25 | #include <linux/regulator/machine.h> |
| 26 | 26 | ||
| 27 | /* Maximum value possible for VSEL */ | ||
| 28 | #define WM8350_DCDC_MAX_VSEL 0x66 | ||
| 29 | |||
| 27 | /* Microamps */ | 30 | /* Microamps */ |
| 28 | static const int isink_cur[] = { | 31 | static const int isink_cur[] = { |
| 29 | 4, | 32 | 4, |
| @@ -385,6 +388,14 @@ static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev) | |||
| 385 | return wm8350_dcdc_val_to_mvolts(val) * 1000; | 388 | return wm8350_dcdc_val_to_mvolts(val) * 1000; |
| 386 | } | 389 | } |
| 387 | 390 | ||
| 391 | static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev, | ||
| 392 | unsigned selector) | ||
| 393 | { | ||
| 394 | if (selector > WM8350_DCDC_MAX_VSEL) | ||
| 395 | return -EINVAL; | ||
| 396 | return wm8350_dcdc_val_to_mvolts(selector) * 1000; | ||
| 397 | } | ||
| 398 | |||
| 388 | static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) | 399 | static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
| 389 | { | 400 | { |
| 390 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | 401 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| @@ -775,6 +786,14 @@ static int wm8350_ldo_get_voltage(struct regulator_dev *rdev) | |||
| 775 | return wm8350_ldo_val_to_mvolts(val) * 1000; | 786 | return wm8350_ldo_val_to_mvolts(val) * 1000; |
| 776 | } | 787 | } |
| 777 | 788 | ||
| 789 | static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, | ||
| 790 | unsigned selector) | ||
| 791 | { | ||
| 792 | if (selector > WM8350_LDO1_VSEL_MASK) | ||
| 793 | return -EINVAL; | ||
| 794 | return wm8350_ldo_val_to_mvolts(selector) * 1000; | ||
| 795 | } | ||
| 796 | |||
| 778 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, | 797 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, |
| 779 | u16 stop, u16 fault) | 798 | u16 stop, u16 fault) |
| 780 | { | 799 | { |
| @@ -1031,18 +1050,30 @@ static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev) | |||
| 1031 | int dcdc = rdev_get_id(rdev); | 1050 | int dcdc = rdev_get_id(rdev); |
| 1032 | u16 mask, sleep, active, force; | 1051 | u16 mask, sleep, active, force; |
| 1033 | int mode = REGULATOR_MODE_NORMAL; | 1052 | int mode = REGULATOR_MODE_NORMAL; |
| 1053 | int reg; | ||
| 1034 | 1054 | ||
| 1035 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | 1055 | switch (dcdc) { |
| 1036 | return -EINVAL; | 1056 | case WM8350_DCDC_1: |
| 1037 | 1057 | reg = WM8350_DCDC1_FORCE_PWM; | |
| 1038 | if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5) | 1058 | break; |
| 1059 | case WM8350_DCDC_3: | ||
| 1060 | reg = WM8350_DCDC3_FORCE_PWM; | ||
| 1061 | break; | ||
| 1062 | case WM8350_DCDC_4: | ||
| 1063 | reg = WM8350_DCDC4_FORCE_PWM; | ||
| 1064 | break; | ||
| 1065 | case WM8350_DCDC_6: | ||
| 1066 | reg = WM8350_DCDC6_FORCE_PWM; | ||
| 1067 | break; | ||
| 1068 | default: | ||
| 1039 | return -EINVAL; | 1069 | return -EINVAL; |
| 1070 | } | ||
| 1040 | 1071 | ||
| 1041 | mask = 1 << (dcdc - WM8350_DCDC_1); | 1072 | mask = 1 << (dcdc - WM8350_DCDC_1); |
| 1042 | active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask; | 1073 | active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask; |
| 1074 | force = wm8350_reg_read(wm8350, reg) & WM8350_DCDC1_FORCE_PWM_ENA; | ||
| 1043 | sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask; | 1075 | sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask; |
| 1044 | force = wm8350_reg_read(wm8350, WM8350_DCDC1_FORCE_PWM) | 1076 | |
| 1045 | & WM8350_DCDC1_FORCE_PWM_ENA; | ||
| 1046 | dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x", | 1077 | dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x", |
| 1047 | mask, active, sleep, force); | 1078 | mask, active, sleep, force); |
| 1048 | 1079 | ||
| @@ -1150,6 +1181,7 @@ static int wm8350_ldo_is_enabled(struct regulator_dev *rdev) | |||
| 1150 | static struct regulator_ops wm8350_dcdc_ops = { | 1181 | static struct regulator_ops wm8350_dcdc_ops = { |
| 1151 | .set_voltage = wm8350_dcdc_set_voltage, | 1182 | .set_voltage = wm8350_dcdc_set_voltage, |
| 1152 | .get_voltage = wm8350_dcdc_get_voltage, | 1183 | .get_voltage = wm8350_dcdc_get_voltage, |
| 1184 | .list_voltage = wm8350_dcdc_list_voltage, | ||
| 1153 | .enable = wm8350_dcdc_enable, | 1185 | .enable = wm8350_dcdc_enable, |
| 1154 | .disable = wm8350_dcdc_disable, | 1186 | .disable = wm8350_dcdc_disable, |
| 1155 | .get_mode = wm8350_dcdc_get_mode, | 1187 | .get_mode = wm8350_dcdc_get_mode, |
| @@ -1173,6 +1205,7 @@ static struct regulator_ops wm8350_dcdc2_5_ops = { | |||
| 1173 | static struct regulator_ops wm8350_ldo_ops = { | 1205 | static struct regulator_ops wm8350_ldo_ops = { |
| 1174 | .set_voltage = wm8350_ldo_set_voltage, | 1206 | .set_voltage = wm8350_ldo_set_voltage, |
| 1175 | .get_voltage = wm8350_ldo_get_voltage, | 1207 | .get_voltage = wm8350_ldo_get_voltage, |
| 1208 | .list_voltage = wm8350_ldo_list_voltage, | ||
| 1176 | .enable = wm8350_ldo_enable, | 1209 | .enable = wm8350_ldo_enable, |
| 1177 | .disable = wm8350_ldo_disable, | 1210 | .disable = wm8350_ldo_disable, |
| 1178 | .is_enabled = wm8350_ldo_is_enabled, | 1211 | .is_enabled = wm8350_ldo_is_enabled, |
| @@ -1197,6 +1230,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
| 1197 | .ops = &wm8350_dcdc_ops, | 1230 | .ops = &wm8350_dcdc_ops, |
| 1198 | .irq = WM8350_IRQ_UV_DC1, | 1231 | .irq = WM8350_IRQ_UV_DC1, |
| 1199 | .type = REGULATOR_VOLTAGE, | 1232 | .type = REGULATOR_VOLTAGE, |
| 1233 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | ||
| 1200 | .owner = THIS_MODULE, | 1234 | .owner = THIS_MODULE, |
| 1201 | }, | 1235 | }, |
| 1202 | { | 1236 | { |
| @@ -1213,6 +1247,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
| 1213 | .ops = &wm8350_dcdc_ops, | 1247 | .ops = &wm8350_dcdc_ops, |
| 1214 | .irq = WM8350_IRQ_UV_DC3, | 1248 | .irq = WM8350_IRQ_UV_DC3, |
| 1215 | .type = REGULATOR_VOLTAGE, | 1249 | .type = REGULATOR_VOLTAGE, |
| 1250 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | ||
| 1216 | .owner = THIS_MODULE, | 1251 | .owner = THIS_MODULE, |
| 1217 | }, | 1252 | }, |
| 1218 | { | 1253 | { |
| @@ -1221,6 +1256,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
| 1221 | .ops = &wm8350_dcdc_ops, | 1256 | .ops = &wm8350_dcdc_ops, |
| 1222 | .irq = WM8350_IRQ_UV_DC4, | 1257 | .irq = WM8350_IRQ_UV_DC4, |
| 1223 | .type = REGULATOR_VOLTAGE, | 1258 | .type = REGULATOR_VOLTAGE, |
| 1259 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | ||
| 1224 | .owner = THIS_MODULE, | 1260 | .owner = THIS_MODULE, |
| 1225 | }, | 1261 | }, |
| 1226 | { | 1262 | { |
| @@ -1237,6 +1273,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
| 1237 | .ops = &wm8350_dcdc_ops, | 1273 | .ops = &wm8350_dcdc_ops, |
| 1238 | .irq = WM8350_IRQ_UV_DC6, | 1274 | .irq = WM8350_IRQ_UV_DC6, |
| 1239 | .type = REGULATOR_VOLTAGE, | 1275 | .type = REGULATOR_VOLTAGE, |
| 1276 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | ||
| 1240 | .owner = THIS_MODULE, | 1277 | .owner = THIS_MODULE, |
| 1241 | }, | 1278 | }, |
| 1242 | { | 1279 | { |
| @@ -1245,6 +1282,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
| 1245 | .ops = &wm8350_ldo_ops, | 1282 | .ops = &wm8350_ldo_ops, |
| 1246 | .irq = WM8350_IRQ_UV_LDO1, | 1283 | .irq = WM8350_IRQ_UV_LDO1, |
| 1247 | .type = REGULATOR_VOLTAGE, | 1284 | .type = REGULATOR_VOLTAGE, |
| 1285 | .n_voltages = WM8350_LDO1_VSEL_MASK + 1, | ||
| 1248 | .owner = THIS_MODULE, | 1286 | .owner = THIS_MODULE, |
| 1249 | }, | 1287 | }, |
| 1250 | { | 1288 | { |
| @@ -1253,6 +1291,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
| 1253 | .ops = &wm8350_ldo_ops, | 1291 | .ops = &wm8350_ldo_ops, |
| 1254 | .irq = WM8350_IRQ_UV_LDO2, | 1292 | .irq = WM8350_IRQ_UV_LDO2, |
| 1255 | .type = REGULATOR_VOLTAGE, | 1293 | .type = REGULATOR_VOLTAGE, |
| 1294 | .n_voltages = WM8350_LDO2_VSEL_MASK + 1, | ||
| 1256 | .owner = THIS_MODULE, | 1295 | .owner = THIS_MODULE, |
| 1257 | }, | 1296 | }, |
| 1258 | { | 1297 | { |
| @@ -1261,6 +1300,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
| 1261 | .ops = &wm8350_ldo_ops, | 1300 | .ops = &wm8350_ldo_ops, |
| 1262 | .irq = WM8350_IRQ_UV_LDO3, | 1301 | .irq = WM8350_IRQ_UV_LDO3, |
| 1263 | .type = REGULATOR_VOLTAGE, | 1302 | .type = REGULATOR_VOLTAGE, |
| 1303 | .n_voltages = WM8350_LDO3_VSEL_MASK + 1, | ||
| 1264 | .owner = THIS_MODULE, | 1304 | .owner = THIS_MODULE, |
| 1265 | }, | 1305 | }, |
| 1266 | { | 1306 | { |
| @@ -1269,6 +1309,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
| 1269 | .ops = &wm8350_ldo_ops, | 1309 | .ops = &wm8350_ldo_ops, |
| 1270 | .irq = WM8350_IRQ_UV_LDO4, | 1310 | .irq = WM8350_IRQ_UV_LDO4, |
| 1271 | .type = REGULATOR_VOLTAGE, | 1311 | .type = REGULATOR_VOLTAGE, |
| 1312 | .n_voltages = WM8350_LDO4_VSEL_MASK + 1, | ||
| 1272 | .owner = THIS_MODULE, | 1313 | .owner = THIS_MODULE, |
| 1273 | }, | 1314 | }, |
| 1274 | { | 1315 | { |
| @@ -1293,6 +1334,7 @@ static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data) | |||
| 1293 | { | 1334 | { |
| 1294 | struct regulator_dev *rdev = (struct regulator_dev *)data; | 1335 | struct regulator_dev *rdev = (struct regulator_dev *)data; |
| 1295 | 1336 | ||
| 1337 | mutex_lock(&rdev->mutex); | ||
| 1296 | if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) | 1338 | if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) |
| 1297 | regulator_notifier_call_chain(rdev, | 1339 | regulator_notifier_call_chain(rdev, |
| 1298 | REGULATOR_EVENT_REGULATION_OUT, | 1340 | REGULATOR_EVENT_REGULATION_OUT, |
| @@ -1301,6 +1343,7 @@ static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data) | |||
| 1301 | regulator_notifier_call_chain(rdev, | 1343 | regulator_notifier_call_chain(rdev, |
| 1302 | REGULATOR_EVENT_UNDER_VOLTAGE, | 1344 | REGULATOR_EVENT_UNDER_VOLTAGE, |
| 1303 | wm8350); | 1345 | wm8350); |
| 1346 | mutex_unlock(&rdev->mutex); | ||
| 1304 | } | 1347 | } |
| 1305 | 1348 | ||
| 1306 | static int wm8350_regulator_probe(struct platform_device *pdev) | 1349 | static int wm8350_regulator_probe(struct platform_device *pdev) |
| @@ -1333,9 +1376,9 @@ static int wm8350_regulator_probe(struct platform_device *pdev) | |||
| 1333 | break; | 1376 | break; |
| 1334 | } | 1377 | } |
| 1335 | 1378 | ||
| 1336 | |||
| 1337 | /* register regulator */ | 1379 | /* register regulator */ |
| 1338 | rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev, | 1380 | rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev, |
| 1381 | pdev->dev.platform_data, | ||
| 1339 | dev_get_drvdata(&pdev->dev)); | 1382 | dev_get_drvdata(&pdev->dev)); |
| 1340 | if (IS_ERR(rdev)) { | 1383 | if (IS_ERR(rdev)) { |
| 1341 | dev_err(&pdev->dev, "failed to register %s\n", | 1384 | dev_err(&pdev->dev, "failed to register %s\n", |
