From e41b49b7e4d4ad9755af4813a57b5f6a09e357d7 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Thu, 7 May 2020 09:23:11 -0700 Subject: [PATCH 01/21] drm: panel: add MODULE_LICENSE to panel-visionox-rm69299.c Add MODULE_LICENSE() to the panel-visionox-rm69299 driver to fix a build warning. WARNING: modpost: missing MODULE_LICENSE() in drivers/gpu/drm/panel/panel-visionox-rm69299.o Signed-off-by: Randy Dunlap Fixes: c7f66d32dd43 ("drm/panel: add support for rm69299 visionox panel") Cc: Harigovindan P Cc: Matthias Kaehlcke Cc: Thierry Reding Cc: Sam Ravnborg Cc: dri-devel@lists.freedesktop.org Signed-off-by: Sam Ravnborg [added fixes: tag] Link: https://patchwork.freedesktop.org/patch/msgid/bbb7b3b3-9968-9a1f-8ef6-2e8e3be998f6@infradead.org --- drivers/gpu/drm/panel/panel-visionox-rm69299.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/panel/panel-visionox-rm69299.c b/drivers/gpu/drm/panel/panel-visionox-rm69299.c index 25fe8b0bb040..42f299ad3804 100644 --- a/drivers/gpu/drm/panel/panel-visionox-rm69299.c +++ b/drivers/gpu/drm/panel/panel-visionox-rm69299.c @@ -300,3 +300,4 @@ static struct mipi_dsi_driver visionox_rm69299_driver = { module_mipi_dsi_driver(visionox_rm69299_driver); MODULE_DESCRIPTION("Visionox RM69299 DSI Panel Driver"); +MODULE_LICENSE("GPL v2"); From d3943821a0e1952aa3319cc6a4ccf937eaabebac Mon Sep 17 00:00:00 2001 From: Konrad Dybcio Date: Wed, 6 May 2020 23:09:56 +0200 Subject: [PATCH 02/21] dt-bindings: display: Document ASUS Z00T TM5P5 NT35596 panel compatible Signed-off-by: Konrad Dybcio Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200506210957.344590-3-konradybcio@gmail.com --- .../panel/asus,z00t-tm5p5-nt35596.yaml | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/panel/asus,z00t-tm5p5-nt35596.yaml diff --git a/Documentation/devicetree/bindings/display/panel/asus,z00t-tm5p5-nt35596.yaml b/Documentation/devicetree/bindings/display/panel/asus,z00t-tm5p5-nt35596.yaml new file mode 100644 index 000000000000..083d2b9d0c69 --- /dev/null +++ b/Documentation/devicetree/bindings/display/panel/asus,z00t-tm5p5-nt35596.yaml @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/panel/asus,z00t-tm5p5-nt35596.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ASUS Z00T TM5P5 NT35596 5.5" 1080×1920 LCD Panel + +maintainers: + - Konrad Dybcio + +description: |+ + This panel seems to only be found in the Asus Z00T + smartphone and we have no straightforward way of + actually getting the correct model number, + as no schematics are released publicly. + +allOf: + - $ref: panel-common.yaml# + +properties: + compatible: + const: asus,z00t-tm5p5-n35596 + reg: true + reset-gpios: true + vdd-supply: + description: core voltage supply + vddio-supply: + description: vddio supply + +required: + - compatible + - reg + - vdd-supply + - vddio-supply + - reset-gpios + +additionalProperties: false + +examples: + - | + #include + + dsi { + #address-cells = <1>; + #size-cells = <0>; + panel@0 { + reg = <0>; + + compatible = "asus,z00t-tm5p5-n35596"; + + vdd-supply = <&pm8916_l8>; + vddio-supply = <&pm8916_l6>; + reset-gpios = <&msmgpio 25 GPIO_ACTIVE_HIGH>; + }; + }; From 02ed76b6da0710a9d24f36a4a9800a68d7edb9a7 Mon Sep 17 00:00:00 2001 From: Konrad Dybcio Date: Wed, 6 May 2020 23:09:55 +0200 Subject: [PATCH 03/21] drivers: drm: panel: Add ASUS TM5P5 NT35596 panel driver This adds support for TMP5P5 NT35596 1080x1920 video mode panel that can be found on some Asus Zenfone 2 Laser (Z00T) devices. This panel seems to only be found in this device and we have no straightforward way of actually getting the correct model number, as no schematics are released publicly. Signed-off-by: Konrad Dybcio Signed-off-by: Sam Ravnborg [fixed checkpatch warnings] Link: https://patchwork.freedesktop.org/patch/msgid/20200506210957.344590-2-konradybcio@gmail.com --- drivers/gpu/drm/panel/Kconfig | 10 + drivers/gpu/drm/panel/Makefile | 1 + .../drm/panel/panel-asus-z00t-tm5p5-n35596.c | 367 ++++++++++++++++++ 3 files changed, 378 insertions(+) create mode 100644 drivers/gpu/drm/panel/panel-asus-z00t-tm5p5-n35596.c diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig index 4b6131f5893d..39055c1f0e2f 100644 --- a/drivers/gpu/drm/panel/Kconfig +++ b/drivers/gpu/drm/panel/Kconfig @@ -18,6 +18,16 @@ config DRM_PANEL_ARM_VERSATILE reference designs. The panel is detected using special registers in the Versatile family syscon registers. +config DRM_PANEL_ASUS_Z00T_TM5P5_NT35596 + tristate "ASUS Z00T TM5P5 NT35596 panel" + depends on GPIOLIB && OF + depends on DRM_MIPI_DSI + depends on BACKLIGHT_CLASS_DEVICE + help + Say Y here if you want to enable support for the ASUS TMP5P5 + NT35596 1080x1920 video mode panel as found in some Asus + Zenfone 2 Laser Z00T devices. + config DRM_PANEL_BOE_HIMAX8279D tristate "Boe Himax8279d panel" depends on OF diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile index 8eac3e6fa82c..de74f282c433 100644 --- a/drivers/gpu/drm/panel/Makefile +++ b/drivers/gpu/drm/panel/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DRM_PANEL_ARM_VERSATILE) += panel-arm-versatile.o +obj-$(CONFIG_DRM_PANEL_ASUS_Z00T_TM5P5_NT35596) += panel-asus-z00t-tm5p5-n35596.o obj-$(CONFIG_DRM_PANEL_BOE_HIMAX8279D) += panel-boe-himax8279d.o obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_NL6) += panel-boe-tv101wum-nl6.o obj-$(CONFIG_DRM_PANEL_LVDS) += panel-lvds.o diff --git a/drivers/gpu/drm/panel/panel-asus-z00t-tm5p5-n35596.c b/drivers/gpu/drm/panel/panel-asus-z00t-tm5p5-n35596.c new file mode 100644 index 000000000000..39e0f0373f3c --- /dev/null +++ b/drivers/gpu/drm/panel/panel-asus-z00t-tm5p5-n35596.c @@ -0,0 +1,367 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +struct tm5p5_nt35596 { + struct drm_panel panel; + struct mipi_dsi_device *dsi; + struct regulator_bulk_data supplies[2]; + struct gpio_desc *reset_gpio; + bool prepared; +}; + +static inline struct tm5p5_nt35596 *to_tm5p5_nt35596(struct drm_panel *panel) +{ + return container_of(panel, struct tm5p5_nt35596, panel); +} + +#define dsi_generic_write_seq(dsi, seq...) do { \ + static const u8 d[] = { seq }; \ + int ret; \ + ret = mipi_dsi_generic_write(dsi, d, ARRAY_SIZE(d)); \ + if (ret < 0) \ + return ret; \ + } while (0) + +#define dsi_dcs_write_seq(dsi, seq...) do { \ + static const u8 d[] = { seq }; \ + int ret; \ + ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \ + if (ret < 0) \ + return ret; \ + } while (0) + +static void tm5p5_nt35596_reset(struct tm5p5_nt35596 *ctx) +{ + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + usleep_range(1000, 2000); + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + usleep_range(1000, 2000); + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + usleep_range(15000, 16000); +} + +static int tm5p5_nt35596_on(struct tm5p5_nt35596 *ctx) +{ + struct mipi_dsi_device *dsi = ctx->dsi; + + dsi_generic_write_seq(dsi, 0xff, 0x05); + dsi_generic_write_seq(dsi, 0xfb, 0x01); + dsi_generic_write_seq(dsi, 0xc5, 0x31); + dsi_generic_write_seq(dsi, 0xff, 0x04); + dsi_generic_write_seq(dsi, 0x01, 0x84); + dsi_generic_write_seq(dsi, 0x05, 0x25); + dsi_generic_write_seq(dsi, 0x06, 0x01); + dsi_generic_write_seq(dsi, 0x07, 0x20); + dsi_generic_write_seq(dsi, 0x08, 0x06); + dsi_generic_write_seq(dsi, 0x09, 0x08); + dsi_generic_write_seq(dsi, 0x0a, 0x10); + dsi_generic_write_seq(dsi, 0x0b, 0x10); + dsi_generic_write_seq(dsi, 0x0c, 0x10); + dsi_generic_write_seq(dsi, 0x0d, 0x14); + dsi_generic_write_seq(dsi, 0x0e, 0x14); + dsi_generic_write_seq(dsi, 0x0f, 0x14); + dsi_generic_write_seq(dsi, 0x10, 0x14); + dsi_generic_write_seq(dsi, 0x11, 0x14); + dsi_generic_write_seq(dsi, 0x12, 0x14); + dsi_generic_write_seq(dsi, 0x17, 0xf3); + dsi_generic_write_seq(dsi, 0x18, 0xc0); + dsi_generic_write_seq(dsi, 0x19, 0xc0); + dsi_generic_write_seq(dsi, 0x1a, 0xc0); + dsi_generic_write_seq(dsi, 0x1b, 0xb3); + dsi_generic_write_seq(dsi, 0x1c, 0xb3); + dsi_generic_write_seq(dsi, 0x1d, 0xb3); + dsi_generic_write_seq(dsi, 0x1e, 0xb3); + dsi_generic_write_seq(dsi, 0x1f, 0xb3); + dsi_generic_write_seq(dsi, 0x20, 0xb3); + dsi_generic_write_seq(dsi, 0xfb, 0x01); + dsi_generic_write_seq(dsi, 0xff, 0x00); + dsi_generic_write_seq(dsi, 0xfb, 0x01); + dsi_generic_write_seq(dsi, 0x35, 0x01); + dsi_generic_write_seq(dsi, 0xd3, 0x06); + dsi_generic_write_seq(dsi, 0xd4, 0x04); + dsi_generic_write_seq(dsi, 0x5e, 0x0d); + dsi_generic_write_seq(dsi, 0x11, 0x00); + msleep(100); + dsi_generic_write_seq(dsi, 0x29, 0x00); + dsi_generic_write_seq(dsi, 0x53, 0x24); + + return 0; +} + +static int tm5p5_nt35596_off(struct tm5p5_nt35596 *ctx) +{ + struct mipi_dsi_device *dsi = ctx->dsi; + struct device *dev = &dsi->dev; + int ret; + + ret = mipi_dsi_dcs_set_display_off(dsi); + if (ret < 0) { + dev_err(dev, "Failed to set display off: %d\n", ret); + return ret; + } + msleep(60); + + ret = mipi_dsi_dcs_enter_sleep_mode(dsi); + if (ret < 0) { + dev_err(dev, "Failed to enter sleep mode: %d\n", ret); + return ret; + } + + dsi_dcs_write_seq(dsi, 0x4f, 0x01); + + return 0; +} + +static int tm5p5_nt35596_prepare(struct drm_panel *panel) +{ + struct tm5p5_nt35596 *ctx = to_tm5p5_nt35596(panel); + struct device *dev = &ctx->dsi->dev; + int ret; + + if (ctx->prepared) + return 0; + + ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies); + if (ret < 0) { + dev_err(dev, "Failed to enable regulators: %d\n", ret); + return ret; + } + + tm5p5_nt35596_reset(ctx); + + ret = tm5p5_nt35596_on(ctx); + if (ret < 0) { + dev_err(dev, "Failed to initialize panel: %d\n", ret); + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), + ctx->supplies); + return ret; + } + + ctx->prepared = true; + return 0; +} + +static int tm5p5_nt35596_unprepare(struct drm_panel *panel) +{ + struct tm5p5_nt35596 *ctx = to_tm5p5_nt35596(panel); + struct device *dev = &ctx->dsi->dev; + int ret; + + if (!ctx->prepared) + return 0; + + ret = tm5p5_nt35596_off(ctx); + if (ret < 0) + dev_err(dev, "Failed to un-initialize panel: %d\n", ret); + + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), + ctx->supplies); + + ctx->prepared = false; + return 0; +} + +static const struct drm_display_mode tm5p5_nt35596_mode = { + .clock = (1080 + 100 + 8 + 16) * (1920 + 4 + 2 + 4) * 60 / 1000, + .hdisplay = 1080, + .hsync_start = 1080 + 100, + .hsync_end = 1080 + 100 + 8, + .htotal = 1080 + 100 + 8 + 16, + .vdisplay = 1920, + .vsync_start = 1920 + 4, + .vsync_end = 1920 + 4 + 2, + .vtotal = 1920 + 4 + 2 + 4, + .vrefresh = 60, + .width_mm = 68, + .height_mm = 121, +}; + +static int tm5p5_nt35596_get_modes(struct drm_panel *panel, + struct drm_connector *connector) +{ + struct drm_display_mode *mode; + + mode = drm_mode_duplicate(connector->dev, &tm5p5_nt35596_mode); + if (!mode) + return -ENOMEM; + + drm_mode_set_name(mode); + + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; + connector->display_info.width_mm = mode->width_mm; + connector->display_info.height_mm = mode->height_mm; + drm_mode_probed_add(connector, mode); + + return 1; +} + +static const struct drm_panel_funcs tm5p5_nt35596_panel_funcs = { + .prepare = tm5p5_nt35596_prepare, + .unprepare = tm5p5_nt35596_unprepare, + .get_modes = tm5p5_nt35596_get_modes, +}; + +static int tm5p5_nt35596_bl_update_status(struct backlight_device *bl) +{ + struct mipi_dsi_device *dsi = bl_get_data(bl); + u16 brightness = bl->props.brightness; + int ret; + + if (bl->props.power != FB_BLANK_UNBLANK || + bl->props.fb_blank != FB_BLANK_UNBLANK || + bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) + brightness = 0; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_set_display_brightness(dsi, brightness); + if (ret < 0) + return ret; + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + return 0; +} + +static int tm5p5_nt35596_bl_get_brightness(struct backlight_device *bl) +{ + struct mipi_dsi_device *dsi = bl_get_data(bl); + u16 brightness = bl->props.brightness; + int ret; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_get_display_brightness(dsi, &brightness); + if (ret < 0) + return ret; + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + return brightness & 0xff; +} + +static const struct backlight_ops tm5p5_nt35596_bl_ops = { + .update_status = tm5p5_nt35596_bl_update_status, + .get_brightness = tm5p5_nt35596_bl_get_brightness, +}; + +static struct backlight_device * +tm5p5_nt35596_create_backlight(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + const struct backlight_properties props = { + .type = BACKLIGHT_RAW, + .brightness = 255, + .max_brightness = 255, + }; + + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi, + &tm5p5_nt35596_bl_ops, &props); +} + +static int tm5p5_nt35596_probe(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + struct tm5p5_nt35596 *ctx; + int ret; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->supplies[0].supply = "vdd"; + ctx->supplies[1].supply = "vddio"; + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies), + ctx->supplies); + if (ret < 0) { + dev_err(dev, "Failed to get regulators: %d\n", ret); + return ret; + } + + ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(ctx->reset_gpio)) { + ret = PTR_ERR(ctx->reset_gpio); + dev_err(dev, "Failed to get reset-gpios: %d\n", ret); + return ret; + } + + ctx->dsi = dsi; + mipi_dsi_set_drvdata(dsi, ctx); + + dsi->lanes = 4; + dsi->format = MIPI_DSI_FMT_RGB888; + dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | + MIPI_DSI_MODE_VIDEO_HSE | MIPI_DSI_MODE_EOT_PACKET | + MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM; + + drm_panel_init(&ctx->panel, dev, &tm5p5_nt35596_panel_funcs, + DRM_MODE_CONNECTOR_DSI); + + ctx->panel.backlight = tm5p5_nt35596_create_backlight(dsi); + if (IS_ERR(ctx->panel.backlight)) { + ret = PTR_ERR(ctx->panel.backlight); + dev_err(dev, "Failed to create backlight: %d\n", ret); + return ret; + } + + ret = drm_panel_add(&ctx->panel); + if (ret < 0) { + dev_err(dev, "Failed to add panel: %d\n", ret); + return ret; + } + + ret = mipi_dsi_attach(dsi); + if (ret < 0) { + dev_err(dev, "Failed to attach to DSI host: %d\n", ret); + return ret; + } + + return 0; +} + +static int tm5p5_nt35596_remove(struct mipi_dsi_device *dsi) +{ + struct tm5p5_nt35596 *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); + + return 0; +} + +static const struct of_device_id tm5p5_nt35596_of_match[] = { + { .compatible = "asus,z00t-tm5p5-n35596" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, tm5p5_nt35596_of_match); + +static struct mipi_dsi_driver tm5p5_nt35596_driver = { + .probe = tm5p5_nt35596_probe, + .remove = tm5p5_nt35596_remove, + .driver = { + .name = "panel-tm5p5-nt35596", + .of_match_table = tm5p5_nt35596_of_match, + }, +}; +module_mipi_dsi_driver(tm5p5_nt35596_driver); + +MODULE_AUTHOR("Konrad Dybcio "); +MODULE_DESCRIPTION("DRM driver for tm5p5 nt35596 1080p video mode dsi panel"); +MODULE_LICENSE("GPL v2"); From 3a53230e1c4b8bb9058d12b4f7df742abc1105e8 Mon Sep 17 00:00:00 2001 From: Samuel Zou Date: Thu, 7 May 2020 10:40:06 +0800 Subject: [PATCH 04/21] drm/ast: Make ast_primary_plane_helper_atomic_update static Fix the following sparse warning: drivers/gpu/drm/ast/ast_mode.c:564:6: warning: symbol 'ast_primary_plane_helper_atomic_update' was not declared. Should it be static? Reported-by: Hulk Robot Signed-off-by: Samuel Zou Signed-off-by: Thomas Zimmermann Reviewed-by: Thomas Zimmermann Link: https://patchwork.freedesktop.org/patch/msgid/1588819206-11406-1-git-send-email-zou_wei@huawei.com --- drivers/gpu/drm/ast/ast_mode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c index 7062bcd78740..4ddf77045759 100644 --- a/drivers/gpu/drm/ast/ast_mode.c +++ b/drivers/gpu/drm/ast/ast_mode.c @@ -561,8 +561,9 @@ static int ast_primary_plane_helper_atomic_check(struct drm_plane *plane, return 0; } -void ast_primary_plane_helper_atomic_update(struct drm_plane *plane, - struct drm_plane_state *old_state) +static void +ast_primary_plane_helper_atomic_update(struct drm_plane *plane, + struct drm_plane_state *old_state) { struct ast_private *ast = plane->dev->dev_private; struct drm_plane_state *state = plane->state; From d6ddbd5c97d1b9156646ac5c42b8851edd664ee2 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 7 May 2020 11:06:40 +0200 Subject: [PATCH 05/21] drm/ast: Don't check new mode if CRTC is being disabled Suspending failed because there's no mode if the CRTC is being disabled. Early-out in this case. This fixes runtime PM for ast. v3: * fixed commit message v2: * added Tested-by/Reported-by tags * added Fixes tags and CC (Sam) * improved comment Signed-off-by: Thomas Zimmermann Reported-by: Cary Garrett Tested-by: Cary Garrett Reviewed-by: Daniel Vetter Fixes: b48e1b6ffd28 ("drm/ast: Add CRTC helpers for atomic modesetting") Cc: Thomas Zimmermann Cc: Gerd Hoffmann Cc: Dave Airlie Cc: Daniel Vetter Cc: Sam Ravnborg Cc: # v5.6+ Link: https://patchwork.freedesktop.org/patch/msgid/20200507090640.21561-1-tzimmermann@suse.de --- drivers/gpu/drm/ast/ast_mode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c index 4ddf77045759..7d39b858c9f1 100644 --- a/drivers/gpu/drm/ast/ast_mode.c +++ b/drivers/gpu/drm/ast/ast_mode.c @@ -802,6 +802,9 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc, return -EINVAL; } + if (!state->enable) + return 0; /* no mode checks if CRTC is being disabled */ + ast_state = to_ast_crtc_state(state); format = ast_state->format; From 50b6f619a099af6dfe06e958bfa08d46440ea788 Mon Sep 17 00:00:00 2001 From: Mika Kahola Date: Wed, 6 May 2020 15:08:27 +0300 Subject: [PATCH 06/21] uapi/drm/drm_fourcc.h: Note on platform specificity for format modifiers Make an additional note on DRM format modifiers for x and y tiling. These format modifiers are defined for BDW+ platforms and therefore definition is not valid for older gens. This is due to address swizzling for tiled surfaces is no longer used. For newer platforms main memory controller has a more effective address swizzling algorithm. v2: Rephrase comment (Daniel) Signed-off-by: Mika Kahola Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20200506120827.12250-1-mika.kahola@intel.com --- include/uapi/drm/drm_fourcc.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h index 8bc0b31597d8..9e488d10f8b4 100644 --- a/include/uapi/drm/drm_fourcc.h +++ b/include/uapi/drm/drm_fourcc.h @@ -354,9 +354,12 @@ extern "C" { * a platform-dependent stride. On top of that the memory can apply * platform-depending swizzling of some higher address bits into bit6. * - * This format is highly platforms specific and not useful for cross-driver - * sharing. It exists since on a given platform it does uniquely identify the - * layout in a simple way for i915-specific userspace. + * Note that this layout is only accurate on intel gen 8+ or valleyview chipsets. + * On earlier platforms the is highly platforms specific and not useful for + * cross-driver sharing. It exists since on a given platform it does uniquely + * identify the layout in a simple way for i915-specific userspace, which + * facilitated conversion of userspace to modifiers. Additionally the exact + * format on some really old platforms is not known. */ #define I915_FORMAT_MOD_X_TILED fourcc_mod_code(INTEL, 1) @@ -369,9 +372,12 @@ extern "C" { * memory can apply platform-depending swizzling of some higher address bits * into bit6. * - * This format is highly platforms specific and not useful for cross-driver - * sharing. It exists since on a given platform it does uniquely identify the - * layout in a simple way for i915-specific userspace. + * Note that this layout is only accurate on intel gen 8+ or valleyview chipsets. + * On earlier platforms the is highly platforms specific and not useful for + * cross-driver sharing. It exists since on a given platform it does uniquely + * identify the layout in a simple way for i915-specific userspace, which + * facilitated conversion of userspace to modifiers. Additionally the exact + * format on some really old platforms is not known. */ #define I915_FORMAT_MOD_Y_TILED fourcc_mod_code(INTEL, 2) From 9694d9c3b5a5bbebd8132b08503211f5752dc205 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Fri, 8 May 2020 15:59:00 -0700 Subject: [PATCH 07/21] panel: simple: Fix size and bpp of BOE NV133FHM-N61 The BOE NV133FHM-N61 is documented in the original commit to be a 13.3" panel, but the size listed in our struct doesn't match. Specifically: math.sqrt(30.0 * 30.0 + 18.7 * 18.7) / 2.54 ==> 13.92 Searching around on the Internet shows that the size that was in the structure was the "Outline Size", not the "Display Area". Let's fix it. Also the Internet says that this panel supports 262K colors. That's 6bpp, not 8bpp. Fixes: b0c664cc80e8 ("panel: simple: Add BOE NV133FHM-N61") Signed-off-by: Douglas Anderson Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200508155859.1.I4d29651c0837b4095fb4951253f44036a371732f@changeid --- drivers/gpu/drm/panel/panel-simple.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c index d6c29543e510..7219436499f1 100644 --- a/drivers/gpu/drm/panel/panel-simple.c +++ b/drivers/gpu/drm/panel/panel-simple.c @@ -1189,10 +1189,10 @@ static const struct drm_display_mode boe_nv133fhm_n61_modes = { static const struct panel_desc boe_nv133fhm_n61 = { .modes = &boe_nv133fhm_n61_modes, .num_modes = 1, - .bpc = 8, + .bpc = 6, .size = { - .width = 300, - .height = 187, + .width = 294, + .height = 165, }, .delay = { .hpd_absent_delay = 200, From 574a38ca06e60d854247d78af0f475a431051dde Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Fri, 8 May 2020 15:59:01 -0700 Subject: [PATCH 08/21] dt-bindings: display: simple: Add BOE NV133FHM-N62 This panel appears to be the same or nearly the same as the BOE NV133FHM-N61, but since (in the very least) it identifies itself as a different model in the EDID we should add a new compatible string for it. Signed-off-by: Douglas Anderson Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200508155859.2.I37c879ef4ec6d4028a3d45728bc3a58060bba175@changeid --- .../devicetree/bindings/display/panel/panel-simple.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/display/panel/panel-simple.yaml b/Documentation/devicetree/bindings/display/panel/panel-simple.yaml index fdd74d07f645..d6cca1479633 100644 --- a/Documentation/devicetree/bindings/display/panel/panel-simple.yaml +++ b/Documentation/devicetree/bindings/display/panel/panel-simple.yaml @@ -75,6 +75,8 @@ properties: - boe,nv101wxmn51 # BOE NV133FHM-N61 13.3" FHD (1920x1080) TFT LCD Panel - boe,nv133fhm-n61 + # BOE NV133FHM-N62 13.3" FHD (1920x1080) TFT LCD Panel + - boe,nv133fhm-n62 # BOE NV140FHM-N49 14.0" FHD a-Si FT panel - boe,nv140fhmn49 # CDTech(H.K.) Electronics Limited 4.3" 480x272 color TFT-LCD panel From cfe40d02238e7dae6f476974b022bdd36ebb96e5 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Fri, 8 May 2020 15:59:02 -0700 Subject: [PATCH 09/21] panel: simple: Add BOE NV133FHM-N62 All info I could find about this panel show that it behaves the same as the BOE NV133FHM-N61. However, it definitely appears to be a unique panel because reading the EDID shows "NV133FHM-N62". We'll add a string match for the new panel but until we find something unique about it we'll just point at the N61's structures. Signed-off-by: Douglas Anderson Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200508155859.3.I525ebd471f5340a6a369af7bde06ef04174d2f41@changeid --- drivers/gpu/drm/panel/panel-simple.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c index 7219436499f1..7fb7b257f968 100644 --- a/drivers/gpu/drm/panel/panel-simple.c +++ b/drivers/gpu/drm/panel/panel-simple.c @@ -1173,6 +1173,7 @@ static const struct panel_desc boe_nv101wxmn51 = { }, }; +/* Also used for boe_nv133fhm_n62 */ static const struct drm_display_mode boe_nv133fhm_n61_modes = { .clock = 147840, .hdisplay = 1920, @@ -1186,6 +1187,7 @@ static const struct drm_display_mode boe_nv133fhm_n61_modes = { .vrefresh = 60, }; +/* Also used for boe_nv133fhm_n62 */ static const struct panel_desc boe_nv133fhm_n61 = { .modes = &boe_nv133fhm_n61_modes, .num_modes = 1, @@ -3659,6 +3661,9 @@ static const struct of_device_id platform_of_match[] = { }, { .compatible = "boe,nv133fhm-n61", .data = &boe_nv133fhm_n61, + }, { + .compatible = "boe,nv133fhm-n62", + .data = &boe_nv133fhm_n61, }, { .compatible = "boe,nv140fhmn49", .data = &boe_nv140fhmn49, From d2528306528d6cca4e1608642a8efec95d7b13dd Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Thu, 7 May 2020 14:34:56 -0700 Subject: [PATCH 10/21] dt-bindings: display: Add hpd-gpios to panel-common bindings In the cases where there is no connector in a system there's no great place to put "hpd-gpios". As per discussion [1] the best place to put it is in the panel. Add this to the device tree bindings. [1] https://lore.kernel.org/r/20200417180819.GE5861@pendragon.ideasonboard.com Signed-off-by: Douglas Anderson Reviewed-by: Stephen Boyd Reviewed-by: Linus Walleij Reviewed-by: Laurent Pinchart Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200507143354.v5.2.I1976736b400a3b30e46efa47782248b86b3bc627@changeid --- .../devicetree/bindings/display/panel/panel-common.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/display/panel/panel-common.yaml b/Documentation/devicetree/bindings/display/panel/panel-common.yaml index 17b8367f12dd..a747b755ad06 100644 --- a/Documentation/devicetree/bindings/display/panel/panel-common.yaml +++ b/Documentation/devicetree/bindings/display/panel/panel-common.yaml @@ -96,6 +96,12 @@ properties: (hot plug detect) signal, but the signal isn't hooked up so we should hardcode the max delay from the panel spec when powering up the panel. + hpd-gpios: + maxItems: 1 + description: + If Hot Plug Detect (HPD) is connected to a GPIO in the system rather + than a dedicated HPD pin the pin can be specified here. + # Control I/Os # Many display panels can be controlled through pins driven by GPIOs. The nature From 48834e6084f185776b0c567d6f9b8e0b099f4b19 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Thu, 7 May 2020 14:34:57 -0700 Subject: [PATCH 11/21] drm/panel-simple: Support hpd-gpios for delaying prepare() People use panel-simple when they have panels that are builtin to their device. In these cases the HPD (Hot Plug Detect) signal isn't really used for hotplugging devices but instead is used for power sequencing. Panel timing diagrams (especially for eDP panels) usually have the HPD signal in them and it acts as an indicator that the panel is ready for us to talk to it. Sometimes the HPD signal is hooked up to a normal GPIO on a system. In this case we need to poll it in the correct place to know that the panel is ready for us. In some system designs the right place for this is panel-simple. When adding this support, we'll account for the case that there might be a circular dependency between panel-simple and the provider of the GPIO. The case this was designed for was for the "ti-sn65dsi86" bridge chip. If HPD is hooked up to one of the GPIOs provided by the bridge chip then in our probe function we'll always get back -EPROBE_DEFER. Let's handle this by allowing this GPIO to show up late if we saw -EPROBE_DEFER during probe. NOTE: since the gpio_get_optional() is used, if the "hpd-gpios" isn't there our variable will just be NULL and we won't do anything in prepare(). Signed-off-by: Douglas Anderson Reviewed-by: Stephen Boyd Reviewed-by: Linus Walleij Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200507143354.v5.3.I53fed5b501a31e7a7fa13268ebcdd6b77bd0cadd@changeid --- drivers/gpu/drm/panel/panel-simple.c | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c index 7fb7b257f968..b6ecd1552132 100644 --- a/drivers/gpu/drm/panel/panel-simple.c +++ b/drivers/gpu/drm/panel/panel-simple.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -108,6 +109,7 @@ struct panel_simple { struct i2c_adapter *ddc; struct gpio_desc *enable_gpio; + struct gpio_desc *hpd_gpio; struct drm_display_mode override_mode; }; @@ -259,11 +261,37 @@ static int panel_simple_unprepare(struct drm_panel *panel) return 0; } +static int panel_simple_get_hpd_gpio(struct device *dev, + struct panel_simple *p, bool from_probe) +{ + int err; + + p->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN); + if (IS_ERR(p->hpd_gpio)) { + err = PTR_ERR(p->hpd_gpio); + + /* + * If we're called from probe we won't consider '-EPROBE_DEFER' + * to be an error--we'll leave the error code in "hpd_gpio". + * When we try to use it we'll try again. This allows for + * circular dependencies where the component providing the + * hpd gpio needs the panel to init before probing. + */ + if (err != -EPROBE_DEFER || !from_probe) { + dev_err(dev, "failed to get 'hpd' GPIO: %d\n", err); + return err; + } + } + + return 0; +} + static int panel_simple_prepare(struct drm_panel *panel) { struct panel_simple *p = to_panel_simple(panel); unsigned int delay; int err; + int hpd_asserted; if (p->prepared) return 0; @@ -282,6 +310,26 @@ static int panel_simple_prepare(struct drm_panel *panel) if (delay) msleep(delay); + if (p->hpd_gpio) { + if (IS_ERR(p->hpd_gpio)) { + err = panel_simple_get_hpd_gpio(panel->dev, p, false); + if (err) + return err; + } + + err = readx_poll_timeout(gpiod_get_value_cansleep, p->hpd_gpio, + hpd_asserted, hpd_asserted, + 1000, 2000000); + if (hpd_asserted < 0) + err = hpd_asserted; + + if (err) { + dev_err(panel->dev, + "error waiting for hpd GPIO: %d\n", err); + return err; + } + } + p->prepared = true; return 0; @@ -462,6 +510,11 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc) panel->desc = desc; panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd"); + if (!panel->no_hpd) { + err = panel_simple_get_hpd_gpio(dev, panel, true); + if (err) + return err; + } panel->supply = devm_regulator_get(dev, "power"); if (IS_ERR(panel->supply)) From 7429e92386b2176bc5474626456a70e4e4b676ea Mon Sep 17 00:00:00 2001 From: Samuel Zou Date: Thu, 7 May 2020 10:49:28 +0800 Subject: [PATCH 12/21] drm/i2c/tda998x: Make tda998x_audio_digital_mute static Fix the following sparse warning: drivers/gpu/drm/i2c/tda998x_drv.c:1136:5: warning: symbol 'tda998x_audio_digital_mute' was not declared. Should it be static? Reported-by: Hulk Robot Signed-off-by: Samuel Zou Cc: Russell King Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/1588819768-11818-1-git-send-email-zou_wei@huawei.com --- drivers/gpu/drm/i2c/tda998x_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c index 3c90d7ae09d6..9517f522dcb9 100644 --- a/drivers/gpu/drm/i2c/tda998x_drv.c +++ b/drivers/gpu/drm/i2c/tda998x_drv.c @@ -1133,7 +1133,8 @@ static void tda998x_audio_shutdown(struct device *dev, void *data) mutex_unlock(&priv->audio_mutex); } -int tda998x_audio_digital_mute(struct device *dev, void *data, bool enable) +static int tda998x_audio_digital_mute(struct device *dev, void *data, + bool enable) { struct tda998x_priv *priv = dev_get_drvdata(dev); From 6e85bd73d50d674912618e3ed226b2f2a47a178a Mon Sep 17 00:00:00 2001 From: Jason Yan Date: Wed, 6 May 2020 14:17:45 +0800 Subject: [PATCH 13/21] video: fbdev: pxa168fb: make pxa168fb_init_mode() return void No other functions use the return value of pxa168fb_init_mode() and the return value is always 0 now. Make it return void. This fixes the following coccicheck warning: drivers/video/fbdev/pxa168fb.c:565:5-8: Unneeded variable: "ret". Return "0" on line 597 Signed-off-by: Jason Yan Signed-off-by: Sam Ravnborg [fixed indent] Link: https://patchwork.freedesktop.org/patch/msgid/20200506061745.19451-1-yanaijie@huawei.com --- drivers/video/fbdev/pxa168fb.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/video/fbdev/pxa168fb.c b/drivers/video/fbdev/pxa168fb.c index aef8a3042590..eedfbd3572a8 100644 --- a/drivers/video/fbdev/pxa168fb.c +++ b/drivers/video/fbdev/pxa168fb.c @@ -557,12 +557,11 @@ static const struct fb_ops pxa168fb_ops = { .fb_imageblit = cfb_imageblit, }; -static int pxa168fb_init_mode(struct fb_info *info, +static void pxa168fb_init_mode(struct fb_info *info, struct pxa168fb_mach_info *mi) { struct pxa168fb_info *fbi = info->par; struct fb_var_screeninfo *var = &info->var; - int ret = 0; u32 total_w, total_h, refresh; u64 div_result; const struct fb_videomode *m; @@ -593,8 +592,6 @@ static int pxa168fb_init_mode(struct fb_info *info, div_result = 1000000000000ll; do_div(div_result, total_w * total_h * refresh); var->pixclock = (u32)div_result; - - return ret; } static int pxa168fb_probe(struct platform_device *pdev) From 8d8ff2a9574e1a822cadf1c346a130f922ae546a Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 7 May 2020 11:03:10 +0200 Subject: [PATCH 14/21] drm/mgag200: Convert struct drm_device to struct mga_device with helper Mgag200 uses dev_private to look up struct mga_device for instances of struct drm_device. Use of dev_private is deprecated, so hide it in the helper function to_mga_device(). v2: * make to_mga_device() a function (Sam) Signed-off-by: Thomas Zimmermann Reviewed-by: Daniel Vetter Reviewed-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200507090315.21274-2-tzimmermann@suse.de --- drivers/gpu/drm/mgag200/mgag200_cursor.c | 4 ++-- drivers/gpu/drm/mgag200/mgag200_drv.c | 2 +- drivers/gpu/drm/mgag200/mgag200_drv.h | 5 +++++ drivers/gpu/drm/mgag200/mgag200_i2c.c | 10 +++++----- drivers/gpu/drm/mgag200/mgag200_main.c | 4 ++-- drivers/gpu/drm/mgag200/mgag200_mode.c | 18 +++++++++--------- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/mgag200/mgag200_cursor.c b/drivers/gpu/drm/mgag200/mgag200_cursor.c index d491edd317ff..aebc9ce43d55 100644 --- a/drivers/gpu/drm/mgag200/mgag200_cursor.c +++ b/drivers/gpu/drm/mgag200/mgag200_cursor.c @@ -260,7 +260,7 @@ int mgag200_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, uint32_t handle, uint32_t width, uint32_t height) { struct drm_device *dev = crtc->dev; - struct mga_device *mdev = (struct mga_device *)dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); struct drm_gem_object *obj; struct drm_gem_vram_object *gbo = NULL; int ret; @@ -307,7 +307,7 @@ int mgag200_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, int mgag200_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) { - struct mga_device *mdev = (struct mga_device *)crtc->dev->dev_private; + struct mga_device *mdev = to_mga_device(crtc->dev); /* Our origin is at (64,64) */ x += 64; diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag200/mgag200_drv.c index 3298b7ef18b0..c2f0e4b40b05 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.c +++ b/drivers/gpu/drm/mgag200/mgag200_drv.c @@ -120,7 +120,7 @@ int mgag200_driver_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args) { - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); unsigned long pg_align; if (WARN_ONCE(!dev->vram_mm, "VRAM MM not initialized")) diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h index 9691252d6233..93e2d232931a 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.h +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h @@ -182,6 +182,11 @@ struct mga_device { struct drm_encoder encoder; }; +static inline struct mga_device *to_mga_device(struct drm_device *dev) +{ + return dev->dev_private; +} + static inline enum mga_type mgag200_type_from_driver_data(kernel_ulong_t driver_data) { diff --git a/drivers/gpu/drm/mgag200/mgag200_i2c.c b/drivers/gpu/drm/mgag200/mgag200_i2c.c index 9f4635916d32..09731e614e46 100644 --- a/drivers/gpu/drm/mgag200/mgag200_i2c.c +++ b/drivers/gpu/drm/mgag200/mgag200_i2c.c @@ -61,34 +61,34 @@ static inline void mga_i2c_set(struct mga_device *mdev, int mask, int state) static void mga_gpio_setsda(void *data, int state) { struct mga_i2c_chan *i2c = data; - struct mga_device *mdev = i2c->dev->dev_private; + struct mga_device *mdev = to_mga_device(i2c->dev); mga_i2c_set(mdev, i2c->data, state); } static void mga_gpio_setscl(void *data, int state) { struct mga_i2c_chan *i2c = data; - struct mga_device *mdev = i2c->dev->dev_private; + struct mga_device *mdev = to_mga_device(i2c->dev); mga_i2c_set(mdev, i2c->clock, state); } static int mga_gpio_getsda(void *data) { struct mga_i2c_chan *i2c = data; - struct mga_device *mdev = i2c->dev->dev_private; + struct mga_device *mdev = to_mga_device(i2c->dev); return (mga_i2c_read_gpio(mdev) & i2c->data) ? 1 : 0; } static int mga_gpio_getscl(void *data) { struct mga_i2c_chan *i2c = data; - struct mga_device *mdev = i2c->dev->dev_private; + struct mga_device *mdev = to_mga_device(i2c->dev); return (mga_i2c_read_gpio(mdev) & i2c->clock) ? 1 : 0; } struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev) { - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); struct mga_i2c_chan *i2c; int ret; int data, clock; diff --git a/drivers/gpu/drm/mgag200/mgag200_main.c b/drivers/gpu/drm/mgag200/mgag200_main.c index b680cf47cbb9..b705b7776d2f 100644 --- a/drivers/gpu/drm/mgag200/mgag200_main.c +++ b/drivers/gpu/drm/mgag200/mgag200_main.c @@ -92,7 +92,7 @@ static int mga_vram_init(struct mga_device *mdev) static int mgag200_device_init(struct drm_device *dev, uint32_t flags) { - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); int ret, option; mdev->flags = mgag200_flags_from_driver_data(flags); @@ -195,7 +195,7 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) void mgag200_driver_unload(struct drm_device *dev) { - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); if (mdev == NULL) return; diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index d90e83959fca..fa91869c0db5 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -28,7 +28,7 @@ static void mga_crtc_load_lut(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); struct drm_framebuffer *fb = crtc->primary->fb; u16 *r_ptr, *g_ptr, *b_ptr; int i; @@ -728,7 +728,7 @@ static int mga_crtc_set_plls(struct mga_device *mdev, long clock) static void mga_g200wb_prepare(struct drm_crtc *crtc) { - struct mga_device *mdev = crtc->dev->dev_private; + struct mga_device *mdev = to_mga_device(crtc->dev); u8 tmp; int iter_max; @@ -783,7 +783,7 @@ static void mga_g200wb_prepare(struct drm_crtc *crtc) static void mga_g200wb_commit(struct drm_crtc *crtc) { u8 tmp; - struct mga_device *mdev = crtc->dev->dev_private; + struct mga_device *mdev = to_mga_device(crtc->dev); /* 1- The first step is to ensure that the vrsten and hrsten are set */ WREG8(MGAREG_CRTCEXT_INDEX, 1); @@ -833,7 +833,7 @@ static void mga_g200wb_commit(struct drm_crtc *crtc) */ static void mga_set_start_address(struct drm_crtc *crtc, unsigned offset) { - struct mga_device *mdev = crtc->dev->dev_private; + struct mga_device *mdev = to_mga_device(crtc->dev); u32 addr; int count; u8 crtcext0; @@ -902,7 +902,7 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc, int x, int y, struct drm_framebuffer *old_fb) { struct drm_device *dev = crtc->dev; - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); const struct drm_framebuffer *fb = crtc->primary->fb; int hdisplay, hsyncstart, hsyncend, htotal; int vdisplay, vsyncstart, vsyncend, vtotal; @@ -1263,7 +1263,7 @@ static int mga_resume(struct drm_crtc *crtc) static void mga_crtc_dpms(struct drm_crtc *crtc, int mode) { struct drm_device *dev = crtc->dev; - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); u8 seq1 = 0, crtcext1 = 0; switch (mode) { @@ -1317,7 +1317,7 @@ static void mga_crtc_dpms(struct drm_crtc *crtc, int mode) static void mga_crtc_prepare(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); u8 tmp; /* mga_resume(crtc);*/ @@ -1353,7 +1353,7 @@ static void mga_crtc_prepare(struct drm_crtc *crtc) static void mga_crtc_commit(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct mga_device *mdev = dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; u8 tmp; @@ -1495,7 +1495,7 @@ static enum drm_mode_status mga_vga_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode) { struct drm_device *dev = connector->dev; - struct mga_device *mdev = (struct mga_device*)dev->dev_private; + struct mga_device *mdev = to_mga_device(dev); int bpp = 32; if (IS_G200_SE(mdev)) { From ed5877b62ec4760f108e5b2b7bc40516638f4f5a Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 7 May 2020 11:03:11 +0200 Subject: [PATCH 15/21] drm/mgag200: Remove several references to struct mga_device.dev Done in preparation of embedding the DRM device in struct mga_device. This patch makes the patch for embedding more readable. v2: * improved commit message (Daniel) Signed-off-by: Thomas Zimmermann Reviewed-by: Daniel Vetter Reviewed-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200507090315.21274-3-tzimmermann@suse.de --- drivers/gpu/drm/mgag200/mgag200_main.c | 23 ++++++++++++----------- drivers/gpu/drm/mgag200/mgag200_mode.c | 17 +++++++++-------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/mgag200/mgag200_main.c b/drivers/gpu/drm/mgag200/mgag200_main.c index b705b7776d2f..51919b5c1d97 100644 --- a/drivers/gpu/drm/mgag200/mgag200_main.c +++ b/drivers/gpu/drm/mgag200/mgag200_main.c @@ -66,25 +66,26 @@ static int mga_probe_vram(struct mga_device *mdev, void __iomem *mem) /* Map the framebuffer from the card and configure the core */ static int mga_vram_init(struct mga_device *mdev) { + struct drm_device *dev = mdev->dev; void __iomem *mem; /* BAR 0 is VRAM */ - mdev->mc.vram_base = pci_resource_start(mdev->dev->pdev, 0); - mdev->mc.vram_window = pci_resource_len(mdev->dev->pdev, 0); + mdev->mc.vram_base = pci_resource_start(dev->pdev, 0); + mdev->mc.vram_window = pci_resource_len(dev->pdev, 0); - if (!devm_request_mem_region(mdev->dev->dev, mdev->mc.vram_base, mdev->mc.vram_window, - "mgadrmfb_vram")) { + if (!devm_request_mem_region(dev->dev, mdev->mc.vram_base, + mdev->mc.vram_window, "mgadrmfb_vram")) { DRM_ERROR("can't reserve VRAM\n"); return -ENXIO; } - mem = pci_iomap(mdev->dev->pdev, 0, 0); + mem = pci_iomap(dev->pdev, 0, 0); if (!mem) return -ENOMEM; mdev->mc.vram_size = mga_probe_vram(mdev, mem); - pci_iounmap(mdev->dev->pdev, mem); + pci_iounmap(dev->pdev, mem); return 0; } @@ -105,12 +106,12 @@ static int mgag200_device_init(struct drm_device *dev, mdev->has_sdram = !(option & (1 << 14)); /* BAR 0 is the framebuffer, BAR 1 contains registers */ - mdev->rmmio_base = pci_resource_start(mdev->dev->pdev, 1); - mdev->rmmio_size = pci_resource_len(mdev->dev->pdev, 1); + mdev->rmmio_base = pci_resource_start(dev->pdev, 1); + mdev->rmmio_size = pci_resource_len(dev->pdev, 1); - if (!devm_request_mem_region(mdev->dev->dev, mdev->rmmio_base, mdev->rmmio_size, - "mgadrmfb_mmio")) { - DRM_ERROR("can't reserve mmio registers\n"); + if (!devm_request_mem_region(dev->dev, mdev->rmmio_base, + mdev->rmmio_size, "mgadrmfb_mmio")) { + drm_err(dev, "can't reserve mmio registers\n"); return -ENOMEM; } diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index fa91869c0db5..aaa73b29b04f 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -1433,6 +1433,7 @@ static const struct drm_crtc_helper_funcs mga_helper_funcs = { /* CRTC setup */ static void mga_crtc_init(struct mga_device *mdev) { + struct drm_device *dev = mdev->dev; struct mga_crtc *mga_crtc; mga_crtc = kzalloc(sizeof(struct mga_crtc) + @@ -1442,7 +1443,7 @@ static void mga_crtc_init(struct mga_device *mdev) if (mga_crtc == NULL) return; - drm_crtc_init(mdev->dev, &mga_crtc->base, &mga_crtc_funcs); + drm_crtc_init(dev, &mga_crtc->base, &mga_crtc_funcs); drm_mode_crtc_set_gamma_size(&mga_crtc->base, MGAG200_LUT_SIZE); mdev->mode_info.crtc = mga_crtc; @@ -1617,30 +1618,30 @@ static struct drm_connector *mga_vga_init(struct drm_device *dev) int mgag200_modeset_init(struct mga_device *mdev) { + struct drm_device *dev = mdev->dev; struct drm_encoder *encoder = &mdev->encoder; struct drm_connector *connector; int ret; mdev->mode_info.mode_config_initialized = true; - mdev->dev->mode_config.max_width = MGAG200_MAX_FB_WIDTH; - mdev->dev->mode_config.max_height = MGAG200_MAX_FB_HEIGHT; + dev->mode_config.max_width = MGAG200_MAX_FB_WIDTH; + dev->mode_config.max_height = MGAG200_MAX_FB_HEIGHT; - mdev->dev->mode_config.fb_base = mdev->mc.vram_base; + dev->mode_config.fb_base = mdev->mc.vram_base; mga_crtc_init(mdev); - ret = drm_simple_encoder_init(mdev->dev, encoder, - DRM_MODE_ENCODER_DAC); + ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_DAC); if (ret) { - drm_err(mdev->dev, + drm_err(dev, "drm_simple_encoder_init() failed, error %d\n", ret); return ret; } encoder->possible_crtcs = 0x1; - connector = mga_vga_init(mdev->dev); + connector = mga_vga_init(dev); if (!connector) { DRM_ERROR("mga_vga_init failed\n"); return -1; From 0858083781b507acb99837d27e4071dc9b0bf976 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 7 May 2020 11:03:12 +0200 Subject: [PATCH 16/21] drm/mgag200: Integrate init function into load function Done to simplify initialization code before embedding the DRM device instance in struct mga_device. Signed-off-by: Thomas Zimmermann Reviewed-by: Daniel Vetter Acked-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200507090315.21274-4-tzimmermann@suse.de --- drivers/gpu/drm/mgag200/mgag200_main.c | 59 +++++++++----------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/drivers/gpu/drm/mgag200/mgag200_main.c b/drivers/gpu/drm/mgag200/mgag200_main.c index 51919b5c1d97..186197b8ffd3 100644 --- a/drivers/gpu/drm/mgag200/mgag200_main.c +++ b/drivers/gpu/drm/mgag200/mgag200_main.c @@ -90,12 +90,17 @@ static int mga_vram_init(struct mga_device *mdev) return 0; } -static int mgag200_device_init(struct drm_device *dev, - uint32_t flags) +int mgag200_driver_load(struct drm_device *dev, unsigned long flags) { - struct mga_device *mdev = to_mga_device(dev); + struct mga_device *mdev; int ret, option; + mdev = devm_kzalloc(dev->dev, sizeof(struct mga_device), GFP_KERNEL); + if (mdev == NULL) + return -ENOMEM; + dev->dev_private = (void *)mdev; + mdev->dev = dev; + mdev->flags = mgag200_flags_from_driver_data(flags); mdev->type = mgag200_type_from_driver_data(flags); @@ -122,8 +127,8 @@ static int mgag200_device_init(struct drm_device *dev, /* stash G200 SE model number for later use */ if (IS_G200_SE(mdev)) { mdev->unique_rev_id = RREG32(0x1e24); - DRM_DEBUG("G200 SE unique revision id is 0x%x\n", - mdev->unique_rev_id); + drm_dbg(dev, "G200 SE unique revision id is 0x%x\n", + mdev->unique_rev_id); } ret = mga_vram_init(mdev); @@ -134,33 +139,9 @@ static int mgag200_device_init(struct drm_device *dev, mdev->bpp_shifts[1] = 1; mdev->bpp_shifts[2] = 0; mdev->bpp_shifts[3] = 2; - return 0; -} -/* - * Functions here will be called by the core once it's bound the driver to - * a PCI device - */ - - -int mgag200_driver_load(struct drm_device *dev, unsigned long flags) -{ - struct mga_device *mdev; - int r; - - mdev = devm_kzalloc(dev->dev, sizeof(struct mga_device), GFP_KERNEL); - if (mdev == NULL) - return -ENOMEM; - dev->dev_private = (void *)mdev; - mdev->dev = dev; - - r = mgag200_device_init(dev, flags); - if (r) { - dev_err(&dev->pdev->dev, "Fatal error during GPU init: %d\n", r); - return r; - } - r = mgag200_mm_init(mdev); - if (r) + ret = mgag200_mm_init(mdev); + if (ret) goto err_mm; drm_mode_config_init(dev); @@ -171,16 +152,15 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) dev->mode_config.preferred_depth = 32; dev->mode_config.prefer_shadow = 1; - r = mgag200_modeset_init(mdev); - if (r) { - dev_err(&dev->pdev->dev, "Fatal error during modeset init: %d\n", r); + ret = mgag200_modeset_init(mdev); + if (ret) { + drm_err(dev, "Fatal error during modeset init: %d\n", ret); goto err_modeset; } - r = mgag200_cursor_init(mdev); - if (r) - dev_warn(&dev->pdev->dev, - "Could not initialize cursors. Not doing hardware cursors.\n"); + ret = mgag200_cursor_init(mdev); + if (ret) + drm_err(dev, "Could not initialize cursors. Not doing hardware cursors.\n"); return 0; @@ -190,8 +170,7 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) mgag200_mm_fini(mdev); err_mm: dev->dev_private = NULL; - - return r; + return ret; } void mgag200_driver_unload(struct drm_device *dev) From 5635b7cf8670367bbf32f8ef7e7d55e79bf227fc Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 7 May 2020 11:03:13 +0200 Subject: [PATCH 17/21] drm/mgag200: Use managed mode-config initialization Mode configuration is now cleanued up automatically. While at it, move all mode-config code into mgag200_mode.c. Done in preparation of switching mgag200 to simple-KMS helpers. v2: * improve commit message (Sam) * rebased during cherry pick * also move bpp_shift initialization Signed-off-by: Thomas Zimmermann Acked-by: Sam Ravnborg Tested-by: John Donnelly Link: https://patchwork.freedesktop.org/patch/msgid/20200507090315.21274-5-tzimmermann@suse.de --- drivers/gpu/drm/mgag200/mgag200_drv.h | 1 - drivers/gpu/drm/mgag200/mgag200_main.c | 28 ++------------------- drivers/gpu/drm/mgag200/mgag200_mode.c | 34 ++++++++++++++++++++++---- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h index 93e2d232931a..65d7096cad88 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.h +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h @@ -201,7 +201,6 @@ mgag200_flags_from_driver_data(kernel_ulong_t driver_data) /* mgag200_mode.c */ int mgag200_modeset_init(struct mga_device *mdev); -void mgag200_modeset_fini(struct mga_device *mdev); /* mgag200_main.c */ int mgag200_driver_load(struct drm_device *dev, unsigned long flags); diff --git a/drivers/gpu/drm/mgag200/mgag200_main.c b/drivers/gpu/drm/mgag200/mgag200_main.c index 186197b8ffd3..fd651eda6f01 100644 --- a/drivers/gpu/drm/mgag200/mgag200_main.c +++ b/drivers/gpu/drm/mgag200/mgag200_main.c @@ -10,15 +10,8 @@ #include -#include -#include - #include "mgag200_drv.h" -static const struct drm_mode_config_funcs mga_mode_funcs = { - .fb_create = drm_gem_fb_create -}; - static int mga_probe_vram(struct mga_device *mdev, void __iomem *mem) { int offset; @@ -135,27 +128,14 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) if (ret) return ret; - mdev->bpp_shifts[0] = 0; - mdev->bpp_shifts[1] = 1; - mdev->bpp_shifts[2] = 0; - mdev->bpp_shifts[3] = 2; - ret = mgag200_mm_init(mdev); if (ret) goto err_mm; - drm_mode_config_init(dev); - dev->mode_config.funcs = (void *)&mga_mode_funcs; - if (IS_G200_SE(mdev) && mdev->vram_fb_available < (2048*1024)) - dev->mode_config.preferred_depth = 16; - else - dev->mode_config.preferred_depth = 32; - dev->mode_config.prefer_shadow = 1; - ret = mgag200_modeset_init(mdev); if (ret) { drm_err(dev, "Fatal error during modeset init: %d\n", ret); - goto err_modeset; + goto err_mgag200_mm_fini; } ret = mgag200_cursor_init(mdev); @@ -164,9 +144,7 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) return 0; -err_modeset: - drm_mode_config_cleanup(dev); - mgag200_cursor_fini(mdev); +err_mgag200_mm_fini: mgag200_mm_fini(mdev); err_mm: dev->dev_private = NULL; @@ -179,8 +157,6 @@ void mgag200_driver_unload(struct drm_device *dev) if (mdev == NULL) return; - mgag200_modeset_fini(mdev); - drm_mode_config_cleanup(dev); mgag200_cursor_fini(mdev); mgag200_mm_fini(mdev); dev->dev_private = NULL; diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index aaa73b29b04f..7dad38691326 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -1615,6 +1616,17 @@ static struct drm_connector *mga_vga_init(struct drm_device *dev) return connector; } +static const struct drm_mode_config_funcs mgag200_mode_config_funcs = { + .fb_create = drm_gem_fb_create +}; + +static unsigned int mgag200_preferred_depth(struct mga_device *mdev) +{ + if (IS_G200_SE(mdev) && mdev->vram_fb_available < (2048*1024)) + return 16; + else + return 32; +} int mgag200_modeset_init(struct mga_device *mdev) { @@ -1623,13 +1635,30 @@ int mgag200_modeset_init(struct mga_device *mdev) struct drm_connector *connector; int ret; + mdev->bpp_shifts[0] = 0; + mdev->bpp_shifts[1] = 1; + mdev->bpp_shifts[2] = 0; + mdev->bpp_shifts[3] = 2; + + ret = drmm_mode_config_init(dev); + if (ret) { + drm_err(dev, "drmm_mode_config_init() failed, error %d\n", + ret); + return ret; + } + mdev->mode_info.mode_config_initialized = true; dev->mode_config.max_width = MGAG200_MAX_FB_WIDTH; dev->mode_config.max_height = MGAG200_MAX_FB_HEIGHT; + dev->mode_config.preferred_depth = mgag200_preferred_depth(mdev); + dev->mode_config.prefer_shadow = 1; + dev->mode_config.fb_base = mdev->mc.vram_base; + dev->mode_config.funcs = &mgag200_mode_config_funcs; + mga_crtc_init(mdev); ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_DAC); @@ -1651,8 +1680,3 @@ int mgag200_modeset_init(struct mga_device *mdev) return 0; } - -void mgag200_modeset_fini(struct mga_device *mdev) -{ - -} From 30b0c940f94137d1b61f59498ea97c66cf956cd2 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 7 May 2020 11:03:14 +0200 Subject: [PATCH 18/21] drm/mgag200: Remove unused fields from struct mga_device The fields mode_info, num_crtcs and mode in struct mga_device serve no purpose. Remove them. Signed-off-by: Thomas Zimmermann Acked-by: Sam Ravnborg Tested-by: John Donnelly Link: https://patchwork.freedesktop.org/patch/msgid/20200507090315.21274-6-tzimmermann@suse.de --- drivers/gpu/drm/mgag200/mgag200_drv.h | 8 -------- drivers/gpu/drm/mgag200/mgag200_main.c | 3 --- drivers/gpu/drm/mgag200/mgag200_mode.c | 6 ------ 3 files changed, 17 deletions(-) diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h index 65d7096cad88..40e6ffbe9794 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.h +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h @@ -104,11 +104,6 @@ struct mga_crtc { bool enabled; }; -struct mga_mode_info { - bool mode_config_initialized; - struct mga_crtc *crtc; -}; - struct mga_i2c_chan { struct i2c_adapter adapter; struct drm_device *dev; @@ -160,17 +155,14 @@ struct mga_device { void __iomem *rmmio; struct mga_mc mc; - struct mga_mode_info mode_info; struct mga_cursor cursor; size_t vram_fb_available; bool suspended; - int num_crtc; enum mga_type type; int has_sdram; - struct drm_display_mode mode; int bpp_shifts[4]; diff --git a/drivers/gpu/drm/mgag200/mgag200_main.c b/drivers/gpu/drm/mgag200/mgag200_main.c index fd651eda6f01..86df799fd38c 100644 --- a/drivers/gpu/drm/mgag200/mgag200_main.c +++ b/drivers/gpu/drm/mgag200/mgag200_main.c @@ -97,9 +97,6 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) mdev->flags = mgag200_flags_from_driver_data(flags); mdev->type = mgag200_type_from_driver_data(flags); - /* Hardcode the number of CRTCs to 1 */ - mdev->num_crtc = 1; - pci_read_config_dword(dev->pdev, PCI_MGA_OPTION, &option); mdev->has_sdram = !(option & (1 << 14)); diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index 7dad38691326..1d1e937203fa 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -1136,9 +1136,6 @@ static int mga_crtc_mode_set(struct drm_crtc *crtc, WREG8(MGA_MISC_OUT, misc); - if (adjusted_mode) - memcpy(&mdev->mode, mode, sizeof(struct drm_display_mode)); - mga_crtc_do_set_base(crtc, old_fb, x, y, 0); /* reset tagfifo */ @@ -1447,7 +1444,6 @@ static void mga_crtc_init(struct mga_device *mdev) drm_crtc_init(dev, &mga_crtc->base, &mga_crtc_funcs); drm_mode_crtc_set_gamma_size(&mga_crtc->base, MGAG200_LUT_SIZE); - mdev->mode_info.crtc = mga_crtc; drm_crtc_helper_add(&mga_crtc->base, &mga_helper_funcs); } @@ -1647,8 +1643,6 @@ int mgag200_modeset_init(struct mga_device *mdev) return ret; } - mdev->mode_info.mode_config_initialized = true; - dev->mode_config.max_width = MGAG200_MAX_FB_WIDTH; dev->mode_config.max_height = MGAG200_MAX_FB_HEIGHT; From 81a15b9a65565dc819c909512c9d83620b33e7ec Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 7 May 2020 11:03:15 +0200 Subject: [PATCH 19/21] drm/mgag200: Embed connector instance in struct mga_device Storing the connector instance in struct mga_device avoids some dynamic memory allocation. On errors, the connector's initializer function now destroys the i2c structure. Done in preparation of converting mgag200 to simple-KMS helpers. v2: * improved commit message (Michael) * fixed error message for mgag200_vga_connector_init() (Sam) Signed-off-by: Thomas Zimmermann Reviewed-by: Michael J. Ruhl Acked-by: Sam Ravnborg Tested-by: John Donnelly Link: https://patchwork.freedesktop.org/patch/msgid/20200507090315.21274-7-tzimmermann@suse.de --- drivers/gpu/drm/mgag200/mgag200_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_mode.c | 56 +++++++++++++++----------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h index 40e6ffbe9794..d9b7e96b214f 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.h +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h @@ -171,6 +171,7 @@ struct mga_device { /* SE model number stored in reg 0x1e24 */ u32 unique_rev_id; + struct mga_connector connector; struct drm_encoder encoder; }; diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index 1d1e937203fa..5f4ac36a9776 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -1448,6 +1448,10 @@ static void mga_crtc_init(struct mga_device *mdev) drm_crtc_helper_add(&mga_crtc->base, &mga_helper_funcs); } +/* + * Connector + */ + static int mga_vga_get_modes(struct drm_connector *connector) { struct mga_connector *mga_connector = to_mga_connector(connector); @@ -1572,7 +1576,6 @@ static void mga_connector_destroy(struct drm_connector *connector) struct mga_connector *mga_connector = to_mga_connector(connector); mgag200_i2c_destroy(mga_connector->i2c); drm_connector_cleanup(connector); - kfree(connector); } static const struct drm_connector_helper_funcs mga_vga_connector_helper_funcs = { @@ -1586,30 +1589,33 @@ static const struct drm_connector_funcs mga_vga_connector_funcs = { .destroy = mga_connector_destroy, }; -static struct drm_connector *mga_vga_init(struct drm_device *dev) +static int mgag200_vga_connector_init(struct mga_device *mdev) { - struct drm_connector *connector; - struct mga_connector *mga_connector; + struct drm_device *dev = mdev->dev; + struct mga_connector *mconnector = &mdev->connector; + struct drm_connector *connector = &mconnector->base; + struct mga_i2c_chan *i2c; + int ret; - mga_connector = kzalloc(sizeof(struct mga_connector), GFP_KERNEL); - if (!mga_connector) - return NULL; - - connector = &mga_connector->base; - mga_connector->i2c = mgag200_i2c_create(dev); - if (!mga_connector->i2c) - DRM_ERROR("failed to add ddc bus\n"); - - drm_connector_init_with_ddc(dev, connector, - &mga_vga_connector_funcs, - DRM_MODE_CONNECTOR_VGA, - &mga_connector->i2c->adapter); + i2c = mgag200_i2c_create(dev); + if (!i2c) + drm_warn(dev, "failed to add DDC bus\n"); + ret = drm_connector_init_with_ddc(dev, connector, + &mga_vga_connector_funcs, + DRM_MODE_CONNECTOR_VGA, + &i2c->adapter); + if (ret) + goto err_mgag200_i2c_destroy; drm_connector_helper_add(connector, &mga_vga_connector_helper_funcs); - drm_connector_register(connector); + mconnector->i2c = i2c; - return connector; + return 0; + +err_mgag200_i2c_destroy: + mgag200_i2c_destroy(i2c); + return ret; } static const struct drm_mode_config_funcs mgag200_mode_config_funcs = { @@ -1628,7 +1634,7 @@ int mgag200_modeset_init(struct mga_device *mdev) { struct drm_device *dev = mdev->dev; struct drm_encoder *encoder = &mdev->encoder; - struct drm_connector *connector; + struct drm_connector *connector = &mdev->connector.base; int ret; mdev->bpp_shifts[0] = 0; @@ -1664,10 +1670,12 @@ int mgag200_modeset_init(struct mga_device *mdev) } encoder->possible_crtcs = 0x1; - connector = mga_vga_init(dev); - if (!connector) { - DRM_ERROR("mga_vga_init failed\n"); - return -1; + ret = mgag200_vga_connector_init(mdev); + if (ret) { + drm_err(dev, + "mgag200_vga_connector_init() failed, error %d\n", + ret); + return ret; } drm_connector_attach_encoder(connector, encoder); From 761e9f4f80a21a4b845097027030bef863001636 Mon Sep 17 00:00:00 2001 From: Wei Yongjun Date: Thu, 30 Apr 2020 07:31:45 +0000 Subject: [PATCH 20/21] drm/mcde: dsi: Fix return value check in mcde_dsi_bind() The of_drm_find_bridge() function returns NULL on error, it doesn't return error pointers so this check doesn't work. Fixes: 5fc537bfd000 ("drm/mcde: Add new driver for ST-Ericsson MCDE") Signed-off-by: Wei Yongjun Signed-off-by: Linus Walleij Link: https://patchwork.freedesktop.org/patch/msgid/20200430073145.52321-1-weiyongjun1@huawei.com --- drivers/gpu/drm/mcde/mcde_dsi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/mcde/mcde_dsi.c b/drivers/gpu/drm/mcde/mcde_dsi.c index 1baa2324cdb9..f303369305a3 100644 --- a/drivers/gpu/drm/mcde/mcde_dsi.c +++ b/drivers/gpu/drm/mcde/mcde_dsi.c @@ -1073,10 +1073,9 @@ static int mcde_dsi_bind(struct device *dev, struct device *master, panel = NULL; bridge = of_drm_find_bridge(child); - if (IS_ERR(bridge)) { - dev_err(dev, "failed to find bridge (%ld)\n", - PTR_ERR(bridge)); - return PTR_ERR(bridge); + if (!bridge) { + dev_err(dev, "failed to find bridge\n"); + return -EINVAL; } } } From 1c530d431c698f156538b8954b07df95337beb34 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 13 May 2020 08:47:47 +0100 Subject: [PATCH 21/21] dma-buf: Use atomic_fetch_add() for the context id Now that atomic64_fetch_add() exists we can use it to return the base context id, rather than the atomic64_add_return(N) - N concoction. Suggested-by: Mika Kuoppala Signed-off-by: Chris Wilson Cc: Mika Kuoppala Reviewed-by: Maciej Patelczyk Link: https://patchwork.freedesktop.org/patch/msgid/20200513074809.18194-2-chris@chris-wilson.co.uk --- drivers/dma-buf/dma-fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 052a41e2451c..90edf2b281b0 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -106,7 +106,7 @@ EXPORT_SYMBOL(dma_fence_get_stub); u64 dma_fence_context_alloc(unsigned num) { WARN_ON(!num); - return atomic64_add_return(num, &dma_fence_context_counter) - num; + return atomic64_fetch_add(num, &dma_fence_context_counter); } EXPORT_SYMBOL(dma_fence_context_alloc);