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