treewide: Try to avoid the preprocessor with OF_REAL

Convert some of these occurences to C code, where it is easy to do. This
should help encourage this approach to be used in new code.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2021-08-07 07:24:06 -06:00
parent 62470afed1
commit dcfc42b12f
21 changed files with 167 additions and 156 deletions

View File

@@ -55,8 +55,7 @@ ulong timer_get_boot_us(void)
/* The timer is available */
rate = timer_get_rate(gd->timer);
timer_get_count(gd->timer, &ticks);
#if CONFIG_IS_ENABLED(OF_REAL)
} else if (ret == -EAGAIN) {
} else if (CONFIG_IS_ENABLED(OF_REAL) && ret == -EAGAIN) {
/* We have been called so early that the DM is not ready,... */
ofnode node = offset_to_ofnode(-1);
struct rk_timer *timer = NULL;
@@ -79,7 +78,6 @@ ulong timer_get_boot_us(void)
debug("%s: could not read clock-frequency\n", __func__);
return 0;
}
#endif
} else {
return 0;
}
@@ -100,13 +98,13 @@ static u64 rockchip_timer_get_count(struct udevice *dev)
static int rockchip_clk_of_to_plat(struct udevice *dev)
{
#if CONFIG_IS_ENABLED(OF_REAL)
struct rockchip_timer_priv *priv = dev_get_priv(dev);
if (CONFIG_IS_ENABLED(OF_REAL)) {
struct rockchip_timer_priv *priv = dev_get_priv(dev);
priv->timer = dev_read_addr_ptr(dev);
if (!priv->timer)
return -ENOENT;
#endif
priv->timer = dev_read_addr_ptr(dev);
if (!priv->timer)
return -ENOENT;
}
return 0;
}

View File

@@ -50,27 +50,29 @@ unsigned long notrace timer_get_rate(struct udevice *dev)
static int timer_pre_probe(struct udevice *dev)
{
#if CONFIG_IS_ENABLED(OF_REAL)
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct clk timer_clk;
int err;
ulong ret;
if (CONFIG_IS_ENABLED(OF_REAL)) {
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct clk timer_clk;
int err;
ulong ret;
/* It is possible that a timer device has a null ofnode */
if (!dev_has_ofnode(dev))
return 0;
/*
* It is possible that a timer device has a null ofnode
*/
if (!dev_has_ofnode(dev))
return 0;
err = clk_get_by_index(dev, 0, &timer_clk);
if (!err) {
ret = clk_get_rate(&timer_clk);
if (IS_ERR_VALUE(ret))
return ret;
uc_priv->clock_rate = ret;
} else {
uc_priv->clock_rate =
dev_read_u32_default(dev, "clock-frequency", 0);
err = clk_get_by_index(dev, 0, &timer_clk);
if (!err) {
ret = clk_get_rate(&timer_clk);
if (IS_ERR_VALUE(ret))
return ret;
uc_priv->clock_rate = ret;
} else {
uc_priv->clock_rate =
dev_read_u32_default(dev, "clock-frequency", 0);
}
}
#endif
return 0;
}
@@ -136,23 +138,23 @@ int notrace dm_timer_init(void)
if (gd->dm_root == NULL)
return -EAGAIN;
#if CONFIG_IS_ENABLED(OF_REAL)
/* Check for a chosen timer to be used for tick */
node = ofnode_get_chosen_node("tick-timer");
if (CONFIG_IS_ENABLED(OF_REAL)) {
/* Check for a chosen timer to be used for tick */
node = ofnode_get_chosen_node("tick-timer");
if (ofnode_valid(node) &&
uclass_get_device_by_ofnode(UCLASS_TIMER, node, &dev)) {
/*
* If the timer is not marked to be bound before
* relocation, bind it anyway.
*/
if (!lists_bind_fdt(dm_root(), node, &dev, false)) {
ret = device_probe(dev);
if (ret)
return ret;
if (ofnode_valid(node) &&
uclass_get_device_by_ofnode(UCLASS_TIMER, node, &dev)) {
/*
* If the timer is not marked to be bound before
* relocation, bind it anyway.
*/
if (!lists_bind_fdt(dm_root(), node, &dev, false)) {
ret = device_probe(dev);
if (ret)
return ret;
}
}
}
#endif
if (!dev) {
/* Fall back to the first available timer */