aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2015-12-11 20:45:06 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-01-07 08:11:32 -0500
commiteebb3e8d8aaf28f4bcaf12fd3645350bfd2f0b36 (patch)
tree5d74ba65967afd6e6c1931887827a5abe66afc5d
parentc3a49cf35ead83829e54fc771a3acc1b1aa6dfd8 (diff)
ACPI / LPSS: override power state for LPSS DMA device
This is a third approach to workaround long standing issue with LPSS on BayTrail. First one [1] was reverted since it didn't resolve the issue comprehensively. Second one [2] was rejected by internal review. The LPSS DMA controller does not have neither _PS0 nor _PS3 method. Moreover it can be powered off automatically whenever the last LPSS device goes down. In case of no power any access to the DMA controller will hang the system. The behaviour is reproduced on some HP laptops based on Intel BayTrail [3,4] as well as on ASuS T100TA transformer. Power on the LPSS island through the registers accessible in a specific way. [1] http://www.spinics.net/lists/linux-acpi/msg53963.html [2] https://bugzilla.redhat.com/attachment.cgi?id=1066779&action=diff [3] https://bugzilla.redhat.com/show_bug.cgi?id=1184273 [4] http://www.spinics.net/lists/dmaengine/msg01514.html Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--arch/x86/Kconfig3
-rw-r--r--arch/x86/include/asm/iosf_mbi.h2
-rw-r--r--drivers/acpi/acpi_lpss.c153
3 files changed, 150 insertions, 8 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index db3622f22b61..790aa3ee1afa 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -523,9 +523,10 @@ config X86_INTEL_QUARK
523 523
524config X86_INTEL_LPSS 524config X86_INTEL_LPSS
525 bool "Intel Low Power Subsystem Support" 525 bool "Intel Low Power Subsystem Support"
526 depends on ACPI 526 depends on X86 && ACPI
527 select COMMON_CLK 527 select COMMON_CLK
528 select PINCTRL 528 select PINCTRL
529 select IOSF_MBI
529 ---help--- 530 ---help---
530 Select to build support for Intel Low Power Subsystem such as 531 Select to build support for Intel Low Power Subsystem such as
531 found on Intel Lynxpoint PCH. Selecting this option enables 532 found on Intel Lynxpoint PCH. Selecting this option enables
diff --git a/arch/x86/include/asm/iosf_mbi.h b/arch/x86/include/asm/iosf_mbi.h
index cdc5f6352ac5..b41ee164930a 100644
--- a/arch/x86/include/asm/iosf_mbi.h
+++ b/arch/x86/include/asm/iosf_mbi.h
@@ -19,6 +19,8 @@
19/* IOSF SB read/write opcodes */ 19/* IOSF SB read/write opcodes */
20#define MBI_MMIO_READ 0x00 20#define MBI_MMIO_READ 0x00
21#define MBI_MMIO_WRITE 0x01 21#define MBI_MMIO_WRITE 0x01
22#define MBI_CFG_READ 0x04
23#define MBI_CFG_WRITE 0x05
22#define MBI_CR_READ 0x06 24#define MBI_CR_READ 0x06
23#define MBI_CR_WRITE 0x07 25#define MBI_CR_WRITE 0x07
24#define MBI_REG_READ 0x10 26#define MBI_REG_READ 0x10
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index a10c2d665ec2..84d3d90557d1 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -15,6 +15,7 @@
15#include <linux/clk-provider.h> 15#include <linux/clk-provider.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/mutex.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19#include <linux/platform_data/clk-lpss.h> 20#include <linux/platform_data/clk-lpss.h>
20#include <linux/pm_runtime.h> 21#include <linux/pm_runtime.h>
@@ -26,6 +27,10 @@ ACPI_MODULE_NAME("acpi_lpss");
26 27
27#ifdef CONFIG_X86_INTEL_LPSS 28#ifdef CONFIG_X86_INTEL_LPSS
28 29
30#include <asm/cpu_device_id.h>
31#include <asm/iosf_mbi.h>
32#include <asm/pmc_atom.h>
33
29#define LPSS_ADDR(desc) ((unsigned long)&desc) 34#define LPSS_ADDR(desc) ((unsigned long)&desc)
30 35
31#define LPSS_CLK_SIZE 0x04 36#define LPSS_CLK_SIZE 0x04
@@ -71,7 +76,7 @@ struct lpss_device_desc {
71 void (*setup)(struct lpss_private_data *pdata); 76 void (*setup)(struct lpss_private_data *pdata);
72}; 77};
73 78
74static struct lpss_device_desc lpss_dma_desc = { 79static const struct lpss_device_desc lpss_dma_desc = {
75 .flags = LPSS_CLK, 80 .flags = LPSS_CLK,
76}; 81};
77 82
@@ -84,6 +89,23 @@ struct lpss_private_data {
84 u32 prv_reg_ctx[LPSS_PRV_REG_COUNT]; 89 u32 prv_reg_ctx[LPSS_PRV_REG_COUNT];
85}; 90};
86 91
92/* LPSS run time quirks */
93static unsigned int lpss_quirks;
94
95/*
96 * LPSS_QUIRK_ALWAYS_POWER_ON: override power state for LPSS DMA device.
97 *
98 * The LPSS DMA controller does not have neither _PS0 nor _PS3 method. Moreover
99 * it can be powered off automatically whenever the last LPSS device goes down.
100 * In case of no power any access to the DMA controller will hang the system.
101 * The behaviour is reproduced on some HP laptops based on Intel BayTrail as
102 * well as on ASuS T100TA transformer.
103 *
104 * This quirk overrides power state of entire LPSS island to keep DMA powered
105 * on whenever we have at least one other device in use.
106 */
107#define LPSS_QUIRK_ALWAYS_POWER_ON BIT(0)
108
87/* UART Component Parameter Register */ 109/* UART Component Parameter Register */
88#define LPSS_UART_CPR 0xF4 110#define LPSS_UART_CPR 0xF4
89#define LPSS_UART_CPR_AFCE BIT(4) 111#define LPSS_UART_CPR_AFCE BIT(4)
@@ -196,13 +218,21 @@ static const struct lpss_device_desc bsw_i2c_dev_desc = {
196 .setup = byt_i2c_setup, 218 .setup = byt_i2c_setup,
197}; 219};
198 220
199static struct lpss_device_desc bsw_spi_dev_desc = { 221static const struct lpss_device_desc bsw_spi_dev_desc = {
200 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX 222 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX
201 | LPSS_NO_D3_DELAY, 223 | LPSS_NO_D3_DELAY,
202 .prv_offset = 0x400, 224 .prv_offset = 0x400,
203 .setup = lpss_deassert_reset, 225 .setup = lpss_deassert_reset,
204}; 226};
205 227
228#define ICPU(model) { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
229
230static const struct x86_cpu_id lpss_cpu_ids[] = {
231 ICPU(0x37), /* Valleyview, Bay Trail */
232 ICPU(0x4c), /* Braswell, Cherry Trail */
233 {}
234};
235
206#else 236#else
207 237
208#define LPSS_ADDR(desc) (0UL) 238#define LPSS_ADDR(desc) (0UL)
@@ -661,6 +691,89 @@ static int acpi_lpss_resume_early(struct device *dev)
661} 691}
662#endif /* CONFIG_PM_SLEEP */ 692#endif /* CONFIG_PM_SLEEP */
663 693
694/* IOSF SB for LPSS island */
695#define LPSS_IOSF_UNIT_LPIOEP 0xA0
696#define LPSS_IOSF_UNIT_LPIO1 0xAB
697#define LPSS_IOSF_UNIT_LPIO2 0xAC
698
699#define LPSS_IOSF_PMCSR 0x84
700#define LPSS_PMCSR_D0 0
701#define LPSS_PMCSR_D3hot 3
702#define LPSS_PMCSR_Dx_MASK GENMASK(1, 0)
703
704#define LPSS_IOSF_GPIODEF0 0x154
705#define LPSS_GPIODEF0_DMA1_D3 BIT(2)
706#define LPSS_GPIODEF0_DMA2_D3 BIT(3)
707#define LPSS_GPIODEF0_DMA_D3_MASK GENMASK(3, 2)
708
709static DEFINE_MUTEX(lpss_iosf_mutex);
710
711static void lpss_iosf_enter_d3_state(void)
712{
713 u32 value1 = 0;
714 u32 mask1 = LPSS_GPIODEF0_DMA_D3_MASK;
715 u32 value2 = LPSS_PMCSR_D3hot;
716 u32 mask2 = LPSS_PMCSR_Dx_MASK;
717 /*
718 * PMC provides an information about actual status of the LPSS devices.
719 * Here we read the values related to LPSS power island, i.e. LPSS
720 * devices, excluding both LPSS DMA controllers, along with SCC domain.
721 */
722 u32 func_dis, d3_sts_0, pmc_status, pmc_mask = 0xfe000ffe;
723 int ret;
724
725 ret = pmc_atom_read(PMC_FUNC_DIS, &func_dis);
726 if (ret)
727 return;
728
729 mutex_lock(&lpss_iosf_mutex);
730
731 ret = pmc_atom_read(PMC_D3_STS_0, &d3_sts_0);
732 if (ret)
733 goto exit;
734
735 /*
736 * Get the status of entire LPSS power island per device basis.
737 * Shutdown both LPSS DMA controllers if and only if all other devices
738 * are already in D3hot.
739 */
740 pmc_status = (~(d3_sts_0 | func_dis)) & pmc_mask;
741 if (pmc_status)
742 goto exit;
743
744 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO1, MBI_CFG_WRITE,
745 LPSS_IOSF_PMCSR, value2, mask2);
746
747 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO2, MBI_CFG_WRITE,
748 LPSS_IOSF_PMCSR, value2, mask2);
749
750 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIOEP, MBI_CR_WRITE,
751 LPSS_IOSF_GPIODEF0, value1, mask1);
752exit:
753 mutex_unlock(&lpss_iosf_mutex);
754}
755
756static void lpss_iosf_exit_d3_state(void)
757{
758 u32 value1 = LPSS_GPIODEF0_DMA1_D3 | LPSS_GPIODEF0_DMA2_D3;
759 u32 mask1 = LPSS_GPIODEF0_DMA_D3_MASK;
760 u32 value2 = LPSS_PMCSR_D0;
761 u32 mask2 = LPSS_PMCSR_Dx_MASK;
762
763 mutex_lock(&lpss_iosf_mutex);
764
765 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIOEP, MBI_CR_WRITE,
766 LPSS_IOSF_GPIODEF0, value1, mask1);
767
768 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO2, MBI_CFG_WRITE,
769 LPSS_IOSF_PMCSR, value2, mask2);
770
771 iosf_mbi_modify(LPSS_IOSF_UNIT_LPIO1, MBI_CFG_WRITE,
772 LPSS_IOSF_PMCSR, value2, mask2);
773
774 mutex_unlock(&lpss_iosf_mutex);
775}
776
664static int acpi_lpss_runtime_suspend(struct device *dev) 777static int acpi_lpss_runtime_suspend(struct device *dev)
665{ 778{
666 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); 779 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
@@ -673,7 +786,17 @@ static int acpi_lpss_runtime_suspend(struct device *dev)
673 if (pdata->dev_desc->flags & LPSS_SAVE_CTX) 786 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
674 acpi_lpss_save_ctx(dev, pdata); 787 acpi_lpss_save_ctx(dev, pdata);
675 788
676 return acpi_dev_runtime_suspend(dev); 789 ret = acpi_dev_runtime_suspend(dev);
790
791 /*
792 * This call must be last in the sequence, otherwise PMC will return
793 * wrong status for devices being about to be powered off. See
794 * lpss_iosf_enter_d3_state() for further information.
795 */
796 if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
797 lpss_iosf_enter_d3_state();
798
799 return ret;
677} 800}
678 801
679static int acpi_lpss_runtime_resume(struct device *dev) 802static int acpi_lpss_runtime_resume(struct device *dev)
@@ -681,6 +804,13 @@ static int acpi_lpss_runtime_resume(struct device *dev)
681 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev)); 804 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
682 int ret; 805 int ret;
683 806
807 /*
808 * This call is kept first to be in symmetry with
809 * acpi_lpss_runtime_suspend() one.
810 */
811 if (lpss_quirks & LPSS_QUIRK_ALWAYS_POWER_ON && iosf_mbi_available())
812 lpss_iosf_exit_d3_state();
813
684 ret = acpi_dev_runtime_resume(dev); 814 ret = acpi_dev_runtime_resume(dev);
685 if (ret) 815 if (ret)
686 return ret; 816 return ret;
@@ -798,10 +928,19 @@ static struct acpi_scan_handler lpss_handler = {
798 928
799void __init acpi_lpss_init(void) 929void __init acpi_lpss_init(void)
800{ 930{
801 if (!lpt_clk_init()) { 931 const struct x86_cpu_id *id;
802 bus_register_notifier(&platform_bus_type, &acpi_lpss_nb); 932 int ret;
803 acpi_scan_add_handler(&lpss_handler); 933
804 } 934 ret = lpt_clk_init();
935 if (ret)
936 return;
937
938 id = x86_match_cpu(lpss_cpu_ids);
939 if (id)
940 lpss_quirks |= LPSS_QUIRK_ALWAYS_POWER_ON;
941
942 bus_register_notifier(&platform_bus_type, &acpi_lpss_nb);
943 acpi_scan_add_handler(&lpss_handler);
805} 944}
806 945
807#else 946#else