Skip to content

Commit 8d942e4

Browse files
committed
ASoC: SDCA: add support for HIDE entity properties and HID descriptor/report
Add support for parsing the HIDE entity descriptor and HID descriptor/report Signed-off-by: Shuming Fan <shumingf@realtek.com>
1 parent 3fc50b3 commit 8d942e4

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

include/sound/sdca_function.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/bits.h>
1313
#include <linux/types.h>
14+
#include <linux/hid.h>
1415

1516
struct device;
1617
struct sdca_entity;
@@ -971,6 +972,32 @@ struct sdca_entity_ge {
971972
int num_modes;
972973
};
973974

975+
/**
976+
* struct sdca_entity_hide - information specific to HIDE Entities
977+
* @hid: HID device structure
978+
* @hidtx_ids: HIDTx Report ID
979+
* @num_hidtx_ids: number of HIDTx Report ID
980+
* @hidrx_ids: HIDRx Report ID
981+
* @num_hidrx_ids: number of HIDRx Report ID
982+
* @hide_reside_function_num: indicating which Audio Function Numbers within this Device
983+
* @max_delay: the maximum time in microseconds allowed for the Device to change the ownership from Device to Host
984+
* @af_number_list: which Audio Function Numbers within this Device are sending/receiving the messages in this HIDE
985+
* @hid_desc: HID descriptor for the HIDE Entity
986+
* @hid_report_desc: HID Report Descriptor for the HIDE Entity
987+
*/
988+
struct sdca_entity_hide {
989+
struct hid_device *hid;
990+
unsigned int *hidtx_ids;
991+
int num_hidtx_ids;
992+
unsigned int *hidrx_ids;
993+
int num_hidrx_ids;
994+
unsigned int hide_reside_function_num;
995+
unsigned int max_delay;
996+
unsigned int af_number_list[SDCA_MAX_FUNCTION_COUNT];
997+
struct hid_descriptor hid_desc;
998+
unsigned char *hid_report_desc;
999+
};
1000+
9741001
/**
9751002
* struct sdca_entity - information for one SDCA Entity
9761003
* @label: String such as "OT 12".
@@ -986,6 +1013,7 @@ struct sdca_entity_ge {
9861013
* @cs: Clock Source specific Entity properties.
9871014
* @pde: Power Domain Entity specific Entity properties.
9881015
* @ge: Group Entity specific Entity properties.
1016+
* @hide: HIDE Entity specific Entity properties.
9891017
*/
9901018
struct sdca_entity {
9911019
const char *label;
@@ -1002,6 +1030,7 @@ struct sdca_entity {
10021030
struct sdca_entity_cs cs;
10031031
struct sdca_entity_pde pde;
10041032
struct sdca_entity_ge ge;
1033+
struct sdca_entity_hide hide;
10051034
};
10061035
};
10071036

sound/soc/sdca/sdca_functions.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,95 @@ static int find_sdca_entity_ge(struct device *dev,
12221222
return -EINVAL;
12231223
}
12241224

