Skip to content

Commit bc163ba

Browse files
robherringbroonie
authored andcommitted
ASoC: Use of_reserved_mem_region_to_resource() for "memory-region"
Use the newly added of_reserved_mem_region_to_resource() function to handle "memory-region" properties. Signed-off-by: Rob Herring (Arm) <[email protected]> Reviewed-by: Tzung-Bi Shih <[email protected]> Reviewed-by: Cheng-Yi Chiang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent baee26a commit bc163ba

File tree

4 files changed

+22
-66
lines changed

4 files changed

+22
-66
lines changed

sound/soc/codecs/cros_ec_codec.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/module.h>
1919
#include <linux/of.h>
2020
#include <linux/of_address.h>
21+
#include <linux/of_reserved_mem.h>
2122
#include <linux/platform_data/cros_ec_commands.h>
2223
#include <linux/platform_data/cros_ec_proto.h>
2324
#include <linux/platform_device.h>
@@ -961,7 +962,6 @@ static int cros_ec_codec_platform_probe(struct platform_device *pdev)
961962
struct ec_response_ec_codec_get_capabilities r;
962963
int ret;
963964
#ifdef CONFIG_OF
964-
struct device_node *node;
965965
struct resource res;
966966
u64 ec_shm_size;
967967
const __be32 *regaddr_p;
@@ -981,22 +981,18 @@ static int cros_ec_codec_platform_probe(struct platform_device *pdev)
981981
priv->ec_shm_addr, priv->ec_shm_len);
982982
}
983983

984-
node = of_parse_phandle(dev->of_node, "memory-region", 0);
985-
if (node) {
986-
ret = of_address_to_resource(node, 0, &res);
987-
if (!ret) {
988-
priv->ap_shm_phys_addr = res.start;
989-
priv->ap_shm_len = resource_size(&res);
990-
priv->ap_shm_addr =
991-
(uint64_t)(uintptr_t)devm_ioremap_wc(
992-
dev, priv->ap_shm_phys_addr,
993-
priv->ap_shm_len);
994-
priv->ap_shm_last_alloc = priv->ap_shm_phys_addr;
995-
996-
dev_dbg(dev, "ap_shm_phys_addr=%#llx len=%#x\n",
997-
priv->ap_shm_phys_addr, priv->ap_shm_len);
998-
}
999-
of_node_put(node);
984+
ret = of_reserved_mem_region_to_resource(dev->of_node, 0, &res);
985+
if (!ret) {
986+
priv->ap_shm_phys_addr = res.start;
987+
priv->ap_shm_len = resource_size(&res);
988+
priv->ap_shm_addr =
989+
(uint64_t)(uintptr_t)devm_ioremap_wc(
990+
dev, priv->ap_shm_phys_addr,
991+
priv->ap_shm_len);
992+
priv->ap_shm_last_alloc = priv->ap_shm_phys_addr;
993+
994+
dev_dbg(dev, "ap_shm_phys_addr=%#llx len=%#x\n",
995+
priv->ap_shm_phys_addr, priv->ap_shm_len);
1000996
}
1001997
#endif
1002998

sound/soc/sof/imx/imx-common.c

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,8 @@ static int imx_region_name_to_blk_type(const char *region_name)
282282
static int imx_parse_ioremap_memory(struct snd_sof_dev *sdev)
283283
{
284284
const struct imx_chip_info *chip_info;
285-
struct reserved_mem *reserved;
286285
struct platform_device *pdev;
287-
struct device_node *res_np;
288-
phys_addr_t base, size;
289-
struct resource *res;
286+
struct resource *res, _res;
290287
int i, blk_type, ret;
291288

292289
pdev = to_platform_device(sdev->dev);
@@ -307,37 +304,18 @@ static int imx_parse_ioremap_memory(struct snd_sof_dev *sdev)
307304
"failed to fetch %s resource\n",
308305
chip_info->memory[i].name);
309306

310-
base = res->start;
311-
size = resource_size(res);
312307
} else {
313-
ret = of_property_match_string(pdev->dev.of_node,
314-
"memory-region-names",
315-
chip_info->memory[i].name);
308+
ret = of_reserved_mem_region_to_resource_byname(pdev->dev.of_node,
309+
chip_info->memory[i].name,
310+
&_res);
316311
if (ret < 0)
317312
return dev_err_probe(sdev->dev, ret,
318-
"no valid index for %s\n",
313+
"no valid entry for %s\n",
319314
chip_info->memory[i].name);
320-
321-
res_np = of_parse_phandle(pdev->dev.of_node,
322-
"memory-region",
323-
ret);
324-
if (!res_np)
325-
return dev_err_probe(sdev->dev, -ENODEV,
326-
"failed to parse phandle %s\n",
327-
chip_info->memory[i].name);
328-
329-
reserved = of_reserved_mem_lookup(res_np);
330-
of_node_put(res_np);
331-
if (!reserved)
332-
return dev_err_probe(sdev->dev, -ENODEV,
333-
"failed to get %s reserved\n",
334-
chip_info->memory[i].name);
335-
336-
base = reserved->base;
337-
size = reserved->size;
315+
res = &_res;
338316
}
339317

