zssp.c revision 1.1.4.2 1 1.1.4.2 yamt /* $OpenBSD: zaurus_ssp.c,v 1.6 2005/04/08 21:58:49 uwe Exp $ */
2 1.1.4.2 yamt
3 1.1.4.2 yamt /*
4 1.1.4.2 yamt * Copyright (c) 2005 Uwe Stuehler <uwe (at) bsdx.de>
5 1.1.4.2 yamt *
6 1.1.4.2 yamt * Permission to use, copy, modify, and distribute this software for any
7 1.1.4.2 yamt * purpose with or without fee is hereby granted, provided that the above
8 1.1.4.2 yamt * copyright notice and this permission notice appear in all copies.
9 1.1.4.2 yamt *
10 1.1.4.2 yamt * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 1.1.4.2 yamt * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 1.1.4.2 yamt * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 1.1.4.2 yamt * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 1.1.4.2 yamt * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 1.1.4.2 yamt * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 1.1.4.2 yamt * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 1.1.4.2 yamt */
18 1.1.4.2 yamt
19 1.1.4.2 yamt #include <sys/cdefs.h>
20 1.1.4.2 yamt __KERNEL_RCSID(0, "$NetBSD: zssp.c,v 1.1.4.2 2006/12/30 20:47:28 yamt Exp $");
21 1.1.4.2 yamt
22 1.1.4.2 yamt #include <sys/param.h>
23 1.1.4.2 yamt #include <sys/systm.h>
24 1.1.4.2 yamt #include <sys/device.h>
25 1.1.4.2 yamt
26 1.1.4.2 yamt #include <machine/bus.h>
27 1.1.4.2 yamt
28 1.1.4.2 yamt #include <arm/xscale/pxa2x0reg.h>
29 1.1.4.2 yamt #include <arm/xscale/pxa2x0var.h>
30 1.1.4.2 yamt #include <arm/xscale/pxa2x0_gpio.h>
31 1.1.4.2 yamt
32 1.1.4.2 yamt #include <zaurus/dev/zsspvar.h>
33 1.1.4.2 yamt #include <zaurus/zaurus/zaurus_var.h>
34 1.1.4.2 yamt
35 1.1.4.2 yamt #include "ioconf.h"
36 1.1.4.2 yamt
37 1.1.4.2 yamt #define GPIO_ADS7846_CS_C3000 14 /* SSP SFRM */
38 1.1.4.2 yamt #define GPIO_MAX1111_CS_C3000 20
39 1.1.4.2 yamt #define GPIO_TG_CS_C3000 53
40 1.1.4.2 yamt
41 1.1.4.2 yamt #define SSCR0_ADS7846_C3000 0x06ab
42 1.1.4.2 yamt #define SSCR0_LZ9JG18 0x01ab
43 1.1.4.2 yamt #define SSCR0_MAX1111 0x0387
44 1.1.4.2 yamt
45 1.1.4.2 yamt struct zssp_softc {
46 1.1.4.2 yamt struct device sc_dev;
47 1.1.4.2 yamt bus_space_tag_t sc_iot;
48 1.1.4.2 yamt bus_space_handle_t sc_ioh;
49 1.1.4.2 yamt };
50 1.1.4.2 yamt
51 1.1.4.2 yamt static int zssp_match(struct device *, struct cfdata *, void *);
52 1.1.4.2 yamt static void zssp_attach(struct device *, struct device *, void *);
53 1.1.4.2 yamt static void zssp_init(void);
54 1.1.4.2 yamt static void zssp_powerhook(int, void *);
55 1.1.4.2 yamt
56 1.1.4.2 yamt CFATTACH_DECL(zssp, sizeof(struct zssp_softc),
57 1.1.4.2 yamt zssp_match, zssp_attach, NULL, NULL);
58 1.1.4.2 yamt
59 1.1.4.2 yamt static int
60 1.1.4.2 yamt zssp_match(struct device *parent, struct cfdata *cf, void *aux)
61 1.1.4.2 yamt {
62 1.1.4.2 yamt
63 1.1.4.2 yamt return 1;
64 1.1.4.2 yamt }
65 1.1.4.2 yamt
66 1.1.4.2 yamt static void
67 1.1.4.2 yamt zssp_attach(struct device *parent, struct device *self, void *aux)
68 1.1.4.2 yamt {
69 1.1.4.2 yamt struct zssp_softc *sc = (struct zssp_softc *)self;
70 1.1.4.2 yamt
71 1.1.4.2 yamt sc->sc_iot = &pxa2x0_bs_tag;
72 1.1.4.2 yamt if (bus_space_map(sc->sc_iot, PXA2X0_SSP1_BASE, PXA2X0_SSP_SIZE,
73 1.1.4.2 yamt 0, &sc->sc_ioh)) {
74 1.1.4.2 yamt printf(": can't map bus space\n");
75 1.1.4.2 yamt return;
76 1.1.4.2 yamt }
77 1.1.4.2 yamt
78 1.1.4.2 yamt printf("\n");
79 1.1.4.2 yamt
80 1.1.4.2 yamt if (powerhook_establish(sc->sc_dev.dv_xname, zssp_powerhook, sc)
81 1.1.4.2 yamt == NULL) {
82 1.1.4.2 yamt printf("%s: can't establish power hook\n",
83 1.1.4.2 yamt sc->sc_dev.dv_xname);
84 1.1.4.2 yamt }
85 1.1.4.2 yamt
86 1.1.4.2 yamt zssp_init();
87 1.1.4.2 yamt }
88 1.1.4.2 yamt
89 1.1.4.2 yamt /*
90 1.1.4.2 yamt * Initialize the dedicated SSP unit and disable all chip selects.
91 1.1.4.2 yamt * This function is called with interrupts disabled.
92 1.1.4.2 yamt */
93 1.1.4.2 yamt static void
94 1.1.4.2 yamt zssp_init(void)
95 1.1.4.2 yamt {
96 1.1.4.2 yamt struct zssp_softc *sc;
97 1.1.4.2 yamt
98 1.1.4.2 yamt KASSERT(zssp_cd.cd_ndevs > 0 && zssp_cd.cd_devs[0] != NULL);
99 1.1.4.2 yamt sc = (struct zssp_softc *)zssp_cd.cd_devs[0];
100 1.1.4.2 yamt
101 1.1.4.2 yamt pxa2x0_clkman_config(CKEN_SSP, 1);
102 1.1.4.2 yamt
103 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, SSCR0_LZ9JG18);
104 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR1, 0);
105 1.1.4.2 yamt
106 1.1.4.2 yamt pxa2x0_gpio_set_function(GPIO_ADS7846_CS_C3000, GPIO_OUT|GPIO_SET);
107 1.1.4.2 yamt pxa2x0_gpio_set_function(GPIO_MAX1111_CS_C3000, GPIO_OUT|GPIO_SET);
108 1.1.4.2 yamt pxa2x0_gpio_set_function(GPIO_TG_CS_C3000, GPIO_OUT|GPIO_SET);
109 1.1.4.2 yamt }
110 1.1.4.2 yamt
111 1.1.4.2 yamt static void
112 1.1.4.2 yamt zssp_powerhook(int why, void *arg)
113 1.1.4.2 yamt {
114 1.1.4.2 yamt int s;
115 1.1.4.2 yamt
116 1.1.4.2 yamt if (why == PWR_RESUME) {
117 1.1.4.2 yamt s = splhigh();
118 1.1.4.2 yamt zssp_init();
119 1.1.4.2 yamt splx(s);
120 1.1.4.2 yamt }
121 1.1.4.2 yamt }
122 1.1.4.2 yamt
123 1.1.4.2 yamt /*
124 1.1.4.2 yamt * Transmit a single data word to one of the ICs, keep the chip selected
125 1.1.4.2 yamt * afterwards, and don't wait for data to be returned in SSDR. Interrupts
126 1.1.4.2 yamt * must be held off until zssp_ic_stop() gets called.
127 1.1.4.2 yamt */
128 1.1.4.2 yamt void
129 1.1.4.2 yamt zssp_ic_start(int ic, uint32_t data)
130 1.1.4.2 yamt {
131 1.1.4.2 yamt struct zssp_softc *sc;
132 1.1.4.2 yamt
133 1.1.4.2 yamt KASSERT(zssp_cd.cd_ndevs > 0 && zssp_cd.cd_devs[0] != NULL);
134 1.1.4.2 yamt sc = (struct zssp_softc *)zssp_cd.cd_devs[0];
135 1.1.4.2 yamt
136 1.1.4.2 yamt /* disable other ICs */
137 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, 0);
138 1.1.4.2 yamt if (ic != ZSSP_IC_ADS7846)
139 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
140 1.1.4.2 yamt if (ic != ZSSP_IC_LZ9JG18)
141 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
142 1.1.4.2 yamt if (ic != ZSSP_IC_MAX1111)
143 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);
144 1.1.4.2 yamt
145 1.1.4.2 yamt /* activate the chosen one */
146 1.1.4.2 yamt switch (ic) {
147 1.1.4.2 yamt case ZSSP_IC_ADS7846:
148 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0,
149 1.1.4.2 yamt SSCR0_ADS7846_C3000);
150 1.1.4.2 yamt pxa2x0_gpio_clear_bit(GPIO_ADS7846_CS_C3000);
151 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR, data);
152 1.1.4.2 yamt while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
153 1.1.4.2 yamt & SSSR_TNF) != SSSR_TNF)
154 1.1.4.2 yamt continue; /* poll */
155 1.1.4.2 yamt break;
156 1.1.4.2 yamt case ZSSP_IC_LZ9JG18:
157 1.1.4.2 yamt pxa2x0_gpio_clear_bit(GPIO_TG_CS_C3000);
158 1.1.4.2 yamt break;
159 1.1.4.2 yamt case ZSSP_IC_MAX1111:
160 1.1.4.2 yamt pxa2x0_gpio_clear_bit(GPIO_MAX1111_CS_C3000);
161 1.1.4.2 yamt break;
162 1.1.4.2 yamt }
163 1.1.4.2 yamt }
164 1.1.4.2 yamt
165 1.1.4.2 yamt /*
166 1.1.4.2 yamt * Read the last value from SSDR and deactivate all chip-selects.
167 1.1.4.2 yamt */
168 1.1.4.2 yamt uint32_t
169 1.1.4.2 yamt zssp_ic_stop(int ic)
170 1.1.4.2 yamt {
171 1.1.4.2 yamt struct zssp_softc *sc;
172 1.1.4.2 yamt uint32_t rv;
173 1.1.4.2 yamt
174 1.1.4.2 yamt KASSERT(zssp_cd.cd_ndevs > 0 && zssp_cd.cd_devs[0] != NULL);
175 1.1.4.2 yamt sc = (struct zssp_softc *)zssp_cd.cd_devs[0];
176 1.1.4.2 yamt
177 1.1.4.2 yamt switch (ic) {
178 1.1.4.2 yamt case ZSSP_IC_ADS7846:
179 1.1.4.2 yamt /* read result of last command */
180 1.1.4.2 yamt while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
181 1.1.4.2 yamt & SSSR_RNE) != SSSR_RNE)
182 1.1.4.2 yamt continue; /* poll */
183 1.1.4.2 yamt rv = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR);
184 1.1.4.2 yamt break;
185 1.1.4.2 yamt case ZSSP_IC_LZ9JG18:
186 1.1.4.2 yamt case ZSSP_IC_MAX1111:
187 1.1.4.2 yamt /* last value received is irrelevant or undefined */
188 1.1.4.2 yamt default:
189 1.1.4.2 yamt rv = 0;
190 1.1.4.2 yamt break;
191 1.1.4.2 yamt }
192 1.1.4.2 yamt
193 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
194 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
195 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);
196 1.1.4.2 yamt
197 1.1.4.2 yamt return rv;
198 1.1.4.2 yamt }
199 1.1.4.2 yamt
200 1.1.4.2 yamt /*
201 1.1.4.2 yamt * Activate one of the chip-select lines, transmit one word value in
202 1.1.4.2 yamt * each direction, and deactivate the chip-select again.
203 1.1.4.2 yamt */
204 1.1.4.2 yamt uint32_t
205 1.1.4.2 yamt zssp_ic_send(int ic, uint32_t data)
206 1.1.4.2 yamt {
207 1.1.4.2 yamt
208 1.1.4.2 yamt switch (ic) {
209 1.1.4.2 yamt case ZSSP_IC_MAX1111:
210 1.1.4.2 yamt return (zssp_read_max1111(data));
211 1.1.4.2 yamt case ZSSP_IC_ADS7846:
212 1.1.4.2 yamt return (zssp_read_ads7846(data));
213 1.1.4.2 yamt case ZSSP_IC_LZ9JG18:
214 1.1.4.2 yamt zssp_write_lz9jg18(data);
215 1.1.4.2 yamt return 0;
216 1.1.4.2 yamt default:
217 1.1.4.2 yamt printf("zssp_ic_send: invalid IC %d\n", ic);
218 1.1.4.2 yamt return 0;
219 1.1.4.2 yamt }
220 1.1.4.2 yamt }
221 1.1.4.2 yamt
222 1.1.4.2 yamt int
223 1.1.4.2 yamt zssp_read_max1111(uint32_t cmd)
224 1.1.4.2 yamt {
225 1.1.4.2 yamt struct zssp_softc *sc;
226 1.1.4.2 yamt int voltage[2];
227 1.1.4.2 yamt int i;
228 1.1.4.2 yamt int s;
229 1.1.4.2 yamt
230 1.1.4.2 yamt KASSERT(zssp_cd.cd_ndevs > 0 && zssp_cd.cd_devs[0] != NULL);
231 1.1.4.2 yamt sc = (struct zssp_softc *)zssp_cd.cd_devs[0];
232 1.1.4.2 yamt
233 1.1.4.2 yamt s = splhigh();
234 1.1.4.2 yamt
235 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, 0);
236 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, SSCR0_MAX1111);
237 1.1.4.2 yamt
238 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
239 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
240 1.1.4.2 yamt pxa2x0_gpio_clear_bit(GPIO_MAX1111_CS_C3000);
241 1.1.4.2 yamt
242 1.1.4.2 yamt delay(1);
243 1.1.4.2 yamt
244 1.1.4.2 yamt /* Send the command word and read a dummy word back. */
245 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR, cmd);
246 1.1.4.2 yamt while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
247 1.1.4.2 yamt & SSSR_TNF) != SSSR_TNF)
248 1.1.4.2 yamt continue; /* poll */
249 1.1.4.2 yamt /* XXX is this delay necessary? */
250 1.1.4.2 yamt delay(1);
251 1.1.4.2 yamt while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
252 1.1.4.2 yamt & SSSR_RNE) != SSSR_RNE)
253 1.1.4.2 yamt continue; /* poll */
254 1.1.4.2 yamt (void) bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR);
255 1.1.4.2 yamt
256 1.1.4.2 yamt for (i = 0; i < 2; i++) {
257 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR, 0);
258 1.1.4.2 yamt while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
259 1.1.4.2 yamt & SSSR_TNF) != SSSR_TNF)
260 1.1.4.2 yamt continue; /* poll */
261 1.1.4.2 yamt /* XXX again, is this delay necessary? */
262 1.1.4.2 yamt delay(1);
263 1.1.4.2 yamt while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
264 1.1.4.2 yamt & SSSR_RNE) != SSSR_RNE)
265 1.1.4.2 yamt continue; /* poll */
266 1.1.4.2 yamt voltage[i] = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
267 1.1.4.2 yamt SSP_SSDR);
268 1.1.4.2 yamt }
269 1.1.4.2 yamt
270 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
271 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
272 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);
273 1.1.4.2 yamt
274 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, 0);
275 1.1.4.2 yamt
276 1.1.4.2 yamt splx(s);
277 1.1.4.2 yamt
278 1.1.4.2 yamt /* XXX no idea what this means, but it's what Linux would do. */
279 1.1.4.2 yamt if ((voltage[0] & 0xc0) != 0 || (voltage[1] & 0x3f) != 0) {
280 1.1.4.2 yamt voltage[0] = -1;
281 1.1.4.2 yamt } else {
282 1.1.4.2 yamt voltage[0] = ((voltage[0] << 2) & 0xfc) |
283 1.1.4.2 yamt ((voltage[1] >> 6) & 0x03);
284 1.1.4.2 yamt }
285 1.1.4.2 yamt
286 1.1.4.2 yamt return voltage[0];
287 1.1.4.2 yamt }
288 1.1.4.2 yamt
289 1.1.4.2 yamt /* XXX - only does CS_ADS7846 */
290 1.1.4.2 yamt uint32_t
291 1.1.4.2 yamt zssp_read_ads7846(uint32_t cmd)
292 1.1.4.2 yamt {
293 1.1.4.2 yamt struct zssp_softc *sc;
294 1.1.4.2 yamt
295 1.1.4.2 yamt sc = (struct zssp_softc *)zssp_cd.cd_devs[0];
296 1.1.4.2 yamt unsigned int cr0;
297 1.1.4.2 yamt int s;
298 1.1.4.2 yamt uint32_t val;
299 1.1.4.2 yamt
300 1.1.4.2 yamt if (zssp_cd.cd_ndevs < 1 || zssp_cd.cd_devs[0] == NULL) {
301 1.1.4.2 yamt printf("zssp_read_ads7846: not configured\n");
302 1.1.4.2 yamt return 0;
303 1.1.4.2 yamt }
304 1.1.4.2 yamt
305 1.1.4.2 yamt sc = (struct zssp_softc *)zssp_cd.cd_devs[0];
306 1.1.4.2 yamt
307 1.1.4.2 yamt s = splhigh();
308 1.1.4.2 yamt if (1) {
309 1.1.4.2 yamt cr0 = SSCR0_ADS7846_C3000;
310 1.1.4.2 yamt } else {
311 1.1.4.2 yamt cr0 = 0x00ab;
312 1.1.4.2 yamt }
313 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, 0);
314 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSCR0, cr0);
315 1.1.4.2 yamt
316 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
317 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);
318 1.1.4.2 yamt pxa2x0_gpio_clear_bit(GPIO_ADS7846_CS_C3000);
319 1.1.4.2 yamt
320 1.1.4.2 yamt bus_space_write_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR, cmd);
321 1.1.4.2 yamt
322 1.1.4.2 yamt while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
323 1.1.4.2 yamt & SSSR_TNF) != SSSR_TNF)
324 1.1.4.2 yamt continue; /* poll */
325 1.1.4.2 yamt
326 1.1.4.2 yamt delay(1);
327 1.1.4.2 yamt
328 1.1.4.2 yamt while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSSR)
329 1.1.4.2 yamt & SSSR_RNE) != SSSR_RNE)
330 1.1.4.2 yamt continue; /* poll */
331 1.1.4.2 yamt
332 1.1.4.2 yamt val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SSP_SSDR);
333 1.1.4.2 yamt
334 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000); /* deselect */
335 1.1.4.2 yamt
336 1.1.4.2 yamt splx(s);
337 1.1.4.2 yamt
338 1.1.4.2 yamt return val;
339 1.1.4.2 yamt }
340 1.1.4.2 yamt
341 1.1.4.2 yamt void
342 1.1.4.2 yamt zssp_write_lz9jg18(uint32_t data)
343 1.1.4.2 yamt {
344 1.1.4.2 yamt int s;
345 1.1.4.2 yamt int sclk_pin, sclk_fn;
346 1.1.4.2 yamt int sfrm_pin, sfrm_fn;
347 1.1.4.2 yamt int txd_pin, txd_fn;
348 1.1.4.2 yamt int rxd_pin, rxd_fn;
349 1.1.4.2 yamt int i;
350 1.1.4.2 yamt
351 1.1.4.2 yamt /* XXX this creates a DAC command from a backlight duty value. */
352 1.1.4.2 yamt data = 0x40 | (data & 0x1f);
353 1.1.4.2 yamt
354 1.1.4.2 yamt if (ZAURUS_ISC3000) {
355 1.1.4.2 yamt /* C3000 */
356 1.1.4.2 yamt sclk_pin = 19;
357 1.1.4.2 yamt sfrm_pin = 14;
358 1.1.4.2 yamt txd_pin = 87;
359 1.1.4.2 yamt rxd_pin = 86;
360 1.1.4.2 yamt } else {
361 1.1.4.2 yamt sclk_pin = 23;
362 1.1.4.2 yamt sfrm_pin = 24;
363 1.1.4.2 yamt txd_pin = 25;
364 1.1.4.2 yamt rxd_pin = 26;
365 1.1.4.2 yamt }
366 1.1.4.2 yamt
367 1.1.4.2 yamt s = splhigh();
368 1.1.4.2 yamt
369 1.1.4.2 yamt sclk_fn = pxa2x0_gpio_get_function(sclk_pin);
370 1.1.4.2 yamt sfrm_fn = pxa2x0_gpio_get_function(sfrm_pin);
371 1.1.4.2 yamt txd_fn = pxa2x0_gpio_get_function(txd_pin);
372 1.1.4.2 yamt rxd_fn = pxa2x0_gpio_get_function(rxd_pin);
373 1.1.4.2 yamt
374 1.1.4.2 yamt pxa2x0_gpio_set_function(sfrm_pin, GPIO_OUT | GPIO_SET);
375 1.1.4.2 yamt pxa2x0_gpio_set_function(sclk_pin, GPIO_OUT | GPIO_CLR);
376 1.1.4.2 yamt pxa2x0_gpio_set_function(txd_pin, GPIO_OUT | GPIO_CLR);
377 1.1.4.2 yamt pxa2x0_gpio_set_function(rxd_pin, GPIO_IN);
378 1.1.4.2 yamt
379 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_MAX1111_CS_C3000);
380 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_ADS7846_CS_C3000);
381 1.1.4.2 yamt pxa2x0_gpio_clear_bit(GPIO_TG_CS_C3000);
382 1.1.4.2 yamt
383 1.1.4.2 yamt delay(10);
384 1.1.4.2 yamt
385 1.1.4.2 yamt for (i = 0; i < 8; i++) {
386 1.1.4.2 yamt if (data & 0x80)
387 1.1.4.2 yamt pxa2x0_gpio_set_bit(txd_pin);
388 1.1.4.2 yamt else
389 1.1.4.2 yamt pxa2x0_gpio_clear_bit(txd_pin);
390 1.1.4.2 yamt delay(10);
391 1.1.4.2 yamt pxa2x0_gpio_set_bit(sclk_pin);
392 1.1.4.2 yamt delay(10);
393 1.1.4.2 yamt pxa2x0_gpio_clear_bit(sclk_pin);
394 1.1.4.2 yamt delay(10);
395 1.1.4.2 yamt data <<= 1;
396 1.1.4.2 yamt }
397 1.1.4.2 yamt
398 1.1.4.2 yamt pxa2x0_gpio_clear_bit(txd_pin);
399 1.1.4.2 yamt pxa2x0_gpio_set_bit(GPIO_TG_CS_C3000);
400 1.1.4.2 yamt
401 1.1.4.2 yamt pxa2x0_gpio_set_function(sclk_pin, sclk_fn);
402 1.1.4.2 yamt pxa2x0_gpio_set_function(sfrm_pin, sfrm_fn);
403 1.1.4.2 yamt pxa2x0_gpio_set_function(txd_pin, txd_fn);
404 1.1.4.2 yamt pxa2x0_gpio_set_function(rxd_pin, rxd_fn);
405 1.1.4.2 yamt
406 1.1.4.2 yamt splx(s);
407 1.1.4.2 yamt }
408