From patchwork Thu Apr 26 09:12:34 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: 134436 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1994360lji; Thu, 26 Apr 2018 02:13:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr+P83D0rsy031xBw2P5VktIE9MZh/6HB0VdIyP/FYK2qyleFktmWGf9z2TJSaPYqmV+Gbg X-Received: by 2002:a17:902:7c81:: with SMTP id y1-v6mr4621245pll.186.1524734037508; Thu, 26 Apr 2018 02:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524734037; cv=none; d=google.com; s=arc-20160816; b=WTzIgBBrTT/sSYVQB3HYqm4KEVe4+qmwmZN9hZpq1Pjv4uyKsnnhGZPU6Jj6xCNuLx PYxdwgps47h6vjA7OiqqmBhkzxrmr750/MaL068GvvIsKaGvpNxHjj+5AMt/DSyt0B9O K9KJJqUk8AHCV+sviqOIbYnwPxbW+XcKkADl+USfCN4Gix66MtSev7YyKDZT4+ehfRRQ r/Htor4N1m64Gj3KcCAdR1CxirC9rROdqS6zOkErX4NFAmsdfQvF4uE1d5dgBHzQQomn ndrrwKbHJ0gQesk2a1sHaTkmh5/tNHoZ14pQZiFlZAZcd2rzfe9hiAybGN3DSWDZYEw+ 2fCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=EgFrSrs9x+u76CDDm9q9SWTIPsAjxW9Rr2c3uaw3YKA=; b=JSbytiT1gxtg7RFCVVM/WUT6jw2gUFY2uTG63lwpQJ1ECJHtZyB2Rcnv/rTYR54rsM GtBCBkGI5ej2NF5i0tbwIu/Z/WCRnt+dLYT/f2FRpLl5TskK4hY251YJ9MECzjiRKlpw qjoQhQcywRatXZtQ7/aUAkOxhLAOozUIITu/ZO4n3xZgLg7gEJgiQZqGXRBwxZnebnNN Ntj+wYZzzOEOt6FPNtjsRernWTDGB0zl7+CdX7bNGlmfYtxt9SR8ULpJHV4niPS//Ul1 flZmMTnw85KqD1yTuTfV6Ir3SzZmCZ/xFt6MsGPTd6tkyNnplXbYI/qQl80isG0TTUFw 68Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NmUhK37t; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g67si7033743pfe.4.2018.04.26.02.13.57 for ; Thu, 26 Apr 2018 02:13:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NmUhK37t; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754940AbeDZJNz (ORCPT ); Thu, 26 Apr 2018 05:13:55 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:40882 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754630AbeDZJNj (ORCPT ); Thu, 26 Apr 2018 05:13:39 -0400 Received: by mail-pg0-f66.google.com with SMTP id l2so2127257pgc.7 for ; Thu, 26 Apr 2018 02:13:39 -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=2m9ISPsGLFvt6KWjas86i/hZ8pkIKFrNpDVHJLJPkgQ=; b=NmUhK37tFIiidjQgB7ZzPHGIni47bCvFiWpxf01E36o99nIdrw2jWEZz3cXSO8UwP7 HE5XPy+r4Uoe7sp8oTbKFABvjHoHTf3Mq94lOD4vZizGWwjlNJbgf6bcLRdqHemUfzeH s1SQuvzQHXrnFNK5Xl0EVRiomE6CBdiCV9HOg= 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=2m9ISPsGLFvt6KWjas86i/hZ8pkIKFrNpDVHJLJPkgQ=; b=Yc+zR5+toQrGq8ImcDgJ3TsHK+bQf0ia6l7BK+kK9+f/4Z0pQIxxr9qWTgf6PGzqr0 U55vRP7t+kZY3wWpmg7u2zbDGI5kExFDgP4GdZhJ5edE0GFXv723sUR9Xha3We13rzlT O8Fvt5fMAyaS7Jje7zjUtaEVaWNyGTxr17zkCntFs43FhHtM0fp5PSDoQ2urko8OMxh0 wqs5LtGlN7TCR6AKKQsQx8GachZjBphPpA7hZ5HtwtVJJZSzD2QtI1Nq9LQmsETjVki6 BIGS/EIVLqsudCFc+jH7N700VXADHTOiBTl5hhztevpfsiEIPG2zupSr8nB/cdDugTBA CFfg== X-Gm-Message-State: ALQs6tBzp7ltl0W4x4/baSql2iP+yJlj17YipR70klV/Epqn0IwCe6Qd 2Wgb0jXnOD5HZr5afux573PjOw== X-Received: by 10.98.185.23 with SMTP id z23mr31050783pfe.180.1524734018838; Thu, 26 Apr 2018 02:13:38 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id f8sm27780548pgs.84.2018.04.26.02.13.35 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Apr 2018 02:13:38 -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: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, xiaotong.lu@spreadtrum.com Subject: [PATCH v3 2/2] input: misc: Add Spreadtrum vibrator driver Date: Thu, 26 Apr 2018 17:12:34 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 --- Changes since v2: - Fix the condition when disabling the vibrator. - Change of_property_read_u32() to device_property_read_u32(). - Correct the device parent relationship. - Call sc27xx_vibra_hw_init() before calling input_register_device(). - Remove platform_set_drvdata(). Changes since v1: - Remove input_ff_destroy() and input_unregister_device() --- drivers/input/misc/Kconfig | 10 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/sc27xx-vibra.c | 154 +++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 drivers/input/misc/sc27xx-vibra.c -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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..1167c48 --- /dev/null +++ b/drivers/input/misc/sc27xx-vibra.c @@ -0,0 +1,154 @@ +// 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->strength == 0 && 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 vibra_info *info; + int error; + + 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; + } + + error = device_property_read_u32(&pdev->dev, "reg", &info->base); + if (error) { + dev_err(&pdev->dev, "failed to get vibrator base address.\n"); + return error; + } + + 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->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; + + error = sc27xx_vibra_hw_init(info); + if (error) { + dev_err(&pdev->dev, "failed to initialize the vibrator.\n"); + return error; + } + + error = input_ff_create_memless(info->input_dev, NULL, + sc27xx_vibra_play); + if (error) { + dev_err(&pdev->dev, "failed to register vibrator to FF.\n"); + return error; + } + + error = input_register_device(info->input_dev); + if (error) { + dev_err(&pdev->dev, "failed to register input device.\n"); + return error; + } + + 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 ");