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; either version 2 of the License, or (at your option)
13 #include <linux/device.h>
15 #define IPACK_BOARD_NAME_SIZE 16
16 #define IPACK_IRQ_NAME_SIZE 50
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
40 * struct ipack_addr_space - Virtual address space mapped for a specified type.
42 * @address: virtual address
43 * @size: size of the mapped space
45 struct ipack_addr_space
{
53 * @board_name: IP mezzanine board name
54 * @bus_name: IP carrier board name
55 * @bus_nr: IP bus number where the device is plugged
56 * @slot: Slot where the device is plugged in the carrier board
58 * @driver: Pointer to the ipack_driver that manages the device
59 * @ops: Carrier board operations to access the device
60 * @id_space: Virtual address to ID space.
61 * @io_space: Virtual address to IO space.
62 * @mem_space: Virtual address to MEM space.
63 * @dev: device in kernel representation.
65 * Warning: Direct access to mapped memory is possible but the endianness
66 * is not the same with PCI carrier or VME carrier. The endianness is managed
67 * by the carrier board throught @ops.
70 char board_name
[IPACK_BOARD_NAME_SIZE
];
71 char bus_name
[IPACK_BOARD_NAME_SIZE
];
75 struct ipack_driver
*driver
;
76 struct ipack_bus_ops
*ops
;
77 struct ipack_addr_space id_space
;
78 struct ipack_addr_space io_space
;
79 struct ipack_addr_space mem_space
;
84 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
86 * @match: Match function
87 * @probe: Probe function
88 * @remove: tell the driver that the carrier board wants to remove one device
91 struct ipack_driver_ops
{
92 int (*match
) (struct ipack_device
*dev
);
93 int (*probe
) (struct ipack_device
*dev
);
94 void (*remove
) (struct ipack_device
*dev
);
98 * struct ipack_driver -- Specific data to each mezzanine board driver
100 * @driver: Device driver kernel representation
101 * @ops: Mezzanine driver operations specific for the ipack bus.
103 struct ipack_driver
{
104 struct module
*owner
;
105 struct device_driver driver
;
106 struct ipack_driver_ops
*ops
;
110 * ipack_driver_register -- Register a new mezzanine driver
112 * Called by the mezzanine driver to register itself as a driver
113 * that can manage ipack devices.
116 int ipack_driver_register(struct ipack_driver
*edrv
);
117 void ipack_driver_unregister(struct ipack_driver
*edrv
);
120 * ipack_device_register -- register a new mezzanine device
122 * Register a new ipack device (mezzanine device). The call is done by
123 * the carrier device driver.
125 int ipack_device_register(struct ipack_device
*dev
);
126 void ipack_device_unregister(struct ipack_device
*dev
);
129 * struct ipack_bus_ops - available operations on a bridge module
131 * @map_space: map IP address space
132 * @unmap_space: unmap IP address space
133 * @request_irq: request IRQ
134 * @free_irq: free IRQ
135 * @read8: read unsigned char
136 * @read16: read unsigned short
137 * @read32: read unsigned int
138 * @write8: read unsigned char
139 * @write16: read unsigned short
140 * @write32: read unsigned int
141 * @remove_device: tell the bridge module that the device has been removed
143 struct ipack_bus_ops
{
144 int (*map_space
) (struct ipack_device
*dev
, unsigned int memory_size
, int space
);
145 int (*unmap_space
) (struct ipack_device
*dev
, int space
);
146 int (*request_irq
) (struct ipack_device
*dev
, int vector
, int (*handler
)(void *), void *arg
);
147 int (*free_irq
) (struct ipack_device
*dev
);
148 int (*read8
) (struct ipack_device
*dev
, int space
, unsigned long offset
, unsigned char *value
);
149 int (*read16
) (struct ipack_device
*dev
, int space
, unsigned long offset
, unsigned short *value
);
150 int (*read32
) (struct ipack_device
*dev
, int space
, unsigned long offset
, unsigned int *value
);
151 int (*write8
) (struct ipack_device
*dev
, int space
, unsigned long offset
, unsigned char value
);
152 int (*write16
) (struct ipack_device
*dev
, int space
, unsigned long offset
, unsigned short value
);
153 int (*write32
) (struct ipack_device
*dev
, int space
, unsigned long offset
, unsigned int value
);
154 int (*remove_device
) (struct ipack_device
*dev
);
158 * struct ipack_bus_device
160 * @dev: pointer to carrier device
161 * @slots: number of slots available
162 * @bus_nr: ipack bus number
163 * @vector: IRQ base vector. IRQ vectors are $vector + $slot_number
165 struct ipack_bus_device
{
173 * ipack_bus_register -- register a new ipack bus
175 * The carrier board device driver should call this function to register itself
176 * as available bus in ipack.
178 int ipack_bus_register(struct ipack_bus_device
*bus
);
181 * ipack_bus_unregister -- unregister an ipack bus
183 int ipack_bus_unregister(struct ipack_bus_device
*bus
);