pinctrl-abx500.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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, 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. return -ENOSYS;
  838. }
  839. int abx500_pin_config_set(struct pinctrl_dev *pctldev,
  840. unsigned pin,
  841. unsigned long config)
  842. {
  843. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  844. struct pullud *pullud = pct->soc->pullud;
  845. struct gpio_chip *chip = &pct->chip;
  846. unsigned offset;
  847. int ret;
  848. enum pin_config_param param = pinconf_to_config_param(config);
  849. enum pin_config_param argument = pinconf_to_config_argument(config);
  850. dev_dbg(chip->dev, "pin %d [%#lx]: %s %s\n",
  851. pin, config, (param == PIN_CONFIG_OUTPUT) ? "output " : "input",
  852. (param == PIN_CONFIG_OUTPUT) ? (argument ? "high" : "low") :
  853. (argument ? "pull up" : "pull down"));
  854. /* on ABx500, there is no GPIO0, so adjust the offset */
  855. offset = pin - 1;
  856. switch (param) {
  857. case PIN_CONFIG_BIAS_PULL_DOWN:
  858. /*
  859. * if argument = 1 set the pull down
  860. * else clear the pull down
  861. */
  862. ret = abx500_gpio_direction_input(chip, offset);
  863. /*
  864. * Some chips only support pull down, while some actually
  865. * support both pull up and pull down. Such chips have
  866. * a "pullud" range specified for the pins that support
  867. * both features. If the pin is not within that range, we
  868. * fall back to the old bit set that only support pull down.
  869. */
  870. if (pullud &&
  871. pin >= pullud->first_pin &&
  872. pin <= pullud->last_pin)
  873. ret = abx500_config_pull_updown(pct,
  874. pin,
  875. argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE);
  876. else
  877. /* Chip only supports pull down */
  878. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_PUD1_REG,
  879. offset, argument ? 0 : 1);
  880. break;
  881. case PIN_CONFIG_OUTPUT:
  882. ret = abx500_gpio_direction_output(chip, offset, argument);
  883. break;
  884. default:
  885. dev_err(chip->dev, "illegal configuration requested\n");
  886. return -EINVAL;
  887. }
  888. return ret;
  889. }
  890. static struct pinconf_ops abx500_pinconf_ops = {
  891. .pin_config_get = abx500_pin_config_get,
  892. .pin_config_set = abx500_pin_config_set,
  893. };
  894. static struct pinctrl_desc abx500_pinctrl_desc = {
  895. .name = "pinctrl-abx500",
  896. .pctlops = &abx500_pinctrl_ops,
  897. .pmxops = &abx500_pinmux_ops,
  898. .confops = &abx500_pinconf_ops,
  899. .owner = THIS_MODULE,
  900. };
  901. static int abx500_get_gpio_num(struct abx500_pinctrl_soc_data *soc)
  902. {
  903. unsigned int lowest = 0;
  904. unsigned int highest = 0;
  905. unsigned int npins = 0;
  906. int i;
  907. /*
  908. * Compute number of GPIOs from the last SoC gpio range descriptors
  909. * These ranges may include "holes" but the GPIO number space shall
  910. * still be homogeneous, so we need to detect and account for any
  911. * such holes so that these are included in the number of GPIO pins.
  912. */
  913. for (i = 0; i < soc->gpio_num_ranges; i++) {
  914. unsigned gstart;
  915. unsigned gend;
  916. const struct abx500_pinrange *p;
  917. p = &soc->gpio_ranges[i];
  918. gstart = p->offset;
  919. gend = p->offset + p->npins - 1;
  920. if (i == 0) {
  921. /* First iteration, set start values */
  922. lowest = gstart;
  923. highest = gend;
  924. } else {
  925. if (gstart < lowest)
  926. lowest = gstart;
  927. if (gend > highest)
  928. highest = gend;
  929. }
  930. }
  931. /* this gives the absolute number of pins */
  932. npins = highest - lowest + 1;
  933. return npins;
  934. }
  935. static int abx500_gpio_probe(struct platform_device *pdev)
  936. {
  937. struct ab8500_platform_data *abx500_pdata =
  938. dev_get_platdata(pdev->dev.parent);
  939. struct abx500_gpio_platform_data *pdata;
  940. struct abx500_pinctrl *pct;
  941. const struct platform_device_id *platid = platform_get_device_id(pdev);
  942. int ret;
  943. int i;
  944. pdata = abx500_pdata->gpio;
  945. if (!pdata) {
  946. dev_err(&pdev->dev, "gpio platform data missing\n");
  947. return -ENODEV;
  948. }
  949. pct = devm_kzalloc(&pdev->dev, sizeof(struct abx500_pinctrl),
  950. GFP_KERNEL);
  951. if (pct == NULL) {
  952. dev_err(&pdev->dev,
  953. "failed to allocate memory for pct\n");
  954. return -ENOMEM;
  955. }
  956. pct->dev = &pdev->dev;
  957. pct->parent = dev_get_drvdata(pdev->dev.parent);
  958. pct->chip = abx500gpio_chip;
  959. pct->chip.dev = &pdev->dev;
  960. pct->chip.base = pdata->gpio_base;
  961. pct->irq_base = pdata->irq_base;
  962. /* initialize the lock */
  963. mutex_init(&pct->lock);
  964. /* Poke in other ASIC variants here */
  965. switch (platid->driver_data) {
  966. case PINCTRL_AB8500:
  967. abx500_pinctrl_ab8500_init(&pct->soc);
  968. break;
  969. case PINCTRL_AB8540:
  970. abx500_pinctrl_ab8540_init(&pct->soc);
  971. break;
  972. case PINCTRL_AB9540:
  973. abx500_pinctrl_ab9540_init(&pct->soc);
  974. break;
  975. case PINCTRL_AB8505:
  976. abx500_pinctrl_ab8505_init(&pct->soc);
  977. break;
  978. default:
  979. dev_err(&pdev->dev, "Unsupported pinctrl sub driver (%d)\n",
  980. (int) platid->driver_data);
  981. return -EINVAL;
  982. }
  983. if (!pct->soc) {
  984. dev_err(&pdev->dev, "Invalid SOC data\n");
  985. return -EINVAL;
  986. }
  987. pct->chip.ngpio = abx500_get_gpio_num(pct->soc);
  988. pct->irq_cluster = pct->soc->gpio_irq_cluster;
  989. pct->irq_cluster_size = pct->soc->ngpio_irq_cluster;
  990. pct->irq_gpio_rising_offset = pct->soc->irq_gpio_rising_offset;
  991. pct->irq_gpio_falling_offset = pct->soc->irq_gpio_falling_offset;
  992. pct->irq_gpio_factor = pct->soc->irq_gpio_factor;
  993. ret = abx500_gpio_irq_init(pct);
  994. if (ret)
  995. goto out_free;
  996. ret = gpiochip_add(&pct->chip);
  997. if (ret) {
  998. dev_err(&pdev->dev, "unable to add gpiochip: %d\n",
  999. ret);
  1000. goto out_rem_irq;
  1001. }
  1002. dev_info(&pdev->dev, "added gpiochip\n");
  1003. abx500_pinctrl_desc.pins = pct->soc->pins;
  1004. abx500_pinctrl_desc.npins = pct->soc->npins;
  1005. pct->pctldev = pinctrl_register(&abx500_pinctrl_desc, &pdev->dev, pct);
  1006. if (!pct->pctldev) {
  1007. dev_err(&pdev->dev,
  1008. "could not register abx500 pinctrl driver\n");
  1009. goto out_rem_chip;
  1010. }
  1011. dev_info(&pdev->dev, "registered pin controller\n");
  1012. /* We will handle a range of GPIO pins */
  1013. for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
  1014. const struct abx500_pinrange *p = &pct->soc->gpio_ranges[i];
  1015. ret = gpiochip_add_pin_range(&pct->chip,
  1016. dev_name(&pdev->dev),
  1017. p->offset - 1, p->offset, p->npins);
  1018. if (ret < 0)
  1019. return ret;
  1020. }
  1021. platform_set_drvdata(pdev, pct);
  1022. dev_info(&pdev->dev, "initialized abx500 pinctrl driver\n");
  1023. return 0;
  1024. out_rem_chip:
  1025. ret = gpiochip_remove(&pct->chip);
  1026. if (ret)
  1027. dev_info(&pdev->dev, "failed to remove gpiochip\n");
  1028. out_rem_irq:
  1029. abx500_gpio_irq_remove(pct);
  1030. out_free:
  1031. mutex_destroy(&pct->lock);
  1032. return ret;
  1033. }
  1034. /*
  1035. * abx500_gpio_remove() - remove Ab8500-gpio driver
  1036. * @pdev : Platform device registered
  1037. */
  1038. static int abx500_gpio_remove(struct platform_device *pdev)
  1039. {
  1040. struct abx500_pinctrl *pct = platform_get_drvdata(pdev);
  1041. int ret;
  1042. ret = gpiochip_remove(&pct->chip);
  1043. if (ret < 0) {
  1044. dev_err(pct->dev, "unable to remove gpiochip: %d\n",
  1045. ret);
  1046. return ret;
  1047. }
  1048. mutex_destroy(&pct->lock);
  1049. return 0;
  1050. }
  1051. static const struct platform_device_id abx500_pinctrl_id[] = {
  1052. { "pinctrl-ab8500", PINCTRL_AB8500 },
  1053. { "pinctrl-ab8540", PINCTRL_AB8540 },
  1054. { "pinctrl-ab9540", PINCTRL_AB9540 },
  1055. { "pinctrl-ab8505", PINCTRL_AB8505 },
  1056. { },
  1057. };
  1058. static struct platform_driver abx500_gpio_driver = {
  1059. .driver = {
  1060. .name = "abx500-gpio",
  1061. .owner = THIS_MODULE,
  1062. },
  1063. .probe = abx500_gpio_probe,
  1064. .remove = abx500_gpio_remove,
  1065. .id_table = abx500_pinctrl_id,
  1066. };
  1067. static int __init abx500_gpio_init(void)
  1068. {
  1069. return platform_driver_register(&abx500_gpio_driver);
  1070. }
  1071. core_initcall(abx500_gpio_init);
  1072. MODULE_AUTHOR("Patrice Chotard <patrice.chotard@st.com>");
  1073. MODULE_DESCRIPTION("Driver allows to use AxB5xx unused pins to be used as GPIO");
  1074. MODULE_ALIAS("platform:abx500-gpio");
  1075. MODULE_LICENSE("GPL v2");