19 #include <linux/device.h>
20 #include <linux/input.h>
21 #include <linux/hid.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
29 static struct class *isku_class;
31 static void isku_profile_activated(
struct isku_device *isku,
uint new_profile)
36 static int isku_receive(
struct usb_device *usb_dev,
uint command,
42 static int isku_get_actual_profile(
struct usb_device *usb_dev)
49 return retval ? retval :
buf.actual_profile;
52 static int isku_set_actual_profile(
struct usb_device *usb_dev,
int new_profile)
58 buf.actual_profile = new_profile;
72 static ssize_t isku_sysfs_set_actual_profile(
struct device *dev,
76 struct usb_device *usb_dev;
83 usb_dev = interface_to_usbdev(to_usb_interface(dev));
94 retval = isku_set_actual_profile(usb_dev, profile);
100 isku_profile_activated(isku, profile);
115 isku_sysfs_show_actual_profile,
116 isku_sysfs_set_actual_profile),
121 char *buf, loff_t off,
size_t count,
127 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
130 if (off >= real_size)
133 if (off != 0 || count != real_size)
137 retval = isku_receive(usb_dev, command, buf, real_size);
140 return retval ? retval : real_size;
144 void const *buf, loff_t off,
size_t count,
145 size_t real_size,
uint command)
150 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
153 if (off != 0 || count != real_size)
158 (
void *)buf, real_size);
161 return retval ? retval : real_size;
164 #define ISKU_SYSFS_W(thingy, THINGY) \
165 static ssize_t isku_sysfs_write_ ## thingy(struct file *fp, struct kobject *kobj, \
166 struct bin_attribute *attr, char *buf, \
167 loff_t off, size_t count) \
169 return isku_sysfs_write(fp, kobj, buf, off, count, \
170 sizeof(struct isku_ ## thingy), ISKU_COMMAND_ ## THINGY); \
173 #define ISKU_SYSFS_R(thingy, THINGY) \
174 static ssize_t isku_sysfs_read_ ## thingy(struct file *fp, struct kobject *kobj, \
175 struct bin_attribute *attr, char *buf, \
176 loff_t off, size_t count) \
178 return isku_sysfs_read(fp, kobj, buf, off, count, \
179 sizeof(struct isku_ ## thingy), ISKU_COMMAND_ ## THINGY); \
182 #define ISKU_SYSFS_RW(thingy, THINGY) \
183 ISKU_SYSFS_R(thingy, THINGY) \
184 ISKU_SYSFS_W(thingy, THINGY)
186 #define ISKU_BIN_ATTR_RW(thingy) \
188 .attr = { .name = #thingy, .mode = 0660 }, \
189 .size = sizeof(struct isku_ ## thingy), \
190 .read = isku_sysfs_read_ ## thingy, \
191 .write = isku_sysfs_write_ ## thingy \
194 #define ISKU_BIN_ATTR_R(thingy) \
196 .attr = { .name = #thingy, .mode = 0440 }, \
197 .size = sizeof(struct isku_ ## thingy), \
198 .read = isku_sysfs_read_ ## thingy, \
201 #define ISKU_BIN_ATTR_W(thingy) \
203 .attr = { .name = #thingy, .mode = 0220 }, \
204 .size = sizeof(struct isku_ ## thingy), \
205 .write = isku_sysfs_write_ ## thingy \
239 static int isku_init_isku_device_struct(
struct usb_device *usb_dev,
246 retval = isku_get_actual_profile(usb_dev);
249 isku_profile_activated(isku, retval);
254 static int isku_init_specials(
struct hid_device *hdev)
257 struct usb_device *usb_dev = interface_to_usbdev(intf);
261 if (intf->cur_altsetting->desc.bInterfaceProtocol
263 hid_set_drvdata(hdev,
NULL);
269 hid_err(hdev,
"can't alloc device descriptor\n");
272 hid_set_drvdata(hdev, isku);
274 retval = isku_init_isku_device_struct(usb_dev, isku);
276 hid_err(hdev,
"couldn't init struct isku_device\n");
283 hid_err(hdev,
"couldn't init char dev\n");
295 static void isku_remove_specials(
struct hid_device *hdev)
300 if (intf->cur_altsetting->desc.bInterfaceProtocol
304 isku = hid_get_drvdata(hdev);
310 static int isku_probe(
struct hid_device *hdev,
315 retval = hid_parse(hdev);
317 hid_err(hdev,
"parse failed\n");
323 hid_err(hdev,
"hw start failed\n");
327 retval = isku_init_specials(hdev);
329 hid_err(hdev,
"couldn't install keyboard\n");
341 static void isku_remove(
struct hid_device *hdev)
343 isku_remove_specials(hdev);
347 static void isku_keep_values_up_to_date(
struct isku_device *isku,
355 switch (button_report->
event) {
357 isku_profile_activated(isku, button_report->
data1 - 1);
364 static void isku_report_to_chrdev(
struct isku_device const *isku,
383 static int isku_raw_event(
struct hid_device *hdev,
389 if (intf->cur_altsetting->desc.bInterfaceProtocol
396 isku_keep_values_up_to_date(isku, data);
399 isku_report_to_chrdev(isku, data);
413 .id_table = isku_devices,
415 .remove = isku_remove,
416 .raw_event = isku_raw_event
419 static int __init isku_init(
void)
423 if (IS_ERR(isku_class))
424 return PTR_ERR(isku_class);
434 static void __exit isku_exit(
void)