1 /* SPDX-License-Identifier: GPL-2.0-only */
9 type Fields
[T
uint32 |
string] struct {
20 func getField(config
uint32, mask
uint32) uint32 {
21 return (config
& mask
) >> bits
.TrailingZeros32(mask
)
24 func Decode(config
uint32) Fields
[uint32] {
25 return Fields
[uint32]{
26 PortConnectivity
: getField(config
, 0xc0000000),
27 Location
: getField(config
, 0x3f000000),
28 DefaultDevice
: getField(config
, 0x00f00000),
29 ConnectionType
: getField(config
, 0x000f0000),
30 Color
: getField(config
, 0x0000f000),
31 Misc
: getField(config
, 0x00000f00),
32 DefaultAssociation
: getField(config
, 0x000000f0),
33 Sequence
: getField(config
, 0x0000000f),
37 func PortIsConnected(config
uint32) bool {
38 return Decode(config
).PortConnectivity
!= 0x1
41 var portConnectivityDescriptions
= map[uint32]string{
44 0x2: "AZALIA_INTEGRATED",
45 0x3: "AZALIA_JACK_AND_INTEGRATED",
48 var grossLocationDescriptions
= map[uint32]string{
49 0x00: "AZALIA_EXTERNAL_PRIMARY_CHASSIS",
50 0x10: "AZALIA_INTERNAL",
51 0x20: "AZALIA_SEPARATE_CHASSIS",
52 0x30: "AZALIA_LOCATION_OTHER",
55 var geometricLocationDescriptions
= map[uint32]string{
56 0x00: "AZALIA_GEOLOCATION_NA",
62 0x06: "AZALIA_BOTTOM",
63 0x07: "AZALIA_SPECIAL7",
64 0x08: "AZALIA_SPECIAL8",
65 0x09: "AZALIA_SPECIAL9",
68 var specialLocationDescriptions
= map[uint32]string{
69 0x00 |
0x07: "AZALIA_REAR_PANEL",
70 0x00 |
0x08: "AZALIA_DRIVE_BAY",
71 0x10 |
0x07: "AZALIA_RISER",
72 0x10 |
0x08: "AZALIA_DIGITAL_DISPLAY",
73 0x10 |
0x09: "AZALIA_ATAPI",
74 0x30 |
0x07: "AZALIA_MOBILE_LID_INSIDE",
75 0x30 |
0x08: "AZALIA_MOBILE_LID_OUTSIDE",
78 var defaultDeviceDescriptions
= map[uint32]string{
79 0x0: "AZALIA_LINE_OUT",
80 0x1: "AZALIA_SPEAKER",
83 0x4: "AZALIA_SPDIF_OUT",
84 0x5: "AZALIA_DIGITAL_OTHER_OUT",
85 0x6: "AZALIA_MODEM_LINE_SIDE",
86 0x7: "AZALIA_MODEM_HANDSET_SIDE",
87 0x8: "AZALIA_LINE_IN",
90 0xb: "AZALIA_TELEPHONY",
91 0xc: "AZALIA_SPDIF_IN",
92 0xd: "AZALIA_DIGITAL_OTHER_IN",
93 0xf: "AZALIA_DEVICE_OTHER",
96 var connectionTypeDescriptions
= map[uint32]string{
97 0x0: "AZALIA_TYPE_UNKNOWN",
98 0x1: "AZALIA_STEREO_MONO_1_8",
99 0x2: "AZALIA_STEREO_MONO_1_4",
100 0x3: "AZALIA_ATAPI_INTERNAL",
102 0x5: "AZALIA_OPTICAL",
103 0x6: "AZALIA_OTHER_DIGITAL",
104 0x7: "AZALIA_OTHER_ANALOG",
105 0x8: "AZALIA_MULTICHANNEL_ANALOG",
108 0xb: "AZALIA_COMBINATION",
109 0xf: "AZALIA_TYPE_OTHER",
112 var colorDescriptions
= map[uint32]string{
113 0x0: "AZALIA_COLOR_UNKNOWN",
119 0x6: "AZALIA_ORANGE",
120 0x7: "AZALIA_YELLOW",
121 0x8: "AZALIA_PURPLE",
124 0xf: "AZALIA_COLOR_OTHER",
127 var miscDescriptions
= map[uint32]string{
128 0x0: "AZALIA_JACK_PRESENCE_DETECT",
129 0x1: "AZALIA_NO_JACK_PRESENCE_DETECT",
132 func getDescription(field
uint32, descriptions
map[uint32]string) string {
133 desc
, exists
:= descriptions
[field
]
136 return fmt
.Sprintf("0x%x", field
)
141 func getLocationDescription(field
uint32) string {
142 desc
, isSpecialLocation
:= specialLocationDescriptions
[field
]
143 if isSpecialLocation
{
147 grossLocation
:= field
& 0x30
148 geometricLocation
:= field
& 0x0f
150 desc
= grossLocationDescriptions
[grossLocation
]
151 if geometricLocation
!= 0x00 {
152 desc
+= " | " + getDescription(geometricLocation
, geometricLocationDescriptions
)
157 func getMiscDescription(field
uint32) string {
158 presenceBit
:= field
& 0b0001
159 reservedBits
:= field
& 0b1110
161 desc
:= miscDescriptions
[presenceBit
]
162 if bits
.OnesCount32(reservedBits
) > 0 {
163 desc
+= fmt
.Sprintf(" | 0x%x", reservedBits
)
168 func ToHumanReadable(fields Fields
[uint32]) Fields
[string] {
169 return Fields
[string]{
170 PortConnectivity
: getDescription(fields
.PortConnectivity
, portConnectivityDescriptions
),
171 Location
: getLocationDescription(fields
.Location
),
172 DefaultDevice
: getDescription(fields
.DefaultDevice
, defaultDeviceDescriptions
),
173 ConnectionType
: getDescription(fields
.ConnectionType
, connectionTypeDescriptions
),
174 Color
: getDescription(fields
.Color
, colorDescriptions
),
175 Misc
: getMiscDescription(fields
.Misc
),
176 DefaultAssociation
: fmt
.Sprintf("%d", fields
.DefaultAssociation
),
177 Sequence
: fmt
.Sprintf("%d", fields
.Sequence
),
181 func ConfigToVerbs(address
uint32, nodeId
uint32, config
uint32) [4]uint32 {
183 (address
<< 28) |
(nodeId
<< 20) |
(0x71c << 8) |
((config
>> 0) & 0xff),
184 (address
<< 28) |
(nodeId
<< 20) |
(0x71d << 8) |
((config
>> 8) & 0xff),
185 (address
<< 28) |
(nodeId
<< 20) |
(0x71e << 8) |
((config
>> 16) & 0xff),
186 (address
<< 28) |
(nodeId
<< 20) |
(0x71f << 8) |
((config
>> 24) & 0xff),