From patchwork Wed Oct 26 14:57:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 9397425 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 6A90B60236 for ; Wed, 26 Oct 2016 15:01:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 473C829B0C for ; Wed, 26 Oct 2016 15:01:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3844A29BA2; Wed, 26 Oct 2016 15:01:07 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 092A729B0C for ; Wed, 26 Oct 2016 15:01:03 +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 1bzPfr-0005bh-Ts; Wed, 26 Oct 2016 14:59:27 +0000 Received: from up.free-electrons.com ([163.172.77.33] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bzPer-00051p-Dh for linux-arm-kernel@lists.infradead.org; Wed, 26 Oct 2016 14:58:32 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 61A6320C5E; Wed, 26 Oct 2016 16:58:00 +0200 (CEST) Received: from localhost (unknown [163.172.35.26]) by mail.free-electrons.com (Postfix) with ESMTPSA id 34F5120790; Wed, 26 Oct 2016 16:58:00 +0200 (CEST) From: Antoine Tenart To: maxime.ripard@free-electrons.com, pantelis.antoniou@konsulko.com, mark.rutland@arm.com, sboyd@codeaurora.org Subject: [RFC PATCH 2/5] of: overlay-mgr: add the CHIP format Date: Wed, 26 Oct 2016 16:57:53 +0200 Message-Id: <20161026145756.21689-3-antoine.tenart@free-electrons.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161026145756.21689-1-antoine.tenart@free-electrons.com> References: <20161026145756.21689-1-antoine.tenart@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161026_075825_892562_F6455B1F X-CRM114-Status: GOOD ( 17.35 ) 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: thomas.petazzoni@free-electrons.com, devicetree@vger.kernel.org, Antoine Tenart , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 Support parsing the header used by capes compatible with Nextthing's C.H.I.P. Signed-off-by: Antoine Tenart --- drivers/of/overlay-manager/Kconfig | 13 ++++++ drivers/of/overlay-manager/Makefile | 1 + drivers/of/overlay-manager/format-chip.c | 72 ++++++++++++++++++++++++++++++++ include/linux/overlay-manager.h | 13 ++++++ 4 files changed, 99 insertions(+) create mode 100644 drivers/of/overlay-manager/format-chip.c diff --git a/drivers/of/overlay-manager/Kconfig b/drivers/of/overlay-manager/Kconfig index eeb76054dcb8..1a36613c0c53 100644 --- a/drivers/of/overlay-manager/Kconfig +++ b/drivers/of/overlay-manager/Kconfig @@ -4,3 +4,16 @@ config OF_OVERLAY_MGR help Enable the overlay manager to handle automatic overlay loading when devices are detected. + +if OF_OVERLAY_MGR + +menu "Dips header formats" + +config OF_OVERLAY_MGR_FORMAT_CHIP + bool "Nextthing's C.H.I.P. dip header format" + help + Enable Nextthing's C.H.I.P. dip header format support. + +endmenu + +endif diff --git a/drivers/of/overlay-manager/Makefile b/drivers/of/overlay-manager/Makefile index 86d2b53950e7..637cc7ba20c2 100644 --- a/drivers/of/overlay-manager/Makefile +++ b/drivers/of/overlay-manager/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_OF_OVERLAY_MGR) += overlay-manager.o +obj-$(CONFIG_OF_OVERLAY_MGR_FORMAT_CHIP) += format-chip.o diff --git a/drivers/of/overlay-manager/format-chip.c b/drivers/of/overlay-manager/format-chip.c new file mode 100644 index 000000000000..3a3d315dcb5c --- /dev/null +++ b/drivers/of/overlay-manager/format-chip.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 - Antoine Tenart + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include + +#define CAPE_CHIP_MAGIC 0x43484950 +#define CAPE_CHIP_VERSION 1 +#define CAPE_CHIP_CANDIDATES 2 + +static int cape_chip_parse(struct device *dev, void *data, char ***candidates, + unsigned *n) +{ + struct chip_header *header = (struct chip_header *)data; + char **tmp; + int err; + + if (dip_convert(header->magic) != CAPE_CHIP_MAGIC) + return -EINVAL; + + if (dip_convert(header->version) > CAPE_CHIP_VERSION) + return -EINVAL; + + tmp = devm_kzalloc(dev, CAPE_CHIP_CANDIDATES * sizeof(char *), GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + tmp[0] = devm_kasprintf(dev, GFP_KERNEL, "%x-%x-%x", + dip_convert(header->vendor_id), + dip_convert(header->product_id), + dip_convert(header->product_version)); + if (!tmp[0]) { + err = -ENOMEM; + goto err_free_list; + } + + tmp[1] = devm_kasprintf(dev, GFP_KERNEL, "%x-%x", + dip_convert(header->vendor_id), + dip_convert(header->product_id)); + if (!tmp[1]) { + err = -ENOMEM; + goto err_free_0; + } + + *candidates = tmp; + *n = CAPE_CHIP_CANDIDATES; + + return 0; + +err_free_0: + devm_kfree(dev, tmp[0]); +err_free_list: + devm_kfree(dev, tmp); + return err; +} + +static struct overlay_mgr_format format_chip = { + .name = "Nextthing C.H.I.P. dip header format", + .parse = &cape_chip_parse, +}; + +static int __init cape_chip_init(void) +{ + return overlay_mgr_register_format(&format_chip); +} +device_initcall(cape_chip_init); diff --git a/include/linux/overlay-manager.h b/include/linux/overlay-manager.h index 8adcc4f5ddf6..d76c3c9fd863 100644 --- a/include/linux/overlay-manager.h +++ b/include/linux/overlay-manager.h @@ -35,4 +35,17 @@ int overlay_mgr_apply(struct device *dev, char **candidates, unsigned n); -1 \ ) +/* Nextthing's C.H.I.P. dip header */ +struct chip_header { + u32 magic; /* rsvd */ + u8 version; /* spec version */ + u32 vendor_id; + u16 product_id; + u8 product_version; + char vendor_name[32]; + char product_name[32]; + u8 rsvd[36]; /* rsvd for futre spec versions */ + u8 data[16]; /* user data, per-cape specific */ +} __packed; + #endif /* __OVERLAY_MGR_H__ */