All of lore.kernel.org
 help / color / mirror / Atom feed
From: tskd08@gmail.com
To: linux-media@vger.kernel.org
Cc: m.chehab@samsung.com, Akihiro Tsukada <tskd08@gmail.com>
Subject: [PATCH 1/5] dvb: qm1d1c0042: use dvb-core i2c binding model template
Date: Fri,  5 Dec 2014 19:55:36 +0900	[thread overview]
Message-ID: <1417776940-16381-2-git-send-email-tskd08@gmail.com> (raw)
In-Reply-To: <1417776940-16381-1-git-send-email-tskd08@gmail.com>
In-Reply-To: <1417776573-16182-1-git-send-email-tskd08@gmail.com>

From: Akihiro Tsukada <tskd08@gmail.com>

Signed-off-by: Akihiro Tsukada <tskd08@gmail.com>
---
 drivers/media/tuners/qm1d1c0042.c | 61 +++++++++++++--------------------------
 drivers/media/tuners/qm1d1c0042.h |  2 --
 2 files changed, 20 insertions(+), 43 deletions(-)

diff --git a/drivers/media/tuners/qm1d1c0042.c b/drivers/media/tuners/qm1d1c0042.c
index 18bc745..f1f4bec 100644
--- a/drivers/media/tuners/qm1d1c0042.c
+++ b/drivers/media/tuners/qm1d1c0042.c
@@ -29,6 +29,7 @@
 
 #include <linux/kernel.h>
 #include <linux/math64.h>
+#include "dvb_i2c.h"
 #include "qm1d1c0042.h"
 
 #define QM1D1C0042_NUM_REGS 0x20
@@ -55,11 +56,6 @@ struct qm1d1c0042_state {
 	u8 regs[QM1D1C0042_NUM_REGS];
 };
 
-static struct qm1d1c0042_state *cfg_to_state(struct qm1d1c0042_config *c)
-{
-	return container_of(c, struct qm1d1c0042_state, cfg);
-}
-
 static int reg_write(struct qm1d1c0042_state *state, u8 reg, u8 val)
 {
 	u8 wbuf[2] = { reg, val };
@@ -106,10 +102,12 @@ static int qm1d1c0042_set_srch_mode(struct qm1d1c0042_state *state, bool fast)
 	return reg_write(state, 0x03, state->regs[0x03]);
 }
 
-static int qm1d1c0042_wakeup(struct qm1d1c0042_state *state)
+static int qm1d1c0042_wakeup(struct dvb_frontend *fe)
 {
+	struct qm1d1c0042_state *state;
 	int ret;
 
+	state = fe->tuner_priv;
 	state->regs[0x01] |= 1 << 3;             /* BB_Reg_enable */
 	state->regs[0x01] &= (~(1 << 0)) & 0xff; /* NORMAL (wake-up) */
 	state->regs[0x05] &= (~(1 << 3)) & 0xff; /* pfd_rst NORMAL */
@@ -119,7 +117,7 @@ static int qm1d1c0042_wakeup(struct qm1d1c0042_state *state)
 
 	if (ret < 0)
 		dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n",
-			__func__, state->cfg.fe->dvb->num, state->cfg.fe->id);
+			__func__, fe->dvb->num, fe->id);
 	return ret;
 }
 
@@ -133,9 +131,6 @@ static int qm1d1c0042_set_config(struct dvb_frontend *fe, void *priv_cfg)
 	state = fe->tuner_priv;
 	cfg = priv_cfg;
 
-	if (cfg->fe)
-		state->cfg.fe = cfg->fe;
-
 	if (cfg->xtal_freq != QM1D1C0042_CFG_XTAL_DFLT)
 		dev_warn(&state->i2c->dev,
 			"(%s) changing xtal_freq not supported. ", __func__);
@@ -359,7 +354,7 @@ static int qm1d1c0042_init(struct dvb_frontend *fe)
 			goto failed;
 	}
 
-	ret = qm1d1c0042_wakeup(state);
+	ret = qm1d1c0042_wakeup(fe);
 	if (ret < 0)
 		goto failed;
 
