From patchwork Thu Mar 9 06:39:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9612365 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70C10602B4 for ; Thu, 9 Mar 2017 07:02:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 532B228435 for ; Thu, 9 Mar 2017 07:02:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 481762846C; Thu, 9 Mar 2017 07:02:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E7AC728435 for ; Thu, 9 Mar 2017 07:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mOrS+cmuU1sPvb6b1MNekTs7SmvFesEYzvVIMTOVamg=; b=TysVmMwQcz9yMk yxCf0B69xMl01o0bv+jlE5dE2DbMzN36wRZIBLTlm5AyuPcuqnV/tJlPKb6fk5e0BWlp1FqIYj64F LagFl91fHYATaVvAt2XqLmTu32Dp/Z5EzvKJ1lCV+evCRQxu55mR+FXTSr1NE8Pu8vu4OwXvJFt6+ cFOhyN2TDszL0/eegW3TkAus3hayKwcsM/cr4TvsoLY3W8MviGZ+2xmnTijbVb6upo1f933t1005h Io8cDpf4svlXgSpODeSWiJYgOSBzENcBsbbko7QbqNPNjKltV/223AxfT2SlU2gEeOVNLKyT6Pz5I eh9sxi6Ma3Ox70SbAXwg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cls5P-0002bo-KC; Thu, 09 Mar 2017 07:02:07 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cls5L-0002Y5-CJ for linux-amlogic@lists.infradead.org; Thu, 09 Mar 2017 07:02:05 +0000 Received: by mail-wr0-x242.google.com with SMTP id g10so6724476wrg.0 for ; Wed, 08 Mar 2017 23:01:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=zFDEI4D9KQzuLgg4Z3zM2keOsnAEiJzRu1xZeu1C+dk=; b=FXc/4wt9mUR9S4ETuVnUpN3iusLghrAEsIiCcmPuLN1UjgPatyLBsnEysF6PWkpFAX SPQOQuiJPlDAk2kTmM1wj8OdVT7A7e0L8bpVQ4E98jBvf4BMI31ByYU1bCc7K80QbFbf ITqb4cCDcnRyvdv1wNi/fcBBkNyfxO03rwlAyayW/YFnMzgk+XrDAMURpucvrHMH30VH 5teRDLrSPpCOlu9LVObL+oR//3nztyuMovqJqXnZiVguLMQeAi8qY1VHwEZthqLLoWrZ cnMQfHQ4hHd3TIqDRrX5TRfkbznSiUCk6qkUxrognX7wpK64usXGkrEaNFWOd6hjPe/V hWIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=zFDEI4D9KQzuLgg4Z3zM2keOsnAEiJzRu1xZeu1C+dk=; b=Re6o4bQEfDTfDfm4c5r1eqchl12uawpEl17pH3ZtYnjJIrpV52ZXSsu7fYmNq4Z0ze f/E5Th/TPIc5fToOhAiSf4V1CQWefDLrLP6EvT3tsY33ybtnhfZU5zz5Wm4kv7S1m5+Y 1f+XFbP8i1H55qfGTmuiwiI9ro/2WYFuFw8i8bceC9pYjRAP64AcT0nyrCj5SNwocGa9 ZwR66PXP+m5hVjalYjnBl4OQj5/+eOFD11WdT4kOrh0gmXHIAUczY9B7fyJxtybumZI9 0jd3wgafjGzDdDev7zw6ZlQt2/zCJcXanHXb+Pb2kgODHLGhXd7wFueyJh8MhhKHoYQ8 PCLw== X-Gm-Message-State: AMke39l/zw5HVlQ++qWqVhmEGbUFcARXHGbUIAAFaz2bXttoimWhkVa9UuI2Gwb+5j4HNQ== X-Received: by 10.223.164.140 with SMTP id g12mr9051251wrb.87.1489042901698; Wed, 08 Mar 2017 23:01:41 -0800 (PST) Received: from ?IPv6:2003:c6:ebdc:4000:b589:624b:5134:aa75? (p200300C6EBDC4000B589624B5134AA75.dip0.t-ipconnect.de. [2003:c6:ebdc:4000:b589:624b:5134:aa75]) by smtp.googlemail.com with ESMTPSA id d75sm7559857wmd.25.2017.03.08.23.01.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Mar 2017 23:01:41 -0800 (PST) Subject: [PATCH v2 03/10] i2c: meson: use i2c core for DT clock-frequency parsing To: Wolfram Sang , Jerome Brunet References: From: Heiner Kallweit Message-ID: <1b175225-9cb1-6c7c-3175-dcba8189fefe@gmail.com> Date: Thu, 9 Mar 2017 07:39:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170308_230203_579386_B676B3C1 X-CRM114-Status: GOOD ( 10.96 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, "linux-i2c@vger.kernel.org" Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We don't have to parse the DT manually to retrieve the bus frequency and we don't have to maintain an own default for the bus frequency. Let the i2c core do this for us. Signed-off-by: Heiner Kallweit Reviewed-by: Jerome Brunet Reviewed-by: Neil Armstrong --- v2: - added Reviewed-by --- drivers/i2c/busses/i2c-meson.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-meson.c b/drivers/i2c/busses/i2c-meson.c index 50059d09..5e243efa 100644 --- a/drivers/i2c/busses/i2c-meson.c +++ b/drivers/i2c/busses/i2c-meson.c @@ -38,7 +38,6 @@ #define REG_CTRL_CLKDIV_MASK ((BIT(10) - 1) << REG_CTRL_CLKDIV_SHIFT) #define I2C_TIMEOUT_MS 500 -#define DEFAULT_FREQ 100000 enum { TOKEN_END = 0, @@ -73,7 +72,7 @@ enum { * @error: Flag set when an error is received * @lock: To avoid race conditions between irq handler and xfer code * @done: Completion used to wait for transfer termination - * @frequency: Operating frequency of I2C bus clock + * @timings: Struct including the bus frequency * @tokens: Sequence of tokens to be written to the device * @num_tokens: Number of tokens */ @@ -92,7 +91,7 @@ struct meson_i2c { spinlock_t lock; struct completion done; - unsigned int frequency; + struct i2c_timings timings; u32 tokens[2]; int num_tokens; }; @@ -136,12 +135,12 @@ static void meson_i2c_set_clk_div(struct meson_i2c *i2c) unsigned long clk_rate = clk_get_rate(i2c->clk); unsigned int div; - div = DIV_ROUND_UP(clk_rate, i2c->frequency * 4); + div = DIV_ROUND_UP(clk_rate, i2c->timings.bus_freq_hz * 4); meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIV_MASK, div << REG_CTRL_CLKDIV_SHIFT); dev_dbg(i2c->dev, "%s: clk %lu, freq %u, div %u\n", __func__, - clk_rate, i2c->frequency, div); + clk_rate, i2c->timings.bus_freq_hz, div); } static void meson_i2c_get_data(struct meson_i2c *i2c, char *buf, int len) @@ -396,9 +395,7 @@ static int meson_i2c_probe(struct platform_device *pdev) if (!i2c) return -ENOMEM; - if (of_property_read_u32(pdev->dev.of_node, "clock-frequency", - &i2c->frequency)) - i2c->frequency = DEFAULT_FREQ; + i2c_parse_fw_timings(&pdev->dev, &i2c->timings, true); i2c->dev = &pdev->dev; platform_set_drvdata(pdev, i2c);