pwm: Add PWM framework support
[linux-2.6-block.git] / Documentation / pwm.txt
CommitLineData
0c2498f1
SH
1Pulse Width Modulation (PWM) interface
2
3This provides an overview about the Linux PWM interface
4
5PWMs are commonly used for controlling LEDs, fans or vibrators in
6cell phones. PWMs with a fixed purpose have no need implementing
7the Linux PWM API (although they could). However, PWMs are often
8found as discrete devices on SoCs which have no fixed purpose. It's
9up to the board designer to connect them to LEDs or fans. To provide
10this kind of flexibility the generic PWM API exists.
11
12Identifying PWMs
13----------------
14
15Users of the legacy PWM API use unique IDs to refer to PWM devices. One
16goal of the new PWM framework is to get rid of this global namespace.
17
18Using PWMs
19----------
20
21A PWM can be requested using pwm_request() and freed after usage with
22pwm_free(). After being requested a PWM has to be configured using
23
24int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);
25
26To start/stop toggling the PWM output use pwm_enable()/pwm_disable().
27
28Implementing a PWM driver
29-------------------------
30
31Currently there are two ways to implement pwm drivers. Traditionally
32there only has been the barebone API meaning that each driver has
33to implement the pwm_*() functions itself. This means that it's impossible
34to have multiple PWM drivers in the system. For this reason it's mandatory
35for new drivers to use the generic PWM framework.
36A new PWM device can be added using pwmchip_add() and removed again with
37pwmchip_remove(). pwmchip_add() takes a filled in struct pwm_chip as
38argument which provides the ops and the pwm id to the framework.
39
40Locking
41-------
42
43The PWM core list manipulations are protected by a mutex, so pwm_request()
44and pwm_free() may not be called from an atomic context. Currently the
45PWM core does not enforce any locking to pwm_enable(), pwm_disable() and
46pwm_config(), so the calling context is currently driver specific. This
47is an issue derived from the former barebone API and should be fixed soon.
48
49Helpers
50-------
51
52Currently a PWM can only be configured with period_ns and duty_ns. For several
53use cases freq_hz and duty_percent might be better. Instead of calculating
54this in your driver please consider adding appropriate helpers to the framework.