pinctrl-abx500.c 32 KB

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