From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: linuxppc-dev@ozlabs.org
Cc: khali@linux-fr.org
Subject: [PATCH 01/15] i2c/powermac: Register i2c devices from device-tree
Date: Thu, 19 Apr 2012 18:16:42 +1000 [thread overview]
Message-ID: <1334823416-9138-2-git-send-email-benh@kernel.crashing.org> (raw)
In-Reply-To: <1334823416-9138-1-git-send-email-benh@kernel.crashing.org>
This causes i2c-powermac to register i2c devices exposed in the
device-tree, enabling new-style probing of devices.
Note that we prefix the IDs with "MAC," in order to prevent the
generic drivers from matching. This is done on purpose as we only
want drivers specifically tested/designed to operate on powermacs
to match.
This removes the special case we had for the AMS driver, and updates
the driver's match table instead.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
arch/powerpc/platforms/powermac/low_i2c.c | 1 +
drivers/i2c/busses/i2c-powermac.c | 98 +++++++++++++++++++++--------
drivers/macintosh/ams/ams-i2c.c | 2 +-
3 files changed, 73 insertions(+), 28 deletions(-)
diff --git a/arch/powerpc/platforms/powermac/low_i2c.c b/arch/powerpc/platforms/powermac/low_i2c.c
index 996c5ff..f991dbb 100644
--- a/arch/powerpc/platforms/powermac/low_i2c.c
+++ b/arch/powerpc/platforms/powermac/low_i2c.c
@@ -1494,6 +1494,7 @@ static int __init pmac_i2c_create_platform_devices(void)
if (bus->platform_dev == NULL)
return -ENOMEM;
bus->platform_dev->dev.platform_data = bus;
+ bus->platform_dev->dev.of_node = bus->busnode;
platform_device_add(bus->platform_dev);
}
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 7b397c6..31c47e1 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -227,6 +227,72 @@ static int __devexit i2c_powermac_remove(struct platform_device *dev)
return 0;
}
+static void __devinit i2c_powermac_register_devices(struct i2c_adapter *adap,
+ struct pmac_i2c_bus *bus)
+{
+ struct i2c_client *newdev;
+ struct device_node *node;
+
+ for_each_child_of_node(adap->dev.of_node, node) {
+ struct i2c_board_info info = {};
+ struct dev_archdata dev_ad = {};
+ const __be32 *reg;
+ char tmp[16];
+ u32 addr;
+ int len;
+
+ /* Get address & channel */
+ reg = of_get_property(node, "reg", &len);
+ if (!reg || (len < sizeof(int))) {
+ dev_err(&adap->dev, "i2c-powermac: invalid reg on %s\n",
+ node->full_name);
+ continue;
+ }
+ addr = be32_to_cpup(reg);
+
+ /* Multibus setup, check channel */
+ if (!pmac_i2c_match_adapter(node, adap))
+ continue;
+
+ dev_dbg(&adap->dev, "i2c-powermac: register %s\n",
+ node->full_name);
+
+ /* Make up a modalias. Note: we to _NOT_ want the standard
+ * i2c drivers to match with any of our powermac stuff
+ * unless they have been specifically modified to handle
+ * it on a case by case basis. For example, for thermal
+ * control, things like lm75 etc... shall match with their
+ * corresponding windfarm drivers, _NOT_ the generic ones,
+ * so we force a prefix of AAPL, onto the modalias to
+ * make that happen
+ */
+ if (of_modalias_node(node, tmp, sizeof(tmp)) < 0) {
+ dev_err(&adap->dev, "i2c-powermac: modalias failure"
+ " on %s\n", node->full_name);
+ continue;
+ }
+ snprintf(info.type, sizeof(info.type), "MAC,%s", tmp);
+
+ /* Fill out the rest of the info structure */
+ info.addr = (addr & 0xff) >> 1;
+ info.irq = irq_of_parse_and_map(node, 0);
+ info.of_node = of_node_get(node);
+ info.archdata = &dev_ad;
+
+ newdev = i2c_new_device(adap, &info);
+ if (!newdev) {
+ dev_err(&adap->dev, "i2c-powermac: Failure to register"
+ " %s\n", node->full_name);
+ of_node_put(node);
+ /* We do not dispose of the interrupt mapping on
+ * purpose. It's not necessary (interrupt cannot be
+ * re-used) and somebody else might have grabbed it
+ * via direct DT lookup so let's not bother
+ */
+ continue;
+ }
+ }
+}
static int __devinit i2c_powermac_probe(struct platform_device *dev)
{
@@ -272,6 +338,7 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev)
adapter->algo = &i2c_powermac_algorithm;
i2c_set_adapdata(adapter, bus);
adapter->dev.parent = &dev->dev;
+ adapter->dev.of_node = dev->dev.of_node;
rc = i2c_add_adapter(adapter);
if (rc) {
printk(KERN_ERR "i2c-powermac: Adapter %s registration "
@@ -281,33 +348,10 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev)
printk(KERN_INFO "PowerMac i2c bus %s registered\n", adapter->name);
- if (!strncmp(basename, "uni-n", 5)) {
- struct device_node *np;
- const u32 *prop;
- struct i2c_board_info info;
-
- /* Instantiate I2C motion sensor if present */
- np = of_find_node_by_name(NULL, "accelerometer");
- if (np && of_device_is_compatible(np, "AAPL,accelerometer_1") &&
- (prop = of_get_property(np, "reg", NULL))) {
- int i2c_bus;
- const char *tmp_bus;
-
- /* look for bus either using "reg" or by path */
- tmp_bus = strstr(np->full_name, "/i2c-bus@");
- if (tmp_bus)
- i2c_bus = *(tmp_bus + 9) - '0';
- else
- i2c_bus = ((*prop) >> 8) & 0x0f;
-
- if (pmac_i2c_get_channel(bus) == i2c_bus) {
- memset(&info, 0, sizeof(struct i2c_board_info));
- info.addr = ((*prop) & 0xff) >> 1;
- strlcpy(info.type, "ams", I2C_NAME_SIZE);
- i2c_new_device(adapter, &info);
- }
- }
- }
+ /* Cannot use of_i2c_register_devices() due to Apple device-tree
+ * funkyness
+ */
+ i2c_powermac_register_devices(adapter, bus);
return rc;
}
diff --git a/drivers/macintosh/ams/ams-i2c.c b/drivers/macintosh/ams/ams-i2c.c
index abeecd2..978eda8 100644
--- a/drivers/macintosh/ams/ams-i2c.c
+++ b/drivers/macintosh/ams/ams-i2c.c
@@ -65,7 +65,7 @@ static int ams_i2c_probe(struct i2c_client *client,
static int ams_i2c_remove(struct i2c_client *client);
static const struct i2c_device_id ams_id[] = {
- { "ams", 0 },
+ { "MAC,accelerometer_1", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, ams_id);
--
1.7.9.5
next prev parent reply other threads:[~2012-04-19 9:04 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 ` Benjamin Herrenschmidt [this message]
2012-04-19 8:16 ` [PATCH 02/15] powerpc/pmac: Convert therm_adt746x to new i2c probing Benjamin Herrenschmidt
2012-04-19 8:16 ` [PATCH 03/15] powerpc/pmac: Convert windfarm_lm75 " Benjamin Herrenschmidt
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-2-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).