1 /* $OpenBSD: i2c.h,v 1.3 2021/07/07 02:38:36 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 #include <linux/acpi.h> 26 27 #include <dev/i2c/i2cvar.h> 28 29 struct i2c_algorithm; 30 31 #define I2C_FUNC_I2C 0 32 #define I2C_FUNC_SMBUS_EMUL 0 33 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0 34 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0 35 #define I2C_FUNC_10BIT_ADDR 0 36 37 struct i2c_lock_operations; 38 39 struct i2c_adapter { 40 struct i2c_controller ic; 41 42 char name[48]; 43 const struct i2c_algorithm *algo; 44 void *algo_data; 45 int retries; 46 const struct i2c_lock_operations *lock_ops; 47 48 void *data; 49 }; 50 51 struct i2c_lock_operations { 52 void (*lock_bus)(struct i2c_adapter *, unsigned int); 53 int (*trylock_bus)(struct i2c_adapter *, unsigned int); 54 void (*unlock_bus)(struct i2c_adapter *, unsigned int); 55 }; 56 57 #define I2C_NAME_SIZE 20 58 59 struct i2c_msg { 60 uint16_t addr; 61 uint16_t flags; 62 uint16_t len; 63 uint8_t *buf; 64 }; 65 66 #define I2C_M_RD 0x0001 67 #define I2C_M_NOSTART 0x0002 68 #define I2C_M_STOP 0x0004 69 70 struct i2c_algorithm { 71 int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *, int); 72 uint32_t (*functionality)(struct i2c_adapter *); 73 }; 74 75 extern struct i2c_algorithm i2c_bit_algo; 76 77 struct i2c_algo_bit_data { 78 struct i2c_controller ic; 79 }; 80 81 int i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int); 82 #define i2c_add_adapter(x) 0 83 #define i2c_del_adapter(x) 84 #define __i2c_transfer(adap, msgs, num) i2c_transfer(adap, msgs, num) 85 86 static inline void * 87 i2c_get_adapdata(struct i2c_adapter *adap) 88 { 89 return adap->data; 90 } 91 92 static inline void 93 i2c_set_adapdata(struct i2c_adapter *adap, void *data) 94 { 95 adap->data = data; 96 } 97 98 int i2c_bit_add_bus(struct i2c_adapter *); 99 100 #endif 101