Skip to content

soundwire: stream: set peripheral frequency before programing port params - #5063

Closed
bardliao wants to merge 2 commits into
thesofproject:topic/sof-devfrom
bardliao:set_frequency
Closed

bardliao wants to merge 2 commits into
thesofproject:topic/sof-devfrom
bardliao:set_frequency

Conversation

@bardliao

Copy link
Copy Markdown
Collaborator

Currently, we set only peripheral frequency when the peripheral is initialized. However, curr_dr_freq may change after a stream is
prepared. set peripheral frequency before sdw_program_slave_port_params() to ensure peripheral frequency is correct when a stream starts.

Currently, we set only peripheral frequency when the peripheral is
initialized. However, curr_dr_freq may change after a stream is
prepared. Expose the function allow we set peripheral frequency when
needed.

Signed-off-by: Bard Liao <[email protected]>
@bardliao
bardliao requested review from plbossart and ujfalusi June 13, 2024 11:53

@ujfalusi ujfalusi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bardliao, @plbossart, amazing find!!

However the commit messages are in need for update.

Comment thread drivers/soundwire/bus.c
}

static int sdw_slave_set_frequency(struct sdw_slave *slave)
int sdw_slave_set_frequency(struct sdw_slave *slave)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reword the commit message, it is hard to follow.

Expose the sdw_slave_set_frequency() to allow re-programming the peripheral frequency to follow the curr_dr_freq, which can change after the stream is prepared.

Or something.

/* Program transport & port parameters for Slave(s) */
list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) {
list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
ret = sdw_slave_set_frequency(s_rt->slave);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my quick reading of the function, it will always program registers, even if they don't change, is that OK?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my quick reading of the function, it will always program registers, even if they don't change, is that OK?

Yes, it should be ok

list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
ret = sdw_slave_set_frequency(s_rt->slave);
if (ret < 0)
return ret;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message: it is a good practice if the "commit title" and the "commit message" alone can be understood, generally referring from the message to the title is not nice as one needs to connect the dots...

Message:
Update the peripheral frequency before setting the port params as the curr_dr_freq might have been changed since it's initialization.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message: it is a good practice if the "commit title" and the "commit message" alone can be understood, generally referring from the message to the title is not nice as one needs to connect the dots...

Message: Update the peripheral frequency before setting the port params as the curr_dr_freq might have been changed since it's initialization.

Updated

…calculated

Update the peripheral frequency before setting the port params as the
curr_dr_freq might have been changed since it's initialization.

Signed-off-by: Bard Liao <[email protected]>

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bardliao see my comments below, this PR is not quite right.

Comment thread drivers/soundwire/bus.h
int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
void sdw_compute_slave_ports(struct sdw_master_runtime *m_rt,
struct sdw_transport_data *t_data);
int sdw_slave_set_frequency(struct sdw_slave *slave);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, no this is not the right direction @bardliao

It is intentional that this initialization is done on startup. The base clock is programmed once, and then we use initial default clock scale registers.

If and when we implement support for the clock change, the only thing that will be updated will be the clock scale registers. The base will NEVER be updated because this breaks audio functionality.

So no I don't think this helper should be used when starting a stream. It's not what it was designed for.

/* Program transport & port parameters for Slave(s) */
list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) {
list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
ret = sdw_slave_set_frequency(s_rt->slave);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to check the clock frequency, it would be done by writing the same clock scale for all the peripherals on a link, and then we would do it atomically with a bank switch.

In other words, changing the clock is NOT related to the notion of stream. It's something that impacts all peripherals and managers.

@bardliao

Copy link
Copy Markdown
Collaborator Author

@plbossart The issue is that bus->params.curr_dr_freq will be assigned in sdw_compute_bus_params(). But we call sdw_slave_set_frequency() only when a peripheral is attached. And we set scale based on mclk and curr_dr_freq in sdw_slave_set_frequency(). The bus->params.curr_dr_freq is set to bus->params.max_dr_freq in sdw_bus_master_add(), and will be calculated in sdw_compute_bus_params() based on required bandwidth. It means peripherals may use a scale based on a wrong curr_dr_freq value.

@bardliao

Copy link
Copy Markdown
Collaborator Author

Close it as we will use single clock rate for now.

@bardliao bardliao closed this Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants