blob: d50af713956975b1032822c5cecfed9f05a4789a [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
12#include <linux/device.h>
13
14#define IPACK_BOARD_NAME_SIZE 16
15#define IPACK_IRQ_NAME_SIZE 50
16#define IPACK_IDPROM_OFFSET_I 0x01
17#define IPACK_IDPROM_OFFSET_P 0x03
18#define IPACK_IDPROM_OFFSET_A 0x05
19#define IPACK_IDPROM_OFFSET_C 0x07
20#define IPACK_IDPROM_OFFSET_MANUFACTURER_ID 0x09
21#define IPACK_IDPROM_OFFSET_MODEL 0x0B
22#define IPACK_IDPROM_OFFSET_REVISION 0x0D
23#define IPACK_IDPROM_OFFSET_RESERVED 0x0F
24#define IPACK_IDPROM_OFFSET_DRIVER_ID_L 0x11
25#define IPACK_IDPROM_OFFSET_DRIVER_ID_H 0x13
26#define IPACK_IDPROM_OFFSET_NUM_BYTES 0x15
27#define IPACK_IDPROM_OFFSET_CRC 0x17
28
29struct ipack_bus_ops;
30struct ipack_driver;
31
32enum ipack_space {
33 IPACK_IO_SPACE = 0,
34 IPACK_ID_SPACE = 1,
35 IPACK_MEM_SPACE = 2,
36};
37
38/**
39 * struct ipack_addr_space - Virtual address space mapped for a specified type.
40 *
41 * @address: virtual address
42 * @size: size of the mapped space
43 */
44struct ipack_addr_space {
Samuel Iglesias Gonsalvez5a81b4a2012-05-14 12:41:25 +020045 void __iomem *address;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020046 unsigned int size;
47};
48
49/**
50 * struct ipack_device
51 *
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020052 * @bus_nr: IP bus number where the device is plugged
53 * @slot: Slot where the device is plugged in the carrier board
54 * @irq: IRQ vector
55 * @driver: Pointer to the ipack_driver that manages the device
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 {
67 char board_name[IPACK_BOARD_NAME_SIZE];
68 char bus_name[IPACK_BOARD_NAME_SIZE];
69 unsigned int bus_nr;
70 unsigned int slot;
71 unsigned int irq;
72 struct ipack_driver *driver;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020073 struct ipack_bus_device *bus;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020074 struct ipack_addr_space id_space;
75 struct ipack_addr_space io_space;
76 struct ipack_addr_space mem_space;
77 struct device dev;
78};
79
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020080/**
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020081 * struct ipack_driver_ops -- callbacks to mezzanine driver for installing/removing one device
82 *
83 * @match: Match function
84 * @probe: Probe function
85 * @remove: tell the driver that the carrier board wants to remove one device
86 */
87
88struct ipack_driver_ops {
89 int (*match) (struct ipack_device *dev);
90 int (*probe) (struct ipack_device *dev);
91 void (*remove) (struct ipack_device *dev);
92};
93
94/**
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +020095 * struct ipack_driver -- Specific data to each ipack board driver
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +020096 *
97 * @driver: Device driver kernel representation
98 * @ops: Mezzanine driver operations specific for the ipack bus.
99 */
100struct ipack_driver {
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200101 struct device_driver driver;
102 struct ipack_driver_ops *ops;
103};
104
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200105/**
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
112 * @read8: read unsigned char
113 * @read16: read unsigned short
114 * @read32: read unsigned int
115 * @write8: read unsigned char
116 * @write16: read unsigned short
117 * @write32: read unsigned int
118 * @remove_device: tell the bridge module that the device has been removed
119 */
120struct ipack_bus_ops {
121 int (*map_space) (struct ipack_device *dev, unsigned int memory_size, int space);
122 int (*unmap_space) (struct ipack_device *dev, int space);
123 int (*request_irq) (struct ipack_device *dev, int vector, int (*handler)(void *), void *arg);
124 int (*free_irq) (struct ipack_device *dev);
125 int (*read8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char *value);
126 int (*read16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short *value);
127 int (*read32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int *value);
128 int (*write8) (struct ipack_device *dev, int space, unsigned long offset, unsigned char value);
129 int (*write16) (struct ipack_device *dev, int space, unsigned long offset, unsigned short value);
130 int (*write32) (struct ipack_device *dev, int space, unsigned long offset, unsigned int value);
131 int (*remove_device) (struct ipack_device *dev);
132};
133
134/**
135 * struct ipack_bus_device
136 *
137 * @dev: pointer to carrier device
138 * @slots: number of slots available
139 * @bus_nr: ipack bus number
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200140 * @ops: bus operations for the mezzanine drivers
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200141 */
142struct ipack_bus_device {
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200143 struct device *parent;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200144 int slots;
145 int bus_nr;
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200146 struct ipack_bus_ops *ops;
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200147};
148
149/**
150 * ipack_bus_register -- register a new ipack bus
151 *
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200152 * @parent: pointer to the parent device, if any.
153 * @slots: number of slots available in the bus device.
154 * @ops: bus operations for the mezzanine drivers.
155 *
156 * The carrier board device should call this function to register itself as
157 * available bus device in ipack.
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200158 */
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200159struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
160 struct ipack_bus_ops *ops);
Samuel Iglesias Gonsalvezd3465872012-05-09 15:27:19 +0200161
162/**
163 * ipack_bus_unregister -- unregister an ipack bus
164 */
165int ipack_bus_unregister(struct ipack_bus_device *bus);
Samuel Iglesias Gonsalvezec440332012-05-18 11:10:05 +0200166
167/**
168 * ipack_driver_register -- Register a new driver
169 *
170 * Called by a ipack driver to register itself as a driver
171 * that can manage ipack devices.
172 */
173int ipack_driver_register(struct ipack_driver *edrv, struct module *owner, char *name);
174void ipack_driver_unregister(struct ipack_driver *edrv);
175
176/**
177 * ipack_device_register -- register a new mezzanine device
178 *
179 * @bus: ipack bus device it is plugged to.
180 * @slot: slot position in the bus device.
181 * @irqv: IRQ vector for the mezzanine.
182 *
183 * Register a new ipack device (mezzanine device). The call is done by
184 * the carrier device driver.
185 */
186struct ipack_device *ipack_device_register(struct ipack_bus_device *bus, int slot, int irqv);
187void ipack_device_unregister(struct ipack_device *dev);