Skip to content

[DM/FEATURE] Update platform depends rules #9576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions components/drivers/core/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ static rt_bool_t platform_match(rt_driver_t drv, rt_device_t dev)
{
struct rt_platform_driver *pdrv = rt_container_of(drv, struct rt_platform_driver, parent);
struct rt_platform_device *pdev = rt_container_of(dev, struct rt_platform_device, parent);

#ifdef RT_USING_OFW
struct rt_ofw_node *np = dev->ofw_node;

/* 1、match with ofw node */
if (np)
{
#ifdef RT_USING_OFW
pdev->id = rt_ofw_node_match(np, pdrv->ids);

#else
pdev->id = RT_NULL;
#endif
if (pdev->id)
{
return RT_TRUE;
}
}
#endif

/* 2、match with name */
if (pdev->name && pdrv->name)
Expand Down Expand Up @@ -123,7 +123,13 @@ static rt_err_t platform_probe(rt_device_t dev)

if (err && err != -RT_EEMPTY)
{
LOG_E("Attach power domain error = %s in device %s", pdev->name, rt_strerror(err));
LOG_E("Attach power domain error = %s in device %s", rt_strerror(err),
#ifdef RT_USING_OFW
(pdev->name && pdev->name[0]) ? pdev->name : rt_ofw_node_full_name(np)
#else
pdev->name
#endif
);

return err;
}
Expand Down
55 changes: 55 additions & 0 deletions components/drivers/core/platform_ofw.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <drivers/ofw_io.h>
#include <drivers/ofw_fdt.h>
#include <drivers/platform.h>
#include <drivers/core/bus.h>
#include <drivers/core/dm.h>

#include "../ofw/ofw_internal.h"
Expand Down Expand Up @@ -161,6 +162,7 @@ static rt_err_t platform_ofw_device_probe_once(struct rt_ofw_node *parent_np)
}

pdev->dev_id = ofw_alias_node_id(np);
np->dev = &pdev->parent;
LOG_D("%s register to bus", np->full_name);

rt_platform_device_register(pdev);
Expand Down Expand Up @@ -199,6 +201,53 @@ rt_err_t rt_platform_ofw_device_probe_child(struct rt_ofw_node *np)
return err;
}

rt_err_t rt_platform_ofw_request(struct rt_ofw_node *np)
{
rt_err_t err;

if (np)
{
struct rt_device *dev = np->dev;

if (dev)
{
/* Was create */
if (dev->drv)
{
/* Was probe OK */
err = RT_EOK;
}
else
{
err = rt_bus_reload_driver_device(dev->bus, dev);
}
}
else
{
struct rt_platform_device *pdev = alloc_ofw_platform_device(np);

if (pdev)
{
pdev->dev_id = ofw_alias_node_id(np);
np->dev = &pdev->parent;
LOG_D("%s register to bus", np->full_name);

err = rt_platform_device_register(pdev);
}
else
{
err = -RT_ENOMEM;
}
}
}
else
{
err = -RT_EINVAL;
}

return err;
}

static int platform_ofw_device_probe(void)
{
rt_err_t err = RT_EOK;
Expand All @@ -218,6 +267,12 @@ static int platform_ofw_device_probe(void)
rt_ofw_node_put(node);
}

if ((node = rt_ofw_find_node_by_path("/clocks")))
{
platform_ofw_device_probe_once(node);
rt_ofw_node_put(node);
}

rt_ofw_node_get(ofw_node_chosen);
if ((node = rt_ofw_get_child_by_compatible(ofw_node_chosen, "simple-framebuffer")))
{
Expand Down
1 change: 1 addition & 0 deletions components/drivers/include/drivers/ofw.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct rt_ofw_node
/* phandles range from 1 to 2^32-2 (0xfffffffe) */
rt_phandle phandle;

struct rt_device *dev;
struct rt_ofw_prop *props;
struct rt_ofw_node *parent;
struct rt_ofw_node *child;
Expand Down
10 changes: 1 addition & 9 deletions components/drivers/include/drivers/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
#ifndef __PLATFORM_H__
#define __PLATFORM_H__

#ifdef RT_USING_OFW
#include <drivers/ofw.h>
#endif

#include <drivers/core/driver.h>

struct rt_platform_device
Expand All @@ -25,10 +22,7 @@ struct rt_platform_device
int dev_id;

const char *name;

#ifdef RT_USING_OFW
const struct rt_ofw_node_id *id;
#endif

void *priv;
};
Expand All @@ -38,10 +32,7 @@ struct rt_platform_driver
struct rt_driver parent;

const char *name;

#ifdef RT_USING_OFW
const struct rt_ofw_node_id *ids;
#endif

rt_err_t (*probe)(struct rt_platform_device *pdev);
rt_err_t (*remove)(struct rt_platform_device *pdev);
Expand All @@ -54,6 +45,7 @@ rt_err_t rt_platform_driver_register(struct rt_platform_driver *pdrv);
rt_err_t rt_platform_device_register(struct rt_platform_device *pdev);

rt_err_t rt_platform_ofw_device_probe_child(struct rt_ofw_node *np);
rt_err_t rt_platform_ofw_request(struct rt_ofw_node *np);
rt_err_t rt_platform_ofw_free(struct rt_platform_device *pdev);

#define RT_PLATFORM_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, platform, BUILIN)
Expand Down
9 changes: 2 additions & 7 deletions include/rtdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,10 @@ typedef int (*init_fn_t)(void);

/* init cpu, memory, interrupt-controller, bus... */
#define INIT_CORE_EXPORT(fn) INIT_EXPORT(fn, "1.0")
/* init pci/pcie, usb platform driver... */
#define INIT_FRAMEWORK_EXPORT(fn) INIT_EXPORT(fn, "1.1")
/* init sys-timer, clk, pinctrl... */
#define INIT_SUBSYS_EXPORT(fn) INIT_EXPORT(fn, "1.1")
/* init platform, user code... */
#define INIT_PLATFORM_EXPORT(fn) INIT_EXPORT(fn, "1.2")
/* init sys-timer, clk, pinctrl... */
#define INIT_SUBSYS_EARLY_EXPORT(fn) INIT_EXPORT(fn, "1.3.0")
#define INIT_SUBSYS_EXPORT(fn) INIT_EXPORT(fn, "1.3.1")
/* init early drivers */
#define INIT_DRIVER_EARLY_EXPORT(fn) INIT_EXPORT(fn, "1.4")

/* pre/device/component/env/app init routines will be called in init_thread */
/* components pre-initialization (pure software initialization) */
Expand Down
2 changes: 1 addition & 1 deletion libcpu/aarch64/common/psci.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,4 @@ static int psci_drv_register(void)

return 0;
}
INIT_FRAMEWORK_EXPORT(psci_drv_register);
INIT_PLATFORM_EXPORT(psci_drv_register);
Loading