Commit e7ca61e4 authored by Martin Jeřábek's avatar Martin Jeřábek
Browse files

driver: timing: correctly distribute tseg1 into prop_seg and phase_seg1

Closes #177
parent beb8f7ed
......@@ -356,9 +356,25 @@ void ctu_can_fd_set_nom_bittiming(struct ctucanfd_priv *priv,
const struct can_bittiming *nbt)
{
union ctu_can_fd_btr btr;
btr.u32 = 0;
btr.s.prop = nbt->prop_seg;
btr.s.ph1 = nbt->phase_seg1;
/*
* The timing calculation functions have only constraints on tseg1,
* which is prop_seg + phase1_seg combined. tseg1 is then split in half
* and stored into prog_seg and phase_seg1. In CTU CAN FD, PROP is 7 bits
* wide but PH1 only 6, so we must re-distribute the values here.
* TODO: get the fixed values to the kernel, so that they are displayed
* accurately
*/
u32 prop_seg = nbt->prop_seg;
u32 phase_seg1 = nbt->phase_seg1;
if (phase_seg1 > 63) {
prop_seg += phase_seg1 - 63;
phase_seg1 = 63;
}
btr.u32 = 0;
btr.s.prop = prop_seg;
btr.s.ph1 = phase_seg1;
btr.s.ph2 = nbt->phase_seg2;
btr.s.brp = nbt->brp;
btr.s.sjw = nbt->sjw;
......@@ -370,9 +386,25 @@ void ctu_can_fd_set_data_bittiming(struct ctucanfd_priv *priv,
const struct can_bittiming *dbt)
{
union ctu_can_fd_btr_fd btr_fd;
/*
* The timing calculation functions have only constraints on tseg1,
* which is prop_seg + phase1_seg combined. tseg1 is then split in half
* and stored into prog_seg and phase_seg1. In CTU CAN FD, PROP_FD is 6 bits
* wide but PH1_FD only 5, so we must re-distribute the values here.
* TODO: get the fixed values to the kernel, so that they are displayed
* accurately
*/
u32 prop_seg = dbt->prop_seg;
u32 phase_seg1 = dbt->phase_seg1;
if (phase_seg1 > 31) {
prop_seg += phase_seg1 - 31;
phase_seg1 = 31;
}
btr_fd.u32 = 0;
btr_fd.s.prop_fd = dbt->prop_seg;
btr_fd.s.ph1_fd = dbt->phase_seg1;
btr_fd.s.prop_fd = prop_seg;
btr_fd.s.ph1_fd = phase_seg1;
btr_fd.s.ph2_fd = dbt->phase_seg2;
btr_fd.s.brp_fd = dbt->brp;
btr_fd.s.sjw_fd = dbt->sjw;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment