summaryrefslogtreecommitdiffstats
path: root/drivers/media/pci/ddbridge
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-02-06 20:27:48 +0100
committerLinus Torvalds <torvalds@linux-foundation.org>2018-02-06 20:27:48 +0100
commit68c5735eaa5e680e701c9a2d1e3c7880bdf5ab66 (patch)
tree4f584693638bf257b66a1646cc30d823cacc0a58 /drivers/media/pci/ddbridge
parentMerge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma (diff)
parentmedia: v4l2-compat-ioctl32.c: make ctrl_is_pointer work for subdevs (diff)
downloadlinux-68c5735eaa5e680e701c9a2d1e3c7880bdf5ab66.tar.xz
linux-68c5735eaa5e680e701c9a2d1e3c7880bdf5ab66.zip
Merge tag 'media/v4.16-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab: - videobuf2 was moved to a media/common dir, as it is now used by the DVB subsystem too - Digital TV core memory mapped support interface - new sensor driver: ov7740 - several improvements at ddbridge driver - new V4L2 driver: IPU3 CIO2 CSI-2 receiver unit, found on some Intel SoCs - new tuner driver: tda18250 - finally got rid of all LIRC staging drivers - as we don't have old lirc drivers anymore, restruct the lirc device code - add support for UVC metadata - add a new staging driver for NVIDIA Tegra Video Decoder Engine - DVB kAPI headers moved to include/media - synchronize the kAPI and uAPI for the DVB subsystem, removing the gap for non-legacy APIs - reduce the kAPI gap for V4L2 - lots of other driver enhancements, cleanups, etc. * tag 'media/v4.16-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (407 commits) media: v4l2-compat-ioctl32.c: make ctrl_is_pointer work for subdevs media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic media: v4l2-compat-ioctl32.c: don't copy back the result for certain errors media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32 media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32 media: v4l2-compat-ioctl32.c: avoid sizeof(type) media: v4l2-compat-ioctl32.c: move 'helper' functions to __get/put_v4l2_format32 media: v4l2-compat-ioctl32.c: fix the indentation media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF media: v4l2-ioctl.c: don't copy back the result for -ENOTTY media: v4l2-ioctl.c: use check_fmt for enum/g/s/try_fmt media: vivid: fix module load error when enabling fb and no_error_inj=1 media: dvb_demux: improve debug messages media: dvb_demux: Better handle discontinuity errors media: cxusb, dib0700: ignore XC2028_I2C_FLUSH media: ts2020: avoid integer overflows on 32 bit machines media: i2c: ov7740: use gpio/consumer.h instead of gpio.h media: entity: Add a nop variant of media_entity_cleanup ...
Diffstat (limited to 'drivers/media/pci/ddbridge')
-rw-r--r--drivers/media/pci/ddbridge/Makefile5
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-ci.c359
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-ci.h31
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-core.c651
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-hw.c8
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-i2c.c16
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-main.c23
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-max.c (renamed from drivers/media/pci/ddbridge/ddbridge-maxs8.c)54
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-max.h (renamed from drivers/media/pci/ddbridge/ddbridge-maxs8.h)12
-rw-r--r--drivers/media/pci/ddbridge/ddbridge-regs.h32
-rw-r--r--drivers/media/pci/ddbridge/ddbridge.h105
11 files changed, 697 insertions, 599 deletions
diff --git a/drivers/media/pci/ddbridge/Makefile b/drivers/media/pci/ddbridge/Makefile
index 7453b65104ff..f58fdec50eab 100644
--- a/drivers/media/pci/ddbridge/Makefile
+++ b/drivers/media/pci/ddbridge/Makefile
@@ -3,12 +3,11 @@
# Makefile for the ddbridge device driver
#
-ddbridge-objs := ddbridge-main.o ddbridge-core.o ddbridge-hw.o \
- ddbridge-i2c.o ddbridge-maxs8.o
+ddbridge-objs := ddbridge-main.o ddbridge-core.o ddbridge-ci.o \
+ ddbridge-hw.o ddbridge-i2c.o ddbridge-max.o
obj-$(CONFIG_DVB_DDBRIDGE) += ddbridge.o
-ccflags-y += -Idrivers/media/dvb-core/
ccflags-y += -Idrivers/media/dvb-frontends/
ccflags-y += -Idrivers/media/tuners/
diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c b/drivers/media/pci/ddbridge/ddbridge-ci.c
new file mode 100644
index 000000000000..5828111487b0
--- /dev/null
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.c
@@ -0,0 +1,359 @@
+/*
+ * ddbridge-ci.c: Digital Devices bridge CI (DuoFlex, CI Bridge) support
+ *
+ * Copyright (C) 2010-2017 Digital Devices GmbH
+ * Marcus Metzler <mocm@metzlerbros.de>
+ * Ralph Metzler <rjkm@metzlerbros.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 only, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * To obtain the license, point your browser to
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include "ddbridge.h"
+#include "ddbridge-regs.h"
+#include "ddbridge-ci.h"
+#include "ddbridge-io.h"
+#include "ddbridge-i2c.h"
+
+#include "cxd2099.h"
+
+/* Octopus CI internal CI interface */
+
+static int wait_ci_ready(struct ddb_ci *ci)
+{
+ u32 count = 10;
+
+ ndelay(500);
+ do {
+ if (ddbreadl(ci->port->dev,
+ CI_CONTROL(ci->nr)) & CI_READY)
+ break;
+ usleep_range(1, 2);
+ if ((--count) == 0)
+ return -1;
+ } while (1);
+ return 0;
+}
+
+static int read_attribute_mem(struct dvb_ca_en50221 *ca,
+ int slot, int address)
+{
+ struct ddb_ci *ci = ca->data;
+ u32 val, off = (address >> 1) & (CI_BUFFER_SIZE - 1);
+
+ if (address > CI_BUFFER_SIZE)
+ return -1;
+ ddbwritel(ci->port->dev, CI_READ_CMD | (1 << 16) | address,
+ CI_DO_READ_ATTRIBUTES(ci->nr));
+ wait_ci_ready(ci);
+ val = 0xff & ddbreadl(ci->port->dev, CI_BUFFER(ci->nr) + off);
+ return val;
+}
+
+static int write_attribute_mem(struct dvb_ca_en50221 *ca, int slot,
+ int address, u8 value)
+{
+ struct ddb_ci *ci = ca->data;
+
+ ddbwritel(ci->port->dev, CI_WRITE_CMD | (value << 16) | address,
+ CI_DO_ATTRIBUTE_RW(ci->nr));
+ wait_ci_ready(ci);
+ return 0;
+}
+
+static int read_cam_control(struct dvb_ca_en50221 *ca,
+ int slot, u8 address)
+{
+ u32 count = 100;
+ struct ddb_ci *ci = ca->data;
+ u32 res;
+
+ ddbwritel(ci->port->dev, CI_READ_CMD | address,
+ CI_DO_IO_RW(ci->nr));
+ ndelay(500);
+ do {
+ res = ddbreadl(ci->port->dev, CI_READDATA(ci->nr));
+ if (res & CI_READY)
+ break;
+ usleep_range(1, 2);
+ if ((--count) == 0)
+ return -1;
+ } while (1);
+ return 0xff & res;
+}
+
+static int write_cam_control(struct dvb_ca_en50221 *ca, int slot,
+ u8 address, u8 value)
+{
+ struct ddb_ci *ci = ca->data;
+
+ ddbwritel(ci->port->dev, CI_WRITE_CMD | (value << 16) | address,
+ CI_DO_IO_RW(ci->nr));
+ wait_ci_ready(ci);
+ return 0;
+}
+
+static int slot_reset(struct dvb_ca_en50221 *ca, int slot)
+{
+ struct ddb_ci *ci = ca->data;
+
+ ddbwritel(ci->port->dev, CI_POWER_ON,
+ CI_CONTROL(ci->nr));
+ msleep(100);
+ ddbwritel(ci->port->dev, CI_POWER_ON | CI_RESET_CAM,
+ CI_CONTROL(ci->nr));
+ ddbwritel(ci->port->dev, CI_ENABLE | CI_POWER_ON | CI_RESET_CAM,
+ CI_CONTROL(ci->nr));
+ usleep_range(20, 25);
+ ddbwritel(ci->port->dev, CI_ENABLE | CI_POWER_ON,
+ CI_CONTROL(ci->nr));
+ return 0;
+}
+
+static int slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
+{
+ struct ddb_ci *ci = ca->data;
+
+ ddbwritel(ci->port->dev, 0, CI_CONTROL(ci->nr));
+ msleep(300);
+ return 0;
+}
+
+static int slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
+{
+ struct ddb_ci *ci = ca->data;
+ u32 val = ddbreadl(ci->port->dev, CI_CONTROL(ci->nr));
+
+ ddbwritel(ci->port->dev, val | CI_BYPASS_DISABLE,
+ CI_CONTROL(ci->nr));
+ return 0;
+}
+
+static int poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
+{
+ struct ddb_ci *ci = ca->data;
+ u32 val = ddbreadl(ci->port->dev, CI_CONTROL(ci->nr));
+ int stat = 0;
+
+ if (val & CI_CAM_DETECT)
+ stat |= DVB_CA_EN50221_POLL_CAM_PRESENT;
+ if (val & CI_CAM_READY)
+ stat |= DVB_CA_EN50221_POLL_CAM_READY;
+ return stat;
+}
+
+static struct dvb_ca_en50221 en_templ = {
+ .read_attribute_mem = read_attribute_mem,
+ .write_attribute_mem = write_attribute_mem,
+ .read_cam_control = read_cam_control,
+ .write_cam_control = write_cam_control,
+ .slot_reset = slot_reset,
+ .slot_shutdown = slot_shutdown,
+ .slot_ts_enable = slot_ts_enable,
+ .poll_slot_status = poll_slot_status,
+};
+
+static void ci_attach(struct ddb_port *port)
+{
+ struct ddb_ci *ci = NULL;
+
+ ci = kzalloc(sizeof(*ci), GFP_KERNEL);
+ if (!ci)
+ return;
+ memcpy(&ci->en, &en_templ, sizeof(en_templ));
+ ci->en.data = ci;
+ port->en = &ci->en;
+ ci->port = port;
+ ci->nr = port->nr - 2;
+}
+
+/* DuoFlex Dual CI support */
+
+static int write_creg(struct ddb_ci *ci, u8 data, u8 mask)
+{
+ struct i2c_adapter *i2c = &ci->port->i2c->adap;
+ u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
+
+ ci->port->creg = (ci->port->creg & ~mask) | data;
+ return i2c_write_reg(i2c, adr, 0x02, ci->port->creg);
+}
+
+static int read_attribute_mem_xo2(struct dvb_ca_en50221 *ca,
+ int slot, int address)
+{
+ struct ddb_ci *ci = ca->data;
+ struct i2c_adapter *i2c = &ci->port->i2c->adap;
+ u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
+ int res;
+ u8 val;
+
+ res = i2c_read_reg16(i2c, adr, 0x8000 | address, &val);
+ return res ? res : val;
+}
+
+static int write_attribute_mem_xo2(struct dvb_ca_en50221 *ca, int slot,
+ int address, u8 value)
+{
+ struct ddb_ci *ci = ca->data;
+ struct i2c_adapter *i2c = &ci->port->i2c->adap;
+ u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
+
+ return i2c_write_reg16(i2c, adr, 0x8000 | address, value);
+}
+
+static int read_cam_control_xo2(struct dvb_ca_en50221 *ca,
+ int slot, u8 address)
+{
+ struct ddb_ci *ci = ca->data;
+ struct i2c_adapter *i2c = &ci->port->i2c->adap;
+ u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
+ u8 val;
+ int res;
+
+ res = i2c_read_reg(i2c, adr, 0x20 | (address & 3), &val);
+ return res ? res : val;
+}
+
+static int write_cam_control_xo2(struct dvb_ca_en50221 *ca, int slot,
+ u8 address, u8 value)
+{
+ struct ddb_ci *ci = ca->data;
+ struct i2c_adapter *i2c = &ci->port->i2c->adap;
+ u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
+
+ return i2c_write_reg(i2c, adr, 0x20 | (address & 3), value);
+}
+
+static int slot_reset_xo2(struct dvb_ca_en50221 *ca, int slot)
+{
+ struct ddb_ci *ci = ca->data;
+
+ dev_dbg(ci->port->dev->dev, "%s\n", __func__);
+ write_creg(ci, 0x01, 0x01);
+ write_creg(ci, 0x04, 0x04);
+ msleep(20);
+ write_creg(ci, 0x02, 0x02);
+ write_creg(ci, 0x00, 0x04);
+ write_creg(ci, 0x18, 0x18);
+ return 0;
+}
+
+static int slot_shutdown_xo2(struct dvb_ca_en50221 *ca, int slot)
+{
+ struct ddb_ci *ci = ca->data;
+
+ dev_dbg(ci->port->dev->dev, "%s\n", __func__);
+ write_creg(ci, 0x10, 0xff);
+ write_creg(ci, 0x08, 0x08);
+ return 0;
+}
+
+static int slot_ts_enable_xo2(struct dvb_ca_en50221 *ca, int slot)
+{
+ struct ddb_ci *ci = ca->data;
+
+ dev_dbg(ci->port->dev->dev, "%s\n", __func__);
+ write_creg(ci, 0x00, 0x10);
+ return 0;
+}
+
+static int poll_slot_status_xo2(struct dvb_ca_en50221 *ca, int slot, int open)
+{
+ struct ddb_ci *ci = ca->data;
+ struct i2c_adapter *i2c = &ci->port->i2c->adap;
+ u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
+ u8 val = 0;
+ int stat = 0;
+
+ i2c_read_reg(i2c, adr, 0x01, &val);
+
+ if (val & 2)
+ stat |= DVB_CA_EN50221_POLL_CAM_PRESENT;
+ if (val & 1)
+ stat |= DVB_CA_EN50221_POLL_CAM_READY;
+ return stat;
+}
+
+static struct dvb_ca_en50221 en_xo2_templ = {
+ .read_attribute_mem = read_attribute_mem_xo2,
+ .write_attribute_mem = write_attribute_mem_xo2,
+ .read_cam_control = read_cam_control_xo2,
+ .write_cam_control = write_cam_control_xo2,
+ .slot_reset = slot_reset_xo2,
+ .slot_shutdown = slot_shutdown_xo2,
+ .slot_ts_enable = slot_ts_enable_xo2,
+ .poll_slot_status = poll_slot_status_xo2,
+};
+
+static void ci_xo2_attach(struct ddb_port *port)
+{
+ struct ddb_ci *ci;
+
+ ci = kzalloc(sizeof(*ci), GFP_KERNEL);
+ if (!ci)
+ return;
+ memcpy(&ci->en, &en_xo2_templ, sizeof(en_xo2_templ));
+ ci->en.data = ci;
+ port->en = &ci->en;
+ ci->port = port;
+ ci->nr = port->nr - 2;
+ ci->port->creg = 0;
+ write_creg(ci, 0x10, 0xff);
+ write_creg(ci, 0x08, 0x08);
+}
+
+static struct cxd2099_cfg cxd_cfg = {
+ .bitrate = 72000,
+ .adr = 0x40,
+ .polarity = 1,
+ .clock_mode = 1,
+ .max_i2c = 512,
+};
+
+int ddb_ci_attach(struct ddb_port *port, u32 bitrate)
+{
+ switch (port->type) {
+ case DDB_CI_EXTERNAL_SONY:
+ cxd_cfg.bitrate = bitrate;
+ port->en = cxd2099_attach(&cxd_cfg, port, &port->i2c->adap);
+ if (!port->en)
+ return -ENODEV;
+ break;
+
+ case DDB_CI_EXTERNAL_XO2:
+ case DDB_CI_EXTERNAL_XO2_B:
+ ci_xo2_attach(port);
+ if (!port->en)
+ return -ENODEV;
+ break;
+
+ case DDB_CI_INTERNAL:
+ ci_attach(port);
+ if (!port->en)
+ return -ENODEV;
+ break;
+ }
+
+ dvb_ca_en50221_init(port->dvb[0].adap, port->en, 0, 1);
+ return 0;
+}
+
+void ddb_ci_detach(struct ddb_port *port)
+{
+ if (port->dvb[0].dev)
+ dvb_unregister_device(port->dvb[0].dev);
+ if (port->en) {
+ dvb_ca_en50221_release(port->en);
+ kfree(port->en->data);
+ port->en = NULL;
+ }
+}
diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.h b/drivers/media/pci/ddbridge/ddbridge-ci.h
new file mode 100644
index 000000000000..35a39182dd83
--- /dev/null
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.h
@@ -0,0 +1,31 @@
+/*
+ * ddbridge-ci.h: Digital Devices bridge CI (DuoFlex, CI Bridge) support
+ *
+ * Copyright (C) 2010-2017 Digital Devices GmbH
+ * Marcus Metzler <mocm@metzlerbros.de>
+ * Ralph Metzler <rjkm@metzlerbros.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 only, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * To obtain the license, point your browser to
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#ifndef __DDBRIDGE_CI_H__
+#define __DDBRIDGE_CI_H__
+
+#include "ddbridge.h"
+
+/******************************************************************************/
+
+int ddb_ci_attach(struct ddb_port *port, u32 bitrate);
+void ddb_ci_detach(struct ddb_port *port);
+
+#endif /* __DDBRIDGE_CI_H__ */
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
index 09a25d6c2cd1..42b42824382c 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -37,7 +37,8 @@
#include "ddbridge.h"
#include "ddbridge-i2c.h"
#include "ddbridge-regs.h"
-#include "ddbridge-maxs8.h"
+#include "ddbridge-max.h"
+#include "ddbridge-ci.h"
#include "ddbridge-io.h"
#include "tda18271c2dd.h"
@@ -112,7 +113,6 @@ static void ddb_set_dma_tables(struct ddb *dev)
}
}
-
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
@@ -210,8 +210,9 @@ static int ddb_redirect(u32 i, u32 p)
if (input->redi) {
input2->redi = input->redi;
input->redi = NULL;
- } else
+ } else {
input2->redi = input;
+ }
}
input->redo = port->output;
port->output->redi = input;
@@ -357,9 +358,9 @@ static void calc_con(struct ddb_output *output, u32 *con, u32 *con2, u32 flags)
max_bitrate = 0;
gap = 0;
if (bitrate != 72000) {
- if (bitrate >= 96000)
+ if (bitrate >= 96000) {
*con |= 0x800;
- else {
+ } else {
*con |= 0x1000;
nco = (bitrate * 8192 + 71999)
/ 72000;
@@ -506,7 +507,6 @@ static void ddb_input_start(struct ddb_input *input)
}
}
-
static void ddb_input_start_all(struct ddb_input *input)
{
struct ddb_input *i = input;
@@ -572,7 +572,7 @@ static ssize_t ddb_output_write(struct ddb_output *output,
while (left) {
len = output->dma->size - output->dma->coff;
if ((((output->dma->cbuf + 1) % output->dma->num) == idx) &&
- (off == 0)) {
+ off == 0) {
if (len <= 188)
break;
len -= 188;
@@ -593,7 +593,8 @@ static ssize_t ddb_output_write(struct ddb_output *output,
buf, len))
return -EIO;
if (alt_dma)
- dma_sync_single_for_device(dev->dev,
+ dma_sync_single_for_device(
+ dev->dev,
output->dma->pbuf[output->dma->cbuf],
output->dma->size, DMA_TO_DEVICE);
left -= len;
@@ -632,7 +633,7 @@ static u32 ddb_input_avail(struct ddb_input *input)
}
static ssize_t ddb_input_read(struct ddb_input *input,
- __user u8 *buf, size_t count)
+ __user u8 *buf, size_t count)
{
struct ddb *dev = input->port->dev;
u32 left = count;
@@ -648,7 +649,8 @@ static ssize_t ddb_input_read(struct ddb_input *input,
if (free > left)
free = left;
if (alt_dma)
- dma_sync_single_for_cpu(dev->dev,
+ dma_sync_single_for_cpu(
+ dev->dev,
input->dma->pbuf[input->dma->cbuf],
input->dma->size, DMA_FROM_DEVICE);
ret = copy_to_user(buf, input->dma->vbuf[input->dma->cbuf] +
@@ -792,8 +794,10 @@ static int ts_open(struct inode *inode, struct file *file)
} else if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
if (!output)
return -EINVAL;
- } else
+ } else {
return -EINVAL;
+ }
+
err = dvb_generic_open(inode, file);
if (err < 0)
return err;
@@ -822,7 +826,6 @@ static struct dvb_device dvbdev_ci = {
.fops = &ci_fops,
};
-
/****************************************************************************/
/****************************************************************************/
@@ -848,21 +851,20 @@ static int demod_attach_drxk(struct ddb_input *input)
struct i2c_adapter *i2c = &input->port->i2c->adap;
struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
struct device *dev = input->port->dev->dev;
- struct dvb_frontend *fe;
struct drxk_config config;
memset(&config, 0, sizeof(config));
config.adr = 0x29 + (input->nr & 1);
config.microcode_name = "drxk_a3.mc";
- fe = dvb->fe = dvb_attach(drxk_attach, &config, i2c);
- if (!fe) {
+ dvb->fe = dvb_attach(drxk_attach, &config, i2c);
+ if (!dvb->fe) {
dev_err(dev, "No DRXK found!\n");
return -ENODEV;
}
- fe->sec_priv = input;
- dvb->i2c_gate_ctrl = fe->ops.i2c_gate_ctrl;
- fe->ops.i2c_gate_ctrl = locked_gate_ctrl;
+ dvb->fe->sec_priv = input;
+ dvb->i2c_gate_ctrl = dvb->fe->ops.i2c_gate_ctrl;
+ dvb->fe->ops.i2c_gate_ctrl = locked_gate_ctrl;
return 0;
}
@@ -912,19 +914,18 @@ static int demod_attach_stv0367(struct ddb_input *input)
struct i2c_adapter *i2c = &input->port->i2c->adap;
struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
struct device *dev = input->port->dev->dev;
- struct dvb_frontend *fe;
/* attach frontend */
- fe = dvb->fe = dvb_attach(stv0367ddb_attach,
- &ddb_stv0367_config[(input->nr & 1)], i2c);
+ dvb->fe = dvb_attach(stv0367ddb_attach,
+ &ddb_stv0367_config[(input->nr & 1)], i2c);
if (!dvb->fe) {
dev_err(dev, "No stv0367 found!\n");
return -ENODEV;
}
- fe->sec_priv = input;
- dvb->i2c_gate_ctrl = fe->ops.i2c_gate_ctrl;
- fe->ops.i2c_gate_ctrl = locked_gate_ctrl;
+ dvb->fe->sec_priv = input;
+ dvb->i2c_gate_ctrl = dvb->fe->ops.i2c_gate_ctrl;
+ dvb->fe->ops.i2c_gate_ctrl = locked_gate_ctrl;
return 0;
}
@@ -956,7 +957,6 @@ static int demod_attach_cxd28xx(struct ddb_input *input, int par, int osc24)
struct i2c_adapter *i2c = &input->port->i2c->adap;
struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
struct device *dev = input->port->dev->dev;
- struct dvb_frontend *fe;
struct cxd2841er_config cfg;
/* the cxd2841er driver expects 8bit/shifted I2C addresses */
@@ -971,15 +971,15 @@ static int demod_attach_cxd28xx(struct ddb_input *input, int par, int osc24)
cfg.flags |= CXD2841ER_TS_SERIAL;
/* attach frontend */
- fe = dvb->fe = dvb_attach(cxd2841er_attach_t_c, &cfg, i2c);
+ dvb->fe = dvb_attach(cxd2841er_attach_t_c, &cfg, i2c);
if (!dvb->fe) {
dev_err(dev, "No cxd2837/38/43/54 found!\n");
return -ENODEV;
}
- fe->sec_priv = input;
- dvb->i2c_gate_ctrl = fe->ops.i2c_gate_ctrl;
- fe->ops.i2c_gate_ctrl = locked_gate_ctrl;
+ dvb->fe->sec_priv = input;
+ dvb->i2c_gate_ctrl = dvb->fe->ops.i2c_gate_ctrl;
+ dvb->fe->ops.i2c_gate_ctrl = locked_gate_ctrl;
return 0;
}
@@ -1020,7 +1020,7 @@ static int tuner_attach_tda18212(struct ddb_input *input, u32 porttype)
/* perform tuner init/attach */
client = i2c_new_device(adapter, &board_info);
- if (client == NULL || client->dev.driver == NULL)
+ if (!client || !client->dev.driver)
goto err;
if (!try_module_get(client->dev.driver->owner)) {
@@ -1032,7 +1032,7 @@ static int tuner_attach_tda18212(struct ddb_input *input, u32 porttype)
return 0;
err:
- dev_notice(dev, "TDA18212 tuner not found. Device is not fully operational.\n");
+ dev_err(dev, "TDA18212 tuner not found. Device is not fully operational.\n");
return -ENODEV;
}
@@ -1114,6 +1114,7 @@ static int demod_attach_stv0900(struct ddb_input *input, int type)
0, (input->nr & 1) ?
(0x09 - type) : (0x0b - type))) {
dev_err(dev, "No LNBH24 found!\n");
+ dvb_frontend_detach(dvb->fe);
return -ENODEV;
}
return 0;
@@ -1135,7 +1136,7 @@ static int tuner_attach_stv6110(struct ddb_input *input, int type)
return -ENODEV;
}
dev_info(dev, "attach tuner input %d adr %02x\n",
- input->nr, tunerconf->addr);
+ input->nr, tunerconf->addr);
feconf->tuner_init = ctl->tuner_init;
feconf->tuner_sleep = ctl->tuner_sleep;
@@ -1196,6 +1197,7 @@ static int demod_attach_stv0910(struct ddb_input *input, int type)
lnbcfg.i2c_address = (((input->nr & 1) ? 0x09 : 0x08) << 1);
if (!dvb_attach(lnbh25_attach, dvb->fe, &lnbcfg, i2c)) {
dev_err(dev, "No LNBH25 found!\n");
+ dvb_frontend_detach(dvb->fe);
return -ENODEV;
}
}
@@ -1261,19 +1263,22 @@ static void dvb_input_detach(struct ddb_input *input)
dvb_unregister_frontend(dvb->fe);
/* fallthrough */
case 0x30:
- if (dvb->fe2)
- dvb_frontend_detach(dvb->fe2);
- if (dvb->fe)
- dvb_frontend_detach(dvb->fe);
- dvb->fe = dvb->fe2 = NULL;
- /* fallthrough */
- case 0x20:
client = dvb->i2c_client[0];
if (client) {
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
+ dvb->i2c_client[0] = NULL;
+ client = NULL;
}
+ if (dvb->fe2)
+ dvb_frontend_detach(dvb->fe2);
+ if (dvb->fe)
+ dvb_frontend_detach(dvb->fe);
+ dvb->fe = NULL;
+ dvb->fe2 = NULL;
+ /* fallthrough */
+ case 0x20:
dvb_net_release(&dvb->dvbnet);
/* fallthrough */
case 0x12:
@@ -1409,7 +1414,8 @@ static int dvb_input_attach(struct ddb_input *input)
DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING;
dvbdemux->start_feed = start_feed;
dvbdemux->stop_feed = stop_feed;
- dvbdemux->filternum = dvbdemux->feednum = 256;
+ dvbdemux->filternum = 256;
+ dvbdemux->feednum = 256;
ret = dvb_dmx_init(dvbdemux);
if (ret < 0)
return ret;
@@ -1419,7 +1425,7 @@ static int dvb_input_attach(struct ddb_input *input)
dvb->dmxdev.demux = &dvbdemux->dmx;
ret = dvb_dmxdev_init(&dvb->dmxdev, adap);
if (ret < 0)
- return ret;
+ goto err_detach;
dvb->attached = 0x11;
dvb->mem_frontend.source = DMX_MEMORY_FE;
@@ -1428,66 +1434,62 @@ static int dvb_input_attach(struct ddb_input *input)
dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->hw_frontend);
ret = dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, &dvb->hw_frontend);
if (ret < 0)
- return ret;
+ goto err_detach;
dvb->attached = 0x12;
ret = dvb_net_init(adap, &dvb->dvbnet, dvb->dmxdev.demux);
if (ret < 0)
- return ret;
+ goto err_detach;
dvb->attached = 0x20;
- dvb->fe = dvb->fe2 = NULL;
+ dvb->fe = NULL;
+ dvb->fe2 = NULL;
switch (port->type) {
case DDB_TUNER_MXL5XX:
- if (fe_attach_mxl5xx(input) < 0)
- return -ENODEV;
+ if (ddb_fe_attach_mxl5xx(input) < 0)
+ goto err_detach;
break;
case DDB_TUNER_DVBS_ST:
if (demod_attach_stv0900(input, 0) < 0)
- return -ENODEV;
+ goto err_detach;
if (tuner_attach_stv6110(input, 0) < 0)
- return -ENODEV;
+ goto err_tuner;
break;
case DDB_TUNER_DVBS_ST_AA:
if (demod_attach_stv0900(input, 1) < 0)
- return -ENODEV;
+ goto err_detach;
if (tuner_attach_stv6110(input, 1) < 0)
- return -ENODEV;
+ goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910:
if (demod_attach_stv0910(input, 0) < 0)
- return -ENODEV;
+ goto err_detach;
if (tuner_attach_stv6111(input, 0) < 0)
- return -ENODEV;
+ goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910_PR:
if (demod_attach_stv0910(input, 1) < 0)
- return -ENODEV;
+ goto err_detach;
if (tuner_attach_stv6111(input, 1) < 0)
- return -ENODEV;
+ goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910_P:
if (demod_attach_stv0910(input, 0) < 0)
- return -ENODEV;
+ goto err_detach;
if (tuner_attach_stv6111(input, 1) < 0)
- return -ENODEV;
+ goto err_tuner;
break;
case DDB_TUNER_DVBCT_TR:
if (demod_attach_drxk(input) < 0)
- return -ENODEV;
+ goto err_detach;
if (tuner_attach_tda18271(input) < 0)
- return -ENODEV;
+ goto err_tuner;
break;
case DDB_TUNER_DVBCT_ST:
if (demod_attach_stv0367(input) < 0)
- return -ENODEV;
- if (tuner_attach_tda18212(input, port->type) < 0) {
- if (dvb->fe2)
- dvb_frontend_detach(dvb->fe2);
- if (dvb->fe)
- dvb_frontend_detach(dvb->fe);
- return -ENODEV;
- }
+ goto err_detach;
+ if (tuner_attach_tda18212(input, port->type) < 0)
+ goto err_tuner;
break;
case DDB_TUNER_DVBC2T2I_SONY_P:
if (input->port->dev->link[input->port->lnr].info->ts_quirks &
@@ -1505,14 +1507,9 @@ static int dvb_input_attach(struct ddb_input *input)
else
par = 1;
if (demod_attach_cxd28xx(input, par, osc24) < 0)
- return -ENODEV;
- if (tuner_attach_tda18212(input, port->type) < 0) {
- if (dvb->fe2)
- dvb_frontend_detach(dvb->fe2);
- if (dvb->fe)
- dvb_frontend_detach(dvb->fe);
- return -ENODEV;
- }
+ goto err_detach;
+ if (tuner_attach_tda18212(input, port->type) < 0)
+ goto err_tuner;
break;
case DDB_TUNER_DVBC2T2I_SONY:
osc24 = 1;
@@ -1521,14 +1518,9 @@ static int dvb_input_attach(struct ddb_input *input)
case DDB_TUNER_DVBC2T2_SONY:
case DDB_TUNER_ISDBT_SONY:
if (demod_attach_cxd28xx(input, 0, osc24) < 0)
- return -ENODEV;
- if (tuner_attach_tda18212(input, port->type) < 0) {
- if (dvb->fe2)
- dvb_frontend_detach(dvb->fe2);
- if (dvb->fe)
- dvb_frontend_detach(dvb->fe);
- return -ENODEV;
- }
+ goto err_detach;
+ if (tuner_attach_tda18212(input, port->type) < 0)
+ goto err_tuner;
break;
default:
return 0;
@@ -1537,11 +1529,13 @@ static int dvb_input_attach(struct ddb_input *input)
if (dvb->fe) {
if (dvb_register_frontend(adap, dvb->fe) < 0)
- return -ENODEV;
+ goto err_detach;
if (dvb->fe2) {
- if (dvb_register_frontend(adap, dvb->fe2) < 0)
- return -ENODEV;
+ if (dvb_register_frontend(adap, dvb->fe2) < 0) {
+ dvb_unregister_frontend(dvb->fe);
+ goto err_detach;
+ }
dvb->fe2->tuner_priv = dvb->fe->tuner_priv;
memcpy(&dvb->fe2->ops.tuner_ops,
&dvb->fe->ops.tuner_ops,
@@ -1551,6 +1545,22 @@ static int dvb_input_attach(struct ddb_input *input)
dvb->attached = 0x31;
return 0;
+
+err_tuner:
+ dev_err(port->dev->dev, "tuner attach failed!\n");
+
+ if (dvb->fe2)
+ dvb_frontend_detach(dvb->fe2);
+ if (dvb->fe)
+ dvb_frontend_detach(dvb->fe);
+err_detach:
+ dvb_input_detach(input);
+
+ /* return error from ret if set */
+ if (ret < 0)
+ return ret;
+
+ return -ENODEV;
}
static int port_has_encti(struct ddb_port *port)
@@ -1703,11 +1713,11 @@ static int init_xo2_ci(struct ddb_port *port)
if (data[0] > 1) {
dev_info(dev->dev, "Port %d: invalid XO2 CI %02x\n",
- port->nr, data[0]);
+ port->nr, data[0]);
return -1;
}
dev_info(dev->dev, "Port %d: DuoFlex CI %u.%u\n",
- port->nr, data[0], data[1]);
+ port->nr, data[0], data[1]);
i2c_read_reg(i2c, 0x10, 0x08, &val);
if (val != 0) {
@@ -1718,7 +1728,6 @@ static int init_xo2_ci(struct ddb_port *port)
i2c_write_reg(i2c, 0x10, 0x08, 3);
usleep_range(2000, 3000);
-
/* speed: 0=55,1=75,2=90,3=104 MBit/s */
i2c_write_reg(i2c, 0x10, 0x09, 1);
@@ -1821,7 +1830,7 @@ static void ddb_port_probe(struct ddb_port *port)
port->i2c->regs + I2C_TIMING);
} else {
dev_info(dev->dev, "Port %d: Uninitialized DuoFlex\n",
- port->nr);
+ port->nr);
return;
}
} else if (port_has_xo2(port, &type, &id)) {
@@ -1912,338 +1921,10 @@ static void ddb_port_probe(struct ddb_port *port)
}
}
-
-/****************************************************************************/
-/****************************************************************************/
-/****************************************************************************/
-
-static int wait_ci_ready(struct ddb_ci *ci)
-{
- u32 count = 10;
-
- ndelay(500);
- do {
- if (ddbreadl(ci->port->dev,
- CI_CONTROL(ci->nr)) & CI_READY)
- break;
- usleep_range(1, 2);
- if ((--count) == 0)
- return -1;
- } while (1);
- return 0;
-}
-
-static int read_attribute_mem(struct dvb_ca_en50221 *ca,
- int slot, int address)
-{
- struct ddb_ci *ci = ca->data;
- u32 val, off = (address >> 1) & (CI_BUFFER_SIZE - 1);
-
- if (address > CI_BUFFER_SIZE)
- return -1;
- ddbwritel(ci->port->dev, CI_READ_CMD | (1 << 16) | address,
- CI_DO_READ_ATTRIBUTES(ci->nr));
- wait_ci_ready(ci);
- val = 0xff & ddbreadl(ci->port->dev, CI_BUFFER(ci->nr) + off);
- return val;
-}
-
-static int write_attribute_mem(struct dvb_ca_en50221 *ca, int slot,
- int address, u8 value)
-{
- struct ddb_ci *ci = ca->data;
-
- ddbwritel(ci->port->dev, CI_WRITE_CMD | (value << 16) | address,
- CI_DO_ATTRIBUTE_RW(ci->nr));
- wait_ci_ready(ci);
- return 0;
-}
-
-static int read_cam_control(struct dvb_ca_en50221 *ca,
- int slot, u8 address)
-{
- u32 count = 100;
- struct ddb_ci *ci = ca->data;
- u32 res;
-
- ddbwritel(ci->port->dev, CI_READ_CMD | address,
- CI_DO_IO_RW(ci->nr));
- ndelay(500);
- do {
- res = ddbreadl(ci->port->dev, CI_READDATA(ci->nr));
- if (res & CI_READY)
- break;
- usleep_range(1, 2);
- if ((--count) == 0)
- return -1;
- } while (1);
- return 0xff & res;
-}
-
-static int write_cam_control(struct dvb_ca_en50221 *ca, int slot,
- u8 address, u8 value)
-{
- struct ddb_ci *ci = ca->data;
-
- ddbwritel(ci->port->dev, CI_WRITE_CMD | (value << 16) | address,
- CI_DO_IO_RW(ci->nr));
- wait_ci_ready(ci);
- return 0;
-}
-
-static int slot_reset(struct dvb_ca_en50221 *ca, int slot)
-{
- struct ddb_ci *ci = ca->data;
-
- ddbwritel(ci->port->dev, CI_POWER_ON,
- CI_CONTROL(ci->nr));
- msleep(100);
- ddbwritel(ci->port->dev, CI_POWER_ON | CI_RESET_CAM,
- CI_CONTROL(ci->nr));
- ddbwritel(ci->port->dev, CI_ENABLE | CI_POWER_ON | CI_RESET_CAM,
- CI_CONTROL(ci->nr));
- udelay(20);
- ddbwritel(ci->port->dev, CI_ENABLE | CI_POWER_ON,
- CI_CONTROL(ci->nr));
- return 0;
-}
-
-static int slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
-{
- struct ddb_ci *ci = ca->data;
-
- ddbwritel(ci->port->dev, 0, CI_CONTROL(ci->nr));
- msleep(300);
- return 0;
-}
-
-static int slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
-{
- struct ddb_ci *ci = ca->data;
- u32 val = ddbreadl(ci->port->dev, CI_CONTROL(ci->nr));
-
- ddbwritel(ci->port->dev, val | CI_BYPASS_DISABLE,
- CI_CONTROL(ci->nr));
- return 0;
-}
-
-static int poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
-{
- struct ddb_ci *ci = ca->data;
- u32 val = ddbreadl(ci->port->dev, CI_CONTROL(ci->nr));
- int stat = 0;
-
- if (val & CI_CAM_DETECT)
- stat |= DVB_CA_EN50221_POLL_CAM_PRESENT;
- if (val & CI_CAM_READY)
- stat |= DVB_CA_EN50221_POLL_CAM_READY;
- return stat;
-}
-
-static struct dvb_ca_en50221 en_templ = {
- .read_attribute_mem = read_attribute_mem,
- .write_attribute_mem = write_attribute_mem,
- .read_cam_control = read_cam_control,
- .write_cam_control = write_cam_control,
- .slot_reset = slot_reset,
- .slot_shutdown = slot_shutdown,
- .slot_ts_enable = slot_ts_enable,
- .poll_slot_status = poll_slot_status,
-};
-
-static void ci_attach(struct ddb_port *port)
-{
- struct ddb_ci *ci = NULL;
-
- ci = kzalloc(sizeof(*ci), GFP_KERNEL);
- if (!ci)
- return;
- memcpy(&ci->en, &en_templ, sizeof(en_templ));
- ci->en.data = ci;
- port->en = &ci->en;
- ci->port = port;
- ci->nr = port->nr - 2;
-}
-
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
-static int write_creg(struct ddb_ci *ci, u8 data, u8 mask)
-{
- struct i2c_adapter *i2c = &ci->port->i2c->adap;
- u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
-
- ci->port->creg = (ci->port->creg & ~mask) | data;
- return i2c_write_reg(i2c, adr, 0x02, ci->port->creg);
-}
-
-static int read_attribute_mem_xo2(struct dvb_ca_en50221 *ca,
- int slot, int address)
-{
- struct ddb_ci *ci = ca->data;
- struct i2c_adapter *i2c = &ci->port->i2c->adap;
- u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
- int res;
- u8 val;
-
- res = i2c_read_reg16(i2c, adr, 0x8000 | address, &val);
- return res ? res : val;
-}
-
-static int write_attribute_mem_xo2(struct dvb_ca_en50221 *ca, int slot,
- int address, u8 value)
-{
- struct ddb_ci *ci = ca->data;
- struct i2c_adapter *i2c = &ci->port->i2c->adap;
- u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
-
- return i2c_write_reg16(i2c, adr, 0x8000 | address, value);
-}
-
-static int read_cam_control_xo2(struct dvb_ca_en50221 *ca,
- int slot, u8 address)
-{
- struct ddb_ci *ci = ca->data;
- struct i2c_adapter *i2c = &ci->port->i2c->adap;
- u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
- u8 val;
- int res;
-
- res = i2c_read_reg(i2c, adr, 0x20 | (address & 3), &val);
- return res ? res : val;
-}
-
-static int write_cam_control_xo2(struct dvb_ca_en50221 *ca, int slot,
- u8 address, u8 value)
-{
- struct ddb_ci *ci = ca->data;
- struct i2c_adapter *i2c = &ci->port->i2c->adap;
- u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
-
- return i2c_write_reg(i2c, adr, 0x20 | (address & 3), value);
-}
-
-static int slot_reset_xo2(struct dvb_ca_en50221 *ca, int slot)
-{
- struct ddb_ci *ci = ca->data;
-
- dev_dbg(ci->port->dev->dev, "%s\n", __func__);
- write_creg(ci, 0x01, 0x01);
- write_creg(ci, 0x04, 0x04);
- msleep(20);
- write_creg(ci, 0x02, 0x02);
- write_creg(ci, 0x00, 0x04);
- write_creg(ci, 0x18, 0x18);
- return 0;
-}
-
-static int slot_shutdown_xo2(struct dvb_ca_en50221 *ca, int slot)
-{
- struct ddb_ci *ci = ca->data;
-
- dev_dbg(ci->port->dev->dev, "%s\n", __func__);
- write_creg(ci, 0x10, 0xff);
- write_creg(ci, 0x08, 0x08);
- return 0;
-}
-
-static int slot_ts_enable_xo2(struct dvb_ca_en50221 *ca, int slot)
-{
- struct ddb_ci *ci = ca->data;
-
- dev_info(ci->port->dev->dev, "%s\n", __func__);
- write_creg(ci, 0x00, 0x10);
- return 0;
-}
-
-static int poll_slot_status_xo2(struct dvb_ca_en50221 *ca, int slot, int open)
-{
- struct ddb_ci *ci = ca->data;
- struct i2c_adapter *i2c = &ci->port->i2c->adap;
- u8 adr = (ci->port->type == DDB_CI_EXTERNAL_XO2) ? 0x12 : 0x13;
- u8 val = 0;
- int stat = 0;
-
- i2c_read_reg(i2c, adr, 0x01, &val);
-
- if (val & 2)
- stat |= DVB_CA_EN50221_POLL_CAM_PRESENT;
- if (val & 1)
- stat |= DVB_CA_EN50221_POLL_CAM_READY;
- return stat;
-}
-
-static struct dvb_ca_en50221 en_xo2_templ = {
- .read_attribute_mem = read_attribute_mem_xo2,
- .write_attribute_mem = write_attribute_mem_xo2,
- .read_cam_control = read_cam_control_xo2,
- .write_cam_control = write_cam_control_xo2,
- .slot_reset = slot_reset_xo2,
- .slot_shutdown = slot_shutdown_xo2,
- .slot_ts_enable = slot_ts_enable_xo2,
- .poll_slot_status = poll_slot_status_xo2,
-};
-
-static void ci_xo2_attach(struct ddb_port *port)
-{
- struct ddb_ci *ci;
-
- ci = kzalloc(sizeof(*ci), GFP_KERNEL);
- if (!ci)
- return;
- memcpy(&ci->en, &en_xo2_templ, sizeof(en_xo2_templ));
- ci->en.data = ci;
- port->en = &ci->en;
- ci->port = port;
- ci->nr = port->nr - 2;
- ci->port->creg = 0;
- write_creg(ci, 0x10, 0xff);
- write_creg(ci, 0x08, 0x08);
-}
-
-/****************************************************************************/
-/****************************************************************************/
-/****************************************************************************/
-
-static struct cxd2099_cfg cxd_cfg = {
- .bitrate = 72000,
- .adr = 0x40,
- .polarity = 1,
- .clock_mode = 1,
- .max_i2c = 512,
-};
-
-static int ddb_ci_attach(struct ddb_port *port)
-{
- switch (port->type) {
- case DDB_CI_EXTERNAL_SONY:
- cxd_cfg.bitrate = ci_bitrate;
- port->en = cxd2099_attach(&cxd_cfg, port, &port->i2c->adap);
- if (!port->en)
- return -ENODEV;
- dvb_ca_en50221_init(port->dvb[0].adap,
- port->en, 0, 1);
- break;
-
- case DDB_CI_EXTERNAL_XO2:
- case DDB_CI_EXTERNAL_XO2_B:
- ci_xo2_attach(port);
- if (!port->en)
- return -ENODEV;
- dvb_ca_en50221_init(port->dvb[0].adap, port->en, 0, 1);
- break;
-
- case DDB_CI_INTERNAL:
- ci_attach(port);
- if (!port->en)
- return -ENODEV;
- dvb_ca_en50221_init(port->dvb[0].adap, port->en, 0, 1);
- break;
- }
- return 0;
-}
-
static int ddb_port_attach(struct ddb_port *port)
{
int ret = 0;
@@ -2254,20 +1935,22 @@ static int ddb_port_attach(struct ddb_port *port)
if (ret < 0)
break;
ret = dvb_input_attach(port->input[1]);
- if (ret < 0)
+ if (ret < 0) {
+ dvb_input_detach(port->input[0]);
break;
+ }
port->input[0]->redi = port->input[0];
port->input[1]->redi = port->input[1];
break;
case DDB_PORT_CI:
- ret = ddb_ci_attach(port);
+ ret = ddb_ci_attach(port, ci_bitrate);
if (ret < 0)
break;
/* fall-through */
case DDB_PORT_LOOP:
ret = dvb_register_device(port->dvb[0].adap,
&port->dvb[0].dev,
- &dvbdev_ci, (void *) port->output,
+ &dvbdev_ci, (void *)port->output,
DVB_DEVICE_SEC, 0);
break;
default:
@@ -2281,7 +1964,7 @@ static int ddb_port_attach(struct ddb_port *port)
int ddb_ports_attach(struct ddb *dev)
{
- int i, ret = 0;
+ int i, numports, err_ports = 0, ret = 0;
struct ddb_port *port;
if (dev->port_num) {
@@ -2291,11 +1974,31 @@ int ddb_ports_attach(struct ddb *dev)
return ret;
}
}
+
+ numports = dev->port_num;
+
for (i = 0; i < dev->port_num; i++) {
port = &dev->port[i];
- ret = ddb_port_attach(port);
+ if (port->class != DDB_PORT_NONE) {
+ ret = ddb_port_attach(port);
+ if (ret)
+ err_ports++;
+ } else {
+ numports--;
+ }
}
- return ret;
+
+ if (err_ports) {
+ if (err_ports == numports) {
+ dev_err(dev->dev, "All connected ports failed to initialise!\n");
+ return -ENODEV;
+ }
+
+ dev_warn(dev->dev, "%d of %d connected ports failed to initialise!\n",
+ err_ports, numports);
+ }
+
+ return 0;
}
void ddb_ports_detach(struct ddb *dev)
@@ -2308,25 +2011,18 @@ void ddb_ports_detach(struct ddb *dev)
switch (port->class) {
case DDB_PORT_TUNER:
- dvb_input_detach(port->input[0]);
dvb_input_detach(port->input[1]);
+ dvb_input_detach(port->input[0]);
break;
case DDB_PORT_CI:
case DDB_PORT_LOOP:
- if (port->dvb[0].dev)
- dvb_unregister_device(port->dvb[0].dev);
- if (port->en) {
- dvb_ca_en50221_release(port->en);
- kfree(port->en);
- port->en = NULL;
- }
+ ddb_ci_detach(port);
break;
}
}
dvb_unregister_adapters(dev);
}
-
/* Copy input DMA pointers to output DMA and ACK. */
static void input_write_output(struct ddb_input *input,
@@ -2353,16 +2049,18 @@ static void input_write_dvb(struct ddb_input *input,
struct ddb *dev = input->port->dev;
int ack = 1;
- dma = dma2 = input->dma;
- /* if there also is an output connected, do not ACK.
+ dma = input->dma;
+ dma2 = input->dma;
+ /*
+ * if there also is an output connected, do not ACK.
* input_write_output will ACK.
*/
if (input->redo) {
dma2 = input->redo->dma;
ack = 0;
}
- while (dma->cbuf != ((dma->stat >> 11) & 0x1f)
- || (4 & dma->ctrl)) {
+ while (dma->cbuf != ((dma->stat >> 11) & 0x1f) ||
+ (4 & dma->ctrl)) {
if (4 & dma->ctrl) {
/* dev_err(dev->dev, "Overflow dma %d\n", dma->nr); */
ack = 1;
@@ -2385,7 +2083,7 @@ static void input_write_dvb(struct ddb_input *input,
static void input_work(struct work_struct *work)
{
struct ddb_dma *dma = container_of(work, struct ddb_dma, work);
- struct ddb_input *input = (struct ddb_input *) dma->io;
+ struct ddb_input *input = (struct ddb_input *)dma->io;
struct ddb *dev = input->port->dev;
unsigned long flags;
@@ -2407,11 +2105,11 @@ static void input_work(struct work_struct *work)
static void input_handler(unsigned long data)
{
- struct ddb_input *input = (struct ddb_input *) data;
+ struct ddb_input *input = (struct ddb_input *)data;
struct ddb_dma *dma = input->dma;
-
- /* If there is no input connected, input_tasklet() will
+ /*
+ * If there is no input connected, input_tasklet() will
* just copy pointers and ACK. So, there is no need to go
* through the tasklet scheduler.
*/
@@ -2423,7 +2121,7 @@ static void input_handler(unsigned long data)
static void output_handler(unsigned long data)
{
- struct ddb_output *output = (struct ddb_output *) data;
+ struct ddb_output *output = (struct ddb_output *)data;
struct ddb_dma *dma = output->dma;
struct ddb *dev = output->port->dev;
@@ -2512,10 +2210,10 @@ static void ddb_input_init(struct ddb_port *port, int nr, int pnr, int anr)
dma_nr += 32 + (port->lnr - 1) * 8;
dev_dbg(dev->dev, "init link %u, input %u, handler %u\n",
- port->lnr, nr, dma_nr + base);
+ port->lnr, nr, dma_nr + base);
dev->handler[0][dma_nr + base] = input_handler;
- dev->handler_data[0][dma_nr + base] = (unsigned long) input;
+ dev->handler_data[0][dma_nr + base] = (unsigned long)input;
ddb_dma_init(input, dma_nr, 0);
}
}
@@ -2534,14 +2232,14 @@ static void ddb_output_init(struct ddb_port *port, int nr)
(rm->output->base + rm->output->size * nr);
dev_dbg(dev->dev, "init link %u, output %u, regs %08x\n",
- port->lnr, nr, output->regs);
+ port->lnr, nr, output->regs);
if (dev->has_dma) {
const struct ddb_regmap *rm0 = io_regmap(output, 0);
u32 base = rm0->irq_base_odma;
dev->handler[0][nr + base] = output_handler;
- dev->handler_data[0][nr + base] = (unsigned long) output;
+ dev->handler_data[0][nr + base] = (unsigned long)output;
ddb_dma_init(output, nr, 1);
}
}
@@ -2609,7 +2307,7 @@ void ddb_ports_init(struct ddb *dev)
port->dvb[0].adap = &dev->adap[2 * p];
port->dvb[1].adap = &dev->adap[2 * p + 1];
- if ((port->class == DDB_PORT_NONE) && i && p &&
+ if (port->class == DDB_PORT_NONE && i && p &&
dev->port[p - 1].type == DDB_CI_EXTERNAL_XO2) {
port->class = DDB_PORT_CI;
port->type = DDB_CI_EXTERNAL_XO2_B;
@@ -2618,8 +2316,8 @@ void ddb_ports_init(struct ddb *dev)
}
dev_info(dev->dev, "Port %u: Link %u, Link Port %u (TAB %u): %s\n",
- port->pnr, port->lnr, port->nr, port->nr + 1,
- port->name);
+ port->pnr, port->lnr, port->nr, port->nr + 1,
+ port->name);
if (port->class == DDB_PORT_CI &&
port->type == DDB_CI_EXTERNAL_XO2) {
@@ -2741,7 +2439,7 @@ static void irq_handle_io(struct ddb *dev, u32 s)
irqreturn_t ddb_irq_handler0(int irq, void *dev_id)
{
- struct ddb *dev = (struct ddb *) dev_id;
+ struct ddb *dev = (struct ddb *)dev_id;
u32 s = ddbreadl(dev, INTERRUPT_STATUS);
do {
@@ -2758,7 +2456,7 @@ irqreturn_t ddb_irq_handler0(int irq, void *dev_id)
irqreturn_t ddb_irq_handler1(int irq, void *dev_id)
{
- struct ddb *dev = (struct ddb *) dev_id;
+ struct ddb *dev = (struct ddb *)dev_id;
u32 s = ddbreadl(dev, INTERRUPT_STATUS);
do {
@@ -2775,7 +2473,7 @@ irqreturn_t ddb_irq_handler1(int irq, void *dev_id)
irqreturn_t ddb_irq_handler(int irq, void *dev_id)
{
- struct ddb *dev = (struct ddb *) dev_id;
+ struct ddb *dev = (struct ddb *)dev_id;
u32 s = ddbreadl(dev, INTERRUPT_STATUS);
int ret = IRQ_HANDLED;
@@ -2812,7 +2510,7 @@ static int reg_wait(struct ddb *dev, u32 reg, u32 bit)
}
static int flashio(struct ddb *dev, u32 lnr, u8 *wbuf, u32 wlen, u8 *rbuf,
- u32 rlen)
+ u32 rlen)
{
u32 data, shift;
u32 tag = DDB_LINK_TAG(lnr);
@@ -2823,7 +2521,7 @@ static int flashio(struct ddb *dev, u32 lnr, u8 *wbuf, u32 wlen, u8 *rbuf,
ddbwritel(dev, 1, tag | SPI_CONTROL);
while (wlen > 4) {
/* FIXME: check for big-endian */
- data = swab32(*(u32 *) wbuf);
+ data = swab32(*(u32 *)wbuf);
wbuf += 4;
wlen -= 4;
ddbwritel(dev, data, tag | SPI_DATA);
@@ -2863,12 +2561,12 @@ static int flashio(struct ddb *dev, u32 lnr, u8 *wbuf, u32 wlen, u8 *rbuf,
if (reg_wait(dev, tag | SPI_CONTROL, 4))
goto fail;
data = ddbreadl(dev, tag | SPI_DATA);
- *(u32 *) rbuf = swab32(data);
+ *(u32 *)rbuf = swab32(data);
rbuf += 4;
rlen -= 4;
}
ddbwritel(dev, 0x0003 | ((rlen << (8 + 3)) & 0x1F00),
- tag | SPI_CONTROL);
+ tag | SPI_CONTROL);
ddbwritel(dev, 0xffffffff, tag | SPI_DATA);
if (reg_wait(dev, tag | SPI_CONTROL, 4))
goto fail;
@@ -3011,7 +2709,7 @@ static ssize_t fan_store(struct device *device, struct device_attribute *d,
}
static ssize_t fanspeed_show(struct device *device,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
struct ddb *dev = dev_get_drvdata(device);
int num = attr->attr.name[8] - 0x30;
@@ -3049,7 +2747,7 @@ static ssize_t temp_show(struct device *device,
}
static ssize_t ctemp_show(struct device *device,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
struct ddb *dev = dev_get_drvdata(device);
struct i2c_adapter *adap;
@@ -3076,7 +2774,6 @@ static ssize_t led_show(struct device *device,
return sprintf(buf, "%d\n", dev->leds & (1 << num) ? 1 : 0);
}
-
static void ddb_set_led(struct ddb *dev, int num, int val)
{
if (!dev->link[0].info->led_num)
@@ -3163,7 +2860,7 @@ static ssize_t bsnr_show(struct device *device,
}
static ssize_t bpsnr_show(struct device *device,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
struct ddb *dev = dev_get_drvdata(device);
unsigned char snr[32];
@@ -3208,7 +2905,6 @@ static ssize_t gap_show(struct device *device,
int num = attr->attr.name[3] - 0x30;
return sprintf(buf, "%d\n", dev->port[num].gap);
-
}
static ssize_t gap_store(struct device *device, struct device_attribute *attr,
@@ -3254,7 +2950,7 @@ static ssize_t regmap_show(struct device *device,
}
static ssize_t fmode_show(struct device *device,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
int num = attr->attr.name[5] - 0x30;
struct ddb *dev = dev_get_drvdata(device);
@@ -3272,7 +2968,7 @@ static ssize_t devid_show(struct device *device,
}
static ssize_t fmode_store(struct device *device, struct device_attribute *attr,
- const char *buf, size_t count)
+ const char *buf, size_t count)
{
struct ddb *dev = dev_get_drvdata(device);
int num = attr->attr.name[5] - 0x30;
@@ -3282,7 +2978,7 @@ static ssize_t fmode_store(struct device *device, struct device_attribute *attr,
return -EINVAL;
if (val > 3)
return -EINVAL;
- lnb_init_fmode(dev, &dev->link[num], val);
+ ddb_lnb_init_fmode(dev, &dev->link[num], val);
return count;
}
@@ -3387,7 +3083,7 @@ static void ddb_device_attrs_del(struct ddb *dev)
device_remove_file(dev->ddb_dev, &ddb_attrs_snr[i]);
device_remove_file(dev->ddb_dev, &ddb_attrs_ctemp[i]);
}
- for (i = 0; ddb_attrs[i].attr.name != NULL; i++)
+ for (i = 0; ddb_attrs[i].attr.name; i++)
device_remove_file(dev->ddb_dev, &ddb_attrs[i]);
}
@@ -3395,7 +3091,7 @@ static int ddb_device_attrs_add(struct ddb *dev)
{
int i;
- for (i = 0; ddb_attrs[i].attr.name != NULL; i++)
+ for (i = 0; ddb_attrs[i].attr.name; i++)
if (device_create_file(dev->ddb_dev, &ddb_attrs[i]))
goto fail;
for (i = 0; i < dev->link[0].info->temp_num; i++)
@@ -3447,8 +3143,9 @@ int ddb_device_create(struct ddb *dev)
device_destroy(&ddb_class, MKDEV(ddb_major, dev->nr));
ddbs[dev->nr] = NULL;
dev->ddb_dev = ERR_PTR(-ENODEV);
- } else
+ } else {
ddb_num++;
+ }
fail:
mutex_unlock(&ddb_mutex);
return res;
@@ -3500,7 +3197,7 @@ static void tempmon_setfan(struct ddb_link *link)
static void temp_handler(unsigned long data)
{
- struct ddb_link *link = (struct ddb_link *) data;
+ struct ddb_link *link = (struct ddb_link *)data;
spin_lock(&link->temp_lock);
tempmon_setfan(link);
@@ -3519,10 +3216,10 @@ static int tempmon_init(struct ddb_link *link, int first_time)
30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80 };
memcpy(link->temp_tab, temperature_table,
- sizeof(temperature_table));
+ sizeof(temperature_table));
}
dev->handler[l][link->info->tempmon_irq] = temp_handler;
- dev->handler_data[l][link->info->tempmon_irq] = (unsigned long) link;
+ dev->handler_data[l][link->info->tempmon_irq] = (unsigned long)link;
ddblwritel(link, (TEMPMON_CONTROL_OVERTEMP | TEMPMON_CONTROL_AUTOSCAN |
TEMPMON_CONTROL_INTENABLE),
TEMPMON_CONTROL);
@@ -3574,11 +3271,11 @@ static int ddb_init_boards(struct ddb *dev)
ddbwritel(dev, 0, DDB_LINK_TAG(l) | BOARD_CONTROL);
msleep(100);
ddbwritel(dev, info->board_control_2,
- DDB_LINK_TAG(l) | BOARD_CONTROL);
+ DDB_LINK_TAG(l) | BOARD_CONTROL);
usleep_range(2000, 3000);
ddbwritel(dev,
- info->board_control_2 | info->board_control,
- DDB_LINK_TAG(l) | BOARD_CONTROL);
+ info->board_control_2 | info->board_control,
+ DDB_LINK_TAG(l) | BOARD_CONTROL);
usleep_range(2000, 3000);
}
ddb_init_tempmon(link);
@@ -3598,7 +3295,7 @@ int ddb_init(struct ddb *dev)
ddb_init_boards(dev);
if (ddb_i2c_init(dev) < 0)
- goto fail;
+ goto fail1;
ddb_ports_init(dev);
if (ddb_buffers_alloc(dev) < 0) {
dev_info(dev->dev, "Could not allocate buffer memory\n");
@@ -3616,14 +3313,14 @@ int ddb_init(struct ddb *dev)
return 0;
fail3:
- ddb_ports_detach(dev);
dev_err(dev->dev, "fail3\n");
- ddb_ports_release(dev);
+ ddb_ports_detach(dev);
+ ddb_buffers_free(dev);
fail2:
dev_err(dev->dev, "fail2\n");
- ddb_buffers_free(dev);
+ ddb_ports_release(dev);
ddb_i2c_release(dev);
-fail:
+fail1:
dev_err(dev->dev, "fail1\n");
return -1;
}
diff --git a/drivers/media/pci/ddbridge/ddbridge-hw.c b/drivers/media/pci/ddbridge/ddbridge-hw.c
index 48248bcd59c2..c6d14925e2fc 100644
--- a/drivers/media/pci/ddbridge/ddbridge-hw.c
+++ b/drivers/media/pci/ddbridge/ddbridge-hw.c
@@ -185,7 +185,7 @@ static const struct ddb_info ddb_ctv7 = {
.board_control_2 = 4,
};
-static const struct ddb_info ddb_satixS2v3 = {
+static const struct ddb_info ddb_satixs2v3 = {
.type = DDB_OCTOPUS,
.name = "Mystique SaTiX-S2 V3 DVB adapter",
.regmap = &octopus_map,
@@ -336,7 +336,7 @@ static const struct ddb_device_id ddb_device_ids[] = {
DDB_DEVID(0x0006, 0x0022, ddb_v7),
DDB_DEVID(0x0006, 0x0024, ddb_v7a),
DDB_DEVID(0x0003, 0x0030, ddb_dvbct),
- DDB_DEVID(0x0003, 0xdb03, ddb_satixS2v3),
+ DDB_DEVID(0x0003, 0xdb03, ddb_satixs2v3),
DDB_DEVID(0x0006, 0x0031, ddb_ctv7),
DDB_DEVID(0x0006, 0x0032, ddb_ctv7),
DDB_DEVID(0x0006, 0x0033, ddb_ctv7),
@@ -367,8 +367,8 @@ const struct ddb_info *get_ddb_info(u16 vendor, u16 device,
if (vendor == id->vendor &&
device == id->device &&
subvendor == id->subvendor &&
- ((subdevice == id->subdevice) ||
- (id->subdevice == 0xffff)))
+ (subdevice == id->subdevice ||
+ id->subdevice == 0xffff))
return id->info;
}
diff --git a/drivers/media/pci/ddbridge/ddbridge-i2c.c b/drivers/media/pci/ddbridge/ddbridge-i2c.c
index e4d39c3270ae..82a9a0e806fc 100644
--- a/drivers/media/pci/ddbridge/ddbridge-i2c.c
+++ b/drivers/media/pci/ddbridge/ddbridge-i2c.c
@@ -81,7 +81,7 @@ static int ddb_i2c_cmd(struct ddb_i2c *i2c, u32 adr, u32 cmd)
static int ddb_i2c_master_xfer(struct i2c_adapter *adapter,
struct i2c_msg msg[], int num)
{
- struct ddb_i2c *i2c = (struct ddb_i2c *) i2c_get_adapdata(adapter);
+ struct ddb_i2c *i2c = (struct ddb_i2c *)i2c_get_adapdata(adapter);
struct ddb *dev = i2c->dev;
u8 addr = 0;
@@ -149,7 +149,7 @@ void ddb_i2c_release(struct ddb *dev)
static void i2c_handler(unsigned long priv)
{
- struct ddb_i2c *i2c = (struct ddb_i2c *) priv;
+ struct ddb_i2c *i2c = (struct ddb_i2c *)priv;
complete(&i2c->completion);
}
@@ -171,20 +171,20 @@ static int ddb_i2c_add(struct ddb *dev, struct ddb_i2c *i2c,
(regmap->i2c->base + regmap->i2c->size * i);
ddbwritel(dev, I2C_SPEED_100, i2c->regs + I2C_TIMING);
ddbwritel(dev, ((i2c->rbuf & 0xffff) << 16) | (i2c->wbuf & 0xffff),
- i2c->regs + I2C_TASKADDRESS);
+ i2c->regs + I2C_TASKADDRESS);
init_completion(&i2c->completion);
adap = &i2c->adap;
i2c_set_adapdata(adap, i2c);
#ifdef I2C_ADAP_CLASS_TV_DIGITAL
- adap->class = I2C_ADAP_CLASS_TV_DIGITAL|I2C_CLASS_TV_ANALOG;
+ adap->class = I2C_ADAP_CLASS_TV_DIGITAL | I2C_CLASS_TV_ANALOG;
#else
#ifdef I2C_CLASS_TV_ANALOG
adap->class = I2C_CLASS_TV_ANALOG;
#endif
#endif
snprintf(adap->name, I2C_NAME_SIZE, "ddbridge_%02x.%x.%x",
- dev->nr, i2c->link, i);
+ dev->nr, i2c->link, i);
adap->algo = &ddb_i2c_algo;
adap->algo_data = (void *)i2c;
adap->dev.parent = dev->dev;
@@ -210,7 +210,7 @@ int ddb_i2c_init(struct ddb *dev)
if (!(dev->link[l].info->i2c_mask & (1 << i)))
continue;
i2c = &dev->i2c[num];
- dev->handler_data[l][i + base] = (unsigned long) i2c;
+ dev->handler_data[l][i + base] = (unsigned long)i2c;
dev->handler[l][i + base] = i2c_handler;
stat = ddb_i2c_add(dev, i2c, regmap, l, i, num);
if (stat)
@@ -224,7 +224,9 @@ int ddb_i2c_init(struct ddb *dev)
adap = &i2c->adap;
i2c_del_adapter(adap);
}
- } else
+ } else {
dev->i2c_num = num;
+ }
+
return stat;
}
diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c b/drivers/media/pci/ddbridge/ddbridge-main.c
index ccac7fe31336..26497d6b1395 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -107,7 +107,7 @@ static void ddb_irq_exit(struct ddb *dev)
static void ddb_remove(struct pci_dev *pdev)
{
- struct ddb *dev = (struct ddb *) pci_get_drvdata(pdev);
+ struct ddb *dev = (struct ddb *)pci_get_drvdata(pdev);
ddb_device_destroy(dev);
ddb_ports_detach(dev);
@@ -132,9 +132,10 @@ static void ddb_irq_msi(struct ddb *dev, int nr)
if (stat >= 1) {
dev->msi = stat;
dev_info(dev->dev, "using %d MSI interrupt(s)\n",
- dev->msi);
- } else
+ dev->msi);
+ } else {
dev_info(dev->dev, "MSI not available.\n");
+ }
}
}
#endif
@@ -160,11 +161,11 @@ static int ddb_irq_init(struct ddb *dev)
irq_flag = 0;
if (dev->msi == 2) {
stat = request_irq(dev->pdev->irq, ddb_irq_handler0,
- irq_flag, "ddbridge", (void *) dev);
+ irq_flag, "ddbridge", (void *)dev);
if (stat < 0)
return stat;
stat = request_irq(dev->pdev->irq + 1, ddb_irq_handler1,
- irq_flag, "ddbridge", (void *) dev);
+ irq_flag, "ddbridge", (void *)dev);
if (stat < 0) {
free_irq(dev->pdev->irq, dev);
return stat;
@@ -173,7 +174,7 @@ static int ddb_irq_init(struct ddb *dev)
#endif
{
stat = request_irq(dev->pdev->irq, ddb_irq_handler,
- irq_flag, "ddbridge", (void *) dev);
+ irq_flag, "ddbridge", (void *)dev);
if (stat < 0)
return stat;
}
@@ -188,7 +189,7 @@ static int ddb_irq_init(struct ddb *dev)
}
static int ddb_probe(struct pci_dev *pdev,
- const struct pci_device_id *id)
+ const struct pci_device_id *id)
{
struct ddb *dev;
int stat = 0;
@@ -202,8 +203,8 @@ static int ddb_probe(struct pci_dev *pdev,
if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))
return -ENODEV;
- dev = vzalloc(sizeof(struct ddb));
- if (dev == NULL)
+ dev = vzalloc(sizeof(*dev));
+ if (!dev)
return -ENOMEM;
mutex_init(&dev->mutex);
@@ -242,7 +243,7 @@ static int ddb_probe(struct pci_dev *pdev,
dev->link[0].ids.regmapid = ddbreadl(dev, 4);
dev_info(&pdev->dev, "HW %08x REGMAP %08x\n",
- dev->link[0].ids.hwid, dev->link[0].ids.regmapid);
+ dev->link[0].ids.hwid, dev->link[0].ids.regmapid);
ddbwritel(dev, 0, DMA_BASE_READ);
ddbwritel(dev, 0, DMA_BASE_WRITE);
@@ -317,7 +318,7 @@ static __init int module_init_ddbridge(void)
if (ddb_class_create() < 0)
return -1;
ddb_wq = create_workqueue("ddbridge");
- if (ddb_wq == NULL)
+ if (!ddb_wq)
goto exit1;
stat = pci_register_driver(&ddb_pci_driver);
if (stat < 0)
diff --git a/drivers/media/pci/ddbridge/ddbridge-maxs8.c b/drivers/media/pci/ddbridge/ddbridge-max.c
index f8a53bc7c86c..dc6b81488746 100644
--- a/drivers/media/pci/ddbridge/ddbridge-maxs8.c
+++ b/drivers/media/pci/ddbridge/ddbridge-max.c
@@ -1,5 +1,5 @@
/*
- * ddbridge-maxs8.c: Digital Devices bridge MaxS4/8 support
+ * ddbridge-max.c: Digital Devices bridge MAX card support
*
* Copyright (C) 2010-2017 Digital Devices GmbH
* Ralph Metzler <rjkm@metzlerbros.de>
@@ -34,7 +34,7 @@
#include "ddbridge-regs.h"
#include "ddbridge-io.h"
-#include "ddbridge-maxs8.h"
+#include "ddbridge-max.h"
#include "mxl5xx.h"
/******************************************************************************/
@@ -68,7 +68,7 @@ static int lnb_command(struct ddb *dev, u32 link, u32 lnb, u32 cmd)
}
if (c == 10)
dev_info(dev->dev, "%s lnb = %08x cmd = %08x\n",
- __func__, lnb, cmd);
+ __func__, lnb, cmd);
return 0;
}
@@ -123,7 +123,7 @@ static int lnb_set_sat(struct ddb *dev, u32 link, u32 input, u32 sat, u32 band,
}
static int lnb_set_tone(struct ddb *dev, u32 link, u32 input,
- enum fe_sec_tone_mode tone)
+ enum fe_sec_tone_mode tone)
{
int s = 0;
u32 mask = (1ULL << input);
@@ -149,7 +149,7 @@ static int lnb_set_tone(struct ddb *dev, u32 link, u32 input,
}
static int lnb_set_voltage(struct ddb *dev, u32 link, u32 input,
- enum fe_sec_voltage voltage)
+ enum fe_sec_voltage voltage)
{
int s = 0;
@@ -291,34 +291,45 @@ static int max_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage)
if (nv != ov) {
if (nv) {
- lnb_set_voltage(dev,
- port->lnr, 0, SEC_VOLTAGE_13);
+ lnb_set_voltage(
+ dev, port->lnr,
+ 0, SEC_VOLTAGE_13);
if (fmode == 1) {
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
0, SEC_VOLTAGE_13);
if (old_quattro) {
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
1, SEC_VOLTAGE_18);
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
2, SEC_VOLTAGE_13);
} else {
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
1, SEC_VOLTAGE_13);
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
2, SEC_VOLTAGE_18);
}
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
3, SEC_VOLTAGE_18);
}
} else {
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
0, SEC_VOLTAGE_OFF);
if (fmode == 1) {
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
1, SEC_VOLTAGE_OFF);
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
2, SEC_VOLTAGE_OFF);
- lnb_set_voltage(dev, port->lnr,
+ lnb_set_voltage(
+ dev, port->lnr,
3, SEC_VOLTAGE_OFF);
}
}
@@ -331,7 +342,6 @@ static int max_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage)
static int max_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
{
-
return 0;
}
@@ -350,7 +360,7 @@ static int mxl_fw_read(void *priv, u8 *buf, u32 len)
return ddbridge_flashread(dev, link->nr, buf, 0xc0000, len);
}
-int lnb_init_fmode(struct ddb *dev, struct ddb_link *link, u32 fm)
+int ddb_lnb_init_fmode(struct ddb *dev, struct ddb_link *link, u32 fm)
{
u32 l = link->nr;
@@ -394,7 +404,7 @@ static struct mxl5xx_cfg mxl5xx = {
.fw_read = mxl_fw_read,
};
-int fe_attach_mxl5xx(struct ddb_input *input)
+int ddb_fe_attach_mxl5xx(struct ddb_input *input)
{
struct ddb *dev = input->port->dev;
struct i2c_adapter *i2c = &input->port->i2c->adap;
@@ -414,7 +424,7 @@ int fe_attach_mxl5xx(struct ddb_input *input)
tuner = 0;
dvb->fe = dvb_attach(mxl5xx_attach, i2c, &cfg,
- demod, tuner, &dvb->set_input);
+ demod, tuner, &dvb->set_input);
if (!dvb->fe) {
dev_err(dev->dev, "No MXL5XX found!\n");
@@ -430,7 +440,7 @@ int fe_attach_mxl5xx(struct ddb_input *input)
lnb_command(dev, port->lnr, input->nr, LNB_CMD_INIT);
lnb_set_voltage(dev, port->lnr, input->nr, SEC_VOLTAGE_OFF);
}
- lnb_init_fmode(dev, link, fmode);
+ ddb_lnb_init_fmode(dev, link, fmode);
dvb->fe->ops.set_voltage = max_set_voltage;
dvb->fe->ops.enable_high_lnb_voltage = max_enable_high_lnb_voltage;
diff --git a/drivers/media/pci/ddbridge/ddbridge-maxs8.h b/drivers/media/pci/ddbridge/ddbridge-max.h
index bb8884811a46..bf8bf38739f6 100644
--- a/drivers/media/pci/ddbridge/ddbridge-maxs8.h
+++ b/drivers/media/pci/ddbridge/ddbridge-max.h
@@ -1,5 +1,5 @@
/*
- * ddbridge-maxs8.h: Digital Devices bridge MaxS4/8 support
+ * ddbridge-max.h: Digital Devices bridge MAX card support
*
* Copyright (C) 2010-2017 Digital Devices GmbH
* Ralph Metzler <rjkm@metzlerbros.de>
@@ -16,14 +16,14 @@
*
*/
-#ifndef _DDBRIDGE_MAXS8_H_
-#define _DDBRIDGE_MAXS8_H_
+#ifndef _DDBRIDGE_MAX_H_
+#define _DDBRIDGE_MAX_H_
#include "ddbridge.h"
/******************************************************************************/
-int lnb_init_fmode(struct ddb *dev, struct ddb_link *link, u32 fm);
-int fe_attach_mxl5xx(struct ddb_input *input);
+int ddb_lnb_init_fmode(struct ddb *dev, struct ddb_link *link, u32 fm);
+int ddb_fe_attach_mxl5xx(struct ddb_input *input);
-#endif /* _DDBRIDGE_MAXS8_H */
+#endif /* _DDBRIDGE_MAX_H */
diff --git a/drivers/media/pci/ddbridge/ddbridge-regs.h b/drivers/media/pci/ddbridge/ddbridge-regs.h
index 9d44f8d3af75..23d74ff83fe4 100644
--- a/drivers/media/pci/ddbridge/ddbridge-regs.h
+++ b/drivers/media/pci/ddbridge/ddbridge-regs.h
@@ -95,27 +95,27 @@
#define DMA_BASE_WRITE (0x100)
#define DMA_BASE_READ (0x140)
-#define TS_CONTROL(_io) (_io->regs + 0x00)
-#define TS_CONTROL2(_io) (_io->regs + 0x04)
+#define TS_CONTROL(_io) ((_io)->regs + 0x00)
+#define TS_CONTROL2(_io) ((_io)->regs + 0x04)
/* ------------------------------------------------------------------------- */
/* DMA Buffer */
-#define DMA_BUFFER_CONTROL(_dma) (_dma->regs + 0x00)
-#define DMA_BUFFER_ACK(_dma) (_dma->regs + 0x04)
-#define DMA_BUFFER_CURRENT(_dma) (_dma->regs + 0x08)
-#define DMA_BUFFER_SIZE(_dma) (_dma->regs + 0x0c)
+#define DMA_BUFFER_CONTROL(_dma) ((_dma)->regs + 0x00)
+#define DMA_BUFFER_ACK(_dma) ((_dma)->regs + 0x04)
+#define DMA_BUFFER_CURRENT(_dma) ((_dma)->regs + 0x08)
+#define DMA_BUFFER_SIZE(_dma) ((_dma)->regs + 0x0c)
/* ------------------------------------------------------------------------- */
/* CI Interface (only CI-Bridge) */
-#define CI_BASE (0x400)
-#define CI_CONTROL(i) (CI_BASE + (i) * 32 + 0x00)
+#define CI_BASE (0x400)
+#define CI_CONTROL(i) (CI_BASE + (i) * 32 + 0x00)
-#define CI_DO_ATTRIBUTE_RW(i) (CI_BASE + (i) * 32 + 0x04)
-#define CI_DO_IO_RW(i) (CI_BASE + (i) * 32 + 0x08)
-#define CI_READDATA(i) (CI_BASE + (i) * 32 + 0x0c)
-#define CI_DO_READ_ATTRIBUTES(i) (CI_BASE + (i) * 32 + 0x10)
+#define CI_DO_ATTRIBUTE_RW(i) (CI_BASE + (i) * 32 + 0x04)
+#define CI_DO_IO_RW(i) (CI_BASE + (i) * 32 + 0x08)
+#define CI_READDATA(i) (CI_BASE + (i) * 32 + 0x0c)
+#define CI_DO_READ_ATTRIBUTES(i) (CI_BASE + (i) * 32 + 0x10)
#define CI_RESET_CAM (0x00000001)
#define CI_POWER_ON (0x00000002)
@@ -132,7 +132,7 @@
#define CI_BUFFER_BASE (0x3000)
#define CI_BUFFER_SIZE (0x0800)
-#define CI_BUFFER(i) (CI_BUFFER_BASE + (i) * CI_BUFFER_SIZE)
+#define CI_BUFFER(i) (CI_BUFFER_BASE + (i) * CI_BUFFER_SIZE)
/* ------------------------------------------------------------------------- */
/* LNB commands (mxl5xx / Max S8) */
@@ -140,7 +140,7 @@
#define LNB_BASE (0x400)
#define LNB_CONTROL(i) (LNB_BASE + (i) * 0x20 + 0x00)
-#define LNB_CMD (7ULL << 0)
+#define LNB_CMD (7ULL << 0)
#define LNB_CMD_NOP 0
#define LNB_CMD_INIT 1
#define LNB_CMD_LOW 3
@@ -148,8 +148,8 @@
#define LNB_CMD_OFF 5
#define LNB_CMD_DISEQC 6
-#define LNB_BUSY (1ULL << 4)
-#define LNB_TONE (1ULL << 15)
+#define LNB_BUSY BIT_ULL(4)
+#define LNB_TONE BIT_ULL(15)
#define LNB_BUF_LEVEL(i) (LNB_BASE + (i) * 0x20 + 0x10)
#define LNB_BUF_WRITE(i) (LNB_BASE + (i) * 0x20 + 0x14)
diff --git a/drivers/media/pci/ddbridge/ddbridge.h b/drivers/media/pci/ddbridge/ddbridge.h
index e9afa96bd9df..095457737bc1 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -55,15 +55,15 @@
#include <linux/device.h>
#include <linux/io.h>
-#include "dmxdev.h"
-#include "dvbdev.h"
-#include "dvb_demux.h"
-#include "dvb_frontend.h"
-#include "dvb_ringbuffer.h"
-#include "dvb_ca_en50221.h"
-#include "dvb_net.h"
+#include <media/dmxdev.h>
+#include <media/dvbdev.h>
+#include <media/dvb_demux.h>
+#include <media/dvb_frontend.h>
+#include <media/dvb_ringbuffer.h>
+#include <media/dvb_ca_en50221.h>
+#include <media/dvb_net.h>
-#define DDBRIDGE_VERSION "0.9.31intermediate-integrated"
+#define DDBRIDGE_VERSION "0.9.32-integrated"
#define DDB_MAX_I2C 32
#define DDB_MAX_PORT 32
@@ -143,11 +143,11 @@ struct ddb_info {
#define DMA_MAX_BUFS 32 /* hardware table limit */
#define INPUT_DMA_BUFS 8
-#define INPUT_DMA_SIZE (128*47*21)
+#define INPUT_DMA_SIZE (128 * 47 * 21)
#define INPUT_DMA_IRQ_DIV 1
#define OUTPUT_DMA_BUFS 8
-#define OUTPUT_DMA_SIZE (128*47*21)
+#define OUTPUT_DMA_SIZE (128 * 47 * 21)
#define OUTPUT_DMA_IRQ_DIV 1
struct ddb;
@@ -166,7 +166,7 @@ struct ddb_dma {
u32 bufval;
struct work_struct work;
- spinlock_t lock;
+ spinlock_t lock; /* DMA lock */
wait_queue_head_t wq;
int running;
u32 stat;
@@ -196,17 +196,16 @@ struct ddb_dvb {
int (*i2c_gate_ctrl)(struct dvb_frontend *, int);
int (*set_voltage)(struct dvb_frontend *fe,
- enum fe_sec_voltage voltage);
+ enum fe_sec_voltage voltage);
int (*set_input)(struct dvb_frontend *fe, int input);
int (*diseqc_send_master_cmd)(struct dvb_frontend *fe,
- struct dvb_diseqc_master_cmd *cmd);
+ struct dvb_diseqc_master_cmd *cmd);
};
struct ddb_ci {
struct dvb_ca_en50221 en;
struct ddb_port *port;
u32 nr;
- struct mutex lock;
};
struct ddb_io {
@@ -240,7 +239,7 @@ struct ddb_port {
u32 regs;
u32 lnr;
struct ddb_i2c *i2c;
- struct mutex i2c_gate_lock;
+ struct mutex i2c_gate_lock; /* I2C access lock */
u32 class;
#define DDB_PORT_NONE 0
#define DDB_PORT_CI 1
@@ -297,7 +296,7 @@ struct ddb_port {
#define TS_CAPTURE_LEN (4096)
struct ddb_lnb {
- struct mutex lock;
+ struct mutex lock; /* lock lnb access */
u32 tone;
enum fe_sec_voltage oldvoltage[4];
u32 voltage[4];
@@ -310,54 +309,54 @@ struct ddb_link {
const struct ddb_info *info;
u32 nr;
u32 regs;
- spinlock_t lock;
- struct mutex flash_mutex;
+ spinlock_t lock; /* lock link access */
+ struct mutex flash_mutex; /* lock flash access */
struct ddb_lnb lnb;
struct tasklet_struct tasklet;
struct ddb_ids ids;
- spinlock_t temp_lock;
+ spinlock_t temp_lock; /* lock temp chip access */
int overtemperature_error;
u8 temp_tab[11];
};
struct ddb {
- struct pci_dev *pdev;
- struct platform_device *pfdev;
- struct device *dev;
+ struct pci_dev *pdev;
+ struct platform_device *pfdev;
+ struct device *dev;
- int msi;
+ int msi;
struct workqueue_struct *wq;
- u32 has_dma;
-
- struct ddb_link link[DDB_MAX_LINK];
- unsigned char __iomem *regs;
- u32 regs_len;
- u32 port_num;
- struct ddb_port port[DDB_MAX_PORT];
- u32 i2c_num;
- struct ddb_i2c i2c[DDB_MAX_I2C];
- struct ddb_input input[DDB_MAX_INPUT];
- struct ddb_output output[DDB_MAX_OUTPUT];
- struct dvb_adapter adap[DDB_MAX_INPUT];
- struct ddb_dma idma[DDB_MAX_INPUT];
- struct ddb_dma odma[DDB_MAX_OUTPUT];
-
- void (*handler[4][256])(unsigned long);
- unsigned long handler_data[4][256];
-
- struct device *ddb_dev;
- u32 ddb_dev_users;
- u32 nr;
- u8 iobuf[1028];
-
- u8 leds;
- u32 ts_irq;
- u32 i2c_irq;
-
- struct mutex mutex;
-
- u8 tsbuf[TS_CAPTURE_LEN];
+ u32 has_dma;
+
+ struct ddb_link link[DDB_MAX_LINK];
+ unsigned char __iomem *regs;
+ u32 regs_len;
+ u32 port_num;
+ struct ddb_port port[DDB_MAX_PORT];
+ u32 i2c_num;
+ struct ddb_i2c i2c[DDB_MAX_I2C];
+ struct ddb_input input[DDB_MAX_INPUT];
+ struct ddb_output output[DDB_MAX_OUTPUT];
+ struct dvb_adapter adap[DDB_MAX_INPUT];
+ struct ddb_dma idma[DDB_MAX_INPUT];
+ struct ddb_dma odma[DDB_MAX_OUTPUT];
+
+ void (*handler[4][256])(unsigned long);
+ unsigned long handler_data[4][256];
+
+ struct device *ddb_dev;
+ u32 ddb_dev_users;
+ u32 nr;
+ u8 iobuf[1028];
+
+ u8 leds;
+ u32 ts_irq;
+ u32 i2c_irq;
+
+ struct mutex mutex; /* lock access to global ddb array */
+
+ u8 tsbuf[TS_CAPTURE_LEN];
};
/****************************************************************************/