pinctrl-abx500.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2013
  3. *
  4. * Author: Patrice Chotard <patrice.chotard@st.com>
  5. * License terms: GNU General Public License (GPL) version 2
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/slab.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/err.h>
  17. #include <linux/of.h>
  18. #include <linux/of_device.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/gpio.h>
  21. #include <linux/irq.h>
  22. #include <linux/irqdomain.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/bitops.h>
  25. #include <linux/mfd/abx500.h>
  26. #include <linux/mfd/abx500/ab8500.h>
  27. #include <linux/mfd/abx500/ab8500-gpio.h>
  28. #include <linux/pinctrl/pinctrl.h>
  29. #include <linux/pinctrl/consumer.h>
  30. #include <linux/pinctrl/pinmux.h>
  31. #include <linux/pinctrl/pinconf.h>
  32. #include <linux/pinctrl/pinconf-generic.h>
  33. #include <linux/pinctrl/machine.h>
  34. #include "pinctrl-abx500.h"
  35. #include "pinconf.h"
  36. /*
  37. * The AB9540 and AB8540 GPIO support are extended versions
  38. * of the AB8500 GPIO support.
  39. * The AB9540 supports an additional (7th) register so that
  40. * more GPIO may be configured and used.
  41. * The AB8540 supports 4 new gpios (GPIOx_VBAT) that have
  42. * internal pull-up and pull-down capabilities.
  43. */
  44. /*
  45. * GPIO registers offset
  46. * Bank: 0x10
  47. */
  48. #define AB8500_GPIO_SEL1_REG 0x00
  49. #define AB8500_GPIO_SEL2_REG 0x01
  50. #define AB8500_GPIO_SEL3_REG 0x02
  51. #define AB8500_GPIO_SEL4_REG 0x03
  52. #define AB8500_GPIO_SEL5_REG 0x04
  53. #define AB8500_GPIO_SEL6_REG 0x05
  54. #define AB9540_GPIO_SEL7_REG 0x06
  55. #define AB8500_GPIO_DIR1_REG 0x10
  56. #define AB8500_GPIO_DIR2_REG 0x11
  57. #define AB8500_GPIO_DIR3_REG 0x12
  58. #define AB8500_GPIO_DIR4_REG 0x13
  59. #define AB8500_GPIO_DIR5_REG 0x14
  60. #define AB8500_GPIO_DIR6_REG 0x15
  61. #define AB9540_GPIO_DIR7_REG 0x16
  62. #define AB8500_GPIO_OUT1_REG 0x20
  63. #define AB8500_GPIO_OUT2_REG 0x21
  64. #define AB8500_GPIO_OUT3_REG 0x22
  65. #define AB8500_GPIO_OUT4_REG 0x23
  66. #define AB8500_GPIO_OUT5_REG 0x24
  67. #define AB8500_GPIO_OUT6_REG 0x25
  68. #define AB9540_GPIO_OUT7_REG 0x26
  69. #define AB8500_GPIO_PUD1_REG 0x30
  70. #define AB8500_GPIO_PUD2_REG 0x31
  71. #define AB8500_GPIO_PUD3_REG 0x32
  72. #define AB8500_GPIO_PUD4_REG 0x33
  73. #define AB8500_GPIO_PUD5_REG 0x34
  74. #define AB8500_GPIO_PUD6_REG 0x35
  75. #define AB9540_GPIO_PUD7_REG 0x36
  76. #define AB8500_GPIO_IN1_REG 0x40
  77. #define AB8500_GPIO_IN2_REG 0x41
  78. #define AB8500_GPIO_IN3_REG 0x42
  79. #define AB8500_GPIO_IN4_REG 0x43
  80. #define AB8500_GPIO_IN5_REG 0x44
  81. #define AB8500_GPIO_IN6_REG 0x45
  82. #define AB9540_GPIO_IN7_REG 0x46
  83. #define AB8540_GPIO_VINSEL_REG 0x47
  84. #define AB8540_GPIO_PULL_UPDOWN_REG 0x48
  85. #define AB8500_GPIO_ALTFUN_REG 0x50
  86. #define AB8540_GPIO_PULL_UPDOWN_MASK 0x03
  87. #define AB8540_GPIO_VINSEL_MASK 0x03
  88. #define AB8540_GPIOX_VBAT_START 51
  89. #define AB8540_GPIOX_VBAT_END 54
  90. struct abx500_pinctrl {
  91. struct device *dev;
  92. struct pinctrl_dev *pctldev;
  93. struct abx500_pinctrl_soc_data *soc;
  94. struct gpio_chip chip;
  95. struct ab8500 *parent;
  96. struct abx500_gpio_irq_cluster *irq_cluster;
  97. int irq_cluster_size;
  98. };
  99. /**
  100. * to_abx500_pinctrl() - get the pointer to abx500_pinctrl
  101. * @chip: Member of the structure abx500_pinctrl
  102. */
  103. static inline struct abx500_pinctrl *to_abx500_pinctrl(struct gpio_chip *chip)
  104. {
  105. return container_of(chip, struct abx500_pinctrl, chip);
  106. }
  107. static int abx500_gpio_get_bit(struct gpio_chip *chip, u8 reg,
  108. unsigned offset, bool *bit)
  109. {
  110. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  111. u8 pos = offset % 8;
  112. u8 val;
  113. int ret;
  114. reg += offset / 8;
  115. ret = abx500_get_register_interruptible(pct->dev,
  116. AB8500_MISC, reg, &val);
  117. *bit = !!(val & BIT(pos));
  118. if (ret < 0)
  119. dev_err(pct->dev,
  120. "%s read reg =%x, offset=%x failed\n",
  121. __func__, reg, offset);
  122. return ret;
  123. }
  124. static int abx500_gpio_set_bits(struct gpio_chip *chip, u8 reg,
  125. unsigned offset, int val)
  126. {
  127. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  128. u8 pos = offset % 8;
  129. int ret;
  130. reg += offset / 8;
  131. ret = abx500_mask_and_set_register_interruptible(pct->dev,
  132. AB8500_MISC, reg, BIT(pos), val << pos);
  133. if (ret < 0)
  134. dev_err(pct->dev, "%s write failed\n", __func__);
  135. return ret;
  136. }
  137. /**
  138. * abx500_gpio_get() - Get the particular GPIO value
  139. * @chip: Gpio device
  140. * @offset: GPIO number to read
  141. */
  142. static int abx500_gpio_get(struct gpio_chip *chip, unsigned offset)
  143. {
  144. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  145. bool bit;
  146. int ret;
  147. ret = abx500_gpio_get_bit(chip, AB8500_GPIO_IN1_REG,
  148. offset, &bit);
  149. if (ret < 0) {
  150. dev_err(pct->dev, "%s failed\n", __func__);
  151. return ret;
  152. }
  153. return bit;
  154. }
  155. static void abx500_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
  156. {
  157. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  158. int ret;
  159. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val);
  160. if (ret < 0)
  161. dev_err(pct->dev, "%s write failed\n", __func__);
  162. }
  163. static int abx500_get_pull_updown(struct abx500_pinctrl *pct, int offset,
  164. enum abx500_gpio_pull_updown *pull_updown)
  165. {
  166. u8 pos;
  167. u8 val;
  168. int ret;
  169. struct pullud *pullud;
  170. if (!pct->soc->pullud) {
  171. dev_err(pct->dev, "%s AB chip doesn't support pull up/down feature",
  172. __func__);
  173. ret = -EPERM;
  174. goto out;
  175. }
  176. pullud = pct->soc->pullud;
  177. if ((offset < pullud->first_pin)
  178. || (offset > pullud->last_pin)) {
  179. ret = -EINVAL;
  180. goto out;
  181. }
  182. ret = abx500_get_register_interruptible(pct->dev,
  183. AB8500_MISC, AB8540_GPIO_PULL_UPDOWN_REG, &val);
  184. pos = (offset - pullud->first_pin) << 1;
  185. *pull_updown = (val >> pos) & AB8540_GPIO_PULL_UPDOWN_MASK;
  186. out:
  187. if (ret < 0)
  188. dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
  189. return ret;
  190. }
  191. static int abx500_set_pull_updown(struct abx500_pinctrl *pct,
  192. int offset, enum abx500_gpio_pull_updown val)
  193. {
  194. u8 pos;
  195. int ret;
  196. struct pullud *pullud;
  197. if (!pct->soc->pullud) {
  198. dev_err(pct->dev, "%s AB chip doesn't support pull up/down feature",
  199. __func__);
  200. ret = -EPERM;
  201. goto out;
  202. }
  203. pullud = pct->soc->pullud;
  204. if ((offset < pullud->first_pin)
  205. || (offset > pullud->last_pin)) {
  206. ret = -EINVAL;
  207. goto out;
  208. }
  209. pos = (offset - pullud->first_pin) << 1;
  210. ret = abx500_mask_and_set_register_interruptible(pct->dev,
  211. AB8500_MISC, AB8540_GPIO_PULL_UPDOWN_REG,
  212. AB8540_GPIO_PULL_UPDOWN_MASK << pos, val << pos);
  213. out:
  214. if (ret < 0)
  215. dev_err(pct->dev, "%s failed (%d)\n", __func__, ret);
  216. return ret;
  217. }
  218. static int abx500_gpio_direction_output(struct gpio_chip *chip,
  219. unsigned offset,
  220. int val)
  221. {
  222. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  223. struct pullud *pullud = pct->soc->pullud;
  224. unsigned gpio;
  225. int ret;
  226. /* set direction as output */
  227. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_DIR1_REG, offset, 1);
  228. if (ret < 0)
  229. return ret;
  230. /* disable pull down */
  231. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_PUD1_REG, offset, 1);
  232. if (ret < 0)
  233. return ret;
  234. /* if supported, disable both pull down and pull up */
  235. gpio = offset + 1;
  236. if (pullud && gpio >= pullud->first_pin && gpio <= pullud->last_pin) {
  237. ret = abx500_set_pull_updown(pct,
  238. gpio,
  239. ABX500_GPIO_PULL_NONE);
  240. if (ret < 0)
  241. return ret;
  242. }
  243. /* set the output as 1 or 0 */
  244. return abx500_gpio_set_bits(chip, AB8500_GPIO_OUT1_REG, offset, val);
  245. }
  246. static int abx500_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  247. {
  248. /* set the register as input */
  249. return abx500_gpio_set_bits(chip, AB8500_GPIO_DIR1_REG, offset, 0);
  250. }
  251. static int abx500_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  252. {
  253. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  254. /* The AB8500 GPIO numbers are off by one */
  255. int gpio = offset + 1;
  256. int hwirq;
  257. int i;
  258. for (i = 0; i < pct->irq_cluster_size; i++) {
  259. struct abx500_gpio_irq_cluster *cluster =
  260. &pct->irq_cluster[i];
  261. if (gpio >= cluster->start && gpio <= cluster->end) {
  262. /*
  263. * The ABx500 GPIO's associated IRQs are clustered together
  264. * throughout the interrupt numbers at irregular intervals.
  265. * To solve this quandry, we have placed the read-in values
  266. * into the cluster information table.
  267. */
  268. hwirq = gpio - cluster->start + cluster->to_irq;
  269. return irq_create_mapping(pct->parent->domain, hwirq);
  270. }
  271. }
  272. return -EINVAL;
  273. }
  274. static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
  275. unsigned gpio, int alt_setting)
  276. {
  277. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  278. struct alternate_functions af = pct->soc->alternate_functions[gpio];
  279. int ret;
  280. int val;
  281. unsigned offset;
  282. const char *modes[] = {
  283. [ABX500_DEFAULT] = "default",
  284. [ABX500_ALT_A] = "altA",
  285. [ABX500_ALT_B] = "altB",
  286. [ABX500_ALT_C] = "altC",
  287. };
  288. /* sanity check */
  289. if (((alt_setting == ABX500_ALT_A) && (af.gpiosel_bit == UNUSED)) ||
  290. ((alt_setting == ABX500_ALT_B) && (af.alt_bit1 == UNUSED)) ||
  291. ((alt_setting == ABX500_ALT_C) && (af.alt_bit2 == UNUSED))) {
  292. dev_dbg(pct->dev, "pin %d doesn't support %s mode\n", gpio,
  293. modes[alt_setting]);
  294. return -EINVAL;
  295. }
  296. /* on ABx5xx, there is no GPIO0, so adjust the offset */
  297. offset = gpio - 1;
  298. switch (alt_setting) {
  299. case ABX500_DEFAULT:
  300. /*
  301. * for ABx5xx family, default mode is always selected by
  302. * writing 0 to GPIOSELx register, except for pins which
  303. * support at least ALT_B mode, default mode is selected
  304. * by writing 1 to GPIOSELx register
  305. */
  306. val = 0;
  307. if (af.alt_bit1 != UNUSED)
  308. val++;
  309. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  310. offset, val);
  311. break;
  312. case ABX500_ALT_A:
  313. /*
  314. * for ABx5xx family, alt_a mode is always selected by
  315. * writing 1 to GPIOSELx register, except for pins which
  316. * support at least ALT_B mode, alt_a mode is selected
  317. * by writing 0 to GPIOSELx register and 0 in ALTFUNC
  318. * register
  319. */
  320. if (af.alt_bit1 != UNUSED) {
  321. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  322. offset, 0);
  323. ret = abx500_gpio_set_bits(chip,
  324. AB8500_GPIO_ALTFUN_REG,
  325. af.alt_bit1,
  326. !!(af.alta_val && BIT(0)));
  327. if (af.alt_bit2 != UNUSED)
  328. ret = abx500_gpio_set_bits(chip,
  329. AB8500_GPIO_ALTFUN_REG,
  330. af.alt_bit2,
  331. !!(af.alta_val && BIT(1)));
  332. } else
  333. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  334. offset, 1);
  335. break;
  336. case ABX500_ALT_B:
  337. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  338. offset, 0);
  339. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
  340. af.alt_bit1, !!(af.altb_val && BIT(0)));
  341. if (af.alt_bit2 != UNUSED)
  342. ret = abx500_gpio_set_bits(chip,
  343. AB8500_GPIO_ALTFUN_REG,
  344. af.alt_bit2,
  345. !!(af.altb_val && BIT(1)));
  346. break;
  347. case ABX500_ALT_C:
  348. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  349. offset, 0);
  350. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
  351. af.alt_bit2, !!(af.altc_val && BIT(0)));
  352. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
  353. af.alt_bit2, !!(af.altc_val && BIT(1)));
  354. break;
  355. default:
  356. dev_dbg(pct->dev, "unknow alt_setting %d\n", alt_setting);
  357. return -EINVAL;
  358. }
  359. return ret;
  360. }
  361. static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
  362. unsigned gpio)
  363. {
  364. u8 mode;
  365. bool bit_mode;
  366. bool alt_bit1;
  367. bool alt_bit2;
  368. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  369. struct alternate_functions af = pct->soc->alternate_functions[gpio];
  370. /* on ABx5xx, there is no GPIO0, so adjust the offset */
  371. unsigned offset = gpio - 1;
  372. /*
  373. * if gpiosel_bit is set to unused,
  374. * it means no GPIO or special case
  375. */
  376. if (af.gpiosel_bit == UNUSED)
  377. return ABX500_DEFAULT;
  378. /* read GpioSelx register */
  379. abx500_gpio_get_bit(chip, AB8500_GPIO_SEL1_REG + (offset / 8),
  380. af.gpiosel_bit, &bit_mode);
  381. mode = bit_mode;
  382. /* sanity check */
  383. if ((af.alt_bit1 < UNUSED) || (af.alt_bit1 > 7) ||
  384. (af.alt_bit2 < UNUSED) || (af.alt_bit2 > 7)) {
  385. dev_err(pct->dev,
  386. "alt_bitX value not in correct range (-1 to 7)\n");
  387. return -EINVAL;
  388. }
  389. /* if alt_bit2 is used, alt_bit1 must be used too */
  390. if ((af.alt_bit2 != UNUSED) && (af.alt_bit1 == UNUSED)) {
  391. dev_err(pct->dev,
  392. "if alt_bit2 is used, alt_bit1 can't be unused\n");
  393. return -EINVAL;
  394. }
  395. /* check if pin use AlternateFunction register */
  396. if ((af.alt_bit1 == UNUSED) && (af.alt_bit2 == UNUSED))
  397. return mode;
  398. /*
  399. * if pin GPIOSEL bit is set and pin supports alternate function,
  400. * it means DEFAULT mode
  401. */
  402. if (mode)
  403. return ABX500_DEFAULT;
  404. /*
  405. * pin use the AlternatFunction register
  406. * read alt_bit1 value
  407. */
  408. abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG,
  409. af.alt_bit1, &alt_bit1);
  410. if (af.alt_bit2 != UNUSED)
  411. /* read alt_bit2 value */
  412. abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG, af.alt_bit2,
  413. &alt_bit2);
  414. else
  415. alt_bit2 = 0;
  416. mode = (alt_bit2 << 1) + alt_bit1;
  417. if (mode == af.alta_val)
  418. return ABX500_ALT_A;
  419. else if (mode == af.altb_val)
  420. return ABX500_ALT_B;
  421. else
  422. return ABX500_ALT_C;
  423. }
  424. #ifdef CONFIG_DEBUG_FS
  425. #include <linux/seq_file.h>
  426. static void abx500_gpio_dbg_show_one(struct seq_file *s,
  427. struct pinctrl_dev *pctldev,
  428. struct gpio_chip *chip,
  429. unsigned offset, unsigned gpio)
  430. {
  431. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  432. struct pullud *pullud = pct->soc->pullud;
  433. const char *label = gpiochip_is_requested(chip, offset - 1);
  434. u8 gpio_offset = offset - 1;
  435. int mode = -1;
  436. bool is_out;
  437. bool pd;
  438. enum abx500_gpio_pull_updown pud = 0;
  439. const char *modes[] = {
  440. [ABX500_DEFAULT] = "default",
  441. [ABX500_ALT_A] = "altA",
  442. [ABX500_ALT_B] = "altB",
  443. [ABX500_ALT_C] = "altC",
  444. };
  445. const char *pull_up_down[] = {
  446. [ABX500_GPIO_PULL_DOWN] = "pull down",
  447. [ABX500_GPIO_PULL_NONE] = "pull none",
  448. [ABX500_GPIO_PULL_NONE + 1] = "pull none",
  449. [ABX500_GPIO_PULL_UP] = "pull up",
  450. };
  451. abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, gpio_offset, &is_out);
  452. seq_printf(s, " gpio-%-3d (%-20.20s) %-3s",
  453. gpio, label ?: "(none)",
  454. is_out ? "out" : "in ");
  455. if (!is_out) {
  456. if (pullud &&
  457. (offset >= pullud->first_pin) &&
  458. (offset <= pullud->last_pin)) {
  459. abx500_get_pull_updown(pct, offset, &pud);
  460. seq_printf(s, " %-9s", pull_up_down[pud]);
  461. } else {
  462. abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG,
  463. gpio_offset, &pd);
  464. seq_printf(s, " %-9s", pull_up_down[pd]);
  465. }
  466. } else
  467. seq_printf(s, " %-9s", chip->get(chip, offset) ? "hi" : "lo");
  468. if (pctldev)
  469. mode = abx500_get_mode(pctldev, chip, offset);
  470. seq_printf(s, " %s", (mode < 0) ? "unknown" : modes[mode]);
  471. }
  472. static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  473. {
  474. unsigned i;
  475. unsigned gpio = chip->base;
  476. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  477. struct pinctrl_dev *pctldev = pct->pctldev;
  478. for (i = 0; i < chip->ngpio; i++, gpio++) {
  479. /* On AB8500, there is no GPIO0, the first is the GPIO 1 */
  480. abx500_gpio_dbg_show_one(s, pctldev, chip, i + 1, gpio);
  481. seq_printf(s, "\n");
  482. }
  483. }
  484. #else
  485. static inline void abx500_gpio_dbg_show_one(struct seq_file *s,
  486. struct pinctrl_dev *pctldev,
  487. struct gpio_chip *chip,
  488. unsigned offset, unsigned gpio)
  489. {
  490. }
  491. #define abx500_gpio_dbg_show NULL
  492. #endif
  493. static int abx500_gpio_request(struct gpio_chip *chip, unsigned offset)
  494. {
  495. int gpio = chip->base + offset;
  496. return pinctrl_request_gpio(gpio);
  497. }
  498. static void abx500_gpio_free(struct gpio_chip *chip, unsigned offset)
  499. {
  500. int gpio = chip->base + offset;
  501. pinctrl_free_gpio(gpio);
  502. }
  503. static struct gpio_chip abx500gpio_chip = {
  504. .label = "abx500-gpio",
  505. .owner = THIS_MODULE,
  506. .request = abx500_gpio_request,
  507. .free = abx500_gpio_free,
  508. .direction_input = abx500_gpio_direction_input,
  509. .get = abx500_gpio_get,
  510. .direction_output = abx500_gpio_direction_output,
  511. .set = abx500_gpio_set,
  512. .to_irq = abx500_gpio_to_irq,
  513. .dbg_show = abx500_gpio_dbg_show,
  514. };
  515. static int abx500_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev)
  516. {
  517. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  518. return pct->soc->nfunctions;
  519. }
  520. static const char *abx500_pmx_get_func_name(struct pinctrl_dev *pctldev,
  521. unsigned function)
  522. {
  523. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  524. return pct->soc->functions[function].name;
  525. }
  526. static int abx500_pmx_get_func_groups(struct pinctrl_dev *pctldev,
  527. unsigned function,
  528. const char * const **groups,
  529. unsigned * const num_groups)
  530. {
  531. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  532. *groups = pct->soc->functions[function].groups;
  533. *num_groups = pct->soc->functions[function].ngroups;
  534. return 0;
  535. }
  536. static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
  537. unsigned group)
  538. {
  539. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  540. struct gpio_chip *chip = &pct->chip;
  541. const struct abx500_pingroup *g;
  542. int i;
  543. int ret = 0;
  544. g = &pct->soc->groups[group];
  545. if (g->altsetting < 0)
  546. return -EINVAL;
  547. dev_dbg(pct->dev, "enable group %s, %u pins\n", g->name, g->npins);
  548. for (i = 0; i < g->npins; i++) {
  549. dev_dbg(pct->dev, "setting pin %d to altsetting %d\n",
  550. g->pins[i], g->altsetting);
  551. ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting);
  552. }
  553. return ret;
  554. }
  555. static void abx500_pmx_disable(struct pinctrl_dev *pctldev,
  556. unsigned function, unsigned group)
  557. {
  558. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  559. const struct abx500_pingroup *g;
  560. g = &pct->soc->groups[group];
  561. if (g->altsetting < 0)
  562. return;
  563. /* FIXME: poke out the mux, set the pin to some default state? */
  564. dev_dbg(pct->dev, "disable group %s, %u pins\n", g->name, g->npins);
  565. }
  566. static int abx500_gpio_request_enable(struct pinctrl_dev *pctldev,
  567. struct pinctrl_gpio_range *range,
  568. unsigned offset)
  569. {
  570. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  571. const struct abx500_pinrange *p;
  572. int ret;
  573. int i;
  574. /*
  575. * Different ranges have different ways to enable GPIO function on a
  576. * pin, so refer back to our local range type, where we handily define
  577. * what altfunc enables GPIO for a certain pin.
  578. */
  579. for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
  580. p = &pct->soc->gpio_ranges[i];
  581. if ((offset >= p->offset) &&
  582. (offset < (p->offset + p->npins)))
  583. break;
  584. }
  585. if (i == pct->soc->gpio_num_ranges) {
  586. dev_err(pct->dev, "%s failed to locate range\n", __func__);
  587. return -ENODEV;
  588. }
  589. dev_dbg(pct->dev, "enable GPIO by altfunc %d at gpio %d\n",
  590. p->altfunc, offset);
  591. ret = abx500_set_mode(pct->pctldev, &pct->chip,
  592. offset, p->altfunc);
  593. if (ret < 0) {
  594. dev_err(pct->dev, "%s setting altfunc failed\n", __func__);
  595. return ret;
  596. }
  597. return ret;
  598. }
  599. static void abx500_gpio_disable_free(struct pinctrl_dev *pctldev,
  600. struct pinctrl_gpio_range *range,
  601. unsigned offset)
  602. {
  603. }
  604. static const struct pinmux_ops abx500_pinmux_ops = {
  605. .get_functions_count = abx500_pmx_get_funcs_cnt,
  606. .get_function_name = abx500_pmx_get_func_name,
  607. .get_function_groups = abx500_pmx_get_func_groups,
  608. .enable = abx500_pmx_enable,
  609. .disable = abx500_pmx_disable,
  610. .gpio_request_enable = abx500_gpio_request_enable,
  611. .gpio_disable_free = abx500_gpio_disable_free,
  612. };
  613. static int abx500_get_groups_cnt(struct pinctrl_dev *pctldev)
  614. {
  615. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  616. return pct->soc->ngroups;
  617. }
  618. static const char *abx500_get_group_name(struct pinctrl_dev *pctldev,
  619. unsigned selector)
  620. {
  621. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  622. return pct->soc->groups[selector].name;
  623. }
  624. static int abx500_get_group_pins(struct pinctrl_dev *pctldev,
  625. unsigned selector,
  626. const unsigned **pins,
  627. unsigned *num_pins)
  628. {
  629. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  630. *pins = pct->soc->groups[selector].pins;
  631. *num_pins = pct->soc->groups[selector].npins;
  632. return 0;
  633. }
  634. static void abx500_pin_dbg_show(struct pinctrl_dev *pctldev,
  635. struct seq_file *s, unsigned offset)
  636. {
  637. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  638. struct gpio_chip *chip = &pct->chip;
  639. abx500_gpio_dbg_show_one(s, pctldev, chip, offset,
  640. chip->base + offset - 1);
  641. }
  642. static void abx500_dt_free_map(struct pinctrl_dev *pctldev,
  643. struct pinctrl_map *map, unsigned num_maps)
  644. {
  645. int i;
  646. for (i = 0; i < num_maps; i++)
  647. if (map[i].type == PIN_MAP_TYPE_CONFIGS_PIN)
  648. kfree(map[i].data.configs.configs);
  649. kfree(map);
  650. }
  651. static int abx500_dt_reserve_map(struct pinctrl_map **map,
  652. unsigned *reserved_maps,
  653. unsigned *num_maps,
  654. unsigned reserve)
  655. {
  656. unsigned old_num = *reserved_maps;
  657. unsigned new_num = *num_maps + reserve;
  658. struct pinctrl_map *new_map;
  659. if (old_num >= new_num)
  660. return 0;
  661. new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
  662. if (!new_map)
  663. return -ENOMEM;
  664. memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map));
  665. *map = new_map;
  666. *reserved_maps = new_num;
  667. return 0;
  668. }
  669. static int abx500_dt_add_map_mux(struct pinctrl_map **map,
  670. unsigned *reserved_maps,
  671. unsigned *num_maps, const char *group,
  672. const char *function)
  673. {
  674. if (*num_maps == *reserved_maps)
  675. return -ENOSPC;
  676. (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
  677. (*map)[*num_maps].data.mux.group = group;
  678. (*map)[*num_maps].data.mux.function = function;
  679. (*num_maps)++;
  680. return 0;
  681. }
  682. static int abx500_dt_add_map_configs(struct pinctrl_map **map,
  683. unsigned *reserved_maps,
  684. unsigned *num_maps, const char *group,
  685. unsigned long *configs, unsigned num_configs)
  686. {
  687. unsigned long *dup_configs;
  688. if (*num_maps == *reserved_maps)
  689. return -ENOSPC;
  690. dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
  691. GFP_KERNEL);
  692. if (!dup_configs)
  693. return -ENOMEM;
  694. (*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_PIN;
  695. (*map)[*num_maps].data.configs.group_or_pin = group;
  696. (*map)[*num_maps].data.configs.configs = dup_configs;
  697. (*map)[*num_maps].data.configs.num_configs = num_configs;
  698. (*num_maps)++;
  699. return 0;
  700. }
  701. static const char *abx500_find_pin_name(struct pinctrl_dev *pctldev,
  702. const char *pin_name)
  703. {
  704. int i, pin_number;
  705. struct abx500_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
  706. if (sscanf((char *)pin_name, "GPIO%d", &pin_number) == 1)
  707. for (i = 0; i < npct->soc->npins; i++)
  708. if (npct->soc->pins[i].number == pin_number)
  709. return npct->soc->pins[i].name;
  710. return NULL;
  711. }
  712. static int abx500_dt_subnode_to_map(struct pinctrl_dev *pctldev,
  713. struct device_node *np,
  714. struct pinctrl_map **map,
  715. unsigned *reserved_maps,
  716. unsigned *num_maps)
  717. {
  718. int ret;
  719. const char *function = NULL;
  720. unsigned long *configs;
  721. unsigned int nconfigs = 0;
  722. bool has_config = 0;
  723. unsigned reserve = 0;
  724. struct property *prop;
  725. const char *group, *gpio_name;
  726. struct device_node *np_config;
  727. ret = of_property_read_string(np, "ste,function", &function);
  728. if (ret >= 0)
  729. reserve = 1;
  730. ret = pinconf_generic_parse_dt_config(np, &configs, &nconfigs);
  731. if (nconfigs)
  732. has_config = 1;
  733. np_config = of_parse_phandle(np, "ste,config", 0);
  734. if (np_config) {
  735. ret = pinconf_generic_parse_dt_config(np_config, &configs,
  736. &nconfigs);
  737. if (ret)
  738. goto exit;
  739. has_config |= nconfigs;
  740. }
  741. ret = of_property_count_strings(np, "ste,pins");
  742. if (ret < 0)
  743. goto exit;
  744. if (has_config)
  745. reserve++;
  746. reserve *= ret;
  747. ret = abx500_dt_reserve_map(map, reserved_maps, num_maps, reserve);
  748. if (ret < 0)
  749. goto exit;
  750. of_property_for_each_string(np, "ste,pins", prop, group) {
  751. if (function) {
  752. ret = abx500_dt_add_map_mux(map, reserved_maps,
  753. num_maps, group, function);
  754. if (ret < 0)
  755. goto exit;
  756. }
  757. if (has_config) {
  758. gpio_name = abx500_find_pin_name(pctldev, group);
  759. ret = abx500_dt_add_map_configs(map, reserved_maps,
  760. num_maps, gpio_name, configs, 1);
  761. if (ret < 0)
  762. goto exit;
  763. }
  764. }
  765. exit:
  766. return ret;
  767. }
  768. static int abx500_dt_node_to_map(struct pinctrl_dev *pctldev,
  769. struct device_node *np_config,
  770. struct pinctrl_map **map, unsigned *num_maps)
  771. {
  772. unsigned reserved_maps;
  773. struct device_node *np;
  774. int ret;
  775. reserved_maps = 0;
  776. *map = NULL;
  777. *num_maps = 0;
  778. for_each_child_of_node(np_config, np) {
  779. ret = abx500_dt_subnode_to_map(pctldev, np, map,
  780. &reserved_maps, num_maps);
  781. if (ret < 0) {
  782. abx500_dt_free_map(pctldev, *map, *num_maps);
  783. return ret;
  784. }
  785. }
  786. return 0;
  787. }
  788. static const struct pinctrl_ops abx500_pinctrl_ops = {
  789. .get_groups_count = abx500_get_groups_cnt,
  790. .get_group_name = abx500_get_group_name,
  791. .get_group_pins = abx500_get_group_pins,
  792. .pin_dbg_show = abx500_pin_dbg_show,
  793. .dt_node_to_map = abx500_dt_node_to_map,
  794. .dt_free_map = abx500_dt_free_map,
  795. };
  796. static int abx500_pin_config_get(struct pinctrl_dev *pctldev,
  797. unsigned pin,
  798. unsigned long *config)
  799. {
  800. return -ENOSYS;
  801. }
  802. static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
  803. unsigned pin,
  804. unsigned long config)
  805. {
  806. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  807. struct pullud *pullud = pct->soc->pullud;
  808. struct gpio_chip *chip = &pct->chip;
  809. unsigned offset;
  810. int ret = 0;
  811. enum pin_config_param param = pinconf_to_config_param(config);
  812. enum pin_config_param argument = pinconf_to_config_argument(config);
  813. dev_dbg(chip->dev, "pin %d [%#lx]: %s %s\n",
  814. pin, config, (param == PIN_CONFIG_OUTPUT) ? "output " : "input",
  815. (param == PIN_CONFIG_OUTPUT) ? (argument ? "high" : "low") :
  816. (argument ? "pull up" : "pull down"));
  817. /* on ABx500, there is no GPIO0, so adjust the offset */
  818. offset = pin - 1;
  819. switch (param) {
  820. case PIN_CONFIG_BIAS_PULL_DOWN:
  821. /*
  822. * if argument = 1 set the pull down
  823. * else clear the pull down
  824. */
  825. ret = abx500_gpio_direction_input(chip, offset);
  826. /*
  827. * Some chips only support pull down, while some actually
  828. * support both pull up and pull down. Such chips have
  829. * a "pullud" range specified for the pins that support
  830. * both features. If the pin is not within that range, we
  831. * fall back to the old bit set that only support pull down.
  832. */
  833. if (pullud &&
  834. pin >= pullud->first_pin &&
  835. pin <= pullud->last_pin)
  836. ret = abx500_set_pull_updown(pct,
  837. pin,
  838. argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE);
  839. else
  840. /* Chip only supports pull down */
  841. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_PUD1_REG,
  842. offset, argument ? 0 : 1);
  843. break;
  844. case PIN_CONFIG_BIAS_PULL_UP:
  845. /*
  846. * if argument = 1 set the pull up
  847. * else clear the pull up
  848. */
  849. ret = abx500_gpio_direction_input(chip, offset);
  850. /*
  851. * Some chips only support pull down, while some actually
  852. * support both pull up and pull down. Such chips have
  853. * a "pullud" range specified for the pins that support
  854. * both features. If the pin is not within that range, do
  855. * nothing
  856. */
  857. if (pullud &&
  858. pin >= pullud->first_pin &&
  859. pin <= pullud->last_pin) {
  860. ret = abx500_set_pull_updown(pct,
  861. pin,
  862. argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE);
  863. }
  864. break;
  865. case PIN_CONFIG_OUTPUT:
  866. ret = abx500_gpio_direction_output(chip, offset, argument);
  867. break;
  868. default:
  869. dev_err(chip->dev, "illegal configuration requested\n");
  870. return -EINVAL;
  871. }
  872. return ret;
  873. }
  874. static const struct pinconf_ops abx500_pinconf_ops = {
  875. .pin_config_get = abx500_pin_config_get,
  876. .pin_config_set = abx500_pin_config_set,
  877. };
  878. static struct pinctrl_desc abx500_pinctrl_desc = {
  879. .name = "pinctrl-abx500",
  880. .pctlops = &abx500_pinctrl_ops,
  881. .pmxops = &abx500_pinmux_ops,
  882. .confops = &abx500_pinconf_ops,
  883. .owner = THIS_MODULE,
  884. };
  885. static int abx500_get_gpio_num(struct abx500_pinctrl_soc_data *soc)
  886. {
  887. unsigned int lowest = 0;
  888. unsigned int highest = 0;
  889. unsigned int npins = 0;
  890. int i;
  891. /*
  892. * Compute number of GPIOs from the last SoC gpio range descriptors
  893. * These ranges may include "holes" but the GPIO number space shall
  894. * still be homogeneous, so we need to detect and account for any
  895. * such holes so that these are included in the number of GPIO pins.
  896. */
  897. for (i = 0; i < soc->gpio_num_ranges; i++) {
  898. unsigned gstart;
  899. unsigned gend;
  900. const struct abx500_pinrange *p;
  901. p = &soc->gpio_ranges[i];
  902. gstart = p->offset;
  903. gend = p->offset + p->npins - 1;
  904. if (i == 0) {
  905. /* First iteration, set start values */
  906. lowest = gstart;
  907. highest = gend;
  908. } else {
  909. if (gstart < lowest)
  910. lowest = gstart;
  911. if (gend > highest)
  912. highest = gend;
  913. }
  914. }
  915. /* this gives the absolute number of pins */
  916. npins = highest - lowest + 1;
  917. return npins;
  918. }
  919. static const struct of_device_id abx500_gpio_match[] = {
  920. { .compatible = "stericsson,ab8500-gpio", .data = (void *)PINCTRL_AB8500, },
  921. { .compatible = "stericsson,ab8505-gpio", .data = (void *)PINCTRL_AB8505, },
  922. { .compatible = "stericsson,ab8540-gpio", .data = (void *)PINCTRL_AB8540, },
  923. { .compatible = "stericsson,ab9540-gpio", .data = (void *)PINCTRL_AB9540, },
  924. { }
  925. };
  926. static int abx500_gpio_probe(struct platform_device *pdev)
  927. {
  928. struct ab8500_platform_data *abx500_pdata =
  929. dev_get_platdata(pdev->dev.parent);
  930. struct abx500_gpio_platform_data *pdata = NULL;
  931. struct device_node *np = pdev->dev.of_node;
  932. struct abx500_pinctrl *pct;
  933. const struct platform_device_id *platid = platform_get_device_id(pdev);
  934. unsigned int id = -1;
  935. int ret, err;
  936. int i;
  937. if (abx500_pdata)
  938. pdata = abx500_pdata->gpio;
  939. if (!(pdata || np)) {
  940. dev_err(&pdev->dev, "gpio dt and platform data missing\n");
  941. return -ENODEV;
  942. }
  943. pct = devm_kzalloc(&pdev->dev, sizeof(struct abx500_pinctrl),
  944. GFP_KERNEL);
  945. if (pct == NULL) {
  946. dev_err(&pdev->dev,
  947. "failed to allocate memory for pct\n");
  948. return -ENOMEM;
  949. }
  950. pct->dev = &pdev->dev;
  951. pct->parent = dev_get_drvdata(pdev->dev.parent);
  952. pct->chip = abx500gpio_chip;
  953. pct->chip.dev = &pdev->dev;
  954. pct->chip.base = (np) ? -1 : pdata->gpio_base;
  955. if (platid)
  956. id = platid->driver_data;
  957. else if (np) {
  958. const struct of_device_id *match;
  959. match = of_match_device(abx500_gpio_match, &pdev->dev);
  960. if (match)
  961. id = (unsigned long)match->data;
  962. }
  963. /* Poke in other ASIC variants here */
  964. switch (id) {
  965. case PINCTRL_AB8500:
  966. abx500_pinctrl_ab8500_init(&pct->soc);
  967. break;
  968. case PINCTRL_AB8540:
  969. abx500_pinctrl_ab8540_init(&pct->soc);
  970. break;
  971. case PINCTRL_AB9540:
  972. abx500_pinctrl_ab9540_init(&pct->soc);
  973. break;
  974. case PINCTRL_AB8505:
  975. abx500_pinctrl_ab8505_init(&pct->soc);
  976. break;
  977. default:
  978. dev_err(&pdev->dev, "Unsupported pinctrl sub driver (%d)\n", id);
  979. return -EINVAL;
  980. }
  981. if (!pct->soc) {
  982. dev_err(&pdev->dev, "Invalid SOC data\n");
  983. return -EINVAL;
  984. }
  985. pct->chip.ngpio = abx500_get_gpio_num(pct->soc);
  986. pct->irq_cluster = pct->soc->gpio_irq_cluster;
  987. pct->irq_cluster_size = pct->soc->ngpio_irq_cluster;
  988. ret = gpiochip_add(&pct->chip);
  989. if (ret) {
  990. dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
  991. return ret;
  992. }
  993. dev_info(&pdev->dev, "added gpiochip\n");
  994. abx500_pinctrl_desc.pins = pct->soc->pins;
  995. abx500_pinctrl_desc.npins = pct->soc->npins;
  996. pct->pctldev = pinctrl_register(&abx500_pinctrl_desc, &pdev->dev, pct);
  997. if (!pct->pctldev) {
  998. dev_err(&pdev->dev,
  999. "could not register abx500 pinctrl driver\n");
  1000. ret = -EINVAL;
  1001. goto out_rem_chip;
  1002. }
  1003. dev_info(&pdev->dev, "registered pin controller\n");
  1004. /* We will handle a range of GPIO pins */
  1005. for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
  1006. const struct abx500_pinrange *p = &pct->soc->gpio_ranges[i];
  1007. ret = gpiochip_add_pin_range(&pct->chip,
  1008. dev_name(&pdev->dev),
  1009. p->offset - 1, p->offset, p->npins);
  1010. if (ret < 0)
  1011. goto out_rem_chip;
  1012. }
  1013. platform_set_drvdata(pdev, pct);
  1014. dev_info(&pdev->dev, "initialized abx500 pinctrl driver\n");
  1015. return 0;
  1016. out_rem_chip:
  1017. err = gpiochip_remove(&pct->chip);
  1018. if (err)
  1019. dev_info(&pdev->dev, "failed to remove gpiochip\n");
  1020. return ret;
  1021. }
  1022. /**
  1023. * abx500_gpio_remove() - remove Ab8500-gpio driver
  1024. * @pdev: Platform device registered
  1025. */
  1026. static int abx500_gpio_remove(struct platform_device *pdev)
  1027. {
  1028. struct abx500_pinctrl *pct = platform_get_drvdata(pdev);
  1029. int ret;
  1030. ret = gpiochip_remove(&pct->chip);
  1031. if (ret < 0) {
  1032. dev_err(pct->dev, "unable to remove gpiochip: %d\n",
  1033. ret);
  1034. return ret;
  1035. }
  1036. return 0;
  1037. }
  1038. static const struct platform_device_id abx500_pinctrl_id[] = {
  1039. { "pinctrl-ab8500", PINCTRL_AB8500 },
  1040. { "pinctrl-ab8540", PINCTRL_AB8540 },
  1041. { "pinctrl-ab9540", PINCTRL_AB9540 },
  1042. { "pinctrl-ab8505", PINCTRL_AB8505 },
  1043. { },
  1044. };
  1045. static struct platform_driver abx500_gpio_driver = {
  1046. .driver = {
  1047. .name = "abx500-gpio",
  1048. .owner = THIS_MODULE,
  1049. .of_match_table = abx500_gpio_match,
  1050. },
  1051. .probe = abx500_gpio_probe,
  1052. .remove = abx500_gpio_remove,
  1053. .id_table = abx500_pinctrl_id,
  1054. };
  1055. static int __init abx500_gpio_init(void)
  1056. {
  1057. return platform_driver_register(&abx500_gpio_driver);
  1058. }
  1059. core_initcall(abx500_gpio_init);
  1060. MODULE_AUTHOR("Patrice Chotard <patrice.chotard@st.com>");
  1061. MODULE_DESCRIPTION("Driver allows to use AxB5xx unused pins to be used as GPIO");
  1062. MODULE_ALIAS("platform:abx500-gpio");
  1063. MODULE_LICENSE("GPL v2");