1571a354bSLiam Girdwood /* 2571a354bSLiam Girdwood * driver.h -- SoC Regulator driver support. 3571a354bSLiam Girdwood * 4571a354bSLiam Girdwood * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. 5571a354bSLiam Girdwood * 61dd68f01SLiam Girdwood * Author: Liam Girdwood <[email protected]> 7571a354bSLiam Girdwood * 8571a354bSLiam Girdwood * This program is free software; you can redistribute it and/or modify 9571a354bSLiam Girdwood * it under the terms of the GNU General Public License version 2 as 10571a354bSLiam Girdwood * published by the Free Software Foundation. 11571a354bSLiam Girdwood * 12571a354bSLiam Girdwood * Regulator Driver Interface. 13571a354bSLiam Girdwood */ 14571a354bSLiam Girdwood 15571a354bSLiam Girdwood #ifndef __LINUX_REGULATOR_DRIVER_H_ 16571a354bSLiam Girdwood #define __LINUX_REGULATOR_DRIVER_H_ 17571a354bSLiam Girdwood 1840c223efSDmitry Osipenko #define MAX_COUPLED 2 19a085a31aSMaciej Purski 20571a354bSLiam Girdwood #include <linux/device.h> 21ced55d4eSPaul Gortmaker #include <linux/notifier.h> 22571a354bSLiam Girdwood #include <linux/regulator/consumer.h> 23f8702f9eSDmitry Osipenko #include <linux/ww_mutex.h> 24571a354bSLiam Girdwood 25e45e290aSLinus Walleij struct gpio_desc; 2665b19ce6SMark Brown struct regmap; 27571a354bSLiam Girdwood struct regulator_dev; 28bfa21a0dSKrzysztof Kozlowski struct regulator_config; 29a5766f11SLiam Girdwood struct regulator_init_data; 30f19b00daSKim, Milo struct regulator_enable_gpio; 31571a354bSLiam Girdwood 32853116a1SDavid Brownell enum regulator_status { 33853116a1SDavid Brownell REGULATOR_STATUS_OFF, 34853116a1SDavid Brownell REGULATOR_STATUS_ON, 35853116a1SDavid Brownell REGULATOR_STATUS_ERROR, 36853116a1SDavid Brownell /* fast/normal/idle/standby are flavors of "on" */ 37853116a1SDavid Brownell REGULATOR_STATUS_FAST, 38853116a1SDavid Brownell REGULATOR_STATUS_NORMAL, 39853116a1SDavid Brownell REGULATOR_STATUS_IDLE, 40853116a1SDavid Brownell REGULATOR_STATUS_STANDBY, 41f59c8f9fSMark Brown /* The regulator is enabled but not regulating */ 42f59c8f9fSMark Brown REGULATOR_STATUS_BYPASS, 431beaf762SKrystian Garbaciak /* in case that any other status doesn't apply */ 441beaf762SKrystian Garbaciak REGULATOR_STATUS_UNDEFINED, 45853116a1SDavid Brownell }; 46853116a1SDavid Brownell 47571a354bSLiam Girdwood /** 487c2330f1SRandy Dunlap * struct regulator_linear_range - specify linear voltage ranges 497c2330f1SRandy Dunlap * 507bd0c7baSMatthias Kaehlcke * Specify a range of voltages for regulator_map_linear_range() and 5194d33c02SMark Brown * regulator_list_linear_range(). 5294d33c02SMark Brown * 5394d33c02SMark Brown * @min_uV: Lowest voltage in range 5494d33c02SMark Brown * @min_sel: Lowest selector for range 5594d33c02SMark Brown * @max_sel: Highest selector for range 5694d33c02SMark Brown * @uV_step: Step size 5794d33c02SMark Brown */ 5894d33c02SMark Brown struct regulator_linear_range { 5994d33c02SMark Brown unsigned int min_uV; 6094d33c02SMark Brown unsigned int min_sel; 6194d33c02SMark Brown unsigned int max_sel; 6294d33c02SMark Brown unsigned int uV_step; 6394d33c02SMark Brown }; 6494d33c02SMark Brown 658828bae4SAxel Lin /* Initialize struct regulator_linear_range */ 668828bae4SAxel Lin #define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \ 678828bae4SAxel Lin { \ 688828bae4SAxel Lin .min_uV = _min_uV, \ 698828bae4SAxel Lin .min_sel = _min_sel, \ 708828bae4SAxel Lin .max_sel = _max_sel, \ 718828bae4SAxel Lin .uV_step = _step_uV, \ 728828bae4SAxel Lin } 738828bae4SAxel Lin 7494d33c02SMark Brown /** 75571a354bSLiam Girdwood * struct regulator_ops - regulator operations. 76571a354bSLiam Girdwood * 773b2a6061SDavid Brownell * @enable: Configure the regulator as enabled. 783b2a6061SDavid Brownell * @disable: Configure the regulator as disabled. 79d87b969dSWolfram Sang * @is_enabled: Return 1 if the regulator is enabled, 0 if not. 80d87b969dSWolfram Sang * May also return negative errno. 81c8e7e464SMark Brown * 82c8e7e464SMark Brown * @set_voltage: Set the voltage for the regulator within the range specified. 83c8e7e464SMark Brown * The driver should select the voltage closest to min_uV. 84e8eef82bSMark Brown * @set_voltage_sel: Set the voltage for the regulator using the specified 85e8eef82bSMark Brown * selector. 86e843fc46SMark Brown * @map_voltage: Convert a voltage into a selector 8784b3a7c9SDouglas Anderson * @get_voltage: Return the currently configured voltage for the regulator; 8884b3a7c9SDouglas Anderson * return -ENOTRECOVERABLE if regulator can't be read at 8984b3a7c9SDouglas Anderson * bootup and hasn't been set yet. 90476c2d83SMark Brown * @get_voltage_sel: Return the currently configured voltage selector for the 9184b3a7c9SDouglas Anderson * regulator; return -ENOTRECOVERABLE if regulator can't 9284b3a7c9SDouglas Anderson * be read at bootup and hasn't been set yet. 934367cfdcSDavid Brownell * @list_voltage: Return one of the supported voltages, in microvolts; zero 944367cfdcSDavid Brownell * if the selector indicates a voltage that is unusable on this system; 954367cfdcSDavid Brownell * or negative errno. Selectors range from zero to one less than 964367cfdcSDavid Brownell * regulator_desc.n_voltages. Voltages may be reported in any order. 97c8e7e464SMark Brown * 98c8e7e464SMark Brown * @set_current_limit: Configure a limit for a current-limited regulator. 9989009e18SAxel Lin * The driver should select the current closest to max_uA. 1003b2a6061SDavid Brownell * @get_current_limit: Get the configured limit for a current-limited regulator. 10136e4f839SStephen Boyd * @set_input_current_limit: Configure an input limit. 102c8e7e464SMark Brown * 103abf2f825SLuis de Bethencourt * @set_over_current_protection: Support capability of automatically shutting 104abf2f825SLuis de Bethencourt * down when detecting an over current event. 105abf2f825SLuis de Bethencourt * 106670666b9SLaxman Dewangan * @set_active_discharge: Set active discharge enable/disable of regulators. 107670666b9SLaxman Dewangan * 1089f653251SRandy Dunlap * @set_mode: Set the configured operating mode for the regulator. 1093b2a6061SDavid Brownell * @get_mode: Get the configured operating mode for the regulator. 1101b5b4221SAxel Haslam * @get_error_flags: Get the current error(s) for the regulator. 1113b2a6061SDavid Brownell * @get_status: Return actual (not as-configured) status of regulator, as a 1123b2a6061SDavid Brownell * REGULATOR_STATUS value (or negative errno) 113c8e7e464SMark Brown * @get_optimum_mode: Get the most efficient operating mode for the regulator 114c8e7e464SMark Brown * when running with the specified parameters. 1158f4490e0SBjorn Andersson * @set_load: Set the load for the regulator. 116c8e7e464SMark Brown * 117f59c8f9fSMark Brown * @set_bypass: Set the regulator in bypass mode. 118f59c8f9fSMark Brown * @get_bypass: Get the regulator bypass mode state. 119f59c8f9fSMark Brown * 12031aae2beSMark Brown * @enable_time: Time taken for the regulator voltage output voltage to 12177af1b26SLinus Walleij * stabilise after being enabled, in microseconds. 1226f0b2c69SYadwinder Singh Brar * @set_ramp_delay: Set the ramp delay for the regulator. The driver should 1236f0b2c69SYadwinder Singh Brar * select ramp delay equal to or less than(closest) ramp_delay. 12473e705bfSMatthias Kaehlcke * @set_voltage_time: Time taken for the regulator voltage output voltage 12573e705bfSMatthias Kaehlcke * to stabilise after being set to a new value, in microseconds. 12673e705bfSMatthias Kaehlcke * The function receives the from and to voltage as input, it 12773e705bfSMatthias Kaehlcke * should return the worst case. 12877af1b26SLinus Walleij * @set_voltage_time_sel: Time taken for the regulator voltage output voltage 12977af1b26SLinus Walleij * to stabilise after being set to a new value, in microseconds. 13073e705bfSMatthias Kaehlcke * The function receives the from and to voltage selector as 13173e705bfSMatthias Kaehlcke * input, it should return the worst case. 132c751ad0dSStephen Boyd * @set_soft_start: Enable soft start for the regulator. 13331aae2beSMark Brown * 134c8e7e464SMark Brown * @set_suspend_voltage: Set the voltage for the regulator when the system 135c8e7e464SMark Brown * is suspended. 136c8e7e464SMark Brown * @set_suspend_enable: Mark the regulator as enabled when the system is 137c8e7e464SMark Brown * suspended. 138c8e7e464SMark Brown * @set_suspend_disable: Mark the regulator as disabled when the system is 139c8e7e464SMark Brown * suspended. 140c8e7e464SMark Brown * @set_suspend_mode: Set the operating mode for the regulator when the 141c8e7e464SMark Brown * system is suspended. 1423b2a6061SDavid Brownell * 14323c779b9SStephen Boyd * @set_pull_down: Configure the regulator to pull down when the regulator 14423c779b9SStephen Boyd * is disabled. 14523c779b9SStephen Boyd * 1463b2a6061SDavid Brownell * This struct describes regulator operations which can be implemented by 1473b2a6061SDavid Brownell * regulator chip drivers. 148571a354bSLiam Girdwood */ 149571a354bSLiam Girdwood struct regulator_ops { 150571a354bSLiam Girdwood 1514367cfdcSDavid Brownell /* enumerate supported voltages */ 1524367cfdcSDavid Brownell int (*list_voltage) (struct regulator_dev *, unsigned selector); 1534367cfdcSDavid Brownell 154571a354bSLiam Girdwood /* get/set regulator voltage */ 1553a93f2a9SMark Brown int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV, 1563a93f2a9SMark Brown unsigned *selector); 157e843fc46SMark Brown int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV); 158e8eef82bSMark Brown int (*set_voltage_sel) (struct regulator_dev *, unsigned selector); 159571a354bSLiam Girdwood int (*get_voltage) (struct regulator_dev *); 160476c2d83SMark Brown int (*get_voltage_sel) (struct regulator_dev *); 161571a354bSLiam Girdwood 162571a354bSLiam Girdwood /* get/set regulator current */ 163571a354bSLiam Girdwood int (*set_current_limit) (struct regulator_dev *, 164571a354bSLiam Girdwood int min_uA, int max_uA); 165571a354bSLiam Girdwood int (*get_current_limit) (struct regulator_dev *); 166571a354bSLiam Girdwood 16736e4f839SStephen Boyd int (*set_input_current_limit) (struct regulator_dev *, int lim_uA); 1683a003baeSStephen Boyd int (*set_over_current_protection) (struct regulator_dev *); 169670666b9SLaxman Dewangan int (*set_active_discharge) (struct regulator_dev *, bool enable); 17036e4f839SStephen Boyd 171571a354bSLiam Girdwood /* enable/disable regulator */ 172571a354bSLiam Girdwood int (*enable) (struct regulator_dev *); 173571a354bSLiam Girdwood int (*disable) (struct regulator_dev *); 174571a354bSLiam Girdwood int (*is_enabled) (struct regulator_dev *); 175571a354bSLiam Girdwood 176fde297bbSKim, Milo /* get/set regulator operating mode (defined in consumer.h) */ 177571a354bSLiam Girdwood int (*set_mode) (struct regulator_dev *, unsigned int mode); 178571a354bSLiam Girdwood unsigned int (*get_mode) (struct regulator_dev *); 179571a354bSLiam Girdwood 1801b5b4221SAxel Haslam /* retrieve current error flags on the regulator */ 1811b5b4221SAxel Haslam int (*get_error_flags)(struct regulator_dev *, unsigned int *flags); 1821b5b4221SAxel Haslam 18377af1b26SLinus Walleij /* Time taken to enable or set voltage on the regulator */ 18431aae2beSMark Brown int (*enable_time) (struct regulator_dev *); 1856f0b2c69SYadwinder Singh Brar int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay); 18673e705bfSMatthias Kaehlcke int (*set_voltage_time) (struct regulator_dev *, int old_uV, 18773e705bfSMatthias Kaehlcke int new_uV); 18877af1b26SLinus Walleij int (*set_voltage_time_sel) (struct regulator_dev *, 18977af1b26SLinus Walleij unsigned int old_selector, 19077af1b26SLinus Walleij unsigned int new_selector); 19131aae2beSMark Brown 19257f66b78SStephen Boyd int (*set_soft_start) (struct regulator_dev *); 19357f66b78SStephen Boyd 194853116a1SDavid Brownell /* report regulator status ... most other accessors report 195853116a1SDavid Brownell * control inputs, this reports results of combining inputs 196853116a1SDavid Brownell * from Linux (and other sources) with the actual load. 1973b2a6061SDavid Brownell * returns REGULATOR_STATUS_* or negative errno. 198853116a1SDavid Brownell */ 199853116a1SDavid Brownell int (*get_status)(struct regulator_dev *); 200853116a1SDavid Brownell 201571a354bSLiam Girdwood /* get most efficient regulator operating mode for load */ 202571a354bSLiam Girdwood unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, 203571a354bSLiam Girdwood int output_uV, int load_uA); 2048f4490e0SBjorn Andersson /* set the load on the regulator */ 2058f4490e0SBjorn Andersson int (*set_load)(struct regulator_dev *, int load_uA); 206571a354bSLiam Girdwood 207f59c8f9fSMark Brown /* control and report on bypass mode */ 208f59c8f9fSMark Brown int (*set_bypass)(struct regulator_dev *dev, bool enable); 209f59c8f9fSMark Brown int (*get_bypass)(struct regulator_dev *dev, bool *enable); 210f59c8f9fSMark Brown 211571a354bSLiam Girdwood /* the operations below are for configuration of regulator state when 2123de89609SMark Brown * its parent PMIC enters a global STANDBY/HIBERNATE state */ 213571a354bSLiam Girdwood 214571a354bSLiam Girdwood /* set regulator suspend voltage */ 215571a354bSLiam Girdwood int (*set_suspend_voltage) (struct regulator_dev *, int uV); 216571a354bSLiam Girdwood 217571a354bSLiam Girdwood /* enable/disable regulator in suspend state */ 218571a354bSLiam Girdwood int (*set_suspend_enable) (struct regulator_dev *); 219571a354bSLiam Girdwood int (*set_suspend_disable) (struct regulator_dev *); 220571a354bSLiam Girdwood 221fde297bbSKim, Milo /* set regulator suspend operating mode (defined in consumer.h) */ 222571a354bSLiam Girdwood int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); 22323c779b9SStephen Boyd 2240380cf7dSpascal paillet int (*resume)(struct regulator_dev *rdev); 225f7efad10SChunyan Zhang 22623c779b9SStephen Boyd int (*set_pull_down) (struct regulator_dev *); 227571a354bSLiam Girdwood }; 228571a354bSLiam Girdwood 229571a354bSLiam Girdwood /* 230571a354bSLiam Girdwood * Regulators can either control voltage or current. 231571a354bSLiam Girdwood */ 232571a354bSLiam Girdwood enum regulator_type { 233571a354bSLiam Girdwood REGULATOR_VOLTAGE, 234571a354bSLiam Girdwood REGULATOR_CURRENT, 235571a354bSLiam Girdwood }; 236571a354bSLiam Girdwood 237571a354bSLiam Girdwood /** 238c172708dSMark Brown * struct regulator_desc - Static regulator descriptor 239571a354bSLiam Girdwood * 240c172708dSMark Brown * Each regulator registered with the core is described with a 241c172708dSMark Brown * structure of this type and a struct regulator_config. This 242c172708dSMark Brown * structure contains the non-varying parts of the regulator 243c172708dSMark Brown * description. 244c8e7e464SMark Brown * 245c8e7e464SMark Brown * @name: Identifying name for the regulator. 24669511a45SRajendra Nayak * @supply_name: Identifying the regulator supply 247a0c7b164SMark Brown * @of_match: Name used to identify regulator in DT. 248a0c7b164SMark Brown * @regulators_node: Name of node containing regulator definitions in DT. 249bfa21a0dSKrzysztof Kozlowski * @of_parse_cb: Optional callback called only if of_match is present. 250bfa21a0dSKrzysztof Kozlowski * Will be called for each regulator parsed from DT, during 251bfa21a0dSKrzysztof Kozlowski * init_data parsing. 252bfa21a0dSKrzysztof Kozlowski * The regulator_config passed as argument to the callback will 253bfa21a0dSKrzysztof Kozlowski * be a copy of config passed to regulator_register, valid only 254bfa21a0dSKrzysztof Kozlowski * for this particular call. Callback may freely change the 255bfa21a0dSKrzysztof Kozlowski * config but it cannot store it for later usage. 256bfa21a0dSKrzysztof Kozlowski * Callback should return 0 on success or negative ERRNO 257bfa21a0dSKrzysztof Kozlowski * indicating failure. 258c8e7e464SMark Brown * @id: Numerical identifier for the regulator. 259c8e7e464SMark Brown * @ops: Regulator operations table. 2600ba4887cSRandy Dunlap * @irq: Interrupt number for the regulator. 261c8e7e464SMark Brown * @type: Indicates if the regulator is a voltage or current regulator. 262c8e7e464SMark Brown * @owner: Module providing the regulator, used for refcounting. 263bca7bbffSMark Brown * 264bd7a2b60SPawel Moll * @continuous_voltage_range: Indicates if the regulator can set any 265bd7a2b60SPawel Moll * voltage within constrains range. 266bca7bbffSMark Brown * @n_voltages: Number of selectors available for ops.list_voltage(). 267bca7bbffSMark Brown * 268bca7bbffSMark Brown * @min_uV: Voltage given by the lowest selector (if linear mapping) 269bca7bbffSMark Brown * @uV_step: Voltage increase with each selector (if linear mapping) 27033234e79SAxel Lin * @linear_min_sel: Minimal selector for starting linear mapping 2715a523605SLaxman Dewangan * @fixed_uV: Fixed voltage of rails. 272ea38d13fSAxel Lin * @ramp_delay: Time to settle down after voltage change (unit: uV/us) 2735abe4f22SSascha Hauer * @min_dropout_uV: The minimum dropout voltage this regulator can handle 274a8dbfeedSRandy Dunlap * @linear_ranges: A constant table of possible voltage ranges. 27518e4b55fSMatti Vaittinen * @linear_range_selectors: A constant table of voltage range selectors. 27618e4b55fSMatti Vaittinen * If pickable ranges are used each range must 27718e4b55fSMatti Vaittinen * have corresponding selector here. 27818e4b55fSMatti Vaittinen * @n_linear_ranges: Number of entries in the @linear_ranges (and in 27918e4b55fSMatti Vaittinen * linear_range_selectors if used) table(s). 280cffc9592SAxel Lin * @volt_table: Voltage mapping table (if table based mapping) 281bca7bbffSMark Brown * 28218e4b55fSMatti Vaittinen * @vsel_range_reg: Register for range selector when using pickable ranges 28318e4b55fSMatti Vaittinen * and regulator_regmap_X_voltage_X_pickable functions. 28418e4b55fSMatti Vaittinen * @vsel_range_mask: Mask for register bitfield used for range selector 2854ab5b3d9SMark Brown * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ 2864ab5b3d9SMark Brown * @vsel_mask: Mask for register bitfield used for selector 287d13d3a57SLuis de Bethencourt * @csel_reg: Register for TPS65218 LS3 current regulator 288d13d3a57SLuis de Bethencourt * @csel_mask: Mask for TPS65218 LS3 current regulator 289c8520b4cSAxel Lin * @apply_reg: Register for initiate voltage change on the output when 290c8520b4cSAxel Lin * using regulator_set_voltage_sel_regmap 291c8520b4cSAxel Lin * @apply_bit: Register bitfield used for initiate voltage change on the 292c8520b4cSAxel Lin * output when using regulator_set_voltage_sel_regmap 293cd6dffb4SMark Brown * @enable_reg: Register for control when using regmap enable/disable ops 294cd6dffb4SMark Brown * @enable_mask: Mask for control when using regmap enable/disable ops 295ca5d1b35SCarlo Caione * @enable_val: Enabling value for control when using regmap enable/disable ops 296ca5d1b35SCarlo Caione * @disable_val: Disabling value for control when using regmap enable/disable ops 29751dcdafcSAxel Lin * @enable_is_inverted: A flag to indicate set enable_mask bits to disable 29851dcdafcSAxel Lin * when using regulator_enable_regmap and friends APIs. 2995838b032SNishanth Menon * @bypass_reg: Register for control when using regmap set_bypass 3005838b032SNishanth Menon * @bypass_mask: Mask for control when using regmap set_bypass 301ca5d1b35SCarlo Caione * @bypass_val_on: Enabling value for control when using regmap set_bypass 302ca5d1b35SCarlo Caione * @bypass_val_off: Disabling value for control when using regmap set_bypass 303354794daSLaxman Dewangan * @active_discharge_off: Enabling value for control when using regmap 304354794daSLaxman Dewangan * set_active_discharge 305354794daSLaxman Dewangan * @active_discharge_on: Disabling value for control when using regmap 306354794daSLaxman Dewangan * set_active_discharge 307354794daSLaxman Dewangan * @active_discharge_mask: Mask for control when using regmap 308354794daSLaxman Dewangan * set_active_discharge 309354794daSLaxman Dewangan * @active_discharge_reg: Register for control when using regmap 310354794daSLaxman Dewangan * set_active_discharge 311a7a453f5SCharles Keepax * @soft_start_reg: Register for control when using regmap set_soft_start 312a7a453f5SCharles Keepax * @soft_start_mask: Mask for control when using regmap set_soft_start 313a7a453f5SCharles Keepax * @soft_start_val_on: Enabling value for control when using regmap 314a7a453f5SCharles Keepax * set_soft_start 315f7d37bc3SCharles Keepax * @pull_down_reg: Register for control when using regmap set_pull_down 316f7d37bc3SCharles Keepax * @pull_down_mask: Mask for control when using regmap set_pull_down 317f7d37bc3SCharles Keepax * @pull_down_val_on: Enabling value for control when using regmap 318f7d37bc3SCharles Keepax * set_pull_down 31979511ed3SMark Brown * 32079511ed3SMark Brown * @enable_time: Time taken for initial enable of regulator (in uS). 321871f5650SGuodong Xu * @off_on_delay: guard time (in uS), before re-enabling a regulator 32287e1e0f2SJavier Martinez Canillas * 32387e1e0f2SJavier Martinez Canillas * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode 324571a354bSLiam Girdwood */ 325571a354bSLiam Girdwood struct regulator_desc { 326571a354bSLiam Girdwood const char *name; 32769511a45SRajendra Nayak const char *supply_name; 328a0c7b164SMark Brown const char *of_match; 329a0c7b164SMark Brown const char *regulators_node; 330bfa21a0dSKrzysztof Kozlowski int (*of_parse_cb)(struct device_node *, 331bfa21a0dSKrzysztof Kozlowski const struct regulator_desc *, 332bfa21a0dSKrzysztof Kozlowski struct regulator_config *); 333571a354bSLiam Girdwood int id; 334de4a54c4SMark Brown unsigned int continuous_voltage_range:1; 3354367cfdcSDavid Brownell unsigned n_voltages; 336df11e506SAxel Lin const struct regulator_ops *ops; 337571a354bSLiam Girdwood int irq; 338571a354bSLiam Girdwood enum regulator_type type; 339571a354bSLiam Girdwood struct module *owner; 3404ab5b3d9SMark Brown 341bca7bbffSMark Brown unsigned int min_uV; 342bca7bbffSMark Brown unsigned int uV_step; 34333234e79SAxel Lin unsigned int linear_min_sel; 3445a523605SLaxman Dewangan int fixed_uV; 34598a175b6SYadwinder Singh Brar unsigned int ramp_delay; 3465abe4f22SSascha Hauer int min_dropout_uV; 347bca7bbffSMark Brown 34894d33c02SMark Brown const struct regulator_linear_range *linear_ranges; 34918e4b55fSMatti Vaittinen const unsigned int *linear_range_selectors; 35018e4b55fSMatti Vaittinen 35194d33c02SMark Brown int n_linear_ranges; 35294d33c02SMark Brown 353cffc9592SAxel Lin const unsigned int *volt_table; 354cffc9592SAxel Lin 35518e4b55fSMatti Vaittinen unsigned int vsel_range_reg; 35618e4b55fSMatti Vaittinen unsigned int vsel_range_mask; 3574ab5b3d9SMark Brown unsigned int vsel_reg; 3584ab5b3d9SMark Brown unsigned int vsel_mask; 359c0ea88b8SNikita Kiryanov unsigned int csel_reg; 360c0ea88b8SNikita Kiryanov unsigned int csel_mask; 361c8520b4cSAxel Lin unsigned int apply_reg; 362c8520b4cSAxel Lin unsigned int apply_bit; 363cd6dffb4SMark Brown unsigned int enable_reg; 364cd6dffb4SMark Brown unsigned int enable_mask; 365ca5d1b35SCarlo Caione unsigned int enable_val; 366ca5d1b35SCarlo Caione unsigned int disable_val; 36751dcdafcSAxel Lin bool enable_is_inverted; 368df367931SMark Brown unsigned int bypass_reg; 369df367931SMark Brown unsigned int bypass_mask; 370ca5d1b35SCarlo Caione unsigned int bypass_val_on; 371ca5d1b35SCarlo Caione unsigned int bypass_val_off; 372354794daSLaxman Dewangan unsigned int active_discharge_on; 373354794daSLaxman Dewangan unsigned int active_discharge_off; 374354794daSLaxman Dewangan unsigned int active_discharge_mask; 375354794daSLaxman Dewangan unsigned int active_discharge_reg; 376a7a453f5SCharles Keepax unsigned int soft_start_reg; 377a7a453f5SCharles Keepax unsigned int soft_start_mask; 378a7a453f5SCharles Keepax unsigned int soft_start_val_on; 379f7d37bc3SCharles Keepax unsigned int pull_down_reg; 380f7d37bc3SCharles Keepax unsigned int pull_down_mask; 381f7d37bc3SCharles Keepax unsigned int pull_down_val_on; 38279511ed3SMark Brown 38379511ed3SMark Brown unsigned int enable_time; 384871f5650SGuodong Xu 385871f5650SGuodong Xu unsigned int off_on_delay; 38687e1e0f2SJavier Martinez Canillas 38787e1e0f2SJavier Martinez Canillas unsigned int (*of_map_mode)(unsigned int mode); 388571a354bSLiam Girdwood }; 389571a354bSLiam Girdwood 390c172708dSMark Brown /** 391c172708dSMark Brown * struct regulator_config - Dynamic regulator descriptor 392c172708dSMark Brown * 393c172708dSMark Brown * Each regulator registered with the core is described with a 394c172708dSMark Brown * structure of this type and a struct regulator_desc. This structure 395c172708dSMark Brown * contains the runtime variable parts of the regulator description. 396c172708dSMark Brown * 397c172708dSMark Brown * @dev: struct device for the regulator 398c172708dSMark Brown * @init_data: platform provided init data, passed through by driver 399c172708dSMark Brown * @driver_data: private regulator data 400c172708dSMark Brown * @of_node: OpenFirmware node to parse for device tree bindings (may be 401c172708dSMark Brown * NULL). 402cf39284dSAxel Lin * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is 403380a0e6fSMark Brown * insufficient. 404*541d052dSLinus Walleij * @ena_gpiod: GPIO controlling regulator enable. 405c172708dSMark Brown */ 406c172708dSMark Brown struct regulator_config { 407c172708dSMark Brown struct device *dev; 408c172708dSMark Brown const struct regulator_init_data *init_data; 409c172708dSMark Brown void *driver_data; 410c172708dSMark Brown struct device_node *of_node; 41165b19ce6SMark Brown struct regmap *regmap; 41265f73508SMark Brown 413e45e290aSLinus Walleij struct gpio_desc *ena_gpiod; 414c172708dSMark Brown }; 415c172708dSMark Brown 4161fa9ad52SMark Brown /* 417a085a31aSMaciej Purski * struct coupling_desc 418a085a31aSMaciej Purski * 419a085a31aSMaciej Purski * Describes coupling of regulators. Each regulator should have 420a085a31aSMaciej Purski * at least a pointer to itself in coupled_rdevs array. 421a085a31aSMaciej Purski * When a new coupled regulator is resolved, n_resolved is 422a085a31aSMaciej Purski * incremented. 423a085a31aSMaciej Purski */ 424a085a31aSMaciej Purski struct coupling_desc { 425a085a31aSMaciej Purski struct regulator_dev *coupled_rdevs[MAX_COUPLED]; 426a085a31aSMaciej Purski int n_resolved; 427a085a31aSMaciej Purski int n_coupled; 428a085a31aSMaciej Purski }; 429a085a31aSMaciej Purski 430a085a31aSMaciej Purski /* 4311fa9ad52SMark Brown * struct regulator_dev 4321fa9ad52SMark Brown * 4331fa9ad52SMark Brown * Voltage / Current regulator class device. One for each 4341fa9ad52SMark Brown * regulator. 4351fa9ad52SMark Brown * 4361fa9ad52SMark Brown * This should *not* be used directly by anything except the regulator 4371fa9ad52SMark Brown * core and notification injection (which should take the mutex and do 4381fa9ad52SMark Brown * no other direct access). 4391fa9ad52SMark Brown */ 4401fa9ad52SMark Brown struct regulator_dev { 44165f26846SMark Brown const struct regulator_desc *desc; 4425ffbd136SMark Brown int exclusive; 4431130e5b3SMark Brown u32 use_count; 4441130e5b3SMark Brown u32 open_count; 445f59c8f9fSMark Brown u32 bypass_count; 4461fa9ad52SMark Brown 4471fa9ad52SMark Brown /* lists we belong to */ 4481fa9ad52SMark Brown struct list_head list; /* list of all regulators */ 4491fa9ad52SMark Brown 4501fa9ad52SMark Brown /* lists we own */ 4511fa9ad52SMark Brown struct list_head consumer_list; /* consumers we supply */ 4521fa9ad52SMark Brown 453a085a31aSMaciej Purski struct coupling_desc coupling_desc; 454a085a31aSMaciej Purski 4551fa9ad52SMark Brown struct blocking_notifier_head notifier; 456f8702f9eSDmitry Osipenko struct ww_mutex mutex; /* consumer lock */ 45766cf9a7eSMaciej Purski struct task_struct *mutex_owner; 45866cf9a7eSMaciej Purski int ref_cnt; 4591fa9ad52SMark Brown struct module *owner; 4601fa9ad52SMark Brown struct device dev; 4611fa9ad52SMark Brown struct regulation_constraints *constraints; 4623801b86aSMark Brown struct regulator *supply; /* for tree */ 4636261b06dSBjorn Andersson const char *supply_name; 46465b19ce6SMark Brown struct regmap *regmap; 4651fa9ad52SMark Brown 466da07ecd9SMark Brown struct delayed_work disable_work; 467da07ecd9SMark Brown 4681fa9ad52SMark Brown void *reg_data; /* regulator_dev data */ 4691130e5b3SMark Brown 4701130e5b3SMark Brown struct dentry *debugfs; 47165f73508SMark Brown 472f19b00daSKim, Milo struct regulator_enable_gpio *ena_pin; 47365f73508SMark Brown unsigned int ena_gpio_state:1; 474871f5650SGuodong Xu 475fd086045SMatthias Kaehlcke unsigned int is_switch:1; 476fd086045SMatthias Kaehlcke 477871f5650SGuodong Xu /* time when this regulator was disabled last time */ 478871f5650SGuodong Xu unsigned long last_off_jiffy; 4791fa9ad52SMark Brown }; 4801fa9ad52SMark Brown 48165f26846SMark Brown struct regulator_dev * 48265f26846SMark Brown regulator_register(const struct regulator_desc *regulator_desc, 483c172708dSMark Brown const struct regulator_config *config); 484b33e46bcSMark Brown struct regulator_dev * 485b33e46bcSMark Brown devm_regulator_register(struct device *dev, 486b33e46bcSMark Brown const struct regulator_desc *regulator_desc, 487b33e46bcSMark Brown const struct regulator_config *config); 488571a354bSLiam Girdwood void regulator_unregister(struct regulator_dev *rdev); 489b33e46bcSMark Brown void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev); 490571a354bSLiam Girdwood 491571a354bSLiam Girdwood int regulator_notifier_call_chain(struct regulator_dev *rdev, 492571a354bSLiam Girdwood unsigned long event, void *data); 493571a354bSLiam Girdwood 494571a354bSLiam Girdwood void *rdev_get_drvdata(struct regulator_dev *rdev); 495a5766f11SLiam Girdwood struct device *rdev_get_dev(struct regulator_dev *rdev); 49603c87b95SBartosz Golaszewski struct regmap *rdev_get_regmap(struct regulator_dev *rdev); 497571a354bSLiam Girdwood int rdev_get_id(struct regulator_dev *rdev); 498571a354bSLiam Girdwood 499be721979SMark Brown int regulator_mode_to_status(unsigned int); 500be721979SMark Brown 501bca7bbffSMark Brown int regulator_list_voltage_linear(struct regulator_dev *rdev, 502bca7bbffSMark Brown unsigned int selector); 50318e4b55fSMatti Vaittinen int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev, 50418e4b55fSMatti Vaittinen unsigned int selector); 50594d33c02SMark Brown int regulator_list_voltage_linear_range(struct regulator_dev *rdev, 50694d33c02SMark Brown unsigned int selector); 507cffc9592SAxel Lin int regulator_list_voltage_table(struct regulator_dev *rdev, 508cffc9592SAxel Lin unsigned int selector); 509bca7bbffSMark Brown int regulator_map_voltage_linear(struct regulator_dev *rdev, 510bca7bbffSMark Brown int min_uV, int max_uV); 51118e4b55fSMatti Vaittinen int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev, 51218e4b55fSMatti Vaittinen int min_uV, int max_uV); 51394d33c02SMark Brown int regulator_map_voltage_linear_range(struct regulator_dev *rdev, 51494d33c02SMark Brown int min_uV, int max_uV); 515e843fc46SMark Brown int regulator_map_voltage_iterate(struct regulator_dev *rdev, 516e843fc46SMark Brown int min_uV, int max_uV); 517fcf371eeSAxel Lin int regulator_map_voltage_ascend(struct regulator_dev *rdev, 518fcf371eeSAxel Lin int min_uV, int max_uV); 51918e4b55fSMatti Vaittinen int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev); 52018e4b55fSMatti Vaittinen int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev, 52118e4b55fSMatti Vaittinen unsigned int sel); 5224ab5b3d9SMark Brown int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev); 5234ab5b3d9SMark Brown int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel); 524cd6dffb4SMark Brown int regulator_is_enabled_regmap(struct regulator_dev *rdev); 525cd6dffb4SMark Brown int regulator_enable_regmap(struct regulator_dev *rdev); 526cd6dffb4SMark Brown int regulator_disable_regmap(struct regulator_dev *rdev); 52798a175b6SYadwinder Singh Brar int regulator_set_voltage_time_sel(struct regulator_dev *rdev, 52898a175b6SYadwinder Singh Brar unsigned int old_selector, 52998a175b6SYadwinder Singh Brar unsigned int new_selector); 530df367931SMark Brown int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable); 531df367931SMark Brown int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable); 532a7a453f5SCharles Keepax int regulator_set_soft_start_regmap(struct regulator_dev *rdev); 533f7d37bc3SCharles Keepax int regulator_set_pull_down_regmap(struct regulator_dev *rdev); 5344ab5b3d9SMark Brown 535354794daSLaxman Dewangan int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, 536354794daSLaxman Dewangan bool enable); 537a5766f11SLiam Girdwood void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 538a5766f11SLiam Girdwood 539f8702f9eSDmitry Osipenko void regulator_lock(struct regulator_dev *rdev); 540f8702f9eSDmitry Osipenko void regulator_unlock(struct regulator_dev *rdev); 541f8702f9eSDmitry Osipenko 542571a354bSLiam Girdwood #endif 543