linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Corbet <corbet@lwn.net>
To: linux-kernel@vger.kernel.org
Cc: Harald Welte <laforge@gnumonks.org>,
	Deepak Saxena <dsaxena@laptop.org>,
	linux-fbdev@vger.kernel.org, JosephChan@via.com.tw,
	ScottFang@viatech.com.cn,
	Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Subject: [PATCH 07/13] via: Do not attempt I/O on inactive I2C adapters
Date: Fri, 23 Apr 2010 21:28:07 +0000	[thread overview]
Message-ID: <1272058093-20914-8-git-send-email-corbet@lwn.net> (raw)
In-Reply-To: <1272058093-20914-1-git-send-email-corbet@lwn.net>

If an adapter has been configured for GPIO, we should not try to use it as
an I2C port.  Also fixed a stupid bug which might, in some configurations,
have resulted in a failure to set up ports.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
---
 drivers/video/via/via_i2c.c |   16 +++++++++++-----
 drivers/video/via/via_i2c.h |    1 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/video/via/via_i2c.c b/drivers/video/via/via_i2c.c
index cabf574..dbb2392 100644
--- a/drivers/video/via/via_i2c.c
+++ b/drivers/video/via/via_i2c.c
@@ -117,6 +117,8 @@ int viafb_i2c_readbyte(u8 adap, u8 slave_addr, u8 index, u8 *pdata)
 	u8 mm1[] = {0x00};
 	struct i2c_msg msgs[2];
 
+	if (!via_i2c_par[adap].is_active)
+		return -ENODEV;
 	*pdata = 0;
 	msgs[0].flags = 0;
 	msgs[1].flags = I2C_M_RD;
@@ -132,6 +134,8 @@ int viafb_i2c_writebyte(u8 adap, u8 slave_addr, u8 index, u8 data)
 	u8 msg[2] = { index, data };
 	struct i2c_msg msgs;
 
+	if (!via_i2c_par[adap].is_active)
+		return -ENODEV;
 	msgs.flags = 0;
 	msgs.addr = slave_addr / 2;
 	msgs.len = 2;
@@ -144,6 +148,8 @@ int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len
 	u8 mm1[] = {0x00};
 	struct i2c_msg msgs[2];
 
+	if (!via_i2c_par[adap].is_active)
+		return -ENODEV;
 	msgs[0].flags = 0;
 	msgs[1].flags = I2C_M_RD;
 	msgs[0].addr = msgs[1].addr = slave_addr / 2;
@@ -200,18 +206,18 @@ static int viafb_i2c_probe(struct platform_device *platdev)
 		struct via_port_cfg *adap_cfg = configs++;
 		struct via_i2c_stuff *i2c_stuff = &via_i2c_par[i];
 
+		i2c_stuff->is_active = 0;
 		if (adap_cfg->type = 0 || adap_cfg->mode != VIA_MODE_I2C)
-			break;
-
+			continue;
 		ret = create_i2c_bus(&i2c_stuff->adapter,
 				     &i2c_stuff->algo, adap_cfg,
 				NULL); /* FIXME: PCIDEV */
 		if (ret < 0) {
 			printk(KERN_ERR "viafb: cannot create i2c bus %u:%d\n",
 				i, ret);
-			/* FIXME: properly release previous busses */
-			return ret;
+			continue;  /* Still try to make the rest */
 		}
+		i2c_stuff->is_active = 1;
 	}
 
 	return 0;
@@ -227,7 +233,7 @@ static int viafb_i2c_remove(struct platform_device *platdev)
 		 * Only remove those entries in the array that we've
 		 * actually used (and thus initialized algo_data)
 		 */
-		if (i2c_stuff->adapter.algo_data = &i2c_stuff->algo)
+		if (i2c_stuff->is_active)
 			i2c_del_adapter(&i2c_stuff->adapter);
 	}
 	return 0;
diff --git a/drivers/video/via/via_i2c.h b/drivers/video/via/via_i2c.h
index 5f9db66..da3a96a 100644
--- a/drivers/video/via/via_i2c.h
+++ b/drivers/video/via/via_i2c.h
@@ -26,6 +26,7 @@
 
 struct via_i2c_stuff {
 	u16 i2c_port;			/* GPIO or I2C port */
+	u16 is_active;			/* Being used as I2C? */
 	struct i2c_adapter adapter;
 	struct i2c_algo_bit_data algo;
 };
-- 
1.7.0.1


  parent reply	other threads:[~2010-04-23 21:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-23 21:28 [RFC] Second OLPC Viafb series Jonathan Corbet
2010-04-23 21:28 ` [PATCH 01/13] viafb: Move core stuff into via-core.c Jonathan Corbet
2010-04-23 21:28 ` [PATCH 02/13] viafb: Separate global and fb-specific data Jonathan Corbet
2010-04-23 21:28 ` [PATCH 03/13] viafb: add a driver for GPIO lines Jonathan Corbet
2010-04-23 21:28 ` [PATCH 04/13] viafb: package often used basic io functions Jonathan Corbet
2010-04-23 21:28 ` [PATCH 05/13] viafb: Convert GPIO and i2c to the new indexed port ops Jonathan Corbet
2010-04-23 21:28 ` [PATCH 06/13] viafb: Turn GPIO and i2c into proper platform devices Jonathan Corbet
2010-04-23 21:28 ` Jonathan Corbet [this message]
2010-04-23 21:28 ` [PATCH 08/13] viafb: Introduce viafb_find_i2c_adapter() Jonathan Corbet
2010-04-23 21:28 ` [PATCH 09/13] via: Rationalize vt1636 detection Jonathan Corbet
2010-04-23 21:28 ` [PATCH 10/13] viafb: Add a simple interrupt management infrastructure Jonathan Corbet
2010-04-23 21:28 ` [PATCH 11/13] viafb: Add a simple VX855 DMA engine driver Jonathan Corbet
2010-04-23 21:28 ` [PATCH 12/13] viafb: Reserve framebuffer memory for the upcoming camera driver Jonathan Corbet
2010-04-23 21:28 ` [PATCH 13/13] viafb: Add a driver for the video capture engine Jonathan Corbet
2010-04-24 15:07 ` [RFC] Second OLPC Viafb series Florian Tobias Schandinat

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=1272058093-20914-8-git-send-email-corbet@lwn.net \
    --to=corbet@lwn.net \
    --cc=FlorianSchandinat@gmx.de \
    --cc=JosephChan@via.com.tw \
    --cc=ScottFang@viatech.com.cn \
    --cc=dsaxena@laptop.org \
    --cc=laforge@gnumonks.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).