floppy_32.h 10 KB

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