|
7 | 7 | // Author: David Rhodes <david.rhodes@cirrus.com> |
8 | 8 |
|
9 | 9 | #include <linux/acpi.h> |
| 10 | +#include <acpi/acpi_bus.h> |
10 | 11 | #include <linux/delay.h> |
11 | 12 | #include <linux/err.h> |
12 | 13 | #include <linux/init.h> |
@@ -1147,45 +1148,55 @@ static int cs35l41_dsp_init(struct cs35l41_private *cs35l41) |
1147 | 1148 | return ret; |
1148 | 1149 | } |
1149 | 1150 |
|
1150 | | -#ifdef CONFIG_ACPI |
1151 | | -static int cs35l41_acpi_get_name(struct cs35l41_private *cs35l41) |
| 1151 | +static int cs35l41_get_system_name(struct cs35l41_private *cs35l41) |
1152 | 1152 | { |
1153 | 1153 | struct acpi_device *adev = ACPI_COMPANION(cs35l41->dev); |
1154 | | - acpi_handle handle = acpi_device_handle(adev); |
1155 | | - const char *hid; |
1156 | | - const char *sub; |
1157 | | - |
1158 | | - /* If there is no acpi_device, there is no ACPI for this system, return 0 */ |
1159 | | - if (!adev) |
1160 | | - return 0; |
| 1154 | + const char *sub = NULL; |
| 1155 | + const char *tmp; |
| 1156 | + int ret = 0; |
1161 | 1157 |
|
1162 | | - sub = acpi_get_subsystem_id(handle); |
1163 | | - if (IS_ERR(sub)) { |
1164 | | - /* If no _SUB, fallback to _HID, otherwise fail */ |
1165 | | - if (PTR_ERR(sub) == -ENODATA) { |
1166 | | - hid = acpi_device_hid(adev); |
1167 | | - /* If dummy hid, return 0 and fallback to legacy firmware path */ |
1168 | | - if (!strcmp(hid, "device")) |
1169 | | - return 0; |
1170 | | - sub = kstrdup(hid, GFP_KERNEL); |
1171 | | - if (!sub) |
1172 | | - sub = ERR_PTR(-ENOMEM); |
1173 | | - |
1174 | | - } else |
1175 | | - return PTR_ERR(sub); |
| 1158 | + /* If there is no acpi_device, there is no ACPI for this system, skip checking ACPI */ |
| 1159 | + if (adev) { |
| 1160 | + acpi_handle handle = acpi_device_handle(adev); |
| 1161 | + |
| 1162 | + sub = acpi_get_subsystem_id(handle); |
| 1163 | + ret = PTR_ERR_OR_ZERO(sub); |
| 1164 | + if (ret) { |
| 1165 | + sub = NULL; |
| 1166 | + /* If no _SUB, fallback to _HID, otherwise fail */ |
| 1167 | + if (ret == -ENODATA) { |
| 1168 | + tmp = acpi_device_hid(adev); |
| 1169 | + /* If dummy hid, return 0 and fallback to legacy firmware path */ |
| 1170 | + if (!strcmp(tmp, "device")) { |
| 1171 | + ret = 0; |
| 1172 | + goto err; |
| 1173 | + } |
| 1174 | + sub = kstrdup(tmp, GFP_KERNEL); |
| 1175 | + if (!sub) { |
| 1176 | + ret = -ENOMEM; |
| 1177 | + goto err; |
| 1178 | + } |
| 1179 | + } |
| 1180 | + } |
| 1181 | + } else { |
| 1182 | + if (!device_property_read_string(cs35l41->dev, "cirrus,subsystem-id", &tmp)) { |
| 1183 | + sub = kstrdup(tmp, GFP_KERNEL); |
| 1184 | + if (!sub) { |
| 1185 | + ret = -ENOMEM; |
| 1186 | + goto err; |
| 1187 | + } |
| 1188 | + } |
1176 | 1189 | } |
1177 | 1190 |
|
1178 | | - cs35l41->dsp.system_name = sub; |
1179 | | - dev_dbg(cs35l41->dev, "Subsystem ID: %s\n", cs35l41->dsp.system_name); |
| 1191 | +err: |
| 1192 | + if (sub) { |
| 1193 | + cs35l41->dsp.system_name = sub; |
| 1194 | + dev_info(cs35l41->dev, "Subsystem ID: %s\n", cs35l41->dsp.system_name); |
| 1195 | + } else |
| 1196 | + dev_warn(cs35l41->dev, "Subsystem ID not found\n"); |
1180 | 1197 |
|
1181 | | - return 0; |
1182 | | -} |
1183 | | -#else |
1184 | | -static int cs35l41_acpi_get_name(struct cs35l41_private *cs35l41) |
1185 | | -{ |
1186 | | - return 0; |
| 1198 | + return ret; |
1187 | 1199 | } |
1188 | | -#endif /* CONFIG_ACPI */ |
1189 | 1200 |
|
1190 | 1201 | int cs35l41_probe(struct cs35l41_private *cs35l41, const struct cs35l41_hw_cfg *hw_cfg) |
1191 | 1202 | { |
@@ -1317,7 +1328,7 @@ int cs35l41_probe(struct cs35l41_private *cs35l41, const struct cs35l41_hw_cfg * |
1317 | 1328 | goto err; |
1318 | 1329 | } |
1319 | 1330 |
|
1320 | | - ret = cs35l41_acpi_get_name(cs35l41); |
| 1331 | + ret = cs35l41_get_system_name(cs35l41); |
1321 | 1332 | if (ret < 0) |
1322 | 1333 | goto err; |
1323 | 1334 |
|
|
0 commit comments