Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp304013rwb; Thu, 22 Sep 2022 18:37:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6b9Rig2jWlGs7VN0CPy6FMr6IvfvSeNHYxhqLEfaVWG3mhIqRCqPuVArWsrsIir5TtActf X-Received: by 2002:a17:903:188:b0:178:3d49:45a0 with SMTP id z8-20020a170903018800b001783d4945a0mr6160818plg.154.1663897044276; Thu, 22 Sep 2022 18:37:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663897044; cv=none; d=google.com; s=arc-20160816; b=XCgqj1Vim9IVW4hDjwq/3IjkQ2PJg+OGsiBOTvUjEZbKAoXM3P/46FScRWsHfoTVhe BNhOLiTKpm5Azl2DJt/1LGVr8Vk4ZAcLo8c7tRk5AiCvvKS3BZlfC481XyQU3Fo58eBI g8sTJu4iKXmGf7/63wlmocv6jox/CWBnQ/EViQE1N32GcKJRSKD+k5qTFNPNwq9RJFl6 BrZLvxFFEQjJMldNWdjDavisO6nvR7QobZI2dNux0pV0Dd6J06JrE08G6+CDZsg4ACeJ e9TyEzc8mcNliBTmwJoPd05bS9GywGV4R7Mz1H2qO57fAFf03tekRSqSsTLfV7Ieh3Uj /qzA== 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 :message-id:date:subject:cc:to:from; bh=KgEea4n5M/xmLpr3q5NcwnN+TbQ1AtoPOtYdfRqblsk=; b=SowX3OyBwgExSQUeIwhr0h/81N48uOUL9SS2W16F9n7A2XuxidSzx2lmUsQCUuw331 PuMZEgNCXyfxF3VDWF9NhUntZqQNgNBUmK0alrq1lISZrQ46ToukXB6iaL4GNekQSXBc MeTd1wn/4GYhNVOXY2owrgtr5aO5JBZIqziWGpyC1g2cnXcnyeZAEqhtOQKgvPEJOPk2 gVCekt5kqfjrSEC1Q8zi+7IU+sslKjiGrsMDs5EqfqhmzDqbPvOT6lZU12Q67CsHXxs3 q+bjnFOavmtOkZVDvys6hfE5E9FO3xXjWcQt7CHtwCKi7JqeZzqUfmAgNL4zRAvbEFG1 HHKg== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a637a47000000b004345da5a712si9454713pgn.188.2022.09.22.18.37.13; Thu, 22 Sep 2022 18:37:24 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231872AbiIWBM7 (ORCPT + 99 others); Thu, 22 Sep 2022 21:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231312AbiIWBMs (ORCPT ); Thu, 22 Sep 2022 21:12:48 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CF3FD11E; Thu, 22 Sep 2022 18:12:46 -0700 (PDT) Received: from canpemm500004.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MYYx52FqDzHqFv; Fri, 23 Sep 2022 09:10:33 +0800 (CST) Received: from localhost (10.175.101.6) by canpemm500004.china.huawei.com (7.192.104.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 23 Sep 2022 09:12:44 +0800 From: Weilong Chen To: , CC: , Subject: [PATCH next v2] i2c: hisi: Add support to get clock frequency from clock property Date: Fri, 23 Sep 2022 09:14:17 +0800 Message-ID: <20220923011417.78994-1-chenweilong@huawei.com> X-Mailer: git-send-email 2.31.GIT MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500004.china.huawei.com (7.192.104.92) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 Support the driver to obtain clock information by clk_rate or clock property. Find clock first, if not, fall back to clk_rate. Signed-off-by: Weilong Chen --- Change since v1: - Ordered struct field to inverted triangle. - Use devm_clk_get_optional_enabled(). - Use IS_ERR_OR_NULL. Link: https://lore.kernel.org/lkml/20220921101540.352553-1-chenweilong@huawei.com/ drivers/i2c/busses/i2c-hisi.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c index 67031024217c..b3bcce71dd2c 100644 --- a/drivers/i2c/busses/i2c-hisi.c +++ b/drivers/i2c/busses/i2c-hisi.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,7 @@ struct hisi_i2c_controller { struct i2c_adapter adapter; void __iomem *iobase; struct device *dev; + struct clk *clk; int irq; /* Intermediates for recording the transfer process */ @@ -456,10 +458,16 @@ static int hisi_i2c_probe(struct platform_device *pdev) return ret; } - ret = device_property_read_u64(dev, "clk_rate", &clk_rate_hz); - if (ret) { - dev_err(dev, "failed to get clock frequency, ret = %d\n", ret); - return ret; + ctlr->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL); + if (IS_ERR_OR_NULL(ctlr->clk)) { + ret = device_property_read_u64(dev, "clk_rate", &clk_rate_hz); + if (ret) { + dev_err(dev, "failed to get clock frequency, ret = %d\n", ret); + return ret; + } + } else { + + clk_rate_hz = clk_get_rate(ctlr->clk); } ctlr->clk_rate_khz = DIV_ROUND_UP_ULL(clk_rate_hz, HZ_PER_KHZ); -- 2.31.GIT