linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: linuxppc-dev@ozlabs.org
Cc: khali@linux-fr.org
Subject: [PATCH 03/15] powerpc/pmac: Convert windfarm_lm75 to new i2c probing
Date: Thu, 19 Apr 2012 18:16:44 +1000	[thread overview]
Message-ID: <1334823416-9138-4-git-send-email-benh@kernel.crashing.org> (raw)
In-Reply-To: <1334823416-9138-1-git-send-email-benh@kernel.crashing.org>

This simplifies the driver to stop using the deprecated attach interface

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 drivers/macintosh/windfarm_lm75_sensor.c |  124 ++++++++----------------------
 1 file changed, 30 insertions(+), 94 deletions(-)

diff --git a/drivers/macintosh/windfarm_lm75_sensor.c b/drivers/macintosh/windfarm_lm75_sensor.c
index 4d6a90a..4cc3f93 100644
--- a/drivers/macintosh/windfarm_lm75_sensor.c
+++ b/drivers/macintosh/windfarm_lm75_sensor.c
@@ -23,7 +23,7 @@
 
 #include "windfarm.h"
 
-#define VERSION "0.2"
+#define VERSION "1.0"
 
 #undef DEBUG
 
@@ -36,8 +36,8 @@
 struct wf_lm75_sensor {
 	int			ds1775 : 1;
 	int			inited : 1;
-	struct 	i2c_client	*i2c;
-	struct 	wf_sensor	sens;
+	struct i2c_client	*i2c;
+	struct wf_sensor	sens;
 };
 #define wf_to_lm75(c) container_of(c, struct wf_lm75_sensor, sens)
 
@@ -90,40 +90,19 @@ static struct wf_sensor_ops wf_lm75_ops = {
 
 static int wf_lm75_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
-{
+{	
 	struct wf_lm75_sensor *lm;
-	int rc;
-
-	lm = kzalloc(sizeof(struct wf_lm75_sensor), GFP_KERNEL);
-	if (lm == NULL)
-		return -ENODEV;
-
-	lm->inited = 0;
-	lm->ds1775 = id->driver_data;
-	lm->i2c = client;
-	lm->sens.name = client->dev.platform_data;
-	lm->sens.ops = &wf_lm75_ops;
-	i2c_set_clientdata(client, lm);
-
-	rc = wf_register_sensor(&lm->sens);
-	if (rc)
-		kfree(lm);
-
-	return rc;
-}
-
-static struct i2c_driver wf_lm75_driver;
-
-static struct i2c_client *wf_lm75_create(struct i2c_adapter *adapter,
-					     u8 addr, int ds1775,
-					     const char *loc)
-{
-	struct i2c_board_info info;
-	struct i2c_client *client;
-	char *name;
+	int rc, ds1775 = id->driver_data;
+	const char *name, *loc;
 
 	DBG("wf_lm75: creating  %s device at address 0x%02x\n",
-	    ds1775 ? "ds1775" : "lm75", addr);
+	    ds1775 ? "ds1775" : "lm75", client->addr);
+
+	loc = of_get_property(client->dev.of_node, "hwsensor-location", NULL);
+	if (!loc) {
+		dev_warn(&client->dev, "Missing hwsensor-location property!\n");
+		return -ENXIO;
+	}
 
 	/* Usual rant about sensor names not beeing very consistent in
 	 * the device-tree, oh well ...
@@ -138,67 +117,24 @@ static struct i2c_client *wf_lm75_create(struct i2c_adapter *adapter,
 	else if (!strcmp(loc, "HD Temp"))
 		name = "hard-drive-temp";
 	else
-		goto fail;
-
-	memset(&info, 0, sizeof(struct i2c_board_info));
-	info.addr = (addr >> 1) & 0x7f;
-	info.platform_data = name;
-	strlcpy(info.type, ds1775 ? "wf_ds1775" : "wf_lm75", I2C_NAME_SIZE);
-
-	client = i2c_new_device(adapter, &info);
-	if (client == NULL) {
-		printk(KERN_ERR "windfarm: failed to attach %s %s to i2c\n",
-		       ds1775 ? "ds1775" : "lm75", name);
-		goto fail;
-	}
-
-	/*
-	 * Let i2c-core delete that device on driver removal.
-	 * This is safe because i2c-core holds the core_lock mutex for us.
-	 */
-	list_add_tail(&client->detected, &wf_lm75_driver.clients);
-	return client;
- fail:
-	return NULL;
-}
-
-static int wf_lm75_attach(struct i2c_adapter *adapter)
-{
-	struct device_node *busnode, *dev;
-	struct pmac_i2c_bus *bus;
+		return -ENXIO;
+ 	
 
-	DBG("wf_lm75: adapter %s detected\n", adapter->name);
-
-	bus = pmac_i2c_adapter_to_bus(adapter);
-	if (bus == NULL)
+	lm = kzalloc(sizeof(struct wf_lm75_sensor), GFP_KERNEL);
+	if (lm == NULL)
 		return -ENODEV;
-	busnode = pmac_i2c_get_bus_node(bus);
 
-	DBG("wf_lm75: bus found, looking for device...\n");
-
-	/* Now look for lm75(s) in there */
-	for (dev = NULL;
-	     (dev = of_get_next_child(busnode, dev)) != NULL;) {
-		const char *loc =
-			of_get_property(dev, "hwsensor-location", NULL);
-		u8 addr;
+	lm->inited = 0;
+	lm->ds1775 = ds1775;
+	lm->i2c = client;
+	lm->sens.name = (char *)name; /* XXX fix constness in structure */
+	lm->sens.ops = &wf_lm75_ops;
+	i2c_set_clientdata(client, lm);
 
-		/* We must re-match the adapter in order to properly check
-		 * the channel on multibus setups
-		 */
-		if (!pmac_i2c_match_adapter(dev, adapter))
-			continue;
-		addr = pmac_i2c_get_dev_addr(dev);
-		if (loc == NULL || addr == 0)
-			continue;
-		/* real lm75 */
-		if (of_device_is_compatible(dev, "lm75"))
-			wf_lm75_create(adapter, addr, 0, loc);
-		/* ds1775 (compatible, better resolution */
-		else if (of_device_is_compatible(dev, "ds1775"))
-			wf_lm75_create(adapter, addr, 1, loc);
-	}
-	return 0;
+	rc = wf_register_sensor(&lm->sens);
+	if (rc)
+		kfree(lm);
+	return rc;
 }
 
 static int wf_lm75_remove(struct i2c_client *client)
@@ -217,16 +153,16 @@ static int wf_lm75_remove(struct i2c_client *client)
 }
 
 static const struct i2c_device_id wf_lm75_id[] = {
-	{ "wf_lm75", 0 },
-	{ "wf_ds1775", 1 },
+	{ "MAC,lm75", 0 },
+	{ "MAC,ds1775", 1 },
 	{ }
 };
