summaryrefslogtreecommitdiffstats
path: root/kernel/drivers/media/tuners
diff options
context:
space:
mode:
authorJosé Pekkarinen <jose.pekkarinen@nokia.com>2016-04-11 10:41:07 +0300
committerJosé Pekkarinen <jose.pekkarinen@nokia.com>2016-04-13 08:17:18 +0300
commite09b41010ba33a20a87472ee821fa407a5b8da36 (patch)
treed10dc367189862e7ca5c592f033dc3726e1df4e3 /kernel/drivers/media/tuners
parentf93b97fd65072de626c074dbe099a1fff05ce060 (diff)
These changes are the raw update to linux-4.4.6-rt14. Kernel sources
are taken from kernel.org, and rt patch from the rt wiki download page. During the rebasing, the following patch collided: Force tick interrupt and get rid of softirq magic(I70131fb85). Collisions have been removed because its logic was found on the source already. Change-Id: I7f57a4081d9deaa0d9ccfc41a6c8daccdee3b769 Signed-off-by: José Pekkarinen <jose.pekkarinen@nokia.com>
Diffstat (limited to 'kernel/drivers/media/tuners')
-rw-r--r--kernel/drivers/media/tuners/Kconfig7
-rw-r--r--kernel/drivers/media/tuners/e4000.c593
-rw-r--r--kernel/drivers/media/tuners/e4000.h1
-rw-r--r--kernel/drivers/media/tuners/e4000_priv.h11
-rw-r--r--kernel/drivers/media/tuners/fc0013.c2
-rw-r--r--kernel/drivers/media/tuners/fc2580.c780
-rw-r--r--kernel/drivers/media/tuners/fc2580.h40
-rw-r--r--kernel/drivers/media/tuners/fc2580_priv.h36
-rw-r--r--kernel/drivers/media/tuners/it913x.c1
-rw-r--r--kernel/drivers/media/tuners/m88rs6000t.c1
-rw-r--r--kernel/drivers/media/tuners/msi001.c268
-rw-r--r--kernel/drivers/media/tuners/qt1010.c8
-rw-r--r--kernel/drivers/media/tuners/r820t.c4
-rw-r--r--kernel/drivers/media/tuners/si2157.c50
-rw-r--r--kernel/drivers/media/tuners/si2157.h6
-rw-r--r--kernel/drivers/media/tuners/si2157_priv.h2
-rw-r--r--kernel/drivers/media/tuners/tda18212.c1
-rw-r--r--kernel/drivers/media/tuners/tua9001.c330
-rw-r--r--kernel/drivers/media/tuners/tua9001.h35
-rw-r--r--kernel/drivers/media/tuners/tua9001_priv.h19
-rw-r--r--kernel/drivers/media/tuners/tuner-i2c.h10
-rw-r--r--kernel/drivers/media/tuners/tuner-xc2028.c2
22 files changed, 1257 insertions, 950 deletions
diff --git a/kernel/drivers/media/tuners/Kconfig b/kernel/drivers/media/tuners/Kconfig
index 983510d28..05998f025 100644
--- a/kernel/drivers/media/tuners/Kconfig
+++ b/kernel/drivers/media/tuners/Kconfig
@@ -15,7 +15,7 @@ config MEDIA_TUNER
select MEDIA_TUNER_MC44S803 if MEDIA_SUBDRV_AUTOSELECT
menu "Customize TV tuners"
- visible if !MEDIA_SUBDRV_AUTOSELECT
+ visible if !MEDIA_SUBDRV_AUTOSELECT || COMPILE_TEST
depends on MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT || MEDIA_RADIO_SUPPORT || MEDIA_SDR_SUPPORT
config MEDIA_TUNER_SIMPLE
@@ -220,6 +220,7 @@ config MEDIA_TUNER_E4000
config MEDIA_TUNER_FC2580
tristate "FCI FC2580 silicon tuner"
depends on MEDIA_SUPPORT && I2C
+ select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
FCI FC2580 silicon tuner driver.
@@ -233,8 +234,9 @@ config MEDIA_TUNER_M88RS6000T
Montage M88RS6000 internal tuner.
config MEDIA_TUNER_TUA9001
- tristate "Infineon TUA 9001 silicon tuner"
+ tristate "Infineon TUA9001 silicon tuner"
depends on MEDIA_SUPPORT && I2C
+ select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
Infineon TUA 9001 silicon tuner driver.
@@ -258,6 +260,7 @@ config MEDIA_TUNER_R820T
tristate "Rafael Micro R820T silicon tuner"
depends on MEDIA_SUPPORT && I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
+ select BITREVERSE
help
Rafael Micro R820T silicon tuner driver.
diff --git a/kernel/drivers/media/tuners/e4000.c b/kernel/drivers/media/tuners/e4000.c
index 510239f80..564a000f5 100644
--- a/kernel/drivers/media/tuners/e4000.c
+++ b/kernel/drivers/media/tuners/e4000.c
@@ -19,164 +19,176 @@
*/
#include "e4000_priv.h"
-#include <linux/math64.h>
-static int e4000_init(struct dvb_frontend *fe)
+static int e4000_init(struct e4000_dev *dev)
{
- struct e4000 *s = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
int ret;
- dev_dbg(&s->client->dev, "\n");
-
- /* dummy I2C to ensure I2C wakes up */
- ret = regmap_write(s->regmap, 0x02, 0x40);
+ dev_dbg(&client->dev, "\n");
/* reset */
- ret = regmap_write(s->regmap, 0x00, 0x01);
+ ret = regmap_write(dev->regmap, 0x00, 0x01);
if (ret)
goto err;
/* disable output clock */
- ret = regmap_write(s->regmap, 0x06, 0x00);
+ ret = regmap_write(dev->regmap, 0x06, 0x00);
if (ret)
goto err;
- ret = regmap_write(s->regmap, 0x7a, 0x96);
+ ret = regmap_write(dev->regmap, 0x7a, 0x96);
if (ret)
goto err;
/* configure gains */
- ret = regmap_bulk_write(s->regmap, 0x7e, "\x01\xfe", 2);
+ ret = regmap_bulk_write(dev->regmap, 0x7e, "\x01\xfe", 2);
if (ret)
goto err;
- ret = regmap_write(s->regmap, 0x82, 0x00);
+ ret = regmap_write(dev->regmap, 0x82, 0x00);
if (ret)
goto err;
- ret = regmap_write(s->regmap, 0x24, 0x05);
+ ret = regmap_write(dev->regmap, 0x24, 0x05);
if (ret)
goto err;
- ret = regmap_bulk_write(s->regmap, 0x87, "\x20\x01", 2);
+ ret = regmap_bulk_write(dev->regmap, 0x87, "\x20\x01", 2);
if (ret)
goto err;
- ret = regmap_bulk_write(s->regmap, 0x9f, "\x7f\x07", 2);
+ ret = regmap_bulk_write(dev->regmap, 0x9f, "\x7f\x07", 2);
if (ret)
goto err;
/* DC offset control */
- ret = regmap_write(s->regmap, 0x2d, 0x1f);
+ ret = regmap_write(dev->regmap, 0x2d, 0x1f);
if (ret)
goto err;
- ret = regmap_bulk_write(s->regmap, 0x70, "\x01\x01", 2);
+ ret = regmap_bulk_write(dev->regmap, 0x70, "\x01\x01", 2);
if (ret)
goto err;
/* gain control */
- ret = regmap_write(s->regmap, 0x1a, 0x17);
+ ret = regmap_write(dev->regmap, 0x1a, 0x17);
if (ret)
goto err;
- ret = regmap_write(s->regmap, 0x1f, 0x1a);
+ ret = regmap_write(dev->regmap, 0x1f, 0x1a);
if (ret)
goto err;
- s->active = true;
-err:
- if (ret)
- dev_dbg(&s->client->dev, "failed=%d\n", ret);
+ dev->active = true;
+ return 0;
+err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
-static int e4000_sleep(struct dvb_frontend *fe)
+static int e4000_sleep(struct e4000_dev *dev)
{
- struct e4000 *s = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
int ret;
- dev_dbg(&s->client->dev, "\n");
+ dev_dbg(&client->dev, "\n");
- s->active = false;
+ dev->active = false;
- ret = regmap_write(s->regmap, 0x00, 0x00);
+ ret = regmap_write(dev->regmap, 0x00, 0x00);
if (ret)
goto err;
-err:
- if (ret)
- dev_dbg(&s->client->dev, "failed=%d\n", ret);
+ return 0;
+err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
-static int e4000_set_params(struct dvb_frontend *fe)
+static int e4000_set_params(struct e4000_dev *dev)
{
- struct e4000 *s = fe->tuner_priv;
- struct dtv_frontend_properties *c = &fe->dtv_property_cache;
- int ret, i, sigma_delta;
- unsigned int pll_n, pll_f;
+ struct i2c_client *client = dev->client;
+ int ret, i;
+ unsigned int div_n, k, k_cw, div_out;
u64 f_vco;
u8 buf[5], i_data[4], q_data[4];
- dev_dbg(&s->client->dev,
- "delivery_system=%d frequency=%u bandwidth_hz=%u\n",
- c->delivery_system, c->frequency, c->bandwidth_hz);
+ if (!dev->active) {
+ dev_dbg(&client->dev, "tuner is sleeping\n");
+ return 0;
+ }
/* gain control manual */
- ret = regmap_write(s->regmap, 0x1a, 0x00);
- if (ret)
- goto err;
-
- /* PLL */
+ ret = regmap_write(dev->regmap, 0x1a, 0x00);
+ if (ret)
+ goto err;
+
+ /*
+ * Fractional-N synthesizer
+ *
+ * +----------------------------+
+ * v |
+ * Fref +----+ +-------+ +------+ +---+
+ * ------> | PD | --> | VCO | ------> | /N.F | <-- | K |
+ * +----+ +-------+ +------+ +---+
+ * |
+ * |
+ * v
+ * +-------+ Fout
+ * | /Rout | ------>
+ * +-------+
+ */
for (i = 0; i < ARRAY_SIZE(e4000_pll_lut); i++) {
- if (c->frequency <= e4000_pll_lut[i].freq)
+ if (dev->f_frequency <= e4000_pll_lut[i].freq)
break;
}
-
if (i == ARRAY_SIZE(e4000_pll_lut)) {
ret = -EINVAL;
goto err;
}
- f_vco = 1ull * c->frequency * e4000_pll_lut[i].mul;
- pll_n = div_u64_rem(f_vco, s->clock, &pll_f);
- sigma_delta = div_u64(0x10000ULL * pll_f, s->clock);
- buf[0] = pll_n;
- buf[1] = (sigma_delta >> 0) & 0xff;
- buf[2] = (sigma_delta >> 8) & 0xff;
+ #define F_REF dev->clk
+ div_out = e4000_pll_lut[i].div_out;
+ f_vco = (u64) dev->f_frequency * div_out;
+ /* calculate PLL integer and fractional control word */
+ div_n = div_u64_rem(f_vco, F_REF, &k);
+ k_cw = div_u64((u64) k * 0x10000, F_REF);
+
+ dev_dbg(&client->dev,
+ "frequency=%u bandwidth=%u f_vco=%llu F_REF=%u div_n=%u k=%u k_cw=%04x div_out=%u\n",
+ dev->f_frequency, dev->f_bandwidth, f_vco, F_REF, div_n, k,
+ k_cw, div_out);
+
+ buf[0] = div_n;
+ buf[1] = (k_cw >> 0) & 0xff;
+ buf[2] = (k_cw >> 8) & 0xff;
buf[3] = 0x00;
- buf[4] = e4000_pll_lut[i].div;
-
- dev_dbg(&s->client->dev, "f_vco=%llu pll div=%d sigma_delta=%04x\n",
- f_vco, buf[0], sigma_delta);
-
- ret = regmap_bulk_write(s->regmap, 0x09, buf, 5);
+ buf[4] = e4000_pll_lut[i].div_out_reg;
+ ret = regmap_bulk_write(dev->regmap, 0x09, buf, 5);
if (ret)
goto err;
/* LNA filter (RF filter) */
for (i = 0; i < ARRAY_SIZE(e400_lna_filter_lut); i++) {
- if (c->frequency <= e400_lna_filter_lut[i].freq)
+ if (dev->f_frequency <= e400_lna_filter_lut[i].freq)
break;
}
-
if (i == ARRAY_SIZE(e400_lna_filter_lut)) {
ret = -EINVAL;
goto err;
}
- ret = regmap_write(s->regmap, 0x10, e400_lna_filter_lut[i].val);
+ ret = regmap_write(dev->regmap, 0x10, e400_lna_filter_lut[i].val);
if (ret)
goto err;
/* IF filters */
for (i = 0; i < ARRAY_SIZE(e4000_if_filter_lut); i++) {
- if (c->bandwidth_hz <= e4000_if_filter_lut[i].freq)
+ if (dev->f_bandwidth <= e4000_if_filter_lut[i].freq)
break;
}
-
if (i == ARRAY_SIZE(e4000_if_filter_lut)) {
ret = -EINVAL;
goto err;
@@ -185,48 +197,47 @@ static int e4000_set_params(struct dvb_frontend *fe)
buf[0] = e4000_if_filter_lut[i].reg11_val;
buf[1] = e4000_if_filter_lut[i].reg12_val;
- ret = regmap_bulk_write(s->regmap, 0x11, buf, 2);
+ ret = regmap_bulk_write(dev->regmap, 0x11, buf, 2);
if (ret)
goto err;
/* frequency band */
for (i = 0; i < ARRAY_SIZE(e4000_band_lut); i++) {
- if (c->frequency <= e4000_band_lut[i].freq)
+ if (dev->f_frequency <= e4000_band_lut[i].freq)
break;
}
-
if (i == ARRAY_SIZE(e4000_band_lut)) {
ret = -EINVAL;
goto err;
}
- ret = regmap_write(s->regmap, 0x07, e4000_band_lut[i].reg07_val);
+ ret = regmap_write(dev->regmap, 0x07, e4000_band_lut[i].reg07_val);
if (ret)
goto err;
- ret = regmap_write(s->regmap, 0x78, e4000_band_lut[i].reg78_val);
+ ret = regmap_write(dev->regmap, 0x78, e4000_band_lut[i].reg78_val);
if (ret)
goto err;
/* DC offset */
for (i = 0; i < 4; i++) {
if (i == 0)
- ret = regmap_bulk_write(s->regmap, 0x15, "\x00\x7e\x24", 3);
+ ret = regmap_bulk_write(dev->regmap, 0x15, "\x00\x7e\x24", 3);
else if (i == 1)
- ret = regmap_bulk_write(s->regmap, 0x15, "\x00\x7f", 2);
+ ret = regmap_bulk_write(dev->regmap, 0x15, "\x00\x7f", 2);
else if (i == 2)
- ret = regmap_bulk_write(s->regmap, 0x15, "\x01", 1);
+ ret = regmap_bulk_write(dev->regmap, 0x15, "\x01", 1);
else
- ret = regmap_bulk_write(s->regmap, 0x16, "\x7e", 1);
+ ret = regmap_bulk_write(dev->regmap, 0x16, "\x7e", 1);
if (ret)
goto err;
- ret = regmap_write(s->regmap, 0x29, 0x01);
+ ret = regmap_write(dev->regmap, 0x29, 0x01);
if (ret)
goto err;
- ret = regmap_bulk_read(s->regmap, 0x2a, buf, 3);
+ ret = regmap_bulk_read(dev->regmap, 0x2a, buf, 3);
if (ret)
goto err;
@@ -237,174 +248,294 @@ static int e4000_set_params(struct dvb_frontend *fe)
swap(q_data[2], q_data[3]);
swap(i_data[2], i_data[3]);
- ret = regmap_bulk_write(s->regmap, 0x50, q_data, 4);
+ ret = regmap_bulk_write(dev->regmap, 0x50, q_data, 4);
if (ret)
goto err;
- ret = regmap_bulk_write(s->regmap, 0x60, i_data, 4);
+ ret = regmap_bulk_write(dev->regmap, 0x60, i_data, 4);
if (ret)
goto err;
/* gain control auto */
- ret = regmap_write(s->regmap, 0x1a, 0x17);
+ ret = regmap_write(dev->regmap, 0x1a, 0x17);
if (ret)
goto err;
+
+ return 0;
err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
+ return ret;
+}
+
+/*
+ * V4L2 API
+ */
+#if IS_ENABLED(CONFIG_VIDEO_V4L2)
+static const struct v4l2_frequency_band bands[] = {
+ {
+ .type = V4L2_TUNER_RF,
+ .index = 0,
+ .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+ .rangelow = 59000000,
+ .rangehigh = 1105000000,
+ },
+ {
+ .type = V4L2_TUNER_RF,
+ .index = 1,
+ .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+ .rangelow = 1249000000,
+ .rangehigh = 2208000000UL,
+ },
+};
+
+static inline struct e4000_dev *e4000_subdev_to_dev(struct v4l2_subdev *sd)
+{
+ return container_of(sd, struct e4000_dev, sd);
+}
+
+static int e4000_s_power(struct v4l2_subdev *sd, int on)
+{
+ struct e4000_dev *dev = e4000_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+ int ret;
+
+ dev_dbg(&client->dev, "on=%d\n", on);
+
+ if (on)
+ ret = e4000_init(dev);
+ else
+ ret = e4000_sleep(dev);
if (ret)
- dev_dbg(&s->client->dev, "failed=%d\n", ret);
+ return ret;
- return ret;
+ return e4000_set_params(dev);
+}
+
+static const struct v4l2_subdev_core_ops e4000_subdev_core_ops = {
+ .s_power = e4000_s_power,
+};
+
+static int e4000_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
+{
+ struct e4000_dev *dev = e4000_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+
+ dev_dbg(&client->dev, "index=%d\n", v->index);
+
+ strlcpy(v->name, "Elonics E4000", sizeof(v->name));
+ v->type = V4L2_TUNER_RF;
+ v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
+ v->rangelow = bands[0].rangelow;
+ v->rangehigh = bands[1].rangehigh;
+ return 0;
}
-static int e4000_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
+static int e4000_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v)
{
- struct e4000 *s = fe->tuner_priv;
+ struct e4000_dev *dev = e4000_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
- dev_dbg(&s->client->dev, "\n");
+ dev_dbg(&client->dev, "index=%d\n", v->index);
+ return 0;
+}
- *frequency = 0; /* Zero-IF */
+static int e4000_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
+{
+ struct e4000_dev *dev = e4000_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+ dev_dbg(&client->dev, "tuner=%d\n", f->tuner);
+ f->frequency = dev->f_frequency;
return 0;
}
-#if IS_ENABLED(CONFIG_VIDEO_V4L2)
+static int e4000_s_frequency(struct v4l2_subdev *sd,
+ const struct v4l2_frequency *f)
+{
+ struct e4000_dev *dev = e4000_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+
+ dev_dbg(&client->dev, "tuner=%d type=%d frequency=%u\n",
+ f->tuner, f->type, f->frequency);
+
+ dev->f_frequency = clamp_t(unsigned int, f->frequency,
+ bands[0].rangelow, bands[1].rangehigh);
+ return e4000_set_params(dev);
+}
+
+static int e4000_enum_freq_bands(struct v4l2_subdev *sd,
+ struct v4l2_frequency_band *band)
+{
+ struct e4000_dev *dev = e4000_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+
+ dev_dbg(&client->dev, "tuner=%d type=%d index=%d\n",
+ band->tuner, band->type, band->index);
+
+ if (band->index >= ARRAY_SIZE(bands))
+ return -EINVAL;
+
+ band->capability = bands[band->index].capability;
+ band->rangelow = bands[band->index].rangelow;
+ band->rangehigh = bands[band->index].rangehigh;
+ return 0;
+}
+
+static const struct v4l2_subdev_tuner_ops e4000_subdev_tuner_ops = {
+ .g_tuner = e4000_g_tuner,
+ .s_tuner = e4000_s_tuner,
+ .g_frequency = e4000_g_frequency,
+ .s_frequency = e4000_s_frequency,
+ .enum_freq_bands = e4000_enum_freq_bands,
+};
+
+static const struct v4l2_subdev_ops e4000_subdev_ops = {
+ .core = &e4000_subdev_core_ops,
+ .tuner = &e4000_subdev_tuner_ops,
+};
+
static int e4000_set_lna_gain(struct dvb_frontend *fe)
{
- struct e4000 *s = fe->tuner_priv;
+ struct e4000_dev *dev = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
int ret;
u8 u8tmp;
- dev_dbg(&s->client->dev, "lna auto=%d->%d val=%d->%d\n",
- s->lna_gain_auto->cur.val, s->lna_gain_auto->val,
- s->lna_gain->cur.val, s->lna_gain->val);
+ dev_dbg(&client->dev, "lna auto=%d->%d val=%d->%d\n",
+ dev->lna_gain_auto->cur.val, dev->lna_gain_auto->val,
+ dev->lna_gain->cur.val, dev->lna_gain->val);
- if (s->lna_gain_auto->val && s->if_gain_auto->cur.val)
+ if (dev->lna_gain_auto->val && dev->if_gain_auto->cur.val)
u8tmp = 0x17;
- else if (s->lna_gain_auto->val)
+ else if (dev->lna_gain_auto->val)
u8tmp = 0x19;
- else if (s->if_gain_auto->cur.val)
+ else if (dev->if_gain_auto->cur.val)
u8tmp = 0x16;
else
u8tmp = 0x10;
- ret = regmap_write(s->regmap, 0x1a, u8tmp);
+ ret = regmap_write(dev->regmap, 0x1a, u8tmp);
if (ret)
goto err;
- if (s->lna_gain_auto->val == false) {
- ret = regmap_write(s->regmap, 0x14, s->lna_gain->val);
+ if (dev->lna_gain_auto->val == false) {
+ ret = regmap_write(dev->regmap, 0x14, dev->lna_gain->val);
if (ret)
goto err;
}
-err:
- if (ret)
- dev_dbg(&s->client->dev, "failed=%d\n", ret);
+ return 0;
+err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int e4000_set_mixer_gain(struct dvb_frontend *fe)
{
- struct e4000 *s = fe->tuner_priv;
+ struct e4000_dev *dev = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
int ret;
u8 u8tmp;
- dev_dbg(&s->client->dev, "mixer auto=%d->%d val=%d->%d\n",
- s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val,
- s->mixer_gain->cur.val, s->mixer_gain->val);
+ dev_dbg(&client->dev, "mixer auto=%d->%d val=%d->%d\n",
+ dev->mixer_gain_auto->cur.val, dev->mixer_gain_auto->val,
+ dev->mixer_gain->cur.val, dev->mixer_gain->val);
- if (s->mixer_gain_auto->val)
+ if (dev->mixer_gain_auto->val)
u8tmp = 0x15;
else
u8tmp = 0x14;
- ret = regmap_write(s->regmap, 0x20, u8tmp);
+ ret = regmap_write(dev->regmap, 0x20, u8tmp);
if (ret)
goto err;
- if (s->mixer_gain_auto->val == false) {
- ret = regmap_write(s->regmap, 0x15, s->mixer_gain->val);
+ if (dev->mixer_gain_auto->val == false) {
+ ret = regmap_write(dev->regmap, 0x15, dev->mixer_gain->val);
if (ret)
goto err;
}
-err:
- if (ret)
- dev_dbg(&s->client->dev, "failed=%d\n", ret);
+ return 0;
+err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int e4000_set_if_gain(struct dvb_frontend *fe)
{
- struct e4000 *s = fe->tuner_priv;
+ struct e4000_dev *dev = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
int ret;
u8 buf[2];
u8 u8tmp;
- dev_dbg(&s->client->dev, "if auto=%d->%d val=%d->%d\n",
- s->if_gain_auto->cur.val, s->if_gain_auto->val,
- s->if_gain->cur.val, s->if_gain->val);
+ dev_dbg(&client->dev, "if auto=%d->%d val=%d->%d\n",
+ dev->if_gain_auto->cur.val, dev->if_gain_auto->val,
+ dev->if_gain->cur.val, dev->if_gain->val);
- if (s->if_gain_auto->val && s->lna_gain_auto->cur.val)
+ if (dev->if_gain_auto->val && dev->lna_gain_auto->cur.val)
u8tmp = 0x17;
- else if (s->lna_gain_auto->cur.val)
+ else if (dev->lna_gain_auto->cur.val)
u8tmp = 0x19;
- else if (s->if_gain_auto->val)
+ else if (dev->if_gain_auto->val)
u8tmp = 0x16;
else
u8tmp = 0x10;
- ret = regmap_write(s->regmap, 0x1a, u8tmp);
+ ret = regmap_write(dev->regmap, 0x1a, u8tmp);
if (ret)
goto err;
- if (s->if_gain_auto->val == false) {
- buf[0] = e4000_if_gain_lut[s->if_gain->val].reg16_val;
- buf[1] = e4000_if_gain_lut[s->if_gain->val].reg17_val;
- ret = regmap_bulk_write(s->regmap, 0x16, buf, 2);
+ if (dev->if_gain_auto->val == false) {
+ buf[0] = e4000_if_gain_lut[dev->if_gain->val].reg16_val;
+ buf[1] = e4000_if_gain_lut[dev->if_gain->val].reg17_val;
+ ret = regmap_bulk_write(dev->regmap, 0x16, buf, 2);
if (ret)
goto err;
}
-err:
- if (ret)
- dev_dbg(&s->client->dev, "failed=%d\n", ret);
+ return 0;
+err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int e4000_pll_lock(struct dvb_frontend *fe)
{
- struct e4000 *s = fe->tuner_priv;
+ struct e4000_dev *dev = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
int ret;
- unsigned int utmp;
+ unsigned int uitmp;
- ret = regmap_read(s->regmap, 0x07, &utmp);
+ ret = regmap_read(dev->regmap, 0x07, &uitmp);
if (ret)
goto err;
- s->pll_lock->val = (utmp & 0x01);
-err:
- if (ret)
- dev_dbg(&s->client->dev, "failed=%d\n", ret);
+ dev->pll_lock->val = (uitmp & 0x01);
+ return 0;
+err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
{
- struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl);
+ struct e4000_dev *dev = container_of(ctrl->handler, struct e4000_dev, hdl);
+ struct i2c_client *client = dev->client;
int ret;
- if (!s->active)
+ if (!dev->active)
return 0;
switch (ctrl->id) {
case V4L2_CID_RF_TUNER_PLL_LOCK:
- ret = e4000_pll_lock(s->fe);
+ ret = e4000_pll_lock(dev->fe);
break;
default:
- dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n",
- ctrl->id, ctrl->name);
+ dev_dbg(&client->dev, "unknown ctrl: id=%d name=%s\n",
+ ctrl->id, ctrl->name);
ret = -EINVAL;
}
@@ -413,35 +544,39 @@ static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
static int e4000_s_ctrl(struct v4l2_ctrl *ctrl)
{
- struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl);
- struct dvb_frontend *fe = s->fe;
- struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+ struct e4000_dev *dev = container_of(ctrl->handler, struct e4000_dev, hdl);
+ struct i2c_client *client = dev->client;
int ret;
- if (!s->active)
+ if (!dev->active)
return 0;
switch (ctrl->id) {
case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
case V4L2_CID_RF_TUNER_BANDWIDTH:
- c->bandwidth_hz = s->bandwidth->val;
- ret = e4000_set_params(s->fe);
+ /*
+ * TODO: Auto logic does not work 100% correctly as tuner driver
+ * do not have information to calculate maximum suitable
+ * bandwidth. Calculating it is responsible of master driver.
+ */
+ dev->f_bandwidth = dev->bandwidth->val;
+ ret = e4000_set_params(dev);
break;
case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO:
case V4L2_CID_RF_TUNER_LNA_GAIN:
- ret = e4000_set_lna_gain(s->fe);
+ ret = e4000_set_lna_gain(dev->fe);
break;
case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO:
case V4L2_CID_RF_TUNER_MIXER_GAIN:
- ret = e4000_set_mixer_gain(s->fe);
+ ret = e4000_set_mixer_gain(dev->fe);
break;
case V4L2_CID_RF_TUNER_IF_GAIN_AUTO:
case V4L2_CID_RF_TUNER_IF_GAIN:
- ret = e4000_set_if_gain(s->fe);
+ ret = e4000_set_if_gain(dev->fe);
break;
default:
- dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n",
- ctrl->id, ctrl->name);
+ dev_dbg(&client->dev, "unknown ctrl: id=%d name=%s\n",
+ ctrl->id, ctrl->name);
ret = -EINVAL;
}
@@ -454,157 +589,175 @@ static const struct v4l2_ctrl_ops e4000_ctrl_ops = {
};
#endif
-static const struct dvb_tuner_ops e4000_tuner_ops = {
+/*
+ * DVB API
+ */
+static int e4000_dvb_set_params(struct dvb_frontend *fe)
+{
+ struct e4000_dev *dev = fe->tuner_priv;
+ struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+
+ dev->f_frequency = c->frequency;
+ dev->f_bandwidth = c->bandwidth_hz;
+ return e4000_set_params(dev);
+}
+
+static int e4000_dvb_init(struct dvb_frontend *fe)
+{
+ return e4000_init(fe->tuner_priv);
+}
+
+static int e4000_dvb_sleep(struct dvb_frontend *fe)
+{
+ return e4000_sleep(fe->tuner_priv);
+}
+
+static int e4000_dvb_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
+{
+ *frequency = 0; /* Zero-IF */
+ return 0;
+}
+
+static const struct dvb_tuner_ops e4000_dvb_tuner_ops = {
.info = {
.name = "Elonics E4000",
.frequency_min = 174000000,
.frequency_max = 862000000,
},
- .init = e4000_init,
- .sleep = e4000_sleep,
- .set_params = e4000_set_params,
+ .init = e4000_dvb_init,
+ .sleep = e4000_dvb_sleep,
+ .set_params = e4000_dvb_set_params,
- .get_if_frequency = e4000_get_if_frequency,
+ .get_if_frequency = e4000_dvb_get_if_frequency,
};
-/*
- * Use V4L2 subdev to carry V4L2 control handler, even we don't implement
- * subdev itself, just to avoid reinventing the wheel.
- */
static int e4000_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+ const struct i2c_device_id *id)
{
+ struct e4000_dev *dev;
struct e4000_config *cfg = client->dev.platform_data;
struct dvb_frontend *fe = cfg->fe;
- struct e4000 *s;
int ret;
- unsigned int utmp;
+ unsigned int uitmp;
static const struct regmap_config regmap_config = {
.reg_bits = 8,
.val_bits = 8,
- .max_register = 0xff,
};
- s = kzalloc(sizeof(struct e4000), GFP_KERNEL);
- if (!s) {
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev) {
ret = -ENOMEM;
- dev_err(&client->dev, "kzalloc() failed\n");
goto err;
}
- s->clock = cfg->clock;
- s->client = client;
- s->fe = cfg->fe;
- s->regmap = devm_regmap_init_i2c(client, &regmap_config);
- if (IS_ERR(s->regmap)) {
- ret = PTR_ERR(s->regmap);
- goto err;
+ dev->clk = cfg->clock;
+ dev->client = client;
+ dev->fe = cfg->fe;
+ dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
+ if (IS_ERR(dev->regmap)) {
+ ret = PTR_ERR(dev->regmap);
+ goto err_kfree;
}
/* check if the tuner is there */
- ret = regmap_read(s->regmap, 0x02, &utmp);
+ ret = regmap_read(dev->regmap, 0x02, &uitmp);
if (ret)
- goto err;
+ goto err_kfree;
- dev_dbg(&s->client->dev, "chip id=%02x\n", utmp);
+ dev_dbg(&client->dev, "chip id=%02x\n", uitmp);
- if (utmp != 0x40) {
+ if (uitmp != 0x40) {
ret = -ENODEV;
- goto err;
+ goto err_kfree;
}
/* put sleep as chip seems to be in normal mode by default */
- ret = regmap_write(s->regmap, 0x00, 0x00);
+ ret = regmap_write(dev->regmap, 0x00, 0x00);
if (ret)
- goto err;
+ goto err_kfree;
#if IS_ENABLED(CONFIG_VIDEO_V4L2)
/* Register controls */
- v4l2_ctrl_handler_init(&s->hdl, 9);
- s->bandwidth_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ v4l2_ctrl_handler_init(&dev->hdl, 9);
+ dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1);
- s->bandwidth = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_BANDWIDTH, 4300000, 11000000, 100000, 4300000);
- v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false);
- s->lna_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
+ dev->lna_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_LNA_GAIN_AUTO, 0, 1, 1, 1);
- s->lna_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ dev->lna_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_LNA_GAIN, 0, 15, 1, 10);
- v4l2_ctrl_auto_cluster(2, &s->lna_gain_auto, 0, false);
- s->mixer_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ v4l2_ctrl_auto_cluster(2, &dev->lna_gain_auto, 0, false);
+ dev->mixer_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO, 0, 1, 1, 1);
- s->mixer_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ dev->mixer_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1);
- v4l2_ctrl_auto_cluster(2, &s->mixer_gain_auto, 0, false);
- s->if_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ v4l2_ctrl_auto_cluster(2, &dev->mixer_gain_auto, 0, false);
+ dev->if_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_IF_GAIN_AUTO, 0, 1, 1, 1);
- s->if_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ dev->if_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_IF_GAIN, 0, 54, 1, 0);
- v4l2_ctrl_auto_cluster(2, &s->if_gain_auto, 0, false);
- s->pll_lock = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops,
+ v4l2_ctrl_auto_cluster(2, &dev->if_gain_auto, 0, false);
+ dev->pll_lock = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops,
V4L2_CID_RF_TUNER_PLL_LOCK, 0, 1, 1, 0);
- if (s->hdl.error) {
- ret = s->hdl.error;
- dev_err(&s->client->dev, "Could not initialize controls\n");
- v4l2_ctrl_handler_free(&s->hdl);
- goto err;
+ if (dev->hdl.error) {
+ ret = dev->hdl.error;
+ dev_err(&client->dev, "Could not initialize controls\n");
+ v4l2_ctrl_handler_free(&dev->hdl);
+ goto err_kfree;
}
- s->sd.ctrl_handler = &s->hdl;
+ dev->sd.ctrl_handler = &dev->hdl;
+ dev->f_frequency = bands[0].rangelow;
+ dev->f_bandwidth = dev->bandwidth->val;
+ v4l2_i2c_subdev_init(&dev->sd, client, &e4000_subdev_ops);
#endif
+ fe->tuner_priv = dev;
+ memcpy(&fe->ops.tuner_ops, &e4000_dvb_tuner_ops,
+ sizeof(fe->ops.tuner_ops));
+ v4l2_set_subdevdata(&dev->sd, client);
+ i2c_set_clientdata(client, &dev->sd);
- dev_info(&s->client->dev, "Elonics E4000 successfully identified\n");
-
- fe->tuner_priv = s;
- memcpy(&fe->ops.tuner_ops, &e4000_tuner_ops,
- sizeof(struct dvb_tuner_ops));
-
- v4l2_set_subdevdata(&s->sd, client);
- i2c_set_clientdata(client, &s->sd);
-
+ dev_info(&client->dev, "Elonics E4000 successfully identified\n");
return 0;
+err_kfree:
+ kfree(dev);
err:
- if (ret) {
- dev_dbg(&client->dev, "failed=%d\n", ret);
- kfree(s);
- }
-
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int e4000_remove(struct i2c_client *client)
{
struct v4l2_subdev *sd = i2c_get_clientdata(client);
- struct e4000 *s = container_of(sd, struct e4000, sd);
- struct dvb_frontend *fe = s->fe;
+ struct e4000_dev *dev = container_of(sd, struct e4000_dev, sd);
dev_dbg(&client->dev, "\n");
#if IS_ENABLED(CONFIG_VIDEO_V4L2)
- v4l2_ctrl_handler_free(&s->hdl);
+ v4l2_ctrl_handler_free(&dev->hdl);
#endif
- memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
- fe->tuner_priv = NULL;
- kfree(s);
+ kfree(dev);
return 0;
}
-static const struct i2c_device_id e4000_id[] = {
+static const struct i2c_device_id e4000_id_table[] = {
{"e4000", 0},
{}
};
-MODULE_DEVICE_TABLE(i2c, e4000_id);
+MODULE_DEVICE_TABLE(i2c, e4000_id_table);
static struct i2c_driver e4000_driver = {
.driver = {
- .owner = THIS_MODULE,
.name = "e4000",
+ .suppress_bind_attrs = true,
},
.probe = e4000_probe,
.remove = e4000_remove,
- .id_table = e4000_id,
+ .id_table = e4000_id_table,
};
module_i2c_driver(e4000_driver);
diff --git a/kernel/drivers/media/tuners/e4000.h b/kernel/drivers/media/tuners/e4000.h
index e74b8b2f2..aa9340c05 100644
--- a/kernel/drivers/media/tuners/e4000.h
+++ b/kernel/drivers/media/tuners/e4000.h
@@ -21,7 +21,6 @@
#ifndef E4000_H
#define E4000_H
-#include <linux/kconfig.h>
#include "dvb_frontend.h"
/*
diff --git a/kernel/drivers/media/tuners/e4000_priv.h b/kernel/drivers/media/tuners/e4000_priv.h
index cb0070483..d6d5d11bb 100644
--- a/kernel/drivers/media/tuners/e4000_priv.h
+++ b/kernel/drivers/media/tuners/e4000_priv.h
@@ -22,17 +22,20 @@
#define E4000_PRIV_H
#include "e4000.h"
+#include <linux/math64.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-subdev.h>
#include <linux/regmap.h>
-struct e4000 {
+struct e4000_dev {
struct i2c_client *client;
struct regmap *regmap;
- u32 clock;
+ u32 clk;
struct dvb_frontend *fe;
struct v4l2_subdev sd;
bool active;
+ unsigned int f_frequency;
+ unsigned int f_bandwidth;
/* Controls */
struct v4l2_ctrl_handler hdl;
@@ -49,8 +52,8 @@ struct e4000 {
struct e4000_pll {
u32 freq;
- u8 div;
- u8 mul;
+ u8 div_out_reg;
+ u8 div_out;
};
static const struct e4000_pll e4000_pll_lut[] = {
diff --git a/kernel/drivers/media/tuners/fc0013.c b/kernel/drivers/media/tuners/fc0013.c
index b41623157..522690d97 100644
--- a/kernel/drivers/media/tuners/fc0013.c
+++ b/kernel/drivers/media/tuners/fc0013.c
@@ -217,8 +217,6 @@ static int fc0013_set_vhf_track(struct fc0013_priv *priv, u32 freq)
} else { /* UHF and GPS */
ret = fc0013_writereg(priv, 0x1d, tmp | 0x1c);
}
- if (ret)
- goto error_out;
error_out:
return ret;
}
diff --git a/kernel/drivers/media/tuners/fc2580.c b/kernel/drivers/media/tuners/fc2580.c
index f0c9c4286..f4d4665de 100644
--- a/kernel/drivers/media/tuners/fc2580.c
+++ b/kernel/drivers/media/tuners/fc2580.c
@@ -20,535 +20,627 @@
#include "fc2580_priv.h"
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE 64
-
/*
* TODO:
* I2C write and read works only for one single register. Multiple registers
* could not be accessed using normal register address auto-increment.
* There could be (very likely) register to change that behavior....
- *
- * Due to that limitation functions:
- * fc2580_wr_regs()
- * fc2580_rd_regs()
- * could not be used for accessing more than one register at once.
- *
- * TODO:
- * Currently it blind writes bunch of static registers from the
- * fc2580_freq_regs_lut[] when fc2580_set_params() is called. Add some
- * logic to reduce unneeded register writes.
*/
-/* write multiple registers */
-static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
-{
- int ret;
- u8 buf[MAX_XFER_SIZE];
- struct i2c_msg msg[1] = {
- {
- .addr = priv->cfg->i2c_addr,
- .flags = 0,
- .len = 1 + len,
- .buf = buf,
- }
- };
-
- if (1 + len > sizeof(buf)) {
- dev_warn(&priv->i2c->dev,
- "%s: i2c wr reg=%04x: len=%d is too big!\n",
- KBUILD_MODNAME, reg, len);
- return -EINVAL;
- }
-
- buf[0] = reg;
- memcpy(&buf[1], val, len);
-
- ret = i2c_transfer(priv->i2c, msg, 1);
- if (ret == 1) {
- ret = 0;
- } else {
- dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \
- "len=%d\n", KBUILD_MODNAME, ret, reg, len);
- ret = -EREMOTEIO;
- }
- return ret;
-}
-
-/* read multiple registers */
-static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
-{
- int ret;
- u8 buf[MAX_XFER_SIZE];
- struct i2c_msg msg[2] = {
- {
- .addr = priv->cfg->i2c_addr,
- .flags = 0,
- .len = 1,
- .buf = &reg,
- }, {
- .addr = priv->cfg->i2c_addr,
- .flags = I2C_M_RD,
- .len = len,
- .buf = buf,
- }
- };
-
- if (len > sizeof(buf)) {
- dev_warn(&priv->i2c->dev,
- "%s: i2c rd reg=%04x: len=%d is too big!\n",
- KBUILD_MODNAME, reg, len);
- return -EINVAL;
- }
-
- ret = i2c_transfer(priv->i2c, msg, 2);
- if (ret == 2) {
- memcpy(val, buf, len);
- ret = 0;
- } else {
- dev_warn(&priv->i2c->dev, "%s: i2c rd failed=%d reg=%02x " \
- "len=%d\n", KBUILD_MODNAME, ret, reg, len);
- ret = -EREMOTEIO;
- }
-
- return ret;
-}
-
-/* write single register */
-static int fc2580_wr_reg(struct fc2580_priv *priv, u8 reg, u8 val)
-{
- return fc2580_wr_regs(priv, reg, &val, 1);
-}
-
-/* read single register */
-static int fc2580_rd_reg(struct fc2580_priv *priv, u8 reg, u8 *val)
-{
- return fc2580_rd_regs(priv, reg, val, 1);
-}
-
/* write single register conditionally only when value differs from 0xff
* XXX: This is special routine meant only for writing fc2580_freq_regs_lut[]
* values. Do not use for the other purposes. */
-static int fc2580_wr_reg_ff(struct fc2580_priv *priv, u8 reg, u8 val)
+static int fc2580_wr_reg_ff(struct fc2580_dev *dev, u8 reg, u8 val)
{
if (val == 0xff)
return 0;
else
- return fc2580_wr_regs(priv, reg, &val, 1);
+ return regmap_write(dev->regmap, reg, val);
}
-static int fc2580_set_params(struct dvb_frontend *fe)
+static int fc2580_set_params(struct fc2580_dev *dev)
{
- struct fc2580_priv *priv = fe->tuner_priv;
- struct dtv_frontend_properties *c = &fe->dtv_property_cache;
- int ret = 0, i;
- unsigned int r_val, n_val, k_val, k_val_reg, f_ref;
- u8 tmp_val, r18_val;
+ struct i2c_client *client = dev->client;
+ int ret, i;
+ unsigned int uitmp, div_ref, div_ref_val, div_n, k, k_cw, div_out;
u64 f_vco;
+ u8 synth_config;
+ unsigned long timeout;
+
+ if (!dev->active) {
+ dev_dbg(&client->dev, "tuner is sleeping\n");
+ return 0;
+ }
/*
- * Fractional-N synthesizer/PLL.
- * Most likely all those PLL calculations are not correct. I am not
- * sure, but it looks like it is divider based Fractional-N synthesizer.
- * There is divider for reference clock too?
- * Anyhow, synthesizer calculation results seems to be quite correct.
+ * Fractional-N synthesizer
+ *
+ * +---------------------------------------+
+ * v |
+ * Fref +----+ +----+ +-------+ +----+ +------+ +---+
+ * ------> | /R | --> | PD | --> | VCO | ------> | /2 | --> | /N.F | <-- | K |
+ * +----+ +----+ +-------+ +----+ +------+ +---+
+ * |
+ * |
+ * v
+ * +-------+ Fout
+ * | /Rout | ------>
+ * +-------+
*/
-
- dev_dbg(&priv->i2c->dev, "%s: delivery_system=%d frequency=%d " \
- "bandwidth_hz=%d\n", __func__,
- c->delivery_system, c->frequency, c->bandwidth_hz);
-
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 1);
-
- /* PLL */
for (i = 0; i < ARRAY_SIZE(fc2580_pll_lut); i++) {
- if (c->frequency <= fc2580_pll_lut[i].freq)
+ if (dev->f_frequency <= fc2580_pll_lut[i].freq)
break;
}
-
- if (i == ARRAY_SIZE(fc2580_pll_lut))
+ if (i == ARRAY_SIZE(fc2580_pll_lut)) {
+ ret = -EINVAL;
goto err;
+ }
- f_vco = c->frequency;
- f_vco *= fc2580_pll_lut[i].div;
-
- if (f_vco >= 2600000000UL)
- tmp_val = 0x0e | fc2580_pll_lut[i].band;
+ #define DIV_PRE_N 2
+ #define F_REF dev->clk
+ div_out = fc2580_pll_lut[i].div_out;
+ f_vco = (u64) dev->f_frequency * div_out;
+ synth_config = fc2580_pll_lut[i].band;
+ if (f_vco < 2600000000ULL)
+ synth_config |= 0x06;
else
- tmp_val = 0x06 | fc2580_pll_lut[i].band;
-
- ret = fc2580_wr_reg(priv, 0x02, tmp_val);
- if (ret < 0)
- goto err;
-
- if (f_vco >= 2UL * 76 * priv->cfg->clock) {
- r_val = 1;
- r18_val = 0x00;
- } else if (f_vco >= 1UL * 76 * priv->cfg->clock) {
- r_val = 2;
- r18_val = 0x10;
+ synth_config |= 0x0e;
+
+ /* select reference divider R (keep PLL div N in valid range) */
+ #define DIV_N_MIN 76
+ if (f_vco >= div_u64((u64) DIV_PRE_N * DIV_N_MIN * F_REF, 1)) {
+ div_ref = 1;
+ div_ref_val = 0x00;
+ } else if (f_vco >= div_u64((u64) DIV_PRE_N * DIV_N_MIN * F_REF, 2)) {
+ div_ref = 2;
+ div_ref_val = 0x10;
} else {
- r_val = 4;
- r18_val = 0x20;
+ div_ref = 4;
+ div_ref_val = 0x20;
}
- f_ref = 2UL * priv->cfg->clock / r_val;
- n_val = div_u64_rem(f_vco, f_ref, &k_val);
- k_val_reg = div_u64(1ULL * k_val * (1 << 20), f_ref);
+ /* calculate PLL integer and fractional control word */
+ uitmp = DIV_PRE_N * F_REF / div_ref;
+ div_n = div_u64_rem(f_vco, uitmp, &k);
+ k_cw = div_u64((u64) k * 0x100000, uitmp);
- ret = fc2580_wr_reg(priv, 0x18, r18_val | ((k_val_reg >> 16) & 0xff));
- if (ret < 0)
- goto err;
+ dev_dbg(&client->dev,
+ "frequency=%u bandwidth=%u f_vco=%llu F_REF=%u div_ref=%u div_n=%u k=%u div_out=%u k_cw=%0x\n",
+ dev->f_frequency, dev->f_bandwidth, f_vco, F_REF, div_ref,
+ div_n, k, div_out, k_cw);
- ret = fc2580_wr_reg(priv, 0x1a, (k_val_reg >> 8) & 0xff);
- if (ret < 0)
+ ret = regmap_write(dev->regmap, 0x02, synth_config);
+ if (ret)
goto err;
- ret = fc2580_wr_reg(priv, 0x1b, (k_val_reg >> 0) & 0xff);
- if (ret < 0)
+ ret = regmap_write(dev->regmap, 0x18, div_ref_val << 0 | k_cw >> 16);
+ if (ret)
goto err;
- ret = fc2580_wr_reg(priv, 0x1c, n_val);
- if (ret < 0)
+ ret = regmap_write(dev->regmap, 0x1a, (k_cw >> 8) & 0xff);
+ if (ret)
goto err;
- if (priv->cfg->clock >= 28000000) {
- ret = fc2580_wr_reg(priv, 0x4b, 0x22);
- if (ret < 0)
- goto err;
- }
-
- if (fc2580_pll_lut[i].band == 0x00) {
- if (c->frequency <= 794000000)
- tmp_val = 0x9f;
- else
- tmp_val = 0x8f;
+ ret = regmap_write(dev->regmap, 0x1b, (k_cw >> 0) & 0xff);
+ if (ret)
+ goto err;
- ret = fc2580_wr_reg(priv, 0x2d, tmp_val);
- if (ret < 0)
- goto err;
- }
+ ret = regmap_write(dev->regmap, 0x1c, div_n);
+ if (ret)
+ goto err;
/* registers */
for (i = 0; i < ARRAY_SIZE(fc2580_freq_regs_lut); i++) {
- if (c->frequency <= fc2580_freq_regs_lut[i].freq)
+ if (dev->f_frequency <= fc2580_freq_regs_lut[i].freq)
break;
}
-
- if (i == ARRAY_SIZE(fc2580_freq_regs_lut))
+ if (i == ARRAY_SIZE(fc2580_freq_regs_lut)) {
+ ret = -EINVAL;
goto err;
+ }
- ret = fc2580_wr_reg_ff(priv, 0x25, fc2580_freq_regs_lut[i].r25_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x25, fc2580_freq_regs_lut[i].r25_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x27, fc2580_freq_regs_lut[i].r27_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x27, fc2580_freq_regs_lut[i].r27_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x28, fc2580_freq_regs_lut[i].r28_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x28, fc2580_freq_regs_lut[i].r28_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x29, fc2580_freq_regs_lut[i].r29_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x29, fc2580_freq_regs_lut[i].r29_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x2b, fc2580_freq_regs_lut[i].r2b_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x2b, fc2580_freq_regs_lut[i].r2b_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x2c, fc2580_freq_regs_lut[i].r2c_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x2c, fc2580_freq_regs_lut[i].r2c_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x2d, fc2580_freq_regs_lut[i].r2d_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x2d, fc2580_freq_regs_lut[i].r2d_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x30, fc2580_freq_regs_lut[i].r30_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x30, fc2580_freq_regs_lut[i].r30_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x44, fc2580_freq_regs_lut[i].r44_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x44, fc2580_freq_regs_lut[i].r44_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x50, fc2580_freq_regs_lut[i].r50_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x50, fc2580_freq_regs_lut[i].r50_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x53, fc2580_freq_regs_lut[i].r53_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x53, fc2580_freq_regs_lut[i].r53_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x5f, fc2580_freq_regs_lut[i].r5f_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x5f, fc2580_freq_regs_lut[i].r5f_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x61, fc2580_freq_regs_lut[i].r61_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x61, fc2580_freq_regs_lut[i].r61_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x62, fc2580_freq_regs_lut[i].r62_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x62, fc2580_freq_regs_lut[i].r62_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x63, fc2580_freq_regs_lut[i].r63_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x63, fc2580_freq_regs_lut[i].r63_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x67, fc2580_freq_regs_lut[i].r67_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x67, fc2580_freq_regs_lut[i].r67_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x68, fc2580_freq_regs_lut[i].r68_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x68, fc2580_freq_regs_lut[i].r68_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x69, fc2580_freq_regs_lut[i].r69_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x69, fc2580_freq_regs_lut[i].r69_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x6a, fc2580_freq_regs_lut[i].r6a_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x6a, fc2580_freq_regs_lut[i].r6a_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x6b, fc2580_freq_regs_lut[i].r6b_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x6b, fc2580_freq_regs_lut[i].r6b_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x6c, fc2580_freq_regs_lut[i].r6c_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x6c, fc2580_freq_regs_lut[i].r6c_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x6d, fc2580_freq_regs_lut[i].r6d_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x6d, fc2580_freq_regs_lut[i].r6d_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x6e, fc2580_freq_regs_lut[i].r6e_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x6e, fc2580_freq_regs_lut[i].r6e_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg_ff(priv, 0x6f, fc2580_freq_regs_lut[i].r6f_val);
- if (ret < 0)
+ ret = fc2580_wr_reg_ff(dev, 0x6f, fc2580_freq_regs_lut[i].r6f_val);
+ if (ret)
goto err;
/* IF filters */
for (i = 0; i < ARRAY_SIZE(fc2580_if_filter_lut); i++) {
- if (c->bandwidth_hz <= fc2580_if_filter_lut[i].freq)
+ if (dev->f_bandwidth <= fc2580_if_filter_lut[i].freq)
break;
}
-
- if (i == ARRAY_SIZE(fc2580_if_filter_lut))
- goto err;
-
- ret = fc2580_wr_reg(priv, 0x36, fc2580_if_filter_lut[i].r36_val);
- if (ret < 0)
+ if (i == ARRAY_SIZE(fc2580_if_filter_lut)) {
+ ret = -EINVAL;
goto err;
+ }
- ret = fc2580_wr_reg(priv, 0x37, div_u64(1ULL * priv->cfg->clock *
- fc2580_if_filter_lut[i].mul, 1000000000));
- if (ret < 0)
+ ret = regmap_write(dev->regmap, 0x36, fc2580_if_filter_lut[i].r36_val);
+ if (ret)
goto err;
- ret = fc2580_wr_reg(priv, 0x39, fc2580_if_filter_lut[i].r39_val);
- if (ret < 0)
+ uitmp = (unsigned int) 8058000 - (dev->f_bandwidth * 122 / 100 / 2);
+ uitmp = div64_u64((u64) dev->clk * uitmp, 1000000000000ULL);
+ ret = regmap_write(dev->regmap, 0x37, uitmp);
+ if (ret)
goto err;
- /* calibration? */
- ret = fc2580_wr_reg(priv, 0x2e, 0x09);
- if (ret < 0)
+ ret = regmap_write(dev->regmap, 0x39, fc2580_if_filter_lut[i].r39_val);
+ if (ret)
goto err;
- for (i = 0; i < 5; i++) {
- ret = fc2580_rd_reg(priv, 0x2f, &tmp_val);
- if (ret < 0)
+ timeout = jiffies + msecs_to_jiffies(30);
+ for (uitmp = ~0xc0; !time_after(jiffies, timeout) && uitmp != 0xc0;) {
+ /* trigger filter */
+ ret = regmap_write(dev->regmap, 0x2e, 0x09);
+ if (ret)
goto err;
- /* done when [7:6] are set */
- if ((tmp_val & 0xc0) == 0xc0)
- break;
-
- ret = fc2580_wr_reg(priv, 0x2e, 0x01);
- if (ret < 0)
+ /* locked when [7:6] are set (val: d7 6MHz, d5 7MHz, cd 8MHz) */
+ ret = regmap_read(dev->regmap, 0x2f, &uitmp);
+ if (ret)
goto err;
+ uitmp &= 0xc0;
- ret = fc2580_wr_reg(priv, 0x2e, 0x09);
- if (ret < 0)
+ ret = regmap_write(dev->regmap, 0x2e, 0x01);
+ if (ret)
goto err;
-
- usleep_range(5000, 25000);
}
-
- dev_dbg(&priv->i2c->dev, "%s: loop=%i\n", __func__, i);
-
- ret = fc2580_wr_reg(priv, 0x2e, 0x01);
- if (ret < 0)
- goto err;
-
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
+ if (uitmp != 0xc0)
+ dev_dbg(&client->dev, "filter did not lock %02x\n", uitmp);
return 0;
err:
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
-
- dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
-static int fc2580_init(struct dvb_frontend *fe)
+static int fc2580_init(struct fc2580_dev *dev)
{
- struct fc2580_priv *priv = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
int ret, i;
- dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
-
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 1);
+ dev_dbg(&client->dev, "\n");
for (i = 0; i < ARRAY_SIZE(fc2580_init_reg_vals); i++) {
- ret = fc2580_wr_reg(priv, fc2580_init_reg_vals[i].reg,
+ ret = regmap_write(dev->regmap, fc2580_init_reg_vals[i].reg,
fc2580_init_reg_vals[i].val);
- if (ret < 0)
+ if (ret)
goto err;
}
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
-
+ dev->active = true;
return 0;
err:
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
-
- dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
-static int fc2580_sleep(struct dvb_frontend *fe)
+static int fc2580_sleep(struct fc2580_dev *dev)
{
- struct fc2580_priv *priv = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
int ret;
- dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
+ dev_dbg(&client->dev, "\n");
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 1);
+ dev->active = false;
- ret = fc2580_wr_reg(priv, 0x02, 0x0a);
- if (ret < 0)
+ ret = regmap_write(dev->regmap, 0x02, 0x0a);
+ if (ret)
goto err;
-
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
-
return 0;
err:
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
-
- dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
-static int fc2580_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
+/*
+ * DVB API
+ */
+static int fc2580_dvb_set_params(struct dvb_frontend *fe)
{
- struct fc2580_priv *priv = fe->tuner_priv;
-
- dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
-
- *frequency = 0; /* Zero-IF */
+ struct fc2580_dev *dev = fe->tuner_priv;
+ struct dtv_frontend_properties *c = &fe->dtv_property_cache;
- return 0;
+ dev->f_frequency = c->frequency;
+ dev->f_bandwidth = c->bandwidth_hz;
+ return fc2580_set_params(dev);
}
-static int fc2580_release(struct dvb_frontend *fe)
+static int fc2580_dvb_init(struct dvb_frontend *fe)
{
- struct fc2580_priv *priv = fe->tuner_priv;
-
- dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
+ return fc2580_init(fe->tuner_priv);
+}
- kfree(fe->tuner_priv);
+static int fc2580_dvb_sleep(struct dvb_frontend *fe)
+{
+ return fc2580_sleep(fe->tuner_priv);
+}
+static int fc2580_dvb_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
+{
+ *frequency = 0; /* Zero-IF */
return 0;
}
-static const struct dvb_tuner_ops fc2580_tuner_ops = {
+static const struct dvb_tuner_ops fc2580_dvb_tuner_ops = {
.info = {
.name = "FCI FC2580",
.frequency_min = 174000000,
.frequency_max = 862000000,
},
- .release = fc2580_release,
+ .init = fc2580_dvb_init,
+ .sleep = fc2580_dvb_sleep,
+ .set_params = fc2580_dvb_set_params,
+
+ .get_if_frequency = fc2580_dvb_get_if_frequency,
+};
+
+/*
+ * V4L2 API
+ */
+#if IS_ENABLED(CONFIG_VIDEO_V4L2)
+static const struct v4l2_frequency_band bands[] = {
+ {
+ .type = V4L2_TUNER_RF,
+ .index = 0,
+ .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
+ .rangelow = 130000000,
+ .rangehigh = 2000000000,
+ },
+};
+
+static inline struct fc2580_dev *fc2580_subdev_to_dev(struct v4l2_subdev *sd)
+{
+ return container_of(sd, struct fc2580_dev, subdev);
+}
+
+static int fc2580_s_power(struct v4l2_subdev *sd, int on)
+{
+ struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+ int ret;
+
+ dev_dbg(&client->dev, "on=%d\n", on);
+
+ if (on)
+ ret = fc2580_init(dev);
+ else
+ ret = fc2580_sleep(dev);
+ if (ret)
+ return ret;
+
+ return fc2580_set_params(dev);
+}
+
+static const struct v4l2_subdev_core_ops fc2580_subdev_core_ops = {
+ .s_power = fc2580_s_power,
+};
+
+static int fc2580_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
+{
+ struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+
+ dev_dbg(&client->dev, "index=%d\n", v->index);
+
+ strlcpy(v->name, "FCI FC2580", sizeof(v->name));
+ v->type = V4L2_TUNER_RF;
+ v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
+ v->rangelow = bands[0].rangelow;
+ v->rangehigh = bands[0].rangehigh;
+ return 0;
+}
+
+static int fc2580_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v)
+{
+ struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+
+ dev_dbg(&client->dev, "index=%d\n", v->index);
+ return 0;
+}
+
+static int fc2580_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
+{
+ struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+
+ dev_dbg(&client->dev, "tuner=%d\n", f->tuner);
+ f->frequency = dev->f_frequency;
+ return 0;
+}
+
+static int fc2580_s_frequency(struct v4l2_subdev *sd,
+ const struct v4l2_frequency *f)
+{
+ struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+
+ dev_dbg(&client->dev, "tuner=%d type=%d frequency=%u\n",
+ f->tuner, f->type, f->frequency);
+
+ dev->f_frequency = clamp_t(unsigned int, f->frequency,
+ bands[0].rangelow, bands[0].rangehigh);
+ return fc2580_set_params(dev);
+}
+
+static int fc2580_enum_freq_bands(struct v4l2_subdev *sd,
+ struct v4l2_frequency_band *band)
+{
+ struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
+ struct i2c_client *client = dev->client;
+
+ dev_dbg(&client->dev, "tuner=%d type=%d index=%d\n",
+ band->tuner, band->type, band->index);
- .init = fc2580_init,
- .sleep = fc2580_sleep,
- .set_params = fc2580_set_params,
+ if (band->index >= ARRAY_SIZE(bands))
+ return -EINVAL;
- .get_if_frequency = fc2580_get_if_frequency,
+ band->capability = bands[band->index].capability;
+ band->rangelow = bands[band->index].rangelow;
+ band->rangehigh = bands[band->index].rangehigh;
+ return 0;
+}
+
+static const struct v4l2_subdev_tuner_ops fc2580_subdev_tuner_ops = {
+ .g_tuner = fc2580_g_tuner,
+ .s_tuner = fc2580_s_tuner,
+ .g_frequency = fc2580_g_frequency,
+ .s_frequency = fc2580_s_frequency,
+ .enum_freq_bands = fc2580_enum_freq_bands,
+};
+
+static const struct v4l2_subdev_ops fc2580_subdev_ops = {
+ .core = &fc2580_subdev_core_ops,
+ .tuner = &fc2580_subdev_tuner_ops,
};
-struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
- struct i2c_adapter *i2c, const struct fc2580_config *cfg)
+static int fc2580_s_ctrl(struct v4l2_ctrl *ctrl)
{
- struct fc2580_priv *priv;
+ struct fc2580_dev *dev = container_of(ctrl->handler, struct fc2580_dev, hdl);
+ struct i2c_client *client = dev->client;
int ret;
- u8 chip_id;
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 1);
+ dev_dbg(&client->dev, "ctrl: id=%d name=%s cur.val=%d val=%d\n",
+ ctrl->id, ctrl->name, ctrl->cur.val, ctrl->val);
+
+ switch (ctrl->id) {
+ case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
+ case V4L2_CID_RF_TUNER_BANDWIDTH:
+ /*
+ * TODO: Auto logic does not work 100% correctly as tuner driver
+ * do not have information to calculate maximum suitable
+ * bandwidth. Calculating it is responsible of master driver.
+ */
+ dev->f_bandwidth = dev->bandwidth->val;
+ ret = fc2580_set_params(dev);
+ break;
+ default:
+ dev_dbg(&client->dev, "unknown ctrl");
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+static const struct v4l2_ctrl_ops fc2580_ctrl_ops = {
+ .s_ctrl = fc2580_s_ctrl,
+};
+#endif
+
+static struct v4l2_subdev *fc2580_get_v4l2_subdev(struct i2c_client *client)
+{
+ struct fc2580_dev *dev = i2c_get_clientdata(client);
+
+ if (dev->subdev.ops)
+ return &dev->subdev;
+ else
+ return NULL;
+}
+
+static int fc2580_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct fc2580_dev *dev;
+ struct fc2580_platform_data *pdata = client->dev.platform_data;
+ struct dvb_frontend *fe = pdata->dvb_frontend;
+ int ret;
+ unsigned int uitmp;
+ static const struct regmap_config regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ };
- priv = kzalloc(sizeof(struct fc2580_priv), GFP_KERNEL);
- if (!priv) {
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev) {
ret = -ENOMEM;
- dev_err(&i2c->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME);
goto err;
}
- priv->cfg = cfg;
- priv->i2c = i2c;
+ if (pdata->clk)
+ dev->clk = pdata->clk;
+ else
+ dev->clk = 16384000; /* internal clock */
+ dev->client = client;
+ dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
+ if (IS_ERR(dev->regmap)) {
+ ret = PTR_ERR(dev->regmap);
+ goto err_kfree;
+ }
/* check if the tuner is there */
- ret = fc2580_rd_reg(priv, 0x01, &chip_id);
- if (ret < 0)
- goto err;
+ ret = regmap_read(dev->regmap, 0x01, &uitmp);
+ if (ret)
+ goto err_kfree;
- dev_dbg(&priv->i2c->dev, "%s: chip_id=%02x\n", __func__, chip_id);
+ dev_dbg(&client->dev, "chip_id=%02x\n", uitmp);
- switch (chip_id) {
+ switch (uitmp) {
case 0x56:
case 0x5a:
break;
default:
- goto err;
+ ret = -ENODEV;
+ goto err_kfree;
}
- dev_info(&priv->i2c->dev,
- "%s: FCI FC2580 successfully identified\n",
- KBUILD_MODNAME);
-
- fe->tuner_priv = priv;
- memcpy(&fe->ops.tuner_ops, &fc2580_tuner_ops,
- sizeof(struct dvb_tuner_ops));
+#if IS_ENABLED(CONFIG_VIDEO_V4L2)
+ /* Register controls */
+ v4l2_ctrl_handler_init(&dev->hdl, 2);
+ dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &fc2580_ctrl_ops,
+ V4L2_CID_RF_TUNER_BANDWIDTH_AUTO,
+ 0, 1, 1, 1);
+ dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &fc2580_ctrl_ops,
+ V4L2_CID_RF_TUNER_BANDWIDTH,
+ 3000, 10000000, 1, 3000);
+ v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
+ if (dev->hdl.error) {
+ ret = dev->hdl.error;
+ dev_err(&client->dev, "Could not initialize controls\n");
+ v4l2_ctrl_handler_free(&dev->hdl);
+ goto err_kfree;
+ }
+ dev->subdev.ctrl_handler = &dev->hdl;
+ dev->f_frequency = bands[0].rangelow;
+ dev->f_bandwidth = dev->bandwidth->val;
+ v4l2_i2c_subdev_init(&dev->subdev, client, &fc2580_subdev_ops);
+#endif
+ fe->tuner_priv = dev;
+ memcpy(&fe->ops.tuner_ops, &fc2580_dvb_tuner_ops,
+ sizeof(fe->ops.tuner_ops));
+ pdata->get_v4l2_subdev = fc2580_get_v4l2_subdev;
+ i2c_set_clientdata(client, dev);
+
+ dev_info(&client->dev, "FCI FC2580 successfully identified\n");
+ return 0;
+err_kfree:
+ kfree(dev);
+err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
+ return ret;
+}
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
+static int fc2580_remove(struct i2c_client *client)
+{
+ struct fc2580_dev *dev = i2c_get_clientdata(client);
- return fe;
-err:
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
+ dev_dbg(&client->dev, "\n");
- dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret);
- kfree(priv);
- return NULL;
+#if IS_ENABLED(CONFIG_VIDEO_V4L2)
+ v4l2_ctrl_handler_free(&dev->hdl);
+#endif
+ kfree(dev);
+ return 0;
}
-EXPORT_SYMBOL(fc2580_attach);
+
+static const struct i2c_device_id fc2580_id_table[] = {
+ {"fc2580", 0},
+ {}
+};
+MODULE_DEVICE_TABLE(i2c, fc2580_id_table);
+
+static struct i2c_driver fc2580_driver = {
+ .driver = {
+ .name = "fc2580",
+ .suppress_bind_attrs = true,
+ },
+ .probe = fc2580_probe,
+ .remove = fc2580_remove,
+ .id_table = fc2580_id_table,
+};
+
+module_i2c_driver(fc2580_driver);
MODULE_DESCRIPTION("FCI FC2580 silicon tuner driver");
MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
diff --git a/kernel/drivers/media/tuners/fc2580.h b/kernel/drivers/media/tuners/fc2580.h
index b1ce6770f..862ea4699 100644
--- a/kernel/drivers/media/tuners/fc2580.h
+++ b/kernel/drivers/media/tuners/fc2580.h
@@ -21,32 +21,26 @@
#ifndef FC2580_H
#define FC2580_H
-#include <linux/kconfig.h>
#include "dvb_frontend.h"
+#include <media/v4l2-subdev.h>
+#include <linux/i2c.h>
-struct fc2580_config {
- /*
- * I2C address
- * 0x56, ...
- */
- u8 i2c_addr;
+/*
+ * I2C address
+ * 0x56, ...
+ */
- /*
- * clock
- */
- u32 clock;
-};
+/**
+ * struct fc2580_platform_data - Platform data for the fc2580 driver
+ * @clk: Clock frequency (0 = internal clock).
+ * @dvb_frontend: DVB frontend.
+ * @get_v4l2_subdev: Get V4L2 subdev.
+ */
+struct fc2580_platform_data {
+ u32 clk;
+ struct dvb_frontend *dvb_frontend;
-#if IS_REACHABLE(CONFIG_MEDIA_TUNER_FC2580)
-extern struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
- struct i2c_adapter *i2c, const struct fc2580_config *cfg);
-#else
-static inline struct dvb_frontend *fc2580_attach(struct dvb_frontend *fe,
- struct i2c_adapter *i2c, const struct fc2580_config *cfg)
-{
- pr_warn("%s: driver disabled by Kconfig\n", __func__);
- return NULL;
-}
-#endif
+ struct v4l2_subdev* (*get_v4l2_subdev)(struct i2c_client *);
+};
#endif
diff --git a/kernel/drivers/media/tuners/fc2580_priv.h b/kernel/drivers/media/tuners/fc2580_priv.h
index 646c99452..031a43d7e 100644
--- a/kernel/drivers/media/tuners/fc2580_priv.h
+++ b/kernel/drivers/media/tuners/fc2580_priv.h
@@ -22,6 +22,9 @@
#define FC2580_PRIV_H
#include "fc2580.h"
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-subdev.h>
+#include <linux/regmap.h>
#include <linux/math64.h>
struct fc2580_reg_val {
@@ -50,7 +53,7 @@ static const struct fc2580_reg_val fc2580_init_reg_vals[] = {
struct fc2580_pll {
u32 freq;
- u8 div;
+ u8 div_out;
u8 band;
};
@@ -63,16 +66,15 @@ static const struct fc2580_pll fc2580_pll_lut[] = {
struct fc2580_if_filter {
u32 freq;
- u16 mul;
u8 r36_val;
u8 r39_val;
};
static const struct fc2580_if_filter fc2580_if_filter_lut[] = {
- { 6000000, 4400, 0x18, 0x00},
- { 7000000, 3910, 0x18, 0x80},
- { 8000000, 3300, 0x18, 0x80},
- {0xffffffff, 3300, 0x18, 0x80},
+ { 6000000, 0x18, 0x00},
+ { 7000000, 0x18, 0x80},
+ { 8000000, 0x18, 0x80},
+ {0xffffffff, 0x18, 0x80},
};
struct fc2580_freq_regs {
@@ -110,15 +112,15 @@ static const struct fc2580_freq_regs fc2580_freq_regs_lut[] = {
0x50, 0x0f, 0x07, 0x00, 0x15, 0x03, 0x05, 0x10, 0x12, 0x08,
0x0a, 0x78, 0x32, 0x54},
{ 538000000,
- 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0xff, 0x09, 0xff, 0x8c,
+ 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x9f, 0x09, 0xff, 0x8c,
0x50, 0x13, 0x07, 0x06, 0x15, 0x06, 0x08, 0x10, 0x12, 0x0b,
0x0c, 0x78, 0x32, 0x14},
{ 794000000,
- 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0xff, 0x09, 0xff, 0x8c,
+ 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x9f, 0x09, 0xff, 0x8c,
0x50, 0x15, 0x03, 0x03, 0x15, 0x03, 0x05, 0x0c, 0x0e, 0x0b,
0x0c, 0x78, 0x32, 0x14},
{1000000000,
- 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0xff, 0x09, 0xff, 0x8c,
+ 0xf0, 0x77, 0x53, 0x60, 0xff, 0xff, 0x8f, 0x09, 0xff, 0x8c,
0x50, 0x15, 0x07, 0x06, 0x15, 0x07, 0x09, 0x10, 0x12, 0x0b,
0x0c, 0x78, 0x32, 0x14},
{0xffffffff,
@@ -127,9 +129,19 @@ static const struct fc2580_freq_regs fc2580_freq_regs_lut[] = {
0x0a, 0xa0, 0x50, 0x14},
};
-struct fc2580_priv {
- const struct fc2580_config *cfg;
- struct i2c_adapter *i2c;
+struct fc2580_dev {
+ u32 clk;
+ struct i2c_client *client;
+ struct regmap *regmap;
+ struct v4l2_subdev subdev;
+ bool active;
+ unsigned int f_frequency;
+ unsigned int f_bandwidth;
+
+ /* Controls */
+ struct v4l2_ctrl_handler hdl;
+ struct v4l2_ctrl *bandwidth_auto;
+ struct v4l2_ctrl *bandwidth;
};
#endif
diff --git a/kernel/drivers/media/tuners/it913x.c b/kernel/drivers/media/tuners/it913x.c
index a076c87ed..5c96da693 100644
--- a/kernel/drivers/media/tuners/it913x.c
+++ b/kernel/drivers/media/tuners/it913x.c
@@ -463,7 +463,6 @@ MODULE_DEVICE_TABLE(i2c, it913x_id_table);
static struct i2c_driver it913x_driver = {
.driver = {
- .owner = THIS_MODULE,
.name = "it913x",
},
.probe = it913x_probe,
diff --git a/kernel/drivers/media/tuners/m88rs6000t.c b/kernel/drivers/media/tuners/m88rs6000t.c
index d4c13fe6e..504bfbc40 100644
--- a/kernel/drivers/media/tuners/m88rs6000t.c
+++ b/kernel/drivers/media/tuners/m88rs6000t.c
@@ -729,7 +729,6 @@ MODULE_DEVICE_TABLE(i2c, m88rs6000t_id);
static struct i2c_driver m88rs6000t_driver = {
.driver = {
- .owner = THIS_MODULE,
.name = "m88rs6000t",
},
.probe = m88rs6000t_probe,
diff --git a/kernel/drivers/media/tuners/msi001.c b/kernel/drivers/media/tuners/msi001.c
index 74cfc3c98..3a12ef356 100644
--- a/kernel/drivers/media/tuners/msi001.c
+++ b/kernel/drivers/media/tuners/msi001.c
@@ -36,7 +36,7 @@ static const struct v4l2_frequency_band bands[] = {
},
};
-struct msi001 {
+struct msi001_dev {
struct spi_device *spi;
struct v4l2_subdev sd;
@@ -51,25 +51,26 @@ struct msi001 {
unsigned int f_tuner;
};
-static inline struct msi001 *sd_to_msi001(struct v4l2_subdev *sd)
+static inline struct msi001_dev *sd_to_msi001_dev(struct v4l2_subdev *sd)
{
- return container_of(sd, struct msi001, sd);
+ return container_of(sd, struct msi001_dev, sd);
}
-static int msi001_wreg(struct msi001 *s, u32 data)
+static int msi001_wreg(struct msi001_dev *dev, u32 data)
{
/* Register format: 4 bits addr + 20 bits value */
- return spi_write(s->spi, &data, 3);
+ return spi_write(dev->spi, &data, 3);
};
-static int msi001_set_gain(struct msi001 *s, int lna_gain, int mixer_gain,
- int if_gain)
+static int msi001_set_gain(struct msi001_dev *dev, int lna_gain, int mixer_gain,
+ int if_gain)
{
+ struct spi_device *spi = dev->spi;
int ret;
u32 reg;
- dev_dbg(&s->spi->dev, "lna=%d mixer=%d if=%d\n",
- lna_gain, mixer_gain, if_gain);
+ dev_dbg(&spi->dev, "lna=%d mixer=%d if=%d\n",
+ lna_gain, mixer_gain, if_gain);
reg = 1 << 0;
reg |= (59 - if_gain) << 4;
@@ -78,28 +79,29 @@ static int msi001_set_gain(struct msi001 *s, int lna_gain, int mixer_gain,
reg |= (1 - lna_gain) << 13;
reg |= 4 << 14;
reg |= 0 << 17;
- ret = msi001_wreg(s, reg);
+ ret = msi001_wreg(dev, reg);
if (ret)
goto err;
return 0;
err:
- dev_dbg(&s->spi->dev, "failed %d\n", ret);
+ dev_dbg(&spi->dev, "failed %d\n", ret);
return ret;
};
-static int msi001_set_tuner(struct msi001 *s)
+static int msi001_set_tuner(struct msi001_dev *dev)
{
+ struct spi_device *spi = dev->spi;
int ret, i;
- unsigned int n, m, thresh, frac, vco_step, tmp, f_if1;
+ unsigned int uitmp, div_n, k, k_thresh, k_frac, div_lo, f_if1;
u32 reg;
- u64 f_vco, tmp64;
- u8 mode, filter_mode, lo_div;
+ u64 f_vco;
+ u8 mode, filter_mode;
static const struct {
u32 rf;
u8 mode;
- u8 lo_div;
+ u8 div_lo;
} band_lut[] = {
{ 50000000, 0xe1, 16}, /* AM_MODE2, antenna 2 */
{108000000, 0x42, 32}, /* VHF_MODE */
@@ -130,7 +132,7 @@ static int msi001_set_tuner(struct msi001 *s)
{8000000, 0x07}, /* 8 MHz */
};
- unsigned int f_rf = s->f_tuner;
+ unsigned int f_rf = dev->f_tuner;
/*
* bandwidth (Hz)
@@ -144,19 +146,18 @@ static int msi001_set_tuner(struct msi001 *s)
*/
unsigned int f_if = 0;
#define F_REF 24000000
- #define R_REF 4
- #define F_OUT_STEP 1
+ #define DIV_PRE_N 4
+ #define F_VCO_STEP div_lo
- dev_dbg(&s->spi->dev, "f_rf=%d f_if=%d\n", f_rf, f_if);
+ dev_dbg(&spi->dev, "f_rf=%d f_if=%d\n", f_rf, f_if);
for (i = 0; i < ARRAY_SIZE(band_lut); i++) {
if (f_rf <= band_lut[i].rf) {
mode = band_lut[i].mode;
- lo_div = band_lut[i].lo_div;
+ div_lo = band_lut[i].div_lo;
break;
}
}
-
if (i == ARRAY_SIZE(band_lut)) {
ret = -EINVAL;
goto err;
@@ -174,14 +175,13 @@ static int msi001_set_tuner(struct msi001 *s)
break;
}
}
-
if (i == ARRAY_SIZE(if_freq_lut)) {
ret = -EINVAL;
goto err;
}
/* filters */
- bandwidth = s->bandwidth->val;
+ bandwidth = dev->bandwidth->val;
bandwidth = clamp(bandwidth, 200000U, 8000000U);
for (i = 0; i < ARRAY_SIZE(bandwidth_lut); i++) {
@@ -190,48 +190,61 @@ static int msi001_set_tuner(struct msi001 *s)
break;
}
}
-
if (i == ARRAY_SIZE(bandwidth_lut)) {
ret = -EINVAL;
goto err;
}
- s->bandwidth->val = bandwidth_lut[i].freq;
+ dev->bandwidth->val = bandwidth_lut[i].freq;
- dev_dbg(&s->spi->dev, "bandwidth selected=%d\n", bandwidth_lut[i].freq);
+ dev_dbg(&spi->dev, "bandwidth selected=%d\n", bandwidth_lut[i].freq);
- f_vco = (u64) (f_rf + f_if + f_if1) * lo_div;
- tmp64 = f_vco;
- m = do_div(tmp64, F_REF * R_REF);
- n = (unsigned int) tmp64;
+ /*
+ * Fractional-N synthesizer
+ *
+ * +---------------------------------------+
+ * v |
+ * Fref +----+ +-------+ +----+ +------+ +---+
+ * ------> | PD | --> | VCO | ------> | /4 | --> | /N.F | <-- | K |
+ * +----+ +-------+ +----+ +------+ +---+
+ * |
+ * |
+ * v
+ * +-------+ Fout
+ * | /Rout | ------>
+ * +-------+
+ */
- vco_step = F_OUT_STEP * lo_div;
- thresh = (F_REF * R_REF) / vco_step;
- frac = 1ul * thresh * m / (F_REF * R_REF);
+ /* Calculate PLL integer and fractional control word. */
+ f_vco = (u64) (f_rf + f_if + f_if1) * div_lo;
+ div_n = div_u64_rem(f_vco, DIV_PRE_N * F_REF, &k);
+ k_thresh = (DIV_PRE_N * F_REF) / F_VCO_STEP;
+ k_frac = div_u64((u64) k * k_thresh, (DIV_PRE_N * F_REF));
/* Find out greatest common divisor and divide to smaller. */
- tmp = gcd(thresh, frac);
- thresh /= tmp;
- frac /= tmp;
+ uitmp = gcd(k_thresh, k_frac);
+ k_thresh /= uitmp;
+ k_frac /= uitmp;
/* Force divide to reg max. Resolution will be reduced. */
- tmp = DIV_ROUND_UP(thresh, 4095);
- thresh = DIV_ROUND_CLOSEST(thresh, tmp);
- frac = DIV_ROUND_CLOSEST(frac, tmp);
+ uitmp = DIV_ROUND_UP(k_thresh, 4095);
+ k_thresh = DIV_ROUND_CLOSEST(k_thresh, uitmp);
+ k_frac = DIV_ROUND_CLOSEST(k_frac, uitmp);
- /* calc real RF set */
- tmp = 1ul * F_REF * R_REF * n;
- tmp += 1ul * F_REF * R_REF * frac / thresh;
- tmp /= lo_div;
+ /* Calculate real RF set. */
+ uitmp = (unsigned int) F_REF * DIV_PRE_N * div_n;
+ uitmp += (unsigned int) F_REF * DIV_PRE_N * k_frac / k_thresh;
+ uitmp /= div_lo;
- dev_dbg(&s->spi->dev, "rf=%u:%u n=%d thresh=%d frac=%d\n",
- f_rf, tmp, n, thresh, frac);
+ dev_dbg(&spi->dev,
+ "f_rf=%u:%u f_vco=%llu div_n=%u k_thresh=%u k_frac=%u div_lo=%u\n",
+ f_rf, uitmp, f_vco, div_n, k_thresh, k_frac, div_lo);
- ret = msi001_wreg(s, 0x00000e);
+ ret = msi001_wreg(dev, 0x00000e);
if (ret)
goto err;
- ret = msi001_wreg(s, 0x000003);
+ ret = msi001_wreg(dev, 0x000003);
if (ret)
goto err;
@@ -241,54 +254,55 @@ static int msi001_set_tuner(struct msi001 *s)
reg |= bandwidth << 14;
reg |= 0x02 << 17;
reg |= 0x00 << 20;
- ret = msi001_wreg(s, reg);
+ ret = msi001_wreg(dev, reg);
if (ret)
goto err;
reg = 5 << 0;
- reg |= thresh << 4;
+ reg |= k_thresh << 4;
reg |= 1 << 19;
reg |= 1 << 21;
- ret = msi001_wreg(s, reg);
+ ret = msi001_wreg(dev, reg);
if (ret)
goto err;
reg = 2 << 0;
- reg |= frac << 4;
- reg |= n << 16;
- ret = msi001_wreg(s, reg);
+ reg |= k_frac << 4;
+ reg |= div_n << 16;
+ ret = msi001_wreg(dev, reg);
if (ret)
goto err;
- ret = msi001_set_gain(s, s->lna_gain->cur.val, s->mixer_gain->cur.val,
- s->if_gain->cur.val);
+ ret = msi001_set_gain(dev, dev->lna_gain->cur.val,
+ dev->mixer_gain->cur.val, dev->if_gain->cur.val);
if (ret)
goto err;
reg = 6 << 0;
reg |= 63 << 4;
reg |= 4095 << 10;
- ret = msi001_wreg(s, reg);
+ ret = msi001_wreg(dev, reg);
if (ret)
goto err;
return 0;
err:
- dev_dbg(&s->spi->dev, "failed %d\n", ret);
+ dev_dbg(&spi->dev, "failed %d\n", ret);
return ret;
-};
+}
static int msi001_s_power(struct v4l2_subdev *sd, int on)
{
- struct msi001 *s = sd_to_msi001(sd);
+ struct msi001_dev *dev = sd_to_msi001_dev(sd);
+ struct spi_device *spi = dev->spi;
int ret;
- dev_dbg(&s->spi->dev, "on=%d\n", on);
+ dev_dbg(&spi->dev, "on=%d\n", on);
if (on)
ret = 0;
else
- ret = msi001_wreg(s, 0x000000);
+ ret = msi001_wreg(dev, 0x000000);
return ret;
}
@@ -299,9 +313,10 @@ static const struct v4l2_subdev_core_ops msi001_core_ops = {
static int msi001_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
{
- struct msi001 *s = sd_to_msi001(sd);
+ struct msi001_dev *dev = sd_to_msi001_dev(sd);
+ struct spi_device *spi = dev->spi;
- dev_dbg(&s->spi->dev, "index=%d\n", v->index);
+ dev_dbg(&spi->dev, "index=%d\n", v->index);
strlcpy(v->name, "Mirics MSi001", sizeof(v->name));
v->type = V4L2_TUNER_RF;
@@ -314,47 +329,51 @@ static int msi001_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
static int msi001_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v)
{
- struct msi001 *s = sd_to_msi001(sd);
+ struct msi001_dev *dev = sd_to_msi001_dev(sd);
+ struct spi_device *spi = dev->spi;
- dev_dbg(&s->spi->dev, "index=%d\n", v->index);
+ dev_dbg(&spi->dev, "index=%d\n", v->index);
return 0;
}
static int msi001_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
{
- struct msi001 *s = sd_to_msi001(sd);
+ struct msi001_dev *dev = sd_to_msi001_dev(sd);
+ struct spi_device *spi = dev->spi;
- dev_dbg(&s->spi->dev, "tuner=%d\n", f->tuner);
- f->frequency = s->f_tuner;
+ dev_dbg(&spi->dev, "tuner=%d\n", f->tuner);
+ f->frequency = dev->f_tuner;
return 0;
}
static int msi001_s_frequency(struct v4l2_subdev *sd,
- const struct v4l2_frequency *f)
+ const struct v4l2_frequency *f)
{
- struct msi001 *s = sd_to_msi001(sd);
+ struct msi001_dev *dev = sd_to_msi001_dev(sd);
+ struct spi_device *spi = dev->spi;
unsigned int band;
- dev_dbg(&s->spi->dev, "tuner=%d type=%d frequency=%u\n",
- f->tuner, f->type, f->frequency);
+ dev_dbg(&spi->dev, "tuner=%d type=%d frequency=%u\n",
+ f->tuner, f->type, f->frequency);
if (f->frequency < ((bands[0].rangehigh + bands[1].rangelow) / 2))
band = 0;
else
band = 1;
- s->f_tuner = clamp_t(unsigned int, f->frequency,
- bands[band].rangelow, bands[band].rangehigh);
+ dev->f_tuner = clamp_t(unsigned int, f->frequency,
+ bands[band].rangelow, bands[band].rangehigh);
- return msi001_set_tuner(s);
+ return msi001_set_tuner(dev);
}
static int msi001_enum_freq_bands(struct v4l2_subdev *sd,
- struct v4l2_frequency_band *band)
+ struct v4l2_frequency_band *band)
{
- struct msi001 *s = sd_to_msi001(sd);
+ struct msi001_dev *dev = sd_to_msi001_dev(sd);
+ struct spi_device *spi = dev->spi;
- dev_dbg(&s->spi->dev, "tuner=%d type=%d index=%d\n",
- band->tuner, band->type, band->index);
+ dev_dbg(&spi->dev, "tuner=%d type=%d index=%d\n",
+ band->tuner, band->type, band->index);
if (band->index >= ARRAY_SIZE(bands))
return -EINVAL;
@@ -381,34 +400,37 @@ static const struct v4l2_subdev_ops msi001_ops = {
static int msi001_s_ctrl(struct v4l2_ctrl *ctrl)
{
- struct msi001 *s = container_of(ctrl->handler, struct msi001, hdl);
+ struct msi001_dev *dev = container_of(ctrl->handler, struct msi001_dev, hdl);
+ struct spi_device *spi = dev->spi;
int ret;
- dev_dbg(&s->spi->dev,
- "id=%d name=%s val=%d min=%lld max=%lld step=%lld\n",
- ctrl->id, ctrl->name, ctrl->val,
- ctrl->minimum, ctrl->maximum, ctrl->step);
+ dev_dbg(&spi->dev, "id=%d name=%s val=%d min=%lld max=%lld step=%lld\n",
+ ctrl->id, ctrl->name, ctrl->val, ctrl->minimum, ctrl->maximum,
+ ctrl->step);
switch (ctrl->id) {
case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
case V4L2_CID_RF_TUNER_BANDWIDTH:
- ret = msi001_set_tuner(s);
+ ret = msi001_set_tuner(dev);
break;
case V4L2_CID_RF_TUNER_LNA_GAIN:
- ret = msi001_set_gain(s, s->lna_gain->val,
- s->mixer_gain->cur.val, s->if_gain->cur.val);
+ ret = msi001_set_gain(dev, dev->lna_gain->val,
+ dev->mixer_gain->cur.val,
+ dev->if_gain->cur.val);
break;
case V4L2_CID_RF_TUNER_MIXER_GAIN:
- ret = msi001_set_gain(s, s->lna_gain->cur.val,
- s->mixer_gain->val, s->if_gain->cur.val);
+ ret = msi001_set_gain(dev, dev->lna_gain->cur.val,
+ dev->mixer_gain->val,
+ dev->if_gain->cur.val);
break;
case V4L2_CID_RF_TUNER_IF_GAIN:
- ret = msi001_set_gain(s, s->lna_gain->cur.val,
- s->mixer_gain->cur.val, s->if_gain->val);
+ ret = msi001_set_gain(dev, dev->lna_gain->cur.val,
+ dev->mixer_gain->cur.val,
+ dev->if_gain->val);
break;
default:
- dev_dbg(&s->spi->dev, "unknown control %d\n", ctrl->id);
+ dev_dbg(&spi->dev, "unknown control %d\n", ctrl->id);
ret = -EINVAL;
}
@@ -421,56 +443,54 @@ static const struct v4l2_ctrl_ops msi001_ctrl_ops = {
static int msi001_probe(struct spi_device *spi)
{
- struct msi001 *s;
+ struct msi001_dev *dev;
int ret;
dev_dbg(&spi->dev, "\n");
- s = kzalloc(sizeof(struct msi001), GFP_KERNEL);
- if (s == NULL) {
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev) {
ret = -ENOMEM;
- dev_dbg(&spi->dev, "Could not allocate memory for msi001\n");
- goto err_kfree;
+ goto err;
}
- s->spi = spi;
- s->f_tuner = bands[0].rangelow;
- v4l2_spi_subdev_init(&s->sd, spi, &msi001_ops);
+ dev->spi = spi;
+ dev->f_tuner = bands[0].rangelow;
+ v4l2_spi_subdev_init(&dev->sd, spi, &msi001_ops);
/* Register controls */
- v4l2_ctrl_handler_init(&s->hdl, 5);
- s->bandwidth_auto = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops,
+ v4l2_ctrl_handler_init(&dev->hdl, 5);
+ dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1);
- s->bandwidth = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops,
+ dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
V4L2_CID_RF_TUNER_BANDWIDTH, 200000, 8000000, 1, 200000);
- v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false);
- s->lna_gain = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops,
+ v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
+ dev->lna_gain = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
V4L2_CID_RF_TUNER_LNA_GAIN, 0, 1, 1, 1);
- s->mixer_gain = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops,
+ dev->mixer_gain = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1);
- s->if_gain = v4l2_ctrl_new_std(&s->hdl, &msi001_ctrl_ops,
+ dev->if_gain = v4l2_ctrl_new_std(&dev->hdl, &msi001_ctrl_ops,
V4L2_CID_RF_TUNER_IF_GAIN, 0, 59, 1, 0);
- if (s->hdl.error) {
- ret = s->hdl.error;
- dev_err(&s->spi->dev, "Could not initialize controls\n");
+ if (dev->hdl.error) {
+ ret = dev->hdl.error;
+ dev_err(&spi->dev, "Could not initialize controls\n");
/* control init failed, free handler */
goto err_ctrl_handler_free;
}
- s->sd.ctrl_handler = &s->hdl;
+ dev->sd.ctrl_handler = &dev->hdl;
return 0;
-
err_ctrl_handler_free:
- v4l2_ctrl_handler_free(&s->hdl);
-err_kfree:
- kfree(s);
+ v4l2_ctrl_handler_free(&dev->hdl);
+ kfree(dev);
+err:
return ret;
}
static int msi001_remove(struct spi_device *spi)
{
struct v4l2_subdev *sd = spi_get_drvdata(spi);
- struct msi001 *s = sd_to_msi001(sd);
+ struct msi001_dev *dev = sd_to_msi001_dev(sd);
dev_dbg(&spi->dev, "\n");
@@ -478,26 +498,26 @@ static int msi001_remove(struct spi_device *spi)
* Registered by v4l2_spi_new_subdev() from master driver, but we must
* unregister it from here. Weird.
*/
- v4l2_device_unregister_subdev(&s->sd);
- v4l2_ctrl_handler_free(&s->hdl);
- kfree(s);
+ v4l2_device_unregister_subdev(&dev->sd);
+ v4l2_ctrl_handler_free(&dev->hdl);
+ kfree(dev);
return 0;
}
-static const struct spi_device_id msi001_id[] = {
+static const struct spi_device_id msi001_id_table[] = {
{"msi001", 0},
{}
};
-MODULE_DEVICE_TABLE(spi, msi001_id);
+MODULE_DEVICE_TABLE(spi, msi001_id_table);
static struct spi_driver msi001_driver = {
.driver = {
.name = "msi001",
- .owner = THIS_MODULE,
+ .suppress_bind_attrs = true,
},
.probe = msi001_probe,
.remove = msi001_remove,
- .id_table = msi001_id,
+ .id_table = msi001_id_table,
};
module_spi_driver(msi001_driver);
diff --git a/kernel/drivers/media/tuners/qt1010.c b/kernel/drivers/media/tuners/qt1010.c
index bc419f8a9..ae8cbece6 100644
--- a/kernel/drivers/media/tuners/qt1010.c
+++ b/kernel/drivers/media/tuners/qt1010.c
@@ -294,7 +294,7 @@ static int qt1010_init(struct dvb_frontend *fe)
int err = 0;
u8 i, tmpval, *valptr = NULL;
- qt1010_i2c_oper_t i2c_data[] = {
+ static const qt1010_i2c_oper_t i2c_data[] = {
{ QT1010_WR, 0x01, 0x80 },
{ QT1010_WR, 0x0d, 0x84 },
{ QT1010_WR, 0x0e, 0xb7 },
@@ -354,13 +354,17 @@ static int qt1010_init(struct dvb_frontend *fe)
valptr = &priv->reg1f_init_val;
else
valptr = &tmpval;
+
+ BUG_ON(i >= ARRAY_SIZE(i2c_data) - 1);
+
err = qt1010_init_meas1(priv, i2c_data[i+1].reg,
i2c_data[i].reg,
i2c_data[i].val, valptr);
i++;
break;
}
- if (err) return err;
+ if (err)
+ return err;
}
for (i = 0x31; i < 0x3a; i++) /* 0x31 - 0x39 */
diff --git a/kernel/drivers/media/tuners/r820t.c b/kernel/drivers/media/tuners/r820t.c
index 71159a588..a7a8452e9 100644
--- a/kernel/drivers/media/tuners/r820t.c
+++ b/kernel/drivers/media/tuners/r820t.c
@@ -941,8 +941,8 @@ static int r820t_sysfreq_sel(struct r820t_priv *priv, u32 freq,
rc = r820t_write_reg_mask(priv, 0x10, 0x00, 0x04);
if (rc < 0)
return rc;
- }
- return 0;
+ }
+ return 0;
}
static int r820t_set_tv_standard(struct r820t_priv *priv,
diff --git a/kernel/drivers/media/tuners/si2157.c b/kernel/drivers/media/tuners/si2157.c
index d74ae2662..0e1ca2b00 100644
--- a/kernel/drivers/media/tuners/si2157.c
+++ b/kernel/drivers/media/tuners/si2157.c
@@ -79,6 +79,7 @@ static int si2157_init(struct dvb_frontend *fe)
{
struct i2c_client *client = fe->tuner_priv;
struct si2157_dev *dev = i2c_get_clientdata(client);
+ struct dtv_frontend_properties *c = &fe->dtv_property_cache;
int ret, len, remaining;
struct si2157_cmd cmd;
const struct firmware *fw;
@@ -165,6 +166,11 @@ static int si2157_init(struct dvb_frontend *fe)
for (remaining = fw->size; remaining > 0; remaining -= 17) {
len = fw->data[fw->size - remaining];
+ if (len > SI2157_ARGLEN) {
+ dev_err(&client->dev, "Bad firmware length\n");
+ ret = -EINVAL;
+ goto err_release_firmware;
+ }
memcpy(cmd.args, &fw->data[(fw->size - remaining) + 1], len);
cmd.wlen = len;
cmd.rlen = 1;
@@ -201,9 +207,14 @@ skip_fw_download:
dev->fw_loaded = true;
warm:
+ /* init statistics in order signal app which are supported */
+ c->strength.len = 1;
+ c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+ /* start statistics polling */
+ schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(1000));
+
dev->active = true;
return 0;
-
err_release_firmware:
release_firmware(fw);
err:
@@ -222,6 +233,9 @@ static int si2157_sleep(struct dvb_frontend *fe)
dev->active = false;
+ /* stop statistics polling */
+ cancel_delayed_work_sync(&dev->stat_work);
+
/* standby */
memcpy(cmd.args, "\x16\x00", 2);
cmd.wlen = 2;
@@ -298,7 +312,8 @@ static int si2157_set_params(struct dvb_frontend *fe)
if (dev->chiptype == SI2157_CHIPTYPE_SI2146)
memcpy(cmd.args, "\x14\x00\x02\x07\x00\x01", 6);
else
- memcpy(cmd.args, "\x14\x00\x02\x07\x01\x00", 6);
+ memcpy(cmd.args, "\x14\x00\x02\x07\x00\x00", 6);
+ cmd.args[4] = dev->if_port;
cmd.wlen = 6;
cmd.rlen = 4;
ret = si2157_cmd_execute(client, &cmd);
@@ -359,6 +374,34 @@ static const struct dvb_tuner_ops si2157_ops = {
.get_if_frequency = si2157_get_if_frequency,
};
+static void si2157_stat_work(struct work_struct *work)
+{
+ struct si2157_dev *dev = container_of(work, struct si2157_dev, stat_work.work);
+ struct dvb_frontend *fe = dev->fe;
+ struct i2c_client *client = fe->tuner_priv;
+ struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+ struct si2157_cmd cmd;
+ int ret;
+
+ dev_dbg(&client->dev, "\n");
+
+ memcpy(cmd.args, "\x42\x00", 2);
+ cmd.wlen = 2;
+ cmd.rlen = 12;
+ ret = si2157_cmd_execute(client, &cmd);
+ if (ret)
+ goto err;
+
+ c->strength.stat[0].scale = FE_SCALE_DECIBEL;
+ c->strength.stat[0].svalue = (s8) cmd.args[3] * 1000;
+
+ schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(2000));
+ return;
+err:
+ c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+ dev_dbg(&client->dev, "failed=%d\n", ret);
+}
+
static int si2157_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -378,10 +421,12 @@ static int si2157_probe(struct i2c_client *client,
i2c_set_clientdata(client, dev);
dev->fe = cfg->fe;
dev->inversion = cfg->inversion;
+ dev->if_port = cfg->if_port;
dev->fw_loaded = false;
dev->chiptype = (u8)id->driver_data;
dev->if_frequency = 5000000; /* default value of property 0x0706 */
mutex_init(&dev->i2c_mutex);
+ INIT_DELAYED_WORK(&dev->stat_work, si2157_stat_work);
/* check if the tuner is there */
cmd.wlen = 0;
@@ -429,7 +474,6 @@ MODULE_DEVICE_TABLE(i2c, si2157_id_table);
static struct i2c_driver si2157_driver = {
.driver = {
- .owner = THIS_MODULE,
.name = "si2157",
},
.probe = si2157_probe,
diff --git a/kernel/drivers/media/tuners/si2157.h b/kernel/drivers/media/tuners/si2157.h
index a564c4a9f..4db97ab74 100644
--- a/kernel/drivers/media/tuners/si2157.h
+++ b/kernel/drivers/media/tuners/si2157.h
@@ -34,6 +34,12 @@ struct si2157_config {
* Spectral Inversion
*/
bool inversion;
+
+ /*
+ * Port selection
+ * Select the RF interface to use (pins 9+11 or 12+13)
+ */
+ u8 if_port;
};
#endif
diff --git a/kernel/drivers/media/tuners/si2157_priv.h b/kernel/drivers/media/tuners/si2157_priv.h
index cd8fa5b25..ecc463db8 100644
--- a/kernel/drivers/media/tuners/si2157_priv.h
+++ b/kernel/drivers/media/tuners/si2157_priv.h
@@ -28,7 +28,9 @@ struct si2157_dev {
bool fw_loaded;
bool inversion;
u8 chiptype;
+ u8 if_port;
u32 if_frequency;
+ struct delayed_work stat_work;
};
#define SI2157_CHIPTYPE_SI2157 0
diff --git a/kernel/drivers/media/tuners/tda18212.c b/kernel/drivers/media/tuners/tda18212.c
index d93e0667b..7b8068354 100644
--- a/kernel/drivers/media/tuners/tda18212.c
+++ b/kernel/drivers/media/tuners/tda18212.c
@@ -277,7 +277,6 @@ MODULE_DEVICE_TABLE(i2c, tda18212_id);
static struct i2c_driver tda18212_driver = {
.driver = {
- .owner = THIS_MODULE,
.name = "tda18212",
},
.probe = tda18212_probe,
diff --git a/kernel/drivers/media/tuners/tua9001.c b/kernel/drivers/media/tuners/tua9001.c
index 83a6240f6..9d70378fe 100644
--- a/kernel/drivers/media/tuners/tua9001.c
+++ b/kernel/drivers/media/tuners/tua9001.c
@@ -1,5 +1,5 @@
/*
- * Infineon TUA 9001 silicon tuner driver
+ * Infineon TUA9001 silicon tuner driver
*
* Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
*
@@ -12,138 +12,87 @@
* 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.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "tua9001.h"
#include "tua9001_priv.h"
-/* write register */
-static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, u16 val)
-{
- int ret;
- u8 buf[3] = { reg, (val >> 8) & 0xff, (val >> 0) & 0xff };
- struct i2c_msg msg[1] = {
- {
- .addr = priv->cfg->i2c_addr,
- .flags = 0,
- .len = sizeof(buf),
- .buf = buf,
- }
- };
-
- ret = i2c_transfer(priv->i2c, msg, 1);
- if (ret == 1) {
- ret = 0;
- } else {
- dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x\n",
- KBUILD_MODNAME, ret, reg);
- ret = -EREMOTEIO;
- }
-
- return ret;
-}
-
-static int tua9001_release(struct dvb_frontend *fe)
-{
- struct tua9001_priv *priv = fe->tuner_priv;
- int ret = 0;
-
- dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
-
- if (fe->callback)
- ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
- TUA9001_CMD_CEN, 0);
-
- kfree(fe->tuner_priv);
- fe->tuner_priv = NULL;
-
- return ret;
-}
-
static int tua9001_init(struct dvb_frontend *fe)
{
- struct tua9001_priv *priv = fe->tuner_priv;
- int ret = 0;
- u8 i;
- struct reg_val data[] = {
- { 0x1e, 0x6512 },
- { 0x25, 0xb888 },
- { 0x39, 0x5460 },
- { 0x3b, 0x00c0 },
- { 0x3a, 0xf000 },
- { 0x08, 0x0000 },
- { 0x32, 0x0030 },
- { 0x41, 0x703a },
- { 0x40, 0x1c78 },
- { 0x2c, 0x1c00 },
- { 0x36, 0xc013 },
- { 0x37, 0x6f18 },
- { 0x27, 0x0008 },
- { 0x2a, 0x0001 },
- { 0x34, 0x0a40 },
+ struct tua9001_dev *dev = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
+ int ret, i;
+ static const struct tua9001_reg_val data[] = {
+ {0x1e, 0x6512},
+ {0x25, 0xb888},
+ {0x39, 0x5460},
+ {0x3b, 0x00c0},
+ {0x3a, 0xf000},
+ {0x08, 0x0000},
+ {0x32, 0x0030},
+ {0x41, 0x703a},
+ {0x40, 0x1c78},
+ {0x2c, 0x1c00},
+ {0x36, 0xc013},
+ {0x37, 0x6f18},
+ {0x27, 0x0008},
+ {0x2a, 0x0001},
+ {0x34, 0x0a40},
};
- dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
+ dev_dbg(&client->dev, "\n");
if (fe->callback) {
- ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
- TUA9001_CMD_RESETN, 0);
- if (ret < 0)
+ ret = fe->callback(client->adapter,
+ DVB_FRONTEND_COMPONENT_TUNER,
+ TUA9001_CMD_RESETN, 0);
+ if (ret)
goto err;
}
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */
-
for (i = 0; i < ARRAY_SIZE(data); i++) {
- ret = tua9001_wr_reg(priv, data[i].reg, data[i].val);
- if (ret < 0)
- goto err_i2c_gate_ctrl;
+ ret = regmap_write(dev->regmap, data[i].reg, data[i].val);
+ if (ret)
+ goto err;
}
-
-err_i2c_gate_ctrl:
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */
+ return 0;
err:
- if (ret < 0)
- dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
-
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int tua9001_sleep(struct dvb_frontend *fe)
{
- struct tua9001_priv *priv = fe->tuner_priv;
- int ret = 0;
-
- dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
-
- if (fe->callback)
- ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
- TUA9001_CMD_RESETN, 1);
+ struct tua9001_dev *dev = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
+ int ret;
- if (ret < 0)
- dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
+ dev_dbg(&client->dev, "\n");
+ if (fe->callback) {
+ ret = fe->callback(client->adapter,
+ DVB_FRONTEND_COMPONENT_TUNER,
+ TUA9001_CMD_RESETN, 1);
+ if (ret)
+ goto err;
+ }
+ return 0;
+err:
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int tua9001_set_params(struct dvb_frontend *fe)
{
- struct tua9001_priv *priv = fe->tuner_priv;
+ struct tua9001_dev *dev = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
- int ret = 0, i;
+ int ret, i;
u16 val;
- u32 frequency;
- struct reg_val data[2];
+ struct tua9001_reg_val data[2];
- dev_dbg(&priv->i2c->dev, "%s: delivery_system=%d frequency=%d " \
- "bandwidth_hz=%d\n", __func__,
- c->delivery_system, c->frequency, c->bandwidth_hz);
+ dev_dbg(&client->dev,
+ "delivery_system=%u frequency=%u bandwidth_hz=%u\n",
+ c->delivery_system, c->frequency, c->bandwidth_hz);
switch (c->delivery_system) {
case SYS_DVBT:
@@ -172,70 +121,54 @@ static int tua9001_set_params(struct dvb_frontend *fe)
data[0].reg = 0x04;
data[0].val = val;
-
- frequency = (c->frequency - 150000000);
- frequency /= 100;
- frequency *= 48;
- frequency /= 10000;
-
data[1].reg = 0x1f;
- data[1].val = frequency;
-
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */
+ data[1].val = div_u64((u64) (c->frequency - 150000000) * 48, 1000000);
if (fe->callback) {
- ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
- TUA9001_CMD_RXEN, 0);
- if (ret < 0)
- goto err_i2c_gate_ctrl;
+ ret = fe->callback(client->adapter,
+ DVB_FRONTEND_COMPONENT_TUNER,
+ TUA9001_CMD_RXEN, 0);
+ if (ret)
+ goto err;
}
for (i = 0; i < ARRAY_SIZE(data); i++) {
- ret = tua9001_wr_reg(priv, data[i].reg, data[i].val);
- if (ret < 0)
- goto err_i2c_gate_ctrl;
+ ret = regmap_write(dev->regmap, data[i].reg, data[i].val);
+ if (ret)
+ goto err;
}
if (fe->callback) {
- ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
- TUA9001_CMD_RXEN, 1);
- if (ret < 0)
- goto err_i2c_gate_ctrl;
+ ret = fe->callback(client->adapter,
+ DVB_FRONTEND_COMPONENT_TUNER,
+ TUA9001_CMD_RXEN, 1);
+ if (ret)
+ goto err;
}
-
-err_i2c_gate_ctrl:
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */
+ return 0;
err:
- if (ret < 0)
- dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
-
+ dev_dbg(&client->dev, "failed=%d\n", ret);
return ret;
}
static int tua9001_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
{
- struct tua9001_priv *priv = fe->tuner_priv;
+ struct tua9001_dev *dev = fe->tuner_priv;
+ struct i2c_client *client = dev->client;
- dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
+ dev_dbg(&client->dev, "\n");
*frequency = 0; /* Zero-IF */
-
return 0;
}
static const struct dvb_tuner_ops tua9001_tuner_ops = {
.info = {
- .name = "Infineon TUA 9001",
-
+ .name = "Infineon TUA9001",
.frequency_min = 170000000,
.frequency_max = 862000000,
- .frequency_step = 0,
},
- .release = tua9001_release,
-
.init = tua9001_init,
.sleep = tua9001_sleep,
.set_params = tua9001_set_params,
@@ -243,52 +176,107 @@ static const struct dvb_tuner_ops tua9001_tuner_ops = {
.get_if_frequency = tua9001_get_if_frequency,
};
-struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
- struct i2c_adapter *i2c, struct tua9001_config *cfg)
+static int tua9001_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
{
- struct tua9001_priv *priv = NULL;
+ struct tua9001_dev *dev;
+ struct tua9001_platform_data *pdata = client->dev.platform_data;
+ struct dvb_frontend *fe = pdata->dvb_frontend;
int ret;
+ static const struct regmap_config regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 16,
+ };
- priv = kzalloc(sizeof(struct tua9001_priv), GFP_KERNEL);
- if (priv == NULL)
- return NULL;
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev) {
+ ret = -ENOMEM;
+ goto err;
+ }
- priv->cfg = cfg;
- priv->i2c = i2c;
+ dev->fe = pdata->dvb_frontend;
+ dev->client = client;
+ dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
+ if (IS_ERR(dev->regmap)) {
+ ret = PTR_ERR(dev->regmap);
+ goto err_kfree;
+ }
if (fe->callback) {
- ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
- TUA9001_CMD_CEN, 1);
- if (ret < 0)
- goto err;
-
- ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
- TUA9001_CMD_RXEN, 0);
- if (ret < 0)
- goto err;
-
- ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
- TUA9001_CMD_RESETN, 1);
- if (ret < 0)
- goto err;
+ ret = fe->callback(client->adapter,
+ DVB_FRONTEND_COMPONENT_TUNER,
+ TUA9001_CMD_CEN, 1);
+ if (ret)
+ goto err_kfree;
+
+ ret = fe->callback(client->adapter,
+ DVB_FRONTEND_COMPONENT_TUNER,
+ TUA9001_CMD_RXEN, 0);
+ if (ret)
+ goto err_kfree;
+
+ ret = fe->callback(client->adapter,
+ DVB_FRONTEND_COMPONENT_TUNER,
+ TUA9001_CMD_RESETN, 1);
+ if (ret)
+ goto err_kfree;
}
- dev_info(&priv->i2c->dev,
- "%s: Infineon TUA 9001 successfully attached\n",
- KBUILD_MODNAME);
-
+ fe->tuner_priv = dev;
memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops,
sizeof(struct dvb_tuner_ops));
+ i2c_set_clientdata(client, dev);
- fe->tuner_priv = priv;
- return fe;
+ dev_info(&client->dev, "Infineon TUA9001 successfully attached\n");
+ return 0;
+err_kfree:
+ kfree(dev);
err:
- dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret);
- kfree(priv);
- return NULL;
+ dev_dbg(&client->dev, "failed=%d\n", ret);
+ return ret;
+}
+
+static int tua9001_remove(struct i2c_client *client)
+{
+ struct tua9001_dev *dev = i2c_get_clientdata(client);
+ struct dvb_frontend *fe = dev->fe;
+ int ret;
+
+ dev_dbg(&client->dev, "\n");
+
+ if (fe->callback) {
+ ret = fe->callback(client->adapter,
+ DVB_FRONTEND_COMPONENT_TUNER,
+ TUA9001_CMD_CEN, 0);
+ if (ret)
+ goto err_kfree;
+ }
+ kfree(dev);
+ return 0;
+err_kfree:
+ kfree(dev);
+ dev_dbg(&client->dev, "failed=%d\n", ret);
+ return ret;
}
-EXPORT_SYMBOL(tua9001_attach);
-MODULE_DESCRIPTION("Infineon TUA 9001 silicon tuner driver");
+static const struct i2c_device_id tua9001_id_table[] = {
+ {"tua9001", 0},
+ {}
+};
+MODULE_DEVICE_TABLE(i2c, tua9001_id_table);
+
+static struct i2c_driver tua9001_driver = {
+ .driver = {
+ .name = "tua9001",
+ .suppress_bind_attrs = true,
+ },
+ .probe = tua9001_probe,
+ .remove = tua9001_remove,
+ .id_table = tua9001_id_table,
+};
+
+module_i2c_driver(tua9001_driver);
+
+MODULE_DESCRIPTION("Infineon TUA9001 silicon tuner driver");
MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
MODULE_LICENSE("GPL");
diff --git a/kernel/drivers/media/tuners/tua9001.h b/kernel/drivers/media/tuners/tua9001.h
index 2c3375c7a..7b0548181 100644
--- a/kernel/drivers/media/tuners/tua9001.h
+++ b/kernel/drivers/media/tuners/tua9001.h
@@ -1,5 +1,5 @@
/*
- * Infineon TUA 9001 silicon tuner driver
+ * Infineon TUA9001 silicon tuner driver
*
* Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
*
@@ -12,23 +12,24 @@
* 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.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef TUA9001_H
#define TUA9001_H
-#include <linux/kconfig.h>
#include "dvb_frontend.h"
-struct tua9001_config {
- /*
- * I2C address
- */
- u8 i2c_addr;
+/*
+ * I2C address
+ * 0x60,
+ */
+
+/**
+ * struct tua9001_platform_data - Platform data for the tua9001 driver
+ * @dvb_frontend: DVB frontend.
+ */
+struct tua9001_platform_data {
+ struct dvb_frontend *dvb_frontend;
};
/*
@@ -51,16 +52,4 @@ struct tua9001_config {
#define TUA9001_CMD_RESETN 1
#define TUA9001_CMD_RXEN 2
-#if IS_REACHABLE(CONFIG_MEDIA_TUNER_TUA9001)
-extern struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
- struct i2c_adapter *i2c, struct tua9001_config *cfg);
-#else
-static inline struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe,
- struct i2c_adapter *i2c, struct tua9001_config *cfg)
-{
- printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
- return NULL;
-}
-#endif
-
#endif
diff --git a/kernel/drivers/media/tuners/tua9001_priv.h b/kernel/drivers/media/tuners/tua9001_priv.h
index 73cc1ce05..bc406c5ec 100644
--- a/kernel/drivers/media/tuners/tua9001_priv.h
+++ b/kernel/drivers/media/tuners/tua9001_priv.h
@@ -1,5 +1,5 @@
/*
- * Infineon TUA 9001 silicon tuner driver
+ * Infineon TUA9001 silicon tuner driver
*
* Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
*
@@ -12,23 +12,24 @@
* 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.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef TUA9001_PRIV_H
#define TUA9001_PRIV_H
-struct reg_val {
+#include "tua9001.h"
+#include <linux/math64.h>
+#include <linux/regmap.h>
+
+struct tua9001_reg_val {
u8 reg;
u16 val;
};
-struct tua9001_priv {
- struct tua9001_config *cfg;
- struct i2c_adapter *i2c;
+struct tua9001_dev {
+ struct dvb_frontend *fe;
+ struct i2c_client *client;
+ struct regmap *regmap;
};
#endif
diff --git a/kernel/drivers/media/tuners/tuner-i2c.h b/kernel/drivers/media/tuners/tuner-i2c.h
index 18f005634..bda67a5a7 100644
--- a/kernel/drivers/media/tuners/tuner-i2c.h
+++ b/kernel/drivers/media/tuners/tuner-i2c.h
@@ -33,7 +33,8 @@ struct tuner_i2c_props {
char *name;
};
-static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len)
+static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props,
+ unsigned char *buf, int len)
{
struct i2c_msg msg = { .addr = props->addr, .flags = 0,
.buf = buf, .len = len };
@@ -42,7 +43,8 @@ static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf,
return (ret == 1) ? len : ret;
}
-static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf, int len)
+static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props,
+ unsigned char *buf, int len)
{
struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD,
.buf = buf, .len = len };
@@ -52,8 +54,8 @@ static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf,
}
static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
- char *obuf, int olen,
- char *ibuf, int ilen)
+ unsigned char *obuf, int olen,
+ unsigned char *ibuf, int ilen)
{
struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0,
.buf = obuf, .len = olen },
diff --git a/kernel/drivers/media/tuners/tuner-xc2028.c b/kernel/drivers/media/tuners/tuner-xc2028.c
index d12f5e4ad..4e941f00b 100644
--- a/kernel/drivers/media/tuners/tuner-xc2028.c
+++ b/kernel/drivers/media/tuners/tuner-xc2028.c
@@ -1094,7 +1094,7 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
* Still need tests for XC3028L (firmware 3.2 or upper)
* So, for now, let's just comment the per-firmware
* version of this change. Reports with xc3028l working
- * with and without the lines bellow are welcome
+ * with and without the lines below are welcome
*/
if (priv->firm_version < 0x0302) {