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) /* Code to support devices on the DIO and DIO-II bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2004 Jochen Friedrich <jochen@scram.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This code has basically these routines at the moment:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * int dio_find(u_int deviceid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *    Search the list of DIO devices and return the select code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *    of the next unconfigured device found that matches the given device ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *    Note that the deviceid parameter should be the encoded ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *    This means that framebuffers should pass it as 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *    DIO_ENCODE_ID(DIO_ID_FBUFFER,DIO_ID2_TOPCAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *    (or whatever); everybody else just uses DIO_ID_FOOBAR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * unsigned long dio_scodetophysaddr(int scode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *    Return the physical address corresponding to the given select code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * int dio_scodetoipl(int scode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *    Every DIO card has a fixed interrupt priority level. This function 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *    returns it, whatever it is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * const char *dio_scodetoname(int scode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *    Return a character string describing this board [might be "" if 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *    not CONFIG_DIO_CONSTANTS]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * void dio_config_board(int scode)     mark board as configured in the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * void dio_unconfig_board(int scode)   mark board as no longer configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * This file is based on the way the Amiga port handles Zorro II cards, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * although we aren't so complicated...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/module.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/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/dio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/slab.h>                         /* kmalloc() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <asm/io.h>                             /* readb() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) struct dio_bus dio_bus = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	.resources = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		/* DIO range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		{ .name = "DIO mem", .start = 0x00600000, .end = 0x007fffff },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		/* DIO-II range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		{ .name = "DIO-II mem", .start = 0x01000000, .end = 0x1fffffff }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.name = "DIO bus"
^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) /* not a real config option yet! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define CONFIG_DIO_CONSTANTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #ifdef CONFIG_DIO_CONSTANTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /* We associate each numeric ID with an appropriate descriptive string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * using a constant array of these structs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * FIXME: we should be able to arrange to throw away most of the strings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * using the initdata stuff. Then we wouldn't need to worry about 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * carrying them around...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * I think we do this by copying them into newly kmalloc()ed memory and 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * marking the names[] array as .initdata ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) struct dioname
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)         int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)         const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) /* useful macro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define DIONAME(x) { DIO_ID_##x, DIO_DESC_##x }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define DIOFBNAME(x) { DIO_ENCODE_ID( DIO_ID_FBUFFER, DIO_ID2_##x), DIO_DESC2_##x }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static struct dioname names[] = 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)         DIONAME(DCA0), DIONAME(DCA0REM), DIONAME(DCA1), DIONAME(DCA1REM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)         DIONAME(DCM), DIONAME(DCMREM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)         DIONAME(LAN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)         DIONAME(FHPIB), DIONAME(NHPIB),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)         DIONAME(SCSI0), DIONAME(SCSI1), DIONAME(SCSI2), DIONAME(SCSI3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)         DIONAME(FBUFFER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)         DIONAME(PARALLEL), DIONAME(VME), DIONAME(DCL), DIONAME(DCLREM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)         DIONAME(MISC0), DIONAME(MISC1), DIONAME(MISC2), DIONAME(MISC3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)         DIONAME(MISC4), DIONAME(MISC5), DIONAME(MISC6), DIONAME(MISC7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)         DIONAME(MISC8), DIONAME(MISC9), DIONAME(MISC10), DIONAME(MISC11), 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)         DIONAME(MISC12), DIONAME(MISC13),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)         DIOFBNAME(GATORBOX), DIOFBNAME(TOPCAT), DIOFBNAME(RENAISSANCE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)         DIOFBNAME(LRCATSEYE), DIOFBNAME(HRCCATSEYE), DIOFBNAME(HRMCATSEYE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)         DIOFBNAME(DAVINCI), DIOFBNAME(XXXCATSEYE), DIOFBNAME(HYPERION),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)         DIOFBNAME(XGENESIS), DIOFBNAME(TIGER), DIOFBNAME(YGENESIS)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #undef DIONAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #undef DIOFBNAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static const char unknowndioname[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	= "unknown DIO board, please email linux-m68k@lists.linux-m68k.org";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static const char *dio_getname(int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)         /* return pointer to a constant string describing the board with given ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	for (i = 0; i < ARRAY_SIZE(names); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)                 if (names[i].id == id) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)                         return names[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)         return unknowndioname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static char dio_no_name[] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define dio_getname(_id)	(dio_no_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #endif /* CONFIG_DIO_CONSTANTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int __init dio_find(int deviceid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* Called to find a DIO device before the full bus scan has run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * Only used by the console driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int scode, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	u_char prid, secid, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	for (scode = 0; scode < DIO_SCMAX; scode++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		void *va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		unsigned long pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)                 if (DIO_SCINHOLE(scode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)                         continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)                 pa = dio_scodetophysaddr(scode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (!pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (scode < DIOII_SCBASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			va = (void *)(pa + DIO_VIRADDRBASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			va = ioremap(pa, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		if (copy_from_kernel_nofault(&i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				(unsigned char *)va + DIO_IDOFF, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			if (scode >= DIOII_SCBASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				iounmap(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)                         continue;             /* no board present at that select code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		prid = DIO_ID(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)                 if (DIO_NEEDSSECID(prid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)                         secid = DIO_SECID(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)                         id = DIO_ENCODE_ID(prid, secid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)                 } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			id = prid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (id == deviceid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			if (scode >= DIOII_SCBASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				iounmap(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			return scode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* This is the function that scans the DIO space and works out what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * hardware is actually present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int __init dio_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int scode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct dio_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (!MACH_IS_HP300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)         printk(KERN_INFO "Scanning for DIO devices...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* Initialize the DIO bus */ 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	INIT_LIST_HEAD(&dio_bus.devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	dev_set_name(&dio_bus.dev, "dio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	error = device_register(&dio_bus.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		pr_err("DIO: Error registering dio_bus\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	/* Request all resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	dio_bus.num_resources = (hp300_model == HP_320 ? 1 : 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	for (i = 0; i < dio_bus.num_resources; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		request_resource(&iomem_resource, &dio_bus.resources[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	/* Register all devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)         for (scode = 0; scode < DIO_SCMAX; ++scode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)                 u_char prid, secid = 0;        /* primary, secondary ID bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)                 u_char *va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		unsigned long pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)                 if (DIO_SCINHOLE(scode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)                         continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		pa = dio_scodetophysaddr(scode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (!pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (scode < DIOII_SCBASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			va = (void *)(pa + DIO_VIRADDRBASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			va = ioremap(pa, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		if (copy_from_kernel_nofault(&i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				(unsigned char *)va + DIO_IDOFF, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			if (scode >= DIOII_SCBASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				iounmap(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)                         continue;              /* no board present at that select code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)                 /* Found a board, allocate it an entry in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		dev = kzalloc(sizeof(struct dio_dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		dev->bus = &dio_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		dev->dev.parent = &dio_bus.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		dev->dev.bus = &dio_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		dev->scode = scode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		dev->resource.start = pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		dev->resource.end = pa + DIO_SIZE(scode, va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		dev_set_name(&dev->dev, "%02x", scode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)                 /* read the ID byte(s) and encode if necessary. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		prid = DIO_ID(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)                 if (DIO_NEEDSSECID(prid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)                         secid = DIO_SECID(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)                         dev->id = DIO_ENCODE_ID(prid, secid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)                 } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)                         dev->id = prid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)                 dev->ipl = DIO_IPL(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)                 strcpy(dev->name,dio_getname(dev->id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)                 printk(KERN_INFO "select code %3d: ipl %d: ID %02X", dev->scode, dev->ipl, prid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)                 if (DIO_NEEDSSECID(prid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)                         printk(":%02X", secid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)                 printk(": %s\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		if (scode >= DIOII_SCBASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			iounmap(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		error = device_register(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			pr_err("DIO: Error registering device %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			       dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		error = dio_create_sysfs_dev_files(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			dev_err(&dev->dev, "Error creating sysfs files\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) subsys_initcall(dio_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* Bear in mind that this is called in the very early stages of initialisation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * in order to get the address of the serial port for the console...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) unsigned long dio_scodetophysaddr(int scode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)         if (scode >= DIOII_SCBASE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)                 return (DIOII_BASE + (scode - 132) * DIOII_DEVSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)         } else if (scode > DIO_SCMAX || scode < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)                 return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)         else if (DIO_SCINHOLE(scode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)                 return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)         return (DIO_BASE + scode * DIO_DEVSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }