1 /* $NetBSD: i2c.h,v 1.2 2014/03/18 18:20:43 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_adapter { 50 char name[I2C_NAME_SIZE]; 51 const struct i2c_algorithm *algo; 52 void *algo_data; 53 int retries; 54 struct module *owner; 55 unsigned int class; 56 struct { 57 device_t parent; 58 } dev; /* XXX Kludge for intel_dp. */ 59 }; 60 61 static inline int 62 i2c_add_adapter(struct i2c_adapter *adapter __unused) 63 { 64 return 0; 65 } 66 67 static inline void 68 i2c_del_adapter(struct i2c_adapter *adapter __unused) 69 { 70 } 71 72 struct i2c_msg { 73 i2c_addr_t addr; 74 uint16_t flags; 75 uint16_t len; 76 uint8_t *buf; 77 }; 78 79 #define I2C_M_RD 0x01 80 #define I2C_M_NOSTART 0x02 81 82 #define I2C_FUNC_I2C 0x01 83 #define I2C_FUNC_NOSTART 0x02 84 #define I2C_FUNC_SMBUS_EMUL 0x04 85 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x08 86 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x10 87 #define I2C_FUNC_10BIT_ADDR 0x20 88 89 struct i2c_algorithm { 90 int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *, 91 int); 92 uint32_t (*functionality)(struct i2c_adapter *); 93 }; 94 95 /* XXX Make the nm output a little more greppable... */ 96 #define i2c_transfer linux_i2c_transfer 97 98 int i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int); 99 100 #endif /* _LINUX_I2C_H_ */ 101