ide.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /****************************************************************************/
  2. /*
  3. * linux/include/asm-m68knommu/ide.h
  4. *
  5. * Copyright (C) 1994-1996 Linus Torvalds & authors
  6. * Copyright (C) 2001 Lineo Inc., davidm@uclinux.org
  7. */
  8. /****************************************************************************/
  9. #ifndef _M68KNOMMU_IDE_H
  10. #define _M68KNOMMU_IDE_H
  11. #ifdef __KERNEL__
  12. /****************************************************************************/
  13. #include <linux/config.h>
  14. #include <linux/interrupt.h>
  15. #include <asm/setup.h>
  16. #include <asm/io.h>
  17. #include <asm/irq.h>
  18. /****************************************************************************/
  19. /*
  20. * some coldfire specifics
  21. */
  22. #ifdef CONFIG_COLDFIRE
  23. #include <asm/coldfire.h>
  24. #include <asm/mcfsim.h>
  25. /*
  26. * Save some space, only have 1 interface
  27. */
  28. #define MAX_HWIFS 1 /* we only have one interface for now */
  29. #ifdef CONFIG_SECUREEDGEMP3
  30. #define MCFSIM_LOCALCS MCFSIM_CSCR4
  31. #else
  32. #define MCFSIM_LOCALCS MCFSIM_CSCR6
  33. #endif
  34. #endif /* CONFIG_COLDFIRE */
  35. /****************************************************************************/
  36. /*
  37. * Fix up things that may not have been provided
  38. */
  39. #ifndef MAX_HWIFS
  40. #define MAX_HWIFS 4 /* same as the other archs */
  41. #endif
  42. #undef SUPPORT_SLOW_DATA_PORTS
  43. #define SUPPORT_SLOW_DATA_PORTS 0
  44. #undef SUPPORT_VLB_SYNC
  45. #define SUPPORT_VLB_SYNC 0
  46. /* this definition is used only on startup .. */
  47. #undef HD_DATA
  48. #define HD_DATA NULL
  49. #define DBGIDE(fmt,a...)
  50. // #define DBGIDE(fmt,a...) printk(fmt, ##a)
  51. #define IDE_INLINE __inline__
  52. // #define IDE_INLINE
  53. /****************************************************************************/
  54. typedef union {
  55. unsigned all : 8; /* all of the bits together */
  56. struct {
  57. unsigned bit7 : 1; /* always 1 */
  58. unsigned lba : 1; /* using LBA instead of CHS */
  59. unsigned bit5 : 1; /* always 1 */
  60. unsigned unit : 1; /* drive select number, 0 or 1 */
  61. unsigned head : 4; /* always zeros here */
  62. } b;
  63. } select_t;
  64. /*
  65. * our list of ports/irq's for different boards
  66. */
  67. static struct m68k_ide_defaults {
  68. ide_ioreg_t base;
  69. int irq;
  70. } m68k_ide_defaults[MAX_HWIFS] = {
  71. #if defined(CONFIG_SECUREEDGEMP3)
  72. { ((ide_ioreg_t)0x30800000), 29 },
  73. #elif defined(CONFIG_eLIA)
  74. { ((ide_ioreg_t)0x30c00000), 29 },
  75. #else
  76. { ((ide_ioreg_t)0x0), 0 }
  77. #endif
  78. };
  79. /****************************************************************************/
  80. static IDE_INLINE int ide_default_irq(ide_ioreg_t base)
  81. {
  82. int i;
  83. for (i = 0; i < MAX_HWIFS; i++)
  84. if (m68k_ide_defaults[i].base == base)
  85. return(m68k_ide_defaults[i].irq);
  86. return 0;
  87. }
  88. static IDE_INLINE ide_ioreg_t ide_default_io_base(int index)
  89. {
  90. if (index >= 0 && index < MAX_HWIFS)
  91. return(m68k_ide_defaults[index].base);
  92. return 0;
  93. }
  94. /*
  95. * Set up a hw structure for a specified data port, control port and IRQ.
  96. * This should follow whatever the default interface uses.
  97. */
  98. static IDE_INLINE void ide_init_hwif_ports(
  99. hw_regs_t *hw,
  100. ide_ioreg_t data_port,
  101. ide_ioreg_t ctrl_port,
  102. int *irq)
  103. {
  104. ide_ioreg_t reg = data_port;
  105. int i;
  106. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  107. hw->io_ports[i] = reg;
  108. reg += 1;
  109. }
  110. if (ctrl_port) {
  111. hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
  112. } else {
  113. hw->io_ports[IDE_CONTROL_OFFSET] = data_port + 0xe;
  114. }
  115. }
  116. #define ide_init_default_irq(base) ide_default_irq(base)
  117. static IDE_INLINE int
  118. ide_request_irq(
  119. unsigned int irq,
  120. void (*handler)(int, void *, struct pt_regs *),
  121. unsigned long flags,
  122. const char *device,
  123. void *dev_id)
  124. {
  125. #ifdef CONFIG_COLDFIRE
  126. mcf_autovector(irq);
  127. #endif
  128. return(request_irq(irq, handler, flags, device, dev_id));
  129. }
  130. static IDE_INLINE void
  131. ide_free_irq(unsigned int irq, void *dev_id)
  132. {
  133. free_irq(irq, dev_id);
  134. }
  135. static IDE_INLINE int
  136. ide_check_region(ide_ioreg_t from, unsigned int extent)
  137. {
  138. return 0;
  139. }
  140. static IDE_INLINE void
  141. ide_request_region(ide_ioreg_t from, unsigned int extent, const char *name)
  142. {
  143. }
  144. static IDE_INLINE void
  145. ide_release_region(ide_ioreg_t from, unsigned int extent)
  146. {
  147. }
  148. static IDE_INLINE void
  149. ide_fix_driveid(struct hd_driveid *id)
  150. {
  151. #ifdef CONFIG_COLDFIRE
  152. int i, n;
  153. unsigned short *wp = (unsigned short *) id;
  154. int avoid[] = {49, 51, 52, 59, -1 }; /* do not swap these words */
  155. /* Need to byte swap shorts, but not char fields */
  156. for (i = n = 0; i < sizeof(*id) / sizeof(*wp); i++, wp++) {
  157. if (avoid[n] == i) {
  158. n++;
  159. continue;
  160. }
  161. *wp = ((*wp & 0xff) << 8) | ((*wp >> 8) & 0xff);
  162. }
  163. /* have to word swap the one 32 bit field */
  164. id->lba_capacity = ((id->lba_capacity & 0xffff) << 16) |
  165. ((id->lba_capacity >> 16) & 0xffff);
  166. #endif
  167. }
  168. static IDE_INLINE void
  169. ide_release_lock (int *ide_lock)
  170. {
  171. }
  172. static IDE_INLINE void
  173. ide_get_lock(
  174. int *ide_lock,
  175. void (*handler)(int, void *, struct pt_regs *),
  176. void *data)
  177. {
  178. }
  179. #define ide_ack_intr(hwif) \
  180. ((hwif)->hw.ack_intr ? (hwif)->hw.ack_intr(hwif) : 1)
  181. #define ide__sti() __sti()
  182. /****************************************************************************/
  183. /*
  184. * System specific IO requirements
  185. */
  186. #ifdef CONFIG_COLDFIRE
  187. #ifdef CONFIG_SECUREEDGEMP3
  188. /* Replace standard IO functions for funky mapping of MP3 board */
  189. #undef outb
  190. #undef outb_p
  191. #undef inb
  192. #undef inb_p
  193. #define outb(v, a) ide_outb(v, (unsigned long) (a))
  194. #define outb_p(v, a) ide_outb(v, (unsigned long) (a))
  195. #define inb(a) ide_inb((unsigned long) (a))
  196. #define inb_p(a) ide_inb((unsigned long) (a))
  197. #define ADDR8_PTR(addr) (((addr) & 0x1) ? (0x8000 + (addr) - 1) : (addr))
  198. #define ADDR16_PTR(addr) (addr)
  199. #define ADDR32_PTR(addr) (addr)
  200. #define SWAP8(w) ((((w) & 0xffff) << 8) | (((w) & 0xffff) >> 8))
  201. #define SWAP16(w) (w)
  202. #define SWAP32(w) (w)
  203. static IDE_INLINE void
  204. ide_outb(unsigned int val, unsigned int addr)
  205. {
  206. volatile unsigned short *rp;
  207. DBGIDE("%s(val=%x,addr=%x)\n", __FUNCTION__, val, addr);
  208. rp = (volatile unsigned short *) ADDR8_PTR(addr);
  209. *rp = SWAP8(val);
  210. }
  211. static IDE_INLINE int
  212. ide_inb(unsigned int addr)
  213. {
  214. volatile unsigned short *rp, val;
  215. DBGIDE("%s(addr=%x)\n", __FUNCTION__, addr);
  216. rp = (volatile unsigned short *) ADDR8_PTR(addr);
  217. val = *rp;
  218. return(SWAP8(val));
  219. }
  220. static IDE_INLINE void
  221. ide_outw(unsigned int val, unsigned int addr)
  222. {
  223. volatile unsigned short *rp;
  224. DBGIDE("%s(val=%x,addr=%x)\n", __FUNCTION__, val, addr);
  225. rp = (volatile unsigned short *) ADDR16_PTR(addr);
  226. *rp = SWAP16(val);
  227. }
  228. static IDE_INLINE void
  229. ide_outsw(unsigned int addr, const void *vbuf, unsigned long len)
  230. {
  231. volatile unsigned short *rp, val;
  232. unsigned short *buf;
  233. DBGIDE("%s(addr=%x,vbuf=%p,len=%x)\n", __FUNCTION__, addr, vbuf, len);
  234. buf = (unsigned short *) vbuf;
  235. rp = (volatile unsigned short *) ADDR16_PTR(addr);
  236. for (; (len > 0); len--) {
  237. val = *buf++;
  238. *rp = SWAP16(val);
  239. }
  240. }
  241. static IDE_INLINE int
  242. ide_inw(unsigned int addr)
  243. {
  244. volatile unsigned short *rp, val;
  245. DBGIDE("%s(addr=%x)\n", __FUNCTION__, addr);
  246. rp = (volatile unsigned short *) ADDR16_PTR(addr);
  247. val = *rp;
  248. return(SWAP16(val));
  249. }
  250. static IDE_INLINE void
  251. ide_insw(unsigned int addr, void *vbuf, unsigned long len)
  252. {
  253. volatile unsigned short *rp;
  254. unsigned short w, *buf;
  255. DBGIDE("%s(addr=%x,vbuf=%p,len=%x)\n", __FUNCTION__, addr, vbuf, len);
  256. buf = (unsigned short *) vbuf;
  257. rp = (volatile unsigned short *) ADDR16_PTR(addr);
  258. for (; (len > 0); len--) {
  259. w = *rp;
  260. *buf++ = SWAP16(w);
  261. }
  262. }
  263. static IDE_INLINE void
  264. ide_insl(unsigned int addr, void *vbuf, unsigned long len)
  265. {
  266. volatile unsigned long *rp;
  267. unsigned long w, *buf;
  268. DBGIDE("%s(addr=%x,vbuf=%p,len=%x)\n", __FUNCTION__, addr, vbuf, len);
  269. buf = (unsigned long *) vbuf;
  270. rp = (volatile unsigned long *) ADDR32_PTR(addr);
  271. for (; (len > 0); len--) {
  272. w = *rp;
  273. *buf++ = SWAP32(w);
  274. }
  275. }
  276. static IDE_INLINE void
  277. ide_outsl(unsigned int addr, const void *vbuf, unsigned long len)
  278. {
  279. volatile unsigned long *rp, val;
  280. unsigned long *buf;
  281. DBGIDE("%s(addr=%x,vbuf=%p,len=%x)\n", __FUNCTION__, addr, vbuf, len);
  282. buf = (unsigned long *) vbuf;
  283. rp = (volatile unsigned long *) ADDR32_PTR(addr);
  284. for (; (len > 0); len--) {
  285. val = *buf++;
  286. *rp = SWAP32(val);
  287. }
  288. }
  289. #elif CONFIG_eLIA
  290. /* 8/16 bit acesses are controlled by flicking bits in the CS register */
  291. #define ACCESS_MODE_16BIT() \
  292. *((volatile unsigned short *) (MCF_MBAR + MCFSIM_LOCALCS)) = 0x0080
  293. #define ACCESS_MODE_8BIT() \
  294. *((volatile unsigned short *) (MCF_MBAR + MCFSIM_LOCALCS)) = 0x0040
  295. static IDE_INLINE void
  296. ide_outw(unsigned int val, unsigned int addr)
  297. {
  298. ACCESS_MODE_16BIT();
  299. outw(val, addr);
  300. ACCESS_MODE_8BIT();
  301. }
  302. static IDE_INLINE void
  303. ide_outsw(unsigned int addr, const void *vbuf, unsigned long len)
  304. {
  305. ACCESS_MODE_16BIT();
  306. outsw(addr, vbuf, len);
  307. ACCESS_MODE_8BIT();
  308. }
  309. static IDE_INLINE int
  310. ide_inw(unsigned int addr)
  311. {
  312. int ret;
  313. ACCESS_MODE_16BIT();
  314. ret = inw(addr);
  315. ACCESS_MODE_8BIT();
  316. return(ret);
  317. }
  318. static IDE_INLINE void
  319. ide_insw(unsigned int addr, void *vbuf, unsigned long len)
  320. {
  321. ACCESS_MODE_16BIT();
  322. insw(addr, vbuf, len);
  323. ACCESS_MODE_8BIT();
  324. }
  325. static IDE_INLINE void
  326. ide_insl(unsigned int addr, void *vbuf, unsigned long len)
  327. {
  328. ACCESS_MODE_16BIT();
  329. insl(addr, vbuf, len);
  330. ACCESS_MODE_8BIT();
  331. }
  332. static IDE_INLINE void
  333. ide_outsl(unsigned int addr, const void *vbuf, unsigned long len)
  334. {
  335. ACCESS_MODE_16BIT();
  336. outsl(addr, vbuf, len);
  337. ACCESS_MODE_8BIT();
  338. }
  339. #endif /* CONFIG_SECUREEDGEMP3 */
  340. #undef outw
  341. #undef outw_p
  342. #undef outsw
  343. #undef inw
  344. #undef inw_p
  345. #undef insw
  346. #undef insl
  347. #undef outsl
  348. #define outw(v, a) ide_outw(v, (unsigned long) (a))
  349. #define outw_p(v, a) ide_outw(v, (unsigned long) (a))
  350. #define outsw(a, b, n) ide_outsw((unsigned long) (a), b, n)
  351. #define inw(a) ide_inw((unsigned long) (a))
  352. #define inw_p(a) ide_inw((unsigned long) (a))
  353. #define insw(a, b, n) ide_insw((unsigned long) (a), b, n)
  354. #define insl(a, b, n) ide_insl((unsigned long) (a), b, n)
  355. #define outsl(a, b, n) ide_outsl((unsigned long) (a), b, n)
  356. #endif CONFIG_COLDFIRE
  357. /****************************************************************************/
  358. #endif /* __KERNEL__ */
  359. #endif /* _M68KNOMMU_IDE_H */
  360. /****************************************************************************/