Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v2.6.28-rc9 143 lines 3.9 kB view raw
1/* 2 * WUSB devices 3 * sysfs bindings 4 * 5 * Copyright (C) 2007 Intel Corporation 6 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License version 10 * 2 as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20 * 02110-1301, USA. 21 * 22 * 23 * Get them out of the way... 24 */ 25 26#include <linux/jiffies.h> 27#include <linux/ctype.h> 28#include <linux/workqueue.h> 29#include "wusbhc.h" 30 31#undef D_LOCAL 32#define D_LOCAL 4 33#include <linux/uwb/debug.h> 34 35static ssize_t wusb_disconnect_store(struct device *dev, 36 struct device_attribute *attr, 37 const char *buf, size_t size) 38{ 39 struct usb_device *usb_dev; 40 struct wusbhc *wusbhc; 41 unsigned command; 42 u8 port_idx; 43 44 if (sscanf(buf, "%u", &command) != 1) 45 return -EINVAL; 46 if (command == 0) 47 return size; 48 usb_dev = to_usb_device(dev); 49 wusbhc = wusbhc_get_by_usb_dev(usb_dev); 50 if (wusbhc == NULL) 51 return -ENODEV; 52 53 mutex_lock(&wusbhc->mutex); 54 port_idx = wusb_port_no_to_idx(usb_dev->portnum); 55 __wusbhc_dev_disable(wusbhc, port_idx); 56 mutex_unlock(&wusbhc->mutex); 57 wusbhc_put(wusbhc); 58 return size; 59} 60static DEVICE_ATTR(wusb_disconnect, 0200, NULL, wusb_disconnect_store); 61 62static ssize_t wusb_cdid_show(struct device *dev, 63 struct device_attribute *attr, char *buf) 64{ 65 ssize_t result; 66 struct wusb_dev *wusb_dev; 67 68 wusb_dev = wusb_dev_get_by_usb_dev(to_usb_device(dev)); 69 if (wusb_dev == NULL) 70 return -ENODEV; 71 result = ckhdid_printf(buf, PAGE_SIZE, &wusb_dev->cdid); 72 strcat(buf, "\n"); 73 wusb_dev_put(wusb_dev); 74 return result + 1; 75} 76static DEVICE_ATTR(wusb_cdid, 0444, wusb_cdid_show, NULL); 77 78static ssize_t wusb_ck_store(struct device *dev, 79 struct device_attribute *attr, 80 const char *buf, size_t size) 81{ 82 int result; 83 struct usb_device *usb_dev; 84 struct wusbhc *wusbhc; 85 struct wusb_ckhdid ck; 86 87 result = sscanf(buf, 88 "%02hhx %02hhx %02hhx %02hhx " 89 "%02hhx %02hhx %02hhx %02hhx " 90 "%02hhx %02hhx %02hhx %02hhx " 91 "%02hhx %02hhx %02hhx %02hhx\n", 92 &ck.data[0] , &ck.data[1], 93 &ck.data[2] , &ck.data[3], 94 &ck.data[4] , &ck.data[5], 95 &ck.data[6] , &ck.data[7], 96 &ck.data[8] , &ck.data[9], 97 &ck.data[10], &ck.data[11], 98 &ck.data[12], &ck.data[13], 99 &ck.data[14], &ck.data[15]); 100 if (result != 16) 101 return -EINVAL; 102 103 usb_dev = to_usb_device(dev); 104 wusbhc = wusbhc_get_by_usb_dev(usb_dev); 105 if (wusbhc == NULL) 106 return -ENODEV; 107 result = wusb_dev_4way_handshake(wusbhc, usb_dev->wusb_dev, &ck); 108 memset(&ck, 0, sizeof(ck)); 109 wusbhc_put(wusbhc); 110 return result < 0 ? result : size; 111} 112static DEVICE_ATTR(wusb_ck, 0200, NULL, wusb_ck_store); 113 114static struct attribute *wusb_dev_attrs[] = { 115 &dev_attr_wusb_disconnect.attr, 116 &dev_attr_wusb_cdid.attr, 117 &dev_attr_wusb_ck.attr, 118 NULL, 119}; 120 121static struct attribute_group wusb_dev_attr_group = { 122 .name = NULL, /* we want them in the same directory */ 123 .attrs = wusb_dev_attrs, 124}; 125 126int wusb_dev_sysfs_add(struct wusbhc *wusbhc, struct usb_device *usb_dev, 127 struct wusb_dev *wusb_dev) 128{ 129 int result = sysfs_create_group(&usb_dev->dev.kobj, 130 &wusb_dev_attr_group); 131 struct device *dev = &usb_dev->dev; 132 if (result < 0) 133 dev_err(dev, "Cannot register WUSB-dev attributes: %d\n", 134 result); 135 return result; 136} 137 138void wusb_dev_sysfs_rm(struct wusb_dev *wusb_dev) 139{ 140 struct usb_device *usb_dev = wusb_dev->usb_dev; 141 if (usb_dev) 142 sysfs_remove_group(&usb_dev->dev.kobj, &wusb_dev_attr_group); 143}