All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Scheller <d.scheller.oss@gmail.com>
To: linux-media@vger.kernel.org, mchehab@kernel.org,
	mchehab@s-opensource.com
Cc: jasmin@anw.at
Subject: [PATCH v2 4/7] [media] ngene: adapt cxd2099 attach to the new i2c_client way
Date: Sat, 17 Feb 2018 16:03:25 +0100	[thread overview]
Message-ID: <20180217150328.686-5-d.scheller.oss@gmail.com> (raw)
In-Reply-To: <20180217150328.686-1-d.scheller.oss@gmail.com>

From: Daniel Scheller <d.scheller@gmx.net>

Change the way the cxd2099 hardware is being attached to the new I2C
client interface way. Also, add I2C_FUNC_I2C to the I2C interface
functionality.

Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
Signed-off-by: Jasmin Jessich <jasmin@anw.at>
---
 drivers/media/pci/ngene/ngene-core.c | 41 ++++++++++++++++++++++++++++++++----
 drivers/media/pci/ngene/ngene-i2c.c  |  2 +-
 drivers/media/pci/ngene/ngene.h      |  1 +
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index 8c92cb7f7e72..80db777cb7ec 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -1562,9 +1562,8 @@ static int init_channels(struct ngene *dev)
 	return 0;
 }
 
-static struct cxd2099_cfg cxd_cfg = {
+static const struct cxd2099_cfg cxd_cfgtmpl = {
 	.bitrate = 62000,
-	.adr = 0x40,
 	.polarity = 0,
 	.clock_mode = 0,
 };
@@ -1572,18 +1571,52 @@ static struct cxd2099_cfg cxd_cfg = {
 static void cxd_attach(struct ngene *dev)
 {
 	struct ngene_ci *ci = &dev->ci;
+	struct cxd2099_cfg cxd_cfg = cxd_cfgtmpl;
+	struct i2c_client *client;
+	struct i2c_board_info board_info = {
+		.type = "cxd2099",
+		.addr = 0x40,
+		.platform_data = &cxd_cfg,
+	};
+
+	cxd_cfg.en = &ci->en;
+
+	request_module(board_info.type);
+
+	client = i2c_new_device(&dev->channel[0].i2c_adapter, &board_info);
+	if (!client || !client->dev.driver)
+		goto err_ret;
+
+	if (!try_module_get(client->dev.driver->owner))
+		goto err_i2c;
+
+	if (!ci->en)
+		goto err_i2c;
 
-	ci->en = cxd2099_attach(&cxd_cfg, dev, &dev->channel[0].i2c_adapter);
 	ci->dev = dev;
+	dev->channel[0].i2c_client[0] = client;
+	return;
+
+err_i2c:
+	i2c_unregister_device(client);
+err_ret:
+	printk(KERN_ERR DEVICE_NAME ": CXD2099AR attach failed\n");
 	return;
 }
 
 static void cxd_detach(struct ngene *dev)
 {
 	struct ngene_ci *ci = &dev->ci;
+	struct i2c_client *client;
 
 	dvb_ca_en50221_release(ci->en);
-	kfree(ci->en);
+
+	client = dev->channel[0].i2c_client[0];
+	if (client) {
+		module_put(client->dev.driver->owner);
+		i2c_unregister_device(client);
+	}
+
 	ci->en = NULL;
 }
 
diff --git a/drivers/media/pci/ngene/ngene-i2c.c b/drivers/media/pci/ngene/ngene-i2c.c
index 3004947f300b..092d46c2a3a9 100644
--- a/drivers/media/pci/ngene/ngene-i2c.c
+++ b/drivers/media/pci/ngene/ngene-i2c.c
@@ -147,7 +147,7 @@ static int ngene_i2c_master_xfer(struct i2c_adapter *adapter,
 
 static u32 ngene_i2c_functionality(struct i2c_adapter *adap)
 {
-	return I2C_FUNC_SMBUS_EMUL;
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
 }
 
 static const struct i2c_algorithm ngene_i2c_algo = {
diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h
index 02dbd18f92d0..caf8602c7459 100644
--- a/drivers/media/pci/ngene/ngene.h
+++ b/drivers/media/pci/ngene/ngene.h
@@ -630,6 +630,7 @@ struct ngene_vopen {
 struct ngene_channel {
 	struct device         device;
 	struct i2c_adapter    i2c_adapter;
+	struct i2c_client    *i2c_client[1];
 
 	struct ngene         *dev;
 	int                   number;
-- 
2.13.6

  parent reply	other threads:[~2018-02-17 15:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-17 15:03 [PATCH v2 0/7] cxd2099: convert to regmap API and move out of staging Daniel Scheller
2018-02-17 15:03 ` [PATCH v2 1/7] [media] ddbridge/ci: further deduplicate code/logic in ddb_ci_attach() Daniel Scheller
2018-02-17 15:03 ` [PATCH v2 2/7] [media] staging/cxd2099: convert to regmap API Daniel Scheller
2018-02-17 15:03 ` [PATCH v2 3/7] [media] ddbridge: adapt cxd2099 attach to new i2c_client way Daniel Scheller
2018-02-17 15:03 ` Daniel Scheller [this message]
2018-02-17 15:03 ` [PATCH v2 5/7] [media] staging/cxd2099: remove remainders from old attach way Daniel Scheller
2018-02-17 15:03 ` [PATCH v2 6/7] [media] cxd2099: move driver out of staging into dvb-frontends Daniel Scheller
2018-02-17 15:03 ` [PATCH v2 7/7] [media] MAINTAINERS: add entry for cxd2099 Daniel Scheller

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=20180217150328.686-5-d.scheller.oss@gmail.com \
    --to=d.scheller.oss@gmail.com \
    --cc=jasmin@anw.at \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mchehab@s-opensource.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.