floppy.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. /* $Id: floppy.h,v 1.32 2001/10/26 17:59:36 davem Exp $
  2. * asm-sparc64/floppy.h: Sparc specific parts of the Floppy driver.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. *
  7. * Ultra/PCI support added: Sep 1997 Eddie C. Dost (ecd@skynet.be)
  8. */
  9. #ifndef __ASM_SPARC64_FLOPPY_H
  10. #define __ASM_SPARC64_FLOPPY_H
  11. #include <linux/init.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. static int FLOPPY_MOTOR_MASK = 0x10;
  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. extern irqreturn_t sparc_floppy_irq(int, void *, struct pt_regs *);
  184. static int sun_fd_request_irq(void)
  185. {
  186. static int once = 0;
  187. int error;
  188. if(!once) {
  189. once = 1;
  190. error = request_irq(FLOPPY_IRQ, sparc_floppy_irq,
  191. SA_INTERRUPT, "floppy", NULL);
  192. return ((error == 0) ? 0 : -1);
  193. }
  194. return 0;
  195. }
  196. static void sun_fd_free_irq(void)
  197. {
  198. }
  199. static unsigned int sun_get_dma_residue(void)
  200. {
  201. /* XXX This isn't really correct. XXX */
  202. return 0;
  203. }
  204. static int sun_fd_eject(int drive)
  205. {
  206. set_dor(0x00, 0xff, 0x90);
  207. udelay(500);
  208. set_dor(0x00, 0x6f, 0x00);
  209. udelay(500);
  210. return 0;
  211. }
  212. #ifdef CONFIG_PCI
  213. #include <asm/ebus.h>
  214. #include <asm/isa.h>
  215. #include <asm/ns87303.h>
  216. static struct ebus_dma_info sun_pci_fd_ebus_dma;
  217. static struct pci_dev *sun_pci_ebus_dev;
  218. static int sun_pci_broken_drive = -1;
  219. struct sun_pci_dma_op {
  220. unsigned int addr;
  221. int len;
  222. int direction;
  223. char *buf;
  224. };
  225. static struct sun_pci_dma_op sun_pci_dma_current = { -1U, 0, 0, NULL};
  226. static struct sun_pci_dma_op sun_pci_dma_pending = { -1U, 0, 0, NULL};
  227. extern irqreturn_t floppy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  228. static unsigned char sun_pci_fd_inb(unsigned long port)
  229. {
  230. udelay(5);
  231. return inb(port);
  232. }
  233. static void sun_pci_fd_outb(unsigned char val, unsigned long port)
  234. {
  235. udelay(5);
  236. outb(val, port);
  237. }
  238. static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
  239. {
  240. udelay(5);
  241. /*
  242. * XXX: Due to SUN's broken floppy connector on AX and AXi
  243. * we need to turn on MOTOR_0 also, if the floppy is
  244. * jumpered to DS1 (like most PC floppies are). I hope
  245. * this does not hurt correct hardware like the AXmp.
  246. * (Eddie, Sep 12 1998).
  247. */
  248. if (port == ((unsigned long)sun_fdc) + 2) {
  249. if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
  250. val |= 0x10;
  251. }
  252. }
  253. outb(val, port);
  254. }
  255. #ifdef PCI_FDC_SWAP_DRIVES
  256. static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
  257. {
  258. udelay(5);
  259. /*
  260. * XXX: Due to SUN's broken floppy connector on AX and AXi
  261. * we need to turn on MOTOR_0 also, if the floppy is
  262. * jumpered to DS1 (like most PC floppies are). I hope
  263. * this does not hurt correct hardware like the AXmp.
  264. * (Eddie, Sep 12 1998).
  265. */
  266. if (port == ((unsigned long)sun_fdc) + 2) {
  267. if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
  268. val &= ~(0x03);
  269. val |= 0x21;
  270. }
  271. }
  272. outb(val, port);
  273. }
  274. #endif /* PCI_FDC_SWAP_DRIVES */
  275. static void sun_pci_fd_enable_dma(void)
  276. {
  277. BUG_ON((NULL == sun_pci_dma_pending.buf) ||
  278. (0 == sun_pci_dma_pending.len) ||
  279. (0 == sun_pci_dma_pending.direction));
  280. sun_pci_dma_current.buf = sun_pci_dma_pending.buf;
  281. sun_pci_dma_current.len = sun_pci_dma_pending.len;
  282. sun_pci_dma_current.direction = sun_pci_dma_pending.direction;
  283. sun_pci_dma_pending.buf = NULL;
  284. sun_pci_dma_pending.len = 0;
  285. sun_pci_dma_pending.direction = 0;
  286. sun_pci_dma_pending.addr = -1U;
  287. sun_pci_dma_current.addr =
  288. pci_map_single(sun_pci_ebus_dev,
  289. sun_pci_dma_current.buf,
  290. sun_pci_dma_current.len,
  291. sun_pci_dma_current.direction);
  292. ebus_dma_enable(&sun_pci_fd_ebus_dma, 1);
  293. if (ebus_dma_request(&sun_pci_fd_ebus_dma,
  294. sun_pci_dma_current.addr,
  295. sun_pci_dma_current.len))
  296. BUG();
  297. }
  298. static void sun_pci_fd_disable_dma(void)
  299. {
  300. ebus_dma_enable(&sun_pci_fd_ebus_dma, 0);
  301. if (sun_pci_dma_current.addr != -1U)
  302. pci_unmap_single(sun_pci_ebus_dev,
  303. sun_pci_dma_current.addr,
  304. sun_pci_dma_current.len,
  305. sun_pci_dma_current.direction);
  306. sun_pci_dma_current.addr = -1U;
  307. }
  308. static void sun_pci_fd_set_dma_mode(int mode)
  309. {
  310. if (mode == DMA_MODE_WRITE)
  311. sun_pci_dma_pending.direction = PCI_DMA_TODEVICE;
  312. else
  313. sun_pci_dma_pending.direction = PCI_DMA_FROMDEVICE;
  314. ebus_dma_prepare(&sun_pci_fd_ebus_dma, mode != DMA_MODE_WRITE);
  315. }
  316. static void sun_pci_fd_set_dma_count(int length)
  317. {
  318. sun_pci_dma_pending.len = length;
  319. }
  320. static void sun_pci_fd_set_dma_addr(char *buffer)
  321. {
  322. sun_pci_dma_pending.buf = buffer;
  323. }
  324. static unsigned int sun_pci_get_dma_residue(void)
  325. {
  326. return ebus_dma_residue(&sun_pci_fd_ebus_dma);
  327. }
  328. static int sun_pci_fd_request_irq(void)
  329. {
  330. return ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 1);
  331. }
  332. static void sun_pci_fd_free_irq(void)
  333. {
  334. ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 0);
  335. }
  336. static int sun_pci_fd_eject(int drive)
  337. {
  338. return -EINVAL;
  339. }
  340. void sun_pci_fd_dma_callback(struct ebus_dma_info *p, int event, void *cookie)
  341. {
  342. floppy_interrupt(0, NULL, NULL);
  343. }
  344. /*
  345. * Floppy probing, we'd like to use /dev/fd0 for a single Floppy on PCI,
  346. * even if this is configured using DS1, thus looks like /dev/fd1 with
  347. * the cabling used in Ultras.
  348. */
  349. #define DOR (port + 2)
  350. #define MSR (port + 4)
  351. #define FIFO (port + 5)
  352. static void sun_pci_fd_out_byte(unsigned long port, unsigned char val,
  353. unsigned long reg)
  354. {
  355. unsigned char status;
  356. int timeout = 1000;
  357. while (!((status = inb(MSR)) & 0x80) && --timeout)
  358. udelay(100);
  359. outb(val, reg);
  360. }
  361. static unsigned char sun_pci_fd_sensei(unsigned long port)
  362. {
  363. unsigned char result[2] = { 0x70, 0x00 };
  364. unsigned char status;
  365. int i = 0;
  366. sun_pci_fd_out_byte(port, 0x08, FIFO);
  367. do {
  368. int timeout = 1000;
  369. while (!((status = inb(MSR)) & 0x80) && --timeout)
  370. udelay(100);
  371. if (!timeout)
  372. break;
  373. if ((status & 0xf0) == 0xd0)
  374. result[i++] = inb(FIFO);
  375. else
  376. break;
  377. } while (i < 2);
  378. return result[0];
  379. }
  380. static void sun_pci_fd_reset(unsigned long port)
  381. {
  382. unsigned char mask = 0x00;
  383. unsigned char status;
  384. int timeout = 10000;
  385. outb(0x80, MSR);
  386. do {
  387. status = sun_pci_fd_sensei(port);
  388. if ((status & 0xc0) == 0xc0)
  389. mask |= 1 << (status & 0x03);
  390. else
  391. udelay(100);
  392. } while ((mask != 0x0f) && --timeout);
  393. }
  394. static int sun_pci_fd_test_drive(unsigned long port, int drive)
  395. {
  396. unsigned char status, data;
  397. int timeout = 1000;
  398. int ready;
  399. sun_pci_fd_reset(port);
  400. data = (0x10 << drive) | 0x0c | drive;
  401. sun_pci_fd_out_byte(port, data, DOR);
  402. sun_pci_fd_out_byte(port, 0x07, FIFO);
  403. sun_pci_fd_out_byte(port, drive & 0x03, FIFO);
  404. do {
  405. udelay(100);
  406. status = sun_pci_fd_sensei(port);
  407. } while (((status & 0xc0) == 0x80) && --timeout);
  408. if (!timeout)
  409. ready = 0;
  410. else
  411. ready = (status & 0x10) ? 0 : 1;
  412. sun_pci_fd_reset(port);
  413. return ready;
  414. }
  415. #undef FIFO
  416. #undef MSR
  417. #undef DOR
  418. #endif /* CONFIG_PCI */
  419. #ifdef CONFIG_PCI
  420. static int __init ebus_fdthree_p(struct linux_ebus_device *edev)
  421. {
  422. if (!strcmp(edev->prom_node->name, "fdthree"))
  423. return 1;
  424. if (!strcmp(edev->prom_node->name, "floppy")) {
  425. char *compat;
  426. compat = of_get_property(edev->prom_node,
  427. "compatible", NULL);
  428. if (compat && !strcmp(compat, "fdthree"))
  429. return 1;
  430. }
  431. return 0;
  432. }
  433. #endif
  434. #ifdef CONFIG_PCI
  435. #undef ISA_FLOPPY_WORKS
  436. #ifdef ISA_FLOPPY_WORKS
  437. static unsigned long __init isa_floppy_init(void)
  438. {
  439. struct sparc_isa_bridge *isa_br;
  440. struct sparc_isa_device *isa_dev = NULL;
  441. for_each_isa(isa_br) {
  442. for_each_isadev(isa_dev, isa_br) {
  443. if (!strcmp(isa_dev->prom_node->name, "dma")) {
  444. struct sparc_isa_device *child =
  445. isa_dev->child;
  446. while (child) {
  447. if (!strcmp(child->prom_node->name,
  448. "floppy")) {
  449. isa_dev = child;
  450. goto isa_done;
  451. }
  452. child = child->next;
  453. }
  454. }
  455. }
  456. }
  457. isa_done:
  458. if (!isa_dev)
  459. return 0;
  460. /* We could use DMA on devices behind the ISA bridge, but...
  461. *
  462. * There is a slight problem. Normally on x86 kit the x86 processor
  463. * delays I/O port instructions when the ISA bus "dma in progress"
  464. * signal is active. Well, sparc64 systems do not monitor this
  465. * signal thus we would need to block all I/O port accesses in software
  466. * when a dma transfer is active for some device.
  467. */
  468. sun_fdc = (struct sun_flpy_controller *)isa_dev->resource.start;
  469. FLOPPY_IRQ = isa_dev->irq;
  470. sun_fdops.fd_inb = sun_pci_fd_inb;
  471. sun_fdops.fd_outb = sun_pci_fd_outb;
  472. can_use_virtual_dma = use_virtual_dma = 1;
  473. sun_fdops.fd_enable_dma = sun_fd_enable_dma;
  474. sun_fdops.fd_disable_dma = sun_fd_disable_dma;
  475. sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
  476. sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
  477. sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
  478. sun_fdops.get_dma_residue = sun_get_dma_residue;
  479. sun_fdops.fd_request_irq = sun_fd_request_irq;
  480. sun_fdops.fd_free_irq = sun_fd_free_irq;
  481. /* Floppy eject is manual. Actually, could determine this
  482. * via presence of 'manual' property in OBP node.
  483. */
  484. sun_fdops.fd_eject = sun_pci_fd_eject;
  485. fdc_status = (unsigned long) &sun_fdc->status_82077;
  486. FLOPPY_MOTOR_MASK = 0xf0;
  487. allowed_drive_mask = 0;
  488. sun_floppy_types[0] = 0;
  489. sun_floppy_types[1] = 4;
  490. sun_pci_broken_drive = 1;
  491. sun_fdops.fd_outb = sun_pci_fd_broken_outb;
  492. return sun_floppy_types[0];
  493. }
  494. #endif /* ISA_FLOPPY_WORKS */
  495. #endif
  496. static unsigned long __init sun_floppy_init(void)
  497. {
  498. char state[128];
  499. struct sbus_bus *bus;
  500. struct sbus_dev *sdev = NULL;
  501. static int initialized = 0;
  502. if (initialized)
  503. return sun_floppy_types[0];
  504. initialized = 1;
  505. for_all_sbusdev (sdev, bus) {
  506. if (!strcmp(sdev->prom_name, "SUNW,fdtwo"))
  507. break;
  508. }
  509. if(sdev) {
  510. floppy_sdev = sdev;
  511. FLOPPY_IRQ = sdev->irqs[0];
  512. } else {
  513. #ifdef CONFIG_PCI
  514. struct linux_ebus *ebus;
  515. struct linux_ebus_device *edev = NULL;
  516. unsigned long config = 0;
  517. void __iomem *auxio_reg;
  518. char *state_prop;
  519. for_each_ebus(ebus) {
  520. for_each_ebusdev(edev, ebus) {
  521. if (ebus_fdthree_p(edev))
  522. goto ebus_done;
  523. }
  524. }
  525. ebus_done:
  526. if (!edev) {
  527. #ifdef ISA_FLOPPY_WORKS
  528. return isa_floppy_init();
  529. #else
  530. return 0;
  531. #endif
  532. }
  533. state_prop = of_get_property(edev->prom_node, "status", NULL);
  534. if (state_prop && !strncmp(state_prop, "disabled", 8))
  535. return 0;
  536. FLOPPY_IRQ = edev->irqs[0];
  537. /* Make sure the high density bit is set, some systems
  538. * (most notably Ultra5/Ultra10) come up with it clear.
  539. */
  540. auxio_reg = (void __iomem *) edev->resource[2].start;
  541. writel(readl(auxio_reg)|0x2, auxio_reg);
  542. sun_pci_ebus_dev = ebus->self;
  543. spin_lock_init(&sun_pci_fd_ebus_dma.lock);
  544. /* XXX ioremap */
  545. sun_pci_fd_ebus_dma.regs = (void __iomem *)
  546. edev->resource[1].start;
  547. if (!sun_pci_fd_ebus_dma.regs)
  548. return 0;
  549. sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER |
  550. EBUS_DMA_FLAG_TCI_DISABLE);
  551. sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback;
  552. sun_pci_fd_ebus_dma.client_cookie = NULL;
  553. sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
  554. strcpy(sun_pci_fd_ebus_dma.name, "floppy");
  555. if (ebus_dma_register(&sun_pci_fd_ebus_dma))
  556. return 0;
  557. /* XXX ioremap */
  558. sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start;
  559. sun_fdops.fd_inb = sun_pci_fd_inb;
  560. sun_fdops.fd_outb = sun_pci_fd_outb;
  561. can_use_virtual_dma = use_virtual_dma = 0;
  562. sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma;
  563. sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma;
  564. sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode;
  565. sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr;
  566. sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count;
  567. sun_fdops.get_dma_residue = sun_pci_get_dma_residue;
  568. sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
  569. sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
  570. sun_fdops.fd_eject = sun_pci_fd_eject;
  571. fdc_status = (unsigned long) &sun_fdc->status_82077;
  572. FLOPPY_MOTOR_MASK = 0xf0;
  573. /*
  574. * XXX: Find out on which machines this is really needed.
  575. */
  576. if (1) {
  577. sun_pci_broken_drive = 1;
  578. sun_fdops.fd_outb = sun_pci_fd_broken_outb;
  579. }
  580. allowed_drive_mask = 0;
  581. if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 0))
  582. sun_floppy_types[0] = 4;
  583. if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 1))
  584. sun_floppy_types[1] = 4;
  585. /*
  586. * Find NS87303 SuperIO config registers (through ecpp).
  587. */
  588. for_each_ebus(ebus) {
  589. for_each_ebusdev(edev, ebus) {
  590. if (!strcmp(edev->prom_node->name, "ecpp")) {
  591. config = edev->resource[1].start;
  592. goto config_done;
  593. }
  594. }
  595. }
  596. config_done:
  597. /*
  598. * Sanity check, is this really the NS87303?
  599. */
  600. switch (config & 0x3ff) {
  601. case 0x02e:
  602. case 0x15c:
  603. case 0x26e:
  604. case 0x398:
  605. break;
  606. default:
  607. config = 0;
  608. }
  609. if (!config)
  610. return sun_floppy_types[0];
  611. /* Enable PC-AT mode. */
  612. ns87303_modify(config, ASC, 0, 0xc0);
  613. #ifdef PCI_FDC_SWAP_DRIVES
  614. /*
  615. * If only Floppy 1 is present, swap drives.
  616. */
  617. if (!sun_floppy_types[0] && sun_floppy_types[1]) {
  618. /*
  619. * Set the drive exchange bit in FCR on NS87303,
  620. * make sure other bits are sane before doing so.
  621. */
  622. ns87303_modify(config, FER, FER_EDM, 0);
  623. ns87303_modify(config, ASC, ASC_DRV2_SEL, 0);
  624. ns87303_modify(config, FCR, 0, FCR_LDE);
  625. config = sun_floppy_types[0];
  626. sun_floppy_types[0] = sun_floppy_types[1];
  627. sun_floppy_types[1] = config;
  628. if (sun_pci_broken_drive != -1) {
  629. sun_pci_broken_drive = 1 - sun_pci_broken_drive;
  630. sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb;
  631. }
  632. }
  633. #endif /* PCI_FDC_SWAP_DRIVES */
  634. return sun_floppy_types[0];
  635. #else
  636. return 0;
  637. #endif
  638. }
  639. prom_getproperty(sdev->prom_node, "status", state, sizeof(state));
  640. if(!strncmp(state, "disabled", 8))
  641. return 0;
  642. /*
  643. * We cannot do sbus_ioremap here: it does request_region,
  644. * which the generic floppy driver tries to do once again.
  645. * But we must use the sdev resource values as they have
  646. * had parent ranges applied.
  647. */
  648. sun_fdc = (struct sun_flpy_controller *)
  649. (sdev->resource[0].start +
  650. ((sdev->resource[0].flags & 0x1ffUL) << 32UL));
  651. /* Last minute sanity check... */
  652. if(sbus_readb(&sun_fdc->status1_82077) == 0xff) {
  653. sun_fdc = (struct sun_flpy_controller *)-1;
  654. return 0;
  655. }
  656. sun_fdops.fd_inb = sun_82077_fd_inb;
  657. sun_fdops.fd_outb = sun_82077_fd_outb;
  658. can_use_virtual_dma = use_virtual_dma = 1;
  659. sun_fdops.fd_enable_dma = sun_fd_enable_dma;
  660. sun_fdops.fd_disable_dma = sun_fd_disable_dma;
  661. sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
  662. sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
  663. sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
  664. sun_fdops.get_dma_residue = sun_get_dma_residue;
  665. sun_fdops.fd_request_irq = sun_fd_request_irq;
  666. sun_fdops.fd_free_irq = sun_fd_free_irq;
  667. sun_fdops.fd_eject = sun_fd_eject;
  668. fdc_status = (unsigned long) &sun_fdc->status_82077;
  669. /* Success... */
  670. allowed_drive_mask = 0x01;
  671. sun_floppy_types[0] = 4;
  672. sun_floppy_types[1] = 0;
  673. return sun_floppy_types[0];
  674. }
  675. #define EXTRA_FLOPPY_PARAMS
  676. #endif /* !(__ASM_SPARC64_FLOPPY_H) */