From patchwork Tue Sep 10 11:39:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 2865421 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2ABC69F2D6 for ; Tue, 10 Sep 2013 11:40:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5984220218 for ; Tue, 10 Sep 2013 11:40:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFA8E20365 for ; Tue, 10 Sep 2013 11:40:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751654Ab3IJLke (ORCPT ); Tue, 10 Sep 2013 07:40:34 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:51348 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751348Ab3IJLke (ORCPT ); Tue, 10 Sep 2013 07:40:34 -0400 Received: by mail-wi0-f177.google.com with SMTP id cb5so543717wib.16 for ; Tue, 10 Sep 2013 04:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Kc7FXcMIE3E0NZEtOnZYV2ojvImjAm+LWtpiqGKrnxM=; b=PK9qYkKUui95PH6Z3Xpivy6MeLv3nvEaAb/08LFF6PjxpfYjuGGKjgoz9u4co/m5/0 tly2ca7bUeQT8TSmcy2gg28jQdQLOBhWBJtAP8XYMv49+ey/0xulx6UL9z3FPdpZtmoh 00QZuqk2pdKnn4EyOXAjIHuUNENqOnjmUVvCPBWamxLRSQCL+qlRRwU0AZPDED4UiPdF C0gwQ4qHDV/VNUekHR83CBDr04sc/QQ/2MqFypbhd5GIWV85Kij6nRcFe5H6qSrijHE1 3ATNKJl9lat8ejNTR/2BuWjAHtrCImZGzMiItxIzAWH/oVXu7r8FVbwME4s/qulTDnob nudg== X-Received: by 10.194.24.168 with SMTP id v8mr17224060wjf.28.1378813233098; Tue, 10 Sep 2013 04:40:33 -0700 (PDT) Received: from groucho.site ([109.201.154.159]) by mx.google.com with ESMTPSA id b13sm2930036wic.9.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 04:40:32 -0700 (PDT) From: Ulrich Hecht To: linux-sh@vger.kernel.org, horms@verge.net.au, magnus.damm@gmail.com Cc: laurent.pinchart@ideasonboard.com, sergei.shtylyov@cogentembedded.com, Nguyen Viet Dung Subject: [PATCH 2/3] i2c: rcar: support R-Car H2 in i2c bus driver Date: Tue, 10 Sep 2013 13:39:53 +0200 Message-Id: <1378813194-19493-3-git-send-email-ulrich.hecht@gmail.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1378813194-19493-1-git-send-email-ulrich.hecht@gmail.com> References: <1378813194-19493-1-git-send-email-ulrich.hecht@gmail.com> 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.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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: Nguyen Viet Dung This patch modifies the I2C bus driver to be usable on both R-Car H1 and H2. Signed-off-by: Nguyen Viet Dung --- drivers/i2c/busses/i2c-rcar.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 0fc5858..883897f 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -101,6 +101,11 @@ enum { #define ID_ARBLOST (1 << 3) #define ID_NACK (1 << 4) +enum rcar_i2c_type { + I2C_RCAR_H1, + I2C_RCAR_H2, +}; + struct rcar_i2c_priv { void __iomem *io; struct i2c_adapter adap; @@ -113,6 +118,7 @@ struct rcar_i2c_priv { int irq; u32 icccr; u32 flags; + enum rcar_i2c_type devtype; }; #define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent) @@ -224,12 +230,25 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, u32 scgd, cdf; u32 round, ick; u32 scl; + u32 cdf_width; if (!clkp) { dev_err(dev, "there is no peripheral_clk\n"); return -EIO; } + switch (priv->devtype) { + case I2C_RCAR_H1: + cdf_width = 2; + break; + case I2C_RCAR_H2: + cdf_width = 3; + break; + default: + dev_err(dev, "device type error\n"); + return -EIO; + } + /* * calculate SCL clock * see @@ -245,7 +264,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, * clkp : peripheral_clk * F[] : integer up-valuation */ - for (cdf = 0; cdf < 4; cdf++) { + for (cdf = 0; cdf < (1 << cdf_width); cdf++) { ick = clk_get_rate(clkp) / (1 + cdf); if (ick < 20000000) goto ick_find; @@ -287,7 +306,7 @@ scgd_find: /* * keep icccr value */ - priv->icccr = (scgd << 2 | cdf); + priv->icccr = (scgd << cdf_width) | cdf; return 0; } @@ -632,6 +651,9 @@ static int rcar_i2c_probe(struct platform_device *pdev) bus_speed = 100000; /* default 100 kHz */ if (pdata && pdata->bus_speed) bus_speed = pdata->bus_speed; + + priv->devtype = platform_get_device_id(pdev)->driver_data; + ret = rcar_i2c_clock_calculate(priv, bus_speed, dev); if (ret < 0) return ret; @@ -686,6 +708,14 @@ static int rcar_i2c_remove(struct platform_device *pdev) return 0; } +static struct platform_device_id rcar_i2c_id_table[] = { + { "i2c-rcar", I2C_RCAR_H1 }, + { "i2c-rcar_h1", I2C_RCAR_H1 }, + { "i2c-rcar_h2", I2C_RCAR_H2 }, + {}, +}; +MODULE_DEVICE_TABLE(platform, rcar_i2c_id_table); + static struct platform_driver rcar_i2c_driver = { .driver = { .name = "i2c-rcar", @@ -693,6 +723,7 @@ static struct platform_driver rcar_i2c_driver = { }, .probe = rcar_i2c_probe, .remove = rcar_i2c_remove, + .id_table = rcar_i2c_id_table, }; module_platform_driver(rcar_i2c_driver);