32 #include <linux/kernel.h>
33 #include <linux/errno.h>
35 #include <linux/slab.h>
36 #include <linux/module.h>
39 #include <linux/ctype.h>
41 #define ASUS_OLED_VERSION "0.04-dev"
42 #define ASUS_OLED_NAME "asus-oled"
43 #define ASUS_OLED_UNDERSCORE_NAME "asus_oled"
45 #define ASUS_OLED_STATIC 's'
46 #define ASUS_OLED_ROLL 'r'
47 #define ASUS_OLED_FLASH 'f'
49 #define ASUS_OLED_MAX_WIDTH 1792
50 #define ASUS_OLED_DISP_HEIGHT 32
51 #define ASUS_OLED_PACKET_BUF_SIZE 256
53 #define USB_VENDOR_ID_ASUS 0x0b05
54 #define USB_DEVICE_ID_ASUS_LCM 0x1726
55 #define USB_DEVICE_ID_ASUS_LCM2 0x175b
62 static struct class *oled_class;
65 static uint start_off;
70 "Set to 1 to switch off OLED display after it is attached");
149 packet->
header.magic1 = 0x55;
150 packet->
header.magic2 = 0xaa;
173 setup_packet_header(packet, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00);
181 usb_sndbulkpipe(odev->
udev, 2),
188 dev_dbg(&odev->
udev->dev,
"retval = %d\n", retval);
201 if (kstrtoul(buf, 10, &value))
204 enable_oled(odev, value);
211 const char *buf,
size_t count)
217 if (kstrtoul(buf, 10, &value))
220 enable_oled(odev, value);
234 static ssize_t class_get_enabled(
struct device *device,
243 static void send_packets(
struct usb_device *
udev,
245 char *buf,
uint8_t p_type,
size_t p_num)
250 for (i = 0; i < p_num; i++) {
255 setup_packet_header(packet, 0x40, 0x80, p_num,
256 i + 1, 0x00, 0x01, 0xff);
259 setup_packet_header(packet, 0x10 + i, 0x80, 0x01,
260 0x01, 0x00, 0x01, 0x00);
263 setup_packet_header(packet, 0x10 + i, 0x80, 0x01,
264 0x01, 0x00, 0x00, 0xff);
276 dev_dbg(&udev->dev,
"retval = %d\n", retval);
288 setup_packet_header(packet, b1, b2, b3, b4, b5, b6, 0x00);
292 usb_sndctrlpipe(udev, 2),
299 dev_dbg(&udev->dev,
"retval = %d\n", retval);
303 static void send_packets_g50(
struct usb_device *udev,
307 0x10, 0x00, 0x02, 0x01, 0x00, 0x01);
309 0x10, 0x00, 0x02, 0x02, 0x80, 0x00);
312 0x11, 0x00, 0x03, 0x01, 0x00, 0x01);
314 0x11, 0x00, 0x03, 0x02, 0x00, 0x01);
316 0x11, 0x00, 0x03, 0x03, 0x80, 0x00);
337 send_packets(odev->
udev, packet, odev->
buf,
344 send_packets(odev->
udev, packet, odev->
buf,
347 send_packets_g50(odev->
udev, packet, odev->
buf);
362 while (count-- > 0) {
386 dev_err(odev->
dev,
"Unknown OLED Pack Mode: %d!\n",
392 dev_err(odev->
dev,
"Buffer overflow! Report a bug:"
393 "offs: %d >= %d i: %d (x: %d y: %d)\n",
395 (
int) i, (
int) x, (
int) y);
401 odev->
buf[
i] &= ~(1<<(y%8));
405 odev->
buf[
i] &= ~(1<<(x%8));
420 const char *buf,
size_t count)
422 size_t offs = 0, max_offs;
444 for (i = 1; i < count && i <= 32 * 32; i++) {
445 odev->
buf[i-1] = buf[
i];
465 if (count < 10 || buf[2] !=
':')
476 dev_err(odev->
dev,
"Wrong picture mode: '%c'.\n",
482 for (i = 3; i <
count; ++
i) {
483 if (buf[i] >=
'0' && buf[i] <=
'9') {
484 w = 10*w + (buf[
i] -
'0');
488 }
else if (
tolower(buf[i]) ==
'x') {
495 for (++i; i <
count; ++
i) {
496 if (buf[i] >=
'0' && buf[i] <=
'9') {
497 h = 10*
h + (buf[
i] -
'0');
501 }
else if (
tolower(buf[i]) ==
'>') {
514 if (i >= count || buf[i] !=
'>')
524 if (
h < ASUS_OLED_DISP_HEIGHT)
550 if (
h < ASUS_OLED_DISP_HEIGHT/2)
551 odev->
y_shift = (ASUS_OLED_DISP_HEIGHT/2 -
h)/2;
553 if (
h < ASUS_OLED_DISP_HEIGHT)
554 odev->
y_shift = (ASUS_OLED_DISP_HEIGHT -
h)/2;
563 while (offs < count && odev->buf_offs < max_offs) {
566 if (buf[offs] ==
'1' || buf[offs] ==
'#') {
567 ret = append_values(odev, 1, 1);
570 }
else if (buf[offs] ==
'0' || buf[offs] ==
' ') {
571 ret = append_values(odev, 0, 1);
574 }
else if (buf[offs] ==
'\n') {
579 ret = append_values(odev, odev->
last_val,
596 dev_err(odev->
dev,
"Wrong picture width specified.\n");
600 dev_err(odev->
dev,
"Wrong picture height specified.\n");
604 dev_err(odev->
dev,
"Wrong picture header.\n");
609 const char *buf,
size_t count)
613 return odev_set_picture(usb_get_intfdata(intf), buf, count);
616 static ssize_t class_set_picture(
struct device *device,
618 const char *buf,
size_t count)
624 #define ASUS_OLED_DEVICE_ATTR(_file) dev_attr_asus_oled_##_file
627 get_enabled, set_enabled);
631 class_get_enabled, class_set_enabled);
637 struct usb_device *udev = interface_to_usbdev(interface);
647 dev_err(&interface->dev,
"No usb_device_id provided!\n");
651 for (; dev_desc->
idVendor; dev_desc++) {
663 "Missing or incomplete device description!\n");
670 dev_err(&interface->dev,
"Out of memory\n");
689 usb_set_intfdata(interface, odev);
702 NULL,
"oled_%d", ++oled_num);
704 if (IS_ERR(odev->
dev)) {
705 retval = PTR_ERR(odev->
dev);
713 goto err_class_enabled;
717 goto err_class_picture;
720 "Attached Asus OLED device: %s [width %u, pack_mode %d]\n",
724 enable_oled(odev, 0);
739 usb_set_intfdata(interface,
NULL);
746 static void asus_oled_disconnect(
struct usb_interface *interface)
750 odev = usb_get_intfdata(interface);
751 usb_set_intfdata(interface,
NULL);
766 dev_info(&interface->dev,
"Disconnected Asus OLED device\n");
774 odev = usb_get_intfdata(intf);
779 enable_oled(odev, 0);
788 odev = usb_get_intfdata(intf);
797 #define asus_oled_suspend NULL
798 #define asus_oled_resume NULL
801 static struct usb_driver oled_driver = {
803 .probe = asus_oled_probe,
804 .disconnect = asus_oled_disconnect,
805 .id_table = id_table,
813 static int __init asus_oled_init(
void)
818 if (IS_ERR(oled_class)) {
820 return PTR_ERR(oled_class);
825 pr_err(
"Error creating class version file\n");
829 retval = usb_register(&oled_driver);
832 pr_err(
"usb_register failed. Error number %d\n", retval);
843 static void __exit asus_oled_exit(
void)