Subject: Re: New i2c framework
To: None <eeh@netbsd.org>
From: Bill Studenmund <wrstuden@netbsd.org>
List: tech-kern
Date: 02/18/2002 12:50:24
On 18 Feb 2002 eeh@netbsd.org wrote:

> The `Motorola syntax' for EEPROM access is that you send an address byte
> to the device then transfer a single data byte.  In that case you would do:
>
> int
> at76c651match(parent, cf, aux)
> 	struct device *parent;
> 	struct cfdata *cf;
> 	void *aux;
> {
> 	struct i2c_attach_args *i2a = aux;
> 	struct i2c_op op[2];
> 	int8_t regaddr = AT_CHIPID; /* Address of CHIPID register */
> 	int16_t id;
>
> 	/* Check the address */
> 	if (i2a->ia_addr < AT_ADDR_BASE || i2a->ia_addr > AT_ADDR_MAX)
> 		return (0);
>
> 	/*
> 	 * Check the version register:
> 	 *
> 	 * 1) address the register
> 	 */
> 	op[0].io_data = &regaddr;
> 	op[0].io_len = sizeof(regaddr);
> 	op[0].io_flags = I2CO_WRITE;
>
> 	/*
> 	 * 2) read 2 bytes of data
> 	 */
> 	op[1].io_data = &id;
> 	op[1].io_len = 2;
> 	op[1].io_flags = I2CO_READ;
>
> 	if (i2c_cmd(i2a->ia_ctlr, i2a->ia_addr, op, 2, I2C_POLL|I2C_REPSTART)
> 		!= 0) {
> #ifdef DEBUG
> 		printf("at76c651match: chipid read failure\n");
> #endif
> 		return (0);
> 	}
>
> 	if (id != AT76C651_CHIPID) {
            ^^^
What is the defined byte ordering for i2c? Is there one? Since id is a
int16_t, BE and LE machines will handle this bit differently...

> #ifdef DEBUG
> 		printf("at76c651match: id %x != %x mismatch\n",
> 			id, AT76C651_CHIPID);
> #endif
> 		return (0);
> 	}
> 	/* We should also match a specific bus... */
> 	return (1);
> }

Take care,

Bill