Skip to content

Commit

Permalink
[media] mantis: add remote control support
Browse files Browse the repository at this point in the history
The embedded UART is apparently used to receive decoded IR (RC5?) codes.
Forward these scan codes to the RC framework and (where known) add
corresponding mapping tables to translate them into regular keys.

This patch has been tested on a TechniSat CableStar HD2. The mappings of other
rc-maps were taken from Christoph Pinkl's patch
(http://patchwork.linuxtv.org/patch/7217/) and the s2-liplianin repository. The
major difference to Christoph's patch is a reworked interrupt handling of the
UART because the RX interrupt is apparently level triggered and requires
masking until the FIFO is read by the UART worker.

Signed-off-by: Jan Klötzke <jan@kloetzke.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
  • Loading branch information
Jan Klötzke authored and Mauro Carvalho Chehab committed Jun 10, 2015
1 parent 1c35cf9 commit a96762d
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 150 deletions.
13 changes: 11 additions & 2 deletions drivers/media/pci/mantis/hopper_cards.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
}
if (stat & MANTIS_INT_IRQ1) {
dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
spin_lock(&mantis->intmask_lock);
mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1, MANTIS_INT_MASK);
spin_unlock(&mantis->intmask_lock);
schedule_work(&mantis->uart_work);
}
if (stat & MANTIS_INT_OCERR) {
Expand Down Expand Up @@ -154,6 +157,7 @@ static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
static int hopper_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *pci_id)
{
struct mantis_pci_drvdata *drvdata;
struct mantis_pci *mantis;
struct mantis_hwconfig *config;
int err = 0;
Expand All @@ -165,12 +169,16 @@ static int hopper_pci_probe(struct pci_dev *pdev,
goto fail0;
}

drvdata = (struct mantis_pci_drvdata *) pci_id->driver_data;
mantis->num = devs;
mantis->verbose = verbose;
mantis->pdev = pdev;
config = (struct mantis_hwconfig *) pci_id->driver_data;
config = drvdata->hwconfig;
config->irq_handler = &hopper_irq_handler;
mantis->hwconfig = config;
mantis->rc_map_name = drvdata->rc_map_name;

spin_lock_init(&mantis->intmask_lock);

err = mantis_pci_init(mantis);
if (err) {
Expand Down Expand Up @@ -247,7 +255,8 @@ static void hopper_pci_remove(struct pci_dev *pdev)
}

static struct pci_device_id hopper_pci_table[] = {
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config,
NULL),
{ }
};

Expand Down
57 changes: 44 additions & 13 deletions drivers/media/pci/mantis/mantis_cards.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <linux/slab.h>
#include <asm/irq.h>
#include <linux/interrupt.h>
#include <media/rc-map.h>

#include "dmxdev.h"
#include "dvbdev.h"
Expand All @@ -49,6 +50,7 @@
#include "mantis_pci.h"
#include "mantis_i2c.h"
#include "mantis_reg.h"
#include "mantis_input.h"

static unsigned int verbose;
module_param(verbose, int, 0644);
Expand Down Expand Up @@ -114,6 +116,9 @@ static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
}
if (stat & MANTIS_INT_IRQ1) {
dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
spin_lock(&mantis->intmask_lock);
mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1, MANTIS_INT_MASK);
spin_unlock(&mantis->intmask_lock);
schedule_work(&mantis->uart_work);
}
if (stat & MANTIS_INT_OCERR) {
Expand Down Expand Up @@ -162,6 +167,7 @@ static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
static int mantis_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *pci_id)
{
struct mantis_pci_drvdata *drvdata;
struct mantis_pci *mantis;
struct mantis_hwconfig *config;
int err = 0;
Expand All @@ -172,12 +178,16 @@ static int mantis_pci_probe(struct pci_dev *pdev,
return -ENOMEM;
}

drvdata = (struct mantis_pci_drvdata *) pci_id->driver_data;
mantis->num = devs;
mantis->verbose = verbose;
mantis->pdev = pdev;
config = (struct mantis_hwconfig *) pci_id->driver_data;
config = drvdata->hwconfig;
config->irq_handler = &mantis_irq_handler;
mantis->hwconfig = config;
mantis->rc_map_name = drvdata->rc_map_name;

spin_lock_init(&mantis->intmask_lock);

err = mantis_pci_init(mantis);
if (err) {
Expand Down Expand Up @@ -215,16 +225,25 @@ static int mantis_pci_probe(struct pci_dev *pdev,
goto err_dma_exit;
}

err = mantis_input_init(mantis);
if (err < 0) {
dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
goto err_dvb_exit;
}

err = mantis_uart_init(mantis);
if (err < 0) {
dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
goto err_dvb_exit;
goto err_input_exit;
}

devs++;

return 0;

err_input_exit:
mantis_input_exit(mantis);

err_dvb_exit:
mantis_dvb_exit(mantis);

Expand All @@ -250,6 +269,7 @@ static void mantis_pci_remove(struct pci_dev *pdev)
if (mantis) {

mantis_uart_exit(mantis);
mantis_input_exit(mantis);
mantis_dvb_exit(mantis);
mantis_dma_exit(mantis);
mantis_i2c_exit(mantis);
Expand All @@ -260,17 +280,28 @@ static void mantis_pci_remove(struct pci_dev *pdev)
}

static struct pci_device_id mantis_pci_table[] = {
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config),
MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config),
MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config),
MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config),
MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config),
MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config),
MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config,
RC_MAP_TECHNISAT_TS35),
MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config,
NULL),
MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config,
NULL),
MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config,
RC_MAP_TERRATEC_CINERGY_C_PCI),
MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config,
RC_MAP_TERRATEC_CINERGY_S2_HD),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config,
NULL),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config,
NULL),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config,
RC_MAP_TWINHAN_DTV_CAB_CI),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config,
RC_MAP_TWINHAN_DTV_CAB_CI),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config,
NULL),
MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config,
NULL),
{ }
};

