/* * struct imx8qxp_lpcg_data - Description of one LPCG clock * @id: clock ID * @name: clock name * @parent: parent clock name * @flags: common clock flags * @offset: offset of this LPCG clock * @bit_idx: bit index of this LPCG clock * @hw_gate: whether supports HW autogate * * This structure describes one LPCG clock
*/ struct imx8qxp_lpcg_data { int id; char *name; char *parent; unsignedlong flags;
u32 offset;
u8 bit_idx; bool hw_gate;
};
/* * struct imx8qxp_ss_lpcg - Description of one subsystem LPCG clocks * @lpcg: LPCG clocks array of one subsystem * @num_lpcg: the number of LPCG clocks * @num_max: the maximum number of LPCG clocks * * This structure describes each subsystem LPCG clocks information * which then will be used to create respective LPCGs clocks
*/ struct imx8qxp_ss_lpcg { conststruct imx8qxp_lpcg_data *lpcg;
u8 num_lpcg;
u8 num_max;
};
if (idx >= hw_data->num) {
pr_err("%s: invalid index %u\n", __func__, idx); return ERR_PTR(-EINVAL);
}
return hw_data->hws[idx];
}
staticint imx_lpcg_parse_clks_from_dt(struct platform_device *pdev, struct device_node *np)
{ constchar *output_names[IMX_LPCG_MAX_CLKS]; constchar *parent_names[IMX_LPCG_MAX_CLKS]; unsignedint bit_offset[IMX_LPCG_MAX_CLKS]; struct clk_hw_onecell_data *clk_data; struct clk_hw **clk_hws; void __iomem *base; int count; int idx; int ret; int i;
if (!of_device_is_compatible(np, "fsl,imx8qxp-lpcg")) return -EINVAL;
base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) return PTR_ERR(base);
count = of_property_count_u32_elems(np, "clock-indices"); if (count < 0) {
dev_err(&pdev->dev, "failed to count clocks\n"); return -EINVAL;
}
/* * A trick here is that we set the num of clks to the MAX instead * of the count from clock-indices because one LPCG supports up to * 8 clock outputs which each of them is fixed to 4 bits. Then we can * easily get the clock by clk-indices (bit-offset) / 4. * And the cost is very limited few pointers.
*/
for (i = 0; i < count; i++) {
idx = bit_offset[i] / 4; if (idx >= IMX_LPCG_MAX_CLKS) {
dev_warn(&pdev->dev, "invalid bit offset of clock %d\n",
i);
ret = -EINVAL; goto unreg;
}
clk_hws[idx] = imx_clk_lpcg_scu_dev(&pdev->dev, output_names[i],
parent_names[i], 0, base,
bit_offset[i], false); if (IS_ERR(clk_hws[idx])) {
dev_warn(&pdev->dev, "failed to register clock %d\n",
idx);
ret = PTR_ERR(clk_hws[idx]); goto unreg;
}
}
ret = devm_of_clk_add_hw_provider(&pdev->dev, imx_lpcg_of_clk_src_get,
clk_data); if (ret) goto unreg;
pm_runtime_put_autosuspend(&pdev->dev);
return 0;
unreg: while (--i >= 0) {
idx = bit_offset[i] / 4; if (clk_hws[idx])
imx_clk_lpcg_scu_unregister(clk_hws[idx]);
}
/* try new binding to parse clocks from device tree first */
ret = imx_lpcg_parse_clks_from_dt(pdev, np); if (!ret) return 0;
ss_lpcg = of_device_get_match_data(dev); if (!ss_lpcg) return -ENODEV;
/* * Please don't replace this with devm_platform_ioremap_resource. * * devm_platform_ioremap_resource calls devm_ioremap_resource which * differs from devm_ioremap by also calling devm_request_mem_region * and preventing other mappings in the same area. * * On imx8 the LPCG nodes map entire subsystems and overlap * peripherals, this means that using devm_platform_ioremap_resource * will cause many devices to fail to probe including serial ports.
*/
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) return -EINVAL;
base = devm_ioremap(dev, res->start, resource_size(res)); if (!base) return -ENOMEM;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.