Commit 7bc7caaf authored by Cristian Marussi's avatar Cristian Marussi Committed by Sudeep Holla

firmware: arm_scmi: Use common iterators in the clock protocol

Make SCMI clock protocol use the common iterator protocol helpers for
issuing the multi-part commands.

Link: https://lore.kernel.org/r/20220330150551.2573938-17-cristian.marussi@arm.comSigned-off-by: default avatarCristian Marussi <cristian.marussi@arm.com>
Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
parent 802b0bed
...@@ -164,81 +164,111 @@ static int rate_cmp_func(const void *_r1, const void *_r2) ...@@ -164,81 +164,111 @@ static int rate_cmp_func(const void *_r1, const void *_r2)
return 1; return 1;
} }
static int struct scmi_clk_ipriv {
scmi_clock_describe_rates_get(const struct scmi_protocol_handle *ph, u32 clk_id, u32 clk_id;
struct scmi_clock_info *clk) struct scmi_clock_info *clk;
{ };
u64 *rate = NULL;
int ret, cnt;
bool rate_discrete = false;
u32 tot_rate_cnt = 0, rates_flag;
u16 num_returned, num_remaining;
struct scmi_xfer *t;
struct scmi_msg_clock_describe_rates *clk_desc;
struct scmi_msg_resp_clock_describe_rates *rlist;
ret = ph->xops->xfer_get_init(ph, CLOCK_DESCRIBE_RATES, static void iter_clk_describe_prepare_message(void *message,
sizeof(*clk_desc), 0, &t); const unsigned int desc_index,
if (ret) const void *priv)
return ret; {
struct scmi_msg_clock_describe_rates *msg = message;
const struct scmi_clk_ipriv *p = priv;
clk_desc = t->tx.buf; msg->id = cpu_to_le32(p->clk_id);
rlist = t->rx.buf; /* Set the number of rates to be skipped/already read */
msg->rate_index = cpu_to_le32(desc_index);
}
do { static int
clk_desc->id = cpu_to_le32(clk_id); iter_clk_describe_update_state(struct scmi_iterator_state *st,
/* Set the number of rates to be skipped/already read */ const void *response, void *priv)
clk_desc->rate_index = cpu_to_le32(tot_rate_cnt); {
u32 flags;
struct scmi_clk_ipriv *p = priv;
const struct scmi_msg_resp_clock_describe_rates *r = response;
ret = ph->xops->do_xfer(ph, t); flags = le32_to_cpu(r->num_rates_flags);
if (ret) st->num_remaining = NUM_REMAINING(flags);
goto err; st->num_returned = NUM_RETURNED(flags);
p->clk->rate_discrete = RATE_DISCRETE(flags);
rates_flag = le32_to_cpu(rlist->num_rates_flags); return 0;
num_remaining = NUM_REMAINING(rates_flag); }
rate_discrete = RATE_DISCRETE(rates_flag);
num_returned = NUM_RETURNED(rates_flag);
if (tot_rate_cnt + num_returned > SCMI_MAX_NUM_RATES) { static int
dev_err(ph->dev, "No. of rates > MAX_NUM_RATES"); iter_clk_describe_process_response(const struct scmi_protocol_handle *ph,
const void *response,
struct scmi_iterator_state *st, void *priv)
{
int ret = 0;
struct scmi_clk_ipriv *p = priv;
const struct scmi_msg_resp_clock_describe_rates *r = response;
if (!p->clk->rate_discrete) {
switch (st->desc_index + st->loop_idx) {
case 0:
p->clk->range.min_rate = RATE_TO_U64(r->rate[0]);
break; break;
} case 1:
p->clk->range.max_rate = RATE_TO_U64(r->rate[1]);
if (!rate_discrete) { break;
clk->range.min_rate = RATE_TO_U64(rlist->rate[0]); case 2:
clk->range.max_rate = RATE_TO_U64(rlist->rate[1]); p->clk->range.step_size = RATE_TO_U64(r->rate[2]);
clk->range.step_size = RATE_TO_U64(rlist->rate[2]); break;
dev_dbg(ph->dev, "Min %llu Max %llu Step %llu Hz\n", default:
clk->range.min_rate, clk->range.max_rate, ret = -EINVAL;
clk->range.step_size);
break; break;
} }
} else {
u64 *rate = &p->clk->list.rates[st->desc_index + st->loop_idx];
rate = &clk->list.rates[tot_rate_cnt]; *rate = RATE_TO_U64(r->rate[st->loop_idx]);
for (cnt = 0; cnt < num_returned; cnt++, rate++) { p->clk->list.num_rates++;
*rate = RATE_TO_U64(rlist->rate[cnt]); //XXX dev_dbg(ph->dev, "Rate %llu Hz\n", *rate);
dev_dbg(ph->dev, "Rate %llu Hz\n", *rate); }
}
return ret;
}
tot_rate_cnt += num_returned; static int
scmi_clock_describe_rates_get(const struct scmi_protocol_handle *ph, u32 clk_id,
struct scmi_clock_info *clk)
{
int ret;
ph->xops->reset_rx_to_maxsz(ph, t); void *iter;
/* struct scmi_msg_clock_describe_rates *msg;
* check for both returned and remaining to avoid infinite struct scmi_iterator_ops ops = {
* loop due to buggy firmware .prepare_message = iter_clk_describe_prepare_message,
*/ .update_state = iter_clk_describe_update_state,
} while (num_returned && num_remaining); .process_response = iter_clk_describe_process_response,
};
struct scmi_clk_ipriv cpriv = {
.clk_id = clk_id,
.clk = clk,
};
iter = ph->hops->iter_response_init(ph, &ops, SCMI_MAX_NUM_RATES,
CLOCK_DESCRIBE_RATES,
sizeof(*msg), &cpriv);
if (IS_ERR(iter))
return PTR_ERR(iter);
ret = ph->hops->iter_response_run(iter);
if (ret)
return ret;
if (rate_discrete && rate) { if (!clk->rate_discrete) {
clk->list.num_rates = tot_rate_cnt; dev_dbg(ph->dev, "Min %llu Max %llu Step %llu Hz\n",
sort(clk->list.rates, tot_rate_cnt, sizeof(*rate), clk->range.min_rate, clk->range.max_rate,
rate_cmp_func, NULL); clk->range.step_size);
} else if (clk->list.num_rates) {
sort(clk->list.rates, clk->list.num_rates,
sizeof(clk->list.rates[0]), rate_cmp_func, NULL);
} }
clk->rate_discrete = rate_discrete;
err:
ph->xops->xfer_put(ph, t);
return ret; return ret;
} }
......
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