19952f691SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2fcfa0ddcSPeter Senna Tschudin /*
3fcfa0ddcSPeter Senna Tschudin * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
4fcfa0ddcSPeter Senna Tschudin * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
5fcfa0ddcSPeter Senna Tschudin
6fcfa0ddcSPeter Senna Tschudin * Copyright (c) 2017, Collabora Ltd.
7fcfa0ddcSPeter Senna Tschudin * Copyright (c) 2017, General Electric Company
8fcfa0ddcSPeter Senna Tschudin
9fcfa0ddcSPeter Senna Tschudin
10fcfa0ddcSPeter Senna Tschudin * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
11fcfa0ddcSPeter Senna Tschudin * display bridge of the GE B850v3. There are two physical bridges on the video
12fcfa0ddcSPeter Senna Tschudin * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
13fcfa0ddcSPeter Senna Tschudin * physical bridges are automatically configured by the input video signal, and
14fcfa0ddcSPeter Senna Tschudin * the driver has no access to the video processing pipeline. The driver is
15fcfa0ddcSPeter Senna Tschudin * only needed to read EDID from the STDP2690 and to handle HPD events from the
16fcfa0ddcSPeter Senna Tschudin * STDP4028. The driver communicates with both bridges over i2c. The video
17fcfa0ddcSPeter Senna Tschudin * signal pipeline is as follows:
18fcfa0ddcSPeter Senna Tschudin *
19fcfa0ddcSPeter Senna Tschudin * Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
20fcfa0ddcSPeter Senna Tschudin */
21fcfa0ddcSPeter Senna Tschudin
22fcfa0ddcSPeter Senna Tschudin #include <linux/i2c.h>
23fcfa0ddcSPeter Senna Tschudin #include <linux/module.h>
24fcfa0ddcSPeter Senna Tschudin #include <linux/of.h>
2595b60804SSam Ravnborg
26fcfa0ddcSPeter Senna Tschudin #include <drm/drm_atomic.h>
27fcfa0ddcSPeter Senna Tschudin #include <drm/drm_atomic_helper.h>
28ee68c743SBoris Brezillon #include <drm/drm_bridge.h>
29fcfa0ddcSPeter Senna Tschudin #include <drm/drm_edid.h>
3095b60804SSam Ravnborg #include <drm/drm_print.h>
31fcd70cd3SDaniel Vetter #include <drm/drm_probe_helper.h>
32fcfa0ddcSPeter Senna Tschudin
33fcfa0ddcSPeter Senna Tschudin #define EDID_EXT_BLOCK_CNT 0x7E
34fcfa0ddcSPeter Senna Tschudin
35fcfa0ddcSPeter Senna Tschudin #define STDP4028_IRQ_OUT_CONF_REG 0x02
36fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_IRQ_EN_REG 0x3C
37fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_IRQ_STS_REG 0x3D
38fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_STS_REG 0x3E
39fcfa0ddcSPeter Senna Tschudin
40fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_DP_IRQ_EN 0x1000
41fcfa0ddcSPeter Senna Tschudin
42fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
43fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
44fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_IRQ_CONFIG \
45fcfa0ddcSPeter Senna Tschudin (STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
46fcfa0ddcSPeter Senna Tschudin
47fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_HOTPLUG_STS 0x0200
48fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_LINK_STS 0x1000
49fcfa0ddcSPeter Senna Tschudin #define STDP4028_CON_STATE_CONNECTED \
50fcfa0ddcSPeter Senna Tschudin (STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
51fcfa0ddcSPeter Senna Tschudin
52fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
53fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_LINK_CH_STS 0x2000
54fcfa0ddcSPeter Senna Tschudin #define STDP4028_DPTX_IRQ_CLEAR \
55fcfa0ddcSPeter Senna Tschudin (STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
56fcfa0ddcSPeter Senna Tschudin
57fcfa0ddcSPeter Senna Tschudin static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
58fcfa0ddcSPeter Senna Tschudin
59fcfa0ddcSPeter Senna Tschudin struct ge_b850v3_lvds {
60fcfa0ddcSPeter Senna Tschudin struct drm_connector connector;
61fcfa0ddcSPeter Senna Tschudin struct drm_bridge bridge;
62fcfa0ddcSPeter Senna Tschudin struct i2c_client *stdp4028_i2c;
63fcfa0ddcSPeter Senna Tschudin struct i2c_client *stdp2690_i2c;
64fcfa0ddcSPeter Senna Tschudin };
65fcfa0ddcSPeter Senna Tschudin
66fcfa0ddcSPeter Senna Tschudin static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
67fcfa0ddcSPeter Senna Tschudin
stdp2690_read_block(void * context,u8 * buf,unsigned int block,size_t len)68e0eb7db4SIan Ray static int stdp2690_read_block(void *context, u8 *buf, unsigned int block, size_t len)
69fcfa0ddcSPeter Senna Tschudin {
70e0eb7db4SIan Ray struct i2c_client *client = context;
71fcfa0ddcSPeter Senna Tschudin struct i2c_adapter *adapter = client->adapter;
72e0eb7db4SIan Ray unsigned char start = block * EDID_LENGTH;
73fcfa0ddcSPeter Senna Tschudin
74fcfa0ddcSPeter Senna Tschudin struct i2c_msg msgs[] = {
75fcfa0ddcSPeter Senna Tschudin {
76fcfa0ddcSPeter Senna Tschudin .addr = client->addr,
77fcfa0ddcSPeter Senna Tschudin .flags = 0,
78fcfa0ddcSPeter Senna Tschudin .len = 1,
79fcfa0ddcSPeter Senna Tschudin .buf = &start,
80fcfa0ddcSPeter Senna Tschudin }, {
81fcfa0ddcSPeter Senna Tschudin .addr = client->addr,
82fcfa0ddcSPeter Senna Tschudin .flags = I2C_M_RD,
83e0eb7db4SIan Ray .len = len,
84e0eb7db4SIan Ray .buf = buf,
85fcfa0ddcSPeter Senna Tschudin }
86fcfa0ddcSPeter Senna Tschudin };
87fcfa0ddcSPeter Senna Tschudin
88e0eb7db4SIan Ray if (i2c_transfer(adapter, msgs, 2) != 2)
89e0eb7db4SIan Ray return -1;
90fcfa0ddcSPeter Senna Tschudin
91e0eb7db4SIan Ray return 0;
92fcfa0ddcSPeter Senna Tschudin }
93fcfa0ddcSPeter Senna Tschudin
ge_b850v3_lvds_edid_read(struct drm_bridge * bridge,struct drm_connector * connector)94*e3cbc95fSJani Nikula static const struct drm_edid *ge_b850v3_lvds_edid_read(struct drm_bridge *bridge,
95489ce80fSSam Ravnborg struct drm_connector *connector)
96fcfa0ddcSPeter Senna Tschudin {
97fcfa0ddcSPeter Senna Tschudin struct i2c_client *client;
98fcfa0ddcSPeter Senna Tschudin
99fcfa0ddcSPeter Senna Tschudin client = ge_b850v3_lvds_ptr->stdp2690_i2c;
100fcfa0ddcSPeter Senna Tschudin
101*e3cbc95fSJani Nikula return drm_edid_read_custom(connector, stdp2690_read_block, client);
102fcfa0ddcSPeter Senna Tschudin }
103fcfa0ddcSPeter Senna Tschudin
ge_b850v3_lvds_get_modes(struct drm_connector * connector)104489ce80fSSam Ravnborg static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
105489ce80fSSam Ravnborg {
106*e3cbc95fSJani Nikula const struct drm_edid *drm_edid;
107489ce80fSSam Ravnborg int num_modes;
108489ce80fSSam Ravnborg
109*e3cbc95fSJani Nikula drm_edid = ge_b850v3_lvds_edid_read(&ge_b850v3_lvds_ptr->bridge, connector);
110489ce80fSSam Ravnborg
111*e3cbc95fSJani Nikula drm_edid_connector_update(connector, drm_edid);
112*e3cbc95fSJani Nikula num_modes = drm_edid_connector_add_modes(connector);
113*e3cbc95fSJani Nikula drm_edid_free(drm_edid);
114489ce80fSSam Ravnborg
115fcfa0ddcSPeter Senna Tschudin return num_modes;
116fcfa0ddcSPeter Senna Tschudin }
117fcfa0ddcSPeter Senna Tschudin
ge_b850v3_lvds_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)118fcfa0ddcSPeter Senna Tschudin static enum drm_mode_status ge_b850v3_lvds_mode_valid(
119fcfa0ddcSPeter Senna Tschudin struct drm_connector *connector, struct drm_display_mode *mode)
120fcfa0ddcSPeter Senna Tschudin {
121fcfa0ddcSPeter Senna Tschudin return MODE_OK;
122fcfa0ddcSPeter Senna Tschudin }
123fcfa0ddcSPeter Senna Tschudin
124fcfa0ddcSPeter Senna Tschudin static const struct
125fcfa0ddcSPeter Senna Tschudin drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
126fcfa0ddcSPeter Senna Tschudin .get_modes = ge_b850v3_lvds_get_modes,
127fcfa0ddcSPeter Senna Tschudin .mode_valid = ge_b850v3_lvds_mode_valid,
128fcfa0ddcSPeter Senna Tschudin };
129fcfa0ddcSPeter Senna Tschudin
ge_b850v3_lvds_bridge_detect(struct drm_bridge * bridge)130a3d495ceSSam Ravnborg static enum drm_connector_status ge_b850v3_lvds_bridge_detect(struct drm_bridge *bridge)
131fcfa0ddcSPeter Senna Tschudin {
132fcfa0ddcSPeter Senna Tschudin struct i2c_client *stdp4028_i2c =
133fcfa0ddcSPeter Senna Tschudin ge_b850v3_lvds_ptr->stdp4028_i2c;
134fcfa0ddcSPeter Senna Tschudin s32 link_state;
135fcfa0ddcSPeter Senna Tschudin
136fcfa0ddcSPeter Senna Tschudin link_state = i2c_smbus_read_word_data(stdp4028_i2c,
137fcfa0ddcSPeter Senna Tschudin STDP4028_DPTX_STS_REG);
138fcfa0ddcSPeter Senna Tschudin
139fcfa0ddcSPeter Senna Tschudin if (link_state == STDP4028_CON_STATE_CONNECTED)
140fcfa0ddcSPeter Senna Tschudin return connector_status_connected;
141fcfa0ddcSPeter Senna Tschudin
142fcfa0ddcSPeter Senna Tschudin if (link_state == 0)
143fcfa0ddcSPeter Senna Tschudin return connector_status_disconnected;
144fcfa0ddcSPeter Senna Tschudin
145fcfa0ddcSPeter Senna Tschudin return connector_status_unknown;
146fcfa0ddcSPeter Senna Tschudin }
147fcfa0ddcSPeter Senna Tschudin
ge_b850v3_lvds_detect(struct drm_connector * connector,bool force)148a3d495ceSSam Ravnborg static enum drm_connector_status ge_b850v3_lvds_detect(struct drm_connector *connector,
149a3d495ceSSam Ravnborg bool force)
150a3d495ceSSam Ravnborg {
151a3d495ceSSam Ravnborg return ge_b850v3_lvds_bridge_detect(&ge_b850v3_lvds_ptr->bridge);
152a3d495ceSSam Ravnborg }
153a3d495ceSSam Ravnborg
154fcfa0ddcSPeter Senna Tschudin static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
155fcfa0ddcSPeter Senna Tschudin .fill_modes = drm_helper_probe_single_connector_modes,
156fcfa0ddcSPeter Senna Tschudin .detect = ge_b850v3_lvds_detect,
157fcfa0ddcSPeter Senna Tschudin .destroy = drm_connector_cleanup,
158fcfa0ddcSPeter Senna Tschudin .reset = drm_atomic_helper_connector_reset,
159fcfa0ddcSPeter Senna Tschudin .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
160fcfa0ddcSPeter Senna Tschudin .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
161fcfa0ddcSPeter Senna Tschudin };
162fcfa0ddcSPeter Senna Tschudin
ge_b850v3_lvds_create_connector(struct drm_bridge * bridge)16343c601a6SSam Ravnborg static int ge_b850v3_lvds_create_connector(struct drm_bridge *bridge)
164fcfa0ddcSPeter Senna Tschudin {
165fcfa0ddcSPeter Senna Tschudin struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
166fcfa0ddcSPeter Senna Tschudin int ret;
167fcfa0ddcSPeter Senna Tschudin
168fcfa0ddcSPeter Senna Tschudin connector->polled = DRM_CONNECTOR_POLL_HPD;
169fcfa0ddcSPeter Senna Tschudin
170fcfa0ddcSPeter Senna Tschudin drm_connector_helper_add(connector,
171fcfa0ddcSPeter Senna Tschudin &ge_b850v3_lvds_connector_helper_funcs);
172fcfa0ddcSPeter Senna Tschudin
173fcfa0ddcSPeter Senna Tschudin ret = drm_connector_init(bridge->dev, connector,
174fcfa0ddcSPeter Senna Tschudin &ge_b850v3_lvds_connector_funcs,
175fcfa0ddcSPeter Senna Tschudin DRM_MODE_CONNECTOR_DisplayPort);
176fcfa0ddcSPeter Senna Tschudin if (ret) {
177fcfa0ddcSPeter Senna Tschudin DRM_ERROR("Failed to initialize connector with drm\n");
178fcfa0ddcSPeter Senna Tschudin return ret;
179fcfa0ddcSPeter Senna Tschudin }
180fcfa0ddcSPeter Senna Tschudin
18143c601a6SSam Ravnborg return drm_connector_attach_encoder(connector, bridge->encoder);
18243c601a6SSam Ravnborg }
18343c601a6SSam Ravnborg
ge_b850v3_lvds_irq_handler(int irq,void * dev_id)18443c601a6SSam Ravnborg static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
18543c601a6SSam Ravnborg {
18643c601a6SSam Ravnborg struct i2c_client *stdp4028_i2c
18743c601a6SSam Ravnborg = ge_b850v3_lvds_ptr->stdp4028_i2c;
18843c601a6SSam Ravnborg
18943c601a6SSam Ravnborg i2c_smbus_write_word_data(stdp4028_i2c,
19043c601a6SSam Ravnborg STDP4028_DPTX_IRQ_STS_REG,
19143c601a6SSam Ravnborg STDP4028_DPTX_IRQ_CLEAR);
19243c601a6SSam Ravnborg
19377860a7cSSam Ravnborg if (ge_b850v3_lvds_ptr->bridge.dev)
19477860a7cSSam Ravnborg drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->bridge.dev);
19543c601a6SSam Ravnborg
19643c601a6SSam Ravnborg return IRQ_HANDLED;
19743c601a6SSam Ravnborg }
19843c601a6SSam Ravnborg
ge_b850v3_lvds_attach(struct drm_bridge * bridge,enum drm_bridge_attach_flags flags)19943c601a6SSam Ravnborg static int ge_b850v3_lvds_attach(struct drm_bridge *bridge,
20043c601a6SSam Ravnborg enum drm_bridge_attach_flags flags)
20143c601a6SSam Ravnborg {
20243c601a6SSam Ravnborg struct i2c_client *stdp4028_i2c
20343c601a6SSam Ravnborg = ge_b850v3_lvds_ptr->stdp4028_i2c;
204fcfa0ddcSPeter Senna Tschudin
205fcfa0ddcSPeter Senna Tschudin /* Configures the bridge to re-enable interrupts after each ack. */
206fcfa0ddcSPeter Senna Tschudin i2c_smbus_write_word_data(stdp4028_i2c,
207fcfa0ddcSPeter Senna Tschudin STDP4028_IRQ_OUT_CONF_REG,
208fcfa0ddcSPeter Senna Tschudin STDP4028_DPTX_DP_IRQ_EN);
209fcfa0ddcSPeter Senna Tschudin
210fcfa0ddcSPeter Senna Tschudin /* Enable interrupts */
211fcfa0ddcSPeter Senna Tschudin i2c_smbus_write_word_data(stdp4028_i2c,
212fcfa0ddcSPeter Senna Tschudin STDP4028_DPTX_IRQ_EN_REG,
213fcfa0ddcSPeter Senna Tschudin STDP4028_DPTX_IRQ_CONFIG);
214fcfa0ddcSPeter Senna Tschudin
215a8ef18d7SSam Ravnborg if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
216fcfa0ddcSPeter Senna Tschudin return 0;
217a8ef18d7SSam Ravnborg
218a8ef18d7SSam Ravnborg return ge_b850v3_lvds_create_connector(bridge);
219fcfa0ddcSPeter Senna Tschudin }
220fcfa0ddcSPeter Senna Tschudin
221fcfa0ddcSPeter Senna Tschudin static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
222fcfa0ddcSPeter Senna Tschudin .attach = ge_b850v3_lvds_attach,
223a3d495ceSSam Ravnborg .detect = ge_b850v3_lvds_bridge_detect,
224*e3cbc95fSJani Nikula .edid_read = ge_b850v3_lvds_edid_read,
225fcfa0ddcSPeter Senna Tschudin };
226fcfa0ddcSPeter Senna Tschudin
ge_b850v3_lvds_init(struct device * dev)227fcfa0ddcSPeter Senna Tschudin static int ge_b850v3_lvds_init(struct device *dev)
228fcfa0ddcSPeter Senna Tschudin {
229fcfa0ddcSPeter Senna Tschudin mutex_lock(&ge_b850v3_lvds_dev_mutex);
230fcfa0ddcSPeter Senna Tschudin
231fcfa0ddcSPeter Senna Tschudin if (ge_b850v3_lvds_ptr)
232fcfa0ddcSPeter Senna Tschudin goto success;
233fcfa0ddcSPeter Senna Tschudin
234fcfa0ddcSPeter Senna Tschudin ge_b850v3_lvds_ptr = devm_kzalloc(dev,
235fcfa0ddcSPeter Senna Tschudin sizeof(*ge_b850v3_lvds_ptr),
236fcfa0ddcSPeter Senna Tschudin GFP_KERNEL);
237fcfa0ddcSPeter Senna Tschudin
238fcfa0ddcSPeter Senna Tschudin if (!ge_b850v3_lvds_ptr) {
239fcfa0ddcSPeter Senna Tschudin mutex_unlock(&ge_b850v3_lvds_dev_mutex);
240fcfa0ddcSPeter Senna Tschudin return -ENOMEM;
241fcfa0ddcSPeter Senna Tschudin }
242fcfa0ddcSPeter Senna Tschudin
243fcfa0ddcSPeter Senna Tschudin success:
244fcfa0ddcSPeter Senna Tschudin mutex_unlock(&ge_b850v3_lvds_dev_mutex);
245fcfa0ddcSPeter Senna Tschudin return 0;
246fcfa0ddcSPeter Senna Tschudin }
247fcfa0ddcSPeter Senna Tschudin
ge_b850v3_lvds_remove(void)248fcfa0ddcSPeter Senna Tschudin static void ge_b850v3_lvds_remove(void)
249fcfa0ddcSPeter Senna Tschudin {
250fcfa0ddcSPeter Senna Tschudin mutex_lock(&ge_b850v3_lvds_dev_mutex);
251fcfa0ddcSPeter Senna Tschudin /*
252fcfa0ddcSPeter Senna Tschudin * This check is to avoid both the drivers
253fcfa0ddcSPeter Senna Tschudin * removing the bridge in their remove() function
254fcfa0ddcSPeter Senna Tschudin */
2551ff67333SZheyu Ma if (!ge_b850v3_lvds_ptr ||
2561ff67333SZheyu Ma !ge_b850v3_lvds_ptr->stdp2690_i2c ||
2571ff67333SZheyu Ma !ge_b850v3_lvds_ptr->stdp4028_i2c)
258fcfa0ddcSPeter Senna Tschudin goto out;
259fcfa0ddcSPeter Senna Tschudin
260fcfa0ddcSPeter Senna Tschudin drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
261fcfa0ddcSPeter Senna Tschudin
262fcfa0ddcSPeter Senna Tschudin ge_b850v3_lvds_ptr = NULL;
263fcfa0ddcSPeter Senna Tschudin out:
264fcfa0ddcSPeter Senna Tschudin mutex_unlock(&ge_b850v3_lvds_dev_mutex);
265fcfa0ddcSPeter Senna Tschudin }
266fcfa0ddcSPeter Senna Tschudin
ge_b850v3_register(void)26711632d4aSMartyn Welch static int ge_b850v3_register(void)
268fcfa0ddcSPeter Senna Tschudin {
26911632d4aSMartyn Welch struct i2c_client *stdp4028_i2c = ge_b850v3_lvds_ptr->stdp4028_i2c;
270fcfa0ddcSPeter Senna Tschudin struct device *dev = &stdp4028_i2c->dev;
271fcfa0ddcSPeter Senna Tschudin
272a68ee76fSPeter Senna Tschudin /* drm bridge initialization */
273a68ee76fSPeter Senna Tschudin ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
274489ce80fSSam Ravnborg ge_b850v3_lvds_ptr->bridge.ops = DRM_BRIDGE_OP_DETECT |
275489ce80fSSam Ravnborg DRM_BRIDGE_OP_EDID;
276a8ef18d7SSam Ravnborg ge_b850v3_lvds_ptr->bridge.type = DRM_MODE_CONNECTOR_DisplayPort;
277a68ee76fSPeter Senna Tschudin ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
278a68ee76fSPeter Senna Tschudin drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
279a68ee76fSPeter Senna Tschudin
280fcfa0ddcSPeter Senna Tschudin /* Clear pending interrupts since power up. */
281fcfa0ddcSPeter Senna Tschudin i2c_smbus_write_word_data(stdp4028_i2c,
282fcfa0ddcSPeter Senna Tschudin STDP4028_DPTX_IRQ_STS_REG,
283fcfa0ddcSPeter Senna Tschudin STDP4028_DPTX_IRQ_CLEAR);
284fcfa0ddcSPeter Senna Tschudin
285fcfa0ddcSPeter Senna Tschudin if (!stdp4028_i2c->irq)
286fcfa0ddcSPeter Senna Tschudin return 0;
287fcfa0ddcSPeter Senna Tschudin
288fcfa0ddcSPeter Senna Tschudin return devm_request_threaded_irq(&stdp4028_i2c->dev,
289fcfa0ddcSPeter Senna Tschudin stdp4028_i2c->irq, NULL,
290fcfa0ddcSPeter Senna Tschudin ge_b850v3_lvds_irq_handler,
291fcfa0ddcSPeter Senna Tschudin IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
292fcfa0ddcSPeter Senna Tschudin "ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
293fcfa0ddcSPeter Senna Tschudin }
294fcfa0ddcSPeter Senna Tschudin
stdp4028_ge_b850v3_fw_probe(struct i2c_client * stdp4028_i2c)295dd14e4f9SUwe Kleine-König static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c)
29611632d4aSMartyn Welch {
29711632d4aSMartyn Welch struct device *dev = &stdp4028_i2c->dev;
29811632d4aSMartyn Welch int ret;
29911632d4aSMartyn Welch
30011632d4aSMartyn Welch ret = ge_b850v3_lvds_init(dev);
30111632d4aSMartyn Welch
30211632d4aSMartyn Welch if (ret)
30311632d4aSMartyn Welch return ret;
30411632d4aSMartyn Welch
30511632d4aSMartyn Welch ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
30611632d4aSMartyn Welch i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
30711632d4aSMartyn Welch
30811632d4aSMartyn Welch /* Only register after both bridges are probed */
30911632d4aSMartyn Welch if (!ge_b850v3_lvds_ptr->stdp2690_i2c)
31011632d4aSMartyn Welch return 0;
31111632d4aSMartyn Welch
31211632d4aSMartyn Welch return ge_b850v3_register();
31311632d4aSMartyn Welch }
31411632d4aSMartyn Welch
stdp4028_ge_b850v3_fw_remove(struct i2c_client * stdp4028_i2c)315ed5c2f5fSUwe Kleine-König static void stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
316fcfa0ddcSPeter Senna Tschudin {
317fcfa0ddcSPeter Senna Tschudin ge_b850v3_lvds_remove();
318fcfa0ddcSPeter Senna Tschudin }
319fcfa0ddcSPeter Senna Tschudin
320fcfa0ddcSPeter Senna Tschudin static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
321fcfa0ddcSPeter Senna Tschudin {"stdp4028_ge_fw", 0},
322fcfa0ddcSPeter Senna Tschudin {},
323fcfa0ddcSPeter Senna Tschudin };
324fcfa0ddcSPeter Senna Tschudin MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
325fcfa0ddcSPeter Senna Tschudin
326fcfa0ddcSPeter Senna Tschudin static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
327fcfa0ddcSPeter Senna Tschudin { .compatible = "megachips,stdp4028-ge-b850v3-fw" },
328fcfa0ddcSPeter Senna Tschudin {},
329fcfa0ddcSPeter Senna Tschudin };
330fcfa0ddcSPeter Senna Tschudin MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
331fcfa0ddcSPeter Senna Tschudin
332fcfa0ddcSPeter Senna Tschudin static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
333fcfa0ddcSPeter Senna Tschudin .id_table = stdp4028_ge_b850v3_fw_i2c_table,
334332af828SUwe Kleine-König .probe = stdp4028_ge_b850v3_fw_probe,
335fcfa0ddcSPeter Senna Tschudin .remove = stdp4028_ge_b850v3_fw_remove,
336fcfa0ddcSPeter Senna Tschudin .driver = {
337fcfa0ddcSPeter Senna Tschudin .name = "stdp4028-ge-b850v3-fw",
338fcfa0ddcSPeter Senna Tschudin .of_match_table = stdp4028_ge_b850v3_fw_match,
339fcfa0ddcSPeter Senna Tschudin },
340fcfa0ddcSPeter Senna Tschudin };
341fcfa0ddcSPeter Senna Tschudin
stdp2690_ge_b850v3_fw_probe(struct i2c_client * stdp2690_i2c)342dd14e4f9SUwe Kleine-König static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c)
343fcfa0ddcSPeter Senna Tschudin {
344fcfa0ddcSPeter Senna Tschudin struct device *dev = &stdp2690_i2c->dev;
345f688a345SNadezda Lutovinova int ret;
346fcfa0ddcSPeter Senna Tschudin
347f688a345SNadezda Lutovinova ret = ge_b850v3_lvds_init(dev);
348f688a345SNadezda Lutovinova
349f688a345SNadezda Lutovinova if (ret)
350f688a345SNadezda Lutovinova return ret;
351fcfa0ddcSPeter Senna Tschudin
352fcfa0ddcSPeter Senna Tschudin ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
353fcfa0ddcSPeter Senna Tschudin i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
354fcfa0ddcSPeter Senna Tschudin
35511632d4aSMartyn Welch /* Only register after both bridges are probed */
35611632d4aSMartyn Welch if (!ge_b850v3_lvds_ptr->stdp4028_i2c)
357fcfa0ddcSPeter Senna Tschudin return 0;
35811632d4aSMartyn Welch
35911632d4aSMartyn Welch return ge_b850v3_register();
360fcfa0ddcSPeter Senna Tschudin }
361fcfa0ddcSPeter Senna Tschudin
stdp2690_ge_b850v3_fw_remove(struct i2c_client * stdp2690_i2c)362ed5c2f5fSUwe Kleine-König static void stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
363fcfa0ddcSPeter Senna Tschudin {
364fcfa0ddcSPeter Senna Tschudin ge_b850v3_lvds_remove();
365fcfa0ddcSPeter Senna Tschudin }
366fcfa0ddcSPeter Senna Tschudin
367fcfa0ddcSPeter Senna Tschudin static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
368fcfa0ddcSPeter Senna Tschudin {"stdp2690_ge_fw", 0},
369fcfa0ddcSPeter Senna Tschudin {},
370fcfa0ddcSPeter Senna Tschudin };
371fcfa0ddcSPeter Senna Tschudin MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
372fcfa0ddcSPeter Senna Tschudin
373fcfa0ddcSPeter Senna Tschudin static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
374fcfa0ddcSPeter Senna Tschudin { .compatible = "megachips,stdp2690-ge-b850v3-fw" },
375fcfa0ddcSPeter Senna Tschudin {},
376fcfa0ddcSPeter Senna Tschudin };
377fcfa0ddcSPeter Senna Tschudin MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
378fcfa0ddcSPeter Senna Tschudin
379fcfa0ddcSPeter Senna Tschudin static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
380fcfa0ddcSPeter Senna Tschudin .id_table = stdp2690_ge_b850v3_fw_i2c_table,
381332af828SUwe Kleine-König .probe = stdp2690_ge_b850v3_fw_probe,
382fcfa0ddcSPeter Senna Tschudin .remove = stdp2690_ge_b850v3_fw_remove,
383fcfa0ddcSPeter Senna Tschudin .driver = {
384fcfa0ddcSPeter Senna Tschudin .name = "stdp2690-ge-b850v3-fw",
385fcfa0ddcSPeter Senna Tschudin .of_match_table = stdp2690_ge_b850v3_fw_match,
386fcfa0ddcSPeter Senna Tschudin },
387fcfa0ddcSPeter Senna Tschudin };
388fcfa0ddcSPeter Senna Tschudin
stdpxxxx_ge_b850v3_init(void)389fcfa0ddcSPeter Senna Tschudin static int __init stdpxxxx_ge_b850v3_init(void)
390fcfa0ddcSPeter Senna Tschudin {
391fcfa0ddcSPeter Senna Tschudin int ret;
392fcfa0ddcSPeter Senna Tschudin
393fcfa0ddcSPeter Senna Tschudin ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
394fcfa0ddcSPeter Senna Tschudin if (ret)
395fcfa0ddcSPeter Senna Tschudin return ret;
396fcfa0ddcSPeter Senna Tschudin
3974ecff954SYuan Can ret = i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
3984ecff954SYuan Can if (ret)
3994ecff954SYuan Can i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
4004ecff954SYuan Can
4014ecff954SYuan Can return ret;
402fcfa0ddcSPeter Senna Tschudin }
403fcfa0ddcSPeter Senna Tschudin module_init(stdpxxxx_ge_b850v3_init);
404fcfa0ddcSPeter Senna Tschudin
stdpxxxx_ge_b850v3_exit(void)405fcfa0ddcSPeter Senna Tschudin static void __exit stdpxxxx_ge_b850v3_exit(void)
406fcfa0ddcSPeter Senna Tschudin {
407fcfa0ddcSPeter Senna Tschudin i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
408fcfa0ddcSPeter Senna Tschudin i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
409fcfa0ddcSPeter Senna Tschudin }
410fcfa0ddcSPeter Senna Tschudin module_exit(stdpxxxx_ge_b850v3_exit);
411fcfa0ddcSPeter Senna Tschudin
412fcfa0ddcSPeter Senna Tschudin MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
413fcfa0ddcSPeter Senna Tschudin MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
414fcfa0ddcSPeter Senna Tschudin MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
415fcfa0ddcSPeter Senna Tschudin MODULE_LICENSE("GPL v2");
416