xref: /netbsd-src/sys/external/bsd/drm2/include/linux/i2c.h (revision f14316bcbc544b96a93e884bc5c2b15fd60e22ae)
1 /*	$NetBSD: i2c.h,v 1.5 2014/08/06 15:01:33 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2013 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Taylor R. Campbell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LINUX_I2C_H_
33 #define _LINUX_I2C_H_
34 
35 #include <sys/types.h>
36 #include <sys/device_if.h>
37 #include <sys/queue.h>		/* XXX include order botch: i2cvar.h needs */
38 
39 #include <dev/i2c/i2cvar.h>
40 
41 struct i2c_adapter;
42 struct i2c_algorithm;
43 struct i2c_msg;
44 
45 #define	I2C_NAME_SIZE	20
46 
47 #define	I2C_CLASS_DDC	0x01
48 
49 struct i2c_board_info {
50 	char			type[I2C_NAME_SIZE];
51 	uint16_t		addr;
52 	void			*platform_data;
53 };
54 
55 static inline void
56 i2c_new_device(const struct i2c_adapter *adapter __unused,
57     const struct i2c_board_info *board __unused)
58 {
59 }
60 
61 struct i2c_driver {
62 };
63 
64 struct module;
65 static inline int
66 i2c_register_driver(const struct module *owner __unused,
67     const struct i2c_driver *driver __unused)
68 {
69 	return 0;
70 }
71 
72 static inline void
73 i2c_del_driver(const struct i2c_driver *driver __unused)
74 {
75 }
76 
77 struct i2c_client;
78 
79 struct i2c_adapter {
80 	char		 		name[I2C_NAME_SIZE];
81 	const struct i2c_algorithm	*algo;
82 	void				*algo_data;
83 	int				retries;
84 	struct module			*owner;
85 	unsigned int			class;
86 	struct {
87 		device_t	parent;
88 	}				dev;	/* XXX Kludge for intel_dp.  */
89 	void				*i2ca_adapdata;
90 };
91 
92 static inline int
93 i2c_add_adapter(struct i2c_adapter *adapter __unused)
94 {
95 	return 0;
96 }
97 
98 static inline void
99 i2c_del_adapter(struct i2c_adapter *adapter __unused)
100 {
101 }
102 
103 static inline void *
104 i2c_get_adapdata(const struct i2c_adapter *adapter)
105 {
106 
107 	return adapter->i2ca_adapdata;
108 }
109 
110 static inline void
111 i2c_set_adapdata(struct i2c_adapter *adapter, void *data)
112 {
113 
114 	adapter->i2ca_adapdata = data;
115 }
116 
117 struct i2c_msg {
118 	i2c_addr_t	addr;
119 	uint16_t	flags;
120 	uint16_t	len;
121 	uint8_t		*buf;
122 };
123 
124 #define	I2C_M_RD		0x01
125 #define	I2C_M_NOSTART		0x02
126 
127 #define	I2C_FUNC_I2C			0x01
128 #define	I2C_FUNC_NOSTART		0x02
129 #define	I2C_FUNC_SMBUS_EMUL		0x04
130 #define	I2C_FUNC_SMBUS_READ_BLOCK_DATA	0x08
131 #define	I2C_FUNC_SMBUS_BLOCK_PROC_CALL	0x10
132 #define	I2C_FUNC_10BIT_ADDR		0x20
133 
134 struct i2c_algorithm {
135 	int		(*master_xfer)(struct i2c_adapter *, struct i2c_msg *,
136 			    int);
137 	uint32_t	(*functionality)(struct i2c_adapter *);
138 };
139 
140 /* XXX Make the nm output a little more greppable...  */
141 #define	i2c_transfer	linux_i2c_transfer
142 
143 int	i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int);
144 
145 #endif  /* _LINUX_I2C_H_ */
146