iiconf.h revision 42442
1250379Strociny/*- 2250379Strociny * Copyright (c) 1998 Nicolas Souchu 3250379Strociny * All rights reserved. 4250379Strociny * 5250379Strociny * Redistribution and use in source and binary forms, with or without 6250379Strociny * modification, are permitted provided that the following conditions 7250379Strociny * are met: 8250379Strociny * 1. Redistributions of source code must retain the above copyright 9250379Strociny * notice, this list of conditions and the following disclaimer. 10250379Strociny * 2. Redistributions in binary form must reproduce the above copyright 11250379Strociny * notice, this list of conditions and the following disclaimer in the 12250379Strociny * documentation and/or other materials provided with the distribution. 13250379Strociny * 14250379Strociny * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15250379Strociny * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16250379Strociny * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17250379Strociny * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18250379Strociny * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19250379Strociny * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20250379Strociny * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21250379Strociny * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22250379Strociny * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23250379Strociny * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24250379Strociny * SUCH DAMAGE. 25250379Strociny * 26250379Strociny * $Id: iiconf.h,v 1.2 1998/10/31 11:31:07 nsouch Exp $ 27250379Strociny */ 28250379Strociny#ifndef __IICONF_H 29250379Strociny#define __IICONF_H 30250379Strociny 31250379Strociny#include <sys/queue.h> 32250379Strociny 33250379Strociny#define IICPRI PZERO+8 /* XXX sleep/wakeup queue priority */ 34250379Strociny 35250379Strociny#define n(flags) (~(flags) & (flags)) 36250379Strociny 37250379Strociny#define LSB 0x1 38250379Strociny 39250379Strociny/* 40250379Strociny * How tsleep() is called in iic_request_bus(). 41250379Strociny */ 42250379Strociny#define IIC_DONTWAIT 0 43250379Strociny#define IIC_NOINTR 0 44250379Strociny#define IIC_WAIT 0x1 45250379Strociny#define IIC_INTR 0x2 46250379Strociny 47250379Strociny/* 48250379Strociny * i2c modes 49250379Strociny */ 50250379Strociny#define IIC_MASTER 0x1 51250379Strociny#define IIC_SLAVE 0x2 52250379Strociny#define IIC_POLLED 0x4 53250379Strociny 54250379Strociny/* 55250379Strociny * i2c speed 56250379Strociny */ 57250379Strociny#define IIC_UNKNOWN 0x0 58250379Strociny#define IIC_SLOW 0x1 59250379Strociny#define IIC_FAST 0x2 60250379Strociny#define IIC_FASTEST 0x3 61250379Strociny 62252820Strociny#define IIC_LAST_READ 0x1 63260413Strociny 64260413Strociny/* 65260413Strociny * callback index 66260413Strociny */ 67260413Strociny#define IIC_REQUEST_BUS 0x1 68250379Strociny#define IIC_RELEASE_BUS 0x2 69250379Strociny 70250379Strociny/* 71250379Strociny * interrupt events 72250379Strociny */ 73250379Strociny#define INTR_GENERAL 0x1 /* general call received */ 74250379Strociny#define INTR_START 0x2 /* the I2C interface is addressed */ 75250379Strociny#define INTR_STOP 0x3 /* stop condition received */ 76250379Strociny#define INTR_RECEIVE 0x4 /* character received */ 77#define INTR_TRANSMIT 0x5 /* character to transmit */ 78#define INTR_ERROR 0x6 /* error */ 79#define INTR_NOACK 0x7 /* no ack from master receiver */ 80 81/* 82 * adapter layer errors 83 */ 84#define IIC_NOERR 0x0 /* no error occured */ 85#define IIC_EBUSERR 0x1 /* bus error */ 86#define IIC_ENOACK 0x2 /* ack not received until timeout */ 87#define IIC_ETIMEOUT 0x3 /* timeout */ 88#define IIC_EBUSBSY 0x4 /* bus busy */ 89#define IIC_ESTATUS 0x5 /* status error */ 90#define IIC_EUNDERFLOW 0x6 /* slave ready for more data */ 91#define IIC_EOVERFLOW 0x7 /* too much data */ 92#define IIC_ENOTSUPP 0x8 /* request not supported */ 93#define IIC_ENOADDR 0x9 /* no address assigned to the interface */ 94 95/* 96 * ivars codes 97 */ 98#define IICBUS_IVAR_ADDR 0x1 /* I2C address of the device */ 99 100extern int iicbus_request_bus(device_t, device_t, int); 101extern int iicbus_release_bus(device_t, device_t); 102extern device_t iicbus_alloc_bus(device_t); 103 104extern void iicbus_intr(device_t, int, char *); 105 106extern int iicbus_null_repeated_start(device_t, u_char); 107extern int iicbus_null_callback(device_t, int, caddr_t); 108 109#define iicbus_repeated_start(bus,slave,timeout) \ 110 (IICBUS_REPEATED_START(device_get_parent(bus), slave, timeout)) 111#define iicbus_reset(bus,speed,addr,oldaddr) \ 112 (IICBUS_RESET(device_get_parent(bus), speed, addr, oldaddr)) 113 114/* basic I2C operations */ 115extern int iicbus_started(device_t); 116extern int iicbus_start(device_t, u_char, int); 117extern int iicbus_stop(device_t); 118extern int iicbus_write(device_t, char *, int, int *, int); 119extern int iicbus_read(device_t, char *, int, int *, int, int); 120 121/* Read/write operations with start/stop conditions managed */ 122extern int iicbus_block_write(device_t, u_char, char *, int, int *); 123extern int iicbus_block_read(device_t, u_char, char *, int, int *); 124 125extern u_char iicbus_get_addr(device_t); 126 127#endif 128