Files
geminux/patches/kernel/0008-gemini-resume-wake-and-spm-standby.patch
T

823 lines
31 KiB
Diff
Raw Normal View History

From: Geminux Project <dev@geminux.local>
Subject: [PATCH] geminux: fix SSD2092 wake, MT6351 fuel-gauge accuracy, and SPM standby
- Ensure mtk_dsi holds WAKEUP_EN >= 1 ms on ULPS exit, stays in LP mode
through LPM panel init before enabling HS clock for video mode, skips
redundant 500 ms VM_DONE waits when already in CMD_MODE, and avoids
restarting video mode while dsi->enabled is false.
- Send the vendor Solomon SSD2092 register initialization sequence on
adopted wake when waking from sleep, and match the 50 ms display-on settle.
- Defer Solomon SSD2092 touch resume (.complete + 60 ms) until after DRM
wakes the display, using vendor DS_CUP_CONTROL (0x0002) LPM wake retries
without pulsing shared TDDI reset GPIO68 while display is active.
- Reject stale MT6351 AUXADC_ADC21 start-up OCV across warm reboots/reflashes,
scale reported capacity properly across [empty_pct .. full], and refresh
empty/untrusted anchors when userspace restores learned_resistance_uohm.
- Enable mt6797-spm-sleep hardware suspend loop, power down unlit AW9120 LEDs
during suspend, and clear INFRA_AO_MD_SRCCLKENA when CCCI MD1 stays gated.
---
diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
--- a/drivers/gpu/drm/mediatek/mtk_dsi.c
+++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
@@ -6,6 +6,7 @@
#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/component.h>
+#include <linux/delay.h>
#include <linux/iopoll.h>
#include <linux/irq.h>
#include <linux/of.h>
@@ -347,6 +348,7 @@
{
mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_ULPM_EN, 0);
mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_WAKEUP_EN, LC_WAKEUP_EN);
+ usleep_range(1000, 1200);
mtk_dsi_mask(dsi, DSI_PHY_LCCON, LC_WAKEUP_EN, 0);
}
@@ -360,6 +362,7 @@
{
mtk_dsi_mask(dsi, DSI_PHY_LD0CON, LD0_ULPM_EN, 0);
mtk_dsi_mask(dsi, DSI_PHY_LD0CON, LD0_WAKEUP_EN, LD0_WAKEUP_EN);
+ usleep_range(1000, 1200);
mtk_dsi_mask(dsi, DSI_PHY_LD0CON, LD0_WAKEUP_EN, 0);
}
@@ -838,7 +841,6 @@
mtk_dsi_config_vdo_timing(dsi);
mtk_dsi_set_interrupt_enable(dsi);
mtk_dsi_lane_ready(dsi);
- mtk_dsi_clk_hs_mode(dsi, 1);
writel(0, dsi->regs + DSI_INTSTA);
enable_irq(dsi->irq);
@@ -869,7 +871,8 @@
*/
mtk_dsi_stop(dsi);
- mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500);
+ if ((readl(dsi->regs + DSI_MODE_CTRL) & MODE) != CMD_MODE)
+ mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500);
mtk_dsi_reset_engine(dsi);
mtk_dsi_lane0_ulp_mode_enter(dsi);
mtk_dsi_clk_ulp_mode_enter(dsi);
@@ -892,6 +895,10 @@
if (dsi->enabled)
return;
+ if (!mtk_dsi_clk_hs_state(dsi)) {
+ mtk_dsi_clk_hs_mode(dsi, 1);
+ usleep_range(200, 300);
+ }
mtk_dsi_set_mode(dsi);
mtk_dsi_start(dsi);
@@ -957,7 +964,8 @@
drm_err(drm, "failed to power on dsi\n");
mtk_dsi_lane_ready(dsi);
- mtk_dsi_clk_hs_mode(dsi, 1);
+ if (!(dsi->mode_flags & MIPI_DSI_MODE_LPM))
+ mtk_dsi_clk_hs_mode(dsi, 1);
}
static void mtk_dsi_bridge_atomic_post_disable(struct drm_bridge *bridge,
@@ -1210,15 +1218,32 @@
static ssize_t mtk_dsi_host_send_cmd(struct mtk_dsi *dsi,
const struct mipi_dsi_msg *msg, u8 flag)
{
+ bool restore_hs_clk = false;
+ ssize_t ret = 0;
+
+ if ((msg->flags & MIPI_DSI_MSG_USE_LPM) && mtk_dsi_clk_hs_state(dsi)) {
+ mtk_dsi_clk_hs_mode(dsi, false);
+ usleep_range(200, 300);
+ restore_hs_clk = true;
+ } else if (!(msg->flags & MIPI_DSI_MSG_USE_LPM) && !mtk_dsi_clk_hs_state(dsi)) {
+ mtk_dsi_clk_hs_mode(dsi, true);
+ usleep_range(200, 300);
+ }
+
mtk_dsi_wait_for_idle(dsi);
mtk_dsi_irq_data_clear(dsi, flag);
mtk_dsi_cmdq(dsi, msg);
mtk_dsi_start(dsi);
if (!mtk_dsi_wait_for_irq_done(dsi, flag, 2000))
- return -ETIME;
- else
- return 0;
+ ret = -ETIME;
+
+ if (restore_hs_clk) {
+ usleep_range(200, 300);
+ mtk_dsi_clk_hs_mode(dsi, true);
+ }
+
+ return ret;
}
static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
@@ -1284,7 +1309,7 @@
recv_cnt, *((u8 *)(msg->tx_buf)));
restore_dsi_mode:
- if (dsi_mode & MODE) {
+ if ((dsi_mode & MODE) && dsi->enabled) {
mtk_dsi_set_mode(dsi);
mtk_dsi_start(dsi);
}
diff --git a/drivers/gpu/drm/panel/panel-novatek-nt36672e.c b/drivers/gpu/drm/panel/panel-novatek-nt36672e.c
--- a/drivers/gpu/drm/panel/panel-novatek-nt36672e.c
+++ b/drivers/gpu/drm/panel/panel-novatek-nt36672e.c
@@ -790,6 +790,194 @@
* survives this module: on the loader's first frame it is awake, and nothing is
* sent.
*/
+static void ssd2092_gemini_1080x2160_init(struct mipi_dsi_multi_context *ctx)
+{
+ mipi_dsi_dcs_set_display_off_multi(ctx);
+ mipi_dsi_dcs_enter_sleep_mode_multi(ctx);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb5, 0x00, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x03, 0x96 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb4, 0x21, 0xff }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xe1, 0x00, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xe1, 0x03, 0x00, 0x10 }, 4);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x04, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x07, 0x14 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc6, 0x04, 0x2d }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x0e, 0x44 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc1, 0x0c, 0x26 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc1, 0x08, 0x99 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x23, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc2, 0x04, 0x0f }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x11, 0x22 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x12, 0x22 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x13, 0x22 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x19, 0x0b }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x3d, 0xc8 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x0f, 0x20 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0x36, 0x02 }, 2);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc7, 0x01, 0x09 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x15, 0x80 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x1e, 0x02 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x14, 0xc0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x16, 0x50 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x1c, 0xe4 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x28, 0x09 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x24, 0x19 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x12, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x13, 0x14 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x1a, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x1b, 0x14 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc1, 0x0d, 0x87 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc1, 0x0e, 0x87 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc3, 0x00, 0x10, 0x2e, 0x3e, 0x48, 0x5e, 0x6b, 0x7a, 0x83, 0x97, 0xa3, 0xa8, 0xa5, 0xac, 0xad, 0xb5, 0xc1, 0xc4, 0x4e, 0x4f, 0x59, 0x5a }, 23);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc3, 0x15, 0x10, 0x2e, 0x3e, 0x48, 0x5e, 0x6b, 0x7a, 0x83, 0x97, 0xa3, 0xa8, 0xa5, 0xac, 0xad, 0xb5, 0xc1, 0xc4, 0x4e, 0x4f, 0x59, 0x5a }, 23);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x01, 0x8a }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x02, 0x23 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x03, 0xbc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x04, 0xc0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x05, 0x19 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x06, 0x37 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x07, 0xee }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x08, 0xdd }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x09, 0xcc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x0a, 0x36 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x0b, 0x70 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x0c, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x0d, 0x8a }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x0e, 0x23 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x0f, 0xbc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x10, 0xc0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x11, 0x18 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x12, 0xa7 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x13, 0xee }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x14, 0xdd }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x15, 0xcc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x16, 0x36 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x17, 0x70 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x18, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x31, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x00, 0xf0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x01, 0xf0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x02, 0xf0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x03, 0xf0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x1a, 0x02 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x1b, 0x24 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x1d, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x1e, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x21, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x1f, 0x79 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x20, 0x14 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x22, 0x89 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x23, 0x13 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x24, 0x35 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x26, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x27, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x2a, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x28, 0x79 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x29, 0x14 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x2b, 0x89 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x2c, 0x33 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x2d, 0x33 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x2e, 0x11 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x2f, 0x11 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x31, 0x22 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x32, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x33, 0x04 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x34, 0x11 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x35, 0x11 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x37, 0x22 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x38, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x39, 0x04 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x3a, 0x1e }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x3b, 0x1e }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x3c, 0x1e }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x3d, 0x1e }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x40, 0xaa }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x42, 0x1e }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x43, 0x1e }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x44, 0x1e }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x45, 0x1e }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x48, 0xaa }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x02, 0x05 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x03, 0x01 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbc, 0x1e, 0x71 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbc, 0x24, 0x83 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb8, 0x03, 0xa9 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x15, 0x41 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x19, 0x8a }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x1a, 0x32 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x1b, 0xbc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x1c, 0xc2 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x1d, 0x39 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x1e, 0x37 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x1f, 0xee }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x20, 0xdd }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x21, 0xcc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x22, 0x36 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x23, 0x70 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x24, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x25, 0x8a }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x26, 0x32 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x27, 0xbc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x28, 0xc2 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x29, 0x38 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x2a, 0xa7 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x2b, 0xee }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x2c, 0xdd }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x2d, 0xcc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x2e, 0x36 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x2f, 0x70 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbb, 0x30, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb8, 0x15, 0xa2 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x39, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc6, 0x00, 0x03, 0x40 }, 4);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x18, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x17, 0x28 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x23, 0x15 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x06, 0x2c }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x17, 0x28 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x23, 0x15 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x16, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x28, 0x02, 0x02 }, 4);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x0f, 0x8c }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x10, 0x0c }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x11, 0x23 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x12, 0x9d, 0x9d, 0x9d }, 5);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x25, 0x22 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x0d, 0x40, 0x02 }, 4);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x2f, 0x8c }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc2, 0x04, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc2, 0x05, 0xc0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 11);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x15, 0x33 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x00, 0x5f, 0x5f, 0x61, 0x0a }, 6);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x08, 0x07 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x09, 0x07 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbc, 0x03, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbc, 0x04, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbc, 0x05, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbc, 0x07, 0x10 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbc, 0x08, 0x10 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbc, 0x09, 0x10 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x11, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x12, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x13, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x1d, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x1e, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x1f, 0x00 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc2, 0x00, 0x07 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc1, 0x0b, 0x1f }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb1, 0x05, 0x2f }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0x35, 0x00 }, 2);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb0, 0x01, 0x08, 0x70 }, 4);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb9, 0x25, 0xa0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xba, 0x2f, 0xcc }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xc1, 0x02, 0xb0 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x1c, 0xc4 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xb3, 0x1d, 0x80 }, 3);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0xbd, 0x11, 0x02, 0x22 }, 4);
+ nt36672e_gemini_write_cmd(ctx, (const u8[]){ 0x36, 0x09 }, 2);
+}
+
static bool gemini_prop_has_ssd2092(const void *prop, int len)
{
int i;
@@ -840,6 +1028,8 @@
if (ctx->awake)
return 0;
dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+ if (ctx->desc->init_sequence)
+ ctx->desc->init_sequence(&mctx);
mipi_dsi_dcs_exit_sleep_mode_multi(&mctx);
mipi_dsi_msleep(&mctx, ctx->desc->exit_sleep_delay_ms);
mipi_dsi_dcs_set_display_on_multi(&mctx);
@@ -1028,6 +1218,7 @@
.format = MIPI_DSI_FMT_RGB888,
.lanes = 4,
.panel_name = "Gemini SSD2092 1080x2160 panel",
+ .init_sequence = ssd2092_gemini_1080x2160_init,
.can_adopt = true,
.no_dcs_read = true,
.power_on_delay_ms = 20,
@@ -1037,7 +1228,7 @@
.display_off_delay_ms = 50,
.sleep_in_delay_ms = 120,
.exit_sleep_delay_ms = 120,
- .display_on_delay_ms = 20,
+ .display_on_delay_ms = 50,
};
static int nt36672e_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector)
diff --git a/drivers/input/touchscreen/novatek-nt36xxx.c b/drivers/input/touchscreen/novatek-nt36xxx.c
--- a/drivers/input/touchscreen/novatek-nt36xxx.c
+++ b/drivers/input/touchscreen/novatek-nt36xxx.c
@@ -28,11 +28,13 @@
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
+#include <linux/workqueue.h>
#include <linux/unaligned.h>
#define NVT36XXX_HW_ADDR 0x62
#define SSD2092_I2C_ADDR 0x53
+#define SSD2092_DS_CUP_CONTROL 0x0002
#define SSD2092_X_MAX 1080
#define SSD2092_Y_MAX 2160
#define NVT36XXX_FW_ADDR 0x01
@@ -75,7 +77,11 @@
u32 orig_irq_type;
u8 fw_version;
u16 pid;
+ u16 last_fw_touch;
+ u16 last_fw_disp;
bool is_ssd2092;
+ bool irq_disabled;
+ struct delayed_work resume_work;
};
static int nvt36xxx_write(struct nvt36xxx_data *data, u16 target,
@@ -562,6 +568,9 @@
int ret = -EIO;
int i;
+ data->last_fw_touch = 0;
+ data->last_fw_disp = 0;
+
for (i = 0; i < 6; i++) {
ret = ssd2092_write_u16(data->ssl, 0x0050, 0x0000);
if (!ret)
@@ -580,6 +589,8 @@
if (!ssd2092_read(data->ssl, 0x0057, buf, sizeof(buf)))
y_nodes = get_unaligned_le16(buf);
+ data->last_fw_touch = fw_touch;
+ data->last_fw_disp = fw_disp;
data->raw_x_max = SSD2092_X_MAX;
data->raw_y_max = SSD2092_Y_MAX;
dev_info(dev, "SSD2092 FW touch=%#06x disp=%#06x nodes=%ux%u\n",
@@ -724,6 +735,68 @@
irq_set_irq_type(data->client->irq, data->orig_irq_type);
}
+/*
+ * Vendor lpm_end2 sequence: wake the SSD2092 TDDI DS16 MCU via
+ * DS_CUP_CONTROL (0x0002) twice without toggling shared GPIO68 reset, which
+ * would blank the active display pipeline.
+ */
+static int ssd2092_lpm_wake(struct nvt36xxx_data *data)
+{
+ int ret;
+
+ ret = ssd2092_write_u16(data->ssl, SSD2092_DS_CUP_CONTROL, 0x0000);
+ if (ret)
+ return ret;
+ usleep_range(1000, 1500);
+ ret = ssd2092_write_u16(data->ssl, SSD2092_DS_CUP_CONTROL, 0x0000);
+ if (ret)
+ return ret;
+ msleep(5);
+
+ ret = ssd2092_hw_init(data);
+ if (ret)
+ return ret;
+ if (!data->last_fw_touch && !data->last_fw_disp)
+ return -EIO;
+ return 0;
+}
+
+static void ssd2092_resume_work_fn(struct work_struct *work)
+{
+ struct nvt36xxx_data *data =
+ container_of(work, struct nvt36xxx_data, resume_work.work);
+ struct device *dev = &data->client->dev;
+ int ret = -EIO;
+ int attempt;
+
+ if (!data->vcc_reg)
+ ssd2092_enable_pmic_vldo28();
+
+ for (attempt = 0; attempt < 5; attempt++) {
+ ret = ssd2092_lpm_wake(data);
+ if (!ret)
+ break;
+ msleep(20);
+ }
+ if (ret) {
+ ret = ssd2092_boot_seeprom(data);
+ if (!ret)
+ ret = ssd2092_hw_init(data);
+ if (ret)
+ dev_warn(dev, "SSD2092 resume init failed: %d\n", ret);
+ }
+
+ if (data->irq_disabled) {
+ data->irq_disabled = false;
+ enable_irq(data->client->irq);
+ }
+}
+
+static void ssd2092_cancel_resume_work(void *arg)
+{
+ cancel_delayed_work_sync(arg);
+}
+
static int ssd2092_probe(struct i2c_client *client, struct nvt36xxx_data *data)
{
struct device *dev = &client->dev;
@@ -747,6 +820,7 @@
data->orig_irq_type = dt_trig;
data->is_ssd2092 = true;
+ INIT_DELAYED_WORK(&data->resume_work, ssd2092_resume_work_fn);
ret = ssd2092_setup_power_and_reset(data);
if (ret)
return ret;
@@ -810,6 +884,11 @@
if (ret)
return dev_err_probe(dev, ret, "failed to request SSD2092 IRQ\n");
+ ret = devm_add_action_or_reset(dev, ssd2092_cancel_resume_work,
+ &data->resume_work);
+ if (ret)
+ return ret;
+
return 0;
}
@@ -908,19 +987,44 @@
return 0;
}
-static int nvt36xxx_suspend(struct device *dev)
+static int __maybe_unused nvt36xxx_pm_prepare(struct device *dev)
{
struct nvt36xxx_data *data = dev_get_drvdata(dev);
- disable_irq(data->client->irq);
-
- /* A finger down at suspend would otherwise stay down until it lifts */
- if (data->is_ssd2092) {
- memset(data->slots, 0, sizeof(data->slots));
- ssd2092_report_slots(data);
+ if (!data->is_ssd2092)
return 0;
+
+ cancel_delayed_work_sync(&data->resume_work);
+ if (!data->irq_disabled) {
+ disable_irq(data->client->irq);
+ data->irq_disabled = true;
}
+ memset(data->slots, 0, sizeof(data->slots));
+ ssd2092_report_slots(data);
+ return 0;
+}
+static void __maybe_unused nvt36xxx_pm_complete(struct device *dev)
+{
+ struct nvt36xxx_data *data = dev_get_drvdata(dev);
+
+ if (!data->is_ssd2092)
+ return;
+
+ schedule_delayed_work(&data->resume_work, msecs_to_jiffies(60));
+}
+
+static int __maybe_unused nvt36xxx_suspend(struct device *dev)
+{
+ struct nvt36xxx_data *data = dev_get_drvdata(dev);
+
+ /* SSD2092 TDDI touch quiesces in .prepare before panel/DSI sleep. */
+ if (data->is_ssd2092)
+ return 0;
+
+ disable_irq(data->client->irq);
+
+ /* A finger down at suspend would otherwise stay down until it lifts */
input_mt_sync_frame(data->input);
input_report_key(data->input, BTN_TOUCH, 0);
input_sync(data->input);
@@ -928,30 +1032,24 @@
return 0;
}
-static int nvt36xxx_resume(struct device *dev)
+static int __maybe_unused nvt36xxx_resume(struct device *dev)
{
struct nvt36xxx_data *data = dev_get_drvdata(dev);
- if (data->is_ssd2092) {
- int ret;
-
- if (!data->vcc_reg)
- ssd2092_enable_pmic_vldo28();
- ssd2092_reset_pulse(data);
- ret = ssd2092_boot_seeprom(data);
- if (!ret)
- ret = ssd2092_hw_init(data);
- if (ret)
- dev_warn(dev, "SSD2092 resume init failed: %d\n", ret);
- }
+ /* Defer SSD2092 touch wake until .complete after display/DSI is up. */
+ if (data->is_ssd2092)
+ return 0;
enable_irq(data->client->irq);
return 0;
}
-static DEFINE_SIMPLE_DEV_PM_OPS(nvt36xxx_pm_ops, nvt36xxx_suspend,
- nvt36xxx_resume);
+static const struct dev_pm_ops nvt36xxx_pm_ops = {
+ .prepare = pm_sleep_ptr(nvt36xxx_pm_prepare),
+ .complete = pm_sleep_ptr(nvt36xxx_pm_complete),
+ SYSTEM_SLEEP_PM_OPS(nvt36xxx_suspend, nvt36xxx_resume)
+};
static const struct of_device_id nvt36xxx_of_match[] = {
{ .compatible = "novatek,nt36772-ts" },
diff --git a/drivers/leds/rgb/leds-aw9120.c b/drivers/leds/rgb/leds-aw9120.c
--- a/drivers/leds/rgb/leds-aw9120.c
+++ b/drivers/leds/rgb/leds-aw9120.c
@@ -16,6 +16,7 @@
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/mutex.h>
+#include <linux/pm.h>
#include <linux/property.h>
#include <linux/regmap.h>
@@ -54,6 +55,7 @@
/* Channels with a non-zero PWM; the chip's oscillator runs only with one */
u32 lit;
u32 used;
+ bool powered_down;
u16 imax[AW9120_NUM_IMAX];
};
@@ -278,6 +280,7 @@
return -ENOMEM;
chip->dev = dev;
+ i2c_set_clientdata(client, chip);
ret = devm_mutex_init(dev, &chip->lock);
if (ret)
@@ -345,6 +348,36 @@
};
MODULE_DEVICE_TABLE(of, aw9120_of_match);
+static int __maybe_unused aw9120_suspend(struct device *dev)
+{
+ struct aw9120 *chip = dev_get_drvdata(dev);
+
+ guard(mutex)(&chip->lock);
+ if (!chip->lit) {
+ gpiod_set_value_cansleep(chip->enable, 0);
+ chip->powered_down = true;
+ }
+ return 0;
+}
+
+static int __maybe_unused aw9120_resume(struct device *dev)
+{
+ struct aw9120 *chip = dev_get_drvdata(dev);
+ int ret = 0;
+
+ guard(mutex)(&chip->lock);
+ if (chip->powered_down) {
+ gpiod_set_value_cansleep(chip->enable, 1);
+ fsleep(AW9120_POWER_ON_US);
+ ret = aw9120_setup_outputs(chip);
+ if (!ret)
+ chip->powered_down = false;
+ }
+ return ret;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(aw9120_pm_ops, aw9120_suspend, aw9120_resume);
+
static const struct i2c_device_id aw9120_id[] = {
{ "aw9120" },
{ }
@@ -355,6 +388,7 @@
.driver = {
.name = "leds-aw9120",
.of_match_table = aw9120_of_match,
+ .pm = pm_sleep_ptr(&aw9120_pm_ops),
},
.probe = aw9120_probe,
.id_table = aw9120_id,
diff --git a/drivers/power/supply/mt6351-fuel-gauge.c b/drivers/power/supply/mt6351-fuel-gauge.c
--- a/drivers/power/supply/mt6351-fuel-gauge.c
+++ b/drivers/power/supply/mt6351-fuel-gauge.c
@@ -691,9 +691,11 @@
static void mt6351_fg_report(struct mt6351_fg *fg, s64 uah, int *capacity, int *charge_uah)
{
s64 full = mt6351_fg_rep_full(fg);
+ s64 empty = div_s64(fg->full_uah * fg->empty_pct, 100);
+ s64 span = max_t(s64, full - empty, 1);
- uah = clamp_t(s64, uah - div_s64(fg->full_uah * fg->empty_pct, 100), 0, full);
- *capacity = div64_s64(uah * 100 + full / 2, full);
+ uah = clamp_t(s64, uah - empty, 0, span);
+ *capacity = div64_s64(uah * 100 + span / 2, span);
*charge_uah = uah;
}
@@ -997,10 +999,10 @@
* After a charge, surface charge raises it a few points, which the next rest
* or charge corrects. Called once at probe.
*/
-static void mt6351_fg_pwron_anchor(struct mt6351_fg *fg)
+static void mt6351_fg_pwron_anchor(struct mt6351_fg *fg, int init_ua)
{
unsigned int val;
- int uv, mc, pct;
+ int uv, mc, pct, live_uv;
if (regmap_read(fg->regmap, MT6351_AUXADC_ADC21, &val) ||
!(val & MT6351_PWRON_RDY) || thermal_zone_get_temp(fg->tz, &mc))
@@ -1014,6 +1016,23 @@
if (pct < 0)
return;
+ /*
+ * ADC21 is only latched on cold battery attach and goes stale across
+ * warm reboots or USB reflashes while VBAT remains present.
+ */
+ if (!mt6351_fg_voltage(fg, &live_uv)) {
+ int live_ocv = mt6351_fg_ocv(fg, live_uv, init_ua, mc);
+ int live_pct = power_supply_batinfo_ocv2cap(fg->info, live_ocv, mc / 1000);
+
+ if (abs(uv - live_ocv) > 80000 ||
+ (live_pct >= 0 && abs(pct - live_pct) > 10)) {
+ dev_info(fg->dev,
+ "ignoring stale start-up OCV %d uV (%d %%) vs live %d uV (%d %%)\n",
+ uv, pct, live_ocv, live_pct);
+ return;
+ }
+ }
+
guard(mutex)(&fg->lock);
fg->anchor_uah = div_s64(fg->full_uah * clamp(pct, 0, 100), 100);
fg->anchor_car = fg->car;
@@ -1103,8 +1122,12 @@
WRITE_ONCE(fg->info, info);
/* Open the first current window now, so the current is known 5 s on. */
- mt6351_fg_read(fg, &ret, &ret);
- mt6351_fg_pwron_anchor(fg);
+ {
+ int init_ua = 0, init_uah = 0;
+
+ ret = mt6351_fg_read(fg, &init_ua, &init_uah);
+ mt6351_fg_pwron_anchor(fg, ret ? 0 : init_ua);
+ }
/*
* A charger attached while the system sleeps wakes it, so that the
@@ -1153,8 +1176,12 @@
if (!READ_ONCE(fg->info))
return -ENODATA;
- scoped_guard(mutex, &fg->lock)
+ scoped_guard(mutex, &fg->lock) {
fg->r25_uohm = r;
+ fg->empty_valid = false;
+ if (!fg->anchor_trusted)
+ fg->anchored = false;
+ }
power_supply_changed(fg->psy);
return count;
diff --git a/drivers/soc/mediatek/mt6797-ccci-cldma.c b/drivers/soc/mediatek/mt6797-ccci-cldma.c
--- a/drivers/soc/mediatek/mt6797-ccci-cldma.c
+++ b/drivers/soc/mediatek/mt6797-ccci-cldma.c
@@ -1310,6 +1310,9 @@
mt6797_ccci_free_irqs(cdev);
cancel_work_sync(&cdev->rx_work);
mt6797_ccci_free_rings(cdev);
+ if (cdev->infracfg)
+ regmap_update_bits(cdev->infracfg, INFRA_AO_MD_SRCCLKENA,
+ 0xff, 0x00);
cdev->md_state = MT6797_MD_STATE_GATED;
cdev->active_stage = 0;
stage = 0;
@@ -1473,6 +1476,9 @@
mutex_lock(&cdev->state_lock);
mt6797_ccci_apply_stage(cdev, clamp_t(u32, stage, 0, 3));
mutex_unlock(&cdev->state_lock);
+ } else if (cdev->infracfg) {
+ regmap_update_bits(cdev->infracfg, INFRA_AO_MD_SRCCLKENA,
+ 0xff, 0x00);
}
dev_info(&pdev->dev,
diff --git a/drivers/soc/mediatek/mt6797-spm-sleep.c b/drivers/soc/mediatek/mt6797-spm-sleep.c
--- a/drivers/soc/mediatek/mt6797-spm-sleep.c
+++ b/drivers/soc/mediatek/mt6797-spm-sleep.c
@@ -482,11 +482,11 @@
u32 im_resident; /* the program IM holds after a return, or 0 */
} s;
-static unsigned int timer_sec = 30;
+static unsigned int timer_sec = 600;
module_param(timer_sec, uint, 0644);
MODULE_PARM_DESC(timer_sec, "PCM wake timer in seconds (1-600)");
-static bool pmic_modes;
+static bool pmic_modes = true;
module_param(pmic_modes, bool, 0644);
MODULE_PARM_DESC(pmic_modes, "Set the static PMIC sleep modes for each suspend");
@@ -1388,7 +1388,11 @@
disable_irq_wake(s.irq);
disable_irq(s.irq);
spm_pmic_finish();
- spm_log_wake("wake");
+ if (!s.entered || !s.wake.returned || s.wake.backstop ||
+ s.wake.r12 != BIT(0))
+ spm_log_wake("wake");
+ else
+ dev_dbg(&s.pdev->dev, "suspend timer tick r12=%08x\n", s.wake.r12);
}
static void spm_log_wake(const char *what)
@@ -1609,7 +1613,7 @@
MODULE_PARM_DESC(sodi_idle_max_ms, "SODI idle: longest period in ms (1-2000)");
/* Whether to register the cpuidle driver at all (stage D5d bisects it) */
-static bool sodi_idle = true;
+static bool sodi_idle;
module_param(sodi_idle, bool, 0444);
MODULE_PARM_DESC(sodi_idle, "SODI idle: register the CPU0 cpuidle driver");
@@ -1870,11 +1874,22 @@
s.idle_registered = false;
}
+static bool spm_suspend_again(void)
+{
+ if (!s.entered || !s.wake.returned || s.wake.backstop)
+ return false;
+ if (pm_wakeup_pending())
+ return false;
+ /* Stay asleep across silent PCM timer rollovers; wake on EINT/other. */
+ return s.wake.r12 == BIT(0);
+}
+
static const struct platform_suspend_ops spm_suspend_ops = {
.valid = spm_valid,
.prepare = spm_prepare,
.enter = spm_enter,
.finish = spm_finish,
+ .suspend_again = spm_suspend_again,
};
/* ---- load ---- */