1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright (C) 2007 Intel Corporation
9 * Get them out of the way...
12 #include <linux/jiffies.h>
13 #include <linux/ctype.h>
14 #include <linux/workqueue.h>
17 static ssize_t wusb_disconnect_store(struct device *dev,
18 struct device_attribute *attr,
19 const char *buf, size_t size)
21 struct usb_device *usb_dev;
22 struct wusbhc *wusbhc;
26 if (sscanf(buf, "%u", &command) != 1)
30 usb_dev = to_usb_device(dev);
31 wusbhc = wusbhc_get_by_usb_dev(usb_dev);
35 mutex_lock(&wusbhc->mutex);
36 port_idx = wusb_port_no_to_idx(usb_dev->portnum);
37 __wusbhc_dev_disable(wusbhc, port_idx);
38 mutex_unlock(&wusbhc->mutex);
42 static DEVICE_ATTR_WO(wusb_disconnect);
44 static ssize_t wusb_cdid_show(struct device *dev,
45 struct device_attribute *attr, char *buf)
48 struct wusb_dev *wusb_dev;
50 wusb_dev = wusb_dev_get_by_usb_dev(to_usb_device(dev));
53 result = ckhdid_printf(buf, PAGE_SIZE, &wusb_dev->cdid);
55 wusb_dev_put(wusb_dev);
58 static DEVICE_ATTR_RO(wusb_cdid);
60 static ssize_t wusb_ck_store(struct device *dev,
61 struct device_attribute *attr,
62 const char *buf, size_t size)
65 struct usb_device *usb_dev;
66 struct wusbhc *wusbhc;
67 struct wusb_ckhdid ck;
70 "%02hhx %02hhx %02hhx %02hhx "
71 "%02hhx %02hhx %02hhx %02hhx "
72 "%02hhx %02hhx %02hhx %02hhx "
73 "%02hhx %02hhx %02hhx %02hhx\n",
74 &ck.data[0] , &ck.data[1],
75 &ck.data[2] , &ck.data[3],
76 &ck.data[4] , &ck.data[5],
77 &ck.data[6] , &ck.data[7],
78 &ck.data[8] , &ck.data[9],
79 &ck.data[10], &ck.data[11],
80 &ck.data[12], &ck.data[13],
81 &ck.data[14], &ck.data[15]);
85 usb_dev = to_usb_device(dev);
86 wusbhc = wusbhc_get_by_usb_dev(usb_dev);
89 result = wusb_dev_4way_handshake(wusbhc, usb_dev->wusb_dev, &ck);
90 memzero_explicit(&ck, sizeof(ck));
92 return result < 0 ? result : size;
94 static DEVICE_ATTR_WO(wusb_ck);
96 static struct attribute *wusb_dev_attrs[] = {
97 &dev_attr_wusb_disconnect.attr,
98 &dev_attr_wusb_cdid.attr,
99 &dev_attr_wusb_ck.attr,
103 static const struct attribute_group wusb_dev_attr_group = {
104 .name = NULL, /* we want them in the same directory */
105 .attrs = wusb_dev_attrs,
108 int wusb_dev_sysfs_add(struct wusbhc *wusbhc, struct usb_device *usb_dev,
109 struct wusb_dev *wusb_dev)
111 int result = sysfs_create_group(&usb_dev->dev.kobj,
112 &wusb_dev_attr_group);
113 struct device *dev = &usb_dev->dev;
115 dev_err(dev, "Cannot register WUSB-dev attributes: %d\n",
120 void wusb_dev_sysfs_rm(struct wusb_dev *wusb_dev)
122 struct usb_device *usb_dev = wusb_dev->usb_dev;
124 sysfs_remove_group(&usb_dev->dev.kobj, &wusb_dev_attr_group);