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 255
  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, 191, 255, 400000),
  207. };
  208. static struct regulator_ops act8865_ops = {
  209. .list_voltage = regulator_list_voltage_linear_range,
  210. .map_voltage = regulator_map_voltage_linear_range,
  211. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  212. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  213. .enable = regulator_enable_regmap,
  214. .disable = regulator_disable_regmap,
  215. .is_enabled = regulator_is_enabled_regmap,
  216. };
  217. static struct regulator_ops act8865_ldo_ops = {
  218. .enable = regulator_enable_regmap,
  219. .disable = regulator_disable_regmap,
  220. .is_enabled = regulator_is_enabled_regmap,
  221. };
  222. #define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \
  223. [_family##_ID_##_id] = { \
  224. .name = _name, \
  225. .supply_name = _supply, \
  226. .id = _family##_ID_##_id, \
  227. .type = REGULATOR_VOLTAGE, \
  228. .ops = &act8865_ops, \
  229. .n_voltages = ACT8865_VOLTAGE_NUM, \
  230. .linear_ranges = act8865_voltage_ranges, \
  231. .n_linear_ranges = ARRAY_SIZE(act8865_voltage_ranges), \
  232. .vsel_reg = _family##_##_id##_##_vsel_reg, \
  233. .vsel_mask = ACT8865_VSEL_MASK, \
  234. .enable_reg = _family##_##_id##_CTRL, \
  235. .enable_mask = ACT8865_ENA, \
  236. .owner = THIS_MODULE, \
  237. }
  238. static const struct regulator_desc act8600_regulators[] = {
  239. ACT88xx_REG("DCDC1", ACT8600, DCDC1, VSET, "vp1"),
  240. ACT88xx_REG("DCDC2", ACT8600, DCDC2, VSET, "vp2"),
  241. ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"),
  242. {
  243. .name = "SUDCDC_REG4",
  244. .id = ACT8600_ID_SUDCDC4,
  245. .ops = &act8865_ops,
  246. .type = REGULATOR_VOLTAGE,
  247. .n_voltages = ACT8600_SUDCDC_VOLTAGE_NUM,
  248. .linear_ranges = act8600_sudcdc_voltage_ranges,
  249. .n_linear_ranges = ARRAY_SIZE(act8600_sudcdc_voltage_ranges),
  250. .vsel_reg = ACT8600_SUDCDC4_VSET,
  251. .vsel_mask = ACT8600_SUDCDC_VSEL_MASK,
  252. .enable_reg = ACT8600_SUDCDC4_CTRL,
  253. .enable_mask = ACT8865_ENA,
  254. .owner = THIS_MODULE,
  255. },
  256. ACT88xx_REG("LDO5", ACT8600, LDO5, VSET, "inl"),
  257. ACT88xx_REG("LDO6", ACT8600, LDO6, VSET, "inl"),
  258. ACT88xx_REG("LDO7", ACT8600, LDO7, VSET, "inl"),
  259. ACT88xx_REG("LDO8", ACT8600, LDO8, VSET, "inl"),
  260. {
  261. .name = "LDO_REG9",
  262. .id = ACT8600_ID_LDO9,
  263. .ops = &act8865_ldo_ops,
  264. .type = REGULATOR_VOLTAGE,
  265. .n_voltages = 1,
  266. .fixed_uV = 3300000,
  267. .enable_reg = ACT8600_LDO910_CTRL,
  268. .enable_mask = ACT8865_ENA,
  269. .owner = THIS_MODULE,
  270. },
  271. {
  272. .name = "LDO_REG10",
  273. .id = ACT8600_ID_LDO10,
  274. .ops = &act8865_ldo_ops,
  275. .type = REGULATOR_VOLTAGE,
  276. .n_voltages = 1,
  277. .fixed_uV = 1200000,
  278. .enable_reg = ACT8600_LDO910_CTRL,
  279. .enable_mask = ACT8600_LDO10_ENA,
  280. .owner = THIS_MODULE,
  281. },
  282. };
  283. static const struct regulator_desc act8846_regulators[] = {
  284. ACT88xx_REG("REG1", ACT8846, REG1, VSET, "vp1"),
  285. ACT88xx_REG("REG2", ACT8846, REG2, VSET0, "vp2"),
  286. ACT88xx_REG("REG3", ACT8846, REG3, VSET0, "vp3"),
  287. ACT88xx_REG("REG4", ACT8846, REG4, VSET0, "vp4"),
  288. ACT88xx_REG("REG5", ACT8846, REG5, VSET, "inl1"),
  289. ACT88xx_REG("REG6", ACT8846, REG6, VSET, "inl1"),
  290. ACT88xx_REG("REG7", ACT8846, REG7, VSET, "inl1"),
  291. ACT88xx_REG("REG8", ACT8846, REG8, VSET, "inl2"),
  292. ACT88xx_REG("REG9", ACT8846, REG9, VSET, "inl2"),
  293. ACT88xx_REG("REG10", ACT8846, REG10, VSET, "inl3"),
  294. ACT88xx_REG("REG11", ACT8846, REG11, VSET, "inl3"),
  295. ACT88xx_REG("REG12", ACT8846, REG12, VSET, "inl3"),
  296. };
  297. static const struct regulator_desc act8865_regulators[] = {
  298. ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET1, "vp1"),
  299. ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET1, "vp2"),
  300. ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET1, "vp3"),
  301. ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
  302. ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
  303. ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
  304. ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
  305. };
  306. static const struct regulator_desc act8865_alt_regulators[] = {
  307. ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET2, "vp1"),
  308. ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET2, "vp2"),
  309. ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET2, "vp3"),
  310. ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
  311. ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
  312. ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
  313. ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
  314. };
  315. #ifdef CONFIG_OF
  316. static const struct of_device_id act8865_dt_ids[] = {
  317. { .compatible = "active-semi,act8600", .data = (void *)ACT8600 },
  318. { .compatible = "active-semi,act8846", .data = (void *)ACT8846 },
  319. { .compatible = "active-semi,act8865", .data = (void *)ACT8865 },
  320. { }
  321. };
  322. MODULE_DEVICE_TABLE(of, act8865_dt_ids);
  323. static struct of_regulator_match act8846_matches[] = {
  324. [ACT8846_ID_REG1] = { .name = "REG1" },
  325. [ACT8846_ID_REG2] = { .name = "REG2" },
  326. [ACT8846_ID_REG3] = { .name = "REG3" },
  327. [ACT8846_ID_REG4] = { .name = "REG4" },
  328. [ACT8846_ID_REG5] = { .name = "REG5" },
  329. [ACT8846_ID_REG6] = { .name = "REG6" },
  330. [ACT8846_ID_REG7] = { .name = "REG7" },
  331. [ACT8846_ID_REG8] = { .name = "REG8" },
  332. [ACT8846_ID_REG9] = { .name = "REG9" },
  333. [ACT8846_ID_REG10] = { .name = "REG10" },
  334. [ACT8846_ID_REG11] = { .name = "REG11" },
  335. [ACT8846_ID_REG12] = { .name = "REG12" },
  336. };
  337. static struct of_regulator_match act8865_matches[] = {
  338. [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"},
  339. [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"},
  340. [ACT8865_ID_DCDC3] = { .name = "DCDC_REG3"},
  341. [ACT8865_ID_LDO1] = { .name = "LDO_REG1"},
  342. [ACT8865_ID_LDO2] = { .name = "LDO_REG2"},
  343. [ACT8865_ID_LDO3] = { .name = "LDO_REG3"},
  344. [ACT8865_ID_LDO4] = { .name = "LDO_REG4"},
  345. };
  346. static struct of_regulator_match act8600_matches[] = {
  347. [ACT8600_ID_DCDC1] = { .name = "DCDC_REG1"},
  348. [ACT8600_ID_DCDC2] = { .name = "DCDC_REG2"},
  349. [ACT8600_ID_DCDC3] = { .name = "DCDC_REG3"},
  350. [ACT8600_ID_SUDCDC4] = { .name = "SUDCDC_REG4"},
  351. [ACT8600_ID_LDO5] = { .name = "LDO_REG5"},
  352. [ACT8600_ID_LDO6] = { .name = "LDO_REG6"},
  353. [ACT8600_ID_LDO7] = { .name = "LDO_REG7"},
  354. [ACT8600_ID_LDO8] = { .name = "LDO_REG8"},
  355. [ACT8600_ID_LDO9] = { .name = "LDO_REG9"},
  356. [ACT8600_ID_LDO10] = { .name = "LDO_REG10"},
  357. };
  358. static int act8865_pdata_from_dt(struct device *dev,
  359. struct act8865_platform_data *pdata,
  360. unsigned long type)
  361. {
  362. int matched, i, num_matches;
  363. struct device_node *np;
  364. struct act8865_regulator_data *regulator;
  365. struct of_regulator_match *matches;
  366. switch (type) {
  367. case ACT8600:
  368. matches = act8600_matches;
  369. num_matches = ARRAY_SIZE(act8600_matches);
  370. break;
  371. case ACT8846:
  372. matches = act8846_matches;
  373. num_matches = ARRAY_SIZE(act8846_matches);
  374. break;
  375. case ACT8865:
  376. matches = act8865_matches;
  377. num_matches = ARRAY_SIZE(act8865_matches);
  378. break;
  379. default:
  380. dev_err(dev, "invalid device id %lu\n", type);
  381. return -EINVAL;
  382. }
  383. np = of_get_child_by_name(dev->of_node, "regulators");
  384. if (!np) {
  385. dev_err(dev, "missing 'regulators' subnode in DT\n");
  386. return -EINVAL;
  387. }
  388. matched = of_regulator_match(dev, np, matches, num_matches);
  389. of_node_put(np);
  390. if (matched <= 0)
  391. return matched;
  392. pdata->regulators = devm_kzalloc(dev,
  393. sizeof(struct act8865_regulator_data) *
  394. num_matches, GFP_KERNEL);
  395. if (!pdata->regulators)
  396. return -ENOMEM;
  397. pdata->num_regulators = num_matches;
  398. regulator = pdata->regulators;
  399. for (i = 0; i < num_matches; i++) {
  400. regulator->id = i;
  401. regulator->name = matches[i].name;
  402. regulator->init_data = matches[i].init_data;
  403. regulator->of_node = matches[i].of_node;
  404. regulator++;
  405. }
  406. return 0;
  407. }
  408. #else
  409. static inline int act8865_pdata_from_dt(struct device *dev,
  410. struct act8865_platform_data *pdata,
  411. unsigned long type)
  412. {
  413. return 0;
  414. }
  415. #endif
  416. static struct act8865_regulator_data *act8865_get_regulator_data(
  417. int id, struct act8865_platform_data *pdata)
  418. {
  419. int i;
  420. if (!pdata)
  421. return NULL;
  422. for (i = 0; i < pdata->num_regulators; i++) {
  423. if (pdata->regulators[i].id == id)
  424. return &pdata->regulators[i];
  425. }
  426. return NULL;
  427. }
  428. static struct i2c_client *act8865_i2c_client;
  429. static void act8865_power_off(void)
  430. {
  431. struct act8865 *act8865;
  432. act8865 = i2c_get_clientdata(act8865_i2c_client);
  433. regmap_write(act8865->regmap, act8865->off_reg, act8865->off_mask);
  434. while (1);
  435. }
  436. static int act8865_pmic_probe(struct i2c_client *client,
  437. const struct i2c_device_id *i2c_id)
  438. {
  439. const struct regulator_desc *regulators;
  440. struct act8865_platform_data pdata_of, *pdata;
  441. struct device *dev = &client->dev;
  442. int i, ret, num_regulators;
  443. struct act8865 *act8865;
  444. const struct regmap_config *regmap_config;
  445. unsigned long type;
  446. int off_reg, off_mask;
  447. int voltage_select = 0;
  448. pdata = dev_get_platdata(dev);
  449. if (dev->of_node && !pdata) {
  450. const struct of_device_id *id;
  451. id = of_match_device(of_match_ptr(act8865_dt_ids), dev);
  452. if (!id)
  453. return -ENODEV;
  454. type = (unsigned long) id->data;
  455. voltage_select = !!of_get_property(dev->of_node,
  456. "active-semi,vsel-high",
  457. NULL);
  458. } else {
  459. type = i2c_id->driver_data;
  460. }
  461. switch (type) {
  462. case ACT8600:
  463. regulators = act8600_regulators;
  464. num_regulators = ARRAY_SIZE(act8600_regulators);
  465. regmap_config = &act8600_regmap_config;
  466. off_reg = -1;
  467. off_mask = -1;
  468. break;
  469. case ACT8846:
  470. regulators = act8846_regulators;
  471. num_regulators = ARRAY_SIZE(act8846_regulators);
  472. regmap_config = &act8865_regmap_config;
  473. off_reg = ACT8846_GLB_OFF_CTRL;
  474. off_mask = ACT8846_OFF_SYSMASK;
  475. break;
  476. case ACT8865:
  477. if (voltage_select) {
  478. regulators = act8865_alt_regulators;
  479. num_regulators = ARRAY_SIZE(act8865_alt_regulators);
  480. } else {
  481. regulators = act8865_regulators;
  482. num_regulators = ARRAY_SIZE(act8865_regulators);
  483. }
  484. regmap_config = &act8865_regmap_config;
  485. off_reg = ACT8865_SYS_CTRL;
  486. off_mask = ACT8865_MSTROFF;
  487. break;
  488. default:
  489. dev_err(dev, "invalid device id %lu\n", type);
  490. return -EINVAL;
  491. }
  492. if (dev->of_node && !pdata) {
  493. ret = act8865_pdata_from_dt(dev, &pdata_of, type);
  494. if (ret < 0)
  495. return ret;
  496. pdata = &pdata_of;
  497. }
  498. act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL);
  499. if (!act8865)
  500. return -ENOMEM;
  501. act8865->regmap = devm_regmap_init_i2c(client, regmap_config);
  502. if (IS_ERR(act8865->regmap)) {
  503. ret = PTR_ERR(act8865->regmap);
  504. dev_err(dev, "Failed to allocate register map: %d\n", ret);
  505. return ret;
  506. }
  507. if (of_device_is_system_power_controller(dev->of_node)) {
  508. if (!pm_power_off && (off_reg > 0)) {
  509. act8865_i2c_client = client;
  510. act8865->off_reg = off_reg;
  511. act8865->off_mask = off_mask;
  512. pm_power_off = act8865_power_off;
  513. } else {
  514. dev_err(dev, "Failed to set poweroff capability, already defined\n");
  515. }
  516. }
  517. /* Finally register devices */
  518. for (i = 0; i < num_regulators; i++) {
  519. const struct regulator_desc *desc = &regulators[i];
  520. struct regulator_config config = { };
  521. struct act8865_regulator_data *rdata;
  522. struct regulator_dev *rdev;
  523. config.dev = dev;
  524. config.driver_data = act8865;
  525. config.regmap = act8865->regmap;
  526. rdata = act8865_get_regulator_data(desc->id, pdata);
  527. if (rdata) {
  528. config.init_data = rdata->init_data;
  529. config.of_node = rdata->of_node;
  530. }
  531. rdev = devm_regulator_register(dev, desc, &config);
  532. if (IS_ERR(rdev)) {
  533. dev_err(dev, "failed to register %s\n", desc->name);
  534. return PTR_ERR(rdev);
  535. }
  536. }
  537. i2c_set_clientdata(client, act8865);
  538. return 0;
  539. }
  540. static const struct i2c_device_id act8865_ids[] = {
  541. { .name = "act8600", .driver_data = ACT8600 },
  542. { .name = "act8846", .driver_data = ACT8846 },
  543. { .name = "act8865", .driver_data = ACT8865 },
  544. { },
  545. };
  546. MODULE_DEVICE_TABLE(i2c, act8865_ids);
  547. static struct i2c_driver act8865_pmic_driver = {
  548. .driver = {
  549. .name = "act8865",
  550. },
  551. .probe = act8865_pmic_probe,
  552. .id_table = act8865_ids,
  553. };
  554. module_i2c_driver(act8865_pmic_driver);
  555. MODULE_DESCRIPTION("active-semi act88xx voltage regulator driver");
  556. MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>");
  557. MODULE_LICENSE("GPL v2");