[PATCH 1/2] PWM: add pwm framework support

Arnd Bergmann arnd at arndb.de
Tue Jun 28 13:03:05 EDT 2011

On Tuesday 28 June 2011, Sascha Hauer wrote:
> > How about using idr? It provides you a fast lookup and handles giving
> > out unique numbers.
> Sounds like a good idea, but is idr compatible with the pwmchip_reserve
> function below? idr gives no guarantee that the first id is zero, but I
> need exactly this to make the ids for the internal PWMs known at compile
> time.

You can certainly use ida_get_new_above to guarantee that implicit
number allocation doesn't interfere with the reserved numbers. Whether
that guarantees that you get the reserved numbers when you ask for them,
I don't know.

A possible way to deal with that would be to allocate an array of pointers
for the reserved space but use IDR for the rest, but at that point the
complexity is probably higher than what you have now ;-)

Another question is whether the dynamic allocation even makes sense. How
does a driver that wants to use a PWM find out what number to ask for
when it's not reserved for the platform to start with. Maybe the
answer is to just use an array or tree for the lookup and refuse to
register multiple PWMs to the same number.


More information about the linux-arm-kernel mailing list