Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4695341iog; Wed, 22 Jun 2022 04:09:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uBmAR9JiX3V0Puskn44BFMyiAwIHvqmcnKCEsKNAatur6AsfNU2ALtdE1g46bYdttLZ3KH X-Received: by 2002:a05:6402:1bcb:b0:435:8ec1:a580 with SMTP id ch11-20020a0564021bcb00b004358ec1a580mr3615990edb.68.1655896163014; Wed, 22 Jun 2022 04:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655896163; cv=none; d=google.com; s=arc-20160816; b=ESdhxUFG3oibfKbz8xPZbjw8YopSaJO5mVBhM3MiKgY8+r1v8YN8rUpHZ7hh6rqmGi HXLCWPvFF3cFJGnnmvhB02OE1f9rs7d2s/5Att/T4jNJDtwsdazhe+dqjzU8wSa1clZe yjWx8tmNuTDKzHhfPzjLp7Z3LNXcMVIfgrdPzY23xmkVQ6iL1aLrwl2+qJb5qssVMDjD hUPrCX6oKWfslUGvmKryzlHo27zyvv0NXsJMpwwsKzzWb3jpuLwfrda5FZPgNU+39Yii YGnhYAaghdxxegMhMI8d+UbI3OgVZxZZGgwMR+3Jr/D87Tx3WOvVLdeA+lHul+LVK91t uj1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=09m75uj4VJKcv8qDIqXsO3yJrvrISC65hIrs8N9FE4I=; b=zNUmw7gpxlmT2ZiGNSzVROs08l9ScgFjHLIDu2bYbKi2EkFI61+ndQkvJIyEzG+Vrt Vy3Qttg9YZd9a69FhbieoUw/pwIo0VwPiwit5KucrIwn77pzP9aW9fJT37LP1BAdpOwD KxmEHz8a0xte5UcXT2Hsi6yBuMGSYBa8pYqduZe1Ow/OOOxK8++P51WzjTBVfegnrwA/ 5PEAyzV8ARLm2vT+BxjewdosqQu7s+DyLSCBhYsRMZlx8nJ2CQLmKQ14dOsye2+jHYo0 Vl/S9Lv+Vn3pXhOIwvVxgbHfIfcE8wH4BCcnXvmNHWPInlUWP2Re9L6urLbz2V8NgCCk HHhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=UdGmC5fm; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020a1709065ac200b006ff1e01c729si14753178ejs.1009.2022.06.22.04.08.57; Wed, 22 Jun 2022 04:09:22 -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=@ti.com header.s=ti-com-17Q1 header.b=UdGmC5fm; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355845AbiFVKyB (ORCPT + 99 others); Wed, 22 Jun 2022 06:54:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355122AbiFVKxi (ORCPT ); Wed, 22 Jun 2022 06:53:38 -0400 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 613123B57B; Wed, 22 Jun 2022 03:53:36 -0700 (PDT) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 25MArL3l020508; Wed, 22 Jun 2022 05:53:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1655895201; bh=09m75uj4VJKcv8qDIqXsO3yJrvrISC65hIrs8N9FE4I=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=UdGmC5fmkakApd7lqlK57Rq/M3yjOL6hddo7ojONKa/oiclikRntxdiEBnte9g5rR UxFS6ILTmwJNCm3zG57nVCffL93pAvbxujM61dRD5tIt4Tm+3fSUev6wAAZg8xW55m wxoUTrxwOX27wOqLC0WwDZ/ZFm5+ph32ielFgkNg= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 25MArLPh026681 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 22 Jun 2022 05:53:21 -0500 Received: from DLEE115.ent.ti.com (157.170.170.26) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Wed, 22 Jun 2022 05:53:20 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14 via Frontend Transport; Wed, 22 Jun 2022 05:53:20 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 25MArJ2P016904; Wed, 22 Jun 2022 05:53:19 -0500 From: Rahul T R To: , , , , , CC: , , , , , , , , , Rahul T R Subject: [PATCH v3 2/3] phy: cdns-dphy: Add band config for dphy tx Date: Wed, 22 Jun 2022 16:23:10 +0530 Message-ID: <20220622105311.21415-3-r-ravikumar@ti.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220622105311.21415-1-r-ravikumar@ti.com> References: <20220622105311.21415-1-r-ravikumar@ti.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Add support for band ctrl config for dphy tx. Signed-off-by: Rahul T R --- drivers/phy/cadence/cdns-dphy.c | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/phy/cadence/cdns-dphy.c b/drivers/phy/cadence/cdns-dphy.c index ba042e39cfaf..14f951013b4f 100644 --- a/drivers/phy/cadence/cdns-dphy.c +++ b/drivers/phy/cadence/cdns-dphy.c @@ -3,6 +3,7 @@ * Copyright: 2017-2018 Cadence Design Systems, Inc. */ +#include #include #include #include @@ -45,6 +46,10 @@ #define DPHY_CMN_OPDIV_FROM_REG BIT(6) #define DPHY_CMN_OPDIV(x) ((x) << 7) +#define DPHY_BAND_CFG DPHY_PCS(0x0) +#define DPHY_BAND_CFG_LEFT_BAND GENMASK(4, 0) +#define DPHY_BAND_CFG_RIGHT_BAND GENMASK(9, 5) + #define DPHY_PSM_CFG DPHY_PCS(0x4) #define DPHY_PSM_CFG_FROM_REG BIT(0) #define DPHY_PSM_CLK_DIV(x) ((x) << 1) @@ -92,6 +97,12 @@ struct cdns_dphy { struct phy *phy; }; +/* Order of bands is important since the index is the band number. */ +static const unsigned int tx_bands[] = { + 80, 100, 120, 160, 200, 240, 320, 390, 450, 510, 560, 640, 690, 770, + 870, 950, 1000, 1200, 1400, 1600, 1800, 2000, 2200, 2500 +}; + static int cdns_dsi_get_dphy_pll_cfg(struct cdns_dphy *dphy, struct cdns_dphy_cfg *cfg, struct phy_configure_opts_mipi_dphy *opts, @@ -232,6 +243,24 @@ static int cdns_dphy_config_from_opts(struct phy *phy, return 0; } +static int cdns_dphy_tx_get_band_ctrl(unsigned long hs_clk_rate) +{ + unsigned int rate; + int i; + + rate = hs_clk_rate / 1000000UL; + + if (rate < tx_bands[0]) + return -EOPNOTSUPP; + + for (i = 0; i < ARRAY_SIZE(tx_bands) - 1; i++) { + if (rate >= tx_bands[i] && rate < tx_bands[i + 1]) + return i; + } + + return -EOPNOTSUPP; +} + static int cdns_dphy_validate(struct phy *phy, enum phy_mode mode, int submode, union phy_configure_opts *opts) { @@ -247,7 +276,8 @@ static int cdns_dphy_configure(struct phy *phy, union phy_configure_opts *opts) { struct cdns_dphy *dphy = phy_get_drvdata(phy); struct cdns_dphy_cfg cfg = { 0 }; - int ret; + int ret, band_ctrl; + unsigned int reg; ret = cdns_dphy_config_from_opts(phy, &opts->mipi_dphy, &cfg); if (ret) @@ -276,6 +306,14 @@ static int cdns_dphy_configure(struct phy *phy, union phy_configure_opts *opts) */ cdns_dphy_set_pll_cfg(dphy, &cfg); + band_ctrl = cdns_dphy_tx_get_band_ctrl(opts->mipi_dphy.hs_clk_rate); + if (band_ctrl < 0) + return band_ctrl; + + reg = FIELD_PREP(DPHY_BAND_CFG_LEFT_BAND, band_ctrl) | + FIELD_PREP(DPHY_BAND_CFG_RIGHT_BAND, band_ctrl); + writel(reg, dphy->regs + DPHY_BAND_CFG); + return 0; } -- 2.36.1