sa1111.c 35 KB

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