eisa.c 12 KB

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