+MODULE_DEVICE_TABLE(i2c, wf_lm75_id);
 
 static struct i2c_driver wf_lm75_driver = {
 	.driver = {
 		.name	= "wf_lm75",
 	},
-	.attach_adapter	= wf_lm75_attach,
 	.probe		= wf_lm75_probe,
 	.remove		= wf_lm75_remove,
 	.id_table	= wf_lm75_id,
-- 
1.7.9.5

  parent reply	other threads:[~2012-04-19  8:20 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-19  8:16 [PATCH 00/15] PowerMac i2c API conversions & windfarm updates Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 01/15] i2c/powermac: Register i2c devices from device-tree Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 02/15] powerpc/pmac: Convert therm_adt746x to new i2c probing Benjamin Herrenschmidt
2012-04-19  8:16 ` Benjamin Herrenschmidt [this message]
2012-04-19  8:16 ` [PATCH 04/15] powerpc/pmac: Convert windfarm_max6690 " Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 05/15] powerpc/pmac: Convert windfarm_smu_sat " Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 06/15] powerpc/windfarm: const'ify and add "priv" field to controls & sensors Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 07/15] powerpc/pmac: Don't add_timer() twice Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 08/15] powerpc/windfarm: Remove spurrious sysfs_attr_init() Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 09/15] powerpc/windfarm: Improve display of fan speeds in sysfs Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 10/15] powerpc/windfarm: Add useful accessors Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 11/15] powerpc/windfarm: Add ad7417 sensor Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 12/15] powerpc/windfarm: Add lm87 sensor Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 13/15] powerpc/windfarm: Updates to lm75 and max6690 sensors Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 14/15] powerpc/windfarm: Add Fan Control Unit controls for G5s Benjamin Herrenschmidt
2012-04-19  8:16 ` [PATCH 15/15] powerpc/powermac: New windfarm driver for PowerMac G5 (AGP) and Xserve G5 Benjamin Herrenschmidt
2012-04-19  9:37 ` [PATCH 00/15] PowerMac i2c API conversions & windfarm updates Jean Delvare
2012-04-19  9:36   ` Christian Kujau
2012-04-19 20:59   ` Benjamin Herrenschmidt
     [not found] ` <20120419113723.03a24d46__2279.25503063506$1334829915$gmane$org@endymion.delvare>
2012-04-19 10:11   ` Andreas Schwab
2012-04-19 11:02     ` Jean Delvare
     [not found]   ` <m27gxc2fqq.fsf__16075.0973890119$1334830355$gmane$org@igel.home>
2012-04-19 10:14     ` Andreas Schwab
     [not found]     ` <m239802flw.fsf__48316.0902433612$1334830569$gmane$org@igel.home>
2012-04-19 10:19       ` Andreas Schwab
     [not found] ` <1334823416-9138-3-git-send-email-benh__10691.3206204355$1334826366$gmane$org@kernel.crashing.org>
2012-04-19 13:10   ` [PATCH 02/15] powerpc/pmac: Convert therm_adt746x to new i2c probing Andreas Schwab
     [not found] ` <1334823416-9138-2-git-send-email-benh__33169.052625499$1334826821$gmane$org@kernel.crashing.org>
2012-04-19  9:34   ` [PATCH 01/15] i2c/powermac: Register i2c devices from device-tree Andreas Schwab
2012-06-09 13:58   ` Andreas Schwab
2012-06-09 22:11     ` Benjamin Herrenschmidt
2012-06-09 22:30       ` Andreas Schwab
2012-06-09 22:36         ` Benjamin Herrenschmidt
2012-06-09 22:59           ` Andreas Schwab
2012-06-09 23:10             ` Benjamin Herrenschmidt
2012-06-10  7:13               ` Andreas Schwab
2012-06-10  7:23                 ` Benjamin Herrenschmidt
2012-06-10 11:35                   ` Andreas Schwab
2012-06-18  1:27                   ` Benjamin Herrenschmidt
2012-06-18  2:03     ` Benjamin Herrenschmidt
2012-06-18  7:30       ` [PATCH] sound/aoa: remove i2c attach_adapter method Andreas Schwab

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=1334823416-9138-4-git-send-email-benh@kernel.crashing.org \
    --to=benh@kernel.crashing.org \
    --cc=khali@linux-fr.org \
    --cc=linuxppc-dev@ozlabs.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).