From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2773BC4338F for ; Sat, 7 Aug 2021 13:26:48 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 72FB7610E7 for ; Sat, 7 Aug 2021 13:26:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 72FB7610E7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D10278326A; Sat, 7 Aug 2021 15:25:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="cFv4F2fm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71AF6831BF; Sat, 7 Aug 2021 15:24:56 +0200 (CEST) Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2E11A831D3 for ; Sat, 7 Aug 2021 15:24:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x230.google.com with SMTP id h11so1316892oie.0 for ; Sat, 07 Aug 2021 06:24:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c5t8YZxF0aD4N+71UmNbOB2xKyhbu9qj/72nRoe7rCo=; b=cFv4F2fmuqT9Q169QxYY8/JjRi1OmK8pA7Hr/d/gJVaLeyXxZpsEBNe70BJJ59Fb1B s0qBKUuhW246ZJDBeKn0auOxMoSP0MikWJNgi6MYG6KCl5bvCxmLoqxOHzxSqcJUoG42 XlMvp8LRY4BIey5IafHAh5EFtnhO3IYm7kZ9I= 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:mime-version:content-transfer-encoding; bh=c5t8YZxF0aD4N+71UmNbOB2xKyhbu9qj/72nRoe7rCo=; b=AiD3fODRHhgxGaa9jiSzTqp8AAZfvMNHekuRkzM7cIrDgdLoxAar0YnXHIxvfFLQ8h DKtEmbTqSeWB4YgfT/nBG3G2nroF9EJVM3LPBm8j7DtbS8Vsjx/CsLkE8dfkq7a/Nh7B 4CucZayXOB/EvB3LGDWP8bIVODufkUklhRXKQGeHMobN1ol585fDWbEzOs/Yti+ImRES k8cXvn/rHbZqxTDJ0C190CzLYQeBUqUQ9gMaDpdqGOyIYtg2HOdd5ixvhHdRW2dQLKWH P+5Gu8cHAGneNl6Ch0nrligQogRGM6wHuaTNx6TmMWWre/fN86KicSHVMO/UasrBVd6Y 8hvw== X-Gm-Message-State: AOAM5334AH9LOcfFtvvVxb/olHPOdRhXPoUbsWQvG9pbKwOiB0msOxpL ONIwWvXpUAeeRNVMA5Fs6CaMggUZjsE8ECIJ X-Google-Smtp-Source: ABdhPJylxXzKK7xB5e83mYEcS37UgovA0ukLMrvKKbtuRC0zv9Rwe8wbfC1iFfBsHv3nIKbxxFR0Rw== X-Received: by 2002:a05:6808:141:: with SMTP id h1mr8707296oie.59.1628342668628; Sat, 07 Aug 2021 06:24:28 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id x16sm1866417ooj.1.2021.08.07.06.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 06:24:28 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH 11/12] irq: Tidy up of-platdata irq support Date: Sat, 7 Aug 2021 07:24:11 -0600 Message-Id: <20210807132413.3513724-12-sjg@chromium.org> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog In-Reply-To: <20210807132413.3513724-1-sjg@chromium.org> References: <20210807132413.3513724-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This function is available but not exported. More generally it does not really work as intended. Reimplement it and add a sandbox test too. Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox.dtsi | 13 +++++++++++++ arch/sandbox/include/asm/irq.h | 20 ++++++++++++++++++++ drivers/misc/Makefile | 2 +- drivers/misc/irq-uclass.c | 10 ++++++++-- drivers/misc/irq_sandbox.c | 15 +++------------ drivers/misc/irq_sandbox_test.c | 22 ++++++++++++++++++++++ include/irq.h | 29 +++++++++++++++++++++++++++++ test/dm/of_platdata.c | 26 ++++++++++++++++++++++---- tools/dtoc/dtb_platdata.py | 1 + 9 files changed, 119 insertions(+), 19 deletions(-) create mode 100644 arch/sandbox/include/asm/irq.h create mode 100644 drivers/misc/irq_sandbox_test.c diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 200fcab6a41..819e81464af 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -123,6 +123,19 @@ #sound-dai-cells = <1>; }; + irq_sandbox: irq-sbox { + u-boot,dm-spl; + compatible = "sandbox,irq"; + interrupt-controller; + #interrupt-cells = <2>; + }; + + irq-test { + u-boot,dm-spl; + compatible = "sandbox,irq-test"; + interrupts-extended = <&irq_sandbox 3 0>; + }; + lcd { u-boot,dm-pre-proper; compatible = "sandbox,lcd-sdl"; diff --git a/arch/sandbox/include/asm/irq.h b/arch/sandbox/include/asm/irq.h new file mode 100644 index 00000000000..f73fec74f5c --- /dev/null +++ b/arch/sandbox/include/asm/irq.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2021 Google LLC + */ + +#ifndef __SANDBOX_IRQ_H +#define __SANDBOX_IRQ_H + +/** + * struct sandbox_irq_priv - private data for this driver + * + * @count: Counts the number calls to the read_and_clear() method + * @pending: true if an interrupt is pending, else false + */ +struct sandbox_irq_priv { + int count; + bool pending; +}; + +#endif /* __SANDBOX_IRQ_H */ diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 0c67d43a5d4..844a46f9311 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -42,7 +42,7 @@ obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o obj-$(CONFIG_IRQ) += irq-uclass.o -obj-$(CONFIG_SANDBOX) += irq_sandbox.o +obj-$(CONFIG_SANDBOX) += irq_sandbox.o irq_sandbox_test.o obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o obj-$(CONFIG_IMX8) += imx8/ diff --git a/drivers/misc/irq-uclass.c b/drivers/misc/irq-uclass.c index 3aa26f61d9e..eb9f3b902f4 100644 --- a/drivers/misc/irq-uclass.c +++ b/drivers/misc/irq-uclass.c @@ -64,8 +64,8 @@ int irq_read_and_clear(struct irq *irq) } #if CONFIG_IS_ENABLED(OF_PLATDATA) -int irq_get_by_driver_info(struct udevice *dev, - struct phandle_1_arg *cells, struct irq *irq) +int irq_get_by_phandle(struct udevice *dev, const struct phandle_2_arg *cells, + struct irq *irq) { int ret; @@ -74,6 +74,12 @@ int irq_get_by_driver_info(struct udevice *dev, return ret; irq->id = cells->arg[0]; + /* + * Note: we could call irq_of_xlate_default() here to do this properly. + * For now, this is good enough for existing cases. + */ + irq->flags = cells->arg[1]; + return 0; } #else diff --git a/drivers/misc/irq_sandbox.c b/drivers/misc/irq_sandbox.c index 1f7e62e6614..8b5573fcadd 100644 --- a/drivers/misc/irq_sandbox.c +++ b/drivers/misc/irq_sandbox.c @@ -9,19 +9,9 @@ #include #include #include +#include #include -/** - * struct sandbox_irq_priv - private data for this driver - * - * @count: Counts the number calls to the read_and_clear() method - * @pending: true if an interrupt is pending, else false - */ -struct sandbox_irq_priv { - int count; - bool pending; -}; - static int sandbox_set_polarity(struct udevice *dev, uint irq, bool active_low) { if (irq > 10) @@ -103,10 +93,11 @@ static const struct udevice_id sandbox_irq_ids[] = { { } }; -U_BOOT_DRIVER(sandbox_irq_drv) = { +U_BOOT_DRIVER(sandbox_irq) = { .name = "sandbox_irq", .id = UCLASS_IRQ, .of_match = sandbox_irq_ids, .ops = &sandbox_irq_ops, .priv_auto = sizeof(struct sandbox_irq_priv), + DM_HEADER() }; diff --git a/drivers/misc/irq_sandbox_test.c b/drivers/misc/irq_sandbox_test.c new file mode 100644 index 00000000000..95c45c24edb --- /dev/null +++ b/drivers/misc/irq_sandbox_test.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sandbox driver for testing interrupts with of-platdata + * + * Copyright 2021 Google LLC + */ + +#include +#include +#include +#include + +static const struct udevice_id sandbox_irq_test_ids[] = { + { .compatible = "sandbox,irq-test" }, + { } +}; + +U_BOOT_DRIVER(sandbox_irq_test) = { + .name = "sandbox_irq_test", + .id = UCLASS_MISC, + .of_match = sandbox_irq_test_ids, +}; diff --git a/include/irq.h b/include/irq.h index 8527e4dd797..a0965e44209 100644 --- a/include/irq.h +++ b/include/irq.h @@ -200,6 +200,35 @@ int irq_restore_polarities(struct udevice *dev); */ int irq_read_and_clear(struct irq *irq); +struct phandle_2_arg; +/** + * irq_get_by_phandle() - Get an irq by its phandle information (of-platadata) + * + * This function is used when of-platdata is enabled. + * + * This looks up an irq using the phandle info. With dtoc, each phandle in the + * 'interrupts-extended ' property is transformed into an idx representing the + * device. For example: + * + * interrupts-extended = <&acpi_gpe 0x3c 0>; + * + * might result in: + * + * .interrupts_extended = {6, {0x3c, 0}},}, + * + * indicating that the irq is udevice idx 6 in dt-plat.c with a arguments of + * 0x3c and 0.This function can return a valid irq given the above + * information. In this example it would return an irq containing the + * 'acpi_gpe' device and the irq ID 0x3c. + * + * @dev: Device containing the phandle + * @cells: Phandle info + * @irq: A pointer to a irq struct to initialise + * @return 0 if OK, or a negative error code + */ +int irq_get_by_phandle(struct udevice *dev, const struct phandle_2_arg *cells, + struct irq *irq); + /** * irq_get_by_index - Get/request an irq by integer index. * diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c index c4a2d114104..082989021d9 100644 --- a/test/dm/of_platdata.c +++ b/test/dm/of_platdata.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -28,11 +29,9 @@ static int dm_test_of_plat_props(struct unit_test_state *uts) struct udevice *dev; int i; - /* Skip the clock */ - ut_assertok(uclass_first_device_err(UCLASS_MISC, &dev)); - ut_asserteq_str("sandbox_clk_test", dev->name); + ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_spl_test", + &dev)); - ut_assertok(uclass_next_device_err(&dev)); plat = dev_get_plat(dev); ut_assert(plat->boolval); ut_asserteq(1, plat->intval); @@ -241,3 +240,22 @@ static int dm_test_of_plat_clk(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_of_plat_clk, UT_TESTF_SCAN_PDATA); + +/* Test irqs with of-platdata */ +static int dm_test_of_plat_irq(struct unit_test_state *uts) +{ + struct dtd_sandbox_irq_test *plat; + struct udevice *dev; + struct irq irq; + + ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "sandbox_irq_test", + &dev)); + plat = dev_get_plat(dev); + + ut_assertok(irq_get_by_phandle(dev, &plat->interrupts_extended[0], + &irq)); + ut_asserteq_str("sandbox_irq", irq.dev->name); + + return 0; +} +DM_TEST(dm_test_of_plat_irq, UT_TESTF_SCAN_PDATA); diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 869c92b49bf..3bb5c680f2e 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -62,6 +62,7 @@ VAL_PREFIX = 'dtv_' # a phandle property. PHANDLE_PROPS = { 'clocks': '#clock-cells', + 'interrupts-extended': '#interrupt-cells', 'gpios': '#gpio-cells', 'sandbox,emul': '#emul-cells', } -- 2.32.0.605.g8dce9f2422-goog