floppy_64.h 19 KB

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