]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/ipack/ipack.h
powerpc: Put the gpr save/restore functions in their own section
[karo-tx-linux.git] / drivers / staging / ipack / ipack.h
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
9  * Software Foundation; version 2 of the License.
10  */
11
12 #include <linux/device.h>
13
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 {
43         void __iomem *address;
44         unsigned int size;
45 };
46
47 /**
48  *      struct ipack_device
49  *
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
54  *      @bus: ipack_bus_device where the device is plugged to.
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
62  * by the carrier board throught bus->ops.
63  */
64 struct ipack_device {
65         unsigned int bus_nr;
66         unsigned int slot;
67         unsigned int irq;
68         struct ipack_driver *driver;
69         struct ipack_bus_device *bus;
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
76 /**
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 /**
91  *      struct ipack_driver -- Specific data to each ipack board driver
92  *
93  *      @driver: Device driver kernel representation
94  *      @ops: Mezzanine driver operations specific for the ipack bus.
95  */
96 struct ipack_driver {
97         struct device_driver driver;
98         struct ipack_driver_ops *ops;
99 };
100
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
108  *      @read8: read unsigned char
109  *      @read16: read unsigned short
110  *      @read32: read unsigned int
111  *      @write8: read unsigned char
112  *      @write16: read unsigned short
113  *      @write32: read unsigned int
114  *      @remove_device: tell the bridge module that the device has been removed
115  */
116 struct ipack_bus_ops {
117         int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space);
118         int (*unmap_space) (struct ipack_device *dev, int space);
119         int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg);
120         int (*free_irq) (struct ipack_device *dev);
121         int (*read8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char *value);
122         int (*read16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short *value);
123         int (*read32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int *value);
124         int (*write8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char value);
125         int (*write16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short value);
126         int (*write32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int value);
127         int (*remove_device) (struct ipack_device *dev);
128 };
129
130 /**
131  *      struct ipack_bus_device
132  *
133  *      @dev: pointer to carrier device
134  *      @slots: number of slots available
135  *      @bus_nr: ipack bus number
136  *      @ops: bus operations for the mezzanine drivers
137  */
138 struct ipack_bus_device {
139         struct device *parent;
140         int slots;
141         int bus_nr;
142         struct ipack_bus_ops *ops;
143 };
144
145 /**
146  *      ipack_bus_register -- register a new ipack bus
147  *
148  * @parent: pointer to the parent device, if any.
149  * @slots: number of slots available in the bus device.
150  * @ops: bus operations for the mezzanine drivers.
151  *
152  * The carrier board device should call this function to register itself as
153  * available bus device in ipack.
154  */
155 struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
156                                             struct ipack_bus_ops *ops);
157
158 /**
159  *      ipack_bus_unregister -- unregister an ipack bus
160  */
161 int ipack_bus_unregister(struct ipack_bus_device *bus);
162
163 /**
164  *      ipack_driver_register -- Register a new driver
165  *
166  * Called by a ipack driver to register itself as a driver
167  * that can manage ipack devices.
168  */
169 int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, char *name);
170 void ipack_driver_unregister(struct ipack_driver *edrv);
171
172 /**
173  *      ipack_device_register -- register a new mezzanine device
174  *
175  * @bus: ipack bus device it is plugged to.
176  * @slot: slot position in the bus device.
177  * @irqv: IRQ vector for the mezzanine.
178  *
179  * Register a new ipack device (mezzanine device). The call is done by
180  * the carrier device driver.
181  */
182 struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int slot, int irqv);
183 void ipack_device_unregister(struct ipack_device *dev);