Skip to content

Commit

Permalink
amba: reorder functions
Browse files Browse the repository at this point in the history
Put helpers (here: amba_get_enable_pclk and amba_put_disable_pclk) at
the top of the file and then define callbacks directly before the
structs they are used in; in the same order.

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20210126165835.687514-3-u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
  • Loading branch information
Uwe Kleine-König authored and Uwe Kleine-König committed Feb 2, 2021
1 parent de5d7ad commit 5150a8f
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions drivers/amba/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,28 @@ amba_lookup(const struct amba_id *table, struct amba_device *dev)
return NULL;
}

static int amba_match(struct device *dev, struct device_driver *drv)
static int amba_get_enable_pclk(struct amba_device *pcdev)
{
struct amba_device *pcdev = to_amba_device(dev);
struct amba_driver *pcdrv = to_amba_driver(drv);
int ret;

/* When driver_override is set, only bind to the matching driver */
if (pcdev->driver_override)
return !strcmp(pcdev->driver_override, drv->name);
pcdev->pclk = clk_get(&pcdev->dev, "apb_pclk");
if (IS_ERR(pcdev->pclk))
return PTR_ERR(pcdev->pclk);

return amba_lookup(pcdrv->id_table, pcdev) != NULL;
ret = clk_prepare_enable(pcdev->pclk);
if (ret)
clk_put(pcdev->pclk);

return ret;
}

static int amba_uevent(struct device *dev, struct kobj_uevent_env *env)
static void amba_put_disable_pclk(struct amba_device *pcdev)
{
struct amba_device *pcdev = to_amba_device(dev);
int retval = 0;

retval = add_uevent_var(env, "AMBA_ID=%08x", pcdev->periphid);
if (retval)
return retval;

retval = add_uevent_var(env, "MODALIAS=amba:d%08X", pcdev->periphid);
return retval;
clk_disable_unprepare(pcdev->pclk);
clk_put(pcdev->pclk);
}


static ssize_t driver_override_show(struct device *_dev,
struct device_attribute *attr, char *buf)
{
Expand Down Expand Up @@ -152,6 +149,31 @@ static struct attribute *amba_dev_attrs[] = {
};
ATTRIBUTE_GROUPS(amba_dev);

static int amba_match(struct device *dev, struct device_driver *drv)
{
struct amba_device *pcdev = to_amba_device(dev);
struct amba_driver *pcdrv = to_amba_driver(drv);

/* When driver_override is set, only bind to the matching driver */
if (pcdev->driver_override)
return !strcmp(pcdev->driver_override, drv->name);

return amba_lookup(pcdrv->id_table, pcdev) != NULL;
}

static int amba_uevent(struct device *dev, struct kobj_uevent_env *env)
{
struct amba_device *pcdev = to_amba_device(dev);
int retval = 0;

retval = add_uevent_var(env, "AMBA_ID=%08x", pcdev->periphid);
if (retval)
return retval;

retval = add_uevent_var(env, "MODALIAS=amba:d%08X", pcdev->periphid);
return retval;
}

#ifdef CONFIG_PM
/*
* Hooks to provide runtime PM of the pclk (bus clock). It is safe to
Expand Down Expand Up @@ -229,27 +251,6 @@ static int __init amba_init(void)

postcore_initcall(amba_init);

static int amba_get_enable_pclk(struct amba_device *pcdev)
{
int ret;

pcdev->pclk = clk_get(&pcdev->dev, "apb_pclk");
if (IS_ERR(pcdev->pclk))
return PTR_ERR(pcdev->pclk);

ret = clk_prepare_enable(pcdev->pclk);
if (ret)
clk_put(pcdev->pclk);

return ret;
}

static void amba_put_disable_pclk(struct amba_device *pcdev)
{
clk_disable_unprepare(pcdev->pclk);
clk_put(pcdev->pclk);
}

/*
* These are the device model conversion veneers; they convert the
* device model structures to our more specific structures.
Expand Down

0 comments on commit 5150a8f

Please sign in to comment.