Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1192485rwb; Wed, 26 Jul 2023 08:51:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlGxy7rPLiFbLYkorQkU8wkevGkd5Thd/qiVkLYbxeBvhISl/TLm40pYFkfOg7CNHsepZ6bn X-Received: by 2002:a05:6a20:7f9d:b0:132:86ea:4725 with SMTP id d29-20020a056a207f9d00b0013286ea4725mr2504635pzj.45.1690386692044; Wed, 26 Jul 2023 08:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690386692; cv=none; d=google.com; s=arc-20160816; b=THVqYhT8evVTli1+ghrptGVl68Ajm8t+HQw6fz0xVUTZ+bp+L9Jlhb961gDFdgMnjK h2tK5/VvG/23hm606Zqii4uqXS0cIQ/b/m85UqAqhhE9XZVHfGA12fcQJx0D4Jiz7cZc KhCeOFVhkggym4dwNbZfJDhh+Y9rQXc2e/Y8aI0CArMykKrqhwsy2eXtaoRkpf/QR4/V yGipfxailFKopzQSFELuTe5wf/o1XDP85n6Jxja6MW3nPqKGzRnApJ7YygBq+NZBfb1b EqLZpywOFiEBEQ66GI28Pu0bSMgDDYuc74VzSyONFXFdRjWdTJnJM7CajO71JypbUFo8 o8Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=O+W+dqmHY3oDSoUaAbXjHwkO+njuNaAcS/shrCuC458=; fh=IhDR6QkA+pMhKfWOnBdLujO6/Spt1ZHEWWjU4OwjUPg=; b=PE8fNNI8B6NwFgaaSk/OwJndMOpkteqKnpKiRlSKY3uwq3C5/Aj3lpe+pvFu8WBKW1 kycQq8V1RGP74GoSa9e85vObO+Jp9ykQeE6yX/6TJmIRiQZFzj8/mVOCjvnw0vEMrVWN o8bd2pRzua1A78SkQuFNMHBKyMEH92kCBUU0lJqjdrwivRae4udp3Up1mIzVHmev9CTE i7ppiPMWcxnuxdLxGCBNxpO4xSnnlQJLy2kYXMRjHvT1YxX5uGu778KhZsrSa5PbL4ar 5TJjneFzA0Gt44ioggQkogBKDclFHcIol/P+lOdsM0Z/tlzPIMbvP+qATx3lcKieasaZ rRPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ewcXk2PX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a6543c7000000b0056387def1cesi11251736pgp.102.2023.07.26.08.51.18; Wed, 26 Jul 2023 08:51:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ewcXk2PX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233621AbjGZPgR (ORCPT + 99 others); Wed, 26 Jul 2023 11:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233542AbjGZPgQ (ORCPT ); Wed, 26 Jul 2023 11:36:16 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21F72DA for ; Wed, 26 Jul 2023 08:36:13 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4fe0fe622c3so1467014e87.2 for ; Wed, 26 Jul 2023 08:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690385771; x=1690990571; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=O+W+dqmHY3oDSoUaAbXjHwkO+njuNaAcS/shrCuC458=; b=ewcXk2PXdG1aOg6qArX1EO342l5M19dX0BLwzHZCzO7wpvr5cGN/ecB5JnRyDp5S26 gafBet5LduTLPF/IZ2ubc4YaMfhO8TJz8pn6Zj9l3vIDUKQKIaOLNA1KdKF7xiTQg2vQ 4APNbu3QTrQIqDkxv6a6SfTVW9DUvpyiSiFRBJIHK4FIZgYQtWZXtPHfC1BUGbjZMdXu B9OOiv6h3S4SuXBp2/7uHKkYHbgqQ8ouTIW1rMdvbmz0XI0ys5po9brQBFXKO2o0NyM6 EERvsi/eIm+Yr/3VQv5pzN0B9OCvdJvC32yPEP18zhTqjdR9G8s7vWB/L9gIRn0StNM3 bxwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690385771; x=1690990571; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O+W+dqmHY3oDSoUaAbXjHwkO+njuNaAcS/shrCuC458=; b=h9K0nhL5X3T/D4Y+xuljqEFw20UkBubWxd2OdikJeAFnKeGwHIf0szHty1DVSYrnTF OxbiS5YKHBr5fzZ5gEjCSaSkgy8Pp/Yc5KCQtN4q2mJJLoFHQLyggn6YwfZ+gPWAA4yB PY4wvo5/TD9d4MrEbWcyfgtUS20g/8bJmbXRIb8vLqHpoWXtlMW/8FM22+FxNFjFNoBX eFbSJKYIX93hB13nVFQmnS/nmEktYtBaKKXtDLmPgk9DlCbaz+NrwqpmvVVE7ic6o21y 6/iz6Mr3EQcwx54F1sWa9m6qKmP4Zsmva0pVk7+8jbBcoA9S4DLvJ8xPG8EWcgDJKYFH VqsA== X-Gm-Message-State: ABy/qLaXMJfFC2Mxz7bdaduS8Y8mpCuJPcis2tOMaz/0QcfoJBewBmET /++0ghaqa6zI0DdxBn1waEiEqQ== X-Received: by 2002:a05:6512:44d:b0:4f9:596d:c803 with SMTP id y13-20020a056512044d00b004f9596dc803mr1836717lfk.53.1690385771119; Wed, 26 Jul 2023 08:36:11 -0700 (PDT) Received: from [192.168.1.101] (abxh240.neoplus.adsl.tpnet.pl. [83.9.1.240]) by smtp.gmail.com with ESMTPSA id s7-20020a19ad47000000b004fbbef8d4dbsm3368900lfd.121.2023.07.26.08.36.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Jul 2023 08:36:10 -0700 (PDT) Message-ID: Date: Wed, 26 Jul 2023 17:36:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/7] soc: qcom: add QCOM PBS driver Content-Language: en-US To: Anjelique Melendez , pavel@ucw.cz, lee@kernel.org, thierry.reding@gmail.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, agross@kernel.org, andersson@kernel.org Cc: luca.weiss@fairphone.com, u.kleine-koenig@pengutronix.de, quic_subbaram@quicinc.com, linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-pwm@vger.kernel.org References: <20230725193423.25047-1-quic_amelende@quicinc.com> <20230725193423.25047-4-quic_amelende@quicinc.com> From: Konrad Dybcio Autocrypt: addr=konrad.dybcio@linaro.org; keydata= xsFNBF9ALYUBEADWAhxdTBWrwAgDQQzc1O/bJ5O7b6cXYxwbBd9xKP7MICh5YA0DcCjJSOum BB/OmIWU6X+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NPYOd58EY9/7mL5u0sJmo+jTeb4JBgIbFPJCFyng4HwbniWgQJZ1WqaUC nas9J77uICis2WH7N8Bs9jy0wQYezNzqS+FxoNXmDQg2jetX8en4bO2Di7Pmx0jXA4TOb9TM izWDgYvmBE8= In-Reply-To: <20230725193423.25047-4-quic_amelende@quicinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.07.2023 21:34, Anjelique Melendez wrote: > Add the Qualcomm PBS (Programmable Boot Sequencer) driver. The QCOM PBS > driver supports configuring software PBS trigger events through PBS RAM > on Qualcomm Technologies, Inc (QTI) PMICs. > > Signed-off-by: Anjelique Melendez > --- [...] > + > + u32 base; > +}; > + > +static int qcom_pbs_read(struct pbs_dev *pbs, u32 address, u8 *val) > +{ > + int ret; > + > + address += pbs->base; Any reason not to just keep the base address in struct pbs_dev and use normal regmap r/w helpers? [...] > + > +static int qcom_pbs_wait_for_ack(struct pbs_dev *pbs, u8 bit_pos) > +{ > + u16 retries = 2000, delay = 1000; > + int ret; > + u8 val; > + > + while (retries--) { > + ret = qcom_pbs_read(pbs, PBS_CLIENT_SCRATCH2, &val); > + if (ret < 0) > + return ret; > + > + if (val == 0xFF) { This should be a constant, not a magic value > + /* PBS error - clear SCRATCH2 register */ > + ret = qcom_pbs_write(pbs, PBS_CLIENT_SCRATCH2, 0); > + if (ret < 0) > + return ret; > + > + dev_err(pbs->dev, "NACK from PBS for bit %u\n", bit_pos); > + return -EINVAL; > + } > + > + if (val & BIT(bit_pos)) { > + dev_dbg(pbs->dev, "PBS sequence for bit %u executed!\n", bit_pos); > + break; > + } > + > + usleep_range(delay, delay + 100); So worst case scenario this will wait for over 2 seconds? > + } > + > + if (!retries) { > + dev_err(pbs->dev, "Timeout for PBS ACK/NACK for bit %u\n", bit_pos); > + return -ETIMEDOUT; > + } > + > + return 0; return 0 instead of break above? > +} > + > +/** > + * qcom_pbs_trigger_event() - Trigger the PBS RAM sequence > + * @pbs: Pointer to PBS device > + * @bitmap: bitmap > + * > + * This function is used to trigger the PBS RAM sequence to be > + * executed by the client driver. > + * > + * The PBS trigger sequence involves > + * 1. setting the PBS sequence bit in PBS_CLIENT_SCRATCH1 > + * 2. Initiating the SW PBS trigger > + * 3. Checking the equivalent bit in PBS_CLIENT_SCRATCH2 for the > + * completion of the sequence. > + * 4. If PBS_CLIENT_SCRATCH2 == 0xFF, the PBS sequence failed to execute > + * > + * Returns: 0 on success, < 0 on failure > + */ > +int qcom_pbs_trigger_event(struct pbs_dev *pbs, u8 bitmap) > +{ > + u8 val, mask; > + u16 bit_pos; > + int ret; > + > + if (!bitmap) { > + dev_err(pbs->dev, "Invalid bitmap passed by client\n"); > + return -EINVAL; > + } > + > + if (IS_ERR_OR_NULL(pbs)) > + return -EINVAL; > + > + mutex_lock(&pbs->lock); > + ret = qcom_pbs_read(pbs, PBS_CLIENT_SCRATCH2, &val); > + if (ret < 0) > + goto out; > + > + if (val == 0xFF) { > + /* PBS error - clear SCRATCH2 register */ > + ret = qcom_pbs_write(pbs, PBS_CLIENT_SCRATCH2, 0); > + if (ret < 0) > + goto out; > + } > + > + for (bit_pos = 0; bit_pos < 8; bit_pos++) { > + if (bitmap & BIT(bit_pos)) { > + /* > + * Clear the PBS sequence bit position in > + * PBS_CLIENT_SCRATCH2 mask register. > + */ Don't think the "in the X register" parts are useful. > + ret = qcom_pbs_masked_write(pbs, PBS_CLIENT_SCRATCH2, BIT(bit_pos), 0); > + if (ret < 0) > + goto error; > + > + /* > + * Set the PBS sequence bit position in > + * PBS_CLIENT_SCRATCH1 register. > + */ > + val = mask = BIT(bit_pos); You're using mask/val for half the function calls.. Stick with one approach. [...] > +struct pbs_dev *get_pbs_client_device(struct device *dev) > +{ > + struct device_node *pbs_dev_node; > + struct platform_device *pdev; > + struct pbs_dev *pbs; > + > + pbs_dev_node = of_parse_phandle(dev->of_node, "qcom,pbs", 0); > + if (!pbs_dev_node) { > + dev_err(dev, "Missing qcom,pbs property\n"); > + return ERR_PTR(-ENODEV); > + } > + > + pdev = of_find_device_by_node(pbs_dev_node); > + if (!pdev) { > + dev_err(dev, "Unable to find PBS dev_node\n"); > + pbs = ERR_PTR(-EPROBE_DEFER); > + goto out; > + } > + > + pbs = platform_get_drvdata(pdev); > + if (!pbs) { This check seems unnecessary, the PBS driver would have had to fail probing if set_drvdata never got called. Konrad