Parallel Port Devices
Parallel Port Devices #
parport_register_driver() #
register a parallel port device driver
Parameters
driver: structure describing the driver
Description
This can be called by a parallel port device driver in order to receive notifications about ports being found in the system, as well as ports no longer available.
The driver structure is allocated by the caller and must not be
deallocated until after calling parport_unregister_driver().
If using the non device model:
The driver's attach() function may block. The port that
attach() is given will be valid for the duration of the
callback, but if the driver wants to take a copy of the
pointer it must call parport_get_port() to do so. Calling
parport_register_device() on that port will do this for you.
The driver's detach() function may block. The port that
detach() is given will be valid for the duration of the
callback, but if the driver wants to take a copy of the
pointer it must call parport_get_port() to do so.
Returns 0 on success. The non device model will always succeeds. but the new device model can fail and will return the error code.
module_parport_driver() #
Helper macro for registering a modular parport driver
Parameters
__parport_driver: struct parport_driver to be used
Description
Helper macro for parport drivers which do not do anything special in module
init and exit. This eliminates a lot of boilerplate. Each module may only
use this macro once, and calling it replaces module_init() and module_exit().
parport_yield() #
int relinquish a parallel port temporarily
Parameters
struct pardevice *dev: a device on the parallel port
Description
This function relinquishes the port if it would be helpful to other
drivers to do so. Afterwards it tries to reclaim the port using
parport_claim(), and the return value is the same as for
parport_claim(). If it fails, the port is left unclaimed and it is
the driver's responsibility to reclaim the port.
The parport_yield() and parport_yield_blocking() functions are for
marking points in the driver at which other drivers may claim the
port and use their devices. Yielding the port is similar to
releasing it and reclaiming it, but is more efficient because no
action is taken if there are no other devices needing the port. In
fact, nothing is done even if there are other devices waiting but
the current device is still within its "timeslice". The default
timeslice is half a second, but it can be adjusted via the /proc
interface.
parport_yield_blocking() #
int relinquish a parallel port temporarily
Parameters
struct pardevice *dev: a device on the parallel port
Description
This function relinquishes the port if it would be helpful to other
drivers to do so. Afterwards it tries to reclaim the port using
parport_claim_or_block(), and the return value is the same as for
parport_claim_or_block().
parport_wait_event() #
int wait for an event on a parallel port
Parameters
struct parport *port: port to wait onsigned long timeout: time to wait (in jiffies)
Description
This function waits for up to timeout jiffies for an interrupt to occur on a parallel port. If the port timeout is set to zero, it returns immediately.
If an interrupt occurs before the timeout period elapses, this function returns zero immediately. If it times out, it returns one. An error code less than zero indicates an error (most likely a pending signal), and the calling code should finish what it's doing as soon as it can.
parport_wait_peripheral() #
int wait for status lines to change in 35ms
Parameters
struct parport *port: port to watchunsigned char mask: status lines to watchunsigned char result: desired values of chosen status lines
Description
This function waits until the masked status lines have the
desired values, or until 35ms have elapsed (see IEEE 1284-1994
page 24 to 25 for why this value in particular is hardcoded).
The mask and result parameters are bitmasks, with the bits
defined by the constants in parport.h: PARPORT_STATUS_BUSY,
and so on.
The port is polled quickly to start off with, in anticipation
of a fast response from the peripheral. This fast polling
time is configurable (using /proc), and defaults to 500usec.
If the timeout for this port (see parport_set_timeout()) is
zero, the fast polling time is 35ms, and this function does
not call schedule().
If the timeout for this port is non-zero, after the fast
polling fails it uses parport_wait_event() to wait for up to
10ms, waking up if an interrupt occurs.
parport_negotiate() #
int negotiate an IEEE 1284 mode
Parameters
struct parport *port: port to useint mode: mode to negotiate to
Description
Use this to negotiate to a particular IEEE 1284 transfer mode.
The mode parameter should be one of the constants in
parport.h starting IEEE1284_MODE_xxx.
The return value is 0 if the peripheral has accepted the negotiation to the mode specified, -1 if the peripheral is not IEEE 1284 compliant (or not present), or 1 if the peripheral has rejected the negotiation.
parport_write() #
ssize_t write a block of data to a parallel port
Parameters
struct parport *port: port to write toconst void *buffer: data buffer (in kernel space)size_t len: number of bytes of data to transfer
Description
This will write up to len bytes of buffer to the port
specified, using the IEEE 1284 transfer mode most recently
negotiated to (using parport_negotiate()), as long as that
mode supports forward transfers (host to peripheral).
It is the caller's responsibility to ensure that the first len bytes of buffer are valid.
This function returns the number of bytes transferred (if zero or positive), or else an error code.
parport_read() #
ssize_t read a block of data from a parallel port
Parameters
struct parport *port: port to read fromvoid *buffer: data buffer (in kernel space)size_t len: number of bytes of data to transfer
Description
This will read up to len bytes of buffer to the port
specified, using the IEEE 1284 transfer mode most recently
negotiated to (using parport_negotiate()), as long as that
mode supports reverse transfers (peripheral to host).
It is the caller's responsibility to ensure that the first len bytes of buffer are available to write to.
This function returns the number of bytes transferred (if zero or positive), or else an error code.
parport_set_timeout() #
long set the inactivity timeout for a device
Parameters
struct pardevice *dev: device on a portlong inactivity: inactivity timeout (in jiffies)
Description
This sets the inactivity timeout for a particular device on a
port. This affects functions like parport_wait_peripheral().
The special value 0 means not to call schedule() while dealing
with this device.
The return value is the previous inactivity timeout.
Any callers of parport_wait_event() for this device are woken
up.
__parport_register_driver() #
int register a parallel port device driver
Parameters
struct parport_driver *drv: structure describing the driverstruct module *owner: owner module of drvconst char *mod_name: module name string
Description
This can be called by a parallel port device driver in order to receive notifications about ports being found in the system, as well as ports no longer available.
If devmodel is true then the new device model is used for registration.
The drv structure is allocated by the caller and must not be
deallocated until after calling parport_unregister_driver().
If using the non device model:
The driver's attach() function may block. The port that
attach() is given will be valid for the duration of the
callback, but if the driver wants to take a copy of the
pointer it must call parport_get_port() to do so. Calling
parport_register_device() on that port will do this for you.
The driver's detach() function may block. The port that
detach() is given will be valid for the duration of the
callback, but if the driver wants to take a copy of the
pointer it must call parport_get_port() to do so.
Returns 0 on success. The non device model will always succeeds. but the new device model can fail and will return the error code.
parport_unregister_driver() #
void deregister a parallel port device driver
Parameters
struct parport_driver *drv: structure describing the driver that was given toparport_register_driver()
Description
This should be called by a parallel port device driver that
has registered itself using parport_register_driver() when it
is about to be unloaded.
When it returns, the driver's attach() routine will no longer
be called, and for each port that attach() was called for, the
detach() routine will have been called.
All the driver's attach() and detach() calls are guaranteed to have
finished by the time this function returns.
parport_get_port() #
struct parport * increment a port's reference count
Parameters
struct parport *port: the port
Description
This ensures that a struct parport pointer remains valid
until the matching parport_put_port() call.
parport_put_port() #
void decrement a port's reference count
Parameters
struct parport *port: the port
Description
This should be called once for each call to parport_get_port(),
once the port is no longer needed. When the reference count reaches
zero (port is no longer used), free_port is called.
parport_register_port() #
struct parport * register a parallel port
Parameters
unsigned long base: base I/O addressint irq: IRQ lineint dma: DMA channelstruct parport_operations *ops: pointer to the port driver's port operations structure
Description
When a parallel port (lowlevel) driver finds a port that
should be made available to parallel port device drivers, it
should call parport_register_port(). The base, irq, and
dma parameters are for the convenience of port drivers, and
for ports where they aren't meaningful needn't be set to
anything special. They can be altered afterwards by adjusting
the relevant members of the parport structure that is returned
and represents the port. They should not be tampered with
after calling parport_announce_port, however.
If there are parallel port device drivers in the system that
have registered themselves using parport_register_driver(),
they are not told about the port at this time; that is done by
parport_announce_port().
The ops structure is allocated by the caller, and must not be
deallocated before calling parport_remove_port().
If there is no memory to allocate a new parport structure,
this function will return NULL.
parport_announce_port() #
void tell device drivers about a parallel port
Parameters
struct parport *port: parallel port to announce
Description
After a port driver has registered a parallel port with
parport_register_port, and performed any necessary
initialisation or adjustments, it should call
parport_announce_port() in order to notify all device drivers
that have called parport_register_driver(). Their attach()
functions will be called, with port as the parameter.
parport_remove_port() #
void deregister a parallel port
Parameters
struct parport *port: parallel port to deregister
Description
When a parallel port driver is forcibly unloaded, or a parallel port becomes inaccessible, the port driver must call this function in order to deal with device drivers that still want to use it.
The parport structure associated with the port has its operations structure replaced with one containing 'null' operations that return errors or just don't do anything.
Any drivers that have registered themselves using
parport_register_driver() are notified that the port is no
longer accessible by having their detach() routines called
with port as the parameter.
parport_register_dev_model() #
struct pardevice * register a device on a parallel port
Parameters
struct parport *port: port to which the device is attachedconst char *name: a name to refer to the deviceconst struct pardev_cb *par_dev_cb: struct containing callbacksint id: device number to be given to the device
Description
This function, called by parallel port device drivers, declares that a device is connected to a port, and tells the system all it needs to know.
The struct pardev_cb contains pointer to callbacks. preemption
callback function, preempt, is called when this device driver
has claimed access to the port but another device driver wants
to use it. It is given, private, as its parameter, and should
return zero if it is willing for the system to release the port
to another driver on its behalf. If it wants to keep control of
the port it should return non-zero, and no action will be taken.
It is good manners for the driver to try to release the port at
the earliest opportunity after its preemption callback rejects a
preemption attempt. Note that if a preemption callback is happy
for preemption to go ahead, there is no need to release the
port; it is done automatically. This function may not block, as
it may be called from interrupt context. If the device driver
does not support preemption, preempt can be NULL.
The wake-up ("kick") callback function, wakeup, is called when
the port is available to be claimed for exclusive access; that
is, parport_claim() is guaranteed to succeed when called from
inside the wake-up callback function. If the driver wants to
claim the port it should do so; otherwise, it need not take
any action. This function may not block, as it may be called
from interrupt context. If the device driver does not want to
be explicitly invited to claim the port in this way, wakeup can
be NULL.
The interrupt handler, irq_func, is called when an interrupt
arrives from the parallel port. Note that if a device driver
wants to use interrupts it should use parport_enable_irq(),
and can also check the irq member of the parport structure
representing the port.
The parallel port (lowlevel) driver is the one that has called
request_irq() and whose interrupt handler is called first.
This handler does whatever needs to be done to the hardware to
acknowledge the interrupt (for PC-style ports there is nothing
special to be done). It then tells the IEEE 1284 code about
the interrupt, which may involve reacting to an IEEE 1284
event depending on the current IEEE 1284 phase. After this,
it calls irq_func. Needless to say, irq_func will be called
from interrupt context, and may not block.
The PARPORT_DEV_EXCL flag is for preventing port sharing, and
so should only be used when sharing the port with other device
drivers is impossible and would lead to incorrect behaviour.
Use it sparingly! Normally, flags will be zero.
This function returns a pointer to a structure that represents
the device on the port, or NULL if there is not enough memory
to allocate space for that structure.
parport_unregister_device() #
void deregister a device on a parallel port
Parameters
struct pardevice *dev: pointer to structure representing device
Description
This undoes the effect of parport_register_device().
parport_find_number() #
struct parport * find a parallel port by number
Parameters
int number: parallel port number
Description
This returns the parallel port with the specified number, or
NULL if there is none.
There is an implicit parport_get_port() done already; to throw
away the reference to the port that parport_find_number()
gives you, use parport_put_port().
parport_find_base() #
struct parport * find a parallel port by base address
Parameters
unsigned long base: base I/O address
Description
This returns the parallel port with the specified base
address, or NULL if there is none.
There is an implicit parport_get_port() done already; to throw
away the reference to the port that parport_find_base()
gives you, use parport_put_port().
parport_claim() #
int claim access to a parallel port device
Parameters
struct pardevice *dev: pointer to structure representing a device on the port
Description
This function will not block and so can be used from interrupt
context. If parport_claim() succeeds in claiming access to
the port it returns zero and the port is available to use. It
may fail (returning non-zero) if the port is in use by another
driver and that driver is not willing to relinquish control of
the port.
parport_claim_or_block() #
int claim access to a parallel port device
Parameters
struct pardevice *dev: pointer to structure representing a device on the port
Description
This behaves like parport_claim(), but will block if necessary
to wait for the port to be free. A return value of 1
indicates that it slept; 0 means that it succeeded without
needing to sleep. A negative error code indicates failure.
parport_release() #
void give up access to a parallel port device
Parameters
struct pardevice *dev: pointer to structure representing parallel port device
Description
This function cannot fail, but it should not be called without the port claimed. Similarly, if the port is already claimed you should not try claiming it again.
parport_open() #
struct pardevice * find a device by canonical device number
Parameters
int devnum: canonical device numberconst char *name: name to associate with the device
Description
This function is similar to parport_register_device(), except
that it locates a device by its number rather than by the port
it is attached to.
All parameters except for devnum are the same as for
parport_register_device(). The return value is the same as
for parport_register_device().
parport_close() #
void close a device opened with parport_open()
Parameters
struct pardevice *dev: device to close
Description
This is to parport_open() as parport_unregister_device() is to
parport_register_device().
16x50 UART Driver #
serial8250_get_port() #
struct uart_8250_port * retrieve struct uart_8250_port
Parameters
int line: serial line number
Description
This function retrieves struct uart_8250_port for the specific line. This struct must not be used to perform a 8250 or serial core operation which is not accessible otherwise. Its only purpose is to make the struct accessible to the runtime-pm callbacks for context suspend/restore. The lock assumption made here is none because runtime-pm suspend/resume callbacks should not be invoked if there is any operation performed on the port.
serial8250_suspend_port() #
void suspend one serial port
Parameters
int line: serial line number
Description
Suspend one serial port.
serial8250_resume_port() #
void resume one serial port
Parameters
int line: serial line number
Description
Resume one serial port.
serial8250_register_8250_port() #
int register a serial port
Parameters
const struct uart_8250_port *up: serial port template
Description
Configure the serial port specified by the request. If the port exists and is in use, it is hung up and unregistered first.
The port is then probed and if necessary the IRQ is autodetected If this fails an error is returned.
On success the port is ready to use and the line number is returned.
serial8250_unregister_port() #
void remove a 16x50 serial port at runtime
Parameters
int line: serial line number
Description
Remove one serial port. This may not be called from interrupt context. We hand the port back to the our control.
See serial/driver.rst for related APIs.
Pulse-Width Modulation (PWM) #
Pulse-width modulation is a modulation technique primarily used to control power supplied to electrical devices.
The PWM framework provides an abstraction for providers and consumers of PWM signals. A controller that provides one or more PWM signals is registered as struct pwm_chip <pwm_chip>. Providers are expected to embed this structure in a driver-specific structure. This structure contains fields that describe a particular chip.
A chip exposes one or more PWM signal sources, each of which exposed as a struct pwm_device <pwm_device>. Operations can be performed on PWM devices to control the period, duty cycle, polarity and active state of the signal.
Note that PWM devices are exclusive resources: they can always only be used by one consumer at a time.
enum pwm_polarity #
polarity of a PWM signal
Constants
PWM_POLARITY_NORMAL: a high signal for the duration of the duty- cycle, followed by a low signal for the remainder of the pulse periodPWM_POLARITY_INVERSED: a low signal for the duration of the duty- cycle, followed by a high signal for the remainder of the pulse period
struct pwm_args #
board-dependent PWM arguments
Definition
;
Members
period: reference periodpolarity: reference polarity
Description
This structure describes board-dependent arguments attached to a PWM device. These arguments are usually retrieved from the PWM lookup table or device tree.
Do not confuse this with the PWM state: PWM arguments represent the initial configuration that users want to use on this PWM device rather than the current PWM hardware state.
struct pwm_waveform #
description of a PWM waveform
Definition
;
Members
period_length_ns: PWM periodduty_length_ns: PWM duty cycleduty_offset_ns: offset of the rising edge from the period's start
Description
This is a representation of a PWM waveform alternative to struct pwm_state below. It's more expressive than struct pwm_state as it contains a duty_offset_ns and so can represent offsets other than zero (with .polarity = PWM_POLARITY_NORMAL) and period - duty_cycle (.polarity = PWM_POLARITY_INVERSED).
Note there is no explicit bool for enabled. A "disabled" PWM is represented by .period_length_ns = 0. Note further that the behaviour of a "disabled" PWM is undefined. Depending on the hardware's capabilities it might drive the active or inactive level, go high-z or even continue to toggle.
The unit for all three members is nanoseconds.
struct pwm_device #
PWM channel object
Definition
;
Members
label: name of the PWM deviceflags: flags associated with the PWM devicehwpwm: per-chip relative index of the PWM devicechip: PWM chip providing this PWM deviceargs: PWM argumentsstate: last applied statelast: last implemented state (for PWM_DEBUG)
pwm_get_state() #
void retrieve the current PWM state
Parameters
const struct pwm_device *pwm: PWM devicestruct pwm_state *state: state to fill with the current PWM state
Description
The returned PWM state represents the state that was applied by a previous call to
pwm_apply_might_sleep(). Drivers may have to slightly tweak that state before programming it to
hardware. If pwm_apply_might_sleep() was never called, this returns either the current hardware
state (if supported) or the default settings.
pwm_init_state() #
void prepare a new state to be applied with pwm_apply_might_sleep()
Parameters
const struct pwm_device *pwm: PWM devicestruct pwm_state *state: state to fill with the prepared PWM state
Description
This functions prepares a state that can later be tweaked and applied
to the PWM device with pwm_apply_might_sleep(). This is a convenient function
that first retrieves the current PWM state and the replaces the period
and polarity fields with the reference values defined in pwm->args.
Once the function returns, you can adjust the ->enabled and ->duty_cycle
fields according to your needs before calling pwm_apply_might_sleep().
->duty_cycle is initially set to zero to avoid cases where the current
->duty_cycle value exceed the pwm_args->period one, which would trigger
an error if the user calls pwm_apply_might_sleep() without adjusting ->duty_cycle
first.
pwm_get_relative_duty_cycle() #
unsigned int Get a relative duty cycle value
Parameters
const struct pwm_state *state: PWM state to extract the duty cycle fromunsigned int scale: target scale of the relative duty cycle
Description
This functions converts the absolute duty cycle stored in state (expressed in nanosecond) into a value relative to the period.
For example if you want to get the duty_cycle expressed in percent, call:
pwm_get_state(pwm, state);
duty = pwm_get_relative_duty_cycle(state, 100);
Return
rounded relative duty cycle multiplied by scale
pwm_set_relative_duty_cycle() #
int Set a relative duty cycle value
Parameters
struct pwm_state *state: PWM state to fillunsigned int duty_cycle: relative duty cycle valueunsigned int scale: scale in which duty_cycle is expressed
Description
This functions converts a relative into an absolute duty cycle (expressed in nanoseconds), and puts the result in state->duty_cycle.
For example if you want to configure a 50% duty cycle, call:
pwm_init_state(pwm, state);
pwm_set_relative_duty_cycle(state, 50, 100);
pwm_apply_might_sleep(pwm, state);
Return
0 on success or -EINVAL if duty_cycle and/or scale are
inconsistent (scale == 0 or duty_cycle > scale)
struct pwm_capture #
PWM capture data
Definition
;
Members
period: period of the PWM signal (in nanoseconds)duty_cycle: duty cycle of the PWM signal (in nanoseconds)
struct pwm_ops #
PWM controller operations
Definition
;
Members
request: optional hook for requesting a PWMfree: optional hook for freeing a PWMcapture: capture and report PWM signalsizeof_wfhw: size (in bytes) of driver specific waveform presentationround_waveform_tohw: convert a struct pwm_waveform to driver specific presentationround_waveform_fromhw: convert a driver specific waveform presentation to struct pwm_waveformread_waveform: read driver specific waveform presentation from hardwarewrite_waveform: write driver specific waveform presentation to hardwareapply: atomically apply a new PWM configget_state: get the current PWM state.
struct pwm_chip #
abstract a PWM controller
Definition
;
Members
dev: device providing the PWMscdev:struct cdevfor this deviceops: callbacks for this PWM controllerowner: module providing this chipid: unique number of this PWM chipnpwm: number of PWMs controlled by this chipof_xlate: request a PWM device given a device tree PWM specifieratomic: can the driver's ->apply()be called in atomic contextgpio:struct gpio_chipto operate this PWM chip's lines as GPOuses_pwmchip_alloc: signals if pwmchip_allow was used to allocate this chipoperational: signals if the chip can be used (or is already deregistered){unnamed_union}: anonymousnonatomic_lock: mutex for nonatomic chipsatomic_lock: mutex for atomic chipspwms: array of PWM devices allocated by the framework
pwmchip_supports_waveform() #
bool checks if the given chip supports waveform callbacks
Parameters
struct pwm_chip *chip: The pwm_chip to test
Return
true iff the pwm chip support the waveform functions like
pwm_set_waveform_might_sleep() and pwm_round_waveform_might_sleep()
pwm_config() #
int change a PWM device configuration
Parameters
struct pwm_device *pwm: PWM deviceint duty_ns: "on" time (in nanoseconds)int period_ns: duration (in nanoseconds) of one cycle
Return
0 on success or a negative error code on failure.
pwm_enable() #
int start a PWM output toggling
Parameters
struct pwm_device *pwm: PWM device
Return
0 on success or a negative error code on failure.
pwm_disable() #
void stop a PWM output toggling
Parameters
struct pwm_device *pwm: PWM device
pwm_might_sleep() #
bool is pwm_apply_atomic() supported?
Parameters
struct pwm_device *pwm: PWM device
Return
false if pwm_apply_atomic() can be called from atomic context.
pwm_round_waveform_might_sleep() #
int Query hardware capabilities Cannot be used in atomic context.
Parameters
struct pwm_device *pwm: PWM devicestruct pwm_waveform *wf: waveform to round and output parameter
Description
Typically a given waveform cannot be implemented exactly by hardware, e.g.
because hardware only supports coarse period resolution or no duty_offset.
This function returns the actually implemented waveform if you pass wf to
pwm_set_waveform_might_sleep() now.
Note however that the world doesn't stop turning when you call it, so when doing:
pwm_round_waveform_might_sleep(mypwm, &wf);
pwm_set_waveform_might_sleep(mypwm, &wf, true);
the latter might fail, e.g. because an input clock changed its rate between
these two calls and the waveform determined by
pwm_round_waveform_might_sleep() cannot be implemented any more.
Usually all values passed in wf are rounded down to the nearest possible
value (in the order period_length_ns, duty_length_ns and then
duty_offset_ns). Only if this isn't possible, a value might grow. See the
documentation for pwm_set_waveform_might_sleep() for a more formal
description.
Return
0 on success, 1 if at least one value had to be rounded up or a negative errno.
Context
May sleep.
pwm_get_waveform_might_sleep() #
int Query hardware about current configuration Cannot be used in atomic context.
Parameters
struct pwm_device *pwm: PWM devicestruct pwm_waveform *wf: output parameter
Description
Stores the current configuration of the PWM in wf. Note this is the
equivalent of pwm_get_state_hw() (and not pwm_get_state()) for pwm_waveform.
Return
0 on success or a negative errno
Context
May sleep.
pwm_set_waveform_might_sleep() #
int Apply a new waveform Cannot be used in atomic context.
Parameters
struct pwm_device *pwm: PWM deviceconst struct pwm_waveform *wf: The waveform to applybool exact: If true no rounding is allowed
Description
Typically a requested waveform cannot be implemented exactly, e.g. because
you requested .period_length_ns = 100 ns, but the hardware can only set
periods that are a multiple of 8.5 ns. With that hardware passing exact =
true results in pwm_set_waveform_might_sleep() failing and returning -EDOM.
If exact = false you get a period of 93.5 ns (i.e. the biggest period not
bigger than the requested value).
Note that even with exact = true, some rounding by less than 1 ns is
possible/needed. In the above example requesting .period_length_ns = 94 and
exact = true, you get the hardware configured with period = 93.5 ns.
Let C be the set of possible hardware configurations for a given PWM device, consisting of tuples (p, d, o) where p is the period length, d is the duty length and o the duty offset.
The following algorithm is implemented to pick the hardware setting (p, d, o) ∈ C for a given request (p', d', o') with exact = false:
p = max( { ṗ | ∃ ḋ, ȯ : (ṗ, ḋ, ȯ) ∈ C ∧ ṗ ≤ p' } ∪ { min({ ṗ | ∃ ḋ, ȯ : (ṗ, ḋ, ȯ) ∈ C }) })
d = max( { ḋ | ∃ ȯ : (p, ḋ, ȯ) ∈ C ∧ ḋ ≤ d' } ∪ { min({ ḋ | ∃ ȯ : (p, ḋ, ȯ) ∈ C }) })
o = max( { ȯ | (p, d, ȯ) ∈ C ∧ ȯ ≤ o' } ∪ { min({ ȯ | (p, d, ȯ) ∈ C }) })
In words: The chosen period length is the maximal possible period length not bigger than the requested period length and if that doesn't exist, the minimal period length. The chosen duty length is the maximal possible duty length that is compatible with the chosen period length and isn't bigger than the requested duty length. Again if such a value doesn't exist, the minimal duty length compatible with the chosen period is picked. After that the duty offset compatible with the chosen period and duty length is chosen in the same way.
Return
0 on success, -EDOM if setting failed due to the exact waveform not being possible (if exact), or a different negative errno on failure.
Context
May sleep.
pwm_apply_might_sleep() #
int atomically apply a new state to a PWM device Cannot be used in atomic context.
Parameters
struct pwm_device *pwm: PWM deviceconst struct pwm_state *state: new state to apply
Return
0 on success, or a negative errno
Context
May sleep.
pwm_apply_atomic() #
int apply a new state to a PWM device from atomic context Not all PWM devices support this function, check with pwm_might_sleep().
Parameters
struct pwm_device *pwm: PWM deviceconst struct pwm_state *state: new state to apply
Return
0 on success, or a negative errno
Context
Any
pwm_get_state_hw() #
int get the current PWM state from hardware
Parameters
struct pwm_device *pwm: PWM devicestruct pwm_state *state: state to fill with the current PWM state
Description
Similar to pwm_get_state() but reads the current PWM state from hardware
instead of the requested state.
Return
0 on success or a negative error code on failure.
Context
May sleep.
pwm_adjust_config() #
int adjust the current PWM config to the PWM arguments
Parameters
struct pwm_device *pwm: PWM device
Description
This function will adjust the PWM config to the PWM arguments provided by the DT or PWM lookup table. This is particularly useful to adapt the bootloader config to the Linux one.
Return
0 on success or a negative error code on failure.
Context
May sleep.
pwm_get() #
struct pwm_device * look up and request a PWM device
Parameters
struct device *dev: device for PWM consumerconst char *con_id: consumer name
Description
Lookup is first attempted using DT. If the device was not instantiated from
a device tree, a PWM chip and a relative index is looked up via a table
supplied by board setup code (see pwm_add_table()).
Once a PWM chip has been found the specified PWM device will be requested and is ready to be used.
Return
A pointer to the requested PWM device or an ERR_PTR()-encoded
error code on failure.
pwm_put() #
void release a PWM device
Parameters
struct pwm_device *pwm: PWM device
devm_pwm_get() #
struct pwm_device * resource managed pwm_get()
Parameters
struct device *dev: device for PWM consumerconst char *con_id: consumer name
Description
This function performs like pwm_get() but the acquired PWM device will
automatically be released on driver detach.
Return
A pointer to the requested PWM device or an ERR_PTR()-encoded
error code on failure.
devm_fwnode_pwm_get() #
struct pwm_device * request a resource managed PWM from firmware node
Parameters
struct device *dev: device for PWM consumerstruct fwnode_handle *fwnode: firmware node to get the PWM fromconst char *con_id: consumer name
Description
Returns the PWM device parsed from the firmware node. See of_pwm_get() and
acpi_pwm_get() for a detailed description.
Return
A pointer to the requested PWM device or an ERR_PTR()-encoded
error code on failure.
__pwmchip_add() #
int register a new PWM chip
Parameters
struct pwm_chip *chip: the PWM chip to addstruct module *owner: reference to the module providing the chip.
Description
Register a new PWM chip. owner is supposed to be THIS_MODULE, use the pwmchip_add wrapper to do this right.
Return
0 on success or a negative error code on failure.
pwmchip_remove() #
void remove a PWM chip
Parameters
struct pwm_chip *chip: the PWM chip to remove
Description
Removes a PWM chip.