forked from Beckhoff/CCAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.h
159 lines (140 loc) · 3.75 KB
/
module.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
Network Driver for Beckhoff CCAT communication controller
Copyright (C) 2014 Beckhoff Automation GmbH
Author: Patrick Bruenn <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// vi: noexpandtab:
#ifndef _CCAT_H_
#define _CCAT_H_
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/hrtimer.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/mfd/core.h>
#define DRV_EXTRAVERSION ""
#define DRV_VERSION "0.16" DRV_EXTRAVERSION
#define DRV_DESCRIPTION "Beckhoff CCAT Ethernet/EtherCAT Network Driver"
#undef pr_fmt
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
/**
* CCAT function type identifiers (u16)
*/
enum ccat_info_t {
CCATINFO_NOTUSED = 0,
CCATINFO_INFO = 0x1,
CCATINFO_ETHERCAT_SLAVE = 0x2,
CCATINFO_ETHERCAT_NODMA = 0x3,
CCATINFO_GPIO = 0xd,
CCATINFO_EPCS_PROM = 0xf,
CCATINFO_SYSTEMTIME = 0x10,
CCATINFO_IRQ = 0x11,
CCATINFO_EEPROM = 0x12,
CCATINFO_ETHERCAT_MASTER_DMA = 0x14,
CCATINFO_SRAM = 0x16,
};
/**
* struct ccat_cell
* @type: ccat function type
* @cell: mfd cell for function
*/
struct ccat_cell {
enum ccat_info_t type;
struct mfd_cell cell;
};
struct ccat_cdev {
atomic_t in_use;
void __iomem *ioaddr;
size_t iosize;
dev_t dev;
struct cdev cdev;
struct ccat_class *class;
struct ccat_function *func;
void *user;
};
/**
* struct cdev_buffer
* @ccdev: referenced character device
* @data: buffer used for write operations
* @size: number of bytes written to the data buffer
*/
struct cdev_buffer {
struct ccat_cdev *ccdev;
size_t size;
char data[];
};
extern int ccat_cdev_open(struct inode *const i, struct file *const f);
extern int ccat_cdev_release(struct inode *const i, struct file *const f);
extern loff_t ccat_cdev_llseek(struct file *f, loff_t offset, int whence);
/**
* struct ccat_device - CCAT device representation
* @pdev: pointer to the pci object allocated by the kernel
* @dev: pointer to the device object allocated by the kernel
* @bar_0: holding information about PCI BAR 0
* @bar_2: holding information about PCI BAR 2 (optional)
*
* One instance of a ccat_device should represent a physical CCAT. Since
* a CCAT is implemented as FPGA the available functions can vary.
*/
struct ccat_device {
void *pdev;
void *dev;
void __iomem *bar_0;
void __iomem *bar_2;
};
struct ccat_info_block {
u16 type;
u16 rev;
union {
u32 config;
u8 num_gpios;
struct {
u16 tx_size;
u16 rx_size;
};
struct {
u8 tx_dma_chan;
u8 rx_dma_chan;
};
struct {
u8 sram_width;
u8 sram_size;
u16 reserved;
};
struct {
u16 revision;
u16 parameter;
};
};
u32 addr;
u32 size;
};
struct ccat_function {
struct ccat_device *ccat;
struct ccat_info_block info;
void *private_data;
};
struct ccat_class {
dev_t dev;
struct class *class;
atomic_t instances;
const unsigned count;
struct ccat_cdev *devices;
const char *name;
struct file_operations fops;
};
extern int ccat_cdev_remove(struct platform_device *pdev);
extern int ccat_cdev_probe(struct ccat_function *func,
struct ccat_class *cdev_class, size_t iosize, void *user);
#endif /* #ifndef _CCAT_H_ */