pinctrl-intel.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Intel pinctrl/GPIO core driver.
  4. *
  5. * Copyright (C) 2015, Intel Corporation
  6. * Authors: Mathias Nyman <[email protected]>
  7. * Mika Westerberg <[email protected]>
  8. */
  9. #include <linux/acpi.h>
  10. #include <linux/gpio/driver.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/log2.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/property.h>
  16. #include <linux/time.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 CAPLIST 0x004
  28. #define CAPLIST_ID_SHIFT 16
  29. #define CAPLIST_ID_MASK GENMASK(23, 16)
  30. #define CAPLIST_ID_GPIO_HW_INFO 1
  31. #define CAPLIST_ID_PWM 2
  32. #define CAPLIST_ID_BLINK 3
  33. #define CAPLIST_ID_EXP 4
  34. #define CAPLIST_NEXT_SHIFT 0
  35. #define CAPLIST_NEXT_MASK GENMASK(15, 0)
  36. #define PADBAR 0x00c
  37. #define PADOWN_BITS 4
  38. #define PADOWN_SHIFT(p) ((p) % 8 * PADOWN_BITS)
  39. #define PADOWN_MASK(p) (GENMASK(3, 0) << PADOWN_SHIFT(p))
  40. #define PADOWN_GPP(p) ((p) / 8)
  41. /* Offset from pad_regs */
  42. #define PADCFG0 0x000
  43. #define PADCFG0_RXEVCFG_SHIFT 25
  44. #define PADCFG0_RXEVCFG_MASK GENMASK(26, 25)
  45. #define PADCFG0_RXEVCFG_LEVEL 0
  46. #define PADCFG0_RXEVCFG_EDGE 1
  47. #define PADCFG0_RXEVCFG_DISABLED 2
  48. #define PADCFG0_RXEVCFG_EDGE_BOTH 3
  49. #define PADCFG0_PREGFRXSEL BIT(24)
  50. #define PADCFG0_RXINV BIT(23)
  51. #define PADCFG0_GPIROUTIOXAPIC BIT(20)
  52. #define PADCFG0_GPIROUTSCI BIT(19)
  53. #define PADCFG0_GPIROUTSMI BIT(18)
  54. #define PADCFG0_GPIROUTNMI BIT(17)
  55. #define PADCFG0_PMODE_SHIFT 10
  56. #define PADCFG0_PMODE_MASK GENMASK(13, 10)
  57. #define PADCFG0_PMODE_GPIO 0
  58. #define PADCFG0_GPIORXDIS BIT(9)
  59. #define PADCFG0_GPIOTXDIS BIT(8)
  60. #define PADCFG0_GPIORXSTATE BIT(1)
  61. #define PADCFG0_GPIOTXSTATE BIT(0)
  62. #define PADCFG1 0x004
  63. #define PADCFG1_TERM_UP BIT(13)
  64. #define PADCFG1_TERM_SHIFT 10
  65. #define PADCFG1_TERM_MASK GENMASK(12, 10)
  66. #define PADCFG1_TERM_20K BIT(2)
  67. #define PADCFG1_TERM_5K BIT(1)
  68. #define PADCFG1_TERM_1K BIT(0)
  69. #define PADCFG1_TERM_833 (BIT(1) | BIT(0))
  70. #define PADCFG2 0x008
  71. #define PADCFG2_DEBEN BIT(0)
  72. #define PADCFG2_DEBOUNCE_SHIFT 1
  73. #define PADCFG2_DEBOUNCE_MASK GENMASK(4, 1)
  74. #define DEBOUNCE_PERIOD_NSEC 31250
  75. struct intel_pad_context {
  76. u32 padcfg0;
  77. u32 padcfg1;
  78. u32 padcfg2;
  79. };
  80. struct intel_community_context {
  81. u32 *intmask;
  82. u32 *hostown;
  83. };
  84. #define pin_to_padno(c, p) ((p) - (c)->pin_base)
  85. #define padgroup_offset(g, p) ((p) - (g)->base)
  86. static struct intel_community *intel_get_community(struct intel_pinctrl *pctrl,
  87. unsigned int pin)
  88. {
  89. struct intel_community *community;
  90. int i;
  91. for (i = 0; i < pctrl->ncommunities; i++) {
  92. community = &pctrl->communities[i];
  93. if (pin >= community->pin_base &&
  94. pin < community->pin_base + community->npins)
  95. return community;
  96. }
  97. dev_warn(pctrl->dev, "failed to find community for pin %u\n", pin);
  98. return NULL;
  99. }
  100. static const struct intel_padgroup *
  101. intel_community_get_padgroup(const struct intel_community *community,
  102. unsigned int pin)
  103. {
  104. int i;
  105. for (i = 0; i < community->ngpps; i++) {
  106. const struct intel_padgroup *padgrp = &community->gpps[i];
  107. if (pin >= padgrp->base && pin < padgrp->base + padgrp->size)
  108. return padgrp;
  109. }
  110. return NULL;
  111. }
  112. static void __iomem *intel_get_padcfg(struct intel_pinctrl *pctrl,
  113. unsigned int pin, unsigned int reg)
  114. {
  115. const struct intel_community *community;
  116. unsigned int padno;
  117. size_t nregs;
  118. community = intel_get_community(pctrl, pin);
  119. if (!community)
  120. return NULL;
  121. padno = pin_to_padno(community, pin);
  122. nregs = (community->features & PINCTRL_FEATURE_DEBOUNCE) ? 4 : 2;
  123. if (reg >= nregs * 4)
  124. return NULL;
  125. return community->pad_regs + reg + padno * nregs * 4;
  126. }
  127. static bool intel_pad_owned_by_host(struct intel_pinctrl *pctrl, unsigned int pin)
  128. {
  129. const struct intel_community *community;
  130. const struct intel_padgroup *padgrp;
  131. unsigned int gpp, offset, gpp_offset;
  132. void __iomem *padown;
  133. community = intel_get_community(pctrl, pin);
  134. if (!community)
  135. return false;
  136. if (!community->padown_offset)
  137. return true;
  138. padgrp = intel_community_get_padgroup(community, pin);
  139. if (!padgrp)
  140. return false;
  141. gpp_offset = padgroup_offset(padgrp, pin);
  142. gpp = PADOWN_GPP(gpp_offset);
  143. offset = community->padown_offset + padgrp->padown_num * 4 + gpp * 4;
  144. padown = community->regs + offset;
  145. return !(readl(padown) & PADOWN_MASK(gpp_offset));
  146. }
  147. static bool intel_pad_acpi_mode(struct intel_pinctrl *pctrl, unsigned int pin)
  148. {
  149. const struct intel_community *community;
  150. const struct intel_padgroup *padgrp;
  151. unsigned int offset, gpp_offset;
  152. void __iomem *hostown;
  153. community = intel_get_community(pctrl, pin);
  154. if (!community)
  155. return true;
  156. if (!community->hostown_offset)
  157. return false;
  158. padgrp = intel_community_get_padgroup(community, pin);
  159. if (!padgrp)
  160. return true;
  161. gpp_offset = padgroup_offset(padgrp, pin);
  162. offset = community->hostown_offset + padgrp->reg_num * 4;
  163. hostown = community->regs + offset;
  164. return !(readl(hostown) & BIT(gpp_offset));
  165. }
  166. /**
  167. * enum - Locking variants of the pad configuration
  168. *
  169. * @PAD_UNLOCKED: pad is fully controlled by the configuration registers
  170. * @PAD_LOCKED: pad configuration registers, except TX state, are locked
  171. * @PAD_LOCKED_TX: pad configuration TX state is locked
  172. * @PAD_LOCKED_FULL: pad configuration registers are locked completely
  173. *
  174. * Locking is considered as read-only mode for corresponding registers and
  175. * their respective fields. That said, TX state bit is locked separately from
  176. * the main locking scheme.
  177. */
  178. enum {
  179. PAD_UNLOCKED = 0,
  180. PAD_LOCKED = 1,
  181. PAD_LOCKED_TX = 2,
  182. PAD_LOCKED_FULL = PAD_LOCKED | PAD_LOCKED_TX,
  183. };
  184. static int intel_pad_locked(struct intel_pinctrl *pctrl, unsigned int pin)
  185. {
  186. struct intel_community *community;
  187. const struct intel_padgroup *padgrp;
  188. unsigned int offset, gpp_offset;
  189. u32 value;
  190. int ret = PAD_UNLOCKED;
  191. community = intel_get_community(pctrl, pin);
  192. if (!community)
  193. return PAD_LOCKED_FULL;
  194. if (!community->padcfglock_offset)
  195. return PAD_UNLOCKED;
  196. padgrp = intel_community_get_padgroup(community, pin);
  197. if (!padgrp)
  198. return PAD_LOCKED_FULL;
  199. gpp_offset = padgroup_offset(padgrp, pin);
  200. /*
  201. * If PADCFGLOCK and PADCFGLOCKTX bits are both clear for this pad,
  202. * the pad is considered unlocked. Any other case means that it is
  203. * either fully or partially locked.
  204. */
  205. offset = community->padcfglock_offset + 0 + padgrp->reg_num * 8;
  206. value = readl(community->regs + offset);
  207. if (value & BIT(gpp_offset))
  208. ret |= PAD_LOCKED;
  209. offset = community->padcfglock_offset + 4 + padgrp->reg_num * 8;
  210. value = readl(community->regs + offset);
  211. if (value & BIT(gpp_offset))
  212. ret |= PAD_LOCKED_TX;
  213. return ret;
  214. }
  215. static bool intel_pad_is_unlocked(struct intel_pinctrl *pctrl, unsigned int pin)
  216. {
  217. return (intel_pad_locked(pctrl, pin) & PAD_LOCKED) == PAD_UNLOCKED;
  218. }
  219. static bool intel_pad_usable(struct intel_pinctrl *pctrl, unsigned int pin)
  220. {
  221. return intel_pad_owned_by_host(pctrl, pin) && intel_pad_is_unlocked(pctrl, pin);
  222. }
  223. static int intel_get_groups_count(struct pinctrl_dev *pctldev)
  224. {
  225. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  226. return pctrl->soc->ngroups;
  227. }
  228. static const char *intel_get_group_name(struct pinctrl_dev *pctldev,
  229. unsigned int group)
  230. {
  231. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  232. return pctrl->soc->groups[group].grp.name;
  233. }
  234. static int intel_get_group_pins(struct pinctrl_dev *pctldev, unsigned int group,
  235. const unsigned int **pins, unsigned int *npins)
  236. {
  237. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  238. *pins = pctrl->soc->groups[group].grp.pins;
  239. *npins = pctrl->soc->groups[group].grp.npins;
  240. return 0;
  241. }
  242. static void intel_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  243. unsigned int pin)
  244. {
  245. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  246. void __iomem *padcfg;
  247. u32 cfg0, cfg1, mode;
  248. int locked;
  249. bool acpi;
  250. if (!intel_pad_owned_by_host(pctrl, pin)) {
  251. seq_puts(s, "not available");
  252. return;
  253. }
  254. cfg0 = readl(intel_get_padcfg(pctrl, pin, PADCFG0));
  255. cfg1 = readl(intel_get_padcfg(pctrl, pin, PADCFG1));
  256. mode = (cfg0 & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT;
  257. if (mode == PADCFG0_PMODE_GPIO)
  258. seq_puts(s, "GPIO ");
  259. else
  260. seq_printf(s, "mode %d ", mode);
  261. seq_printf(s, "0x%08x 0x%08x", cfg0, cfg1);
  262. /* Dump the additional PADCFG registers if available */
  263. padcfg = intel_get_padcfg(pctrl, pin, PADCFG2);
  264. if (padcfg)
  265. seq_printf(s, " 0x%08x", readl(padcfg));
  266. locked = intel_pad_locked(pctrl, pin);
  267. acpi = intel_pad_acpi_mode(pctrl, pin);
  268. if (locked || acpi) {
  269. seq_puts(s, " [");
  270. if (locked)
  271. seq_puts(s, "LOCKED");
  272. if ((locked & PAD_LOCKED_FULL) == PAD_LOCKED_TX)
  273. seq_puts(s, " tx");
  274. else if ((locked & PAD_LOCKED_FULL) == PAD_LOCKED_FULL)
  275. seq_puts(s, " full");
  276. if (locked && acpi)
  277. seq_puts(s, ", ");
  278. if (acpi)
  279. seq_puts(s, "ACPI");
  280. seq_puts(s, "]");
  281. }
  282. }
  283. static const struct pinctrl_ops intel_pinctrl_ops = {
  284. .get_groups_count = intel_get_groups_count,
  285. .get_group_name = intel_get_group_name,
  286. .get_group_pins = intel_get_group_pins,
  287. .pin_dbg_show = intel_pin_dbg_show,
  288. };
  289. static int intel_get_functions_count(struct pinctrl_dev *pctldev)
  290. {
  291. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  292. return pctrl->soc->nfunctions;
  293. }
  294. static const char *intel_get_function_name(struct pinctrl_dev *pctldev,
  295. unsigned int function)
  296. {
  297. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  298. return pctrl->soc->functions[function].name;
  299. }
  300. static int intel_get_function_groups(struct pinctrl_dev *pctldev,
  301. unsigned int function,
  302. const char * const **groups,
  303. unsigned int * const ngroups)
  304. {
  305. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  306. *groups = pctrl->soc->functions[function].groups;
  307. *ngroups = pctrl->soc->functions[function].ngroups;
  308. return 0;
  309. }
  310. static int intel_pinmux_set_mux(struct pinctrl_dev *pctldev,
  311. unsigned int function, unsigned int group)
  312. {
  313. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  314. const struct intel_pingroup *grp = &pctrl->soc->groups[group];
  315. unsigned long flags;
  316. int i;
  317. raw_spin_lock_irqsave(&pctrl->lock, flags);
  318. /*
  319. * All pins in the groups needs to be accessible and writable
  320. * before we can enable the mux for this group.
  321. */
  322. for (i = 0; i < grp->grp.npins; i++) {
  323. if (!intel_pad_usable(pctrl, grp->grp.pins[i])) {
  324. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  325. return -EBUSY;
  326. }
  327. }
  328. /* Now enable the mux setting for each pin in the group */
  329. for (i = 0; i < grp->grp.npins; i++) {
  330. void __iomem *padcfg0;
  331. u32 value;
  332. padcfg0 = intel_get_padcfg(pctrl, grp->grp.pins[i], PADCFG0);
  333. value = readl(padcfg0);
  334. value &= ~PADCFG0_PMODE_MASK;
  335. if (grp->modes)
  336. value |= grp->modes[i] << PADCFG0_PMODE_SHIFT;
  337. else
  338. value |= grp->mode << PADCFG0_PMODE_SHIFT;
  339. writel(value, padcfg0);
  340. }
  341. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  342. return 0;
  343. }
  344. static void __intel_gpio_set_direction(void __iomem *padcfg0, bool input)
  345. {
  346. u32 value;
  347. value = readl(padcfg0);
  348. if (input) {
  349. value &= ~PADCFG0_GPIORXDIS;
  350. value |= PADCFG0_GPIOTXDIS;
  351. } else {
  352. value &= ~PADCFG0_GPIOTXDIS;
  353. value |= PADCFG0_GPIORXDIS;
  354. }
  355. writel(value, padcfg0);
  356. }
  357. static int __intel_gpio_get_gpio_mode(u32 value)
  358. {
  359. return (value & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT;
  360. }
  361. static int intel_gpio_get_gpio_mode(void __iomem *padcfg0)
  362. {
  363. return __intel_gpio_get_gpio_mode(readl(padcfg0));
  364. }
  365. static void intel_gpio_set_gpio_mode(void __iomem *padcfg0)
  366. {
  367. u32 value;
  368. value = readl(padcfg0);
  369. /* Put the pad into GPIO mode */
  370. value &= ~PADCFG0_PMODE_MASK;
  371. value |= PADCFG0_PMODE_GPIO;
  372. /* Disable TX buffer and enable RX (this will be input) */
  373. value &= ~PADCFG0_GPIORXDIS;
  374. value |= PADCFG0_GPIOTXDIS;
  375. /* Disable SCI/SMI/NMI generation */
  376. value &= ~(PADCFG0_GPIROUTIOXAPIC | PADCFG0_GPIROUTSCI);
  377. value &= ~(PADCFG0_GPIROUTSMI | PADCFG0_GPIROUTNMI);
  378. writel(value, padcfg0);
  379. }
  380. static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
  381. struct pinctrl_gpio_range *range,
  382. unsigned int pin)
  383. {
  384. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  385. void __iomem *padcfg0;
  386. unsigned long flags;
  387. padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
  388. raw_spin_lock_irqsave(&pctrl->lock, flags);
  389. if (!intel_pad_owned_by_host(pctrl, pin)) {
  390. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  391. return -EBUSY;
  392. }
  393. if (!intel_pad_is_unlocked(pctrl, pin)) {
  394. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  395. return 0;
  396. }
  397. /*
  398. * If pin is already configured in GPIO mode, we assume that
  399. * firmware provides correct settings. In such case we avoid
  400. * potential glitches on the pin. Otherwise, for the pin in
  401. * alternative mode, consumer has to supply respective flags.
  402. */
  403. if (intel_gpio_get_gpio_mode(padcfg0) == PADCFG0_PMODE_GPIO) {
  404. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  405. return 0;
  406. }
  407. intel_gpio_set_gpio_mode(padcfg0);
  408. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  409. return 0;
  410. }
  411. static int intel_gpio_set_direction(struct pinctrl_dev *pctldev,
  412. struct pinctrl_gpio_range *range,
  413. unsigned int pin, bool input)
  414. {
  415. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  416. void __iomem *padcfg0;
  417. unsigned long flags;
  418. padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
  419. raw_spin_lock_irqsave(&pctrl->lock, flags);
  420. __intel_gpio_set_direction(padcfg0, input);
  421. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  422. return 0;
  423. }
  424. static const struct pinmux_ops intel_pinmux_ops = {
  425. .get_functions_count = intel_get_functions_count,
  426. .get_function_name = intel_get_function_name,
  427. .get_function_groups = intel_get_function_groups,
  428. .set_mux = intel_pinmux_set_mux,
  429. .gpio_request_enable = intel_gpio_request_enable,
  430. .gpio_set_direction = intel_gpio_set_direction,
  431. };
  432. static int intel_config_get_pull(struct intel_pinctrl *pctrl, unsigned int pin,
  433. enum pin_config_param param, u32 *arg)
  434. {
  435. const struct intel_community *community;
  436. void __iomem *padcfg1;
  437. unsigned long flags;
  438. u32 value, term;
  439. community = intel_get_community(pctrl, pin);
  440. padcfg1 = intel_get_padcfg(pctrl, pin, PADCFG1);
  441. raw_spin_lock_irqsave(&pctrl->lock, flags);
  442. value = readl(padcfg1);
  443. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  444. term = (value & PADCFG1_TERM_MASK) >> PADCFG1_TERM_SHIFT;
  445. switch (param) {
  446. case PIN_CONFIG_BIAS_DISABLE:
  447. if (term)
  448. return -EINVAL;
  449. break;
  450. case PIN_CONFIG_BIAS_PULL_UP:
  451. if (!term || !(value & PADCFG1_TERM_UP))
  452. return -EINVAL;
  453. switch (term) {
  454. case PADCFG1_TERM_833:
  455. *arg = 833;
  456. break;
  457. case PADCFG1_TERM_1K:
  458. *arg = 1000;
  459. break;
  460. case PADCFG1_TERM_5K:
  461. *arg = 5000;
  462. break;
  463. case PADCFG1_TERM_20K:
  464. *arg = 20000;
  465. break;
  466. }
  467. break;
  468. case PIN_CONFIG_BIAS_PULL_DOWN:
  469. if (!term || value & PADCFG1_TERM_UP)
  470. return -EINVAL;
  471. switch (term) {
  472. case PADCFG1_TERM_833:
  473. if (!(community->features & PINCTRL_FEATURE_1K_PD))
  474. return -EINVAL;
  475. *arg = 833;
  476. break;
  477. case PADCFG1_TERM_1K:
  478. if (!(community->features & PINCTRL_FEATURE_1K_PD))
  479. return -EINVAL;
  480. *arg = 1000;
  481. break;
  482. case PADCFG1_TERM_5K:
  483. *arg = 5000;
  484. break;
  485. case PADCFG1_TERM_20K:
  486. *arg = 20000;
  487. break;
  488. }
  489. break;
  490. default:
  491. return -EINVAL;
  492. }
  493. return 0;
  494. }
  495. static int intel_config_get_debounce(struct intel_pinctrl *pctrl, unsigned int pin,
  496. enum pin_config_param param, u32 *arg)
  497. {
  498. void __iomem *padcfg2;
  499. unsigned long flags;
  500. unsigned long v;
  501. u32 value2;
  502. padcfg2 = intel_get_padcfg(pctrl, pin, PADCFG2);
  503. if (!padcfg2)
  504. return -ENOTSUPP;
  505. raw_spin_lock_irqsave(&pctrl->lock, flags);
  506. value2 = readl(padcfg2);
  507. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  508. if (!(value2 & PADCFG2_DEBEN))
  509. return -EINVAL;
  510. v = (value2 & PADCFG2_DEBOUNCE_MASK) >> PADCFG2_DEBOUNCE_SHIFT;
  511. *arg = BIT(v) * DEBOUNCE_PERIOD_NSEC / NSEC_PER_USEC;
  512. return 0;
  513. }
  514. static int intel_config_get(struct pinctrl_dev *pctldev, unsigned int pin,
  515. unsigned long *config)
  516. {
  517. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  518. enum pin_config_param param = pinconf_to_config_param(*config);
  519. u32 arg = 0;
  520. int ret;
  521. if (!intel_pad_owned_by_host(pctrl, pin))
  522. return -ENOTSUPP;
  523. switch (param) {
  524. case PIN_CONFIG_BIAS_DISABLE:
  525. case PIN_CONFIG_BIAS_PULL_UP:
  526. case PIN_CONFIG_BIAS_PULL_DOWN:
  527. ret = intel_config_get_pull(pctrl, pin, param, &arg);
  528. if (ret)
  529. return ret;
  530. break;
  531. case PIN_CONFIG_INPUT_DEBOUNCE:
  532. ret = intel_config_get_debounce(pctrl, pin, param, &arg);
  533. if (ret)
  534. return ret;
  535. break;
  536. default:
  537. return -ENOTSUPP;
  538. }
  539. *config = pinconf_to_config_packed(param, arg);
  540. return 0;
  541. }
  542. static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
  543. unsigned long config)
  544. {
  545. unsigned int param = pinconf_to_config_param(config);
  546. unsigned int arg = pinconf_to_config_argument(config);
  547. const struct intel_community *community;
  548. void __iomem *padcfg1;
  549. unsigned long flags;
  550. int ret = 0;
  551. u32 value;
  552. community = intel_get_community(pctrl, pin);
  553. padcfg1 = intel_get_padcfg(pctrl, pin, PADCFG1);
  554. raw_spin_lock_irqsave(&pctrl->lock, flags);
  555. value = readl(padcfg1);
  556. switch (param) {
  557. case PIN_CONFIG_BIAS_DISABLE:
  558. value &= ~(PADCFG1_TERM_MASK | PADCFG1_TERM_UP);
  559. break;
  560. case PIN_CONFIG_BIAS_PULL_UP:
  561. value &= ~PADCFG1_TERM_MASK;
  562. value |= PADCFG1_TERM_UP;
  563. /* Set default strength value in case none is given */
  564. if (arg == 1)
  565. arg = 5000;
  566. switch (arg) {
  567. case 20000:
  568. value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT;
  569. break;
  570. case 5000:
  571. value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT;
  572. break;
  573. case 1000:
  574. value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT;
  575. break;
  576. case 833:
  577. value |= PADCFG1_TERM_833 << PADCFG1_TERM_SHIFT;
  578. break;
  579. default:
  580. ret = -EINVAL;
  581. }
  582. break;
  583. case PIN_CONFIG_BIAS_PULL_DOWN:
  584. value &= ~(PADCFG1_TERM_UP | PADCFG1_TERM_MASK);
  585. /* Set default strength value in case none is given */
  586. if (arg == 1)
  587. arg = 5000;
  588. switch (arg) {
  589. case 20000:
  590. value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT;
  591. break;
  592. case 5000:
  593. value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT;
  594. break;
  595. case 1000:
  596. if (!(community->features & PINCTRL_FEATURE_1K_PD)) {
  597. ret = -EINVAL;
  598. break;
  599. }
  600. value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT;
  601. break;
  602. case 833:
  603. if (!(community->features & PINCTRL_FEATURE_1K_PD)) {
  604. ret = -EINVAL;
  605. break;
  606. }
  607. value |= PADCFG1_TERM_833 << PADCFG1_TERM_SHIFT;
  608. break;
  609. default:
  610. ret = -EINVAL;
  611. }
  612. break;
  613. }
  614. if (!ret)
  615. writel(value, padcfg1);
  616. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  617. return ret;
  618. }
  619. static int intel_config_set_debounce(struct intel_pinctrl *pctrl,
  620. unsigned int pin, unsigned int debounce)
  621. {
  622. void __iomem *padcfg0, *padcfg2;
  623. unsigned long flags;
  624. u32 value0, value2;
  625. padcfg2 = intel_get_padcfg(pctrl, pin, PADCFG2);
  626. if (!padcfg2)
  627. return -ENOTSUPP;
  628. padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
  629. raw_spin_lock_irqsave(&pctrl->lock, flags);
  630. value0 = readl(padcfg0);
  631. value2 = readl(padcfg2);
  632. /* Disable glitch filter and debouncer */
  633. value0 &= ~PADCFG0_PREGFRXSEL;
  634. value2 &= ~(PADCFG2_DEBEN | PADCFG2_DEBOUNCE_MASK);
  635. if (debounce) {
  636. unsigned long v;
  637. v = order_base_2(debounce * NSEC_PER_USEC / DEBOUNCE_PERIOD_NSEC);
  638. if (v < 3 || v > 15) {
  639. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  640. return -EINVAL;
  641. }
  642. /* Enable glitch filter and debouncer */
  643. value0 |= PADCFG0_PREGFRXSEL;
  644. value2 |= v << PADCFG2_DEBOUNCE_SHIFT;
  645. value2 |= PADCFG2_DEBEN;
  646. }
  647. writel(value0, padcfg0);
  648. writel(value2, padcfg2);
  649. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  650. return 0;
  651. }
  652. static int intel_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
  653. unsigned long *configs, unsigned int nconfigs)
  654. {
  655. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  656. int i, ret;
  657. if (!intel_pad_usable(pctrl, pin))
  658. return -ENOTSUPP;
  659. for (i = 0; i < nconfigs; i++) {
  660. switch (pinconf_to_config_param(configs[i])) {
  661. case PIN_CONFIG_BIAS_DISABLE:
  662. case PIN_CONFIG_BIAS_PULL_UP:
  663. case PIN_CONFIG_BIAS_PULL_DOWN:
  664. ret = intel_config_set_pull(pctrl, pin, configs[i]);
  665. if (ret)
  666. return ret;
  667. break;
  668. case PIN_CONFIG_INPUT_DEBOUNCE:
  669. ret = intel_config_set_debounce(pctrl, pin,
  670. pinconf_to_config_argument(configs[i]));
  671. if (ret)
  672. return ret;
  673. break;
  674. default:
  675. return -ENOTSUPP;
  676. }
  677. }
  678. return 0;
  679. }
  680. static const struct pinconf_ops intel_pinconf_ops = {
  681. .is_generic = true,
  682. .pin_config_get = intel_config_get,
  683. .pin_config_set = intel_config_set,
  684. };
  685. static const struct pinctrl_desc intel_pinctrl_desc = {
  686. .pctlops = &intel_pinctrl_ops,
  687. .pmxops = &intel_pinmux_ops,
  688. .confops = &intel_pinconf_ops,
  689. .owner = THIS_MODULE,
  690. };
  691. /**
  692. * intel_gpio_to_pin() - Translate from GPIO offset to pin number
  693. * @pctrl: Pinctrl structure
  694. * @offset: GPIO offset from gpiolib
  695. * @community: Community is filled here if not %NULL
  696. * @padgrp: Pad group is filled here if not %NULL
  697. *
  698. * When coming through gpiolib irqchip, the GPIO offset is not
  699. * automatically translated to pinctrl pin number. This function can be
  700. * used to find out the corresponding pinctrl pin.
  701. *
  702. * Return: a pin number and pointers to the community and pad group, which
  703. * the pin belongs to, or negative error code if translation can't be done.
  704. */
  705. static int intel_gpio_to_pin(struct intel_pinctrl *pctrl, unsigned int offset,
  706. const struct intel_community **community,
  707. const struct intel_padgroup **padgrp)
  708. {
  709. int i;
  710. for (i = 0; i < pctrl->ncommunities; i++) {
  711. const struct intel_community *comm = &pctrl->communities[i];
  712. int j;
  713. for (j = 0; j < comm->ngpps; j++) {
  714. const struct intel_padgroup *pgrp = &comm->gpps[j];
  715. if (pgrp->gpio_base == INTEL_GPIO_BASE_NOMAP)
  716. continue;
  717. if (offset >= pgrp->gpio_base &&
  718. offset < pgrp->gpio_base + pgrp->size) {
  719. int pin;
  720. pin = pgrp->base + offset - pgrp->gpio_base;
  721. if (community)
  722. *community = comm;
  723. if (padgrp)
  724. *padgrp = pgrp;
  725. return pin;
  726. }
  727. }
  728. }
  729. return -EINVAL;
  730. }
  731. /**
  732. * intel_pin_to_gpio() - Translate from pin number to GPIO offset
  733. * @pctrl: Pinctrl structure
  734. * @pin: pin number
  735. *
  736. * Translate the pin number of pinctrl to GPIO offset
  737. *
  738. * Return: a GPIO offset, or negative error code if translation can't be done.
  739. */
  740. static __maybe_unused int intel_pin_to_gpio(struct intel_pinctrl *pctrl, int pin)
  741. {
  742. const struct intel_community *community;
  743. const struct intel_padgroup *padgrp;
  744. community = intel_get_community(pctrl, pin);
  745. if (!community)
  746. return -EINVAL;
  747. padgrp = intel_community_get_padgroup(community, pin);
  748. if (!padgrp)
  749. return -EINVAL;
  750. return pin - padgrp->base + padgrp->gpio_base;
  751. }
  752. static int intel_gpio_get(struct gpio_chip *chip, unsigned int offset)
  753. {
  754. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  755. void __iomem *reg;
  756. u32 padcfg0;
  757. int pin;
  758. pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL);
  759. if (pin < 0)
  760. return -EINVAL;
  761. reg = intel_get_padcfg(pctrl, pin, PADCFG0);
  762. if (!reg)
  763. return -EINVAL;
  764. padcfg0 = readl(reg);
  765. if (!(padcfg0 & PADCFG0_GPIOTXDIS))
  766. return !!(padcfg0 & PADCFG0_GPIOTXSTATE);
  767. return !!(padcfg0 & PADCFG0_GPIORXSTATE);
  768. }
  769. static void intel_gpio_set(struct gpio_chip *chip, unsigned int offset,
  770. int value)
  771. {
  772. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  773. unsigned long flags;
  774. void __iomem *reg;
  775. u32 padcfg0;
  776. int pin;
  777. pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL);
  778. if (pin < 0)
  779. return;
  780. reg = intel_get_padcfg(pctrl, pin, PADCFG0);
  781. if (!reg)
  782. return;
  783. raw_spin_lock_irqsave(&pctrl->lock, flags);
  784. padcfg0 = readl(reg);
  785. if (value)
  786. padcfg0 |= PADCFG0_GPIOTXSTATE;
  787. else
  788. padcfg0 &= ~PADCFG0_GPIOTXSTATE;
  789. writel(padcfg0, reg);
  790. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  791. }
  792. static int intel_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
  793. {
  794. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  795. unsigned long flags;
  796. void __iomem *reg;
  797. u32 padcfg0;
  798. int pin;
  799. pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL);
  800. if (pin < 0)
  801. return -EINVAL;
  802. reg = intel_get_padcfg(pctrl, pin, PADCFG0);
  803. if (!reg)
  804. return -EINVAL;
  805. raw_spin_lock_irqsave(&pctrl->lock, flags);
  806. padcfg0 = readl(reg);
  807. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  808. if (padcfg0 & PADCFG0_PMODE_MASK)
  809. return -EINVAL;
  810. if (padcfg0 & PADCFG0_GPIOTXDIS)
  811. return GPIO_LINE_DIRECTION_IN;
  812. return GPIO_LINE_DIRECTION_OUT;
  813. }
  814. static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
  815. {
  816. return pinctrl_gpio_direction_input(chip->base + offset);
  817. }
  818. static int intel_gpio_direction_output(struct gpio_chip *chip, unsigned int offset,
  819. int value)
  820. {
  821. intel_gpio_set(chip, offset, value);
  822. return pinctrl_gpio_direction_output(chip->base + offset);
  823. }
  824. static const struct gpio_chip intel_gpio_chip = {
  825. .owner = THIS_MODULE,
  826. .request = gpiochip_generic_request,
  827. .free = gpiochip_generic_free,
  828. .get_direction = intel_gpio_get_direction,
  829. .direction_input = intel_gpio_direction_input,
  830. .direction_output = intel_gpio_direction_output,
  831. .get = intel_gpio_get,
  832. .set = intel_gpio_set,
  833. .set_config = gpiochip_generic_config,
  834. };
  835. static void intel_gpio_irq_ack(struct irq_data *d)
  836. {
  837. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  838. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  839. const struct intel_community *community;
  840. const struct intel_padgroup *padgrp;
  841. int pin;
  842. pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), &community, &padgrp);
  843. if (pin >= 0) {
  844. unsigned int gpp, gpp_offset, is_offset;
  845. gpp = padgrp->reg_num;
  846. gpp_offset = padgroup_offset(padgrp, pin);
  847. is_offset = community->is_offset + gpp * 4;
  848. raw_spin_lock(&pctrl->lock);
  849. writel(BIT(gpp_offset), community->regs + is_offset);
  850. raw_spin_unlock(&pctrl->lock);
  851. }
  852. }
  853. static void intel_gpio_irq_mask_unmask(struct gpio_chip *gc, irq_hw_number_t hwirq, bool mask)
  854. {
  855. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  856. const struct intel_community *community;
  857. const struct intel_padgroup *padgrp;
  858. int pin;
  859. pin = intel_gpio_to_pin(pctrl, hwirq, &community, &padgrp);
  860. if (pin >= 0) {
  861. unsigned int gpp, gpp_offset;
  862. unsigned long flags;
  863. void __iomem *reg, *is;
  864. u32 value;
  865. gpp = padgrp->reg_num;
  866. gpp_offset = padgroup_offset(padgrp, pin);
  867. reg = community->regs + community->ie_offset + gpp * 4;
  868. is = community->regs + community->is_offset + gpp * 4;
  869. raw_spin_lock_irqsave(&pctrl->lock, flags);
  870. /* Clear interrupt status first to avoid unexpected interrupt */
  871. writel(BIT(gpp_offset), is);
  872. value = readl(reg);
  873. if (mask)
  874. value &= ~BIT(gpp_offset);
  875. else
  876. value |= BIT(gpp_offset);
  877. writel(value, reg);
  878. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  879. }
  880. }
  881. static void intel_gpio_irq_mask(struct irq_data *d)
  882. {
  883. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  884. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  885. intel_gpio_irq_mask_unmask(gc, hwirq, true);
  886. gpiochip_disable_irq(gc, hwirq);
  887. }
  888. static void intel_gpio_irq_unmask(struct irq_data *d)
  889. {
  890. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  891. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  892. gpiochip_enable_irq(gc, hwirq);
  893. intel_gpio_irq_mask_unmask(gc, hwirq, false);
  894. }
  895. static int intel_gpio_irq_type(struct irq_data *d, unsigned int type)
  896. {
  897. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  898. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  899. unsigned int pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), NULL, NULL);
  900. unsigned long flags;
  901. void __iomem *reg;
  902. u32 value;
  903. reg = intel_get_padcfg(pctrl, pin, PADCFG0);
  904. if (!reg)
  905. return -EINVAL;
  906. /*
  907. * If the pin is in ACPI mode it is still usable as a GPIO but it
  908. * cannot be used as IRQ because GPI_IS status bit will not be
  909. * updated by the host controller hardware.
  910. */
  911. if (intel_pad_acpi_mode(pctrl, pin)) {
  912. dev_warn(pctrl->dev, "pin %u cannot be used as IRQ\n", pin);
  913. return -EPERM;
  914. }
  915. raw_spin_lock_irqsave(&pctrl->lock, flags);
  916. intel_gpio_set_gpio_mode(reg);
  917. value = readl(reg);
  918. value &= ~(PADCFG0_RXEVCFG_MASK | PADCFG0_RXINV);
  919. if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) {
  920. value |= PADCFG0_RXEVCFG_EDGE_BOTH << PADCFG0_RXEVCFG_SHIFT;
  921. } else if (type & IRQ_TYPE_EDGE_FALLING) {
  922. value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT;
  923. value |= PADCFG0_RXINV;
  924. } else if (type & IRQ_TYPE_EDGE_RISING) {
  925. value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT;
  926. } else if (type & IRQ_TYPE_LEVEL_MASK) {
  927. if (type & IRQ_TYPE_LEVEL_LOW)
  928. value |= PADCFG0_RXINV;
  929. } else {
  930. value |= PADCFG0_RXEVCFG_DISABLED << PADCFG0_RXEVCFG_SHIFT;
  931. }
  932. writel(value, reg);
  933. if (type & IRQ_TYPE_EDGE_BOTH)
  934. irq_set_handler_locked(d, handle_edge_irq);
  935. else if (type & IRQ_TYPE_LEVEL_MASK)
  936. irq_set_handler_locked(d, handle_level_irq);
  937. raw_spin_unlock_irqrestore(&pctrl->lock, flags);
  938. return 0;
  939. }
  940. static int intel_gpio_irq_wake(struct irq_data *d, unsigned int on)
  941. {
  942. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  943. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  944. unsigned int pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), NULL, NULL);
  945. if (on)
  946. enable_irq_wake(pctrl->irq);
  947. else
  948. disable_irq_wake(pctrl->irq);
  949. dev_dbg(pctrl->dev, "%sable wake for pin %u\n", on ? "en" : "dis", pin);
  950. return 0;
  951. }
  952. static const struct irq_chip intel_gpio_irq_chip = {
  953. .name = "intel-gpio",
  954. .irq_ack = intel_gpio_irq_ack,
  955. .irq_mask = intel_gpio_irq_mask,
  956. .irq_unmask = intel_gpio_irq_unmask,
  957. .irq_set_type = intel_gpio_irq_type,
  958. .irq_set_wake = intel_gpio_irq_wake,
  959. .flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_IMMUTABLE,
  960. GPIOCHIP_IRQ_RESOURCE_HELPERS,
  961. };
  962. static int intel_gpio_community_irq_handler(struct intel_pinctrl *pctrl,
  963. const struct intel_community *community)
  964. {
  965. struct gpio_chip *gc = &pctrl->chip;
  966. unsigned int gpp;
  967. int ret = 0;
  968. for (gpp = 0; gpp < community->ngpps; gpp++) {
  969. const struct intel_padgroup *padgrp = &community->gpps[gpp];
  970. unsigned long pending, enabled, gpp_offset;
  971. raw_spin_lock(&pctrl->lock);
  972. pending = readl(community->regs + community->is_offset +
  973. padgrp->reg_num * 4);
  974. enabled = readl(community->regs + community->ie_offset +
  975. padgrp->reg_num * 4);
  976. raw_spin_unlock(&pctrl->lock);
  977. /* Only interrupts that are enabled */
  978. pending &= enabled;
  979. for_each_set_bit(gpp_offset, &pending, padgrp->size) {
  980. unsigned int irq;
  981. irq = irq_find_mapping(gc->irq.domain,
  982. padgrp->gpio_base + gpp_offset);
  983. generic_handle_irq(irq);
  984. }
  985. ret += pending ? 1 : 0;
  986. }
  987. return ret;
  988. }
  989. static irqreturn_t intel_gpio_irq(int irq, void *data)
  990. {
  991. const struct intel_community *community;
  992. struct intel_pinctrl *pctrl = data;
  993. unsigned int i;
  994. int ret = 0;
  995. /* Need to check all communities for pending interrupts */
  996. for (i = 0; i < pctrl->ncommunities; i++) {
  997. community = &pctrl->communities[i];
  998. ret += intel_gpio_community_irq_handler(pctrl, community);
  999. }
  1000. return IRQ_RETVAL(ret);
  1001. }
  1002. static void intel_gpio_irq_init(struct intel_pinctrl *pctrl)
  1003. {
  1004. int i;
  1005. for (i = 0; i < pctrl->ncommunities; i++) {
  1006. const struct intel_community *community;
  1007. void __iomem *base;
  1008. unsigned int gpp;
  1009. community = &pctrl->communities[i];
  1010. base = community->regs;
  1011. for (gpp = 0; gpp < community->ngpps; gpp++) {
  1012. /* Mask and clear all interrupts */
  1013. writel(0, base + community->ie_offset + gpp * 4);
  1014. writel(0xffff, base + community->is_offset + gpp * 4);
  1015. }
  1016. }
  1017. }
  1018. static int intel_gpio_irq_init_hw(struct gpio_chip *gc)
  1019. {
  1020. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  1021. /*
  1022. * Make sure the interrupt lines are in a proper state before
  1023. * further configuration.
  1024. */
  1025. intel_gpio_irq_init(pctrl);
  1026. return 0;
  1027. }
  1028. static int intel_gpio_add_community_ranges(struct intel_pinctrl *pctrl,
  1029. const struct intel_community *community)
  1030. {
  1031. int ret = 0, i;
  1032. for (i = 0; i < community->ngpps; i++) {
  1033. const struct intel_padgroup *gpp = &community->gpps[i];
  1034. if (gpp->gpio_base == INTEL_GPIO_BASE_NOMAP)
  1035. continue;
  1036. ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev),
  1037. gpp->gpio_base, gpp->base,
  1038. gpp->size);
  1039. if (ret)
  1040. return ret;
  1041. }
  1042. return ret;
  1043. }
  1044. static int intel_gpio_add_pin_ranges(struct gpio_chip *gc)
  1045. {
  1046. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  1047. int ret, i;
  1048. for (i = 0; i < pctrl->ncommunities; i++) {
  1049. struct intel_community *community = &pctrl->communities[i];
  1050. ret = intel_gpio_add_community_ranges(pctrl, community);
  1051. if (ret) {
  1052. dev_err(pctrl->dev, "failed to add GPIO pin range\n");
  1053. return ret;
  1054. }
  1055. }
  1056. return 0;
  1057. }
  1058. static unsigned int intel_gpio_ngpio(const struct intel_pinctrl *pctrl)
  1059. {
  1060. const struct intel_community *community;
  1061. unsigned int ngpio = 0;
  1062. int i, j;
  1063. for (i = 0; i < pctrl->ncommunities; i++) {
  1064. community = &pctrl->communities[i];
  1065. for (j = 0; j < community->ngpps; j++) {
  1066. const struct intel_padgroup *gpp = &community->gpps[j];
  1067. if (gpp->gpio_base == INTEL_GPIO_BASE_NOMAP)
  1068. continue;
  1069. if (gpp->gpio_base + gpp->size > ngpio)
  1070. ngpio = gpp->gpio_base + gpp->size;
  1071. }
  1072. }
  1073. return ngpio;
  1074. }
  1075. static int intel_gpio_probe(struct intel_pinctrl *pctrl, int irq)
  1076. {
  1077. int ret;
  1078. struct gpio_irq_chip *girq;
  1079. pctrl->chip = intel_gpio_chip;
  1080. /* Setup GPIO chip */
  1081. pctrl->chip.ngpio = intel_gpio_ngpio(pctrl);
  1082. pctrl->chip.label = dev_name(pctrl->dev);
  1083. pctrl->chip.parent = pctrl->dev;
  1084. pctrl->chip.base = -1;
  1085. pctrl->chip.add_pin_ranges = intel_gpio_add_pin_ranges;
  1086. pctrl->irq = irq;
  1087. /*
  1088. * On some platforms several GPIO controllers share the same interrupt
  1089. * line.
  1090. */
  1091. ret = devm_request_irq(pctrl->dev, irq, intel_gpio_irq,
  1092. IRQF_SHARED | IRQF_NO_THREAD,
  1093. dev_name(pctrl->dev), pctrl);
  1094. if (ret) {
  1095. dev_err(pctrl->dev, "failed to request interrupt\n");
  1096. return ret;
  1097. }
  1098. /* Setup IRQ chip */
  1099. girq = &pctrl->chip.irq;
  1100. gpio_irq_chip_set_chip(girq, &intel_gpio_irq_chip);
  1101. /* This will let us handle the IRQ in the driver */
  1102. girq->parent_handler = NULL;
  1103. girq->num_parents = 0;
  1104. girq->default_type = IRQ_TYPE_NONE;
  1105. girq->handler = handle_bad_irq;
  1106. girq->init_hw = intel_gpio_irq_init_hw;
  1107. ret = devm_gpiochip_add_data(pctrl->dev, &pctrl->chip, pctrl);
  1108. if (ret) {
  1109. dev_err(pctrl->dev, "failed to register gpiochip\n");
  1110. return ret;
  1111. }
  1112. return 0;
  1113. }
  1114. static int intel_pinctrl_add_padgroups_by_gpps(struct intel_pinctrl *pctrl,
  1115. struct intel_community *community)
  1116. {
  1117. struct intel_padgroup *gpps;
  1118. unsigned int padown_num = 0;
  1119. size_t i, ngpps = community->ngpps;
  1120. gpps = devm_kcalloc(pctrl->dev, ngpps, sizeof(*gpps), GFP_KERNEL);
  1121. if (!gpps)
  1122. return -ENOMEM;
  1123. for (i = 0; i < ngpps; i++) {
  1124. gpps[i] = community->gpps[i];
  1125. if (gpps[i].size > 32)
  1126. return -EINVAL;
  1127. /* Special treatment for GPIO base */
  1128. switch (gpps[i].gpio_base) {
  1129. case INTEL_GPIO_BASE_MATCH:
  1130. gpps[i].gpio_base = gpps[i].base;
  1131. break;
  1132. case INTEL_GPIO_BASE_ZERO:
  1133. gpps[i].gpio_base = 0;
  1134. break;
  1135. case INTEL_GPIO_BASE_NOMAP:
  1136. break;
  1137. default:
  1138. break;
  1139. }
  1140. gpps[i].padown_num = padown_num;
  1141. padown_num += DIV_ROUND_UP(gpps[i].size * 4, 32);
  1142. }
  1143. community->gpps = gpps;
  1144. return 0;
  1145. }
  1146. static int intel_pinctrl_add_padgroups_by_size(struct intel_pinctrl *pctrl,
  1147. struct intel_community *community)
  1148. {
  1149. struct intel_padgroup *gpps;
  1150. unsigned int npins = community->npins;
  1151. unsigned int padown_num = 0;
  1152. size_t i, ngpps = DIV_ROUND_UP(npins, community->gpp_size);
  1153. if (community->gpp_size > 32)
  1154. return -EINVAL;
  1155. gpps = devm_kcalloc(pctrl->dev, ngpps, sizeof(*gpps), GFP_KERNEL);
  1156. if (!gpps)
  1157. return -ENOMEM;
  1158. for (i = 0; i < ngpps; i++) {
  1159. unsigned int gpp_size = community->gpp_size;
  1160. gpps[i].reg_num = i;
  1161. gpps[i].base = community->pin_base + i * gpp_size;
  1162. gpps[i].size = min(gpp_size, npins);
  1163. npins -= gpps[i].size;
  1164. gpps[i].gpio_base = gpps[i].base;
  1165. gpps[i].padown_num = padown_num;
  1166. /*
  1167. * In older hardware the number of padown registers per
  1168. * group is fixed regardless of the group size.
  1169. */
  1170. if (community->gpp_num_padown_regs)
  1171. padown_num += community->gpp_num_padown_regs;
  1172. else
  1173. padown_num += DIV_ROUND_UP(gpps[i].size * 4, 32);
  1174. }
  1175. community->ngpps = ngpps;
  1176. community->gpps = gpps;
  1177. return 0;
  1178. }
  1179. static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
  1180. {
  1181. #ifdef CONFIG_PM_SLEEP
  1182. const struct intel_pinctrl_soc_data *soc = pctrl->soc;
  1183. struct intel_community_context *communities;
  1184. struct intel_pad_context *pads;
  1185. int i;
  1186. pads = devm_kcalloc(pctrl->dev, soc->npins, sizeof(*pads), GFP_KERNEL);
  1187. if (!pads)
  1188. return -ENOMEM;
  1189. communities = devm_kcalloc(pctrl->dev, pctrl->ncommunities,
  1190. sizeof(*communities), GFP_KERNEL);
  1191. if (!communities)
  1192. return -ENOMEM;
  1193. for (i = 0; i < pctrl->ncommunities; i++) {
  1194. struct intel_community *community = &pctrl->communities[i];
  1195. u32 *intmask, *hostown;
  1196. intmask = devm_kcalloc(pctrl->dev, community->ngpps,
  1197. sizeof(*intmask), GFP_KERNEL);
  1198. if (!intmask)
  1199. return -ENOMEM;
  1200. communities[i].intmask = intmask;
  1201. hostown = devm_kcalloc(pctrl->dev, community->ngpps,
  1202. sizeof(*hostown), GFP_KERNEL);
  1203. if (!hostown)
  1204. return -ENOMEM;
  1205. communities[i].hostown = hostown;
  1206. }
  1207. pctrl->context.pads = pads;
  1208. pctrl->context.communities = communities;
  1209. #endif
  1210. return 0;
  1211. }
  1212. static int intel_pinctrl_probe(struct platform_device *pdev,
  1213. const struct intel_pinctrl_soc_data *soc_data)
  1214. {
  1215. struct intel_pinctrl *pctrl;
  1216. int i, ret, irq;
  1217. pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
  1218. if (!pctrl)
  1219. return -ENOMEM;
  1220. pctrl->dev = &pdev->dev;
  1221. pctrl->soc = soc_data;
  1222. raw_spin_lock_init(&pctrl->lock);
  1223. /*
  1224. * Make a copy of the communities which we can use to hold pointers
  1225. * to the registers.
  1226. */
  1227. pctrl->ncommunities = pctrl->soc->ncommunities;
  1228. pctrl->communities = devm_kcalloc(&pdev->dev, pctrl->ncommunities,
  1229. sizeof(*pctrl->communities), GFP_KERNEL);
  1230. if (!pctrl->communities)
  1231. return -ENOMEM;
  1232. for (i = 0; i < pctrl->ncommunities; i++) {
  1233. struct intel_community *community = &pctrl->communities[i];
  1234. void __iomem *regs;
  1235. u32 offset;
  1236. u32 value;
  1237. *community = pctrl->soc->communities[i];
  1238. regs = devm_platform_ioremap_resource(pdev, community->barno);
  1239. if (IS_ERR(regs))
  1240. return PTR_ERR(regs);
  1241. /*
  1242. * Determine community features based on the revision.
  1243. * A value of all ones means the device is not present.
  1244. */
  1245. value = readl(regs + REVID);
  1246. if (value == ~0u)
  1247. return -ENODEV;
  1248. if (((value & REVID_MASK) >> REVID_SHIFT) >= 0x94) {
  1249. community->features |= PINCTRL_FEATURE_DEBOUNCE;
  1250. community->features |= PINCTRL_FEATURE_1K_PD;
  1251. }
  1252. /* Determine community features based on the capabilities */
  1253. offset = CAPLIST;
  1254. do {
  1255. value = readl(regs + offset);
  1256. switch ((value & CAPLIST_ID_MASK) >> CAPLIST_ID_SHIFT) {
  1257. case CAPLIST_ID_GPIO_HW_INFO:
  1258. community->features |= PINCTRL_FEATURE_GPIO_HW_INFO;
  1259. break;
  1260. case CAPLIST_ID_PWM:
  1261. community->features |= PINCTRL_FEATURE_PWM;
  1262. break;
  1263. case CAPLIST_ID_BLINK:
  1264. community->features |= PINCTRL_FEATURE_BLINK;
  1265. break;
  1266. case CAPLIST_ID_EXP:
  1267. community->features |= PINCTRL_FEATURE_EXP;
  1268. break;
  1269. default:
  1270. break;
  1271. }
  1272. offset = (value & CAPLIST_NEXT_MASK) >> CAPLIST_NEXT_SHIFT;
  1273. } while (offset);
  1274. dev_dbg(&pdev->dev, "Community%d features: %#08x\n", i, community->features);
  1275. /* Read offset of the pad configuration registers */
  1276. offset = readl(regs + PADBAR);
  1277. community->regs = regs;
  1278. community->pad_regs = regs + offset;
  1279. if (community->gpps)
  1280. ret = intel_pinctrl_add_padgroups_by_gpps(pctrl, community);
  1281. else
  1282. ret = intel_pinctrl_add_padgroups_by_size(pctrl, community);
  1283. if (ret)
  1284. return ret;
  1285. }
  1286. irq = platform_get_irq(pdev, 0);
  1287. if (irq < 0)
  1288. return irq;
  1289. ret = intel_pinctrl_pm_init(pctrl);
  1290. if (ret)
  1291. return ret;
  1292. pctrl->pctldesc = intel_pinctrl_desc;
  1293. pctrl->pctldesc.name = dev_name(&pdev->dev);
  1294. pctrl->pctldesc.pins = pctrl->soc->pins;
  1295. pctrl->pctldesc.npins = pctrl->soc->npins;
  1296. pctrl->pctldev = devm_pinctrl_register(&pdev->dev, &pctrl->pctldesc,
  1297. pctrl);
  1298. if (IS_ERR(pctrl->pctldev)) {
  1299. dev_err(&pdev->dev, "failed to register pinctrl driver\n");
  1300. return PTR_ERR(pctrl->pctldev);
  1301. }
  1302. ret = intel_gpio_probe(pctrl, irq);
  1303. if (ret)
  1304. return ret;
  1305. platform_set_drvdata(pdev, pctrl);
  1306. return 0;
  1307. }
  1308. int intel_pinctrl_probe_by_hid(struct platform_device *pdev)
  1309. {
  1310. const struct intel_pinctrl_soc_data *data;
  1311. data = device_get_match_data(&pdev->dev);
  1312. if (!data)
  1313. return -ENODATA;
  1314. return intel_pinctrl_probe(pdev, data);
  1315. }
  1316. EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_hid);
  1317. int intel_pinctrl_probe_by_uid(struct platform_device *pdev)
  1318. {
  1319. const struct intel_pinctrl_soc_data *data;
  1320. data = intel_pinctrl_get_soc_data(pdev);
  1321. if (IS_ERR(data))
  1322. return PTR_ERR(data);
  1323. return intel_pinctrl_probe(pdev, data);
  1324. }
  1325. EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_uid);
  1326. const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev)
  1327. {
  1328. const struct intel_pinctrl_soc_data * const *table;
  1329. const struct intel_pinctrl_soc_data *data = NULL;
  1330. table = device_get_match_data(&pdev->dev);
  1331. if (table) {
  1332. struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
  1333. unsigned int i;
  1334. for (i = 0; table[i]; i++) {
  1335. if (!strcmp(adev->pnp.unique_id, table[i]->uid)) {
  1336. data = table[i];
  1337. break;
  1338. }
  1339. }
  1340. } else {
  1341. const struct platform_device_id *id;
  1342. id = platform_get_device_id(pdev);
  1343. if (!id)
  1344. return ERR_PTR(-ENODEV);
  1345. table = (const struct intel_pinctrl_soc_data * const *)id->driver_data;
  1346. data = table[pdev->id];
  1347. }
  1348. return data ?: ERR_PTR(-ENODATA);
  1349. }
  1350. EXPORT_SYMBOL_GPL(intel_pinctrl_get_soc_data);
  1351. #ifdef CONFIG_PM_SLEEP
  1352. static bool __intel_gpio_is_direct_irq(u32 value)
  1353. {
  1354. return (value & PADCFG0_GPIROUTIOXAPIC) && (value & PADCFG0_GPIOTXDIS) &&
  1355. (__intel_gpio_get_gpio_mode(value) == PADCFG0_PMODE_GPIO);
  1356. }
  1357. static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned int pin)
  1358. {
  1359. const struct pin_desc *pd = pin_desc_get(pctrl->pctldev, pin);
  1360. u32 value;
  1361. if (!pd || !intel_pad_usable(pctrl, pin))
  1362. return false;
  1363. /*
  1364. * Only restore the pin if it is actually in use by the kernel (or
  1365. * by userspace). It is possible that some pins are used by the
  1366. * BIOS during resume and those are not always locked down so leave
  1367. * them alone.
  1368. */
  1369. if (pd->mux_owner || pd->gpio_owner ||
  1370. gpiochip_line_is_irq(&pctrl->chip, intel_pin_to_gpio(pctrl, pin)))
  1371. return true;
  1372. /*
  1373. * The firmware on some systems may configure GPIO pins to be
  1374. * an interrupt source in so called "direct IRQ" mode. In such
  1375. * cases the GPIO controller driver has no idea if those pins
  1376. * are being used or not. At the same time, there is a known bug
  1377. * in the firmwares that don't restore the pin settings correctly
  1378. * after suspend, i.e. by an unknown reason the Rx value becomes
  1379. * inverted.
  1380. *
  1381. * Hence, let's save and restore the pins that are configured
  1382. * as GPIOs in the input mode with GPIROUTIOXAPIC bit set.
  1383. *
  1384. * See https://bugzilla.kernel.org/show_bug.cgi?id=214749.
  1385. */
  1386. value = readl(intel_get_padcfg(pctrl, pin, PADCFG0));
  1387. if (__intel_gpio_is_direct_irq(value))
  1388. return true;
  1389. return false;
  1390. }
  1391. int intel_pinctrl_suspend_noirq(struct device *dev)
  1392. {
  1393. struct intel_pinctrl *pctrl = dev_get_drvdata(dev);
  1394. struct intel_community_context *communities;
  1395. struct intel_pad_context *pads;
  1396. int i;
  1397. pads = pctrl->context.pads;
  1398. for (i = 0; i < pctrl->soc->npins; i++) {
  1399. const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i];
  1400. void __iomem *padcfg;
  1401. u32 val;
  1402. if (!intel_pinctrl_should_save(pctrl, desc->number))
  1403. continue;
  1404. val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG0));
  1405. pads[i].padcfg0 = val & ~PADCFG0_GPIORXSTATE;
  1406. val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG1));
  1407. pads[i].padcfg1 = val;
  1408. padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG2);
  1409. if (padcfg)
  1410. pads[i].padcfg2 = readl(padcfg);
  1411. }
  1412. communities = pctrl->context.communities;
  1413. for (i = 0; i < pctrl->ncommunities; i++) {
  1414. struct intel_community *community = &pctrl->communities[i];
  1415. void __iomem *base;
  1416. unsigned int gpp;
  1417. base = community->regs + community->ie_offset;
  1418. for (gpp = 0; gpp < community->ngpps; gpp++)
  1419. communities[i].intmask[gpp] = readl(base + gpp * 4);
  1420. base = community->regs + community->hostown_offset;
  1421. for (gpp = 0; gpp < community->ngpps; gpp++)
  1422. communities[i].hostown[gpp] = readl(base + gpp * 4);
  1423. }
  1424. return 0;
  1425. }
  1426. EXPORT_SYMBOL_GPL(intel_pinctrl_suspend_noirq);
  1427. static bool intel_gpio_update_reg(void __iomem *reg, u32 mask, u32 value)
  1428. {
  1429. u32 curr, updated;
  1430. curr = readl(reg);
  1431. updated = (curr & ~mask) | (value & mask);
  1432. if (curr == updated)
  1433. return false;
  1434. writel(updated, reg);
  1435. return true;
  1436. }
  1437. static void intel_restore_hostown(struct intel_pinctrl *pctrl, unsigned int c,
  1438. void __iomem *base, unsigned int gpp, u32 saved)
  1439. {
  1440. const struct intel_community *community = &pctrl->communities[c];
  1441. const struct intel_padgroup *padgrp = &community->gpps[gpp];
  1442. struct device *dev = pctrl->dev;
  1443. const char *dummy;
  1444. u32 requested = 0;
  1445. unsigned int i;
  1446. if (padgrp->gpio_base == INTEL_GPIO_BASE_NOMAP)
  1447. return;
  1448. for_each_requested_gpio_in_range(&pctrl->chip, i, padgrp->gpio_base, padgrp->size, dummy)
  1449. requested |= BIT(i);
  1450. if (!intel_gpio_update_reg(base + gpp * 4, requested, saved))
  1451. return;
  1452. dev_dbg(dev, "restored hostown %u/%u %#08x\n", c, gpp, readl(base + gpp * 4));
  1453. }
  1454. static void intel_restore_intmask(struct intel_pinctrl *pctrl, unsigned int c,
  1455. void __iomem *base, unsigned int gpp, u32 saved)
  1456. {
  1457. struct device *dev = pctrl->dev;
  1458. if (!intel_gpio_update_reg(base + gpp * 4, ~0U, saved))
  1459. return;
  1460. dev_dbg(dev, "restored mask %u/%u %#08x\n", c, gpp, readl(base + gpp * 4));
  1461. }
  1462. static void intel_restore_padcfg(struct intel_pinctrl *pctrl, unsigned int pin,
  1463. unsigned int reg, u32 saved)
  1464. {
  1465. u32 mask = (reg == PADCFG0) ? PADCFG0_GPIORXSTATE : 0;
  1466. unsigned int n = reg / sizeof(u32);
  1467. struct device *dev = pctrl->dev;
  1468. void __iomem *padcfg;
  1469. padcfg = intel_get_padcfg(pctrl, pin, reg);
  1470. if (!padcfg)
  1471. return;
  1472. if (!intel_gpio_update_reg(padcfg, ~mask, saved))
  1473. return;
  1474. dev_dbg(dev, "restored pin %u padcfg%u %#08x\n", pin, n, readl(padcfg));
  1475. }
  1476. int intel_pinctrl_resume_noirq(struct device *dev)
  1477. {
  1478. struct intel_pinctrl *pctrl = dev_get_drvdata(dev);
  1479. const struct intel_community_context *communities;
  1480. const struct intel_pad_context *pads;
  1481. int i;
  1482. /* Mask all interrupts */
  1483. intel_gpio_irq_init(pctrl);
  1484. pads = pctrl->context.pads;
  1485. for (i = 0; i < pctrl->soc->npins; i++) {
  1486. const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i];
  1487. if (!(intel_pinctrl_should_save(pctrl, desc->number) ||
  1488. /*
  1489. * If the firmware mangled the register contents too much,
  1490. * check the saved value for the Direct IRQ mode.
  1491. */
  1492. __intel_gpio_is_direct_irq(pads[i].padcfg0)))
  1493. continue;
  1494. intel_restore_padcfg(pctrl, desc->number, PADCFG0, pads[i].padcfg0);
  1495. intel_restore_padcfg(pctrl, desc->number, PADCFG1, pads[i].padcfg1);
  1496. intel_restore_padcfg(pctrl, desc->number, PADCFG2, pads[i].padcfg2);
  1497. }
  1498. communities = pctrl->context.communities;
  1499. for (i = 0; i < pctrl->ncommunities; i++) {
  1500. struct intel_community *community = &pctrl->communities[i];
  1501. void __iomem *base;
  1502. unsigned int gpp;
  1503. base = community->regs + community->ie_offset;
  1504. for (gpp = 0; gpp < community->ngpps; gpp++)
  1505. intel_restore_intmask(pctrl, i, base, gpp, communities[i].intmask[gpp]);
  1506. base = community->regs + community->hostown_offset;
  1507. for (gpp = 0; gpp < community->ngpps; gpp++)
  1508. intel_restore_hostown(pctrl, i, base, gpp, communities[i].hostown[gpp]);
  1509. }
  1510. return 0;
  1511. }
  1512. EXPORT_SYMBOL_GPL(intel_pinctrl_resume_noirq);
  1513. #endif
  1514. MODULE_AUTHOR("Mathias Nyman <[email protected]>");
  1515. MODULE_AUTHOR("Mika Westerberg <[email protected]>");
  1516. MODULE_DESCRIPTION("Intel pinctrl/GPIO core driver");
  1517. MODULE_LICENSE("GPL v2");