diff --git a/Documentation/devicetree/bindings/display/panel/samsung,s6e3hc4.yaml b/Documentation/devicetree/bindings/display/panel/samsung,s6e3hc4.yaml index 39c26ee093..4a5081ceab 100644 --- a/Documentation/devicetree/bindings/display/panel/samsung,s6e3hc4.yaml +++ b/Documentation/devicetree/bindings/display/panel/samsung,s6e3hc4.yaml @@ -20,7 +20,9 @@ allOf: properties: compatible: - const: samsung,s6e3hc4 + enum: + - samsung,s6e3hc3 + - samsung,s6e3hc4 reg: maxItems: 1 @@ -39,7 +41,15 @@ properties: required: - compatible - reg - - reset-gpios + +if: + properties: + compatible: + contains: + const: samsung,s6e3hc4 +then: + required: + - reset-gpios unevaluatedProperties: false diff --git a/Documentation/devicetree/bindings/display/samsung/google,gs201-decon.yaml b/Documentation/devicetree/bindings/display/samsung/google,gs201-decon.yaml index baf0a8b90c..28dfb1a80e 100644 --- a/Documentation/devicetree/bindings/display/samsung/google,gs201-decon.yaml +++ b/Documentation/devicetree/bindings/display/samsung/google,gs201-decon.yaml @@ -20,10 +20,14 @@ description: properties: compatible: - enum: - - google,gs201-decon - - google,zuma-decon - - google,zumapro-decon + oneOf: + - enum: + - google,gs201-decon + - google,zuma-decon + - google,zumapro-decon + - items: + - const: google,gs101-decon + - const: google,gs201-decon reg: items: diff --git a/Documentation/devicetree/bindings/display/samsung/google,gs201-dsim.yaml b/Documentation/devicetree/bindings/display/samsung/google,gs201-dsim.yaml index db2f48a8cb..1244b872cf 100644 --- a/Documentation/devicetree/bindings/display/samsung/google,gs201-dsim.yaml +++ b/Documentation/devicetree/bindings/display/samsung/google,gs201-dsim.yaml @@ -26,6 +26,7 @@ properties: - const: google,gs201-dsim - items: - enum: + - google,gs101-dsim - google,zuma-dsim - google,zumapro-dsim - const: google,gs201-dsim diff --git a/MAINTAINERS b/MAINTAINERS index a41d259607..2c4ec69a7a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8498,6 +8498,11 @@ S: Maintained F: Documentation/devicetree/bindings/display/panel/samsung,s6e3ha8.yaml F: drivers/gpu/drm/panel/panel-samsung-s6e3ha8.c +DRM DRIVER FOR SAMSUNG S6E3HC3 PANELS +M: saiththerobo +S: Maintained +F: drivers/gpu/drm/panel/panel-samsung-s6e3hc3.c + DRM DRIVER FOR SAMSUNG S6E8FC0 PANELS M: Yedaya Katsman S: Maintained diff --git a/arch/arm64/boot/dts/exynos/google/gs101-raven.dts b/arch/arm64/boot/dts/exynos/google/gs101-raven.dts index 266456f9a0..164e2dd58c 100644 --- a/arch/arm64/boot/dts/exynos/google/gs101-raven.dts +++ b/arch/arm64/boot/dts/exynos/google/gs101-raven.dts @@ -44,6 +44,22 @@ constant-charge-voltage-max-microvolt = <4450000>; constant-charge-current-max-microamp = <1466730>; }; + + reserved-memory { + /* + * Scanout buffers for gs-decon: DPP0 takes 32-bit addresses and + * the DPU SysMMU is bypassed (as on cheetah). Five 1440x3120 + * XRGB8888 buffers; reusable while unused. + */ + display_pool: display-pool { + compatible = "shared-dma-pool"; + reusable; + size = <0x5c00000>; + alignment = <0x0 0x200000>; + /* Not in 3.75-4 GiB: DPP0's reads from 0xf2c00000+ hung silently */ + alloc-ranges = <0x0 0xa0000000 0x40000000>; + }; + }; }; &acpm_ipc { @@ -155,6 +171,25 @@ status = "okay"; }; +/* The display: gs-decon takes over the bootloader's pipeline from simpledrm */ +&decon0 { + memory-region = <&display_pool>, <&cont_splash_mem>; + memory-region-names = "pool", "boot-framebuffer"; + status = "okay"; +}; + +&dsi0 { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + + /* brightness, display on/off and 60/120 Hz; the bootloader runs it */ + panel@0 { + compatible = "samsung,s6e3hc3"; + reg = <0>; + }; +}; + &framebuffer0 { width = <1440>; height = <3120>; @@ -342,3 +377,17 @@ cirrus,boost-ctl-microvolt = <7500000>; }; }; + +/* + * The panel's rails (the framebuffer's vci and vddi supplies). simpledrm + * holds them; when gs-decon takes the display over, simpledrm goes away and + * releases them, the panel lost power and DECON stalled on its first flip. + * The S6E3HC3 driver doesn't switch them, so they stay on. + */ +&s2mpg10_ldo22m { + regulator-always-on; +}; + +&s2mpg11_bucka { + regulator-always-on; +}; diff --git a/arch/arm64/boot/dts/exynos/google/gs101.dtsi b/arch/arm64/boot/dts/exynos/google/gs101.dtsi index ad1816b74f..95135701b8 100644 --- a/arch/arm64/boot/dts/exynos/google/gs101.dtsi +++ b/arch/arm64/boot/dts/exynos/google/gs101.dtsi @@ -2123,6 +2123,48 @@ clocks = <&cmu_dpu CLK_GOUT_DPU_SYSREG_DPU_PCLK>; }; + /* + * The display pipeline as the bootloader leaves it running: + * DECON0 in DSI command mode, scanning out through the DPP0 + * read DMA, into DSIM0 (Google's gs101-drm-dpu.dtsi). No + * power-domains: nothing may power the DPU down under DECON. + */ + decon0: display-controller@1c300000 { + compatible = "google,gs101-decon", "google,gs201-decon"; + reg = <0x1c300000 0x6000>, <0x1c0b0000 0x1000>; + reg-names = "main", "dma"; + interrupts = , + , + ; + interrupt-names = "frame_start", "frame_done", "extra"; + clocks = <&acpm_ipc GS101_CLK_ACPM_DVFS_MIF>, + <&acpm_ipc GS101_CLK_ACPM_DVFS_DISP>; + clock-names = "mif", "disp"; + status = "disabled"; + + port { + decon0_out: endpoint { + remote-endpoint = <&dsi0_in>; + }; + }; + }; + + dsi0: dsi@1c2c0000 { + compatible = "google,gs101-dsim", "google,gs201-dsim"; + reg = <0x1c2c0000 0x300>, + <0x1c2e0100 0x700>, + <0x1c2e0000 0x100>; + reg-names = "dsi", "dphy", "dphy-extra"; + interrupts = ; + status = "disabled"; + + port { + dsi0_in: endpoint { + remote-endpoint = <&decon0_out>; + }; + }; + }; + gpu: gpu@1c500000 { compatible = "google,gs101-mali", "arm,mali-valhall-jm"; reg = <0x1c500000 0x5000>; diff --git a/drivers/gpu/drm/google/gs-decon.c b/drivers/gpu/drm/google/gs-decon.c index cbeeddc11d..1a5dd8c216 100644 --- a/drivers/gpu/drm/google/gs-decon.c +++ b/drivers/gpu/drm/google/gs-decon.c @@ -33,9 +33,10 @@ * * Register layout from Google's GPL display driver * (google-modules/display/samsung/cal_9845/regs-decon.h and regs-dpp.h), - * which gs201 shares with gs101. G3 and G4 offsets and the fourteen-window - * mask follow cal_9865/regs-decon.h and regs-dpp.h in the same GPL driver, - * which builds that CAL for both. + * which gs201 shares with gs101. On gs101 only DECON0's address and the + * interrupt numbers differ (device tree). G3 and G4 offsets and the + * fourteen-window mask follow cal_9865/regs-decon.h and regs-dpp.h in the + * same GPL driver, which builds that CAL for both. */ #include @@ -53,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -268,6 +270,10 @@ struct gs_decon_soc_data { bool start_hw_trigger; /* the bootloader leaves MIF and DISP above the 120 Hz floors */ bool floors_optional; + /* hold the boot framebuffer's aperture after evicting simpledrm */ + bool hold_boot_fb; + /* a VT switch around system sleep only with the fbdev console */ + bool vt_switch_fbdev_only; }; static const struct gs_decon_soc_data gs201_decon_data = { @@ -278,6 +284,20 @@ static const struct gs_decon_soc_data gs201_decon_data = { .shadow_update_mask = SHD_REG_UP_REQ_FLIP(SHD_REG_UP_REQ_ALL_WIN), }; +/* + * gs101 is gs201's DECON; the boot framebuffer and sleep handling below were + * found and tested on raven only, so they stay off for gs201. + */ +static const struct gs_decon_soc_data gs101_decon_data = { + .modes = gs_decon_modes, + .num_modes = ARRAY_SIZE(gs_decon_modes), + .image_size_reg = RDMA_IMG_SIZE, + .source_offset_reg = RDMA_SRC_OFFSET, + .shadow_update_mask = SHD_REG_UP_REQ_FLIP(SHD_REG_UP_REQ_ALL_WIN), + .hold_boot_fb = true, + .vt_switch_fbdev_only = true, +}; + static const struct gs_decon_soc_data zumapro_decon_data = { .modes = tegu_decon_modes, .num_modes = ARRAY_SIZE(tegu_decon_modes), @@ -331,6 +351,8 @@ struct gs_decon { /* optional ACPM DVFS domains, floors at 120 Hz */ struct clk *mif; + /* MIF before any 120 Hz floor, put back when the floor goes */ + unsigned long mif_rest; struct clk *disp; /* the link and panel, for rate switching; NULL: 60 Hz only */ @@ -706,6 +728,17 @@ static void gs_decon_set_floors(struct gs_decon *dc, unsigned int hz) if (ret) dev_warn(dc->dev, "DISP floor for %u Hz: %d\n", hz, ret); + /* + * Nothing else votes on MIF yet, so without this it would stay at the + * 120 Hz floor after every 120 Hz stint, screen off included. + */ + if (!high && dc->mif_rest && clk_get_rate(dc->mif) > dc->mif_rest) { + ret = clk_set_rate(dc->mif, dc->mif_rest); + if (ret) + dev_warn(dc->dev, "MIF back to %lu Hz: %d\n", + dc->mif_rest, ret); + } + if (high) dev_dbg(dc->dev, "MIF %lu Hz, DISP %lu Hz\n", clk_get_rate(dc->mif), clk_get_rate(dc->disp)); @@ -1468,8 +1501,10 @@ static int gs_decon_probe(struct platform_device *pdev) dc->disp = devm_clk_get_optional(dev, "disp"); if (IS_ERR(dc->disp)) return dev_err_probe(dev, PTR_ERR(dc->disp), "disp clock\n"); - if (dc->mif) - dev_info(dev, "MIF at %lu Hz\n", clk_get_rate(dc->mif)); + if (dc->mif) { + dc->mif_rest = clk_get_rate(dc->mif); + dev_info(dev, "MIF at %lu Hz\n", dc->mif_rest); + } if (dc->disp) dev_info(dev, "DISP at %lu Hz\n", clk_get_rate(dc->disp)); @@ -1518,6 +1553,17 @@ static int gs_decon_probe(struct platform_device *pdev) gs_decon_driver.name); if (ret) goto err_irqs; + /* + * and keep it: on raven simpledrm probed 30 ms after us, found the + * aperture free and stayed as a second, phantom output. Holding the + * range makes its own acquire fail with -EBUSY. + */ + if (dc->soc->hold_boot_fb) { + ret = devm_aperture_acquire_for_platform_device(pdev, dc->boot_fb.start, + resource_size(&dc->boot_fb)); + if (ret) + goto err_irqs; + } dc->kms = true; ret = drm_dev_register(&dc->drm, 0); @@ -1531,6 +1577,15 @@ static int gs_decon_probe(struct platform_device *pdev) */ if (fbdev) drm_client_setup(&dc->drm, NULL); + + /* + * Without an fbdev console, a VT switch around system sleep has + * nothing to show, and it costs the compositor its input devices: + * logind takes the session away and gives it back, and the key press + * that woke the phone is lost with the device it was queued on. + */ + if (dc->soc->vt_switch_fbdev_only) + pm_vt_switch_required(dev, fbdev); dev_info(dev, "flip-only KMS on DECON0, %ux%u, up to %u Hz (at %u Hz)\n", dc->width, dc->height, dc->max_hz, dc->hz); @@ -1549,6 +1604,8 @@ static void gs_decon_remove(struct platform_device *pdev) struct gs_decon *dc = platform_get_drvdata(pdev); if (dc->kms) { + if (dc->soc->vt_switch_fbdev_only) + pm_vt_switch_unregister(&pdev->dev); dc->going_down = true; drm_dev_unplug(&dc->drm); drm_atomic_helper_shutdown(&dc->drm); @@ -1579,6 +1636,7 @@ static void gs_decon_shutdown(struct platform_device *pdev) } static const struct of_device_id gs_decon_of_match[] = { + { .compatible = "google,gs101-decon", .data = &gs101_decon_data }, { .compatible = "google,gs201-decon", .data = &gs201_decon_data }, { .compatible = "google,zuma-decon", .data = &zuma_decon_data }, { .compatible = "google,zumapro-decon", .data = &zumapro_decon_data }, diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig index 625290c7fa..d82882275e 100644 --- a/drivers/gpu/drm/panel/Kconfig +++ b/drivers/gpu/drm/panel/Kconfig @@ -1085,6 +1085,18 @@ config DRM_PANEL_SAMSUNG_S6E3HA8 Samsung AMB577PX01 (found in the Samsung S9 smartphone) +config DRM_PANEL_SAMSUNG_S6E3HC3 + tristate "Samsung S6E3HC3 DSI command mode panel" + depends on OF + depends on DRM_MIPI_DSI + depends on BACKLIGHT_CLASS_DEVICE + help + Say Y or M here to control the Samsung S6E3HC3 command-mode AMOLED + panel in the Google Pixel 6 Pro: its brightness through a backlight + device, and display on and off. The panel is used as the bootloader + left it running: the driver sends no initialisation sequence, and + the display modes come from the display controller's driver. + config DRM_PANEL_SAMSUNG_S6E3HC4 tristate "Samsung S6E3HC4 DSI command mode panel" depends on GPIOLIB diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile index 93ed5eecea..e9506c1721 100644 --- a/drivers/gpu/drm/panel/Makefile +++ b/drivers/gpu/drm/panel/Makefile @@ -103,6 +103,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3FC2X01) += panel-samsung-s6e3fc2x01.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3FC3) += panel-samsung-s6e3fc3.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3HA2) += panel-samsung-s6e3ha2.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3HA8) += panel-samsung-s6e3ha8.o +obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3HC3) += panel-samsung-s6e3hc3.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3HC4) += panel-samsung-s6e3hc4.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63J0X03) += panel-samsung-s6e63j0x03.o obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63M0) += panel-samsung-s6e63m0.o diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e3hc3.c b/drivers/gpu/drm/panel/panel-samsung-s6e3hc3.c new file mode 100644 index 0000000000..0aaaf56eff --- /dev/null +++ b/drivers/gpu/drm/panel/panel-samsung-s6e3hc3.c @@ -0,0 +1,204 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Samsung S6E3HC3 DSI command-mode AMOLED panel (Google Pixel 6 Pro) + * + * Brightness levels and the display off/on commands from Google's GPL panel + * driver (google-modules/display/samsung/panel/panel-samsung-s6e3hc3.c). + * + * The bootloader powers the panel on and leaves it running, scanned out by + * simpledrm or gs-decon. This driver takes it over as it is: it never drives + * the reset line or the rails, and sends nothing until the brightness or the + * backlight power state changes. A blanked backlight (bl_power) turns the + * display off, which stops the OLED emitting but keeps the panel out of + * sleep with its registers intact; unblanking turns it back on. Level 0 + * is the dimmest level, not off. It switches between 60 and 120 Hz for the + * DSIM (drm_panel_set_refresh_rate()). + */ + +#include +#include +#include +#include + +#include +#include +#include + +/* Normal range; 2232..3152 are the high brightness mode (HBM) levels. */ +#define S6E3HC3_MIN_BRIGHTNESS 4 +#define S6E3HC3_MAX_BRIGHTNESS 2047 +#define S6E3HC3_DEFAULT_BRIGHTNESS 1023 + +struct s6e3hc3 { + struct drm_panel panel; + struct mipi_dsi_device *dsi; + /* guards the state below and keeps sequences from interleaving */ + struct mutex lock; + bool display_off; +}; + +static int s6e3hc3_bl_update_status(struct backlight_device *bl) +{ + struct s6e3hc3 *ctx = bl_get_data(bl); + struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi }; + u16 brightness = backlight_get_brightness(bl); + int ret; + + guard(mutex)(&ctx->lock); + + /* + * Only a blanked backlight turns the display off. Level 0 is the + * dimmest level: Omarchy darkens with 0 before locking and puts the + * level back afterwards, and a level left at 0 must not leave the + * panel dark with nothing to wake it. + */ + if (backlight_is_blank(bl)) { + if (!ctx->display_off) { + mipi_dsi_dcs_set_display_off_multi(&dsi_ctx); + /* as the vendor driver: 20 ms after display off */ + mipi_dsi_msleep(&dsi_ctx, 20); + if (!dsi_ctx.accum_err) + ctx->display_off = true; + } + return dsi_ctx.accum_err; + } + + /* DBV, most significant byte first */ + brightness = max_t(u16, brightness, S6E3HC3_MIN_BRIGHTNESS); + ret = mipi_dsi_dcs_set_display_brightness_large(ctx->dsi, brightness); + if (ret < 0) + return ret; + + if (ctx->display_off) { + mipi_dsi_dcs_set_display_on_multi(&dsi_ctx); + if (!dsi_ctx.accum_err) + ctx->display_off = false; + } + + return dsi_ctx.accum_err; +} + +static const struct backlight_ops s6e3hc3_bl_ops = { + .update_status = s6e3hc3_bl_update_status, +}; + +/* + * Manual 60/120 Hz, as the vendor driver's s6e3hc3_set_manual_mode(): the + * rate takes effect at the panel's next frame (frequency update), with no + * power cycle. The DSIM switches its link timers around this. + */ +static int s6e3hc3_set_refresh_rate(struct drm_panel *panel, unsigned int hz) +{ + struct s6e3hc3 *ctx = container_of(panel, struct s6e3hc3, panel); + struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi }; + + if (hz != 60 && hz != 120) + return -EINVAL; + + guard(mutex)(&ctx->lock); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0x5a, 0x5a); + /* manual mode, then 0x00 for 120 Hz or 0x01 for 60 Hz */ + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xbd, 0x21); + if (hz == 120) + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x60, 0x00); + else + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x60, 0x01); + /* frequency update */ + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf7, 0x0f); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0xa5, 0xa5); + + return dsi_ctx.accum_err; +} + +static const struct drm_panel_funcs s6e3hc3_panel_funcs = { + .set_refresh_rate = s6e3hc3_set_refresh_rate, +}; + +static int s6e3hc3_probe(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + struct backlight_properties props = { + .type = BACKLIGHT_RAW, + .brightness = S6E3HC3_DEFAULT_BRIGHTNESS, + .max_brightness = S6E3HC3_MAX_BRIGHTNESS, + .scale = BACKLIGHT_SCALE_NON_LINEAR, + }; + struct backlight_device *bl; + struct s6e3hc3 *ctx; + int ret; + + ctx = devm_drm_panel_alloc(dev, struct s6e3hc3, panel, + &s6e3hc3_panel_funcs, + DRM_MODE_CONNECTOR_DSI); + if (IS_ERR(ctx)) + return PTR_ERR(ctx); + + ret = devm_mutex_init(dev, &ctx->lock); + if (ret) + return ret; + + ctx->dsi = dsi; + mipi_dsi_set_drvdata(dsi, ctx); + /* + * Unknown after a module reload: the first unblanked update sends + * display on, which is harmless on a lit panel. + */ + ctx->display_off = true; + + dsi->lanes = 4; + dsi->format = MIPI_DSI_FMT_RGB888; + dsi->mode_flags = MIPI_DSI_CLOCK_NON_CONTINUOUS; + + /* + * The bootloader's level is unknown, so the first write sets the + * default. Nothing is sent until then. + */ + bl = devm_backlight_device_register(dev, dev_name(dev), dev, ctx, + &s6e3hc3_bl_ops, &props); + if (IS_ERR(bl)) + return dev_err_probe(dev, PTR_ERR(bl), + "failed to register backlight\n"); + ctx->panel.backlight = bl; + + drm_panel_add(&ctx->panel); + + ret = mipi_dsi_attach(dsi); + if (ret < 0) { + drm_panel_remove(&ctx->panel); + return dev_err_probe(dev, ret, "failed to attach to DSI host\n"); + } + + dev_info(dev, "taken over from the bootloader\n"); + return 0; +} + +static void s6e3hc3_remove(struct mipi_dsi_device *dsi) +{ + struct s6e3hc3 *ctx = mipi_dsi_get_drvdata(dsi); + int ret; + + ret = mipi_dsi_detach(dsi); + if (ret < 0) + dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", ret); + + drm_panel_remove(&ctx->panel); +} + +static const struct of_device_id s6e3hc3_of_match[] = { + { .compatible = "samsung,s6e3hc3" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, s6e3hc3_of_match); + +static struct mipi_dsi_driver s6e3hc3_driver = { + .probe = s6e3hc3_probe, + .remove = s6e3hc3_remove, + .driver = { + .name = "panel-samsung-s6e3hc3", + .of_match_table = s6e3hc3_of_match, + }, +}; +module_mipi_dsi_driver(s6e3hc3_driver); + +MODULE_DESCRIPTION("Samsung S6E3HC3 panel: brightness and display on/off"); +MODULE_LICENSE("GPL");