Commit graph

40 commits

Author SHA1 Message Date
Dennis Grijalva 78b4735e07 drivers: led: led_pwm: Fix PM callback error logging
If the underlying PWM device does not have a PM callback,
the PWM LED driver will flood the console with error logs.
The change ignores the error if there is no PM callback
for the PWM device.

Signed-off-by: Dennis Grijalva <dennisgrijalva@meta.com>
2023-10-20 15:03:27 +02:00
Simon Guinot a4645908ee drivers: led_pwm: fix overflow in set_brightness
The set_brightness function of the led_pwm driver uses a default PWM
period (defined in the pwms DT property) to compute a pulse passed to
the pwm_set_pulse_dt function. If this default period is greater than
2^32/100 nanoseconds (about 43 milliseconds) then the calculation may
overflow.

This patch prevents this overflow by running the pulse computation under
a cast with a larger type (uint64_t).

Reported-by: Scott Worley <scott.worley@microchip.com>
Signed-off-by: Simon Guinot <simon.guinot@seagate.com>
2023-07-18 10:45:05 +00:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Gerard Marull-Paretas 44552df4f5 drivers: led: pwm: use DT_INST_FOREACH_CHILD_SEP
Remove the need for auxiliary macros by using DT_INST_FOREACH_CHILD_SEP.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-30 16:19:57 +02:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Daniel DeGrasse b0ec63fe01 drivers: led_pwm: fix build error
Remove stray parenthesis causing build error in led_pwm driver.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-04-29 08:56:42 +02:00
Gerard Marull-Paretas ae91933c4a drivers: pwm: always use nanoseconds for set
In order to be consistent with what is possible in Devicetree, always
take a period in nanoseconds. Other scales or units may be specified by
using, e.g., the PWM_MSEC() macros (all of them converting down to
nanoseconds). This change then deletes the "_nsec" and "_usec" versions
of the pwm_set call.

Note that this change limits the period to UINT32_MAX nanoseconds,
~4.3s. PWM is, in generali, used with periods below the second so it
should not be a problem.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-04-28 11:29:38 +02:00
Gerard Marull-Paretas 2bc6279866 drivers: led: led_pwm: use pwm_dt_spec
Simplify the driver by using pwm_dt_spec.

TODO: decide if pwm_dt_spec should also store period.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-04-28 11:29:38 +02:00
Gerard Marull-Paretas 10ee44c94b drivers/samples/tests: remove usage of deprecated PWM APIs
Use the new API calls that remove pin naming.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-04-28 11:29:38 +02:00
Gerard Marull-Paretas d231c11ec8 drivers: led: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Gerard Marull-Paretas ddc168fa78 pm: s/PM_DEVICE_(DT_(INST))_REF/PM_DEVICE_(DT_(INST))_GET
In order to align with macros used to obtain a device reference (e.g.
DEVICE_DT_GET), align the PM macros to use "GET" instead of "REF". This
change should have low impact since no official release has gone out yet
with the "REF" macros.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-18 12:14:06 -05:00
Gerard Marull-Paretas 89a4f36fc8 device: remove inclusion of pm/device.h
The device PM subsystem _depends_ on device, not vice-versa. Devices
only hold a reference to struct pm_device now, and initialize this
reference with the value provided in Z_DEVICE_DEFINE. This requirement
can be solved with a forward struct declaration, meaning there is no
need to include device PM headers.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-29 11:08:38 +01:00
Flavio Ceolin 6451626ce7 pm: Use pm_device_action_run instead of state_set
Since drivers implement a callback based on action and not the state,
we should be using the API based on the action instead of the one based
on the state.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-24 14:21:50 -05:00
Flavio Ceolin 80d26d996e drivers: led_pwm: Fix log message
The log message was using the uninitialized variable state.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-24 14:21:50 -05:00
Gerard Marull-Paretas 88a69674c0 drivers: use new PM macros
Port some drivers to the recently introduced macros to showcase its
usage and be able to do some initial testing (nRF52840).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-19 10:11:32 +01:00
Jan Zyczkowski d435340f1b drivers: led_pwm: Decrease power consumption
Changed pwm_pin_set_cycles into pwm_pin_set_nsec
to decrease power consumption. Changed default
value for period to 100000. There is no need in having
period for pwm leds equal to 100 cycles as human eye has ~100 fps.

Signed-off-by: Jan Zyczkowski <jan.zyczkowski@nordicsemi.no>
2021-11-06 21:38:35 -04:00
Gerard Marull-Paretas 4baf1e01ff drivers: use common PM action callback naming
The PM callback is no longer referenced as "pm_control" but
"pm_action_cb", so reflect this new naming on the callbacks.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 20:27:18 -04:00
Marek Pieta 07b9e4e992 drivers: led_pwm: Fix power management action callback
A single PWM driver can be used for multiple LED numbers. In that
case -EALREADY may be reported. It should be ignored.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2021-10-27 13:45:43 -04:00
Gerard Marull-Paretas 7ccc1a41bc pm: use actions for device PM control
Instead of passing target states, use actions for device PM control.
Actions represent better the meaning of the callback argument.
Furthermore, they are more future proof as they can be suitable for
other PM actions that have no direct mapping to a state. If we compare
with Linux, we could have a multi-stage suspend/resume. Such scenario
would not have a good mapping when using target states.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 495672ab62 pm: cleanup pm control callback implementations
- Return -ENOTSUP if the requested state is not supported
- Remove redundant "noop style" functions.
- Use switch everywhere to handle requested state (not necessary in all
  drivers, but better take off with consistency in place after current
  changes).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 920f30cc0e pm: simplify state change check logic
