sa1111.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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. .type = sa1111_type_lowirq,
  237. .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. .type = sa1111_type_highirq,
  317. .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 void __sa1111_remove(struct sa1111 *sachip)
  617. {
  618. struct list_head *l, *n;
  619. void __iomem *irqbase = sachip->base + SA1111_INTC;
  620. list_for_each_safe(l, n, &sachip->dev->children) {
  621. struct device *d = list_to_dev(l);
  622. device_unregister(d);
  623. }
  624. /* disable all IRQs */
  625. sa1111_writel(0, irqbase + SA1111_INTEN0);
  626. sa1111_writel(0, irqbase + SA1111_INTEN1);
  627. sa1111_writel(0, irqbase + SA1111_WAKEEN0);
  628. sa1111_writel(0, irqbase + SA1111_WAKEEN1);
  629. if (sachip->irq != NO_IRQ) {
  630. set_irq_chained_handler(sachip->irq, NULL);
  631. set_irq_data(sachip->irq, NULL);
  632. release_mem_region(sachip->phys + SA1111_INTC, 512);
  633. }
  634. iounmap(sachip->base);
  635. kfree(sachip);
  636. }
  637. /*
  638. * According to the "Intel StrongARM SA-1111 Microprocessor Companion
  639. * Chip Specification Update" (June 2000), erratum #7, there is a
  640. * significant bug in the SA1111 SDRAM shared memory controller. If
  641. * an access to a region of memory above 1MB relative to the bank base,
  642. * it is important that address bit 10 _NOT_ be asserted. Depending
  643. * on the configuration of the RAM, bit 10 may correspond to one
  644. * of several different (processor-relative) address bits.
  645. *
  646. * This routine only identifies whether or not a given DMA address
  647. * is susceptible to the bug.
  648. *
  649. * This should only get called for sa1111_device types due to the
  650. * way we configure our device dma_masks.
  651. */
  652. int dma_needs_bounce(struct device *dev, dma_addr_t addr, size_t size)
  653. {
  654. /*
  655. * Section 4.6 of the "Intel StrongARM SA-1111 Development Module
  656. * User's Guide" mentions that jumpers R51 and R52 control the
  657. * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or
  658. * SDRAM bank 1 on Neponset). The default configuration selects
  659. * Assabet, so any address in bank 1 is necessarily invalid.
  660. */
  661. return ((machine_is_assabet() || machine_is_pfs168()) &&
  662. (addr >= 0xc8000000 || (addr + size) >= 0xc8000000));
  663. }
  664. struct sa1111_save_data {
  665. unsigned int skcr;
  666. unsigned int skpcr;
  667. unsigned int skcdr;
  668. unsigned char skaud;
  669. unsigned char skpwm0;
  670. unsigned char skpwm1;
  671. /*
  672. * Interrupt controller
  673. */
  674. unsigned int intpol0;
  675. unsigned int intpol1;
  676. unsigned int inten0;
  677. unsigned int inten1;
  678. unsigned int wakepol0;
  679. unsigned int wakepol1;
  680. unsigned int wakeen0;
  681. unsigned int wakeen1;
  682. };
  683. #ifdef CONFIG_PM
  684. static int sa1111_suspend(struct device *dev, pm_message_t state, u32 level)
  685. {
  686. struct sa1111 *sachip = dev_get_drvdata(dev);
  687. struct sa1111_save_data *save;
  688. unsigned long flags;
  689. unsigned int val;
  690. void __iomem *base;
  691. if (level != SUSPEND_DISABLE)
  692. return 0;
  693. save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL);
  694. if (!save)
  695. return -ENOMEM;
  696. dev->power.saved_state = save;
  697. spin_lock_irqsave(&sachip->lock, flags);
  698. /*
  699. * Save state.
  700. */
  701. base = sachip->base;
  702. save->skcr = sa1111_readl(base + SA1111_SKCR);
  703. save->skpcr = sa1111_readl(base + SA1111_SKPCR);
  704. save->skcdr = sa1111_readl(base + SA1111_SKCDR);
  705. save->skaud = sa1111_readl(base + SA1111_SKAUD);
  706. save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0);
  707. save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1);
  708. base = sachip->base + SA1111_INTC;
  709. save->intpol0 = sa1111_readl(base + SA1111_INTPOL0);
  710. save->intpol1 = sa1111_readl(base + SA1111_INTPOL1);
  711. save->inten0 = sa1111_readl(base + SA1111_INTEN0);
  712. save->inten1 = sa1111_readl(base + SA1111_INTEN1);
  713. save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0);
  714. save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1);
  715. save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0);
  716. save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1);
  717. /*
  718. * Disable.
  719. */
  720. val = sa1111_readl(sachip->base + SA1111_SKCR);
  721. sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR);
  722. sa1111_writel(0, sachip->base + SA1111_SKPWM0);
  723. sa1111_writel(0, sachip->base + SA1111_SKPWM1);
  724. spin_unlock_irqrestore(&sachip->lock, flags);
  725. return 0;
  726. }
  727. /*
  728. * sa1111_resume - Restore the SA1111 device state.
  729. * @dev: device to restore
  730. * @level: resume level
  731. *
  732. * Restore the general state of the SA1111; clock control and
  733. * interrupt controller. Other parts of the SA1111 must be
  734. * restored by their respective drivers, and must be called
  735. * via LDM after this function.
  736. */
  737. static int sa1111_resume(struct device *dev, u32 level)
  738. {
  739. struct sa1111 *sachip = dev_get_drvdata(dev);
  740. struct sa1111_save_data *save;
  741. unsigned long flags, id;
  742. void __iomem *base;
  743. if (level != RESUME_ENABLE)
  744. return 0;
  745. save = (struct sa1111_save_data *)dev->power.saved_state;
  746. if (!save)
  747. return 0;
  748. spin_lock_irqsave(&sachip->lock, flags);
  749. /*
  750. * Ensure that the SA1111 is still here.
  751. * FIXME: shouldn't do this here.
  752. */
  753. id = sa1111_readl(sachip->base + SA1111_SKID);
  754. if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
  755. __sa1111_remove(sachip);
  756. dev_set_drvdata(dev, NULL);
  757. kfree(save);
  758. return 0;
  759. }
  760. /*
  761. * First of all, wake up the chip.
  762. */
  763. sa1111_wake(sachip);
  764. sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0);
  765. sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1);
  766. base = sachip->base;
  767. sa1111_writel(save->skcr, base + SA1111_SKCR);
  768. sa1111_writel(save->skpcr, base + SA1111_SKPCR);
  769. sa1111_writel(save->skcdr, base + SA1111_SKCDR);
  770. sa1111_writel(save->skaud, base + SA1111_SKAUD);
  771. sa1111_writel(save->skpwm0, base + SA1111_SKPWM0);
  772. sa1111_writel(save->skpwm1, base + SA1111_SKPWM1);
  773. base = sachip->base + SA1111_INTC;
  774. sa1111_writel(save->intpol0, base + SA1111_INTPOL0);
  775. sa1111_writel(save->intpol1, base + SA1111_INTPOL1);
  776. sa1111_writel(save->inten0, base + SA1111_INTEN0);
  777. sa1111_writel(save->inten1, base + SA1111_INTEN1);
  778. sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0);
  779. sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1);
  780. sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0);
  781. sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1);
  782. spin_unlock_irqrestore(&sachip->lock, flags);
  783. dev->power.saved_state = NULL;
  784. kfree(save);
  785. return 0;
  786. }
  787. #else
  788. #define sa1111_suspend NULL
  789. #define sa1111_resume NULL
  790. #endif
  791. static int sa1111_probe(struct device *dev)
  792. {
  793. struct platform_device *pdev = to_platform_device(dev);
  794. struct resource *mem;
  795. int irq;
  796. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  797. if (!mem)
  798. return -EINVAL;
  799. irq = platform_get_irq(pdev, 0);
  800. return __sa1111_probe(dev, mem, irq);
  801. }
  802. static int sa1111_remove(struct device *dev)
  803. {
  804. struct sa1111 *sachip = dev_get_drvdata(dev);
  805. if (sachip) {
  806. __sa1111_remove(sachip);
  807. dev_set_drvdata(dev, NULL);
  808. #ifdef CONFIG_PM
  809. kfree(dev->power.saved_state);
  810. dev->power.saved_state = NULL;
  811. #endif
  812. }
  813. return 0;
  814. }
  815. /*
  816. * Not sure if this should be on the system bus or not yet.
  817. * We really want some way to register a system device at
  818. * the per-machine level, and then have this driver pick
  819. * up the registered devices.
  820. *
  821. * We also need to handle the SDRAM configuration for
  822. * PXA250/SA1110 machine classes.
  823. */
  824. static struct device_driver sa1111_device_driver = {
  825. .name = "sa1111",
  826. .bus = &platform_bus_type,
  827. .probe = sa1111_probe,
  828. .remove = sa1111_remove,
  829. .suspend = sa1111_suspend,
  830. .resume = sa1111_resume,
  831. };
  832. /*
  833. * Get the parent device driver (us) structure
  834. * from a child function device
  835. */
  836. static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev)
  837. {
  838. return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent);
  839. }
  840. /*
  841. * The bits in the opdiv field are non-linear.
  842. */
  843. static unsigned char opdiv_table[] = { 1, 4, 2, 8 };
  844. static unsigned int __sa1111_pll_clock(struct sa1111 *sachip)
  845. {
  846. unsigned int skcdr, fbdiv, ipdiv, opdiv;
  847. skcdr = sa1111_readl(sachip->base + SA1111_SKCDR);
  848. fbdiv = (skcdr & 0x007f) + 2;
  849. ipdiv = ((skcdr & 0x0f80) >> 7) + 2;
  850. opdiv = opdiv_table[(skcdr & 0x3000) >> 12];
  851. return 3686400 * fbdiv / (ipdiv * opdiv);
  852. }
  853. /**
  854. * sa1111_pll_clock - return the current PLL clock frequency.
  855. * @sadev: SA1111 function block
  856. *
  857. * BUG: we should look at SKCR. We also blindly believe that
  858. * the chip is being fed with the 3.6864MHz clock.
  859. *
  860. * Returns the PLL clock in Hz.
  861. */
  862. unsigned int sa1111_pll_clock(struct sa1111_dev *sadev)
  863. {
  864. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  865. return __sa1111_pll_clock(sachip);
  866. }
  867. /**
  868. * sa1111_select_audio_mode - select I2S or AC link mode
  869. * @sadev: SA1111 function block
  870. * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S
  871. *
  872. * Frob the SKCR to select AC Link mode or I2S mode for
  873. * the audio block.
  874. */
  875. void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode)
  876. {
  877. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  878. unsigned long flags;
  879. unsigned int val;
  880. spin_lock_irqsave(&sachip->lock, flags);
  881. val = sa1111_readl(sachip->base + SA1111_SKCR);
  882. if (mode == SA1111_AUDIO_I2S) {
  883. val &= ~SKCR_SELAC;
  884. } else {
  885. val |= SKCR_SELAC;
  886. }
  887. sa1111_writel(val, sachip->base + SA1111_SKCR);
  888. spin_unlock_irqrestore(&sachip->lock, flags);
  889. }
  890. /**
  891. * sa1111_set_audio_rate - set the audio sample rate
  892. * @sadev: SA1111 SAC function block
  893. * @rate: sample rate to select
  894. */
  895. int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate)
  896. {
  897. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  898. unsigned int div;
  899. if (sadev->devid != SA1111_DEVID_SAC)
  900. return -EINVAL;
  901. div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate;
  902. if (div == 0)
  903. div = 1;
  904. if (div > 128)
  905. div = 128;
  906. sa1111_writel(div - 1, sachip->base + SA1111_SKAUD);
  907. return 0;
  908. }
  909. /**
  910. * sa1111_get_audio_rate - get the audio sample rate
  911. * @sadev: SA1111 SAC function block device
  912. */
  913. int sa1111_get_audio_rate(struct sa1111_dev *sadev)
  914. {
  915. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  916. unsigned long div;
  917. if (sadev->devid != SA1111_DEVID_SAC)
  918. return -EINVAL;
  919. div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1;
  920. return __sa1111_pll_clock(sachip) / (256 * div);
  921. }
  922. void sa1111_set_io_dir(struct sa1111_dev *sadev,
  923. unsigned int bits, unsigned int dir,
  924. unsigned int sleep_dir)
  925. {
  926. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  927. unsigned long flags;
  928. unsigned int val;
  929. void __iomem *gpio = sachip->base + SA1111_GPIO;
  930. #define MODIFY_BITS(port, mask, dir) \
  931. if (mask) { \
  932. val = sa1111_readl(port); \
  933. val &= ~(mask); \
  934. val |= (dir) & (mask); \
  935. sa1111_writel(val, port); \
  936. }
  937. spin_lock_irqsave(&sachip->lock, flags);
  938. MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir);
  939. MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8);
  940. MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16);
  941. MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir);
  942. MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8);
  943. MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16);
  944. spin_unlock_irqrestore(&sachip->lock, flags);
  945. }
  946. void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
  947. {
  948. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  949. unsigned long flags;
  950. unsigned int val;
  951. void __iomem *gpio = sachip->base + SA1111_GPIO;
  952. spin_lock_irqsave(&sachip->lock, flags);
  953. MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v);
  954. MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8);
  955. MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16);
  956. spin_unlock_irqrestore(&sachip->lock, flags);
  957. }
  958. void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
  959. {
  960. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  961. unsigned long flags;
  962. unsigned int val;
  963. void __iomem *gpio = sachip->base + SA1111_GPIO;
  964. spin_lock_irqsave(&sachip->lock, flags);
  965. MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v);
  966. MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8);
  967. MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16);
  968. spin_unlock_irqrestore(&sachip->lock, flags);
  969. }
  970. /*
  971. * Individual device operations.
  972. */
  973. /**
  974. * sa1111_enable_device - enable an on-chip SA1111 function block
  975. * @sadev: SA1111 function block device to enable
  976. */
  977. void sa1111_enable_device(struct sa1111_dev *sadev)
  978. {
  979. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  980. unsigned long flags;
  981. unsigned int val;
  982. spin_lock_irqsave(&sachip->lock, flags);
  983. val = sa1111_readl(sachip->base + SA1111_SKPCR);
  984. sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
  985. spin_unlock_irqrestore(&sachip->lock, flags);
  986. }
  987. /**
  988. * sa1111_disable_device - disable an on-chip SA1111 function block
  989. * @sadev: SA1111 function block device to disable
  990. */
  991. void sa1111_disable_device(struct sa1111_dev *sadev)
  992. {
  993. struct sa1111 *sachip = sa1111_chip_driver(sadev);
  994. unsigned long flags;
  995. unsigned int val;
  996. spin_lock_irqsave(&sachip->lock, flags);
  997. val = sa1111_readl(sachip->base + SA1111_SKPCR);
  998. sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
  999. spin_unlock_irqrestore(&sachip->lock, flags);
  1000. }
  1001. /*
  1002. * SA1111 "Register Access Bus."
  1003. *
  1004. * We model this as a regular bus type, and hang devices directly
  1005. * off this.
  1006. */
  1007. static int sa1111_match(struct device *_dev, struct device_driver *_drv)
  1008. {
  1009. struct sa1111_dev *dev = SA1111_DEV(_dev);
  1010. struct sa1111_driver *drv = SA1111_DRV(_drv);
  1011. return dev->devid == drv->devid;
  1012. }
  1013. static int sa1111_bus_suspend(struct device *dev, pm_message_t state)
  1014. {
  1015. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1016. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1017. int ret = 0;
  1018. if (drv && drv->suspend)
  1019. ret = drv->suspend(sadev, state);
  1020. return ret;
  1021. }
  1022. static int sa1111_bus_resume(struct device *dev)
  1023. {
  1024. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1025. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1026. int ret = 0;
  1027. if (drv && drv->resume)
  1028. ret = drv->resume(sadev);
  1029. return ret;
  1030. }
  1031. static int sa1111_bus_probe(struct device *dev)
  1032. {
  1033. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1034. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1035. int ret = -ENODEV;
  1036. if (drv->probe)
  1037. ret = drv->probe(sadev);
  1038. return ret;
  1039. }
  1040. static int sa1111_bus_remove(struct device *dev)
  1041. {
  1042. struct sa1111_dev *sadev = SA1111_DEV(dev);
  1043. struct sa1111_driver *drv = SA1111_DRV(dev->driver);
  1044. int ret = 0;
  1045. if (drv->remove)
  1046. ret = drv->remove(sadev);
  1047. return ret;
  1048. }
  1049. struct bus_type sa1111_bus_type = {
  1050. .name = "sa1111-rab",
  1051. .match = sa1111_match,
  1052. .suspend = sa1111_bus_suspend,
  1053. .resume = sa1111_bus_resume,
  1054. };
  1055. int sa1111_driver_register(struct sa1111_driver *driver)
  1056. {
  1057. driver->drv.probe = sa1111_bus_probe;
  1058. driver->drv.remove = sa1111_bus_remove;
  1059. driver->drv.bus = &sa1111_bus_type;
  1060. return driver_register(&driver->drv);
  1061. }
  1062. void sa1111_driver_unregister(struct sa1111_driver *driver)
  1063. {
  1064. driver_unregister(&driver->drv);
  1065. }
  1066. static int __init sa1111_init(void)
  1067. {
  1068. int ret = bus_register(&sa1111_bus_type);
  1069. if (ret == 0)
  1070. driver_register(&sa1111_device_driver);
  1071. return ret;
  1072. }
  1073. static void __exit sa1111_exit(void)
  1074. {
  1075. driver_unregister(&sa1111_device_driver);
  1076. bus_unregister(&sa1111_bus_type);
  1077. }
  1078. module_init(sa1111_init);
  1079. module_exit(sa1111_exit);
  1080. MODULE_DESCRIPTION("Intel Corporation SA1111 core driver");
  1081. MODULE_LICENSE("GPL");
  1082. EXPORT_SYMBOL(sa1111_select_audio_mode);
  1083. EXPORT_SYMBOL(sa1111_set_audio_rate);
  1084. EXPORT_SYMBOL(sa1111_get_audio_rate);
  1085. EXPORT_SYMBOL(sa1111_set_io_dir);
  1086. EXPORT_SYMBOL(sa1111_set_io);
  1087. EXPORT_SYMBOL(sa1111_set_sleep_io);
  1088. EXPORT_SYMBOL(sa1111_enable_device);
  1089. EXPORT_SYMBOL(sa1111_disable_device);
  1090. EXPORT_SYMBOL(sa1111_pll_clock);
  1091. EXPORT_SYMBOL(sa1111_bus_type);
  1092. EXPORT_SYMBOL(sa1111_driver_register);
  1093. EXPORT_SYMBOL(sa1111_driver_unregister);