From patchwork Sat Apr 20 12:23:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Weiss X-Patchwork-Id: 10910321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB19B1390 for ; Sat, 20 Apr 2019 12:24:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B66CA28917 for ; Sat, 20 Apr 2019 12:24:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8DB528D5D; Sat, 20 Apr 2019 12:24:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BE3828917 for ; Sat, 20 Apr 2019 12:24:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727779AbfDTMYQ (ORCPT ); Sat, 20 Apr 2019 08:24:16 -0400 Received: from mail.z3ntu.xyz ([128.199.32.197]:46428 "EHLO mail.z3ntu.xyz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726082AbfDTMYQ (ORCPT ); Sat, 20 Apr 2019 08:24:16 -0400 Received: from localhost.localdomain (91-115-28-155.adsl.highway.telekom.at [91.115.28.155]) by mail.z3ntu.xyz (Postfix) with ESMTPSA id 1F776C17A5; Sat, 20 Apr 2019 12:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=z3ntu.xyz; s=z3ntu; t=1555763053; bh=U/6xQAEPyP1EsnAjW4EqK13j+ZKhfQvV0IwSY8CpWEk=; h=From:To:Cc:Subject:Date; b=W/vcSW1w5ZNHo1cbiwivBW18eUdf1jQrpGnDl20De+Ki/yO4QJSV2fi9NyxwkfVnd tXou1MywKLQKzAbL2DvVJs8yq1SbCDcC42AI7+iMGlD2u4hCC3BHAeZRz3IUumeAZ/ MF6U2Aaa09FsBxvXKpeoWusmV0kZaEGN9hCyLvP4= From: Luca Weiss Cc: Dmitry Torokhov , Rob Herring , Mark Rutland , Mauro Carvalho Chehab , Pascal PAILLET-LME , Coly Li , Lee Jones , Xiaotong Lu , Brian Masney , Rob Herring , Baolin Wang , David Brown , linux-arm-msm@vger.kernel.org (open list:ARM/QUALCOMM SUPPORT), linux-input@vger.kernel.org (open list:INPUT (KEYBOARD, MOUSE, JOYSTICK , TOUCHSCREEN)...), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-kernel@vger.kernel.org (open list), Luca Weiss Subject: [PATCH v4 1/3] dt-bindings: input: add GPIO controllable vibrator Date: Sat, 20 Apr 2019 14:23:31 +0200 Message-Id: <20190420122333.23662-1-luca@z3ntu.xyz> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide a simple driver for GPIO controllable vibrators. It will be used by the Fairphone 2. Signed-off-by: Luca Weiss Reviewed-by: Rob Herring --- Changes from v3: - Convert .txt based doc to the new yaml based format .../bindings/input/gpio-vibrator.yaml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/gpio-vibrator.yaml diff --git a/Documentation/devicetree/bindings/input/gpio-vibrator.yaml b/Documentation/devicetree/bindings/input/gpio-vibrator.yaml new file mode 100644 index 000000000000..bca1b6ea07a4 --- /dev/null +++ b/Documentation/devicetree/bindings/input/gpio-vibrator.yaml @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/bindings/input/gpio-vibrator.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: GPIO vibrator + +maintainers: + - Luca Weiss + +description: |+ + Registers a GPIO device as vibrator, where the on/off capability is controlled by a GPIO. + +properties: + compatible: + items: + - const: gpio-vibrator + + enable-gpios: + maxItems: 1 + + vcc-supply: + $ref: /schemas/types.yaml#/definitions/phandle + description: Regulator that provides power + +required: + - compatible + - enable-gpios + +examples: + - | + #include + + vibrator { + compatible = "gpio-vibrator"; + enable-gpios = <&msmgpio 86 GPIO_ACTIVE_HIGH>; + vcc-supply = <&pm8941_l18>; + }; From patchwork Sat Apr 20 12:23:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Weiss X-Patchwork-Id: 10910325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A0E7922 for ; Sat, 20 Apr 2019 12:24:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 798E828917 for ; Sat, 20 Apr 2019 12:24:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D78628D5D; Sat, 20 Apr 2019 12:24:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6D4128917 for ; Sat, 20 Apr 2019 12:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728299AbfDTMYT (ORCPT ); Sat, 20 Apr 2019 08:24:19 -0400 Received: from mail.z3ntu.xyz ([128.199.32.197]:46442 "EHLO mail.z3ntu.xyz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbfDTMYS (ORCPT ); Sat, 20 Apr 2019 08:24:18 -0400 Received: from localhost.localdomain (91-115-28-155.adsl.highway.telekom.at [91.115.28.155]) by mail.z3ntu.xyz (Postfix) with ESMTPSA id D94A5C4BC4; Sat, 20 Apr 2019 12:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=z3ntu.xyz; s=z3ntu; t=1555763054; bh=jKCZU7nKGneH+crRFqKJQMpcp2oYDXPnPH5/3MmsDQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GNcex7KOP7N5DCof5dkfvgt7jia6ms0siiZp63nKunLvlBlA7fQTtiAFL7u7cWaSt y/LAjzV7hPyXa+/lZu2yYwJezPWB6MaFr6qhvHmvH8fGZXKJkoJth7fBwa7oxrbhFc xIKKYNjwum0nt5wuQwhrE5KQqnQ55M3X1x7KjhB8= From: Luca Weiss Cc: Dmitry Torokhov , Rob Herring , Mark Rutland , Mauro Carvalho Chehab , Pascal PAILLET-LME , Coly Li , Lee Jones , Xiaotong Lu , Brian Masney , Rob Herring , Baolin Wang , David Brown , linux-arm-msm@vger.kernel.org (open list:ARM/QUALCOMM SUPPORT), linux-input@vger.kernel.org (open list:INPUT (KEYBOARD, MOUSE, JOYSTICK , TOUCHSCREEN)...), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-kernel@vger.kernel.org (open list), Luca Weiss Subject: [PATCH v4 2/3] Input: add a driver for GPIO controllable vibrators Date: Sat, 20 Apr 2019 14:23:32 +0200 Message-Id: <20190420122333.23662-2-luca@z3ntu.xyz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190420122333.23662-1-luca@z3ntu.xyz> References: <20190420122333.23662-1-luca@z3ntu.xyz> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide a simple driver for GPIO controllable vibrators. It will be used by the Fairphone 2. Signed-off-by: Luca Weiss --- Changes from v3: - Apply suggestions from Stephen Boyd drivers/input/misc/Kconfig | 12 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/gpio-vibra.c | 209 ++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 drivers/input/misc/gpio-vibra.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index e15ed1bb8558..6dfe9e2fe5b1 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -290,6 +290,18 @@ config INPUT_GPIO_DECODER To compile this driver as a module, choose M here: the module will be called gpio_decoder. +config INPUT_GPIO_VIBRA + tristate "GPIO vibrator support" + depends on GPIOLIB || COMPILE_TEST + select INPUT_FF_MEMLESS + help + Say Y here to get support for GPIO based vibrator devices. + + If unsure, say N. + + To compile this driver as a module, choose M here: the module will be + called gpio-vibra. + config INPUT_IXP4XX_BEEPER tristate "IXP4XX Beeper support" depends on ARCH_IXP4XX diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index b936c5b1d4ac..f38ebbdb05e2 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_INPUT_DRV2667_HAPTICS) += drv2667.o obj-$(CONFIG_INPUT_GP2A) += gp2ap002a00f.o obj-$(CONFIG_INPUT_GPIO_BEEPER) += gpio-beeper.o obj-$(CONFIG_INPUT_GPIO_DECODER) += gpio_decoder.o +obj-$(CONFIG_INPUT_GPIO_VIBRA) += gpio-vibra.o obj-$(CONFIG_INPUT_HISI_POWERKEY) += hisi_powerkey.o obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o obj-$(CONFIG_INPUT_IMS_PCU) += ims-pcu.o diff --git a/drivers/input/misc/gpio-vibra.c b/drivers/input/misc/gpio-vibra.c new file mode 100644 index 000000000000..b76c81015de9 --- /dev/null +++ b/drivers/input/misc/gpio-vibra.c @@ -0,0 +1,209 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * GPIO vibrator driver + * + * Copyright (C) 2019 Luca Weiss + * + * Based on PWM vibrator driver: + * Copyright (C) 2017 Collabora Ltd. + * + * Based on previous work from: + * Copyright (C) 2012 Dmitry Torokhov + * + * Based on PWM beeper driver: + * Copyright (C) 2010, Lars-Peter Clausen + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct gpio_vibrator { + struct input_dev *input; + struct gpio_desc *gpio; + struct regulator *vcc; + + struct work_struct play_work; + bool running; + bool vcc_on; +}; + +static int gpio_vibrator_start(struct gpio_vibrator *vibrator) +{ + struct device *pdev = vibrator->input->dev.parent; + int err; + + if (!vibrator->vcc_on) { + err = regulator_enable(vibrator->vcc); + if (err) { + dev_err(pdev, "failed to enable regulator: %d\n", err); + return err; + } + vibrator->vcc_on = true; + } + + gpiod_set_value_cansleep(vibrator->gpio, 1); + + return 0; +} + +static void gpio_vibrator_stop(struct gpio_vibrator *vibrator) +{ + gpiod_set_value_cansleep(vibrator->gpio, 0); + + if (vibrator->vcc_on) { + regulator_disable(vibrator->vcc); + vibrator->vcc_on = false; + } +} + +static void gpio_vibrator_play_work(struct work_struct *work) +{ + struct gpio_vibrator *vibrator = + container_of(work, struct gpio_vibrator, play_work); + + if (vibrator->running) + gpio_vibrator_start(vibrator); + else + gpio_vibrator_stop(vibrator); +} + +static int gpio_vibrator_play_effect(struct input_dev *dev, void *data, + struct ff_effect *effect) +{ + struct gpio_vibrator *vibrator = input_get_drvdata(dev); + + int level = effect->u.rumble.strong_magnitude; + + if (!level) + level = effect->u.rumble.weak_magnitude; + + if (level) + vibrator->running = true; + else + vibrator->running = false; + + schedule_work(&vibrator->play_work); + + return 0; +} + +static void gpio_vibrator_close(struct input_dev *input) +{ + struct gpio_vibrator *vibrator = input_get_drvdata(input); + + cancel_work_sync(&vibrator->play_work); + gpio_vibrator_stop(vibrator); + vibrator->running = false; +} + +static int gpio_vibrator_probe(struct platform_device *pdev) +{ + struct gpio_vibrator *vibrator; + int err; + + vibrator = devm_kzalloc(&pdev->dev, sizeof(*vibrator), GFP_KERNEL); + if (!vibrator) + return -ENOMEM; + + vibrator->input = devm_input_allocate_device(&pdev->dev); + if (!vibrator->input) + return -ENOMEM; + + vibrator->vcc = devm_regulator_get(&pdev->dev, "vcc"); + err = PTR_ERR_OR_ZERO(vibrator->vcc); + if (err) { + if (err != -EPROBE_DEFER) + dev_err(&pdev->dev, "Failed to request regulator: %d\n", + err); + return err; + } + + vibrator->gpio = devm_gpiod_get(&pdev->dev, "enable", GPIOD_OUT_LOW); + err = PTR_ERR_OR_ZERO(vibrator->gpio); + if (err) { + if (err != -EPROBE_DEFER) + dev_err(&pdev->dev, "Failed to request main gpio: %d\n", + err); + return err; + } + + INIT_WORK(&vibrator->play_work, gpio_vibrator_play_work); + + vibrator->input->name = "gpio-vibrator"; + vibrator->input->id.bustype = BUS_HOST; + vibrator->input->close = gpio_vibrator_close; + + input_set_drvdata(vibrator->input, vibrator); + input_set_capability(vibrator->input, EV_FF, FF_RUMBLE); + + err = input_ff_create_memless(vibrator->input, NULL, + gpio_vibrator_play_effect); + if (err) { + dev_err(&pdev->dev, "Couldn't create FF dev: %d\n", err); + return err; + } + + err = input_register_device(vibrator->input); + if (err) { + dev_err(&pdev->dev, "Couldn't register input dev: %d\n", err); + return err; + } + + platform_set_drvdata(pdev, vibrator); + + return 0; +} + +static int __maybe_unused gpio_vibrator_suspend(struct device *dev) +{ + struct gpio_vibrator *vibrator = dev_get_drvdata(dev); + + cancel_work_sync(&vibrator->play_work); + if (vibrator->running) + gpio_vibrator_stop(vibrator); + + return 0; +} + +static int __maybe_unused gpio_vibrator_resume(struct device *dev) +{ + struct gpio_vibrator *vibrator = dev_get_drvdata(dev); + + if (vibrator->running) + gpio_vibrator_start(vibrator); + + return 0; +} + +static SIMPLE_DEV_PM_OPS(gpio_vibrator_pm_ops, + gpio_vibrator_suspend, gpio_vibrator_resume); + +#ifdef CONFIG_OF +static const struct of_device_id gpio_vibra_dt_match_table[] = { + { .compatible = "gpio-vibrator" }, + {} +}; +MODULE_DEVICE_TABLE(of, gpio_vibra_dt_match_table); +#endif + +static struct platform_driver gpio_vibrator_driver = { + .probe = gpio_vibrator_probe, + .driver = { + .name = "gpio-vibrator", + .pm = &gpio_vibrator_pm_ops, + .of_match_table = of_match_ptr(gpio_vibra_dt_match_table), + }, +}; +module_platform_driver(gpio_vibrator_driver); + +MODULE_AUTHOR("Luca Weiss "); +MODULE_DESCRIPTION("GPIO vibrator driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:gpio-vibrator"); From patchwork Sat Apr 20 12:23:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Weiss X-Patchwork-Id: 10910331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF3AD17EE for ; Sat, 20 Apr 2019 12:24:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACE422870F for ; Sat, 20 Apr 2019 12:24:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DEDC28CD5; Sat, 20 Apr 2019 12:24:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51E552870F for ; Sat, 20 Apr 2019 12:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728258AbfDTMYS (ORCPT ); Sat, 20 Apr 2019 08:24:18 -0400 Received: from mail.z3ntu.xyz ([128.199.32.197]:46448 "EHLO mail.z3ntu.xyz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727640AbfDTMYR (ORCPT ); Sat, 20 Apr 2019 08:24:17 -0400 Received: from localhost.localdomain (91-115-28-155.adsl.highway.telekom.at [91.115.28.155]) by mail.z3ntu.xyz (Postfix) with ESMTPSA id B2720C4BCF; Sat, 20 Apr 2019 12:24:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=z3ntu.xyz; s=z3ntu; t=1555763055; bh=QR00LtWv8/eoQ1jFUpVKmnz8LHOduZ1ATvV/Pnuo9is=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tyC6yRfm8zcoSAdGI+9bjQsDcSGmSHFHVZyyYhBk3u7BzU/enWth+VLWc1xMsun20 PDYtjoI5XiZVuU9DTmnM25SbDZHcOxmZZq/l3UDQcMMu9EiOOhV0CPl32UElcvAFqg Hh/nOikB67N0rpJ2VDEYVYbOtUZ5IGsU2watXLMM= From: Luca Weiss Cc: Dmitry Torokhov , Rob Herring , Mark Rutland , Mauro Carvalho Chehab , Pascal PAILLET-LME , Coly Li , Lee Jones , Xiaotong Lu , Brian Masney , Rob Herring , Baolin Wang , David Brown , linux-arm-msm@vger.kernel.org (open list:ARM/QUALCOMM SUPPORT), linux-input@vger.kernel.org (open list:INPUT (KEYBOARD, MOUSE, JOYSTICK , TOUCHSCREEN)...), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-kernel@vger.kernel.org (open list), Luca Weiss Subject: [PATCH v4 3/3] ARM: dts: msm8974-FP2: Add vibration motor Date: Sat, 20 Apr 2019 14:23:33 +0200 Message-Id: <20190420122333.23662-3-luca@z3ntu.xyz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190420122333.23662-1-luca@z3ntu.xyz> References: <20190420122333.23662-1-luca@z3ntu.xyz> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Luca Weiss --- arch/arm/boot/dts/qcom-msm8974-fairphone-fp2.dts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/boot/dts/qcom-msm8974-fairphone-fp2.dts b/arch/arm/boot/dts/qcom-msm8974-fairphone-fp2.dts index 643c57f84818..bf402ae39226 100644 --- a/arch/arm/boot/dts/qcom-msm8974-fairphone-fp2.dts +++ b/arch/arm/boot/dts/qcom-msm8974-fairphone-fp2.dts @@ -50,6 +50,12 @@ }; }; + vibrator { + compatible = "gpio-vibrator"; + enable-gpios = <&msmgpio 86 GPIO_ACTIVE_HIGH>; + vcc-supply = <&pm8941_l18>; + }; + smd { rpm { rpm_requests {