| 1 |
|
| 2 |
|
| 3 |
#include <stdint.h> |
| 4 |
#include <string.h> |
| 5 |
#include <acpi/acpi.h> |
| 6 |
#include <acpi/acpi_pld.h> |
| 7 |
|
| 8 |
int acpi_pld_fill_usb(struct acpi_pld *pld, enum acpi_upc_type type, |
| 9 |
struct acpi_pld_group *group) |
| 10 |
{ |
| 11 |
if (!pld) |
| 12 |
return -1; |
| 13 |
|
| 14 |
memset(pld, 0, sizeof(struct acpi_pld)); |
| 15 |
|
| 16 |
|
| 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; |
| 25 |
|
| 26 |
|
| 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; |
| 51 |
} |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
int acpi_pld_to_buffer(const struct acpi_pld *pld, uint8_t *buf, int buf_len) |
| 57 |
{ |
| 58 |
if (!pld || !buf) |
| 59 |
return -1; |
| 60 |
|
| 61 |
memset(buf, 0, buf_len); |
| 62 |
|
| 63 |
|
| 64 |
buf[0] = 0x2; |
| 65 |
|
| 66 |
if (pld->ignore_color) { |
| 67 |
|
| 68 |
buf[0] |= 0x80; |
| 69 |
} else { |
| 70 |
|
| 71 |
buf[1] = pld->color_red; |
| 72 |
|
| 73 |
buf[2] = pld->color_green; |
| 74 |
|
| 75 |
buf[3] = pld->color_blue; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
buf[4] = pld->width & 0xff; |
| 80 |
buf[5] = pld->width >> 8; |
| 81 |
|
| 82 |
|
| 83 |
buf[6] = pld->height & 0xff; |
| 84 |
buf[7] = pld->height >> 8; |
| 85 |
|
| 86 |
|
| 87 |
buf[8] |= (pld->visible & 0x1); |
| 88 |
|
| 89 |
|
| 90 |
buf[8] |= (pld->dock & 0x1) << 1; |
| 91 |
|
| 92 |
|
| 93 |
buf[8] |= (pld->lid & 0x1) << 2; |
| 94 |
|
| 95 |
|
| 96 |
buf[8] |= (pld->panel & 0x7) << 3; |
| 97 |
|
| 98 |
|
| 99 |
buf[8] |= (pld->vertical_position & 0x3) << 6; |
| 100 |
|
| 101 |
|
| 102 |
buf[9] |= (pld->horizontal_position & 0x3); |
| 103 |
|
| 104 |
|
| 105 |
buf[9] |= (pld->shape & 0xf) << 2; |
| 106 |
|
| 107 |
|
| 108 |
buf[9] |= (pld->orientation & 0x1) << 6; |
| 109 |
|
| 110 |
|
| 111 |
buf[9] |= (pld->group.token & 0x1) << 7; |
| 112 |
buf[10] |= (pld->group.token >> 0x1) & 0x7f; |
| 113 |
|
| 114 |
|
| 115 |
buf[10] |= (pld->group.position & 0x1) << 7; |
| 116 |
buf[11] |= (pld->group.position >> 0x1) & 0x7f; |
| 117 |
|
| 118 |
|
| 119 |
buf[11] |= (pld->bay & 0x1) << 7; |
| 120 |
|
| 121 |
|
| 122 |
buf[12] |= (pld->ejectable & 0x1); |
| 123 |
|
| 124 |
|
| 125 |
buf[12] |= (pld->ejectable_ospm & 0x1) << 1; |
| 126 |
|
| 127 |
|
| 128 |
buf[12] |= (pld->cabinet_number & 0x3f) << 2; |
| 129 |
buf[13] |= (pld->cabinet_number >> 6) & 0x3; |
| 130 |
|
| 131 |
|
| 132 |
buf[13] |= (pld->card_cage_number & 0x3f) << 2; |
| 133 |
buf[14] |= (pld->card_cage_number >> 6) & 0x3; |
| 134 |
|
| 135 |
|
| 136 |
buf[14] |= (pld->reference_shape & 0x1) << 2; |
| 137 |
|
| 138 |
|
| 139 |
buf[14] |= (pld->rotation & 0xf) << 3; |
| 140 |
|
| 141 |
|
| 142 |
buf[14] |= (pld->draw_order & 0x1) << 7; |
| 143 |
buf[15] |= (pld->draw_order >> 1) & 0xf; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
if (buf_len == 20) { |
| 149 |
|
| 150 |
buf[16] = pld->vertical_offset & 0xff; |
| 151 |
buf[17] = pld->vertical_offset >> 8; |
| 152 |
|
| 153 |
|
| 154 |
buf[18] = pld->horizontal_offset & 0xff; |
| 155 |
buf[19] = pld->horizontal_offset >> 8; |
| 156 |
} |
| 157 |
|
| 158 |
return 0; |
| 159 |
} |