pinctrl-abx500.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  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, BIT(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,
  401. struct gpio_chip *chip,
  402. unsigned offset, unsigned gpio)
  403. {
  404. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  405. const char *label = gpiochip_is_requested(chip, offset - 1);
  406. u8 gpio_offset = offset - 1;
  407. int mode = -1;
  408. bool is_out;
  409. bool pull;
  410. const char *modes[] = {
  411. [ABX500_DEFAULT] = "default",
  412. [ABX500_ALT_A] = "altA",
  413. [ABX500_ALT_B] = "altB",
  414. [ABX500_ALT_C] = "altC",
  415. };
  416. abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, gpio_offset, &is_out);
  417. abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG, gpio_offset, &pull);
  418. if (pctldev)
  419. mode = abx500_get_mode(pctldev, chip, offset);
  420. seq_printf(s, " gpio-%-3d (%-20.20s) %-3s %-9s %s",
  421. gpio, label ?: "(none)",
  422. is_out ? "out" : "in ",
  423. is_out ?
  424. (chip->get
  425. ? (chip->get(chip, offset) ? "hi" : "lo")
  426. : "? ")
  427. : (pull ? "pull up" : "pull down"),
  428. (mode < 0) ? "unknown" : modes[mode]);
  429. if (label && !is_out) {
  430. int irq = gpio_to_irq(gpio);
  431. struct irq_desc *desc = irq_to_desc(irq);
  432. if (irq >= 0 && desc->action) {
  433. char *trigger;
  434. int irq_offset = irq - pct->irq_base;
  435. if (pct->rising & BIT(irq_offset))
  436. trigger = "edge-rising";
  437. else if (pct->falling & BIT(irq_offset))
  438. trigger = "edge-falling";
  439. else
  440. trigger = "edge-undefined";
  441. seq_printf(s, " irq-%d %s", irq, trigger);
  442. }
  443. }
  444. }
  445. static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  446. {
  447. unsigned i;
  448. unsigned gpio = chip->base;
  449. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  450. struct pinctrl_dev *pctldev = pct->pctldev;
  451. for (i = 0; i < chip->ngpio; i++, gpio++) {
  452. /* On AB8500, there is no GPIO0, the first is the GPIO 1 */
  453. abx500_gpio_dbg_show_one(s, pctldev, chip, i + 1, gpio);
  454. seq_printf(s, "\n");
  455. }
  456. }
  457. #else
  458. static inline void abx500_gpio_dbg_show_one(struct seq_file *s,
  459. struct pinctrl_dev *pctldev,
  460. struct gpio_chip *chip,
  461. unsigned offset, unsigned gpio)
  462. {
  463. }
  464. #define abx500_gpio_dbg_show NULL
  465. #endif
  466. int abx500_gpio_request(struct gpio_chip *chip, unsigned offset)
  467. {
  468. int gpio = chip->base + offset;
  469. return pinctrl_request_gpio(gpio);
  470. }
  471. void abx500_gpio_free(struct gpio_chip *chip, unsigned offset)
  472. {
  473. int gpio = chip->base + offset;
  474. pinctrl_free_gpio(gpio);
  475. }
  476. static struct gpio_chip abx500gpio_chip = {
  477. .label = "abx500-gpio",
  478. .owner = THIS_MODULE,
  479. .request = abx500_gpio_request,
  480. .free = abx500_gpio_free,
  481. .direction_input = abx500_gpio_direction_input,
  482. .get = abx500_gpio_get,
  483. .direction_output = abx500_gpio_direction_output,
  484. .set = abx500_gpio_set,
  485. .to_irq = abx500_gpio_to_irq,
  486. .dbg_show = abx500_gpio_dbg_show,
  487. };
  488. static unsigned int irq_to_rising(unsigned int irq)
  489. {
  490. struct abx500_pinctrl *pct = irq_get_chip_data(irq);
  491. int offset = irq - pct->irq_base;
  492. int new_irq;
  493. new_irq = offset * pct->irq_gpio_factor
  494. + pct->irq_gpio_rising_offset
  495. + pct->parent->irq_base;
  496. return new_irq;
  497. }
  498. static unsigned int irq_to_falling(unsigned int irq)
  499. {
  500. struct abx500_pinctrl *pct = irq_get_chip_data(irq);
  501. int offset = irq - pct->irq_base;
  502. int new_irq;
  503. new_irq = offset * pct->irq_gpio_factor
  504. + pct->irq_gpio_falling_offset
  505. + pct->parent->irq_base;
  506. return new_irq;
  507. }
  508. static unsigned int rising_to_irq(unsigned int irq, void *dev)
  509. {
  510. struct abx500_pinctrl *pct = dev;
  511. int offset, new_irq;
  512. offset = irq - pct->irq_gpio_rising_offset
  513. - pct->parent->irq_base;
  514. new_irq = (offset / pct->irq_gpio_factor)
  515. + pct->irq_base;
  516. return new_irq;
  517. }
  518. static unsigned int falling_to_irq(unsigned int irq, void *dev)
  519. {
  520. struct abx500_pinctrl *pct = dev;
  521. int offset, new_irq;
  522. offset = irq - pct->irq_gpio_falling_offset
  523. - pct->parent->irq_base;
  524. new_irq = (offset / pct->irq_gpio_factor)
  525. + pct->irq_base;
  526. return new_irq;
  527. }
  528. /*
  529. * IRQ handler
  530. */
  531. static irqreturn_t handle_rising(int irq, void *dev)
  532. {
  533. handle_nested_irq(rising_to_irq(irq , dev));
  534. return IRQ_HANDLED;
  535. }
  536. static irqreturn_t handle_falling(int irq, void *dev)
  537. {
  538. handle_nested_irq(falling_to_irq(irq, dev));
  539. return IRQ_HANDLED;
  540. }
  541. static void abx500_gpio_irq_lock(struct irq_data *data)
  542. {
  543. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  544. mutex_lock(&pct->lock);
  545. }
  546. static void abx500_gpio_irq_sync_unlock(struct irq_data *data)
  547. {
  548. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  549. unsigned int irq = data->irq;
  550. int offset = irq - pct->irq_base;
  551. bool rising = pct->rising & BIT(offset);
  552. bool falling = pct->falling & BIT(offset);
  553. int ret;
  554. switch (pct->irq_action) {
  555. case STARTUP:
  556. if (rising)
  557. ret = request_threaded_irq(irq_to_rising(irq),
  558. NULL, handle_rising,
  559. IRQF_TRIGGER_RISING | IRQF_NO_SUSPEND,
  560. "abx500-gpio-r", pct);
  561. if (falling)
  562. ret = request_threaded_irq(irq_to_falling(irq),
  563. NULL, handle_falling,
  564. IRQF_TRIGGER_FALLING | IRQF_NO_SUSPEND,
  565. "abx500-gpio-f", pct);
  566. break;
  567. case SHUTDOWN:
  568. if (rising)
  569. free_irq(irq_to_rising(irq), pct);
  570. if (falling)
  571. free_irq(irq_to_falling(irq), pct);
  572. break;
  573. case MASK:
  574. if (rising)
  575. disable_irq(irq_to_rising(irq));
  576. if (falling)
  577. disable_irq(irq_to_falling(irq));
  578. break;
  579. case UNMASK:
  580. if (rising)
  581. enable_irq(irq_to_rising(irq));
  582. if (falling)
  583. enable_irq(irq_to_falling(irq));
  584. break;
  585. case NONE:
  586. break;
  587. }
  588. pct->irq_action = NONE;
  589. pct->rising &= ~(BIT(offset));
  590. pct->falling &= ~(BIT(offset));
  591. mutex_unlock(&pct->lock);
  592. }
  593. static void abx500_gpio_irq_mask(struct irq_data *data)
  594. {
  595. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  596. pct->irq_action = MASK;
  597. }
  598. static void abx500_gpio_irq_unmask(struct irq_data *data)
  599. {
  600. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  601. pct->irq_action = UNMASK;
  602. }
  603. static int abx500_gpio_irq_set_type(struct irq_data *data, unsigned int type)
  604. {
  605. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  606. unsigned int irq = data->irq;
  607. int offset = irq - pct->irq_base;
  608. if (type == IRQ_TYPE_EDGE_BOTH) {
  609. pct->rising = BIT(offset);
  610. pct->falling = BIT(offset);
  611. } else if (type == IRQ_TYPE_EDGE_RISING) {
  612. pct->rising = BIT(offset);
  613. } else {
  614. pct->falling = BIT(offset);
  615. }
  616. return 0;
  617. }
  618. static unsigned int abx500_gpio_irq_startup(struct irq_data *data)
  619. {
  620. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  621. pct->irq_action = STARTUP;
  622. return 0;
  623. }
  624. static void abx500_gpio_irq_shutdown(struct irq_data *data)
  625. {
  626. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  627. pct->irq_action = SHUTDOWN;
  628. }
  629. static struct irq_chip abx500_gpio_irq_chip = {
  630. .name = "abx500-gpio",
  631. .irq_startup = abx500_gpio_irq_startup,
  632. .irq_shutdown = abx500_gpio_irq_shutdown,
  633. .irq_bus_lock = abx500_gpio_irq_lock,
  634. .irq_bus_sync_unlock = abx500_gpio_irq_sync_unlock,
  635. .irq_mask = abx500_gpio_irq_mask,
  636. .irq_unmask = abx500_gpio_irq_unmask,
  637. .irq_set_type = abx500_gpio_irq_set_type,
  638. };
  639. static int abx500_gpio_irq_init(struct abx500_pinctrl *pct)
  640. {
  641. u32 base = pct->irq_base;
  642. int irq;
  643. for (irq = base; irq < base + AB8500_NUM_VIR_GPIO_IRQ ; irq++) {
  644. irq_set_chip_data(irq, pct);
  645. irq_set_chip_and_handler(irq, &abx500_gpio_irq_chip,
  646. handle_simple_irq);
  647. irq_set_nested_thread(irq, 1);
  648. #ifdef CONFIG_ARM
  649. set_irq_flags(irq, IRQF_VALID);
  650. #else
  651. irq_set_noprobe(irq);
  652. #endif
  653. }
  654. return 0;
  655. }
  656. static void abx500_gpio_irq_remove(struct abx500_pinctrl *pct)
  657. {
  658. int base = pct->irq_base;
  659. int irq;
  660. for (irq = base; irq < base + AB8500_NUM_VIR_GPIO_IRQ; irq++) {
  661. #ifdef CONFIG_ARM
  662. set_irq_flags(irq, 0);
  663. #endif
  664. irq_set_chip_and_handler(irq, NULL, NULL);
  665. irq_set_chip_data(irq, NULL);
  666. }
  667. }
  668. static int abx500_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev)
  669. {
  670. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  671. return pct->soc->nfunctions;
  672. }
  673. static const char *abx500_pmx_get_func_name(struct pinctrl_dev *pctldev,
  674. unsigned function)
  675. {
  676. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  677. return pct->soc->functions[function].name;
  678. }
  679. static int abx500_pmx_get_func_groups(struct pinctrl_dev *pctldev,
  680. unsigned function,
  681. const char * const **groups,
  682. unsigned * const num_groups)
  683. {
  684. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  685. *groups = pct->soc->functions[function].groups;
  686. *num_groups = pct->soc->functions[function].ngroups;
  687. return 0;
  688. }
  689. static void abx500_disable_lazy_irq(struct gpio_chip *chip, unsigned gpio)
  690. {
  691. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  692. int irq;
  693. int offset;
  694. bool rising;
  695. bool falling;
  696. /*
  697. * check if gpio has interrupt capability and convert
  698. * gpio number to irq
  699. * On ABx5xx, there is no GPIO0, GPIO1 is the
  700. * first one, so adjust gpio number
  701. */
  702. gpio--;
  703. irq = gpio_to_irq(gpio + chip->base);
  704. if (irq < 0)
  705. return;
  706. offset = irq - pct->irq_base;
  707. rising = pct->rising & BIT(offset);
  708. falling = pct->falling & BIT(offset);
  709. /* nothing to do ?*/
  710. if (!rising && !falling)
  711. return;
  712. if (rising) {
  713. disable_irq(irq_to_rising(irq));
  714. free_irq(irq_to_rising(irq), pct);
  715. }
  716. if (falling) {
  717. disable_irq(irq_to_falling(irq));
  718. free_irq(irq_to_falling(irq), pct);
  719. }
  720. }
  721. static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
  722. unsigned group)
  723. {
  724. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  725. struct gpio_chip *chip = &pct->chip;
  726. const struct abx500_pingroup *g;
  727. int i;
  728. int ret = 0;
  729. g = &pct->soc->groups[group];
  730. if (g->altsetting < 0)
  731. return -EINVAL;
  732. dev_dbg(pct->dev, "enable group %s, %u pins\n", g->name, g->npins);
  733. for (i = 0; i < g->npins; i++) {
  734. dev_dbg(pct->dev, "setting pin %d to altsetting %d\n",
  735. g->pins[i], g->altsetting);
  736. abx500_disable_lazy_irq(chip, g->pins[i]);
  737. ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting);
  738. }
  739. return ret;
  740. }
  741. static void abx500_pmx_disable(struct pinctrl_dev *pctldev,
  742. unsigned function, unsigned group)
  743. {
  744. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  745. const struct abx500_pingroup *g;
  746. g = &pct->soc->groups[group];
  747. if (g->altsetting < 0)
  748. return;
  749. /* FIXME: poke out the mux, set the pin to some default state? */
  750. dev_dbg(pct->dev, "disable group %s, %u pins\n", g->name, g->npins);
  751. }
  752. int abx500_gpio_request_enable(struct pinctrl_dev *pctldev,
  753. struct pinctrl_gpio_range *range,
  754. unsigned offset)
  755. {
  756. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  757. const struct abx500_pinrange *p;
  758. int ret;
  759. int i;
  760. /*
  761. * Different ranges have different ways to enable GPIO function on a
  762. * pin, so refer back to our local range type, where we handily define
  763. * what altfunc enables GPIO for a certain pin.
  764. */
  765. for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
  766. p = &pct->soc->gpio_ranges[i];
  767. if ((offset >= p->offset) &&
  768. (offset < (p->offset + p->npins)))
  769. break;
  770. }
  771. if (i == pct->soc->gpio_num_ranges) {
  772. dev_err(pct->dev, "%s failed to locate range\n", __func__);
  773. return -ENODEV;
  774. }
  775. dev_dbg(pct->dev, "enable GPIO by altfunc %d at gpio %d\n",
  776. p->altfunc, offset);
  777. ret = abx500_set_mode(pct->pctldev, &pct->chip,
  778. offset, p->altfunc);
  779. if (ret < 0) {
  780. dev_err(pct->dev, "%s setting altfunc failed\n", __func__);
  781. return ret;
  782. }
  783. return ret;
  784. }
  785. static void abx500_gpio_disable_free(struct pinctrl_dev *pctldev,
  786. struct pinctrl_gpio_range *range,
  787. unsigned offset)
  788. {
  789. }
  790. static struct pinmux_ops abx500_pinmux_ops = {
  791. .get_functions_count = abx500_pmx_get_funcs_cnt,
  792. .get_function_name = abx500_pmx_get_func_name,
  793. .get_function_groups = abx500_pmx_get_func_groups,
  794. .enable = abx500_pmx_enable,
  795. .disable = abx500_pmx_disable,
  796. .gpio_request_enable = abx500_gpio_request_enable,
  797. .gpio_disable_free = abx500_gpio_disable_free,
  798. };
  799. static int abx500_get_groups_cnt(struct pinctrl_dev *pctldev)
  800. {
  801. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  802. return pct->soc->ngroups;
  803. }
  804. static const char *abx500_get_group_name(struct pinctrl_dev *pctldev,
  805. unsigned selector)
  806. {
  807. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  808. return pct->soc->groups[selector].name;
  809. }
  810. static int abx500_get_group_pins(struct pinctrl_dev *pctldev,
  811. unsigned selector,
  812. const unsigned **pins,
  813. unsigned *num_pins)
  814. {
  815. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  816. *pins = pct->soc->groups[selector].pins;
  817. *num_pins = pct->soc->groups[selector].npins;
  818. return 0;
  819. }
  820. static void abx500_pin_dbg_show(struct pinctrl_dev *pctldev,
  821. struct seq_file *s, unsigned offset)
  822. {
  823. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  824. struct gpio_chip *chip = &pct->chip;
  825. abx500_gpio_dbg_show_one(s, pctldev, chip, offset,
  826. chip->base + offset - 1);
  827. }
  828. static struct pinctrl_ops abx500_pinctrl_ops = {
  829. .get_groups_count = abx500_get_groups_cnt,
  830. .get_group_name = abx500_get_group_name,
  831. .get_group_pins = abx500_get_group_pins,
  832. .pin_dbg_show = abx500_pin_dbg_show,
  833. };
  834. int abx500_pin_config_get(struct pinctrl_dev *pctldev,
  835. unsigned pin,
  836. unsigned long *config)
  837. {
  838. return -ENOSYS;
  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_AB8540:
  971. abx500_pinctrl_ab8540_init(&pct->soc);
  972. break;
  973. case PINCTRL_AB9540:
  974. abx500_pinctrl_ab9540_init(&pct->soc);
  975. break;
  976. case PINCTRL_AB8505:
  977. abx500_pinctrl_ab8505_init(&pct->soc);
  978. break;
  979. default:
  980. dev_err(&pdev->dev, "Unsupported pinctrl sub driver (%d)\n",
  981. (int) platid->driver_data);
  982. mutex_destroy(&pct->lock);
  983. return -EINVAL;
  984. }
  985. if (!pct->soc) {
  986. dev_err(&pdev->dev, "Invalid SOC data\n");
  987. mutex_destroy(&pct->lock);
  988. return -EINVAL;
  989. }
  990. pct->chip.ngpio = abx500_get_gpio_num(pct->soc);
  991. pct->irq_cluster = pct->soc->gpio_irq_cluster;
  992. pct->irq_cluster_size = pct->soc->ngpio_irq_cluster;
  993. pct->irq_gpio_rising_offset = pct->soc->irq_gpio_rising_offset;
  994. pct->irq_gpio_falling_offset = pct->soc->irq_gpio_falling_offset;
  995. pct->irq_gpio_factor = pct->soc->irq_gpio_factor;
  996. ret = abx500_gpio_irq_init(pct);
  997. if (ret)
  998. goto out_free;
  999. ret = gpiochip_add(&pct->chip);
  1000. if (ret) {
  1001. dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
  1002. mutex_destroy(&pct->lock);
  1003. goto out_rem_irq;
  1004. }
  1005. dev_info(&pdev->dev, "added gpiochip\n");
  1006. abx500_pinctrl_desc.pins = pct->soc->pins;
  1007. abx500_pinctrl_desc.npins = pct->soc->npins;
  1008. pct->pctldev = pinctrl_register(&abx500_pinctrl_desc, &pdev->dev, pct);
  1009. if (!pct->pctldev) {
  1010. dev_err(&pdev->dev,
  1011. "could not register abx500 pinctrl driver\n");
  1012. goto out_rem_chip;
  1013. }
  1014. dev_info(&pdev->dev, "registered pin controller\n");
  1015. /* We will handle a range of GPIO pins */
  1016. for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
  1017. const struct abx500_pinrange *p = &pct->soc->gpio_ranges[i];
  1018. ret = gpiochip_add_pin_range(&pct->chip,
  1019. dev_name(&pdev->dev),
  1020. p->offset - 1, p->offset, p->npins);
  1021. if (ret < 0)
  1022. return ret;
  1023. }
  1024. platform_set_drvdata(pdev, pct);
  1025. dev_info(&pdev->dev, "initialized abx500 pinctrl driver\n");
  1026. return 0;
  1027. out_rem_chip:
  1028. ret = gpiochip_remove(&pct->chip);
  1029. if (ret)
  1030. dev_info(&pdev->dev, "failed to remove gpiochip\n");
  1031. out_rem_irq:
  1032. abx500_gpio_irq_remove(pct);
  1033. out_free:
  1034. mutex_destroy(&pct->lock);
  1035. return ret;
  1036. }
  1037. /**
  1038. * abx500_gpio_remove() - remove Ab8500-gpio driver
  1039. * @pdev: Platform device registered
  1040. */
  1041. static int abx500_gpio_remove(struct platform_device *pdev)
  1042. {
  1043. struct abx500_pinctrl *pct = platform_get_drvdata(pdev);
  1044. int ret;
  1045. ret = gpiochip_remove(&pct->chip);
  1046. if (ret < 0) {
  1047. dev_err(pct->dev, "unable to remove gpiochip: %d\n",
  1048. ret);
  1049. return ret;
  1050. }
  1051. mutex_destroy(&pct->lock);
  1052. return 0;
  1053. }
  1054. static const struct platform_device_id abx500_pinctrl_id[] = {
  1055. { "pinctrl-ab8500", PINCTRL_AB8500 },
  1056. { "pinctrl-ab8540", PINCTRL_AB8540 },
  1057. { "pinctrl-ab9540", PINCTRL_AB9540 },
  1058. { "pinctrl-ab8505", PINCTRL_AB8505 },
  1059. { },
  1060. };
  1061. static struct platform_driver abx500_gpio_driver = {
  1062. .driver = {
  1063. .name = "abx500-gpio",
  1064. .owner = THIS_MODULE,
  1065. },
  1066. .probe = abx500_gpio_probe,
  1067. .remove = abx500_gpio_remove,
  1068. .id_table = abx500_pinctrl_id,
  1069. };
  1070. static int __init abx500_gpio_init(void)
  1071. {
  1072. return platform_driver_register(&abx500_gpio_driver);
  1073. }
  1074. core_initcall(abx500_gpio_init);
  1075. MODULE_AUTHOR("Patrice Chotard <patrice.chotard@st.com>");
  1076. MODULE_DESCRIPTION("Driver allows to use AxB5xx unused pins to be used as GPIO");
  1077. MODULE_ALIAS("platform:abx500-gpio");
  1078. MODULE_LICENSE("GPL v2");