core.c 67 KB

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