<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">Subject: [PATCH] m68k: Atari ROM port ISA adapter support

From: Michael Schmitz &lt;schmitz@opal.biophys.uni-duesseldorf.de&gt;

Atari ROM port ISA adapter support

Signed-off-by: Michael Schmitz &lt;schmitz@debian.org&gt;
Signed-off-by: Roman Zippel &lt;zippel@linux-m68k.org&gt;
Signed-off-by: Geert Uytterhoeven &lt;geert@linux-m68k.org&gt;
---
 arch/m68k/Kconfig         |   10 +++
 include/asm-m68k/io.h     |  137 ++++++++++++++++++++++++++++++++++++++++++++--
 include/asm-m68k/raw_io.h |  116 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 258 insertions(+), 5 deletions(-)

--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -153,6 +153,16 @@ config PCI
 	  your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
 	  VESA. If you have PCI, say Y, otherwise N.
 
+config ATARI_ROM_ISA
+	bool "Atari ROM port ISA adapter support"
+	depends on ATARI
+	help
+	  This option enables support for the ROM port ISA adapter used to
+	  operate ISA cards on Atari. Only 8  bit cards are supported, and
+	  no interrupt lines are connected.
+	  The only driver currently using this adapter is the EtherNEC
+	  driver for RTL8019AS based NE2000 compatible network cards.
+
 config MAC
 	bool "Macintosh support"
 	depends on !MMU_SUN3
--- a/include/asm-m68k/io.h
+++ b/include/asm-m68k/io.h
@@ -83,9 +83,26 @@ extern unsigned long gg2_isa_base;
 #endif
 #endif /* AMIGA_PCMCIA */
 
+#ifdef CONFIG_ATARI_ROM_ISA
 
+#define enec_isa_read_base  0xfffa0000
+#define enec_isa_write_base 0xfffb0000
 
-#ifdef CONFIG_ISA
+#define ENEC_ISA_IO_B(ioaddr)	(enec_isa_read_base+((((unsigned long)(ioaddr))&amp;0x1F)&lt;&lt;9))
+#define ENEC_ISA_IO_W(ioaddr)	(enec_isa_read_base+((((unsigned long)(ioaddr))&amp;0x1F)&lt;&lt;9))
+#define ENEC_ISA_MEM_B(madr)	(enec_isa_read_base+((((unsigned long)(madr))&amp;0x1F)&lt;&lt;9))
+#define ENEC_ISA_MEM_W(madr)	(enec_isa_read_base+((((unsigned long)(madr))&amp;0x1F)&lt;&lt;9))
+
+#ifndef MULTI_ISA
+#define MULTI_ISA 0
+#else
+#undef MULTI_ISA
+#define MULTI_ISA 1
+#endif
+#endif /* ATARI */
+
+
+#if defined(CONFIG_ISA) || defined(CONFIG_ATARI_ROM_ISA)
 
 #if MULTI_ISA == 0
 #undef MULTI_ISA
@@ -94,6 +111,7 @@ extern unsigned long gg2_isa_base;
 #define Q40_ISA (1)
 #define GG2_ISA (2)
 #define AG_ISA  (3)
+#define ENEC_ISA (4)
 
 #if defined(CONFIG_Q40) &amp;&amp; !defined(MULTI_ISA)
 #define ISA_TYPE Q40_ISA
@@ -107,6 +125,10 @@ extern unsigned long gg2_isa_base;
 #define ISA_TYPE GG2_ISA
 #define ISA_SEX  0
 #endif
+#if defined(CONFIG_ATARI_ROM_ISA) &amp;&amp; !defined(MULTI_ISA)
+#define ISA_TYPE ENEC_ISA
+#define ISA_SEX  0
+#endif
 
 #ifdef MULTI_ISA
 extern int isa_type;
