eisa.c 12 KB

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