xref: /openbsd-src/sys/dev/pci/drm/include/linux/i2c.h (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1 /*	$OpenBSD: i2c.h,v 1.1 2019/04/14 10:14:53 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_adapter {
37 	struct i2c_controller ic;
38 
39 	char name[48];
40 	const struct i2c_algorithm *algo;
41 	void *algo_data;
42 	int retries;
43 
44 	void *data;
45 };
46 
47 #define I2C_NAME_SIZE	20
48 
49 struct i2c_msg {
50 	uint16_t addr;
51 	uint16_t flags;
52 	uint16_t len;
53 	uint8_t *buf;
54 };
55 
56 #define I2C_M_RD	0x0001
57 #define I2C_M_NOSTART	0x0002
58 #define I2C_M_STOP	0x0004
59 
60 struct i2c_algorithm {
61 	int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *, int);
62 	uint32_t (*functionality)(struct i2c_adapter *);
63 };
64 
65 extern struct i2c_algorithm i2c_bit_algo;
66 
67 struct i2c_algo_bit_data {
68 	struct i2c_controller ic;
69 };
70 
71 int i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int);
72 #define i2c_add_adapter(x) 0
73 #define i2c_del_adapter(x)
74 #define __i2c_transfer(adap, msgs, num)	i2c_transfer(adap, msgs, num)
75 
76 static inline void *
77 i2c_get_adapdata(struct i2c_adapter *adap)
78 {
79 	return adap->data;
80 }
81 
82 static inline void
83 i2c_set_adapdata(struct i2c_adapter *adap, void *data)
84 {
85 	adap->data = data;
86 }
87 
88 int i2c_bit_add_bus(struct i2c_adapter *);
89 
90 #endif
91