staging: ipack: Rename IPACK_MEM_SPACE to IPACK_MEM8_SPACE.
[linux-2.6-block.git] / drivers / staging / ipack / ipack.h
CommitLineData
d3465872
SIG
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
416289b1 9 * Software Foundation; version 2 of the License.
d3465872
SIG
10 */
11
849e0ad2 12#include <linux/mod_devicetable.h>
d3465872 13#include <linux/device.h>
faa75c40 14#include <linux/interrupt.h>
d3465872 15
187e4782
JT
16#include "ipack_ids.h"
17
d3465872
SIG
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
30
31struct ipack_bus_ops;
32struct ipack_driver;
33
34enum ipack_space {
35 IPACK_IO_SPACE = 0,
84a08fa9 36 IPACK_ID_SPACE,
e4af9497 37 IPACK_INT_SPACE,
fe4a3ed0 38 IPACK_MEM8_SPACE,
84a08fa9
JT
39 /* Dummy for counting the number of entries. Must remain the last
40 * entry */
41 IPACK_SPACE_COUNT,
d3465872
SIG
42};
43
bb29ab86
JT
44/**
45 */
46struct ipack_region {
47 phys_addr_t start;
48 size_t size;
49};
50
d3465872
SIG
51/**
52 * struct ipack_device
53 *
d3465872 54 * @slot: Slot where the device is plugged in the carrier board
ec440335 55 * @bus: ipack_bus_device where the device is plugged to.
d3465872
SIG
56 * @id_space: Virtual address to ID space.
57 * @io_space: Virtual address to IO space.
58 * @mem_space: Virtual address to MEM space.
59 * @dev: device in kernel representation.
60 *
61 * Warning: Direct access to mapped memory is possible but the endianness
62 * is not the same with PCI carrier or VME carrier. The endianness is managed
ec440335 63 * by the carrier board throught bus->ops.
d3465872
SIG
64 */
65struct ipack_device {
d3465872 66 unsigned int slot;
ec440335 67 struct ipack_bus_device *bus;
d3465872 68 struct device dev;
1e91795c 69 void (*release) (struct ipack_device *dev);
a19ad7d0 70 struct ipack_region region[IPACK_SPACE_COUNT];
e8ed3276 71 u8 *id;
187e4782 72 size_t id_avail;
e8ed3276
JT
73 u32 id_vendor;
74 u32 id_device;
187e4782 75 u8 id_format;
a92caeb8 76 unsigned int id_crc_correct:1;
0b0f3a1b
JT
77 unsigned int speed_8mhz:1;
78 unsigned int speed_32mhz:1;
d3465872
SIG
79};
80
ec440335 81/**
d3465872
SIG
82 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
83 *
d3465872
SIG
84 * @probe: Probe function
85 * @remove: tell the driver that the carrier board wants to remove one device
86 */
87
88struct ipack_driver_ops {
d3465872
SIG
89 int (*probe) (struct ipack_device *dev);
90 void (*remove) (struct ipack_device *dev);
91};
92
93/**
ec440335 94 * struct ipack_driver -- Specific data to each ipack board driver
d3465872
SIG
95 *
96 * @driver: Device driver kernel representation
97 * @ops: Mezzanine driver operations specific for the ipack bus.
98 */
99struct ipack_driver {
d3465872 100 struct device_driver driver;
849e0ad2 101 const struct ipack_device_id *id_table;
e8011135 102 const struct ipack_driver_ops *ops;
d3465872
SIG
103};
104
d3465872
SIG
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
7b6ab33c
JT
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.
d3465872
SIG
121 */
122struct ipack_bus_ops {
c6e2dfaa 123 int (*request_irq) (struct ipack_device *dev,
faa75c40 124 irqreturn_t (*handler)(void *), void *arg);
d3465872 125 int (*free_irq) (struct ipack_device *dev);
7b6ab33c
JT
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);
d3465872
SIG
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
ec440335 139 * @ops: bus operations for the mezzanine drivers
d3465872
SIG
140 */
141struct ipack_bus_device {
ec440335 142 struct device *parent;
d3465872
SIG
143 int slots;
144 int bus_nr;
9869a937 145 const struct ipack_bus_ops *ops;
d3465872
SIG
146};
147
148/**
149 * ipack_bus_register -- register a new ipack bus
150 *
ec440335
SIG
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.
d3465872 157 */
ec440335 158struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
9869a937 159 const struct ipack_bus_ops *ops);
d3465872
SIG
160
161/**
162 * ipack_bus_unregister -- unregister an ipack bus
163 */
164int ipack_bus_unregister(struct ipack_bus_device *bus);
ec440335
SIG
165
166/**
167 * ipack_driver_register -- Register a new driver
168 *
169 * Called by a ipack driver to register itself as a driver
170 * that can manage ipack devices.
171 */
9869a937
SH
172int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
173 const char *name);
ec440335
SIG
174void ipack_driver_unregister(struct ipack_driver *edrv);
175
176/**
1e91795c
JT
177 * ipack_device_register -- register an IPack device with the kernel
178 * @dev: the new device to register.
ec440335 179 *
1e91795c
JT
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
a19ad7d0
JT
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.
ec440335 185 *
1e91795c 186 * Return zero on success or error code on failure.
ec440335 187 */
1e91795c 188int ipack_device_register(struct ipack_device *dev);
ec440335 189void ipack_device_unregister(struct ipack_device *dev);
849e0ad2
JT
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)