From patchwork Wed Dec 19 12:33:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Qian Wang X-Patchwork-Id: 10737205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0A1D13B5 for ; Wed, 19 Dec 2018 12:33:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF08E2B199 for ; Wed, 19 Dec 2018 12:33:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACF7D2B1A3; Wed, 19 Dec 2018 12:33:32 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 09B9E2B1BD for ; Wed, 19 Dec 2018 12:33:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E81B7893E8; Wed, 19 Dec 2018 12:33:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10070.outbound.protection.outlook.com [40.107.1.70]) by gabe.freedesktop.org (Postfix) with ESMTPS id 078FF89176 for ; Wed, 19 Dec 2018 12:33:30 +0000 (UTC) Received: from AM0PR08MB4483.eurprd08.prod.outlook.com (20.179.35.149) by AM0PR08MB3924.eurprd08.prod.outlook.com (20.178.118.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.19; Wed, 19 Dec 2018 12:33:26 +0000 Received: from AM0PR08MB4483.eurprd08.prod.outlook.com ([fe80::1dff:434f:5905:45db]) by AM0PR08MB4483.eurprd08.prod.outlook.com ([fe80::1dff:434f:5905:45db%5]) with mapi id 15.20.1446.018; Wed, 19 Dec 2018 12:33:26 +0000 From: "james qian wang (Arm Technology China)" To: Liviu Dudau Subject: [PATCH v2 3/9] drm/komeda: Build komeda to be a platform module Thread-Topic: [PATCH v2 3/9] drm/komeda: Build komeda to be a platform module Thread-Index: AQHUl5cKZzRqrCwt8EOLSMI+kFCkBw== Date: Wed, 19 Dec 2018 12:33:26 +0000 Message-ID: <20181219123147.16090-4-james.qian.wang@arm.com> References: <20181219123147.16090-1-james.qian.wang@arm.com> In-Reply-To: <20181219123147.16090-1-james.qian.wang@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [113.29.88.7] x-clientproxiedby: SYBPR01CA0132.ausprd01.prod.outlook.com (2603:10c6:10:5::24) To AM0PR08MB4483.eurprd08.prod.outlook.com (2603:10a6:208:145::21) x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM0PR08MB3924; 6:WZVkXpjLwvROQ1175cA5uaqifybNquO5YsFUXH0Us/xjaN3yZNkUY2KyxrrnAYqtG4J1sL1qk/qwlXjGqknWB5jF0S9R9GpcxYgvBUHc/KmXEIuxKyx21L26D8VrFd4S/Q1aEXQaGfKobWtR0k+VmseDzHtvZFER8y5iujbvH58Bx1RjROqzLYzDIkxFxkaBMOhMWz5NSvGLzQiev5vDhxr8NkCEWbfaTJx/Hdzvv5j5H+eI0RuJZ/g9cUPC0kkMvRk2k5Od5o9DClyHqbizzxMFtDSPc/md4YRAWwy/9XA+ufavQB+qpHnpFaAaEQgpJCBriRDCJsZkV1UonqfuBhHmppMzdu5A42LLfXllwIF5eZ7koaiHw3/SEcTlFCK/xuP7En7/bweHII8WknM9KvuDZCD9/uMotyWw6o08TQNkJhDFixQ5XiwZU5SgtJfA+5sFVfbptmAhxiKP2JgtlQ==; 5:gnOvcKByq6AN/vMmBSXyPAtTTGvg/m/DOxMN/8D5Ur1k1o11taIm6tbhlaysv3cE5/rYYDp8SOwPmoD8BnUUHaebgiu7umFfWCxupl5h6zFIIUiuZCoqjlKYap1O5h5BoPTNrZcOuJ5YhkKF7niU4lu+Cinlp0TYWABIjxb9agA=; 7:5EBCqxxPTwW5UrnzzJTX4siVqXK+O9Zlu5YiyjR97ZjiaHhrEpCbLsmniWbR8wf+9AqAqHbmJMHqkcYoPg/N2UJjG07maeXpv14iwI9ARk3+N5dGQ+22vwaZfVJcvkPXS1SWwEK/bBR6WnvtNNFB+A== x-ms-office365-filtering-correlation-id: a6922a6b-eafb-4c1e-2898-08d665ae2c72 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3924; x-ms-traffictypediagnostic: AM0PR08MB3924: nodisclaimer: True x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231475)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:AM0PR08MB3924; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3924; x-forefront-prvs: 0891BC3F3D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(396003)(346002)(39860400002)(366004)(376002)(199004)(189003)(316002)(8936002)(103116003)(37006003)(1076003)(71190400001)(81166006)(81156014)(11346002)(446003)(97736004)(36756003)(54906003)(256004)(2616005)(486006)(6636002)(99286004)(71200400001)(476003)(575784001)(86362001)(8676002)(106356001)(105586002)(5660300001)(3846002)(7416002)(6116002)(14454004)(68736007)(6512007)(2906002)(4326008)(25786009)(6486002)(76176011)(52116002)(53936002)(186003)(55236004)(102836004)(26005)(6862004)(6436002)(305945005)(478600001)(6506007)(66066001)(386003)(7736002)(21314003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB3924; H:AM0PR08MB4483.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: KEccncioqT6ImzVnK8uxjlkTHqij61LFmWaGk4JXF7SRf2DZeXWPFj6ITOSK4QBUV/YZnGsApwzg+szw1CfzPyhX99xF6olAK2xL2I6JZKDClk7W1Cq8BRM2VLRDBIimy87k0Yj5j9GZNIZUEN3j6XBl1YjcReIe2uwjK0ebINvPeU5hV1zWTrMFkGTsrQ9/thBHXlExQ/chPjEsFgaKHduuQtEQtovxAtrEnstEfkohj0Q0a1sq8uqgfYaF69TFpMGpcfpLorgG4fny3OfB89F3/Or2/QYbfbxbteXvpDsFjqivWi3sNyJtOB/4hbNJ spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6922a6b-eafb-4c1e-2898-08d665ae2c72 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2018 12:33:26.7440 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3924 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , "linux-doc@vger.kernel.org" , "maxime.ripard@bootlin.com" , "Jonathan Chai \(Arm Technology China\)" , Alexandru-Cosmin Gheorghe , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "yamada.masahiro@socionext.com" , "Yiqi Kang \(Arm Technology China\)" , "mchehab+samsung@kernel.org" , "Tiannan Zhu \(Arm Technology China\)" , "corbet@lwn.net" , "airlied@linux.ie" , "malidp@foss.arm.com" , "thomas Sun \(Arm Technology China\)" , Ayan Halder , "devicetree@vger.kernel.org" , "arnd@arndb.de" , "robh+dt@kernel.org" , "Jin Gao \(Arm Technology China\)" , nd , "sean@poorly.run" , "Lowry Li \(Arm Technology China\)" , "gregkh@linuxfoundation.org" , "rdunlap@infradead.org" , "nicolas.ferre@microchip.com" , "Julien Yin \(Arm Technology China\)" , "james qian wang \(Arm Technology China\)" , "akpm@linux-foundation.org" , "davem@davemloft.net" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implement a simple wrapper for platform module to build komeda to module, Also add a very simple D71 layer code to show how to discover a product. Komeda driver direct bind the product ENTRY function xxx_identity to DT compatible name like: d71_product = { .product_id = MALIDP_D71_PRODUCT_ID, .identify = d71_identify, }, const struct of_device_id komeda_of_match[] = { { .compatible = "arm,mali-d71", .data = &d71_product, }, {}, }; Then when linux found a matched DT node and call driver to probe, we can easily get the of data, and call into the product to do the identify: komeda_bind() { ... product = of_device_get_match_data(dev); product->identify(); ... } Signed-off-by: James (Qian) Wang --- .../gpu/drm/arm/display/include/malidp_io.h | 42 ++++++ drivers/gpu/drm/arm/display/komeda/Makefile | 6 +- .../gpu/drm/arm/display/komeda/d71/d71_dev.c | 33 +++++ .../gpu/drm/arm/display/komeda/komeda_dev.h | 4 +- .../gpu/drm/arm/display/komeda/komeda_drv.c | 132 ++++++++++++++++++ 5 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/arm/display/include/malidp_io.h create mode 100644 drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_drv.c diff --git a/drivers/gpu/drm/arm/display/include/malidp_io.h b/drivers/gpu/drm/arm/display/include/malidp_io.h new file mode 100644 index 000000000000..4fb3caf864ce --- /dev/null +++ b/drivers/gpu/drm/arm/display/include/malidp_io.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * (C) COPYRIGHT 2018 ARM Limited. All rights reserved. + * Author: James.Qian.Wang + * + */ +#ifndef _MALIDP_IO_H_ +#define _MALIDP_IO_H_ + +#include + +static inline u32 +malidp_read32(u32 __iomem *base, u32 offset) +{ + return readl((base + (offset >> 2))); +} + +static inline void +malidp_write32(u32 __iomem *base, u32 offset, u32 v) +{ + writel(v, (base + (offset >> 2))); +} + +static inline void +malidp_write32_mask(u32 __iomem *base, u32 offset, u32 m, u32 v) +{ + u32 tmp = malidp_read32(base, offset); + + tmp &= (~m); + malidp_write32(base, offset, v | tmp); +} + +static inline void +malidp_write_group(u32 __iomem *base, u32 offset, int num, const u32 *values) +{ + int i; + + for (i = 0; i < num; i++) + malidp_write32(base, offset + i * 4, values[i]); +} + +#endif /*_MALIDP_IO_H_*/ diff --git a/drivers/gpu/drm/arm/display/komeda/Makefile b/drivers/gpu/drm/arm/display/komeda/Makefile index 07b5965f3808..4efcce0cdce8 100644 --- a/drivers/gpu/drm/arm/display/komeda/Makefile +++ b/drivers/gpu/drm/arm/display/komeda/Makefile @@ -5,7 +5,11 @@ ccflags-y := \ -I$(src) komeda-y := \ + komeda_drv.o \ komeda_dev.o \ - komeda_pipeline.o \ + komeda_pipeline.o + +komeda-y += \ + d71/d71_dev.o obj-$(CONFIG_DRM_KOMEDA) += komeda.o \ No newline at end of file diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c new file mode 100644 index 000000000000..af3dabb499cd --- /dev/null +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * (C) COPYRIGHT 2018 ARM Limited. All rights reserved. + * Author: James.Qian.Wang + * + */ +#include "malidp_io.h" +#include "komeda_dev.h" + +static int d71_enum_resources(struct komeda_dev *mdev) +{ + /* TODO add enum resources */ + return -1; +} + +static struct komeda_dev_funcs d71_chip_funcs = { + .enum_resources = d71_enum_resources, + .cleanup = NULL, +}; + +#define GLB_ARCH_ID 0x000 +#define GLB_CORE_ID 0x004 +#define GLB_CORE_INFO 0x008 + +struct komeda_dev_funcs * +d71_identify(u32 __iomem *reg_base, struct komeda_chip_info *chip) +{ + chip->arch_id = malidp_read32(reg_base, GLB_ARCH_ID); + chip->core_id = malidp_read32(reg_base, GLB_CORE_ID); + chip->core_info = malidp_read32(reg_base, GLB_CORE_INFO); + + return &d71_chip_funcs; +} diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h index 25c79528dac4..680e3e2cf100 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h @@ -12,7 +12,6 @@ #include "komeda_pipeline.h" #include "malidp_product.h" - /* malidp device id */ enum { MALI_D71 = 0, @@ -93,6 +92,9 @@ komeda_product_match(struct komeda_dev *mdev, u32 target) return MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id) == target; } +struct komeda_dev_funcs * +d71_identify(u32 __iomem *reg, struct komeda_chip_info *chip); + struct komeda_dev *komeda_dev_create(struct device *dev); void komeda_dev_destroy(struct komeda_dev *mdev); diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c new file mode 100644 index 000000000000..bf32d334d20d --- /dev/null +++ b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * (C) COPYRIGHT 2018 ARM Limited. All rights reserved. + * Author: James.Qian.Wang + * + */ +#include +#include +#include +#include +#include +#include "komeda_dev.h" + +struct komeda_drv { + struct komeda_dev *mdev; +}; + +static void komeda_unbind(struct device *dev) +{ + struct komeda_drv *mdrv = dev_get_drvdata(dev); + + dev_set_drvdata(dev, NULL); + + if (mdrv == NULL) + return; + + komeda_dev_destroy(mdrv->mdev); + kfree(mdrv); +} + +static int komeda_bind(struct device *dev) +{ + struct komeda_drv *mdrv; + int err; + + mdrv = kzalloc(sizeof(*mdrv), GFP_KERNEL); + if (mdrv == NULL) + return -ENOMEM; + + mdrv->mdev = komeda_dev_create(dev); + if (IS_ERR(mdrv->mdev)) { + err = PTR_ERR(mdrv->mdev); + goto free_mdrv; + } + + dev_set_drvdata(dev, mdrv); + + return 0; + +free_mdrv: + kfree(mdrv); + return err; +} + +static const struct component_master_ops komeda_master_ops = { + .bind = komeda_bind, + .unbind = komeda_unbind, +}; + +static int compare_of(struct device *dev, void *data) +{ + return dev->of_node == data; +} + +static void komeda_add_slave(struct device *master, + struct component_match **match, + struct device_node *np, int port) +{ + struct device_node *remote; + + remote = of_graph_get_remote_node(np, port, 0); + if (remote != NULL) { + drm_of_component_match_add(master, match, compare_of, remote); + of_node_put(remote); + } +} + +static int komeda_platform_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct component_match *match = NULL; + struct device_node *child; + + if (dev->of_node == NULL) + return -ENODEV; + + for_each_available_child_of_node(dev->of_node, child) { + if (of_node_cmp(child->name, "pipeline") != 0) + continue; + + /* add connector */ + komeda_add_slave(dev, &match, child, KOMEDA_OF_PORT_OUTPUT); + } + + return component_master_add_with_match(dev, &komeda_master_ops, match); +} + +static int komeda_platform_remove(struct platform_device *pdev) +{ + component_master_del(&pdev->dev, &komeda_master_ops); + return 0; +} + +static const struct komeda_product_data komeda_products[] = { + [MALI_D71] = { + .product_id = MALIDP_D71_PRODUCT_ID, + .identify = d71_identify, + }, +}; + +const struct of_device_id komeda_of_match[] = { + { .compatible = "arm,mali-d71", .data = &komeda_products[MALI_D71], }, + {}, +}; + +MODULE_DEVICE_TABLE(of, komeda_of_match); + +static struct platform_driver komeda_platform_driver = { + .probe = komeda_platform_probe, + .remove = komeda_platform_remove, + .driver = { + .name = "komeda", + .of_match_table = komeda_of_match, + .pm = NULL, + }, +}; + +module_platform_driver(komeda_platform_driver); + +MODULE_AUTHOR("James.Qian.Wang "); +MODULE_DESCRIPTION("Komeda KMS driver"); +MODULE_LICENSE("GPL v2");