floppy.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. /* $Id: floppy.h,v 1.32 2001/10/26 17:59:36 davem Exp $
  2. * asm-sparc64/floppy.h: Sparc specific parts of the Floppy driver.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. *
  7. * Ultra/PCI support added: Sep 1997 Eddie C. Dost (ecd@skynet.be)
  8. */
  9. #ifndef __ASM_SPARC64_FLOPPY_H
  10. #define __ASM_SPARC64_FLOPPY_H
  11. #include <linux/config.h>
  12. #include <linux/init.h>
  13. #include <asm/page.h>
  14. #include <asm/pgtable.h>
  15. #include <asm/system.h>
  16. #include <asm/idprom.h>
  17. #include <asm/oplib.h>
  18. #include <asm/auxio.h>
  19. #include <asm/sbus.h>
  20. #include <asm/irq.h>
  21. /*
  22. * Define this to enable exchanging drive 0 and 1 if only drive 1 is
  23. * probed on PCI machines.
  24. */
  25. #undef PCI_FDC_SWAP_DRIVES
  26. /* References:
  27. * 1) Netbsd Sun floppy driver.
  28. * 2) NCR 82077 controller manual
  29. * 3) Intel 82077 controller manual
  30. */
  31. struct sun_flpy_controller {
  32. volatile unsigned char status1_82077; /* Auxiliary Status reg. 1 */
  33. volatile unsigned char status2_82077; /* Auxiliary Status reg. 2 */
  34. volatile unsigned char dor_82077; /* Digital Output reg. */
  35. volatile unsigned char tapectl_82077; /* Tape Control reg */
  36. volatile unsigned char status_82077; /* Main Status Register. */
  37. #define drs_82077 status_82077 /* Digital Rate Select reg. */
  38. volatile unsigned char data_82077; /* Data fifo. */
  39. volatile unsigned char ___unused;
  40. volatile unsigned char dir_82077; /* Digital Input reg. */
  41. #define dcr_82077 dir_82077 /* Config Control reg. */
  42. };
  43. /* You'll only ever find one controller on an Ultra anyways. */
  44. static struct sun_flpy_controller *sun_fdc = (struct sun_flpy_controller *)-1;
  45. unsigned long fdc_status;
  46. static struct sbus_dev *floppy_sdev = NULL;
  47. struct sun_floppy_ops {
  48. unsigned char (*fd_inb) (unsigned long port);
  49. void (*fd_outb) (unsigned char value, unsigned long port);
  50. void (*fd_enable_dma) (void);
  51. void (*fd_disable_dma) (void);
  52. void (*fd_set_dma_mode) (int);
  53. void (*fd_set_dma_addr) (char *);
  54. void (*fd_set_dma_count) (int);
  55. unsigned int (*get_dma_residue) (void);
  56. int (*fd_request_irq) (void);
  57. void (*fd_free_irq) (void);
  58. int (*fd_eject) (int);
  59. };
  60. static struct sun_floppy_ops sun_fdops;
  61. #define fd_inb(port) sun_fdops.fd_inb(port)
  62. #define fd_outb(value,port) sun_fdops.fd_outb(value,port)
  63. #define fd_enable_dma() sun_fdops.fd_enable_dma()
  64. #define fd_disable_dma() sun_fdops.fd_disable_dma()
  65. #define fd_request_dma() (0) /* nothing... */
  66. #define fd_free_dma() /* nothing... */
  67. #define fd_clear_dma_ff() /* nothing... */
  68. #define fd_set_dma_mode(mode) sun_fdops.fd_set_dma_mode(mode)
  69. #define fd_set_dma_addr(addr) sun_fdops.fd_set_dma_addr(addr)
  70. #define fd_set_dma_count(count) sun_fdops.fd_set_dma_count(count)
  71. #define get_dma_residue(x) sun_fdops.get_dma_residue()
  72. #define fd_cacheflush(addr, size) /* nothing... */
  73. #define fd_request_irq() sun_fdops.fd_request_irq()
  74. #define fd_free_irq() sun_fdops.fd_free_irq()
  75. #define fd_eject(drive) sun_fdops.fd_eject(drive)
  76. static int FLOPPY_MOTOR_MASK = 0x10;
  77. /* Super paranoid... */
  78. #undef HAVE_DISABLE_HLT
  79. static int sun_floppy_types[2] = { 0, 0 };
  80. /* Here is where we catch the floppy driver trying to initialize,
  81. * therefore this is where we call the PROM device tree probing
  82. * routine etc. on the Sparc.
  83. */
  84. #define FLOPPY0_TYPE sun_floppy_init()
  85. #define FLOPPY1_TYPE sun_floppy_types[1]
  86. #define FDC1 ((unsigned long)sun_fdc)
  87. #define N_FDC 1
  88. #define N_DRIVE 8
  89. /* No 64k boundary crossing problems on the Sparc. */
  90. #define CROSS_64KB(a,s) (0)
  91. static unsigned char sun_82077_fd_inb(unsigned long port)
  92. {
  93. udelay(5);
  94. switch(port & 7) {
  95. default:
  96. printk("floppy: Asked to read unknown port %lx\n", port);
  97. panic("floppy: Port bolixed.");
  98. case 4: /* FD_STATUS */
  99. return sbus_readb(&sun_fdc->status_82077) & ~STATUS_DMA;
  100. case 5: /* FD_DATA */
  101. return sbus_readb(&sun_fdc->data_82077);
  102. case 7: /* FD_DIR */
  103. /* XXX: Is DCL on 0x80 in sun4m? */
  104. return sbus_readb(&sun_fdc->dir_82077);
  105. };
  106. panic("sun_82072_fd_inb: How did I get here?");
  107. }
  108. static void sun_82077_fd_outb(unsigned char value, unsigned long port)
  109. {
  110. udelay(5);
  111. switch(port & 7) {
  112. default:
  113. printk("floppy: Asked to write to unknown port %lx\n", port);
  114. panic("floppy: Port bolixed.");
  115. case 2: /* FD_DOR */
  116. /* Happily, the 82077 has a real DOR register. */
  117. sbus_writeb(value, &sun_fdc->dor_82077);
  118. break;
  119. case 5: /* FD_DATA */
  120. sbus_writeb(value, &sun_fdc->data_82077);
  121. break;
  122. case 7: /* FD_DCR */
  123. sbus_writeb(value, &sun_fdc->dcr_82077);
  124. break;
  125. case 4: /* FD_STATUS */
  126. sbus_writeb(value, &sun_fdc->status_82077);
  127. break;
  128. };
  129. return;
  130. }
  131. /* For pseudo-dma (Sun floppy drives have no real DMA available to
  132. * them so we must eat the data fifo bytes directly ourselves) we have
  133. * three state variables. doing_pdma tells our inline low-level
  134. * assembly floppy interrupt entry point whether it should sit and eat
  135. * bytes from the fifo or just transfer control up to the higher level
  136. * floppy interrupt c-code. I tried very hard but I could not get the
  137. * pseudo-dma to work in c-code without getting many overruns and
  138. * underruns. If non-zero, doing_pdma encodes the direction of
  139. * the transfer for debugging. 1=read 2=write
  140. */
  141. char *pdma_vaddr;
  142. unsigned long pdma_size;
  143. volatile int doing_pdma = 0;
  144. /* This is software state */
  145. char *pdma_base = NULL;
  146. unsigned long pdma_areasize;
  147. /* Common routines to all controller types on the Sparc. */
  148. static void sun_fd_disable_dma(void)
  149. {
  150. doing_pdma = 0;
  151. if (pdma_base) {
  152. mmu_unlockarea(pdma_base, pdma_areasize);
  153. pdma_base = NULL;
  154. }
  155. }
  156. static void sun_fd_set_dma_mode(int mode)
  157. {
  158. switch(mode) {
  159. case DMA_MODE_READ:
  160. doing_pdma = 1;
  161. break;
  162. case DMA_MODE_WRITE:
  163. doing_pdma = 2;
  164. break;
  165. default:
  166. printk("Unknown dma mode %d\n", mode);
  167. panic("floppy: Giving up...");
  168. }
  169. }
  170. static void sun_fd_set_dma_addr(char *buffer)
  171. {
  172. pdma_vaddr = buffer;
  173. }
  174. static void sun_fd_set_dma_count(int length)
  175. {
  176. pdma_size = length;
  177. }
  178. static void sun_fd_enable_dma(void)
  179. {
  180. pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
  181. pdma_base = pdma_vaddr;
  182. pdma_areasize = pdma_size;
  183. }
  184. /* Our low-level entry point in arch/sparc/kernel/entry.S */
  185. extern irqreturn_t floppy_hardint(int irq, void *unused, struct pt_regs *regs);
  186. static int sun_fd_request_irq(void)
  187. {
  188. static int once = 0;
  189. int error;
  190. if(!once) {
  191. once = 1;
  192. error = request_fast_irq(FLOPPY_IRQ, floppy_hardint,
  193. SA_INTERRUPT, "floppy", NULL);
  194. return ((error == 0) ? 0 : -1);
  195. }
  196. return 0;
  197. }
  198. static void sun_fd_free_irq(void)
  199. {
  200. }
  201. static unsigned int sun_get_dma_residue(void)
  202. {
  203. /* XXX This isn't really correct. XXX */
  204. return 0;
  205. }
  206. static int sun_fd_eject(int drive)
  207. {
  208. set_dor(0x00, 0xff, 0x90);
  209. udelay(500);
  210. set_dor(0x00, 0x6f, 0x00);
  211. udelay(500);
  212. return 0;
  213. }
  214. #ifdef CONFIG_PCI
  215. #include <asm/ebus.h>
  216. #include <asm/isa.h>
  217. #include <asm/ns87303.h>
  218. static struct ebus_dma_info sun_pci_fd_ebus_dma;
  219. static struct pci_dev *sun_pci_ebus_dev;
  220. static int sun_pci_broken_drive = -1;
  221. struct sun_pci_dma_op {
  222. unsigned int addr;
  223. int len;
  224. int direction;
  225. char *buf;
  226. };
  227. static struct sun_pci_dma_op sun_pci_dma_current = { -1U, 0, 0, NULL};
  228. static struct sun_pci_dma_op sun_pci_dma_pending = { -1U, 0, 0, NULL};
  229. extern irqreturn_t floppy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  230. static unsigned char sun_pci_fd_inb(unsigned long port)
  231. {
  232. udelay(5);
  233. return inb(port);
  234. }
  235. static void sun_pci_fd_outb(unsigned char val, unsigned long port)
  236. {
  237. udelay(5);
  238. outb(val, port);
  239. }
  240. static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
  241. {
  242. udelay(5);
  243. /*
  244. * XXX: Due to SUN's broken floppy connector on AX and AXi
  245. * we need to turn on MOTOR_0 also, if the floppy is
  246. * jumpered to DS1 (like most PC floppies are). I hope
  247. * this does not hurt correct hardware like the AXmp.
  248. * (Eddie, Sep 12 1998).
  249. */
  250. if (port == ((unsigned long)sun_fdc) + 2) {
  251. if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
  252. val |= 0x10;
  253. }
  254. }
  255. outb(val, port);
  256. }
  257. #ifdef PCI_FDC_SWAP_DRIVES
  258. static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
  259. {
  260. udelay(5);
  261. /*
  262. * XXX: Due to SUN's broken floppy connector on AX and AXi
  263. * we need to turn on MOTOR_0 also, if the floppy is
  264. * jumpered to DS1 (like most PC floppies are). I hope
  265. * this does not hurt correct hardware like the AXmp.
  266. * (Eddie, Sep 12 1998).
  267. */
  268. if (port == ((unsigned long)sun_fdc) + 2) {
  269. if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
  270. val &= ~(0x03);
  271. val |= 0x21;
  272. }
  273. }
  274. outb(val, port);
  275. }
  276. #endif /* PCI_FDC_SWAP_DRIVES */
  277. static void sun_pci_fd_enable_dma(void)
  278. {
  279. BUG_ON((NULL == sun_pci_dma_pending.buf) ||
  280. (0 == sun_pci_dma_pending.len) ||
  281. (0 == sun_pci_dma_pending.direction));
  282. sun_pci_dma_current.buf = sun_pci_dma_pending.buf;
  283. sun_pci_dma_current.len = sun_pci_dma_pending.len;
  284. sun_pci_dma_current.direction = sun_pci_dma_pending.direction;
  285. sun_pci_dma_pending.buf = NULL;
  286. sun_pci_dma_pending.len = 0;
  287. sun_pci_dma_pending.direction = 0;
  288. sun_pci_dma_pending.addr = -1U;
  289. sun_pci_dma_current.addr =
  290. pci_map_single(sun_pci_ebus_dev,
  291. sun_pci_dma_current.buf,
  292. sun_pci_dma_current.len,
  293. sun_pci_dma_current.direction);
  294. ebus_dma_enable(&sun_pci_fd_ebus_dma, 1);
  295. if (ebus_dma_request(&sun_pci_fd_ebus_dma,
  296. sun_pci_dma_current.addr,
  297. sun_pci_dma_current.len))
  298. BUG();
  299. }
  300. static void sun_pci_fd_disable_dma(void)
  301. {
  302. ebus_dma_enable(&sun_pci_fd_ebus_dma, 0);
  303. if (sun_pci_dma_current.addr != -1U)
  304. pci_unmap_single(sun_pci_ebus_dev,
  305. sun_pci_dma_current.addr,
  306. sun_pci_dma_current.len,
  307. sun_pci_dma_current.direction);
  308. sun_pci_dma_current.addr = -1U;
  309. }
  310. static void sun_pci_fd_set_dma_mode(int mode)
  311. {
  312. if (mode == DMA_MODE_WRITE)
  313. sun_pci_dma_pending.direction = PCI_DMA_TODEVICE;
  314. else
  315. sun_pci_dma_pending.direction = PCI_DMA_FROMDEVICE;
  316. ebus_dma_prepare(&sun_pci_fd_ebus_dma, mode != DMA_MODE_WRITE);
  317. }
  318. static void sun_pci_fd_set_dma_count(int length)
  319. {
  320. sun_pci_dma_pending.len = length;
  321. }
  322. static void sun_pci_fd_set_dma_addr(char *buffer)
  323. {
  324. sun_pci_dma_pending.buf = buffer;
  325. }
  326. static unsigned int sun_pci_get_dma_residue(void)
  327. {
  328. return ebus_dma_residue(&sun_pci_fd_ebus_dma);
  329. }
  330. static int sun_pci_fd_request_irq(void)
  331. {
  332. return ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 1);
  333. }
  334. static void sun_pci_fd_free_irq(void)
  335. {
  336. ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 0);
  337. }
  338. static int sun_pci_fd_eject(int drive)
  339. {
  340. return -EINVAL;
  341. }
  342. void sun_pci_fd_dma_callback(struct ebus_dma_info *p, int event, void *cookie)
  343. {
  344. floppy_interrupt(0, NULL, NULL);
  345. }
  346. /*
  347. * Floppy probing, we'd like to use /dev/fd0 for a single Floppy on PCI,
  348. * even if this is configured using DS1, thus looks like /dev/fd1 with
  349. * the cabling used in Ultras.
  350. */
  351. #define DOR (port + 2)
  352. #define MSR (port + 4)
  353. #define FIFO (port + 5)
  354. static void sun_pci_fd_out_byte(unsigned long port, unsigned char val,
  355. unsigned long reg)
  356. {
  357. unsigned char status;
  358. int timeout = 1000;
  359. while (!((status = inb(MSR)) & 0x80) && --timeout)
  360. udelay(100);
  361. outb(val, reg);
  362. }
  363. static unsigned char sun_pci_fd_sensei(unsigned long port)
  364. {
  365. unsigned char result[2] = { 0x70, 0x00 };
  366. unsigned char status;
  367. int i = 0;
  368. sun_pci_fd_out_byte(port, 0x08, FIFO);
  369. do {
  370. int timeout = 1000;
  371. while (!((status = inb(MSR)) & 0x80) && --timeout)
  372. udelay(100);
  373. if (!timeout)
  374. break;
  375. if ((status & 0xf0) == 0xd0)
  376. result[i++] = inb(FIFO);
  377. else
  378. break;
  379. } while (i < 2);
  380. return result[0];
  381. }
  382. static void sun_pci_fd_reset(unsigned long port)
  383. {
  384. unsigned char mask = 0x00;
  385. unsigned char status;
  386. int timeout = 10000;
  387. outb(0x80, MSR);
  388. do {
  389. status = sun_pci_fd_sensei(port);
  390. if ((status & 0xc0) == 0xc0)
  391. mask |= 1 << (status & 0x03);
  392. else
  393. udelay(100);
  394. } while ((mask != 0x0f) && --timeout);
  395. }
  396. static int sun_pci_fd_test_drive(unsigned long port, int drive)
  397. {
  398. unsigned char status, data;
  399. int timeout = 1000;
  400. int ready;
  401. sun_pci_fd_reset(port);
  402. data = (0x10 << drive) | 0x0c | drive;
  403. sun_pci_fd_out_byte(port, data, DOR);
  404. sun_pci_fd_out_byte(port, 0x07, FIFO);
  405. sun_pci_fd_out_byte(port, drive & 0x03, FIFO);
  406. do {
  407. udelay(100);
  408. status = sun_pci_fd_sensei(port);
  409. } while (((status & 0xc0) == 0x80) && --timeout);
  410. if (!timeout)
  411. ready = 0;
  412. else
  413. ready = (status & 0x10) ? 0 : 1;
  414. sun_pci_fd_reset(port);
  415. return ready;
  416. }
  417. #undef FIFO
  418. #undef MSR
  419. #undef DOR
  420. #endif /* CONFIG_PCI */
  421. #ifdef CONFIG_PCI
  422. static int __init ebus_fdthree_p(struct linux_ebus_device *edev)
  423. {
  424. if (!strcmp(edev->prom_name, "fdthree"))
  425. return 1;
  426. if (!strcmp(edev->prom_name, "floppy")) {
  427. char compat[16];
  428. prom_getstring(edev->prom_node,
  429. "compatible",
  430. compat, sizeof(compat));
  431. compat[15] = '\0';
  432. if (!strcmp(compat, "fdthree"))
  433. return 1;
  434. }
  435. return 0;
  436. }
  437. #endif
  438. #ifdef CONFIG_PCI
  439. #undef ISA_FLOPPY_WORKS
  440. #ifdef ISA_FLOPPY_WORKS
  441. static unsigned long __init isa_floppy_init(void)
  442. {
  443. struct sparc_isa_bridge *isa_br;
  444. struct sparc_isa_device *isa_dev = NULL;
  445. for_each_isa(isa_br) {
  446. for_each_isadev(isa_dev, isa_br) {
  447. if (!strcmp(isa_dev->prom_name, "dma")) {
  448. struct sparc_isa_device *child =
  449. isa_dev->child;
  450. while (child) {
  451. if (!strcmp(child->prom_name,
  452. "floppy")) {
  453. isa_dev = child;
  454. goto isa_done;
  455. }
  456. child = child->next;
  457. }
  458. }
  459. }
  460. }
  461. isa_done:
  462. if (!isa_dev)
  463. return 0;
  464. /* We could use DMA on devices behind the ISA bridge, but...
  465. *
  466. * There is a slight problem. Normally on x86 kit the x86 processor
  467. * delays I/O port instructions when the ISA bus "dma in progress"
  468. * signal is active. Well, sparc64 systems do not monitor this
  469. * signal thus we would need to block all I/O port accesses in software
  470. * when a dma transfer is active for some device.
  471. */
  472. sun_fdc = (struct sun_flpy_controller *)isa_dev->resource.start;
  473. FLOPPY_IRQ = isa_dev->irq;
  474. sun_fdops.fd_inb = sun_pci_fd_inb;
  475. sun_fdops.fd_outb = sun_pci_fd_outb;
  476. can_use_virtual_dma = use_virtual_dma = 1;
  477. sun_fdops.fd_enable_dma = sun_fd_enable_dma;
  478. sun_fdops.fd_disable_dma = sun_fd_disable_dma;
  479. sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
  480. sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
  481. sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
  482. sun_fdops.get_dma_residue = sun_get_dma_residue;
  483. sun_fdops.fd_request_irq = sun_fd_request_irq;
  484. sun_fdops.fd_free_irq = sun_fd_free_irq;
  485. /* Floppy eject is manual. Actually, could determine this
  486. * via presence of 'manual' property in OBP node.
  487. */
  488. sun_fdops.fd_eject = sun_pci_fd_eject;
  489. fdc_status = (unsigned long) &sun_fdc->status_82077;
  490. FLOPPY_MOTOR_MASK = 0xf0;
  491. allowed_drive_mask = 0;
  492. sun_floppy_types[0] = 0;
  493. sun_floppy_types[1] = 4;
  494. sun_pci_broken_drive = 1;
  495. sun_fdops.fd_outb = sun_pci_fd_broken_outb;
  496. return sun_floppy_types[0];
  497. }
  498. #endif /* ISA_FLOPPY_WORKS */
  499. #endif
  500. static unsigned long __init sun_floppy_init(void)
  501. {
  502. char state[128];
  503. struct sbus_bus *bus;
  504. struct sbus_dev *sdev = NULL;
  505. static int initialized = 0;
  506. if (initialized)
  507. return sun_floppy_types[0];
  508. initialized = 1;
  509. for_all_sbusdev (sdev, bus) {
  510. if (!strcmp(sdev->prom_name, "SUNW,fdtwo"))
  511. break;
  512. }
  513. if(sdev) {
  514. floppy_sdev = sdev;
  515. FLOPPY_IRQ = sdev->irqs[0];
  516. } else {
  517. #ifdef CONFIG_PCI
  518. struct linux_ebus *ebus;
  519. struct linux_ebus_device *edev = NULL;
  520. unsigned long config = 0;
  521. unsigned long auxio_reg;
  522. for_each_ebus(ebus) {
  523. for_each_ebusdev(edev, ebus) {
  524. if (ebus_fdthree_p(edev))
  525. goto ebus_done;
  526. }
  527. }
  528. ebus_done:
  529. if (!edev) {
  530. #ifdef ISA_FLOPPY_WORKS
  531. return isa_floppy_init();
  532. #else
  533. return 0;
  534. #endif
  535. }
  536. prom_getproperty(edev->prom_node, "status",
  537. state, sizeof(state));
  538. if (!strncmp(state, "disabled", 8))
  539. return 0;
  540. FLOPPY_IRQ = edev->irqs[0];
  541. /* Make sure the high density bit is set, some systems
  542. * (most notably Ultra5/Ultra10) come up with it clear.
  543. */
  544. auxio_reg = edev->resource[2].start;
  545. writel(readl(auxio_reg)|0x2, auxio_reg);
  546. sun_pci_ebus_dev = ebus->self;
  547. spin_lock_init(&sun_pci_fd_ebus_dma.lock);
  548. /* XXX ioremap */
  549. sun_pci_fd_ebus_dma.regs = edev->resource[1].start;
  550. if (!sun_pci_fd_ebus_dma.regs)
  551. return 0;
  552. sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER |
  553. EBUS_DMA_FLAG_TCI_DISABLE);
  554. sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback;
  555. sun_pci_fd_ebus_dma.client_cookie = NULL;
  556. sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
  557. strcpy(sun_pci_fd_ebus_dma.name, "floppy");
  558. if (ebus_dma_register(&sun_pci_fd_ebus_dma))
  559. return 0;
  560. /* XXX ioremap */
  561. sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start;
  562. sun_fdops.fd_inb = sun_pci_fd_inb;
  563. sun_fdops.fd_outb = sun_pci_fd_outb;
  564. can_use_virtual_dma = use_virtual_dma = 0;
  565. sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma;
  566. sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma;
  567. sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode;
  568. sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr;
  569. sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count;
  570. sun_fdops.get_dma_residue = sun_pci_get_dma_residue;
  571. sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
  572. sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
  573. sun_fdops.fd_eject = sun_pci_fd_eject;
  574. fdc_status = (unsigned long) &sun_fdc->status_82077;
  575. FLOPPY_MOTOR_MASK = 0xf0;
  576. /*
  577. * XXX: Find out on which machines this is really needed.
  578. */
  579. if (1) {
  580. sun_pci_broken_drive = 1;
  581. sun_fdops.fd_outb = sun_pci_fd_broken_outb;
  582. }
  583. allowed_drive_mask = 0;
  584. if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 0))
  585. sun_floppy_types[0] = 4;
  586. if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 1))
  587. sun_floppy_types[1] = 4;
  588. /*
  589. * Find NS87303 SuperIO config registers (through ecpp).
  590. */
  591. for_each_ebus(ebus) {
  592. for_each_ebusdev(edev, ebus) {
  593. if (!strcmp(edev->prom_name, "ecpp")) {
  594. config = edev->resource[1].start;
  595. goto config_done;
  596. }
  597. }
  598. }
  599. config_done:
  600. /*
  601. * Sanity check, is this really the NS87303?
  602. */
  603. switch (config & 0x3ff) {
  604. case 0x02e:
  605. case 0x15c:
  606. case 0x26e:
  607. case 0x398:
  608. break;
  609. default:
  610. config = 0;
  611. }
  612. if (!config)
  613. return sun_floppy_types[0];
  614. /* Enable PC-AT mode. */
  615. ns87303_modify(config, ASC, 0, 0xc0);
  616. #ifdef PCI_FDC_SWAP_DRIVES
  617. /*
  618. * If only Floppy 1 is present, swap drives.
  619. */
  620. if (!sun_floppy_types[0] && sun_floppy_types[1]) {
  621. /*
  622. * Set the drive exchange bit in FCR on NS87303,
  623. * make shure other bits are sane before doing so.
  624. */
  625. ns87303_modify(config, FER, FER_EDM, 0);
  626. ns87303_modify(config, ASC, ASC_DRV2_SEL, 0);
  627. ns87303_modify(config, FCR, 0, FCR_LDE);
  628. config = sun_floppy_types[0];
  629. sun_floppy_types[0] = sun_floppy_types[1];
  630. sun_floppy_types[1] = config;
  631. if (sun_pci_broken_drive != -1) {
  632. sun_pci_broken_drive = 1 - sun_pci_broken_drive;
  633. sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb;
  634. }
  635. }
  636. #endif /* PCI_FDC_SWAP_DRIVES */
  637. return sun_floppy_types[0];
  638. #else
  639. return 0;
  640. #endif
  641. }
  642. prom_getproperty(sdev->prom_node, "status", state, sizeof(state));
  643. if(!strncmp(state, "disabled", 8))
  644. return 0;
  645. /*
  646. * We cannot do sbus_ioremap here: it does request_region,
  647. * which the generic floppy driver tries to do once again.
  648. * But we must use the sdev resource values as they have
  649. * had parent ranges applied.
  650. */
  651. sun_fdc = (struct sun_flpy_controller *)
  652. (sdev->resource[0].start +
  653. ((sdev->resource[0].flags & 0x1ffUL) << 32UL));
  654. /* Last minute sanity check... */
  655. if(sbus_readb(&sun_fdc->status1_82077) == 0xff) {
  656. sun_fdc = (struct sun_flpy_controller *)-1;
  657. return 0;
  658. }
  659. sun_fdops.fd_inb = sun_82077_fd_inb;
  660. sun_fdops.fd_outb = sun_82077_fd_outb;
  661. can_use_virtual_dma = use_virtual_dma = 1;
  662. sun_fdops.fd_enable_dma = sun_fd_enable_dma;
  663. sun_fdops.fd_disable_dma = sun_fd_disable_dma;
  664. sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
  665. sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
  666. sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
  667. sun_fdops.get_dma_residue = sun_get_dma_residue;
  668. sun_fdops.fd_request_irq = sun_fd_request_irq;
  669. sun_fdops.fd_free_irq = sun_fd_free_irq;
  670. sun_fdops.fd_eject = sun_fd_eject;
  671. fdc_status = (unsigned long) &sun_fdc->status_82077;
  672. /* Success... */
  673. allowed_drive_mask = 0x01;
  674. sun_floppy_types[0] = 4;
  675. sun_floppy_types[1] = 0;
  676. return sun_floppy_types[0];
  677. }
  678. #define EXTRA_FLOPPY_PARAMS
  679. #endif /* !(__ASM_SPARC64_FLOPPY_H) */