From patchwork Mon Sep 30 05:13:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 20696 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 843D525B8B for ; Mon, 30 Sep 2013 05:22:32 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hf12sf4637376vcb.3 for ; Sun, 29 Sep 2013 22:22:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=yIPb189Fm10nUbC8XrhewG3nUHfZ5zgkaTffGV+OSXs=; b=DxHo2zTM/2sfOeyiM4mHm2XzLzBXKiFCA7QY9KSkzvpBEMXL5rDL1kdzLHFNIpKjEA 0LBw2OghFh3Sff09SjOt8YkPQUGK7JPhrUIoPstqCWCEEgfkmK5AcGml6kI5O531tz8D Jppzoc5eWcNvGVFB92sJjuTR5xEOLAE3srB1aAyC3ANYeUDzTU6OaurAEaVwX0wtJA+a vBfF4YxEZYtToItGzBO4N7ha4+N9rnYrlqA/Jhmx+aDMnYe0rcWiRZgnF2GmA+yOd3OX oKpfC66MFE41ocx1/s4x6goxq0aG+zf5GQ7GF7O+O1UN43VMCe1OmVQ2xhGIcLBGp8HE cdgA== X-Received: by 10.236.135.79 with SMTP id t55mr3403770yhi.39.1380518552345; Sun, 29 Sep 2013 22:22:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.16.6 with SMTP id b6ls2027689qed.79.gmail; Sun, 29 Sep 2013 22:22:32 -0700 (PDT) X-Received: by 10.58.117.71 with SMTP id kc7mr157298veb.16.1380518552250; Sun, 29 Sep 2013 22:22:32 -0700 (PDT) Received: from mail-vb0-f52.google.com (mail-vb0-f52.google.com [209.85.212.52]) by mx.google.com with ESMTPS id zw10si5323183vdb.148.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 29 Sep 2013 22:22:32 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.52 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.52; Received: by mail-vb0-f52.google.com with SMTP id f12so3308627vbg.25 for ; Sun, 29 Sep 2013 22:22:02 -0700 (PDT) X-Gm-Message-State: ALoCoQl8wlM/UO97WMO25KJKRK/hTIBOmNawpYYxV/AnZlhGYOfG2qA7fOCkHWZsvfp5NNwndCKp X-Received: by 10.52.113.99 with SMTP id ix3mr17218618vdb.22.1380518522136; Sun, 29 Sep 2013 22:22:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp84818vcz; Sun, 29 Sep 2013 22:22:01 -0700 (PDT) X-Received: by 10.50.36.5 with SMTP id m5mr12397796igj.3.1380518521489; Sun, 29 Sep 2013 22:22:01 -0700 (PDT) Received: from hanjun-Latitude-D630 ([218.17.215.175]) by mx.google.com with ESMTPS id yw6si18934823icb.59.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 29 Sep 2013 22:22:01 -0700 (PDT) Received-SPF: neutral (google.com: 218.17.215.175 is neither permitted nor denied by best guess record for domain of hanjun@hanjun-latitude-d630) client-ip=218.17.215.175; Received: from hanjun-Latitude-D630 (localhost [127.0.0.1]) by hanjun-Latitude-D630 (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id r8U5Gdtr005360; Mon, 30 Sep 2013 13:16:39 +0800 Received: (from hanjun@localhost) by hanjun-Latitude-D630 (8.14.4/8.14.4/Submit) id r8U5Gce6005359; Mon, 30 Sep 2013 13:16:38 +0800 From: Hanjun Guo To: Greg Kroah-Hartman , Wolfram Sang , Mark Brown Cc: "Rafael J. Wysocki" , Fabio Porcedda , Grant Likely , Linus Walleij , Libo Chen , linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, linaro-acpi@lists.linaro.org, Hanjun Guo Subject: [PATCH 1/4] driver core: introduce helper macro initcall_driver() Date: Mon, 30 Sep 2013 13:13:52 +0800 Message-Id: <1380518035-5319-2-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1380518035-5319-1-git-send-email-hanjun.guo@linaro.org> References: <1380518035-5319-1-git-send-email-hanjun.guo@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: hanjun.guo@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.52 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , For some devices especially on platform/I2C/SPI bus, they want to be initialized earlier than other devices, so the driver use initcall such as subsys_initcall to make this device initialize earlier. But for those drivers, lots of them just do nothing special in xxx_initcall/exit, so introduce a helper macro initcall_driver() to eliminate lots of boilerplate just like module_driver() did. Signed-off-by: Hanjun Guo --- include/linux/device.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index 2a9d6ed..1903f7f 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1198,4 +1198,31 @@ static void __exit __driver##_exit(void) \ } \ module_exit(__driver##_exit); +/** + * initcall_driver() - Helper macro for drivers that don't do anything + * special in buid-in module xxx_initcall/exit. This eliminates a lot + * of boilerplate. Each driver may only use this macro once, and calling + * it replaces xxx_initcall() and module_exit(). + * + * @__type: initcall type + * @__driver: driver name + * @__register: register function for this driver type + * @__unregister: unregister function for this driver type + * @...: Additional arguments to be passed to __register and __unregister. + * + * Use this macro to construct bus specific macros for registering + * drivers, and do not use it on its own. + */ +#define initcall_driver(__type, __driver, __register, __unregister, ...) \ +static int __init __driver##_init(void) \ +{ \ + return __register(&(__driver) , ##__VA_ARGS__); \ +} \ +__type##_initcall(__driver##_init); \ +static void __exit __driver##_exit(void) \ +{ \ + __unregister(&(__driver) , ##__VA_ARGS__); \ +} \ +module_exit(__driver##_exit); + #endif /* _DEVICE_H_ */