Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0-only
 2/***************************************************************************
 3 *   Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org>  *
 4 *                                                                         *
 5 *   Based on Logitech G13 driver (v0.4)                                   *
 6 *     Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu>   *
 7 *                                                                         *
 
 
 
 
 
 
 
 
 
 
 
 8 ***************************************************************************/
 9
10#include <linux/hid.h>
11
12#include <linux/fb.h>
13#include <linux/lcd.h>
14
15#include "hid-picolcd.h"
16
17/*
18 * lcd class device
19 */
20static int picolcd_get_contrast(struct lcd_device *ldev)
21{
22	struct picolcd_data *data = lcd_get_data(ldev);
23	return data->lcd_contrast;
24}
25
26static int picolcd_set_contrast(struct lcd_device *ldev, int contrast)
27{
28	struct picolcd_data *data = lcd_get_data(ldev);
29	struct hid_report *report = picolcd_out_report(REPORT_CONTRAST, data->hdev);
30	unsigned long flags;
31
32	if (!report || report->maxfield != 1 || report->field[0]->report_count != 1)
33		return -ENODEV;
34
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);
41	return 0;
42}
43
44static const struct lcd_ops picolcd_lcdops = {
 
 
 
 
 
45	.get_contrast   = picolcd_get_contrast,
46	.set_contrast   = picolcd_set_contrast,
 
47};
48
49int picolcd_init_lcd(struct picolcd_data *data, struct hid_report *report)
50{
51	struct device *dev = &data->hdev->dev;
52	struct lcd_device *ldev;
53
54	if (!report)
55		return -ENODEV;
56	if (report->maxfield != 1 || report->field[0]->report_count != 1 ||
57			report->field[0]->report_size != 8) {
58		dev_err(dev, "unsupported CONTRAST report");
59		return -EINVAL;
60	}
61
62	ldev = lcd_device_register(dev_name(dev), dev, data, &picolcd_lcdops);
63	if (IS_ERR(ldev)) {
64		dev_err(dev, "failed to register LCD\n");
65		return PTR_ERR(ldev);
66	}
67	ldev->props.max_contrast = 0x0ff;
68	data->lcd_contrast = 0xe5;
69	data->lcd = ldev;
70	picolcd_set_contrast(ldev, 0xe5);
71	return 0;
72}
73
74void picolcd_exit_lcd(struct picolcd_data *data)
75{
76	struct lcd_device *ldev = data->lcd;
77
78	data->lcd = NULL;
79	lcd_device_unregister(ldev);
 
80}
81
82int picolcd_resume_lcd(struct picolcd_data *data)
83{
84	if (!data->lcd)
85		return 0;
86	return picolcd_set_contrast(data->lcd, data->lcd_contrast);
87}
88
v3.15
 
  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
 22#include <linux/fb.h>
 23#include <linux/lcd.h>
 24
 25#include "hid-picolcd.h"
 26
 27/*
 28 * lcd class device
 29 */
 30static int picolcd_get_contrast(struct lcd_device *ldev)
 31{
 32	struct picolcd_data *data = lcd_get_data(ldev);
 33	return data->lcd_contrast;
 34}
 35
 36static int picolcd_set_contrast(struct lcd_device *ldev, int contrast)
 37{
 38	struct picolcd_data *data = lcd_get_data(ldev);
 39	struct hid_report *report = picolcd_out_report(REPORT_CONTRAST, data->hdev);
 40	unsigned long flags;
 41
 42	if (!report || report->maxfield != 1 || report->field[0]->report_count != 1)
 43		return -ENODEV;
 44
 45	data->lcd_contrast = contrast & 0x0ff;
 46	spin_lock_irqsave(&data->lock, flags);
 47	hid_set_field(report->field[0], 0, data->lcd_contrast);
 48	if (!(data->status & PICOLCD_FAILED))
 49		hid_hw_request(data->hdev, report, HID_REQ_SET_REPORT);
 50	spin_unlock_irqrestore(&data->lock, flags);
 51	return 0;
 52}
 53
 54static int picolcd_check_lcd_fb(struct lcd_device *ldev, struct fb_info *fb)
 55{
 56	return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev));
 57}
 58
 59static struct lcd_ops picolcd_lcdops = {
 60	.get_contrast   = picolcd_get_contrast,
 61	.set_contrast   = picolcd_set_contrast,
 62	.check_fb       = picolcd_check_lcd_fb,
 63};
 64
 65int picolcd_init_lcd(struct picolcd_data *data, struct hid_report *report)
 66{
 67	struct device *dev = &data->hdev->dev;
 68	struct lcd_device *ldev;
 69
 70	if (!report)
 71		return -ENODEV;
 72	if (report->maxfield != 1 || report->field[0]->report_count != 1 ||
 73			report->field[0]->report_size != 8) {
 74		dev_err(dev, "unsupported CONTRAST report");
 75		return -EINVAL;
 76	}
 77
 78	ldev = lcd_device_register(dev_name(dev), dev, data, &picolcd_lcdops);
 79	if (IS_ERR(ldev)) {
 80		dev_err(dev, "failed to register LCD\n");
 81		return PTR_ERR(ldev);
 82	}
 83	ldev->props.max_contrast = 0x0ff;
 84	data->lcd_contrast = 0xe5;
 85	data->lcd = ldev;
 86	picolcd_set_contrast(ldev, 0xe5);
 87	return 0;
 88}
 89
 90void picolcd_exit_lcd(struct picolcd_data *data)
 91{
 92	struct lcd_device *ldev = data->lcd;
 93
 94	data->lcd = NULL;
 95	if (ldev)
 96		lcd_device_unregister(ldev);
 97}
 98
 99int picolcd_resume_lcd(struct picolcd_data *data)
100{
101	if (!data->lcd)
102		return 0;
103	return picolcd_set_contrast(data->lcd, data->lcd_contrast);
104}
105