Expand Down
33 changes: 29 additions & 4 deletions drivers/media/pci/mantis/mantis_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <linux/mutex.h>
#include <linux/workqueue.h>

#include "mantis_reg.h"
#include "mantis_uart.h"

#include "mantis_link.h"
Expand Down Expand Up @@ -68,12 +69,13 @@
#define TECHNISAT 0x1ae4
#define TERRATEC 0x153b

#define MAKE_ENTRY(__subven, __subdev, __configptr) { \
#define MAKE_ENTRY(__subven, __subdev, __configptr, __rc) { \
.vendor = TWINHAN_TECHNOLOGIES, \
.device = MANTIS, \
.subvendor = (__subven), \
.subdevice = (__subdev), \
.driver_data = (unsigned long) (__configptr) \
.driver_data = (unsigned long) \
&(struct mantis_pci_drvdata){__configptr, __rc} \
}

enum mantis_i2c_mode {
Expand Down Expand Up @@ -101,6 +103,11 @@ struct mantis_hwconfig {
enum mantis_i2c_mode i2c_mode;
};

struct mantis_pci_drvdata {
struct mantis_hwconfig *hwconfig;
char *rc_map_name;
};

struct mantis_pci {
unsigned int verbose;

Expand Down Expand Up @@ -131,6 +138,7 @@ struct mantis_pci {
dma_addr_t risc_dma;

struct tasklet_struct tasklet;
spinlock_t intmask_lock;

struct i2c_adapter adapter;
int i2c_rc;
Expand Down Expand Up @@ -165,15 +173,32 @@ struct mantis_pci {

struct mantis_ca *mantis_ca;

wait_queue_head_t uart_wq;
struct work_struct uart_work;
spinlock_t uart_lock;

struct rc_dev *rc;
char input_name[80];
char input_phys[80];
char *rc_map_name;
};

#define MANTIS_HIF_STATUS (mantis->gpio_status)

static inline void mantis_mask_ints(struct mantis_pci *mantis, u32 mask)
{
unsigned long flags;

spin_lock_irqsave(&mantis->intmask_lock, flags);
mmwrite(mmread(MANTIS_INT_MASK) & ~mask, MANTIS_INT_MASK);
spin_unlock_irqrestore(&mantis->intmask_lock, flags);
}

static inline void mantis_unmask_ints(struct mantis_pci *mantis, u32 mask)
{
unsigned long flags;

spin_lock_irqsave(&mantis->intmask_lock, flags);
mmwrite(mmread(MANTIS_INT_MASK) | mask, MANTIS_INT_MASK);
spin_unlock_irqrestore(&mantis->intmask_lock, flags);
}

#endif /* __MANTIS_COMMON_H */
5 changes: 2 additions & 3 deletions drivers/media/pci/mantis/mantis_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void mantis_dma_start(struct mantis_pci *mantis)
mmwrite(0, MANTIS_DMA_CTL);
mantis->last_block = mantis->busy_block = 0;

mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_RISCI, MANTIS_INT_MASK);
mantis_unmask_ints(mantis, MANTIS_INT_RISCI);

mmwrite(MANTIS_FIFO_EN | MANTIS_DCAP_EN
| MANTIS_RISC_EN, MANTIS_DMA_CTL);
Expand All @@ -209,8 +209,7 @@ void mantis_dma_stop(struct mantis_pci *mantis)

mmwrite(mmread(MANTIS_INT_STAT), MANTIS_INT_STAT);

mmwrite(mmread(MANTIS_INT_MASK) & ~(MANTIS_INT_RISCI |
MANTIS_INT_RISCEN), MANTIS_INT_MASK);
mantis_mask_ints(mantis, MANTIS_INT_RISCI | MANTIS_INT_RISCEN);
}


Expand Down
8 changes: 2 additions & 6 deletions drivers/media/pci/mantis/mantis_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,16 @@ int mantis_i2c_init(struct mantis_pci *mantis)
intmask = mmread(MANTIS_INT_MASK);
mmwrite(intstat, MANTIS_INT_STAT);
dprintk(MANTIS_DEBUG, 1, "Disabling I2C interrupt");
intmask = mmread(MANTIS_INT_MASK);
mmwrite((intmask & ~MANTIS_INT_I2CDONE), MANTIS_INT_MASK);
mantis_mask_ints(mantis, MANTIS_INT_I2CDONE);

return 0;
}
EXPORT_SYMBOL_GPL(mantis_i2c_init);

int mantis_i2c_exit(struct mantis_pci *mantis)
{
u32 intmask;

dprintk(MANTIS_DEBUG, 1, "Disabling I2C interrupt");
intmask = mmread(MANTIS_INT_MASK);
mmwrite((intmask & ~MANTIS_INT_I2CDONE), MANTIS_INT_MASK);
mantis_mask_ints(mantis, MANTIS_INT_I2CDONE);

dprintk(MANTIS_DEBUG, 1, "Removing I2C adapter");
i2c_del_adapter(&mantis->adapter);
Expand Down
Loading

0 comments on commit a96762d

Please sign in to comment.