Blame view

include/linux/ipack.h 8.85 KB
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
1
2
3
  /*
   * Industry-pack bus.
   *
76859725a   Samuel Iglesias Gonsalvez   Staging: ipack: a...
4
5
   * Copyright (C) 2011-2012 CERN (www.cern.ch)
   * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
6
7
8
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License as published by the Free
416289b14   Samuel Iglesias Gonsalvez   Staging: ipack: c...
9
   * Software Foundation; version 2 of the License.
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
10
   */
849e0ad25   Jens Taprogge   Staging: ipack: i...
11
  #include <linux/mod_devicetable.h>
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
12
  #include <linux/device.h>
faa75c406   Jens Taprogge   Staging: ipack: L...
13
  #include <linux/interrupt.h>
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
14

d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
15
16
17
18
19
20
21
22
23
24
25
26
  #define IPACK_IDPROM_OFFSET_I			0x01
  #define IPACK_IDPROM_OFFSET_P			0x03
  #define IPACK_IDPROM_OFFSET_A			0x05
  #define IPACK_IDPROM_OFFSET_C			0x07
  #define IPACK_IDPROM_OFFSET_MANUFACTURER_ID	0x09
  #define IPACK_IDPROM_OFFSET_MODEL		0x0B
  #define IPACK_IDPROM_OFFSET_REVISION		0x0D
  #define IPACK_IDPROM_OFFSET_RESERVED		0x0F
  #define IPACK_IDPROM_OFFSET_DRIVER_ID_L		0x11
  #define IPACK_IDPROM_OFFSET_DRIVER_ID_H		0x13
  #define IPACK_IDPROM_OFFSET_NUM_BYTES		0x15
  #define IPACK_IDPROM_OFFSET_CRC			0x17
