Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5177163rwb; Wed, 21 Sep 2022 04:24:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7PdisQTRBLyWC5kjuLgV8utwDm7D0L4IbjVPKeT2RhGG3KkDamA8MzbYjYFd+4xe094BdC X-Received: by 2002:a17:907:31c1:b0:742:28a3:5d08 with SMTP id xf1-20020a17090731c100b0074228a35d08mr20279600ejb.112.1663759461594; Wed, 21 Sep 2022 04:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663759461; cv=none; d=google.com; s=arc-20160816; b=pEegvmrGX6TNOjrmF3vH5UDO7DYXEGOPsUgy9bziPy5OrDFj5dJqfmMmaGvJnN5mCA kFh5pFbp9kvv0N6T1R3R/NH9p30yBGI3h1ZaLQA5s4IZAlsjcfzpNTIUy0OvyhgI9tj1 uMYjzsZmIKEBc6zVeckx2C5pf11l2duLYpX7p2JJpUQstGWWVqoDDk2FPHk0xxWH+viA OMFLhbtgGOp0d7WMYxmlPuRqo9h2ustHU6TaaswMYb2LTxihplb+/H2+hb6u6xk9PnNd zGZ2ZdhQ4EN8oNZjphvc9CzJ7PsCyHE9AQTzhGhLer9iX1519ciTCsYJeiitys+FGOTH M9MA== 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=DDvZeUPRCeqd9gPA+ABe+HXLhz0ecUWic+vr4TeHNb0=; b=yMPhpDKtHEcmYzHD83+pPLLuBCFMdovwgRdfeud1chE6+4AznA6oYDQuO1qP3+h1Eb OmRfGW+iokbceQGNK52HmQqNZCaiEYaSD1CV0DXiwO8pM960WFk679RXpewtq9wMlhul m7QBr0Vpr3XSWk6c/5IdGBc+OHj+7v4g3jAc1q4Noip55OWOEOiVbO+Xf0Lf1wOO19O8 f58wjYKCoi+OZVLLXsUMNZuCrq/EEPdE5/6I6t4Dzky7tVpFEYaushxYlGJGvCOtlUGB eF37MW/UxnLcaTKRy4MIYmJCgdBWK2461L4Fd//VG9Z9eVINBJLgcuzLmcxtESYRsxvF 3Rng== 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 r19-20020aa7c153000000b00452e7ae21e6si1930962edp.286.2022.09.21.04.23.55; Wed, 21 Sep 2022 04:24:21 -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 S229775AbiIUKOJ (ORCPT + 99 others); Wed, 21 Sep 2022 06:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiIUKOH (ORCPT ); Wed, 21 Sep 2022 06:14:07 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D62CB7FF84; Wed, 21 Sep 2022 03:14:05 -0700 (PDT) Received: from canpemm500004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MXZ0P0DlrzlWv4; Wed, 21 Sep 2022 18:09:57 +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; Wed, 21 Sep 2022 18:14:04 +0800 From: Weilong Chen To: , CC: , Subject: [PATCH] i2c: hisi: Add support to get clock frequency from clock property Date: Wed, 21 Sep 2022 18:15:40 +0800 Message-ID: <20220921101540.352553-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: dggems706-chm.china.huawei.com (10.3.19.183) 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 --- drivers/i2c/busses/i2c-hisi.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c index 67031024217c..5e48d4ee0c6d 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 @@ -91,6 +92,7 @@ struct hisi_i2c_controller { void __iomem *iobase; struct device *dev; int irq; + struct clk *clk; /* Intermediates for recording the transfer process */ struct completion *completion; @@ -456,10 +458,21 @@ 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(&pdev->dev, NULL); + if (IS_ERR(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 { + ret = clk_prepare_enable(ctlr->clk); + if (ret) { + dev_err(dev, "failed to enable clock, ret = %d\n", ret); + return ret; + } + + clk_rate_hz = clk_get_rate(ctlr->clk); } ctlr->clk_rate_khz = DIV_ROUND_UP_ULL(clk_rate_hz, HZ_PER_KHZ); @@ -475,8 +488,10 @@ static int hisi_i2c_probe(struct platform_device *pdev) i2c_set_adapdata(adapter, ctlr); ret = devm_i2c_add_adapter(dev, adapter); - if (ret) + if (ret) { + clk_disable_unprepare(ctlr->clk); return ret; + } hw_version = readl(ctlr->iobase + HISI_I2C_VERSION); dev_info(ctlr->dev, "speed mode is %s. hw version 0x%x\n", -- 2.31.GIT