Skip to content

Commit

Permalink
net: dsa: b53: mmap: Add device tree support
Browse files Browse the repository at this point in the history
Add device tree support to b53_mmap.c while keeping platform devices support.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Noltari authored and davem330 committed Mar 18, 2021
1 parent 7b78702 commit a5538a7
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions drivers/net/dsa/b53/b53_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <linux/bits.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/io.h>
Expand Down Expand Up @@ -228,11 +229,65 @@ static const struct b53_io_ops b53_mmap_ops = {
.write64 = b53_mmap_write64,
};

static int b53_mmap_probe_of(struct platform_device *pdev,
struct b53_platform_data **ppdata)
{
struct device_node *np = pdev->dev.of_node;
struct device_node *of_ports, *of_port;
struct device *dev = &pdev->dev;
struct b53_platform_data *pdata;
void __iomem *mem;

mem = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(mem))
return PTR_ERR(mem);

pdata = devm_kzalloc(dev, sizeof(struct b53_platform_data),
GFP_KERNEL);
if (!pdata)
return -ENOMEM;

pdata->regs = mem;
pdata->chip_id = BCM63XX_DEVICE_ID;
pdata->big_endian = of_property_read_bool(np, "big-endian");

of_ports = of_get_child_by_name(np, "ports");
if (!of_ports) {
dev_err(dev, "no ports child node found\n");
return -EINVAL;
}

for_each_available_child_of_node(of_ports, of_port) {
u32 reg;

if (of_property_read_u32(of_port, "reg", &reg))
continue;

if (reg < B53_CPU_PORT)
pdata->enabled_ports |= BIT(reg);
}

of_node_put(of_ports);
*ppdata = pdata;

return 0;
}

static int b53_mmap_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct b53_platform_data *pdata = pdev->dev.platform_data;
struct b53_mmap_priv *priv;
struct b53_device *dev;
int ret;

if (!pdata && np) {
ret = b53_mmap_probe_of(pdev, &pdata);
if (ret) {
dev_err(&pdev->dev, "OF probe error\n");
return ret;
}
}

if (!pdata)
return -EINVAL;
Expand Down

0 comments on commit a5538a7

Please sign in to comment.