From patchwork Fri Apr 3 12:42:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 6156331 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 51229BF4A6 for ; Fri, 3 Apr 2015 12:43:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55FA8203DB for ; Fri, 3 Apr 2015 12:43:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 45001203DA for ; Fri, 3 Apr 2015 12:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752956AbbDCMmM (ORCPT ); Fri, 3 Apr 2015 08:42:12 -0400 Received: from laurent.telenet-ops.be ([195.130.137.89]:43138 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752785AbbDCMmJ (ORCPT ); Fri, 3 Apr 2015 08:42:09 -0400 Received: from ayla.of.borg ([84.193.93.87]) by laurent.telenet-ops.be with bizsmtp id BQi11q00r1t5w8s01Qi106; Fri, 03 Apr 2015 14:42:07 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1Ye0vB-0006AT-JH; Fri, 03 Apr 2015 14:42:01 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1Ye0vH-0006VV-2g; Fri, 03 Apr 2015 14:42:07 +0200 From: Geert Uytterhoeven To: Greg Kroah-Hartman , Magnus Damm , Arnd Bergmann , Simon Horman , Laurent Pinchart , Kuninori Morimoto Cc: Marc Zyngier , devel@driverdev.osuosl.org, linux-sh@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC 5/6] staging: board: Add support for devices with complex dependencies Date: Fri, 3 Apr 2015 14:42:02 +0200 Message-Id: <1428064923-24950-6-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428064923-24950-1-git-send-email-geert+renesas@glider.be> References: <1428064923-24950-1-git-send-email-geert+renesas@glider.be> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for easy registering of one ore more platform devices that may: - need clocks that are described in DT, - need pin control configuration, - rely on a configured GPIO, - be part of a PM Domain. All these dependencies are optional. Signed-off-by: Geert Uytterhoeven --- drivers/staging/board/board.c | 76 +++++++++++++++++++++++++++++++++++++++++++ drivers/staging/board/board.h | 31 ++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/drivers/staging/board/board.c b/drivers/staging/board/board.c index b84ac2837a20bf06..da2469e2d4262fac 100644 --- a/drivers/staging/board/board.c +++ b/drivers/staging/board/board.c @@ -9,6 +9,9 @@ #define pr_fmt(fmt) "board_staging: " fmt +#include +#include +#include #include #include #include @@ -16,6 +19,9 @@ #include #include #include +#include +#include +#include #include "board.h" @@ -104,3 +110,73 @@ void __init board_staging_fixup_irq_resources(struct resource *res, res[i].start = virq; } } + +int __init board_staging_register_clock(const struct board_staging_clk *bsc) +{ + struct clk *clk; + int error; + + pr_debug("Registering clock %s for con_id %s dev_id %s\n", bsc->clk, + bsc->con_id, bsc->dev_id); + clk = clk_get(NULL, bsc->clk); + if (IS_ERR(clk)) { + error = PTR_ERR(clk); + pr_err("Failed to get clock %s (%d)\n", bsc->clk, error); + return error; + } + + error = clk_register_clkdev(clk, bsc->con_id, bsc->dev_id); + if (error) + pr_err("Failed to register clock %s (%d)\n", bsc->clk, error); + return error; + + clk_put(clk); + return 0; +} + +int __init board_staging_register_device(const struct board_staging_dev *dev) +{ + struct platform_device *pdev = dev->pdev; + unsigned int i; + int error; + + pr_debug("Trying to register device %s\n", pdev->name); + if (board_staging_dt_node_available(pdev->resource, + pdev->num_resources)) { + pr_warn("Skipping %s, already in DT\n", pdev->name); + return -EEXIST; + } + + board_staging_fixup_irq_resources(pdev->resource, pdev->num_resources); + + for (i = 0; i < dev->nclocks; i++) + board_staging_register_clock(&dev->clocks[i]); + + if (dev->npinmaps) + pinctrl_register_mappings(dev->pinmaps, dev->npinmaps); + + for (i = 0; i < dev->ngpios; i++) + gpio_request_one(dev->gpios[i].gpio, dev->gpios[i].flags, + pdev->name); + + error = platform_device_register(pdev); + if (error) { + pr_err("Failed to register device %s (%d)\n", pdev->name, + error); + return error; + } + + if (dev->domain) + __pm_genpd_name_add_device(dev->domain, &pdev->dev, NULL); + + return error; +} + +void __init board_staging_register_devices(const struct board_staging_dev *devs, + unsigned int ndevs) +{ + unsigned int i; + + for (i = 0; i < ndevs; i++) + board_staging_register_device(&devs[i]); +} diff --git a/drivers/staging/board/board.h b/drivers/staging/board/board.h index 4cedc3c46e287eb7..7aaa0f7d6fafb9e5 100644 --- a/drivers/staging/board/board.h +++ b/drivers/staging/board/board.h @@ -4,12 +4,43 @@ #include #include +struct board_staging_clk { + const char *clk; + const char *con_id; + const char *dev_id; +}; + +struct board_staging_gpio { + unsigned int gpio; + unsigned long flags; /* See GPIOF_* */ +}; + +struct board_staging_dev { + /* Platform Device */ + struct platform_device *pdev; + /* Clocks (optional) */ + const struct board_staging_clk *clocks; + unsigned int nclocks; + /* Pin Control Maps (optional) */ + const struct pinctrl_map *pinmaps; + unsigned int npinmaps; + /* GPIOs (optional) */ + const struct board_staging_gpio *gpios; + unsigned int ngpios; + /* PM Domain (optional) */ + const char *domain; +}; + struct resource; bool board_staging_dt_node_available(const struct resource *resource, unsigned int num_resources); int board_staging_setup_hwirq_xlate(const char *irqc_match, unsigned int base); void board_staging_fixup_irq_resources(struct resource *res, unsigned int nres); +int board_staging_register_clock(const struct board_staging_clk *bsc); +int board_staging_register_device(const struct board_staging_dev *dev); +void board_staging_register_devices(const struct board_staging_dev *devs, + unsigned int ndevs); #define board_staging(str, fn) \ static int __init runtime_board_check(void) \