Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp203343lqn; Thu, 11 Apr 2024 20:41:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBPjP0ga1hBEMRA+g1ur065tLETZXNbRMG82tL1hSRXDOOCefJ2uZEusNRHDHs4S9F/F22GyTLCeAMGbSgtomfpTroi3DJ9+OtB8ulLg== X-Google-Smtp-Source: AGHT+IEpddgkrWQN7rpzDyHzqU/NlhXK4/+aR+j4mUonFCp64QdVGoQycLOnQCCkw1sB7xTFZEUv X-Received: by 2002:a0c:f846:0:b0:69b:ae3:ee1a with SMTP id g6-20020a0cf846000000b0069b0ae3ee1amr1643517qvo.65.1712893280182; Thu, 11 Apr 2024 20:41:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712893280; cv=pass; d=google.com; s=arc-20160816; b=sip1f9tQ5RN/RZd9FcijyovgDSzoxtcBZaVL3PVm1y6Ec7mEP9g2LcAiTVcVOIN2LV nNEXAOecLq/qA3LEzcfyq9bX0kamqIM7tTDLxdfJNvwswQPNqcH/2WWv+JK1FZEVH64N DLJbLOmui6MhT8fNIlo9EVzUl+s2rl6/Jquxfx8J1Op0CP8MfR5p5tJm5CiZO4ZTbUl6 fcKaIAZKXonZIPKtBptCXdvHfBhux92L+Th0pIOkc7Z3Jx4+3dJiZqN8TsSKQzA81yuq Bh6CiGd1omHJPoYFTq6fsl9kNO66/zSoX5d8tw4dh8vBW40IkR17kDGd9H53pGM0EpHM EeCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=fj9TE7Tah5pI7bwVBO6O9IC+pILPNJ+nxYjZRR9bq6c=; fh=iTzJ2H1wEvTp9arzqKHkEO9GdQjFyUydq3lgST85mjE=; b=C6wqgzJ1nfmdhpyja9Pt4OKGQEmqHeNc+sqW7VaOk4Vp6S/atglicG3qn+GPku36dF 5l8SZghTo5Bm6pAcUbnxwy+yB3uRgdqlU94rWcJj22RNtaU+HaHY9miCNshwx/XRSpxB hUZR907d9fLx5vZmBBVqz3HwNDlZs6sB/39vKd9ojRLrv3EDg/Aa8biWQ7A9h/NjL6z6 leIHDd1qXGPdvEAkqkkEbdPJvtZIstGsNpp30Mf9XdGlmNHjYQqg9Cg/UcrqNjEKBMNO TeLAlD++S2Ihfe8E7qEU1pCJkYPzQUWb5DYpyaRTCFeImC5SA3i1ocTqtrOB9OmdsPbw UEgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Jl1oJ0LP; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-141875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141875-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h2-20020a0cf8c2000000b00698ebf6b7ecsi2951133qvo.203.2024.04.11.20.41.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 20:41:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Jl1oJ0LP; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-141875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141875-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D731D1C217A2 for ; Fri, 12 Apr 2024 03:41:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE56717C7F; Fri, 12 Apr 2024 03:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Jl1oJ0LP" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C1921FB2; Fri, 12 Apr 2024 03:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712893268; cv=none; b=kcokscsdXMiv15C67qwN016Tn8/kAdgt/KXb0zBzOM9Xhd9l1H09t6CSSvo+vqIl6CD/Iw0l8rZfG88ONiJZwRThO6b649XRA/XknWGabh4xQdskuBroTqhr7DZL97XClv+EzZlGxRoh1x+UiumQULbUfzZjBGOW1D5UycPwXGo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712893268; c=relaxed/simple; bh=9tQthn+WuwAFh21oeDvVu3RA7MtXUpZV4U0rHfmsASA=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=RzTyFzItqp+gNeY661OrPi8voGLXvxRBEfZPqVv9YTcEleXbp1VNPHc+//yDL9iDRiypoGRCVcv3Lb3J8TpU4erfo2g28f8CsMRCga9IEcOwR4QLQPQla+pJuFJmAkxeNwmRbNdtYMFa0OEc0tuM88imPhFll7w+TtzdEvPj5q4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=Jl1oJ0LP; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 43C3Zhil025621; Fri, 12 Apr 2024 03:41:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=fj9TE7Tah5pI7bwVBO6O9IC+pILPNJ+nxYjZRR9bq6c=; b=Jl 1oJ0LPAMSQsJZcPnA2TvjmI00aTnljd+tqDe2NEYBtpgpRQOzEgHUAbahqk1kwgk xfTndYprS6UtzyGux9WaYsO9A8Q+tL+rpe51qUXsIM2iPZ7HEbIOMOYhnAwxP4f6 at0rQV19XqvEzY0ZbaWOczpCWQOoDAJAvT8fRtqUifj45UgsFnf9WNXLseazodX0 7QoiOUvXoQvyjUK5YXYpPEit7yXoHUST9ShGCI+MkNisve3bKUtOhZAUCZaFR9F7 d4p+GokfXvxV6dk5N7zG5DdhuilMFPOYpKF7LD8W8cg4Jig86Xz1fBCUPaKz3+Tr avhczuusnMMTUeAH5Sxg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3xer1trgx1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 12 Apr 2024 03:41:02 +0000 (GMT) Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 43C3f1mk017741 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 12 Apr 2024 03:41:01 GMT Received: from [10.253.12.44] (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 11 Apr 2024 20:40:56 -0700 Message-ID: <00b8cea6-fed2-4224-8aeb-c731dc1b666f@quicinc.com> Date: Fri, 12 Apr 2024 11:40:53 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 2/4] input: pm8xxx-vibrator: refactor to support new SPMI vibrator Content-Language: en-US To: Dmitry Baryshkov CC: , Andy Gross , Bjorn Andersson , Konrad Dybcio , "Dmitry Torokhov" , Rob Herring , Krzysztof Kozlowski , , , , References: <20240411-pm8xxx-vibrator-new-design-v9-0-7bf56cb92b28@quicinc.com> <20240411-pm8xxx-vibrator-new-design-v9-2-7bf56cb92b28@quicinc.com> From: Fenglin Wu In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: -2XnKRWx_gXOT_47-sjIb57XJJvoq4MN X-Proofpoint-GUID: -2XnKRWx_gXOT_47-sjIb57XJJvoq4MN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-11_14,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 malwarescore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 impostorscore=0 clxscore=1015 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2404120024 On 4/11/2024 10:05 PM, Dmitry Baryshkov wrote: > On Thu, 11 Apr 2024 at 16:45, Fenglin Wu wrote: >> >> >> >> On 2024/4/11 18:58, Dmitry Baryshkov wrote: >>> On Thu, 11 Apr 2024 at 11:32, Fenglin Wu via B4 Relay >>> wrote: >>>> >>>> From: Fenglin Wu >>>> >>>> Currently, vibrator control register addresses are hard coded, >>>> including the base address and offsets, it's not flexible to >>>> support new SPMI vibrator module which is usually included in >>>> different PMICs with different base address. Refactor it by using >>>> the base address defined in devicetree. >>>> >>>> Signed-off-by: Fenglin Wu >>>> --- >>>> drivers/input/misc/pm8xxx-vibrator.c | 42 ++++++++++++++++++++++++------------ >>>> 1 file changed, 28 insertions(+), 14 deletions(-) >>>> >>>> diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c >>>> index 89f0f1c810d8..2959edca8eb9 100644 >>>> --- a/drivers/input/misc/pm8xxx-vibrator.c >>>> +++ b/drivers/input/misc/pm8xxx-vibrator.c >>>> @@ -20,26 +20,26 @@ >>>> #define MAX_FF_SPEED 0xff >>>> >>>> struct pm8xxx_regs { >>>> - unsigned int enable_addr; >>>> + unsigned int enable_offset; >>>> unsigned int enable_mask; >>>> >>>> - unsigned int drv_addr; >>>> + unsigned int drv_offset; >>>> unsigned int drv_mask; >>>> unsigned int drv_shift; >>>> unsigned int drv_en_manual_mask; >>>> }; >>>> >>>> static const struct pm8xxx_regs pm8058_regs = { >>>> - .drv_addr = 0x4A, >>>> + .drv_offset = 0x4A, >>> >>> If the DT already has reg = <0x4a> and you add drv_offset = 0x4a, >>> which register will be used by the driver? >>> >>> Also, while we are at it, please downcase all the hex numbers that you >>> are touching. >>> >> For SSBI vibrator, the "reg" value defined in DT is not used, see below. >> >> >>>> .drv_mask = 0xf8, >>>> .drv_shift = 3, >>>> .drv_en_manual_mask = 0xfc, >>>> }; >>>> >>>> static struct pm8xxx_regs pm8916_regs = { >>>> - .enable_addr = 0xc046, >>>> + .enable_offset = 0x46, >> >> [...] >> >>>> @@ -170,7 +173,7 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) >>>> struct pm8xxx_vib *vib; >>>> struct input_dev *input_dev; >>>> int error; >>>> - unsigned int val; >>>> + unsigned int val, reg_base = 0; >>>> const struct pm8xxx_regs *regs; >>>> >>>> vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL); >>>> @@ -190,13 +193,24 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) >>>> >>>> regs = of_device_get_match_data(&pdev->dev); >>>> >>>> + if (regs->enable_offset != 0) { >>>> + error = fwnode_property_read_u32(pdev->dev.fwnode, "reg", ®_base); >>>> + if (error < 0) { >>>> + dev_err(&pdev->dev, "Failed to read reg address, rc=%d\n", error); >>>> + return error; >>>> + } >>>> + } >>>> + >>>> + vib->enable_addr = reg_base + regs->enable_offset; >>>> + vib->drv_addr = reg_base + regs->drv_offset; >> >> The reg_base is initialized as 0 and it is assigned as the "reg" value >> defined in DT only for SPMI vibrators. > > Please don't. This is counterintuitive. We have reg in DT. We should > be using it. > Hmm, the original driver doesn't use the reg value defined in DT at all, Anyway, I can make the SSBI offset to 0, so the base address defined in the DT will be always added regardless of SSBI or SPMI vibrator. Let me know. Thanks >> >>>> + >>>> /* operate in manual mode */ >>>> - error = regmap_read(vib->regmap, regs->drv_addr, &val); >>>> + error = regmap_read(vib->regmap, vib->drv_addr, &val); >>>> if (error < 0) >>>> return error; >>>> >>>> val &= regs->drv_en_manual_mask; >>>> - error = regmap_write(vib->regmap, regs->drv_addr, val); >>>> + error = regmap_write(vib->regmap, vib->drv_addr, val); >>>> if (error < 0) >>>> return error; >>>> >>>> >>>> -- >>>> 2.25.1 >>>> >>>> >>> >>> > > >