pinctrl-lpi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Copyright (c) 2016-2017, 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/io.h>
  15. #include <linux/module.h>
  16. #include <linux/of.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/slab.h>
  22. #include <linux/types.h>
  23. #include <dsp/audio_notifier.h>
  24. #include "core.h"
  25. #include "pinctrl-utils.h"
  26. #define LPI_ADDRESS_SIZE 0x20000
  27. #define LPI_GPIO_REG_VAL_CTL 0x00
  28. #define LPI_GPIO_REG_DIR_CTL 0x04
  29. #define LPI_GPIO_REG_PULL_SHIFT 0x0
  30. #define LPI_GPIO_REG_PULL_MASK 0x3
  31. #define LPI_GPIO_REG_FUNCTION_SHIFT 0x2
  32. #define LPI_GPIO_REG_FUNCTION_MASK 0x3C
  33. #define LPI_GPIO_REG_OUT_STRENGTH_SHIFT 0x6
  34. #define LPI_GPIO_REG_OUT_STRENGTH_MASK 0x1C0
  35. #define LPI_GPIO_REG_OE_SHIFT 0x9
  36. #define LPI_GPIO_REG_OE_MASK 0x200
  37. #define LPI_GPIO_REG_DIR_SHIFT 0x1
  38. #define LPI_GPIO_REG_DIR_MASK 0x2
  39. #define LPI_GPIO_BIAS_DISABLE 0x0
  40. #define LPI_GPIO_PULL_DOWN 0x1
  41. #define LPI_GPIO_KEEPER 0x2
  42. #define LPI_GPIO_PULL_UP 0x3
  43. #define LPI_GPIO_FUNC_GPIO "gpio"
  44. #define LPI_GPIO_FUNC_FUNC1 "func1"
  45. #define LPI_GPIO_FUNC_FUNC2 "func2"
  46. #define LPI_GPIO_FUNC_FUNC3 "func3"
  47. #define LPI_GPIO_FUNC_FUNC4 "func4"
  48. #define LPI_GPIO_FUNC_FUNC5 "func5"
  49. static bool lpi_dev_up;
  50. /* The index of each function in lpi_gpio_functions[] array */
  51. enum lpi_gpio_func_index {
  52. LPI_GPIO_FUNC_INDEX_GPIO = 0x00,
  53. LPI_GPIO_FUNC_INDEX_FUNC1 = 0x01,
  54. LPI_GPIO_FUNC_INDEX_FUNC2 = 0x02,
  55. LPI_GPIO_FUNC_INDEX_FUNC3 = 0x03,
  56. LPI_GPIO_FUNC_INDEX_FUNC4 = 0x04,
  57. LPI_GPIO_FUNC_INDEX_FUNC5 = 0x05,
  58. };
  59. /**
  60. * struct lpi_gpio_pad - keep current GPIO settings
  61. * @offset: Nth GPIO in supported GPIOs.
  62. * @output_enabled: Set to true if GPIO output logic is enabled.
  63. * @value: value of a pin
  64. * @base: Address base of LPI GPIO PAD.
  65. * @pullup: Constant current which flow through GPIO output buffer.
  66. * @strength: No, Low, Medium, High
  67. * @function: See lpi_gpio_functions[]
  68. */
  69. struct lpi_gpio_pad {
  70. u16 offset;
  71. bool output_enabled;
  72. bool value;
  73. char __iomem *base;
  74. unsigned int pullup;
  75. unsigned int strength;
  76. unsigned int function;
  77. };
  78. struct lpi_gpio_state {
  79. struct device *dev;
  80. struct pinctrl_dev *ctrl;
  81. struct gpio_chip chip;
  82. char __iomem *base;
  83. };
  84. static const char *const lpi_gpio_groups[] = {
  85. "gpio0", "gpio1", "gpio2", "gpio3", "gpio4", "gpio5", "gpio6", "gpio7",
  86. "gpio8", "gpio9", "gpio10", "gpio11", "gpio12", "gpio13", "gpio14",
  87. "gpio15", "gpio16", "gpio17", "gpio18", "gpio19", "gpio20", "gpio21",
  88. "gpio22", "gpio23", "gpio24", "gpio25", "gpio26", "gpio27", "gpio28",
  89. "gpio29", "gpio30", "gpio31",
  90. };
  91. static const u32 lpi_offset[] = {
  92. 0x00000000,
  93. 0x00001000,
  94. 0x00002000,
  95. 0x00003000,
  96. 0x00004000,
  97. 0x00005000,
  98. 0x00006000,
  99. 0x00007000,
  100. 0x00008000,
  101. 0x00009000,
  102. 0x0000A000,
  103. 0x0000B000,
  104. 0x0000C000,
  105. 0x0000D000,
  106. 0x0000E000,
  107. 0x0000F000,
  108. 0x00010000,
  109. 0x00011000,
  110. 0x00012000,
  111. 0x00013000,
  112. 0x00014000,
  113. 0x00015000,
  114. 0x00016000,
  115. 0x00017000,
  116. 0x00018000,
  117. 0x00019000,
  118. 0x0001A000,
  119. 0x0001B000,
  120. 0x0001C000,
  121. 0x0001D000,
  122. 0x0001E000,
  123. 0x0001F000,
  124. };
  125. static const char *const lpi_gpio_functions[] = {
  126. [LPI_GPIO_FUNC_INDEX_GPIO] = LPI_GPIO_FUNC_GPIO,
  127. [LPI_GPIO_FUNC_INDEX_FUNC1] = LPI_GPIO_FUNC_FUNC1,
  128. [LPI_GPIO_FUNC_INDEX_FUNC2] = LPI_GPIO_FUNC_FUNC2,
  129. [LPI_GPIO_FUNC_INDEX_FUNC3] = LPI_GPIO_FUNC_FUNC3,
  130. [LPI_GPIO_FUNC_INDEX_FUNC4] = LPI_GPIO_FUNC_FUNC4,
  131. [LPI_GPIO_FUNC_INDEX_FUNC5] = LPI_GPIO_FUNC_FUNC5,
  132. };
  133. static int lpi_gpio_read(struct lpi_gpio_pad *pad, unsigned int addr)
  134. {
  135. int ret;
  136. if (!lpi_dev_up) {
  137. pr_err_ratelimited("%s: ADSP is down due to SSR, return\n",
  138. __func__);
  139. return 0;
  140. }
  141. ret = ioread32(pad->base + pad->offset + addr);
  142. if (ret < 0)
  143. pr_err("%s: read 0x%x failed\n", __func__, addr);
  144. return ret;
  145. }
  146. static int lpi_gpio_write(struct lpi_gpio_pad *pad, unsigned int addr,
  147. unsigned int val)
  148. {
  149. if (!lpi_dev_up) {
  150. pr_err_ratelimited("%s: ADSP is down due to SSR, return\n",
  151. __func__);
  152. return 0;
  153. }
  154. iowrite32(val, pad->base + pad->offset + addr);
  155. return 0;
  156. }
  157. static int lpi_gpio_get_groups_count(struct pinctrl_dev *pctldev)
  158. {
  159. /* Every PIN is a group */
  160. return pctldev->desc->npins;
  161. }
  162. static const char *lpi_gpio_get_group_name(struct pinctrl_dev *pctldev,
  163. unsigned int pin)
  164. {
  165. return pctldev->desc->pins[pin].name;
  166. }
  167. static int lpi_gpio_get_group_pins(struct pinctrl_dev *pctldev,
  168. unsigned int pin,
  169. const unsigned int **pins,
  170. unsigned int *num_pins)
  171. {
  172. *pins = &pctldev->desc->pins[pin].number;
  173. *num_pins = 1;
  174. return 0;
  175. }
  176. static const struct pinctrl_ops lpi_gpio_pinctrl_ops = {
  177. .get_groups_count = lpi_gpio_get_groups_count,
  178. .get_group_name = lpi_gpio_get_group_name,
  179. .get_group_pins = lpi_gpio_get_group_pins,
  180. .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
  181. .dt_free_map = pinctrl_utils_free_map,
  182. };
  183. static int lpi_gpio_get_functions_count(struct pinctrl_dev *pctldev)
  184. {
  185. return ARRAY_SIZE(lpi_gpio_functions);
  186. }
  187. static const char *lpi_gpio_get_function_name(struct pinctrl_dev *pctldev,
  188. unsigned int function)
  189. {
  190. return lpi_gpio_functions[function];
  191. }
  192. static int lpi_gpio_get_function_groups(struct pinctrl_dev *pctldev,
  193. unsigned int function,
  194. const char *const **groups,
  195. unsigned *const num_qgroups)
  196. {
  197. *groups = lpi_gpio_groups;
  198. *num_qgroups = pctldev->desc->npins;
  199. return 0;
  200. }
  201. static int lpi_gpio_set_mux(struct pinctrl_dev *pctldev, unsigned int function,
  202. unsigned int pin)
  203. {
  204. struct lpi_gpio_pad *pad;
  205. unsigned int val;
  206. pad = pctldev->desc->pins[pin].drv_data;
  207. pad->function = function;
  208. val = lpi_gpio_read(pad, LPI_GPIO_REG_VAL_CTL);
  209. val &= ~(LPI_GPIO_REG_FUNCTION_MASK);
  210. val |= pad->function << LPI_GPIO_REG_FUNCTION_SHIFT;
  211. lpi_gpio_write(pad, LPI_GPIO_REG_VAL_CTL, val);
  212. return 0;
  213. }
  214. static const struct pinmux_ops lpi_gpio_pinmux_ops = {
  215. .get_functions_count = lpi_gpio_get_functions_count,
  216. .get_function_name = lpi_gpio_get_function_name,
  217. .get_function_groups = lpi_gpio_get_function_groups,
  218. .set_mux = lpi_gpio_set_mux,
  219. };
  220. static int lpi_config_get(struct pinctrl_dev *pctldev,
  221. unsigned int pin, unsigned long *config)
  222. {
  223. unsigned int param = pinconf_to_config_param(*config);
  224. struct lpi_gpio_pad *pad;
  225. unsigned int arg;
  226. pad = pctldev->desc->pins[pin].drv_data;
  227. switch (param) {
  228. case PIN_CONFIG_BIAS_DISABLE:
  229. arg = pad->pullup = LPI_GPIO_BIAS_DISABLE;
  230. break;
  231. case PIN_CONFIG_BIAS_PULL_DOWN:
  232. arg = pad->pullup == LPI_GPIO_PULL_DOWN;
  233. break;
  234. case PIN_CONFIG_BIAS_BUS_HOLD:
  235. arg = pad->pullup = LPI_GPIO_KEEPER;
  236. break;
  237. case PIN_CONFIG_BIAS_PULL_UP:
  238. arg = pad->pullup == LPI_GPIO_PULL_UP;
  239. break;
  240. case PIN_CONFIG_INPUT_ENABLE:
  241. case PIN_CONFIG_OUTPUT:
  242. arg = pad->output_enabled;
  243. break;
  244. default:
  245. return -EINVAL;
  246. }
  247. *config = pinconf_to_config_packed(param, arg);
  248. return 0;
  249. }
  250. static unsigned int lpi_drive_to_regval(u32 arg)
  251. {
  252. return (arg/2 - 1);
  253. }
  254. static int lpi_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
  255. unsigned long *configs, unsigned int nconfs)
  256. {
  257. struct lpi_gpio_pad *pad;
  258. unsigned int param, arg;
  259. int i, ret = 0, val;
  260. pad = pctldev->desc->pins[pin].drv_data;
  261. for (i = 0; i < nconfs; i++) {
  262. param = pinconf_to_config_param(configs[i]);
  263. arg = pinconf_to_config_argument(configs[i]);
  264. dev_dbg(pctldev->dev, "%s: param: %d arg: %d pin: %d\n",
  265. __func__, param, arg, pin);
  266. switch (param) {
  267. case PIN_CONFIG_BIAS_DISABLE:
  268. pad->pullup = LPI_GPIO_BIAS_DISABLE;
  269. break;
  270. case PIN_CONFIG_BIAS_PULL_DOWN:
  271. pad->pullup = LPI_GPIO_PULL_DOWN;
  272. break;
  273. case PIN_CONFIG_BIAS_BUS_HOLD:
  274. pad->pullup = LPI_GPIO_KEEPER;
  275. break;
  276. case PIN_CONFIG_BIAS_PULL_UP:
  277. pad->pullup = LPI_GPIO_PULL_UP;
  278. break;
  279. case PIN_CONFIG_INPUT_ENABLE:
  280. pad->output_enabled = false;
  281. break;
  282. case PIN_CONFIG_OUTPUT:
  283. pad->output_enabled = true;
  284. pad->value = arg;
  285. break;
  286. case PIN_CONFIG_DRIVE_STRENGTH:
  287. pad->strength = arg;
  288. break;
  289. default:
  290. ret = -EINVAL;
  291. goto done;
  292. }
  293. }
  294. val = lpi_gpio_read(pad, LPI_GPIO_REG_VAL_CTL);
  295. val &= ~(LPI_GPIO_REG_PULL_MASK | LPI_GPIO_REG_OUT_STRENGTH_MASK |
  296. LPI_GPIO_REG_OE_MASK);
  297. val |= pad->pullup << LPI_GPIO_REG_PULL_SHIFT;
  298. val |= lpi_drive_to_regval(pad->strength) <<
  299. LPI_GPIO_REG_OUT_STRENGTH_SHIFT;
  300. if (pad->output_enabled)
  301. val |= pad->value << LPI_GPIO_REG_OE_SHIFT;
  302. lpi_gpio_write(pad, LPI_GPIO_REG_VAL_CTL, val);
  303. lpi_gpio_write(pad, LPI_GPIO_REG_DIR_CTL,
  304. pad->output_enabled << LPI_GPIO_REG_DIR_SHIFT);
  305. done:
  306. return ret;
  307. }
  308. static const struct pinconf_ops lpi_gpio_pinconf_ops = {
  309. .is_generic = true,
  310. .pin_config_group_get = lpi_config_get,
  311. .pin_config_group_set = lpi_config_set,
  312. };
  313. static int lpi_gpio_direction_input(struct gpio_chip *chip, unsigned int pin)
  314. {
  315. struct lpi_gpio_state *state = gpiochip_get_data(chip);
  316. unsigned long config;
  317. config = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE, 1);
  318. return lpi_config_set(state->ctrl, pin, &config, 1);
  319. }
  320. static int lpi_gpio_direction_output(struct gpio_chip *chip,
  321. unsigned int pin, int val)
  322. {
  323. struct lpi_gpio_state *state = gpiochip_get_data(chip);
  324. unsigned long config;
  325. config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT, val);
  326. return lpi_config_set(state->ctrl, pin, &config, 1);
  327. }
  328. static int lpi_gpio_get(struct gpio_chip *chip, unsigned int pin)
  329. {
  330. struct lpi_gpio_state *state = gpiochip_get_data(chip);
  331. struct lpi_gpio_pad *pad;
  332. int value;
  333. pad = state->ctrl->desc->pins[pin].drv_data;
  334. value = lpi_gpio_read(pad, LPI_GPIO_REG_VAL_CTL);
  335. return value;
  336. }
  337. static void lpi_gpio_set(struct gpio_chip *chip, unsigned int pin, int value)
  338. {
  339. struct lpi_gpio_state *state = gpiochip_get_data(chip);
  340. unsigned long config;
  341. config = pinconf_to_config_packed(PIN_CONFIG_OUTPUT, value);
  342. lpi_config_set(state->ctrl, pin, &config, 1);
  343. }
  344. static int lpi_notifier_service_cb(struct notifier_block *this,
  345. unsigned long opcode, void *ptr)
  346. {
  347. static bool initial_boot = true;
  348. pr_debug("%s: Service opcode 0x%lx\n", __func__, opcode);
  349. switch (opcode) {
  350. case AUDIO_NOTIFIER_SERVICE_DOWN:
  351. if (initial_boot) {
  352. initial_boot = false;
  353. break;
  354. }
  355. lpi_dev_up = false;
  356. break;
  357. case AUDIO_NOTIFIER_SERVICE_UP:
  358. if (initial_boot)
  359. initial_boot = false;
  360. lpi_dev_up = true;
  361. break;
  362. default:
  363. break;
  364. }
  365. return NOTIFY_OK;
  366. }
  367. static struct notifier_block service_nb = {
  368. .notifier_call = lpi_notifier_service_cb,
  369. .priority = -INT_MAX,
  370. };
  371. #ifdef CONFIG_DEBUG_FS
  372. #include <linux/seq_file.h>
  373. static unsigned int lpi_regval_to_drive(u32 val)
  374. {
  375. return (val + 1) * 2;
  376. }
  377. static void lpi_gpio_dbg_show_one(struct seq_file *s,
  378. struct pinctrl_dev *pctldev,
  379. struct gpio_chip *chip,
  380. unsigned int offset,
  381. unsigned int gpio)
  382. {
  383. struct lpi_gpio_state *state = gpiochip_get_data(chip);
  384. struct pinctrl_pin_desc pindesc;
  385. struct lpi_gpio_pad *pad;
  386. unsigned int func;
  387. int is_out;
  388. int drive;
  389. int pull;
  390. u32 ctl_reg;
  391. static const char * const pulls[] = {
  392. "no pull",
  393. "pull down",
  394. "keeper",
  395. "pull up"
  396. };
  397. pctldev = pctldev ? : state->ctrl;
  398. pindesc = pctldev->desc->pins[offset];
  399. pad = pctldev->desc->pins[offset].drv_data;
  400. ctl_reg = lpi_gpio_read(pad, LPI_GPIO_REG_DIR_CTL);
  401. is_out = (ctl_reg & LPI_GPIO_REG_DIR_MASK) >> LPI_GPIO_REG_DIR_SHIFT;
  402. ctl_reg = lpi_gpio_read(pad, LPI_GPIO_REG_VAL_CTL);
  403. func = (ctl_reg & LPI_GPIO_REG_FUNCTION_MASK) >>
  404. LPI_GPIO_REG_FUNCTION_SHIFT;
  405. drive = (ctl_reg & LPI_GPIO_REG_OUT_STRENGTH_MASK) >>
  406. LPI_GPIO_REG_OUT_STRENGTH_SHIFT;
  407. pull = (ctl_reg & LPI_GPIO_REG_PULL_MASK) >> LPI_GPIO_REG_PULL_SHIFT;
  408. seq_printf(s, " %-8s: %-3s %d",
  409. pindesc.name, is_out ? "out" : "in", func);
  410. seq_printf(s, " %dmA", lpi_regval_to_drive(drive));
  411. seq_printf(s, " %s", pulls[pull]);
  412. }
  413. static void lpi_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  414. {
  415. unsigned int gpio = chip->base;
  416. unsigned int i;
  417. for (i = 0; i < chip->ngpio; i++, gpio++) {
  418. lpi_gpio_dbg_show_one(s, NULL, chip, i, gpio);
  419. seq_puts(s, "\n");
  420. }
  421. }
  422. #else
  423. #define lpi_gpio_dbg_show NULL
  424. #endif
  425. static const struct gpio_chip lpi_gpio_template = {
  426. .direction_input = lpi_gpio_direction_input,
  427. .direction_output = lpi_gpio_direction_output,
  428. .get = lpi_gpio_get,
  429. .set = lpi_gpio_set,
  430. .request = gpiochip_generic_request,
  431. .free = gpiochip_generic_free,
  432. .dbg_show = lpi_gpio_dbg_show,
  433. };
  434. static int lpi_pinctrl_probe(struct platform_device *pdev)
  435. {
  436. struct device *dev = &pdev->dev;
  437. struct pinctrl_pin_desc *pindesc;
  438. struct pinctrl_desc *pctrldesc;
  439. struct lpi_gpio_pad *pad, *pads;
  440. struct lpi_gpio_state *state;
  441. int ret, npins, i;
  442. char __iomem *lpi_base;
  443. u32 reg;
  444. ret = of_property_read_u32(dev->of_node, "reg", &reg);
  445. if (ret < 0) {
  446. dev_err(dev, "missing base address\n");
  447. return ret;
  448. }
  449. ret = of_property_read_u32(dev->of_node, "qcom,num-gpios", &npins);
  450. if (ret < 0)
  451. return ret;
  452. WARN_ON(npins > ARRAY_SIZE(lpi_gpio_groups));
  453. state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
  454. if (!state)
  455. return -ENOMEM;
  456. platform_set_drvdata(pdev, state);
  457. state->dev = &pdev->dev;
  458. pindesc = devm_kcalloc(dev, npins, sizeof(*pindesc), GFP_KERNEL);
  459. if (!pindesc)
  460. return -ENOMEM;
  461. pads = devm_kcalloc(dev, npins, sizeof(*pads), GFP_KERNEL);
  462. if (!pads)
  463. return -ENOMEM;
  464. pctrldesc = devm_kzalloc(dev, sizeof(*pctrldesc), GFP_KERNEL);
  465. if (!pctrldesc)
  466. return -ENOMEM;
  467. pctrldesc->pctlops = &lpi_gpio_pinctrl_ops;
  468. pctrldesc->pmxops = &lpi_gpio_pinmux_ops;
  469. pctrldesc->confops = &lpi_gpio_pinconf_ops;
  470. pctrldesc->owner = THIS_MODULE;
  471. pctrldesc->name = dev_name(dev);
  472. pctrldesc->pins = pindesc;
  473. pctrldesc->npins = npins;
  474. lpi_base = devm_ioremap(dev, reg, LPI_ADDRESS_SIZE);
  475. if (lpi_base == NULL) {
  476. dev_err(dev, "%s devm_ioremap failed\n", __func__);
  477. return -ENOMEM;
  478. }
  479. state->base = lpi_base;
  480. for (i = 0; i < npins; i++, pindesc++) {
  481. pad = &pads[i];
  482. pindesc->drv_data = pad;
  483. pindesc->number = i;
  484. pindesc->name = lpi_gpio_groups[i];
  485. pad->base = lpi_base;
  486. pad->offset = lpi_offset[i];
  487. }
  488. state->chip = lpi_gpio_template;
  489. state->chip.parent = dev;
  490. state->chip.base = -1;
  491. state->chip.ngpio = npins;
  492. state->chip.label = dev_name(dev);
  493. state->chip.of_gpio_n_cells = 2;
  494. state->chip.can_sleep = false;
  495. state->ctrl = devm_pinctrl_register(dev, pctrldesc, state);
  496. if (IS_ERR(state->ctrl))
  497. return PTR_ERR(state->ctrl);
  498. ret = gpiochip_add_data(&state->chip, state);
  499. if (ret) {
  500. dev_err(state->dev, "can't add gpio chip\n");
  501. goto err_chip;
  502. }
  503. ret = gpiochip_add_pin_range(&state->chip, dev_name(dev), 0, 0, npins);
  504. if (ret) {
  505. dev_err(dev, "failed to add pin range\n");
  506. goto err_range;
  507. }
  508. lpi_dev_up = true;
  509. ret = audio_notifier_register("lpi_tlmm", AUDIO_NOTIFIER_ADSP_DOMAIN,
  510. &service_nb);
  511. if (ret < 0) {
  512. pr_err("%s: Audio notifier register failed ret = %d\n",
  513. __func__, ret);
  514. goto err_range;
  515. }
  516. return 0;
  517. err_range:
  518. gpiochip_remove(&state->chip);
  519. err_chip:
  520. return ret;
  521. }
  522. static int lpi_pinctrl_remove(struct platform_device *pdev)
  523. {
  524. struct lpi_gpio_state *state = platform_get_drvdata(pdev);
  525. gpiochip_remove(&state->chip);
  526. return 0;
  527. }
  528. static const struct of_device_id lpi_pinctrl_of_match[] = {
  529. { .compatible = "qcom,lpi-pinctrl" }, /* Generic */
  530. { },
  531. };
  532. MODULE_DEVICE_TABLE(of, lpi_pinctrl_of_match);
  533. static struct platform_driver lpi_pinctrl_driver = {
  534. .driver = {
  535. .name = "qcom-lpi-pinctrl",
  536. .of_match_table = lpi_pinctrl_of_match,
  537. },
  538. .probe = lpi_pinctrl_probe,
  539. .remove = lpi_pinctrl_remove,
  540. };
  541. module_platform_driver(lpi_pinctrl_driver);
  542. MODULE_DESCRIPTION("QTI LPI GPIO pin control driver");
  543. MODULE_LICENSE("GPL v2");