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