27cf2d1b8   Samuel Iglesias Gonsalvez   ipack: remove ipa...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  /*
   * IndustryPack Fromat, Vendor and Device IDs.
   */
  
  /* ID section format versions */
  #define IPACK_ID_VERSION_INVALID	0x00
  #define IPACK_ID_VERSION_1		0x01
  #define IPACK_ID_VERSION_2		0x02
  
  /* Vendors and devices. Sort key: vendor first, device next. */
  #define IPACK1_VENDOR_ID_RESERVED1	0x00
  #define IPACK1_VENDOR_ID_RESERVED2	0xFF
  #define IPACK1_VENDOR_ID_UNREGISTRED01	0x01
  #define IPACK1_VENDOR_ID_UNREGISTRED02	0x02
  #define IPACK1_VENDOR_ID_UNREGISTRED03	0x03
  #define IPACK1_VENDOR_ID_UNREGISTRED04	0x04
  #define IPACK1_VENDOR_ID_UNREGISTRED05	0x05
  #define IPACK1_VENDOR_ID_UNREGISTRED06	0x06
  #define IPACK1_VENDOR_ID_UNREGISTRED07	0x07
  #define IPACK1_VENDOR_ID_UNREGISTRED08	0x08
  #define IPACK1_VENDOR_ID_UNREGISTRED09	0x09
  #define IPACK1_VENDOR_ID_UNREGISTRED10	0x0A
  #define IPACK1_VENDOR_ID_UNREGISTRED11	0x0B
  #define IPACK1_VENDOR_ID_UNREGISTRED12	0x0C
  #define IPACK1_VENDOR_ID_UNREGISTRED13	0x0D
  #define IPACK1_VENDOR_ID_UNREGISTRED14	0x0E
  #define IPACK1_VENDOR_ID_UNREGISTRED15	0x0F
  
  #define IPACK1_VENDOR_ID_SBS            0xF0
  #define IPACK1_DEVICE_ID_SBS_OCTAL_232  0x22
  #define IPACK1_DEVICE_ID_SBS_OCTAL_422  0x2A
  #define IPACK1_DEVICE_ID_SBS_OCTAL_485  0x48
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
59
60
61
62
63
  struct ipack_bus_ops;
  struct ipack_driver;
  
  enum ipack_space {
  	IPACK_IO_SPACE    = 0,
84a08fa9e   Jens Taprogge   Staging: ipack/br...
64
  	IPACK_ID_SPACE,
e4af9497b   Jens Taprogge   Staging: ipack: A...
65
  	IPACK_INT_SPACE,
fe4a3ed0d   Jens Taprogge   staging: ipack: R...
66
  	IPACK_MEM8_SPACE,
48a97352e   Jens Taprogge   staging: ipack: A...
67
  	IPACK_MEM16_SPACE,
84a08fa9e   Jens Taprogge   Staging: ipack/br...
68
69
70
  	/* Dummy for counting the number of entries.  Must remain the last
  	 * entry */
  	IPACK_SPACE_COUNT,
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
71
72
73
  };
  
  /**
bb29ab86d   Jens Taprogge   Staging: ipack/br...
74
75
76
77
78
79
80
   */
  struct ipack_region {
  	phys_addr_t start;
  	size_t      size;
  };
  
  /**
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
81
82
   *	struct ipack_device
   *
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
83
   *	@slot: Slot where the device is plugged in the carrier board
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
84
   *	@bus: ipack_bus_device where the device is plugged to.
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
85
86
87
88
89
90
91
   *	@id_space: Virtual address to ID space.
   *	@io_space: Virtual address to IO space.
   *	@mem_space: Virtual address to MEM space.
   *	@dev: device in kernel representation.
   *
   * Warning: Direct access to mapped memory is possible but the endianness
   * is not the same with PCI carrier or VME carrier. The endianness is managed
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
92
   * by the carrier board throught bus->ops.
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
93
94
   */
  struct ipack_device {
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
95
  	unsigned int slot;
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
96
  	struct ipack_bus_device *bus;
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
97
  	struct device dev;
1e91795c8   Jens Taprogge   Staging: ipack: M...
98
  	void (*release) (struct ipack_device *dev);
a19ad7d08   Jens Taprogge   Staging: ipack: P...
99
  	struct ipack_region      region[IPACK_SPACE_COUNT];
e8ed3276c   Jens Taprogge   Staging: ipack: P...
100
  	u8                      *id;
187e47824   Jens Taprogge   Staging: ipack: R...
101
  	size_t			 id_avail;
e8ed3276c   Jens Taprogge   Staging: ipack: P...
102
103
  	u32			 id_vendor;
  	u32			 id_device;
187e47824   Jens Taprogge   Staging: ipack: R...
104
  	u8			 id_format;
a92caeb8e   Jens Taprogge   Staging: ipack: c...
105
  	unsigned int		 id_crc_correct:1;
0b0f3a1be   Jens Taprogge   Staging: ipack: O...
106
107
  	unsigned int		 speed_8mhz:1;
  	unsigned int		 speed_32mhz:1;
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
108
  };
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
109
  /**
26c295cb4   Jens Taprogge   staging: ipack: D...
110
   * struct ipack_driver_ops -- Callbacks to IPack device driver
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
111
   *
26c295cb4   Jens Taprogge   staging: ipack: D...
112
113
114
   * @probe:  Probe function
   * @remove: Prepare imminent removal of the device.  Services provided by the
   *          device should be revoked.
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
115
116
117
   */
  
  struct ipack_driver_ops {
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
118
119
120
121
122
  	int (*probe) (struct ipack_device *dev);
  	void (*remove) (struct ipack_device *dev);
  };
  
  /**
26c295cb4   Jens Taprogge   staging: ipack: D...
123
   * struct ipack_driver -- Specific data to each ipack device driver
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
124
   *
26c295cb4   Jens Taprogge   staging: ipack: D...
125
126
   * @driver: Device driver kernel representation
   * @ops:    Callbacks provided by the IPack device driver
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
127
128
   */
  struct ipack_driver {
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
129
  	struct device_driver driver;
849e0ad25   Jens Taprogge   Staging: ipack: i...
130
  	const struct ipack_device_id *id_table;
e80111354   Jens Taprogge   Staging: ipack: M...
131
  	const struct ipack_driver_ops *ops;
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
132
  };
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
133
134
135
136
137
138
139
  /**
   *	struct ipack_bus_ops - available operations on a bridge module
   *
   *	@map_space: map IP address space
   *	@unmap_space: unmap IP address space
   *	@request_irq: request IRQ
   *	@free_irq: free IRQ
7b6ab33c2   Jens Taprogge   Staging: ipack: P...
140
141
142
143
144
145
146
147
148
   *	@get_clockrate: Returns the clockrate the carrier is currently
   *		communicating with the device at.
   *	@set_clockrate: Sets the clock-rate for carrier / module communication.
   *		Should return -EINVAL if the requested speed is not supported.
   *	@get_error: Returns the error state for the slot the device is attached
   *		to.
   *	@get_timeout: Returns 1 if the communication with the device has
   *		previously timed out.
   *	@reset_timeout: Resets the state returned by get_timeout.
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
149
150
   */
  struct ipack_bus_ops {
c6e2dfaa5   Jens Taprogge   staging: ipack: r...
151
  	int (*request_irq) (struct ipack_device *dev,
faa75c406   Jens Taprogge   Staging: ipack: L...
152
  			    irqreturn_t (*handler)(void *), void *arg);
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
153
  	int (*free_irq) (struct ipack_device *dev);
7b6ab33c2   Jens Taprogge   Staging: ipack: P...
154
155
156
157
158
  	int (*get_clockrate) (struct ipack_device *dev);
  	int (*set_clockrate) (struct ipack_device *dev, int mherz);
  	int (*get_error) (struct ipack_device *dev);
  	int (*get_timeout) (struct ipack_device *dev);
  	int (*reset_timeout) (struct ipack_device *dev);
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
159
160
161
162
163
164
165
166
  };
  
  /**
   *	struct ipack_bus_device
   *
   *	@dev: pointer to carrier device
   *	@slots: number of slots available
   *	@bus_nr: ipack bus number
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
167
   *	@ops: bus operations for the mezzanine drivers
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
168
169
   */
  struct ipack_bus_device {
36c53b3cc   Federico Vaga   ipack: save carri...
170
  	struct module *owner;
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
171
  	struct device *parent;
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
172
173
  	int slots;
  	int bus_nr;
9869a937d   Stephen Hemminger   staging: ipack: m...
174
  	const struct ipack_bus_ops *ops;
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
175
176
177
178
179
  };
  
  /**
   *	ipack_bus_register -- register a new ipack bus
   *
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
180
181
182
183
184
185
   * @parent: pointer to the parent device, if any.
   * @slots: number of slots available in the bus device.
   * @ops: bus operations for the mezzanine drivers.
   *
   * The carrier board device should call this function to register itself as
   * available bus device in ipack.
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
186
   */
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
187
  struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
