Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /***************************************************************************
0003  *   Copyright (C) 2010-2012 by Bruno Prémont <bonbons@linux-vserver.org>  *
0004  *                                                                         *
0005  *   Based on Logitech G13 driver (v0.4)                                   *
0006  *     Copyright (C) 2009 by Rick L. Vinyard, Jr. <rvinyard@cs.nmsu.edu>   *
0007  *                                                                         *
0008  ***************************************************************************/
0009 
0010 #include <linux/hid.h>
0011 #include <linux/hid-debug.h>
0012 #include <linux/input.h>
0013 #include "hid-ids.h"
0014 
0015 #include <linux/fb.h>
0016 #include <linux/vmalloc.h>
0017 #include <linux/backlight.h>
0018 #include <linux/lcd.h>
0019 
0020 #include <linux/leds.h>
0021 
0022 #include <linux/seq_file.h>
0023 #include <linux/debugfs.h>
0024 
0025 #include <linux/completion.h>
0026 #include <linux/uaccess.h>
0027 #include <linux/module.h>
0028 #include <media/rc-core.h>
0029 
0030 #include "hid-picolcd.h"
0031 
0032 
0033 int picolcd_raw_cir(struct picolcd_data *data,
0034         struct hid_report *report, u8 *raw_data, int size)
0035 {
0036     unsigned long flags;
0037     int i, w, sz;
0038     struct ir_raw_event rawir = {};
0039 
0040     /* ignore if rc_dev is NULL or status is shunned */
0041     spin_lock_irqsave(&data->lock, flags);
0042     if (!data->rc_dev || (data->status & PICOLCD_CIR_SHUN)) {
0043         spin_unlock_irqrestore(&data->lock, flags);
0044         return 1;
0045     }
0046     spin_unlock_irqrestore(&data->lock, flags);
0047 
0048     /* PicoLCD USB packets contain 16-bit intervals in network order,
0049      * with value negated for pulse. Intervals are in microseconds.
0050      *
0051      * Note: some userspace LIRC code for PicoLCD says negated values
0052      * for space - is it a matter of IR chip? (pulse for my TSOP2236)
0053      *
0054      * In addition, the first interval seems to be around 15000 + base
0055      * interval for non-first report of IR data - thus the quirk below
0056      * to get RC_CODE to understand Sony and JVC remotes I have at hand
0057      */
0058     sz = size > 0 ? min((int)raw_data[0], size-1) : 0;
0059     for (i = 0; i+1 < sz; i += 2) {
0060         w = (raw_data[i] << 8) | (raw_data[i+1]);
0061         rawir.pulse = !!(w & 0x8000);
0062         rawir.duration = rawir.pulse ? (65536 - w) : w;
0063         /* Quirk!! - see above */
0064         if (i == 0 && rawir.duration > 15000)
0065             rawir.duration -= 15000;
0066         ir_raw_event_store(data->rc_dev, &rawir);
0067     }
0068     ir_raw_event_handle(data->rc_dev);
0069 
0070     return 1;
0071 }
0072 
0073 static int picolcd_cir_open(struct rc_dev *dev)
0074 {
0075     struct picolcd_data *data = dev->priv;
0076     unsigned long flags;
0077 
0078     spin_lock_irqsave(&data->lock, flags);
0079     data->status &= ~PICOLCD_CIR_SHUN;
0080     spin_unlock_irqrestore(&data->lock, flags);
0081     return 0;
0082 }
0083 
0084 static void picolcd_cir_close(struct rc_dev *dev)
0085 {
0086     struct picolcd_data *data = dev->priv;
0087     unsigned long flags;
0088 
0089     spin_lock_irqsave(&data->lock, flags);
0090     data->status |= PICOLCD_CIR_SHUN;
0091     spin_unlock_irqrestore(&data->lock, flags);
0092 }
0093 
0094 /* initialize CIR input device */
0095 int picolcd_init_cir(struct picolcd_data *data, struct hid_report *report)
0096 {
0097     struct rc_dev *rdev;
0098     int ret = 0;
0099 
0100     rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
0101     if (!rdev)
0102         return -ENOMEM;
0103 
0104     rdev->priv             = data;
0105     rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
0106     rdev->open             = picolcd_cir_open;
0107     rdev->close            = picolcd_cir_close;
0108     rdev->device_name      = data->hdev->name;
0109     rdev->input_phys       = data->hdev->phys;
0110     rdev->input_id.bustype = data->hdev->bus;
0111     rdev->input_id.vendor  = data->hdev->vendor;
0112     rdev->input_id.product = data->hdev->product;
0113     rdev->input_id.version = data->hdev->version;
0114     rdev->dev.parent       = &data->hdev->dev;
0115     rdev->driver_name      = PICOLCD_NAME;
0116     rdev->map_name         = RC_MAP_RC6_MCE;
0117     rdev->timeout          = MS_TO_US(100);
0118     rdev->rx_resolution    = 1;
0119 
0120     ret = rc_register_device(rdev);
0121     if (ret)
0122         goto err;
0123     data->rc_dev = rdev;
0124     return 0;
0125 
0126 err:
0127     rc_free_device(rdev);
0128     return ret;
0129 }
0130 
0131 void picolcd_exit_cir(struct picolcd_data *data)
0132 {
0133     struct rc_dev *rdev = data->rc_dev;
0134 
0135     data->rc_dev = NULL;
0136     rc_unregister_device(rdev);
0137 }
0138