<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 15 July 2013 20:43, Rob Herring <span dir="ltr"><<a href="mailto:robherring2@gmail.com" target="_blank">robherring2@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 07/15/2013 10:36 AM, <a href="mailto:mathieu.poirier@linaro.org">mathieu.poirier@linaro.org</a> wrote:<br>
> From: "Mathieu J. Poirier" <<a href="mailto:mathieu.poirier@linaro.org">mathieu.poirier@linaro.org</a>><br>
><br>
> Adding a simple device tree binding for the specification of key sequences.<br>
> Definition of the keys found in the sequence are located in<br>
> 'include/uapi/linux/input.h'.<br>
><br>
> For the sysrq driver, holding the sequence of keys down for a specific amount of time<br>
> will reset the system.<br>
><br>
> Signed-off-by: Mathieu Poirier <<a href="mailto:mathieu.poirier@linaro.org">mathieu.poirier@linaro.org</a>><br>
> ---<br>
> changes for v4:<br>
>   - Moved seach of reset sequence nodes to a single call.<br>
> ---<br>
>  .../devicetree/bindings/input/input-reset.txt      | 34 ++++++++++++++<br>
>  drivers/tty/sysrq.c                                | 54 ++++++++++++++++++++++<br>
>  2 files changed, 88 insertions(+)<br>
>  create mode 100644 Documentation/devicetree/bindings/input/input-reset.txt<br>
><br>
> diff --git a/Documentation/devicetree/bindings/input/input-reset.txt b/Documentation/devicetree/bindings/input/input-reset.txt<br>
> new file mode 100644<br>
> index 0000000..79504af<br>
> --- /dev/null<br>
> +++ b/Documentation/devicetree/bindings/input/input-reset.txt<br>
> @@ -0,0 +1,34 @@<br>
> +Input: sysrq reset sequence<br>
> +<br>
> +A simple binding to represent a set of keys as described in<br>
> +include/uapi/linux/input.h.  This is to communicate a<br>
> +sequence of keys to the sysrq driver.  Upon holding the keys<br>
> +for a specified amount of time (if specified) the system is<br>
> +sync'ed and reset.<br>
> +<br>
> +Key sequences are global to the system but all the keys in a<br>
> +set must be coming from the same input device.<br>
> +<br>
> +The /chosen node should contain a 'linux,sysrq-reset-seq' child<br>
> +node to define a set of keys.<br>
> +<br>
> +Required property:<br>
> +sysrq-reset-seq: array of keycodes<br>
> +<br>
> +Optional property:<br>
> +timeout-ms: duration keys must be pressed together in microseconds<br>
<br>
milliseconds (ms) or microseconds (us)?<br>
<br></blockquote><div><br></div><div>Right, milliseconds.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> +before generating a sysrq<br>
> +<br>
> +Example:<br>
> +<br>
> + chosen {<br>
> +                linux,sysrq-reset-seq {<br>
> +                        keyset = <0x03<br>
> +                                  0x04<br>
> +                                  0x0a>;<br>
> +                        timeout-ms = <3000>;<br>
> +                };<br>
> +         };<br>
> +<br>
> +Would represent KEY_2, KEY_3 and KEY_9.<br>
> +<br>
> diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c<br>
> index b51c154..01a8729 100644<br>
> --- a/drivers/tty/sysrq.c<br>
> +++ b/drivers/tty/sysrq.c<br>
> @@ -44,6 +44,7 @@<br>
>  #include <linux/uaccess.h><br>
>  #include <linux/moduleparam.h><br>
>  #include <linux/jiffies.h><br>
> +#include <linux/of.h><br>
><br>
>  #include <asm/ptrace.h><br>
>  #include <asm/irq_regs.h><br>
> @@ -671,6 +672,50 @@ static void sysrq_detect_reset_sequence(struct sysrq_state *state,<br>
>       }<br>
>  }<br>
><br>
> +static void sysrq_of_get_keyreset_config(void)<br>
> +{<br>
> +     unsigned short key;<br>
> +     struct device_node *np;<br>
> +     const struct property *prop;<br>
> +     const __be32 *val;<br>
> +     int count, i;<br>
> +<br>
> +     np = of_find_node_by_path("/chosen/linux,sysrq-reset-seq");<br>
> +     if (!np) {<br>
> +             pr_debug("No sysrq node found");<br>
> +             goto out;<br>
> +     }<br>
> +<br>
> +     prop = of_find_property(np, "keyset", NULL);<br>
> +     if (!prop || !prop->value) {<br>
> +             pr_err("Invalid input keyset");<br>
> +             goto out;<br>
> +     }<br>
> +<br>
> +     count = prop->length / sizeof(u32);<br>
> +     val = prop->value;<br>
<br>
None of the existing helpers to retrieve property arrays doesn't work here?<br></blockquote><div><br></div><div>The problem here is that we never know how long the sequence will be.  As such the 'of_property_read_uXY_array' functions won't work.  Or maybe you're referring to another set of helpers... If so, please clarify.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> +<br>
> +     if (count > SYSRQ_KEY_RESET_MAX)<br>
> +             count = SYSRQ_KEY_RESET_MAX;<br>
> +<br>
> +     /* reset in case a __weak definition was present */<br>
> +     sysrq_reset_seq_len = 0;<br>
> +<br>
> +     for (i = 0; i < count; i++) {<br>
> +             key = (unsigned short)be32_to_cpup(val++);<br>
> +             if (key == KEY_RESERVED || key > KEY_MAX)<br>
> +                     break;<br>
> +<br>
> +             sysrq_reset_seq[sysrq_reset_seq_len++] = key;<br>
> +     }<br>
> +<br>
> +     /* get reset timeout if any */<br>
> +     of_property_read_u32(np, "timeout-ms", &sysrq_reset_downtime_ms);<br>
> +<br>
> + out:<br>
> +     ;<br>
> +}<br>
> +<br>
>  static void sysrq_reinject_alt_sysrq(struct work_struct *work)<br>
>  {<br>
>       struct sysrq_state *sysrq =<br>
> @@ -688,6 +733,7 @@ static void sysrq_reinject_alt_sysrq(struct work_struct *work)<br>
>               input_inject_event(handle, EV_KEY, KEY_SYSRQ, 1);<br>
>               input_inject_event(handle, EV_SYN, SYN_REPORT, 1);<br>
><br>
> +<br>
<br>
spurious ws change </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
>               input_inject_event(handle, EV_KEY, KEY_SYSRQ, 0);<br>
>               input_inject_event(handle, EV_KEY, alt_code, 0);<br>
>               input_inject_event(handle, EV_SYN, SYN_REPORT, 1);<br>
> @@ -903,6 +949,7 @@ static inline void sysrq_register_handler(void)<br>
>       int error;<br>
>       int i;<br>
><br>
> +     /* first check if a __weak interface was instantiated */<br>
>       for (i = 0; i < ARRAY_SIZE(sysrq_reset_seq); i++) {<br>
>               key = platform_sysrq_reset_seq[i];<br>
>               if (key == KEY_RESERVED || key > KEY_MAX)<br>
> @@ -911,6 +958,13 @@ static inline void sysrq_register_handler(void)<br>
>               sysrq_reset_seq[sysrq_reset_seq_len++] = key;<br>
>       }<br>
><br>
> +     /*<br>
> +      * DT configuration takes precedence over anything<br>
> +      * that would have been defined via the __weak<br>
> +      * interface<br>
> +      */<br>
> +     sysrq_of_get_keyreset_config();<br>
> +<br>
>       error = input_register_handler(&sysrq_handler);<br>
>       if (error)<br>
>               pr_err("Failed to register input handler, error %d", error);<br>
><br>
<br>
</blockquote></div><br></div></div>