Re: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization
On Thu, Jun 13, 2024 at 12:17:00AM -0500, Mario Limonciello wrote:
> If the lid on a laptop is closed when eDP connectors are populated
> then it remains enabled when the initial framebuffer configuration
> is built.
>
> When creating the initial framebuffer configuration detect the
> lid status and if it's closed disable any eDP connectors.
>
> Also set up a workqueue to monitor for any future lid events.
>
> Suggested-by: Dmitry Torokhov
> Reported-by: Chris Bainbridge
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3349
> Signed-off-by: Mario Limonciello
More fundamental question: Do we even want to solve this issues?
This is fbdev we're talking about, if people use this actually in
production, they don't care much about the fallout.
Plus this has the potential to cause regressions, like we might not be
able to enable edp after having enabled and external screen. Which would
be bad.
Imo this needs a lot more justification than "one random user asked for
it". Especially since it's been the behaviour for like well over a decade
for any integrated panel that we just light them always up when using
fbdev/fbcon.
If people want full control over all this, they can use a display manager
(or a userspace console).
Cheers, Sima
> ---
> v2->v3:
> * Use input device instead of ACPI device
> * Detect lid open/close events
> ---
> drivers/gpu/drm/drm_client_modeset.c | 29 ++
> drivers/gpu/drm/drm_fb_helper.c | 132 +++
> include/drm/drm_device.h | 6 ++
> include/drm/drm_fb_helper.h | 2 +
> 4 files changed, 169 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_client_modeset.c
> b/drivers/gpu/drm/drm_client_modeset.c
> index 31af5cf37a09..b8adfe87334b 100644
> --- a/drivers/gpu/drm/drm_client_modeset.c
> +++ b/drivers/gpu/drm/drm_client_modeset.c
> @@ -257,6 +257,34 @@ static void drm_client_connectors_enabled(struct
> drm_connector **connectors,
> enabled[i] = drm_connector_enabled(connectors[i], false);
> }
>
> +static void drm_client_match_edp_lid(struct drm_device *dev,
> + struct drm_connector **connectors,
> + unsigned int connector_count,
> + bool *enabled)
> +{
> + int i;
> +
> + for (i = 0; i < connector_count; i++) {
> + struct drm_connector *connector = connectors[i];
> +
> + switch (connector->connector_type) {
> + case DRM_MODE_CONNECTOR_LVDS:
> + case DRM_MODE_CONNECTOR_eDP:
> + if (!enabled[i])
> + continue;
> + break;
> + default:
> + continue;
> + }
> +
> + if (dev->lid_closed) {
> + drm_dbg_kms(dev, "[CONNECTOR:%d:%s] lid is closed,
> disabling\n",
> + connector->base.id, connector->name);
> + enabled[i] = false;
> + }
> + }
> +}
> +
> static bool drm_client_target_cloned(struct drm_device *dev,
>struct drm_connector **connectors,
>unsigned int connector_count,
> @@ -844,6 +872,7 @@ int drm_client_modeset_probe(struct drm_client_dev
> *client, unsigned int width,
> memset(crtcs, 0, connector_count * sizeof(*crtcs));
> memset(offsets, 0, connector_count * sizeof(*offsets));
>
> + drm_client_match_edp_lid(dev, connectors, connector_count,
> enabled);
> if (!drm_client_target_cloned(dev, connectors, connector_count,
> modes,
> offsets, enabled, width, height)
> &&
> !drm_client_target_preferred(dev, connectors,
> connector_count, modes,
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index d612133e2cf7..41dd5887599a 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -30,6 +30,8 @@
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> #include
> +#include
> +#include
> #include
> #include
> #include
> @@ -413,6 +415,128 @@ static void drm_fb_helper_damage_work(struct
> work_struct *work)
> drm_fb_helper_fb_dirty(helper);
> }
>
> +static void drm_fb_helper_lid_event(struct input_handle *handle, unsigned
> int type,
> + unsigned int code, int value)
> +{
> + if (type == EV_SW && code == SW_LID) {
> + struct drm_fb_helper *fb_helper = handle->handler->private;
> +
> + if (value != fb_helper->dev->lid_closed) {
> + fb_helper->dev->lid_closed = value;
> + queue_work(fb_helper->input_wq, &fb_helper->lid_work);
> + }
> + }
> +}
> +
> +struct drm_fb_lid {
> + struct input_handle handle;
> +};
> +
> +static int drm_fb_helper_lid_connect(struc
Re: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization
Hi Mario, kernel test robot noticed the following build errors: [auto build test ERROR on drm-misc/drm-misc-next] [also build test ERROR on linus/master v6.10-rc3 next-20240613] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/drm-fb-helper-Detect-when-lid-is-closed-during-initialization/20240613-132009 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20240613051700.1112-1-mario.limonciello%40amd.com patch subject: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization config: x86_64-buildonly-randconfig-003-20240614 (https://download.01.org/0day-ci/archive/20240616/[email protected]/config) compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240616/[email protected]/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ All errors (new ones prefixed by >>, old ones prefixed by <<): WARNING: modpost: missing MODULE_DESCRIPTION() in vmlinux.o WARNING: modpost: missing MODULE_DESCRIPTION() in arch/x86/events/rapl.o WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/locking/test-ww_mutex.o WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/rcu/rcutorture.o WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/time/time_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in mm/kasan/kasan_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in mm/kasan/kasan_test_module.o WARNING: modpost: missing MODULE_DESCRIPTION() in mm/kfence/kfence_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp737.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp775.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp850.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp852.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp861.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp863.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_cp1251.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_ascii.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-3.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-5.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-7.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_iso8859-15.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/nls_koi8-r.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/nls/mac-inuit.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/binfmt_script.o WARNING: modpost: missing MODULE_DESCRIPTION() in fs/isofs/isofs.o WARNING: modpost: missing MODULE_DESCRIPTION() in security/keys/trusted-keys/trusted.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/kunit/kunit.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/kunit/kunit-example-test.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/math/prime_numbers.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/crypto/libdes.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/test_ubsan.o WARNING: modpost: missing MODULE_DESCRIPTION() in lib/asn1_encoder.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/video/backlight/platform_lcd.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/video/fbdev/macmodes.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/clk_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/clk-gate_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/virtio/virtio.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/virtio/virtio_ring.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/regulator/max20411-regulator.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/agp/amd64-agp.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/agp/intel-agp.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/agp/intel-gtt.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/char/nvram.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/gpu/drm/tests/drm_hdmi_state_helper_test.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-kunit.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-ram.o WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/base/regmap/regmap-raw-ram.o WARNING: modpost: missing MODULE_DESCRIPTION() i
Re: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization
On 6/14/2024 09:17, Thomas Zimmermann wrote:
Hi
Am 14.06.24 um 15:47 schrieb Mario Limonciello:
On 6/14/2024 03:15, Thomas Zimmermann wrote:
Hi Mario
Am 13.06.24 um 07:17 schrieb Mario Limonciello:
If the lid on a laptop is closed when eDP connectors are populated
then it remains enabled when the initial framebuffer configuration
is built.
When creating the initial framebuffer configuration detect the
lid status and if it's closed disable any eDP connectors.
Also set up a workqueue to monitor for any future lid events.
After reading through this patchset, I think fbdev emulation is not
the right place for this code, as lid state is global.
You could put this into drm_client_modeset.c and track lid state per
client. drm_fb_helper_lid_work() would call the client's hotplug
callback. But preferable, lid state should be tracked per DRM device
in struct drm_mode_config and call drm_client_dev_hotplug() on each
lid-state event. Thoughts? Best regards Thomas
This is pretty similar to what I first did when moving from ACPI over
to generic input switch.
It works for the initial configuration. But I don't believe it makes
sense for the lid switch events because not all DRM clients will
"want" to respond to the lid switch events. By leaving it up to the
client for everything except fbdev emulation they can also track the
lid switch and decide the policy.
All our current clients do fbdev emulation, possibly others would be the
panic screen and a boot-up logo. A panic screen doesn't do actual mode
setting, but any other client would most likely want enable and disable
the display depending on the lid state. Having this code in the DRM
client helpers make perfect sense. But as it's global state, it makes no
sense to set this up per client. Hence the suggestion to manage this in
per DRM device.
It would also make sense to try to integrate this into the probe
helpers. When the lid state changes, the probe helpers would invoke the
driver's regular hotplugging code.
Got it; I'll do some experimentation with this change, thanks for the
feedback.
I also worry about what happens if the kernel does a hotplug callback
on lid events as well at the client choosing to do it. Don't we end up
with two modesets? So then I would think you need a handshake of some
sort to decide whether to do it for a given client where fbdev
emulation would opt in and then all other clients can choose to opt in
or not.
What do you mean by the kernel does a hotplug event and the client does
one? There should really only be one place to handle all of this. If we
end up with two modesets, we'd get an additional flicker when the lid
gets opened.
I'll see if my worry is founded after I move it all over.
Best regards
Thomas
Suggested-by: Dmitry Torokhov
Reported-by: Chris Bainbridge
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3349
Signed-off-by: Mario Limonciello
---
v2->v3:
* Use input device instead of ACPI device
* Detect lid open/close events
---
drivers/gpu/drm/drm_client_modeset.c | 29 ++
drivers/gpu/drm/drm_fb_helper.c | 132
+++
include/drm/drm_device.h | 6 ++
include/drm/drm_fb_helper.h | 2 +
4 files changed, 169 insertions(+)
diff --git a/drivers/gpu/drm/drm_client_modeset.c
b/drivers/gpu/drm/drm_client_modeset.c
index 31af5cf37a09..b8adfe87334b 100644
--- a/drivers/gpu/drm/drm_client_modeset.c
+++ b/drivers/gpu/drm/drm_client_modeset.c
@@ -257,6 +257,34 @@ static void
drm_client_connectors_enabled(struct drm_connector **connectors,
enabled[i] = drm_connector_enabled(connectors[i], false);
}
+static void drm_client_match_edp_lid(struct drm_device *dev,
+ struct drm_connector **connectors,
+ unsigned int connector_count,
+ bool *enabled)
+{
+ int i;
+
+ for (i = 0; i < connector_count; i++) {
+ struct drm_connector *connector = connectors[i];
+
+ switch (connector->connector_type) {
+ case DRM_MODE_CONNECTOR_LVDS:
+ case DRM_MODE_CONNECTOR_eDP:
+ if (!enabled[i])
+ continue;
+ break;
+ default:
+ continue;
+ }
+
+ if (dev->lid_closed) {
+ drm_dbg_kms(dev, "[CONNECTOR:%d:%s] lid is closed,
disabling\n",
+ connector->base.id, connector->name);
+ enabled[i] = false;
+ }
+ }
+}
+
static bool drm_client_target_cloned(struct drm_device *dev,
struct drm_connector **connectors,
unsigned int connector_count,
@@ -844,6 +872,7 @@ int drm_client_modeset_probe(struct
drm_client_dev *client, unsigned int width,
memset(crtcs, 0, connector_count * sizeof(*crtcs));
memset(offsets, 0, connector_count * sizeof(*offsets));
+ drm_client_match_edp_lid(dev, connectors, connector_count,
enabled);
Re: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization
Hi
Am 14.06.24 um 15:47 schrieb Mario Limonciello:
On 6/14/2024 03:15, Thomas Zimmermann wrote:
Hi Mario
Am 13.06.24 um 07:17 schrieb Mario Limonciello:
If the lid on a laptop is closed when eDP connectors are populated
then it remains enabled when the initial framebuffer configuration
is built.
When creating the initial framebuffer configuration detect the
lid status and if it's closed disable any eDP connectors.
Also set up a workqueue to monitor for any future lid events.
After reading through this patchset, I think fbdev emulation is not
the right place for this code, as lid state is global.
You could put this into drm_client_modeset.c and track lid state per
client. drm_fb_helper_lid_work() would call the client's hotplug
callback. But preferable, lid state should be tracked per DRM device
in struct drm_mode_config and call drm_client_dev_hotplug() on each
lid-state event. Thoughts? Best regards Thomas
This is pretty similar to what I first did when moving from ACPI over
to generic input switch.
It works for the initial configuration. But I don't believe it makes
sense for the lid switch events because not all DRM clients will
"want" to respond to the lid switch events. By leaving it up to the
client for everything except fbdev emulation they can also track the
lid switch and decide the policy.
All our current clients do fbdev emulation, possibly others would be the
panic screen and a boot-up logo. A panic screen doesn't do actual mode
setting, but any other client would most likely want enable and disable
the display depending on the lid state. Having this code in the DRM
client helpers make perfect sense. But as it's global state, it makes no
sense to set this up per client. Hence the suggestion to manage this in
per DRM device.
It would also make sense to try to integrate this into the probe
helpers. When the lid state changes, the probe helpers would invoke the
driver's regular hotplugging code.
I also worry about what happens if the kernel does a hotplug callback
on lid events as well at the client choosing to do it. Don't we end up
with two modesets? So then I would think you need a handshake of some
sort to decide whether to do it for a given client where fbdev
emulation would opt in and then all other clients can choose to opt in
or not.
What do you mean by the kernel does a hotplug event and the client does
one? There should really only be one place to handle all of this. If we
end up with two modesets, we'd get an additional flicker when the lid
gets opened.
Best regards
Thomas
Suggested-by: Dmitry Torokhov
Reported-by: Chris Bainbridge
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3349
Signed-off-by: Mario Limonciello
---
v2->v3:
* Use input device instead of ACPI device
* Detect lid open/close events
---
drivers/gpu/drm/drm_client_modeset.c | 29 ++
drivers/gpu/drm/drm_fb_helper.c | 132
+++
include/drm/drm_device.h | 6 ++
include/drm/drm_fb_helper.h | 2 +
4 files changed, 169 insertions(+)
diff --git a/drivers/gpu/drm/drm_client_modeset.c
b/drivers/gpu/drm/drm_client_modeset.c
index 31af5cf37a09..b8adfe87334b 100644
--- a/drivers/gpu/drm/drm_client_modeset.c
+++ b/drivers/gpu/drm/drm_client_modeset.c
@@ -257,6 +257,34 @@ static void
drm_client_connectors_enabled(struct drm_connector **connectors,
enabled[i] = drm_connector_enabled(connectors[i], false);
}
+static void drm_client_match_edp_lid(struct drm_device *dev,
+ struct drm_connector **connectors,
+ unsigned int connector_count,
+ bool *enabled)
+{
+ int i;
+
+ for (i = 0; i < connector_count; i++) {
+ struct drm_connector *connector = connectors[i];
+
+ switch (connector->connector_type) {
+ case DRM_MODE_CONNECTOR_LVDS:
+ case DRM_MODE_CONNECTOR_eDP:
+ if (!enabled[i])
+ continue;
+ break;
+ default:
+ continue;
+ }
+
+ if (dev->lid_closed) {
+ drm_dbg_kms(dev, "[CONNECTOR:%d:%s] lid is closed,
disabling\n",
+ connector->base.id, connector->name);
+ enabled[i] = false;
+ }
+ }
+}
+
static bool drm_client_target_cloned(struct drm_device *dev,
struct drm_connector **connectors,
unsigned int connector_count,
@@ -844,6 +872,7 @@ int drm_client_modeset_probe(struct
drm_client_dev *client, unsigned int width,
memset(crtcs, 0, connector_count * sizeof(*crtcs));
memset(offsets, 0, connector_count * sizeof(*offsets));
+ drm_client_match_edp_lid(dev, connectors, connector_count,
enabled);
if (!drm_client_target_cloned(dev, connectors,
connector_count, modes,
offsets, enabled, width, height) &&
!drm_client_target_preferred(dev, connect
Re: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization
On 6/14/2024 03:15, Thomas Zimmermann wrote:
Hi Mario
Am 13.06.24 um 07:17 schrieb Mario Limonciello:
If the lid on a laptop is closed when eDP connectors are populated
then it remains enabled when the initial framebuffer configuration
is built.
When creating the initial framebuffer configuration detect the
lid status and if it's closed disable any eDP connectors.
Also set up a workqueue to monitor for any future lid events.
After reading through this patchset, I think fbdev emulation is not the
right place for this code, as lid state is global.
You could put this into drm_client_modeset.c and track lid state per
client. drm_fb_helper_lid_work() would call the client's hotplug
callback. But preferable, lid state should be tracked per DRM device in
struct drm_mode_config and call drm_client_dev_hotplug() on each
lid-state event. Thoughts? Best regards Thomas
This is pretty similar to what I first did when moving from ACPI over to
generic input switch.
It works for the initial configuration. But I don't believe it makes
sense for the lid switch events because not all DRM clients will "want"
to respond to the lid switch events. By leaving it up to the client for
everything except fbdev emulation they can also track the lid switch and
decide the policy.
I also worry about what happens if the kernel does a hotplug callback on
lid events as well at the client choosing to do it. Don't we end up
with two modesets? So then I would think you need a handshake of some
sort to decide whether to do it for a given client where fbdev emulation
would opt in and then all other clients can choose to opt in or not.
Suggested-by: Dmitry Torokhov
Reported-by: Chris Bainbridge
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3349
Signed-off-by: Mario Limonciello
---
v2->v3:
* Use input device instead of ACPI device
* Detect lid open/close events
---
drivers/gpu/drm/drm_client_modeset.c | 29 ++
drivers/gpu/drm/drm_fb_helper.c | 132 +++
include/drm/drm_device.h | 6 ++
include/drm/drm_fb_helper.h | 2 +
4 files changed, 169 insertions(+)
diff --git a/drivers/gpu/drm/drm_client_modeset.c
b/drivers/gpu/drm/drm_client_modeset.c
index 31af5cf37a09..b8adfe87334b 100644
--- a/drivers/gpu/drm/drm_client_modeset.c
+++ b/drivers/gpu/drm/drm_client_modeset.c
@@ -257,6 +257,34 @@ static void drm_client_connectors_enabled(struct
drm_connector **connectors,
enabled[i] = drm_connector_enabled(connectors[i], false);
}
+static void drm_client_match_edp_lid(struct drm_device *dev,
+ struct drm_connector **connectors,
+ unsigned int connector_count,
+ bool *enabled)
+{
+ int i;
+
+ for (i = 0; i < connector_count; i++) {
+ struct drm_connector *connector = connectors[i];
+
+ switch (connector->connector_type) {
+ case DRM_MODE_CONNECTOR_LVDS:
+ case DRM_MODE_CONNECTOR_eDP:
+ if (!enabled[i])
+ continue;
+ break;
+ default:
+ continue;
+ }
+
+ if (dev->lid_closed) {
+ drm_dbg_kms(dev, "[CONNECTOR:%d:%s] lid is closed,
disabling\n",
+ connector->base.id, connector->name);
+ enabled[i] = false;
+ }
+ }
+}
+
static bool drm_client_target_cloned(struct drm_device *dev,
struct drm_connector **connectors,
unsigned int connector_count,
@@ -844,6 +872,7 @@ int drm_client_modeset_probe(struct drm_client_dev
*client, unsigned int width,
memset(crtcs, 0, connector_count * sizeof(*crtcs));
memset(offsets, 0, connector_count * sizeof(*offsets));
+ drm_client_match_edp_lid(dev, connectors, connector_count,
enabled);
if (!drm_client_target_cloned(dev, connectors,
connector_count, modes,
offsets, enabled, width, height) &&
!drm_client_target_preferred(dev, connectors,
connector_count, modes,
diff --git a/drivers/gpu/drm/drm_fb_helper.c
b/drivers/gpu/drm/drm_fb_helper.c
index d612133e2cf7..41dd5887599a 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -30,6 +30,8 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include
+#include
+#include
#include
#include
#include
@@ -413,6 +415,128 @@ static void drm_fb_helper_damage_work(struct
work_struct *work)
drm_fb_helper_fb_dirty(helper);
}
+static void drm_fb_helper_lid_event(struct input_handle *handle,
unsigned int type,
+ unsigned int code, int value)
+{
+ if (type == EV_SW && code == SW_LID) {
+ struct drm_fb_helper *fb_helper = handle->handler->private;
+
+ if (value != fb_helper->dev->lid_closed) {
+ fb_helper->dev->lid_closed = value;
+ queue_work(fb_helper->input_wq, &fb_helper->lid_work);
+ }
+ }
+}
+
+struc
Re: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization
Hi Mario
Am 13.06.24 um 07:17 schrieb Mario Limonciello:
If the lid on a laptop is closed when eDP connectors are populated
then it remains enabled when the initial framebuffer configuration
is built.
When creating the initial framebuffer configuration detect the
lid status and if it's closed disable any eDP connectors.
Also set up a workqueue to monitor for any future lid events.
After reading through this patchset, I think fbdev emulation is not the
right place for this code, as lid state is global.
You could put this into drm_client_modeset.c and track lid state per
client. drm_fb_helper_lid_work() would call the client's hotplug
callback. But preferable, lid state should be tracked per DRM device in
struct drm_mode_config and call drm_client_dev_hotplug() on each
lid-state event. Thoughts? Best regards Thomas
Suggested-by: Dmitry Torokhov
Reported-by: Chris Bainbridge
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3349
Signed-off-by: Mario Limonciello
---
v2->v3:
* Use input device instead of ACPI device
* Detect lid open/close events
---
drivers/gpu/drm/drm_client_modeset.c | 29 ++
drivers/gpu/drm/drm_fb_helper.c | 132 +++
include/drm/drm_device.h | 6 ++
include/drm/drm_fb_helper.h | 2 +
4 files changed, 169 insertions(+)
diff --git a/drivers/gpu/drm/drm_client_modeset.c
b/drivers/gpu/drm/drm_client_modeset.c
index 31af5cf37a09..b8adfe87334b 100644
--- a/drivers/gpu/drm/drm_client_modeset.c
+++ b/drivers/gpu/drm/drm_client_modeset.c
@@ -257,6 +257,34 @@ static void drm_client_connectors_enabled(struct
drm_connector **connectors,
enabled[i] = drm_connector_enabled(connectors[i], false);
}
+static void drm_client_match_edp_lid(struct drm_device *dev,
+struct drm_connector **connectors,
+unsigned int connector_count,
+bool *enabled)
+{
+ int i;
+
+ for (i = 0; i < connector_count; i++) {
+ struct drm_connector *connector = connectors[i];
+
+ switch (connector->connector_type) {
+ case DRM_MODE_CONNECTOR_LVDS:
+ case DRM_MODE_CONNECTOR_eDP:
+ if (!enabled[i])
+ continue;
+ break;
+ default:
+ continue;
+ }
+
+ if (dev->lid_closed) {
+ drm_dbg_kms(dev, "[CONNECTOR:%d:%s] lid is closed,
disabling\n",
+ connector->base.id, connector->name);
+ enabled[i] = false;
+ }
+ }
+}
+
static bool drm_client_target_cloned(struct drm_device *dev,
struct drm_connector **connectors,
unsigned int connector_count,
@@ -844,6 +872,7 @@ int drm_client_modeset_probe(struct drm_client_dev *client,
unsigned int width,
memset(crtcs, 0, connector_count * sizeof(*crtcs));
memset(offsets, 0, connector_count * sizeof(*offsets));
+ drm_client_match_edp_lid(dev, connectors, connector_count, enabled);
if (!drm_client_target_cloned(dev, connectors, connector_count,
modes,
offsets, enabled, width, height)
&&
!drm_client_target_preferred(dev, connectors,
connector_count, modes,
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index d612133e2cf7..41dd5887599a 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -30,6 +30,8 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include
+#include
+#include
#include
#include
#include
@@ -413,6 +415,128 @@ static void drm_fb_helper_damage_work(struct work_struct
*work)
drm_fb_helper_fb_dirty(helper);
}
+static void drm_fb_helper_lid_event(struct input_handle *handle, unsigned int type,
+ unsigned int code, int value)
+{
+ if (type == EV_SW && code == SW_LID) {
+ struct drm_fb_helper *fb_helper = handle->handler->private;
+
+ if (value != fb_helper->dev->lid_closed) {
+ fb_helper->dev->lid_closed = value;
+ queue_work(fb_helper->input_wq, &fb_helper->lid_work);
+ }
+ }
+}
+
+struct drm_fb_lid {
+ struct input_handle handle;
+};
+
+static int drm_fb_helper_lid_connect(struct input_handler *handler,
+struct input_dev *dev,
+const struct input_device_id *id)
+{
+ struct drm_fb_helper *fb_helper = handler->private;
+ struct drm_fb_lid *lid;
+ char *name;
+ int error;
+
+ lid = kzalloc(sizeof(*lid), GFP_KERNEL);
+ if (!lid)
+ return
Re: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization
Hi Mario, kernel test robot noticed the following build errors: [auto build test ERROR on drm-misc/drm-misc-next] [also build test ERROR on linus/master v6.10-rc3 next-20240613] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/drm-fb-helper-Detect-when-lid-is-closed-during-initialization/20240613-132009 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20240613051700.1112-1-mario.limonciello%40amd.com patch subject: [PATCH v3] drm/fb-helper: Detect when lid is closed during initialization config: sparc-randconfig-001-20240614 (https://download.01.org/0day-ci/archive/20240614/[email protected]/config) compiler: sparc64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240614/[email protected]/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ All errors (new ones prefixed by >>): sparc64-linux-ld: drivers/gpu/drm/drm_fb_helper.o: in function `drm_fb_helper_lid_disconnect': >> drm_fb_helper.c:(.text+0x76c): undefined reference to `input_close_device' >> sparc64-linux-ld: drm_fb_helper.c:(.text+0x774): undefined reference to >> `input_unregister_handle' sparc64-linux-ld: drivers/gpu/drm/drm_fb_helper.o: in function `drm_fb_helper_lid_connect': >> drm_fb_helper.c:(.text+0xed8): undefined reference to `input_register_handle' >> sparc64-linux-ld: drm_fb_helper.c:(.text+0xf24): undefined reference to >> `input_open_device' sparc64-linux-ld: drm_fb_helper.c:(.text+0xf9c): undefined reference to `input_unregister_handle' sparc64-linux-ld: drivers/gpu/drm/drm_fb_helper.o: in function `__drm_fb_helper_initial_config_and_unlock': >> drm_fb_helper.c:(.text+0x1d2c): undefined reference to >> `input_register_handler' sparc64-linux-ld: drivers/gpu/drm/drm_fb_helper.o: in function `drm_fb_helper_fini': >> drm_fb_helper.c:(.text+0x2ce4): undefined reference to >> `input_unregister_handler' -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
