blob: 135009a243d63be44aecbb78102fbdf82f561227 [file] [log] [blame]
Patrick Georgi11f00792020-03-04 15:10:45 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Laurie3e7197a2018-05-07 14:18:13 -07003
4#include <stdint.h>
5#include <string.h>
6#include <arch/acpi.h>
7#include <arch/acpi_pld.h>
8
Duncan Lauriee1eca1d2018-12-01 17:14:35 -08009int acpi_pld_fill_usb(struct acpi_pld *pld, enum acpi_upc_type type,
10 struct acpi_pld_group *group)
Duncan Laurie3e7197a2018-05-07 14:18:13 -070011{
12 if (!pld)
13 return -1;
14
15 memset(pld, 0, sizeof(struct acpi_pld));
16
17 /* Set defaults */
18 pld->ignore_color = 1;
19 pld->panel = PLD_PANEL_UNKNOWN;
20 pld->vertical_position = PLD_VERTICAL_POSITION_CENTER;
21 pld->horizontal_position = PLD_HORIZONTAL_POSITION_CENTER;
22 pld->rotation = PLD_ROTATE_0;
23 pld->visible = 1;
Duncan Lauriee1eca1d2018-12-01 17:14:35 -080024 pld->group.token = group->token;
25 pld->group.position = group->position;
Duncan Laurie3e7197a2018-05-07 14:18:13 -070026
27 /* Set the shape based on port type */
28 switch (type) {
29 case UPC_TYPE_A:
30 case UPC_TYPE_USB3_A:
31 case UPC_TYPE_USB3_POWER_B:
32 pld->shape = PLD_SHAPE_HORIZONTAL_RECTANGLE;
33 break;
34 case UPC_TYPE_MINI_AB:
35 case UPC_TYPE_USB3_B:
36 pld->shape = PLD_SHAPE_CHAMFERED;
37 break;
38 case UPC_TYPE_USB3_MICRO_B:
39 case UPC_TYPE_USB3_MICRO_AB:
40 pld->shape = PLD_SHAPE_HORIZONTAL_TRAPEZOID;
41 break;
42 case UPC_TYPE_C_USB2_ONLY:
43 case UPC_TYPE_C_USB2_SS_SWITCH:
44 case UPC_TYPE_C_USB2_SS:
45 pld->shape = PLD_SHAPE_OVAL;
46 break;
47 case UPC_TYPE_INTERNAL:
48 default:
49 pld->shape = PLD_SHAPE_UNKNOWN;
50 pld->visible = 0;
51 break;
52 }
53
54 return 0;
55}
56
57int acpi_pld_to_buffer(const struct acpi_pld *pld, uint8_t *buf, int buf_len)
58{
59 if (!pld || !buf)
60 return -1;
61
62 memset(buf, 0, buf_len);
63
64 /* [0] Revision (=2) */
65 buf[0] = 0x2;
66
67 if (pld->ignore_color) {
68 /* [1] Ignore Color */
69 buf[0] |= 0x80;
70 } else {
71 /* [15:8] Red Color */
72 buf[1] = pld->color_red;
73 /* [23:16] Green Color */
74 buf[2] = pld->color_green;
75 /* [31:24] Blue Color */
76 buf[3] = pld->color_blue;
77 }
78
79 /* [47:32] Width */
80 buf[4] = pld->width & 0xff;
81 buf[5] = pld->width >> 8;
82
83 /* [63:48] Height */
84 buf[6] = pld->height & 0xff;
85 buf[7] = pld->height >> 8;
86
87 /* [64] User Visible */
88 buf[8] |= (pld->visible & 0x1);
89
90 /* [65] Dock */
91 buf[8] |= (pld->dock & 0x1) << 1;
92
93 /* [66] Lid */
94 buf[8] |= (pld->lid & 0x1) << 2;
95
96 /* [69:67] Panel */
97 buf[8] |= (pld->panel & 0x7) << 3;
98
99 /* [71:70] Vertical Position */
100 buf[8] |= (pld->vertical_position & 0x3) << 6;
101
102 /* [73:72] Horizontal Position */
103 buf[9] |= (pld->horizontal_position & 0x3);
104
105 /* [77:74] Shape */
106 buf[9] |= (pld->shape & 0xf) << 2;
107
Duncan Lauriee1eca1d2018-12-01 17:14:35 -0800108 /* [78] Orientation */
109 buf[9] |= (pld->orientation & 0x1) << 6;
Duncan Laurie3e7197a2018-05-07 14:18:13 -0700110
111 /* [86:79] Group Token (incorrectly defined as 1 bit in ACPI 6.2A) */
Duncan Lauriee1eca1d2018-12-01 17:14:35 -0800112 buf[9] |= (pld->group.token & 0x1) << 7;
113 buf[10] |= (pld->group.token >> 0x1) & 0x7f;
Duncan Laurie3e7197a2018-05-07 14:18:13 -0700114
115 /* [94:87] Group Position */
Duncan Lauriee1eca1d2018-12-01 17:14:35 -0800116 buf[10] |= (pld->group.position & 0x1) << 7;
117 buf[11] |= (pld->group.position >> 0x1) & 0x7f;
Duncan Laurie3e7197a2018-05-07 14:18:13 -0700118
119 /* [95] Bay */
120 buf[11] |= (pld->bay & 0x1) << 7;
121
122 /* [96] Ejectable */
123 buf[12] |= (pld->ejectable & 0x1);
124
125 /* [97] Ejectable with OSPM help */
126 buf[12] |= (pld->ejectable_ospm & 0x1) << 1;
127
128 /* [105:98] Cabinet Number */
129 buf[12] |= (pld->cabinet_number & 0x3f) << 2;
130 buf[13] |= (pld->cabinet_number >> 6) & 0x3;
131
132 /* [113:106] Card Cage Number */
133 buf[13] |= (pld->card_cage_number & 0x3f) << 2;
134 buf[14] |= (pld->card_cage_number >> 6) & 0x3;
135
136 /* [114] PLD is a Reference Shape */
137 buf[14] |= (pld->reference_shape & 0x1) << 2;
138
139 /* [118:115] Rotation */
140 buf[14] |= (pld->rotation & 0xf) << 3;
141
142 /* [123:119] Draw Order */
143 buf[14] |= (pld->draw_order & 0x1) << 7;
144 buf[15] |= (pld->draw_order >> 1) & 0xf;
145
146 /* [127:124] Reserved */
147
148 /* Both 16 byte and 20 byte buffers are supported by the spec */
149 if (buf_len == 20) {
150 /* [143:128] Vertical Offset */
151 buf[16] = pld->vertical_offset & 0xff;
152 buf[17] = pld->vertical_offset >> 8;
153
154 /* [159:144] Horizontal Offset */
155 buf[18] = pld->horizontal_offset & 0xff;
156 buf[19] = pld->horizontal_offset >> 8;
157 }
158
159 return 0;
160}