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