@@ -134,6 +156,9 @@ static inline u8 __iomem *isa_itb(unsign
 #ifdef CONFIG_AMIGA_PCMCIA
     case AG_ISA: return (u8 __iomem *)AG_ISA_IO_B(addr);
 #endif
+#ifdef CONFIG_ATARI_ROM_ISA
+    case ENEC_ISA: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
+#endif
     default: return NULL; /* avoid warnings, just in case */
     }
 }
@@ -150,6 +175,9 @@ static inline u16 __iomem *isa_itw(unsig
 #ifdef CONFIG_AMIGA_PCMCIA
     case AG_ISA: return (u16 __iomem *)AG_ISA_IO_W(addr);
 #endif
+#ifdef CONFIG_ATARI_ROM_ISA
+    case ENEC_ISA: return (u16 __iomem *)ENEC_ISA_IO_W(addr);
+#endif
     default: return NULL; /* avoid warnings, just in case */
     }
 }
@@ -160,7 +188,7 @@ static inline u32 __iomem *isa_itl(unsig
 #ifdef CONFIG_AMIGA_PCMCIA
     case AG_ISA: return (u32 __iomem *)AG_ISA_IO_W(addr);
 #endif
-    default: return 0; /* avoid warnings, just in case */
+    default: return NULL; /* avoid warnings, just in case */
     }
 }
 static inline u8 __iomem *isa_mtb(unsigned long addr)
@@ -176,6 +204,9 @@ static inline u8 __iomem *isa_mtb(unsign
 #ifdef CONFIG_AMIGA_PCMCIA
     case AG_ISA: return (u8 __iomem *)addr;
 #endif
+#ifdef CONFIG_ATARI_ROM_ISA
+    case ENEC_ISA: return (u8 __iomem *)ENEC_ISA_MEM_B(addr);
+#endif
     default: return NULL; /* avoid warnings, just in case */
     }
 }
@@ -192,6 +223,9 @@ static inline u16 __iomem *isa_mtw(unsig
 #ifdef CONFIG_AMIGA_PCMCIA
     case AG_ISA: return (u16 __iomem *)addr;
 #endif
+#ifdef CONFIG_ATARI_ROM_ISA
+    case ENEC_ISA: return (u16 __iomem *)ENEC_ISA_MEM_W(addr);
+#endif
     default: return NULL; /* avoid warnings, just in case */
     }
 }
@@ -213,6 +247,34 @@ static inline u16 __iomem *isa_mtw(unsig
 	(ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val))	\
 		 : out_le16(isa_mtw((unsigned long)(p)),(val)))
 
+#if defined(CONFIG_ATARI_ROM_ISA)
+#define isa_rom_inb(port)      rom_in_8(isa_itb(port))
+#define isa_rom_inw(port)	\
+	(ISA_SEX ? rom_in_be16(isa_itw(port))	\
+		 : rom_in_le16(isa_itw(port)))
+#define isa_rom_inl(port)	\
+	(ISA_SEX ? rom_in_be32(isa_itw(port))	\
+		 : rom_in_le32(isa_itw(port)))
+
+#define isa_rom_outb(val, port) rom_out_8(isa_itb(port), (val))
+#define isa_rom_outw(val, port)	\
+	(ISA_SEX ? rom_out_be16(isa_itw(port), (val))	\
+		 : rom_out_le16(isa_itw(port), (val)))
+#define isa_rom_outl(val, port)	\
+	(ISA_SEX ? rom_out_be32(isa_itw(port), (val))	\
+		 : rom_out_le32(isa_itw(port), (val)))
+
+#define isa_rom_readb(p)       rom_in_8(isa_mtb((unsigned long)(p)))
+#define isa_rom_readw(p)       \
+	(ISA_SEX ? rom_in_be16(isa_mtw((unsigned long)(p)))	\
+		 : rom_in_le16(isa_mtw((unsigned long)(p))))
+
+#define isa_rom_writeb(val, p)  rom_out_8(isa_mtb((unsigned long)(p)), (val))
+#define isa_rom_writew(val, p)  \
+	(ISA_SEX ? rom_out_be16(isa_mtw((unsigned long)(p)), (val))	\
+		 : rom_out_le16(isa_mtw((unsigned long)(p)), (val)))
+#endif
+
 static inline void isa_delay(void)
 {
   switch(ISA_TYPE)
@@ -226,6 +288,9 @@ static inline void isa_delay(void)
 #ifdef CONFIG_AMIGA_PCMCIA
     case AG_ISA: break;
 #endif
+#ifdef CONFIG_ATARI_ROM_ISA
+    case ENEC_ISA: break;
+#endif
     default: break; /* avoid warnings */
     }
 }
