Home | History | Annotate | Line # | Download | only in dev
uda1341.c revision 1.15.68.1
      1  1.15.68.1  thorpej /*	$NetBSD: uda1341.c,v 1.15.68.1 2021/03/20 19:33:35 thorpej Exp $	*/
      2        1.1   ichiro 
      3        1.1   ichiro /*-
      4        1.1   ichiro  * Copyright (c) 2001 The NetBSD Foundation, Inc.  All rights reserved.
      5        1.1   ichiro  *
      6        1.1   ichiro  * This code is derived from software contributed to The NetBSD Foundation
      7        1.1   ichiro  * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
      8        1.1   ichiro  *
      9        1.1   ichiro  * Redistribution and use in source and binary forms, with or without
     10        1.1   ichiro  * modification, are permitted provided that the following conditions
     11        1.1   ichiro  * are met:
     12        1.1   ichiro  * 1. Redistributions of source code must retain the above copyright
     13        1.1   ichiro  *    notice, this list of conditions and the following disclaimer.
     14        1.1   ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     15        1.1   ichiro  *    notice, this list of conditions and the following disclaimer in the
     16        1.1   ichiro  *    documentation and/or other materials provided with the distribution.
     17        1.1   ichiro  *
     18        1.1   ichiro  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19        1.1   ichiro  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20        1.1   ichiro  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21        1.1   ichiro  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22        1.1   ichiro  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23        1.1   ichiro  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24        1.1   ichiro  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25        1.1   ichiro  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26        1.1   ichiro  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27        1.1   ichiro  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28        1.1   ichiro  * POSSIBILITY OF SUCH DAMAGE.
     29        1.1   ichiro  */
     30        1.5    lukem 
     31        1.5    lukem #include <sys/cdefs.h>
     32  1.15.68.1  thorpej __KERNEL_RCSID(0, "$NetBSD: uda1341.c,v 1.15.68.1 2021/03/20 19:33:35 thorpej Exp $");
     33        1.1   ichiro 
     34        1.1   ichiro #include <sys/param.h>
     35        1.1   ichiro #include <sys/systm.h>
     36        1.1   ichiro #include <sys/types.h>
     37        1.1   ichiro #include <sys/conf.h>
     38        1.1   ichiro #include <sys/file.h>
     39        1.1   ichiro #include <sys/device.h>
     40        1.1   ichiro #include <sys/kernel.h>
     41        1.1   ichiro #include <sys/kthread.h>
     42        1.1   ichiro #include <sys/malloc.h>
     43       1.15   dyoung #include <sys/bus.h>
     44        1.1   ichiro 
     45        1.1   ichiro #include <hpcarm/dev/ipaq_saipvar.h>
     46        1.1   ichiro #include <hpcarm/dev/ipaq_gpioreg.h>
     47        1.1   ichiro #include <hpcarm/dev/uda1341.h>
     48       1.10    peter 
     49       1.10    peter #include <arm/sa11x0/sa11x0_gpioreg.h>
     50       1.10    peter #include <arm/sa11x0/sa11x0_sspreg.h>
     51        1.1   ichiro 
     52        1.1   ichiro struct uda1341_softc {
     53       1.14      rjs 	device_t		sc_dev;
     54        1.1   ichiro 	bus_space_tag_t		sc_iot;
     55        1.1   ichiro 	bus_space_handle_t	sc_ioh;
     56        1.1   ichiro 	struct ipaq_softc	*sc_parent;
     57        1.1   ichiro };
     58        1.1   ichiro 
     59       1.14      rjs static	int	uda1341_match(device_t, cfdata_t, void *);
     60       1.14      rjs static	void	uda1341_attach(device_t, device_t, void *);
     61        1.1   ichiro static	int	uda1341_print(void *, const char *);
     62       1.14      rjs static	int	uda1341_search(device_t, cfdata_t, const int *, void *);
     63        1.1   ichiro 
     64        1.1   ichiro static	void	uda1341_output_high(struct uda1341_softc *);
     65        1.1   ichiro static	void	uda1341_output_low(struct uda1341_softc *);
     66        1.1   ichiro static	void	uda1341_L3_init(struct uda1341_softc *);
     67        1.1   ichiro static	void	uda1341_init(struct uda1341_softc *);
     68        1.1   ichiro static	void	uda1341_reset(struct uda1341_softc *);
     69        1.1   ichiro static	void	uda1341_reginit(struct uda1341_softc *);
     70        1.1   ichiro 
     71       1.14      rjs #if 0
     72        1.1   ichiro static	int	L3_getbit(struct uda1341_softc *);
     73       1.14      rjs #endif
     74        1.1   ichiro static	void	L3_sendbit(struct uda1341_softc *, int);
     75       1.14      rjs #if 0
     76        1.9    peter static	uint8_t L3_getbyte(struct uda1341_softc *, int);
     77       1.14      rjs #endif
     78        1.9    peter static	void	L3_sendbyte(struct uda1341_softc *, uint8_t, int);
     79       1.14      rjs #if 0
     80        1.9    peter static	int	L3_read(struct uda1341_softc *, uint8_t, uint8_t *, int);
     81       1.14      rjs #endif
     82        1.9    peter static	int	L3_write(struct uda1341_softc *, uint8_t, uint8_t *, int);
     83        1.1   ichiro 
     84       1.14      rjs CFATTACH_DECL_NEW(uda, sizeof(struct uda1341_softc),
     85        1.4  thorpej     uda1341_match, uda1341_attach, NULL, NULL);
     86        1.1   ichiro 
     87        1.1   ichiro /*
     88        1.1   ichiro  * Philips L3 bus support.
     89        1.1   ichiro  * GPIO lines are used for clock, data and mode pins.
     90        1.1   ichiro  */
     91        1.1   ichiro #define L3_DATA		GPIO_H3600_L3_DATA
     92        1.1   ichiro #define L3_MODE		GPIO_H3600_L3_MODE
     93        1.1   ichiro #define L3_CLK		GPIO_H3600_L3_CLK
     94        1.1   ichiro 
     95        1.1   ichiro static struct {
     96        1.9    peter 	uint8_t data0;	/* direct addressing register */
     97        1.1   ichiro } DIRECT_REG = {0};
     98        1.1   ichiro 
     99        1.1   ichiro static struct {
    100        1.9    peter 	uint8_t data0;	/* extended addressing register 1 */
    101        1.9    peter 	uint8_t data1;	/* extended addressing register 2 */
    102        1.1   ichiro } EXTEND_REG = {0, 0};
    103        1.1   ichiro 
    104        1.1   ichiro /*
    105        1.1   ichiro  * register space access macros
    106        1.1   ichiro  */
    107        1.1   ichiro #define GPIO_WRITE(sc, reg, val) \
    108        1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_parent->sc_gpioh, reg, val)
    109        1.1   ichiro #define GPIO_READ(sc, reg) \
    110        1.1   ichiro 	bus_space_read_4(sc->sc_iot, sc->sc_parent->sc_gpioh, reg)
    111        1.1   ichiro #define EGPIO_WRITE(sc) \
    112        1.1   ichiro 	bus_space_write_2(sc->sc_iot, sc->sc_parent->sc_egpioh, \
    113        1.1   ichiro 			  0, sc->sc_parent->ipaq_egpio)
    114        1.1   ichiro #define SSP_WRITE(sc, reg, val) \
    115        1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_parent->sc_ssph, reg, val)
    116        1.1   ichiro 
    117        1.1   ichiro static int
    118       1.14      rjs uda1341_match(device_t parent, cfdata_t cf, void *aux)
    119        1.1   ichiro {
    120        1.1   ichiro 	return (1);
    121        1.1   ichiro }
    122        1.1   ichiro 
    123        1.1   ichiro static void
    124       1.14      rjs uda1341_attach(device_t parent, device_t self, void *aux)
    125        1.1   ichiro {
    126       1.14      rjs 	struct uda1341_softc *sc = device_private(self);
    127       1.14      rjs 	struct ipaq_softc *psc = device_private(parent);
    128        1.1   ichiro 
    129       1.14      rjs 	aprint_normal("\n");
    130       1.14      rjs 	aprint_normal_dev(self, "UDA1341 CODEC\n");
    131        1.1   ichiro 
    132       1.14      rjs 	sc->sc_dev = self;
    133        1.1   ichiro 	sc->sc_iot = psc->sc_iot;
    134        1.1   ichiro 	sc->sc_ioh = psc->sc_ioh;
    135       1.14      rjs 	sc->sc_parent = psc;
    136        1.1   ichiro 
    137        1.1   ichiro 	uda1341_L3_init(sc);
    138        1.1   ichiro 	uda1341_init(sc);
    139        1.1   ichiro 
    140        1.1   ichiro 	uda1341_reset(sc);
    141        1.1   ichiro 
    142        1.1   ichiro 	uda1341_reginit(sc);
    143        1.1   ichiro 
    144        1.1   ichiro 
    145        1.1   ichiro 	/*
    146        1.1   ichiro 	 *  Attach each devices
    147        1.1   ichiro 	 */
    148        1.1   ichiro 
    149  1.15.68.1  thorpej 	config_search(self, NULL,
    150  1.15.68.1  thorpej 	    CFARG_SUBMATCH, uda1341_search,
    151  1.15.68.1  thorpej 	    CFARG_IATTR, "udaif",
    152  1.15.68.1  thorpej 	    CFARG_EOL);
    153        1.1   ichiro }
    154        1.1   ichiro 
    155        1.1   ichiro static int
    156       1.14      rjs uda1341_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    157        1.1   ichiro {
    158        1.2  thorpej 	if (config_match(parent, cf, NULL) > 0)
    159        1.1   ichiro 		config_attach(parent, cf, NULL, uda1341_print);
    160        1.1   ichiro 	return 0;
    161        1.1   ichiro }
    162        1.1   ichiro 
    163        1.1   ichiro 
    164        1.1   ichiro static int
    165       1.12      dsl uda1341_print(void *aux, const char *name)
    166        1.1   ichiro {
    167        1.1   ichiro 	return (UNCONF);
    168        1.1   ichiro }
    169        1.1   ichiro 
    170        1.1   ichiro static void
    171       1.12      dsl uda1341_output_high(struct uda1341_softc *sc)
    172        1.1   ichiro {
    173        1.1   ichiro 	int cr;
    174        1.1   ichiro 
    175        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PSR, (L3_DATA | L3_MODE | L3_CLK));
    176        1.1   ichiro 	cr = GPIO_READ(sc, SAGPIO_PDR) | (L3_DATA | L3_MODE | L3_CLK);
    177        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PDR, cr);
    178        1.1   ichiro }
    179        1.1   ichiro 
    180        1.1   ichiro static void
    181       1.12      dsl uda1341_output_low(struct uda1341_softc *sc)
    182        1.1   ichiro {
    183        1.1   ichiro 	int cr;
    184        1.1   ichiro 
    185        1.1   ichiro 	cr = GPIO_READ(sc, SAGPIO_PDR);
    186        1.1   ichiro 	cr &= ~(L3_DATA | L3_MODE | L3_CLK);
    187        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PDR, cr);
    188        1.1   ichiro }
    189        1.1   ichiro 
    190        1.1   ichiro static void
    191       1.12      dsl uda1341_L3_init(struct uda1341_softc *sc)
    192        1.1   ichiro {
    193        1.1   ichiro 	int cr;
    194        1.1   ichiro 
    195        1.1   ichiro 	cr = GPIO_READ(sc, SAGPIO_AFR);
    196        1.1   ichiro 	cr &= ~(L3_DATA | L3_MODE | L3_CLK);
    197        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_AFR, cr);
    198        1.1   ichiro 
    199        1.1   ichiro 	uda1341_output_low(sc);
    200        1.1   ichiro }
    201        1.1   ichiro 
    202        1.1   ichiro static void
    203       1.12      dsl uda1341_init(struct uda1341_softc *sc)
    204        1.1   ichiro {
    205        1.1   ichiro 	int cr;
    206        1.1   ichiro 
    207        1.1   ichiro 	/* GPIO initialize */
    208        1.1   ichiro 	cr = GPIO_READ(sc, SAGPIO_AFR);
    209        1.1   ichiro 	cr &= ~(GPIO_ALT_SSP_TXD | GPIO_ALT_SSP_RXD | GPIO_ALT_SSP_SCLK |
    210        1.1   ichiro 		GPIO_ALT_SSP_SFRM);
    211        1.1   ichiro 	cr |= GPIO_ALT_SSP_CLK;
    212        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_AFR, cr);
    213        1.1   ichiro 
    214        1.1   ichiro 	cr = GPIO_READ(sc, SAGPIO_PDR);
    215        1.1   ichiro 	cr &= ~GPIO_ALT_SSP_CLK;
    216        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PDR, cr);
    217        1.1   ichiro 
    218        1.1   ichiro 	/* SSP initialize & enable */
    219        1.1   ichiro 	SSP_WRITE(sc, SASSP_CR1, CR1_ECS);
    220        1.1   ichiro 	cr = 0xF | (CR0_FRF_MASK & (1<<4)) | (CR0_SCR_MASK & (3<<8)) | CR0_SSE;
    221        1.1   ichiro 	SSP_WRITE(sc, SASSP_CR0, cr);
    222        1.1   ichiro 
    223        1.1   ichiro 	/* Enable the audio power */
    224        1.1   ichiro 	sc->sc_parent->ipaq_egpio |=
    225        1.1   ichiro 			(EGPIO_H3600_AUD_PWRON | EGPIO_H3600_AUD_ON);
    226        1.1   ichiro 	sc->sc_parent->ipaq_egpio &=
    227        1.1   ichiro 			~(EGPIO_H3600_CODEC_RESET | EGPIO_H3600_QMUTE);
    228        1.1   ichiro 	EGPIO_WRITE(sc);
    229        1.1   ichiro 
    230        1.1   ichiro 	/* external clock configured for 44100 samples/sec */
    231        1.1   ichiro 	cr = GPIO_READ(sc, SAGPIO_PDR);
    232        1.1   ichiro 	cr |= (GPIO_H3600_CLK_SET0 | GPIO_H3600_CLK_SET1);
    233        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PDR, cr);
    234        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PSR, GPIO_H3600_CLK_SET0);
    235        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PCR, GPIO_H3600_CLK_SET1);
    236        1.1   ichiro 
    237        1.1   ichiro 	/* wait for power on */
    238        1.1   ichiro 	delay(100*1000);
    239        1.1   ichiro 	sc->sc_parent->ipaq_egpio |= EGPIO_H3600_CODEC_RESET;
    240        1.1   ichiro 	EGPIO_WRITE(sc);
    241        1.1   ichiro 
    242        1.1   ichiro 	/* Wait for the UDA1341 to wake up */
    243        1.1   ichiro 	delay(100*1000);
    244        1.1   ichiro }
    245        1.1   ichiro 
    246        1.1   ichiro static void
    247       1.14      rjs uda1341_reset(struct uda1341_softc *sc)
    248        1.1   ichiro {
    249        1.9    peter 	uint8_t command;
    250        1.1   ichiro 
    251        1.1   ichiro 	command = (L3_ADDRESS_COM << 2) | L3_ADDRESS_STATUS;
    252        1.1   ichiro 	DIRECT_REG.data0 = STATUS0_RST | STATUS0_SC_256 | STATUS0_IF_LSB16;
    253        1.9    peter 	L3_write(sc, command, (uint8_t *) &DIRECT_REG, 1);
    254        1.1   ichiro 
    255        1.1   ichiro 	sc->sc_parent->ipaq_egpio &= ~EGPIO_H3600_CODEC_RESET;
    256        1.1   ichiro 	EGPIO_WRITE(sc);
    257        1.1   ichiro 	sc->sc_parent->ipaq_egpio |= EGPIO_H3600_CODEC_RESET;
    258        1.1   ichiro 	EGPIO_WRITE(sc);
    259        1.1   ichiro 
    260        1.1   ichiro 	DIRECT_REG.data0 &= ~STATUS0_RST;
    261        1.9    peter 	L3_write(sc, command, (uint8_t *) &DIRECT_REG, 1);
    262        1.1   ichiro }
    263        1.1   ichiro 
    264        1.1   ichiro static void
    265       1.12      dsl uda1341_reginit(struct uda1341_softc *sc)
    266        1.1   ichiro {
    267        1.9    peter 	uint8_t command;
    268        1.1   ichiro 
    269        1.1   ichiro 	/* STATUS 0 */
    270        1.1   ichiro 	command = (L3_ADDRESS_COM << 2) | L3_ADDRESS_STATUS;
    271        1.1   ichiro 	DIRECT_REG.data0 = STATUS0_SC_256 | STATUS0_IF_LSB16;
    272        1.9    peter 	L3_write(sc, command, (uint8_t *) &DIRECT_REG, 1);
    273        1.1   ichiro 
    274        1.1   ichiro 	/* STATUS 1 */
    275        1.1   ichiro 	DIRECT_REG.data0 = STATUS1_OGS | STATUS1_IGS | (1<<7);
    276        1.9    peter 	L3_write(sc, command, (uint8_t *) &DIRECT_REG, 1);
    277        1.1   ichiro 
    278        1.1   ichiro 	/* DATA 0 */
    279        1.1   ichiro 	command = (L3_ADDRESS_COM << 2) | L3_ADDRESS_DATA0;
    280        1.1   ichiro 	DIRECT_REG.data0 = DATA0_VC(100) | DATA0_COMMON;
    281        1.9    peter 	L3_write(sc, command, (uint8_t *) &DIRECT_REG, 1);
    282        1.1   ichiro 
    283        1.1   ichiro 	/* DATA 1 */
    284        1.1   ichiro 	DIRECT_REG.data0 = DATA1_BB(0) | DATA1_TR(0) | DATA1_COMMON;
    285        1.9    peter 	L3_write(sc, command, (uint8_t *) &DIRECT_REG, 1);
    286        1.1   ichiro 
    287        1.1   ichiro 	/* DATA 2*/
    288        1.1   ichiro 	DIRECT_REG.data0 = DATA2_PP | DATA2_COMMON;
    289        1.9    peter 	L3_write(sc, command, (uint8_t *) &DIRECT_REG, 1);
    290        1.1   ichiro 
    291        1.1   ichiro 	/* Extended DATA 0 */
    292        1.1   ichiro 	EXTEND_REG.data0 = EXT_ADDR_COMMON | EXT_ADDR_E0;
    293        1.1   ichiro 	EXTEND_REG.data1 = EXT_DATA_COMMN | 0x4 ;
    294        1.9    peter 	L3_write(sc, command, (uint8_t *) &EXTEND_REG, 2);
    295        1.1   ichiro 
    296        1.1   ichiro 	/* Extended DATA 1 */
    297        1.1   ichiro 	EXTEND_REG.data0 = EXT_ADDR_COMMON | EXT_ADDR_E1;
    298        1.1   ichiro 	EXTEND_REG.data1 = EXT_DATA_COMMN | 0x4 ;
    299        1.9    peter 	L3_write(sc, command, (uint8_t *) &EXTEND_REG, 2);
    300        1.1   ichiro 
    301        1.1   ichiro 	/* Extended DATA 2 */
    302        1.1   ichiro 	EXTEND_REG.data0 = EXT_ADDR_COMMON | EXT_ADDR_E2;
    303        1.1   ichiro 	EXTEND_REG.data1 = EXT_DATA_COMMN | DATA_E2_MS(30);
    304        1.9    peter 	L3_write(sc, command, (uint8_t *) &EXTEND_REG, 2);
    305        1.1   ichiro 
    306        1.1   ichiro 	/* Extended DATA 3 */
    307        1.1   ichiro 	EXTEND_REG.data0 = EXT_ADDR_COMMON | EXT_ADDR_E3;
    308        1.1   ichiro 	EXTEND_REG.data1 = EXT_DATA_COMMN | DATA_E3_IG_L(0);
    309        1.9    peter 	L3_write(sc, command, (uint8_t *) &EXTEND_REG, 2);
    310        1.1   ichiro 
    311        1.1   ichiro 	/* Extended DATA 4 */
    312        1.1   ichiro 	EXTEND_REG.data0 = EXT_ADDR_COMMON | EXT_ADDR_E4;
    313        1.1   ichiro 	EXTEND_REG.data1 = EXT_DATA_COMMN | DATA_E4_IG_H(0);
    314        1.9    peter 	L3_write(sc, command, (uint8_t *) &EXTEND_REG, 2);
    315        1.1   ichiro 
    316        1.1   ichiro 	/* Extended DATA 5 */
    317        1.1   ichiro 	EXTEND_REG.data0 = EXT_ADDR_COMMON | EXT_ADDR_E5;
    318        1.1   ichiro 	EXTEND_REG.data1 = EXT_DATA_COMMN;
    319        1.9    peter 	L3_write(sc, command, (uint8_t *) &EXTEND_REG, 2);
    320        1.1   ichiro }
    321        1.1   ichiro 
    322       1.14      rjs #if 0
    323        1.1   ichiro static int
    324       1.12      dsl L3_getbit(struct uda1341_softc *sc)
    325        1.1   ichiro {
    326        1.1   ichiro 	int cr, data;
    327        1.1   ichiro 
    328        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PCR, L3_CLK);	/* Clock down */
    329        1.1   ichiro 	delay(L3_CLK_LOW);
    330        1.1   ichiro 
    331        1.1   ichiro 	cr = GPIO_READ(sc, SAGPIO_PLR);
    332        1.1   ichiro 	data = (cr & L3_DATA) ? 1 : 0;
    333        1.1   ichiro 
    334        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PSR, L3_CLK);	/* Clock up */
    335        1.1   ichiro 	delay(L3_CLK_HIGH);
    336        1.1   ichiro 
    337        1.1   ichiro 	return (data);
    338        1.1   ichiro }
    339       1.14      rjs #endif
    340        1.1   ichiro 
    341        1.1   ichiro static void
    342       1.12      dsl L3_sendbit(struct uda1341_softc *sc, int bit)
    343        1.1   ichiro {
    344        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PCR, L3_CLK);	/* Clock down */
    345        1.1   ichiro 
    346        1.1   ichiro 	if (bit & 0x01)
    347        1.1   ichiro 		GPIO_WRITE(sc, SAGPIO_PSR, L3_DATA);
    348        1.1   ichiro 	else
    349        1.1   ichiro 		GPIO_WRITE(sc, SAGPIO_PCR, L3_DATA);
    350        1.1   ichiro 
    351        1.1   ichiro 	delay(L3_CLK_LOW);
    352        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PSR, L3_CLK);     /* Clock up */
    353        1.1   ichiro 	delay(L3_CLK_HIGH);
    354        1.1   ichiro }
    355        1.1   ichiro 
    356       1.14      rjs #if 0
    357        1.9    peter static uint8_t
    358       1.12      dsl L3_getbyte(struct uda1341_softc *sc, int mode)
    359        1.1   ichiro {
    360        1.1   ichiro 	int i;
    361        1.9    peter 	uint8_t data;
    362        1.1   ichiro 
    363        1.1   ichiro 	switch (mode) {
    364        1.1   ichiro 	case 0:		/* Address mode */
    365        1.1   ichiro 	case 1:		/* First data byte */
    366        1.1   ichiro 		break;
    367        1.1   ichiro 	default:	/* second data byte via halt-Time */
    368        1.1   ichiro 		GPIO_WRITE(sc, SAGPIO_PCR, L3_CLK);     /* Clock down */
    369        1.1   ichiro 		delay(L3_HALT);
    370        1.1   ichiro 		GPIO_WRITE(sc, SAGPIO_PSR, L3_CLK);	/* Clock up */
    371        1.1   ichiro 		break;
    372        1.1   ichiro 	}
    373        1.1   ichiro 
    374        1.1   ichiro 	delay(L3_MODE_SETUP);
    375        1.1   ichiro 
    376        1.1   ichiro 	for (i = 0; i < 8; i++)
    377        1.1   ichiro 		data |= (L3_getbit(sc) << i);
    378        1.1   ichiro 
    379        1.1   ichiro 	delay(L3_MODE_HOLD);
    380        1.1   ichiro 
    381        1.1   ichiro 	return (data);
    382        1.1   ichiro }
    383       1.14      rjs #endif
    384        1.1   ichiro 
    385        1.1   ichiro static void
    386       1.12      dsl L3_sendbyte(struct uda1341_softc *sc, uint8_t data, int mode)
    387        1.1   ichiro {
    388        1.1   ichiro 	int i;
    389        1.1   ichiro 
    390        1.1   ichiro 	switch (mode) {
    391        1.1   ichiro 	case 0:		/* Address mode */
    392        1.1   ichiro 		GPIO_WRITE(sc, SAGPIO_PCR, L3_CLK);	/* Clock down */
    393        1.1   ichiro 		break;
    394        1.1   ichiro 	case 1:		/* First data byte */
    395        1.1   ichiro 		break;
    396        1.1   ichiro 	default:	/* second data byte via halt-Time */
    397        1.1   ichiro 		GPIO_WRITE(sc, SAGPIO_PCR, L3_CLK);     /* Clock down */
    398        1.1   ichiro 		delay(L3_HALT);
    399        1.1   ichiro 		GPIO_WRITE(sc, SAGPIO_PSR, L3_CLK);	/* Clock up */
    400        1.1   ichiro 		break;
    401        1.1   ichiro 	}
    402        1.1   ichiro 
    403        1.1   ichiro 	delay(L3_MODE_SETUP);
    404        1.1   ichiro 
    405        1.1   ichiro 	for (i = 0; i < 8; i++)
    406        1.1   ichiro 		L3_sendbit(sc, data >> i);
    407        1.1   ichiro 
    408        1.1   ichiro 	if (mode == 0)		/* Address mode */
    409        1.1   ichiro 		GPIO_WRITE(sc, SAGPIO_PSR, L3_CLK);	/* Clock up */
    410        1.1   ichiro 
    411        1.1   ichiro 	delay(L3_MODE_HOLD);
    412        1.1   ichiro }
    413        1.1   ichiro 
    414       1.14      rjs #if 0
    415        1.1   ichiro static int
    416       1.13      dsl L3_read(struct uda1341_softc *sc, uint8_t addr, uint8_t *data, int len)
    417        1.1   ichiro {
    418        1.1   ichiro 	int cr, mode;
    419        1.1   ichiro 	mode = 0;
    420        1.1   ichiro 
    421        1.1   ichiro 	uda1341_output_high(sc);
    422        1.1   ichiro 	L3_sendbyte(sc, addr, mode++);
    423        1.1   ichiro 
    424        1.1   ichiro 	cr = GPIO_READ(sc, SAGPIO_PDR);
    425        1.1   ichiro 	cr &= ~(L3_DATA);
    426        1.1   ichiro 	GPIO_WRITE(sc, SAGPIO_PDR, cr);
    427        1.1   ichiro 
    428        1.1   ichiro 	while(len--)
    429        1.1   ichiro 		*data++ = L3_getbyte(sc, mode++);
    430        1.1   ichiro 	uda1341_output_low(sc);
    431        1.1   ichiro 
    432        1.1   ichiro 	return len;
    433        1.1   ichiro }
    434       1.14      rjs #endif
    435        1.1   ichiro 
    436        1.1   ichiro static int
    437       1.13      dsl L3_write(struct uda1341_softc *sc, uint8_t addr, uint8_t *data, int len)
    438        1.1   ichiro {
    439        1.1   ichiro 	int mode = 0;
    440        1.1   ichiro 
    441        1.1   ichiro 	uda1341_output_high(sc);
    442        1.1   ichiro 	L3_sendbyte(sc, addr, mode++);
    443        1.1   ichiro 	while(len--)
    444        1.1   ichiro 		L3_sendbyte(sc, *data++, mode++);
    445        1.1   ichiro 	uda1341_output_low(sc);
    446        1.1   ichiro 
    447        1.1   ichiro 	return len;
    448        1.1   ichiro }
    449