Testing CANFD on RZ/G3E shows that many registers do not reset to their initial values with the current flow of deasserting resets first and then enabling clocks. Based on the HW manual, clocks should be supplied first and the resets deasserted afterward. section 7.4.3 Procedure for Activating Modules: RZ/G2L section 4.4.9.3 Procedure for Starting up Units: RZ/G3E So, update the order of the initializing flow for resets and clocks to match the hardware manual, resetting all CANFD registers to their initial values. Also update rcar_canfd_global_deinit() to assert resets before disabling clocks, so the teardown path mirrors the new init ordering.
Unified · Split
| @@ -2003,20 +2003,12 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv) · 2002 unmodified lines | ||
| 2003 | 2003 | u32 ch, sts; |
| 2004 | 2004 | int err; |
| 2005 | 2005 | |
| 2006 | − err = reset_control_reset(gpriv->rstc1); | |
| 2007 | − if (err) | |
| 2008 | − return err; | |
| 2009 | − | |
| 2010 | − err = reset_control_reset(gpriv->rstc2); | |
| 2011 | − if (err) | |
| 2012 | − goto fail_reset1; | |
| 2013 | − | |
| 2014 | 2006 | /* Enable peripheral clock for register access */ |
| 2015 | 2007 | err = clk_prepare_enable(gpriv->clkp); |
| 2016 | 2008 | if (err) { |
| 2017 | 2009 | dev_err(dev, "failed to enable peripheral clock: %pe\n", |
| 2018 | 2010 | ERR_PTR(err)); |
| 2019 | − goto fail_reset2; | |
| 2011 | + return err; | |
| 2020 | 2012 | } |
| 2021 | 2013 | |
| 2022 | 2014 | /* Enable RAM clock */ |
| @@ -2027,10 +2019,18 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv) · 4 unmodified lines | ||
| 2027 | 2019 | goto fail_clk; |
| 2028 | 2020 | } |
| 2029 | 2021 | |
| 2022 | + err = reset_control_reset(gpriv->rstc1); | |
| 2023 | + if (err) | |
| 2024 | + goto fail_ram_clk; | |
| 2025 | + | |
| 2026 | + err = reset_control_reset(gpriv->rstc2); | |
| 2027 | + if (err) | |
| 2028 | + goto fail_reset1; | |
| 2029 | + | |
| 2030 | 2030 | err = rcar_canfd_reset_controller(gpriv); |
| 2031 | 2031 | if (err) { |
| 2032 | 2032 | dev_err(dev, "reset controller failed: %pe\n", ERR_PTR(err)); |
| 2033 | − goto fail_ram_clk; | |
| 2033 | + goto fail_reset2; | |
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | 2036 | /* Controller in Global reset & Channel reset mode */ |
| @@ -2068,14 +2068,14 @@ static int rcar_canfd_global_init(struct rcar_canfd_global *gpriv) · 31 unmodified lines | ||
| 2068 | 2068 | |
| 2069 | 2069 | fail_mode: |
| 2070 | 2070 | rcar_canfd_disable_global_interrupts(gpriv); |
| 2071 | −fail_ram_clk: | |
| 2072 | − clk_disable_unprepare(gpriv->clk_ram); | |
| 2073 | −fail_clk: | |
| 2074 | − clk_disable_unprepare(gpriv->clkp); | |
| 2075 | 2071 | fail_reset2: |
| 2076 | 2072 | reset_control_assert(gpriv->rstc2); |
| 2077 | 2073 | fail_reset1: |
| 2078 | 2074 | reset_control_assert(gpriv->rstc1); |
| 2075 | +fail_ram_clk: | |
| 2076 | + clk_disable_unprepare(gpriv->clk_ram); | |
| 2077 | +fail_clk: | |
| 2078 | + clk_disable_unprepare(gpriv->clkp); | |
| 2079 | 2079 | return err; |
| 2080 | 2080 | } |
| 2081 | 2081 | |
| @@ -2090,10 +2090,10 @@ static void rcar_canfd_global_deinit(struct rcar_canfd_global *gpriv, bool full) · 8 unmodified lines | ||
| 2090 | 2090 | rcar_canfd_set_bit(gpriv->base, RCANFD_GCTR, RCANFD_GCTR_GSLPR); |
| 2091 | 2091 | } |
| 2092 | 2092 | |
| 2093 | − clk_disable_unprepare(gpriv->clk_ram); | |
| 2094 | − clk_disable_unprepare(gpriv->clkp); | |
| 2095 | 2093 | reset_control_assert(gpriv->rstc2); |
| 2096 | 2094 | reset_control_assert(gpriv->rstc1); |
| 2095 | + clk_disable_unprepare(gpriv->clk_ram); | |
| 2096 | + clk_disable_unprepare(gpriv->clkp); | |
| 2097 | 2097 | } |
| 2098 | 2098 | |
| 2099 | 2099 | static int rcar_canfd_probe(struct platform_device *pdev) |