sa1111.c 34 KB

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