eisa.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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_mask_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_unmask_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 struct irq_chip eisa_interrupt_type = {
  161. .name = "EISA",
  162. .unmask = eisa_unmask_irq,
  163. .mask = eisa_mask_irq,
  164. };
  165. static irqreturn_t eisa_irq(int wax_irq, void *intr_dev)
  166. {
  167. int irq = gsc_readb(0xfc01f000); /* EISA supports 16 irqs */
  168. unsigned long flags;
  169. spin_lock_irqsave(&eisa_irq_lock, flags);
  170. /* read IRR command */
  171. eisa_out8(0x0a, 0x20);
  172. eisa_out8(0x0a, 0xa0);
  173. EISA_DBG("irq IAR %02x 8259-1 irr %02x 8259-2 irr %02x\n",
  174. irq, eisa_in8(0x20), eisa_in8(0xa0));
  175. /* read ISR command */
  176. eisa_out8(0x0a, 0x20);
  177. eisa_out8(0x0a, 0xa0);
  178. EISA_DBG("irq 8259-1 isr %02x imr %02x 8259-2 isr %02x imr %02x\n",
  179. eisa_in8(0x20), eisa_in8(0x21), eisa_in8(0xa0), eisa_in8(0xa1));
  180. irq &= 0xf;
  181. /* mask irq and write eoi */
  182. if (irq & 8) {
  183. slave_mask |= (1 << (irq&7));
  184. eisa_out8(slave_mask, 0xa1);
  185. eisa_out8(0x60 | (irq&7),0xa0);/* 'Specific EOI' to slave */
  186. eisa_out8(0x62,0x20); /* 'Specific EOI' to master-IRQ2 */
  187. } else {
  188. master_mask |= (1 << (irq&7));
  189. eisa_out8(master_mask, 0x21);
  190. eisa_out8(0x60|irq,0x20); /* 'Specific EOI' to master */
  191. }
  192. spin_unlock_irqrestore(&eisa_irq_lock, flags);
  193. generic_handle_irq(irq);
  194. spin_lock_irqsave(&eisa_irq_lock, flags);
  195. /* unmask */
  196. if (irq & 8) {
  197. slave_mask &= ~(1 << (irq&7));
  198. eisa_out8(slave_mask, 0xa1);
  199. } else {
  200. master_mask &= ~(1 << (irq&7));
  201. eisa_out8(master_mask, 0x21);
  202. }
  203. spin_unlock_irqrestore(&eisa_irq_lock, flags);
  204. return IRQ_HANDLED;
  205. }
  206. static irqreturn_t dummy_irq2_handler(int _, void *dev)
  207. {
  208. printk(KERN_ALERT "eisa: uhh, irq2?\n");
  209. return IRQ_HANDLED;
  210. }
  211. static struct irqaction irq2_action = {
  212. .handler = dummy_irq2_handler,
  213. .name = "cascade",
  214. };
  215. static void init_eisa_pic(void)
  216. {
  217. unsigned long flags;
  218. spin_lock_irqsave(&eisa_irq_lock, flags);
  219. eisa_out8(0xff, 0x21); /* mask during init */
  220. eisa_out8(0xff, 0xa1); /* mask during init */
  221. /* master pic */
  222. eisa_out8(0x11,0x20); /* ICW1 */
  223. eisa_out8(0x00,0x21); /* ICW2 */
  224. eisa_out8(0x04,0x21); /* ICW3 */
  225. eisa_out8(0x01,0x21); /* ICW4 */
  226. eisa_out8(0x40,0x20); /* OCW2 */
  227. /* slave pic */
  228. eisa_out8(0x11,0xa0); /* ICW1 */
  229. eisa_out8(0x08,0xa1); /* ICW2 */
  230. eisa_out8(0x02,0xa1); /* ICW3 */
  231. eisa_out8(0x01,0xa1); /* ICW4 */
  232. eisa_out8(0x40,0xa0); /* OCW2 */
  233. udelay(100);
  234. slave_mask = 0xff;
  235. master_mask = 0xfb;
  236. eisa_out8(slave_mask, 0xa1); /* OCW1 */
  237. eisa_out8(master_mask, 0x21); /* OCW1 */
  238. /* setup trig level */
  239. EISA_DBG("EISA edge/level %04x\n", eisa_irq_level);
  240. eisa_out8(eisa_irq_level&0xff, 0x4d0); /* Set all irq's to edge */
  241. eisa_out8((eisa_irq_level >> 8) & 0xff, 0x4d1);
  242. EISA_DBG("pic0 mask %02x\n", eisa_in8(0x21));
  243. EISA_DBG("pic1 mask %02x\n", eisa_in8(0xa1));
  244. EISA_DBG("pic0 edge/level %02x\n", eisa_in8(0x4d0));
  245. EISA_DBG("pic1 edge/level %02x\n", eisa_in8(0x4d1));
  246. spin_unlock_irqrestore(&eisa_irq_lock, flags);
  247. }
  248. /* Device initialisation */
  249. #define is_mongoose(dev) (dev->id.sversion == 0x00076)
  250. static int __init eisa_probe(struct parisc_device *dev)
  251. {
  252. int i, result;
  253. char *name = is_mongoose(dev) ? "Mongoose" : "Wax";
  254. printk(KERN_INFO "%s EISA Adapter found at 0x%08lx\n",
  255. name, (unsigned long)dev->hpa.start);
  256. eisa_dev.hba.dev = dev;
  257. eisa_dev.hba.iommu = ccio_get_iommu(dev);
  258. eisa_dev.hba.lmmio_space.name = "EISA";
  259. eisa_dev.hba.lmmio_space.start = F_EXTEND(0xfc000000);
  260. eisa_dev.hba.lmmio_space.end = F_EXTEND(0xffbfffff);
  261. eisa_dev.hba.lmmio_space.flags = IORESOURCE_MEM;
  262. result = ccio_request_resource(dev, &eisa_dev.hba.lmmio_space);
  263. if (result < 0) {
  264. printk(KERN_ERR "EISA: failed to claim EISA Bus address space!\n");
  265. return result;
  266. }
  267. eisa_dev.hba.io_space.name = "EISA";
  268. eisa_dev.hba.io_space.start = 0;
  269. eisa_dev.hba.io_space.end = 0xffff;
  270. eisa_dev.hba.lmmio_space.flags = IORESOURCE_IO;
  271. result = request_resource(&ioport_resource, &eisa_dev.hba.io_space);
  272. if (result < 0) {
  273. printk(KERN_ERR "EISA: failed to claim EISA Bus port space!\n");
  274. return result;
  275. }
  276. pcibios_register_hba(&eisa_dev.hba);
  277. result = request_irq(dev->irq, eisa_irq, IRQF_SHARED, "EISA", &eisa_dev);
  278. if (result) {
  279. printk(KERN_ERR "EISA: request_irq failed!\n");
  280. return result;
  281. }
  282. /* Reserve IRQ2 */
  283. setup_irq(2, &irq2_action);
  284. for (i = 0; i < 16; i++) {
  285. set_irq_chip_and_handler(i, &eisa_interrupt_type,
  286. handle_simple_irq);
  287. }
  288. EISA_bus = 1;
  289. if (dev->num_addrs) {
  290. /* newer firmware hand out the eeprom address */
  291. eisa_dev.eeprom_addr = dev->addr[0];
  292. } else {
  293. /* old firmware, need to figure out the box */
  294. if (is_mongoose(dev)) {
  295. eisa_dev.eeprom_addr = SNAKES_EEPROM_BASE_ADDR;
  296. } else {
  297. eisa_dev.eeprom_addr = MIRAGE_EEPROM_BASE_ADDR;
  298. }
  299. }
  300. eisa_eeprom_addr = ioremap_nocache(eisa_dev.eeprom_addr, HPEE_MAX_LENGTH);
  301. result = eisa_enumerator(eisa_dev.eeprom_addr, &eisa_dev.hba.io_space,
  302. &eisa_dev.hba.lmmio_space);
  303. init_eisa_pic();
  304. if (result >= 0) {
  305. /* FIXME : Don't enumerate the bus twice. */
  306. eisa_dev.root.dev = &dev->dev;
  307. dev_set_drvdata(&dev->dev, &eisa_dev.root);
  308. eisa_dev.root.bus_base_addr = 0;
  309. eisa_dev.root.res = &eisa_dev.hba.io_space;
  310. eisa_dev.root.slots = result;
  311. eisa_dev.root.dma_mask = 0xffffffff; /* wild guess */
  312. if (eisa_root_register (&eisa_dev.root)) {
  313. printk(KERN_ERR "EISA: Failed to register EISA root\n");
  314. return -1;
  315. }
  316. }
  317. return 0;
  318. }
  319. static const struct parisc_device_id eisa_tbl[] = {
  320. { HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00076 }, /* Mongoose */
  321. { HPHW_BA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00090 }, /* Wax EISA */
  322. { 0, }
  323. };
  324. MODULE_DEVICE_TABLE(parisc, eisa_tbl);
  325. static struct parisc_driver eisa_driver = {
  326. .name = "eisa_ba",
  327. .id_table = eisa_tbl,
  328. .probe = eisa_probe,
  329. };
  330. void __init eisa_init(void)
  331. {
  332. register_parisc_driver(&eisa_driver);
  333. }
  334. static unsigned int eisa_irq_configured;
  335. void eisa_make_irq_level(int num)
  336. {
  337. if (eisa_irq_configured& (1<<num)) {
  338. printk(KERN_WARNING
  339. "IRQ %d polarity configured twice (last to level)\n",
  340. num);
  341. }
  342. eisa_irq_level |= (1<<num); /* set the corresponding bit */
  343. eisa_irq_configured |= (1<<num); /* set the corresponding bit */
  344. }
  345. void eisa_make_irq_edge(int num)
  346. {
  347. if (eisa_irq_configured& (1<<num)) {
  348. printk(KERN_WARNING
  349. "IRQ %d polarity configured twice (last to edge)\n",
  350. num);
  351. }
  352. eisa_irq_level &= ~(1<<num); /* clear the corresponding bit */
  353. eisa_irq_configured |= (1<<num); /* set the corresponding bit */
  354. }
  355. static int __init eisa_irq_setup(char *str)
  356. {
  357. char *cur = str;
  358. int val;
  359. EISA_DBG("IRQ setup\n");
  360. while (cur != NULL) {
  361. char *pe;
  362. val = (int) simple_strtoul(cur, &pe, 0);
  363. if (val > 15 || val < 0) {
  364. printk(KERN_ERR "eisa: EISA irq value are 0-15\n");
  365. continue;
  366. }
  367. if (val == 2) {
  368. val = 9;
  369. }
  370. eisa_make_irq_edge(val); /* clear the corresponding bit */
  371. EISA_DBG("setting IRQ %d to edge-triggered mode\n", val);
  372. if ((cur = strchr(cur, ','))) {
  373. cur++;
  374. } else {
  375. break;
  376. }
  377. }
  378. return 1;
  379. }
  380. __setup("eisa_irq_edge=", eisa_irq_setup);