mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kyle Manna <kyle.manna@fuel7.com>
To: linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org
Cc: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Liam Girdwood <lrg@ti.com>, Samuel Ortiz <sameo@linux.intel.com>,
	Kyle Manna <kyle.manna@fuel7.com>
Subject: [PATCH v3 1/6] mfd: TPS65910: Handle non-existent devices
Date: Thu,  3 Nov 2011 12:08:01 -0500	[thread overview]
Message-ID: <1320340086-15371-2-git-send-email-kyle.manna@fuel7.com> (raw)
In-Reply-To: <1320340086-15371-1-git-send-email-kyle.manna@fuel7.com>

The JTAGREVNUM register contains a silicon revision number in the lower
four bits and the upper four bits are to always read 0.

To detect the presence of the device, attempt to read JTAGREVNUM
register and check that it returns a valid value.  If the I2C device
fails to respond or returns an invalid value, return -ENODEV.

Signed-off-by: Kyle Manna <kyle.manna@fuel7.com>
---
 drivers/mfd/tps65910.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index 6f5b8cf..0d9c3eb 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -138,6 +138,7 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	struct tps65910_board *pmic_plat_data;
 	struct tps65910_platform_data *init_data;
 	int ret = 0;
+	char reg = 0;
 
 	pmic_plat_data = dev_get_platdata(&i2c->dev);
 	if (!pmic_plat_data)
@@ -161,11 +162,19 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	tps65910->write = tps65910_i2c_write;
 	mutex_init(&tps65910->io_mutex);
 
-	ret = mfd_add_devices(tps65910->dev, -1,
-			      tps65910s, ARRAY_SIZE(tps65910s),
-			      NULL, 0);
-	if (ret < 0)
+	/* Check that the device is there */
+	ret = tps65910_i2c_read(tps65910, TPS65910_JTAGVERNUM, 1, &reg);
+	if (ret < 0 || (reg & ~JTAGVERNUM_VERNUM_MASK)) {
+		dev_err(tps65910->dev, "unknown version: JTAGREVNUM = 0x%x\n",
+				       reg);
+		ret = -ENODEV;
 		goto err;
+	}
+
+	ret = mfd_add_devices(tps65910->dev, -1, tps65910s,
+			ARRAY_SIZE(tps65910s), NULL, 0);
+	if (ret < 0)
+		goto err2;
 
 	init_data->irq = pmic_plat_data->irq;
 	init_data->irq_base = pmic_plat_data->irq;
@@ -174,13 +183,14 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 
 	ret = tps65910_irq_init(tps65910, init_data->irq, init_data);
 	if (ret < 0)
-		goto err;
+		goto err2;
 
 	kfree(init_data);
 	return ret;
 
-err:
+err2:
 	mfd_remove_devices(tps65910->dev);
+err:
 	kfree(tps65910);
 	kfree(init_data);
 	return ret;
-- 
1.7.5.4


  reply	other threads:[~2011-11-03 17:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-03 17:08 [PATCH v3 0/6] mfd: TPS65910: Bug fixes and enhancements Kyle Manna
2011-11-03 17:08 ` Kyle Manna [this message]
2011-11-04  5:53   ` [PATCH v3 1/6] mfd: TPS65910: Handle non-existent devices Mohammed, Afzal
2011-11-04  6:22   ` Mohammed, Afzal
2011-11-03 17:08 ` [PATCH v3 2/6] mfd: TPS65910: Add I2C slave address macros Kyle Manna
2011-11-03 17:08 ` [PATCH v3 3/6] mfd: TPS65910: Fix typo that clobbers genirq Kyle Manna
2011-11-03 17:08 ` [PATCH v3 4/6] mfd: TPS65910: Move linux/gpio.h include to header Kyle Manna
2011-11-03 17:25   ` Felipe Balbi
2011-11-03 17:08 ` [PATCH v3 5/6] regulator: TPS65910: Move regulator defs " Kyle Manna
2011-11-03 17:08 ` [PATCH v3 6/6] regulator: TPS65910: Create an array for init data Kyle Manna

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=1320340086-15371-2-git-send-email-kyle.manna@fuel7.com \
    --to=kyle.manna@fuel7.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=jedu@slimlogic.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=lrg@ti.com \
    --cc=sameo@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®