soc: fsl: cpm1: qmc: Add support for child devices

QMC child devices support is needed to avoid orphan DT nodes that use a
simple DT phandle to reference a QMC channel.

Allow to instantiate child devices and also extend the API to get the
qmc_chan using a child device.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Link: https://lore.kernel.org/r/20231205152116.122512-7-herve.codina@bootlin.com
This commit is contained in:
Herve Codina 2023-12-05 16:21:03 +01:00
parent 48490dc367
commit ba3b7e4753
2 changed files with 73 additions and 20 deletions

View File

@ -1425,8 +1425,16 @@ static int qmc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, qmc);
/* Populate channel related devices */
ret = devm_of_platform_populate(qmc->dev);
if (ret)
goto err_disable_txrx;
return 0;
err_disable_txrx:
qmc_setbits32(qmc->scc_regs + SCC_GSMRL, 0);
err_disable_intr:
qmc_write16(qmc->scc_regs + SCC_SCCM, 0);
@ -1465,26 +1473,16 @@ static struct platform_driver qmc_driver = {
};
module_platform_driver(qmc_driver);
struct qmc_chan *qmc_chan_get_byphandle(struct device_node *np, const char *phandle_name)
static struct qmc_chan *qmc_chan_get_from_qmc(struct device_node *qmc_np, unsigned int chan_index)
{
struct of_phandle_args out_args;
struct platform_device *pdev;
struct qmc_chan *qmc_chan;
struct qmc *qmc;
int ret;
ret = of_parse_phandle_with_fixed_args(np, phandle_name, 1, 0,
&out_args);
if (ret < 0)
return ERR_PTR(ret);
if (!of_match_node(qmc_driver.driver.of_match_table, out_args.np)) {
of_node_put(out_args.np);
if (!of_match_node(qmc_driver.driver.of_match_table, qmc_np))
return ERR_PTR(-EINVAL);
}
pdev = of_find_device_by_node(out_args.np);
of_node_put(out_args.np);
pdev = of_find_device_by_node(qmc_np);
if (!pdev)
return ERR_PTR(-ENODEV);
@ -1494,17 +1492,12 @@ struct qmc_chan *qmc_chan_get_byphandle(struct device_node *np, const char *phan
return ERR_PTR(-EPROBE_DEFER);
}
if (out_args.args_count != 1) {
if (chan_index >= ARRAY_SIZE(qmc->chans)) {
platform_device_put(pdev);
return ERR_PTR(-EINVAL);
}
if (out_args.args[0] >= ARRAY_SIZE(qmc->chans)) {
platform_device_put(pdev);
return ERR_PTR(-EINVAL);
}
qmc_chan = qmc->chans[out_args.args[0]];
qmc_chan = qmc->chans[chan_index];
if (!qmc_chan) {
platform_device_put(pdev);
return ERR_PTR(-ENOENT);
@ -1512,8 +1505,44 @@ struct qmc_chan *qmc_chan_get_byphandle(struct device_node *np, const char *phan
return qmc_chan;
}
struct qmc_chan *qmc_chan_get_byphandle(struct device_node *np, const char *phandle_name)
{
struct of_phandle_args out_args;
struct qmc_chan *qmc_chan;
int ret;
ret = of_parse_phandle_with_fixed_args(np, phandle_name, 1, 0,
&out_args);
if (ret < 0)
return ERR_PTR(ret);
if (out_args.args_count != 1) {
of_node_put(out_args.np);
return ERR_PTR(-EINVAL);
}
qmc_chan = qmc_chan_get_from_qmc(out_args.np, out_args.args[0]);
of_node_put(out_args.np);
return qmc_chan;
}
EXPORT_SYMBOL(qmc_chan_get_byphandle);
struct qmc_chan *qmc_chan_get_bychild(struct device_node *np)
{
struct device_node *qmc_np;
u32 chan_index;
int ret;
qmc_np = np->parent;
ret = of_property_read_u32(np, "reg", &chan_index);
if (ret)
return ERR_PTR(-EINVAL);
return qmc_chan_get_from_qmc(qmc_np, chan_index);
}
EXPORT_SYMBOL(qmc_chan_get_bychild);
void qmc_chan_put(struct qmc_chan *chan)
{
put_device(chan->qmc->dev);
@ -1550,6 +1579,28 @@ struct qmc_chan *devm_qmc_chan_get_byphandle(struct device *dev,
}
EXPORT_SYMBOL(devm_qmc_chan_get_byphandle);
struct qmc_chan *devm_qmc_chan_get_bychild(struct device *dev,
struct device_node *np)
{
struct qmc_chan *qmc_chan;
struct qmc_chan **dr;
dr = devres_alloc(devm_qmc_chan_release, sizeof(*dr), GFP_KERNEL);
if (!dr)
return ERR_PTR(-ENOMEM);
qmc_chan = qmc_chan_get_bychild(np);
if (!IS_ERR(qmc_chan)) {
*dr = qmc_chan;
devres_add(dev, dr);
} else {
devres_free(dr);
}
return qmc_chan;
}
EXPORT_SYMBOL(devm_qmc_chan_get_bychild);
MODULE_AUTHOR("Herve Codina <herve.codina@bootlin.com>");
MODULE_DESCRIPTION("CPM QMC driver");
MODULE_LICENSE("GPL");

View File

@ -17,9 +17,11 @@ struct device;
struct qmc_chan;
struct qmc_chan *qmc_chan_get_byphandle(struct device_node *np, const char *phandle_name);
struct qmc_chan *qmc_chan_get_bychild(struct device_node *np);
void qmc_chan_put(struct qmc_chan *chan);
struct qmc_chan *devm_qmc_chan_get_byphandle(struct device *dev, struct device_node *np,
const char *phandle_name);
struct qmc_chan *devm_qmc_chan_get_bychild(struct device *dev, struct device_node *np);
enum qmc_mode {
QMC_TRANSPARENT,