Home | History | Annotate | Line # | Download | only in linux
i2c.h revision 1.3
      1 /*	$NetBSD: i2c.h,v 1.3 2014/07/16 20:59:58 riastradh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Taylor R. Campbell.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _LINUX_I2C_H_
     33 #define _LINUX_I2C_H_
     34 
     35 #include <sys/types.h>
     36 #include <sys/device_if.h>
     37 #include <sys/queue.h>		/* XXX include order botch: i2cvar.h needs */
     38 
     39 #include <dev/i2c/i2cvar.h>
     40 
     41 struct i2c_adapter;
     42 struct i2c_algorithm;
     43 struct i2c_msg;
     44 
     45 #define	I2C_NAME_SIZE	20
     46 
     47 #define	I2C_CLASS_DDC	0x01
     48 
     49 struct i2c_board_info {
     50 	char			type[I2C_NAME_SIZE];
     51 	uint16_t		addr;
     52 };
     53 
     54 static inline void
     55 i2c_new_device(struct i2c_adapter *adapter __unused,
     56     struct i2c_board_info *board __unused)
     57 {
     58 }
     59 
     60 struct i2c_adapter {
     61 	char		 		name[I2C_NAME_SIZE];
     62 	const struct i2c_algorithm	*algo;
     63 	void				*algo_data;
     64 	int				retries;
     65 	struct module			*owner;
     66 	unsigned int			class;
     67 	struct {
     68 		device_t	parent;
     69 	}				dev;	/* XXX Kludge for intel_dp.  */
     70 	void				*i2ca_adapdata;
     71 };
     72 
     73 static inline int
     74 i2c_add_adapter(struct i2c_adapter *adapter __unused)
     75 {
     76 	return 0;
     77 }
     78 
     79 static inline void
     80 i2c_del_adapter(struct i2c_adapter *adapter __unused)
     81 {
     82 }
     83 
     84 static inline void *
     85 i2c_get_adapdata(const struct i2c_adapter *adapter)
     86 {
     87 
     88 	return adapter->i2ca_adapdata;
     89 }
     90 
     91 static inline void
     92 i2c_set_adapdata(struct i2c_adapter *adapter, void *data)
     93 {
     94 
     95 	adapter->i2ca_adapdata = data;
     96 }
     97 
     98 struct i2c_msg {
     99 	i2c_addr_t	addr;
    100 	uint16_t	flags;
    101 	uint16_t	len;
    102 	uint8_t		*buf;
    103 };
    104 
    105 #define	I2C_M_RD		0x01
    106 #define	I2C_M_NOSTART		0x02
    107 
    108 #define	I2C_FUNC_I2C			0x01
    109 #define	I2C_FUNC_NOSTART		0x02
    110 #define	I2C_FUNC_SMBUS_EMUL		0x04
    111 #define	I2C_FUNC_SMBUS_READ_BLOCK_DATA	0x08
    112 #define	I2C_FUNC_SMBUS_BLOCK_PROC_CALL	0x10
    113 #define	I2C_FUNC_10BIT_ADDR		0x20
    114 
    115 struct i2c_algorithm {
    116 	int		(*master_xfer)(struct i2c_adapter *, struct i2c_msg *,
    117 			    int);
    118 	uint32_t	(*functionality)(struct i2c_adapter *);
    119 };
    120 
    121 /* XXX Make the nm output a little more greppable...  */
    122 #define	i2c_transfer	linux_i2c_transfer
    123 
    124 int	i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int);
    125 
    126 #endif  /* _LINUX_I2C_H_ */
    127