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/mod_devicetable.h>
13 #include <linux/device.h>
14 #include <linux/interrupt.h>
16 #include "ipack_ids.h"
18 #define IPACK_IDPROM_OFFSET_I 0x01
19 #define IPACK_IDPROM_OFFSET_P 0x03
20 #define IPACK_IDPROM_OFFSET_A 0x05
21 #define IPACK_IDPROM_OFFSET_C 0x07
22 #define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09
23 #define IPACK_IDPROM_OFFSET_MODEL 0x0B
24 #define IPACK_IDPROM_OFFSET_REVISION 0x0D
25 #define IPACK_IDPROM_OFFSET_RESERVED 0x0F
26 #define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11
27 #define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13
28 #define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15
29 #define IPACK_IDPROM_OFFSET_CRC 0x17
42 * struct ipack_addr_space - Virtual address space mapped for a specified type.
44 * @address: virtual address
45 * @size: size of the mapped space
47 struct ipack_addr_space
{
48 void __iomem
*address
;
55 * @bus_nr: IP bus number where the device is plugged
56 * @slot: Slot where the device is plugged in the carrier board
57 * @bus: ipack_bus_device where the device is plugged to.
58 * @id_space: Virtual address to ID space.
59 * @io_space: Virtual address to IO space.
60 * @mem_space: Virtual address to MEM space.
61 * @dev: device in kernel representation.
63 * Warning: Direct access to mapped memory is possible but the endianness
64 * is not the same with PCI carrier or VME carrier. The endianness is managed
65 * by the carrier board throught bus->ops.
70 struct ipack_bus_device
*bus
;
71 struct ipack_addr_space id_space
;
72 struct ipack_addr_space io_space
;
73 struct ipack_addr_space int_space
;
74 struct ipack_addr_space mem_space
;
81 unsigned int id_crc_correct
:1;
82 unsigned int speed_8mhz
:1;
83 unsigned int speed_32mhz
:1;
87 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
89 * @probe: Probe function
90 * @remove: tell the driver that the carrier board wants to remove one device
93 struct ipack_driver_ops
{
94 int (*probe
) (struct ipack_device
*dev
);
95 void (*remove
) (struct ipack_device
*dev
);
99 * struct ipack_driver -- Specific data to each ipack board driver
101 * @driver: Device driver kernel representation
102 * @ops: Mezzanine driver operations specific for the ipack bus.
104 struct ipack_driver
{
105 struct device_driver driver
;
106 const struct ipack_device_id
*id_table
;
107 const struct ipack_driver_ops
*ops
;
111 * struct ipack_bus_ops - available operations on a bridge module
113 * @map_space: map IP address space
114 * @unmap_space: unmap IP address space
115 * @request_irq: request IRQ
116 * @free_irq: free IRQ
117 * @get_clockrate: Returns the clockrate the carrier is currently
118 * communicating with the device at.
119 * @set_clockrate: Sets the clock-rate for carrier / module communication.
120 * Should return -EINVAL if the requested speed is not supported.
121 * @get_error: Returns the error state for the slot the device is attached
123 * @get_timeout: Returns 1 if the communication with the device has
124 * previously timed out.
125 * @reset_timeout: Resets the state returned by get_timeout.
127 struct ipack_bus_ops
{
128 int (*map_space
) (struct ipack_device
*dev
, unsigned int memory_size
, int space
);
129 int (*unmap_space
) (struct ipack_device
*dev
, int space
);
130 int (*request_irq
) (struct ipack_device
*dev
,
131 irqreturn_t (*handler
)(void *), void *arg
);
132 int (*free_irq
) (struct ipack_device
*dev
);
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
);
141 * struct ipack_bus_device
143 * @dev: pointer to carrier device
144 * @slots: number of slots available
145 * @bus_nr: ipack bus number
146 * @ops: bus operations for the mezzanine drivers
148 struct ipack_bus_device
{
149 struct device
*parent
;
152 const struct ipack_bus_ops
*ops
;
156 * ipack_bus_register -- register a new ipack bus
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.
162 * The carrier board device should call this function to register itself as
163 * available bus device in ipack.
165 struct ipack_bus_device
*ipack_bus_register(struct device
*parent
, int slots
,
166 const struct ipack_bus_ops
*ops
);
169 * ipack_bus_unregister -- unregister an ipack bus
171 int ipack_bus_unregister(struct ipack_bus_device
*bus
);
174 * ipack_driver_register -- Register a new driver
176 * Called by a ipack driver to register itself as a driver
177 * that can manage ipack devices.
179 int ipack_driver_register(struct ipack_driver
*edrv
, struct module
*owner
,
181 void ipack_driver_unregister(struct ipack_driver
*edrv
);
184 * ipack_device_register -- register a new mezzanine device
186 * @bus: ipack bus device it is plugged to.
187 * @slot: slot position in the bus device.
189 * Register a new ipack device (mezzanine device). The call is done by
190 * the carrier device driver.
192 struct ipack_device
*ipack_device_register(struct ipack_bus_device
*bus
, int slot
);
193 void ipack_device_unregister(struct ipack_device
*dev
);
196 * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
197 * @_table: device table name
199 * This macro is used to create a struct ipack_device_id array (a device table)
200 * in a generic manner.
202 #define DEFINE_IPACK_DEVICE_TABLE(_table) \
203 const struct ipack_device_id _table[] __devinitconst
206 * IPACK_DEVICE - macro used to describe a specific IndustryPack device
207 * @_format: the format version (currently either 1 or 2, 8 bit value)
208 * @vend: the 8 or 24 bit IndustryPack Vendor ID
209 * @dev: the 8 or 16 bit IndustryPack Device ID
211 * This macro is used to create a struct ipack_device_id that matches a specific
214 #define IPACK_DEVICE(_format, vend, dev) \
215 .format = (_format), \