Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Industry-pack bus. |
| 3 | * |
| 4 | * (C) 2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN |
| 5 | * (C) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the Free |
Samuel Iglesias Gonsalvez | 416289b | 2012-05-11 10:17:13 +0200 | [diff] [blame] | 9 | * Software Foundation; version 2 of the License. |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
Jens Taprogge | 849e0ad | 2012-09-04 17:01:13 +0200 | [diff] [blame] | 12 | #include <linux/mod_devicetable.h> |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 13 | #include <linux/device.h> |
| 14 | |
Jens Taprogge | 187e478 | 2012-09-04 17:01:14 +0200 | [diff] [blame^] | 15 | #include "ipack_ids.h" |
| 16 | |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 17 | #define IPACK_IDPROM_OFFSET_I 0x01 |
| 18 | #define IPACK_IDPROM_OFFSET_P 0x03 |
| 19 | #define IPACK_IDPROM_OFFSET_A 0x05 |
| 20 | #define IPACK_IDPROM_OFFSET_C 0x07 |
| 21 | #define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09 |
| 22 | #define IPACK_IDPROM_OFFSET_MODEL 0x0B |
| 23 | #define IPACK_IDPROM_OFFSET_REVISION 0x0D |
| 24 | #define IPACK_IDPROM_OFFSET_RESERVED 0x0F |
| 25 | #define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11 |
| 26 | #define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13 |
| 27 | #define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15 |
| 28 | #define IPACK_IDPROM_OFFSET_CRC 0x17 |
| 29 | |
| 30 | struct ipack_bus_ops; |
| 31 | struct ipack_driver; |
| 32 | |
| 33 | enum ipack_space { |
| 34 | IPACK_IO_SPACE = 0, |
| 35 | IPACK_ID_SPACE = 1, |
| 36 | IPACK_MEM_SPACE = 2, |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * struct ipack_addr_space - Virtual address space mapped for a specified type. |
| 41 | * |
| 42 | * @address: virtual address |
| 43 | * @size: size of the mapped space |
| 44 | */ |
| 45 | struct ipack_addr_space { |
Samuel Iglesias Gonsalvez | 5a81b4a | 2012-05-14 12:41:25 +0200 | [diff] [blame] | 46 | void __iomem *address; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 47 | unsigned int size; |
| 48 | }; |
| 49 | |
| 50 | /** |
| 51 | * struct ipack_device |
| 52 | * |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 53 | * @bus_nr: IP bus number where the device is plugged |
| 54 | * @slot: Slot where the device is plugged in the carrier board |
| 55 | * @irq: IRQ vector |
| 56 | * @driver: Pointer to the ipack_driver that manages the device |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 57 | * @bus: ipack_bus_device where the device is plugged to. |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 58 | * @id_space: Virtual address to ID space. |
| 59 | * @io_space: Virtual address to IO space. |
| 60 | * @mem_space: Virtual address to MEM space. |
| 61 | * @dev: device in kernel representation. |
| 62 | * |
| 63 | * Warning: Direct access to mapped memory is possible but the endianness |
| 64 | * is not the same with PCI carrier or VME carrier. The endianness is managed |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 65 | * by the carrier board throught bus->ops. |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 66 | */ |
| 67 | struct ipack_device { |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 68 | unsigned int bus_nr; |
| 69 | unsigned int slot; |
| 70 | unsigned int irq; |
| 71 | struct ipack_driver *driver; |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 72 | struct ipack_bus_device *bus; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 73 | struct ipack_addr_space id_space; |
| 74 | struct ipack_addr_space io_space; |
| 75 | struct ipack_addr_space mem_space; |
| 76 | struct device dev; |
Jens Taprogge | 187e478 | 2012-09-04 17:01:14 +0200 | [diff] [blame^] | 77 | unsigned char *id; |
| 78 | size_t id_avail; |
| 79 | u8 id_format; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 82 | /** |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 83 | * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device |
| 84 | * |
| 85 | * @match: Match function |
| 86 | * @probe: Probe function |
| 87 | * @remove: tell the driver that the carrier board wants to remove one device |
| 88 | */ |
| 89 | |
| 90 | struct ipack_driver_ops { |
| 91 | int (*match) (struct ipack_device *dev); |
| 92 | int (*probe) (struct ipack_device *dev); |
| 93 | void (*remove) (struct ipack_device *dev); |
| 94 | }; |
| 95 | |
| 96 | /** |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 97 | * struct ipack_driver -- Specific data to each ipack board driver |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 98 | * |
| 99 | * @driver: Device driver kernel representation |
| 100 | * @ops: Mezzanine driver operations specific for the ipack bus. |
| 101 | */ |
| 102 | struct ipack_driver { |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 103 | struct device_driver driver; |
Jens Taprogge | 849e0ad | 2012-09-04 17:01:13 +0200 | [diff] [blame] | 104 | const struct ipack_device_id *id_table; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 105 | struct ipack_driver_ops *ops; |
| 106 | }; |
| 107 | |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 108 | /** |
| 109 | * struct ipack_bus_ops - available operations on a bridge module |
| 110 | * |
| 111 | * @map_space: map IP address space |
| 112 | * @unmap_space: unmap IP address space |
| 113 | * @request_irq: request IRQ |
| 114 | * @free_irq: free IRQ |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 115 | * @remove_device: tell the bridge module that the device has been removed |
| 116 | */ |
| 117 | struct ipack_bus_ops { |
| 118 | int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space); |
| 119 | int (*unmap_space) (struct ipack_device *dev, int space); |
| 120 | int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg); |
| 121 | int (*free_irq) (struct ipack_device *dev); |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 122 | int (*remove_device) (struct ipack_device *dev); |
| 123 | }; |
| 124 | |
| 125 | /** |
| 126 | * struct ipack_bus_device |
| 127 | * |
| 128 | * @dev: pointer to carrier device |
| 129 | * @slots: number of slots available |
| 130 | * @bus_nr: ipack bus number |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 131 | * @ops: bus operations for the mezzanine drivers |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 132 | */ |
| 133 | struct ipack_bus_device { |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 134 | struct device *parent; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 135 | int slots; |
| 136 | int bus_nr; |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 137 | struct ipack_bus_ops *ops; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | /** |
| 141 | * ipack_bus_register -- register a new ipack bus |
| 142 | * |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 143 | * @parent: pointer to the parent device, if any. |
| 144 | * @slots: number of slots available in the bus device. |
| 145 | * @ops: bus operations for the mezzanine drivers. |
| 146 | * |
| 147 | * The carrier board device should call this function to register itself as |
| 148 | * available bus device in ipack. |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 149 | */ |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 150 | struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots, |
| 151 | struct ipack_bus_ops *ops); |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * ipack_bus_unregister -- unregister an ipack bus |
| 155 | */ |
| 156 | int ipack_bus_unregister(struct ipack_bus_device *bus); |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame] | 157 | |
| 158 | /** |
| 159 | * ipack_driver_register -- Register a new driver |
| 160 | * |
| 161 | * Called by a ipack driver to register itself as a driver |
| 162 | * that can manage ipack devices. |
| 163 | */ |
| 164 | int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, char *name); |
| 165 | void ipack_driver_unregister(struct ipack_driver *edrv); |
| 166 | |
| 167 | /** |
| 168 | * ipack_device_register -- register a new mezzanine device |
| 169 | * |
| 170 | * @bus: ipack bus device it is plugged to. |
| 171 | * @slot: slot position in the bus device. |
| 172 | * @irqv: IRQ vector for the mezzanine. |
| 173 | * |
| 174 | * Register a new ipack device (mezzanine device). The call is done by |
| 175 | * the carrier device driver. |
| 176 | */ |
| 177 | struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int slot, int irqv); |
| 178 | void ipack_device_unregister(struct ipack_device *dev); |
Jens Taprogge | 849e0ad | 2012-09-04 17:01:13 +0200 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table |
| 182 | * @_table: device table name |
| 183 | * |
| 184 | * This macro is used to create a struct ipack_device_id array (a device table) |
| 185 | * in a generic manner. |
| 186 | */ |
| 187 | #define DEFINE_IPACK_DEVICE_TABLE(_table) \ |
| 188 | const struct ipack_device_id _table[] __devinitconst |
| 189 | |
| 190 | /** |
| 191 | * IPACK_DEVICE - macro used to describe a specific IndustryPack device |
| 192 | * @_format: the format version (currently either 1 or 2, 8 bit value) |
| 193 | * @vend: the 8 or 24 bit IndustryPack Vendor ID |
| 194 | * @dev: the 8 or 16 bit IndustryPack Device ID |
| 195 | * |
| 196 | * This macro is used to create a struct ipack_device_id that matches a specific |
| 197 | * device. |
| 198 | */ |
| 199 | #define IPACK_DEVICE(_format, vend, dev) \ |
| 200 | .format = (_format), \ |
| 201 | .vendor = (vend), \ |
| 202 | .device = (dev) |