Commit 7cfe2494 authored by Russell King's avatar Russell King

ARM: AMBA: Add pclk support to AMBA bus infrastructure

Some platforms gate the pclk (APB - the bus - clock) to the peripherals
for power saving, along with the functional clock.  When devices are
accessed without pclk enabled, the kernel will oops.

This gives them two options:

1. Leave all clocks on all the time.
2. Attempt to gate pclk along with the functional clock.

(With some hardware, pclk and the functional clock are gated by a single
bit in a register.)

(1) has the disadvantage that it causes increased power usage, which is
bad news for battery operated devices.  (2) can lead to kernel oops if
registers are accessed without the functional clock being enabled.

So, introduce the apb_pclk signal in such a way existing drivers don't
need to be updated.  Essentially, this means we guarantee that:

1. pclk will be enabled whenever the driver is bound to a device -
   from probe() to remove() time.
2. pclk will also be enabled when reading the primecell IDs from the device.

In order to allow drivers to be incrementally updated to achieve greater
power savings, we provide two additional calls to allow drivers to
manage the pclk - amba_pclk_enable()/amba_pclk_disable().
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 06385e49
...@@ -122,6 +122,31 @@ static int __init amba_init(void) ...@@ -122,6 +122,31 @@ static int __init amba_init(void)
postcore_initcall(amba_init); postcore_initcall(amba_init);
static int amba_get_enable_pclk(struct amba_device *pcdev)
{
struct clk *pclk = clk_get(&pcdev->dev, "apb_pclk");
int ret;
pcdev->pclk = pclk;
if (IS_ERR(pclk))
return PTR_ERR(pclk);
ret = clk_enable(pclk);
if (ret)
clk_put(pclk);
return ret;
}
static void amba_put_disable_pclk(struct amba_device *pcdev)
{
struct clk *pclk = pcdev->pclk;
clk_disable(pclk);
clk_put(pclk);
}
/* /*
* These are the device model conversion veneers; they convert the * These are the device model conversion veneers; they convert the
* device model structures to our more specific structures. * device model structures to our more specific structures.
...@@ -130,17 +155,33 @@ static int amba_probe(struct device *dev) ...@@ -130,17 +155,33 @@ static int amba_probe(struct device *dev)
{ {
struct amba_device *pcdev = to_amba_device(dev); struct amba_device *pcdev = to_amba_device(dev);
struct amba_driver *pcdrv = to_amba_driver(dev->driver); struct amba_driver *pcdrv = to_amba_driver(dev->driver);
struct amba_id *id; struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
int ret;
do {
ret = amba_get_enable_pclk(pcdev);
if (ret)
break;
ret = pcdrv->probe(pcdev, id);
if (ret == 0)
break;
id = amba_lookup(pcdrv->id_table, pcdev); amba_put_disable_pclk(pcdev);
} while (0);
return pcdrv->probe(pcdev, id); return ret;
} }
static int amba_remove(struct device *dev) static int amba_remove(struct device *dev)
{ {
struct amba_device *pcdev = to_amba_device(dev);
struct amba_driver *drv = to_amba_driver(dev->driver); struct amba_driver *drv = to_amba_driver(dev->driver);
return drv->remove(to_amba_device(dev)); int ret = drv->remove(pcdev);
amba_put_disable_pclk(pcdev);
return ret;
} }
static void amba_shutdown(struct device *dev) static void amba_shutdown(struct device *dev)
...@@ -203,7 +244,6 @@ static void amba_device_release(struct device *dev) ...@@ -203,7 +244,6 @@ static void amba_device_release(struct device *dev)
*/ */
int amba_device_register(struct amba_device *dev, struct resource *parent) int amba_device_register(struct amba_device *dev, struct resource *parent)
{ {
u32 pid, cid;
u32 size; u32 size;
void __iomem *tmp; void __iomem *tmp;
int i, ret; int i, ret;
...@@ -241,25 +281,35 @@ int amba_device_register(struct amba_device *dev, struct resource *parent) ...@@ -241,25 +281,35 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
goto err_release; goto err_release;
} }
ret = amba_get_enable_pclk(dev);
if (ret == 0) {
u32 pid, cid;
/* /*
* Read pid and cid based on size of resource * Read pid and cid based on size of resource
* they are located at end of region * they are located at end of region
*/ */
for (pid = 0, i = 0; i < 4; i++) for (pid = 0, i = 0; i < 4; i++)
pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) << (i * 8); pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) <<
(i * 8);
for (cid = 0, i = 0; i < 4; i++) for (cid = 0, i = 0; i < 4; i++)
cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << (i * 8); cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) <<
(i * 8);
iounmap(tmp); amba_put_disable_pclk(dev);
if (cid == 0xb105f00d) if (cid == 0xb105f00d)
dev->periphid = pid; dev->periphid = pid;
if (!dev->periphid) { if (!dev->periphid)
ret = -ENODEV; ret = -ENODEV;
goto err_release;
} }
iounmap(tmp);
if (ret)
goto err_release;
ret = device_add(&dev->dev); ret = device_add(&dev->dev);
if (ret) if (ret)
goto err_release; goto err_release;
......
...@@ -14,14 +14,19 @@ ...@@ -14,14 +14,19 @@
#ifndef ASMARM_AMBA_H #ifndef ASMARM_AMBA_H
#define ASMARM_AMBA_H #define ASMARM_AMBA_H
#include <linux/clk.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/err.h>
#include <linux/resource.h> #include <linux/resource.h>
#define AMBA_NR_IRQS 2 #define AMBA_NR_IRQS 2
struct clk;
struct amba_device { struct amba_device {
struct device dev; struct device dev;
struct resource res; struct resource res;
struct clk *pclk;
u64 dma_mask; u64 dma_mask;
unsigned int periphid; unsigned int periphid;
unsigned int irq[AMBA_NR_IRQS]; unsigned int irq[AMBA_NR_IRQS];
...@@ -59,6 +64,12 @@ struct amba_device *amba_find_device(const char *, struct device *, unsigned int ...@@ -59,6 +64,12 @@ struct amba_device *amba_find_device(const char *, struct device *, unsigned int
int amba_request_regions(struct amba_device *, const char *); int amba_request_regions(struct amba_device *, const char *);
void amba_release_regions(struct amba_device *); void amba_release_regions(struct amba_device *);
#define amba_pclk_enable(d) \
(IS_ERR((d)->pclk) ? 0 : clk_enable((d)->pclk))
#define amba_pclk_disable(d) \
do { if (!IS_ERR((d)->pclk)) clk_disable((d)->pclk); } while (0)
#define amba_config(d) (((d)->periphid >> 24) & 0xff) #define amba_config(d) (((d)->periphid >> 24) & 0xff)
#define amba_rev(d) (((d)->periphid >> 20) & 0x0f) #define amba_rev(d) (((d)->periphid >> 20) & 0x0f)
#define amba_manf(d) (((d)->periphid >> 12) & 0xff) #define amba_manf(d) (((d)->periphid >> 12) & 0xff)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment