pinctrl-intel.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. /*
  2. * Intel pinctrl/GPIO core driver.
  3. *
  4. * Copyright (C) 2015, Intel Corporation
  5. * Authors: Mathias Nyman <mathias.nyman@linux.intel.com>
  6. * Mika Westerberg <mika.westerberg@linux.intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/gpio/driver.h>
  15. #include <linux/log2.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pinctrl/pinctrl.h>
  18. #include <linux/pinctrl/pinmux.h>
  19. #include <linux/pinctrl/pinconf.h>
  20. #include <linux/pinctrl/pinconf-generic.h>
  21. #include "../core.h"
  22. #include "pinctrl-intel.h"
  23. /* Offset from regs */
  24. #define REVID 0x000
  25. #define REVID_SHIFT 16
  26. #define REVID_MASK GENMASK(31, 16)
  27. #define PADBAR 0x00c
  28. #define GPI_IS 0x100
  29. #define GPI_GPE_STS 0x140
  30. #define GPI_GPE_EN 0x160
  31. #define PADOWN_BITS 4
  32. #define PADOWN_SHIFT(p) ((p) % 8 * PADOWN_BITS)
  33. #define PADOWN_MASK(p) (0xf << PADOWN_SHIFT(p))
  34. #define PADOWN_GPP(p) ((p) / 8)
  35. /* Offset from pad_regs */
  36. #define PADCFG0 0x000
  37. #define PADCFG0_RXEVCFG_SHIFT 25
  38. #define PADCFG0_RXEVCFG_MASK (3 << PADCFG0_RXEVCFG_SHIFT)
  39. #define PADCFG0_RXEVCFG_LEVEL 0
  40. #define PADCFG0_RXEVCFG_EDGE 1
  41. #define PADCFG0_RXEVCFG_DISABLED 2
  42. #define PADCFG0_RXEVCFG_EDGE_BOTH 3
  43. #define PADCFG0_PREGFRXSEL BIT(24)
  44. #define PADCFG0_RXINV BIT(23)
  45. #define PADCFG0_GPIROUTIOXAPIC BIT(20)
  46. #define PADCFG0_GPIROUTSCI BIT(19)
  47. #define PADCFG0_GPIROUTSMI BIT(18)
  48. #define PADCFG0_GPIROUTNMI BIT(17)
  49. #define PADCFG0_PMODE_SHIFT 10
  50. #define PADCFG0_PMODE_MASK (0xf << PADCFG0_PMODE_SHIFT)
  51. #define PADCFG0_GPIORXDIS BIT(9)
  52. #define PADCFG0_GPIOTXDIS BIT(8)
  53. #define PADCFG0_GPIORXSTATE BIT(1)
  54. #define PADCFG0_GPIOTXSTATE BIT(0)
  55. #define PADCFG1 0x004
  56. #define PADCFG1_TERM_UP BIT(13)
  57. #define PADCFG1_TERM_SHIFT 10
  58. #define PADCFG1_TERM_MASK (7 << PADCFG1_TERM_SHIFT)
  59. #define PADCFG1_TERM_20K 4
  60. #define PADCFG1_TERM_2K 3
  61. #define PADCFG1_TERM_5K 2
  62. #define PADCFG1_TERM_1K 1
  63. #define PADCFG2 0x008
  64. #define PADCFG2_DEBEN BIT(0)
  65. #define PADCFG2_DEBOUNCE_SHIFT 1
  66. #define PADCFG2_DEBOUNCE_MASK GENMASK(4, 1)
  67. #define DEBOUNCE_PERIOD 31250 /* ns */
  68. struct intel_pad_context {
  69. u32 padcfg0;
  70. u32 padcfg1;
  71. u32 padcfg2;
  72. };
  73. struct intel_community_context {
  74. u32 *intmask;
  75. };
  76. struct intel_pinctrl_context {
  77. struct intel_pad_context *pads;
  78. struct intel_community_context *communities;
  79. };
  80. /**
  81. * struct intel_pinctrl - Intel pinctrl private structure
  82. * @dev: Pointer to the device structure
  83. * @lock: Lock to serialize register access
  84. * @pctldesc: Pin controller description
  85. * @pctldev: Pointer to the pin controller device
  86. * @chip: GPIO chip in this pin controller
  87. * @soc: SoC/PCH specific pin configuration data
  88. * @communities: All communities in this pin controller
  89. * @ncommunities: Number of communities in this pin controller
  90. * @context: Configuration saved over system sleep
  91. * @irq: pinctrl/GPIO chip irq number
  92. */
  93. struct intel_pinctrl {
  94. struct device *dev;
  95. raw_spinlock_t lock;
  96. struct pinctrl_desc pctldesc;
  97. struct pinctrl_dev *pctldev;
  98. struct gpio_chip chip;
  99. const struct intel_pinctrl_soc_data *soc;
  100. struct intel_community *communities;
  101. size_t ncommunities;
  102. struct intel_pinctrl_context context;
  103. int irq;
  104. };
  105. #define pin_to_padno(c, p) ((p) - (c)->pin_base)
  106. static struct intel_community *intel_get_community(struct intel_pinctrl *pctrl,
  107. unsigned pin)
  108. {
  109. struct intel_community *community;
  110. int i;
  111. for (i = 0; i < pctrl->ncommunities; i++) {
  112. community = &pctrl->communities[i];
  113. if (pin >= community->pin_base &&
  114. pin < community->pin_base + community->npins)
  115. return community;
  116. }
  117. dev_warn(pctrl->dev, "failed to find community for pin %u\n", pin);
  118. return NULL;
  119. }
  120. static void __iomem *intel_get_padcfg(struct intel_pinctrl *pctrl, unsigned pin,
  121. unsigned reg)
  122. {
  123. const struct intel_community *community;
  124. unsigned padno;
  125. size_t nregs;
  126. community = intel_get_community(pctrl, pin);
  127. if (!community)
  128. return NULL;
  129. padno = pin_to_padno(community, pin);
  130. nregs = (community->features & PINCTRL_FEATURE_DEBOUNCE) ? 4 : 2;
  131. if (reg == PADCFG2 && !(community->features & PINCTRL_FEATURE_DEBOUNCE))
  132. return NULL;
  133. return community->pad_regs + reg + padno * nregs * 4;
  134. }
  135. static bool intel_pad_owned_by_host(struct intel_pinctrl *pctrl, unsigned pin)
  136. {
  137. const struct intel_community *community;
  138. unsigned padno, gpp, offset, group;
  139. void __iomem *padown;
  140. community = intel_get_community(pctrl, pin);
  141. if (!community)
  142. return false;
  143. if (!community->padown_offset)
  144. return true;
  145. padno = pin_to_padno(community, pin);
  146. group = padno / community->gpp_size;
  147. gpp = PADOWN_GPP(padno % community->gpp_size);
  148. offset = community->padown_offset + 0x10 * group + gpp * 4;
  149. padown = community->regs + offset;
  150. return !(readl(padown) & PADOWN_MASK(padno));
  151. }
  152. static bool intel_pad_acpi_mode(struct intel_pinctrl *pctrl, unsigned pin)
  153. {
  154. const struct intel_community *community;
  155. unsigned padno, gpp, offset;
  156. void __iomem *hostown;
  157. community = intel_get_community(pctrl, pin);
  158. if (!community)
  159. return true;
  160. if (!community->hostown_offset)
  161. return false;
  162. padno = pin_to_padno(community, pin);
  163. gpp = padno / community->gpp_size;
  164. offset = community->hostown_offset + gpp * 4;
  165. hostown = community->regs + offset;
  166. return !(readl(hostown) & BIT(padno % community->gpp_size));
  167. }
  168. static bool intel_pad_locked(struct intel_pinctrl *pctrl, unsigned pin)
  169. {
  170. struct intel_community *community;
  171. unsigned padno, gpp, offset;
  172. u32 value;
  173. community = intel_get_community(pctrl, pin);
  174. if (!community)
  175. return true;
  176. if (!community->padcfglock_offset)
  177. return false;
  178. padno = pin_to_padno(community, pin);
  179. gpp = padno / community->gpp_size;
  180. /*
  181. * If PADCFGLOCK and PADCFGLOCKTX bits are both clear for this pad,
  182. * the pad is considered unlocked. Any other case means that it is
  183. * either fully or partially locked and we don't touch it.
  184. */
  185. offset = community->padcfglock_offset + gpp * 8;
  186. value = readl(community->regs + offset);
  187. if (value & BIT(pin % community->gpp_size))
  188. return true;
  189. offset = community->padcfglock_offset + 4 + gpp * 8;
  190. value = readl(community->regs + offset);
  191. if (value & BIT(pin % community->gpp_size))
  192. return true;
  193. return false;
  194. }
  195. static bool intel_pad_usable(struct intel_pinctrl *pctrl, unsigned pin)
  196. {
  197. return intel_pad_owned_by_host(pctrl, pin) &&
  198. !intel_pad_locked(pctrl, pin);
  199. }
  200. static int intel_get_groups_count(struct pinctrl_dev *pctldev)
  201. {
  202. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  203. return pctrl->soc->ngroups;
  204. }
  205. static const char *intel_get_group_name(struct pinctrl_dev *pctldev,
  206. unsigned group)
  207. {
  208. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  209. return pctrl->soc->groups[group].name;
  210. }
  211. static int intel_get_group_pins(struct pinctrl_dev *pctldev, unsigned group,
  212. const unsigned **pins, unsigned *npins)
  213. {
  214. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  215. *pins = pctrl->soc->groups[group].pins;
  216. *npins = pctrl->soc->groups[group].npins;
  217. return 0;
  218. }
  219. static void intel_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  220. unsigned pin)
  221. {
  222. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  223. void __iomem *padcfg;
  224. u32 cfg0, cfg1, mode;
  225. bool locked, acpi;
  226. if (!intel_pad_owned_by_host(pctrl, pin)) {
  227. seq_puts(s, "not available");
  228. return;
  229. }
  230. cfg0 = readl(intel_get_padcfg(pctrl, pin, PADCFG0));
  231. cfg1 = readl(intel_get_padcfg(pctrl, pin, PADCFG1));
  232. mode = (cfg0 & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT;
  233. if (!mode)
  234. seq_puts(s, "GPIO ");
  235. else
  236. seq_printf(s, "mode %d ", mode);
  237. seq_printf(s, "0x%08x 0x%08x", cfg0, cfg1);
  238. /* Dump the additional PADCFG registers if available */
  239. padcfg = intel_get_padcfg(pctrl, pin, PADCFG2);
  240. if (padcfg)
  241. seq_printf(s, " 0x%08x", readl(padcfg));
  242. locked = intel_pad_locked(pctrl, pin);
  243. acpi = intel_pad_acpi_mode(pctrl, pin);
  244. if (locked || acpi) {
  245. seq_puts(s, " [");
  246. if (locked) {
  247. seq_puts(s, "LOCKED");
  248. if (acpi)
  249. seq_puts(s, ", ");
  250. }
  251. if (acpi)
  252. seq_puts(s, "ACPI");
  253. seq_puts(s, "]");
  254. }
  255. }
  256. static const struct pinctrl_ops intel_pinctrl_ops = {
  257. .get_groups_count = intel_get_groups_count,
  258. .get_group_name = intel_get_group_name,
  259. .get_group_pins = intel_get_group_pins,
  260. .pin_dbg_show = intel_pin_dbg_show,
  261. };
  262. static int intel_get_functions_count(struct pinctrl_dev *pctldev)
  263. {
  264. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  265. return pctrl->soc->nfunctions;
  266. }
  267. static const char *intel_get_function_name(struct pinctrl_dev *pctldev,
  268. unsigned function)
  269. {
  270. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  271. return pctrl->soc->functions[function].name;
  272. }
  273. static int intel_get_function_groups(struct pinctrl_dev *pctldev,
  274. unsigned function,
  275. const char * const **groups,
  276. unsigned * const ngroups)
  277. {
  278. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  279. *groups = pctrl->soc->functions[function].groups;
  280. *ngroups = pctrl->soc->functions[function].ngroups;
  281. return 0;
  282. }
  283. static int intel_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned function,
  284. unsigned group)
  285. {
  286. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  287. const struct intel_pingroup *grp = &pctrl->soc->groups[group];
  288. unsigned long flags;
  289. int i;
  290. raw_spin_lock_irqsave(&pctrl->lock, flags);
  291. /*
  292. * All pins in the groups needs to be accessible and writable
  293. * before we can enable the mux for this group.
  294. */
  295. for (i = 0; i < grp->npins; i++) {
  296. if (!intel_pad_usable(pctrl, grp->pins[i])) {
  297. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  298. return -EBUSY;
  299. }
  300. }
  301. /* Now enable the mux setting for each pin in the group */
  302. for (i = 0; i < grp->npins; i++) {
  303. void __iomem *padcfg0;
  304. u32 value;
  305. padcfg0 = intel_get_padcfg(pctrl, grp->pins[i], PADCFG0);
  306. value = readl(padcfg0);
  307. value &= ~PADCFG0_PMODE_MASK;
  308. value |= grp->mode << PADCFG0_PMODE_SHIFT;
  309. writel(value, padcfg0);
  310. }
  311. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  312. return 0;
  313. }
  314. static void __intel_gpio_set_direction(void __iomem *padcfg0, bool input)
  315. {
  316. u32 value;
  317. value = readl(padcfg0);
  318. if (input) {
  319. value &= ~PADCFG0_GPIORXDIS;
  320. value |= PADCFG0_GPIOTXDIS;
  321. } else {
  322. value &= ~PADCFG0_GPIOTXDIS;
  323. value |= PADCFG0_GPIORXDIS;
  324. }
  325. writel(value, padcfg0);
  326. }
  327. static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
  328. struct pinctrl_gpio_range *range,
  329. unsigned pin)
  330. {
  331. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  332. void __iomem *padcfg0;
  333. unsigned long flags;
  334. u32 value;
  335. raw_spin_lock_irqsave(&pctrl->lock, flags);
  336. if (!intel_pad_usable(pctrl, pin)) {
  337. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  338. return -EBUSY;
  339. }
  340. padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
  341. /* Put the pad into GPIO mode */
  342. value = readl(padcfg0) & ~PADCFG0_PMODE_MASK;
  343. /* Disable SCI/SMI/NMI generation */
  344. value &= ~(PADCFG0_GPIROUTIOXAPIC | PADCFG0_GPIROUTSCI);
  345. value &= ~(PADCFG0_GPIROUTSMI | PADCFG0_GPIROUTNMI);
  346. writel(value, padcfg0);
  347. /* Disable TX buffer and enable RX (this will be input) */
  348. __intel_gpio_set_direction(padcfg0, true);
  349. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  350. return 0;
  351. }
  352. static int intel_gpio_set_direction(struct pinctrl_dev *pctldev,
  353. struct pinctrl_gpio_range *range,
  354. unsigned pin, bool input)
  355. {
  356. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  357. void __iomem *padcfg0;
  358. unsigned long flags;
  359. raw_spin_lock_irqsave(&pctrl->lock, flags);
  360. padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
  361. __intel_gpio_set_direction(padcfg0, input);
  362. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  363. return 0;
  364. }
  365. static const struct pinmux_ops intel_pinmux_ops = {
  366. .get_functions_count = intel_get_functions_count,
  367. .get_function_name = intel_get_function_name,
  368. .get_function_groups = intel_get_function_groups,
  369. .set_mux = intel_pinmux_set_mux,
  370. .gpio_request_enable = intel_gpio_request_enable,
  371. .gpio_set_direction = intel_gpio_set_direction,
  372. };
  373. static int intel_config_get(struct pinctrl_dev *pctldev, unsigned pin,
  374. unsigned long *config)
  375. {
  376. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  377. enum pin_config_param param = pinconf_to_config_param(*config);
  378. const struct intel_community *community;
  379. u32 value, term;
  380. u32 arg = 0;
  381. if (!intel_pad_owned_by_host(pctrl, pin))
  382. return -ENOTSUPP;
  383. community = intel_get_community(pctrl, pin);
  384. value = readl(intel_get_padcfg(pctrl, pin, PADCFG1));
  385. term = (value & PADCFG1_TERM_MASK) >> PADCFG1_TERM_SHIFT;
  386. switch (param) {
  387. case PIN_CONFIG_BIAS_DISABLE:
  388. if (term)
  389. return -EINVAL;
  390. break;
  391. case PIN_CONFIG_BIAS_PULL_UP:
  392. if (!term || !(value & PADCFG1_TERM_UP))
  393. return -EINVAL;
  394. switch (term) {
  395. case PADCFG1_TERM_1K:
  396. arg = 1000;
  397. break;
  398. case PADCFG1_TERM_2K:
  399. arg = 2000;
  400. break;
  401. case PADCFG1_TERM_5K:
  402. arg = 5000;
  403. break;
  404. case PADCFG1_TERM_20K:
  405. arg = 20000;
  406. break;
  407. }
  408. break;
  409. case PIN_CONFIG_BIAS_PULL_DOWN:
  410. if (!term || value & PADCFG1_TERM_UP)
  411. return -EINVAL;
  412. switch (term) {
  413. case PADCFG1_TERM_1K:
  414. if (!(community->features & PINCTRL_FEATURE_1K_PD))
  415. return -EINVAL;
  416. arg = 1000;
  417. break;
  418. case PADCFG1_TERM_5K:
  419. arg = 5000;
  420. break;
  421. case PADCFG1_TERM_20K:
  422. arg = 20000;
  423. break;
  424. }
  425. break;
  426. case PIN_CONFIG_INPUT_DEBOUNCE: {
  427. void __iomem *padcfg2;
  428. u32 v;
  429. padcfg2 = intel_get_padcfg(pctrl, pin, PADCFG2);
  430. if (!padcfg2)
  431. return -ENOTSUPP;
  432. v = readl(padcfg2);
  433. if (!(v & PADCFG2_DEBEN))
  434. return -EINVAL;
  435. v = (v & PADCFG2_DEBOUNCE_MASK) >> PADCFG2_DEBOUNCE_SHIFT;
  436. arg = BIT(v) * DEBOUNCE_PERIOD / 1000;
  437. break;
  438. }
  439. default:
  440. return -ENOTSUPP;
  441. }
  442. *config = pinconf_to_config_packed(param, arg);
  443. return 0;
  444. }
  445. static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned pin,
  446. unsigned long config)
  447. {
  448. unsigned param = pinconf_to_config_param(config);
  449. unsigned arg = pinconf_to_config_argument(config);
  450. const struct intel_community *community;
  451. void __iomem *padcfg1;
  452. unsigned long flags;
  453. int ret = 0;
  454. u32 value;
  455. raw_spin_lock_irqsave(&pctrl->lock, flags);
  456. community = intel_get_community(pctrl, pin);
  457. padcfg1 = intel_get_padcfg(pctrl, pin, PADCFG1);
  458. value = readl(padcfg1);
  459. switch (param) {
  460. case PIN_CONFIG_BIAS_DISABLE:
  461. value &= ~(PADCFG1_TERM_MASK | PADCFG1_TERM_UP);
  462. break;
  463. case PIN_CONFIG_BIAS_PULL_UP:
  464. value &= ~PADCFG1_TERM_MASK;
  465. value |= PADCFG1_TERM_UP;
  466. switch (arg) {
  467. case 20000:
  468. value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT;
  469. break;
  470. case 5000:
  471. value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT;
  472. break;
  473. case 2000:
  474. value |= PADCFG1_TERM_2K << PADCFG1_TERM_SHIFT;
  475. break;
  476. case 1000:
  477. value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT;
  478. break;
  479. default:
  480. ret = -EINVAL;
  481. }
  482. break;
  483. case PIN_CONFIG_BIAS_PULL_DOWN:
  484. value &= ~(PADCFG1_TERM_UP | PADCFG1_TERM_MASK);
  485. switch (arg) {
  486. case 20000:
  487. value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT;
  488. break;
  489. case 5000:
  490. value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT;
  491. break;
  492. case 1000:
  493. if (!(community->features & PINCTRL_FEATURE_1K_PD)) {
  494. ret = -EINVAL;
  495. break;
  496. }
  497. value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT;
  498. break;
  499. default:
  500. ret = -EINVAL;
  501. }
  502. break;
  503. }
  504. if (!ret)
  505. writel(value, padcfg1);
  506. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  507. return ret;
  508. }
  509. static int intel_config_set_debounce(struct intel_pinctrl *pctrl, unsigned pin,
  510. unsigned debounce)
  511. {
  512. void __iomem *padcfg0, *padcfg2;
  513. unsigned long flags;
  514. u32 value0, value2;
  515. int ret = 0;
  516. padcfg2 = intel_get_padcfg(pctrl, pin, PADCFG2);
  517. if (!padcfg2)
  518. return -ENOTSUPP;
  519. padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
  520. raw_spin_lock_irqsave(&pctrl->lock, flags);
  521. value0 = readl(padcfg0);
  522. value2 = readl(padcfg2);
  523. /* Disable glitch filter and debouncer */
  524. value0 &= ~PADCFG0_PREGFRXSEL;
  525. value2 &= ~(PADCFG2_DEBEN | PADCFG2_DEBOUNCE_MASK);
  526. if (debounce) {
  527. unsigned long v;
  528. v = order_base_2(debounce * 1000 / DEBOUNCE_PERIOD);
  529. if (v < 3 || v > 15) {
  530. ret = -EINVAL;
  531. goto exit_unlock;
  532. } else {
  533. /* Enable glitch filter and debouncer */
  534. value0 |= PADCFG0_PREGFRXSEL;
  535. value2 |= v << PADCFG2_DEBOUNCE_SHIFT;
  536. value2 |= PADCFG2_DEBEN;
  537. }
  538. }
  539. writel(value0, padcfg0);
  540. writel(value2, padcfg2);
  541. exit_unlock:
  542. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  543. return ret;
  544. }
  545. static int intel_config_set(struct pinctrl_dev *pctldev, unsigned pin,
  546. unsigned long *configs, unsigned nconfigs)
  547. {
  548. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  549. int i, ret;
  550. if (!intel_pad_usable(pctrl, pin))
  551. return -ENOTSUPP;
  552. for (i = 0; i < nconfigs; i++) {
  553. switch (pinconf_to_config_param(configs[i])) {
  554. case PIN_CONFIG_BIAS_DISABLE:
  555. case PIN_CONFIG_BIAS_PULL_UP:
  556. case PIN_CONFIG_BIAS_PULL_DOWN:
  557. ret = intel_config_set_pull(pctrl, pin, configs[i]);
  558. if (ret)
  559. return ret;
  560. break;
  561. case PIN_CONFIG_INPUT_DEBOUNCE:
  562. ret = intel_config_set_debounce(pctrl, pin,
  563. pinconf_to_config_argument(configs[i]));
  564. if (ret)
  565. return ret;
  566. break;
  567. default:
  568. return -ENOTSUPP;
  569. }
  570. }
  571. return 0;
  572. }
  573. static const struct pinconf_ops intel_pinconf_ops = {
  574. .is_generic = true,
  575. .pin_config_get = intel_config_get,
  576. .pin_config_set = intel_config_set,
  577. };
  578. static const struct pinctrl_desc intel_pinctrl_desc = {
  579. .pctlops = &intel_pinctrl_ops,
  580. .pmxops = &intel_pinmux_ops,
  581. .confops = &intel_pinconf_ops,
  582. .owner = THIS_MODULE,
  583. };
  584. static int intel_gpio_get(struct gpio_chip *chip, unsigned offset)
  585. {
  586. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  587. void __iomem *reg;
  588. reg = intel_get_padcfg(pctrl, offset, PADCFG0);
  589. if (!reg)
  590. return -EINVAL;
  591. return !!(readl(reg) & PADCFG0_GPIORXSTATE);
  592. }
  593. static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  594. {
  595. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  596. void __iomem *reg;
  597. reg = intel_get_padcfg(pctrl, offset, PADCFG0);
  598. if (reg) {
  599. unsigned long flags;
  600. u32 padcfg0;
  601. raw_spin_lock_irqsave(&pctrl->lock, flags);
  602. padcfg0 = readl(reg);
  603. if (value)
  604. padcfg0 |= PADCFG0_GPIOTXSTATE;
  605. else
  606. padcfg0 &= ~PADCFG0_GPIOTXSTATE;
  607. writel(padcfg0, reg);
  608. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  609. }
  610. }
  611. static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  612. {
  613. return pinctrl_gpio_direction_input(chip->base + offset);
  614. }
  615. static int intel_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
  616. int value)
  617. {
  618. intel_gpio_set(chip, offset, value);
  619. return pinctrl_gpio_direction_output(chip->base + offset);
  620. }
  621. static const struct gpio_chip intel_gpio_chip = {
  622. .owner = THIS_MODULE,
  623. .request = gpiochip_generic_request,
  624. .free = gpiochip_generic_free,
  625. .direction_input = intel_gpio_direction_input,
  626. .direction_output = intel_gpio_direction_output,
  627. .get = intel_gpio_get,
  628. .set = intel_gpio_set,
  629. .set_config = gpiochip_generic_config,
  630. };
  631. static void intel_gpio_irq_ack(struct irq_data *d)
  632. {
  633. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  634. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  635. const struct intel_community *community;
  636. unsigned pin = irqd_to_hwirq(d);
  637. raw_spin_lock(&pctrl->lock);
  638. community = intel_get_community(pctrl, pin);
  639. if (community) {
  640. unsigned padno = pin_to_padno(community, pin);
  641. unsigned gpp_offset = padno % community->gpp_size;
  642. unsigned gpp = padno / community->gpp_size;
  643. writel(BIT(gpp_offset), community->regs + GPI_IS + gpp * 4);
  644. }
  645. raw_spin_unlock(&pctrl->lock);
  646. }
  647. static void intel_gpio_irq_enable(struct irq_data *d)
  648. {
  649. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  650. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  651. const struct intel_community *community;
  652. unsigned pin = irqd_to_hwirq(d);
  653. unsigned long flags;
  654. raw_spin_lock_irqsave(&pctrl->lock, flags);
  655. community = intel_get_community(pctrl, pin);
  656. if (community) {
  657. unsigned padno = pin_to_padno(community, pin);
  658. unsigned gpp_size = community->gpp_size;
  659. unsigned gpp_offset = padno % gpp_size;
  660. unsigned gpp = padno / gpp_size;
  661. u32 value;
  662. /* Clear interrupt status first to avoid unexpected interrupt */
  663. writel(BIT(gpp_offset), community->regs + GPI_IS + gpp * 4);
  664. value = readl(community->regs + community->ie_offset + gpp * 4);
  665. value |= BIT(gpp_offset);
  666. writel(value, community->regs + community->ie_offset + gpp * 4);
  667. }
  668. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  669. }
  670. static void intel_gpio_irq_mask_unmask(struct irq_data *d, bool mask)
  671. {
  672. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  673. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  674. const struct intel_community *community;
  675. unsigned pin = irqd_to_hwirq(d);
  676. unsigned long flags;
  677. raw_spin_lock_irqsave(&pctrl->lock, flags);
  678. community = intel_get_community(pctrl, pin);
  679. if (community) {
  680. unsigned padno = pin_to_padno(community, pin);
  681. unsigned gpp_offset = padno % community->gpp_size;
  682. unsigned gpp = padno / community->gpp_size;
  683. void __iomem *reg;
  684. u32 value;
  685. reg = community->regs + community->ie_offset + gpp * 4;
  686. value = readl(reg);
  687. if (mask)
  688. value &= ~BIT(gpp_offset);
  689. else
  690. value |= BIT(gpp_offset);
  691. writel(value, reg);
  692. }
  693. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  694. }
  695. static void intel_gpio_irq_mask(struct irq_data *d)
  696. {
  697. intel_gpio_irq_mask_unmask(d, true);
  698. }
  699. static void intel_gpio_irq_unmask(struct irq_data *d)
  700. {
  701. intel_gpio_irq_mask_unmask(d, false);
  702. }
  703. static int intel_gpio_irq_type(struct irq_data *d, unsigned type)
  704. {
  705. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  706. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  707. unsigned pin = irqd_to_hwirq(d);
  708. unsigned long flags;
  709. void __iomem *reg;
  710. u32 value;
  711. reg = intel_get_padcfg(pctrl, pin, PADCFG0);
  712. if (!reg)
  713. return -EINVAL;
  714. /*
  715. * If the pin is in ACPI mode it is still usable as a GPIO but it
  716. * cannot be used as IRQ because GPI_IS status bit will not be
  717. * updated by the host controller hardware.
  718. */
  719. if (intel_pad_acpi_mode(pctrl, pin)) {
  720. dev_warn(pctrl->dev, "pin %u cannot be used as IRQ\n", pin);
  721. return -EPERM;
  722. }
  723. raw_spin_lock_irqsave(&pctrl->lock, flags);
  724. value = readl(reg);
  725. value &= ~(PADCFG0_RXEVCFG_MASK | PADCFG0_RXINV);
  726. if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) {
  727. value |= PADCFG0_RXEVCFG_EDGE_BOTH << PADCFG0_RXEVCFG_SHIFT;
  728. } else if (type & IRQ_TYPE_EDGE_FALLING) {
  729. value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT;
  730. value |= PADCFG0_RXINV;
  731. } else if (type & IRQ_TYPE_EDGE_RISING) {
  732. value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT;
  733. } else if (type & IRQ_TYPE_LEVEL_MASK) {
  734. if (type & IRQ_TYPE_LEVEL_LOW)
  735. value |= PADCFG0_RXINV;
  736. } else {
  737. value |= PADCFG0_RXEVCFG_DISABLED << PADCFG0_RXEVCFG_SHIFT;
  738. }
  739. writel(value, reg);
  740. if (type & IRQ_TYPE_EDGE_BOTH)
  741. irq_set_handler_locked(d, handle_edge_irq);
  742. else if (type & IRQ_TYPE_LEVEL_MASK)
  743. irq_set_handler_locked(d, handle_level_irq);
  744. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  745. return 0;
  746. }
  747. static int intel_gpio_irq_wake(struct irq_data *d, unsigned int on)
  748. {
  749. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  750. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  751. unsigned pin = irqd_to_hwirq(d);
  752. if (on)
  753. enable_irq_wake(pctrl->irq);
  754. else
  755. disable_irq_wake(pctrl->irq);
  756. dev_dbg(pctrl->dev, "%sable wake for pin %u\n", on ? "en" : "dis", pin);
  757. return 0;
  758. }
  759. static irqreturn_t intel_gpio_community_irq_handler(struct intel_pinctrl *pctrl,
  760. const struct intel_community *community)
  761. {
  762. struct gpio_chip *gc = &pctrl->chip;
  763. irqreturn_t ret = IRQ_NONE;
  764. int gpp;
  765. for (gpp = 0; gpp < community->ngpps; gpp++) {
  766. unsigned long pending, enabled, gpp_offset;
  767. pending = readl(community->regs + GPI_IS + gpp * 4);
  768. enabled = readl(community->regs + community->ie_offset +
  769. gpp * 4);
  770. /* Only interrupts that are enabled */
  771. pending &= enabled;
  772. for_each_set_bit(gpp_offset, &pending, community->gpp_size) {
  773. unsigned padno, irq;
  774. /*
  775. * The last group in community can have less pins
  776. * than NPADS_IN_GPP.
  777. */
  778. padno = gpp_offset + gpp * community->gpp_size;
  779. if (padno >= community->npins)
  780. break;
  781. irq = irq_find_mapping(gc->irqdomain,
  782. community->pin_base + padno);
  783. generic_handle_irq(irq);
  784. ret |= IRQ_HANDLED;
  785. }
  786. }
  787. return ret;
  788. }
  789. static irqreturn_t intel_gpio_irq(int irq, void *data)
  790. {
  791. const struct intel_community *community;
  792. struct intel_pinctrl *pctrl = data;
  793. irqreturn_t ret = IRQ_NONE;
  794. int i;
  795. /* Need to check all communities for pending interrupts */
  796. for (i = 0; i < pctrl->ncommunities; i++) {
  797. community = &pctrl->communities[i];
  798. ret |= intel_gpio_community_irq_handler(pctrl, community);
  799. }
  800. return ret;
  801. }
  802. static struct irq_chip intel_gpio_irqchip = {
  803. .name = "intel-gpio",
  804. .irq_enable = intel_gpio_irq_enable,
  805. .irq_ack = intel_gpio_irq_ack,
  806. .irq_mask = intel_gpio_irq_mask,
  807. .irq_unmask = intel_gpio_irq_unmask,
  808. .irq_set_type = intel_gpio_irq_type,
  809. .irq_set_wake = intel_gpio_irq_wake,
  810. };
  811. static int intel_gpio_probe(struct intel_pinctrl *pctrl, int irq)
  812. {
  813. int ret;
  814. pctrl->chip = intel_gpio_chip;
  815. pctrl->chip.ngpio = pctrl->soc->npins;
  816. pctrl->chip.label = dev_name(pctrl->dev);
  817. pctrl->chip.parent = pctrl->dev;
  818. pctrl->chip.base = -1;
  819. pctrl->irq = irq;
  820. ret = devm_gpiochip_add_data(pctrl->dev, &pctrl->chip, pctrl);
  821. if (ret) {
  822. dev_err(pctrl->dev, "failed to register gpiochip\n");
  823. return ret;
  824. }
  825. ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev),
  826. 0, 0, pctrl->soc->npins);
  827. if (ret) {
  828. dev_err(pctrl->dev, "failed to add GPIO pin range\n");
  829. return ret;
  830. }
  831. /*
  832. * We need to request the interrupt here (instead of providing chip
  833. * to the irq directly) because on some platforms several GPIO
  834. * controllers share the same interrupt line.
  835. */
  836. ret = devm_request_irq(pctrl->dev, irq, intel_gpio_irq,
  837. IRQF_SHARED | IRQF_NO_THREAD,
  838. dev_name(pctrl->dev), pctrl);
  839. if (ret) {
  840. dev_err(pctrl->dev, "failed to request interrupt\n");
  841. return ret;
  842. }
  843. ret = gpiochip_irqchip_add(&pctrl->chip, &intel_gpio_irqchip, 0,
  844. handle_bad_irq, IRQ_TYPE_NONE);
  845. if (ret) {
  846. dev_err(pctrl->dev, "failed to add irqchip\n");
  847. return ret;
  848. }
  849. gpiochip_set_chained_irqchip(&pctrl->chip, &intel_gpio_irqchip, irq,
  850. NULL);
  851. return 0;
  852. }
  853. static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
  854. {
  855. #ifdef CONFIG_PM_SLEEP
  856. const struct intel_pinctrl_soc_data *soc = pctrl->soc;
  857. struct intel_community_context *communities;
  858. struct intel_pad_context *pads;
  859. int i;
  860. pads = devm_kcalloc(pctrl->dev, soc->npins, sizeof(*pads), GFP_KERNEL);
  861. if (!pads)
  862. return -ENOMEM;
  863. communities = devm_kcalloc(pctrl->dev, pctrl->ncommunities,
  864. sizeof(*communities), GFP_KERNEL);
  865. if (!communities)
  866. return -ENOMEM;
  867. for (i = 0; i < pctrl->ncommunities; i++) {
  868. struct intel_community *community = &pctrl->communities[i];
  869. u32 *intmask;
  870. intmask = devm_kcalloc(pctrl->dev, community->ngpps,
  871. sizeof(*intmask), GFP_KERNEL);
  872. if (!intmask)
  873. return -ENOMEM;
  874. communities[i].intmask = intmask;
  875. }
  876. pctrl->context.pads = pads;
  877. pctrl->context.communities = communities;
  878. #endif
  879. return 0;
  880. }
  881. int intel_pinctrl_probe(struct platform_device *pdev,
  882. const struct intel_pinctrl_soc_data *soc_data)
  883. {
  884. struct intel_pinctrl *pctrl;
  885. int i, ret, irq;
  886. if (!soc_data)
  887. return -EINVAL;
  888. pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
  889. if (!pctrl)
  890. return -ENOMEM;
  891. pctrl->dev = &pdev->dev;
  892. pctrl->soc = soc_data;
  893. raw_spin_lock_init(&pctrl->lock);
  894. /*
  895. * Make a copy of the communities which we can use to hold pointers
  896. * to the registers.
  897. */
  898. pctrl->ncommunities = pctrl->soc->ncommunities;
  899. pctrl->communities = devm_kcalloc(&pdev->dev, pctrl->ncommunities,
  900. sizeof(*pctrl->communities), GFP_KERNEL);
  901. if (!pctrl->communities)
  902. return -ENOMEM;
  903. for (i = 0; i < pctrl->ncommunities; i++) {
  904. struct intel_community *community = &pctrl->communities[i];
  905. struct resource *res;
  906. void __iomem *regs;
  907. u32 padbar;
  908. *community = pctrl->soc->communities[i];
  909. res = platform_get_resource(pdev, IORESOURCE_MEM,
  910. community->barno);
  911. regs = devm_ioremap_resource(&pdev->dev, res);
  912. if (IS_ERR(regs))
  913. return PTR_ERR(regs);
  914. /*
  915. * Determine community features based on the revision if
  916. * not specified already.
  917. */
  918. if (!community->features) {
  919. u32 rev;
  920. rev = (readl(regs + REVID) & REVID_MASK) >> REVID_SHIFT;
  921. if (rev >= 0x94) {
  922. community->features |= PINCTRL_FEATURE_DEBOUNCE;
  923. community->features |= PINCTRL_FEATURE_1K_PD;
  924. }
  925. }
  926. /* Read offset of the pad configuration registers */
  927. padbar = readl(regs + PADBAR);
  928. community->regs = regs;
  929. community->pad_regs = regs + padbar;
  930. community->ngpps = DIV_ROUND_UP(community->npins,
  931. community->gpp_size);
  932. }
  933. irq = platform_get_irq(pdev, 0);
  934. if (irq < 0) {
  935. dev_err(&pdev->dev, "failed to get interrupt number\n");
  936. return irq;
  937. }
  938. ret = intel_pinctrl_pm_init(pctrl);
  939. if (ret)
  940. return ret;
  941. pctrl->pctldesc = intel_pinctrl_desc;
  942. pctrl->pctldesc.name = dev_name(&pdev->dev);
  943. pctrl->pctldesc.pins = pctrl->soc->pins;
  944. pctrl->pctldesc.npins = pctrl->soc->npins;
  945. pctrl->pctldev = devm_pinctrl_register(&pdev->dev, &pctrl->pctldesc,
  946. pctrl);
  947. if (IS_ERR(pctrl->pctldev)) {
  948. dev_err(&pdev->dev, "failed to register pinctrl driver\n");
  949. return PTR_ERR(pctrl->pctldev);
  950. }
  951. ret = intel_gpio_probe(pctrl, irq);
  952. if (ret)
  953. return ret;
  954. platform_set_drvdata(pdev, pctrl);
  955. return 0;
  956. }
  957. EXPORT_SYMBOL_GPL(intel_pinctrl_probe);
  958. #ifdef CONFIG_PM_SLEEP
  959. static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned pin)
  960. {
  961. const struct pin_desc *pd = pin_desc_get(pctrl->pctldev, pin);
  962. if (!pd || !intel_pad_usable(pctrl, pin))
  963. return false;
  964. /*
  965. * Only restore the pin if it is actually in use by the kernel (or
  966. * by userspace). It is possible that some pins are used by the
  967. * BIOS during resume and those are not always locked down so leave
  968. * them alone.
  969. */
  970. if (pd->mux_owner || pd->gpio_owner ||
  971. gpiochip_line_is_irq(&pctrl->chip, pin))
  972. return true;
  973. return false;
  974. }
  975. int intel_pinctrl_suspend(struct device *dev)
  976. {
  977. struct platform_device *pdev = to_platform_device(dev);
  978. struct intel_pinctrl *pctrl = platform_get_drvdata(pdev);
  979. struct intel_community_context *communities;
  980. struct intel_pad_context *pads;
  981. int i;
  982. pads = pctrl->context.pads;
  983. for (i = 0; i < pctrl->soc->npins; i++) {
  984. const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i];
  985. void __iomem *padcfg;
  986. u32 val;
  987. if (!intel_pinctrl_should_save(pctrl, desc->number))
  988. continue;
  989. val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG0));
  990. pads[i].padcfg0 = val & ~PADCFG0_GPIORXSTATE;
  991. val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG1));
  992. pads[i].padcfg1 = val;
  993. padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG2);
  994. if (padcfg)
  995. pads[i].padcfg2 = readl(padcfg);
  996. }
  997. communities = pctrl->context.communities;
  998. for (i = 0; i < pctrl->ncommunities; i++) {
  999. struct intel_community *community = &pctrl->communities[i];
  1000. void __iomem *base;
  1001. unsigned gpp;
  1002. base = community->regs + community->ie_offset;
  1003. for (gpp = 0; gpp < community->ngpps; gpp++)
  1004. communities[i].intmask[gpp] = readl(base + gpp * 4);
  1005. }
  1006. return 0;
  1007. }
  1008. EXPORT_SYMBOL_GPL(intel_pinctrl_suspend);
  1009. static void intel_gpio_irq_init(struct intel_pinctrl *pctrl)
  1010. {
  1011. size_t i;
  1012. for (i = 0; i < pctrl->ncommunities; i++) {
  1013. const struct intel_community *community;
  1014. void __iomem *base;
  1015. unsigned gpp;
  1016. community = &pctrl->communities[i];
  1017. base = community->regs;
  1018. for (gpp = 0; gpp < community->ngpps; gpp++) {
  1019. /* Mask and clear all interrupts */
  1020. writel(0, base + community->ie_offset + gpp * 4);
  1021. writel(0xffff, base + GPI_IS + gpp * 4);
  1022. }
  1023. }
  1024. }
  1025. int intel_pinctrl_resume(struct device *dev)
  1026. {
  1027. struct platform_device *pdev = to_platform_device(dev);
  1028. struct intel_pinctrl *pctrl = platform_get_drvdata(pdev);
  1029. const struct intel_community_context *communities;
  1030. const struct intel_pad_context *pads;
  1031. int i;
  1032. /* Mask all interrupts */
  1033. intel_gpio_irq_init(pctrl);
  1034. pads = pctrl->context.pads;
  1035. for (i = 0; i < pctrl->soc->npins; i++) {
  1036. const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i];
  1037. void __iomem *padcfg;
  1038. u32 val;
  1039. if (!intel_pinctrl_should_save(pctrl, desc->number))
  1040. continue;
  1041. padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG0);
  1042. val = readl(padcfg) & ~PADCFG0_GPIORXSTATE;
  1043. if (val != pads[i].padcfg0) {
  1044. writel(pads[i].padcfg0, padcfg);
  1045. dev_dbg(dev, "restored pin %u padcfg0 %#08x\n",
  1046. desc->number, readl(padcfg));
  1047. }
  1048. padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG1);
  1049. val = readl(padcfg);
  1050. if (val != pads[i].padcfg1) {
  1051. writel(pads[i].padcfg1, padcfg);
  1052. dev_dbg(dev, "restored pin %u padcfg1 %#08x\n",
  1053. desc->number, readl(padcfg));
  1054. }
  1055. padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG2);
  1056. if (padcfg) {
  1057. val = readl(padcfg);
  1058. if (val != pads[i].padcfg2) {
  1059. writel(pads[i].padcfg2, padcfg);
  1060. dev_dbg(dev, "restored pin %u padcfg2 %#08x\n",
  1061. desc->number, readl(padcfg));
  1062. }
  1063. }
  1064. }
  1065. communities = pctrl->context.communities;
  1066. for (i = 0; i < pctrl->ncommunities; i++) {
  1067. struct intel_community *community = &pctrl->communities[i];
  1068. void __iomem *base;
  1069. unsigned gpp;
  1070. base = community->regs + community->ie_offset;
  1071. for (gpp = 0; gpp < community->ngpps; gpp++) {
  1072. writel(communities[i].intmask[gpp], base + gpp * 4);
  1073. dev_dbg(dev, "restored mask %d/%u %#08x\n", i, gpp,
  1074. readl(base + gpp * 4));
  1075. }
  1076. }
  1077. return 0;
  1078. }
  1079. EXPORT_SYMBOL_GPL(intel_pinctrl_resume);
  1080. #endif
  1081. MODULE_AUTHOR("Mathias Nyman <mathias.nyman@linux.intel.com>");
  1082. MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
  1083. MODULE_DESCRIPTION("Intel pinctrl/GPIO core driver");
  1084. MODULE_LICENSE("GPL v2");