Received: by 10.192.165.148 with SMTP id m20csp3644737imm; Mon, 23 Apr 2018 09:53:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+eFt8BrwGQpstwcm8dslye7aL+IA1XSM1ocziKz3xGwXeBXMxsPreDqkRKVw9QAMq84T0C X-Received: by 10.101.96.150 with SMTP id t22mr17648167pgu.4.1524502439037; Mon, 23 Apr 2018 09:53:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524502439; cv=none; d=google.com; s=arc-20160816; b=J9LOUDrYRxU0bp9NgaKPQxIIJy8P9OFEL6erql+zBbFvPr7uxHJGNU36VO1JPvgsON 1AFmqqxX//7MUlDHZWpxIx9hWOaB8+varxJhVqt3p/o2IdvHIbi+SE9+i/bq2zJ4slik 3xgGNWhA27I6bJkli+r3k9WpwgYptDh98FFz8JU500kYcv4UMhHp7p668J31Cc886lYe qSGyNecMkrdKOneAzRZvNbTUFQbK5TahTBLhwpCRvfYPEhBaKM7C0Ylo+MbBZpfEo5bp NO8b0N5jEBOh0oWM6S2dwJx7yL2znShCF2XzRgRgzZi/pRA4LlU0jwtAb5bO9OUXkPzS nXTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter :arc-authentication-results; bh=Ac7SraYtEeMzP7iWE/5FtzMiSqEX9Jq95gq7Sf9OIkE=; b=TGRF3tB0x4WiXhwcSL1GaVXmqtlRut5Rg5GKrflZlssPXrftI2qU7moewN0TO4yuOq ehKZsT5WW9nmM3nJlCHara8R8X3GnoBxU59+UHOgTm1a4ECJCdeAlbcJ9WuARQ2yNgAh yb3hg5QP8v/yPimJbS3473Ml9o218VuUK/BkKUOlaYOgDPe/bkw74IgAtgNu3HARZzcn TALrWkyVJNzoxCKLOmCURDy28gZQGF01RdRfvOP4Z7twysycJ55hPsPJTPke1X5MpK05 OEqd0SyDrzq9ecH+Vqd1WXoKAz/Wc3PC1WK35XwEqq0802nJjTxG/qrZAMsYrjN//pM7 SGPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12-v6si12313030plm.83.2018.04.23.09.53.43; Mon, 23 Apr 2018 09:53:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755915AbeDWQwS (ORCPT + 99 others); Mon, 23 Apr 2018 12:52:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:39320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755817AbeDWQwP (ORCPT ); Mon, 23 Apr 2018 12:52:15 -0400 Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6078D217D2; Mon, 23 Apr 2018 16:52:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6078D217D2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=robh@kernel.org Received: by mail-qk0-f172.google.com with SMTP id j10so16812262qke.9; Mon, 23 Apr 2018 09:52:14 -0700 (PDT) X-Gm-Message-State: ALQs6tAZkULyhk7xa8XxmuzoA8RcT72Br5OpIlokdbmQHzPplQVwceO1 4/cXGu5quIl3n+gV2eEc/iyyV/0FH/Y42Pt78w== X-Received: by 10.55.31.132 with SMTP id n4mr22253838qkh.375.1524502333468; Mon, 23 Apr 2018 09:52:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.163.228 with HTTP; Mon, 23 Apr 2018 09:51:52 -0700 (PDT) In-Reply-To: <20180420214722.GA18510@minitux> References: <20180418222905.10414-1-robh@kernel.org> <20180420214722.GA18510@minitux> From: Rob Herring Date: Mon, 23 Apr 2018 11:51:52 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH] dt-bindings: add a jsonschema binding example To: Bjorn Andersson Cc: devicetree@vger.kernel.org, devicetree-spec@vger.kernel.org, "linux-kernel@vger.kernel.org" , Grant Likely , Frank Rowand , Mark Rutland , Geert Uytterhoeven , Linus Walleij , Thierry Reding , Mark Brown , Shawn Guo , Arnd Bergmann , Stephen Boyd , Jonathan Cameron Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 20, 2018 at 4:47 PM, Bjorn Andersson wrote: > On Wed 18 Apr 15:29 PDT 2018, Rob Herring wrote: > >> The current DT binding documentation format of freeform text is painful >> to write, review, validate and maintain. >> >> This is just an example of what a binding in the schema format looks >> like. It's using jsonschema vocabulary in a YAML encoded document. Using >> jsonschema gives us access to existing tooling. A YAML encoding gives us >> something easy to edit. >> >> This example is just the tip of the iceberg, but it the part most >> developers writing bindings will interact with. Backing all this up >> are meta-schema (to validate the binding schemas), some DT core schema, >> YAML encoded DT output with dtc, and a small number of python scripts to >> run validation. The gory details including how to run end-to-end >> validation can be found here: >> >> https://www.spinics.net/lists/devicetree-spec/msg00649.html >> >> Signed-off-by: Rob Herring >> --- >> Cc list, >> You all review and/or write lots of binding documents. I'd like some feedback >> on the format. >> > > I really like the idea of formalizing the binding document format and > the ability of validating a dtb is really nice. > >> Thanks, >> Rob >> >> .../devicetree/bindings/example-schema.yaml | 149 +++++++++++++++++++++ >> 1 file changed, 149 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/example-schema.yaml >> >> diff --git a/Documentation/devicetree/bindings/example-schema.yaml b/Documentation/devicetree/bindings/example-schema.yaml > [..] >> + reg: >> + # The description of each element defines the order and implicitly defines >> + # the number of reg entries >> + items: >> + - description: core registers >> + - description: aux registers >> + # minItems/maxItems equal to 2 is implied > > I assume that a reg with variable number of entries would have > "description" for all of them and then a minItems that matches the > required ones and maxItems matching all of them? You could do that, but it doesn't really enforce which compatible(s) each size of reg is valid for. It would work okay when just the last N entries are variable, but it will break down if you have cases where essentially any subset is valid. For bindings with lots of conditional sizes for reg, clocks, resets, etc. based on compatible strings, I think we will need to split the binding into a schema per compatible. IMO, things like this are probably not going to be addressed at the start and may remain in the description (as we have today). I think we need to start with a base schema and can improve them over time. >> + >> + reg-names: >> + # The core schema enforces this is a string array >> + items: >> + - const: core >> + - const: aux > > I presume validation based on this should check that there's equal > number of entries in reg-names as there where in reg. Should this > relationship be described in the schema? Yes, if we can figure out how. But I don't think it belongs in per device schema as it is a core requirement. > > [..] >> + interrupts: >> + # Either 1 or 2 interrupts can be present >> + minItems: 1 >> + maxItems: 2 >> + items: >> + - description: tx or combined interrupt >> + - description: rx interrupt >> + >> + description: | >> + A variable number of interrupts warrants a description of what conditions >> + affect the number of interrupts. Otherwise, descriptions on standard >> + properties are not necessary. > > For validation purposes this could be interrupts with interrupt-parents > or a interrupts-extend, a fact that we probably don't want to duplicate > in every definition? > > Perhaps we should just do like you did here and define the "interrupts" > and then in the validation tool - where we need to encode the logic > behind this anyways - we support the different variants. Yes, essentially as we do now where the binding just describes 'interrupts' and 'interrupts-extended' is implicitly supported. >> + >> + interrupt-names: >> + # minItems must be specified here because the default would be 2 >> + minItems: 1 > > As with reg-names, it would be good to have the validator warn if this > is not the same number of items as entries in "interrupts". > >> + items: >> + - const: "tx irq" >> + - const: "rx irq" >> + >> + # Property names starting with '#' must be quoted >> + '#interrupt-cells': >> + # A simple case where the value must always be '2'. >> + # The core schema handles that this must be a single integer. >> + const: 2 > > If this is specified then interrupt-controller should also be given, or > vise versa. How would we describe that? The core meta-schema can check that with 'dependencies'. Here's gpio meta-schema for example: dependencies: gpio-controller: ['#gpio-cells'] '#gpio-cells': [gpio-controller] gpio-ranges: [gpio-controller] ngpios: [gpio-controller] Rob