Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1680854pxb; Fri, 20 Aug 2021 11:10:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt4TYmiYRR/vSxq7ZXjM/ppfoq+p1oTKhWKl4j8y2VnuqTMdOjS5PbWDb0IeisBbZi3mH6 X-Received: by 2002:a05:6e02:1a6b:: with SMTP id w11mr13760289ilv.69.1629483042783; Fri, 20 Aug 2021 11:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629483042; cv=none; d=google.com; s=arc-20160816; b=aFqvp+92LbrkYLS6ViNFGcK+lgqeiLzMoA+a7xEMhqRrjBMFT6bEAsxW24RfqmymDR TokI4/xVKddfZ4jUZsm5Ss/4sca3O1GHyNgLLRuGKaz7For/GzF+i4CMRWpQ6rs1V72s KQl83TgVaFzH+xoTSX8qZPQvym/fzXZ2XZqRacHsVQ8xJSERO0GObrwweD4Q0/Injrl0 1LhYvIOPavWzj0gIawYJ7GMRKEJL7bt3V/yTyiWjxvLqkrFZX1FvsRLDzo9BMQjmyWcL OutpmblwdmCTPoZVuT+kT9CCoZVhan0VS/fQphnuHCNSRJs31m4+Gt+OuJgXs9ndCI1P B3/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=apjmD1xneUA7925DyFY2dWBIVZwhAXCudJdH1Ujm/QA=; b=fFmY/LoUWxLuWuVZLb3xvSEdQAubbGAWbrVEkDdqzslJBbycdMTjU8J0w/6CYCl4/F 2B8dYYwBM8yCguTyqJUVyI5lurFKUHJakiGtDzqMfrvkX+fkraAmyaRFg3ubyH7s2woT tRih+TKjHwTRz/qbhUp2gXlzqtjcr7n0MhvyLz0Pitr3eYVtsi1LMy+dpcY1y1VKyRrC M6wyDZ6C5s0XsCILiam+sik5qYN4ohVByE6W+0qUrN76gFLUzBlpseYnjHDMSVq0OAVy SEyWHt+NI781HvNt7ngTiEYKP4984WpgCrWUI605sGAY2fIwaU/iLJMluW8uO3wpmzyt y5ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=INiDjjLh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si8326521jav.71.2021.08.20.11.10.28; Fri, 20 Aug 2021 11:10:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=INiDjjLh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236015AbhHTSJK (ORCPT + 99 others); Fri, 20 Aug 2021 14:09:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57091 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235533AbhHTSJE (ORCPT ); Fri, 20 Aug 2021 14:09:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629482906; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=apjmD1xneUA7925DyFY2dWBIVZwhAXCudJdH1Ujm/QA=; b=INiDjjLhn5sa1L+rN/wj09xK2WT8CCFk8l0KO0Q0KLoGzWpsXbHN7Vjq/GEtzmNjdoR2ys 2Or1hqRvhwhqFpAorkgx58fpZLDlPvmvoLGeThqWEBmAyk7ebDzD2+UlP6+iG7nm2OSUfY HoQHqdyVnxGX0STkqLDbcFOvjJ4Njsg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-XZd279OoNMqEMF5gYHXk4A-1; Fri, 20 Aug 2021 14:08:24 -0400 X-MC-Unique: XZd279OoNMqEMF5gYHXk4A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88F7C8015C7; Fri, 20 Aug 2021 18:08:23 +0000 (UTC) Received: from cmirabil.remote.csb (unknown [10.22.9.218]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00EA05D9D5; Fri, 20 Aug 2021 18:08:21 +0000 (UTC) From: Charles Mirabile To: linux-kernel@vger.kernel.org Cc: Charles Mirabile , Dmitry Torokhov , linux-input@vger.kernel.org, Serge Schneider , Stefan Wahren , Nicolas Saenz Julienne , linux-rpi-kernel@lists.infradead.org, fedora-rpi@googlegroups.com, Mwesigwa Guma , Joel Savitz Subject: [RFC PATCH vs 2/4] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver Date: Fri, 20 Aug 2021 14:07:59 -0400 Message-Id: <20210820180801.561119-3-cmirabil@redhat.com> In-Reply-To: <20210820180801.561119-1-cmirabil@redhat.com> References: <20210820180801.561119-1-cmirabil@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch implements support for the joystick. It supports left/right/up/down/enter attached via i2c Signed-off-by: Charles Mirabile Signed-off-by: Mwesigwa Guma Signed-off-by: Joel Savitz --- drivers/input/joystick/Kconfig | 8 ++ drivers/input/joystick/Makefile | 1 + drivers/input/joystick/sensehat-joystick.c | 124 +++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 drivers/input/joystick/sensehat-joystick.c diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig index 3b23078bc7b5..d2f78353b74c 100644 --- a/drivers/input/joystick/Kconfig +++ b/drivers/input/joystick/Kconfig @@ -399,4 +399,12 @@ config JOYSTICK_N64 Say Y here if you want enable support for the four built-in controller ports on the Nintendo 64 console. +config JOYSTICK_SENSEHAT + tristate "Raspberry Pi Sense HAT joystick" + depends on GPIOLIB && INPUT + select MFD_SENSEHAT_CORE + + help + This is the joystick driver for the Raspberry Pi Sense HAT + endif diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile index 5174b8aba2dd..39c8b5c6e5ae 100644 --- a/drivers/input/joystick/Makefile +++ b/drivers/input/joystick/Makefile @@ -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_SENSEHAT) += sensehat-joystick.o obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o obj-$(CONFIG_JOYSTICK_SPACEBALL) += spaceball.o obj-$(CONFIG_JOYSTICK_SPACEORB) += spaceorb.o diff --git a/drivers/input/joystick/sensehat-joystick.c b/drivers/input/joystick/sensehat-joystick.c new file mode 100644 index 000000000000..4aca125bc29d --- /dev/null +++ b/drivers/input/joystick/sensehat-joystick.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Raspberry Pi Sense HAT joystick driver + * http://raspberrypi.org + * + * Copyright (C) 2015 Raspberry Pi + * Copyright (C) 2021 Charles Mirabile, Mwesigwa Guma, Joel Savitz + * + * Original Author: Serge Schneider + * Revised for upstream Linux by: Charles Mirabile, Mwesigwa Guma, Joel Savitz + */ + +#include +#include +#include +#include +#include +#include + +#include + +static unsigned char keymap[] = {KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,}; + +static irqreturn_t sensehat_joystick_report(int n, void *cookie) +{ + int i; + static s32 prev_keys; + struct sensehat *sensehat = cookie; + struct sensehat_joystick *sensehat_joystick = &sensehat->joystick; + s32 keys = sensehat_get_joystick_state(sensehat); + s32 changes = keys ^ prev_keys; + + prev_keys = keys; + for (i = 0; i < ARRAY_SIZE(keymap); ++i) { + if (changes & (1<keys_dev, + keymap[i], keys & (1<keys_dev); + return IRQ_HANDLED; +} + +static int sensehat_joystick_probe(struct platform_device *pdev) +{ + int ret; + int i; + struct sensehat *sensehat = dev_get_drvdata(&pdev->dev); + struct sensehat_joystick *sensehat_joystick = &sensehat->joystick; + + sensehat_joystick->keys_desc = devm_gpiod_get(&sensehat->i2c_client->dev, + "keys-int", GPIOD_IN); + if (IS_ERR(sensehat_joystick->keys_desc)) { + dev_warn(&pdev->dev, "Failed to get keys-int descriptor.\n"); + return PTR_ERR(sensehat_joystick->keys_desc); + } + + + sensehat_joystick->keys_dev = devm_input_allocate_device(&pdev->dev); + if (!sensehat_joystick->keys_dev) { + dev_err(&pdev->dev, "Could not allocate input device.\n"); + return -ENOMEM; + } + + for (i = 0; i < ARRAY_SIZE(keymap); i++) { + set_bit(keymap[i], + sensehat_joystick->keys_dev->keybit); + } + + sensehat_joystick->keys_dev->name = "Raspberry Pi Sense HAT Joystick"; + sensehat_joystick->keys_dev->phys = "rpi-sense-joy/input0"; + sensehat_joystick->keys_dev->id.bustype = BUS_I2C; + sensehat_joystick->keys_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); + sensehat_joystick->keys_dev->keycode = keymap; + sensehat_joystick->keys_dev->keycodesize = sizeof(unsigned char); + sensehat_joystick->keys_dev->keycodemax = ARRAY_SIZE(keymap); + + ret = input_register_device(sensehat_joystick->keys_dev); + if (ret) { + dev_err(&pdev->dev, "Could not register input device.\n"); + return ret; + } + + ret = gpiod_direction_input(sensehat_joystick->keys_desc); + if (ret) { + dev_err(&pdev->dev, "Could not set keys-int direction.\n"); + return ret; + } + + sensehat_joystick->keys_irq = gpiod_to_irq(sensehat_joystick->keys_desc); + if (sensehat_joystick->keys_irq < 0) { + dev_err(&pdev->dev, "Could not determine keys-int IRQ.\n"); + return sensehat_joystick->keys_irq; + } + + ret = devm_request_threaded_irq(&pdev->dev, sensehat_joystick->keys_irq, + NULL, sensehat_joystick_report, IRQF_TRIGGER_RISING | IRQF_ONESHOT, + "keys", sensehat); + + if (ret) { + dev_err(&pdev->dev, "IRQ request failed.\n"); + return ret; + } + return 0; +} + +static struct platform_device_id sensehat_joystick_device_id[] = { + { .name = "sensehat-joystick" }, + { }, +}; +MODULE_DEVICE_TABLE(platform, sensehat_joystick_device_id); + +static struct platform_driver sensehat_joystick_driver = { + .probe = sensehat_joystick_probe, + .driver = { + .name = "sensehat-joystick", + }, +}; + +module_platform_driver(sensehat_joystick_driver); + +MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver"); +MODULE_AUTHOR("Serge Schneider "); +MODULE_LICENSE("GPL"); -- 2.27.0