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 | |
| 12 | #include <linux/device.h> |
| 13 | |
| 14 | #define IPACK_BOARD_NAME_SIZE 16 |
| 15 | #define IPACK_IRQ_NAME_SIZE 50 |
| 16 | #define IPACK_IDPROM_OFFSET_I 0x01 |
| 17 | #define IPACK_IDPROM_OFFSET_P 0x03 |
| 18 | #define IPACK_IDPROM_OFFSET_A 0x05 |
| 19 | #define IPACK_IDPROM_OFFSET_C 0x07 |
| 20 | #define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09 |
| 21 | #define IPACK_IDPROM_OFFSET_MODEL 0x0B |
| 22 | #define IPACK_IDPROM_OFFSET_REVISION 0x0D |
| 23 | #define IPACK_IDPROM_OFFSET_RESERVED 0x0F |
| 24 | #define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11 |
| 25 | #define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13 |
| 26 | #define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15 |
| 27 | #define IPACK_IDPROM_OFFSET_CRC 0x17 |
| 28 | |
| 29 | struct ipack_bus_ops; |
| 30 | struct ipack_driver; |
| 31 | |
| 32 | enum ipack_space { |
| 33 | IPACK_IO_SPACE = 0, |
| 34 | IPACK_ID_SPACE = 1, |
| 35 | IPACK_MEM_SPACE = 2, |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * struct ipack_addr_space - Virtual address space mapped for a specified type. |
| 40 | * |
| 41 | * @address: virtual address |
| 42 | * @size: size of the mapped space |
| 43 | */ |
| 44 | struct ipack_addr_space { |
Samuel Iglesias Gonsalvez | 5a81b4a | 2012-05-14 12:41:25 +0200 | [diff] [blame] | 45 | void __iomem *address; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 46 | unsigned int size; |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * struct ipack_device |
| 51 | * |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 52 | * @bus_nr: IP bus number where the device is plugged |
| 53 | * @slot: Slot where the device is plugged in the carrier board |
| 54 | * @irq: IRQ vector |
| 55 | * @driver: Pointer to the ipack_driver that manages the device |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 56 | * @bus: ipack_bus_device where the device is plugged to. |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 57 | * @id_space: Virtual address to ID space. |
| 58 | * @io_space: Virtual address to IO space. |
| 59 | * @mem_space: Virtual address to MEM space. |
| 60 | * @dev: device in kernel representation. |
| 61 | * |
| 62 | * Warning: Direct access to mapped memory is possible but the endianness |
| 63 | * 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^] | 64 | * by the carrier board throught bus->ops. |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 65 | */ |
| 66 | struct ipack_device { |
| 67 | char board_name[IPACK_BOARD_NAME_SIZE]; |
| 68 | char bus_name[IPACK_BOARD_NAME_SIZE]; |
| 69 | unsigned int bus_nr; |
| 70 | unsigned int slot; |
| 71 | unsigned int irq; |
| 72 | struct ipack_driver *driver; |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 73 | struct ipack_bus_device *bus; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 74 | struct ipack_addr_space id_space; |
| 75 | struct ipack_addr_space io_space; |
| 76 | struct ipack_addr_space mem_space; |
| 77 | struct device dev; |
| 78 | }; |
| 79 | |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 80 | /** |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 81 | * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device |
| 82 | * |
| 83 | * @match: Match function |
| 84 | * @probe: Probe function |
| 85 | * @remove: tell the driver that the carrier board wants to remove one device |
| 86 | */ |
| 87 | |
| 88 | struct ipack_driver_ops { |
| 89 | int (*match) (struct ipack_device *dev); |
| 90 | int (*probe) (struct ipack_device *dev); |
| 91 | void (*remove) (struct ipack_device *dev); |
| 92 | }; |
| 93 | |
| 94 | /** |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 95 | * struct ipack_driver -- Specific data to each ipack board driver |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 96 | * |
| 97 | * @driver: Device driver kernel representation |
| 98 | * @ops: Mezzanine driver operations specific for the ipack bus. |
| 99 | */ |
| 100 | struct ipack_driver { |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 101 | struct device_driver driver; |
| 102 | struct ipack_driver_ops *ops; |
| 103 | }; |
| 104 | |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 105 | /** |
| 106 | * struct ipack_bus_ops - available operations on a bridge module |
| 107 | * |
| 108 | * @map_space: map IP address space |
| 109 | * @unmap_space: unmap IP address space |
| 110 | * @request_irq: request IRQ |
| 111 | * @free_irq: free IRQ |
| 112 | * @read8: read unsigned char |
| 113 | * @read16: read unsigned short |
| 114 | * @read32: read unsigned int |
| 115 | * @write8: read unsigned char |
| 116 | * @write16: read unsigned short |
| 117 | * @write32: read unsigned int |
| 118 | * @remove_device: tell the bridge module that the device has been removed |
| 119 | */ |
| 120 | struct ipack_bus_ops { |
| 121 | int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space); |
| 122 | int (*unmap_space) (struct ipack_device *dev, int space); |
| 123 | int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg); |
| 124 | int (*free_irq) (struct ipack_device *dev); |
| 125 | int (*read8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char *value); |
| 126 | int (*read16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short *value); |
| 127 | int (*read32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int *value); |
| 128 | int (*write8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char value); |
| 129 | int (*write16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short value); |
| 130 | int (*write32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int value); |
| 131 | int (*remove_device) (struct ipack_device *dev); |
| 132 | }; |
| 133 | |
| 134 | /** |
| 135 | * struct ipack_bus_device |
| 136 | * |
| 137 | * @dev: pointer to carrier device |
| 138 | * @slots: number of slots available |
| 139 | * @bus_nr: ipack bus number |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 140 | * @ops: bus operations for the mezzanine drivers |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 141 | */ |
| 142 | struct ipack_bus_device { |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 143 | struct device *parent; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 144 | int slots; |
| 145 | int bus_nr; |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 146 | struct ipack_bus_ops *ops; |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | /** |
| 150 | * ipack_bus_register -- register a new ipack bus |
| 151 | * |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 152 | * @parent: pointer to the parent device, if any. |
| 153 | * @slots: number of slots available in the bus device. |
| 154 | * @ops: bus operations for the mezzanine drivers. |
| 155 | * |
| 156 | * The carrier board device should call this function to register itself as |
| 157 | * available bus device in ipack. |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 158 | */ |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 159 | struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots, |
| 160 | struct ipack_bus_ops *ops); |
Samuel Iglesias Gonsalvez | d346587 | 2012-05-09 15:27:19 +0200 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * ipack_bus_unregister -- unregister an ipack bus |
| 164 | */ |
| 165 | int ipack_bus_unregister(struct ipack_bus_device *bus); |
Samuel Iglesias Gonsalvez | ec44033 | 2012-05-18 11:10:05 +0200 | [diff] [blame^] | 166 | |
| 167 | /** |
| 168 | * ipack_driver_register -- Register a new driver |
| 169 | * |
| 170 | * Called by a ipack driver to register itself as a driver |
| 171 | * that can manage ipack devices. |
| 172 | */ |
| 173 | int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, char *name); |
| 174 | void ipack_driver_unregister(struct ipack_driver *edrv); |
| 175 | |
| 176 | /** |
| 177 | * ipack_device_register -- register a new mezzanine device |
| 178 | * |
| 179 | * @bus: ipack bus device it is plugged to. |
| 180 | * @slot: slot position in the bus device. |
| 181 | * @irqv: IRQ vector for the mezzanine. |
| 182 | * |
| 183 | * Register a new ipack device (mezzanine device). The call is done by |
| 184 | * the carrier device driver. |
| 185 | */ |
| 186 | struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int slot, int irqv); |
| 187 | void ipack_device_unregister(struct ipack_device *dev); |