blob: 0ea9d849e36ed67d0340285753b58b76ad123019 [file] [log] [blame]
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +02001/*
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
Samuel Iglesias Gonsalvez416289b2012-05-11 10:17:13 +02009 * Software Foundation; version 2 of the License.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020010 */
11
Jens Taprogge849e0ad2012-09-04 17:01:13 +020012#include <linux/mod_devicetable.h>
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020013#include <linux/device.h>
14
Jens Taprogge187e4782012-09-04 17:01:14 +020015#include "ipack_ids.h"
16
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020017#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
29
30struct ipack_bus_ops;
31struct ipack_driver;
32
33enum ipack_space {
34 IPACK_IO_SPACE = 0,
35 IPACK_ID_SPACE = 1,
36 IPACK_MEM_SPACE = 2,
37};
38
39/**
40 * struct ipack_addr_space - Virtual address space mapped for a specified type.
41 *
42 * @address: virtual address
43 * @size: size of the mapped space
44 */
45struct ipack_addr_space {
Samuel Iglesias Gonsalvez5a81b4a2012-05-14 12:41:25 +020046 void __iomem *address;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020047 unsigned int size;
48};
49
50/**
51 * struct ipack_device
52 *
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020053 * @bus_nr: IP bus number where the device is plugged
54 * @slot: Slot where the device is plugged in the carrier board
55 * @irq: IRQ vector
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020056 * @bus: ipack_bus_device where the device is plugged to.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020057 * @id_space: Virtual address to ID space.
58 * @io_space: Virtual address to IO space.
59 * @mem_space: Virtual address to MEM space.
60 * @dev: device in kernel representation.
61 *
62 * Warning: Direct access to mapped memory is possible but the endianness
63 * is not the same with PCI carrier or VME carrier. The endianness is managed
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020064 * by the carrier board throught bus->ops.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020065 */
66struct ipack_device {
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020067 unsigned int bus_nr;
68 unsigned int slot;
69 unsigned int irq;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020070 struct ipack_bus_device *bus;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020071 struct ipack_addr_space id_space;
72 struct ipack_addr_space io_space;
73 struct ipack_addr_space mem_space;
74 struct device dev;
Jens Taproggee8ed3272012-09-04 17:01:15 +020075 u8 *id;
Jens Taprogge187e4782012-09-04 17:01:14 +020076 size_t id_avail;
Jens Taproggee8ed3272012-09-04 17:01:15 +020077 u32 id_vendor;
78 u32 id_device;
Jens Taprogge187e4782012-09-04 17:01:14 +020079 u8 id_format;
Jens Taproggea92caeb2012-09-11 13:35:03 +020080 unsigned int id_crc_correct:1;
Jens Taprogge0b0f3a12012-09-11 13:34:57 +020081 unsigned int speed_8mhz:1;
82 unsigned int speed_32mhz:1;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020083};
84
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020085/**
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020086 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
87 *
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020088 * @probe: Probe function
89 * @remove: tell the driver that the carrier board wants to remove one device
90 */
91
92struct ipack_driver_ops {
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020093 int (*probe) (struct ipack_device *dev);
94 void (*remove) (struct ipack_device *dev);
95};
96
97/**
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020098 * struct ipack_driver -- Specific data to each ipack board driver
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020099 *
100 * @driver: Device driver kernel representation
101 * @ops: Mezzanine driver operations specific for the ipack bus.
102 */
103struct ipack_driver {
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200104 struct device_driver driver;
Jens Taprogge849e0ad2012-09-04 17:01:13 +0200105 const struct ipack_device_id *id_table;
Jens Taproggee8011132012-09-04 17:01:17 +0200106 const struct ipack_driver_ops *ops;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200107};
108
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200109/**
110 * struct ipack_bus_ops - available operations on a bridge module
111 *
112 * @map_space: map IP address space
113 * @unmap_space: unmap IP address space
114 * @request_irq: request IRQ
115 * @free_irq: free IRQ
Jens Taprogge7b6ab332012-09-11 13:34:55 +0200116 * @get_clockrate: Returns the clockrate the carrier is currently
117 * communicating with the device at.
118 * @set_clockrate: Sets the clock-rate for carrier / module communication.
119 * Should return -EINVAL if the requested speed is not supported.
120 * @get_error: Returns the error state for the slot the device is attached
121 * to.
122 * @get_timeout: Returns 1 if the communication with the device has
123 * previously timed out.
124 * @reset_timeout: Resets the state returned by get_timeout.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200125 */
126struct ipack_bus_ops {
127 int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space);
128 int (*unmap_space) (struct ipack_device *dev, int space);
129 int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg);
130 int (*free_irq) (struct ipack_device *dev);
Jens Taprogge7b6ab332012-09-11 13:34:55 +0200131 int (*get_clockrate) (struct ipack_device *dev);
132 int (*set_clockrate) (struct ipack_device *dev, int mherz);
133 int (*get_error) (struct ipack_device *dev);
134 int (*get_timeout) (struct ipack_device *dev);
135 int (*reset_timeout) (struct ipack_device *dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200136};
137
138/**
139 * struct ipack_bus_device
140 *
141 * @dev: pointer to carrier device
142 * @slots: number of slots available
143 * @bus_nr: ipack bus number
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200144 * @ops: bus operations for the mezzanine drivers
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200145 */
146struct ipack_bus_device {
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200147 struct device *parent;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200148 int slots;
149 int bus_nr;
Stephen Hemminger9869a932012-09-10 11:14:01 -0700150 const struct ipack_bus_ops *ops;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200151};
152
153/**
154 * ipack_bus_register -- register a new ipack bus
155 *
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200156 * @parent: pointer to the parent device, if any.
157 * @slots: number of slots available in the bus device.
158 * @ops: bus operations for the mezzanine drivers.
159 *
160 * The carrier board device should call this function to register itself as
161 * available bus device in ipack.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200162 */
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200163struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
Stephen Hemminger9869a932012-09-10 11:14:01 -0700164 const struct ipack_bus_ops *ops);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200165
166/**
167 * ipack_bus_unregister -- unregister an ipack bus
168 */
169int ipack_bus_unregister(struct ipack_bus_device *bus);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200170
171/**
172 * ipack_driver_register -- Register a new driver
173 *
174 * Called by a ipack driver to register itself as a driver
175 * that can manage ipack devices.
176 */
Stephen Hemminger9869a932012-09-10 11:14:01 -0700177int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
178 const char *name);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200179void ipack_driver_unregister(struct ipack_driver *edrv);
180
181/**
182 * ipack_device_register -- register a new mezzanine device
183 *
184 * @bus: ipack bus device it is plugged to.
185 * @slot: slot position in the bus device.
186 * @irqv: IRQ vector for the mezzanine.
187 *
188 * Register a new ipack device (mezzanine device). The call is done by
189 * the carrier device driver.
190 */
Stephen Hemminger9869a932012-09-10 11:14:01 -0700191struct ipack_device *ipack_device_register(struct ipack_bus_device *bus,
192 int slot, int irqv);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200193void ipack_device_unregister(struct ipack_device *dev);
Jens Taprogge849e0ad2012-09-04 17:01:13 +0200194
195/**
196 * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
197 * @_table: device table name
198 *
199 * This macro is used to create a struct ipack_device_id array (a device table)
200 * in a generic manner.
201 */
202#define DEFINE_IPACK_DEVICE_TABLE(_table) \
203 const struct ipack_device_id _table[] __devinitconst
204
205/**
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
210 *
211 * This macro is used to create a struct ipack_device_id that matches a specific
212 * device.
213 */
214#define IPACK_DEVICE(_format, vend, dev) \
215 .format = (_format), \
216 .vendor = (vend), \
217 .device = (dev)