i2c.h revision 1.6 1 /* $NetBSD: i2c.h,v 1.6 2014/08/23 08:03: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 #define I2C_BOARD_INFO(board_type, board_addr) \
56 .type = (board_type), \
57 .addr = (board_addr)
58
59 static inline void
60 i2c_new_device(const struct i2c_adapter *adapter __unused,
61 const struct i2c_board_info *board __unused)
62 {
63 }
64
65 struct i2c_driver {
66 };
67
68 struct module;
69 static inline int
70 i2c_register_driver(const struct module *owner __unused,
71 const struct i2c_driver *driver __unused)
72 {
73 return 0;
74 }
75
76 static inline void
77 i2c_del_driver(const struct i2c_driver *driver __unused)
78 {
79 }
80
81 struct i2c_client;
82
83 struct i2c_adapter {
84 char name[I2C_NAME_SIZE];
85 const struct i2c_algorithm *algo;
86 void *algo_data;
87 int retries;
88 struct module *owner;
89 unsigned int class;
90 struct {
91 device_t parent;
92 } dev; /* XXX Kludge for intel_dp. */
93 void *i2ca_adapdata;
94 };
95
96 static inline int
97 i2c_add_adapter(struct i2c_adapter *adapter __unused)
98 {
99 return 0;
100 }
101
102 static inline void
103 i2c_del_adapter(struct i2c_adapter *adapter __unused)
104 {
105 }
106
107 static inline void *
108 i2c_get_adapdata(const struct i2c_adapter *adapter)
109 {
110
111 return adapter->i2ca_adapdata;
112 }
113
114 static inline void
115 i2c_set_adapdata(struct i2c_adapter *adapter, void *data)
116 {
117
118 adapter->i2ca_adapdata = data;
119 }
120
121 struct i2c_msg {
122 i2c_addr_t addr;
123 uint16_t flags;
124 uint16_t len;
125 uint8_t *buf;
126 };
127
128 #define I2C_M_RD 0x01
129 #define I2C_M_NOSTART 0x02
130
131 #define I2C_FUNC_I2C 0x01
132 #define I2C_FUNC_NOSTART 0x02
133 #define I2C_FUNC_SMBUS_EMUL 0x04
134 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x08
135 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x10
136 #define I2C_FUNC_10BIT_ADDR 0x20
137
138 struct i2c_algorithm {
139 int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *,
140 int);
141 uint32_t (*functionality)(struct i2c_adapter *);
142 };
143
144 /* XXX Make the nm output a little more greppable... */
145 #define i2c_transfer linux_i2c_transfer
146
147 int i2c_transfer(struct i2c_adapter *, struct i2c_msg *, int);
148
149 #endif /* _LINUX_I2C_H_ */
150