summaryrefslogtreecommitdiff
path: root/sys/external/bsd/drm2/include/linux/i2c.h
blob: 03079506e1ad949b3d3567dcd8ea285d68a29a2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*	$NetBSD: i2c.h,v 1.14 2021/12/19 11:49:12 riastradh Exp $	*/

/*-
 * Copyright (c) 2015 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Taylor R. Campbell.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _LINUX_I2C_H_
#define _LINUX_I2C_H_

#include <sys/types.h>
#include <sys/device_if.h>
#include <sys/queue.h>		/* XXX include order botch: i2cvar.h needs */
#include <sys/systm.h>

#include <dev/i2c/i2cvar.h>

#include <linux/pm.h>
#include <linux/module.h>
#include <linux/mutex.h>

struct i2c_adapter;
struct i2c_algorithm;
struct i2c_msg;

#define	I2C_NAME_SIZE	20

/*
 * I2C_M_*: i2c_msg flags
 */
#define	I2C_M_RD		0x01 /* xfer is read, not write */
#define	I2C_M_NOSTART		0x02 /* don't initiate xfer */
#define	I2C_M_TEN		0x04 /* 10-bit chip address */
#define	I2C_M_STOP		0x08 /* send stop after msg */

/*
 * I2C_CLASS_*: i2c_adapter classes
 */
#define	I2C_CLASS_DDC	0x01
#define	I2C_CLASS_SPD	0x02

/*
 * I2C_FUNC_*: i2c_adapter functionality bits
 */
#define	I2C_FUNC_I2C			0x01
#define	I2C_FUNC_NOSTART		0x02
#define	I2C_FUNC_SMBUS_EMUL		0x04
#define	I2C_FUNC_SMBUS_READ_BLOCK_DATA	0x08
#define	I2C_FUNC_SMBUS_BLOCK_PROC_CALL	0x10
#define	I2C_FUNC_10BIT_ADDR		0x20

/*
 * struct i2c_msg: A single i2c message request on a particular
 * address.  Read if I2C_M_RD is set, write otherwise.
 */
struct i2c_msg {
	i2c_addr_t	addr;
	uint16_t	flags;	/* I2C_M_* */
	uint16_t	len;
	uint8_t		*buf;
};

/*
 * struct i2c_adapter: An i2c bus controller.
 */
struct i2c_adapter {
	char		 		name[I2C_NAME_SIZE];
	const struct i2c_algorithm	*algo;
	void				*algo_data;
	const struct i2c_lock_operations *lock_ops;
	int				retries;
	struct module			*owner;
	unsigned int			class; /* I2C_CLASS_* */
	struct {
		device_t	parent;
	}				dev;
	void				*i2ca_adapdata;
};

/*
 * struct i2c_algorithm: A procedure for transferring an i2c message on
 * an i2c bus, along with a set of flags describing its functionality.
 */
struct i2c_algorithm {
	int		(*master_xfer)(struct i2c_adapter *, struct i2c_msg *,
			    int);
	uint32_t	(*functionality)(struct i2c_adapter *);
};

/*
 * struct i2c_lock_operations: i2c bus lock operations.
 */
struct i2c_lock_operations {
	void	(*lock_bus)(struct i2c_adapter *, unsigned);
	int	(*trylock_bus)(struct i2c_adapter *, unsigned);
	void	(*unlock_bus)(struct i2c_adapter *, unsigned);
};

/*
 * struct i2c_board_info: Parameters to find an i2c bus and a slave on
 * it.  type is the name of an i2c driver; addr is the slave address;
 * platform_data is an extra parameter to pass to the i2c driver.
 */
struct i2c_board_info {
	char			type[I2C_NAME_SIZE];
	uint16_t		addr;
	uint16_t		flags;
	void			*platform_data;
};

#define	I2C_BOARD_INFO(board_type, board_addr)		\
	.type = (board_type),				\
	.addr = (board_addr)

/*
 * struct i2c_client: An i2c slave device at a particular address on a
 * particular bus.
 */
struct i2c_client {
	struct i2c_adapter	*adapter;
	uint16_t		addr;
	uint16_t		flags;
};

/*
 * struct i2c_device_id: Device id naming a class of i2c slave devices
 * and parameters to the driver for the devices.
 */
struct i2c_device_id {
	char		name[I2C_NAME_SIZE];
	unsigned long	driver_data;
};

/*
 * struct i2c_driver: A driver for a class of i2c slave devices.  We
 * don't actually use this.
 */
struct i2c_driver {
	int	(*probe)(struct i2c_client *, const struct i2c_device_id *);
	int	(*remove)(struct i2c_client *);
	struct {
		char			name[I2C_NAME_SIZE];
		const struct dev_pm_ops	pm;
	}	driver;
};

/*
 * Adapter management.  We don't register these in a global database
 * like Linux, so these are just stubs.
 */
static inline int
i2c_add_adapter(struct i2c_adapter *adapter __unused)
{

	return 0;
}

static inline void
i2c_del_adapter(struct i2c_adapter *adapter __unused)
{
}

static inline void *
i2c_get_adapdata(const struct i2c_adapter *adapter)
{

	return adapter->i2ca_adapdata;
}

static inline void
i2c_set_adapdata(struct i2c_adapter *adapter, void *data)
{

	adapter->i2ca_adapdata = data;
}

/* XXX Make the nm output a little more greppable...  */
#define	__i2c_transfer		linux___i2c_transfer
#define	i2c_master_recv		linux_i2c_master_recv
#define	i2c_master_send		linux_i2c_master_send
#define	i2c_new_device		linux_i2c_new_device
#define	i2c_transfer		linux_i2c_transfer
#define	i2c_unregister_device	linux_i2c_unregister_device

int	i2c_master_send(const struct i2c_client *, const char *, int);
int	i2c_master_recv(const struct i2c_client *, char *, int);
struct i2c_client *
	i2c_new_device(struct i2c_adapter *, const struct i2c_board_info *);
int	__i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int);
int	i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int);
void	i2c_unregister_device(struct i2c_client *);

#endif  /* _LINUX_I2C_H_ */