sa1111.c 32 KB

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