1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
/*
* The MIPI SDCA specification is available for public downloads at
* https://www.mipi.org/mipi-sdca-v1-0-download
*/
#include <linux/acpi.h>
#include <linux/byteorder/generic.h>
#include <linux/cleanup.h>
#include <linux/device.h>
#include <linux/dev_printk.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/soundwire/sdw.h>
#include <linux/types.h>
#include <sound/sdca.h>
#include <sound/sdca_function.h>
#include <sound/sdca_hid.h>
static int sdwhid_parse(struct hid_device *hid)
{
struct sdca_entity *entity = hid->driver_data;
unsigned int rsize;
int ret;
rsize = le16_to_cpu(entity->hide.hid_desc.rpt_desc.wDescriptorLength);
if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
dev_err(&hid->dev, "invalid size of report descriptor (%u)\n", rsize);
return -EINVAL;
}
ret = hid_parse_report(hid, entity->hide.hid_report_desc, rsize);
if (!ret)
return 0;
dev_err(&hid->dev, "parsing report descriptor failed\n");
return ret;
}
static int sdwhid_start(struct hid_device *hid)
{
return 0;
}
static void sdwhid_stop(struct hid_device *hid)
{
}
static int sdwhid_raw_request(struct hid_device *hid, unsigned char reportnum,
__u8 *buf, size_t len, unsigned char rtype, int reqtype)
{
switch (reqtype) {
case HID_REQ_GET_REPORT:
/* not implemented yet */
return 0;
case HID_REQ_SET_REPORT:
/* not implemented yet */
return 0;
default:
return -EIO;
}
}
static int sdwhid_open(struct hid_device *hid)
{
return 0;
}
static void sdwhid_close(struct hid_device *hid)
{
}
static const struct hid_ll_driver sdw_hid_driver = {
.parse = sdwhid_parse,
.start = sdwhid_start,
.stop = sdwhid_stop,
.open = sdwhid_open,
.close = sdwhid_close,
.raw_request = sdwhid_raw_request,
};
int sdca_add_hid_device(struct device *dev, struct sdca_entity *entity)
{
struct sdw_bus *bus;
struct hid_device *hid;
struct sdw_slave *slave = dev_to_sdw_dev(dev);
int ret;
bus = slave->bus;
hid = hid_allocate_device();
if (IS_ERR(hid))
return PTR_ERR(hid);
hid->ll_driver = &sdw_hid_driver;
hid->dev.parent = dev;
hid->bus = BUS_SDW;
hid->version = le16_to_cpu(entity->hide.hid_desc.bcdHID);
snprintf(hid->name, sizeof(hid->name),
"HID sdw:%01x:%01x:%04x:%04x:%02x",
bus->controller_id, bus->link_id, slave->id.mfg_id,
slave->id.part_id, slave->id.class_id);
snprintf(hid->phys, sizeof(hid->phys), "%s", dev->bus->name);
hid->driver_data = entity;
ret = hid_add_device(hid);
if (ret && ret != -ENODEV) {
dev_err(dev, "can't add hid device: %d\n", ret);
hid_destroy_device(hid);
return ret;
}
entity->hide.hid = hid;
return 0;
}
EXPORT_SYMBOL_NS(sdca_add_hid_device, "SND_SOC_SDCA");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("SDCA HID library");
|