bd718x7-regulator.c 53 KB

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