1 /* $OpenBSD: i2c.h,v 1.6 2022/03/01 11:50:37 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 #define I2C_AQ_COMB 0 38 #define I2C_AQ_COMB_SAME_ADDR 0 39 #define I2C_AQ_NO_ZERO_LEN 0 40 41 struct i2c_lock_operations; 42 43 struct i2c_adapter_quirks { 44 unsigned int flags; 45 uint16_t max_read_len; 46 uint16_t max_write_len; 47 uint16_t max_comb_1st_msg_len; 48 uint16_t max_comb_2nd_msg_len; 49 }; 50 51 struct i2c_adapter { 52 struct i2c_controller ic; 53 54 char name[48]; 55 const struct i2c_algorithm *algo; 56 void *algo_data; 57 int retries; 58 const struct i2c_lock_operations *lock_ops; 59 const struct i2c_adapter_quirks *quirks; 60 61 void *data; 62 }; 63 64 struct i2c_lock_operations { 65 void (*lock_bus)(struct i2c_adapter *, unsigned int); 66 int (*trylock_bus)(struct i2c_adapter *, unsigned int); 67 void (*unlock_bus)(struct i2c_adapter *, unsigned int); 68 }; 69 70 #define I2C_NAME_SIZE 20 71 72 struct i2c_msg { 73 uint16_t addr; 74 uint16_t flags; 75 uint16_t len; 76 uint8_t *buf; 77 }; 78 79 #define I2C_M_RD 0x0001 80 #define I2C_M_NOSTART 0x0002 81 #define I2C_M_STOP 0x0004 82 83 struct i2c_algorithm { 84 int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *, int); 85 uint32_t (*functionality)(struct i2c_adapter *); 86 }; 87 88 extern struct i2c_algorithm i2c_bit_algo; 89 90 struct i2c_algo_bit_data { 91 struct i2c_controller ic; 92 }; 93 94 int __i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int); 95 int i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int); 96 97 static inline int 98 i2c_add_adapter(struct i2c_adapter *adap) 99 { 100 return 0; 101 } 102 103 static inline void 104 i2c_del_adapter(struct i2c_adapter *adap) 105 { 106 } 107 108 static inline void * 109 i2c_get_adapdata(struct i2c_adapter *adap) 110 { 111 return adap->data; 112 } 113 114 static inline void 115 i2c_set_adapdata(struct i2c_adapter *adap, void *data) 116 { 117 adap->data = data; 118 } 119 120 int i2c_bit_add_bus(struct i2c_adapter *); 121 122 #endif 123