pinctrl-cherryview.c 54 KB

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