Rev 1404 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1404 | Rev 1963 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright © 2009 Keith Packard |
2 | * Copyright © 2009 Keith Packard |
3 | * |
3 | * |
4 | * Permission to use, copy, modify, distribute, and sell this software and its |
4 | * Permission to use, copy, modify, distribute, and sell this software and its |
5 | * documentation for any purpose is hereby granted without fee, provided that |
5 | * documentation for any purpose is hereby granted without fee, provided that |
6 | * the above copyright notice appear in all copies and that both that copyright |
6 | * the above copyright notice appear in all copies and that both that copyright |
7 | * notice and this permission notice appear in supporting documentation, and |
7 | * notice and this permission notice appear in supporting documentation, and |
8 | * that the name of the copyright holders not be used in advertising or |
8 | * that the name of the copyright holders not be used in advertising or |
9 | * publicity pertaining to distribution of the software without specific, |
9 | * publicity pertaining to distribution of the software without specific, |
10 | * written prior permission. The copyright holders make no representations |
10 | * written prior permission. The copyright holders make no representations |
11 | * about the suitability of this software for any purpose. It is provided "as |
11 | * about the suitability of this software for any purpose. It is provided "as |
12 | * is" without express or implied warranty. |
12 | * is" without express or implied warranty. |
13 | * |
13 | * |
14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
20 | * OF THIS SOFTWARE. |
20 | * OF THIS SOFTWARE. |
21 | */ |
21 | */ |
22 | 22 | ||
23 | #include |
23 | #include |
24 | #include |
24 | #include |
25 | //#include |
25 | //#include |
26 | //#include |
- | |
27 | //#include |
26 | //#include |
28 | #include |
27 | #include |
29 | #include |
28 | #include |
30 | #include |
29 | #include |
31 | #include "drm_dp_helper.h" |
30 | #include "drm_dp_helper.h" |
32 | #include "drmP.h" |
31 | #include "drmP.h" |
33 | 32 | ||
34 | /* Run a single AUX_CH I2C transaction, writing/reading data as necessary */ |
33 | /* Run a single AUX_CH I2C transaction, writing/reading data as necessary */ |
35 | static int |
34 | static int |
36 | i2c_algo_dp_aux_transaction(struct i2c_adapter *adapter, int mode, |
35 | i2c_algo_dp_aux_transaction(struct i2c_adapter *adapter, int mode, |
37 | uint8_t write_byte, uint8_t *read_byte) |
36 | uint8_t write_byte, uint8_t *read_byte) |
38 | { |
37 | { |
39 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
38 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
40 | int ret; |
39 | int ret; |
41 | 40 | ||
42 | ret = (*algo_data->aux_ch)(adapter, mode, |
41 | ret = (*algo_data->aux_ch)(adapter, mode, |
43 | write_byte, read_byte); |
42 | write_byte, read_byte); |
44 | return ret; |
43 | return ret; |
45 | } |
44 | } |
46 | 45 | ||
47 | /* |
46 | /* |
48 | * I2C over AUX CH |
47 | * I2C over AUX CH |
49 | */ |
48 | */ |
50 | 49 | ||
51 | /* |
50 | /* |
52 | * Send the address. If the I2C link is running, this 'restarts' |
51 | * Send the address. If the I2C link is running, this 'restarts' |
53 | * the connection with the new address, this is used for doing |
52 | * the connection with the new address, this is used for doing |
54 | * a write followed by a read (as needed for DDC) |
53 | * a write followed by a read (as needed for DDC) |
55 | */ |
54 | */ |
56 | static int |
55 | static int |
57 | i2c_algo_dp_aux_address(struct i2c_adapter *adapter, u16 address, bool reading) |
56 | i2c_algo_dp_aux_address(struct i2c_adapter *adapter, u16 address, bool reading) |
58 | { |
57 | { |
59 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
58 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
60 | int mode = MODE_I2C_START; |
59 | int mode = MODE_I2C_START; |
61 | int ret; |
60 | int ret; |
62 | 61 | ||
63 | if (reading) |
62 | if (reading) |
64 | mode |= MODE_I2C_READ; |
63 | mode |= MODE_I2C_READ; |
65 | else |
64 | else |
66 | mode |= MODE_I2C_WRITE; |
65 | mode |= MODE_I2C_WRITE; |
67 | algo_data->address = address; |
66 | algo_data->address = address; |
68 | algo_data->running = true; |
67 | algo_data->running = true; |
69 | ret = i2c_algo_dp_aux_transaction(adapter, mode, 0, NULL); |
68 | ret = i2c_algo_dp_aux_transaction(adapter, mode, 0, NULL); |
70 | return ret; |
69 | return ret; |
71 | } |
70 | } |
72 | 71 | ||
73 | /* |
72 | /* |
74 | * Stop the I2C transaction. This closes out the link, sending |
73 | * Stop the I2C transaction. This closes out the link, sending |
75 | * a bare address packet with the MOT bit turned off |
74 | * a bare address packet with the MOT bit turned off |
76 | */ |
75 | */ |
77 | static void |
76 | static void |
78 | i2c_algo_dp_aux_stop(struct i2c_adapter *adapter, bool reading) |
77 | i2c_algo_dp_aux_stop(struct i2c_adapter *adapter, bool reading) |
79 | { |
78 | { |
80 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
79 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
81 | int mode = MODE_I2C_STOP; |
80 | int mode = MODE_I2C_STOP; |
82 | 81 | ||
83 | if (reading) |
82 | if (reading) |
84 | mode |= MODE_I2C_READ; |
83 | mode |= MODE_I2C_READ; |
85 | else |
84 | else |
86 | mode |= MODE_I2C_WRITE; |
85 | mode |= MODE_I2C_WRITE; |
87 | if (algo_data->running) { |
86 | if (algo_data->running) { |
88 | (void) i2c_algo_dp_aux_transaction(adapter, mode, 0, NULL); |
87 | (void) i2c_algo_dp_aux_transaction(adapter, mode, 0, NULL); |
89 | algo_data->running = false; |
88 | algo_data->running = false; |
90 | } |
89 | } |
91 | } |
90 | } |
92 | 91 | ||
93 | /* |
92 | /* |
94 | * Write a single byte to the current I2C address, the |
93 | * Write a single byte to the current I2C address, the |
95 | * the I2C link must be running or this returns -EIO |
94 | * the I2C link must be running or this returns -EIO |
96 | */ |
95 | */ |
97 | static int |
96 | static int |
98 | i2c_algo_dp_aux_put_byte(struct i2c_adapter *adapter, u8 byte) |
97 | i2c_algo_dp_aux_put_byte(struct i2c_adapter *adapter, u8 byte) |
99 | { |
98 | { |
100 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
99 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
101 | int ret; |
100 | int ret; |
102 | 101 | ||
103 | if (!algo_data->running) |
102 | if (!algo_data->running) |
104 | return -EIO; |
103 | return -EIO; |
105 | 104 | ||
106 | ret = i2c_algo_dp_aux_transaction(adapter, MODE_I2C_WRITE, byte, NULL); |
105 | ret = i2c_algo_dp_aux_transaction(adapter, MODE_I2C_WRITE, byte, NULL); |
107 | return ret; |
106 | return ret; |
108 | } |
107 | } |
109 | 108 | ||
110 | /* |
109 | /* |
111 | * Read a single byte from the current I2C address, the |
110 | * Read a single byte from the current I2C address, the |
112 | * I2C link must be running or this returns -EIO |
111 | * I2C link must be running or this returns -EIO |
113 | */ |
112 | */ |
114 | static int |
113 | static int |
115 | i2c_algo_dp_aux_get_byte(struct i2c_adapter *adapter, u8 *byte_ret) |
114 | i2c_algo_dp_aux_get_byte(struct i2c_adapter *adapter, u8 *byte_ret) |
116 | { |
115 | { |
117 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
116 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
118 | int ret; |
117 | int ret; |
119 | 118 | ||
120 | if (!algo_data->running) |
119 | if (!algo_data->running) |
121 | return -EIO; |
120 | return -EIO; |
122 | 121 | ||
123 | ret = i2c_algo_dp_aux_transaction(adapter, MODE_I2C_READ, 0, byte_ret); |
122 | ret = i2c_algo_dp_aux_transaction(adapter, MODE_I2C_READ, 0, byte_ret); |
124 | return ret; |
123 | return ret; |
125 | } |
124 | } |
126 | 125 | ||
127 | static int |
126 | static int |
128 | i2c_algo_dp_aux_xfer(struct i2c_adapter *adapter, |
127 | i2c_algo_dp_aux_xfer(struct i2c_adapter *adapter, |
129 | struct i2c_msg *msgs, |
128 | struct i2c_msg *msgs, |
130 | int num) |
129 | int num) |
131 | { |
130 | { |
132 | int ret = 0; |
131 | int ret = 0; |
133 | bool reading = false; |
132 | bool reading = false; |
134 | int m; |
133 | int m; |
135 | int b; |
134 | int b; |
136 | 135 | ||
137 | for (m = 0; m < num; m++) { |
136 | for (m = 0; m < num; m++) { |
138 | u16 len = msgs[m].len; |
137 | u16 len = msgs[m].len; |
139 | u8 *buf = msgs[m].buf; |
138 | u8 *buf = msgs[m].buf; |
140 | reading = (msgs[m].flags & I2C_M_RD) != 0; |
139 | reading = (msgs[m].flags & I2C_M_RD) != 0; |
141 | ret = i2c_algo_dp_aux_address(adapter, msgs[m].addr, reading); |
140 | ret = i2c_algo_dp_aux_address(adapter, msgs[m].addr, reading); |
142 | if (ret < 0) |
141 | if (ret < 0) |
143 | break; |
142 | break; |
144 | if (reading) { |
143 | if (reading) { |
145 | for (b = 0; b < len; b++) { |
144 | for (b = 0; b < len; b++) { |
146 | ret = i2c_algo_dp_aux_get_byte(adapter, &buf[b]); |
145 | ret = i2c_algo_dp_aux_get_byte(adapter, &buf[b]); |
147 | if (ret < 0) |
146 | if (ret < 0) |
148 | break; |
147 | break; |
149 | } |
148 | } |
150 | } else { |
149 | } else { |
151 | for (b = 0; b < len; b++) { |
150 | for (b = 0; b < len; b++) { |
152 | ret = i2c_algo_dp_aux_put_byte(adapter, buf[b]); |
151 | ret = i2c_algo_dp_aux_put_byte(adapter, buf[b]); |
153 | if (ret < 0) |
152 | if (ret < 0) |
154 | break; |
153 | break; |
155 | } |
154 | } |
156 | } |
155 | } |
157 | if (ret < 0) |
156 | if (ret < 0) |
158 | break; |
157 | break; |
159 | } |
158 | } |
160 | if (ret >= 0) |
159 | if (ret >= 0) |
161 | ret = num; |
160 | ret = num; |
162 | i2c_algo_dp_aux_stop(adapter, reading); |
161 | i2c_algo_dp_aux_stop(adapter, reading); |
163 | DRM_DEBUG_KMS("dp_aux_xfer return %d\n", ret); |
162 | DRM_DEBUG_KMS("dp_aux_xfer return %d\n", ret); |
164 | return ret; |
163 | return ret; |
165 | } |
164 | } |
166 | 165 | ||
167 | static u32 |
166 | static u32 |
168 | i2c_algo_dp_aux_functionality(struct i2c_adapter *adapter) |
167 | i2c_algo_dp_aux_functionality(struct i2c_adapter *adapter) |
169 | { |
168 | { |
170 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | |
169 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | |
171 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | |
170 | I2C_FUNC_SMBUS_READ_BLOCK_DATA | |
172 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | |
171 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL | |
173 | I2C_FUNC_10BIT_ADDR; |
172 | I2C_FUNC_10BIT_ADDR; |
174 | } |
173 | } |
175 | 174 | ||
176 | static const struct i2c_algorithm i2c_dp_aux_algo = { |
175 | static const struct i2c_algorithm i2c_dp_aux_algo = { |
177 | .master_xfer = i2c_algo_dp_aux_xfer, |
176 | .master_xfer = i2c_algo_dp_aux_xfer, |
178 | .functionality = i2c_algo_dp_aux_functionality, |
177 | .functionality = i2c_algo_dp_aux_functionality, |
179 | }; |
178 | }; |
180 | 179 | ||
181 | static void |
180 | static void |
182 | i2c_dp_aux_reset_bus(struct i2c_adapter *adapter) |
181 | i2c_dp_aux_reset_bus(struct i2c_adapter *adapter) |
183 | { |
182 | { |
184 | (void) i2c_algo_dp_aux_address(adapter, 0, false); |
183 | (void) i2c_algo_dp_aux_address(adapter, 0, false); |
185 | (void) i2c_algo_dp_aux_stop(adapter, false); |
184 | (void) i2c_algo_dp_aux_stop(adapter, false); |
186 | 185 | ||
187 | } |
186 | } |
188 | 187 | ||
189 | static int |
188 | static int |
190 | i2c_dp_aux_prepare_bus(struct i2c_adapter *adapter) |
189 | i2c_dp_aux_prepare_bus(struct i2c_adapter *adapter) |
191 | { |
190 | { |
192 | adapter->algo = &i2c_dp_aux_algo; |
191 | adapter->algo = &i2c_dp_aux_algo; |
193 | adapter->retries = 3; |
192 | adapter->retries = 3; |
194 | i2c_dp_aux_reset_bus(adapter); |
193 | i2c_dp_aux_reset_bus(adapter); |
195 | return 0; |
194 | return 0; |
196 | } |
195 | } |
197 | 196 | ||
198 | int |
197 | int |
199 | i2c_dp_aux_add_bus(struct i2c_adapter *adapter) |
198 | i2c_dp_aux_add_bus(struct i2c_adapter *adapter) |
200 | { |
199 | { |
201 | int error; |
200 | int error; |
202 | 201 | ||
203 | error = i2c_dp_aux_prepare_bus(adapter); |
202 | error = i2c_dp_aux_prepare_bus(adapter); |
204 | if (error) |
203 | if (error) |
205 | return error; |
204 | return error; |
206 | // error = i2c_add_adapter(adapter); |
205 | // error = i2c_add_adapter(adapter); |
207 | return error; |
206 | return error; |
208 | } |
207 | } |
209 | EXPORT_SYMBOL(i2c_dp_aux_add_bus);>>>>>>> |
208 | EXPORT_SYMBOL(i2c_dp_aux_add_bus);>>>>>>> |