max77823.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * max77823.c
  3. * Samsung Mobile Battery Driver
  4. *
  5. * Copyright (C) 2012 Samsung Electronics
  6. *
  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 version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #define DEBUG
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/mutex.h>
  16. #include <linux/regulator/machine.h>
  17. #include <linux/i2c.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/irq.h>
  20. #include <linux/mfd/core.h>
  21. #include <linux/mfd/max77823.h>
  22. #include <linux/mfd/max77823-private.h>
  23. #if defined (CONFIG_OF)
  24. #include <linux/of_device.h>
  25. #include <linux/of_gpio.h>
  26. #endif /* CONFIG_OF */
  27. static struct mfd_cell max77823_devs[] = {
  28. { .name = "max77823-charger",},
  29. { .name = "max77823-fuelgauge",},
  30. { .name = "max77823-safeout",},
  31. };
  32. static const u8 max77823_mask_reg[] = {
  33. [CHG_IRQ] = MAX77823_CHG_INT_MASK,
  34. [FUEL_IRQ] = MAX77823_FUEL_INT_MASK,
  35. };
  36. int max77823_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
  37. {
  38. struct max77823_dev *max77823 = i2c_get_clientdata(i2c);
  39. int ret;
  40. mutex_lock(&max77823->i2c_lock);
  41. ret = i2c_smbus_read_byte_data(i2c, reg);
  42. mutex_unlock(&max77823->i2c_lock);
  43. if (ret < 0) {
  44. pr_info("%s reg(0x%x), ret(%d)\n", __func__, reg, ret);
  45. return ret;
  46. }
  47. ret &= 0xff;
  48. *dest = ret;
  49. return 0;
  50. }
  51. EXPORT_SYMBOL_GPL(max77823_read_reg);
  52. int max77823_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
  53. {
  54. struct max77823_dev *max77823 = i2c_get_clientdata(i2c);
  55. int ret;
  56. mutex_lock(&max77823->i2c_lock);
  57. ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf);
  58. mutex_unlock(&max77823->i2c_lock);
  59. if (ret < 0)
  60. return ret;
  61. return 0;
  62. }
  63. EXPORT_SYMBOL_GPL(max77823_bulk_read);
  64. int max77823_read_word(struct i2c_client *i2c, u8 reg)
  65. {
  66. struct max77823_dev *max77823 = i2c_get_clientdata(i2c);
  67. int ret;
  68. mutex_lock(&max77823->i2c_lock);
  69. ret = i2c_smbus_read_word_data(i2c, reg);
  70. mutex_unlock(&max77823->i2c_lock);
  71. if (ret < 0)
  72. return ret;
  73. return ret;
  74. }
  75. EXPORT_SYMBOL_GPL(max77823_read_word);
  76. int max77823_write_reg(struct i2c_client *i2c, u8 reg, u8 value)
  77. {
  78. struct max77823_dev *max77823 = i2c_get_clientdata(i2c);
  79. int ret;
  80. mutex_lock(&max77823->i2c_lock);
  81. ret = i2c_smbus_write_byte_data(i2c, reg, value);
  82. mutex_unlock(&max77823->i2c_lock);
  83. if (ret < 0)
  84. pr_info("%s reg(0x%x), ret(%d)\n",
  85. __func__, reg, ret);
  86. return ret;
  87. }
  88. EXPORT_SYMBOL_GPL(max77823_write_reg);
  89. int max77823_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf)
  90. {
  91. struct max77823_dev *max77823 = i2c_get_clientdata(i2c);
  92. int ret;
  93. mutex_lock(&max77823->i2c_lock);
  94. ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf);
  95. mutex_unlock(&max77823->i2c_lock);
  96. if (ret < 0)
  97. return ret;
  98. return 0;
  99. }
  100. EXPORT_SYMBOL_GPL(max77823_bulk_write);
  101. int max77823_write_word(struct i2c_client *i2c, u8 reg, u16 value)
  102. {
  103. struct max77823_dev *max77823 = i2c_get_clientdata(i2c);
  104. int ret;
  105. mutex_lock(&max77823->i2c_lock);
  106. ret = i2c_smbus_write_word_data(i2c, reg, value);
  107. mutex_unlock(&max77823->i2c_lock);
  108. if (ret < 0)
  109. return ret;
  110. return 0;
  111. }
  112. EXPORT_SYMBOL_GPL(max77823_write_word);
  113. int max77823_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
  114. {
  115. struct max77823_dev *max77823 = i2c_get_clientdata(i2c);
  116. int ret;
  117. mutex_lock(&max77823->i2c_lock);
  118. ret = i2c_smbus_read_byte_data(i2c, reg);
  119. if (ret >= 0) {
  120. u8 old_val = ret & 0xff;
  121. u8 new_val = (val & mask) | (old_val & (~mask));
  122. ret = i2c_smbus_write_byte_data(i2c, reg, new_val);
  123. }
  124. mutex_unlock(&max77823->i2c_lock);
  125. return ret;
  126. }
  127. EXPORT_SYMBOL_GPL(max77823_update_reg);
  128. static struct i2c_client *get_i2c(struct max77823_dev *max77823,
  129. enum max77823_irq_source src)
  130. {
  131. switch (src) {
  132. case CHG_IRQ:
  133. return max77823->charger;
  134. case FUEL_IRQ:
  135. return max77823->fuelgauge;
  136. default:
  137. return ERR_PTR(-EINVAL);
  138. }
  139. }
  140. struct max77823_irq_data {
  141. int mask;
  142. enum max77823_irq_source group;
  143. };
  144. #define DECLARE_IRQ(idx, _group, _mask) \
  145. [(idx)] = { .group = (_group), .mask = (_mask) }
  146. static const struct max77823_irq_data max77823_irqs[] = {
  147. DECLARE_IRQ(MAX77823_CHG_IRQ_BYP_I, CHG_IRQ, 1 << 0),
  148. DECLARE_IRQ(MAX77823_CHG_IRQ_BATP_I, CHG_IRQ, 1 << 2),
  149. DECLARE_IRQ(MAX77823_CHG_IRQ_BAT_I, CHG_IRQ, 1 << 3),
  150. DECLARE_IRQ(MAX77823_CHG_IRQ_CHG_I, CHG_IRQ, 1 << 4),
  151. DECLARE_IRQ(MAX77823_CHG_IRQ_WCIN_I, CHG_IRQ, 1 << 5),
  152. DECLARE_IRQ(MAX77823_CHG_IRQ_CHGIN_I, CHG_IRQ, 1 << 6),
  153. DECLARE_IRQ(MAX77823_FG_IRQ_ALERT, FUEL_IRQ, 1 << 1),
  154. };
  155. static void max77823_irq_lock(struct irq_data *data)
  156. {
  157. struct max77823_dev *max77823 = irq_get_chip_data(data->irq);
  158. mutex_lock(&max77823->irqlock);
  159. }
  160. static void max77823_irq_sync_unlock(struct irq_data *data)
  161. {
  162. struct max77823_dev *max77823 = irq_get_chip_data(data->irq);
  163. int i;
  164. for (i = 0; i < MAX77823_IRQ_GROUP_NR; i++) {
  165. u8 mask_reg = max77823_mask_reg[i];
  166. struct i2c_client *i2c = get_i2c(max77823, i);
  167. if (mask_reg == MAX77823_REG_INVALID ||
  168. IS_ERR_OR_NULL(i2c))
  169. continue;
  170. max77823->irq_masks_cache[i] = max77823->irq_masks_cur[i];
  171. max77823_write_reg(i2c, max77823_mask_reg[i],
  172. max77823->irq_masks_cur[i]);
  173. }
  174. mutex_unlock(&max77823->irqlock);
  175. }
  176. static const inline struct max77823_irq_data *
  177. irq_to_max77823_irq(struct max77823_dev *max77823, int irq)
  178. {
  179. return &max77823_irqs[irq - max77823->irq_base];
  180. }
  181. static void max77823_irq_mask(struct irq_data *data)
  182. {
  183. struct max77823_dev *max77823 = irq_get_chip_data(data->irq);
  184. const struct max77823_irq_data *irq_data =
  185. irq_to_max77823_irq(max77823, data->irq);
  186. if (irq_data->group >= MAX77823_IRQ_GROUP_NR)
  187. return;
  188. max77823->irq_masks_cur[irq_data->group] |= irq_data->mask;
  189. }
  190. static void max77823_irq_unmask(struct irq_data *data)
  191. {
  192. struct max77823_dev *max77823 = irq_get_chip_data(data->irq);
  193. const struct max77823_irq_data *irq_data =
  194. irq_to_max77823_irq(max77823, data->irq);
  195. if (irq_data->group >= MAX77823_IRQ_GROUP_NR)
  196. return;
  197. max77823->irq_masks_cur[irq_data->group] &= ~irq_data->mask;
  198. }
  199. static struct irq_chip max77823_irq_chip = {
  200. .name = "max77823",
  201. .irq_bus_lock = max77823_irq_lock,
  202. .irq_bus_sync_unlock = max77823_irq_sync_unlock,
  203. .irq_mask = max77823_irq_mask,
  204. .irq_unmask = max77823_irq_unmask,
  205. };
  206. static irqreturn_t max77823_irq_thread(int irq, void *data)
  207. {
  208. struct max77823_dev *max77823 = data;
  209. u8 irq_reg[MAX77823_IRQ_GROUP_NR] = {0};
  210. u8 irq_src;
  211. int ret;
  212. int i;
  213. pr_debug("%s: irq gpio pre-state(0x%02x)\n", __func__,
  214. gpio_get_value(max77823->irq_gpio));
  215. clear_retry:
  216. ret = max77823_read_reg(max77823->i2c,
  217. MAX77823_PMIC_INT, &irq_src);
  218. if (ret < 0) {
  219. dev_err(max77823->dev, "Failed to read interrupt source: %d\n",
  220. ret);
  221. return IRQ_NONE;
  222. }
  223. pr_info("%s: interrupt source(0x%02x)\n", __func__, irq_src);
  224. if (irq_src & MAX77823_IRQSRC_CHG) {
  225. /* CHG_IRQ */
  226. ret = max77823_read_reg(max77823->charger,
  227. MAX77823_CHG_INT, &irq_reg[CHG_IRQ]);
  228. pr_info("%s: charger interrupt(0x%02x)\n",
  229. __func__, irq_reg[CHG_IRQ]);
  230. /* mask chgin to prevent chgin infinite interrupt
  231. * chgin is unmasked chgin isr
  232. */
  233. if (irq_reg[CHG_IRQ] &
  234. max77823_irqs[MAX77823_CHG_IRQ_CHGIN_I].mask) {
  235. u8 reg_data;
  236. max77823_read_reg(max77823->charger,
  237. MAX77823_CHG_INT_MASK, &reg_data);
  238. reg_data |= (1 << 6);
  239. max77823_write_reg(max77823->charger,
  240. MAX77823_CHG_INT_MASK, reg_data);
  241. }
  242. }
  243. if (irq_src & MAX77823_IRQSRC_FG) {
  244. irq_reg[FUEL_IRQ] = irq_src;
  245. }
  246. if (irq_src & MAX77823_IRQSRC_SYS) {
  247. u8 reg_data;
  248. ret = max77823_read_reg(max77823->i2c,
  249. MAX77823_PMIC_SYS_INT, &irq_reg[SYS_IRQ]);
  250. pr_info("%s: sys interrupt(0x%02x)\n",
  251. __func__, irq_reg[SYS_IRQ]);
  252. ret = max77823_read_reg(max77823->i2c,
  253. MAX77823_PMIC_INT_MASK, &reg_data);
  254. pr_info("%s: int mask(0x%02x)\n",
  255. __func__, reg_data);
  256. ret = max77823_read_reg(max77823->i2c,
  257. MAX77823_PMIC_SYS_INT_MASK, &reg_data);
  258. pr_info("%s: sys int mask(0x%02x)\n",
  259. __func__, reg_data);
  260. }
  261. pr_debug("%s: irq gpio post-state(0x%02x)\n", __func__,
  262. gpio_get_value(max77823->irq_gpio));
  263. if (gpio_get_value(max77823->irq_gpio) == 0) {
  264. pr_warn("%s: irq_gpio is not High!\n", __func__);
  265. goto clear_retry;
  266. }
  267. /* Apply masking */
  268. for (i = 0; i < MAX77823_IRQ_GROUP_NR; i++) {
  269. irq_reg[i] &= ~max77823->irq_masks_cur[i];
  270. }
  271. /* Report */
  272. for (i = 0; i < MAX77823_IRQ_NR; i++) {
  273. if (irq_reg[max77823_irqs[i].group] & max77823_irqs[i].mask) {
  274. handle_nested_irq(max77823->irq_base + i);
  275. }
  276. }
  277. return IRQ_HANDLED;
  278. }
  279. static int max77823_irq_init(struct max77823_dev *max77823)
  280. {
  281. int i;
  282. int cur_irq;
  283. int ret;
  284. u8 i2c_data;
  285. if (!max77823->irq_gpio) {
  286. dev_warn(max77823->dev, "No interrupt specified.\n");
  287. max77823->irq_base = 0;
  288. return 0;
  289. }
  290. if (!max77823->irq_base) {
  291. dev_err(max77823->dev, "No interrupt base specified.\n");
  292. return 0;
  293. }
  294. mutex_init(&max77823->irqlock);
  295. max77823->irq = gpio_to_irq(max77823->irq_gpio);
  296. pr_info("%s irq=%d, irq->gpio=%d\n", __func__,
  297. max77823->irq, max77823->irq_gpio);
  298. ret = gpio_request(max77823->irq_gpio, "max77823_irq");
  299. if (ret) {
  300. dev_err(max77823->dev, "%s: failed requesting gpio %d\n",
  301. __func__, max77823->irq_gpio);
  302. return ret;
  303. }
  304. gpio_direction_input(max77823->irq_gpio);
  305. gpio_free(max77823->irq_gpio);
  306. /* Mask individual interrupt sources */
  307. for (i = 0; i < MAX77823_IRQ_GROUP_NR; i++) {
  308. struct i2c_client *i2c;
  309. max77823->irq_masks_cur[i] = 0xff;
  310. max77823->irq_masks_cache[i] = 0xff;
  311. i2c = get_i2c(max77823, i);
  312. if (IS_ERR_OR_NULL(i2c))
  313. continue;
  314. if (max77823_mask_reg[i] == MAX77823_REG_INVALID)
  315. continue;
  316. if (i == FUEL_IRQ)
  317. max77823_write_reg(i2c, max77823_mask_reg[i], 0x00);
  318. else
  319. max77823_write_reg(i2c, max77823_mask_reg[i], 0xff);
  320. }
  321. /* Register with genirq */
  322. for (i = 0; i < MAX77823_IRQ_NR; i++) {
  323. cur_irq = i + max77823->irq_base;
  324. irq_set_chip_data(cur_irq, max77823);
  325. irq_set_chip_and_handler(cur_irq, &max77823_irq_chip,
  326. handle_edge_irq);
  327. irq_set_nested_thread(cur_irq, 1);
  328. #ifdef CONFIG_ARM
  329. set_irq_flags(cur_irq, IRQF_VALID);
  330. #else
  331. irq_set_noprobe(cur_irq);
  332. #endif
  333. }
  334. /* Unmask max77804 interrupt */
  335. ret = max77823_read_reg(max77823->i2c, MAX77823_PMIC_INT_MASK,
  336. &i2c_data);
  337. if (ret) {
  338. dev_err(max77823->dev, "%s: fail to read max77823 reg\n", __func__);
  339. return ret;
  340. }
  341. i2c_data &= ~(MAX77823_IRQSRC_CHG); /* Unmask charger interrupt */
  342. //i2c_data &= ~(MAX77823_IRQSRC_FG); /* Unmask fuelgauge interrupt */
  343. max77823_write_reg(max77823->i2c, MAX77823_PMIC_INT_MASK,
  344. i2c_data);
  345. pr_info("%s max77804_PMIC_REG_INTSRC_MASK=0x%02x\n",
  346. __func__, i2c_data);
  347. ret = request_threaded_irq(max77823->irq, NULL, max77823_irq_thread,
  348. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  349. "max77823-irq", max77823);
  350. if (ret) {
  351. dev_err(max77823->dev, "Failed to request IRQ %d: %d\n",
  352. max77823->irq, ret);
  353. return ret;
  354. }
  355. return 0;
  356. }
  357. #if defined(CONFIG_OF)
  358. static int of_max77823_dt(struct device *dev, struct max77823_platform_data *pdata)
  359. {
  360. struct device_node *np_max77823 = dev->of_node;
  361. if(!np_max77823)
  362. return -EINVAL;
  363. pdata->irq_gpio = of_get_named_gpio(np_max77823, "max77823,irq-gpio", 0);
  364. pdata->wakeup = of_property_read_bool(np_max77823, "max77823,wakeup");
  365. pr_info("%s: irq-gpio: %u \n", __func__, pdata->irq_gpio);
  366. return 0;
  367. }
  368. #endif /* CONFIG_OF */
  369. static struct regulator_consumer_supply safeout1_supply[] = {
  370. REGULATOR_SUPPLY("safeout1", NULL),
  371. };
  372. static struct regulator_consumer_supply safeout2_supply[] = {
  373. REGULATOR_SUPPLY("safeout2", NULL),
  374. };
  375. static struct regulator_consumer_supply charger_supply[] = {
  376. REGULATOR_SUPPLY("vinchg1", "charger-manager.0"),
  377. REGULATOR_SUPPLY("vinchg1", NULL),
  378. };
  379. static struct regulator_init_data safeout1_init_data = {
  380. .constraints = {
  381. .name = "safeout1 range",
  382. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  383. .always_on = 1,
  384. .boot_on = 1,
  385. .state_mem = {
  386. .enabled = 1,
  387. },
  388. },
  389. .num_consumer_supplies = ARRAY_SIZE(safeout1_supply),
  390. .consumer_supplies = safeout1_supply,
  391. };
  392. static struct regulator_init_data safeout2_init_data = {
  393. .constraints = {
  394. .name = "safeout2 range",
  395. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  396. .always_on = 0,
  397. .boot_on = 0,
  398. .state_mem = {
  399. .enabled = 1,
  400. },
  401. },
  402. .num_consumer_supplies = ARRAY_SIZE(safeout2_supply),
  403. .consumer_supplies = safeout2_supply,
  404. };
  405. static struct regulator_init_data charger_init_data = {
  406. .constraints = {
  407. .name = "CHARGER",
  408. .valid_ops_mask = REGULATOR_CHANGE_STATUS |
  409. REGULATOR_CHANGE_CURRENT,
  410. .always_on = 1,
  411. .boot_on = 1,
  412. .min_uA = 60000,
  413. .max_uA = 2580000,
  414. },
  415. .num_consumer_supplies = ARRAY_SIZE(charger_supply),
  416. .consumer_supplies = charger_supply,
  417. };
  418. struct max77823_regulator_data max77823_regulators[] = {
  419. {MAX77823_ESAFEOUT1, &safeout1_init_data,},
  420. {MAX77823_ESAFEOUT2, &safeout2_init_data,},
  421. {MAX77823_CHARGER, &charger_init_data,},
  422. };
  423. static int __devinit max77823_probe(struct i2c_client *client,
  424. const struct i2c_device_id *id)
  425. {
  426. struct max77823_dev *max77823;
  427. struct max77823_platform_data *pdata = client->dev.platform_data;
  428. u8 reg_data;
  429. int ret;
  430. pr_info("[%s] START\n", __func__);
  431. max77823 = kzalloc(sizeof(struct max77823_dev), GFP_KERNEL);
  432. if (max77823 == NULL)
  433. return -ENOMEM;
  434. if (client->dev.of_node) {
  435. pdata = devm_kzalloc(&client->dev,
  436. sizeof(struct max77823_platform_data),
  437. GFP_KERNEL);
  438. if (!pdata) {
  439. dev_err(&client->dev,
  440. "Failed to allocate memory\n");
  441. ret = -ENOMEM;
  442. }
  443. ret = of_max77823_dt(&client->dev, pdata);
  444. if (ret < 0) {
  445. dev_err(&client->dev, "Failed to get device of_node\n");
  446. return ret;
  447. }
  448. pdata->num_regulators = MAX77823_REG_MAX;
  449. pdata->regulators = max77823_regulators;
  450. client->dev.platform_data = pdata;
  451. } else
  452. pdata = client->dev.platform_data;
  453. max77823->i2c = client;
  454. max77823->dev = &client->dev;
  455. max77823->irq = client->irq;
  456. if (pdata) {
  457. max77823->pdata = pdata;
  458. pdata->irq_base = irq_alloc_descs(-1, 0, MAX77823_IRQ_NR, -1);
  459. if (pdata->irq_base < 0) {
  460. pr_err("%s: irq_alloc_descs Fail ret(%d)\n",
  461. __func__, pdata->irq_base);
  462. ret = -EINVAL;
  463. } else
  464. max77823->irq_base = pdata->irq_base;
  465. printk("%s: irq_base(%d)\n",__func__,pdata->irq_base);
  466. max77823->irq_gpio = pdata->irq_gpio;
  467. max77823->wakeup = pdata->wakeup;
  468. } else {
  469. ret = -EINVAL;
  470. }
  471. mutex_init(&max77823->i2c_lock);
  472. i2c_set_clientdata(client, max77823);
  473. max77823->charger = i2c_new_dummy(client->adapter, I2C_ADDR_CHARGER);
  474. if (max77823->charger)
  475. i2c_set_clientdata(max77823->charger, max77823);
  476. max77823->fuelgauge = i2c_new_dummy(client->adapter, I2C_ADDR_FUELGAUGE);
  477. if (max77823->fuelgauge)
  478. i2c_set_clientdata(max77823->fuelgauge, max77823);
  479. if (max77823_read_reg(max77823->i2c, MAX77823_PMIC_ID, &reg_data) < 0) {
  480. dev_err(max77823->dev,
  481. "device not found on this channel (this is not an error)\n");
  482. ret = -ENODEV;
  483. goto err;
  484. }
  485. if (max77823_read_reg(max77823->i2c, MAX77823_PMIC_SAFEOUT_LDO_Control, &reg_data) < 0) {
  486. dev_err(max77823->dev,
  487. "device not found on this channel (this is not an error)\n");
  488. }
  489. if((max77823_update_reg(max77823->i2c, MAX77823_PMIC_SAFEOUT_LDO_Control, 0x00,0x30) , 0))
  490. printk("Error 1 reading LDO control\n");
  491. if (max77823_read_reg(max77823->i2c, MAX77823_PMIC_SAFEOUT_LDO_Control, &reg_data) < 0) {
  492. dev_err(max77823->dev,
  493. "device not found on this channel (this is not an error)\n");
  494. }
  495. ret = max77823_irq_init(max77823);
  496. if (ret < 0)
  497. goto err_irq_init;
  498. ret = mfd_add_devices(max77823->dev, -1, max77823_devs,
  499. ARRAY_SIZE(max77823_devs), NULL,
  500. max77823->irq_base);
  501. if (ret) {
  502. dev_err(&client->dev, "%s : failed to add devices\n", __func__);
  503. goto err_mfd;
  504. }
  505. device_init_wakeup(max77823->dev, pdata->wakeup);
  506. pr_info("[%s] END\n", __func__);
  507. return ret;
  508. err_mfd:
  509. mfd_remove_devices(max77823->dev);
  510. err_irq_init:
  511. i2c_unregister_device(max77823->charger);
  512. i2c_unregister_device(max77823->fuelgauge);
  513. err:
  514. kfree(max77823);
  515. return ret;
  516. }
  517. static int __devexit max77823_remove(struct i2c_client *client)
  518. {
  519. struct max77823_dev *max77823 = i2c_get_clientdata(client);
  520. mfd_remove_devices(max77823->dev);
  521. i2c_unregister_device(max77823->charger);
  522. i2c_unregister_device(max77823->fuelgauge);
  523. return 0;
  524. }
  525. static const struct i2c_device_id max77823_id[] = {
  526. {"max77823", 0},
  527. {}
  528. };
  529. MODULE_DEVICE_TABLE(i2c, max77823_id);
  530. #if defined(CONFIG_OF)
  531. static struct of_device_id max77823_i2c_dt_ids[] = {
  532. { .compatible = "maxim,max77823" },
  533. { },
  534. };
  535. MODULE_DEVICE_TABLE(of, max77823_i2c_dt_ids);
  536. #endif /* CONFIG_OF */
  537. static struct i2c_driver max77823_driver = {
  538. .driver = {
  539. .name = "max77823",
  540. .owner = THIS_MODULE,
  541. #if defined(CONFIG_OF)
  542. .of_match_table = max77823_i2c_dt_ids,
  543. #endif
  544. },
  545. .probe = max77823_probe,
  546. .remove = __devexit_p(max77823_remove),
  547. .id_table = max77823_id,
  548. };
  549. static int __init max77823_init(void)
  550. {
  551. pr_info("[%s] start \n", __func__);
  552. return i2c_add_driver(&max77823_driver);
  553. }
  554. static void __exit max77823_exit(void)
  555. {
  556. i2c_del_driver(&max77823_driver);
  557. }
  558. module_init(max77823_init);
  559. module_exit(max77823_exit);
  560. MODULE_DESCRIPTION("Samsung MAX77823 Driver");
  561. MODULE_AUTHOR("Samsung Electronics");
  562. MODULE_LICENSE("GPL");