floppy.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /* asm-sparc/floppy.h: Sparc specific parts of the Floppy driver.
  2. *
  3. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  4. */
  5. #ifndef __ASM_SPARC_FLOPPY_H
  6. #define __ASM_SPARC_FLOPPY_H
  7. #include <asm/page.h>
  8. #include <asm/pgtable.h>
  9. #include <asm/system.h>
  10. #include <asm/idprom.h>
  11. #include <asm/machines.h>
  12. #include <asm/oplib.h>
  13. #include <asm/auxio.h>
  14. #include <asm/irq.h>
  15. /* We don't need no stinkin' I/O port allocation crap. */
  16. #undef release_region
  17. #undef request_region
  18. #define release_region(X, Y) do { } while(0)
  19. #define request_region(X, Y, Z) (1)
  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 status_82072; /* Main Status reg. */
  27. #define dcr_82072 status_82072 /* Digital Control reg. */
  28. #define status1_82077 status_82072 /* Auxiliary Status reg. 1 */
  29. volatile unsigned char data_82072; /* Data fifo. */
  30. #define status2_82077 data_82072 /* Auxiliary Status reg. 2 */
  31. volatile unsigned char dor_82077; /* Digital Output reg. */
  32. volatile unsigned char tapectl_82077; /* What the? Tape control reg? */
  33. volatile unsigned char status_82077; /* Main Status Register. */
  34. #define drs_82077 status_82077 /* Digital Rate Select reg. */
  35. volatile unsigned char data_82077; /* Data fifo. */
  36. volatile unsigned char ___unused;
  37. volatile unsigned char dir_82077; /* Digital Input reg. */
  38. #define dcr_82077 dir_82077 /* Config Control reg. */
  39. };
  40. /* You'll only ever find one controller on a SparcStation anyways. */
  41. static struct sun_flpy_controller *sun_fdc = NULL;
  42. volatile unsigned char *fdc_status;
  43. struct sun_floppy_ops {
  44. unsigned char (*fd_inb)(int port);
  45. void (*fd_outb)(unsigned char value, int port);
  46. };
  47. static struct sun_floppy_ops sun_fdops;
  48. #define fd_inb(port) sun_fdops.fd_inb(port)
  49. #define fd_outb(value,port) sun_fdops.fd_outb(value,port)
  50. #define fd_enable_dma() sun_fd_enable_dma()
  51. #define fd_disable_dma() sun_fd_disable_dma()
  52. #define fd_request_dma() (0) /* nothing... */
  53. #define fd_free_dma() /* nothing... */
  54. #define fd_clear_dma_ff() /* nothing... */
  55. #define fd_set_dma_mode(mode) sun_fd_set_dma_mode(mode)
  56. #define fd_set_dma_addr(addr) sun_fd_set_dma_addr(addr)
  57. #define fd_set_dma_count(count) sun_fd_set_dma_count(count)
  58. #define fd_enable_irq() /* nothing... */
  59. #define fd_disable_irq() /* nothing... */
  60. #define fd_cacheflush(addr, size) /* nothing... */
  61. #define fd_request_irq() sun_fd_request_irq()
  62. #define fd_free_irq() /* nothing... */
  63. #if 0 /* P3: added by Alain, these cause a MMU corruption. 19960524 XXX */
  64. #define fd_dma_mem_alloc(size) ((unsigned long) vmalloc(size))
  65. #define fd_dma_mem_free(addr,size) (vfree((void *)(addr)))
  66. #endif
  67. #define FLOPPY_MOTOR_MASK 0x10
  68. /* XXX This isn't really correct. XXX */
  69. #define get_dma_residue(x) (0)
  70. #define FLOPPY0_TYPE 4
  71. #define FLOPPY1_TYPE 0
  72. /* Super paranoid... */
  73. #undef HAVE_DISABLE_HLT
  74. /* Here is where we catch the floppy driver trying to initialize,
  75. * therefore this is where we call the PROM device tree probing
  76. * routine etc. on the Sparc.
  77. */
  78. #define FDC1 sun_floppy_init()
  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. /* Routines unique to each controller type on a Sun. */
  84. static unsigned char sun_82072_fd_inb(int port)
  85. {
  86. udelay(5);
  87. switch(port & 7) {
  88. default:
  89. printk("floppy: Asked to read unknown port %d\n", port);
  90. panic("floppy: Port bolixed.");
  91. case 4: /* FD_STATUS */
  92. return sun_fdc->status_82072 & ~STATUS_DMA;
  93. case 5: /* FD_DATA */
  94. return sun_fdc->data_82072;
  95. case 7: /* FD_DIR */
  96. return (get_auxio() & AUXIO_FLPY_DCHG)? 0x80: 0;
  97. };
  98. panic("sun_82072_fd_inb: How did I get here?");
  99. }
  100. static void sun_82072_fd_outb(unsigned char value, int port)
  101. {
  102. udelay(5);
  103. switch(port & 7) {
  104. default:
  105. printk("floppy: Asked to write to unknown port %d\n", port);
  106. panic("floppy: Port bolixed.");
  107. case 2: /* FD_DOR */
  108. /* Oh geese, 82072 on the Sun has no DOR register,
  109. * the functionality is implemented via the AUXIO
  110. * I/O register. So we must emulate the behavior.
  111. *
  112. * ASSUMPTIONS: There will only ever be one floppy
  113. * drive attached to a Sun controller
  114. * and it will be at drive zero.
  115. */
  116. {
  117. unsigned bits = 0;
  118. if (value & 0x10) bits |= AUXIO_FLPY_DSEL;
  119. if ((value & 0x80) == 0) bits |= AUXIO_FLPY_EJCT;
  120. set_auxio(bits, (~bits) & (AUXIO_FLPY_DSEL|AUXIO_FLPY_EJCT));
  121. }
  122. break;
  123. case 5: /* FD_DATA */
  124. sun_fdc->data_82072 = value;
  125. break;
  126. case 7: /* FD_DCR */
  127. sun_fdc->dcr_82072 = value;
  128. break;
  129. case 4: /* FD_STATUS */
  130. sun_fdc->status_82072 = value;
  131. break;
  132. };
  133. return;
  134. }
  135. static unsigned char sun_82077_fd_inb(int port)
  136. {
  137. udelay(5);
  138. switch(port & 7) {
  139. default:
  140. printk("floppy: Asked to read unknown port %d\n", port);
  141. panic("floppy: Port bolixed.");
  142. case 4: /* FD_STATUS */
  143. return sun_fdc->status_82077 & ~STATUS_DMA;
  144. case 5: /* FD_DATA */
  145. return sun_fdc->data_82077;
  146. case 7: /* FD_DIR */
  147. /* XXX: Is DCL on 0x80 in sun4m? */
  148. return sun_fdc->dir_82077;
  149. };
  150. panic("sun_82072_fd_inb: How did I get here?");
  151. }
  152. static void sun_82077_fd_outb(unsigned char value, int port)
  153. {
  154. udelay(5);
  155. switch(port & 7) {
  156. default:
  157. printk("floppy: Asked to write to unknown port %d\n", port);
  158. panic("floppy: Port bolixed.");
  159. case 2: /* FD_DOR */
  160. /* Happily, the 82077 has a real DOR register. */
  161. sun_fdc->dor_82077 = value;
  162. break;
  163. case 5: /* FD_DATA */
  164. sun_fdc->data_82077 = value;
  165. break;
  166. case 7: /* FD_DCR */
  167. sun_fdc->dcr_82077 = value;
  168. break;
  169. case 4: /* FD_STATUS */
  170. sun_fdc->status_82077 = value;
  171. break;
  172. };
  173. return;
  174. }
  175. /* For pseudo-dma (Sun floppy drives have no real DMA available to
  176. * them so we must eat the data fifo bytes directly ourselves) we have
  177. * three state variables. doing_pdma tells our inline low-level
  178. * assembly floppy interrupt entry point whether it should sit and eat
  179. * bytes from the fifo or just transfer control up to the higher level
  180. * floppy interrupt c-code. I tried very hard but I could not get the
  181. * pseudo-dma to work in c-code without getting many overruns and
  182. * underruns. If non-zero, doing_pdma encodes the direction of
  183. * the transfer for debugging. 1=read 2=write
  184. */
  185. char *pdma_vaddr;
  186. unsigned long pdma_size;
  187. volatile int doing_pdma = 0;
  188. /* This is software state */
  189. char *pdma_base = NULL;
  190. unsigned long pdma_areasize;
  191. /* Common routines to all controller types on the Sparc. */
  192. static __inline__ void virtual_dma_init(void)
  193. {
  194. /* nothing... */
  195. }
  196. static __inline__ void sun_fd_disable_dma(void)
  197. {
  198. doing_pdma = 0;
  199. if (pdma_base) {
  200. mmu_unlockarea(pdma_base, pdma_areasize);
  201. pdma_base = NULL;
  202. }
  203. }
  204. static __inline__ void sun_fd_set_dma_mode(int mode)
  205. {
  206. switch(mode) {
  207. case DMA_MODE_READ:
  208. doing_pdma = 1;
  209. break;
  210. case DMA_MODE_WRITE:
  211. doing_pdma = 2;
  212. break;
  213. default:
  214. printk("Unknown dma mode %d\n", mode);
  215. panic("floppy: Giving up...");
  216. }
  217. }
  218. static __inline__ void sun_fd_set_dma_addr(char *buffer)
  219. {
  220. pdma_vaddr = buffer;
  221. }
  222. static __inline__ void sun_fd_set_dma_count(int length)
  223. {
  224. pdma_size = length;
  225. }
  226. static __inline__ void sun_fd_enable_dma(void)
  227. {
  228. pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
  229. pdma_base = pdma_vaddr;
  230. pdma_areasize = pdma_size;
  231. }
  232. /* Our low-level entry point in arch/sparc/kernel/entry.S */
  233. irqreturn_t floppy_hardint(int irq, void *unused, struct pt_regs *regs);
  234. static int sun_fd_request_irq(void)
  235. {
  236. static int once = 0;
  237. int error;
  238. if(!once) {
  239. once = 1;
  240. error = request_fast_irq(FLOPPY_IRQ, floppy_hardint, SA_INTERRUPT, "floppy");
  241. return ((error == 0) ? 0 : -1);
  242. } else return 0;
  243. }
  244. static struct linux_prom_registers fd_regs[2];
  245. static int sun_floppy_init(void)
  246. {
  247. char state[128];
  248. int tnode, fd_node, num_regs;
  249. struct resource r;
  250. use_virtual_dma = 1;
  251. FLOPPY_IRQ = 11;
  252. /* Forget it if we aren't on a machine that could possibly
  253. * ever have a floppy drive.
  254. */
  255. if((sparc_cpu_model != sun4c && sparc_cpu_model != sun4m) ||
  256. ((idprom->id_machtype == (SM_SUN4C | SM_4C_SLC)) ||
  257. (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC)))) {
  258. /* We certainly don't have a floppy controller. */
  259. goto no_sun_fdc;
  260. }
  261. /* Well, try to find one. */
  262. tnode = prom_getchild(prom_root_node);
  263. fd_node = prom_searchsiblings(tnode, "obio");
  264. if(fd_node != 0) {
  265. tnode = prom_getchild(fd_node);
  266. fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo");
  267. } else {
  268. fd_node = prom_searchsiblings(tnode, "fd");
  269. }
  270. if(fd_node == 0) {
  271. goto no_sun_fdc;
  272. }
  273. /* The sun4m lets us know if the controller is actually usable. */
  274. if(sparc_cpu_model == sun4m &&
  275. prom_getproperty(fd_node, "status", state, sizeof(state)) != -1) {
  276. if(!strcmp(state, "disabled")) {
  277. goto no_sun_fdc;
  278. }
  279. }
  280. num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs));
  281. num_regs = (num_regs / sizeof(fd_regs[0]));
  282. prom_apply_obio_ranges(fd_regs, num_regs);
  283. memset(&r, 0, sizeof(r));
  284. r.flags = fd_regs[0].which_io;
  285. r.start = fd_regs[0].phys_addr;
  286. sun_fdc = (struct sun_flpy_controller *)
  287. sbus_ioremap(&r, 0, fd_regs[0].reg_size, "floppy");
  288. /* Last minute sanity check... */
  289. if(sun_fdc->status_82072 == 0xff) {
  290. sun_fdc = NULL;
  291. goto no_sun_fdc;
  292. }
  293. if(sparc_cpu_model == sun4c) {
  294. sun_fdops.fd_inb = sun_82072_fd_inb;
  295. sun_fdops.fd_outb = sun_82072_fd_outb;
  296. fdc_status = &sun_fdc->status_82072;
  297. /* printk("AUXIO @0x%lx\n", auxio_register); */ /* P3 */
  298. } else {
  299. sun_fdops.fd_inb = sun_82077_fd_inb;
  300. sun_fdops.fd_outb = sun_82077_fd_outb;
  301. fdc_status = &sun_fdc->status_82077;
  302. /* printk("DOR @0x%p\n", &sun_fdc->dor_82077); */ /* P3 */
  303. }
  304. /* Success... */
  305. allowed_drive_mask = 0x01;
  306. return (int) sun_fdc;
  307. no_sun_fdc:
  308. return -1;
  309. }
  310. static int sparc_eject(void)
  311. {
  312. set_dor(0x00, 0xff, 0x90);
  313. udelay(500);
  314. set_dor(0x00, 0x6f, 0x00);
  315. udelay(500);
  316. return 0;
  317. }
  318. #define fd_eject(drive) sparc_eject()
  319. #define EXTRA_FLOPPY_PARAMS
  320. #endif /* !(__ASM_SPARC_FLOPPY_H) */