b82c061f205a0c6888986c9705d4c6454fe46390
[sfrench/cifs-2.6.git] / drivers / acpi / acpica / rsserial.c
1 /*******************************************************************************
2  *
3  * Module Name: rsserial - GPIO/serial_bus resource descriptors
4  *
5  ******************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2016, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acresrc.h"
47
48 #define _COMPONENT          ACPI_RESOURCES
49 ACPI_MODULE_NAME("rsserial")
50
51 /*******************************************************************************
52  *
53  * acpi_rs_convert_gpio
54  *
55  ******************************************************************************/
56 struct acpi_rsconvert_info acpi_rs_convert_gpio[18] = {
57         {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_GPIO,
58          ACPI_RS_SIZE(struct acpi_resource_gpio),
59          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_gpio)},
60
61         {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_GPIO,
62          sizeof(struct aml_resource_gpio),
63          0},
64
65         /*
66          * These fields are contiguous in both the source and destination:
67          * revision_id
68          * connection_type
69          */
70         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.gpio.revision_id),
71          AML_OFFSET(gpio.revision_id),
72          2},
73
74         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.gpio.producer_consumer),
75          AML_OFFSET(gpio.flags),
76          0},
77
78         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.gpio.sharable),
79          AML_OFFSET(gpio.int_flags),
80          3},
81
82         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.gpio.wake_capable),
83          AML_OFFSET(gpio.int_flags),
84          4},
85
86         {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.gpio.io_restriction),
87          AML_OFFSET(gpio.int_flags),
88          0},
89
90         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.gpio.triggering),
91          AML_OFFSET(gpio.int_flags),
92          0},
93
94         {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.gpio.polarity),
95          AML_OFFSET(gpio.int_flags),
96          1},
97
98         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.gpio.pin_config),
99          AML_OFFSET(gpio.pin_config),
100          1},
101
102         /*
103          * These fields are contiguous in both the source and destination:
104          * drive_strength
105          * debounce_timeout
106          */
107         {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.gpio.drive_strength),
108          AML_OFFSET(gpio.drive_strength),
109          2},
110
111         /* Pin Table */
112
113         {ACPI_RSC_COUNT_GPIO_PIN, ACPI_RS_OFFSET(data.gpio.pin_table_length),
114          AML_OFFSET(gpio.pin_table_offset),
115          AML_OFFSET(gpio.res_source_offset)},
116
117         {ACPI_RSC_MOVE_GPIO_PIN, ACPI_RS_OFFSET(data.gpio.pin_table),
118          AML_OFFSET(gpio.pin_table_offset),
119          0},
120
121         /* Resource Source */
122
123         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.gpio.resource_source.index),
124          AML_OFFSET(gpio.res_source_index),
125          1},
126
127         {ACPI_RSC_COUNT_GPIO_RES,
128          ACPI_RS_OFFSET(data.gpio.resource_source.string_length),
129          AML_OFFSET(gpio.res_source_offset),
130          AML_OFFSET(gpio.vendor_offset)},
131
132         {ACPI_RSC_MOVE_GPIO_RES,
133          ACPI_RS_OFFSET(data.gpio.resource_source.string_ptr),
134          AML_OFFSET(gpio.res_source_offset),
135          0},
136
137         /* Vendor Data */
138
139         {ACPI_RSC_COUNT_GPIO_VEN, ACPI_RS_OFFSET(data.gpio.vendor_length),
140          AML_OFFSET(gpio.vendor_length),
141          1},
142
143         {ACPI_RSC_MOVE_GPIO_RES, ACPI_RS_OFFSET(data.gpio.vendor_data),
144          AML_OFFSET(gpio.vendor_offset),
145          0},
146 };
147
148 /*******************************************************************************
149  *
150  * acpi_rs_convert_i2c_serial_bus
151  *
152  ******************************************************************************/
153
154 struct acpi_rsconvert_info acpi_rs_convert_i2c_serial_bus[17] = {
155         {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_SERIAL_BUS,
156          ACPI_RS_SIZE(struct acpi_resource_i2c_serialbus),
157          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_i2c_serial_bus)},
158
159         {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_SERIAL_BUS,
160          sizeof(struct aml_resource_i2c_serialbus),
161          0},
162
163         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.common_serial_bus.revision_id),
164          AML_OFFSET(common_serial_bus.revision_id),
165          1},
166
167         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.common_serial_bus.type),
168          AML_OFFSET(common_serial_bus.type),
169          1},
170
171         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.common_serial_bus.slave_mode),
172          AML_OFFSET(common_serial_bus.flags),
173          0},
174
175         {ACPI_RSC_1BITFLAG,
176          ACPI_RS_OFFSET(data.common_serial_bus.producer_consumer),
177          AML_OFFSET(common_serial_bus.flags),
178          1},
179
180         {ACPI_RSC_1BITFLAG,
181          ACPI_RS_OFFSET(data.common_serial_bus.connection_sharing),
182          AML_OFFSET(common_serial_bus.flags),
183          2},
184
185         {ACPI_RSC_MOVE8,
186          ACPI_RS_OFFSET(data.common_serial_bus.type_revision_id),
187          AML_OFFSET(common_serial_bus.type_revision_id),
188          1},
189
190         {ACPI_RSC_MOVE16,
191          ACPI_RS_OFFSET(data.common_serial_bus.type_data_length),
192          AML_OFFSET(common_serial_bus.type_data_length),
193          1},
194
195         /* Vendor data */
196
197         {ACPI_RSC_COUNT_SERIAL_VEN,
198          ACPI_RS_OFFSET(data.common_serial_bus.vendor_length),
199          AML_OFFSET(common_serial_bus.type_data_length),
200          AML_RESOURCE_I2C_MIN_DATA_LEN},
201
202         {ACPI_RSC_MOVE_SERIAL_VEN,
203          ACPI_RS_OFFSET(data.common_serial_bus.vendor_data),
204          0,
205          sizeof(struct aml_resource_i2c_serialbus)},
206
207         /* Resource Source */
208
209         {ACPI_RSC_MOVE8,
210          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.index),
211          AML_OFFSET(common_serial_bus.res_source_index),
212          1},
213
214         {ACPI_RSC_COUNT_SERIAL_RES,
215          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.string_length),
216          AML_OFFSET(common_serial_bus.type_data_length),
217          sizeof(struct aml_resource_common_serialbus)},
218
219         {ACPI_RSC_MOVE_SERIAL_RES,
220          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.string_ptr),
221          AML_OFFSET(common_serial_bus.type_data_length),
222          sizeof(struct aml_resource_common_serialbus)},
223
224         /* I2C bus type specific */
225
226         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.i2c_serial_bus.access_mode),
227          AML_OFFSET(i2c_serial_bus.type_specific_flags),
228          0},
229
230         {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.i2c_serial_bus.connection_speed),
231          AML_OFFSET(i2c_serial_bus.connection_speed),
232          1},
233
234         {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.i2c_serial_bus.slave_address),
235          AML_OFFSET(i2c_serial_bus.slave_address),
236          1},
237 };
238
239 /*******************************************************************************
240  *
241  * acpi_rs_convert_spi_serial_bus
242  *
243  ******************************************************************************/
244
245 struct acpi_rsconvert_info acpi_rs_convert_spi_serial_bus[21] = {
246         {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_SERIAL_BUS,
247          ACPI_RS_SIZE(struct acpi_resource_spi_serialbus),
248          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_spi_serial_bus)},
249
250         {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_SERIAL_BUS,
251          sizeof(struct aml_resource_spi_serialbus),
252          0},
253
254         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.common_serial_bus.revision_id),
255          AML_OFFSET(common_serial_bus.revision_id),
256          1},
257
258         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.common_serial_bus.type),
259          AML_OFFSET(common_serial_bus.type),
260          1},
261
262         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.common_serial_bus.slave_mode),
263          AML_OFFSET(common_serial_bus.flags),
264          0},
265
266         {ACPI_RSC_1BITFLAG,
267          ACPI_RS_OFFSET(data.common_serial_bus.producer_consumer),
268          AML_OFFSET(common_serial_bus.flags),
269          1},
270
271         {ACPI_RSC_1BITFLAG,
272          ACPI_RS_OFFSET(data.common_serial_bus.connection_sharing),
273          AML_OFFSET(common_serial_bus.flags),
274          2},
275
276         {ACPI_RSC_MOVE8,
277          ACPI_RS_OFFSET(data.common_serial_bus.type_revision_id),
278          AML_OFFSET(common_serial_bus.type_revision_id),
279          1},
280
281         {ACPI_RSC_MOVE16,
282          ACPI_RS_OFFSET(data.common_serial_bus.type_data_length),
283          AML_OFFSET(common_serial_bus.type_data_length),
284          1},
285
286         /* Vendor data */
287
288         {ACPI_RSC_COUNT_SERIAL_VEN,
289          ACPI_RS_OFFSET(data.common_serial_bus.vendor_length),
290          AML_OFFSET(common_serial_bus.type_data_length),
291          AML_RESOURCE_SPI_MIN_DATA_LEN},
292
293         {ACPI_RSC_MOVE_SERIAL_VEN,
294          ACPI_RS_OFFSET(data.common_serial_bus.vendor_data),
295          0,
296          sizeof(struct aml_resource_spi_serialbus)},
297
298         /* Resource Source */
299
300         {ACPI_RSC_MOVE8,
301          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.index),
302          AML_OFFSET(common_serial_bus.res_source_index),
303          1},
304
305         {ACPI_RSC_COUNT_SERIAL_RES,
306          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.string_length),
307          AML_OFFSET(common_serial_bus.type_data_length),
308          sizeof(struct aml_resource_common_serialbus)},
309
310         {ACPI_RSC_MOVE_SERIAL_RES,
311          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.string_ptr),
312          AML_OFFSET(common_serial_bus.type_data_length),
313          sizeof(struct aml_resource_common_serialbus)},
314
315         /* Spi bus type specific  */
316
317         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.spi_serial_bus.wire_mode),
318          AML_OFFSET(spi_serial_bus.type_specific_flags),
319          0},
320
321         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.spi_serial_bus.device_polarity),
322          AML_OFFSET(spi_serial_bus.type_specific_flags),
323          1},
324
325         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.spi_serial_bus.data_bit_length),
326          AML_OFFSET(spi_serial_bus.data_bit_length),
327          1},
328
329         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.spi_serial_bus.clock_phase),
330          AML_OFFSET(spi_serial_bus.clock_phase),
331          1},
332
333         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.spi_serial_bus.clock_polarity),
334          AML_OFFSET(spi_serial_bus.clock_polarity),
335          1},
336
337         {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.spi_serial_bus.device_selection),
338          AML_OFFSET(spi_serial_bus.device_selection),
339          1},
340
341         {ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.spi_serial_bus.connection_speed),
342          AML_OFFSET(spi_serial_bus.connection_speed),
343          1},
344 };
345
346 /*******************************************************************************
347  *
348  * acpi_rs_convert_uart_serial_bus
349  *
350  ******************************************************************************/
351
352 struct acpi_rsconvert_info acpi_rs_convert_uart_serial_bus[23] = {
353         {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_SERIAL_BUS,
354          ACPI_RS_SIZE(struct acpi_resource_uart_serialbus),
355          ACPI_RSC_TABLE_SIZE(acpi_rs_convert_uart_serial_bus)},
356
357         {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_SERIAL_BUS,
358          sizeof(struct aml_resource_uart_serialbus),
359          0},
360
361         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.common_serial_bus.revision_id),
362          AML_OFFSET(common_serial_bus.revision_id),
363          1},
364
365         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.common_serial_bus.type),
366          AML_OFFSET(common_serial_bus.type),
367          1},
368
369         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.common_serial_bus.slave_mode),
370          AML_OFFSET(common_serial_bus.flags),
371          0},
372
373         {ACPI_RSC_1BITFLAG,
374          ACPI_RS_OFFSET(data.common_serial_bus.producer_consumer),
375          AML_OFFSET(common_serial_bus.flags),
376          1},
377
378         {ACPI_RSC_1BITFLAG,
379          ACPI_RS_OFFSET(data.common_serial_bus.connection_sharing),
380          AML_OFFSET(common_serial_bus.flags),
381          2},
382
383         {ACPI_RSC_MOVE8,
384          ACPI_RS_OFFSET(data.common_serial_bus.type_revision_id),
385          AML_OFFSET(common_serial_bus.type_revision_id),
386          1},
387
388         {ACPI_RSC_MOVE16,
389          ACPI_RS_OFFSET(data.common_serial_bus.type_data_length),
390          AML_OFFSET(common_serial_bus.type_data_length),
391          1},
392
393         /* Vendor data */
394
395         {ACPI_RSC_COUNT_SERIAL_VEN,
396          ACPI_RS_OFFSET(data.common_serial_bus.vendor_length),
397          AML_OFFSET(common_serial_bus.type_data_length),
398          AML_RESOURCE_UART_MIN_DATA_LEN},
399
400         {ACPI_RSC_MOVE_SERIAL_VEN,
401          ACPI_RS_OFFSET(data.common_serial_bus.vendor_data),
402          0,
403          sizeof(struct aml_resource_uart_serialbus)},
404
405         /* Resource Source */
406
407         {ACPI_RSC_MOVE8,
408          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.index),
409          AML_OFFSET(common_serial_bus.res_source_index),
410          1},
411
412         {ACPI_RSC_COUNT_SERIAL_RES,
413          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.string_length),
414          AML_OFFSET(common_serial_bus.type_data_length),
415          sizeof(struct aml_resource_common_serialbus)},
416
417         {ACPI_RSC_MOVE_SERIAL_RES,
418          ACPI_RS_OFFSET(data.common_serial_bus.resource_source.string_ptr),
419          AML_OFFSET(common_serial_bus.type_data_length),
420          sizeof(struct aml_resource_common_serialbus)},
421
422         /* Uart bus type specific  */
423
424         {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.uart_serial_bus.flow_control),
425          AML_OFFSET(uart_serial_bus.type_specific_flags),
426          0},
427
428         {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.uart_serial_bus.stop_bits),
429          AML_OFFSET(uart_serial_bus.type_specific_flags),
430          2},
431
432         {ACPI_RSC_3BITFLAG, ACPI_RS_OFFSET(data.uart_serial_bus.data_bits),
433          AML_OFFSET(uart_serial_bus.type_specific_flags),
434          4},
435
436         {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.uart_serial_bus.endian),
437          AML_OFFSET(uart_serial_bus.type_specific_flags),
438          7},
439
440         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.uart_serial_bus.parity),
441          AML_OFFSET(uart_serial_bus.parity),
442          1},
443
444         {ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.uart_serial_bus.lines_enabled),
445          AML_OFFSET(uart_serial_bus.lines_enabled),
446          1},
447
448         {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.uart_serial_bus.rx_fifo_size),
449          AML_OFFSET(uart_serial_bus.rx_fifo_size),
450          1},
451
452         {ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.uart_serial_bus.tx_fifo_size),
453          AML_OFFSET(uart_serial_bus.tx_fifo_size),
454          1},
455
456         {ACPI_RSC_MOVE32,
457          ACPI_RS_OFFSET(data.uart_serial_bus.default_baud_rate),
458          AML_OFFSET(uart_serial_bus.default_baud_rate),
459          1},
460 };