From patchwork Wed Dec 7 00:14:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Bostic X-Patchwork-Id: 9463601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 44B2760459 for ; Wed, 7 Dec 2016 00:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35F9F284E9 for ; Wed, 7 Dec 2016 00:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ABF3284F3; Wed, 7 Dec 2016 00:20:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BCFE6284E9 for ; Wed, 7 Dec 2016 00:20:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cEPwC-0007M1-Tx; Wed, 07 Dec 2016 00:18:20 +0000 Received: from mail-oi0-x241.google.com ([2607:f8b0:4003:c06::241]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cEPtW-0005hS-Rl for linux-arm-kernel@lists.infradead.org; Wed, 07 Dec 2016 00:15:37 +0000 Received: by mail-oi0-x241.google.com with SMTP id f201so43591258oib.0 for ; Tue, 06 Dec 2016 16:15:17 -0800 (PST) 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=uBi1QcYA6aVpYrC0FvVTKjX8JK1irAaql4VpUd/uIzA=; b=xXc/Hv25O0CX53O3Sq7p1fK6wkKO7lRn9M4qFKYKwBm+DGKT95CvzjlL5MNlMw7LM0 LriUq7SB03QEyEh8oqs94M/vbFD+48s6EyjV+VdGgvxjSWfRMY9YJK8PWBwfQmpAXEEQ rzeqT9XeLTgK2LPpVSR87ZNDASVDzZWhmMFHzEAoatNz+TeVNEtThdwXqQsYnLWHex3y QE5BMHeXWy7+gG1QZEJX5A9CbOi9FnOCSdRtasXJ2MHtKSulzKWLRsAjvM9VDxt+rPLS uENeibAzxGwl+8MwBWghKkggNoGsqcuhZSgRbf0IxZXvXLx8Rhl80rw+AuyEErx0Ims3 Y3jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uBi1QcYA6aVpYrC0FvVTKjX8JK1irAaql4VpUd/uIzA=; b=XfsAABsU2EBxkpx/k5ZZC95x/mXZIyCw0xDH26Y4ZQPBBtkYDm9e9O8flQt4hLqpfA pUcY1pCAE92POi3cTM3UJ2fV8dINXzeNCpNLg/ptraL6xWQtiOlKeLLtqYWffcKkCWCe d3fAjwyfuU3ZsKLdpFN3+lU+mKF0e6nS9d/9k6R5Y9Ujy2MUR5yXm+leIvGzRDJoO6xT gbCOx+qv5lQ7Buf484MnVceHFfQlGWJgtYtYcj5N1zfTeQScVPYbhwkO/tDa4BIMHnGD kJiHeZBmRuP+ADSGbspExgIyIc3q5mlIr0ZExonWTQM+qE1QEgtsm9FvIKc6zYfFAZoS BqEQ== X-Gm-Message-State: AKaTC021P2b5FEj9oGFUt/O2vy5lwU+sHjSt+OywAVbWLvhxsHjfdQoEXXDFYCwYUXvGTQ== X-Received: by 10.157.33.122 with SMTP id l55mr33965927otd.61.1481069717445; Tue, 06 Dec 2016 16:15:17 -0800 (PST) Received: from Christophers-MacBook-Pro.local.com (45-20-192-79.lightspeed.austtx.sbcglobal.net. [45.20.192.79]) by smtp.gmail.com with ESMTPSA id r102sm8568294ota.11.2016.12.06.16.15.16 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 06 Dec 2016 16:15:16 -0800 (PST) From: Chris Bostic To: robh+dt@kernel.org, mark.rutland@arm.com, linux@armlinux.org.uk, gregkh@linuxfoundation.org, sre@kernel.org, mturquette@baylibre.com, geert+renesas@glider.be, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 10/16] drivers/fsi: scan slaves & register devices Date: Tue, 6 Dec 2016 18:14:31 -0600 Message-Id: <1481069677-53660-11-git-send-email-christopher.lee.bostic@gmail.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) In-Reply-To: <1481069677-53660-1-git-send-email-christopher.lee.bostic@gmail.com> References: <1481069677-53660-1-git-send-email-christopher.lee.bostic@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161206_161535_117040_7343237E X-CRM114-Status: GOOD ( 17.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: andrew@aj.id.au, alistair@popple.id.au, linux-kernel@vger.kernel.org, Chris Bostic , Jeremy Kerr , benh@kernel.crashing.org, joel@jms.id.au MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeremy Kerr Now that we have fsi_slave devices, scan each for endpoints, and register them on the fsi bus. Includes contributions from Chris Bostic Signed-off-by: Jeremy Kerr Signed-off-by: Chris Bostic --- drivers/fsi/fsi-core.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++-- include/linux/fsi.h | 4 ++ 2 files changed, 136 insertions(+), 4 deletions(-) diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c index aa4330a..b51ea35 100644 --- a/drivers/fsi/fsi-core.c +++ b/drivers/fsi/fsi-core.c @@ -21,9 +21,19 @@ #include "fsi-master.h" #define FSI_N_SLAVES 4 -#define FSI_SLAVE_CONF_CRC_SHIFT 4 -#define FSI_SLAVE_CONF_CRC_MASK 0x0000000f -#define FSI_SLAVE_CONF_DATA_BITS 28 + +#define FSI_SLAVE_CONF_NEXT_MASK 0x80000000 +#define FSI_SLAVE_CONF_SLOTS_MASK 0x00ff0000 +#define FSI_SLAVE_CONF_SLOTS_SHIFT 16 +#define FSI_SLAVE_CONF_VERSION_MASK 0x0000f000 +#define FSI_SLAVE_CONF_VERSION_SHIFT 12 +#define FSI_SLAVE_CONF_TYPE_MASK 0x00000ff0 +#define FSI_SLAVE_CONF_TYPE_SHIFT 4 +#define FSI_SLAVE_CONF_CRC_SHIFT 4 +#define FSI_SLAVE_CONF_CRC_MASK 0x0000000f +#define FSI_SLAVE_CONF_DATA_BITS 28 + +static const int engine_page_size = 0x400; static atomic_t master_idx = ATOMIC_INIT(-1); @@ -36,6 +46,30 @@ struct fsi_slave { #define to_fsi_slave(d) container_of(d, struct fsi_slave, dev) +/* FSI endpoint-device support */ + +static void fsi_device_release(struct device *_device) +{ + struct fsi_device *device = to_fsi_dev(_device); + + kfree(device); +} + +static struct fsi_device *fsi_create_device(struct fsi_slave *slave) +{ + struct fsi_device *dev; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return NULL; + + dev->dev.parent = &slave->dev; + dev->dev.bus = &fsi_bus_type; + dev->dev.release = fsi_device_release; + + return dev; +} + /* crc helpers */ static const uint8_t crc4_tab[] = { 0x0, 0x7, 0xe, 0x9, 0xb, 0xc, 0x5, 0x2, @@ -59,6 +93,99 @@ uint8_t fsi_crc4(uint8_t c, uint64_t x, int bits) /* FSI slave support */ +static int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, + void *val, size_t size) +{ + return slave->master->read(slave->master, slave->link, + slave->id, addr, val, size); +} + +static int fsi_slave_scan(struct fsi_slave *slave) +{ + uint32_t engine_addr; + uint32_t conf; + int rc, i; + + /* + * scan engines + * + * We keep the peek mode and slave engines for the core; so start + * at the third slot in the configuration table. We also need to + * skip the chip ID entry at the start of the address space. + */ + engine_addr = engine_page_size * 3; + for (i = 2; i < engine_page_size / sizeof(uint32_t); i++) { + uint8_t slots, version, type, crc; + struct fsi_device *dev; + + rc = fsi_slave_read(slave, (i + 1) * sizeof(conf), + &conf, sizeof(conf)); + if (rc) { + dev_warn(&slave->dev, + "error reading slave registers\n"); + return -1; + } + + crc = fsi_crc4(0, conf >> FSI_SLAVE_CONF_CRC_SHIFT, + FSI_SLAVE_CONF_DATA_BITS); + if (crc != (conf & FSI_SLAVE_CONF_CRC_MASK)) { + dev_warn(&slave->dev, + "crc error in slave register at 0x%04x\n", + i); + return -1; + } + + slots = (conf & FSI_SLAVE_CONF_SLOTS_MASK) + >> FSI_SLAVE_CONF_SLOTS_SHIFT; + version = (conf & FSI_SLAVE_CONF_VERSION_MASK) + >> FSI_SLAVE_CONF_VERSION_SHIFT; + type = (conf & FSI_SLAVE_CONF_TYPE_MASK) + >> FSI_SLAVE_CONF_TYPE_SHIFT; + + /* + * Unused address areas are marked by a zero type value; this + * skips the defined address areas + */ + if (type != 0) { + + /* create device */ + dev = fsi_create_device(slave); + if (!dev) + return -ENOMEM; + + dev->slave = slave; + dev->engine_type = type; + dev->version = version; + dev->unit = i; + dev->addr = engine_addr; + dev->size = slots * engine_page_size; + + dev_info(&slave->dev, + "engine[%i]: type %x, version %x, addr %x size %x\n", + dev->unit, dev->engine_type, version, + dev->addr, dev->size); + + device_initialize(&dev->dev); + dev_set_name(&dev->dev, "%02x:%02x:%02x:%02x", + slave->master->idx, slave->link, + slave->id, i - 2); + + rc = device_add(&dev->dev); + if (rc) { + dev_warn(&slave->dev, "add failed: %d\n", rc); + put_device(&dev->dev); + } + } + + engine_addr += slots * engine_page_size; + + if (!(conf & FSI_SLAVE_CONF_NEXT_MASK)) + break; + } + + return 0; +} + static void fsi_slave_release(struct device *dev) { struct fsi_slave *slave = to_fsi_slave(dev); @@ -110,7 +237,8 @@ static int fsi_slave_init(struct fsi_master *master, return rc; } - return rc; + fsi_slave_scan(slave); + return 0; } /* FSI master support */ diff --git a/include/linux/fsi.h b/include/linux/fsi.h index 273cbf6..efa55ba 100644 --- a/include/linux/fsi.h +++ b/include/linux/fsi.h @@ -21,6 +21,10 @@ struct fsi_device { struct device dev; u8 engine_type; u8 version; + u8 unit; + struct fsi_slave *slave; + uint32_t addr; + uint32_t size; }; struct fsi_device_id {