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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Copyright (c) 1999-2001 Vojtech Pavlik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (c) 1999 Brian Gerst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * NS558 based standard IBM game port driver for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) /*
^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) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/gameport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/pnp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) MODULE_DESCRIPTION("Classic gameport (ISA/PnP) driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int ns558_isa_portlist[] = { 0x201, 0x200, 0x202, 0x203, 0x204, 0x205, 0x207, 0x209,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 				    0x20b, 0x20c, 0x20e, 0x20f, 0x211, 0x219, 0x101, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct ns558 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct pnp_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct gameport *gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static LIST_HEAD(ns558_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * ns558_isa_probe() tries to find an isa gameport at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * specified address, and also checks for mirrors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * A joystick must be attached for this to work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int ns558_isa_probe(int io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	int i, j, b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned char c, u, v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct ns558 *ns558;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct gameport *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * No one should be using this address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (!request_region(io, 1, "ns558-isa"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return -EBUSY;
^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)  * We must not be able to write arbitrary values to the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * The lower two axis bits must be 1 after a write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	c = inb(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	outb(~c & ~3, io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (~(u = v = inb(io)) & 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		outb(c, io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		release_region(io, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * After a trigger, there must be at least some bits changing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	for (i = 0; i < 1000; i++) v &= inb(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (u == v) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		outb(c, io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		release_region(io, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	msleep(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * After some time (4ms) the axes shouldn't change anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	u = inb(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	for (i = 0; i < 1000; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if ((u ^ inb(io)) & 0xf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			outb(c, io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			release_region(io, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			return -ENODEV;
^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)  * And now find the number of mirrors of the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	for (i = 1; i < 5; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		release_region(io & (-1 << (i - 1)), (1 << (i - 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		if (!request_region(io & (-1 << i), (1 << i), "ns558-isa"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			break;				/* Don't disturb anyone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		outb(0xff, io & (-1 << i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		for (j = b = 0; j < 1000; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			if (inb(io & (-1 << i)) != inb((io & (-1 << i)) + (1 << i) - 1)) b++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		msleep(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		if (b > 300) {				/* We allow 30% difference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			release_region(io & (-1 << i), (1 << i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	i--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (i != 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (!request_region(io & (-1 << i), (1 << i), "ns558-isa"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	ns558 = kzalloc(sizeof(struct ns558), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	port = gameport_allocate_port();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (!ns558 || !port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		printk(KERN_ERR "ns558: Memory allocation failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		release_region(io & (-1 << i), (1 << i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		kfree(ns558);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		gameport_free_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ns558->io = io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ns558->size = 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ns558->gameport = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	port->io = io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	gameport_set_name(port, "NS558 ISA Gameport");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	gameport_set_phys(port, "isa%04x/gameport0", io & (-1 << i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	gameport_register_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	list_add(&ns558->node, &ns558_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return 0;
^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) #ifdef CONFIG_PNP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static const struct pnp_device_id pnp_devids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	{ .id = "@P@0001", .driver_data = 0 }, /* ALS 100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	{ .id = "@P@0020", .driver_data = 0 }, /* ALS 200 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	{ .id = "@P@1001", .driver_data = 0 }, /* ALS 100+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	{ .id = "@P@2001", .driver_data = 0 }, /* ALS 120 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	{ .id = "ASB16fd", .driver_data = 0 }, /* AdLib NSC16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	{ .id = "AZT3001", .driver_data = 0 }, /* AZT1008 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	{ .id = "CDC0001", .driver_data = 0 }, /* Opl3-SAx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	{ .id = "CSC0001", .driver_data = 0 }, /* CS4232 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	{ .id = "CSC000f", .driver_data = 0 }, /* CS4236 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	{ .id = "CSC0101", .driver_data = 0 }, /* CS4327 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	{ .id = "CTL7001", .driver_data = 0 }, /* SB16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	{ .id = "CTL7002", .driver_data = 0 }, /* AWE64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	{ .id = "CTL7005", .driver_data = 0 }, /* Vibra16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	{ .id = "ENS2020", .driver_data = 0 }, /* SoundscapeVIVO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	{ .id = "ESS0001", .driver_data = 0 }, /* ES1869 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	{ .id = "ESS0005", .driver_data = 0 }, /* ES1878 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	{ .id = "ESS6880", .driver_data = 0 }, /* ES688 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	{ .id = "IBM0012", .driver_data = 0 }, /* CS4232 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	{ .id = "OPT0001", .driver_data = 0 }, /* OPTi Audio16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	{ .id = "YMH0006", .driver_data = 0 }, /* Opl3-SA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	{ .id = "YMH0022", .driver_data = 0 }, /* Opl3-SAx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	{ .id = "PNPb02f", .driver_data = 0 }, /* Generic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	{ .id = "", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) MODULE_DEVICE_TABLE(pnp, pnp_devids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int ns558_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *did)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	int ioport, iolen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct ns558 *ns558;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct gameport *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (!pnp_port_valid(dev, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		printk(KERN_WARNING "ns558: No i/o ports on a gameport? Weird\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return -ENODEV;
^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) 	ioport = pnp_port_start(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	iolen = pnp_port_len(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (!request_region(ioport, iolen, "ns558-pnp"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	ns558 = kzalloc(sizeof(struct ns558), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	port = gameport_allocate_port();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (!ns558 || !port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		printk(KERN_ERR "ns558: Memory allocation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		kfree(ns558);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		gameport_free_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	ns558->io = ioport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	ns558->size = iolen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	ns558->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	ns558->gameport = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	gameport_set_name(port, "NS558 PnP Gameport");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	gameport_set_phys(port, "pnp%s/gameport0", dev_name(&dev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	port->dev.parent = &dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	port->io = ioport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	gameport_register_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	list_add_tail(&ns558->node, &ns558_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static struct pnp_driver ns558_pnp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.name		= "ns558",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.id_table	= pnp_devids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	.probe		= ns558_pnp_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static struct pnp_driver ns558_pnp_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int __init ns558_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	error = pnp_register_driver(&ns558_pnp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (error && error != -ENODEV)	/* should be ENOSYS really */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * Probe ISA ports after PnP, so that PnP ports that are already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * enabled get detected as PnP. This may be suboptimal in multi-device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * configurations, but saves hassle with simple setups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	while (ns558_isa_portlist[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		ns558_isa_probe(ns558_isa_portlist[i++]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return list_empty(&ns558_list) && error ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void __exit ns558_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct ns558 *ns558, *safe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	list_for_each_entry_safe(ns558, safe, &ns558_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		gameport_unregister_port(ns558->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		release_region(ns558->io & ~(ns558->size - 1), ns558->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		kfree(ns558);
^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) 	pnp_unregister_driver(&ns558_pnp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) module_init(ns558_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) module_exit(ns558_exit);