1 // SPDX-License-Identifier: GPL-2.0-only
2 /***************************************************************************
3 * Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org> *
5 * Based on Logitech G13 driver (v0.4) *
6 * Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu> *
8 ***************************************************************************/
10 #include <linux/hid.h>
13 #include <linux/lcd.h>
15 #include "hid-picolcd.h"
20 static int picolcd_get_contrast(struct lcd_device
*ldev
)
22 struct picolcd_data
*data
= lcd_get_data(ldev
);
23 return data
->lcd_contrast
;
26 static int picolcd_set_contrast(struct lcd_device
*ldev
, int contrast
)
28 struct picolcd_data
*data
= lcd_get_data(ldev
);
29 struct hid_report
*report
= picolcd_out_report(REPORT_CONTRAST
, data
->hdev
);
32 if (!report
|| report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1)
35 data
->lcd_contrast
= contrast
& 0x0ff;
36 spin_lock_irqsave(&data
->lock
, flags
);
37 hid_set_field(report
->field
[0], 0, data
->lcd_contrast
);
38 if (!(data
->status
& PICOLCD_FAILED
))
39 hid_hw_request(data
->hdev
, report
, HID_REQ_SET_REPORT
);
40 spin_unlock_irqrestore(&data
->lock
, flags
);
44 static int picolcd_check_lcd_fb(struct lcd_device
*ldev
, struct fb_info
*fb
)
46 return fb
&& fb
== picolcd_fbinfo((struct picolcd_data
*)lcd_get_data(ldev
));
49 static struct lcd_ops picolcd_lcdops
= {
50 .get_contrast
= picolcd_get_contrast
,
51 .set_contrast
= picolcd_set_contrast
,
52 .check_fb
= picolcd_check_lcd_fb
,
55 int picolcd_init_lcd(struct picolcd_data
*data
, struct hid_report
*report
)
57 struct device
*dev
= &data
->hdev
->dev
;
58 struct lcd_device
*ldev
;
62 if (report
->maxfield
!= 1 || report
->field
[0]->report_count
!= 1 ||
63 report
->field
[0]->report_size
!= 8) {
64 dev_err(dev
, "unsupported CONTRAST report");
68 ldev
= lcd_device_register(dev_name(dev
), dev
, data
, &picolcd_lcdops
);
70 dev_err(dev
, "failed to register LCD\n");
73 ldev
->props
.max_contrast
= 0x0ff;
74 data
->lcd_contrast
= 0xe5;
76 picolcd_set_contrast(ldev
, 0xe5);
80 void picolcd_exit_lcd(struct picolcd_data
*data
)
82 struct lcd_device
*ldev
= data
->lcd
;
85 lcd_device_unregister(ldev
);
88 int picolcd_resume_lcd(struct picolcd_data
*data
)
92 return picolcd_set_contrast(data
->lcd
, data
->lcd_contrast
);