act8865-regulator.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * act8865-regulator.c - Voltage regulation for active-semi ACT88xx PMUs
  3. *
  4. * http://www.active-semi.com/products/power-management-units/act88xx/
  5. *
  6. * Copyright (C) 2013 Atmel Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/i2c.h>
  21. #include <linux/err.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/regulator/driver.h>
  24. #include <linux/regulator/act8865.h>
  25. #include <linux/of.h>
  26. #include <linux/of_device.h>
  27. #include <linux/regulator/of_regulator.h>
  28. #include <linux/regmap.h>
  29. /*
  30. * ACT8600 Global Register Map.
  31. */
  32. #define ACT8600_SYS_MODE 0x00
  33. #define ACT8600_SYS_CTRL 0x01
  34. #define ACT8600_DCDC1_VSET 0x10
  35. #define ACT8600_DCDC1_CTRL 0x12
  36. #define ACT8600_DCDC2_VSET 0x20
  37. #define ACT8600_DCDC2_CTRL 0x22
  38. #define ACT8600_DCDC3_VSET 0x30
  39. #define ACT8600_DCDC3_CTRL 0x32
  40. #define ACT8600_SUDCDC4_VSET 0x40
  41. #define ACT8600_SUDCDC4_CTRL 0x41
  42. #define ACT8600_LDO5_VSET 0x50
  43. #define ACT8600_LDO5_CTRL 0x51
  44. #define ACT8600_LDO6_VSET 0x60
  45. #define ACT8600_LDO6_CTRL 0x61
  46. #define ACT8600_LDO7_VSET 0x70
  47. #define ACT8600_LDO7_CTRL 0x71
  48. #define ACT8600_LDO8_VSET 0x80
  49. #define ACT8600_LDO8_CTRL 0x81
  50. #define ACT8600_LDO910_CTRL 0x91
  51. #define ACT8600_APCH0 0xA1
  52. #define ACT8600_APCH1 0xA8
  53. #define ACT8600_APCH2 0xA9
  54. #define ACT8600_APCH_STAT 0xAA
  55. #define ACT8600_OTG0 0xB0
  56. #define ACT8600_OTG1 0xB2
  57. /*
  58. * ACT8846 Global Register Map.
  59. */
  60. #define ACT8846_SYS0 0x00
  61. #define ACT8846_SYS1 0x01
  62. #define ACT8846_REG1_VSET 0x10
  63. #define ACT8846_REG1_CTRL 0x12
  64. #define ACT8846_REG2_VSET0 0x20
  65. #define ACT8846_REG2_VSET1 0x21
  66. #define ACT8846_REG2_CTRL 0x22
  67. #define ACT8846_REG3_VSET0 0x30
  68. #define ACT8846_REG3_VSET1 0x31
  69. #define ACT8846_REG3_CTRL 0x32
  70. #define ACT8846_REG4_VSET0 0x40
  71. #define ACT8846_REG4_VSET1 0x41
  72. #define ACT8846_REG4_CTRL 0x42
  73. #define ACT8846_REG5_VSET 0x50
  74. #define ACT8846_REG5_CTRL 0x51
  75. #define ACT8846_REG6_VSET 0x58
  76. #define ACT8846_REG6_CTRL 0x59
  77. #define ACT8846_REG7_VSET 0x60
  78. #define ACT8846_REG7_CTRL 0x61
  79. #define ACT8846_REG8_VSET 0x68
  80. #define ACT8846_REG8_CTRL 0x69
  81. #define ACT8846_REG9_VSET 0x70
  82. #define ACT8846_REG9_CTRL 0x71
  83. #define ACT8846_REG10_VSET 0x80
  84. #define ACT8846_REG10_CTRL 0x81
  85. #define ACT8846_REG11_VSET 0x90
  86. #define ACT8846_REG11_CTRL 0x91
  87. #define ACT8846_REG12_VSET 0xa0
  88. #define ACT8846_REG12_CTRL 0xa1
  89. #define ACT8846_REG13_CTRL 0xb1
  90. #define ACT8846_GLB_OFF_CTRL 0xc3
  91. #define ACT8846_OFF_SYSMASK 0x18
  92. /*
  93. * ACT8865 Global Register Map.
  94. */
  95. #define ACT8865_SYS_MODE 0x00
  96. #define ACT8865_SYS_CTRL 0x01
  97. #define ACT8865_DCDC1_VSET1 0x20
  98. #define ACT8865_DCDC1_VSET2 0x21
  99. #define ACT8865_DCDC1_CTRL 0x22
  100. #define ACT8865_DCDC2_VSET1 0x30
  101. #define ACT8865_DCDC2_VSET2 0x31
  102. #define ACT8865_DCDC2_CTRL 0x32
  103. #define ACT8865_DCDC3_VSET1 0x40
  104. #define ACT8865_DCDC3_VSET2 0x41
  105. #define ACT8865_DCDC3_CTRL 0x42
  106. #define ACT8865_LDO1_VSET 0x50
  107. #define ACT8865_LDO1_CTRL 0x51
  108. #define ACT8865_LDO2_VSET 0x54
  109. #define ACT8865_LDO2_CTRL 0x55
  110. #define ACT8865_LDO3_VSET 0x60
  111. #define ACT8865_LDO3_CTRL 0x61
  112. #define ACT8865_LDO4_VSET 0x64
  113. #define ACT8865_LDO4_CTRL 0x65
  114. #define ACT8865_MSTROFF 0x20
  115. /*
  116. * Field Definitions.
  117. */
  118. #define ACT8865_ENA 0x80 /* ON - [7] */
  119. #define ACT8865_VSEL_MASK 0x3F /* VSET - [5:0] */
  120. #define ACT8600_LDO10_ENA 0x40 /* ON - [6] */
  121. #define ACT8600_SUDCDC_VSEL_MASK 0xFF /* SUDCDC VSET - [7:0] */
  122. /*
  123. * ACT8865 voltage number
  124. */
  125. #define ACT8865_VOLTAGE_NUM 64
  126. #define ACT8600_SUDCDC_VOLTAGE_NUM 256
  127. struct act8865 {
  128. struct regmap *regmap;
  129. int off_reg;
  130. int off_mask;
  131. };
  132. static const struct regmap_range act8600_reg_ranges[] = {
  133. regmap_reg_range(0x00, 0x01),
  134. regmap_reg_range(0x10, 0x10),
  135. regmap_reg_range(0x12, 0x12),
  136. regmap_reg_range(0x20, 0x20),
  137. regmap_reg_range(0x22, 0x22),
  138. regmap_reg_range(0x30, 0x30),
  139. regmap_reg_range(0x32, 0x32),
  140. regmap_reg_range(0x40, 0x41),
  141. regmap_reg_range(0x50, 0x51),
  142. regmap_reg_range(0x60, 0x61),
  143. regmap_reg_range(0x70, 0x71),
  144. regmap_reg_range(0x80, 0x81),
  145. regmap_reg_range(0x91, 0x91),
  146. regmap_reg_range(0xA1, 0xA1),
  147. regmap_reg_range(0xA8, 0xAA),
  148. regmap_reg_range(0xB0, 0xB0),
  149. regmap_reg_range(0xB2, 0xB2),
  150. regmap_reg_range(0xC1, 0xC1),
  151. };
  152. static const struct regmap_range act8600_reg_ro_ranges[] = {
  153. regmap_reg_range(0xAA, 0xAA),
  154. regmap_reg_range(0xC1, 0xC1),
  155. };
  156. static const struct regmap_range act8600_reg_volatile_ranges[] = {
  157. regmap_reg_range(0x00, 0x01),
  158. regmap_reg_range(0x12, 0x12),
  159. regmap_reg_range(0x22, 0x22),
  160. regmap_reg_range(0x32, 0x32),
  161. regmap_reg_range(0x41, 0x41),
  162. regmap_reg_range(0x51, 0x51),
  163. regmap_reg_range(0x61, 0x61),
  164. regmap_reg_range(0x71, 0x71),
  165. regmap_reg_range(0x81, 0x81),
  166. regmap_reg_range(0xA8, 0xA8),
  167. regmap_reg_range(0xAA, 0xAA),
  168. regmap_reg_range(0xB0, 0xB0),
  169. regmap_reg_range(0xC1, 0xC1),
  170. };
  171. static const struct regmap_access_table act8600_write_ranges_table = {
  172. .yes_ranges = act8600_reg_ranges,
  173. .n_yes_ranges = ARRAY_SIZE(act8600_reg_ranges),
  174. .no_ranges = act8600_reg_ro_ranges,
  175. .n_no_ranges = ARRAY_SIZE(act8600_reg_ro_ranges),
  176. };
  177. static const struct regmap_access_table act8600_read_ranges_table = {
  178. .yes_ranges = act8600_reg_ranges,
  179. .n_yes_ranges = ARRAY_SIZE(act8600_reg_ranges),
  180. };
  181. static const struct regmap_access_table act8600_volatile_ranges_table = {
  182. .yes_ranges = act8600_reg_volatile_ranges,
  183. .n_yes_ranges = ARRAY_SIZE(act8600_reg_volatile_ranges),
  184. };
  185. static const struct regmap_config act8600_regmap_config = {
  186. .reg_bits = 8,
  187. .val_bits = 8,
  188. .max_register = 0xFF,
  189. .wr_table = &act8600_write_ranges_table,
  190. .rd_table = &act8600_read_ranges_table,
  191. .volatile_table = &act8600_volatile_ranges_table,
  192. };
  193. static const struct regmap_config act8865_regmap_config = {
  194. .reg_bits = 8,
  195. .val_bits = 8,
  196. };
  197. static const struct regulator_linear_range act8865_voltage_ranges[] = {
  198. REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000),
  199. REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000),
  200. REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000),
  201. };
  202. static const struct regulator_linear_range act8600_sudcdc_voltage_ranges[] = {
  203. REGULATOR_LINEAR_RANGE(3000000, 0, 63, 0),
  204. REGULATOR_LINEAR_RANGE(3000000, 64, 159, 100000),
  205. REGULATOR_LINEAR_RANGE(12600000, 160, 191, 200000),
  206. REGULATOR_LINEAR_RANGE(19000000, 192, 247, 400000),
  207. REGULATOR_LINEAR_RANGE(41400000, 248, 255, 0),
  208. };
  209. static struct regulator_ops act8865_ops = {
  210. .list_voltage = regulator_list_voltage_linear_range,
  211. .map_voltage = regulator_map_voltage_linear_range,
  212. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  213. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  214. .enable = regulator_enable_regmap,
  215. .disable = regulator_disable_regmap,
  216. .is_enabled = regulator_is_enabled_regmap,
  217. };
  218. static struct regulator_ops act8865_ldo_ops = {
  219. .enable = regulator_enable_regmap,
  220. .disable = regulator_disable_regmap,
  221. .is_enabled = regulator_is_enabled_regmap,
  222. };
  223. #define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \
  224. [_family##_ID_##_id] = { \
  225. .name = _name, \
  226. .supply_name = _supply, \
  227. .id = _family##_ID_##_id, \
  228. .type = REGULATOR_VOLTAGE, \
  229. .ops = &act8865_ops, \
  230. .n_voltages = ACT8865_VOLTAGE_NUM, \
  231. .linear_ranges = act8865_voltage_ranges, \
  232. .n_linear_ranges = ARRAY_SIZE(act8865_voltage_ranges), \
  233. .vsel_reg = _family##_##_id##_##_vsel_reg, \
  234. .vsel_mask = ACT8865_VSEL_MASK, \
  235. .enable_reg = _family##_##_id##_CTRL, \
  236. .enable_mask = ACT8865_ENA, \
  237. .owner = THIS_MODULE, \
  238. }
  239. static const struct regulator_desc act8600_regulators[] = {
  240. ACT88xx_REG("DCDC1", ACT8600, DCDC1, VSET, "vp1"),
  241. ACT88xx_REG("DCDC2", ACT8600, DCDC2, VSET, "vp2"),
  242. ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"),
  243. {
  244. .name = "SUDCDC_REG4",
  245. .id = ACT8600_ID_SUDCDC4,
  246. .ops = &act8865_ops,
  247. .type = REGULATOR_VOLTAGE,
  248. .n_voltages = ACT8600_SUDCDC_VOLTAGE_NUM,
  249. .linear_ranges = act8600_sudcdc_voltage_ranges,
  250. .n_linear_ranges = ARRAY_SIZE(act8600_sudcdc_voltage_ranges),
  251. .vsel_reg = ACT8600_SUDCDC4_VSET,
  252. .vsel_mask = ACT8600_SUDCDC_VSEL_MASK,
  253. .enable_reg = ACT8600_SUDCDC4_CTRL,
  254. .enable_mask = ACT8865_ENA,
  255. .owner = THIS_MODULE,
  256. },
  257. ACT88xx_REG("LDO5", ACT8600, LDO5, VSET, "inl"),
  258. ACT88xx_REG("LDO6", ACT8600, LDO6, VSET, "inl"),
  259. ACT88xx_REG("LDO7", ACT8600, LDO7, VSET, "inl"),
  260. ACT88xx_REG("LDO8", ACT8600, LDO8, VSET, "inl"),
  261. {
  262. .name = "LDO_REG9",
  263. .id = ACT8600_ID_LDO9,
  264. .ops = &act8865_ldo_ops,
  265. .type = REGULATOR_VOLTAGE,
  266. .n_voltages = 1,
  267. .fixed_uV = 3300000,
  268. .enable_reg = ACT8600_LDO910_CTRL,
  269. .enable_mask = ACT8865_ENA,
  270. .owner = THIS_MODULE,
  271. },
  272. {
  273. .name = "LDO_REG10",
  274. .id = ACT8600_ID_LDO10,
  275. .ops = &act8865_ldo_ops,
  276. .type = REGULATOR_VOLTAGE,
  277. .n_voltages = 1,
  278. .fixed_uV = 1200000,
  279. .enable_reg = ACT8600_LDO910_CTRL,
  280. .enable_mask = ACT8600_LDO10_ENA,
  281. .owner = THIS_MODULE,
  282. },
  283. };
  284. static const struct regulator_desc act8846_regulators[] = {
  285. ACT88xx_REG("REG1", ACT8846, REG1, VSET, "vp1"),
  286. ACT88xx_REG("REG2", ACT8846, REG2, VSET0, "vp2"),
  287. ACT88xx_REG("REG3", ACT8846, REG3, VSET0, "vp3"),
  288. ACT88xx_REG("REG4", ACT8846, REG4, VSET0, "vp4"),
  289. ACT88xx_REG("REG5", ACT8846, REG5, VSET, "inl1"),
  290. ACT88xx_REG("REG6", ACT8846, REG6, VSET, "inl1"),
  291. ACT88xx_REG("REG7", ACT8846, REG7, VSET, "inl1"),
  292. ACT88xx_REG("REG8", ACT8846, REG8, VSET, "inl2"),
  293. ACT88xx_REG("REG9", ACT8846, REG9, VSET, "inl2"),
  294. ACT88xx_REG("REG10", ACT8846, REG10, VSET, "inl3"),
  295. ACT88xx_REG("REG11", ACT8846, REG11, VSET, "inl3"),
  296. ACT88xx_REG("REG12", ACT8846, REG12, VSET, "inl3"),
  297. };
  298. static const struct regulator_desc act8865_regulators[] = {
  299. ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET1, "vp1"),
  300. ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET1, "vp2"),
  301. ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET1, "vp3"),
  302. ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
  303. ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
  304. ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
  305. ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
  306. };
  307. static const struct regulator_desc act8865_alt_regulators[] = {
  308. ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET2, "vp1"),
  309. ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET2, "vp2"),
  310. ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET2, "vp3"),
  311. ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
  312. ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
  313. ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
  314. ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
  315. };
  316. #ifdef CONFIG_OF
  317. static const struct of_device_id act8865_dt_ids[] = {
  318. { .compatible = "active-semi,act8600", .data = (void *)ACT8600 },
  319. { .compatible = "active-semi,act8846", .data = (void *)ACT8846 },
  320. { .compatible = "active-semi,act8865", .data = (void *)ACT8865 },
  321. { }
  322. };
  323. MODULE_DEVICE_TABLE(of, act8865_dt_ids);
  324. static struct of_regulator_match act8846_matches[] = {
  325. [ACT8846_ID_REG1] = { .name = "REG1" },
  326. [ACT8846_ID_REG2] = { .name = "REG2" },
  327. [ACT8846_ID_REG3] = { .name = "REG3" },
  328. [ACT8846_ID_REG4] = { .name = "REG4" },
  329. [ACT8846_ID_REG5] = { .name = "REG5" },
  330. [ACT8846_ID_REG6] = { .name = "REG6" },
  331. [ACT8846_ID_REG7] = { .name = "REG7" },
  332. [ACT8846_ID_REG8] = { .name = "REG8" },
  333. [ACT8846_ID_REG9] = { .name = "REG9" },
  334. [ACT8846_ID_REG10] = { .name = "REG10" },
  335. [ACT8846_ID_REG11] = { .name = "REG11" },
  336. [ACT8846_ID_REG12] = { .name = "REG12" },
  337. };
  338. static struct of_regulator_match act8865_matches[] = {
  339. [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"},
  340. [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"},
  341. [ACT8865_ID_DCDC3] = { .name = "DCDC_REG3"},
  342. [ACT8865_ID_LDO1] = { .name = "LDO_REG1"},
  343. [ACT8865_ID_LDO2] = { .name = "LDO_REG2"},
  344. [ACT8865_ID_LDO3] = { .name = "LDO_REG3"},
  345. [ACT8865_ID_LDO4] = { .name = "LDO_REG4"},
  346. };
  347. static struct of_regulator_match act8600_matches[] = {
  348. [ACT8600_ID_DCDC1] = { .name = "DCDC_REG1"},
  349. [ACT8600_ID_DCDC2] = { .name = "DCDC_REG2"},
  350. [ACT8600_ID_DCDC3] = { .name = "DCDC_REG3"},
  351. [ACT8600_ID_SUDCDC4] = { .name = "SUDCDC_REG4"},
  352. [ACT8600_ID_LDO5] = { .name = "LDO_REG5"},
  353. [ACT8600_ID_LDO6] = { .name = "LDO_REG6"},
  354. [ACT8600_ID_LDO7] = { .name = "LDO_REG7"},
  355. [ACT8600_ID_LDO8] = { .name = "LDO_REG8"},
  356. [ACT8600_ID_LDO9] = { .name = "LDO_REG9"},
  357. [ACT8600_ID_LDO10] = { .name = "LDO_REG10"},
  358. };
  359. static int act8865_pdata_from_dt(struct device *dev,
  360. struct act8865_platform_data *pdata,
  361. unsigned long type)
  362. {
  363. int matched, i, num_matches;
  364. struct device_node *np;
  365. struct act8865_regulator_data *regulator;
  366. struct of_regulator_match *matches;
  367. switch (type) {
  368. case ACT8600:
  369. matches = act8600_matches;
  370. num_matches = ARRAY_SIZE(act8600_matches);
  371. break;
  372. case ACT8846:
  373. matches = act8846_matches;
  374. num_matches = ARRAY_SIZE(act8846_matches);
  375. break;
  376. case ACT8865:
  377. matches = act8865_matches;
  378. num_matches = ARRAY_SIZE(act8865_matches);
  379. break;
  380. default:
  381. dev_err(dev, "invalid device id %lu\n", type);
  382. return -EINVAL;
  383. }
  384. np = of_get_child_by_name(dev->of_node, "regulators");
  385. if (!np) {
  386. dev_err(dev, "missing 'regulators' subnode in DT\n");
  387. return -EINVAL;
  388. }
  389. matched = of_regulator_match(dev, np, matches, num_matches);
  390. of_node_put(np);
  391. if (matched <= 0)
  392. return matched;
  393. pdata->regulators = devm_kzalloc(dev,
  394. sizeof(struct act8865_regulator_data) *
  395. num_matches, GFP_KERNEL);
  396. if (!pdata->regulators)
  397. return -ENOMEM;
  398. pdata->num_regulators = num_matches;
  399. regulator = pdata->regulators;
  400. for (i = 0; i < num_matches; i++) {
  401. regulator->id = i;
  402. regulator->name = matches[i].name;
  403. regulator->init_data = matches[i].init_data;
  404. regulator->of_node = matches[i].of_node;
  405. regulator++;
  406. }
  407. return 0;
  408. }
  409. #else
  410. static inline int act8865_pdata_from_dt(struct device *dev,
  411. struct act8865_platform_data *pdata,
  412. unsigned long type)
  413. {
  414. return 0;
  415. }
  416. #endif
  417. static struct act8865_regulator_data *act8865_get_regulator_data(
  418. int id, struct act8865_platform_data *pdata)
  419. {
  420. int i;
  421. if (!pdata)
  422. return NULL;
  423. for (i = 0; i < pdata->num_regulators; i++) {
  424. if (pdata->regulators[i].id == id)
  425. return &pdata->regulators[i];
  426. }
  427. return NULL;
  428. }
  429. static struct i2c_client *act8865_i2c_client;
  430. static void act8865_power_off(void)
  431. {
  432. struct act8865 *act8865;
  433. act8865 = i2c_get_clientdata(act8865_i2c_client);
  434. regmap_write(act8865->regmap, act8865->off_reg, act8865->off_mask);
  435. while (1);
  436. }
  437. static int act8865_pmic_probe(struct i2c_client *client,
  438. const struct i2c_device_id *i2c_id)
  439. {
  440. const struct regulator_desc *regulators;
  441. struct act8865_platform_data pdata_of, *pdata;
  442. struct device *dev = &client->dev;
  443. int i, ret, num_regulators;
  444. struct act8865 *act8865;
  445. const struct regmap_config *regmap_config;
  446. unsigned long type;
  447. int off_reg, off_mask;
  448. int voltage_select = 0;
  449. pdata = dev_get_platdata(dev);
  450. if (dev->of_node && !pdata) {
  451. const struct of_device_id *id;
  452. id = of_match_device(of_match_ptr(act8865_dt_ids), dev);
  453. if (!id)
  454. return -ENODEV;
  455. type = (unsigned long) id->data;
  456. voltage_select = !!of_get_property(dev->of_node,
  457. "active-semi,vsel-high",
  458. NULL);
  459. } else {
  460. type = i2c_id->driver_data;
  461. }
  462. switch (type) {
  463. case ACT8600:
  464. regulators = act8600_regulators;
  465. num_regulators = ARRAY_SIZE(act8600_regulators);
  466. regmap_config = &act8600_regmap_config;
  467. off_reg = -1;
  468. off_mask = -1;
  469. break;
  470. case ACT8846:
  471. regulators = act8846_regulators;
  472. num_regulators = ARRAY_SIZE(act8846_regulators);
  473. regmap_config = &act8865_regmap_config;
  474. off_reg = ACT8846_GLB_OFF_CTRL;
  475. off_mask = ACT8846_OFF_SYSMASK;
  476. break;
  477. case ACT8865:
  478. if (voltage_select) {
  479. regulators = act8865_alt_regulators;
  480. num_regulators = ARRAY_SIZE(act8865_alt_regulators);
  481. } else {
  482. regulators = act8865_regulators;
  483. num_regulators = ARRAY_SIZE(act8865_regulators);
  484. }
  485. regmap_config = &act8865_regmap_config;
  486. off_reg = ACT8865_SYS_CTRL;
  487. off_mask = ACT8865_MSTROFF;
  488. break;
  489. default:
  490. dev_err(dev, "invalid device id %lu\n", type);
  491. return -EINVAL;
  492. }
  493. if (dev->of_node && !pdata) {
  494. ret = act8865_pdata_from_dt(dev, &pdata_of, type);
  495. if (ret < 0)
  496. return ret;
  497. pdata = &pdata_of;
  498. }
  499. act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL);
  500. if (!act8865)
  501. return -ENOMEM;
  502. act8865->regmap = devm_regmap_init_i2c(client, regmap_config);
  503. if (IS_ERR(act8865->regmap)) {
  504. ret = PTR_ERR(act8865->regmap);
  505. dev_err(dev, "Failed to allocate register map: %d\n", ret);
  506. return ret;
  507. }
  508. if (of_device_is_system_power_controller(dev->of_node)) {
  509. if (!pm_power_off && (off_reg > 0)) {
  510. act8865_i2c_client = client;
  511. act8865->off_reg = off_reg;
  512. act8865->off_mask = off_mask;
  513. pm_power_off = act8865_power_off;
  514. } else {
  515. dev_err(dev, "Failed to set poweroff capability, already defined\n");
  516. }
  517. }
  518. /* Finally register devices */
  519. for (i = 0; i < num_regulators; i++) {
  520. const struct regulator_desc *desc = &regulators[i];
  521. struct regulator_config config = { };
  522. struct act8865_regulator_data *rdata;
  523. struct regulator_dev *rdev;
  524. config.dev = dev;
  525. config.driver_data = act8865;
  526. config.regmap = act8865->regmap;
  527. rdata = act8865_get_regulator_data(desc->id, pdata);
  528. if (rdata) {
  529. config.init_data = rdata->init_data;
  530. config.of_node = rdata->of_node;
  531. }
  532. rdev = devm_regulator_register(dev, desc, &config);
  533. if (IS_ERR(rdev)) {
  534. dev_err(dev, "failed to register %s\n", desc->name);
  535. return PTR_ERR(rdev);
  536. }
  537. }
  538. i2c_set_clientdata(client, act8865);
  539. return 0;
  540. }
  541. static const struct i2c_device_id act8865_ids[] = {
  542. { .name = "act8600", .driver_data = ACT8600 },
  543. { .name = "act8846", .driver_data = ACT8846 },
  544. { .name = "act8865", .driver_data = ACT8865 },
  545. { },
  546. };
  547. MODULE_DEVICE_TABLE(i2c, act8865_ids);
  548. static struct i2c_driver act8865_pmic_driver = {
  549. .driver = {
  550. .name = "act8865",
  551. },
  552. .probe = act8865_pmic_probe,
  553. .id_table = act8865_ids,
  554. };
  555. module_i2c_driver(act8865_pmic_driver);
  556. MODULE_DESCRIPTION("active-semi act88xx voltage regulator driver");
  557. MODULE_AUTHOR("Wenyou Yang <[email protected]>");
  558. MODULE_LICENSE("GPL v2");