1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/module.h>
3 #include <linux/netdevice.h>
4 #include <linux/platform_device.h>
5 #include <linux/zorro.h>
6 #include <net/ax88796.h>
7 #include <asm/amigaints.h>
9 #define ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF100 \
10 ZORRO_ID(INDIVIDUAL_COMPUTERS, 0x64, 0)
12 #define XS100_IRQSTATUS_BASE 0x40
13 #define XS100_8390_BASE 0x800
15 /* Longword-access area. Translated to 2 16-bit access cycles by the
18 #define XS100_8390_DATA32_BASE 0x8000
19 #define XS100_8390_DATA32_SIZE 0x2000
20 /* Sub-Areas for fast data register access; addresses relative to area begin */
21 #define XS100_8390_DATA_READ32_BASE 0x0880
22 #define XS100_8390_DATA_WRITE32_BASE 0x0C80
23 #define XS100_8390_DATA_AREA_SIZE 0x80
25 /* force unsigned long back to 'void __iomem *' */
26 #define ax_convert_addr(_a) ((void __force __iomem *)(_a))
28 #define ei_inb(_a) z_readb(ax_convert_addr(_a))
29 #define ei_outb(_v, _a) z_writeb(_v, ax_convert_addr(_a))
31 #define ei_inw(_a) z_readw(ax_convert_addr(_a))
32 #define ei_outw(_v, _a) z_writew(_v, ax_convert_addr(_a))
34 #define ei_inb_p(_a) ei_inb(_a)
35 #define ei_outb_p(_v, _a) ei_outb(_v, _a)
37 /* define EI_SHIFT() to take into account our register offsets */
38 #define EI_SHIFT(x) (ei_local->reg_offset[(x)])
40 /* Ensure we have our RCR base value */
41 #define AX88796_PLATFORM
46 #define NE_CMD EI_SHIFT(0x00)
47 #define NE_RESET EI_SHIFT(0x1f)
48 #define NE_DATAPORT EI_SHIFT(0x10)
50 struct xsurf100_ax_plat_data
{
51 struct ax_plat_data ax
;
52 void __iomem
*base_regs
;
53 void __iomem
*data_area
;
56 static int is_xsurf100_network_irq(struct platform_device
*pdev
)
58 struct xsurf100_ax_plat_data
*xs100
= dev_get_platdata(&pdev
->dev
);
60 return (readw(xs100
->base_regs
+ XS100_IRQSTATUS_BASE
) & 0xaaaa) != 0;
63 /* These functions guarantee that the iomem is accessed with 32 bit
64 * cycles only. z_memcpy_fromio / z_memcpy_toio don't
66 static void z_memcpy_fromio32(void *dst
, const void __iomem
*src
, size_t bytes
)
70 ("movem.l (%0)+,%%d0-%%d7\n"
71 "movem.l %%d0-%%d7,(%1)\n"
72 "adda.l #32,%1" : "=a"(src
), "=a"(dst
)
73 : "0"(src
), "1"(dst
) : "d0", "d1", "d2", "d3", "d4",
74 "d5", "d6", "d7", "memory");
78 *(uint32_t *)dst
= z_readl(src
);
85 static void z_memcpy_toio32(void __iomem
*dst
, const void *src
, size_t bytes
)
88 z_writel(*(const uint32_t *)src
, dst
);
95 static void xs100_write(struct net_device
*dev
, const void *src
,
98 struct ei_device
*ei_local
= netdev_priv(dev
);
99 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
100 struct xsurf100_ax_plat_data
*xs100
= dev_get_platdata(&pdev
->dev
);
102 /* copy whole blocks */
103 while (count
> XS100_8390_DATA_AREA_SIZE
) {
104 z_memcpy_toio32(xs100
->data_area
+
105 XS100_8390_DATA_WRITE32_BASE
, src
,
106 XS100_8390_DATA_AREA_SIZE
);
107 src
+= XS100_8390_DATA_AREA_SIZE
;
108 count
-= XS100_8390_DATA_AREA_SIZE
;
110 /* copy whole dwords */
111 z_memcpy_toio32(xs100
->data_area
+ XS100_8390_DATA_WRITE32_BASE
,
115 ei_outw(*(uint16_t *)src
, ei_local
->mem
+ NE_DATAPORT
);
119 ei_outb(*(uint8_t *)src
, ei_local
->mem
+ NE_DATAPORT
);
122 static void xs100_read(struct net_device
*dev
, void *dst
, unsigned int count
)
124 struct ei_device
*ei_local
= netdev_priv(dev
);
125 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
126 struct xsurf100_ax_plat_data
*xs100
= dev_get_platdata(&pdev
->dev
);
128 /* copy whole blocks */
129 while (count
> XS100_8390_DATA_AREA_SIZE
) {
130 z_memcpy_fromio32(dst
, xs100
->data_area
+
131 XS100_8390_DATA_READ32_BASE
,
132 XS100_8390_DATA_AREA_SIZE
);
133 dst
+= XS100_8390_DATA_AREA_SIZE
;
134 count
-= XS100_8390_DATA_AREA_SIZE
;
136 /* copy whole dwords */
137 z_memcpy_fromio32(dst
, xs100
->data_area
+ XS100_8390_DATA_READ32_BASE
,
141 *(uint16_t *)dst
= ei_inw(ei_local
->mem
+ NE_DATAPORT
);
145 *(uint8_t *)dst
= ei_inb(ei_local
->mem
+ NE_DATAPORT
);
148 /* Block input and output, similar to the Crynwr packet driver. If
149 * you are porting to a new ethercard, look at the packet driver
150 * source for hints. The NEx000 doesn't share the on-board packet
151 * memory -- you have to put the packet out through the "remote DMA"
152 * dataport using ei_outb.
154 static void xs100_block_input(struct net_device
*dev
, int count
,
155 struct sk_buff
*skb
, int ring_offset
)
157 struct ei_device
*ei_local
= netdev_priv(dev
);
158 void __iomem
*nic_base
= ei_local
->mem
;
159 char *buf
= skb
->data
;
161 if (ei_local
->dmaing
) {
163 "DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
165 ei_local
->dmaing
, ei_local
->irqlock
);
169 ei_local
->dmaing
|= 0x01;
171 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_START
, nic_base
+ NE_CMD
);
172 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
173 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
174 ei_outb(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
175 ei_outb(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
176 ei_outb(E8390_RREAD
+ E8390_START
, nic_base
+ NE_CMD
);
178 xs100_read(dev
, buf
, count
);
180 ei_local
->dmaing
&= ~1;
183 static void xs100_block_output(struct net_device
*dev
, int count
,
184 const unsigned char *buf
, const int start_page
)
186 struct ei_device
*ei_local
= netdev_priv(dev
);
187 void __iomem
*nic_base
= ei_local
->mem
;
188 unsigned long dma_start
;
190 /* Round the count up for word writes. Do we need to do this?
191 * What effect will an odd byte count have on the 8390? I
192 * should check someday.
194 if (ei_local
->word16
&& (count
& 0x01))
197 /* This *shouldn't* happen. If it does, it's the last thing
200 if (ei_local
->dmaing
) {
202 "DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
204 ei_local
->dmaing
, ei_local
->irqlock
);
208 ei_local
->dmaing
|= 0x01;
209 /* We should already be in page 0, but to be safe... */
210 ei_outb(E8390_PAGE0
+ E8390_START
+ E8390_NODMA
, nic_base
+ NE_CMD
);
212 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
);
214 /* Now the normal output. */
215 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
216 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
217 ei_outb(0x00, nic_base
+ EN0_RSARLO
);
218 ei_outb(start_page
, nic_base
+ EN0_RSARHI
);
220 ei_outb(E8390_RWRITE
+ E8390_START
, nic_base
+ NE_CMD
);
222 xs100_write(dev
, buf
, count
);
226 while ((ei_inb(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0) {
227 if (jiffies
- dma_start
> 2 * HZ
/ 100) { /* 20ms */
228 netdev_warn(dev
, "timeout waiting for Tx RDC.\n");
229 ei_local
->reset_8390(dev
);
230 ax_NS8390_reinit(dev
);
235 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
236 ei_local
->dmaing
&= ~0x01;
239 static int xsurf100_probe(struct zorro_dev
*zdev
,
240 const struct zorro_device_id
*ent
)
242 struct platform_device
*pdev
;
243 struct xsurf100_ax_plat_data ax88796_data
;
244 struct resource res
[2] = {
245 DEFINE_RES_NAMED(IRQ_AMIGA_PORTS
, 1, NULL
,
246 IORESOURCE_IRQ
| IORESOURCE_IRQ_SHAREABLE
),
247 DEFINE_RES_MEM(zdev
->resource
.start
+ XS100_8390_BASE
,
251 /* This table is referenced in the device structure, so it must
252 * outlive the scope of xsurf100_probe.
254 static u32 reg_offsets
[32];
257 /* X-Surf 100 control and 32 bit ring buffer data access areas.
258 * These resources are not used by the ax88796 driver, so must
259 * be requested here and passed via platform data.
262 if (!request_mem_region(zdev
->resource
.start
, 0x100, zdev
->name
)) {
263 dev_err(&zdev
->dev
, "cannot reserve X-Surf 100 control registers\n");
267 if (!request_mem_region(zdev
->resource
.start
+
268 XS100_8390_DATA32_BASE
,
269 XS100_8390_DATA32_SIZE
,
270 "X-Surf 100 32-bit data access")) {
271 dev_err(&zdev
->dev
, "cannot reserve 32-bit area\n");
276 for (reg
= 0; reg
< 0x20; reg
++)
277 reg_offsets
[reg
] = 4 * reg
;
279 memset(&ax88796_data
, 0, sizeof(ax88796_data
));
280 ax88796_data
.ax
.flags
= AXFLG_HAS_EEPROM
;
281 ax88796_data
.ax
.wordlength
= 2;
282 ax88796_data
.ax
.dcr_val
= 0x48;
283 ax88796_data
.ax
.rcr_val
= 0x40;
284 ax88796_data
.ax
.reg_offsets
= reg_offsets
;
285 ax88796_data
.ax
.check_irq
= is_xsurf100_network_irq
;
286 ax88796_data
.base_regs
= ioremap(zdev
->resource
.start
, 0x100);
288 /* error handling for ioremap regs */
289 if (!ax88796_data
.base_regs
) {
290 dev_err(&zdev
->dev
, "Cannot ioremap area %pR (registers)\n",
297 ax88796_data
.data_area
= ioremap(zdev
->resource
.start
+
298 XS100_8390_DATA32_BASE
, XS100_8390_DATA32_SIZE
);
300 /* error handling for ioremap data */
301 if (!ax88796_data
.data_area
) {
303 "Cannot ioremap area %pR offset %x (32-bit access)\n",
304 &zdev
->resource
, XS100_8390_DATA32_BASE
);
310 ax88796_data
.ax
.block_output
= xs100_block_output
;
311 ax88796_data
.ax
.block_input
= xs100_block_input
;
313 pdev
= platform_device_register_resndata(&zdev
->dev
, "ax88796",
314 zdev
->slotaddr
, res
, 2,
316 sizeof(ax88796_data
));
319 dev_err(&zdev
->dev
, "cannot register platform device\n");
324 zorro_set_drvdata(zdev
, pdev
);
330 iounmap(ax88796_data
.data_area
);
333 iounmap(ax88796_data
.base_regs
);
336 release_mem_region(zdev
->resource
.start
+ XS100_8390_DATA32_BASE
,
337 XS100_8390_DATA32_SIZE
);
340 release_mem_region(zdev
->resource
.start
, 0x100);
345 static void xsurf100_remove(struct zorro_dev
*zdev
)
347 struct platform_device
*pdev
= zorro_get_drvdata(zdev
);
348 struct xsurf100_ax_plat_data
*xs100
= dev_get_platdata(&pdev
->dev
);
350 platform_device_unregister(pdev
);
352 iounmap(xs100
->base_regs
);
353 release_mem_region(zdev
->resource
.start
, 0x100);
354 iounmap(xs100
->data_area
);
355 release_mem_region(zdev
->resource
.start
+ XS100_8390_DATA32_BASE
,
356 XS100_8390_DATA32_SIZE
);
359 static const struct zorro_device_id xsurf100_zorro_tbl
[] = {
360 { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF100
, },
364 MODULE_DEVICE_TABLE(zorro
, xsurf100_zorro_tbl
);
366 static struct zorro_driver xsurf100_driver
= {
368 .id_table
= xsurf100_zorro_tbl
,
369 .probe
= xsurf100_probe
,
370 .remove
= xsurf100_remove
,
373 module_driver(xsurf100_driver
, zorro_register_driver
, zorro_unregister_driver
);
375 MODULE_DESCRIPTION("X-Surf 100 driver");
376 MODULE_AUTHOR("Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>");
377 MODULE_LICENSE("GPL v2");