eisa.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * eisa.c - provide support for EISA adapters in PA-RISC machines
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Copyright (c) 2001 Matthew Wilcox for Hewlett Packard
  10. * Copyright (c) 2001 Daniel Engstrom <5116@telia.com>
  11. *
  12. * There are two distinct EISA adapters. Mongoose is found in machines
  13. * before the 712; then the Wax ASIC is used. To complicate matters, the
  14. * Wax ASIC also includes a PS/2 and RS-232 controller, but those are
  15. * dealt with elsewhere; this file is concerned only with the EISA portions
  16. * of Wax.
  17. *
  18. *
  19. * HINT:
  20. * -----
  21. * To allow an ISA card to work properly in the EISA slot you need to
  22. * set an edge trigger level. This may be done on the palo command line
  23. * by adding the kernel parameter "eisa_irq_edge=n,n2,[...]]", with
  24. * n and n2 as the irq levels you want to use.
  25. *
  26. * Example: "eisa_irq_edge=10,11" allows ISA cards to operate at
  27. * irq levels 10 and 11.
  28. */
  29. #include <linux/init.h>
  30. #include <linux/ioport.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/pci.h>
  35. #include <linux/sched.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/eisa.h>
  38. #include <asm/byteorder.h>
  39. #include <asm/io.h>
  40. #include <asm/hardware.h>
  41. #include <asm/processor.h>
  42. #include <asm/parisc-device.h>
  43. #include <asm/delay.h>
  44. #include <asm/eisa_bus.h>
  45. #include <asm/eisa_eeprom.h>
  46. #if 0
  47. #define EISA_DBG(msg, arg... ) printk(KERN_DEBUG "eisa: " msg , ## arg )
  48. #else
  49. #define EISA_DBG(msg, arg... )
  50. #endif
  51. #define SNAKES_EEPROM_BASE_ADDR 0xF0810400
  52. #define MIRAGE_EEPROM_BASE_ADDR 0xF00C0400
  53. static DEFINE_SPINLOCK(eisa_irq_lock);
  54. void __iomem *eisa_eeprom_addr __read_mostly;
  55. /* We can only have one EISA adapter in the system because neither
  56. * implementation can be flexed.
  57. */
  58. static struct eisa_ba {
  59. struct pci_hba_data hba;
  60. unsigned long eeprom_addr;
  61. struct eisa_root_device root;
  62. } eisa_dev;
  63. /* Port ops */
  64. static inline unsigned long eisa_permute(unsigned short port)
  65. {
  66. if (port & 0x300) {
  67. return 0xfc000000 | ((port & 0xfc00) >> 6)
  68. | ((port & 0x3f8) << 9) | (port & 7);
  69. } else {
  70. return 0xfc000000 | port;
  71. }
  72. }
  73. unsigned char eisa_in8(unsigned short port)
  74. {
  75. if (EISA_bus)
  76. return gsc_readb(eisa_permute(port));
  77. return 0xff;
  78. }
  79. unsigned short eisa_in16(unsigned short port)
  80. {
  81. if (EISA_bus)
  82. return le16_to_cpu(gsc_readw(eisa_permute(port)));
  83. return 0xffff;
  84. }
  85. unsigned int eisa_in32(unsigned short port)
  86. {
  87. if (EISA_bus)
  88. return le32_to_cpu(gsc_readl(eisa_permute(port)));
  89. return 0xffffffff;
  90. }
  91. void eisa_out8(unsigned char data, unsigned short port)
  92. {
  93. if (EISA_bus)
  94. gsc_writeb(data, eisa_permute(port));
  95. }
  96. void eisa_out16(unsigned short data, unsigned short port)
  97. {
  98. if (EISA_bus)
  99. gsc_writew(cpu_to_le16(data), eisa_permute(port));
  100. }
  101. void eisa_out32(unsigned int data, unsigned short port)
  102. {
  103. if (EISA_bus)
  104. gsc_writel(cpu_to_le32(data), eisa_permute(port));
  105. }
  106. #ifndef CONFIG_PCI
  107. /* We call these directly without PCI. See asm/io.h. */
  108. EXPORT_SYMBOL(eisa_in8);
  109. EXPORT_SYMBOL(eisa_in16);
  110. EXPORT_SYMBOL(eisa_in32);
  111. EXPORT_SYMBOL(eisa_out8);
  112. EXPORT_SYMBOL(eisa_out16);
  113. EXPORT_SYMBOL(eisa_out32);
  114. #endif
  115. /* Interrupt handling */
  116. /* cached interrupt mask registers */
  117. static int master_mask;
  118. static int slave_mask;
  119. /* the trig level can be set with the
  120. * eisa_irq_edge=n,n,n commandline parameter
  121. * We should really read this from the EEPROM
  122. * in the furure.
  123. */
  124. /* irq 13,8,2,1,0 must be edge */
  125. static unsigned int eisa_irq_level __read_mostly; /* default to edge triggered */
  126. /* called by free irq */
  127. static void eisa_disable_irq(unsigned int irq)
  128. {
  129. unsigned long flags;
  130. EISA_DBG("disable irq %d\n", irq);
  131. /* just mask for now */
  132. spin_lock_irqsave(&eisa_irq_lock, flags);
  133. if (irq & 8) {
  134. slave_mask |= (1 << (irq&7));
  135. eisa_out8(slave_mask, 0xa1);
  136. } else {
  137. master_mask |= (1 << (irq&7));
  138. eisa_out8(master_mask, 0x21);
  139. }
  140. spin_unlock_irqrestore(&eisa_irq_lock, flags);
  141. EISA_DBG("pic0 mask %02x\n", eisa_in8(0x21));
  142. EISA_DBG("pic1 mask %02x\n", eisa_in8(0xa1));
  143. }
  144. /* called by request irq */
  145. static void eisa_enable_irq(unsigned int irq)
  146. {
  147. unsigned long flags;
  148. EISA_DBG("enable irq %d\n", irq);
  149. spin_lock_irqsave(&eisa_irq_lock, flags);
  150. if (irq & 8) {
  151. slave_mask &= ~(1 << (irq&7));
  152. eisa_out8(slave_mask, 0xa1);
  153. } else {
  154. master_mask &= ~(1 << (irq&7));
  155. eisa_out8(master_mask, 0x21);
  156. }
  157. spin_unlock_irqrestore(&eisa_irq_lock, flags);
  158. EISA_DBG("pic0 mask %02x\n", eisa_in8(0x21));
  159. EISA_DBG("pic1 mask %02x\n", eisa_in8(0xa1));
  160. }
  161. static unsigned int eisa_startup_irq(unsigned int irq)
  162. {
  163. eisa_enable_irq(irq);
  164. return 0;
  165. }
  166. static struct hw_interrupt_type eisa_interrupt_type = {
  167. .typename = "EISA",
  168. .startup = eisa_startup_irq,
  169. .shutdown = eisa_disable_irq,
  170. .enable = eisa_enable_irq,
  171. .disable = eisa_disable_irq,
  172. .ack = no_ack_irq,
  173. .end = no_end_irq,
  174. };
  175. static irqreturn_t eisa_irq(int wax_irq, void *intr_dev, struct pt_regs *regs)
  176. {
  177. int irq = gsc_readb(0xfc01f000); /* EISA supports 16 irqs */
  178. unsigned long flags;
  179. spin_lock_irqsave(&eisa_irq_lock, flags);
  180. /* read IRR command */
  181. eisa_out8(0x0a, 0x20);
  182. eisa_out8(0x0a, 0xa0);
  183. EISA_DBG("irq IAR %02x 8259-1 irr %02x 8259-2 irr %02x\n",
  184. irq, eisa_in8(0x20), eisa_in8(0xa0));
  185. /* read ISR command */
  186. eisa_out8(0x0a, 0x20);
  187. eisa_out8(0x0a, 0xa0);
  188. EISA_DBG("irq 8259-1 isr %02x imr %02x 8259-2 isr %02x imr %02x\n",
  189. eisa_in8(0x20), eisa_in8(0x21), eisa_in8(0xa0), eisa_in8(0xa1));
  190. irq &= 0xf;
  191. /* mask irq and write eoi */
  192. if (irq & 8) {
  193. slave_mask |= (1 << (irq&7));
  194. eisa_out8(slave_mask, 0xa1);
  195. eisa_out8(0x60 | (irq&7),0xa0);/* 'Specific EOI' to slave */
  196. eisa_out8(0x62,0x20); /* 'Specific EOI' to master-IRQ2 */
  197. } else {
  198. master_mask |= (1 << (irq&7));
  199. eisa_out8(master_mask, 0x21);
  200. eisa_out8(0x60|irq,0x20); /* 'Specific EOI' to master */
  201. }
  202. spin_unlock_irqrestore(&eisa_irq_lock, flags);
  203. __do_IRQ(irq, regs);
  204. spin_lock_irqsave(&eisa_irq_lock, flags);
  205. /* unmask */
  206. if (irq & 8) {
  207. slave_mask &= ~(1 << (irq&7));
  208. eisa_out8(slave_mask, 0xa1);
  209. } else {
  210. master_mask &= ~(1 << (irq&7));
  211. eisa_out8(master_mask, 0x21);
  212. }
  213. spin_unlock_irqrestore(&eisa_irq_lock, flags);
  214. return IRQ_HANDLED;
  215. }
  216. static irqreturn_t dummy_irq2_handler(int _, void *dev, struct pt_regs *regs)
  217. {
  218. printk(KERN_ALERT "eisa: uhh, irq2?\n");
  219. return IRQ_HANDLED;
  220. }
  221. static struct irqaction irq2_action = {
  222. .handler = dummy_irq2_handler,
  223. .name = "cascade",
  224. };
  225. static void init_eisa_pic(void)
  226. {
  227. unsigned long flags;
  228. spin_lock_irqsave(&eisa_irq_lock, flags);
  229. eisa_out8(0xff, 0x21); /* mask during init */
  230. eisa_out8(0xff, 0xa1); /* mask during init */
  231. /* master pic */
  232. eisa_out8(0x11,0x20); /* ICW1 */
  233. eisa_out8(0x00,0x21); /* ICW2 */
  234. eisa_out8(0x04,0x21); /* ICW3 */
  235. eisa_out8(0x01,0x21); /* ICW4 */
  236. eisa_out8(0x40,0x20); /* OCW2 */
  237. /* slave pic */
  238. eisa_out8(0x11,0xa0); /* ICW1 */
  239. eisa_out8(0x08,0xa1); /* ICW2 */
  240. eisa_out8(0x02,0xa1); /* ICW3 */
  241. eisa_out8(0x01,0xa1); /* ICW4 */
  242. eisa_out8(0x40,0xa0); /* OCW2 */
  243. udelay(100);
  244. slave_mask = 0xff;
  245. master_mask = 0xfb;
  246. eisa_out8(slave_mask, 0xa1); /* OCW1 */
  247. eisa_out8(master_mask, 0x21); /* OCW1 */
  248. /* setup trig level */
  249. EISA_DBG("EISA edge/level %04x\n", eisa_irq_level);
  250. eisa_out8(eisa_irq_level&0xff, 0x4d0); /* Set all irq's to edge */
  251. eisa_out8((eisa_irq_level >> 8) & 0xff, 0x4d1);
  252. EISA_DBG("pic0 mask %02x\n", eisa_in8(0x21));
  253. EISA_DBG("pic1 mask %02x\n", eisa_in8(0xa1));
  254. EISA_DBG("pic0 edge/level %02x\n", eisa_in8(0x4d0));
  255. EISA_DBG("pic1 edge/level %02x\n", eisa_in8(0x4d1));
  256. spin_unlock_irqrestore(&eisa_irq_lock, flags);
  257. }
  258. /* Device initialisation */
  259. #define is_mongoose(dev) (dev->id.sversion == 0x00076)
  260. static int __devinit eisa_probe(struct parisc_device *dev)
  261. {
  262. int i, result;
  263. char *name = is_mongoose(dev) ? "Mongoose" : "Wax";
  264. printk(KERN_INFO "%s EISA Adapter found at 0x%08lx\n",
  265. name, dev->hpa.start);
  266. eisa_dev.hba.dev = dev;
  267. eisa_dev.hba.iommu = ccio_get_iommu(dev);
  268. eisa_dev.hba.lmmio_space.name = "EISA";
  269. eisa_dev.hba.lmmio_space.start = F_EXTEND(0xfc000000);
  270. eisa_dev.hba.lmmio_space.end = F_EXTEND(0xffbfffff);
  271. eisa_dev.hba.lmmio_space.flags = IORESOURCE_MEM;
  272. result = ccio_request_resource(dev, &eisa_dev.hba.lmmio_space);
  273. if (result < 0) {
  274. printk(KERN_ERR "EISA: failed to claim EISA Bus address space!\n");
  275. return result;
  276. }
  277. eisa_dev.hba.io_space.name = "EISA";
  278. eisa_dev.hba.io_space.start = 0;
  279. eisa_dev.hba.io_space.end = 0xffff;
  280. eisa_dev.hba.lmmio_space.flags = IORESOURCE_IO;
  281. result = request_resource(&ioport_resource, &eisa_dev.hba.io_space);
  282. if (result < 0) {
  283. printk(KERN_ERR "EISA: failed to claim EISA Bus port space!\n");
  284. return result;
  285. }
  286. pcibios_register_hba(&eisa_dev.hba);
  287. result = request_irq(dev->irq, eisa_irq, SA_SHIRQ, "EISA", &eisa_dev);
  288. if (result) {
  289. printk(KERN_ERR "EISA: request_irq failed!\n");
  290. return result;
  291. }
  292. /* Reserve IRQ2 */
  293. irq_desc[2].action = &irq2_action;
  294. for (i = 0; i < 16; i++) {
  295. irq_desc[i].handler = &eisa_interrupt_type;
  296. }
  297. EISA_bus = 1;
  298. if (dev->num_addrs) {
  299. /* newer firmware hand out the eeprom address */
  300. eisa_dev.eeprom_addr = dev->addr[0];
  301. } else {
  302. /* old firmware, need to figure out the box */
  303. if (is_mongoose(dev)) {
  304. eisa_dev.eeprom_addr = SNAKES_EEPROM_BASE_ADDR;
  305. } else {
  306. eisa_dev.eeprom_addr = MIRAGE_EEPROM_BASE_ADDR;
  307. }
  308. }
  309. eisa_eeprom_addr = ioremap_nocache(eisa_dev.eeprom_addr, HPEE_MAX_LENGTH);
  310. result = eisa_enumerator(eisa_dev.eeprom_addr, &eisa_dev.hba.io_space,
  311. &eisa_dev.hba.lmmio_space);
  312. init_eisa_pic();
  313. if (result >= 0) {
  314. /* FIXME : Don't enumerate the bus twice. */
  315. eisa_dev.root.dev = &dev->dev;
  316. dev->dev.driver_data = &eisa_dev.root;
  317. eisa_dev.root.bus_base_addr = 0;
  318. eisa_dev.root.res = &eisa_dev.hba.io_space;
  319. eisa_dev.root.slots = result;
  320. eisa_dev.root.dma_mask = 0xffffffff; /* wild guess */
  321. if (eisa_root_register (&eisa_dev.root)) {
  322. printk(KERN_ERR "EISA: Failed to register EISA root\n");
  323. return -1;
  324. }
  325. }
  326. return 0;
  327. }
  328. static struct parisc_device_id eisa_tbl[] = {
  329. { HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00076 }, /* Mongoose */
  330. { HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00090 }, /* Wax EISA */
  331. { 0, }
  332. };
  333. MODULE_DEVICE_TABLE(parisc, eisa_tbl);
  334. static struct parisc_driver eisa_driver = {
  335. .name = "eisa_ba",
  336. .id_table = eisa_tbl,
  337. .probe = eisa_probe,
  338. };
  339. void __init eisa_init(void)
  340. {
  341. register_parisc_driver(&eisa_driver);
  342. }
  343. static unsigned int eisa_irq_configured;
  344. void eisa_make_irq_level(int num)
  345. {
  346. if (eisa_irq_configured& (1<<num)) {
  347. printk(KERN_WARNING
  348. "IRQ %d polarity configured twice (last to level)\n",
  349. num);
  350. }
  351. eisa_irq_level |= (1<<num); /* set the corresponding bit */
  352. eisa_irq_configured |= (1<<num); /* set the corresponding bit */
  353. }
  354. void eisa_make_irq_edge(int num)
  355. {
  356. if (eisa_irq_configured& (1<<num)) {
  357. printk(KERN_WARNING
  358. "IRQ %d polarity configured twice (last to edge)\n",
  359. num);
  360. }
  361. eisa_irq_level &= ~(1<<num); /* clear the corresponding bit */
  362. eisa_irq_configured |= (1<<num); /* set the corresponding bit */
  363. }
  364. static int __init eisa_irq_setup(char *str)
  365. {
  366. char *cur = str;
  367. int val;
  368. EISA_DBG("IRQ setup\n");
  369. while (cur != NULL) {
  370. char *pe;
  371. val = (int) simple_strtoul(cur, &pe, 0);
  372. if (val > 15 || val < 0) {
  373. printk(KERN_ERR "eisa: EISA irq value are 0-15\n");
  374. continue;
  375. }
  376. if (val == 2) {
  377. val = 9;
  378. }
  379. eisa_make_irq_edge(val); /* clear the corresponding bit */
  380. EISA_DBG("setting IRQ %d to edge-triggered mode\n", val);
  381. if ((cur = strchr(cur, ','))) {
  382. cur++;
  383. } else {
  384. break;
  385. }
  386. }
  387. return 1;
  388. }
  389. __setup("eisa_irq_edge=", eisa_irq_setup);