From patchwork Tue Mar 11 04:25:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Roszko X-Patchwork-Id: 3808661 Return-Path: X-Original-To: patchwork-linux-arm@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 A6140BF540 for ; Tue, 11 Mar 2014 04:31:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B8097202F0 for ; Tue, 11 Mar 2014 04:31:58 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B73F8202A1 for ; Tue, 11 Mar 2014 04:31:57 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WNEM0-0005xN-8a; Tue, 11 Mar 2014 04:31:48 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WNELx-0007UC-Nz; Tue, 11 Mar 2014 04:31:45 +0000 Received: from mail-qa0-f42.google.com ([209.85.216.42]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WNELu-0007TY-JD for linux-arm-kernel@lists.infradead.org; Tue, 11 Mar 2014 04:31:43 +0000 Received: by mail-qa0-f42.google.com with SMTP id k15so8093558qaq.1 for ; Mon, 10 Mar 2014 21:31:16 -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; bh=HCVOFsKTJtRXlGN4lMSVHPHDC6IC9kTWw2zVXNWGNNk=; b=miXnd34Dyvc5i4rn9tgQwxpZJ49eO2QDircFXde3Z8WbU7LT/of1rv8mOn9ZYOrlFL t3hP1bYf6kCHQK5HDafLO5FInwrnhF9Sgsj7cdlcaH6sPIMbSTAAeJW8Fjsryg5cjJiE X9e0L+LEHFYYWQ8jHr6I+UobChcFazhFybg+O2QUULNRIfoVKtTKbVCdem/2OqQY7nDJ RGuf31NX1w7+sKyBNUX7ErDMkn2kr+ZBz+ufUKbu6cdiNbbCvaPwKvd3DxTriK9Wq6a2 ZPtwHh13tVghPYxCq7ZwABn1h+H1AfWpZdpbkoLlbwxhQke9AcfNG6XduhMz7e/Qhiof bP2A== X-Received: by 10.140.85.230 with SMTP id n93mr42587881qgd.26.1394512276744; Mon, 10 Mar 2014 21:31:16 -0700 (PDT) Received: from localhost.localdomain (ool-18e4a8f6.dyn.optonline.net. [24.228.168.246]) by mx.google.com with ESMTPSA id 110sm29895802qgv.19.2014.03.10.21.31.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Mar 2014 21:31:15 -0700 (PDT) From: Marek Roszko To: wsa@the-dreams.de, ludovic.desroches@atmel.com Subject: [PATCH v3] i2c:at91: Add device tree property to set clock-frequency Date: Tue, 11 Mar 2014 00:25:38 -0400 Message-Id: <1394511938-28653-1-git-send-email-mark.roszko@gmail.com> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140311_003142_690464_5C229EFE X-CRM114-Status: GOOD ( 13.76 ) X-Spam-Score: -2.7 (--) Cc: Marek Roszko , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_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 This adds the ability to set "clock-frequency" in the device tree for the at91 i2cbus following the naming of other i2c bus implementations. If the property is not set,the clock frequency will default to the previously used define of 100KHz. Signed-off-by: Marek Roszko --- v3: -changed bus_clk_rate to u32 v2: -fixed return code usage and check to not compare agaisnt less than zero --- Documentation/devicetree/bindings/i2c/i2c-at91.txt | 2 ++ drivers/i2c/busses/i2c-at91.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/i2c/i2c-at91.txt b/Documentation/devicetree/bindings/i2c/i2c-at91.txt index 4fade84..388f0a2 100644 --- a/Documentation/devicetree/bindings/i2c/i2c-at91.txt +++ b/Documentation/devicetree/bindings/i2c/i2c-at91.txt @@ -12,6 +12,7 @@ Required properties : - clocks: phandles to input clocks. Optional properties: +- clock-frequency: Desired I2C bus frequency in Hz, otherwise defaults to 100000 - Child nodes conforming to i2c bus binding Examples : @@ -23,6 +24,7 @@ i2c0: i2c@fff84000 { #address-cells = <1>; #size-cells = <0>; clocks = <&twi0_clk>; + clock-frequency = <400000>; 24c512@50 { compatible = "24c512"; diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index 843d012..334c851 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c @@ -32,7 +32,7 @@ #include #include -#define TWI_CLK_HZ 100000 /* max 400 Kbits/s */ +#define DEFAULT_TWI_CLK_HZ 100000 /* max 400 Kbits/s */ #define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */ #define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */ @@ -711,6 +711,7 @@ static int at91_twi_probe(struct platform_device *pdev) struct resource *mem; int rc; u32 phy_addr; + u32 bus_clk_rate; dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) @@ -756,7 +757,12 @@ static int at91_twi_probe(struct platform_device *pdev) dev->use_dma = true; } - at91_calc_twi_clock(dev, TWI_CLK_HZ); + rc = of_property_read_u32(dev->dev->of_node, "clock-frequency", + &bus_clk_rate); + if (rc) + bus_clk_rate = DEFAULT_TWI_CLK_HZ; + + at91_calc_twi_clock(dev, bus_clk_rate); at91_init_twi_bus(dev); snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91");