1 /* SPDX-License-Identifier: GPL-2.0-only */
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
)
14 memset(pld
, 0, sizeof(struct acpi_pld
));
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
;
23 pld
->group
.token
= group
->token
;
24 pld
->group
.position
= group
->position
;
26 /* Set the shape based on port type */
30 case UPC_TYPE_USB3_POWER_B
:
31 pld
->shape
= PLD_SHAPE_HORIZONTAL_RECTANGLE
;
33 case UPC_TYPE_MINI_AB
:
35 pld
->shape
= PLD_SHAPE_CHAMFERED
;
37 case UPC_TYPE_USB3_MICRO_B
:
38 case UPC_TYPE_USB3_MICRO_AB
:
39 pld
->shape
= PLD_SHAPE_HORIZONTAL_TRAPEZOID
;
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
;
46 case UPC_TYPE_INTERNAL
:
48 pld
->shape
= PLD_SHAPE_UNKNOWN
;
56 int acpi_pld_to_buffer(const struct acpi_pld
*pld
, uint8_t *buf
, int buf_len
)
61 memset(buf
, 0, buf_len
);
63 /* [0] Revision (=2) */
66 if (pld
->ignore_color
) {
67 /* [1] Ignore Color */
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
;
79 buf
[4] = pld
->width
& 0xff;
80 buf
[5] = pld
->width
>> 8;
83 buf
[6] = pld
->height
& 0xff;
84 buf
[7] = pld
->height
>> 8;
86 /* [64] User Visible */
87 buf
[8] |= (pld
->visible
& 0x1);
90 buf
[8] |= (pld
->dock
& 0x1) << 1;
93 buf
[8] |= (pld
->lid
& 0x1) << 2;
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);
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;
119 buf
[11] |= (pld
->bay
& 0x1) << 7;
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 */
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;