xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/zorro.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun========================================
2*4882a593SmuzhiyunWriting Device Drivers for Zorro Devices
3*4882a593Smuzhiyun========================================
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun:Author: Written by Geert Uytterhoeven <geert@linux-m68k.org>
6*4882a593Smuzhiyun:Last revised: September 5, 2003
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunIntroduction
10*4882a593Smuzhiyun------------
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunThe Zorro bus is the bus used in the Amiga family of computers. Thanks to
13*4882a593SmuzhiyunAutoConfig(tm), it's 100% Plug-and-Play.
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunThere are two types of Zorro buses, Zorro II and Zorro III:
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun  - The Zorro II address space is 24-bit and lies within the first 16 MB of the
18*4882a593Smuzhiyun    Amiga's address map.
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun  - Zorro III is a 32-bit extension of Zorro II, which is backwards compatible
21*4882a593Smuzhiyun    with Zorro II. The Zorro III address space lies outside the first 16 MB.
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunProbing for Zorro Devices
25*4882a593Smuzhiyun-------------------------
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunZorro devices are found by calling ``zorro_find_device()``, which returns a
28*4882a593Smuzhiyunpointer to the ``next`` Zorro device with the specified Zorro ID. A probe loop
29*4882a593Smuzhiyunfor the board with Zorro ID ``ZORRO_PROD_xxx`` looks like::
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun    struct zorro_dev *z = NULL;
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun    while ((z = zorro_find_device(ZORRO_PROD_xxx, z))) {
34*4882a593Smuzhiyun	if (!zorro_request_region(z->resource.start+MY_START, MY_SIZE,
35*4882a593Smuzhiyun				  "My explanation"))
36*4882a593Smuzhiyun	...
37*4882a593Smuzhiyun    }
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun``ZORRO_WILDCARD`` acts as a wildcard and finds any Zorro device. If your driver
40*4882a593Smuzhiyunsupports different types of boards, you can use a construct like::
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun    struct zorro_dev *z = NULL;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun    while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
45*4882a593Smuzhiyun	if (z->id != ZORRO_PROD_xxx1 && z->id != ZORRO_PROD_xxx2 && ...)
46*4882a593Smuzhiyun	    continue;
47*4882a593Smuzhiyun	if (!zorro_request_region(z->resource.start+MY_START, MY_SIZE,
48*4882a593Smuzhiyun				  "My explanation"))
49*4882a593Smuzhiyun	...
50*4882a593Smuzhiyun    }
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun
53*4882a593SmuzhiyunZorro Resources
54*4882a593Smuzhiyun---------------
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunBefore you can access a Zorro device's registers, you have to make sure it's
57*4882a593Smuzhiyunnot yet in use. This is done using the I/O memory space resource management
58*4882a593Smuzhiyunfunctions::
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun    request_mem_region()
61*4882a593Smuzhiyun    release_mem_region()
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunShortcuts to claim the whole device's address space are provided as well::
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun    zorro_request_device
66*4882a593Smuzhiyun    zorro_release_device
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunAccessing the Zorro Address Space
70*4882a593Smuzhiyun---------------------------------
71*4882a593Smuzhiyun
72*4882a593SmuzhiyunThe address regions in the Zorro device resources are Zorro bus address
73*4882a593Smuzhiyunregions. Due to the identity bus-physical address mapping on the Zorro bus,
74*4882a593Smuzhiyunthey are CPU physical addresses as well.
75*4882a593Smuzhiyun
76*4882a593SmuzhiyunThe treatment of these regions depends on the type of Zorro space:
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun  - Zorro II address space is always mapped and does not have to be mapped
79*4882a593Smuzhiyun    explicitly using z_ioremap().
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun    Conversion from bus/physical Zorro II addresses to kernel virtual addresses
82*4882a593Smuzhiyun    and vice versa is done using::
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun	virt_addr = ZTWO_VADDR(bus_addr);
85*4882a593Smuzhiyun	bus_addr = ZTWO_PADDR(virt_addr);
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun  - Zorro III address space must be mapped explicitly using z_ioremap() first
88*4882a593Smuzhiyun    before it can be accessed::
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun	virt_addr = z_ioremap(bus_addr, size);
91*4882a593Smuzhiyun	...
92*4882a593Smuzhiyun	z_iounmap(virt_addr);
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun
95*4882a593SmuzhiyunReferences
96*4882a593Smuzhiyun----------
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun#. linux/include/linux/zorro.h
99*4882a593Smuzhiyun#. linux/include/uapi/linux/zorro.h
100*4882a593Smuzhiyun#. linux/include/uapi/linux/zorro_ids.h
101*4882a593Smuzhiyun#. linux/arch/m68k/include/asm/zorro.h
102*4882a593Smuzhiyun#. linux/drivers/zorro
103*4882a593Smuzhiyun#. /proc/bus/zorro
104*4882a593Smuzhiyun
105