bd718x7-regulator.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 ROHM Semiconductors
  3. // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
  4. #include <linux/cleanup.h>
  5. #include <linux/delay.h>
  6. #include <linux/err.h>
  7. #include <linux/interrupt.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mfd/rohm-bd718x7.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/regulator/driver.h>
  14. #include <linux/regulator/machine.h>
  15. #include <linux/regulator/of_regulator.h>
  16. #include <linux/slab.h>
  17. /* Typical regulator startup times as per data sheet in uS */
  18. #define BD71847_BUCK1_STARTUP_TIME 144
  19. #define BD71847_BUCK2_STARTUP_TIME 162
  20. #define BD71847_BUCK3_STARTUP_TIME 162
  21. #define BD71847_BUCK4_STARTUP_TIME 240
  22. #define BD71847_BUCK5_STARTUP_TIME 270
  23. #define BD71847_BUCK6_STARTUP_TIME 200
  24. #define BD71847_LDO1_STARTUP_TIME 440
  25. #define BD71847_LDO2_STARTUP_TIME 370
  26. #define BD71847_LDO3_STARTUP_TIME 310
  27. #define BD71847_LDO4_STARTUP_TIME 400
  28. #define BD71847_LDO5_STARTUP_TIME 530
  29. #define BD71847_LDO6_STARTUP_TIME 400
  30. #define BD71837_BUCK1_STARTUP_TIME 160
  31. #define BD71837_BUCK2_STARTUP_TIME 180
  32. #define BD71837_BUCK3_STARTUP_TIME 180
  33. #define BD71837_BUCK4_STARTUP_TIME 180
  34. #define BD71837_BUCK5_STARTUP_TIME 160
  35. #define BD71837_BUCK6_STARTUP_TIME 240
  36. #define BD71837_BUCK7_STARTUP_TIME 220
  37. #define BD71837_BUCK8_STARTUP_TIME 200
  38. #define BD71837_LDO1_STARTUP_TIME 440
  39. #define BD71837_LDO2_STARTUP_TIME 370
  40. #define BD71837_LDO3_STARTUP_TIME 310
  41. #define BD71837_LDO4_STARTUP_TIME 400
  42. #define BD71837_LDO5_STARTUP_TIME 310
  43. #define BD71837_LDO6_STARTUP_TIME 400
  44. #define BD71837_LDO7_STARTUP_TIME 530
  45. /*
  46. * BD718(37/47/50) have two "enable control modes". ON/OFF can either be
  47. * controlled by software - or by PMIC internal HW state machine. Whether
  48. * regulator should be under SW or HW control can be defined from device-tree.
  49. * Let's provide separate ops for regulators to use depending on the "enable
  50. * control mode".
  51. */
  52. #define BD718XX_HWOPNAME(swopname) swopname##_hwcontrol
  53. #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \
  54. _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay, \
  55. _set_uvp, _set_ovp) \
  56. static const struct regulator_ops name = { \
  57. .enable = regulator_enable_regmap, \
  58. .disable = regulator_disable_regmap, \
  59. .is_enabled = regulator_is_enabled_regmap, \
  60. .list_voltage = (_list_voltage), \
  61. .map_voltage = (_map_voltage), \
  62. .set_voltage_sel = (_set_voltage_sel), \
  63. .get_voltage_sel = (_get_voltage_sel), \
  64. .set_voltage_time_sel = (_set_voltage_time_sel), \
  65. .set_ramp_delay = (_set_ramp_delay), \
  66. .set_under_voltage_protection = (_set_uvp), \
  67. .set_over_voltage_protection = (_set_ovp), \
  68. }; \
  69. \
  70. static const struct regulator_ops BD718XX_HWOPNAME(name) = { \
  71. .is_enabled = always_enabled_by_hwstate, \
  72. .list_voltage = (_list_voltage), \
  73. .map_voltage = (_map_voltage), \
  74. .set_voltage_sel = (_set_voltage_sel), \
  75. .get_voltage_sel = (_get_voltage_sel), \
  76. .set_voltage_time_sel = (_set_voltage_time_sel), \
  77. .set_ramp_delay = (_set_ramp_delay), \
  78. .set_under_voltage_protection = (_set_uvp), \
  79. .set_over_voltage_protection = (_set_ovp), \
  80. } \
  81. /*
  82. * BUCK1/2/3/4
  83. * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
  84. * 00: 10.00mV/usec 10mV 1uS
  85. * 01: 5.00mV/usec 10mV 2uS
  86. * 10: 2.50mV/usec 10mV 4uS
  87. * 11: 1.25mV/usec 10mV 8uS
  88. */
  89. static const unsigned int bd718xx_ramp_delay[] = { 10000, 5000, 2500, 1250 };
  90. /* These functions are used when regulators are under HW state machine control.
  91. * We assume PMIC is in RUN state because SW running and able to query the
  92. * status. Most of the regulators have fixed ON or OFF state at RUN/IDLE so for
  93. * them we just return a constant. BD71837 BUCK3 and BUCK4 are exceptions as
  94. * they support configuring the ON/OFF state for RUN.
  95. *
  96. * Note for next hacker - these PMICs have a register where the HW state can be
  97. * read. If assuming RUN appears to be false in your use-case - you can
  98. * implement state reading (although that is not going to be atomic) before
  99. * returning the enable state.
  100. */
  101. static int always_enabled_by_hwstate(struct regulator_dev *rdev)
  102. {
  103. return 1;
  104. }
  105. static int never_enabled_by_hwstate(struct regulator_dev *rdev)
  106. {
  107. return 0;
  108. }
  109. static int bd71837_get_buck34_enable_hwctrl(struct regulator_dev *rdev)
  110. {
  111. int ret;
  112. unsigned int val;
  113. ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
  114. if (ret)
  115. return ret;
  116. return !!(BD718XX_BUCK_RUN_ON & val);
  117. }
  118. static void voltage_change_done(struct regulator_dev *rdev, unsigned int sel,
  119. unsigned int *mask)
  120. {
  121. int ret;
  122. if (*mask) {
  123. /*
  124. * We had fault detection disabled for the duration of the
  125. * voltage change.
  126. *
  127. * According to HW colleagues the maximum time it takes is
  128. * 1000us. I assume that on systems with light load this
  129. * might be less - and we could probably use DT to give
  130. * system specific delay value if performance matters.
  131. *
  132. * Well, knowing we use I2C here and can add scheduling delays
  133. * I don't think it is worth the hassle and I just add fixed
  134. * 1ms sleep here (and allow scheduling). If this turns out to
  135. * be a problem we can change it to delay and make the delay
  136. * time configurable.
  137. */
  138. msleep(1);
  139. ret = regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
  140. *mask);
  141. if (ret)
  142. dev_err(&rdev->dev,
  143. "Failed to re-enable voltage monitoring (%d)\n",
  144. ret);
  145. }
  146. }
  147. static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int sel,
  148. unsigned int *mask)
  149. {
  150. int ret;
  151. *mask = 0;
  152. if (rdev->desc->ops->is_enabled(rdev)) {
  153. int now, new;
  154. now = rdev->desc->ops->get_voltage_sel(rdev);
  155. if (now < 0)
  156. return now;
  157. now = rdev->desc->ops->list_voltage(rdev, now);
  158. if (now < 0)
  159. return now;
  160. new = rdev->desc->ops->list_voltage(rdev, sel);
  161. if (new < 0)
  162. return new;
  163. /*
  164. * If we increase LDO voltage when LDO is enabled we need to
  165. * disable the power-good detection until voltage has reached
  166. * the new level.
  167. */
  168. if (new > now) {
  169. int tmp;
  170. int prot_bit;
  171. int ldo_offset = rdev->desc->id - BD718XX_LDO1;
  172. prot_bit = BD718XX_LDO1_VRMON80 << ldo_offset;
  173. ret = regmap_read(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
  174. &tmp);
  175. if (ret) {
  176. dev_err(&rdev->dev,
  177. "Failed to read voltage monitoring state\n");
  178. return ret;
  179. }
  180. if (!(tmp & prot_bit)) {
  181. /* We disable protection if it was enabled... */
  182. ret = regmap_set_bits(rdev->regmap,
  183. BD718XX_REG_MVRFLTMASK2,
  184. prot_bit);
  185. /* ...and we also want to re-enable it */
  186. *mask = prot_bit;
  187. }
  188. if (ret) {
  189. dev_err(&rdev->dev,
  190. "Failed to stop voltage monitoring\n");
  191. return ret;
  192. }
  193. }
  194. }
  195. return 0;
  196. }
  197. static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
  198. unsigned int sel)
  199. {
  200. int ret;
  201. int mask;
  202. ret = voltage_change_prepare(rdev, sel, &mask);
  203. if (ret)
  204. return ret;
  205. ret = regulator_set_voltage_sel_regmap(rdev, sel);
  206. voltage_change_done(rdev, sel, &mask);
  207. return ret;
  208. }
  209. static int bd718xx_set_voltage_sel_pickable_restricted(
  210. struct regulator_dev *rdev, unsigned int sel)
  211. {
  212. int ret;
  213. int mask;
  214. ret = voltage_change_prepare(rdev, sel, &mask);
  215. if (ret)
  216. return ret;
  217. ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel);
  218. voltage_change_done(rdev, sel, &mask);
  219. return ret;
  220. }
  221. static int bd71837_set_voltage_sel_pickable_restricted(
  222. struct regulator_dev *rdev, unsigned int sel)
  223. {
  224. if (rdev->desc->ops->is_enabled(rdev))
  225. return -EBUSY;
  226. return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
  227. }
  228. /*
  229. * BD71837 BUCK1/2/3/4
  230. * BD71847 BUCK1/2
  231. * 0.70 to 1.30V (10mV step)
  232. */
  233. static const struct linear_range bd718xx_dvs_buck_volts[] = {
  234. REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
  235. REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
  236. };
  237. /*
  238. * BD71837 BUCK5
  239. * 0.7V to 1.35V (range 0)
  240. * and
  241. * 0.675 to 1.325 (range 1)
  242. */
  243. static const struct linear_range bd71837_buck5_volts[] = {
  244. /* Ranges when VOLT_SEL bit is 0 */
  245. REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
  246. REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
  247. REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
  248. /* Ranges when VOLT_SEL bit is 1 */
  249. REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
  250. REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
  251. REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
  252. };
  253. /*
  254. * Range selector for first 3 linear ranges is 0x0
  255. * and 0x1 for last 3 ranges.
  256. */
  257. static const unsigned int bd71837_buck5_volt_range_sel[] = {
  258. 0x0, 0x0, 0x0, 0x1, 0x1, 0x1
  259. };
  260. /*
  261. * BD71847 BUCK3
  262. */
  263. static const struct linear_range bd71847_buck3_volts[] = {
  264. /* Ranges when VOLT_SEL bits are 00 */
  265. REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
  266. REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
  267. REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
  268. /* Ranges when VOLT_SEL bits are 01 */
  269. REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
  270. /* Ranges when VOLT_SEL bits are 11 */
  271. REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
  272. REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
  273. REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
  274. };
  275. static const unsigned int bd71847_buck3_volt_range_sel[] = {
  276. 0x0, 0x0, 0x0, 0x1, 0x2, 0x2, 0x2
  277. };
  278. static const struct linear_range bd71847_buck4_volts[] = {
  279. REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  280. REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
  281. };
  282. static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x1 };
  283. /*
  284. * BUCK6
  285. * 3.0V to 3.3V (step 100mV)
  286. */
  287. static const struct linear_range bd71837_buck6_volts[] = {
  288. REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  289. };
  290. /*
  291. * BD71837 BUCK7
  292. * BD71847 BUCK5
  293. * 000 = 1.605V
  294. * 001 = 1.695V
  295. * 010 = 1.755V
  296. * 011 = 1.8V (Initial)
  297. * 100 = 1.845V
  298. * 101 = 1.905V
  299. * 110 = 1.95V
  300. * 111 = 1.995V
  301. */
  302. static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
  303. 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
  304. };
  305. /*
  306. * BUCK8
  307. * 0.8V to 1.40V (step 10mV)
  308. */
  309. static const struct linear_range bd718xx_4th_nodvs_buck_volts[] = {
  310. REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
  311. };
  312. /*
  313. * LDO1
  314. * 3.0 to 3.3V (100mV step)
  315. */
  316. static const struct linear_range bd718xx_ldo1_volts[] = {
  317. REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  318. REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
  319. };
  320. static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x1 };
  321. /*
  322. * LDO2
  323. * 0.8 or 0.9V
  324. */
  325. static const unsigned int ldo_2_volts[] = {
  326. 900000, 800000
  327. };
  328. /*
  329. * LDO3
  330. * 1.8 to 3.3V (100mV step)
  331. */
  332. static const struct linear_range bd718xx_ldo3_volts[] = {
  333. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  334. };
  335. /*
  336. * LDO4
  337. * 0.9 to 1.8V (100mV step)
  338. */
  339. static const struct linear_range bd718xx_ldo4_volts[] = {
  340. REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
  341. };
  342. /*
  343. * LDO5 for BD71837
  344. * 1.8 to 3.3V (100mV step)
  345. */
  346. static const struct linear_range bd71837_ldo5_volts[] = {
  347. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  348. };
  349. /*
  350. * LDO5 for BD71837
  351. * 1.8 to 3.3V (100mV step)
  352. */
  353. static const struct linear_range bd71847_ldo5_volts[] = {
  354. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  355. REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
  356. };
  357. static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x1 };
  358. /*
  359. * LDO6
  360. * 0.9 to 1.8V (100mV step)
  361. */
  362. static const struct linear_range bd718xx_ldo6_volts[] = {
  363. REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
  364. };
  365. /*
  366. * LDO7
  367. * 1.8 to 3.3V (100mV step)
  368. */
  369. static const struct linear_range bd71837_ldo7_volts[] = {
  370. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  371. };
  372. struct reg_init {
  373. unsigned int reg;
  374. unsigned int mask;
  375. unsigned int val;
  376. };
  377. struct bd718xx_regulator_data {
  378. struct regulator_desc desc;
  379. const struct rohm_dvs_config dvs;
  380. const struct reg_init init;
  381. const struct reg_init *additional_inits;
  382. int additional_init_amnt;
  383. };
  384. static int bd718x7_xvp_sanity_check(struct regulator_dev *rdev, int lim_uV,
  385. int severity)
  386. {
  387. /*
  388. * BD71837/47/50 ... (ICs supported by this driver) do not provide
  389. * warnings, only protection
  390. */
  391. if (severity != REGULATOR_SEVERITY_PROT) {
  392. dev_err(&rdev->dev,
  393. "Unsupported Under Voltage protection level\n");
  394. return -EINVAL;
  395. }
  396. /*
  397. * And protection limit is not changeable. It can only be enabled
  398. * or disabled
  399. */
  400. if (lim_uV)
  401. return -EINVAL;
  402. return 0;
  403. }
  404. static int bd718x7_set_ldo_uvp(struct regulator_dev *rdev, int lim_uV,
  405. int severity, bool enable)
  406. {
  407. int ldo_offset = rdev->desc->id - BD718XX_LDO1;
  408. int prot_bit, ret;
  409. ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
  410. if (ret)
  411. return ret;
  412. prot_bit = BD718XX_LDO1_VRMON80 << ldo_offset;
  413. if (enable)
  414. return regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
  415. prot_bit);
  416. return regmap_set_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
  417. prot_bit);
  418. }
  419. static int bd718x7_get_buck_prot_reg(int id, int *reg)
  420. {
  421. if (id > BD718XX_BUCK8) {
  422. WARN_ON(id > BD718XX_BUCK8);
  423. return -EINVAL;
  424. }
  425. if (id > BD718XX_BUCK4)
  426. *reg = BD718XX_REG_MVRFLTMASK0;
  427. else
  428. *reg = BD718XX_REG_MVRFLTMASK1;
  429. return 0;
  430. }
  431. static int bd718x7_get_buck_ovp_info(int id, int *reg, int *bit)
  432. {
  433. int ret;
  434. ret = bd718x7_get_buck_prot_reg(id, reg);
  435. if (ret)
  436. return ret;
  437. *bit = BIT((id % 4) * 2 + 1);
  438. return 0;
  439. }
  440. static int bd718x7_get_buck_uvp_info(int id, int *reg, int *bit)
  441. {
  442. int ret;
  443. ret = bd718x7_get_buck_prot_reg(id, reg);
  444. if (ret)
  445. return ret;
  446. *bit = BIT((id % 4) * 2);
  447. return 0;
  448. }
  449. static int bd718x7_set_buck_uvp(struct regulator_dev *rdev, int lim_uV,
  450. int severity, bool enable)
  451. {
  452. int bit, reg, ret;
  453. ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
  454. if (ret)
  455. return ret;
  456. ret = bd718x7_get_buck_uvp_info(rdev->desc->id, &reg, &bit);
  457. if (ret)
  458. return ret;
  459. if (enable)
  460. return regmap_clear_bits(rdev->regmap, reg, bit);
  461. return regmap_set_bits(rdev->regmap, reg, bit);
  462. }
  463. static int bd718x7_set_buck_ovp(struct regulator_dev *rdev, int lim_uV,
  464. int severity,
  465. bool enable)
  466. {
  467. int bit, reg, ret;
  468. ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
  469. if (ret)
  470. return ret;
  471. ret = bd718x7_get_buck_ovp_info(rdev->desc->id, &reg, &bit);
  472. if (ret)
  473. return ret;
  474. if (enable)
  475. return regmap_clear_bits(rdev->regmap, reg, bit);
  476. return regmap_set_bits(rdev->regmap, reg, bit);
  477. }
  478. /*
  479. * OPS common for BD71847 and BD71850
  480. */
  481. BD718XX_OPS(bd718xx_pickable_range_ldo_ops,
  482. regulator_list_voltage_pickable_linear_range, NULL,
  483. bd718xx_set_voltage_sel_pickable_restricted,
  484. regulator_get_voltage_sel_pickable_regmap, NULL, NULL,
  485. bd718x7_set_ldo_uvp, NULL);
  486. /* BD71847 and BD71850 LDO 5 is by default OFF at RUN state */
  487. static const struct regulator_ops bd718xx_ldo5_ops_hwstate = {
  488. .is_enabled = never_enabled_by_hwstate,
  489. .list_voltage = regulator_list_voltage_pickable_linear_range,
  490. .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
  491. .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
  492. .set_under_voltage_protection = bd718x7_set_ldo_uvp,
  493. };
  494. BD718XX_OPS(bd718xx_pickable_range_buck_ops,
  495. regulator_list_voltage_pickable_linear_range, NULL,
  496. regulator_set_voltage_sel_pickable_regmap,
  497. regulator_get_voltage_sel_pickable_regmap,
  498. regulator_set_voltage_time_sel, NULL, bd718x7_set_buck_uvp,
  499. bd718x7_set_buck_ovp);
  500. BD718XX_OPS(bd718xx_ldo_regulator_ops, regulator_list_voltage_linear_range,
  501. NULL, bd718xx_set_voltage_sel_restricted,
  502. regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp,
  503. NULL);
  504. BD718XX_OPS(bd718xx_ldo_regulator_nolinear_ops, regulator_list_voltage_table,
  505. NULL, bd718xx_set_voltage_sel_restricted,
  506. regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp,
  507. NULL);
  508. BD718XX_OPS(bd718xx_buck_regulator_ops, regulator_list_voltage_linear_range,
  509. NULL, regulator_set_voltage_sel_regmap,
  510. regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  511. NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp);
  512. BD718XX_OPS(bd718xx_buck_regulator_nolinear_ops, regulator_list_voltage_table,
  513. regulator_map_voltage_ascend, regulator_set_voltage_sel_regmap,
  514. regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  515. NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp);
  516. /*
  517. * OPS for BD71837
  518. */
  519. BD718XX_OPS(bd71837_pickable_range_ldo_ops,
  520. regulator_list_voltage_pickable_linear_range, NULL,
  521. bd71837_set_voltage_sel_pickable_restricted,
  522. regulator_get_voltage_sel_pickable_regmap, NULL, NULL,
  523. bd718x7_set_ldo_uvp, NULL);
  524. BD718XX_OPS(bd71837_pickable_range_buck_ops,
  525. regulator_list_voltage_pickable_linear_range, NULL,
  526. bd71837_set_voltage_sel_pickable_restricted,
  527. regulator_get_voltage_sel_pickable_regmap,
  528. regulator_set_voltage_time_sel, NULL, bd718x7_set_buck_uvp,
  529. bd718x7_set_buck_ovp);
  530. BD718XX_OPS(bd71837_ldo_regulator_ops, regulator_list_voltage_linear_range,
  531. NULL, rohm_regulator_set_voltage_sel_restricted,
  532. regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp,
  533. NULL);
  534. BD718XX_OPS(bd71837_ldo_regulator_nolinear_ops, regulator_list_voltage_table,
  535. NULL, rohm_regulator_set_voltage_sel_restricted,
  536. regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp,
  537. NULL);
  538. BD718XX_OPS(bd71837_buck_regulator_ops, regulator_list_voltage_linear_range,
  539. NULL, rohm_regulator_set_voltage_sel_restricted,
  540. regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  541. NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp);
  542. BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_table,
  543. regulator_map_voltage_ascend, rohm_regulator_set_voltage_sel_restricted,
  544. regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  545. NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp);
  546. /*
  547. * BD71837 bucks 3 and 4 support defining their enable/disable state also
  548. * when buck enable state is under HW state machine control. In that case the
  549. * bit [2] in CTRL register is used to indicate if regulator should be ON.
  550. */
  551. static const struct regulator_ops bd71837_buck34_ops_hwctrl = {
  552. .is_enabled = bd71837_get_buck34_enable_hwctrl,
  553. .list_voltage = regulator_list_voltage_linear_range,
  554. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  555. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  556. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  557. .set_ramp_delay = regulator_set_ramp_delay_regmap,
  558. .set_under_voltage_protection = bd718x7_set_buck_uvp,
  559. .set_over_voltage_protection = bd718x7_set_buck_ovp,
  560. };
  561. /*
  562. * OPS for all of the ICs - BD718(37/47/50)
  563. */
  564. BD718XX_OPS(bd718xx_dvs_buck_regulator_ops, regulator_list_voltage_linear_range,
  565. NULL, regulator_set_voltage_sel_regmap,
  566. regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  567. regulator_set_ramp_delay_regmap, bd718x7_set_buck_uvp,
  568. bd718x7_set_buck_ovp);
  569. /*
  570. * There is a HW quirk in BD71837. The shutdown sequence timings for
  571. * bucks/LDOs which are controlled via register interface are changed.
  572. * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
  573. * beginning of shut-down sequence. As bucks 6 and 7 are parent
  574. * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
  575. * monitoring to errorneously detect under voltage and force PMIC to
  576. * emergency state instead of poweroff. In order to avoid this we
  577. * disable voltage monitoring for LDO5 and LDO6
  578. */
  579. static const struct reg_init bd71837_ldo5_inits[] = {
  580. {
  581. .reg = BD718XX_REG_MVRFLTMASK2,
  582. .mask = BD718XX_LDO5_VRMON80,
  583. .val = BD718XX_LDO5_VRMON80,
  584. },
  585. };
  586. static const struct reg_init bd71837_ldo6_inits[] = {
  587. {
  588. .reg = BD718XX_REG_MVRFLTMASK2,
  589. .mask = BD718XX_LDO6_VRMON80,
  590. .val = BD718XX_LDO6_VRMON80,
  591. },
  592. };
  593. static int buck_set_hw_dvs_levels(struct device_node *np,
  594. const struct regulator_desc *desc,
  595. struct regulator_config *cfg)
  596. {
  597. const struct bd718xx_regulator_data *data;
  598. data = container_of_const(desc, struct bd718xx_regulator_data, desc);
  599. return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
  600. }
  601. static const struct regulator_ops *bd71847_swcontrol_ops[] = {
  602. &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
  603. &bd718xx_pickable_range_buck_ops, &bd718xx_pickable_range_buck_ops,
  604. &bd718xx_buck_regulator_nolinear_ops, &bd718xx_buck_regulator_ops,
  605. &bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_nolinear_ops,
  606. &bd718xx_ldo_regulator_ops, &bd718xx_ldo_regulator_ops,
  607. &bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_ops,
  608. };
  609. static const struct regulator_ops *bd71847_hwcontrol_ops[] = {
  610. &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
  611. &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
  612. &BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops),
  613. &BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops),
  614. &BD718XX_HWOPNAME(bd718xx_buck_regulator_nolinear_ops),
  615. &BD718XX_HWOPNAME(bd718xx_buck_regulator_ops),
  616. &BD718XX_HWOPNAME(bd718xx_pickable_range_ldo_ops),
  617. &BD718XX_HWOPNAME(bd718xx_ldo_regulator_nolinear_ops),
  618. &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
  619. &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
  620. &bd718xx_ldo5_ops_hwstate,
  621. &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
  622. };
  623. static struct bd718xx_regulator_data bd71847_regulators[] = {
  624. {
  625. .desc = {
  626. .name = "buck1",
  627. .of_match = of_match_ptr("BUCK1"),
  628. .regulators_node = of_match_ptr("regulators"),
  629. .id = BD718XX_BUCK1,
  630. .type = REGULATOR_VOLTAGE,
  631. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  632. .linear_ranges = bd718xx_dvs_buck_volts,
  633. .n_linear_ranges =
  634. ARRAY_SIZE(bd718xx_dvs_buck_volts),
  635. .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  636. .vsel_mask = DVS_BUCK_RUN_MASK,
  637. .enable_reg = BD718XX_REG_BUCK1_CTRL,
  638. .enable_mask = BD718XX_BUCK_EN,
  639. .enable_time = BD71847_BUCK1_STARTUP_TIME,
  640. .owner = THIS_MODULE,
  641. .ramp_delay_table = bd718xx_ramp_delay,
  642. .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
  643. .ramp_reg = BD718XX_REG_BUCK1_CTRL,
  644. .ramp_mask = BUCK_RAMPRATE_MASK,
  645. .of_parse_cb = buck_set_hw_dvs_levels,
  646. },
  647. .dvs = {
  648. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  649. ROHM_DVS_LEVEL_SUSPEND,
  650. .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  651. .run_mask = DVS_BUCK_RUN_MASK,
  652. .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
  653. .idle_mask = DVS_BUCK_RUN_MASK,
  654. .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
  655. .suspend_mask = DVS_BUCK_RUN_MASK,
  656. },
  657. .init = {
  658. .reg = BD718XX_REG_BUCK1_CTRL,
  659. .mask = BD718XX_BUCK_SEL,
  660. .val = BD718XX_BUCK_SEL,
  661. },
  662. },
  663. {
  664. .desc = {
  665. .name = "buck2",
  666. .of_match = of_match_ptr("BUCK2"),
  667. .regulators_node = of_match_ptr("regulators"),
  668. .id = BD718XX_BUCK2,
  669. .type = REGULATOR_VOLTAGE,
  670. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  671. .linear_ranges = bd718xx_dvs_buck_volts,
  672. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  673. .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  674. .vsel_mask = DVS_BUCK_RUN_MASK,
  675. .enable_reg = BD718XX_REG_BUCK2_CTRL,
  676. .enable_mask = BD718XX_BUCK_EN,
  677. .enable_time = BD71847_BUCK2_STARTUP_TIME,
  678. .ramp_delay_table = bd718xx_ramp_delay,
  679. .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
  680. .ramp_reg = BD718XX_REG_BUCK2_CTRL,
  681. .ramp_mask = BUCK_RAMPRATE_MASK,
  682. .owner = THIS_MODULE,
  683. .of_parse_cb = buck_set_hw_dvs_levels,
  684. },
  685. .dvs = {
  686. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
  687. .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  688. .run_mask = DVS_BUCK_RUN_MASK,
  689. .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
  690. .idle_mask = DVS_BUCK_RUN_MASK,
  691. },
  692. .init = {
  693. .reg = BD718XX_REG_BUCK2_CTRL,
  694. .mask = BD718XX_BUCK_SEL,
  695. .val = BD718XX_BUCK_SEL,
  696. },
  697. },
  698. {
  699. .desc = {
  700. .name = "buck3",
  701. .of_match = of_match_ptr("BUCK3"),
  702. .regulators_node = of_match_ptr("regulators"),
  703. .id = BD718XX_BUCK3,
  704. .type = REGULATOR_VOLTAGE,
  705. .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
  706. .linear_ranges = bd71847_buck3_volts,
  707. .n_linear_ranges =
  708. ARRAY_SIZE(bd71847_buck3_volts),
  709. .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  710. .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
  711. .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  712. .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
  713. .linear_range_selectors_bitfield = bd71847_buck3_volt_range_sel,
  714. .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  715. .enable_mask = BD718XX_BUCK_EN,
  716. .enable_time = BD71847_BUCK3_STARTUP_TIME,
  717. .owner = THIS_MODULE,
  718. },
  719. .init = {
  720. .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  721. .mask = BD718XX_BUCK_SEL,
  722. .val = BD718XX_BUCK_SEL,
  723. },
  724. },
  725. {
  726. .desc = {
  727. .name = "buck4",
  728. .of_match = of_match_ptr("BUCK4"),
  729. .regulators_node = of_match_ptr("regulators"),
  730. .id = BD718XX_BUCK4,
  731. .type = REGULATOR_VOLTAGE,
  732. .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
  733. .linear_ranges = bd71847_buck4_volts,
  734. .n_linear_ranges =
  735. ARRAY_SIZE(bd71847_buck4_volts),
  736. .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  737. .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  738. .vsel_mask = BD71847_BUCK4_MASK,
  739. .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  740. .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
  741. .linear_range_selectors_bitfield = bd71847_buck4_volt_range_sel,
  742. .enable_mask = BD718XX_BUCK_EN,
  743. .enable_time = BD71847_BUCK4_STARTUP_TIME,
  744. .owner = THIS_MODULE,
  745. },
  746. .init = {
  747. .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  748. .mask = BD718XX_BUCK_SEL,
  749. .val = BD718XX_BUCK_SEL,
  750. },
  751. },
  752. {
  753. .desc = {
  754. .name = "buck5",
  755. .of_match = of_match_ptr("BUCK5"),
  756. .regulators_node = of_match_ptr("regulators"),
  757. .id = BD718XX_BUCK5,
  758. .type = REGULATOR_VOLTAGE,
  759. .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
  760. .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
  761. .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
  762. .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
  763. .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  764. .enable_mask = BD718XX_BUCK_EN,
  765. .enable_time = BD71847_BUCK5_STARTUP_TIME,
  766. .owner = THIS_MODULE,
  767. },
  768. .init = {
  769. .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  770. .mask = BD718XX_BUCK_SEL,
  771. .val = BD718XX_BUCK_SEL,
  772. },
  773. },
  774. {
  775. .desc = {
  776. .name = "buck6",
  777. .of_match = of_match_ptr("BUCK6"),
  778. .regulators_node = of_match_ptr("regulators"),
  779. .id = BD718XX_BUCK6,
  780. .type = REGULATOR_VOLTAGE,
  781. .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
  782. .linear_ranges = bd718xx_4th_nodvs_buck_volts,
  783. .n_linear_ranges =
  784. ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
  785. .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
  786. .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
  787. .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  788. .enable_mask = BD718XX_BUCK_EN,
  789. .enable_time = BD71847_BUCK6_STARTUP_TIME,
  790. .owner = THIS_MODULE,
  791. },
  792. .init = {
  793. .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  794. .mask = BD718XX_BUCK_SEL,
  795. .val = BD718XX_BUCK_SEL,
  796. },
  797. },
  798. {
  799. .desc = {
  800. .name = "ldo1",
  801. .of_match = of_match_ptr("LDO1"),
  802. .regulators_node = of_match_ptr("regulators"),
  803. .id = BD718XX_LDO1,
  804. .type = REGULATOR_VOLTAGE,
  805. .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
  806. .linear_ranges = bd718xx_ldo1_volts,
  807. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
  808. .vsel_reg = BD718XX_REG_LDO1_VOLT,
  809. .vsel_mask = BD718XX_LDO1_MASK,
  810. .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
  811. .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
  812. .linear_range_selectors_bitfield = bd718xx_ldo1_volt_range_sel,
  813. .enable_reg = BD718XX_REG_LDO1_VOLT,
  814. .enable_mask = BD718XX_LDO_EN,
  815. .enable_time = BD71847_LDO1_STARTUP_TIME,
  816. .owner = THIS_MODULE,
  817. },
  818. .init = {
  819. .reg = BD718XX_REG_LDO1_VOLT,
  820. .mask = BD718XX_LDO_SEL,
  821. .val = BD718XX_LDO_SEL,
  822. },
  823. },
  824. {
  825. .desc = {
  826. .name = "ldo2",
  827. .of_match = of_match_ptr("LDO2"),
  828. .regulators_node = of_match_ptr("regulators"),
  829. .id = BD718XX_LDO2,
  830. .type = REGULATOR_VOLTAGE,
  831. .volt_table = &ldo_2_volts[0],
  832. .vsel_reg = BD718XX_REG_LDO2_VOLT,
  833. .vsel_mask = BD718XX_LDO2_MASK,
  834. .n_voltages = ARRAY_SIZE(ldo_2_volts),
  835. .enable_reg = BD718XX_REG_LDO2_VOLT,
  836. .enable_mask = BD718XX_LDO_EN,
  837. .enable_time = BD71847_LDO2_STARTUP_TIME,
  838. .owner = THIS_MODULE,
  839. },
  840. .init = {
  841. .reg = BD718XX_REG_LDO2_VOLT,
  842. .mask = BD718XX_LDO_SEL,
  843. .val = BD718XX_LDO_SEL,
  844. },
  845. },
  846. {
  847. .desc = {
  848. .name = "ldo3",
  849. .of_match = of_match_ptr("LDO3"),
  850. .regulators_node = of_match_ptr("regulators"),
  851. .id = BD718XX_LDO3,
  852. .type = REGULATOR_VOLTAGE,
  853. .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
  854. .linear_ranges = bd718xx_ldo3_volts,
  855. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
  856. .vsel_reg = BD718XX_REG_LDO3_VOLT,
  857. .vsel_mask = BD718XX_LDO3_MASK,
  858. .enable_reg = BD718XX_REG_LDO3_VOLT,
  859. .enable_mask = BD718XX_LDO_EN,
  860. .enable_time = BD71847_LDO3_STARTUP_TIME,
  861. .owner = THIS_MODULE,
  862. },
  863. .init = {
  864. .reg = BD718XX_REG_LDO3_VOLT,
  865. .mask = BD718XX_LDO_SEL,
  866. .val = BD718XX_LDO_SEL,
  867. },
  868. },
  869. {
  870. .desc = {
  871. .name = "ldo4",
  872. .of_match = of_match_ptr("LDO4"),
  873. .regulators_node = of_match_ptr("regulators"),
  874. .id = BD718XX_LDO4,
  875. .type = REGULATOR_VOLTAGE,
  876. .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
  877. .linear_ranges = bd718xx_ldo4_volts,
  878. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
  879. .vsel_reg = BD718XX_REG_LDO4_VOLT,
  880. .vsel_mask = BD718XX_LDO4_MASK,
  881. .enable_reg = BD718XX_REG_LDO4_VOLT,
  882. .enable_mask = BD718XX_LDO_EN,
  883. .enable_time = BD71847_LDO4_STARTUP_TIME,
  884. .owner = THIS_MODULE,
  885. },
  886. .init = {
  887. .reg = BD718XX_REG_LDO4_VOLT,
  888. .mask = BD718XX_LDO_SEL,
  889. .val = BD718XX_LDO_SEL,
  890. },
  891. },
  892. {
  893. .desc = {
  894. .name = "ldo5",
  895. .of_match = of_match_ptr("LDO5"),
  896. .regulators_node = of_match_ptr("regulators"),
  897. .id = BD718XX_LDO5,
  898. .type = REGULATOR_VOLTAGE,
  899. .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
  900. .linear_ranges = bd71847_ldo5_volts,
  901. .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
  902. .vsel_reg = BD718XX_REG_LDO5_VOLT,
  903. .vsel_mask = BD71847_LDO5_MASK,
  904. .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
  905. .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
  906. .linear_range_selectors_bitfield = bd71847_ldo5_volt_range_sel,
  907. .enable_reg = BD718XX_REG_LDO5_VOLT,
  908. .enable_mask = BD718XX_LDO_EN,
  909. .enable_time = BD71847_LDO5_STARTUP_TIME,
  910. .owner = THIS_MODULE,
  911. },
  912. .init = {
  913. .reg = BD718XX_REG_LDO5_VOLT,
  914. .mask = BD718XX_LDO_SEL,
  915. .val = BD718XX_LDO_SEL,
  916. },
  917. },
  918. {
  919. .desc = {
  920. .name = "ldo6",
  921. .of_match = of_match_ptr("LDO6"),
  922. .regulators_node = of_match_ptr("regulators"),
  923. .id = BD718XX_LDO6,
  924. .type = REGULATOR_VOLTAGE,
  925. .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
  926. .linear_ranges = bd718xx_ldo6_volts,
  927. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
  928. /* LDO6 is supplied by buck5 */
  929. .supply_name = "buck5",
  930. .vsel_reg = BD718XX_REG_LDO6_VOLT,
  931. .vsel_mask = BD718XX_LDO6_MASK,
  932. .enable_reg = BD718XX_REG_LDO6_VOLT,
  933. .enable_mask = BD718XX_LDO_EN,
  934. .enable_time = BD71847_LDO6_STARTUP_TIME,
  935. .owner = THIS_MODULE,
  936. },
  937. .init = {
  938. .reg = BD718XX_REG_LDO6_VOLT,
  939. .mask = BD718XX_LDO_SEL,
  940. .val = BD718XX_LDO_SEL,
  941. },
  942. },
  943. };
  944. static const struct regulator_ops *bd71837_swcontrol_ops[] = {
  945. &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
  946. &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
  947. &bd71837_pickable_range_buck_ops, &bd71837_buck_regulator_ops,
  948. &bd71837_buck_regulator_nolinear_ops, &bd71837_buck_regulator_ops,
  949. &bd71837_pickable_range_ldo_ops, &bd71837_ldo_regulator_nolinear_ops,
  950. &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
  951. &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
  952. &bd71837_ldo_regulator_ops,
  953. };
  954. static const struct regulator_ops *bd71837_hwcontrol_ops[] = {
  955. &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
  956. &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
  957. &bd71837_buck34_ops_hwctrl, &bd71837_buck34_ops_hwctrl,
  958. &BD718XX_HWOPNAME(bd71837_pickable_range_buck_ops),
  959. &BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
  960. &BD718XX_HWOPNAME(bd71837_buck_regulator_nolinear_ops),
  961. &BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
  962. &BD718XX_HWOPNAME(bd71837_pickable_range_ldo_ops),
  963. &BD718XX_HWOPNAME(bd71837_ldo_regulator_nolinear_ops),
  964. &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  965. &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  966. &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  967. &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  968. &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  969. };
  970. static struct bd718xx_regulator_data bd71837_regulators[] = {
  971. {
  972. .desc = {
  973. .name = "buck1",
  974. .of_match = of_match_ptr("BUCK1"),
  975. .regulators_node = of_match_ptr("regulators"),
  976. .id = BD718XX_BUCK1,
  977. .type = REGULATOR_VOLTAGE,
  978. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  979. .linear_ranges = bd718xx_dvs_buck_volts,
  980. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  981. .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  982. .vsel_mask = DVS_BUCK_RUN_MASK,
  983. .enable_reg = BD718XX_REG_BUCK1_CTRL,
  984. .enable_mask = BD718XX_BUCK_EN,
  985. .enable_time = BD71837_BUCK1_STARTUP_TIME,
  986. .ramp_delay_table = bd718xx_ramp_delay,
  987. .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
  988. .ramp_reg = BD718XX_REG_BUCK1_CTRL,
  989. .ramp_mask = BUCK_RAMPRATE_MASK,
  990. .owner = THIS_MODULE,
  991. .of_parse_cb = buck_set_hw_dvs_levels,
  992. },
  993. .dvs = {
  994. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  995. ROHM_DVS_LEVEL_SUSPEND,
  996. .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  997. .run_mask = DVS_BUCK_RUN_MASK,
  998. .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
  999. .idle_mask = DVS_BUCK_RUN_MASK,
  1000. .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
  1001. .suspend_mask = DVS_BUCK_RUN_MASK,
  1002. },
  1003. .init = {
  1004. .reg = BD718XX_REG_BUCK1_CTRL,
  1005. .mask = BD718XX_BUCK_SEL,
  1006. .val = BD718XX_BUCK_SEL,
  1007. },
  1008. },
  1009. {
  1010. .desc = {
  1011. .name = "buck2",
  1012. .of_match = of_match_ptr("BUCK2"),
  1013. .regulators_node = of_match_ptr("regulators"),
  1014. .id = BD718XX_BUCK2,
  1015. .type = REGULATOR_VOLTAGE,
  1016. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  1017. .linear_ranges = bd718xx_dvs_buck_volts,
  1018. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  1019. .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  1020. .vsel_mask = DVS_BUCK_RUN_MASK,
  1021. .enable_reg = BD718XX_REG_BUCK2_CTRL,
  1022. .enable_mask = BD718XX_BUCK_EN,
  1023. .enable_time = BD71837_BUCK2_STARTUP_TIME,
  1024. .ramp_delay_table = bd718xx_ramp_delay,
  1025. .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
  1026. .ramp_reg = BD718XX_REG_BUCK2_CTRL,
  1027. .ramp_mask = BUCK_RAMPRATE_MASK,
  1028. .owner = THIS_MODULE,
  1029. .of_parse_cb = buck_set_hw_dvs_levels,
  1030. },
  1031. .dvs = {
  1032. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
  1033. .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  1034. .run_mask = DVS_BUCK_RUN_MASK,
  1035. .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
  1036. .idle_mask = DVS_BUCK_RUN_MASK,
  1037. },
  1038. .init = {
  1039. .reg = BD718XX_REG_BUCK2_CTRL,
  1040. .mask = BD718XX_BUCK_SEL,
  1041. .val = BD718XX_BUCK_SEL,
  1042. },
  1043. },
  1044. {
  1045. .desc = {
  1046. .name = "buck3",
  1047. .of_match = of_match_ptr("BUCK3"),
  1048. .regulators_node = of_match_ptr("regulators"),
  1049. .id = BD718XX_BUCK3,
  1050. .type = REGULATOR_VOLTAGE,
  1051. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  1052. .linear_ranges = bd718xx_dvs_buck_volts,
  1053. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  1054. .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
  1055. .vsel_mask = DVS_BUCK_RUN_MASK,
  1056. .enable_reg = BD71837_REG_BUCK3_CTRL,
  1057. .enable_mask = BD718XX_BUCK_EN,
  1058. .enable_time = BD71837_BUCK3_STARTUP_TIME,
  1059. .ramp_delay_table = bd718xx_ramp_delay,
  1060. .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
  1061. .ramp_reg = BD71837_REG_BUCK3_CTRL,
  1062. .ramp_mask = BUCK_RAMPRATE_MASK,
  1063. .owner = THIS_MODULE,
  1064. .of_parse_cb = buck_set_hw_dvs_levels,
  1065. },
  1066. .dvs = {
  1067. .level_map = ROHM_DVS_LEVEL_RUN,
  1068. .run_reg = BD71837_REG_BUCK3_VOLT_RUN,
  1069. .run_mask = DVS_BUCK_RUN_MASK,
  1070. },
  1071. .init = {
  1072. .reg = BD71837_REG_BUCK3_CTRL,
  1073. .mask = BD718XX_BUCK_SEL,
  1074. .val = BD718XX_BUCK_SEL,
  1075. },
  1076. },
  1077. {
  1078. .desc = {
  1079. .name = "buck4",
  1080. .of_match = of_match_ptr("BUCK4"),
  1081. .regulators_node = of_match_ptr("regulators"),
  1082. .id = BD718XX_BUCK4,
  1083. .type = REGULATOR_VOLTAGE,
  1084. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  1085. .linear_ranges = bd718xx_dvs_buck_volts,
  1086. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  1087. .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
  1088. .vsel_mask = DVS_BUCK_RUN_MASK,
  1089. .enable_reg = BD71837_REG_BUCK4_CTRL,
  1090. .enable_mask = BD718XX_BUCK_EN,
  1091. .enable_time = BD71837_BUCK4_STARTUP_TIME,
  1092. .ramp_delay_table = bd718xx_ramp_delay,
  1093. .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
  1094. .ramp_reg = BD71837_REG_BUCK4_CTRL,
  1095. .ramp_mask = BUCK_RAMPRATE_MASK,
  1096. .owner = THIS_MODULE,
  1097. .of_parse_cb = buck_set_hw_dvs_levels,
  1098. },
  1099. .dvs = {
  1100. .level_map = ROHM_DVS_LEVEL_RUN,
  1101. .run_reg = BD71837_REG_BUCK4_VOLT_RUN,
  1102. .run_mask = DVS_BUCK_RUN_MASK,
  1103. },
  1104. .init = {
  1105. .reg = BD71837_REG_BUCK4_CTRL,
  1106. .mask = BD718XX_BUCK_SEL,
  1107. .val = BD718XX_BUCK_SEL,
  1108. },
  1109. },
  1110. {
  1111. .desc = {
  1112. .name = "buck5",
  1113. .of_match = of_match_ptr("BUCK5"),
  1114. .regulators_node = of_match_ptr("regulators"),
  1115. .id = BD718XX_BUCK5,
  1116. .type = REGULATOR_VOLTAGE,
  1117. .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
  1118. .linear_ranges = bd71837_buck5_volts,
  1119. .n_linear_ranges =
  1120. ARRAY_SIZE(bd71837_buck5_volts),
  1121. .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  1122. .vsel_mask = BD71837_BUCK5_MASK,
  1123. .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  1124. .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
  1125. .linear_range_selectors_bitfield = bd71837_buck5_volt_range_sel,
  1126. .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  1127. .enable_mask = BD718XX_BUCK_EN,
  1128. .enable_time = BD71837_BUCK5_STARTUP_TIME,
  1129. .owner = THIS_MODULE,
  1130. },
  1131. .init = {
  1132. .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  1133. .mask = BD718XX_BUCK_SEL,
  1134. .val = BD718XX_BUCK_SEL,
  1135. },
  1136. },
  1137. {
  1138. .desc = {
  1139. .name = "buck6",
  1140. .of_match = of_match_ptr("BUCK6"),
  1141. .regulators_node = of_match_ptr("regulators"),
  1142. .id = BD718XX_BUCK6,
  1143. .type = REGULATOR_VOLTAGE,
  1144. .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
  1145. .linear_ranges = bd71837_buck6_volts,
  1146. .n_linear_ranges =
  1147. ARRAY_SIZE(bd71837_buck6_volts),
  1148. .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  1149. .vsel_mask = BD71837_BUCK6_MASK,
  1150. .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  1151. .enable_mask = BD718XX_BUCK_EN,
  1152. .enable_time = BD71837_BUCK6_STARTUP_TIME,
  1153. .owner = THIS_MODULE,
  1154. },
  1155. .init = {
  1156. .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  1157. .mask = BD718XX_BUCK_SEL,
  1158. .val = BD718XX_BUCK_SEL,
  1159. },
  1160. },
  1161. {
  1162. .desc = {
  1163. .name = "buck7",
  1164. .of_match = of_match_ptr("BUCK7"),
  1165. .regulators_node = of_match_ptr("regulators"),
  1166. .id = BD718XX_BUCK7,
  1167. .type = REGULATOR_VOLTAGE,
  1168. .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
  1169. .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
  1170. .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
  1171. .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
  1172. .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  1173. .enable_mask = BD718XX_BUCK_EN,
  1174. .enable_time = BD71837_BUCK7_STARTUP_TIME,
  1175. .owner = THIS_MODULE,
  1176. },
  1177. .init = {
  1178. .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  1179. .mask = BD718XX_BUCK_SEL,
  1180. .val = BD718XX_BUCK_SEL,
  1181. },
  1182. },
  1183. {
  1184. .desc = {
  1185. .name = "buck8",
  1186. .of_match = of_match_ptr("BUCK8"),
  1187. .regulators_node = of_match_ptr("regulators"),
  1188. .id = BD718XX_BUCK8,
  1189. .type = REGULATOR_VOLTAGE,
  1190. .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
  1191. .linear_ranges = bd718xx_4th_nodvs_buck_volts,
  1192. .n_linear_ranges =
  1193. ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
  1194. .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
  1195. .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
  1196. .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  1197. .enable_mask = BD718XX_BUCK_EN,
  1198. .enable_time = BD71837_BUCK8_STARTUP_TIME,
  1199. .owner = THIS_MODULE,
  1200. },
  1201. .init = {
  1202. .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  1203. .mask = BD718XX_BUCK_SEL,
  1204. .val = BD718XX_BUCK_SEL,
  1205. },
  1206. },
  1207. {
  1208. .desc = {
  1209. .name = "ldo1",
  1210. .of_match = of_match_ptr("LDO1"),
  1211. .regulators_node = of_match_ptr("regulators"),
  1212. .id = BD718XX_LDO1,
  1213. .type = REGULATOR_VOLTAGE,
  1214. .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
  1215. .linear_ranges = bd718xx_ldo1_volts,
  1216. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
  1217. .vsel_reg = BD718XX_REG_LDO1_VOLT,
  1218. .vsel_mask = BD718XX_LDO1_MASK,
  1219. .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
  1220. .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
  1221. .linear_range_selectors_bitfield = bd718xx_ldo1_volt_range_sel,
  1222. .enable_reg = BD718XX_REG_LDO1_VOLT,
  1223. .enable_mask = BD718XX_LDO_EN,
  1224. .enable_time = BD71837_LDO1_STARTUP_TIME,
  1225. .owner = THIS_MODULE,
  1226. },
  1227. .init = {
  1228. .reg = BD718XX_REG_LDO1_VOLT,
  1229. .mask = BD718XX_LDO_SEL,
  1230. .val = BD718XX_LDO_SEL,
  1231. },
  1232. },
  1233. {
  1234. .desc = {
  1235. .name = "ldo2",
  1236. .of_match = of_match_ptr("LDO2"),
  1237. .regulators_node = of_match_ptr("regulators"),
  1238. .id = BD718XX_LDO2,
  1239. .type = REGULATOR_VOLTAGE,
  1240. .volt_table = &ldo_2_volts[0],
  1241. .vsel_reg = BD718XX_REG_LDO2_VOLT,
  1242. .vsel_mask = BD718XX_LDO2_MASK,
  1243. .n_voltages = ARRAY_SIZE(ldo_2_volts),
  1244. .enable_reg = BD718XX_REG_LDO2_VOLT,
  1245. .enable_mask = BD718XX_LDO_EN,
  1246. .enable_time = BD71837_LDO2_STARTUP_TIME,
  1247. .owner = THIS_MODULE,
  1248. },
  1249. .init = {
  1250. .reg = BD718XX_REG_LDO2_VOLT,
  1251. .mask = BD718XX_LDO_SEL,
  1252. .val = BD718XX_LDO_SEL,
  1253. },
  1254. },
  1255. {
  1256. .desc = {
  1257. .name = "ldo3",
  1258. .of_match = of_match_ptr("LDO3"),
  1259. .regulators_node = of_match_ptr("regulators"),
  1260. .id = BD718XX_LDO3,
  1261. .type = REGULATOR_VOLTAGE,
  1262. .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
  1263. .linear_ranges = bd718xx_ldo3_volts,
  1264. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
  1265. .vsel_reg = BD718XX_REG_LDO3_VOLT,
  1266. .vsel_mask = BD718XX_LDO3_MASK,
  1267. .enable_reg = BD718XX_REG_LDO3_VOLT,
  1268. .enable_mask = BD718XX_LDO_EN,
  1269. .enable_time = BD71837_LDO3_STARTUP_TIME,
  1270. .owner = THIS_MODULE,
  1271. },
  1272. .init = {
  1273. .reg = BD718XX_REG_LDO3_VOLT,
  1274. .mask = BD718XX_LDO_SEL,
  1275. .val = BD718XX_LDO_SEL,
  1276. },
  1277. },
  1278. {
  1279. .desc = {
  1280. .name = "ldo4",
  1281. .of_match = of_match_ptr("LDO4"),
  1282. .regulators_node = of_match_ptr("regulators"),
  1283. .id = BD718XX_LDO4,
  1284. .type = REGULATOR_VOLTAGE,
  1285. .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
  1286. .linear_ranges = bd718xx_ldo4_volts,
  1287. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
  1288. .vsel_reg = BD718XX_REG_LDO4_VOLT,
  1289. .vsel_mask = BD718XX_LDO4_MASK,
  1290. .enable_reg = BD718XX_REG_LDO4_VOLT,
  1291. .enable_mask = BD718XX_LDO_EN,
  1292. .enable_time = BD71837_LDO4_STARTUP_TIME,
  1293. .owner = THIS_MODULE,
  1294. },
  1295. .init = {
  1296. .reg = BD718XX_REG_LDO4_VOLT,
  1297. .mask = BD718XX_LDO_SEL,
  1298. .val = BD718XX_LDO_SEL,
  1299. },
  1300. },
  1301. {
  1302. .desc = {
  1303. .name = "ldo5",
  1304. .of_match = of_match_ptr("LDO5"),
  1305. .regulators_node = of_match_ptr("regulators"),
  1306. .id = BD718XX_LDO5,
  1307. .type = REGULATOR_VOLTAGE,
  1308. .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
  1309. .linear_ranges = bd71837_ldo5_volts,
  1310. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
  1311. /* LDO5 is supplied by buck6 */
  1312. .supply_name = "buck6",
  1313. .vsel_reg = BD718XX_REG_LDO5_VOLT,
  1314. .vsel_mask = BD71837_LDO5_MASK,
  1315. .enable_reg = BD718XX_REG_LDO5_VOLT,
  1316. .enable_mask = BD718XX_LDO_EN,
  1317. .enable_time = BD71837_LDO5_STARTUP_TIME,
  1318. .owner = THIS_MODULE,
  1319. },
  1320. .init = {
  1321. .reg = BD718XX_REG_LDO5_VOLT,
  1322. .mask = BD718XX_LDO_SEL,
  1323. .val = BD718XX_LDO_SEL,
  1324. },
  1325. .additional_inits = bd71837_ldo5_inits,
  1326. .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
  1327. },
  1328. {
  1329. .desc = {
  1330. .name = "ldo6",
  1331. .of_match = of_match_ptr("LDO6"),
  1332. .regulators_node = of_match_ptr("regulators"),
  1333. .id = BD718XX_LDO6,
  1334. .type = REGULATOR_VOLTAGE,
  1335. .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
  1336. .linear_ranges = bd718xx_ldo6_volts,
  1337. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
  1338. /* LDO6 is supplied by buck7 */
  1339. .supply_name = "buck7",
  1340. .vsel_reg = BD718XX_REG_LDO6_VOLT,
  1341. .vsel_mask = BD718XX_LDO6_MASK,
  1342. .enable_reg = BD718XX_REG_LDO6_VOLT,
  1343. .enable_mask = BD718XX_LDO_EN,
  1344. .enable_time = BD71837_LDO6_STARTUP_TIME,
  1345. .owner = THIS_MODULE,
  1346. },
  1347. .init = {
  1348. .reg = BD718XX_REG_LDO6_VOLT,
  1349. .mask = BD718XX_LDO_SEL,
  1350. .val = BD718XX_LDO_SEL,
  1351. },
  1352. .additional_inits = bd71837_ldo6_inits,
  1353. .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
  1354. },
  1355. {
  1356. .desc = {
  1357. .name = "ldo7",
  1358. .of_match = of_match_ptr("LDO7"),
  1359. .regulators_node = of_match_ptr("regulators"),
  1360. .id = BD718XX_LDO7,
  1361. .type = REGULATOR_VOLTAGE,
  1362. .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
  1363. .linear_ranges = bd71837_ldo7_volts,
  1364. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
  1365. .vsel_reg = BD71837_REG_LDO7_VOLT,
  1366. .vsel_mask = BD71837_LDO7_MASK,
  1367. .enable_reg = BD71837_REG_LDO7_VOLT,
  1368. .enable_mask = BD718XX_LDO_EN,
  1369. .enable_time = BD71837_LDO7_STARTUP_TIME,
  1370. .owner = THIS_MODULE,
  1371. },
  1372. .init = {
  1373. .reg = BD71837_REG_LDO7_VOLT,
  1374. .mask = BD718XX_LDO_SEL,
  1375. .val = BD718XX_LDO_SEL,
  1376. },
  1377. },
  1378. };
  1379. static void mark_hw_controlled(struct device *dev, struct device_node *np,
  1380. struct bd718xx_regulator_data *reg_data,
  1381. unsigned int num_reg_data, int *info)
  1382. {
  1383. int i;
  1384. for (i = 1; i <= num_reg_data; i++) {
  1385. if (!of_node_name_eq(np, reg_data[i-1].desc.of_match))
  1386. continue;
  1387. *info |= 1 << (i - 1);
  1388. dev_dbg(dev, "regulator %d runlevel controlled\n", i);
  1389. return;
  1390. }
  1391. dev_warn(dev, "Bad regulator node\n");
  1392. }
  1393. /*
  1394. * Setups where regulator (especially the buck8) output voltage is scaled
  1395. * by adding external connection where some other regulator output is connected
  1396. * to feedback-pin (over suitable resistors) is getting popular amongst users
  1397. * of BD71837. (This allows for example scaling down the buck8 voltages to suit
  1398. * lover GPU voltages for projects where buck8 is (ab)used to supply power
  1399. * for GPU. Additionally some setups do allow DVS for buck8 but as this do
  1400. * produce voltage spikes the HW must be evaluated to be able to survive this
  1401. * - hence I keep the DVS disabled for non DVS bucks by default. I don't want
  1402. * to help you burn your proto board)
  1403. *
  1404. * So we allow describing this external connection from DT and scale the
  1405. * voltages accordingly. This is what the connection should look like:
  1406. *
  1407. * |------------|
  1408. * | buck 8 |-------+----->Vout
  1409. * | | |
  1410. * |------------| |
  1411. * | FB pin |
  1412. * | |
  1413. * +-------+--R2---+
  1414. * |
  1415. * R1
  1416. * |
  1417. * V FB-pull-up
  1418. *
  1419. * Here the buck output is sifted according to formula:
  1420. *
  1421. * Vout_o = Vo - (Vpu - Vo)*R2/R1
  1422. * Linear_step = step_orig*(R1+R2)/R1
  1423. *
  1424. * where:
  1425. * Vout_o is adjusted voltage output at vsel reg value 0
  1426. * Vo is original voltage output at vsel reg value 0
  1427. * Vpu is the pull-up voltage V FB-pull-up in the picture
  1428. * R1 and R2 are resistor values.
  1429. *
  1430. * As a real world example for buck8 and a specific GPU:
  1431. * VLDO = 1.6V (used as FB-pull-up)
  1432. * R1 = 1000ohms
  1433. * R2 = 150ohms
  1434. * VSEL 0x0 => 0.8V – (VLDO – 0.8) * R2 / R1 = 0.68V
  1435. * Linear Step = 10mV * (R1 + R2) / R1 = 11.5mV
  1436. */
  1437. static int setup_feedback_loop(struct device *dev, struct device_node *np,
  1438. struct bd718xx_regulator_data *reg_data,
  1439. unsigned int num_reg_data, int fb_uv)
  1440. {
  1441. int i, r1, r2, ret;
  1442. /*
  1443. * We do adjust the values in the global desc based on DT settings.
  1444. * This may not be best approach as it can cause problems if more than
  1445. * one PMIC is controlled from same processor. I don't see such use-case
  1446. * for BD718x7 now - so we spare some bits.
  1447. *
  1448. * If this will point out to be a problem - then we can allocate new
  1449. * bd718xx_regulator_data array at probe and just use the global
  1450. * array as a template where we copy initial values. Then we can
  1451. * use allocated descs for regultor registration and do IC specific
  1452. * modifications to this copy while leaving other PMICs untouched. But
  1453. * that means allocating new array for each PMIC - and currently I see
  1454. * no need for that.
  1455. */
  1456. for (i = 0; i < num_reg_data; i++) {
  1457. struct regulator_desc *desc = &reg_data[i].desc;
  1458. int j;
  1459. if (!of_node_name_eq(np, desc->of_match))
  1460. continue;
  1461. /* The feedback loop connection does not make sense for LDOs */
  1462. if (desc->id >= BD718XX_LDO1)
  1463. return -EINVAL;
  1464. ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms",
  1465. &r1);
  1466. if (ret)
  1467. return ret;
  1468. if (!r1)
  1469. return -EINVAL;
  1470. ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms",
  1471. &r2);
  1472. if (ret)
  1473. return ret;
  1474. if (desc->n_linear_ranges && desc->linear_ranges) {
  1475. struct linear_range *new;
  1476. new = devm_kcalloc(dev, desc->n_linear_ranges,
  1477. sizeof(struct linear_range),
  1478. GFP_KERNEL);
  1479. if (!new)
  1480. return -ENOMEM;
  1481. for (j = 0; j < desc->n_linear_ranges; j++) {
  1482. int min = desc->linear_ranges[j].min;
  1483. int step = desc->linear_ranges[j].step;
  1484. min -= (fb_uv - min)*r2/r1;
  1485. step = step * (r1 + r2);
  1486. step /= r1;
  1487. new[j].min = min;
  1488. new[j].min_sel = desc->linear_ranges[j].min_sel;
  1489. new[j].max_sel = desc->linear_ranges[j].max_sel;
  1490. new[j].step = step;
  1491. dev_dbg(dev, "%s: old range min %d, step %d\n",
  1492. desc->name, desc->linear_ranges[j].min,
  1493. desc->linear_ranges[j].step);
  1494. dev_dbg(dev, "new range min %d, step %d\n", min,
  1495. step);
  1496. }
  1497. desc->linear_ranges = new;
  1498. }
  1499. dev_dbg(dev, "regulator '%s' has FB pull-up configured\n",
  1500. desc->name);
  1501. return 0;
  1502. }
  1503. return -ENODEV;
  1504. }
  1505. static int get_special_regulators(struct device *dev,
  1506. struct bd718xx_regulator_data *reg_data,
  1507. unsigned int num_reg_data, int *info)
  1508. {
  1509. int ret;
  1510. int uv;
  1511. *info = 0;
  1512. struct device_node *nproot __free(device_node) = of_get_child_by_name(dev->of_node,
  1513. "regulators");
  1514. if (!nproot) {
  1515. dev_err(dev, "failed to find regulators node\n");
  1516. return -ENODEV;
  1517. }
  1518. for_each_child_of_node_scoped(nproot, np) {
  1519. if (of_property_read_bool(np, "rohm,no-regulator-enable-control"))
  1520. mark_hw_controlled(dev, np, reg_data, num_reg_data,
  1521. info);
  1522. ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt",
  1523. &uv);
  1524. if (ret) {
  1525. if (ret == -EINVAL)
  1526. continue;
  1527. else
  1528. return ret;
  1529. }
  1530. ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv);
  1531. if (ret)
  1532. return ret;
  1533. }
  1534. return 0;
  1535. }
  1536. static int bd718xx_probe(struct platform_device *pdev)
  1537. {
  1538. struct regmap *regmap;
  1539. struct regulator_config config = { 0 };
  1540. int i, j, err, omit_enable;
  1541. bool use_snvs;
  1542. struct bd718xx_regulator_data *reg_data;
  1543. unsigned int num_reg_data;
  1544. enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
  1545. const struct regulator_ops **swops, **hwops;
  1546. regmap = dev_get_regmap(pdev->dev.parent, NULL);
  1547. if (!regmap) {
  1548. dev_err(&pdev->dev, "No MFD driver data\n");
  1549. return -EINVAL;
  1550. }
  1551. switch (chip) {
  1552. case ROHM_CHIP_TYPE_BD71837:
  1553. reg_data = bd71837_regulators;
  1554. num_reg_data = ARRAY_SIZE(bd71837_regulators);
  1555. swops = &bd71837_swcontrol_ops[0];
  1556. hwops = &bd71837_hwcontrol_ops[0];
  1557. break;
  1558. case ROHM_CHIP_TYPE_BD71847:
  1559. reg_data = bd71847_regulators;
  1560. num_reg_data = ARRAY_SIZE(bd71847_regulators);
  1561. swops = &bd71847_swcontrol_ops[0];
  1562. hwops = &bd71847_hwcontrol_ops[0];
  1563. break;
  1564. default:
  1565. dev_err(&pdev->dev, "Unsupported chip type\n");
  1566. return -EINVAL;
  1567. }
  1568. /* Register LOCK release */
  1569. err = regmap_update_bits(regmap, BD718XX_REG_REGLOCK,
  1570. (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
  1571. if (err)
  1572. return dev_err_probe(&pdev->dev, err, "Failed to unlock PMIC\n");
  1573. dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
  1574. BD718XX_REG_REGLOCK);
  1575. use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
  1576. "rohm,reset-snvs-powered");
  1577. /*
  1578. * Change the next stage from poweroff to be READY instead of SNVS
  1579. * for all reset types because OTP loading at READY will clear SEL
  1580. * bit allowing HW defaults for power rails to be used
  1581. */
  1582. if (!use_snvs) {
  1583. err = regmap_update_bits(regmap, BD718XX_REG_TRANS_COND1,
  1584. BD718XX_ON_REQ_POWEROFF_MASK |
  1585. BD718XX_SWRESET_POWEROFF_MASK |
  1586. BD718XX_WDOG_POWEROFF_MASK |
  1587. BD718XX_KEY_L_POWEROFF_MASK,
  1588. BD718XX_POWOFF_TO_RDY);
  1589. if (err)
  1590. return dev_err_probe(&pdev->dev, err,
  1591. "Failed to change reset target\n");
  1592. dev_dbg(&pdev->dev, "Changed all resets from SVNS to READY\n");
  1593. }
  1594. config.dev = pdev->dev.parent;
  1595. config.regmap = regmap;
  1596. /*
  1597. * There are cases when we want to leave the enable-control for
  1598. * the HW state machine and use this driver only for voltage control.
  1599. * One special case is when we use PMIC_STBY_REQ line from SoC to PMIC
  1600. * in order to set the system to SUSPEND state.
  1601. *
  1602. * If regulator is taken under SW control the regulator state will not
  1603. * be affected by PMIC state machine - Eg. regulator is likely to stay
  1604. * on even in SUSPEND
  1605. */
  1606. err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data,
  1607. &omit_enable);
  1608. if (err)
  1609. return err;
  1610. for (i = 0; i < num_reg_data; i++) {
  1611. struct regulator_desc *desc;
  1612. struct regulator_dev *rdev;
  1613. struct bd718xx_regulator_data *r;
  1614. int no_enable_control = omit_enable & (1 << i);
  1615. r = &reg_data[i];
  1616. desc = &r->desc;
  1617. if (no_enable_control)
  1618. desc->ops = hwops[i];
  1619. else
  1620. desc->ops = swops[i];
  1621. rdev = devm_regulator_register(&pdev->dev, desc, &config);
  1622. if (IS_ERR(rdev))
  1623. return dev_err_probe(&pdev->dev, PTR_ERR(rdev),
  1624. "failed to register %s regulator\n",
  1625. desc->name);
  1626. /*
  1627. * Regulator register gets the regulator constraints and
  1628. * applies them (set_machine_constraints). This should have
  1629. * turned the control register(s) to correct values and we
  1630. * can now switch the control from PMIC state machine to the
  1631. * register interface
  1632. *
  1633. * At poweroff transition PMIC HW disables EN bit for
  1634. * regulators but leaves SEL bit untouched. So if state
  1635. * transition from POWEROFF is done to SNVS - then all power
  1636. * rails controlled by SW (having SEL bit set) stay disabled
  1637. * as EN is cleared. This will result boot failure if any
  1638. * crucial systems are powered by these rails. We don't
  1639. * enable SW control for crucial regulators if snvs state is
  1640. * used
  1641. */
  1642. if (!no_enable_control && (!use_snvs ||
  1643. !rdev->constraints->always_on ||
  1644. !rdev->constraints->boot_on)) {
  1645. err = regmap_update_bits(regmap, r->init.reg,
  1646. r->init.mask, r->init.val);
  1647. if (err)
  1648. return dev_err_probe(&pdev->dev, err,
  1649. "Failed to take control for (%s)\n",
  1650. desc->name);
  1651. }
  1652. for (j = 0; j < r->additional_init_amnt; j++) {
  1653. err = regmap_update_bits(regmap,
  1654. r->additional_inits[j].reg,
  1655. r->additional_inits[j].mask,
  1656. r->additional_inits[j].val);
  1657. if (err)
  1658. return dev_err_probe(&pdev->dev, err,
  1659. "Buck (%s) initialization failed\n",
  1660. desc->name);
  1661. }
  1662. }
  1663. return err;
  1664. }
  1665. static const struct platform_device_id bd718x7_pmic_id[] = {
  1666. { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
  1667. { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
  1668. { },
  1669. };
  1670. MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id);
  1671. static struct platform_driver bd718xx_regulator = {
  1672. .driver = {
  1673. .name = "bd718xx-pmic",
  1674. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  1675. },
  1676. .probe = bd718xx_probe,
  1677. .id_table = bd718x7_pmic_id,
  1678. };
  1679. module_platform_driver(bd718xx_regulator);
  1680. MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
  1681. MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
  1682. MODULE_LICENSE("GPL");
  1683. MODULE_ALIAS("platform:bd718xx-pmic");