linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH/RFC 5/6] staging: board: Add support for devices with complex dependencies
Date: Sat, 04 Apr 2015 12:46:52 +0000	[thread overview]
Message-ID: <34835209.cQQp4PEGGk@avalon> (raw)
In-Reply-To: <1428064923-24950-6-git-send-email-geert+renesas@glider.be>

Hi Geert,

Thank you for the patch.

On Friday 03 April 2015 14:42:02 Geert Uytterhoeven wrote:
> 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 <geert+renesas@glider.be>
> ---
>  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 <linux/clk.h>
> +#include <linux/clkdev.h>
> +#include <linux/gpio.h>
>  #include <linux/init.h>
>  #include <linux/irq.h>
>  #include <linux/device.h>
> @@ -16,6 +19,9 @@
>  #include <linux/of.h>
>  #include <linux/of_address.h>
>  #include <linux/of_irq.h>
> +#include <linux/pinctrl/machine.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm_domain.h>
> 
>  #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);

Aren't GPIO numbers dynamic too in DT-based systems ? Beside, shouldn't it be 
the responsibility of the drievr to request the GPIOs it needs ?

> +	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 <linux/init.h>
>  #include <linux/of.h>
> 
> +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)	\

-- 
Regards,

Laurent Pinchart


  parent reply	other threads:[~2015-04-04 12:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-03 12:41 [PATCH/RFC 0/6] staging: board: armadillo800eva: Board staging for sh_mobile_lcdc_fb Geert Uytterhoeven
2015-04-03 12:41 ` [PATCH 1/6] Revert "staging: board: disable as it breaks the build" Geert Uytterhoeven
2015-04-06  0:40   ` Simon Horman
2015-04-07 13:16     ` Geert Uytterhoeven
2015-04-08  0:44       ` Simon Horman
2015-04-03 12:41 ` [PATCH/RFC 2/6] staging: board: Initialize staging board code earlier Geert Uytterhoeven
2015-04-03 12:42 ` [PATCH/RFC 3/6] staging: board: Add support for translating hwirq to virq numbers Geert Uytterhoeven
2015-04-06 10:45   ` Marc Zyngier
2015-04-03 12:42 ` [PATCH/RFC 4/6] staging: board: kzm9d: Translate hwirq numbers " Geert Uytterhoeven
2015-04-03 12:42 ` [PATCH/RFC 5/6] staging: board: Add support for devices with complex dependencies Geert Uytterhoeven
2015-04-03 12:57   ` Dan Carpenter
2015-04-03 13:27     ` Geert Uytterhoeven
2015-04-03 17:07       ` Russell King - ARM Linux
2015-04-03 17:04     ` Russell King - ARM Linux
2015-04-05  8:55       ` Geert Uytterhoeven
2015-04-04 12:46   ` Laurent Pinchart [this message]
2015-04-05  9:00     ` Geert Uytterhoeven
2015-04-05 20:06       ` Laurent Pinchart
2015-04-03 12:42 ` [PATCH/RFC 6/6] staging: board: armadillo800eva: Board staging for sh_mobile_lcdc_fb Geert Uytterhoeven
2015-04-03 16:24 ` [PATCH/RFC 0/6] " Laurent Pinchart
2015-04-03 19:35   ` Geert Uytterhoeven
2015-04-06 10:23 ` [PATCH/RFC 0/6] staging: board: armadillo800eva: Board staging for =?UTF-8?Q?sh=5Fmobile=5Flcdc Marc Zyngier

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=34835209.cQQp4PEGGk@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.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).