Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3104338ybl; Fri, 20 Dec 2019 04:03:34 -0800 (PST) X-Google-Smtp-Source: APXvYqwqgh3b7YqutTKX+DKfzkWZNt49gUPWGogbhxy+WNQywmF5GGFGpQo1EqMTsPDBWCtKRaA3 X-Received: by 2002:a05:6830:139a:: with SMTP id d26mr14902717otq.75.1576843414378; Fri, 20 Dec 2019 04:03:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576843414; cv=none; d=google.com; s=arc-20160816; b=r8fpnLRseVyP/Av7I9DFOTr/nyXDKi/rX2jpWI/VLOL/vZhj7VXnTS33QcThdB0jYB 9hI5yAUxkV/1x/qJYKdCSta/0/ii0CNtt3VaGmyK2Zl98yAHFcVG5qpu67Rm/KYbpamb LXSBh0xGplFtAt+o3SGTYsk6nHTCXHYzrHtMrhN2qGmc47WqskDsB5f7HcEZDtt0kZSm J+EgXRZqM8o2ZPO52ClnFfcae4ALonUHk3XKpTp7rMle1F9XBAB8ISc6DEenpcWUcIV3 H56+QGe0y04RKJI3whZp+GcEOs92NEfVX4icASX80UJ9IXFqubICbY8cG/1F179qfcRp e94w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type :content-transfer-encoding:mime-version:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=EMoPAC75FBY1rzEvXerOmj/3hLvCyILy+vvdDVXy7a8=; b=axVW3bVzvtISaHiVYSiTzssxPjghZ34zflHWvEi32YcB6mFF51eBCDiPI0K4sb1cY4 r5zxLGESjh3JzQzivYQ80o0RyS/O/YWb5npOWJZbKrlBX7be5Z7ZdbxBuBfs8hwsVy0S 1xn2KkB1vKn3Uq1mjN79csZh+Y9IaD0GWdiImMnMlmzVKYNe1zamuL76rnmgUptMNdPi 01AHSCD7DSYzVpDCTfCitSVUTDy9xdOwGg3ccTwmXVl0dL0rnmySsXcgm1tAuQZ5mXHm LC+rKfVxqCKWBjbsHuZDmyDmyhwtuQfb7cn7TZv+J2hhpSNyWHtzjHJ/S4As/vGzoVX4 fYiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=tRCnruzb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si5010168oto.169.2019.12.20.04.03.16; Fri, 20 Dec 2019 04:03:34 -0800 (PST) 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; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=tRCnruzb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727526AbfLTMCG (ORCPT + 99 others); Fri, 20 Dec 2019 07:02:06 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:36382 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727444AbfLTMBr (ORCPT ); Fri, 20 Dec 2019 07:01:47 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20191220120145euoutp0175192bba426daa13945e41437ec8cd60~iEqHXJnls1021810218euoutp01- for ; Fri, 20 Dec 2019 12:01:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20191220120145euoutp0175192bba426daa13945e41437ec8cd60~iEqHXJnls1021810218euoutp01- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1576843305; bh=EMoPAC75FBY1rzEvXerOmj/3hLvCyILy+vvdDVXy7a8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tRCnruzb/wY9YAaY5gD3giVNZ2IaC86gwj8514iGy1XRgMfyzA5i66EzStxwldjmz Dmnc508mUSlm09ciGE+o+5Qj5bv+BeIWD52KrLF+Qg8taD48ZXXWYj525anWcmCepn Nu4wa72qB3QvgybK72cEdeADTUJpamHtO9qu0wvw= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20191220120145eucas1p15c70bfb8a1ed29cdc9146915b0ba97ba~iEqHFhwRt1908419084eucas1p1S; Fri, 20 Dec 2019 12:01:45 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id A4.3E.60698.928BCFD5; Fri, 20 Dec 2019 12:01:45 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20191220120145eucas1p295af63eed7b23982d8c49fcf875cec8c~iEqGt9ZyO2958229582eucas1p24; Fri, 20 Dec 2019 12:01:45 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20191220120145eusmtrp2bddf4a83107f924dccfe910146f1c3a1~iEqGtG9RP2149221492eusmtrp2y; Fri, 20 Dec 2019 12:01:45 +0000 (GMT) X-AuditID: cbfec7f5-a0fff7000001ed1a-4b-5dfcb82996b3 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id B5.87.08375.928BCFD5; Fri, 20 Dec 2019 12:01:45 +0000 (GMT) Received: from AMDC3555.digital.local (unknown [106.120.51.67]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20191220120144eusmtip2b8b1a1fa0c24155f199d95970587d722~iEqF9D0FK3105631056eusmtip2a; Fri, 20 Dec 2019 12:01:44 +0000 (GMT) From: =?UTF-8?q?Artur=20=C5=9Awigo=C5=84?= To: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: =?UTF-8?q?Artur=20=C5=9Awigo=C5=84?= , cw00.choi@samsung.com, myungjoo.ham@samsung.com, inki.dae@samsung.com, sw0312.kim@samsung.com, georgi.djakov@linaro.org, leonard.crestez@nxp.com, m.szyprowski@samsung.com, b.zolnierkie@samsung.com, krzk@kernel.org Subject: [RFC PATCH v3 5/7] devfreq: exynos-bus: Add interconnect functionality to exynos-bus Date: Fri, 20 Dec 2019 12:56:51 +0100 Message-Id: <20191220115653.6487-6-a.swigon@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191220115653.6487-1-a.swigon@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA01SfUyMcRzf73nuee7p6vJ0aX1F4pq1whX54ydmtbEdNjNjrEkdPdJ0l91T kT84jlTnpWWtK72RVcuMHrFqhNxqybrp9Titoogh7aoJQ0/Pmf77fH+fl+/Lfgyp6qICmGRD Gmc06FLUtEL2oHXGvjq04VdcRN73QDxYdh7hOusdCvdPfqBwua2Twj1T4zQufCTQOH8wT4bt 9rtyXDMwQWHhXR+Fu5tKaOy6ZEPYam8m8G3bgBw7z9TQ2Hr1Ix3NaoXaHFr7pu8hrR20tBHa ezdPa+u+NhDay/W1SOsSlu6Uxyo2JnIpyRmcMXxTguKIc8xJH/sdfuLKswnahKpCchHDALsO vrzYk4sUjIqtQdD9uYbKRR6zxSSCOsd+iXAhuPzos0wkRIOQbSIkohpB/Wvrf0dFwRYR02wM 5BcMyUXRQtaG4GrFuEw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wioZufnPqh6QYmT M5+wdDFyAM1Xl1g/TwhilbxE89bZzBMYBWchqZqFUDULSdUCRuZVjCKppcW56bnFhnrFibnF pXnpesn5uZsYgfG67djPzTsYL20MPsQowMGoxMP7Mvl3rBBrYllxZe4hRgkOZiUR3tsdP2OF eFMSK6tSi/Lji0pzUosPMZoCvTaRWUo0OR+YSvJK4g1NDc0tLA3Njc2NzSyUxHk7BA7GCAmk J5akZqemFqQWwfQxcXBKNTDOfa7uftNQeXXJrxMce0Wk+Dc7Hv9cf2xFqufltQuj7/zITJdx MxML+3xxnvqRvn0buNKvTLu1yOTbz61MKp+uPzZ73JUV13v1r0yP/5n3NhemymXfr+2Nvrfr z/XF+acSpnxJKNzYYbFC6CXT+g26/xNO7VD1tP9YU3EmvVDO2zZXNjMn/XCZEktxRqKhFnNR cSIAfK1wku0CAAA= X-CMS-MailID: 20191220120145eucas1p295af63eed7b23982d8c49fcf875cec8c X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20191220120145eucas1p295af63eed7b23982d8c49fcf875cec8c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191220120145eucas1p295af63eed7b23982d8c49fcf875cec8c References: <20191220115653.6487-1-a.swigon@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds interconnect functionality to the exynos-bus devfreq driver. The SoC topology is a graph (or, more specifically, a tree) and its edges are specified using the 'exynos,interconnect-parent-node' in the DT. Due to unspecified relative probing order, -EPROBE_DEFER may be propagated to ensure that the parent is probed before its children. Each bus is now an interconnect provider and an interconnect node as well (cf. Documentation/interconnect/interconnect.rst), i.e. every bus registers itself as a node. Node IDs are not hardcoded but rather assigned at runtime, in probing order (subject to the above-mentioned exception regarding relative order). This approach allows for using this driver with various Exynos SoCs. Frequencies requested via the interconnect API for a given node are propagated to devfreq using dev_pm_qos_update_request(). Please note that it is not an error when CONFIG_INTERCONNECT is 'n', in which case all interconnect API functions are no-op. Signed-off-by: Artur Świgoń --- drivers/devfreq/exynos-bus.c | 144 +++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c index 9fdb188915e8..694a9581dcdb 100644 --- a/drivers/devfreq/exynos-bus.c +++ b/drivers/devfreq/exynos-bus.c @@ -14,14 +14,19 @@ #include #include #include +#include +#include #include #include #include +#include #include #include #define DEFAULT_SATURATION_RATIO 40 +#define kbps_to_khz(x) ((x) / 8) + struct exynos_bus { struct device *dev; @@ -35,6 +40,12 @@ struct exynos_bus { struct opp_table *opp_table; struct clk *clk; unsigned int ratio; + + /* One provider per bus, one node per provider */ + struct icc_provider provider; + struct icc_node *node; + + struct dev_pm_qos_request qos_req; }; /* @@ -205,6 +216,39 @@ static void exynos_bus_passive_exit(struct device *dev) clk_disable_unprepare(bus->clk); } +static int exynos_bus_icc_set(struct icc_node *src, struct icc_node *dst) +{ + struct exynos_bus *src_bus = src->data, *dst_bus = dst->data; + s32 src_freq = kbps_to_khz(src->avg_bw); + s32 dst_freq = kbps_to_khz(dst->avg_bw); + int ret; + + ret = dev_pm_qos_update_request(&src_bus->qos_req, src_freq); + if (ret < 0) { + dev_err(src_bus->dev, "failed to update PM QoS request"); + return ret; + } + + ret = dev_pm_qos_update_request(&dst_bus->qos_req, dst_freq); + if (ret < 0) { + dev_err(dst_bus->dev, "failed to update PM QoS request"); + return ret; + } + + return 0; +} + +static struct icc_node *exynos_bus_icc_xlate(struct of_phandle_args *spec, + void *data) +{ + struct exynos_bus *bus = data; + + if (spec->np != bus->dev->of_node) + return ERR_PTR(-EINVAL); + + return bus->node; +} + static int exynos_bus_parent_parse_of(struct device_node *np, struct exynos_bus *bus) { @@ -419,6 +463,96 @@ static int exynos_bus_profile_init_passive(struct exynos_bus *bus, return 0; } +static struct icc_node *exynos_bus_icc_get_parent(struct exynos_bus *bus) +{ + struct device_node *np = bus->dev->of_node; + struct of_phandle_args args; + int num, ret; + + num = of_count_phandle_with_args(np, "exynos,interconnect-parent-node", + "#interconnect-cells"); + if (num != 1) + return NULL; /* parent nodes are optional */ + + ret = of_parse_phandle_with_args(np, "exynos,interconnect-parent-node", + "#interconnect-cells", 0, &args); + if (ret < 0) + return ERR_PTR(ret); + + of_node_put(args.np); + + return of_icc_get_from_provider(&args); +} + +static int exynos_bus_icc_init(struct exynos_bus *bus) +{ + static DEFINE_IDA(ida); + + struct device *dev = bus->dev; + struct icc_provider *provider = &bus->provider; + struct icc_node *node, *parent_node; + int id, ret; + + /* Initialize the interconnect provider */ + provider->set = exynos_bus_icc_set; + provider->aggregate = icc_std_aggregate; + provider->xlate = exynos_bus_icc_xlate; + provider->dev = dev; + provider->inter_set = true; + provider->data = bus; + + ret = icc_provider_add(provider); + if (ret < 0) + return ret; + + ret = id = ida_alloc(&ida, GFP_KERNEL); + if (ret < 0) + goto err_id; + + node = icc_node_create(id); + if (IS_ERR(node)) { + ret = PTR_ERR(node); + goto err_node; + } + + bus->node = node; + node->name = dev->of_node->name; + node->data = bus; + icc_node_add(node, provider); + + parent_node = exynos_bus_icc_get_parent(bus); + if (IS_ERR(parent_node)) { + ret = PTR_ERR(parent_node); + goto err_parent; + } + + if (parent_node) { + ret = icc_link_create(node, parent_node->id); + if (ret < 0) + goto err_parent; + } + + ret = dev_pm_qos_add_request(bus->devfreq->dev.parent, &bus->qos_req, + DEV_PM_QOS_MIN_FREQUENCY, 0); + if (ret < 0) + goto err_request; + + return 0; + +err_request: + if (parent_node) + icc_link_destroy(node, parent_node); +err_parent: + icc_node_del(node); + icc_node_destroy(id); +err_node: + ida_free(&ida, id); +err_id: + icc_provider_del(provider); + + return ret; +} + static int exynos_bus_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -468,6 +602,16 @@ static int exynos_bus_probe(struct platform_device *pdev) if (ret < 0) goto err; + /* + * Initialize interconnect provider. A return value of -ENOTSUPP means + * that CONFIG_INTERCONNECT is disabled. + */ + ret = exynos_bus_icc_init(bus); + if (ret < 0 && ret != -ENOTSUPP) { + dev_err(dev, "failed to initialize the interconnect provider"); + goto err; + } + max_state = bus->devfreq->profile->max_state; min_freq = (bus->devfreq->profile->freq_table[0] / 1000); max_freq = (bus->devfreq->profile->freq_table[max_state - 1] / 1000); -- 2.17.1