From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794841836; b=bomtgsPsgi6BXkUHRflCCPkDezK6BgwRxkEYfUO82YdEvRQFRx+e2pI5CUERY/HW0E/T j1ji+yycVsASNHh7Pw9TTE3XOM+e2lMcTPRy7NalIW266nKm/uplcTf72gboN5WkASkA2 G/f8Q5O6CphGy+IzID4z4ypcABTuK0hEcwHUk/ol3BKEb2mZPtCUzKP6Ngnjj3qnI+O+X Z9k96dnT+yiI6H6QigI47CH5exmWCMAMQNZIt+e5y1au3I2lJKuIAfHf3A16AttKkRvre 6xO+L9S99OgQ55RX9/uChW89eqC/na9qp97rDh4Mnm8YG/hsO3OOZn38CBUHniuqUqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794841836; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=Q3yyEOX4PTNhScPxIGzl170lewq9VZJENU/JVMlpYRE=; b=MR6/q3/FquWQ/Tn0xpkFWYtQdmKzvYioN2o2fjCTXEZK4H2zA4JPPUCfzONDMao6S0ov dudumV8cCaue3RRK2xjSWwJo3ggxn8QiVHK+/xceeKL010d7/0wWo9PjzMNF3DcfwDtHU x/VynYleebIvgycDGjaTjLhgeZO4sPrZtjxqqJnQQ04j3eaqeFot4agBe80VnsJ7s80mE 2oI0uJljFYezNEbxfjvPdUxngC5cL3Cb7hNnTi1KocPfQmfVJWpYTu0cdbfYR9TUCixPv 7EjhQVyt8CZ9jSr+x+09eYL3L3HOfXpRiv2P9zMXpd8I5sMUEBfFGYVX6yph3y7CAZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Da36E70n; arc=none smtp.remote-ip=209.85.218.44 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86289606A335 for ; Mon, 16 Nov 2026 15:10:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 86289606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Da36E70n Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-c50e26763a4so131510966b.1 for ; Mon, 16 Nov 2026 07:10:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794841834; x=1795446634; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Q3yyEOX4PTNhScPxIGzl170lewq9VZJENU/JVMlpYRE=; b=Da36E70nI/1UFJ/4ZTOpnFSb1GFcnlgbApY63N3rqmEfrKkg0CZe7NCW2gHTZ5jNAt ify/Cm5azc2ujgf62d2geS7Kd/DAlSgT+OVcEBZGn5EsMQAtJc6Yi5k2NLt+/a4B2QbD ts19km3VPPZkoqoT85agLBhzZlWHhyxdrMbn+/EeLvnvniscGfI4ONoGvHzES5zEov55 sxV0bYixrNbdAj6p/xIQmmxPMq9FLnsR7MvAg+GZm9cl4rHSmnfuJGYGeBbk3hGjWMhi fRqOShoJyy3RJQEqOaYdYloSpOtJdrFqTuvFT3Reb/bwah9Ed6f4PWSWBCxv6SBN7cmX 7idQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794841834; x=1795446634; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Q3yyEOX4PTNhScPxIGzl170lewq9VZJENU/JVMlpYRE=; b=XwTwR2bYDtgz9+op0nwh+LH5YEM5c4el253NJ9lctCxzgwl90RRCSBeRp1p8wah262 k4FxoNUq15EDHr6/AL7iglHoX+svKEr1K2UvqN2ty7rHhH1xGc4raRpH44ncX5ZsvRB/ cXaiEiaympYcDeYAUYQnQUJTX/zKOqw/KLifiy2bXyiNe5PAhvxpP7LQOKQxm/mSl3ZX G1QCKuA0slKFJqgQhgkhUgHu/mBVZLL0DcAo+4GOUjS60MVX3u/68XkIES4vhSNu9HeS J4oEtM+EsozGXBOuULb3dRHhGLh7CNf9RJSA7/KWKrK18r6gEUHEoxZ4TkOPY8TAg21W acfw== X-Forwarded-Encrypted: i=1; AL+hErFnVB0/6bMeZIGOMIVTJxTjblX7v6mUwk5iMip/P/mPzOWqTgSLgxLPs+GXBOo8OGLBcrXxBRj1auZ+Eyg=@vger.kernel.org X-Gm-Message-State: APuU4Z8z1F7K4oQaa6SDLa2xs8KddwABNsSxH0JpYpCOuLQPL1z/4L7x zBvAhcN/7KlV0jnYCF2q0X+r21IqbFBFMpAAvqshHXxkEE82gi9192wg X-Gm-Gg: AYBFou1PAwsxWWlFj3tReQF2yCc5qIowgi2xx5gRZVSVENwi1TYE7P8CKlOc1jTgGHk vmF09ADzUqlfgHNnQol77h/FtiW+tL8ef9tdirUj1MTfrAOHkmXfmz8T6ZB06tgEL2cJymnsChl zORdoexy+pE8rJUCMtvUkbmNFhBMpBnGknz6Bfz2mM7bNcU21VFkOiqKr+lzmHv+Ymz5CBtfl7u 1yh8pBEG/BlzJrwy6mjc6bGYZVJM4UgPTjP1MQyaljaKX9TifhsfKsXLSOpvAufBky9snOd7cI7 DT0s0xdUvsdQYlXhtnXyB4hxHNHawcEtOL/PXNCyDolJCpxTG5QsnrmMWWiMGoegF8Aw8KLI/ip aaxu9hO6LVThx2WjObbrWHayu6B3j/j83/cxVxV3mvKQNPhQFA6RLQI1jXQtm/z/BFu/KksEJfF BGVqm85V93UVkyfDf/MFgx+ZhcTuwLvZQ2s4Cys6XXRHVV9GABfUzcMvJdiLAcQnRQBln0bS3Yw 4psQ/PfIfALvByx2ElDRod2kaWrPwVDL69XzeBdRIQKHdsuymC0Fwm7gPJRlW0cpHcYjAqTol7Y I2dhs7BzANxWNR75xWZxkY338fVkzimwikWJHLFYJfwVvJ7LXzuE23CLqecKu6XDxA32RiNDICl EiFc2uJLs3Ks= X-Received: by 2002:a17:907:608f:b0:c50:95a4:d2d9 with SMTP id a640c23a62f3a-c50963bba18mr894423866b.49.1794841833866; Mon, 16 Nov 2026 07:10:33 -0800 (PST) Received: from xeon ([188.163.112.62]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c5095b93a85sm420868466b.84.2026.11.16.07.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2026 07:10:32 -0800 (PST) From: Svyatoslav Ryhel To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Thierry Reding , Jonathan Hunter , Neil Armstrong , Jessica Zhang , Mikko Perttunen , Svyatoslav Ryhel Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 01/12] drm: Add MIPI DBI bus support for MIPI DBI Type A and B Date: Mon, 16 Nov 2026 17:10:06 +0200 Message-ID: <20261116151017.274764-2-clamor95@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261116151017.274764-1-clamor95@gmail.com> References: <20261116151017.274764-1-clamor95@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The MIPI DBI bus allows modeling DBI hosts and peripherals using the Linux driver model. DBI hosts are registered by their respective drivers. During registration, DBI peripherals are created from the device tree nodes provided by the host. DBI hosts expose operations that can be used by peripheral drivers to access associated devices. This implementation adds support for MIPI DBI Type A and Type B only. Type C support existing in drm_mipi_dbi.c was not altered. The framework is modeled to closely resemble the existing MIPI DSI setup for seamless integration. Suggested-by: Mikko Perttunen # preliminary sketch Signed-off-by: Svyatoslav Ryhel --- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_mipi_dbi_bus.c | 258 +++++++++++++++++++++++++++++ include/drm/drm_mipi_dbi_bus.h | 113 +++++++++++++ 3 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/drm_mipi_dbi_bus.c create mode 100644 include/drm/drm_mipi_dbi_bus.h diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 2c6bc093a923a..880f0dc930b85 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -166,7 +166,7 @@ obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o obj-y += tests/ -obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o +obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o drm_mipi_dbi_bus.o obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o obj-y += arm/ obj-y += clients/ diff --git a/drivers/gpu/drm/drm_mipi_dbi_bus.c b/drivers/gpu/drm/drm_mipi_dbi_bus.c new file mode 100644 index 0000000000000..fa8cd748d7b3c --- /dev/null +++ b/drivers/gpu/drm/drm_mipi_dbi_bus.c @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * MIPI DBI devices with command transport through parallel interface + * + * Copyright 2026 Mikko Perttunen + * Copyright 2026 Svyatoslav Ryhel + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +/** + * DOC: overview + * + * There are three MIPI DBI implementation types: + * + * A. Motorola 6800-type parallel bus + * + * B. Intel 8080-type parallel bus + * + * C. SPI-type with three options: + * + * 1. 9-bit with the Data/Command signal as the ninth bit + * 2. Same as above, except it is sent as 16 bits + * 3. 8-bit with the Data/Command signal as a separate D/CX pin + * + * This library provides a framework for MIPI Display Bus Interface (DBI) + * compatible display controllers using Type A and Type B. This + * implementation closely matches existing DSI framework behavior to + * allow seamless integration. + * + * Type C options 1 and 3 are covered by drm_mipi_dbi.c with + * mipi_dbi_spi_init(). + */ + +static int mipi_dbi_match(struct device *dev, const struct device_driver *driver) +{ + return of_driver_match_device(dev, driver); +} + +static int mipi_dbi_uevent(const struct device *dev, struct kobj_uevent_env *env) +{ + return of_device_uevent_modalias(dev, env); +} + +static const struct dev_pm_ops mipi_dbi_device_pm_ops = { + .runtime_suspend = pm_generic_runtime_suspend, + .runtime_resume = pm_generic_runtime_resume, + .suspend = pm_generic_suspend, + .resume = pm_generic_resume, + .freeze = pm_generic_freeze, + .thaw = pm_generic_thaw, + .poweroff = pm_generic_poweroff, + .restore = pm_generic_restore, +}; + +static const struct bus_type mipi_dbi_bus_type = { + .name = "mipi-dbi", + .match = mipi_dbi_match, + .uevent = mipi_dbi_uevent, + .pm = &mipi_dbi_device_pm_ops, +}; + +static void mipi_dbi_device_release(struct device *dev) +{ + of_node_put(dev->of_node); + kfree(to_mipi_dbi_device(dev)); +} + +static void mipi_dbi_device_unregister(void *data) +{ + struct device *dev = data; + + of_node_clear_flag(dev->of_node, OF_POPULATED); + device_unregister(dev); +} + +/** + * devm_mipi_dbi_device_register() - create a managed peripheral MIPI DBI + * Type A or B device. + * @dev: device to tie the MIPI-DBI device lifetime to + * @host: DBI host to which this device is connected + * @np: device tree node associated with the panel MIPI DBI device + * + * This function is called by DBI host driver to create panel device. + * It automatically calls mipi_dbi_device_unregister() when @dev is + * unbound. It does not automatically free passed device node pointer, + * it must be put manually. + * + * Returns: + * A pointer to the newly created MIPI DBI device, or, a pointer encoded + * with an error. + */ +struct mipi_dbi_device * +devm_mipi_dbi_device_register(struct device *dev, struct mipi_dbi_host *host, + struct device_node *np) +{ + struct mipi_dbi_device *dbidev; + int ret; + + if (!host || !host->dev || !host->dbi || !host->dbi->command || + !host->ops || !host->ops->attach || !host->ops->detach || !np) + return ERR_PTR(-EINVAL); + + if (!of_device_is_available(np)) + return ERR_PTR(-ENODEV); + + dbidev = kzalloc_obj(*dbidev); + if (!dbidev) + return ERR_PTR(-ENOMEM); + + if (of_node_test_and_set_flag(np, OF_POPULATED)) { + kfree(dbidev); + return ERR_PTR(-EBUSY); + } + + dbidev->host = host; + dbidev->dbi = host->dbi; + device_initialize(&dbidev->dev); + dbidev->dev.parent = host->dev; + dbidev->dev.bus = &mipi_dbi_bus_type; + dbidev->dev.release = mipi_dbi_device_release; + device_set_node(&dbidev->dev, of_fwnode_handle(np)); + + ret = dev_set_name(&dbidev->dev, "%s:%s", dev_name(host->dev), np->full_name); + if (ret) + goto put_device; + + ret = device_add(&dbidev->dev); + if (ret) + goto put_device; + + ret = devm_add_action_or_reset(dev, mipi_dbi_device_unregister, + &dbidev->dev); + if (ret) + return ERR_PTR(ret); + + return dbidev; + +put_device: + of_node_clear_flag(np, OF_POPULATED); + put_device(&dbidev->dev); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(devm_mipi_dbi_device_register); + +static void mipi_dbi_detach(void *data) +{ + struct mipi_dbi_device *dbidev = data; + + dbidev->host->ops->detach(dbidev->host, dbidev); + dbidev->attached = false; +} + +/** + * devm_mipi_dbi_attach() - managed attach of peripheral DBI device to its MIPI + * DBI Type A or B devices. + * @dev: device to tie the MIPI-DBI device lifetime to + * @dbidev: DBI peripheral + */ +int devm_mipi_dbi_attach(struct device *dev, struct mipi_dbi_device *dbidev) +{ + int ret; + + if (dbidev->attached) + return -EBUSY; + + ret = dbidev->host->ops->attach(dbidev->host, dbidev); + if (ret) + return ret; + + dbidev->attached = true; + return devm_add_action_or_reset(dev, mipi_dbi_detach, dbidev); +} +EXPORT_SYMBOL_GPL(devm_mipi_dbi_attach); + +static int mipi_dbi_drv_probe(struct device *dev) +{ + struct mipi_dbi_driver *drv = to_mipi_dbi_driver(dev->driver); + struct mipi_dbi_device *dbidev = to_mipi_dbi_device(dev); + + return drv->probe(dbidev); +} + +static int mipi_dbi_drv_remove(struct device *dev) +{ + struct mipi_dbi_driver *drv = to_mipi_dbi_driver(dev->driver); + struct mipi_dbi_device *dbidev = to_mipi_dbi_device(dev); + + drv->remove(dbidev); + + return 0; +} + +static void mipi_dbi_drv_shutdown(struct device *dev) +{ + struct mipi_dbi_driver *drv = to_mipi_dbi_driver(dev->driver); + struct mipi_dbi_device *dbidev = to_mipi_dbi_device(dev); + + drv->shutdown(dbidev); +} + +/** + * __mipi_dbi_driver_register() - register a driver for MIPI DBI Type A or B devices. + * @drv: DBI driver structure + * @owner: owner module + * + * Return: 0 on success or a negative error code on failure. + */ +int __mipi_dbi_driver_register(struct mipi_dbi_driver *drv, struct module *owner) +{ + drv->driver.bus = &mipi_dbi_bus_type; + drv->driver.owner = owner; + + if (drv->probe) + drv->driver.probe = mipi_dbi_drv_probe; + if (drv->remove) + drv->driver.remove = mipi_dbi_drv_remove; + if (drv->shutdown) + drv->driver.shutdown = mipi_dbi_drv_shutdown; + + return driver_register(&drv->driver); +} +EXPORT_SYMBOL_GPL(__mipi_dbi_driver_register); + +/** + * mipi_dbi_driver_unregister() - unregister a driver for MIPI DBI Type A or B devices. + * @drv: DBI driver structure + * + * Return: 0 on success or a negative error code on failure. + */ +void mipi_dbi_driver_unregister(struct mipi_dbi_driver *drv) +{ + driver_unregister(&drv->driver); +} +EXPORT_SYMBOL_GPL(mipi_dbi_driver_unregister); + +static int __init mipi_dbi_bus_init(void) +{ + return bus_register(&mipi_dbi_bus_type); +} +subsys_initcall(mipi_dbi_bus_init); + +static void __exit mipi_dbi_bus_exit(void) +{ + bus_unregister(&mipi_dbi_bus_type); +} +module_exit(mipi_dbi_bus_exit); + +MODULE_DESCRIPTION("MIPI DBI devices with command transport through parallel interface"); +MODULE_LICENSE("GPL"); diff --git a/include/drm/drm_mipi_dbi_bus.h b/include/drm/drm_mipi_dbi_bus.h new file mode 100644 index 0000000000000..886f175a80cb9 --- /dev/null +++ b/include/drm/drm_mipi_dbi_bus.h @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * MIPI DBI devices with command transport through parallel interface + * + * Copyright 2026 Mikko Perttunen + * Copyright 2026 Svyatoslav Ryhel + */ + +#ifndef __DRM_MIPI_DBI_BUS_H__ +#define __DRM_MIPI_DBI_BUS_H__ + +#include +#include + +struct device_node; +struct mipi_dbi; +struct mipi_dbi_device; +struct mipi_dbi_host; + +/** + * struct mipi_dbi_host_ops - DBI bus operations for MIPI DBI Type A and B. + * @attach: attach DBI device to DBI host + * @detach: detach DBI device from DBI host + */ +struct mipi_dbi_host_ops { + int (*attach)(struct mipi_dbi_host *host, struct mipi_dbi_device *dev); + void (*detach)(struct mipi_dbi_host *host, struct mipi_dbi_device *dev); +}; + +/** + * struct mipi_dbi_host - DBI host device for MIPI DBI Type A and B. + * @dev: driver model device node for this DBI host + * @dbi: MIPI DBI interface + * @ops: DBI host operations + */ +struct mipi_dbi_host { + struct device *dev; + struct mipi_dbi *dbi; + const struct mipi_dbi_host_ops *ops; +}; + +/** + * struct mipi_dbi_device - DBI peripheral device for MIPI DBI Type A and B. + * This structure describes a peripheral DBI device, + * an endpoint for DSC commands and video data, and must + * be paired with a DBI host device for MIPI DBI Type A + * and B. This layout is built to closely resemble + * the DSI framework. + * + * If your device is MIPI DBI Type C (with an SPI + * control bus) and incorporates DBI within, you + * should use the mipi_dbi_dev structure and Type C + * framework from drm_mipi_dbi.c. + * @dev: driver model device node for this peripheral + * @dbi: MIPI DBI interface + * @host: DBI host for this peripheral + * @attached: the DBI device has been successfully attached + */ +struct mipi_dbi_device { + struct device dev; + struct mipi_dbi *dbi; + struct mipi_dbi_host *host; + bool attached; +}; + +#define to_mipi_dbi_device(__dev) container_of_const(__dev, struct mipi_dbi_device, dev) + +struct mipi_dbi_device * +devm_mipi_dbi_device_register(struct device *dev, struct mipi_dbi_host *host, + struct device_node *np); +int devm_mipi_dbi_attach(struct device *dev, struct mipi_dbi_device *dbidev); + +/** + * struct mipi_dbi_driver - DBI driver for MIPI DBI Type A and B. + * @driver: device driver model driver + * @probe: callback for device binding + * @remove: callback for device unbinding + * @shutdown: called at shutdown time to quiesce the device + */ +struct mipi_dbi_driver { + struct device_driver driver; + int (*probe)(struct mipi_dbi_device *dbi); + void (*remove)(struct mipi_dbi_device *dbi); + void (*shutdown)(struct mipi_dbi_device *dbi); +}; + +static inline struct mipi_dbi_driver * +to_mipi_dbi_driver(struct device_driver *driver) +{ + return container_of(driver, struct mipi_dbi_driver, driver); +} + +static inline void *mipi_dbi_get_drvdata(const struct mipi_dbi_device *dbi) +{ + return dev_get_drvdata(&dbi->dev); +} + +static inline void mipi_dbi_set_drvdata(struct mipi_dbi_device *dbi, void *data) +{ + dev_set_drvdata(&dbi->dev, data); +} + +int __mipi_dbi_driver_register(struct mipi_dbi_driver *drv, struct module *owner); +void mipi_dbi_driver_unregister(struct mipi_dbi_driver *drv); + +#define mipi_dbi_driver_register(driver) \ + __mipi_dbi_driver_register(driver, THIS_MODULE) + +#define module_mipi_dbi_driver(__mipi_dbi_driver) \ + module_driver(__mipi_dbi_driver, mipi_dbi_driver_register, \ + mipi_dbi_driver_unregister) + +#endif /* __DRM_MIPI_DBI_BUS__ */ -- 2.53.0