neponset.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*
  2. * linux/arch/arm/mach-sa1100/neponset.c
  3. */
  4. #include <linux/err.h>
  5. #include <linux/init.h>
  6. #include <linux/ioport.h>
  7. #include <linux/irq.h>
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/platform_data/sa11x0-serial.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/pm.h>
  13. #include <linux/serial_core.h>
  14. #include <linux/slab.h>
  15. #include <linux/smc91x.h>
  16. #include <asm/mach-types.h>
  17. #include <asm/mach/map.h>
  18. #include <asm/hardware/sa1111.h>
  19. #include <asm/sizes.h>
  20. #include <mach/hardware.h>
  21. #include <mach/assabet.h>
  22. #include <mach/neponset.h>
  23. #include <mach/irqs.h>
  24. #define NEP_IRQ_SMC91X 0
  25. #define NEP_IRQ_USAR 1
  26. #define NEP_IRQ_SA1111 2
  27. #define NEP_IRQ_NR 3
  28. #define WHOAMI 0x00
  29. #define LEDS 0x10
  30. #define SWPK 0x20
  31. #define IRR 0x24
  32. #define KP_Y_IN 0x80
  33. #define KP_X_OUT 0x90
  34. #define NCR_0 0xa0
  35. #define MDM_CTL_0 0xb0
  36. #define MDM_CTL_1 0xb4
  37. #define AUD_CTL 0xc0
  38. #define IRR_ETHERNET (1 << 0)
  39. #define IRR_USAR (1 << 1)
  40. #define IRR_SA1111 (1 << 2)
  41. #define MDM_CTL0_RTS1 (1 << 0)
  42. #define MDM_CTL0_DTR1 (1 << 1)
  43. #define MDM_CTL0_RTS2 (1 << 2)
  44. #define MDM_CTL0_DTR2 (1 << 3)
  45. #define MDM_CTL1_CTS1 (1 << 0)
  46. #define MDM_CTL1_DSR1 (1 << 1)
  47. #define MDM_CTL1_DCD1 (1 << 2)
  48. #define MDM_CTL1_CTS2 (1 << 3)
  49. #define MDM_CTL1_DSR2 (1 << 4)
  50. #define MDM_CTL1_DCD2 (1 << 5)
  51. #define AUD_SEL_1341 (1 << 0)
  52. #define AUD_MUTE_1341 (1 << 1)
  53. extern void sa1110_mb_disable(void);
  54. struct neponset_drvdata {
  55. void __iomem *base;
  56. struct platform_device *sa1111;
  57. struct platform_device *smc91x;
  58. unsigned irq_base;
  59. #ifdef CONFIG_PM_SLEEP
  60. u32 ncr0;
  61. u32 mdm_ctl_0;
  62. #endif
  63. };
  64. static void __iomem *nep_base;
  65. void neponset_ncr_frob(unsigned int mask, unsigned int val)
  66. {
  67. void __iomem *base = nep_base;
  68. if (base) {
  69. unsigned long flags;
  70. unsigned v;
  71. local_irq_save(flags);
  72. v = readb_relaxed(base + NCR_0);
  73. writeb_relaxed((v & ~mask) | val, base + NCR_0);
  74. local_irq_restore(flags);
  75. } else {
  76. WARN(1, "nep_base unset\n");
  77. }
  78. }
  79. EXPORT_SYMBOL(neponset_ncr_frob);
  80. static void neponset_set_mctrl(struct uart_port *port, u_int mctrl)
  81. {
  82. void __iomem *base = nep_base;
  83. u_int mdm_ctl0;
  84. if (!base)
  85. return;
  86. mdm_ctl0 = readb_relaxed(base + MDM_CTL_0);
  87. if (port->mapbase == _Ser1UTCR0) {
  88. if (mctrl & TIOCM_RTS)
  89. mdm_ctl0 &= ~MDM_CTL0_RTS2;
  90. else
  91. mdm_ctl0 |= MDM_CTL0_RTS2;
  92. if (mctrl & TIOCM_DTR)
  93. mdm_ctl0 &= ~MDM_CTL0_DTR2;
  94. else
  95. mdm_ctl0 |= MDM_CTL0_DTR2;
  96. } else if (port->mapbase == _Ser3UTCR0) {
  97. if (mctrl & TIOCM_RTS)
  98. mdm_ctl0 &= ~MDM_CTL0_RTS1;
  99. else
  100. mdm_ctl0 |= MDM_CTL0_RTS1;
  101. if (mctrl & TIOCM_DTR)
  102. mdm_ctl0 &= ~MDM_CTL0_DTR1;
  103. else
  104. mdm_ctl0 |= MDM_CTL0_DTR1;
  105. }
  106. writeb_relaxed(mdm_ctl0, base + MDM_CTL_0);
  107. }
  108. static u_int neponset_get_mctrl(struct uart_port *port)
  109. {
  110. void __iomem *base = nep_base;
  111. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  112. u_int mdm_ctl1;
  113. if (!base)
  114. return ret;
  115. mdm_ctl1 = readb_relaxed(base + MDM_CTL_1);
  116. if (port->mapbase == _Ser1UTCR0) {
  117. if (mdm_ctl1 & MDM_CTL1_DCD2)
  118. ret &= ~TIOCM_CD;
  119. if (mdm_ctl1 & MDM_CTL1_CTS2)
  120. ret &= ~TIOCM_CTS;
  121. if (mdm_ctl1 & MDM_CTL1_DSR2)
  122. ret &= ~TIOCM_DSR;
  123. } else if (port->mapbase == _Ser3UTCR0) {
  124. if (mdm_ctl1 & MDM_CTL1_DCD1)
  125. ret &= ~TIOCM_CD;
  126. if (mdm_ctl1 & MDM_CTL1_CTS1)
  127. ret &= ~TIOCM_CTS;
  128. if (mdm_ctl1 & MDM_CTL1_DSR1)
  129. ret &= ~TIOCM_DSR;
  130. }
  131. return ret;
  132. }
  133. static struct sa1100_port_fns neponset_port_fns = {
  134. .set_mctrl = neponset_set_mctrl,
  135. .get_mctrl = neponset_get_mctrl,
  136. };
  137. /*
  138. * Install handler for Neponset IRQ. Note that we have to loop here
  139. * since the ETHERNET and USAR IRQs are level based, and we need to
  140. * ensure that the IRQ signal is deasserted before returning. This
  141. * is rather unfortunate.
  142. */
  143. static void neponset_irq_handler(struct irq_desc *desc)
  144. {
  145. struct neponset_drvdata *d = irq_desc_get_handler_data(desc);
  146. unsigned int irr;
  147. while (1) {
  148. /*
  149. * Acknowledge the parent IRQ.
  150. */
  151. desc->irq_data.chip->irq_ack(&desc->irq_data);
  152. /*
  153. * Read the interrupt reason register. Let's have all
  154. * active IRQ bits high. Note: there is a typo in the
  155. * Neponset user's guide for the SA1111 IRR level.
  156. */
  157. irr = readb_relaxed(d->base + IRR);
  158. irr ^= IRR_ETHERNET | IRR_USAR;
  159. if ((irr & (IRR_ETHERNET | IRR_USAR | IRR_SA1111)) == 0)
  160. break;
  161. /*
  162. * Since there is no individual mask, we have to
  163. * mask the parent IRQ. This is safe, since we'll
  164. * recheck the register for any pending IRQs.
  165. */
  166. if (irr & (IRR_ETHERNET | IRR_USAR)) {
  167. desc->irq_data.chip->irq_mask(&desc->irq_data);
  168. /*
  169. * Ack the interrupt now to prevent re-entering
  170. * this neponset handler. Again, this is safe
  171. * since we'll check the IRR register prior to
  172. * leaving.
  173. */
  174. desc->irq_data.chip->irq_ack(&desc->irq_data);
  175. if (irr & IRR_ETHERNET)
  176. generic_handle_irq(d->irq_base + NEP_IRQ_SMC91X);
  177. if (irr & IRR_USAR)
  178. generic_handle_irq(d->irq_base + NEP_IRQ_USAR);
  179. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  180. }
  181. if (irr & IRR_SA1111)
  182. generic_handle_irq(d->irq_base + NEP_IRQ_SA1111);
  183. }
  184. }
  185. /* Yes, we really do not have any kind of masking or unmasking */
  186. static void nochip_noop(struct irq_data *irq)
  187. {
  188. }
  189. static struct irq_chip nochip = {
  190. .name = "neponset",
  191. .irq_ack = nochip_noop,
  192. .irq_mask = nochip_noop,
  193. .irq_unmask = nochip_noop,
  194. };
  195. static struct sa1111_platform_data sa1111_info = {
  196. .disable_devs = SA1111_DEVID_PS2_MSE,
  197. };
  198. static int neponset_probe(struct platform_device *dev)
  199. {
  200. struct neponset_drvdata *d;
  201. struct resource *nep_res, *sa1111_res, *smc91x_res;
  202. struct resource sa1111_resources[] = {
  203. DEFINE_RES_MEM(0x40000000, SZ_8K),
  204. { .flags = IORESOURCE_IRQ },
  205. };
  206. struct platform_device_info sa1111_devinfo = {
  207. .parent = &dev->dev,
  208. .name = "sa1111",
  209. .id = 0,
  210. .res = sa1111_resources,
  211. .num_res = ARRAY_SIZE(sa1111_resources),
  212. .data = &sa1111_info,
  213. .size_data = sizeof(sa1111_info),
  214. .dma_mask = 0xffffffffUL,
  215. };
  216. struct resource smc91x_resources[] = {
  217. DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS,
  218. 0x02000000, "smc91x-regs"),
  219. DEFINE_RES_MEM_NAMED(SA1100_CS3_PHYS + 0x02000000,
  220. 0x02000000, "smc91x-attrib"),
  221. { .flags = IORESOURCE_IRQ },
  222. };
  223. struct smc91x_platdata smc91x_platdata = {
  224. .flags = SMC91X_USE_8BIT | SMC91X_IO_SHIFT_2 | SMC91X_NOWAIT,
  225. };
  226. struct platform_device_info smc91x_devinfo = {
  227. .parent = &dev->dev,
  228. .name = "smc91x",
  229. .id = 0,
  230. .res = smc91x_resources,
  231. .num_res = ARRAY_SIZE(smc91x_resources),
  232. .data = &smc91x_platdata,
  233. .size_data = sizeof(smc91x_platdata),
  234. };
  235. int ret, irq;
  236. if (nep_base)
  237. return -EBUSY;
  238. irq = ret = platform_get_irq(dev, 0);
  239. if (ret < 0)
  240. goto err_alloc;
  241. nep_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  242. smc91x_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
  243. sa1111_res = platform_get_resource(dev, IORESOURCE_MEM, 2);
  244. if (!nep_res || !smc91x_res || !sa1111_res) {
  245. ret = -ENXIO;
  246. goto err_alloc;
  247. }
  248. d = kzalloc(sizeof(*d), GFP_KERNEL);
  249. if (!d) {
  250. ret = -ENOMEM;
  251. goto err_alloc;
  252. }
  253. d->base = ioremap(nep_res->start, SZ_4K);
  254. if (!d->base) {
  255. ret = -ENOMEM;
  256. goto err_ioremap;
  257. }
  258. if (readb_relaxed(d->base + WHOAMI) != 0x11) {
  259. dev_warn(&dev->dev, "Neponset board detected, but wrong ID: %02x\n",
  260. readb_relaxed(d->base + WHOAMI));
  261. ret = -ENODEV;
  262. goto err_id;
  263. }
  264. ret = irq_alloc_descs(-1, IRQ_BOARD_START, NEP_IRQ_NR, -1);
  265. if (ret <= 0) {
  266. dev_err(&dev->dev, "unable to allocate %u irqs: %d\n",
  267. NEP_IRQ_NR, ret);
  268. if (ret == 0)
  269. ret = -ENOMEM;
  270. goto err_irq_alloc;
  271. }
  272. d->irq_base = ret;
  273. irq_set_chip_and_handler(d->irq_base + NEP_IRQ_SMC91X, &nochip,
  274. handle_simple_irq);
  275. irq_clear_status_flags(d->irq_base + NEP_IRQ_SMC91X, IRQ_NOREQUEST | IRQ_NOPROBE);
  276. irq_set_chip_and_handler(d->irq_base + NEP_IRQ_USAR, &nochip,
  277. handle_simple_irq);
  278. irq_clear_status_flags(d->irq_base + NEP_IRQ_USAR, IRQ_NOREQUEST | IRQ_NOPROBE);
  279. irq_set_chip(d->irq_base + NEP_IRQ_SA1111, &nochip);
  280. irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
  281. irq_set_chained_handler_and_data(irq, neponset_irq_handler, d);
  282. /*
  283. * We would set IRQ_GPIO25 to be a wake-up IRQ, but unfortunately
  284. * something on the Neponset activates this IRQ on sleep (eth?)
  285. */
  286. #if 0
  287. enable_irq_wake(irq);
  288. #endif
  289. dev_info(&dev->dev, "Neponset daughter board, providing IRQ%u-%u\n",
  290. d->irq_base, d->irq_base + NEP_IRQ_NR - 1);
  291. nep_base = d->base;
  292. sa1100_register_uart_fns(&neponset_port_fns);
  293. /* Ensure that the memory bus request/grant signals are setup */
  294. sa1110_mb_disable();
  295. /* Disable GPIO 0/1 drivers so the buttons work on the Assabet */
  296. writeb_relaxed(NCR_GP01_OFF, d->base + NCR_0);
  297. sa1111_resources[0].parent = sa1111_res;
  298. sa1111_resources[1].start = d->irq_base + NEP_IRQ_SA1111;
  299. sa1111_resources[1].end = d->irq_base + NEP_IRQ_SA1111;
  300. d->sa1111 = platform_device_register_full(&sa1111_devinfo);
  301. smc91x_resources[0].parent = smc91x_res;
  302. smc91x_resources[1].parent = smc91x_res;
  303. smc91x_resources[2].start = d->irq_base + NEP_IRQ_SMC91X;
  304. smc91x_resources[2].end = d->irq_base + NEP_IRQ_SMC91X;
  305. d->smc91x = platform_device_register_full(&smc91x_devinfo);
  306. platform_set_drvdata(dev, d);
  307. return 0;
  308. err_irq_alloc:
  309. err_id:
  310. iounmap(d->base);
  311. err_ioremap:
  312. kfree(d);
  313. err_alloc:
  314. return ret;
  315. }
  316. static int neponset_remove(struct platform_device *dev)
  317. {
  318. struct neponset_drvdata *d = platform_get_drvdata(dev);
  319. int irq = platform_get_irq(dev, 0);
  320. if (!IS_ERR(d->sa1111))
  321. platform_device_unregister(d->sa1111);
  322. if (!IS_ERR(d->smc91x))
  323. platform_device_unregister(d->smc91x);
  324. irq_set_chained_handler(irq, NULL);
  325. irq_free_descs(d->irq_base, NEP_IRQ_NR);
  326. nep_base = NULL;
  327. iounmap(d->base);
  328. kfree(d);
  329. return 0;
  330. }
  331. #ifdef CONFIG_PM_SLEEP
  332. static int neponset_suspend(struct device *dev)
  333. {
  334. struct neponset_drvdata *d = dev_get_drvdata(dev);
  335. d->ncr0 = readb_relaxed(d->base + NCR_0);
  336. d->mdm_ctl_0 = readb_relaxed(d->base + MDM_CTL_0);
  337. return 0;
  338. }
  339. static int neponset_resume(struct device *dev)
  340. {
  341. struct neponset_drvdata *d = dev_get_drvdata(dev);
  342. writeb_relaxed(d->ncr0, d->base + NCR_0);
  343. writeb_relaxed(d->mdm_ctl_0, d->base + MDM_CTL_0);
  344. return 0;
  345. }
  346. static const struct dev_pm_ops neponset_pm_ops = {
  347. .suspend_noirq = neponset_suspend,
  348. .resume_noirq = neponset_resume,
  349. .freeze_noirq = neponset_suspend,
  350. .restore_noirq = neponset_resume,
  351. };
  352. #define PM_OPS &neponset_pm_ops
  353. #else
  354. #define PM_OPS NULL
  355. #endif
  356. static struct platform_driver neponset_device_driver = {
  357. .probe = neponset_probe,
  358. .remove = neponset_remove,
  359. .driver = {
  360. .name = "neponset",
  361. .pm = PM_OPS,
  362. },
  363. };
  364. static int __init neponset_init(void)
  365. {
  366. return platform_driver_register(&neponset_device_driver);
  367. }
  368. subsys_initcall(neponset_init);