pinctrl-sirf.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  1. /*
  2. * pinmux driver for CSR SiRFprimaII
  3. *
  4. * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/module.h>
  10. #include <linux/irq.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/io.h>
  13. #include <linux/slab.h>
  14. #include <linux/err.h>
  15. #include <linux/irqdomain.h>
  16. #include <linux/pinctrl/pinctrl.h>
  17. #include <linux/pinctrl/pinmux.h>
  18. #include <linux/pinctrl/consumer.h>
  19. #include <linux/pinctrl/machine.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_device.h>
  23. #include <linux/of_platform.h>
  24. #include <linux/bitops.h>
  25. #include <linux/gpio.h>
  26. #include <linux/of_gpio.h>
  27. #include <asm/mach/irq.h>
  28. #define DRIVER_NAME "pinmux-sirf"
  29. #define SIRFSOC_NUM_PADS 622
  30. #define SIRFSOC_RSC_PIN_MUX 0x4
  31. #define SIRFSOC_GPIO_PAD_EN(g) ((g)*0x100 + 0x84)
  32. #define SIRFSOC_GPIO_PAD_EN_CLR(g) ((g)*0x100 + 0x90)
  33. #define SIRFSOC_GPIO_CTRL(g, i) ((g)*0x100 + (i)*4)
  34. #define SIRFSOC_GPIO_DSP_EN0 (0x80)
  35. #define SIRFSOC_GPIO_INT_STATUS(g) ((g)*0x100 + 0x8C)
  36. #define SIRFSOC_GPIO_CTL_INTR_LOW_MASK 0x1
  37. #define SIRFSOC_GPIO_CTL_INTR_HIGH_MASK 0x2
  38. #define SIRFSOC_GPIO_CTL_INTR_TYPE_MASK 0x4
  39. #define SIRFSOC_GPIO_CTL_INTR_EN_MASK 0x8
  40. #define SIRFSOC_GPIO_CTL_INTR_STS_MASK 0x10
  41. #define SIRFSOC_GPIO_CTL_OUT_EN_MASK 0x20
  42. #define SIRFSOC_GPIO_CTL_DATAOUT_MASK 0x40
  43. #define SIRFSOC_GPIO_CTL_DATAIN_MASK 0x80
  44. #define SIRFSOC_GPIO_CTL_PULL_MASK 0x100
  45. #define SIRFSOC_GPIO_CTL_PULL_HIGH 0x200
  46. #define SIRFSOC_GPIO_CTL_DSP_INT 0x400
  47. #define SIRFSOC_GPIO_NO_OF_BANKS 5
  48. #define SIRFSOC_GPIO_BANK_SIZE 32
  49. #define SIRFSOC_GPIO_NUM(bank, index) (((bank)*(32)) + (index))
  50. struct sirfsoc_gpio_bank {
  51. struct of_mm_gpio_chip chip;
  52. struct irq_domain *domain;
  53. int id;
  54. int parent_irq;
  55. spinlock_t lock;
  56. bool is_marco; /* for marco, some registers are different with prima2 */
  57. };
  58. static struct sirfsoc_gpio_bank sgpio_bank[SIRFSOC_GPIO_NO_OF_BANKS];
  59. static DEFINE_SPINLOCK(sgpio_lock);
  60. /*
  61. * pad list for the pinmux subsystem
  62. * refer to CS-131858-DC-6A.xls
  63. */
  64. static const struct pinctrl_pin_desc sirfsoc_pads[] = {
  65. PINCTRL_PIN(0, "gpio0-0"),
  66. PINCTRL_PIN(1, "gpio0-1"),
  67. PINCTRL_PIN(2, "gpio0-2"),
  68. PINCTRL_PIN(3, "gpio0-3"),
  69. PINCTRL_PIN(4, "pwm0"),
  70. PINCTRL_PIN(5, "pwm1"),
  71. PINCTRL_PIN(6, "pwm2"),
  72. PINCTRL_PIN(7, "pwm3"),
  73. PINCTRL_PIN(8, "warm_rst_b"),
  74. PINCTRL_PIN(9, "odo_0"),
  75. PINCTRL_PIN(10, "odo_1"),
  76. PINCTRL_PIN(11, "dr_dir"),
  77. PINCTRL_PIN(12, "viprom_fa"),
  78. PINCTRL_PIN(13, "scl_1"),
  79. PINCTRL_PIN(14, "ntrst"),
  80. PINCTRL_PIN(15, "sda_1"),
  81. PINCTRL_PIN(16, "x_ldd[16]"),
  82. PINCTRL_PIN(17, "x_ldd[17]"),
  83. PINCTRL_PIN(18, "x_ldd[18]"),
  84. PINCTRL_PIN(19, "x_ldd[19]"),
  85. PINCTRL_PIN(20, "x_ldd[20]"),
  86. PINCTRL_PIN(21, "x_ldd[21]"),
  87. PINCTRL_PIN(22, "x_ldd[22]"),
  88. PINCTRL_PIN(23, "x_ldd[23], lcdrom_frdy"),
  89. PINCTRL_PIN(24, "gps_sgn"),
  90. PINCTRL_PIN(25, "gps_mag"),
  91. PINCTRL_PIN(26, "gps_clk"),
  92. PINCTRL_PIN(27, "sd_cd_b_1"),
  93. PINCTRL_PIN(28, "sd_vcc_on_1"),
  94. PINCTRL_PIN(29, "sd_wp_b_1"),
  95. PINCTRL_PIN(30, "sd_clk_3"),
  96. PINCTRL_PIN(31, "sd_cmd_3"),
  97. PINCTRL_PIN(32, "x_sd_dat_3[0]"),
  98. PINCTRL_PIN(33, "x_sd_dat_3[1]"),
  99. PINCTRL_PIN(34, "x_sd_dat_3[2]"),
  100. PINCTRL_PIN(35, "x_sd_dat_3[3]"),
  101. PINCTRL_PIN(36, "x_sd_clk_4"),
  102. PINCTRL_PIN(37, "x_sd_cmd_4"),
  103. PINCTRL_PIN(38, "x_sd_dat_4[0]"),
  104. PINCTRL_PIN(39, "x_sd_dat_4[1]"),
  105. PINCTRL_PIN(40, "x_sd_dat_4[2]"),
  106. PINCTRL_PIN(41, "x_sd_dat_4[3]"),
  107. PINCTRL_PIN(42, "x_cko_1"),
  108. PINCTRL_PIN(43, "x_ac97_bit_clk"),
  109. PINCTRL_PIN(44, "x_ac97_dout"),
  110. PINCTRL_PIN(45, "x_ac97_din"),
  111. PINCTRL_PIN(46, "x_ac97_sync"),
  112. PINCTRL_PIN(47, "x_txd_1"),
  113. PINCTRL_PIN(48, "x_txd_2"),
  114. PINCTRL_PIN(49, "x_rxd_1"),
  115. PINCTRL_PIN(50, "x_rxd_2"),
  116. PINCTRL_PIN(51, "x_usclk_0"),
  117. PINCTRL_PIN(52, "x_utxd_0"),
  118. PINCTRL_PIN(53, "x_urxd_0"),
  119. PINCTRL_PIN(54, "x_utfs_0"),
  120. PINCTRL_PIN(55, "x_urfs_0"),
  121. PINCTRL_PIN(56, "x_usclk_1"),
  122. PINCTRL_PIN(57, "x_utxd_1"),
  123. PINCTRL_PIN(58, "x_urxd_1"),
  124. PINCTRL_PIN(59, "x_utfs_1"),
  125. PINCTRL_PIN(60, "x_urfs_1"),
  126. PINCTRL_PIN(61, "x_usclk_2"),
  127. PINCTRL_PIN(62, "x_utxd_2"),
  128. PINCTRL_PIN(63, "x_urxd_2"),
  129. PINCTRL_PIN(64, "x_utfs_2"),
  130. PINCTRL_PIN(65, "x_urfs_2"),
  131. PINCTRL_PIN(66, "x_df_we_b"),
  132. PINCTRL_PIN(67, "x_df_re_b"),
  133. PINCTRL_PIN(68, "x_txd_0"),
  134. PINCTRL_PIN(69, "x_rxd_0"),
  135. PINCTRL_PIN(78, "x_cko_0"),
  136. PINCTRL_PIN(79, "x_vip_pxd[7]"),
  137. PINCTRL_PIN(80, "x_vip_pxd[6]"),
  138. PINCTRL_PIN(81, "x_vip_pxd[5]"),
  139. PINCTRL_PIN(82, "x_vip_pxd[4]"),
  140. PINCTRL_PIN(83, "x_vip_pxd[3]"),
  141. PINCTRL_PIN(84, "x_vip_pxd[2]"),
  142. PINCTRL_PIN(85, "x_vip_pxd[1]"),
  143. PINCTRL_PIN(86, "x_vip_pxd[0]"),
  144. PINCTRL_PIN(87, "x_vip_vsync"),
  145. PINCTRL_PIN(88, "x_vip_hsync"),
  146. PINCTRL_PIN(89, "x_vip_pxclk"),
  147. PINCTRL_PIN(90, "x_sda_0"),
  148. PINCTRL_PIN(91, "x_scl_0"),
  149. PINCTRL_PIN(92, "x_df_ry_by"),
  150. PINCTRL_PIN(93, "x_df_cs_b[1]"),
  151. PINCTRL_PIN(94, "x_df_cs_b[0]"),
  152. PINCTRL_PIN(95, "x_l_pclk"),
  153. PINCTRL_PIN(96, "x_l_lck"),
  154. PINCTRL_PIN(97, "x_l_fck"),
  155. PINCTRL_PIN(98, "x_l_de"),
  156. PINCTRL_PIN(99, "x_ldd[0]"),
  157. PINCTRL_PIN(100, "x_ldd[1]"),
  158. PINCTRL_PIN(101, "x_ldd[2]"),
  159. PINCTRL_PIN(102, "x_ldd[3]"),
  160. PINCTRL_PIN(103, "x_ldd[4]"),
  161. PINCTRL_PIN(104, "x_ldd[5]"),
  162. PINCTRL_PIN(105, "x_ldd[6]"),
  163. PINCTRL_PIN(106, "x_ldd[7]"),
  164. PINCTRL_PIN(107, "x_ldd[8]"),
  165. PINCTRL_PIN(108, "x_ldd[9]"),
  166. PINCTRL_PIN(109, "x_ldd[10]"),
  167. PINCTRL_PIN(110, "x_ldd[11]"),
  168. PINCTRL_PIN(111, "x_ldd[12]"),
  169. PINCTRL_PIN(112, "x_ldd[13]"),
  170. PINCTRL_PIN(113, "x_ldd[14]"),
  171. PINCTRL_PIN(114, "x_ldd[15]"),
  172. };
  173. /**
  174. * @dev: a pointer back to containing device
  175. * @virtbase: the offset to the controller in virtual memory
  176. */
  177. struct sirfsoc_pmx {
  178. struct device *dev;
  179. struct pinctrl_dev *pmx;
  180. void __iomem *gpio_virtbase;
  181. void __iomem *rsc_virtbase;
  182. bool is_marco;
  183. };
  184. /* SIRFSOC_GPIO_PAD_EN set */
  185. struct sirfsoc_muxmask {
  186. unsigned long group;
  187. unsigned long mask;
  188. };
  189. struct sirfsoc_padmux {
  190. unsigned long muxmask_counts;
  191. const struct sirfsoc_muxmask *muxmask;
  192. /* RSC_PIN_MUX set */
  193. unsigned long funcmask;
  194. unsigned long funcval;
  195. };
  196. /**
  197. * struct sirfsoc_pin_group - describes a SiRFprimaII pin group
  198. * @name: the name of this specific pin group
  199. * @pins: an array of discrete physical pins used in this group, taken
  200. * from the driver-local pin enumeration space
  201. * @num_pins: the number of pins in this group array, i.e. the number of
  202. * elements in .pins so we can iterate over that array
  203. */
  204. struct sirfsoc_pin_group {
  205. const char *name;
  206. const unsigned int *pins;
  207. const unsigned num_pins;
  208. };
  209. static const struct sirfsoc_muxmask lcd_16bits_sirfsoc_muxmask[] = {
  210. {
  211. .group = 3,
  212. .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) |
  213. BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(15) | BIT(16) |
  214. BIT(17) | BIT(18),
  215. }, {
  216. .group = 2,
  217. .mask = BIT(31),
  218. },
  219. };
  220. static const struct sirfsoc_padmux lcd_16bits_padmux = {
  221. .muxmask_counts = ARRAY_SIZE(lcd_16bits_sirfsoc_muxmask),
  222. .muxmask = lcd_16bits_sirfsoc_muxmask,
  223. .funcmask = BIT(4),
  224. .funcval = 0,
  225. };
  226. static const unsigned lcd_16bits_pins[] = { 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
  227. 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
  228. static const struct sirfsoc_muxmask lcd_18bits_muxmask[] = {
  229. {
  230. .group = 3,
  231. .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) |
  232. BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(15) | BIT(16) |
  233. BIT(17) | BIT(18),
  234. }, {
  235. .group = 2,
  236. .mask = BIT(31),
  237. }, {
  238. .group = 0,
  239. .mask = BIT(16) | BIT(17),
  240. },
  241. };
  242. static const struct sirfsoc_padmux lcd_18bits_padmux = {
  243. .muxmask_counts = ARRAY_SIZE(lcd_18bits_muxmask),
  244. .muxmask = lcd_18bits_muxmask,
  245. .funcmask = BIT(4),
  246. .funcval = 0,
  247. };
  248. static const unsigned lcd_18bits_pins[] = { 16, 17, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
  249. 105, 106, 107, 108, 109, 110, 111, 112, 113, 114};
  250. static const struct sirfsoc_muxmask lcd_24bits_muxmask[] = {
  251. {
  252. .group = 3,
  253. .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) |
  254. BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(15) | BIT(16) |
  255. BIT(17) | BIT(18),
  256. }, {
  257. .group = 2,
  258. .mask = BIT(31),
  259. }, {
  260. .group = 0,
  261. .mask = BIT(16) | BIT(17) | BIT(18) | BIT(19) | BIT(20) | BIT(21) | BIT(22) | BIT(23),
  262. },
  263. };
  264. static const struct sirfsoc_padmux lcd_24bits_padmux = {
  265. .muxmask_counts = ARRAY_SIZE(lcd_24bits_muxmask),
  266. .muxmask = lcd_24bits_muxmask,
  267. .funcmask = BIT(4),
  268. .funcval = 0,
  269. };
  270. static const unsigned lcd_24bits_pins[] = { 16, 17, 18, 19, 20, 21, 22, 23, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
  271. 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
  272. static const struct sirfsoc_muxmask lcdrom_muxmask[] = {
  273. {
  274. .group = 3,
  275. .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) |
  276. BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(15) | BIT(16) |
  277. BIT(17) | BIT(18),
  278. }, {
  279. .group = 2,
  280. .mask = BIT(31),
  281. }, {
  282. .group = 0,
  283. .mask = BIT(23),
  284. },
  285. };
  286. static const struct sirfsoc_padmux lcdrom_padmux = {
  287. .muxmask_counts = ARRAY_SIZE(lcdrom_muxmask),
  288. .muxmask = lcdrom_muxmask,
  289. .funcmask = BIT(4),
  290. .funcval = BIT(4),
  291. };
  292. static const unsigned lcdrom_pins[] = { 23, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
  293. 105, 106, 107, 108, 109, 110, 111, 112, 113, 114 };
  294. static const struct sirfsoc_muxmask uart0_muxmask[] = {
  295. {
  296. .group = 2,
  297. .mask = BIT(4) | BIT(5),
  298. }, {
  299. .group = 1,
  300. .mask = BIT(23) | BIT(28),
  301. },
  302. };
  303. static const struct sirfsoc_padmux uart0_padmux = {
  304. .muxmask_counts = ARRAY_SIZE(uart0_muxmask),
  305. .muxmask = uart0_muxmask,
  306. .funcmask = BIT(9),
  307. .funcval = BIT(9),
  308. };
  309. static const unsigned uart0_pins[] = { 55, 60, 68, 69 };
  310. static const struct sirfsoc_muxmask uart0_nostreamctrl_muxmask[] = {
  311. {
  312. .group = 2,
  313. .mask = BIT(4) | BIT(5),
  314. },
  315. };
  316. static const struct sirfsoc_padmux uart0_nostreamctrl_padmux = {
  317. .muxmask_counts = ARRAY_SIZE(uart0_nostreamctrl_muxmask),
  318. .muxmask = uart0_nostreamctrl_muxmask,
  319. };
  320. static const unsigned uart0_nostreamctrl_pins[] = { 68, 39 };
  321. static const struct sirfsoc_muxmask uart1_muxmask[] = {
  322. {
  323. .group = 1,
  324. .mask = BIT(15) | BIT(17),
  325. },
  326. };
  327. static const struct sirfsoc_padmux uart1_padmux = {
  328. .muxmask_counts = ARRAY_SIZE(uart1_muxmask),
  329. .muxmask = uart1_muxmask,
  330. };
  331. static const unsigned uart1_pins[] = { 47, 49 };
  332. static const struct sirfsoc_muxmask uart2_muxmask[] = {
  333. {
  334. .group = 1,
  335. .mask = BIT(16) | BIT(18) | BIT(24) | BIT(27),
  336. },
  337. };
  338. static const struct sirfsoc_padmux uart2_padmux = {
  339. .muxmask_counts = ARRAY_SIZE(uart2_muxmask),
  340. .muxmask = uart2_muxmask,
  341. .funcmask = BIT(10),
  342. .funcval = BIT(10),
  343. };
  344. static const unsigned uart2_pins[] = { 48, 50, 56, 59 };
  345. static const struct sirfsoc_muxmask uart2_nostreamctrl_muxmask[] = {
  346. {
  347. .group = 1,
  348. .mask = BIT(16) | BIT(18),
  349. },
  350. };
  351. static const struct sirfsoc_padmux uart2_nostreamctrl_padmux = {
  352. .muxmask_counts = ARRAY_SIZE(uart2_nostreamctrl_muxmask),
  353. .muxmask = uart2_nostreamctrl_muxmask,
  354. };
  355. static const unsigned uart2_nostreamctrl_pins[] = { 48, 50 };
  356. static const struct sirfsoc_muxmask sdmmc3_muxmask[] = {
  357. {
  358. .group = 0,
  359. .mask = BIT(30) | BIT(31),
  360. }, {
  361. .group = 1,
  362. .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3),
  363. },
  364. };
  365. static const struct sirfsoc_padmux sdmmc3_padmux = {
  366. .muxmask_counts = ARRAY_SIZE(sdmmc3_muxmask),
  367. .muxmask = sdmmc3_muxmask,
  368. .funcmask = BIT(7),
  369. .funcval = 0,
  370. };
  371. static const unsigned sdmmc3_pins[] = { 30, 31, 32, 33, 34, 35 };
  372. static const struct sirfsoc_muxmask spi0_muxmask[] = {
  373. {
  374. .group = 1,
  375. .mask = BIT(0) | BIT(1) | BIT(2) | BIT(3),
  376. },
  377. };
  378. static const struct sirfsoc_padmux spi0_padmux = {
  379. .muxmask_counts = ARRAY_SIZE(spi0_muxmask),
  380. .muxmask = spi0_muxmask,
  381. .funcmask = BIT(7),
  382. .funcval = BIT(7),
  383. };
  384. static const unsigned spi0_pins[] = { 32, 33, 34, 35 };
  385. static const struct sirfsoc_muxmask sdmmc4_muxmask[] = {
  386. {
  387. .group = 1,
  388. .mask = BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) | BIT(9),
  389. },
  390. };
  391. static const struct sirfsoc_padmux sdmmc4_padmux = {
  392. .muxmask_counts = ARRAY_SIZE(sdmmc4_muxmask),
  393. .muxmask = sdmmc4_muxmask,
  394. };
  395. static const unsigned sdmmc4_pins[] = { 36, 37, 38, 39, 40, 41 };
  396. static const struct sirfsoc_muxmask cko1_muxmask[] = {
  397. {
  398. .group = 1,
  399. .mask = BIT(10),
  400. },
  401. };
  402. static const struct sirfsoc_padmux cko1_padmux = {
  403. .muxmask_counts = ARRAY_SIZE(cko1_muxmask),
  404. .muxmask = cko1_muxmask,
  405. .funcmask = BIT(3),
  406. .funcval = 0,
  407. };
  408. static const unsigned cko1_pins[] = { 42 };
  409. static const struct sirfsoc_muxmask i2s_muxmask[] = {
  410. {
  411. .group = 1,
  412. .mask =
  413. BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14) | BIT(19)
  414. | BIT(23) | BIT(28),
  415. },
  416. };
  417. static const struct sirfsoc_padmux i2s_padmux = {
  418. .muxmask_counts = ARRAY_SIZE(i2s_muxmask),
  419. .muxmask = i2s_muxmask,
  420. .funcmask = BIT(3) | BIT(9),
  421. .funcval = BIT(3),
  422. };
  423. static const unsigned i2s_pins[] = { 42, 43, 44, 45, 46, 51, 55, 60 };
  424. static const struct sirfsoc_muxmask ac97_muxmask[] = {
  425. {
  426. .group = 1,
  427. .mask = BIT(11) | BIT(12) | BIT(13) | BIT(14),
  428. },
  429. };
  430. static const struct sirfsoc_padmux ac97_padmux = {
  431. .muxmask_counts = ARRAY_SIZE(ac97_muxmask),
  432. .muxmask = ac97_muxmask,
  433. .funcmask = BIT(8),
  434. .funcval = 0,
  435. };
  436. static const unsigned ac97_pins[] = { 33, 34, 35, 36 };
  437. static const struct sirfsoc_muxmask spi1_muxmask[] = {
  438. {
  439. .group = 1,
  440. .mask = BIT(11) | BIT(12) | BIT(13) | BIT(14),
  441. },
  442. };
  443. static const struct sirfsoc_padmux spi1_padmux = {
  444. .muxmask_counts = ARRAY_SIZE(spi1_muxmask),
  445. .muxmask = spi1_muxmask,
  446. .funcmask = BIT(8),
  447. .funcval = BIT(8),
  448. };
  449. static const unsigned spi1_pins[] = { 43, 44, 45, 46 };
  450. static const struct sirfsoc_muxmask sdmmc1_muxmask[] = {
  451. {
  452. .group = 0,
  453. .mask = BIT(27) | BIT(28) | BIT(29),
  454. },
  455. };
  456. static const struct sirfsoc_padmux sdmmc1_padmux = {
  457. .muxmask_counts = ARRAY_SIZE(sdmmc1_muxmask),
  458. .muxmask = sdmmc1_muxmask,
  459. };
  460. static const unsigned sdmmc1_pins[] = { 27, 28, 29 };
  461. static const struct sirfsoc_muxmask gps_muxmask[] = {
  462. {
  463. .group = 0,
  464. .mask = BIT(24) | BIT(25) | BIT(26),
  465. },
  466. };
  467. static const struct sirfsoc_padmux gps_padmux = {
  468. .muxmask_counts = ARRAY_SIZE(gps_muxmask),
  469. .muxmask = gps_muxmask,
  470. .funcmask = BIT(12) | BIT(13) | BIT(14),
  471. .funcval = BIT(12),
  472. };
  473. static const unsigned gps_pins[] = { 24, 25, 26 };
  474. static const struct sirfsoc_muxmask sdmmc5_muxmask[] = {
  475. {
  476. .group = 0,
  477. .mask = BIT(24) | BIT(25) | BIT(26),
  478. }, {
  479. .group = 1,
  480. .mask = BIT(29),
  481. }, {
  482. .group = 2,
  483. .mask = BIT(0) | BIT(1),
  484. },
  485. };
  486. static const struct sirfsoc_padmux sdmmc5_padmux = {
  487. .muxmask_counts = ARRAY_SIZE(sdmmc5_muxmask),
  488. .muxmask = sdmmc5_muxmask,
  489. .funcmask = BIT(13) | BIT(14),
  490. .funcval = BIT(13) | BIT(14),
  491. };
  492. static const unsigned sdmmc5_pins[] = { 24, 25, 26, 61, 64, 65 };
  493. static const struct sirfsoc_muxmask usp0_muxmask[] = {
  494. {
  495. .group = 1,
  496. .mask = BIT(19) | BIT(20) | BIT(21) | BIT(22) | BIT(23),
  497. },
  498. };
  499. static const struct sirfsoc_padmux usp0_padmux = {
  500. .muxmask_counts = ARRAY_SIZE(usp0_muxmask),
  501. .muxmask = usp0_muxmask,
  502. .funcmask = BIT(1) | BIT(2) | BIT(6) | BIT(9),
  503. .funcval = 0,
  504. };
  505. static const unsigned usp0_pins[] = { 51, 52, 53, 54, 55 };
  506. static const struct sirfsoc_muxmask usp1_muxmask[] = {
  507. {
  508. .group = 1,
  509. .mask = BIT(24) | BIT(25) | BIT(26) | BIT(27) | BIT(28),
  510. },
  511. };
  512. static const struct sirfsoc_padmux usp1_padmux = {
  513. .muxmask_counts = ARRAY_SIZE(usp1_muxmask),
  514. .muxmask = usp1_muxmask,
  515. .funcmask = BIT(1) | BIT(9) | BIT(10) | BIT(11),
  516. .funcval = 0,
  517. };
  518. static const unsigned usp1_pins[] = { 56, 57, 58, 59, 60 };
  519. static const struct sirfsoc_muxmask usp2_muxmask[] = {
  520. {
  521. .group = 1,
  522. .mask = BIT(29) | BIT(30) | BIT(31),
  523. }, {
  524. .group = 2,
  525. .mask = BIT(0) | BIT(1),
  526. },
  527. };
  528. static const struct sirfsoc_padmux usp2_padmux = {
  529. .muxmask_counts = ARRAY_SIZE(usp2_muxmask),
  530. .muxmask = usp2_muxmask,
  531. .funcmask = BIT(13) | BIT(14),
  532. .funcval = 0,
  533. };
  534. static const unsigned usp2_pins[] = { 61, 62, 63, 64, 65 };
  535. static const struct sirfsoc_muxmask nand_muxmask[] = {
  536. {
  537. .group = 2,
  538. .mask = BIT(2) | BIT(3) | BIT(28) | BIT(29) | BIT(30),
  539. },
  540. };
  541. static const struct sirfsoc_padmux nand_padmux = {
  542. .muxmask_counts = ARRAY_SIZE(nand_muxmask),
  543. .muxmask = nand_muxmask,
  544. .funcmask = BIT(5),
  545. .funcval = 0,
  546. };
  547. static const unsigned nand_pins[] = { 64, 65, 92, 93, 94 };
  548. static const struct sirfsoc_padmux sdmmc0_padmux = {
  549. .muxmask_counts = 0,
  550. .funcmask = BIT(5),
  551. .funcval = 0,
  552. };
  553. static const unsigned sdmmc0_pins[] = { };
  554. static const struct sirfsoc_muxmask sdmmc2_muxmask[] = {
  555. {
  556. .group = 2,
  557. .mask = BIT(2) | BIT(3),
  558. },
  559. };
  560. static const struct sirfsoc_padmux sdmmc2_padmux = {
  561. .muxmask_counts = ARRAY_SIZE(sdmmc2_muxmask),
  562. .muxmask = sdmmc2_muxmask,
  563. .funcmask = BIT(5),
  564. .funcval = BIT(5),
  565. };
  566. static const unsigned sdmmc2_pins[] = { 66, 67 };
  567. static const struct sirfsoc_muxmask cko0_muxmask[] = {
  568. {
  569. .group = 2,
  570. .mask = BIT(14),
  571. },
  572. };
  573. static const struct sirfsoc_padmux cko0_padmux = {
  574. .muxmask_counts = ARRAY_SIZE(cko0_muxmask),
  575. .muxmask = cko0_muxmask,
  576. };
  577. static const unsigned cko0_pins[] = { 78 };
  578. static const struct sirfsoc_muxmask vip_muxmask[] = {
  579. {
  580. .group = 2,
  581. .mask = BIT(15) | BIT(16) | BIT(17) | BIT(18) | BIT(19)
  582. | BIT(20) | BIT(21) | BIT(22) | BIT(23) | BIT(24) |
  583. BIT(25),
  584. },
  585. };
  586. static const struct sirfsoc_padmux vip_padmux = {
  587. .muxmask_counts = ARRAY_SIZE(vip_muxmask),
  588. .muxmask = vip_muxmask,
  589. .funcmask = BIT(0),
  590. .funcval = 0,
  591. };
  592. static const unsigned vip_pins[] = { 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89 };
  593. static const struct sirfsoc_muxmask i2c0_muxmask[] = {
  594. {
  595. .group = 2,
  596. .mask = BIT(26) | BIT(27),
  597. },
  598. };
  599. static const struct sirfsoc_padmux i2c0_padmux = {
  600. .muxmask_counts = ARRAY_SIZE(i2c0_muxmask),
  601. .muxmask = i2c0_muxmask,
  602. };
  603. static const unsigned i2c0_pins[] = { 90, 91 };
  604. static const struct sirfsoc_muxmask i2c1_muxmask[] = {
  605. {
  606. .group = 0,
  607. .mask = BIT(13) | BIT(15),
  608. },
  609. };
  610. static const struct sirfsoc_padmux i2c1_padmux = {
  611. .muxmask_counts = ARRAY_SIZE(i2c1_muxmask),
  612. .muxmask = i2c1_muxmask,
  613. };
  614. static const unsigned i2c1_pins[] = { 13, 15 };
  615. static const struct sirfsoc_muxmask viprom_muxmask[] = {
  616. {
  617. .group = 2,
  618. .mask = BIT(15) | BIT(16) | BIT(17) | BIT(18) | BIT(19)
  619. | BIT(20) | BIT(21) | BIT(22) | BIT(23) | BIT(24) |
  620. BIT(25),
  621. }, {
  622. .group = 0,
  623. .mask = BIT(12),
  624. },
  625. };
  626. static const struct sirfsoc_padmux viprom_padmux = {
  627. .muxmask_counts = ARRAY_SIZE(viprom_muxmask),
  628. .muxmask = viprom_muxmask,
  629. .funcmask = BIT(0),
  630. .funcval = BIT(0),
  631. };
  632. static const unsigned viprom_pins[] = { 12, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89 };
  633. static const struct sirfsoc_muxmask pwm0_muxmask[] = {
  634. {
  635. .group = 0,
  636. .mask = BIT(4),
  637. },
  638. };
  639. static const struct sirfsoc_padmux pwm0_padmux = {
  640. .muxmask_counts = ARRAY_SIZE(pwm0_muxmask),
  641. .muxmask = pwm0_muxmask,
  642. .funcmask = BIT(12),
  643. .funcval = 0,
  644. };
  645. static const unsigned pwm0_pins[] = { 4 };
  646. static const struct sirfsoc_muxmask pwm1_muxmask[] = {
  647. {
  648. .group = 0,
  649. .mask = BIT(5),
  650. },
  651. };
  652. static const struct sirfsoc_padmux pwm1_padmux = {
  653. .muxmask_counts = ARRAY_SIZE(pwm1_muxmask),
  654. .muxmask = pwm1_muxmask,
  655. };
  656. static const unsigned pwm1_pins[] = { 5 };
  657. static const struct sirfsoc_muxmask pwm2_muxmask[] = {
  658. {
  659. .group = 0,
  660. .mask = BIT(6),
  661. },
  662. };
  663. static const struct sirfsoc_padmux pwm2_padmux = {
  664. .muxmask_counts = ARRAY_SIZE(pwm2_muxmask),
  665. .muxmask = pwm2_muxmask,
  666. };
  667. static const unsigned pwm2_pins[] = { 6 };
  668. static const struct sirfsoc_muxmask pwm3_muxmask[] = {
  669. {
  670. .group = 0,
  671. .mask = BIT(7),
  672. },
  673. };
  674. static const struct sirfsoc_padmux pwm3_padmux = {
  675. .muxmask_counts = ARRAY_SIZE(pwm3_muxmask),
  676. .muxmask = pwm3_muxmask,
  677. };
  678. static const unsigned pwm3_pins[] = { 7 };
  679. static const struct sirfsoc_muxmask warm_rst_muxmask[] = {
  680. {
  681. .group = 0,
  682. .mask = BIT(8),
  683. },
  684. };
  685. static const struct sirfsoc_padmux warm_rst_padmux = {
  686. .muxmask_counts = ARRAY_SIZE(warm_rst_muxmask),
  687. .muxmask = warm_rst_muxmask,
  688. };
  689. static const unsigned warm_rst_pins[] = { 8 };
  690. static const struct sirfsoc_muxmask usb0_utmi_drvbus_muxmask[] = {
  691. {
  692. .group = 1,
  693. .mask = BIT(22),
  694. },
  695. };
  696. static const struct sirfsoc_padmux usb0_utmi_drvbus_padmux = {
  697. .muxmask_counts = ARRAY_SIZE(usb0_utmi_drvbus_muxmask),
  698. .muxmask = usb0_utmi_drvbus_muxmask,
  699. .funcmask = BIT(6),
  700. .funcval = BIT(6), /* refer to PAD_UTMI_DRVVBUS0_ENABLE */
  701. };
  702. static const unsigned usb0_utmi_drvbus_pins[] = { 54 };
  703. static const struct sirfsoc_muxmask usb1_utmi_drvbus_muxmask[] = {
  704. {
  705. .group = 1,
  706. .mask = BIT(27),
  707. },
  708. };
  709. static const struct sirfsoc_padmux usb1_utmi_drvbus_padmux = {
  710. .muxmask_counts = ARRAY_SIZE(usb1_utmi_drvbus_muxmask),
  711. .muxmask = usb1_utmi_drvbus_muxmask,
  712. .funcmask = BIT(11),
  713. .funcval = BIT(11), /* refer to PAD_UTMI_DRVVBUS1_ENABLE */
  714. };
  715. static const unsigned usb1_utmi_drvbus_pins[] = { 59 };
  716. static const struct sirfsoc_muxmask pulse_count_muxmask[] = {
  717. {
  718. .group = 0,
  719. .mask = BIT(9) | BIT(10) | BIT(11),
  720. },
  721. };
  722. static const struct sirfsoc_padmux pulse_count_padmux = {
  723. .muxmask_counts = ARRAY_SIZE(pulse_count_muxmask),
  724. .muxmask = pulse_count_muxmask,
  725. };
  726. static const unsigned pulse_count_pins[] = { 9, 10, 11 };
  727. #define SIRFSOC_PIN_GROUP(n, p) \
  728. { \
  729. .name = n, \
  730. .pins = p, \
  731. .num_pins = ARRAY_SIZE(p), \
  732. }
  733. static const struct sirfsoc_pin_group sirfsoc_pin_groups[] = {
  734. SIRFSOC_PIN_GROUP("lcd_16bitsgrp", lcd_16bits_pins),
  735. SIRFSOC_PIN_GROUP("lcd_18bitsgrp", lcd_18bits_pins),
  736. SIRFSOC_PIN_GROUP("lcd_24bitsgrp", lcd_24bits_pins),
  737. SIRFSOC_PIN_GROUP("lcdrom_grp", lcdrom_pins),
  738. SIRFSOC_PIN_GROUP("uart0grp", uart0_pins),
  739. SIRFSOC_PIN_GROUP("uart1grp", uart1_pins),
  740. SIRFSOC_PIN_GROUP("uart2grp", uart2_pins),
  741. SIRFSOC_PIN_GROUP("uart2_nostreamctrlgrp", uart2_nostreamctrl_pins),
  742. SIRFSOC_PIN_GROUP("usp0grp", usp0_pins),
  743. SIRFSOC_PIN_GROUP("usp1grp", usp1_pins),
  744. SIRFSOC_PIN_GROUP("usp2grp", usp2_pins),
  745. SIRFSOC_PIN_GROUP("i2c0grp", i2c0_pins),
  746. SIRFSOC_PIN_GROUP("i2c1grp", i2c1_pins),
  747. SIRFSOC_PIN_GROUP("pwm0grp", pwm0_pins),
  748. SIRFSOC_PIN_GROUP("pwm1grp", pwm1_pins),
  749. SIRFSOC_PIN_GROUP("pwm2grp", pwm2_pins),
  750. SIRFSOC_PIN_GROUP("pwm3grp", pwm3_pins),
  751. SIRFSOC_PIN_GROUP("vipgrp", vip_pins),
  752. SIRFSOC_PIN_GROUP("vipromgrp", viprom_pins),
  753. SIRFSOC_PIN_GROUP("warm_rstgrp", warm_rst_pins),
  754. SIRFSOC_PIN_GROUP("cko0_rstgrp", cko0_pins),
  755. SIRFSOC_PIN_GROUP("cko1_rstgrp", cko1_pins),
  756. SIRFSOC_PIN_GROUP("sdmmc0grp", sdmmc0_pins),
  757. SIRFSOC_PIN_GROUP("sdmmc1grp", sdmmc1_pins),
  758. SIRFSOC_PIN_GROUP("sdmmc2grp", sdmmc2_pins),
  759. SIRFSOC_PIN_GROUP("sdmmc3grp", sdmmc3_pins),
  760. SIRFSOC_PIN_GROUP("sdmmc4grp", sdmmc4_pins),
  761. SIRFSOC_PIN_GROUP("sdmmc5grp", sdmmc5_pins),
  762. SIRFSOC_PIN_GROUP("usb0_utmi_drvbusgrp", usb0_utmi_drvbus_pins),
  763. SIRFSOC_PIN_GROUP("usb1_utmi_drvbusgrp", usb1_utmi_drvbus_pins),
  764. SIRFSOC_PIN_GROUP("pulse_countgrp", pulse_count_pins),
  765. SIRFSOC_PIN_GROUP("i2sgrp", i2s_pins),
  766. SIRFSOC_PIN_GROUP("ac97grp", ac97_pins),
  767. SIRFSOC_PIN_GROUP("nandgrp", nand_pins),
  768. SIRFSOC_PIN_GROUP("spi0grp", spi0_pins),
  769. SIRFSOC_PIN_GROUP("spi1grp", spi1_pins),
  770. SIRFSOC_PIN_GROUP("gpsgrp", gps_pins),
  771. };
  772. static int sirfsoc_get_groups_count(struct pinctrl_dev *pctldev)
  773. {
  774. return ARRAY_SIZE(sirfsoc_pin_groups);
  775. }
  776. static const char *sirfsoc_get_group_name(struct pinctrl_dev *pctldev,
  777. unsigned selector)
  778. {
  779. return sirfsoc_pin_groups[selector].name;
  780. }
  781. static int sirfsoc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
  782. const unsigned **pins,
  783. unsigned *num_pins)
  784. {
  785. *pins = sirfsoc_pin_groups[selector].pins;
  786. *num_pins = sirfsoc_pin_groups[selector].num_pins;
  787. return 0;
  788. }
  789. static void sirfsoc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  790. unsigned offset)
  791. {
  792. seq_printf(s, " " DRIVER_NAME);
  793. }
  794. static int sirfsoc_dt_node_to_map(struct pinctrl_dev *pctldev,
  795. struct device_node *np_config,
  796. struct pinctrl_map **map, unsigned *num_maps)
  797. {
  798. struct sirfsoc_pmx *spmx = pinctrl_dev_get_drvdata(pctldev);
  799. struct device_node *np;
  800. struct property *prop;
  801. const char *function, *group;
  802. int ret, index = 0, count = 0;
  803. /* calculate number of maps required */
  804. for_each_child_of_node(np_config, np) {
  805. ret = of_property_read_string(np, "sirf,function", &function);
  806. if (ret < 0)
  807. return ret;
  808. ret = of_property_count_strings(np, "sirf,pins");
  809. if (ret < 0)
  810. return ret;
  811. count += ret;
  812. }
  813. if (!count) {
  814. dev_err(spmx->dev, "No child nodes passed via DT\n");
  815. return -ENODEV;
  816. }
  817. *map = kzalloc(sizeof(**map) * count, GFP_KERNEL);
  818. if (!*map)
  819. return -ENOMEM;
  820. for_each_child_of_node(np_config, np) {
  821. of_property_read_string(np, "sirf,function", &function);
  822. of_property_for_each_string(np, "sirf,pins", prop, group) {
  823. (*map)[index].type = PIN_MAP_TYPE_MUX_GROUP;
  824. (*map)[index].data.mux.group = group;
  825. (*map)[index].data.mux.function = function;
  826. index++;
  827. }
  828. }
  829. *num_maps = count;
  830. return 0;
  831. }
  832. static void sirfsoc_dt_free_map(struct pinctrl_dev *pctldev,
  833. struct pinctrl_map *map, unsigned num_maps)
  834. {
  835. kfree(map);
  836. }
  837. static struct pinctrl_ops sirfsoc_pctrl_ops = {
  838. .get_groups_count = sirfsoc_get_groups_count,
  839. .get_group_name = sirfsoc_get_group_name,
  840. .get_group_pins = sirfsoc_get_group_pins,
  841. .pin_dbg_show = sirfsoc_pin_dbg_show,
  842. .dt_node_to_map = sirfsoc_dt_node_to_map,
  843. .dt_free_map = sirfsoc_dt_free_map,
  844. };
  845. struct sirfsoc_pmx_func {
  846. const char *name;
  847. const char * const *groups;
  848. const unsigned num_groups;
  849. const struct sirfsoc_padmux *padmux;
  850. };
  851. static const char * const lcd_16bitsgrp[] = { "lcd_16bitsgrp" };
  852. static const char * const lcd_18bitsgrp[] = { "lcd_18bitsgrp" };
  853. static const char * const lcd_24bitsgrp[] = { "lcd_24bitsgrp" };
  854. static const char * const lcdromgrp[] = { "lcdromgrp" };
  855. static const char * const uart0grp[] = { "uart0grp" };
  856. static const char * const uart1grp[] = { "uart1grp" };
  857. static const char * const uart2grp[] = { "uart2grp" };
  858. static const char * const uart2_nostreamctrlgrp[] = { "uart2_nostreamctrlgrp" };
  859. static const char * const usp0grp[] = { "usp0grp" };
  860. static const char * const usp1grp[] = { "usp1grp" };
  861. static const char * const usp2grp[] = { "usp2grp" };
  862. static const char * const i2c0grp[] = { "i2c0grp" };
  863. static const char * const i2c1grp[] = { "i2c1grp" };
  864. static const char * const pwm0grp[] = { "pwm0grp" };
  865. static const char * const pwm1grp[] = { "pwm1grp" };
  866. static const char * const pwm2grp[] = { "pwm2grp" };
  867. static const char * const pwm3grp[] = { "pwm3grp" };
  868. static const char * const vipgrp[] = { "vipgrp" };
  869. static const char * const vipromgrp[] = { "vipromgrp" };
  870. static const char * const warm_rstgrp[] = { "warm_rstgrp" };
  871. static const char * const cko0grp[] = { "cko0grp" };
  872. static const char * const cko1grp[] = { "cko1grp" };
  873. static const char * const sdmmc0grp[] = { "sdmmc0grp" };
  874. static const char * const sdmmc1grp[] = { "sdmmc1grp" };
  875. static const char * const sdmmc2grp[] = { "sdmmc2grp" };
  876. static const char * const sdmmc3grp[] = { "sdmmc3grp" };
  877. static const char * const sdmmc4grp[] = { "sdmmc4grp" };
  878. static const char * const sdmmc5grp[] = { "sdmmc5grp" };
  879. static const char * const usb0_utmi_drvbusgrp[] = { "usb0_utmi_drvbusgrp" };
  880. static const char * const usb1_utmi_drvbusgrp[] = { "usb1_utmi_drvbusgrp" };
  881. static const char * const pulse_countgrp[] = { "pulse_countgrp" };
  882. static const char * const i2sgrp[] = { "i2sgrp" };
  883. static const char * const ac97grp[] = { "ac97grp" };
  884. static const char * const nandgrp[] = { "nandgrp" };
  885. static const char * const spi0grp[] = { "spi0grp" };
  886. static const char * const spi1grp[] = { "spi1grp" };
  887. static const char * const gpsgrp[] = { "gpsgrp" };
  888. #define SIRFSOC_PMX_FUNCTION(n, g, m) \
  889. { \
  890. .name = n, \
  891. .groups = g, \
  892. .num_groups = ARRAY_SIZE(g), \
  893. .padmux = &m, \
  894. }
  895. static const struct sirfsoc_pmx_func sirfsoc_pmx_functions[] = {
  896. SIRFSOC_PMX_FUNCTION("lcd_16bits", lcd_16bitsgrp, lcd_16bits_padmux),
  897. SIRFSOC_PMX_FUNCTION("lcd_18bits", lcd_18bitsgrp, lcd_18bits_padmux),
  898. SIRFSOC_PMX_FUNCTION("lcd_24bits", lcd_24bitsgrp, lcd_24bits_padmux),
  899. SIRFSOC_PMX_FUNCTION("lcdrom", lcdromgrp, lcdrom_padmux),
  900. SIRFSOC_PMX_FUNCTION("uart0", uart0grp, uart0_padmux),
  901. SIRFSOC_PMX_FUNCTION("uart1", uart1grp, uart1_padmux),
  902. SIRFSOC_PMX_FUNCTION("uart2", uart2grp, uart2_padmux),
  903. SIRFSOC_PMX_FUNCTION("uart2_nostreamctrl", uart2_nostreamctrlgrp, uart2_nostreamctrl_padmux),
  904. SIRFSOC_PMX_FUNCTION("usp0", usp0grp, usp0_padmux),
  905. SIRFSOC_PMX_FUNCTION("usp1", usp1grp, usp1_padmux),
  906. SIRFSOC_PMX_FUNCTION("usp2", usp2grp, usp2_padmux),
  907. SIRFSOC_PMX_FUNCTION("i2c0", i2c0grp, i2c0_padmux),
  908. SIRFSOC_PMX_FUNCTION("i2c1", i2c1grp, i2c1_padmux),
  909. SIRFSOC_PMX_FUNCTION("pwm0", pwm0grp, pwm0_padmux),
  910. SIRFSOC_PMX_FUNCTION("pwm1", pwm1grp, pwm1_padmux),
  911. SIRFSOC_PMX_FUNCTION("pwm2", pwm2grp, pwm2_padmux),
  912. SIRFSOC_PMX_FUNCTION("pwm3", pwm3grp, pwm3_padmux),
  913. SIRFSOC_PMX_FUNCTION("vip", vipgrp, vip_padmux),
  914. SIRFSOC_PMX_FUNCTION("viprom", vipromgrp, viprom_padmux),
  915. SIRFSOC_PMX_FUNCTION("warm_rst", warm_rstgrp, warm_rst_padmux),
  916. SIRFSOC_PMX_FUNCTION("cko0", cko0grp, cko0_padmux),
  917. SIRFSOC_PMX_FUNCTION("cko1", cko1grp, cko1_padmux),
  918. SIRFSOC_PMX_FUNCTION("sdmmc0", sdmmc0grp, sdmmc0_padmux),
  919. SIRFSOC_PMX_FUNCTION("sdmmc1", sdmmc1grp, sdmmc1_padmux),
  920. SIRFSOC_PMX_FUNCTION("sdmmc2", sdmmc2grp, sdmmc2_padmux),
  921. SIRFSOC_PMX_FUNCTION("sdmmc3", sdmmc3grp, sdmmc3_padmux),
  922. SIRFSOC_PMX_FUNCTION("sdmmc4", sdmmc4grp, sdmmc4_padmux),
  923. SIRFSOC_PMX_FUNCTION("sdmmc5", sdmmc5grp, sdmmc5_padmux),
  924. SIRFSOC_PMX_FUNCTION("usb0_utmi_drvbus", usb0_utmi_drvbusgrp, usb0_utmi_drvbus_padmux),
  925. SIRFSOC_PMX_FUNCTION("usb1_utmi_drvbus", usb1_utmi_drvbusgrp, usb1_utmi_drvbus_padmux),
  926. SIRFSOC_PMX_FUNCTION("pulse_count", pulse_countgrp, pulse_count_padmux),
  927. SIRFSOC_PMX_FUNCTION("i2s", i2sgrp, i2s_padmux),
  928. SIRFSOC_PMX_FUNCTION("ac97", ac97grp, ac97_padmux),
  929. SIRFSOC_PMX_FUNCTION("nand", nandgrp, nand_padmux),
  930. SIRFSOC_PMX_FUNCTION("spi0", spi0grp, spi0_padmux),
  931. SIRFSOC_PMX_FUNCTION("spi1", spi1grp, spi1_padmux),
  932. SIRFSOC_PMX_FUNCTION("gps", gpsgrp, gps_padmux),
  933. };
  934. static void sirfsoc_pinmux_endisable(struct sirfsoc_pmx *spmx, unsigned selector,
  935. bool enable)
  936. {
  937. int i;
  938. const struct sirfsoc_padmux *mux = sirfsoc_pmx_functions[selector].padmux;
  939. const struct sirfsoc_muxmask *mask = mux->muxmask;
  940. for (i = 0; i < mux->muxmask_counts; i++) {
  941. u32 muxval;
  942. if (!spmx->is_marco) {
  943. muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(mask[i].group));
  944. if (enable)
  945. muxval = muxval & ~mask[i].mask;
  946. else
  947. muxval = muxval | mask[i].mask;
  948. writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(mask[i].group));
  949. } else {
  950. if (enable)
  951. writel(mask[i].mask, spmx->gpio_virtbase +
  952. SIRFSOC_GPIO_PAD_EN_CLR(mask[i].group));
  953. else
  954. writel(mask[i].mask, spmx->gpio_virtbase +
  955. SIRFSOC_GPIO_PAD_EN(mask[i].group));
  956. }
  957. }
  958. if (mux->funcmask && enable) {
  959. u32 func_en_val;
  960. func_en_val =
  961. readl(spmx->rsc_virtbase + SIRFSOC_RSC_PIN_MUX);
  962. func_en_val =
  963. (func_en_val & ~mux->funcmask) | (mux->
  964. funcval);
  965. writel(func_en_val, spmx->rsc_virtbase + SIRFSOC_RSC_PIN_MUX);
  966. }
  967. }
  968. static int sirfsoc_pinmux_enable(struct pinctrl_dev *pmxdev, unsigned selector,
  969. unsigned group)
  970. {
  971. struct sirfsoc_pmx *spmx;
  972. spmx = pinctrl_dev_get_drvdata(pmxdev);
  973. sirfsoc_pinmux_endisable(spmx, selector, true);
  974. return 0;
  975. }
  976. static void sirfsoc_pinmux_disable(struct pinctrl_dev *pmxdev, unsigned selector,
  977. unsigned group)
  978. {
  979. struct sirfsoc_pmx *spmx;
  980. spmx = pinctrl_dev_get_drvdata(pmxdev);
  981. sirfsoc_pinmux_endisable(spmx, selector, false);
  982. }
  983. static int sirfsoc_pinmux_get_funcs_count(struct pinctrl_dev *pmxdev)
  984. {
  985. return ARRAY_SIZE(sirfsoc_pmx_functions);
  986. }
  987. static const char *sirfsoc_pinmux_get_func_name(struct pinctrl_dev *pctldev,
  988. unsigned selector)
  989. {
  990. return sirfsoc_pmx_functions[selector].name;
  991. }
  992. static int sirfsoc_pinmux_get_groups(struct pinctrl_dev *pctldev, unsigned selector,
  993. const char * const **groups,
  994. unsigned * const num_groups)
  995. {
  996. *groups = sirfsoc_pmx_functions[selector].groups;
  997. *num_groups = sirfsoc_pmx_functions[selector].num_groups;
  998. return 0;
  999. }
  1000. static int sirfsoc_pinmux_request_gpio(struct pinctrl_dev *pmxdev,
  1001. struct pinctrl_gpio_range *range, unsigned offset)
  1002. {
  1003. struct sirfsoc_pmx *spmx;
  1004. int group = range->id;
  1005. u32 muxval;
  1006. spmx = pinctrl_dev_get_drvdata(pmxdev);
  1007. if (!spmx->is_marco) {
  1008. muxval = readl(spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group));
  1009. muxval = muxval | (1 << (offset - range->pin_base));
  1010. writel(muxval, spmx->gpio_virtbase + SIRFSOC_GPIO_PAD_EN(group));
  1011. } else {
  1012. writel(1 << (offset - range->pin_base), spmx->gpio_virtbase +
  1013. SIRFSOC_GPIO_PAD_EN(group));
  1014. }
  1015. return 0;
  1016. }
  1017. static struct pinmux_ops sirfsoc_pinmux_ops = {
  1018. .enable = sirfsoc_pinmux_enable,
  1019. .disable = sirfsoc_pinmux_disable,
  1020. .get_functions_count = sirfsoc_pinmux_get_funcs_count,
  1021. .get_function_name = sirfsoc_pinmux_get_func_name,
  1022. .get_function_groups = sirfsoc_pinmux_get_groups,
  1023. .gpio_request_enable = sirfsoc_pinmux_request_gpio,
  1024. };
  1025. static struct pinctrl_desc sirfsoc_pinmux_desc = {
  1026. .name = DRIVER_NAME,
  1027. .pins = sirfsoc_pads,
  1028. .npins = ARRAY_SIZE(sirfsoc_pads),
  1029. .pctlops = &sirfsoc_pctrl_ops,
  1030. .pmxops = &sirfsoc_pinmux_ops,
  1031. .owner = THIS_MODULE,
  1032. };
  1033. /*
  1034. * Todo: bind irq_chip to every pinctrl_gpio_range
  1035. */
  1036. static struct pinctrl_gpio_range sirfsoc_gpio_ranges[] = {
  1037. {
  1038. .name = "sirfsoc-gpio*",
  1039. .id = 0,
  1040. .base = 0,
  1041. .pin_base = 0,
  1042. .npins = 32,
  1043. }, {
  1044. .name = "sirfsoc-gpio*",
  1045. .id = 1,
  1046. .base = 32,
  1047. .pin_base = 32,
  1048. .npins = 32,
  1049. }, {
  1050. .name = "sirfsoc-gpio*",
  1051. .id = 2,
  1052. .base = 64,
  1053. .pin_base = 64,
  1054. .npins = 32,
  1055. }, {
  1056. .name = "sirfsoc-gpio*",
  1057. .id = 3,
  1058. .base = 96,
  1059. .pin_base = 96,
  1060. .npins = 19,
  1061. },
  1062. };
  1063. static void __iomem *sirfsoc_rsc_of_iomap(void)
  1064. {
  1065. const struct of_device_id rsc_ids[] = {
  1066. { .compatible = "sirf,prima2-rsc" },
  1067. { .compatible = "sirf,marco-rsc" },
  1068. {}
  1069. };
  1070. struct device_node *np;
  1071. np = of_find_matching_node(NULL, rsc_ids);
  1072. if (!np)
  1073. panic("unable to find compatible rsc node in dtb\n");
  1074. return of_iomap(np, 0);
  1075. }
  1076. static int sirfsoc_gpio_of_xlate(struct gpio_chip *gc,
  1077. const struct of_phandle_args *gpiospec,
  1078. u32 *flags)
  1079. {
  1080. if (gpiospec->args[0] > SIRFSOC_GPIO_NO_OF_BANKS * SIRFSOC_GPIO_BANK_SIZE)
  1081. return -EINVAL;
  1082. if (gc != &sgpio_bank[gpiospec->args[0] / SIRFSOC_GPIO_BANK_SIZE].chip.gc)
  1083. return -EINVAL;
  1084. if (flags)
  1085. *flags = gpiospec->args[1];
  1086. return gpiospec->args[0] % SIRFSOC_GPIO_BANK_SIZE;
  1087. }
  1088. static int sirfsoc_pinmux_probe(struct platform_device *pdev)
  1089. {
  1090. int ret;
  1091. struct sirfsoc_pmx *spmx;
  1092. struct device_node *np = pdev->dev.of_node;
  1093. int i;
  1094. /* Create state holders etc for this driver */
  1095. spmx = devm_kzalloc(&pdev->dev, sizeof(*spmx), GFP_KERNEL);
  1096. if (!spmx)
  1097. return -ENOMEM;
  1098. spmx->dev = &pdev->dev;
  1099. platform_set_drvdata(pdev, spmx);
  1100. spmx->gpio_virtbase = of_iomap(np, 0);
  1101. if (!spmx->gpio_virtbase) {
  1102. ret = -ENOMEM;
  1103. dev_err(&pdev->dev, "can't map gpio registers\n");
  1104. goto out_no_gpio_remap;
  1105. }
  1106. spmx->rsc_virtbase = sirfsoc_rsc_of_iomap();
  1107. if (!spmx->rsc_virtbase) {
  1108. ret = -ENOMEM;
  1109. dev_err(&pdev->dev, "can't map rsc registers\n");
  1110. goto out_no_rsc_remap;
  1111. }
  1112. if (of_device_is_compatible(np, "sirf,marco-pinctrl"))
  1113. spmx->is_marco = 1;
  1114. /* Now register the pin controller and all pins it handles */
  1115. spmx->pmx = pinctrl_register(&sirfsoc_pinmux_desc, &pdev->dev, spmx);
  1116. if (!spmx->pmx) {
  1117. dev_err(&pdev->dev, "could not register SIRFSOC pinmux driver\n");
  1118. ret = -EINVAL;
  1119. goto out_no_pmx;
  1120. }
  1121. for (i = 0; i < ARRAY_SIZE(sirfsoc_gpio_ranges); i++) {
  1122. sirfsoc_gpio_ranges[i].gc = &sgpio_bank[i].chip.gc;
  1123. pinctrl_add_gpio_range(spmx->pmx, &sirfsoc_gpio_ranges[i]);
  1124. }
  1125. dev_info(&pdev->dev, "initialized SIRFSOC pinmux driver\n");
  1126. return 0;
  1127. out_no_pmx:
  1128. iounmap(spmx->rsc_virtbase);
  1129. out_no_rsc_remap:
  1130. iounmap(spmx->gpio_virtbase);
  1131. out_no_gpio_remap:
  1132. platform_set_drvdata(pdev, NULL);
  1133. return ret;
  1134. }
  1135. static const struct of_device_id pinmux_ids[] = {
  1136. { .compatible = "sirf,prima2-pinctrl" },
  1137. { .compatible = "sirf,marco-pinctrl" },
  1138. {}
  1139. };
  1140. static struct platform_driver sirfsoc_pinmux_driver = {
  1141. .driver = {
  1142. .name = DRIVER_NAME,
  1143. .owner = THIS_MODULE,
  1144. .of_match_table = pinmux_ids,
  1145. },
  1146. .probe = sirfsoc_pinmux_probe,
  1147. };
  1148. static int __init sirfsoc_pinmux_init(void)
  1149. {
  1150. return platform_driver_register(&sirfsoc_pinmux_driver);
  1151. }
  1152. arch_initcall(sirfsoc_pinmux_init);
  1153. static inline int sirfsoc_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  1154. {
  1155. struct sirfsoc_gpio_bank *bank = container_of(to_of_mm_gpio_chip(chip),
  1156. struct sirfsoc_gpio_bank, chip);
  1157. return irq_find_mapping(bank->domain, offset);
  1158. }
  1159. static inline int sirfsoc_gpio_to_offset(unsigned int gpio)
  1160. {
  1161. return gpio % SIRFSOC_GPIO_BANK_SIZE;
  1162. }
  1163. static inline struct sirfsoc_gpio_bank *sirfsoc_gpio_to_bank(unsigned int gpio)
  1164. {
  1165. return &sgpio_bank[gpio / SIRFSOC_GPIO_BANK_SIZE];
  1166. }
  1167. static inline struct sirfsoc_gpio_bank *sirfsoc_irqchip_to_bank(struct gpio_chip *chip)
  1168. {
  1169. return container_of(to_of_mm_gpio_chip(chip), struct sirfsoc_gpio_bank, chip);
  1170. }
  1171. static void sirfsoc_gpio_irq_ack(struct irq_data *d)
  1172. {
  1173. struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
  1174. int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE;
  1175. u32 val, offset;
  1176. unsigned long flags;
  1177. offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
  1178. spin_lock_irqsave(&sgpio_lock, flags);
  1179. val = readl(bank->chip.regs + offset);
  1180. writel(val, bank->chip.regs + offset);
  1181. spin_unlock_irqrestore(&sgpio_lock, flags);
  1182. }
  1183. static void __sirfsoc_gpio_irq_mask(struct sirfsoc_gpio_bank *bank, int idx)
  1184. {
  1185. u32 val, offset;
  1186. unsigned long flags;
  1187. offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
  1188. spin_lock_irqsave(&sgpio_lock, flags);
  1189. val = readl(bank->chip.regs + offset);
  1190. val &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK;
  1191. val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK;
  1192. writel(val, bank->chip.regs + offset);
  1193. spin_unlock_irqrestore(&sgpio_lock, flags);
  1194. }
  1195. static void sirfsoc_gpio_irq_mask(struct irq_data *d)
  1196. {
  1197. struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
  1198. __sirfsoc_gpio_irq_mask(bank, d->hwirq % SIRFSOC_GPIO_BANK_SIZE);
  1199. }
  1200. static void sirfsoc_gpio_irq_unmask(struct irq_data *d)
  1201. {
  1202. struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
  1203. int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE;
  1204. u32 val, offset;
  1205. unsigned long flags;
  1206. offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
  1207. spin_lock_irqsave(&sgpio_lock, flags);
  1208. val = readl(bank->chip.regs + offset);
  1209. val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK;
  1210. val |= SIRFSOC_GPIO_CTL_INTR_EN_MASK;
  1211. writel(val, bank->chip.regs + offset);
  1212. spin_unlock_irqrestore(&sgpio_lock, flags);
  1213. }
  1214. static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type)
  1215. {
  1216. struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
  1217. int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE;
  1218. u32 val, offset;
  1219. unsigned long flags;
  1220. offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
  1221. spin_lock_irqsave(&sgpio_lock, flags);
  1222. val = readl(bank->chip.regs + offset);
  1223. val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK;
  1224. switch (type) {
  1225. case IRQ_TYPE_NONE:
  1226. break;
  1227. case IRQ_TYPE_EDGE_RISING:
  1228. val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK;
  1229. val &= ~SIRFSOC_GPIO_CTL_INTR_LOW_MASK;
  1230. break;
  1231. case IRQ_TYPE_EDGE_FALLING:
  1232. val &= ~SIRFSOC_GPIO_CTL_INTR_HIGH_MASK;
  1233. val |= SIRFSOC_GPIO_CTL_INTR_LOW_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK;
  1234. break;
  1235. case IRQ_TYPE_EDGE_BOTH:
  1236. val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_LOW_MASK |
  1237. SIRFSOC_GPIO_CTL_INTR_TYPE_MASK;
  1238. break;
  1239. case IRQ_TYPE_LEVEL_LOW:
  1240. val &= ~(SIRFSOC_GPIO_CTL_INTR_HIGH_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
  1241. val |= SIRFSOC_GPIO_CTL_INTR_LOW_MASK;
  1242. break;
  1243. case IRQ_TYPE_LEVEL_HIGH:
  1244. val |= SIRFSOC_GPIO_CTL_INTR_HIGH_MASK;
  1245. val &= ~(SIRFSOC_GPIO_CTL_INTR_LOW_MASK | SIRFSOC_GPIO_CTL_INTR_TYPE_MASK);
  1246. break;
  1247. }
  1248. writel(val, bank->chip.regs + offset);
  1249. spin_unlock_irqrestore(&sgpio_lock, flags);
  1250. return 0;
  1251. }
  1252. static struct irq_chip sirfsoc_irq_chip = {
  1253. .name = "sirf-gpio-irq",
  1254. .irq_ack = sirfsoc_gpio_irq_ack,
  1255. .irq_mask = sirfsoc_gpio_irq_mask,
  1256. .irq_unmask = sirfsoc_gpio_irq_unmask,
  1257. .irq_set_type = sirfsoc_gpio_irq_type,
  1258. };
  1259. static void sirfsoc_gpio_handle_irq(unsigned int irq, struct irq_desc *desc)
  1260. {
  1261. struct sirfsoc_gpio_bank *bank = irq_get_handler_data(irq);
  1262. u32 status, ctrl;
  1263. int idx = 0;
  1264. unsigned int first_irq;
  1265. struct irq_chip *chip = irq_get_chip(irq);
  1266. chained_irq_enter(chip, desc);
  1267. status = readl(bank->chip.regs + SIRFSOC_GPIO_INT_STATUS(bank->id));
  1268. if (!status) {
  1269. printk(KERN_WARNING
  1270. "%s: gpio id %d status %#x no interrupt is flaged\n",
  1271. __func__, bank->id, status);
  1272. handle_bad_irq(irq, desc);
  1273. return;
  1274. }
  1275. first_irq = bank->domain->revmap_data.legacy.first_irq;
  1276. while (status) {
  1277. ctrl = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, idx));
  1278. /*
  1279. * Here we must check whether the corresponding GPIO's interrupt
  1280. * has been enabled, otherwise just skip it
  1281. */
  1282. if ((status & 0x1) && (ctrl & SIRFSOC_GPIO_CTL_INTR_EN_MASK)) {
  1283. pr_debug("%s: gpio id %d idx %d happens\n",
  1284. __func__, bank->id, idx);
  1285. generic_handle_irq(first_irq + idx);
  1286. }
  1287. idx++;
  1288. status = status >> 1;
  1289. }
  1290. chained_irq_exit(chip, desc);
  1291. }
  1292. static inline void sirfsoc_gpio_set_input(struct sirfsoc_gpio_bank *bank, unsigned ctrl_offset)
  1293. {
  1294. u32 val;
  1295. val = readl(bank->chip.regs + ctrl_offset);
  1296. val &= ~SIRFSOC_GPIO_CTL_OUT_EN_MASK;
  1297. writel(val, bank->chip.regs + ctrl_offset);
  1298. }
  1299. static int sirfsoc_gpio_request(struct gpio_chip *chip, unsigned offset)
  1300. {
  1301. struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
  1302. unsigned long flags;
  1303. if (pinctrl_request_gpio(chip->base + offset))
  1304. return -ENODEV;
  1305. spin_lock_irqsave(&bank->lock, flags);
  1306. /*
  1307. * default status:
  1308. * set direction as input and mask irq
  1309. */
  1310. sirfsoc_gpio_set_input(bank, SIRFSOC_GPIO_CTRL(bank->id, offset));
  1311. __sirfsoc_gpio_irq_mask(bank, offset);
  1312. spin_unlock_irqrestore(&bank->lock, flags);
  1313. return 0;
  1314. }
  1315. static void sirfsoc_gpio_free(struct gpio_chip *chip, unsigned offset)
  1316. {
  1317. struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
  1318. unsigned long flags;
  1319. spin_lock_irqsave(&bank->lock, flags);
  1320. __sirfsoc_gpio_irq_mask(bank, offset);
  1321. sirfsoc_gpio_set_input(bank, SIRFSOC_GPIO_CTRL(bank->id, offset));
  1322. spin_unlock_irqrestore(&bank->lock, flags);
  1323. pinctrl_free_gpio(chip->base + offset);
  1324. }
  1325. static int sirfsoc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  1326. {
  1327. struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
  1328. int idx = sirfsoc_gpio_to_offset(gpio);
  1329. unsigned long flags;
  1330. unsigned offset;
  1331. offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
  1332. spin_lock_irqsave(&bank->lock, flags);
  1333. sirfsoc_gpio_set_input(bank, offset);
  1334. spin_unlock_irqrestore(&bank->lock, flags);
  1335. return 0;
  1336. }
  1337. static inline void sirfsoc_gpio_set_output(struct sirfsoc_gpio_bank *bank, unsigned offset,
  1338. int value)
  1339. {
  1340. u32 out_ctrl;
  1341. unsigned long flags;
  1342. spin_lock_irqsave(&bank->lock, flags);
  1343. out_ctrl = readl(bank->chip.regs + offset);
  1344. if (value)
  1345. out_ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK;
  1346. else
  1347. out_ctrl &= ~SIRFSOC_GPIO_CTL_DATAOUT_MASK;
  1348. out_ctrl &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK;
  1349. out_ctrl |= SIRFSOC_GPIO_CTL_OUT_EN_MASK;
  1350. writel(out_ctrl, bank->chip.regs + offset);
  1351. spin_unlock_irqrestore(&bank->lock, flags);
  1352. }
  1353. static int sirfsoc_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
  1354. {
  1355. struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
  1356. int idx = sirfsoc_gpio_to_offset(gpio);
  1357. u32 offset;
  1358. unsigned long flags;
  1359. offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
  1360. spin_lock_irqsave(&sgpio_lock, flags);
  1361. sirfsoc_gpio_set_output(bank, offset, value);
  1362. spin_unlock_irqrestore(&sgpio_lock, flags);
  1363. return 0;
  1364. }
  1365. static int sirfsoc_gpio_get_value(struct gpio_chip *chip, unsigned offset)
  1366. {
  1367. struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
  1368. u32 val;
  1369. unsigned long flags;
  1370. spin_lock_irqsave(&bank->lock, flags);
  1371. val = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset));
  1372. spin_unlock_irqrestore(&bank->lock, flags);
  1373. return !!(val & SIRFSOC_GPIO_CTL_DATAIN_MASK);
  1374. }
  1375. static void sirfsoc_gpio_set_value(struct gpio_chip *chip, unsigned offset,
  1376. int value)
  1377. {
  1378. struct sirfsoc_gpio_bank *bank = sirfsoc_irqchip_to_bank(chip);
  1379. u32 ctrl;
  1380. unsigned long flags;
  1381. spin_lock_irqsave(&bank->lock, flags);
  1382. ctrl = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset));
  1383. if (value)
  1384. ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK;
  1385. else
  1386. ctrl &= ~SIRFSOC_GPIO_CTL_DATAOUT_MASK;
  1387. writel(ctrl, bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset));
  1388. spin_unlock_irqrestore(&bank->lock, flags);
  1389. }
  1390. static int sirfsoc_gpio_irq_map(struct irq_domain *d, unsigned int irq,
  1391. irq_hw_number_t hwirq)
  1392. {
  1393. struct sirfsoc_gpio_bank *bank = d->host_data;
  1394. if (!bank)
  1395. return -EINVAL;
  1396. irq_set_chip(irq, &sirfsoc_irq_chip);
  1397. irq_set_handler(irq, handle_level_irq);
  1398. irq_set_chip_data(irq, bank);
  1399. set_irq_flags(irq, IRQF_VALID);
  1400. return 0;
  1401. }
  1402. const struct irq_domain_ops sirfsoc_gpio_irq_simple_ops = {
  1403. .map = sirfsoc_gpio_irq_map,
  1404. .xlate = irq_domain_xlate_twocell,
  1405. };
  1406. static void sirfsoc_gpio_set_pullup(const u32 *pullups)
  1407. {
  1408. int i, n;
  1409. const unsigned long *p = (const unsigned long *)pullups;
  1410. for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) {
  1411. n = find_first_bit(p + i, BITS_PER_LONG);
  1412. while (n < BITS_PER_LONG) {
  1413. u32 offset = SIRFSOC_GPIO_CTRL(i, n);
  1414. u32 val = readl(sgpio_bank[i].chip.regs + offset);
  1415. val |= SIRFSOC_GPIO_CTL_PULL_MASK;
  1416. val |= SIRFSOC_GPIO_CTL_PULL_HIGH;
  1417. writel(val, sgpio_bank[i].chip.regs + offset);
  1418. n = find_next_bit(p + i, BITS_PER_LONG, n + 1);
  1419. }
  1420. }
  1421. }
  1422. static void sirfsoc_gpio_set_pulldown(const u32 *pulldowns)
  1423. {
  1424. int i, n;
  1425. const unsigned long *p = (const unsigned long *)pulldowns;
  1426. for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) {
  1427. n = find_first_bit(p + i, BITS_PER_LONG);
  1428. while (n < BITS_PER_LONG) {
  1429. u32 offset = SIRFSOC_GPIO_CTRL(i, n);
  1430. u32 val = readl(sgpio_bank[i].chip.regs + offset);
  1431. val |= SIRFSOC_GPIO_CTL_PULL_MASK;
  1432. val &= ~SIRFSOC_GPIO_CTL_PULL_HIGH;
  1433. writel(val, sgpio_bank[i].chip.regs + offset);
  1434. n = find_next_bit(p + i, BITS_PER_LONG, n + 1);
  1435. }
  1436. }
  1437. }
  1438. static int sirfsoc_gpio_probe(struct device_node *np)
  1439. {
  1440. int i, err = 0;
  1441. struct sirfsoc_gpio_bank *bank;
  1442. void *regs;
  1443. struct platform_device *pdev;
  1444. bool is_marco = false;
  1445. u32 pullups[SIRFSOC_GPIO_NO_OF_BANKS], pulldowns[SIRFSOC_GPIO_NO_OF_BANKS];
  1446. pdev = of_find_device_by_node(np);
  1447. if (!pdev)
  1448. return -ENODEV;
  1449. regs = of_iomap(np, 0);
  1450. if (!regs)
  1451. return -ENOMEM;
  1452. if (of_device_is_compatible(np, "sirf,marco-pinctrl"))
  1453. is_marco = 1;
  1454. for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) {
  1455. bank = &sgpio_bank[i];
  1456. spin_lock_init(&bank->lock);
  1457. bank->chip.gc.request = sirfsoc_gpio_request;
  1458. bank->chip.gc.free = sirfsoc_gpio_free;
  1459. bank->chip.gc.direction_input = sirfsoc_gpio_direction_input;
  1460. bank->chip.gc.get = sirfsoc_gpio_get_value;
  1461. bank->chip.gc.direction_output = sirfsoc_gpio_direction_output;
  1462. bank->chip.gc.set = sirfsoc_gpio_set_value;
  1463. bank->chip.gc.to_irq = sirfsoc_gpio_to_irq;
  1464. bank->chip.gc.base = i * SIRFSOC_GPIO_BANK_SIZE;
  1465. bank->chip.gc.ngpio = SIRFSOC_GPIO_BANK_SIZE;
  1466. bank->chip.gc.label = kstrdup(np->full_name, GFP_KERNEL);
  1467. bank->chip.gc.of_node = np;
  1468. bank->chip.gc.of_xlate = sirfsoc_gpio_of_xlate;
  1469. bank->chip.gc.of_gpio_n_cells = 2;
  1470. bank->chip.regs = regs;
  1471. bank->id = i;
  1472. bank->is_marco = is_marco;
  1473. bank->parent_irq = platform_get_irq(pdev, i);
  1474. if (bank->parent_irq < 0) {
  1475. err = bank->parent_irq;
  1476. goto out;
  1477. }
  1478. err = gpiochip_add(&bank->chip.gc);
  1479. if (err) {
  1480. pr_err("%s: error in probe function with status %d\n",
  1481. np->full_name, err);
  1482. goto out;
  1483. }
  1484. bank->domain = irq_domain_add_legacy(np, SIRFSOC_GPIO_BANK_SIZE,
  1485. SIRFSOC_GPIO_IRQ_START + i * SIRFSOC_GPIO_BANK_SIZE, 0,
  1486. &sirfsoc_gpio_irq_simple_ops, bank);
  1487. if (!bank->domain) {
  1488. pr_err("%s: Failed to create irqdomain\n", np->full_name);
  1489. err = -ENOSYS;
  1490. goto out;
  1491. }
  1492. irq_set_chained_handler(bank->parent_irq, sirfsoc_gpio_handle_irq);
  1493. irq_set_handler_data(bank->parent_irq, bank);
  1494. }
  1495. if (!of_property_read_u32_array(np, "sirf,pullups", pullups,
  1496. SIRFSOC_GPIO_NO_OF_BANKS))
  1497. sirfsoc_gpio_set_pullup(pullups);
  1498. if (!of_property_read_u32_array(np, "sirf,pulldowns", pulldowns,
  1499. SIRFSOC_GPIO_NO_OF_BANKS))
  1500. sirfsoc_gpio_set_pulldown(pulldowns);
  1501. return 0;
  1502. out:
  1503. iounmap(regs);
  1504. return err;
  1505. }
  1506. static int __init sirfsoc_gpio_init(void)
  1507. {
  1508. struct device_node *np;
  1509. np = of_find_matching_node(NULL, pinmux_ids);
  1510. if (!np)
  1511. return -ENODEV;
  1512. return sirfsoc_gpio_probe(np);
  1513. }
  1514. subsys_initcall(sirfsoc_gpio_init);
  1515. MODULE_AUTHOR("Rongjun Ying <rongjun.ying@csr.com>, "
  1516. "Yuping Luo <yuping.luo@csr.com>, "
  1517. "Barry Song <baohua.song@csr.com>");
  1518. MODULE_DESCRIPTION("SIRFSOC pin control driver");
  1519. MODULE_LICENSE("GPL");