mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
f991fae5c6
- Hotplug changes allowing device hot-removal operations to fail gracefully (instead of crashing the kernel) if they cannot be carried out completely. From Rafael J Wysocki and Toshi Kani. - Freezer update from Colin Cross and Mandeep Singh Baines targeted at making the freezing of tasks a bit less heavy weight operation. - cpufreq resume fix from Srivatsa S Bhat for a regression introduced during the 3.10 cycle causing some cpufreq sysfs attributes to return wrong values to user space after resume. - New freqdomain_cpus sysfs attribute for the acpi-cpufreq driver to provide information previously available via related_cpus from Lan Tianyu. - cpufreq fixes and cleanups from Viresh Kumar, Jacob Shin, Heiko Stübner, Xiaoguang Chen, Ezequiel Garcia, Arnd Bergmann, and Tang Yuantian. - Fix for an ACPICA regression causing suspend/resume issues to appear on some systems introduced during the 3.4 development cycle from Lv Zheng. - ACPICA fixes and cleanups from Bob Moore, Tomasz Nowicki, Lv Zheng, Chao Guan, and Zhang Rui. - New cupidle driver for Xilinx Zynq processors from Michal Simek. - cpuidle fixes and cleanups from Daniel Lezcano. - Changes to make suspend/resume work correctly in Xen guests from Konrad Rzeszutek Wilk. - ACPI device power management fixes and cleanups from Fengguang Wu and Rafael J Wysocki. - ACPI documentation updates from Lv Zheng, Aaron Lu and Hanjun Guo. - Fix for the IA-64 issue that was the reason for reverting commit9f29ab1
and updates of the ACPI scan code from Rafael J Wysocki. - Mechanism for adding CMOS RTC address space handlers from Lan Tianyu (to allow some EC-related breakage to be fixed on some systems). - Spec-compliant implementation of acpi_os_get_timer() from Mika Westerberg. - Modification of do_acpi_find_child() to execute _STA in order to to avoid situations in which a pointer to a disabled device object is returned instead of an enabled one with the same _ADR value. From Jeff Wu. - Intel BayTrail PCH (Platform Controller Hub) support for the ACPI Intel Low-Power Subsystems (LPSS) driver and modificaions of that driver to work around a couple of known BIOS issues from Mika Westerberg and Heikki Krogerus. - EC driver fix from Vasiliy Kulikov to make it use get_user() and put_user() instead of dereferencing user space pointers blindly. - Assorted ACPI code cleanups from Bjorn Helgaas, Nicholas Mazzuca and Toshi Kani. - Modification of the "runtime idle" helper routine to take the return values of the callbacks executed by it into account and to call rpm_suspend() if they return 0, which allows some code bloat reduction to be done, from Rafael J Wysocki and Alan Stern. - New trace points for PM QoS from Sahara <keun-o.park@windriver.com>. - PM QoS documentation update from Lan Tianyu. - Assorted core PM code cleanups and changes from Bernie Thompson, Bjorn Helgaas, Julius Werner, and Shuah Khan. - New devfreq driver for the Exynos5-bus device from Abhilash Kesavan. - Minor devfreq cleanups, fixes and MAINTAINERS update from MyungJoo Ham, Abhilash Kesavan, Paul Bolle, Rajagopal Venkat, and Wei Yongjun. - OMAP Adaptive Voltage Scaling (AVS) SmartReflex voltage control driver updates from Andrii Tseglytskyi and Nishanth Menon. / -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQIcBAABAgAGBQJR0ZNOAAoJEKhOf7ml8uNsDLYP/0EU4rmvw0TWTITfp6RS1KDE 9GwBn96ZR4Q5bJd9gBCTPSqhHOYMqxWEUp99sn/M2wehG1pk/jw5LO56+2IhM3UZ g1HDcJ7te2nVT/iXsKiAGTVhU9Rk0aYwoVSknwk27qpIBGxW9w/s5tLX8pY3Q3Zq wL/7aTPjyL+PFFFEaxgH7qLqsl3DhbtYW5AriUBTkXout/tJ4eO1b7MNBncLDh8X VQ/0DNCKE95VEJfkO4rk9RKUyVp9GDn0i+HXCD/FS4IA5oYzePdVdNDmXf7g+swe CGlTZq8pB+oBpDiHl4lxzbNrKQjRNbGnDUkoRcWqn0nAw56xK+vmYnWJhW99gQ/I fKnvxeLca5po1aiqmC4VSJxZIatFZqLrZAI4dzoCLWY+bGeTnCKmj0/F8ytFnZA2 8IuLLs7/dFOaHXV/pKmpg6FAlFa9CPxoqRFoyqb4M0GjEarADyalXUWsPtG+6xCp R/p0CISpwk+guKZR/qPhL7M654S7SHrPwd2DPF0KgGsvk+G2GhoB8EzvD8BVp98Z 9siCGCdgKQfJQVI6R0k9aFmn/4gRQIAgyPhkhv9tqULUUkiaXki+/t8kPfnb8O/d zep+CA57E2G8MYLkDJfpFeKS7GpPD6TIdgFdGmOUC0Y6sl9iTdiw4yTx8O2JM37z rHBZfYGkJBrbGRu+Q1gs =VBBq -----END PGP SIGNATURE----- Merge tag 'pm+acpi-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm Pull power management and ACPI updates from Rafael Wysocki: "This time the total number of ACPI commits is slightly greater than the number of cpufreq commits, but Viresh Kumar (who works on cpufreq) remains the most active patch submitter. To me, the most significant change is the addition of offline/online device operations to the driver core (with the Greg's blessing) and the related modifications of the ACPI core hotplug code. Next are the freezer updates from Colin Cross that should make the freezing of tasks a bit less heavy weight. We also have a couple of regression fixes, a number of fixes for issues that have not been identified as regressions, two new drivers and a bunch of cleanups all over. Highlights: - Hotplug changes to support graceful hot-removal failures. It sometimes is necessary to fail device hot-removal operations gracefully if they cannot be carried out completely. For example, if memory from a memory module being hot-removed has been allocated for the kernel's own use and cannot be moved elsewhere, it's desirable to fail the hot-removal operation in a graceful way rather than to crash the kernel, but currenty a success or a kernel crash are the only possible outcomes of an attempted memory hot-removal. Needless to say, that is not a very attractive alternative and it had to be addressed. However, in order to make it work for memory, I first had to make it work for CPUs and for this purpose I needed to modify the ACPI processor driver. It's been split into two parts, a resident one handling the low-level initialization/cleanup and a modular one playing the actual driver's role (but it binds to the CPU system device objects rather than to the ACPI device objects representing processors). That's been sort of like a live brain surgery on a patient who's riding a bike. So this is a little scary, but since we found and fixed a couple of regressions it caused to happen during the early linux-next testing (a month ago), nobody has complained. As a bonus we remove some duplicated ACPI hotplug code, because the ACPI-based CPU hotplug is now going to use the common ACPI hotplug code. - Lighter weight freezing of tasks. These changes from Colin Cross and Mandeep Singh Baines are targeted at making the freezing of tasks a bit less heavy weight operation. They reduce the number of tasks woken up every time during the freezing, by using the observation that the freezer simply doesn't need to wake up some of them and wait for them all to call refrigerator(). The time needed for the freezer to decide to report a failure is reduced too. Also reintroduced is the check causing a lockdep warining to trigger when try_to_freeze() is called with locks held (which is generally unsafe and shouldn't happen). - cpufreq updates First off, a commit from Srivatsa S Bhat fixes a resume regression introduced during the 3.10 cycle causing some cpufreq sysfs attributes to return wrong values to user space after resume. The fix is kind of fresh, but also it's pretty obvious once Srivatsa has identified the root cause. Second, we have a new freqdomain_cpus sysfs attribute for the acpi-cpufreq driver to provide information previously available via related_cpus. From Lan Tianyu. Finally, we fix a number of issues, mostly related to the CPUFREQ_POSTCHANGE notifier and cpufreq Kconfig options and clean up some code. The majority of changes from Viresh Kumar with bits from Jacob Shin, Heiko Stübner, Xiaoguang Chen, Ezequiel Garcia, Arnd Bergmann, and Tang Yuantian. - ACPICA update A usual bunch of updates from the ACPICA upstream. During the 3.4 cycle we introduced support for ACPI 5 extended sleep registers, but they are only supposed to be used if the HW-reduced mode bit is set in the FADT flags and the code attempted to use them without checking that bit. That caused suspend/resume regressions to happen on some systems. Fix from Lv Zheng causes those registers to be used only if the HW-reduced mode bit is set. Apart from this some other ACPICA bugs are fixed and code cleanups are made by Bob Moore, Tomasz Nowicki, Lv Zheng, Chao Guan, and Zhang Rui. - cpuidle updates New driver for Xilinx Zynq processors is added by Michal Simek. Multidriver support simplification, addition of some missing kerneldoc comments and Kconfig-related fixes come from Daniel Lezcano. - ACPI power management updates Changes to make suspend/resume work correctly in Xen guests from Konrad Rzeszutek Wilk, sparse warning fix from Fengguang Wu and cleanups and fixes of the ACPI device power state selection routine. - ACPI documentation updates Some previously missing pieces of ACPI documentation are added by Lv Zheng and Aaron Lu (hopefully, that will help people to uderstand how the ACPI subsystem works) and one outdated doc is updated by Hanjun Guo. - Assorted ACPI updates We finally nailed down the IA-64 issue that was the reason for reverting commit9f29ab11dd
("ACPI / scan: do not match drivers against objects having scan handlers"), so we can fix it and move the ACPI scan handler check added to the ACPI video driver back to the core. A mechanism for adding CMOS RTC address space handlers is introduced by Lan Tianyu to allow some EC-related breakage to be fixed on some systems. A spec-compliant implementation of acpi_os_get_timer() is added by Mika Westerberg. The evaluation of _STA is added to do_acpi_find_child() to avoid situations in which a pointer to a disabled device object is returned instead of an enabled one with the same _ADR value. From Jeff Wu. Intel BayTrail PCH (Platform Controller Hub) support is added to the ACPI driver for Intel Low-Power Subsystems (LPSS) and that driver is modified to work around a couple of known BIOS issues. Changes from Mika Westerberg and Heikki Krogerus. The EC driver is fixed by Vasiliy Kulikov to use get_user() and put_user() instead of dereferencing user space pointers blindly. Code cleanups are made by Bjorn Helgaas, Nicholas Mazzuca and Toshi Kani. - Assorted power management updates The "runtime idle" helper routine is changed to take the return values of the callbacks executed by it into account and to call rpm_suspend() if they return 0, which allows us to reduce the overall code bloat a bit (by dropping some code that's not necessary any more after that modification). The runtime PM documentation is updated by Alan Stern (to reflect the "runtime idle" behavior change). New trace points for PM QoS are added by Sahara (<keun-o.park@windriver.com>). PM QoS documentation is updated by Lan Tianyu. Code cleanups are made and minor issues are addressed by Bernie Thompson, Bjorn Helgaas, Julius Werner, and Shuah Khan. - devfreq updates New driver for the Exynos5-bus device from Abhilash Kesavan. Minor cleanups, fixes and MAINTAINERS update from MyungJoo Ham, Abhilash Kesavan, Paul Bolle, Rajagopal Venkat, and Wei Yongjun. - OMAP power management updates Adaptive Voltage Scaling (AVS) SmartReflex voltage control driver updates from Andrii Tseglytskyi and Nishanth Menon." * tag 'pm+acpi-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (162 commits) cpufreq: Fix cpufreq regression after suspend/resume ACPI / PM: Fix possible NULL pointer deref in acpi_pm_device_sleep_state() PM / Sleep: Warn about system time after resume with pm_trace cpufreq: don't leave stale policy pointer in cdbs->cur_policy acpi-cpufreq: Add new sysfs attribute freqdomain_cpus cpufreq: make sure frequency transitions are serialized ACPI: implement acpi_os_get_timer() according the spec ACPI / EC: Add HP Folio 13 to ec_dmi_table in order to skip DSDT scan ACPI: Add CMOS RTC Operation Region handler support ACPI / processor: Drop unused variable from processor_perflib.c cpufreq: tegra: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: s3c64xx: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: omap: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: imx6q: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: exynos: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: dbx500: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: davinci: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: arm-big-little: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: powernow-k8: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: pcc: call CPUFREQ_POSTCHANGE notfier in error cases ...
870 lines
23 KiB
C
870 lines
23 KiB
C
/*
|
|
* omap_device implementation
|
|
*
|
|
* Copyright (C) 2009-2010 Nokia Corporation
|
|
* Paul Walmsley, Kevin Hilman
|
|
*
|
|
* Developed in collaboration with (alphabetical order): Benoit
|
|
* Cousson, Thara Gopinath, Tony Lindgren, Rajendra Nayak, Vikram
|
|
* Pandita, Sakari Poussa, Anand Sawant, Santosh Shilimkar, Richard
|
|
* Woodruff
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This code provides a consistent interface for OMAP device drivers
|
|
* to control power management and interconnect properties of their
|
|
* devices.
|
|
*
|
|
* In the medium- to long-term, this code should be implemented as a
|
|
* proper omap_bus/omap_device in Linux, no more platform_data func
|
|
* pointers
|
|
*
|
|
*
|
|
*/
|
|
#undef DEBUG
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/err.h>
|
|
#include <linux/io.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/clkdev.h>
|
|
#include <linux/pm_runtime.h>
|
|
#include <linux/of.h>
|
|
#include <linux/notifier.h>
|
|
|
|
#include "soc.h"
|
|
#include "omap_device.h"
|
|
#include "omap_hwmod.h"
|
|
|
|
/* Private functions */
|
|
|
|
static void _add_clkdev(struct omap_device *od, const char *clk_alias,
|
|
const char *clk_name)
|
|
{
|
|
struct clk *r;
|
|
struct clk_lookup *l;
|
|
|
|
if (!clk_alias || !clk_name)
|
|
return;
|
|
|
|
dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
|
|
|
|
r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
|
|
if (!IS_ERR(r)) {
|
|
dev_warn(&od->pdev->dev,
|
|
"alias %s already exists\n", clk_alias);
|
|
clk_put(r);
|
|
return;
|
|
}
|
|
|
|
r = clk_get(NULL, clk_name);
|
|
if (IS_ERR(r)) {
|
|
dev_err(&od->pdev->dev,
|
|
"clk_get for %s failed\n", clk_name);
|
|
return;
|
|
}
|
|
|
|
l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
|
|
if (!l) {
|
|
dev_err(&od->pdev->dev,
|
|
"clkdev_alloc for %s failed\n", clk_alias);
|
|
return;
|
|
}
|
|
|
|
clkdev_add(l);
|
|
}
|
|
|
|
/**
|
|
* _add_hwmod_clocks_clkdev - Add clkdev entry for hwmod optional clocks
|
|
* and main clock
|
|
* @od: struct omap_device *od
|
|
* @oh: struct omap_hwmod *oh
|
|
*
|
|
* For the main clock and every optional clock present per hwmod per
|
|
* omap_device, this function adds an entry in the clkdev table of the
|
|
* form <dev-id=dev_name, con-id=role> if it does not exist already.
|
|
*
|
|
* The function is called from inside omap_device_build_ss(), after
|
|
* omap_device_register.
|
|
*
|
|
* This allows drivers to get a pointer to its optional clocks based on its role
|
|
* by calling clk_get(<dev*>, <role>).
|
|
* In the case of the main clock, a "fck" alias is used.
|
|
*
|
|
* No return value.
|
|
*/
|
|
static void _add_hwmod_clocks_clkdev(struct omap_device *od,
|
|
struct omap_hwmod *oh)
|
|
{
|
|
int i;
|
|
|
|
_add_clkdev(od, "fck", oh->main_clk);
|
|
|
|
for (i = 0; i < oh->opt_clks_cnt; i++)
|
|
_add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk);
|
|
}
|
|
|
|
|
|
/**
|
|
* omap_device_build_from_dt - build an omap_device with multiple hwmods
|
|
* @pdev_name: name of the platform_device driver to use
|
|
* @pdev_id: this platform_device's connection ID
|
|
* @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
* @pdata: platform_data ptr to associate with the platform_device
|
|
* @pdata_len: amount of memory pointed to by @pdata
|
|
*
|
|
* Function for building an omap_device already registered from device-tree
|
|
*
|
|
* Returns 0 or PTR_ERR() on error.
|
|
*/
|
|
static int omap_device_build_from_dt(struct platform_device *pdev)
|
|
{
|
|
struct omap_hwmod **hwmods;
|
|
struct omap_device *od;
|
|
struct omap_hwmod *oh;
|
|
struct device_node *node = pdev->dev.of_node;
|
|
const char *oh_name;
|
|
int oh_cnt, i, ret = 0;
|
|
|
|
oh_cnt = of_property_count_strings(node, "ti,hwmods");
|
|
if (oh_cnt <= 0) {
|
|
dev_dbg(&pdev->dev, "No 'hwmods' to build omap_device\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
|
|
if (!hwmods) {
|
|
ret = -ENOMEM;
|
|
goto odbfd_exit;
|
|
}
|
|
|
|
for (i = 0; i < oh_cnt; i++) {
|
|
of_property_read_string_index(node, "ti,hwmods", i, &oh_name);
|
|
oh = omap_hwmod_lookup(oh_name);
|
|
if (!oh) {
|
|
dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n",
|
|
oh_name);
|
|
ret = -EINVAL;
|
|
goto odbfd_exit1;
|
|
}
|
|
hwmods[i] = oh;
|
|
}
|
|
|
|
od = omap_device_alloc(pdev, hwmods, oh_cnt);
|
|
if (!od) {
|
|
dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
|
|
oh_name);
|
|
ret = PTR_ERR(od);
|
|
goto odbfd_exit1;
|
|
}
|
|
|
|
/* Fix up missing resource names */
|
|
for (i = 0; i < pdev->num_resources; i++) {
|
|
struct resource *r = &pdev->resource[i];
|
|
|
|
if (r->name == NULL)
|
|
r->name = dev_name(&pdev->dev);
|
|
}
|
|
|
|
pdev->dev.pm_domain = &omap_device_pm_domain;
|
|
|
|
odbfd_exit1:
|
|
kfree(hwmods);
|
|
odbfd_exit:
|
|
return ret;
|
|
}
|
|
|
|
static int _omap_device_notifier_call(struct notifier_block *nb,
|
|
unsigned long event, void *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct omap_device *od;
|
|
|
|
switch (event) {
|
|
case BUS_NOTIFY_DEL_DEVICE:
|
|
if (pdev->archdata.od)
|
|
omap_device_delete(pdev->archdata.od);
|
|
break;
|
|
case BUS_NOTIFY_ADD_DEVICE:
|
|
if (pdev->dev.of_node)
|
|
omap_device_build_from_dt(pdev);
|
|
/* fall through */
|
|
default:
|
|
od = to_omap_device(pdev);
|
|
if (od)
|
|
od->_driver_status = event;
|
|
}
|
|
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
/**
|
|
* _omap_device_enable_hwmods - call omap_hwmod_enable() on all hwmods
|
|
* @od: struct omap_device *od
|
|
*
|
|
* Enable all underlying hwmods. Returns 0.
|
|
*/
|
|
static int _omap_device_enable_hwmods(struct omap_device *od)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
omap_hwmod_enable(od->hwmods[i]);
|
|
|
|
/* XXX pass along return value here? */
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* _omap_device_idle_hwmods - call omap_hwmod_idle() on all hwmods
|
|
* @od: struct omap_device *od
|
|
*
|
|
* Idle all underlying hwmods. Returns 0.
|
|
*/
|
|
static int _omap_device_idle_hwmods(struct omap_device *od)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
omap_hwmod_idle(od->hwmods[i]);
|
|
|
|
/* XXX pass along return value here? */
|
|
return 0;
|
|
}
|
|
|
|
/* Public functions for use by core code */
|
|
|
|
/**
|
|
* omap_device_get_context_loss_count - get lost context count
|
|
* @od: struct omap_device *
|
|
*
|
|
* Using the primary hwmod, query the context loss count for this
|
|
* device.
|
|
*
|
|
* Callers should consider context for this device lost any time this
|
|
* function returns a value different than the value the caller got
|
|
* the last time it called this function.
|
|
*
|
|
* If any hwmods exist for the omap_device assoiated with @pdev,
|
|
* return the context loss counter for that hwmod, otherwise return
|
|
* zero.
|
|
*/
|
|
int omap_device_get_context_loss_count(struct platform_device *pdev)
|
|
{
|
|
struct omap_device *od;
|
|
u32 ret = 0;
|
|
|
|
od = to_omap_device(pdev);
|
|
|
|
if (od->hwmods_cnt)
|
|
ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* omap_device_count_resources - count number of struct resource entries needed
|
|
* @od: struct omap_device *
|
|
* @flags: Type of resources to include when counting (IRQ/DMA/MEM)
|
|
*
|
|
* Count the number of struct resource entries needed for this
|
|
* omap_device @od. Used by omap_device_build_ss() to determine how
|
|
* much memory to allocate before calling
|
|
* omap_device_fill_resources(). Returns the count.
|
|
*/
|
|
static int omap_device_count_resources(struct omap_device *od,
|
|
unsigned long flags)
|
|
{
|
|
int c = 0;
|
|
int i;
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++)
|
|
c += omap_hwmod_count_resources(od->hwmods[i], flags);
|
|
|
|
pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
|
|
od->pdev->name, c, od->hwmods_cnt);
|
|
|
|
return c;
|
|
}
|
|
|
|
/**
|
|
* omap_device_fill_resources - fill in array of struct resource
|
|
* @od: struct omap_device *
|
|
* @res: pointer to an array of struct resource to be filled in
|
|
*
|
|
* Populate one or more empty struct resource pointed to by @res with
|
|
* the resource data for this omap_device @od. Used by
|
|
* omap_device_build_ss() after calling omap_device_count_resources().
|
|
* Ideally this function would not be needed at all. If omap_device
|
|
* replaces platform_device, then we can specify our own
|
|
* get_resource()/ get_irq()/etc functions that use the underlying
|
|
* omap_hwmod information. Or if platform_device is extended to use
|
|
* subarchitecture-specific function pointers, the various
|
|
* platform_device functions can simply call omap_device internal
|
|
* functions to get device resources. Hacking around the existing
|
|
* platform_device code wastes memory. Returns 0.
|
|
*/
|
|
static int omap_device_fill_resources(struct omap_device *od,
|
|
struct resource *res)
|
|
{
|
|
int i, r;
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
r = omap_hwmod_fill_resources(od->hwmods[i], res);
|
|
res += r;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* _od_fill_dma_resources - fill in array of struct resource with dma resources
|
|
* @od: struct omap_device *
|
|
* @res: pointer to an array of struct resource to be filled in
|
|
*
|
|
* Populate one or more empty struct resource pointed to by @res with
|
|
* the dma resource data for this omap_device @od. Used by
|
|
* omap_device_alloc() after calling omap_device_count_resources().
|
|
*
|
|
* Ideally this function would not be needed at all. If we have
|
|
* mechanism to get dma resources from DT.
|
|
*
|
|
* Returns 0.
|
|
*/
|
|
static int _od_fill_dma_resources(struct omap_device *od,
|
|
struct resource *res)
|
|
{
|
|
int i, r;
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
r = omap_hwmod_fill_dma_resources(od->hwmods[i], res);
|
|
res += r;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* omap_device_alloc - allocate an omap_device
|
|
* @pdev: platform_device that will be included in this omap_device
|
|
* @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
* @pdata: platform_data ptr to associate with the platform_device
|
|
* @pdata_len: amount of memory pointed to by @pdata
|
|
*
|
|
* Convenience function for allocating an omap_device structure and filling
|
|
* hwmods, and resources.
|
|
*
|
|
* Returns an struct omap_device pointer or ERR_PTR() on error;
|
|
*/
|
|
struct omap_device *omap_device_alloc(struct platform_device *pdev,
|
|
struct omap_hwmod **ohs, int oh_cnt)
|
|
{
|
|
int ret = -ENOMEM;
|
|
struct omap_device *od;
|
|
struct resource *res = NULL;
|
|
int i, res_count;
|
|
struct omap_hwmod **hwmods;
|
|
|
|
od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
|
|
if (!od) {
|
|
ret = -ENOMEM;
|
|
goto oda_exit1;
|
|
}
|
|
od->hwmods_cnt = oh_cnt;
|
|
|
|
hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
|
|
if (!hwmods)
|
|
goto oda_exit2;
|
|
|
|
od->hwmods = hwmods;
|
|
od->pdev = pdev;
|
|
|
|
/*
|
|
* Non-DT Boot:
|
|
* Here, pdev->num_resources = 0, and we should get all the
|
|
* resources from hwmod.
|
|
*
|
|
* DT Boot:
|
|
* OF framework will construct the resource structure (currently
|
|
* does for MEM & IRQ resource) and we should respect/use these
|
|
* resources, killing hwmod dependency.
|
|
* If pdev->num_resources > 0, we assume that MEM & IRQ resources
|
|
* have been allocated by OF layer already (through DTB).
|
|
* As preparation for the future we examine the OF provided resources
|
|
* to see if we have DMA resources provided already. In this case
|
|
* there is no need to update the resources for the device, we use the
|
|
* OF provided ones.
|
|
*
|
|
* TODO: Once DMA resource is available from OF layer, we should
|
|
* kill filling any resources from hwmod.
|
|
*/
|
|
if (!pdev->num_resources) {
|
|
/* Count all resources for the device */
|
|
res_count = omap_device_count_resources(od, IORESOURCE_IRQ |
|
|
IORESOURCE_DMA |
|
|
IORESOURCE_MEM);
|
|
} else {
|
|
/* Take a look if we already have DMA resource via DT */
|
|
for (i = 0; i < pdev->num_resources; i++) {
|
|
struct resource *r = &pdev->resource[i];
|
|
|
|
/* We have it, no need to touch the resources */
|
|
if (r->flags == IORESOURCE_DMA)
|
|
goto have_everything;
|
|
}
|
|
/* Count only DMA resources for the device */
|
|
res_count = omap_device_count_resources(od, IORESOURCE_DMA);
|
|
/* The device has no DMA resource, no need for update */
|
|
if (!res_count)
|
|
goto have_everything;
|
|
|
|
res_count += pdev->num_resources;
|
|
}
|
|
|
|
/* Allocate resources memory to account for new resources */
|
|
res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
|
|
if (!res)
|
|
goto oda_exit3;
|
|
|
|
if (!pdev->num_resources) {
|
|
dev_dbg(&pdev->dev, "%s: using %d resources from hwmod\n",
|
|
__func__, res_count);
|
|
omap_device_fill_resources(od, res);
|
|
} else {
|
|
dev_dbg(&pdev->dev,
|
|
"%s: appending %d DMA resources from hwmod\n",
|
|
__func__, res_count - pdev->num_resources);
|
|
memcpy(res, pdev->resource,
|
|
sizeof(struct resource) * pdev->num_resources);
|
|
_od_fill_dma_resources(od, &res[pdev->num_resources]);
|
|
}
|
|
|
|
ret = platform_device_add_resources(pdev, res, res_count);
|
|
kfree(res);
|
|
|
|
if (ret)
|
|
goto oda_exit3;
|
|
|
|
have_everything:
|
|
pdev->archdata.od = od;
|
|
|
|
for (i = 0; i < oh_cnt; i++) {
|
|
hwmods[i]->od = od;
|
|
_add_hwmod_clocks_clkdev(od, hwmods[i]);
|
|
}
|
|
|
|
return od;
|
|
|
|
oda_exit3:
|
|
kfree(hwmods);
|
|
oda_exit2:
|
|
kfree(od);
|
|
oda_exit1:
|
|
dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
|
|
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
void omap_device_delete(struct omap_device *od)
|
|
{
|
|
if (!od)
|
|
return;
|
|
|
|
od->pdev->archdata.od = NULL;
|
|
kfree(od->hwmods);
|
|
kfree(od);
|
|
}
|
|
|
|
/**
|
|
* omap_device_build - build and register an omap_device with one omap_hwmod
|
|
* @pdev_name: name of the platform_device driver to use
|
|
* @pdev_id: this platform_device's connection ID
|
|
* @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
* @pdata: platform_data ptr to associate with the platform_device
|
|
* @pdata_len: amount of memory pointed to by @pdata
|
|
*
|
|
* Convenience function for building and registering a single
|
|
* omap_device record, which in turn builds and registers a
|
|
* platform_device record. See omap_device_build_ss() for more
|
|
* information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
|
|
* passes along the return value of omap_device_build_ss().
|
|
*/
|
|
struct platform_device __init *omap_device_build(const char *pdev_name,
|
|
int pdev_id,
|
|
struct omap_hwmod *oh,
|
|
void *pdata, int pdata_len)
|
|
{
|
|
struct omap_hwmod *ohs[] = { oh };
|
|
|
|
if (!oh)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
|
|
pdata_len);
|
|
}
|
|
|
|
/**
|
|
* omap_device_build_ss - build and register an omap_device with multiple hwmods
|
|
* @pdev_name: name of the platform_device driver to use
|
|
* @pdev_id: this platform_device's connection ID
|
|
* @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
* @pdata: platform_data ptr to associate with the platform_device
|
|
* @pdata_len: amount of memory pointed to by @pdata
|
|
*
|
|
* Convenience function for building and registering an omap_device
|
|
* subsystem record. Subsystem records consist of multiple
|
|
* omap_hwmods. This function in turn builds and registers a
|
|
* platform_device record. Returns an ERR_PTR() on error, or passes
|
|
* along the return value of omap_device_register().
|
|
*/
|
|
struct platform_device __init *omap_device_build_ss(const char *pdev_name,
|
|
int pdev_id,
|
|
struct omap_hwmod **ohs,
|
|
int oh_cnt, void *pdata,
|
|
int pdata_len)
|
|
{
|
|
int ret = -ENOMEM;
|
|
struct platform_device *pdev;
|
|
struct omap_device *od;
|
|
|
|
if (!ohs || oh_cnt == 0 || !pdev_name)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
if (!pdata && pdata_len > 0)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
pdev = platform_device_alloc(pdev_name, pdev_id);
|
|
if (!pdev) {
|
|
ret = -ENOMEM;
|
|
goto odbs_exit;
|
|
}
|
|
|
|
/* Set the dev_name early to allow dev_xxx in omap_device_alloc */
|
|
if (pdev->id != -1)
|
|
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
|
|
else
|
|
dev_set_name(&pdev->dev, "%s", pdev->name);
|
|
|
|
od = omap_device_alloc(pdev, ohs, oh_cnt);
|
|
if (IS_ERR(od))
|
|
goto odbs_exit1;
|
|
|
|
ret = platform_device_add_data(pdev, pdata, pdata_len);
|
|
if (ret)
|
|
goto odbs_exit2;
|
|
|
|
ret = omap_device_register(pdev);
|
|
if (ret)
|
|
goto odbs_exit2;
|
|
|
|
return pdev;
|
|
|
|
odbs_exit2:
|
|
omap_device_delete(od);
|
|
odbs_exit1:
|
|
platform_device_put(pdev);
|
|
odbs_exit:
|
|
|
|
pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
|
|
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
#ifdef CONFIG_PM_RUNTIME
|
|
static int _od_runtime_suspend(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
int ret;
|
|
|
|
ret = pm_generic_runtime_suspend(dev);
|
|
|
|
if (!ret)
|
|
omap_device_idle(pdev);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int _od_runtime_resume(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
omap_device_enable(pdev);
|
|
|
|
return pm_generic_runtime_resume(dev);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SUSPEND
|
|
static int _od_suspend_noirq(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
int ret;
|
|
|
|
/* Don't attempt late suspend on a driver that is not bound */
|
|
if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER)
|
|
return 0;
|
|
|
|
ret = pm_generic_suspend_noirq(dev);
|
|
|
|
if (!ret && !pm_runtime_status_suspended(dev)) {
|
|
if (pm_generic_runtime_suspend(dev) == 0) {
|
|
omap_device_idle(pdev);
|
|
od->flags |= OMAP_DEVICE_SUSPENDED;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int _od_resume_noirq(struct device *dev)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
|
|
if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
|
|
!pm_runtime_status_suspended(dev)) {
|
|
od->flags &= ~OMAP_DEVICE_SUSPENDED;
|
|
omap_device_enable(pdev);
|
|
pm_generic_runtime_resume(dev);
|
|
}
|
|
|
|
return pm_generic_resume_noirq(dev);
|
|
}
|
|
#else
|
|
#define _od_suspend_noirq NULL
|
|
#define _od_resume_noirq NULL
|
|
#endif
|
|
|
|
struct dev_pm_domain omap_device_pm_domain = {
|
|
.ops = {
|
|
SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
|
|
NULL)
|
|
USE_PLATFORM_PM_SLEEP_OPS
|
|
.suspend_noirq = _od_suspend_noirq,
|
|
.resume_noirq = _od_resume_noirq,
|
|
}
|
|
};
|
|
|
|
/**
|
|
* omap_device_register - register an omap_device with one omap_hwmod
|
|
* @od: struct omap_device * to register
|
|
*
|
|
* Register the omap_device structure. This currently just calls
|
|
* platform_device_register() on the underlying platform_device.
|
|
* Returns the return value of platform_device_register().
|
|
*/
|
|
int omap_device_register(struct platform_device *pdev)
|
|
{
|
|
pr_debug("omap_device: %s: registering\n", pdev->name);
|
|
|
|
pdev->dev.pm_domain = &omap_device_pm_domain;
|
|
return platform_device_add(pdev);
|
|
}
|
|
|
|
|
|
/* Public functions for use by device drivers through struct platform_data */
|
|
|
|
/**
|
|
* omap_device_enable - fully activate an omap_device
|
|
* @od: struct omap_device * to activate
|
|
*
|
|
* Do whatever is necessary for the hwmods underlying omap_device @od
|
|
* to be accessible and ready to operate. This generally involves
|
|
* enabling clocks, setting SYSCONFIG registers; and in the future may
|
|
* involve remuxing pins. Device drivers should call this function
|
|
* indirectly via pm_runtime_get*(). Returns -EINVAL if called when
|
|
* the omap_device is already enabled, or passes along the return
|
|
* value of _omap_device_enable_hwmods().
|
|
*/
|
|
int omap_device_enable(struct platform_device *pdev)
|
|
{
|
|
int ret;
|
|
struct omap_device *od;
|
|
|
|
od = to_omap_device(pdev);
|
|
|
|
if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
|
|
dev_warn(&pdev->dev,
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
__func__, od->_state);
|
|
return -EINVAL;
|
|
}
|
|
|
|
ret = _omap_device_enable_hwmods(od);
|
|
|
|
od->_state = OMAP_DEVICE_STATE_ENABLED;
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* omap_device_idle - idle an omap_device
|
|
* @od: struct omap_device * to idle
|
|
*
|
|
* Idle omap_device @od. Device drivers call this function indirectly
|
|
* via pm_runtime_put*(). Returns -EINVAL if the omap_device is not
|
|
* currently enabled, or passes along the return value of
|
|
* _omap_device_idle_hwmods().
|
|
*/
|
|
int omap_device_idle(struct platform_device *pdev)
|
|
{
|
|
int ret;
|
|
struct omap_device *od;
|
|
|
|
od = to_omap_device(pdev);
|
|
|
|
if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
|
|
dev_warn(&pdev->dev,
|
|
"omap_device: %s() called from invalid state %d\n",
|
|
__func__, od->_state);
|
|
return -EINVAL;
|
|
}
|
|
|
|
ret = _omap_device_idle_hwmods(od);
|
|
|
|
od->_state = OMAP_DEVICE_STATE_IDLE;
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* omap_device_assert_hardreset - set a device's hardreset line
|
|
* @pdev: struct platform_device * to reset
|
|
* @name: const char * name of the reset line
|
|
*
|
|
* Set the hardreset line identified by @name on the IP blocks
|
|
* associated with the hwmods backing the platform_device @pdev. All
|
|
* of the hwmods associated with @pdev must have the same hardreset
|
|
* line linked to them for this to work. Passes along the return value
|
|
* of omap_hwmod_assert_hardreset() in the event of any failure, or
|
|
* returns 0 upon success.
|
|
*/
|
|
int omap_device_assert_hardreset(struct platform_device *pdev, const char *name)
|
|
{
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
int ret = 0;
|
|
int i;
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
ret = omap_hwmod_assert_hardreset(od->hwmods[i], name);
|
|
if (ret)
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* omap_device_deassert_hardreset - release a device's hardreset line
|
|
* @pdev: struct platform_device * to reset
|
|
* @name: const char * name of the reset line
|
|
*
|
|
* Release the hardreset line identified by @name on the IP blocks
|
|
* associated with the hwmods backing the platform_device @pdev. All
|
|
* of the hwmods associated with @pdev must have the same hardreset
|
|
* line linked to them for this to work. Passes along the return
|
|
* value of omap_hwmod_deassert_hardreset() in the event of any
|
|
* failure, or returns 0 upon success.
|
|
*/
|
|
int omap_device_deassert_hardreset(struct platform_device *pdev,
|
|
const char *name)
|
|
{
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
int ret = 0;
|
|
int i;
|
|
|
|
for (i = 0; i < od->hwmods_cnt; i++) {
|
|
ret = omap_hwmod_deassert_hardreset(od->hwmods[i], name);
|
|
if (ret)
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* omap_device_get_by_hwmod_name() - convert a hwmod name to
|
|
* device pointer.
|
|
* @oh_name: name of the hwmod device
|
|
*
|
|
* Returns back a struct device * pointer associated with a hwmod
|
|
* device represented by a hwmod_name
|
|
*/
|
|
struct device *omap_device_get_by_hwmod_name(const char *oh_name)
|
|
{
|
|
struct omap_hwmod *oh;
|
|
|
|
if (!oh_name) {
|
|
WARN(1, "%s: no hwmod name!\n", __func__);
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
|
|
oh = omap_hwmod_lookup(oh_name);
|
|
if (!oh) {
|
|
WARN(1, "%s: no hwmod for %s\n", __func__,
|
|
oh_name);
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
if (!oh->od) {
|
|
WARN(1, "%s: no omap_device for %s\n", __func__,
|
|
oh_name);
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
return &oh->od->pdev->dev;
|
|
}
|
|
|
|
static struct notifier_block platform_nb = {
|
|
.notifier_call = _omap_device_notifier_call,
|
|
};
|
|
|
|
static int __init omap_device_init(void)
|
|
{
|
|
bus_register_notifier(&platform_bus_type, &platform_nb);
|
|
return 0;
|
|
}
|
|
omap_core_initcall(omap_device_init);
|
|
|
|
/**
|
|
* omap_device_late_idle - idle devices without drivers
|
|
* @dev: struct device * associated with omap_device
|
|
* @data: unused
|
|
*
|
|
* Check the driver bound status of this device, and idle it
|
|
* if there is no driver attached.
|
|
*/
|
|
static int __init omap_device_late_idle(struct device *dev, void *data)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct omap_device *od = to_omap_device(pdev);
|
|
|
|
if (!od)
|
|
return 0;
|
|
|
|
/*
|
|
* If omap_device state is enabled, but has no driver bound,
|
|
* idle it.
|
|
*/
|
|
if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER) {
|
|
if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
|
|
dev_warn(dev, "%s: enabled but no driver. Idling\n",
|
|
__func__);
|
|
omap_device_idle(pdev);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __init omap_device_late_init(void)
|
|
{
|
|
bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle);
|
|
return 0;
|
|
}
|
|
omap_late_initcall_sync(omap_device_late_init);
|