atc260x-regulator.c 17 KB

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