From: Thierry Reding <thierry.reding@avionic-design.de>
To: guanxuetao@mprc.pku.edu.cn
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>,
Mike Turquette <mturquette@linaro.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] unicore32: pwm: Properly remap memory-mapped registers
Date: Fri, 7 Sep 2012 14:50:35 +0200 [thread overview]
Message-ID: <20120907125035.GA29340@avionic-0098.mockup.avionic-design.de> (raw)
In-Reply-To: <63235.162.105.203.8.1346920695.squirrel@mprc.pku.edu.cn>
[-- Attachment #1: Type: text/plain, Size: 3203 bytes --]
On Thu, Sep 06, 2012 at 04:38:15PM +0800, guanxuetao@mprc.pku.edu.cn wrote:
> > Instead of writing to the timer controller registers by dereferencing a
> > pointer to the memory location, properly remap the memory region with a
> > call to ioremap_nocache() and access the registers using writel().
> >
> > Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
> > ---
> > arch/unicore32/kernel/pwm.c | 25 ++++++++++++++++++++++---
> > 1 file changed, 22 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/unicore32/kernel/pwm.c b/arch/unicore32/kernel/pwm.c
> > index 4615d51..410b786 100644
> > --- a/arch/unicore32/kernel/pwm.c
> > +++ b/arch/unicore32/kernel/pwm.c
> > @@ -23,10 +23,16 @@
> > #include <asm/div64.h>
> > #include <mach/hardware.h>
> >
> > +#define PWCR 0x00
> > +#define DCCR 0x04
> > +#define PCR 0x08
> I think old register names could be used here by some small modifications.
> Please see arch/unicore32/include/mach/regs-ost.h
> We can avoid ioremap and use writel/readl directly on these registers.
>
> Guan
The whole point of this patch was to make the PWM driver behave more
like other drivers. If the registers are addressed directly, there is no
way that the driver will work for a second instance of the PWM
controller. I know that there probably is no second instance right now,
but given that pretty much every regular driver accesses its register
through the ioremap()'ed addresses and this patch doesn't go through
hoops to achieve this, I think this is a perfectly valid cleanup.
Thierry
> > +
> > struct pwm_device {
> > struct list_head node;
> > struct platform_device *pdev;
> >
> > + void __iomem *base;
> > +
> > const char *label;
> > struct clk *clk;
> > int clk_enabled;
> > @@ -69,9 +75,11 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int
> > period_ns)
> > * before writing to the registers
> > */
> > clk_enable(pwm->clk);
> > - OST_PWMPWCR = prescale;
> > - OST_PWMDCCR = pv - dc;
> > - OST_PWMPCR = pv;
> > +
> > + writel(prescale, pwm->base + PWCR);
> > + writel(pv - dc, pwm->base + DCCR);
> > + writel(pv, pwm->base + PCR);
> > +
> > clk_disable(pwm->clk);
> >
> > return 0;
> > @@ -190,10 +198,19 @@ static struct pwm_device *pwm_probe(struct
> > platform_device *pdev,
> > goto err_free_clk;
> > }
> >
> > + pwm->base = ioremap_nocache(r->start, resource_size(r));
> > + if (pwm->base == NULL) {
> > + dev_err(&pdev->dev, "failed to remap memory resource\n");
> > + ret = -EADDRNOTAVAIL;
> > + goto err_release_mem;
> > + }
> > +
> > __add_pwm(pwm);
> > platform_set_drvdata(pdev, pwm);
> > return pwm;
> >
> > +err_release_mem:
> > + release_mem_region(r->start, resource_size(r));
> > err_free_clk:
> > clk_put(pwm->clk);
> > err_free:
> > @@ -224,6 +241,8 @@ static int __devexit pwm_remove(struct platform_device
> > *pdev)
> > list_del(&pwm->node);
> > mutex_unlock(&pwm_lock);
> >
> > + iounmap(pwm->base);
> > +
> > r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > release_mem_region(r->start, resource_size(r));
> >
> > --
> > 1.7.12
> >
>
>
>
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-09-07 12:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-02 10:21 [PATCH 0/6] unicore32: Move PWM driver to PWM framework Thierry Reding
2012-09-02 10:21 ` [PATCH 1/6] unicore32: pwm: Properly remap memory-mapped registers Thierry Reding
2012-09-06 8:38 ` guanxuetao
2012-09-07 12:50 ` Thierry Reding [this message]
2012-09-02 10:21 ` [PATCH 2/6] unicore32: pwm: Use module_platform_driver() Thierry Reding
2012-09-02 10:21 ` [PATCH 3/6] unicore32: pwm: Remove unnecessary indirection Thierry Reding
2012-09-02 10:21 ` [PATCH 4/6] unicore32: Add common clock support Thierry Reding
2012-09-06 8:42 ` guanxuetao
2012-09-07 12:53 ` Thierry Reding
2012-09-08 1:22 ` Mike Turquette
2012-09-02 10:21 ` [PATCH 5/6] unicore32: pwm: Use managed resource allocations Thierry Reding
2012-09-02 10:21 ` [PATCH 6/6] pwm: Move PUV3 PWM driver to PWM framework 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=20120907125035.GA29340@avionic-0098.mockup.avionic-design.de \
--to=thierry.reding@avionic-design.de \
--cc=guanxuetao@mprc.pku.edu.cn \
--cc=gxt@mprc.pku.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@linaro.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
Powered by JetHome