@@ -256,10 +321,40 @@ static inline void isa_delay(void)
        (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) :  \
                   raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)&lt;&lt;1))
 
+
+#if defined(CONFIG_ATARI_ROM_ISA)
+#define isa_rom_inb_p(p)	({ u8 _v = isa_rom_inb(p); isa_delay(); _v; })
+#define isa_rom_inw_p(p)	({ u16 _v = isa_rom_inw(p); isa_delay(); _v; })
+#define isa_rom_inl_p(p)	({ u32 _v = isa_rom_inl(p); isa_delay(); _v; })
+#define isa_rom_outb_p(v, p)	({ isa_rom_outb((v), (p)); isa_delay(); })
+#define isa_rom_outw_p(v, p)	({ isa_rom_outw((v), (p)); isa_delay(); })
+#define isa_rom_outl_p(v, p)	({ isa_rom_outl((v), (p)); isa_delay(); })
+
+#define isa_rom_insb(port, buf, nr) raw_rom_insb(isa_itb(port), (u8 *)(buf), (nr))
+
+#define isa_rom_insw(port, buf, nr)     \
+       (ISA_SEX ? raw_rom_insw(isa_itw(port), (u16 *)(buf), (nr)) :    \
+		  raw_rom_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
+
+#define isa_rom_insl(port, buf, nr)     \
+       (ISA_SEX ? raw_rom_insl(isa_itw(port), (u32 *)(buf), (nr)) :    \
+                  raw_rom_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)&lt;&lt;1))
+
+#define isa_rom_outsb(port, buf, nr) raw_rom_outsb(isa_itb(port), (u8 *)(buf), (nr))
+
+#define isa_rom_outsw(port, buf, nr)    \
+       (ISA_SEX ? raw_rom_outsw(isa_itw(port), (u16 *)(buf), (nr)) :  \
+		  raw_rom_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
+
+#define isa_rom_outsl(port, buf, nr)    \
+       (ISA_SEX ? raw_rom_outsl(isa_itw(port), (u32 *)(buf), (nr)) :  \
+                  raw_rom_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)&lt;&lt;1))
+#endif
+
 #endif  /* CONFIG_ISA */
 
 
-#if defined(CONFIG_ISA) &amp;&amp; !defined(CONFIG_PCI)
+#if defined(CONFIG_ISA) &amp;&amp; !defined(CONFIG_PCI) &amp;&amp; !defined(CONFIG_ATARI_ROM_ISA)
 #define inb     isa_inb
 #define inb_p   isa_inb_p
 #define outb    isa_outb
@@ -330,7 +425,41 @@ static inline void isa_delay(void)
 #endif
 #endif /* CONFIG_PCI */
 
