pinctrl-max77620.c 18 KB

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