floppy_64.h 19 KB

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