From patchwork Wed Aug 1 13:35:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 952185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=microchip.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41gZ7j3X1Fz9sBD for ; Wed, 1 Aug 2018 23:35:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389429AbeHAPVY (ORCPT ); Wed, 1 Aug 2018 11:21:24 -0400 Received: from esa5.microchip.iphmx.com ([216.71.150.166]:59737 "EHLO esa5.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389338AbeHAPVX (ORCPT ); Wed, 1 Aug 2018 11:21:23 -0400 X-IronPort-AV: E=Sophos;i="5.51,432,1526367600"; d="scan'208";a="15042264" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Aug 2018 06:35:35 -0700 Received: from localhost.localdomain.com (10.10.76.4) by chn-sv-exch02.mchp-main.com (10.10.76.38) with Microsoft SMTP Server id 14.3.352.0; Wed, 1 Aug 2018 06:35:33 -0700 From: Tudor Ambarus To: , , , , CC: , , , Tudor Ambarus Subject: [PATCH 1/2] i2c: enable buses to save their clock frequency in adapter Date: Wed, 1 Aug 2018 16:35:11 +0300 Message-ID: <20180801133512.12276-2-tudor.ambarus@microchip.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20180801133512.12276-1-tudor.ambarus@microchip.com> References: <20180801133512.12276-1-tudor.ambarus@microchip.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The clock-frequency property is not mandatory for the i2c buses. If it's not present in the device tree, the buses __usually__ assume it's 100kHZ (see altera, at91, axxia, etc.). Broadcom uses a 375kHZ default clock-frequency, so the default clock frequency varies from bus to bus. There are i2c clients that need to know the bus clock frequency in order to compute their wake token (see atecc508a i2c client). The clock-frequency value has to be propagated to the i2c clients, otherwise, if they will not find the i2c bus clock frequency in the device tree, they will have to make their own assumption of the clock frequency. Spare the i2c clients of making wrong assumptions of the i2c bus clock frequency and enable the buses to save their clock frequency in adapter. Signed-off-by: Tudor Ambarus --- include/linux/i2c.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index bc8d42f..fe65768 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -677,6 +677,7 @@ struct i2c_adapter { struct rt_mutex bus_lock; struct rt_mutex mux_lock; + u32 bus_freq_hz; int timeout; /* in jiffies */ int retries; struct device dev; /* the adapter device */ From patchwork Wed Aug 1 13:35:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 952184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=microchip.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41gZ7b6y43z9s5c for ; Wed, 1 Aug 2018 23:35:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389338AbeHAPV1 (ORCPT ); Wed, 1 Aug 2018 11:21:27 -0400 Received: from esa5.microchip.iphmx.com ([216.71.150.166]:59737 "EHLO esa5.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389272AbeHAPV0 (ORCPT ); Wed, 1 Aug 2018 11:21:26 -0400 X-IronPort-AV: E=Sophos;i="5.51,432,1526367600"; d="scan'208";a="15042267" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Aug 2018 06:35:37 -0700 Received: from localhost.localdomain.com (10.10.76.4) by chn-sv-exch02.mchp-main.com (10.10.76.38) with Microsoft SMTP Server id 14.3.352.0; Wed, 1 Aug 2018 06:35:36 -0700 From: Tudor Ambarus To: , , , , CC: , , , Tudor Ambarus Subject: [PATCH 2/2] i2c: at91: Save the bus clock frequency in adapter Date: Wed, 1 Aug 2018 16:35:12 +0300 Message-ID: <20180801133512.12276-3-tudor.ambarus@microchip.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20180801133512.12276-1-tudor.ambarus@microchip.com> References: <20180801133512.12276-1-tudor.ambarus@microchip.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The clock-frequency property is not mandatory for the i2c buses. If it's not present in the device tree, the buses __usually__ assume it's 100kHZ (see altera, at91, axxia, etc.). Broadcom uses a 375kHZ default clock-frequency, so the default clock frequency varies from bus to bus. There are i2c clients that need to know the bus clock frequency in order to compute their wake token (see atecc508a i2c client). The clock-frequency value has to be propagated to the i2c clients, otherwise, if they will not find the i2c bus clock frequency in the device tree, they will have to make their own assumption of the clock frequency. Spare the i2c clients of making wrong assumptions of the i2c bus clock frequency and provide the bus clock frequency in adapter. Signed-off-by: Tudor Ambarus Acked-by: Ludovic Desroches --- drivers/i2c/busses/i2c-at91.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index 3f3e8b3..9aa0937 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c @@ -1124,6 +1124,7 @@ static int at91_twi_probe(struct platform_device *pdev) dev->adapter.quirks = &at91_twi_quirks; dev->adapter.dev.parent = dev->dev; dev->adapter.nr = pdev->id; + dev->adapter.bus_freq_hz = bus_clk_rate; dev->adapter.timeout = AT91_I2C_TIMEOUT; dev->adapter.dev.of_node = pdev->dev.of_node;