Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * xtsonic.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * (C) 2001 - 2007 Tensilica Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Kevin Chea <kchea@yahoo.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	Marc Gauthier <marc@linux-xtensa.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	Chris Zankel <chris@zankel.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * This driver is based on work from Andreas Busse, but most of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * the code is rewritten.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * A driver for the onboard Sonic ethernet controller on the XT2000.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static char xtsonic_string[] = "xtsonic";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) extern unsigned xtboard_nvram_valid(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) extern void xtboard_get_ether_addr(unsigned char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include "sonic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * According to the documentation for the Sonic ethernet controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * EOBC should be 760 words (1520 bytes) for 32-bit applications, and,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * as such, 2 words less than the buffer size. The value for RBSIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * defined in sonic.h, however is only 1520.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * (Note that in 16-bit configurations, EOBC is 759 words (1518 bytes) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * RBSIZE 1520 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #undef SONIC_RBSIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define SONIC_RBSIZE	1524
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * The chip provides 256 byte register space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define SONIC_MEM_SIZE	0x100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * Macros to access SONIC registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define SONIC_READ(reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	(0xffff & *((volatile unsigned int *)dev->base_addr+reg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define SONIC_WRITE(reg,val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	*((volatile unsigned int *)dev->base_addr+reg) = val
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * We cannot use station (ethernet) address prefixes to detect the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * sonic controller since these are board manufacturer depended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * So we check for known Silicon Revision IDs instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static unsigned short known_revisions[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	0x101,			/* SONIC 83934 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	0xffff			/* end of list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static int xtsonic_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	retval = request_irq(dev->irq, sonic_interrupt, 0, "sonic", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		printk(KERN_ERR "%s: unable to get IRQ %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		       dev->name, dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	retval = sonic_open(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		free_irq(dev->irq, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int xtsonic_close(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	err = sonic_close(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	free_irq(dev->irq, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const struct net_device_ops xtsonic_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	.ndo_open		= xtsonic_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	.ndo_stop		= xtsonic_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.ndo_start_xmit		= sonic_send_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.ndo_get_stats		= sonic_get_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.ndo_set_rx_mode	= sonic_multicast_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.ndo_tx_timeout		= sonic_tx_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.ndo_validate_addr	= eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.ndo_set_mac_address	= eth_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int sonic_probe1(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	unsigned int silicon_revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct sonic_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	unsigned int base_addr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!request_mem_region(base_addr, 0x100, xtsonic_string))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	 * get the Silicon Revision ID. If this is one of the known
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * one assume that we found a SONIC ethernet controller at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * the expected location.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	silicon_revision = SONIC_READ(SONIC_SR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	while ((known_revisions[i] != 0xffff) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			(known_revisions[i] != silicon_revision))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (known_revisions[i] == 0xffff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		pr_info("SONIC ethernet controller not found (0x%4x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			silicon_revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 * Put the sonic into software reset, then retrieve ethernet address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 * Note: we are assuming that the boot-loader has initialized the cam.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	SONIC_WRITE(SONIC_DCR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		    SONIC_DCR_WC0|SONIC_DCR_DW|SONIC_DCR_LBR|SONIC_DCR_SBUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	SONIC_WRITE(SONIC_CEP,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	SONIC_WRITE(SONIC_IMR,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	SONIC_WRITE(SONIC_CEP,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	for (i=0; i<3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		unsigned int val = SONIC_READ(SONIC_CAP0-i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		dev->dev_addr[i*2] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		dev->dev_addr[i*2+1] = val >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	lp->dma_bitmode = SONIC_BITMODE32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	err = sonic_alloc_descriptors(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	dev->netdev_ops		= &xtsonic_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	dev->watchdog_timeo	= TX_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 * clear tally counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	SONIC_WRITE(SONIC_CRCT,0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	SONIC_WRITE(SONIC_FAET,0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	SONIC_WRITE(SONIC_MPT,0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	release_region(dev->base_addr, SONIC_MEM_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * Probe for a SONIC ethernet controller on an XT2000 board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * Actually probing is superfluous but we're paranoid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int xtsonic_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct sonic_local *lp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct resource *resmem, *resirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if ((resmem = platform_get_resource(pdev, IORESOURCE_MEM, 0)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if ((resirq = platform_get_resource(pdev, IORESOURCE_IRQ, 0)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if ((dev = alloc_etherdev(sizeof(struct sonic_local))) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	lp->device = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	platform_set_drvdata(pdev, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	SET_NETDEV_DEV(dev, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	netdev_boot_setup_check(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	dev->base_addr = resmem->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	dev->irq = resirq->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if ((err = sonic_probe1(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		dev->base_addr, dev->dev_addr, dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	sonic_msg_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if ((err = register_netdev(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		goto undo_probe1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) undo_probe1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	dma_free_coherent(lp->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			  lp->descriptors, lp->descriptors_laddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	release_region(dev->base_addr, SONIC_MEM_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) MODULE_DESCRIPTION("Xtensa XT2000 SONIC ethernet driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #include "sonic.c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int xtsonic_device_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct net_device *dev = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct sonic_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	unregister_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	dma_free_coherent(lp->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			  lp->descriptors, lp->descriptors_laddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	release_region (dev->base_addr, SONIC_MEM_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static struct platform_driver xtsonic_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	.probe = xtsonic_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.remove = xtsonic_device_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		.name = xtsonic_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) module_platform_driver(xtsonic_driver);