From patchwork Mon Nov 14 23:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dinh Nguyen X-Patchwork-Id: 20075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2408967wru; Mon, 14 Nov 2022 15:05:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf4n9qYe7lE6KGUogwofTyYVi3n28X7LbNaZ9nqdnm110MSMmKG5QqVhdsOLXtWgwk5Gfq5z X-Received: by 2002:a17:907:6d18:b0:7ad:aedb:2e6d with SMTP id sa24-20020a1709076d1800b007adaedb2e6dmr11666327ejc.536.1668467157231; Mon, 14 Nov 2022 15:05:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668467157; cv=none; d=google.com; s=arc-20160816; b=ccLxY3tEvG3UVqAd4Wq7OaW1Dl5VCL97/F7R8pyB9C5yMK/UucdZ5Hq+BBUDyf5Jwp CkEJrQwr8emxTdFoT28BNKm8yjP2k/9Ux/x8aFLVYmziLRV6UkIsA1NHfcumE1X7wumP Bk9sPImxrCnrEqEwR16cEPoJMFKuc29BMLq1panKG3s2u7NDVt7oU5aFZxl4bdqSbTZz Yu9DHNq4lUBkvFt/m8Jd5AKcDPR20cPoWoJmJAJCDDXP9aNmNBNbVJTKwZW0AXKvPjSN EPCdQ/SNCFUAZaA0JjjV83YRuD7RqfXNgUmge3WF6fAcoY5PKChvuOSqpMo3LKFIDsof vpcA== 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=X1B4yLEmeRxGz88Y3RqVjxALlovDQl34Selvexpf9/8=; b=AAL4zPI5doZJ6g8IpBHZTtosTknTMjDLEObG2syV3q8rr7feXhO+Wo4cu+iHvCpNJv BZpbbwlsDqxeTldVgZ9EuGdDRtBHGNEGAGG/mhM9caYXdqkgnfm6X2Bh+6m5+yu9JtuQ M1siVyuotGT02HJeEsoUbvihJhavU4cSx8dopPvXQB8brWQnF68NRchfu8XMg2BAEU3p NXkVxCi6TOUEkx7qNJgHnEzORZDQ9Ay6LGYaHeMgr8fck3ql91xqh303nFJZV9zHKydi fO/hZt3D7UaZZW6SIlyJPTjKbDF9ejdHFufuokPgo8UQljctOu1B8zgoHJY8bSngoYsG C+xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X88qJahL; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cy24-20020a0564021c9800b00458cdba7a90si9473930edb.471.2022.11.14.15.05.33; Mon, 14 Nov 2022 15:05:57 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=X88qJahL; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237901AbiKNXCo (ORCPT + 99 others); Mon, 14 Nov 2022 18:02:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237841AbiKNXC3 (ORCPT ); Mon, 14 Nov 2022 18:02:29 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C5091B7A2; Mon, 14 Nov 2022 15:02:29 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BC52EB815BD; Mon, 14 Nov 2022 23:02:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6900CC43140; Mon, 14 Nov 2022 23:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668466946; bh=mP1glOMgwwjtxxD/5YyQGpy9Kmwl+tbpsLXysXmem+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X88qJahLWjU6ipVHtqUEc2mvYoJbNkgZHmy3j0WyJZi4p5bH7nFWT70KpFbBbASgI ugMuU270WgpeAi6aXl/dD6joIQRx0iqTyi0MM/7nyDGifmXkPWlU0Rj7dlmqKH3Ov1 4HleICOIGJJ8Hk7FupQpyhxiTmtPhPYP+YPFG35w0cHMxJRBZ8anYsstT81Fz8iFGK vGEwboFb5YlYtTluHS+2s613TXX0shIu56wOoJm28pkjY79U9+gx4uRFjrieZUhoaB NEtV6mEQpB5NfwT8ep0gZ8p+j+BL83DsD3OY6+WreLqBbJuot7xRLIV10rRMbVUTVB Y+XHRn9Tp+1ng== From: Dinh Nguyen To: jh80.chung@samsung.com Cc: dinguyen@kernel.org, ulf.hansson@linaro.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, mturquette@baylibre.com, sboyd@kernel.org, linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org Subject: [PATCHv9 4/6] mmc: dw_mmc-pltfm: socfpga: add method to configure clk-phase Date: Mon, 14 Nov 2022 17:02:15 -0600 Message-Id: <20221114230217.202634-4-dinguyen@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221114230217.202634-1-dinguyen@kernel.org> References: <20221114230217.202634-1-dinguyen@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749514618047942917?= X-GMAIL-MSGID: =?utf-8?q?1749514618047942917?= The clock-phase settings for the SDMMC controller in the SoCFPGA platforms reside in a register in the System Manager. Add a method to access that register through the syscon interface. Signed-off-by: Dinh Nguyen --- v9: no changes v8: no changes v7: use dev_warn if clk-phase-sd-hs is specified, but "altr,sysmgr-syscon" is not found v6: not getting the clk-phase-sd-hs is not a hard failure v5: change error handling from of_property_read_variable_u32_array() support arm32 by reading the reg_shift v4: no change v3: add space before &socfpga_drv_data v2: simplify clk-phase calculations --- drivers/mmc/host/dw_mmc-pltfm.c | 41 ++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/dw_mmc-pltfm.c b/drivers/mmc/host/dw_mmc-pltfm.c index 9901208be797..13e55cff8237 100644 --- a/drivers/mmc/host/dw_mmc-pltfm.c +++ b/drivers/mmc/host/dw_mmc-pltfm.c @@ -17,10 +17,16 @@ #include #include #include +#include +#include #include "dw_mmc.h" #include "dw_mmc-pltfm.h" +#define SOCFPGA_DW_MMC_CLK_PHASE_STEP 45 +#define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel, reg_shift) \ + ((((smplsel) & 0x7) << reg_shift) | (((drvsel) & 0x7) << 0)) + int dw_mci_pltfm_register(struct platform_device *pdev, const struct dw_mci_drv_data *drv_data) { @@ -62,9 +68,42 @@ const struct dev_pm_ops dw_mci_pltfm_pmops = { }; EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops); +static int dw_mci_socfpga_priv_init(struct dw_mci *host) +{ + struct device_node *np = host->dev->of_node; + struct regmap *sys_mgr_base_addr; + u32 clk_phase[2] = {0}, reg_offset, reg_shift; + int i, rc, hs_timing; + + rc = of_property_read_variable_u32_array(np, "clk-phase-sd-hs", &clk_phase[0], 2, 0); + if (rc < 0) + return 0; + + sys_mgr_base_addr = altr_sysmgr_regmap_lookup_by_phandle(np, "altr,sysmgr-syscon"); + if (IS_ERR(sys_mgr_base_addr)) { + dev_warn(host->dev, "clk-phase-sd-hs was specified, but failed to find altr,sys-mgr regmap!\n"); + return 0; + } + + of_property_read_u32_index(np, "altr,sysmgr-syscon", 1, ®_offset); + of_property_read_u32_index(np, "altr,sysmgr-syscon", 2, ®_shift); + + for (i = 0; i < ARRAY_SIZE(clk_phase); i++) + clk_phase[i] /= SOCFPGA_DW_MMC_CLK_PHASE_STEP; + + hs_timing = SYSMGR_SDMMC_CTRL_SET(clk_phase[0], clk_phase[1], reg_shift); + regmap_write(sys_mgr_base_addr, reg_offset, hs_timing); + + return 0; +} + +static const struct dw_mci_drv_data socfpga_drv_data = { + .init = dw_mci_socfpga_priv_init, +}; + static const struct of_device_id dw_mci_pltfm_match[] = { { .compatible = "snps,dw-mshc", }, - { .compatible = "altr,socfpga-dw-mshc", }, + { .compatible = "altr,socfpga-dw-mshc", .data = &socfpga_drv_data, }, { .compatible = "img,pistachio-dw-mshc", }, {}, };