sa1111.c 34 KB

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