public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Linux I2C <i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org>
Cc: David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
Subject: [PATCH 5/5] i2c: Convert the eeprom driver to a new-style i2c driver
Date: Mon, 16 Jun 2008 22:23:28 +0200	[thread overview]
Message-ID: <20080616222328.526402b8@hyperion.delvare> (raw)
In-Reply-To: <20080616221257.446a2145-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>

The new-style eeprom driver implements the optional detect() callback
to cover the use cases of the legacy driver.

Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
---
Depends on at least the following patches:
http://khali.linux-fr.org/devel/linux-2.6/jdelvare-i2c/i2c-03-eeprom-should-not-probe-all-adapters.patch
http://khali.linux-fr.org/devel/linux-2.6/jdelvare-i2c/i2c-eeprom-use-word-read-transactions.patch
http://khali.linux-fr.org/devel/linux-2.6/jdelvare-i2c/i2c-clean-up-old-chip-drivers.patch

 drivers/i2c/chips/eeprom.c |   82 ++++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 44 deletions(-)

--- linux-2.6.26-rc6.orig/drivers/i2c/chips/eeprom.c	2008-06-16 20:28:46.000000000 +0200
+++ linux-2.6.26-rc6/drivers/i2c/chips/eeprom.c	2008-06-16 21:02:13.000000000 +0200
@@ -51,7 +51,6 @@ enum eeprom_nature {
 
 /* Each client has this additional data */
 struct eeprom_data {
-	struct i2c_client client;
 	struct mutex update_lock;
 	u8 valid;			/* bitfield, bit!=0 if slice is valid */
 	unsigned long last_updated[8];	/* In jiffies, 8 slices */
@@ -60,17 +59,28 @@ struct eeprom_data {
 };
 
 
-static int eeprom_attach_adapter(struct i2c_adapter *adapter);
-static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind);
-static int eeprom_detach_client(struct i2c_client *client);
+static int eeprom_probe(struct i2c_client *client,
+			const struct i2c_device_id *id);
+static int eeprom_detect(struct i2c_client *client, int kind,
+			 struct i2c_board_info *info);
+static int eeprom_remove(struct i2c_client *client);
+
+static struct i2c_device_id eeprom_id[] = {
+	{ "eeprom", 0 },
+	{ }
+};
 
 /* This is the driver that will be inserted */
 static struct i2c_driver eeprom_driver = {
+	.class		= I2C_CLASS_DDC | I2C_CLASS_SPD,
 	.driver = {
 		.name	= "eeprom",
 	},
-	.attach_adapter	= eeprom_attach_adapter,
-	.detach_client	= eeprom_detach_client,
+	.probe		= eeprom_probe,
+	.remove		= eeprom_remove,
+	.detect		= eeprom_detect,
+	.id_table	= eeprom_id,
+	.address_data	= &addr_data,
 };
 
 static void eeprom_update_client(struct i2c_client *client, u8 slice)
@@ -152,25 +162,17 @@ static struct bin_attribute eeprom_attr 
 	.read = eeprom_read,
 };
 
-static int eeprom_attach_adapter(struct i2c_adapter *adapter)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int eeprom_detect(struct i2c_client *client, int kind,
+			 struct i2c_board_info *info)
 {
-	if (!(adapter->class & (I2C_CLASS_DDC | I2C_CLASS_SPD)))
-		return 0;
-	return i2c_probe(adapter, &addr_data, eeprom_detect);
-}
-
-/* This function is called by i2c_probe */
-static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
-{
-	struct i2c_client *client;
-	struct eeprom_data *data;
-	int err = 0;
+	struct i2c_adapter *adapter = client->adapter;
 
 	/* EDID EEPROMs are often 24C00 EEPROMs, which answer to all
 	   addresses 0x50-0x57, but we only care about 0x50. So decline
 	   attaching to addresses >= 0x51 on DDC buses */
-	if (!(adapter->class & I2C_CLASS_SPD) && address >= 0x51)
-		goto exit;
+	if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51)
+		return -ENODEV;
 
 	/* There are four ways we can read the EEPROM data:
 	   (1) I2C block reads (faster, but unsupported by most adapters)
@@ -181,32 +183,33 @@ static int eeprom_detect(struct i2c_adap
 	   because all known adapters support one of the first two. */
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)
 	 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
-		goto exit;
+		return -ENODEV;
+
+	strlcpy(info->type, "eeprom", I2C_NAME_SIZE);
+
+	return 0;
+}
+
+static int eeprom_probe(struct i2c_client *client,
+			const struct i2c_device_id *id)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	struct eeprom_data *data;
+	int err;
 
 	if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
 		err = -ENOMEM;
 		goto exit;
 	}
 
-	client = &data->client;
 	memset(data->data, 0xff, EEPROM_SIZE);
 	i2c_set_clientdata(client, data);
-	client->addr = address;
-	client->adapter = adapter;
-	client->driver = &eeprom_driver;
-
-	/* Fill in the remaining client fields */
-	strlcpy(client->name, "eeprom", I2C_NAME_SIZE);
 	mutex_init(&data->update_lock);
 	data->nature = UNKNOWN;
 
-	/* Tell the I2C layer a new client has arrived */
-	if ((err = i2c_attach_client(client)))
-		goto exit_kfree;
-
 	/* Detect the Vaio nature of EEPROMs.
 	   We use the "PCG-" or "VGN-" prefix as the signature. */
-	if (address == 0x57
+	if (client->addr == 0x57
 	 && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
 		char name[4];
 
@@ -225,28 +228,19 @@ static int eeprom_detect(struct i2c_adap
 	/* create the sysfs eeprom file */
 	err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr);
 	if (err)
-		goto exit_detach;
+		goto exit_kfree;
 
 	return 0;
 
-exit_detach:
-	i2c_detach_client(client);
 exit_kfree:
 	kfree(data);
 exit:
 	return err;
 }
 
-static int eeprom_detach_client(struct i2c_client *client)
+static int eeprom_remove(struct i2c_client *client)
 {
-	int err;
-
 	sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
-
-	err = i2c_detach_client(client);
-	if (err)
-		return err;
-
 	kfree(i2c_get_clientdata(client));
 
 	return 0;

-- 
Jean Delvare

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

      parent reply	other threads:[~2008-06-16 20:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-16 20:12 [PATCH 0/5] i2c: Add detection capability to new-style drivers Jean Delvare
     [not found] ` <20080616221257.446a2145-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-16 20:16   ` [PATCH 1/5] " Jean Delvare
2008-06-16 20:17   ` [PATCH 2/5] i2c: Convert the lm90 driver to a new-style i2c driver Jean Delvare
2008-06-16 20:18   ` [PATCH 3/5] i2c: Drop legacy f75375s driver Jean Delvare
2008-06-16 20:20   ` [PATCH 4/5] i2c: Drop legacy lm75 driver Jean Delvare
2008-06-16 20:23   ` Jean Delvare [this message]

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=20080616222328.526402b8@hyperion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org \
    --cc=i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.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