Linux Input/HID development
 help / color / mirror / Atom feed
From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
To: Bastien Nocera <hadess@hadess.net>,
	Darren Hart <dvhart@infradead.org>,
	ibm-acpi-devel@lists.sourceforge.net,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-input <linux-input@vger.kernel.org>,
	Jiri Kosina <jkosina@suse.cz>
Subject: Re: [PATCH 2/4] thinkpad_acpi: Factor out get/set adaptive kbd mode
Date: Mon, 02 Mar 2015 14:14:54 -0300	[thread overview]
Message-ID: <1425316494.517241.234431241.0FD71073@webmail.messagingengine.com> (raw)
In-Reply-To: <1425303922.16791.33.camel@hadess.net>

On Mon, Mar 2, 2015, at 10:45, Bastien Nocera wrote:
> Move the getting/setting of the adaptive keyboard mode to separate
> functions, so that we can reuse them later through sysfs attributes.
> 
> Signed-off-by: Bastien Nocera <hadess@hadess.net>

Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>

> ---
>  drivers/platform/x86/thinkpad_acpi.c | 61
>  ++++++++++++++++++++++--------------
>  1 file changed, 38 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/platform/x86/thinkpad_acpi.c
> b/drivers/platform/x86/thinkpad_acpi.c
> index 763aef0..5dea4c2 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -3483,6 +3483,32 @@ static const int adaptive_keyboard_modes[] = {
>  static bool adaptive_keyboard_mode_is_saved;
>  static int adaptive_keyboard_prev_mode;
>  
> +static int adaptive_keyboard_get_mode(void)
> +{
> +       int mode = 0;
> +
> +       if (!acpi_evalf(hkey_handle, &mode, "GTRW", "dd", 0)) {
> +               pr_err("Cannot read adaptive keyboard mode\n");
> +               return -EIO;
> +       }
> +
> +       return mode;
> +}
> +
> +static int adaptive_keyboard_set_mode(int new_mode)
> +{
> +       if (new_mode < 0 ||
> +               new_mode > LAYFLAT_MODE)
> +               return -EINVAL;
> +
> +       if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd", new_mode)) {
> +               pr_err("Cannot set adaptive keyboard mode\n");
> +               return -EIO;
> +       }
> +
> +       return 0;
> +}
> +
>  static int adaptive_keyboard_get_next_mode(int mode)
>  {
>  	size_t i;
> @@ -3512,39 +3538,28 @@ static bool
> adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
>  			new_mode = adaptive_keyboard_prev_mode;
>  			adaptive_keyboard_mode_is_saved = false;
>  		} else {
> -                       if (!acpi_evalf(
> -                                       hkey_handle, &current_mode,
> -                                       "GTRW", "dd", 0)) {
> -                               pr_err("Cannot read adaptive keyboard
> mode\n");
> +                       current_mode = adaptive_keyboard_get_mode();
> +                       if (current_mode < 0)
>  				return false;
> -                       } else {
> -                               new_mode =
> adaptive_keyboard_get_next_mode(
> -                                               current_mode);
> -                       }
> +                       new_mode = adaptive_keyboard_get_next_mode(
> +                                       current_mode);
>  		}
>  
> -               if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd",
> new_mode)) {
> -                       pr_err("Cannot set adaptive keyboard mode\n");
> +               if (adaptive_keyboard_set_mode(new_mode) < 0)
>  			return false;
> -               }
>  
>  		return true;
>  
>  	case DFR_SHOW_QUICKVIEW_ROW:
> -               if (!acpi_evalf(hkey_handle,
> -                               &adaptive_keyboard_prev_mode,
> -                               "GTRW", "dd", 0)) {
> -                       pr_err("Cannot read adaptive keyboard mode\n");
> +               current_mode = adaptive_keyboard_get_mode();
> +               if (current_mode < 0)
>  			return false;
> -               } else {
> -                       adaptive_keyboard_mode_is_saved = true;
>  
> -                       if (!acpi_evalf(hkey_handle,
> -                                       NULL, "STRW", "vd",
> FUNCTION_MODE)) {
> -                               pr_err("Cannot set adaptive keyboard
> mode\n");
> -                               return false;
> -                       }
> -               }
> +               adaptive_keyboard_prev_mode = current_mode;
> +               adaptive_keyboard_mode_is_saved = true;
> +
> +               if (adaptive_keyboard_set_mode (FUNCTION_MODE) < 0)
> +                       return false;
>  		return true;
>  
>  	default:
> -- 
> 2.1.0
> 
> 


-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

      parent reply	other threads:[~2015-03-02 17:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-02 13:45 [PATCH 2/4] thinkpad_acpi: Factor out get/set adaptive kbd mode Bastien Nocera
2015-03-02 17:12 ` ibm-acpi
2015-03-02 17:14 ` Henrique de Moraes Holschuh [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425316494.517241.234431241.0FD71073@webmail.messagingengine.com \
    --to=hmh@hmh.eng.br \
    --cc=dvhart@infradead.org \
    --cc=hadess@hadess.net \
    --cc=ibm-acpi-devel@lists.sourceforge.net \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox