Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp566745imw; Thu, 14 Jul 2022 06:50:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uufDr8RhE31h0RJbZKFTY8g3rcMhtl8BvgEaODZxcRi0Eknjma4HwaPfnVlMAqEn2iwLFI X-Received: by 2002:a17:903:245:b0:16b:9b6d:20bc with SMTP id j5-20020a170903024500b0016b9b6d20bcmr8292076plh.14.1657806642109; Thu, 14 Jul 2022 06:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657806642; cv=none; d=google.com; s=arc-20160816; b=pM1aTe4VvRhwibrYERJhVDXdco5rIYcAOMgR0s4B4R1gBqFrsKi2HVq5dA4iyftkAp E8jGNZJVfJyEAu0amlPoyG6kE70AGG6EqR8qtgHTy0wRBFT1GP6k1Cuh5DWQAkcq21GM T1sEI1Tzpss77WQ3Z4BFlmm/DwlOq44mr/ZtZxIImsFKOa0Ih8O13KYXNM5gpwHVLYnZ yevVzmlrLGwTMsgUMNx4NgDtGvCER3SF3VSx0CrNDtxkkRJcu29nBPxrnKGlpRVNdk/N 2NLWwgc28FdyxC/F3ZN4N5+pXVhb207PbWRJCel9QsUP9ZgLcCXAs8FjAl0LPSgn2KTX sk2A== 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:dkim-signature; bh=o/uCGcJ47frDAidTP8LfsgkkatSl2wQ4r/QApE2FaGU=; b=oWOflWAZtAqyF7S5zwEhMEbYYsvlKx4aOheQ5It3efoschdHMDTKP0R9vilx86wJHx HVG0X7KoS59uEwQskoKF+jVKdsrykVY2CzSK81Pi3oF6xVmA70DrluSAITHC4pvSIiOo aC1xVzdGeCgfEcjXzqd1Am9TtNU8EJSbrcfjWEDo1G9xH4FCwSvmY9TUE7aIAJsvO8kX hfOGL+kIzjDW4uH/rwu+VrRmp/5F3E2zNsin+y/+ASWXvmadZUGR24pmZtzt1u24EDjf MKWqP/rmxoIq8ZwzhzKNxson5g+MPIBV66ZmQGe3L85jLvmy/sHtFI3e1UviA4JAr/+j pRBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=zESrki1a; 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=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a056a00181500b005182fb67e66si2905353pfa.159.2022.07.14.06.50.27; Thu, 14 Jul 2022 06:50:42 -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=@quicinc.com header.s=qcdkim header.b=zESrki1a; 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=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238767AbiGNNFa (ORCPT + 99 others); Thu, 14 Jul 2022 09:05:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231947AbiGNNF0 (ORCPT ); Thu, 14 Jul 2022 09:05:26 -0400 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABBFD2D1F9; Thu, 14 Jul 2022 06:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1657803925; x=1689339925; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=o/uCGcJ47frDAidTP8LfsgkkatSl2wQ4r/QApE2FaGU=; b=zESrki1aa27DopVzSh/NxADoXkmLgdzSmFcyGTs5BBAL+eRPovrEtsp8 CA3h6dEuhHE8/S1vuCECzsi83M4irllxr2ANJMefbuob/aIqBUa4h0n9Z a9htUp1eUKkgoqiWaIDoIiXSZZzoo730Lqn2a+SJelYD55ymCBtA4GIWp 0=; Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by alexa-out-sd-01.qualcomm.com with ESMTP; 14 Jul 2022 06:05:25 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg01-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2022 06:05:24 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 14 Jul 2022 06:05:24 -0700 Received: from [10.242.7.35] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Thu, 14 Jul 2022 06:05:20 -0700 Message-ID: <1bc53dc5-fc7f-54fd-ab7c-f1e77548b20d@quicinc.com> Date: Thu, 14 Jul 2022 18:35:17 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [V5] tty: serial: qcom-geni-serial: Fix get_clk_div_rate() which otherwise could return a sub-optimal clock rate. Content-Language: en-CA To: Jiri Slaby , , , , , , , CC: , , , References: <1657629905-24685-1-git-send-email-quic_vnivarth@quicinc.com> From: Vijaya Krishna Nivarthi In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 7/14/2022 4:16 PM, Jiri Slaby wrote: > On 12. 07. 22, 14:45, Vijaya Krishna Nivarthi wrote: > ... >> +static unsigned long get_clk_div_rate(struct clk *clk, struct device >> *dev, >> +        unsigned int baud, unsigned int sampling_rate, unsigned int >> *clk_div) >> +{ >> +    unsigned long ser_clk; >> +    unsigned long desired_clk; >> + >> +    desired_clk = baud * sampling_rate; >> +    if (!desired_clk) { >> +        dev_dbg(dev, "Invalid frequency\n"); >> +        return 0; >>       } >>   -    *clk_div = ser_clk / desired_clk; >> -    if (!(*clk_div)) >> -        *clk_div = 1; >> +    /* >> +     * try to find a clock rate within 2% tolerance, then within > > "then within" ... "5" is missing, perhaps? Yes :( Will change. > >> +     */ >> +    ser_clk = find_clk_rate_in_tol(clk, desired_clk, clk_div, 2); >> +    if (!ser_clk) >> +        ser_clk = find_clk_rate_in_tol(clk, desired_clk, clk_div, 5); >> + >> +    if (!ser_clk) >> +        dev_err(dev, "Couldn't find suitable clock rate for %lu\n", >> desired_clk); >> +    else >> +        dev_dbg(dev, "desired_clk-%lu, ser_clk-%lu, clk_div-%u\n", >> +                desired_clk, ser_clk, *clk_div); >>         return ser_clk; >>   } >> @@ -1021,8 +1040,8 @@ static void qcom_geni_serial_set_termios(struct >> uart_port *uport, >>       if (ver >= QUP_SE_VERSION_2_5) >>           sampling_rate /= 2; >>   -    clk_rate = get_clk_div_rate(port->se.clk, baud, >> -        sampling_rate, &clk_div); >> +    clk_rate = get_clk_div_rate(port->se.clk, port->se.dev, baud, > > Maybe worth passing whole geni_se (port->se) then? but then geni_se is a struct; shall we pass port instead? Alternately move logging to caller? Thank you. > >> +                    sampling_rate, &clk_div); >>       if (!clk_rate) >>           goto out_restart_rx; > > thanks,