floppy_64.h 19 KB

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