core.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949
  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/err.h>
  19. #include <linux/mutex.h>
  20. #include <linux/suspend.h>
  21. #include <linux/regulator/consumer.h>
  22. #include <linux/regulator/driver.h>
  23. #include <linux/regulator/machine.h>
  24. #define REGULATOR_VERSION "0.5"
  25. static DEFINE_MUTEX(regulator_list_mutex);
  26. static LIST_HEAD(regulator_list);
  27. static LIST_HEAD(regulator_map_list);
  28. /**
  29. * struct regulator_dev
  30. *
  31. * Voltage / Current regulator class device. One for each regulator.
  32. */
  33. struct regulator_dev {
  34. struct regulator_desc *desc;
  35. int use_count;
  36. /* lists we belong to */
  37. struct list_head list; /* list of all regulators */
  38. struct list_head slist; /* list of supplied regulators */
  39. /* lists we own */
  40. struct list_head consumer_list; /* consumers we supply */
  41. struct list_head supply_list; /* regulators we supply */
  42. struct blocking_notifier_head notifier;
  43. struct mutex mutex; /* consumer lock */
  44. struct module *owner;
  45. struct device dev;
  46. struct regulation_constraints *constraints;
  47. struct regulator_dev *supply; /* for tree */
  48. void *reg_data; /* regulator_dev data */
  49. };
  50. /**
  51. * struct regulator_map
  52. *
  53. * Used to provide symbolic supply names to devices.
  54. */
  55. struct regulator_map {
  56. struct list_head list;
  57. struct device *dev;
  58. const char *supply;
  59. struct regulator_dev *regulator;
  60. };
  61. /*
  62. * struct regulator
  63. *
  64. * One for each consumer device.
  65. */
  66. struct regulator {
  67. struct device *dev;
  68. struct list_head list;
  69. int uA_load;
  70. int min_uV;
  71. int max_uV;
  72. int enabled; /* client has called enabled */
  73. char *supply_name;
  74. struct device_attribute dev_attr;
  75. struct regulator_dev *rdev;
  76. };
  77. static int _regulator_is_enabled(struct regulator_dev *rdev);
  78. static int _regulator_disable(struct regulator_dev *rdev);
  79. static int _regulator_get_voltage(struct regulator_dev *rdev);
  80. static int _regulator_get_current_limit(struct regulator_dev *rdev);
  81. static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
  82. static void _notifier_call_chain(struct regulator_dev *rdev,
  83. unsigned long event, void *data);
  84. /* gets the regulator for a given consumer device */
  85. static struct regulator *get_device_regulator(struct device *dev)
  86. {
  87. struct regulator *regulator = NULL;
  88. struct regulator_dev *rdev;
  89. mutex_lock(&regulator_list_mutex);
  90. list_for_each_entry(rdev, &regulator_list, list) {
  91. mutex_lock(&rdev->mutex);
  92. list_for_each_entry(regulator, &rdev->consumer_list, list) {
  93. if (regulator->dev == dev) {
  94. mutex_unlock(&rdev->mutex);
  95. mutex_unlock(&regulator_list_mutex);
  96. return regulator;
  97. }
  98. }
  99. mutex_unlock(&rdev->mutex);
  100. }
  101. mutex_unlock(&regulator_list_mutex);
  102. return NULL;
  103. }
  104. /* Platform voltage constraint check */
  105. static int regulator_check_voltage(struct regulator_dev *rdev,
  106. int *min_uV, int *max_uV)
  107. {
  108. BUG_ON(*min_uV > *max_uV);
  109. if (!rdev->constraints) {
  110. printk(KERN_ERR "%s: no constraints for %s\n", __func__,
  111. rdev->desc->name);
  112. return -ENODEV;
  113. }
  114. if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
  115. printk(KERN_ERR "%s: operation not allowed for %s\n",
  116. __func__, rdev->desc->name);
  117. return -EPERM;
  118. }
  119. if (*max_uV > rdev->constraints->max_uV)
  120. *max_uV = rdev->constraints->max_uV;
  121. if (*min_uV < rdev->constraints->min_uV)
  122. *min_uV = rdev->constraints->min_uV;
  123. if (*min_uV > *max_uV)
  124. return -EINVAL;
  125. return 0;
  126. }
  127. /* current constraint check */
  128. static int regulator_check_current_limit(struct regulator_dev *rdev,
  129. int *min_uA, int *max_uA)
  130. {
  131. BUG_ON(*min_uA > *max_uA);
  132. if (!rdev->constraints) {
  133. printk(KERN_ERR "%s: no constraints for %s\n", __func__,
  134. rdev->desc->name);
  135. return -ENODEV;
  136. }
  137. if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
  138. printk(KERN_ERR "%s: operation not allowed for %s\n",
  139. __func__, rdev->desc->name);
  140. return -EPERM;
  141. }
  142. if (*max_uA > rdev->constraints->max_uA)
  143. *max_uA = rdev->constraints->max_uA;
  144. if (*min_uA < rdev->constraints->min_uA)
  145. *min_uA = rdev->constraints->min_uA;
  146. if (*min_uA > *max_uA)
  147. return -EINVAL;
  148. return 0;
  149. }
  150. /* operating mode constraint check */
  151. static int regulator_check_mode(struct regulator_dev *rdev, int mode)
  152. {
  153. if (!rdev->constraints) {
  154. printk(KERN_ERR "%s: no constraints for %s\n", __func__,
  155. rdev->desc->name);
  156. return -ENODEV;
  157. }
  158. if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
  159. printk(KERN_ERR "%s: operation not allowed for %s\n",
  160. __func__, rdev->desc->name);
  161. return -EPERM;
  162. }
  163. if (!(rdev->constraints->valid_modes_mask & mode)) {
  164. printk(KERN_ERR "%s: invalid mode %x for %s\n",
  165. __func__, mode, rdev->desc->name);
  166. return -EINVAL;
  167. }
  168. return 0;
  169. }
  170. /* dynamic regulator mode switching constraint check */
  171. static int regulator_check_drms(struct regulator_dev *rdev)
  172. {
  173. if (!rdev->constraints) {
  174. printk(KERN_ERR "%s: no constraints for %s\n", __func__,
  175. rdev->desc->name);
  176. return -ENODEV;
  177. }
  178. if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
  179. printk(KERN_ERR "%s: operation not allowed for %s\n",
  180. __func__, rdev->desc->name);
  181. return -EPERM;
  182. }
  183. return 0;
  184. }
  185. static ssize_t device_requested_uA_show(struct device *dev,
  186. struct device_attribute *attr, char *buf)
  187. {
  188. struct regulator *regulator;
  189. regulator = get_device_regulator(dev);
  190. if (regulator == NULL)
  191. return 0;
  192. return sprintf(buf, "%d\n", regulator->uA_load);
  193. }
  194. static ssize_t regulator_uV_show(struct device *dev,
  195. struct device_attribute *attr, char *buf)
  196. {
  197. struct regulator_dev *rdev = dev_get_drvdata(dev);
  198. ssize_t ret;
  199. mutex_lock(&rdev->mutex);
  200. ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev));
  201. mutex_unlock(&rdev->mutex);
  202. return ret;
  203. }
  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 ssize_t regulator_name_show(struct device *dev,
  211. struct device_attribute *attr, char *buf)
  212. {
  213. struct regulator_dev *rdev = dev_get_drvdata(dev);
  214. const char *name;
  215. if (rdev->constraints->name)
  216. name = rdev->constraints->name;
  217. else if (rdev->desc->name)
  218. name = rdev->desc->name;
  219. else
  220. name = "";
  221. return sprintf(buf, "%s\n", name);
  222. }
  223. static ssize_t regulator_opmode_show(struct device *dev,
  224. struct device_attribute *attr, char *buf)
  225. {
  226. struct regulator_dev *rdev = dev_get_drvdata(dev);
  227. int mode = _regulator_get_mode(rdev);
  228. switch (mode) {
  229. case REGULATOR_MODE_FAST:
  230. return sprintf(buf, "fast\n");
  231. case REGULATOR_MODE_NORMAL:
  232. return sprintf(buf, "normal\n");
  233. case REGULATOR_MODE_IDLE:
  234. return sprintf(buf, "idle\n");
  235. case REGULATOR_MODE_STANDBY:
  236. return sprintf(buf, "standby\n");
  237. }
  238. return sprintf(buf, "unknown\n");
  239. }
  240. static ssize_t regulator_state_show(struct device *dev,
  241. struct device_attribute *attr, char *buf)
  242. {
  243. struct regulator_dev *rdev = dev_get_drvdata(dev);
  244. int state = _regulator_is_enabled(rdev);
  245. if (state > 0)
  246. return sprintf(buf, "enabled\n");
  247. else if (state == 0)
  248. return sprintf(buf, "disabled\n");
  249. else
  250. return sprintf(buf, "unknown\n");
  251. }
  252. static ssize_t regulator_min_uA_show(struct device *dev,
  253. struct device_attribute *attr, char *buf)
  254. {
  255. struct regulator_dev *rdev = dev_get_drvdata(dev);
  256. if (!rdev->constraints)
  257. return sprintf(buf, "constraint not defined\n");
  258. return sprintf(buf, "%d\n", rdev->constraints->min_uA);
  259. }
  260. static ssize_t regulator_max_uA_show(struct device *dev,
  261. struct device_attribute *attr, char *buf)
  262. {
  263. struct regulator_dev *rdev = dev_get_drvdata(dev);
  264. if (!rdev->constraints)
  265. return sprintf(buf, "constraint not defined\n");
  266. return sprintf(buf, "%d\n", rdev->constraints->max_uA);
  267. }
  268. static ssize_t regulator_min_uV_show(struct device *dev,
  269. struct device_attribute *attr, char *buf)
  270. {
  271. struct regulator_dev *rdev = dev_get_drvdata(dev);
  272. if (!rdev->constraints)
  273. return sprintf(buf, "constraint not defined\n");
  274. return sprintf(buf, "%d\n", rdev->constraints->min_uV);
  275. }
  276. static ssize_t regulator_max_uV_show(struct device *dev,
  277. struct device_attribute *attr, char *buf)
  278. {
  279. struct regulator_dev *rdev = dev_get_drvdata(dev);
  280. if (!rdev->constraints)
  281. return sprintf(buf, "constraint not defined\n");
  282. return sprintf(buf, "%d\n", rdev->constraints->max_uV);
  283. }
  284. static ssize_t regulator_total_uA_show(struct device *dev,
  285. struct device_attribute *attr, char *buf)
  286. {
  287. struct regulator_dev *rdev = dev_get_drvdata(dev);
  288. struct regulator *regulator;
  289. int uA = 0;
  290. mutex_lock(&rdev->mutex);
  291. list_for_each_entry(regulator, &rdev->consumer_list, list)
  292. uA += regulator->uA_load;
  293. mutex_unlock(&rdev->mutex);
  294. return sprintf(buf, "%d\n", uA);
  295. }
  296. static ssize_t regulator_num_users_show(struct device *dev,
  297. struct device_attribute *attr, char *buf)
  298. {
  299. struct regulator_dev *rdev = dev_get_drvdata(dev);
  300. return sprintf(buf, "%d\n", rdev->use_count);
  301. }
  302. static ssize_t regulator_type_show(struct device *dev,
  303. struct device_attribute *attr, char *buf)
  304. {
  305. struct regulator_dev *rdev = dev_get_drvdata(dev);
  306. switch (rdev->desc->type) {
  307. case REGULATOR_VOLTAGE:
  308. return sprintf(buf, "voltage\n");
  309. case REGULATOR_CURRENT:
  310. return sprintf(buf, "current\n");
  311. }
  312. return sprintf(buf, "unknown\n");
  313. }
  314. static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
  315. struct device_attribute *attr, char *buf)
  316. {
  317. struct regulator_dev *rdev = dev_get_drvdata(dev);
  318. if (!rdev->constraints)
  319. return sprintf(buf, "not defined\n");
  320. return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV);
  321. }
  322. static ssize_t regulator_suspend_disk_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, "not defined\n");
  328. return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV);
  329. }
  330. static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
  331. struct device_attribute *attr, char *buf)
  332. {
  333. struct regulator_dev *rdev = dev_get_drvdata(dev);
  334. if (!rdev->constraints)
  335. return sprintf(buf, "not defined\n");
  336. return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV);
  337. }
  338. static ssize_t suspend_opmode_show(struct regulator_dev *rdev,
  339. unsigned int mode, char *buf)
  340. {
  341. switch (mode) {
  342. case REGULATOR_MODE_FAST:
  343. return sprintf(buf, "fast\n");
  344. case REGULATOR_MODE_NORMAL:
  345. return sprintf(buf, "normal\n");
  346. case REGULATOR_MODE_IDLE:
  347. return sprintf(buf, "idle\n");
  348. case REGULATOR_MODE_STANDBY:
  349. return sprintf(buf, "standby\n");
  350. }
  351. return sprintf(buf, "unknown\n");
  352. }
  353. static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
  354. struct device_attribute *attr, char *buf)
  355. {
  356. struct regulator_dev *rdev = dev_get_drvdata(dev);
  357. if (!rdev->constraints)
  358. return sprintf(buf, "not defined\n");
  359. return suspend_opmode_show(rdev,
  360. rdev->constraints->state_mem.mode, buf);
  361. }
  362. static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
  363. struct device_attribute *attr, char *buf)
  364. {
  365. struct regulator_dev *rdev = dev_get_drvdata(dev);
  366. if (!rdev->constraints)
  367. return sprintf(buf, "not defined\n");
  368. return suspend_opmode_show(rdev,
  369. rdev->constraints->state_disk.mode, buf);
  370. }
  371. static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
  372. struct device_attribute *attr, char *buf)
  373. {
  374. struct regulator_dev *rdev = dev_get_drvdata(dev);
  375. if (!rdev->constraints)
  376. return sprintf(buf, "not defined\n");
  377. return suspend_opmode_show(rdev,
  378. rdev->constraints->state_standby.mode, buf);
  379. }
  380. static ssize_t regulator_suspend_mem_state_show(struct device *dev,
  381. struct device_attribute *attr, char *buf)
  382. {
  383. struct regulator_dev *rdev = dev_get_drvdata(dev);
  384. if (!rdev->constraints)
  385. return sprintf(buf, "not defined\n");
  386. if (rdev->constraints->state_mem.enabled)
  387. return sprintf(buf, "enabled\n");
  388. else
  389. return sprintf(buf, "disabled\n");
  390. }
  391. static ssize_t regulator_suspend_disk_state_show(struct device *dev,
  392. struct device_attribute *attr, char *buf)
  393. {
  394. struct regulator_dev *rdev = dev_get_drvdata(dev);
  395. if (!rdev->constraints)
  396. return sprintf(buf, "not defined\n");
  397. if (rdev->constraints->state_disk.enabled)
  398. return sprintf(buf, "enabled\n");
  399. else
  400. return sprintf(buf, "disabled\n");
  401. }
  402. static ssize_t regulator_suspend_standby_state_show(struct device *dev,
  403. struct device_attribute *attr, char *buf)
  404. {
  405. struct regulator_dev *rdev = dev_get_drvdata(dev);
  406. if (!rdev->constraints)
  407. return sprintf(buf, "not defined\n");
  408. if (rdev->constraints->state_standby.enabled)
  409. return sprintf(buf, "enabled\n");
  410. else
  411. return sprintf(buf, "disabled\n");
  412. }
  413. static struct device_attribute regulator_dev_attrs[] = {
  414. __ATTR(name, 0444, regulator_name_show, NULL),
  415. __ATTR(microvolts, 0444, regulator_uV_show, NULL),
  416. __ATTR(microamps, 0444, regulator_uA_show, NULL),
  417. __ATTR(opmode, 0444, regulator_opmode_show, NULL),
  418. __ATTR(state, 0444, regulator_state_show, NULL),
  419. __ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL),
  420. __ATTR(min_microamps, 0444, regulator_min_uA_show, NULL),
  421. __ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL),
  422. __ATTR(max_microamps, 0444, regulator_max_uA_show, NULL),
  423. __ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL),
  424. __ATTR(num_users, 0444, regulator_num_users_show, NULL),
  425. __ATTR(type, 0444, regulator_type_show, NULL),
  426. __ATTR(suspend_mem_microvolts, 0444,
  427. regulator_suspend_mem_uV_show, NULL),
  428. __ATTR(suspend_disk_microvolts, 0444,
  429. regulator_suspend_disk_uV_show, NULL),
  430. __ATTR(suspend_standby_microvolts, 0444,
  431. regulator_suspend_standby_uV_show, NULL),
  432. __ATTR(suspend_mem_mode, 0444,
  433. regulator_suspend_mem_mode_show, NULL),
  434. __ATTR(suspend_disk_mode, 0444,
  435. regulator_suspend_disk_mode_show, NULL),
  436. __ATTR(suspend_standby_mode, 0444,
  437. regulator_suspend_standby_mode_show, NULL),
  438. __ATTR(suspend_mem_state, 0444,
  439. regulator_suspend_mem_state_show, NULL),
  440. __ATTR(suspend_disk_state, 0444,
  441. regulator_suspend_disk_state_show, NULL),
  442. __ATTR(suspend_standby_state, 0444,
  443. regulator_suspend_standby_state_show, NULL),
  444. __ATTR_NULL,
  445. };
  446. static void regulator_dev_release(struct device *dev)
  447. {
  448. struct regulator_dev *rdev = dev_get_drvdata(dev);
  449. kfree(rdev);
  450. }
  451. static struct class regulator_class = {
  452. .name = "regulator",
  453. .dev_release = regulator_dev_release,
  454. .dev_attrs = regulator_dev_attrs,
  455. };
  456. /* Calculate the new optimum regulator operating mode based on the new total
  457. * consumer load. All locks held by caller */
  458. static void drms_uA_update(struct regulator_dev *rdev)
  459. {
  460. struct regulator *sibling;
  461. int current_uA = 0, output_uV, input_uV, err;
  462. unsigned int mode;
  463. err = regulator_check_drms(rdev);
  464. if (err < 0 || !rdev->desc->ops->get_optimum_mode ||
  465. !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode);
  466. return;
  467. /* get output voltage */
  468. output_uV = rdev->desc->ops->get_voltage(rdev);
  469. if (output_uV <= 0)
  470. return;
  471. /* get input voltage */
  472. if (rdev->supply && rdev->supply->desc->ops->get_voltage)
  473. input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply);
  474. else
  475. input_uV = rdev->constraints->input_uV;
  476. if (input_uV <= 0)
  477. return;
  478. /* calc total requested load */
  479. list_for_each_entry(sibling, &rdev->consumer_list, list)
  480. current_uA += sibling->uA_load;
  481. /* now get the optimum mode for our new total regulator load */
  482. mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV,
  483. output_uV, current_uA);
  484. /* check the new mode is allowed */
  485. err = regulator_check_mode(rdev, mode);
  486. if (err == 0)
  487. rdev->desc->ops->set_mode(rdev, mode);
  488. }
  489. static int suspend_set_state(struct regulator_dev *rdev,
  490. struct regulator_state *rstate)
  491. {
  492. int ret = 0;
  493. /* enable & disable are mandatory for suspend control */
  494. if (!rdev->desc->ops->set_suspend_enable ||
  495. !rdev->desc->ops->set_suspend_disable) {
  496. printk(KERN_ERR "%s: no way to set suspend state\n",
  497. __func__);
  498. return -EINVAL;
  499. }
  500. if (rstate->enabled)
  501. ret = rdev->desc->ops->set_suspend_enable(rdev);
  502. else
  503. ret = rdev->desc->ops->set_suspend_disable(rdev);
  504. if (ret < 0) {
  505. printk(KERN_ERR "%s: failed to enabled/disable\n", __func__);
  506. return ret;
  507. }
  508. if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) {
  509. ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV);
  510. if (ret < 0) {
  511. printk(KERN_ERR "%s: failed to set voltage\n",
  512. __func__);
  513. return ret;
  514. }
  515. }
  516. if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) {
  517. ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode);
  518. if (ret < 0) {
  519. printk(KERN_ERR "%s: failed to set mode\n", __func__);
  520. return ret;
  521. }
  522. }
  523. return ret;
  524. }
  525. /* locks held by caller */
  526. static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state)
  527. {
  528. if (!rdev->constraints)
  529. return -EINVAL;
  530. switch (state) {
  531. case PM_SUSPEND_STANDBY:
  532. return suspend_set_state(rdev,
  533. &rdev->constraints->state_standby);
  534. case PM_SUSPEND_MEM:
  535. return suspend_set_state(rdev,
  536. &rdev->constraints->state_mem);
  537. case PM_SUSPEND_MAX:
  538. return suspend_set_state(rdev,
  539. &rdev->constraints->state_disk);
  540. default:
  541. return -EINVAL;
  542. }
  543. }
  544. static void print_constraints(struct regulator_dev *rdev)
  545. {
  546. struct regulation_constraints *constraints = rdev->constraints;
  547. char buf[80];
  548. int count;
  549. if (rdev->desc->type == REGULATOR_VOLTAGE) {
  550. if (constraints->min_uV == constraints->max_uV)
  551. count = sprintf(buf, "%d mV ",
  552. constraints->min_uV / 1000);
  553. else
  554. count = sprintf(buf, "%d <--> %d mV ",
  555. constraints->min_uV / 1000,
  556. constraints->max_uV / 1000);
  557. } else {
  558. if (constraints->min_uA == constraints->max_uA)
  559. count = sprintf(buf, "%d mA ",
  560. constraints->min_uA / 1000);
  561. else
  562. count = sprintf(buf, "%d <--> %d mA ",
  563. constraints->min_uA / 1000,
  564. constraints->max_uA / 1000);
  565. }
  566. if (constraints->valid_modes_mask & REGULATOR_MODE_FAST)
  567. count += sprintf(buf + count, "fast ");
  568. if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL)
  569. count += sprintf(buf + count, "normal ");
  570. if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE)
  571. count += sprintf(buf + count, "idle ");
  572. if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
  573. count += sprintf(buf + count, "standby");
  574. printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf);
  575. }
  576. /**
  577. * set_machine_constraints - sets regulator constraints
  578. * @regulator: regulator source
  579. *
  580. * Allows platform initialisation code to define and constrain
  581. * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
  582. * Constraints *must* be set by platform code in order for some
  583. * regulator operations to proceed i.e. set_voltage, set_current_limit,
  584. * set_mode.
  585. */
  586. static int set_machine_constraints(struct regulator_dev *rdev,
  587. struct regulation_constraints *constraints)
  588. {
  589. int ret = 0;
  590. const char *name;
  591. struct regulator_ops *ops = rdev->desc->ops;
  592. if (constraints->name)
  593. name = constraints->name;
  594. else if (rdev->desc->name)
  595. name = rdev->desc->name;
  596. else
  597. name = "regulator";
  598. rdev->constraints = constraints;
  599. /* do we need to apply the constraint voltage */
  600. if (rdev->constraints->apply_uV &&
  601. rdev->constraints->min_uV == rdev->constraints->max_uV &&
  602. ops->set_voltage) {
  603. ret = ops->set_voltage(rdev,
  604. rdev->constraints->min_uV, rdev->constraints->max_uV);
  605. if (ret < 0) {
  606. printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
  607. __func__,
  608. rdev->constraints->min_uV, name);
  609. rdev->constraints = NULL;
  610. goto out;
  611. }
  612. }
  613. /* are we enabled at boot time by firmware / bootloader */
  614. if (rdev->constraints->boot_on)
  615. rdev->use_count = 1;
  616. /* do we need to setup our suspend state */
  617. if (constraints->initial_state) {
  618. ret = suspend_prepare(rdev, constraints->initial_state);
  619. if (ret < 0) {
  620. printk(KERN_ERR "%s: failed to set suspend state for %s\n",
  621. __func__, name);
  622. rdev->constraints = NULL;
  623. goto out;
  624. }
  625. }
  626. /* if always_on is set then turn the regulator on if it's not
  627. * already on. */
  628. if (constraints->always_on && ops->enable &&
  629. ((ops->is_enabled && !ops->is_enabled(rdev)) ||
  630. (!ops->is_enabled && !constraints->boot_on))) {
  631. ret = ops->enable(rdev);
  632. if (ret < 0) {
  633. printk(KERN_ERR "%s: failed to enable %s\n",
  634. __func__, name);
  635. rdev->constraints = NULL;
  636. goto out;
  637. }
  638. }
  639. print_constraints(rdev);
  640. out:
  641. return ret;
  642. }
  643. /**
  644. * set_supply - set regulator supply regulator
  645. * @regulator: regulator name
  646. * @supply: supply regulator name
  647. *
  648. * Called by platform initialisation code to set the supply regulator for this
  649. * regulator. This ensures that a regulators supply will also be enabled by the
  650. * core if it's child is enabled.
  651. */
  652. static int set_supply(struct regulator_dev *rdev,
  653. struct regulator_dev *supply_rdev)
  654. {
  655. int err;
  656. err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
  657. "supply");
  658. if (err) {
  659. printk(KERN_ERR
  660. "%s: could not add device link %s err %d\n",
  661. __func__, supply_rdev->dev.kobj.name, err);
  662. goto out;
  663. }
  664. rdev->supply = supply_rdev;
  665. list_add(&rdev->slist, &supply_rdev->supply_list);
  666. out:
  667. return err;
  668. }
  669. /**
  670. * set_consumer_device_supply: Bind a regulator to a symbolic supply
  671. * @regulator: regulator source
  672. * @dev: device the supply applies to
  673. * @supply: symbolic name for supply
  674. *
  675. * Allows platform initialisation code to map physical regulator
  676. * sources to symbolic names for supplies for use by devices. Devices
  677. * should use these symbolic names to request regulators, avoiding the
  678. * need to provide board-specific regulator names as platform data.
  679. */
  680. static int set_consumer_device_supply(struct regulator_dev *rdev,
  681. struct device *consumer_dev, const char *supply)
  682. {
  683. struct regulator_map *node;
  684. if (supply == NULL)
  685. return -EINVAL;
  686. node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
  687. if (node == NULL)
  688. return -ENOMEM;
  689. node->regulator = rdev;
  690. node->dev = consumer_dev;
  691. node->supply = supply;
  692. list_add(&node->list, &regulator_map_list);
  693. return 0;
  694. }
  695. static void unset_consumer_device_supply(struct regulator_dev *rdev,
  696. struct device *consumer_dev)
  697. {
  698. struct regulator_map *node, *n;
  699. list_for_each_entry_safe(node, n, &regulator_map_list, list) {
  700. if (rdev == node->regulator &&
  701. consumer_dev == node->dev) {
  702. list_del(&node->list);
  703. kfree(node);
  704. return;
  705. }
  706. }
  707. }
  708. #define REG_STR_SIZE 32
  709. static struct regulator *create_regulator(struct regulator_dev *rdev,
  710. struct device *dev,
  711. const char *supply_name)
  712. {
  713. struct regulator *regulator;
  714. char buf[REG_STR_SIZE];
  715. int err, size;
  716. regulator = kzalloc(sizeof(*regulator), GFP_KERNEL);
  717. if (regulator == NULL)
  718. return NULL;
  719. mutex_lock(&rdev->mutex);
  720. regulator->rdev = rdev;
  721. list_add(&regulator->list, &rdev->consumer_list);
  722. if (dev) {
  723. /* create a 'requested_microamps_name' sysfs entry */
  724. size = scnprintf(buf, REG_STR_SIZE, "microamps_requested_%s",
  725. supply_name);
  726. if (size >= REG_STR_SIZE)
  727. goto overflow_err;
  728. regulator->dev = dev;
  729. regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL);
  730. if (regulator->dev_attr.attr.name == NULL)
  731. goto attr_name_err;
  732. regulator->dev_attr.attr.owner = THIS_MODULE;
  733. regulator->dev_attr.attr.mode = 0444;
  734. regulator->dev_attr.show = device_requested_uA_show;
  735. err = device_create_file(dev, &regulator->dev_attr);
  736. if (err < 0) {
  737. printk(KERN_WARNING "%s: could not add regulator_dev"
  738. " load sysfs\n", __func__);
  739. goto attr_name_err;
  740. }
  741. /* also add a link to the device sysfs entry */
  742. size = scnprintf(buf, REG_STR_SIZE, "%s-%s",
  743. dev->kobj.name, supply_name);
  744. if (size >= REG_STR_SIZE)
  745. goto attr_err;
  746. regulator->supply_name = kstrdup(buf, GFP_KERNEL);
  747. if (regulator->supply_name == NULL)
  748. goto attr_err;
  749. err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj,
  750. buf);
  751. if (err) {
  752. printk(KERN_WARNING
  753. "%s: could not add device link %s err %d\n",
  754. __func__, dev->kobj.name, err);
  755. device_remove_file(dev, &regulator->dev_attr);
  756. goto link_name_err;
  757. }
  758. }
  759. mutex_unlock(&rdev->mutex);
  760. return regulator;
  761. link_name_err:
  762. kfree(regulator->supply_name);
  763. attr_err:
  764. device_remove_file(regulator->dev, &regulator->dev_attr);
  765. attr_name_err:
  766. kfree(regulator->dev_attr.attr.name);
  767. overflow_err:
  768. list_del(&regulator->list);
  769. kfree(regulator);
  770. mutex_unlock(&rdev->mutex);
  771. return NULL;
  772. }
  773. /**
  774. * regulator_get - lookup and obtain a reference to a regulator.
  775. * @dev: device for regulator "consumer"
  776. * @id: Supply name or regulator ID.
  777. *
  778. * Returns a struct regulator corresponding to the regulator producer,
  779. * or IS_ERR() condition containing errno. Use of supply names
  780. * configured via regulator_set_device_supply() is strongly
  781. * encouraged.
  782. */
  783. struct regulator *regulator_get(struct device *dev, const char *id)
  784. {
  785. struct regulator_dev *rdev;
  786. struct regulator_map *map;
  787. struct regulator *regulator = ERR_PTR(-ENODEV);
  788. if (id == NULL) {
  789. printk(KERN_ERR "regulator: get() with no identifier\n");
  790. return regulator;
  791. }
  792. mutex_lock(&regulator_list_mutex);
  793. list_for_each_entry(map, &regulator_map_list, list) {
  794. if (dev == map->dev &&
  795. strcmp(map->supply, id) == 0) {
  796. rdev = map->regulator;
  797. goto found;
  798. }
  799. }
  800. printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n",
  801. id);
  802. mutex_unlock(&regulator_list_mutex);
  803. return regulator;
  804. found:
  805. if (!try_module_get(rdev->owner))
  806. goto out;
  807. regulator = create_regulator(rdev, dev, id);
  808. if (regulator == NULL) {
  809. regulator = ERR_PTR(-ENOMEM);
  810. module_put(rdev->owner);
  811. }
  812. out:
  813. mutex_unlock(&regulator_list_mutex);
  814. return regulator;
  815. }
  816. EXPORT_SYMBOL_GPL(regulator_get);
  817. /**
  818. * regulator_put - "free" the regulator source
  819. * @regulator: regulator source
  820. *
  821. * Note: drivers must ensure that all regulator_enable calls made on this
  822. * regulator source are balanced by regulator_disable calls prior to calling
  823. * this function.
  824. */
  825. void regulator_put(struct regulator *regulator)
  826. {
  827. struct regulator_dev *rdev;
  828. if (regulator == NULL || IS_ERR(regulator))
  829. return;
  830. if (regulator->enabled) {
  831. printk(KERN_WARNING "Releasing supply %s while enabled\n",
  832. regulator->supply_name);
  833. WARN_ON(regulator->enabled);
  834. regulator_disable(regulator);
  835. }
  836. mutex_lock(&regulator_list_mutex);
  837. rdev = regulator->rdev;
  838. /* remove any sysfs entries */
  839. if (regulator->dev) {
  840. sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name);
  841. kfree(regulator->supply_name);
  842. device_remove_file(regulator->dev, &regulator->dev_attr);
  843. kfree(regulator->dev_attr.attr.name);
  844. }
  845. list_del(&regulator->list);
  846. kfree(regulator);
  847. module_put(rdev->owner);
  848. mutex_unlock(&regulator_list_mutex);
  849. }
  850. EXPORT_SYMBOL_GPL(regulator_put);
  851. /* locks held by regulator_enable() */
  852. static int _regulator_enable(struct regulator_dev *rdev)
  853. {
  854. int ret = -EINVAL;
  855. if (!rdev->constraints) {
  856. printk(KERN_ERR "%s: %s has no constraints\n",
  857. __func__, rdev->desc->name);
  858. return ret;
  859. }
  860. /* do we need to enable the supply regulator first */
  861. if (rdev->supply) {
  862. ret = _regulator_enable(rdev->supply);
  863. if (ret < 0) {
  864. printk(KERN_ERR "%s: failed to enable %s: %d\n",
  865. __func__, rdev->desc->name, ret);
  866. return ret;
  867. }
  868. }
  869. /* check voltage and requested load before enabling */
  870. if (rdev->desc->ops->enable) {
  871. if (rdev->constraints &&
  872. (rdev->constraints->valid_ops_mask &
  873. REGULATOR_CHANGE_DRMS))
  874. drms_uA_update(rdev);
  875. ret = rdev->desc->ops->enable(rdev);
  876. if (ret < 0) {
  877. printk(KERN_ERR "%s: failed to enable %s: %d\n",
  878. __func__, rdev->desc->name, ret);
  879. return ret;
  880. }
  881. rdev->use_count++;
  882. return ret;
  883. }
  884. return ret;
  885. }
  886. /**
  887. * regulator_enable - enable regulator output
  888. * @regulator: regulator source
  889. *
  890. * Enable the regulator output at the predefined voltage or current value.
  891. * NOTE: the output value can be set by other drivers, boot loader or may be
  892. * hardwired in the regulator.
  893. * NOTE: calls to regulator_enable() must be balanced with calls to
  894. * regulator_disable().
  895. */
  896. int regulator_enable(struct regulator *regulator)
  897. {
  898. int ret;
  899. if (regulator->enabled) {
  900. printk(KERN_CRIT "Regulator %s already enabled\n",
  901. regulator->supply_name);
  902. WARN_ON(regulator->enabled);
  903. return 0;
  904. }
  905. mutex_lock(&regulator->rdev->mutex);
  906. regulator->enabled = 1;
  907. ret = _regulator_enable(regulator->rdev);
  908. if (ret != 0)
  909. regulator->enabled = 0;
  910. mutex_unlock(&regulator->rdev->mutex);
  911. return ret;
  912. }
  913. EXPORT_SYMBOL_GPL(regulator_enable);
  914. /* locks held by regulator_disable() */
  915. static int _regulator_disable(struct regulator_dev *rdev)
  916. {
  917. int ret = 0;
  918. /* are we the last user and permitted to disable ? */
  919. if (rdev->use_count == 1 && !rdev->constraints->always_on) {
  920. /* we are last user */
  921. if (rdev->desc->ops->disable) {
  922. ret = rdev->desc->ops->disable(rdev);
  923. if (ret < 0) {
  924. printk(KERN_ERR "%s: failed to disable %s\n",
  925. __func__, rdev->desc->name);
  926. return ret;
  927. }
  928. }
  929. /* decrease our supplies ref count and disable if required */
  930. if (rdev->supply)
  931. _regulator_disable(rdev->supply);
  932. rdev->use_count = 0;
  933. } else if (rdev->use_count > 1) {
  934. if (rdev->constraints &&
  935. (rdev->constraints->valid_ops_mask &
  936. REGULATOR_CHANGE_DRMS))
  937. drms_uA_update(rdev);
  938. rdev->use_count--;
  939. }
  940. return ret;
  941. }
  942. /**
  943. * regulator_disable - disable regulator output
  944. * @regulator: regulator source
  945. *
  946. * Disable the regulator output voltage or current.
  947. * NOTE: this will only disable the regulator output if no other consumer
  948. * devices have it enabled.
  949. * NOTE: calls to regulator_enable() must be balanced with calls to
  950. * regulator_disable().
  951. */
  952. int regulator_disable(struct regulator *regulator)
  953. {
  954. int ret;
  955. if (!regulator->enabled) {
  956. printk(KERN_ERR "%s: not in use by this consumer\n",
  957. __func__);
  958. return 0;
  959. }
  960. mutex_lock(&regulator->rdev->mutex);
  961. regulator->enabled = 0;
  962. regulator->uA_load = 0;
  963. ret = _regulator_disable(regulator->rdev);
  964. mutex_unlock(&regulator->rdev->mutex);
  965. return ret;
  966. }
  967. EXPORT_SYMBOL_GPL(regulator_disable);
  968. /* locks held by regulator_force_disable() */
  969. static int _regulator_force_disable(struct regulator_dev *rdev)
  970. {
  971. int ret = 0;
  972. /* force disable */
  973. if (rdev->desc->ops->disable) {
  974. /* ah well, who wants to live forever... */
  975. ret = rdev->desc->ops->disable(rdev);
  976. if (ret < 0) {
  977. printk(KERN_ERR "%s: failed to force disable %s\n",
  978. __func__, rdev->desc->name);
  979. return ret;
  980. }
  981. /* notify other consumers that power has been forced off */
  982. _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE,
  983. NULL);
  984. }
  985. /* decrease our supplies ref count and disable if required */
  986. if (rdev->supply)
  987. _regulator_disable(rdev->supply);
  988. rdev->use_count = 0;
  989. return ret;
  990. }
  991. /**
  992. * regulator_force_disable - force disable regulator output
  993. * @regulator: regulator source
  994. *
  995. * Forcibly disable the regulator output voltage or current.
  996. * NOTE: this *will* disable the regulator output even if other consumer
  997. * devices have it enabled. This should be used for situations when device
  998. * damage will likely occur if the regulator is not disabled (e.g. over temp).
  999. */
  1000. int regulator_force_disable(struct regulator *regulator)
  1001. {
  1002. int ret;
  1003. mutex_lock(&regulator->rdev->mutex);
  1004. regulator->enabled = 0;
  1005. regulator->uA_load = 0;
  1006. ret = _regulator_force_disable(regulator->rdev);
  1007. mutex_unlock(&regulator->rdev->mutex);
  1008. return ret;
  1009. }
  1010. EXPORT_SYMBOL_GPL(regulator_force_disable);
  1011. static int _regulator_is_enabled(struct regulator_dev *rdev)
  1012. {
  1013. int ret;
  1014. mutex_lock(&rdev->mutex);
  1015. /* sanity check */
  1016. if (!rdev->desc->ops->is_enabled) {
  1017. ret = -EINVAL;
  1018. goto out;
  1019. }
  1020. ret = rdev->desc->ops->is_enabled(rdev);
  1021. out:
  1022. mutex_unlock(&rdev->mutex);
  1023. return ret;
  1024. }
  1025. /**
  1026. * regulator_is_enabled - is the regulator output enabled
  1027. * @regulator: regulator source
  1028. *
  1029. * Returns zero for disabled otherwise return number of enable requests.
  1030. */
  1031. int regulator_is_enabled(struct regulator *regulator)
  1032. {
  1033. return _regulator_is_enabled(regulator->rdev);
  1034. }
  1035. EXPORT_SYMBOL_GPL(regulator_is_enabled);
  1036. /**
  1037. * regulator_set_voltage - set regulator output voltage
  1038. * @regulator: regulator source
  1039. * @min_uV: Minimum required voltage in uV
  1040. * @max_uV: Maximum acceptable voltage in uV
  1041. *
  1042. * Sets a voltage regulator to the desired output voltage. This can be set
  1043. * during any regulator state. IOW, regulator can be disabled or enabled.
  1044. *
  1045. * If the regulator is enabled then the voltage will change to the new value
  1046. * immediately otherwise if the regulator is disabled the regulator will
  1047. * output at the new voltage when enabled.
  1048. *
  1049. * NOTE: If the regulator is shared between several devices then the lowest
  1050. * request voltage that meets the system constraints will be used.
  1051. * NOTE: Regulator system constraints must be set for this regulator before
  1052. * calling this function otherwise this call will fail.
  1053. */
  1054. int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
  1055. {
  1056. struct regulator_dev *rdev = regulator->rdev;
  1057. int ret;
  1058. mutex_lock(&rdev->mutex);
  1059. /* sanity check */
  1060. if (!rdev->desc->ops->set_voltage) {
  1061. ret = -EINVAL;
  1062. goto out;
  1063. }
  1064. /* constraints check */
  1065. ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
  1066. if (ret < 0)
  1067. goto out;
  1068. regulator->min_uV = min_uV;
  1069. regulator->max_uV = max_uV;
  1070. ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV);
  1071. out:
  1072. mutex_unlock(&rdev->mutex);
  1073. return ret;
  1074. }
  1075. EXPORT_SYMBOL_GPL(regulator_set_voltage);
  1076. static int _regulator_get_voltage(struct regulator_dev *rdev)
  1077. {
  1078. /* sanity check */
  1079. if (rdev->desc->ops->get_voltage)
  1080. return rdev->desc->ops->get_voltage(rdev);
  1081. else
  1082. return -EINVAL;
  1083. }
  1084. /**
  1085. * regulator_get_voltage - get regulator output voltage
  1086. * @regulator: regulator source
  1087. *
  1088. * This returns the current regulator voltage in uV.
  1089. *
  1090. * NOTE: If the regulator is disabled it will return the voltage value. This
  1091. * function should not be used to determine regulator state.
  1092. */
  1093. int regulator_get_voltage(struct regulator *regulator)
  1094. {
  1095. int ret;
  1096. mutex_lock(&regulator->rdev->mutex);
  1097. ret = _regulator_get_voltage(regulator->rdev);
  1098. mutex_unlock(&regulator->rdev->mutex);
  1099. return ret;
  1100. }
  1101. EXPORT_SYMBOL_GPL(regulator_get_voltage);
  1102. /**
  1103. * regulator_set_current_limit - set regulator output current limit
  1104. * @regulator: regulator source
  1105. * @min_uA: Minimuum supported current in uA
  1106. * @max_uA: Maximum supported current in uA
  1107. *
  1108. * Sets current sink to the desired output current. This can be set during
  1109. * any regulator state. IOW, regulator can be disabled or enabled.
  1110. *
  1111. * If the regulator is enabled then the current will change to the new value
  1112. * immediately otherwise if the regulator is disabled the regulator will
  1113. * output at the new current when enabled.
  1114. *
  1115. * NOTE: Regulator system constraints must be set for this regulator before
  1116. * calling this function otherwise this call will fail.
  1117. */
  1118. int regulator_set_current_limit(struct regulator *regulator,
  1119. int min_uA, int max_uA)
  1120. {
  1121. struct regulator_dev *rdev = regulator->rdev;
  1122. int ret;
  1123. mutex_lock(&rdev->mutex);
  1124. /* sanity check */
  1125. if (!rdev->desc->ops->set_current_limit) {
  1126. ret = -EINVAL;
  1127. goto out;
  1128. }
  1129. /* constraints check */
  1130. ret = regulator_check_current_limit(rdev, &min_uA, &max_uA);
  1131. if (ret < 0)
  1132. goto out;
  1133. ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA);
  1134. out:
  1135. mutex_unlock(&rdev->mutex);
  1136. return ret;
  1137. }
  1138. EXPORT_SYMBOL_GPL(regulator_set_current_limit);
  1139. static int _regulator_get_current_limit(struct regulator_dev *rdev)
  1140. {
  1141. int ret;
  1142. mutex_lock(&rdev->mutex);
  1143. /* sanity check */
  1144. if (!rdev->desc->ops->get_current_limit) {
  1145. ret = -EINVAL;
  1146. goto out;
  1147. }
  1148. ret = rdev->desc->ops->get_current_limit(rdev);
  1149. out:
  1150. mutex_unlock(&rdev->mutex);
  1151. return ret;
  1152. }
  1153. /**
  1154. * regulator_get_current_limit - get regulator output current
  1155. * @regulator: regulator source
  1156. *
  1157. * This returns the current supplied by the specified current sink in uA.
  1158. *
  1159. * NOTE: If the regulator is disabled it will return the current value. This
  1160. * function should not be used to determine regulator state.
  1161. */
  1162. int regulator_get_current_limit(struct regulator *regulator)
  1163. {
  1164. return _regulator_get_current_limit(regulator->rdev);
  1165. }
  1166. EXPORT_SYMBOL_GPL(regulator_get_current_limit);
  1167. /**
  1168. * regulator_set_mode - set regulator operating mode
  1169. * @regulator: regulator source
  1170. * @mode: operating mode - one of the REGULATOR_MODE constants
  1171. *
  1172. * Set regulator operating mode to increase regulator efficiency or improve
  1173. * regulation performance.
  1174. *
  1175. * NOTE: Regulator system constraints must be set for this regulator before
  1176. * calling this function otherwise this call will fail.
  1177. */
  1178. int regulator_set_mode(struct regulator *regulator, unsigned int mode)
  1179. {
  1180. struct regulator_dev *rdev = regulator->rdev;
  1181. int ret;
  1182. mutex_lock(&rdev->mutex);
  1183. /* sanity check */
  1184. if (!rdev->desc->ops->set_mode) {
  1185. ret = -EINVAL;
  1186. goto out;
  1187. }
  1188. /* constraints check */
  1189. ret = regulator_check_mode(rdev, mode);
  1190. if (ret < 0)
  1191. goto out;
  1192. ret = rdev->desc->ops->set_mode(rdev, mode);
  1193. out:
  1194. mutex_unlock(&rdev->mutex);
  1195. return ret;
  1196. }
  1197. EXPORT_SYMBOL_GPL(regulator_set_mode);
  1198. static unsigned int _regulator_get_mode(struct regulator_dev *rdev)
  1199. {
  1200. int ret;
  1201. mutex_lock(&rdev->mutex);
  1202. /* sanity check */
  1203. if (!rdev->desc->ops->get_mode) {
  1204. ret = -EINVAL;
  1205. goto out;
  1206. }
  1207. ret = rdev->desc->ops->get_mode(rdev);
  1208. out:
  1209. mutex_unlock(&rdev->mutex);
  1210. return ret;
  1211. }
  1212. /**
  1213. * regulator_get_mode - get regulator operating mode
  1214. * @regulator: regulator source
  1215. *
  1216. * Get the current regulator operating mode.
  1217. */
  1218. unsigned int regulator_get_mode(struct regulator *regulator)
  1219. {
  1220. return _regulator_get_mode(regulator->rdev);
  1221. }
  1222. EXPORT_SYMBOL_GPL(regulator_get_mode);
  1223. /**
  1224. * regulator_set_optimum_mode - set regulator optimum operating mode
  1225. * @regulator: regulator source
  1226. * @uA_load: load current
  1227. *
  1228. * Notifies the regulator core of a new device load. This is then used by
  1229. * DRMS (if enabled by constraints) to set the most efficient regulator
  1230. * operating mode for the new regulator loading.
  1231. *
  1232. * Consumer devices notify their supply regulator of the maximum power
  1233. * they will require (can be taken from device datasheet in the power
  1234. * consumption tables) when they change operational status and hence power
  1235. * state. Examples of operational state changes that can affect power
  1236. * consumption are :-
  1237. *
  1238. * o Device is opened / closed.
  1239. * o Device I/O is about to begin or has just finished.
  1240. * o Device is idling in between work.
  1241. *
  1242. * This information is also exported via sysfs to userspace.
  1243. *
  1244. * DRMS will sum the total requested load on the regulator and change
  1245. * to the most efficient operating mode if platform constraints allow.
  1246. *
  1247. * Returns the new regulator mode or error.
  1248. */
  1249. int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
  1250. {
  1251. struct regulator_dev *rdev = regulator->rdev;
  1252. struct regulator *consumer;
  1253. int ret, output_uV, input_uV, total_uA_load = 0;
  1254. unsigned int mode;
  1255. mutex_lock(&rdev->mutex);
  1256. regulator->uA_load = uA_load;
  1257. ret = regulator_check_drms(rdev);
  1258. if (ret < 0)
  1259. goto out;
  1260. ret = -EINVAL;
  1261. /* sanity check */
  1262. if (!rdev->desc->ops->get_optimum_mode)
  1263. goto out;
  1264. /* get output voltage */
  1265. output_uV = rdev->desc->ops->get_voltage(rdev);
  1266. if (output_uV <= 0) {
  1267. printk(KERN_ERR "%s: invalid output voltage found for %s\n",
  1268. __func__, rdev->desc->name);
  1269. goto out;
  1270. }
  1271. /* get input voltage */
  1272. if (rdev->supply && rdev->supply->desc->ops->get_voltage)
  1273. input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply);
  1274. else
  1275. input_uV = rdev->constraints->input_uV;
  1276. if (input_uV <= 0) {
  1277. printk(KERN_ERR "%s: invalid input voltage found for %s\n",
  1278. __func__, rdev->desc->name);
  1279. goto out;
  1280. }
  1281. /* calc total requested load for this regulator */
  1282. list_for_each_entry(consumer, &rdev->consumer_list, list)
  1283. total_uA_load += consumer->uA_load;
  1284. mode = rdev->desc->ops->get_optimum_mode(rdev,
  1285. input_uV, output_uV,
  1286. total_uA_load);
  1287. if (ret <= 0) {
  1288. printk(KERN_ERR "%s: failed to get optimum mode for %s @"
  1289. " %d uA %d -> %d uV\n", __func__, rdev->desc->name,
  1290. total_uA_load, input_uV, output_uV);
  1291. goto out;
  1292. }
  1293. ret = rdev->desc->ops->set_mode(rdev, mode);
  1294. if (ret <= 0) {
  1295. printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n",
  1296. __func__, mode, rdev->desc->name);
  1297. goto out;
  1298. }
  1299. ret = mode;
  1300. out:
  1301. mutex_unlock(&rdev->mutex);
  1302. return ret;
  1303. }
  1304. EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
  1305. /**
  1306. * regulator_register_notifier - register regulator event notifier
  1307. * @regulator: regulator source
  1308. * @notifier_block: notifier block
  1309. *
  1310. * Register notifier block to receive regulator events.
  1311. */
  1312. int regulator_register_notifier(struct regulator *regulator,
  1313. struct notifier_block *nb)
  1314. {
  1315. return blocking_notifier_chain_register(&regulator->rdev->notifier,
  1316. nb);
  1317. }
  1318. EXPORT_SYMBOL_GPL(regulator_register_notifier);
  1319. /**
  1320. * regulator_unregister_notifier - unregister regulator event notifier
  1321. * @regulator: regulator source
  1322. * @notifier_block: notifier block
  1323. *
  1324. * Unregister regulator event notifier block.
  1325. */
  1326. int regulator_unregister_notifier(struct regulator *regulator,
  1327. struct notifier_block *nb)
  1328. {
  1329. return blocking_notifier_chain_unregister(&regulator->rdev->notifier,
  1330. nb);
  1331. }
  1332. EXPORT_SYMBOL_GPL(regulator_unregister_notifier);
  1333. /* notify regulator consumers and downstream regulator consumers */
  1334. static void _notifier_call_chain(struct regulator_dev *rdev,
  1335. unsigned long event, void *data)
  1336. {
  1337. struct regulator_dev *_rdev;
  1338. /* call rdev chain first */
  1339. mutex_lock(&rdev->mutex);
  1340. blocking_notifier_call_chain(&rdev->notifier, event, NULL);
  1341. mutex_unlock(&rdev->mutex);
  1342. /* now notify regulator we supply */
  1343. list_for_each_entry(_rdev, &rdev->supply_list, slist)
  1344. _notifier_call_chain(_rdev, event, data);
  1345. }
  1346. /**
  1347. * regulator_bulk_get - get multiple regulator consumers
  1348. *
  1349. * @dev: Device to supply
  1350. * @num_consumers: Number of consumers to register
  1351. * @consumers: Configuration of consumers; clients are stored here.
  1352. *
  1353. * @return 0 on success, an errno on failure.
  1354. *
  1355. * This helper function allows drivers to get several regulator
  1356. * consumers in one operation. If any of the regulators cannot be
  1357. * acquired then any regulators that were allocated will be freed
  1358. * before returning to the caller.
  1359. */
  1360. int regulator_bulk_get(struct device *dev, int num_consumers,
  1361. struct regulator_bulk_data *consumers)
  1362. {
  1363. int i;
  1364. int ret;
  1365. for (i = 0; i < num_consumers; i++)
  1366. consumers[i].consumer = NULL;
  1367. for (i = 0; i < num_consumers; i++) {
  1368. consumers[i].consumer = regulator_get(dev,
  1369. consumers[i].supply);
  1370. if (IS_ERR(consumers[i].consumer)) {
  1371. dev_err(dev, "Failed to get supply '%s'\n",
  1372. consumers[i].supply);
  1373. ret = PTR_ERR(consumers[i].consumer);
  1374. consumers[i].consumer = NULL;
  1375. goto err;
  1376. }
  1377. }
  1378. return 0;
  1379. err:
  1380. for (i = 0; i < num_consumers && consumers[i].consumer; i++)
  1381. regulator_put(consumers[i].consumer);
  1382. return ret;
  1383. }
  1384. EXPORT_SYMBOL_GPL(regulator_bulk_get);
  1385. /**
  1386. * regulator_bulk_enable - enable multiple regulator consumers
  1387. *
  1388. * @num_consumers: Number of consumers
  1389. * @consumers: Consumer data; clients are stored here.
  1390. * @return 0 on success, an errno on failure
  1391. *
  1392. * This convenience API allows consumers to enable multiple regulator
  1393. * clients in a single API call. If any consumers cannot be enabled
  1394. * then any others that were enabled will be disabled again prior to
  1395. * return.
  1396. */
  1397. int regulator_bulk_enable(int num_consumers,
  1398. struct regulator_bulk_data *consumers)
  1399. {
  1400. int i;
  1401. int ret;
  1402. for (i = 0; i < num_consumers; i++) {
  1403. ret = regulator_enable(consumers[i].consumer);
  1404. if (ret != 0)
  1405. goto err;
  1406. }
  1407. return 0;
  1408. err:
  1409. printk(KERN_ERR "Failed to enable %s\n", consumers[i].supply);
  1410. for (i = 0; i < num_consumers; i++)
  1411. regulator_disable(consumers[i].consumer);
  1412. return ret;
  1413. }
  1414. EXPORT_SYMBOL_GPL(regulator_bulk_enable);
  1415. /**
  1416. * regulator_bulk_disable - disable multiple regulator consumers
  1417. *
  1418. * @num_consumers: Number of consumers
  1419. * @consumers: Consumer data; clients are stored here.
  1420. * @return 0 on success, an errno on failure
  1421. *
  1422. * This convenience API allows consumers to disable multiple regulator
  1423. * clients in a single API call. If any consumers cannot be enabled
  1424. * then any others that were disabled will be disabled again prior to
  1425. * return.
  1426. */
  1427. int regulator_bulk_disable(int num_consumers,
  1428. struct regulator_bulk_data *consumers)
  1429. {
  1430. int i;
  1431. int ret;
  1432. for (i = 0; i < num_consumers; i++) {
  1433. ret = regulator_disable(consumers[i].consumer);
  1434. if (ret != 0)
  1435. goto err;
  1436. }
  1437. return 0;
  1438. err:
  1439. printk(KERN_ERR "Failed to disable %s\n", consumers[i].supply);
  1440. for (i = 0; i < num_consumers; i++)
  1441. regulator_enable(consumers[i].consumer);
  1442. return ret;
  1443. }
  1444. EXPORT_SYMBOL_GPL(regulator_bulk_disable);
  1445. /**
  1446. * regulator_bulk_free - free multiple regulator consumers
  1447. *
  1448. * @num_consumers: Number of consumers
  1449. * @consumers: Consumer data; clients are stored here.
  1450. *
  1451. * This convenience API allows consumers to free multiple regulator
  1452. * clients in a single API call.
  1453. */
  1454. void regulator_bulk_free(int num_consumers,
  1455. struct regulator_bulk_data *consumers)
  1456. {
  1457. int i;
  1458. for (i = 0; i < num_consumers; i++) {
  1459. regulator_put(consumers[i].consumer);
  1460. consumers[i].consumer = NULL;
  1461. }
  1462. }
  1463. EXPORT_SYMBOL_GPL(regulator_bulk_free);
  1464. /**
  1465. * regulator_notifier_call_chain - call regulator event notifier
  1466. * @regulator: regulator source
  1467. * @event: notifier block
  1468. * @data:
  1469. *
  1470. * Called by regulator drivers to notify clients a regulator event has
  1471. * occurred. We also notify regulator clients downstream.
  1472. */
  1473. int regulator_notifier_call_chain(struct regulator_dev *rdev,
  1474. unsigned long event, void *data)
  1475. {
  1476. _notifier_call_chain(rdev, event, data);
  1477. return NOTIFY_DONE;
  1478. }
  1479. EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
  1480. /**
  1481. * regulator_register - register regulator
  1482. * @regulator: regulator source
  1483. * @reg_data: private regulator data
  1484. *
  1485. * Called by regulator drivers to register a regulator.
  1486. * Returns 0 on success.
  1487. */
  1488. struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
  1489. struct device *dev, void *driver_data)
  1490. {
  1491. static atomic_t regulator_no = ATOMIC_INIT(0);
  1492. struct regulator_dev *rdev;
  1493. struct regulator_init_data *init_data = dev->platform_data;
  1494. int ret, i;
  1495. if (regulator_desc == NULL)
  1496. return ERR_PTR(-EINVAL);
  1497. if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
  1498. return ERR_PTR(-EINVAL);
  1499. if (!regulator_desc->type == REGULATOR_VOLTAGE &&
  1500. !regulator_desc->type == REGULATOR_CURRENT)
  1501. return ERR_PTR(-EINVAL);
  1502. if (!init_data)
  1503. return ERR_PTR(-EINVAL);
  1504. rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
  1505. if (rdev == NULL)
  1506. return ERR_PTR(-ENOMEM);
  1507. mutex_lock(&regulator_list_mutex);
  1508. mutex_init(&rdev->mutex);
  1509. rdev->reg_data = driver_data;
  1510. rdev->owner = regulator_desc->owner;
  1511. rdev->desc = regulator_desc;
  1512. INIT_LIST_HEAD(&rdev->consumer_list);
  1513. INIT_LIST_HEAD(&rdev->supply_list);
  1514. INIT_LIST_HEAD(&rdev->list);
  1515. INIT_LIST_HEAD(&rdev->slist);
  1516. BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
  1517. /* preform any regulator specific init */
  1518. if (init_data->regulator_init) {
  1519. ret = init_data->regulator_init(rdev->reg_data);
  1520. if (ret < 0) {
  1521. kfree(rdev);
  1522. rdev = ERR_PTR(ret);
  1523. goto out;
  1524. }
  1525. }
  1526. /* set regulator constraints */
  1527. ret = set_machine_constraints(rdev, &init_data->constraints);
  1528. if (ret < 0) {
  1529. kfree(rdev);
  1530. rdev = ERR_PTR(ret);
  1531. goto out;
  1532. }
  1533. /* register with sysfs */
  1534. rdev->dev.class = &regulator_class;
  1535. rdev->dev.parent = dev;
  1536. snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id),
  1537. "regulator.%d", atomic_inc_return(&regulator_no) - 1);
  1538. ret = device_register(&rdev->dev);
  1539. if (ret != 0) {
  1540. kfree(rdev);
  1541. rdev = ERR_PTR(ret);
  1542. goto out;
  1543. }
  1544. dev_set_drvdata(&rdev->dev, rdev);
  1545. /* set supply regulator if it exists */
  1546. if (init_data->supply_regulator_dev) {
  1547. ret = set_supply(rdev,
  1548. dev_get_drvdata(init_data->supply_regulator_dev));
  1549. if (ret < 0) {
  1550. device_unregister(&rdev->dev);
  1551. kfree(rdev);
  1552. rdev = ERR_PTR(ret);
  1553. goto out;
  1554. }
  1555. }
  1556. /* add consumers devices */
  1557. for (i = 0; i < init_data->num_consumer_supplies; i++) {
  1558. ret = set_consumer_device_supply(rdev,
  1559. init_data->consumer_supplies[i].dev,
  1560. init_data->consumer_supplies[i].supply);
  1561. if (ret < 0) {
  1562. for (--i; i >= 0; i--)
  1563. unset_consumer_device_supply(rdev,
  1564. init_data->consumer_supplies[i].dev);
  1565. device_unregister(&rdev->dev);
  1566. kfree(rdev);
  1567. rdev = ERR_PTR(ret);
  1568. goto out;
  1569. }
  1570. }
  1571. list_add(&rdev->list, &regulator_list);
  1572. out:
  1573. mutex_unlock(&regulator_list_mutex);
  1574. return rdev;
  1575. }
  1576. EXPORT_SYMBOL_GPL(regulator_register);
  1577. /**
  1578. * regulator_unregister - unregister regulator
  1579. * @regulator: regulator source
  1580. *
  1581. * Called by regulator drivers to unregister a regulator.
  1582. */
  1583. void regulator_unregister(struct regulator_dev *rdev)
  1584. {
  1585. if (rdev == NULL)
  1586. return;
  1587. mutex_lock(&regulator_list_mutex);
  1588. list_del(&rdev->list);
  1589. if (rdev->supply)
  1590. sysfs_remove_link(&rdev->dev.kobj, "supply");
  1591. device_unregister(&rdev->dev);
  1592. mutex_unlock(&regulator_list_mutex);
  1593. }
  1594. EXPORT_SYMBOL_GPL(regulator_unregister);
  1595. /**
  1596. * regulator_suspend_prepare: prepare regulators for system wide suspend
  1597. * @state: system suspend state
  1598. *
  1599. * Configure each regulator with it's suspend operating parameters for state.
  1600. * This will usually be called by machine suspend code prior to supending.
  1601. */
  1602. int regulator_suspend_prepare(suspend_state_t state)
  1603. {
  1604. struct regulator_dev *rdev;
  1605. int ret = 0;
  1606. /* ON is handled by regulator active state */
  1607. if (state == PM_SUSPEND_ON)
  1608. return -EINVAL;
  1609. mutex_lock(&regulator_list_mutex);
  1610. list_for_each_entry(rdev, &regulator_list, list) {
  1611. mutex_lock(&rdev->mutex);
  1612. ret = suspend_prepare(rdev, state);
  1613. mutex_unlock(&rdev->mutex);
  1614. if (ret < 0) {
  1615. printk(KERN_ERR "%s: failed to prepare %s\n",
  1616. __func__, rdev->desc->name);
  1617. goto out;
  1618. }
  1619. }
  1620. out:
  1621. mutex_unlock(&regulator_list_mutex);
  1622. return ret;
  1623. }
  1624. EXPORT_SYMBOL_GPL(regulator_suspend_prepare);
  1625. /**
  1626. * rdev_get_drvdata - get rdev regulator driver data
  1627. * @regulator: regulator
  1628. *
  1629. * Get rdev regulator driver private data. This call can be used in the
  1630. * regulator driver context.
  1631. */
  1632. void *rdev_get_drvdata(struct regulator_dev *rdev)
  1633. {
  1634. return rdev->reg_data;
  1635. }
  1636. EXPORT_SYMBOL_GPL(rdev_get_drvdata);
  1637. /**
  1638. * regulator_get_drvdata - get regulator driver data
  1639. * @regulator: regulator
  1640. *
  1641. * Get regulator driver private data. This call can be used in the consumer
  1642. * driver context when non API regulator specific functions need to be called.
  1643. */
  1644. void *regulator_get_drvdata(struct regulator *regulator)
  1645. {
  1646. return regulator->rdev->reg_data;
  1647. }
  1648. EXPORT_SYMBOL_GPL(regulator_get_drvdata);
  1649. /**
  1650. * regulator_set_drvdata - set regulator driver data
  1651. * @regulator: regulator
  1652. * @data: data
  1653. */
  1654. void regulator_set_drvdata(struct regulator *regulator, void *data)
  1655. {
  1656. regulator->rdev->reg_data = data;
  1657. }
  1658. EXPORT_SYMBOL_GPL(regulator_set_drvdata);
  1659. /**
  1660. * regulator_get_id - get regulator ID
  1661. * @regulator: regulator
  1662. */
  1663. int rdev_get_id(struct regulator_dev *rdev)
  1664. {
  1665. return rdev->desc->id;
  1666. }
  1667. EXPORT_SYMBOL_GPL(rdev_get_id);
  1668. struct device *rdev_get_dev(struct regulator_dev *rdev)
  1669. {
  1670. return &rdev->dev;
  1671. }
  1672. EXPORT_SYMBOL_GPL(rdev_get_dev);
  1673. void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
  1674. {
  1675. return reg_init_data->driver_data;
  1676. }
  1677. EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
  1678. static int __init regulator_init(void)
  1679. {
  1680. printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
  1681. return class_register(&regulator_class);
  1682. }
  1683. /* init early to allow our consumers to complete system booting */
  1684. core_initcall(regulator_init);