From patchwork Thu May 1 11:59:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 4098961 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C2211BFF02 for ; Thu, 1 May 2014 11:59:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B226C20303 for ; Thu, 1 May 2014 11:59:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37982202F8 for ; Thu, 1 May 2014 11:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754808AbaEAL7d (ORCPT ); Thu, 1 May 2014 07:59:33 -0400 Received: from sauhun.de ([89.238.76.85]:59251 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752102AbaEAL7d (ORCPT ); Thu, 1 May 2014 07:59:33 -0400 Received: from p4fe242c8.dip0.t-ipconnect.de ([79.226.66.200]:55595 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1WfpeA-0002b5-4t; Thu, 01 May 2014 13:59:26 +0200 From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , linux-sh@vger.kernel.org, Magnus Damm , Geert Uytterhoeven , Wolfram Sang Subject: [RFC] i2c: sh_mobile: WIP! Fix clock calculation for newer SoCs Date: Thu, 1 May 2014 13:59:14 +0200 Message-Id: <1398945555-12928-1-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 1.9.2 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wolfram Sang Newer SoCs have so fast input clocks that the ICCL/H registers only count every second clock to have a meaningful 9-bit range. The driver was already prepared for that happening, but didn't use it so far. This patch still needs some improvements, but already shows what I am aiming for. Signed-off-by: Wolfram Sang --- drivers/i2c/busses/i2c-sh_mobile.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c index ddc9970fd724..d399b9a355b6 100644 --- a/drivers/i2c/busses/i2c-sh_mobile.c +++ b/drivers/i2c/busses/i2c-sh_mobile.c @@ -32,6 +32,7 @@ #include #include #include +#include #include /* Transmit operation: */ @@ -611,6 +612,14 @@ static struct i2c_algorithm sh_mobile_i2c_algorithm = { .master_xfer = sh_mobile_i2c_xfer, }; +static const struct of_device_id sh_mobile_i2c_dt_ids[] = { + { .compatible = "renesas,rmobile-iic", .data = (void *)1 }, + { .compatible = "renesas,iic-r8a7790", .data = (void *)2 }, + { .compatible = "renesas,iic-r8a7791", .data = (void *)2 }, + {}, +}; +MODULE_DEVICE_TABLE(of, sh_mobile_i2c_dt_ids); + static int sh_mobile_i2c_hook_irqs(struct platform_device *dev) { struct resource *res; @@ -668,11 +677,18 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed); pd->bus_speed = ret ? STANDARD_MODE : bus_speed; - if (pdata && pdata->bus_speed) - pd->bus_speed = pdata->bus_speed; - pd->clks_per_count = 1; - if (pdata && pdata->clks_per_count) - pd->clks_per_count = pdata->clks_per_count; + if (dev->dev.of_node) { + const struct of_device_id *match; + + match = of_match_device(sh_mobile_i2c_dt_ids, &dev->dev); + pd->clks_per_count = match->data; + } else { + if (pdata && pdata->bus_speed) + pd->bus_speed = pdata->bus_speed; + pd->clks_per_count = 1; + if (pdata && pdata->clks_per_count) + pd->clks_per_count = pdata->clks_per_count; + } /* The IIC blocks on SH-Mobile ARM processors * come with two new bits in ICIC. @@ -750,12 +766,6 @@ static const struct dev_pm_ops sh_mobile_i2c_dev_pm_ops = { .runtime_resume = sh_mobile_i2c_runtime_nop, }; -static const struct of_device_id sh_mobile_i2c_dt_ids[] = { - { .compatible = "renesas,rmobile-iic", }, - {}, -}; -MODULE_DEVICE_TABLE(of, sh_mobile_i2c_dt_ids); - static struct platform_driver sh_mobile_i2c_driver = { .driver = { .name = "i2c-sh_mobile",