Commit f03631da authored by Suzuki K Poulose's avatar Suzuki K Poulose Committed by Greg Kroah-Hartman

coresight: Introduce generic platform data helper

So far we have hard coded the DT platform parsing code in
every driver. Introduce generic helper to parse the information
provided by the firmware in a platform agnostic manner, in preparation
for the ACPI support.
Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a15dab75
...@@ -503,17 +503,14 @@ static int catu_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -503,17 +503,14 @@ static int catu_probe(struct amba_device *adev, const struct amba_id *id)
struct coresight_desc catu_desc; struct coresight_desc catu_desc;
struct coresight_platform_data *pdata = NULL; struct coresight_platform_data *pdata = NULL;
struct device *dev = &adev->dev; struct device *dev = &adev->dev;
struct device_node *np = dev->of_node;
void __iomem *base; void __iomem *base;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) { if (IS_ERR(pdata)) {
ret = PTR_ERR(pdata); ret = PTR_ERR(pdata);
goto out; goto out;
} }
dev->platform_data = pdata; dev->platform_data = pdata;
}
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata) { if (!drvdata) {
......
...@@ -732,14 +732,11 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -732,14 +732,11 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id)
struct etb_drvdata *drvdata; struct etb_drvdata *drvdata;
struct resource *res = &adev->res; struct resource *res = &adev->res;
struct coresight_desc desc = { 0 }; struct coresight_desc desc = { 0 };
struct device_node *np = adev->dev.of_node;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) if (IS_ERR(pdata))
return PTR_ERR(pdata); return PTR_ERR(pdata);
adev->dev.platform_data = pdata; adev->dev.platform_data = pdata;
}
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata) if (!drvdata)
......
...@@ -790,20 +790,16 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -790,20 +790,16 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
struct etm_drvdata *drvdata; struct etm_drvdata *drvdata;
struct resource *res = &adev->res; struct resource *res = &adev->res;
struct coresight_desc desc = { 0 }; struct coresight_desc desc = { 0 };
struct device_node *np = adev->dev.of_node;
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata) if (!drvdata)
return -ENOMEM; return -ENOMEM;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) if (IS_ERR(pdata))
return PTR_ERR(pdata); return PTR_ERR(pdata);
adev->dev.platform_data = pdata; adev->dev.platform_data = pdata;
}
drvdata->use_cp14 = fwnode_property_read_bool(dev->fwnode, "arm,cp14"); drvdata->use_cp14 = fwnode_property_read_bool(dev->fwnode, "arm,cp14");
dev_set_drvdata(dev, drvdata); dev_set_drvdata(dev, drvdata);
......
...@@ -1084,18 +1084,15 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -1084,18 +1084,15 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
struct etmv4_drvdata *drvdata; struct etmv4_drvdata *drvdata;
struct resource *res = &adev->res; struct resource *res = &adev->res;
struct coresight_desc desc = { 0 }; struct coresight_desc desc = { 0 };
struct device_node *np = adev->dev.of_node;
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata) if (!drvdata)
return -ENOMEM; return -ENOMEM;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) if (IS_ERR(pdata))
return PTR_ERR(pdata); return PTR_ERR(pdata);
adev->dev.platform_data = pdata; adev->dev.platform_data = pdata;
}
dev_set_drvdata(dev, drvdata); dev_set_drvdata(dev, drvdata);
......
...@@ -187,14 +187,11 @@ static int funnel_probe(struct device *dev, struct resource *res) ...@@ -187,14 +187,11 @@ static int funnel_probe(struct device *dev, struct resource *res)
struct coresight_platform_data *pdata = NULL; struct coresight_platform_data *pdata = NULL;
struct funnel_drvdata *drvdata; struct funnel_drvdata *drvdata;
struct coresight_desc desc = { 0 }; struct coresight_desc desc = { 0 };
struct device_node *np = dev->of_node;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) if (IS_ERR(pdata))
return PTR_ERR(pdata); return PTR_ERR(pdata);
dev->platform_data = pdata; dev->platform_data = pdata;
}
if (is_of_node(dev_fwnode(dev)) && if (is_of_node(dev_fwnode(dev)) &&
of_device_is_compatible(dev->of_node, "arm,coresight-funnel")) of_device_is_compatible(dev->of_node, "arm,coresight-funnel"))
......
...@@ -230,23 +230,16 @@ static int of_coresight_parse_endpoint(struct device *dev, ...@@ -230,23 +230,16 @@ static int of_coresight_parse_endpoint(struct device *dev,
return ret; return ret;
} }
struct coresight_platform_data * static int of_get_coresight_platform_data(struct device *dev,
of_get_coresight_platform_data(struct device *dev, struct coresight_platform_data *pdata)
const struct device_node *node)
{ {
int ret = 0; int ret = 0;
struct coresight_platform_data *pdata;
struct coresight_connection *conn; struct coresight_connection *conn;
struct device_node *ep = NULL; struct device_node *ep = NULL;
const struct device_node *parent = NULL; const struct device_node *parent = NULL;
bool legacy_binding = false; bool legacy_binding = false;
struct device_node *node = dev->of_node;
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return ERR_PTR(-ENOMEM);
/* Use device name as sysfs handle */
pdata->name = dev_name(dev);
pdata->cpu = of_coresight_get_cpu(node); pdata->cpu = of_coresight_get_cpu(node);
/* Get the number of input and output port for this component */ /* Get the number of input and output port for this component */
...@@ -254,11 +247,11 @@ of_get_coresight_platform_data(struct device *dev, ...@@ -254,11 +247,11 @@ of_get_coresight_platform_data(struct device *dev,
/* If there are no output connections, we are done */ /* If there are no output connections, we are done */
if (!pdata->nr_outport) if (!pdata->nr_outport)
return pdata; return 0;
ret = coresight_alloc_conns(dev, pdata); ret = coresight_alloc_conns(dev, pdata);
if (ret) if (ret)
return ERR_PTR(ret); return ret;
parent = of_coresight_get_output_ports_node(node); parent = of_coresight_get_output_ports_node(node);
/* /*
...@@ -292,11 +285,46 @@ of_get_coresight_platform_data(struct device *dev, ...@@ -292,11 +285,46 @@ of_get_coresight_platform_data(struct device *dev,
case 0: case 0:
break; break;
default: default:
return ERR_PTR(ret); return ret;
} }
} }
return pdata; return 0;
}
#else
static inline int
of_get_coresight_platform_data(struct device *dev,
struct coresight_platform_data *pdata)
{
return -ENOENT;
} }
EXPORT_SYMBOL_GPL(of_get_coresight_platform_data);
#endif #endif
struct coresight_platform_data *
coresight_get_platform_data(struct device *dev)
{
int ret = -ENOENT;
struct coresight_platform_data *pdata;
struct fwnode_handle *fwnode = dev_fwnode(dev);
if (IS_ERR_OR_NULL(fwnode))
goto error;
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) {
ret = -ENOMEM;
goto error;
}
/* Use device name as sysfs handle */
pdata->name = dev_name(dev);
if (is_of_node(fwnode))
ret = of_get_coresight_platform_data(dev, pdata);
if (!ret)
return pdata;
error:
return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(coresight_get_platform_data);
...@@ -177,15 +177,12 @@ static int replicator_probe(struct device *dev, struct resource *res) ...@@ -177,15 +177,12 @@ static int replicator_probe(struct device *dev, struct resource *res)
struct coresight_platform_data *pdata = NULL; struct coresight_platform_data *pdata = NULL;
struct replicator_drvdata *drvdata; struct replicator_drvdata *drvdata;
struct coresight_desc desc = { 0 }; struct coresight_desc desc = { 0 };
struct device_node *np = dev->of_node;
void __iomem *base; void __iomem *base;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) if (IS_ERR(pdata))
return PTR_ERR(pdata); return PTR_ERR(pdata);
dev->platform_data = pdata; dev->platform_data = pdata;
}
if (is_of_node(dev_fwnode(dev)) && if (is_of_node(dev_fwnode(dev)) &&
of_device_is_compatible(dev->of_node, "arm,coresight-replicator")) of_device_is_compatible(dev->of_node, "arm,coresight-replicator"))
......
...@@ -809,14 +809,11 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -809,14 +809,11 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
struct resource ch_res; struct resource ch_res;
size_t bitmap_size; size_t bitmap_size;
struct coresight_desc desc = { 0 }; struct coresight_desc desc = { 0 };
struct device_node *np = adev->dev.of_node;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) if (IS_ERR(pdata))
return PTR_ERR(pdata); return PTR_ERR(pdata);
adev->dev.platform_data = pdata; adev->dev.platform_data = pdata;
}
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata) if (!drvdata)
return -ENOMEM; return -ENOMEM;
......
...@@ -397,16 +397,13 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -397,16 +397,13 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
struct tmc_drvdata *drvdata; struct tmc_drvdata *drvdata;
struct resource *res = &adev->res; struct resource *res = &adev->res;
struct coresight_desc desc = { 0 }; struct coresight_desc desc = { 0 };
struct device_node *np = adev->dev.of_node;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) { if (IS_ERR(pdata)) {
ret = PTR_ERR(pdata); ret = PTR_ERR(pdata);
goto out; goto out;
} }
adev->dev.platform_data = pdata; adev->dev.platform_data = pdata;
}
ret = -ENOMEM; ret = -ENOMEM;
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
......
...@@ -124,14 +124,11 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -124,14 +124,11 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
struct tpiu_drvdata *drvdata; struct tpiu_drvdata *drvdata;
struct resource *res = &adev->res; struct resource *res = &adev->res;
struct coresight_desc desc = { 0 }; struct coresight_desc desc = { 0 };
struct device_node *np = adev->dev.of_node;
if (np) { pdata = coresight_get_platform_data(dev);
pdata = of_get_coresight_platform_data(dev, np);
if (IS_ERR(pdata)) if (IS_ERR(pdata))
return PTR_ERR(pdata); return PTR_ERR(pdata);
adev->dev.platform_data = pdata; dev->platform_data = pdata;
}
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata) if (!drvdata)
......
...@@ -294,14 +294,11 @@ static inline void coresight_disclaim_device_unlocked(void __iomem *base) {} ...@@ -294,14 +294,11 @@ static inline void coresight_disclaim_device_unlocked(void __iomem *base) {}
#ifdef CONFIG_OF #ifdef CONFIG_OF
extern int of_coresight_get_cpu(const struct device_node *node); extern int of_coresight_get_cpu(const struct device_node *node);
extern struct coresight_platform_data *
of_get_coresight_platform_data(struct device *dev,
const struct device_node *node);
#else #else
static inline int of_coresight_get_cpu(const struct device_node *node) static inline int of_coresight_get_cpu(const struct device_node *node)
{ return 0; } { return 0; }
static inline struct coresight_platform_data *of_get_coresight_platform_data(
struct device *dev, const struct device_node *node) { return NULL; }
#endif #endif
struct coresight_platform_data *coresight_get_platform_data(struct device *dev);
#endif #endif
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