pinctrl-abx500.c 32 KB

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