Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp902945pxt; Fri, 6 Aug 2021 17:30:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyW+WZJxAPi5kOV64Dty3HY8MWRhF0r2/bSCQYBKSwfrR9aSsUXEZbIGEKOiqbo+AZLUCv X-Received: by 2002:a05:6638:62c:: with SMTP id h12mr12600528jar.0.1628296219980; Fri, 06 Aug 2021 17:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628296219; cv=none; d=google.com; s=arc-20160816; b=GCf0BlTnWiGyt/ZR5loA/araIIN0XdBtrICkuuuUfxYMMxHyGwAg//BJyyk7tknhin todXP80am5Vp3vO86sfLzC5JAVcng2A8W4nc5HRIiXL8jsYxQ2pGrsvjyDmhtiyIEz6g GjmDM+J4QMGdmFV8T0CbrEig8MgbdwG1taNXOFiZ7W3beCOvUt1Q/H2Hzl74LnUknUYH AOW4LAlEqehiL5nQdMo17K/0wKqDGzQr+wS263FYrlxijNnXBh3yAFUj1GwMviFRDbqz 7hhLeCKiVDzIvXxL8CqQHBTcSHjY94xgtKQge10TDmpTt3snI+9so5Q2LmBfM9OYWfpX OLOw== 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=pn1hyRJM8BURrd6NXAk48E748YVbCwToMWhQgVC9nvY=; b=soCkO+V/D1HdxY0N6Jq6DhH+yx0WJ7dI5/5/jmM/qqnQW6vTxymqTl56pXHeOQGDWZ mxy42oFe+Uj/tm4ilCHUPh+q4Jms1nLdF/xIUroDq4itJgIQaTGT3U344I1brrg2EtM4 PIPzWMTvov484uTNVP+K2rAVXSKDl9cdc5dpkQM3JzqckNtiLTPL18linytJKCugsLC5 OiuqVR6tPDf1Ej7AHMAiiJatGDqicbSI5rJZa8WgcNS3g4xGEF4x8Tb2kR3qAzn7LgDU G8DIMiH6oBCRXomoMwIn15t8DxKqiXGthzktwtIn6NVsOlyvRTNhcvb3tuzNox2cACI4 3zxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MsQlFqPj; 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 r3si10550580jan.7.2021.08.06.17.30.08; Fri, 06 Aug 2021 17:30:19 -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=MsQlFqPj; 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 S229833AbhHGA2P (ORCPT + 99 others); Fri, 6 Aug 2021 20:28:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57714 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbhHGA2N (ORCPT ); Fri, 6 Aug 2021 20:28:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628296076; 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=pn1hyRJM8BURrd6NXAk48E748YVbCwToMWhQgVC9nvY=; b=MsQlFqPjEiUEFA4WwaFjeOEP0nJs/kAZC8IVfKoU0bIVP+QylXbcAtPN/DxQxUBtlM/Bl0 Z/qiOJeFjgbq6jBKYIxEDRLsdGwH73iHNxSpw0mVNwfSsBjvwJ+IxODKP3TbZ6RgToquLz GJApo3TqJAUN9ZvSgMmv2q4wvHMlBLU= 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-162-2JzGYSByMrma0DISvdHSOg-1; Fri, 06 Aug 2021 20:27:55 -0400 X-MC-Unique: 2JzGYSByMrma0DISvdHSOg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0101B593A8; Sat, 7 Aug 2021 00:27:54 +0000 (UTC) Received: from jsavitz.bos.com (unknown [10.22.8.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 311E969FAD; Sat, 7 Aug 2021 00:27:53 +0000 (UTC) From: Joel Savitz To: linux-kernel@vger.kernel.org Cc: Joel Savitz , Lee Jones , Stefan Wahren , Nicolas Saenz Julienne , linux-rpi-kernel@lists.infradead.org, fedora-rpi@googlegroups.com, Charles Mirabile , Mwesigwa Guma Subject: [RFC PATCH 2/3] drivers/mfd: rpisense: Raspberry Pi senseHAT joystick driver Date: Fri, 6 Aug 2021 20:27:21 -0400 Message-Id: <20210807002722.2634585-3-jsavitz@redhat.com> In-Reply-To: <20210807002722.2634585-1-jsavitz@redhat.com> References: <20210807002722.2634585-1-jsavitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch implements support for the joystick, including a threaded IRQ routine. Signed-off-by: Charles Mirabile Signed-off-by: Mwesigwa Guma Signed-off-by: Joel Savitz --- drivers/mfd/Makefile | 1 + drivers/mfd/rpisense-js.c | 132 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 drivers/mfd/rpisense-js.c diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 76f9a9221241..71356153ccdc 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -264,6 +264,7 @@ obj-$(CONFIG_MFD_ROHM_BD957XMUF) += rohm-bd9576.o obj-$(CONFIG_MFD_STMFX) += stmfx.o obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o obj-$(CONFIG_MFD_RPISENSE) += rpisense-core.o +obj-$(CONFIG_MFD_RPISENSE) += rpisense-js.o obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o diff --git a/drivers/mfd/rpisense-js.c b/drivers/mfd/rpisense-js.c new file mode 100644 index 000000000000..c6c97bff118c --- /dev/null +++ b/drivers/mfd/rpisense-js.c @@ -0,0 +1,132 @@ +// 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 rpisense_js_report(int n, void *cookie) +{ + int i; + static s32 prev_keys; + struct rpisense *rpisense = cookie; + struct rpisense_js *rpisense_js = &rpisense->joystick; + s32 keys = rpisense_get_joystick_state(rpisense); + 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 rpisense_js_probe(struct platform_device *pdev) +{ + int ret; + int i; + struct rpisense *rpisense = dev_get_drvdata(&pdev->dev); + struct rpisense_js *rpisense_js = &rpisense->joystick; + + rpisense_js->keys_desc = devm_gpiod_get(&rpisense->i2c_client->dev, + "keys-int", GPIOD_IN); + if (IS_ERR(rpisense_js->keys_desc)) { + dev_warn(&pdev->dev, "Failed to get keys-int descriptor.\n"); + return PTR_ERR(rpisense_js->keys_desc); + } + + + rpisense_js->keys_dev = devm_input_allocate_device(&pdev->dev); + if (rpisense_js->keys_dev == NULL) { + dev_err(&pdev->dev, "Could not allocate input device.\n"); + return -ENOMEM; + } + + for (i = 0; i < ARRAY_SIZE(keymap); i++) { + set_bit(keymap[i], + rpisense_js->keys_dev->keybit); + } + + rpisense_js->keys_dev->name = "Raspberry Pi Sense HAT Joystick"; + rpisense_js->keys_dev->phys = "rpi-sense-joy/input0"; + rpisense_js->keys_dev->id.bustype = BUS_I2C; + rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); + rpisense_js->keys_dev->keycode = keymap; + rpisense_js->keys_dev->keycodesize = sizeof(unsigned char); + rpisense_js->keys_dev->keycodemax = ARRAY_SIZE(keymap); + + ret = input_register_device(rpisense_js->keys_dev); + if (ret) { + dev_err(&pdev->dev, "Could not register input device.\n"); + return ret; + } + + ret = gpiod_direction_input(rpisense_js->keys_desc); + if (ret) { + dev_err(&pdev->dev, "Could not set keys-int direction.\n"); + return ret; + } + + rpisense_js->keys_irq = gpiod_to_irq(rpisense_js->keys_desc); + if (rpisense_js->keys_irq < 0) { + dev_err(&pdev->dev, "Could not determine keys-int IRQ.\n"); + return rpisense_js->keys_irq; + } + + ret = devm_request_threaded_irq(&pdev->dev, rpisense_js->keys_irq, + NULL, rpisense_js_report, IRQF_TRIGGER_RISING | IRQF_ONESHOT, + "keys", rpisense); + + if (ret) { + dev_err(&pdev->dev, "IRQ request failed.\n"); + return ret; + } + return 0; +} + +#ifdef CONFIG_OF +static const struct of_device_id rpisense_js_id[] = { + { .compatible = "rpi,rpi-sense-js" }, + { }, +}; +MODULE_DEVICE_TABLE(of, rpisense_js_id); +#endif + +static struct platform_device_id rpisense_js_device_id[] = { + { .name = "rpi-sense-js" }, + { }, +}; +MODULE_DEVICE_TABLE(platform, rpisense_js_device_id); + +static struct platform_driver rpisense_js_driver = { + .probe = rpisense_js_probe, + .driver = { + .name = "rpi-sense-js", + }, +}; + +module_platform_driver(rpisense_js_driver); + +MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver"); +MODULE_AUTHOR("Serge Schneider "); +MODULE_LICENSE("GPL"); -- 2.27.0