diff options
Diffstat (limited to 'drivers/hid/hid-picolcd_lcd.c')
-rw-r--r-- | drivers/hid/hid-picolcd_lcd.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/drivers/hid/hid-picolcd_lcd.c b/drivers/hid/hid-picolcd_lcd.c new file mode 100644 index 000000000000..64a067fc837c --- /dev/null +++ b/drivers/hid/hid-picolcd_lcd.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /*************************************************************************** | ||
2 | * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> * | ||
3 | * * | ||
4 | * Based on Logitech G13 driver (v0.4) * | ||
5 | * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> * | ||
6 | * * | ||
7 | * This program is free software: you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation, version 2 of the License. * | ||
10 | * * | ||
11 | * This driver is distributed in the hope that it will be useful, but * | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||
14 | * General Public License for more details. * | ||
15 | * * | ||
16 | * You should have received a copy of the GNU General Public License * | ||
17 | * along with this software. If not see <http://www.gnu.org/licenses/>. * | ||
18 | ***************************************************************************/ | ||
19 | |||
20 | #include <linux/hid.h> | ||
21 | #include "usbhid/usbhid.h" | ||
22 | #include <linux/usb.h> | ||
23 | |||
24 | #include <linux/fb.h> | ||
25 | #include <linux/lcd.h> | ||
26 | |||
27 | #include "hid-picolcd.h" | ||
28 | |||
29 | /* | ||
30 | * lcd class device | ||
31 | */ | ||
32 | static int picolcd_get_contrast(struct lcd_device *ldev) | ||
33 | { | ||
34 | struct picolcd_data *data = lcd_get_data(ldev); | ||
35 | return data->lcd_contrast; | ||
36 | } | ||
37 | |||
38 | static int picolcd_set_contrast(struct lcd_device *ldev, int contrast) | ||
39 | { | ||
40 | struct picolcd_data *data = lcd_get_data(ldev); | ||
41 | struct hid_report *report = picolcd_out_report(REPORT_CONTRAST, data->hdev); | ||
42 | unsigned long flags; | ||
43 | |||
44 | if (!report || report->maxfield != 1 || report->field[0]->report_count != 1) | ||
45 | return -ENODEV; | ||
46 | |||
47 | data->lcd_contrast = contrast & 0x0ff; | ||
48 | spin_lock_irqsave(&data->lock, flags); | ||
49 | hid_set_field(report->field[0], 0, data->lcd_contrast); | ||
50 | usbhid_submit_report(data->hdev, report, USB_DIR_OUT); | ||
51 | spin_unlock_irqrestore(&data->lock, flags); | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static int picolcd_check_lcd_fb(struct lcd_device *ldev, struct fb_info *fb) | ||
56 | { | ||
57 | return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev)); | ||
58 | } | ||
59 | |||
60 | static struct lcd_ops picolcd_lcdops = { | ||
61 | .get_contrast = picolcd_get_contrast, | ||
62 | .set_contrast = picolcd_set_contrast, | ||
63 | .check_fb = picolcd_check_lcd_fb, | ||
64 | }; | ||
65 | |||
66 | int picolcd_init_lcd(struct picolcd_data *data, struct hid_report *report) | ||
67 | { | ||
68 | struct device *dev = &data->hdev->dev; | ||
69 | struct lcd_device *ldev; | ||
70 | |||
71 | if (!report) | ||
72 | return -ENODEV; | ||
73 | if (report->maxfield != 1 || report->field[0]->report_count != 1 || | ||
74 | report->field[0]->report_size != 8) { | ||
75 | dev_err(dev, "unsupported CONTRAST report"); | ||
76 | return -EINVAL; | ||
77 | } | ||
78 | |||
79 | ldev = lcd_device_register(dev_name(dev), dev, data, &picolcd_lcdops); | ||
80 | if (IS_ERR(ldev)) { | ||
81 | dev_err(dev, "failed to register LCD\n"); | ||
82 | return PTR_ERR(ldev); | ||
83 | } | ||
84 | ldev->props.max_contrast = 0x0ff; | ||
85 | data->lcd_contrast = 0xe5; | ||
86 | data->lcd = ldev; | ||
87 | picolcd_set_contrast(ldev, 0xe5); | ||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | void picolcd_exit_lcd(struct picolcd_data *data) | ||
92 | { | ||
93 | struct lcd_device *ldev = data->lcd; | ||
94 | |||
95 | data->lcd = NULL; | ||
96 | if (ldev) | ||
97 | lcd_device_unregister(ldev); | ||
98 | } | ||
99 | |||
100 | int picolcd_resume_lcd(struct picolcd_data *data) | ||
101 | { | ||
102 | if (!data->lcd) | ||
103 | return 0; | ||
104 | return picolcd_set_contrast(data->lcd, data->lcd_contrast); | ||
105 | } | ||
106 | |||