Home | History | Annotate | Line # | Download | only in dev
ki2c.c revision 1.2.2.1
      1  1.2.2.1   yamt /*	$NetBSD: ki2c.c,v 1.2.2.1 2006/06/21 14:53:13 yamt Exp $	*/
      2      1.1  grant /*	Id: ki2c.c,v 1.7 2002/10/05 09:56:05 tsubai Exp	*/
      3      1.1  grant 
      4      1.1  grant /*-
      5      1.1  grant  * Copyright (c) 2001 Tsubai Masanari.  All rights reserved.
      6      1.1  grant  *
      7      1.1  grant  * Redistribution and use in source and binary forms, with or without
      8      1.1  grant  * modification, are permitted provided that the following conditions
      9      1.1  grant  * are met:
     10      1.1  grant  * 1. Redistributions of source code must retain the above copyright
     11      1.1  grant  *    notice, this list of conditions and the following disclaimer.
     12      1.1  grant  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  grant  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  grant  *    documentation and/or other materials provided with the distribution.
     15      1.1  grant  * 3. The name of the author may not be used to endorse or promote products
     16      1.1  grant  *    derived from this software without specific prior written permission.
     17      1.1  grant  *
     18      1.1  grant  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19      1.1  grant  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20      1.1  grant  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21      1.1  grant  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22      1.1  grant  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23      1.1  grant  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24      1.1  grant  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25      1.1  grant  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26      1.1  grant  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27      1.1  grant  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28      1.1  grant  */
     29      1.1  grant 
     30      1.1  grant #include <sys/param.h>
     31      1.1  grant #include <sys/device.h>
     32      1.1  grant #include <sys/systm.h>
     33      1.1  grant 
     34      1.1  grant #include <dev/ofw/openfirm.h>
     35      1.1  grant #include <uvm/uvm_extern.h>
     36      1.1  grant #include <machine/autoconf.h>
     37      1.1  grant 
     38  1.2.2.1   yamt #include <macppc/dev/ki2cvar.h>
     39      1.1  grant 
     40      1.1  grant int ki2c_match(struct device *, struct cfdata *, void *);
     41      1.1  grant void ki2c_attach(struct device *, struct device *, void *);
     42      1.1  grant inline u_int ki2c_readreg(struct ki2c_softc *, int);
     43      1.1  grant inline void ki2c_writereg(struct ki2c_softc *, int, u_int);
     44      1.1  grant u_int ki2c_getmode(struct ki2c_softc *);
     45      1.1  grant void ki2c_setmode(struct ki2c_softc *, u_int);
     46      1.1  grant u_int ki2c_getspeed(struct ki2c_softc *);
     47      1.1  grant void ki2c_setspeed(struct ki2c_softc *, u_int);
     48      1.1  grant int ki2c_intr(struct ki2c_softc *);
     49      1.1  grant int ki2c_poll(struct ki2c_softc *, int);
     50      1.1  grant int ki2c_start(struct ki2c_softc *, int, int, void *, int);
     51      1.1  grant int ki2c_read(struct ki2c_softc *, int, int, void *, int);
     52  1.2.2.1   yamt int ki2c_write(struct ki2c_softc *, int, int, void *, int);
     53  1.2.2.1   yamt int ki2c_print __P((void *, const char *));
     54  1.2.2.1   yamt 
     55  1.2.2.1   yamt /* I2C glue */
     56  1.2.2.1   yamt static int ki2c_i2c_acquire_bus(void *, int);
     57  1.2.2.1   yamt static void ki2c_i2c_release_bus(void *, int);
     58  1.2.2.1   yamt static int ki2c_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
     59  1.2.2.1   yamt 		    void *, size_t, int);
     60  1.2.2.1   yamt 
     61      1.1  grant 
     62      1.1  grant struct cfattach ki2c_ca = {
     63      1.1  grant 	"ki2c", {}, sizeof(struct ki2c_softc), ki2c_match, ki2c_attach
     64      1.1  grant };
     65      1.1  grant 
     66      1.1  grant int
     67      1.1  grant ki2c_match(parent, match, aux)
     68      1.1  grant 	struct device *parent;
     69      1.1  grant 	struct cfdata *match;
     70      1.1  grant 	void *aux;
     71      1.1  grant {
     72      1.1  grant 	struct confargs *ca = aux;
     73      1.1  grant 
     74      1.1  grant 	if (strcmp(ca->ca_name, "i2c") == 0)
     75      1.1  grant 		return 1;
     76      1.1  grant 
     77      1.1  grant 	return 0;
     78      1.1  grant }
     79      1.1  grant 
     80      1.1  grant void
     81      1.1  grant ki2c_attach(parent, self, aux)
     82      1.1  grant 	struct device *parent;
     83      1.1  grant 	struct device *self;
     84      1.1  grant 	void *aux;
     85      1.1  grant {
     86      1.1  grant 	struct ki2c_softc *sc = (struct ki2c_softc *)self;
     87      1.1  grant 	struct confargs *ca = aux;
     88      1.1  grant 	int node = ca->ca_node;
     89  1.2.2.1   yamt 	int rate, child, namelen, i2cbus;
     90  1.2.2.1   yamt 	struct ki2c_confargs ka;
     91  1.2.2.1   yamt 	struct i2cbus_attach_args iba;
     92  1.2.2.1   yamt 
     93  1.2.2.1   yamt 	char name[32];
     94  1.2.2.1   yamt 	u_int reg[20];
     95  1.2.2.1   yamt 
     96      1.1  grant 	ca->ca_reg[0] += ca->ca_baseaddr;
     97      1.1  grant 
     98      1.1  grant 	if (OF_getprop(node, "AAPL,i2c-rate", &rate, 4) != 4) {
     99      1.1  grant 		printf(": cannot get i2c-rate\n");
    100      1.1  grant 		return;
    101      1.1  grant 	}
    102      1.1  grant 	if (OF_getprop(node, "AAPL,address", &sc->sc_reg, 4) != 4) {
    103      1.1  grant 		printf(": unable to find i2c address\n");
    104      1.1  grant 		return;
    105      1.1  grant 	}
    106      1.1  grant 	if (OF_getprop(node, "AAPL,address-step", &sc->sc_regstep, 4) != 4) {
    107      1.1  grant 		printf(": unable to find i2c address step\n");
    108      1.1  grant 		return;
    109      1.1  grant 	}
    110      1.1  grant 
    111      1.1  grant 	printf("\n");
    112      1.1  grant 
    113      1.1  grant 	ki2c_writereg(sc, STATUS, 0);
    114      1.1  grant 	ki2c_writereg(sc, ISR, 0);
    115      1.1  grant 	ki2c_writereg(sc, IER, 0);
    116      1.1  grant 
    117      1.1  grant 	ki2c_setmode(sc, I2C_STDSUBMODE);
    118      1.1  grant 	ki2c_setspeed(sc, I2C_100kHz);		/* XXX rate */
    119  1.2.2.1   yamt 
    120  1.2.2.1   yamt 	lockinit(&sc->sc_buslock, PRIBIO|PCATCH, sc->sc_dev.dv_xname, 0, 0);
    121  1.2.2.1   yamt 	ki2c_writereg(sc, IER,I2C_INT_DATA|I2C_INT_ADDR|I2C_INT_STOP);
    122  1.2.2.1   yamt 
    123  1.2.2.1   yamt 	/* fill in the i2c tag */
    124  1.2.2.1   yamt 	sc->sc_i2c.ic_cookie = sc;
    125  1.2.2.1   yamt 	sc->sc_i2c.ic_acquire_bus = ki2c_i2c_acquire_bus;
    126  1.2.2.1   yamt 	sc->sc_i2c.ic_release_bus = ki2c_i2c_release_bus;
    127  1.2.2.1   yamt 	sc->sc_i2c.ic_send_start = NULL;
    128  1.2.2.1   yamt 	sc->sc_i2c.ic_send_stop = NULL;
    129  1.2.2.1   yamt 	sc->sc_i2c.ic_initiate_xfer = NULL;
    130  1.2.2.1   yamt 	sc->sc_i2c.ic_read_byte = NULL;
    131  1.2.2.1   yamt 	sc->sc_i2c.ic_write_byte = NULL;
    132  1.2.2.1   yamt 	sc->sc_i2c.ic_exec = ki2c_i2c_exec;
    133  1.2.2.1   yamt 
    134  1.2.2.1   yamt 	iba.iba_name = "iic";
    135  1.2.2.1   yamt 	iba.iba_tag = &sc->sc_i2c;
    136  1.2.2.1   yamt 	(void) config_found(&sc->sc_dev, &iba, iicbus_print);
    137  1.2.2.1   yamt 
    138  1.2.2.1   yamt 	/*
    139  1.2.2.1   yamt 	 * newer OF puts I2C devices under 'i2c-bus' instead of attaching them
    140  1.2.2.1   yamt 	 * directly to the ki2c node so we just check if we have a child named
    141  1.2.2.1   yamt 	 * 'i2c-bus' and if so we attach its children, not ours
    142  1.2.2.1   yamt 	 */
    143  1.2.2.1   yamt 	i2cbus = 0;
    144  1.2.2.1   yamt 	child = OF_child(node);
    145  1.2.2.1   yamt 	while ((child != 0) && (i2cbus == 0)) {
    146  1.2.2.1   yamt 		OF_getprop(child, "name", name, sizeof(name));
    147  1.2.2.1   yamt 		if (strcmp(name, "i2c-bus") == 0)
    148  1.2.2.1   yamt 			i2cbus = child;
    149  1.2.2.1   yamt 		child = OF_peer(child);
    150  1.2.2.1   yamt 	}
    151  1.2.2.1   yamt 	if (i2cbus == 0)
    152  1.2.2.1   yamt 		i2cbus = node;
    153  1.2.2.1   yamt 
    154  1.2.2.1   yamt 	for (child = OF_child(i2cbus); child; child = OF_peer(child)) {
    155  1.2.2.1   yamt 		namelen = OF_getprop(child, "name", name, sizeof(name));
    156  1.2.2.1   yamt 		if (namelen < 0)
    157  1.2.2.1   yamt 			continue;
    158  1.2.2.1   yamt 		if (namelen >= sizeof(name))
    159  1.2.2.1   yamt 			continue;
    160  1.2.2.1   yamt 
    161  1.2.2.1   yamt 		name[namelen] = 0;
    162  1.2.2.1   yamt 		ka.ka_name = name;
    163  1.2.2.1   yamt 		ka.ka_node = child;
    164  1.2.2.1   yamt 		if (OF_getprop(child, "reg", reg, sizeof(reg))>0) {
    165  1.2.2.1   yamt 			ka.ka_addr = reg[0];
    166  1.2.2.1   yamt 			ka.ka_tag = &sc->sc_i2c;
    167  1.2.2.1   yamt 			config_found(self, &ka, ki2c_print);
    168  1.2.2.1   yamt 		}
    169  1.2.2.1   yamt 	}
    170  1.2.2.1   yamt }
    171  1.2.2.1   yamt 
    172  1.2.2.1   yamt int
    173  1.2.2.1   yamt ki2c_print(aux, ki2c)
    174  1.2.2.1   yamt 	void *aux;
    175  1.2.2.1   yamt 	const char *ki2c;
    176  1.2.2.1   yamt {
    177  1.2.2.1   yamt 	struct ki2c_confargs *ka = aux;
    178  1.2.2.1   yamt 
    179  1.2.2.1   yamt 	if (ki2c) {
    180  1.2.2.1   yamt 		aprint_normal("%s at %s", ka->ka_name, ki2c);
    181  1.2.2.1   yamt 		aprint_normal(" address 0x%x", ka->ka_addr);
    182  1.2.2.1   yamt 	}
    183  1.2.2.1   yamt 	return UNCONF;
    184      1.1  grant }
    185      1.1  grant 
    186      1.1  grant u_int
    187      1.1  grant ki2c_readreg(sc, reg)
    188      1.1  grant 	struct ki2c_softc *sc;
    189      1.1  grant 	int reg;
    190      1.1  grant {
    191      1.1  grant 	u_char *addr = sc->sc_reg + sc->sc_regstep * reg;
    192      1.1  grant 
    193      1.1  grant 	return *addr;
    194      1.1  grant }
    195      1.1  grant 
    196      1.1  grant void
    197      1.1  grant ki2c_writereg(sc, reg, val)
    198      1.1  grant 	struct ki2c_softc *sc;
    199      1.1  grant 	int reg;
    200      1.1  grant 	u_int val;
    201      1.1  grant {
    202      1.1  grant 	u_char *addr = sc->sc_reg + sc->sc_regstep * reg;
    203      1.1  grant 
    204      1.1  grant 	*addr = val;
    205  1.2.2.1   yamt 	__asm volatile ("eieio");
    206      1.1  grant 	delay(10);
    207      1.1  grant }
    208      1.1  grant 
    209      1.1  grant u_int
    210      1.1  grant ki2c_getmode(sc)
    211      1.1  grant 	struct ki2c_softc *sc;
    212      1.1  grant {
    213      1.1  grant 	return ki2c_readreg(sc, MODE) & I2C_MODE;
    214      1.1  grant }
    215      1.1  grant 
    216      1.1  grant void
    217      1.1  grant ki2c_setmode(sc, mode)
    218      1.1  grant 	struct ki2c_softc *sc;
    219      1.1  grant 	u_int mode;
    220      1.1  grant {
    221      1.1  grant 	u_int x;
    222      1.1  grant 
    223      1.1  grant 	KASSERT((mode & ~I2C_MODE) == 0);
    224      1.1  grant 	x = ki2c_readreg(sc, MODE);
    225      1.1  grant 	x &= ~I2C_MODE;
    226      1.1  grant 	x |= mode;
    227      1.1  grant 	ki2c_writereg(sc, MODE, x);
    228      1.1  grant }
    229      1.1  grant 
    230      1.1  grant u_int
    231      1.1  grant ki2c_getspeed(sc)
    232      1.1  grant 	struct ki2c_softc *sc;
    233      1.1  grant {
    234      1.1  grant 	return ki2c_readreg(sc, MODE) & I2C_SPEED;
    235      1.1  grant }
    236      1.1  grant 
    237      1.1  grant void
    238      1.1  grant ki2c_setspeed(sc, speed)
    239      1.1  grant 	struct ki2c_softc *sc;
    240      1.1  grant 	u_int speed;
    241      1.1  grant {
    242      1.1  grant 	u_int x;
    243      1.1  grant 
    244      1.1  grant 	KASSERT((speed & ~I2C_SPEED) == 0);
    245      1.1  grant 	x = ki2c_readreg(sc, MODE);
    246      1.1  grant 	x &= ~I2C_SPEED;
    247      1.1  grant 	x |= speed;
    248      1.1  grant 	ki2c_writereg(sc, MODE, x);
    249      1.1  grant }
    250      1.1  grant 
    251      1.1  grant int
    252      1.1  grant ki2c_intr(sc)
    253      1.1  grant 	struct ki2c_softc *sc;
    254      1.1  grant {
    255      1.1  grant 	u_int isr, x;
    256      1.1  grant 
    257      1.1  grant 	isr = ki2c_readreg(sc, ISR);
    258      1.1  grant 	if (isr & I2C_INT_ADDR) {
    259      1.1  grant #if 0
    260      1.1  grant 		if ((ki2c_readreg(sc, STATUS) & I2C_ST_LASTAAK) == 0) {
    261      1.1  grant 			/* No slave responded. */
    262      1.1  grant 			sc->sc_flags |= I2C_ERROR;
    263      1.1  grant 			goto out;
    264      1.1  grant 		}
    265      1.1  grant #endif
    266      1.1  grant 
    267      1.1  grant 		if (sc->sc_flags & I2C_READING) {
    268      1.1  grant 			if (sc->sc_resid > 1) {
    269      1.1  grant 				x = ki2c_readreg(sc, CONTROL);
    270      1.1  grant 				x |= I2C_CT_AAK;
    271      1.1  grant 				ki2c_writereg(sc, CONTROL, x);
    272      1.1  grant 			}
    273      1.1  grant 		} else {
    274      1.1  grant 			ki2c_writereg(sc, DATA, *sc->sc_data++);
    275      1.1  grant 			sc->sc_resid--;
    276      1.1  grant 		}
    277      1.1  grant 	}
    278      1.1  grant 
    279      1.1  grant 	if (isr & I2C_INT_DATA) {
    280      1.1  grant 		if (sc->sc_flags & I2C_READING) {
    281      1.1  grant 			*sc->sc_data++ = ki2c_readreg(sc, DATA);
    282      1.1  grant 			sc->sc_resid--;
    283      1.1  grant 
    284      1.1  grant 			if (sc->sc_resid == 0) {	/* Completed */
    285      1.1  grant 				ki2c_writereg(sc, CONTROL, 0);
    286      1.1  grant 				goto out;
    287      1.1  grant 			}
    288      1.1  grant 		} else {
    289      1.1  grant #if 0
    290      1.1  grant 			if ((ki2c_readreg(sc, STATUS) & I2C_ST_LASTAAK) == 0) {
    291      1.1  grant 				/* No slave responded. */
    292      1.1  grant 				sc->sc_flags |= I2C_ERROR;
    293      1.1  grant 				goto out;
    294      1.1  grant 			}
    295      1.1  grant #endif
    296      1.1  grant 
    297      1.1  grant 			if (sc->sc_resid == 0) {
    298      1.1  grant 				x = ki2c_readreg(sc, CONTROL) | I2C_CT_STOP;
    299      1.1  grant 				ki2c_writereg(sc, CONTROL, x);
    300      1.1  grant 			} else {
    301      1.1  grant 				ki2c_writereg(sc, DATA, *sc->sc_data++);
    302      1.1  grant 				sc->sc_resid--;
    303      1.1  grant 			}
    304      1.1  grant 		}
    305      1.1  grant 	}
    306      1.1  grant 
    307      1.1  grant out:
    308      1.1  grant 	if (isr & I2C_INT_STOP) {
    309      1.1  grant 		ki2c_writereg(sc, CONTROL, 0);
    310      1.1  grant 		sc->sc_flags &= ~I2C_BUSY;
    311      1.1  grant 	}
    312      1.1  grant 
    313      1.1  grant 	ki2c_writereg(sc, ISR, isr);
    314      1.1  grant 
    315      1.1  grant 	return 1;
    316      1.1  grant }
    317      1.1  grant 
    318      1.1  grant int
    319      1.1  grant ki2c_poll(sc, timo)
    320      1.1  grant 	struct ki2c_softc *sc;
    321      1.1  grant 	int timo;
    322      1.1  grant {
    323      1.1  grant 	while (sc->sc_flags & I2C_BUSY) {
    324      1.1  grant 		if (ki2c_readreg(sc, ISR))
    325      1.1  grant 			ki2c_intr(sc);
    326      1.1  grant 		timo -= 100;
    327      1.1  grant 		if (timo < 0) {
    328      1.1  grant 			printf("i2c_poll: timeout\n");
    329      1.1  grant 			return -1;
    330      1.1  grant 		}
    331      1.1  grant 		delay(100);
    332      1.1  grant 	}
    333      1.1  grant 	return 0;
    334      1.1  grant }
    335      1.1  grant 
    336      1.1  grant int
    337      1.1  grant ki2c_start(sc, addr, subaddr, data, len)
    338      1.1  grant 	struct ki2c_softc *sc;
    339      1.1  grant 	int addr, subaddr, len;
    340      1.1  grant 	void *data;
    341      1.1  grant {
    342      1.1  grant 	int rw = (sc->sc_flags & I2C_READING) ? 1 : 0;
    343      1.1  grant 	int timo, x;
    344      1.1  grant 
    345      1.1  grant 	KASSERT((addr & 1) == 0);
    346      1.1  grant 
    347      1.1  grant 	sc->sc_data = data;
    348      1.1  grant 	sc->sc_resid = len;
    349      1.1  grant 	sc->sc_flags |= I2C_BUSY;
    350      1.1  grant 
    351      1.1  grant 	timo = 1000 + len * 200;
    352      1.1  grant 
    353      1.1  grant 	/* XXX TAS3001 sometimes takes 50ms to finish writing registers. */
    354      1.1  grant 	/* if (addr == 0x68) */
    355      1.1  grant 		timo += 100000;
    356      1.1  grant 
    357      1.1  grant 	ki2c_writereg(sc, ADDR, addr | rw);
    358      1.1  grant 	ki2c_writereg(sc, SUBADDR, subaddr);
    359      1.1  grant 
    360      1.1  grant 	x = ki2c_readreg(sc, CONTROL) | I2C_CT_ADDR;
    361      1.1  grant 	ki2c_writereg(sc, CONTROL, x);
    362      1.1  grant 
    363      1.1  grant 	if (ki2c_poll(sc, timo))
    364      1.1  grant 		return -1;
    365      1.1  grant 	if (sc->sc_flags & I2C_ERROR) {
    366      1.1  grant 		printf("I2C_ERROR\n");
    367      1.1  grant 		return -1;
    368      1.1  grant 	}
    369      1.1  grant 	return 0;
    370      1.1  grant }
    371      1.1  grant 
    372      1.1  grant int
    373      1.1  grant ki2c_read(sc, addr, subaddr, data, len)
    374      1.1  grant 	struct ki2c_softc *sc;
    375      1.1  grant 	int addr, subaddr, len;
    376      1.1  grant 	void *data;
    377      1.1  grant {
    378      1.1  grant 	sc->sc_flags = I2C_READING;
    379  1.2.2.1   yamt 	#ifdef KI2C_DEBUG
    380  1.2.2.1   yamt 		printf("ki2c_read: %02x %d\n", addr, len);
    381  1.2.2.1   yamt 	#endif
    382      1.1  grant 	return ki2c_start(sc, addr, subaddr, data, len);
    383      1.1  grant }
    384      1.1  grant 
    385      1.1  grant int
    386      1.1  grant ki2c_write(sc, addr, subaddr, data, len)
    387      1.1  grant 	struct ki2c_softc *sc;
    388      1.1  grant 	int addr, subaddr, len;
    389  1.2.2.1   yamt 	void *data;
    390      1.1  grant {
    391      1.1  grant 	sc->sc_flags = 0;
    392  1.2.2.1   yamt 	#ifdef KI2C_DEBUG
    393  1.2.2.1   yamt 		printf("ki2c_write: %02x %d\n",addr,len);
    394  1.2.2.1   yamt 	#endif
    395  1.2.2.1   yamt 	return ki2c_start(sc, addr, subaddr, data, len);
    396  1.2.2.1   yamt }
    397  1.2.2.1   yamt 
    398  1.2.2.1   yamt static int
    399  1.2.2.1   yamt ki2c_i2c_acquire_bus(void *cookie, int flags)
    400  1.2.2.1   yamt {
    401  1.2.2.1   yamt 	struct ki2c_softc *sc = cookie;
    402  1.2.2.1   yamt 
    403  1.2.2.1   yamt 	return (lockmgr(&sc->sc_buslock, LK_EXCLUSIVE, NULL));
    404  1.2.2.1   yamt }
    405  1.2.2.1   yamt 
    406  1.2.2.1   yamt static void
    407  1.2.2.1   yamt ki2c_i2c_release_bus(void *cookie, int flags)
    408  1.2.2.1   yamt {
    409  1.2.2.1   yamt 	struct ki2c_softc *sc = cookie;
    410  1.2.2.1   yamt 
    411  1.2.2.1   yamt 	(void) lockmgr(&sc->sc_buslock, LK_RELEASE, NULL);
    412  1.2.2.1   yamt }
    413  1.2.2.1   yamt 
    414  1.2.2.1   yamt int
    415  1.2.2.1   yamt ki2c_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *vcmd,
    416  1.2.2.1   yamt     size_t cmdlen, void *vbuf, size_t buflen, int flags)
    417  1.2.2.1   yamt {
    418  1.2.2.1   yamt 	struct ki2c_softc *sc = cookie;
    419  1.2.2.1   yamt 
    420  1.2.2.1   yamt 	/* we handle the subaddress stuff ourselves */
    421  1.2.2.1   yamt 	ki2c_setmode(sc, I2C_STDMODE);
    422  1.2.2.1   yamt 
    423  1.2.2.1   yamt 	if (ki2c_write(sc, addr, 0, __UNCONST(vcmd), cmdlen) !=0 )
    424  1.2.2.1   yamt 		return -1;
    425  1.2.2.1   yamt 	if (I2C_OP_READ_P(op))
    426  1.2.2.1   yamt 	{
    427  1.2.2.1   yamt 		if (ki2c_read(sc, addr, 0, vbuf, buflen) !=0 )
    428  1.2.2.1   yamt 			return -1;
    429  1.2.2.1   yamt 	}
    430  1.2.2.1   yamt 	return 0;
    431      1.1  grant }
    432