sa1111.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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. #ifdef CONFIG_DMABOUNCE
  498. /*
  499. * If the parent device has a DMA mask associated with it,
  500. * propagate it down to the children.
  501. */
  502. if (sachip->dev->dma_mask) {
  503. dev->dma_mask = *sachip->dev->dma_mask;
  504. dev->dev.dma_mask = &dev->dma_mask;
  505. if (dev->dma_mask != 0xffffffffUL) {
  506. ret = dmabounce_register_dev(&dev->dev, 1024, 4096);
  507. if (ret) {
  508. dev_err(&dev->dev, "SA1111: Failed to register"
  509. " with dmabounce\n");
  510. device_unregister(&dev->dev);
  511. }
  512. }
  513. }
  514. #endif
  515. out:
  516. return ret;
  517. }
  518. /**
  519. * sa1111_probe - probe for a single SA1111 chip.
  520. * @phys_addr: physical address of device.
  521. *
  522. * Probe for a SA1111 chip. This must be called
  523. * before any other SA1111-specific code.
  524. *
  525. * Returns:
  526. * %-ENODEV device not found.
  527. * %-EBUSY physical address already marked in-use.
  528. * %0 successful.
  529. */
  530. static int
  531. __sa1111_probe(struct device *me, struct resource *mem, int irq)
  532. {
  533. struct sa1111 *sachip;
  534. unsigned long id;
  535. unsigned int has_devs;
  536. int i, ret = -ENODEV;
  537. sachip = kzalloc(sizeof(struct sa1111), GFP_KERNEL);
  538. if (!sachip)
  539. return -ENOMEM;
  540. sachip->clk = clk_get(me, "SA1111_CLK");
  541. if (IS_ERR(sachip->clk)) {
  542. ret = PTR_ERR(sachip->clk);
  543. goto err_free;
  544. }
  545. spin_lock_init(&sachip->lock);
  546. sachip->dev = me;
  547. dev_set_drvdata(sachip->dev, sachip);
  548. sachip->phys = mem->start;
  549. sachip->irq = irq;
  550. /*
  551. * Map the whole region. This also maps the
  552. * registers for our children.
  553. */
  554. sachip->base = ioremap(mem->start, PAGE_SIZE * 2);
  555. if (!sachip->base) {
  556. ret = -ENOMEM;
  557. goto err_clkput;
  558. }
  559. /*
  560. * Probe for the chip. Only touch the SBI registers.
  561. */
  562. id = sa1111_readl(sachip->base + SA1111_SKID);
  563. if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
  564. printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id);
  565. ret = -ENODEV;
  566. goto err_unmap;
  567. }
  568. printk(KERN_INFO "SA1111 Microprocessor Companion Chip: "
  569. "silicon revision %lx, metal revision %lx\n",
  570. (id & SKID_SIREV_MASK)>>4, (id & SKID_MTREV_MASK));
  571. /*
  572. * We found it. Wake the chip up, and initialise.
  573. */
  574. sa1111_wake(sachip);
  575. #ifdef CONFIG_ARCH_SA1100
  576. {
  577. unsigned int val;
  578. /*
  579. * The SDRAM configuration of the SA1110 and the SA1111 must
  580. * match. This is very important to ensure that SA1111 accesses
  581. * don't corrupt the SDRAM. Note that this ungates the SA1111's
  582. * MBGNT signal, so we must have called sa1110_mb_disable()
  583. * beforehand.
  584. */
  585. sa1111_configure_smc(sachip, 1,
  586. FExtr(MDCNFG, MDCNFG_SA1110_DRAC0),
  587. FExtr(MDCNFG, MDCNFG_SA1110_TDL0));
  588. /*
  589. * We only need to turn on DCLK whenever we want to use the
  590. * DMA. It can otherwise be held firmly in the off position.
  591. * (currently, we always enable it.)
  592. */
  593. val = sa1111_readl(sachip->base + SA1111_SKPCR);
  594. sa1111_writel(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR);
  595. /*
  596. * Enable the SA1110 memory bus request and grant signals.
  597. */
  598. sa1110_mb_enable();
  599. }
  600. #endif
  601. /*
  602. * The interrupt controller must be initialised before any
  603. * other device to ensure that the interrupts are available.
  604. */
  605. if (sachip->irq != NO_IRQ)
  606. sa1111_setup_irq(sachip);
  607. g_sa1111 = sachip;
  608. has_devs = ~0;
  609. if (machine_is_assabet() || machine_is_jornada720() ||
  610. machine_is_badge4())
  611. has_devs &= ~(1 << 4);
  612. else
  613. has_devs &= ~(1 << 1);
  614. for (i = 0; i < ARRAY_SIZE(sa1111_devices); i++)
  615. if (has_devs & (1 << i))
  616. sa1111_init_one_child(sachip, mem, &sa1111_devices[i]);
  617. return 0;
  618. err_unmap:
  619. iounmap(sachip->base);
  620. err_clkput:
  621. clk_put(sachip->clk);
  622. err_free:
  623. kfree(sachip);
  624. return ret;
  625. }
  626. static int sa1111_remove_one(struct device *dev, void *data)
  627. {
  628. device_unregister(dev);
  629. return 0;
  630. }
  631. static void __sa1111_remove(struct sa1111 *sachip)
  632. {
  633. void __iomem *irqbase = sachip->base + SA1111_INTC;
  634. device_for_each_child(sachip->dev, NULL, sa1111_remove_one);
  635. /* disable all IRQs */
  636. sa1111_writel(0, irqbase + SA1111_INTEN0);
  637. sa1111_writel(0, irqbase + SA1111_INTEN1);
  638. sa1111_writel(0, irqbase + SA1111_WAKEEN0);
  639. sa1111_writel(0, irqbase + SA1111_WAKEEN1);
  640. clk_disable(sachip->clk);
  641. if (sachip->irq != NO_IRQ) {
  642. set_irq_chained_handler(sachip->irq, NULL);
  643. set_irq_data(sachip->irq, NULL);
  644. release_mem_region(sachip->phys + SA1111_INTC, 512);
  645. }
  646. iounmap(sachip->base);
  647. clk_put(sachip->clk);
  648. kfree(sachip);
  649. }
  650. /*
  651. * According to the "Intel StrongARM SA-1111 Microprocessor Companion
  652. * Chip Specification Update" (June 2000), erratum #7, there is a
  653. * significant bug in the SA1111 SDRAM shared memory controller. If
  654. * an access to a region of memory above 1MB relative to the bank base,
  655. * it is important that address bit 10 _NOT_ be asserted. Depending
  656. * on the configuration of the RAM, bit 10 may correspond to one
  657. * of several different (processor-relative) address bits.
  658. *
  659. * This routine only identifies whether or not a given DMA address
  660. * is susceptible to the bug.
  661. *
  662. * This should only get called for sa1111_device types due to the
  663. * way we configure our device dma_masks.
  664. */
  665. int dma_needs_bounce(struct device *dev, dma_addr_t addr, size_t size)
  666. {
  667. /*
  668. * Section 4.6 of the "Intel StrongARM SA-1111 Development Module
  669. * User's Guide" mentions that jumpers R51 and R52 control the
  670. * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or
  671. * SDRAM bank 1 on Neponset). The default configuration selects
  672. * Assabet, so any address in bank 1 is necessarily invalid.
  673. */
  674. return ((machine_is_assabet() || machine_is_pfs168()) &&
  675. (addr >= 0xc8000000 || (addr + size) >= 0xc8000000));
  676. }
  677. struct sa1111_save_data {
  678. unsigned int skcr;
  679. unsigned int skpcr;
  680. unsigned int skcdr;
  681. unsigned char skaud;
  682. unsigned char skpwm0;
  683. unsigned char skpwm1;
  684. /*
  685. * Interrupt controller
  686. */
  687. unsigned int intpol0;
  688. unsigned int intpol1;
  689. unsigned int inten0;
  690. unsigned int inten1;
  691. unsigned int wakepol0;
  692. unsigned int wakepol1;
  693. unsigned int wakeen0;
  694. unsigned int wakeen1;
  695. };
  696. #ifdef CONFIG_PM
  697. static int sa1111_suspend(struct platform_device *dev, pm_message_t state)
  698. {
  699. struct sa1111 *sachip = platform_get_drvdata(dev);
  700. struct sa1111_save_data *save;
  701. unsigned long flags;
  702. unsigned int val;
  703. void __iomem *base;
  704. save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL);
  705. if (!save)
  706. return -ENOMEM;
  707. sachip->saved_state = save;
  708. spin_lock_irqsave(&sachip->lock, flags);
  709. /*
  710. * Save state.
  711. */
  712. base = sachip->base;
  713. save->skcr = sa1111_readl(base + SA1111_SKCR);
  714. save->skpcr = sa1111_readl(base + SA1111_SKPCR);
  715. save->skcdr = sa1111_readl(base + SA1111_SKCDR);
  716. save->skaud = sa1111_readl(base + SA1111_SKAUD);
  717. save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0);
  718. save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1);
  719. base = sachip->base + SA1111_INTC;
  720. save->intpol0 = sa1111_readl(base + SA1111_INTPOL0);
  721. save->intpol1 = sa1111_readl(base + SA1111_INTPOL1);
  722. save->inten0 = sa1111_readl(base + SA1111_INTEN0);
  723. save->inten1 = sa1111_readl(base + SA1111_INTEN1);
  724. save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0);
  725. save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1);
  726. save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0);
  727. save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1);
  728. /*
  729. * Disable.
  730. */
  731. val = sa1111_readl(sachip->base + SA1111_SKCR);
  732. sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR);
  733. sa1111_writel(0, sachip->base + SA1111_SKPWM0);
  734. sa1111_writel(0, sachip->base + SA1111_SKPWM1);
  735. clk_disable(sachip->clk);
  736. spin_unlock_irqrestore(&sachip->lock, flags);
  737. return 0;
  738. }
  739. /*
  740. * sa1111_resume - Restore the SA1111 device state.
  741. * @dev: device to restore
  742. *
  743. * Restore the general state of the SA1111; clock control and
  744. * interrupt controller. Other parts of the SA1111 must be
  745. * restored by their respective drivers, and must be called
  746. * via LDM after this function.
  747. */
  748. static int sa1111_resume(struct platform_device *dev)
  749. {
  750. struct sa1111 *sachip = platform_get_drvdata(dev);
  751. struct sa1111_save_data *save;
  752. unsigned long flags, id;
  753. void __iomem *base;
  754. save = sachip->saved_state;
  755. if (!save)
  756. return 0;
  757. spin_lock_irqsave(&sachip->lock, flags);
  758. /*
  759. * Ensure that the SA1111 is still here.
  760. * FIXME: shouldn't do this here.
  761. */
  762. id = sa1111_readl(sachip->base + SA1111_SKID);
  763. if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
  764. __sa1111_remove(sachip);
  765. platform_set_drvdata(dev, NULL);
  766. kfree(save);
  767. return 0;
  768. }
  769. /*
  770. * First of all, wake up the chip.
  771. */
  772. sa1111_wake(sachip);
  773. sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0);
  774. sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1);
  775. base = sachip->base;
  776. sa1111_writel(save->skcr, base + SA1111_SKCR);
  777. sa1111_writel(save->skpcr, base + SA1111_SKPCR);
  778. sa1111_writel(save->skcdr, base + SA1111_SKCDR);
  779. sa1111_writel(save->skaud, base + SA1111_SKAUD);
  780. sa1111_writel(save->skpwm0, base + SA1111_SKPWM0);
  781. sa1111_writel(save->skpwm1, base + SA1111_SKPWM1);
  782. base = sachip->base + SA1111_INTC;
  783. sa1111_writel(save->intpol0, base + SA1111_INTPOL0);
  784. sa1111_writel(save->intpol1, base + SA1111_INTPOL1);
  785. sa1111_writel(save->inten0, base + SA1111_INTEN0);
  786. sa1111_writel(save->inten1, base + SA1111_INTEN1);
  787. sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0);
  788. sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1);
  789. sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0);
  790. sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1);
  791. spin_unlock_irqrestore(&sachip->lock, flags);
  792. sachip->saved_state = NULL;
  793. kfree(save);
  794. return 0;
  795. }
  796. #else
  797. #define sa1111_suspend NULL
  798. #define sa1111_resume NULL
  799. #endif
  800. static int __devinit sa1111_probe(struct platform_device *pdev)
  801. {
  802. struct resource *mem;
  803. int irq;
  804. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  805. if (!mem)
  806. return -EINVAL;
  807. irq = platform_get_irq(pdev, 0);
  808. if (irq < 0)
  809. return -ENXIO;
  810. return __sa1111_probe(&pdev->dev, mem, irq);
  811. }
  812. static int sa1111_remove(struct platform_device *pdev)
  813. {
  814. struct sa1111 *sachip = platform_get_drvdata(pdev);
  815. if (sachip) {
  816. __sa1111_remove(sachip);
  817. platform_set_drvdata(pdev, NULL);
  818. #ifdef CONFIG_PM
  819. kfree(sachip->saved_state);
  820. sachip->saved_state = NULL;
  821. #endif
  822. }
  823. return 0;
  824. }
  825. /*
  826. * Not sure if this should be on the system bus or not yet.
  827. * We really want some way to register a system device at
  828. * the per-machine level, and then have this driver pick
  829. * up the registered devices.
  830. *
  831. * We also need to handle the SDRAM configuration for
  832. * PXA250/SA1110 machine classes.
  833. */
  834. static struct platform_driver sa1111_device_driver = {
  835. .probe = sa1111_probe,
  836. .remove = sa1111_remove,
  837. .suspend = sa1111_suspend,
  838. .resume = sa1111_resume,
  839. .driver = {
  840. .name = "sa1111",
  841. },
  842. };
  843. /*
  844. * Get the parent device driver (us) structure
  845. * from a child function device
  846. */
  847. static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev)
  848. {
  849. return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent);
  850. }
  851. /*
  852. * The bits in the opdiv field are non-linear.
  853. */
  854. static unsigned char opdiv_table[] = { 1, 4, 2, 8 };
  855. static unsigned int __sa1111_pll_clock(struct sa1111 *sachip)
  856. {
  857. unsigned int skcdr, fbdiv, ipdiv, opdiv;
  858. skcdr = sa1111_readl(sachip->base + SA1111_SKCDR);
  859. fbdiv = (skcdr & 0x007f) + 2;
  860. ipdiv = ((skcdr & 0x0f80) >> 7) + 2;
  861. opdiv = opdiv_table[(skcdr & 0x3000) >> 12];
  862. return 3686400 * fbdiv / (ipdiv * opdiv);
  863. }
  864. /**
  865. * sa1111_pll_clock - return the current PLL clock frequency.
  866. * @sadev: SA1111 function block
  867. *
  868. * BUG: we should look at SKCR. We also blindly believe that
  869. * the chip is being fed with the 3.6864MHz clock.
  870. *
  871. * Returns the PLL clock in Hz.
  872. */
  873. unsigned int sa1111_pll_clock(struct sa1111_dev *sadev)
  874. {
  875. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  876. return __sa1111_pll_clock(sachip);
  877. }
  878. /**
  879. * sa1111_select_audio_mode - select I2S or AC link mode
  880. * @sadev: SA1111 function block
  881. * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S
  882. *
  883. * Frob the SKCR to select AC Link mode or I2S mode for
  884. * the audio block.
  885. */
  886. void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode)
  887. {
  888. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  889. unsigned long flags;
  890. unsigned int val;
  891. spin_lock_irqsave(&sachip->lock, flags);
  892. val = sa1111_readl(sachip->base + SA1111_SKCR);
  893. if (mode == SA1111_AUDIO_I2S) {
  894. val &= ~SKCR_SELAC;
  895. } else {
  896. val |= SKCR_SELAC;
  897. }
  898. sa1111_writel(val, sachip->base + SA1111_SKCR);
  899. spin_unlock_irqrestore(&sachip->lock, flags);
  900. }
  901. /**
  902. * sa1111_set_audio_rate - set the audio sample rate
  903. * @sadev: SA1111 SAC function block
  904. * @rate: sample rate to select
  905. */
  906. int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate)
  907. {
  908. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  909. unsigned int div;
  910. if (sadev->devid != SA1111_DEVID_SAC)
  911. return -EINVAL;
  912. div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate;
  913. if (div == 0)
  914. div = 1;
  915. if (div > 128)
  916. div = 128;
  917. sa1111_writel(div - 1, sachip->base + SA1111_SKAUD);
  918. return 0;
  919. }
  920. /**
  921. * sa1111_get_audio_rate - get the audio sample rate
  922. * @sadev: SA1111 SAC function block device
  923. */
  924. int sa1111_get_audio_rate(struct sa1111_dev *sadev)
  925. {
  926. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  927. unsigned long div;
  928. if (sadev->devid != SA1111_DEVID_SAC)
  929. return -EINVAL;
  930. div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1;
  931. return __sa1111_pll_clock(sachip) / (256 * div);
  932. }
  933. void sa1111_set_io_dir(struct sa1111_dev *sadev,
  934. unsigned int bits, unsigned int dir,
  935. unsigned int sleep_dir)
  936. {
  937. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  938. unsigned long flags;
  939. unsigned int val;
  940. void __iomem *gpio = sachip->base + SA1111_GPIO;
  941. #define MODIFY_BITS(port, mask, dir) \
  942. if (mask) { \
  943. val = sa1111_readl(port); \
  944. val &= ~(mask); \
  945. val |= (dir) & (mask); \
  946. sa1111_writel(val, port); \
  947. }
  948. spin_lock_irqsave(&sachip->lock, flags);
  949. MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir);
  950. MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8);
  951. MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16);
  952. MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir);
  953. MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8);
  954. MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16);
  955. spin_unlock_irqrestore(&sachip->lock, flags);
  956. }
  957. void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
  958. {
  959. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  960. unsigned long flags;
  961. unsigned int val;
  962. void __iomem *gpio = sachip->base + SA1111_GPIO;
  963. spin_lock_irqsave(&sachip->lock, flags);
  964. MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v);
  965. MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8);
  966. MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16);
  967. spin_unlock_irqrestore(&sachip->lock, flags);
  968. }
  969. void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
  970. {
  971. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  972. unsigned long flags;
  973. unsigned int val;
  974. void __iomem *gpio = sachip->base + SA1111_GPIO;
  975. spin_lock_irqsave(&sachip->lock, flags);
  976. MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v);
  977. MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8);
  978. MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16);
  979. spin_unlock_irqrestore(&sachip->lock, flags);
  980. }
  981. /*
  982. * Individual device operations.
  983. */
  984. /**
  985. * sa1111_enable_device - enable an on-chip SA1111 function block
  986. * @sadev: SA1111 function block device to enable
  987. */
  988. void sa1111_enable_device(struct sa1111_dev *sadev)
  989. {
  990. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  991. unsigned long flags;
  992. unsigned int val;
  993. spin_lock_irqsave(&sachip->lock, flags);
  994. val = sa1111_readl(sachip->base + SA1111_SKPCR);
  995. sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
  996. spin_unlock_irqrestore(&sachip->lock, flags);
  997. }
  998. /**
  999. * sa1111_disable_device - disable an on-chip SA1111 function block
  1000. * @sadev: SA1111 function block device to disable
  1001. */
  1002. void sa1111_disable_device(struct sa1111_dev *sadev)
  1003. {
  1004. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  1005. unsigned long flags;
  1006. unsigned int val;
  1007. spin_lock_irqsave(&sachip->lock, flags);
  1008. val = sa1111_readl(sachip->base + SA1111_SKPCR);
  1009. sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
  1010. spin_unlock_irqrestore(&sachip->lock, flags);
  1011. }
  1012. /*
  1013. * SA1111 "Register Access Bus."
  1014. *
  1015. * We model this as a regular bus type, and hang devices directly
  1016. * off this.
  1017. */
  1018. static int sa1111_match(struct device *_dev, struct device_driver *_drv)
  1019. {
  1020. struct sa1111_dev *dev = SA1111_DEV(_dev);
  1021. struct sa1111_driver *drv = SA1111_DRV(_drv);
  1022. return dev->devid == drv->devid;
  1023. }
  1024. static int sa1111_bus_suspend(struct device *dev, pm_message_t state)
  1025. {
  1026. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1027. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1028. int ret = 0;
  1029. if (drv && drv->suspend)
  1030. ret = drv->suspend(sadev, state);
  1031. return ret;
  1032. }
  1033. static int sa1111_bus_resume(struct device *dev)
  1034. {
  1035. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1036. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1037. int ret = 0;
  1038. if (drv && drv->resume)
  1039. ret = drv->resume(sadev);
  1040. return ret;
  1041. }
  1042. static int sa1111_bus_probe(struct device *dev)
  1043. {
  1044. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1045. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1046. int ret = -ENODEV;
  1047. if (drv->probe)
  1048. ret = drv->probe(sadev);
  1049. return ret;
  1050. }
  1051. static int sa1111_bus_remove(struct device *dev)
  1052. {
  1053. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1054. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1055. int ret = 0;
  1056. if (drv->remove)
  1057. ret = drv->remove(sadev);
  1058. return ret;
  1059. }
  1060. struct bus_type sa1111_bus_type = {
  1061. .name = "sa1111-rab",
  1062. .match = sa1111_match,
  1063. .probe = sa1111_bus_probe,
  1064. .remove = sa1111_bus_remove,
  1065. .suspend = sa1111_bus_suspend,
  1066. .resume = sa1111_bus_resume,
  1067. };
  1068. int sa1111_driver_register(struct sa1111_driver *driver)
  1069. {
  1070. driver->drv.bus = &sa1111_bus_type;
  1071. return driver_register(&driver->drv);
  1072. }
  1073. void sa1111_driver_unregister(struct sa1111_driver *driver)
  1074. {
  1075. driver_unregister(&driver->drv);
  1076. }
  1077. static int __init sa1111_init(void)
  1078. {
  1079. int ret = bus_register(&sa1111_bus_type);
  1080. if (ret == 0)
  1081. platform_driver_register(&sa1111_device_driver);
  1082. return ret;
  1083. }
  1084. static void __exit sa1111_exit(void)
  1085. {
  1086. platform_driver_unregister(&sa1111_device_driver);
  1087. bus_unregister(&sa1111_bus_type);
  1088. }
  1089. subsys_initcall(sa1111_init);
  1090. module_exit(sa1111_exit);
  1091. MODULE_DESCRIPTION("Intel Corporation SA1111 core driver");
  1092. MODULE_LICENSE("GPL");
  1093. EXPORT_SYMBOL(sa1111_select_audio_mode);
  1094. EXPORT_SYMBOL(sa1111_set_audio_rate);
  1095. EXPORT_SYMBOL(sa1111_get_audio_rate);
  1096. EXPORT_SYMBOL(sa1111_set_io_dir);
  1097. EXPORT_SYMBOL(sa1111_set_io);
  1098. EXPORT_SYMBOL(sa1111_set_sleep_io);
  1099. EXPORT_SYMBOL(sa1111_enable_device);
  1100. EXPORT_SYMBOL(sa1111_disable_device);
  1101. EXPORT_SYMBOL(sa1111_pll_clock);
  1102. EXPORT_SYMBOL(sa1111_bus_type);
  1103. EXPORT_SYMBOL(sa1111_driver_register);
  1104. EXPORT_SYMBOL(sa1111_driver_unregister);