pinctrl-max77620.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * MAX77620 pin control driver.
  3. *
  4. * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * Author:
  7. * Chaitanya Bandi <bandik@nvidia.com>
  8. * Laxman Dewangan <ldewangan@nvidia.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms and conditions of the GNU General Public License,
  12. * version 2, as published by the Free Software Foundation.
  13. */
  14. #include <linux/mfd/max77620.h>
  15. #include <linux/module.h>
  16. #include <linux/of.h>
  17. #include <linux/pinctrl/pinctrl.h>
  18. #include <linux/pinctrl/pinconf-generic.h>
  19. #include <linux/pinctrl/pinconf.h>
  20. #include <linux/pinctrl/pinmux.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regmap.h>
  23. #include "core.h"
  24. #include "pinconf.h"
  25. #include "pinctrl-utils.h"
  26. #define MAX77620_PIN_NUM 8
  27. enum max77620_pin_ppdrv {
  28. MAX77620_PIN_UNCONFIG_DRV,
  29. MAX77620_PIN_OD_DRV,
  30. MAX77620_PIN_PP_DRV,
  31. };
  32. enum max77620_pinconf_param {
  33. MAX77620_ACTIVE_FPS_SOURCE = PIN_CONFIG_END + 1,
  34. MAX77620_ACTIVE_FPS_POWER_ON_SLOTS,
  35. MAX77620_ACTIVE_FPS_POWER_DOWN_SLOTS,
  36. MAX77620_SUSPEND_FPS_SOURCE,
  37. MAX77620_SUSPEND_FPS_POWER_ON_SLOTS,
  38. MAX77620_SUSPEND_FPS_POWER_DOWN_SLOTS,
  39. };
  40. struct max77620_pin_function {
  41. const char *name;
  42. const char * const *groups;
  43. unsigned int ngroups;
  44. int mux_option;
  45. };
  46. static const struct pinconf_generic_params max77620_cfg_params[] = {
  47. {
  48. .property = "maxim,active-fps-source",
  49. .param = MAX77620_ACTIVE_FPS_SOURCE,
  50. }, {
  51. .property = "maxim,active-fps-power-up-slot",
  52. .param = MAX77620_ACTIVE_FPS_POWER_ON_SLOTS,
  53. }, {
  54. .property = "maxim,active-fps-power-down-slot",
  55. .param = MAX77620_ACTIVE_FPS_POWER_DOWN_SLOTS,
  56. }, {
  57. .property = "maxim,suspend-fps-source",
  58. .param = MAX77620_SUSPEND_FPS_SOURCE,
  59. }, {
  60. .property = "maxim,suspend-fps-power-up-slot",
  61. .param = MAX77620_SUSPEND_FPS_POWER_ON_SLOTS,
  62. }, {
  63. .property = "maxim,suspend-fps-power-down-slot",
  64. .param = MAX77620_SUSPEND_FPS_POWER_DOWN_SLOTS,
  65. },
  66. };
  67. enum max77620_alternate_pinmux_option {
  68. MAX77620_PINMUX_GPIO = 0,
  69. MAX77620_PINMUX_LOW_POWER_MODE_CONTROL_IN = 1,
  70. MAX77620_PINMUX_FLEXIBLE_POWER_SEQUENCER_OUT = 2,
  71. MAX77620_PINMUX_32K_OUT1 = 3,
  72. MAX77620_PINMUX_SD0_DYNAMIC_VOLTAGE_SCALING_IN = 4,
  73. MAX77620_PINMUX_SD1_DYNAMIC_VOLTAGE_SCALING_IN = 5,
  74. MAX77620_PINMUX_REFERENCE_OUT = 6,
  75. };
  76. struct max77620_pingroup {
  77. const char *name;
  78. const unsigned int pins[1];
  79. unsigned int npins;
  80. enum max77620_alternate_pinmux_option alt_option;
  81. };
  82. struct max77620_pin_info {
  83. enum max77620_pin_ppdrv drv_type;
  84. int pull_config;
  85. };
  86. struct max77620_fps_config {
  87. int active_fps_src;
  88. int active_power_up_slots;
  89. int active_power_down_slots;
  90. int suspend_fps_src;
  91. int suspend_power_up_slots;
  92. int suspend_power_down_slots;
  93. };
  94. struct max77620_pctrl_info {
  95. struct device *dev;
  96. struct pinctrl_dev *pctl;
  97. struct regmap *rmap;
  98. int pins_current_opt[MAX77620_GPIO_NR];
  99. const struct max77620_pin_function *functions;
  100. unsigned int num_functions;
  101. const struct max77620_pingroup *pin_groups;
  102. int num_pin_groups;
  103. const struct pinctrl_pin_desc *pins;
  104. unsigned int num_pins;
  105. struct max77620_pin_info pin_info[MAX77620_PIN_NUM];
  106. struct max77620_fps_config fps_config[MAX77620_PIN_NUM];
  107. };
  108. static const struct pinctrl_pin_desc max77620_pins_desc[] = {
  109. PINCTRL_PIN(MAX77620_GPIO0, "gpio0"),
  110. PINCTRL_PIN(MAX77620_GPIO1, "gpio1"),
  111. PINCTRL_PIN(MAX77620_GPIO2, "gpio2"),
  112. PINCTRL_PIN(MAX77620_GPIO3, "gpio3"),
  113. PINCTRL_PIN(MAX77620_GPIO4, "gpio4"),
  114. PINCTRL_PIN(MAX77620_GPIO5, "gpio5"),
  115. PINCTRL_PIN(MAX77620_GPIO6, "gpio6"),
  116. PINCTRL_PIN(MAX77620_GPIO7, "gpio7"),
  117. };
  118. static const char * const gpio_groups[] = {
  119. "gpio0",
  120. "gpio1",
  121. "gpio2",
  122. "gpio3",
  123. "gpio4",
  124. "gpio5",
  125. "gpio6",
  126. "gpio7",
  127. };
  128. #define FUNCTION_GROUP(fname, mux) \
  129. { \
  130. .name = fname, \
  131. .groups = gpio_groups, \
  132. .ngroups = ARRAY_SIZE(gpio_groups), \
  133. .mux_option = MAX77620_PINMUX_##mux, \
  134. }
  135. static const struct max77620_pin_function max77620_pin_function[] = {
  136. FUNCTION_GROUP("gpio", GPIO),
  137. FUNCTION_GROUP("lpm-control-in", LOW_POWER_MODE_CONTROL_IN),
  138. FUNCTION_GROUP("fps-out", FLEXIBLE_POWER_SEQUENCER_OUT),
  139. FUNCTION_GROUP("32k-out1", 32K_OUT1),
  140. FUNCTION_GROUP("sd0-dvs-in", SD0_DYNAMIC_VOLTAGE_SCALING_IN),
  141. FUNCTION_GROUP("sd1-dvs-in", SD1_DYNAMIC_VOLTAGE_SCALING_IN),
  142. FUNCTION_GROUP("reference-out", REFERENCE_OUT),
  143. };
  144. #define MAX77620_PINGROUP(pg_name, pin_id, option) \
  145. { \
  146. .name = #pg_name, \
  147. .pins = {MAX77620_##pin_id}, \
  148. .npins = 1, \
  149. .alt_option = MAX77620_PINMUX_##option, \
  150. }
  151. static const struct max77620_pingroup max77620_pingroups[] = {
  152. MAX77620_PINGROUP(gpio0, GPIO0, LOW_POWER_MODE_CONTROL_IN),
  153. MAX77620_PINGROUP(gpio1, GPIO1, FLEXIBLE_POWER_SEQUENCER_OUT),
  154. MAX77620_PINGROUP(gpio2, GPIO2, FLEXIBLE_POWER_SEQUENCER_OUT),
  155. MAX77620_PINGROUP(gpio3, GPIO3, FLEXIBLE_POWER_SEQUENCER_OUT),
  156. MAX77620_PINGROUP(gpio4, GPIO4, 32K_OUT1),
  157. MAX77620_PINGROUP(gpio5, GPIO5, SD0_DYNAMIC_VOLTAGE_SCALING_IN),
  158. MAX77620_PINGROUP(gpio6, GPIO6, SD1_DYNAMIC_VOLTAGE_SCALING_IN),
  159. MAX77620_PINGROUP(gpio7, GPIO7, REFERENCE_OUT),
  160. };
  161. static int max77620_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
  162. {
  163. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  164. return mpci->num_pin_groups;
  165. }
  166. static const char *max77620_pinctrl_get_group_name(
  167. struct pinctrl_dev *pctldev, unsigned int group)
  168. {
  169. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  170. return mpci->pin_groups[group].name;
  171. }
  172. static int max77620_pinctrl_get_group_pins(
  173. struct pinctrl_dev *pctldev, unsigned int group,
  174. const unsigned int **pins, unsigned int *num_pins)
  175. {
  176. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  177. *pins = mpci->pin_groups[group].pins;
  178. *num_pins = mpci->pin_groups[group].npins;
  179. return 0;
  180. }
  181. static const struct pinctrl_ops max77620_pinctrl_ops = {
  182. .get_groups_count = max77620_pinctrl_get_groups_count,
  183. .get_group_name = max77620_pinctrl_get_group_name,
  184. .get_group_pins = max77620_pinctrl_get_group_pins,
  185. .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
  186. .dt_free_map = pinctrl_utils_free_map,
  187. };
  188. static int max77620_pinctrl_get_funcs_count(struct pinctrl_dev *pctldev)
  189. {
  190. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  191. return mpci->num_functions;
  192. }
  193. static const char *max77620_pinctrl_get_func_name(struct pinctrl_dev *pctldev,
  194. unsigned int function)
  195. {
  196. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  197. return mpci->functions[function].name;
  198. }
  199. static int max77620_pinctrl_get_func_groups(struct pinctrl_dev *pctldev,
  200. unsigned int function,
  201. const char * const **groups,
  202. unsigned int * const num_groups)
  203. {
  204. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  205. *groups = mpci->functions[function].groups;
  206. *num_groups = mpci->functions[function].ngroups;
  207. return 0;
  208. }
  209. static int max77620_pinctrl_enable(struct pinctrl_dev *pctldev,
  210. unsigned int function, unsigned int group)
  211. {
  212. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  213. u8 val;
  214. int ret;
  215. if (function == MAX77620_PINMUX_GPIO) {
  216. val = 0;
  217. } else if (function == mpci->pin_groups[group].alt_option) {
  218. val = 1 << group;
  219. } else {
  220. dev_err(mpci->dev, "GPIO %u doesn't have function %u\n",
  221. group, function);
  222. return -EINVAL;
  223. }
  224. ret = regmap_update_bits(mpci->rmap, MAX77620_REG_AME_GPIO,
  225. BIT(group), val);
  226. if (ret < 0)
  227. dev_err(mpci->dev, "REG AME GPIO update failed: %d\n", ret);
  228. return ret;
  229. }
  230. static const struct pinmux_ops max77620_pinmux_ops = {
  231. .get_functions_count = max77620_pinctrl_get_funcs_count,
  232. .get_function_name = max77620_pinctrl_get_func_name,
  233. .get_function_groups = max77620_pinctrl_get_func_groups,
  234. .set_mux = max77620_pinctrl_enable,
  235. };
  236. static int max77620_pinconf_get(struct pinctrl_dev *pctldev,
  237. unsigned int pin, unsigned long *config)
  238. {
  239. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  240. struct device *dev = mpci->dev;
  241. enum pin_config_param param = pinconf_to_config_param(*config);
  242. unsigned int val;
  243. int arg = 0;
  244. int ret;
  245. switch (param) {
  246. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  247. if (mpci->pin_info[pin].drv_type == MAX77620_PIN_OD_DRV)
  248. arg = 1;
  249. break;
  250. case PIN_CONFIG_DRIVE_PUSH_PULL:
  251. if (mpci->pin_info[pin].drv_type == MAX77620_PIN_PP_DRV)
  252. arg = 1;
  253. break;
  254. case PIN_CONFIG_BIAS_PULL_UP:
  255. ret = regmap_read(mpci->rmap, MAX77620_REG_PUE_GPIO, &val);
  256. if (ret < 0) {
  257. dev_err(dev, "Reg PUE_GPIO read failed: %d\n", ret);
  258. return ret;
  259. }
  260. if (val & BIT(pin))
  261. arg = 1;
  262. break;
  263. case PIN_CONFIG_BIAS_PULL_DOWN:
  264. ret = regmap_read(mpci->rmap, MAX77620_REG_PDE_GPIO, &val);
  265. if (ret < 0) {
  266. dev_err(dev, "Reg PDE_GPIO read failed: %d\n", ret);
  267. return ret;
  268. }
  269. if (val & BIT(pin))
  270. arg = 1;
  271. break;
  272. default:
  273. dev_err(dev, "Properties not supported\n");
  274. return -ENOTSUPP;
  275. }
  276. *config = pinconf_to_config_packed(param, (u16)arg);
  277. return 0;
  278. }
  279. static int max77620_get_default_fps(struct max77620_pctrl_info *mpci,
  280. int addr, int *fps)
  281. {
  282. unsigned int val;
  283. int ret;
  284. ret = regmap_read(mpci->rmap, addr, &val);
  285. if (ret < 0) {
  286. dev_err(mpci->dev, "Reg PUE_GPIO read failed: %d\n", ret);
  287. return ret;
  288. }
  289. *fps = (val & MAX77620_FPS_SRC_MASK) >> MAX77620_FPS_SRC_SHIFT;
  290. return 0;
  291. }
  292. static int max77620_set_fps_param(struct max77620_pctrl_info *mpci,
  293. int pin, int param)
  294. {
  295. struct max77620_fps_config *fps_config = &mpci->fps_config[pin];
  296. int addr, ret;
  297. int param_val;
  298. int mask, shift;
  299. if ((pin < MAX77620_GPIO1) || (pin > MAX77620_GPIO3))
  300. return 0;
  301. addr = MAX77620_REG_FPS_GPIO1 + pin - 1;
  302. switch (param) {
  303. case MAX77620_ACTIVE_FPS_SOURCE:
  304. case MAX77620_SUSPEND_FPS_SOURCE:
  305. mask = MAX77620_FPS_SRC_MASK;
  306. shift = MAX77620_FPS_SRC_SHIFT;
  307. param_val = fps_config->active_fps_src;
  308. if (param == MAX77620_SUSPEND_FPS_SOURCE)
  309. param_val = fps_config->suspend_fps_src;
  310. break;
  311. case MAX77620_ACTIVE_FPS_POWER_ON_SLOTS:
  312. case MAX77620_SUSPEND_FPS_POWER_ON_SLOTS:
  313. mask = MAX77620_FPS_PU_PERIOD_MASK;
  314. shift = MAX77620_FPS_PU_PERIOD_SHIFT;
  315. param_val = fps_config->active_power_up_slots;
  316. if (param == MAX77620_SUSPEND_FPS_POWER_ON_SLOTS)
  317. param_val = fps_config->suspend_power_up_slots;
  318. break;
  319. case MAX77620_ACTIVE_FPS_POWER_DOWN_SLOTS:
  320. case MAX77620_SUSPEND_FPS_POWER_DOWN_SLOTS:
  321. mask = MAX77620_FPS_PD_PERIOD_MASK;
  322. shift = MAX77620_FPS_PD_PERIOD_SHIFT;
  323. param_val = fps_config->active_power_down_slots;
  324. if (param == MAX77620_SUSPEND_FPS_POWER_DOWN_SLOTS)
  325. param_val = fps_config->suspend_power_down_slots;
  326. break;
  327. default:
  328. dev_err(mpci->dev, "Invalid parameter %d for pin %d\n",
  329. param, pin);
  330. return -EINVAL;
  331. }
  332. if (param_val < 0)
  333. return 0;
  334. ret = regmap_update_bits(mpci->rmap, addr, mask, param_val << shift);
  335. if (ret < 0)
  336. dev_err(mpci->dev, "Reg 0x%02x update failed %d\n", addr, ret);
  337. return ret;
  338. }
  339. static int max77620_pinconf_set(struct pinctrl_dev *pctldev,
  340. unsigned int pin, unsigned long *configs,
  341. unsigned int num_configs)
  342. {
  343. struct max77620_pctrl_info *mpci = pinctrl_dev_get_drvdata(pctldev);
  344. struct device *dev = mpci->dev;
  345. struct max77620_fps_config *fps_config;
  346. int param;
  347. u16 param_val;
  348. unsigned int val;
  349. unsigned int pu_val;
  350. unsigned int pd_val;
  351. int addr, ret;
  352. int i;
  353. for (i = 0; i < num_configs; i++) {
  354. param = pinconf_to_config_param(configs[i]);
  355. param_val = pinconf_to_config_argument(configs[i]);
  356. switch (param) {
  357. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  358. val = param_val ? 0 : 1;
  359. ret = regmap_update_bits(mpci->rmap,
  360. MAX77620_REG_GPIO0 + pin,
  361. MAX77620_CNFG_GPIO_DRV_MASK,
  362. val);
  363. if (ret < 0) {
  364. dev_err(dev, "Reg 0x%02x update failed %d\n",
  365. MAX77620_REG_GPIO0 + pin, ret);
  366. return ret;
  367. }
  368. mpci->pin_info[pin].drv_type = val ?
  369. MAX77620_PIN_PP_DRV : MAX77620_PIN_OD_DRV;
  370. break;
  371. case PIN_CONFIG_DRIVE_PUSH_PULL:
  372. val = param_val ? 1 : 0;
  373. ret = regmap_update_bits(mpci->rmap,
  374. MAX77620_REG_GPIO0 + pin,
  375. MAX77620_CNFG_GPIO_DRV_MASK,
  376. val);
  377. if (ret < 0) {
  378. dev_err(dev, "Reg 0x%02x update failed %d\n",
  379. MAX77620_REG_GPIO0 + pin, ret);
  380. return ret;
  381. }
  382. mpci->pin_info[pin].drv_type = val ?
  383. MAX77620_PIN_PP_DRV : MAX77620_PIN_OD_DRV;
  384. break;
  385. case MAX77620_ACTIVE_FPS_SOURCE:
  386. case MAX77620_ACTIVE_FPS_POWER_ON_SLOTS:
  387. case MAX77620_ACTIVE_FPS_POWER_DOWN_SLOTS:
  388. if ((pin < MAX77620_GPIO1) || (pin > MAX77620_GPIO3))
  389. return -EINVAL;
  390. fps_config = &mpci->fps_config[pin];
  391. if ((param == MAX77620_ACTIVE_FPS_SOURCE) &&
  392. (param_val == MAX77620_FPS_SRC_DEF)) {
  393. addr = MAX77620_REG_FPS_GPIO1 + pin - 1;
  394. ret = max77620_get_default_fps(
  395. mpci, addr,
  396. &fps_config->active_fps_src);
  397. if (ret < 0)
  398. return ret;
  399. break;
  400. }
  401. if (param == MAX77620_ACTIVE_FPS_SOURCE)
  402. fps_config->active_fps_src = param_val;
  403. else if (param == MAX77620_ACTIVE_FPS_POWER_ON_SLOTS)
  404. fps_config->active_power_up_slots = param_val;
  405. else
  406. fps_config->active_power_down_slots = param_val;
  407. ret = max77620_set_fps_param(mpci, pin, param);
  408. if (ret < 0)
  409. return ret;
  410. break;
  411. case MAX77620_SUSPEND_FPS_SOURCE:
  412. case MAX77620_SUSPEND_FPS_POWER_ON_SLOTS:
  413. case MAX77620_SUSPEND_FPS_POWER_DOWN_SLOTS:
  414. if ((pin < MAX77620_GPIO1) || (pin > MAX77620_GPIO3))
  415. return -EINVAL;
  416. fps_config = &mpci->fps_config[pin];
  417. if ((param == MAX77620_SUSPEND_FPS_SOURCE) &&
  418. (param_val == MAX77620_FPS_SRC_DEF)) {
  419. addr = MAX77620_REG_FPS_GPIO1 + pin - 1;
  420. ret = max77620_get_default_fps(
  421. mpci, addr,
  422. &fps_config->suspend_fps_src);
  423. if (ret < 0)
  424. return ret;
  425. break;
  426. }
  427. if (param == MAX77620_SUSPEND_FPS_SOURCE)
  428. fps_config->suspend_fps_src = param_val;
  429. else if (param == MAX77620_SUSPEND_FPS_POWER_ON_SLOTS)
  430. fps_config->suspend_power_up_slots = param_val;
  431. else
  432. fps_config->suspend_power_down_slots =
  433. param_val;
  434. break;
  435. case PIN_CONFIG_BIAS_PULL_UP:
  436. case PIN_CONFIG_BIAS_PULL_DOWN:
  437. pu_val = (param == PIN_CONFIG_BIAS_PULL_UP) ?
  438. BIT(pin) : 0;
  439. pd_val = (param == PIN_CONFIG_BIAS_PULL_DOWN) ?
  440. BIT(pin) : 0;
  441. ret = regmap_update_bits(mpci->rmap,
  442. MAX77620_REG_PUE_GPIO,
  443. BIT(pin), pu_val);
  444. if (ret < 0) {
  445. dev_err(dev, "PUE_GPIO update failed: %d\n",
  446. ret);
  447. return ret;
  448. }
  449. ret = regmap_update_bits(mpci->rmap,
  450. MAX77620_REG_PDE_GPIO,
  451. BIT(pin), pd_val);
  452. if (ret < 0) {
  453. dev_err(dev, "PDE_GPIO update failed: %d\n",
  454. ret);
  455. return ret;
  456. }
  457. break;
  458. default:
  459. dev_err(dev, "Properties not supported\n");
  460. return -ENOTSUPP;
  461. }
  462. }
  463. return 0;
  464. }
  465. static const struct pinconf_ops max77620_pinconf_ops = {
  466. .pin_config_get = max77620_pinconf_get,
  467. .pin_config_set = max77620_pinconf_set,
  468. };
  469. static struct pinctrl_desc max77620_pinctrl_desc = {
  470. .pctlops = &max77620_pinctrl_ops,
  471. .pmxops = &max77620_pinmux_ops,
  472. .confops = &max77620_pinconf_ops,
  473. };
  474. static int max77620_pinctrl_probe(struct platform_device *pdev)
  475. {
  476. struct max77620_chip *max77620 = dev_get_drvdata(pdev->dev.parent);
  477. struct max77620_pctrl_info *mpci;
  478. int i;
  479. mpci = devm_kzalloc(&pdev->dev, sizeof(*mpci), GFP_KERNEL);
  480. if (!mpci)
  481. return -ENOMEM;
  482. mpci->dev = &pdev->dev;
  483. mpci->dev->of_node = pdev->dev.parent->of_node;
  484. mpci->rmap = max77620->rmap;
  485. mpci->pins = max77620_pins_desc;
  486. mpci->num_pins = ARRAY_SIZE(max77620_pins_desc);
  487. mpci->functions = max77620_pin_function;
  488. mpci->num_functions = ARRAY_SIZE(max77620_pin_function);
  489. mpci->pin_groups = max77620_pingroups;
  490. mpci->num_pin_groups = ARRAY_SIZE(max77620_pingroups);
  491. platform_set_drvdata(pdev, mpci);
  492. max77620_pinctrl_desc.name = dev_name(&pdev->dev);
  493. max77620_pinctrl_desc.pins = max77620_pins_desc;
  494. max77620_pinctrl_desc.npins = ARRAY_SIZE(max77620_pins_desc);
  495. max77620_pinctrl_desc.num_custom_params =
  496. ARRAY_SIZE(max77620_cfg_params);
  497. max77620_pinctrl_desc.custom_params = max77620_cfg_params;
  498. for (i = 0; i < MAX77620_PIN_NUM; ++i) {
  499. mpci->fps_config[i].active_fps_src = -1;
  500. mpci->fps_config[i].active_power_up_slots = -1;
  501. mpci->fps_config[i].active_power_down_slots = -1;
  502. mpci->fps_config[i].suspend_fps_src = -1;
  503. mpci->fps_config[i].suspend_power_up_slots = -1;
  504. mpci->fps_config[i].suspend_power_down_slots = -1;
  505. }
  506. mpci->pctl = devm_pinctrl_register(&pdev->dev, &max77620_pinctrl_desc,
  507. mpci);
  508. if (IS_ERR(mpci->pctl)) {
  509. dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
  510. return PTR_ERR(mpci->pctl);
  511. }
  512. return 0;
  513. }
  514. #ifdef CONFIG_PM_SLEEP
  515. static int max77620_suspend_fps_param[] = {
  516. MAX77620_SUSPEND_FPS_SOURCE,
  517. MAX77620_SUSPEND_FPS_POWER_ON_SLOTS,
  518. MAX77620_SUSPEND_FPS_POWER_DOWN_SLOTS,
  519. };
  520. static int max77620_active_fps_param[] = {
  521. MAX77620_ACTIVE_FPS_SOURCE,
  522. MAX77620_ACTIVE_FPS_POWER_ON_SLOTS,
  523. MAX77620_ACTIVE_FPS_POWER_DOWN_SLOTS,
  524. };
  525. static int max77620_pinctrl_suspend(struct device *dev)
  526. {
  527. struct max77620_pctrl_info *mpci = dev_get_drvdata(dev);
  528. int pin, p;
  529. for (pin = 0; pin < MAX77620_PIN_NUM; ++pin) {
  530. if ((pin < MAX77620_GPIO1) || (pin > MAX77620_GPIO3))
  531. continue;
  532. for (p = 0; p < 3; ++p)
  533. max77620_set_fps_param(
  534. mpci, pin, max77620_suspend_fps_param[p]);
  535. }
  536. return 0;
  537. };
  538. static int max77620_pinctrl_resume(struct device *dev)
  539. {
  540. struct max77620_pctrl_info *mpci = dev_get_drvdata(dev);
  541. int pin, p;
  542. for (pin = 0; pin < MAX77620_PIN_NUM; ++pin) {
  543. if ((pin < MAX77620_GPIO1) || (pin > MAX77620_GPIO3))
  544. continue;
  545. for (p = 0; p < 3; ++p)
  546. max77620_set_fps_param(
  547. mpci, pin, max77620_active_fps_param[p]);
  548. }
  549. return 0;
  550. }
  551. #endif
  552. static const struct dev_pm_ops max77620_pinctrl_pm_ops = {
  553. SET_SYSTEM_SLEEP_PM_OPS(
  554. max77620_pinctrl_suspend, max77620_pinctrl_resume)
  555. };
  556. static const struct platform_device_id max77620_pinctrl_devtype[] = {
  557. { .name = "max77620-pinctrl", },
  558. { .name = "max20024-pinctrl", },
  559. {},
  560. };
  561. MODULE_DEVICE_TABLE(platform, max77620_pinctrl_devtype);
  562. static struct platform_driver max77620_pinctrl_driver = {
  563. .driver = {
  564. .name = "max77620-pinctrl",
  565. .pm = &max77620_pinctrl_pm_ops,
  566. },
  567. .probe = max77620_pinctrl_probe,
  568. .id_table = max77620_pinctrl_devtype,
  569. };
  570. module_platform_driver(max77620_pinctrl_driver);
  571. MODULE_DESCRIPTION("MAX77620/MAX20024 pin control driver");
  572. MODULE_AUTHOR("Chaitanya Bandi<bandik@nvidia.com>");
  573. MODULE_AUTHOR("Laxman Dewangan<ldewangan@nvidia.com>");
  574. MODULE_ALIAS("platform:max77620-pinctrl");
  575. MODULE_LICENSE("GPL v2");