^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2017 Broadcom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <drm/drm_atomic_helper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <drm/drm_bridge.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <drm/drm_connector.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <drm/drm_encoder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <drm/drm_modeset_helper_vtables.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <drm/drm_panel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <drm/drm_print.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <drm/drm_probe_helper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct panel_bridge {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct drm_bridge bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct drm_connector connector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct drm_panel *panel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) u32 connector_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static inline struct panel_bridge *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) drm_bridge_to_panel_bridge(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return container_of(bridge, struct panel_bridge, bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static inline struct panel_bridge *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) drm_connector_to_panel_bridge(struct drm_connector *connector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return container_of(connector, struct panel_bridge, connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int panel_bridge_connector_get_modes(struct drm_connector *connector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct panel_bridge *panel_bridge =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) drm_connector_to_panel_bridge(connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return drm_panel_get_modes(panel_bridge->panel, connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const struct drm_connector_helper_funcs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) panel_bridge_connector_helper_funcs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .get_modes = panel_bridge_connector_get_modes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static const struct drm_connector_funcs panel_bridge_connector_funcs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .reset = drm_atomic_helper_connector_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .fill_modes = drm_helper_probe_single_connector_modes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .destroy = drm_connector_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int panel_bridge_attach(struct drm_bridge *bridge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) enum drm_bridge_attach_flags flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct drm_connector *connector = &panel_bridge->connector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!bridge->encoder) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) DRM_ERROR("Missing encoder\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) drm_connector_helper_add(connector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) &panel_bridge_connector_helper_funcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ret = drm_connector_init(bridge->dev, connector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) &panel_bridge_connector_funcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) panel_bridge->connector_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) DRM_ERROR("Failed to initialize connector\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) drm_connector_attach_encoder(&panel_bridge->connector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) bridge->encoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static void panel_bridge_detach(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct drm_connector *connector = &panel_bridge->connector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Cleanup the connector if we know it was initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * FIXME: This wouldn't be needed if the panel_bridge structure was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * allocated with drmm_kzalloc(). This might be tricky since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * drm_device pointer can only be retrieved when the bridge is attached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (connector->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) drm_connector_cleanup(connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void panel_bridge_pre_enable(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) drm_panel_prepare(panel_bridge->panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void panel_bridge_enable(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) drm_panel_enable(panel_bridge->panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static void panel_bridge_disable(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) drm_panel_disable(panel_bridge->panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static void panel_bridge_post_disable(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) drm_panel_unprepare(panel_bridge->panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int panel_bridge_get_modes(struct drm_bridge *bridge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct drm_connector *connector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return drm_panel_get_modes(panel_bridge->panel, connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .attach = panel_bridge_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .detach = panel_bridge_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .pre_enable = panel_bridge_pre_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .enable = panel_bridge_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .disable = panel_bridge_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .post_disable = panel_bridge_post_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .get_modes = panel_bridge_get_modes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .atomic_reset = drm_atomic_helper_bridge_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .atomic_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * drm_panel_bridge_add - Creates a &drm_bridge and &drm_connector that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * just calls the appropriate functions from &drm_panel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * @panel: The drm_panel being wrapped. Must be non-NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * For drivers converting from directly using drm_panel: The expected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * usage pattern is that during either encoder module probe or DSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * host attach, a drm_panel will be looked up through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * drm_of_find_panel_or_bridge(). drm_panel_bridge_add() is used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * wrap that panel in the new bridge, and the result can then be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * passed to drm_bridge_attach(). The drm_panel_prepare() and related
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * functions can be dropped from the encoder driver (they're now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * called by the KMS helpers before calling into the encoder), along
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * with connector creation. When done with the bridge (after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * drm_mode_config_cleanup() if the bridge has already been attached), then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * drm_panel_bridge_remove() to free it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * The connector type is set to @panel->connector_type, which must be set to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * known type. Calling this function with a panel whose connector type is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * DRM_MODE_CONNECTOR_Unknown will return ERR_PTR(-EINVAL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * See devm_drm_panel_bridge_add() for an automatically managed version of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return drm_panel_bridge_add_typed(panel, panel->connector_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) EXPORT_SYMBOL(drm_panel_bridge_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * drm_panel_bridge_add_typed - Creates a &drm_bridge and &drm_connector with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * an explicit connector type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @panel: The drm_panel being wrapped. Must be non-NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * @connector_type: The connector type (DRM_MODE_CONNECTOR_*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * This is just like drm_panel_bridge_add(), but forces the connector type to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * @connector_type instead of infering it from the panel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * This function is deprecated and should not be used in new drivers. Use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * drm_panel_bridge_add() instead, and fix panel drivers as necessary if they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * don't report a connector type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) u32 connector_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct panel_bridge *panel_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (!panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) panel_bridge = devm_kzalloc(panel->dev, sizeof(*panel_bridge),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (!panel_bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) panel_bridge->connector_type = connector_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) panel_bridge->panel = panel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) panel_bridge->bridge.funcs = &panel_bridge_bridge_funcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) panel_bridge->bridge.of_node = panel->dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) panel_bridge->bridge.ops = DRM_BRIDGE_OP_MODES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) panel_bridge->bridge.type = connector_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) drm_bridge_add(&panel_bridge->bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return &panel_bridge->bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) EXPORT_SYMBOL(drm_panel_bridge_add_typed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * drm_panel_bridge_remove - Unregisters and frees a drm_bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * created by drm_panel_bridge_add().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * @bridge: The drm_bridge being freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) void drm_panel_bridge_remove(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct panel_bridge *panel_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (!bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (bridge->funcs != &panel_bridge_bridge_funcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) drm_bridge_remove(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) devm_kfree(panel_bridge->panel->dev, bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) EXPORT_SYMBOL(drm_panel_bridge_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static void devm_drm_panel_bridge_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct drm_bridge **bridge = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) drm_panel_bridge_remove(*bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * devm_drm_panel_bridge_add - Creates a managed &drm_bridge and &drm_connector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * that just calls the appropriate functions from &drm_panel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * @dev: device to tie the bridge lifetime to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * @panel: The drm_panel being wrapped. Must be non-NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * This is the managed version of drm_panel_bridge_add() which automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * calls drm_panel_bridge_remove() when @dev is unbound.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct drm_panel *panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return devm_drm_panel_bridge_add_typed(dev, panel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) panel->connector_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) EXPORT_SYMBOL(devm_drm_panel_bridge_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * devm_drm_panel_bridge_add_typed - Creates a managed &drm_bridge and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * &drm_connector with an explicit connector type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * @dev: device to tie the bridge lifetime to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * @panel: The drm_panel being wrapped. Must be non-NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * @connector_type: The connector type (DRM_MODE_CONNECTOR_*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * This is just like devm_drm_panel_bridge_add(), but forces the connector type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * to @connector_type instead of infering it from the panel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * This function is deprecated and should not be used in new drivers. Use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * devm_drm_panel_bridge_add() instead, and fix panel drivers as necessary if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * they don't report a connector type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct drm_panel *panel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) u32 connector_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct drm_bridge **ptr, *bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ptr = devres_alloc(devm_drm_panel_bridge_release, sizeof(*ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) bridge = drm_panel_bridge_add_typed(panel, connector_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (!IS_ERR(bridge)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) *ptr = bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * drm_panel_bridge_connector - return the connector for the panel bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * @bridge: The drm_bridge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * drm_panel_bridge creates the connector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * This function gives external access to the connector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * Returns: Pointer to drm_connector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct panel_bridge *panel_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) panel_bridge = drm_bridge_to_panel_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return &panel_bridge->connector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) EXPORT_SYMBOL(drm_panel_bridge_connector);