act8865-regulator.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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_config act8865_regmap_config = {
  133. .reg_bits = 8,
  134. .val_bits = 8,
  135. };
  136. static const struct regulator_linear_range act8865_voltage_ranges[] = {
  137. REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000),
  138. REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000),
  139. REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000),
  140. };
  141. static const struct regulator_linear_range act8600_sudcdc_voltage_ranges[] = {
  142. REGULATOR_LINEAR_RANGE(3000000, 0, 63, 0),
  143. REGULATOR_LINEAR_RANGE(3000000, 64, 159, 100000),
  144. REGULATOR_LINEAR_RANGE(12600000, 160, 191, 200000),
  145. REGULATOR_LINEAR_RANGE(19000000, 191, 255, 400000),
  146. };
  147. static struct regulator_ops act8865_ops = {
  148. .list_voltage = regulator_list_voltage_linear_range,
  149. .map_voltage = regulator_map_voltage_linear_range,
  150. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  151. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  152. .enable = regulator_enable_regmap,
  153. .disable = regulator_disable_regmap,
  154. .is_enabled = regulator_is_enabled_regmap,
  155. };
  156. static struct regulator_ops act8865_ldo_ops = {
  157. .enable = regulator_enable_regmap,
  158. .disable = regulator_disable_regmap,
  159. .is_enabled = regulator_is_enabled_regmap,
  160. };
  161. #define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \
  162. [_family##_ID_##_id] = { \
  163. .name = _name, \
  164. .supply_name = _supply, \
  165. .id = _family##_ID_##_id, \
  166. .type = REGULATOR_VOLTAGE, \
  167. .ops = &act8865_ops, \
  168. .n_voltages = ACT8865_VOLTAGE_NUM, \
  169. .linear_ranges = act8865_voltage_ranges, \
  170. .n_linear_ranges = ARRAY_SIZE(act8865_voltage_ranges), \
  171. .vsel_reg = _family##_##_id##_##_vsel_reg, \
  172. .vsel_mask = ACT8865_VSEL_MASK, \
  173. .enable_reg = _family##_##_id##_CTRL, \
  174. .enable_mask = ACT8865_ENA, \
  175. .owner = THIS_MODULE, \
  176. }
  177. static const struct regulator_desc act8600_regulators[] = {
  178. ACT88xx_REG("DCDC1", ACT8600, DCDC1, VSET, "vp1"),
  179. ACT88xx_REG("DCDC2", ACT8600, DCDC2, VSET, "vp2"),
  180. ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"),
  181. {
  182. .name = "SUDCDC_REG4",
  183. .id = ACT8600_ID_SUDCDC4,
  184. .ops = &act8865_ops,
  185. .type = REGULATOR_VOLTAGE,
  186. .n_voltages = ACT8600_SUDCDC_VOLTAGE_NUM,
  187. .linear_ranges = act8600_sudcdc_voltage_ranges,
  188. .n_linear_ranges = ARRAY_SIZE(act8600_sudcdc_voltage_ranges),
  189. .vsel_reg = ACT8600_SUDCDC4_VSET,
  190. .vsel_mask = ACT8600_SUDCDC_VSEL_MASK,
  191. .enable_reg = ACT8600_SUDCDC4_CTRL,
  192. .enable_mask = ACT8865_ENA,
  193. .owner = THIS_MODULE,
  194. },
  195. ACT88xx_REG("LDO5", ACT8600, LDO5, VSET, "inl"),
  196. ACT88xx_REG("LDO6", ACT8600, LDO6, VSET, "inl"),
  197. ACT88xx_REG("LDO7", ACT8600, LDO7, VSET, "inl"),
  198. ACT88xx_REG("LDO8", ACT8600, LDO8, VSET, "inl"),
  199. {
  200. .name = "LDO_REG9",
  201. .id = ACT8600_ID_LDO9,
  202. .ops = &act8865_ldo_ops,
  203. .type = REGULATOR_VOLTAGE,
  204. .n_voltages = 1,
  205. .fixed_uV = 3300000,
  206. .enable_reg = ACT8600_LDO910_CTRL,
  207. .enable_mask = ACT8865_ENA,
  208. .owner = THIS_MODULE,
  209. },
  210. {
  211. .name = "LDO_REG10",
  212. .id = ACT8600_ID_LDO10,
  213. .ops = &act8865_ldo_ops,
  214. .type = REGULATOR_VOLTAGE,
  215. .n_voltages = 1,
  216. .fixed_uV = 1200000,
  217. .enable_reg = ACT8600_LDO910_CTRL,
  218. .enable_mask = ACT8600_LDO10_ENA,
  219. .owner = THIS_MODULE,
  220. },
  221. };
  222. static const struct regulator_desc act8846_regulators[] = {
  223. ACT88xx_REG("REG1", ACT8846, REG1, VSET, "vp1"),
  224. ACT88xx_REG("REG2", ACT8846, REG2, VSET0, "vp2"),
  225. ACT88xx_REG("REG3", ACT8846, REG3, VSET0, "vp3"),
  226. ACT88xx_REG("REG4", ACT8846, REG4, VSET0, "vp4"),
  227. ACT88xx_REG("REG5", ACT8846, REG5, VSET, "inl1"),
  228. ACT88xx_REG("REG6", ACT8846, REG6, VSET, "inl1"),
  229. ACT88xx_REG("REG7", ACT8846, REG7, VSET, "inl1"),
  230. ACT88xx_REG("REG8", ACT8846, REG8, VSET, "inl2"),
  231. ACT88xx_REG("REG9", ACT8846, REG9, VSET, "inl2"),
  232. ACT88xx_REG("REG10", ACT8846, REG10, VSET, "inl3"),
  233. ACT88xx_REG("REG11", ACT8846, REG11, VSET, "inl3"),
  234. ACT88xx_REG("REG12", ACT8846, REG12, VSET, "inl3"),
  235. };
  236. static const struct regulator_desc act8865_regulators[] = {
  237. ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET1, "vp1"),
  238. ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET1, "vp2"),
  239. ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET1, "vp3"),
  240. ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
  241. ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
  242. ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
  243. ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
  244. };
  245. static const struct regulator_desc act8865_alt_regulators[] = {
  246. ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET2, "vp1"),
  247. ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET2, "vp2"),
  248. ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET2, "vp3"),
  249. ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"),
  250. ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"),
  251. ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"),
  252. ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"),
  253. };
  254. #ifdef CONFIG_OF
  255. static const struct of_device_id act8865_dt_ids[] = {
  256. { .compatible = "active-semi,act8600", .data = (void *)ACT8600 },
  257. { .compatible = "active-semi,act8846", .data = (void *)ACT8846 },
  258. { .compatible = "active-semi,act8865", .data = (void *)ACT8865 },
  259. { }
  260. };
  261. MODULE_DEVICE_TABLE(of, act8865_dt_ids);
  262. static struct of_regulator_match act8846_matches[] = {
  263. [ACT8846_ID_REG1] = { .name = "REG1" },
  264. [ACT8846_ID_REG2] = { .name = "REG2" },
  265. [ACT8846_ID_REG3] = { .name = "REG3" },
  266. [ACT8846_ID_REG4] = { .name = "REG4" },
  267. [ACT8846_ID_REG5] = { .name = "REG5" },
  268. [ACT8846_ID_REG6] = { .name = "REG6" },
  269. [ACT8846_ID_REG7] = { .name = "REG7" },
  270. [ACT8846_ID_REG8] = { .name = "REG8" },
  271. [ACT8846_ID_REG9] = { .name = "REG9" },
  272. [ACT8846_ID_REG10] = { .name = "REG10" },
  273. [ACT8846_ID_REG11] = { .name = "REG11" },
  274. [ACT8846_ID_REG12] = { .name = "REG12" },
  275. };
  276. static struct of_regulator_match act8865_matches[] = {
  277. [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"},
  278. [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"},
  279. [ACT8865_ID_DCDC3] = { .name = "DCDC_REG3"},
  280. [ACT8865_ID_LDO1] = { .name = "LDO_REG1"},
  281. [ACT8865_ID_LDO2] = { .name = "LDO_REG2"},
  282. [ACT8865_ID_LDO3] = { .name = "LDO_REG3"},
  283. [ACT8865_ID_LDO4] = { .name = "LDO_REG4"},
  284. };
  285. static struct of_regulator_match act8600_matches[] = {
  286. [ACT8600_ID_DCDC1] = { .name = "DCDC_REG1"},
  287. [ACT8600_ID_DCDC2] = { .name = "DCDC_REG2"},
  288. [ACT8600_ID_DCDC3] = { .name = "DCDC_REG3"},
  289. [ACT8600_ID_SUDCDC4] = { .name = "SUDCDC_REG4"},
  290. [ACT8600_ID_LDO5] = { .name = "LDO_REG5"},
  291. [ACT8600_ID_LDO6] = { .name = "LDO_REG6"},
  292. [ACT8600_ID_LDO7] = { .name = "LDO_REG7"},
  293. [ACT8600_ID_LDO8] = { .name = "LDO_REG8"},
  294. [ACT8600_ID_LDO9] = { .name = "LDO_REG9"},
  295. [ACT8600_ID_LDO10] = { .name = "LDO_REG10"},
  296. };
  297. static int act8865_pdata_from_dt(struct device *dev,
  298. struct device_node **of_node,
  299. struct act8865_platform_data *pdata,
  300. unsigned long type)
  301. {
  302. int matched, i, num_matches;
  303. struct device_node *np;
  304. struct act8865_regulator_data *regulator;
  305. struct of_regulator_match *matches;
  306. np = of_get_child_by_name(dev->of_node, "regulators");
  307. if (!np) {
  308. dev_err(dev, "missing 'regulators' subnode in DT\n");
  309. return -EINVAL;
  310. }
  311. switch (type) {
  312. case ACT8600:
  313. matches = act8600_matches;
  314. num_matches = ARRAY_SIZE(act8600_matches);
  315. break;
  316. case ACT8846:
  317. matches = act8846_matches;
  318. num_matches = ARRAY_SIZE(act8846_matches);
  319. break;
  320. case ACT8865:
  321. matches = act8865_matches;
  322. num_matches = ARRAY_SIZE(act8865_matches);
  323. break;
  324. default:
  325. dev_err(dev, "invalid device id %lu\n", type);
  326. return -EINVAL;
  327. }
  328. matched = of_regulator_match(dev, np, matches, num_matches);
  329. of_node_put(np);
  330. if (matched <= 0)
  331. return matched;
  332. pdata->regulators = devm_kzalloc(dev,
  333. sizeof(struct act8865_regulator_data) *
  334. num_matches, GFP_KERNEL);
  335. if (!pdata->regulators)
  336. return -ENOMEM;
  337. pdata->num_regulators = num_matches;
  338. regulator = pdata->regulators;
  339. for (i = 0; i < num_matches; i++) {
  340. regulator->id = i;
  341. regulator->name = matches[i].name;
  342. regulator->init_data = matches[i].init_data;
  343. of_node[i] = matches[i].of_node;
  344. regulator++;
  345. }
  346. return 0;
  347. }
  348. #else
  349. static inline int act8865_pdata_from_dt(struct device *dev,
  350. struct device_node **of_node,
  351. struct act8865_platform_data *pdata,
  352. unsigned long type)
  353. {
  354. return 0;
  355. }
  356. #endif
  357. static struct regulator_init_data
  358. *act8865_get_init_data(int id, struct act8865_platform_data *pdata)
  359. {
  360. int i;
  361. if (!pdata)
  362. return NULL;
  363. for (i = 0; i < pdata->num_regulators; i++) {
  364. if (pdata->regulators[i].id == id)
  365. return pdata->regulators[i].init_data;
  366. }
  367. return NULL;
  368. }
  369. static struct i2c_client *act8865_i2c_client;
  370. static void act8865_power_off(void)
  371. {
  372. struct act8865 *act8865;
  373. act8865 = i2c_get_clientdata(act8865_i2c_client);
  374. regmap_write(act8865->regmap, act8865->off_reg, act8865->off_mask);
  375. while (1);
  376. }
  377. static int act8865_pmic_probe(struct i2c_client *client,
  378. const struct i2c_device_id *i2c_id)
  379. {
  380. const struct regulator_desc *regulators;
  381. struct act8865_platform_data pdata_of, *pdata;
  382. struct device *dev = &client->dev;
  383. struct device_node **of_node;
  384. int i, ret, num_regulators;
  385. struct act8865 *act8865;
  386. unsigned long type;
  387. int off_reg, off_mask;
  388. int voltage_select = 0;
  389. pdata = dev_get_platdata(dev);
  390. if (dev->of_node && !pdata) {
  391. const struct of_device_id *id;
  392. id = of_match_device(of_match_ptr(act8865_dt_ids), dev);
  393. if (!id)
  394. return -ENODEV;
  395. type = (unsigned long) id->data;
  396. voltage_select = !!of_get_property(dev->of_node,
  397. "active-semi,vsel-high",
  398. NULL);
  399. } else {
  400. type = i2c_id->driver_data;
  401. }
  402. switch (type) {
  403. case ACT8600:
  404. regulators = act8600_regulators;
  405. num_regulators = ARRAY_SIZE(act8600_regulators);
  406. off_reg = -1;
  407. off_mask = -1;
  408. break;
  409. case ACT8846:
  410. regulators = act8846_regulators;
  411. num_regulators = ARRAY_SIZE(act8846_regulators);
  412. off_reg = ACT8846_GLB_OFF_CTRL;
  413. off_mask = ACT8846_OFF_SYSMASK;
  414. break;
  415. case ACT8865:
  416. if (voltage_select) {
  417. regulators = act8865_alt_regulators;
  418. num_regulators = ARRAY_SIZE(act8865_alt_regulators);
  419. } else {
  420. regulators = act8865_regulators;
  421. num_regulators = ARRAY_SIZE(act8865_regulators);
  422. }
  423. off_reg = ACT8865_SYS_CTRL;
  424. off_mask = ACT8865_MSTROFF;
  425. break;
  426. default:
  427. dev_err(dev, "invalid device id %lu\n", type);
  428. return -EINVAL;
  429. }
  430. of_node = devm_kzalloc(dev, sizeof(struct device_node *) *
  431. num_regulators, GFP_KERNEL);
  432. if (!of_node)
  433. return -ENOMEM;
  434. if (dev->of_node && !pdata) {
  435. ret = act8865_pdata_from_dt(dev, of_node, &pdata_of, type);
  436. if (ret < 0)
  437. return ret;
  438. pdata = &pdata_of;
  439. }
  440. if (pdata->num_regulators > num_regulators) {
  441. dev_err(dev, "too many regulators: %d\n",
  442. pdata->num_regulators);
  443. return -EINVAL;
  444. }
  445. act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL);
  446. if (!act8865)
  447. return -ENOMEM;
  448. act8865->regmap = devm_regmap_init_i2c(client, &act8865_regmap_config);
  449. if (IS_ERR(act8865->regmap)) {
  450. ret = PTR_ERR(act8865->regmap);
  451. dev_err(&client->dev, "Failed to allocate register map: %d\n",
  452. ret);
  453. return ret;
  454. }
  455. if (of_device_is_system_power_controller(dev->of_node)) {
  456. if (!pm_power_off && (off_reg > 0)) {
  457. act8865_i2c_client = client;
  458. act8865->off_reg = off_reg;
  459. act8865->off_mask = off_mask;
  460. pm_power_off = act8865_power_off;
  461. } else {
  462. dev_err(dev, "Failed to set poweroff capability, already defined\n");
  463. }
  464. }
  465. /* Finally register devices */
  466. for (i = 0; i < num_regulators; i++) {
  467. const struct regulator_desc *desc = &regulators[i];
  468. struct regulator_config config = { };
  469. struct regulator_dev *rdev;
  470. config.dev = dev;
  471. config.init_data = act8865_get_init_data(desc->id, pdata);
  472. config.of_node = of_node[i];
  473. config.driver_data = act8865;
  474. config.regmap = act8865->regmap;
  475. rdev = devm_regulator_register(&client->dev, desc, &config);
  476. if (IS_ERR(rdev)) {
  477. dev_err(dev, "failed to register %s\n", desc->name);
  478. return PTR_ERR(rdev);
  479. }
  480. }
  481. i2c_set_clientdata(client, act8865);
  482. devm_kfree(dev, of_node);
  483. return 0;
  484. }
  485. static const struct i2c_device_id act8865_ids[] = {
  486. { .name = "act8600", .driver_data = ACT8600 },
  487. { .name = "act8846", .driver_data = ACT8846 },
  488. { .name = "act8865", .driver_data = ACT8865 },
  489. { },
  490. };
  491. MODULE_DEVICE_TABLE(i2c, act8865_ids);
  492. static struct i2c_driver act8865_pmic_driver = {
  493. .driver = {
  494. .name = "act8865",
  495. },
  496. .probe = act8865_pmic_probe,
  497. .id_table = act8865_ids,
  498. };
  499. module_i2c_driver(act8865_pmic_driver);
  500. MODULE_DESCRIPTION("active-semi act88xx voltage regulator driver");
  501. MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>");
  502. MODULE_LICENSE("GPL v2");