1
2
3
4
5
6
7
8
9
10#ifndef __LINUX_FMC_H__
11#define __LINUX_FMC_H__
12#include <linux/types.h>
13#include <linux/moduleparam.h>
14#include <linux/device.h>
15#include <linux/list.h>
16#include <linux/interrupt.h>
17#include <linux/io.h>
18
19struct fmc_device;
20struct fmc_driver;
21
22
23
24
25
26
27#define FMC_MAJOR 3
28#define FMC_MINOR 0
29#define FMC_VERSION ((FMC_MAJOR << 16) | FMC_MINOR)
30#define __FMC_MAJOR(x) ((x) >> 16)
31#define __FMC_MINOR(x) ((x) & 0xffff)
32
33
34
35
36
37
38
39
40
41
42
43struct fmc_fru_id {
44 char *manufacturer;
45 char *product_name;
46};
47
48
49
50
51
52
53
54
55struct fmc_sdb_one_id {
56 uint64_t vendor;
57 uint32_t device;
58};
59struct fmc_sdb_id {
60 struct fmc_sdb_one_id *cores;
61 int cores_nr;
62};
63
64struct fmc_device_id {
65 struct fmc_fru_id *fru_id;
66 int fru_id_nr;
67 struct fmc_sdb_id *sdb_id;
68 int sdb_id_nr;
69};
70
71
72#define FMC_MAX_CARDS 32
73
74
75struct fmc_driver {
76 unsigned long version;
77 struct device_driver driver;
78 int (*probe)(struct fmc_device *);
79 int (*remove)(struct fmc_device *);
80 const struct fmc_device_id id_table;
81
82 int busid_n;
83 int busid_val[FMC_MAX_CARDS];
84 int gw_n;
85 char *gw_val[FMC_MAX_CARDS];
86};
87#define to_fmc_driver(x) container_of((x), struct fmc_driver, driver)
88
89
90#define FMC_PARAM_BUSID(_d) \
91 module_param_array_named(busid, _d.busid_val, int, &_d.busid_n, 0444)
92#define FMC_PARAM_GATEWARE(_d) \
93 module_param_array_named(gateware, _d.gw_val, charp, &_d.gw_n, 0444)
94
95
96
97
98
99
100struct fmc_gpio {
101 char *carrier_name;
102 int gpio;
103 int _gpio;
104 int mode;
105 int irqmode;
106};
107
108
109#define FMC_GPIO_RAW(x) (x)
110#define __FMC_GPIO_IS_RAW(x) ((x) < 0x1000)
111#define FMC_GPIO_IRQ(x) ((x) + 0x1000)
112#define FMC_GPIO_LED(x) ((x) + 0x1100)
113#define FMC_GPIO_KEY(x) ((x) + 0x1200)
114#define FMC_GPIO_TP(x) ((x) + 0x1300)
115#define FMC_GPIO_USER(x) ((x) + 0x1400)
116
117
118
119#ifndef GPIOF_DIR_IN
120# define GPIOF_DIR_OUT (0 << 0)
121# define GPIOF_DIR_IN (1 << 0)
122# define GPIOF_INIT_LOW (0 << 1)
123# define GPIOF_INIT_HIGH (1 << 1)
124#endif
125
126
127
128
129
130
131struct fmc_operations {
132 uint32_t (*read32)(struct fmc_device *fmc, int offset);
133 void (*write32)(struct fmc_device *fmc, uint32_t value, int offset);
134 int (*validate)(struct fmc_device *fmc, struct fmc_driver *drv);
135 int (*reprogram)(struct fmc_device *f, struct fmc_driver *d, char *gw);
136 int (*irq_request)(struct fmc_device *fmc, irq_handler_t h,
137 char *name, int flags);
138 void (*irq_ack)(struct fmc_device *fmc);
139 int (*irq_free)(struct fmc_device *fmc);
140 int (*gpio_config)(struct fmc_device *fmc, struct fmc_gpio *gpio,
141 int ngpio);
142 int (*read_ee)(struct fmc_device *fmc, int pos, void *d, int l);
143 int (*write_ee)(struct fmc_device *fmc, int pos, const void *d, int l);
144};
145
146
147extern int fmc_reprogram(struct fmc_device *f, struct fmc_driver *d, char *gw,
148 int sdb_entry);
149
150
151
152
153
154
155
156
157
158struct fmc_device {
159 unsigned long version;
160 unsigned long flags;
161 struct module *owner;
162 struct fmc_fru_id id;
163 struct fmc_operations *op;
164 int irq;
165 int eeprom_len;
166 int eeprom_addr;
167 uint8_t *eeprom;
168 char *carrier_name;
169 void *carrier_data;
170 __iomem void *fpga_base;
171 __iomem void *slot_base;
172 struct fmc_device **devarray;
173 int slot_id;
174 int nr_slots;
175 unsigned long memlen;
176 struct device dev;
177 struct device *hwdev;
178 unsigned long sdbfs_entry;
179 struct sdb_array *sdb;
180 uint32_t device_id;
181 char *mezzanine_name;
182 void *mezzanine_data;
183};
184#define to_fmc_device(x) container_of((x), struct fmc_device, dev)
185
186#define FMC_DEVICE_HAS_GOLDEN 1
187#define FMC_DEVICE_HAS_CUSTOM 2
188#define FMC_DEVICE_NO_MEZZANINE 4
189#define FMC_DEVICE_MATCH_SDB 8
190
191
192
193
194
195static inline uint32_t fmc_readl(struct fmc_device *fmc, int offset)
196{
197 if (unlikely(fmc->op->read32))
198 return fmc->op->read32(fmc, offset);
199 return readl(fmc->fpga_base + offset);
200}
201static inline void fmc_writel(struct fmc_device *fmc, uint32_t val, int off)
202{
203 if (unlikely(fmc->op->write32))
204 fmc->op->write32(fmc, val, off);
205 else
206 writel(val, fmc->fpga_base + off);
207}
208
209
210static inline void *fmc_get_drvdata(const struct fmc_device *fmc)
211{
212 return dev_get_drvdata(&fmc->dev);
213}
214
215static inline void fmc_set_drvdata(struct fmc_device *fmc, void *data)
216{
217 dev_set_drvdata(&fmc->dev, data);
218}
219
220
221extern int fmc_driver_register(struct fmc_driver *drv);
222extern void fmc_driver_unregister(struct fmc_driver *drv);
223extern int fmc_device_register(struct fmc_device *tdev);
224extern void fmc_device_unregister(struct fmc_device *tdev);
225
226
227extern int fmc_device_register_n(struct fmc_device **devs, int n);
228extern void fmc_device_unregister_n(struct fmc_device **devs, int n);
229
230
231extern int fmc_match(struct device *dev, struct device_driver *drv);
232extern int fmc_fill_id_info(struct fmc_device *fmc);
233extern void fmc_free_id_info(struct fmc_device *fmc);
234extern void fmc_dump_eeprom(const struct fmc_device *fmc);
235extern void fmc_dump_sdb(const struct fmc_device *fmc);
236
237#endif
238