4 * (C) 2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
5 * (C) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
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.
12 #include <linux/device.h>
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
37 * struct ipack_addr_space - Virtual address space mapped for a specified type.
39 * @address: virtual address
40 * @size: size of the mapped space
42 struct ipack_addr_space
{
43 void __iomem
*address
;
50 * @bus_nr: IP bus number where the device is plugged
51 * @slot: Slot where the device is plugged in the carrier board
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.
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.
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
;
77 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
79 * @match: Match function
80 * @probe: Probe function
81 * @remove: tell the driver that the carrier board wants to remove one device
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
);
91 * struct ipack_driver -- Specific data to each ipack board driver
93 * @driver: Device driver kernel representation
94 * @ops: Mezzanine driver operations specific for the ipack bus.
97 struct device_driver driver
;
98 struct ipack_driver_ops
*ops
;
102 * struct ipack_bus_ops - available operations on a bridge module
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
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
);
131 * struct ipack_bus_device
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
138 struct ipack_bus_device
{
139 struct device
*parent
;
142 struct ipack_bus_ops
*ops
;
146 * ipack_bus_register -- register a new ipack bus
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.
152 * The carrier board device should call this function to register itself as
153 * available bus device in ipack.
155 struct ipack_bus_device
*ipack_bus_register(struct device
*parent
, int slots
,
156 struct ipack_bus_ops
*ops
);
159 * ipack_bus_unregister -- unregister an ipack bus
161 int ipack_bus_unregister(struct ipack_bus_device
*bus
);
164 * ipack_driver_register -- Register a new driver
166 * Called by a ipack driver to register itself as a driver
167 * that can manage ipack devices.
169 int ipack_driver_register(struct ipack_driver
*edrv
, struct module
*owner
, char *name
);
170 void ipack_driver_unregister(struct ipack_driver
*edrv
);
173 * ipack_device_register -- register a new mezzanine device
175 * @bus: ipack bus device it is plugged to.
176 * @slot: slot position in the bus device.
177 * @irqv: IRQ vector for the mezzanine.
179 * Register a new ipack device (mezzanine device). The call is done by
180 * the carrier device driver.
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
);