core.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606
  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 uA ", 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.owner = THIS_MODULE;
  878. regulator->dev_attr.attr.mode = 0444;
  879. regulator->dev_attr.show = device_requested_uA_show;
  880. err = device_create_file(dev, &regulator->dev_attr);
  881. if (err < 0) {
  882. printk(KERN_WARNING "%s: could not add regulator_dev"
  883. " load sysfs\n", __func__);
  884. goto attr_name_err;
  885. }
  886. /* also add a link to the device sysfs entry */
  887. size = scnprintf(buf, REG_STR_SIZE, "%s-%s",
  888. dev->kobj.name, supply_name);
  889. if (size >= REG_STR_SIZE)
  890. goto attr_err;
  891. regulator->supply_name = kstrdup(buf, GFP_KERNEL);
  892. if (regulator->supply_name == NULL)
  893. goto attr_err;
  894. err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj,
  895. buf);
  896. if (err) {
  897. printk(KERN_WARNING
  898. "%s: could not add device link %s err %d\n",
  899. __func__, dev->kobj.name, err);
  900. device_remove_file(dev, &regulator->dev_attr);
  901. goto link_name_err;
  902. }
  903. }
  904. mutex_unlock(&rdev->mutex);
  905. return regulator;
  906. link_name_err:
  907. kfree(regulator->supply_name);
  908. attr_err:
  909. device_remove_file(regulator->dev, &regulator->dev_attr);
  910. attr_name_err:
  911. kfree(regulator->dev_attr.attr.name);
  912. overflow_err:
  913. list_del(&regulator->list);
  914. kfree(regulator);
  915. mutex_unlock(&rdev->mutex);
  916. return NULL;
  917. }
  918. static int _regulator_get_enable_time(struct regulator_dev *rdev)
  919. {
  920. if (!rdev->desc->ops->enable_time)
  921. return 0;
  922. return rdev->desc->ops->enable_time(rdev);
  923. }
  924. /* Internal regulator request function */
  925. static struct regulator *_regulator_get(struct device *dev, const char *id,
  926. int exclusive)
  927. {
  928. struct regulator_dev *rdev;
  929. struct regulator_map *map;
  930. struct regulator *regulator = ERR_PTR(-ENODEV);
  931. const char *devname = NULL;
  932. int ret;
  933. if (id == NULL) {
  934. printk(KERN_ERR "regulator: get() with no identifier\n");
  935. return regulator;
  936. }
  937. if (dev)
  938. devname = dev_name(dev);
  939. mutex_lock(&regulator_list_mutex);
  940. list_for_each_entry(map, &regulator_map_list, list) {
  941. /* If the mapping has a device set up it must match */
  942. if (map->dev_name &&
  943. (!devname || strcmp(map->dev_name, devname)))
  944. continue;
  945. if (strcmp(map->supply, id) == 0) {
  946. rdev = map->regulator;
  947. goto found;
  948. }
  949. }
  950. #ifdef CONFIG_REGULATOR_DUMMY
  951. if (!devname)
  952. devname = "deviceless";
  953. /* If the board didn't flag that it was fully constrained then
  954. * substitute in a dummy regulator so consumers can continue.
  955. */
  956. if (!has_full_constraints) {
  957. pr_warning("%s supply %s not found, using dummy regulator\n",
  958. devname, id);
  959. rdev = dummy_regulator_rdev;
  960. goto found;
  961. }
  962. #endif
  963. mutex_unlock(&regulator_list_mutex);
  964. return regulator;
  965. found:
  966. if (rdev->exclusive) {
  967. regulator = ERR_PTR(-EPERM);
  968. goto out;
  969. }
  970. if (exclusive && rdev->open_count) {
  971. regulator = ERR_PTR(-EBUSY);
  972. goto out;
  973. }
  974. if (!try_module_get(rdev->owner))
  975. goto out;
  976. regulator = create_regulator(rdev, dev, id);
  977. if (regulator == NULL) {
  978. regulator = ERR_PTR(-ENOMEM);
  979. module_put(rdev->owner);
  980. }
  981. rdev->open_count++;
  982. if (exclusive) {
  983. rdev->exclusive = 1;
  984. ret = _regulator_is_enabled(rdev);
  985. if (ret > 0)
  986. rdev->use_count = 1;
  987. else
  988. rdev->use_count = 0;
  989. }
  990. out:
  991. mutex_unlock(&regulator_list_mutex);
  992. return regulator;
  993. }
  994. /**
  995. * regulator_get - lookup and obtain a reference to a regulator.
  996. * @dev: device for regulator "consumer"
  997. * @id: Supply name or regulator ID.
  998. *
  999. * Returns a struct regulator corresponding to the regulator producer,
  1000. * or IS_ERR() condition containing errno.
  1001. *
  1002. * Use of supply names configured via regulator_set_device_supply() is
  1003. * strongly encouraged. It is recommended that the supply name used
  1004. * should match the name used for the supply and/or the relevant
  1005. * device pins in the datasheet.
  1006. */
  1007. struct regulator *regulator_get(struct device *dev, const char *id)
  1008. {
  1009. return _regulator_get(dev, id, 0);
  1010. }
  1011. EXPORT_SYMBOL_GPL(regulator_get);
  1012. /**
  1013. * regulator_get_exclusive - obtain exclusive access to a regulator.
  1014. * @dev: device for regulator "consumer"
  1015. * @id: Supply name or regulator ID.
  1016. *
  1017. * Returns a struct regulator corresponding to the regulator producer,
  1018. * or IS_ERR() condition containing errno. Other consumers will be
  1019. * unable to obtain this reference is held and the use count for the
  1020. * regulator will be initialised to reflect the current state of the
  1021. * regulator.
  1022. *
  1023. * This is intended for use by consumers which cannot tolerate shared
  1024. * use of the regulator such as those which need to force the
  1025. * regulator off for correct operation of the hardware they are
  1026. * controlling.
  1027. *
  1028. * Use of supply names configured via regulator_set_device_supply() is
  1029. * strongly encouraged. It is recommended that the supply name used
  1030. * should match the name used for the supply and/or the relevant
  1031. * device pins in the datasheet.
  1032. */
  1033. struct regulator *regulator_get_exclusive(struct device *dev, const char *id)
  1034. {
  1035. return _regulator_get(dev, id, 1);
  1036. }
  1037. EXPORT_SYMBOL_GPL(regulator_get_exclusive);
  1038. /**
  1039. * regulator_put - "free" the regulator source
  1040. * @regulator: regulator source
  1041. *
  1042. * Note: drivers must ensure that all regulator_enable calls made on this
  1043. * regulator source are balanced by regulator_disable calls prior to calling
  1044. * this function.
  1045. */
  1046. void regulator_put(struct regulator *regulator)
  1047. {
  1048. struct regulator_dev *rdev;
  1049. if (regulator == NULL || IS_ERR(regulator))
  1050. return;
  1051. mutex_lock(&regulator_list_mutex);
  1052. rdev = regulator->rdev;
  1053. /* remove any sysfs entries */
  1054. if (regulator->dev) {
  1055. sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name);
  1056. kfree(regulator->supply_name);
  1057. device_remove_file(regulator->dev, &regulator->dev_attr);
  1058. kfree(regulator->dev_attr.attr.name);
  1059. }
  1060. list_del(&regulator->list);
  1061. kfree(regulator);
  1062. rdev->open_count--;
  1063. rdev->exclusive = 0;
  1064. module_put(rdev->owner);
  1065. mutex_unlock(&regulator_list_mutex);
  1066. }
  1067. EXPORT_SYMBOL_GPL(regulator_put);
  1068. static int _regulator_can_change_status(struct regulator_dev *rdev)
  1069. {
  1070. if (!rdev->constraints)
  1071. return 0;
  1072. if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS)
  1073. return 1;
  1074. else
  1075. return 0;
  1076. }
  1077. /* locks held by regulator_enable() */
  1078. static int _regulator_enable(struct regulator_dev *rdev)
  1079. {
  1080. int ret, delay;
  1081. /* do we need to enable the supply regulator first */
  1082. if (rdev->supply) {
  1083. ret = _regulator_enable(rdev->supply);
  1084. if (ret < 0) {
  1085. printk(KERN_ERR "%s: failed to enable %s: %d\n",
  1086. __func__, rdev_get_name(rdev), ret);
  1087. return ret;
  1088. }
  1089. }
  1090. /* check voltage and requested load before enabling */
  1091. if (rdev->constraints &&
  1092. (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
  1093. drms_uA_update(rdev);
  1094. if (rdev->use_count == 0) {
  1095. /* The regulator may on if it's not switchable or left on */
  1096. ret = _regulator_is_enabled(rdev);
  1097. if (ret == -EINVAL || ret == 0) {
  1098. if (!_regulator_can_change_status(rdev))
  1099. return -EPERM;
  1100. if (!rdev->desc->ops->enable)
  1101. return -EINVAL;
  1102. /* Query before enabling in case configuration
  1103. * dependant. */
  1104. ret = _regulator_get_enable_time(rdev);
  1105. if (ret >= 0) {
  1106. delay = ret;
  1107. } else {
  1108. printk(KERN_WARNING
  1109. "%s: enable_time() failed for %s: %d\n",
  1110. __func__, rdev_get_name(rdev),
  1111. ret);
  1112. delay = 0;
  1113. }
  1114. /* Allow the regulator to ramp; it would be useful
  1115. * to extend this for bulk operations so that the
  1116. * regulators can ramp together. */
  1117. ret = rdev->desc->ops->enable(rdev);
  1118. if (ret < 0)
  1119. return ret;
  1120. if (delay >= 1000)
  1121. mdelay(delay / 1000);
  1122. else if (delay)
  1123. udelay(delay);
  1124. } else if (ret < 0) {
  1125. printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n",
  1126. __func__, rdev_get_name(rdev), ret);
  1127. return ret;
  1128. }
  1129. /* Fallthrough on positive return values - already enabled */
  1130. }
  1131. rdev->use_count++;
  1132. return 0;
  1133. }
  1134. /**
  1135. * regulator_enable - enable regulator output
  1136. * @regulator: regulator source
  1137. *
  1138. * Request that the regulator be enabled with the regulator output at
  1139. * the predefined voltage or current value. Calls to regulator_enable()
  1140. * must be balanced with calls to regulator_disable().
  1141. *
  1142. * NOTE: the output value can be set by other drivers, boot loader or may be
  1143. * hardwired in the regulator.
  1144. */
  1145. int regulator_enable(struct regulator *regulator)
  1146. {
  1147. struct regulator_dev *rdev = regulator->rdev;
  1148. int ret = 0;
  1149. mutex_lock(&rdev->mutex);
  1150. ret = _regulator_enable(rdev);
  1151. mutex_unlock(&rdev->mutex);
  1152. return ret;
  1153. }
  1154. EXPORT_SYMBOL_GPL(regulator_enable);
  1155. /* locks held by regulator_disable() */
  1156. static int _regulator_disable(struct regulator_dev *rdev)
  1157. {
  1158. int ret = 0;
  1159. if (WARN(rdev->use_count <= 0,
  1160. "unbalanced disables for %s\n",
  1161. rdev_get_name(rdev)))
  1162. return -EIO;
  1163. /* are we the last user and permitted to disable ? */
  1164. if (rdev->use_count == 1 &&
  1165. (rdev->constraints && !rdev->constraints->always_on)) {
  1166. /* we are last user */
  1167. if (_regulator_can_change_status(rdev) &&
  1168. rdev->desc->ops->disable) {
  1169. ret = rdev->desc->ops->disable(rdev);
  1170. if (ret < 0) {
  1171. printk(KERN_ERR "%s: failed to disable %s\n",
  1172. __func__, rdev_get_name(rdev));
  1173. return ret;
  1174. }
  1175. _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
  1176. NULL);
  1177. }
  1178. /* decrease our supplies ref count and disable if required */
  1179. if (rdev->supply)
  1180. _regulator_disable(rdev->supply);
  1181. rdev->use_count = 0;
  1182. } else if (rdev->use_count > 1) {
  1183. if (rdev->constraints &&
  1184. (rdev->constraints->valid_ops_mask &
  1185. REGULATOR_CHANGE_DRMS))
  1186. drms_uA_update(rdev);
  1187. rdev->use_count--;
  1188. }
  1189. return ret;
  1190. }
  1191. /**
  1192. * regulator_disable - disable regulator output
  1193. * @regulator: regulator source
  1194. *
  1195. * Disable the regulator output voltage or current. Calls to
  1196. * regulator_enable() must be balanced with calls to
  1197. * regulator_disable().
  1198. *
  1199. * NOTE: this will only disable the regulator output if no other consumer
  1200. * devices have it enabled, the regulator device supports disabling and
  1201. * machine constraints permit this operation.
  1202. */
  1203. int regulator_disable(struct regulator *regulator)
  1204. {
  1205. struct regulator_dev *rdev = regulator->rdev;
  1206. int ret = 0;
  1207. mutex_lock(&rdev->mutex);
  1208. ret = _regulator_disable(rdev);
  1209. mutex_unlock(&rdev->mutex);
  1210. return ret;
  1211. }
  1212. EXPORT_SYMBOL_GPL(regulator_disable);
  1213. /* locks held by regulator_force_disable() */
  1214. static int _regulator_force_disable(struct regulator_dev *rdev)
  1215. {
  1216. int ret = 0;
  1217. /* force disable */
  1218. if (rdev->desc->ops->disable) {
  1219. /* ah well, who wants to live forever... */
  1220. ret = rdev->desc->ops->disable(rdev);
  1221. if (ret < 0) {
  1222. printk(KERN_ERR "%s: failed to force disable %s\n",
  1223. __func__, rdev_get_name(rdev));
  1224. return ret;
  1225. }
  1226. /* notify other consumers that power has been forced off */
  1227. _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
  1228. REGULATOR_EVENT_DISABLE, NULL);
  1229. }
  1230. /* decrease our supplies ref count and disable if required */
  1231. if (rdev->supply)
  1232. _regulator_disable(rdev->supply);
  1233. rdev->use_count = 0;
  1234. return ret;
  1235. }
  1236. /**
  1237. * regulator_force_disable - force disable regulator output
  1238. * @regulator: regulator source
  1239. *
  1240. * Forcibly disable the regulator output voltage or current.
  1241. * NOTE: this *will* disable the regulator output even if other consumer
  1242. * devices have it enabled. This should be used for situations when device
  1243. * damage will likely occur if the regulator is not disabled (e.g. over temp).
  1244. */
  1245. int regulator_force_disable(struct regulator *regulator)
  1246. {
  1247. int ret;
  1248. mutex_lock(&regulator->rdev->mutex);
  1249. regulator->uA_load = 0;
  1250. ret = _regulator_force_disable(regulator->rdev);
  1251. mutex_unlock(&regulator->rdev->mutex);
  1252. return ret;
  1253. }
  1254. EXPORT_SYMBOL_GPL(regulator_force_disable);
  1255. static int _regulator_is_enabled(struct regulator_dev *rdev)
  1256. {
  1257. /* If we don't know then assume that the regulator is always on */
  1258. if (!rdev->desc->ops->is_enabled)
  1259. return 1;
  1260. return rdev->desc->ops->is_enabled(rdev);
  1261. }
  1262. /**
  1263. * regulator_is_enabled - is the regulator output enabled
  1264. * @regulator: regulator source
  1265. *
  1266. * Returns positive if the regulator driver backing the source/client
  1267. * has requested that the device be enabled, zero if it hasn't, else a
  1268. * negative errno code.
  1269. *
  1270. * Note that the device backing this regulator handle can have multiple
  1271. * users, so it might be enabled even if regulator_enable() was never
  1272. * called for this particular source.
  1273. */
  1274. int regulator_is_enabled(struct regulator *regulator)
  1275. {
  1276. int ret;
  1277. mutex_lock(&regulator->rdev->mutex);
  1278. ret = _regulator_is_enabled(regulator->rdev);
  1279. mutex_unlock(&regulator->rdev->mutex);
  1280. return ret;
  1281. }
  1282. EXPORT_SYMBOL_GPL(regulator_is_enabled);
  1283. /**
  1284. * regulator_count_voltages - count regulator_list_voltage() selectors
  1285. * @regulator: regulator source
  1286. *
  1287. * Returns number of selectors, or negative errno. Selectors are
  1288. * numbered starting at zero, and typically correspond to bitfields
  1289. * in hardware registers.
  1290. */
  1291. int regulator_count_voltages(struct regulator *regulator)
  1292. {
  1293. struct regulator_dev *rdev = regulator->rdev;
  1294. return rdev->desc->n_voltages ? : -EINVAL;
  1295. }
  1296. EXPORT_SYMBOL_GPL(regulator_count_voltages);
  1297. /**
  1298. * regulator_list_voltage - enumerate supported voltages
  1299. * @regulator: regulator source
  1300. * @selector: identify voltage to list
  1301. * Context: can sleep
  1302. *
  1303. * Returns a voltage that can be passed to @regulator_set_voltage(),
  1304. * zero if this selector code can't be used on this system, or a
  1305. * negative errno.
  1306. */
  1307. int regulator_list_voltage(struct regulator *regulator, unsigned selector)
  1308. {
  1309. struct regulator_dev *rdev = regulator->rdev;
  1310. struct regulator_ops *ops = rdev->desc->ops;
  1311. int ret;
  1312. if (!ops->list_voltage || selector >= rdev->desc->n_voltages)
  1313. return -EINVAL;
  1314. mutex_lock(&rdev->mutex);
  1315. ret = ops->list_voltage(rdev, selector);
  1316. mutex_unlock(&rdev->mutex);
  1317. if (ret > 0) {
  1318. if (ret < rdev->constraints->min_uV)
  1319. ret = 0;
  1320. else if (ret > rdev->constraints->max_uV)
  1321. ret = 0;
  1322. }
  1323. return ret;
  1324. }
  1325. EXPORT_SYMBOL_GPL(regulator_list_voltage);
  1326. /**
  1327. * regulator_is_supported_voltage - check if a voltage range can be supported
  1328. *
  1329. * @regulator: Regulator to check.
  1330. * @min_uV: Minimum required voltage in uV.
  1331. * @max_uV: Maximum required voltage in uV.
  1332. *
  1333. * Returns a boolean or a negative error code.
  1334. */
  1335. int regulator_is_supported_voltage(struct regulator *regulator,
  1336. int min_uV, int max_uV)
  1337. {
  1338. int i, voltages, ret;
  1339. ret = regulator_count_voltages(regulator);
  1340. if (ret < 0)
  1341. return ret;
  1342. voltages = ret;
  1343. for (i = 0; i < voltages; i++) {
  1344. ret = regulator_list_voltage(regulator, i);
  1345. if (ret >= min_uV && ret <= max_uV)
  1346. return 1;
  1347. }
  1348. return 0;
  1349. }
  1350. /**
  1351. * regulator_set_voltage - set regulator output voltage
  1352. * @regulator: regulator source
  1353. * @min_uV: Minimum required voltage in uV
  1354. * @max_uV: Maximum acceptable voltage in uV
  1355. *
  1356. * Sets a voltage regulator to the desired output voltage. This can be set
  1357. * during any regulator state. IOW, regulator can be disabled or enabled.
  1358. *
  1359. * If the regulator is enabled then the voltage will change to the new value
  1360. * immediately otherwise if the regulator is disabled the regulator will
  1361. * output at the new voltage when enabled.
  1362. *
  1363. * NOTE: If the regulator is shared between several devices then the lowest
  1364. * request voltage that meets the system constraints will be used.
  1365. * Regulator system constraints must be set for this regulator before
  1366. * calling this function otherwise this call will fail.
  1367. */
  1368. int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
  1369. {
  1370. struct regulator_dev *rdev = regulator->rdev;
  1371. int ret;
  1372. mutex_lock(&rdev->mutex);
  1373. /* sanity check */
  1374. if (!rdev->desc->ops->set_voltage) {
  1375. ret = -EINVAL;
  1376. goto out;
  1377. }
  1378. /* constraints check */
  1379. ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
  1380. if (ret < 0)
  1381. goto out;
  1382. regulator->min_uV = min_uV;
  1383. regulator->max_uV = max_uV;
  1384. ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV);
  1385. out:
  1386. _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL);
  1387. mutex_unlock(&rdev->mutex);
  1388. return ret;
  1389. }
  1390. EXPORT_SYMBOL_GPL(regulator_set_voltage);
  1391. static int _regulator_get_voltage(struct regulator_dev *rdev)
  1392. {
  1393. /* sanity check */
  1394. if (rdev->desc->ops->get_voltage)
  1395. return rdev->desc->ops->get_voltage(rdev);
  1396. else
  1397. return -EINVAL;
  1398. }
  1399. /**
  1400. * regulator_get_voltage - get regulator output voltage
  1401. * @regulator: regulator source
  1402. *
  1403. * This returns the current regulator voltage in uV.
  1404. *
  1405. * NOTE: If the regulator is disabled it will return the voltage value. This
  1406. * function should not be used to determine regulator state.
  1407. */
  1408. int regulator_get_voltage(struct regulator *regulator)
  1409. {
  1410. int ret;
  1411. mutex_lock(&regulator->rdev->mutex);
  1412. ret = _regulator_get_voltage(regulator->rdev);
  1413. mutex_unlock(&regulator->rdev->mutex);
  1414. return ret;
  1415. }
  1416. EXPORT_SYMBOL_GPL(regulator_get_voltage);
  1417. /**
  1418. * regulator_set_current_limit - set regulator output current limit
  1419. * @regulator: regulator source
  1420. * @min_uA: Minimuum supported current in uA
  1421. * @max_uA: Maximum supported current in uA
  1422. *
  1423. * Sets current sink to the desired output current. This can be set during
  1424. * any regulator state. IOW, regulator can be disabled or enabled.
  1425. *
  1426. * If the regulator is enabled then the current will change to the new value
  1427. * immediately otherwise if the regulator is disabled the regulator will
  1428. * output at the new current when enabled.
  1429. *
  1430. * NOTE: Regulator system constraints must be set for this regulator before
  1431. * calling this function otherwise this call will fail.
  1432. */
  1433. int regulator_set_current_limit(struct regulator *regulator,
  1434. int min_uA, int max_uA)
  1435. {
  1436. struct regulator_dev *rdev = regulator->rdev;
  1437. int ret;
  1438. mutex_lock(&rdev->mutex);
  1439. /* sanity check */
  1440. if (!rdev->desc->ops->set_current_limit) {
  1441. ret = -EINVAL;
  1442. goto out;
  1443. }
  1444. /* constraints check */
  1445. ret = regulator_check_current_limit(rdev, &min_uA, &max_uA);
  1446. if (ret < 0)
  1447. goto out;
  1448. ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA);
  1449. out:
  1450. mutex_unlock(&rdev->mutex);
  1451. return ret;
  1452. }
  1453. EXPORT_SYMBOL_GPL(regulator_set_current_limit);
  1454. static int _regulator_get_current_limit(struct regulator_dev *rdev)
  1455. {
  1456. int ret;
  1457. mutex_lock(&rdev->mutex);
  1458. /* sanity check */
  1459. if (!rdev->desc->ops->get_current_limit) {
  1460. ret = -EINVAL;
  1461. goto out;
  1462. }
  1463. ret = rdev->desc->ops->get_current_limit(rdev);
  1464. out:
  1465. mutex_unlock(&rdev->mutex);
  1466. return ret;
  1467. }
  1468. /**
  1469. * regulator_get_current_limit - get regulator output current
  1470. * @regulator: regulator source
  1471. *
  1472. * This returns the current supplied by the specified current sink in uA.
  1473. *
  1474. * NOTE: If the regulator is disabled it will return the current value. This
  1475. * function should not be used to determine regulator state.
  1476. */
  1477. int regulator_get_current_limit(struct regulator *regulator)
  1478. {
  1479. return _regulator_get_current_limit(regulator->rdev);
  1480. }
  1481. EXPORT_SYMBOL_GPL(regulator_get_current_limit);
  1482. /**
  1483. * regulator_set_mode - set regulator operating mode
  1484. * @regulator: regulator source
  1485. * @mode: operating mode - one of the REGULATOR_MODE constants
  1486. *
  1487. * Set regulator operating mode to increase regulator efficiency or improve
  1488. * regulation performance.
  1489. *
  1490. * NOTE: Regulator system constraints must be set for this regulator before
  1491. * calling this function otherwise this call will fail.
  1492. */
  1493. int regulator_set_mode(struct regulator *regulator, unsigned int mode)
  1494. {
  1495. struct regulator_dev *rdev = regulator->rdev;
  1496. int ret;
  1497. int regulator_curr_mode;
  1498. mutex_lock(&rdev->mutex);
  1499. /* sanity check */
  1500. if (!rdev->desc->ops->set_mode) {
  1501. ret = -EINVAL;
  1502. goto out;
  1503. }
  1504. /* return if the same mode is requested */
  1505. if (rdev->desc->ops->get_mode) {
  1506. regulator_curr_mode = rdev->desc->ops->get_mode(rdev);
  1507. if (regulator_curr_mode == mode) {
  1508. ret = 0;
  1509. goto out;
  1510. }
  1511. }
  1512. /* constraints check */
  1513. ret = regulator_check_mode(rdev, mode);
  1514. if (ret < 0)
  1515. goto out;
  1516. ret = rdev->desc->ops->set_mode(rdev, mode);
  1517. out:
  1518. mutex_unlock(&rdev->mutex);
  1519. return ret;
  1520. }
  1521. EXPORT_SYMBOL_GPL(regulator_set_mode);
  1522. static unsigned int _regulator_get_mode(struct regulator_dev *rdev)
  1523. {
  1524. int ret;
  1525. mutex_lock(&rdev->mutex);
  1526. /* sanity check */
  1527. if (!rdev->desc->ops->get_mode) {
  1528. ret = -EINVAL;
  1529. goto out;
  1530. }
  1531. ret = rdev->desc->ops->get_mode(rdev);
  1532. out:
  1533. mutex_unlock(&rdev->mutex);
  1534. return ret;
  1535. }
  1536. /**
  1537. * regulator_get_mode - get regulator operating mode
  1538. * @regulator: regulator source
  1539. *
  1540. * Get the current regulator operating mode.
  1541. */
  1542. unsigned int regulator_get_mode(struct regulator *regulator)
  1543. {
  1544. return _regulator_get_mode(regulator->rdev);
  1545. }
  1546. EXPORT_SYMBOL_GPL(regulator_get_mode);
  1547. /**
  1548. * regulator_set_optimum_mode - set regulator optimum operating mode
  1549. * @regulator: regulator source
  1550. * @uA_load: load current
  1551. *
  1552. * Notifies the regulator core of a new device load. This is then used by
  1553. * DRMS (if enabled by constraints) to set the most efficient regulator
  1554. * operating mode for the new regulator loading.
  1555. *
  1556. * Consumer devices notify their supply regulator of the maximum power
  1557. * they will require (can be taken from device datasheet in the power
  1558. * consumption tables) when they change operational status and hence power
  1559. * state. Examples of operational state changes that can affect power
  1560. * consumption are :-
  1561. *
  1562. * o Device is opened / closed.
  1563. * o Device I/O is about to begin or has just finished.
  1564. * o Device is idling in between work.
  1565. *
  1566. * This information is also exported via sysfs to userspace.
  1567. *
  1568. * DRMS will sum the total requested load on the regulator and change
  1569. * to the most efficient operating mode if platform constraints allow.
  1570. *
  1571. * Returns the new regulator mode or error.
  1572. */
  1573. int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
  1574. {
  1575. struct regulator_dev *rdev = regulator->rdev;
  1576. struct regulator *consumer;
  1577. int ret, output_uV, input_uV, total_uA_load = 0;
  1578. unsigned int mode;
  1579. mutex_lock(&rdev->mutex);
  1580. regulator->uA_load = uA_load;
  1581. ret = regulator_check_drms(rdev);
  1582. if (ret < 0)
  1583. goto out;
  1584. ret = -EINVAL;
  1585. /* sanity check */
  1586. if (!rdev->desc->ops->get_optimum_mode)
  1587. goto out;
  1588. /* get output voltage */
  1589. output_uV = rdev->desc->ops->get_voltage(rdev);
  1590. if (output_uV <= 0) {
  1591. printk(KERN_ERR "%s: invalid output voltage found for %s\n",
  1592. __func__, rdev_get_name(rdev));
  1593. goto out;
  1594. }
  1595. /* get input voltage */
  1596. if (rdev->supply && rdev->supply->desc->ops->get_voltage)
  1597. input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply);
  1598. else
  1599. input_uV = rdev->constraints->input_uV;
  1600. if (input_uV <= 0) {
  1601. printk(KERN_ERR "%s: invalid input voltage found for %s\n",
  1602. __func__, rdev_get_name(rdev));
  1603. goto out;
  1604. }
  1605. /* calc total requested load for this regulator */
  1606. list_for_each_entry(consumer, &rdev->consumer_list, list)
  1607. total_uA_load += consumer->uA_load;
  1608. mode = rdev->desc->ops->get_optimum_mode(rdev,
  1609. input_uV, output_uV,
  1610. total_uA_load);
  1611. ret = regulator_check_mode(rdev, mode);
  1612. if (ret < 0) {
  1613. printk(KERN_ERR "%s: failed to get optimum mode for %s @"
  1614. " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev),
  1615. total_uA_load, input_uV, output_uV);
  1616. goto out;
  1617. }
  1618. ret = rdev->desc->ops->set_mode(rdev, mode);
  1619. if (ret < 0) {
  1620. printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n",
  1621. __func__, mode, rdev_get_name(rdev));
  1622. goto out;
  1623. }
  1624. ret = mode;
  1625. out:
  1626. mutex_unlock(&rdev->mutex);
  1627. return ret;
  1628. }
  1629. EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
  1630. /**
  1631. * regulator_register_notifier - register regulator event notifier
  1632. * @regulator: regulator source
  1633. * @nb: notifier block
  1634. *
  1635. * Register notifier block to receive regulator events.
  1636. */
  1637. int regulator_register_notifier(struct regulator *regulator,
  1638. struct notifier_block *nb)
  1639. {
  1640. return blocking_notifier_chain_register(&regulator->rdev->notifier,
  1641. nb);
  1642. }
  1643. EXPORT_SYMBOL_GPL(regulator_register_notifier);
  1644. /**
  1645. * regulator_unregister_notifier - unregister regulator event notifier
  1646. * @regulator: regulator source
  1647. * @nb: notifier block
  1648. *
  1649. * Unregister regulator event notifier block.
  1650. */
  1651. int regulator_unregister_notifier(struct regulator *regulator,
  1652. struct notifier_block *nb)
  1653. {
  1654. return blocking_notifier_chain_unregister(&regulator->rdev->notifier,
  1655. nb);
  1656. }
  1657. EXPORT_SYMBOL_GPL(regulator_unregister_notifier);
  1658. /* notify regulator consumers and downstream regulator consumers.
  1659. * Note mutex must be held by caller.
  1660. */
  1661. static void _notifier_call_chain(struct regulator_dev *rdev,
  1662. unsigned long event, void *data)
  1663. {
  1664. struct regulator_dev *_rdev;
  1665. /* call rdev chain first */
  1666. blocking_notifier_call_chain(&rdev->notifier, event, NULL);
  1667. /* now notify regulator we supply */
  1668. list_for_each_entry(_rdev, &rdev->supply_list, slist) {
  1669. mutex_lock(&_rdev->mutex);
  1670. _notifier_call_chain(_rdev, event, data);
  1671. mutex_unlock(&_rdev->mutex);
  1672. }
  1673. }
  1674. /**
  1675. * regulator_bulk_get - get multiple regulator consumers
  1676. *
  1677. * @dev: Device to supply
  1678. * @num_consumers: Number of consumers to register
  1679. * @consumers: Configuration of consumers; clients are stored here.
  1680. *
  1681. * @return 0 on success, an errno on failure.
  1682. *
  1683. * This helper function allows drivers to get several regulator
  1684. * consumers in one operation. If any of the regulators cannot be
  1685. * acquired then any regulators that were allocated will be freed
  1686. * before returning to the caller.
  1687. */
  1688. int regulator_bulk_get(struct device *dev, int num_consumers,
  1689. struct regulator_bulk_data *consumers)
  1690. {
  1691. int i;
  1692. int ret;
  1693. for (i = 0; i < num_consumers; i++)
  1694. consumers[i].consumer = NULL;
  1695. for (i = 0; i < num_consumers; i++) {
  1696. consumers[i].consumer = regulator_get(dev,
  1697. consumers[i].supply);
  1698. if (IS_ERR(consumers[i].consumer)) {
  1699. ret = PTR_ERR(consumers[i].consumer);
  1700. dev_err(dev, "Failed to get supply '%s': %d\n",
  1701. consumers[i].supply, ret);
  1702. consumers[i].consumer = NULL;
  1703. goto err;
  1704. }
  1705. }
  1706. return 0;
  1707. err:
  1708. for (i = 0; i < num_consumers && consumers[i].consumer; i++)
  1709. regulator_put(consumers[i].consumer);
  1710. return ret;
  1711. }
  1712. EXPORT_SYMBOL_GPL(regulator_bulk_get);
  1713. /**
  1714. * regulator_bulk_enable - enable multiple regulator consumers
  1715. *
  1716. * @num_consumers: Number of consumers
  1717. * @consumers: Consumer data; clients are stored here.
  1718. * @return 0 on success, an errno on failure
  1719. *
  1720. * This convenience API allows consumers to enable multiple regulator
  1721. * clients in a single API call. If any consumers cannot be enabled
  1722. * then any others that were enabled will be disabled again prior to
  1723. * return.
  1724. */
  1725. int regulator_bulk_enable(int num_consumers,
  1726. struct regulator_bulk_data *consumers)
  1727. {
  1728. int i;
  1729. int ret;
  1730. for (i = 0; i < num_consumers; i++) {
  1731. ret = regulator_enable(consumers[i].consumer);
  1732. if (ret != 0)
  1733. goto err;
  1734. }
  1735. return 0;
  1736. err:
  1737. printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret);
  1738. for (--i; i >= 0; --i)
  1739. regulator_disable(consumers[i].consumer);
  1740. return ret;
  1741. }
  1742. EXPORT_SYMBOL_GPL(regulator_bulk_enable);
  1743. /**
  1744. * regulator_bulk_disable - disable multiple regulator consumers
  1745. *
  1746. * @num_consumers: Number of consumers
  1747. * @consumers: Consumer data; clients are stored here.
  1748. * @return 0 on success, an errno on failure
  1749. *
  1750. * This convenience API allows consumers to disable multiple regulator
  1751. * clients in a single API call. If any consumers cannot be enabled
  1752. * then any others that were disabled will be disabled again prior to
  1753. * return.
  1754. */
  1755. int regulator_bulk_disable(int num_consumers,
  1756. struct regulator_bulk_data *consumers)
  1757. {
  1758. int i;
  1759. int ret;
  1760. for (i = 0; i < num_consumers; i++) {
  1761. ret = regulator_disable(consumers[i].consumer);
  1762. if (ret != 0)
  1763. goto err;
  1764. }
  1765. return 0;
  1766. err:
  1767. printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply,
  1768. ret);
  1769. for (--i; i >= 0; --i)
  1770. regulator_enable(consumers[i].consumer);
  1771. return ret;
  1772. }
  1773. EXPORT_SYMBOL_GPL(regulator_bulk_disable);
  1774. /**
  1775. * regulator_bulk_free - free multiple regulator consumers
  1776. *
  1777. * @num_consumers: Number of consumers
  1778. * @consumers: Consumer data; clients are stored here.
  1779. *
  1780. * This convenience API allows consumers to free multiple regulator
  1781. * clients in a single API call.
  1782. */
  1783. void regulator_bulk_free(int num_consumers,
  1784. struct regulator_bulk_data *consumers)
  1785. {
  1786. int i;
  1787. for (i = 0; i < num_consumers; i++) {
  1788. regulator_put(consumers[i].consumer);
  1789. consumers[i].consumer = NULL;
  1790. }
  1791. }
  1792. EXPORT_SYMBOL_GPL(regulator_bulk_free);
  1793. /**
  1794. * regulator_notifier_call_chain - call regulator event notifier
  1795. * @rdev: regulator source
  1796. * @event: notifier block
  1797. * @data: callback-specific data.
  1798. *
  1799. * Called by regulator drivers to notify clients a regulator event has
  1800. * occurred. We also notify regulator clients downstream.
  1801. * Note lock must be held by caller.
  1802. */
  1803. int regulator_notifier_call_chain(struct regulator_dev *rdev,
  1804. unsigned long event, void *data)
  1805. {
  1806. _notifier_call_chain(rdev, event, data);
  1807. return NOTIFY_DONE;
  1808. }
  1809. EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
  1810. /**
  1811. * regulator_mode_to_status - convert a regulator mode into a status
  1812. *
  1813. * @mode: Mode to convert
  1814. *
  1815. * Convert a regulator mode into a status.
  1816. */
  1817. int regulator_mode_to_status(unsigned int mode)
  1818. {
  1819. switch (mode) {
  1820. case REGULATOR_MODE_FAST:
  1821. return REGULATOR_STATUS_FAST;
  1822. case REGULATOR_MODE_NORMAL:
  1823. return REGULATOR_STATUS_NORMAL;
  1824. case REGULATOR_MODE_IDLE:
  1825. return REGULATOR_STATUS_IDLE;
  1826. case REGULATOR_STATUS_STANDBY:
  1827. return REGULATOR_STATUS_STANDBY;
  1828. default:
  1829. return 0;
  1830. }
  1831. }
  1832. EXPORT_SYMBOL_GPL(regulator_mode_to_status);
  1833. /*
  1834. * To avoid cluttering sysfs (and memory) with useless state, only
  1835. * create attributes that can be meaningfully displayed.
  1836. */
  1837. static int add_regulator_attributes(struct regulator_dev *rdev)
  1838. {
  1839. struct device *dev = &rdev->dev;
  1840. struct regulator_ops *ops = rdev->desc->ops;
  1841. int status = 0;
  1842. /* some attributes need specific methods to be displayed */
  1843. if (ops->get_voltage) {
  1844. status = device_create_file(dev, &dev_attr_microvolts);
  1845. if (status < 0)
  1846. return status;
  1847. }
  1848. if (ops->get_current_limit) {
  1849. status = device_create_file(dev, &dev_attr_microamps);
  1850. if (status < 0)
  1851. return status;
  1852. }
  1853. if (ops->get_mode) {
  1854. status = device_create_file(dev, &dev_attr_opmode);
  1855. if (status < 0)
  1856. return status;
  1857. }
  1858. if (ops->is_enabled) {
  1859. status = device_create_file(dev, &dev_attr_state);
  1860. if (status < 0)
  1861. return status;
  1862. }
  1863. if (ops->get_status) {
  1864. status = device_create_file(dev, &dev_attr_status);
  1865. if (status < 0)
  1866. return status;
  1867. }
  1868. /* some attributes are type-specific */
  1869. if (rdev->desc->type == REGULATOR_CURRENT) {
  1870. status = device_create_file(dev, &dev_attr_requested_microamps);
  1871. if (status < 0)
  1872. return status;
  1873. }
  1874. /* all the other attributes exist to support constraints;
  1875. * don't show them if there are no constraints, or if the
  1876. * relevant supporting methods are missing.
  1877. */
  1878. if (!rdev->constraints)
  1879. return status;
  1880. /* constraints need specific supporting methods */
  1881. if (ops->set_voltage) {
  1882. status = device_create_file(dev, &dev_attr_min_microvolts);
  1883. if (status < 0)
  1884. return status;
  1885. status = device_create_file(dev, &dev_attr_max_microvolts);
  1886. if (status < 0)
  1887. return status;
  1888. }
  1889. if (ops->set_current_limit) {
  1890. status = device_create_file(dev, &dev_attr_min_microamps);
  1891. if (status < 0)
  1892. return status;
  1893. status = device_create_file(dev, &dev_attr_max_microamps);
  1894. if (status < 0)
  1895. return status;
  1896. }
  1897. /* suspend mode constraints need multiple supporting methods */
  1898. if (!(ops->set_suspend_enable && ops->set_suspend_disable))
  1899. return status;
  1900. status = device_create_file(dev, &dev_attr_suspend_standby_state);
  1901. if (status < 0)
  1902. return status;
  1903. status = device_create_file(dev, &dev_attr_suspend_mem_state);
  1904. if (status < 0)
  1905. return status;
  1906. status = device_create_file(dev, &dev_attr_suspend_disk_state);
  1907. if (status < 0)
  1908. return status;
  1909. if (ops->set_suspend_voltage) {
  1910. status = device_create_file(dev,
  1911. &dev_attr_suspend_standby_microvolts);
  1912. if (status < 0)
  1913. return status;
  1914. status = device_create_file(dev,
  1915. &dev_attr_suspend_mem_microvolts);
  1916. if (status < 0)
  1917. return status;
  1918. status = device_create_file(dev,
  1919. &dev_attr_suspend_disk_microvolts);
  1920. if (status < 0)
  1921. return status;
  1922. }
  1923. if (ops->set_suspend_mode) {
  1924. status = device_create_file(dev,
  1925. &dev_attr_suspend_standby_mode);
  1926. if (status < 0)
  1927. return status;
  1928. status = device_create_file(dev,
  1929. &dev_attr_suspend_mem_mode);
  1930. if (status < 0)
  1931. return status;
  1932. status = device_create_file(dev,
  1933. &dev_attr_suspend_disk_mode);
  1934. if (status < 0)
  1935. return status;
  1936. }
  1937. return status;
  1938. }
  1939. /**
  1940. * regulator_register - register regulator
  1941. * @regulator_desc: regulator to register
  1942. * @dev: struct device for the regulator
  1943. * @init_data: platform provided init data, passed through by driver
  1944. * @driver_data: private regulator data
  1945. *
  1946. * Called by regulator drivers to register a regulator.
  1947. * Returns 0 on success.
  1948. */
  1949. struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
  1950. struct device *dev, struct regulator_init_data *init_data,
  1951. void *driver_data)
  1952. {
  1953. static atomic_t regulator_no = ATOMIC_INIT(0);
  1954. struct regulator_dev *rdev;
  1955. int ret, i;
  1956. if (regulator_desc == NULL)
  1957. return ERR_PTR(-EINVAL);
  1958. if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
  1959. return ERR_PTR(-EINVAL);
  1960. if (regulator_desc->type != REGULATOR_VOLTAGE &&
  1961. regulator_desc->type != REGULATOR_CURRENT)
  1962. return ERR_PTR(-EINVAL);
  1963. if (!init_data)
  1964. return ERR_PTR(-EINVAL);
  1965. rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
  1966. if (rdev == NULL)
  1967. return ERR_PTR(-ENOMEM);
  1968. mutex_lock(&regulator_list_mutex);
  1969. mutex_init(&rdev->mutex);
  1970. rdev->reg_data = driver_data;
  1971. rdev->owner = regulator_desc->owner;
  1972. rdev->desc = regulator_desc;
  1973. INIT_LIST_HEAD(&rdev->consumer_list);
  1974. INIT_LIST_HEAD(&rdev->supply_list);
  1975. INIT_LIST_HEAD(&rdev->list);
  1976. INIT_LIST_HEAD(&rdev->slist);
  1977. BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
  1978. /* preform any regulator specific init */
  1979. if (init_data->regulator_init) {
  1980. ret = init_data->regulator_init(rdev->reg_data);
  1981. if (ret < 0)
  1982. goto clean;
  1983. }
  1984. /* register with sysfs */
  1985. rdev->dev.class = &regulator_class;
  1986. rdev->dev.parent = dev;
  1987. dev_set_name(&rdev->dev, "regulator.%d",
  1988. atomic_inc_return(&regulator_no) - 1);
  1989. ret = device_register(&rdev->dev);
  1990. if (ret != 0)
  1991. goto clean;
  1992. dev_set_drvdata(&rdev->dev, rdev);
  1993. /* set regulator constraints */
  1994. ret = set_machine_constraints(rdev, &init_data->constraints);
  1995. if (ret < 0)
  1996. goto scrub;
  1997. /* add attributes supported by this regulator */
  1998. ret = add_regulator_attributes(rdev);
  1999. if (ret < 0)
  2000. goto scrub;
  2001. /* set supply regulator if it exists */
  2002. if (init_data->supply_regulator && init_data->supply_regulator_dev) {
  2003. dev_err(dev,
  2004. "Supply regulator specified by both name and dev\n");
  2005. goto scrub;
  2006. }
  2007. if (init_data->supply_regulator) {
  2008. struct regulator_dev *r;
  2009. int found = 0;
  2010. list_for_each_entry(r, &regulator_list, list) {
  2011. if (strcmp(rdev_get_name(r),
  2012. init_data->supply_regulator) == 0) {
  2013. found = 1;
  2014. break;
  2015. }
  2016. }
  2017. if (!found) {
  2018. dev_err(dev, "Failed to find supply %s\n",
  2019. init_data->supply_regulator);
  2020. goto scrub;
  2021. }
  2022. ret = set_supply(rdev, r);
  2023. if (ret < 0)
  2024. goto scrub;
  2025. }
  2026. if (init_data->supply_regulator_dev) {
  2027. dev_warn(dev, "Uses supply_regulator_dev instead of regulator_supply\n");
  2028. ret = set_supply(rdev,
  2029. dev_get_drvdata(init_data->supply_regulator_dev));
  2030. if (ret < 0)
  2031. goto scrub;
  2032. }
  2033. /* add consumers devices */
  2034. for (i = 0; i < init_data->num_consumer_supplies; i++) {
  2035. ret = set_consumer_device_supply(rdev,
  2036. init_data->consumer_supplies[i].dev,
  2037. init_data->consumer_supplies[i].dev_name,
  2038. init_data->consumer_supplies[i].supply);
  2039. if (ret < 0)
  2040. goto unset_supplies;
  2041. }
  2042. list_add(&rdev->list, &regulator_list);
  2043. out:
  2044. mutex_unlock(&regulator_list_mutex);
  2045. return rdev;
  2046. unset_supplies:
  2047. unset_regulator_supplies(rdev);
  2048. scrub:
  2049. device_unregister(&rdev->dev);
  2050. /* device core frees rdev */
  2051. rdev = ERR_PTR(ret);
  2052. goto out;
  2053. clean:
  2054. kfree(rdev);
  2055. rdev = ERR_PTR(ret);
  2056. goto out;
  2057. }
  2058. EXPORT_SYMBOL_GPL(regulator_register);
  2059. /**
  2060. * regulator_unregister - unregister regulator
  2061. * @rdev: regulator to unregister
  2062. *
  2063. * Called by regulator drivers to unregister a regulator.
  2064. */
  2065. void regulator_unregister(struct regulator_dev *rdev)
  2066. {
  2067. if (rdev == NULL)
  2068. return;
  2069. mutex_lock(&regulator_list_mutex);
  2070. WARN_ON(rdev->open_count);
  2071. unset_regulator_supplies(rdev);
  2072. list_del(&rdev->list);
  2073. if (rdev->supply)
  2074. sysfs_remove_link(&rdev->dev.kobj, "supply");
  2075. device_unregister(&rdev->dev);
  2076. mutex_unlock(&regulator_list_mutex);
  2077. }
  2078. EXPORT_SYMBOL_GPL(regulator_unregister);
  2079. /**
  2080. * regulator_suspend_prepare - prepare regulators for system wide suspend
  2081. * @state: system suspend state
  2082. *
  2083. * Configure each regulator with it's suspend operating parameters for state.
  2084. * This will usually be called by machine suspend code prior to supending.
  2085. */
  2086. int regulator_suspend_prepare(suspend_state_t state)
  2087. {
  2088. struct regulator_dev *rdev;
  2089. int ret = 0;
  2090. /* ON is handled by regulator active state */
  2091. if (state == PM_SUSPEND_ON)
  2092. return -EINVAL;
  2093. mutex_lock(&regulator_list_mutex);
  2094. list_for_each_entry(rdev, &regulator_list, list) {
  2095. mutex_lock(&rdev->mutex);
  2096. ret = suspend_prepare(rdev, state);
  2097. mutex_unlock(&rdev->mutex);
  2098. if (ret < 0) {
  2099. printk(KERN_ERR "%s: failed to prepare %s\n",
  2100. __func__, rdev_get_name(rdev));
  2101. goto out;
  2102. }
  2103. }
  2104. out:
  2105. mutex_unlock(&regulator_list_mutex);
  2106. return ret;
  2107. }
  2108. EXPORT_SYMBOL_GPL(regulator_suspend_prepare);
  2109. /**
  2110. * regulator_has_full_constraints - the system has fully specified constraints
  2111. *
  2112. * Calling this function will cause the regulator API to disable all
  2113. * regulators which have a zero use count and don't have an always_on
  2114. * constraint in a late_initcall.
  2115. *
  2116. * The intention is that this will become the default behaviour in a
  2117. * future kernel release so users are encouraged to use this facility
  2118. * now.
  2119. */
  2120. void regulator_has_full_constraints(void)
  2121. {
  2122. has_full_constraints = 1;
  2123. }
  2124. EXPORT_SYMBOL_GPL(regulator_has_full_constraints);
  2125. /**
  2126. * rdev_get_drvdata - get rdev regulator driver data
  2127. * @rdev: regulator
  2128. *
  2129. * Get rdev regulator driver private data. This call can be used in the
  2130. * regulator driver context.
  2131. */
  2132. void *rdev_get_drvdata(struct regulator_dev *rdev)
  2133. {
  2134. return rdev->reg_data;
  2135. }
  2136. EXPORT_SYMBOL_GPL(rdev_get_drvdata);
  2137. /**
  2138. * regulator_get_drvdata - get regulator driver data
  2139. * @regulator: regulator
  2140. *
  2141. * Get regulator driver private data. This call can be used in the consumer
  2142. * driver context when non API regulator specific functions need to be called.
  2143. */
  2144. void *regulator_get_drvdata(struct regulator *regulator)
  2145. {
  2146. return regulator->rdev->reg_data;
  2147. }
  2148. EXPORT_SYMBOL_GPL(regulator_get_drvdata);
  2149. /**
  2150. * regulator_set_drvdata - set regulator driver data
  2151. * @regulator: regulator
  2152. * @data: data
  2153. */
  2154. void regulator_set_drvdata(struct regulator *regulator, void *data)
  2155. {
  2156. regulator->rdev->reg_data = data;
  2157. }
  2158. EXPORT_SYMBOL_GPL(regulator_set_drvdata);
  2159. /**
  2160. * regulator_get_id - get regulator ID
  2161. * @rdev: regulator
  2162. */
  2163. int rdev_get_id(struct regulator_dev *rdev)
  2164. {
  2165. return rdev->desc->id;
  2166. }
  2167. EXPORT_SYMBOL_GPL(rdev_get_id);
  2168. struct device *rdev_get_dev(struct regulator_dev *rdev)
  2169. {
  2170. return &rdev->dev;
  2171. }
  2172. EXPORT_SYMBOL_GPL(rdev_get_dev);
  2173. void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
  2174. {
  2175. return reg_init_data->driver_data;
  2176. }
  2177. EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
  2178. static int __init regulator_init(void)
  2179. {
  2180. int ret;
  2181. printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
  2182. ret = class_register(&regulator_class);
  2183. regulator_dummy_init();
  2184. return ret;
  2185. }
  2186. /* init early to allow our consumers to complete system booting */
  2187. core_initcall(regulator_init);
  2188. static int __init regulator_init_complete(void)
  2189. {
  2190. struct regulator_dev *rdev;
  2191. struct regulator_ops *ops;
  2192. struct regulation_constraints *c;
  2193. int enabled, ret;
  2194. const char *name;
  2195. mutex_lock(&regulator_list_mutex);
  2196. /* If we have a full configuration then disable any regulators
  2197. * which are not in use or always_on. This will become the
  2198. * default behaviour in the future.
  2199. */
  2200. list_for_each_entry(rdev, &regulator_list, list) {
  2201. ops = rdev->desc->ops;
  2202. c = rdev->constraints;
  2203. name = rdev_get_name(rdev);
  2204. if (!ops->disable || (c && c->always_on))
  2205. continue;
  2206. mutex_lock(&rdev->mutex);
  2207. if (rdev->use_count)
  2208. goto unlock;
  2209. /* If we can't read the status assume it's on. */
  2210. if (ops->is_enabled)
  2211. enabled = ops->is_enabled(rdev);
  2212. else
  2213. enabled = 1;
  2214. if (!enabled)
  2215. goto unlock;
  2216. if (has_full_constraints) {
  2217. /* We log since this may kill the system if it
  2218. * goes wrong. */
  2219. printk(KERN_INFO "%s: disabling %s\n",
  2220. __func__, name);
  2221. ret = ops->disable(rdev);
  2222. if (ret != 0) {
  2223. printk(KERN_ERR
  2224. "%s: couldn't disable %s: %d\n",
  2225. __func__, name, ret);
  2226. }
  2227. } else {
  2228. /* The intention is that in future we will
  2229. * assume that full constraints are provided
  2230. * so warn even if we aren't going to do
  2231. * anything here.
  2232. */
  2233. printk(KERN_WARNING
  2234. "%s: incomplete constraints, leaving %s on\n",
  2235. __func__, name);
  2236. }
  2237. unlock:
  2238. mutex_unlock(&rdev->mutex);
  2239. }
  2240. mutex_unlock(&regulator_list_mutex);
  2241. return 0;
  2242. }
  2243. late_initcall(regulator_init_complete);