sa1111.c 32 KB

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