sa1111.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  1. /*
  2. * linux/arch/arm/common/sa1111.c
  3. *
  4. * SA1111 support
  5. *
  6. * Original code by John Dorsey
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This file contains all generic SA1111 support.
  13. *
  14. * All initialization functions provided here are intended to be called
  15. * from machine specific code with proper arguments when required.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/irq.h>
  20. #include <linux/kernel.h>
  21. #include <linux/delay.h>
  22. #include <linux/errno.h>
  23. #include <linux/ioport.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/dma-mapping.h>
  28. #include <linux/clk.h>
  29. #include <linux/io.h>
  30. #include <mach/hardware.h>
  31. #include <asm/mach/irq.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/sizes.h>
  34. #include <asm/hardware/sa1111.h>
  35. /* SA1111 IRQs */
  36. #define IRQ_GPAIN0 (0)
  37. #define IRQ_GPAIN1 (1)
  38. #define IRQ_GPAIN2 (2)
  39. #define IRQ_GPAIN3 (3)
  40. #define IRQ_GPBIN0 (4)
  41. #define IRQ_GPBIN1 (5)
  42. #define IRQ_GPBIN2 (6)
  43. #define IRQ_GPBIN3 (7)
  44. #define IRQ_GPBIN4 (8)
  45. #define IRQ_GPBIN5 (9)
  46. #define IRQ_GPCIN0 (10)
  47. #define IRQ_GPCIN1 (11)
  48. #define IRQ_GPCIN2 (12)
  49. #define IRQ_GPCIN3 (13)
  50. #define IRQ_GPCIN4 (14)
  51. #define IRQ_GPCIN5 (15)
  52. #define IRQ_GPCIN6 (16)
  53. #define IRQ_GPCIN7 (17)
  54. #define IRQ_MSTXINT (18)
  55. #define IRQ_MSRXINT (19)
  56. #define IRQ_MSSTOPERRINT (20)
  57. #define IRQ_TPTXINT (21)
  58. #define IRQ_TPRXINT (22)
  59. #define IRQ_TPSTOPERRINT (23)
  60. #define SSPXMTINT (24)
  61. #define SSPRCVINT (25)
  62. #define SSPROR (26)
  63. #define AUDXMTDMADONEA (32)
  64. #define AUDRCVDMADONEA (33)
  65. #define AUDXMTDMADONEB (34)
  66. #define AUDRCVDMADONEB (35)
  67. #define AUDTFSR (36)
  68. #define AUDRFSR (37)
  69. #define AUDTUR (38)
  70. #define AUDROR (39)
  71. #define AUDDTS (40)
  72. #define AUDRDD (41)
  73. #define AUDSTO (42)
  74. #define IRQ_USBPWR (43)
  75. #define IRQ_HCIM (44)
  76. #define IRQ_HCIBUFFACC (45)
  77. #define IRQ_HCIRMTWKP (46)
  78. #define IRQ_NHCIMFCIR (47)
  79. #define IRQ_USB_PORT_RESUME (48)
  80. #define IRQ_S0_READY_NINT (49)
  81. #define IRQ_S1_READY_NINT (50)
  82. #define IRQ_S0_CD_VALID (51)
  83. #define IRQ_S1_CD_VALID (52)
  84. #define IRQ_S0_BVD1_STSCHG (53)
  85. #define IRQ_S1_BVD1_STSCHG (54)
  86. #define SA1111_IRQ_NR (55)
  87. extern void sa1110_mb_enable(void);
  88. extern void sa1110_mb_disable(void);
  89. /*
  90. * We keep the following data for the overall SA1111. Note that the
  91. * struct device and struct resource are "fake"; they should be supplied
  92. * by the bus above us. However, in the interests of getting all SA1111
  93. * drivers converted over to the device model, we provide this as an
  94. * anchor point for all the other drivers.
  95. */
  96. struct sa1111 {
  97. struct device *dev;
  98. struct clk *clk;
  99. unsigned long phys;
  100. int irq;
  101. int irq_base; /* base for cascaded on-chip IRQs */
  102. spinlock_t lock;
  103. void __iomem *base;
  104. struct sa1111_platform_data *pdata;
  105. #ifdef CONFIG_PM
  106. void *saved_state;
  107. #endif
  108. };
  109. /*
  110. * We _really_ need to eliminate this. Its only users
  111. * are the PWM and DMA checking code.
  112. */
  113. static struct sa1111 *g_sa1111;
  114. struct sa1111_dev_info {
  115. unsigned long offset;
  116. unsigned long skpcr_mask;
  117. bool dma;
  118. unsigned int devid;
  119. unsigned int irq[6];
  120. };
  121. static struct sa1111_dev_info sa1111_devices[] = {
  122. {
  123. .offset = SA1111_USB,
  124. .skpcr_mask = SKPCR_UCLKEN,
  125. .dma = true,
  126. .devid = SA1111_DEVID_USB,
  127. .irq = {
  128. IRQ_USBPWR,
  129. IRQ_HCIM,
  130. IRQ_HCIBUFFACC,
  131. IRQ_HCIRMTWKP,
  132. IRQ_NHCIMFCIR,
  133. IRQ_USB_PORT_RESUME
  134. },
  135. },
  136. {
  137. .offset = 0x0600,
  138. .skpcr_mask = SKPCR_I2SCLKEN | SKPCR_L3CLKEN,
  139. .dma = true,
  140. .devid = SA1111_DEVID_SAC,
  141. .irq = {
  142. AUDXMTDMADONEA,
  143. AUDXMTDMADONEB,
  144. AUDRCVDMADONEA,
  145. AUDRCVDMADONEB
  146. },
  147. },
  148. {
  149. .offset = 0x0800,
  150. .skpcr_mask = SKPCR_SCLKEN,
  151. .devid = SA1111_DEVID_SSP,
  152. },
  153. {
  154. .offset = SA1111_KBD,
  155. .skpcr_mask = SKPCR_PTCLKEN,
  156. .devid = SA1111_DEVID_PS2_KBD,
  157. .irq = {
  158. IRQ_TPRXINT,
  159. IRQ_TPTXINT
  160. },
  161. },
  162. {
  163. .offset = SA1111_MSE,
  164. .skpcr_mask = SKPCR_PMCLKEN,
  165. .devid = SA1111_DEVID_PS2_MSE,
  166. .irq = {
  167. IRQ_MSRXINT,
  168. IRQ_MSTXINT
  169. },
  170. },
  171. {
  172. .offset = 0x1800,
  173. .skpcr_mask = 0,
  174. .devid = SA1111_DEVID_PCMCIA,
  175. .irq = {
  176. IRQ_S0_READY_NINT,
  177. IRQ_S0_CD_VALID,
  178. IRQ_S0_BVD1_STSCHG,
  179. IRQ_S1_READY_NINT,
  180. IRQ_S1_CD_VALID,
  181. IRQ_S1_BVD1_STSCHG,
  182. },
  183. },
  184. };
  185. /*
  186. * SA1111 interrupt support. Since clearing an IRQ while there are
  187. * active IRQs causes the interrupt output to pulse, the upper levels
  188. * will call us again if there are more interrupts to process.
  189. */
  190. static void sa1111_irq_handler(struct irq_desc *desc)
  191. {
  192. unsigned int stat0, stat1, i;
  193. struct sa1111 *sachip = irq_desc_get_handler_data(desc);
  194. void __iomem *mapbase = sachip->base + SA1111_INTC;
  195. stat0 = sa1111_readl(mapbase + SA1111_INTSTATCLR0);
  196. stat1 = sa1111_readl(mapbase + SA1111_INTSTATCLR1);
  197. sa1111_writel(stat0, mapbase + SA1111_INTSTATCLR0);
  198. desc->irq_data.chip->irq_ack(&desc->irq_data);
  199. sa1111_writel(stat1, mapbase + SA1111_INTSTATCLR1);
  200. if (stat0 == 0 && stat1 == 0) {
  201. do_bad_IRQ(desc);
  202. return;
  203. }
  204. for (i = 0; stat0; i++, stat0 >>= 1)
  205. if (stat0 & 1)
  206. generic_handle_irq(i + sachip->irq_base);
  207. for (i = 32; stat1; i++, stat1 >>= 1)
  208. if (stat1 & 1)
  209. generic_handle_irq(i + sachip->irq_base);
  210. /* For level-based interrupts */
  211. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  212. }
  213. #define SA1111_IRQMASK_LO(x) (1 << (x - sachip->irq_base))
  214. #define SA1111_IRQMASK_HI(x) (1 << (x - sachip->irq_base - 32))
  215. static void sa1111_ack_irq(struct irq_data *d)
  216. {
  217. }
  218. static void sa1111_mask_lowirq(struct irq_data *d)
  219. {
  220. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  221. void __iomem *mapbase = sachip->base + SA1111_INTC;
  222. unsigned long ie0;
  223. ie0 = sa1111_readl(mapbase + SA1111_INTEN0);
  224. ie0 &= ~SA1111_IRQMASK_LO(d->irq);
  225. writel(ie0, mapbase + SA1111_INTEN0);
  226. }
  227. static void sa1111_unmask_lowirq(struct irq_data *d)
  228. {
  229. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  230. void __iomem *mapbase = sachip->base + SA1111_INTC;
  231. unsigned long ie0;
  232. ie0 = sa1111_readl(mapbase + SA1111_INTEN0);
  233. ie0 |= SA1111_IRQMASK_LO(d->irq);
  234. sa1111_writel(ie0, mapbase + SA1111_INTEN0);
  235. }
  236. /*
  237. * Attempt to re-trigger the interrupt. The SA1111 contains a register
  238. * (INTSET) which claims to do this. However, in practice no amount of
  239. * manipulation of INTEN and INTSET guarantees that the interrupt will
  240. * be triggered. In fact, its very difficult, if not impossible to get
  241. * INTSET to re-trigger the interrupt.
  242. */
  243. static int sa1111_retrigger_lowirq(struct irq_data *d)
  244. {
  245. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  246. void __iomem *mapbase = sachip->base + SA1111_INTC;
  247. unsigned int mask = SA1111_IRQMASK_LO(d->irq);
  248. unsigned long ip0;
  249. int i;
  250. ip0 = sa1111_readl(mapbase + SA1111_INTPOL0);
  251. for (i = 0; i < 8; i++) {
  252. sa1111_writel(ip0 ^ mask, mapbase + SA1111_INTPOL0);
  253. sa1111_writel(ip0, mapbase + SA1111_INTPOL0);
  254. if (sa1111_readl(mapbase + SA1111_INTSTATCLR0) & mask)
  255. break;
  256. }
  257. if (i == 8)
  258. pr_err("Danger Will Robinson: failed to re-trigger IRQ%d\n",
  259. d->irq);
  260. return i == 8 ? -1 : 0;
  261. }
  262. static int sa1111_type_lowirq(struct irq_data *d, unsigned int flags)
  263. {
  264. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  265. void __iomem *mapbase = sachip->base + SA1111_INTC;
  266. unsigned int mask = SA1111_IRQMASK_LO(d->irq);
  267. unsigned long ip0;
  268. if (flags == IRQ_TYPE_PROBE)
  269. return 0;
  270. if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0)
  271. return -EINVAL;
  272. ip0 = sa1111_readl(mapbase + SA1111_INTPOL0);
  273. if (flags & IRQ_TYPE_EDGE_RISING)
  274. ip0 &= ~mask;
  275. else
  276. ip0 |= mask;
  277. sa1111_writel(ip0, mapbase + SA1111_INTPOL0);
  278. sa1111_writel(ip0, mapbase + SA1111_WAKEPOL0);
  279. return 0;
  280. }
  281. static int sa1111_wake_lowirq(struct irq_data *d, unsigned int on)
  282. {
  283. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  284. void __iomem *mapbase = sachip->base + SA1111_INTC;
  285. unsigned int mask = SA1111_IRQMASK_LO(d->irq);
  286. unsigned long we0;
  287. we0 = sa1111_readl(mapbase + SA1111_WAKEEN0);
  288. if (on)
  289. we0 |= mask;
  290. else
  291. we0 &= ~mask;
  292. sa1111_writel(we0, mapbase + SA1111_WAKEEN0);
  293. return 0;
  294. }
  295. static struct irq_chip sa1111_low_chip = {
  296. .name = "SA1111-l",
  297. .irq_ack = sa1111_ack_irq,
  298. .irq_mask = sa1111_mask_lowirq,
  299. .irq_unmask = sa1111_unmask_lowirq,
  300. .irq_retrigger = sa1111_retrigger_lowirq,
  301. .irq_set_type = sa1111_type_lowirq,
  302. .irq_set_wake = sa1111_wake_lowirq,
  303. };
  304. static void sa1111_mask_highirq(struct irq_data *d)
  305. {
  306. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  307. void __iomem *mapbase = sachip->base + SA1111_INTC;
  308. unsigned long ie1;
  309. ie1 = sa1111_readl(mapbase + SA1111_INTEN1);
  310. ie1 &= ~SA1111_IRQMASK_HI(d->irq);
  311. sa1111_writel(ie1, mapbase + SA1111_INTEN1);
  312. }
  313. static void sa1111_unmask_highirq(struct irq_data *d)
  314. {
  315. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  316. void __iomem *mapbase = sachip->base + SA1111_INTC;
  317. unsigned long ie1;
  318. ie1 = sa1111_readl(mapbase + SA1111_INTEN1);
  319. ie1 |= SA1111_IRQMASK_HI(d->irq);
  320. sa1111_writel(ie1, mapbase + SA1111_INTEN1);
  321. }
  322. /*
  323. * Attempt to re-trigger the interrupt. The SA1111 contains a register
  324. * (INTSET) which claims to do this. However, in practice no amount of
  325. * manipulation of INTEN and INTSET guarantees that the interrupt will
  326. * be triggered. In fact, its very difficult, if not impossible to get
  327. * INTSET to re-trigger the interrupt.
  328. */
  329. static int sa1111_retrigger_highirq(struct irq_data *d)
  330. {
  331. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  332. void __iomem *mapbase = sachip->base + SA1111_INTC;
  333. unsigned int mask = SA1111_IRQMASK_HI(d->irq);
  334. unsigned long ip1;
  335. int i;
  336. ip1 = sa1111_readl(mapbase + SA1111_INTPOL1);
  337. for (i = 0; i < 8; i++) {
  338. sa1111_writel(ip1 ^ mask, mapbase + SA1111_INTPOL1);
  339. sa1111_writel(ip1, mapbase + SA1111_INTPOL1);
  340. if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask)
  341. break;
  342. }
  343. if (i == 8)
  344. pr_err("Danger Will Robinson: failed to re-trigger IRQ%d\n",
  345. d->irq);
  346. return i == 8 ? -1 : 0;
  347. }
  348. static int sa1111_type_highirq(struct irq_data *d, unsigned int flags)
  349. {
  350. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  351. void __iomem *mapbase = sachip->base + SA1111_INTC;
  352. unsigned int mask = SA1111_IRQMASK_HI(d->irq);
  353. unsigned long ip1;
  354. if (flags == IRQ_TYPE_PROBE)
  355. return 0;
  356. if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0)
  357. return -EINVAL;
  358. ip1 = sa1111_readl(mapbase + SA1111_INTPOL1);
  359. if (flags & IRQ_TYPE_EDGE_RISING)
  360. ip1 &= ~mask;
  361. else
  362. ip1 |= mask;
  363. sa1111_writel(ip1, mapbase + SA1111_INTPOL1);
  364. sa1111_writel(ip1, mapbase + SA1111_WAKEPOL1);
  365. return 0;
  366. }
  367. static int sa1111_wake_highirq(struct irq_data *d, unsigned int on)
  368. {
  369. struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
  370. void __iomem *mapbase = sachip->base + SA1111_INTC;
  371. unsigned int mask = SA1111_IRQMASK_HI(d->irq);
  372. unsigned long we1;
  373. we1 = sa1111_readl(mapbase + SA1111_WAKEEN1);
  374. if (on)
  375. we1 |= mask;
  376. else
  377. we1 &= ~mask;
  378. sa1111_writel(we1, mapbase + SA1111_WAKEEN1);
  379. return 0;
  380. }
  381. static struct irq_chip sa1111_high_chip = {
  382. .name = "SA1111-h",
  383. .irq_ack = sa1111_ack_irq,
  384. .irq_mask = sa1111_mask_highirq,
  385. .irq_unmask = sa1111_unmask_highirq,
  386. .irq_retrigger = sa1111_retrigger_highirq,
  387. .irq_set_type = sa1111_type_highirq,
  388. .irq_set_wake = sa1111_wake_highirq,
  389. };
  390. static int sa1111_setup_irq(struct sa1111 *sachip, unsigned irq_base)
  391. {
  392. void __iomem *irqbase = sachip->base + SA1111_INTC;
  393. unsigned i, irq;
  394. int ret;
  395. /*
  396. * We're guaranteed that this region hasn't been taken.
  397. */
  398. request_mem_region(sachip->phys + SA1111_INTC, 512, "irq");
  399. ret = irq_alloc_descs(-1, irq_base, SA1111_IRQ_NR, -1);
  400. if (ret <= 0) {
  401. dev_err(sachip->dev, "unable to allocate %u irqs: %d\n",
  402. SA1111_IRQ_NR, ret);
  403. if (ret == 0)
  404. ret = -EINVAL;
  405. return ret;
  406. }
  407. sachip->irq_base = ret;
  408. /* disable all IRQs */
  409. sa1111_writel(0, irqbase + SA1111_INTEN0);
  410. sa1111_writel(0, irqbase + SA1111_INTEN1);
  411. sa1111_writel(0, irqbase + SA1111_WAKEEN0);
  412. sa1111_writel(0, irqbase + SA1111_WAKEEN1);
  413. /*
  414. * detect on rising edge. Note: Feb 2001 Errata for SA1111
  415. * specifies that S0ReadyInt and S1ReadyInt should be '1'.
  416. */
  417. sa1111_writel(0, irqbase + SA1111_INTPOL0);
  418. sa1111_writel(BIT(IRQ_S0_READY_NINT & 31) |
  419. BIT(IRQ_S1_READY_NINT & 31),
  420. irqbase + SA1111_INTPOL1);
  421. /* clear all IRQs */
  422. sa1111_writel(~0, irqbase + SA1111_INTSTATCLR0);
  423. sa1111_writel(~0, irqbase + SA1111_INTSTATCLR1);
  424. for (i = IRQ_GPAIN0; i <= SSPROR; i++) {
  425. irq = sachip->irq_base + i;
  426. irq_set_chip_and_handler(irq, &sa1111_low_chip,
  427. handle_edge_irq);
  428. irq_set_chip_data(irq, sachip);
  429. irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
  430. }
  431. for (i = AUDXMTDMADONEA; i <= IRQ_S1_BVD1_STSCHG; i++) {
  432. irq = sachip->irq_base + i;
  433. irq_set_chip_and_handler(irq, &sa1111_high_chip,
  434. handle_edge_irq);
  435. irq_set_chip_data(irq, sachip);
  436. irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
  437. }
  438. /*
  439. * Register SA1111 interrupt
  440. */
  441. irq_set_irq_type(sachip->irq, IRQ_TYPE_EDGE_RISING);
  442. irq_set_chained_handler_and_data(sachip->irq, sa1111_irq_handler,
  443. sachip);
  444. dev_info(sachip->dev, "Providing IRQ%u-%u\n",
  445. sachip->irq_base, sachip->irq_base + SA1111_IRQ_NR - 1);
  446. return 0;
  447. }
  448. /*
  449. * Bring the SA1111 out of reset. This requires a set procedure:
  450. * 1. nRESET asserted (by hardware)
  451. * 2. CLK turned on from SA1110
  452. * 3. nRESET deasserted
  453. * 4. VCO turned on, PLL_BYPASS turned off
  454. * 5. Wait lock time, then assert RCLKEn
  455. * 7. PCR set to allow clocking of individual functions
  456. *
  457. * Until we've done this, the only registers we can access are:
  458. * SBI_SKCR
  459. * SBI_SMCR
  460. * SBI_SKID
  461. */
  462. static void sa1111_wake(struct sa1111 *sachip)
  463. {
  464. unsigned long flags, r;
  465. spin_lock_irqsave(&sachip->lock, flags);
  466. clk_enable(sachip->clk);
  467. /*
  468. * Turn VCO on, and disable PLL Bypass.
  469. */
  470. r = sa1111_readl(sachip->base + SA1111_SKCR);
  471. r &= ~SKCR_VCO_OFF;
  472. sa1111_writel(r, sachip->base + SA1111_SKCR);
  473. r |= SKCR_PLL_BYPASS | SKCR_OE_EN;
  474. sa1111_writel(r, sachip->base + SA1111_SKCR);
  475. /*
  476. * Wait lock time. SA1111 manual _doesn't_
  477. * specify a figure for this! We choose 100us.
  478. */
  479. udelay(100);
  480. /*
  481. * Enable RCLK. We also ensure that RDYEN is set.
  482. */
  483. r |= SKCR_RCLKEN | SKCR_RDYEN;
  484. sa1111_writel(r, sachip->base + SA1111_SKCR);
  485. /*
  486. * Wait 14 RCLK cycles for the chip to finish coming out
  487. * of reset. (RCLK=24MHz). This is 590ns.
  488. */
  489. udelay(1);
  490. /*
  491. * Ensure all clocks are initially off.
  492. */
  493. sa1111_writel(0, sachip->base + SA1111_SKPCR);
  494. spin_unlock_irqrestore(&sachip->lock, flags);
  495. }
  496. #ifdef CONFIG_ARCH_SA1100
  497. static u32 sa1111_dma_mask[] = {
  498. ~0,
  499. ~(1 << 20),
  500. ~(1 << 23),
  501. ~(1 << 24),
  502. ~(1 << 25),
  503. ~(1 << 20),
  504. ~(1 << 20),
  505. 0,
  506. };
  507. /*
  508. * Configure the SA1111 shared memory controller.
  509. */
  510. void
  511. sa1111_configure_smc(struct sa1111 *sachip, int sdram, unsigned int drac,
  512. unsigned int cas_latency)
  513. {
  514. unsigned int smcr = SMCR_DTIM | SMCR_MBGE | FInsrt(drac, SMCR_DRAC);
  515. if (cas_latency == 3)
  516. smcr |= SMCR_CLAT;
  517. sa1111_writel(smcr, sachip->base + SA1111_SMCR);
  518. /*
  519. * Now clear the bits in the DMA mask to work around the SA1111
  520. * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion
  521. * Chip Specification Update, June 2000, Erratum #7).
  522. */
  523. if (sachip->dev->dma_mask)
  524. *sachip->dev->dma_mask &= sa1111_dma_mask[drac >> 2];
  525. sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2];
  526. }
  527. #endif
  528. static void sa1111_dev_release(struct device *_dev)
  529. {
  530. struct sa1111_dev *dev = SA1111_DEV(_dev);
  531. kfree(dev);
  532. }
  533. static int
  534. sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
  535. struct sa1111_dev_info *info)
  536. {
  537. struct sa1111_dev *dev;
  538. unsigned i;
  539. int ret;
  540. dev = kzalloc(sizeof(struct sa1111_dev), GFP_KERNEL);
  541. if (!dev) {
  542. ret = -ENOMEM;
  543. goto err_alloc;
  544. }
  545. device_initialize(&dev->dev);
  546. dev_set_name(&dev->dev, "%4.4lx", info->offset);
  547. dev->devid = info->devid;
  548. dev->dev.parent = sachip->dev;
  549. dev->dev.bus = &sa1111_bus_type;
  550. dev->dev.release = sa1111_dev_release;
  551. dev->res.start = sachip->phys + info->offset;
  552. dev->res.end = dev->res.start + 511;
  553. dev->res.name = dev_name(&dev->dev);
  554. dev->res.flags = IORESOURCE_MEM;
  555. dev->mapbase = sachip->base + info->offset;
  556. dev->skpcr_mask = info->skpcr_mask;
  557. for (i = 0; i < ARRAY_SIZE(info->irq); i++)
  558. dev->irq[i] = sachip->irq_base + info->irq[i];
  559. /*
  560. * If the parent device has a DMA mask associated with it, and
  561. * this child supports DMA, propagate it down to the children.
  562. */
  563. if (info->dma && sachip->dev->dma_mask) {
  564. dev->dma_mask = *sachip->dev->dma_mask;
  565. dev->dev.dma_mask = &dev->dma_mask;
  566. dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask;
  567. }
  568. ret = request_resource(parent, &dev->res);
  569. if (ret) {
  570. dev_err(sachip->dev, "failed to allocate resource for %s\n",
  571. dev->res.name);
  572. goto err_resource;
  573. }
  574. ret = device_add(&dev->dev);
  575. if (ret)
  576. goto err_add;
  577. return 0;
  578. err_add:
  579. release_resource(&dev->res);
  580. err_resource:
  581. put_device(&dev->dev);
  582. err_alloc:
  583. return ret;
  584. }
  585. /**
  586. * sa1111_probe - probe for a single SA1111 chip.
  587. * @phys_addr: physical address of device.
  588. *
  589. * Probe for a SA1111 chip. This must be called
  590. * before any other SA1111-specific code.
  591. *
  592. * Returns:
  593. * %-ENODEV device not found.
  594. * %-EBUSY physical address already marked in-use.
  595. * %-EINVAL no platform data passed
  596. * %0 successful.
  597. */
  598. static int __sa1111_probe(struct device *me, struct resource *mem, int irq)
  599. {
  600. struct sa1111_platform_data *pd = me->platform_data;
  601. struct sa1111 *sachip;
  602. unsigned long id;
  603. unsigned int has_devs;
  604. int i, ret = -ENODEV;
  605. if (!pd)
  606. return -EINVAL;
  607. sachip = kzalloc(sizeof(struct sa1111), GFP_KERNEL);
  608. if (!sachip)
  609. return -ENOMEM;
  610. sachip->clk = clk_get(me, "SA1111_CLK");
  611. if (IS_ERR(sachip->clk)) {
  612. ret = PTR_ERR(sachip->clk);
  613. goto err_free;
  614. }
  615. ret = clk_prepare(sachip->clk);
  616. if (ret)
  617. goto err_clkput;
  618. spin_lock_init(&sachip->lock);
  619. sachip->dev = me;
  620. dev_set_drvdata(sachip->dev, sachip);
  621. sachip->pdata = pd;
  622. sachip->phys = mem->start;
  623. sachip->irq = irq;
  624. /*
  625. * Map the whole region. This also maps the
  626. * registers for our children.
  627. */
  628. sachip->base = ioremap(mem->start, PAGE_SIZE * 2);
  629. if (!sachip->base) {
  630. ret = -ENOMEM;
  631. goto err_clk_unprep;
  632. }
  633. /*
  634. * Probe for the chip. Only touch the SBI registers.
  635. */
  636. id = sa1111_readl(sachip->base + SA1111_SKID);
  637. if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
  638. printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id);
  639. ret = -ENODEV;
  640. goto err_unmap;
  641. }
  642. pr_info("SA1111 Microprocessor Companion Chip: silicon revision %lx, metal revision %lx\n",
  643. (id & SKID_SIREV_MASK) >> 4, id & SKID_MTREV_MASK);
  644. /*
  645. * We found it. Wake the chip up, and initialise.
  646. */
  647. sa1111_wake(sachip);
  648. /*
  649. * The interrupt controller must be initialised before any
  650. * other device to ensure that the interrupts are available.
  651. */
  652. if (sachip->irq != NO_IRQ) {
  653. ret = sa1111_setup_irq(sachip, pd->irq_base);
  654. if (ret)
  655. goto err_clk;
  656. }
  657. #ifdef CONFIG_ARCH_SA1100
  658. {
  659. unsigned int val;
  660. /*
  661. * The SDRAM configuration of the SA1110 and the SA1111 must
  662. * match. This is very important to ensure that SA1111 accesses
  663. * don't corrupt the SDRAM. Note that this ungates the SA1111's
  664. * MBGNT signal, so we must have called sa1110_mb_disable()
  665. * beforehand.
  666. */
  667. sa1111_configure_smc(sachip, 1,
  668. FExtr(MDCNFG, MDCNFG_SA1110_DRAC0),
  669. FExtr(MDCNFG, MDCNFG_SA1110_TDL0));
  670. /*
  671. * We only need to turn on DCLK whenever we want to use the
  672. * DMA. It can otherwise be held firmly in the off position.
  673. * (currently, we always enable it.)
  674. */
  675. val = sa1111_readl(sachip->base + SA1111_SKPCR);
  676. sa1111_writel(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR);
  677. /*
  678. * Enable the SA1110 memory bus request and grant signals.
  679. */
  680. sa1110_mb_enable();
  681. }
  682. #endif
  683. g_sa1111 = sachip;
  684. has_devs = ~0;
  685. if (pd)
  686. has_devs &= ~pd->disable_devs;
  687. for (i = 0; i < ARRAY_SIZE(sa1111_devices); i++)
  688. if (sa1111_devices[i].devid & has_devs)
  689. sa1111_init_one_child(sachip, mem, &sa1111_devices[i]);
  690. return 0;
  691. err_clk:
  692. clk_disable(sachip->clk);
  693. err_unmap:
  694. iounmap(sachip->base);
  695. err_clk_unprep:
  696. clk_unprepare(sachip->clk);
  697. err_clkput:
  698. clk_put(sachip->clk);
  699. err_free:
  700. kfree(sachip);
  701. return ret;
  702. }
  703. static int sa1111_remove_one(struct device *dev, void *data)
  704. {
  705. struct sa1111_dev *sadev = SA1111_DEV(dev);
  706. device_del(&sadev->dev);
  707. release_resource(&sadev->res);
  708. put_device(&sadev->dev);
  709. return 0;
  710. }
  711. static void __sa1111_remove(struct sa1111 *sachip)
  712. {
  713. void __iomem *irqbase = sachip->base + SA1111_INTC;
  714. device_for_each_child(sachip->dev, NULL, sa1111_remove_one);
  715. /* disable all IRQs */
  716. sa1111_writel(0, irqbase + SA1111_INTEN0);
  717. sa1111_writel(0, irqbase + SA1111_INTEN1);
  718. sa1111_writel(0, irqbase + SA1111_WAKEEN0);
  719. sa1111_writel(0, irqbase + SA1111_WAKEEN1);
  720. clk_disable(sachip->clk);
  721. clk_unprepare(sachip->clk);
  722. if (sachip->irq != NO_IRQ) {
  723. irq_set_chained_handler_and_data(sachip->irq, NULL, NULL);
  724. irq_free_descs(sachip->irq_base, SA1111_IRQ_NR);
  725. release_mem_region(sachip->phys + SA1111_INTC, 512);
  726. }
  727. iounmap(sachip->base);
  728. clk_put(sachip->clk);
  729. kfree(sachip);
  730. }
  731. struct sa1111_save_data {
  732. unsigned int skcr;
  733. unsigned int skpcr;
  734. unsigned int skcdr;
  735. unsigned char skaud;
  736. unsigned char skpwm0;
  737. unsigned char skpwm1;
  738. /*
  739. * Interrupt controller
  740. */
  741. unsigned int intpol0;
  742. unsigned int intpol1;
  743. unsigned int inten0;
  744. unsigned int inten1;
  745. unsigned int wakepol0;
  746. unsigned int wakepol1;
  747. unsigned int wakeen0;
  748. unsigned int wakeen1;
  749. };
  750. #ifdef CONFIG_PM
  751. static int sa1111_suspend_noirq(struct device *dev)
  752. {
  753. struct sa1111 *sachip = dev_get_drvdata(dev);
  754. struct sa1111_save_data *save;
  755. unsigned long flags;
  756. unsigned int val;
  757. void __iomem *base;
  758. save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL);
  759. if (!save)
  760. return -ENOMEM;
  761. sachip->saved_state = save;
  762. spin_lock_irqsave(&sachip->lock, flags);
  763. /*
  764. * Save state.
  765. */
  766. base = sachip->base;
  767. save->skcr = sa1111_readl(base + SA1111_SKCR);
  768. save->skpcr = sa1111_readl(base + SA1111_SKPCR);
  769. save->skcdr = sa1111_readl(base + SA1111_SKCDR);
  770. save->skaud = sa1111_readl(base + SA1111_SKAUD);
  771. save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0);
  772. save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1);
  773. sa1111_writel(0, sachip->base + SA1111_SKPWM0);
  774. sa1111_writel(0, sachip->base + SA1111_SKPWM1);
  775. base = sachip->base + SA1111_INTC;
  776. save->intpol0 = sa1111_readl(base + SA1111_INTPOL0);
  777. save->intpol1 = sa1111_readl(base + SA1111_INTPOL1);
  778. save->inten0 = sa1111_readl(base + SA1111_INTEN0);
  779. save->inten1 = sa1111_readl(base + SA1111_INTEN1);
  780. save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0);
  781. save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1);
  782. save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0);
  783. save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1);
  784. /*
  785. * Disable.
  786. */
  787. val = sa1111_readl(sachip->base + SA1111_SKCR);
  788. sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR);
  789. clk_disable(sachip->clk);
  790. spin_unlock_irqrestore(&sachip->lock, flags);
  791. #ifdef CONFIG_ARCH_SA1100
  792. sa1110_mb_disable();
  793. #endif
  794. return 0;
  795. }
  796. /*
  797. * sa1111_resume - Restore the SA1111 device state.
  798. * @dev: device to restore
  799. *
  800. * Restore the general state of the SA1111; clock control and
  801. * interrupt controller. Other parts of the SA1111 must be
  802. * restored by their respective drivers, and must be called
  803. * via LDM after this function.
  804. */
  805. static int sa1111_resume_noirq(struct device *dev)
  806. {
  807. struct sa1111 *sachip = dev_get_drvdata(dev);
  808. struct sa1111_save_data *save;
  809. unsigned long flags, id;
  810. void __iomem *base;
  811. save = sachip->saved_state;
  812. if (!save)
  813. return 0;
  814. /*
  815. * Ensure that the SA1111 is still here.
  816. * FIXME: shouldn't do this here.
  817. */
  818. id = sa1111_readl(sachip->base + SA1111_SKID);
  819. if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
  820. __sa1111_remove(sachip);
  821. dev_set_drvdata(dev, NULL);
  822. kfree(save);
  823. return 0;
  824. }
  825. /*
  826. * First of all, wake up the chip.
  827. */
  828. sa1111_wake(sachip);
  829. #ifdef CONFIG_ARCH_SA1100
  830. /* Enable the memory bus request/grant signals */
  831. sa1110_mb_enable();
  832. #endif
  833. /*
  834. * Only lock for write ops. Also, sa1111_wake must be called with
  835. * released spinlock!
  836. */
  837. spin_lock_irqsave(&sachip->lock, flags);
  838. sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0);
  839. sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1);
  840. base = sachip->base;
  841. sa1111_writel(save->skcr, base + SA1111_SKCR);
  842. sa1111_writel(save->skpcr, base + SA1111_SKPCR);
  843. sa1111_writel(save->skcdr, base + SA1111_SKCDR);
  844. sa1111_writel(save->skaud, base + SA1111_SKAUD);
  845. sa1111_writel(save->skpwm0, base + SA1111_SKPWM0);
  846. sa1111_writel(save->skpwm1, base + SA1111_SKPWM1);
  847. base = sachip->base + SA1111_INTC;
  848. sa1111_writel(save->intpol0, base + SA1111_INTPOL0);
  849. sa1111_writel(save->intpol1, base + SA1111_INTPOL1);
  850. sa1111_writel(save->inten0, base + SA1111_INTEN0);
  851. sa1111_writel(save->inten1, base + SA1111_INTEN1);
  852. sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0);
  853. sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1);
  854. sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0);
  855. sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1);
  856. spin_unlock_irqrestore(&sachip->lock, flags);
  857. sachip->saved_state = NULL;
  858. kfree(save);
  859. return 0;
  860. }
  861. #else
  862. #define sa1111_suspend_noirq NULL
  863. #define sa1111_resume_noirq NULL
  864. #endif
  865. static int sa1111_probe(struct platform_device *pdev)
  866. {
  867. struct resource *mem;
  868. int irq;
  869. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  870. if (!mem)
  871. return -EINVAL;
  872. irq = platform_get_irq(pdev, 0);
  873. if (irq < 0)
  874. return irq;
  875. return __sa1111_probe(&pdev->dev, mem, irq);
  876. }
  877. static int sa1111_remove(struct platform_device *pdev)
  878. {
  879. struct sa1111 *sachip = platform_get_drvdata(pdev);
  880. if (sachip) {
  881. #ifdef CONFIG_PM
  882. kfree(sachip->saved_state);
  883. sachip->saved_state = NULL;
  884. #endif
  885. __sa1111_remove(sachip);
  886. platform_set_drvdata(pdev, NULL);
  887. }
  888. return 0;
  889. }
  890. static struct dev_pm_ops sa1111_pm_ops = {
  891. .suspend_noirq = sa1111_suspend_noirq,
  892. .resume_noirq = sa1111_resume_noirq,
  893. };
  894. /*
  895. * Not sure if this should be on the system bus or not yet.
  896. * We really want some way to register a system device at
  897. * the per-machine level, and then have this driver pick
  898. * up the registered devices.
  899. *
  900. * We also need to handle the SDRAM configuration for
  901. * PXA250/SA1110 machine classes.
  902. */
  903. static struct platform_driver sa1111_device_driver = {
  904. .probe = sa1111_probe,
  905. .remove = sa1111_remove,
  906. .driver = {
  907. .name = "sa1111",
  908. .pm = &sa1111_pm_ops,
  909. },
  910. };
  911. /*
  912. * Get the parent device driver (us) structure
  913. * from a child function device
  914. */
  915. static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev)
  916. {
  917. return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent);
  918. }
  919. /*
  920. * The bits in the opdiv field are non-linear.
  921. */
  922. static unsigned char opdiv_table[] = { 1, 4, 2, 8 };
  923. static unsigned int __sa1111_pll_clock(struct sa1111 *sachip)
  924. {
  925. unsigned int skcdr, fbdiv, ipdiv, opdiv;
  926. skcdr = sa1111_readl(sachip->base + SA1111_SKCDR);
  927. fbdiv = (skcdr & 0x007f) + 2;
  928. ipdiv = ((skcdr & 0x0f80) >> 7) + 2;
  929. opdiv = opdiv_table[(skcdr & 0x3000) >> 12];
  930. return 3686400 * fbdiv / (ipdiv * opdiv);
  931. }
  932. /**
  933. * sa1111_pll_clock - return the current PLL clock frequency.
  934. * @sadev: SA1111 function block
  935. *
  936. * BUG: we should look at SKCR. We also blindly believe that
  937. * the chip is being fed with the 3.6864MHz clock.
  938. *
  939. * Returns the PLL clock in Hz.
  940. */
  941. unsigned int sa1111_pll_clock(struct sa1111_dev *sadev)
  942. {
  943. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  944. return __sa1111_pll_clock(sachip);
  945. }
  946. EXPORT_SYMBOL(sa1111_pll_clock);
  947. /**
  948. * sa1111_select_audio_mode - select I2S or AC link mode
  949. * @sadev: SA1111 function block
  950. * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S
  951. *
  952. * Frob the SKCR to select AC Link mode or I2S mode for
  953. * the audio block.
  954. */
  955. void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode)
  956. {
  957. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  958. unsigned long flags;
  959. unsigned int val;
  960. spin_lock_irqsave(&sachip->lock, flags);
  961. val = sa1111_readl(sachip->base + SA1111_SKCR);
  962. if (mode == SA1111_AUDIO_I2S) {
  963. val &= ~SKCR_SELAC;
  964. } else {
  965. val |= SKCR_SELAC;
  966. }
  967. sa1111_writel(val, sachip->base + SA1111_SKCR);
  968. spin_unlock_irqrestore(&sachip->lock, flags);
  969. }
  970. EXPORT_SYMBOL(sa1111_select_audio_mode);
  971. /**
  972. * sa1111_set_audio_rate - set the audio sample rate
  973. * @sadev: SA1111 SAC function block
  974. * @rate: sample rate to select
  975. */
  976. int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate)
  977. {
  978. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  979. unsigned int div;
  980. if (sadev->devid != SA1111_DEVID_SAC)
  981. return -EINVAL;
  982. div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate;
  983. if (div == 0)
  984. div = 1;
  985. if (div > 128)
  986. div = 128;
  987. sa1111_writel(div - 1, sachip->base + SA1111_SKAUD);
  988. return 0;
  989. }
  990. EXPORT_SYMBOL(sa1111_set_audio_rate);
  991. /**
  992. * sa1111_get_audio_rate - get the audio sample rate
  993. * @sadev: SA1111 SAC function block device
  994. */
  995. int sa1111_get_audio_rate(struct sa1111_dev *sadev)
  996. {
  997. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  998. unsigned long div;
  999. if (sadev->devid != SA1111_DEVID_SAC)
  1000. return -EINVAL;
  1001. div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1;
  1002. return __sa1111_pll_clock(sachip) / (256 * div);
  1003. }
  1004. EXPORT_SYMBOL(sa1111_get_audio_rate);
  1005. void sa1111_set_io_dir(struct sa1111_dev *sadev,
  1006. unsigned int bits, unsigned int dir,
  1007. unsigned int sleep_dir)
  1008. {
  1009. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  1010. unsigned long flags;
  1011. unsigned int val;
  1012. void __iomem *gpio = sachip->base + SA1111_GPIO;
  1013. #define MODIFY_BITS(port, mask, dir) \
  1014. if (mask) { \
  1015. val = sa1111_readl(port); \
  1016. val &= ~(mask); \
  1017. val |= (dir) & (mask); \
  1018. sa1111_writel(val, port); \
  1019. }
  1020. spin_lock_irqsave(&sachip->lock, flags);
  1021. MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir);
  1022. MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8);
  1023. MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16);
  1024. MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir);
  1025. MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8);
  1026. MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16);
  1027. spin_unlock_irqrestore(&sachip->lock, flags);
  1028. }
  1029. EXPORT_SYMBOL(sa1111_set_io_dir);
  1030. void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
  1031. {
  1032. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  1033. unsigned long flags;
  1034. unsigned int val;
  1035. void __iomem *gpio = sachip->base + SA1111_GPIO;
  1036. spin_lock_irqsave(&sachip->lock, flags);
  1037. MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v);
  1038. MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8);
  1039. MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16);
  1040. spin_unlock_irqrestore(&sachip->lock, flags);
  1041. }
  1042. EXPORT_SYMBOL(sa1111_set_io);
  1043. void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
  1044. {
  1045. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  1046. unsigned long flags;
  1047. unsigned int val;
  1048. void __iomem *gpio = sachip->base + SA1111_GPIO;
  1049. spin_lock_irqsave(&sachip->lock, flags);
  1050. MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v);
  1051. MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8);
  1052. MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16);
  1053. spin_unlock_irqrestore(&sachip->lock, flags);
  1054. }
  1055. EXPORT_SYMBOL(sa1111_set_sleep_io);
  1056. /*
  1057. * Individual device operations.
  1058. */
  1059. /**
  1060. * sa1111_enable_device - enable an on-chip SA1111 function block
  1061. * @sadev: SA1111 function block device to enable
  1062. */
  1063. int sa1111_enable_device(struct sa1111_dev *sadev)
  1064. {
  1065. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  1066. unsigned long flags;
  1067. unsigned int val;
  1068. int ret = 0;
  1069. if (sachip->pdata && sachip->pdata->enable)
  1070. ret = sachip->pdata->enable(sachip->pdata->data, sadev->devid);
  1071. if (ret == 0) {
  1072. spin_lock_irqsave(&sachip->lock, flags);
  1073. val = sa1111_readl(sachip->base + SA1111_SKPCR);
  1074. sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
  1075. spin_unlock_irqrestore(&sachip->lock, flags);
  1076. }
  1077. return ret;
  1078. }
  1079. EXPORT_SYMBOL(sa1111_enable_device);
  1080. /**
  1081. * sa1111_disable_device - disable an on-chip SA1111 function block
  1082. * @sadev: SA1111 function block device to disable
  1083. */
  1084. void sa1111_disable_device(struct sa1111_dev *sadev)
  1085. {
  1086. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  1087. unsigned long flags;
  1088. unsigned int val;
  1089. spin_lock_irqsave(&sachip->lock, flags);
  1090. val = sa1111_readl(sachip->base + SA1111_SKPCR);
  1091. sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
  1092. spin_unlock_irqrestore(&sachip->lock, flags);
  1093. if (sachip->pdata && sachip->pdata->disable)
  1094. sachip->pdata->disable(sachip->pdata->data, sadev->devid);
  1095. }
  1096. EXPORT_SYMBOL(sa1111_disable_device);
  1097. /*
  1098. * SA1111 "Register Access Bus."
  1099. *
  1100. * We model this as a regular bus type, and hang devices directly
  1101. * off this.
  1102. */
  1103. static int sa1111_match(struct device *_dev, struct device_driver *_drv)
  1104. {
  1105. struct sa1111_dev *dev = SA1111_DEV(_dev);
  1106. struct sa1111_driver *drv = SA1111_DRV(_drv);
  1107. return !!(dev->devid & drv->devid);
  1108. }
  1109. static int sa1111_bus_suspend(struct device *dev, pm_message_t state)
  1110. {
  1111. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1112. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1113. int ret = 0;
  1114. if (drv && drv->suspend)
  1115. ret = drv->suspend(sadev, state);
  1116. return ret;
  1117. }
  1118. static int sa1111_bus_resume(struct device *dev)
  1119. {
  1120. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1121. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1122. int ret = 0;
  1123. if (drv && drv->resume)
  1124. ret = drv->resume(sadev);
  1125. return ret;
  1126. }
  1127. static void sa1111_bus_shutdown(struct device *dev)
  1128. {
  1129. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1130. if (drv && drv->shutdown)
  1131. drv->shutdown(SA1111_DEV(dev));
  1132. }
  1133. static int sa1111_bus_probe(struct device *dev)
  1134. {
  1135. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1136. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1137. int ret = -ENODEV;
  1138. if (drv->probe)
  1139. ret = drv->probe(sadev);
  1140. return ret;
  1141. }
  1142. static int sa1111_bus_remove(struct device *dev)
  1143. {
  1144. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1145. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1146. int ret = 0;
  1147. if (drv->remove)
  1148. ret = drv->remove(sadev);
  1149. return ret;
  1150. }
  1151. struct bus_type sa1111_bus_type = {
  1152. .name = "sa1111-rab",
  1153. .match = sa1111_match,
  1154. .probe = sa1111_bus_probe,
  1155. .remove = sa1111_bus_remove,
  1156. .suspend = sa1111_bus_suspend,
  1157. .resume = sa1111_bus_resume,
  1158. .shutdown = sa1111_bus_shutdown,
  1159. };
  1160. EXPORT_SYMBOL(sa1111_bus_type);
  1161. int sa1111_driver_register(struct sa1111_driver *driver)
  1162. {
  1163. driver->drv.bus = &sa1111_bus_type;
  1164. return driver_register(&driver->drv);
  1165. }
  1166. EXPORT_SYMBOL(sa1111_driver_register);
  1167. void sa1111_driver_unregister(struct sa1111_driver *driver)
  1168. {
  1169. driver_unregister(&driver->drv);
  1170. }
  1171. EXPORT_SYMBOL(sa1111_driver_unregister);
  1172. #ifdef CONFIG_DMABOUNCE
  1173. /*
  1174. * According to the "Intel StrongARM SA-1111 Microprocessor Companion
  1175. * Chip Specification Update" (June 2000), erratum #7, there is a
  1176. * significant bug in the SA1111 SDRAM shared memory controller. If
  1177. * an access to a region of memory above 1MB relative to the bank base,
  1178. * it is important that address bit 10 _NOT_ be asserted. Depending
  1179. * on the configuration of the RAM, bit 10 may correspond to one
  1180. * of several different (processor-relative) address bits.
  1181. *
  1182. * This routine only identifies whether or not a given DMA address
  1183. * is susceptible to the bug.
  1184. *
  1185. * This should only get called for sa1111_device types due to the
  1186. * way we configure our device dma_masks.
  1187. */
  1188. static int sa1111_needs_bounce(struct device *dev, dma_addr_t addr, size_t size)
  1189. {
  1190. /*
  1191. * Section 4.6 of the "Intel StrongARM SA-1111 Development Module
  1192. * User's Guide" mentions that jumpers R51 and R52 control the
  1193. * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or
  1194. * SDRAM bank 1 on Neponset). The default configuration selects
  1195. * Assabet, so any address in bank 1 is necessarily invalid.
  1196. */
  1197. return (machine_is_assabet() || machine_is_pfs168()) &&
  1198. (addr >= 0xc8000000 || (addr + size) >= 0xc8000000);
  1199. }
  1200. static int sa1111_notifier_call(struct notifier_block *n, unsigned long action,
  1201. void *data)
  1202. {
  1203. struct sa1111_dev *dev = SA1111_DEV(data);
  1204. switch (action) {
  1205. case BUS_NOTIFY_ADD_DEVICE:
  1206. if (dev->dev.dma_mask && dev->dma_mask < 0xffffffffUL) {
  1207. int ret = dmabounce_register_dev(&dev->dev, 1024, 4096,
  1208. sa1111_needs_bounce);
  1209. if (ret)
  1210. dev_err(&dev->dev, "failed to register with dmabounce: %d\n", ret);
  1211. }
  1212. break;
  1213. case BUS_NOTIFY_DEL_DEVICE:
  1214. if (dev->dev.dma_mask && dev->dma_mask < 0xffffffffUL)
  1215. dmabounce_unregister_dev(&dev->dev);
  1216. break;
  1217. }
  1218. return NOTIFY_OK;
  1219. }
  1220. static struct notifier_block sa1111_bus_notifier = {
  1221. .notifier_call = sa1111_notifier_call,
  1222. };
  1223. #endif
  1224. static int __init sa1111_init(void)
  1225. {
  1226. int ret = bus_register(&sa1111_bus_type);
  1227. #ifdef CONFIG_DMABOUNCE
  1228. if (ret == 0)
  1229. bus_register_notifier(&sa1111_bus_type, &sa1111_bus_notifier);
  1230. #endif
  1231. if (ret == 0)
  1232. platform_driver_register(&sa1111_device_driver);
  1233. return ret;
  1234. }
  1235. static void __exit sa1111_exit(void)
  1236. {
  1237. platform_driver_unregister(&sa1111_device_driver);
  1238. #ifdef CONFIG_DMABOUNCE
  1239. bus_unregister_notifier(&sa1111_bus_type, &sa1111_bus_notifier);
  1240. #endif
  1241. bus_unregister(&sa1111_bus_type);
  1242. }
  1243. subsys_initcall(sa1111_init);
  1244. module_exit(sa1111_exit);
  1245. MODULE_DESCRIPTION("Intel Corporation SA1111 core driver");
  1246. MODULE_LICENSE("GPL");