Skip to contentSkip to conversation

dt-bindings: input: bindings for Adafruit Seesaw Gamepad

PATCH Superseded Anshul Dalal 3 participants 4 messages Nov 6, 2023 – Nov 11, 2023

Subsystems (4)

v7 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Anshul Dalal

author maintainer
#0 lore raw

PATCH v7 1/2 dt-bindings: input: bindings for Adafruit Seesaw Gamepad

Adds bindings for the Adafruit Seesaw Gamepad.

The gamepad functions as an i2c device with the default address of 0x50 and has an IRQ pin that can be enabled in the driver to allow for a rising edge trigger on each button press or joystick movement.

Product page:
https://www.adafruit.com/product/5743
Arduino driver:
https://github.com/adafruit/Adafruit_Seesaw

---

Changes for v7:
- no updates

Changes for v6:
- no updates

Changes for v5:
- Added link to the datasheet

Changes for v4:
- Fixed the URI for the id field
- Added interrupts property

Changes for v3:
- Updated id field to reflect updated file name from previous version
- Added reg property

Changes for v2:
- Renamed file to adafruit,seesaw-gamepad.yaml
- Removed quotes for $id and $schema
- Removed "Bindings for" from the description
- Changed node name to the generic name "joystick"
- Changed compatible to 'adafruit,seesaw-gamepad' instead of 'adafruit,seesaw_gamepad'

---
 .../input/adafruit,seesaw-gamepad.yaml        | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/adafruit,seesaw-gamepad.yaml
Documentation/devicetree/bindings/input/adafruit,seesaw-gamepad.yaml new file +60 -0
new file mode 100644
index 000000000000..3f0d1c5a3b9b
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/adafruit,seesaw-gamepad.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Adafruit Mini I2C Gamepad with seesaw
+
+maintainers:
+  - Anshul Dalal <[email protected]>
+
+description: |
+  Adafruit Mini I2C Gamepad
+
+    +-----------------------------+
+    |   ___                       |
+    |  /   \               (X)    |
+    | |  S  |  __   __  (Y)   (A) |
+    |  \___/  |ST| |SE|    (B)    |
+    |                             |
+    +-----------------------------+
+
+  S -> 10-bit percision bidirectional analog joystick
+  ST -> Start
+  SE -> Select
+  X, A, B, Y -> Digital action buttons
+
+  Datasheet: https://cdn-learn.adafruit.com/downloads/pdf/gamepad-qt.pdf
+  Product page: https://www.adafruit.com/product/5743
+  Arduino Driver: https://github.com/adafruit/Adafruit_Seesaw
+
+properties:
+  compatible:
+    const: adafruit,seesaw-gamepad
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+    description:
+      The gamepad's IRQ pin triggers a rising edge if interrupts are enabled.
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        joystick@50 {
+            compatible = "adafruit,seesaw-gamepad";
+            reg = <0x50>;
+        };
+    };
Signature · 1 line
2.42.0
author maintainer
#1 lore raw

PATCH v7 2/2 input: joystick: driver for Adafruit Seesaw Gamepad

Adds a driver for a mini gamepad that communicates over i2c, the gamepad has bidirectional thumb stick input and six buttons.

The gamepad chip utilizes the open framework from Adafruit called 'Seesaw' to transmit the ADC data for the joystick and digital pin state for the buttons. I have only implemented the functionality required to receive the thumb stick and button state.

Steps in reading the gamepad state over i2c:
1. Reset the registers
2. Set the pin mode of the pins specified by the BUTTON_MASK to input BUTTON_MASK: A bit-map for the six digital pins internally connected to the joystick buttons.
3. Enable internal pullup resistors for the BUTTON_MASK
4. Bulk set the pin state HIGH for BUTTON_MASK
5. Poll the device for button and joystick state done by:
seesaw_read_data(struct i2c_client *client, struct seesaw_data *data)

Product page:
https://www.adafruit.com/product/5743
Arduino driver:
https://github.com/adafruit/Adafruit_Seesaw

Driver tested on RPi Zero 2W

---

Changes for v7:
adafruit-seesaw.c
- Fixed formatting for macro definitions
- Made SEESAW_BUTTON_MASK static const
- Removed __be16 type for x and y fields of seesaw_data
- Used sparse_keymap implementation instead of custom keymap
- Used i2c_msg instead of i2c_master_send and recv in seesaw_register_read
- Use temporary variable adc_data to store data received from ADC
- Changed read_buf from u8[4] to __be32
- Use usleep_range instead of msleep
- Removed 'Reviewed-by: Thomas Weißschuh' due to large number of changes since last review
Kconfig:
- Added select INPUT_SPARSEKMAP

Changes for v6:
- Added TODO
- Removed clang-format directives
- Namespaced device buttons
- Removed char physical_path[32] field from struct seesaw_gamepad
- Added packed attribute to struct seesaw_data
- Moved from having booleans per button to single u32 button_state
- Added seesaw_button_description array to directly associate device buttons with respective keycodes
- Added wrapper functions seesaw_register_ around i2c_master_ API
- Ratelimited input error reporting with dev_err_ratelimited
- Removed of_device_id

Changes for v5:
- Added link to the datasheet
- Added debug log message when seesaw_read_data fails

Changes for v4:
- Changed 1UL << BUTTON_ to BIT(BUTTON_)
- Removed hardware_id field from struct seesaw_gamepad
- Removed redundant checks for the number of bytes written and received by i2c_master_send and i2c_master_recv
- Used get_unaligned_be32 to instantiate u32 result from read_buf
- Changed result & (1UL << BUTTON_) to
test_bit(BUTTON_, (long *)&result)
- Changed KBUILD_MODNAME in id-tables to SEESAW_DEVICE_NAME
- Fixed formatting issues
- Changed button reporting:
Since the gamepad had the action buttons in a non-standard layout:
(X)
(Y) (A)
(B)
Therefore moved to using generic directional action button event codes instead of BTN_[ABXY].

