floppy_64.h 19 KB

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