On 04.10.2023 19:50:55, Vincent Mailhol wrote: > On Wed. 4 Oct. 2023, 18:24, Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx> wrote: > > Some CAN controllers do not have a register that contains the current > > CAN state, but only a register that contains the error counters. > > > > Introduce a new function can_state_get_by_berr_counter() that returns > > the current TX and RX state depending on the provided CAN bit error > > counters. > > > > Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx> > > --- > > drivers/net/can/dev/dev.c | 22 ++++++++++++++++++++++ > > include/linux/can/dev.h | 4 ++++ > > 2 files changed, 26 insertions(+) > > > > diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c > > index 7f9334a8af50..6242424fadbc 100644 > > --- a/drivers/net/can/dev/dev.c > > +++ b/drivers/net/can/dev/dev.c > > @@ -90,6 +90,28 @@ const char *can_get_state_str(const enum can_state state) > > } > > EXPORT_SYMBOL_GPL(can_get_state_str); > > > > +static enum can_state can_state_err_to_state(u16 err) > > +{ > > + if (err < 96) > > + return CAN_STATE_ERROR_ACTIVE; > > + if (err < 128) > > + return CAN_STATE_ERROR_WARNING; > > + if (err < 256) > > + return CAN_STATE_ERROR_PASSIVE; > > Please use the macros from include/uapi/linux/can/error.h. > > https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/can/error.h#L130 Done. Marc -- Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Attachment:
signature.asc
Description: PGP signature