sa1111.c 37 KB

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