* Re: [Intel-gfx] [PATCH] ACPI button: provide lid status functions
[not found] ` <1252621686-27307-2-git-send-email-jbarnes@virtuousgeek.org>
@ 2009-09-11 1:02 ` ykzhao
2009-09-11 1:08 ` Jesse Barnes
2009-09-15 23:57 ` [PATCH] ACPI: make ACPI button funcs no-ops if not built in Jesse Barnes
0 siblings, 2 replies; 3+ messages in thread
From: ykzhao @ 2009-09-11 1:02 UTC (permalink / raw)
To: Jesse Barnes; +Cc: intel-gfx@lists.freedesktop.org, linux-acpi
On Fri, 2009-09-11 at 06:28 +0800, Jesse Barnes wrote:
cc: linux-acpi
> Some drivers need to know when a lid event occurs and get the current
> status. This can be useful for when a platform firmware clobbers some
> hardware state at lid time, and a driver needs to restore things when
> the lid is opened again.
>
> Acked-by: Matthew Garrett <mjg59@srcf.ucam.org>
> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
> ---
> drivers/acpi/button.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
> include/acpi/button.h | 10 ++++++++++
> 2 files changed, 53 insertions(+), 2 deletions(-)
> create mode 100644 include/acpi/button.h
>
> diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
> index 9195deb..ebb593e 100644
> --- a/drivers/acpi/button.c
> +++ b/drivers/acpi/button.c
> @@ -113,6 +113,9 @@ static const struct file_operations acpi_button_state_fops = {
> .release = single_release,
> };
>
> +static BLOCKING_NOTIFIER_HEAD(acpi_lid_notifier);
> +static struct acpi_device *lid_device;
> +
> /* --------------------------------------------------------------------------
> FS Interface (/proc)
> -------------------------------------------------------------------------- */
> @@ -229,11 +232,38 @@ static int acpi_button_remove_fs(struct acpi_device *device)
> /* --------------------------------------------------------------------------
> Driver Interface
> -------------------------------------------------------------------------- */
> +int acpi_lid_notifier_register(struct notifier_block *nb)
> +{
> + return blocking_notifier_chain_register(&acpi_lid_notifier, nb);
> +}
> +EXPORT_SYMBOL(acpi_lid_notifier_register);
> +
> +int acpi_lid_notifier_unregister(struct notifier_block *nb)
> +{
> + return blocking_notifier_chain_unregister(&acpi_lid_notifier, nb);
> +}
> +EXPORT_SYMBOL(acpi_lid_notifier_unregister);
> +
> +int acpi_lid_open(void)
> +{
> + acpi_status status;
> + unsigned long long state;
> +
> + status = acpi_evaluate_integer(lid_device->handle, "_LID", NULL,
> + &state);
> + if (ACPI_FAILURE(status))
> + return -ENODEV;
> +
> + return !!state;
> +}
> +EXPORT_SYMBOL(acpi_lid_open);
> +
> static int acpi_lid_send_state(struct acpi_device *device)
> {
> struct acpi_button *button = acpi_driver_data(device);
> unsigned long long state;
> acpi_status status;
> + int ret;
>
> status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state);
> if (ACPI_FAILURE(status))
> @@ -242,7 +272,12 @@ static int acpi_lid_send_state(struct acpi_device *device)
> /* input layer checks if event is redundant */
> input_report_switch(button->input, SW_LID, !state);
> input_sync(button->input);
> - return 0;
> +
> + ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device);
> + if (ret == NOTIFY_DONE)
> + ret = blocking_notifier_call_chain(&acpi_lid_notifier, state,
> + device);
> + return ret;
> }
>
> static void acpi_button_notify(struct acpi_device *device, u32 event)
> @@ -364,8 +399,14 @@ static int acpi_button_add(struct acpi_device *device)
> error = input_register_device(input);
> if (error)
> goto err_remove_fs;
> - if (button->type == ACPI_BUTTON_TYPE_LID)
> + if (button->type == ACPI_BUTTON_TYPE_LID) {
> acpi_lid_send_state(device);
> + /*
> + * This assumes there's only one lid device, or if there are
> + * more we only care about the last one...
> + */
> + lid_device = device;
> + }
>
> if (device->wakeup.flags.valid) {
> /* Button's GPE is run-wake GPE */
> diff --git a/include/acpi/button.h b/include/acpi/button.h
> new file mode 100644
> index 0000000..bb643a7
> --- /dev/null
> +++ b/include/acpi/button.h
> @@ -0,0 +1,10 @@
> +#ifndef ACPI_BUTTON_H
> +#define ACPI_BUTTON_H
It will be better that the function prototype is defined in the
following:
#if (defined(CONFIG_ACPI_BUTTON) || defined(CONFIG_ACPI_BUTTON_MODULE))
extern int acpi_lid_notifier_register(struct notifier_block *nb);
extern int acpi_lid_notifier_unregister(struct notifier_block *nb);
extern int acpi_lid_open(void);
#else
static inline int acpi_lid_notifier_register( ...) { return 0;}
static inline int acpi_lid_notifier_unregister(struct notifier_block
*nb) { return 0; }
static inline int acpi_lid_open(void) { return 1; }
#endif
> +
> +#include <linux/notifier.h>
> +
> +extern int acpi_lid_notifier_register(struct notifier_block *nb);
> +extern int acpi_lid_notifier_unregister(struct notifier_block *nb);
> +extern int acpi_lid_open(void);
> +
> +#endif /* ACPI_BUTTON_H */
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Intel-gfx] [PATCH] ACPI button: provide lid status functions
2009-09-11 1:02 ` [Intel-gfx] [PATCH] ACPI button: provide lid status functions ykzhao
@ 2009-09-11 1:08 ` Jesse Barnes
2009-09-15 23:57 ` [PATCH] ACPI: make ACPI button funcs no-ops if not built in Jesse Barnes
1 sibling, 0 replies; 3+ messages in thread
From: Jesse Barnes @ 2009-09-11 1:08 UTC (permalink / raw)
To: ykzhao; +Cc: intel-gfx@lists.freedesktop.org, linux-acpi
On Fri, 11 Sep 2009 09:02:02 +0800
ykzhao <yakui.zhao@intel.com> wrote:
> On Fri, 2009-09-11 at 06:28 +0800, Jesse Barnes wrote:
> cc: linux-acpi
> > Some drivers need to know when a lid event occurs and get the
> > current status. This can be useful for when a platform firmware
> > clobbers some hardware state at lid time, and a driver needs to
> > restore things when the lid is opened again.
> >
> > Acked-by: Matthew Garrett <mjg59@srcf.ucam.org>
> > Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
> > ---
> > drivers/acpi/button.c | 45
> > +++++++++++++++++++++++++++++++++++++++++++-- include/acpi/button.h
> > | 10 ++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-)
> > create mode 100644 include/acpi/button.h
> >
> > diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
> > index 9195deb..ebb593e 100644
> > --- a/drivers/acpi/button.c
> > +++ b/drivers/acpi/button.c
> > @@ -113,6 +113,9 @@ static const struct file_operations
> > acpi_button_state_fops = { .release = single_release,
> > };
> >
> > +static BLOCKING_NOTIFIER_HEAD(acpi_lid_notifier);
> > +static struct acpi_device *lid_device;
> > +
> > /*
> > --------------------------------------------------------------------------
> > FS Interface (/proc)
> > --------------------------------------------------------------------------
> > */ @@ -229,11 +232,38 @@ static int acpi_button_remove_fs(struct
> > acpi_device *device) /*
> > --------------------------------------------------------------------------
> > Driver Interface
> > --------------------------------------------------------------------------
> > */ +int acpi_lid_notifier_register(struct notifier_block *nb) +{
> > + return
> > blocking_notifier_chain_register(&acpi_lid_notifier, nb); +}
> > +EXPORT_SYMBOL(acpi_lid_notifier_register);
> > +
> > +int acpi_lid_notifier_unregister(struct notifier_block *nb)
> > +{
> > + return
> > blocking_notifier_chain_unregister(&acpi_lid_notifier, nb); +}
> > +EXPORT_SYMBOL(acpi_lid_notifier_unregister);
> > +
> > +int acpi_lid_open(void)
> > +{
> > + acpi_status status;
> > + unsigned long long state;
> > +
> > + status = acpi_evaluate_integer(lid_device->handle, "_LID",
> > NULL,
> > + &state);
> > + if (ACPI_FAILURE(status))
> > + return -ENODEV;
> > +
> > + return !!state;
> > +}
> > +EXPORT_SYMBOL(acpi_lid_open);
> > +
> > static int acpi_lid_send_state(struct acpi_device *device)
> > {
> > struct acpi_button *button = acpi_driver_data(device);
> > unsigned long long state;
> > acpi_status status;
> > + int ret;
> >
> > status = acpi_evaluate_integer(device->handle, "_LID",
> > NULL, &state); if (ACPI_FAILURE(status))
> > @@ -242,7 +272,12 @@ static int acpi_lid_send_state(struct
> > acpi_device *device) /* input layer checks if event is redundant */
> > input_report_switch(button->input, SW_LID, !state);
> > input_sync(button->input);
> > - return 0;
> > +
> > + ret = blocking_notifier_call_chain(&acpi_lid_notifier,
> > state, device);
> > + if (ret == NOTIFY_DONE)
> > + ret =
> > blocking_notifier_call_chain(&acpi_lid_notifier, state,
> > + device);
> > + return ret;
> > }
> >
> > static void acpi_button_notify(struct acpi_device *device, u32
> > event) @@ -364,8 +399,14 @@ static int acpi_button_add(struct
> > acpi_device *device) error = input_register_device(input);
> > if (error)
> > goto err_remove_fs;
> > - if (button->type == ACPI_BUTTON_TYPE_LID)
> > + if (button->type == ACPI_BUTTON_TYPE_LID) {
> > acpi_lid_send_state(device);
> > + /*
> > + * This assumes there's only one lid device, or if
> > there are
> > + * more we only care about the last one...
> > + */
> > + lid_device = device;
> > + }
> >
> > if (device->wakeup.flags.valid) {
> > /* Button's GPE is run-wake GPE */
> > diff --git a/include/acpi/button.h b/include/acpi/button.h
> > new file mode 100644
> > index 0000000..bb643a7
> > --- /dev/null
> > +++ b/include/acpi/button.h
> > @@ -0,0 +1,10 @@
> > +#ifndef ACPI_BUTTON_H
> > +#define ACPI_BUTTON_H
> It will be better that the function prototype is defined in the
> following:
>
> #if (defined(CONFIG_ACPI_BUTTON) ||
> defined(CONFIG_ACPI_BUTTON_MODULE)) extern int
> acpi_lid_notifier_register(struct notifier_block *nb); extern int
> acpi_lid_notifier_unregister(struct notifier_block *nb); extern int
> acpi_lid_open(void); #else
> static inline int acpi_lid_notifier_register( ...) { return 0;}
> static inline int acpi_lid_notifier_unregister(struct notifier_block
> *nb) { return 0; }
> static inline int acpi_lid_open(void) { return 1; }
> #endif
Oh right, I missed that part. I'll send a followup patch on top with
this fix (unless you beat me to it).
Thanks,
--
Jesse Barnes, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] ACPI: make ACPI button funcs no-ops if not built in
2009-09-11 1:02 ` [Intel-gfx] [PATCH] ACPI button: provide lid status functions ykzhao
2009-09-11 1:08 ` Jesse Barnes
@ 2009-09-15 23:57 ` Jesse Barnes
1 sibling, 0 replies; 3+ messages in thread
From: Jesse Barnes @ 2009-09-15 23:57 UTC (permalink / raw)
To: ykzhao; +Cc: intel-gfx@lists.freedesktop.org, linux-acpi, eric
On Fri, 11 Sep 2009 09:02:02 +0800
ykzhao <yakui.zhao@intel.com> wrote:
> > +#ifndef ACPI_BUTTON_H
> > +#define ACPI_BUTTON_H
> It will be better that the function prototype is defined in the
> following:
>
> #if (defined(CONFIG_ACPI_BUTTON) ||
> defined(CONFIG_ACPI_BUTTON_MODULE)) extern int
> acpi_lid_notifier_register(struct notifier_block *nb); extern int
> acpi_lid_notifier_unregister(struct notifier_block *nb); extern int
> acpi_lid_open(void); #else
> static inline int acpi_lid_notifier_register( ...) { return 0;}
> static inline int acpi_lid_notifier_unregister(struct notifier_block
> *nb) { return 0; }
> static inline int acpi_lid_open(void) { return 1; }
> #endif
Here you go.
--
Jesse Barnes, Intel Open Source Technology Center
Yakui pointed out that we don't properly no-op the ACPI button routines
if the button driver isn't built in. This will cause problems if ACPI
is disabled, so provide stub functions in that case.
Reported-by: ykzhao <yakui.zhao@intel.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
diff --git a/include/acpi/button.h b/include/acpi/button.h
index bb643a7..97eea0e 100644
--- a/include/acpi/button.h
+++ b/include/acpi/button.h
@@ -3,8 +3,23 @@
#include <linux/notifier.h>
+#if defined(CONFIG_ACPI_BUTTON) || defined(CONFIG_ACPI_BUTTON_MODULE)
extern int acpi_lid_notifier_register(struct notifier_block *nb);
extern int acpi_lid_notifier_unregister(struct notifier_block *nb);
extern int acpi_lid_open(void);
+#else
+static inline int acpi_lid_notifier_register(struct notifier_block *nb)
+{
+ return 0;
+}
+static inline int acpi_lid_notifier_unregister(struct notifier_block *nb)
+{
+ return 0;
+}
+static inline int acpi_lid_open(void)
+{
+ return 1;
+}
+#endif /* defined(CONFIG_ACPI_BUTTON) || defined(CONFIG_ACPI_BUTTON_MODULE) */
#endif /* ACPI_BUTTON_H */
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-09-16 0:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1252621686-27307-1-git-send-email-jbarnes@virtuousgeek.org>
[not found] ` <1252621686-27307-2-git-send-email-jbarnes@virtuousgeek.org>
2009-09-11 1:02 ` [Intel-gfx] [PATCH] ACPI button: provide lid status functions ykzhao
2009-09-11 1:08 ` Jesse Barnes
2009-09-15 23:57 ` [PATCH] ACPI: make ACPI button funcs no-ops if not built in Jesse Barnes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox