From patchwork Mon Apr 24 04:45:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 754092 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wBDMD1sjZz9s8T for ; Mon, 24 Apr 2017 14:46:32 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wBDMD05lXzDqGx for ; Mon, 24 Apr 2017 14:46:32 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wBDLz13wpzDq5W for ; Mon, 24 Apr 2017 14:46:18 +1000 (AEST) Received: from pasglop.ozlabs.ibm.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id v3O4jqAL018334; Sun, 23 Apr 2017 23:45:54 -0500 From: Benjamin Herrenschmidt To: skiboot@lists.ozlabs.org Date: Mon, 24 Apr 2017 14:45:40 +1000 Message-Id: <20170424044544.23810-1-benh@kernel.crashing.org> X-Mailer: git-send-email 2.9.3 Subject: [Skiboot] [PATCH 1/5] hdata/i2c: Fix bus and clock frequencies X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The clock-frequency of the i2c master should be derived from the xscom bus frequency (itself derived from the nest frequency). The bus-frequency of the i2c bus should be in Hz so convert the HDAT value from kHz to Hz. Signed-off-by: Benjamin Herrenschmidt Reviewed-by: Oliver O'Halloran --- hdata/i2c.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hdata/i2c.c b/hdata/i2c.c index 5a74a7f..24e9257 100644 --- a/hdata/i2c.c +++ b/hdata/i2c.c @@ -31,6 +31,7 @@ static struct dt_node *get_i2cm_node(struct dt_node *xscom, int engine) { uint64_t xscom_base = P9_I2CM_XSCOM_BASE + P9_I2CM_XSCOM_SIZE * engine; struct dt_node *i2cm; + uint64_t freq, clock; i2cm = dt_find_by_name_addr(xscom, "i2cm", xscom_base); if (!i2cm) { @@ -45,8 +46,12 @@ static struct dt_node *get_i2cm_node(struct dt_node *xscom, int engine) dt_add_property_cells(i2cm, "#address-cells", 1); dt_add_property_cells(i2cm, "chip-engine#", engine); - /* XXX: verify this */ - dt_add_property_cells(i2cm, "clock-frequency", 150000000); + freq = dt_prop_get_u64_def(xscom, "bus-frequency", 0); + clock = (u32)(freq / 4); + if (clock) + dt_add_property_cells(i2cm, "clock-frequency", clock); + else + dt_add_property_cells(i2cm, "clock-frequency", 150000000); } return i2cm; @@ -73,7 +78,7 @@ static struct dt_node *get_bus_node(struct dt_node *i2cm, int port, int freq) * reduce the frequency to something that all devices * can tolerate. */ - dt_add_property_cells(bus, "bus-frequency", freq); + dt_add_property_cells(bus, "bus-frequency", freq * 1000); } return bus;