^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * NXP PTN3460 DP/LVDS bridge driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2013 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <drm/drm_atomic_helper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <drm/drm_bridge.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <drm/drm_crtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <drm/drm_edid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <drm/drm_of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <drm/drm_panel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <drm/drm_print.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <drm/drm_probe_helper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define PTN3460_EDID_ADDR 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PTN3460_EDID_EMULATION_ADDR 0x84
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define PTN3460_EDID_ENABLE_EMULATION 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define PTN3460_EDID_EMULATION_SELECTION 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define PTN3460_EDID_SRAM_LOAD_ADDR 0x85
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct ptn3460_bridge {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct drm_connector connector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct drm_bridge bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct drm_bridge *panel_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct gpio_desc *gpio_pd_n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct gpio_desc *gpio_rst_n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u32 edid_emulation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) bool enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static inline struct ptn3460_bridge *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) bridge_to_ptn3460(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return container_of(bridge, struct ptn3460_bridge, bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static inline struct ptn3460_bridge *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) connector_to_ptn3460(struct drm_connector *connector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return container_of(connector, struct ptn3460_bridge, connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int ptn3460_read_bytes(struct ptn3460_bridge *ptn_bridge, char addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ret = i2c_master_send(ptn_bridge->client, &addr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ret = i2c_master_recv(ptn_bridge->client, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return 0;
^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) static int ptn3460_write_byte(struct ptn3460_bridge *ptn_bridge, char addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) char val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) char buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) buf[0] = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) buf[1] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ret = i2c_master_send(ptn_bridge->client, buf, ARRAY_SIZE(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static int ptn3460_select_edid(struct ptn3460_bridge *ptn_bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) char val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* Load the selected edid into SRAM (accessed at PTN3460_EDID_ADDR) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ret = ptn3460_write_byte(ptn_bridge, PTN3460_EDID_SRAM_LOAD_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ptn_bridge->edid_emulation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) DRM_ERROR("Failed to transfer EDID to sram, ret=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* Enable EDID emulation and select the desired EDID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) val = 1 << PTN3460_EDID_ENABLE_EMULATION |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ptn_bridge->edid_emulation << PTN3460_EDID_EMULATION_SELECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ret = ptn3460_write_byte(ptn_bridge, PTN3460_EDID_EMULATION_ADDR, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) DRM_ERROR("Failed to write EDID value, ret=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static void ptn3460_pre_enable(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (ptn_bridge->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) gpiod_set_value(ptn_bridge->gpio_pd_n, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) gpiod_set_value(ptn_bridge->gpio_rst_n, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) usleep_range(10, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * There's a bug in the PTN chip where it falsely asserts hotplug before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * it is fully functional. We're forced to wait for the maximum start up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * time specified in the chip's datasheet to make sure we're really up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) msleep(90);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ret = ptn3460_select_edid(ptn_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) DRM_ERROR("Select EDID failed ret=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ptn_bridge->enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static void ptn3460_disable(struct drm_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!ptn_bridge->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ptn_bridge->enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) gpiod_set_value(ptn_bridge->gpio_pd_n, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static struct edid *ptn3460_get_edid(struct drm_bridge *bridge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct drm_connector *connector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) bool power_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) u8 *edid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) power_off = !ptn_bridge->enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ptn3460_pre_enable(&ptn_bridge->bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (!edid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) DRM_ERROR("Failed to allocate EDID\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ret = ptn3460_read_bytes(ptn_bridge, PTN3460_EDID_ADDR, edid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) EDID_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) kfree(edid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) edid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ptn3460_disable(&ptn_bridge->bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return (struct edid *)edid;
^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) static int ptn3460_connector_get_modes(struct drm_connector *connector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct ptn3460_bridge *ptn_bridge = connector_to_ptn3460(connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct edid *edid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int num_modes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) edid = ptn3460_get_edid(&ptn_bridge->bridge, connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) drm_connector_update_edid_property(connector, edid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) num_modes = drm_add_edid_modes(connector, edid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) kfree(edid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return num_modes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static const struct drm_connector_helper_funcs ptn3460_connector_helper_funcs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .get_modes = ptn3460_connector_get_modes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static const struct drm_connector_funcs ptn3460_connector_funcs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .fill_modes = drm_helper_probe_single_connector_modes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .destroy = drm_connector_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) .reset = drm_atomic_helper_connector_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int ptn3460_bridge_attach(struct drm_bridge *bridge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) enum drm_bridge_attach_flags flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* Let this driver create connector if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ret = drm_bridge_attach(bridge->encoder, ptn_bridge->panel_bridge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) bridge, flags | DRM_BRIDGE_ATTACH_NO_CONNECTOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (!bridge->encoder) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) DRM_ERROR("Parent encoder object not found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) ptn_bridge->connector.polled = DRM_CONNECTOR_POLL_HPD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ret = drm_connector_init(bridge->dev, &ptn_bridge->connector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) &ptn3460_connector_funcs, DRM_MODE_CONNECTOR_LVDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) DRM_ERROR("Failed to initialize connector with drm\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) drm_connector_helper_add(&ptn_bridge->connector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) &ptn3460_connector_helper_funcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) drm_connector_register(&ptn_bridge->connector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) drm_connector_attach_encoder(&ptn_bridge->connector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) bridge->encoder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) drm_helper_hpd_irq_event(ptn_bridge->connector.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static const struct drm_bridge_funcs ptn3460_bridge_funcs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .pre_enable = ptn3460_pre_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .disable = ptn3460_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .attach = ptn3460_bridge_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .get_edid = ptn3460_get_edid,
^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) static int ptn3460_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct ptn3460_bridge *ptn_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct drm_bridge *panel_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct drm_panel *panel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ptn_bridge = devm_kzalloc(dev, sizeof(*ptn_bridge), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (!ptn_bridge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &panel, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) panel_bridge = devm_drm_panel_bridge_add(dev, panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (IS_ERR(panel_bridge))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return PTR_ERR(panel_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ptn_bridge->panel_bridge = panel_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ptn_bridge->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ptn_bridge->gpio_pd_n = devm_gpiod_get(&client->dev, "powerdown",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (IS_ERR(ptn_bridge->gpio_pd_n)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ret = PTR_ERR(ptn_bridge->gpio_pd_n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) dev_err(dev, "cannot get gpio_pd_n %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Request the reset pin low to avoid the bridge being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * initialized prematurely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ptn_bridge->gpio_rst_n = devm_gpiod_get(&client->dev, "reset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (IS_ERR(ptn_bridge->gpio_rst_n)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ret = PTR_ERR(ptn_bridge->gpio_rst_n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) DRM_ERROR("cannot get gpio_rst_n %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ret = of_property_read_u32(dev->of_node, "edid-emulation",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) &ptn_bridge->edid_emulation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) dev_err(dev, "Can't read EDID emulation value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ptn_bridge->bridge.funcs = &ptn3460_bridge_funcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) ptn_bridge->bridge.ops = DRM_BRIDGE_OP_EDID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ptn_bridge->bridge.type = DRM_MODE_CONNECTOR_LVDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ptn_bridge->bridge.of_node = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) drm_bridge_add(&ptn_bridge->bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) i2c_set_clientdata(client, ptn_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static int ptn3460_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct ptn3460_bridge *ptn_bridge = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) drm_bridge_remove(&ptn_bridge->bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static const struct i2c_device_id ptn3460_i2c_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {"ptn3460", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) MODULE_DEVICE_TABLE(i2c, ptn3460_i2c_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static const struct of_device_id ptn3460_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) { .compatible = "nxp,ptn3460" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) MODULE_DEVICE_TABLE(of, ptn3460_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static struct i2c_driver ptn3460_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .id_table = ptn3460_i2c_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .probe = ptn3460_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .remove = ptn3460_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) .name = "nxp,ptn3460",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .of_match_table = ptn3460_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) module_i2c_driver(ptn3460_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) MODULE_AUTHOR("Sean Paul <seanpaul@chromium.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) MODULE_DESCRIPTION("NXP ptn3460 eDP-LVDS converter driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) MODULE_LICENSE("GPL v2");