From patchwork Tue Apr 17 03:18:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10344263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0F67E60542 for ; Tue, 17 Apr 2018 03:19:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03B5B288D8 for ; Tue, 17 Apr 2018 03:19:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBFE428980; Tue, 17 Apr 2018 03:19: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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 49892288D8 for ; Tue, 17 Apr 2018 03:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752696AbeDQDTQ (ORCPT ); Mon, 16 Apr 2018 23:19:16 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:44001 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752593AbeDQDTM (ORCPT ); Mon, 16 Apr 2018 23:19:12 -0400 Received: by mail-pl0-f66.google.com with SMTP id a39-v6so11173113pla.10 for ; Mon, 16 Apr 2018 20:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=DUurtXNnpKELfGoUlsy4N4qFPXYb9g+VOr+NHXXADSU=; b=JBbVIhQMQYDUyf88hfOHYMnbplEcuC7/HuPmvXZ/ZxM4eBLHsZg7Ty3bSm8QObQiNu GIhCMOlOlJbnAA8eij8tFEMeIjeeOOgCpJtHWqYntTsX6bFgbkilYwoB83eQ9+bhFzo8 KVBNgtjHI9mMtGW4MLZTZtd2cfCedoxzqW/7Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=DUurtXNnpKELfGoUlsy4N4qFPXYb9g+VOr+NHXXADSU=; b=r7ey6VlqH/qnoxvyQq13HtifDZa4KR5xBpisqKArR8RtB6KljwWQjoCkh99KfPmfNP 1u+fZTGBdzohonybh8uVrTusEnonsFUjA+ngv4X0mB18Khq7jNqMiZFrGuw6aitrYSuM 5/nBezQGUnkJjv7dLiPFbr1JIkPfnmWpRbkM+JN/pf36Jo17Px88cBt4PLq1jRz3cniH PioJG3xLegfHquOITxR5Af1xv9MeGbLmhebnETYzfjKMey197xhenptbMEjFqPWOqANz oriM+5MG16IMmIdiff5DF8IyHKuQ/IipTlbQJzvtThZcIsLGVxnjaSUhJ+XqpwMih/9h H7Cw== X-Gm-Message-State: ALQs6tC5fDWSkFAWQSpglSonIZP5V5QAVOfeFa9PIFt5/TKEjn0QXFel 5K6mL62KpjbDRsFsgUfOn4GstxyKzvo= X-Google-Smtp-Source: AIpwx4+rHNrXXVmujOjvj7xEOr3EY4/+HeM7+Qw/r9fCSay4SjuAlNla3Hc2RZFHQOGUkGHzqt6ExQ== X-Received: by 2002:a17:902:4464:: with SMTP id k91-v6mr383717pld.219.1523935151552; Mon, 16 Apr 2018 20:19:11 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id w134sm27638623pfd.132.2018.04.16.20.19.07 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Apr 2018 20:19:11 -0700 (PDT) From: Baolin Wang To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, mark.rutland@arm.com, orsonzhai@gmail.com, zhang.lyra@gmail.com Cc: baolin.wang@linaro.org, linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, xiaotong.lu@spreadtrum.com Subject: [PATCH 2/2] input: misc: Add Spreadtrum vibrator driver Date: Tue, 17 Apr 2018 11:18:24 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <0bfdc811c2b3da3aa1cde2feef278a86503e3804.1523934640.git.baolin.wang@linaro.org> References: <0bfdc811c2b3da3aa1cde2feef278a86503e3804.1523934640.git.baolin.wang@linaro.org> In-Reply-To: <0bfdc811c2b3da3aa1cde2feef278a86503e3804.1523934640.git.baolin.wang@linaro.org> References: <0bfdc811c2b3da3aa1cde2feef278a86503e3804.1523934640.git.baolin.wang@linaro.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiaotong Lu This patch adds the Spreadtrum vibrator driver, which embedded in the Spreadtrum SC27xx series PMICs. Signed-off-by: Xiaotong Lu Signed-off-by: Baolin Wang --- drivers/input/misc/Kconfig | 10 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/sc27xx-vibra.c | 159 +++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 drivers/input/misc/sc27xx-vibra.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 572b15f..c761c0c 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -841,4 +841,14 @@ config INPUT_RAVE_SP_PWRBUTTON To compile this driver as a module, choose M here: the module will be called rave-sp-pwrbutton. +config INPUT_SC27XX_VIBRA + tristate "Spreadtrum sc27xx vibrator support" + depends on MFD_SC27XX_PMIC || COMPILE_TEST + select INPUT_FF_MEMLESS + help + This option enables support for Spreadtrum sc27xx vibrator driver. + + To compile this driver as a module, choose M here. The module will + be called sc27xx_vibra. + endif diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 72cde28..9d0f9d1 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_INPUT_RETU_PWRBUTTON) += retu-pwrbutton.o obj-$(CONFIG_INPUT_AXP20X_PEK) += axp20x-pek.o obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o obj-$(CONFIG_INPUT_RK805_PWRKEY) += rk805-pwrkey.o +obj-$(CONFIG_INPUT_SC27XX_VIBRA) += sc27xx-vibra.o obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o obj-$(CONFIG_INPUT_SIRFSOC_ONKEY) += sirfsoc-onkey.o obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY) += soc_button_array.o diff --git a/drivers/input/misc/sc27xx-vibra.c b/drivers/input/misc/sc27xx-vibra.c new file mode 100644 index 0000000..a34a315 --- /dev/null +++ b/drivers/input/misc/sc27xx-vibra.c @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Spreadtrum Communications Inc. + */ + +#include +#include +#include +#include +#include +#include + +#define CUR_DRV_CAL_SEL GENMASK(13, 12) +#define SLP_LDOVIBR_PD_EN BIT(9) +#define LDO_VIBR_PD BIT(8) + +struct vibra_info { + struct input_dev *input_dev; + struct work_struct play_work; + struct regmap *regmap; + u32 base; + u32 strength; + bool enabled; +}; + +static void sc27xx_vibra_set(struct vibra_info *info, bool on) +{ + if (on) { + regmap_update_bits(info->regmap, info->base, LDO_VIBR_PD, 0); + regmap_update_bits(info->regmap, info->base, + SLP_LDOVIBR_PD_EN, 0); + info->enabled = true; + } else { + regmap_update_bits(info->regmap, info->base, LDO_VIBR_PD, + LDO_VIBR_PD); + regmap_update_bits(info->regmap, info->base, + SLP_LDOVIBR_PD_EN, SLP_LDOVIBR_PD_EN); + info->enabled = false; + } +} + +static int sc27xx_vibra_hw_init(struct vibra_info *info) +{ + return regmap_update_bits(info->regmap, info->base, CUR_DRV_CAL_SEL, 0); +} + +static void sc27xx_vibra_play_work(struct work_struct *work) +{ + struct vibra_info *info = container_of(work, struct vibra_info, + play_work); + + if (info->strength && !info->enabled) + sc27xx_vibra_set(info, true); + else if (info->enabled) + sc27xx_vibra_set(info, false); +} + +static int sc27xx_vibra_play(struct input_dev *input, void *data, + struct ff_effect *effect) +{ + struct vibra_info *info = input_get_drvdata(input); + + info->strength = effect->u.rumble.weak_magnitude; + schedule_work(&info->play_work); + + return 0; +} + +static void sc27xx_vibra_close(struct input_dev *input) +{ + struct vibra_info *info = input_get_drvdata(input); + + cancel_work_sync(&info->play_work); + if (info->enabled) + sc27xx_vibra_set(info, false); +} + +static int sc27xx_vibra_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + struct vibra_info *info; + int ret; + + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!info->regmap) { + dev_err(&pdev->dev, "failed to get vibrator regmap.\n"); + return -ENODEV; + } + + ret = of_property_read_u32(node, "reg", &info->base); + if (ret) { + dev_err(&pdev->dev, "failed to get vibrator base address.\n"); + return ret; + } + + info->input_dev = devm_input_allocate_device(&pdev->dev); + if (!info->input_dev) { + dev_err(&pdev->dev, "failed to allocate input device.\n"); + return -ENOMEM; + } + + info->input_dev->name = "sc27xx:vibrator"; + info->input_dev->id.version = 0; + info->input_dev->dev.parent = pdev->dev.parent; + info->input_dev->close = sc27xx_vibra_close; + + input_set_drvdata(info->input_dev, info); + input_set_capability(info->input_dev, EV_FF, FF_RUMBLE); + INIT_WORK(&info->play_work, sc27xx_vibra_play_work); + info->enabled = false; + + ret = input_ff_create_memless(info->input_dev, NULL, sc27xx_vibra_play); + if (ret) { + dev_err(&pdev->dev, "failed to register vibrator to FF.\n"); + return ret; + } + + ret = input_register_device(info->input_dev); + if (ret) { + dev_err(&pdev->dev, "failed to register input device.\n"); + input_ff_destroy(info->input_dev); + return ret; + } + + ret = sc27xx_vibra_hw_init(info); + if (ret) { + dev_err(&pdev->dev, "failed to initialize the vibrator.\n"); + input_ff_destroy(info->input_dev); + input_unregister_device(info->input_dev); + return ret; + } + + platform_set_drvdata(pdev, info); + return 0; +} + +static const struct of_device_id sc27xx_vibra_of_match[] = { + { .compatible = "sprd,sc27xx-vibrator", }, + {} +}; +MODULE_DEVICE_TABLE(of, sc27xx_vibra_of_match); + +static struct platform_driver sc27xx_vibra_driver = { + .driver = { + .name = "sc27xx-vibrator", + .of_match_table = sc27xx_vibra_of_match, + }, + .probe = sc27xx_vibra_probe, +}; + +module_platform_driver(sc27xx_vibra_driver); + +MODULE_DESCRIPTION("Spreadtrum SC27xx Vibrator Driver"); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Xiaotong Lu ");