-
Notifications
You must be signed in to change notification settings - Fork 3
/
bolo8_sysfs.c
184 lines (161 loc) · 5.9 KB
/
bolo8_sysfs.c
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* ------------------------------------------------------------------------- *
* bolo8_sysfs.c D-TACQ ACQ400 FMC DRIVER
* Project: ACQ420_FMC
* Created: 7 Dec 2016 / User: pgm
* ------------------------------------------------------------------------- *
* Copyright (C) 2016 Peter Milne, D-TACQ Solutions Ltd *
* <peter dot milne at D hyphen TACQ dot com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of Version 2 of the GNU General Public License *
* as published by the Free Software Foundation; *
* *
* 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., 675 Mass Ave, Cambridge, MA 02139, USA. *
*
* TODO
* TODO
* ------------------------------------------------------------------------- */
#include "acq400.h"
#include "bolo.h"
#include "acq400_sysfs.h"
static ssize_t show_offset_dacN(
struct device * dev,
struct device_attribute *attr,
char * buf,
const int ix)
{
struct acq400_dev* adev = acq400_devices[dev->id];
u32 offset_dac = bolo8_get_offset_dacN(adev, ix);
return sprintf(buf, "0x%08x\n", offset_dac);
}
static ssize_t store_offset_dacN(
struct device * dev,
struct device_attribute *attr,
const char * buf,
size_t count,
const int ix)
{
struct acq400_dev* adev = acq400_devices[dev->id];
struct acq400_bolo_dev* b8_dev = container_of(adev, struct acq400_bolo_dev, adev);
int rc = count;
int offset;
if (sscanf(buf, "++%d", &offset) == 1){
offset = b8_dev->bolo8.offset_dacs[ix] + offset;
}else if (sscanf(buf, "--%d", &offset) == 1){
offset = b8_dev->bolo8.offset_dacs[ix] - offset;
}else if (sscanf(buf, "0x%x", &offset) == 1){
;
}else if (sscanf(buf, "%d", &offset) == 1){
;
}else{
return -1;
}
bolo8_set_offset_dacN(adev, ix, b8_dev->bolo8.offset_dacs[ix] = offset);
return rc;
}
#define MAKE_OFFSET_DAC(IX) \
static ssize_t show_offset_dac##IX( \
struct device * dev, \
struct device_attribute *attr, \
char * buf) \
{ \
return show_offset_dacN(dev, attr, buf, IX-1); \
} \
\
static ssize_t store_offset_dac##IX( \
struct device * dev, \
struct device_attribute *attr, \
const char * buf, \
size_t count) \
{ \
return store_offset_dacN(dev, attr, buf, count, IX-1); \
} \
static DEVICE_ATTR(offset_dac##IX, S_IRUGO|S_IWUSR, \
show_offset_dac##IX, store_offset_dac##IX)
MAKE_OFFSET_DAC(1);
MAKE_OFFSET_DAC(2);
MAKE_OFFSET_DAC(3);
MAKE_OFFSET_DAC(4);
MAKE_OFFSET_DAC(5);
MAKE_OFFSET_DAC(6);
MAKE_OFFSET_DAC(7);
MAKE_OFFSET_DAC(8);
static ssize_t show_adc_sample_count(
struct device * dev,
struct device_attribute *attr,
char * buf)
{
u32 count = acq400rd32_upcount(acq400_devices[dev->id], B8_ADC_SAMPLE_CNT);
return sprintf(buf, "%u\n", count&ADC_SAMPLE_CTR_MASK);
}
static DEVICE_ATTR(adc_sample_count, S_IRUGO, show_adc_sample_count, 0);
static ssize_t show_dac_sample_count(
struct device * dev,
struct device_attribute *attr,
char * buf)
{
u32 count = acq400rd32_upcount(acq400_devices[dev->id], B8_DAC_SAMPLE_CNT);
return sprintf(buf, "%u\n", count&ADC_SAMPLE_CTR_MASK);
}
static DEVICE_ATTR(dac_sample_count, S_IRUGO, show_dac_sample_count, 0);
MAKE_BITS(current_adc_enable, B8_CAD_CON, MAKE_BITS_FROM_MASK, B8_CAD_CON_ENABLE);
MAKE_BITS(offset_dac_enable, B8_ODA_CON, MAKE_BITS_FROM_MASK, B8_ODA_CON_ENABLE);
MAKE_BITS(bolo_dac_lowlat, B8_DAC_CON, MAKE_BITS_FROM_MASK, B8_DAC_CON_LL);
MAKE_BITS(bolo_dac_data32, B8_DAC_CON, MAKE_BITS_FROM_MASK, B8_DAC_CON_DS32);
DEPRECATED_MAKE_BITS(bolo_dac_reset, B8_DAC_CON, MAKE_BITS_FROM_MASK, B8_DAC_CON_RST);
DEPRECATED_MAKE_BITS(bolo_dac_enable, B8_DAC_CON, MAKE_BITS_FROM_MASK, B8_DAC_CON_ENA);
DEPRECATED_MAKE_BITS(bolo_dac_control, B8_DAC_CON, 0, 0x1ff);
#define BOLO_DSP_BITS (B8_DAC_CON_LL|B8_DAC_CON_DS32|B8_DAC_CON_ENA|DAC_CTRL_FIFO_EN|DAC_CTRL_MODULE_EN)
#define BOLO_AWG_BITS (B8_DAC_CON_ENA|DAC_CTRL_MODULE_EN)
static ssize_t show_bolo_dsp_enable(
struct device * dev,
struct device_attribute *attr,
char * buf)
{
u32 bolo_dsp_enable = acq400rd32(acq400_devices[dev->id], B8_DAC_CON);
return sprintf(buf, "%u\n", bolo_dsp_enable==BOLO_DSP_BITS);
}
static ssize_t store_bolo_dsp_enable(
struct device * dev,
struct device_attribute *attr,
const char * buf,
size_t count)
{
struct acq400_dev* adev = acq400_devices[dev->id];
u32 bolo_dsp_enable;
if (sscanf(buf, "%u", &bolo_dsp_enable) == 1){
acq400wr32(adev, B8_DAC_CON, bolo_dsp_enable? BOLO_DSP_BITS: BOLO_AWG_BITS);
return count;
}else{
return -1;
}
}
static DEVICE_ATTR(bolo_dsp_enable, S_IRUGO|S_IWUSR, show_bolo_dsp_enable, store_bolo_dsp_enable);
const struct attribute *bolo8_attrs[] = {
&dev_attr_current_adc_enable.attr,
&dev_attr_offset_dac_enable.attr,
&dev_attr_bolo_dac_lowlat.attr,
&dev_attr_bolo_dac_data32.attr,
&dev_attr_bolo_dac_reset.attr,
&dev_attr_bolo_dac_enable.attr,
&dev_attr_offset_dac1.attr,
&dev_attr_offset_dac2.attr,
&dev_attr_offset_dac3.attr,
&dev_attr_offset_dac4.attr,
&dev_attr_offset_dac5.attr,
&dev_attr_offset_dac6.attr,
&dev_attr_offset_dac7.attr,
&dev_attr_offset_dac8.attr,
&dev_attr_adc_sample_count.attr,
&dev_attr_dac_sample_count.attr,
&dev_attr_bolo_dac_control.attr,
&dev_attr_bolo_dsp_enable.attr,
NULL
};