pinctrl-cherryview.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Cherryview/Braswell pinctrl driver
  4. *
  5. * Copyright (C) 2014, 2020 Intel Corporation
  6. * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
  7. *
  8. * This driver is based on the original Cherryview GPIO driver by
  9. * Ning Li <ning.li@intel.com>
  10. * Alan Cox <alan@linux.intel.com>
  11. */
  12. #include <linux/acpi.h>
  13. #include <linux/array_size.h>
  14. #include <linux/cleanup.h>
  15. #include <linux/dmi.h>
  16. #include <linux/gpio/driver.h>
  17. #include <linux/module.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/types.h>
  21. #include <linux/pinctrl/consumer.h>
  22. #include <linux/pinctrl/pinconf-generic.h>
  23. #include <linux/pinctrl/pinconf.h>
  24. #include <linux/pinctrl/pinctrl.h>
  25. #include <linux/pinctrl/pinmux.h>
  26. #include "pinctrl-intel.h"
  27. #define CHV_INTSTAT 0x300
  28. #define CHV_INTMASK 0x380
  29. #define FAMILY_PAD_REGS_OFF 0x4400
  30. #define FAMILY_PAD_REGS_SIZE 0x400
  31. #define MAX_FAMILY_PAD_GPIO_NO 15
  32. #define GPIO_REGS_SIZE 8
  33. #define CHV_PADCTRL0 0x000
  34. #define CHV_PADCTRL0_INTSEL_SHIFT 28
  35. #define CHV_PADCTRL0_INTSEL_MASK GENMASK(31, 28)
  36. #define CHV_PADCTRL0_TERM_UP BIT(23)
  37. #define CHV_PADCTRL0_TERM_SHIFT 20
  38. #define CHV_PADCTRL0_TERM_MASK GENMASK(22, 20)
  39. #define CHV_PADCTRL0_TERM_20K 1
  40. #define CHV_PADCTRL0_TERM_5K 2
  41. #define CHV_PADCTRL0_TERM_1K 4
  42. #define CHV_PADCTRL0_PMODE_SHIFT 16
  43. #define CHV_PADCTRL0_PMODE_MASK GENMASK(19, 16)
  44. #define CHV_PADCTRL0_GPIOEN BIT(15)
  45. #define CHV_PADCTRL0_GPIOCFG_SHIFT 8
  46. #define CHV_PADCTRL0_GPIOCFG_MASK GENMASK(10, 8)
  47. #define CHV_PADCTRL0_GPIOCFG_GPIO 0
  48. #define CHV_PADCTRL0_GPIOCFG_GPO 1
  49. #define CHV_PADCTRL0_GPIOCFG_GPI 2
  50. #define CHV_PADCTRL0_GPIOCFG_HIZ 3
  51. #define CHV_PADCTRL0_GPIOTXSTATE BIT(1)
  52. #define CHV_PADCTRL0_GPIORXSTATE BIT(0)
  53. #define CHV_PADCTRL1 0x004
  54. #define CHV_PADCTRL1_CFGLOCK BIT(31)
  55. #define CHV_PADCTRL1_INVRXTX_SHIFT 4
  56. #define CHV_PADCTRL1_INVRXTX_MASK GENMASK(7, 4)
  57. #define CHV_PADCTRL1_INVRXTX_TXDATA BIT(7)
  58. #define CHV_PADCTRL1_INVRXTX_RXDATA BIT(6)
  59. #define CHV_PADCTRL1_INVRXTX_TXENABLE BIT(5)
  60. #define CHV_PADCTRL1_ODEN BIT(3)
  61. #define CHV_PADCTRL1_INTWAKECFG_MASK GENMASK(2, 0)
  62. #define CHV_PADCTRL1_INTWAKECFG_FALLING 1
  63. #define CHV_PADCTRL1_INTWAKECFG_RISING 2
  64. #define CHV_PADCTRL1_INTWAKECFG_BOTH 3
  65. #define CHV_PADCTRL1_INTWAKECFG_LEVEL 4
  66. struct intel_pad_context {
  67. u32 padctrl0;
  68. u32 padctrl1;
  69. };
  70. #define CHV_INVALID_HWIRQ (~0U)
  71. /**
  72. * struct intel_community_context - community context for Cherryview
  73. * @intr_lines: Mapping between 16 HW interrupt wires and GPIO offset (in GPIO number space)
  74. * @saved_intmask: Interrupt mask saved for system sleep
  75. */
  76. struct intel_community_context {
  77. unsigned int intr_lines[16];
  78. u32 saved_intmask;
  79. };
  80. #define PINMODE_INVERT_OE BIT(15)
  81. #define PINMODE(m, i) ((m) | ((i) * PINMODE_INVERT_OE))
  82. #define CHV_GPP(start, end) \
  83. { \
  84. .base = (start), \
  85. .size = (end) - (start) + 1, \
  86. }
  87. #define CHV_COMMUNITY(g, i, a) \
  88. { \
  89. .gpps = (g), \
  90. .ngpps = ARRAY_SIZE(g), \
  91. .nirqs = (i), \
  92. .acpi_space_id = (a), \
  93. }
  94. static const struct pinctrl_pin_desc southwest_pins[] = {
  95. PINCTRL_PIN(0, "FST_SPI_D2"),
  96. PINCTRL_PIN(1, "FST_SPI_D0"),
  97. PINCTRL_PIN(2, "FST_SPI_CLK"),
  98. PINCTRL_PIN(3, "FST_SPI_D3"),
  99. PINCTRL_PIN(4, "FST_SPI_CS1_B"),
  100. PINCTRL_PIN(5, "FST_SPI_D1"),
  101. PINCTRL_PIN(6, "FST_SPI_CS0_B"),
  102. PINCTRL_PIN(7, "FST_SPI_CS2_B"),
  103. PINCTRL_PIN(15, "UART1_RTS_B"),
  104. PINCTRL_PIN(16, "UART1_RXD"),
  105. PINCTRL_PIN(17, "UART2_RXD"),
  106. PINCTRL_PIN(18, "UART1_CTS_B"),
  107. PINCTRL_PIN(19, "UART2_RTS_B"),
  108. PINCTRL_PIN(20, "UART1_TXD"),
  109. PINCTRL_PIN(21, "UART2_TXD"),
  110. PINCTRL_PIN(22, "UART2_CTS_B"),
  111. PINCTRL_PIN(30, "MF_HDA_CLK"),
  112. PINCTRL_PIN(31, "MF_HDA_RSTB"),
  113. PINCTRL_PIN(32, "MF_HDA_SDIO"),
  114. PINCTRL_PIN(33, "MF_HDA_SDO"),
  115. PINCTRL_PIN(34, "MF_HDA_DOCKRSTB"),
  116. PINCTRL_PIN(35, "MF_HDA_SYNC"),
  117. PINCTRL_PIN(36, "MF_HDA_SDI1"),
  118. PINCTRL_PIN(37, "MF_HDA_DOCKENB"),
  119. PINCTRL_PIN(45, "I2C5_SDA"),
  120. PINCTRL_PIN(46, "I2C4_SDA"),
  121. PINCTRL_PIN(47, "I2C6_SDA"),
  122. PINCTRL_PIN(48, "I2C5_SCL"),
  123. PINCTRL_PIN(49, "I2C_NFC_SDA"),
  124. PINCTRL_PIN(50, "I2C4_SCL"),
  125. PINCTRL_PIN(51, "I2C6_SCL"),
  126. PINCTRL_PIN(52, "I2C_NFC_SCL"),
  127. PINCTRL_PIN(60, "I2C1_SDA"),
  128. PINCTRL_PIN(61, "I2C0_SDA"),
  129. PINCTRL_PIN(62, "I2C2_SDA"),
  130. PINCTRL_PIN(63, "I2C1_SCL"),
  131. PINCTRL_PIN(64, "I2C3_SDA"),
  132. PINCTRL_PIN(65, "I2C0_SCL"),
  133. PINCTRL_PIN(66, "I2C2_SCL"),
  134. PINCTRL_PIN(67, "I2C3_SCL"),
  135. PINCTRL_PIN(75, "SATA_GP0"),
  136. PINCTRL_PIN(76, "SATA_GP1"),
  137. PINCTRL_PIN(77, "SATA_LEDN"),
  138. PINCTRL_PIN(78, "SATA_GP2"),
  139. PINCTRL_PIN(79, "MF_SMB_ALERTB"),
  140. PINCTRL_PIN(80, "SATA_GP3"),
  141. PINCTRL_PIN(81, "MF_SMB_CLK"),
  142. PINCTRL_PIN(82, "MF_SMB_DATA"),
  143. PINCTRL_PIN(90, "PCIE_CLKREQ0B"),
  144. PINCTRL_PIN(91, "PCIE_CLKREQ1B"),
  145. PINCTRL_PIN(92, "GP_SSP_2_CLK"),
  146. PINCTRL_PIN(93, "PCIE_CLKREQ2B"),
  147. PINCTRL_PIN(94, "GP_SSP_2_RXD"),
  148. PINCTRL_PIN(95, "PCIE_CLKREQ3B"),
  149. PINCTRL_PIN(96, "GP_SSP_2_FS"),
  150. PINCTRL_PIN(97, "GP_SSP_2_TXD"),
  151. };
  152. static const unsigned southwest_uart0_pins[] = { 16, 20 };
  153. static const unsigned southwest_uart1_pins[] = { 15, 16, 18, 20 };
  154. static const unsigned southwest_uart2_pins[] = { 17, 19, 21, 22 };
  155. static const unsigned southwest_i2c0_pins[] = { 61, 65 };
  156. static const unsigned southwest_hda_pins[] = { 30, 31, 32, 33, 34, 35, 36, 37 };
  157. static const unsigned southwest_lpe_pins[] = {
  158. 30, 31, 32, 33, 34, 35, 36, 37, 92, 94, 96, 97,
  159. };
  160. static const unsigned southwest_i2c1_pins[] = { 60, 63 };
  161. static const unsigned southwest_i2c2_pins[] = { 62, 66 };
  162. static const unsigned southwest_i2c3_pins[] = { 64, 67 };
  163. static const unsigned southwest_i2c4_pins[] = { 46, 50 };
  164. static const unsigned southwest_i2c5_pins[] = { 45, 48 };
  165. static const unsigned southwest_i2c6_pins[] = { 47, 51 };
  166. static const unsigned southwest_i2c_nfc_pins[] = { 49, 52 };
  167. static const unsigned southwest_spi3_pins[] = { 76, 79, 80, 81, 82 };
  168. /* Some of LPE I2S TXD pins need to have OE inversion set */
  169. static const unsigned int southwest_lpe_altfuncs[] = {
  170. PINMODE(1, 1), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), /* 30, 31, 32, 33 */
  171. PINMODE(1, 1), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), /* 34, 35, 36, 37 */
  172. PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 1), /* 92, 94, 96, 97 */
  173. };
  174. /*
  175. * Two spi3 chipselects are available in different mode than the main spi3
  176. * functionality, which is using mode 2.
  177. */
  178. static const unsigned int southwest_spi3_altfuncs[] = {
  179. PINMODE(3, 0), PINMODE(2, 0), PINMODE(3, 0), PINMODE(2, 0), /* 76, 79, 80, 81 */
  180. PINMODE(2, 0), /* 82 */
  181. };
  182. static const struct intel_pingroup southwest_groups[] = {
  183. PIN_GROUP("uart0_grp", southwest_uart0_pins, PINMODE(2, 0)),
  184. PIN_GROUP("uart1_grp", southwest_uart1_pins, PINMODE(1, 0)),
  185. PIN_GROUP("uart2_grp", southwest_uart2_pins, PINMODE(1, 0)),
  186. PIN_GROUP("hda_grp", southwest_hda_pins, PINMODE(2, 0)),
  187. PIN_GROUP("i2c0_grp", southwest_i2c0_pins, PINMODE(1, 1)),
  188. PIN_GROUP("i2c1_grp", southwest_i2c1_pins, PINMODE(1, 1)),
  189. PIN_GROUP("i2c2_grp", southwest_i2c2_pins, PINMODE(1, 1)),
  190. PIN_GROUP("i2c3_grp", southwest_i2c3_pins, PINMODE(1, 1)),
  191. PIN_GROUP("i2c4_grp", southwest_i2c4_pins, PINMODE(1, 1)),
  192. PIN_GROUP("i2c5_grp", southwest_i2c5_pins, PINMODE(1, 1)),
  193. PIN_GROUP("i2c6_grp", southwest_i2c6_pins, PINMODE(1, 1)),
  194. PIN_GROUP("i2c_nfc_grp", southwest_i2c_nfc_pins, PINMODE(2, 1)),
  195. PIN_GROUP("lpe_grp", southwest_lpe_pins, southwest_lpe_altfuncs),
  196. PIN_GROUP("spi3_grp", southwest_spi3_pins, southwest_spi3_altfuncs),
  197. };
  198. static const char * const southwest_uart0_groups[] = { "uart0_grp" };
  199. static const char * const southwest_uart1_groups[] = { "uart1_grp" };
  200. static const char * const southwest_uart2_groups[] = { "uart2_grp" };
  201. static const char * const southwest_hda_groups[] = { "hda_grp" };
  202. static const char * const southwest_lpe_groups[] = { "lpe_grp" };
  203. static const char * const southwest_i2c0_groups[] = { "i2c0_grp" };
  204. static const char * const southwest_i2c1_groups[] = { "i2c1_grp" };
  205. static const char * const southwest_i2c2_groups[] = { "i2c2_grp" };
  206. static const char * const southwest_i2c3_groups[] = { "i2c3_grp" };
  207. static const char * const southwest_i2c4_groups[] = { "i2c4_grp" };
  208. static const char * const southwest_i2c5_groups[] = { "i2c5_grp" };
  209. static const char * const southwest_i2c6_groups[] = { "i2c6_grp" };
  210. static const char * const southwest_i2c_nfc_groups[] = { "i2c_nfc_grp" };
  211. static const char * const southwest_spi3_groups[] = { "spi3_grp" };
  212. /*
  213. * Only do pinmuxing for certain LPSS devices for now. Rest of the pins are
  214. * enabled only as GPIOs.
  215. */
  216. static const struct intel_function southwest_functions[] = {
  217. FUNCTION("uart0", southwest_uart0_groups),
  218. FUNCTION("uart1", southwest_uart1_groups),
  219. FUNCTION("uart2", southwest_uart2_groups),
  220. FUNCTION("hda", southwest_hda_groups),
  221. FUNCTION("lpe", southwest_lpe_groups),
  222. FUNCTION("i2c0", southwest_i2c0_groups),
  223. FUNCTION("i2c1", southwest_i2c1_groups),
  224. FUNCTION("i2c2", southwest_i2c2_groups),
  225. FUNCTION("i2c3", southwest_i2c3_groups),
  226. FUNCTION("i2c4", southwest_i2c4_groups),
  227. FUNCTION("i2c5", southwest_i2c5_groups),
  228. FUNCTION("i2c6", southwest_i2c6_groups),
  229. FUNCTION("i2c_nfc", southwest_i2c_nfc_groups),
  230. FUNCTION("spi3", southwest_spi3_groups),
  231. };
  232. static const struct intel_padgroup southwest_gpps[] = {
  233. CHV_GPP(0, 7),
  234. CHV_GPP(15, 22),
  235. CHV_GPP(30, 37),
  236. CHV_GPP(45, 52),
  237. CHV_GPP(60, 67),
  238. CHV_GPP(75, 82),
  239. CHV_GPP(90, 97),
  240. };
  241. /*
  242. * Southwest community can generate GPIO interrupts only for the first 8
  243. * interrupts. The upper half (8-15) can only be used to trigger GPEs.
  244. */
  245. static const struct intel_community southwest_communities[] = {
  246. CHV_COMMUNITY(southwest_gpps, 8, 0x91),
  247. };
  248. static const struct intel_pinctrl_soc_data southwest_soc_data = {
  249. .uid = "1",
  250. .pins = southwest_pins,
  251. .npins = ARRAY_SIZE(southwest_pins),
  252. .groups = southwest_groups,
  253. .ngroups = ARRAY_SIZE(southwest_groups),
  254. .functions = southwest_functions,
  255. .nfunctions = ARRAY_SIZE(southwest_functions),
  256. .communities = southwest_communities,
  257. .ncommunities = ARRAY_SIZE(southwest_communities),
  258. };
  259. static const struct pinctrl_pin_desc north_pins[] = {
  260. PINCTRL_PIN(0, "GPIO_DFX_0"),
  261. PINCTRL_PIN(1, "GPIO_DFX_3"),
  262. PINCTRL_PIN(2, "GPIO_DFX_7"),
  263. PINCTRL_PIN(3, "GPIO_DFX_1"),
  264. PINCTRL_PIN(4, "GPIO_DFX_5"),
  265. PINCTRL_PIN(5, "GPIO_DFX_4"),
  266. PINCTRL_PIN(6, "GPIO_DFX_8"),
  267. PINCTRL_PIN(7, "GPIO_DFX_2"),
  268. PINCTRL_PIN(8, "GPIO_DFX_6"),
  269. PINCTRL_PIN(15, "GPIO_SUS0"),
  270. PINCTRL_PIN(16, "SEC_GPIO_SUS10"),
  271. PINCTRL_PIN(17, "GPIO_SUS3"),
  272. PINCTRL_PIN(18, "GPIO_SUS7"),
  273. PINCTRL_PIN(19, "GPIO_SUS1"),
  274. PINCTRL_PIN(20, "GPIO_SUS5"),
  275. PINCTRL_PIN(21, "SEC_GPIO_SUS11"),
  276. PINCTRL_PIN(22, "GPIO_SUS4"),
  277. PINCTRL_PIN(23, "SEC_GPIO_SUS8"),
  278. PINCTRL_PIN(24, "GPIO_SUS2"),
  279. PINCTRL_PIN(25, "GPIO_SUS6"),
  280. PINCTRL_PIN(26, "CX_PREQ_B"),
  281. PINCTRL_PIN(27, "SEC_GPIO_SUS9"),
  282. PINCTRL_PIN(30, "TRST_B"),
  283. PINCTRL_PIN(31, "TCK"),
  284. PINCTRL_PIN(32, "PROCHOT_B"),
  285. PINCTRL_PIN(33, "SVIDO_DATA"),
  286. PINCTRL_PIN(34, "TMS"),
  287. PINCTRL_PIN(35, "CX_PRDY_B_2"),
  288. PINCTRL_PIN(36, "TDO_2"),
  289. PINCTRL_PIN(37, "CX_PRDY_B"),
  290. PINCTRL_PIN(38, "SVIDO_ALERT_B"),
  291. PINCTRL_PIN(39, "TDO"),
  292. PINCTRL_PIN(40, "SVIDO_CLK"),
  293. PINCTRL_PIN(41, "TDI"),
  294. PINCTRL_PIN(45, "GP_CAMERASB_05"),
  295. PINCTRL_PIN(46, "GP_CAMERASB_02"),
  296. PINCTRL_PIN(47, "GP_CAMERASB_08"),
  297. PINCTRL_PIN(48, "GP_CAMERASB_00"),
  298. PINCTRL_PIN(49, "GP_CAMERASB_06"),
  299. PINCTRL_PIN(50, "GP_CAMERASB_10"),
  300. PINCTRL_PIN(51, "GP_CAMERASB_03"),
  301. PINCTRL_PIN(52, "GP_CAMERASB_09"),
  302. PINCTRL_PIN(53, "GP_CAMERASB_01"),
  303. PINCTRL_PIN(54, "GP_CAMERASB_07"),
  304. PINCTRL_PIN(55, "GP_CAMERASB_11"),
  305. PINCTRL_PIN(56, "GP_CAMERASB_04"),
  306. PINCTRL_PIN(60, "PANEL0_BKLTEN"),
  307. PINCTRL_PIN(61, "HV_DDI0_HPD"),
  308. PINCTRL_PIN(62, "HV_DDI2_DDC_SDA"),
  309. PINCTRL_PIN(63, "PANEL1_BKLTCTL"),
  310. PINCTRL_PIN(64, "HV_DDI1_HPD"),
  311. PINCTRL_PIN(65, "PANEL0_BKLTCTL"),
  312. PINCTRL_PIN(66, "HV_DDI0_DDC_SDA"),
  313. PINCTRL_PIN(67, "HV_DDI2_DDC_SCL"),
  314. PINCTRL_PIN(68, "HV_DDI2_HPD"),
  315. PINCTRL_PIN(69, "PANEL1_VDDEN"),
  316. PINCTRL_PIN(70, "PANEL1_BKLTEN"),
  317. PINCTRL_PIN(71, "HV_DDI0_DDC_SCL"),
  318. PINCTRL_PIN(72, "PANEL0_VDDEN"),
  319. };
  320. static const struct intel_padgroup north_gpps[] = {
  321. CHV_GPP(0, 8),
  322. CHV_GPP(15, 27),
  323. CHV_GPP(30, 41),
  324. CHV_GPP(45, 56),
  325. CHV_GPP(60, 72),
  326. };
  327. /*
  328. * North community can generate GPIO interrupts only for the first 8
  329. * interrupts. The upper half (8-15) can only be used to trigger GPEs.
  330. */
  331. static const struct intel_community north_communities[] = {
  332. CHV_COMMUNITY(north_gpps, 8, 0x92),
  333. };
  334. static const struct intel_pinctrl_soc_data north_soc_data = {
  335. .uid = "2",
  336. .pins = north_pins,
  337. .npins = ARRAY_SIZE(north_pins),
  338. .communities = north_communities,
  339. .ncommunities = ARRAY_SIZE(north_communities),
  340. };
  341. static const struct pinctrl_pin_desc east_pins[] = {
  342. PINCTRL_PIN(0, "PMU_SLP_S3_B"),
  343. PINCTRL_PIN(1, "PMU_BATLOW_B"),
  344. PINCTRL_PIN(2, "SUS_STAT_B"),
  345. PINCTRL_PIN(3, "PMU_SLP_S0IX_B"),
  346. PINCTRL_PIN(4, "PMU_AC_PRESENT"),
  347. PINCTRL_PIN(5, "PMU_PLTRST_B"),
  348. PINCTRL_PIN(6, "PMU_SUSCLK"),
  349. PINCTRL_PIN(7, "PMU_SLP_LAN_B"),
  350. PINCTRL_PIN(8, "PMU_PWRBTN_B"),
  351. PINCTRL_PIN(9, "PMU_SLP_S4_B"),
  352. PINCTRL_PIN(10, "PMU_WAKE_B"),
  353. PINCTRL_PIN(11, "PMU_WAKE_LAN_B"),
  354. PINCTRL_PIN(15, "MF_ISH_GPIO_3"),
  355. PINCTRL_PIN(16, "MF_ISH_GPIO_7"),
  356. PINCTRL_PIN(17, "MF_ISH_I2C1_SCL"),
  357. PINCTRL_PIN(18, "MF_ISH_GPIO_1"),
  358. PINCTRL_PIN(19, "MF_ISH_GPIO_5"),
  359. PINCTRL_PIN(20, "MF_ISH_GPIO_9"),
  360. PINCTRL_PIN(21, "MF_ISH_GPIO_0"),
  361. PINCTRL_PIN(22, "MF_ISH_GPIO_4"),
  362. PINCTRL_PIN(23, "MF_ISH_GPIO_8"),
  363. PINCTRL_PIN(24, "MF_ISH_GPIO_2"),
  364. PINCTRL_PIN(25, "MF_ISH_GPIO_6"),
  365. PINCTRL_PIN(26, "MF_ISH_I2C1_SDA"),
  366. };
  367. static const struct intel_padgroup east_gpps[] = {
  368. CHV_GPP(0, 11),
  369. CHV_GPP(15, 26),
  370. };
  371. static const struct intel_community east_communities[] = {
  372. CHV_COMMUNITY(east_gpps, 16, 0x93),
  373. };
  374. static const struct intel_pinctrl_soc_data east_soc_data = {
  375. .uid = "3",
  376. .pins = east_pins,
  377. .npins = ARRAY_SIZE(east_pins),
  378. .communities = east_communities,
  379. .ncommunities = ARRAY_SIZE(east_communities),
  380. };
  381. static const struct pinctrl_pin_desc southeast_pins[] = {
  382. PINCTRL_PIN(0, "MF_PLT_CLK0"),
  383. PINCTRL_PIN(1, "PWM1"),
  384. PINCTRL_PIN(2, "MF_PLT_CLK1"),
  385. PINCTRL_PIN(3, "MF_PLT_CLK4"),
  386. PINCTRL_PIN(4, "MF_PLT_CLK3"),
  387. PINCTRL_PIN(5, "PWM0"),
  388. PINCTRL_PIN(6, "MF_PLT_CLK5"),
  389. PINCTRL_PIN(7, "MF_PLT_CLK2"),
  390. PINCTRL_PIN(15, "SDMMC2_D3_CD_B"),
  391. PINCTRL_PIN(16, "SDMMC1_CLK"),
  392. PINCTRL_PIN(17, "SDMMC1_D0"),
  393. PINCTRL_PIN(18, "SDMMC2_D1"),
  394. PINCTRL_PIN(19, "SDMMC2_CLK"),
  395. PINCTRL_PIN(20, "SDMMC1_D2"),
  396. PINCTRL_PIN(21, "SDMMC2_D2"),
  397. PINCTRL_PIN(22, "SDMMC2_CMD"),
  398. PINCTRL_PIN(23, "SDMMC1_CMD"),
  399. PINCTRL_PIN(24, "SDMMC1_D1"),
  400. PINCTRL_PIN(25, "SDMMC2_D0"),
  401. PINCTRL_PIN(26, "SDMMC1_D3_CD_B"),
  402. PINCTRL_PIN(30, "SDMMC3_D1"),
  403. PINCTRL_PIN(31, "SDMMC3_CLK"),
  404. PINCTRL_PIN(32, "SDMMC3_D3"),
  405. PINCTRL_PIN(33, "SDMMC3_D2"),
  406. PINCTRL_PIN(34, "SDMMC3_CMD"),
  407. PINCTRL_PIN(35, "SDMMC3_D0"),
  408. PINCTRL_PIN(45, "MF_LPC_AD2"),
  409. PINCTRL_PIN(46, "LPC_CLKRUNB"),
  410. PINCTRL_PIN(47, "MF_LPC_AD0"),
  411. PINCTRL_PIN(48, "LPC_FRAMEB"),
  412. PINCTRL_PIN(49, "MF_LPC_CLKOUT1"),
  413. PINCTRL_PIN(50, "MF_LPC_AD3"),
  414. PINCTRL_PIN(51, "MF_LPC_CLKOUT0"),
  415. PINCTRL_PIN(52, "MF_LPC_AD1"),
  416. PINCTRL_PIN(60, "SPI1_MISO"),
  417. PINCTRL_PIN(61, "SPI1_CSO_B"),
  418. PINCTRL_PIN(62, "SPI1_CLK"),
  419. PINCTRL_PIN(63, "MMC1_D6"),
  420. PINCTRL_PIN(64, "SPI1_MOSI"),
  421. PINCTRL_PIN(65, "MMC1_D5"),
  422. PINCTRL_PIN(66, "SPI1_CS1_B"),
  423. PINCTRL_PIN(67, "MMC1_D4_SD_WE"),
  424. PINCTRL_PIN(68, "MMC1_D7"),
  425. PINCTRL_PIN(69, "MMC1_RCLK"),
  426. PINCTRL_PIN(75, "USB_OC1_B"),
  427. PINCTRL_PIN(76, "PMU_RESETBUTTON_B"),
  428. PINCTRL_PIN(77, "GPIO_ALERT"),
  429. PINCTRL_PIN(78, "SDMMC3_PWR_EN_B"),
  430. PINCTRL_PIN(79, "ILB_SERIRQ"),
  431. PINCTRL_PIN(80, "USB_OC0_B"),
  432. PINCTRL_PIN(81, "SDMMC3_CD_B"),
  433. PINCTRL_PIN(82, "SPKR"),
  434. PINCTRL_PIN(83, "SUSPWRDNACK"),
  435. PINCTRL_PIN(84, "SPARE_PIN"),
  436. PINCTRL_PIN(85, "SDMMC3_1P8_EN"),
  437. };
  438. static const unsigned southeast_pwm0_pins[] = { 5 };
  439. static const unsigned southeast_pwm1_pins[] = { 1 };
  440. static const unsigned southeast_sdmmc1_pins[] = {
  441. 16, 17, 20, 23, 24, 26, 63, 65, 67, 68, 69,
  442. };
  443. static const unsigned southeast_sdmmc2_pins[] = { 15, 18, 19, 21, 22, 25 };
  444. static const unsigned southeast_sdmmc3_pins[] = {
  445. 30, 31, 32, 33, 34, 35, 78, 81, 85,
  446. };
  447. static const unsigned southeast_spi1_pins[] = { 60, 61, 62, 64, 66 };
  448. static const unsigned southeast_spi2_pins[] = { 2, 3, 4, 6, 7 };
  449. static const struct intel_pingroup southeast_groups[] = {
  450. PIN_GROUP("pwm0_grp", southeast_pwm0_pins, PINMODE(1, 0)),
  451. PIN_GROUP("pwm1_grp", southeast_pwm1_pins, PINMODE(1, 0)),
  452. PIN_GROUP("sdmmc1_grp", southeast_sdmmc1_pins, PINMODE(1, 0)),
  453. PIN_GROUP("sdmmc2_grp", southeast_sdmmc2_pins, PINMODE(1, 0)),
  454. PIN_GROUP("sdmmc3_grp", southeast_sdmmc3_pins, PINMODE(1, 0)),
  455. PIN_GROUP("spi1_grp", southeast_spi1_pins, PINMODE(1, 0)),
  456. PIN_GROUP("spi2_grp", southeast_spi2_pins, PINMODE(4, 0)),
  457. };
  458. static const char * const southeast_pwm0_groups[] = { "pwm0_grp" };
  459. static const char * const southeast_pwm1_groups[] = { "pwm1_grp" };
  460. static const char * const southeast_sdmmc1_groups[] = { "sdmmc1_grp" };
  461. static const char * const southeast_sdmmc2_groups[] = { "sdmmc2_grp" };
  462. static const char * const southeast_sdmmc3_groups[] = { "sdmmc3_grp" };
  463. static const char * const southeast_spi1_groups[] = { "spi1_grp" };
  464. static const char * const southeast_spi2_groups[] = { "spi2_grp" };
  465. static const struct intel_function southeast_functions[] = {
  466. FUNCTION("pwm0", southeast_pwm0_groups),
  467. FUNCTION("pwm1", southeast_pwm1_groups),
  468. FUNCTION("sdmmc1", southeast_sdmmc1_groups),
  469. FUNCTION("sdmmc2", southeast_sdmmc2_groups),
  470. FUNCTION("sdmmc3", southeast_sdmmc3_groups),
  471. FUNCTION("spi1", southeast_spi1_groups),
  472. FUNCTION("spi2", southeast_spi2_groups),
  473. };
  474. static const struct intel_padgroup southeast_gpps[] = {
  475. CHV_GPP(0, 7),
  476. CHV_GPP(15, 26),
  477. CHV_GPP(30, 35),
  478. CHV_GPP(45, 52),
  479. CHV_GPP(60, 69),
  480. CHV_GPP(75, 85),
  481. };
  482. static const struct intel_community southeast_communities[] = {
  483. CHV_COMMUNITY(southeast_gpps, 16, 0x94),
  484. };
  485. static const struct intel_pinctrl_soc_data southeast_soc_data = {
  486. .uid = "4",
  487. .pins = southeast_pins,
  488. .npins = ARRAY_SIZE(southeast_pins),
  489. .groups = southeast_groups,
  490. .ngroups = ARRAY_SIZE(southeast_groups),
  491. .functions = southeast_functions,
  492. .nfunctions = ARRAY_SIZE(southeast_functions),
  493. .communities = southeast_communities,
  494. .ncommunities = ARRAY_SIZE(southeast_communities),
  495. };
  496. static const struct intel_pinctrl_soc_data *chv_soc_data[] = {
  497. &southwest_soc_data,
  498. &north_soc_data,
  499. &east_soc_data,
  500. &southeast_soc_data,
  501. NULL
  502. };
  503. /*
  504. * Lock to serialize register accesses
  505. *
  506. * Due to a silicon issue, a shared lock must be used to prevent
  507. * concurrent accesses across the 4 GPIO controllers.
  508. *
  509. * See Intel Atom Z8000 Processor Series Specification Update (Rev. 005),
  510. * errata #CHT34, for further information.
  511. */
  512. static DEFINE_RAW_SPINLOCK(chv_lock);
  513. static u32 chv_pctrl_readl(struct intel_pinctrl *pctrl, unsigned int offset)
  514. {
  515. const struct intel_community *community = &pctrl->communities[0];
  516. return readl(community->regs + offset);
  517. }
  518. static void chv_pctrl_writel(struct intel_pinctrl *pctrl, unsigned int offset, u32 value)
  519. {
  520. const struct intel_community *community = &pctrl->communities[0];
  521. void __iomem *reg = community->regs + offset;
  522. /* Write and simple read back to confirm the bus transferring done */
  523. writel(value, reg);
  524. readl(reg);
  525. }
  526. static void __iomem *chv_padreg(struct intel_pinctrl *pctrl, unsigned int offset,
  527. unsigned int reg)
  528. {
  529. const struct intel_community *community = &pctrl->communities[0];
  530. unsigned int family_no = offset / MAX_FAMILY_PAD_GPIO_NO;
  531. unsigned int pad_no = offset % MAX_FAMILY_PAD_GPIO_NO;
  532. offset = FAMILY_PAD_REGS_SIZE * family_no + GPIO_REGS_SIZE * pad_no;
  533. return community->pad_regs + offset + reg;
  534. }
  535. static u32 chv_readl(struct intel_pinctrl *pctrl, unsigned int pin, unsigned int offset)
  536. {
  537. return readl(chv_padreg(pctrl, pin, offset));
  538. }
  539. static void chv_writel(struct intel_pinctrl *pctrl, unsigned int pin, unsigned int offset, u32 value)
  540. {
  541. void __iomem *reg = chv_padreg(pctrl, pin, offset);
  542. /* Write and simple read back to confirm the bus transferring done */
  543. writel(value, reg);
  544. readl(reg);
  545. }
  546. /* When Pad Cfg is locked, driver can only change GPIOTXState or GPIORXState */
  547. static bool chv_pad_is_locked(u32 ctrl1)
  548. {
  549. return ctrl1 & CHV_PADCTRL1_CFGLOCK;
  550. }
  551. static bool chv_pad_locked(struct intel_pinctrl *pctrl, unsigned int offset)
  552. {
  553. return chv_pad_is_locked(chv_readl(pctrl, offset, CHV_PADCTRL1));
  554. }
  555. static void chv_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  556. unsigned int offset)
  557. {
  558. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  559. u32 ctrl0, ctrl1;
  560. scoped_guard(raw_spinlock_irqsave, &chv_lock) {
  561. ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0);
  562. ctrl1 = chv_readl(pctrl, offset, CHV_PADCTRL1);
  563. }
  564. if (ctrl0 & CHV_PADCTRL0_GPIOEN) {
  565. seq_puts(s, "GPIO ");
  566. } else {
  567. u32 mode;
  568. mode = ctrl0 & CHV_PADCTRL0_PMODE_MASK;
  569. mode >>= CHV_PADCTRL0_PMODE_SHIFT;
  570. seq_printf(s, "mode %d ", mode);
  571. }
  572. seq_printf(s, "0x%08x 0x%08x", ctrl0, ctrl1);
  573. if (chv_pad_is_locked(ctrl1))
  574. seq_puts(s, " [LOCKED]");
  575. }
  576. static const struct pinctrl_ops chv_pinctrl_ops = {
  577. .get_groups_count = intel_get_groups_count,
  578. .get_group_name = intel_get_group_name,
  579. .get_group_pins = intel_get_group_pins,
  580. .pin_dbg_show = chv_pin_dbg_show,
  581. };
  582. static int chv_pinmux_set_mux(struct pinctrl_dev *pctldev,
  583. unsigned int function, unsigned int group)
  584. {
  585. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  586. struct device *dev = pctrl->dev;
  587. const struct intel_pingroup *grp;
  588. int i;
  589. grp = &pctrl->soc->groups[group];
  590. guard(raw_spinlock_irqsave)(&chv_lock);
  591. /* Check first that the pad is not locked */
  592. for (i = 0; i < grp->grp.npins; i++) {
  593. if (chv_pad_locked(pctrl, grp->grp.pins[i])) {
  594. dev_warn(dev, "unable to set mode for locked pin %u\n", grp->grp.pins[i]);
  595. return -EBUSY;
  596. }
  597. }
  598. for (i = 0; i < grp->grp.npins; i++) {
  599. int pin = grp->grp.pins[i];
  600. unsigned int mode;
  601. bool invert_oe;
  602. u32 value;
  603. /* Check if there is pin-specific config */
  604. if (grp->modes)
  605. mode = grp->modes[i];
  606. else
  607. mode = grp->mode;
  608. /* Extract OE inversion */
  609. invert_oe = mode & PINMODE_INVERT_OE;
  610. mode &= ~PINMODE_INVERT_OE;
  611. value = chv_readl(pctrl, pin, CHV_PADCTRL0);
  612. /* Disable GPIO mode */
  613. value &= ~CHV_PADCTRL0_GPIOEN;
  614. /* Set to desired mode */
  615. value &= ~CHV_PADCTRL0_PMODE_MASK;
  616. value |= mode << CHV_PADCTRL0_PMODE_SHIFT;
  617. chv_writel(pctrl, pin, CHV_PADCTRL0, value);
  618. /* Update for invert_oe */
  619. value = chv_readl(pctrl, pin, CHV_PADCTRL1) & ~CHV_PADCTRL1_INVRXTX_MASK;
  620. if (invert_oe)
  621. value |= CHV_PADCTRL1_INVRXTX_TXENABLE;
  622. chv_writel(pctrl, pin, CHV_PADCTRL1, value);
  623. dev_dbg(dev, "configured pin %u mode %u OE %sinverted\n", pin, mode,
  624. invert_oe ? "" : "not ");
  625. }
  626. return 0;
  627. }
  628. static void chv_gpio_clear_triggering(struct intel_pinctrl *pctrl,
  629. unsigned int offset)
  630. {
  631. u32 invrxtx_mask = CHV_PADCTRL1_INVRXTX_MASK;
  632. u32 value;
  633. /*
  634. * One some devices the GPIO should output the inverted value from what
  635. * device-drivers / ACPI code expects (inverted external buffer?). The
  636. * BIOS makes this work by setting the CHV_PADCTRL1_INVRXTX_TXDATA flag,
  637. * preserve this flag if the pin is already setup as GPIO.
  638. */
  639. value = chv_readl(pctrl, offset, CHV_PADCTRL0);
  640. if (value & CHV_PADCTRL0_GPIOEN)
  641. invrxtx_mask &= ~CHV_PADCTRL1_INVRXTX_TXDATA;
  642. value = chv_readl(pctrl, offset, CHV_PADCTRL1);
  643. value &= ~CHV_PADCTRL1_INTWAKECFG_MASK;
  644. value &= ~invrxtx_mask;
  645. chv_writel(pctrl, offset, CHV_PADCTRL1, value);
  646. }
  647. static int chv_gpio_request_enable(struct pinctrl_dev *pctldev,
  648. struct pinctrl_gpio_range *range,
  649. unsigned int offset)
  650. {
  651. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  652. u32 value;
  653. guard(raw_spinlock_irqsave)(&chv_lock);
  654. if (chv_pad_locked(pctrl, offset)) {
  655. value = chv_readl(pctrl, offset, CHV_PADCTRL0);
  656. if (!(value & CHV_PADCTRL0_GPIOEN)) {
  657. /* Locked so cannot enable */
  658. return -EBUSY;
  659. }
  660. } else {
  661. struct intel_community_context *cctx = &pctrl->context.communities[0];
  662. int i;
  663. /* Reset the interrupt mapping */
  664. for (i = 0; i < ARRAY_SIZE(cctx->intr_lines); i++) {
  665. if (cctx->intr_lines[i] == offset) {
  666. cctx->intr_lines[i] = CHV_INVALID_HWIRQ;
  667. break;
  668. }
  669. }
  670. /* Disable interrupt generation */
  671. chv_gpio_clear_triggering(pctrl, offset);
  672. value = chv_readl(pctrl, offset, CHV_PADCTRL0);
  673. /*
  674. * If the pin is in HiZ mode (both TX and RX buffers are
  675. * disabled) we turn it to be input now.
  676. */
  677. if ((value & CHV_PADCTRL0_GPIOCFG_MASK) ==
  678. (CHV_PADCTRL0_GPIOCFG_HIZ << CHV_PADCTRL0_GPIOCFG_SHIFT)) {
  679. value &= ~CHV_PADCTRL0_GPIOCFG_MASK;
  680. value |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT;
  681. }
  682. /* Switch to a GPIO mode */
  683. value |= CHV_PADCTRL0_GPIOEN;
  684. chv_writel(pctrl, offset, CHV_PADCTRL0, value);
  685. }
  686. return 0;
  687. }
  688. static void chv_gpio_disable_free(struct pinctrl_dev *pctldev,
  689. struct pinctrl_gpio_range *range,
  690. unsigned int offset)
  691. {
  692. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  693. guard(raw_spinlock_irqsave)(&chv_lock);
  694. if (chv_pad_locked(pctrl, offset))
  695. return;
  696. chv_gpio_clear_triggering(pctrl, offset);
  697. }
  698. static int chv_gpio_set_direction(struct pinctrl_dev *pctldev,
  699. struct pinctrl_gpio_range *range,
  700. unsigned int offset, bool input)
  701. {
  702. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  703. u32 ctrl0;
  704. guard(raw_spinlock_irqsave)(&chv_lock);
  705. ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0) & ~CHV_PADCTRL0_GPIOCFG_MASK;
  706. if (input)
  707. ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT;
  708. else
  709. ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPO << CHV_PADCTRL0_GPIOCFG_SHIFT;
  710. chv_writel(pctrl, offset, CHV_PADCTRL0, ctrl0);
  711. return 0;
  712. }
  713. static const struct pinmux_ops chv_pinmux_ops = {
  714. .get_functions_count = intel_get_functions_count,
  715. .get_function_name = intel_get_function_name,
  716. .get_function_groups = intel_get_function_groups,
  717. .set_mux = chv_pinmux_set_mux,
  718. .gpio_request_enable = chv_gpio_request_enable,
  719. .gpio_disable_free = chv_gpio_disable_free,
  720. .gpio_set_direction = chv_gpio_set_direction,
  721. };
  722. static int chv_config_get(struct pinctrl_dev *pctldev, unsigned int pin,
  723. unsigned long *config)
  724. {
  725. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  726. enum pin_config_param param = pinconf_to_config_param(*config);
  727. u32 ctrl0, ctrl1;
  728. u16 arg = 0;
  729. u32 term;
  730. scoped_guard(raw_spinlock_irqsave, &chv_lock) {
  731. ctrl0 = chv_readl(pctrl, pin, CHV_PADCTRL0);
  732. ctrl1 = chv_readl(pctrl, pin, CHV_PADCTRL1);
  733. }
  734. term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT;
  735. switch (param) {
  736. case PIN_CONFIG_BIAS_DISABLE:
  737. if (term)
  738. return -EINVAL;
  739. break;
  740. case PIN_CONFIG_BIAS_PULL_UP:
  741. if (!(ctrl0 & CHV_PADCTRL0_TERM_UP))
  742. return -EINVAL;
  743. switch (term) {
  744. case CHV_PADCTRL0_TERM_20K:
  745. arg = 20000;
  746. break;
  747. case CHV_PADCTRL0_TERM_5K:
  748. arg = 5000;
  749. break;
  750. case CHV_PADCTRL0_TERM_1K:
  751. arg = 1000;
  752. break;
  753. }
  754. break;
  755. case PIN_CONFIG_BIAS_PULL_DOWN:
  756. if (!term || (ctrl0 & CHV_PADCTRL0_TERM_UP))
  757. return -EINVAL;
  758. switch (term) {
  759. case CHV_PADCTRL0_TERM_20K:
  760. arg = 20000;
  761. break;
  762. case CHV_PADCTRL0_TERM_5K:
  763. arg = 5000;
  764. break;
  765. }
  766. break;
  767. case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: {
  768. u32 cfg;
  769. cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
  770. cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
  771. if (cfg != CHV_PADCTRL0_GPIOCFG_HIZ)
  772. return -EINVAL;
  773. break;
  774. }
  775. case PIN_CONFIG_DRIVE_PUSH_PULL:
  776. if (ctrl1 & CHV_PADCTRL1_ODEN)
  777. return -EINVAL;
  778. break;
  779. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  780. if (!(ctrl1 & CHV_PADCTRL1_ODEN))
  781. return -EINVAL;
  782. break;
  783. default:
  784. return -ENOTSUPP;
  785. }
  786. *config = pinconf_to_config_packed(param, arg);
  787. return 0;
  788. }
  789. static int chv_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
  790. enum pin_config_param param, u32 arg)
  791. {
  792. u32 ctrl0, pull;
  793. guard(raw_spinlock_irqsave)(&chv_lock);
  794. ctrl0 = chv_readl(pctrl, pin, CHV_PADCTRL0);
  795. switch (param) {
  796. case PIN_CONFIG_BIAS_DISABLE:
  797. ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
  798. break;
  799. case PIN_CONFIG_BIAS_PULL_UP:
  800. ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
  801. switch (arg) {
  802. case 1000:
  803. /* For 1k there is only pull up */
  804. pull = CHV_PADCTRL0_TERM_1K << CHV_PADCTRL0_TERM_SHIFT;
  805. break;
  806. case 5000:
  807. pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT;
  808. break;
  809. case 20000:
  810. pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT;
  811. break;
  812. default:
  813. return -EINVAL;
  814. }
  815. ctrl0 |= CHV_PADCTRL0_TERM_UP | pull;
  816. break;
  817. case PIN_CONFIG_BIAS_PULL_DOWN:
  818. ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
  819. switch (arg) {
  820. case 5000:
  821. pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT;
  822. break;
  823. case 20000:
  824. pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT;
  825. break;
  826. default:
  827. return -EINVAL;
  828. }
  829. ctrl0 |= pull;
  830. break;
  831. default:
  832. return -EINVAL;
  833. }
  834. chv_writel(pctrl, pin, CHV_PADCTRL0, ctrl0);
  835. return 0;
  836. }
  837. static int chv_config_set_oden(struct intel_pinctrl *pctrl, unsigned int pin,
  838. bool enable)
  839. {
  840. u32 ctrl1;
  841. guard(raw_spinlock_irqsave)(&chv_lock);
  842. ctrl1 = chv_readl(pctrl, pin, CHV_PADCTRL1);
  843. if (enable)
  844. ctrl1 |= CHV_PADCTRL1_ODEN;
  845. else
  846. ctrl1 &= ~CHV_PADCTRL1_ODEN;
  847. chv_writel(pctrl, pin, CHV_PADCTRL1, ctrl1);
  848. return 0;
  849. }
  850. static int chv_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
  851. unsigned long *configs, unsigned int nconfigs)
  852. {
  853. struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
  854. struct device *dev = pctrl->dev;
  855. enum pin_config_param param;
  856. int i, ret;
  857. u32 arg;
  858. if (chv_pad_locked(pctrl, pin))
  859. return -EBUSY;
  860. for (i = 0; i < nconfigs; i++) {
  861. param = pinconf_to_config_param(configs[i]);
  862. arg = pinconf_to_config_argument(configs[i]);
  863. switch (param) {
  864. case PIN_CONFIG_BIAS_DISABLE:
  865. case PIN_CONFIG_BIAS_PULL_UP:
  866. case PIN_CONFIG_BIAS_PULL_DOWN:
  867. ret = chv_config_set_pull(pctrl, pin, param, arg);
  868. if (ret)
  869. return ret;
  870. break;
  871. case PIN_CONFIG_DRIVE_PUSH_PULL:
  872. ret = chv_config_set_oden(pctrl, pin, false);
  873. if (ret)
  874. return ret;
  875. break;
  876. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  877. ret = chv_config_set_oden(pctrl, pin, true);
  878. if (ret)
  879. return ret;
  880. break;
  881. default:
  882. return -ENOTSUPP;
  883. }
  884. dev_dbg(dev, "pin %d set config %d arg %u\n", pin, param, arg);
  885. }
  886. return 0;
  887. }
  888. static int chv_config_group_get(struct pinctrl_dev *pctldev,
  889. unsigned int group,
  890. unsigned long *config)
  891. {
  892. const unsigned int *pins;
  893. unsigned int npins;
  894. int ret;
  895. ret = intel_get_group_pins(pctldev, group, &pins, &npins);
  896. if (ret)
  897. return ret;
  898. ret = chv_config_get(pctldev, pins[0], config);
  899. if (ret)
  900. return ret;
  901. return 0;
  902. }
  903. static int chv_config_group_set(struct pinctrl_dev *pctldev,
  904. unsigned int group, unsigned long *configs,
  905. unsigned int num_configs)
  906. {
  907. const unsigned int *pins;
  908. unsigned int npins;
  909. int i, ret;
  910. ret = intel_get_group_pins(pctldev, group, &pins, &npins);
  911. if (ret)
  912. return ret;
  913. for (i = 0; i < npins; i++) {
  914. ret = chv_config_set(pctldev, pins[i], configs, num_configs);
  915. if (ret)
  916. return ret;
  917. }
  918. return 0;
  919. }
  920. static const struct pinconf_ops chv_pinconf_ops = {
  921. .is_generic = true,
  922. .pin_config_set = chv_config_set,
  923. .pin_config_get = chv_config_get,
  924. .pin_config_group_get = chv_config_group_get,
  925. .pin_config_group_set = chv_config_group_set,
  926. };
  927. static struct pinctrl_desc chv_pinctrl_desc = {
  928. .pctlops = &chv_pinctrl_ops,
  929. .pmxops = &chv_pinmux_ops,
  930. .confops = &chv_pinconf_ops,
  931. .owner = THIS_MODULE,
  932. };
  933. static int chv_gpio_get(struct gpio_chip *chip, unsigned int offset)
  934. {
  935. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  936. u32 ctrl0, cfg;
  937. scoped_guard(raw_spinlock_irqsave, &chv_lock)
  938. ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0);
  939. cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
  940. cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
  941. if (cfg == CHV_PADCTRL0_GPIOCFG_GPO)
  942. return !!(ctrl0 & CHV_PADCTRL0_GPIOTXSTATE);
  943. return !!(ctrl0 & CHV_PADCTRL0_GPIORXSTATE);
  944. }
  945. static void chv_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
  946. {
  947. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  948. u32 ctrl0;
  949. guard(raw_spinlock_irqsave)(&chv_lock);
  950. ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0);
  951. if (value)
  952. ctrl0 |= CHV_PADCTRL0_GPIOTXSTATE;
  953. else
  954. ctrl0 &= ~CHV_PADCTRL0_GPIOTXSTATE;
  955. chv_writel(pctrl, offset, CHV_PADCTRL0, ctrl0);
  956. }
  957. static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
  958. {
  959. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  960. u32 ctrl0, direction;
  961. scoped_guard(raw_spinlock_irqsave, &chv_lock)
  962. ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0);
  963. direction = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
  964. direction >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
  965. if (direction == CHV_PADCTRL0_GPIOCFG_GPO)
  966. return GPIO_LINE_DIRECTION_OUT;
  967. return GPIO_LINE_DIRECTION_IN;
  968. }
  969. static int chv_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
  970. {
  971. return pinctrl_gpio_direction_input(chip, offset);
  972. }
  973. static int chv_gpio_direction_output(struct gpio_chip *chip, unsigned int offset,
  974. int value)
  975. {
  976. chv_gpio_set(chip, offset, value);
  977. return pinctrl_gpio_direction_output(chip, offset);
  978. }
  979. static const struct gpio_chip chv_gpio_chip = {
  980. .owner = THIS_MODULE,
  981. .request = gpiochip_generic_request,
  982. .free = gpiochip_generic_free,
  983. .get_direction = chv_gpio_get_direction,
  984. .direction_input = chv_gpio_direction_input,
  985. .direction_output = chv_gpio_direction_output,
  986. .get = chv_gpio_get,
  987. .set = chv_gpio_set,
  988. };
  989. static void chv_gpio_irq_ack(struct irq_data *d)
  990. {
  991. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  992. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  993. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  994. u32 intr_line;
  995. guard(raw_spinlock)(&chv_lock);
  996. intr_line = chv_readl(pctrl, hwirq, CHV_PADCTRL0);
  997. intr_line &= CHV_PADCTRL0_INTSEL_MASK;
  998. intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT;
  999. chv_pctrl_writel(pctrl, CHV_INTSTAT, BIT(intr_line));
  1000. }
  1001. static void chv_gpio_irq_mask_unmask(struct gpio_chip *gc, irq_hw_number_t hwirq, bool mask)
  1002. {
  1003. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  1004. u32 value, intr_line;
  1005. guard(raw_spinlock_irqsave)(&chv_lock);
  1006. intr_line = chv_readl(pctrl, hwirq, CHV_PADCTRL0);
  1007. intr_line &= CHV_PADCTRL0_INTSEL_MASK;
  1008. intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT;
  1009. value = chv_pctrl_readl(pctrl, CHV_INTMASK);
  1010. if (mask)
  1011. value &= ~BIT(intr_line);
  1012. else
  1013. value |= BIT(intr_line);
  1014. chv_pctrl_writel(pctrl, CHV_INTMASK, value);
  1015. }
  1016. static void chv_gpio_irq_mask(struct irq_data *d)
  1017. {
  1018. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  1019. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  1020. chv_gpio_irq_mask_unmask(gc, hwirq, true);
  1021. gpiochip_disable_irq(gc, hwirq);
  1022. }
  1023. static void chv_gpio_irq_unmask(struct irq_data *d)
  1024. {
  1025. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  1026. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  1027. gpiochip_enable_irq(gc, hwirq);
  1028. chv_gpio_irq_mask_unmask(gc, hwirq, false);
  1029. }
  1030. static unsigned chv_gpio_irq_startup(struct irq_data *d)
  1031. {
  1032. /*
  1033. * Check if the interrupt has been requested with 0 as triggering
  1034. * type. If not, bail out, ...
  1035. */
  1036. if (irqd_get_trigger_type(d) != IRQ_TYPE_NONE) {
  1037. chv_gpio_irq_unmask(d);
  1038. return 0;
  1039. }
  1040. /*
  1041. * ...otherwise it is assumed that the current values
  1042. * programmed to the hardware are used (e.g BIOS configured
  1043. * defaults).
  1044. *
  1045. * In that case ->irq_set_type() will never be called so we need to
  1046. * read back the values from hardware now, set correct flow handler
  1047. * and update mappings before the interrupt is being used.
  1048. */
  1049. scoped_guard(raw_spinlock_irqsave, &chv_lock) {
  1050. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  1051. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  1052. struct device *dev = pctrl->dev;
  1053. struct intel_community_context *cctx = &pctrl->context.communities[0];
  1054. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  1055. irq_flow_handler_t handler;
  1056. u32 intsel, value;
  1057. intsel = chv_readl(pctrl, hwirq, CHV_PADCTRL0);
  1058. intsel &= CHV_PADCTRL0_INTSEL_MASK;
  1059. intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
  1060. value = chv_readl(pctrl, hwirq, CHV_PADCTRL1);
  1061. if (value & CHV_PADCTRL1_INTWAKECFG_LEVEL)
  1062. handler = handle_level_irq;
  1063. else
  1064. handler = handle_edge_irq;
  1065. if (cctx->intr_lines[intsel] == CHV_INVALID_HWIRQ) {
  1066. irq_set_handler_locked(d, handler);
  1067. dev_dbg(dev, "using interrupt line %u for IRQ_TYPE_NONE on pin %lu\n",
  1068. intsel, hwirq);
  1069. cctx->intr_lines[intsel] = hwirq;
  1070. }
  1071. }
  1072. chv_gpio_irq_unmask(d);
  1073. return 0;
  1074. }
  1075. static int chv_gpio_set_intr_line(struct intel_pinctrl *pctrl, unsigned int pin)
  1076. {
  1077. struct device *dev = pctrl->dev;
  1078. struct intel_community_context *cctx = &pctrl->context.communities[0];
  1079. const struct intel_community *community = &pctrl->communities[0];
  1080. u32 value, intsel;
  1081. int i;
  1082. value = chv_readl(pctrl, pin, CHV_PADCTRL0);
  1083. intsel = (value & CHV_PADCTRL0_INTSEL_MASK) >> CHV_PADCTRL0_INTSEL_SHIFT;
  1084. if (cctx->intr_lines[intsel] == pin)
  1085. return 0;
  1086. if (cctx->intr_lines[intsel] == CHV_INVALID_HWIRQ) {
  1087. dev_dbg(dev, "using interrupt line %u for pin %u\n", intsel, pin);
  1088. cctx->intr_lines[intsel] = pin;
  1089. return 0;
  1090. }
  1091. /*
  1092. * The interrupt line selected by the BIOS is already in use by
  1093. * another pin, this is a known BIOS bug found on several models.
  1094. * But this may also be caused by Linux deciding to use a pin as
  1095. * IRQ which was not expected to be used as such by the BIOS authors,
  1096. * so log this at info level only.
  1097. */
  1098. dev_info(dev, "interrupt line %u is used by both pin %u and pin %u\n", intsel,
  1099. cctx->intr_lines[intsel], pin);
  1100. if (chv_pad_locked(pctrl, pin))
  1101. return -EBUSY;
  1102. /*
  1103. * The BIOS fills the interrupt lines from 0 counting up, start at
  1104. * the other end to find a free interrupt line to workaround this.
  1105. */
  1106. for (i = community->nirqs - 1; i >= 0; i--) {
  1107. if (cctx->intr_lines[i] == CHV_INVALID_HWIRQ)
  1108. break;
  1109. }
  1110. if (i < 0)
  1111. return -EBUSY;
  1112. dev_info(dev, "changing the interrupt line for pin %u to %d\n", pin, i);
  1113. value = (value & ~CHV_PADCTRL0_INTSEL_MASK) | (i << CHV_PADCTRL0_INTSEL_SHIFT);
  1114. chv_writel(pctrl, pin, CHV_PADCTRL0, value);
  1115. cctx->intr_lines[i] = pin;
  1116. return 0;
  1117. }
  1118. static int chv_gpio_irq_type(struct irq_data *d, unsigned int type)
  1119. {
  1120. struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  1121. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  1122. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  1123. u32 value;
  1124. int ret;
  1125. guard(raw_spinlock_irqsave)(&chv_lock);
  1126. ret = chv_gpio_set_intr_line(pctrl, hwirq);
  1127. if (ret)
  1128. return ret;
  1129. /*
  1130. * Pins which can be used as shared interrupt are configured in
  1131. * BIOS. Driver trusts BIOS configurations and assigns different
  1132. * handler according to the irq type.
  1133. *
  1134. * Driver needs to save the mapping between each pin and
  1135. * its interrupt line.
  1136. * 1. If the pin cfg is locked in BIOS:
  1137. * Trust BIOS has programmed IntWakeCfg bits correctly,
  1138. * driver just needs to save the mapping.
  1139. * 2. If the pin cfg is not locked in BIOS:
  1140. * Driver programs the IntWakeCfg bits and save the mapping.
  1141. */
  1142. if (!chv_pad_locked(pctrl, hwirq)) {
  1143. value = chv_readl(pctrl, hwirq, CHV_PADCTRL1);
  1144. value &= ~CHV_PADCTRL1_INTWAKECFG_MASK;
  1145. value &= ~CHV_PADCTRL1_INVRXTX_MASK;
  1146. if (type & IRQ_TYPE_EDGE_BOTH) {
  1147. if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
  1148. value |= CHV_PADCTRL1_INTWAKECFG_BOTH;
  1149. else if (type & IRQ_TYPE_EDGE_RISING)
  1150. value |= CHV_PADCTRL1_INTWAKECFG_RISING;
  1151. else if (type & IRQ_TYPE_EDGE_FALLING)
  1152. value |= CHV_PADCTRL1_INTWAKECFG_FALLING;
  1153. } else if (type & IRQ_TYPE_LEVEL_MASK) {
  1154. value |= CHV_PADCTRL1_INTWAKECFG_LEVEL;
  1155. if (type & IRQ_TYPE_LEVEL_LOW)
  1156. value |= CHV_PADCTRL1_INVRXTX_RXDATA;
  1157. }
  1158. chv_writel(pctrl, hwirq, CHV_PADCTRL1, value);
  1159. }
  1160. if (type & IRQ_TYPE_EDGE_BOTH)
  1161. irq_set_handler_locked(d, handle_edge_irq);
  1162. else if (type & IRQ_TYPE_LEVEL_MASK)
  1163. irq_set_handler_locked(d, handle_level_irq);
  1164. return 0;
  1165. }
  1166. static const struct irq_chip chv_gpio_irq_chip = {
  1167. .name = "chv-gpio",
  1168. .irq_startup = chv_gpio_irq_startup,
  1169. .irq_ack = chv_gpio_irq_ack,
  1170. .irq_mask = chv_gpio_irq_mask,
  1171. .irq_unmask = chv_gpio_irq_unmask,
  1172. .irq_set_type = chv_gpio_irq_type,
  1173. .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_IMMUTABLE,
  1174. GPIOCHIP_IRQ_RESOURCE_HELPERS,
  1175. };
  1176. static void chv_gpio_irq_handler(struct irq_desc *desc)
  1177. {
  1178. struct gpio_chip *gc = irq_desc_get_handler_data(desc);
  1179. struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
  1180. struct device *dev = pctrl->dev;
  1181. const struct intel_community *community = &pctrl->communities[0];
  1182. struct intel_community_context *cctx = &pctrl->context.communities[0];
  1183. struct irq_chip *chip = irq_desc_get_chip(desc);
  1184. unsigned long pending;
  1185. u32 intr_line;
  1186. chained_irq_enter(chip, desc);
  1187. scoped_guard(raw_spinlock_irqsave, &chv_lock)
  1188. pending = chv_pctrl_readl(pctrl, CHV_INTSTAT);
  1189. for_each_set_bit(intr_line, &pending, community->nirqs) {
  1190. unsigned int offset;
  1191. offset = cctx->intr_lines[intr_line];
  1192. if (offset == CHV_INVALID_HWIRQ) {
  1193. dev_warn_once(dev, "interrupt on unmapped interrupt line %u\n", intr_line);
  1194. /* Some boards expect hwirq 0 to trigger in this case */
  1195. offset = 0;
  1196. }
  1197. generic_handle_domain_irq(gc->irq.domain, offset);
  1198. }
  1199. chained_irq_exit(chip, desc);
  1200. }
  1201. /*
  1202. * Certain machines seem to hardcode Linux IRQ numbers in their ACPI
  1203. * tables. Since we leave GPIOs that are not capable of generating
  1204. * interrupts out of the irqdomain the numbering will be different and
  1205. * cause devices using the hardcoded IRQ numbers fail. In order not to
  1206. * break such machines we will only mask pins from irqdomain if the machine
  1207. * is not listed below.
  1208. */
  1209. static const struct dmi_system_id chv_no_valid_mask[] = {
  1210. /* See https://bugzilla.kernel.org/show_bug.cgi?id=194945 */
  1211. {
  1212. .ident = "Intel_Strago based Chromebooks (All models)",
  1213. .matches = {
  1214. DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
  1215. DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_Strago"),
  1216. },
  1217. },
  1218. {
  1219. .ident = "HP Chromebook 11 G5 (Setzer)",
  1220. .matches = {
  1221. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  1222. DMI_MATCH(DMI_PRODUCT_NAME, "Setzer"),
  1223. },
  1224. },
  1225. {
  1226. .ident = "Acer Chromebook R11 (Cyan)",
  1227. .matches = {
  1228. DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
  1229. DMI_MATCH(DMI_PRODUCT_NAME, "Cyan"),
  1230. },
  1231. },
  1232. {
  1233. .ident = "Samsung Chromebook 3 (Celes)",
  1234. .matches = {
  1235. DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
  1236. DMI_MATCH(DMI_PRODUCT_NAME, "Celes"),
  1237. },
  1238. },
  1239. {}
  1240. };
  1241. static void chv_init_irq_valid_mask(struct gpio_chip *chip,
  1242. unsigned long *valid_mask,
  1243. unsigned int ngpios)
  1244. {
  1245. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  1246. const struct intel_community *community = &pctrl->communities[0];
  1247. int i;
  1248. /* Do not add GPIOs that can only generate GPEs to the IRQ domain */
  1249. for (i = 0; i < pctrl->soc->npins; i++) {
  1250. const struct pinctrl_pin_desc *desc;
  1251. u32 intsel;
  1252. desc = &pctrl->soc->pins[i];
  1253. intsel = chv_readl(pctrl, desc->number, CHV_PADCTRL0);
  1254. intsel &= CHV_PADCTRL0_INTSEL_MASK;
  1255. intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
  1256. if (intsel >= community->nirqs)
  1257. clear_bit(desc->number, valid_mask);
  1258. }
  1259. }
  1260. static int chv_gpio_irq_init_hw(struct gpio_chip *chip)
  1261. {
  1262. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  1263. const struct intel_community *community = &pctrl->communities[0];
  1264. /*
  1265. * The same set of machines in chv_no_valid_mask[] have incorrectly
  1266. * configured GPIOs that generate spurious interrupts so we use
  1267. * this same list to apply another quirk for them.
  1268. *
  1269. * See also https://bugzilla.kernel.org/show_bug.cgi?id=197953.
  1270. */
  1271. if (!pctrl->chip.irq.init_valid_mask) {
  1272. /*
  1273. * Mask all interrupts the community is able to generate
  1274. * but leave the ones that can only generate GPEs unmasked.
  1275. */
  1276. chv_pctrl_writel(pctrl, CHV_INTMASK, GENMASK(31, community->nirqs));
  1277. }
  1278. /* Clear all interrupts */
  1279. chv_pctrl_writel(pctrl, CHV_INTSTAT, 0xffff);
  1280. return 0;
  1281. }
  1282. static int chv_gpio_add_pin_ranges(struct gpio_chip *chip)
  1283. {
  1284. struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
  1285. struct device *dev = pctrl->dev;
  1286. const struct intel_community *community = &pctrl->communities[0];
  1287. const struct intel_padgroup *gpp;
  1288. int ret, i;
  1289. for (i = 0; i < community->ngpps; i++) {
  1290. gpp = &community->gpps[i];
  1291. ret = gpiochip_add_pin_range(chip, dev_name(dev), gpp->base, gpp->base, gpp->size);
  1292. if (ret) {
  1293. dev_err(dev, "failed to add GPIO pin range\n");
  1294. return ret;
  1295. }
  1296. }
  1297. return 0;
  1298. }
  1299. static int chv_gpio_probe(struct intel_pinctrl *pctrl, int irq)
  1300. {
  1301. const struct intel_community *community = &pctrl->communities[0];
  1302. const struct intel_padgroup *gpp;
  1303. struct gpio_chip *chip = &pctrl->chip;
  1304. struct device *dev = pctrl->dev;
  1305. bool need_valid_mask = !dmi_check_system(chv_no_valid_mask);
  1306. int ret, i, irq_base;
  1307. *chip = chv_gpio_chip;
  1308. chip->ngpio = pctrl->soc->pins[pctrl->soc->npins - 1].number + 1;
  1309. chip->label = dev_name(dev);
  1310. chip->add_pin_ranges = chv_gpio_add_pin_ranges;
  1311. chip->parent = dev;
  1312. chip->base = -1;
  1313. pctrl->irq = irq;
  1314. gpio_irq_chip_set_chip(&chip->irq, &chv_gpio_irq_chip);
  1315. chip->irq.init_hw = chv_gpio_irq_init_hw;
  1316. chip->irq.parent_handler = chv_gpio_irq_handler;
  1317. chip->irq.num_parents = 1;
  1318. chip->irq.parents = &pctrl->irq;
  1319. chip->irq.default_type = IRQ_TYPE_NONE;
  1320. chip->irq.handler = handle_bad_irq;
  1321. if (need_valid_mask) {
  1322. chip->irq.init_valid_mask = chv_init_irq_valid_mask;
  1323. } else {
  1324. irq_base = devm_irq_alloc_descs(dev, -1, 0, pctrl->soc->npins, NUMA_NO_NODE);
  1325. if (irq_base < 0) {
  1326. dev_err(dev, "Failed to allocate IRQ numbers\n");
  1327. return irq_base;
  1328. }
  1329. }
  1330. ret = devm_gpiochip_add_data(dev, chip, pctrl);
  1331. if (ret) {
  1332. dev_err(dev, "Failed to register gpiochip\n");
  1333. return ret;
  1334. }
  1335. if (!need_valid_mask) {
  1336. for (i = 0; i < community->ngpps; i++) {
  1337. gpp = &community->gpps[i];
  1338. irq_domain_associate_many(chip->irq.domain, irq_base,
  1339. gpp->base, gpp->size);
  1340. irq_base += gpp->size;
  1341. }
  1342. }
  1343. return 0;
  1344. }
  1345. static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
  1346. acpi_physical_address address, u32 bits, u64 *value,
  1347. void *handler_context, void *region_context)
  1348. {
  1349. struct intel_pinctrl *pctrl = region_context;
  1350. guard(raw_spinlock_irqsave)(&chv_lock);
  1351. if (function == ACPI_WRITE)
  1352. chv_pctrl_writel(pctrl, address, *value);
  1353. else if (function == ACPI_READ)
  1354. *value = chv_pctrl_readl(pctrl, address);
  1355. else
  1356. return AE_BAD_PARAMETER;
  1357. return AE_OK;
  1358. }
  1359. static int chv_pinctrl_probe(struct platform_device *pdev)
  1360. {
  1361. const struct intel_pinctrl_soc_data *soc_data;
  1362. struct intel_community_context *cctx;
  1363. struct intel_community *community;
  1364. struct device *dev = &pdev->dev;
  1365. struct intel_pinctrl *pctrl;
  1366. acpi_status status;
  1367. unsigned int i;
  1368. int ret, irq;
  1369. soc_data = intel_pinctrl_get_soc_data(pdev);
  1370. if (IS_ERR(soc_data))
  1371. return PTR_ERR(soc_data);
  1372. pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL);
  1373. if (!pctrl)
  1374. return -ENOMEM;
  1375. pctrl->dev = dev;
  1376. pctrl->soc = soc_data;
  1377. pctrl->ncommunities = pctrl->soc->ncommunities;
  1378. pctrl->communities = devm_kmemdup(dev, pctrl->soc->communities,
  1379. pctrl->ncommunities * sizeof(*pctrl->communities),
  1380. GFP_KERNEL);
  1381. if (!pctrl->communities)
  1382. return -ENOMEM;
  1383. community = &pctrl->communities[0];
  1384. community->regs = devm_platform_ioremap_resource(pdev, 0);
  1385. if (IS_ERR(community->regs))
  1386. return PTR_ERR(community->regs);
  1387. community->pad_regs = community->regs + FAMILY_PAD_REGS_OFF;
  1388. #ifdef CONFIG_PM_SLEEP
  1389. pctrl->context.pads = devm_kcalloc(dev, pctrl->soc->npins,
  1390. sizeof(*pctrl->context.pads),
  1391. GFP_KERNEL);
  1392. if (!pctrl->context.pads)
  1393. return -ENOMEM;
  1394. #endif
  1395. pctrl->context.communities = devm_kcalloc(dev, pctrl->soc->ncommunities,
  1396. sizeof(*pctrl->context.communities),
  1397. GFP_KERNEL);
  1398. if (!pctrl->context.communities)
  1399. return -ENOMEM;
  1400. cctx = &pctrl->context.communities[0];
  1401. for (i = 0; i < ARRAY_SIZE(cctx->intr_lines); i++)
  1402. cctx->intr_lines[i] = CHV_INVALID_HWIRQ;
  1403. irq = platform_get_irq(pdev, 0);
  1404. if (irq < 0)
  1405. return irq;
  1406. pctrl->pctldesc = chv_pinctrl_desc;
  1407. pctrl->pctldesc.name = dev_name(dev);
  1408. pctrl->pctldesc.pins = pctrl->soc->pins;
  1409. pctrl->pctldesc.npins = pctrl->soc->npins;
  1410. pctrl->pctldev = devm_pinctrl_register(dev, &pctrl->pctldesc, pctrl);
  1411. if (IS_ERR(pctrl->pctldev)) {
  1412. dev_err(dev, "failed to register pinctrl driver\n");
  1413. return PTR_ERR(pctrl->pctldev);
  1414. }
  1415. ret = chv_gpio_probe(pctrl, irq);
  1416. if (ret)
  1417. return ret;
  1418. status = acpi_install_address_space_handler(ACPI_HANDLE(dev),
  1419. community->acpi_space_id,
  1420. chv_pinctrl_mmio_access_handler,
  1421. NULL, pctrl);
  1422. if (ACPI_FAILURE(status))
  1423. dev_err(dev, "failed to install ACPI addr space handler\n");
  1424. platform_set_drvdata(pdev, pctrl);
  1425. return 0;
  1426. }
  1427. static void chv_pinctrl_remove(struct platform_device *pdev)
  1428. {
  1429. struct intel_pinctrl *pctrl = platform_get_drvdata(pdev);
  1430. const struct intel_community *community = &pctrl->communities[0];
  1431. acpi_remove_address_space_handler(ACPI_HANDLE(&pdev->dev),
  1432. community->acpi_space_id,
  1433. chv_pinctrl_mmio_access_handler);
  1434. }
  1435. static int chv_pinctrl_suspend_noirq(struct device *dev)
  1436. {
  1437. struct intel_pinctrl *pctrl = dev_get_drvdata(dev);
  1438. struct intel_community_context *cctx = &pctrl->context.communities[0];
  1439. int i;
  1440. guard(raw_spinlock_irqsave)(&chv_lock);
  1441. cctx->saved_intmask = chv_pctrl_readl(pctrl, CHV_INTMASK);
  1442. for (i = 0; i < pctrl->soc->npins; i++) {
  1443. const struct pinctrl_pin_desc *desc;
  1444. struct intel_pad_context *ctx = &pctrl->context.pads[i];
  1445. desc = &pctrl->soc->pins[i];
  1446. if (chv_pad_locked(pctrl, desc->number))
  1447. continue;
  1448. ctx->padctrl0 = chv_readl(pctrl, desc->number, CHV_PADCTRL0);
  1449. ctx->padctrl0 &= ~CHV_PADCTRL0_GPIORXSTATE;
  1450. ctx->padctrl1 = chv_readl(pctrl, desc->number, CHV_PADCTRL1);
  1451. }
  1452. return 0;
  1453. }
  1454. static int chv_pinctrl_resume_noirq(struct device *dev)
  1455. {
  1456. struct intel_pinctrl *pctrl = dev_get_drvdata(dev);
  1457. struct intel_community_context *cctx = &pctrl->context.communities[0];
  1458. int i;
  1459. guard(raw_spinlock_irqsave)(&chv_lock);
  1460. /*
  1461. * Mask all interrupts before restoring per-pin configuration
  1462. * registers because we don't know in which state BIOS left them
  1463. * upon exiting suspend.
  1464. */
  1465. chv_pctrl_writel(pctrl, CHV_INTMASK, 0x0000);
  1466. for (i = 0; i < pctrl->soc->npins; i++) {
  1467. const struct pinctrl_pin_desc *desc;
  1468. struct intel_pad_context *ctx = &pctrl->context.pads[i];
  1469. u32 val;
  1470. desc = &pctrl->soc->pins[i];
  1471. if (chv_pad_locked(pctrl, desc->number))
  1472. continue;
  1473. /* Only restore if our saved state differs from the current */
  1474. val = chv_readl(pctrl, desc->number, CHV_PADCTRL0);
  1475. val &= ~CHV_PADCTRL0_GPIORXSTATE;
  1476. if (ctx->padctrl0 != val) {
  1477. chv_writel(pctrl, desc->number, CHV_PADCTRL0, ctx->padctrl0);
  1478. dev_dbg(dev, "restored pin %2u ctrl0 0x%08x\n", desc->number,
  1479. chv_readl(pctrl, desc->number, CHV_PADCTRL0));
  1480. }
  1481. val = chv_readl(pctrl, desc->number, CHV_PADCTRL1);
  1482. if (ctx->padctrl1 != val) {
  1483. chv_writel(pctrl, desc->number, CHV_PADCTRL1, ctx->padctrl1);
  1484. dev_dbg(dev, "restored pin %2u ctrl1 0x%08x\n", desc->number,
  1485. chv_readl(pctrl, desc->number, CHV_PADCTRL1));
  1486. }
  1487. }
  1488. /*
  1489. * Now that all pins are restored to known state, we can restore
  1490. * the interrupt mask register as well.
  1491. */
  1492. chv_pctrl_writel(pctrl, CHV_INTSTAT, 0xffff);
  1493. chv_pctrl_writel(pctrl, CHV_INTMASK, cctx->saved_intmask);
  1494. return 0;
  1495. }
  1496. static DEFINE_NOIRQ_DEV_PM_OPS(chv_pinctrl_pm_ops,
  1497. chv_pinctrl_suspend_noirq, chv_pinctrl_resume_noirq);
  1498. static const struct acpi_device_id chv_pinctrl_acpi_match[] = {
  1499. { "INT33FF", (kernel_ulong_t)chv_soc_data },
  1500. { }
  1501. };
  1502. MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match);
  1503. static struct platform_driver chv_pinctrl_driver = {
  1504. .probe = chv_pinctrl_probe,
  1505. .remove_new = chv_pinctrl_remove,
  1506. .driver = {
  1507. .name = "cherryview-pinctrl",
  1508. .pm = pm_sleep_ptr(&chv_pinctrl_pm_ops),
  1509. .acpi_match_table = chv_pinctrl_acpi_match,
  1510. },
  1511. };
  1512. static int __init chv_pinctrl_init(void)
  1513. {
  1514. return platform_driver_register(&chv_pinctrl_driver);
  1515. }
  1516. subsys_initcall(chv_pinctrl_init);
  1517. static void __exit chv_pinctrl_exit(void)
  1518. {
  1519. platform_driver_unregister(&chv_pinctrl_driver);
  1520. }
  1521. module_exit(chv_pinctrl_exit);
  1522. MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
  1523. MODULE_DESCRIPTION("Intel Cherryview/Braswell pinctrl driver");
  1524. MODULE_LICENSE("GPL v2");
  1525. MODULE_IMPORT_NS(PINCTRL_INTEL);