Thomas Gleixner | 24c9d96 | 2019-05-29 07:12:39 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 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 | * * |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 8 | ***************************************************************************/ |
| 9 | |
| 10 | #include <linux/hid.h> |
| 11 | #include <linux/hid-debug.h> |
| 12 | #include <linux/input.h> |
| 13 | #include "hid-ids.h" |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 14 | |
| 15 | #include <linux/fb.h> |
| 16 | #include <linux/vmalloc.h> |
| 17 | #include <linux/backlight.h> |
| 18 | #include <linux/lcd.h> |
| 19 | |
| 20 | #include <linux/leds.h> |
| 21 | |
| 22 | #include <linux/seq_file.h> |
| 23 | #include <linux/debugfs.h> |
| 24 | |
| 25 | #include <linux/completion.h> |
| 26 | #include <linux/uaccess.h> |
| 27 | #include <linux/module.h> |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 28 | #include <media/rc-core.h> |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 29 | |
| 30 | #include "hid-picolcd.h" |
| 31 | |
| 32 | |
| 33 | int picolcd_raw_cir(struct picolcd_data *data, |
| 34 | struct hid_report *report, u8 *raw_data, int size) |
| 35 | { |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 36 | unsigned long flags; |
| 37 | int i, w, sz; |
Sean Young | 183e19f | 2018-08-21 15:57:52 -0400 | [diff] [blame] | 38 | struct ir_raw_event rawir = {}; |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 39 | |
| 40 | /* ignore if rc_dev is NULL or status is shunned */ |
| 41 | spin_lock_irqsave(&data->lock, flags); |
Dan Carpenter | 02d9be1 | 2012-09-07 09:47:41 +0300 | [diff] [blame] | 42 | if (!data->rc_dev || (data->status & PICOLCD_CIR_SHUN)) { |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 43 | spin_unlock_irqrestore(&data->lock, flags); |
| 44 | return 1; |
| 45 | } |
| 46 | spin_unlock_irqrestore(&data->lock, flags); |
| 47 | |
| 48 | /* PicoLCD USB packets contain 16-bit intervals in network order, |
| 49 | * with value negated for pulse. Intervals are in microseconds. |
| 50 | * |
| 51 | * Note: some userspace LIRC code for PicoLCD says negated values |
| 52 | * for space - is it a matter of IR chip? (pulse for my TSOP2236) |
| 53 | * |
| 54 | * In addition, the first interval seems to be around 15000 + base |
| 55 | * interval for non-first report of IR data - thus the quirk below |
| 56 | * to get RC_CODE to understand Sony and JVC remotes I have at hand |
| 57 | */ |
| 58 | sz = size > 0 ? min((int)raw_data[0], size-1) : 0; |
| 59 | for (i = 0; i+1 < sz; i += 2) { |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 60 | w = (raw_data[i] << 8) | (raw_data[i+1]); |
| 61 | rawir.pulse = !!(w & 0x8000); |
| 62 | rawir.duration = US_TO_NS(rawir.pulse ? (65536 - w) : w); |
| 63 | /* Quirk!! - see above */ |
| 64 | if (i == 0 && rawir.duration > 15000000) |
| 65 | rawir.duration -= 15000000; |
| 66 | ir_raw_event_store(data->rc_dev, &rawir); |
| 67 | } |
| 68 | ir_raw_event_handle(data->rc_dev); |
| 69 | |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 70 | return 1; |
| 71 | } |
| 72 | |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 73 | static int picolcd_cir_open(struct rc_dev *dev) |
| 74 | { |
| 75 | struct picolcd_data *data = dev->priv; |
| 76 | unsigned long flags; |
| 77 | |
| 78 | spin_lock_irqsave(&data->lock, flags); |
| 79 | data->status &= ~PICOLCD_CIR_SHUN; |
| 80 | spin_unlock_irqrestore(&data->lock, flags); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static void picolcd_cir_close(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 | } |
| 93 | |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 94 | /* initialize CIR input device */ |
| 95 | int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report) |
| 96 | { |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 97 | struct rc_dev *rdev; |
| 98 | int ret = 0; |
| 99 | |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 100 | rdev = rc_allocate_device(RC_DRIVER_IR_RAW); |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 101 | if (!rdev) |
| 102 | return -ENOMEM; |
| 103 | |
| 104 | rdev->priv = data; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 105 | rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 106 | rdev->open = picolcd_cir_open; |
| 107 | rdev->close = picolcd_cir_close; |
Sean Young | 518f4b2 | 2017-07-01 12:13:19 -0400 | [diff] [blame] | 108 | rdev->device_name = data->hdev->name; |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 109 | rdev->input_phys = data->hdev->phys; |
| 110 | rdev->input_id.bustype = data->hdev->bus; |
| 111 | rdev->input_id.vendor = data->hdev->vendor; |
| 112 | rdev->input_id.product = data->hdev->product; |
| 113 | rdev->input_id.version = data->hdev->version; |
| 114 | rdev->dev.parent = &data->hdev->dev; |
| 115 | rdev->driver_name = PICOLCD_NAME; |
| 116 | rdev->map_name = RC_MAP_RC6_MCE; |
| 117 | rdev->timeout = MS_TO_NS(100); |
| 118 | rdev->rx_resolution = US_TO_NS(1); |
| 119 | |
| 120 | ret = rc_register_device(rdev); |
| 121 | if (ret) |
| 122 | goto err; |
| 123 | data->rc_dev = rdev; |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 124 | return 0; |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 125 | |
| 126 | err: |
| 127 | rc_free_device(rdev); |
| 128 | return ret; |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void picolcd_exit_cir(struct picolcd_data *data) |
| 132 | { |
Bruno Prémont | ae08e32 | 2012-08-19 19:32:54 +0200 | [diff] [blame] | 133 | struct rc_dev *rdev = data->rc_dev; |
| 134 | |
| 135 | data->rc_dev = NULL; |
Markus Elfring | 4b8a826 | 2014-11-19 18:30:22 +0100 | [diff] [blame] | 136 | rc_unregister_device(rdev); |
Bruno Prémont | fabdbf2 | 2012-07-30 21:38:28 +0200 | [diff] [blame] | 137 | } |
| 138 | |