Commit | Line | Data |
---|---|---|
d3465872 SIG |
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 | |
416289b1 | 9 | * Software Foundation; version 2 of the License. |
d3465872 SIG |
10 | */ |
11 | ||
849e0ad2 | 12 | #include <linux/mod_devicetable.h> |
d3465872 SIG |
13 | #include <linux/device.h> |
14 | ||
187e4782 JT |
15 | #include "ipack_ids.h" |
16 | ||
d3465872 SIG |
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 { | |
5a81b4a0 | 46 | void __iomem *address; |
d3465872 SIG |
47 | unsigned int size; |
48 | }; | |
49 | ||
50 | /** | |
51 | * struct ipack_device | |
52 | * | |
d3465872 SIG |
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 | |
ec440335 | 56 | * @bus: ipack_bus_device where the device is plugged to. |
d3465872 SIG |
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 | |
ec440335 | 64 | * by the carrier board throught bus->ops. |
d3465872 SIG |
65 | */ |
66 | struct ipack_device { | |
d3465872 SIG |
67 | unsigned int bus_nr; |
68 | unsigned int slot; | |
69 | unsigned int irq; | |
ec440335 | 70 | struct ipack_bus_device *bus; |
d3465872 SIG |
71 | struct ipack_addr_space id_space; |
72 | struct ipack_addr_space io_space; | |
73 | struct ipack_addr_space mem_space; | |
74 | struct device dev; | |
e8ed3276 | 75 | u8 *id; |
187e4782 | 76 | size_t id_avail; |
e8ed3276 JT |
77 | u32 id_vendor; |
78 | u32 id_device; | |
187e4782 | 79 | u8 id_format; |
0b0f3a1b JT |
80 | unsigned int speed_8mhz:1; |
81 | unsigned int speed_32mhz:1; | |
d3465872 SIG |
82 | }; |
83 | ||
ec440335 | 84 | /** |
d3465872 SIG |
85 | * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device |
86 | * | |
d3465872 SIG |
87 | * @probe: Probe function |
88 | * @remove: tell the driver that the carrier board wants to remove one device | |
89 | */ | |
90 | ||
91 | struct ipack_driver_ops { | |
d3465872 SIG |
92 | int (*probe) (struct ipack_device *dev); |
93 | void (*remove) (struct ipack_device *dev); | |
94 | }; | |
95 | ||
96 | /** | |
ec440335 | 97 | * struct ipack_driver -- Specific data to each ipack board driver |
d3465872 SIG |
98 | * |
99 | * @driver: Device driver kernel representation | |
100 | * @ops: Mezzanine driver operations specific for the ipack bus. | |
101 | */ | |
102 | struct ipack_driver { | |
d3465872 | 103 | struct device_driver driver; |
849e0ad2 | 104 | const struct ipack_device_id *id_table; |
e8011135 | 105 | const struct ipack_driver_ops *ops; |
d3465872 SIG |
106 | }; |
107 | ||
d3465872 SIG |
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 | |
d3465872 | 115 | * @remove_device: tell the bridge module that the device has been removed |
7b6ab33c JT |
116 | * @get_clockrate: Returns the clockrate the carrier is currently |
117 | * communicating with the device at. | |
118 | * @set_clockrate: Sets the clock-rate for carrier / module communication. | |
119 | * Should return -EINVAL if the requested speed is not supported. | |
120 | * @get_error: Returns the error state for the slot the device is attached | |
121 | * to. | |
122 | * @get_timeout: Returns 1 if the communication with the device has | |
123 | * previously timed out. | |
124 | * @reset_timeout: Resets the state returned by get_timeout. | |
d3465872 SIG |
125 | */ |
126 | struct ipack_bus_ops { | |
127 | int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space); | |
128 | int (*unmap_space) (struct ipack_device *dev, int space); | |
129 | int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg); | |
130 | int (*free_irq) (struct ipack_device *dev); | |
d3465872 | 131 | int (*remove_device) (struct ipack_device *dev); |
7b6ab33c JT |
132 | |
133 | int (*get_clockrate) (struct ipack_device *dev); | |
134 | int (*set_clockrate) (struct ipack_device *dev, int mherz); | |
135 | int (*get_error) (struct ipack_device *dev); | |
136 | int (*get_timeout) (struct ipack_device *dev); | |
137 | int (*reset_timeout) (struct ipack_device *dev); | |
d3465872 SIG |
138 | }; |
139 | ||
140 | /** | |
141 | * struct ipack_bus_device | |
142 | * | |
143 | * @dev: pointer to carrier device | |
144 | * @slots: number of slots available | |
145 | * @bus_nr: ipack bus number | |
ec440335 | 146 | * @ops: bus operations for the mezzanine drivers |
d3465872 SIG |
147 | */ |
148 | struct ipack_bus_device { | |
ec440335 | 149 | struct device *parent; |
d3465872 SIG |
150 | int slots; |
151 | int bus_nr; | |
9869a937 | 152 | const struct ipack_bus_ops *ops; |
d3465872 SIG |
153 | }; |
154 | ||
155 | /** | |
156 | * ipack_bus_register -- register a new ipack bus | |
157 | * | |
ec440335 SIG |
158 | * @parent: pointer to the parent device, if any. |
159 | * @slots: number of slots available in the bus device. | |
160 | * @ops: bus operations for the mezzanine drivers. | |
161 | * | |
162 | * The carrier board device should call this function to register itself as | |
163 | * available bus device in ipack. | |
d3465872 | 164 | */ |
ec440335 | 165 | struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots, |
9869a937 | 166 | const struct ipack_bus_ops *ops); |
d3465872 SIG |
167 | |
168 | /** | |
169 | * ipack_bus_unregister -- unregister an ipack bus | |
170 | */ | |
171 | int ipack_bus_unregister(struct ipack_bus_device *bus); | |
ec440335 SIG |
172 | |
173 | /** | |
174 | * ipack_driver_register -- Register a new driver | |
175 | * | |
176 | * Called by a ipack driver to register itself as a driver | |
177 | * that can manage ipack devices. | |
178 | */ | |
9869a937 SH |
179 | int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, |
180 | const char *name); | |
ec440335 SIG |
181 | void ipack_driver_unregister(struct ipack_driver *edrv); |
182 | ||
183 | /** | |
184 | * ipack_device_register -- register a new mezzanine device | |
185 | * | |
186 | * @bus: ipack bus device it is plugged to. | |
187 | * @slot: slot position in the bus device. | |
188 | * @irqv: IRQ vector for the mezzanine. | |
189 | * | |
190 | * Register a new ipack device (mezzanine device). The call is done by | |
191 | * the carrier device driver. | |
192 | */ | |
9869a937 SH |
193 | struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, |
194 | int slot, int irqv); | |
ec440335 | 195 | void ipack_device_unregister(struct ipack_device *dev); |
849e0ad2 JT |
196 | |
197 | /** | |
198 | * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table | |
199 | * @_table: device table name | |
200 | * | |
201 | * This macro is used to create a struct ipack_device_id array (a device table) | |
202 | * in a generic manner. | |
203 | */ | |
204 | #define DEFINE_IPACK_DEVICE_TABLE(_table) \ | |
205 | const struct ipack_device_id _table[] __devinitconst | |
206 | ||
207 | /** | |
208 | * IPACK_DEVICE - macro used to describe a specific IndustryPack device | |
209 | * @_format: the format version (currently either 1 or 2, 8 bit value) | |
210 | * @vend: the 8 or 24 bit IndustryPack Vendor ID | |
211 | * @dev: the 8 or 16 bit IndustryPack Device ID | |
212 | * | |
213 | * This macro is used to create a struct ipack_device_id that matches a specific | |
214 | * device. | |
215 | */ | |
216 | #define IPACK_DEVICE(_format, vend, dev) \ | |
217 | .format = (_format), \ | |
218 | .vendor = (vend), \ | |
219 | .device = (dev) |