bd718x7-regulator.c 54 KB

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