sa1111.c 32 KB

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