@@ -4991,6 +4991,12 @@ T: git git://anongit.freedesktop.org/drm/drm-misc
S: Maintained
F: drivers/gpu/drm/bochs/
+DRM DRIVER FOR CHIPONE ICN6211 MIPI-DSI to RGB CONVERTOR BRIDGE
+M: Jagan Teki <jagan@amarulasolutions.com>
+S: Maintained
+F: drivers/gpu/drm/bridge/chipone-icn6211.c
+F: Documentation/devicetree/bindings/display/bridge/chipone,icn6211.txt
+
DRM DRIVER FOR FARADAY TVE200 TV ENCODER
M: Linus Walleij <linus.walleij@linaro.org>
T: git git://anongit.freedesktop.org/drm/drm-misc
@@ -36,6 +36,16 @@ config DRM_CDNS_DSI
Support Cadence DPI to DSI bridge. This is an internal
bridge and is meant to be directly embedded in a SoC.
+config DRM_CHIPONE_ICN6211
+ tristate "Chipone ICN6211 MIPI-DSI/RGB converter bridge"
+ depends on DRM && DRM_PANEL
+ depends on OF
+ select DRM_MIPI_DSI
+ help
+ ICN6211 is MIPI-DSI/RGB converter bridge from chipone.
+ It has a flexible configuration of MIPI DSI signal input
+ and produce RGB565, RGB666, RGB888 output format.
+
config DRM_DUMB_VGA_DAC
tristate "Dumb VGA DAC Bridge support"
depends on OF
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_DRM_ANALOGIX_ANX78XX) += analogix-anx78xx.o
obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o
+obj-$(CONFIG_DRM_CHIPONE_ICN6211) += chipone-icn6211.o
obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
obj-$(CONFIG_DRM_LVDS_ENCODER) += lvds-encoder.o
obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
new file mode 100644
@@ -0,0 +1,344 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Amarula Solutions
+ * Author: Jagan Teki <jagan@amarulasolutions.com>
+ */
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_fb_helper.h>
+#include <drm/drm_of.h>
+#include <drm/drm_panel.h>
+#include <drm/drm_print.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_mipi_dsi.h>
+
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_graph.h>
+
+#include <video/mipi_display.h>
+
+struct chipone_bridge_desc {
+ unsigned int lanes;
+ unsigned long mode_flags;
+ enum mipi_dsi_pixel_format format;
+ void (*chipone_bridge_init)(struct drm_bridge *bridge);
+};
+
+struct chipone {
+ struct device *dev;
+ struct drm_bridge bridge;
+ struct drm_connector connector;
+ struct drm_panel *panel;
+ const struct drm_display_mode *mode;
+ const struct chipone_bridge_desc *desc;
+
+ struct gpio_desc *reset_gpio;
+};
+
+static inline struct chipone *bridge_to_chipone(struct drm_bridge *bridge)
+{
+ return container_of(bridge, struct chipone, bridge);
+}
+
+static inline
+struct chipone *connector_to_chipone(struct drm_connector *connector)
+{
+ return container_of(connector, struct chipone, connector);
+}
+
+static int chipone_get_modes(struct drm_connector *connector)
+{
+ struct chipone *icn = connector_to_chipone(connector);
+
+ return drm_panel_get_modes(icn->panel);
+}
+
+static const
+struct drm_connector_helper_funcs chipone_connector_helper_funcs = {
+ .get_modes = chipone_get_modes,
+};
+
+static const struct drm_connector_funcs chipone_connector_funcs = {
+ .fill_modes = drm_helper_probe_single_connector_modes,
+ .destroy = drm_connector_cleanup,
+ .reset = drm_atomic_helper_connector_reset,
+ .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+ .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static void chipone_disable(struct drm_bridge *bridge)
+{
+ struct chipone *icn = bridge_to_chipone(bridge);
+ int ret;
+
+ ret = drm_panel_disable(bridge_to_chipone(bridge)->panel);
+ if (ret < 0)
+ DRM_DEV_ERROR(icn->dev, "error disabling panel (%d)\n", ret);
+}
+
+static void chipone_post_disable(struct drm_bridge *bridge)
+{
+ struct chipone *icn = bridge_to_chipone(bridge);
+ int ret;
+
+ ret = drm_panel_unprepare(icn->panel);
+ if (ret < 0)
+ DRM_DEV_ERROR(icn->dev, "error unpreparing panel (%d)\n", ret);
+
+ msleep(50);
+
+ gpiod_set_value(icn->reset_gpio, 0);
+}
+
+static inline int chipone_dsi_write(struct chipone *icn, const void *seq,
+ size_t len)
+{
+ struct mipi_dsi_device *dsi = to_mipi_dsi_device(icn->dev);
+
+ return mipi_dsi_generic_write(dsi, seq, len);
+}
+
+#define CHIPONE_DSI(icn, seq...) \
+ { \
+ const u8 d[] = { seq }; \
+ chipone_dsi_write(icn, d, ARRAY_SIZE(d)); \
+ }
+
+static void icn6211_bridge_init(struct drm_bridge *bridge)
+{
+ struct chipone *icn = bridge_to_chipone(bridge);
+ const struct drm_display_mode *mode = icn->mode;
+
+ CHIPONE_DSI(icn, 0x7A, 0xC1);
+
+ /* lower 8 bits of hdisplay */
+ CHIPONE_DSI(icn, 0x20, mode->hdisplay & 0xff);
+
+ /* lower 8 bits of vdisplay */
+ CHIPONE_DSI(icn, 0x21, mode->vdisplay & 0xff);
+
+ /**
+ * lsb nibble: 2nd nibble of hdisplay
+ * msb nibble: 2nd nibble of vdisplay
+ */
+ CHIPONE_DSI(icn, 0x22, (((mode->hdisplay >> 8) & 0xf) |
+ (((mode->vdisplay >> 8) & 0xf) << 4)));
+
+ /* HFP */
+ CHIPONE_DSI(icn, 0x23, mode->hsync_start - mode->hdisplay);
+
+ /* HSYNC */
+ CHIPONE_DSI(icn, 0x24, mode->hsync_end - mode->hsync_start);
+
+ /* HBP */
+ CHIPONE_DSI(icn, 0x25, mode->htotal - mode->hsync_end);
+
+ CHIPONE_DSI(icn, 0x26, 0x00);
+
+ /* VFP */
+ CHIPONE_DSI(icn, 0x27, mode->vsync_start - mode->vdisplay);
+
+ /* VSYNC */
+ CHIPONE_DSI(icn, 0x28, mode->vsync_end - mode->vsync_start);
+
+ /* VBP */
+ CHIPONE_DSI(icn, 0x29, mode->vtotal - mode->vsync_end);
+
+ /* dsi specific sequence */
+ CHIPONE_DSI(icn, MIPI_DCS_SET_TEAR_OFF, 0x80);
+ CHIPONE_DSI(icn, MIPI_DCS_SET_ADDRESS_MODE, 0x28);
+ CHIPONE_DSI(icn, 0xB5, 0xA0);
+ CHIPONE_DSI(icn, 0x5C, 0xFF);
+ CHIPONE_DSI(icn, MIPI_DCS_SET_COLUMN_ADDRESS, 0x01);
+ CHIPONE_DSI(icn, MIPI_DCS_GET_POWER_SAVE, 0x92);
+ CHIPONE_DSI(icn, 0x6B, 0x71);
+ CHIPONE_DSI(icn, 0x69, 0x2B);
+ CHIPONE_DSI(icn, MIPI_DCS_ENTER_SLEEP_MODE, 0x40);
+ CHIPONE_DSI(icn, MIPI_DCS_EXIT_SLEEP_MODE, 0x98);
+
+ /* icn6211 specific sequence */
+ CHIPONE_DSI(icn, 0xB6, 0x20);
+ CHIPONE_DSI(icn, 0x51, 0x20);
+ CHIPONE_DSI(icn, 0x09, 0x10);
+}
+
+static void chipone_pre_enable(struct drm_bridge *bridge)
+{
+ struct chipone *icn = bridge_to_chipone(bridge);
+ int ret;
+
+ gpiod_set_value(icn->reset_gpio, 0);
+ msleep(20);
+
+ gpiod_set_value(icn->reset_gpio, 1);
+ msleep(50);
+
+ icn->desc->chipone_bridge_init(bridge);
+
+ ret = drm_panel_prepare(icn->panel);
+ if (ret < 0)
+ DRM_DEV_ERROR(icn->dev, "error preparing panel (%d)\n", ret);
+}
+
+static void chipone_enable(struct drm_bridge *bridge)
+{
+ struct chipone *icn = bridge_to_chipone(bridge);
+ int ret;
+
+ ret = drm_panel_enable(icn->panel);
+ if (ret < 0)
+ DRM_DEV_ERROR(icn->dev, "error enabling panel (%d)\n", ret);
+}
+
+static int chipone_attach(struct drm_bridge *bridge)
+{
+ struct chipone *icn = bridge_to_chipone(bridge);
+ struct drm_device *drm = bridge->dev;
+ int ret;
+
+ if (!bridge->encoder) {
+ DRM_ERROR("Parent encoder object not found");
+ return -ENODEV;
+ }
+
+ icn->connector.polled = DRM_CONNECTOR_POLL_HPD;
+ ret = drm_connector_init(drm, &icn->connector,
+ &chipone_connector_funcs,
+ DRM_MODE_CONNECTOR_DPI);
+ if (ret) {
+ DRM_DEV_ERROR(icn->dev,
+ "Couldn't initialise the rgb connector\n");
+ goto err_out;
+ }
+
+ drm_connector_helper_add(&icn->connector,
+ &chipone_connector_helper_funcs);
+ drm_connector_register(&icn->connector);
+ drm_connector_attach_encoder(&icn->connector, bridge->encoder);
+
+ ret = drm_panel_attach(icn->panel, &icn->connector);
+ if (ret) {
+ DRM_DEV_ERROR(icn->dev, "Couldn't attach our panel\n");
+ goto err_cleanup_connector;
+ }
+
+ return 0;
+
+err_cleanup_connector:
+ drm_encoder_cleanup(bridge->encoder);
+err_out:
+ return ret;
+}
+
+static void chipone_detach(struct drm_bridge *bridge)
+{
+ struct chipone *icn = bridge_to_chipone(bridge);
+
+ drm_connector_unregister(&icn->connector);
+ drm_panel_detach(icn->panel);
+ icn->panel = NULL;
+ drm_connector_put(&icn->connector);
+}
+
+static enum drm_mode_status chipone_mode_valid(struct drm_bridge *bridge,
+ const struct drm_display_mode *mode)
+{
+ struct chipone *icn = bridge_to_chipone(bridge);
+
+ /* mode timings are useful during bridge init */
+ icn->mode = mode;
+
+ return MODE_OK;
+}
+
+static const struct drm_bridge_funcs chipone_bridge_funcs = {
+ .disable = chipone_disable,
+ .post_disable = chipone_post_disable,
+ .enable = chipone_enable,
+ .pre_enable = chipone_pre_enable,
+ .attach = chipone_attach,
+ .detach = chipone_detach,
+ .mode_valid = chipone_mode_valid,
+};
+
+static const struct chipone_bridge_desc icn6211_desc = {
+ .lanes = 4,
+ .mode_flags = MIPI_DSI_MODE_VIDEO_SYNC_PULSE,
+ .format = MIPI_DSI_FMT_RGB888,
+ .chipone_bridge_init = icn6211_bridge_init,
+};
+
+static int chipone_probe(struct mipi_dsi_device *dsi)
+{
+ struct device *dev = &dsi->dev;
+ const struct chipone_bridge_desc *desc;
+ struct chipone *icn;
+ int ret;
+
+ icn = devm_kzalloc(dev, sizeof(struct chipone), GFP_KERNEL);
+ if (!icn)
+ return -ENOMEM;
+
+ desc = of_device_get_match_data(dev);
+
+ icn->dev = dev;
+ dsi->mode_flags = desc->mode_flags;
+ dsi->format = desc->format;
+ dsi->lanes = desc->lanes;
+
+ icn->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+ if (IS_ERR(icn->reset_gpio)) {
+ DRM_DEV_ERROR(dev, "Couldn't get our reset GPIO\n");
+ return PTR_ERR(icn->reset_gpio);
+ }
+
+ ret = drm_of_find_panel_or_bridge(icn->dev->of_node, 1, 0,
+ &icn->panel, NULL);
+ if (ret && ret != -EPROBE_DEFER) {
+ DRM_DEV_ERROR(dev, "Couldn't find the panel (ret = %d)\n", ret);
+ return ret;
+ }
+
+ icn->bridge.funcs = &chipone_bridge_funcs;
+ icn->bridge.of_node = dev->of_node;
+
+ drm_bridge_add(&icn->bridge);
+ mipi_dsi_set_drvdata(dsi, icn);
+ icn->desc = desc;
+
+ return mipi_dsi_attach(dsi);
+}
+
+static int chipone_remove(struct mipi_dsi_device *dsi)
+{
+ struct chipone *icn = mipi_dsi_get_drvdata(dsi);
+
+ mipi_dsi_detach(dsi);
+ drm_bridge_remove(&icn->bridge);
+
+ return 0;
+}
+
+static const struct of_device_id chipone_of_match[] = {
+ { .compatible = "chipone,icn6211", .data = &icn6211_desc },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, chipone_of_match);
+
+static struct mipi_dsi_driver chipone_driver = {
+ .probe = chipone_probe,
+ .remove = chipone_remove,
+ .driver = {
+ .name = "chipone-icn6211",
+ .owner = THIS_MODULE,
+ .of_match_table = chipone_of_match,
+ },
+};
+module_mipi_dsi_driver(chipone_driver);
+
+MODULE_AUTHOR("Jagan Teki <jagan@amarulasolutions.com>");
+MODULE_DESCRIPTION("Chipone ICN6211 MIPI-DSI to RGB Convertor Bridge");
+MODULE_LICENSE("GPL v2");
ICN6211 is MIPI-DSI/RGB converter bridge from chipone. It has a flexible configuration of MIPI DSI signal input and produce RGB565, RGB666, RGB888 output format. Add bridge driver for it. Signed-off-by: Jagan Teki <jagan@amarulasolutions.com> --- Note: - drm_panel_bridge_add seems not working or incompatible as per driver setup. any inputs on this would be great. MAINTAINERS | 6 + drivers/gpu/drm/bridge/Kconfig | 10 + drivers/gpu/drm/bridge/Makefile | 1 + drivers/gpu/drm/bridge/chipone-icn6211.c | 344 +++++++++++++++++++++++ 4 files changed, 361 insertions(+) create mode 100644 drivers/gpu/drm/bridge/chipone-icn6211.c