atc260x-regulator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // Regulator driver for ATC260x PMICs
  4. //
  5. // Copyright (C) 2019 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
  6. // Copyright (C) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
  7. #include <linux/mfd/atc260x/core.h>
  8. #include <linux/module.h>
  9. #include <linux/of.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/regmap.h>
  12. #include <linux/regulator/driver.h>
  13. struct atc260x_regulator_data {
  14. int voltage_time_dcdc;
  15. int voltage_time_ldo;
  16. };
  17. static const struct linear_range atc2603c_dcdc_voltage_ranges[] = {
  18. REGULATOR_LINEAR_RANGE(1300000, 0, 13, 50000),
  19. REGULATOR_LINEAR_RANGE(1950000, 14, 15, 100000),
  20. };
  21. static const struct linear_range atc2609a_dcdc_voltage_ranges[] = {
  22. REGULATOR_LINEAR_RANGE(600000, 0, 127, 6250),
  23. REGULATOR_LINEAR_RANGE(1400000, 128, 232, 25000),
  24. };
  25. static const struct linear_range atc2609a_ldo_voltage_ranges0[] = {
  26. REGULATOR_LINEAR_RANGE(700000, 0, 15, 100000),
  27. REGULATOR_LINEAR_RANGE(2100000, 0, 12, 100000),
  28. };
  29. static const struct linear_range atc2609a_ldo_voltage_ranges1[] = {
  30. REGULATOR_LINEAR_RANGE(850000, 0, 15, 100000),
  31. REGULATOR_LINEAR_RANGE(2100000, 0, 11, 100000),
  32. };
  33. static const unsigned int atc260x_ldo_voltage_range_sel[] = {
  34. 0x0, 0x1,
  35. };
  36. static int atc260x_dcdc_set_voltage_time_sel(struct regulator_dev *rdev,
  37. unsigned int old_selector,
  38. unsigned int new_selector)
  39. {
  40. struct atc260x_regulator_data *data = rdev_get_drvdata(rdev);
  41. if (new_selector > old_selector)
  42. return data->voltage_time_dcdc;
  43. return 0;
  44. }
  45. static int atc260x_ldo_set_voltage_time_sel(struct regulator_dev *rdev,
  46. unsigned int old_selector,
  47. unsigned int new_selector)
  48. {
  49. struct atc260x_regulator_data *data = rdev_get_drvdata(rdev);
  50. if (new_selector > old_selector)
  51. return data->voltage_time_ldo;
  52. return 0;
  53. }
  54. static const struct regulator_ops atc260x_dcdc_ops = {
  55. .enable = regulator_enable_regmap,
  56. .disable = regulator_disable_regmap,
  57. .is_enabled = regulator_is_enabled_regmap,
  58. .list_voltage = regulator_list_voltage_linear,
  59. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  60. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  61. .set_voltage_time_sel = atc260x_dcdc_set_voltage_time_sel,
  62. };
  63. static const struct regulator_ops atc260x_ldo_ops = {
  64. .enable = regulator_enable_regmap,
  65. .disable = regulator_disable_regmap,
  66. .is_enabled = regulator_is_enabled_regmap,
  67. .list_voltage = regulator_list_voltage_linear,
  68. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  69. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  70. .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel,
  71. };
  72. static const struct regulator_ops atc260x_ldo_bypass_ops = {
  73. .enable = regulator_enable_regmap,
  74. .disable = regulator_disable_regmap,
  75. .is_enabled = regulator_is_enabled_regmap,
  76. .list_voltage = regulator_list_voltage_linear,
  77. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  78. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  79. .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel,
  80. .set_bypass = regulator_set_bypass_regmap,
  81. .get_bypass = regulator_get_bypass_regmap,
  82. };
  83. static const struct regulator_ops atc260x_ldo_bypass_discharge_ops = {
  84. .enable = regulator_enable_regmap,
  85. .disable = regulator_disable_regmap,
  86. .is_enabled = regulator_is_enabled_regmap,
  87. .list_voltage = regulator_list_voltage_linear,
  88. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  89. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  90. .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel,
  91. .set_bypass = regulator_set_bypass_regmap,
  92. .get_bypass = regulator_get_bypass_regmap,
  93. .set_active_discharge = regulator_set_active_discharge_regmap,
  94. };
  95. static const struct regulator_ops atc260x_dcdc_range_ops = {
  96. .enable = regulator_enable_regmap,
  97. .disable = regulator_disable_regmap,
  98. .is_enabled = regulator_is_enabled_regmap,
  99. .list_voltage = regulator_list_voltage_linear_range,
  100. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  101. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  102. .set_voltage_time_sel = atc260x_dcdc_set_voltage_time_sel,
  103. };
  104. static const struct regulator_ops atc260x_ldo_range_pick_ops = {
  105. .enable = regulator_enable_regmap,
  106. .disable = regulator_disable_regmap,
  107. .is_enabled = regulator_is_enabled_regmap,
  108. .list_voltage = regulator_list_voltage_pickable_linear_range,
  109. .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap,
  110. .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
  111. .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel,
  112. };
  113. static const struct regulator_ops atc260x_dcdc_fixed_ops = {
  114. .list_voltage = regulator_list_voltage_linear,
  115. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  116. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  117. .set_voltage_time_sel = atc260x_dcdc_set_voltage_time_sel,
  118. };
  119. static const struct regulator_ops atc260x_ldo_fixed_ops = {
  120. .list_voltage = regulator_list_voltage_linear,
  121. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  122. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  123. .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel,
  124. };
  125. static const struct regulator_ops atc260x_no_ops = {
  126. };
  127. /*
  128. * Note LDO8 is not documented in datasheet (v2.4), but supported
  129. * in the vendor's driver implementation (xapp-le-kernel).
  130. */
  131. enum atc2603c_reg_ids {
  132. ATC2603C_ID_DCDC1,
  133. ATC2603C_ID_DCDC2,
  134. ATC2603C_ID_DCDC3,
  135. ATC2603C_ID_LDO1,
  136. ATC2603C_ID_LDO2,
  137. ATC2603C_ID_LDO3,
  138. ATC2603C_ID_LDO5,
  139. ATC2603C_ID_LDO6,
  140. ATC2603C_ID_LDO7,
  141. ATC2603C_ID_LDO8,
  142. ATC2603C_ID_LDO11,
  143. ATC2603C_ID_LDO12,
  144. ATC2603C_ID_SWITCHLDO1,
  145. ATC2603C_ID_MAX,
  146. };
  147. #define atc2603c_reg_desc_dcdc(num, min, step, n_volt, vsel_h, vsel_l) { \
  148. .name = "DCDC"#num, \
  149. .supply_name = "dcdc"#num, \
  150. .of_match = of_match_ptr("dcdc"#num), \
  151. .regulators_node = of_match_ptr("regulators"), \
  152. .id = ATC2603C_ID_DCDC##num, \
  153. .ops = &atc260x_dcdc_ops, \
  154. .type = REGULATOR_VOLTAGE, \
  155. .min_uV = min, \
  156. .uV_step = step, \
  157. .n_voltages = n_volt, \
  158. .vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \
  159. .vsel_mask = GENMASK(vsel_h, vsel_l), \
  160. .enable_reg = ATC2603C_PMU_DC##num##_CTL0, \
  161. .enable_mask = BIT(15), \
  162. .enable_time = 800, \
  163. .owner = THIS_MODULE, \
  164. }
  165. #define atc2603c_reg_desc_dcdc_range(num, vsel_h, vsel_l) { \
  166. .name = "DCDC"#num, \
  167. .supply_name = "dcdc"#num, \
  168. .of_match = of_match_ptr("dcdc"#num), \
  169. .regulators_node = of_match_ptr("regulators"), \
  170. .id = ATC2603C_ID_DCDC##num, \
  171. .ops = &atc260x_dcdc_range_ops, \
  172. .type = REGULATOR_VOLTAGE, \
  173. .n_voltages = 16, \
  174. .linear_ranges = atc2603c_dcdc_voltage_ranges, \
  175. .n_linear_ranges = ARRAY_SIZE(atc2603c_dcdc_voltage_ranges), \
  176. .vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \
  177. .vsel_mask = GENMASK(vsel_h, vsel_l), \
  178. .enable_reg = ATC2603C_PMU_DC##num##_CTL0, \
  179. .enable_mask = BIT(15), \
  180. .enable_time = 800, \
  181. .owner = THIS_MODULE, \
  182. }
  183. #define atc2603c_reg_desc_dcdc_fixed(num, min, step, n_volt, vsel_h, vsel_l) { \
  184. .name = "DCDC"#num, \
  185. .supply_name = "dcdc"#num, \
  186. .of_match = of_match_ptr("dcdc"#num), \
  187. .regulators_node = of_match_ptr("regulators"), \
  188. .id = ATC2603C_ID_DCDC##num, \
  189. .ops = &atc260x_dcdc_fixed_ops, \
  190. .type = REGULATOR_VOLTAGE, \
  191. .min_uV = min, \
  192. .uV_step = step, \
  193. .n_voltages = n_volt, \
  194. .vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \
  195. .vsel_mask = GENMASK(vsel_h, vsel_l), \
  196. .enable_time = 800, \
  197. .owner = THIS_MODULE, \
  198. }
  199. #define atc2603c_reg_desc_ldo(num, min, step, n_volt, vsel_h, vsel_l) { \
  200. .name = "LDO"#num, \
  201. .supply_name = "ldo"#num, \
  202. .of_match = of_match_ptr("ldo"#num), \
  203. .regulators_node = of_match_ptr("regulators"), \
  204. .id = ATC2603C_ID_LDO##num, \
  205. .ops = &atc260x_ldo_ops, \
  206. .type = REGULATOR_VOLTAGE, \
  207. .min_uV = min, \
  208. .uV_step = step, \
  209. .n_voltages = n_volt, \
  210. .vsel_reg = ATC2603C_PMU_LDO##num##_CTL, \
  211. .vsel_mask = GENMASK(vsel_h, vsel_l), \
  212. .enable_reg = ATC2603C_PMU_LDO##num##_CTL, \
  213. .enable_mask = BIT(0), \
  214. .enable_time = 2000, \
  215. .owner = THIS_MODULE, \
  216. }
  217. #define atc2603c_reg_desc_ldo_fixed(num, min, step, n_volt, vsel_h, vsel_l) { \
  218. .name = "LDO"#num, \
  219. .supply_name = "ldo"#num, \
  220. .of_match = of_match_ptr("ldo"#num), \
  221. .regulators_node = of_match_ptr("regulators"), \
  222. .id = ATC2603C_ID_LDO##num, \
  223. .ops = &atc260x_ldo_fixed_ops, \
  224. .type = REGULATOR_VOLTAGE, \
  225. .min_uV = min, \
  226. .uV_step = step, \
  227. .n_voltages = n_volt, \
  228. .vsel_reg = ATC2603C_PMU_LDO##num##_CTL, \
  229. .vsel_mask = GENMASK(vsel_h, vsel_l), \
  230. .enable_time = 2000, \
  231. .owner = THIS_MODULE, \
  232. }
  233. #define atc2603c_reg_desc_ldo_noops(num, vfixed) { \
  234. .name = "LDO"#num, \
  235. .supply_name = "ldo"#num, \
  236. .of_match = of_match_ptr("ldo"#num), \
  237. .regulators_node = of_match_ptr("regulators"), \
  238. .id = ATC2603C_ID_LDO##num, \
  239. .ops = &atc260x_no_ops, \
  240. .type = REGULATOR_VOLTAGE, \
  241. .fixed_uV = vfixed, \
  242. .n_voltages = 1, \
  243. .owner = THIS_MODULE, \
  244. }
  245. #define atc2603c_reg_desc_ldo_switch(num, min, step, n_volt, vsel_h, vsel_l) { \
  246. .name = "SWITCHLDO"#num, \
  247. .supply_name = "switchldo"#num, \
  248. .of_match = of_match_ptr("switchldo"#num), \
  249. .regulators_node = of_match_ptr("regulators"), \
  250. .id = ATC2603C_ID_SWITCHLDO##num, \
  251. .ops = &atc260x_ldo_bypass_discharge_ops, \
  252. .type = REGULATOR_VOLTAGE, \
  253. .min_uV = min, \
  254. .uV_step = step, \
  255. .n_voltages = n_volt, \
  256. .vsel_reg = ATC2603C_PMU_SWITCH_CTL, \
  257. .vsel_mask = GENMASK(vsel_h, vsel_l), \
  258. .enable_reg = ATC2603C_PMU_SWITCH_CTL, \
  259. .enable_mask = BIT(15), \
  260. .enable_is_inverted = true, \
  261. .enable_time = 2000, \
  262. .bypass_reg = ATC2603C_PMU_SWITCH_CTL, \
  263. .bypass_mask = BIT(5), \
  264. .active_discharge_reg = ATC2603C_PMU_SWITCH_CTL, \
  265. .active_discharge_mask = BIT(1), \
  266. .active_discharge_on = BIT(1), \
  267. .owner = THIS_MODULE, \
  268. }
  269. static const struct regulator_desc atc2603c_reg[] = {
  270. atc2603c_reg_desc_dcdc_fixed(1, 700000, 25000, 29, 11, 7),
  271. atc2603c_reg_desc_dcdc_range(2, 12, 8),
  272. atc2603c_reg_desc_dcdc_fixed(3, 2600000, 100000, 8, 11, 9),
  273. atc2603c_reg_desc_ldo_fixed(1, 2600000, 100000, 8, 15, 13),
  274. atc2603c_reg_desc_ldo_fixed(2, 2600000, 100000, 8, 15, 13),
  275. atc2603c_reg_desc_ldo_fixed(3, 1500000, 100000, 6, 15, 13),
  276. atc2603c_reg_desc_ldo(5, 2600000, 100000, 8, 15, 13),
  277. atc2603c_reg_desc_ldo_fixed(6, 700000, 25000, 29, 15, 11),
  278. atc2603c_reg_desc_ldo(7, 1500000, 100000, 6, 15, 13),
  279. atc2603c_reg_desc_ldo(8, 2300000, 100000, 11, 15, 12),
  280. atc2603c_reg_desc_ldo_fixed(11, 2600000, 100000, 8, 15, 13),
  281. atc2603c_reg_desc_ldo_noops(12, 1800000),
  282. atc2603c_reg_desc_ldo_switch(1, 3000000, 100000, 4, 4, 3),
  283. };
  284. static const struct regulator_desc atc2603c_reg_dcdc2_ver_b =
  285. atc2603c_reg_desc_dcdc(2, 1000000, 50000, 18, 12, 8);
  286. enum atc2609a_reg_ids {
  287. ATC2609A_ID_DCDC0,
  288. ATC2609A_ID_DCDC1,
  289. ATC2609A_ID_DCDC2,
  290. ATC2609A_ID_DCDC3,
  291. ATC2609A_ID_DCDC4,
  292. ATC2609A_ID_LDO0,
  293. ATC2609A_ID_LDO1,
  294. ATC2609A_ID_LDO2,
  295. ATC2609A_ID_LDO3,
  296. ATC2609A_ID_LDO4,
  297. ATC2609A_ID_LDO5,
  298. ATC2609A_ID_LDO6,
  299. ATC2609A_ID_LDO7,
  300. ATC2609A_ID_LDO8,
  301. ATC2609A_ID_LDO9,
  302. ATC2609A_ID_MAX,
  303. };
  304. #define atc2609a_reg_desc_dcdc(num, en_bit) { \
  305. .name = "DCDC"#num, \
  306. .supply_name = "dcdc"#num, \
  307. .of_match = of_match_ptr("dcdc"#num), \
  308. .regulators_node = of_match_ptr("regulators"), \
  309. .id = ATC2609A_ID_DCDC##num, \
  310. .ops = &atc260x_dcdc_ops, \
  311. .type = REGULATOR_VOLTAGE, \
  312. .min_uV = 600000, \
  313. .uV_step = 6250, \
  314. .n_voltages = 256, \
  315. .vsel_reg = ATC2609A_PMU_DC##num##_CTL0, \
  316. .vsel_mask = GENMASK(15, 8), \
  317. .enable_reg = ATC2609A_PMU_DC_OSC, \
  318. .enable_mask = BIT(en_bit), \
  319. .enable_time = 800, \
  320. .owner = THIS_MODULE, \
  321. }
  322. #define atc2609a_reg_desc_dcdc_range(num, en_bit) { \
  323. .name = "DCDC"#num, \
  324. .supply_name = "dcdc"#num, \
  325. .of_match = of_match_ptr("dcdc"#num), \
  326. .regulators_node = of_match_ptr("regulators"), \
  327. .id = ATC2609A_ID_DCDC##num, \
  328. .ops = &atc260x_dcdc_range_ops, \
  329. .type = REGULATOR_VOLTAGE, \
  330. .n_voltages = 233, \
  331. .linear_ranges = atc2609a_dcdc_voltage_ranges, \
  332. .n_linear_ranges = ARRAY_SIZE(atc2609a_dcdc_voltage_ranges), \
  333. .vsel_reg = ATC2609A_PMU_DC##num##_CTL0, \
  334. .vsel_mask = GENMASK(15, 8), \
  335. .enable_reg = ATC2609A_PMU_DC_OSC, \
  336. .enable_mask = BIT(en_bit), \
  337. .enable_time = 800, \
  338. .owner = THIS_MODULE, \
  339. }
  340. #define atc2609a_reg_desc_ldo(num) { \
  341. .name = "LDO"#num, \
  342. .supply_name = "ldo"#num, \
  343. .of_match = of_match_ptr("ldo"#num), \
  344. .regulators_node = of_match_ptr("regulators"), \
  345. .id = ATC2609A_ID_LDO##num, \
  346. .ops = &atc260x_ldo_ops, \
  347. .type = REGULATOR_VOLTAGE, \
  348. .min_uV = 700000, \
  349. .uV_step = 100000, \
  350. .n_voltages = 16, \
  351. .vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \
  352. .vsel_mask = GENMASK(4, 1), \
  353. .enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \
  354. .enable_mask = BIT(0), \
  355. .enable_time = 2000, \
  356. .owner = THIS_MODULE, \
  357. }
  358. #define atc2609a_reg_desc_ldo_bypass(num) { \
  359. .name = "LDO"#num, \
  360. .supply_name = "ldo"#num, \
  361. .of_match = of_match_ptr("ldo"#num), \
  362. .regulators_node = of_match_ptr("regulators"), \
  363. .id = ATC2609A_ID_LDO##num, \
  364. .ops = &atc260x_ldo_bypass_ops, \
  365. .type = REGULATOR_VOLTAGE, \
  366. .min_uV = 2300000, \
  367. .uV_step = 100000, \
  368. .n_voltages = 12, \
  369. .vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \
  370. .vsel_mask = GENMASK(5, 2), \
  371. .enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \
  372. .enable_mask = BIT(0), \
  373. .enable_time = 2000, \
  374. .bypass_reg = ATC2609A_PMU_LDO##num##_CTL0, \
  375. .bypass_mask = BIT(1), \
  376. .owner = THIS_MODULE, \
  377. }
  378. #define atc2609a_reg_desc_ldo_range_pick(num, n_range, n_volt) { \
  379. .name = "LDO"#num, \
  380. .supply_name = "ldo"#num, \
  381. .of_match = of_match_ptr("ldo"#num), \
  382. .regulators_node = of_match_ptr("regulators"), \
  383. .id = ATC2609A_ID_LDO##num, \
  384. .ops = &atc260x_ldo_range_pick_ops, \
  385. .type = REGULATOR_VOLTAGE, \
  386. .linear_ranges = atc2609a_ldo_voltage_ranges##n_range, \
  387. .n_linear_ranges = ARRAY_SIZE(atc2609a_ldo_voltage_ranges##n_range), \
  388. .n_voltages = n_volt, \
  389. .vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \
  390. .vsel_mask = GENMASK(4, 1), \
  391. .vsel_range_reg = ATC2609A_PMU_LDO##num##_CTL0, \
  392. .vsel_range_mask = BIT(5), \
  393. .linear_range_selectors_bitfield = atc260x_ldo_voltage_range_sel, \
  394. .enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \
  395. .enable_mask = BIT(0), \
  396. .enable_time = 2000, \
  397. .owner = THIS_MODULE, \
  398. }
  399. #define atc2609a_reg_desc_ldo_fixed(num) { \
  400. .name = "LDO"#num, \
  401. .supply_name = "ldo"#num, \
  402. .of_match = of_match_ptr("ldo"#num), \
  403. .regulators_node = of_match_ptr("regulators"), \
  404. .id = ATC2609A_ID_LDO##num, \
  405. .ops = &atc260x_ldo_fixed_ops, \
  406. .type = REGULATOR_VOLTAGE, \
  407. .min_uV = 2600000, \
  408. .uV_step = 100000, \
  409. .n_voltages = 8, \
  410. .vsel_reg = ATC2609A_PMU_LDO##num##_CTL, \
  411. .vsel_mask = GENMASK(15, 13), \
  412. .enable_time = 2000, \
  413. .owner = THIS_MODULE, \
  414. }
  415. static const struct regulator_desc atc2609a_reg[] = {
  416. atc2609a_reg_desc_dcdc(0, 4),
  417. atc2609a_reg_desc_dcdc(1, 5),
  418. atc2609a_reg_desc_dcdc(2, 6),
  419. atc2609a_reg_desc_dcdc_range(3, 7),
  420. atc2609a_reg_desc_dcdc(4, 8),
  421. atc2609a_reg_desc_ldo_bypass(0),
  422. atc2609a_reg_desc_ldo_bypass(1),
  423. atc2609a_reg_desc_ldo_bypass(2),
  424. atc2609a_reg_desc_ldo_range_pick(3, 0, 29),
  425. atc2609a_reg_desc_ldo_range_pick(4, 0, 29),
  426. atc2609a_reg_desc_ldo(5),
  427. atc2609a_reg_desc_ldo_range_pick(6, 1, 28),
  428. atc2609a_reg_desc_ldo_range_pick(7, 0, 29),
  429. atc2609a_reg_desc_ldo_range_pick(8, 0, 29),
  430. atc2609a_reg_desc_ldo_fixed(9),
  431. };
  432. static int atc260x_regulator_probe(struct platform_device *pdev)
  433. {
  434. struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent);
  435. struct device *dev = atc260x->dev;
  436. struct atc260x_regulator_data *atc260x_data;
  437. struct regulator_config config = {};
  438. struct regulator_dev *atc260x_rdev;
  439. const struct regulator_desc *regulators;
  440. bool atc2603c_ver_b = false;
  441. int i, nregulators;
  442. atc260x_data = devm_kzalloc(&pdev->dev, sizeof(*atc260x_data), GFP_KERNEL);
  443. if (!atc260x_data)
  444. return -ENOMEM;
  445. atc260x_data->voltage_time_dcdc = 350;
  446. atc260x_data->voltage_time_ldo = 800;
  447. switch (atc260x->ic_type) {
  448. case ATC2603C:
  449. regulators = atc2603c_reg;
  450. nregulators = ATC2603C_ID_MAX;
  451. atc2603c_ver_b = atc260x->ic_ver == ATC260X_B;
  452. break;
  453. case ATC2609A:
  454. atc260x_data->voltage_time_dcdc = 250;
  455. regulators = atc2609a_reg;
  456. nregulators = ATC2609A_ID_MAX;
  457. break;
  458. default:
  459. dev_err(dev, "unsupported ATC260X ID %d\n", atc260x->ic_type);
  460. return -EINVAL;
  461. }
  462. config.dev = dev;
  463. config.regmap = atc260x->regmap;
  464. config.driver_data = atc260x_data;
  465. /* Instantiate the regulators */
  466. for (i = 0; i < nregulators; i++) {
  467. if (atc2603c_ver_b && regulators[i].id == ATC2603C_ID_DCDC2)
  468. atc260x_rdev = devm_regulator_register(&pdev->dev,
  469. &atc2603c_reg_dcdc2_ver_b,
  470. &config);
  471. else
  472. atc260x_rdev = devm_regulator_register(&pdev->dev,
  473. &regulators[i],
  474. &config);
  475. if (IS_ERR(atc260x_rdev)) {
  476. dev_err(dev, "failed to register regulator: %d\n", i);
  477. return PTR_ERR(atc260x_rdev);
  478. }
  479. }
  480. return 0;
  481. }
  482. static struct platform_driver atc260x_regulator_driver = {
  483. .probe = atc260x_regulator_probe,
  484. .driver = {
  485. .name = "atc260x-regulator",
  486. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  487. },
  488. };
  489. module_platform_driver(atc260x_regulator_driver);
  490. MODULE_DESCRIPTION("Regulator driver for ATC260x PMICs");
  491. MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
  492. MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>");
  493. MODULE_LICENSE("GPL");