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