Skip to content

Commit

Permalink
thunderbolt: Check valid TMU configuration in tb_switch_tmu_configure()
Browse files Browse the repository at this point in the history
Instead of at enable time we can do this already in
tb_switch_tmu_configure().

Signed-off-by: Mika Westerberg <[email protected]>
  • Loading branch information
westeri committed Jun 9, 2023
1 parent 4e7b495 commit ef34add
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions drivers/thunderbolt/tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,11 @@ static int tb_enable_tmu(struct tb_switch *sw)
* highest accuracy.
*/
if (tb_switch_is_clx_enabled(sw, TB_CL1))
tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_NORMAL, true);
ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_NORMAL, true);
else
tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, false);
ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, false);
if (ret)
return ret;

/* If it is already enabled in correct mode, don't touch it */
if (tb_switch_tmu_is_enabled(sw))
Expand Down
5 changes: 2 additions & 3 deletions drivers/thunderbolt/tb.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,8 @@ int tb_switch_tmu_init(struct tb_switch *sw);
int tb_switch_tmu_post_time(struct tb_switch *sw);
int tb_switch_tmu_disable(struct tb_switch *sw);
int tb_switch_tmu_enable(struct tb_switch *sw);
void tb_switch_tmu_configure(struct tb_switch *sw,
enum tb_switch_tmu_rate rate,
bool unidirectional);
int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_rate rate,
bool unidirectional);
/**
* tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
* @sw: Router whose TMU mode to check
Expand Down
13 changes: 8 additions & 5 deletions drivers/thunderbolt/tmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,6 @@ int tb_switch_tmu_enable(struct tb_switch *sw)
bool unidirectional = sw->tmu.unidirectional_request;
int ret;

if (unidirectional && !sw->tmu.has_ucap)
return -EOPNOTSUPP;

/*
* No need to enable TMU on devices that don't support CLx since on
* these devices e.g. Alpine Ridge and earlier, the TMU mode HiFi
Expand Down Expand Up @@ -724,10 +721,16 @@ int tb_switch_tmu_enable(struct tb_switch *sw)
*
* Selects the rate of the TMU and directionality (uni-directional or
* bi-directional). Must be called before tb_switch_tmu_enable().
*
* Returns %0 in success and negative errno otherwise.
*/
void tb_switch_tmu_configure(struct tb_switch *sw,
enum tb_switch_tmu_rate rate, bool unidirectional)
int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_rate rate,
bool unidirectional)
{
if (unidirectional && !sw->tmu.has_ucap)
return -EINVAL;

sw->tmu.unidirectional_request = unidirectional;
sw->tmu.rate_request = rate;
return 0;
}

0 comments on commit ef34add

Please sign in to comment.