1e4ee831fSMark Brown /* 2e4ee831fSMark Brown * wm831x-dcdc.c -- DC-DC buck convertor driver for the WM831x series 3e4ee831fSMark Brown * 4e4ee831fSMark Brown * Copyright 2009 Wolfson Microelectronics PLC. 5e4ee831fSMark Brown * 6e4ee831fSMark Brown * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7e4ee831fSMark Brown * 8e4ee831fSMark Brown * This program is free software; you can redistribute it and/or modify it 9e4ee831fSMark Brown * under the terms of the GNU General Public License as published by the 10e4ee831fSMark Brown * Free Software Foundation; either version 2 of the License, or (at your 11e4ee831fSMark Brown * option) any later version. 12e4ee831fSMark Brown */ 13e4ee831fSMark Brown 14e4ee831fSMark Brown #include <linux/module.h> 15e4ee831fSMark Brown #include <linux/moduleparam.h> 16e4ee831fSMark Brown #include <linux/init.h> 17e4ee831fSMark Brown #include <linux/bitops.h> 18e4ee831fSMark Brown #include <linux/err.h> 19e4ee831fSMark Brown #include <linux/i2c.h> 20e4ee831fSMark Brown #include <linux/platform_device.h> 21e4ee831fSMark Brown #include <linux/regulator/driver.h> 22e24a04c4SMark Brown #include <linux/regulator/machine.h> 23e24a04c4SMark Brown #include <linux/gpio.h> 245a0e3ad6STejun Heo #include <linux/slab.h> 25e4ee831fSMark Brown 26e4ee831fSMark Brown #include <linux/mfd/wm831x/core.h> 27e4ee831fSMark Brown #include <linux/mfd/wm831x/regulator.h> 28e4ee831fSMark Brown #include <linux/mfd/wm831x/pdata.h> 29e4ee831fSMark Brown 30e4ee831fSMark Brown #define WM831X_BUCKV_MAX_SELECTOR 0x68 31e4ee831fSMark Brown #define WM831X_BUCKP_MAX_SELECTOR 0x66 32e4ee831fSMark Brown 33e4ee831fSMark Brown #define WM831X_DCDC_MODE_FAST 0 34e4ee831fSMark Brown #define WM831X_DCDC_MODE_NORMAL 1 35e4ee831fSMark Brown #define WM831X_DCDC_MODE_IDLE 2 36e4ee831fSMark Brown #define WM831X_DCDC_MODE_STANDBY 3 37e4ee831fSMark Brown 3882caa978SMark Brown #define WM831X_DCDC_MAX_NAME 9 39e4ee831fSMark Brown 40e4ee831fSMark Brown /* Register offsets in control block */ 41e4ee831fSMark Brown #define WM831X_DCDC_CONTROL_1 0 42e4ee831fSMark Brown #define WM831X_DCDC_CONTROL_2 1 43e4ee831fSMark Brown #define WM831X_DCDC_ON_CONFIG 2 44e4ee831fSMark Brown #define WM831X_DCDC_SLEEP_CONTROL 3 45e24a04c4SMark Brown #define WM831X_DCDC_DVS_CONTROL 4 46e4ee831fSMark Brown 47e4ee831fSMark Brown /* 48e4ee831fSMark Brown * Shared 49e4ee831fSMark Brown */ 50e4ee831fSMark Brown 51e4ee831fSMark Brown struct wm831x_dcdc { 52e4ee831fSMark Brown char name[WM831X_DCDC_MAX_NAME]; 5382caa978SMark Brown char supply_name[WM831X_DCDC_MAX_NAME]; 54e4ee831fSMark Brown struct regulator_desc desc; 55e4ee831fSMark Brown int base; 56e4ee831fSMark Brown struct wm831x *wm831x; 57e4ee831fSMark Brown struct regulator_dev *regulator; 58e24a04c4SMark Brown int dvs_gpio; 59e24a04c4SMark Brown int dvs_gpio_state; 60e24a04c4SMark Brown int on_vsel; 61e24a04c4SMark Brown int dvs_vsel; 62e4ee831fSMark Brown }; 63e4ee831fSMark Brown 64e4ee831fSMark Brown static unsigned int wm831x_dcdc_get_mode(struct regulator_dev *rdev) 65e4ee831fSMark Brown 66e4ee831fSMark Brown { 67e4ee831fSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 68e4ee831fSMark Brown struct wm831x *wm831x = dcdc->wm831x; 69e4ee831fSMark Brown u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 70e4ee831fSMark Brown int val; 71e4ee831fSMark Brown 72e4ee831fSMark Brown val = wm831x_reg_read(wm831x, reg); 73e4ee831fSMark Brown if (val < 0) 74e4ee831fSMark Brown return val; 75e4ee831fSMark Brown 76e4ee831fSMark Brown val = (val & WM831X_DC1_ON_MODE_MASK) >> WM831X_DC1_ON_MODE_SHIFT; 77e4ee831fSMark Brown 78e4ee831fSMark Brown switch (val) { 79e4ee831fSMark Brown case WM831X_DCDC_MODE_FAST: 80e4ee831fSMark Brown return REGULATOR_MODE_FAST; 81e4ee831fSMark Brown case WM831X_DCDC_MODE_NORMAL: 82e4ee831fSMark Brown return REGULATOR_MODE_NORMAL; 83e4ee831fSMark Brown case WM831X_DCDC_MODE_STANDBY: 84e4ee831fSMark Brown return REGULATOR_MODE_STANDBY; 85e4ee831fSMark Brown case WM831X_DCDC_MODE_IDLE: 86e4ee831fSMark Brown return REGULATOR_MODE_IDLE; 87e4ee831fSMark Brown default: 88e4ee831fSMark Brown BUG(); 899ee291a4SMark Brown return -EINVAL; 90e4ee831fSMark Brown } 91e4ee831fSMark Brown } 92e4ee831fSMark Brown 93e4ee831fSMark Brown static int wm831x_dcdc_set_mode_int(struct wm831x *wm831x, int reg, 94e4ee831fSMark Brown unsigned int mode) 95e4ee831fSMark Brown { 96e4ee831fSMark Brown int val; 97e4ee831fSMark Brown 98e4ee831fSMark Brown switch (mode) { 99e4ee831fSMark Brown case REGULATOR_MODE_FAST: 100e4ee831fSMark Brown val = WM831X_DCDC_MODE_FAST; 101e4ee831fSMark Brown break; 102e4ee831fSMark Brown case REGULATOR_MODE_NORMAL: 103e4ee831fSMark Brown val = WM831X_DCDC_MODE_NORMAL; 104e4ee831fSMark Brown break; 105e4ee831fSMark Brown case REGULATOR_MODE_STANDBY: 106e4ee831fSMark Brown val = WM831X_DCDC_MODE_STANDBY; 107e4ee831fSMark Brown break; 108e4ee831fSMark Brown case REGULATOR_MODE_IDLE: 109e4ee831fSMark Brown val = WM831X_DCDC_MODE_IDLE; 110e4ee831fSMark Brown break; 111e4ee831fSMark Brown default: 112e4ee831fSMark Brown return -EINVAL; 113e4ee831fSMark Brown } 114e4ee831fSMark Brown 115e4ee831fSMark Brown return wm831x_set_bits(wm831x, reg, WM831X_DC1_ON_MODE_MASK, 116e4ee831fSMark Brown val << WM831X_DC1_ON_MODE_SHIFT); 117e4ee831fSMark Brown } 118e4ee831fSMark Brown 119e4ee831fSMark Brown static int wm831x_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode) 120e4ee831fSMark Brown { 121e4ee831fSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 122e4ee831fSMark Brown struct wm831x *wm831x = dcdc->wm831x; 123e4ee831fSMark Brown u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 124e4ee831fSMark Brown 125e4ee831fSMark Brown return wm831x_dcdc_set_mode_int(wm831x, reg, mode); 126e4ee831fSMark Brown } 127e4ee831fSMark Brown 128e4ee831fSMark Brown static int wm831x_dcdc_set_suspend_mode(struct regulator_dev *rdev, 129e4ee831fSMark Brown unsigned int mode) 130e4ee831fSMark Brown { 131e4ee831fSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 132e4ee831fSMark Brown struct wm831x *wm831x = dcdc->wm831x; 133e4ee831fSMark Brown u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 134e4ee831fSMark Brown 135e4ee831fSMark Brown return wm831x_dcdc_set_mode_int(wm831x, reg, mode); 136e4ee831fSMark Brown } 137e4ee831fSMark Brown 138e4ee831fSMark Brown static int wm831x_dcdc_get_status(struct regulator_dev *rdev) 139e4ee831fSMark Brown { 140e4ee831fSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 141e4ee831fSMark Brown struct wm831x *wm831x = dcdc->wm831x; 142e4ee831fSMark Brown int ret; 143e4ee831fSMark Brown 144e4ee831fSMark Brown /* First, check for errors */ 145e4ee831fSMark Brown ret = wm831x_reg_read(wm831x, WM831X_DCDC_UV_STATUS); 146e4ee831fSMark Brown if (ret < 0) 147e4ee831fSMark Brown return ret; 148e4ee831fSMark Brown 149e4ee831fSMark Brown if (ret & (1 << rdev_get_id(rdev))) { 150e4ee831fSMark Brown dev_dbg(wm831x->dev, "DCDC%d under voltage\n", 151e4ee831fSMark Brown rdev_get_id(rdev) + 1); 152e4ee831fSMark Brown return REGULATOR_STATUS_ERROR; 153e4ee831fSMark Brown } 154e4ee831fSMark Brown 155e4ee831fSMark Brown /* DCDC1 and DCDC2 can additionally detect high voltage/current */ 156e4ee831fSMark Brown if (rdev_get_id(rdev) < 2) { 157e4ee831fSMark Brown if (ret & (WM831X_DC1_OV_STS << rdev_get_id(rdev))) { 158e4ee831fSMark Brown dev_dbg(wm831x->dev, "DCDC%d over voltage\n", 159e4ee831fSMark Brown rdev_get_id(rdev) + 1); 160e4ee831fSMark Brown return REGULATOR_STATUS_ERROR; 161e4ee831fSMark Brown } 162e4ee831fSMark Brown 163e4ee831fSMark Brown if (ret & (WM831X_DC1_HC_STS << rdev_get_id(rdev))) { 164e4ee831fSMark Brown dev_dbg(wm831x->dev, "DCDC%d over current\n", 165e4ee831fSMark Brown rdev_get_id(rdev) + 1); 166e4ee831fSMark Brown return REGULATOR_STATUS_ERROR; 167e4ee831fSMark Brown } 168e4ee831fSMark Brown } 169e4ee831fSMark Brown 170e4ee831fSMark Brown /* Is the regulator on? */ 171e4ee831fSMark Brown ret = wm831x_reg_read(wm831x, WM831X_DCDC_STATUS); 172e4ee831fSMark Brown if (ret < 0) 173e4ee831fSMark Brown return ret; 174e4ee831fSMark Brown if (!(ret & (1 << rdev_get_id(rdev)))) 175e4ee831fSMark Brown return REGULATOR_STATUS_OFF; 176e4ee831fSMark Brown 177e4ee831fSMark Brown /* TODO: When we handle hardware control modes so we can report the 178e4ee831fSMark Brown * current mode. */ 179e4ee831fSMark Brown return REGULATOR_STATUS_ON; 180e4ee831fSMark Brown } 181e4ee831fSMark Brown 182e4ee831fSMark Brown static irqreturn_t wm831x_dcdc_uv_irq(int irq, void *data) 183e4ee831fSMark Brown { 184e4ee831fSMark Brown struct wm831x_dcdc *dcdc = data; 185e4ee831fSMark Brown 186e4ee831fSMark Brown regulator_notifier_call_chain(dcdc->regulator, 187e4ee831fSMark Brown REGULATOR_EVENT_UNDER_VOLTAGE, 188e4ee831fSMark Brown NULL); 189e4ee831fSMark Brown 190e4ee831fSMark Brown return IRQ_HANDLED; 191e4ee831fSMark Brown } 192e4ee831fSMark Brown 193e4ee831fSMark Brown static irqreturn_t wm831x_dcdc_oc_irq(int irq, void *data) 194e4ee831fSMark Brown { 195e4ee831fSMark Brown struct wm831x_dcdc *dcdc = data; 196e4ee831fSMark Brown 197e4ee831fSMark Brown regulator_notifier_call_chain(dcdc->regulator, 198e4ee831fSMark Brown REGULATOR_EVENT_OVER_CURRENT, 199e4ee831fSMark Brown NULL); 200e4ee831fSMark Brown 201e4ee831fSMark Brown return IRQ_HANDLED; 202e4ee831fSMark Brown } 203e4ee831fSMark Brown 204e4ee831fSMark Brown /* 205e4ee831fSMark Brown * BUCKV specifics 206e4ee831fSMark Brown */ 207e4ee831fSMark Brown 208ccffcb8eSAxel Lin static const struct regulator_linear_range wm831x_buckv_ranges[] = { 209ccffcb8eSAxel Lin REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0), 210ccffcb8eSAxel Lin REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500), 211ccffcb8eSAxel Lin }; 212e24a04c4SMark Brown 213e24a04c4SMark Brown static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state) 214e24a04c4SMark Brown { 215e24a04c4SMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 216e24a04c4SMark Brown 217e24a04c4SMark Brown if (state == dcdc->dvs_gpio_state) 218e24a04c4SMark Brown return 0; 219e24a04c4SMark Brown 220e24a04c4SMark Brown dcdc->dvs_gpio_state = state; 221e24a04c4SMark Brown gpio_set_value(dcdc->dvs_gpio, state); 222e24a04c4SMark Brown 223e24a04c4SMark Brown /* Should wait for DVS state change to be asserted if we have 224e24a04c4SMark Brown * a GPIO for it, for now assume the device is configured 225e24a04c4SMark Brown * for the fastest possible transition. 226e24a04c4SMark Brown */ 227e24a04c4SMark Brown 228e24a04c4SMark Brown return 0; 229e4ee831fSMark Brown } 230e4ee831fSMark Brown 231b5fb77e0SAxel Lin static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev, 232b5fb77e0SAxel Lin unsigned vsel) 233e4ee831fSMark Brown { 234e4ee831fSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 235e24a04c4SMark Brown struct wm831x *wm831x = dcdc->wm831x; 236e24a04c4SMark Brown int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 237e24a04c4SMark Brown int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL; 238b5fb77e0SAxel Lin int ret; 2393a93f2a9SMark Brown 240e24a04c4SMark Brown /* If this value is already set then do a GPIO update if we can */ 241e24a04c4SMark Brown if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) 242e24a04c4SMark Brown return wm831x_buckv_set_dvs(rdev, 0); 243e24a04c4SMark Brown 244e24a04c4SMark Brown if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel) 245e24a04c4SMark Brown return wm831x_buckv_set_dvs(rdev, 1); 246e24a04c4SMark Brown 247e24a04c4SMark Brown /* Always set the ON status to the minimum voltage */ 248e24a04c4SMark Brown ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel); 249e24a04c4SMark Brown if (ret < 0) 250e24a04c4SMark Brown return ret; 251e24a04c4SMark Brown dcdc->on_vsel = vsel; 252e24a04c4SMark Brown 253e24a04c4SMark Brown if (!dcdc->dvs_gpio) 254e24a04c4SMark Brown return ret; 255e24a04c4SMark Brown 256e24a04c4SMark Brown /* Kick the voltage transition now */ 257e24a04c4SMark Brown ret = wm831x_buckv_set_dvs(rdev, 0); 258e24a04c4SMark Brown if (ret < 0) 259e24a04c4SMark Brown return ret; 260e24a04c4SMark Brown 26188cda60eSMark Brown /* 26288cda60eSMark Brown * If this VSEL is higher than the last one we've seen then 26388cda60eSMark Brown * remember it as the DVS VSEL. This is optimised for CPUfreq 26488cda60eSMark Brown * usage where we want to get to the highest voltage very 26588cda60eSMark Brown * quickly. 26688cda60eSMark Brown */ 26788cda60eSMark Brown if (vsel > dcdc->dvs_vsel) { 26888cda60eSMark Brown ret = wm831x_set_bits(wm831x, dvs_reg, 26988cda60eSMark Brown WM831X_DC1_DVS_VSEL_MASK, 27013ae633cSMark Brown vsel); 271e24a04c4SMark Brown if (ret == 0) 272e24a04c4SMark Brown dcdc->dvs_vsel = vsel; 273e24a04c4SMark Brown else 27488cda60eSMark Brown dev_warn(wm831x->dev, 27588cda60eSMark Brown "Failed to set DCDC DVS VSEL: %d\n", ret); 27688cda60eSMark Brown } 277e24a04c4SMark Brown 278e24a04c4SMark Brown return 0; 279e4ee831fSMark Brown } 280e4ee831fSMark Brown 281e4ee831fSMark Brown static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev, 282e4ee831fSMark Brown int uV) 283e4ee831fSMark Brown { 284e4ee831fSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 285e24a04c4SMark Brown struct wm831x *wm831x = dcdc->wm831x; 286e4ee831fSMark Brown u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 287e24a04c4SMark Brown int vsel; 288e4ee831fSMark Brown 289ccffcb8eSAxel Lin vsel = regulator_map_voltage_linear_range(rdev, uV, uV); 290e24a04c4SMark Brown if (vsel < 0) 291e24a04c4SMark Brown return vsel; 292e24a04c4SMark Brown 293e24a04c4SMark Brown return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel); 294e4ee831fSMark Brown } 295e4ee831fSMark Brown 296afb8bb80SMark Brown static int wm831x_buckv_get_voltage_sel(struct regulator_dev *rdev) 297e4ee831fSMark Brown { 298e4ee831fSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 299e4ee831fSMark Brown 300e24a04c4SMark Brown if (dcdc->dvs_gpio && dcdc->dvs_gpio_state) 301afb8bb80SMark Brown return dcdc->dvs_vsel; 302e24a04c4SMark Brown else 303afb8bb80SMark Brown return dcdc->on_vsel; 304e4ee831fSMark Brown } 305e4ee831fSMark Brown 306e4ee831fSMark Brown /* Current limit options */ 307c25d4788SAxel Lin static const unsigned int wm831x_dcdc_ilim[] = { 308c25d4788SAxel Lin 125000, 250000, 375000, 500000, 625000, 750000, 875000, 1000000 309e4ee831fSMark Brown }; 310e4ee831fSMark Brown 311b0d6dd3bSJulia Lawall static const struct regulator_ops wm831x_buckv_ops = { 312b5fb77e0SAxel Lin .set_voltage_sel = wm831x_buckv_set_voltage_sel, 313afb8bb80SMark Brown .get_voltage_sel = wm831x_buckv_get_voltage_sel, 314ccffcb8eSAxel Lin .list_voltage = regulator_list_voltage_linear_range, 315ccffcb8eSAxel Lin .map_voltage = regulator_map_voltage_linear_range, 316e4ee831fSMark Brown .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, 31720eb641eSAxel Lin .set_current_limit = regulator_set_current_limit_regmap, 31820eb641eSAxel Lin .get_current_limit = regulator_get_current_limit_regmap, 319e4ee831fSMark Brown 3203d138fccSMark Brown .is_enabled = regulator_is_enabled_regmap, 3213d138fccSMark Brown .enable = regulator_enable_regmap, 3223d138fccSMark Brown .disable = regulator_disable_regmap, 323e4ee831fSMark Brown .get_status = wm831x_dcdc_get_status, 324e4ee831fSMark Brown .get_mode = wm831x_dcdc_get_mode, 325e4ee831fSMark Brown .set_mode = wm831x_dcdc_set_mode, 326e4ee831fSMark Brown .set_suspend_mode = wm831x_dcdc_set_suspend_mode, 327e4ee831fSMark Brown }; 328e4ee831fSMark Brown 329e24a04c4SMark Brown /* 330e24a04c4SMark Brown * Set up DVS control. We just log errors since we can still run 331e24a04c4SMark Brown * (with reduced performance) if we fail. 332e24a04c4SMark Brown */ 3331aa20d27SMark Brown static void wm831x_buckv_dvs_init(struct platform_device *pdev, 3341aa20d27SMark Brown struct wm831x_dcdc *dcdc, 335e24a04c4SMark Brown struct wm831x_buckv_pdata *pdata) 336e24a04c4SMark Brown { 337e24a04c4SMark Brown struct wm831x *wm831x = dcdc->wm831x; 338e24a04c4SMark Brown int ret; 339e24a04c4SMark Brown u16 ctrl; 340e24a04c4SMark Brown 341e24a04c4SMark Brown if (!pdata || !pdata->dvs_gpio) 342e24a04c4SMark Brown return; 343e24a04c4SMark Brown 344e24a04c4SMark Brown /* gpiolib won't let us read the GPIO status so pick the higher 345e24a04c4SMark Brown * of the two existing voltages so we take it as platform data. 346e24a04c4SMark Brown */ 347e24a04c4SMark Brown dcdc->dvs_gpio_state = pdata->dvs_init_state; 348e24a04c4SMark Brown 3491aa20d27SMark Brown ret = devm_gpio_request_one(&pdev->dev, pdata->dvs_gpio, 350053fa1b7SMark Brown dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, 351053fa1b7SMark Brown "DCDC DVS"); 352e24a04c4SMark Brown if (ret < 0) { 353053fa1b7SMark Brown dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", 354e24a04c4SMark Brown dcdc->name, ret); 355e24a04c4SMark Brown return; 356e24a04c4SMark Brown } 357e24a04c4SMark Brown 358e24a04c4SMark Brown dcdc->dvs_gpio = pdata->dvs_gpio; 359b47ba9fdSMark Brown 360b47ba9fdSMark Brown switch (pdata->dvs_control_src) { 361b47ba9fdSMark Brown case 1: 362b47ba9fdSMark Brown ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT; 363b47ba9fdSMark Brown break; 364b47ba9fdSMark Brown case 2: 365b47ba9fdSMark Brown ctrl = 3 << WM831X_DC1_DVS_SRC_SHIFT; 366b47ba9fdSMark Brown break; 367b47ba9fdSMark Brown default: 368b47ba9fdSMark Brown dev_err(wm831x->dev, "Invalid DVS control source %d for %s\n", 369b47ba9fdSMark Brown pdata->dvs_control_src, dcdc->name); 370b47ba9fdSMark Brown return; 371b47ba9fdSMark Brown } 372b47ba9fdSMark Brown 373c439b8f4SMark Brown /* If DVS_VSEL is set to the minimum value then raise it to ON_VSEL 374c439b8f4SMark Brown * to make bootstrapping a bit smoother. 375c439b8f4SMark Brown */ 376c439b8f4SMark Brown if (!dcdc->dvs_vsel) { 377c439b8f4SMark Brown ret = wm831x_set_bits(wm831x, 378c439b8f4SMark Brown dcdc->base + WM831X_DCDC_DVS_CONTROL, 379c439b8f4SMark Brown WM831X_DC1_DVS_VSEL_MASK, dcdc->on_vsel); 380c439b8f4SMark Brown if (ret == 0) 381c439b8f4SMark Brown dcdc->dvs_vsel = dcdc->on_vsel; 382c439b8f4SMark Brown else 383c439b8f4SMark Brown dev_warn(wm831x->dev, "Failed to set DVS_VSEL: %d\n", 384c439b8f4SMark Brown ret); 385c439b8f4SMark Brown } 386c439b8f4SMark Brown 387b47ba9fdSMark Brown ret = wm831x_set_bits(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL, 388b47ba9fdSMark Brown WM831X_DC1_DVS_SRC_MASK, ctrl); 389b47ba9fdSMark Brown if (ret < 0) { 390b47ba9fdSMark Brown dev_err(wm831x->dev, "Failed to set %s DVS source: %d\n", 391b47ba9fdSMark Brown dcdc->name, ret); 392b47ba9fdSMark Brown } 393e24a04c4SMark Brown } 394e24a04c4SMark Brown 395a5023574SBill Pemberton static int wm831x_buckv_probe(struct platform_device *pdev) 396e4ee831fSMark Brown { 397e4ee831fSMark Brown struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 398dff91d0bSJingoo Han struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 399c172708dSMark Brown struct regulator_config config = { }; 400137a6354SMark Brown int id; 401e4ee831fSMark Brown struct wm831x_dcdc *dcdc; 402e4ee831fSMark Brown struct resource *res; 403e4ee831fSMark Brown int ret, irq; 404e4ee831fSMark Brown 405137a6354SMark Brown if (pdata && pdata->wm831x_num) 406137a6354SMark Brown id = (pdata->wm831x_num * 10) + 1; 407137a6354SMark Brown else 408137a6354SMark Brown id = 0; 409137a6354SMark Brown id = pdev->id - id; 410137a6354SMark Brown 411e4ee831fSMark Brown dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); 412e4ee831fSMark Brown 413fded2f4fSMark Brown dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), 414fded2f4fSMark Brown GFP_KERNEL); 4155730aa57SSachin Kamat if (!dcdc) 416e4ee831fSMark Brown return -ENOMEM; 417e4ee831fSMark Brown 418e4ee831fSMark Brown dcdc->wm831x = wm831x; 419e4ee831fSMark Brown 4205656098eSMark Brown res = platform_get_resource(pdev, IORESOURCE_REG, 0); 421e4ee831fSMark Brown if (res == NULL) { 4225656098eSMark Brown dev_err(&pdev->dev, "No REG resource\n"); 423e4ee831fSMark Brown ret = -EINVAL; 424e4ee831fSMark Brown goto err; 425e4ee831fSMark Brown } 426e4ee831fSMark Brown dcdc->base = res->start; 427e4ee831fSMark Brown 428e4ee831fSMark Brown snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); 429e4ee831fSMark Brown dcdc->desc.name = dcdc->name; 43082caa978SMark Brown 43182caa978SMark Brown snprintf(dcdc->supply_name, sizeof(dcdc->supply_name), 43282caa978SMark Brown "DC%dVDD", id + 1); 43382caa978SMark Brown dcdc->desc.supply_name = dcdc->supply_name; 43482caa978SMark Brown 435e4ee831fSMark Brown dcdc->desc.id = id; 436e4ee831fSMark Brown dcdc->desc.type = REGULATOR_VOLTAGE; 437e4ee831fSMark Brown dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1; 438ccffcb8eSAxel Lin dcdc->desc.linear_ranges = wm831x_buckv_ranges; 439ccffcb8eSAxel Lin dcdc->desc.n_linear_ranges = ARRAY_SIZE(wm831x_buckv_ranges); 440e4ee831fSMark Brown dcdc->desc.ops = &wm831x_buckv_ops; 441e4ee831fSMark Brown dcdc->desc.owner = THIS_MODULE; 4423d138fccSMark Brown dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; 4433d138fccSMark Brown dcdc->desc.enable_mask = 1 << id; 44420eb641eSAxel Lin dcdc->desc.csel_reg = dcdc->base + WM831X_DCDC_CONTROL_2; 44520eb641eSAxel Lin dcdc->desc.csel_mask = WM831X_DC1_HC_THR_MASK; 44620eb641eSAxel Lin dcdc->desc.n_current_limits = ARRAY_SIZE(wm831x_dcdc_ilim); 44720eb641eSAxel Lin dcdc->desc.curr_table = wm831x_dcdc_ilim; 448e4ee831fSMark Brown 449e24a04c4SMark Brown ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG); 450e24a04c4SMark Brown if (ret < 0) { 451e24a04c4SMark Brown dev_err(wm831x->dev, "Failed to read ON VSEL: %d\n", ret); 452e24a04c4SMark Brown goto err; 453e24a04c4SMark Brown } 454e24a04c4SMark Brown dcdc->on_vsel = ret & WM831X_DC1_ON_VSEL_MASK; 455e24a04c4SMark Brown 456a1b81dd3SMark Brown ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL); 457e24a04c4SMark Brown if (ret < 0) { 458e24a04c4SMark Brown dev_err(wm831x->dev, "Failed to read DVS VSEL: %d\n", ret); 459e24a04c4SMark Brown goto err; 460e24a04c4SMark Brown } 461e24a04c4SMark Brown dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK; 462e24a04c4SMark Brown 463f0b067d9SMark Brown if (pdata && pdata->dcdc[id]) 4641aa20d27SMark Brown wm831x_buckv_dvs_init(pdev, dcdc, 4651aa20d27SMark Brown pdata->dcdc[id]->driver_data); 466e24a04c4SMark Brown 467c172708dSMark Brown config.dev = pdev->dev.parent; 468b7ca8788SMark Brown if (pdata) 469c172708dSMark Brown config.init_data = pdata->dcdc[id]; 470c172708dSMark Brown config.driver_data = dcdc; 4713d138fccSMark Brown config.regmap = wm831x->regmap; 472c172708dSMark Brown 473d73b4cb7SMark Brown dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc, 474d73b4cb7SMark Brown &config); 475e4ee831fSMark Brown if (IS_ERR(dcdc->regulator)) { 476e4ee831fSMark Brown ret = PTR_ERR(dcdc->regulator); 477e4ee831fSMark Brown dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 478e4ee831fSMark Brown id + 1, ret); 479e4ee831fSMark Brown goto err; 480e4ee831fSMark Brown } 481e4ee831fSMark Brown 482cd99758bSMark Brown irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 483b0c4c0c6SMark Brown ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 484b0c4c0c6SMark Brown wm831x_dcdc_uv_irq, 48529454738SFabio Estevam IRQF_TRIGGER_RISING | IRQF_ONESHOT, 48629454738SFabio Estevam dcdc->name, dcdc); 487e4ee831fSMark Brown if (ret != 0) { 488e4ee831fSMark Brown dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 489e4ee831fSMark Brown irq, ret); 490d73b4cb7SMark Brown goto err; 491e4ee831fSMark Brown } 492e4ee831fSMark Brown 493cd99758bSMark Brown irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC")); 494b0c4c0c6SMark Brown ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 495b0c4c0c6SMark Brown wm831x_dcdc_oc_irq, 49629454738SFabio Estevam IRQF_TRIGGER_RISING | IRQF_ONESHOT, 49729454738SFabio Estevam dcdc->name, dcdc); 498e4ee831fSMark Brown if (ret != 0) { 499e4ee831fSMark Brown dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n", 500e4ee831fSMark Brown irq, ret); 501d73b4cb7SMark Brown goto err; 502e4ee831fSMark Brown } 503e4ee831fSMark Brown 504e4ee831fSMark Brown platform_set_drvdata(pdev, dcdc); 505e4ee831fSMark Brown 506e4ee831fSMark Brown return 0; 507e4ee831fSMark Brown 508e4ee831fSMark Brown err: 509e4ee831fSMark Brown return ret; 510e4ee831fSMark Brown } 511e4ee831fSMark Brown 512e4ee831fSMark Brown static struct platform_driver wm831x_buckv_driver = { 513e4ee831fSMark Brown .probe = wm831x_buckv_probe, 514e4ee831fSMark Brown .driver = { 515e4ee831fSMark Brown .name = "wm831x-buckv", 516e4ee831fSMark Brown }, 517e4ee831fSMark Brown }; 518e4ee831fSMark Brown 519e4ee831fSMark Brown /* 520e4ee831fSMark Brown * BUCKP specifics 521e4ee831fSMark Brown */ 522e4ee831fSMark Brown 523d580cb5eSAxel Lin static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, int uV) 524e4ee831fSMark Brown { 525e4ee831fSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 526e4ee831fSMark Brown struct wm831x *wm831x = dcdc->wm831x; 527e4ee831fSMark Brown u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 528d580cb5eSAxel Lin int sel; 529e4ee831fSMark Brown 530d580cb5eSAxel Lin sel = regulator_map_voltage_linear(rdev, uV, uV); 531d580cb5eSAxel Lin if (sel < 0) 532d580cb5eSAxel Lin return sel; 533d580cb5eSAxel Lin 534d580cb5eSAxel Lin return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, sel); 535e4ee831fSMark Brown } 536e4ee831fSMark Brown 537b0d6dd3bSJulia Lawall static const struct regulator_ops wm831x_buckp_ops = { 538d580cb5eSAxel Lin .set_voltage_sel = regulator_set_voltage_sel_regmap, 539817436e7SMark Brown .get_voltage_sel = regulator_get_voltage_sel_regmap, 540c70ad9dcSAxel Lin .list_voltage = regulator_list_voltage_linear, 541d580cb5eSAxel Lin .map_voltage = regulator_map_voltage_linear, 542e4ee831fSMark Brown .set_suspend_voltage = wm831x_buckp_set_suspend_voltage, 543e4ee831fSMark Brown 5443d138fccSMark Brown .is_enabled = regulator_is_enabled_regmap, 5453d138fccSMark Brown .enable = regulator_enable_regmap, 5463d138fccSMark Brown .disable = regulator_disable_regmap, 547e4ee831fSMark Brown .get_status = wm831x_dcdc_get_status, 548e4ee831fSMark Brown .get_mode = wm831x_dcdc_get_mode, 549e4ee831fSMark Brown .set_mode = wm831x_dcdc_set_mode, 550e4ee831fSMark Brown .set_suspend_mode = wm831x_dcdc_set_suspend_mode, 551e4ee831fSMark Brown }; 552e4ee831fSMark Brown 553a5023574SBill Pemberton static int wm831x_buckp_probe(struct platform_device *pdev) 554e4ee831fSMark Brown { 555e4ee831fSMark Brown struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 556dff91d0bSJingoo Han struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 557c172708dSMark Brown struct regulator_config config = { }; 558137a6354SMark Brown int id; 559e4ee831fSMark Brown struct wm831x_dcdc *dcdc; 560e4ee831fSMark Brown struct resource *res; 561e4ee831fSMark Brown int ret, irq; 562e4ee831fSMark Brown 563137a6354SMark Brown if (pdata && pdata->wm831x_num) 564137a6354SMark Brown id = (pdata->wm831x_num * 10) + 1; 565137a6354SMark Brown else 566137a6354SMark Brown id = 0; 567137a6354SMark Brown id = pdev->id - id; 568137a6354SMark Brown 569e4ee831fSMark Brown dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); 570e4ee831fSMark Brown 571fded2f4fSMark Brown dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), 572fded2f4fSMark Brown GFP_KERNEL); 5735730aa57SSachin Kamat if (!dcdc) 574e4ee831fSMark Brown return -ENOMEM; 575e4ee831fSMark Brown 576e4ee831fSMark Brown dcdc->wm831x = wm831x; 577e4ee831fSMark Brown 5785656098eSMark Brown res = platform_get_resource(pdev, IORESOURCE_REG, 0); 579e4ee831fSMark Brown if (res == NULL) { 5805656098eSMark Brown dev_err(&pdev->dev, "No REG resource\n"); 581e4ee831fSMark Brown ret = -EINVAL; 582e4ee831fSMark Brown goto err; 583e4ee831fSMark Brown } 584e4ee831fSMark Brown dcdc->base = res->start; 585e4ee831fSMark Brown 586e4ee831fSMark Brown snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); 587e4ee831fSMark Brown dcdc->desc.name = dcdc->name; 58882caa978SMark Brown 58982caa978SMark Brown snprintf(dcdc->supply_name, sizeof(dcdc->supply_name), 59082caa978SMark Brown "DC%dVDD", id + 1); 59182caa978SMark Brown dcdc->desc.supply_name = dcdc->supply_name; 59282caa978SMark Brown 593e4ee831fSMark Brown dcdc->desc.id = id; 594e4ee831fSMark Brown dcdc->desc.type = REGULATOR_VOLTAGE; 595e4ee831fSMark Brown dcdc->desc.n_voltages = WM831X_BUCKP_MAX_SELECTOR + 1; 596e4ee831fSMark Brown dcdc->desc.ops = &wm831x_buckp_ops; 597e4ee831fSMark Brown dcdc->desc.owner = THIS_MODULE; 598817436e7SMark Brown dcdc->desc.vsel_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 599817436e7SMark Brown dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK; 6003d138fccSMark Brown dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; 6013d138fccSMark Brown dcdc->desc.enable_mask = 1 << id; 602c70ad9dcSAxel Lin dcdc->desc.min_uV = 850000; 603c70ad9dcSAxel Lin dcdc->desc.uV_step = 25000; 604e4ee831fSMark Brown 605c172708dSMark Brown config.dev = pdev->dev.parent; 606b7ca8788SMark Brown if (pdata) 607c172708dSMark Brown config.init_data = pdata->dcdc[id]; 608c172708dSMark Brown config.driver_data = dcdc; 609817436e7SMark Brown config.regmap = wm831x->regmap; 610c172708dSMark Brown 611d73b4cb7SMark Brown dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc, 612d73b4cb7SMark Brown &config); 613e4ee831fSMark Brown if (IS_ERR(dcdc->regulator)) { 614e4ee831fSMark Brown ret = PTR_ERR(dcdc->regulator); 615e4ee831fSMark Brown dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 616e4ee831fSMark Brown id + 1, ret); 617e4ee831fSMark Brown goto err; 618e4ee831fSMark Brown } 619e4ee831fSMark Brown 620cd99758bSMark Brown irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 621b0c4c0c6SMark Brown ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 622b0c4c0c6SMark Brown wm831x_dcdc_uv_irq, 62329454738SFabio Estevam IRQF_TRIGGER_RISING | IRQF_ONESHOT, 62429454738SFabio Estevam dcdc->name, dcdc); 625e4ee831fSMark Brown if (ret != 0) { 626e4ee831fSMark Brown dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 627e4ee831fSMark Brown irq, ret); 628d73b4cb7SMark Brown goto err; 629e4ee831fSMark Brown } 630e4ee831fSMark Brown 631e4ee831fSMark Brown platform_set_drvdata(pdev, dcdc); 632e4ee831fSMark Brown 633e4ee831fSMark Brown return 0; 634e4ee831fSMark Brown 635e4ee831fSMark Brown err: 636e4ee831fSMark Brown return ret; 637e4ee831fSMark Brown } 638e4ee831fSMark Brown 639e4ee831fSMark Brown static struct platform_driver wm831x_buckp_driver = { 640e4ee831fSMark Brown .probe = wm831x_buckp_probe, 641e4ee831fSMark Brown .driver = { 642e4ee831fSMark Brown .name = "wm831x-buckp", 643e4ee831fSMark Brown }, 644e4ee831fSMark Brown }; 645e4ee831fSMark Brown 6468267a9baSMark Brown /* 6471304850dSMark Brown * DCDC boost convertors 6481304850dSMark Brown */ 6491304850dSMark Brown 6501304850dSMark Brown static int wm831x_boostp_get_status(struct regulator_dev *rdev) 6511304850dSMark Brown { 6521304850dSMark Brown struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 6531304850dSMark Brown struct wm831x *wm831x = dcdc->wm831x; 6541304850dSMark Brown int ret; 6551304850dSMark Brown 6561304850dSMark Brown /* First, check for errors */ 6571304850dSMark Brown ret = wm831x_reg_read(wm831x, WM831X_DCDC_UV_STATUS); 6581304850dSMark Brown if (ret < 0) 6591304850dSMark Brown return ret; 6601304850dSMark Brown 6611304850dSMark Brown if (ret & (1 << rdev_get_id(rdev))) { 6621304850dSMark Brown dev_dbg(wm831x->dev, "DCDC%d under voltage\n", 6631304850dSMark Brown rdev_get_id(rdev) + 1); 6641304850dSMark Brown return REGULATOR_STATUS_ERROR; 6651304850dSMark Brown } 6661304850dSMark Brown 6671304850dSMark Brown /* Is the regulator on? */ 6681304850dSMark Brown ret = wm831x_reg_read(wm831x, WM831X_DCDC_STATUS); 6691304850dSMark Brown if (ret < 0) 6701304850dSMark Brown return ret; 6711304850dSMark Brown if (ret & (1 << rdev_get_id(rdev))) 6721304850dSMark Brown return REGULATOR_STATUS_ON; 6731304850dSMark Brown else 6741304850dSMark Brown return REGULATOR_STATUS_OFF; 6751304850dSMark Brown } 6761304850dSMark Brown 677b0d6dd3bSJulia Lawall static const struct regulator_ops wm831x_boostp_ops = { 6781304850dSMark Brown .get_status = wm831x_boostp_get_status, 6791304850dSMark Brown 6803d138fccSMark Brown .is_enabled = regulator_is_enabled_regmap, 6813d138fccSMark Brown .enable = regulator_enable_regmap, 6823d138fccSMark Brown .disable = regulator_disable_regmap, 6831304850dSMark Brown }; 6841304850dSMark Brown 685a5023574SBill Pemberton static int wm831x_boostp_probe(struct platform_device *pdev) 6861304850dSMark Brown { 6871304850dSMark Brown struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 688dff91d0bSJingoo Han struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 689c172708dSMark Brown struct regulator_config config = { }; 6901304850dSMark Brown int id = pdev->id % ARRAY_SIZE(pdata->dcdc); 6911304850dSMark Brown struct wm831x_dcdc *dcdc; 6921304850dSMark Brown struct resource *res; 6931304850dSMark Brown int ret, irq; 6941304850dSMark Brown 6951304850dSMark Brown dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); 6961304850dSMark Brown 6971304850dSMark Brown if (pdata == NULL || pdata->dcdc[id] == NULL) 6981304850dSMark Brown return -ENODEV; 6991304850dSMark Brown 7004c60165dSAxel Lin dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL); 7015730aa57SSachin Kamat if (!dcdc) 7021304850dSMark Brown return -ENOMEM; 7031304850dSMark Brown 7041304850dSMark Brown dcdc->wm831x = wm831x; 7051304850dSMark Brown 7065656098eSMark Brown res = platform_get_resource(pdev, IORESOURCE_REG, 0); 7071304850dSMark Brown if (res == NULL) { 7085656098eSMark Brown dev_err(&pdev->dev, "No REG resource\n"); 709477b2bacSFabio Estevam return -EINVAL; 7101304850dSMark Brown } 7111304850dSMark Brown dcdc->base = res->start; 7121304850dSMark Brown 7131304850dSMark Brown snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); 7141304850dSMark Brown dcdc->desc.name = dcdc->name; 7151304850dSMark Brown dcdc->desc.id = id; 7161304850dSMark Brown dcdc->desc.type = REGULATOR_VOLTAGE; 7171304850dSMark Brown dcdc->desc.ops = &wm831x_boostp_ops; 7181304850dSMark Brown dcdc->desc.owner = THIS_MODULE; 7193d138fccSMark Brown dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; 7203d138fccSMark Brown dcdc->desc.enable_mask = 1 << id; 7211304850dSMark Brown 722c172708dSMark Brown config.dev = pdev->dev.parent; 723f0b067d9SMark Brown if (pdata) 724c172708dSMark Brown config.init_data = pdata->dcdc[id]; 725c172708dSMark Brown config.driver_data = dcdc; 7263d138fccSMark Brown config.regmap = wm831x->regmap; 727c172708dSMark Brown 728d73b4cb7SMark Brown dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc, 729d73b4cb7SMark Brown &config); 7301304850dSMark Brown if (IS_ERR(dcdc->regulator)) { 7311304850dSMark Brown ret = PTR_ERR(dcdc->regulator); 7321304850dSMark Brown dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 7331304850dSMark Brown id + 1, ret); 734477b2bacSFabio Estevam return ret; 7351304850dSMark Brown } 7361304850dSMark Brown 737cd99758bSMark Brown irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 738b0c4c0c6SMark Brown ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 739b0c4c0c6SMark Brown wm831x_dcdc_uv_irq, 74029454738SFabio Estevam IRQF_TRIGGER_RISING | IRQF_ONESHOT, 74129454738SFabio Estevam dcdc->name, 7421304850dSMark Brown dcdc); 7431304850dSMark Brown if (ret != 0) { 7441304850dSMark Brown dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 7451304850dSMark Brown irq, ret); 746477b2bacSFabio Estevam return ret; 7471304850dSMark Brown } 7481304850dSMark Brown 7491304850dSMark Brown platform_set_drvdata(pdev, dcdc); 7501304850dSMark Brown 7511304850dSMark Brown return 0; 7521304850dSMark Brown } 7531304850dSMark Brown 7541304850dSMark Brown static struct platform_driver wm831x_boostp_driver = { 7551304850dSMark Brown .probe = wm831x_boostp_probe, 7561304850dSMark Brown .driver = { 7571304850dSMark Brown .name = "wm831x-boostp", 7581304850dSMark Brown }, 7591304850dSMark Brown }; 7601304850dSMark Brown 7611304850dSMark Brown /* 7628267a9baSMark Brown * External Power Enable 7638267a9baSMark Brown * 7648267a9baSMark Brown * These aren't actually DCDCs but look like them in hardware so share 7658267a9baSMark Brown * code. 7668267a9baSMark Brown */ 7678267a9baSMark Brown 7688267a9baSMark Brown #define WM831X_EPE_BASE 6 7698267a9baSMark Brown 770b0d6dd3bSJulia Lawall static const struct regulator_ops wm831x_epe_ops = { 7713d138fccSMark Brown .is_enabled = regulator_is_enabled_regmap, 7723d138fccSMark Brown .enable = regulator_enable_regmap, 7733d138fccSMark Brown .disable = regulator_disable_regmap, 7748267a9baSMark Brown .get_status = wm831x_dcdc_get_status, 7758267a9baSMark Brown }; 7768267a9baSMark Brown 777a5023574SBill Pemberton static int wm831x_epe_probe(struct platform_device *pdev) 7788267a9baSMark Brown { 7798267a9baSMark Brown struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 780dff91d0bSJingoo Han struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 781c172708dSMark Brown struct regulator_config config = { }; 7828267a9baSMark Brown int id = pdev->id % ARRAY_SIZE(pdata->epe); 7838267a9baSMark Brown struct wm831x_dcdc *dcdc; 7848267a9baSMark Brown int ret; 7858267a9baSMark Brown 7868267a9baSMark Brown dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1); 7878267a9baSMark Brown 7884c60165dSAxel Lin dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL); 7895730aa57SSachin Kamat if (!dcdc) 7908267a9baSMark Brown return -ENOMEM; 7918267a9baSMark Brown 7928267a9baSMark Brown dcdc->wm831x = wm831x; 7938267a9baSMark Brown 7948267a9baSMark Brown /* For current parts this is correct; probably need to revisit 7958267a9baSMark Brown * in future. 7968267a9baSMark Brown */ 7978267a9baSMark Brown snprintf(dcdc->name, sizeof(dcdc->name), "EPE%d", id + 1); 7988267a9baSMark Brown dcdc->desc.name = dcdc->name; 7998267a9baSMark Brown dcdc->desc.id = id + WM831X_EPE_BASE; /* Offset in DCDC registers */ 8008267a9baSMark Brown dcdc->desc.ops = &wm831x_epe_ops; 8018267a9baSMark Brown dcdc->desc.type = REGULATOR_VOLTAGE; 8028267a9baSMark Brown dcdc->desc.owner = THIS_MODULE; 8033d138fccSMark Brown dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; 8043d138fccSMark Brown dcdc->desc.enable_mask = 1 << dcdc->desc.id; 8058267a9baSMark Brown 806c172708dSMark Brown config.dev = pdev->dev.parent; 807b7ca8788SMark Brown if (pdata) 808c172708dSMark Brown config.init_data = pdata->epe[id]; 809c172708dSMark Brown config.driver_data = dcdc; 8103d138fccSMark Brown config.regmap = wm831x->regmap; 811c172708dSMark Brown 812d73b4cb7SMark Brown dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc, 813d73b4cb7SMark Brown &config); 8148267a9baSMark Brown if (IS_ERR(dcdc->regulator)) { 8158267a9baSMark Brown ret = PTR_ERR(dcdc->regulator); 8168267a9baSMark Brown dev_err(wm831x->dev, "Failed to register EPE%d: %d\n", 8178267a9baSMark Brown id + 1, ret); 8188267a9baSMark Brown goto err; 8198267a9baSMark Brown } 8208267a9baSMark Brown 8218267a9baSMark Brown platform_set_drvdata(pdev, dcdc); 8228267a9baSMark Brown 8238267a9baSMark Brown return 0; 8248267a9baSMark Brown 8258267a9baSMark Brown err: 8268267a9baSMark Brown return ret; 8278267a9baSMark Brown } 8288267a9baSMark Brown 8298267a9baSMark Brown static struct platform_driver wm831x_epe_driver = { 8308267a9baSMark Brown .probe = wm831x_epe_probe, 8318267a9baSMark Brown .driver = { 8328267a9baSMark Brown .name = "wm831x-epe", 8338267a9baSMark Brown }, 8348267a9baSMark Brown }; 8358267a9baSMark Brown 83655e03e9cSThierry Reding static struct platform_driver * const drivers[] = { 83755e03e9cSThierry Reding &wm831x_buckv_driver, 83855e03e9cSThierry Reding &wm831x_buckp_driver, 83955e03e9cSThierry Reding &wm831x_boostp_driver, 84055e03e9cSThierry Reding &wm831x_epe_driver, 84155e03e9cSThierry Reding }; 84255e03e9cSThierry Reding 843e4ee831fSMark Brown static int __init wm831x_dcdc_init(void) 844e4ee831fSMark Brown { 84555e03e9cSThierry Reding return platform_register_drivers(drivers, ARRAY_SIZE(drivers)); 846e4ee831fSMark Brown } 847e4ee831fSMark Brown subsys_initcall(wm831x_dcdc_init); 848e4ee831fSMark Brown 849e4ee831fSMark Brown static void __exit wm831x_dcdc_exit(void) 850e4ee831fSMark Brown { 85155e03e9cSThierry Reding platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); 852e4ee831fSMark Brown } 853e4ee831fSMark Brown module_exit(wm831x_dcdc_exit); 854e4ee831fSMark Brown 855e4ee831fSMark Brown /* Module information */ 856e4ee831fSMark Brown MODULE_AUTHOR("Mark Brown"); 857e4ee831fSMark Brown MODULE_DESCRIPTION("WM831x DC-DC convertor driver"); 858e4ee831fSMark Brown MODULE_LICENSE("GPL"); 859e4ee831fSMark Brown MODULE_ALIAS("platform:wm831x-buckv"); 860e4ee831fSMark Brown MODULE_ALIAS("platform:wm831x-buckp"); 86143f1f216SAxel Lin MODULE_ALIAS("platform:wm831x-boostp"); 86224b43150SMark Brown MODULE_ALIAS("platform:wm831x-epe"); 863