pinctrl-abx500.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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. /* The AB8500 GPIO numbers are off by one */
  238. int gpio = offset + 1;
  239. int base = pct->irq_base;
  240. int i;
  241. for (i = 0; i < pct->irq_cluster_size; i++) {
  242. struct abx500_gpio_irq_cluster *cluster =
  243. &pct->irq_cluster[i];
  244. if (gpio >= cluster->start && gpio <= cluster->end)
  245. return base + gpio - cluster->start;
  246. /* Advance by the number of gpios in this cluster */
  247. base += cluster->end + cluster->offset - cluster->start + 1;
  248. }
  249. return -EINVAL;
  250. }
  251. static int abx500_set_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
  252. unsigned gpio, int alt_setting)
  253. {
  254. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  255. struct alternate_functions af = pct->soc->alternate_functions[gpio];
  256. int ret;
  257. int val;
  258. unsigned offset;
  259. const char *modes[] = {
  260. [ABX500_DEFAULT] = "default",
  261. [ABX500_ALT_A] = "altA",
  262. [ABX500_ALT_B] = "altB",
  263. [ABX500_ALT_C] = "altC",
  264. };
  265. /* sanity check */
  266. if (((alt_setting == ABX500_ALT_A) && (af.gpiosel_bit == UNUSED)) ||
  267. ((alt_setting == ABX500_ALT_B) && (af.alt_bit1 == UNUSED)) ||
  268. ((alt_setting == ABX500_ALT_C) && (af.alt_bit2 == UNUSED))) {
  269. dev_dbg(pct->dev, "pin %d doesn't support %s mode\n", gpio,
  270. modes[alt_setting]);
  271. return -EINVAL;
  272. }
  273. /* on ABx5xx, there is no GPIO0, so adjust the offset */
  274. offset = gpio - 1;
  275. switch (alt_setting) {
  276. case ABX500_DEFAULT:
  277. /*
  278. * for ABx5xx family, default mode is always selected by
  279. * writing 0 to GPIOSELx register, except for pins which
  280. * support at least ALT_B mode, default mode is selected
  281. * by writing 1 to GPIOSELx register
  282. */
  283. val = 0;
  284. if (af.alt_bit1 != UNUSED)
  285. val++;
  286. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  287. offset, val);
  288. break;
  289. case ABX500_ALT_A:
  290. /*
  291. * for ABx5xx family, alt_a mode is always selected by
  292. * writing 1 to GPIOSELx register, except for pins which
  293. * support at least ALT_B mode, alt_a mode is selected
  294. * by writing 0 to GPIOSELx register and 0 in ALTFUNC
  295. * register
  296. */
  297. if (af.alt_bit1 != UNUSED) {
  298. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  299. offset, 0);
  300. ret = abx500_gpio_set_bits(chip,
  301. AB8500_GPIO_ALTFUN_REG,
  302. af.alt_bit1,
  303. !!(af.alta_val && BIT(0)));
  304. if (af.alt_bit2 != UNUSED)
  305. ret = abx500_gpio_set_bits(chip,
  306. AB8500_GPIO_ALTFUN_REG,
  307. af.alt_bit2,
  308. !!(af.alta_val && BIT(1)));
  309. } else
  310. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  311. offset, 1);
  312. break;
  313. case ABX500_ALT_B:
  314. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  315. offset, 0);
  316. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
  317. af.alt_bit1, !!(af.altb_val && BIT(0)));
  318. if (af.alt_bit2 != UNUSED)
  319. ret = abx500_gpio_set_bits(chip,
  320. AB8500_GPIO_ALTFUN_REG,
  321. af.alt_bit2,
  322. !!(af.altb_val && BIT(1)));
  323. break;
  324. case ABX500_ALT_C:
  325. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_SEL1_REG,
  326. offset, 0);
  327. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
  328. af.alt_bit2, !!(af.altc_val && BIT(0)));
  329. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_ALTFUN_REG,
  330. af.alt_bit2, !!(af.altc_val && BIT(1)));
  331. break;
  332. default:
  333. dev_dbg(pct->dev, "unknow alt_setting %d\n", alt_setting);
  334. return -EINVAL;
  335. }
  336. return ret;
  337. }
  338. static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
  339. unsigned gpio)
  340. {
  341. u8 mode;
  342. bool bit_mode;
  343. bool alt_bit1;
  344. bool alt_bit2;
  345. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  346. struct alternate_functions af = pct->soc->alternate_functions[gpio];
  347. /*
  348. * if gpiosel_bit is set to unused,
  349. * it means no GPIO or special case
  350. */
  351. if (af.gpiosel_bit == UNUSED)
  352. return ABX500_DEFAULT;
  353. /* read GpioSelx register */
  354. abx500_gpio_get_bit(chip, AB8500_GPIO_SEL1_REG + (gpio / 8),
  355. af.gpiosel_bit, &bit_mode);
  356. mode = bit_mode;
  357. /* sanity check */
  358. if ((af.alt_bit1 < UNUSED) || (af.alt_bit1 > 7) ||
  359. (af.alt_bit2 < UNUSED) || (af.alt_bit2 > 7)) {
  360. dev_err(pct->dev,
  361. "alt_bitX value not in correct range (-1 to 7)\n");
  362. return -EINVAL;
  363. }
  364. /* if alt_bit2 is used, alt_bit1 must be used too */
  365. if ((af.alt_bit2 != UNUSED) && (af.alt_bit1 == UNUSED)) {
  366. dev_err(pct->dev,
  367. "if alt_bit2 is used, alt_bit1 can't be unused\n");
  368. return -EINVAL;
  369. }
  370. /* check if pin use AlternateFunction register */
  371. if ((af.alt_bit1 == UNUSED) && (af.alt_bit1 == UNUSED))
  372. return mode;
  373. /*
  374. * if pin GPIOSEL bit is set and pin supports alternate function,
  375. * it means DEFAULT mode
  376. */
  377. if (mode)
  378. return ABX500_DEFAULT;
  379. /*
  380. * pin use the AlternatFunction register
  381. * read alt_bit1 value
  382. */
  383. abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG,
  384. af.alt_bit1, &alt_bit1);
  385. if (af.alt_bit2 != UNUSED)
  386. /* read alt_bit2 value */
  387. abx500_gpio_get_bit(chip, AB8500_GPIO_ALTFUN_REG, af.alt_bit2,
  388. &alt_bit2);
  389. else
  390. alt_bit2 = 0;
  391. mode = (alt_bit2 << 1) + alt_bit1;
  392. if (mode == af.alta_val)
  393. return ABX500_ALT_A;
  394. else if (mode == af.altb_val)
  395. return ABX500_ALT_B;
  396. else
  397. return ABX500_ALT_C;
  398. }
  399. #ifdef CONFIG_DEBUG_FS
  400. #include <linux/seq_file.h>
  401. static void abx500_gpio_dbg_show_one(struct seq_file *s,
  402. struct pinctrl_dev *pctldev,
  403. struct gpio_chip *chip,
  404. unsigned offset, unsigned gpio)
  405. {
  406. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  407. const char *label = gpiochip_is_requested(chip, offset - 1);
  408. u8 gpio_offset = offset - 1;
  409. int mode = -1;
  410. bool is_out;
  411. bool pull;
  412. const char *modes[] = {
  413. [ABX500_DEFAULT] = "default",
  414. [ABX500_ALT_A] = "altA",
  415. [ABX500_ALT_B] = "altB",
  416. [ABX500_ALT_C] = "altC",
  417. };
  418. abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, gpio_offset, &is_out);
  419. abx500_gpio_get_bit(chip, AB8500_GPIO_PUD1_REG, gpio_offset, &pull);
  420. if (pctldev)
  421. mode = abx500_get_mode(pctldev, chip, offset);
  422. seq_printf(s, " gpio-%-3d (%-20.20s) %-3s %-9s %s",
  423. gpio, label ?: "(none)",
  424. is_out ? "out" : "in ",
  425. is_out ?
  426. (chip->get
  427. ? (chip->get(chip, offset) ? "hi" : "lo")
  428. : "? ")
  429. : (pull ? "pull up" : "pull down"),
  430. (mode < 0) ? "unknown" : modes[mode]);
  431. if (label && !is_out) {
  432. int irq = gpio_to_irq(gpio);
  433. struct irq_desc *desc = irq_to_desc(irq);
  434. if (irq >= 0 && desc->action) {
  435. char *trigger;
  436. int irq_offset = irq - pct->irq_base;
  437. if (pct->rising & BIT(irq_offset))
  438. trigger = "edge-rising";
  439. else if (pct->falling & BIT(irq_offset))
  440. trigger = "edge-falling";
  441. else
  442. trigger = "edge-undefined";
  443. seq_printf(s, " irq-%d %s", irq, trigger);
  444. }
  445. }
  446. }
  447. static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  448. {
  449. unsigned i;
  450. unsigned gpio = chip->base;
  451. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  452. struct pinctrl_dev *pctldev = pct->pctldev;
  453. for (i = 0; i < chip->ngpio; i++, gpio++) {
  454. /* On AB8500, there is no GPIO0, the first is the GPIO 1 */
  455. abx500_gpio_dbg_show_one(s, pctldev, chip, i + 1, gpio);
  456. seq_printf(s, "\n");
  457. }
  458. }
  459. #else
  460. static inline void abx500_gpio_dbg_show_one(struct seq_file *s,
  461. struct pinctrl_dev *pctldev,
  462. struct gpio_chip *chip,
  463. unsigned offset, unsigned gpio)
  464. {
  465. }
  466. #define abx500_gpio_dbg_show NULL
  467. #endif
  468. int abx500_gpio_request(struct gpio_chip *chip, unsigned offset)
  469. {
  470. int gpio = chip->base + offset;
  471. return pinctrl_request_gpio(gpio);
  472. }
  473. void abx500_gpio_free(struct gpio_chip *chip, unsigned offset)
  474. {
  475. int gpio = chip->base + offset;
  476. pinctrl_free_gpio(gpio);
  477. }
  478. static struct gpio_chip abx500gpio_chip = {
  479. .label = "abx500-gpio",
  480. .owner = THIS_MODULE,
  481. .request = abx500_gpio_request,
  482. .free = abx500_gpio_free,
  483. .direction_input = abx500_gpio_direction_input,
  484. .get = abx500_gpio_get,
  485. .direction_output = abx500_gpio_direction_output,
  486. .set = abx500_gpio_set,
  487. .to_irq = abx500_gpio_to_irq,
  488. .dbg_show = abx500_gpio_dbg_show,
  489. };
  490. static unsigned int irq_to_rising(unsigned int irq)
  491. {
  492. struct abx500_pinctrl *pct = irq_get_chip_data(irq);
  493. int offset = irq - pct->irq_base;
  494. int new_irq;
  495. new_irq = offset * pct->irq_gpio_factor
  496. + pct->irq_gpio_rising_offset
  497. + pct->parent->irq_base;
  498. return new_irq;
  499. }
  500. static unsigned int irq_to_falling(unsigned int irq)
  501. {
  502. struct abx500_pinctrl *pct = irq_get_chip_data(irq);
  503. int offset = irq - pct->irq_base;
  504. int new_irq;
  505. new_irq = offset * pct->irq_gpio_factor
  506. + pct->irq_gpio_falling_offset
  507. + pct->parent->irq_base;
  508. return new_irq;
  509. }
  510. static unsigned int rising_to_irq(unsigned int irq, void *dev)
  511. {
  512. struct abx500_pinctrl *pct = dev;
  513. int offset, new_irq;
  514. offset = irq - pct->irq_gpio_rising_offset
  515. - pct->parent->irq_base;
  516. new_irq = (offset / pct->irq_gpio_factor)
  517. + pct->irq_base;
  518. return new_irq;
  519. }
  520. static unsigned int falling_to_irq(unsigned int irq, void *dev)
  521. {
  522. struct abx500_pinctrl *pct = dev;
  523. int offset, new_irq;
  524. offset = irq - pct->irq_gpio_falling_offset
  525. - pct->parent->irq_base;
  526. new_irq = (offset / pct->irq_gpio_factor)
  527. + pct->irq_base;
  528. return new_irq;
  529. }
  530. /*
  531. * IRQ handler
  532. */
  533. static irqreturn_t handle_rising(int irq, void *dev)
  534. {
  535. handle_nested_irq(rising_to_irq(irq , dev));
  536. return IRQ_HANDLED;
  537. }
  538. static irqreturn_t handle_falling(int irq, void *dev)
  539. {
  540. handle_nested_irq(falling_to_irq(irq, dev));
  541. return IRQ_HANDLED;
  542. }
  543. static void abx500_gpio_irq_lock(struct irq_data *data)
  544. {
  545. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  546. mutex_lock(&pct->lock);
  547. }
  548. static void abx500_gpio_irq_sync_unlock(struct irq_data *data)
  549. {
  550. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  551. unsigned int irq = data->irq;
  552. int offset = irq - pct->irq_base;
  553. bool rising = pct->rising & BIT(offset);
  554. bool falling = pct->falling & BIT(offset);
  555. int ret;
  556. switch (pct->irq_action) {
  557. case STARTUP:
  558. if (rising)
  559. ret = request_threaded_irq(irq_to_rising(irq),
  560. NULL, handle_rising,
  561. IRQF_TRIGGER_RISING | IRQF_NO_SUSPEND,
  562. "abx500-gpio-r", pct);
  563. if (falling)
  564. ret = request_threaded_irq(irq_to_falling(irq),
  565. NULL, handle_falling,
  566. IRQF_TRIGGER_FALLING | IRQF_NO_SUSPEND,
  567. "abx500-gpio-f", pct);
  568. break;
  569. case SHUTDOWN:
  570. if (rising)
  571. free_irq(irq_to_rising(irq), pct);
  572. if (falling)
  573. free_irq(irq_to_falling(irq), pct);
  574. break;
  575. case MASK:
  576. if (rising)
  577. disable_irq(irq_to_rising(irq));
  578. if (falling)
  579. disable_irq(irq_to_falling(irq));
  580. break;
  581. case UNMASK:
  582. if (rising)
  583. enable_irq(irq_to_rising(irq));
  584. if (falling)
  585. enable_irq(irq_to_falling(irq));
  586. break;
  587. case NONE:
  588. break;
  589. }
  590. pct->irq_action = NONE;
  591. pct->rising &= ~(BIT(offset));
  592. pct->falling &= ~(BIT(offset));
  593. mutex_unlock(&pct->lock);
  594. }
  595. static void abx500_gpio_irq_mask(struct irq_data *data)
  596. {
  597. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  598. pct->irq_action = MASK;
  599. }
  600. static void abx500_gpio_irq_unmask(struct irq_data *data)
  601. {
  602. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  603. pct->irq_action = UNMASK;
  604. }
  605. static int abx500_gpio_irq_set_type(struct irq_data *data, unsigned int type)
  606. {
  607. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  608. unsigned int irq = data->irq;
  609. int offset = irq - pct->irq_base;
  610. if (type == IRQ_TYPE_EDGE_BOTH) {
  611. pct->rising = BIT(offset);
  612. pct->falling = BIT(offset);
  613. } else if (type == IRQ_TYPE_EDGE_RISING) {
  614. pct->rising = BIT(offset);
  615. } else {
  616. pct->falling = BIT(offset);
  617. }
  618. return 0;
  619. }
  620. static unsigned int abx500_gpio_irq_startup(struct irq_data *data)
  621. {
  622. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  623. pct->irq_action = STARTUP;
  624. return 0;
  625. }
  626. static void abx500_gpio_irq_shutdown(struct irq_data *data)
  627. {
  628. struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
  629. pct->irq_action = SHUTDOWN;
  630. }
  631. static struct irq_chip abx500_gpio_irq_chip = {
  632. .name = "abx500-gpio",
  633. .irq_startup = abx500_gpio_irq_startup,
  634. .irq_shutdown = abx500_gpio_irq_shutdown,
  635. .irq_bus_lock = abx500_gpio_irq_lock,
  636. .irq_bus_sync_unlock = abx500_gpio_irq_sync_unlock,
  637. .irq_mask = abx500_gpio_irq_mask,
  638. .irq_unmask = abx500_gpio_irq_unmask,
  639. .irq_set_type = abx500_gpio_irq_set_type,
  640. };
  641. static int abx500_gpio_irq_init(struct abx500_pinctrl *pct)
  642. {
  643. u32 base = pct->irq_base;
  644. int irq;
  645. for (irq = base; irq < base + AB8500_NUM_VIR_GPIO_IRQ ; irq++) {
  646. irq_set_chip_data(irq, pct);
  647. irq_set_chip_and_handler(irq, &abx500_gpio_irq_chip,
  648. handle_simple_irq);
  649. irq_set_nested_thread(irq, 1);
  650. #ifdef CONFIG_ARM
  651. set_irq_flags(irq, IRQF_VALID);
  652. #else
  653. irq_set_noprobe(irq);
  654. #endif
  655. }
  656. return 0;
  657. }
  658. static void abx500_gpio_irq_remove(struct abx500_pinctrl *pct)
  659. {
  660. int base = pct->irq_base;
  661. int irq;
  662. for (irq = base; irq < base + AB8500_NUM_VIR_GPIO_IRQ; irq++) {
  663. #ifdef CONFIG_ARM
  664. set_irq_flags(irq, 0);
  665. #endif
  666. irq_set_chip_and_handler(irq, NULL, NULL);
  667. irq_set_chip_data(irq, NULL);
  668. }
  669. }
  670. static int abx500_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev)
  671. {
  672. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  673. return pct->soc->nfunctions;
  674. }
  675. static const char *abx500_pmx_get_func_name(struct pinctrl_dev *pctldev,
  676. unsigned function)
  677. {
  678. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  679. return pct->soc->functions[function].name;
  680. }
  681. static int abx500_pmx_get_func_groups(struct pinctrl_dev *pctldev,
  682. unsigned function,
  683. const char * const **groups,
  684. unsigned * const num_groups)
  685. {
  686. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  687. *groups = pct->soc->functions[function].groups;
  688. *num_groups = pct->soc->functions[function].ngroups;
  689. return 0;
  690. }
  691. static void abx500_disable_lazy_irq(struct gpio_chip *chip, unsigned gpio)
  692. {
  693. struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
  694. int irq;
  695. int offset;
  696. bool rising;
  697. bool falling;
  698. /*
  699. * check if gpio has interrupt capability and convert
  700. * gpio number to irq
  701. * On ABx5xx, there is no GPIO0, GPIO1 is the
  702. * first one, so adjust gpio number
  703. */
  704. gpio--;
  705. irq = gpio_to_irq(gpio + chip->base);
  706. if (irq < 0)
  707. return;
  708. offset = irq - pct->irq_base;
  709. rising = pct->rising & BIT(offset);
  710. falling = pct->falling & BIT(offset);
  711. /* nothing to do ?*/
  712. if (!rising && !falling)
  713. return;
  714. if (rising) {
  715. disable_irq(irq_to_rising(irq));
  716. free_irq(irq_to_rising(irq), pct);
  717. }
  718. if (falling) {
  719. disable_irq(irq_to_falling(irq));
  720. free_irq(irq_to_falling(irq), pct);
  721. }
  722. }
  723. static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
  724. unsigned group)
  725. {
  726. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  727. struct gpio_chip *chip = &pct->chip;
  728. const struct abx500_pingroup *g;
  729. int i;
  730. int ret = 0;
  731. g = &pct->soc->groups[group];
  732. if (g->altsetting < 0)
  733. return -EINVAL;
  734. dev_dbg(pct->dev, "enable group %s, %u pins\n", g->name, g->npins);
  735. for (i = 0; i < g->npins; i++) {
  736. dev_dbg(pct->dev, "setting pin %d to altsetting %d\n",
  737. g->pins[i], g->altsetting);
  738. abx500_disable_lazy_irq(chip, g->pins[i]);
  739. ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting);
  740. }
  741. return ret;
  742. }
  743. static void abx500_pmx_disable(struct pinctrl_dev *pctldev,
  744. unsigned function, unsigned group)
  745. {
  746. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  747. const struct abx500_pingroup *g;
  748. g = &pct->soc->groups[group];
  749. if (g->altsetting < 0)
  750. return;
  751. /* FIXME: poke out the mux, set the pin to some default state? */
  752. dev_dbg(pct->dev, "disable group %s, %u pins\n", g->name, g->npins);
  753. }
  754. int abx500_gpio_request_enable(struct pinctrl_dev *pctldev,
  755. struct pinctrl_gpio_range *range,
  756. unsigned offset)
  757. {
  758. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  759. const struct abx500_pinrange *p;
  760. int ret;
  761. int i;
  762. /*
  763. * Different ranges have different ways to enable GPIO function on a
  764. * pin, so refer back to our local range type, where we handily define
  765. * what altfunc enables GPIO for a certain pin.
  766. */
  767. for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
  768. p = &pct->soc->gpio_ranges[i];
  769. if ((offset >= p->offset) &&
  770. (offset < (p->offset + p->npins)))
  771. break;
  772. }
  773. if (i == pct->soc->gpio_num_ranges) {
  774. dev_err(pct->dev, "%s failed to locate range\n", __func__);
  775. return -ENODEV;
  776. }
  777. dev_dbg(pct->dev, "enable GPIO by altfunc %d at gpio %d\n",
  778. p->altfunc, offset);
  779. ret = abx500_set_mode(pct->pctldev, &pct->chip,
  780. offset, p->altfunc);
  781. if (ret < 0) {
  782. dev_err(pct->dev, "%s setting altfunc failed\n", __func__);
  783. return ret;
  784. }
  785. return ret;
  786. }
  787. static void abx500_gpio_disable_free(struct pinctrl_dev *pctldev,
  788. struct pinctrl_gpio_range *range,
  789. unsigned offset)
  790. {
  791. }
  792. static struct pinmux_ops abx500_pinmux_ops = {
  793. .get_functions_count = abx500_pmx_get_funcs_cnt,
  794. .get_function_name = abx500_pmx_get_func_name,
  795. .get_function_groups = abx500_pmx_get_func_groups,
  796. .enable = abx500_pmx_enable,
  797. .disable = abx500_pmx_disable,
  798. .gpio_request_enable = abx500_gpio_request_enable,
  799. .gpio_disable_free = abx500_gpio_disable_free,
  800. };
  801. static int abx500_get_groups_cnt(struct pinctrl_dev *pctldev)
  802. {
  803. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  804. return pct->soc->ngroups;
  805. }
  806. static const char *abx500_get_group_name(struct pinctrl_dev *pctldev,
  807. unsigned selector)
  808. {
  809. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  810. return pct->soc->groups[selector].name;
  811. }
  812. static int abx500_get_group_pins(struct pinctrl_dev *pctldev,
  813. unsigned selector,
  814. const unsigned **pins,
  815. unsigned *num_pins)
  816. {
  817. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  818. *pins = pct->soc->groups[selector].pins;
  819. *num_pins = pct->soc->groups[selector].npins;
  820. return 0;
  821. }
  822. static void abx500_pin_dbg_show(struct pinctrl_dev *pctldev,
  823. struct seq_file *s, unsigned offset)
  824. {
  825. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  826. struct gpio_chip *chip = &pct->chip;
  827. abx500_gpio_dbg_show_one(s, pctldev, chip, offset,
  828. chip->base + offset - 1);
  829. }
  830. static struct pinctrl_ops abx500_pinctrl_ops = {
  831. .get_groups_count = abx500_get_groups_cnt,
  832. .get_group_name = abx500_get_group_name,
  833. .get_group_pins = abx500_get_group_pins,
  834. .pin_dbg_show = abx500_pin_dbg_show,
  835. };
  836. int abx500_pin_config_get(struct pinctrl_dev *pctldev,
  837. unsigned pin,
  838. unsigned long *config)
  839. {
  840. return -ENOSYS;
  841. }
  842. int abx500_pin_config_set(struct pinctrl_dev *pctldev,
  843. unsigned pin,
  844. unsigned long config)
  845. {
  846. struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
  847. struct pullud *pullud = pct->soc->pullud;
  848. struct gpio_chip *chip = &pct->chip;
  849. unsigned offset;
  850. int ret;
  851. enum pin_config_param param = pinconf_to_config_param(config);
  852. enum pin_config_param argument = pinconf_to_config_argument(config);
  853. dev_dbg(chip->dev, "pin %d [%#lx]: %s %s\n",
  854. pin, config, (param == PIN_CONFIG_OUTPUT) ? "output " : "input",
  855. (param == PIN_CONFIG_OUTPUT) ? (argument ? "high" : "low") :
  856. (argument ? "pull up" : "pull down"));
  857. /* on ABx500, there is no GPIO0, so adjust the offset */
  858. offset = pin - 1;
  859. switch (param) {
  860. case PIN_CONFIG_BIAS_PULL_DOWN:
  861. /*
  862. * if argument = 1 set the pull down
  863. * else clear the pull down
  864. */
  865. ret = abx500_gpio_direction_input(chip, offset);
  866. /*
  867. * Some chips only support pull down, while some actually
  868. * support both pull up and pull down. Such chips have
  869. * a "pullud" range specified for the pins that support
  870. * both features. If the pin is not within that range, we
  871. * fall back to the old bit set that only support pull down.
  872. */
  873. if (pullud &&
  874. pin >= pullud->first_pin &&
  875. pin <= pullud->last_pin)
  876. ret = abx500_config_pull_updown(pct,
  877. pin,
  878. argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE);
  879. else
  880. /* Chip only supports pull down */
  881. ret = abx500_gpio_set_bits(chip, AB8500_GPIO_PUD1_REG,
  882. offset, argument ? 0 : 1);
  883. break;
  884. case PIN_CONFIG_OUTPUT:
  885. ret = abx500_gpio_direction_output(chip, offset, argument);
  886. break;
  887. default:
  888. dev_err(chip->dev, "illegal configuration requested\n");
  889. return -EINVAL;
  890. }
  891. return ret;
  892. }
  893. static struct pinconf_ops abx500_pinconf_ops = {
  894. .pin_config_get = abx500_pin_config_get,
  895. .pin_config_set = abx500_pin_config_set,
  896. };
  897. static struct pinctrl_desc abx500_pinctrl_desc = {
  898. .name = "pinctrl-abx500",
  899. .pctlops = &abx500_pinctrl_ops,
  900. .pmxops = &abx500_pinmux_ops,
  901. .confops = &abx500_pinconf_ops,
  902. .owner = THIS_MODULE,
  903. };
  904. static int abx500_get_gpio_num(struct abx500_pinctrl_soc_data *soc)
  905. {
  906. unsigned int lowest = 0;
  907. unsigned int highest = 0;
  908. unsigned int npins = 0;
  909. int i;
  910. /*
  911. * Compute number of GPIOs from the last SoC gpio range descriptors
  912. * These ranges may include "holes" but the GPIO number space shall
  913. * still be homogeneous, so we need to detect and account for any
  914. * such holes so that these are included in the number of GPIO pins.
  915. */
  916. for (i = 0; i < soc->gpio_num_ranges; i++) {
  917. unsigned gstart;
  918. unsigned gend;
  919. const struct abx500_pinrange *p;
  920. p = &soc->gpio_ranges[i];
  921. gstart = p->offset;
  922. gend = p->offset + p->npins - 1;
  923. if (i == 0) {
  924. /* First iteration, set start values */
  925. lowest = gstart;
  926. highest = gend;
  927. } else {
  928. if (gstart < lowest)
  929. lowest = gstart;
  930. if (gend > highest)
  931. highest = gend;
  932. }
  933. }
  934. /* this gives the absolute number of pins */
  935. npins = highest - lowest + 1;
  936. return npins;
  937. }
  938. static int abx500_gpio_probe(struct platform_device *pdev)
  939. {
  940. struct ab8500_platform_data *abx500_pdata =
  941. dev_get_platdata(pdev->dev.parent);
  942. struct abx500_gpio_platform_data *pdata;
  943. struct abx500_pinctrl *pct;
  944. const struct platform_device_id *platid = platform_get_device_id(pdev);
  945. int ret, err;
  946. int i;
  947. pdata = abx500_pdata->gpio;
  948. if (!pdata) {
  949. dev_err(&pdev->dev, "gpio platform data missing\n");
  950. return -ENODEV;
  951. }
  952. pct = devm_kzalloc(&pdev->dev, sizeof(struct abx500_pinctrl),
  953. GFP_KERNEL);
  954. if (pct == NULL) {
  955. dev_err(&pdev->dev,
  956. "failed to allocate memory for pct\n");
  957. return -ENOMEM;
  958. }
  959. pct->dev = &pdev->dev;
  960. pct->parent = dev_get_drvdata(pdev->dev.parent);
  961. pct->chip = abx500gpio_chip;
  962. pct->chip.dev = &pdev->dev;
  963. pct->chip.base = pdata->gpio_base;
  964. pct->irq_base = pdata->irq_base;
  965. /* initialize the lock */
  966. mutex_init(&pct->lock);
  967. /* Poke in other ASIC variants here */
  968. switch (platid->driver_data) {
  969. case PINCTRL_AB8500:
  970. abx500_pinctrl_ab8500_init(&pct->soc);
  971. break;
  972. case PINCTRL_AB8540:
  973. abx500_pinctrl_ab8540_init(&pct->soc);
  974. break;
  975. case PINCTRL_AB9540:
  976. abx500_pinctrl_ab9540_init(&pct->soc);
  977. break;
  978. case PINCTRL_AB8505:
  979. abx500_pinctrl_ab8505_init(&pct->soc);
  980. break;
  981. default:
  982. dev_err(&pdev->dev, "Unsupported pinctrl sub driver (%d)\n",
  983. (int) platid->driver_data);
  984. mutex_destroy(&pct->lock);
  985. return -EINVAL;
  986. }
  987. if (!pct->soc) {
  988. dev_err(&pdev->dev, "Invalid SOC data\n");
  989. mutex_destroy(&pct->lock);
  990. return -EINVAL;
  991. }
  992. pct->chip.ngpio = abx500_get_gpio_num(pct->soc);
  993. pct->irq_cluster = pct->soc->gpio_irq_cluster;
  994. pct->irq_cluster_size = pct->soc->ngpio_irq_cluster;
  995. pct->irq_gpio_rising_offset = pct->soc->irq_gpio_rising_offset;
  996. pct->irq_gpio_falling_offset = pct->soc->irq_gpio_falling_offset;
  997. pct->irq_gpio_factor = pct->soc->irq_gpio_factor;
  998. ret = abx500_gpio_irq_init(pct);
  999. if (ret)
  1000. goto out_free;
  1001. ret = gpiochip_add(&pct->chip);
  1002. if (ret) {
  1003. dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
  1004. mutex_destroy(&pct->lock);
  1005. goto out_rem_irq;
  1006. }
  1007. dev_info(&pdev->dev, "added gpiochip\n");
  1008. abx500_pinctrl_desc.pins = pct->soc->pins;
  1009. abx500_pinctrl_desc.npins = pct->soc->npins;
  1010. pct->pctldev = pinctrl_register(&abx500_pinctrl_desc, &pdev->dev, pct);
  1011. if (!pct->pctldev) {
  1012. dev_err(&pdev->dev,
  1013. "could not register abx500 pinctrl driver\n");
  1014. ret = -EINVAL;
  1015. goto out_rem_chip;
  1016. }
  1017. dev_info(&pdev->dev, "registered pin controller\n");
  1018. /* We will handle a range of GPIO pins */
  1019. for (i = 0; i < pct->soc->gpio_num_ranges; i++) {
  1020. const struct abx500_pinrange *p = &pct->soc->gpio_ranges[i];
  1021. ret = gpiochip_add_pin_range(&pct->chip,
  1022. dev_name(&pdev->dev),
  1023. p->offset - 1, p->offset, p->npins);
  1024. if (ret < 0)
  1025. goto out_rem_chip;
  1026. }
  1027. platform_set_drvdata(pdev, pct);
  1028. dev_info(&pdev->dev, "initialized abx500 pinctrl driver\n");
  1029. return 0;
  1030. out_rem_chip:
  1031. err = gpiochip_remove(&pct->chip);
  1032. if (err)
  1033. dev_info(&pdev->dev, "failed to remove gpiochip\n");
  1034. out_rem_irq:
  1035. abx500_gpio_irq_remove(pct);
  1036. out_free:
  1037. mutex_destroy(&pct->lock);
  1038. return ret;
  1039. }
  1040. /**
  1041. * abx500_gpio_remove() - remove Ab8500-gpio driver
  1042. * @pdev: Platform device registered
  1043. */
  1044. static int abx500_gpio_remove(struct platform_device *pdev)
  1045. {
  1046. struct abx500_pinctrl *pct = platform_get_drvdata(pdev);
  1047. int ret;
  1048. ret = gpiochip_remove(&pct->chip);
  1049. if (ret < 0) {
  1050. dev_err(pct->dev, "unable to remove gpiochip: %d\n",
  1051. ret);
  1052. return ret;
  1053. }
  1054. mutex_destroy(&pct->lock);
  1055. return 0;
  1056. }
  1057. static const struct platform_device_id abx500_pinctrl_id[] = {
  1058. { "pinctrl-ab8500", PINCTRL_AB8500 },
  1059. { "pinctrl-ab8540", PINCTRL_AB8540 },
  1060. { "pinctrl-ab9540", PINCTRL_AB9540 },
  1061. { "pinctrl-ab8505", PINCTRL_AB8505 },
  1062. { },
  1063. };
  1064. static struct platform_driver abx500_gpio_driver = {
  1065. .driver = {
  1066. .name = "abx500-gpio",
  1067. .owner = THIS_MODULE,
  1068. },
  1069. .probe = abx500_gpio_probe,
  1070. .remove = abx500_gpio_remove,
  1071. .id_table = abx500_pinctrl_id,
  1072. };
  1073. static int __init abx500_gpio_init(void)
  1074. {
  1075. return platform_driver_register(&abx500_gpio_driver);
  1076. }
  1077. core_initcall(abx500_gpio_init);
  1078. MODULE_AUTHOR("Patrice Chotard <patrice.chotard@st.com>");
  1079. MODULE_DESCRIPTION("Driver allows to use AxB5xx unused pins to be used as GPIO");
  1080. MODULE_ALIAS("platform:abx500-gpio");
  1081. MODULE_LICENSE("GPL v2");