1 /* If you are going to abuse the preprocessor, why not ABUSE the preprocessor? 2 I stuck this header in a separate file so I don't have to look at it */ 3 4 // FIXME Need locking or atomic ops 5 6 #define show_set_mbit(dname,value,bit) \ 7 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 8 { \ 9 struct usb_interface *intf = to_usb_interface(dev); \ 10 struct usb_##dname *t = usb_get_intfdata(intf); \ 11 int temp = (1 && (t->value & (1 << bit))); \ 12 return sprintf(buf, "%d\n", temp); \ 13 } \ 14 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 15 { \ 16 struct usb_interface *intf = to_usb_interface(dev); \ 17 struct usb_##dname *t = usb_get_intfdata(intf); \ 18 int temp = simple_strtoul(buf, NULL, 10); \ 19 if(temp > 0) { long b = 1 << bit; t->value |= b; } \ 20 else { long b = ~(1 << bit); t->value &= b ; \ 21 return count; \ 22 } \ 23 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 24 25 #define show_set_ebit(dname,enumname,value,bit) \ 26 static ssize_t show_##bit(struct device *dev, struct device_attribute *attr, char *buf) \ 27 { \ 28 struct usb_interface *intf = to_usb_interface(dev); \ 29 struct usb_##dname *t = usb_get_intfdata(intf); \ 30 enum enumname l = bit; \ 31 int temp = t->value & (1 << l); \ 32 return sprintf(buf, "%d\n", temp); \ 33 } \ 34 static ssize_t set_##bit(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 35 { \ 36 struct usb_interface *intf = to_usb_interface(dev); \ 37 struct usb_##dname *t = usb_get_intfdata(intf); \ 38 int temp = simple_strtoul(buf, NULL, 10); \ 39 enum enumname l = bit;\ 40 long b = 1 << l; \ 41 if(temp > 0) { t->value |= b; } \ 42 else { t->value &= ~b ; \ 43 return count; \ 44 } \ 45 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 46 47 // FIXME FOR CORRECTLY SETTING HEX from a string 48 #define show_set_mcmd(dname,value) \ 49 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 50 { \ 51 struct usb_interface *intf = to_usb_interface(dev); \ 52 struct usb_##dname *t = usb_get_intfdata(intf); \ 53 int count = 0;\ 54 int i; \ 55 for (i = 0,i<sizeof(dname); i++) count += snprintf(buf, "%02x",t->dname[i]); \ 56 return(count);\ 57 } \ 58 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 59 { \ 60 struct usb_interface *intf = to_usb_interface(dev); \ 61 struct usb_##dname *t = usb_get_intfdata(intf); \ 62 int temp = simple_strtoul(buf, NULL, 10); \ 63 t->value = temp; \ 64 return count; \ 65 } \ 66 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 67 68 #define show_set_mint(dname,value) \ 69 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 70 { \ 71 struct usb_interface *intf = to_usb_interface(dev); \ 72 struct usb_##dname *t = usb_get_intfdata(intf); \ 73 return sprintf(buf, "%d\n", t->value); \ 74 } \ 75 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 76 { \ 77 struct usb_interface *intf = to_usb_interface(dev); \ 78 struct usb_##dname *t = usb_get_intfdata(intf); \ 79 int temp = simple_strtoul(buf, NULL, 10); \ 80 t->value = temp; \ 81 return count; \ 82 } \ 83 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 84 85 #define show_set_mchar(dname,value) \ 86 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 87 { \ 88 struct usb_interface *intf = to_usb_interface(dev); \ 89 struct usb_##dname *t = usb_get_intfdata(intf); \ 90 return sprintf(buf, "%c\n", t->value); \ 91 } \ 92 static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 93 { \ 94 struct usb_interface *intf = to_usb_interface(dev); \ 95 struct usb_##dname *t = usb_get_intfdata(intf); \ 96 int temp = simple_strtoul(buf, NULL, 10); \ 97 t->value = temp; \ 98 return count; \ 99 } \ 100 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 101