linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: thierry.reding@gmail.com (Thierry Reding)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 08/15] pwm: Add new pwm-samsung driver
Date: Wed, 19 Jun 2013 00:17:06 +0200	[thread overview]
Message-ID: <20130618221705.GC1926@mithrandir> (raw)
In-Reply-To: <1920640.1A218CWh3x@flatron>

On Mon, Jun 17, 2013 at 10:50:40PM +0200, Tomasz Figa wrote:
> On Monday 17 of June 2013 22:29:11 Thierry Reding wrote:
> > On Wed, Jun 05, 2013 at 11:18:13PM +0200, Tomasz Figa wrote:
[...]
> > > +#ifndef CONFIG_CLKSRC_SAMSUNG_PWM
> > > +static DEFINE_SPINLOCK(samsung_pwm_lock);
> > > +#endif
> > 
> > Why is this lock global? Shouldn't it more correctly be part of
> > samsung_pwm_chip?
> 
> There are few registers shared with samsung_pwm_timer clocksource driver 
> and so normally the spinlock is exported from it. However on on some 
> platforms (namely Exynos >=4x12) kernel can be compiled without that 
> driver, so the lock must be defined locally, just to synchronize multiple 
> PWM channels, as they share registers as well.

Okay, I think this needs further explanation. The clocksource driver is
used for what exactly? From a quick look it seems to be very much PWM-
specific. According to the device tree binding for the PWM driver, the
timer blocks can also be used as clock sources and clock event timers.
So if I understand correctly you have setups where you use one or more
channels as clock source or clock event timer and one or more channels
as PWM outputs.

In that case it's a very bad idea to use a global lock to synchronize
accesses. You need to do much more than that. To properly split this
across several drivers there needs to be a mechanism to allocate
channels for use either as clock source/event timer or PWM. Otherwise,
how do you know that drivers aren't stepping on each other's toes?

