max77620.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * Maxim MAX77620 MFD Driver
  3. *
  4. * Copyright (C) 2016 NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * Author:
  7. * Laxman Dewangan <ldewangan@nvidia.com>
  8. * Chaitanya Bandi <bandik@nvidia.com>
  9. * Mallikarjun Kasoju <mkasoju@nvidia.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. /****************** Teminology used in driver ********************
  16. * Here are some terminology used from datasheet for quick reference:
  17. * Flexible Power Sequence (FPS):
  18. * The Flexible Power Sequencer (FPS) allows each regulator to power up under
  19. * hardware or software control. Additionally, each regulator can power on
  20. * independently or among a group of other regulators with an adjustable
  21. * power-up and power-down delays (sequencing). GPIO1, GPIO2, and GPIO3 can
  22. * be programmed to be part of a sequence allowing external regulators to be
  23. * sequenced along with internal regulators. 32KHz clock can be programmed to
  24. * be part of a sequence.
  25. * There is 3 FPS confguration registers and all resources are configured to
  26. * any of these FPS or no FPS.
  27. */
  28. #include <linux/i2c.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/mfd/core.h>
  31. #include <linux/mfd/max77620.h>
  32. #include <linux/init.h>
  33. #include <linux/of.h>
  34. #include <linux/of_device.h>
  35. #include <linux/regmap.h>
  36. #include <linux/slab.h>
  37. static const struct resource gpio_resources[] = {
  38. DEFINE_RES_IRQ(MAX77620_IRQ_TOP_GPIO),
  39. };
  40. static const struct resource power_resources[] = {
  41. DEFINE_RES_IRQ(MAX77620_IRQ_LBT_MBATLOW),
  42. };
  43. static const struct resource rtc_resources[] = {
  44. DEFINE_RES_IRQ(MAX77620_IRQ_TOP_RTC),
  45. };
  46. static const struct resource thermal_resources[] = {
  47. DEFINE_RES_IRQ(MAX77620_IRQ_LBT_TJALRM1),
  48. DEFINE_RES_IRQ(MAX77620_IRQ_LBT_TJALRM2),
  49. };
  50. static const struct regmap_irq max77620_top_irqs[] = {
  51. REGMAP_IRQ_REG(MAX77620_IRQ_TOP_GLBL, 0, MAX77620_IRQ_TOP_GLBL_MASK),
  52. REGMAP_IRQ_REG(MAX77620_IRQ_TOP_SD, 0, MAX77620_IRQ_TOP_SD_MASK),
  53. REGMAP_IRQ_REG(MAX77620_IRQ_TOP_LDO, 0, MAX77620_IRQ_TOP_LDO_MASK),
  54. REGMAP_IRQ_REG(MAX77620_IRQ_TOP_GPIO, 0, MAX77620_IRQ_TOP_GPIO_MASK),
  55. REGMAP_IRQ_REG(MAX77620_IRQ_TOP_RTC, 0, MAX77620_IRQ_TOP_RTC_MASK),
  56. REGMAP_IRQ_REG(MAX77620_IRQ_TOP_32K, 0, MAX77620_IRQ_TOP_32K_MASK),
  57. REGMAP_IRQ_REG(MAX77620_IRQ_TOP_ONOFF, 0, MAX77620_IRQ_TOP_ONOFF_MASK),
  58. REGMAP_IRQ_REG(MAX77620_IRQ_LBT_MBATLOW, 1, MAX77620_IRQ_LBM_MASK),
  59. REGMAP_IRQ_REG(MAX77620_IRQ_LBT_TJALRM1, 1, MAX77620_IRQ_TJALRM1_MASK),
  60. REGMAP_IRQ_REG(MAX77620_IRQ_LBT_TJALRM2, 1, MAX77620_IRQ_TJALRM2_MASK),
  61. };
  62. static const struct mfd_cell max77620_children[] = {
  63. { .name = "max77620-pinctrl", },
  64. { .name = "max77620-clock", },
  65. { .name = "max77620-pmic", },
  66. { .name = "max77620-watchdog", },
  67. {
  68. .name = "max77620-gpio",
  69. .resources = gpio_resources,
  70. .num_resources = ARRAY_SIZE(gpio_resources),
  71. }, {
  72. .name = "max77620-rtc",
  73. .resources = rtc_resources,
  74. .num_resources = ARRAY_SIZE(rtc_resources),
  75. }, {
  76. .name = "max77620-power",
  77. .resources = power_resources,
  78. .num_resources = ARRAY_SIZE(power_resources),
  79. }, {
  80. .name = "max77620-thermal",
  81. .resources = thermal_resources,
  82. .num_resources = ARRAY_SIZE(thermal_resources),
  83. },
  84. };
  85. static const struct mfd_cell max20024_children[] = {
  86. { .name = "max20024-pinctrl", },
  87. { .name = "max77620-clock", },
  88. { .name = "max20024-pmic", },
  89. { .name = "max77620-watchdog", },
  90. {
  91. .name = "max77620-gpio",
  92. .resources = gpio_resources,
  93. .num_resources = ARRAY_SIZE(gpio_resources),
  94. }, {
  95. .name = "max77620-rtc",
  96. .resources = rtc_resources,
  97. .num_resources = ARRAY_SIZE(rtc_resources),
  98. }, {
  99. .name = "max20024-power",
  100. .resources = power_resources,
  101. .num_resources = ARRAY_SIZE(power_resources),
  102. },
  103. };
  104. static const struct regmap_range max77620_readable_ranges[] = {
  105. regmap_reg_range(MAX77620_REG_CNFGGLBL1, MAX77620_REG_DVSSD4),
  106. };
  107. static const struct regmap_access_table max77620_readable_table = {
  108. .yes_ranges = max77620_readable_ranges,
  109. .n_yes_ranges = ARRAY_SIZE(max77620_readable_ranges),
  110. };
  111. static const struct regmap_range max20024_readable_ranges[] = {
  112. regmap_reg_range(MAX77620_REG_CNFGGLBL1, MAX77620_REG_DVSSD4),
  113. regmap_reg_range(MAX20024_REG_MAX_ADD, MAX20024_REG_MAX_ADD),
  114. };
  115. static const struct regmap_access_table max20024_readable_table = {
  116. .yes_ranges = max20024_readable_ranges,
  117. .n_yes_ranges = ARRAY_SIZE(max20024_readable_ranges),
  118. };
  119. static const struct regmap_range max77620_writable_ranges[] = {
  120. regmap_reg_range(MAX77620_REG_CNFGGLBL1, MAX77620_REG_DVSSD4),
  121. };
  122. static const struct regmap_access_table max77620_writable_table = {
  123. .yes_ranges = max77620_writable_ranges,
  124. .n_yes_ranges = ARRAY_SIZE(max77620_writable_ranges),
  125. };
  126. static const struct regmap_range max77620_cacheable_ranges[] = {
  127. regmap_reg_range(MAX77620_REG_SD0_CFG, MAX77620_REG_LDO_CFG3),
  128. regmap_reg_range(MAX77620_REG_FPS_CFG0, MAX77620_REG_FPS_SD3),
  129. };
  130. static const struct regmap_access_table max77620_volatile_table = {
  131. .no_ranges = max77620_cacheable_ranges,
  132. .n_no_ranges = ARRAY_SIZE(max77620_cacheable_ranges),
  133. };
  134. static const struct regmap_config max77620_regmap_config = {
  135. .name = "power-slave",
  136. .reg_bits = 8,
  137. .val_bits = 8,
  138. .max_register = MAX77620_REG_DVSSD4 + 1,
  139. .cache_type = REGCACHE_RBTREE,
  140. .rd_table = &max77620_readable_table,
  141. .wr_table = &max77620_writable_table,
  142. .volatile_table = &max77620_volatile_table,
  143. };
  144. static const struct regmap_config max20024_regmap_config = {
  145. .name = "power-slave",
  146. .reg_bits = 8,
  147. .val_bits = 8,
  148. .max_register = MAX20024_REG_MAX_ADD + 1,
  149. .cache_type = REGCACHE_RBTREE,
  150. .rd_table = &max20024_readable_table,
  151. .wr_table = &max77620_writable_table,
  152. .volatile_table = &max77620_volatile_table,
  153. };
  154. /*
  155. * MAX77620 and MAX20024 has the following steps of the interrupt handling
  156. * for TOP interrupts:
  157. * 1. When interrupt occurs from PMIC, mask the PMIC interrupt by setting GLBLM.
  158. * 2. Read IRQTOP and service the interrupt.
  159. * 3. Once all interrupts has been checked and serviced, the interrupt service
  160. * routine un-masks the hardware interrupt line by clearing GLBLM.
  161. */
  162. static int max77620_irq_global_mask(void *irq_drv_data)
  163. {
  164. struct max77620_chip *chip = irq_drv_data;
  165. int ret;
  166. ret = regmap_update_bits(chip->rmap, MAX77620_REG_INTENLBT,
  167. MAX77620_GLBLM_MASK, MAX77620_GLBLM_MASK);
  168. if (ret < 0)
  169. dev_err(chip->dev, "Failed to set GLBLM: %d\n", ret);
  170. return ret;
  171. }
  172. static int max77620_irq_global_unmask(void *irq_drv_data)
  173. {
  174. struct max77620_chip *chip = irq_drv_data;
  175. int ret;
  176. ret = regmap_update_bits(chip->rmap, MAX77620_REG_INTENLBT,
  177. MAX77620_GLBLM_MASK, 0);
  178. if (ret < 0)
  179. dev_err(chip->dev, "Failed to reset GLBLM: %d\n", ret);
  180. return ret;
  181. }
  182. static struct regmap_irq_chip max77620_top_irq_chip = {
  183. .name = "max77620-top",
  184. .irqs = max77620_top_irqs,
  185. .num_irqs = ARRAY_SIZE(max77620_top_irqs),
  186. .num_regs = 2,
  187. .status_base = MAX77620_REG_IRQTOP,
  188. .mask_base = MAX77620_REG_IRQTOPM,
  189. .handle_pre_irq = max77620_irq_global_mask,
  190. .handle_post_irq = max77620_irq_global_unmask,
  191. };
  192. /* max77620_get_fps_period_reg_value: Get FPS bit field value from
  193. * requested periods.
  194. * MAX77620 supports the FPS period of 40, 80, 160, 320, 540, 1280, 2560
  195. * and 5120 microseconds. MAX20024 supports the FPS period of 20, 40, 80,
  196. * 160, 320, 540, 1280 and 2560 microseconds.
  197. * The FPS register has 3 bits field to set the FPS period as
  198. * bits max77620 max20024
  199. * 000 40 20
  200. * 001 80 40
  201. * :::
  202. */
  203. static int max77620_get_fps_period_reg_value(struct max77620_chip *chip,
  204. int tperiod)
  205. {
  206. int fps_min_period;
  207. int i;
  208. switch (chip->chip_id) {
  209. case MAX20024:
  210. fps_min_period = MAX20024_FPS_PERIOD_MIN_US;
  211. break;
  212. case MAX77620:
  213. fps_min_period = MAX77620_FPS_PERIOD_MIN_US;
  214. break;
  215. default:
  216. return -EINVAL;
  217. }
  218. for (i = 0; i < 7; i++) {
  219. if (fps_min_period >= tperiod)
  220. return i;
  221. fps_min_period *= 2;
  222. }
  223. return i;
  224. }
  225. /* max77620_config_fps: Configure FPS configuration registers
  226. * based on platform specific information.
  227. */
  228. static int max77620_config_fps(struct max77620_chip *chip,
  229. struct device_node *fps_np)
  230. {
  231. struct device *dev = chip->dev;
  232. unsigned int mask = 0, config = 0;
  233. u32 fps_max_period;
  234. u32 param_val;
  235. int tperiod, fps_id;
  236. int ret;
  237. char fps_name[10];
  238. switch (chip->chip_id) {
  239. case MAX20024:
  240. fps_max_period = MAX20024_FPS_PERIOD_MAX_US;
  241. break;
  242. case MAX77620:
  243. fps_max_period = MAX77620_FPS_PERIOD_MAX_US;
  244. break;
  245. default:
  246. return -EINVAL;
  247. }
  248. for (fps_id = 0; fps_id < MAX77620_FPS_COUNT; fps_id++) {
  249. sprintf(fps_name, "fps%d", fps_id);
  250. if (!strcmp(fps_np->name, fps_name))
  251. break;
  252. }
  253. if (fps_id == MAX77620_FPS_COUNT) {
  254. dev_err(dev, "FPS node name %s is not valid\n", fps_np->name);
  255. return -EINVAL;
  256. }
  257. ret = of_property_read_u32(fps_np, "maxim,shutdown-fps-time-period-us",
  258. &param_val);
  259. if (!ret) {
  260. mask |= MAX77620_FPS_TIME_PERIOD_MASK;
  261. chip->shutdown_fps_period[fps_id] = min(param_val,
  262. fps_max_period);
  263. tperiod = max77620_get_fps_period_reg_value(chip,
  264. chip->shutdown_fps_period[fps_id]);
  265. config |= tperiod << MAX77620_FPS_TIME_PERIOD_SHIFT;
  266. }
  267. ret = of_property_read_u32(fps_np, "maxim,suspend-fps-time-period-us",
  268. &param_val);
  269. if (!ret)
  270. chip->suspend_fps_period[fps_id] = min(param_val,
  271. fps_max_period);
  272. ret = of_property_read_u32(fps_np, "maxim,fps-event-source",
  273. &param_val);
  274. if (!ret) {
  275. if (param_val > 2) {
  276. dev_err(dev, "FPS%d event-source invalid\n", fps_id);
  277. return -EINVAL;
  278. }
  279. mask |= MAX77620_FPS_EN_SRC_MASK;
  280. config |= param_val << MAX77620_FPS_EN_SRC_SHIFT;
  281. if (param_val == 2) {
  282. mask |= MAX77620_FPS_ENFPS_SW_MASK;
  283. config |= MAX77620_FPS_ENFPS_SW;
  284. }
  285. }
  286. if (!chip->sleep_enable && !chip->enable_global_lpm) {
  287. ret = of_property_read_u32(fps_np,
  288. "maxim,device-state-on-disabled-event",
  289. &param_val);
  290. if (!ret) {
  291. if (param_val == 0)
  292. chip->sleep_enable = true;
  293. else if (param_val == 1)
  294. chip->enable_global_lpm = true;
  295. }
  296. }
  297. ret = regmap_update_bits(chip->rmap, MAX77620_REG_FPS_CFG0 + fps_id,
  298. mask, config);
  299. if (ret < 0) {
  300. dev_err(dev, "Failed to update FPS CFG: %d\n", ret);
  301. return ret;
  302. }
  303. return 0;
  304. }
  305. static int max77620_initialise_fps(struct max77620_chip *chip)
  306. {
  307. struct device *dev = chip->dev;
  308. struct device_node *fps_np, *fps_child;
  309. u8 config;
  310. int fps_id;
  311. int ret;
  312. for (fps_id = 0; fps_id < MAX77620_FPS_COUNT; fps_id++) {
  313. chip->shutdown_fps_period[fps_id] = -1;
  314. chip->suspend_fps_period[fps_id] = -1;
  315. }
  316. fps_np = of_get_child_by_name(dev->of_node, "fps");
  317. if (!fps_np)
  318. goto skip_fps;
  319. for_each_child_of_node(fps_np, fps_child) {
  320. ret = max77620_config_fps(chip, fps_child);
  321. if (ret < 0)
  322. return ret;
  323. }
  324. config = chip->enable_global_lpm ? MAX77620_ONOFFCNFG2_SLP_LPM_MSK : 0;
  325. ret = regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG2,
  326. MAX77620_ONOFFCNFG2_SLP_LPM_MSK, config);
  327. if (ret < 0) {
  328. dev_err(dev, "Failed to update SLP_LPM: %d\n", ret);
  329. return ret;
  330. }
  331. skip_fps:
  332. /* Enable wake on EN0 pin */
  333. ret = regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG2,
  334. MAX77620_ONOFFCNFG2_WK_EN0,
  335. MAX77620_ONOFFCNFG2_WK_EN0);
  336. if (ret < 0) {
  337. dev_err(dev, "Failed to update WK_EN0: %d\n", ret);
  338. return ret;
  339. }
  340. /* For MAX20024, SLPEN will be POR reset if CLRSE is b11 */
  341. if ((chip->chip_id == MAX20024) && chip->sleep_enable) {
  342. config = MAX77620_ONOFFCNFG1_SLPEN | MAX20024_ONOFFCNFG1_CLRSE;
  343. ret = regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG1,
  344. config, config);
  345. if (ret < 0) {
  346. dev_err(dev, "Failed to update SLPEN: %d\n", ret);
  347. return ret;
  348. }
  349. }
  350. return 0;
  351. }
  352. static int max77620_read_es_version(struct max77620_chip *chip)
  353. {
  354. unsigned int val;
  355. u8 cid_val[6];
  356. int i;
  357. int ret;
  358. for (i = MAX77620_REG_CID0; i <= MAX77620_REG_CID5; i++) {
  359. ret = regmap_read(chip->rmap, i, &val);
  360. if (ret < 0) {
  361. dev_err(chip->dev, "Failed to read CID: %d\n", ret);
  362. return ret;
  363. }
  364. dev_dbg(chip->dev, "CID%d: 0x%02x\n",
  365. i - MAX77620_REG_CID0, val);
  366. cid_val[i - MAX77620_REG_CID0] = val;
  367. }
  368. /* CID4 is OTP Version and CID5 is ES version */
  369. dev_info(chip->dev, "PMIC Version OTP:0x%02X and ES:0x%X\n",
  370. cid_val[4], MAX77620_CID5_DIDM(cid_val[5]));
  371. return ret;
  372. }
  373. static int max77620_probe(struct i2c_client *client,
  374. const struct i2c_device_id *id)
  375. {
  376. const struct regmap_config *rmap_config;
  377. struct max77620_chip *chip;
  378. const struct mfd_cell *mfd_cells;
  379. int n_mfd_cells;
  380. int ret;
  381. chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
  382. if (!chip)
  383. return -ENOMEM;
  384. i2c_set_clientdata(client, chip);
  385. chip->dev = &client->dev;
  386. chip->irq_base = -1;
  387. chip->chip_irq = client->irq;
  388. chip->chip_id = (enum max77620_chip_id)id->driver_data;
  389. switch (chip->chip_id) {
  390. case MAX77620:
  391. mfd_cells = max77620_children;
  392. n_mfd_cells = ARRAY_SIZE(max77620_children);
  393. rmap_config = &max77620_regmap_config;
  394. break;
  395. case MAX20024:
  396. mfd_cells = max20024_children;
  397. n_mfd_cells = ARRAY_SIZE(max20024_children);
  398. rmap_config = &max20024_regmap_config;
  399. break;
  400. default:
  401. dev_err(chip->dev, "ChipID is invalid %d\n", chip->chip_id);
  402. return -EINVAL;
  403. }
  404. chip->rmap = devm_regmap_init_i2c(client, rmap_config);
  405. if (IS_ERR(chip->rmap)) {
  406. ret = PTR_ERR(chip->rmap);
  407. dev_err(chip->dev, "Failed to initialise regmap: %d\n", ret);
  408. return ret;
  409. }
  410. ret = max77620_read_es_version(chip);
  411. if (ret < 0)
  412. return ret;
  413. max77620_top_irq_chip.irq_drv_data = chip;
  414. ret = devm_regmap_add_irq_chip(chip->dev, chip->rmap, client->irq,
  415. IRQF_ONESHOT | IRQF_SHARED,
  416. chip->irq_base, &max77620_top_irq_chip,
  417. &chip->top_irq_data);
  418. if (ret < 0) {
  419. dev_err(chip->dev, "Failed to add regmap irq: %d\n", ret);
  420. return ret;
  421. }
  422. ret = max77620_initialise_fps(chip);
  423. if (ret < 0)
  424. return ret;
  425. ret = devm_mfd_add_devices(chip->dev, PLATFORM_DEVID_NONE,
  426. mfd_cells, n_mfd_cells, NULL, 0,
  427. regmap_irq_get_domain(chip->top_irq_data));
  428. if (ret < 0) {
  429. dev_err(chip->dev, "Failed to add MFD children: %d\n", ret);
  430. return ret;
  431. }
  432. return 0;
  433. }
  434. #ifdef CONFIG_PM_SLEEP
  435. static int max77620_set_fps_period(struct max77620_chip *chip,
  436. int fps_id, int time_period)
  437. {
  438. int period = max77620_get_fps_period_reg_value(chip, time_period);
  439. int ret;
  440. ret = regmap_update_bits(chip->rmap, MAX77620_REG_FPS_CFG0 + fps_id,
  441. MAX77620_FPS_TIME_PERIOD_MASK,
  442. period << MAX77620_FPS_TIME_PERIOD_SHIFT);
  443. if (ret < 0) {
  444. dev_err(chip->dev, "Failed to update FPS period: %d\n", ret);
  445. return ret;
  446. }
  447. return 0;
  448. }
  449. static int max77620_i2c_suspend(struct device *dev)
  450. {
  451. struct max77620_chip *chip = dev_get_drvdata(dev);
  452. struct i2c_client *client = to_i2c_client(dev);
  453. unsigned int config;
  454. int fps;
  455. int ret;
  456. for (fps = 0; fps < MAX77620_FPS_COUNT; fps++) {
  457. if (chip->suspend_fps_period[fps] < 0)
  458. continue;
  459. ret = max77620_set_fps_period(chip, fps,
  460. chip->suspend_fps_period[fps]);
  461. if (ret < 0)
  462. return ret;
  463. }
  464. /*
  465. * For MAX20024: No need to configure SLPEN on suspend as
  466. * it will be configured on Init.
  467. */
  468. if (chip->chip_id == MAX20024)
  469. goto out;
  470. config = (chip->sleep_enable) ? MAX77620_ONOFFCNFG1_SLPEN : 0;
  471. ret = regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG1,
  472. MAX77620_ONOFFCNFG1_SLPEN,
  473. config);
  474. if (ret < 0) {
  475. dev_err(dev, "Failed to configure sleep in suspend: %d\n", ret);
  476. return ret;
  477. }
  478. /* Disable WK_EN0 */
  479. ret = regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG2,
  480. MAX77620_ONOFFCNFG2_WK_EN0, 0);
  481. if (ret < 0) {
  482. dev_err(dev, "Failed to configure WK_EN in suspend: %d\n", ret);
  483. return ret;
  484. }
  485. out:
  486. disable_irq(client->irq);
  487. return 0;
  488. }
  489. static int max77620_i2c_resume(struct device *dev)
  490. {
  491. struct max77620_chip *chip = dev_get_drvdata(dev);
  492. struct i2c_client *client = to_i2c_client(dev);
  493. int ret;
  494. int fps;
  495. for (fps = 0; fps < MAX77620_FPS_COUNT; fps++) {
  496. if (chip->shutdown_fps_period[fps] < 0)
  497. continue;
  498. ret = max77620_set_fps_period(chip, fps,
  499. chip->shutdown_fps_period[fps]);
  500. if (ret < 0)
  501. return ret;
  502. }
  503. /*
  504. * For MAX20024: No need to configure WKEN0 on resume as
  505. * it is configured on Init.
  506. */
  507. if (chip->chip_id == MAX20024)
  508. goto out;
  509. /* Enable WK_EN0 */
  510. ret = regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG2,
  511. MAX77620_ONOFFCNFG2_WK_EN0,
  512. MAX77620_ONOFFCNFG2_WK_EN0);
  513. if (ret < 0) {
  514. dev_err(dev, "Failed to configure WK_EN0 n resume: %d\n", ret);
  515. return ret;
  516. }
  517. out:
  518. enable_irq(client->irq);
  519. return 0;
  520. }
  521. #endif
  522. static const struct i2c_device_id max77620_id[] = {
  523. {"max77620", MAX77620},
  524. {"max20024", MAX20024},
  525. {},
  526. };
  527. static const struct dev_pm_ops max77620_pm_ops = {
  528. SET_SYSTEM_SLEEP_PM_OPS(max77620_i2c_suspend, max77620_i2c_resume)
  529. };
  530. static struct i2c_driver max77620_driver = {
  531. .driver = {
  532. .name = "max77620",
  533. .pm = &max77620_pm_ops,
  534. },
  535. .probe = max77620_probe,
  536. .id_table = max77620_id,
  537. };
  538. builtin_i2c_driver(max77620_driver);