tps6524x-regulator.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * Regulator driver for TPS6524x PMIC
  3. *
  4. * Copyright (C) 2010 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
  11. * whether express or implied; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/err.h>
  18. #include <linux/errno.h>
  19. #include <linux/slab.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/regulator/driver.h>
  22. #include <linux/regulator/machine.h>
  23. #define REG_LDO_SET 0x0
  24. #define LDO_ILIM_MASK 1 /* 0 = 400-800, 1 = 900-1500 */
  25. #define LDO_VSEL_MASK 0x0f
  26. #define LDO2_ILIM_SHIFT 12
  27. #define LDO2_VSEL_SHIFT 4
  28. #define LDO1_ILIM_SHIFT 8
  29. #define LDO1_VSEL_SHIFT 0
  30. #define REG_BLOCK_EN 0x1
  31. #define BLOCK_MASK 1
  32. #define BLOCK_LDO1_SHIFT 0
  33. #define BLOCK_LDO2_SHIFT 1
  34. #define BLOCK_LCD_SHIFT 2
  35. #define BLOCK_USB_SHIFT 3
  36. #define REG_DCDC_SET 0x2
  37. #define DCDC_VDCDC_MASK 0x1f
  38. #define DCDC_VDCDC1_SHIFT 0
  39. #define DCDC_VDCDC2_SHIFT 5
  40. #define DCDC_VDCDC3_SHIFT 10
  41. #define REG_DCDC_EN 0x3
  42. #define DCDCDCDC_EN_MASK 0x1
  43. #define DCDCDCDC1_EN_SHIFT 0
  44. #define DCDCDCDC1_PG_MSK BIT(1)
  45. #define DCDCDCDC2_EN_SHIFT 2
  46. #define DCDCDCDC2_PG_MSK BIT(3)
  47. #define DCDCDCDC3_EN_SHIFT 4
  48. #define DCDCDCDC3_PG_MSK BIT(5)
  49. #define REG_USB 0x4
  50. #define USB_ILIM_SHIFT 0
  51. #define USB_ILIM_MASK 0x3
  52. #define USB_TSD_SHIFT 2
  53. #define USB_TSD_MASK 0x3
  54. #define USB_TWARN_SHIFT 4
  55. #define USB_TWARN_MASK 0x3
  56. #define USB_IWARN_SD BIT(6)
  57. #define USB_FAST_LOOP BIT(7)
  58. #define REG_ALARM 0x5
  59. #define ALARM_LDO1 BIT(0)
  60. #define ALARM_DCDC1 BIT(1)
  61. #define ALARM_DCDC2 BIT(2)
  62. #define ALARM_DCDC3 BIT(3)
  63. #define ALARM_LDO2 BIT(4)
  64. #define ALARM_USB_WARN BIT(5)
  65. #define ALARM_USB_ALARM BIT(6)
  66. #define ALARM_LCD BIT(9)
  67. #define ALARM_TEMP_WARM BIT(10)
  68. #define ALARM_TEMP_HOT BIT(11)
  69. #define ALARM_NRST BIT(14)
  70. #define ALARM_POWERUP BIT(15)
  71. #define REG_INT_ENABLE 0x6
  72. #define INT_LDO1 BIT(0)
  73. #define INT_DCDC1 BIT(1)
  74. #define INT_DCDC2 BIT(2)
  75. #define INT_DCDC3 BIT(3)
  76. #define INT_LDO2 BIT(4)
  77. #define INT_USB_WARN BIT(5)
  78. #define INT_USB_ALARM BIT(6)
  79. #define INT_LCD BIT(9)
  80. #define INT_TEMP_WARM BIT(10)
  81. #define INT_TEMP_HOT BIT(11)
  82. #define INT_GLOBAL_EN BIT(15)
  83. #define REG_INT_STATUS 0x7
  84. #define STATUS_LDO1 BIT(0)
  85. #define STATUS_DCDC1 BIT(1)
  86. #define STATUS_DCDC2 BIT(2)
  87. #define STATUS_DCDC3 BIT(3)
  88. #define STATUS_LDO2 BIT(4)
  89. #define STATUS_USB_WARN BIT(5)
  90. #define STATUS_USB_ALARM BIT(6)
  91. #define STATUS_LCD BIT(9)
  92. #define STATUS_TEMP_WARM BIT(10)
  93. #define STATUS_TEMP_HOT BIT(11)
  94. #define REG_SOFTWARE_RESET 0xb
  95. #define REG_WRITE_ENABLE 0xd
  96. #define REG_REV_ID 0xf
  97. #define N_DCDC 3
  98. #define N_LDO 2
  99. #define N_SWITCH 2
  100. #define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH)
  101. #define FIXED_ILIMSEL BIT(0)
  102. #define FIXED_VOLTAGE BIT(1)
  103. #define CMD_READ(reg) ((reg) << 6)
  104. #define CMD_WRITE(reg) (BIT(5) | (reg) << 6)
  105. #define STAT_CLK BIT(3)
  106. #define STAT_WRITE BIT(2)
  107. #define STAT_INVALID BIT(1)
  108. #define STAT_WP BIT(0)
  109. struct field {
  110. int reg;
  111. int shift;
  112. int mask;
  113. };
  114. struct supply_info {
  115. const char *name;
  116. int n_voltages;
  117. const int *voltages;
  118. int fixed_voltage;
  119. int n_ilimsels;
  120. const int *ilimsels;
  121. int fixed_ilimsel;
  122. int flags;
  123. struct field enable, voltage, ilimsel;
  124. };
  125. struct tps6524x {
  126. struct device *dev;
  127. struct spi_device *spi;
  128. struct mutex lock;
  129. struct regulator_desc desc[N_REGULATORS];
  130. struct regulator_dev *rdev[N_REGULATORS];
  131. };
  132. static int __read_reg(struct tps6524x *hw, int reg)
  133. {
  134. int error = 0;
  135. u16 cmd = CMD_READ(reg), in;
  136. u8 status;
  137. struct spi_message m;
  138. struct spi_transfer t[3];
  139. spi_message_init(&m);
  140. memset(t, 0, sizeof(t));
  141. t[0].tx_buf = &cmd;
  142. t[0].len = 2;
  143. t[0].bits_per_word = 12;
  144. spi_message_add_tail(&t[0], &m);
  145. t[1].rx_buf = &in;
  146. t[1].len = 2;
  147. t[1].bits_per_word = 16;
  148. spi_message_add_tail(&t[1], &m);
  149. t[2].rx_buf = &status;
  150. t[2].len = 1;
  151. t[2].bits_per_word = 4;
  152. spi_message_add_tail(&t[2], &m);
  153. error = spi_sync(hw->spi, &m);
  154. if (error < 0)
  155. return error;
  156. dev_dbg(hw->dev, "read reg %d, data %x, status %x\n",
  157. reg, in, status);
  158. if (!(status & STAT_CLK) || (status & STAT_WRITE))
  159. return -EIO;
  160. if (status & STAT_INVALID)
  161. return -EINVAL;
  162. return in;
  163. }
  164. static int read_reg(struct tps6524x *hw, int reg)
  165. {
  166. int ret;
  167. mutex_lock(&hw->lock);
  168. ret = __read_reg(hw, reg);
  169. mutex_unlock(&hw->lock);
  170. return ret;
  171. }
  172. static int __write_reg(struct tps6524x *hw, int reg, int val)
  173. {
  174. int error = 0;
  175. u16 cmd = CMD_WRITE(reg), out = val;
  176. u8 status;
  177. struct spi_message m;
  178. struct spi_transfer t[3];
  179. spi_message_init(&m);
  180. memset(t, 0, sizeof(t));
  181. t[0].tx_buf = &cmd;
  182. t[0].len = 2;
  183. t[0].bits_per_word = 12;
  184. spi_message_add_tail(&t[0], &m);
  185. t[1].tx_buf = &out;
  186. t[1].len = 2;
  187. t[1].bits_per_word = 16;
  188. spi_message_add_tail(&t[1], &m);
  189. t[2].rx_buf = &status;
  190. t[2].len = 1;
  191. t[2].bits_per_word = 4;
  192. spi_message_add_tail(&t[2], &m);
  193. error = spi_sync(hw->spi, &m);
  194. if (error < 0)
  195. return error;
  196. dev_dbg(hw->dev, "wrote reg %d, data %x, status %x\n",
  197. reg, out, status);
  198. if (!(status & STAT_CLK) || !(status & STAT_WRITE))
  199. return -EIO;
  200. if (status & (STAT_INVALID | STAT_WP))
  201. return -EINVAL;
  202. return error;
  203. }
  204. static int __rmw_reg(struct tps6524x *hw, int reg, int mask, int val)
  205. {
  206. int ret;
  207. ret = __read_reg(hw, reg);
  208. if (ret < 0)
  209. return ret;
  210. ret &= ~mask;
  211. ret |= val;
  212. ret = __write_reg(hw, reg, ret);
  213. return (ret < 0) ? ret : 0;
  214. }
  215. static int rmw_protect(struct tps6524x *hw, int reg, int mask, int val)
  216. {
  217. int ret;
  218. mutex_lock(&hw->lock);
  219. ret = __write_reg(hw, REG_WRITE_ENABLE, 1);
  220. if (ret) {
  221. dev_err(hw->dev, "failed to set write enable\n");
  222. goto error;
  223. }
  224. ret = __rmw_reg(hw, reg, mask, val);
  225. if (ret)
  226. dev_err(hw->dev, "failed to rmw register %d\n", reg);
  227. ret = __write_reg(hw, REG_WRITE_ENABLE, 0);
  228. if (ret) {
  229. dev_err(hw->dev, "failed to clear write enable\n");
  230. goto error;
  231. }
  232. error:
  233. mutex_unlock(&hw->lock);
  234. return ret;
  235. }
  236. static int read_field(struct tps6524x *hw, const struct field *field)
  237. {
  238. int tmp;
  239. tmp = read_reg(hw, field->reg);
  240. if (tmp < 0)
  241. return tmp;
  242. return (tmp >> field->shift) & field->mask;
  243. }
  244. static int write_field(struct tps6524x *hw, const struct field *field,
  245. int val)
  246. {
  247. if (val & ~field->mask)
  248. return -EOVERFLOW;
  249. return rmw_protect(hw, field->reg,
  250. field->mask << field->shift,
  251. val << field->shift);
  252. }
  253. static const int dcdc1_voltages[] = {
  254. 800000, 825000, 850000, 875000,
  255. 900000, 925000, 950000, 975000,
  256. 1000000, 1025000, 1050000, 1075000,
  257. 1100000, 1125000, 1150000, 1175000,
  258. 1200000, 1225000, 1250000, 1275000,
  259. 1300000, 1325000, 1350000, 1375000,
  260. 1400000, 1425000, 1450000, 1475000,
  261. 1500000, 1525000, 1550000, 1575000,
  262. };
  263. static const int dcdc2_voltages[] = {
  264. 1400000, 1450000, 1500000, 1550000,
  265. 1600000, 1650000, 1700000, 1750000,
  266. 1800000, 1850000, 1900000, 1950000,
  267. 2000000, 2050000, 2100000, 2150000,
  268. 2200000, 2250000, 2300000, 2350000,
  269. 2400000, 2450000, 2500000, 2550000,
  270. 2600000, 2650000, 2700000, 2750000,
  271. 2800000, 2850000, 2900000, 2950000,
  272. };
  273. static const int dcdc3_voltages[] = {
  274. 2400000, 2450000, 2500000, 2550000, 2600000,
  275. 2650000, 2700000, 2750000, 2800000, 2850000,
  276. 2900000, 2950000, 3000000, 3050000, 3100000,
  277. 3150000, 3200000, 3250000, 3300000, 3350000,
  278. 3400000, 3450000, 3500000, 3550000, 3600000,
  279. };
  280. static const int ldo1_voltages[] = {
  281. 4300000, 4350000, 4400000, 4450000,
  282. 4500000, 4550000, 4600000, 4650000,
  283. 4700000, 4750000, 4800000, 4850000,
  284. 4900000, 4950000, 5000000, 5050000,
  285. };
  286. static const int ldo2_voltages[] = {
  287. 1100000, 1150000, 1200000, 1250000,
  288. 1300000, 1700000, 1750000, 1800000,
  289. 1850000, 1900000, 3150000, 3200000,
  290. 3250000, 3300000, 3350000, 3400000,
  291. };
  292. static const int ldo_ilimsel[] = {
  293. 400000, 1500000
  294. };
  295. static const int usb_ilimsel[] = {
  296. 200000, 400000, 800000, 1000000
  297. };
  298. #define __MK_FIELD(_reg, _mask, _shift) \
  299. { .reg = (_reg), .mask = (_mask), .shift = (_shift), }
  300. static const struct supply_info supply_info[N_REGULATORS] = {
  301. {
  302. .name = "DCDC1",
  303. .flags = FIXED_ILIMSEL,
  304. .n_voltages = ARRAY_SIZE(dcdc1_voltages),
  305. .voltages = dcdc1_voltages,
  306. .fixed_ilimsel = 2400000,
  307. .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
  308. DCDCDCDC1_EN_SHIFT),
  309. .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
  310. DCDC_VDCDC1_SHIFT),
  311. },
  312. {
  313. .name = "DCDC2",
  314. .flags = FIXED_ILIMSEL,
  315. .n_voltages = ARRAY_SIZE(dcdc2_voltages),
  316. .voltages = dcdc2_voltages,
  317. .fixed_ilimsel = 1200000,
  318. .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
  319. DCDCDCDC2_EN_SHIFT),
  320. .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
  321. DCDC_VDCDC2_SHIFT),
  322. },
  323. {
  324. .name = "DCDC3",
  325. .flags = FIXED_ILIMSEL,
  326. .n_voltages = ARRAY_SIZE(dcdc3_voltages),
  327. .voltages = dcdc3_voltages,
  328. .fixed_ilimsel = 1200000,
  329. .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
  330. DCDCDCDC3_EN_SHIFT),
  331. .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
  332. DCDC_VDCDC3_SHIFT),
  333. },
  334. {
  335. .name = "LDO1",
  336. .n_voltages = ARRAY_SIZE(ldo1_voltages),
  337. .voltages = ldo1_voltages,
  338. .n_ilimsels = ARRAY_SIZE(ldo_ilimsel),
  339. .ilimsels = ldo_ilimsel,
  340. .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
  341. BLOCK_LDO1_SHIFT),
  342. .voltage = __MK_FIELD(REG_LDO_SET, LDO_VSEL_MASK,
  343. LDO1_VSEL_SHIFT),
  344. .ilimsel = __MK_FIELD(REG_LDO_SET, LDO_ILIM_MASK,
  345. LDO1_ILIM_SHIFT),
  346. },
  347. {
  348. .name = "LDO2",
  349. .n_voltages = ARRAY_SIZE(ldo2_voltages),
  350. .voltages = ldo2_voltages,
  351. .n_ilimsels = ARRAY_SIZE(ldo_ilimsel),
  352. .ilimsels = ldo_ilimsel,
  353. .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
  354. BLOCK_LDO2_SHIFT),
  355. .voltage = __MK_FIELD(REG_LDO_SET, LDO_VSEL_MASK,
  356. LDO2_VSEL_SHIFT),
  357. .ilimsel = __MK_FIELD(REG_LDO_SET, LDO_ILIM_MASK,
  358. LDO2_ILIM_SHIFT),
  359. },
  360. {
  361. .name = "USB",
  362. .flags = FIXED_VOLTAGE,
  363. .fixed_voltage = 5000000,
  364. .n_ilimsels = ARRAY_SIZE(usb_ilimsel),
  365. .ilimsels = usb_ilimsel,
  366. .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
  367. BLOCK_USB_SHIFT),
  368. .ilimsel = __MK_FIELD(REG_USB, USB_ILIM_MASK,
  369. USB_ILIM_SHIFT),
  370. },
  371. {
  372. .name = "LCD",
  373. .flags = FIXED_VOLTAGE | FIXED_ILIMSEL,
  374. .fixed_voltage = 5000000,
  375. .fixed_ilimsel = 400000,
  376. .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
  377. BLOCK_LCD_SHIFT),
  378. },
  379. };
  380. static int list_voltage(struct regulator_dev *rdev, unsigned selector)
  381. {
  382. const struct supply_info *info;
  383. struct tps6524x *hw;
  384. hw = rdev_get_drvdata(rdev);
  385. info = &supply_info[rdev_get_id(rdev)];
  386. if (info->flags & FIXED_VOLTAGE)
  387. return selector ? -EINVAL : info->fixed_voltage;
  388. return ((selector < info->n_voltages) ?
  389. info->voltages[selector] : -EINVAL);
  390. }
  391. static int set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
  392. unsigned *selector)
  393. {
  394. const struct supply_info *info;
  395. struct tps6524x *hw;
  396. unsigned i;
  397. hw = rdev_get_drvdata(rdev);
  398. info = &supply_info[rdev_get_id(rdev)];
  399. if (info->flags & FIXED_VOLTAGE)
  400. return -EINVAL;
  401. for (i = 0; i < info->n_voltages; i++)
  402. if (min_uV <= info->voltages[i] &&
  403. max_uV >= info->voltages[i])
  404. break;
  405. if (i >= info->n_voltages)
  406. i = info->n_voltages - 1;
  407. *selector = i;
  408. return write_field(hw, &info->voltage, i);
  409. }
  410. static int get_voltage(struct regulator_dev *rdev)
  411. {
  412. const struct supply_info *info;
  413. struct tps6524x *hw;
  414. int ret;
  415. hw = rdev_get_drvdata(rdev);
  416. info = &supply_info[rdev_get_id(rdev)];
  417. if (info->flags & FIXED_VOLTAGE)
  418. return info->fixed_voltage;
  419. ret = read_field(hw, &info->voltage);
  420. if (ret < 0)
  421. return ret;
  422. if (WARN_ON(ret >= info->n_voltages))
  423. return -EIO;
  424. return info->voltages[ret];
  425. }
  426. static int set_current_limit(struct regulator_dev *rdev, int min_uA,
  427. int max_uA)
  428. {
  429. const struct supply_info *info;
  430. struct tps6524x *hw;
  431. int i;
  432. hw = rdev_get_drvdata(rdev);
  433. info = &supply_info[rdev_get_id(rdev)];
  434. if (info->flags & FIXED_ILIMSEL)
  435. return -EINVAL;
  436. for (i = 0; i < info->n_ilimsels; i++)
  437. if (min_uA <= info->ilimsels[i] &&
  438. max_uA >= info->ilimsels[i])
  439. break;
  440. if (i >= info->n_ilimsels)
  441. return -EINVAL;
  442. return write_field(hw, &info->ilimsel, i);
  443. }
  444. static int get_current_limit(struct regulator_dev *rdev)
  445. {
  446. const struct supply_info *info;
  447. struct tps6524x *hw;
  448. int ret;
  449. hw = rdev_get_drvdata(rdev);
  450. info = &supply_info[rdev_get_id(rdev)];
  451. if (info->flags & FIXED_ILIMSEL)
  452. return info->fixed_ilimsel;
  453. ret = read_field(hw, &info->ilimsel);
  454. if (ret < 0)
  455. return ret;
  456. if (WARN_ON(ret >= info->n_ilimsels))
  457. return -EIO;
  458. return info->ilimsels[ret];
  459. }
  460. static int enable_supply(struct regulator_dev *rdev)
  461. {
  462. const struct supply_info *info;
  463. struct tps6524x *hw;
  464. hw = rdev_get_drvdata(rdev);
  465. info = &supply_info[rdev_get_id(rdev)];
  466. return write_field(hw, &info->enable, 1);
  467. }
  468. static int disable_supply(struct regulator_dev *rdev)
  469. {
  470. const struct supply_info *info;
  471. struct tps6524x *hw;
  472. hw = rdev_get_drvdata(rdev);
  473. info = &supply_info[rdev_get_id(rdev)];
  474. return write_field(hw, &info->enable, 0);
  475. }
  476. static int is_supply_enabled(struct regulator_dev *rdev)
  477. {
  478. const struct supply_info *info;
  479. struct tps6524x *hw;
  480. hw = rdev_get_drvdata(rdev);
  481. info = &supply_info[rdev_get_id(rdev)];
  482. return read_field(hw, &info->enable);
  483. }
  484. static struct regulator_ops regulator_ops = {
  485. .is_enabled = is_supply_enabled,
  486. .enable = enable_supply,
  487. .disable = disable_supply,
  488. .get_voltage = get_voltage,
  489. .set_voltage = set_voltage,
  490. .list_voltage = list_voltage,
  491. .set_current_limit = set_current_limit,
  492. .get_current_limit = get_current_limit,
  493. };
  494. static int pmic_remove(struct spi_device *spi)
  495. {
  496. struct tps6524x *hw = spi_get_drvdata(spi);
  497. int i;
  498. if (!hw)
  499. return 0;
  500. for (i = 0; i < N_REGULATORS; i++) {
  501. if (hw->rdev[i])
  502. regulator_unregister(hw->rdev[i]);
  503. hw->rdev[i] = NULL;
  504. }
  505. spi_set_drvdata(spi, NULL);
  506. kfree(hw);
  507. return 0;
  508. }
  509. static int __devinit pmic_probe(struct spi_device *spi)
  510. {
  511. struct tps6524x *hw;
  512. struct device *dev = &spi->dev;
  513. const struct supply_info *info = supply_info;
  514. struct regulator_init_data *init_data;
  515. int ret = 0, i;
  516. init_data = dev->platform_data;
  517. if (!init_data) {
  518. dev_err(dev, "could not find regulator platform data\n");
  519. return -EINVAL;
  520. }
  521. hw = kzalloc(sizeof(struct tps6524x), GFP_KERNEL);
  522. if (!hw) {
  523. dev_err(dev, "cannot allocate regulator private data\n");
  524. return -ENOMEM;
  525. }
  526. spi_set_drvdata(spi, hw);
  527. memset(hw, 0, sizeof(struct tps6524x));
  528. hw->dev = dev;
  529. hw->spi = spi_dev_get(spi);
  530. mutex_init(&hw->lock);
  531. for (i = 0; i < N_REGULATORS; i++, info++, init_data++) {
  532. hw->desc[i].name = info->name;
  533. hw->desc[i].id = i;
  534. hw->desc[i].n_voltages = info->n_voltages;
  535. hw->desc[i].ops = &regulator_ops;
  536. hw->desc[i].type = REGULATOR_VOLTAGE;
  537. hw->desc[i].owner = THIS_MODULE;
  538. if (info->flags & FIXED_VOLTAGE)
  539. hw->desc[i].n_voltages = 1;
  540. hw->rdev[i] = regulator_register(&hw->desc[i], dev,
  541. init_data, hw, NULL);
  542. if (IS_ERR(hw->rdev[i])) {
  543. ret = PTR_ERR(hw->rdev[i]);
  544. hw->rdev[i] = NULL;
  545. goto fail;
  546. }
  547. }
  548. return 0;
  549. fail:
  550. pmic_remove(spi);
  551. return ret;
  552. }
  553. static struct spi_driver pmic_driver = {
  554. .probe = pmic_probe,
  555. .remove = __devexit_p(pmic_remove),
  556. .driver = {
  557. .name = "tps6524x",
  558. .owner = THIS_MODULE,
  559. },
  560. };
  561. static int __init pmic_driver_init(void)
  562. {
  563. return spi_register_driver(&pmic_driver);
  564. }
  565. module_init(pmic_driver_init);
  566. static void __exit pmic_driver_exit(void)
  567. {
  568. spi_unregister_driver(&pmic_driver);
  569. }
  570. module_exit(pmic_driver_exit);
  571. MODULE_DESCRIPTION("TPS6524X PMIC Driver");
  572. MODULE_AUTHOR("Cyril Chemparathy");
  573. MODULE_LICENSE("GPL");
  574. MODULE_ALIAS("spi:tps6524x");