pinctrl-abx500.c 31 KB

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