From patchwork Sat Mar 12 22:32:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Green X-Patchwork-Id: 529 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:43:22 -0000 Delivered-To: patches@linaro.org Received: by 10.224.45.75 with SMTP id d11cs13466qaf; Sat, 12 Mar 2011 14:32:31 -0800 (PST) Received: by 10.216.145.200 with SMTP id p50mr841810wej.79.1299969150584; Sat, 12 Mar 2011 14:32:30 -0800 (PST) Received: from mail-wy0-f178.google.com (mail-wy0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id 39si6864146wet.99.2011.03.12.14.32.29 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 12 Mar 2011 14:32:30 -0800 (PST) Received-SPF: pass (google.com: domain of andy.warmcat.com@googlemail.com designates 74.125.82.178 as permitted sender) client-ip=74.125.82.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of andy.warmcat.com@googlemail.com designates 74.125.82.178 as permitted sender) smtp.mail=andy.warmcat.com@googlemail.com; dkim=pass (test mode) header.i=@googlemail.com Received: by mail-wy0-f178.google.com with SMTP id 26so4056169wyj.37 for ; Sat, 12 Mar 2011 14:32:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:sender:from:subject:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version:content-type :content-transfer-encoding; bh=SQnpOTyVbWPNzUYzVOVd6I7rkfQbApKV0G063KeiWO4=; b=DfqCaCU32ACmV5NcYG0reGNprUb5dCOHMg1v6sxNnpdZlq4QNHmxEF55o8NjMF7eHX fcNcF9NTOO8QoWbxDlV93P/H4JSZJMBXosm34BOVnFXyPq0/awohaElAWHE2e2m2CXhd ungcKGwA41ShHRk5EIAQl8ZZSQMQGc2es3wc0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=sender:from:subject:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; b=YMwaIu5a0Bi5kXsiAI3bkZVP6OmDF6W1YHqzWfIgdC3p6Pw+pZym1d9eqFbrQF+wnk K+gemZ7eG9JwUPkJ4BWyCp6h/19rW4gsQOWdD0tUvpyI56XuljNvgWAzotpi1fPp9+12 l+QNgZHWBoN/c4hV9jDwtsXH3oZbGApgALRns= Received: by 10.227.169.76 with SMTP id x12mr3597613wby.155.1299969149816; Sat, 12 Mar 2011 14:32:29 -0800 (PST) Received: from otae.warmcat.com (s15404224.onlinehome-server.info [87.106.134.80]) by mx.google.com with ESMTPS id y29sm1952789wbd.10.2011.03.12.14.32.28 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 12 Mar 2011 14:32:29 -0800 (PST) Sender: Andy Green From: Andy Green Subject: [RFC PATCH 3/4] PLATFORM: Introduce async platform_data attach api To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: patches@linaro.org, Andy Green Date: Sat, 12 Mar 2011 22:32:27 +0000 Message-ID: <20110312223227.27020.83925.stgit@otae.warmcat.com> In-Reply-To: <20110312222633.27020.19543.stgit@otae.warmcat.com> References: <20110312222633.27020.19543.stgit@otae.warmcat.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 This introduces a platform API so busses can allow platform_data to be attached to any struct device they create from probing in one step. The function checks through the async platform_data map if one was previously registered, and checks the device's device path for itself and its parents against the mapped device path names. If it sees a match, it attaches the associated platform_data and sets that map entry's device_path to NULL so no further time is spent trying to match it. Signed-off-by: Andy Green --- drivers/base/platform.c | 70 +++++++++++++++++++++++++++++++++++++++ include/linux/platform_device.h | 2 + 2 files changed, 72 insertions(+), 0 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 180e372..534bf3a 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1353,3 +1353,73 @@ void platform_async_platform_data_register( platform_async_platform_data_count = count; } EXPORT_SYMBOL_GPL(platform_async_platform_data_register); + +/** + * platform_async_platform_data_attach - if there is any async devname map + * defined, go through it looking for a match with the + * device's path considering its parent device names. + * If a match is found, attach the corresponding + * platform_data and the entry in the map table set to + * NULL so it won't be looked for again. + * + * @dev: device to have data attched to if it matches any map entry + */ +void platform_async_platform_data_attach(struct device *dev) +{ + struct platform_async_platform_data *map; + const char *path; + int count; + const char *p; + int len; + struct device *devn; + + map = platform_async_platform_data_map; + count = platform_async_platform_data_count; + + while (count--) { + + if (map->device_path == NULL) { + map++; + continue; + } + + p = map->device_path + strlen(map->device_path); + devn = dev; + + while (devn) { + + path = dev_name(devn); + len = strlen(path); + + if ((p - map->device_path) < len) { + devn = NULL; + continue; + } + + p -= len; + + if (strncmp(path, p, len)) { + devn = NULL; + continue; + } + + devn = devn->parent; + if (p == map->device_path) { + dev_info(dev, "Attched async platform data\n"); + dev->platform_data = map->platform_data; + map->device_path = NULL; + return; + } + + if (devn != NULL && (p - map->device_path) < 2) + devn = NULL; + + p--; + if (devn != NULL && *p != '/') + devn = NULL; + } + + map++; + } +} +EXPORT_SYMBOL_GPL(platform_async_platform_data_attach); diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 19ea497..4b5fa12 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -213,4 +213,6 @@ struct platform_async_platform_data { extern void platform_async_platform_data_register( struct platform_async_platform_data *map, int count); +extern void platform_async_platform_data_attach(struct device *dev); + #endif /* _PLATFORM_DEVICE_H_ */