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