36c53b3cc   Federico Vaga   ipack: save carri...
188
189
  					    const struct ipack_bus_ops *ops,
  					    struct module *owner);
d3465872c   Samuel Iglesias Gonsalvez   Staging: Industry...
190
191
192
193
194
  
  /**
   *	ipack_bus_unregister -- unregister an ipack bus
   */
  int ipack_bus_unregister(struct ipack_bus_device *bus);
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
195
196
  
  /**
26c295cb4   Jens Taprogge   staging: ipack: D...
197
   * ipack_driver_register -- Register a new ipack device driver
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
198
199
200
201
   *
   * Called by a ipack driver to register itself as a driver
   * that can manage ipack devices.
   */
9869a937d   Stephen Hemminger   staging: ipack: m...
202
203
  int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
  			  const char *name);
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
204
205
206
  void ipack_driver_unregister(struct ipack_driver *edrv);
  
  /**
e926301b3   Samuel Iglesias Gonsalvez   ipack: split ipac...
207
208
   *	ipack_device_init -- initialize an IPack device
   * @dev: the new device to initialize.
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
209
   *
e926301b3   Samuel Iglesias Gonsalvez   ipack: split ipac...
210
211
212
213
214
   * Initialize a new IPack device ("module" in IndustryPack jargon). The call
   * is done by the carrier driver.  The carrier should populate the fields
   * bus and slot as well as the region array of @dev prior to calling this
   * function.  The rest of the fields will be allocated and populated
   * during initalization.
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
215
   *
e926301b3   Samuel Iglesias Gonsalvez   ipack: split ipac...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
   * Return zero on success or error code on failure.
   *
   * NOTE: _Never_ directly free @dev after calling this function, even
   * if it returned an error! Always use ipack_put_device() to give up the
   * reference initialized in this function instead.
   */
  int ipack_device_init(struct ipack_device *dev);
  
  /**
   *	ipack_device_add -- Add an IPack device
   * @dev: the new device to add.
   *
   * Add a new IPack device. The call is done by the carrier driver
   * after calling ipack_device_init().
   *
   * Return zero on success or error code on failure.
   *
   * NOTE: _Never_ directly free @dev after calling this function, even
   * if it returned an error! Always use ipack_put_device() to give up the
   * reference initialized in this function instead.
ec440335b   Samuel Iglesias Gonsalvez   Staging: ipack: i...
236
   */
