diff options
Diffstat (limited to 'drivers/gpu/drm/bridge')
-rw-r--r-- | drivers/gpu/drm/bridge/Kconfig | 33 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/Makefile | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/analogix/Kconfig | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/analogix/analogix-anx6345.c | 27 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c | 27 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/analogix/anx7625.c | 34 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/analogix/anx7625.h | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/chipone-icn6211.c | 293 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/lontium-lt8912b.c | 768 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/lontium-lt9611.c | 8 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/lontium-lt9611uxc.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/panel.c | 12 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/tc358767.c | 20 | ||||
-rw-r--r-- | drivers/gpu/drm/bridge/ti-sn65dsi86.c | 18 |
16 files changed, 1222 insertions, 27 deletions
diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig index e4110d6ca7b3..400193e38d29 100644 --- a/drivers/gpu/drm/bridge/Kconfig +++ b/drivers/gpu/drm/bridge/Kconfig @@ -27,6 +27,19 @@ 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 OF + select DRM_MIPI_DSI + select DRM_PANEL_BRIDGE + 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. + + If in doubt, say "N". + config DRM_CHRONTEL_CH7033 tristate "Chrontel CH7033 Video Encoder" depends on OF @@ -42,18 +55,34 @@ config DRM_DISPLAY_CONNECTOR depends on OF help Driver for display connectors with support for DDC and hot-plug - detection. Most display controller handle display connectors + detection. Most display controllers handle display connectors internally and don't need this driver, but the DRM subsystem is moving towards separating connector handling from display controllers on ARM-based platforms. Saying Y here when this driver is not needed will not cause any issue. +config DRM_LONTIUM_LT8912B + tristate "Lontium LT8912B DSI/HDMI bridge" + depends on OF + select DRM_PANEL_BRIDGE + select DRM_KMS_HELPER + select DRM_MIPI_DSI + select REGMAP_I2C + help + Driver for Lontium LT8912B DSI to HDMI bridge + chip driver. + Please say Y if you have such hardware. + + Say M here if you want to support this hardware as a module. + The module will be named "lontium-lt8912b". + config DRM_LONTIUM_LT9611 tristate "Lontium LT9611 DSI/HDMI bridge" select SND_SOC_HDMI_CODEC if SND_SOC depends on OF select DRM_PANEL_BRIDGE select DRM_KMS_HELPER + select DRM_MIPI_DSI select REGMAP_I2C help Driver for Lontium LT9611 DSI to HDMI bridge @@ -67,6 +96,7 @@ config DRM_LONTIUM_LT9611UXC depends on OF select DRM_PANEL_BRIDGE select DRM_KMS_HELPER + select DRM_MIPI_DSI select REGMAP_I2C help Driver for Lontium LT9611UXC DSI to HDMI bridge @@ -183,6 +213,7 @@ config DRM_TOSHIBA_TC358762 tristate "TC358762 DSI/DPI bridge" depends on OF select DRM_MIPI_DSI + select DRM_KMS_HELPER select DRM_PANEL_BRIDGE help Toshiba TC358762 DSI/DPI bridge driver. diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile index 86e7acc76f8d..5c61b50c1663 100644 --- a/drivers/gpu/drm/bridge/Makefile +++ b/drivers/gpu/drm/bridge/Makefile @@ -1,7 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DRM_CDNS_DSI) += cdns-dsi.o +obj-$(CONFIG_DRM_CHIPONE_ICN6211) += chipone-icn6211.o obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o obj-$(CONFIG_DRM_DISPLAY_CONNECTOR) += display-connector.o +obj-$(CONFIG_DRM_LONTIUM_LT8912B) += lontium-lt8912b.o obj-$(CONFIG_DRM_LONTIUM_LT9611) += lontium-lt9611.o obj-$(CONFIG_DRM_LONTIUM_LT9611UXC) += lontium-lt9611uxc.o obj-$(CONFIG_DRM_LVDS_CODEC) += lvds-codec.o diff --git a/drivers/gpu/drm/bridge/analogix/Kconfig b/drivers/gpu/drm/bridge/analogix/Kconfig index 024ea2a570e7..9160fd80dd70 100644 --- a/drivers/gpu/drm/bridge/analogix/Kconfig +++ b/drivers/gpu/drm/bridge/analogix/Kconfig @@ -30,6 +30,7 @@ config DRM_ANALOGIX_ANX7625 tristate "Analogix Anx7625 MIPI to DP interface support" depends on DRM depends on OF + select DRM_MIPI_DSI help ANX7625 is an ultra-low power 4K mobile HD transmitter designed for portable devices. It converts MIPI/DPI to diff --git a/drivers/gpu/drm/bridge/analogix/analogix-anx6345.c b/drivers/gpu/drm/bridge/analogix/analogix-anx6345.c index d9164fab044d..aa6cda458eb9 100644 --- a/drivers/gpu/drm/bridge/analogix/analogix-anx6345.c +++ b/drivers/gpu/drm/bridge/analogix/analogix-anx6345.c @@ -550,28 +550,38 @@ static int anx6345_bridge_attach(struct drm_bridge *bridge, DRM_MODE_CONNECTOR_eDP); if (err) { DRM_ERROR("Failed to initialize connector: %d\n", err); - return err; + goto aux_unregister; } drm_connector_helper_add(&anx6345->connector, &anx6345_connector_helper_funcs); - err = drm_connector_register(&anx6345->connector); - if (err) { - DRM_ERROR("Failed to register connector: %d\n", err); - return err; - } - anx6345->connector.polled = DRM_CONNECTOR_POLL_HPD; err = drm_connector_attach_encoder(&anx6345->connector, bridge->encoder); if (err) { DRM_ERROR("Failed to link up connector to encoder: %d\n", err); - return err; + goto connector_cleanup; + } + + err = drm_connector_register(&anx6345->connector); + if (err) { + DRM_ERROR("Failed to register connector: %d\n", err); + goto connector_cleanup; } return 0; +connector_cleanup: + drm_connector_cleanup(&anx6345->connector); +aux_unregister: + drm_dp_aux_unregister(&anx6345->aux); + return err; +} + +static void anx6345_bridge_detach(struct drm_bridge *bridge) +{ + drm_dp_aux_unregister(&bridge_to_anx6345(bridge)->aux); } static enum drm_mode_status @@ -624,6 +634,7 @@ static void anx6345_bridge_enable(struct drm_bridge *bridge) static const struct drm_bridge_funcs anx6345_bridge_funcs = { .attach = anx6345_bridge_attach, + .detach = anx6345_bridge_detach, .mode_valid = anx6345_bridge_mode_valid, .disable = anx6345_bridge_disable, .enable = anx6345_bridge_enable, diff --git a/drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c b/drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c index 81debd02c169..f20558618220 100644 --- a/drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c +++ b/drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c @@ -918,28 +918,38 @@ static int anx78xx_bridge_attach(struct drm_bridge *bridge, DRM_MODE_CONNECTOR_DisplayPort); if (err) { DRM_ERROR("Failed to initialize connector: %d\n", err); - return err; + goto aux_unregister; } drm_connector_helper_add(&anx78xx->connector, &anx78xx_connector_helper_funcs); - err = drm_connector_register(&anx78xx->connector); - if (err) { - DRM_ERROR("Failed to register connector: %d\n", err); - return err; - } - anx78xx->connector.polled = DRM_CONNECTOR_POLL_HPD; err = drm_connector_attach_encoder(&anx78xx->connector, bridge->encoder); if (err) { DRM_ERROR("Failed to link up connector to encoder: %d\n", err); - return err; + goto connector_cleanup; + } + + err = drm_connector_register(&anx78xx->connector); + if (err) { + DRM_ERROR("Failed to register connector: %d\n", err); + goto connector_cleanup; } return 0; +connector_cleanup: + drm_connector_cleanup(&anx78xx->connector); +aux_unregister: + drm_dp_aux_unregister(&anx78xx->aux); + return err; +} + +static void anx78xx_bridge_detach(struct drm_bridge *bridge) +{ + drm_dp_aux_unregister(&bridge_to_anx78xx(bridge)->aux); } static enum drm_mode_status @@ -1013,6 +1023,7 @@ static void anx78xx_bridge_enable(struct drm_bridge *bridge) static const struct drm_bridge_funcs anx78xx_bridge_funcs = { .attach = anx78xx_bridge_attach, + .detach = anx78xx_bridge_detach, .mode_valid = anx78xx_bridge_mode_valid, .disable = anx78xx_bridge_disable, .mode_set = anx78xx_bridge_mode_set, diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c index aa1bb86293fd..f115233b1cb9 100644 --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c @@ -1782,6 +1782,7 @@ int analogix_dp_bind(struct analogix_dp_device *dp, struct drm_device *drm_dev) err_disable_pm_runtime: pm_runtime_disable(dp->dev); + drm_dp_aux_unregister(&dp->aux); return ret; } diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index 65cc05982f82..23283ba0c4f9 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -11,6 +11,7 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/mutex.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/types.h> #include <linux/workqueue.h> @@ -875,12 +876,25 @@ static int sp_tx_edid_read(struct anx7625_data *ctx, static void anx7625_power_on(struct anx7625_data *ctx) { struct device *dev = &ctx->client->dev; + int ret, i; if (!ctx->pdata.low_power_mode) { DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n"); return; } + for (i = 0; i < ARRAY_SIZE(ctx->pdata.supplies); i++) { + ret = regulator_enable(ctx->pdata.supplies[i].consumer); + if (ret < 0) { + DRM_DEV_DEBUG_DRIVER(dev, "cannot enable supply %d: %d\n", + i, ret); + goto reg_err; + } + usleep_range(2000, 2100); + } + + usleep_range(4000, 4100); + /* Power on pin enable */ gpiod_set_value(ctx->pdata.gpio_p_on, 1); usleep_range(10000, 11000); @@ -889,11 +903,16 @@ static void anx7625_power_on(struct anx7625_data *ctx) usleep_range(10000, 11000); DRM_DEV_DEBUG_DRIVER(dev, "power on !\n"); + return; +reg_err: + for (--i; i >= 0; i--) + regulator_disable(ctx->pdata.supplies[i].consumer); } static void anx7625_power_standby(struct anx7625_data *ctx) { struct device *dev = &ctx->client->dev; + int ret; if (!ctx->pdata.low_power_mode) { DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n"); @@ -904,6 +923,12 @@ static void anx7625_power_standby(struct anx7625_data *ctx) usleep_range(1000, 1100); gpiod_set_value(ctx->pdata.gpio_p_on, 0); usleep_range(1000, 1100); + + ret = regulator_bulk_disable(ARRAY_SIZE(ctx->pdata.supplies), + ctx->pdata.supplies); + if (ret < 0) + DRM_DEV_DEBUG_DRIVER(dev, "cannot disable supplies %d\n", ret); + DRM_DEV_DEBUG_DRIVER(dev, "power down\n"); } @@ -1742,6 +1767,15 @@ static int anx7625_i2c_probe(struct i2c_client *client, platform->client = client; i2c_set_clientdata(client, platform); + pdata->supplies[0].supply = "vdd10"; + pdata->supplies[1].supply = "vdd18"; + pdata->supplies[2].supply = "vdd33"; + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pdata->supplies), + pdata->supplies); + if (ret) { + DRM_DEV_ERROR(dev, "fail to get power supplies: %d\n", ret); + return ret; + } anx7625_init_gpio(platform); atomic_set(&platform->power_status, 0); diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h index 193ad86c5450..e4a086b3a3d7 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.h +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h @@ -350,6 +350,7 @@ struct s_edid_data { struct anx7625_platform_data { struct gpio_desc *gpio_p_on; struct gpio_desc *gpio_reset; + struct regulator_bulk_data supplies[3]; struct drm_bridge *panel_bridge; int intp_irq; u32 low_power_mode; diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c index d0c65610ebb5..989a05bc8197 100644 --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c @@ -2457,7 +2457,7 @@ clk_disable: static int cdns_mhdp_remove(struct platform_device *pdev) { - struct cdns_mhdp_device *mhdp = dev_get_drvdata(&pdev->dev); + struct cdns_mhdp_device *mhdp = platform_get_drvdata(pdev); unsigned long timeout = msecs_to_jiffies(100); bool stop_fw = false; int ret; diff --git a/drivers/gpu/drm/bridge/chipone-icn6211.c b/drivers/gpu/drm/bridge/chipone-icn6211.c new file mode 100644 index 000000000000..a6151db95586 --- /dev/null +++ b/drivers/gpu/drm/bridge/chipone-icn6211.c @@ -0,0 +1,293 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Amarula Solutions(India) + * Author: Jagan Teki <jagan@amarulasolutions.com> + */ + +#include <drm/drm_of.h> +#include <drm/drm_print.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/regulator/consumer.h> + +#include <video/mipi_display.h> + +#define HACTIVE_LI 0x20 +#define VACTIVE_LI 0x21 +#define VACTIVE_HACTIVE_HI 0x22 +#define HFP_LI 0x23 +#define HSYNC_LI 0x24 +#define HBP_LI 0x25 +#define HFP_HSW_HBP_HI 0x26 +#define VFP 0x27 +#define VSYNC 0x28 +#define VBP 0x29 + +struct chipone { + struct device *dev; + struct drm_bridge bridge; + struct drm_bridge *panel_bridge; + struct gpio_desc *enable_gpio; + struct regulator *vdd1; + struct regulator *vdd2; + struct regulator *vdd3; +}; + +static inline struct chipone *bridge_to_chipone(struct drm_bridge *bridge) +{ + return container_of(bridge, struct chipone, bridge); +} + +static struct drm_display_mode *bridge_to_mode(struct drm_bridge *bridge) +{ + return &bridge->encoder->crtc->state->adjusted_mode; +} + +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 ICN6211_DSI(icn, seq...) \ + { \ + const u8 d[] = { seq }; \ + chipone_dsi_write(icn, d, ARRAY_SIZE(d)); \ + } + +static void chipone_enable(struct drm_bridge *bridge) +{ + struct chipone *icn = bridge_to_chipone(bridge); + struct drm_display_mode *mode = bridge_to_mode(bridge); + + ICN6211_DSI(icn, 0x7a, 0xc1); + + ICN6211_DSI(icn, HACTIVE_LI, mode->hdisplay & 0xff); + + ICN6211_DSI(icn, VACTIVE_LI, mode->vdisplay & 0xff); + + /** + * lsb nibble: 2nd nibble of hdisplay + * msb nibble: 2nd nibble of vdisplay + */ + ICN6211_DSI(icn, VACTIVE_HACTIVE_HI, + ((mode->hdisplay >> 8) & 0xf) | + (((mode->vdisplay >> 8) & 0xf) << 4)); + + ICN6211_DSI(icn, HFP_LI, mode->hsync_start - mode->hdisplay); + + ICN6211_DSI(icn, HSYNC_LI, mode->hsync_end - mode->hsync_start); + + ICN6211_DSI(icn, HBP_LI, mode->htotal - mode->hsync_end); + + ICN6211_DSI(icn, HFP_HSW_HBP_HI, 0x00); + + ICN6211_DSI(icn, VFP, mode->vsync_start - mode->vdisplay); + + ICN6211_DSI(icn, VSYNC, mode->vsync_end - mode->vsync_start); + + ICN6211_DSI(icn, VBP, mode->vtotal - mode->vsync_end); + + /* dsi specific sequence */ + ICN6211_DSI(icn, MIPI_DCS_SET_TEAR_OFF, 0x80); + ICN6211_DSI(icn, MIPI_DCS_SET_ADDRESS_MODE, 0x28); + ICN6211_DSI(icn, 0xb5, 0xa0); + ICN6211_DSI(icn, 0x5c, 0xff); + ICN6211_DSI(icn, MIPI_DCS_SET_COLUMN_ADDRESS, 0x01); + ICN6211_DSI(icn, MIPI_DCS_GET_POWER_SAVE, 0x92); + ICN6211_DSI(icn, 0x6b, 0x71); + ICN6211_DSI(icn, 0x69, 0x2b); + ICN6211_DSI(icn, MIPI_DCS_ENTER_SLEEP_MODE, 0x40); + ICN6211_DSI(icn, MIPI_DCS_EXIT_SLEEP_MODE, 0x98); + + /* icn6211 specific sequence */ + ICN6211_DSI(icn, 0xb6, 0x20); + ICN6211_DSI(icn, 0x51, 0x20); + ICN6211_DSI(icn, 0x09, 0x10); + + usleep_range(10000, 11000); +} + +static void chipone_pre_enable(struct drm_bridge *bridge) +{ + struct chipone *icn = bridge_to_chipone(bridge); + int ret; + + if (icn->vdd1) { + ret = regulator_enable(icn->vdd1); + if (ret) + DRM_DEV_ERROR(icn->dev, + "failed to enable VDD1 regulator: %d\n", ret); + } + + if (icn->vdd2) { + ret = regulator_enable(icn->vdd2); + if (ret) + DRM_DEV_ERROR(icn->dev, + "failed to enable VDD2 regulator: %d\n", ret); + } + + if (icn->vdd3) { + ret = regulator_enable(icn->vdd3); + if (ret) + DRM_DEV_ERROR(icn->dev, + "failed to enable VDD3 regulator: %d\n", ret); + } + + gpiod_set_value(icn->enable_gpio, 1); + + usleep_range(10000, 11000); +} + +static void chipone_post_disable(struct drm_bridge *bridge) +{ + struct chipone *icn = bridge_to_chipone(bridge); + + if (icn->vdd1) + regulator_disable(icn->vdd1); + + if (icn->vdd2) + regulator_disable(icn->vdd2); + + if (icn->vdd3) + regulator_disable(icn->vdd3); + + gpiod_set_value(icn->enable_gpio, 0); +} + +static int chipone_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) +{ + struct chipone *icn = bridge_to_chipone(bridge); + + return drm_bridge_attach(bridge->encoder, icn->panel_bridge, bridge, flags); +} + +static const struct drm_bridge_funcs chipone_bridge_funcs = { + .attach = chipone_attach, + .post_disable = chipone_post_disable, + .pre_enable = chipone_pre_enable, + .enable = chipone_enable, +}; + +static int chipone_parse_dt(struct chipone *icn) +{ + struct device *dev = icn->dev; + struct drm_panel *panel; + int ret; + + icn->vdd1 = devm_regulator_get_optional(dev, "vdd1"); + if (IS_ERR(icn->vdd1)) { + ret = PTR_ERR(icn->vdd1); + if (ret == -EPROBE_DEFER) + return -EPROBE_DEFER; + icn->vdd1 = NULL; + DRM_DEV_DEBUG(dev, "failed to get VDD1 regulator: %d\n", ret); + } + + icn->vdd2 = devm_regulator_get_optional(dev, "vdd2"); + if (IS_ERR(icn->vdd2)) { + ret = PTR_ERR(icn->vdd2); + if (ret == -EPROBE_DEFER) + return -EPROBE_DEFER; + icn->vdd2 = NULL; + DRM_DEV_DEBUG(dev, "failed to get VDD2 regulator: %d\n", ret); + } + + icn->vdd3 = devm_regulator_get_optional(dev, "vdd3"); + if (IS_ERR(icn->vdd3)) { + ret = PTR_ERR(icn->vdd3); + if (ret == -EPROBE_DEFER) + return -EPROBE_DEFER; + icn->vdd3 = NULL; + DRM_DEV_DEBUG(dev, "failed to get VDD3 regulator: %d\n", ret); + } + + icn->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); + if (IS_ERR(icn->enable_gpio)) { + DRM_DEV_ERROR(dev, "failed to get enable GPIO\n"); + return PTR_ERR(icn->enable_gpio); + } + + ret = drm_of_find_panel_or_bridge(dev->of_node, 1, 0, &panel, NULL); + if (ret) + return ret; + + icn->panel_bridge = devm_drm_panel_bridge_add(dev, panel); + if (IS_ERR(icn->panel_bridge)) + return PTR_ERR(icn->panel_bridge); + + return 0; +} + +static int chipone_probe(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + struct chipone *icn; + int ret; + + icn = devm_kzalloc(dev, sizeof(struct chipone), GFP_KERNEL); + if (!icn) + return -ENOMEM; + + mipi_dsi_set_drvdata(dsi, icn); + icn->dev = dev; + + ret = chipone_parse_dt(icn); + if (ret) + return ret; + + icn->bridge.funcs = &chipone_bridge_funcs; + icn->bridge.type = DRM_MODE_CONNECTOR_DPI; + icn->bridge.of_node = dev->of_node; + + drm_bridge_add(&icn->bridge); + + dsi->lanes = 4; + dsi->format = MIPI_DSI_FMT_RGB888; + dsi->mode_flags = MIPI_DSI_MODE_VIDEO_SYNC_PULSE; + + ret = mipi_dsi_attach(dsi); + if (ret < 0) { + drm_bridge_remove(&icn->bridge); + dev_err(dev, "failed to attach dsi\n"); + } + + return ret; +} + +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", }, + { /* 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 Converter Bridge"); +MODULE_LICENSE("GPL"); diff --git a/drivers/gpu/drm/bridge/lontium-lt8912b.c b/drivers/gpu/drm/bridge/lontium-lt8912b.c new file mode 100644 index 000000000000..443f1b47e031 --- /dev/null +++ b/drivers/gpu/drm/bridge/lontium-lt8912b.c @@ -0,0 +1,768 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2018, The Linux Foundation. All rights reserved. + */ + +#include <linux/device.h> +#include <linux/delay.h> +#include <linux/gpio/consumer.h> +#include <linux/i2c.h> +#include <linux/gpio.h> +#include <linux/of_gpio.h> +#include <linux/regmap.h> + +#include <drm/drm_probe_helper.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_mipi_dsi.h> +#include <drm/drm_of.h> + +#include <video/videomode.h> + +#define I2C_MAIN 0 +#define I2C_ADDR_MAIN 0x48 + +#define I2C_CEC_DSI 1 +#define I2C_ADDR_CEC_DSI 0x49 + +#define I2C_MAX_IDX 2 + +struct lt8912 { + struct device *dev; + struct drm_bridge bridge; + struct drm_connector connector; + + struct i2c_client *i2c_client[I2C_MAX_IDX]; + struct regmap *regmap[I2C_MAX_IDX]; + + struct device_node *host_node; + struct drm_bridge *hdmi_port; + + struct mipi_dsi_device *dsi; + + struct gpio_desc *gp_reset; + + struct videomode mode; + + u8 data_lanes; + bool is_power_on; + bool is_attached; +}; + +static int lt8912_write_init_config(struct lt8912 *lt) +{ + const struct reg_sequence seq[] = { + /* Digital clock en*/ + {0x08, 0xff}, + {0x09, 0xff}, + {0x0a, 0xff}, + {0x0b, 0x7c}, + {0x0c, 0xff}, + {0x42, 0x04}, + + /*Tx Analog*/ + {0x31, 0xb1}, + {0x32, 0xb1}, + {0x33, 0x0e}, + {0x37, 0x00}, + {0x38, 0x22}, + {0x60, 0x82}, + + /*Cbus Analog*/ + {0x39, 0x45}, + {0x3a, 0x00}, + {0x3b, 0x00}, + + /*HDMI Pll Analog*/ + {0x44, 0x31}, + {0x55, 0x44}, + {0x57, 0x01}, + {0x5a, 0x02}, + + /*MIPI Analog*/ + {0x3e, 0xd6}, + {0x3f, 0xd4}, + {0x41, 0x3c}, + {0xB2, 0x00}, + }; + + return regmap_multi_reg_write(lt->regmap[I2C_MAIN], seq, ARRAY_SIZE(seq)); +} + +static int lt8912_write_mipi_basic_config(struct lt8912 *lt) +{ + const struct reg_sequence seq[] = { + {0x12, 0x04}, + {0x14, 0x00}, + {0x15, 0x00}, + {0x1a, 0x03}, + {0x1b, 0x03}, + }; + + return regmap_multi_reg_write(lt->regmap[I2C_CEC_DSI], seq, ARRAY_SIZE(seq)); +}; + +static int lt8912_write_dds_config(struct lt8912 *lt) +{ + const struct reg_sequence seq[] = { + {0x4e, 0xff}, + {0x4f, 0x56}, + {0x50, 0x69}, + {0x51, 0x80}, + {0x1f, 0x5e}, + {0x20, 0x01}, + {0x21, 0x2c}, + {0x22, 0x01}, + {0x23, 0xfa}, + {0x24, 0x00}, + {0x25, 0xc8}, + {0x26, 0x00}, + {0x27, 0x5e}, + {0x28, 0x01}, + {0x29, 0x2c}, + {0x2a, 0x01}, + {0x2b, 0xfa}, + {0x2c, 0x00}, + {0x2d, 0xc8}, + {0x2e, 0x00}, + {0x42, 0x64}, + {0x43, 0x00}, + {0x44, 0x04}, + {0x45, 0x00}, + {0x46, 0x59}, + {0x47, 0x00}, + {0x48, 0xf2}, + {0x49, 0x06}, + {0x4a, 0x00}, + {0x4b, 0x72}, + {0x4c, 0x45}, + {0x4d, 0x00}, + {0x52, 0x08}, + {0x53, 0x00}, + {0x54, 0xb2}, + {0x55, 0x00}, + {0x56, 0xe4}, + {0x57, 0x0d}, + {0x58, 0x00}, + {0x59, 0xe4}, + {0x5a, 0x8a}, + {0x5b, 0x00}, + {0x5c, 0x34}, + {0x1e, 0x4f}, + {0x51, 0x00}, + }; + + return regmap_multi_reg_write(lt->regmap[I2C_CEC_DSI], seq, ARRAY_SIZE(seq)); +} + +static int lt8912_write_rxlogicres_config(struct lt8912 *lt) +{ + int ret; + + ret = regmap_write(lt->regmap[I2C_MAIN], 0x03, 0x7f); + usleep_range(10000, 20000); + ret |= regmap_write(lt->regmap[I2C_MAIN], 0x03, 0xff); + + return ret; +}; + +static int lt8912_write_lvds_config(struct lt8912 *lt) +{ + const struct reg_sequence seq[] = { + {0x44, 0x30}, + {0x51, 0x05}, + {0x50, 0x24}, + {0x51, 0x2d}, + {0x52, 0x04}, + {0x69, 0x0e}, + {0x69, 0x8e}, + {0x6a, 0x00}, + {0x6c, 0xb8}, + {0x6b, 0x51}, + {0x04, 0xfb}, + {0x04, 0xff}, + {0x7f, 0x00}, + {0xa8, 0x13}, + {0x02, 0xf7}, + {0x02, 0xff}, + {0x03, 0xcf}, + {0x03, 0xff}, + }; + + return regmap_multi_reg_write(lt->regmap[I2C_CEC_DSI], seq, ARRAY_SIZE(seq)); +}; + +static inline struct lt8912 *bridge_to_lt8912(struct drm_bridge *b) +{ + return container_of(b, struct lt8912, bridge); +} + +static inline struct lt8912 *connector_to_lt8912(struct drm_connector *c) +{ + return container_of(c, struct lt8912, connector); +} + +static const struct regmap_config lt8912_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0xff, +}; + +static int lt8912_init_i2c(struct lt8912 *lt, struct i2c_client *client) +{ + unsigned int i; + /* + * At this time we only initialize 2 chips, but the lt8912 provides + * a third interface for the audio over HDMI configuration. + */ + struct i2c_board_info info[] = { + { I2C_BOARD_INFO("lt8912p0", I2C_ADDR_MAIN), }, + { I2C_BOARD_INFO("lt8912p1", I2C_ADDR_CEC_DSI), }, + }; + + if (!lt) + return -ENODEV; + + for (i = 0; i < ARRAY_SIZE(info); i++) { + if (i > 0) { + lt->i2c_client[i] = i2c_new_dummy_device(client->adapter, + info[i].addr); + if (IS_ERR(lt->i2c_client[i])) + return PTR_ERR(lt->i2c_client[i]); + } + + lt->regmap[i] = devm_regmap_init_i2c(lt->i2c_client[i], + <8912_regmap_config); + if (IS_ERR(lt->regmap[i])) + return PTR_ERR(lt->regmap[i]); + } + return 0; +} + +static int lt8912_free_i2c(struct lt8912 *lt) +{ + unsigned int i; + + for (i = 1; i < I2C_MAX_IDX; i++) + i2c_unregister_device(lt->i2c_client[i]); + + return 0; +} + +static int lt8912_hard_power_on(struct lt8912 *lt) +{ + gpiod_set_value_cansleep(lt->gp_reset, 0); + msleep(20); + + return 0; +} + +static void lt8912_hard_power_off(struct lt8912 *lt) +{ + gpiod_set_value_cansleep(lt->gp_reset, 1); + msleep(20); + lt->is_power_on = false; +} + +static int lt8912_video_setup(struct lt8912 *lt) +{ + u32 hactive, h_total, hpw, hfp, hbp; + u32 vactive, v_total, vpw, vfp, vbp; + u8 settle = 0x08; + int ret; + + if (!lt) + return -EINVAL; + + hactive = lt->mode.hactive; + hfp = lt->mode.hfront_porch; + hpw = lt->mode.hsync_len; + hbp = lt->mode.hback_porch; + h_total = hactive + hfp + hpw + hbp; + + vactive = lt->mode.vactive; + vfp = lt->mode.vfront_porch; + vpw = lt->mode.vsync_len; + vbp = lt->mode.vback_porch; + v_total = vactive + vfp + vpw + vbp; + + if (vactive <= 600) + settle = 0x04; + else if (vactive == 1080) + settle = 0x0a; + + ret = regmap_write(lt->regmap[I2C_CEC_DSI], 0x10, 0x01); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x11, settle); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x18, hpw); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x19, vpw); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x1c, hactive & 0xff); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x1d, hactive >> 8); + + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x2f, 0x0c); + + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x34, h_total & 0xff); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x35, h_total >> 8); + + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x36, v_total & 0xff); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x37, v_total >> 8); + + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x38, vbp & 0xff); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x39, vbp >> 8); + + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3a, vfp & 0xff); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3b, vfp >> 8); + + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3c, hbp & 0xff); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3d, hbp >> 8); + + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3e, hfp & 0xff); + ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3f, hfp >> 8); + + return ret; +} + +static int lt8912_soft_power_on(struct lt8912 *lt) +{ + if (!lt->is_power_on) { + u32 lanes = lt->data_lanes; + + lt8912_write_init_config(lt); + regmap_write(lt->regmap[I2C_CEC_DSI], 0x13, lanes & 3); + + lt8912_write_mipi_basic_config(lt); + + lt->is_power_on = true; + } + + return 0; +} + +static int lt8912_video_on(struct lt8912 *lt) +{ + int ret; + + ret = lt8912_video_setup(lt); + if (ret < 0) + goto end; + + ret = lt8912_write_dds_config(lt); + if (ret < 0) + goto end; + + ret = lt8912_write_rxlogicres_config(lt); + if (ret < 0) + goto end; + + ret = lt8912_write_lvds_config(lt); + if (ret < 0) + goto end; + +end: + return ret; +} + +static enum drm_connector_status lt8912_check_cable_status(struct lt8912 *lt) +{ + int ret; + unsigned int reg_val; + + ret = regmap_read(lt->regmap[I2C_MAIN], 0xC1, ®_val); + if (ret) + return connector_status_unknown; + + if (reg_val & BIT(7)) + return connector_status_connected; + + return connector_status_disconnected; +} + +static enum drm_connector_status +lt8912_connector_detect(struct drm_connector *connector, bool force) +{ + struct lt8912 *lt = connector_to_lt8912(connector); + + if (lt->hdmi_port->ops & DRM_BRIDGE_OP_DETECT) + return drm_bridge_detect(lt->hdmi_port); + + return lt8912_check_cable_status(lt); +} + +static const struct drm_connector_funcs lt8912_connector_funcs = { + .detect = lt8912_connector_detect, + .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 enum drm_mode_status +lt8912_connector_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) +{ + if (mode->clock > 150000) + return MODE_CLOCK_HIGH; + + if (mode->hdisplay > 1920) + return MODE_BAD_HVALUE; + + if (mode->vdisplay > 1080) + return MODE_BAD_VVALUE; + + return MODE_OK; +} + +static int lt8912_connector_get_modes(struct drm_connector *connector) +{ + struct edid *edid; + int ret = -1; + int num = 0; + struct lt8912 *lt = connector_to_lt8912(connector); + u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24; + + edid = drm_bridge_get_edid(lt->hdmi_port, connector); + if (edid) { + drm_connector_update_edid_property(connector, edid); + num = drm_add_edid_modes(connector, edid); + } else { + return ret; + } + + ret = drm_display_info_set_bus_formats(&connector->display_info, + &bus_format, 1); + if (ret) + num = ret; + + kfree(edid); + return num; +} + +static const struct drm_connector_helper_funcs lt8912_connector_helper_funcs = { + .get_modes = lt8912_connector_get_modes, + .mode_valid = lt8912_connector_mode_valid, +}; + +static void lt8912_bridge_mode_set(struct drm_bridge *bridge, + const struct drm_display_mode *mode, + const struct drm_display_mode *adj) +{ + struct lt8912 *lt = bridge_to_lt8912(bridge); + + drm_display_mode_to_videomode(adj, <->mode); +} + +static void lt8912_bridge_enable(struct drm_bridge *bridge) +{ + struct lt8912 *lt = bridge_to_lt8912(bridge); + + lt8912_video_on(lt); +} + +static int lt8912_attach_dsi(struct lt8912 *lt) +{ + struct device *dev = lt->dev; + struct mipi_dsi_host *host; + struct mipi_dsi_device *dsi; + int ret = -1; + const struct mipi_dsi_device_info info = { .type = "lt8912", + .channel = 0, + .node = NULL, + }; + + host = of_find_mipi_dsi_host_by_node(lt->host_node); + if (!host) { + dev_err(dev, "failed to find dsi host\n"); + return -EPROBE_DEFER; + } + + dsi = mipi_dsi_device_register_full(host, &info); + if (IS_ERR(dsi)) { + ret = PTR_ERR(dsi); + dev_err(dev, "failed to create dsi device (%d)\n", ret); + goto err_dsi_device; + } + + lt->dsi = dsi; + + dsi->lanes = lt->data_lanes; + dsi->format = MIPI_DSI_FMT_RGB888; + + dsi->mode_flags = MIPI_DSI_MODE_VIDEO | + MIPI_DSI_MODE_VIDEO_BURST | + MIPI_DSI_MODE_LPM | + MIPI_DSI_MODE_EOT_PACKET; + + ret = mipi_dsi_attach(dsi); + if (ret < 0) { + dev_err(dev, "failed to attach dsi to host\n"); + goto err_dsi_attach; + } + + return 0; + +err_dsi_attach: + mipi_dsi_device_unregister(dsi); +err_dsi_device: + return ret; +} + +static void lt8912_detach_dsi(struct lt8912 *lt) +{ + mipi_dsi_detach(lt->dsi); + mipi_dsi_device_unregister(lt->dsi); +} + +static int lt8912_bridge_connector_init(struct drm_bridge *bridge) +{ + int ret; + struct lt8912 *lt = bridge_to_lt8912(bridge); + struct drm_connector *connector = <->connector; + + connector->polled = DRM_CONNECTOR_POLL_CONNECT | + DRM_CONNECTOR_POLL_DISCONNECT; + + ret = drm_connector_init(bridge->dev, connector, + <8912_connector_funcs, + lt->hdmi_port->type); + if (ret) + goto exit; + + drm_connector_helper_add(connector, <8912_connector_helper_funcs); + + connector->dpms = DRM_MODE_DPMS_OFF; + drm_connector_attach_encoder(connector, bridge->encoder); + +exit: + return ret; +} + +static int lt8912_bridge_attach(struct drm_bridge *bridge, + enum drm_bridge_attach_flags flags) +{ + struct lt8912 *lt = bridge_to_lt8912(bridge); + int ret; + + if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) { + ret = lt8912_bridge_connector_init(bridge); + if (ret) { + dev_err(lt->dev, "Failed to init bridge ! (%d)\n", ret); + return ret; + } + } + + ret = lt8912_hard_power_on(lt); + if (ret) + return ret; + + ret = lt8912_soft_power_on(lt); + if (ret) + goto error; + + ret = lt8912_attach_dsi(lt); + if (ret) + goto error; + + lt->is_attached = true; + + return 0; + +error: + lt8912_hard_power_off(lt); + return ret; +} + +static void lt8912_bridge_detach(struct drm_bridge *bridge) +{ + struct lt8912 *lt = bridge_to_lt8912(bridge); + + if (lt->is_attached) { + lt8912_detach_dsi(lt); + lt8912_hard_power_off(lt); + drm_connector_unregister(<->connector); + drm_connector_cleanup(<->connector); + } +} + +static enum drm_connector_status +lt8912_bridge_detect(struct drm_bridge *bridge) +{ + struct lt8912 *lt = bridge_to_lt8912(bridge); + + if (lt->hdmi_port->ops & DRM_BRIDGE_OP_DETECT) + return drm_bridge_detect(lt->hdmi_port); + + return lt8912_check_cable_status(lt); +} + +static struct edid *lt8912_bridge_get_edid(struct drm_bridge *bridge, + struct drm_connector *connector) +{ + struct lt8912 *lt = bridge_to_lt8912(bridge); + + /* + * edid must be read through the ddc bus but it must be + * given to the hdmi connector node. + */ + if (lt->hdmi_port->ops & DRM_BRIDGE_OP_EDID) + return drm_bridge_get_edid(lt->hdmi_port, connector); + + dev_warn(lt->dev, "The connected bridge does not supports DRM_BRIDGE_OP_EDID\n"); + return NULL; +} + +static const struct drm_bridge_funcs lt8912_bridge_funcs = { + .attach = lt8912_bridge_attach, + .detach = lt8912_bridge_detach, + .mode_set = lt8912_bridge_mode_set, + .enable = lt8912_bridge_enable, + .detect = lt8912_bridge_detect, + .get_edid = lt8912_bridge_get_edid, +}; + +static int lt8912_parse_dt(struct lt8912 *lt) +{ + struct gpio_desc *gp_reset; + struct device *dev = lt->dev; + int ret; + int data_lanes; + struct device_node *port_node; + struct device_node *endpoint; + + gp_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(gp_reset)) { + ret = PTR_ERR(gp_reset); + if (ret != -EPROBE_DEFER) + dev_err(dev, "Failed to get reset gpio: %d\n", ret); + return ret; + } + lt->gp_reset = gp_reset; + + endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1); + if (!endpoint) + return -ENODEV; + + data_lanes = of_property_count_u32_elems(endpoint, "data-lanes"); + of_node_put(endpoint); + if (data_lanes < 0) { + dev_err(lt->dev, "%s: Bad data-lanes property\n", __func__); + return data_lanes; + } + lt->data_lanes = data_lanes; + + lt->host_node = of_graph_get_remote_node(dev->of_node, 0, -1); + if (!lt->host_node) { + dev_err(lt->dev, "%s: Failed to get remote port\n", __func__); + return -ENODEV; + } + + port_node = of_graph_get_remote_node(dev->of_node, 1, -1); + if (!port_node) { + dev_err(lt->dev, "%s: Failed to get connector port\n", __func__); + ret = -ENODEV; + goto err_free_host_node; + } + + lt->hdmi_port = of_drm_find_bridge(port_node); + if (!lt->hdmi_port) { + dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__); + ret = -ENODEV; + goto err_free_host_node; + } + + if (!of_device_is_compatible(port_node, "hdmi-connector")) { + dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__); + ret = -EINVAL; + goto err_free_host_node; + } + + of_node_put(port_node); + return 0; + +err_free_host_node: + of_node_put(port_node); + of_node_put(lt->host_node); + return ret; +} + +static int lt8912_put_dt(struct lt8912 *lt) +{ + of_node_put(lt->host_node); + return 0; +} + +static int lt8912_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + static struct lt8912 *lt; + int ret = 0; + struct device *dev = &client->dev; + + lt = devm_kzalloc(dev, sizeof(struct lt8912), GFP_KERNEL); + if (!lt) + return -ENOMEM; + + lt->dev = dev; + lt->i2c_client[0] = client; + + ret = lt8912_parse_dt(lt); + if (ret) + goto err_dt_parse; + + ret = lt8912_init_i2c(lt, client); + if (ret) + goto err_i2c; + + i2c_set_clientdata(client, lt); + + lt->bridge.funcs = <8912_bridge_funcs; + lt->bridge.of_node = dev->of_node; + lt->bridge.ops = (DRM_BRIDGE_OP_EDID | + DRM_BRIDGE_OP_DETECT); + + drm_bridge_add(<->bridge); + + return 0; + +err_i2c: + lt8912_put_dt(lt); +err_dt_parse: + return ret; +} + +static int lt8912_remove(struct i2c_client *client) +{ + struct lt8912 *lt = i2c_get_clientdata(client); + + lt8912_bridge_detach(<->bridge); + drm_bridge_remove(<->bridge); + lt8912_free_i2c(lt); + lt8912_put_dt(lt); + return 0; +} + +static const struct of_device_id lt8912_dt_match[] = { + {.compatible = "lontium,lt8912b"}, + {} +}; +MODULE_DEVICE_TABLE(of, lt8912_dt_match); + +static const struct i2c_device_id lt8912_id[] = { + {"lt8912", 0}, + {}, +}; +MODULE_DEVICE_TABLE(i2c, lt8912_id); + +static struct i2c_driver lt8912_i2c_driver = { + .driver = { + .name = "lt8912", + .of_match_table = lt8912_dt_match, + .owner = THIS_MODULE, + }, + .probe = lt8912_probe, + .remove = lt8912_remove, + .id_table = lt8912_id, +}; +module_i2c_driver(lt8912_i2c_driver); + +MODULE_AUTHOR("Adrien Grassein <adrien.grassein@gmail.com>"); +MODULE_DESCRIPTION("lt8912 drm driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/gpu/drm/bridge/lontium-lt9611.c b/drivers/gpu/drm/bridge/lontium-lt9611.c index d734d9402c35..e8eb8deb444b 100644 --- a/drivers/gpu/drm/bridge/lontium-lt9611.c +++ b/drivers/gpu/drm/bridge/lontium-lt9611.c @@ -867,8 +867,14 @@ static enum drm_mode_status lt9611_bridge_mode_valid(struct drm_bridge *bridge, const struct drm_display_mode *mode) { struct lt9611_mode *lt9611_mode = lt9611_find_mode(mode); + struct lt9611 *lt9611 = bridge_to_lt9611(bridge); - return lt9611_mode ? MODE_OK : MODE_BAD; + if (!lt9611_mode) + return MODE_BAD; + else if (lt9611_mode->intfs > 1 && !lt9611->dsi1) + return MODE_PANEL; + else + return MODE_OK; } static void lt9611_bridge_pre_enable(struct drm_bridge *bridge) diff --git a/drivers/gpu/drm/bridge/lontium-lt9611uxc.c b/drivers/gpu/drm/bridge/lontium-lt9611uxc.c index fee27952ec6d..3cac16db970f 100644 --- a/drivers/gpu/drm/bridge/lontium-lt9611uxc.c +++ b/drivers/gpu/drm/bridge/lontium-lt9611uxc.c @@ -855,7 +855,7 @@ static ssize_t lt9611uxc_firmware_show(struct device *dev, struct device_attribu { struct lt9611uxc *lt9611uxc = dev_get_drvdata(dev); - return snprintf(buf, PAGE_SIZE, "%02x\n", lt9611uxc->fw_version); + return sysfs_emit(buf, "%02x\n", lt9611uxc->fw_version); } static DEVICE_ATTR_RW(lt9611uxc_firmware); diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c index 0ddc37551194..c916f4b8907e 100644 --- a/drivers/gpu/drm/bridge/panel.c +++ b/drivers/gpu/drm/bridge/panel.c @@ -87,6 +87,18 @@ static int panel_bridge_attach(struct drm_bridge *bridge, static void panel_bridge_detach(struct drm_bridge *bridge) { + struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); + struct drm_connector *connector = &panel_bridge->connector; + + /* + * Cleanup the connector if we know it was initialized. + * + * FIXME: This wouldn't be needed if the panel_bridge structure was + * allocated with drmm_kzalloc(). This might be tricky since the + * drm_device pointer can only be retrieved when the bridge is attached. + */ + if (connector->dev) + drm_connector_cleanup(connector); } static void panel_bridge_pre_enable(struct drm_bridge *bridge) diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c index 34a3e4e9f717..da89922721ed 100644 --- a/drivers/gpu/drm/bridge/tc358767.c +++ b/drivers/gpu/drm/bridge/tc358767.c @@ -1414,11 +1414,15 @@ static int tc_bridge_attach(struct drm_bridge *bridge, if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) return 0; + ret = drm_dp_aux_register(&tc->aux); + if (ret < 0) + return ret; + /* Create DP/eDP connector */ drm_connector_helper_add(&tc->connector, &tc_connector_helper_funcs); ret = drm_connector_init(drm, &tc->connector, &tc_connector_funcs, tc->bridge.type); if (ret) - return ret; + goto aux_unregister; /* Don't poll if don't have HPD connected */ if (tc->hpd_pin >= 0) { @@ -1438,10 +1442,19 @@ static int tc_bridge_attach(struct drm_bridge *bridge, drm_connector_attach_encoder(&tc->connector, tc->bridge.encoder); return 0; +aux_unregister: + drm_dp_aux_unregister(&tc->aux); + return ret; +} + +static void tc_bridge_detach(struct drm_bridge *bridge) +{ + drm_dp_aux_unregister(&bridge_to_tc(bridge)->aux); } static const struct drm_bridge_funcs tc_bridge_funcs = { .attach = tc_bridge_attach, + .detach = tc_bridge_detach, .mode_valid = tc_mode_valid, .mode_set = tc_bridge_mode_set, .enable = tc_bridge_enable, @@ -1680,9 +1693,7 @@ static int tc_probe(struct i2c_client *client, const struct i2c_device_id *id) tc->aux.name = "TC358767 AUX i2c adapter"; tc->aux.dev = tc->dev; tc->aux.transfer = tc_aux_transfer; - ret = drm_dp_aux_register(&tc->aux); - if (ret) - return ret; + drm_dp_aux_init(&tc->aux); tc->bridge.funcs = &tc_bridge_funcs; if (tc->hpd_pin >= 0) @@ -1702,7 +1713,6 @@ static int tc_remove(struct i2c_client *client) struct tc_data *tc = i2c_get_clientdata(client); drm_bridge_remove(&tc->bridge); - drm_dp_aux_unregister(&tc->aux); return 0; } diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c index f27306c51e4d..88df4dd0f39d 100644 --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c @@ -362,12 +362,18 @@ static int ti_sn_bridge_attach(struct drm_bridge *bridge, return -EINVAL; } + ret = drm_dp_aux_register(&pdata->aux); + if (ret < 0) { + drm_err(bridge->dev, "Failed to register DP AUX channel: %d\n", ret); + return ret; + } + ret = drm_connector_init(bridge->dev, &pdata->connector, &ti_sn_bridge_connector_funcs, DRM_MODE_CONNECTOR_eDP); if (ret) { DRM_ERROR("Failed to initialize connector with drm\n"); - return ret; + goto err_conn_init; } drm_connector_helper_add(&pdata->connector, @@ -424,9 +430,16 @@ err_dsi_attach: mipi_dsi_device_unregister(dsi); err_dsi_host: drm_connector_cleanup(&pdata->connector); +err_conn_init: + drm_dp_aux_unregister(&pdata->aux); return ret; } +static void ti_sn_bridge_detach(struct drm_bridge *bridge) +{ + drm_dp_aux_unregister(&bridge_to_ti_sn_bridge(bridge)->aux); +} + static void ti_sn_bridge_disable(struct drm_bridge *bridge) { struct ti_sn_bridge *pdata = bridge_to_ti_sn_bridge(bridge); @@ -863,6 +876,7 @@ static void ti_sn_bridge_post_disable(struct drm_bridge *bridge) static const struct drm_bridge_funcs ti_sn_bridge_funcs = { .attach = ti_sn_bridge_attach, + .detach = ti_sn_bridge_detach, .pre_enable = ti_sn_bridge_pre_enable, .enable = ti_sn_bridge_enable, .disable = ti_sn_bridge_disable, @@ -1287,7 +1301,7 @@ static int ti_sn_bridge_probe(struct i2c_client *client, pdata->aux.name = "ti-sn65dsi86-aux"; pdata->aux.dev = pdata->dev; pdata->aux.transfer = ti_sn_aux_transfer; - drm_dp_aux_register(&pdata->aux); + drm_dp_aux_init(&pdata->aux); pdata->bridge.funcs = &ti_sn_bridge_funcs; pdata->bridge.of_node = client->dev.of_node; |