pinctrl-spmi-gpio.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /*
  2. * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/gpio.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/of_irq.h>
  17. #include <linux/pinctrl/pinconf-generic.h>
  18. #include <linux/pinctrl/pinconf.h>
  19. #include <linux/pinctrl/pinmux.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/regmap.h>
  22. #include <linux/slab.h>
  23. #include <linux/types.h>
  24. #include <dt-bindings/pinctrl/qcom,pmic-gpio.h>
  25. #include "../core.h"
  26. #include "../pinctrl-utils.h"
  27. #define PMIC_GPIO_ADDRESS_RANGE 0x100
  28. /* type and subtype registers base address offsets */
  29. #define PMIC_GPIO_REG_TYPE 0x4
  30. #define PMIC_GPIO_REG_SUBTYPE 0x5
  31. /* GPIO peripheral type and subtype out_values */
  32. #define PMIC_GPIO_TYPE 0x10
  33. #define PMIC_GPIO_SUBTYPE_GPIO_4CH 0x1
  34. #define PMIC_GPIO_SUBTYPE_GPIOC_4CH 0x5
  35. #define PMIC_GPIO_SUBTYPE_GPIO_8CH 0x9
  36. #define PMIC_GPIO_SUBTYPE_GPIOC_8CH 0xd
  37. #define PMIC_GPIO_SUBTYPE_GPIO_LV 0x10
  38. #define PMIC_GPIO_SUBTYPE_GPIO_MV 0x11
  39. #define PMIC_MPP_REG_RT_STS 0x10
  40. #define PMIC_MPP_REG_RT_STS_VAL_MASK 0x1
  41. /* control register base address offsets */
  42. #define PMIC_GPIO_REG_MODE_CTL 0x40
  43. #define PMIC_GPIO_REG_DIG_VIN_CTL 0x41
  44. #define PMIC_GPIO_REG_DIG_PULL_CTL 0x42
  45. #define PMIC_GPIO_REG_LV_MV_DIG_OUT_SOURCE_CTL 0x44
  46. #define PMIC_GPIO_REG_DIG_IN_CTL 0x43
  47. #define PMIC_GPIO_REG_DIG_OUT_CTL 0x45
  48. #define PMIC_GPIO_REG_EN_CTL 0x46
  49. #define PMIC_GPIO_REG_LV_MV_ANA_PASS_THRU_SEL 0x4A
  50. /* PMIC_GPIO_REG_MODE_CTL */
  51. #define PMIC_GPIO_REG_MODE_VALUE_SHIFT 0x1
  52. #define PMIC_GPIO_REG_MODE_FUNCTION_SHIFT 1
  53. #define PMIC_GPIO_REG_MODE_FUNCTION_MASK 0x7
  54. #define PMIC_GPIO_REG_MODE_DIR_SHIFT 4
  55. #define PMIC_GPIO_REG_MODE_DIR_MASK 0x7
  56. #define PMIC_GPIO_MODE_DIGITAL_INPUT 0
  57. #define PMIC_GPIO_MODE_DIGITAL_OUTPUT 1
  58. #define PMIC_GPIO_MODE_DIGITAL_INPUT_OUTPUT 2
  59. #define PMIC_GPIO_MODE_ANALOG_PASS_THRU 3
  60. #define PMIC_GPIO_REG_LV_MV_MODE_DIR_MASK 0x3
  61. /* PMIC_GPIO_REG_DIG_VIN_CTL */
  62. #define PMIC_GPIO_REG_VIN_SHIFT 0
  63. #define PMIC_GPIO_REG_VIN_MASK 0x7
  64. /* PMIC_GPIO_REG_DIG_PULL_CTL */
  65. #define PMIC_GPIO_REG_PULL_SHIFT 0
  66. #define PMIC_GPIO_REG_PULL_MASK 0x7
  67. #define PMIC_GPIO_PULL_DOWN 4
  68. #define PMIC_GPIO_PULL_DISABLE 5
  69. /* PMIC_GPIO_REG_LV_MV_DIG_OUT_SOURCE_CTL for LV/MV */
  70. #define PMIC_GPIO_LV_MV_OUTPUT_INVERT 0x80
  71. #define PMIC_GPIO_LV_MV_OUTPUT_INVERT_SHIFT 7
  72. #define PMIC_GPIO_LV_MV_OUTPUT_SOURCE_SEL_MASK 0xF
  73. /* PMIC_GPIO_REG_DIG_IN_CTL */
  74. #define PMIC_GPIO_LV_MV_DIG_IN_DTEST_EN 0x80
  75. #define PMIC_GPIO_LV_MV_DIG_IN_DTEST_SEL_MASK 0x7
  76. #define PMIC_GPIO_DIG_IN_DTEST_SEL_MASK 0xf
  77. /* PMIC_GPIO_REG_DIG_OUT_CTL */
  78. #define PMIC_GPIO_REG_OUT_STRENGTH_SHIFT 0
  79. #define PMIC_GPIO_REG_OUT_STRENGTH_MASK 0x3
  80. #define PMIC_GPIO_REG_OUT_TYPE_SHIFT 4
  81. #define PMIC_GPIO_REG_OUT_TYPE_MASK 0x3
  82. /*
  83. * Output type - indicates pin should be configured as push-pull,
  84. * open drain or open source.
  85. */
  86. #define PMIC_GPIO_OUT_BUF_CMOS 0
  87. #define PMIC_GPIO_OUT_BUF_OPEN_DRAIN_NMOS 1
  88. #define PMIC_GPIO_OUT_BUF_OPEN_DRAIN_PMOS 2
  89. /* PMIC_GPIO_REG_EN_CTL */
  90. #define PMIC_GPIO_REG_MASTER_EN_SHIFT 7
  91. #define PMIC_GPIO_PHYSICAL_OFFSET 1
  92. /* PMIC_GPIO_REG_LV_MV_ANA_PASS_THRU_SEL */
  93. #define PMIC_GPIO_LV_MV_ANA_MUX_SEL_MASK 0x3
  94. /* Qualcomm specific pin configurations */
  95. #define PMIC_GPIO_CONF_PULL_UP (PIN_CONFIG_END + 1)
  96. #define PMIC_GPIO_CONF_STRENGTH (PIN_CONFIG_END + 2)
  97. #define PMIC_GPIO_CONF_ATEST (PIN_CONFIG_END + 3)
  98. #define PMIC_GPIO_CONF_ANALOG_PASS (PIN_CONFIG_END + 4)
  99. #define PMIC_GPIO_CONF_DTEST_BUFFER (PIN_CONFIG_END + 5)
  100. /* The index of each function in pmic_gpio_functions[] array */
  101. enum pmic_gpio_func_index {
  102. PMIC_GPIO_FUNC_INDEX_NORMAL,
  103. PMIC_GPIO_FUNC_INDEX_PAIRED,
  104. PMIC_GPIO_FUNC_INDEX_FUNC1,
  105. PMIC_GPIO_FUNC_INDEX_FUNC2,
  106. PMIC_GPIO_FUNC_INDEX_FUNC3,
  107. PMIC_GPIO_FUNC_INDEX_FUNC4,
  108. PMIC_GPIO_FUNC_INDEX_DTEST1,
  109. PMIC_GPIO_FUNC_INDEX_DTEST2,
  110. PMIC_GPIO_FUNC_INDEX_DTEST3,
  111. PMIC_GPIO_FUNC_INDEX_DTEST4,
  112. };
  113. /**
  114. * struct pmic_gpio_pad - keep current GPIO settings
  115. * @base: Address base in SPMI device.
  116. * @irq: IRQ number which this GPIO generate.
  117. * @is_enabled: Set to false when GPIO should be put in high Z state.
  118. * @out_value: Cached pin output value
  119. * @have_buffer: Set to true if GPIO output could be configured in push-pull,
  120. * open-drain or open-source mode.
  121. * @output_enabled: Set to true if GPIO output logic is enabled.
  122. * @input_enabled: Set to true if GPIO input buffer logic is enabled.
  123. * @analog_pass: Set to true if GPIO is in analog-pass-through mode.
  124. * @lv_mv_type: Set to true if GPIO subtype is GPIO_LV(0x10) or GPIO_MV(0x11).
  125. * @num_sources: Number of power-sources supported by this GPIO.
  126. * @power_source: Current power-source used.
  127. * @buffer_type: Push-pull, open-drain or open-source.
  128. * @pullup: Constant current which flow trough GPIO output buffer.
  129. * @strength: No, Low, Medium, High
  130. * @function: See pmic_gpio_functions[]
  131. * @atest: the ATEST selection for GPIO analog-pass-through mode
  132. * @dtest_buffer: the DTEST buffer selection for digital input mode.
  133. */
  134. struct pmic_gpio_pad {
  135. u16 base;
  136. int irq;
  137. bool is_enabled;
  138. bool out_value;
  139. bool have_buffer;
  140. bool output_enabled;
  141. bool input_enabled;
  142. bool analog_pass;
  143. bool lv_mv_type;
  144. unsigned int num_sources;
  145. unsigned int power_source;
  146. unsigned int buffer_type;
  147. unsigned int pullup;
  148. unsigned int strength;
  149. unsigned int function;
  150. unsigned int atest;
  151. unsigned int dtest_buffer;
  152. };
  153. struct pmic_gpio_state {
  154. struct device *dev;
  155. struct regmap *map;
  156. struct pinctrl_dev *ctrl;
  157. struct gpio_chip chip;
  158. };
  159. static const struct pinconf_generic_params pmic_gpio_bindings[] = {
  160. {"qcom,pull-up-strength", PMIC_GPIO_CONF_PULL_UP, 0},
  161. {"qcom,drive-strength", PMIC_GPIO_CONF_STRENGTH, 0},
  162. {"qcom,atest", PMIC_GPIO_CONF_ATEST, 0},
  163. {"qcom,analog-pass", PMIC_GPIO_CONF_ANALOG_PASS, 0},
  164. {"qcom,dtest-buffer", PMIC_GPIO_CONF_DTEST_BUFFER, 0},
  165. };
  166. #ifdef CONFIG_DEBUG_FS
  167. static const struct pin_config_item pmic_conf_items[ARRAY_SIZE(pmic_gpio_bindings)] = {
  168. PCONFDUMP(PMIC_GPIO_CONF_PULL_UP, "pull up strength", NULL, true),
  169. PCONFDUMP(PMIC_GPIO_CONF_STRENGTH, "drive-strength", NULL, true),
  170. PCONFDUMP(PMIC_GPIO_CONF_ATEST, "atest", NULL, true),
  171. PCONFDUMP(PMIC_GPIO_CONF_ANALOG_PASS, "analog-pass", NULL, true),
  172. PCONFDUMP(PMIC_GPIO_CONF_DTEST_BUFFER, "dtest-buffer", NULL, true),
  173. };
  174. #endif
  175. static const char *const pmic_gpio_groups[] = {
  176. "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7", "gpio8",
  177. "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14", "gpio15",
  178. "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21", "gpio22",
  179. "gpio23", "gpio24", "gpio25", "gpio26", "gpio27", "gpio28", "gpio29",
  180. "gpio30", "gpio31", "gpio32", "gpio33", "gpio34", "gpio35", "gpio36",
  181. };
  182. static const char *const pmic_gpio_functions[] = {
  183. [PMIC_GPIO_FUNC_INDEX_NORMAL] = PMIC_GPIO_FUNC_NORMAL,
  184. [PMIC_GPIO_FUNC_INDEX_PAIRED] = PMIC_GPIO_FUNC_PAIRED,
  185. [PMIC_GPIO_FUNC_INDEX_FUNC1] = PMIC_GPIO_FUNC_FUNC1,
  186. [PMIC_GPIO_FUNC_INDEX_FUNC2] = PMIC_GPIO_FUNC_FUNC2,
  187. [PMIC_GPIO_FUNC_INDEX_FUNC3] = PMIC_GPIO_FUNC_FUNC3,
  188. [PMIC_GPIO_FUNC_INDEX_FUNC4] = PMIC_GPIO_FUNC_FUNC4,
  189. [PMIC_GPIO_FUNC_INDEX_DTEST1] = PMIC_GPIO_FUNC_DTEST1,
  190. [PMIC_GPIO_FUNC_INDEX_DTEST2] = PMIC_GPIO_FUNC_DTEST2,
  191. [PMIC_GPIO_FUNC_INDEX_DTEST3] = PMIC_GPIO_FUNC_DTEST3,
  192. [PMIC_GPIO_FUNC_INDEX_DTEST4] = PMIC_GPIO_FUNC_DTEST4,
  193. };
  194. static int pmic_gpio_read(struct pmic_gpio_state *state,
  195. struct pmic_gpio_pad *pad, unsigned int addr)
  196. {
  197. unsigned int val;
  198. int ret;
  199. ret = regmap_read(state->map, pad->base + addr, &val);
  200. if (ret < 0)
  201. dev_err(state->dev, "read 0x%x failed\n", addr);
  202. else
  203. ret = val;
  204. return ret;
  205. }
  206. static int pmic_gpio_write(struct pmic_gpio_state *state,
  207. struct pmic_gpio_pad *pad, unsigned int addr,
  208. unsigned int val)
  209. {
  210. int ret;
  211. ret = regmap_write(state->map, pad->base + addr, val);
  212. if (ret < 0)
  213. dev_err(state->dev, "write 0x%x failed\n", addr);
  214. return ret;
  215. }
  216. static int pmic_gpio_get_groups_count(struct pinctrl_dev *pctldev)
  217. {
  218. /* Every PIN is a group */
  219. return pctldev->desc->npins;
  220. }
  221. static const char *pmic_gpio_get_group_name(struct pinctrl_dev *pctldev,
  222. unsigned pin)
  223. {
  224. return pctldev->desc->pins[pin].name;
  225. }
  226. static int pmic_gpio_get_group_pins(struct pinctrl_dev *pctldev, unsigned pin,
  227. const unsigned **pins, unsigned *num_pins)
  228. {
  229. *pins = &pctldev->desc->pins[pin].number;
  230. *num_pins = 1;
  231. return 0;
  232. }
  233. static const struct pinctrl_ops pmic_gpio_pinctrl_ops = {
  234. .get_groups_count = pmic_gpio_get_groups_count,
  235. .get_group_name = pmic_gpio_get_group_name,
  236. .get_group_pins = pmic_gpio_get_group_pins,
  237. .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
  238. .dt_free_map = pinctrl_utils_free_map,
  239. };
  240. static int pmic_gpio_get_functions_count(struct pinctrl_dev *pctldev)
  241. {
  242. return ARRAY_SIZE(pmic_gpio_functions);
  243. }
  244. static const char *pmic_gpio_get_function_name(struct pinctrl_dev *pctldev,
  245. unsigned function)
  246. {
  247. return pmic_gpio_functions[function];
  248. }
  249. static int pmic_gpio_get_function_groups(struct pinctrl_dev *pctldev,
  250. unsigned function,
  251. const char *const **groups,
  252. unsigned *const num_qgroups)
  253. {
  254. *groups = pmic_gpio_groups;
  255. *num_qgroups = pctldev->desc->npins;
  256. return 0;
  257. }
  258. static int pmic_gpio_set_mux(struct pinctrl_dev *pctldev, unsigned function,
  259. unsigned pin)
  260. {
  261. struct pmic_gpio_state *state = pinctrl_dev_get_drvdata(pctldev);
  262. struct pmic_gpio_pad *pad;
  263. unsigned int val;
  264. int ret;
  265. if (function > PMIC_GPIO_FUNC_INDEX_DTEST4) {
  266. pr_err("function: %d is not defined\n", function);
  267. return -EINVAL;
  268. }
  269. pad = pctldev->desc->pins[pin].drv_data;
  270. /*
  271. * Non-LV/MV subtypes only support 2 special functions,
  272. * offsetting the dtestx function values by 2
  273. */
  274. if (!pad->lv_mv_type) {
  275. if (function == PMIC_GPIO_FUNC_INDEX_FUNC3 ||
  276. function == PMIC_GPIO_FUNC_INDEX_FUNC4) {
  277. pr_err("LV/MV subtype doesn't have func3/func4\n");
  278. return -EINVAL;
  279. }
  280. if (function >= PMIC_GPIO_FUNC_INDEX_DTEST1)
  281. function -= (PMIC_GPIO_FUNC_INDEX_DTEST1 -
  282. PMIC_GPIO_FUNC_INDEX_FUNC3);
  283. }
  284. pad->function = function;
  285. if (pad->analog_pass)
  286. val = PMIC_GPIO_MODE_ANALOG_PASS_THRU;
  287. else if (pad->output_enabled && pad->input_enabled)
  288. val = PMIC_GPIO_MODE_DIGITAL_INPUT_OUTPUT;
  289. else if (pad->output_enabled)
  290. val = PMIC_GPIO_MODE_DIGITAL_OUTPUT;
  291. else
  292. val = PMIC_GPIO_MODE_DIGITAL_INPUT;
  293. if (pad->lv_mv_type) {
  294. ret = pmic_gpio_write(state, pad,
  295. PMIC_GPIO_REG_MODE_CTL, val);
  296. if (ret < 0)
  297. return ret;
  298. val = pad->atest - 1;
  299. ret = pmic_gpio_write(state, pad,
  300. PMIC_GPIO_REG_LV_MV_ANA_PASS_THRU_SEL, val);
  301. if (ret < 0)
  302. return ret;
  303. val = pad->out_value
  304. << PMIC_GPIO_LV_MV_OUTPUT_INVERT_SHIFT;
  305. val |= pad->function
  306. & PMIC_GPIO_LV_MV_OUTPUT_SOURCE_SEL_MASK;
  307. ret = pmic_gpio_write(state, pad,
  308. PMIC_GPIO_REG_LV_MV_DIG_OUT_SOURCE_CTL, val);
  309. if (ret < 0)
  310. return ret;
  311. } else {
  312. val = val << PMIC_GPIO_REG_MODE_DIR_SHIFT;
  313. val |= pad->function << PMIC_GPIO_REG_MODE_FUNCTION_SHIFT;
  314. val |= pad->out_value & PMIC_GPIO_REG_MODE_VALUE_SHIFT;
  315. ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_MODE_CTL, val);
  316. if (ret < 0)
  317. return ret;
  318. }
  319. val = pad->is_enabled << PMIC_GPIO_REG_MASTER_EN_SHIFT;
  320. return pmic_gpio_write(state, pad, PMIC_GPIO_REG_EN_CTL, val);
  321. }
  322. static const struct pinmux_ops pmic_gpio_pinmux_ops = {
  323. .get_functions_count = pmic_gpio_get_functions_count,
  324. .get_function_name = pmic_gpio_get_function_name,
  325. .get_function_groups = pmic_gpio_get_function_groups,
  326. .set_mux = pmic_gpio_set_mux,
  327. };
  328. static int pmic_gpio_config_get(struct pinctrl_dev *pctldev,
  329. unsigned int pin, unsigned long *config)
  330. {
  331. unsigned param = pinconf_to_config_param(*config);
  332. struct pmic_gpio_pad *pad;
  333. unsigned arg;
  334. pad = pctldev->desc->pins[pin].drv_data;
  335. switch (param) {
  336. case PIN_CONFIG_DRIVE_PUSH_PULL:
  337. if (pad->buffer_type != PMIC_GPIO_OUT_BUF_CMOS)
  338. return -EINVAL;
  339. arg = 1;
  340. break;
  341. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  342. if (pad->buffer_type != PMIC_GPIO_OUT_BUF_OPEN_DRAIN_NMOS)
  343. return -EINVAL;
  344. arg = 1;
  345. break;
  346. case PIN_CONFIG_DRIVE_OPEN_SOURCE:
  347. if (pad->buffer_type != PMIC_GPIO_OUT_BUF_OPEN_DRAIN_PMOS)
  348. return -EINVAL;
  349. arg = 1;
  350. break;
  351. case PIN_CONFIG_BIAS_PULL_DOWN:
  352. if (pad->pullup != PMIC_GPIO_PULL_DOWN)
  353. return -EINVAL;
  354. arg = 1;
  355. break;
  356. case PIN_CONFIG_BIAS_DISABLE:
  357. if (pad->pullup != PMIC_GPIO_PULL_DISABLE)
  358. return -EINVAL;
  359. arg = 1;
  360. break;
  361. case PIN_CONFIG_BIAS_PULL_UP:
  362. if (pad->pullup != PMIC_GPIO_PULL_UP_30)
  363. return -EINVAL;
  364. arg = 1;
  365. break;
  366. case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
  367. if (pad->is_enabled)
  368. return -EINVAL;
  369. arg = 1;
  370. break;
  371. case PIN_CONFIG_POWER_SOURCE:
  372. arg = pad->power_source;
  373. break;
  374. case PIN_CONFIG_INPUT_ENABLE:
  375. if (!pad->input_enabled)
  376. return -EINVAL;
  377. arg = 1;
  378. break;
  379. case PIN_CONFIG_OUTPUT:
  380. arg = pad->out_value;
  381. break;
  382. case PMIC_GPIO_CONF_PULL_UP:
  383. arg = pad->pullup;
  384. break;
  385. case PMIC_GPIO_CONF_STRENGTH:
  386. arg = pad->strength;
  387. break;
  388. case PMIC_GPIO_CONF_ATEST:
  389. arg = pad->atest;
  390. break;
  391. case PMIC_GPIO_CONF_ANALOG_PASS:
  392. arg = pad->analog_pass;
  393. break;
  394. case PMIC_GPIO_CONF_DTEST_BUFFER:
  395. arg = pad->dtest_buffer;
  396. break;
  397. default:
  398. return -EINVAL;
  399. }
  400. *config = pinconf_to_config_packed(param, arg);
  401. return 0;
  402. }
  403. static int pmic_gpio_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
  404. unsigned long *configs, unsigned nconfs)
  405. {
  406. struct pmic_gpio_state *state = pinctrl_dev_get_drvdata(pctldev);
  407. struct pmic_gpio_pad *pad;
  408. unsigned param, arg;
  409. unsigned int val;
  410. int i, ret;
  411. pad = pctldev->desc->pins[pin].drv_data;
  412. for (i = 0; i < nconfs; i++) {
  413. param = pinconf_to_config_param(configs[i]);
  414. arg = pinconf_to_config_argument(configs[i]);
  415. switch (param) {
  416. case PIN_CONFIG_DRIVE_PUSH_PULL:
  417. pad->buffer_type = PMIC_GPIO_OUT_BUF_CMOS;
  418. break;
  419. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  420. if (!pad->have_buffer)
  421. return -EINVAL;
  422. pad->buffer_type = PMIC_GPIO_OUT_BUF_OPEN_DRAIN_NMOS;
  423. break;
  424. case PIN_CONFIG_DRIVE_OPEN_SOURCE:
  425. if (!pad->have_buffer)
  426. return -EINVAL;
  427. pad->buffer_type = PMIC_GPIO_OUT_BUF_OPEN_DRAIN_PMOS;
  428. break;
  429. case PIN_CONFIG_BIAS_DISABLE:
  430. pad->pullup = PMIC_GPIO_PULL_DISABLE;
  431. break;
  432. case PIN_CONFIG_BIAS_PULL_UP:
  433. pad->pullup = PMIC_GPIO_PULL_UP_30;
  434. break;
  435. case PIN_CONFIG_BIAS_PULL_DOWN:
  436. if (arg)
  437. pad->pullup = PMIC_GPIO_PULL_DOWN;
  438. else
  439. pad->pullup = PMIC_GPIO_PULL_DISABLE;
  440. break;
  441. case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
  442. pad->is_enabled = false;
  443. break;
  444. case PIN_CONFIG_POWER_SOURCE:
  445. if (arg >= pad->num_sources)
  446. return -EINVAL;
  447. pad->power_source = arg;
  448. break;
  449. case PIN_CONFIG_INPUT_ENABLE:
  450. pad->input_enabled = arg ? true : false;
  451. break;
  452. case PIN_CONFIG_OUTPUT:
  453. pad->output_enabled = true;
  454. pad->out_value = arg;
  455. break;
  456. case PMIC_GPIO_CONF_PULL_UP:
  457. if (arg > PMIC_GPIO_PULL_UP_1P5_30)
  458. return -EINVAL;
  459. pad->pullup = arg;
  460. break;
  461. case PMIC_GPIO_CONF_STRENGTH:
  462. if (arg > PMIC_GPIO_STRENGTH_LOW)
  463. return -EINVAL;
  464. pad->strength = arg;
  465. break;
  466. case PMIC_GPIO_CONF_ATEST:
  467. if (!pad->lv_mv_type || arg > 4)
  468. return -EINVAL;
  469. pad->atest = arg;
  470. break;
  471. case PMIC_GPIO_CONF_ANALOG_PASS:
  472. if (!pad->lv_mv_type)
  473. return -EINVAL;
  474. pad->analog_pass = true;
  475. break;
  476. case PMIC_GPIO_CONF_DTEST_BUFFER:
  477. if (arg > 4)
  478. return -EINVAL;
  479. pad->dtest_buffer = arg;
  480. break;
  481. default:
  482. return -EINVAL;
  483. }
  484. }
  485. val = pad->power_source << PMIC_GPIO_REG_VIN_SHIFT;
  486. ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_DIG_VIN_CTL, val);
  487. if (ret < 0)
  488. return ret;
  489. val = pad->pullup << PMIC_GPIO_REG_PULL_SHIFT;
  490. ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_DIG_PULL_CTL, val);
  491. if (ret < 0)
  492. return ret;
  493. val = pad->buffer_type << PMIC_GPIO_REG_OUT_TYPE_SHIFT;
  494. val |= pad->strength << PMIC_GPIO_REG_OUT_STRENGTH_SHIFT;
  495. ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_DIG_OUT_CTL, val);
  496. if (ret < 0)
  497. return ret;
  498. if (pad->dtest_buffer == 0) {
  499. val = 0;
  500. } else {
  501. if (pad->lv_mv_type) {
  502. val = pad->dtest_buffer - 1;
  503. val |= PMIC_GPIO_LV_MV_DIG_IN_DTEST_EN;
  504. } else {
  505. val = BIT(pad->dtest_buffer - 1);
  506. }
  507. }
  508. ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_DIG_IN_CTL, val);
  509. if (ret < 0)
  510. return ret;
  511. if (pad->analog_pass)
  512. val = PMIC_GPIO_MODE_ANALOG_PASS_THRU;
  513. else if (pad->output_enabled && pad->input_enabled)
  514. val = PMIC_GPIO_MODE_DIGITAL_INPUT_OUTPUT;
  515. else if (pad->output_enabled)
  516. val = PMIC_GPIO_MODE_DIGITAL_OUTPUT;
  517. else
  518. val = PMIC_GPIO_MODE_DIGITAL_INPUT;
  519. if (pad->lv_mv_type) {
  520. ret = pmic_gpio_write(state, pad,
  521. PMIC_GPIO_REG_MODE_CTL, val);
  522. if (ret < 0)
  523. return ret;
  524. val = pad->atest - 1;
  525. ret = pmic_gpio_write(state, pad,
  526. PMIC_GPIO_REG_LV_MV_ANA_PASS_THRU_SEL, val);
  527. if (ret < 0)
  528. return ret;
  529. val = pad->out_value
  530. << PMIC_GPIO_LV_MV_OUTPUT_INVERT_SHIFT;
  531. val |= pad->function
  532. & PMIC_GPIO_LV_MV_OUTPUT_SOURCE_SEL_MASK;
  533. ret = pmic_gpio_write(state, pad,
  534. PMIC_GPIO_REG_LV_MV_DIG_OUT_SOURCE_CTL, val);
  535. if (ret < 0)
  536. return ret;
  537. } else {
  538. val = val << PMIC_GPIO_REG_MODE_DIR_SHIFT;
  539. val |= pad->function << PMIC_GPIO_REG_MODE_FUNCTION_SHIFT;
  540. val |= pad->out_value & PMIC_GPIO_REG_MODE_VALUE_SHIFT;
  541. ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_MODE_CTL, val);
  542. if (ret < 0)
  543. return ret;
  544. }
  545. return ret;
  546. }
  547. static void pmic_gpio_config_dbg_show(struct pinctrl_dev *pctldev,
  548. struct seq_file *s, unsigned pin)
  549. {
  550. struct pmic_gpio_state *state = pinctrl_dev_get_drvdata(pctldev);
  551. struct pmic_gpio_pad *pad;
  552. int ret, val, function;
  553. static const char *const biases[] = {
  554. "pull-up 30uA", "pull-up 1.5uA", "pull-up 31.5uA",
  555. "pull-up 1.5uA + 30uA boost", "pull-down 10uA", "no pull"
  556. };
  557. static const char *const buffer_types[] = {
  558. "push-pull", "open-drain", "open-source"
  559. };
  560. static const char *const strengths[] = {
  561. "no", "high", "medium", "low"
  562. };
  563. pad = pctldev->desc->pins[pin].drv_data;
  564. seq_printf(s, " gpio%-2d:", pin + PMIC_GPIO_PHYSICAL_OFFSET);
  565. val = pmic_gpio_read(state, pad, PMIC_GPIO_REG_EN_CTL);
  566. if (val < 0 || !(val >> PMIC_GPIO_REG_MASTER_EN_SHIFT)) {
  567. seq_puts(s, " ---");
  568. } else {
  569. if (pad->input_enabled) {
  570. ret = pmic_gpio_read(state, pad, PMIC_MPP_REG_RT_STS);
  571. if (ret < 0)
  572. return;
  573. ret &= PMIC_MPP_REG_RT_STS_VAL_MASK;
  574. pad->out_value = ret;
  575. }
  576. /*
  577. * For the non-LV/MV subtypes only 2 special functions are
  578. * available, offsetting the dtest function values by 2.
  579. */
  580. function = pad->function;
  581. if (!pad->lv_mv_type &&
  582. pad->function >= PMIC_GPIO_FUNC_INDEX_FUNC3)
  583. function += PMIC_GPIO_FUNC_INDEX_DTEST1 -
  584. PMIC_GPIO_FUNC_INDEX_FUNC3;
  585. if (pad->analog_pass)
  586. seq_puts(s, " analog-pass");
  587. else
  588. seq_printf(s, " %-4s",
  589. pad->output_enabled ? "out" : "in");
  590. seq_printf(s, " %-7s", pmic_gpio_functions[function]);
  591. seq_printf(s, " vin-%d", pad->power_source);
  592. seq_printf(s, " %-27s", biases[pad->pullup]);
  593. seq_printf(s, " %-10s", buffer_types[pad->buffer_type]);
  594. seq_printf(s, " %-4s", pad->out_value ? "high" : "low");
  595. seq_printf(s, " %-7s", strengths[pad->strength]);
  596. seq_printf(s, " atest-%d", pad->atest);
  597. seq_printf(s, " dtest-%d", pad->dtest_buffer);
  598. }
  599. }
  600. static const struct pinconf_ops pmic_gpio_pinconf_ops = {
  601. .is_generic = true,
  602. .pin_config_group_get = pmic_gpio_config_get,
  603. .pin_config_group_set = pmic_gpio_config_set,
  604. .pin_config_group_dbg_show = pmic_gpio_config_dbg_show,
  605. };
  606. static int pmic_gpio_direction_input(struct gpio_chip *chip, unsigned pin)
  607. {
  608. struct pmic_gpio_state *state = gpiochip_get_data(chip);
  609. unsigned long config;
  610. config = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE, 1);
  611. return pmic_gpio_config_set(state->ctrl, pin, &config, 1);
  612. }
  613. static int pmic_gpio_direction_output(struct gpio_chip *chip,
  614. unsigned pin, int val)
  615. {
  616. struct pmic_gpio_state *state = gpiochip_get_data(chip);
  617. unsigned long config;
  618. config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT, val);
  619. return pmic_gpio_config_set(state->ctrl, pin, &config, 1);
  620. }
  621. static int pmic_gpio_get(struct gpio_chip *chip, unsigned pin)
  622. {
  623. struct pmic_gpio_state *state = gpiochip_get_data(chip);
  624. struct pmic_gpio_pad *pad;
  625. int ret;
  626. pad = state->ctrl->desc->pins[pin].drv_data;
  627. if (!pad->is_enabled)
  628. return -EINVAL;
  629. if (pad->input_enabled) {
  630. ret = pmic_gpio_read(state, pad, PMIC_MPP_REG_RT_STS);
  631. if (ret < 0)
  632. return ret;
  633. pad->out_value = ret & PMIC_MPP_REG_RT_STS_VAL_MASK;
  634. }
  635. return !!pad->out_value;
  636. }
  637. static void pmic_gpio_set(struct gpio_chip *chip, unsigned pin, int value)
  638. {
  639. struct pmic_gpio_state *state = gpiochip_get_data(chip);
  640. unsigned long config;
  641. config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT, value);
  642. pmic_gpio_config_set(state->ctrl, pin, &config, 1);
  643. }
  644. static int pmic_gpio_of_xlate(struct gpio_chip *chip,
  645. const struct of_phandle_args *gpio_desc,
  646. u32 *flags)
  647. {
  648. if (chip->of_gpio_n_cells < 2)
  649. return -EINVAL;
  650. if (flags)
  651. *flags = gpio_desc->args[1];
  652. return gpio_desc->args[0] - PMIC_GPIO_PHYSICAL_OFFSET;
  653. }
  654. static int pmic_gpio_to_irq(struct gpio_chip *chip, unsigned pin)
  655. {
  656. struct pmic_gpio_state *state = gpiochip_get_data(chip);
  657. struct pmic_gpio_pad *pad;
  658. pad = state->ctrl->desc->pins[pin].drv_data;
  659. return pad->irq;
  660. }
  661. static void pmic_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  662. {
  663. struct pmic_gpio_state *state = gpiochip_get_data(chip);
  664. unsigned i;
  665. for (i = 0; i < chip->ngpio; i++) {
  666. pmic_gpio_config_dbg_show(state->ctrl, s, i);
  667. seq_puts(s, "\n");
  668. }
  669. }
  670. static const struct gpio_chip pmic_gpio_gpio_template = {
  671. .direction_input = pmic_gpio_direction_input,
  672. .direction_output = pmic_gpio_direction_output,
  673. .get = pmic_gpio_get,
  674. .set = pmic_gpio_set,
  675. .request = gpiochip_generic_request,
  676. .free = gpiochip_generic_free,
  677. .of_xlate = pmic_gpio_of_xlate,
  678. .to_irq = pmic_gpio_to_irq,
  679. .dbg_show = pmic_gpio_dbg_show,
  680. };
  681. static int pmic_gpio_populate(struct pmic_gpio_state *state,
  682. struct pmic_gpio_pad *pad)
  683. {
  684. int type, subtype, val, dir;
  685. type = pmic_gpio_read(state, pad, PMIC_GPIO_REG_TYPE);
  686. if (type < 0)
  687. return type;
  688. if (type != PMIC_GPIO_TYPE) {
  689. dev_err(state->dev, "incorrect block type 0x%x at 0x%x\n",
  690. type, pad->base);
  691. return -ENODEV;
  692. }
  693. subtype = pmic_gpio_read(state, pad, PMIC_GPIO_REG_SUBTYPE);
  694. if (subtype < 0)
  695. return subtype;
  696. switch (subtype) {
  697. case PMIC_GPIO_SUBTYPE_GPIO_4CH:
  698. pad->have_buffer = true;
  699. case PMIC_GPIO_SUBTYPE_GPIOC_4CH:
  700. pad->num_sources = 4;
  701. break;
  702. case PMIC_GPIO_SUBTYPE_GPIO_8CH:
  703. pad->have_buffer = true;
  704. case PMIC_GPIO_SUBTYPE_GPIOC_8CH:
  705. pad->num_sources = 8;
  706. break;
  707. case PMIC_GPIO_SUBTYPE_GPIO_LV:
  708. pad->num_sources = 1;
  709. pad->have_buffer = true;
  710. pad->lv_mv_type = true;
  711. break;
  712. case PMIC_GPIO_SUBTYPE_GPIO_MV:
  713. pad->num_sources = 2;
  714. pad->have_buffer = true;
  715. pad->lv_mv_type = true;
  716. break;
  717. default:
  718. dev_err(state->dev, "unknown GPIO type 0x%x\n", subtype);
  719. return -ENODEV;
  720. }
  721. if (pad->lv_mv_type) {
  722. val = pmic_gpio_read(state, pad,
  723. PMIC_GPIO_REG_LV_MV_DIG_OUT_SOURCE_CTL);
  724. if (val < 0)
  725. return val;
  726. pad->out_value = !!(val & PMIC_GPIO_LV_MV_OUTPUT_INVERT);
  727. pad->function = val & PMIC_GPIO_LV_MV_OUTPUT_SOURCE_SEL_MASK;
  728. val = pmic_gpio_read(state, pad, PMIC_GPIO_REG_MODE_CTL);
  729. if (val < 0)
  730. return val;
  731. dir = val & PMIC_GPIO_REG_LV_MV_MODE_DIR_MASK;
  732. } else {
  733. val = pmic_gpio_read(state, pad, PMIC_GPIO_REG_MODE_CTL);
  734. if (val < 0)
  735. return val;
  736. pad->out_value = val & PMIC_GPIO_REG_MODE_VALUE_SHIFT;
  737. dir = val >> PMIC_GPIO_REG_MODE_DIR_SHIFT;
  738. dir &= PMIC_GPIO_REG_MODE_DIR_MASK;
  739. pad->function = val >> PMIC_GPIO_REG_MODE_FUNCTION_SHIFT;
  740. pad->function &= PMIC_GPIO_REG_MODE_FUNCTION_MASK;
  741. }
  742. switch (dir) {
  743. case PMIC_GPIO_MODE_DIGITAL_INPUT:
  744. pad->input_enabled = true;
  745. pad->output_enabled = false;
  746. break;
  747. case PMIC_GPIO_MODE_DIGITAL_OUTPUT:
  748. pad->input_enabled = false;
  749. pad->output_enabled = true;
  750. break;
  751. case PMIC_GPIO_MODE_DIGITAL_INPUT_OUTPUT:
  752. pad->input_enabled = true;
  753. pad->output_enabled = true;
  754. break;
  755. case PMIC_GPIO_MODE_ANALOG_PASS_THRU:
  756. if (!pad->lv_mv_type)
  757. return -ENODEV;
  758. pad->analog_pass = true;
  759. break;
  760. default:
  761. dev_err(state->dev, "unknown GPIO direction\n");
  762. return -ENODEV;
  763. }
  764. val = pmic_gpio_read(state, pad, PMIC_GPIO_REG_DIG_VIN_CTL);
  765. if (val < 0)
  766. return val;
  767. pad->power_source = val >> PMIC_GPIO_REG_VIN_SHIFT;
  768. pad->power_source &= PMIC_GPIO_REG_VIN_MASK;
  769. val = pmic_gpio_read(state, pad, PMIC_GPIO_REG_DIG_PULL_CTL);
  770. if (val < 0)
  771. return val;
  772. pad->pullup = val >> PMIC_GPIO_REG_PULL_SHIFT;
  773. pad->pullup &= PMIC_GPIO_REG_PULL_MASK;
  774. val = pmic_gpio_read(state, pad, PMIC_GPIO_REG_DIG_IN_CTL);
  775. if (val < 0)
  776. return val;
  777. if (pad->lv_mv_type && (val & PMIC_GPIO_LV_MV_DIG_IN_DTEST_EN))
  778. pad->dtest_buffer =
  779. (val & PMIC_GPIO_LV_MV_DIG_IN_DTEST_SEL_MASK) + 1;
  780. else if (!pad->lv_mv_type)
  781. pad->dtest_buffer = ffs(val);
  782. else
  783. pad->dtest_buffer = 0;
  784. val = pmic_gpio_read(state, pad, PMIC_GPIO_REG_DIG_OUT_CTL);
  785. if (val < 0)
  786. return val;
  787. pad->strength = val >> PMIC_GPIO_REG_OUT_STRENGTH_SHIFT;
  788. pad->strength &= PMIC_GPIO_REG_OUT_STRENGTH_MASK;
  789. pad->buffer_type = val >> PMIC_GPIO_REG_OUT_TYPE_SHIFT;
  790. pad->buffer_type &= PMIC_GPIO_REG_OUT_TYPE_MASK;
  791. if (pad->lv_mv_type) {
  792. val = pmic_gpio_read(state, pad,
  793. PMIC_GPIO_REG_LV_MV_ANA_PASS_THRU_SEL);
  794. if (val < 0)
  795. return val;
  796. pad->atest = (val & PMIC_GPIO_LV_MV_ANA_MUX_SEL_MASK) + 1;
  797. }
  798. /* Pin could be disabled with PIN_CONFIG_BIAS_HIGH_IMPEDANCE */
  799. pad->is_enabled = true;
  800. return 0;
  801. }
  802. static int pmic_gpio_probe(struct platform_device *pdev)
  803. {
  804. struct device *dev = &pdev->dev;
  805. struct pinctrl_pin_desc *pindesc;
  806. struct pinctrl_desc *pctrldesc;
  807. struct pmic_gpio_pad *pad, *pads;
  808. struct pmic_gpio_state *state;
  809. int ret, npins, i;
  810. u32 reg;
  811. ret = of_property_read_u32(dev->of_node, "reg", &reg);
  812. if (ret < 0) {
  813. dev_err(dev, "missing base address");
  814. return ret;
  815. }
  816. npins = platform_irq_count(pdev);
  817. if (!npins)
  818. return -EINVAL;
  819. if (npins < 0)
  820. return npins;
  821. BUG_ON(npins > ARRAY_SIZE(pmic_gpio_groups));
  822. state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
  823. if (!state)
  824. return -ENOMEM;
  825. platform_set_drvdata(pdev, state);
  826. state->dev = &pdev->dev;
  827. state->map = dev_get_regmap(dev->parent, NULL);
  828. pindesc = devm_kcalloc(dev, npins, sizeof(*pindesc), GFP_KERNEL);
  829. if (!pindesc)
  830. return -ENOMEM;
  831. pads = devm_kcalloc(dev, npins, sizeof(*pads), GFP_KERNEL);
  832. if (!pads)
  833. return -ENOMEM;
  834. pctrldesc = devm_kzalloc(dev, sizeof(*pctrldesc), GFP_KERNEL);
  835. if (!pctrldesc)
  836. return -ENOMEM;
  837. pctrldesc->pctlops = &pmic_gpio_pinctrl_ops;
  838. pctrldesc->pmxops = &pmic_gpio_pinmux_ops;
  839. pctrldesc->confops = &pmic_gpio_pinconf_ops;
  840. pctrldesc->owner = THIS_MODULE;
  841. pctrldesc->name = dev_name(dev);
  842. pctrldesc->pins = pindesc;
  843. pctrldesc->npins = npins;
  844. pctrldesc->num_custom_params = ARRAY_SIZE(pmic_gpio_bindings);
  845. pctrldesc->custom_params = pmic_gpio_bindings;
  846. #ifdef CONFIG_DEBUG_FS
  847. pctrldesc->custom_conf_items = pmic_conf_items;
  848. #endif
  849. for (i = 0; i < npins; i++, pindesc++) {
  850. pad = &pads[i];
  851. pindesc->drv_data = pad;
  852. pindesc->number = i;
  853. pindesc->name = pmic_gpio_groups[i];
  854. pad->irq = platform_get_irq(pdev, i);
  855. if (pad->irq < 0)
  856. return pad->irq;
  857. pad->base = reg + i * PMIC_GPIO_ADDRESS_RANGE;
  858. ret = pmic_gpio_populate(state, pad);
  859. if (ret < 0)
  860. return ret;
  861. }
  862. state->chip = pmic_gpio_gpio_template;
  863. state->chip.parent = dev;
  864. state->chip.base = -1;
  865. state->chip.ngpio = npins;
  866. state->chip.label = dev_name(dev);
  867. state->chip.of_gpio_n_cells = 2;
  868. state->chip.can_sleep = false;
  869. state->ctrl = devm_pinctrl_register(dev, pctrldesc, state);
  870. if (IS_ERR(state->ctrl))
  871. return PTR_ERR(state->ctrl);
  872. ret = gpiochip_add_data(&state->chip, state);
  873. if (ret) {
  874. dev_err(state->dev, "can't add gpio chip\n");
  875. return ret;
  876. }
  877. /*
  878. * For DeviceTree-supported systems, the gpio core checks the
  879. * pinctrl's device node for the "gpio-ranges" property.
  880. * If it is present, it takes care of adding the pin ranges
  881. * for the driver. In this case the driver can skip ahead.
  882. *
  883. * In order to remain compatible with older, existing DeviceTree
  884. * files which don't set the "gpio-ranges" property or systems that
  885. * utilize ACPI the driver has to call gpiochip_add_pin_range().
  886. */
  887. if (!of_property_read_bool(dev->of_node, "gpio-ranges")) {
  888. ret = gpiochip_add_pin_range(&state->chip, dev_name(dev), 0, 0,
  889. npins);
  890. if (ret) {
  891. dev_err(dev, "failed to add pin range\n");
  892. goto err_range;
  893. }
  894. }
  895. return 0;
  896. err_range:
  897. gpiochip_remove(&state->chip);
  898. return ret;
  899. }
  900. static int pmic_gpio_remove(struct platform_device *pdev)
  901. {
  902. struct pmic_gpio_state *state = platform_get_drvdata(pdev);
  903. gpiochip_remove(&state->chip);
  904. return 0;
  905. }
  906. static const struct of_device_id pmic_gpio_of_match[] = {
  907. { .compatible = "qcom,pm8916-gpio" }, /* 4 GPIO's */
  908. { .compatible = "qcom,pm8941-gpio" }, /* 36 GPIO's */
  909. { .compatible = "qcom,pm8994-gpio" }, /* 22 GPIO's */
  910. { .compatible = "qcom,pma8084-gpio" }, /* 22 GPIO's */
  911. { .compatible = "qcom,spmi-gpio" }, /* Generic */
  912. { },
  913. };
  914. MODULE_DEVICE_TABLE(of, pmic_gpio_of_match);
  915. static struct platform_driver pmic_gpio_driver = {
  916. .driver = {
  917. .name = "qcom-spmi-gpio",
  918. .of_match_table = pmic_gpio_of_match,
  919. },
  920. .probe = pmic_gpio_probe,
  921. .remove = pmic_gpio_remove,
  922. };
  923. module_platform_driver(pmic_gpio_driver);
  924. MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
  925. MODULE_DESCRIPTION("Qualcomm SPMI PMIC GPIO pin control driver");
  926. MODULE_ALIAS("platform:qcom-spmi-gpio");
  927. MODULE_LICENSE("GPL v2");