core.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607
  1. /*
  2. * core.c -- Voltage/Current Regulator framework.
  3. *
  4. * Copyright 2007, 2008 Wolfson Microelectronics PLC.
  5. * Copyright 2008 SlimLogic Ltd.
  6. *
  7. * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/device.h>
  18. #include <linux/slab.h>
  19. #include <linux/err.h>
  20. #include <linux/mutex.h>
  21. #include <linux/suspend.h>
  22. #include <linux/delay.h>
  23. #include <linux/regulator/consumer.h>
  24. #include <linux/regulator/driver.h>
  25. #include <linux/regulator/machine.h>
  26. #include "dummy.h"
  27. #define REGULATOR_VERSION "0.5"
  28. static DEFINE_MUTEX(regulator_list_mutex);
  29. static LIST_HEAD(regulator_list);
  30. static LIST_HEAD(regulator_map_list);
  31. static int has_full_constraints;
  32. /*
  33. * struct regulator_map
  34. *
  35. * Used to provide symbolic supply names to devices.
  36. */
  37. struct regulator_map {
  38. struct list_head list;
  39. const char *dev_name; /* The dev_name() for the consumer */
  40. const char *supply;
  41. struct regulator_dev *regulator;
  42. };
  43. /*
  44. * struct regulator
  45. *
  46. * One for each consumer device.
  47. */
  48. struct regulator {
  49. struct device *dev;
  50. struct list_head list;
  51. int uA_load;
  52. int min_uV;
  53. int max_uV;
  54. char *supply_name;
  55. struct device_attribute dev_attr;
  56. struct regulator_dev *rdev;
  57. };
  58. static int _regulator_is_enabled(struct regulator_dev *rdev);
  59. static int _regulator_disable(struct regulator_dev *rdev);
  60. static int _regulator_get_voltage(struct regulator_dev *rdev);
  61. static int _regulator_get_current_limit(struct regulator_dev *rdev);
  62. static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
  63. static void _notifier_call_chain(struct regulator_dev *rdev,
  64. unsigned long event, void *data);
  65. static const char *rdev_get_name(struct regulator_dev *rdev)
  66. {
  67. if (rdev->constraints && rdev->constraints->name)
  68. return rdev->constraints->name;
  69. else if (rdev->desc->name)
  70. return rdev->desc->name;
  71. else
  72. return "";
  73. }
  74. /* gets the regulator for a given consumer device */
  75. static struct regulator *get_device_regulator(struct device *dev)
  76. {
  77. struct regulator *regulator = NULL;
  78. struct regulator_dev *rdev;
  79. mutex_lock(&regulator_list_mutex);
  80. list_for_each_entry(rdev, &regulator_list, list) {
  81. mutex_lock(&rdev->mutex);
  82. list_for_each_entry(regulator, &rdev->consumer_list, list) {
  83. if (regulator->dev == dev) {
  84. mutex_unlock(&rdev->mutex);
  85. mutex_unlock(&regulator_list_mutex);
  86. return regulator;
  87. }
  88. }
  89. mutex_unlock(&rdev->mutex);
  90. }
  91. mutex_unlock(&regulator_list_mutex);
  92. return NULL;
  93. }
  94. /* Platform voltage constraint check */
  95. static int regulator_check_voltage(struct regulator_dev *rdev,
  96. int *min_uV, int *max_uV)
  97. {
  98. BUG_ON(*min_uV > *max_uV);
  99. if (!rdev->constraints) {
  100. printk(KERN_ERR "%s: no constraints for %s\n", __func__,
  101. rdev_get_name(rdev));
  102. return -ENODEV;
  103. }
  104. if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
  105. printk(KERN_ERR "%s: operation not allowed for %s\n",
  106. __func__, rdev_get_name(rdev));
  107. return -EPERM;
  108. }
  109. if (*max_uV > rdev->constraints->max_uV)
  110. *max_uV = rdev->constraints->max_uV;
  111. if (*min_uV < rdev->constraints->min_uV)
  112. *min_uV = rdev->constraints->min_uV;
  113. if (*min_uV > *max_uV)
  114. return -EINVAL;
  115. return 0;
  116. }
  117. /* current constraint check */
  118. static int regulator_check_current_limit(struct regulator_dev *rdev,
  119. int *min_uA, int *max_uA)
  120. {
  121. BUG_ON(*min_uA > *max_uA);
  122. if (!rdev->constraints) {
  123. printk(KERN_ERR "%s: no constraints for %s\n", __func__,
  124. rdev_get_name(rdev));
  125. return -ENODEV;
  126. }
  127. if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
  128. printk(KERN_ERR "%s: operation not allowed for %s\n",
  129. __func__, rdev_get_name(rdev));
  130. return -EPERM;
  131. }
  132. if (*max_uA > rdev->constraints->max_uA)
  133. *max_uA = rdev->constraints->max_uA;
  134. if (*min_uA < rdev->constraints->min_uA)
  135. *min_uA = rdev->constraints->min_uA;
  136. if (*min_uA > *max_uA)
  137. return -EINVAL;
  138. return 0;
  139. }
  140. /* operating mode constraint check */
  141. static int regulator_check_mode(struct regulator_dev *rdev, int mode)
  142. {
  143. switch (mode) {
  144. case REGULATOR_MODE_FAST:
  145. case REGULATOR_MODE_NORMAL:
  146. case REGULATOR_MODE_IDLE:
  147. case REGULATOR_MODE_STANDBY:
  148. break;
  149. default:
  150. return -EINVAL;
  151. }
  152. if (!rdev->constraints) {
  153. printk(KERN_ERR "%s: no constraints for %s\n", __func__,
  154. rdev_get_name(rdev));
  155. return -ENODEV;
  156. }
  157. if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
  158. printk(KERN_ERR "%s: operation not allowed for %s\n",
  159. __func__, rdev_get_name(rdev));
  160. return -EPERM;
  161. }
  162. if (!(rdev->constraints->valid_modes_mask & mode)) {
  163. printk(KERN_ERR "%s: invalid mode %x for %s\n",
  164. __func__, mode, rdev_get_name(rdev));
  165. return -EINVAL;
  166. }
  167. return 0;
  168. }
  169. /* dynamic regulator mode switching constraint check */
  170. static int regulator_check_drms(struct regulator_dev *rdev)
  171. {
  172. if (!rdev->constraints) {
  173. printk(KERN_ERR "%s: no constraints for %s\n", __func__,
  174. rdev_get_name(rdev));
  175. return -ENODEV;
  176. }
  177. if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
  178. printk(KERN_ERR "%s: operation not allowed for %s\n",
  179. __func__, rdev_get_name(rdev));
  180. return -EPERM;
  181. }
  182. return 0;
  183. }
  184. static ssize_t device_requested_uA_show(struct device *dev,
  185. struct device_attribute *attr, char *buf)
  186. {
  187. struct regulator *regulator;
  188. regulator = get_device_regulator(dev);
  189. if (regulator == NULL)
  190. return 0;
  191. return sprintf(buf, "%d\n", regulator->uA_load);
  192. }
  193. static ssize_t regulator_uV_show(struct device *dev,
  194. struct device_attribute *attr, char *buf)
  195. {
  196. struct regulator_dev *rdev = dev_get_drvdata(dev);
  197. ssize_t ret;
  198. mutex_lock(&rdev->mutex);
  199. ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev));
  200. mutex_unlock(&rdev->mutex);
  201. return ret;
  202. }
  203. static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
  204. static ssize_t regulator_uA_show(struct device *dev,
  205. struct device_attribute *attr, char *buf)
  206. {
  207. struct regulator_dev *rdev = dev_get_drvdata(dev);
  208. return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
  209. }
  210. static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL);
  211. static ssize_t regulator_name_show(struct device *dev,
  212. struct device_attribute *attr, char *buf)
  213. {
  214. struct regulator_dev *rdev = dev_get_drvdata(dev);
  215. return sprintf(buf, "%s\n", rdev_get_name(rdev));
  216. }
  217. static ssize_t regulator_print_opmode(char *buf, int mode)
  218. {
  219. switch (mode) {
  220. case REGULATOR_MODE_FAST:
  221. return sprintf(buf, "fast\n");
  222. case REGULATOR_MODE_NORMAL:
  223. return sprintf(buf, "normal\n");
  224. case REGULATOR_MODE_IDLE:
  225. return sprintf(buf, "idle\n");
  226. case REGULATOR_MODE_STANDBY:
  227. return sprintf(buf, "standby\n");
  228. }
  229. return sprintf(buf, "unknown\n");
  230. }
  231. static ssize_t regulator_opmode_show(struct device *dev,
  232. struct device_attribute *attr, char *buf)
  233. {
  234. struct regulator_dev *rdev = dev_get_drvdata(dev);
  235. return regulator_print_opmode(buf, _regulator_get_mode(rdev));
  236. }
  237. static DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL);
  238. static ssize_t regulator_print_state(char *buf, int state)
  239. {
  240. if (state > 0)
  241. return sprintf(buf, "enabled\n");
  242. else if (state == 0)
  243. return sprintf(buf, "disabled\n");
  244. else
  245. return sprintf(buf, "unknown\n");
  246. }
  247. static ssize_t regulator_state_show(struct device *dev,
  248. struct device_attribute *attr, char *buf)
  249. {
  250. struct regulator_dev *rdev = dev_get_drvdata(dev);
  251. ssize_t ret;
  252. mutex_lock(&rdev->mutex);
  253. ret = regulator_print_state(buf, _regulator_is_enabled(rdev));
  254. mutex_unlock(&rdev->mutex);
  255. return ret;
  256. }
  257. static DEVICE_ATTR(state, 0444, regulator_state_show, NULL);
  258. static ssize_t regulator_status_show(struct device *dev,
  259. struct device_attribute *attr, char *buf)
  260. {
  261. struct regulator_dev *rdev = dev_get_drvdata(dev);
  262. int status;
  263. char *label;
  264. status = rdev->desc->ops->get_status(rdev);
  265. if (status < 0)
  266. return status;
  267. switch (status) {
  268. case REGULATOR_STATUS_OFF:
  269. label = "off";
  270. break;
  271. case REGULATOR_STATUS_ON:
  272. label = "on";
  273. break;
  274. case REGULATOR_STATUS_ERROR:
  275. label = "error";
  276. break;
  277. case REGULATOR_STATUS_FAST:
  278. label = "fast";
  279. break;
  280. case REGULATOR_STATUS_NORMAL:
  281. label = "normal";
  282. break;
  283. case REGULATOR_STATUS_IDLE:
  284. label = "idle";
  285. break;
  286. case REGULATOR_STATUS_STANDBY:
  287. label = "standby";
  288. break;
  289. default:
  290. return -ERANGE;
  291. }
  292. return sprintf(buf, "%s\n", label);
  293. }
  294. static DEVICE_ATTR(status, 0444, regulator_status_show, NULL);
  295. static ssize_t regulator_min_uA_show(struct device *dev,
  296. struct device_attribute *attr, char *buf)
  297. {
  298. struct regulator_dev *rdev = dev_get_drvdata(dev);
  299. if (!rdev->constraints)
  300. return sprintf(buf, "constraint not defined\n");
  301. return sprintf(buf, "%d\n", rdev->constraints->min_uA);
  302. }
  303. static DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL);
  304. static ssize_t regulator_max_uA_show(struct device *dev,
  305. struct device_attribute *attr, char *buf)
  306. {
  307. struct regulator_dev *rdev = dev_get_drvdata(dev);
  308. if (!rdev->constraints)
  309. return sprintf(buf, "constraint not defined\n");
  310. return sprintf(buf, "%d\n", rdev->constraints->max_uA);
  311. }
  312. static DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL);
  313. static ssize_t regulator_min_uV_show(struct device *dev,
  314. struct device_attribute *attr, char *buf)
  315. {
  316. struct regulator_dev *rdev = dev_get_drvdata(dev);
  317. if (!rdev->constraints)
  318. return sprintf(buf, "constraint not defined\n");
  319. return sprintf(buf, "%d\n", rdev->constraints->min_uV);
  320. }
  321. static DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL);
  322. static ssize_t regulator_max_uV_show(struct device *dev,
  323. struct device_attribute *attr, char *buf)
  324. {
  325. struct regulator_dev *rdev = dev_get_drvdata(dev);
  326. if (!rdev->constraints)
  327. return sprintf(buf, "constraint not defined\n");
  328. return sprintf(buf, "%d\n", rdev->constraints->max_uV);
  329. }
  330. static DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL);
  331. static ssize_t regulator_total_uA_show(struct device *dev,
  332. struct device_attribute *attr, char *buf)
  333. {
  334. struct regulator_dev *rdev = dev_get_drvdata(dev);
  335. struct regulator *regulator;
  336. int uA = 0;
  337. mutex_lock(&rdev->mutex);
  338. list_for_each_entry(regulator, &rdev->consumer_list, list)
  339. uA += regulator->uA_load;
  340. mutex_unlock(&rdev->mutex);
  341. return sprintf(buf, "%d\n", uA);
  342. }
  343. static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL);
  344. static ssize_t regulator_num_users_show(struct device *dev,
  345. struct device_attribute *attr, char *buf)
  346. {
  347. struct regulator_dev *rdev = dev_get_drvdata(dev);
  348. return sprintf(buf, "%d\n", rdev->use_count);
  349. }
  350. static ssize_t regulator_type_show(struct device *dev,
  351. struct device_attribute *attr, char *buf)
  352. {
  353. struct regulator_dev *rdev = dev_get_drvdata(dev);
  354. switch (rdev->desc->type) {
  355. case REGULATOR_VOLTAGE:
  356. return sprintf(buf, "voltage\n");
  357. case REGULATOR_CURRENT:
  358. return sprintf(buf, "current\n");
  359. }
  360. return sprintf(buf, "unknown\n");
  361. }
  362. static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
  363. struct device_attribute *attr, char *buf)
  364. {
  365. struct regulator_dev *rdev = dev_get_drvdata(dev);
  366. return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV);
  367. }
  368. static DEVICE_ATTR(suspend_mem_microvolts, 0444,
  369. regulator_suspend_mem_uV_show, NULL);
  370. static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
  371. struct device_attribute *attr, char *buf)
  372. {
  373. struct regulator_dev *rdev = dev_get_drvdata(dev);
  374. return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV);
  375. }
  376. static DEVICE_ATTR(suspend_disk_microvolts, 0444,
  377. regulator_suspend_disk_uV_show, NULL);
  378. static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
  379. struct device_attribute *attr, char *buf)
  380. {
  381. struct regulator_dev *rdev = dev_get_drvdata(dev);
  382. return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV);
  383. }
  384. static DEVICE_ATTR(suspend_standby_microvolts, 0444,
  385. regulator_suspend_standby_uV_show, NULL);
  386. static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
  387. struct device_attribute *attr, char *buf)
  388. {
  389. struct regulator_dev *rdev = dev_get_drvdata(dev);
  390. return regulator_print_opmode(buf,
  391. rdev->constraints->state_mem.mode);
  392. }
  393. static DEVICE_ATTR(suspend_mem_mode, 0444,
  394. regulator_suspend_mem_mode_show, NULL);
  395. static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
  396. struct device_attribute *attr, char *buf)
  397. {
  398. struct regulator_dev *rdev = dev_get_drvdata(dev);
  399. return regulator_print_opmode(buf,
  400. rdev->constraints->state_disk.mode);
  401. }
  402. static DEVICE_ATTR(suspend_disk_mode, 0444,
  403. regulator_suspend_disk_mode_show, NULL);
  404. static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
  405. struct device_attribute *attr, char *buf)
  406. {
  407. struct regulator_dev *rdev = dev_get_drvdata(dev);
  408. return regulator_print_opmode(buf,
  409. rdev->constraints->state_standby.mode);
  410. }
  411. static DEVICE_ATTR(suspend_standby_mode, 0444,
  412. regulator_suspend_standby_mode_show, NULL);
  413. static ssize_t regulator_suspend_mem_state_show(struct device *dev,
  414. struct device_attribute *attr, char *buf)
  415. {
  416. struct regulator_dev *rdev = dev_get_drvdata(dev);
  417. return regulator_print_state(buf,
  418. rdev->constraints->state_mem.enabled);
  419. }
  420. static DEVICE_ATTR(suspend_mem_state, 0444,
  421. regulator_suspend_mem_state_show, NULL);
  422. static ssize_t regulator_suspend_disk_state_show(struct device *dev,
  423. struct device_attribute *attr, char *buf)
  424. {
  425. struct regulator_dev *rdev = dev_get_drvdata(dev);
  426. return regulator_print_state(buf,
  427. rdev->constraints->state_disk.enabled);
  428. }
  429. static DEVICE_ATTR(suspend_disk_state, 0444,
  430. regulator_suspend_disk_state_show, NULL);
  431. static ssize_t regulator_suspend_standby_state_show(struct device *dev,
  432. struct device_attribute *attr, char *buf)
  433. {
  434. struct regulator_dev *rdev = dev_get_drvdata(dev);
  435. return regulator_print_state(buf,
  436. rdev->constraints->state_standby.enabled);
  437. }
  438. static DEVICE_ATTR(suspend_standby_state, 0444,
  439. regulator_suspend_standby_state_show, NULL);
  440. /*
  441. * These are the only attributes are present for all regulators.
  442. * Other attributes are a function of regulator functionality.
  443. */
  444. static struct device_attribute regulator_dev_attrs[] = {
  445. __ATTR(name, 0444, regulator_name_show, NULL),
  446. __ATTR(num_users, 0444, regulator_num_users_show, NULL),
  447. __ATTR(type, 0444, regulator_type_show, NULL),
  448. __ATTR_NULL,
  449. };
  450. static void regulator_dev_release(struct device *dev)
  451. {
  452. struct regulator_dev *rdev = dev_get_drvdata(dev);
  453. kfree(rdev);
  454. }
  455. static struct class regulator_class = {
  456. .name = "regulator",
  457. .dev_release = regulator_dev_release,
  458. .dev_attrs = regulator_dev_attrs,
  459. };
  460. /* Calculate the new optimum regulator operating mode based on the new total
  461. * consumer load. All locks held by caller */
  462. static void drms_uA_update(struct regulator_dev *rdev)
  463. {
  464. struct regulator *sibling;
  465. int current_uA = 0, output_uV, input_uV, err;
  466. unsigned int mode;
  467. err = regulator_check_drms(rdev);
  468. if (err < 0 || !rdev->desc->ops->get_optimum_mode ||
  469. !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode)
  470. return;
  471. /* get output voltage */
  472. output_uV = rdev->desc->ops->get_voltage(rdev);
  473. if (output_uV <= 0)
  474. return;
  475. /* get input voltage */
  476. if (rdev->supply && rdev->supply->desc->ops->get_voltage)
  477. input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply);
  478. else
  479. input_uV = rdev->constraints->input_uV;
  480. if (input_uV <= 0)
  481. return;
  482. /* calc total requested load */
  483. list_for_each_entry(sibling, &rdev->consumer_list, list)
  484. current_uA += sibling->uA_load;
  485. /* now get the optimum mode for our new total regulator load */
  486. mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV,
  487. output_uV, current_uA);
  488. /* check the new mode is allowed */
  489. err = regulator_check_mode(rdev, mode);
  490. if (err == 0)
  491. rdev->desc->ops->set_mode(rdev, mode);
  492. }
  493. static int suspend_set_state(struct regulator_dev *rdev,
  494. struct regulator_state *rstate)
  495. {
  496. int ret = 0;
  497. bool can_set_state;
  498. can_set_state = rdev->desc->ops->set_suspend_enable &&
  499. rdev->desc->ops->set_suspend_disable;
  500. /* If we have no suspend mode configration don't set anything;
  501. * only warn if the driver actually makes the suspend mode
  502. * configurable.
  503. */
  504. if (!rstate->enabled && !rstate->disabled) {
  505. if (can_set_state)
  506. printk(KERN_WARNING "%s: No configuration for %s\n",
  507. __func__, rdev_get_name(rdev));
  508. return 0;
  509. }
  510. if (rstate->enabled && rstate->disabled) {
  511. printk(KERN_ERR "%s: invalid configuration for %s\n",
  512. __func__, rdev_get_name(rdev));
  513. return -EINVAL;
  514. }
  515. if (!can_set_state) {
  516. printk(KERN_ERR "%s: no way to set suspend state\n",
  517. __func__);
  518. return -EINVAL;
  519. }
  520. if (rstate->enabled)
  521. ret = rdev->desc->ops->set_suspend_enable(rdev);
  522. else
  523. ret = rdev->desc->ops->set_suspend_disable(rdev);
  524. if (ret < 0) {
  525. printk(KERN_ERR "%s: failed to enabled/disable\n", __func__);
  526. return ret;
  527. }
  528. if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) {
  529. ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV);
  530. if (ret < 0) {
  531. printk(KERN_ERR "%s: failed to set voltage\n",
  532. __func__);
  533. return ret;
  534. }
  535. }
  536. if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) {
  537. ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode);
  538. if (ret < 0) {
  539. printk(KERN_ERR "%s: failed to set mode\n", __func__);
  540. return ret;
  541. }
  542. }
  543. return ret;
  544. }
  545. /* locks held by caller */
  546. static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state)
  547. {
  548. if (!rdev->constraints)
  549. return -EINVAL;
  550. switch (state) {
  551. case PM_SUSPEND_STANDBY:
  552. return suspend_set_state(rdev,
  553. &rdev->constraints->state_standby);
  554. case PM_SUSPEND_MEM:
  555. return suspend_set_state(rdev,
  556. &rdev->constraints->state_mem);
  557. case PM_SUSPEND_MAX:
  558. return suspend_set_state(rdev,
  559. &rdev->constraints->state_disk);
  560. default:
  561. return -EINVAL;
  562. }
  563. }
  564. static void print_constraints(struct regulator_dev *rdev)
  565. {
  566. struct regulation_constraints *constraints = rdev->constraints;
  567. char buf[80] = "";
  568. int count = 0;
  569. int ret;
  570. if (constraints->min_uV && constraints->max_uV) {
  571. if (constraints->min_uV == constraints->max_uV)
  572. count += sprintf(buf + count, "%d mV ",
  573. constraints->min_uV / 1000);
  574. else
  575. count += sprintf(buf + count, "%d <--> %d mV ",
  576. constraints->min_uV / 1000,
  577. constraints->max_uV / 1000);
  578. }
  579. if (!constraints->min_uV ||
  580. constraints->min_uV != constraints->max_uV) {
  581. ret = _regulator_get_voltage(rdev);
  582. if (ret > 0)
  583. count += sprintf(buf + count, "at %d mV ", ret / 1000);
  584. }
  585. if (constraints->min_uA && constraints->max_uA) {
  586. if (constraints->min_uA == constraints->max_uA)
  587. count += sprintf(buf + count, "%d mA ",
  588. constraints->min_uA / 1000);
  589. else
  590. count += sprintf(buf + count, "%d <--> %d mA ",
  591. constraints->min_uA / 1000,
  592. constraints->max_uA / 1000);
  593. }
  594. if (!constraints->min_uA ||
  595. constraints->min_uA != constraints->max_uA) {
  596. ret = _regulator_get_current_limit(rdev);
  597. if (ret > 0)
  598. count += sprintf(buf + count, "at %d mA ", ret / 1000);
  599. }
  600. if (constraints->valid_modes_mask & REGULATOR_MODE_FAST)
  601. count += sprintf(buf + count, "fast ");
  602. if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL)
  603. count += sprintf(buf + count, "normal ");
  604. if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE)
  605. count += sprintf(buf + count, "idle ");
  606. if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
  607. count += sprintf(buf + count, "standby");
  608. printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf);
  609. }
  610. static int machine_constraints_voltage(struct regulator_dev *rdev,
  611. struct regulation_constraints *constraints)
  612. {
  613. struct regulator_ops *ops = rdev->desc->ops;
  614. const char *name = rdev_get_name(rdev);
  615. int ret;
  616. /* do we need to apply the constraint voltage */
  617. if (rdev->constraints->apply_uV &&
  618. rdev->constraints->min_uV == rdev->constraints->max_uV &&
  619. ops->set_voltage) {
  620. ret = ops->set_voltage(rdev,
  621. rdev->constraints->min_uV, rdev->constraints->max_uV);
  622. if (ret < 0) {
  623. printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
  624. __func__,
  625. rdev->constraints->min_uV, name);
  626. rdev->constraints = NULL;
  627. return ret;
  628. }
  629. }
  630. /* constrain machine-level voltage specs to fit
  631. * the actual range supported by this regulator.
  632. */
  633. if (ops->list_voltage && rdev->desc->n_voltages) {
  634. int count = rdev->desc->n_voltages;
  635. int i;
  636. int min_uV = INT_MAX;
  637. int max_uV = INT_MIN;
  638. int cmin = constraints->min_uV;
  639. int cmax = constraints->max_uV;
  640. /* it's safe to autoconfigure fixed-voltage supplies
  641. and the constraints are used by list_voltage. */
  642. if (count == 1 && !cmin) {
  643. cmin = 1;
  644. cmax = INT_MAX;
  645. constraints->min_uV = cmin;
  646. constraints->max_uV = cmax;
  647. }
  648. /* voltage constraints are optional */
  649. if ((cmin == 0) && (cmax == 0))
  650. return 0;
  651. /* else require explicit machine-level constraints */
  652. if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
  653. pr_err("%s: %s '%s' voltage constraints\n",
  654. __func__, "invalid", name);
  655. return -EINVAL;
  656. }
  657. /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */
  658. for (i = 0; i < count; i++) {
  659. int value;
  660. value = ops->list_voltage(rdev, i);
  661. if (value <= 0)
  662. continue;
  663. /* maybe adjust [min_uV..max_uV] */
  664. if (value >= cmin && value < min_uV)
  665. min_uV = value;
  666. if (value <= cmax && value > max_uV)
  667. max_uV = value;
  668. }
  669. /* final: [min_uV..max_uV] valid iff constraints valid */
  670. if (max_uV < min_uV) {
  671. pr_err("%s: %s '%s' voltage constraints\n",
  672. __func__, "unsupportable", name);
  673. return -EINVAL;
  674. }
  675. /* use regulator's subset of machine constraints */
  676. if (constraints->min_uV < min_uV) {
  677. pr_debug("%s: override '%s' %s, %d -> %d\n",
  678. __func__, name, "min_uV",
  679. constraints->min_uV, min_uV);
  680. constraints->min_uV = min_uV;
  681. }
  682. if (constraints->max_uV > max_uV) {
  683. pr_debug("%s: override '%s' %s, %d -> %d\n",
  684. __func__, name, "max_uV",
  685. constraints->max_uV, max_uV);
  686. constraints->max_uV = max_uV;
  687. }
  688. }
  689. return 0;
  690. }
  691. /**
  692. * set_machine_constraints - sets regulator constraints
  693. * @rdev: regulator source
  694. * @constraints: constraints to apply
  695. *
  696. * Allows platform initialisation code to define and constrain
  697. * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
  698. * Constraints *must* be set by platform code in order for some
  699. * regulator operations to proceed i.e. set_voltage, set_current_limit,
  700. * set_mode.
  701. */
  702. static int set_machine_constraints(struct regulator_dev *rdev,
  703. struct regulation_constraints *constraints)
  704. {
  705. int ret = 0;
  706. const char *name;
  707. struct regulator_ops *ops = rdev->desc->ops;
  708. rdev->constraints = constraints;
  709. name = rdev_get_name(rdev);
  710. ret = machine_constraints_voltage(rdev, constraints);
  711. if (ret != 0)
  712. goto out;
  713. /* do we need to setup our suspend state */
  714. if (constraints->initial_state) {
  715. ret = suspend_prepare(rdev, constraints->initial_state);
  716. if (ret < 0) {
  717. printk(KERN_ERR "%s: failed to set suspend state for %s\n",
  718. __func__, name);
  719. rdev->constraints = NULL;
  720. goto out;
  721. }
  722. }
  723. if (constraints->initial_mode) {
  724. if (!ops->set_mode) {
  725. printk(KERN_ERR "%s: no set_mode operation for %s\n",
  726. __func__, name);
  727. ret = -EINVAL;
  728. goto out;
  729. }
  730. ret = ops->set_mode(rdev, constraints->initial_mode);
  731. if (ret < 0) {
  732. printk(KERN_ERR
  733. "%s: failed to set initial mode for %s: %d\n",
  734. __func__, name, ret);
  735. goto out;
  736. }
  737. }
  738. /* If the constraints say the regulator should be on at this point
  739. * and we have control then make sure it is enabled.
  740. */
  741. if ((constraints->always_on || constraints->boot_on) && ops->enable) {
  742. ret = ops->enable(rdev);
  743. if (ret < 0) {
  744. printk(KERN_ERR "%s: failed to enable %s\n",
  745. __func__, name);
  746. rdev->constraints = NULL;
  747. goto out;
  748. }
  749. }
  750. print_constraints(rdev);
  751. out:
  752. return ret;
  753. }
  754. /**
  755. * set_supply - set regulator supply regulator
  756. * @rdev: regulator name
  757. * @supply_rdev: supply regulator name
  758. *
  759. * Called by platform initialisation code to set the supply regulator for this
  760. * regulator. This ensures that a regulators supply will also be enabled by the
  761. * core if it's child is enabled.
  762. */
  763. static int set_supply(struct regulator_dev *rdev,
  764. struct regulator_dev *supply_rdev)
  765. {
  766. int err;
  767. err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
  768. "supply");
  769. if (err) {
  770. printk(KERN_ERR
  771. "%s: could not add device link %s err %d\n",
  772. __func__, supply_rdev->dev.kobj.name, err);
  773. goto out;
  774. }
  775. rdev->supply = supply_rdev;
  776. list_add(&rdev->slist, &supply_rdev->supply_list);
  777. out:
  778. return err;
  779. }
  780. /**
  781. * set_consumer_device_supply: Bind a regulator to a symbolic supply
  782. * @rdev: regulator source
  783. * @consumer_dev: device the supply applies to
  784. * @consumer_dev_name: dev_name() string for device supply applies to
  785. * @supply: symbolic name for supply
  786. *
  787. * Allows platform initialisation code to map physical regulator
  788. * sources to symbolic names for supplies for use by devices. Devices
  789. * should use these symbolic names to request regulators, avoiding the
  790. * need to provide board-specific regulator names as platform data.
  791. *
  792. * Only one of consumer_dev and consumer_dev_name may be specified.
  793. */
  794. static int set_consumer_device_supply(struct regulator_dev *rdev,
  795. struct device *consumer_dev, const char *consumer_dev_name,
  796. const char *supply)
  797. {
  798. struct regulator_map *node;
  799. int has_dev;
  800. if (consumer_dev && consumer_dev_name)
  801. return -EINVAL;
  802. if (!consumer_dev_name && consumer_dev)
  803. consumer_dev_name = dev_name(consumer_dev);
  804. if (supply == NULL)
  805. return -EINVAL;
  806. if (consumer_dev_name != NULL)
  807. has_dev = 1;
  808. else
  809. has_dev = 0;
  810. list_for_each_entry(node, &regulator_map_list, list) {
  811. if (node->dev_name && consumer_dev_name) {
  812. if (strcmp(node->dev_name, consumer_dev_name) != 0)
  813. continue;
  814. } else if (node->dev_name || consumer_dev_name) {
  815. continue;
  816. }
  817. if (strcmp(node->supply, supply) != 0)
  818. continue;
  819. dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n",
  820. dev_name(&node->regulator->dev),
  821. node->regulator->desc->name,
  822. supply,
  823. dev_name(&rdev->dev), rdev_get_name(rdev));
  824. return -EBUSY;
  825. }
  826. node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL);
  827. if (node == NULL)
  828. return -ENOMEM;
  829. node->regulator = rdev;
  830. node->supply = supply;
  831. if (has_dev) {
  832. node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
  833. if (node->dev_name == NULL) {
  834. kfree(node);
  835. return -ENOMEM;
  836. }
  837. }
  838. list_add(&node->list, &regulator_map_list);
  839. return 0;
  840. }
  841. static void unset_regulator_supplies(struct regulator_dev *rdev)
  842. {
  843. struct regulator_map *node, *n;
  844. list_for_each_entry_safe(node, n, &regulator_map_list, list) {
  845. if (rdev == node->regulator) {
  846. list_del(&node->list);
  847. kfree(node->dev_name);
  848. kfree(node);
  849. }
  850. }
  851. }
  852. #define REG_STR_SIZE 32
  853. static struct regulator *create_regulator(struct regulator_dev *rdev,
  854. struct device *dev,
  855. const char *supply_name)
  856. {
  857. struct regulator *regulator;
  858. char buf[REG_STR_SIZE];
  859. int err, size;
  860. regulator = kzalloc(sizeof(*regulator), GFP_KERNEL);
  861. if (regulator == NULL)
  862. return NULL;
  863. mutex_lock(&rdev->mutex);
  864. regulator->rdev = rdev;
  865. list_add(&regulator->list, &rdev->consumer_list);
  866. if (dev) {
  867. /* create a 'requested_microamps_name' sysfs entry */
  868. size = scnprintf(buf, REG_STR_SIZE, "microamps_requested_%s",
  869. supply_name);
  870. if (size >= REG_STR_SIZE)
  871. goto overflow_err;
  872. regulator->dev = dev;
  873. sysfs_attr_init(&regulator->dev_attr.attr);
  874. regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL);
  875. if (regulator->dev_attr.attr.name == NULL)
  876. goto attr_name_err;
  877. regulator->dev_attr.attr.mode = 0444;
  878. regulator->dev_attr.show = device_requested_uA_show;
  879. err = device_create_file(dev, &regulator->dev_attr);
  880. if (err < 0) {
  881. printk(KERN_WARNING "%s: could not add regulator_dev"
  882. " load sysfs\n", __func__);
  883. goto attr_name_err;
  884. }
  885. /* also add a link to the device sysfs entry */
  886. size = scnprintf(buf, REG_STR_SIZE, "%s-%s",
  887. dev->kobj.name, supply_name);
  888. if (size >= REG_STR_SIZE)
  889. goto attr_err;
  890. regulator->supply_name = kstrdup(buf, GFP_KERNEL);
  891. if (regulator->supply_name == NULL)
  892. goto attr_err;
  893. err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj,
  894. buf);
  895. if (err) {
  896. printk(KERN_WARNING
  897. "%s: could not add device link %s err %d\n",
  898. __func__, dev->kobj.name, err);
  899. device_remove_file(dev, &regulator->dev_attr);
  900. goto link_name_err;
  901. }
  902. }
  903. mutex_unlock(&rdev->mutex);
  904. return regulator;
  905. link_name_err:
  906. kfree(regulator->supply_name);
  907. attr_err:
  908. device_remove_file(regulator->dev, &regulator->dev_attr);
  909. attr_name_err:
  910. kfree(regulator->dev_attr.attr.name);
  911. overflow_err:
  912. list_del(&regulator->list);
  913. kfree(regulator);
  914. mutex_unlock(&rdev->mutex);
  915. return NULL;
  916. }
  917. static int _regulator_get_enable_time(struct regulator_dev *rdev)
  918. {
  919. if (!rdev->desc->ops->enable_time)
  920. return 0;
  921. return rdev->desc->ops->enable_time(rdev);
  922. }
  923. /* Internal regulator request function */
  924. static struct regulator *_regulator_get(struct device *dev, const char *id,
  925. int exclusive)
  926. {
  927. struct regulator_dev *rdev;
  928. struct regulator_map *map;
  929. struct regulator *regulator = ERR_PTR(-ENODEV);
  930. const char *devname = NULL;
  931. int ret;
  932. if (id == NULL) {
  933. printk(KERN_ERR "regulator: get() with no identifier\n");
  934. return regulator;
  935. }
  936. if (dev)
  937. devname = dev_name(dev);
  938. mutex_lock(&regulator_list_mutex);
  939. list_for_each_entry(map, &regulator_map_list, list) {
  940. /* If the mapping has a device set up it must match */
  941. if (map->dev_name &&
  942. (!devname || strcmp(map->dev_name, devname)))
  943. continue;
  944. if (strcmp(map->supply, id) == 0) {
  945. rdev = map->regulator;
  946. goto found;
  947. }
  948. }
  949. #ifdef CONFIG_REGULATOR_DUMMY
  950. if (!devname)
  951. devname = "deviceless";
  952. /* If the board didn't flag that it was fully constrained then
  953. * substitute in a dummy regulator so consumers can continue.
  954. */
  955. if (!has_full_constraints) {
  956. pr_warning("%s supply %s not found, using dummy regulator\n",
  957. devname, id);
  958. rdev = dummy_regulator_rdev;
  959. goto found;
  960. }
  961. #endif
  962. mutex_unlock(&regulator_list_mutex);
  963. return regulator;
  964. found:
  965. if (rdev->exclusive) {
  966. regulator = ERR_PTR(-EPERM);
  967. goto out;
  968. }
  969. if (exclusive && rdev->open_count) {
  970. regulator = ERR_PTR(-EBUSY);
  971. goto out;
  972. }
  973. if (!try_module_get(rdev->owner))
  974. goto out;
  975. regulator = create_regulator(rdev, dev, id);
  976. if (regulator == NULL) {
  977. regulator = ERR_PTR(-ENOMEM);
  978. module_put(rdev->owner);
  979. }
  980. rdev->open_count++;
  981. if (exclusive) {
  982. rdev->exclusive = 1;
  983. ret = _regulator_is_enabled(rdev);
  984. if (ret > 0)
  985. rdev->use_count = 1;
  986. else
  987. rdev->use_count = 0;
  988. }
  989. out:
  990. mutex_unlock(&regulator_list_mutex);
  991. return regulator;
  992. }
  993. /**
  994. * regulator_get - lookup and obtain a reference to a regulator.
  995. * @dev: device for regulator "consumer"
  996. * @id: Supply name or regulator ID.
  997. *
  998. * Returns a struct regulator corresponding to the regulator producer,
  999. * or IS_ERR() condition containing errno.
  1000. *
  1001. * Use of supply names configured via regulator_set_device_supply() is
  1002. * strongly encouraged. It is recommended that the supply name used
  1003. * should match the name used for the supply and/or the relevant
  1004. * device pins in the datasheet.
  1005. */
  1006. struct regulator *regulator_get(struct device *dev, const char *id)
  1007. {
  1008. return _regulator_get(dev, id, 0);
  1009. }
  1010. EXPORT_SYMBOL_GPL(regulator_get);
  1011. /**
  1012. * regulator_get_exclusive - obtain exclusive access to a regulator.
  1013. * @dev: device for regulator "consumer"
  1014. * @id: Supply name or regulator ID.
  1015. *
  1016. * Returns a struct regulator corresponding to the regulator producer,
  1017. * or IS_ERR() condition containing errno. Other consumers will be
  1018. * unable to obtain this reference is held and the use count for the
  1019. * regulator will be initialised to reflect the current state of the
  1020. * regulator.
  1021. *
  1022. * This is intended for use by consumers which cannot tolerate shared
  1023. * use of the regulator such as those which need to force the
  1024. * regulator off for correct operation of the hardware they are
  1025. * controlling.
  1026. *
  1027. * Use of supply names configured via regulator_set_device_supply() is
  1028. * strongly encouraged. It is recommended that the supply name used
  1029. * should match the name used for the supply and/or the relevant
  1030. * device pins in the datasheet.
  1031. */
  1032. struct regulator *regulator_get_exclusive(struct device *dev, const char *id)
  1033. {
  1034. return _regulator_get(dev, id, 1);
  1035. }
  1036. EXPORT_SYMBOL_GPL(regulator_get_exclusive);
  1037. /**
  1038. * regulator_put - "free" the regulator source
  1039. * @regulator: regulator source
  1040. *
  1041. * Note: drivers must ensure that all regulator_enable calls made on this
  1042. * regulator source are balanced by regulator_disable calls prior to calling
  1043. * this function.
  1044. */
  1045. void regulator_put(struct regulator *regulator)
  1046. {
  1047. struct regulator_dev *rdev;
  1048. if (regulator == NULL || IS_ERR(regulator))
  1049. return;
  1050. mutex_lock(&regulator_list_mutex);
  1051. rdev = regulator->rdev;
  1052. /* remove any sysfs entries */
  1053. if (regulator->dev) {
  1054. sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name);
  1055. kfree(regulator->supply_name);
  1056. device_remove_file(regulator->dev, &regulator->dev_attr);
  1057. kfree(regulator->dev_attr.attr.name);
  1058. }
  1059. list_del(&regulator->list);
  1060. kfree(regulator);
  1061. rdev->open_count--;
  1062. rdev->exclusive = 0;
  1063. module_put(rdev->owner);
  1064. mutex_unlock(&regulator_list_mutex);
  1065. }
  1066. EXPORT_SYMBOL_GPL(regulator_put);
  1067. static int _regulator_can_change_status(struct regulator_dev *rdev)
  1068. {
  1069. if (!rdev->constraints)
  1070. return 0;
  1071. if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS)
  1072. return 1;
  1073. else
  1074. return 0;
  1075. }
  1076. /* locks held by regulator_enable() */
  1077. static int _regulator_enable(struct regulator_dev *rdev)
  1078. {
  1079. int ret, delay;
  1080. /* do we need to enable the supply regulator first */
  1081. if (rdev->supply) {
  1082. ret = _regulator_enable(rdev->supply);
  1083. if (ret < 0) {
  1084. printk(KERN_ERR "%s: failed to enable %s: %d\n",
  1085. __func__, rdev_get_name(rdev), ret);
  1086. return ret;
  1087. }
  1088. }
  1089. /* check voltage and requested load before enabling */
  1090. if (rdev->constraints &&
  1091. (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
  1092. drms_uA_update(rdev);
  1093. if (rdev->use_count == 0) {
  1094. /* The regulator may on if it's not switchable or left on */
  1095. ret = _regulator_is_enabled(rdev);
  1096. if (ret == -EINVAL || ret == 0) {
  1097. if (!_regulator_can_change_status(rdev))
  1098. return -EPERM;
  1099. if (!rdev->desc->ops->enable)
  1100. return -EINVAL;
  1101. /* Query before enabling in case configuration
  1102. * dependant. */
  1103. ret = _regulator_get_enable_time(rdev);
  1104. if (ret >= 0) {
  1105. delay = ret;
  1106. } else {
  1107. printk(KERN_WARNING
  1108. "%s: enable_time() failed for %s: %d\n",
  1109. __func__, rdev_get_name(rdev),
  1110. ret);
  1111. delay = 0;
  1112. }
  1113. /* Allow the regulator to ramp; it would be useful
  1114. * to extend this for bulk operations so that the
  1115. * regulators can ramp together. */
  1116. ret = rdev->desc->ops->enable(rdev);
  1117. if (ret < 0)
  1118. return ret;
  1119. if (delay >= 1000)
  1120. mdelay(delay / 1000);
  1121. else if (delay)
  1122. udelay(delay);
  1123. } else if (ret < 0) {
  1124. printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n",
  1125. __func__, rdev_get_name(rdev), ret);
  1126. return ret;
  1127. }
  1128. /* Fallthrough on positive return values - already enabled */
  1129. }
  1130. rdev->use_count++;
  1131. return 0;
  1132. }
  1133. /**
  1134. * regulator_enable - enable regulator output
  1135. * @regulator: regulator source
  1136. *
  1137. * Request that the regulator be enabled with the regulator output at
  1138. * the predefined voltage or current value. Calls to regulator_enable()
  1139. * must be balanced with calls to regulator_disable().
  1140. *
  1141. * NOTE: the output value can be set by other drivers, boot loader or may be
  1142. * hardwired in the regulator.
  1143. */
  1144. int regulator_enable(struct regulator *regulator)
  1145. {
  1146. struct regulator_dev *rdev = regulator->rdev;
  1147. int ret = 0;
  1148. mutex_lock(&rdev->mutex);
  1149. ret = _regulator_enable(rdev);
  1150. mutex_unlock(&rdev->mutex);
  1151. return ret;
  1152. }
  1153. EXPORT_SYMBOL_GPL(regulator_enable);
  1154. /* locks held by regulator_disable() */
  1155. static int _regulator_disable(struct regulator_dev *rdev)
  1156. {
  1157. int ret = 0;
  1158. if (WARN(rdev->use_count <= 0,
  1159. "unbalanced disables for %s\n",
  1160. rdev_get_name(rdev)))
  1161. return -EIO;
  1162. /* are we the last user and permitted to disable ? */
  1163. if (rdev->use_count == 1 &&
  1164. (rdev->constraints && !rdev->constraints->always_on)) {
  1165. /* we are last user */
  1166. if (_regulator_can_change_status(rdev) &&
  1167. rdev->desc->ops->disable) {
  1168. ret = rdev->desc->ops->disable(rdev);
  1169. if (ret < 0) {
  1170. printk(KERN_ERR "%s: failed to disable %s\n",
  1171. __func__, rdev_get_name(rdev));
  1172. return ret;
  1173. }
  1174. _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
  1175. NULL);
  1176. }
  1177. /* decrease our supplies ref count and disable if required */
  1178. if (rdev->supply)
  1179. _regulator_disable(rdev->supply);
  1180. rdev->use_count = 0;
  1181. } else if (rdev->use_count > 1) {
  1182. if (rdev->constraints &&
  1183. (rdev->constraints->valid_ops_mask &
  1184. REGULATOR_CHANGE_DRMS))
  1185. drms_uA_update(rdev);
  1186. rdev->use_count--;
  1187. }
  1188. return ret;
  1189. }
  1190. /**
  1191. * regulator_disable - disable regulator output
  1192. * @regulator: regulator source
  1193. *
  1194. * Disable the regulator output voltage or current. Calls to
  1195. * regulator_enable() must be balanced with calls to
  1196. * regulator_disable().
  1197. *
  1198. * NOTE: this will only disable the regulator output if no other consumer
  1199. * devices have it enabled, the regulator device supports disabling and
  1200. * machine constraints permit this operation.
  1201. */
  1202. int regulator_disable(struct regulator *regulator)
  1203. {
  1204. struct regulator_dev *rdev = regulator->rdev;
  1205. int ret = 0;
  1206. mutex_lock(&rdev->mutex);
  1207. ret = _regulator_disable(rdev);
  1208. mutex_unlock(&rdev->mutex);
  1209. return ret;
  1210. }
  1211. EXPORT_SYMBOL_GPL(regulator_disable);
  1212. /* locks held by regulator_force_disable() */
  1213. static int _regulator_force_disable(struct regulator_dev *rdev)
  1214. {
  1215. int ret = 0;
  1216. /* force disable */
  1217. if (rdev->desc->ops->disable) {
  1218. /* ah well, who wants to live forever... */
  1219. ret = rdev->desc->ops->disable(rdev);
  1220. if (ret < 0) {
  1221. printk(KERN_ERR "%s: failed to force disable %s\n",
  1222. __func__, rdev_get_name(rdev));
  1223. return ret;
  1224. }
  1225. /* notify other consumers that power has been forced off */
  1226. _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
  1227. REGULATOR_EVENT_DISABLE, NULL);
  1228. }
  1229. /* decrease our supplies ref count and disable if required */
  1230. if (rdev->supply)
  1231. _regulator_disable(rdev->supply);
  1232. rdev->use_count = 0;
  1233. return ret;
  1234. }
  1235. /**
  1236. * regulator_force_disable - force disable regulator output
  1237. * @regulator: regulator source
  1238. *
  1239. * Forcibly disable the regulator output voltage or current.
  1240. * NOTE: this *will* disable the regulator output even if other consumer
  1241. * devices have it enabled. This should be used for situations when device
  1242. * damage will likely occur if the regulator is not disabled (e.g. over temp).
  1243. */
  1244. int regulator_force_disable(struct regulator *regulator)
  1245. {
  1246. int ret;
  1247. mutex_lock(&regulator->rdev->mutex);
  1248. regulator->uA_load = 0;
  1249. ret = _regulator_force_disable(regulator->rdev);
  1250. mutex_unlock(&regulator->rdev->mutex);
  1251. return ret;
  1252. }
  1253. EXPORT_SYMBOL_GPL(regulator_force_disable);
  1254. static int _regulator_is_enabled(struct regulator_dev *rdev)
  1255. {
  1256. /* If we don't know then assume that the regulator is always on */
  1257. if (!rdev->desc->ops->is_enabled)
  1258. return 1;
  1259. return rdev->desc->ops->is_enabled(rdev);
  1260. }
  1261. /**
  1262. * regulator_is_enabled - is the regulator output enabled
  1263. * @regulator: regulator source
  1264. *
  1265. * Returns positive if the regulator driver backing the source/client
  1266. * has requested that the device be enabled, zero if it hasn't, else a
  1267. * negative errno code.
  1268. *
  1269. * Note that the device backing this regulator handle can have multiple
  1270. * users, so it might be enabled even if regulator_enable() was never
  1271. * called for this particular source.
  1272. */
  1273. int regulator_is_enabled(struct regulator *regulator)
  1274. {
  1275. int ret;
  1276. mutex_lock(&regulator->rdev->mutex);
  1277. ret = _regulator_is_enabled(regulator->rdev);
  1278. mutex_unlock(&regulator->rdev->mutex);
  1279. return ret;
  1280. }
  1281. EXPORT_SYMBOL_GPL(regulator_is_enabled);
  1282. /**
  1283. * regulator_count_voltages - count regulator_list_voltage() selectors
  1284. * @regulator: regulator source
  1285. *
  1286. * Returns number of selectors, or negative errno. Selectors are
  1287. * numbered starting at zero, and typically correspond to bitfields
  1288. * in hardware registers.
  1289. */
  1290. int regulator_count_voltages(struct regulator *regulator)
  1291. {
  1292. struct regulator_dev *rdev = regulator->rdev;
  1293. return rdev->desc->n_voltages ? : -EINVAL;
  1294. }
  1295. EXPORT_SYMBOL_GPL(regulator_count_voltages);
  1296. /**
  1297. * regulator_list_voltage - enumerate supported voltages
  1298. * @regulator: regulator source
  1299. * @selector: identify voltage to list
  1300. * Context: can sleep
  1301. *
  1302. * Returns a voltage that can be passed to @regulator_set_voltage(),
  1303. * zero if this selector code can't be used on this system, or a
  1304. * negative errno.
  1305. */
  1306. int regulator_list_voltage(struct regulator *regulator, unsigned selector)
  1307. {
  1308. struct regulator_dev *rdev = regulator->rdev;
  1309. struct regulator_ops *ops = rdev->desc->ops;
  1310. int ret;
  1311. if (!ops->list_voltage || selector >= rdev->desc->n_voltages)
  1312. return -EINVAL;
  1313. mutex_lock(&rdev->mutex);
  1314. ret = ops->list_voltage(rdev, selector);
  1315. mutex_unlock(&rdev->mutex);
  1316. if (ret > 0) {
  1317. if (ret < rdev->constraints->min_uV)
  1318. ret = 0;
  1319. else if (ret > rdev->constraints->max_uV)
  1320. ret = 0;
  1321. }
  1322. return ret;
  1323. }
  1324. EXPORT_SYMBOL_GPL(regulator_list_voltage);
  1325. /**
  1326. * regulator_is_supported_voltage - check if a voltage range can be supported
  1327. *
  1328. * @regulator: Regulator to check.
  1329. * @min_uV: Minimum required voltage in uV.
  1330. * @max_uV: Maximum required voltage in uV.
  1331. *
  1332. * Returns a boolean or a negative error code.
  1333. */
  1334. int regulator_is_supported_voltage(struct regulator *regulator,
  1335. int min_uV, int max_uV)
  1336. {
  1337. int i, voltages, ret;
  1338. ret = regulator_count_voltages(regulator);
  1339. if (ret < 0)
  1340. return ret;
  1341. voltages = ret;
  1342. for (i = 0; i < voltages; i++) {
  1343. ret = regulator_list_voltage(regulator, i);
  1344. if (ret >= min_uV && ret <= max_uV)
  1345. return 1;
  1346. }
  1347. return 0;
  1348. }
  1349. /**
  1350. * regulator_set_voltage - set regulator output voltage
  1351. * @regulator: regulator source
  1352. * @min_uV: Minimum required voltage in uV
  1353. * @max_uV: Maximum acceptable voltage in uV
  1354. *
  1355. * Sets a voltage regulator to the desired output voltage. This can be set
  1356. * during any regulator state. IOW, regulator can be disabled or enabled.
  1357. *
  1358. * If the regulator is enabled then the voltage will change to the new value
  1359. * immediately otherwise if the regulator is disabled the regulator will
  1360. * output at the new voltage when enabled.
  1361. *
  1362. * NOTE: If the regulator is shared between several devices then the lowest
  1363. * request voltage that meets the system constraints will be used.
  1364. * Regulator system constraints must be set for this regulator before
  1365. * calling this function otherwise this call will fail.
  1366. */
  1367. int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
  1368. {
  1369. struct regulator_dev *rdev = regulator->rdev;
  1370. int ret;
  1371. mutex_lock(&rdev->mutex);
  1372. /* sanity check */
  1373. if (!rdev->desc->ops->set_voltage) {
  1374. ret = -EINVAL;
  1375. goto out;
  1376. }
  1377. /* constraints check */
  1378. ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
  1379. if (ret < 0)
  1380. goto out;
  1381. regulator->min_uV = min_uV;
  1382. regulator->max_uV = max_uV;
  1383. ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV);
  1384. out:
  1385. _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL);
  1386. mutex_unlock(&rdev->mutex);
  1387. return ret;
  1388. }
  1389. EXPORT_SYMBOL_GPL(regulator_set_voltage);
  1390. static int _regulator_get_voltage(struct regulator_dev *rdev)
  1391. {
  1392. /* sanity check */
  1393. if (rdev->desc->ops->get_voltage)
  1394. return rdev->desc->ops->get_voltage(rdev);
  1395. else
  1396. return -EINVAL;
  1397. }
  1398. /**
  1399. * regulator_get_voltage - get regulator output voltage
  1400. * @regulator: regulator source
  1401. *
  1402. * This returns the current regulator voltage in uV.
  1403. *
  1404. * NOTE: If the regulator is disabled it will return the voltage value. This
  1405. * function should not be used to determine regulator state.
  1406. */
  1407. int regulator_get_voltage(struct regulator *regulator)
  1408. {
  1409. int ret;
  1410. mutex_lock(&regulator->rdev->mutex);
  1411. ret = _regulator_get_voltage(regulator->rdev);
  1412. mutex_unlock(&regulator->rdev->mutex);
  1413. return ret;
  1414. }
  1415. EXPORT_SYMBOL_GPL(regulator_get_voltage);
  1416. /**
  1417. * regulator_set_current_limit - set regulator output current limit
  1418. * @regulator: regulator source
  1419. * @min_uA: Minimuum supported current in uA
  1420. * @max_uA: Maximum supported current in uA
  1421. *
  1422. * Sets current sink to the desired output current. This can be set during
  1423. * any regulator state. IOW, regulator can be disabled or enabled.
  1424. *
  1425. * If the regulator is enabled then the current will change to the new value
  1426. * immediately otherwise if the regulator is disabled the regulator will
  1427. * output at the new current when enabled.
  1428. *
  1429. * NOTE: Regulator system constraints must be set for this regulator before
  1430. * calling this function otherwise this call will fail.
  1431. */
  1432. int regulator_set_current_limit(struct regulator *regulator,
  1433. int min_uA, int max_uA)
  1434. {
  1435. struct regulator_dev *rdev = regulator->rdev;
  1436. int ret;
  1437. mutex_lock(&rdev->mutex);
  1438. /* sanity check */
  1439. if (!rdev->desc->ops->set_current_limit) {
  1440. ret = -EINVAL;
  1441. goto out;
  1442. }
  1443. /* constraints check */
  1444. ret = regulator_check_current_limit(rdev, &min_uA, &max_uA);
  1445. if (ret < 0)
  1446. goto out;
  1447. ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA);
  1448. out:
  1449. mutex_unlock(&rdev->mutex);
  1450. return ret;
  1451. }
  1452. EXPORT_SYMBOL_GPL(regulator_set_current_limit);
  1453. static int _regulator_get_current_limit(struct regulator_dev *rdev)
  1454. {
  1455. int ret;
  1456. mutex_lock(&rdev->mutex);
  1457. /* sanity check */
  1458. if (!rdev->desc->ops->get_current_limit) {
  1459. ret = -EINVAL;
  1460. goto out;
  1461. }
  1462. ret = rdev->desc->ops->get_current_limit(rdev);
  1463. out:
  1464. mutex_unlock(&rdev->mutex);
  1465. return ret;
  1466. }
  1467. /**
  1468. * regulator_get_current_limit - get regulator output current
  1469. * @regulator: regulator source
  1470. *
  1471. * This returns the current supplied by the specified current sink in uA.
  1472. *
  1473. * NOTE: If the regulator is disabled it will return the current value. This
  1474. * function should not be used to determine regulator state.
  1475. */
  1476. int regulator_get_current_limit(struct regulator *regulator)
  1477. {
  1478. return _regulator_get_current_limit(regulator->rdev);
  1479. }
  1480. EXPORT_SYMBOL_GPL(regulator_get_current_limit);
  1481. /**
  1482. * regulator_set_mode - set regulator operating mode
  1483. * @regulator: regulator source
  1484. * @mode: operating mode - one of the REGULATOR_MODE constants
  1485. *
  1486. * Set regulator operating mode to increase regulator efficiency or improve
  1487. * regulation performance.
  1488. *
  1489. * NOTE: Regulator system constraints must be set for this regulator before
  1490. * calling this function otherwise this call will fail.
  1491. */
  1492. int regulator_set_mode(struct regulator *regulator, unsigned int mode)
  1493. {
  1494. struct regulator_dev *rdev = regulator->rdev;
  1495. int ret;
  1496. int regulator_curr_mode;
  1497. mutex_lock(&rdev->mutex);
  1498. /* sanity check */
  1499. if (!rdev->desc->ops->set_mode) {
  1500. ret = -EINVAL;
  1501. goto out;
  1502. }
  1503. /* return if the same mode is requested */
  1504. if (rdev->desc->ops->get_mode) {
  1505. regulator_curr_mode = rdev->desc->ops->get_mode(rdev);
  1506. if (regulator_curr_mode == mode) {
  1507. ret = 0;
  1508. goto out;
  1509. }
  1510. }
  1511. /* constraints check */
  1512. ret = regulator_check_mode(rdev, mode);
  1513. if (ret < 0)
  1514. goto out;
  1515. ret = rdev->desc->ops->set_mode(rdev, mode);
  1516. out:
  1517. mutex_unlock(&rdev->mutex);
  1518. return ret;
  1519. }
  1520. EXPORT_SYMBOL_GPL(regulator_set_mode);
  1521. static unsigned int _regulator_get_mode(struct regulator_dev *rdev)
  1522. {
  1523. int ret;
  1524. mutex_lock(&rdev->mutex);
  1525. /* sanity check */
  1526. if (!rdev->desc->ops->get_mode) {
  1527. ret = -EINVAL;
  1528. goto out;
  1529. }
  1530. ret = rdev->desc->ops->get_mode(rdev);
  1531. out:
  1532. mutex_unlock(&rdev->mutex);
  1533. return ret;
  1534. }
  1535. /**
  1536. * regulator_get_mode - get regulator operating mode
  1537. * @regulator: regulator source
  1538. *
  1539. * Get the current regulator operating mode.
  1540. */
  1541. unsigned int regulator_get_mode(struct regulator *regulator)
  1542. {
  1543. return _regulator_get_mode(regulator->rdev);
  1544. }
  1545. EXPORT_SYMBOL_GPL(regulator_get_mode);
  1546. /**
  1547. * regulator_set_optimum_mode - set regulator optimum operating mode
  1548. * @regulator: regulator source
  1549. * @uA_load: load current
  1550. *
  1551. * Notifies the regulator core of a new device load. This is then used by
  1552. * DRMS (if enabled by constraints) to set the most efficient regulator
  1553. * operating mode for the new regulator loading.
  1554. *
  1555. * Consumer devices notify their supply regulator of the maximum power
  1556. * they will require (can be taken from device datasheet in the power
  1557. * consumption tables) when they change operational status and hence power
  1558. * state. Examples of operational state changes that can affect power
  1559. * consumption are :-
  1560. *
  1561. * o Device is opened / closed.
  1562. * o Device I/O is about to begin or has just finished.
  1563. * o Device is idling in between work.
  1564. *
  1565. * This information is also exported via sysfs to userspace.
  1566. *
  1567. * DRMS will sum the total requested load on the regulator and change
  1568. * to the most efficient operating mode if platform constraints allow.
  1569. *
  1570. * Returns the new regulator mode or error.
  1571. */
  1572. int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
  1573. {
  1574. struct regulator_dev *rdev = regulator->rdev;
  1575. struct regulator *consumer;
  1576. int ret, output_uV, input_uV, total_uA_load = 0;
  1577. unsigned int mode;
  1578. mutex_lock(&rdev->mutex);
  1579. regulator->uA_load = uA_load;
  1580. ret = regulator_check_drms(rdev);
  1581. if (ret < 0)
  1582. goto out;
  1583. ret = -EINVAL;
  1584. /* sanity check */
  1585. if (!rdev->desc->ops->get_optimum_mode)
  1586. goto out;
  1587. /* get output voltage */
  1588. output_uV = rdev->desc->ops->get_voltage(rdev);
  1589. if (output_uV <= 0) {
  1590. printk(KERN_ERR "%s: invalid output voltage found for %s\n",
  1591. __func__, rdev_get_name(rdev));
  1592. goto out;
  1593. }
  1594. /* get input voltage */
  1595. if (rdev->supply && rdev->supply->desc->ops->get_voltage)
  1596. input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply);
  1597. else
  1598. input_uV = rdev->constraints->input_uV;
  1599. if (input_uV <= 0) {
  1600. printk(KERN_ERR "%s: invalid input voltage found for %s\n",
  1601. __func__, rdev_get_name(rdev));
  1602. goto out;
  1603. }
  1604. /* calc total requested load for this regulator */
  1605. list_for_each_entry(consumer, &rdev->consumer_list, list)
  1606. total_uA_load += consumer->uA_load;
  1607. mode = rdev->desc->ops->get_optimum_mode(rdev,
  1608. input_uV, output_uV,
  1609. total_uA_load);
  1610. ret = regulator_check_mode(rdev, mode);
  1611. if (ret < 0) {
  1612. printk(KERN_ERR "%s: failed to get optimum mode for %s @"
  1613. " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev),
  1614. total_uA_load, input_uV, output_uV);
  1615. goto out;
  1616. }
  1617. ret = rdev->desc->ops->set_mode(rdev, mode);
  1618. if (ret < 0) {
  1619. printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n",
  1620. __func__, mode, rdev_get_name(rdev));
  1621. goto out;
  1622. }
  1623. ret = mode;
  1624. out:
  1625. mutex_unlock(&rdev->mutex);
  1626. return ret;
  1627. }
  1628. EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
  1629. /**
  1630. * regulator_register_notifier - register regulator event notifier
  1631. * @regulator: regulator source
  1632. * @nb: notifier block
  1633. *
  1634. * Register notifier block to receive regulator events.
  1635. */
  1636. int regulator_register_notifier(struct regulator *regulator,
  1637. struct notifier_block *nb)
  1638. {
  1639. return blocking_notifier_chain_register(&regulator->rdev->notifier,
  1640. nb);
  1641. }
  1642. EXPORT_SYMBOL_GPL(regulator_register_notifier);
  1643. /**
  1644. * regulator_unregister_notifier - unregister regulator event notifier
  1645. * @regulator: regulator source
  1646. * @nb: notifier block
  1647. *
  1648. * Unregister regulator event notifier block.
  1649. */
  1650. int regulator_unregister_notifier(struct regulator *regulator,
  1651. struct notifier_block *nb)
  1652. {
  1653. return blocking_notifier_chain_unregister(&regulator->rdev->notifier,
  1654. nb);
  1655. }
  1656. EXPORT_SYMBOL_GPL(regulator_unregister_notifier);
  1657. /* notify regulator consumers and downstream regulator consumers.
  1658. * Note mutex must be held by caller.
  1659. */
  1660. static void _notifier_call_chain(struct regulator_dev *rdev,
  1661. unsigned long event, void *data)
  1662. {
  1663. struct regulator_dev *_rdev;
  1664. /* call rdev chain first */
  1665. blocking_notifier_call_chain(&rdev->notifier, event, NULL);
  1666. /* now notify regulator we supply */
  1667. list_for_each_entry(_rdev, &rdev->supply_list, slist) {
  1668. mutex_lock(&_rdev->mutex);
  1669. _notifier_call_chain(_rdev, event, data);
  1670. mutex_unlock(&_rdev->mutex);
  1671. }
  1672. }
  1673. /**
  1674. * regulator_bulk_get - get multiple regulator consumers
  1675. *
  1676. * @dev: Device to supply
  1677. * @num_consumers: Number of consumers to register
  1678. * @consumers: Configuration of consumers; clients are stored here.
  1679. *
  1680. * @return 0 on success, an errno on failure.
  1681. *
  1682. * This helper function allows drivers to get several regulator
  1683. * consumers in one operation. If any of the regulators cannot be
  1684. * acquired then any regulators that were allocated will be freed
  1685. * before returning to the caller.
  1686. */
  1687. int regulator_bulk_get(struct device *dev, int num_consumers,
  1688. struct regulator_bulk_data *consumers)
  1689. {
  1690. int i;
  1691. int ret;
  1692. for (i = 0; i < num_consumers; i++)
  1693. consumers[i].consumer = NULL;
  1694. for (i = 0; i < num_consumers; i++) {
  1695. consumers[i].consumer = regulator_get(dev,
  1696. consumers[i].supply);
  1697. if (IS_ERR(consumers[i].consumer)) {
  1698. ret = PTR_ERR(consumers[i].consumer);
  1699. dev_err(dev, "Failed to get supply '%s': %d\n",
  1700. consumers[i].supply, ret);
  1701. consumers[i].consumer = NULL;
  1702. goto err;
  1703. }
  1704. }
  1705. return 0;
  1706. err:
  1707. for (i = 0; i < num_consumers && consumers[i].consumer; i++)
  1708. regulator_put(consumers[i].consumer);
  1709. return ret;
  1710. }
  1711. EXPORT_SYMBOL_GPL(regulator_bulk_get);
  1712. /**
  1713. * regulator_bulk_enable - enable multiple regulator consumers
  1714. *
  1715. * @num_consumers: Number of consumers
  1716. * @consumers: Consumer data; clients are stored here.
  1717. * @return 0 on success, an errno on failure
  1718. *
  1719. * This convenience API allows consumers to enable multiple regulator
  1720. * clients in a single API call. If any consumers cannot be enabled
  1721. * then any others that were enabled will be disabled again prior to
  1722. * return.
  1723. */
  1724. int regulator_bulk_enable(int num_consumers,
  1725. struct regulator_bulk_data *consumers)
  1726. {
  1727. int i;
  1728. int ret;
  1729. for (i = 0; i < num_consumers; i++) {
  1730. ret = regulator_enable(consumers[i].consumer);
  1731. if (ret != 0)
  1732. goto err;
  1733. }
  1734. return 0;
  1735. err:
  1736. printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret);
  1737. for (--i; i >= 0; --i)
  1738. regulator_disable(consumers[i].consumer);
  1739. return ret;
  1740. }
  1741. EXPORT_SYMBOL_GPL(regulator_bulk_enable);
  1742. /**
  1743. * regulator_bulk_disable - disable multiple regulator consumers
  1744. *
  1745. * @num_consumers: Number of consumers
  1746. * @consumers: Consumer data; clients are stored here.
  1747. * @return 0 on success, an errno on failure
  1748. *
  1749. * This convenience API allows consumers to disable multiple regulator
  1750. * clients in a single API call. If any consumers cannot be enabled
  1751. * then any others that were disabled will be disabled again prior to
  1752. * return.
  1753. */
  1754. int regulator_bulk_disable(int num_consumers,
  1755. struct regulator_bulk_data *consumers)
  1756. {
  1757. int i;
  1758. int ret;
  1759. for (i = 0; i < num_consumers; i++) {
  1760. ret = regulator_disable(consumers[i].consumer);
  1761. if (ret != 0)
  1762. goto err;
  1763. }
  1764. return 0;
  1765. err:
  1766. printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply,
  1767. ret);
  1768. for (--i; i >= 0; --i)
  1769. regulator_enable(consumers[i].consumer);
  1770. return ret;
  1771. }
  1772. EXPORT_SYMBOL_GPL(regulator_bulk_disable);
  1773. /**
  1774. * regulator_bulk_free - free multiple regulator consumers
  1775. *
  1776. * @num_consumers: Number of consumers
  1777. * @consumers: Consumer data; clients are stored here.
  1778. *
  1779. * This convenience API allows consumers to free multiple regulator
  1780. * clients in a single API call.
  1781. */
  1782. void regulator_bulk_free(int num_consumers,
  1783. struct regulator_bulk_data *consumers)
  1784. {
  1785. int i;
  1786. for (i = 0; i < num_consumers; i++) {
  1787. regulator_put(consumers[i].consumer);
  1788. consumers[i].consumer = NULL;
  1789. }
  1790. }
  1791. EXPORT_SYMBOL_GPL(regulator_bulk_free);
  1792. /**
  1793. * regulator_notifier_call_chain - call regulator event notifier
  1794. * @rdev: regulator source
  1795. * @event: notifier block
  1796. * @data: callback-specific data.
  1797. *
  1798. * Called by regulator drivers to notify clients a regulator event has
  1799. * occurred. We also notify regulator clients downstream.
  1800. * Note lock must be held by caller.
  1801. */
  1802. int regulator_notifier_call_chain(struct regulator_dev *rdev,
  1803. unsigned long event, void *data)
  1804. {
  1805. _notifier_call_chain(rdev, event, data);
  1806. return NOTIFY_DONE;
  1807. }
  1808. EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
  1809. /**
  1810. * regulator_mode_to_status - convert a regulator mode into a status
  1811. *
  1812. * @mode: Mode to convert
  1813. *
  1814. * Convert a regulator mode into a status.
  1815. */
  1816. int regulator_mode_to_status(unsigned int mode)
  1817. {
  1818. switch (mode) {
  1819. case REGULATOR_MODE_FAST:
  1820. return REGULATOR_STATUS_FAST;
  1821. case REGULATOR_MODE_NORMAL:
  1822. return REGULATOR_STATUS_NORMAL;
  1823. case REGULATOR_MODE_IDLE:
  1824. return REGULATOR_STATUS_IDLE;
  1825. case REGULATOR_STATUS_STANDBY:
  1826. return REGULATOR_STATUS_STANDBY;
  1827. default:
  1828. return 0;
  1829. }
  1830. }
  1831. EXPORT_SYMBOL_GPL(regulator_mode_to_status);
  1832. /*
  1833. * To avoid cluttering sysfs (and memory) with useless state, only
  1834. * create attributes that can be meaningfully displayed.
  1835. */
  1836. static int add_regulator_attributes(struct regulator_dev *rdev)
  1837. {
  1838. struct device *dev = &rdev->dev;
  1839. struct regulator_ops *ops = rdev->desc->ops;
  1840. int status = 0;
  1841. /* some attributes need specific methods to be displayed */
  1842. if (ops->get_voltage) {
  1843. status = device_create_file(dev, &dev_attr_microvolts);
  1844. if (status < 0)
  1845. return status;
  1846. }
  1847. if (ops->get_current_limit) {
  1848. status = device_create_file(dev, &dev_attr_microamps);
  1849. if (status < 0)
  1850. return status;
  1851. }
  1852. if (ops->get_mode) {
  1853. status = device_create_file(dev, &dev_attr_opmode);
  1854. if (status < 0)
  1855. return status;
  1856. }
  1857. if (ops->is_enabled) {
  1858. status = device_create_file(dev, &dev_attr_state);
  1859. if (status < 0)
  1860. return status;
  1861. }
  1862. if (ops->get_status) {
  1863. status = device_create_file(dev, &dev_attr_status);
  1864. if (status < 0)
  1865. return status;
  1866. }
  1867. /* some attributes are type-specific */
  1868. if (rdev->desc->type == REGULATOR_CURRENT) {
  1869. status = device_create_file(dev, &dev_attr_requested_microamps);
  1870. if (status < 0)
  1871. return status;
  1872. }
  1873. /* all the other attributes exist to support constraints;
  1874. * don't show them if there are no constraints, or if the
  1875. * relevant supporting methods are missing.
  1876. */
  1877. if (!rdev->constraints)
  1878. return status;
  1879. /* constraints need specific supporting methods */
  1880. if (ops->set_voltage) {
  1881. status = device_create_file(dev, &dev_attr_min_microvolts);
  1882. if (status < 0)
  1883. return status;
  1884. status = device_create_file(dev, &dev_attr_max_microvolts);
  1885. if (status < 0)
  1886. return status;
  1887. }
  1888. if (ops->set_current_limit) {
  1889. status = device_create_file(dev, &dev_attr_min_microamps);
  1890. if (status < 0)
  1891. return status;
  1892. status = device_create_file(dev, &dev_attr_max_microamps);
  1893. if (status < 0)
  1894. return status;
  1895. }
  1896. /* suspend mode constraints need multiple supporting methods */
  1897. if (!(ops->set_suspend_enable && ops->set_suspend_disable))
  1898. return status;
  1899. status = device_create_file(dev, &dev_attr_suspend_standby_state);
  1900. if (status < 0)
  1901. return status;
  1902. status = device_create_file(dev, &dev_attr_suspend_mem_state);
  1903. if (status < 0)
  1904. return status;
  1905. status = device_create_file(dev, &dev_attr_suspend_disk_state);
  1906. if (status < 0)
  1907. return status;
  1908. if (ops->set_suspend_voltage) {
  1909. status = device_create_file(dev,
  1910. &dev_attr_suspend_standby_microvolts);
  1911. if (status < 0)
  1912. return status;
  1913. status = device_create_file(dev,
  1914. &dev_attr_suspend_mem_microvolts);
  1915. if (status < 0)
  1916. return status;
  1917. status = device_create_file(dev,
  1918. &dev_attr_suspend_disk_microvolts);
  1919. if (status < 0)
  1920. return status;
  1921. }
  1922. if (ops->set_suspend_mode) {
  1923. status = device_create_file(dev,
  1924. &dev_attr_suspend_standby_mode);
  1925. if (status < 0)
  1926. return status;
  1927. status = device_create_file(dev,
  1928. &dev_attr_suspend_mem_mode);
  1929. if (status < 0)
  1930. return status;
  1931. status = device_create_file(dev,
  1932. &dev_attr_suspend_disk_mode);
  1933. if (status < 0)
  1934. return status;
  1935. }
  1936. return status;
  1937. }
  1938. /**
  1939. * regulator_register - register regulator
  1940. * @regulator_desc: regulator to register
  1941. * @dev: struct device for the regulator
  1942. * @init_data: platform provided init data, passed through by driver
  1943. * @driver_data: private regulator data
  1944. *
  1945. * Called by regulator drivers to register a regulator.
  1946. * Returns 0 on success.
  1947. */
  1948. struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
  1949. struct device *dev, struct regulator_init_data *init_data,
  1950. void *driver_data)
  1951. {
  1952. static atomic_t regulator_no = ATOMIC_INIT(0);
  1953. struct regulator_dev *rdev;
  1954. int ret, i;
  1955. if (regulator_desc == NULL)
  1956. return ERR_PTR(-EINVAL);
  1957. if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
  1958. return ERR_PTR(-EINVAL);
  1959. if (regulator_desc->type != REGULATOR_VOLTAGE &&
  1960. regulator_desc->type != REGULATOR_CURRENT)
  1961. return ERR_PTR(-EINVAL);
  1962. if (!init_data)
  1963. return ERR_PTR(-EINVAL);
  1964. rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
  1965. if (rdev == NULL)
  1966. return ERR_PTR(-ENOMEM);
  1967. mutex_lock(&regulator_list_mutex);
  1968. mutex_init(&rdev->mutex);
  1969. rdev->reg_data = driver_data;
  1970. rdev->owner = regulator_desc->owner;
  1971. rdev->desc = regulator_desc;
  1972. INIT_LIST_HEAD(&rdev->consumer_list);
  1973. INIT_LIST_HEAD(&rdev->supply_list);
  1974. INIT_LIST_HEAD(&rdev->list);
  1975. INIT_LIST_HEAD(&rdev->slist);
  1976. BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
  1977. /* preform any regulator specific init */
  1978. if (init_data->regulator_init) {
  1979. ret = init_data->regulator_init(rdev->reg_data);
  1980. if (ret < 0)
  1981. goto clean;
  1982. }
  1983. /* register with sysfs */
  1984. rdev->dev.class = &regulator_class;
  1985. rdev->dev.parent = dev;
  1986. dev_set_name(&rdev->dev, "regulator.%d",
  1987. atomic_inc_return(&regulator_no) - 1);
  1988. ret = device_register(&rdev->dev);
  1989. if (ret != 0) {
  1990. put_device(&rdev->dev);
  1991. goto clean;
  1992. }
  1993. dev_set_drvdata(&rdev->dev, rdev);
  1994. /* set regulator constraints */
  1995. ret = set_machine_constraints(rdev, &init_data->constraints);
  1996. if (ret < 0)
  1997. goto scrub;
  1998. /* add attributes supported by this regulator */
  1999. ret = add_regulator_attributes(rdev);
  2000. if (ret < 0)
  2001. goto scrub;
  2002. /* set supply regulator if it exists */
  2003. if (init_data->supply_regulator && init_data->supply_regulator_dev) {
  2004. dev_err(dev,
  2005. "Supply regulator specified by both name and dev\n");
  2006. goto scrub;
  2007. }
  2008. if (init_data->supply_regulator) {
  2009. struct regulator_dev *r;
  2010. int found = 0;
  2011. list_for_each_entry(r, &regulator_list, list) {
  2012. if (strcmp(rdev_get_name(r),
  2013. init_data->supply_regulator) == 0) {
  2014. found = 1;
  2015. break;
  2016. }
  2017. }
  2018. if (!found) {
  2019. dev_err(dev, "Failed to find supply %s\n",
  2020. init_data->supply_regulator);
  2021. goto scrub;
  2022. }
  2023. ret = set_supply(rdev, r);
  2024. if (ret < 0)
  2025. goto scrub;
  2026. }
  2027. if (init_data->supply_regulator_dev) {
  2028. dev_warn(dev, "Uses supply_regulator_dev instead of regulator_supply\n");
  2029. ret = set_supply(rdev,
  2030. dev_get_drvdata(init_data->supply_regulator_dev));
  2031. if (ret < 0)
  2032. goto scrub;
  2033. }
  2034. /* add consumers devices */
  2035. for (i = 0; i < init_data->num_consumer_supplies; i++) {
  2036. ret = set_consumer_device_supply(rdev,
  2037. init_data->consumer_supplies[i].dev,
  2038. init_data->consumer_supplies[i].dev_name,
  2039. init_data->consumer_supplies[i].supply);
  2040. if (ret < 0)
  2041. goto unset_supplies;
  2042. }
  2043. list_add(&rdev->list, &regulator_list);
  2044. out:
  2045. mutex_unlock(&regulator_list_mutex);
  2046. return rdev;
  2047. unset_supplies:
  2048. unset_regulator_supplies(rdev);
  2049. scrub:
  2050. device_unregister(&rdev->dev);
  2051. /* device core frees rdev */
  2052. rdev = ERR_PTR(ret);
  2053. goto out;
  2054. clean:
  2055. kfree(rdev);
  2056. rdev = ERR_PTR(ret);
  2057. goto out;
  2058. }
  2059. EXPORT_SYMBOL_GPL(regulator_register);
  2060. /**
  2061. * regulator_unregister - unregister regulator
  2062. * @rdev: regulator to unregister
  2063. *
  2064. * Called by regulator drivers to unregister a regulator.
  2065. */
  2066. void regulator_unregister(struct regulator_dev *rdev)
  2067. {
  2068. if (rdev == NULL)
  2069. return;
  2070. mutex_lock(&regulator_list_mutex);
  2071. WARN_ON(rdev->open_count);
  2072. unset_regulator_supplies(rdev);
  2073. list_del(&rdev->list);
  2074. if (rdev->supply)
  2075. sysfs_remove_link(&rdev->dev.kobj, "supply");
  2076. device_unregister(&rdev->dev);
  2077. mutex_unlock(&regulator_list_mutex);
  2078. }
  2079. EXPORT_SYMBOL_GPL(regulator_unregister);
  2080. /**
  2081. * regulator_suspend_prepare - prepare regulators for system wide suspend
  2082. * @state: system suspend state
  2083. *
  2084. * Configure each regulator with it's suspend operating parameters for state.
  2085. * This will usually be called by machine suspend code prior to supending.
  2086. */
  2087. int regulator_suspend_prepare(suspend_state_t state)
  2088. {
  2089. struct regulator_dev *rdev;
  2090. int ret = 0;
  2091. /* ON is handled by regulator active state */
  2092. if (state == PM_SUSPEND_ON)
  2093. return -EINVAL;
  2094. mutex_lock(&regulator_list_mutex);
  2095. list_for_each_entry(rdev, &regulator_list, list) {
  2096. mutex_lock(&rdev->mutex);
  2097. ret = suspend_prepare(rdev, state);
  2098. mutex_unlock(&rdev->mutex);
  2099. if (ret < 0) {
  2100. printk(KERN_ERR "%s: failed to prepare %s\n",
  2101. __func__, rdev_get_name(rdev));
  2102. goto out;
  2103. }
  2104. }
  2105. out:
  2106. mutex_unlock(&regulator_list_mutex);
  2107. return ret;
  2108. }
  2109. EXPORT_SYMBOL_GPL(regulator_suspend_prepare);
  2110. /**
  2111. * regulator_has_full_constraints - the system has fully specified constraints
  2112. *
  2113. * Calling this function will cause the regulator API to disable all
  2114. * regulators which have a zero use count and don't have an always_on
  2115. * constraint in a late_initcall.
  2116. *
  2117. * The intention is that this will become the default behaviour in a
  2118. * future kernel release so users are encouraged to use this facility
  2119. * now.
  2120. */
  2121. void regulator_has_full_constraints(void)
  2122. {
  2123. has_full_constraints = 1;
  2124. }
  2125. EXPORT_SYMBOL_GPL(regulator_has_full_constraints);
  2126. /**
  2127. * rdev_get_drvdata - get rdev regulator driver data
  2128. * @rdev: regulator
  2129. *
  2130. * Get rdev regulator driver private data. This call can be used in the
  2131. * regulator driver context.
  2132. */
  2133. void *rdev_get_drvdata(struct regulator_dev *rdev)
  2134. {
  2135. return rdev->reg_data;
  2136. }
  2137. EXPORT_SYMBOL_GPL(rdev_get_drvdata);
  2138. /**
  2139. * regulator_get_drvdata - get regulator driver data
  2140. * @regulator: regulator
  2141. *
  2142. * Get regulator driver private data. This call can be used in the consumer
  2143. * driver context when non API regulator specific functions need to be called.
  2144. */
  2145. void *regulator_get_drvdata(struct regulator *regulator)
  2146. {
  2147. return regulator->rdev->reg_data;
  2148. }
  2149. EXPORT_SYMBOL_GPL(regulator_get_drvdata);
  2150. /**
  2151. * regulator_set_drvdata - set regulator driver data
  2152. * @regulator: regulator
  2153. * @data: data
  2154. */
  2155. void regulator_set_drvdata(struct regulator *regulator, void *data)
  2156. {
  2157. regulator->rdev->reg_data = data;
  2158. }
  2159. EXPORT_SYMBOL_GPL(regulator_set_drvdata);
  2160. /**
  2161. * regulator_get_id - get regulator ID
  2162. * @rdev: regulator
  2163. */
  2164. int rdev_get_id(struct regulator_dev *rdev)
  2165. {
  2166. return rdev->desc->id;
  2167. }
  2168. EXPORT_SYMBOL_GPL(rdev_get_id);
  2169. struct device *rdev_get_dev(struct regulator_dev *rdev)
  2170. {
  2171. return &rdev->dev;
  2172. }
  2173. EXPORT_SYMBOL_GPL(rdev_get_dev);
  2174. void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
  2175. {
  2176. return reg_init_data->driver_data;
  2177. }
  2178. EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
  2179. static int __init regulator_init(void)
  2180. {
  2181. int ret;
  2182. printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
  2183. ret = class_register(&regulator_class);
  2184. regulator_dummy_init();
  2185. return ret;
  2186. }
  2187. /* init early to allow our consumers to complete system booting */
  2188. core_initcall(regulator_init);
  2189. static int __init regulator_init_complete(void)
  2190. {
  2191. struct regulator_dev *rdev;
  2192. struct regulator_ops *ops;
  2193. struct regulation_constraints *c;
  2194. int enabled, ret;
  2195. const char *name;
  2196. mutex_lock(&regulator_list_mutex);
  2197. /* If we have a full configuration then disable any regulators
  2198. * which are not in use or always_on. This will become the
  2199. * default behaviour in the future.
  2200. */
  2201. list_for_each_entry(rdev, &regulator_list, list) {
  2202. ops = rdev->desc->ops;
  2203. c = rdev->constraints;
  2204. name = rdev_get_name(rdev);
  2205. if (!ops->disable || (c && c->always_on))
  2206. continue;
  2207. mutex_lock(&rdev->mutex);
  2208. if (rdev->use_count)
  2209. goto unlock;
  2210. /* If we can't read the status assume it's on. */
  2211. if (ops->is_enabled)
  2212. enabled = ops->is_enabled(rdev);
  2213. else
  2214. enabled = 1;
  2215. if (!enabled)
  2216. goto unlock;
  2217. if (has_full_constraints) {
  2218. /* We log since this may kill the system if it
  2219. * goes wrong. */
  2220. printk(KERN_INFO "%s: disabling %s\n",
  2221. __func__, name);
  2222. ret = ops->disable(rdev);
  2223. if (ret != 0) {
  2224. printk(KERN_ERR
  2225. "%s: couldn't disable %s: %d\n",
  2226. __func__, name, ret);
  2227. }
  2228. } else {
  2229. /* The intention is that in future we will
  2230. * assume that full constraints are provided
  2231. * so warn even if we aren't going to do
  2232. * anything here.
  2233. */
  2234. printk(KERN_WARNING
  2235. "%s: incomplete constraints, leaving %s on\n",
  2236. __func__, name);
  2237. }
  2238. unlock:
  2239. mutex_unlock(&rdev->mutex);
  2240. }
  2241. mutex_unlock(&regulator_list_mutex);
  2242. return 0;
  2243. }
  2244. late_initcall(regulator_init_complete);