blob: 32747b7f917ee40ec63709df72bb5b3c53337445 [file] [log] [blame]
Bruno Prémontfabdbf22012-07-30 21:38:28 +02001/***************************************************************************
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 <linux/hid-debug.h>
22#include <linux/input.h>
23#include "hid-ids.h"
Bruno Prémontfabdbf22012-07-30 21:38:28 +020024
25#include <linux/fb.h>
26#include <linux/vmalloc.h>
27#include <linux/backlight.h>
28#include <linux/lcd.h>
29
30#include <linux/leds.h>
31
32#include <linux/seq_file.h>
33#include <linux/debugfs.h>
34
35#include <linux/completion.h>
36#include <linux/uaccess.h>
37#include <linux/module.h>
Bruno Prémontae08e322012-08-19 19:32:54 +020038#include <media/rc-core.h>
Bruno Prémontfabdbf22012-07-30 21:38:28 +020039
40#include "hid-picolcd.h"
41
42
43int picolcd_raw_cir(struct picolcd_data *data,
44 struct hid_report *report, u8 *raw_data, int size)
45{
Bruno Prémontae08e322012-08-19 19:32:54 +020046 unsigned long flags;
47 int i, w, sz;
48 DEFINE_IR_RAW_EVENT(rawir);
49
50 /* ignore if rc_dev is NULL or status is shunned */
51 spin_lock_irqsave(&data->lock, flags);
Dan Carpenter02d9be12012-09-07 09:47:41 +030052 if (!data->rc_dev || (data->status & PICOLCD_CIR_SHUN)) {
Bruno Prémontae08e322012-08-19 19:32:54 +020053 spin_unlock_irqrestore(&data->lock, flags);
54 return 1;
55 }
56 spin_unlock_irqrestore(&data->lock, flags);
57
58 /* PicoLCD USB packets contain 16-bit intervals in network order,
59 * with value negated for pulse. Intervals are in microseconds.
60 *
61 * Note: some userspace LIRC code for PicoLCD says negated values
62 * for space - is it a matter of IR chip? (pulse for my TSOP2236)
63 *
64 * In addition, the first interval seems to be around 15000 + base
65 * interval for non-first report of IR data - thus the quirk below
66 * to get RC_CODE to understand Sony and JVC remotes I have at hand
67 */
68 sz = size > 0 ? min((int)raw_data[0], size-1) : 0;
69 for (i = 0; i+1 < sz; i += 2) {
70 init_ir_raw_event(&rawir);
71 w = (raw_data[i] << 8) | (raw_data[i+1]);
72 rawir.pulse = !!(w & 0x8000);
73 rawir.duration = US_TO_NS(rawir.pulse ? (65536 - w) : w);
74 /* Quirk!! - see above */
75 if (i == 0 && rawir.duration > 15000000)
76 rawir.duration -= 15000000;
77 ir_raw_event_store(data->rc_dev, &rawir);
78 }
79 ir_raw_event_handle(data->rc_dev);
80
Bruno Prémontfabdbf22012-07-30 21:38:28 +020081 return 1;
82}
83
Bruno Prémontae08e322012-08-19 19:32:54 +020084static int picolcd_cir_open(struct rc_dev *dev)
85{
86 struct picolcd_data *data = dev->priv;
87 unsigned long flags;
88
89 spin_lock_irqsave(&data->lock, flags);
90 data->status &= ~PICOLCD_CIR_SHUN;
91 spin_unlock_irqrestore(&data->lock, flags);
92 return 0;
93}
94
95static void picolcd_cir_close(struct rc_dev *dev)
96{
97 struct picolcd_data *data = dev->priv;
98 unsigned long flags;
99
100 spin_lock_irqsave(&data->lock, flags);
101 data->status |= PICOLCD_CIR_SHUN;
102 spin_unlock_irqrestore(&data->lock, flags);
103}
104
Bruno Prémontfabdbf22012-07-30 21:38:28 +0200105/* initialize CIR input device */
106int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report)
107{
Bruno Prémontae08e322012-08-19 19:32:54 +0200108 struct rc_dev *rdev;
109 int ret = 0;
110
Andi Shyti0f7499f2016-12-16 06:50:58 -0200111 rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
Bruno Prémontae08e322012-08-19 19:32:54 +0200112 if (!rdev)
113 return -ENOMEM;
114
115 rdev->priv = data;
Sean Young6d741bf2017-08-07 16:20:58 -0400116 rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
Bruno Prémontae08e322012-08-19 19:32:54 +0200117 rdev->open = picolcd_cir_open;
118 rdev->close = picolcd_cir_close;
Sean Young518f4b22017-07-01 12:13:19 -0400119 rdev->device_name = data->hdev->name;
Bruno Prémontae08e322012-08-19 19:32:54 +0200120 rdev->input_phys = data->hdev->phys;
121 rdev->input_id.bustype = data->hdev->bus;
122 rdev->input_id.vendor = data->hdev->vendor;
123 rdev->input_id.product = data->hdev->product;
124 rdev->input_id.version = data->hdev->version;
125 rdev->dev.parent = &data->hdev->dev;
126 rdev->driver_name = PICOLCD_NAME;
127 rdev->map_name = RC_MAP_RC6_MCE;
128 rdev->timeout = MS_TO_NS(100);
129 rdev->rx_resolution = US_TO_NS(1);
130
131 ret = rc_register_device(rdev);
132 if (ret)
133 goto err;
134 data->rc_dev = rdev;
Bruno Prémontfabdbf22012-07-30 21:38:28 +0200135 return 0;
Bruno Prémontae08e322012-08-19 19:32:54 +0200136
137err:
138 rc_free_device(rdev);
139 return ret;
Bruno Prémontfabdbf22012-07-30 21:38:28 +0200140}
141
142void picolcd_exit_cir(struct picolcd_data *data)
143{
Bruno Prémontae08e322012-08-19 19:32:54 +0200144 struct rc_dev *rdev = data->rc_dev;
145
146 data->rc_dev = NULL;
Markus Elfring4b8a8262014-11-19 18:30:22 +0100147 rc_unregister_device(rdev);
Bruno Prémontfabdbf22012-07-30 21:38:28 +0200148}
149