10 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/string.h>
14 #include <linux/slab.h>
23 #define to_amba_driver(d) container_of(d, struct amba_driver, drv)
37 return ret ? table :
NULL;
62 #define amba_uevent NULL
65 #define amba_attr_func(name,fmt,arg...) \
66 static ssize_t name##_show(struct device *_dev, \
67 struct device_attribute *attr, char *buf) \
69 struct amba_device *dev = to_amba_device(_dev); \
70 return sprintf(buf, fmt, arg); \
73 #define amba_attr(name,fmt,arg...) \
74 amba_attr_func(name,fmt,arg) \
75 static DEVICE_ATTR(name, S_IRUGO, name##_show, NULL)
81 (
unsigned long long)dev->res.start, (
unsigned long long)dev->res.end,
90 #ifdef CONFIG_PM_SLEEP
99 ret = adrv->
suspend(adev, mesg);
104 static int amba_legacy_resume(
struct device *dev)
118 #ifdef CONFIG_SUSPEND
129 if (drv->
pm->suspend)
130 ret = drv->
pm->suspend(dev);
148 ret = drv->
pm->resume(dev);
150 ret = amba_legacy_resume(dev);
158 #define amba_pm_suspend NULL
159 #define amba_pm_resume NULL
163 #ifdef CONFIG_HIBERNATE_CALLBACKS
175 ret = drv->
pm->freeze(dev);
193 ret = drv->
pm->thaw(dev);
195 ret = amba_legacy_resume(dev);
210 if (drv->
pm->poweroff)
211 ret = drv->
pm->poweroff(dev);
228 if (drv->
pm->restore)
229 ret = drv->
pm->restore(dev);
231 ret = amba_legacy_resume(dev);
239 #define amba_pm_freeze NULL
240 #define amba_pm_thaw NULL
241 #define amba_pm_poweroff NULL
242 #define amba_pm_restore NULL
246 #ifdef CONFIG_PM_RUNTIME
252 static int amba_pm_runtime_suspend(
struct device *dev)
255 int ret = pm_generic_runtime_suspend(dev);
257 if (ret == 0 && dev->
driver)
263 static int amba_pm_runtime_resume(
struct device *dev)
275 return pm_generic_runtime_resume(dev);
289 amba_pm_runtime_suspend,
290 amba_pm_runtime_resume,
291 pm_generic_runtime_idle
295 #define AMBA_PM (&amba_pm)
309 .dev_attrs = amba_dev_attrs,
315 static int __init amba_init(
void)
322 static int amba_get_enable_pclk(
struct amba_device *pcdev)
330 return PTR_ERR(pclk);
347 static void amba_put_disable_pclk(
struct amba_device *pcdev)
349 struct clk *pclk = pcdev->
pclk;
360 static int amba_probe(
struct device *dev)
368 ret = amba_get_enable_pclk(pcdev);
372 pm_runtime_get_noresume(dev);
373 pm_runtime_set_active(dev);
376 ret = pcdrv->
probe(pcdev,
id);
380 pm_runtime_disable(dev);
381 pm_runtime_set_suspended(dev);
382 pm_runtime_put_noidle(dev);
384 amba_put_disable_pclk(pcdev);
390 static int amba_remove(
struct device *dev)
396 pm_runtime_get_sync(dev);
398 pm_runtime_put_noidle(dev);
401 pm_runtime_disable(dev);
402 pm_runtime_set_suspended(dev);
403 pm_runtime_put_noidle(dev);
405 amba_put_disable_pclk(pcdev);
410 static void amba_shutdown(
struct device *dev)
428 #define SETFN(fn) if (drv->fn) drv->drv.fn = amba_##fn
450 static void amba_device_release(
struct device *dev)
489 size = resource_size(&dev->
res);
496 ret = amba_get_enable_pclk(dev);
504 for (pid = 0, i = 0; i < 4; i++)
505 pid |= (
readl(tmp + size - 0x20 + 4 * i) & 255) <<
507 for (cid = 0, i = 0; i < 4; i++)
508 cid |= (
readl(tmp + size - 0x10 + 4 * i) & 255) <<
511 amba_put_disable_pclk(dev);
532 if (ret == 0 && dev->
irq[1])
547 amba_aphb_device_add(
struct device *parent,
const char *
name,
564 dev->
dev.parent = parent;
578 void *pdata,
unsigned int periphid)
580 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
588 void *pdata,
unsigned int periphid)
590 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
595 static void amba_device_initialize(
struct amba_device *dev,
const char *name)
600 dev->
dev.release = amba_device_release;
603 dev->
res.name = dev_name(&dev->
dev);
622 amba_device_initialize(dev, name);
623 dev->
res.start = base;
624 dev->
res.end = base + size - 1;
643 amba_device_initialize(dev, dev->
dev.init_name);
647 dev_warn(&dev->
dev,
"coherent dma mask is unset\n");
687 static int amba_find_match(
struct device *dev,
void *
data)
749 name = dev->
dev.driver->name;
751 size = resource_size(&dev->
res);
769 size = resource_size(&dev->
res);