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

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6: (32 commits)
regulator: twl4030 VAUX3 supports 3.0V
regulator: Support disabling of unused regulators by machines
regulator: Don't increment use_count for boot_on regulators
twl4030-regulator: expose VPLL2
regulator: refcount fixes
regulator: Don't warn if we failed to get a regulator
regulator: Allow boot_on regulators to be disabled by clients
regulator: Implement list_voltage for WM835x LDOs and DCDCs
twl4030-regulator: list more VAUX4 voltages
regulator: Don't warn on omitted voltage constraints
regulator: Implement list_voltage() for WM8400 DCDCs and LDOs
MMC: regulator utilities
regulator: twl4030 voltage enumeration (v2)
regulator: twl4030 regulators
regulator: get_status() grows kerneldoc
regulator: enumerate voltages (v2)
regulator: Fix get_mode() for WM835x DCDCs
regulator: Allow regulators to set the initial operating mode
regulator: Suggest use of datasheet supply or pin names for consumers
regulator: email - update email address and regulator webpage.
...

+1220 -117
+48 -9
Documentation/ABI/testing/sysfs-class-regulator
··· 4 4 Contact: Liam Girdwood <lrg@slimlogic.co.uk> 5 5 Description: 6 6 Some regulator directories will contain a field called 7 - state. This reports the regulator enable status, for 8 - regulators which can report that value. 7 + state. This reports the regulator enable control, for 8 + regulators which can report that input value. 9 9 10 10 This will be one of the following strings: 11 11 ··· 14 14 'unknown' 15 15 16 16 'enabled' means the regulator output is ON and is supplying 17 - power to the system. 17 + power to the system (assuming no error prevents it). 18 18 19 19 'disabled' means the regulator output is OFF and is not 20 - supplying power to the system.. 20 + supplying power to the system (unless some non-Linux 21 + control has enabled it). 21 22 22 23 'unknown' means software cannot determine the state, or 23 24 the reported state is invalid. 24 25 25 26 NOTE: this field can be used in conjunction with microvolts 26 - and microamps to determine regulator output levels. 27 + or microamps to determine configured regulator output levels. 28 + 29 + 30 + What: /sys/class/regulator/.../status 31 + Description: 32 + Some regulator directories will contain a field called 33 + "status". This reports the current regulator status, for 34 + regulators which can report that output value. 35 + 36 + This will be one of the following strings: 37 + 38 + off 39 + on 40 + error 41 + fast 42 + normal 43 + idle 44 + standby 45 + 46 + "off" means the regulator is not supplying power to the 47 + system. 48 + 49 + "on" means the regulator is supplying power to the system, 50 + and the regulator can't report a detailed operation mode. 51 + 52 + "error" indicates an out-of-regulation status such as being 53 + disabled due to thermal shutdown, or voltage being unstable 54 + because of problems with the input power supply. 55 + 56 + "fast", "normal", "idle", and "standby" are all detailed 57 + regulator operation modes (described elsewhere). They 58 + imply "on", but provide more detail. 59 + 60 + Note that regulator status is a function of many inputs, 61 + not limited to control inputs from Linux. For example, 62 + the actual load presented may trigger "error" status; or 63 + a regulator may be enabled by another user, even though 64 + Linux did not enable it. 27 65 28 66 29 67 What: /sys/class/regulator/.../type ··· 96 58 Some regulator directories will contain a field called 97 59 microvolts. This holds the regulator output voltage setting 98 60 measured in microvolts (i.e. E-6 Volts), for regulators 99 - which can report that voltage. 61 + which can report the control input for voltage. 100 62 101 63 NOTE: This value should not be used to determine the regulator 102 64 output voltage level as this value is the same regardless of ··· 111 73 Some regulator directories will contain a field called 112 74 microamps. This holds the regulator output current limit 113 75 setting measured in microamps (i.e. E-6 Amps), for regulators 114 - which can report that current. 76 + which can report the control input for a current limit. 115 77 116 78 NOTE: This value should not be used to determine the regulator 117 79 output current level as this value is the same regardless of ··· 125 87 Description: 126 88 Some regulator directories will contain a field called 127 89 opmode. This holds the current regulator operating mode, 128 - for regulators which can report it. 90 + for regulators which can report that control input value. 129 91 130 92 The opmode value can be one of the following strings: 131 93 ··· 139 101 140 102 NOTE: This value should not be used to determine the regulator 141 103 output operating mode as this value is the same regardless of 142 - whether the regulator is enabled or disabled. 104 + whether the regulator is enabled or disabled. A "status" 105 + attribute may be available to determine the actual mode. 143 106 144 107 145 108 What: /sys/class/regulator/.../min_microvolts
+1 -1
MAINTAINERS
··· 4847 4847 P: Mark Brown 4848 4848 M: broonie@opensource.wolfsonmicro.com 4849 4849 W: http://opensource.wolfsonmicro.com/node/15 4850 - W: http://www.slimlogic.co.uk/?page_id=5 4850 + W: http://www.slimlogic.co.uk/?p=48 4851 4851 T: git kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6.git 4852 4852 S: Supported 4853 4853
-2
drivers/mfd/twl4030-core.c
··· 592 592 593 593 /* maybe add LDOs that are omitted on cost-reduced parts */ 594 594 if (twl_has_regulator() && !(features & TPS_SUBSET)) { 595 - /* 596 595 child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2); 597 596 if (IS_ERR(child)) 598 597 return PTR_ERR(child); 599 - */ 600 598 601 599 child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2); 602 600 if (IS_ERR(child))
+100
drivers/mmc/core/core.c
··· 21 21 #include <linux/leds.h> 22 22 #include <linux/scatterlist.h> 23 23 #include <linux/log2.h> 24 + #include <linux/regulator/consumer.h> 24 25 25 26 #include <linux/mmc/card.h> 26 27 #include <linux/mmc/host.h> ··· 523 522 return mask; 524 523 } 525 524 EXPORT_SYMBOL(mmc_vddrange_to_ocrmask); 525 + 526 + #ifdef CONFIG_REGULATOR 527 + 528 + /** 529 + * mmc_regulator_get_ocrmask - return mask of supported voltages 530 + * @supply: regulator to use 531 + * 532 + * This returns either a negative errno, or a mask of voltages that 533 + * can be provided to MMC/SD/SDIO devices using the specified voltage 534 + * regulator. This would normally be called before registering the 535 + * MMC host adapter. 536 + */ 537 + int mmc_regulator_get_ocrmask(struct regulator *supply) 538 + { 539 + int result = 0; 540 + int count; 541 + int i; 542 + 543 + count = regulator_count_voltages(supply); 544 + if (count < 0) 545 + return count; 546 + 547 + for (i = 0; i < count; i++) { 548 + int vdd_uV; 549 + int vdd_mV; 550 + 551 + vdd_uV = regulator_list_voltage(supply, i); 552 + if (vdd_uV <= 0) 553 + continue; 554 + 555 + vdd_mV = vdd_uV / 1000; 556 + result |= mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV); 557 + } 558 + 559 + return result; 560 + } 561 + EXPORT_SYMBOL(mmc_regulator_get_ocrmask); 562 + 563 + /** 564 + * mmc_regulator_set_ocr - set regulator to match host->ios voltage 565 + * @vdd_bit: zero for power off, else a bit number (host->ios.vdd) 566 + * @supply: regulator to use 567 + * 568 + * Returns zero on success, else negative errno. 569 + * 570 + * MMC host drivers may use this to enable or disable a regulator using 571 + * a particular supply voltage. This would normally be called from the 572 + * set_ios() method. 573 + */ 574 + int mmc_regulator_set_ocr(struct regulator *supply, unsigned short vdd_bit) 575 + { 576 + int result = 0; 577 + int min_uV, max_uV; 578 + int enabled; 579 + 580 + enabled = regulator_is_enabled(supply); 581 + if (enabled < 0) 582 + return enabled; 583 + 584 + if (vdd_bit) { 585 + int tmp; 586 + int voltage; 587 + 588 + /* REVISIT mmc_vddrange_to_ocrmask() may have set some 589 + * bits this regulator doesn't quite support ... don't 590 + * be too picky, most cards and regulators are OK with 591 + * a 0.1V range goof (it's a small error percentage). 592 + */ 593 + tmp = vdd_bit - ilog2(MMC_VDD_165_195); 594 + if (tmp == 0) { 595 + min_uV = 1650 * 1000; 596 + max_uV = 1950 * 1000; 597 + } else { 598 + min_uV = 1900 * 1000 + tmp * 100 * 1000; 599 + max_uV = min_uV + 100 * 1000; 600 + } 601 + 602 + /* avoid needless changes to this voltage; the regulator 603 + * might not allow this operation 604 + */ 605 + voltage = regulator_get_voltage(supply); 606 + if (voltage < 0) 607 + result = voltage; 608 + else if (voltage < min_uV || voltage > max_uV) 609 + result = regulator_set_voltage(supply, min_uV, max_uV); 610 + else 611 + result = 0; 612 + 613 + if (result == 0 && !enabled) 614 + result = regulator_enable(supply); 615 + } else if (enabled) { 616 + result = regulator_disable(supply); 617 + } 618 + 619 + return result; 620 + } 621 + EXPORT_SYMBOL(mmc_regulator_set_ocr); 622 + 623 + #endif 526 624 527 625 /* 528 626 * Mask off any voltages we don't support and select
+12 -1
drivers/regulator/Kconfig
··· 29 29 Say yes here to enable debugging support. 30 30 31 31 config REGULATOR_FIXED_VOLTAGE 32 - tristate 32 + tristate "Fixed voltage regulator support" 33 33 default n 34 + help 35 + This driver provides support for fixed voltage regulators, 36 + useful for systems which use a combination of software 37 + managed regulators and simple non-configurable regulators. 34 38 35 39 config REGULATOR_VIRTUAL_CONSUMER 36 40 tristate "Virtual regulator consumer support" ··· 55 51 GPIOs. The provided current regulator can enable/disable 56 52 charging select between 100 mA and 500 mA charging current 57 53 limit. 54 + 55 + config REGULATOR_TWL4030 56 + bool "TI TWL4030/TWL5030/TPS695x0 PMIC" 57 + depends on TWL4030_CORE 58 + help 59 + This driver supports the voltage regulators provided by 60 + this family of companion chips. 58 61 59 62 config REGULATOR_WM8350 60 63 tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC"
+1
drivers/regulator/Makefile
··· 8 8 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 9 9 10 10 obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o 11 + obj-$(CONFIG_REGULATOR_TWL4030) += twl4030-regulator.o 11 12 obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o 12 13 obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o 13 14 obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
+2 -1
drivers/regulator/bq24022.c
··· 105 105 ret = gpio_direction_output(pdata->gpio_iset2, 0); 106 106 ret = gpio_direction_output(pdata->gpio_nce, 1); 107 107 108 - bq24022 = regulator_register(&bq24022_desc, &pdev->dev, pdata); 108 + bq24022 = regulator_register(&bq24022_desc, &pdev->dev, 109 + pdata->init_data, pdata); 109 110 if (IS_ERR(bq24022)) { 110 111 dev_dbg(&pdev->dev, "couldn't register regulator\n"); 111 112 ret = PTR_ERR(bq24022);
+316 -70
drivers/regulator/core.c
··· 28 28 static DEFINE_MUTEX(regulator_list_mutex); 29 29 static LIST_HEAD(regulator_list); 30 30 static LIST_HEAD(regulator_map_list); 31 - 32 - /* 33 - * struct regulator_dev 34 - * 35 - * Voltage / Current regulator class device. One for each regulator. 36 - */ 37 - struct regulator_dev { 38 - struct regulator_desc *desc; 39 - int use_count; 40 - 41 - /* lists we belong to */ 42 - struct list_head list; /* list of all regulators */ 43 - struct list_head slist; /* list of supplied regulators */ 44 - 45 - /* lists we own */ 46 - struct list_head consumer_list; /* consumers we supply */ 47 - struct list_head supply_list; /* regulators we supply */ 48 - 49 - struct blocking_notifier_head notifier; 50 - struct mutex mutex; /* consumer lock */ 51 - struct module *owner; 52 - struct device dev; 53 - struct regulation_constraints *constraints; 54 - struct regulator_dev *supply; /* for tree */ 55 - 56 - void *reg_data; /* regulator_dev data */ 57 - }; 31 + static int has_full_constraints; 58 32 59 33 /* 60 34 * struct regulator_map ··· 53 79 int uA_load; 54 80 int min_uV; 55 81 int max_uV; 56 - int enabled; /* count of client enables */ 57 82 char *supply_name; 58 83 struct device_attribute dev_attr; 59 84 struct regulator_dev *rdev; ··· 284 311 return regulator_print_state(buf, _regulator_is_enabled(rdev)); 285 312 } 286 313 static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); 314 + 315 + static ssize_t regulator_status_show(struct device *dev, 316 + struct device_attribute *attr, char *buf) 317 + { 318 + struct regulator_dev *rdev = dev_get_drvdata(dev); 319 + int status; 320 + char *label; 321 + 322 + status = rdev->desc->ops->get_status(rdev); 323 + if (status < 0) 324 + return status; 325 + 326 + switch (status) { 327 + case REGULATOR_STATUS_OFF: 328 + label = "off"; 329 + break; 330 + case REGULATOR_STATUS_ON: 331 + label = "on"; 332 + break; 333 + case REGULATOR_STATUS_ERROR: 334 + label = "error"; 335 + break; 336 + case REGULATOR_STATUS_FAST: 337 + label = "fast"; 338 + break; 339 + case REGULATOR_STATUS_NORMAL: 340 + label = "normal"; 341 + break; 342 + case REGULATOR_STATUS_IDLE: 343 + label = "idle"; 344 + break; 345 + case REGULATOR_STATUS_STANDBY: 346 + label = "standby"; 347 + break; 348 + default: 349 + return -ERANGE; 350 + } 351 + 352 + return sprintf(buf, "%s\n", label); 353 + } 354 + static DEVICE_ATTR(status, 0444, regulator_status_show, NULL); 287 355 288 356 static ssize_t regulator_min_uA_show(struct device *dev, 289 357 struct device_attribute *attr, char *buf) ··· 692 678 else 693 679 name = "regulator"; 694 680 681 + /* constrain machine-level voltage specs to fit 682 + * the actual range supported by this regulator. 683 + */ 684 + if (ops->list_voltage && rdev->desc->n_voltages) { 685 + int count = rdev->desc->n_voltages; 686 + int i; 687 + int min_uV = INT_MAX; 688 + int max_uV = INT_MIN; 689 + int cmin = constraints->min_uV; 690 + int cmax = constraints->max_uV; 691 + 692 + /* it's safe to autoconfigure fixed-voltage supplies */ 693 + if (count == 1 && !cmin) { 694 + cmin = INT_MIN; 695 + cmax = INT_MAX; 696 + } 697 + 698 + /* voltage constraints are optional */ 699 + if ((cmin == 0) && (cmax == 0)) 700 + goto out; 701 + 702 + /* else require explicit machine-level constraints */ 703 + if (cmin <= 0 || cmax <= 0 || cmax < cmin) { 704 + pr_err("%s: %s '%s' voltage constraints\n", 705 + __func__, "invalid", name); 706 + ret = -EINVAL; 707 + goto out; 708 + } 709 + 710 + /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ 711 + for (i = 0; i < count; i++) { 712 + int value; 713 + 714 + value = ops->list_voltage(rdev, i); 715 + if (value <= 0) 716 + continue; 717 + 718 + /* maybe adjust [min_uV..max_uV] */ 719 + if (value >= cmin && value < min_uV) 720 + min_uV = value; 721 + if (value <= cmax && value > max_uV) 722 + max_uV = value; 723 + } 724 + 725 + /* final: [min_uV..max_uV] valid iff constraints valid */ 726 + if (max_uV < min_uV) { 727 + pr_err("%s: %s '%s' voltage constraints\n", 728 + __func__, "unsupportable", name); 729 + ret = -EINVAL; 730 + goto out; 731 + } 732 + 733 + /* use regulator's subset of machine constraints */ 734 + if (constraints->min_uV < min_uV) { 735 + pr_debug("%s: override '%s' %s, %d -> %d\n", 736 + __func__, name, "min_uV", 737 + constraints->min_uV, min_uV); 738 + constraints->min_uV = min_uV; 739 + } 740 + if (constraints->max_uV > max_uV) { 741 + pr_debug("%s: override '%s' %s, %d -> %d\n", 742 + __func__, name, "max_uV", 743 + constraints->max_uV, max_uV); 744 + constraints->max_uV = max_uV; 745 + } 746 + } 747 + 695 748 rdev->constraints = constraints; 696 749 697 750 /* do we need to apply the constraint voltage */ ··· 776 695 } 777 696 } 778 697 779 - /* are we enabled at boot time by firmware / bootloader */ 780 - if (rdev->constraints->boot_on) 781 - rdev->use_count = 1; 782 - 783 698 /* do we need to setup our suspend state */ 784 699 if (constraints->initial_state) { 785 700 ret = suspend_prepare(rdev, constraints->initial_state); ··· 787 710 } 788 711 } 789 712 790 - /* if always_on is set then turn the regulator on if it's not 791 - * already on. */ 792 - if (constraints->always_on && ops->enable && 793 - ((ops->is_enabled && !ops->is_enabled(rdev)) || 794 - (!ops->is_enabled && !constraints->boot_on))) { 713 + if (constraints->initial_mode) { 714 + if (!ops->set_mode) { 715 + printk(KERN_ERR "%s: no set_mode operation for %s\n", 716 + __func__, name); 717 + ret = -EINVAL; 718 + goto out; 719 + } 720 + 721 + ret = ops->set_mode(rdev, constraints->initial_mode); 722 + if (ret < 0) { 723 + printk(KERN_ERR 724 + "%s: failed to set initial mode for %s: %d\n", 725 + __func__, name, ret); 726 + goto out; 727 + } 728 + } 729 + 730 + /* If the constraints say the regulator should be on at this point 731 + * and we have control then make sure it is enabled. 732 + */ 733 + if ((constraints->always_on || constraints->boot_on) && ops->enable) { 795 734 ret = ops->enable(rdev); 796 735 if (ret < 0) { 797 736 printk(KERN_ERR "%s: failed to enable %s\n", ··· 910 817 } 911 818 } 912 819 820 + static void unset_regulator_supplies(struct regulator_dev *rdev) 821 + { 822 + struct regulator_map *node, *n; 823 + 824 + list_for_each_entry_safe(node, n, &regulator_map_list, list) { 825 + if (rdev == node->regulator) { 826 + list_del(&node->list); 827 + kfree(node); 828 + return; 829 + } 830 + } 831 + } 832 + 913 833 #define REG_STR_SIZE 32 914 834 915 835 static struct regulator *create_regulator(struct regulator_dev *rdev, ··· 1004 898 * @id: Supply name or regulator ID. 1005 899 * 1006 900 * Returns a struct regulator corresponding to the regulator producer, 1007 - * or IS_ERR() condition containing errno. Use of supply names 1008 - * configured via regulator_set_device_supply() is strongly 1009 - * encouraged. 901 + * or IS_ERR() condition containing errno. 902 + * 903 + * Use of supply names configured via regulator_set_device_supply() is 904 + * strongly encouraged. It is recommended that the supply name used 905 + * should match the name used for the supply and/or the relevant 906 + * device pins in the datasheet. 1010 907 */ 1011 908 struct regulator *regulator_get(struct device *dev, const char *id) 1012 909 { ··· 1031 922 goto found; 1032 923 } 1033 924 } 1034 - printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", 1035 - id); 1036 925 mutex_unlock(&regulator_list_mutex); 1037 926 return regulator; 1038 927 ··· 1067 960 1068 961 mutex_lock(&regulator_list_mutex); 1069 962 rdev = regulator->rdev; 1070 - 1071 - if (WARN(regulator->enabled, "Releasing supply %s while enabled\n", 1072 - regulator->supply_name)) 1073 - _regulator_disable(rdev); 1074 963 1075 964 /* remove any sysfs entries */ 1076 965 if (regulator->dev) { ··· 1142 1039 int ret = 0; 1143 1040 1144 1041 mutex_lock(&rdev->mutex); 1145 - if (regulator->enabled == 0) 1146 - ret = _regulator_enable(rdev); 1147 - else if (regulator->enabled < 0) 1148 - ret = -EIO; 1149 - if (ret == 0) 1150 - regulator->enabled++; 1042 + ret = _regulator_enable(rdev); 1151 1043 mutex_unlock(&rdev->mutex); 1152 1044 return ret; 1153 1045 } ··· 1152 1054 static int _regulator_disable(struct regulator_dev *rdev) 1153 1055 { 1154 1056 int ret = 0; 1057 + 1058 + if (WARN(rdev->use_count <= 0, 1059 + "unbalanced disables for %s\n", 1060 + rdev->desc->name)) 1061 + return -EIO; 1155 1062 1156 1063 /* are we the last user and permitted to disable ? */ 1157 1064 if (rdev->use_count == 1 && !rdev->constraints->always_on) { ··· 1206 1103 int ret = 0; 1207 1104 1208 1105 mutex_lock(&rdev->mutex); 1209 - if (regulator->enabled == 1) { 1210 - ret = _regulator_disable(rdev); 1211 - if (ret == 0) 1212 - regulator->uA_load = 0; 1213 - } else if (WARN(regulator->enabled <= 0, 1214 - "unbalanced disables for supply %s\n", 1215 - regulator->supply_name)) 1216 - ret = -EIO; 1217 - if (ret == 0) 1218 - regulator->enabled--; 1106 + ret = _regulator_disable(rdev); 1219 1107 mutex_unlock(&rdev->mutex); 1220 1108 return ret; 1221 1109 } ··· 1253 1159 int ret; 1254 1160 1255 1161 mutex_lock(&regulator->rdev->mutex); 1256 - regulator->enabled = 0; 1257 1162 regulator->uA_load = 0; 1258 1163 ret = _regulator_force_disable(regulator->rdev); 1259 1164 mutex_unlock(&regulator->rdev->mutex); ··· 1297 1204 EXPORT_SYMBOL_GPL(regulator_is_enabled); 1298 1205 1299 1206 /** 1207 + * regulator_count_voltages - count regulator_list_voltage() selectors 1208 + * @regulator: regulator source 1209 + * 1210 + * Returns number of selectors, or negative errno. Selectors are 1211 + * numbered starting at zero, and typically correspond to bitfields 1212 + * in hardware registers. 1213 + */ 1214 + int regulator_count_voltages(struct regulator *regulator) 1215 + { 1216 + struct regulator_dev *rdev = regulator->rdev; 1217 + 1218 + return rdev->desc->n_voltages ? : -EINVAL; 1219 + } 1220 + EXPORT_SYMBOL_GPL(regulator_count_voltages); 1221 + 1222 + /** 1223 + * regulator_list_voltage - enumerate supported voltages 1224 + * @regulator: regulator source 1225 + * @selector: identify voltage to list 1226 + * Context: can sleep 1227 + * 1228 + * Returns a voltage that can be passed to @regulator_set_voltage(), 1229 + * zero if this selector code can't be used on this sytem, or a 1230 + * negative errno. 1231 + */ 1232 + int regulator_list_voltage(struct regulator *regulator, unsigned selector) 1233 + { 1234 + struct regulator_dev *rdev = regulator->rdev; 1235 + struct regulator_ops *ops = rdev->desc->ops; 1236 + int ret; 1237 + 1238 + if (!ops->list_voltage || selector >= rdev->desc->n_voltages) 1239 + return -EINVAL; 1240 + 1241 + mutex_lock(&rdev->mutex); 1242 + ret = ops->list_voltage(rdev, selector); 1243 + mutex_unlock(&rdev->mutex); 1244 + 1245 + if (ret > 0) { 1246 + if (ret < rdev->constraints->min_uV) 1247 + ret = 0; 1248 + else if (ret > rdev->constraints->max_uV) 1249 + ret = 0; 1250 + } 1251 + 1252 + return ret; 1253 + } 1254 + EXPORT_SYMBOL_GPL(regulator_list_voltage); 1255 + 1256 + /** 1300 1257 * regulator_set_voltage - set regulator output voltage 1301 1258 * @regulator: regulator source 1302 1259 * @min_uV: Minimum required voltage in uV ··· 1386 1243 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); 1387 1244 1388 1245 out: 1246 + _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL); 1389 1247 mutex_unlock(&rdev->mutex); 1390 1248 return ret; 1391 1249 } ··· 1687 1543 } 1688 1544 EXPORT_SYMBOL_GPL(regulator_unregister_notifier); 1689 1545 1690 - /* notify regulator consumers and downstream regulator consumers */ 1546 + /* notify regulator consumers and downstream regulator consumers. 1547 + * Note mutex must be held by caller. 1548 + */ 1691 1549 static void _notifier_call_chain(struct regulator_dev *rdev, 1692 1550 unsigned long event, void *data) 1693 1551 { 1694 1552 struct regulator_dev *_rdev; 1695 1553 1696 1554 /* call rdev chain first */ 1697 - mutex_lock(&rdev->mutex); 1698 1555 blocking_notifier_call_chain(&rdev->notifier, event, NULL); 1699 - mutex_unlock(&rdev->mutex); 1700 1556 1701 1557 /* now notify regulator we supply */ 1702 - list_for_each_entry(_rdev, &rdev->supply_list, slist) 1703 - _notifier_call_chain(_rdev, event, data); 1558 + list_for_each_entry(_rdev, &rdev->supply_list, slist) { 1559 + mutex_lock(&_rdev->mutex); 1560 + _notifier_call_chain(_rdev, event, data); 1561 + mutex_unlock(&_rdev->mutex); 1562 + } 1704 1563 } 1705 1564 1706 1565 /** ··· 1850 1703 * 1851 1704 * Called by regulator drivers to notify clients a regulator event has 1852 1705 * occurred. We also notify regulator clients downstream. 1706 + * Note lock must be held by caller. 1853 1707 */ 1854 1708 int regulator_notifier_call_chain(struct regulator_dev *rdev, 1855 1709 unsigned long event, void *data) ··· 1889 1741 } 1890 1742 if (ops->is_enabled) { 1891 1743 status = device_create_file(dev, &dev_attr_state); 1744 + if (status < 0) 1745 + return status; 1746 + } 1747 + if (ops->get_status) { 1748 + status = device_create_file(dev, &dev_attr_status); 1892 1749 if (status < 0) 1893 1750 return status; 1894 1751 } ··· 1981 1828 * regulator_register - register regulator 1982 1829 * @regulator_desc: regulator to register 1983 1830 * @dev: struct device for the regulator 1831 + * @init_data: platform provided init data, passed through by driver 1984 1832 * @driver_data: private regulator data 1985 1833 * 1986 1834 * Called by regulator drivers to register a regulator. 1987 1835 * Returns 0 on success. 1988 1836 */ 1989 1837 struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 1990 - struct device *dev, void *driver_data) 1838 + struct device *dev, struct regulator_init_data *init_data, 1839 + void *driver_data) 1991 1840 { 1992 1841 static atomic_t regulator_no = ATOMIC_INIT(0); 1993 1842 struct regulator_dev *rdev; 1994 - struct regulator_init_data *init_data = dev->platform_data; 1995 1843 int ret, i; 1996 1844 1997 1845 if (regulator_desc == NULL) ··· 2099 1945 return; 2100 1946 2101 1947 mutex_lock(&regulator_list_mutex); 1948 + unset_regulator_supplies(rdev); 2102 1949 list_del(&rdev->list); 2103 1950 if (rdev->supply) 2104 1951 sysfs_remove_link(&rdev->dev.kobj, "supply"); ··· 2142 1987 return ret; 2143 1988 } 2144 1989 EXPORT_SYMBOL_GPL(regulator_suspend_prepare); 1990 + 1991 + /** 1992 + * regulator_has_full_constraints - the system has fully specified constraints 1993 + * 1994 + * Calling this function will cause the regulator API to disable all 1995 + * regulators which have a zero use count and don't have an always_on 1996 + * constraint in a late_initcall. 1997 + * 1998 + * The intention is that this will become the default behaviour in a 1999 + * future kernel release so users are encouraged to use this facility 2000 + * now. 2001 + */ 2002 + void regulator_has_full_constraints(void) 2003 + { 2004 + has_full_constraints = 1; 2005 + } 2006 + EXPORT_SYMBOL_GPL(regulator_has_full_constraints); 2145 2007 2146 2008 /** 2147 2009 * rdev_get_drvdata - get rdev regulator driver data ··· 2227 2055 2228 2056 /* init early to allow our consumers to complete system booting */ 2229 2057 core_initcall(regulator_init); 2058 + 2059 + static int __init regulator_init_complete(void) 2060 + { 2061 + struct regulator_dev *rdev; 2062 + struct regulator_ops *ops; 2063 + struct regulation_constraints *c; 2064 + int enabled, ret; 2065 + const char *name; 2066 + 2067 + mutex_lock(&regulator_list_mutex); 2068 + 2069 + /* If we have a full configuration then disable any regulators 2070 + * which are not in use or always_on. This will become the 2071 + * default behaviour in the future. 2072 + */ 2073 + list_for_each_entry(rdev, &regulator_list, list) { 2074 + ops = rdev->desc->ops; 2075 + c = rdev->constraints; 2076 + 2077 + if (c->name) 2078 + name = c->name; 2079 + else if (rdev->desc->name) 2080 + name = rdev->desc->name; 2081 + else 2082 + name = "regulator"; 2083 + 2084 + if (!ops->disable || c->always_on) 2085 + continue; 2086 + 2087 + mutex_lock(&rdev->mutex); 2088 + 2089 + if (rdev->use_count) 2090 + goto unlock; 2091 + 2092 + /* If we can't read the status assume it's on. */ 2093 + if (ops->is_enabled) 2094 + enabled = ops->is_enabled(rdev); 2095 + else 2096 + enabled = 1; 2097 + 2098 + if (!enabled) 2099 + goto unlock; 2100 + 2101 + if (has_full_constraints) { 2102 + /* We log since this may kill the system if it 2103 + * goes wrong. */ 2104 + printk(KERN_INFO "%s: disabling %s\n", 2105 + __func__, name); 2106 + ret = ops->disable(rdev); 2107 + if (ret != 0) { 2108 + printk(KERN_ERR 2109 + "%s: couldn't disable %s: %d\n", 2110 + __func__, name, ret); 2111 + } 2112 + } else { 2113 + /* The intention is that in future we will 2114 + * assume that full constraints are provided 2115 + * so warn even if we aren't going to do 2116 + * anything here. 2117 + */ 2118 + printk(KERN_WARNING 2119 + "%s: incomplete constraints, leaving %s on\n", 2120 + __func__, name); 2121 + } 2122 + 2123 + unlock: 2124 + mutex_unlock(&rdev->mutex); 2125 + } 2126 + 2127 + mutex_unlock(&regulator_list_mutex); 2128 + 2129 + return 0; 2130 + } 2131 + late_initcall(regulator_init_complete);
+2 -1
drivers/regulator/da903x.c
··· 471 471 if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15) 472 472 ri->desc.ops = &da9030_regulator_ldo1_15_ops; 473 473 474 - rdev = regulator_register(&ri->desc, &pdev->dev, ri); 474 + rdev = regulator_register(&ri->desc, &pdev->dev, 475 + pdev->dev.platform_data, ri); 475 476 if (IS_ERR(rdev)) { 476 477 dev_err(&pdev->dev, "failed to register regulator %s\n", 477 478 ri->desc.name);
+2 -1
drivers/regulator/fixed.c
··· 73 73 74 74 drvdata->microvolts = config->microvolts; 75 75 76 - drvdata->dev = regulator_register(&drvdata->desc, drvdata); 76 + drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, 77 + config->init_data, drvdata); 77 78 if (IS_ERR(drvdata->dev)) { 78 79 ret = PTR_ERR(drvdata->dev); 79 80 goto err_name;
+2 -1
drivers/regulator/pcf50633-regulator.c
··· 284 284 /* Already set by core driver */ 285 285 pcf = platform_get_drvdata(pdev); 286 286 287 - rdev = regulator_register(&regulators[pdev->id], &pdev->dev, pcf); 287 + rdev = regulator_register(&regulators[pdev->id], &pdev->dev, 288 + pdev->dev.platform_data, pcf); 288 289 if (IS_ERR(rdev)) 289 290 return PTR_ERR(rdev); 290 291
+500
drivers/regulator/twl4030-regulator.c
··· 1 + /* 2 + * twl4030-regulator.c -- support regulators in twl4030 family chips 3 + * 4 + * Copyright (C) 2008 David Brownell 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + */ 11 + 12 + #include <linux/module.h> 13 + #include <linux/init.h> 14 + #include <linux/err.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/regulator/driver.h> 17 + #include <linux/regulator/machine.h> 18 + #include <linux/i2c/twl4030.h> 19 + 20 + 21 + /* 22 + * The TWL4030/TW5030/TPS659x0 family chips include power management, a 23 + * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions 24 + * include an audio codec, battery charger, and more voltage regulators. 25 + * These chips are often used in OMAP-based systems. 26 + * 27 + * This driver implements software-based resource control for various 28 + * voltage regulators. This is usually augmented with state machine 29 + * based control. 30 + */ 31 + 32 + struct twlreg_info { 33 + /* start of regulator's PM_RECEIVER control register bank */ 34 + u8 base; 35 + 36 + /* twl4030 resource ID, for resource control state machine */ 37 + u8 id; 38 + 39 + /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ 40 + u8 table_len; 41 + const u16 *table; 42 + 43 + /* chip constraints on regulator behavior */ 44 + u16 min_mV; 45 + 46 + /* used by regulator core */ 47 + struct regulator_desc desc; 48 + }; 49 + 50 + 51 + /* LDO control registers ... offset is from the base of its register bank. 52 + * The first three registers of all power resource banks help hardware to 53 + * manage the various resource groups. 54 + */ 55 + #define VREG_GRP 0 56 + #define VREG_TYPE 1 57 + #define VREG_REMAP 2 58 + #define VREG_DEDICATED 3 /* LDO control */ 59 + 60 + 61 + static inline int 62 + twl4030reg_read(struct twlreg_info *info, unsigned offset) 63 + { 64 + u8 value; 65 + int status; 66 + 67 + status = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, 68 + &value, info->base + offset); 69 + return (status < 0) ? status : value; 70 + } 71 + 72 + static inline int 73 + twl4030reg_write(struct twlreg_info *info, unsigned offset, u8 value) 74 + { 75 + return twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 76 + value, info->base + offset); 77 + } 78 + 79 + /*----------------------------------------------------------------------*/ 80 + 81 + /* generic power resource operations, which work on all regulators */ 82 + 83 + static int twl4030reg_grp(struct regulator_dev *rdev) 84 + { 85 + return twl4030reg_read(rdev_get_drvdata(rdev), VREG_GRP); 86 + } 87 + 88 + /* 89 + * Enable/disable regulators by joining/leaving the P1 (processor) group. 90 + * We assume nobody else is updating the DEV_GRP registers. 91 + */ 92 + 93 + #define P3_GRP BIT(7) /* "peripherals" */ 94 + #define P2_GRP BIT(6) /* secondary processor, modem, etc */ 95 + #define P1_GRP BIT(5) /* CPU/Linux */ 96 + 97 + static int twl4030reg_is_enabled(struct regulator_dev *rdev) 98 + { 99 + int state = twl4030reg_grp(rdev); 100 + 101 + if (state < 0) 102 + return state; 103 + 104 + return (state & P1_GRP) != 0; 105 + } 106 + 107 + static int twl4030reg_enable(struct regulator_dev *rdev) 108 + { 109 + struct twlreg_info *info = rdev_get_drvdata(rdev); 110 + int grp; 111 + 112 + grp = twl4030reg_read(info, VREG_GRP); 113 + if (grp < 0) 114 + return grp; 115 + 116 + grp |= P1_GRP; 117 + return twl4030reg_write(info, VREG_GRP, grp); 118 + } 119 + 120 + static int twl4030reg_disable(struct regulator_dev *rdev) 121 + { 122 + struct twlreg_info *info = rdev_get_drvdata(rdev); 123 + int grp; 124 + 125 + grp = twl4030reg_read(info, VREG_GRP); 126 + if (grp < 0) 127 + return grp; 128 + 129 + grp &= ~P1_GRP; 130 + return twl4030reg_write(info, VREG_GRP, grp); 131 + } 132 + 133 + static int twl4030reg_get_status(struct regulator_dev *rdev) 134 + { 135 + int state = twl4030reg_grp(rdev); 136 + 137 + if (state < 0) 138 + return state; 139 + state &= 0x0f; 140 + 141 + /* assume state != WARM_RESET; we'd not be running... */ 142 + if (!state) 143 + return REGULATOR_STATUS_OFF; 144 + return (state & BIT(3)) 145 + ? REGULATOR_STATUS_NORMAL 146 + : REGULATOR_STATUS_STANDBY; 147 + } 148 + 149 + static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) 150 + { 151 + struct twlreg_info *info = rdev_get_drvdata(rdev); 152 + unsigned message; 153 + int status; 154 + 155 + /* We can only set the mode through state machine commands... */ 156 + switch (mode) { 157 + case REGULATOR_MODE_NORMAL: 158 + message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); 159 + break; 160 + case REGULATOR_MODE_STANDBY: 161 + message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP); 162 + break; 163 + default: 164 + return -EINVAL; 165 + } 166 + 167 + /* Ensure the resource is associated with some group */ 168 + status = twl4030reg_grp(rdev); 169 + if (status < 0) 170 + return status; 171 + if (!(status & (P3_GRP | P2_GRP | P1_GRP))) 172 + return -EACCES; 173 + 174 + status = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 175 + message >> 8, 0x15 /* PB_WORD_MSB */ ); 176 + if (status >= 0) 177 + return status; 178 + 179 + return twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 180 + message, 0x16 /* PB_WORD_LSB */ ); 181 + } 182 + 183 + /*----------------------------------------------------------------------*/ 184 + 185 + /* 186 + * Support for adjustable-voltage LDOs uses a four bit (or less) voltage 187 + * select field in its control register. We use tables indexed by VSEL 188 + * to record voltages in milliVolts. (Accuracy is about three percent.) 189 + * 190 + * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon; 191 + * currently handled by listing two slightly different VAUX2 regulators, 192 + * only one of which will be configured. 193 + * 194 + * VSEL values documented as "TI cannot support these values" are flagged 195 + * in these tables as UNSUP() values; we normally won't assign them. 196 + * 197 + * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. 198 + * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting. 199 + */ 200 + #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED 201 + #define UNSUP_MASK 0x0000 202 + #else 203 + #define UNSUP_MASK 0x8000 204 + #endif 205 + 206 + #define UNSUP(x) (UNSUP_MASK | (x)) 207 + #define IS_UNSUP(x) (UNSUP_MASK & (x)) 208 + #define LDO_MV(x) (~UNSUP_MASK & (x)) 209 + 210 + 211 + static const u16 VAUX1_VSEL_table[] = { 212 + UNSUP(1500), UNSUP(1800), 2500, 2800, 213 + 3000, 3000, 3000, 3000, 214 + }; 215 + static const u16 VAUX2_4030_VSEL_table[] = { 216 + UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300, 217 + 1500, 1800, UNSUP(1850), 2500, 218 + UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), 219 + UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 220 + }; 221 + static const u16 VAUX2_VSEL_table[] = { 222 + 1700, 1700, 1900, 1300, 223 + 1500, 1800, 2000, 2500, 224 + 2100, 2800, 2200, 2300, 225 + 2400, 2400, 2400, 2400, 226 + }; 227 + static const u16 VAUX3_VSEL_table[] = { 228 + 1500, 1800, 2500, 2800, 229 + 3000, 3000, 3000, 3000, 230 + }; 231 + static const u16 VAUX4_VSEL_table[] = { 232 + 700, 1000, 1200, UNSUP(1300), 233 + 1500, 1800, UNSUP(1850), 2500, 234 + UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), 235 + UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 236 + }; 237 + static const u16 VMMC1_VSEL_table[] = { 238 + 1850, 2850, 3000, 3150, 239 + }; 240 + static const u16 VMMC2_VSEL_table[] = { 241 + UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300), 242 + UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500), 243 + 2600, 2800, 2850, 3000, 244 + 3150, 3150, 3150, 3150, 245 + }; 246 + static const u16 VPLL1_VSEL_table[] = { 247 + 1000, 1200, 1300, 1800, 248 + UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000), 249 + }; 250 + static const u16 VPLL2_VSEL_table[] = { 251 + 700, 1000, 1200, 1300, 252 + UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500), 253 + UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000), 254 + UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 255 + }; 256 + static const u16 VSIM_VSEL_table[] = { 257 + UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800, 258 + 2800, 3000, 3000, 3000, 259 + }; 260 + static const u16 VDAC_VSEL_table[] = { 261 + 1200, 1300, 1800, 1800, 262 + }; 263 + 264 + 265 + static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) 266 + { 267 + struct twlreg_info *info = rdev_get_drvdata(rdev); 268 + int mV = info->table[index]; 269 + 270 + return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000); 271 + } 272 + 273 + static int 274 + twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 275 + { 276 + struct twlreg_info *info = rdev_get_drvdata(rdev); 277 + int vsel; 278 + 279 + for (vsel = 0; vsel < info->table_len; vsel++) { 280 + int mV = info->table[vsel]; 281 + int uV; 282 + 283 + if (IS_UNSUP(mV)) 284 + continue; 285 + uV = LDO_MV(mV) * 1000; 286 + 287 + /* REVISIT for VAUX2, first match may not be best/lowest */ 288 + 289 + /* use the first in-range value */ 290 + if (min_uV <= uV && uV <= max_uV) 291 + return twl4030reg_write(info, VREG_DEDICATED, vsel); 292 + } 293 + 294 + return -EDOM; 295 + } 296 + 297 + static int twl4030ldo_get_voltage(struct regulator_dev *rdev) 298 + { 299 + struct twlreg_info *info = rdev_get_drvdata(rdev); 300 + int vsel = twl4030reg_read(info, VREG_DEDICATED); 301 + 302 + if (vsel < 0) 303 + return vsel; 304 + 305 + vsel &= info->table_len - 1; 306 + return LDO_MV(info->table[vsel]) * 1000; 307 + } 308 + 309 + static struct regulator_ops twl4030ldo_ops = { 310 + .list_voltage = twl4030ldo_list_voltage, 311 + 312 + .set_voltage = twl4030ldo_set_voltage, 313 + .get_voltage = twl4030ldo_get_voltage, 314 + 315 + .enable = twl4030reg_enable, 316 + .disable = twl4030reg_disable, 317 + .is_enabled = twl4030reg_is_enabled, 318 + 319 + .set_mode = twl4030reg_set_mode, 320 + 321 + .get_status = twl4030reg_get_status, 322 + }; 323 + 324 + /*----------------------------------------------------------------------*/ 325 + 326 + /* 327 + * Fixed voltage LDOs don't have a VSEL field to update. 328 + */ 329 + static int twl4030fixed_list_voltage(struct regulator_dev *rdev, unsigned index) 330 + { 331 + struct twlreg_info *info = rdev_get_drvdata(rdev); 332 + 333 + return info->min_mV * 1000; 334 + } 335 + 336 + static int twl4030fixed_get_voltage(struct regulator_dev *rdev) 337 + { 338 + struct twlreg_info *info = rdev_get_drvdata(rdev); 339 + 340 + return info->min_mV * 1000; 341 + } 342 + 343 + static struct regulator_ops twl4030fixed_ops = { 344 + .list_voltage = twl4030fixed_list_voltage, 345 + 346 + .get_voltage = twl4030fixed_get_voltage, 347 + 348 + .enable = twl4030reg_enable, 349 + .disable = twl4030reg_disable, 350 + .is_enabled = twl4030reg_is_enabled, 351 + 352 + .set_mode = twl4030reg_set_mode, 353 + 354 + .get_status = twl4030reg_get_status, 355 + }; 356 + 357 + /*----------------------------------------------------------------------*/ 358 + 359 + #define TWL_ADJUSTABLE_LDO(label, offset, num) { \ 360 + .base = offset, \ 361 + .id = num, \ 362 + .table_len = ARRAY_SIZE(label##_VSEL_table), \ 363 + .table = label##_VSEL_table, \ 364 + .desc = { \ 365 + .name = #label, \ 366 + .id = TWL4030_REG_##label, \ 367 + .n_voltages = ARRAY_SIZE(label##_VSEL_table), \ 368 + .ops = &twl4030ldo_ops, \ 369 + .type = REGULATOR_VOLTAGE, \ 370 + .owner = THIS_MODULE, \ 371 + }, \ 372 + } 373 + 374 + #define TWL_FIXED_LDO(label, offset, mVolts, num) { \ 375 + .base = offset, \ 376 + .id = num, \ 377 + .min_mV = mVolts, \ 378 + .desc = { \ 379 + .name = #label, \ 380 + .id = TWL4030_REG_##label, \ 381 + .n_voltages = 1, \ 382 + .ops = &twl4030fixed_ops, \ 383 + .type = REGULATOR_VOLTAGE, \ 384 + .owner = THIS_MODULE, \ 385 + }, \ 386 + } 387 + 388 + /* 389 + * We list regulators here if systems need some level of 390 + * software control over them after boot. 391 + */ 392 + static struct twlreg_info twl4030_regs[] = { 393 + TWL_ADJUSTABLE_LDO(VAUX1, 0x17, 1), 394 + TWL_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2), 395 + TWL_ADJUSTABLE_LDO(VAUX2, 0x1b, 2), 396 + TWL_ADJUSTABLE_LDO(VAUX3, 0x1f, 3), 397 + TWL_ADJUSTABLE_LDO(VAUX4, 0x23, 4), 398 + TWL_ADJUSTABLE_LDO(VMMC1, 0x27, 5), 399 + TWL_ADJUSTABLE_LDO(VMMC2, 0x2b, 6), 400 + /* 401 + TWL_ADJUSTABLE_LDO(VPLL1, 0x2f, 7), 402 + */ 403 + TWL_ADJUSTABLE_LDO(VPLL2, 0x33, 8), 404 + TWL_ADJUSTABLE_LDO(VSIM, 0x37, 9), 405 + TWL_ADJUSTABLE_LDO(VDAC, 0x3b, 10), 406 + /* 407 + TWL_ADJUSTABLE_LDO(VINTANA1, 0x3f, 11), 408 + TWL_ADJUSTABLE_LDO(VINTANA2, 0x43, 12), 409 + TWL_ADJUSTABLE_LDO(VINTDIG, 0x47, 13), 410 + TWL_SMPS(VIO, 0x4b, 14), 411 + TWL_SMPS(VDD1, 0x55, 15), 412 + TWL_SMPS(VDD2, 0x63, 16), 413 + */ 414 + TWL_FIXED_LDO(VUSB1V5, 0x71, 1500, 17), 415 + TWL_FIXED_LDO(VUSB1V8, 0x74, 1800, 18), 416 + TWL_FIXED_LDO(VUSB3V1, 0x77, 3100, 19), 417 + /* VUSBCP is managed *only* by the USB subchip */ 418 + }; 419 + 420 + static int twl4030reg_probe(struct platform_device *pdev) 421 + { 422 + int i; 423 + struct twlreg_info *info; 424 + struct regulator_init_data *initdata; 425 + struct regulation_constraints *c; 426 + struct regulator_dev *rdev; 427 + 428 + for (i = 0, info = NULL; i < ARRAY_SIZE(twl4030_regs); i++) { 429 + if (twl4030_regs[i].desc.id != pdev->id) 430 + continue; 431 + info = twl4030_regs + i; 432 + break; 433 + } 434 + if (!info) 435 + return -ENODEV; 436 + 437 + initdata = pdev->dev.platform_data; 438 + if (!initdata) 439 + return -EINVAL; 440 + 441 + /* Constrain board-specific capabilities according to what 442 + * this driver and the chip itself can actually do. 443 + */ 444 + c = &initdata->constraints; 445 + c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY; 446 + c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE 447 + | REGULATOR_CHANGE_MODE 448 + | REGULATOR_CHANGE_STATUS; 449 + 450 + rdev = regulator_register(&info->desc, &pdev->dev, initdata, info); 451 + if (IS_ERR(rdev)) { 452 + dev_err(&pdev->dev, "can't register %s, %ld\n", 453 + info->desc.name, PTR_ERR(rdev)); 454 + return PTR_ERR(rdev); 455 + } 456 + platform_set_drvdata(pdev, rdev); 457 + 458 + /* NOTE: many regulators support short-circuit IRQs (presentable 459 + * as REGULATOR_OVER_CURRENT notifications?) configured via: 460 + * - SC_CONFIG 461 + * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4) 462 + * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2) 463 + * - IT_CONFIG 464 + */ 465 + 466 + return 0; 467 + } 468 + 469 + static int __devexit twl4030reg_remove(struct platform_device *pdev) 470 + { 471 + regulator_unregister(platform_get_drvdata(pdev)); 472 + return 0; 473 + } 474 + 475 + MODULE_ALIAS("platform:twl4030_reg"); 476 + 477 + static struct platform_driver twl4030reg_driver = { 478 + .probe = twl4030reg_probe, 479 + .remove = __devexit_p(twl4030reg_remove), 480 + /* NOTE: short name, to work around driver model truncation of 481 + * "twl4030_regulator.12" (and friends) to "twl4030_regulator.1". 482 + */ 483 + .driver.name = "twl4030_reg", 484 + .driver.owner = THIS_MODULE, 485 + }; 486 + 487 + static int __init twl4030reg_init(void) 488 + { 489 + return platform_driver_register(&twl4030reg_driver); 490 + } 491 + subsys_initcall(twl4030reg_init); 492 + 493 + static void __exit twl4030reg_exit(void) 494 + { 495 + platform_driver_unregister(&twl4030reg_driver); 496 + } 497 + module_exit(twl4030reg_exit) 498 + 499 + MODULE_DESCRIPTION("TWL4030 regulator driver"); 500 + MODULE_LICENSE("GPL");
+9 -5
drivers/regulator/virtual.c
··· 226 226 unsigned int mode; 227 227 int ret; 228 228 229 - if (strncmp(buf, "fast", strlen("fast")) == 0) 229 + /* 230 + * sysfs_streq() doesn't need the \n's, but we add them so the strings 231 + * will be shared with show_mode(), above. 232 + */ 233 + if (sysfs_streq(buf, "fast\n") == 0) 230 234 mode = REGULATOR_MODE_FAST; 231 - else if (strncmp(buf, "normal", strlen("normal")) == 0) 235 + else if (sysfs_streq(buf, "normal\n") == 0) 232 236 mode = REGULATOR_MODE_NORMAL; 233 - else if (strncmp(buf, "idle", strlen("idle")) == 0) 237 + else if (sysfs_streq(buf, "idle\n") == 0) 234 238 mode = REGULATOR_MODE_IDLE; 235 - else if (strncmp(buf, "standby", strlen("standby")) == 0) 239 + else if (sysfs_streq(buf, "standby\n") == 0) 236 240 mode = REGULATOR_MODE_STANDBY; 237 241 else { 238 242 dev_err(dev, "Configuring invalid mode\n"); ··· 260 256 static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); 261 257 static DEVICE_ATTR(mode, 0666, show_mode, set_mode); 262 258 263 - struct device_attribute *attributes[] = { 259 + static struct device_attribute *attributes[] = { 264 260 &dev_attr_min_microvolts, 265 261 &dev_attr_max_microvolts, 266 262 &dev_attr_min_microamps,
+50 -7
drivers/regulator/wm8350-regulator.c
··· 24 24 #include <linux/regulator/driver.h> 25 25 #include <linux/regulator/machine.h> 26 26 27 + /* Maximum value possible for VSEL */ 28 + #define WM8350_DCDC_MAX_VSEL 0x66 29 + 27 30 /* Microamps */ 28 31 static const int isink_cur[] = { 29 32 4, ··· 386 383 /* all DCDCs have same mV bits */ 387 384 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK; 388 385 return wm8350_dcdc_val_to_mvolts(val) * 1000; 386 + } 387 + 388 + static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev, 389 + unsigned selector) 390 + { 391 + if (selector > WM8350_DCDC_MAX_VSEL) 392 + return -EINVAL; 393 + return wm8350_dcdc_val_to_mvolts(selector) * 1000; 389 394 } 390 395 391 396 static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) ··· 786 775 return wm8350_ldo_val_to_mvolts(val) * 1000; 787 776 } 788 777 778 + static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, 779 + unsigned selector) 780 + { 781 + if (selector > WM8350_LDO1_VSEL_MASK) 782 + return -EINVAL; 783 + return wm8350_ldo_val_to_mvolts(selector) * 1000; 784 + } 785 + 789 786 int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, 790 787 u16 stop, u16 fault) 791 788 { ··· 1050 1031 int dcdc = rdev_get_id(rdev); 1051 1032 u16 mask, sleep, active, force; 1052 1033 int mode = REGULATOR_MODE_NORMAL; 1034 + int reg; 1053 1035 1054 - if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) 1036 + switch (dcdc) { 1037 + case WM8350_DCDC_1: 1038 + reg = WM8350_DCDC1_FORCE_PWM; 1039 + break; 1040 + case WM8350_DCDC_3: 1041 + reg = WM8350_DCDC3_FORCE_PWM; 1042 + break; 1043 + case WM8350_DCDC_4: 1044 + reg = WM8350_DCDC4_FORCE_PWM; 1045 + break; 1046 + case WM8350_DCDC_6: 1047 + reg = WM8350_DCDC6_FORCE_PWM; 1048 + break; 1049 + default: 1055 1050 return -EINVAL; 1056 - 1057 - if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5) 1058 - return -EINVAL; 1051 + } 1059 1052 1060 1053 mask = 1 << (dcdc - WM8350_DCDC_1); 1061 1054 active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask; 1055 + force = wm8350_reg_read(wm8350, reg) & WM8350_DCDC1_FORCE_PWM_ENA; 1062 1056 sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask; 1063 - force = wm8350_reg_read(wm8350, WM8350_DCDC1_FORCE_PWM) 1064 - & WM8350_DCDC1_FORCE_PWM_ENA; 1057 + 1065 1058 dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x", 1066 1059 mask, active, sleep, force); 1067 1060 ··· 1181 1150 static struct regulator_ops wm8350_dcdc_ops = { 1182 1151 .set_voltage = wm8350_dcdc_set_voltage, 1183 1152 .get_voltage = wm8350_dcdc_get_voltage, 1153 + .list_voltage = wm8350_dcdc_list_voltage, 1184 1154 .enable = wm8350_dcdc_enable, 1185 1155 .disable = wm8350_dcdc_disable, 1186 1156 .get_mode = wm8350_dcdc_get_mode, ··· 1205 1173 static struct regulator_ops wm8350_ldo_ops = { 1206 1174 .set_voltage = wm8350_ldo_set_voltage, 1207 1175 .get_voltage = wm8350_ldo_get_voltage, 1176 + .list_voltage = wm8350_ldo_list_voltage, 1208 1177 .enable = wm8350_ldo_enable, 1209 1178 .disable = wm8350_ldo_disable, 1210 1179 .is_enabled = wm8350_ldo_is_enabled, ··· 1230 1197 .ops = &wm8350_dcdc_ops, 1231 1198 .irq = WM8350_IRQ_UV_DC1, 1232 1199 .type = REGULATOR_VOLTAGE, 1200 + .n_voltages = WM8350_DCDC_MAX_VSEL + 1, 1233 1201 .owner = THIS_MODULE, 1234 1202 }, 1235 1203 { ··· 1247 1213 .ops = &wm8350_dcdc_ops, 1248 1214 .irq = WM8350_IRQ_UV_DC3, 1249 1215 .type = REGULATOR_VOLTAGE, 1216 + .n_voltages = WM8350_DCDC_MAX_VSEL + 1, 1250 1217 .owner = THIS_MODULE, 1251 1218 }, 1252 1219 { ··· 1256 1221 .ops = &wm8350_dcdc_ops, 1257 1222 .irq = WM8350_IRQ_UV_DC4, 1258 1223 .type = REGULATOR_VOLTAGE, 1224 + .n_voltages = WM8350_DCDC_MAX_VSEL + 1, 1259 1225 .owner = THIS_MODULE, 1260 1226 }, 1261 1227 { ··· 1273 1237 .ops = &wm8350_dcdc_ops, 1274 1238 .irq = WM8350_IRQ_UV_DC6, 1275 1239 .type = REGULATOR_VOLTAGE, 1240 + .n_voltages = WM8350_DCDC_MAX_VSEL + 1, 1276 1241 .owner = THIS_MODULE, 1277 1242 }, 1278 1243 { ··· 1282 1245 .ops = &wm8350_ldo_ops, 1283 1246 .irq = WM8350_IRQ_UV_LDO1, 1284 1247 .type = REGULATOR_VOLTAGE, 1248 + .n_voltages = WM8350_LDO1_VSEL_MASK + 1, 1285 1249 .owner = THIS_MODULE, 1286 1250 }, 1287 1251 { ··· 1291 1253 .ops = &wm8350_ldo_ops, 1292 1254 .irq = WM8350_IRQ_UV_LDO2, 1293 1255 .type = REGULATOR_VOLTAGE, 1256 + .n_voltages = WM8350_LDO2_VSEL_MASK + 1, 1294 1257 .owner = THIS_MODULE, 1295 1258 }, 1296 1259 { ··· 1300 1261 .ops = &wm8350_ldo_ops, 1301 1262 .irq = WM8350_IRQ_UV_LDO3, 1302 1263 .type = REGULATOR_VOLTAGE, 1264 + .n_voltages = WM8350_LDO3_VSEL_MASK + 1, 1303 1265 .owner = THIS_MODULE, 1304 1266 }, 1305 1267 { ··· 1309 1269 .ops = &wm8350_ldo_ops, 1310 1270 .irq = WM8350_IRQ_UV_LDO4, 1311 1271 .type = REGULATOR_VOLTAGE, 1272 + .n_voltages = WM8350_LDO4_VSEL_MASK + 1, 1312 1273 .owner = THIS_MODULE, 1313 1274 }, 1314 1275 { ··· 1334 1293 { 1335 1294 struct regulator_dev *rdev = (struct regulator_dev *)data; 1336 1295 1296 + mutex_lock(&rdev->mutex); 1337 1297 if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) 1338 1298 regulator_notifier_call_chain(rdev, 1339 1299 REGULATOR_EVENT_REGULATION_OUT, ··· 1343 1301 regulator_notifier_call_chain(rdev, 1344 1302 REGULATOR_EVENT_UNDER_VOLTAGE, 1345 1303 wm8350); 1304 + mutex_unlock(&rdev->mutex); 1346 1305 } 1347 1306 1348 1307 static int wm8350_regulator_probe(struct platform_device *pdev) ··· 1376 1333 break; 1377 1334 } 1378 1335 1379 - 1380 1336 /* register regulator */ 1381 1337 rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev, 1338 + pdev->dev.platform_data, 1382 1339 dev_get_drvdata(&pdev->dev)); 1383 1340 if (IS_ERR(rdev)) { 1384 1341 dev_err(&pdev->dev, "failed to register %s\n",
+31 -5
drivers/regulator/wm8400-regulator.c
··· 43 43 WM8400_LDO1_ENA, 0); 44 44 } 45 45 46 + static int wm8400_ldo_list_voltage(struct regulator_dev *dev, 47 + unsigned selector) 48 + { 49 + if (selector > WM8400_LDO1_VSEL_MASK) 50 + return -EINVAL; 51 + 52 + if (selector < 15) 53 + return 900000 + (selector * 50000); 54 + else 55 + return 1600000 + ((selector - 14) * 100000); 56 + } 57 + 46 58 static int wm8400_ldo_get_voltage(struct regulator_dev *dev) 47 59 { 48 60 struct wm8400 *wm8400 = rdev_get_drvdata(dev); ··· 63 51 val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); 64 52 val &= WM8400_LDO1_VSEL_MASK; 65 53 66 - if (val < 15) 67 - return 900000 + (val * 50000); 68 - else 69 - return 1600000 + ((val - 14) * 100000); 54 + return wm8400_ldo_list_voltage(dev, val); 70 55 } 71 56 72 57 static int wm8400_ldo_set_voltage(struct regulator_dev *dev, ··· 101 92 .is_enabled = wm8400_ldo_is_enabled, 102 93 .enable = wm8400_ldo_enable, 103 94 .disable = wm8400_ldo_disable, 95 + .list_voltage = wm8400_ldo_list_voltage, 104 96 .get_voltage = wm8400_ldo_get_voltage, 105 97 .set_voltage = wm8400_ldo_set_voltage, 106 98 }; ··· 132 122 133 123 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 134 124 WM8400_DC1_ENA, 0); 125 + } 126 + 127 + static int wm8400_dcdc_list_voltage(struct regulator_dev *dev, 128 + unsigned selector) 129 + { 130 + if (selector > WM8400_DC1_VSEL_MASK) 131 + return -EINVAL; 132 + 133 + return 850000 + (selector * 25000); 135 134 } 136 135 137 136 static int wm8400_dcdc_get_voltage(struct regulator_dev *dev) ··· 256 237 .is_enabled = wm8400_dcdc_is_enabled, 257 238 .enable = wm8400_dcdc_enable, 258 239 .disable = wm8400_dcdc_disable, 240 + .list_voltage = wm8400_dcdc_list_voltage, 259 241 .get_voltage = wm8400_dcdc_get_voltage, 260 242 .set_voltage = wm8400_dcdc_set_voltage, 261 243 .get_mode = wm8400_dcdc_get_mode, ··· 269 249 .name = "LDO1", 270 250 .id = WM8400_LDO1, 271 251 .ops = &wm8400_ldo_ops, 252 + .n_voltages = WM8400_LDO1_VSEL_MASK + 1, 272 253 .type = REGULATOR_VOLTAGE, 273 254 .owner = THIS_MODULE, 274 255 }, ··· 277 256 .name = "LDO2", 278 257 .id = WM8400_LDO2, 279 258 .ops = &wm8400_ldo_ops, 259 + .n_voltages = WM8400_LDO2_VSEL_MASK + 1, 280 260 .type = REGULATOR_VOLTAGE, 281 261 .owner = THIS_MODULE, 282 262 }, ··· 285 263 .name = "LDO3", 286 264 .id = WM8400_LDO3, 287 265 .ops = &wm8400_ldo_ops, 266 + .n_voltages = WM8400_LDO3_VSEL_MASK + 1, 288 267 .type = REGULATOR_VOLTAGE, 289 268 .owner = THIS_MODULE, 290 269 }, ··· 293 270 .name = "LDO4", 294 271 .id = WM8400_LDO4, 295 272 .ops = &wm8400_ldo_ops, 273 + .n_voltages = WM8400_LDO4_VSEL_MASK + 1, 296 274 .type = REGULATOR_VOLTAGE, 297 275 .owner = THIS_MODULE, 298 276 }, ··· 301 277 .name = "DCDC1", 302 278 .id = WM8400_DCDC1, 303 279 .ops = &wm8400_dcdc_ops, 280 + .n_voltages = WM8400_DC1_VSEL_MASK + 1, 304 281 .type = REGULATOR_VOLTAGE, 305 282 .owner = THIS_MODULE, 306 283 }, ··· 309 284 .name = "DCDC2", 310 285 .id = WM8400_DCDC2, 311 286 .ops = &wm8400_dcdc_ops, 287 + .n_voltages = WM8400_DC2_VSEL_MASK + 1, 312 288 .type = REGULATOR_VOLTAGE, 313 289 .owner = THIS_MODULE, 314 290 }, ··· 320 294 struct regulator_dev *rdev; 321 295 322 296 rdev = regulator_register(&regulators[pdev->id], &pdev->dev, 323 - pdev->dev.driver_data); 297 + pdev->dev.platform_data, pdev->dev.driver_data); 324 298 325 299 if (IS_ERR(rdev)) 326 300 return PTR_ERR(rdev);
+47
include/linux/i2c/twl4030.h
··· 218 218 219 219 /*----------------------------------------------------------------------*/ 220 220 221 + /* Power bus message definitions */ 222 + 223 + #define DEV_GRP_NULL 0x0 224 + #define DEV_GRP_P1 0x1 225 + #define DEV_GRP_P2 0x2 226 + #define DEV_GRP_P3 0x4 227 + 228 + #define RES_GRP_RES 0x0 229 + #define RES_GRP_PP 0x1 230 + #define RES_GRP_RC 0x2 231 + #define RES_GRP_PP_RC 0x3 232 + #define RES_GRP_PR 0x4 233 + #define RES_GRP_PP_PR 0x5 234 + #define RES_GRP_RC_PR 0x6 235 + #define RES_GRP_ALL 0x7 236 + 237 + #define RES_TYPE2_R0 0x0 238 + 239 + #define RES_TYPE_ALL 0x7 240 + 241 + #define RES_STATE_WRST 0xF 242 + #define RES_STATE_ACTIVE 0xE 243 + #define RES_STATE_SLEEP 0x8 244 + #define RES_STATE_OFF 0x0 245 + 246 + /* 247 + * Power Bus Message Format ... these can be sent individually by Linux, 248 + * but are usually part of downloaded scripts that are run when various 249 + * power events are triggered. 250 + * 251 + * Broadcast Message (16 Bits): 252 + * DEV_GRP[15:13] MT[12] RES_GRP[11:9] RES_TYPE2[8:7] RES_TYPE[6:4] 253 + * RES_STATE[3:0] 254 + * 255 + * Singular Message (16 Bits): 256 + * DEV_GRP[15:13] MT[12] RES_ID[11:4] RES_STATE[3:0] 257 + */ 258 + 259 + #define MSG_BROADCAST(devgrp, grp, type, type2, state) \ 260 + ( (devgrp) << 13 | 1 << 12 | (grp) << 9 | (type2) << 7 \ 261 + | (type) << 4 | (state)) 262 + 263 + #define MSG_SINGULAR(devgrp, id, state) \ 264 + ((devgrp) << 13 | 0 << 12 | (id) << 4 | (state)) 265 + 266 + /*----------------------------------------------------------------------*/ 267 + 221 268 struct twl4030_bci_platform_data { 222 269 int *battery_tmp_tbl; 223 270 unsigned int tblsize;
+5
include/linux/mmc/host.h
··· 192 192 wake_up_process(host->sdio_irq_thread); 193 193 } 194 194 195 + struct regulator; 196 + 197 + int mmc_regulator_get_ocrmask(struct regulator *supply); 198 + int mmc_regulator_set_ocr(struct regulator *supply, unsigned short vdd_bit); 199 + 195 200 #endif 196 201
+3
include/linux/regulator/bq24022.h
··· 10 10 * 11 11 */ 12 12 13 + struct regulator_init_data; 14 + 13 15 /** 14 16 * bq24022_mach_info - platform data for bq24022 15 17 * @gpio_nce: GPIO line connected to the nCE pin, used to enable / disable charging ··· 20 18 struct bq24022_mach_info { 21 19 int gpio_nce; 22 20 int gpio_iset2; 21 + struct regulator_init_data *init_data; 23 22 };
+5 -1
include/linux/regulator/consumer.h
··· 3 3 * 4 4 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. 5 5 * 6 - * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> 6 + * Author: Liam Girdwood <lrg@slimlogic.co.uk> 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify 9 9 * it under the terms of the GNU General Public License version 2 as ··· 88 88 * FAIL Regulator output has failed. 89 89 * OVER_TEMP Regulator over temp. 90 90 * FORCE_DISABLE Regulator shut down by software. 91 + * VOLTAGE_CHANGE Regulator voltage changed. 91 92 * 92 93 * NOTE: These events can be OR'ed together when passed into handler. 93 94 */ ··· 99 98 #define REGULATOR_EVENT_FAIL 0x08 100 99 #define REGULATOR_EVENT_OVER_TEMP 0x10 101 100 #define REGULATOR_EVENT_FORCE_DISABLE 0x20 101 + #define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40 102 102 103 103 struct regulator; 104 104 ··· 142 140 void regulator_bulk_free(int num_consumers, 143 141 struct regulator_bulk_data *consumers); 144 142 143 + int regulator_count_voltages(struct regulator *regulator); 144 + int regulator_list_voltage(struct regulator *regulator, unsigned selector); 145 145 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); 146 146 int regulator_get_voltage(struct regulator *regulator); 147 147 int regulator_set_current_limit(struct regulator *regulator,
+71 -10
include/linux/regulator/driver.h
··· 3 3 * 4 4 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. 5 5 * 6 - * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> 6 + * Author: Liam Girdwood <lrg@slimlogic.co.uk> 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify 9 9 * it under the terms of the GNU General Public License version 2 as ··· 21 21 struct regulator_dev; 22 22 struct regulator_init_data; 23 23 24 + enum regulator_status { 25 + REGULATOR_STATUS_OFF, 26 + REGULATOR_STATUS_ON, 27 + REGULATOR_STATUS_ERROR, 28 + /* fast/normal/idle/standby are flavors of "on" */ 29 + REGULATOR_STATUS_FAST, 30 + REGULATOR_STATUS_NORMAL, 31 + REGULATOR_STATUS_IDLE, 32 + REGULATOR_STATUS_STANDBY, 33 + }; 34 + 24 35 /** 25 36 * struct regulator_ops - regulator operations. 26 37 * 27 - * This struct describes regulator operations which can be implemented by 28 - * regulator chip drivers. 29 - * 30 - * @enable: Enable the regulator. 31 - * @disable: Disable the regulator. 38 + * @enable: Configure the regulator as enabled. 39 + * @disable: Configure the regulator as disabled. 32 40 * @is_enabled: Return 1 if the regulator is enabled, 0 otherwise. 33 41 * 34 42 * @set_voltage: Set the voltage for the regulator within the range specified. 35 43 * The driver should select the voltage closest to min_uV. 36 44 * @get_voltage: Return the currently configured voltage for the regulator. 45 + * @list_voltage: Return one of the supported voltages, in microvolts; zero 46 + * if the selector indicates a voltage that is unusable on this system; 47 + * or negative errno. Selectors range from zero to one less than 48 + * regulator_desc.n_voltages. Voltages may be reported in any order. 37 49 * 38 50 * @set_current_limit: Configure a limit for a current-limited regulator. 39 - * @get_current_limit: Get the limit for a current-limited regulator. 51 + * @get_current_limit: Get the configured limit for a current-limited regulator. 40 52 * 41 - * @set_mode: Set the operating mode for the regulator. 42 - * @get_mode: Get the current operating mode for the regulator. 53 + * @get_mode: Get the configured operating mode for the regulator. 54 + * @get_status: Return actual (not as-configured) status of regulator, as a 55 + * REGULATOR_STATUS value (or negative errno) 43 56 * @get_optimum_mode: Get the most efficient operating mode for the regulator 44 57 * when running with the specified parameters. 45 58 * ··· 64 51 * suspended. 65 52 * @set_suspend_mode: Set the operating mode for the regulator when the 66 53 * system is suspended. 54 + * 55 + * This struct describes regulator operations which can be implemented by 56 + * regulator chip drivers. 67 57 */ 68 58 struct regulator_ops { 59 + 60 + /* enumerate supported voltages */ 61 + int (*list_voltage) (struct regulator_dev *, unsigned selector); 69 62 70 63 /* get/set regulator voltage */ 71 64 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV); ··· 90 71 /* get/set regulator operating mode (defined in regulator.h) */ 91 72 int (*set_mode) (struct regulator_dev *, unsigned int mode); 92 73 unsigned int (*get_mode) (struct regulator_dev *); 74 + 75 + /* report regulator status ... most other accessors report 76 + * control inputs, this reports results of combining inputs 77 + * from Linux (and other sources) with the actual load. 78 + * returns REGULATOR_STATUS_* or negative errno. 79 + */ 80 + int (*get_status)(struct regulator_dev *); 93 81 94 82 /* get most efficient regulator operating mode for load */ 95 83 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, ··· 132 106 * 133 107 * @name: Identifying name for the regulator. 134 108 * @id: Numerical identifier for the regulator. 109 + * @n_voltages: Number of selectors available for ops.list_voltage(). 135 110 * @ops: Regulator operations table. 136 111 * @irq: Interrupt number for the regulator. 137 112 * @type: Indicates if the regulator is a voltage or current regulator. ··· 141 114 struct regulator_desc { 142 115 const char *name; 143 116 int id; 117 + unsigned n_voltages; 144 118 struct regulator_ops *ops; 145 119 int irq; 146 120 enum regulator_type type; 147 121 struct module *owner; 148 122 }; 149 123 124 + /* 125 + * struct regulator_dev 126 + * 127 + * Voltage / Current regulator class device. One for each 128 + * regulator. 129 + * 130 + * This should *not* be used directly by anything except the regulator 131 + * core and notification injection (which should take the mutex and do 132 + * no other direct access). 133 + */ 134 + struct regulator_dev { 135 + struct regulator_desc *desc; 136 + int use_count; 137 + 138 + /* lists we belong to */ 139 + struct list_head list; /* list of all regulators */ 140 + struct list_head slist; /* list of supplied regulators */ 141 + 142 + /* lists we own */ 143 + struct list_head consumer_list; /* consumers we supply */ 144 + struct list_head supply_list; /* regulators we supply */ 145 + 146 + struct blocking_notifier_head notifier; 147 + struct mutex mutex; /* consumer lock */ 148 + struct module *owner; 149 + struct device dev; 150 + struct regulation_constraints *constraints; 151 + struct regulator_dev *supply; /* for tree */ 152 + 153 + void *reg_data; /* regulator_dev data */ 154 + }; 155 + 150 156 struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 151 - struct device *dev, void *driver_data); 157 + struct device *dev, struct regulator_init_data *init_data, 158 + void *driver_data); 152 159 void regulator_unregister(struct regulator_dev *rdev); 153 160 154 161 int regulator_notifier_call_chain(struct regulator_dev *rdev,
+3
include/linux/regulator/fixed.h
··· 14 14 #ifndef __REGULATOR_FIXED_H 15 15 #define __REGULATOR_FIXED_H 16 16 17 + struct regulator_init_data; 18 + 17 19 struct fixed_voltage_config { 18 20 const char *supply_name; 19 21 int microvolts; 22 + struct regulator_init_data *init_data; 20 23 }; 21 24 22 25 #endif
+10 -2
include/linux/regulator/machine.h
··· 3 3 * 4 4 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. 5 5 * 6 - * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> 6 + * Author: Liam Girdwood <lrg@slimlogic.co.uk> 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify 9 9 * it under the terms of the GNU General Public License version 2 as ··· 73 73 * 74 74 * @always_on: Set if the regulator should never be disabled. 75 75 * @boot_on: Set if the regulator is enabled when the system is initially 76 - * started. 76 + * started. If the regulator is not enabled by the hardware or 77 + * bootloader then it will be enabled when the constraints are 78 + * applied. 77 79 * @apply_uV: Apply the voltage constraint when initialising. 78 80 * 79 81 * @input_uV: Input voltage for regulator when supplied by another regulator. ··· 85 83 * @state_standby: State for regulator when system is suspended in standby 86 84 * mode. 87 85 * @initial_state: Suspend state to set by default. 86 + * @initial_mode: Mode to set at startup. 88 87 */ 89 88 struct regulation_constraints { 90 89 ··· 113 110 struct regulator_state state_mem; 114 111 struct regulator_state state_standby; 115 112 suspend_state_t initial_state; /* suspend state to set at init */ 113 + 114 + /* mode to set on startup */ 115 + unsigned int initial_mode; 116 116 117 117 /* constriant flags */ 118 118 unsigned always_on:1; /* regulator never off when system is on */ ··· 165 159 }; 166 160 167 161 int regulator_suspend_prepare(suspend_state_t state); 162 + 163 + void regulator_has_full_constraints(void); 168 164 169 165 #endif