-#if !defined(CONFIG_ISA) &amp;&amp; !defined(CONFIG_PCI)
+#if defined(CONFIG_ATARI_ROM_ISA)
+/*
+ * kernel with both ROM port ISA and IDE compiled in, those have
+ * conflicting defs for in/out. Simply consider port &lt; 1024
+ * ROM port ISA and everything else regular ISA for IDE. read,write not defined
+ * in this case
+ */
+#define inb(port)	((port) &lt; 1024 ? isa_rom_inb(port) : in_8(port))
+#define inb_p(port)	((port) &lt; 1024 ? isa_rom_inb_p(port) : in_8(port))
+#define inw(port)	((port) &lt; 1024 ? isa_rom_inw(port) : in_le16(port))
+#define inw_p(port)	((port) &lt; 1024 ? isa_rom_inw_p(port) : in_le16(port))
+#define inl(port)	((port) &lt; 1024 ? isa_rom_inl(port) : in_le32(port))
+#define inl_p(port)	((port) &lt; 1024 ? isa_rom_inl_p(port) : in_le32(port))
+
+#define outb(val, port)	((port) &lt; 1024 ? isa_rom_outb((val), (port)) : out_8((port), (val)))
+#define outb_p(val, port) ((port) &lt; 1024 ? isa_rom_outb_p((val), (port)) : out_8((port), (val)))
+#define outw(val, port)	((port) &lt; 1024 ? isa_rom_outw((val), (port)) : out_le16((port), (val)))
+#define outw_p(val, port) ((port) &lt; 1024 ? isa_rom_outw_p((val), (port)) : out_le16((port), (val)))
+#define outl(val, port)	((port) &lt; 1024 ? isa_rom_outl((val), (port)) : out_le32((port), (val)))
+#define outl_p(val, port) ((port) &lt; 1024 ? isa_rom_outl_p((val), (port)) : out_le32((port), (val)))
+
+#define insb    isa_rom_insb
+#define insw    isa_rom_insw
+#define insl    isa_rom_insl
+#define outsb   isa_rom_outsb
+#define outsw   isa_rom_outsw
+#define outsl   isa_rom_outsl
+
+#define readb   isa_readb
+#define readw   isa_readw
+#define writeb  isa_writeb
+#define writew  isa_writew
+#endif
+
+#if !defined(CONFIG_ISA) &amp;&amp; !defined(CONFIG_PCI) &amp;&amp; !defined(CONFIG_ATARI_ROM_ISA)
 /*
  * We need to define dummy functions for GENERIC_IOMAP support.
  */
--- a/include/asm-m68k/raw_io.h
+++ b/include/asm-m68k/raw_io.h
@@ -10,7 +10,7 @@
 
 #ifdef __KERNEL__
 
-#include &lt;asm/types.h&gt;
+#include &lt;asm/byteorder.h&gt;
 
 
 /* Values for nocacheflag and cmode */
