Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3788138pxv; Tue, 13 Jul 2021 03:52:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxDtBOyVZfJV2cNrfMZ9ar5K2DXcp8xFsjOEnD0YdT9GZiG8qdvrF6kcYkfhjGnu0pNyhK X-Received: by 2002:a17:906:615:: with SMTP id s21mr4874273ejb.218.1626173538942; Tue, 13 Jul 2021 03:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626173538; cv=none; d=google.com; s=arc-20160816; b=KjrzQnX79GzsJ1+OY0Lz5bBMqm744rtPGsgLgk2Rqjqi49p+6VQTk376xGAcXayrPX Cd3ewCzaWmqvuJRhdek6pYMZKKJML0GXupW6sDYBuJlkUPWtLXVxjc/d8IlN02nN7Tk2 4emLW9gXhmziUagR085a2myXM22yJQ5VRVg1G2fLm3SXzrNc31sOVfGs5hLZ1LqWqNCa 6muxU9LQuyZyg50/kdZaret4lkETYfa1F0gsyzkMMxYH3Tg2CdWUiCAWLHODnmoni9NZ 3MhQz3gYFFo44yBrzhH4X0CCfo0ZCGErV/pMwA0uzsL9aVrsw8XEEOGzdK5VYVK5ICEd hcHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=986/a+XL1T//36W39++oB7kOlKnW5eYSo8veeEHej88=; b=A7tpGu6ZqzII2maVa4Nb8R+HoOc+nhcqvmOuGS3p1jh+iGykVKwXIQksUghW0QqBpG t33eZD1i7734jKAV9E8rYo6smUFb+PIGUw//d53T1GwCTGteo17Bk5sObH35OAXr2vMP wY9LjsdbzhNihwRG97cx7ho0gO9XR113dstEyKyMa2fMoskgY+cndbxZ/Axhjr1kcfry dCQ2pZD6FE7YNor6w8mgcN+3SNGiNxjFqB735vwafSkoFkXn6qR8+lyECBag4EcZJHUG qPO+7jRDJ5Wi0JYY3slLwFP0l8UUXQ80qLGv41vx4w9bEliDJ1z151KYs4tcbqpykvi5 u6fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="A3Q/umcF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y19si20493225edi.515.2021.07.13.03.51.56; Tue, 13 Jul 2021 03:52:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="A3Q/umcF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235790AbhGMKxp (ORCPT + 99 others); Tue, 13 Jul 2021 06:53:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235716AbhGMKxn (ORCPT ); Tue, 13 Jul 2021 06:53:43 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B71CC0613E9 for ; Tue, 13 Jul 2021 03:50:53 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id n10so3720670plk.1 for ; Tue, 13 Jul 2021 03:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=986/a+XL1T//36W39++oB7kOlKnW5eYSo8veeEHej88=; b=A3Q/umcFWAyQTFsjWu0zZq7yNfzjuO2F03oZsK9+N4gsF+Yto7uv9o93Cw5O4pU30l pmnq3CcUhEL/8tHaQIa+H/J2XMafGoTkXXFgigVY7VlwFGYDdhNmVsHwifGLRFlY6aBF MhZjtulyDf+CNgTgvShltXI9F0SdCXh8U3XJrTebKTTnwD7KJkBiCo6+0X64QFfMWTCP mpx5FAYJl1zlDjBE91cO4IM6oEEZBzb7Oh9yI6PC8BwncgDUhYF+CuBM/obQfTg5AqOc 4JVUPbUiBB3xNewdVUjwYvLePcJIV3R0zNGOZDUrLFAn56bpGPhYm7ZQgbg+7xnbUY6v 9gcQ== 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=986/a+XL1T//36W39++oB7kOlKnW5eYSo8veeEHej88=; b=q15MVmmAs61IqmkIWPboSwxTQGwXOA7ygTwacXPjLziJQpgg1oJ+FAgpL6tHp7/DZR 3F5p25b8bHE0B+C+iXo0GfEOLpUvcrmM84FHV3oN4CaMsx9f2W+8ANtq6xSWXPduHICt Yf4/eB2Qh8304spiHXInkmjYB2zODAuuWhm/TGP+02PPBN/r2xZpUEx9GYhIpV5gUAgJ ZiO0XVvNUvREjYUqVP6XkQwEerpU6EXrcnwNyonxJ2OFpdwS+hjfIUASPisRiW8EZI5+ UlJVKdz9/7KOHRRq/2JtVqTEvKNbgq6ARU0o7iafgdKmdfHAtwVM1hnnItq2pjr9B6B1 HcQw== X-Gm-Message-State: AOAM531rB23asS6XGH3ZKkw1jV2QCHnsH/VjqPDsdLQz87xxVa2jpVao 17B09zqkE8eVsfC8ee5Fz8FeLQ== X-Received: by 2002:a17:90a:1549:: with SMTP id y9mr3808382pja.211.1626173452771; Tue, 13 Jul 2021 03:50:52 -0700 (PDT) Received: from localhost ([106.201.108.2]) by smtp.gmail.com with ESMTPSA id y15sm8993842pfn.63.2021.07.13.03.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 03:50:52 -0700 (PDT) From: Viresh Kumar To: Jason Wang , "Michael S. Tsirkin" , Rob Herring , Arnd Bergmann , Jean-Philippe Brucker Cc: Viresh Kumar , Vincent Guittot , Bill Mills , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Enrico Weigelt, metux IT consult" , Jie Deng , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 2/5] virtio_mmio: Bind virtio device to device-tree node Date: Tue, 13 Jul 2021 16:20:31 +0530 Message-Id: <26ba6941fa01eee88c99ecdd611d235c22bd6e3c.1626173013.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bind the virtio device with its device protocol's sub-node. This will help users of the virtio device to mention their dependencies on the device in the DT file itself. Like GPIO pin users can use the phandle of the device node, or the node may contain more subnodes to add i2c or spi eeproms and other users. Signed-off-by: Viresh Kumar --- drivers/virtio/virtio_mmio.c | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index 56128b9c46eb..ae40546a66a3 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -551,11 +551,51 @@ static void virtio_mmio_release_dev(struct device *_d) struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev); struct platform_device *pdev = vm_dev->pdev; + of_node_put(vdev->dev.of_node); devm_kfree(&pdev->dev, vm_dev); } /* Platform device */ +static int virtio_mmio_of_init(struct virtio_device *vdev) +{ + struct device_node *np, *pnode = vdev->dev.parent->of_node; + int ret, count; + u32 reg; + + if (!pnode) + return 0; + + count = of_get_available_child_count(pnode); + if (!count) + return 0; + + /* There can be only 1 child node */ + if (WARN_ON(count > 1)) + return -EINVAL; + + np = of_get_next_available_child(pnode, NULL); + if (WARN_ON(!np)) + return -ENODEV; + + ret = of_property_read_u32(np, "reg", ®); + if (ret < 0) + goto out; + + /* The reg field should match the device id */ + if (WARN_ON(reg != vdev->id.device)) { + ret = -EINVAL; + goto out; + } + + vdev->dev.of_node = np; + return 0; + +out: + of_node_put(np); + return ret; +} + static int virtio_mmio_probe(struct platform_device *pdev) { struct virtio_mmio_device *vm_dev; @@ -621,6 +661,10 @@ static int virtio_mmio_probe(struct platform_device *pdev) if (rc) dev_warn(&pdev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n"); + rc = virtio_mmio_of_init(&vm_dev->vdev); + if (rc) + return rc; + platform_set_drvdata(pdev, vm_dev); rc = register_virtio_device(&vm_dev->vdev); -- 2.31.1.272.g89b43f80a514