blob: 703142d1859b1736aaded18fee02c7620e8130cb [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
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020015#define IPACK_IDPROM_OFFSET_I 0x01
16#define IPACK_IDPROM_OFFSET_P 0x03
17#define IPACK_IDPROM_OFFSET_A 0x05
18#define IPACK_IDPROM_OFFSET_C 0x07
19#define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09
20#define IPACK_IDPROM_OFFSET_MODEL 0x0B
21#define IPACK_IDPROM_OFFSET_REVISION 0x0D
22#define IPACK_IDPROM_OFFSET_RESERVED 0x0F
23#define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11
24#define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13
25#define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15
26#define IPACK_IDPROM_OFFSET_CRC 0x17
27
28struct ipack_bus_ops;
29struct ipack_driver;
30
31enum ipack_space {
32 IPACK_IO_SPACE = 0,
33 IPACK_ID_SPACE = 1,
34 IPACK_MEM_SPACE = 2,
35};
36
37/**
38 * struct ipack_addr_space - Virtual address space mapped for a specified type.
39 *
40 * @address: virtual address
41 * @size: size of the mapped space
42 */
43struct ipack_addr_space {
Samuel Iglesias Gonsalvez5a81b4a2012-05-14 12:41:25 +020044 void __iomem *address;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020045 unsigned int size;
46};
47
48/**
49 * struct ipack_device
50 *
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020051 * @bus_nr: IP bus number where the device is plugged
52 * @slot: Slot where the device is plugged in the carrier board
53 * @irq: IRQ vector
54 * @driver: Pointer to the ipack_driver that manages the device
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020055 * @bus: ipack_bus_device where the device is plugged to.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020056 * @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
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020063 * by the carrier board throught bus->ops.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020064 */
65struct ipack_device {
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020066 unsigned int bus_nr;
67 unsigned int slot;
68 unsigned int irq;
69 struct ipack_driver *driver;
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;
75};
76
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020077/**
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020078 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
79 *
80 * @match: Match function
81 * @probe: Probe function
82 * @remove: tell the driver that the carrier board wants to remove one device
83 */
84
85struct ipack_driver_ops {
86 int (*match) (struct ipack_device *dev);
87 int (*probe) (struct ipack_device *dev);
88 void (*remove) (struct ipack_device *dev);
89};
90
91/**
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020092 * struct ipack_driver -- Specific data to each ipack board driver
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020093 *
94 * @driver: Device driver kernel representation
95 * @ops: Mezzanine driver operations specific for the ipack bus.
96 */
97struct ipack_driver {
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020098 struct device_driver driver;
Jens Taprogge849e0ad2012-09-04 17:01:13 +020099 const struct ipack_device_id *id_table;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200100 struct ipack_driver_ops *ops;
101};
102
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200103/**
104 * struct ipack_bus_ops - available operations on a bridge module
105 *
106 * @map_space: map IP address space
107 * @unmap_space: unmap IP address space
108 * @request_irq: request IRQ
109 * @free_irq: free IRQ
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200110 * @remove_device: tell the bridge module that the device has been removed
111 */
112struct ipack_bus_ops {
113 int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space);
114 int (*unmap_space) (struct ipack_device *dev, int space);
115 int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg);
116 int (*free_irq) (struct ipack_device *dev);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200117 int (*remove_device) (struct ipack_device *dev);
118};
119
120/**
121 * struct ipack_bus_device
122 *
123 * @dev: pointer to carrier device
124 * @slots: number of slots available
125 * @bus_nr: ipack bus number
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200126 * @ops: bus operations for the mezzanine drivers
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200127 */
128struct ipack_bus_device {
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200129 struct device *parent;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200130 int slots;
131 int bus_nr;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200132 struct ipack_bus_ops *ops;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200133};
134
135/**
136 * ipack_bus_register -- register a new ipack bus
137 *
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200138 * @parent: pointer to the parent device, if any.
139 * @slots: number of slots available in the bus device.
140 * @ops: bus operations for the mezzanine drivers.
141 *
142 * The carrier board device should call this function to register itself as
143 * available bus device in ipack.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200144 */
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200145struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
146 struct ipack_bus_ops *ops);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200147
148/**
149 * ipack_bus_unregister -- unregister an ipack bus
150 */
151int ipack_bus_unregister(struct ipack_bus_device *bus);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200152
153/**
154 * ipack_driver_register -- Register a new driver
155 *
156 * Called by a ipack driver to register itself as a driver
157 * that can manage ipack devices.
158 */
159int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, char *name);
160void ipack_driver_unregister(struct ipack_driver *edrv);
161
162/**
163 * ipack_device_register -- register a new mezzanine device
164 *
165 * @bus: ipack bus device it is plugged to.
166 * @slot: slot position in the bus device.
167 * @irqv: IRQ vector for the mezzanine.
168 *
169 * Register a new ipack device (mezzanine device). The call is done by
170 * the carrier device driver.
171 */
172struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int slot, int irqv);
173void ipack_device_unregister(struct ipack_device *dev);
Jens Taprogge849e0ad2012-09-04 17:01:13 +0200174
175/**
176 * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
177 * @_table: device table name
178 *
179 * This macro is used to create a struct ipack_device_id array (a device table)
180 * in a generic manner.
181 */
182#define DEFINE_IPACK_DEVICE_TABLE(_table) \
183 const struct ipack_device_id _table[] __devinitconst
184
185/**
186 * IPACK_DEVICE - macro used to describe a specific IndustryPack device
187 * @_format: the format version (currently either 1 or 2, 8 bit value)
188 * @vend: the 8 or 24 bit IndustryPack Vendor ID
189 * @dev: the 8 or 16 bit IndustryPack Device ID
190 *
191 * This macro is used to create a struct ipack_device_id that matches a specific
192 * device.
193 */
194#define IPACK_DEVICE(_format, vend, dev) \
195 .format = (_format), \
196 .vendor = (vend), \
197 .device = (dev)