Home | History | Annotate | Line # | Download | only in i2c
i2cvar.h revision 1.1.18.1
      1  1.1.18.1     yamt /*	$NetBSD: i2cvar.h,v 1.1.18.1 2006/06/21 15:02:51 yamt Exp $	*/
      2       1.1  thorpej 
      3       1.1  thorpej /*
      4       1.1  thorpej  * Copyright (c) 2003 Wasabi Systems, Inc.
      5       1.1  thorpej  * All rights reserved.
      6       1.1  thorpej  *
      7       1.1  thorpej  * Written by Steve C. Woodford and Jason R. Thorpe for Wasabi Systems, Inc.
      8       1.1  thorpej  *
      9       1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     10       1.1  thorpej  * modification, are permitted provided that the following conditions
     11       1.1  thorpej  * are met:
     12       1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     13       1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     14       1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     16       1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     17       1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     18       1.1  thorpej  *    must display the following acknowledgement:
     19       1.1  thorpej  *      This product includes software developed for the NetBSD Project by
     20       1.1  thorpej  *      Wasabi Systems, Inc.
     21       1.1  thorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22       1.1  thorpej  *    or promote products derived from this software without specific prior
     23       1.1  thorpej  *    written permission.
     24       1.1  thorpej  *
     25       1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26       1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27       1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28       1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29       1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30       1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31       1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32       1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33       1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34       1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35       1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     36       1.1  thorpej  */
     37       1.1  thorpej 
     38       1.1  thorpej #ifndef _DEV_I2C_I2CVAR_H_
     39       1.1  thorpej #define	_DEV_I2C_I2CVAR_H_
     40       1.1  thorpej 
     41       1.1  thorpej #include <dev/i2c/i2c_io.h>
     42       1.1  thorpej 
     43       1.1  thorpej /* Flags passed to i2c routines. */
     44       1.1  thorpej #define	I2C_F_WRITE		0x00	/* new transfer is a write */
     45       1.1  thorpej #define	I2C_F_READ		0x01	/* new transfer is a read */
     46       1.1  thorpej #define	I2C_F_LAST		0x02	/* last byte of read */
     47       1.1  thorpej #define	I2C_F_STOP		0x04	/* send stop after byte */
     48       1.1  thorpej #define	I2C_F_POLL		0x08	/* poll, don't sleep */
     49  1.1.18.1     yamt #define	I2C_F_PEC		0x10	/* smbus packet error checking */
     50       1.1  thorpej 
     51       1.1  thorpej /*
     52       1.1  thorpej  * This structure provides the interface between the i2c framework
     53       1.1  thorpej  * and the underlying i2c controller.
     54       1.1  thorpej  *
     55       1.1  thorpej  * Note that this structure is designed specifically to allow us
     56       1.1  thorpej  * to either use the autoconfiguration framework or not.  This
     57       1.1  thorpej  * allows a driver for a board with a private i2c bus use generic
     58       1.1  thorpej  * i2c client drivers for chips that might be on that board.
     59       1.1  thorpej  */
     60       1.1  thorpej typedef struct i2c_controller {
     61       1.1  thorpej 	void	*ic_cookie;		/* controller private */
     62       1.1  thorpej 
     63       1.1  thorpej 	/*
     64       1.1  thorpej 	 * These provide synchronization in the presence of
     65       1.1  thorpej 	 * multiple users of the i2c bus.  When a device
     66       1.1  thorpej 	 * driver wishes to perform transfers on the i2c
     67       1.1  thorpej 	 * bus, the driver should acquire the bus.  When
     68       1.1  thorpej 	 * the driver is finished, it should release the
     69       1.1  thorpej 	 * bus.
     70       1.1  thorpej 	 *
     71       1.1  thorpej 	 * This is provided by the back-end since a single
     72       1.1  thorpej 	 * controller may present e.g. i2c and smbus views
     73       1.1  thorpej 	 * of the same set of i2c wires.
     74       1.1  thorpej 	 */
     75       1.1  thorpej 	int	(*ic_acquire_bus)(void *, int);
     76       1.1  thorpej 	void	(*ic_release_bus)(void *, int);
     77       1.1  thorpej 
     78       1.1  thorpej 	/*
     79       1.1  thorpej 	 * The preferred API for clients of the i2c interface
     80       1.1  thorpej 	 * is the scripted API.  This handles i2c controllers
     81       1.1  thorpej 	 * that do not provide raw access to the i2c signals.
     82       1.1  thorpej 	 */
     83       1.1  thorpej 	int	(*ic_exec)(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
     84       1.1  thorpej 		    void *, size_t, int);
     85       1.1  thorpej 
     86       1.1  thorpej 	int	(*ic_send_start)(void *, int);
     87       1.1  thorpej 	int	(*ic_send_stop)(void *, int);
     88       1.1  thorpej 	int	(*ic_initiate_xfer)(void *, i2c_addr_t, int);
     89       1.1  thorpej 	int	(*ic_read_byte)(void *, uint8_t *, int);
     90       1.1  thorpej 	int	(*ic_write_byte)(void *, uint8_t, int);
     91       1.1  thorpej } *i2c_tag_t;
     92       1.1  thorpej 
     93  1.1.18.1     yamt /* I2C bus types */
     94  1.1.18.1     yamt #define	I2C_TYPE_SMBUS	1
     95  1.1.18.1     yamt 
     96       1.1  thorpej /* Used to attach the i2c framework to the controller. */
     97       1.1  thorpej struct i2cbus_attach_args {
     98       1.1  thorpej 	const char *iba_name;		/* bus name ("iic") */
     99       1.1  thorpej 	i2c_tag_t iba_tag;		/* the controller */
    100  1.1.18.1     yamt 	int iba_type;			/* bus type */
    101       1.1  thorpej };
    102       1.1  thorpej 
    103       1.1  thorpej /* Used to attach devices on the i2c bus. */
    104       1.1  thorpej struct i2c_attach_args {
    105       1.1  thorpej 	i2c_tag_t	ia_tag;		/* our controller */
    106       1.1  thorpej 	i2c_addr_t	ia_addr;	/* address of device */
    107       1.1  thorpej 	int		ia_size;	/* size (for EEPROMs) */
    108  1.1.18.1     yamt 	int		ia_type;	/* bus type */
    109       1.1  thorpej };
    110       1.1  thorpej 
    111       1.1  thorpej /*
    112       1.1  thorpej  * API presented to i2c controllers.
    113       1.1  thorpej  */
    114       1.1  thorpej int	iicbus_print(void *, const char *);
    115       1.1  thorpej 
    116       1.1  thorpej #ifdef _I2C_PRIVATE
    117       1.1  thorpej /*
    118       1.1  thorpej  * Macros used internally by the i2c framework.
    119       1.1  thorpej  */
    120       1.1  thorpej #define	iic_send_start(ic, flags)					\
    121       1.1  thorpej 	(*(ic)->ic_send_start)((ic)->ic_cookie, (flags))
    122       1.1  thorpej #define	iic_send_stop(ic, flags)					\
    123       1.1  thorpej 	(*(ic)->ic_send_stop)((ic)->ic_cookie, (flags))
    124       1.1  thorpej #define	iic_initiate_xfer(ic, addr, flags)				\
    125       1.1  thorpej 	(*(ic)->ic_initiate_xfer)((ic)->ic_cookie, (addr), (flags))
    126       1.1  thorpej 
    127       1.1  thorpej #define	iic_read_byte(ic, bytep, flags)					\
    128       1.1  thorpej 	(*(ic)->ic_read_byte)((ic)->ic_cookie, (bytep), (flags))
    129       1.1  thorpej #define	iic_write_byte(ic, byte, flags)					\
    130       1.1  thorpej 	(*(ic)->ic_write_byte)((ic)->ic_cookie, (byte), (flags))
    131       1.1  thorpej #endif /* _I2C_PRIVATE */
    132       1.1  thorpej 
    133       1.1  thorpej /*
    134       1.1  thorpej  * Simplified API for clients of the i2c framework.  Definitions
    135       1.1  thorpej  * in <dev/i2c/i2c_io.h>.
    136       1.1  thorpej  */
    137       1.1  thorpej #define	iic_acquire_bus(ic, flags)					\
    138       1.1  thorpej 	(*(ic)->ic_acquire_bus)((ic)->ic_cookie, (flags))
    139       1.1  thorpej #define	iic_release_bus(ic, flags)					\
    140       1.1  thorpej 	(*(ic)->ic_release_bus)((ic)->ic_cookie, (flags))
    141       1.1  thorpej 
    142       1.1  thorpej int	iic_exec(i2c_tag_t, i2c_op_t, i2c_addr_t, const void *,
    143       1.1  thorpej 	    size_t, void *, size_t, int);
    144       1.1  thorpej 
    145       1.1  thorpej int	iic_smbus_write_byte(i2c_tag_t, i2c_addr_t, uint8_t, uint8_t, int);
    146  1.1.18.1     yamt int	iic_smbus_write_word(i2c_tag_t, i2c_addr_t, uint8_t, uint16_t, int);
    147       1.1  thorpej int	iic_smbus_read_byte(i2c_tag_t, i2c_addr_t, uint8_t, uint8_t *, int);
    148  1.1.18.1     yamt int	iic_smbus_read_word(i2c_tag_t, i2c_addr_t, uint8_t, uint16_t *, int);
    149       1.1  thorpej int	iic_smbus_receive_byte(i2c_tag_t, i2c_addr_t, uint8_t *, int);
    150  1.1.18.1     yamt int	iic_smbus_send_byte(i2c_tag_t, i2c_addr_t, uint8_t, int);
    151  1.1.18.1     yamt int	iic_smbus_quick_read(i2c_tag_t, i2c_addr_t, int);
    152  1.1.18.1     yamt int	iic_smbus_quick_write(i2c_tag_t, i2c_addr_t, int);
    153  1.1.18.1     yamt int	iic_smbus_block_read(i2c_tag_t, i2c_addr_t, uint8_t, uint8_t *,
    154  1.1.18.1     yamt 	    size_t, int);
    155  1.1.18.1     yamt int	iic_smbus_block_write(i2c_tag_t, i2c_addr_t, uint8_t, uint8_t *,
    156  1.1.18.1     yamt 	    size_t, int);
    157       1.1  thorpej 
    158       1.1  thorpej #endif /* _DEV_I2C_I2CVAR_H_ */
    159