340-
sdev->bar[blk_type] = devm_ioremap(sdev->dev, base, size);
318+
sdev->bar[blk_type] = devm_ioremap_resource(sdev->dev, res);
341319
if (!sdev->bar[blk_type])
342320
return dev_err_probe(sdev->dev,
343321
-ENOMEM,

sound/soc/sof/mediatek/mt8186/mt8186.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/delay.h>
1313
#include <linux/firmware.h>
1414
#include <linux/io.h>
15-
#include <linux/of_address.h>
1615
#include <linux/of_irq.h>
1716
#include <linux/of_platform.h>
1817
#include <linux/of_reserved_mem.h>
@@ -46,7 +45,6 @@ static int platform_parse_resource(struct platform_device *pdev, void *data)
4645
{
4746
struct resource *mmio;
4847
struct resource res;
49-
struct device_node *mem_region;
5048
struct device *dev = &pdev->dev;
5149
struct mtk_adsp_chip_info *adsp = data;
5250
int ret;
@@ -57,14 +55,7 @@ static int platform_parse_resource(struct platform_device *pdev, void *data)
5755
return ret;
5856
}
5957

60-
mem_region = of_parse_phandle(dev->of_node, "memory-region", 1);
61-
if (!mem_region) {
62-
dev_err(dev, "no memory-region sysmem phandle\n");
63-
return -ENODEV;
64-
}
65-
66-
ret = of_address_to_resource(mem_region, 0, &res);
67-
of_node_put(mem_region);
58+
ret = of_reserved_mem_region_to_resource(dev->of_node, 1, &res);
6859
if (ret) {
6960
dev_err(dev, "of_address_to_resource sysmem failed\n");
7061
return ret;

sound/soc/sof/mediatek/mt8195/mt8195.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/delay.h>
1313
#include <linux/firmware.h>
1414
#include <linux/io.h>
15-
#include <linux/of_address.h>
1615
#include <linux/of_irq.h>
1716
#include <linux/of_platform.h>
1817
#include <linux/of_reserved_mem.h>
@@ -46,7 +45,6 @@ static int platform_parse_resource(struct platform_device *pdev, void *data)
4645
{
4746
struct resource *mmio;
4847
struct resource res;
49-
struct device_node *mem_region;
5048
struct device *dev = &pdev->dev;
5149
struct mtk_adsp_chip_info *adsp = data;
5250
int ret;
@@ -57,14 +55,7 @@ static int platform_parse_resource(struct platform_device *pdev, void *data)
5755
return ret;
5856
}
5957

60-
mem_region = of_parse_phandle(dev->of_node, "memory-region", 1);
61-
if (!mem_region) {
62-
dev_err(dev, "no memory-region sysmem phandle\n");
63-
return -ENODEV;
64-
}
65-
66-
ret = of_address_to_resource(mem_region, 0, &res);
67-
of_node_put(mem_region);
58+
ret = of_reserved_mem_region_to_resource(dev->of_node, 1, &res);
6859
if (ret) {
6960
dev_err(dev, "of_address_to_resource sysmem failed\n");
7061
return ret;

0 commit comments

Comments
 (0)