> > > +		ret = pwm_samsung_parse_dt(chip);
> > > +		if (ret)
> > > +			return ret;
> > > +
> > > +		chip->chip.of_xlate = of_pwm_xlate_with_flags;
> > > +		chip->chip.of_pwm_n_cells = 3;
> > > +	} else {
> > > +		if (!pdev->dev.platform_data) {
> > > +			dev_err(&pdev->dev, "no platform data 
> specified\n");
> > > +			return -EINVAL;
> > > +		}
> > > +
> > > +		memcpy(&chip->variant, pdev->dev.platform_data,
> > > +							sizeof(chip-
> >variant));
> > > +	}
> > 
> > Obviously this needs some modification in order for the variant to
> > become constant. But I think you can easily do so by making the driver
> > match using the platform_driver's id_table field, similar to how the
> > matching is done for OF.
> 
> Generally output_mask is board-dependent and is passed inside a variant 
> struct using platform_data pointer.

That's okay. But output_mask is the only thing that's board-dependent.
Everything else in the variant is SoC dependent judging by the OF device
table. So really only the output_mask should be part of the platform
data.

> Same platform data is used in samsung_pwm_timer clocksource driver, so I 
> just reused it here without adding the need to rename platform device at 
> runtime (see arch/arm/plat-samsung/devs.c).

Looking a bit at git log for the clocksource driver, there's this
commit:

	a3ce54f clocksource: samsung_pwm_timer: Do not request PWM mem region

That's an ugly workaround for sharing registers between two drivers.
There's a reason why drivers do request_mem_region(), and it is
precisely to prevent them from accessing the same registers. As I
already said above, I think you need to come up with some sort of API to
share resources between the drivers.

There was a similar issue a few months back with the pwm-tiehrpwm and
pwm-tiecap drivers, which use a shared block of registers. Initially
something similar was done as you do here, but eventually we came up
with a much better solution that involved introducing a new driver for
the shared functionality and an exported API.

The situation seems to be somewhat different here since you actually
share the same resources for different functionality instead of sharing
one subset of register across multiple drivers, but I think a similar
solution can be applied here.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130619/a85e8a07/attachment-0001.sig>

  reply	other threads:[~2013-06-18 22:17 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-05 21:18 [PATCH 00/15] Final Samsung PWM support cleanup Tomasz Figa
2013-06-05 21:18 ` [PATCH 01/15] ARM: SAMSUNG: Unify base address definitions of timer block Tomasz Figa
2013-06-05 21:18 ` [PATCH 02/15] ARM: SAMSUNG: Add new PWM platform device Tomasz Figa
2013-06-05 21:18 ` [PATCH 03/15] ARM: SAMSUNG: Set PWM platform data Tomasz Figa
2013-06-05 21:18 ` [PATCH 04/15] ARM: SAMSUNG: Move all platforms to new clocksource driver Tomasz Figa
2013-06-05 21:18 ` [PATCH 05/15] ARM: SAMSUNG: Remove old samsung-time driver Tomasz Figa
2013-06-05 21:18 ` [PATCH 06/15] ARM: SAMSUNG: Remove unused PWM timer IRQ chip code Tomasz Figa
2013-06-05 21:18 ` [PATCH 07/15] pwm: samsung: Rename to pwm-samsung-legacy Tomasz Figa
2013-06-05 21:18 ` [PATCH 08/15] pwm: Add new pwm-samsung driver Tomasz Figa
2013-06-13 20:14   ` Heiko Stübner
2013-06-13 20:18     ` Tomasz Figa
2013-06-16 17:19   ` Tomasz Figa
2013-06-16 20:45     ` Kukjin Kim
2013-06-17 20:29   ` Thierry Reding
2013-06-17 20:50     ` Tomasz Figa
2013-06-18 22:17       ` Thierry Reding [this message]
2013-06-18 22:45         ` Tomasz Figa
2013-06-19  9:43           ` Thierry Reding
2013-06-19 10:23             ` Tomasz Figa
2013-06-24 17:52               ` Tomasz Figa
2013-06-24 19:50                 ` Thierry Reding
2013-06-24 20:03                   ` Tomasz Figa
2013-06-24 20:28                     ` Thierry Reding
2013-06-24 20:55                     ` Arnd Bergmann
2013-06-18 17:59     ` Tomasz Figa
2013-06-18 18:06       ` Kukjin Kim
2013-06-18 18:13         ` Tomasz Figa
2013-06-18 21:33           ` Thierry Reding
2013-06-18 21:35             ` Tomasz Figa
2013-06-18 19:41     ` Tomasz Figa
2013-06-18 21:40       ` Thierry Reding
2013-06-18 21:42         ` Tomasz Figa
2013-06-18 22:20           ` Thierry Reding
2013-06-05 21:18 ` [PATCH 09/15] ARM: SAMSUNG: Rework private data handling in dev-backlight Tomasz Figa
2013-06-05 21:18 ` [PATCH 10/15] ARM: SAMSUNG: Modify board files to use new PWM platform device Tomasz Figa
2013-06-05 21:18 ` [PATCH 11/15] pwm: Remove superseded pwm-samsung-legacy driver Tomasz Figa
2013-06-05 21:18 ` [PATCH 12/15] ARM: SAMSUNG: Remove old PWM timer platform devices Tomasz Figa
2013-06-05 21:18 ` [PATCH 13/15] ARM: SAMSUNG: Remove pwm-clock infrastructure Tomasz Figa
2013-06-05 21:18 ` [PATCH 14/15] ARM: SAMSUNG: Remove remaining uses of plat/regs-timer.h header Tomasz Figa
2013-06-13 20:24   ` Heiko Stübner
2013-06-13 20:38     ` Tomasz Figa
2013-06-05 21:18 ` [PATCH 15/15] ARM: SAMSUNG: Remove " Tomasz Figa
2013-06-12 21:48 ` [PATCH 00/15] Final Samsung PWM support cleanup Tomasz Figa
2013-06-12 23:00   ` Olof Johansson
2013-06-12 23:13     ` Tomasz Figa
2013-06-12 23:38       ` Heiko Stübner
2013-06-12 23:52         ` Sylwester Nawrocki
2013-06-13  9:07           ` Tomasz Figa
2013-06-13 20:17             ` Heiko Stübner
2013-06-13 22:27               ` Heiko Stübner
2013-06-13  0:25     ` Kukjin Kim

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=20130618221705.GC1926@mithrandir \
    --to=thierry.reding@gmail.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).