zynqmp: pm: Reimplement clock get parent EEMI API

Clock get parent EEMI API is reimplemented to use system-level clock
and pll EEMI APIs rather than direct MMIO read/write accesses to clock
and pll control registers.
Since linux still uses clock set parent API to get pre_src, post_src, div2
and bypasss, in the implementation of pm_clock_get_parent() we need to
workaround this by distinguishing two cases:
1) if the given clock ID corresponds to a PLL-related clock ID (*_PRE_SRC,
   *_POST_SRC, *_INT_MUX or *_PLL clock IDs); or
2) given clock ID is truly an on-chip clock.
For case 1) we'll map the call onto PLL-specific EEMI API with the
respective parameter ID. For case 2) the call is passed to the PMU.

Signed-off-by: Mirela Simonovic <mirela.simonovic@aggios.com>
Acked-by: Will Wong <WILLW@xilinx.com>
Signed-off-by: Jolly Shah <jollys@xilinx.com>
This commit is contained in:
Jolly Shah 2019-01-02 13:44:25 -08:00
parent be48511e79
commit b6c56bdb0c
3 changed files with 44 additions and 42 deletions

View File

@ -2710,51 +2710,36 @@ enum pm_ret_status pm_clock_pll_set_parent(struct pm_pll *pll,
} }
/** /**
* pm_api_clock_getparent - Get the clock parent for given id * pm_clock_pll_get_parent - Get mux select value of PLL-related clock parent
* @clock_id Id of the clock * @pll Target PLL structure
* @parent_idx parent index * @clock_id Id of the clock
* @parent_index parent index (=mux select value)
* *
* This function is used by master to get parent index * This function is used by master to get parent index for PLL-related clock.
* for any clock.
* *
* Return: Returns status, either success or error+reason. * Return: Returns status, either success or error+reason.
*/ */
enum pm_ret_status pm_api_clock_getparent(unsigned int clock_id, enum pm_ret_status pm_clock_pll_get_parent(struct pm_pll *pll,
unsigned int *parent_idx) enum clock_id clock_id,
unsigned int *parent_index)
{ {
enum pm_ret_status ret = PM_RET_SUCCESS; if (!pll)
struct pm_clock_node *nodes;
uint8_t num_nodes;
unsigned int reg, val;
uint8_t i = 0, offset = NA_SHIFT, width = NA_WIDTH;
if (!pm_clock_valid(clock_id))
return PM_RET_ERROR_ARGS; return PM_RET_ERROR_ARGS;
if (pll->pre_src == clock_id)
if (pm_clock_type(clock_id) != CLK_TYPE_OUTPUT) return pm_pll_get_parameter(pll->nid, PM_PLL_PARAM_PRE_SRC,
return PM_RET_ERROR_NOTSUPPORTED; parent_index);
if (pll->post_src == clock_id)
nodes = *clocks[clock_id].nodes; return pm_pll_get_parameter(pll->nid, PM_PLL_PARAM_POST_SRC,
num_nodes = clocks[clock_id].num_nodes; parent_index);
if (pll->div2 == clock_id)
for (i = 0; i < num_nodes; i++) { return pm_pll_get_parameter(pll->nid, PM_PLL_PARAM_DIV2,
if (nodes->type == TYPE_MUX) { parent_index);
offset = nodes->offset; if (pll->bypass == clock_id) {
width = nodes->width; *parent_index = 0;
} return PM_RET_SUCCESS;
nodes++;
} }
if (width == NA_WIDTH)
return PM_RET_ERROR_NOTSUPPORTED;
reg = clocks[clock_id].control_reg; return PM_RET_ERROR_ARGS;
ret = pm_mmio_read(reg, &val);
val >>= offset;
val &= ((1U << width) - 1);
*parent_idx = val;
return ret;
} }
/** /**

View File

@ -304,8 +304,9 @@ enum pm_ret_status pm_clock_pll_get_state(struct pm_pll *pll,
enum pm_ret_status pm_clock_pll_set_parent(struct pm_pll *pll, enum pm_ret_status pm_clock_pll_set_parent(struct pm_pll *pll,
enum clock_id clock_id, enum clock_id clock_id,
unsigned int parent_index); unsigned int parent_index);
enum pm_ret_status pm_api_clock_getparent(unsigned int clock_id, enum pm_ret_status pm_clock_pll_get_parent(struct pm_pll *pll,
unsigned int *parent_idx); enum clock_id clock_id,
unsigned int *parent_index);
enum pm_ret_status pm_clock_set_pll_mode(enum clock_id clock_id, enum pm_ret_status pm_clock_set_pll_mode(enum clock_id clock_id,
unsigned int mode); unsigned int mode);
enum pm_ret_status pm_clock_get_pll_mode(enum clock_id clock_id, enum pm_ret_status pm_clock_get_pll_mode(enum clock_id clock_id,

View File

@ -1113,7 +1113,7 @@ enum pm_ret_status pm_clock_setparent(unsigned int clock_id,
/** /**
* pm_clock_getparent - Get the clock parent for given id * pm_clock_getparent - Get the clock parent for given id
* @clock_id: Id of the clock * @clock_id: Id of the clock
* @parent_id: parent id * @parent_index: parent index
* *
* This function is used by master to get parent index * This function is used by master to get parent index
* for any clock. * for any clock.
@ -1121,9 +1121,25 @@ enum pm_ret_status pm_clock_setparent(unsigned int clock_id,
* Return: Returns status, either success or error+reason. * Return: Returns status, either success or error+reason.
*/ */
enum pm_ret_status pm_clock_getparent(unsigned int clock_id, enum pm_ret_status pm_clock_getparent(unsigned int clock_id,
unsigned int *parent_id) unsigned int *parent_index)
{ {
return pm_api_clock_getparent(clock_id, parent_id); struct pm_pll *pll;
uint32_t payload[PAYLOAD_ARG_CNT];
enum pm_ret_status status;
/* First try to handle it as a PLL */
pll = pm_clock_get_pll_by_related_clk(clock_id);
if (pll)
return pm_clock_pll_get_parent(pll, clock_id, parent_index);
/* Check if clock ID is a valid on-chip clock */
status = pm_clock_id_is_valid(clock_id);
if (status != PM_RET_SUCCESS)
return status;
/* Send request to the PMU */
PM_PACK_PAYLOAD2(payload, PM_CLOCK_GETPARENT, clock_id);
return pm_ipi_send_sync(primary_proc, payload, parent_index, 1);
} }
/** /**