The device PM control function will only be called if the requested
state is different from the current one. A significant amount of drivers
were checking for state changes, now unnecessary. This patch removes all
this redundant logic.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 11eef4d8c8 pm: device: remove pointer usage for state
Since the state is no longer modified by the device PM callback, just
use the state value.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 9e7d545bb4 pm: device: remove ctrl_command callback argument
The ctrl_command is not used anymore, so remove it from the callback
signature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas da0ff4ae46 pm: device: remove usage of ctrl_command
The callback is now invoked to set the device PM state in all cases, so
the usage of ctrl_command is redundant.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas c2cf1ad203 pm: device: remove usage of local states
The device PM subsystem already holds the device state, so there is no
need to keep duplicates inside the device. The pm_device_state_get has
been refactored to just return the device state. Note that this is still
not safe, but the same applied to the previous implementation. This
problem will be addressed later.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 26ad8376bd pm: remove callback from control function
The callback is not used anymore, so just delete it from the pm_control
callback signature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-13 09:36:45 -04:00
Gerard Marull-Paretas 217e610d8f pm: remove redundant callback usage
the device PM callback is not used anymore by the device PM subsystem,
so remove it from all drivers/tests using it.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-13 09:36:45 -04:00
Gerard Marull-Paretas cc2f0e9c08 pm: use enum for device PM states
Move all PM_DEVICE_STATE_* definitions to an enum. The
PM_DEVICE_STATE_SET and PM_DEVICE_STATE_GET definitions have been kept
out of the enum since they do not represent any state. However, their
name has not been changed since they will be removed soon.

All drivers and tests have been adjusted accordingly.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-07 14:13:12 -04:00
Marek Pieta 3851a14ff8 drivers: led_pwm: Update pm_control function
Change updates pm_control function to make it compatible with new
API.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2021-05-19 07:52:02 -05:00
Simon Guinot df01148aeb drivers: led_pwm: fix device name fallback
If the label property is missing in a "pwm-leds" compatible DT node
(which is almost always the case), then the device name is now set to
DT_NODE_FULL_NAME instead of "LED_PWM_$inst" previously.

This allows applications to use the DEVICE_DT_NAME macro to retrieve
the device name instead of gessing an arbitrary string.

Signed-off-by: Simon Guinot <simon.guinot@seagate.com>
2021-05-19 11:56:01 +02:00
Flavio Ceolin 0c607adb63 pm: device: Align state names with system states
Change device pm states to the same pattern used by system power
management.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-05-07 18:35:12 -04:00
Gerard Marull-Paretas 56f1a8ce98 pm: rename PM_DEVICE_GET/SET_POWER_STATE to PM_DEVICE_STATE_GET/SET
Adjust name to be consistent with device PM naming conventions.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 7988ab4a26 pm: rename device_set/get_power_state to pm_device_set/get
Make name consistent with other device PM APIs.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas dbf46b3815 pm: rename device_pm_cb to pm_device_cb
Prefix all device PM functions/data structures with pm.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 2c7b763e47 pm: replace DEVICE_PM_* states with PM_DEVICE_*
Prefix device PM states with PM.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Pawel Dunaj 1caf5fd21e drivers: led_pwm: Handle power state changes
Suspend/resume PMW device when PWM LEDs are suspended/resumed.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2021-04-13 16:21:07 -04:00
Kumar Gala f2ebf488d7 drivers: led_pwm: Convert to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access
to the pwm controller device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-24 13:45:46 -06:00
Peter Bigot d03dbab105 drivers: led: fix led_pwm initialization
The PM control function and the init function were swapped.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-20 10:30:29 -06:00
Kumar Gala e1c47a9bb7 drivers: led: Convert DEVICE_AND_API_INIT to DEVICE_DEFINE
Convert LED PWM driver to DEVICE_DEFINE instead of DEVICE_AND_API_INIT
so we can deprecate DEVICE_AND_API_INIT in the future.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-19 04:53:13 -06:00
Simon Guinot 525a588db4 drivers: led: add driver for PWM LEDs
This driver supports the PWM driven LEDs. The devices are created from
the DT nodes with a compatible property matching "pwm-leds". For each
child node a LED is created and its "pwms" phandle's node is used to
retrieve the PWM configuration: channel, period and flags. If some of
this properties are missing (it is the case for some PWM controllers),
then reasonable default values are used.

This driver implements the following LED API methods:

- led_on
- led_off
- led_blink
- led_set_brightness

Signed-off-by: Simon Guinot <simon.guinot@seagate.com>
2020-10-28 10:44:46 -05:00