e926301b3   Samuel Iglesias Gonsalvez   ipack: split ipac...
237
238
  int ipack_device_add(struct ipack_device *dev);
  void ipack_device_del(struct ipack_device *dev);
849e0ad25   Jens Taprogge   Staging: ipack: i...
239

fa882867a   Samuel Iglesias Gonsalvez   ipack: add ipack_...
240
241
  void ipack_get_device(struct ipack_device *dev);
  void ipack_put_device(struct ipack_device *dev);
849e0ad25   Jens Taprogge   Staging: ipack: i...
242
243
244
245
246
247
248
249
  /**
   * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
   * @_table: device table name
   *
   * This macro is used to create a struct ipack_device_id array (a device table)
   * in a generic manner.
   */
  #define DEFINE_IPACK_DEVICE_TABLE(_table) \
d79251f0f   Bill Pemberton   ipack: remove use...
250
  	const struct ipack_device_id _table[]
849e0ad25   Jens Taprogge   Staging: ipack: i...
251
252
253
254
255
256
257
258
259
260
261
262
263
  /**
   * IPACK_DEVICE - macro used to describe a specific IndustryPack device
   * @_format: the format version (currently either 1 or 2, 8 bit value)
   * @vend:    the 8 or 24 bit IndustryPack Vendor ID
   * @dev:     the 8 or 16  bit IndustryPack Device ID
   *
   * This macro is used to create a struct ipack_device_id that matches a specific
   * device.
   */
  #define IPACK_DEVICE(_format, vend, dev) \
  	 .format = (_format), \
  	 .vendor = (vend), \
  	 .device = (dev)
36c53b3cc   Federico Vaga   ipack: save carri...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
  
  /**
   * ipack_get_carrier - it increase the carrier ref. counter of
   *                     the carrier module
   * @dev: mezzanine device which wants to get the carrier
   */
  static inline int ipack_get_carrier(struct ipack_device *dev)
  {
  	return try_module_get(dev->bus->owner);
  }
  
  /**
   * ipack_get_carrier - it decrease the carrier ref. counter of
   *                     the carrier module
   * @dev: mezzanine device which wants to get the carrier
   */
  static inline void ipack_put_carrier(struct ipack_device *dev)
  {
  	module_put(dev->bus->owner);
  }