xref: /freebsd/sys/dev/iicbus/iic.h (revision efce3748f32e713bcb1fba45b021e843760e6fac)
1*efce3748SRui Paulo /*-
2*efce3748SRui Paulo  * Copyright (c) 1998 Nicolas Souchu
3*efce3748SRui Paulo  * All rights reserved.
4*efce3748SRui Paulo  *
5*efce3748SRui Paulo  * Redistribution and use in source and binary forms, with or without
6*efce3748SRui Paulo  * modification, are permitted provided that the following conditions
7*efce3748SRui Paulo  * are met:
8*efce3748SRui Paulo  * 1. Redistributions of source code must retain the above copyright
9*efce3748SRui Paulo  *    notice, this list of conditions and the following disclaimer.
10*efce3748SRui Paulo  * 2. Redistributions in binary form must reproduce the above copyright
11*efce3748SRui Paulo  *    notice, this list of conditions and the following disclaimer in the
12*efce3748SRui Paulo  *    documentation and/or other materials provided with the distribution.
13*efce3748SRui Paulo  *
14*efce3748SRui Paulo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*efce3748SRui Paulo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*efce3748SRui Paulo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*efce3748SRui Paulo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*efce3748SRui Paulo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*efce3748SRui Paulo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*efce3748SRui Paulo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*efce3748SRui Paulo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*efce3748SRui Paulo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*efce3748SRui Paulo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*efce3748SRui Paulo  * SUCH DAMAGE.
25*efce3748SRui Paulo  *
26*efce3748SRui Paulo  * $FreeBSD$
27*efce3748SRui Paulo  *
28*efce3748SRui Paulo  */
29*efce3748SRui Paulo #ifndef __IIC_H
30*efce3748SRui Paulo #define __IIC_H
31*efce3748SRui Paulo 
32*efce3748SRui Paulo #include <sys/ioccom.h>
33*efce3748SRui Paulo 
34*efce3748SRui Paulo /* Designed to be compatible with linux's struct i2c_msg */
35*efce3748SRui Paulo struct iic_msg
36*efce3748SRui Paulo {
37*efce3748SRui Paulo 	uint16_t	slave;
38*efce3748SRui Paulo 	uint16_t	flags;
39*efce3748SRui Paulo #define	IIC_M_WR	0	/* Fake flag for write */
40*efce3748SRui Paulo #define	IIC_M_RD	0x0001	/* read vs write */
41*efce3748SRui Paulo #define	IIC_M_NOSTOP	0x0002	/* do not send a I2C stop after message */
42*efce3748SRui Paulo #define	IIC_M_NOSTART	0x0004	/* do not send a I2C start before message */
43*efce3748SRui Paulo 	uint16_t	len;	/* msg length */
44*efce3748SRui Paulo 	uint8_t *	buf;
45*efce3748SRui Paulo };
46*efce3748SRui Paulo 
47*efce3748SRui Paulo struct iiccmd {
48*efce3748SRui Paulo 	u_char slave;
49*efce3748SRui Paulo 	int count;
50*efce3748SRui Paulo 	int last;
51*efce3748SRui Paulo 	char *buf;
52*efce3748SRui Paulo };
53*efce3748SRui Paulo 
54*efce3748SRui Paulo struct iic_rdwr_data {
55*efce3748SRui Paulo 	struct iic_msg *msgs;
56*efce3748SRui Paulo 	uint32_t nmsgs;
57*efce3748SRui Paulo };
58*efce3748SRui Paulo 
59*efce3748SRui Paulo #define I2CSTART	_IOW('i', 1, struct iiccmd)	/* start condition */
60*efce3748SRui Paulo #define I2CSTOP		_IO('i', 2)			/* stop condition */
61*efce3748SRui Paulo #define I2CRSTCARD	_IOW('i', 3, struct iiccmd)	/* reset the card */
62*efce3748SRui Paulo #define I2CWRITE	_IOW('i', 4, struct iiccmd)	/* send data */
63*efce3748SRui Paulo #define I2CREAD		_IOW('i', 5, struct iiccmd)	/* receive data */
64*efce3748SRui Paulo #define I2CRDWR		_IOW('i', 6, struct iic_rdwr_data)	/* General read/write interface */
65*efce3748SRui Paulo #define I2CRPTSTART	_IOW('i', 7, struct iiccmd)	/* repeated start */
66*efce3748SRui Paulo 
67*efce3748SRui Paulo #endif
68