Lines Matching +full:pm +full:- +full:bus
1 // SPDX-License-Identifier: GPL-2.0-only
13 #include <linux/pm.h>
16 #include <linux/amba/bus.h>
19 #include <linux/clk/clk-conf.h>
27 #include <linux/dma-map-ops.h>
38 uci = table->data; in amba_cs_uci_id_match()
40 /* no table data or zero mask - return match on periphid */ in amba_cs_uci_id_match()
41 if (!uci || (uci->devarch_mask == 0)) in amba_cs_uci_id_match()
45 ret = (dev->uci.devtype == uci->devtype) && in amba_cs_uci_id_match()
46 ((dev->uci.devarch & uci->devarch_mask) == uci->devarch); in amba_cs_uci_id_match()
53 while (table->mask) { in amba_lookup()
54 if (((dev->periphid & table->mask) == table->id) && in amba_lookup()
55 ((dev->cid != CORESIGHT_CID) || in amba_lookup()
67 pcdev->pclk = clk_get(&pcdev->dev, "apb_pclk"); in amba_get_enable_pclk()
68 if (IS_ERR(pcdev->pclk)) in amba_get_enable_pclk()
69 return PTR_ERR(pcdev->pclk); in amba_get_enable_pclk()
71 ret = clk_prepare_enable(pcdev->pclk); in amba_get_enable_pclk()
73 clk_put(pcdev->pclk); in amba_get_enable_pclk()
80 clk_disable_unprepare(pcdev->pclk); in amba_put_disable_pclk()
81 clk_put(pcdev->pclk); in amba_put_disable_pclk()
92 len = sprintf(buf, "%s\n", dev->driver_override); in driver_override_show()
104 ret = driver_set_override(_dev, &dev->driver_override, buf, count); in driver_override_store()
121 amba_attr_func(id, "%08x\n", dev->periphid);
123 (unsigned long long)dev->res.start, (unsigned long long)dev->res.end,
124 dev->res.flags);
141 ret = dev_pm_domain_attach(&dev->dev, true); in amba_read_periphid()
143 dev_dbg(&dev->dev, "can't get PM domain: %d\n", ret); in amba_read_periphid()
149 dev_dbg(&dev->dev, "can't get pclk: %d\n", ret); in amba_read_periphid()
154 * Find reset control(s) of the amba bus and de-assert them. in amba_read_periphid()
156 rstc = of_reset_control_array_get_optional_shared(dev->dev.of_node); in amba_read_periphid()
159 if (ret != -EPROBE_DEFER) in amba_read_periphid()
160 dev_err(&dev->dev, "can't get reset: %d\n", ret); in amba_read_periphid()
166 size = resource_size(&dev->res); in amba_read_periphid()
167 tmp = ioremap(dev->res.start, size); in amba_read_periphid()
169 ret = -ENOMEM; in amba_read_periphid()
178 pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) << (i * 8); in amba_read_periphid()
180 cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << (i * 8); in amba_read_periphid()
184 void __iomem *csbase = tmp + size - 4096; in amba_read_periphid()
186 dev->uci.devarch = readl(csbase + UCI_REG_DEVARCH_OFFSET); in amba_read_periphid()
187 dev->uci.devtype = readl(csbase + UCI_REG_DEVTYPE_OFFSET) & 0xff; in amba_read_periphid()
191 dev->periphid = pid; in amba_read_periphid()
192 dev->cid = cid; in amba_read_periphid()
195 if (!dev->periphid) in amba_read_periphid()
196 ret = -ENODEV; in amba_read_periphid()
203 dev_pm_domain_detach(&dev->dev, true); in amba_read_periphid()
213 mutex_lock(&pcdev->periphid_lock); in amba_match()
214 if (!pcdev->periphid) { in amba_match()
218 * Returning any error other than -EPROBE_DEFER from bus match in amba_match()
221 * -EPROBE_DEFER. in amba_match()
224 mutex_unlock(&pcdev->periphid_lock); in amba_match()
225 return -EPROBE_DEFER; in amba_match()
228 kobject_uevent(&dev->kobj, KOBJ_ADD); in amba_match()
230 mutex_unlock(&pcdev->periphid_lock); in amba_match()
233 if (pcdev->driver_override) in amba_match()
234 return !strcmp(pcdev->driver_override, drv->name); in amba_match()
236 return amba_lookup(pcdrv->id_table, pcdev) != NULL; in amba_match()
244 retval = add_uevent_var(env, "AMBA_ID=%08x", pcdev->periphid); in amba_uevent()
248 retval = add_uevent_var(env, "MODALIAS=amba:d%08X", pcdev->periphid); in amba_uevent()
254 struct device_node *node = dev->dev.of_node; in of_amba_device_decode_irq()
262 if (irq == -EPROBE_DEFER) in of_amba_device_decode_irq()
267 dev->irq[i] = irq; in of_amba_device_decode_irq()
281 struct amba_driver *pcdrv = to_amba_driver(dev->driver); in amba_probe()
282 const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev); in amba_probe()
290 ret = of_clk_set_defaults(dev->of_node, false); in amba_probe()
308 ret = pcdrv->probe(pcdev, id); in amba_probe()
326 struct amba_driver *drv = to_amba_driver(dev->driver); in amba_remove()
329 if (drv->remove) in amba_remove()
330 drv->remove(pcdev); in amba_remove()
333 /* Undo the runtime PM settings in amba_probe() */ in amba_remove()
346 if (!dev->driver) in amba_shutdown()
349 drv = to_amba_driver(dev->driver); in amba_shutdown()
350 if (drv->shutdown) in amba_shutdown()
351 drv->shutdown(to_amba_device(dev)); in amba_shutdown()
356 struct amba_driver *drv = to_amba_driver(dev->driver); in amba_dma_configure()
360 if (dev->of_node) { in amba_dma_configure()
361 ret = of_dma_configure(dev, dev->of_node, true); in amba_dma_configure()
363 attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode)); in amba_dma_configure()
367 if (!ret && !drv->driver_managed_dma) { in amba_dma_configure()
378 struct amba_driver *drv = to_amba_driver(dev->driver); in amba_dma_cleanup()
380 if (!drv->driver_managed_dma) in amba_dma_cleanup()
386 * Hooks to provide runtime PM of the pclk (bus clock). It is safe to
387 * enable/disable the bus clock at runtime PM suspend/resume as this
395 if (ret == 0 && dev->driver) { in amba_pm_runtime_suspend()
397 clk_disable(pcdev->pclk); in amba_pm_runtime_suspend()
399 clk_disable_unprepare(pcdev->pclk); in amba_pm_runtime_suspend()
410 if (dev->driver) { in amba_pm_runtime_resume()
412 ret = clk_enable(pcdev->pclk); in amba_pm_runtime_resume()
414 ret = clk_prepare_enable(pcdev->pclk); in amba_pm_runtime_resume()
433 * Primecells are part of the Advanced Microcontroller Bus Architecture,
434 * so we call the bus "amba".
435 * DMA configuration for platform and AMBA bus is same. So here we reuse
448 .pm = &amba_pm,
463 return -ENODEV; in amba_proxy_probe()
472 .name = "amba-proxy",
486 * only loaded based on uevents, then we'll hit a chicken-and-egg in amba_stub_drv_init()
496 * __amba_driver_register - register an AMBA device driver
501 * core. If devices pre-exist, the drivers probe function will
507 if (!drv->probe) in __amba_driver_register()
508 return -EINVAL; in __amba_driver_register()
510 drv->drv.owner = owner; in __amba_driver_register()
511 drv->drv.bus = &amba_bustype; in __amba_driver_register()
513 return driver_register(&drv->drv); in __amba_driver_register()
518 * amba_driver_unregister - remove an AMBA device driver
527 driver_unregister(&drv->drv); in amba_driver_unregister()
535 fwnode_handle_put(dev_fwnode(&d->dev)); in amba_device_release()
536 if (d->res.parent) in amba_device_release()
537 release_resource(&d->res); in amba_device_release()
538 mutex_destroy(&d->periphid_lock); in amba_device_release()
543 * amba_device_add - add a previously allocated AMBA device structure
555 fwnode_handle_get(dev_fwnode(&dev->dev)); in amba_device_add()
557 ret = request_resource(parent, &dev->res); in amba_device_add()
561 /* If primecell ID isn't hard-coded, figure it out */ in amba_device_add()
562 if (!dev->periphid) { in amba_device_add()
572 dev_set_uevent_suppress(&dev->dev, true); in amba_device_add()
575 ret = device_add(&dev->dev); in amba_device_add()
577 release_resource(&dev->res); in amba_device_add()
585 device_initialize(&dev->dev); in amba_device_initialize()
587 dev_set_name(&dev->dev, "%s", name); in amba_device_initialize()
588 dev->dev.release = amba_device_release; in amba_device_initialize()
589 dev->dev.bus = &amba_bustype; in amba_device_initialize()
590 dev->dev.dma_mask = &dev->dev.coherent_dma_mask; in amba_device_initialize()
591 dev->dev.dma_parms = &dev->dma_parms; in amba_device_initialize()
592 dev->res.name = dev_name(&dev->dev); in amba_device_initialize()
593 mutex_init(&dev->periphid_lock); in amba_device_initialize()
597 * amba_device_alloc - allocate an AMBA device
613 dev->res.start = base; in amba_device_alloc()
614 dev->res.end = base + size - 1; in amba_device_alloc()
615 dev->res.flags = IORESOURCE_MEM; in amba_device_alloc()
623 * amba_device_register - register an AMBA device
633 amba_device_initialize(dev, dev->dev.init_name); in amba_device_register()
634 dev->dev.init_name = NULL; in amba_device_register()
641 * amba_device_put - put an AMBA device
646 put_device(&dev->dev); in amba_device_put()
651 * amba_device_unregister - unregister an AMBA device
663 device_unregister(&dev->dev); in amba_device_unregister()
668 * amba_request_regions - request all mem regions associated with device
678 name = dev->dev.driver->name; in amba_request_regions()
680 size = resource_size(&dev->res); in amba_request_regions()
682 if (!request_mem_region(dev->res.start, size, name)) in amba_request_regions()
683 ret = -EBUSY; in amba_request_regions()
690 * amba_release_regions - release mem regions associated with device
699 size = resource_size(&dev->res); in amba_release_regions()
700 release_mem_region(dev->res.start, size); in amba_release_regions()