2019-05-27 14:55:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-06-29 22:09:42 +08:00
|
|
|
/*
|
|
|
|
* SMI PCIe driver for DVBSky cards.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Max nibble <nibble.max@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "smipcie.h"
|
|
|
|
|
2019-01-24 08:04:20 +08:00
|
|
|
#define SMI_SAMPLE_PERIOD 83
|
|
|
|
#define SMI_SAMPLE_IDLEMIN (10000 / SMI_SAMPLE_PERIOD)
|
|
|
|
|
2015-06-29 22:09:42 +08:00
|
|
|
static void smi_ir_enableInterrupt(struct smi_rc *ir)
|
|
|
|
{
|
|
|
|
struct smi_dev *dev = ir->dev;
|
|
|
|
|
|
|
|
smi_write(MSI_INT_ENA_SET, IR_X_INT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smi_ir_disableInterrupt(struct smi_rc *ir)
|
|
|
|
{
|
|
|
|
struct smi_dev *dev = ir->dev;
|
|
|
|
|
|
|
|
smi_write(MSI_INT_ENA_CLR, IR_X_INT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smi_ir_clearInterrupt(struct smi_rc *ir)
|
|
|
|
{
|
|
|
|
struct smi_dev *dev = ir->dev;
|
|
|
|
|
|
|
|
smi_write(MSI_INT_STATUS_CLR, IR_X_INT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smi_ir_stop(struct smi_rc *ir)
|
|
|
|
{
|
|
|
|
struct smi_dev *dev = ir->dev;
|
|
|
|
|
|
|
|
smi_ir_disableInterrupt(ir);
|
2019-01-24 08:04:20 +08:00
|
|
|
smi_clear(IR_Init_Reg, rbIRen);
|
2015-06-29 22:09:42 +08:00
|
|
|
}
|
|
|
|
|
2019-01-24 08:04:20 +08:00
|
|
|
static void smi_raw_process(struct rc_dev *rc_dev, const u8 *buffer,
|
|
|
|
const u8 length)
|
2015-06-29 22:09:42 +08:00
|
|
|
{
|
2019-01-24 08:04:20 +08:00
|
|
|
struct ir_raw_event rawir = {};
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
for (cnt = 0; cnt < length; cnt++) {
|
|
|
|
if (buffer[cnt] & 0x7f) {
|
|
|
|
rawir.pulse = (buffer[cnt] & 0x80) == 0;
|
|
|
|
rawir.duration = ((buffer[cnt] & 0x7f) +
|
|
|
|
(rawir.pulse ? 0 : -1)) *
|
|
|
|
rc_dev->rx_resolution;
|
|
|
|
ir_raw_event_store_with_filter(rc_dev, &rawir);
|
2015-06-29 22:09:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 08:04:20 +08:00
|
|
|
static void smi_ir_decode(struct smi_rc *ir)
|
2015-06-29 22:09:42 +08:00
|
|
|
{
|
|
|
|
struct smi_dev *dev = ir->dev;
|
|
|
|
struct rc_dev *rc_dev = ir->rc_dev;
|
2019-01-24 08:04:20 +08:00
|
|
|
u32 dwIRControl, dwIRData;
|
|
|
|
u8 index, ucIRCount, readLoop;
|
2015-06-29 22:09:42 +08:00
|
|
|
|
|
|
|
dwIRControl = smi_read(IR_Init_Reg);
|
2019-01-24 08:04:20 +08:00
|
|
|
|
2015-06-29 22:09:42 +08:00
|
|
|
if (dwIRControl & rbIRVld) {
|
|
|
|
ucIRCount = (u8) smi_read(IR_Data_Cnt);
|
|
|
|
|
|
|
|
readLoop = ucIRCount/4;
|
|
|
|
if (ucIRCount % 4)
|
|
|
|
readLoop += 1;
|
|
|
|
for (index = 0; index < readLoop; index++) {
|
2019-01-24 08:04:20 +08:00
|
|
|
dwIRData = smi_read(IR_DATA_BUFFER_BASE + (index * 4));
|
2015-06-29 22:09:42 +08:00
|
|
|
|
|
|
|
ir->irData[index*4 + 0] = (u8)(dwIRData);
|
|
|
|
ir->irData[index*4 + 1] = (u8)(dwIRData >> 8);
|
|
|
|
ir->irData[index*4 + 2] = (u8)(dwIRData >> 16);
|
|
|
|
ir->irData[index*4 + 3] = (u8)(dwIRData >> 24);
|
|
|
|
}
|
2019-01-24 08:04:20 +08:00
|
|
|
smi_raw_process(rc_dev, ir->irData, ucIRCount);
|
|
|
|
smi_set(IR_Init_Reg, rbIRVld);
|
2015-06-29 22:09:42 +08:00
|
|
|
}
|
2019-01-24 08:04:20 +08:00
|
|
|
|
|
|
|
if (dwIRControl & rbIRhighidle) {
|
|
|
|
struct ir_raw_event rawir = {};
|
|
|
|
|
|
|
|
rawir.pulse = 0;
|
|
|
|
rawir.duration = US_TO_NS(SMI_SAMPLE_PERIOD *
|
|
|
|
SMI_SAMPLE_IDLEMIN);
|
|
|
|
ir_raw_event_store_with_filter(rc_dev, &rawir);
|
|
|
|
smi_set(IR_Init_Reg, rbIRhighidle);
|
|
|
|
}
|
|
|
|
|
|
|
|
ir_raw_event_handle(rc_dev);
|
2015-06-29 22:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ir functions call by main driver.*/
|
|
|
|
int smi_ir_irq(struct smi_rc *ir, u32 int_status)
|
|
|
|
{
|
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
if (int_status & IR_X_INT) {
|
|
|
|
smi_ir_disableInterrupt(ir);
|
|
|
|
smi_ir_clearInterrupt(ir);
|
2019-01-24 08:04:20 +08:00
|
|
|
smi_ir_decode(ir);
|
|
|
|
smi_ir_enableInterrupt(ir);
|
2015-06-29 22:09:42 +08:00
|
|
|
handled = 1;
|
|
|
|
}
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smi_ir_start(struct smi_rc *ir)
|
|
|
|
{
|
|
|
|
struct smi_dev *dev = ir->dev;
|
|
|
|
|
2019-01-24 08:04:20 +08:00
|
|
|
smi_write(IR_Idle_Cnt_Low,
|
|
|
|
(((SMI_SAMPLE_PERIOD - 1) & 0xFFFF) << 16) |
|
|
|
|
(SMI_SAMPLE_IDLEMIN & 0xFFFF));
|
2015-06-29 22:09:42 +08:00
|
|
|
msleep(20);
|
2019-01-24 08:04:20 +08:00
|
|
|
smi_set(IR_Init_Reg, rbIRen | rbIRhighidle);
|
2015-06-29 22:09:42 +08:00
|
|
|
|
|
|
|
smi_ir_enableInterrupt(ir);
|
|
|
|
}
|
|
|
|
|
|
|
|
int smi_ir_init(struct smi_dev *dev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct rc_dev *rc_dev;
|
|
|
|
struct smi_rc *ir = &dev->ir;
|
|
|
|
|
2019-01-24 08:04:20 +08:00
|
|
|
rc_dev = rc_allocate_device(RC_DRIVER_IR_RAW);
|
2015-06-29 22:09:42 +08:00
|
|
|
if (!rc_dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* init input device */
|
2017-07-02 00:13:19 +08:00
|
|
|
snprintf(ir->device_name, sizeof(ir->device_name), "IR (%s)",
|
2015-06-29 22:09:42 +08:00
|
|
|
dev->info->name);
|
|
|
|
snprintf(ir->input_phys, sizeof(ir->input_phys), "pci-%s/ir0",
|
|
|
|
pci_name(dev->pci_dev));
|
|
|
|
|
2019-01-24 08:04:20 +08:00
|
|
|
rc_dev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
|
2015-06-29 22:09:42 +08:00
|
|
|
rc_dev->driver_name = "SMI_PCIe";
|
|
|
|
rc_dev->input_phys = ir->input_phys;
|
2017-07-02 00:13:19 +08:00
|
|
|
rc_dev->device_name = ir->device_name;
|
2015-06-29 22:09:42 +08:00
|
|
|
rc_dev->input_id.bustype = BUS_PCI;
|
|
|
|
rc_dev->input_id.version = 1;
|
|
|
|
rc_dev->input_id.vendor = dev->pci_dev->subsystem_vendor;
|
|
|
|
rc_dev->input_id.product = dev->pci_dev->subsystem_device;
|
|
|
|
rc_dev->dev.parent = &dev->pci_dev->dev;
|
|
|
|
|
2016-03-11 14:48:03 +08:00
|
|
|
rc_dev->map_name = dev->info->rc_map;
|
2019-01-24 08:04:20 +08:00
|
|
|
rc_dev->timeout = MS_TO_NS(100);
|
|
|
|
rc_dev->rx_resolution = US_TO_NS(SMI_SAMPLE_PERIOD);
|
2015-06-29 22:09:42 +08:00
|
|
|
|
|
|
|
ir->rc_dev = rc_dev;
|
|
|
|
ir->dev = dev;
|
|
|
|
|
|
|
|
smi_ir_disableInterrupt(ir);
|
|
|
|
|
|
|
|
ret = rc_register_device(rc_dev);
|
|
|
|
if (ret)
|
|
|
|
goto ir_err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
ir_err:
|
|
|
|
rc_free_device(rc_dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smi_ir_exit(struct smi_dev *dev)
|
|
|
|
{
|
|
|
|
struct smi_rc *ir = &dev->ir;
|
|
|
|
struct rc_dev *rc_dev = ir->rc_dev;
|
|
|
|
|
|
|
|
smi_ir_stop(ir);
|
|
|
|
rc_unregister_device(rc_dev);
|
|
|
|
ir->rc_dev = NULL;
|
|
|
|
}
|