From: Thierry Reding <thierry.reding@avionic-design.de>
To: "Philip, Avinash" <avinashphilip@ti.com>
Cc: grant.likely@secretlab.ca, rob.herring@calxeda.com,
rob@landley.net, linux-kernel@vger.kernel.org,
devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org,
nsekhar@ti.com, gururaja.hebbar@ti.com
Subject: Re: [PATCH 1/2] pwm: pwm-tiecap: Add device-tree binding support for APWM driver
Date: Tue, 2 Oct 2012 08:00:14 +0200 [thread overview]
Message-ID: <20121002060014.GA4298@avionic-0098.mockup.avionic-design.de> (raw)
In-Reply-To: <1348658863-29428-2-git-send-email-avinashphilip@ti.com>
[-- Attachment #1: Type: text/plain, Size: 5129 bytes --]
On Wed, Sep 26, 2012 at 04:57:42PM +0530, Philip, Avinash wrote:
[...]
> +#include <linux/platform_data/ti-pwmss.h>
[...]
> +static struct pwmss_platform_data am33xx_data = {
> + .has_configspace = true,
> +};
This structure is defined in a public header. I don't see why it has to,
given that it's only used to associate some data with an of_device_id
entry below. Since AM33xx never had anything but OF support in the
mainline kernel I don't think we should add platform data.
> +#ifdef CONFIG_OF
> +static const struct of_device_id ecap_of_match[] = {
> + {
> + .compatible = "ti,am33xx-ecap",
> + .data = &am33xx_data,
> + },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, ecap_of_match);
> +#endif
> +
I don't quite see why we need to pass this platform data to the device
at all since there is no other variant anyway. I think this should only
be added if this turns out to be required at some point.
> static int __devinit ecap_pwm_probe(struct platform_device *pdev)
> {
> int ret;
> struct resource *r;
> struct clk *clk;
> struct ecap_pwm_chip *pc;
> + struct pwmss_platform_data *pdata = pdev->dev.platform_data;
> + const struct of_device_id *match;
> + u16 regval;
> + struct pinctrl *pinctrl;
> +
> + match = of_match_device(of_match_ptr(ecap_of_match), &pdev->dev);
I've never seen of_match_ptr() used this way. Maybe you should think
about not #ifdef'ing OF specific code at all. That way ecap_of_match
will always exist and you could use the IS_ENABLED() macro to
conditionalize at compile time. The compiler will probably be clever
enough to optimize the ecap_of_match away if OF is not enabled.
Given my comment earlier, since AM33xx is OF only you might just as well
add a depends on OF to this driver and things will become a lot easier.
> +
> + if (match)
> + pdata = (struct pwmss_platform_data *)match->data;
> +
> + pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
> + if (IS_ERR(pinctrl))
> + dev_warn(&pdev->dev, "failed to configure pins from driver\n");
>
> pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
> if (!pc) {
> @@ -211,6 +268,8 @@ static int __devinit ecap_pwm_probe(struct platform_device *pdev)
>
> pc->chip.dev = &pdev->dev;
> pc->chip.ops = &ecap_pwm_ops;
> + pc->chip.of_xlate = of_ecap_xlate;
> + pc->chip.of_pwm_n_cells = PWM_CELL_SIZE;
> pc->chip.base = -1;
> pc->chip.npwm = 1;
>
> @@ -231,13 +290,56 @@ static int __devinit ecap_pwm_probe(struct platform_device *pdev)
> }
>
> pm_runtime_enable(&pdev->dev);
> +
> + /*
> + * Some platform has extra PWM-subsystem common config space
> + * and requires special handling of clock gating.
> + */
> + if (pdata && pdata->has_configspace) {
> + r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> + if (!r) {
> + dev_err(&pdev->dev, "no memory resource defined\n");
> + ret = -ENODEV;
> + goto err_disable_clock;
> + }
> +
> + pc->config_base = devm_ioremap(&pdev->dev, r->start,
> + resource_size(r));
> + if (!pc->config_base) {
> + dev_err(&pdev->dev, "failed to ioremap() registers\n");
> + ret = -EADDRNOTAVAIL;
> + goto err_disable_clock;
> + }
Isn't this missing a request_mem_region()? I assume you don't do that
here because you need the same region in the EHRPWM driver, right? This
should be indication enough that the design is not right here. I think
we need a proper abstraction here. Can this not be done via PM runtime
support? If not, maybe this should be represented by clock objects since
the bit obviously enables a clock.
> +
> + /* Enable ECAP clock gating at PWM-subsystem common config */
> + pm_runtime_get_sync(&pdev->dev);
> + regval = readw(pc->config_base + PWMSS_CLKCONFIG);
> + regval |= PWMSS_ECAP_CLK_EN;
> + writew(regval, pc->config_base + PWMSS_CLKCONFIG);
> + pm_runtime_put_sync(&pdev->dev);
> + }
> +
> platform_set_drvdata(pdev, pc);
> return 0;
> +
> +err_disable_clock:
> + pm_runtime_disable(&pdev->dev);
> + return ret;
> }
>
> static int __devexit ecap_pwm_remove(struct platform_device *pdev)
> {
> struct ecap_pwm_chip *pc = platform_get_drvdata(pdev);
> + u16 regval;
> +
> + if (pc->config_base) {
> + /* Disable ECAP clock gating at PWM-subsystem common config */
> + pm_runtime_get_sync(&pdev->dev);
> + regval = readw(pc->config_base + PWMSS_CLKCONFIG);
> + regval &= ~PWMSS_ECAP_CLK_EN;
> + writew(regval, pc->config_base + PWMSS_CLKCONFIG);
> + pm_runtime_put_sync(&pdev->dev);
> + }
>
> pm_runtime_put_sync(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
> @@ -247,6 +349,9 @@ static int __devexit ecap_pwm_remove(struct platform_device *pdev)
> static struct platform_driver ecap_pwm_driver = {
> .driver = {
> .name = "ecap",
> +#ifdef CONFIG_OF
> + .of_match_table = of_match_ptr(ecap_of_match),
> +#endif
If you use of_match_ptr() you don't need the additional #ifdef
CONFIG_OF. But as I already said I don't think you need this at all
anyway. You should really just depend on OF and be done with it.
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-10-02 6:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 11:27 [PATCH 0/2] DT binding support for ECAP & EHRPWM driver Philip, Avinash
2012-09-26 11:27 ` [PATCH 1/2] pwm: pwm-tiecap: Add device-tree binding support for APWM driver Philip, Avinash
2012-10-02 6:00 ` Thierry Reding [this message]
2012-10-02 7:16 ` Sekhar Nori
2012-10-02 8:07 ` Thierry Reding
2012-10-02 8:27 ` Sekhar Nori
2012-10-08 13:31 ` Philip, Avinash
2012-10-08 13:39 ` Thierry Reding
2012-10-09 12:36 ` Philip, Avinash
2012-10-09 12:48 ` Thierry Reding
2012-09-26 11:27 ` [PATCH 2/2] pwm: pwm-tiehrpwm: Add device-tree binding support for EHRPWM driver Philip, Avinash
2012-10-02 6:11 ` Thierry Reding
2012-10-08 13:31 ` Philip, Avinash
2012-10-08 13:50 ` Thierry Reding
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=20121002060014.GA4298@avionic-0098.mockup.avionic-design.de \
--to=thierry.reding@avionic-design.de \
--cc=avinashphilip@ti.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@secretlab.ca \
--cc=gururaja.hebbar@ti.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nsekhar@ti.com \
--cc=rob.herring@calxeda.com \
--cc=rob@landley.net \
/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