pwm/tracing: Also record trace events for failed API calls

Record and report an error code for the events. This allows to report
about failed calls without ambiguity and so gives a more complete
picture.

Acked-by: Conor Dooley <conor.dooley@microchip.com>
Link: https://lore.kernel.org/r/20221130152148.2769768-3-u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
This commit is contained in:
Uwe Kleine-König
2022-12-02 19:35:27 +01:00
committed by Thierry Reding
parent 6c452cff79
commit 3dae106f4c
2 changed files with 18 additions and 20 deletions

View File

@@ -115,8 +115,8 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
} }
if (pwm->chip->ops->get_state) { if (pwm->chip->ops->get_state) {
pwm->chip->ops->get_state(pwm->chip, pwm, &pwm->state); err = pwm->chip->ops->get_state(pwm->chip, pwm, &pwm->state);
trace_pwm_get(pwm, &pwm->state); trace_pwm_get(pwm, &pwm->state, err);
if (IS_ENABLED(CONFIG_PWM_DEBUG)) if (IS_ENABLED(CONFIG_PWM_DEBUG))
pwm->last = pwm->state; pwm->last = pwm->state;
@@ -458,8 +458,8 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
* checks. * checks.
*/ */
chip->ops->get_state(chip, pwm, &s1); err = chip->ops->get_state(chip, pwm, &s1);
trace_pwm_get(pwm, &s1); trace_pwm_get(pwm, &s1, err);
/* /*
* The lowlevel driver either ignored .polarity (which is a bug) or as * The lowlevel driver either ignored .polarity (which is a bug) or as
@@ -515,16 +515,15 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
/* reapply the state that the driver reported being configured. */ /* reapply the state that the driver reported being configured. */
err = chip->ops->apply(chip, pwm, &s1); err = chip->ops->apply(chip, pwm, &s1);
trace_pwm_apply(pwm, &s1, err);
if (err) { if (err) {
*last = s1; *last = s1;
dev_err(chip->dev, "failed to reapply current setting\n"); dev_err(chip->dev, "failed to reapply current setting\n");
return; return;
} }
trace_pwm_apply(pwm, &s1); err = chip->ops->get_state(chip, pwm, last);
trace_pwm_get(pwm, last, err);
chip->ops->get_state(chip, pwm, last);
trace_pwm_get(pwm, last);
/* reapplication of the current state should give an exact match */ /* reapplication of the current state should give an exact match */
if (s1.enabled != last->enabled || if (s1.enabled != last->enabled ||
@@ -572,11 +571,10 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
return 0; return 0;
err = chip->ops->apply(chip, pwm, state); err = chip->ops->apply(chip, pwm, state);
trace_pwm_apply(pwm, state, err);
if (err) if (err)
return err; return err;
trace_pwm_apply(pwm, state);
pwm->state = *state; pwm->state = *state;
/* /*

View File

@@ -10,9 +10,9 @@
DECLARE_EVENT_CLASS(pwm, DECLARE_EVENT_CLASS(pwm,
TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state), TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state, int err),
TP_ARGS(pwm, state), TP_ARGS(pwm, state, err),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(struct pwm_device *, pwm) __field(struct pwm_device *, pwm)
@@ -20,6 +20,7 @@ DECLARE_EVENT_CLASS(pwm,
__field(u64, duty_cycle) __field(u64, duty_cycle)
__field(enum pwm_polarity, polarity) __field(enum pwm_polarity, polarity)
__field(bool, enabled) __field(bool, enabled)
__field(int, err)
), ),
TP_fast_assign( TP_fast_assign(
@@ -28,28 +29,27 @@ DECLARE_EVENT_CLASS(pwm,
__entry->duty_cycle = state->duty_cycle; __entry->duty_cycle = state->duty_cycle;
__entry->polarity = state->polarity; __entry->polarity = state->polarity;
__entry->enabled = state->enabled; __entry->enabled = state->enabled;
__entry->err = err;
), ),
TP_printk("%p: period=%llu duty_cycle=%llu polarity=%d enabled=%d", TP_printk("%p: period=%llu duty_cycle=%llu polarity=%d enabled=%d err=%d",
__entry->pwm, __entry->period, __entry->duty_cycle, __entry->pwm, __entry->period, __entry->duty_cycle,
__entry->polarity, __entry->enabled) __entry->polarity, __entry->enabled, __entry->err)
); );
DEFINE_EVENT(pwm, pwm_apply, DEFINE_EVENT(pwm, pwm_apply,
TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state), TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state, int err),
TP_ARGS(pwm, state)
TP_ARGS(pwm, state, err)
); );
DEFINE_EVENT(pwm, pwm_get, DEFINE_EVENT(pwm, pwm_get,
TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state), TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state, int err),
TP_ARGS(pwm, state)
TP_ARGS(pwm, state, err)
); );
#endif /* _TRACE_PWM_H */ #endif /* _TRACE_PWM_H */