pinctrl-at91-pio4.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. /*
  2. * Driver for the Atmel PIO4 controller
  3. *
  4. * Copyright (C) 2015 Atmel,
  5. * 2015 Ludovic Desroches <ludovic.desroches@atmel.com>
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/clk.h>
  17. #include <linux/gpio/driver.h>
  18. /* FIXME: needed for gpio_to_irq(), get rid of this */
  19. #include <linux/gpio.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/io.h>
  22. #include <linux/init.h>
  23. #include <linux/of.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/pinctrl/pinconf.h>
  26. #include <linux/pinctrl/pinconf-generic.h>
  27. #include <linux/pinctrl/pinctrl.h>
  28. #include <linux/pinctrl/pinmux.h>
  29. #include <linux/slab.h>
  30. #include "core.h"
  31. #include "pinconf.h"
  32. #include "pinctrl-utils.h"
  33. /*
  34. * Warning:
  35. * In order to not introduce confusion between Atmel PIO groups and pinctrl
  36. * framework groups, Atmel PIO groups will be called banks, line is kept to
  37. * designed the pin id into this bank.
  38. */
  39. #define ATMEL_PIO_MSKR 0x0000
  40. #define ATMEL_PIO_CFGR 0x0004
  41. #define ATMEL_PIO_CFGR_FUNC_MASK GENMASK(2, 0)
  42. #define ATMEL_PIO_DIR_MASK BIT(8)
  43. #define ATMEL_PIO_PUEN_MASK BIT(9)
  44. #define ATMEL_PIO_PDEN_MASK BIT(10)
  45. #define ATMEL_PIO_IFEN_MASK BIT(12)
  46. #define ATMEL_PIO_IFSCEN_MASK BIT(13)
  47. #define ATMEL_PIO_OPD_MASK BIT(14)
  48. #define ATMEL_PIO_SCHMITT_MASK BIT(15)
  49. #define ATMEL_PIO_CFGR_EVTSEL_MASK GENMASK(26, 24)
  50. #define ATMEL_PIO_CFGR_EVTSEL_FALLING (0 << 24)
  51. #define ATMEL_PIO_CFGR_EVTSEL_RISING (1 << 24)
  52. #define ATMEL_PIO_CFGR_EVTSEL_BOTH (2 << 24)
  53. #define ATMEL_PIO_CFGR_EVTSEL_LOW (3 << 24)
  54. #define ATMEL_PIO_CFGR_EVTSEL_HIGH (4 << 24)
  55. #define ATMEL_PIO_PDSR 0x0008
  56. #define ATMEL_PIO_LOCKSR 0x000C
  57. #define ATMEL_PIO_SODR 0x0010
  58. #define ATMEL_PIO_CODR 0x0014
  59. #define ATMEL_PIO_ODSR 0x0018
  60. #define ATMEL_PIO_IER 0x0020
  61. #define ATMEL_PIO_IDR 0x0024
  62. #define ATMEL_PIO_IMR 0x0028
  63. #define ATMEL_PIO_ISR 0x002C
  64. #define ATMEL_PIO_IOFR 0x003C
  65. #define ATMEL_PIO_NPINS_PER_BANK 32
  66. #define ATMEL_PIO_BANK(pin_id) (pin_id / ATMEL_PIO_NPINS_PER_BANK)
  67. #define ATMEL_PIO_LINE(pin_id) (pin_id % ATMEL_PIO_NPINS_PER_BANK)
  68. #define ATMEL_PIO_BANK_OFFSET 0x40
  69. #define ATMEL_GET_PIN_NO(pinfunc) ((pinfunc) & 0xff)
  70. #define ATMEL_GET_PIN_FUNC(pinfunc) ((pinfunc >> 16) & 0xf)
  71. #define ATMEL_GET_PIN_IOSET(pinfunc) ((pinfunc >> 20) & 0xf)
  72. struct atmel_pioctrl_data {
  73. unsigned nbanks;
  74. };
  75. struct atmel_group {
  76. const char *name;
  77. u32 pin;
  78. };
  79. struct atmel_pin {
  80. unsigned pin_id;
  81. unsigned mux;
  82. unsigned ioset;
  83. unsigned bank;
  84. unsigned line;
  85. const char *device;
  86. };
  87. /**
  88. * struct atmel_pioctrl - Atmel PIO controller (pinmux + gpio)
  89. * @reg_base: base address of the controller.
  90. * @clk: clock of the controller.
  91. * @nbanks: number of PIO groups, it can vary depending on the SoC.
  92. * @pinctrl_dev: pinctrl device registered.
  93. * @groups: groups table to provide group name and pin in the group to pinctrl.
  94. * @group_names: group names table to provide all the group/pin names to
  95. * pinctrl or gpio.
  96. * @pins: pins table used for both pinctrl and gpio. pin_id, bank and line
  97. * fields are set at probe time. Other ones are set when parsing dt
  98. * pinctrl.
  99. * @npins: number of pins.
  100. * @gpio_chip: gpio chip registered.
  101. * @irq_domain: irq domain for the gpio controller.
  102. * @irqs: table containing the hw irq number of the bank. The index of the
  103. * table is the bank id.
  104. * @dev: device entry for the Atmel PIO controller.
  105. * @node: node of the Atmel PIO controller.
  106. */
  107. struct atmel_pioctrl {
  108. void __iomem *reg_base;
  109. struct clk *clk;
  110. unsigned nbanks;
  111. struct pinctrl_dev *pinctrl_dev;
  112. struct atmel_group *groups;
  113. const char * const *group_names;
  114. struct atmel_pin **pins;
  115. unsigned npins;
  116. struct gpio_chip *gpio_chip;
  117. struct irq_domain *irq_domain;
  118. int *irqs;
  119. unsigned *pm_wakeup_sources;
  120. struct {
  121. u32 imr;
  122. u32 odsr;
  123. u32 cfgr[ATMEL_PIO_NPINS_PER_BANK];
  124. } *pm_suspend_backup;
  125. struct device *dev;
  126. struct device_node *node;
  127. };
  128. static const char * const atmel_functions[] = {
  129. "GPIO", "A", "B", "C", "D", "E", "F", "G"
  130. };
  131. /* --- GPIO --- */
  132. static unsigned int atmel_gpio_read(struct atmel_pioctrl *atmel_pioctrl,
  133. unsigned int bank, unsigned int reg)
  134. {
  135. return readl_relaxed(atmel_pioctrl->reg_base
  136. + ATMEL_PIO_BANK_OFFSET * bank + reg);
  137. }
  138. static void atmel_gpio_write(struct atmel_pioctrl *atmel_pioctrl,
  139. unsigned int bank, unsigned int reg,
  140. unsigned int val)
  141. {
  142. writel_relaxed(val, atmel_pioctrl->reg_base
  143. + ATMEL_PIO_BANK_OFFSET * bank + reg);
  144. }
  145. static void atmel_gpio_irq_ack(struct irq_data *d)
  146. {
  147. /*
  148. * Nothing to do, interrupt is cleared when reading the status
  149. * register.
  150. */
  151. }
  152. static int atmel_gpio_irq_set_type(struct irq_data *d, unsigned type)
  153. {
  154. struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
  155. struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
  156. unsigned reg;
  157. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
  158. BIT(pin->line));
  159. reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
  160. reg &= (~ATMEL_PIO_CFGR_EVTSEL_MASK);
  161. switch (type) {
  162. case IRQ_TYPE_EDGE_RISING:
  163. irq_set_handler_locked(d, handle_edge_irq);
  164. reg |= ATMEL_PIO_CFGR_EVTSEL_RISING;
  165. break;
  166. case IRQ_TYPE_EDGE_FALLING:
  167. irq_set_handler_locked(d, handle_edge_irq);
  168. reg |= ATMEL_PIO_CFGR_EVTSEL_FALLING;
  169. break;
  170. case IRQ_TYPE_EDGE_BOTH:
  171. irq_set_handler_locked(d, handle_edge_irq);
  172. reg |= ATMEL_PIO_CFGR_EVTSEL_BOTH;
  173. break;
  174. case IRQ_TYPE_LEVEL_LOW:
  175. irq_set_handler_locked(d, handle_level_irq);
  176. reg |= ATMEL_PIO_CFGR_EVTSEL_LOW;
  177. break;
  178. case IRQ_TYPE_LEVEL_HIGH:
  179. irq_set_handler_locked(d, handle_level_irq);
  180. reg |= ATMEL_PIO_CFGR_EVTSEL_HIGH;
  181. break;
  182. case IRQ_TYPE_NONE:
  183. default:
  184. return -EINVAL;
  185. }
  186. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
  187. return 0;
  188. }
  189. static void atmel_gpio_irq_mask(struct irq_data *d)
  190. {
  191. struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
  192. struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
  193. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_IDR,
  194. BIT(pin->line));
  195. }
  196. static void atmel_gpio_irq_unmask(struct irq_data *d)
  197. {
  198. struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
  199. struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
  200. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_IER,
  201. BIT(pin->line));
  202. }
  203. #ifdef CONFIG_PM_SLEEP
  204. static int atmel_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
  205. {
  206. struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
  207. int bank = ATMEL_PIO_BANK(d->hwirq);
  208. int line = ATMEL_PIO_LINE(d->hwirq);
  209. /* The gpio controller has one interrupt line per bank. */
  210. irq_set_irq_wake(atmel_pioctrl->irqs[bank], on);
  211. if (on)
  212. atmel_pioctrl->pm_wakeup_sources[bank] |= BIT(line);
  213. else
  214. atmel_pioctrl->pm_wakeup_sources[bank] &= ~(BIT(line));
  215. return 0;
  216. }
  217. #else
  218. #define atmel_gpio_irq_set_wake NULL
  219. #endif /* CONFIG_PM_SLEEP */
  220. static struct irq_chip atmel_gpio_irq_chip = {
  221. .name = "GPIO",
  222. .irq_ack = atmel_gpio_irq_ack,
  223. .irq_mask = atmel_gpio_irq_mask,
  224. .irq_unmask = atmel_gpio_irq_unmask,
  225. .irq_set_type = atmel_gpio_irq_set_type,
  226. .irq_set_wake = atmel_gpio_irq_set_wake,
  227. };
  228. static void atmel_gpio_irq_handler(struct irq_desc *desc)
  229. {
  230. unsigned int irq = irq_desc_get_irq(desc);
  231. struct atmel_pioctrl *atmel_pioctrl = irq_desc_get_handler_data(desc);
  232. struct irq_chip *chip = irq_desc_get_chip(desc);
  233. unsigned long isr;
  234. int n, bank = -1;
  235. /* Find from which bank is the irq received. */
  236. for (n = 0; n < atmel_pioctrl->nbanks; n++) {
  237. if (atmel_pioctrl->irqs[n] == irq) {
  238. bank = n;
  239. break;
  240. }
  241. }
  242. if (bank < 0) {
  243. dev_err(atmel_pioctrl->dev,
  244. "no bank associated to irq %u\n", irq);
  245. return;
  246. }
  247. chained_irq_enter(chip, desc);
  248. for (;;) {
  249. isr = (unsigned long)atmel_gpio_read(atmel_pioctrl, bank,
  250. ATMEL_PIO_ISR);
  251. isr &= (unsigned long)atmel_gpio_read(atmel_pioctrl, bank,
  252. ATMEL_PIO_IMR);
  253. if (!isr)
  254. break;
  255. for_each_set_bit(n, &isr, BITS_PER_LONG)
  256. generic_handle_irq(gpio_to_irq(bank *
  257. ATMEL_PIO_NPINS_PER_BANK + n));
  258. }
  259. chained_irq_exit(chip, desc);
  260. }
  261. static int atmel_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  262. {
  263. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  264. struct atmel_pin *pin = atmel_pioctrl->pins[offset];
  265. unsigned reg;
  266. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
  267. BIT(pin->line));
  268. reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
  269. reg &= ~ATMEL_PIO_DIR_MASK;
  270. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
  271. return 0;
  272. }
  273. static int atmel_gpio_get(struct gpio_chip *chip, unsigned offset)
  274. {
  275. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  276. struct atmel_pin *pin = atmel_pioctrl->pins[offset];
  277. unsigned reg;
  278. reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_PDSR);
  279. return !!(reg & BIT(pin->line));
  280. }
  281. static int atmel_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
  282. int value)
  283. {
  284. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  285. struct atmel_pin *pin = atmel_pioctrl->pins[offset];
  286. unsigned reg;
  287. atmel_gpio_write(atmel_pioctrl, pin->bank,
  288. value ? ATMEL_PIO_SODR : ATMEL_PIO_CODR,
  289. BIT(pin->line));
  290. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
  291. BIT(pin->line));
  292. reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
  293. reg |= ATMEL_PIO_DIR_MASK;
  294. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
  295. return 0;
  296. }
  297. static void atmel_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
  298. {
  299. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  300. struct atmel_pin *pin = atmel_pioctrl->pins[offset];
  301. atmel_gpio_write(atmel_pioctrl, pin->bank,
  302. val ? ATMEL_PIO_SODR : ATMEL_PIO_CODR,
  303. BIT(pin->line));
  304. }
  305. static int atmel_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  306. {
  307. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  308. return irq_find_mapping(atmel_pioctrl->irq_domain, offset);
  309. }
  310. static struct gpio_chip atmel_gpio_chip = {
  311. .direction_input = atmel_gpio_direction_input,
  312. .get = atmel_gpio_get,
  313. .direction_output = atmel_gpio_direction_output,
  314. .set = atmel_gpio_set,
  315. .to_irq = atmel_gpio_to_irq,
  316. .base = 0,
  317. };
  318. /* --- PINCTRL --- */
  319. static unsigned int atmel_pin_config_read(struct pinctrl_dev *pctldev,
  320. unsigned pin_id)
  321. {
  322. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  323. unsigned bank = atmel_pioctrl->pins[pin_id]->bank;
  324. unsigned line = atmel_pioctrl->pins[pin_id]->line;
  325. void __iomem *addr = atmel_pioctrl->reg_base
  326. + bank * ATMEL_PIO_BANK_OFFSET;
  327. writel_relaxed(BIT(line), addr + ATMEL_PIO_MSKR);
  328. /* Have to set MSKR first, to access the right pin CFGR. */
  329. wmb();
  330. return readl_relaxed(addr + ATMEL_PIO_CFGR);
  331. }
  332. static void atmel_pin_config_write(struct pinctrl_dev *pctldev,
  333. unsigned pin_id, u32 conf)
  334. {
  335. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  336. unsigned bank = atmel_pioctrl->pins[pin_id]->bank;
  337. unsigned line = atmel_pioctrl->pins[pin_id]->line;
  338. void __iomem *addr = atmel_pioctrl->reg_base
  339. + bank * ATMEL_PIO_BANK_OFFSET;
  340. writel_relaxed(BIT(line), addr + ATMEL_PIO_MSKR);
  341. /* Have to set MSKR first, to access the right pin CFGR. */
  342. wmb();
  343. writel_relaxed(conf, addr + ATMEL_PIO_CFGR);
  344. }
  345. static int atmel_pctl_get_groups_count(struct pinctrl_dev *pctldev)
  346. {
  347. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  348. return atmel_pioctrl->npins;
  349. }
  350. static const char *atmel_pctl_get_group_name(struct pinctrl_dev *pctldev,
  351. unsigned selector)
  352. {
  353. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  354. return atmel_pioctrl->groups[selector].name;
  355. }
  356. static int atmel_pctl_get_group_pins(struct pinctrl_dev *pctldev,
  357. unsigned selector, const unsigned **pins,
  358. unsigned *num_pins)
  359. {
  360. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  361. *pins = (unsigned *)&atmel_pioctrl->groups[selector].pin;
  362. *num_pins = 1;
  363. return 0;
  364. }
  365. static struct atmel_group *
  366. atmel_pctl_find_group_by_pin(struct pinctrl_dev *pctldev, unsigned pin)
  367. {
  368. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  369. int i;
  370. for (i = 0; i < atmel_pioctrl->npins; i++) {
  371. struct atmel_group *grp = atmel_pioctrl->groups + i;
  372. if (grp->pin == pin)
  373. return grp;
  374. }
  375. return NULL;
  376. }
  377. static int atmel_pctl_xlate_pinfunc(struct pinctrl_dev *pctldev,
  378. struct device_node *np,
  379. u32 pinfunc, const char **grp_name,
  380. const char **func_name)
  381. {
  382. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  383. unsigned pin_id, func_id;
  384. struct atmel_group *grp;
  385. pin_id = ATMEL_GET_PIN_NO(pinfunc);
  386. func_id = ATMEL_GET_PIN_FUNC(pinfunc);
  387. if (func_id >= ARRAY_SIZE(atmel_functions))
  388. return -EINVAL;
  389. *func_name = atmel_functions[func_id];
  390. grp = atmel_pctl_find_group_by_pin(pctldev, pin_id);
  391. if (!grp)
  392. return -EINVAL;
  393. *grp_name = grp->name;
  394. atmel_pioctrl->pins[pin_id]->mux = func_id;
  395. atmel_pioctrl->pins[pin_id]->ioset = ATMEL_GET_PIN_IOSET(pinfunc);
  396. /* Want the device name not the group one. */
  397. if (np->parent == atmel_pioctrl->node)
  398. atmel_pioctrl->pins[pin_id]->device = np->name;
  399. else
  400. atmel_pioctrl->pins[pin_id]->device = np->parent->name;
  401. return 0;
  402. }
  403. static int atmel_pctl_dt_subnode_to_map(struct pinctrl_dev *pctldev,
  404. struct device_node *np,
  405. struct pinctrl_map **map,
  406. unsigned *reserved_maps,
  407. unsigned *num_maps)
  408. {
  409. unsigned num_pins, num_configs, reserve;
  410. unsigned long *configs;
  411. struct property *pins;
  412. u32 pinfunc;
  413. int ret, i;
  414. pins = of_find_property(np, "pinmux", NULL);
  415. if (!pins)
  416. return -EINVAL;
  417. ret = pinconf_generic_parse_dt_config(np, pctldev, &configs,
  418. &num_configs);
  419. if (ret < 0) {
  420. dev_err(pctldev->dev, "%pOF: could not parse node property\n",
  421. np);
  422. return ret;
  423. }
  424. num_pins = pins->length / sizeof(u32);
  425. if (!num_pins) {
  426. dev_err(pctldev->dev, "no pins found in node %pOF\n", np);
  427. ret = -EINVAL;
  428. goto exit;
  429. }
  430. /*
  431. * Reserve maps, at least there is a mux map and an optional conf
  432. * map for each pin.
  433. */
  434. reserve = 1;
  435. if (num_configs)
  436. reserve++;
  437. reserve *= num_pins;
  438. ret = pinctrl_utils_reserve_map(pctldev, map, reserved_maps, num_maps,
  439. reserve);
  440. if (ret < 0)
  441. goto exit;
  442. for (i = 0; i < num_pins; i++) {
  443. const char *group, *func;
  444. ret = of_property_read_u32_index(np, "pinmux", i, &pinfunc);
  445. if (ret)
  446. goto exit;
  447. ret = atmel_pctl_xlate_pinfunc(pctldev, np, pinfunc, &group,
  448. &func);
  449. if (ret)
  450. goto exit;
  451. pinctrl_utils_add_map_mux(pctldev, map, reserved_maps, num_maps,
  452. group, func);
  453. if (num_configs) {
  454. ret = pinctrl_utils_add_map_configs(pctldev, map,
  455. reserved_maps, num_maps, group,
  456. configs, num_configs,
  457. PIN_MAP_TYPE_CONFIGS_GROUP);
  458. if (ret < 0)
  459. goto exit;
  460. }
  461. }
  462. exit:
  463. kfree(configs);
  464. return ret;
  465. }
  466. static int atmel_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
  467. struct device_node *np_config,
  468. struct pinctrl_map **map,
  469. unsigned *num_maps)
  470. {
  471. struct device_node *np;
  472. unsigned reserved_maps;
  473. int ret;
  474. *map = NULL;
  475. *num_maps = 0;
  476. reserved_maps = 0;
  477. /*
  478. * If all the pins of a device have the same configuration (or no one),
  479. * it is useless to add a subnode, so directly parse node referenced by
  480. * phandle.
  481. */
  482. ret = atmel_pctl_dt_subnode_to_map(pctldev, np_config, map,
  483. &reserved_maps, num_maps);
  484. if (ret) {
  485. for_each_child_of_node(np_config, np) {
  486. ret = atmel_pctl_dt_subnode_to_map(pctldev, np, map,
  487. &reserved_maps, num_maps);
  488. if (ret < 0) {
  489. of_node_put(np);
  490. break;
  491. }
  492. }
  493. }
  494. if (ret < 0) {
  495. pinctrl_utils_free_map(pctldev, *map, *num_maps);
  496. dev_err(pctldev->dev, "can't create maps for node %pOF\n",
  497. np_config);
  498. }
  499. return ret;
  500. }
  501. static const struct pinctrl_ops atmel_pctlops = {
  502. .get_groups_count = atmel_pctl_get_groups_count,
  503. .get_group_name = atmel_pctl_get_group_name,
  504. .get_group_pins = atmel_pctl_get_group_pins,
  505. .dt_node_to_map = atmel_pctl_dt_node_to_map,
  506. .dt_free_map = pinctrl_utils_free_map,
  507. };
  508. static int atmel_pmx_get_functions_count(struct pinctrl_dev *pctldev)
  509. {
  510. return ARRAY_SIZE(atmel_functions);
  511. }
  512. static const char *atmel_pmx_get_function_name(struct pinctrl_dev *pctldev,
  513. unsigned selector)
  514. {
  515. return atmel_functions[selector];
  516. }
  517. static int atmel_pmx_get_function_groups(struct pinctrl_dev *pctldev,
  518. unsigned selector,
  519. const char * const **groups,
  520. unsigned * const num_groups)
  521. {
  522. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  523. *groups = atmel_pioctrl->group_names;
  524. *num_groups = atmel_pioctrl->npins;
  525. return 0;
  526. }
  527. static int atmel_pmx_set_mux(struct pinctrl_dev *pctldev,
  528. unsigned function,
  529. unsigned group)
  530. {
  531. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  532. unsigned pin;
  533. u32 conf;
  534. dev_dbg(pctldev->dev, "enable function %s group %s\n",
  535. atmel_functions[function], atmel_pioctrl->groups[group].name);
  536. pin = atmel_pioctrl->groups[group].pin;
  537. conf = atmel_pin_config_read(pctldev, pin);
  538. conf &= (~ATMEL_PIO_CFGR_FUNC_MASK);
  539. conf |= (function & ATMEL_PIO_CFGR_FUNC_MASK);
  540. dev_dbg(pctldev->dev, "pin: %u, conf: 0x%08x\n", pin, conf);
  541. atmel_pin_config_write(pctldev, pin, conf);
  542. return 0;
  543. }
  544. static const struct pinmux_ops atmel_pmxops = {
  545. .get_functions_count = atmel_pmx_get_functions_count,
  546. .get_function_name = atmel_pmx_get_function_name,
  547. .get_function_groups = atmel_pmx_get_function_groups,
  548. .set_mux = atmel_pmx_set_mux,
  549. };
  550. static int atmel_conf_pin_config_group_get(struct pinctrl_dev *pctldev,
  551. unsigned group,
  552. unsigned long *config)
  553. {
  554. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  555. unsigned param = pinconf_to_config_param(*config), arg = 0;
  556. struct atmel_group *grp = atmel_pioctrl->groups + group;
  557. unsigned pin_id = grp->pin;
  558. u32 res;
  559. res = atmel_pin_config_read(pctldev, pin_id);
  560. switch (param) {
  561. case PIN_CONFIG_BIAS_PULL_UP:
  562. if (!(res & ATMEL_PIO_PUEN_MASK))
  563. return -EINVAL;
  564. arg = 1;
  565. break;
  566. case PIN_CONFIG_BIAS_PULL_DOWN:
  567. if ((res & ATMEL_PIO_PUEN_MASK) ||
  568. (!(res & ATMEL_PIO_PDEN_MASK)))
  569. return -EINVAL;
  570. arg = 1;
  571. break;
  572. case PIN_CONFIG_BIAS_DISABLE:
  573. if ((res & ATMEL_PIO_PUEN_MASK) ||
  574. ((res & ATMEL_PIO_PDEN_MASK)))
  575. return -EINVAL;
  576. arg = 1;
  577. break;
  578. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  579. if (!(res & ATMEL_PIO_OPD_MASK))
  580. return -EINVAL;
  581. arg = 1;
  582. break;
  583. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  584. if (!(res & ATMEL_PIO_SCHMITT_MASK))
  585. return -EINVAL;
  586. arg = 1;
  587. break;
  588. default:
  589. return -ENOTSUPP;
  590. }
  591. *config = pinconf_to_config_packed(param, arg);
  592. return 0;
  593. }
  594. static int atmel_conf_pin_config_group_set(struct pinctrl_dev *pctldev,
  595. unsigned group,
  596. unsigned long *configs,
  597. unsigned num_configs)
  598. {
  599. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  600. struct atmel_group *grp = atmel_pioctrl->groups + group;
  601. unsigned bank, pin, pin_id = grp->pin;
  602. u32 mask, conf = 0;
  603. int i;
  604. conf = atmel_pin_config_read(pctldev, pin_id);
  605. for (i = 0; i < num_configs; i++) {
  606. unsigned param = pinconf_to_config_param(configs[i]);
  607. unsigned arg = pinconf_to_config_argument(configs[i]);
  608. dev_dbg(pctldev->dev, "%s: pin=%u, config=0x%lx\n",
  609. __func__, pin_id, configs[i]);
  610. switch (param) {
  611. case PIN_CONFIG_BIAS_DISABLE:
  612. conf &= (~ATMEL_PIO_PUEN_MASK);
  613. conf &= (~ATMEL_PIO_PDEN_MASK);
  614. break;
  615. case PIN_CONFIG_BIAS_PULL_UP:
  616. conf |= ATMEL_PIO_PUEN_MASK;
  617. conf &= (~ATMEL_PIO_PDEN_MASK);
  618. break;
  619. case PIN_CONFIG_BIAS_PULL_DOWN:
  620. conf |= ATMEL_PIO_PDEN_MASK;
  621. conf &= (~ATMEL_PIO_PUEN_MASK);
  622. break;
  623. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  624. if (arg == 0)
  625. conf &= (~ATMEL_PIO_OPD_MASK);
  626. else
  627. conf |= ATMEL_PIO_OPD_MASK;
  628. break;
  629. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  630. if (arg == 0)
  631. conf |= ATMEL_PIO_SCHMITT_MASK;
  632. else
  633. conf &= (~ATMEL_PIO_SCHMITT_MASK);
  634. break;
  635. case PIN_CONFIG_INPUT_DEBOUNCE:
  636. if (arg == 0) {
  637. conf &= (~ATMEL_PIO_IFEN_MASK);
  638. conf &= (~ATMEL_PIO_IFSCEN_MASK);
  639. } else {
  640. /*
  641. * We don't care about the debounce value for several reasons:
  642. * - can't have different debounce periods inside a same group,
  643. * - the register to configure this period is a secure register.
  644. * The debouncing filter can filter a pulse with a duration of less
  645. * than 1/2 slow clock period.
  646. */
  647. conf |= ATMEL_PIO_IFEN_MASK;
  648. conf |= ATMEL_PIO_IFSCEN_MASK;
  649. }
  650. break;
  651. case PIN_CONFIG_OUTPUT:
  652. conf |= ATMEL_PIO_DIR_MASK;
  653. bank = ATMEL_PIO_BANK(pin_id);
  654. pin = ATMEL_PIO_LINE(pin_id);
  655. mask = 1 << pin;
  656. if (arg == 0) {
  657. writel_relaxed(mask, atmel_pioctrl->reg_base +
  658. bank * ATMEL_PIO_BANK_OFFSET +
  659. ATMEL_PIO_CODR);
  660. } else {
  661. writel_relaxed(mask, atmel_pioctrl->reg_base +
  662. bank * ATMEL_PIO_BANK_OFFSET +
  663. ATMEL_PIO_SODR);
  664. }
  665. break;
  666. default:
  667. dev_warn(pctldev->dev,
  668. "unsupported configuration parameter: %u\n",
  669. param);
  670. continue;
  671. }
  672. }
  673. dev_dbg(pctldev->dev, "%s: reg=0x%08x\n", __func__, conf);
  674. atmel_pin_config_write(pctldev, pin_id, conf);
  675. return 0;
  676. }
  677. static void atmel_conf_pin_config_dbg_show(struct pinctrl_dev *pctldev,
  678. struct seq_file *s, unsigned pin_id)
  679. {
  680. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  681. u32 conf;
  682. if (!atmel_pioctrl->pins[pin_id]->device)
  683. return;
  684. if (atmel_pioctrl->pins[pin_id])
  685. seq_printf(s, " (%s, ioset %u) ",
  686. atmel_pioctrl->pins[pin_id]->device,
  687. atmel_pioctrl->pins[pin_id]->ioset);
  688. conf = atmel_pin_config_read(pctldev, pin_id);
  689. if (conf & ATMEL_PIO_PUEN_MASK)
  690. seq_printf(s, "%s ", "pull-up");
  691. if (conf & ATMEL_PIO_PDEN_MASK)
  692. seq_printf(s, "%s ", "pull-down");
  693. if (conf & ATMEL_PIO_IFEN_MASK)
  694. seq_printf(s, "%s ", "debounce");
  695. if (conf & ATMEL_PIO_OPD_MASK)
  696. seq_printf(s, "%s ", "open-drain");
  697. if (conf & ATMEL_PIO_SCHMITT_MASK)
  698. seq_printf(s, "%s ", "schmitt");
  699. }
  700. static const struct pinconf_ops atmel_confops = {
  701. .pin_config_group_get = atmel_conf_pin_config_group_get,
  702. .pin_config_group_set = atmel_conf_pin_config_group_set,
  703. .pin_config_dbg_show = atmel_conf_pin_config_dbg_show,
  704. };
  705. static struct pinctrl_desc atmel_pinctrl_desc = {
  706. .name = "atmel_pinctrl",
  707. .confops = &atmel_confops,
  708. .pctlops = &atmel_pctlops,
  709. .pmxops = &atmel_pmxops,
  710. };
  711. static int __maybe_unused atmel_pctrl_suspend(struct device *dev)
  712. {
  713. struct platform_device *pdev = to_platform_device(dev);
  714. struct atmel_pioctrl *atmel_pioctrl = platform_get_drvdata(pdev);
  715. int i, j;
  716. /*
  717. * For each bank, save IMR to restore it later and disable all GPIO
  718. * interrupts excepting the ones marked as wakeup sources.
  719. */
  720. for (i = 0; i < atmel_pioctrl->nbanks; i++) {
  721. atmel_pioctrl->pm_suspend_backup[i].imr =
  722. atmel_gpio_read(atmel_pioctrl, i, ATMEL_PIO_IMR);
  723. atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_IDR,
  724. ~atmel_pioctrl->pm_wakeup_sources[i]);
  725. atmel_pioctrl->pm_suspend_backup[i].odsr =
  726. atmel_gpio_read(atmel_pioctrl, i, ATMEL_PIO_ODSR);
  727. for (j = 0; j < ATMEL_PIO_NPINS_PER_BANK; j++) {
  728. atmel_gpio_write(atmel_pioctrl, i,
  729. ATMEL_PIO_MSKR, BIT(j));
  730. atmel_pioctrl->pm_suspend_backup[i].cfgr[j] =
  731. atmel_gpio_read(atmel_pioctrl, i,
  732. ATMEL_PIO_CFGR);
  733. }
  734. }
  735. return 0;
  736. }
  737. static int __maybe_unused atmel_pctrl_resume(struct device *dev)
  738. {
  739. struct platform_device *pdev = to_platform_device(dev);
  740. struct atmel_pioctrl *atmel_pioctrl = platform_get_drvdata(pdev);
  741. int i, j;
  742. for (i = 0; i < atmel_pioctrl->nbanks; i++) {
  743. atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_IER,
  744. atmel_pioctrl->pm_suspend_backup[i].imr);
  745. atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_SODR,
  746. atmel_pioctrl->pm_suspend_backup[i].odsr);
  747. for (j = 0; j < ATMEL_PIO_NPINS_PER_BANK; j++) {
  748. atmel_gpio_write(atmel_pioctrl, i,
  749. ATMEL_PIO_MSKR, BIT(j));
  750. atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_CFGR,
  751. atmel_pioctrl->pm_suspend_backup[i].cfgr[j]);
  752. }
  753. }
  754. return 0;
  755. }
  756. static const struct dev_pm_ops atmel_pctrl_pm_ops = {
  757. SET_SYSTEM_SLEEP_PM_OPS(atmel_pctrl_suspend, atmel_pctrl_resume)
  758. };
  759. /*
  760. * The number of banks can be different from a SoC to another one.
  761. * We can have up to 16 banks.
  762. */
  763. static const struct atmel_pioctrl_data atmel_sama5d2_pioctrl_data = {
  764. .nbanks = 4,
  765. };
  766. static const struct of_device_id atmel_pctrl_of_match[] = {
  767. {
  768. .compatible = "atmel,sama5d2-pinctrl",
  769. .data = &atmel_sama5d2_pioctrl_data,
  770. }, {
  771. /* sentinel */
  772. }
  773. };
  774. static int atmel_pinctrl_probe(struct platform_device *pdev)
  775. {
  776. struct device *dev = &pdev->dev;
  777. struct pinctrl_pin_desc *pin_desc;
  778. const char **group_names;
  779. const struct of_device_id *match;
  780. int i, ret;
  781. struct resource *res;
  782. struct atmel_pioctrl *atmel_pioctrl;
  783. struct atmel_pioctrl_data *atmel_pioctrl_data;
  784. atmel_pioctrl = devm_kzalloc(dev, sizeof(*atmel_pioctrl), GFP_KERNEL);
  785. if (!atmel_pioctrl)
  786. return -ENOMEM;
  787. atmel_pioctrl->dev = dev;
  788. atmel_pioctrl->node = dev->of_node;
  789. platform_set_drvdata(pdev, atmel_pioctrl);
  790. match = of_match_node(atmel_pctrl_of_match, dev->of_node);
  791. if (!match) {
  792. dev_err(dev, "unknown compatible string\n");
  793. return -ENODEV;
  794. }
  795. atmel_pioctrl_data = (struct atmel_pioctrl_data *)match->data;
  796. atmel_pioctrl->nbanks = atmel_pioctrl_data->nbanks;
  797. atmel_pioctrl->npins = atmel_pioctrl->nbanks * ATMEL_PIO_NPINS_PER_BANK;
  798. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  799. if (!res) {
  800. dev_err(dev, "unable to get atmel pinctrl resource\n");
  801. return -EINVAL;
  802. }
  803. atmel_pioctrl->reg_base = devm_ioremap_resource(dev, res);
  804. if (IS_ERR(atmel_pioctrl->reg_base))
  805. return -EINVAL;
  806. atmel_pioctrl->clk = devm_clk_get(dev, NULL);
  807. if (IS_ERR(atmel_pioctrl->clk)) {
  808. dev_err(dev, "failed to get clock\n");
  809. return PTR_ERR(atmel_pioctrl->clk);
  810. }
  811. atmel_pioctrl->pins = devm_kzalloc(dev, sizeof(*atmel_pioctrl->pins)
  812. * atmel_pioctrl->npins, GFP_KERNEL);
  813. if (!atmel_pioctrl->pins)
  814. return -ENOMEM;
  815. pin_desc = devm_kzalloc(dev, sizeof(*pin_desc)
  816. * atmel_pioctrl->npins, GFP_KERNEL);
  817. if (!pin_desc)
  818. return -ENOMEM;
  819. atmel_pinctrl_desc.pins = pin_desc;
  820. atmel_pinctrl_desc.npins = atmel_pioctrl->npins;
  821. /* One pin is one group since a pin can achieve all functions. */
  822. group_names = devm_kzalloc(dev, sizeof(*group_names)
  823. * atmel_pioctrl->npins, GFP_KERNEL);
  824. if (!group_names)
  825. return -ENOMEM;
  826. atmel_pioctrl->group_names = group_names;
  827. atmel_pioctrl->groups = devm_kzalloc(&pdev->dev,
  828. sizeof(*atmel_pioctrl->groups) * atmel_pioctrl->npins,
  829. GFP_KERNEL);
  830. if (!atmel_pioctrl->groups)
  831. return -ENOMEM;
  832. for (i = 0 ; i < atmel_pioctrl->npins; i++) {
  833. struct atmel_group *group = atmel_pioctrl->groups + i;
  834. unsigned bank = ATMEL_PIO_BANK(i);
  835. unsigned line = ATMEL_PIO_LINE(i);
  836. atmel_pioctrl->pins[i] = devm_kzalloc(dev,
  837. sizeof(**atmel_pioctrl->pins), GFP_KERNEL);
  838. if (!atmel_pioctrl->pins[i])
  839. return -ENOMEM;
  840. atmel_pioctrl->pins[i]->pin_id = i;
  841. atmel_pioctrl->pins[i]->bank = bank;
  842. atmel_pioctrl->pins[i]->line = line;
  843. pin_desc[i].number = i;
  844. /* Pin naming convention: P(bank_name)(bank_pin_number). */
  845. pin_desc[i].name = kasprintf(GFP_KERNEL, "P%c%d",
  846. bank + 'A', line);
  847. group->name = group_names[i] = pin_desc[i].name;
  848. group->pin = pin_desc[i].number;
  849. dev_dbg(dev, "pin_id=%u, bank=%u, line=%u", i, bank, line);
  850. }
  851. atmel_pioctrl->gpio_chip = &atmel_gpio_chip;
  852. atmel_pioctrl->gpio_chip->of_node = dev->of_node;
  853. atmel_pioctrl->gpio_chip->ngpio = atmel_pioctrl->npins;
  854. atmel_pioctrl->gpio_chip->label = dev_name(dev);
  855. atmel_pioctrl->gpio_chip->parent = dev;
  856. atmel_pioctrl->gpio_chip->names = atmel_pioctrl->group_names;
  857. atmel_pioctrl->pm_wakeup_sources = devm_kzalloc(dev,
  858. sizeof(*atmel_pioctrl->pm_wakeup_sources)
  859. * atmel_pioctrl->nbanks, GFP_KERNEL);
  860. if (!atmel_pioctrl->pm_wakeup_sources)
  861. return -ENOMEM;
  862. atmel_pioctrl->pm_suspend_backup = devm_kzalloc(dev,
  863. sizeof(*atmel_pioctrl->pm_suspend_backup)
  864. * atmel_pioctrl->nbanks, GFP_KERNEL);
  865. if (!atmel_pioctrl->pm_suspend_backup)
  866. return -ENOMEM;
  867. atmel_pioctrl->irqs = devm_kzalloc(dev, sizeof(*atmel_pioctrl->irqs)
  868. * atmel_pioctrl->nbanks, GFP_KERNEL);
  869. if (!atmel_pioctrl->irqs)
  870. return -ENOMEM;
  871. /* There is one controller but each bank has its own irq line. */
  872. for (i = 0; i < atmel_pioctrl->nbanks; i++) {
  873. res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
  874. if (!res) {
  875. dev_err(dev, "missing irq resource for group %c\n",
  876. 'A' + i);
  877. return -EINVAL;
  878. }
  879. atmel_pioctrl->irqs[i] = res->start;
  880. irq_set_chained_handler(res->start, atmel_gpio_irq_handler);
  881. irq_set_handler_data(res->start, atmel_pioctrl);
  882. dev_dbg(dev, "bank %i: irq=%pr\n", i, res);
  883. }
  884. atmel_pioctrl->irq_domain = irq_domain_add_linear(dev->of_node,
  885. atmel_pioctrl->gpio_chip->ngpio,
  886. &irq_domain_simple_ops, NULL);
  887. if (!atmel_pioctrl->irq_domain) {
  888. dev_err(dev, "can't add the irq domain\n");
  889. return -ENODEV;
  890. }
  891. atmel_pioctrl->irq_domain->name = "atmel gpio";
  892. for (i = 0; i < atmel_pioctrl->npins; i++) {
  893. int irq = irq_create_mapping(atmel_pioctrl->irq_domain, i);
  894. irq_set_chip_and_handler(irq, &atmel_gpio_irq_chip,
  895. handle_simple_irq);
  896. irq_set_chip_data(irq, atmel_pioctrl);
  897. dev_dbg(dev,
  898. "atmel gpio irq domain: hwirq: %d, linux irq: %d\n",
  899. i, irq);
  900. }
  901. ret = clk_prepare_enable(atmel_pioctrl->clk);
  902. if (ret) {
  903. dev_err(dev, "failed to prepare and enable clock\n");
  904. goto clk_prepare_enable_error;
  905. }
  906. atmel_pioctrl->pinctrl_dev = devm_pinctrl_register(&pdev->dev,
  907. &atmel_pinctrl_desc,
  908. atmel_pioctrl);
  909. if (IS_ERR(atmel_pioctrl->pinctrl_dev)) {
  910. ret = PTR_ERR(atmel_pioctrl->pinctrl_dev);
  911. dev_err(dev, "pinctrl registration failed\n");
  912. goto clk_unprep;
  913. }
  914. ret = gpiochip_add_data(atmel_pioctrl->gpio_chip, atmel_pioctrl);
  915. if (ret) {
  916. dev_err(dev, "failed to add gpiochip\n");
  917. goto clk_unprep;
  918. }
  919. ret = gpiochip_add_pin_range(atmel_pioctrl->gpio_chip, dev_name(dev),
  920. 0, 0, atmel_pioctrl->gpio_chip->ngpio);
  921. if (ret) {
  922. dev_err(dev, "failed to add gpio pin range\n");
  923. goto gpiochip_add_pin_range_error;
  924. }
  925. dev_info(&pdev->dev, "atmel pinctrl initialized\n");
  926. return 0;
  927. gpiochip_add_pin_range_error:
  928. gpiochip_remove(atmel_pioctrl->gpio_chip);
  929. clk_unprep:
  930. clk_disable_unprepare(atmel_pioctrl->clk);
  931. clk_prepare_enable_error:
  932. irq_domain_remove(atmel_pioctrl->irq_domain);
  933. return ret;
  934. }
  935. static struct platform_driver atmel_pinctrl_driver = {
  936. .driver = {
  937. .name = "pinctrl-at91-pio4",
  938. .of_match_table = atmel_pctrl_of_match,
  939. .pm = &atmel_pctrl_pm_ops,
  940. .suppress_bind_attrs = true,
  941. },
  942. .probe = atmel_pinctrl_probe,
  943. };
  944. builtin_platform_driver(atmel_pinctrl_driver);