drm/udl: Better modesetting, hot-unplug, protocol
Subsystems (3)
Thomas Zimmermann
maintainercover drm/udl: Better modesetting, hot-unplug, protocol
This patchset reworks the udl driver's modesetting code.
Patches #1 to #5 improve the connector code with various updates.
Patches #6 to #10 improve the modesetting code. Patch #7 replaces the simple-KMS helpers with the regular atomic helpers. Patch #9 adds DRM hot-unplugging. The driver had some unplugging support via USB functions, the DRM side was probably not prepared yet. Patch #10 changes damage updates to the damage iterator. This minimizes the amount of data to send over USB.
Patches #11 to #16 add protocol constants for the various UDL display operations.
Tested with X11, console and Weston.
Thomas Zimmermann (16):
drm/udl: Rename struct udl_drm_connector to struct udl_connector drm/udl: Test pixel limit in mode-config's mode-valid function drm/udl: Use USB timeout constant when reading EDID drm/udl: Various improvements to the connector drm/udl: Move connector to modesetting code
drm/udl: Remove udl_simple_display_pipe_mode_valid() drm/udl: Convert to atomic-modesetting helpers drm/udl: Simplify modesetting in CRTC's enable function drm/udl: Support DRM hot-unplugging
drm/udl: Use damage iterator
drm/udl: Move register constants to udl_proto.h drm/udl: Add constants for display-mode registers drm/udl: Add register constants for color depth drm/udl: Add register constants for video locks drm/udl: Add register constants for framebuffer scanout addresses drm/udl: Add constants for commands
drivers/gpu/drm/udl/Makefile | 2 +- drivers/gpu/drm/udl/udl_connector.c | 139 ------- drivers/gpu/drm/udl/udl_connector.h | 15 - drivers/gpu/drm/udl/udl_drv.h | 42 +-- drivers/gpu/drm/udl/udl_modeset.c | 567 ++++++++++++++++++---------- drivers/gpu/drm/udl/udl_proto.h | 62 +++ drivers/gpu/drm/udl/udl_transfer.c | 7 +- 7 files changed, 450 insertions(+), 384 deletions(-) delete mode 100644 drivers/gpu/drm/udl/udl_connector.c delete mode 100644 drivers/gpu/drm/udl/udl_connector.h create mode 100644 drivers/gpu/drm/udl/udl_proto.h
base-commit: d8deedaa0fcd8192715a052a0239bee3f74a8fb1
Signature · 1 line
2.37.3
Thomas Zimmermann
maintainerPATCH 1/16 drm/udl: Rename struct udl_drm_connector to struct udl_connector
Remove the _drm_ infix from struct udl_drm_connector and introduce a macro for upcasting from struct drm_connector. No functional changes.
--- drivers/gpu/drm/udl/udl_connector.c | 19 +++++-------------- drivers/gpu/drm/udl/udl_connector.h | 10 ++++++++-- 2 files changed, 13 insertions(+), 16 deletions(-)
drivers/gpu/drm/udl/udl_connector.c +5 -14
@@ -46,10 +46,7 @@ static int udl_get_edid_block(void *data, u8 *buf, unsigned int block,static int udl_get_modes (struct drm_connector *connector) { -struct udl_drm_connector *udl_connector = -container_of (connector, - struct udl_drm_connector, - connector); +struct udl_connector *udl_connector =to_udl_connector (connector);drm_connector_update_edid_property (connector, udl_connector->edid);if (udl_connector->edid)
@@ -74,10 +71,7 @@ static enum drm_connector_status udl_detect(struct drm_connector *connector, bool force) {struct udl_device *udl =to_udl (connector->dev); -struct udl_drm_connector *udl_connector = -container_of (connector, - struct udl_drm_connector, - connector); +struct udl_connector *udl_connector =to_udl_connector (connector);/* cleanup previous edid */ if (udl_connector->edid !=NULL ) {
@@ -94,10 +88,7 @@ udl_detect(struct drm_connector *connector, bool force)static void udl_connector_destroy (struct drm_connector *connector) { -struct udl_drm_connector *udl_connector = -container_of (connector, - struct udl_drm_connector, - connector); +struct udl_connector *udl_connector =to_udl_connector (connector);drm_connector_cleanup (connector);kfree (udl_connector->edid);
@@ -120,10 +111,10 @@ static const struct drm_connector_funcs udl_connector_funcs = {struct drm_connector *udl_connector_init (struct drm_device *dev) { -struct udl_drm_connector *udl_connector; +struct udl_connector *udl_connector;struct drm_connector *connector; - udl_connector =kzalloc (sizeof (struct udl_drm_connector ),GFP_KERNEL ); + udl_connector =kzalloc (sizeof (*udl_connector),GFP_KERNEL );if (!udl_connector)return ERR_PTR (-ENOMEM );
drivers/gpu/drm/udl/udl_connector.h +8 -2
@@ -1,15 +1,21 @@#ifndef __UDL_CONNECTOR_H__#define __UDL_CONNECTOR_H__ -#include <drm/drm_crtc.h> +#include <linux/container_of.h> + +#include <drm/drm_connector.h> struct edid ; -struct udl_drm_connector { +struct udl_connector {struct drm_connector connector;/* last udl_detect edid */ struct edid *edid; }; +static inline struct udl_connector *to_udl_connector (struct drm_connector *connector) +{ + return container_of(connector, struct udl_connector, connector); +}#endif //__UDL_CONNECTOR_H__
Signature · 1 line
2.37.3
Re: [PATCH 01/16] drm/udl: Rename struct udl_drm_connector to struct udl_connector
Hello Thomas,
Quoted 5 lines · Thomas Zimmermann
Remove the _drm_ infix from struct
udl_drm_connectorand introduce a macro for upcasting from structdrm_connector. No functional changes.Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 2/16 drm/udl: Test pixel limit in mode-config's mode-valid function
In reply to Thomas ZimmermannThe sku_pixel_limit is a per-device property, similar to the amount of available video memory. Move the respective mode-valid test from the connector to the mode-config structure.
--- drivers/gpu/drm/udl/udl_connector.c | 14 -------------- drivers/gpu/drm/udl/udl_modeset.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/udl/udl_connector.c +0 -14
@@ -54,19 +54,6 @@ static int udl_get_modes(struct drm_connector *connector)return 0 ; } -static enum drm_mode_status udl_mode_valid (struct drm_connector *connector, -struct drm_display_mode *mode) -{ -struct udl_device *udl =to_udl (connector->dev); -if (!udl->sku_pixel_limit) -return 0 ; - -if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit) -return MODE_VIRTUAL_Y ; - -return 0 ; -} -static enum drm_connector_status udl_detect (struct drm_connector *connector,bool force) {
@@ -97,7 +84,6 @@ static void udl_connector_destroy(struct drm_connector *connector)static const struct drm_connector_helper_funcs udl_connector_helper_funcs = { .get_modes = udl_get_modes, - .mode_valid = udl_mode_valid, };static const struct drm_connector_funcs udl_connector_funcs = {
drivers/gpu/drm/udl/udl_modeset.c +14 -0
@@ -407,8 +407,22 @@ static const struct drm_simple_display_pipe_funcs udl_simple_display_pipe_funcs* Modesetting */ +static enum drm_mode_status udl_mode_config_mode_valid (struct drm_device *dev, +const struct drm_display_mode *mode) +{ +struct udl_device *udl =to_udl (dev); + +if (udl->sku_pixel_limit) { +if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit) +return MODE_MEM ; + } + +return MODE_OK ; +} +static const struct drm_mode_config_funcs udl_mode_funcs = { .fb_create = drm_gem_fb_create_with_dirty, + .mode_valid = udl_mode_config_mode_valid, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit, };
Signature · 1 line
2.37.3
Re: [PATCH 02/16] drm/udl: Test pixel limit in mode-config's mode-valid function
Quoted 6 lines · Thomas Zimmermann
The
sku_pixel_limitis a per-device property, similar to the amount of available video memory. Move the respective mode-valid test from the connector to the mode-config structure.Signed-off-by Thomas Zimmermann <[email protected]>---
[...]
Quoted 9 lines
drivers/gpu/drm/udl/udl_modeset.c +9
-0+static enum drm_mode_status udl_mode_config_mode_valid (struct drm_device *dev, +const struct drm_display_mode *mode) +{ +struct udl_device *udl =to_udl (dev); + +if (udl->sku_pixel_limit) { +if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit) +return MODE_MEM ; + }
drivers/gpu/drm/udl/udl_modeset.c static const struct drm_simple_display_pipe_funcs udl_simple_display_pipe_funcs · line 428
Quoted 10 lines
drivers/gpu/drm/udl/udl_modeset.c +5
-0+ +return MODE_OK ; +} +static const struct drm_mode_config_funcs udl_mode_funcs = { .fb_create = drm_gem_fb_create_with_dirty, + .mode_valid = udl_mode_config_mode_valid, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit, };
It's always confusing to me whether something has to be in the .mode_valid for drm_mode_config helper function or for the drm_crtc_helper_funcs. This driver is still using the simple-KMS at this point so that will be in the udl_simple_display_pipe_mode_valid() if should be the latter.
In this case since it seems to be about a pixel limit, it might make sense to have this constraint for the DRM mode config. But since it depends on the {h,v}display, I thought that needed to ask if instead should be for the CRTC.
Any in case,
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerRe: [PATCH 02/16] drm/udl: Test pixel limit in mode-config's mode-valid function
Hi
Am 29.09.22 um 15:20 schrieb Javier Martinez Canillas:
Quoted 35 lines · Thomas Zimmermann
Quoted 6 lines
The
sku_pixel_limitis a per-device property, similar to the amount of available video memory. Move the respective mode-valid test from the connector to the mode-config structure.Signed-off-by Thomas Zimmermann <[email protected]>---
[...]
Quoted 9 lines
drivers/gpu/drm/udl/udl_modeset.c +9
-0+static enum drm_mode_status udl_mode_config_mode_valid (struct drm_device *dev, +const struct drm_display_mode *mode) +{ +struct udl_device *udl =to_udl (dev); + +if (udl->sku_pixel_limit) { +if (mode->vdisplay * mode->hdisplay > udl->sku_pixel_limit) +return MODE_MEM ; + }drivers/gpu/drm/udl/udl_modeset.c static const struct drm_simple_display_pipe_funcs udl_simple_display_pipe_funcs · line 428
Quoted 10 lines
drivers/gpu/drm/udl/udl_modeset.c +5
-0+ +return MODE_OK ; +} +static const struct drm_mode_config_funcs udl_mode_funcs = { .fb_create = drm_gem_fb_create_with_dirty, + .mode_valid = udl_mode_config_mode_valid, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit, };It's always confusing to me whether something has to be in the .mode_valid for
drm_mode_confighelper function or for thedrm_crtc_helper_funcs. This driver is still using the simple-KMS at this point so that will be in theudl_simple_display_pipe_mode_valid()if should be the latter.
Quoted 3 lines
In this case since it seems to be about a pixel limit, it might make sense to have this constraint for the DRM mode config. But since it depends on the {h,v}display, I thought that needed to ask if instead should be for the CRTC.
We're testing modes against limitations of the driver or hardware. The rule of thumb is to use the mode_valid function of the component that imposes the limitation. In the case at hand, the limit is the maximum number of pixels that the adapter can store. So it goes into the device-wide mode_valid.
Best regards
Thomas
Quoted 5 lines
Any in case,
Reviewed-by Javier Martinez Canillas <[email protected]>
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Thomas Zimmermann
maintainerPATCH 3/16 drm/udl: Use USB timeout constant when reading EDID
In reply to Thomas ZimmermannSet the USB control-message timeout to the USB default of 5 seconds. Done for consistency with other uses of usb_control_msg() in udl and other drivers.
--- drivers/gpu/drm/udl/udl_connector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/udl/udl_connector.c +1 -1
@@ -31,7 +31,7 @@ static int udl_get_edid_block(void *data, u8 *buf, unsigned int block,int bval = (i + block *EDID_LENGTH ) <<8 ; ret =usb_control_msg (udev,usb_rcvctrlpipe (udev,0 ),0x02 , (0x80 | (0x02 <<5 )), bval, -0xA1 , read_buff,2 ,1000 ); +0xA1 , read_buff,2 ,USB_CTRL_GET_TIMEOUT );if (ret <1 ) {DRM_ERROR ("Read EDID byte %d failed err %x\n" , i, ret);kfree (read_buff);
Signature · 1 line
2.37.3
Re: [PATCH 03/16] drm/udl: Use USB timeout constant when reading EDID
Quoted 14 lines · Thomas Zimmermann
Set the USB control-message timeout to the USB default of 5 seconds. Done for consistency with other uses of
usb_control_msg()in udl and other drivers.Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/udl/udl_connector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/udl/udl_connector.c +0
-0
drivers/gpu/drm/udl/udl_connector.c static int udl_get_edid_block(void *data, u8 *buf, unsigned int block, · line 34
Quoted 5 lines
drivers/gpu/drm/udl/udl_connector.c +1
-1@@ -31,7 +31,7 @@ static int udl_get_edid_block(void *data, u8 *buf, unsigned int block,int bval = (i + block *EDID_LENGTH ) <<8 ; ret =usb_control_msg (udev,usb_rcvctrlpipe (udev,0 ),0x02 , (0x80 | (0x02 <<5 )), bval, -0xA1 , read_buff,2 ,1000 ); +0xA1 , read_buff,2 ,USB_CTRL_GET_TIMEOUT );
Agreed, much better than an arbitrary 1 sec.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 4/16 drm/udl: Various improvements to the connector
In reply to Thomas ZimmermannAdd style fixes, better error handling and reporting, and minor clean-up changes to the connector code before moving the code to the rest of the modesetting pipeline.
--- drivers/gpu/drm/udl/udl_connector.c | 64 ++++++++++++++++++----------- 1 file changed, 40 insertions(+), 24 deletions(-)
drivers/gpu/drm/udl/udl_connector.c +40 -24
@@ -15,56 +15,64 @@#include "udl_connector.h" #include "udl_drv.h" -static int udl_get_edid_block (void *data,u8 *buf,unsigned int block, -size_t len) +static int udl_get_edid_block (void *data,u8 *buf,unsigned int block,size_t len) { -int ret, i; -u8 *read_buff;struct udl_device *udl = data; +struct drm_device *dev = &udl->drm;struct usb_device *udev =udl_to_usb_device (udl); +u8 *read_buff; +int ret; +size_t i; read_buff =kmalloc (2 ,GFP_KERNEL );if (!read_buff) -return -1 ; +return -ENOMEM ;for (i =0 ; i < len; i++) {int bval = (i + block *EDID_LENGTH ) <<8 ; + ret =usb_control_msg (udev,usb_rcvctrlpipe (udev,0 ),0x02 , (0x80 | (0x02 <<5 )), bval,0xA1 , read_buff,2 ,USB_CTRL_GET_TIMEOUT ); -if (ret <1 ) { -DRM_ERROR ("Read EDID byte %d failed err %x\n" , i, ret); -kfree (read_buff); -return -1 ; +if (ret <0 ) { +drm_err (dev,"Read EDID byte %zu failed err %x\n" , i, ret); + goto err_kfree; + }else if (ret <1 ) { + ret = -EIO ; +drm_err (dev,"Read EDID byte %zu failed\n" , i); + goto err_kfree; } + buf[i] = read_buff[1 ]; }kfree (read_buff); +return 0 ; + +err_kfree: +kfree (read_buff); +return ret; } -static int udl_get_modes (struct drm_connector *connector) +static int udl_connector_helper_get_modes (struct drm_connector *connector) {struct udl_connector *udl_connector =to_udl_connector (connector);drm_connector_update_edid_property (connector, udl_connector->edid);if (udl_connector->edid)return drm_add_edid_modes (connector, udl_connector->edid); +return 0 ; } -static enum drm_connector_status -udl_detect (struct drm_connector *connector,bool force) +static enum drm_connector_status udl_connector_detect (struct drm_connector *connector,bool force) {struct udl_device *udl =to_udl (connector->dev);struct udl_connector *udl_connector =to_udl_connector (connector); -/* cleanup previous edid */ -if (udl_connector->edid !=NULL ) { -kfree (udl_connector->edid); - udl_connector->edid =NULL ; - } +/* cleanup previous EDID */ +kfree (udl_connector->edid); udl_connector->edid =drm_do_get_edid (connector, udl_get_edid_block, udl);if (!udl_connector->edid)
@@ -79,38 +87,46 @@ static void udl_connector_destroy(struct drm_connector *connector)drm_connector_cleanup (connector);kfree (udl_connector->edid); -kfree (connector); +kfree (udl_connector); }static const struct drm_connector_helper_funcs udl_connector_helper_funcs = { - .get_modes = udl_get_modes, + .get_modes = udl_connector_helper_get_modes, };static const struct drm_connector_funcs udl_connector_funcs = { .reset = drm_atomic_helper_connector_reset, - .detect = udl_detect, + .detect = udl_connector_detect, .fill_modes = drm_helper_probe_single_connector_modes, .destroy = udl_connector_destroy, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, };struct drm_connector *udl_connector_init (struct drm_device *dev) {struct udl_connector *udl_connector;struct drm_connector *connector; +int ret; udl_connector =kzalloc (sizeof (*udl_connector),GFP_KERNEL );if (!udl_connector)return ERR_PTR (-ENOMEM ); connector = &udl_connector->connector; -drm_connector_init (dev, connector, &udl_connector_funcs, -DRM_MODE_CONNECTOR_VGA ); + ret =drm_connector_init (dev, connector, &udl_connector_funcs,DRM_MODE_CONNECTOR_VGA ); +if (ret) + goto err_kfree; +drm_connector_helper_add (connector, &udl_connector_helper_funcs); connector->polled =DRM_CONNECTOR_POLL_HPD | -DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; +DRM_CONNECTOR_POLL_CONNECT | +DRM_CONNECTOR_POLL_DISCONNECT ;return connector; + +err_kfree: +kfree (udl_connector); +return ERR_PTR (ret); }
Signature · 1 line
2.37.3
Re: [PATCH 04/16] drm/udl: Various improvements to the connector
Quoted 6 lines · Thomas Zimmermann
Add style fixes, better error handling and reporting, and minor clean-up changes to the connector code before moving the code to the rest of the modesetting pipeline.
Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 5/16 drm/udl: Move connector to modesetting code
In reply to Thomas ZimmermannMove the connector next to the rest of the modesetting code. No functional changes.
--- drivers/gpu/drm/udl/Makefile | 2 +- drivers/gpu/drm/udl/udl_connector.c | 132 ---------------------------- drivers/gpu/drm/udl/udl_connector.h | 21 ----- drivers/gpu/drm/udl/udl_drv.h | 11 +++ drivers/gpu/drm/udl/udl_modeset.c | 122 +++++++++++++++++++++++++ 5 files changed, 134 insertions(+), 154 deletions(-) delete mode 100644 drivers/gpu/drm/udl/udl_connector.c delete mode 100644 drivers/gpu/drm/udl/udl_connector.h
drivers/gpu/drm/udl/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -udl-y := udl_drv.o udl_modeset.o udl_connector.o udl_main.o udl_transfer.o +udl-y := udl_drv.o udl_modeset.o udl_main.o udl_transfer.o obj-$(CONFIG_DRM_UDL) := udl.o
drivers/gpu/drm/udl/udl_connector.c deleted +0 -132
132 lines not on this page · raw message
drivers/gpu/drm/udl/udl_connector.h deleted +0 -21
@@ -1,21 +0,0 @@ -#ifndef __UDL_CONNECTOR_H__ -#define __UDL_CONNECTOR_H__ - -#include <linux/container_of.h> - -#include <drm/drm_connector.h> - -struct edid ; - -struct udl_connector { -struct drm_connector connector; -/* last udl_detect edid */ -struct edid *edid; -}; - -static inline struct udl_connector *to_udl_connector (struct drm_connector *connector) -{ - return container_of(connector, struct udl_connector, connector); -} - -#endif //__UDL_CONNECTOR_H__
drivers/gpu/drm/udl/udl_drv.h +11 -0
@@ -46,6 +46,17 @@ struct urb_list {size_t size; }; +struct udl_connector { +struct drm_connector connector; +/* last udl_detect edid */ +struct edid *edid; +}; + +static inline struct udl_connector *to_udl_connector (struct drm_connector *connector) +{ + return container_of(connector, struct udl_connector, connector); +} +struct udl_device {struct drm_device drm;struct device *dev;
drivers/gpu/drm/udl/udl_modeset.c +122 -0
139 lines not on this page · raw message
Signature · 1 line
2.37.3
Re: [PATCH 05/16] drm/udl: Move connector to modesetting code
Quoted 5 lines · Thomas Zimmermann
Move the connector next to the rest of the modesetting code. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Indeed. I wondered why the connector could was special to require a separate source code file.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 6/16 drm/udl: Remove udl_simple_display_pipe_mode_valid()
In reply to Thomas ZimmermannRemove the empty function udl_simple_display_pipe_mode_valid() and let simple-KMS helpers accept the modes. No functional changes.
--- drivers/gpu/drm/udl/udl_modeset.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/gpu/drm/udl/udl_modeset.c +0 -8
@@ -310,13 +310,6 @@ static const uint32_t udl_simple_display_pipe_formats[] = { DRM_FORMAT_XRGB8888, }; -static enum drm_mode_status -udl_simple_display_pipe_mode_valid (struct drm_simple_display_pipe *pipe, -const struct drm_display_mode *mode) -{ -return MODE_OK ; -} - static void udl_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, struct drm_crtc_state *crtc_state,
@@ -398,7 +391,6 @@ udl_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, }static const struct drm_simple_display_pipe_funcs udl_simple_display_pipe_funcs = { - .mode_valid = udl_simple_display_pipe_mode_valid, .enable = udl_simple_display_pipe_enable, .disable = udl_simple_display_pipe_disable, .update = udl_simple_display_pipe_update,
Signature · 1 line
2.37.3
Re: [PATCH 06/16] drm/udl: Remove udl_simple_display_pipe_mode_valid()
Quoted 5 lines · Thomas Zimmermann
Remove the empty function
udl_simple_display_pipe_mode_valid()and let simple-KMS helpers accept the modes. No functional changes.Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 7/16 drm/udl: Convert to atomic-modesetting helpers
In reply to Thomas ZimmermannReplace simple-KMS helpers with regular atomic-modesetting helpers. The simple-KMS helpers introduce a mid-layer abstraction without added functionality. Using regular atomic helpers makes the driver's implementation more discoverable and simplifies code sharing.
The conversion effectively open-codes the simple-KMS functions and data structure within udl. No functional changes.
--- drivers/gpu/drm/udl/udl_drv.h | 9 +- drivers/gpu/drm/udl/udl_modeset.c | 166 ++++++++++++++++++++---------- 2 files changed, 121 insertions(+), 54 deletions(-)
drivers/gpu/drm/udl/udl_drv.h +7 -2
@@ -14,10 +14,13 @@#include <linux/mm_types.h> #include <linux/usb.h> +#include <drm/drm_connector.h> +#include <drm/drm_crtc.h> #include <drm/drm_device.h> +#include <drm/drm_encoder.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem.h> -#include <drm/drm_simple_kms_helper.h> +#include <drm/drm_plane.h> struct drm_mode_create_dumb ;
@@ -62,7 +65,9 @@ struct udl_device {struct device *dev;struct device *dmadev; -struct drm_simple_display_pipe display_pipe; +struct drm_plane primary_plane; +struct drm_crtc crtc; +struct drm_encoder encoder;struct mutex gem_lock;
drivers/gpu/drm/udl/udl_modeset.c +114 -52
257 lines not on this page · raw message
Signature · 1 line
2.37.3
Re: [PATCH 07/16] drm/udl: Convert to atomic-modesetting helpers
Quoted 10 lines · Thomas Zimmermann
Replace simple-KMS helpers with regular atomic-modesetting helpers. The simple-KMS helpers introduce a mid-layer abstraction without added functionality. Using regular atomic helpers makes the driver's implementation more discoverable and simplifies code sharing.
The conversion effectively open-codes the simple-KMS functions and data structure within udl. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Looks good to me.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 8/16 drm/udl: Simplify modesetting in CRTC's enable function
In reply to Thomas ZimmermannInline a modesetting helper in the CRTC's enable function. Build the command set directly in the USB URB's buffer and drop an intermediate buffer. No functional changes.
--- drivers/gpu/drm/udl/udl_drv.h | 3 -- drivers/gpu/drm/udl/udl_modeset.c | 61 +++++++------------------------ 2 files changed, 14 insertions(+), 50 deletions(-)
drivers/gpu/drm/udl/udl_drv.h +0 -3
@@ -74,9 +74,6 @@ struct udl_device {int sku_pixel_limit;struct urb_list urbs; - -char mode_buf[1024 ]; -uint32_t mode_buf_len; };#define to_udl (x) container_of(x, struct udl_device, drm)
drivers/gpu/drm/udl/udl_modeset.c +14 -47
81 lines not on this page · raw message
Signature · 1 line
2.37.3
Re: [PATCH 08/16] drm/udl: Simplify modesetting in CRTC's enable function
Quoted 6 lines · Thomas Zimmermann
Inline a modesetting helper in the CRTC's enable function. Build the command set directly in the USB URB's buffer and drop an intermediate buffer. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 9/16 drm/udl: Support DRM hot-unplugging
In reply to Thomas ZimmermannAdd drm_dev_enter() and drm_dev_exit() to the various modesetting functions that interact with the device. After hot-unplugging the device, these functions will return early. So far, the udl driver relied on USB interfaces to handle unplugging of the device.
--- drivers/gpu/drm/udl/udl_modeset.c | 43 ++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-)
drivers/gpu/drm/udl/udl_modeset.c +37 -6
@@ -12,6 +12,7 @@#include <drm/drm_atomic_helper.h> #include <drm/drm_crtc_helper.h> #include <drm/drm_damage_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_edid.h> #include <drm/drm_fourcc.h> #include <drm/drm_gem_atomic_helper.h>
@@ -295,14 +296,21 @@ static const uint64_t udl_primary_plane_fmtmods[] = {static void udl_primary_plane_helper_atomic_update (struct drm_plane *plane,struct drm_atomic_state *state) { +struct drm_device *dev = plane->dev;struct drm_plane_state *plane_state =drm_atomic_get_new_plane_state (state, plane);struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);struct drm_framebuffer *fb = plane_state->fb;struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane);struct drm_rect rect; +int idx; + +if (!drm_dev_enter (dev, &idx)) +return ;if (drm_atomic_helper_damage_merged (old_plane_state, plane_state, &rect))udl_handle_damage (fb, &shadow_plane_state->data[0 ], &rect); + +drm_dev_exit (idx); } static void udl_primary_plane_helper_atomic_disable(struct drm_plane *plane,
@@ -348,10 +356,14 @@ static void udl_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomstruct drm_display_mode *mode = &crtc_state->mode;struct urb *urb;char *buf; +int idx; + +if (!drm_dev_enter (dev, &idx)) +return ; urb =udl_get_urb (dev);if (!urb) -return ; + goto out; buf = (char *)urb->transfer_buffer; buf =udl_vidreg_lock (buf);
@@ -366,6 +378,9 @@ static void udl_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atom buf =udl_dummy_render (buf);udl_submit_urb (dev, urb, buf - (char *)urb->transfer_buffer); + +out: +drm_dev_exit (idx); }static void udl_crtc_helper_atomic_disable (struct drm_crtc *crtc,struct drm_atomic_state *state)
@@ -373,10 +388,14 @@ static void udl_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_atostruct drm_device *dev = crtc->dev;struct urb *urb;char *buf; +int idx; + +if (!drm_dev_enter (dev, &idx)) +return ; urb =udl_get_urb (dev);if (!urb) -return ; + goto out; buf = (char *)urb->transfer_buffer; buf =udl_vidreg_lock (buf);
@@ -385,6 +404,9 @@ static void udl_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_ato buf =udl_dummy_render (buf);udl_submit_urb (dev, urb, buf - (char *)urb->transfer_buffer); + +out: +drm_dev_exit (idx); }static const struct drm_crtc_helper_funcs udl_crtc_helper_funcs = {
@@ -471,17 +493,26 @@ static int udl_get_edid_block(void *data, u8 *buf, unsigned int block, size_t lestatic enum drm_connector_status udl_connector_detect (struct drm_connector *connector,bool force) { -struct udl_device *udl =to_udl (connector->dev); +struct drm_device *dev = connector->dev; +struct udl_device *udl =to_udl (dev);struct udl_connector *udl_connector =to_udl_connector (connector); +enum drm_connector_status status = connector_status_disconnected; +int idx;/* cleanup previous EDID */ kfree (udl_connector->edid); + udl_connector->edid =NULL ; - udl_connector->edid =drm_do_get_edid (connector, udl_get_edid_block, udl); -if (!udl_connector->edid) +if (!drm_dev_enter (dev, &idx))return connector_status_disconnected; -return connector_status_connected; + udl_connector->edid =drm_do_get_edid (connector, udl_get_edid_block, udl); +if (udl_connector->edid) + status = connector_status_connected; + +drm_dev_exit (idx); + +return status; }static void udl_connector_destroy (struct drm_connector *connector)
Signature · 1 line
2.37.3
Re: [PATCH 09/16] drm/udl: Support DRM hot-unplugging
Quoted 7 lines · Thomas Zimmermann
Add
drm_dev_enter()anddrm_dev_exit()to the various modesetting functions that interact with the device. After hot-unplugging the device, these functions will return early. So far, the udl driver relied on USB interfaces to handle unplugging of the device.Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 10/16 drm/udl: Use damage iterator
In reply to Thomas ZimmermannUse a damage iterator to process damage areas individually. Merging damage areas can resul tin large updates of unchanged framebuffer regions. As USB is rather slow, it's better to process damage areas individually and hence minimize USB-transfered data.
--- drivers/gpu/drm/udl/udl_modeset.c | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-)
drivers/gpu/drm/udl/udl_modeset.c +19 -19
@@ -238,15 +238,9 @@ static int udl_handle_damage(struct drm_framebuffer *fb,return ret; log_bpp = ret; - ret =drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE ); -if (ret) -return ret; - urb =udl_get_urb (dev); -if (!urb) { - ret = -ENOMEM ; - goto out_drm_gem_fb_end_cpu_access; - } +if (!urb) +return -ENOMEM ; cmd = urb->transfer_buffer;for (i = clip->y1; i < clip->y2; i++) {
@@ -258,7 +252,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, &cmd, byte_offset, dev_byte_offset, byte_width);if (ret) - goto out_drm_gem_fb_end_cpu_access; +return ret; }if (cmd > (char *)urb->transfer_buffer) {
@@ -272,11 +266,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb,udl_urb_completion (urb); } - ret =0 ; - -out_drm_gem_fb_end_cpu_access: -drm_gem_fb_end_cpu_access (fb,DMA_FROM_DEVICE ); -return ret; +return 0 ; }/*
@@ -301,16 +291,26 @@ static void udl_primary_plane_helper_atomic_update(struct drm_plane *plane,struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);struct drm_framebuffer *fb = plane_state->fb;struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); -struct drm_rect rect; -int idx; +struct drm_atomic_helper_damage_iter iter; +struct drm_rect damage; +int ret, idx; -if (!drm_dev_enter (dev, &idx)) + ret =drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE ); +if (ret)return ; -if (drm_atomic_helper_damage_merged (old_plane_state, plane_state, &rect)) -udl_handle_damage (fb, &shadow_plane_state->data[0 ], &rect); +if (!drm_dev_enter (dev, &idx)) + goto out_drm_gem_fb_end_cpu_access; + +drm_atomic_helper_damage_iter_init (&iter, old_plane_state, plane_state); +drm_atomic_for_each_plane_damage (&iter, &damage) { +udl_handle_damage (fb, &shadow_plane_state->data[0 ], &damage); + }drm_dev_exit (idx); + +out_drm_gem_fb_end_cpu_access: +drm_gem_fb_end_cpu_access (fb,DMA_FROM_DEVICE ); } static void udl_primary_plane_helper_atomic_disable(struct drm_plane *plane,
Signature · 1 line
2.37.3
Re: [PATCH 10/16] drm/udl: Use damage iterator
Quoted 2 lines · Thomas Zimmermann
Use a damage iterator to process damage areas individually. Merging damage areas can resul tin large updates of unchanged framebuffer
result in
Quoted 5 lines
regions. As USB is rather slow, it's better to process damage areas individually and hence minimize USB-transfered data.
Signed-off-by Thomas Zimmermann <[email protected]>---
but I've a comment below.
Quoted 7 lines
/*
drivers/gpu/drm/udl/udl_modeset.c +0
-1@@ -301,16 +291,26 @@ static void udl_primary_plane_helper_atomic_update(struct drm_plane *plane,struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);struct drm_framebuffer *fb = plane_state->fb;struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); -struct drm_rect rect;
drivers/gpu/drm/udl/udl_modeset.c static void udl_primary_plane_helper_atomic_update(struct drm_plane *plane, · line 301
Quoted 10 lines
drivers/gpu/drm/udl/udl_modeset.c +5
-2-int idx; +struct drm_atomic_helper_damage_iter iter; +struct drm_rect damage; +int ret, idx; -if (!drm_dev_enter (dev, &idx)) + ret =drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE ); +if (ret)return ;
This is an unrelated change. The sync was made in udl_handle_damage() before and you are moving to udl_primary_plane_helper_atomic_update() in this patch.
I don't have a strong opinion and I see that there are drivers that do once before iterating over the damage areas and others do the sync for each damage area update. But it would be good to mention that this change is done too and provided some justification.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerRe: [PATCH 10/16] drm/udl: Use damage iterator
Hi
Am 05.10.22 um 00:28 schrieb Javier Martinez Canillas:
Quoted 37 lines · Thomas Zimmermann
Quoted 2 lines
Use a damage iterator to process damage areas individually. Merging damage areas can resul tin large updates of unchanged framebuffer
result in
Quoted 5 lines
regions. As USB is rather slow, it's better to process damage areas individually and hence minimize USB-transfered data.
Signed-off-by Thomas Zimmermann <[email protected]>---
Reviewed-by Javier Martinez Canillas <[email protected]>but I've a comment below.
Quoted 7 lines
/*
drivers/gpu/drm/udl/udl_modeset.c +0
-1@@ -301,16 +291,26 @@ static void udl_primary_plane_helper_atomic_update(struct drm_plane *plane,struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);struct drm_framebuffer *fb = plane_state->fb;struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); -struct drm_rect rect;drivers/gpu/drm/udl/udl_modeset.c static void udl_primary_plane_helper_atomic_update(struct drm_plane *plane, · line 301
Quoted 10 lines
drivers/gpu/drm/udl/udl_modeset.c +5
-2-int idx; +struct drm_atomic_helper_damage_iter iter; +struct drm_rect damage; +int ret, idx; -if (!drm_dev_enter (dev, &idx)) + ret =drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE ); +if (ret)return ;This is an unrelated change. The sync was made in
udl_handle_damage()before and you are moving toudl_primary_plane_helper_atomic_update()in this patch.
Quoted 4 lines
I don't have a strong opinion and I see that there are drivers that do once before iterating over the damage areas and others do the sync for each damage area update. But it would be good to mention that this change is done too and provided some justification.
OK, I'll do that. Very briefly; it's for minimizing the overheads of the possible locking and synchronization, and to maybe it keeps possible writers out while we copy from the buffer.
Best regards
Thomas
Quoted 1 line
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Thomas Zimmermann
maintainerPATCH 11/16 drm/udl: Move register constants to udl_proto.h
In reply to Thomas ZimmermannMove the existing register constants to a new file in preparation of adding more of them. Renaming is intentional. No functional changes.
--- drivers/gpu/drm/udl/udl_drv.h | 9 --------- drivers/gpu/drm/udl/udl_modeset.c | 11 +++++------ drivers/gpu/drm/udl/udl_proto.h | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/udl/udl_proto.h
drivers/gpu/drm/udl/udl_drv.h +0 -9
@@ -112,13 +112,4 @@ int udl_select_std_channel(struct udl_device *udl);#define CMD_WRITE_COPY16 "\xAF\x6A"/**< 16 bit copy command. */ #define CMD_WRITE_RLX16 "\xAF\x6B"/**< 16 bit extended run length command. */ -/* On/Off for driving the DisplayLink framebuffer to the display */ -#define UDL_REG_BLANK_MODE 0x1f - -#define UDL_BLANK_MODE_ON 0x00/* hsync and vsync on, visible */ -#define UDL_BLANK_MODE_BLANKED 0x01/* hsync and vsync on, blanked */ -#define UDL_BLANK_MODE_VSYNC_OFF 0x03/* vsync off, blanked */ -#define UDL_BLANK_MODE_HSYNC_OFF 0x05/* hsync off, blanked */ -#define UDL_BLANK_MODE_POWERDOWN 0x07/* powered off; requires modeset */ -#endif
drivers/gpu/drm/udl/udl_modeset.c +5 -6
@@ -24,8 +24,7 @@#include <drm/drm_vblank.h> #include "udl_drv.h" - -#define UDL_COLOR_DEPTH_16BPP 0 +#include "udl_proto.h" /* * All DisplayLink bulk operations start with 0xAF, followed by specific code
@@ -52,7 +51,7 @@ static char *udl_vidreg_unlock(char *buf)static char *udl_set_blank_mode (char *buf,u8 mode) { -return udl_set_register (buf,UDL_REG_BLANK_MODE , mode); +return udl_set_register (buf,UDL_REG_BLANKMODE , mode); }static char *udl_set_color_depth (char *buf,u8 selection)
@@ -367,13 +366,13 @@ static void udl_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atom buf = (char *)urb->transfer_buffer; buf =udl_vidreg_lock (buf); - buf =udl_set_color_depth (buf,UDL_COLOR_DEPTH_16BPP ); + buf =udl_set_color_depth (buf,UDL_COLORDEPTH_16BPP );/* set base for 16bpp segment to 0 */ buf =udl_set_base16bpp (buf,0 );/* set base for 8bpp segment to end of fb */ buf =udl_set_base8bpp (buf,2 * mode->vdisplay * mode->hdisplay); buf =udl_set_vid_cmds (buf, mode); - buf =udl_set_blank_mode (buf,UDL_BLANK_MODE_ON ); + buf =udl_set_blank_mode (buf,UDL_BLANKMODE_ON ); buf =udl_vidreg_unlock (buf); buf =udl_dummy_render (buf);
@@ -399,7 +398,7 @@ static void udl_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_ato buf = (char *)urb->transfer_buffer; buf =udl_vidreg_lock (buf); - buf =udl_set_blank_mode (buf,UDL_BLANK_MODE_POWERDOWN ); + buf =udl_set_blank_mode (buf,UDL_BLANKMODE_POWERDOWN ); buf =udl_vidreg_unlock (buf); buf =udl_dummy_render (buf);
drivers/gpu/drm/udl/udl_proto.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef UDL_PROTO_H +#define UDL_PROTO_H + +#define UDL_COLORDEPTH_16BPP 0 + +/* On/Off for driving the DisplayLink framebuffer to the display */ +#define UDL_REG_BLANKMODE 0x1f +#define UDL_BLANKMODE_ON 0x00/* hsync and vsync on, visible */ +#define UDL_BLANKMODE_BLANKED 0x01/* hsync and vsync on, blanked */ +#define UDL_BLANKMODE_VSYNC_OFF 0x03/* vsync off, blanked */ +#define UDL_BLANKMODE_HSYNC_OFF 0x05/* hsync off, blanked */ +#define UDL_BLANKMODE_POWERDOWN 0x07/* powered off; requires modeset */ + +#endif
Signature · 1 line
2.37.3
Re: [PATCH 11/16] drm/udl: Move register constants to udl_proto.h
Quoted 5 lines · Thomas Zimmermann
Move the existing register constants to a new file in preparation of adding more of them. Renaming is intentional. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 12/16 drm/udl: Add constants for display-mode registers
In reply to Thomas ZimmermannAdd constants for the registers the contain various display-mode parameters and update the mode-setting function. No functional changes.
--- drivers/gpu/drm/udl/udl_modeset.c | 102 ++++++++++-------------------- drivers/gpu/drm/udl/udl_proto.h | 15 +++++ 2 files changed, 47 insertions(+), 70 deletions(-)
drivers/gpu/drm/udl/udl_modeset.c +32 -70
@@ -126,78 +126,40 @@ static char *udl_set_register_lfsr16(char *wrptr, u8 reg, u16 value) }/* -* This takes a standard fbdev screeninfo struct and all of its monitor mode -* details and converts them into the DisplayLink equivalent register commands. -ERR(vreg(dev, 0x00, (color_depth == 16) ? 0 : 1)); -ERR(vreg_lfsr16(dev, 0x01, xDisplayStart)); -ERR(vreg_lfsr16(dev, 0x03, xDisplayEnd)); -ERR(vreg_lfsr16(dev, 0x05, yDisplayStart)); -ERR(vreg_lfsr16(dev, 0x07, yDisplayEnd)); -ERR(vreg_lfsr16(dev, 0x09, xEndCount)); -ERR(vreg_lfsr16(dev, 0x0B, hSyncStart)); -ERR(vreg_lfsr16(dev, 0x0D, hSyncEnd)); -ERR(vreg_big_endian(dev, 0x0F, hPixels)); -ERR(vreg_lfsr16(dev, 0x11, yEndCount)); -ERR(vreg_lfsr16(dev, 0x13, vSyncStart)); -ERR(vreg_lfsr16(dev, 0x15, vSyncEnd)); -ERR(vreg_big_endian(dev, 0x17, vPixels)); -ERR(vreg_little_endian(dev, 0x1B, pixelClock5KHz)); - -ERR(vreg(dev, 0x1F, 0)); - -ERR(vbuf(dev, WRITE_VIDREG_UNLOCK, DSIZEOF(WRITE_VIDREG_UNLOCK))); +* Takes a DRM display mode and converts it into the DisplayLink +* equivalent register commands. */ -static char *udl_set_vid_cmds (char *wrptr,struct drm_display_mode *mode) +static char *udl_set_display_mode (char *buf,struct drm_display_mode *mode) { -u16 xds, yds; -u16 xde, yde; -u16 yec; +u16 reg01 = mode->crtc_htotal - mode->crtc_hsync_start; +u16 reg03 = reg01 + mode->crtc_hdisplay; +u16 reg05 = mode->crtc_vtotal - mode->crtc_vsync_start; +u16 reg07 = reg05 + mode->crtc_vdisplay; +u16 reg09 = mode->crtc_htotal -1 ; +u16 reg0b =1 ;/* libdlo hardcodes hsync start to 1 */ +u16 reg0d = mode->crtc_hsync_end - mode->crtc_hsync_start +1 ; +u16 reg0f = mode->hdisplay; +u16 reg11 = mode->crtc_vtotal; +u16 reg13 =0 ;/* libdlo hardcodes vsync start to 0 */ +u16 reg15 = mode->crtc_vsync_end - mode->crtc_vsync_start; +u16 reg17 = mode->crtc_vdisplay; +u16 reg1b = mode->clock /5 ; + + buf =udl_set_register_lfsr16 (buf,UDL_REG_XDISPLAYSTART , reg01); + buf =udl_set_register_lfsr16 (buf,UDL_REG_XDISPLAYEND , reg03); + buf =udl_set_register_lfsr16 (buf,UDL_REG_YDISPLAYSTART , reg05); + buf =udl_set_register_lfsr16 (buf,UDL_REG_YDISPLAYEND , reg07); + buf =udl_set_register_lfsr16 (buf,UDL_REG_XENDCOUNT , reg09); + buf =udl_set_register_lfsr16 (buf,UDL_REG_HSYNCSTART , reg0b); + buf =udl_set_register_lfsr16 (buf,UDL_REG_HSYNCEND , reg0d); + buf =udl_set_register_16 (buf,UDL_REG_HPIXELS , reg0f); + buf =udl_set_register_lfsr16 (buf,UDL_REG_YENDCOUNT , reg11); + buf =udl_set_register_lfsr16 (buf,UDL_REG_VSYNCSTART , reg13); + buf =udl_set_register_lfsr16 (buf,UDL_REG_VSYNCEND , reg15); + buf =udl_set_register_16 (buf,UDL_REG_VPIXELS , reg17); + buf =udl_set_register_16be (buf,UDL_REG_PIXELCLOCK5KHZ , reg1b); -/* x display start */ - xds = mode->crtc_htotal - mode->crtc_hsync_start; - wrptr =udl_set_register_lfsr16 (wrptr,0x01 , xds); -/* x display end */ - xde = xds + mode->crtc_hdisplay; - wrptr =udl_set_register_lfsr16 (wrptr,0x03 , xde); - -/* y display start */ - yds = mode->crtc_vtotal - mode->crtc_vsync_start; - wrptr =udl_set_register_lfsr16 (wrptr,0x05 , yds); -/* y display end */ - yde = yds + mode->crtc_vdisplay; - wrptr =udl_set_register_lfsr16 (wrptr,0x07 , yde); - -/* x end count is active + blanking - 1 */ - wrptr =udl_set_register_lfsr16 (wrptr,0x09 , - mode->crtc_htotal -1 ); - -/* libdlo hardcodes hsync start to 1 */ - wrptr =udl_set_register_lfsr16 (wrptr,0x0B ,1 ); - -/* hsync end is width of sync pulse + 1 */ - wrptr =udl_set_register_lfsr16 (wrptr,0x0D , - mode->crtc_hsync_end - mode->crtc_hsync_start +1 ); - -/* hpixels is active pixels */ - wrptr =udl_set_register_16 (wrptr,0x0F , mode->hdisplay); - -/* yendcount is vertical active + vertical blanking */ - yec = mode->crtc_vtotal; - wrptr =udl_set_register_lfsr16 (wrptr,0x11 , yec); - -/* libdlo hardcodes vsync start to 0 */ - wrptr =udl_set_register_lfsr16 (wrptr,0x13 ,0 ); - -/* vsync end is width of vsync pulse */ - wrptr =udl_set_register_lfsr16 (wrptr,0x15 , mode->crtc_vsync_end - mode->crtc_vsync_start); - -/* vpixels is active pixels */ - wrptr =udl_set_register_16 (wrptr,0x17 , mode->crtc_vdisplay); - - wrptr =udl_set_register_16be (wrptr,0x1B , - mode->clock /5 ); - -return wrptr; +return buf; }static char *udl_dummy_render (char *wrptr)
@@ -371,7 +333,7 @@ static void udl_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atom buf =udl_set_base16bpp (buf,0 );/* set base for 8bpp segment to end of fb */ buf =udl_set_base8bpp (buf,2 * mode->vdisplay * mode->hdisplay); - buf =udl_set_vid_cmds (buf, mode); + buf =udl_set_display_mode (buf, mode); buf =udl_set_blank_mode (buf,UDL_BLANKMODE_ON ); buf =udl_vidreg_unlock (buf); buf =udl_dummy_render (buf);
drivers/gpu/drm/udl/udl_proto.h +15 -0
@@ -5,6 +5,21 @@#define UDL_COLORDEPTH_16BPP 0 +/* Display-mode settings */ +#define UDL_REG_XDISPLAYSTART 0x01 +#define UDL_REG_XDISPLAYEND 0x03 +#define UDL_REG_YDISPLAYSTART 0x05 +#define UDL_REG_YDISPLAYEND 0x07 +#define UDL_REG_XENDCOUNT 0x09 +#define UDL_REG_HSYNCSTART 0x0b +#define UDL_REG_HSYNCEND 0x0d +#define UDL_REG_HPIXELS 0x0f +#define UDL_REG_YENDCOUNT 0x11 +#define UDL_REG_VSYNCSTART 0x13 +#define UDL_REG_VSYNCEND 0x15 +#define UDL_REG_VPIXELS 0x17 +#define UDL_REG_PIXELCLOCK5KHZ 0x1b +/* On/Off for driving the DisplayLink framebuffer to the display */ #define UDL_REG_BLANKMODE 0x1f#define UDL_BLANKMODE_ON 0x00/* hsync and vsync on, visible */
Signature · 1 line
2.37.3
Re: [PATCH 12/16] drm/udl: Add constants for display-mode registers
Quoted 6 lines · Thomas Zimmermann
Add constants for the registers the contain various display-mode parameters and update the mode-setting function. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 13/16 drm/udl: Add register constants for color depth
In reply to Thomas ZimmermannAdd the register constants for setting the color depth. The driver only uses 16bpp. No functional changes.
--- drivers/gpu/drm/udl/udl_modeset.c | 2 +- drivers/gpu/drm/udl/udl_proto.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/udl/udl_modeset.c +1 -1
@@ -56,7 +56,7 @@ static char *udl_set_blank_mode(char *buf, u8 mode)static char *udl_set_color_depth (char *buf,u8 selection) { -return udl_set_register (buf,0x00 , selection); +return udl_set_register (buf,UDL_REG_COLORDEPTH , selection); }static char *udl_set_base16bpp (char *wrptr,u32 base)
drivers/gpu/drm/udl/udl_proto.h +3 -0
@@ -3,7 +3,10 @@#ifndef UDL_PROTO_H #define UDL_PROTO_H +/* Color depth */ +#define UDL_REG_COLORDEPTH 0x00#define UDL_COLORDEPTH_16BPP 0 +#define UDL_COLORDEPTH_24BPP 1/* Display-mode settings */ #define UDL_REG_XDISPLAYSTART 0x01
Signature · 1 line
2.37.3
Re: [PATCH 13/16] drm/udl: Add register constants for color depth
Quoted 5 lines · Thomas Zimmermann
Add the register constants for setting the color depth. The driver only uses 16bpp. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 14/16 drm/udl: Add register constants for video locks
In reply to Thomas ZimmermannAdd register constants for the video lock. No functional changes.
--- drivers/gpu/drm/udl/udl_modeset.c | 4 ++-- drivers/gpu/drm/udl/udl_proto.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/udl/udl_modeset.c +2 -2
@@ -41,12 +41,12 @@ static char *udl_set_register(char *buf, u8 reg, u8 val)static char *udl_vidreg_lock (char *buf) { -return udl_set_register (buf,0xFF ,0x00 ); +return udl_set_register (buf,UDL_REG_VIDREG ,UDL_VIDREG_LOCK ); }static char *udl_vidreg_unlock (char *buf) { -return udl_set_register (buf,0xFF ,0xFF ); +return udl_set_register (buf,UDL_REG_VIDREG ,UDL_VIDREG_UNLOCK ); }static char *udl_set_blank_mode (char *buf,u8 mode)
drivers/gpu/drm/udl/udl_proto.h +5 -0
@@ -31,4 +31,9 @@#define UDL_BLANKMODE_HSYNC_OFF 0x05/* hsync off, blanked */ #define UDL_BLANKMODE_POWERDOWN 0x07/* powered off; requires modeset */ +/* Lock/unlock video registers */ +#define UDL_REG_VIDREG 0xff +#define UDL_VIDREG_LOCK 0x00 +#define UDL_VIDREG_UNLOCK 0xff +#endif
Signature · 1 line
2.37.3
Re: [PATCH 14/16] drm/udl: Add register constants for video locks
Quoted 4 lines · Thomas Zimmermann
Add register constants for the video lock. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerPATCH 15/16 drm/udl: Add register constants for framebuffer scanout addresses
In reply to Thomas ZimmermannAdd register constants for the framebuffer scanout addresses and update the related helper functions. No functional changes.
--- drivers/gpu/drm/udl/udl_modeset.c | 28 ++++++++++++++++++++-------- drivers/gpu/drm/udl/udl_proto.h | 8 ++++++++ 2 files changed, 28 insertions(+), 8 deletions(-)
drivers/gpu/drm/udl/udl_modeset.c +20 -8
@@ -59,23 +59,35 @@ static char *udl_set_color_depth(char *buf, u8 selection)return udl_set_register (buf,UDL_REG_COLORDEPTH , selection); } -static char *udl_set_base16bpp (char *wrptr,u32 base) +static char *udl_set_base16bpp (char *buf,u32 base) {/* the base pointer is 16 bits wide, 0x20 is hi byte. */ - wrptr =udl_set_register (wrptr,0x20 , base >>16 ); - wrptr =udl_set_register (wrptr,0x21 , base >>8 ); -return udl_set_register (wrptr,0x22 , base); +u8 reg20 = (base &0xff0000 ) >>16 ; +u8 reg21 = (base &0x00ff00 ) >>8 ; +u8 reg22 = (base &0x0000ff ); + + buf =udl_set_register (buf,UDL_REG_BASE16BPP_ADDR2 , reg20); + buf =udl_set_register (buf,UDL_REG_BASE16BPP_ADDR1 , reg21); + buf =udl_set_register (buf,UDL_REG_BASE16BPP_ADDR0 , reg22); + +return buf; }/* * DisplayLink HW has separate 16bpp and 8bpp framebuffers. * In 24bpp modes, the low 323 RGB bits go in the 8bpp framebuffer */ -static char *udl_set_base8bpp (char *wrptr,u32 base) +static char *udl_set_base8bpp (char *buf,u32 base) { - wrptr =udl_set_register (wrptr,0x26 , base >>16 ); - wrptr =udl_set_register (wrptr,0x27 , base >>8 ); -return udl_set_register (wrptr,0x28 , base); +u8 reg26 = (base &0xff0000 ) >>16 ; +u8 reg27 = (base &0x00ff00 ) >>8 ; +u8 reg28 = (base &0x0000ff ); + + buf =udl_set_register (buf,UDL_REG_BASE8BPP_ADDR2 , reg26); + buf =udl_set_register (buf,UDL_REG_BASE8BPP_ADDR1 , reg27); + buf =udl_set_register (buf,UDL_REG_BASE8BPP_ADDR0 , reg28); + +return buf; }static char *udl_set_register_16 (char *wrptr,u8 reg,u16 value)
drivers/gpu/drm/udl/udl_proto.h +8 -0
@@ -31,6 +31,14 @@#define UDL_BLANKMODE_HSYNC_OFF 0x05/* hsync off, blanked */ #define UDL_BLANKMODE_POWERDOWN 0x07/* powered off; requires modeset */ +/* Framebuffer address */ +#define UDL_REG_BASE16BPP_ADDR2 0x20 +#define UDL_REG_BASE16BPP_ADDR1 0x21 +#define UDL_REG_BASE16BPP_ADDR0 0x22 +#define UDL_REG_BASE8BPP_ADDR2 0x26 +#define UDL_REG_BASE8BPP_ADDR1 0x27 +#define UDL_REG_BASE8BPP_ADDR0 0x28 +/* Lock/unlock video registers */ #define UDL_REG_VIDREG 0xff#define UDL_VIDREG_LOCK 0x00
Signature · 1 line
2.37.3
Re: [PATCH 15/16] drm/udl: Add register constants for framebuffer scanout addresses
Quoted 5 lines · Thomas Zimmermann
Add register constants for the framebuffer scanout addresses and update the related helper functions. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
[...]
drivers/gpu/drm/udl/udl_modeset.c static char *udl_set_color_depth(char *buf, u8 selection) · line 68
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +4
-0+u8 reg20 = (base &0xff0000 ) >>16 ; +u8 reg21 = (base &0x00ff00 ) >>8 ; +u8 reg22 = (base &0x0000ff ); +
Maybe would be cleaner to use the FIELD_PREP() and GENMASK() macros instead ?
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Thomas Zimmermann
maintainerRe: [PATCH 15/16] drm/udl: Add register constants for framebuffer scanout addresses
Hi
Am 05.10.22 um 00:59 schrieb Javier Martinez Canillas:
Quoted 9 lines · Thomas Zimmermann
Quoted 5 lines
Add register constants for the framebuffer scanout addresses and update the related helper functions. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Reviewed-by Javier Martinez Canillas <[email protected]>
Quoted 9 lines
[...]
drivers/gpu/drm/udl/udl_modeset.c static char *udl_set_color_depth(char *buf, u8 selection) · line 68
Quoted 4 lines
drivers/gpu/drm/udl/udl_modeset.c +4
-0+u8 reg20 = (base &0xff0000 ) >>16 ; +u8 reg21 = (base &0x00ff00 ) >>8 ; +u8 reg22 = (base &0x0000ff ); +Maybe would be cleaner to use the
FIELD_PREP()andGENMASK()macros instead ?
Thank you for reviewing my patchset. I'll update the patch with these macros.
Best regards
Thomas
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Thomas Zimmermann
maintainerPATCH 16/16 drm/udl: Add constants for commands
In reply to Thomas ZimmermannAdd constants for the various commands that the driver can send to the device and update the respective helper functions. No functional changes.
--- drivers/gpu/drm/udl/udl_drv.h | 10 ---------- drivers/gpu/drm/udl/udl_modeset.c | 16 +++++++++------- drivers/gpu/drm/udl/udl_proto.h | 15 +++++++++++++++ drivers/gpu/drm/udl/udl_transfer.c | 7 ++++--- 4 files changed, 28 insertions(+), 20 deletions(-)
drivers/gpu/drm/udl/udl_drv.h +0 -10
@@ -102,14 +102,4 @@ int udl_render_hline(struct drm_device *dev, int log_bpp, struct urb **urb_ptr,int udl_drop_usb (struct drm_device *dev);int udl_select_std_channel (struct udl_device *udl); -#define CMD_WRITE_RAW8 "\xAF\x60"/**< 8 bit raw write command. */ -#define CMD_WRITE_RL8 "\xAF\x61"/**< 8 bit run length command. */ -#define CMD_WRITE_COPY8 "\xAF\x62"/**< 8 bit copy command. */ -#define CMD_WRITE_RLX8 "\xAF\x63"/**< 8 bit extended run length command. */ - -#define CMD_WRITE_RAW16 "\xAF\x68"/**< 16 bit raw write command. */ -#define CMD_WRITE_RL16 "\xAF\x69"/**< 16 bit run length command. */ -#define CMD_WRITE_COPY16 "\xAF\x6A"/**< 16 bit copy command. */ -#define CMD_WRITE_RLX16 "\xAF\x6B"/**< 16 bit extended run length command. */ -#endif
drivers/gpu/drm/udl/udl_modeset.c +9 -7
@@ -27,15 +27,17 @@#include "udl_proto.h" /* -* All DisplayLink bulk operations start with 0xAF, followed by specific code -* All operations are written to buffers which then later get sent to device +* All DisplayLink bulk operations start with 0xaf (UDL_MSG_BULK), followed by +* a specific command code. All operations are written to a command buffer, which +* the driver sends to the device. */ static char *udl_set_register (char *buf,u8 reg,u8 val) { - *buf++ =0xAF ; - *buf++ =0x20 ; + *buf++ =UDL_MSG_BULK ; + *buf++ =UDL_CMD_WRITEREG ; *buf++ = reg; *buf++ = val; +return buf; }
@@ -176,8 +178,8 @@ static char *udl_set_display_mode(char *buf, struct drm_display_mode *mode)static char *udl_dummy_render (char *wrptr) { - *wrptr++ =0xAF ; - *wrptr++ =0x6A ;/* copy */ + *wrptr++ =UDL_MSG_BULK ; + *wrptr++ =UDL_CMD_WRITECOPY16 ; *wrptr++ =0x00 ;/* from addr */ *wrptr++ =0x00 ; *wrptr++ =0x00 ;
@@ -232,7 +234,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb,/* Send partial buffer remaining before exiting */ int len;if (cmd < (char *)urb->transfer_buffer + urb->transfer_buffer_length) - *cmd++ =0xAF ; + *cmd++ =UDL_MSG_BULK ; len = cmd - (char *)urb->transfer_buffer; ret =udl_submit_urb (dev, urb, len); }else {
drivers/gpu/drm/udl/udl_proto.h +15 -0
@@ -3,6 +3,21 @@#ifndef UDL_PROTO_H #define UDL_PROTO_H +#define UDL_MSG_BULK 0xaf + +/* Register access */ +#define UDL_CMD_WRITEREG 0x20/* See register constants below */ + +/* Framebuffer access */ +#define UDL_CMD_WRITERAW8 0x60/* 8 bit raw write command. */ +#define UDL_CMD_WRITERL8 0x61/* 8 bit run length command. */ +#define UDL_CMD_WRITECOPY8 0x62/* 8 bit copy command. */ +#define UDL_CMD_WRITERLX8 0x63/* 8 bit extended run length command. */ +#define UDL_CMD_WRITERAW16 0x68/* 16 bit raw write command. */ +#define UDL_CMD_WRITERL16 0x69/* 16 bit run length command. */ +#define UDL_CMD_WRITECOPY16 0x6a/* 16 bit copy command. */ +#define UDL_CMD_WRITERLX16 0x6b/* 16 bit extended run length command. */ +/* Color depth */ #define UDL_REG_COLORDEPTH 0x00#define UDL_COLORDEPTH_16BPP 0
drivers/gpu/drm/udl/udl_transfer.c +4 -3
@@ -10,6 +10,7 @@#include <asm/unaligned.h> #include "udl_drv.h" +#include "udl_proto.h" #define MAX_CMD_PIXELS 255
@@ -89,8 +90,8 @@ static void udl_compress_hline16(const u8 *cmd_pixel_start, *cmd_pixel_end =NULL ;uint16_t pixel_val16; - *cmd++ =0xaf ; - *cmd++ =0x6b ; + *cmd++ =UDL_MSG_BULK ; + *cmd++ =UDL_CMD_WRITERLX16 ; *cmd++ = (uint8_t ) ((dev_addr >>16 ) &0xFF ); *cmd++ = (uint8_t ) ((dev_addr >>8 ) &0xFF ); *cmd++ = (uint8_t ) ((dev_addr) &0xFF );
@@ -152,7 +153,7 @@ static void udl_compress_hline16(if (cmd_buffer_end <=MIN_RLX_CMD_BYTES + cmd) {/* Fill leftover bytes with no-ops */ if (cmd_buffer_end > cmd) -memset (cmd,0xAF , cmd_buffer_end - cmd); +memset (cmd,UDL_MSG_BULK , cmd_buffer_end - cmd); cmd = (uint8_t *) cmd_buffer_end; }
Signature · 1 line
2.37.3
Re: [PATCH 16/16] drm/udl: Add constants for commands
Quoted 6 lines · Thomas Zimmermann
Add constants for the various commands that the driver can send to the device and update the respective helper functions. No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat