diff --git a/arch/arm/boot/dts/qcom/qcom-msm8905-nokia-argon.dts b/arch/arm/boot/dts/qcom/qcom-msm8905-nokia-argon.dts index 9b214d3..aa80133 100644 --- a/arch/arm/boot/dts/qcom/qcom-msm8905-nokia-argon.dts +++ b/arch/arm/boot/dts/qcom/qcom-msm8905-nokia-argon.dts @@ -20,7 +20,6 @@ aliases { }; chosen { - stdout-path = "serial0"; }; reserved-memory { @@ -194,7 +193,7 @@ panel-timing { }; &blsp_uart1 { - status = "okay"; + status = "disabled"; }; &mpss { diff --git a/arch/arm/boot/dts/qcom/qcom-msm8909-nokia-leo-common.dtsi b/arch/arm/boot/dts/qcom/qcom-msm8909-nokia-leo-common.dtsi index 011f088..58c23eb 100644 --- a/arch/arm/boot/dts/qcom/qcom-msm8909-nokia-leo-common.dtsi +++ b/arch/arm/boot/dts/qcom/qcom-msm8909-nokia-leo-common.dtsi @@ -12,7 +12,6 @@ aliases { }; chosen { - stdout-path = "serial0"; }; reserved-memory { @@ -160,7 +159,7 @@ panel-timing { }; &blsp_uart1 { - status = "okay"; + status = "disabled"; }; &mpss { diff --git a/arch/arm/boot/dts/qcom/qcom-msm8909.dtsi b/arch/arm/boot/dts/qcom/qcom-msm8909.dtsi index 131dad7..52bbf7a 100644 --- a/arch/arm/boot/dts/qcom/qcom-msm8909.dtsi +++ b/arch/arm/boot/dts/qcom/qcom-msm8909.dtsi @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -111,6 +112,7 @@ cpu3: cpu@3 { L2_0: l2-cache { compatible = "cache"; cache-level = <2>; + qcom,saw = <&l2_saw>; }; idle-states { @@ -461,13 +463,56 @@ tsens_mode: mode@de { rpm_msg_ram: sram@60000 { compatible = "qcom,rpm-msg-ram"; reg = <0x00060000 0x8000>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x00060000 0x8000>; + + apss_master_stats: sram@150 { + reg = <0x150 0x50>; + }; + + vmpm: sram@1d0 { + reg = <0x1d0 0x40>; + }; + + mpss_master_stats: sram@1150 { + reg = <0x1150 0x50>; + }; + + pronto_master_stats: sram@2150 { + reg = <0x2150 0x50>; + }; }; sram@290000 { - compatible = "qcom,rpm-stats"; + compatible = "qcom,msm8916-rpm-stats"; reg = <0x00290000 0x10000>; }; + mpm: interrupt-controller@601d0 { + compatible = "qcom,mpm"; + qcom,rpm-msg-ram = <&vmpm>; + interrupts = ; + mboxes = <&apcs 1>; + interrupt-controller; + #interrupt-cells = <2>; + #power-domain-cells = <0>; + interrupt-parent = <&intc>; + qcom,mpm-pin-count = <64>; + qcom,mpm-pin-map = <2 184>, + <48 136>, + <49 140>, + <53 72>, + <58 134>, + <62 190>; + }; + + bimc: interconnect@400000 { + compatible = "qcom,msm8909-bimc"; + reg = <0x00400000 0x62000>; + #interconnect-cells = <1>; + }; + tsens: thermal-sensor@4a9000 { compatible = "qcom,msm8909-tsens", "qcom,tsens-v0_1"; reg = <0x004a9000 0x1000>, /* TM */ @@ -497,6 +542,18 @@ restart@4ab000 { reg = <0x004ab000 0x4>; }; + pcnoc: interconnect@500000 { + compatible = "qcom,msm8909-pcnoc"; + reg = <0x00500000 0x11000>; + #interconnect-cells = <1>; + }; + + snoc: interconnect@580000 { + compatible = "qcom,msm8909-snoc"; + reg = <0x00580000 0x14000>; + #interconnect-cells = <1>; + }; + tlmm: pinctrl@1000000 { compatible = "qcom,msm8909-tlmm"; reg = <0x01000000 0x300000>; @@ -506,6 +563,7 @@ tlmm: pinctrl@1000000 { gpio-ranges = <&tlmm 0 0 117>; interrupt-controller; #interrupt-cells = <2>; + wakeup-parent = <&mpm>; blsp_i2c1_default: blsp-i2c1-default-state { pins = "gpio6", "gpio7"; @@ -876,6 +934,8 @@ gpu: gpu@1c00000 { power-domains = <&gcc OXILI_GDSC>; operating-points-v2 = <&gpu_opp_table>; iommus = <&gpu_iommu 1>, <&gpu_iommu 2>; + interconnects = <&bimc MAS_OXILI &bimc SLV_EBI>; + interconnect-names = "gfx-mem"; #cooling-cells = <2>; gpu_opp_table: opp-table { @@ -1603,6 +1663,11 @@ frame@b028000 { }; }; + l2_saw: power-manager@b012000 { + compatible = "qcom,msm8909-saw2-v3.0-scu", "qcom,saw2"; + reg = <0x0b012000 0x1000>; + }; + cpu0_acc: power-manager@b088000 { compatible = "qcom,msm8909-acc"; reg = <0x0b088000 0x1000>; @@ -1757,6 +1822,16 @@ modem_alert0: trip-point0 { }; + rpm-master-stats { + compatible = "qcom,rpm-master-stats"; + qcom,rpm-msg-ram = <&apss_master_stats>, + <&mpss_master_stats>, + <&pronto_master_stats>; + qcom,master-names = "APSS", + "MPSS", + "PRONTO"; + }; + timer { compatible = "arm,armv7-timer"; interrupts = , diff --git a/drivers/clk/qcom/gcc-msm8909.c b/drivers/clk/qcom/gcc-msm8909.c index cc36e81..4a1349d 100644 --- a/drivers/clk/qcom/gcc-msm8909.c +++ b/drivers/clk/qcom/gcc-msm8909.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -2630,6 +2631,19 @@ static struct gdsc *gcc_msm8909_gdscs[] = { [VFE_GDSC] = &vfe_gdsc, }; +bool qcom_msm8909_gdsc_is_active(void) +{ + size_t i; + + for (i = 0; i < ARRAY_SIZE(gcc_msm8909_gdscs); i++) { + struct gdsc *sc = gcc_msm8909_gdscs[i]; + + if (sc && READ_ONCE(sc->pd.status) == GENPD_STATE_ON) + return true; + } + return false; +} + static const struct qcom_reset_map gcc_msm8909_resets[] = { [GCC_AUDIO_CORE_BCR] = { 0x1c008 }, [GCC_BLSP1_BCR] = { 0x01000 }, diff --git a/drivers/cpuidle/cpuidle-qcom-spm.c b/drivers/cpuidle/cpuidle-qcom-spm.c index 69aaa21..d97f0ce 100644 --- a/drivers/cpuidle/cpuidle-qcom-spm.c +++ b/drivers/cpuidle/cpuidle-qcom-spm.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -17,21 +18,118 @@ #include #include #include +#include +#include +#include #include +#include #include #include #include "dt_idle_states.h" +#define QTMR_V1_CNTP_CVAL_LO 0x20 +#define QTMR_V1_CNTP_CVAL_HI 0x24 +#define QTMR_V1_CNTP_CTL 0x2c +#define QTMR_CTL_ENABLE BIT(0) +#define QTMR_CTL_IMASK BIT(1) +#define QCOM_MPM_TIMER_PHYS_BASE 0x0b022000 +#define QCOM_MPM_TIMER_SIZE 0x1000 +#define QCOM_MPM_MIN_DELTA_TICKS 19200ULL /* 1 ms @ 19.2 MHz */ + +static bool rpm_sleep; +module_param(rpm_sleep, bool, 0644); + +static bool l2_sleep; +module_param(l2_sleep, bool, 0644); + +static bool screen_off; +module_param(screen_off, bool, 0644); + +static unsigned int rpm_min_residency_us = 3000; +module_param(rpm_min_residency_us, uint, 0644); + +static unsigned long rpm_sleep_count; +module_param(rpm_sleep_count, ulong, 0444); + +static unsigned long l2_off_count; +module_param(l2_off_count, ulong, 0444); + +static DEFINE_RAW_SPINLOCK(qcom_spm_cluster_lock); +static cpumask_t qcom_spm_idle_cpus; +static bool qcom_spm_cluster_sleeping; +static bool qcom_spm_cluster_l2_off; +static void __iomem *qcom_qtmr_frame0_base; + struct cpuidle_qcom_spm_data { struct cpuidle_driver cpuidle_driver; struct spm_driver_data *spm; }; -static int qcom_pm_collapse(unsigned long int unused) +static u64 qcom_spm_next_wakeup_tick(ktime_t sleep_len) { - qcom_scm_cpu_power_down(QCOM_SCM_CPU_PWR_DOWN_L2_ON); + u64 now = arch_timer_read_counter(); + u64 cval_soft; + u64 wakeup; + + if (sleep_len < 0) + sleep_len = 0; + cval_soft = now + mul_u64_u32_div(ktime_to_ns(sleep_len), + 192, 10000); + wakeup = cval_soft; + + if (qcom_qtmr_frame0_base) { + u32 ctl = readl_relaxed(qcom_qtmr_frame0_base + + QTMR_V1_CNTP_CTL); + + if ((ctl & (QTMR_CTL_ENABLE | QTMR_CTL_IMASK)) == QTMR_CTL_ENABLE) { + u32 hi1, lo, hi2; + + do { + hi1 = readl_relaxed(qcom_qtmr_frame0_base + + QTMR_V1_CNTP_CVAL_HI); + lo = readl_relaxed(qcom_qtmr_frame0_base + + QTMR_V1_CNTP_CVAL_LO); + hi2 = readl_relaxed(qcom_qtmr_frame0_base + + QTMR_V1_CNTP_CVAL_HI); + } while (hi1 != hi2); + + wakeup = min(wakeup, ((u64)hi2 << 32) | lo); + } + } + + if (wakeup < now + QCOM_MPM_MIN_DELTA_TICKS) + wakeup = now + QCOM_MPM_MIN_DELTA_TICKS; + + return wakeup; +} + +static int qcom_pm_collapse(unsigned long l2_off) +{ + if (l2_off) { + unsigned long flags; + struct spm_driver_data *l2_spm = spm_get_l2_device(); + + raw_spin_lock_irqsave(&qcom_spm_cluster_lock, flags); + if (!qcom_spm_cluster_sleeping || + !cpumask_subset(cpu_online_mask, &qcom_spm_idle_cpus)) { + qcom_spm_cluster_sleeping = false; + qcom_spm_cluster_l2_off = false; + spm_set_l2_mode(l2_spm, PM_SLEEP_MODE_STBY); + qcom_mpm_exit_sleep(); + raw_spin_unlock_irqrestore(&qcom_spm_cluster_lock, flags); + qcom_scm_cpu_power_down(QCOM_SCM_CPU_PWR_DOWN_L2_ON); + return -1; + } + l2_off_count++; + raw_spin_unlock_irqrestore(&qcom_spm_cluster_lock, flags); + + flush_cache_all(); + qcom_scm_cpu_power_down(QCOM_SCM_CPU_PWR_DOWN_L2_OFF); + } else { + qcom_scm_cpu_power_down(QCOM_SCM_CPU_PWR_DOWN_L2_ON); + } /* * Returns here only if there was a pending interrupt and we did not @@ -42,14 +140,70 @@ static int qcom_pm_collapse(unsigned long int unused) static int qcom_cpu_spc(struct spm_driver_data *drv) { + int cpu = smp_processor_id(); + struct spm_driver_data *l2_spm = NULL; + unsigned long flags; + bool cluster_rpm = false; + bool do_l2_off = false; + ktime_t sleep_len; int ret; - spm_set_low_power_mode(drv, PM_SLEEP_MODE_SPC); + raw_spin_lock_irqsave(&qcom_spm_cluster_lock, flags); + cpumask_set_cpu(cpu, &qcom_spm_idle_cpus); + + if (READ_ONCE(rpm_sleep) && READ_ONCE(screen_off) && + qcom_mpm_is_ready() && !qcom_spm_cluster_sleeping && + cpumask_subset(cpu_online_mask, &qcom_spm_idle_cpus) && + !qcom_msm8909_gdsc_is_active() && !nr_iowait()) { + sleep_len = ktime_sub(tick_nohz_get_next_hrtimer(), ktime_get()); + if (ktime_to_us(sleep_len) >= + READ_ONCE(rpm_min_residency_us)) { + l2_spm = READ_ONCE(l2_sleep) ? + spm_get_l2_device() : NULL; + if (!qcom_mpm_enter_sleep( + qcom_spm_next_wakeup_tick(sleep_len))) { + cluster_rpm = true; + qcom_spm_cluster_sleeping = true; + rpm_sleep_count++; + if (l2_spm) { + spm_set_l2_mode(l2_spm, + PM_SLEEP_MODE_PC); + spm_set_low_power_mode(drv, + PM_SLEEP_MODE_SPC); + qcom_spm_cluster_l2_off = true; + do_l2_off = true; + } else { + spm_set_low_power_mode(drv, + PM_SLEEP_MODE_SPC); + qcom_spm_cluster_l2_off = false; + } + } + } + } + + if (!cluster_rpm) + spm_set_low_power_mode(drv, PM_SLEEP_MODE_SPC); + raw_spin_unlock_irqrestore(&qcom_spm_cluster_lock, flags); + if (!IS_ENABLED(CONFIG_ARM64)) ct_cpuidle_enter(); - ret = cpu_suspend(0, qcom_pm_collapse); + ret = cpu_suspend(do_l2_off ? 1 : 0, qcom_pm_collapse); if (!IS_ENABLED(CONFIG_ARM64)) ct_cpuidle_exit(); + + raw_spin_lock_irqsave(&qcom_spm_cluster_lock, flags); + cpumask_clear_cpu(cpu, &qcom_spm_idle_cpus); + if (qcom_spm_cluster_sleeping) { + struct spm_driver_data *active_l2 = spm_get_l2_device(); + + qcom_spm_cluster_sleeping = false; + if (qcom_spm_cluster_l2_off && active_l2) + spm_set_l2_mode(active_l2, PM_SLEEP_MODE_STBY); + qcom_spm_cluster_l2_off = false; + qcom_mpm_exit_sleep(); + } + raw_spin_unlock_irqrestore(&qcom_spm_cluster_lock, flags); + /* * ARM common code executes WFI without calling into our driver and * if the SPM mode is not reset, then we may accidently power down the @@ -145,6 +299,9 @@ static int spm_cpuidle_drv_probe(struct platform_device *pdev) if (ret) return dev_err_probe(&pdev->dev, ret, "set warm boot addr failed"); + qcom_qtmr_frame0_base = ioremap(QCOM_MPM_TIMER_PHYS_BASE, + QCOM_MPM_TIMER_SIZE); + for_each_possible_cpu(cpu) { ret = spm_cpuidle_register(&pdev->dev, cpu); if (ret && ret != -ENODEV) { diff --git a/drivers/gpu/drm/msm/adreno/a3xx_gpu.c b/drivers/gpu/drm/msm/adreno/a3xx_gpu.c index 8dab9e6..43ac0e0 100644 --- a/drivers/gpu/drm/msm/adreno/a3xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a3xx_gpu.c @@ -623,13 +623,8 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev) } - /* - * Set the ICC path to maximum speed for now by multiplying the fastest - * frequency by the bus width (8). We'll want to scale this later on to - * improve battery life. - */ - icc_set_bw(icc_path, 0, Bps_to_icc(gpu->fast_rate) * 8); - icc_set_bw(ocmem_icc_path, 0, Bps_to_icc(gpu->fast_rate) * 8); + gpu->icc_path = icc_path; + gpu->ocmem_icc_path = ocmem_icc_path; return gpu; diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c index 465a4cd..af48bec 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c @@ -7,11 +7,14 @@ */ #include +#include #include #include #include #include +#include #include +#include #include #include #include @@ -616,11 +619,33 @@ void adreno_recover(struct msm_gpu *gpu) struct drm_device *dev = gpu->dev; int ret; - // XXX pm-runtime?? we *need* the device to be off after this - // so maybe continuing to call ->pm_suspend/resume() is better? + if (adreno_is_a304(to_adreno_gpu(gpu))) { + int active_submits; - gpu->funcs->pm_suspend(gpu); - gpu->funcs->pm_resume(gpu); + pm_runtime_dont_use_autosuspend(&gpu->pdev->dev); + + mutex_lock(&gpu->active_lock); + active_submits = gpu->active_submits; + gpu->active_submits = 0; + + dev_pm_genpd_synced_poweroff(&gpu->pdev->dev); + if (active_submits) + pm_runtime_put(&gpu->pdev->dev); + pm_runtime_put_sync(&gpu->pdev->dev); + + udelay(20); + + pm_runtime_use_autosuspend(&gpu->pdev->dev); + if (active_submits) + pm_runtime_get(&gpu->pdev->dev); + pm_runtime_get_sync(&gpu->pdev->dev); + + gpu->active_submits = active_submits; + mutex_unlock(&gpu->active_lock); + } else { + gpu->funcs->pm_suspend(gpu); + gpu->funcs->pm_resume(gpu); + } ret = msm_gpu_hw_init(gpu); if (ret) { diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index a274b84..4562eb0 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -16,6 +16,7 @@ #include #include #include +#include #include /* @@ -96,8 +97,17 @@ static int disable_axi(struct msm_gpu *gpu) return 0; } +static void msm_gpu_icc_set_bw(struct msm_gpu *gpu, u32 peak_bw) +{ + if (gpu->icc_path) + icc_set_bw(gpu->icc_path, 0, peak_bw); + if (gpu->ocmem_icc_path) + icc_set_bw(gpu->ocmem_icc_path, 0, peak_bw); +} + int msm_gpu_pm_resume(struct msm_gpu *gpu) { + u32 peak_bw = Bps_to_icc(gpu->fast_rate) * 8; int ret; DBG("%s", gpu->name); @@ -107,19 +117,28 @@ int msm_gpu_pm_resume(struct msm_gpu *gpu) if (ret) return ret; + msm_gpu_icc_set_bw(gpu, peak_bw); + ret = enable_clk(gpu); if (ret) - return ret; + goto err_icc; ret = enable_axi(gpu); - if (ret) - return ret; + if (ret) { + disable_clk(gpu); + goto err_icc; + } msm_devfreq_resume(gpu); gpu->needs_hw_init = true; return 0; + +err_icc: + msm_gpu_icc_set_bw(gpu, 0); + disable_pwrrail(gpu); + return ret; } int msm_gpu_pm_suspend(struct msm_gpu *gpu) @@ -139,6 +158,8 @@ int msm_gpu_pm_suspend(struct msm_gpu *gpu) if (ret) return ret; + msm_gpu_icc_set_bw(gpu, 0); + ret = disable_pwrrail(gpu); if (ret) return ret; diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h index 1f02bb9..9d48c7f 100644 --- a/drivers/gpu/drm/msm/msm_gpu.h +++ b/drivers/gpu/drm/msm/msm_gpu.h @@ -246,6 +246,7 @@ struct msm_gpu { struct clk_bulk_data *grp_clks; int nr_clocks; struct clk *ebi1_clk, *core_clk, *rbbmtimer_clk; + struct icc_path *icc_path, *ocmem_icc_path; uint32_t fast_rate; /* Hang and Inactivity Detection: diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index b98a7a5..9e2ace4 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -61,6 +61,12 @@ struct qcom_iommu_ctx { bool secured_ctx; u8 asid; /* asid and ctx bank # are 1:1 */ struct iommu_domain *domain; + u64 ttbr0; + u32 tcr; + u32 tcr2; + u32 mair0; + u32 mair1; + u32 sctlr; }; struct qcom_iommu_domain { @@ -277,22 +283,22 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, iommu_writel(ctx, ARM_SMMU_CB_FSR, ARM_SMMU_CB_FSR_FAULT); /* TTBRs */ - iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, - pgtbl_cfg.arm_lpae_s1_cfg.ttbr | - FIELD_PREP(ARM_SMMU_TTBRn_ASID, ctx->asid)); + ctx->ttbr0 = pgtbl_cfg.arm_lpae_s1_cfg.ttbr | + FIELD_PREP(ARM_SMMU_TTBRn_ASID, ctx->asid); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, ctx->ttbr0); iommu_writeq(ctx, ARM_SMMU_CB_TTBR1, 0); /* TCR */ - iommu_writel(ctx, ARM_SMMU_CB_TCR2, - arm_smmu_lpae_tcr2(&pgtbl_cfg)); - iommu_writel(ctx, ARM_SMMU_CB_TCR, - arm_smmu_lpae_tcr(&pgtbl_cfg) | ARM_SMMU_TCR_EAE); + ctx->tcr2 = arm_smmu_lpae_tcr2(&pgtbl_cfg); + ctx->tcr = arm_smmu_lpae_tcr(&pgtbl_cfg) | ARM_SMMU_TCR_EAE; + iommu_writel(ctx, ARM_SMMU_CB_TCR2, ctx->tcr2); + iommu_writel(ctx, ARM_SMMU_CB_TCR, ctx->tcr); /* MAIRs (stage-1 only) */ - iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR0, - pgtbl_cfg.arm_lpae_s1_cfg.mair); - iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR1, - pgtbl_cfg.arm_lpae_s1_cfg.mair >> 32); + ctx->mair0 = pgtbl_cfg.arm_lpae_s1_cfg.mair; + ctx->mair1 = pgtbl_cfg.arm_lpae_s1_cfg.mair >> 32; + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR0, ctx->mair0); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR1, ctx->mair1); /* SCTLR */ reg = ARM_SMMU_SCTLR_CFIE | ARM_SMMU_SCTLR_CFRE | @@ -303,6 +309,7 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) reg |= ARM_SMMU_SCTLR_E; + ctx->sctlr = reg; iommu_writel(ctx, ARM_SMMU_CB_SCTLR, reg); ctx->domain = domain; @@ -411,6 +418,7 @@ static int qcom_iommu_identity_attach(struct iommu_domain *identity_domain, /* Disable the context bank: */ iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + ctx->sctlr = 0; ctx->domain = NULL; } pm_runtime_put_sync(qcom_iommu->dev); @@ -434,13 +442,18 @@ static int qcom_iommu_map(struct iommu_domain *domain, unsigned long iova, unsigned long flags; struct qcom_iommu_domain *qcom_domain = to_qcom_iommu_domain(domain); struct io_pgtable_ops *ops = qcom_domain->pgtbl_ops; + bool rpm = gfpflags_allow_blocking(gfp) && qcom_domain->iommu; if (!ops) return -ENODEV; + if (rpm) + pm_runtime_get_sync(qcom_domain->iommu->dev); spin_lock_irqsave(&qcom_domain->pgtbl_lock, flags); ret = ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot, GFP_ATOMIC, mapped); spin_unlock_irqrestore(&qcom_domain->pgtbl_lock, flags); + if (rpm) + pm_runtime_put_sync(qcom_domain->iommu->dev); return ret; } @@ -888,19 +901,74 @@ static void qcom_iommu_device_remove(struct platform_device *pdev) iommu_device_unregister(&qcom_iommu->iommu); } +static void qcom_iommu_ctx_tlb_flush_atomic(struct qcom_iommu_ctx *ctx) +{ + unsigned int val; + + iommu_writel(ctx, ARM_SMMU_CB_S1_TLBIASID, ctx->asid); + iommu_writel(ctx, ARM_SMMU_CB_TLBSYNC, 0); + readl_poll_timeout_atomic(ctx->base + ARM_SMMU_CB_TLBSTATUS, val, + (val & 0x1) == 0, 0, 5000000); +} + static int __maybe_unused qcom_iommu_resume(struct device *dev) { struct qcom_iommu_dev *qcom_iommu = dev_get_drvdata(dev); + unsigned int i; int ret; ret = clk_bulk_prepare_enable(CLK_NUM, qcom_iommu->clks); if (ret < 0) return ret; - if (dev->pm_domain) - return qcom_scm_restore_sec_cfg(qcom_iommu->sec_id, 0); + if (qcom_iommu->local_base) + writel_relaxed(0xffffffff, + qcom_iommu->local_base + SMMU_INTR_SEL_NS); - return ret; + if (dev->pm_domain) { + ret = qcom_scm_restore_sec_cfg(qcom_iommu->sec_id, 0); + if (ret) { + clk_bulk_disable_unprepare(CLK_NUM, qcom_iommu->clks); + return ret; + } + } + + for (i = 0; i <= qcom_iommu->max_asid; i++) { + struct qcom_iommu_ctx *ctx = qcom_iommu->ctxs[i]; + + if (!ctx || !ctx->domain || ctx->secured_ctx || !ctx->sctlr) + continue; + + if (!dev->pm_domain && + (iommu_readl(ctx, ARM_SMMU_CB_SCTLR) & ARM_SMMU_SCTLR_M)) { + qcom_iommu_ctx_tlb_flush_atomic(ctx); + continue; + } + + if (!dev->pm_domain && ctx->secure_init) { + ret = qcom_scm_restore_sec_cfg(qcom_iommu->sec_id, + ctx->asid); + if (ret) { + clk_bulk_disable_unprepare(CLK_NUM, + qcom_iommu->clks); + return ret; + } + } + + iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + iommu_writel(ctx, ARM_SMMU_CB_FAR, 0); + iommu_writel(ctx, ARM_SMMU_CB_FSR, ARM_SMMU_CB_FSR_FAULT); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, ctx->ttbr0); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR1, 0); + iommu_writel(ctx, ARM_SMMU_CB_TCR2, ctx->tcr2); + iommu_writel(ctx, ARM_SMMU_CB_TCR, ctx->tcr); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR0, ctx->mair0); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR1, ctx->mair1); + iommu_writel(ctx, ARM_SMMU_CB_SCTLR, ctx->sctlr); + qcom_iommu_ctx_tlb_flush_atomic(ctx); + } + + return 0; } static int __maybe_unused qcom_iommu_suspend(struct device *dev) diff --git a/drivers/irqchip/irq-qcom-mpm.c b/drivers/irqchip/irq-qcom-mpm.c index 7942d8e..1141ee0 100644 --- a/drivers/irqchip/irq-qcom-mpm.c +++ b/drivers/irqchip/irq-qcom-mpm.c @@ -21,6 +21,7 @@ #include #include #include +#include /* * This is the driver for Qualcomm MPM (MSM Power Manager) interrupt controller, @@ -277,8 +278,12 @@ static irqreturn_t qcom_mpm_handler(int irq, void *dev_id) for_each_set_bit(j, &pending, 32) { unsigned int pin = 32 * i + j; struct irq_desc *desc = irq_resolve_mapping(priv->domain, pin); - struct irq_data *d = &desc->irq_data; + struct irq_data *d; + if (!desc) + continue; + + d = &desc->irq_data; if (!irqd_is_level_type(d)) irq_set_irqchip_state(d->irq, IRQCHIP_STATE_PENDING, true); @@ -289,6 +294,57 @@ static irqreturn_t qcom_mpm_handler(int irq, void *dev_id) return ret; } +static struct qcom_mpm_priv *qcom_mpm_dev; + +bool qcom_mpm_is_ready(void) +{ + return READ_ONCE(qcom_mpm_dev) != NULL; +} + +int qcom_mpm_enter_sleep(u64 wakeup_tick) +{ + struct qcom_mpm_priv *priv = READ_ONCE(qcom_mpm_dev); + unsigned long flags; + int i, ret; + + if (!priv) + return -ENODEV; + + raw_spin_lock_irqsave(&priv->lock, flags); + for (i = 0; i < priv->reg_stride; i++) + qcom_mpm_write(priv, MPM_REG_STATUS, i, 0); + writel_relaxed(lower_32_bits(wakeup_tick), priv->base + 0x00); + writel_relaxed(upper_32_bits(wakeup_tick), priv->base + 0x04); + wmb(); + raw_spin_unlock_irqrestore(&priv->lock, flags); + + ret = mbox_send_message(priv->mbox_chan, NULL); + return ret < 0 ? ret : 0; +} + +void qcom_mpm_exit_sleep(void) +{ + struct qcom_mpm_priv *priv = READ_ONCE(qcom_mpm_dev); + unsigned long flags; + int i; + + if (!priv) + return; + + raw_spin_lock_irqsave(&priv->lock, flags); + writel_relaxed(~0U, priv->base + 0x00); + writel_relaxed(~0U, priv->base + 0x04); + wmb(); + raw_spin_unlock_irqrestore(&priv->lock, flags); + + qcom_mpm_handler(0, priv); + + raw_spin_lock_irqsave(&priv->lock, flags); + for (i = 0; i < priv->reg_stride; i++) + qcom_mpm_write(priv, MPM_REG_STATUS, i, 0); + raw_spin_unlock_irqrestore(&priv->lock, flags); +} + static int mpm_pd_power_off(struct generic_pm_domain *genpd) { struct qcom_mpm_priv *priv = container_of(genpd, struct qcom_mpm_priv, @@ -463,6 +519,21 @@ static int qcom_mpm_init(struct device_node *np, struct device_node *parent) goto remove_domain; } + /* + * Pre-enable SPMI/PMIC wakeup (pin 62, level-high) and USB HS async + * wakeup (pins 49 & 58, rising + high) in vMPM. + */ + if (priv->reg_stride >= 2) { + qcom_mpm_write(priv, MPM_REG_RISING_EDGE, 1, + BIT(17) | BIT(26)); + qcom_mpm_write(priv, MPM_REG_POLARITY, 1, + BIT(17) | BIT(26) | BIT(30)); + qcom_mpm_write(priv, MPM_REG_ENABLE, 1, + BIT(17) | BIT(26) | BIT(30)); + } + + WRITE_ONCE(qcom_mpm_dev, priv); + return 0; remove_domain: diff --git a/drivers/regulator/qcom_smd-regulator.c b/drivers/regulator/qcom_smd-regulator.c index 28e7ce6..83bd819 100644 --- a/drivers/regulator/qcom_smd-regulator.c +++ b/drivers/regulator/qcom_smd-regulator.c @@ -1421,6 +1421,18 @@ static int rpm_regulator_init_vreg(struct qcom_rpm_reg *vreg, struct device *dev config.of_node = node; config.driver_data = vreg; + /* + * SBL1/aboot can leave auxiliary LDOs (touch/sensor/cam-IO) enabled + * in hardware before handing off to Linux. Seed is_enabled = 1 for + * unclaimed PM8909 auxiliary rails so regulator_late_cleanup() can + * send RPM_KEY_SWEN = 0 when no consumer claims them. + */ + if (pmic_rpm_data == rpm_pm8909_regulators && + (!strcmp(rpm_data->name, "l14") || + !strcmp(rpm_data->name, "l15") || + !strcmp(rpm_data->name, "l18"))) + vreg->is_enabled = 1; + rdev = devm_regulator_register(dev, &vreg->desc, &config); if (IS_ERR(rdev)) { ret = PTR_ERR(rdev); diff --git a/drivers/soc/qcom/spm.c b/drivers/soc/qcom/spm.c index f75659f..6ed8e51 100644 --- a/drivers/soc/qcom/spm.c +++ b/drivers/soc/qcom/spm.c @@ -27,8 +27,12 @@ (((current) & ~(mask)) | FIELD_PREP((mask), (val))) #define SPM_CTL_INDEX 0x7f +#define SPM_CTL_INDEX_V3 0x1ff #define SPM_CTL_INDEX_SHIFT 4 #define SPM_CTL_EN BIT(0) +#define SPM_CTL_RET_MODE BIT(15) +#define SPM_CTL_PC_MODE BIT(16) +#define SPM_CTL_SLP_CMD_MODE BIT(17) /* These registers might be specific to SPM 1.1 */ #define SPM_VCTL_VLVL GENMASK(7, 0) @@ -47,6 +51,8 @@ enum spm_reg { SPM_REG_PMIC_DLY, SPM_REG_PMIC_DATA_0, SPM_REG_PMIC_DATA_1, + SPM_REG_PMIC_DATA_4, + SPM_REG_PMIC_DATA_5, SPM_REG_VCTL, SPM_REG_SEQ_ENTRY, SPM_REG_STS0, @@ -67,6 +73,8 @@ struct spm_reg_data { u32 spm_dly; u32 pmic_dly; u32 pmic_data[MAX_PMIC_DATA]; + u32 pmic_data4; + u32 pmic_data5; u32 avs_ctl; u32 avs_limit; u8 seq[MAX_SEQ_DATA]; @@ -120,6 +128,10 @@ static const u16 spm_reg_offset_v3_0[SPM_REG_NR] = { [SPM_REG_CFG] = 0x08, [SPM_REG_SPM_CTL] = 0x30, [SPM_REG_DLY] = 0x34, + [SPM_REG_PMIC_DATA_0] = 0x40, + [SPM_REG_PMIC_DATA_1] = 0x44, + [SPM_REG_PMIC_DATA_4] = 0x50, + [SPM_REG_PMIC_DATA_5] = 0x54, [SPM_REG_SEQ_ENTRY] = 0x400, }; @@ -129,10 +141,34 @@ static const struct spm_reg_data spm_reg_8909_cpu = { .spm_cfg = 0x1, .spm_dly = 0x3C102800, .seq = { 0x60, 0x03, 0x60, 0x0B, 0x0F, 0x20, 0x10, 0x80, 0x30, 0x90, - 0x5B, 0x60, 0x03, 0x60, 0x76, 0x76, 0x0B, 0x94, 0x5B, 0x80, - 0x10, 0x26, 0x30, 0x0F }, + 0x5B, 0x60, 0x03, 0x60, 0x3B, 0x76, 0x76, 0x0B, 0x94, 0x5B, + 0x80, 0x10, 0x26, 0x30, 0x0F }, .start_index[PM_SLEEP_MODE_STBY] = 0, .start_index[PM_SLEEP_MODE_SPC] = 5, + .start_index[PM_SLEEP_MODE_PC] = 5, +}; + +/* L2 SAW2 register data for 8909 (from msm8909-pm8916-pm.dtsi) */ +static const struct spm_reg_data spm_reg_8909_l2 = { + .reg_offset = spm_reg_offset_v3_0, + .spm_cfg = 0x14, + .spm_dly = 0x3C102800, + .pmic_data[0] = 0x05030080, + .pmic_data[1] = 0x00030000, + .pmic_data4 = 0x00010080, + .pmic_data5 = 0x00010000, + .seq = { + 0x00, 0x03, 0x00, 0x0F, + 0x00, 0x20, 0x32, 0x6B, 0xC0, 0xE0, 0xD0, 0x42, 0x03, 0x50, + 0x4E, 0x02, 0x02, 0xD0, 0xE0, 0xC0, 0x22, 0x6B, 0x02, 0x32, + 0x50, 0x0F, + 0x00, 0x32, 0xB0, 0x10, 0xE0, 0xD0, 0x6B, 0xC0, 0x42, 0xF0, + 0x51, 0x11, 0x07, 0x01, 0x41, 0xB0, 0x50, 0x4E, 0x02, 0x02, + 0xC0, 0xD0, 0x12, 0xE0, 0x6B, 0x02, 0x32, 0x50, 0xF0, 0x0F + }, + .start_index[PM_SLEEP_MODE_STBY] = 0, + .start_index[PM_SLEEP_MODE_SPC] = 4, + .start_index[PM_SLEEP_MODE_PC] = 26, }; /* SPM register data for 8916 */ @@ -287,6 +323,8 @@ static inline u32 spm_register_read(struct spm_driver_data *drv, return readl_relaxed(drv->reg_base + drv->reg_data->reg_offset[reg]); } +static struct spm_driver_data *qcom_l2_spm_drv; + void spm_set_low_power_mode(struct spm_driver_data *drv, enum pm_sleep_mode mode) { @@ -296,12 +334,51 @@ void spm_set_low_power_mode(struct spm_driver_data *drv, start_index = drv->reg_data->start_index[mode]; ctl_val = spm_register_read(drv, SPM_REG_SPM_CTL); - ctl_val &= ~(SPM_CTL_INDEX << SPM_CTL_INDEX_SHIFT); - ctl_val |= start_index << SPM_CTL_INDEX_SHIFT; + if (drv->reg_data->reg_offset == spm_reg_offset_v3_0) { + ctl_val &= ~((SPM_CTL_INDEX_V3 << SPM_CTL_INDEX_SHIFT) | + SPM_CTL_RET_MODE | SPM_CTL_PC_MODE | + SPM_CTL_SLP_CMD_MODE); + ctl_val |= (start_index & SPM_CTL_INDEX_V3) << SPM_CTL_INDEX_SHIFT; + if (mode == PM_SLEEP_MODE_SPC) + ctl_val |= SPM_CTL_PC_MODE; + else if (mode == PM_SLEEP_MODE_PC) + ctl_val |= SPM_CTL_PC_MODE | SPM_CTL_SLP_CMD_MODE; + } else { + ctl_val &= ~(SPM_CTL_INDEX << SPM_CTL_INDEX_SHIFT); + ctl_val |= start_index << SPM_CTL_INDEX_SHIFT; + } ctl_val |= SPM_CTL_EN; spm_register_write_sync(drv, SPM_REG_SPM_CTL, ctl_val); } +struct spm_driver_data *spm_get_l2_device(void) +{ + return READ_ONCE(qcom_l2_spm_drv); +} + +void spm_set_l2_mode(struct spm_driver_data *drv, enum pm_sleep_mode mode) +{ + u32 ctl_val; + + if (!drv) + return; + + if (mode == PM_SLEEP_MODE_PC) { + u32 start_index = drv->reg_data->start_index[PM_SLEEP_MODE_PC]; + + /* + * Match downstream skip_l2_spm: enable PC_MODE at pc seq offset + * and let TZ set SLP_CMD_MODE after L2 flush in SCM terminate. + */ + ctl_val = 0x0e | SPM_CTL_EN | SPM_CTL_PC_MODE | + ((start_index & SPM_CTL_INDEX_V3) << SPM_CTL_INDEX_SHIFT); + } else { + ctl_val = 0; + } + + spm_register_write_sync(drv, SPM_REG_SPM_CTL, ctl_val); +} + static int spm_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector) { struct spm_driver_data *drv = rdev_get_drvdata(rdev); @@ -483,6 +560,8 @@ static const struct of_device_id spm_match_table[] = { .data = &spm_reg_8226_cpu }, { .compatible = "qcom,msm8909-saw2-v3.0-cpu", .data = &spm_reg_8909_cpu }, + { .compatible = "qcom,msm8909-saw2-v3.0-scu", + .data = &spm_reg_8909_l2 }, { .compatible = "qcom,msm8916-saw2-v3.0-cpu", .data = &spm_reg_8916_cpu }, { .compatible = "qcom,msm8939-saw2-v3.0-cpu", @@ -547,10 +626,23 @@ static int spm_dev_probe(struct platform_device *pdev) drv->reg_data->pmic_data[0]); spm_register_write(drv, SPM_REG_PMIC_DATA_1, drv->reg_data->pmic_data[1]); + spm_register_write(drv, SPM_REG_PMIC_DATA_4, + drv->reg_data->pmic_data4); + spm_register_write(drv, SPM_REG_PMIC_DATA_5, + drv->reg_data->pmic_data5); /* Set up Standby as the default low power mode */ - if (drv->reg_data->reg_offset[SPM_REG_SPM_CTL]) + if (drv->reg_data == &spm_reg_8909_l2) { + spm_register_write_sync(drv, SPM_REG_SPM_CTL, 0); + if (spm_register_read(drv, SPM_REG_CFG) == drv->reg_data->spm_cfg) + WRITE_ONCE(qcom_l2_spm_drv, drv); + else + dev_warn(&pdev->dev, "L2 SAW2 XPU-locked, L2 off skipped\n"); + } else if (drv->reg_data->reg_offset[SPM_REG_SPM_CTL]) { + if (drv->reg_data->reg_offset == spm_reg_offset_v3_0) + spm_register_write_sync(drv, SPM_REG_SPM_CTL, 0x0e); spm_set_low_power_mode(drv, PM_SLEEP_MODE_STBY); + } if (IS_ENABLED(CONFIG_REGULATOR)) return spm_register_regulator(&pdev->dev, drv); diff --git a/include/soc/qcom/spm.h b/include/soc/qcom/spm.h index 5b263c6..ffe192e 100644 --- a/include/soc/qcom/spm.h +++ b/include/soc/qcom/spm.h @@ -18,5 +18,12 @@ enum pm_sleep_mode { struct spm_driver_data; void spm_set_low_power_mode(struct spm_driver_data *drv, enum pm_sleep_mode mode); +struct spm_driver_data *spm_get_l2_device(void); +void spm_set_l2_mode(struct spm_driver_data *drv, enum pm_sleep_mode mode); + +bool qcom_mpm_is_ready(void); +int qcom_mpm_enter_sleep(u64 wakeup_tick); +void qcom_mpm_exit_sleep(void); +bool qcom_msm8909_gdsc_is_active(void); #endif /* __SPM_H__ */ diff --git a/sound/soc/codecs/msm8916-wcd-digital.c b/sound/soc/codecs/msm8916-wcd-digital.c index ebb6f2e..81d1134 100644 --- a/sound/soc/codecs/msm8916-wcd-digital.c +++ b/sound/soc/codecs/msm8916-wcd-digital.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -226,6 +227,7 @@ struct wcd_iir_filter_ctl { struct msm8916_wcd_digital_priv { struct clk *ahbclk, *mclk; + struct regmap *regmap; }; static const unsigned long rx_gain_reg[] = { @@ -1152,7 +1154,7 @@ static const struct snd_soc_component_driver msm8916_wcd_digital = { .num_dapm_widgets = ARRAY_SIZE(msm8916_wcd_digital_dapm_widgets), .dapm_routes = msm8916_wcd_digital_audio_map, .num_dapm_routes = ARRAY_SIZE(msm8916_wcd_digital_audio_map), - .idle_bias_on = 1, + .idle_bias_on = 0, .use_pmdown_time = 1, .endianness = 1, }; @@ -1165,12 +1167,49 @@ static const struct regmap_config msm8916_codec_regmap_config = { .cache_type = REGCACHE_FLAT, }; +static int msm8916_wcd_digital_runtime_suspend(struct device *dev) +{ + struct msm8916_wcd_digital_priv *priv = dev_get_drvdata(dev); + + regcache_cache_only(priv->regmap, true); + regcache_mark_dirty(priv->regmap); + clk_disable_unprepare(priv->mclk); + clk_disable_unprepare(priv->ahbclk); + + return 0; +} + +static int msm8916_wcd_digital_runtime_resume(struct device *dev) +{ + struct msm8916_wcd_digital_priv *priv = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(priv->ahbclk); + if (ret < 0) + return ret; + + ret = clk_prepare_enable(priv->mclk); + if (ret < 0) { + clk_disable_unprepare(priv->ahbclk); + return ret; + } + + regcache_cache_only(priv->regmap, false); + return regcache_sync(priv->regmap); +} + +static const struct dev_pm_ops msm8916_wcd_digital_pm_ops = { + SET_RUNTIME_PM_OPS(msm8916_wcd_digital_runtime_suspend, + msm8916_wcd_digital_runtime_resume, NULL) +}; + static int msm8916_wcd_digital_probe(struct platform_device *pdev) { struct msm8916_wcd_digital_priv *priv; struct device *dev = &pdev->dev; void __iomem *base; struct regmap *digital_map; + unsigned int reg, val; int ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); @@ -1187,6 +1226,8 @@ static int msm8916_wcd_digital_probe(struct platform_device *pdev) if (IS_ERR(digital_map)) return PTR_ERR(digital_map); + priv->regmap = digital_map; + ret = msm8916_wcd_digital_get_clks(pdev, priv); if (ret < 0) return ret; @@ -1203,13 +1244,29 @@ static int msm8916_wcd_digital_probe(struct platform_device *pdev) goto err_clk; } + for (reg = 0; reg <= LPASS_CDC_TX2_DMIC_CTL; reg += 4) + regmap_read(digital_map, reg, &val); + dev_set_drvdata(dev, priv); + pm_runtime_set_autosuspend_delay(dev, 200); + pm_runtime_use_autosuspend(dev); + pm_runtime_get_noresume(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + ret = devm_snd_soc_register_component(dev, &msm8916_wcd_digital, msm8916_wcd_digital_dai, ARRAY_SIZE(msm8916_wcd_digital_dai)); - if (ret) + if (ret) { + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + pm_runtime_set_suspended(dev); goto err_mclk; + } + + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); return 0; @@ -1224,8 +1281,12 @@ static void msm8916_wcd_digital_remove(struct platform_device *pdev) { struct msm8916_wcd_digital_priv *priv = dev_get_drvdata(&pdev->dev); - clk_disable_unprepare(priv->mclk); - clk_disable_unprepare(priv->ahbclk); + pm_runtime_disable(&pdev->dev); + if (!pm_runtime_status_suspended(&pdev->dev)) { + clk_disable_unprepare(priv->mclk); + clk_disable_unprepare(priv->ahbclk); + } + pm_runtime_set_suspended(&pdev->dev); } static const struct of_device_id msm8916_wcd_digital_match_table[] = { @@ -1238,6 +1299,7 @@ MODULE_DEVICE_TABLE(of, msm8916_wcd_digital_match_table); static struct platform_driver msm8916_wcd_digital_driver = { .driver = { .name = "msm8916-wcd-digital-codec", + .pm = pm_ptr(&msm8916_wcd_digital_pm_ops), .of_match_table = msm8916_wcd_digital_match_table, }, .probe = msm8916_wcd_digital_probe,