floppy_32.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /* asm/floppy.h: Sparc specific parts of the Floppy driver.
  2. *
  3. * Copyright (C) 1995 David S. Miller ([email protected])
  4. */
  5. #ifndef __ASM_SPARC_FLOPPY_H
  6. #define __ASM_SPARC_FLOPPY_H
  7. #include <linux/of.h>
  8. #include <linux/of_device.h>
  9. #include <asm/pgtable.h>
  10. #include <asm/idprom.h>
  11. #include <asm/oplib.h>
  12. #include <asm/auxio.h>
  13. #include <asm/setup.h>
  14. #include <asm/page.h>
  15. #include <asm/irq.h>
  16. /* We don't need no stinkin' I/O port allocation crap. */
  17. #undef release_region
  18. #undef request_region
  19. #define release_region(X, Y) do { } while(0)
  20. #define request_region(X, Y, Z) (1)
  21. /* References:
  22. * 1) Netbsd Sun floppy driver.
  23. * 2) NCR 82077 controller manual
  24. * 3) Intel 82077 controller manual
  25. */
  26. struct sun_flpy_controller {
  27. volatile unsigned char status_82072; /* Main Status reg. */
  28. #define dcr_82072 status_82072 /* Digital Control reg. */
  29. #define status1_82077 status_82072 /* Auxiliary Status reg. 1 */
  30. volatile unsigned char data_82072; /* Data fifo. */
  31. #define status2_82077 data_82072 /* Auxiliary Status reg. 2 */
  32. volatile unsigned char dor_82077; /* Digital Output reg. */
  33. volatile unsigned char tapectl_82077; /* What the? Tape control reg? */
  34. volatile unsigned char status_82077; /* Main Status Register. */
  35. #define drs_82077 status_82077 /* Digital Rate Select reg. */
  36. volatile unsigned char data_82077; /* Data fifo. */
  37. volatile unsigned char ___unused;
  38. volatile unsigned char dir_82077; /* Digital Input reg. */
  39. #define dcr_82077 dir_82077 /* Config Control reg. */
  40. };
  41. /* You'll only ever find one controller on a SparcStation anyways. */
  42. static struct sun_flpy_controller *sun_fdc = NULL;
  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. /* XXX This isn't really correct. XXX */
  68. #define get_dma_residue(x) (0)
  69. #define FLOPPY0_TYPE 4
  70. #define FLOPPY1_TYPE 0
  71. /* Super paranoid... */
  72. #undef HAVE_DISABLE_HLT
  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 FDC1 sun_floppy_init()
  78. #define N_FDC 1
  79. #define N_DRIVE 8
  80. /* No 64k boundary crossing problems on the Sparc. */
  81. #define CROSS_64KB(a,s) (0)
  82. /* Routines unique to each controller type on a Sun. */
  83. static void sun_set_dor(unsigned char value, int fdc_82077)
  84. {
  85. if (fdc_82077)
  86. sun_fdc->dor_82077 = value;
  87. }
  88. static unsigned char sun_read_dir(void)
  89. {
  90. return sun_fdc->dir_82077;
  91. }
  92. static unsigned char sun_82072_fd_inb(int port)
  93. {
  94. udelay(5);
  95. switch(port & 7) {
  96. default:
  97. printk("floppy: Asked to read unknown port %d\n", port);
  98. panic("floppy: Port bolixed.");
  99. case 4: /* FD_STATUS */
  100. return sun_fdc->status_82072 & ~STATUS_DMA;
  101. case 5: /* FD_DATA */
  102. return sun_fdc->data_82072;
  103. case 7: /* FD_DIR */
  104. return sun_read_dir();
  105. }
  106. panic("sun_82072_fd_inb: How did I get here?");
  107. }
  108. static void sun_82072_fd_outb(unsigned char value, int port)
  109. {
  110. udelay(5);
  111. switch(port & 7) {
  112. default:
  113. printk("floppy: Asked to write to unknown port %d\n", port);
  114. panic("floppy: Port bolixed.");
  115. case 2: /* FD_DOR */
  116. sun_set_dor(value, 0);
  117. break;
  118. case 5: /* FD_DATA */
  119. sun_fdc->data_82072 = value;
  120. break;
  121. case 7: /* FD_DCR */
  122. sun_fdc->dcr_82072 = value;
  123. break;
  124. case 4: /* FD_STATUS */
  125. sun_fdc->status_82072 = value;
  126. break;
  127. }
  128. return;
  129. }
  130. static unsigned char sun_82077_fd_inb(int port)
  131. {
  132. udelay(5);
  133. switch(port & 7) {
  134. default:
  135. printk("floppy: Asked to read unknown port %d\n", port);
  136. panic("floppy: Port bolixed.");
  137. case 0: /* FD_STATUS_0 */
  138. return sun_fdc->status1_82077;
  139. case 1: /* FD_STATUS_1 */
  140. return sun_fdc->status2_82077;
  141. case 2: /* FD_DOR */
  142. return sun_fdc->dor_82077;
  143. case 3: /* FD_TDR */
  144. return sun_fdc->tapectl_82077;
  145. case 4: /* FD_STATUS */
  146. return sun_fdc->status_82077 & ~STATUS_DMA;
  147. case 5: /* FD_DATA */
  148. return sun_fdc->data_82077;
  149. case 7: /* FD_DIR */
  150. return sun_read_dir();
  151. }
  152. panic("sun_82077_fd_inb: How did I get here?");
  153. }
  154. static void sun_82077_fd_outb(unsigned char value, int port)
  155. {
  156. udelay(5);
  157. switch(port & 7) {
  158. default:
  159. printk("floppy: Asked to write to unknown port %d\n", port);
  160. panic("floppy: Port bolixed.");
  161. case 2: /* FD_DOR */
  162. sun_set_dor(value, 1);
  163. break;
  164. case 5: /* FD_DATA */
  165. sun_fdc->data_82077 = value;
  166. break;
  167. case 7: /* FD_DCR */
  168. sun_fdc->dcr_82077 = value;
  169. break;
  170. case 4: /* FD_STATUS */
  171. sun_fdc->status_82077 = value;
  172. break;
  173. case 3: /* FD_TDR */
  174. sun_fdc->tapectl_82077 = value;
  175. break;
  176. }
  177. return;
  178. }
  179. /* For pseudo-dma (Sun floppy drives have no real DMA available to
  180. * them so we must eat the data fifo bytes directly ourselves) we have
  181. * three state variables. doing_pdma tells our inline low-level
  182. * assembly floppy interrupt entry point whether it should sit and eat
  183. * bytes from the fifo or just transfer control up to the higher level
  184. * floppy interrupt c-code. I tried very hard but I could not get the
  185. * pseudo-dma to work in c-code without getting many overruns and
  186. * underruns. If non-zero, doing_pdma encodes the direction of
  187. * the transfer for debugging. 1=read 2=write
  188. */
  189. /* Common routines to all controller types on the Sparc. */
  190. static inline void virtual_dma_init(void)
  191. {
  192. /* nothing... */
  193. }
  194. static inline void sun_fd_disable_dma(void)
  195. {
  196. doing_pdma = 0;
  197. pdma_base = NULL;
  198. }
  199. static inline void sun_fd_set_dma_mode(int mode)
  200. {
  201. switch(mode) {
  202. case DMA_MODE_READ:
  203. doing_pdma = 1;
  204. break;
  205. case DMA_MODE_WRITE:
  206. doing_pdma = 2;
  207. break;
  208. default:
  209. printk("Unknown dma mode %d\n", mode);
  210. panic("floppy: Giving up...");
  211. }
  212. }
  213. static inline void sun_fd_set_dma_addr(char *buffer)
  214. {
  215. pdma_vaddr = buffer;
  216. }
  217. static inline void sun_fd_set_dma_count(int length)
  218. {
  219. pdma_size = length;
  220. }
  221. static inline void sun_fd_enable_dma(void)
  222. {
  223. pdma_base = pdma_vaddr;
  224. pdma_areasize = pdma_size;
  225. }
  226. int sparc_floppy_request_irq(unsigned int irq, irq_handler_t irq_handler);
  227. static int sun_fd_request_irq(void)
  228. {
  229. static int once = 0;
  230. if (!once) {
  231. once = 1;
  232. return sparc_floppy_request_irq(FLOPPY_IRQ, floppy_interrupt);
  233. } else {
  234. return 0;
  235. }
  236. }
  237. static struct linux_prom_registers fd_regs[2];
  238. static int sun_floppy_init(void)
  239. {
  240. struct platform_device *op;
  241. struct device_node *dp;
  242. struct resource r;
  243. char state[128];
  244. phandle fd_node;
  245. phandle tnode;
  246. int num_regs;
  247. use_virtual_dma = 1;
  248. /* Forget it if we aren't on a machine that could possibly
  249. * ever have a floppy drive.
  250. */
  251. if (sparc_cpu_model != sun4m) {
  252. /* We certainly don't have a floppy controller. */
  253. goto no_sun_fdc;
  254. }
  255. /* Well, try to find one. */
  256. tnode = prom_getchild(prom_root_node);
  257. fd_node = prom_searchsiblings(tnode, "obio");
  258. if (fd_node != 0) {
  259. tnode = prom_getchild(fd_node);
  260. fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo");
  261. } else {
  262. fd_node = prom_searchsiblings(tnode, "fd");
  263. }
  264. if (fd_node == 0) {
  265. goto no_sun_fdc;
  266. }
  267. /* The sun4m lets us know if the controller is actually usable. */
  268. if (prom_getproperty(fd_node, "status", state, sizeof(state)) != -1) {
  269. if(!strcmp(state, "disabled")) {
  270. goto no_sun_fdc;
  271. }
  272. }
  273. num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs));
  274. num_regs = (num_regs / sizeof(fd_regs[0]));
  275. prom_apply_obio_ranges(fd_regs, num_regs);
  276. memset(&r, 0, sizeof(r));
  277. r.flags = fd_regs[0].which_io;
  278. r.start = fd_regs[0].phys_addr;
  279. sun_fdc = of_ioremap(&r, 0, fd_regs[0].reg_size, "floppy");
  280. /* Look up irq in platform_device.
  281. * We try "SUNW,fdtwo" and "fd"
  282. */
  283. op = NULL;
  284. for_each_node_by_name(dp, "SUNW,fdtwo") {
  285. op = of_find_device_by_node(dp);
  286. if (op)
  287. break;
  288. }
  289. if (!op) {
  290. for_each_node_by_name(dp, "fd") {
  291. op = of_find_device_by_node(dp);
  292. if (op)
  293. break;
  294. }
  295. }
  296. if (!op)
  297. goto no_sun_fdc;
  298. FLOPPY_IRQ = op->archdata.irqs[0];
  299. /* Last minute sanity check... */
  300. if (sun_fdc->status_82072 == 0xff) {
  301. sun_fdc = NULL;
  302. goto no_sun_fdc;
  303. }
  304. sun_fdops.fd_inb = sun_82077_fd_inb;
  305. sun_fdops.fd_outb = sun_82077_fd_outb;
  306. fdc_status = &sun_fdc->status_82077;
  307. if (sun_fdc->dor_82077 == 0x80) {
  308. sun_fdc->dor_82077 = 0x02;
  309. if (sun_fdc->dor_82077 == 0x80) {
  310. sun_fdops.fd_inb = sun_82072_fd_inb;
  311. sun_fdops.fd_outb = sun_82072_fd_outb;
  312. fdc_status = &sun_fdc->status_82072;
  313. }
  314. }
  315. /* Success... */
  316. allowed_drive_mask = 0x01;
  317. return (int) sun_fdc;
  318. no_sun_fdc:
  319. return -1;
  320. }
  321. static int sparc_eject(void)
  322. {
  323. set_dor(0x00, 0xff, 0x90);
  324. udelay(500);
  325. set_dor(0x00, 0x6f, 0x00);
  326. udelay(500);
  327. return 0;
  328. }
  329. #define fd_eject(drive) sparc_eject()
  330. #define EXTRA_FLOPPY_PARAMS
  331. static DEFINE_SPINLOCK(dma_spin_lock);
  332. #define claim_dma_lock() \
  333. ({ unsigned long flags; \
  334. spin_lock_irqsave(&dma_spin_lock, flags); \
  335. flags; \
  336. })
  337. #define release_dma_lock(__flags) \
  338. spin_unlock_irqrestore(&dma_spin_lock, __flags);
  339. #endif /* !(__ASM_SPARC_FLOPPY_H) */