blob: a3cd559825279cbd99f56354e9d304ed293bd3de [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
56 * @driver: Pointer to the ipack_driver that manages the device
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020057 * @bus: ipack_bus_device where the device is plugged to.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020058 * @id_space: Virtual address to ID space.
59 * @io_space: Virtual address to IO space.
60 * @mem_space: Virtual address to MEM space.
61 * @dev: device in kernel representation.
62 *
63 * Warning: Direct access to mapped memory is possible but the endianness
64 * is not the same with PCI carrier or VME carrier. The endianness is managed
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020065 * by the carrier board throught bus->ops.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020066 */
67struct ipack_device {
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020068 unsigned int bus_nr;
69 unsigned int slot;
70 unsigned int irq;
71 struct ipack_driver *driver;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020072 struct ipack_bus_device *bus;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020073 struct ipack_addr_space id_space;
74 struct ipack_addr_space io_space;
75 struct ipack_addr_space mem_space;
76 struct device dev;
Jens Taproggee8ed3272012-09-04 17:01:15 +020077 u8 *id;
Jens Taprogge187e4782012-09-04 17:01:14 +020078 size_t id_avail;
Jens Taproggee8ed3272012-09-04 17:01:15 +020079 u32 id_vendor;
80 u32 id_device;
Jens Taprogge187e4782012-09-04 17:01:14 +020081 u8 id_format;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020082};
83
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020084/**
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020085 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
86 *
87 * @match: Match function
88 * @probe: Probe function
89 * @remove: tell the driver that the carrier board wants to remove one device
90 */
91
92struct ipack_driver_ops {
93 int (*match) (struct ipack_device *dev);
94 int (*probe) (struct ipack_device *dev);
95 void (*remove) (struct ipack_device *dev);
96};
97
98/**
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020099 * struct ipack_driver -- Specific data to each ipack board driver
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200100 *
101 * @driver: Device driver kernel representation
102 * @ops: Mezzanine driver operations specific for the ipack bus.
103 */
104struct ipack_driver {
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200105 struct device_driver driver;
Jens Taprogge849e0ad2012-09-04 17:01:13 +0200106 const struct ipack_device_id *id_table;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200107 struct ipack_driver_ops *ops;
108};
109
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200110/**
111 * struct ipack_bus_ops - available operations on a bridge module
112 *
113 * @map_space: map IP address space
114 * @unmap_space: unmap IP address space
115 * @request_irq: request IRQ
116 * @free_irq: free IRQ
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200117 * @remove_device: tell the bridge module that the device has been removed
118 */
119struct ipack_bus_ops {
120 int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space);
121 int (*unmap_space) (struct ipack_device *dev, int space);
122 int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg);
123 int (*free_irq) (struct ipack_device *dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200124 int (*remove_device) (struct ipack_device *dev);
125};
126
127/**
128 * struct ipack_bus_device
129 *
130 * @dev: pointer to carrier device
131 * @slots: number of slots available
132 * @bus_nr: ipack bus number
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200133 * @ops: bus operations for the mezzanine drivers
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200134 */
135struct ipack_bus_device {
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200136 struct device *parent;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200137 int slots;
138 int bus_nr;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200139 struct ipack_bus_ops *ops;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200140};
141
142/**
143 * ipack_bus_register -- register a new ipack bus
144 *
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200145 * @parent: pointer to the parent device, if any.
146 * @slots: number of slots available in the bus device.
147 * @ops: bus operations for the mezzanine drivers.
148 *
149 * The carrier board device should call this function to register itself as
150 * available bus device in ipack.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200151 */
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200152struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
153 struct ipack_bus_ops *ops);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200154
155/**
156 * ipack_bus_unregister -- unregister an ipack bus
157 */
158int ipack_bus_unregister(struct ipack_bus_device *bus);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200159
160/**
161 * ipack_driver_register -- Register a new driver
162 *
163 * Called by a ipack driver to register itself as a driver
164 * that can manage ipack devices.
165 */
166int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, char *name);
167void ipack_driver_unregister(struct ipack_driver *edrv);
168
169/**
170 * ipack_device_register -- register a new mezzanine device
171 *
172 * @bus: ipack bus device it is plugged to.
173 * @slot: slot position in the bus device.
174 * @irqv: IRQ vector for the mezzanine.
175 *
176 * Register a new ipack device (mezzanine device). The call is done by
177 * the carrier device driver.
178 */
179struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int slot, int irqv);
180void ipack_device_unregister(struct ipack_device *dev);
Jens Taprogge849e0ad2012-09-04 17:01:13 +0200181
182/**
183 * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
184 * @_table: device table name
185 *
186 * This macro is used to create a struct ipack_device_id array (a device table)
187 * in a generic manner.
188 */
189#define DEFINE_IPACK_DEVICE_TABLE(_table) \
190 const struct ipack_device_id _table[] __devinitconst
191
192/**
193 * IPACK_DEVICE - macro used to describe a specific IndustryPack device
194 * @_format: the format version (currently either 1 or 2, 8 bit value)
195 * @vend: the 8 or 24 bit IndustryPack Vendor ID
196 * @dev: the 8 or 16 bit IndustryPack Device ID
197 *
198 * This macro is used to create a struct ipack_device_id that matches a specific
199 * device.
200 */
201#define IPACK_DEVICE(_format, vend, dev) \
202 .format = (_format), \
203 .vendor = (vend), \
204 .device = (dev)