This source file includes following definitions.
- tc921x_encode_freq
- tc921x_decode_freq
- tc921x_read_addr
- tc921x_write_addr
- __tc921x_write_burst
- __tc921x_read_burst
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 #include <sys/param.h>
51 #include <sys/radioio.h>
52
53 #include <dev/ic/tc921x.h>
54
55 #define PL_CL_DL(c) ((0 << c->period) | (0 << c->clock) | (0 << c->data))
56 #define PL_CL_DH(c) ((0 << c->period) | (0 << c->clock) | (1 << c->data))
57 #define PL_CH_DL(c) ((0 << c->period) | (1 << c->clock) | (0 << c->data))
58 #define PL_CH_DH(c) ((0 << c->period) | (1 << c->clock) | (1 << c->data))
59
60 #define PH_CL_DL(c) ((1 << c->period) | (0 << c->clock) | (0 << c->data))
61 #define PH_CL_DH(c) ((1 << c->period) | (0 << c->clock) | (1 << c->data))
62 #define PH_CH_DL(c) ((1 << c->period) | (1 << c->clock) | (0 << c->data))
63 #define PH_CH_DH(c) ((1 << c->period) | (1 << c->clock) | (1 << c->data))
64
65 #define PERIOD_LOW 0
66 #define PERIOD_HIGH 1
67
68 static void __tc921x_write_burst(unsigned int, u_int32_t, struct tc921x_t *, int);
69 static u_int32_t __tc921x_read_burst(unsigned int, struct tc921x_t *);
70
71 u_int32_t
72 tc921x_encode_freq(u_int32_t freq) {
73
74 if (freq < MIN_FM_FREQ)
75 freq = MIN_FM_FREQ;
76 if (freq > MAX_FM_FREQ)
77 freq = MAX_FM_FREQ;
78
79 return (freq + IF_FREQ)/10;
80 }
81
82 u_int32_t
83 tc921x_decode_freq(u_int32_t reg) {
84 return (reg & TC921X_D0_FREQ_DIVIDER) * 10 - IF_FREQ;
85 }
86
87 u_int32_t
88 tc921x_read_addr(struct tc921x_t *c, u_int8_t addr) {
89 u_int32_t ret;
90
91
92 bus_space_write_1(c->iot, c->ioh, c->offset, PH_CH_DH(c));
93
94 bus_space_write_1(c->iot, c->ioh, c->offset, PL_CH_DH(c));
95
96
97
98
99
100
101 __tc921x_write_burst(4, addr, c, PERIOD_LOW);
102 __tc921x_write_burst(4, addr >> 4, c, PERIOD_HIGH);
103
104
105 ret = __tc921x_read_burst(TC921X_REGISTER_LENGTH, c);
106
107
108 bus_space_write_1(c->iot, c->ioh, c->offset, PL_CH_DH(c));
109 bus_space_write_1(c->iot, c->ioh, c->offset, PH_CH_DH(c));
110
111 return ret;
112 }
113
114 void
115 tc921x_write_addr(struct tc921x_t *c, u_int8_t addr, u_int32_t reg) {
116
117 bus_space_write_1(c->iot, c->ioh, c->offset, PH_CH_DH(c));
118
119 bus_space_write_1(c->iot, c->ioh, c->offset, PL_CH_DH(c));
120
121
122
123
124
125
126 __tc921x_write_burst(4, addr, c, PERIOD_LOW);
127 __tc921x_write_burst(4, addr >> 4, c, PERIOD_HIGH);
128
129
130 __tc921x_write_burst(TC921X_REGISTER_LENGTH, reg, c, 1);
131
132
133 bus_space_write_1(c->iot, c->ioh, c->offset, PL_CH_DH(c));
134 bus_space_write_1(c->iot, c->ioh, c->offset, PH_CH_DH(c));
135 }
136
137 static void
138 __tc921x_write_burst(unsigned int length, u_int32_t data, struct tc921x_t *c, int p) {
139 int i;
140 u_int8_t cldh, chdh, cldl, chdl;
141
142 cldh = p == PERIOD_LOW ? PL_CL_DH(c) : PH_CL_DH(c);
143 chdh = p == PERIOD_LOW ? PL_CH_DH(c) : PH_CH_DH(c);
144 cldl = p == PERIOD_LOW ? PL_CL_DL(c) : PH_CL_DL(c);
145 chdl = p == PERIOD_LOW ? PL_CH_DL(c) : PH_CH_DL(c);
146
147 for (i = 0; i < length; i++)
148 if (data & (1 << i)) {
149 bus_space_write_1(c->iot, c->ioh, c->offset, cldh);
150 bus_space_write_1(c->iot, c->ioh, c->offset, chdh);
151 } else {
152 bus_space_write_1(c->iot, c->ioh, c->offset, cldl);
153 bus_space_write_1(c->iot, c->ioh, c->offset, chdl);
154 }
155 }
156
157 static u_int32_t
158 __tc921x_read_burst(unsigned int length, struct tc921x_t *c) {
159 unsigned int i;
160 u_int32_t ret = 0ul;
161
162 #define DATA_ON (1 << c->data)
163
164 for (i = 0; i < length; i++) {
165 bus_space_write_1(c->iot, c->ioh, c->offset, PH_CL_DH(c));
166 bus_space_write_1(c->iot, c->ioh, c->offset, PH_CH_DH(c));
167 ret |= bus_space_read_1(c->iot, c->ioh, c->offset) & DATA_ON ?
168 (1 << i) : (0 << i);
169 }
170
171 return ret;
172 }