1225+
static int
1226+
find_sdca_entity_hide(struct device *dev, struct fwnode_handle *function_node,
1227+
struct fwnode_handle *entity_node,
1228+
struct sdca_entity *entity)
1229+
{
1230+
struct sdca_entity_hide *hide = &entity->hide;
1231+
struct hid_descriptor hid_desc;
1232+
unsigned int delay, af_list[SDCA_MAX_FUNCTION_COUNT];
1233+
int nval, ret;
1234+
unsigned char *report_desc = NULL;
1235+
1236+
ret = fwnode_property_read_u32(entity_node,
1237+
"mipi-sdca-RxUMP-ownership-transition-maxdelay", &delay);
1238+
if (!ret)
1239+
hide->max_delay = delay;
1240+
1241+
nval = fwnode_property_count_u32(entity_node, "mipi-sdca-HIDTx-supported-report-ids");
1242+
if (nval > 0) {
1243+
hide->num_hidtx_ids = nval;
1244+
hide->hidtx_ids = devm_kcalloc(dev, hide->num_hidtx_ids,
1245+
sizeof(*hide->hidtx_ids), GFP_KERNEL);
1246+
if (!hide->hidtx_ids)
1247+
return -ENOMEM;
1248+
1249+
ret = fwnode_property_read_u32_array(entity_node,
1250+
"mipi-sdca-HIDTx-supported-report-ids",
1251+
hide->hidtx_ids,
1252+
hide->num_hidtx_ids);
1253+
if (ret < 0)
1254+
return ret;
1255+
} else {
1256+
hide->hidtx_ids = NULL;
1257+
}
1258+
1259+
nval = fwnode_property_count_u32(entity_node, "mipi-sdca-HIDRx-supported-report-ids");
1260+
if (nval > 0) {
1261+
hide->num_hidtx_ids = nval;
1262+
hide->hidtx_ids = devm_kcalloc(dev, hide->num_hidtx_ids,
1263+
sizeof(*hide->hidtx_ids), GFP_KERNEL);
1264+
if (!hide->hidtx_ids)
1265+
return -ENOMEM;
1266+
1267+
ret = fwnode_property_read_u32_array(entity_node,
1268+
"mipi-sdca-HIDRx-supported-report-ids",
1269+
hide->hidtx_ids,
1270+
hide->num_hidtx_ids);
1271+
if (ret < 0)
1272+
return ret;
1273+
} else {
1274+
hide->hidrx_ids = NULL;
1275+
}
1276+
1277+
nval = fwnode_property_count_u32(entity_node, "mipi-sdca-hide-related-audio-function-list");
1278+
if (nval <= 0) {
1279+
dev_err(dev, "%pfwP: HIDE - audio function numbers list missing: %d\n",
1280+
entity_node, nval);
1281+
return -EINVAL;
1282+
} else if (nval > SDCA_MAX_FUNCTION_COUNT) {
1283+
dev_err(dev, "%pfwP: maximum number of audio function exceeded\n", entity_node);
1284+
return -EINVAL;
1285+
}
1286+
1287+
fwnode_property_read_u32_array(entity_node, "mipi-sdca-hide-related-audio-function-list",
1288+
&af_list[0], nval);
1289+
1290+
nval = fwnode_property_count_u8(function_node, "mipi-sdca-hid-descriptor");
1291+
if (nval)
1292+
fwnode_property_read_u8_array(function_node, "mipi-sdca-hid-descriptor", (u8 *)&hid_desc, nval);
1293+
memcpy(&hide->hid_desc, &hid_desc, sizeof(hid_desc));
1294+
1295+
printk("HIDE: num_hid_desc = %d, bLength=0x%x \
1296+
bDescriptorType=0x%x, bcdHID=0x%x, bCountryCode=0x%x bNumDescriptors=0x%x \n",
1297+
nval, hide->hid_desc.bLength, hide->hid_desc.bDescriptorType,
1298+
hide->hid_desc.bcdHID, hide->hid_desc.bCountryCode, hide->hid_desc.bNumDescriptors);
1299+
1300+
if (hid_desc.bNumDescriptors) {
1301+
nval = fwnode_property_count_u8(function_node, "mipi-sdca-report-descriptor");
1302+
if (nval) {
1303+
report_desc = devm_kzalloc(dev, nval, GFP_KERNEL);
1304+
if (!report_desc)
1305+
return -ENOMEM;
1306+
hide->hid_report_desc = report_desc;
1307+
fwnode_property_read_u8_array(function_node, "mipi-sdca-report-descriptor", report_desc, nval);
1308+
}
1309+
}
1310+
1311+
return 0;
1312+
}
1313+
12251314
static int find_sdca_entity(struct device *dev,
12261315
struct fwnode_handle *function_node,
12271316
struct fwnode_handle *entity_node,
@@ -1263,6 +1352,9 @@ static int find_sdca_entity(struct device *dev,
12631352
case SDCA_ENTITY_TYPE_GE:
12641353
ret = find_sdca_entity_ge(dev, entity_node, entity);
12651354
break;
1355+
case SDCA_ENTITY_TYPE_HIDE:
1356+
ret = find_sdca_entity_hide(dev, function_node, entity_node, entity);
1357+
break;
12661358
default:
12671359
break;
12681360
}

0 commit comments

Comments
 (0)