1 /* $OpenBSD: i2c.h,v 1.2 2020/06/08 04:48:14 jsg Exp $ */ 2 /* 3 * Copyright (c) 2017 Mark Kettenis 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _LINUX_I2C_H 19 #define _LINUX_I2C_H 20 21 #include <sys/stdint.h> 22 #include <sys/rwlock.h> 23 #include <linux/workqueue.h> 24 #include <linux/seq_file.h> 25 26 #include <dev/i2c/i2cvar.h> 27 28 struct i2c_algorithm; 29 30 #define I2C_FUNC_I2C 0 31 #define I2C_FUNC_SMBUS_EMUL 0 32 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0 33 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0 34 #define I2C_FUNC_10BIT_ADDR 0 35 36 struct i2c_lock_operations; 37 38 struct i2c_adapter { 39 struct i2c_controller ic; 40 41 char name[48]; 42 const struct i2c_algorithm *algo; 43 void *algo_data; 44 int retries; 45 const struct i2c_lock_operations *lock_ops; 46 47 void *data; 48 }; 49 50 struct i2c_lock_operations { 51 void (*lock_bus)(struct i2c_adapter *, unsigned int); 52 int (*trylock_bus)(struct i2c_adapter *, unsigned int); 53 void (*unlock_bus)(struct i2c_adapter *, unsigned int); 54 }; 55 56 #define I2C_NAME_SIZE 20 57 58 struct i2c_msg { 59 uint16_t addr; 60 uint16_t flags; 61 uint16_t len; 62 uint8_t *buf; 63 }; 64 65 #define I2C_M_RD 0x0001 66 #define I2C_M_NOSTART 0x0002 67 #define I2C_M_STOP 0x0004 68 69 struct i2c_algorithm { 70 int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *, int); 71 uint32_t (*functionality)(struct i2c_adapter *); 72 }; 73 74 extern struct i2c_algorithm i2c_bit_algo; 75 76 struct i2c_algo_bit_data { 77 struct i2c_controller ic; 78 }; 79 80 int i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int); 81 #define i2c_add_adapter(x) 0 82 #define i2c_del_adapter(x) 83 #define __i2c_transfer(adap, msgs, num) i2c_transfer(adap, msgs, num) 84 85 static inline void * 86 i2c_get_adapdata(struct i2c_adapter *adap) 87 { 88 return adap->data; 89 } 90 91 static inline void 92 i2c_set_adapdata(struct i2c_adapter *adap, void *data) 93 { 94 adap->data = data; 95 } 96 97 int i2c_bit_add_bus(struct i2c_adapter *); 98 99 #endif 100