X-Received: by 2002:a17:90b:4aca:b0:1b9:ed62:b917 with SMTP id mh10-20020a17090b4aca00b001b9ed62b917mr2574084pjb.237.1645511046360; Mon, 21 Feb 2022 22:24:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645511046; cv=none; d=google.com; s=arc-20160816; b=Q3MyeXnshWv8qjEiy3fkW5WD3FazDm1l16Ld0HRmI3NHrHRAmDJ7CbKqHDd7qqMwhM MCgPXLr/UD9+ANFpX/LT6TTWjX2phWzS0rmgbr8BezvY2v54kAm5NCUA1W6pRU9k7EGg VS+nJ5nNmCJ4ytuMBMbhUGHpH9ZekBWEolTx1lYTfV4vqsh8uMDTQVs8GK15ntwDXaam ZQJznPJE03K+0AjrALtmt33IH3ola9TMyc/BbfJQcTte/oHBaugek6Yzy6iYD89s+vGu q6e4WI3Y/V+v/dfTuibWyA0xJdfs011hQzYZUUt7AI6LhRmiQfgzDVzfstTdQR3b7Lwo FR6w== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:sender:hmm_source_type:hmm_attache_num :hmm_source_ip; bh=nK2BfRn1vFBR3wRDuuDAvhPLrK/zBDk7ZLJlWDk/ivY=; b=jZXWvTyh2kW0B0mDOhNgPZAJ3LEqox13v88DO0QBF+6Wgm48bmuGgv1MhB6xW8kZig ds+V9bAL7s1Ay7AS2V47xwg6EhlEaIRV1PDFl2ucuM1duo4C7CmHZnH4ASaWi5SUJExw D9hb6n+RrAnwTtTRVvrAQ4i5g1UtsfL1lOFeTz7TEn01zTtng7qSNCpk2ikfFksn3MK0 M9/9q9fwELSz+ynF79CSsesLiFm4J7m9AGTc6BfhRczcq8PpK6GU/XWyoowxXKUb/xWo w+NUuodJWXFw9982e8Q5J39l+GNSpOWQ4ZbI5jbfw+F13+6ecuHeHuJ65nHhOUh5XO8O 2Q3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r21si18500615pgr.24.2022.02.21.22.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 22:24:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7AB488B6CB; Mon, 21 Feb 2022 22:19:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230232AbiBVGTr (ORCPT + 99 others); Tue, 22 Feb 2022 01:19:47 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:59400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbiBVGTo (ORCPT ); Tue, 22 Feb 2022 01:19:44 -0500 Received: from 189.cn (ptr.189.cn [183.61.185.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 956CC38D; Mon, 21 Feb 2022 22:19:17 -0800 (PST) HMM_SOURCE_IP: 10.64.8.41:48930.1246802973 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 37FD110029B; Tue, 22 Feb 2022 14:19:13 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-749df8664c-mvcg4 with ESMTP id c91b0e0e5db24317b915d9bb4d3e7f4d for gregkh@linuxfoundation.org; Tue, 22 Feb 2022 14:19:14 CST X-Transaction-ID: c91b0e0e5db24317b915d9bb4d3e7f4d X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 Sender: chensong_2000@189.cn Message-ID: Date: Tue, 22 Feb 2022 14:19:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v2] staging: greybus: introduce pwm_ops::apply Content-Language: en-US To: Greg KH Cc: johan@kernel.org, elder@kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de, lee.jones@linaro.org, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org References: <1644580947-8529-1-git-send-email-chensong_2000@189.cn> From: Song Chen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, SPOOFED_FREEMAIL_NO_RDNS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi Greg, 在 2022/2/22 01:06, Greg KH 写道: > On Fri, Feb 11, 2022 at 08:02:27PM +0800, Song Chen wrote: >> Introduce apply in pwm_ops to replace legacy operations, >> like enable, disable, config and set_polarity. >> >> Signed-off-by: Song Chen >> >> --- >> V2: >> 1, define duty_cycle and period as u64 in gb_pwm_config_operation. >> 2, define duty and period as u64 in gb_pwm_config_request. >> 3, disable before configuring duty and period if the eventual goal >> is a disabled state. >> --- >> drivers/staging/greybus/pwm.c | 61 ++++++++++++----------- >> include/linux/greybus/greybus_protocols.h | 4 +- >> 2 files changed, 34 insertions(+), 31 deletions(-) >> >> diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c >> index 891a6a672378..03c69db5b9be 100644 >> --- a/drivers/staging/greybus/pwm.c >> +++ b/drivers/staging/greybus/pwm.c >> @@ -89,7 +89,7 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, >> } >> >> static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc, >> - u8 which, u32 duty, u32 period) >> + u8 which, u64 duty, u64 period) >> { >> struct gb_pwm_config_request request; >> struct gbphy_device *gbphy_dev; >> @@ -99,8 +99,8 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc, >> return -EINVAL; >> >> request.which = which; >> - request.duty = cpu_to_le32(duty); >> - request.period = cpu_to_le32(period); >> + request.duty = duty; >> + request.period = period; >> >> gbphy_dev = to_gbphy_dev(pwmc->chip.dev); >> ret = gbphy_runtime_get_sync(gbphy_dev); >> @@ -204,43 +204,46 @@ static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) >> gb_pwm_deactivate_operation(pwmc, pwm->hwpwm); >> } >> >> -static int gb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, >> - int duty_ns, int period_ns) >> +static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, >> + const struct pwm_state *state) >> { >> + int err; >> + bool enabled = pwm->state.enabled; >> struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); >> >> - return gb_pwm_config_operation(pwmc, pwm->hwpwm, duty_ns, period_ns); >> -}; >> - >> -static int gb_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, >> - enum pwm_polarity polarity) >> -{ >> - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); >> - >> - return gb_pwm_set_polarity_operation(pwmc, pwm->hwpwm, polarity); >> -}; >> + /* set polarity */ >> + if (state->polarity != pwm->state.polarity) { >> + if (enabled) { >> + gb_pwm_disable_operation(pwmc, pwm->hwpwm); >> + enabled = false; >> + } >> + err = gb_pwm_set_polarity_operation(pwmc, pwm->hwpwm, state->polarity); >> + if (err) >> + return err; >> + } >> >> -static int gb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) >> -{ >> - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); >> + if (!state->enabled) { >> + if (enabled) >> + gb_pwm_disable_operation(pwmc, pwm->hwpwm); >> + return 0; >> + } >> >> - return gb_pwm_enable_operation(pwmc, pwm->hwpwm); >> -}; >> + /* set period and duty cycle*/ >> + err = gb_pwm_config_operation(pwmc, pwm->hwpwm, state->duty_cycle, state->period); >> + if (err) >> + return err; >> >> -static void gb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) >> -{ >> - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); >> + /* enable/disable */ >> + if (!enabled) >> + return gb_pwm_enable_operation(pwmc, pwm->hwpwm); >> >> - gb_pwm_disable_operation(pwmc, pwm->hwpwm); >> -}; >> + return 0; >> +} >> >> static const struct pwm_ops gb_pwm_ops = { >> .request = gb_pwm_request, >> .free = gb_pwm_free, >> - .config = gb_pwm_config, >> - .set_polarity = gb_pwm_set_polarity, >> - .enable = gb_pwm_enable, >> - .disable = gb_pwm_disable, >> + .apply = gb_pwm_apply, >> .owner = THIS_MODULE, >> }; >> >> diff --git a/include/linux/greybus/greybus_protocols.h b/include/linux/greybus/greybus_protocols.h >> index aeb8f9243545..81a6f16de098 100644 >> --- a/include/linux/greybus/greybus_protocols.h >> +++ b/include/linux/greybus/greybus_protocols.h >> @@ -812,8 +812,8 @@ struct gb_pwm_deactivate_request { >> >> struct gb_pwm_config_request { >> __u8 which; >> - __le32 duty; >> - __le32 period; >> + __u64 duty; >> + __u64 period; >> } __packed; > > Did you just change a greybus protocol message that is sent over the > wire? Why? And why drop the endian marking of it? I discussed with Uwe about losing bit and found there is no perfect way to avoid, even in Uwe's patch[1], as a result, we decided to widen duty and period in gb_pwm_config_request, the other side of the wire is supposed to change accordingly to support 64bit duty and period too(this will introduce compatibility problem and there is no variable like version to address it), similar with ktime_t in y2038, below is the detail [2] [1]:https://lore.kernel.org/all/20210312212119.1342666-1-u.kleine-koenig@pengutronix.de/ [2]:https://lore.kernel.org/all/20220211071601.4rpfbkit6c6dre2o@pengutronix.de/ endian is a problem, i shouldn't drop it. BR Song > > Are you sure this is ok? > > thanks, > > greg k-h >