Changes for v3:
- no updates

Changes for v2:
adafruit-seesaw.c:
- Renamed file from 'adafruit_seesaw.c'
- Changed device name from 'seesaw_gamepad' to 'seesaw-gamepad'
- Changed count parameter for receiving joystick x on line 118:

    `2` to `sizeof(write_buf)`
- Fixed invalid buffer size on line 123 and 126:
    `data->y` to `sizeof(data->y)`

- Added comment for the mdelay(10) on line 169
- Changed inconsistent indentation on line 271
Kconfig:
- Fixed indentation for the help text
- Updated module name
Makefile:
- Updated module object file name
MAINTAINERS:
- Updated file name for the driver and bindings

---
 MAINTAINERS                              |   7 +
 drivers/input/joystick/Kconfig           |  10 +
 drivers/input/joystick/Makefile          |   1 +
 drivers/input/joystick/adafruit-seesaw.c | 315 +++++++++++++++++++++++
 4 files changed, 333 insertions(+)
 create mode 100644 drivers/input/joystick/adafruit-seesaw.c
MAINTAINERS +7 -0
index 81d5fc0bba68..cd4f9deb77e2 100644
@@ -441,6 +441,13 @@ W:	http://wiki.analog.com/AD7879
 W:	https://ez.analog.com/linux-software-drivers
 F:	drivers/input/touchscreen/ad7879.c
 
+ADAFRUIT MINI I2C GAMEPAD
+M:	Anshul Dalal <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/input/adafruit_seesaw.yaml
+F:	drivers/input/joystick/adafruit_seesaw.c
+
 ADDRESS SPACE LAYOUT RANDOMIZATION (ASLR)
 M:	Jiri Kosina <[email protected]>
 S:	Maintained
drivers/input/joystick/Kconfig +10 -0
index ac6925ce8366..7914bef999b7 100644
@@ -412,4 +412,14 @@ config JOYSTICK_SENSEHAT
 	  To compile this driver as a module, choose M here: the
 	  module will be called sensehat_joystick.
 
+config JOYSTICK_SEESAW
+	tristate "Adafruit Mini I2C Gamepad with Seesaw"
+	depends on I2C
+	select INPUT_SPARSEKMAP
+	help
+	  Say Y here if you want to use the Adafruit Mini I2C Gamepad.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called adafruit_seesaw.
+
 endif
drivers/input/joystick/Makefile +1 -0
index 3937535f0098..fdc653209542 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_JOYSTICK_N64)		+= n64joy.o
 obj-$(CONFIG_JOYSTICK_PSXPAD_SPI)	+= psxpad-spi.o
 obj-$(CONFIG_JOYSTICK_PXRC)		+= pxrc.o
 obj-$(CONFIG_JOYSTICK_QWIIC)		+= qwiic-joystick.o
+obj-$(CONFIG_JOYSTICK_SEESAW)		+= adafruit_seesaw.o
 obj-$(CONFIG_JOYSTICK_SENSEHAT)	+= sensehat-joystick.o
 obj-$(CONFIG_JOYSTICK_SIDEWINDER)	+= sidewinder.o
 obj-$(CONFIG_JOYSTICK_SPACEBALL)	+= spaceball.o
drivers/input/joystick/adafruit-seesaw.c new file +315 -0

315 lines not on this page · raw message

Signature · 1 line
2.42.0
#2 lore raw

Re: [PATCH v7 2/2] input: joystick: driver for Adafruit Seesaw Gamepad

kernel test robot noticed the following build errors:

Hi Anshul,

kernel test robot noticed the following build errors:

[auto build test ERROR on dtor-input/next]
[also build test ERROR on dtor-input/for-linus hid/for-next linus/master v6.6 next-20231107] [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/Anshul-Dalal/input-joystick-driver-for-Adafruit-Seesaw-Gamepad/20231107-004813
base:   https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
patch link:    https://lore.kernel.org/r/20231106164134.114668-2-anshulusr%40gmail.com
patch subject: [PATCH v7 2/2] input: joystick: driver for Adafruit Seesaw Gamepad
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20231108/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231108/[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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> make[6]: *** No rule to make target 'drivers/input/joystick/adafruit_seesaw.o', needed by 'drivers/input/joystick/built-in.a'.

make[6]: Target 'drivers/input/joystick/' not remade because of errors.

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Anshul Dalal

Hi!

Quoted 11 lines

Adds bindings for the Adafruit Seesaw Gamepad.

The gamepad functions as an i2c device with the default address of 0x50 and has an IRQ pin that can be enabled in the driver to allow for a rising edge trigger on each button press or joystick movement.

Product page:
https://www.adafruit.com/product/5743
Arduino driver:
https://github.com/adafruit/Adafruit_Seesaw

Documentation/devicetree/bindings/input/adafruit,seesaw-gamepad.yaml line 23

Quoted 9 lines
Documentation/devicetree/bindings/input/adafruit,seesaw-gamepad.yaml new file +9 -0
+    +-----------------------------+
+    |   ___                       |
+    |  /   \               (X)    |
+    | |  S  |  __   __  (Y)   (A) |
+    |  \___/  |ST| |SE|    (B)    |
+    |                             |
+    +-----------------------------+
+
+  S -> 10-bit percision bidirectional analog joystick

"preci..."

Best regards,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.