docs: Add 24.12 release notes
[coreboot2.git] / src / acpi / pld.c
blobb9c98a14544b470927f61e81df04417f08eafd75
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdint.h>
4 #include <string.h>
5 #include <acpi/acpi.h>
6 #include <acpi/acpi_pld.h>
8 int acpi_pld_fill_usb(struct acpi_pld *pld, enum acpi_upc_type type,
9 struct acpi_pld_group *group)
11 if (!pld)
12 return -1;
14 memset(pld, 0, sizeof(struct acpi_pld));
16 /* Set defaults */
17 pld->ignore_color = 1;
18 pld->panel = PLD_PANEL_UNKNOWN;
19 pld->vertical_position = PLD_VERTICAL_POSITION_CENTER;
20 pld->horizontal_position = PLD_HORIZONTAL_POSITION_CENTER;
21 pld->rotation = PLD_ROTATE_0;
22 pld->visible = 1;
23 pld->group.token = group->token;
24 pld->group.position = group->position;
26 /* Set the shape based on port type */
27 switch (type) {
28 case UPC_TYPE_A:
29 case UPC_TYPE_USB3_A:
30 case UPC_TYPE_USB3_POWER_B:
31 pld->shape = PLD_SHAPE_HORIZONTAL_RECTANGLE;
32 break;
33 case UPC_TYPE_MINI_AB:
34 case UPC_TYPE_USB3_B:
35 pld->shape = PLD_SHAPE_CHAMFERED;
36 break;
37 case UPC_TYPE_USB3_MICRO_B:
38 case UPC_TYPE_USB3_MICRO_AB:
39 pld->shape = PLD_SHAPE_HORIZONTAL_TRAPEZOID;
40 break;
41 case UPC_TYPE_C_USB2_ONLY:
42 case UPC_TYPE_C_USB2_SS_SWITCH:
43 case UPC_TYPE_C_USB2_SS:
44 pld->shape = PLD_SHAPE_OVAL;
45 break;
46 case UPC_TYPE_INTERNAL:
47 default:
48 pld->shape = PLD_SHAPE_UNKNOWN;
49 pld->visible = 0;
50 break;
53 return 0;
56 int acpi_pld_to_buffer(const struct acpi_pld *pld, uint8_t *buf, int buf_len)
58 if (!pld || !buf)
59 return -1;
61 memset(buf, 0, buf_len);
63 /* [0] Revision (=2) */
64 buf[0] = 0x2;
66 if (pld->ignore_color) {
67 /* [1] Ignore Color */
68 buf[0] |= 0x80;
69 } else {
70 /* [15:8] Red Color */
71 buf[1] = pld->color_red;
72 /* [23:16] Green Color */
73 buf[2] = pld->color_green;
74 /* [31:24] Blue Color */
75 buf[3] = pld->color_blue;
78 /* [47:32] Width */
79 buf[4] = pld->width & 0xff;
80 buf[5] = pld->width >> 8;
82 /* [63:48] Height */
83 buf[6] = pld->height & 0xff;
84 buf[7] = pld->height >> 8;
86 /* [64] User Visible */
87 buf[8] |= (pld->visible & 0x1);
89 /* [65] Dock */
90 buf[8] |= (pld->dock & 0x1) << 1;
92 /* [66] Lid */
93 buf[8] |= (pld->lid & 0x1) << 2;
95 /* [69:67] Panel */
96 buf[8] |= (pld->panel & 0x7) << 3;
98 /* [71:70] Vertical Position */
99 buf[8] |= (pld->vertical_position & 0x3) << 6;
101 /* [73:72] Horizontal Position */
102 buf[9] |= (pld->horizontal_position & 0x3);
104 /* [77:74] Shape */
105 buf[9] |= (pld->shape & 0xf) << 2;
107 /* [78] Orientation */
108 buf[9] |= (pld->orientation & 0x1) << 6;
110 /* [86:79] Group Token (incorrectly defined as 1 bit in ACPI 6.2A) */
111 buf[9] |= (pld->group.token & 0x1) << 7;
112 buf[10] |= (pld->group.token >> 0x1) & 0x7f;
114 /* [94:87] Group Position */
115 buf[10] |= (pld->group.position & 0x1) << 7;
116 buf[11] |= (pld->group.position >> 0x1) & 0x7f;
118 /* [95] Bay */
119 buf[11] |= (pld->bay & 0x1) << 7;
121 /* [96] Ejectable */
122 buf[12] |= (pld->ejectable & 0x1);
124 /* [97] Ejectable with OSPM help */
125 buf[12] |= (pld->ejectable_ospm & 0x1) << 1;
127 /* [105:98] Cabinet Number */
128 buf[12] |= (pld->cabinet_number & 0x3f) << 2;
129 buf[13] |= (pld->cabinet_number >> 6) & 0x3;
131 /* [113:106] Card Cage Number */
132 buf[13] |= (pld->card_cage_number & 0x3f) << 2;
133 buf[14] |= (pld->card_cage_number >> 6) & 0x3;
135 /* [114] PLD is a Reference Shape */
136 buf[14] |= (pld->reference_shape & 0x1) << 2;
138 /* [118:115] Rotation */
139 buf[14] |= (pld->rotation & 0xf) << 3;
141 /* [123:119] Draw Order */
142 buf[14] |= (pld->draw_order & 0x1) << 7;
143 buf[15] |= (pld->draw_order >> 1) & 0xf;
145 /* [127:124] Reserved */
147 /* Both 16 byte and 20 byte buffers are supported by the spec */
148 if (buf_len == 20) {
149 /* [143:128] Vertical Offset */
150 buf[16] = pld->vertical_offset & 0xff;
151 buf[17] = pld->vertical_offset >> 8;
153 /* [159:144] Horizontal Offset */
154 buf[18] = pld->horizontal_offset & 0xff;
155 buf[19] = pld->horizontal_offset >> 8;
158 return 0;