aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ipack.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/ipack.h')
-rw-r--r--include/linux/ipack.h213
1 files changed, 213 insertions, 0 deletions
diff --git a/include/linux/ipack.h b/include/linux/ipack.h
new file mode 100644
index 000000000000..7a0a3085ab5b
--- /dev/null
+++ b/include/linux/ipack.h
@@ -0,0 +1,213 @@
1/*
2 * Industry-pack bus.
3 *
4 * Copyright (C) 2011-2012 CERN (www.cern.ch)
5 * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
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/mod_devicetable.h>
13#include <linux/device.h>
14#include <linux/interrupt.h>
15
16#define IPACK_IDPROM_OFFSET_I 0x01
17#define IPACK_IDPROM_OFFSET_P 0x03
18#define IPACK_IDPROM_OFFSET_A 0x05
19#define IPACK_IDPROM_OFFSET_C 0x07
20#define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09
21#define IPACK_IDPROM_OFFSET_MODEL 0x0B
22#define IPACK_IDPROM_OFFSET_REVISION 0x0D
23#define IPACK_IDPROM_OFFSET_RESERVED 0x0F
24#define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11
25#define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13
26#define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15
27#define IPACK_IDPROM_OFFSET_CRC 0x17
28
29struct ipack_bus_ops;
30struct ipack_driver;
31
32enum ipack_space {
33 IPACK_IO_SPACE = 0,
34 IPACK_ID_SPACE,
35 IPACK_INT_SPACE,
36 IPACK_MEM8_SPACE,
37 IPACK_MEM16_SPACE,
38 /* Dummy for counting the number of entries. Must remain the last
39 * entry */
40 IPACK_SPACE_COUNT,
41};
42
43/**
44 */
45struct ipack_region {
46 phys_addr_t start;
47 size_t size;
48};
49
50/**
51 * struct ipack_device
52 *
53 * @slot: Slot where the device is plugged in the carrier board
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 */
64struct ipack_device {
65 unsigned int slot;
66 struct ipack_bus_device *bus;
67 struct device dev;
68 void (*release) (struct ipack_device *dev);
69 struct ipack_region region[IPACK_SPACE_COUNT];
70 u8 *id;
71 size_t id_avail;
72 u32 id_vendor;
73 u32 id_device;
74 u8 id_format;
75 unsigned int id_crc_correct:1;
76 unsigned int speed_8mhz:1;
77 unsigned int speed_32mhz:1;
78};
79
80/**
81 * struct ipack_driver_ops -- Callbacks to IPack device driver
82 *
83 * @probe: Probe function
84 * @remove: Prepare imminent removal of the device. Services provided by the
85 * device should be revoked.
86 */
87
88struct ipack_driver_ops {
89 int (*probe) (struct ipack_device *dev);
90 void (*remove) (struct ipack_device *dev);
91};
92
93/**
94 * struct ipack_driver -- Specific data to each ipack device driver
95 *
96 * @driver: Device driver kernel representation
97 * @ops: Callbacks provided by the IPack device driver
98 */
99struct ipack_driver {
100 struct device_driver driver;
101 const struct ipack_device_id *id_table;
102 const struct ipack_driver_ops *ops;
103};
104
105/**
106 * struct ipack_bus_ops - available operations on a bridge module
107 *
108 * @map_space: map IP address space
109 * @unmap_space: unmap IP address space
110 * @request_irq: request IRQ
111 * @free_irq: free IRQ
112 * @get_clockrate: Returns the clockrate the carrier is currently
113 * communicating with the device at.
114 * @set_clockrate: Sets the clock-rate for carrier / module communication.
115 * Should return -EINVAL if the requested speed is not supported.
116 * @get_error: Returns the error state for the slot the device is attached
117 * to.
118 * @get_timeout: Returns 1 if the communication with the device has
119 * previously timed out.
120 * @reset_timeout: Resets the state returned by get_timeout.
121 */
122struct ipack_bus_ops {
123 int (*request_irq) (struct ipack_device *dev,
124 irqreturn_t (*handler)(void *), void *arg);
125 int (*free_irq) (struct ipack_device *dev);
126 int (*get_clockrate) (struct ipack_device *dev);
127 int (*set_clockrate) (struct ipack_device *dev, int mherz);
128 int (*get_error) (struct ipack_device *dev);
129 int (*get_timeout) (struct ipack_device *dev);
130 int (*reset_timeout) (struct ipack_device *dev);
131};
132
133/**
134 * struct ipack_bus_device
135 *
136 * @dev: pointer to carrier device
137 * @slots: number of slots available
138 * @bus_nr: ipack bus number
139 * @ops: bus operations for the mezzanine drivers
140 */
141struct ipack_bus_device {
142 struct device *parent;
143 int slots;
144 int bus_nr;
145 const struct ipack_bus_ops *ops;
146};
147
148/**
149 * ipack_bus_register -- register a new ipack bus
150 *
151 * @parent: pointer to the parent device, if any.
152 * @slots: number of slots available in the bus device.
153 * @ops: bus operations for the mezzanine drivers.
154 *
155 * The carrier board device should call this function to register itself as
156 * available bus device in ipack.
157 */
158struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
159 const struct ipack_bus_ops *ops);
160
161/**
162 * ipack_bus_unregister -- unregister an ipack bus
163 */
164int ipack_bus_unregister(struct ipack_bus_device *bus);
165
166/**
167 * ipack_driver_register -- Register a new ipack device driver
168 *
169 * Called by a ipack driver to register itself as a driver
170 * that can manage ipack devices.
171 */
172int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
173 const char *name);
174void ipack_driver_unregister(struct ipack_driver *edrv);
175
176/**
177 * ipack_device_register -- register an IPack device with the kernel
178 * @dev: the new device to register.
179 *
180 * Register a new IPack device ("module" in IndustryPack jargon). The call
181 * is done by the carrier driver. The carrier should populate the fields
182 * bus and slot as well as the region array of @dev prior to calling this
183 * function. The rest of the fields will be allocated and populated
184 * during registration.
185 *
186 * Return zero on success or error code on failure.
187 */
188int ipack_device_register(struct ipack_device *dev);
189void ipack_device_unregister(struct ipack_device *dev);
190
191/**
192 * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
193 * @_table: device table name
194 *
195 * This macro is used to create a struct ipack_device_id array (a device table)
196 * in a generic manner.
197 */
198#define DEFINE_IPACK_DEVICE_TABLE(_table) \
199 const struct ipack_device_id _table[] __devinitconst
200
201/**
202 * IPACK_DEVICE - macro used to describe a specific IndustryPack device
203 * @_format: the format version (currently either 1 or 2, 8 bit value)
204 * @vend: the 8 or 24 bit IndustryPack Vendor ID
205 * @dev: the 8 or 16 bit IndustryPack Device ID
206 *
207 * This macro is used to create a struct ipack_device_id that matches a specific
208 * device.
209 */
210#define IPACK_DEVICE(_format, vend, dev) \
211 .format = (_format), \
212 .vendor = (vend), \
213 .device = (dev)