@@ -395,53 +390,37 @@ static const struct dvb_tuner_ops qm1d1c0042_ops = {
 static int qm1d1c0042_probe(struct i2c_client *client,
 			    const struct i2c_device_id *id)
 {
-	struct qm1d1c0042_state *state;
-	struct qm1d1c0042_config *cfg;
+	struct dvb_i2c_tuner_config *tcfg;
 	struct dvb_frontend *fe;
+	struct qm1d1c0042_state *state;
 
-	state = kzalloc(sizeof(*state), GFP_KERNEL);
-	if (!state)
-		return -ENOMEM;
+dev_info(&client->dev, "qm1d1c0042_probe().\n");
+	tcfg = client->dev.platform_data;
+	fe = tcfg->fe;
+	state = fe->tuner_priv;
 	state->i2c = client;
 
-	cfg = client->dev.platform_data;
-	fe = cfg->fe;
-	fe->tuner_priv = state;
-	qm1d1c0042_set_config(fe, cfg);
-	memcpy(&fe->ops.tuner_ops, &qm1d1c0042_ops, sizeof(qm1d1c0042_ops));
+	qm1d1c0042_set_config(fe, (void *)tcfg->devcfg.priv_cfg);
 
-	i2c_set_clientdata(client, &state->cfg);
 	dev_info(&client->dev, "Sharp QM1D1C0042 attached.\n");
 	return 0;
 }
 
-static int qm1d1c0042_remove(struct i2c_client *client)
-{
-	struct qm1d1c0042_state *state;
-
-	state = cfg_to_state(i2c_get_clientdata(client));
-	state->cfg.fe->tuner_priv = NULL;
-	kfree(state);
-	return 0;
-}
-
 
 static const struct i2c_device_id qm1d1c0042_id[] = {
 	{"qm1d1c0042", 0},
 	{}
 };
-MODULE_DEVICE_TABLE(i2c, qm1d1c0042_id);
 
-static struct i2c_driver qm1d1c0042_driver = {
-	.driver = {
-		.name	= "qm1d1c0042",
-	},
-	.probe		= qm1d1c0042_probe,
-	.remove		= qm1d1c0042_remove,
-	.id_table	= qm1d1c0042_id,
+static const struct dvb_i2c_module_param qm1d1c0042_param = {
+	.ops.tuner_ops = &qm1d1c0042_ops,
+	.priv_probe = qm1d1c0042_probe,
+
+	.priv_size = sizeof(struct qm1d1c0042_state),
+	.is_tuner = true,
 };
 
-module_i2c_driver(qm1d1c0042_driver);
+DEFINE_DVB_I2C_MODULE(qm1d1c0042, qm1d1c0042_id, qm1d1c0042_param);
 
 MODULE_DESCRIPTION("Sharp QM1D1C0042 tuner");
 MODULE_AUTHOR("Akihiro TSUKADA");
diff --git a/drivers/media/tuners/qm1d1c0042.h b/drivers/media/tuners/qm1d1c0042.h
index 4f5c188..043787e 100644
--- a/drivers/media/tuners/qm1d1c0042.h
+++ b/drivers/media/tuners/qm1d1c0042.h
@@ -21,8 +21,6 @@
 
 
 struct qm1d1c0042_config {
-	struct dvb_frontend *fe;
-
 	u32  xtal_freq;    /* [kHz] */ /* currently ignored */
 	bool lpf;          /* enable LPF */
 	bool fast_srch;    /* enable fast search mode, no LPF */
-- 
2.1.3


  parent reply	other threads:[~2014-12-05 10:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-05 10:49 [RFC/PATCH] dvb-core: add template code for i2c binding model tskd08
2014-12-05 10:55 ` [PATCH 0/5] ports to dvb-core i2c template code tskd08
2014-12-05 10:55 ` tskd08 [this message]
2014-12-05 10:55 ` [PATCH 2/5] dvb: mxl301rf: use dvb-core i2c binding model template tskd08
2014-12-05 10:55 ` [PATCH 3/5] dvb: tc90522: " tskd08
2014-12-05 10:55 ` [PATCH 4/5] dvb: tc90522: remove a redundant state variable tskd08
2014-12-05 10:55 ` [PATCH 5/5] dvb: pci/pt3: use dvb-core i2c binding model template tskd08
2014-12-26 11:00 ` [RFC/PATCH] dvb-core: add template code for i2c binding model Akihiro TSUKADA
2014-12-30 13:10 ` Mauro Carvalho Chehab
2014-12-30 20:01   ` Mauro Carvalho Chehab
2015-01-05 12:14     ` Akihiro TSUKADA
2015-01-05 12:24       ` Mauro Carvalho Chehab
2015-01-05 11:59   ` Akihiro TSUKADA
2015-01-13 18:54 ` Antti Palosaari
2015-01-15 11:20   ` Akihiro TSUKADA

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417776940-16381-2-git-send-email-tskd08@gmail.com \
    --to=tskd08@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.