mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-01 11:56:45 +07:00
92a578b064
This time we have some more new material than we used to have during the last couple of development cycles. The most important part of it to me is the introduction of a unified interface for accessing device properties provided by platform firmware. It works with Device Trees and ACPI in a uniform way and drivers using it need not worry about where the properties come from as long as the platform firmware (either DT or ACPI) makes them available. It covers both devices and "bare" device node objects without struct device representation as that turns out to be necessary in some cases. This has been in the works for quite a few months (and development cycles) and has been approved by all of the relevant maintainers. On top of that, some drivers are switched over to the new interface (at25, leds-gpio, gpio_keys_polled) and some additional changes are made to the core GPIO subsystem to allow device drivers to manipulate GPIOs in the "canonical" way on platforms that provide GPIO information in their ACPI tables, but don't assign names to GPIO lines (in which case the driver needs to do that on the basis of what it knows about the device in question). That also has been approved by the GPIO core maintainers and the rfkill driver is now going to use it. Second is support for hardware P-states in the intel_pstate driver. It uses CPUID to detect whether or not the feature is supported by the processor in which case it will be enabled by default. However, it can be disabled entirely from the kernel command line if necessary. Next is support for a platform firmware interface based on ACPI operation regions used by the PMIC (Power Management Integrated Circuit) chips on the Intel Baytrail-T and Baytrail-T-CR platforms. That interface is used for manipulating power resources and for thermal management: sensor temperature reporting, trip point setting and so on. Also the ACPI core is now going to support the _DEP configuration information in a limited way. Basically, _DEP it supposed to reflect off-the-hierarchy dependencies between devices which may be very indirect, like when AML for one device accesses locations in an operation region handled by another device's driver (usually, the device depended on this way is a serial bus or GPIO controller). The support added this time is sufficient to make the ACPI battery driver work on Asus T100A, but it is general enough to be able to cover some other use cases in the future. Finally, we have a new cpufreq driver for the Loongson1B processor. In addition to the above, there are fixes and cleanups all over the place as usual and a traditional ACPICA update to a recent upstream release. As far as the fixes go, the ACPI LPSS (Low-power Subsystem) driver for Intel platforms should be able to handle power management of the DMA engine correctly, the cpufreq-dt driver should interact with the thermal subsystem in a better way and the ACPI backlight driver should handle some more corner cases, among other things. On top of the ACPICA update there are fixes for race conditions in the ACPICA's interrupt handling code which might lead to some random and strange looking failures on some systems. In the cleanups department the most visible part is the series of commits targeted at getting rid of the CONFIG_PM_RUNTIME configuration option. That was triggered by a discussion regarding the generic power domains code during which we realized that trying to support certain combinations of PM config options was painful and not really worth it, because nobody would use them in production anyway. For this reason, we decided to make CONFIG_PM_SLEEP select CONFIG_PM_RUNTIME and that lead to the conclusion that the latter became redundant and CONFIG_PM could be used instead of it. The material here makes that replacement in a major part of the tree, but there will be at least one more batch of that in the second part of the merge window. Specifics: - Support for retrieving device properties information from ACPI _DSD device configuration objects and a unified device properties interface for device drivers (and subsystems) on top of that. As stated above, this works with Device Trees and ACPI and allows device drivers to be written in a platform firmware (DT or ACPI) agnostic way. The at25, leds-gpio and gpio_keys_polled drivers are now going to use this new interface and the GPIO subsystem is additionally modified to allow device drivers to assign names to GPIO resources returned by ACPI _CRS objects (in case _DSD is not present or does not provide the expected data). The changes in this set are mostly from Mika Westerberg, Rafael J Wysocki, Aaron Lu, and Darren Hart with some fixes from others (Fabio Estevam, Geert Uytterhoeven). - Support for Hardware Managed Performance States (HWP) as described in Volume 3, section 14.4, of the Intel SDM in the intel_pstate driver. CPUID is used to detect whether or not the feature is supported by the processor. If supported, it will be enabled automatically unless the intel_pstate=no_hwp switch is present in the kernel command line. From Dirk Brandewie. - New Intel Broadwell-H ID for intel_pstate (Dirk Brandewie). - Support for firmware interface based on ACPI operation regions used by the PMIC chips on the Intel Baytrail-T and Baytrail-T-CR platforms for power resource control and thermal management (Aaron Lu). - Limited support for retrieving off-the-hierarchy dependencies between devices from ACPI _DEP device configuration objects and deferred probing support for the ACPI battery driver based on the _DEP information to make that driver work on Asus T100A (Lan Tianyu). - New cpufreq driver for the Loongson1B processor (Kelvin Cheung). - ACPICA update to upstream revision 20141107 which only affects tools (Bob Moore). - Fixes for race conditions in the ACPICA's interrupt handling code and in the ACPI code related to system suspend and resume (Lv Zheng and Rafael J Wysocki). - ACPI core fix for an RCU-related issue in the ioremap() regions management code that slowed down significantly after CPUs had been allowed to enter idle states even if they'd had RCU callbakcs queued and triggered some problems in certain proprietary graphics driver (and elsewhere). The fix replaces synchronize_rcu() in that code with synchronize_rcu_expedited() which makes the issue go away. From Konstantin Khlebnikov. - ACPI LPSS (Low-Power Subsystem) driver fix to handle power management of the DMA engine included into the LPSS correctly. The problem is that the DMA engine doesn't have ACPI PM support of its own and it simply is turned off when the last LPSS device having ACPI PM support goes into D3cold. To work around that, the PM domain used by the ACPI LPSS driver is redesigned so at least one device with ACPI PM support will be on as long as the DMA engine is in use. From Andy Shevchenko. - ACPI backlight driver fix to avoid using it on "Win8-compatible" systems where it doesn't work and where it was used by default by mistake (Aaron Lu). - Assorted minor ACPI core fixes and cleanups from Tomasz Nowicki, Sudeep Holla, Huang Rui, Hanjun Guo, Fabian Frederick, and Ashwin Chaugule (mostly related to the upcoming ARM64 support). - Intel RAPL (Running Average Power Limit) power capping driver fixes and improvements including new processor IDs (Jacob Pan). - Generic power domains modification to power up domains after attaching devices to them to meet the expectations of device drivers and bus types assuming devices to be accessible at probe time (Ulf Hansson). - Preliminary support for controlling device clocks from the generic power domains core code and modifications of the ARM/shmobile platform to use that feature (Ulf Hansson). - Assorted minor fixes and cleanups of the generic power domains core code (Ulf Hansson, Geert Uytterhoeven). - Assorted minor fixes and cleanups of the device clocks control code in the PM core (Geert Uytterhoeven, Grygorii Strashko). - Consolidation of device power management Kconfig options by making CONFIG_PM_SLEEP select CONFIG_PM_RUNTIME and removing the latter which is now redundant (Rafael J Wysocki and Kevin Hilman). That is the first batch of the changes needed for this purpose. - Core device runtime power management support code cleanup related to the execution of callbacks (Andrzej Hajda). - cpuidle ARM support improvements (Lorenzo Pieralisi). - cpuidle cleanup related to the CPUIDLE_FLAG_TIME_VALID flag and a new MAINTAINERS entry for ARM Exynos cpuidle (Daniel Lezcano and Bartlomiej Zolnierkiewicz). - New cpufreq driver callback (->ready) to be executed when the cpufreq core is ready to use a given policy object and cpufreq-dt driver modification to use that callback for cooling device registration (Viresh Kumar). - cpufreq core fixes and cleanups (Viresh Kumar, Vince Hsu, James Geboski, Tomeu Vizoso). - Assorted fixes and cleanups in the cpufreq-pcc, intel_pstate, cpufreq-dt, pxa2xx cpufreq drivers (Lenny Szubowicz, Ethan Zhao, Stefan Wahren, Petr Cvek). - OPP (Operating Performance Points) framework modification to allow OPPs to be removed too and update of a few cpufreq drivers (cpufreq-dt, exynos5440, imx6q, cpufreq) to remove OPPs (added during initialization) on driver removal (Viresh Kumar). - Hibernation core fixes and cleanups (Tina Ruchandani and Markus Elfring). - PM Kconfig fix related to CPU power management (Pankaj Dubey). - cpupower tool fix (Prarit Bhargava). / -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABCAAGBQJUhj6JAAoJEILEb/54YlRxTM4P/j5g5SfqvY0QKsn7sR7MGZ6v nsgCBhJAqTw3ocNC7EAs8z9h2GWy1KbKpakKYWAh9Fs1yZoey7tFSlcv/Rgjlp70 uU5sDQHtpE9mHKiymdsowiQuWgpl962L4k+k8hUslhlvgk1PvVbpajR6OqG8G+pD asuIW9eh1APNkLyXmRJ3ZPomzs0VmRdZJ0NEs0lKX9mJskqEvxPIwdaxq3iaJq9B Fo0J345zUDcJnxWblDRdHlOigCimglElfN5qJwaC4KpwUKuBvLRKbp4f69+wfT0c kYFiR29X5KjJ2kLfP/wKsLyuDCYYXRq3tCia5M1tAqOjZ+UA89H/GDftx/5lntmv qUlBa35VfdS1SX4HyApZitOHiLgo+It/hl8Z9bJnhyVw66NxmMQ8JYN2imb8Lhqh XCLR7BxLTah82AapLJuQ0ZDHPzZqMPG2veC2vAzRMYzVijict/p4Y2+qBqONltER 4rs9uRVn+hamX33lCLg8BEN8zqlnT3rJFIgGaKjq/wXHAU/zpE9CjOrKMQcAg9+s t51XMNPwypHMAYyGVhEL89ImjXnXxBkLRuquhlmEpvQchIhR+mR3dLsarGn7da44 WPIQJXzcsojXczcwwfqsJCR4I1FTFyQIW+UNh02GkDRgRovQqo+Jk762U7vQwqH+ LBdhvVaS1VW4v+FWXEoZ =5dox -----END PGP SIGNATURE----- Merge tag 'pm+acpi-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm Pull ACPI and power management updates from Rafael Wysocki: "This time we have some more new material than we used to have during the last couple of development cycles. The most important part of it to me is the introduction of a unified interface for accessing device properties provided by platform firmware. It works with Device Trees and ACPI in a uniform way and drivers using it need not worry about where the properties come from as long as the platform firmware (either DT or ACPI) makes them available. It covers both devices and "bare" device node objects without struct device representation as that turns out to be necessary in some cases. This has been in the works for quite a few months (and development cycles) and has been approved by all of the relevant maintainers. On top of that, some drivers are switched over to the new interface (at25, leds-gpio, gpio_keys_polled) and some additional changes are made to the core GPIO subsystem to allow device drivers to manipulate GPIOs in the "canonical" way on platforms that provide GPIO information in their ACPI tables, but don't assign names to GPIO lines (in which case the driver needs to do that on the basis of what it knows about the device in question). That also has been approved by the GPIO core maintainers and the rfkill driver is now going to use it. Second is support for hardware P-states in the intel_pstate driver. It uses CPUID to detect whether or not the feature is supported by the processor in which case it will be enabled by default. However, it can be disabled entirely from the kernel command line if necessary. Next is support for a platform firmware interface based on ACPI operation regions used by the PMIC (Power Management Integrated Circuit) chips on the Intel Baytrail-T and Baytrail-T-CR platforms. That interface is used for manipulating power resources and for thermal management: sensor temperature reporting, trip point setting and so on. Also the ACPI core is now going to support the _DEP configuration information in a limited way. Basically, _DEP it supposed to reflect off-the-hierarchy dependencies between devices which may be very indirect, like when AML for one device accesses locations in an operation region handled by another device's driver (usually, the device depended on this way is a serial bus or GPIO controller). The support added this time is sufficient to make the ACPI battery driver work on Asus T100A, but it is general enough to be able to cover some other use cases in the future. Finally, we have a new cpufreq driver for the Loongson1B processor. In addition to the above, there are fixes and cleanups all over the place as usual and a traditional ACPICA update to a recent upstream release. As far as the fixes go, the ACPI LPSS (Low-power Subsystem) driver for Intel platforms should be able to handle power management of the DMA engine correctly, the cpufreq-dt driver should interact with the thermal subsystem in a better way and the ACPI backlight driver should handle some more corner cases, among other things. On top of the ACPICA update there are fixes for race conditions in the ACPICA's interrupt handling code which might lead to some random and strange looking failures on some systems. In the cleanups department the most visible part is the series of commits targeted at getting rid of the CONFIG_PM_RUNTIME configuration option. That was triggered by a discussion regarding the generic power domains code during which we realized that trying to support certain combinations of PM config options was painful and not really worth it, because nobody would use them in production anyway. For this reason, we decided to make CONFIG_PM_SLEEP select CONFIG_PM_RUNTIME and that lead to the conclusion that the latter became redundant and CONFIG_PM could be used instead of it. The material here makes that replacement in a major part of the tree, but there will be at least one more batch of that in the second part of the merge window. Specifics: - Support for retrieving device properties information from ACPI _DSD device configuration objects and a unified device properties interface for device drivers (and subsystems) on top of that. As stated above, this works with Device Trees and ACPI and allows device drivers to be written in a platform firmware (DT or ACPI) agnostic way. The at25, leds-gpio and gpio_keys_polled drivers are now going to use this new interface and the GPIO subsystem is additionally modified to allow device drivers to assign names to GPIO resources returned by ACPI _CRS objects (in case _DSD is not present or does not provide the expected data). The changes in this set are mostly from Mika Westerberg, Rafael J Wysocki, Aaron Lu, and Darren Hart with some fixes from others (Fabio Estevam, Geert Uytterhoeven). - Support for Hardware Managed Performance States (HWP) as described in Volume 3, section 14.4, of the Intel SDM in the intel_pstate driver. CPUID is used to detect whether or not the feature is supported by the processor. If supported, it will be enabled automatically unless the intel_pstate=no_hwp switch is present in the kernel command line. From Dirk Brandewie. - New Intel Broadwell-H ID for intel_pstate (Dirk Brandewie). - Support for firmware interface based on ACPI operation regions used by the PMIC chips on the Intel Baytrail-T and Baytrail-T-CR platforms for power resource control and thermal management (Aaron Lu). - Limited support for retrieving off-the-hierarchy dependencies between devices from ACPI _DEP device configuration objects and deferred probing support for the ACPI battery driver based on the _DEP information to make that driver work on Asus T100A (Lan Tianyu). - New cpufreq driver for the Loongson1B processor (Kelvin Cheung). - ACPICA update to upstream revision 20141107 which only affects tools (Bob Moore). - Fixes for race conditions in the ACPICA's interrupt handling code and in the ACPI code related to system suspend and resume (Lv Zheng and Rafael J Wysocki). - ACPI core fix for an RCU-related issue in the ioremap() regions management code that slowed down significantly after CPUs had been allowed to enter idle states even if they'd had RCU callbakcs queued and triggered some problems in certain proprietary graphics driver (and elsewhere). The fix replaces synchronize_rcu() in that code with synchronize_rcu_expedited() which makes the issue go away. From Konstantin Khlebnikov. - ACPI LPSS (Low-Power Subsystem) driver fix to handle power management of the DMA engine included into the LPSS correctly. The problem is that the DMA engine doesn't have ACPI PM support of its own and it simply is turned off when the last LPSS device having ACPI PM support goes into D3cold. To work around that, the PM domain used by the ACPI LPSS driver is redesigned so at least one device with ACPI PM support will be on as long as the DMA engine is in use. From Andy Shevchenko. - ACPI backlight driver fix to avoid using it on "Win8-compatible" systems where it doesn't work and where it was used by default by mistake (Aaron Lu). - Assorted minor ACPI core fixes and cleanups from Tomasz Nowicki, Sudeep Holla, Huang Rui, Hanjun Guo, Fabian Frederick, and Ashwin Chaugule (mostly related to the upcoming ARM64 support). - Intel RAPL (Running Average Power Limit) power capping driver fixes and improvements including new processor IDs (Jacob Pan). - Generic power domains modification to power up domains after attaching devices to them to meet the expectations of device drivers and bus types assuming devices to be accessible at probe time (Ulf Hansson). - Preliminary support for controlling device clocks from the generic power domains core code and modifications of the ARM/shmobile platform to use that feature (Ulf Hansson). - Assorted minor fixes and cleanups of the generic power domains core code (Ulf Hansson, Geert Uytterhoeven). - Assorted minor fixes and cleanups of the device clocks control code in the PM core (Geert Uytterhoeven, Grygorii Strashko). - Consolidation of device power management Kconfig options by making CONFIG_PM_SLEEP select CONFIG_PM_RUNTIME and removing the latter which is now redundant (Rafael J Wysocki and Kevin Hilman). That is the first batch of the changes needed for this purpose. - Core device runtime power management support code cleanup related to the execution of callbacks (Andrzej Hajda). - cpuidle ARM support improvements (Lorenzo Pieralisi). - cpuidle cleanup related to the CPUIDLE_FLAG_TIME_VALID flag and a new MAINTAINERS entry for ARM Exynos cpuidle (Daniel Lezcano and Bartlomiej Zolnierkiewicz). - New cpufreq driver callback (->ready) to be executed when the cpufreq core is ready to use a given policy object and cpufreq-dt driver modification to use that callback for cooling device registration (Viresh Kumar). - cpufreq core fixes and cleanups (Viresh Kumar, Vince Hsu, James Geboski, Tomeu Vizoso). - Assorted fixes and cleanups in the cpufreq-pcc, intel_pstate, cpufreq-dt, pxa2xx cpufreq drivers (Lenny Szubowicz, Ethan Zhao, Stefan Wahren, Petr Cvek). - OPP (Operating Performance Points) framework modification to allow OPPs to be removed too and update of a few cpufreq drivers (cpufreq-dt, exynos5440, imx6q, cpufreq) to remove OPPs (added during initialization) on driver removal (Viresh Kumar). - Hibernation core fixes and cleanups (Tina Ruchandani and Markus Elfring). - PM Kconfig fix related to CPU power management (Pankaj Dubey). - cpupower tool fix (Prarit Bhargava)" * tag 'pm+acpi-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (120 commits) i2c-omap / PM: Drop CONFIG_PM_RUNTIME from i2c-omap.c dmaengine / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM tools: cpupower: fix return checks for sysfs_get_idlestate_count() drivers: sh / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM e1000e / igb / PM: Eliminate CONFIG_PM_RUNTIME MMC / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM MFD / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM misc / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM media / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM input / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM leds: leds-gpio: Fix multiple instances registration without 'label' property iio / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM hsi / OMAP / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM i2c-hid / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM drm / exynos / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM gpio / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM hwrandom / exynos / PM: Use CONFIG_PM in #ifdef block / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PM USB / PM: Drop CONFIG_PM_RUNTIME from the USB core PM: Merge the SET*_RUNTIME_PM_OPS() macros ...
629 lines
16 KiB
C
629 lines
16 KiB
C
/*
|
|
* arch/arm/plat-orion/gpio.c
|
|
*
|
|
* Marvell Orion SoC GPIO handling.
|
|
*
|
|
* This file is licensed under the terms of the GNU General Public
|
|
* License version 2. This program is licensed "as is" without any
|
|
* warranty of any kind, whether express or implied.
|
|
*/
|
|
|
|
#define DEBUG
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/irq.h>
|
|
#include <linux/irqdomain.h>
|
|
#include <linux/module.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/io.h>
|
|
#include <linux/gpio.h>
|
|
#include <linux/leds.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_irq.h>
|
|
#include <linux/of_address.h>
|
|
#include <plat/orion-gpio.h>
|
|
|
|
/*
|
|
* GPIO unit register offsets.
|
|
*/
|
|
#define GPIO_OUT_OFF 0x0000
|
|
#define GPIO_IO_CONF_OFF 0x0004
|
|
#define GPIO_BLINK_EN_OFF 0x0008
|
|
#define GPIO_IN_POL_OFF 0x000c
|
|
#define GPIO_DATA_IN_OFF 0x0010
|
|
#define GPIO_EDGE_CAUSE_OFF 0x0014
|
|
#define GPIO_EDGE_MASK_OFF 0x0018
|
|
#define GPIO_LEVEL_MASK_OFF 0x001c
|
|
|
|
struct orion_gpio_chip {
|
|
struct gpio_chip chip;
|
|
spinlock_t lock;
|
|
void __iomem *base;
|
|
unsigned long valid_input;
|
|
unsigned long valid_output;
|
|
int mask_offset;
|
|
int secondary_irq_base;
|
|
struct irq_domain *domain;
|
|
};
|
|
|
|
static void __iomem *GPIO_OUT(struct orion_gpio_chip *ochip)
|
|
{
|
|
return ochip->base + GPIO_OUT_OFF;
|
|
}
|
|
|
|
static void __iomem *GPIO_IO_CONF(struct orion_gpio_chip *ochip)
|
|
{
|
|
return ochip->base + GPIO_IO_CONF_OFF;
|
|
}
|
|
|
|
static void __iomem *GPIO_BLINK_EN(struct orion_gpio_chip *ochip)
|
|
{
|
|
return ochip->base + GPIO_BLINK_EN_OFF;
|
|
}
|
|
|
|
static void __iomem *GPIO_IN_POL(struct orion_gpio_chip *ochip)
|
|
{
|
|
return ochip->base + GPIO_IN_POL_OFF;
|
|
}
|
|
|
|
static void __iomem *GPIO_DATA_IN(struct orion_gpio_chip *ochip)
|
|
{
|
|
return ochip->base + GPIO_DATA_IN_OFF;
|
|
}
|
|
|
|
static void __iomem *GPIO_EDGE_CAUSE(struct orion_gpio_chip *ochip)
|
|
{
|
|
return ochip->base + GPIO_EDGE_CAUSE_OFF;
|
|
}
|
|
|
|
static void __iomem *GPIO_EDGE_MASK(struct orion_gpio_chip *ochip)
|
|
{
|
|
return ochip->base + ochip->mask_offset + GPIO_EDGE_MASK_OFF;
|
|
}
|
|
|
|
static void __iomem *GPIO_LEVEL_MASK(struct orion_gpio_chip *ochip)
|
|
{
|
|
return ochip->base + ochip->mask_offset + GPIO_LEVEL_MASK_OFF;
|
|
}
|
|
|
|
|
|
static struct orion_gpio_chip orion_gpio_chips[2];
|
|
static int orion_gpio_chip_count;
|
|
|
|
static inline void
|
|
__set_direction(struct orion_gpio_chip *ochip, unsigned pin, int input)
|
|
{
|
|
u32 u;
|
|
|
|
u = readl(GPIO_IO_CONF(ochip));
|
|
if (input)
|
|
u |= 1 << pin;
|
|
else
|
|
u &= ~(1 << pin);
|
|
writel(u, GPIO_IO_CONF(ochip));
|
|
}
|
|
|
|
static void __set_level(struct orion_gpio_chip *ochip, unsigned pin, int high)
|
|
{
|
|
u32 u;
|
|
|
|
u = readl(GPIO_OUT(ochip));
|
|
if (high)
|
|
u |= 1 << pin;
|
|
else
|
|
u &= ~(1 << pin);
|
|
writel(u, GPIO_OUT(ochip));
|
|
}
|
|
|
|
static inline void
|
|
__set_blinking(struct orion_gpio_chip *ochip, unsigned pin, int blink)
|
|
{
|
|
u32 u;
|
|
|
|
u = readl(GPIO_BLINK_EN(ochip));
|
|
if (blink)
|
|
u |= 1 << pin;
|
|
else
|
|
u &= ~(1 << pin);
|
|
writel(u, GPIO_BLINK_EN(ochip));
|
|
}
|
|
|
|
static inline int
|
|
orion_gpio_is_valid(struct orion_gpio_chip *ochip, unsigned pin, int mode)
|
|
{
|
|
if (pin >= ochip->chip.ngpio)
|
|
goto err_out;
|
|
|
|
if ((mode & GPIO_INPUT_OK) && !test_bit(pin, &ochip->valid_input))
|
|
goto err_out;
|
|
|
|
if ((mode & GPIO_OUTPUT_OK) && !test_bit(pin, &ochip->valid_output))
|
|
goto err_out;
|
|
|
|
return 1;
|
|
|
|
err_out:
|
|
pr_debug("%s: invalid GPIO %d\n", __func__, pin);
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* GPIO primitives.
|
|
*/
|
|
static int orion_gpio_request(struct gpio_chip *chip, unsigned pin)
|
|
{
|
|
struct orion_gpio_chip *ochip =
|
|
container_of(chip, struct orion_gpio_chip, chip);
|
|
|
|
if (orion_gpio_is_valid(ochip, pin, GPIO_INPUT_OK) ||
|
|
orion_gpio_is_valid(ochip, pin, GPIO_OUTPUT_OK))
|
|
return 0;
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
static int orion_gpio_direction_input(struct gpio_chip *chip, unsigned pin)
|
|
{
|
|
struct orion_gpio_chip *ochip =
|
|
container_of(chip, struct orion_gpio_chip, chip);
|
|
unsigned long flags;
|
|
|
|
if (!orion_gpio_is_valid(ochip, pin, GPIO_INPUT_OK))
|
|
return -EINVAL;
|
|
|
|
spin_lock_irqsave(&ochip->lock, flags);
|
|
__set_direction(ochip, pin, 1);
|
|
spin_unlock_irqrestore(&ochip->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int orion_gpio_get(struct gpio_chip *chip, unsigned pin)
|
|
{
|
|
struct orion_gpio_chip *ochip =
|
|
container_of(chip, struct orion_gpio_chip, chip);
|
|
int val;
|
|
|
|
if (readl(GPIO_IO_CONF(ochip)) & (1 << pin)) {
|
|
val = readl(GPIO_DATA_IN(ochip)) ^ readl(GPIO_IN_POL(ochip));
|
|
} else {
|
|
val = readl(GPIO_OUT(ochip));
|
|
}
|
|
|
|
return (val >> pin) & 1;
|
|
}
|
|
|
|
static int
|
|
orion_gpio_direction_output(struct gpio_chip *chip, unsigned pin, int value)
|
|
{
|
|
struct orion_gpio_chip *ochip =
|
|
container_of(chip, struct orion_gpio_chip, chip);
|
|
unsigned long flags;
|
|
|
|
if (!orion_gpio_is_valid(ochip, pin, GPIO_OUTPUT_OK))
|
|
return -EINVAL;
|
|
|
|
spin_lock_irqsave(&ochip->lock, flags);
|
|
__set_blinking(ochip, pin, 0);
|
|
__set_level(ochip, pin, value);
|
|
__set_direction(ochip, pin, 0);
|
|
spin_unlock_irqrestore(&ochip->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void orion_gpio_set(struct gpio_chip *chip, unsigned pin, int value)
|
|
{
|
|
struct orion_gpio_chip *ochip =
|
|
container_of(chip, struct orion_gpio_chip, chip);
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&ochip->lock, flags);
|
|
__set_level(ochip, pin, value);
|
|
spin_unlock_irqrestore(&ochip->lock, flags);
|
|
}
|
|
|
|
static int orion_gpio_to_irq(struct gpio_chip *chip, unsigned pin)
|
|
{
|
|
struct orion_gpio_chip *ochip =
|
|
container_of(chip, struct orion_gpio_chip, chip);
|
|
|
|
return irq_create_mapping(ochip->domain,
|
|
ochip->secondary_irq_base + pin);
|
|
}
|
|
|
|
/*
|
|
* Orion-specific GPIO API extensions.
|
|
*/
|
|
static struct orion_gpio_chip *orion_gpio_chip_find(int pin)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < orion_gpio_chip_count; i++) {
|
|
struct orion_gpio_chip *ochip = orion_gpio_chips + i;
|
|
struct gpio_chip *chip = &ochip->chip;
|
|
|
|
if (pin >= chip->base && pin < chip->base + chip->ngpio)
|
|
return ochip;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void __init orion_gpio_set_unused(unsigned pin)
|
|
{
|
|
struct orion_gpio_chip *ochip = orion_gpio_chip_find(pin);
|
|
|
|
if (ochip == NULL)
|
|
return;
|
|
|
|
pin -= ochip->chip.base;
|
|
|
|
/* Configure as output, drive low. */
|
|
__set_level(ochip, pin, 0);
|
|
__set_direction(ochip, pin, 0);
|
|
}
|
|
|
|
void __init orion_gpio_set_valid(unsigned pin, int mode)
|
|
{
|
|
struct orion_gpio_chip *ochip = orion_gpio_chip_find(pin);
|
|
|
|
if (ochip == NULL)
|
|
return;
|
|
|
|
pin -= ochip->chip.base;
|
|
|
|
if (mode == 1)
|
|
mode = GPIO_INPUT_OK | GPIO_OUTPUT_OK;
|
|
|
|
if (mode & GPIO_INPUT_OK)
|
|
__set_bit(pin, &ochip->valid_input);
|
|
else
|
|
__clear_bit(pin, &ochip->valid_input);
|
|
|
|
if (mode & GPIO_OUTPUT_OK)
|
|
__set_bit(pin, &ochip->valid_output);
|
|
else
|
|
__clear_bit(pin, &ochip->valid_output);
|
|
}
|
|
|
|
void orion_gpio_set_blink(unsigned pin, int blink)
|
|
{
|
|
struct orion_gpio_chip *ochip = orion_gpio_chip_find(pin);
|
|
unsigned long flags;
|
|
|
|
if (ochip == NULL)
|
|
return;
|
|
|
|
spin_lock_irqsave(&ochip->lock, flags);
|
|
__set_level(ochip, pin & 31, 0);
|
|
__set_blinking(ochip, pin & 31, blink);
|
|
spin_unlock_irqrestore(&ochip->lock, flags);
|
|
}
|
|
EXPORT_SYMBOL(orion_gpio_set_blink);
|
|
|
|
#define ORION_BLINK_HALF_PERIOD 100 /* ms */
|
|
|
|
int orion_gpio_led_blink_set(struct gpio_desc *desc, int state,
|
|
unsigned long *delay_on, unsigned long *delay_off)
|
|
{
|
|
unsigned gpio = desc_to_gpio(desc);
|
|
|
|
if (delay_on && delay_off && !*delay_on && !*delay_off)
|
|
*delay_on = *delay_off = ORION_BLINK_HALF_PERIOD;
|
|
|
|
switch (state) {
|
|
case GPIO_LED_NO_BLINK_LOW:
|
|
case GPIO_LED_NO_BLINK_HIGH:
|
|
orion_gpio_set_blink(gpio, 0);
|
|
gpio_set_value(gpio, state);
|
|
break;
|
|
case GPIO_LED_BLINK:
|
|
orion_gpio_set_blink(gpio, 1);
|
|
}
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(orion_gpio_led_blink_set);
|
|
|
|
|
|
/*****************************************************************************
|
|
* Orion GPIO IRQ
|
|
*
|
|
* GPIO_IN_POL register controls whether GPIO_DATA_IN will hold the same
|
|
* value of the line or the opposite value.
|
|
*
|
|
* Level IRQ handlers: DATA_IN is used directly as cause register.
|
|
* Interrupt are masked by LEVEL_MASK registers.
|
|
* Edge IRQ handlers: Change in DATA_IN are latched in EDGE_CAUSE.
|
|
* Interrupt are masked by EDGE_MASK registers.
|
|
* Both-edge handlers: Similar to regular Edge handlers, but also swaps
|
|
* the polarity to catch the next line transaction.
|
|
* This is a race condition that might not perfectly
|
|
* work on some use cases.
|
|
*
|
|
* Every eight GPIO lines are grouped (OR'ed) before going up to main
|
|
* cause register.
|
|
*
|
|
* EDGE cause mask
|
|
* data-in /--------| |-----| |----\
|
|
* -----| |----- ---- to main cause reg
|
|
* X \----------------| |----/
|
|
* polarity LEVEL mask
|
|
*
|
|
****************************************************************************/
|
|
|
|
static int gpio_irq_set_type(struct irq_data *d, u32 type)
|
|
{
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
|
|
struct irq_chip_type *ct = irq_data_get_chip_type(d);
|
|
struct orion_gpio_chip *ochip = gc->private;
|
|
int pin;
|
|
u32 u;
|
|
|
|
pin = d->hwirq - ochip->secondary_irq_base;
|
|
|
|
u = readl(GPIO_IO_CONF(ochip)) & (1 << pin);
|
|
if (!u) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
type &= IRQ_TYPE_SENSE_MASK;
|
|
if (type == IRQ_TYPE_NONE)
|
|
return -EINVAL;
|
|
|
|
/* Check if we need to change chip and handler */
|
|
if (!(ct->type & type))
|
|
if (irq_setup_alt_chip(d, type))
|
|
return -EINVAL;
|
|
|
|
/*
|
|
* Configure interrupt polarity.
|
|
*/
|
|
if (type == IRQ_TYPE_EDGE_RISING || type == IRQ_TYPE_LEVEL_HIGH) {
|
|
u = readl(GPIO_IN_POL(ochip));
|
|
u &= ~(1 << pin);
|
|
writel(u, GPIO_IN_POL(ochip));
|
|
} else if (type == IRQ_TYPE_EDGE_FALLING || type == IRQ_TYPE_LEVEL_LOW) {
|
|
u = readl(GPIO_IN_POL(ochip));
|
|
u |= 1 << pin;
|
|
writel(u, GPIO_IN_POL(ochip));
|
|
} else if (type == IRQ_TYPE_EDGE_BOTH) {
|
|
u32 v;
|
|
|
|
v = readl(GPIO_IN_POL(ochip)) ^ readl(GPIO_DATA_IN(ochip));
|
|
|
|
/*
|
|
* set initial polarity based on current input level
|
|
*/
|
|
u = readl(GPIO_IN_POL(ochip));
|
|
if (v & (1 << pin))
|
|
u |= 1 << pin; /* falling */
|
|
else
|
|
u &= ~(1 << pin); /* rising */
|
|
writel(u, GPIO_IN_POL(ochip));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void gpio_irq_handler(unsigned irq, struct irq_desc *desc)
|
|
{
|
|
struct orion_gpio_chip *ochip = irq_get_handler_data(irq);
|
|
u32 cause, type;
|
|
int i;
|
|
|
|
if (ochip == NULL)
|
|
return;
|
|
|
|
cause = readl(GPIO_DATA_IN(ochip)) & readl(GPIO_LEVEL_MASK(ochip));
|
|
cause |= readl(GPIO_EDGE_CAUSE(ochip)) & readl(GPIO_EDGE_MASK(ochip));
|
|
|
|
for (i = 0; i < ochip->chip.ngpio; i++) {
|
|
int irq;
|
|
|
|
irq = ochip->secondary_irq_base + i;
|
|
|
|
if (!(cause & (1 << i)))
|
|
continue;
|
|
|
|
type = irq_get_trigger_type(irq);
|
|
if ((type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
|
|
/* Swap polarity (race with GPIO line) */
|
|
u32 polarity;
|
|
|
|
polarity = readl(GPIO_IN_POL(ochip));
|
|
polarity ^= 1 << i;
|
|
writel(polarity, GPIO_IN_POL(ochip));
|
|
}
|
|
generic_handle_irq(irq);
|
|
}
|
|
}
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
#include <linux/seq_file.h>
|
|
|
|
static void orion_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
|
|
{
|
|
struct orion_gpio_chip *ochip =
|
|
container_of(chip, struct orion_gpio_chip, chip);
|
|
u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk;
|
|
int i;
|
|
|
|
out = readl_relaxed(GPIO_OUT(ochip));
|
|
io_conf = readl_relaxed(GPIO_IO_CONF(ochip));
|
|
blink = readl_relaxed(GPIO_BLINK_EN(ochip));
|
|
in_pol = readl_relaxed(GPIO_IN_POL(ochip));
|
|
data_in = readl_relaxed(GPIO_DATA_IN(ochip));
|
|
cause = readl_relaxed(GPIO_EDGE_CAUSE(ochip));
|
|
edg_msk = readl_relaxed(GPIO_EDGE_MASK(ochip));
|
|
lvl_msk = readl_relaxed(GPIO_LEVEL_MASK(ochip));
|
|
|
|
for (i = 0; i < chip->ngpio; i++) {
|
|
const char *label;
|
|
u32 msk;
|
|
bool is_out;
|
|
|
|
label = gpiochip_is_requested(chip, i);
|
|
if (!label)
|
|
continue;
|
|
|
|
msk = 1 << i;
|
|
is_out = !(io_conf & msk);
|
|
|
|
seq_printf(s, " gpio-%-3d (%-20.20s)", chip->base + i, label);
|
|
|
|
if (is_out) {
|
|
seq_printf(s, " out %s %s\n",
|
|
out & msk ? "hi" : "lo",
|
|
blink & msk ? "(blink )" : "");
|
|
continue;
|
|
}
|
|
|
|
seq_printf(s, " in %s (act %s) - IRQ",
|
|
(data_in ^ in_pol) & msk ? "hi" : "lo",
|
|
in_pol & msk ? "lo" : "hi");
|
|
if (!((edg_msk | lvl_msk) & msk)) {
|
|
seq_printf(s, " disabled\n");
|
|
continue;
|
|
}
|
|
if (edg_msk & msk)
|
|
seq_printf(s, " edge ");
|
|
if (lvl_msk & msk)
|
|
seq_printf(s, " level");
|
|
seq_printf(s, " (%s)\n", cause & msk ? "pending" : "clear ");
|
|
}
|
|
}
|
|
#else
|
|
#define orion_gpio_dbg_show NULL
|
|
#endif
|
|
|
|
static void orion_gpio_unmask_irq(struct irq_data *d)
|
|
{
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
|
|
struct irq_chip_type *ct = irq_data_get_chip_type(d);
|
|
u32 reg_val;
|
|
u32 mask = d->mask;
|
|
|
|
irq_gc_lock(gc);
|
|
reg_val = irq_reg_readl(gc, ct->regs.mask);
|
|
reg_val |= mask;
|
|
irq_reg_writel(gc, reg_val, ct->regs.mask);
|
|
irq_gc_unlock(gc);
|
|
}
|
|
|
|
static void orion_gpio_mask_irq(struct irq_data *d)
|
|
{
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
|
|
struct irq_chip_type *ct = irq_data_get_chip_type(d);
|
|
u32 mask = d->mask;
|
|
u32 reg_val;
|
|
|
|
irq_gc_lock(gc);
|
|
reg_val = irq_reg_readl(gc, ct->regs.mask);
|
|
reg_val &= ~mask;
|
|
irq_reg_writel(gc, reg_val, ct->regs.mask);
|
|
irq_gc_unlock(gc);
|
|
}
|
|
|
|
void __init orion_gpio_init(struct device_node *np,
|
|
int gpio_base, int ngpio,
|
|
void __iomem *base, int mask_offset,
|
|
int secondary_irq_base,
|
|
int irqs[4])
|
|
{
|
|
struct orion_gpio_chip *ochip;
|
|
struct irq_chip_generic *gc;
|
|
struct irq_chip_type *ct;
|
|
char gc_label[16];
|
|
int i;
|
|
|
|
if (orion_gpio_chip_count == ARRAY_SIZE(orion_gpio_chips))
|
|
return;
|
|
|
|
snprintf(gc_label, sizeof(gc_label), "orion_gpio%d",
|
|
orion_gpio_chip_count);
|
|
|
|
ochip = orion_gpio_chips + orion_gpio_chip_count;
|
|
ochip->chip.label = kstrdup(gc_label, GFP_KERNEL);
|
|
ochip->chip.request = orion_gpio_request;
|
|
ochip->chip.direction_input = orion_gpio_direction_input;
|
|
ochip->chip.get = orion_gpio_get;
|
|
ochip->chip.direction_output = orion_gpio_direction_output;
|
|
ochip->chip.set = orion_gpio_set;
|
|
ochip->chip.to_irq = orion_gpio_to_irq;
|
|
ochip->chip.base = gpio_base;
|
|
ochip->chip.ngpio = ngpio;
|
|
ochip->chip.can_sleep = 0;
|
|
#ifdef CONFIG_OF
|
|
ochip->chip.of_node = np;
|
|
#endif
|
|
ochip->chip.dbg_show = orion_gpio_dbg_show;
|
|
|
|
spin_lock_init(&ochip->lock);
|
|
ochip->base = (void __iomem *)base;
|
|
ochip->valid_input = 0;
|
|
ochip->valid_output = 0;
|
|
ochip->mask_offset = mask_offset;
|
|
ochip->secondary_irq_base = secondary_irq_base;
|
|
|
|
gpiochip_add(&ochip->chip);
|
|
|
|
/*
|
|
* Mask and clear GPIO interrupts.
|
|
*/
|
|
writel(0, GPIO_EDGE_CAUSE(ochip));
|
|
writel(0, GPIO_EDGE_MASK(ochip));
|
|
writel(0, GPIO_LEVEL_MASK(ochip));
|
|
|
|
/* Setup the interrupt handlers. Each chip can have up to 4
|
|
* interrupt handlers, with each handler dealing with 8 GPIO
|
|
* pins. */
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
if (irqs[i]) {
|
|
irq_set_handler_data(irqs[i], ochip);
|
|
irq_set_chained_handler(irqs[i], gpio_irq_handler);
|
|
}
|
|
}
|
|
|
|
gc = irq_alloc_generic_chip("orion_gpio_irq", 2,
|
|
secondary_irq_base,
|
|
ochip->base, handle_level_irq);
|
|
gc->private = ochip;
|
|
ct = gc->chip_types;
|
|
ct->regs.mask = ochip->mask_offset + GPIO_LEVEL_MASK_OFF;
|
|
ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW;
|
|
ct->chip.irq_mask = orion_gpio_mask_irq;
|
|
ct->chip.irq_unmask = orion_gpio_unmask_irq;
|
|
ct->chip.irq_set_type = gpio_irq_set_type;
|
|
ct->chip.name = ochip->chip.label;
|
|
|
|
ct++;
|
|
ct->regs.mask = ochip->mask_offset + GPIO_EDGE_MASK_OFF;
|
|
ct->regs.ack = GPIO_EDGE_CAUSE_OFF;
|
|
ct->type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
|
|
ct->chip.irq_ack = irq_gc_ack_clr_bit;
|
|
ct->chip.irq_mask = orion_gpio_mask_irq;
|
|
ct->chip.irq_unmask = orion_gpio_unmask_irq;
|
|
ct->chip.irq_set_type = gpio_irq_set_type;
|
|
ct->handler = handle_edge_irq;
|
|
ct->chip.name = ochip->chip.label;
|
|
|
|
irq_setup_generic_chip(gc, IRQ_MSK(ngpio), IRQ_GC_INIT_MASK_CACHE,
|
|
IRQ_NOREQUEST, IRQ_LEVEL | IRQ_NOPROBE);
|
|
|
|
/* Setup irq domain on top of the generic chip. */
|
|
ochip->domain = irq_domain_add_legacy(np,
|
|
ochip->chip.ngpio,
|
|
ochip->secondary_irq_base,
|
|
ochip->secondary_irq_base,
|
|
&irq_domain_simple_ops,
|
|
ochip);
|
|
if (!ochip->domain)
|
|
panic("%s: couldn't allocate irq domain (DT).\n",
|
|
ochip->chip.label);
|
|
|
|
orion_gpio_chip_count++;
|
|
}
|