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>
This commit is contained in:
parent
1ca6828db9
commit
f2ebf488d7
1 changed files with 7 additions and 20 deletions
|
@ -21,10 +21,9 @@
|
|||
LOG_MODULE_REGISTER(led_pwm, CONFIG_LED_LOG_LEVEL);
|
||||
|
||||
#define DEV_CFG(dev) ((const struct led_pwm_config *) ((dev)->config))
|
||||
#define DEV_DATA(dev) ((struct led_pwm_data *) ((dev)->data))
|
||||
|
||||
struct led_pwm {
|
||||
char *pwm_label;
|
||||
const struct device *dev;
|
||||
uint32_t channel;
|
||||
uint32_t period;
|
||||
pwm_flags_t flags;
|
||||
|
@ -35,15 +34,10 @@ struct led_pwm_config {
|
|||
const struct led_pwm *led;
|
||||
};
|
||||
|
||||
struct led_pwm_data {
|
||||
const struct device *pwm;
|
||||
};
|
||||
|
||||
static int led_pwm_blink(const struct device *dev, uint32_t led,
|
||||
uint32_t delay_on, uint32_t delay_off)
|
||||
{
|
||||
const struct led_pwm_config *config = DEV_CFG(dev);
|
||||
struct led_pwm_data *data = DEV_DATA(dev);
|
||||
const struct led_pwm *led_pwm;
|
||||
uint32_t period_usec, pulse_usec;
|
||||
|
||||
|
@ -63,7 +57,7 @@ static int led_pwm_blink(const struct device *dev, uint32_t led,
|
|||
|
||||
led_pwm = &config->led[led];
|
||||
|
||||
return pwm_pin_set_usec(data[led].pwm, led_pwm->channel,
|
||||
return pwm_pin_set_usec(led_pwm->dev, led_pwm->channel,
|
||||
period_usec, pulse_usec, led_pwm->flags);
|
||||
}
|
||||
|
||||
|
@ -71,7 +65,6 @@ static int led_pwm_set_brightness(const struct device *dev,
|
|||
uint32_t led, uint8_t value)
|
||||
{
|
||||
const struct led_pwm_config *config = DEV_CFG(dev);
|
||||
struct led_pwm_data *data = DEV_DATA(dev);
|
||||
const struct led_pwm *led_pwm;
|
||||
uint32_t pulse;
|
||||
|
||||
|
@ -83,7 +76,7 @@ static int led_pwm_set_brightness(const struct device *dev,
|
|||
|
||||
pulse = led_pwm->period * value / 100;
|
||||
|
||||
return pwm_pin_set_cycles(data[led].pwm, led_pwm->channel,
|
||||
return pwm_pin_set_cycles(led_pwm->dev, led_pwm->channel,
|
||||
led_pwm->period, pulse, led_pwm->flags);
|
||||
}
|
||||
|
||||
|
@ -100,7 +93,6 @@ static int led_pwm_off(const struct device *dev, uint32_t led)
|
|||
static int led_pwm_init(const struct device *dev)
|
||||
{
|
||||
const struct led_pwm_config *config = DEV_CFG(dev);
|
||||
struct led_pwm_data *data = DEV_DATA(dev);
|
||||
int i;
|
||||
|
||||
if (!config->num_leds) {
|
||||
|
@ -112,10 +104,8 @@ static int led_pwm_init(const struct device *dev)
|
|||
for (i = 0; i < config->num_leds; i++) {
|
||||
const struct led_pwm *led = &config->led[i];
|
||||
|
||||
data[i].pwm = device_get_binding(led->pwm_label);
|
||||
if (data->pwm == NULL) {
|
||||
LOG_ERR("%s: device %s not found",
|
||||
dev->name, led->pwm_label);
|
||||
if (!device_is_ready(led->dev)) {
|
||||
LOG_ERR("%s: pwm device not ready", dev->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +122,7 @@ static const struct led_driver_api led_pwm_api = {
|
|||
|
||||
#define LED_PWM(led_node_id) \
|
||||
{ \
|
||||
.pwm_label = DT_PWMS_LABEL(led_node_id), \
|
||||
.dev = DEVICE_DT_GET(DT_PWMS_CTLR(led_node_id)), \
|
||||
.channel = DT_PWMS_CHANNEL(led_node_id), \
|
||||
.period = DT_PHA_OR(led_node_id, pwms, period, 100), \
|
||||
.flags = DT_PHA_OR(led_node_id, pwms, flags, \
|
||||
|
@ -150,14 +140,11 @@ const struct led_pwm_config led_pwm_config_##id = { \
|
|||
.led = led_pwm_##id, \
|
||||
}; \
|
||||
\
|
||||
static struct led_pwm_data \
|
||||
led_pwm_data_##id[ARRAY_SIZE(led_pwm_##id)]; \
|
||||
\
|
||||
DEVICE_DEFINE(led_pwm_##id, \
|
||||
DT_INST_PROP_OR(id, label, "LED_PWM_"#id), \
|
||||
&led_pwm_init, \
|
||||
device_pm_control_nop, \
|
||||
&led_pwm_data_##id, \
|
||||
NULL, \
|
||||
&led_pwm_config_##id, \
|
||||
POST_KERNEL, CONFIG_LED_INIT_PRIORITY, \
|
||||
&led_pwm_api);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue