From patchwork Thu Apr 18 01:26:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 1087332 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44l1gG4DYPz9s3l for ; Thu, 18 Apr 2019 11:27:22 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tB9tNvVs"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 44l1gF4kB0zDqPl for ; Thu, 18 Apr 2019 11:27:21 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::444; helo=mail-pf1-x444.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tB9tNvVs"; dkim-atps=neutral Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44l1g51tCgzDqNr for ; Thu, 18 Apr 2019 11:27:13 +1000 (AEST) Received: by mail-pf1-x444.google.com with SMTP id e24so291998pfi.12 for ; Wed, 17 Apr 2019 18:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cxaSM0PBX2aH5fY6yvXvdhC1idzV4RRRFxOmTKyDtoQ=; b=tB9tNvVsE3/GpgT/5Vm7FWbwcsO9L2c/gVKVmKQ+xaIqRrK0jQ4WNPvGEvB1xfwTOB snO4Ctl0x56uVuvOGeMuMDC7yPRbZxMpQoRHKmRcT893PwvwQihmroyjTyg7dbJcgFeD 5/HoKrprHswwjYR7rhYKiM0WpumC/6q6XpdWo+1roG+ENNw8qotUJvUu2KZs0JzyEq0o OA4eUIt136S6xISkaAIcAMfnbjybtJQQJbl8yLWGynCgFhyuy//rCkUBL1EZ3v9toOVQ 08Uzr/e+Xng+x+CSzITgK8aQmpY0rV9VJxtBX14fnECnHrlGZwipsxsi3tmyzwniTrEV vxJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cxaSM0PBX2aH5fY6yvXvdhC1idzV4RRRFxOmTKyDtoQ=; b=NnFUpIMGyGfuOsYJmy7yUoh4wbfyLex3bLxC4UjGdCofAP8pEvNSbM0jnVKLDe6daY LN1LB2zUgwA8cDUSKBig8mPzeP1PMuxYFrAMGTR1ufIw+Wot5FEwFV0mymh6T7K83YzN QC6sM+lajmQ9hys14csoozRhw5NtQSvZrx6Sxex5xbWFvGH+gUz136bmiKnYkYk4kMhE HMiDIz6YvFmXByuIdv3HB0BkY8G7uFhrEUbPAQRFy3kt4ZXSPShLbsH5eTbpg+Uc1l/U nqOLIrQPe58/ZevHatwHYhvobSCpae/54zxMAHtV9kNRPwEoSmSPNAfKlvFbggthbst5 cl3A== X-Gm-Message-State: APjAAAWddQwPzVbVWkJV/Sp/P8ruYPC1d5la5k0IHnRNKsOHktd3rqO9 izCgAk3eemybyHhJ81Nl1SqLsB/e X-Google-Smtp-Source: APXvYqxMEupESSQVlYHb+9lqyQy8gXiZf4ampVUGU34lNUDM+OhbF/cl7fjd/BPx+nFPn0mux4zf5g== X-Received: by 2002:a63:1550:: with SMTP id 16mr150580pgv.132.1555550831265; Wed, 17 Apr 2019 18:27:11 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id j62sm610585pfg.6.2019.04.17.18.27.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 18:27:10 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org, alistair@popple.id.au, joel@jms.id.au Date: Thu, 18 Apr 2019 11:26:55 +1000 Message-Id: <20190418012658.23315-2-rashmica.g@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190418012658.23315-1-rashmica.g@gmail.com> References: <20190418012658.23315-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH v2 1/4] pdbg: Add in parser for uint8_t X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Rashmica Gupta --- src/parsers.c | 18 ++++++++++++++++++ src/parsers.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/parsers.c b/src/parsers.c index 8575784..4c03db9 100644 --- a/src/parsers.c +++ b/src/parsers.c @@ -56,6 +56,24 @@ uint16_t *parse_number16(const char *argv) return n; } +uint8_t *parse_number8(const char *argv) +{ + unsigned long long tmp; + uint8_t *n = malloc(sizeof(*n)); + char *endptr; + + if (!argv) + return NULL; + + errno = 0; + tmp = strtoul(argv, &endptr, 0); + if (errno || *endptr != '\0' || tmp > UINT8_MAX) + return NULL; + + *n = tmp; + return n; +} + /* Parse an 8-bit number that is a power of 2 */ uint8_t *parse_number8_pow2(const char *argv) { diff --git a/src/parsers.h b/src/parsers.h index ba52178..27ada1f 100644 --- a/src/parsers.h +++ b/src/parsers.h @@ -9,6 +9,7 @@ #define DATA (parse_number64, NULL) #define DATA32 (parse_number32, NULL) #define DATA16 (parse_number16, NULL) +#define DATA8 (parse_number8, NULL) #define DEFAULT_DATA(default) (parse_number64, default) #define GPR (parse_gpr, NULL) #define SPR (parse_spr, NULL) @@ -16,6 +17,7 @@ uint64_t *parse_number64(const char *argv); uint32_t *parse_number32(const char *argv); uint16_t *parse_number16(const char *argv); +uint8_t *parse_number8(const char *argv); uint8_t *parse_number8_pow2(const char *argv); int *parse_gpr(const char *argv); int *parse_spr(const char *argv); From patchwork Thu Apr 18 01:26:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 1087333 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44l1gL4fy4z9s5c for ; Thu, 18 Apr 2019 11:27:26 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rs4RrU1Z"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 44l1gL2fHpzDqPP for ; Thu, 18 Apr 2019 11:27:26 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::442; helo=mail-pf1-x442.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rs4RrU1Z"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44l1g773svzDqNr for ; Thu, 18 Apr 2019 11:27:15 +1000 (AEST) Received: by mail-pf1-x442.google.com with SMTP id 188so301400pfd.8 for ; Wed, 17 Apr 2019 18:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=r1Mis/529/LPI2wshbqr3cb+fYcixeKmh9R7UNqoQVo=; b=rs4RrU1ZTu86ppVMlyQY5Q8ZheAe9Fkps1sUAnhqh9MYiGfP6KYkIAI/JvGRiKeTwH ptchtwu1Q089UmkUeLdOr/wJUbjC8MC67a6foFHEv92DaG+B4uNrlhQ8akpQ0ieLkPhc H8oC5c/n7HW3+TdDGi/2goAw3qd4gaMjMETXZ0YpX2Epr7VEdD5jD+k/JQjCvloMENBA 7L7aah7cHuLtQGPXlYEO8Cg2cZ5osbcJ1Cdi8U+84tlN9O+5iwtlx055LeQLykwKCB13 IWB9Vxe4dSOWK2aryCozK0Eg3HMWUqH0EkPmR5LqGo/z4av2OKDXeLjku5Q2Gbf1XBy0 JGLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=r1Mis/529/LPI2wshbqr3cb+fYcixeKmh9R7UNqoQVo=; b=WuIWAWajhkkiQEuLbMwXHSQQvEcmNrP7w2qipTw8pJjFC88x+QVLJNtu/h7vNx0aXb 2T+thspnUiM9PIvsOsVhLEgFJ9rGzTD4sEJ1PmMRsRVZiNUAvW+plGLte4d0ocidohdm btVn/UmZoExxwehvThQrj2Yd3AsglRPJ6J4F5VU/FoECLvui4DneqaoVdqsJ8PhZvgYL xskJcW4/qSSxtVUehtCXlc7m2PM+DDgO9XFEKukoBBp7Gcek6ncSsJmnMA25zjs+W+Fg lBf10pm0OQ9Ca+3eAYXv/OH85M9DFwK383HpBBkiTAcsoTaiZ3ny7EFVj8ZPqCUdmeRf y5YQ== X-Gm-Message-State: APjAAAUjttZOIxRQ/wFwk0n+q0QaZBqGTRmEDDiQYK6T14lM00X9XqB/ 68j/YLFXBim7oqg+J4rdsQyD2utr X-Google-Smtp-Source: APXvYqzs6WjHTaZvcn2ZxEAHeCAECyQTE2pylKCCVFE556UXUaOBqTxUaFBINsPy2uIFdHO0Tnlf6Q== X-Received: by 2002:aa7:9ab1:: with SMTP id x17mr87363308pfi.4.1555550834070; Wed, 17 Apr 2019 18:27:14 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id j62sm610585pfg.6.2019.04.17.18.27.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 18:27:13 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org, alistair@popple.id.au, joel@jms.id.au Date: Thu, 18 Apr 2019 11:26:56 +1000 Message-Id: <20190418012658.23315-3-rashmica.g@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190418012658.23315-1-rashmica.g@gmail.com> References: <20190418012658.23315-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH v2 2/4] libpdbg: use i2ctools lib X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This should do the same thing as the i2ctools i2cget cmd. Signed-off-by: Rashmica Gupta --- Makefile.am | 6 ++++ configure.ac | 5 +++ libpdbg/i2cm.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ libpdbg/libpdbg.h | 3 ++ libpdbg/target.c | 11 +++++++ libpdbg/target.h | 9 +++++ p9-i2c.dts.m4 | 21 ++++++++++++ p9-kernel.dts.m4 | 8 +++++ src/i2c.c | 53 ++++++++++++++++++++++++++++++ src/main.c | 5 +-- 10 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 libpdbg/i2cm.c create mode 100644 p9-i2c.dts.m4 create mode 100644 src/i2c.c diff --git a/Makefile.am b/Makefile.am index d34cf20..1608fd4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -75,6 +75,7 @@ pdbg_SOURCES = \ src/cfam.c \ src/htm.c \ src/htm.h \ + src/i2c.c \ src/main.c \ src/main.h \ src/mem.c \ @@ -132,6 +133,10 @@ lib_LTLIBRARIES = libfdt.la libpdbg.la libfdt_la_CFLAGS = -I$(top_srcdir)/libfdt libpdbg_la_CFLAGS = -I$(top_srcdir)/libfdt -Wall -Werror +if I2CLIB +pdbg_LDADD += -li2c +libpdbg_la_CFLAGS += -DENABLE_I2CLIB +endif libfdt_la_SOURCES = \ libfdt/fdt_addresses.c \ @@ -164,6 +169,7 @@ libpdbg_la_SOURCES = \ libpdbg/host.c \ libpdbg/htm.c \ libpdbg/i2c.c \ + libpdbg/i2cm.c \ libpdbg/kernel.c \ libpdbg/libpdbg.c \ libpdbg/libpdbg.h \ diff --git a/configure.ac b/configure.ac index a52e1ed..ae661d5 100644 --- a/configure.ac +++ b/configure.ac @@ -42,4 +42,9 @@ want_gdbserver=false, want_gdbserver=true) AM_CONDITIONAL([GDBSERVER], [test x$want_gdbserver = xtrue]) +AC_ARG_ENABLE(i2clib, +AC_HELP_STRING([--enable-i2clib], [enables looking for the i2c lib]), +want_i2clib=true, +want_i2clib=false) +AM_CONDITIONAL([I2CLIB], [test x$want_i2clib = xtrue]) AC_OUTPUT diff --git a/libpdbg/i2cm.c b/libpdbg/i2cm.c new file mode 100644 index 0000000..3e0218d --- /dev/null +++ b/libpdbg/i2cm.c @@ -0,0 +1,83 @@ +/* Copyright 2019 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "operations.h" +#include "debug.h" + +#include +#include +#include + +#ifdef ENABLE_I2CLIB +#include + +static int kernel_i2c_get(struct i2cbus *i2cbus, uint8_t addr, uint16_t size, uint8_t *data) +{ + int res = 0; + //fix this is smbus not i2cget + + if (ioctl(i2cbus->i2c_fd, I2C_SLAVE, addr) < 0) + return -1; + + res = i2c_smbus_read_byte_data(i2cbus->i2c_fd, 0); + PR_DEBUG("read %x from device %x\n", res, addr); + if (res >= 0) { + *data = (uint64_t)res; + return 0; + } + return -1; +} + +static int i2cbus_probe(struct pdbg_target *target) +{ + int i2c_fd = 0; + int len; + char i2c_path[NAME_MAX]; + struct i2cbus *i2cbus; + + len = snprintf(i2c_path, NAME_MAX, "/dev/i2c-%i", target->index); + if (len >= NAME_MAX) + return -1; + i2c_fd = open(i2c_path, O_RDWR); + if (!i2c_fd) + return -1; + + i2cbus = target_to_i2cbus(target); + i2cbus->i2c_fd = i2c_fd; + return 0; +} + +static struct i2cbus i2c_bus = { + .target = { + .name = "I2C Bus", + .compatible = "ibm,power9-i2c-port", + .class = "i2c_bus", + .probe = i2cbus_probe, + }, + .read = kernel_i2c_get, +}; +DECLARE_HW_UNIT(i2c_bus); +#endif diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 4fad158..c09faa5 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -123,6 +123,9 @@ struct pdbg_target *pdbg_address_absolute(struct pdbg_target *target, uint64_t * int fsi_read(struct pdbg_target *target, uint32_t addr, uint32_t *val); int fsi_write(struct pdbg_target *target, uint32_t addr, uint32_t val); +int i2c_read(struct pdbg_target *target, uint8_t addr, uint16_t size, + uint8_t *data); + int pib_read(struct pdbg_target *target, uint64_t addr, uint64_t *val); int pib_write(struct pdbg_target *target, uint64_t addr, uint64_t val); int pib_wait(struct pdbg_target *pib_dt, uint64_t addr, uint64_t mask, uint64_t data); diff --git a/libpdbg/target.c b/libpdbg/target.c index e678470..2366ed9 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -195,6 +195,17 @@ int opb_write(struct pdbg_target *opb_dt, uint32_t addr, uint32_t data) return opb->write(opb, addr64, data); } +int i2c_read(struct pdbg_target *i2cm_dt, uint8_t addr, uint16_t size, uint8_t *data) +{ + struct i2cbus *i2cbus; + uint64_t addr64 = addr; + + i2cm_dt = get_class_target_addr(i2cm_dt, "i2c_bus", &addr64); + i2cbus = target_to_i2cbus(i2cm_dt); + + return i2cbus->read(i2cbus, addr, size, data); +} + int fsi_read(struct pdbg_target *fsi_dt, uint32_t addr, uint32_t *data) { struct fsi *fsi; diff --git a/libpdbg/target.h b/libpdbg/target.h index 04897ed..814e59a 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -138,6 +138,15 @@ struct fsi { }; #define target_to_fsi(x) container_of(x, struct fsi, target) +struct i2cbus { + struct pdbg_target target; + int (*read)(struct i2cbus *, uint8_t, uint16_t, uint8_t *); + int (*write)(struct i2cbus *, uint8_t, uint16_t, uint8_t*); + int i2c_fd; +}; +#define target_to_i2cbus(x) container_of(x, struct i2cbus, target) + + struct core { struct pdbg_target target; bool release_spwkup; diff --git a/p9-i2c.dts.m4 b/p9-i2c.dts.m4 new file mode 100644 index 0000000..d51dc83 --- /dev/null +++ b/p9-i2c.dts.m4 @@ -0,0 +1,21 @@ +define(`I2CBUS', `i2c_bus@$1 { +bus-frequency = <0x61a80>; +compatible = "ibm,opal-i2c", "ibm,power8-i2c-port", "ibm,power9-i2c-port"; +index = <$1>; +reg = <$1>; +}')dnl + +I2CBUS(0); +I2CBUS(1); +I2CBUS(2); +I2CBUS(3); +I2CBUS(4); +I2CBUS(5); +I2CBUS(6); +I2CBUS(7); +I2CBUS(8); +I2CBUS(9); +I2CBUS(10); +I2CBUS(11); +I2CBUS(12); +I2CBUS(13); diff --git a/p9-kernel.dts.m4 b/p9-kernel.dts.m4 index 195be59..cc07682 100644 --- a/p9-kernel.dts.m4 +++ b/p9-kernel.dts.m4 @@ -22,6 +22,14 @@ include(p9-pib.dts.m4)dnl }; + i2cm@1800 { + #address-cells = <0x1>; + #size-cells = <0x0>; + reg = <0x0 0x1800 0x400>; + compatible = "ibm,kernel-i2c-master"; + include(p9-i2c.dts.m4)dnl + }; + hmfsi@100000 { #address-cells = <0x2>; #size-cells = <0x1>; diff --git a/src/i2c.c b/src/i2c.c new file mode 100644 index 0000000..5d1fc5b --- /dev/null +++ b/src/i2c.c @@ -0,0 +1,53 @@ +/* Copyright 2019 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "main.h" +#include "optcmd.h" +#include "path.h" +#include "target.h" +#include "util.h" +#include "debug.h" + +static int geti2c(uint8_t addr, uint16_t size) +{ + uint8_t *data = NULL; + struct pdbg_target *target, *selected = NULL; + int rc = 0; + + data = malloc(size); + assert(data); + + for_each_path_target_class("i2c_bus", target) { + if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED) + continue; + selected = target; + rc = i2c_read(target, addr, size, data); + break; + } + if (selected == NULL) + return -1; + if (rc) { + PR_ERROR("Unable to read device.\n"); + return rc; + } + hexdump(0, data, size, 1); + return 0; +} +OPTCMD_DEFINE_CMD_WITH_ARGS(geti2c, geti2c, (DATA8, DATA16)); diff --git a/src/main.c b/src/main.c index d5f9385..3441d3c 100644 --- a/src/main.c +++ b/src/main.c @@ -93,7 +93,7 @@ extern struct optcmd_cmd optcmd_threadstatus, optcmd_sreset, optcmd_regs, optcmd_probe, optcmd_getmem, optcmd_putmem, optcmd_getmemio, optcmd_putmemio, optcmd_getxer, optcmd_putxer, optcmd_getcr, optcmd_putcr, - optcmd_gdbserver; + optcmd_gdbserver, optcmd_geti2c; static struct optcmd_cmd *cmds[] = { &optcmd_getscom, &optcmd_putscom, &optcmd_getcfam, &optcmd_putcfam, @@ -103,7 +103,7 @@ static struct optcmd_cmd *cmds[] = { &optcmd_threadstatus, &optcmd_sreset, &optcmd_regs, &optcmd_probe, &optcmd_getmem, &optcmd_putmem, &optcmd_getmemio, &optcmd_putmemio, &optcmd_getxer, &optcmd_putxer, &optcmd_getcr, &optcmd_putcr, - &optcmd_gdbserver, + &optcmd_gdbserver, &optcmd_geti2c, }; /* Purely for printing usage text. We could integrate printing argument and flag @@ -145,6 +145,7 @@ static struct action actions[] = { { "sreset", "", "Reset" }, { "regs", "[--backtrace]", "State (optionally display backtrace)" }, { "gdbserver", "", "Start a gdb server" }, + { "geti2c", " ", "Read n bytes from specified device" }, }; static void print_usage(void) From patchwork Thu Apr 18 01:26:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 1087334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44l1gN5fyxz9s9G for ; Thu, 18 Apr 2019 11:27:28 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="m3MyS0d0"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 44l1gN3XbZzDqPl for ; Thu, 18 Apr 2019 11:27:28 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::442; helo=mail-pf1-x442.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="m3MyS0d0"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44l1gC0dShzDqPC for ; Thu, 18 Apr 2019 11:27:18 +1000 (AEST) Received: by mail-pf1-x442.google.com with SMTP id b3so316104pfd.1 for ; Wed, 17 Apr 2019 18:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l6xnKi4cwBYVPcwKfCqi+wuSpS5fixQjiZvuquMQFVE=; b=m3MyS0d09OA2+CddHTH/x2eXntETuewRriR81TF2cKU7MNmVc6QdRg3+rTzNCCOXDI CLP1Rayjc3CuU9keLOsIPOB781734a2MMjTsVOH4r6faj6Inw6GhyDgSTsYh3N/XyHGk hMyTwaVpozCJyg9zk0ZGT6l3G/77TwBGKdC/tWwrTm1HGF3SSf4J861G4exOTXJr6FnX 7bi/v5NnhykJFqr+0NA+jL53OhKOUkeLIfZmHv+yY9Cfki0URhD20u8JDJgCckmsHVRh 8mh0gxuXsEPJLVYMpa/7rMtZizGQdtVQnXhpnqMQbS0FrAK+00H1wNilYjy/gQXPlmiS SmvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l6xnKi4cwBYVPcwKfCqi+wuSpS5fixQjiZvuquMQFVE=; b=MDdaRbel2iyCRBco9PWXcjeKeXM/ILgzH8tRs04DFvLbBI/8zK4cmfVwSwRSQRNOUI JNS8jYh3xzi9fCMa/5ANEue6lZKKlfAbTNTw1hgW6r9h8roJXYAOfeoFilSu/Zj1xZsW lsNzvdlKL6R+c7OX9L+CALOFbqPyH4a0Z9odSekyuxFVYfGybajHmH8aTYbZnqi2w6yE TjVBsVWZUMfHssmZd7IXp9iT22uW4SEFiy1sIIeuqEheQWxr/dPbiDAp3D/FA53tvIz3 3WTGGU54He9UmoMp18deNtuSVYtKc+mMJyXH30vLVegef/L2PcyB59WESu9ysEMhJ8gf DStA== X-Gm-Message-State: APjAAAULwrGpEjMGXIWk9tyWw/bms1qQkmsBPDztrk1Rq1MWik0AdWnH 7ZJmyEkF8DzXcpb8IOr8SDPKQECy X-Google-Smtp-Source: APXvYqz1meRLJwrkkrfVL14R0UV93fCkd/wzAgr9Lb7kL/3J8GsVD1K33JSoPi/u+BEo4W/82364mQ== X-Received: by 2002:a62:a219:: with SMTP id m25mr94396068pff.197.1555550836772; Wed, 17 Apr 2019 18:27:16 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id j62sm610585pfg.6.2019.04.17.18.27.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 18:27:16 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org, alistair@popple.id.au, joel@jms.id.au Date: Thu, 18 Apr 2019 11:26:57 +1000 Message-Id: <20190418012658.23315-4-rashmica.g@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190418012658.23315-1-rashmica.g@gmail.com> References: <20190418012658.23315-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH v2 3/4] libpdbg: Add i2c get and put functions for i2c master on CFAM X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This enables the two basic i2c functions from the BMC. Signed-off-by: Rashmica Gupta --- libpdbg/i2cm.c | 428 ++++++++++++++++++++++++++++++++++++++++++++++ libpdbg/libpdbg.h | 2 + libpdbg/target.c | 11 ++ libpdbg/target.h | 5 + p9-kernel.dts.m4 | 2 +- src/i2c.c | 26 +++ src/main.c | 5 +- 7 files changed, 476 insertions(+), 3 deletions(-) diff --git a/libpdbg/i2cm.c b/libpdbg/i2cm.c index 3e0218d..c260405 100644 --- a/libpdbg/i2cm.c +++ b/libpdbg/i2cm.c @@ -31,6 +31,434 @@ #include #include +/* I2C common registers */ +#define I2C_FIFO_REG 0x0 +#define I2C_CMD_REG 0x1 +#define I2C_MODE_REG 0x2 +#define I2C_WATERMARK_REG 0x3 +#define I2C_INT_MASK_REG 0x4 +#define I2C_INT_COND_REG 0x5 +#define I2C_STATUS_REG 0x7 +#define I2C_IMD_RESET_REG 0x7 +#define I2C_IMD_RESET_ERR_REG 0x8 +#define I2C_ESTAT_REG 0x8 +#define I2C_RESIDUAL_REG 0x9 +#define I2C_PORT_BUSY_REG 0xA + +#define I2C_PIB_OFFSET 0x4 +#define I2C_PIB_ENGINE_0 0x0000 +#define I2C_PIB_ENGINE_1 0x1000 +#define I2C_PIB_ENGINE_2 0x2000 +#define I2C_PIB_ENGINE_3 0x3000 + +/* I2C command register bits */ +#define I2C_CMD_WITH_START PPC_BIT32(0) +#define I2C_CMD_WITH_ADDR PPC_BIT32(1) +#define I2C_CMD_READ_CONTINUE PPC_BIT32(2) +#define I2C_CMD_WITH_STOP PPC_BIT32(3) +#define I2C_CMD_INT_STEER PPC_BITMASK32(6, 7) +#define I2C_CMD_DEV_ADDR PPC_BITMASK32(8, 14) +#define I2C_CMD_READ_NOT_WRITE PPC_BIT32(15) +#define I2C_CMD_LENGTH PPC_BITMASK32(16, 31) + +/* I2C mode register bits */ +#define I2C_MODE_BIT_RATE_DIV PPC_BITMASK32(0, 15) +#define I2C_MODE_PORT_NUM PPC_BITMASK32(16, 21) +#define I2C_ENHANCED_MODE PPC_BIT32(28) +#define I2C_MODE_PACING PPC_BIT32(30) + +/* watermark */ +#define I2C_WATERMARK_HIGH PPC_BITMASK32(16,19) +#define I2C_WATERMARK_LOW PPC_BITMASK32(24,27) + +/* I2C status register */ +#define I2C_STAT_INV_CMD PPC_BIT32(0) +#define I2C_STAT_PARITY PPC_BIT32(1) +#define I2C_STAT_BE_OVERRUN PPC_BIT32(2) +#define I2C_STAT_BE_ACCESS PPC_BIT32(3) +#define I2C_STAT_LOST_ARB PPC_BIT32(4) +#define I2C_STAT_NACK PPC_BIT32(5) +#define I2C_STAT_DAT_REQ PPC_BIT32(6) +#define I2C_STAT_CMD_COMP PPC_BIT32(7) +#define I2C_STAT_STOP_ERR PPC_BIT32(8) +#define I2C_STAT_MAX_PORT PPC_BITMASK32(9, 15) +#define I2C_STAT_ANY_INT PPC_BIT32(16) +#define I2C_STAT_WAIT_BUSY PPC_BIT32(17) +#define I2C_STAT_ERR_IN PPC_BIT32(18) +#define I2C_STAT_PORT_HIST_BUSY PPC_BIT32(19) +#define I2C_STAT_SCL_IN PPC_BIT32(20) +#define I2C_STAT_SDA_IN PPC_BIT32(21) +#define I2C_STAT_PORT_BUSY PPC_BIT32(22) +#define I2C_STAT_SELF_BUSY PPC_BIT32(23) +#define I2C_STAT_FIFO_COUNT PPC_BITMASK32(24, 31) + +#define I2C_STAT_ERR (I2C_STAT_INV_CMD | I2C_STAT_PARITY \ + | I2C_STAT_BE_OVERRUN | I2C_STAT_BE_ACCESS \ + | I2C_STAT_LOST_ARB | I2C_STAT_NACK \ + | I2C_STAT_STOP_ERR) + +/* I2C extended status register */ +#define I2C_ESTAT_FIFO_SIZE PPC_BITMASK32(0,7) +#define I2C_ESTAT_MSM_STATE PPC_BITMASK32(11,15) +#define I2C_ESTAT_HIGH_WATER PPC_BIT32(22) +#define I2C_ESTAT_LOW_WATER PPC_BIT32(23) + +/* I2C interrupt mask register */ +#define I2C_INT_INV_CMD PPC_BIT32(16) +#define I2C_INT_PARITY PPC_BIT32(17) +#define I2C_INT_BE_OVERRUN PPC_BIT32(18) +#define I2C_INT_BE_ACCESS PPC_BIT32(19) +#define I2C_INT_LOST_ARB PPC_BIT32(20) +#define I2C_INT_NACK PPC_BIT32(21) +#define I2C_INT_DAT_REQ PPC_BIT32(22) +#define I2C_INT_CMD_COMP PPC_BIT32(23) +#define I2C_INT_STOP_ERR PPC_BIT32(24) +#define I2C_INT_BUSY PPC_BIT32(25) +#define I2C_INT_IDLE PPC_BIT32(26) + +/* I2C residual register */ +#define I2C_RESID_FRONT PPC_BITMASK32(0,15) +#define I2C_RESID_BACK PPC_BITMASK32(16,31) + +static int _i2cm_reg_write(struct i2cm *i2cm, uint32_t addr, uint32_t data) +{ + CHECK_ERR(fsi_write(&i2cm->target, addr, data)); + return 0; +} + +static int _i2cm_reg_read(struct i2cm *i2cm, uint32_t addr, uint32_t *data) +{ + CHECK_ERR(fsi_read(&i2cm->target, addr, data)); + return 0; +} + +static void debug_print_reg(struct i2cm *i2cm) +{ + uint32_t fsidata = 0; + + PR_INFO("\t --------\n"); + _i2cm_reg_read(i2cm, I2C_STATUS_REG, &fsidata); + PR_INFO("\t status reg \t has value 0x%x \n", fsidata); + if (fsidata & I2C_STAT_INV_CMD) + PR_INFO("\t\tinvalid cmd\n"); + if (fsidata & I2C_STAT_PARITY) + PR_INFO("\t\tparity\n"); + if (fsidata & I2C_STAT_BE_OVERRUN) + PR_INFO("\t\tback endoverrun\n"); + if (fsidata & I2C_STAT_BE_ACCESS) + PR_INFO("\t\tback end access error\n"); + if (fsidata & I2C_STAT_LOST_ARB) + PR_INFO("\t\tarbitration lost\n"); + if (fsidata & I2C_STAT_NACK) + PR_INFO("\t\tnack\n"); + if (fsidata & I2C_STAT_DAT_REQ) + PR_INFO("\t\tdata request\n"); + if (fsidata & I2C_STAT_STOP_ERR) + PR_INFO("\t\tstop error\n"); + if (fsidata & I2C_STAT_PORT_BUSY) + PR_INFO("\t\ti2c busy\n"); + PR_INFO("\t\tfifo entry count: %li \n",fsidata&I2C_STAT_FIFO_COUNT); + + _i2cm_reg_read(i2cm, I2C_ESTAT_REG, &fsidata); + PR_INFO("\t extended status reg has value 0x%x \n", fsidata); + if (fsidata & I2C_ESTAT_HIGH_WATER) + PR_INFO("\t\thigh water mark reached\n"); + if (fsidata & I2C_ESTAT_LOW_WATER) + PR_INFO("\t\tlow water mark reached\n"); + + + _i2cm_reg_read(i2cm, I2C_WATERMARK_REG, &fsidata); + PR_INFO("\t watermark reg has value 0x%x \n", fsidata); + PR_INFO("\t\twatermark high: %li \n",fsidata&I2C_WATERMARK_HIGH); + PR_INFO("\t\twatermark low: %li \n",fsidata&I2C_WATERMARK_LOW); + + _i2cm_reg_read(i2cm, I2C_RESIDUAL_REG, &fsidata); + PR_INFO("\t residual reg has value 0x%x \n", fsidata); + PR_INFO("\t\tfrontend_len: %li \n",fsidata&I2C_RESID_FRONT); + PR_INFO("\t\tbackend_len: %li \n",fsidata&I2C_RESID_BACK); + + _i2cm_reg_read(i2cm, I2C_PORT_BUSY_REG, &fsidata); + PR_INFO("\t port busy reg has value 0x%x \n", fsidata); + PR_INFO("\t -------\n"); + +} + +static void i2c_mode_write(struct i2cm *i2cm, uint16_t port) +{ + uint32_t data = I2C_MODE_PACING; + + // hardcoding bit rate divisor because not too important + data = SETFIELD(I2C_MODE_BIT_RATE_DIV, data, 28); + data = SETFIELD(I2C_MODE_PORT_NUM, data, port); + PR_INFO("setting mode to %x\n", data); + _i2cm_reg_write(i2cm, I2C_MODE_REG, data); +} + +static void i2c_watermark_write(struct i2cm *i2cm) +{ + uint32_t data = 0; + + data = SETFIELD(I2C_WATERMARK_HIGH, data, 4); + data = SETFIELD(I2C_WATERMARK_LOW, data, 4); + PR_INFO("setting watermark (0x%x) to: %x\n", I2C_WATERMARK_REG, data); + _i2cm_reg_write(i2cm, I2C_WATERMARK_REG, data); +} + +static int i2c_reset(struct i2cm *i2cm) +{ + uint32_t fsidata = 0; + debug_print_reg(i2cm); + PR_INFO("### RESETING i2cm \n"); + + fsidata = 0xB; + _i2cm_reg_write(i2cm, I2C_IMD_RESET_REG, fsidata); + _i2cm_reg_write(i2cm, I2C_IMD_RESET_ERR_REG, fsidata); + + usleep(10000); + debug_print_reg(i2cm); + return 0; +} + +/* + * If there are errors in the status register, redo the whole + * operation after resetting the i2cm. +*/ +static int i2c_poll_status(struct i2cm *i2cm, uint32_t *data) +{ + int loop; + + for (loop = 0; loop < 10; loop++) + { + usleep(10000); + _i2cm_reg_read(i2cm, I2C_STATUS_REG, data); + + if (((*data) & I2C_STAT_CMD_COMP)) + break; + } + if ((*data) & I2C_STAT_PORT_BUSY) + PR_INFO("portbusy\n"); + if ((*data) & I2C_STAT_ERR) { + PR_INFO("ERROR IN STATUS\n"); + debug_print_reg(i2cm); + return 1; + } + return 0; +} + +static int i2c_fifo_write(struct i2cm *i2cm, uint32_t *data, uint16_t size) +{ + int bytes_in_fifo = 1; + int rc = 0, bytes_written = 0; + uint32_t status; + + while (bytes_written < size) { + + if (bytes_written == size) + return 0; + + /* Poll status register's FIFO_ENTRY_COUNT to check that FIFO isn't full */ + rc = i2c_poll_status(i2cm, &status); + bytes_in_fifo = status & I2C_STAT_FIFO_COUNT; + PR_INFO("%x bytes in fifo \n", bytes_in_fifo); + + if (rc) + return 0; + + if (bytes_in_fifo == 8) + continue; + + PR_INFO("\twriting: %x to FIFO\n", data[bytes_written / 4]); + rc = _i2cm_reg_write(i2cm, I2C_FIFO_REG, data[bytes_written / 4]); + if (rc) + return bytes_written; + bytes_written += 4; + } + return bytes_written; +} + +static int i2c_fifo_read(struct i2cm *i2cm, uint32_t *data, uint16_t size) +{ + int bytes_to_read = 1; + int rc = 0, bytes_read = 0; + uint32_t tmp; + uint32_t status; + + while (bytes_to_read) { + + if (bytes_read > size) + return 0; + + /* Poll status register's FIFO_ENTRY_COUNT to check that there is data to consume */ + rc = i2c_poll_status(i2cm, &status); + bytes_to_read = status & I2C_STAT_FIFO_COUNT; + PR_INFO("%x bytes in fifo \n", bytes_to_read); + + if (rc) + return 0; + + if (!bytes_to_read) + continue; + + rc = _i2cm_reg_read(i2cm, I2C_FIFO_REG, &tmp); + if (rc) + return bytes_read; + memcpy(data + (bytes_read / 4), &tmp, 4); + PR_INFO(" %x \n", data[bytes_read / 4]); + bytes_read += 4; + } + return bytes_read; +} + +static int i2cm_ok_to_use(struct i2cm *i2cm, uint16_t port) +{ + uint32_t data; + + _i2cm_reg_read(i2cm, I2C_STATUS_REG, &data); + + if (!(data & I2C_STAT_CMD_COMP) || (data & I2C_STAT_ERR)) + { + PR_INFO("Attempting to reset the i2cm %x \n", data); + i2c_reset(i2cm); + _i2cm_reg_read(i2cm, I2C_STATUS_REG, &data); + } + if (data & I2C_STAT_ERR) { + PR_ERROR("I2C master error: %x\n", data); + return 0; + } + i2c_watermark_write(i2cm); + i2c_mode_write(i2cm, port); + return 1; +} + +static int _i2c_put(struct i2cm *i2cm, uint16_t port, uint8_t addr, + uint16_t size, uint8_t *d) +{ + uint32_t fsidata; + uint32_t data = 0; + int rc = 0; + + if(!i2cm_ok_to_use(i2cm, port)) { + rc = 1; + return rc; + } + //TODO: if size > 64kB then use I2C_CMD_READ_CONTINUE and do multiple commands + if (size > 64*1024 -1) { + PR_ERROR("Can only support up to 64K bytes\n"); + return -1; + } + + /* Set slave device */ + fsidata = I2C_CMD_WITH_START | I2C_CMD_WITH_ADDR; + fsidata = SETFIELD(I2C_CMD_DEV_ADDR, fsidata, addr); + fsidata = SETFIELD(I2C_CMD_LENGTH, fsidata, size); + _i2cm_reg_write(i2cm, I2C_CMD_REG, fsidata); + + rc = i2c_poll_status(i2cm, &data); + if (rc) { + PR_ERROR("FAILED to set i2c device\n"); + return rc; + } + + /* Write data into the FIFO of the slave device */ + i2c_fifo_write(i2cm, (uint32_t *)d, size); + + rc = i2c_poll_status(i2cm, &data); + if (rc) { + PR_ERROR("FAILED to write all data\n"); + return rc; + } + return rc; +} + +static int _i2c_get(struct i2cm *i2cm, uint16_t port, uint8_t addr, + uint16_t size, uint8_t *d) +{ + uint32_t fsidata; + uint32_t data = 0; + int rc = 0; + int bytes_read; + + if(!i2cm_ok_to_use(i2cm, port)) { + rc = 1; + return rc; + } + + //TODO: if size > 64kB then use I2C_CMD_READ_CONTINUE and do multiple commands + if (size > 64*1024 -1) { + PR_ERROR("Can only support up to 64K bytes\n"); + return -1; + } + + /* Tell i2c master to read from slave device's fifo */ + fsidata = I2C_CMD_WITH_START | I2C_CMD_WITH_STOP | I2C_CMD_WITH_ADDR | I2C_CMD_READ_NOT_WRITE; + fsidata = SETFIELD(I2C_CMD_DEV_ADDR, fsidata, addr); + fsidata = SETFIELD(I2C_CMD_LENGTH, fsidata, size); + _i2cm_reg_write(i2cm, I2C_CMD_REG, fsidata); + + bytes_read = i2c_fifo_read(i2cm, (uint32_t*)d, size); + + rc = i2c_poll_status(i2cm, &data); + if (rc) { + PR_ERROR("Error occured while reading FIFO\n"); + return rc; + } + + if (bytes_read < size) { + PR_ERROR("Read %i bytes, expected to read %i bytes\n", bytes_read, size); + debug_print_reg(i2cm); + return -1; + } + + if (data & I2C_STAT_CMD_COMP) + rc = 0; + else + rc = -1; + return rc; +} + +static int i2c_get(struct i2cbus *i2cbus, uint8_t addr, uint16_t size, uint8_t *d) +{ + struct i2cm *i2cm = target_to_i2cm(i2cbus->target.parent); + return _i2c_get(i2cm, i2cbus->port, addr, size, d); +} + +static int i2c_put(struct i2cbus *i2cbus, uint8_t addr, uint16_t size, uint8_t *d) +{ + struct i2cm *i2cm = target_to_i2cm(i2cbus->target.parent); + return _i2c_put(i2cm, i2cbus->port, addr, size, d); +} + +static int i2cm_target_probe(struct pdbg_target *target) +{ + struct i2cbus *i2cbus = target_to_i2cbus(target); + i2cbus->port = target->index; + + return 0; +} + +static struct i2cbus i2c_bus_cfam = { + .target = { + .name = "CFAM I2C bus", + .compatible = "ibm,power9-i2c-port", + .class = "i2c_bus", + .probe = i2cm_target_probe, + }, + .read = i2c_get, + .write = i2c_put, +}; +DECLARE_HW_UNIT(i2c_bus_cfam); + +static struct i2cm i2cm_cfam = { + .target = { + .name = "CFAM I2C Master", + .compatible = "ibm,fsi-i2c-master", + .class = "i2cm", + } +}; +DECLARE_HW_UNIT(i2cm_cfam); + +///////////////////////////////////////////////////////////////////////////// + #ifdef ENABLE_I2CLIB #include diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index c09faa5..7e9b488 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -125,6 +125,8 @@ int fsi_write(struct pdbg_target *target, uint32_t addr, uint32_t val); int i2c_read(struct pdbg_target *target, uint8_t addr, uint16_t size, uint8_t *data); +int i2c_write(struct pdbg_target *target, uint8_t addr, uint16_t size, + uint8_t *data); int pib_read(struct pdbg_target *target, uint64_t addr, uint64_t *val); int pib_write(struct pdbg_target *target, uint64_t addr, uint64_t val); diff --git a/libpdbg/target.c b/libpdbg/target.c index 2366ed9..21efba9 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -206,6 +206,17 @@ int i2c_read(struct pdbg_target *i2cm_dt, uint8_t addr, uint16_t size, uint8_t * return i2cbus->read(i2cbus, addr, size, data); } +int i2c_write(struct pdbg_target *i2cm_dt, uint8_t addr, uint16_t size, uint8_t *data) +{ + struct i2cbus *i2cbus; + uint64_t addr64 = addr; + + i2cm_dt = get_class_target_addr(i2cm_dt, "i2c_bus", &addr64); + i2cbus = target_to_i2cbus(i2cm_dt); + + return i2cbus->write(i2cbus, addr, size, data); +} + int fsi_read(struct pdbg_target *fsi_dt, uint32_t addr, uint32_t *data) { struct fsi *fsi; diff --git a/libpdbg/target.h b/libpdbg/target.h index 814e59a..ca9f401 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -142,10 +142,15 @@ struct i2cbus { struct pdbg_target target; int (*read)(struct i2cbus *, uint8_t, uint16_t, uint8_t *); int (*write)(struct i2cbus *, uint8_t, uint16_t, uint8_t*); + uint8_t port; int i2c_fd; }; #define target_to_i2cbus(x) container_of(x, struct i2cbus, target) +struct i2cm { + struct pdbg_target target; +}; +#define target_to_i2cm(x) container_of(x, struct i2cm, target) struct core { struct pdbg_target target; diff --git a/p9-kernel.dts.m4 b/p9-kernel.dts.m4 index cc07682..9973b45 100644 --- a/p9-kernel.dts.m4 +++ b/p9-kernel.dts.m4 @@ -26,7 +26,7 @@ #address-cells = <0x1>; #size-cells = <0x0>; reg = <0x0 0x1800 0x400>; - compatible = "ibm,kernel-i2c-master"; + compatible = "ibm,fsi-i2c-master"; include(p9-i2c.dts.m4)dnl }; diff --git a/src/i2c.c b/src/i2c.c index 5d1fc5b..c3b88a5 100644 --- a/src/i2c.c +++ b/src/i2c.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "main.h" #include "optcmd.h" @@ -33,6 +35,7 @@ static int geti2c(uint8_t addr, uint16_t size) data = malloc(size); assert(data); + assert(!(size % 4)); for_each_path_target_class("i2c_bus", target) { if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED) @@ -51,3 +54,26 @@ static int geti2c(uint8_t addr, uint16_t size) return 0; } OPTCMD_DEFINE_CMD_WITH_ARGS(geti2c, geti2c, (DATA8, DATA16)); + +static int puti2c(uint8_t addr, uint16_t size, uint64_t data) +{ + uint8_t *d = (uint8_t *) &data; + struct pdbg_target *target, *selected = NULL; + + assert(!(size % 4)); + + for_each_path_target_class("i2c_bus", target) { + if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED) + continue; + selected = target; + if (i2c_write(target, addr, size, d) == 0) + break; + break; + } + + if (selected == NULL) + return -1; + printf("wrote %i bytes \n", size); + return 0; +} +OPTCMD_DEFINE_CMD_WITH_ARGS(puti2c, puti2c, (DATA8, DATA16, DATA)); diff --git a/src/main.c b/src/main.c index 3441d3c..7e03556 100644 --- a/src/main.c +++ b/src/main.c @@ -93,7 +93,7 @@ extern struct optcmd_cmd optcmd_threadstatus, optcmd_sreset, optcmd_regs, optcmd_probe, optcmd_getmem, optcmd_putmem, optcmd_getmemio, optcmd_putmemio, optcmd_getxer, optcmd_putxer, optcmd_getcr, optcmd_putcr, - optcmd_gdbserver, optcmd_geti2c; + optcmd_gdbserver, optcmd_geti2c, optcmd_puti2c; static struct optcmd_cmd *cmds[] = { &optcmd_getscom, &optcmd_putscom, &optcmd_getcfam, &optcmd_putcfam, @@ -103,7 +103,7 @@ static struct optcmd_cmd *cmds[] = { &optcmd_threadstatus, &optcmd_sreset, &optcmd_regs, &optcmd_probe, &optcmd_getmem, &optcmd_putmem, &optcmd_getmemio, &optcmd_putmemio, &optcmd_getxer, &optcmd_putxer, &optcmd_getcr, &optcmd_putcr, - &optcmd_gdbserver, &optcmd_geti2c, + &optcmd_gdbserver, &optcmd_geti2c, &optcmd_puti2c, }; /* Purely for printing usage text. We could integrate printing argument and flag @@ -146,6 +146,7 @@ static struct action actions[] = { { "regs", "[--backtrace]", "State (optionally display backtrace)" }, { "gdbserver", "", "Start a gdb server" }, { "geti2c", " ", "Read n bytes from specified device" }, + { "puti2c", " ", "Write n bytes to the specified device " }, }; static void print_usage(void) From patchwork Thu Apr 18 01:26:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 1087335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44l1gR1HJqz9s9h for ; Thu, 18 Apr 2019 11:27:31 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EeOngrEt"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 44l1gR05vKzDqPl for ; Thu, 18 Apr 2019 11:27:31 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EeOngrEt"; dkim-atps=neutral Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44l1gG0mZzzDqPQ for ; Thu, 18 Apr 2019 11:27:21 +1000 (AEST) Received: by mail-pl1-x644.google.com with SMTP id ck15so343468plb.3 for ; Wed, 17 Apr 2019 18:27:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1pEDHnG8a8Fi1Mx+OKNhSnEDqc+DqnZ7ohi0E8yyz+g=; b=EeOngrEt1urIUBFVp9RrtoQVGm6oOpSBC+gwhAbCdwgmuiHk7ShT4GlepKCoFlZVF+ 8whA97f692kuXW6rbdyPtDWcz5BAm3YTSz78cBpBcoKBd2D5lwt/e+e+AveiHYWov70O wsnzJqFgJ4XyD4KFAmYUzhGyuJ6jCb7FFC4EY7oeZ0bfEkmgQKfMKJF1oANYL3m47eD9 JyeweKaTACAxE4O6NxeCtP1EHvYvJD6YhJXNRs1dsgTUNGznM1S+3/wVTX7manYTOFVs fIP2X9GQnXeM3kADCYa7fk2Qw+bHlCsn49DjCUsrnQMP+CmEfNNDeYZdCWmFaxuVLqab Qu8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1pEDHnG8a8Fi1Mx+OKNhSnEDqc+DqnZ7ohi0E8yyz+g=; b=mIm3L6BFMDyth5R9GEoJ5/qu+ViUT7PiS2ZSq8aF6DJdw7xNE/aYUkreNI23NGV+Kb CIcyv39NS6QW9hE24oOHad3IpTJvT/oJtelExmk9tnhXufRghoXX136pmZJWMLJc1QIQ BhR1dkh7IkTXmL0fzhklcXaTzqMzJkk9tbfFMaOOqhThxn5OadHAUJenFuRHp3atjcxQ 8MOn3+XMASbCWFQXjDM7U1o1EgIm3Tsq25WHihtr+52vPyp0/R5kBnU8Ra6HU3sSphAq PdbqIgCY5YkY+28kecPp4QFzB4Q/3jOLcbYQJJGbNqX+8hlBN+aso74gXkgkX8FMPYfm zdAQ== X-Gm-Message-State: APjAAAV//R6Da6THJsEKFE9Vf6lMOp326GwfNSNisyW9LgANQMQRu+PI gvrEl9NSo8eb/BunJxuUWNCjGks5 X-Google-Smtp-Source: APXvYqy+zKb7e/FaJ7wOixic2cASeJEQqXHONVlBLJmOsP/MVJ8CUEgJiDRuvqIfGxXbjB43cScw7Q== X-Received: by 2002:a17:902:1101:: with SMTP id d1mr75716404pla.16.1555550839388; Wed, 17 Apr 2019 18:27:19 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id j62sm610585pfg.6.2019.04.17.18.27.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 18:27:18 -0700 (PDT) From: Rashmica Gupta To: pdbg@lists.ozlabs.org, alistair@popple.id.au, joel@jms.id.au Date: Thu, 18 Apr 2019 11:26:58 +1000 Message-Id: <20190418012658.23315-5-rashmica.g@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190418012658.23315-1-rashmica.g@gmail.com> References: <20190418012658.23315-1-rashmica.g@gmail.com> Subject: [Pdbg] [PATCH v2 4/4] libpdbg: Add i2c get and put for i2c masters on the PIB X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This enables the basic i2c functions from the host. Signed-off-by: Rashmica Gupta --- libpdbg/i2cm.c | 187 +++++++++++++++++++++++++++++++++++++++++++++-- libpdbg/target.h | 2 + p9-host.dts.m4 | 46 ++++++++++++ 3 files changed, 229 insertions(+), 6 deletions(-) diff --git a/libpdbg/i2cm.c b/libpdbg/i2cm.c index c260405..833f9d3 100644 --- a/libpdbg/i2cm.c +++ b/libpdbg/i2cm.c @@ -31,7 +31,11 @@ #include #include -/* I2C common registers */ +/* + * I2C common registers + * - use as is on CFAM + * - use with I2C_PIB_OFFSET on PIB + */ #define I2C_FIFO_REG 0x0 #define I2C_CMD_REG 0x1 #define I2C_MODE_REG 0x2 @@ -45,11 +49,13 @@ #define I2C_RESIDUAL_REG 0x9 #define I2C_PORT_BUSY_REG 0xA +/* I2C PIB only */ #define I2C_PIB_OFFSET 0x4 #define I2C_PIB_ENGINE_0 0x0000 #define I2C_PIB_ENGINE_1 0x1000 #define I2C_PIB_ENGINE_2 0x2000 #define I2C_PIB_ENGINE_3 0x3000 +#define I2C_PIB_FIFO4_REG 0x12 /* I2C command register bits */ #define I2C_CMD_WITH_START PPC_BIT32(0) @@ -122,13 +128,24 @@ static int _i2cm_reg_write(struct i2cm *i2cm, uint32_t addr, uint32_t data) { - CHECK_ERR(fsi_write(&i2cm->target, addr, data)); + if (i2cm->host) + /* pib addr space is 64 bits and i2cm only uses top 32 bits */ + CHECK_ERR(pib_write(&i2cm->target, addr + I2C_PIB_OFFSET, (uint64_t)data << 32)); + else + CHECK_ERR(fsi_write(&i2cm->target, addr, data)); return 0; } static int _i2cm_reg_read(struct i2cm *i2cm, uint32_t addr, uint32_t *data) { - CHECK_ERR(fsi_read(&i2cm->target, addr, data)); + uint64_t d = (uint64_t)*data; + + if (i2cm->host) { + CHECK_ERR(pib_read(&i2cm->target, addr + I2C_PIB_OFFSET, &d)); + *data = d >> 32; + } else { + CHECK_ERR(fsi_read(&i2cm->target, addr, data)); + } return 0; } @@ -268,7 +285,11 @@ static int i2c_fifo_write(struct i2cm *i2cm, uint32_t *data, uint16_t size) continue; PR_INFO("\twriting: %x to FIFO\n", data[bytes_written / 4]); - rc = _i2cm_reg_write(i2cm, I2C_FIFO_REG, data[bytes_written / 4]); + if (i2cm->host) + rc = _i2cm_reg_write(i2cm, I2C_PIB_FIFO4_REG - I2C_PIB_OFFSET, + data[bytes_written / 4]); + else + rc = _i2cm_reg_write(i2cm, I2C_FIFO_REG, data[bytes_written / 4]); if (rc) return bytes_written; bytes_written += 4; @@ -299,9 +320,14 @@ static int i2c_fifo_read(struct i2cm *i2cm, uint32_t *data, uint16_t size) if (!bytes_to_read) continue; - rc = _i2cm_reg_read(i2cm, I2C_FIFO_REG, &tmp); + if (i2cm->host) + rc = _i2cm_reg_read(i2cm, I2C_PIB_FIFO4_REG -I2C_PIB_OFFSET, &tmp); + else + rc = _i2cm_reg_read(i2cm, I2C_FIFO_REG, &tmp); + if (rc) return bytes_read; + memcpy(data + (bytes_read / 4), &tmp, 4); PR_INFO(" %x \n", data[bytes_read / 4]); bytes_read += 4; @@ -453,10 +479,159 @@ static struct i2cm i2cm_cfam = { .name = "CFAM I2C Master", .compatible = "ibm,fsi-i2c-master", .class = "i2cm", - } + }, + .host = false }; DECLARE_HW_UNIT(i2cm_cfam); + +///////////////////////////////////////////////////////////////////////////// +#define OCC_BASE 0x00000000006C08A +#define OCC_CLEAR 0x00000000006C08B +#define OCC_SET 0x00000000006C08C + + +#define OCC_LOCKED_ENGINE_1 PPC_BIT(17) +#define OCC_LOCKED_ENGINE_2 PPC_BIT(19) +#define OCC_LOCKED_ENGINE_3 PPC_BIT(21) +#define I2CM_DT_TO_ID(x) ((x>>12) & 0xf) +static int i2cm_locked_by_occ(int id, uint64_t occ_base) +{ + uint64_t mask; + switch (id) + { + case 1: + mask = OCC_LOCKED_ENGINE_1; + break; + case 2: + mask = OCC_LOCKED_ENGINE_2; + break; + case 3: + mask = OCC_LOCKED_ENGINE_3; + break; + default: + mask = 0; + break; + } + return !!(mask & occ_base); +} + +static int pib_i2c_get(struct i2cbus *i2cbus, uint8_t addr, uint16_t size, uint8_t *d) +{ + uint64_t data = 0; + uint64_t bit; + struct pdbg_target *p; + struct i2cm *i2cm = target_to_i2cm(i2cbus->target.parent); + + pdbg_for_each_class_target("pib", p) { + if (pdbg_target_probe(p) == PDBG_TARGET_ENABLED) + break; + } + + if (!p) { + fprintf(stderr, "No PIB found\n"); + return 0; + } + bit = PPC_BIT(16 + (i2cbus->id - 1) * 2); + pib_read(p, OCC_BASE, &data); + + if( !i2cm_locked_by_occ(i2cbus->id, data)) { + /* lock i2cm */ + pib_write(p, OCC_SET, bit); + pib_read(p, OCC_BASE, &data); + + _i2c_get(i2cm, i2cbus->port, addr, size, d); + + /* unlock i2cm */ + pib_read(p, OCC_BASE, &data); + pib_read(p, OCC_CLEAR, &data); + pib_write(p, OCC_CLEAR, bit); + pib_read(p, OCC_BASE, &data); + } else { + PR_INFO("I2C: de%d: occflags = 0x%16" PRIx64 "(locks = %x:%x:%x)\n", + i2cbus->id, (u64) data, (u16) GETFIELD(PPC_BITMASK(16, 17), data), + (u16) GETFIELD(PPC_BITMASK(18, 19), data), + (u16) GETFIELD(PPC_BITMASK(20, 21), data)); + PR_INFO("I2C master %x is locked by OCC :( \n", i2cbus->id); + } + + return 0; +} + +static int pib_i2c_put(struct i2cbus *i2cbus, uint8_t addr, uint16_t size, uint8_t *d) +{ + uint64_t data = 0; + uint64_t bit; + struct i2cm *i2cm = target_to_i2cm(i2cbus->target.parent); + struct pdbg_target *p; + + pdbg_for_each_class_target("pib", p) { + if (pdbg_target_probe(p) == PDBG_TARGET_ENABLED) + break; + } + + if (!p) { + fprintf(stderr, "No PIB found\n"); + return 0; + } + bit = PPC_BIT(16 + (i2cbus->id - 1) * 2); + pib_read(p, OCC_BASE, &data); + + if( !i2cm_locked_by_occ(i2cbus->id, data)) { + /* lock i2cm */ + pib_write(p, OCC_SET, bit); + pib_read(p, OCC_BASE, &data); + + _i2c_put(i2cm, i2cbus->port, addr, size, d); + + /* unlock i2cm */ + pib_read(p, OCC_BASE, &data); + pib_read(p, OCC_CLEAR, &data); + pib_write(p, OCC_CLEAR, bit); + pib_read(p, OCC_BASE, &data); + } else { + PR_INFO("I2C: de%d: occflags = 0x%16" PRIx64 "(locks = %x:%x:%x)\n", + i2cbus->id, (u64) data, (u16) GETFIELD(PPC_BITMASK(16, 17), data), + (u16) GETFIELD(PPC_BITMASK(18, 19), data), + (u16) GETFIELD(PPC_BITMASK(20, 21), data)); + PR_INFO("I2C master %x is locked by OCC :( \n", i2cbus->id); + } + return 0; +} + +int host_i2cm_target_probe(struct pdbg_target *target) +{ + int dt_id = pdbg_target_address(target, NULL); + int id = I2CM_DT_TO_ID(dt_id); + struct i2cbus *i2cbus = target_to_i2cbus(target); + + i2cbus->id = id; + i2cbus->port = target->index; + + return 0; +} + +static struct i2cbus i2c_bus_pib = { + .target = { + .name = "PIB I2C Bus", + .compatible = "ibm,power9-i2c-port", + .class = "i2c_bus", + .probe = i2cm_target_probe, + }, + .read = pib_i2c_get, + .write = pib_i2c_put, +}; +DECLARE_HW_UNIT(i2c_bus_pib); + +static struct i2cm i2c_pib = { + .target = { + .name = "PIB I2C Master", + .compatible = "ibm,power9-i2cm", + .class = "i2cm", + }, + .host = true, +}; +DECLARE_HW_UNIT(i2c_pib); ///////////////////////////////////////////////////////////////////////////// #ifdef ENABLE_I2CLIB diff --git a/libpdbg/target.h b/libpdbg/target.h index ca9f401..b864960 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -144,11 +144,13 @@ struct i2cbus { int (*write)(struct i2cbus *, uint8_t, uint16_t, uint8_t*); uint8_t port; int i2c_fd; + int id; }; #define target_to_i2cbus(x) container_of(x, struct i2cbus, target) struct i2cm { struct pdbg_target target; + bool host; }; #define target_to_i2cm(x) container_of(x, struct i2cm, target) diff --git a/p9-host.dts.m4 b/p9-host.dts.m4 index 52973ff..24c784f 100644 --- a/p9-host.dts.m4 +++ b/p9-host.dts.m4 @@ -12,6 +12,28 @@ reg = <0x0>; index = <0x0>; include(p9-pib.dts.m4)dnl + + i2cm@a1000 { + #address-cells = <0x1>; + #size-cells = <0x0>; + reg = <0x0 0xa1000 0x400>; + compatible = "ibm,power9-i2cm"; + include(p9-i2c.dts.m4)dnl + }; + i2cm@a2000 { + #address-cells = <0x1>; + #size-cells = <0x0>; + reg = <0x0 0xa2000 0x400>; + compatible = "ibm,power9-i2cm"; + include(p9-i2c.dts.m4)dnl + }; + i2cm@a3000 { + #address-cells = <0x1>; + #size-cells = <0x0>; + reg = <0x0 0xa3000 0x400>; + compatible = "ibm,power9-i2cm"; + include(p9-i2c.dts.m4)dnl + }; }; pib@8 { @@ -21,5 +43,29 @@ reg = <0x8>; index = <0x8>; include(p9-pib.dts.m4)dnl + + i2cm@a1000 { + #address-cells = <0x1>; + #size-cells = <0x0>; + reg = <0x0 0xa1000 0x400>; + compatible = "ibm,power9-i2cm"; + include(p9-i2c.dts.m4)dnl + }; + i2cm@a2000 { + #address-cells = <0x1>; + #size-cells = <0x0>; + reg = <0x0 0xa2000 0x400>; + compatible = "ibm,power9-i2cm"; + include(p9-i2c.dts.m4)dnl + }; + i2cm@a3000 { + #address-cells = <0x1>; + #size-cells = <0x0>; + reg = <0x0 0xa3000 0x400>; + compatible = "ibm,power9-i2cm"; + include(p9-i2c.dts.m4)dnl + }; + + }; };