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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Linux ARCnet driver - COM20020 PCMCIA support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Written 1994-1999 by Avery Pennarun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *    based on an ISA version by David Woodhouse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Derived from ibmtr_cs.c by Steve Kipisz (pcmcia-cs 3.1.4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    which was derived from pcnet_cs.c by David Hinds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Some additional portions derived from skeleton.c by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  for sponsoring the further development of this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * The original copyright of skeleton.c was as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * skeleton.c Written 1993 by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Copyright 1993 United States Government as represented by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Director, National Security Agency.  This software may only be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * and distributed according to the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * modified by SRC, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * - reorganize kmallocs in com20020_attach, checking all for failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *   and releasing the previous allocations if one fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * For more details, see drivers/net/arcnet.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <pcmcia/cistpl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <pcmcia/ds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include "arcdevice.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include "com20020.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static void regdump(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	int ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	netdev_dbg(dev, "register dump:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	for (count = 0; count < 16; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		if (!(count % 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			pr_cont("%04X:", ioaddr + count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		pr_cont(" %02X", arcnet_inb(ioaddr, count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	netdev_dbg(dev, "buffer0 dump:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	/* set up the address register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	arcnet_outb((count >> 8) | RDDATAflag | AUTOINCflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		    ioaddr, com20020_REG_W_ADDR_HI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	arcnet_outb(count & 0xff, ioaddr, COM20020_REG_W_ADDR_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	for (count = 0; count < 256 + 32; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (!(count % 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			pr_cont("%04X:", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		/* copy the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		pr_cont(" %02X", arcnet_inb(ioaddr, COM20020_REG_RW_MEMDATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /*====================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /* Parameters that can be set with 'insmod' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static int node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int timeout = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int backplane;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int clockp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static int clockm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) module_param(node, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) module_param(timeout, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) module_param(backplane, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) module_param(clockp, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) module_param(clockm, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^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 com20020_config(struct pcmcia_device *link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void com20020_release(struct pcmcia_device *link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void com20020_detach(struct pcmcia_device *p_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*====================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int com20020_probe(struct pcmcia_device *p_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct com20020_dev *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct arcnet_local *lp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	dev_dbg(&p_dev->dev, "com20020_attach()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* Create new network device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	info = kzalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		goto fail_alloc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	dev = alloc_arcdev("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		goto fail_alloc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	lp->timeout = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	lp->backplane = backplane;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	lp->clockp = clockp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	lp->clockm = clockm & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	lp->hw.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* fill in our module parameters as defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	dev->dev_addr[0] = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	p_dev->resource[0]->end = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	p_dev->config_flags |= CONF_ENABLE_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	info->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	p_dev->priv = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return com20020_config(p_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) fail_alloc_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) fail_alloc_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) } /* com20020_attach */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static void com20020_detach(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct com20020_dev *info = link->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct net_device *dev = info->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	dev_dbg(&link->dev, "detach...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	dev_dbg(&link->dev, "com20020_detach\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	dev_dbg(&link->dev, "unregister...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	unregister_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* this is necessary because we register our IRQ separately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 * from card services.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (dev->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		free_irq(dev->irq, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	com20020_release(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* Unlink device structure, free bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	dev_dbg(&link->dev, "unlinking...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (link->priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		dev = info->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			dev_dbg(&link->dev, "kfree...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		dev_dbg(&link->dev, "kfree2...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) } /* com20020_detach */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static int com20020_config(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct arcnet_local *lp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct com20020_dev *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int ioaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	info = link->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	dev = info->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	dev_dbg(&link->dev, "config...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	dev_dbg(&link->dev, "com20020_config\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	dev_dbg(&link->dev, "baseport1 is %Xh\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		(unsigned int)link->resource[0]->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	i = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	link->io_lines = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (!link->resource[0]->start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			link->resource[0]->start = ioaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			i = pcmcia_request_io(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			if (i == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		i = pcmcia_request_io(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (i != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		dev_dbg(&link->dev, "requestIO failed totally!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	ioaddr = dev->base_addr = link->resource[0]->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	dev_dbg(&link->dev, "got ioaddr %Xh\n", ioaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	dev_dbg(&link->dev, "request IRQ %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		link->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (!link->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		dev_dbg(&link->dev, "requestIRQ failed totally!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	dev->irq = link->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	ret = pcmcia_enable_device(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (com20020_check(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		regdump(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	lp->card_name = "PCMCIA COM20020";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	SET_NETDEV_DEV(dev, &link->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	i = com20020_found(dev, 0);	/* calls register_netdev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (i != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		dev_notice(&link->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			   "com20020_found() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	netdev_dbg(dev, "port %#3lx, irq %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		   dev->base_addr, dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	dev_dbg(&link->dev, "com20020_config failed...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	com20020_release(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) } /* com20020_config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static void com20020_release(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	dev_dbg(&link->dev, "com20020_release\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	pcmcia_disable_device(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static int com20020_suspend(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct com20020_dev *info = link->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct net_device *dev = info->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (link->open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		netif_device_detach(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static int com20020_resume(struct pcmcia_device *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	struct com20020_dev *info = link->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct net_device *dev = info->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (link->open) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		int ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		arcnet_outb(lp->config | 0x80, ioaddr, COM20020_REG_W_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		udelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static const struct pcmcia_device_id com20020_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	PCMCIA_DEVICE_PROD_ID12("Contemporary Control Systems, Inc.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 				"PCM20 Arcnet Adapter", 0x59991666, 0x95dfffaf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	PCMCIA_DEVICE_PROD_ID12("SoHard AG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 				"SH ARC PCMCIA", 0xf8991729, 0x69dff0c7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	PCMCIA_DEVICE_NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) MODULE_DEVICE_TABLE(pcmcia, com20020_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static struct pcmcia_driver com20020_cs_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	.name		= "com20020_cs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.probe		= com20020_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	.remove		= com20020_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	.id_table	= com20020_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	.suspend	= com20020_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	.resume		= com20020_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) module_pcmcia_driver(com20020_cs_driver);