sa1111.c 34 KB

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