drivers: can: move bitrate limit checks to arbitration/data functions

Move the check for the maximum allowed CAN bitrate to the corresponding
can_calc_timing()/can_calc_timing_data() function.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2022-08-18 14:53:51 +02:00 committed by Fabio Baltieri
commit 2b99b05d0a

View file

@ -88,9 +88,7 @@ static int can_calc_timing_int(uint32_t core_clock, struct can_timing *res,
int sp_err; int sp_err;
struct can_timing tmp_res; struct can_timing tmp_res;
if (bitrate == 0 || sp >= 1000 || if (bitrate == 0 || sp >= 1000) {
(!IS_ENABLED(CONFIG_CAN_FD_MODE) && bitrate > 1000000) ||
(IS_ENABLED(CONFIG_CAN_FD_MODE) && bitrate > 8000000)) {
return -EINVAL; return -EINVAL;
} }
@ -139,6 +137,10 @@ int z_impl_can_calc_timing(const struct device *dev, struct can_timing *res,
uint32_t core_clock; uint32_t core_clock;
int ret; int ret;
if (bitrate > 1000000) {
return -EINVAL;
}
ret = can_get_core_clock(dev, &core_clock); ret = can_get_core_clock(dev, &core_clock);
if (ret != 0) { if (ret != 0) {
return ret; return ret;
@ -156,6 +158,10 @@ int z_impl_can_calc_timing_data(const struct device *dev, struct can_timing *res
uint32_t core_clock; uint32_t core_clock;
int ret; int ret;
if (bitrate > 8000000) {
return -EINVAL;
}
ret = can_get_core_clock(dev, &core_clock); ret = can_get_core_clock(dev, &core_clock);
if (ret != 0) { if (ret != 0) {
return ret; return ret;