# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
# Copyright 2019-2022 AKSys.co.kr
%YAML 1.2
---
$id: "http://devicetree.org/schemas/input/aks,adc-joystick.yaml#"
$schema: "http://devicetree.org/meta-schemas/core.yaml#"

title: support  ADC attached joystick and gpio keys also

maintainers:
  - Daniel.G <daniel@aksys.co.kr>

description: |
  Bindings for joystick devices connected to ADC controllers supporting the Industrial I/O subsystem.
  Support GPIO keys input also

properties:
  status:
    description: |
      enable('ok') or disable('disable') this section

  compatible:
    const: aks,joystick_mt

  label:
    const: aks,joystick_mt

  pinctrl-names:
    description: |
      list the pre-defined pinctrl arrays names

  pinctrl-0:
    description: |
      the pre-defined pinctrl arrays for active status

  pinctrl-1:
    description: |
      the pre-defined pinctrl arrays for sleep status

  io-channels:
    minItems: 1
    maxItems: 1024
    description: |
      List of phandle and IIO specifier pairs.
      Each pair defines one ADC channel to which a joystick axis is connected.
      See
      https://github.com/devicetree-org/dt-schema/blob/master/schemas/iio/iio-consumer.yaml
      for details.

  '#address-cells':
    const: 1

  '#size-cells':
    const: 0

required:
  - compatible
  - pinctrl-names
  - pinctrl-0
  - pinctrl-1
  - io-channels
  - '#address-cells'
  - '#size-cells'

additionalProperties: false

patternProperties:
  "^axis@[0-9a-f]+$":
    type: object
    description: |
      Represents a joystick axis bound to the given ADC channel.
      For each entry in the io-channels list, one axis subnode with a matching
      reg property must be specified.

  "^axis@[0-9a-f]+$":
    type: object
    description: |
      Represents a joystick axis bound to the given ADC channel.
      For each entry in the io-channels list, one axis subnode with a matching
      reg property must be specified.

    properties:
      reg:
        minimum: 0
        maximum: 1023
        description: Index of an io-channels list entry bound to this axis.

      linux,code:
        $ref: /schemas/types.yaml#/definitions/uint32
        description: EV_ABS specific event code generated by the axis.

      abs-range:
        allOf:
          - $ref: /schemas/types.yaml#/definitions/uint32-array
          - items:
              - description: minimum value
              - description: maximum value
        description: |
          Minimum and maximum values produced by the axis.
          For an ABS_X axis this will be the left-most and right-most
          inclination of the joystick. If min > max, it is left to userspace to
          treat the axis as inverted.
          This property is interpreted as two signed 32 bit values.

      abs-fuzz:
        $ref: /schemas/types.yaml#/definitions/uint32
        description: |
          Amount of noise in the input value.
          Omitting this property indicates the axis is precise.

      abs-flat:
        $ref: /schemas/types.yaml#/definitions/uint32
        description: |
          Axial "deadzone", or area around the center position, where the axis
          is considered to be at rest.
          Omitting this property indicates the axis always returns to exactly
          the center position.

    required:
      - reg
      - linux,code
      - abs-range

    additionalProperties: false

examples:
  - |
    #include <dt-bindings/iio/adc/ingenic,adc.h>
    #include <dt-bindings/input/input.h>

    aks_joystick_mt: aks_joystick_mt {
        status = "ok";
        compatible = "aks,joystick_mt";
        label = "aks-joystick-mt";
        pinctrl-names = "default","sleep";
        pinctrl-0 = <&gpio_key_active>;
        pinctrl-1 = <&gpio_key_suspend>;
        io-channels = <&adcl 4>, <&adcl 5>, <&adcl 6>, <&adcr 4>, <&adcr 5>, <&adcr 6>;
        #address-cells = <1>;
        #size-cells = <0>;

        btn_mode {
            label = "btn_mode";
            gpios = <&gpios 15 GPIO_ACTIVE_LOW>;
            linux,input-type = <1>;
            linux,code = <BTN_MODE>;
            debounce-interval = <15>;
        };

        axis@0 {
            reg = <0>;
            index = <0>;
            linux,code = <ABS_X>;
            abs-range = <580 2040>;
            abs-fuzz = <5>;
            abs-flat = <5>;
        };

        axis@1 {
            reg = <1>;
            index = <1>;
            linux,code = <ABS_Y>;
            abs-range = <630 2040>;
            abs-fuzz = <5>;
            abs-flat = <5>;
        };
    };