@@ -60,6 +60,46 @@ extern void __iounmap(void *addr, unsign
 #define __raw_writew(val,addr) out_be16((addr),(val))
 #define __raw_writel(val,addr) out_be32((addr),(val))
 
+/*
+ * Atari ROM port (cartridge port) ISA adapter, used for the EtherNEC NE2000
+ * network card driver.
+ * The ISA adapter connects address lines A9-A13 to ISA address lines A0-A4,
+ * and hardwires the rest of the ISA addresses for a base address of 0x300.
+ *
+ * Data lines D8-D15 are connected to ISA data lines D0-D7 for reading.
+ * For writes, address lines A1-A8 are latched to ISA data lines D0-D7
+ * (meaning the bit pattern on A1-A8 can be read back as byte).
+ *
+ * Reads and writes are byte only.
+ */
+
+#if defined(CONFIG_ATARI_ROM_ISA)
+#define rom_in_8(addr) \
+	({ u16 __v = (*(__force volatile u16 *) (addr)); __v &gt;&gt;= 8; __v; })
+#define rom_in_be16(addr) \
+	({ u16 __v = (*(__force volatile u16 *) (addr)); __v &gt;&gt;= 8; __v; })
+#define rom_in_be32(addr) \
+	({ u32 __v = (*(__force volatile u32 *) (addr)); __v &gt;&gt;= 8; __v; })
+#define rom_in_le16(addr) \
+	({ u16 __v = le16_to_cpu(*(__force volatile u16 *) (addr)); __v &gt;&gt;= 8; __v; })
+#define rom_in_le32(addr) \
+	({ u32 __v = le32_to_cpu(*(__force volatile u32 *) (addr)); __v &gt;&gt;= 8; __v; })
+
+#define rom_out_8(addr, b)	({u8 __w, __v = (b); __w = ((*(__force volatile u8 *)  ((addr) + 0x10000 + (__v&lt;&lt;1)))); })
+#define rom_out_be16(addr, w)	({u16 __w, __v = (w); __w = ((*(__force volatile u16 *) ((addr) + 0x10000 + (__v&lt;&lt;1)))); })
+#define rom_out_be32(addr, l)	({u32 __w, __v = (l); __w = ((*(__force volatile u32 *) ((addr) + 0x10000 + (__v&lt;&lt;1)))); })
+#define rom_out_le16(addr, w)	({u16 __w, __v = cpu_to_le16(w); __w = ((*(__force volatile u16 *) ((addr) + 0x10000 + (__v&lt;&lt;1)))); })
+#define rom_out_le32(addr, l)	({u32 __w, __v = cpu_to_le32(l); __w = ((*(__force volatile u32 *) ((addr) + 0x10000 + (__v&lt;&lt;1)))); })
+
+#define raw_rom_inb rom_in_8
+#define raw_rom_inw rom_in_be16
+#define raw_rom_inl rom_in_be32
+
+#define raw_rom_outb(val, port) rom_out_8((port), (val))
+#define raw_rom_outw(val, port) rom_out_be16((port), (val))
+#define raw_rom_outl(val, port) rom_out_be32((port), (val))
+#endif /* CONFIG_ATARI_ROM_ISA */
+
 static inline void raw_insb(volatile u8 __iomem *port, u8 *buf, unsigned int len)
 {
 	unsigned int i;
@@ -342,6 +382,80 @@ static inline void raw_outsw_swapw(volat
 		: "d0", "a0", "a1", "d6");
 }
 
+
+#if defined(CONFIG_ATARI_ROM_ISA)
+static inline void raw_rom_insb(volatile u8 __iomem *port, u8 *buf, unsigned int len)
+{
+	unsigned int i;
+
+	for (i = 0; i &lt; len; i++)
+		*buf++ = rom_in_8(port);
+}
+
+static inline void raw_rom_outsb(volatile u8 __iomem *port, const u8 *buf,
+			     unsigned int len)
+{
+	unsigned int i;
+
+	for (i = 0; i &lt; len; i++)
+		rom_out_8(port, *buf++);
+}
+
+static inline void raw_rom_insw(volatile u16 __iomem *port, u16 *buf,
+				   unsigned int nr)
+{
+	unsigned int i;
+
+	for (i = 0; i &lt; nr; i++)
+		*buf++ = rom_in_be16(port);
+}
+
+static inline void raw_rom_outsw(volatile u16 __iomem *port, const u16 *buf,
+				   unsigned int nr)
+{
+	unsigned int i;
+
+	for (i = 0; i &lt; nr; i++)
+		rom_out_be16(port, *buf++);
+}
+
+static inline void raw_rom_insw_swapw(volatile u16 __iomem *port, u16 *buf,
+				   unsigned int nr)
+{
+	unsigned int i;
+
+	for (i = 0; i &lt; nr; i++)
+		*buf++ = rom_in_le16(port);
+}
+
+static inline void raw_rom_outsw_swapw(volatile u16 __iomem *port, const u16 *buf,
+				   unsigned int nr)
+{
+	unsigned int i;
+
+	for (i = 0; i &lt; nr; i++)
+		rom_out_le16(port, *buf++);
+}
+
+static inline void raw_rom_insl(volatile u16 __iomem *port, u32 *buf,
+				   unsigned int nr)
+{
+	unsigned int i;
+
+	for (i = 0; i &lt; nr; i++)
+		*buf++ = rom_in_be32(port);
+}
+
+static inline void raw_rom_outsl(volatile u16 __iomem *port, const u32 *buf,
+				   unsigned int nr)
+{
+	unsigned int i;
+
+	for (i = 0; i &lt; nr; i++)
+		rom_out_be32(port, *buf++);
+}
+#endif /* CONFIG_ATARI_ROM_ISA */
+
 #endif /* __KERNEL__ */
 
 #endif /* _RAW_IO_H */
</pre></body></html>