Linux Audio

Check our new training course

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