sa1111.c 32 KB

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