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