sa1111.c 32 KB

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