Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2019-2020. Linaro Limited.
5 */
6
7#include <linux/firmware.h>
8#include <linux/gpio/consumer.h>
9#include <linux/i2c.h>
10#include <linux/interrupt.h>
11#include <linux/module.h>
12#include <linux/mutex.h>
13#include <linux/of_graph.h>
14#include <linux/platform_device.h>
15#include <linux/regmap.h>
16#include <linux/regulator/consumer.h>
17#include <linux/wait.h>
18#include <linux/workqueue.h>
19
20#include <sound/hdmi-codec.h>
21
22#include <drm/drm_atomic_helper.h>
23#include <drm/drm_bridge.h>
24#include <drm/drm_edid.h>
25#include <drm/drm_mipi_dsi.h>
26#include <drm/drm_of.h>
27#include <drm/drm_print.h>
28#include <drm/drm_probe_helper.h>
29
30#define EDID_BLOCK_SIZE 128
31#define EDID_NUM_BLOCKS 2
32
33#define FW_FILE "lt9611uxc_fw.bin"
34
35struct lt9611uxc {
36 struct device *dev;
37 struct drm_bridge bridge;
38 struct drm_bridge *next_bridge;
39
40 struct regmap *regmap;
41 /* Protects all accesses to registers by stopping the on-chip MCU */
42 struct mutex ocm_lock;
43
44 struct wait_queue_head wq;
45 struct work_struct work;
46
47 struct device_node *dsi0_node;
48 struct device_node *dsi1_node;
49 struct mipi_dsi_device *dsi0;
50 struct mipi_dsi_device *dsi1;
51 struct platform_device *audio_pdev;
52
53 struct gpio_desc *reset_gpio;
54 struct gpio_desc *enable_gpio;
55
56 struct regulator_bulk_data supplies[2];
57
58 struct i2c_client *client;
59
60 bool hpd_supported;
61 bool edid_read;
62 /* can be accessed from different threads, so protect this with ocm_lock */
63 bool hdmi_connected;
64 uint8_t fw_version;
65};
66
67#define LT9611_PAGE_CONTROL 0xff
68
69static const struct regmap_range_cfg lt9611uxc_ranges[] = {
70 {
71 .name = "register_range",
72 .range_min = 0,
73 .range_max = 0xd0ff,
74 .selector_reg = LT9611_PAGE_CONTROL,
75 .selector_mask = 0xff,
76 .selector_shift = 0,
77 .window_start = 0,
78 .window_len = 0x100,
79 },
80};
81
82static const struct regmap_config lt9611uxc_regmap_config = {
83 .reg_bits = 8,
84 .val_bits = 8,
85 .max_register = 0xffff,
86 .ranges = lt9611uxc_ranges,
87 .num_ranges = ARRAY_SIZE(lt9611uxc_ranges),
88};
89
90struct lt9611uxc_mode {
91 u16 hdisplay;
92 u16 vdisplay;
93 u8 vrefresh;
94};
95
96/*
97 * This chip supports only a fixed set of modes.
98 * Enumerate them here to check whether the mode is supported.
99 */
100static struct lt9611uxc_mode lt9611uxc_modes[] = {
101 { 1920, 1080, 60 },
102 { 1920, 1080, 30 },
103 { 1920, 1080, 25 },
104 { 1366, 768, 60 },
105 { 1360, 768, 60 },
106 { 1280, 1024, 60 },
107 { 1280, 800, 60 },
108 { 1280, 720, 60 },
109 { 1280, 720, 50 },
110 { 1280, 720, 30 },
111 { 1152, 864, 60 },
112 { 1024, 768, 60 },
113 { 800, 600, 60 },
114 { 720, 576, 50 },
115 { 720, 480, 60 },
116 { 640, 480, 60 },
117};
118
119static struct lt9611uxc *bridge_to_lt9611uxc(struct drm_bridge *bridge)
120{
121 return container_of(bridge, struct lt9611uxc, bridge);
122}
123
124static void lt9611uxc_lock(struct lt9611uxc *lt9611uxc)
125{
126 mutex_lock(<9611uxc->ocm_lock);
127 regmap_write(lt9611uxc->regmap, 0x80ee, 0x01);
128}
129
130static void lt9611uxc_unlock(struct lt9611uxc *lt9611uxc)
131{
132 regmap_write(lt9611uxc->regmap, 0x80ee, 0x00);
133 msleep(50);
134 mutex_unlock(<9611uxc->ocm_lock);
135}
136
137static irqreturn_t lt9611uxc_irq_thread_handler(int irq, void *dev_id)
138{
139 struct lt9611uxc *lt9611uxc = dev_id;
140 unsigned int irq_status = 0;
141 unsigned int hpd_status = 0;
142
143 lt9611uxc_lock(lt9611uxc);
144
145 regmap_read(lt9611uxc->regmap, 0xb022, &irq_status);
146 regmap_read(lt9611uxc->regmap, 0xb023, &hpd_status);
147 if (irq_status)
148 regmap_write(lt9611uxc->regmap, 0xb022, 0);
149
150 if (irq_status & BIT(0)) {
151 lt9611uxc->edid_read = !!(hpd_status & BIT(0));
152 wake_up_all(<9611uxc->wq);
153 }
154
155 if (irq_status & BIT(1)) {
156 lt9611uxc->hdmi_connected = hpd_status & BIT(1);
157 schedule_work(<9611uxc->work);
158 }
159
160 lt9611uxc_unlock(lt9611uxc);
161
162 return IRQ_HANDLED;
163}
164
165static void lt9611uxc_hpd_work(struct work_struct *work)
166{
167 struct lt9611uxc *lt9611uxc = container_of(work, struct lt9611uxc, work);
168 bool connected;
169
170 mutex_lock(<9611uxc->ocm_lock);
171 connected = lt9611uxc->hdmi_connected;
172 mutex_unlock(<9611uxc->ocm_lock);
173
174 drm_bridge_hpd_notify(<9611uxc->bridge,
175 connected ?
176 connector_status_connected :
177 connector_status_disconnected);
178}
179
180static void lt9611uxc_reset(struct lt9611uxc *lt9611uxc)
181{
182 gpiod_set_value_cansleep(lt9611uxc->reset_gpio, 1);
183 msleep(20);
184
185 gpiod_set_value_cansleep(lt9611uxc->reset_gpio, 0);
186 msleep(20);
187
188 gpiod_set_value_cansleep(lt9611uxc->reset_gpio, 1);
189 msleep(300);
190}
191
192static void lt9611uxc_assert_5v(struct lt9611uxc *lt9611uxc)
193{
194 if (!lt9611uxc->enable_gpio)
195 return;
196
197 gpiod_set_value_cansleep(lt9611uxc->enable_gpio, 1);
198 msleep(20);
199}
200
201static int lt9611uxc_regulator_init(struct lt9611uxc *lt9611uxc)
202{
203 int ret;
204
205 lt9611uxc->supplies[0].supply = "vdd";
206 lt9611uxc->supplies[1].supply = "vcc";
207
208 ret = devm_regulator_bulk_get(lt9611uxc->dev, 2, lt9611uxc->supplies);
209 if (ret < 0)
210 return ret;
211
212 return regulator_set_load(lt9611uxc->supplies[0].consumer, 200000);
213}
214
215static int lt9611uxc_regulator_enable(struct lt9611uxc *lt9611uxc)
216{
217 int ret;
218
219 ret = regulator_enable(lt9611uxc->supplies[0].consumer);
220 if (ret < 0)
221 return ret;
222
223 usleep_range(1000, 10000); /* 50000 according to dtsi */
224
225 ret = regulator_enable(lt9611uxc->supplies[1].consumer);
226 if (ret < 0) {
227 regulator_disable(lt9611uxc->supplies[0].consumer);
228 return ret;
229 }
230
231 return 0;
232}
233
234static struct lt9611uxc_mode *lt9611uxc_find_mode(const struct drm_display_mode *mode)
235{
236 int i;
237
238 for (i = 0; i < ARRAY_SIZE(lt9611uxc_modes); i++) {
239 if (lt9611uxc_modes[i].hdisplay == mode->hdisplay &&
240 lt9611uxc_modes[i].vdisplay == mode->vdisplay &&
241 lt9611uxc_modes[i].vrefresh == drm_mode_vrefresh(mode)) {
242 return <9611uxc_modes[i];
243 }
244 }
245
246 return NULL;
247}
248
249static struct mipi_dsi_device *lt9611uxc_attach_dsi(struct lt9611uxc *lt9611uxc,
250 struct device_node *dsi_node)
251{
252 const struct mipi_dsi_device_info info = { "lt9611uxc", 0, NULL };
253 struct mipi_dsi_device *dsi;
254 struct mipi_dsi_host *host;
255 struct device *dev = lt9611uxc->dev;
256 int ret;
257
258 host = of_find_mipi_dsi_host_by_node(dsi_node);
259 if (!host)
260 return ERR_PTR(dev_err_probe(dev, -EPROBE_DEFER, "failed to find dsi host\n"));
261
262 dsi = devm_mipi_dsi_device_register_full(dev, host, &info);
263 if (IS_ERR(dsi)) {
264 dev_err(dev, "failed to create dsi device\n");
265 return dsi;
266 }
267
268 dsi->lanes = 4;
269 dsi->format = MIPI_DSI_FMT_RGB888;
270 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
271 MIPI_DSI_MODE_VIDEO_HSE;
272
273 ret = devm_mipi_dsi_attach(dev, dsi);
274 if (ret < 0) {
275 dev_err(dev, "failed to attach dsi to host\n");
276 return ERR_PTR(ret);
277 }
278
279 return dsi;
280}
281
282static int lt9611uxc_bridge_attach(struct drm_bridge *bridge,
283 enum drm_bridge_attach_flags flags)
284{
285 struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
286
287 return drm_bridge_attach(bridge->encoder, lt9611uxc->next_bridge,
288 bridge, flags);
289}
290
291static enum drm_mode_status
292lt9611uxc_bridge_mode_valid(struct drm_bridge *bridge,
293 const struct drm_display_info *info,
294 const struct drm_display_mode *mode)
295{
296 struct lt9611uxc_mode *lt9611uxc_mode;
297
298 lt9611uxc_mode = lt9611uxc_find_mode(mode);
299
300 return lt9611uxc_mode ? MODE_OK : MODE_BAD;
301}
302
303static void lt9611uxc_video_setup(struct lt9611uxc *lt9611uxc,
304 const struct drm_display_mode *mode)
305{
306 u32 h_total, hactive, hsync_len, hfront_porch;
307 u32 v_total, vactive, vsync_len, vfront_porch;
308
309 h_total = mode->htotal;
310 v_total = mode->vtotal;
311
312 hactive = mode->hdisplay;
313 hsync_len = mode->hsync_end - mode->hsync_start;
314 hfront_porch = mode->hsync_start - mode->hdisplay;
315
316 vactive = mode->vdisplay;
317 vsync_len = mode->vsync_end - mode->vsync_start;
318 vfront_porch = mode->vsync_start - mode->vdisplay;
319
320 regmap_write(lt9611uxc->regmap, 0xd00d, (u8)(v_total / 256));
321 regmap_write(lt9611uxc->regmap, 0xd00e, (u8)(v_total % 256));
322
323 regmap_write(lt9611uxc->regmap, 0xd00f, (u8)(vactive / 256));
324 regmap_write(lt9611uxc->regmap, 0xd010, (u8)(vactive % 256));
325
326 regmap_write(lt9611uxc->regmap, 0xd011, (u8)(h_total / 256));
327 regmap_write(lt9611uxc->regmap, 0xd012, (u8)(h_total % 256));
328
329 regmap_write(lt9611uxc->regmap, 0xd013, (u8)(hactive / 256));
330 regmap_write(lt9611uxc->regmap, 0xd014, (u8)(hactive % 256));
331
332 regmap_write(lt9611uxc->regmap, 0xd015, (u8)(vsync_len % 256));
333
334 regmap_update_bits(lt9611uxc->regmap, 0xd016, 0xf, (u8)(hsync_len / 256));
335 regmap_write(lt9611uxc->regmap, 0xd017, (u8)(hsync_len % 256));
336
337 regmap_update_bits(lt9611uxc->regmap, 0xd018, 0xf, (u8)(vfront_porch / 256));
338 regmap_write(lt9611uxc->regmap, 0xd019, (u8)(vfront_porch % 256));
339
340 regmap_update_bits(lt9611uxc->regmap, 0xd01a, 0xf, (u8)(hfront_porch / 256));
341 regmap_write(lt9611uxc->regmap, 0xd01b, (u8)(hfront_porch % 256));
342}
343
344static void lt9611uxc_bridge_mode_set(struct drm_bridge *bridge,
345 const struct drm_display_mode *mode,
346 const struct drm_display_mode *adj_mode)
347{
348 struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
349
350 lt9611uxc_lock(lt9611uxc);
351 lt9611uxc_video_setup(lt9611uxc, mode);
352 lt9611uxc_unlock(lt9611uxc);
353}
354
355static enum drm_connector_status lt9611uxc_bridge_detect(struct drm_bridge *bridge)
356{
357 struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
358 unsigned int reg_val = 0;
359 int ret;
360 bool connected = true;
361
362 lt9611uxc_lock(lt9611uxc);
363
364 if (lt9611uxc->hpd_supported) {
365 ret = regmap_read(lt9611uxc->regmap, 0xb023, ®_val);
366
367 if (ret)
368 dev_err(lt9611uxc->dev, "failed to read hpd status: %d\n", ret);
369 else
370 connected = reg_val & BIT(1);
371 }
372 lt9611uxc->hdmi_connected = connected;
373
374 lt9611uxc_unlock(lt9611uxc);
375
376 return connected ? connector_status_connected :
377 connector_status_disconnected;
378}
379
380static int lt9611uxc_wait_for_edid(struct lt9611uxc *lt9611uxc)
381{
382 return wait_event_interruptible_timeout(lt9611uxc->wq, lt9611uxc->edid_read,
383 msecs_to_jiffies(500));
384}
385
386static int lt9611uxc_get_edid_block(void *data, u8 *buf, unsigned int block, size_t len)
387{
388 struct lt9611uxc *lt9611uxc = data;
389 int ret;
390
391 if (len > EDID_BLOCK_SIZE)
392 return -EINVAL;
393
394 if (block >= EDID_NUM_BLOCKS)
395 return -EINVAL;
396
397 lt9611uxc_lock(lt9611uxc);
398
399 regmap_write(lt9611uxc->regmap, 0xb00b, 0x10);
400
401 regmap_write(lt9611uxc->regmap, 0xb00a, block * EDID_BLOCK_SIZE);
402
403 ret = regmap_noinc_read(lt9611uxc->regmap, 0xb0b0, buf, len);
404 if (ret)
405 dev_err(lt9611uxc->dev, "edid read failed: %d\n", ret);
406
407 lt9611uxc_unlock(lt9611uxc);
408
409 return 0;
410};
411
412static const struct drm_edid *lt9611uxc_bridge_edid_read(struct drm_bridge *bridge,
413 struct drm_connector *connector)
414{
415 struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
416 int ret;
417
418 ret = lt9611uxc_wait_for_edid(lt9611uxc);
419 if (ret < 0) {
420 dev_err(lt9611uxc->dev, "wait for EDID failed: %d\n", ret);
421 return NULL;
422 } else if (ret == 0) {
423 dev_err(lt9611uxc->dev, "wait for EDID timeout\n");
424 return NULL;
425 }
426
427 return drm_edid_read_custom(connector, lt9611uxc_get_edid_block, lt9611uxc);
428}
429
430static const struct drm_bridge_funcs lt9611uxc_bridge_funcs = {
431 .attach = lt9611uxc_bridge_attach,
432 .mode_valid = lt9611uxc_bridge_mode_valid,
433 .mode_set = lt9611uxc_bridge_mode_set,
434 .detect = lt9611uxc_bridge_detect,
435 .edid_read = lt9611uxc_bridge_edid_read,
436};
437
438static int lt9611uxc_parse_dt(struct device *dev,
439 struct lt9611uxc *lt9611uxc)
440{
441 lt9611uxc->dsi0_node = of_graph_get_remote_node(dev->of_node, 0, -1);
442 if (!lt9611uxc->dsi0_node) {
443 dev_err(lt9611uxc->dev, "failed to get remote node for primary dsi\n");
444 return -ENODEV;
445 }
446
447 lt9611uxc->dsi1_node = of_graph_get_remote_node(dev->of_node, 1, -1);
448
449 return drm_of_find_panel_or_bridge(dev->of_node, 2, -1, NULL, <9611uxc->next_bridge);
450}
451
452static int lt9611uxc_gpio_init(struct lt9611uxc *lt9611uxc)
453{
454 struct device *dev = lt9611uxc->dev;
455
456 lt9611uxc->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
457 if (IS_ERR(lt9611uxc->reset_gpio)) {
458 dev_err(dev, "failed to acquire reset gpio\n");
459 return PTR_ERR(lt9611uxc->reset_gpio);
460 }
461
462 lt9611uxc->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
463 if (IS_ERR(lt9611uxc->enable_gpio)) {
464 dev_err(dev, "failed to acquire enable gpio\n");
465 return PTR_ERR(lt9611uxc->enable_gpio);
466 }
467
468 return 0;
469}
470
471static int lt9611uxc_read_device_rev(struct lt9611uxc *lt9611uxc)
472{
473 unsigned int rev0, rev1, rev2;
474 int ret;
475
476 lt9611uxc_lock(lt9611uxc);
477
478 ret = regmap_read(lt9611uxc->regmap, 0x8100, &rev0);
479 ret |= regmap_read(lt9611uxc->regmap, 0x8101, &rev1);
480 ret |= regmap_read(lt9611uxc->regmap, 0x8102, &rev2);
481 if (ret)
482 dev_err(lt9611uxc->dev, "failed to read revision: %d\n", ret);
483 else
484 dev_info(lt9611uxc->dev, "LT9611 revision: 0x%02x.%02x.%02x\n", rev0, rev1, rev2);
485
486 lt9611uxc_unlock(lt9611uxc);
487
488 return ret;
489}
490
491static int lt9611uxc_read_version(struct lt9611uxc *lt9611uxc)
492{
493 unsigned int rev;
494 int ret;
495
496 lt9611uxc_lock(lt9611uxc);
497
498 ret = regmap_read(lt9611uxc->regmap, 0xb021, &rev);
499 if (ret)
500 dev_err(lt9611uxc->dev, "failed to read revision: %d\n", ret);
501 else
502 dev_info(lt9611uxc->dev, "LT9611 version: 0x%02x\n", rev);
503
504 lt9611uxc_unlock(lt9611uxc);
505
506 return ret < 0 ? ret : rev;
507}
508
509static int lt9611uxc_hdmi_hw_params(struct device *dev, void *data,
510 struct hdmi_codec_daifmt *fmt,
511 struct hdmi_codec_params *hparms)
512{
513 /*
514 * LT9611UXC will automatically detect rate and sample size, so no need
515 * to setup anything here.
516 */
517 return 0;
518}
519
520static void lt9611uxc_audio_shutdown(struct device *dev, void *data)
521{
522}
523
524static int lt9611uxc_hdmi_i2s_get_dai_id(struct snd_soc_component *component,
525 struct device_node *endpoint)
526{
527 struct of_endpoint of_ep;
528 int ret;
529
530 ret = of_graph_parse_endpoint(endpoint, &of_ep);
531 if (ret < 0)
532 return ret;
533
534 /*
535 * HDMI sound should be located as reg = <2>
536 * Then, it is sound port 0
537 */
538 if (of_ep.port == 2)
539 return 0;
540
541 return -EINVAL;
542}
543
544static const struct hdmi_codec_ops lt9611uxc_codec_ops = {
545 .hw_params = lt9611uxc_hdmi_hw_params,
546 .audio_shutdown = lt9611uxc_audio_shutdown,
547 .get_dai_id = lt9611uxc_hdmi_i2s_get_dai_id,
548};
549
550static int lt9611uxc_audio_init(struct device *dev, struct lt9611uxc *lt9611uxc)
551{
552 struct hdmi_codec_pdata codec_data = {
553 .ops = <9611uxc_codec_ops,
554 .max_i2s_channels = 2,
555 .i2s = 1,
556 .data = lt9611uxc,
557 };
558
559 lt9611uxc->audio_pdev =
560 platform_device_register_data(dev, HDMI_CODEC_DRV_NAME,
561 PLATFORM_DEVID_AUTO,
562 &codec_data, sizeof(codec_data));
563
564 return PTR_ERR_OR_ZERO(lt9611uxc->audio_pdev);
565}
566
567static void lt9611uxc_audio_exit(struct lt9611uxc *lt9611uxc)
568{
569 if (lt9611uxc->audio_pdev) {
570 platform_device_unregister(lt9611uxc->audio_pdev);
571 lt9611uxc->audio_pdev = NULL;
572 }
573}
574
575#define LT9611UXC_FW_PAGE_SIZE 32
576static void lt9611uxc_firmware_write_page(struct lt9611uxc *lt9611uxc, u16 addr, const u8 *buf)
577{
578 struct reg_sequence seq_write_prepare[] = {
579 REG_SEQ0(0x805a, 0x04),
580 REG_SEQ0(0x805a, 0x00),
581
582 REG_SEQ0(0x805e, 0xdf),
583 REG_SEQ0(0x805a, 0x20),
584 REG_SEQ0(0x805a, 0x00),
585 REG_SEQ0(0x8058, 0x21),
586 };
587
588 struct reg_sequence seq_write_addr[] = {
589 REG_SEQ0(0x805b, (addr >> 16) & 0xff),
590 REG_SEQ0(0x805c, (addr >> 8) & 0xff),
591 REG_SEQ0(0x805d, addr & 0xff),
592 REG_SEQ0(0x805a, 0x10),
593 REG_SEQ0(0x805a, 0x00),
594 };
595
596 regmap_write(lt9611uxc->regmap, 0x8108, 0xbf);
597 msleep(20);
598 regmap_write(lt9611uxc->regmap, 0x8108, 0xff);
599 msleep(20);
600 regmap_multi_reg_write(lt9611uxc->regmap, seq_write_prepare, ARRAY_SIZE(seq_write_prepare));
601 regmap_noinc_write(lt9611uxc->regmap, 0x8059, buf, LT9611UXC_FW_PAGE_SIZE);
602 regmap_multi_reg_write(lt9611uxc->regmap, seq_write_addr, ARRAY_SIZE(seq_write_addr));
603 msleep(20);
604}
605
606static void lt9611uxc_firmware_read_page(struct lt9611uxc *lt9611uxc, u16 addr, char *buf)
607{
608 struct reg_sequence seq_read_page[] = {
609 REG_SEQ0(0x805a, 0xa0),
610 REG_SEQ0(0x805a, 0x80),
611 REG_SEQ0(0x805b, (addr >> 16) & 0xff),
612 REG_SEQ0(0x805c, (addr >> 8) & 0xff),
613 REG_SEQ0(0x805d, addr & 0xff),
614 REG_SEQ0(0x805a, 0x90),
615 REG_SEQ0(0x805a, 0x80),
616 REG_SEQ0(0x8058, 0x21),
617 };
618
619 regmap_multi_reg_write(lt9611uxc->regmap, seq_read_page, ARRAY_SIZE(seq_read_page));
620 regmap_noinc_read(lt9611uxc->regmap, 0x805f, buf, LT9611UXC_FW_PAGE_SIZE);
621}
622
623static char *lt9611uxc_firmware_read(struct lt9611uxc *lt9611uxc, size_t size)
624{
625 struct reg_sequence seq_read_setup[] = {
626 REG_SEQ0(0x805a, 0x84),
627 REG_SEQ0(0x805a, 0x80),
628 };
629
630 char *readbuf;
631 u16 offset;
632
633 readbuf = kzalloc(ALIGN(size, 32), GFP_KERNEL);
634 if (!readbuf)
635 return NULL;
636
637 regmap_multi_reg_write(lt9611uxc->regmap, seq_read_setup, ARRAY_SIZE(seq_read_setup));
638
639 for (offset = 0;
640 offset < size;
641 offset += LT9611UXC_FW_PAGE_SIZE)
642 lt9611uxc_firmware_read_page(lt9611uxc, offset, &readbuf[offset]);
643
644 return readbuf;
645}
646
647static int lt9611uxc_firmware_update(struct lt9611uxc *lt9611uxc)
648{
649 int ret;
650 u16 offset;
651 size_t remain;
652 char *readbuf;
653 const struct firmware *fw;
654
655 struct reg_sequence seq_setup[] = {
656 REG_SEQ0(0x805e, 0xdf),
657 REG_SEQ0(0x8058, 0x00),
658 REG_SEQ0(0x8059, 0x50),
659 REG_SEQ0(0x805a, 0x10),
660 REG_SEQ0(0x805a, 0x00),
661 };
662
663
664 struct reg_sequence seq_block_erase[] = {
665 REG_SEQ0(0x805a, 0x04),
666 REG_SEQ0(0x805a, 0x00),
667 REG_SEQ0(0x805b, 0x00),
668 REG_SEQ0(0x805c, 0x00),
669 REG_SEQ0(0x805d, 0x00),
670 REG_SEQ0(0x805a, 0x01),
671 REG_SEQ0(0x805a, 0x00),
672 };
673
674 ret = request_firmware(&fw, FW_FILE, lt9611uxc->dev);
675 if (ret < 0)
676 return ret;
677
678 dev_info(lt9611uxc->dev, "Updating firmware\n");
679 lt9611uxc_lock(lt9611uxc);
680
681 regmap_multi_reg_write(lt9611uxc->regmap, seq_setup, ARRAY_SIZE(seq_setup));
682
683 /*
684 * Need erase block 2 timess here. Sometimes, block erase can fail.
685 * This is a workaroud.
686 */
687 regmap_multi_reg_write(lt9611uxc->regmap, seq_block_erase, ARRAY_SIZE(seq_block_erase));
688 msleep(3000);
689 regmap_multi_reg_write(lt9611uxc->regmap, seq_block_erase, ARRAY_SIZE(seq_block_erase));
690 msleep(3000);
691
692 for (offset = 0, remain = fw->size;
693 remain >= LT9611UXC_FW_PAGE_SIZE;
694 offset += LT9611UXC_FW_PAGE_SIZE, remain -= LT9611UXC_FW_PAGE_SIZE)
695 lt9611uxc_firmware_write_page(lt9611uxc, offset, fw->data + offset);
696
697 if (remain > 0) {
698 char buf[LT9611UXC_FW_PAGE_SIZE];
699
700 memset(buf, 0xff, LT9611UXC_FW_PAGE_SIZE);
701 memcpy(buf, fw->data + offset, remain);
702 lt9611uxc_firmware_write_page(lt9611uxc, offset, buf);
703 }
704 msleep(20);
705
706 readbuf = lt9611uxc_firmware_read(lt9611uxc, fw->size);
707 if (!readbuf) {
708 ret = -ENOMEM;
709 goto out;
710 }
711
712 if (!memcmp(readbuf, fw->data, fw->size)) {
713 dev_err(lt9611uxc->dev, "Firmware update failed\n");
714 print_hex_dump(KERN_ERR, "fw: ", DUMP_PREFIX_OFFSET, 16, 1, readbuf, fw->size, false);
715 ret = -EINVAL;
716 } else {
717 dev_info(lt9611uxc->dev, "Firmware updates successfully\n");
718 ret = 0;
719 }
720 kfree(readbuf);
721
722out:
723 lt9611uxc_unlock(lt9611uxc);
724 lt9611uxc_reset(lt9611uxc);
725 release_firmware(fw);
726
727 return ret;
728}
729
730static ssize_t lt9611uxc_firmware_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
731{
732 struct lt9611uxc *lt9611uxc = dev_get_drvdata(dev);
733 int ret;
734
735 ret = lt9611uxc_firmware_update(lt9611uxc);
736 if (ret < 0)
737 return ret;
738 return len;
739}
740
741static ssize_t lt9611uxc_firmware_show(struct device *dev, struct device_attribute *attr, char *buf)
742{
743 struct lt9611uxc *lt9611uxc = dev_get_drvdata(dev);
744
745 return sysfs_emit(buf, "%02x\n", lt9611uxc->fw_version);
746}
747
748static DEVICE_ATTR_RW(lt9611uxc_firmware);
749
750static struct attribute *lt9611uxc_attrs[] = {
751 &dev_attr_lt9611uxc_firmware.attr,
752 NULL,
753};
754
755static const struct attribute_group lt9611uxc_attr_group = {
756 .attrs = lt9611uxc_attrs,
757};
758
759static const struct attribute_group *lt9611uxc_attr_groups[] = {
760 <9611uxc_attr_group,
761 NULL,
762};
763
764static int lt9611uxc_probe(struct i2c_client *client)
765{
766 struct lt9611uxc *lt9611uxc;
767 struct device *dev = &client->dev;
768 int ret;
769 bool fw_updated = false;
770
771 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
772 dev_err(dev, "device doesn't support I2C\n");
773 return -ENODEV;
774 }
775
776 lt9611uxc = devm_kzalloc(dev, sizeof(*lt9611uxc), GFP_KERNEL);
777 if (!lt9611uxc)
778 return -ENOMEM;
779
780 lt9611uxc->dev = dev;
781 lt9611uxc->client = client;
782 mutex_init(<9611uxc->ocm_lock);
783
784 lt9611uxc->regmap = devm_regmap_init_i2c(client, <9611uxc_regmap_config);
785 if (IS_ERR(lt9611uxc->regmap)) {
786 dev_err(lt9611uxc->dev, "regmap i2c init failed\n");
787 return PTR_ERR(lt9611uxc->regmap);
788 }
789
790 ret = lt9611uxc_parse_dt(dev, lt9611uxc);
791 if (ret) {
792 dev_err(dev, "failed to parse device tree\n");
793 return ret;
794 }
795
796 ret = lt9611uxc_gpio_init(lt9611uxc);
797 if (ret < 0)
798 goto err_of_put;
799
800 ret = lt9611uxc_regulator_init(lt9611uxc);
801 if (ret < 0)
802 goto err_of_put;
803
804 lt9611uxc_assert_5v(lt9611uxc);
805
806 ret = lt9611uxc_regulator_enable(lt9611uxc);
807 if (ret)
808 goto err_of_put;
809
810 lt9611uxc_reset(lt9611uxc);
811
812 ret = lt9611uxc_read_device_rev(lt9611uxc);
813 if (ret) {
814 dev_err(dev, "failed to read chip rev\n");
815 goto err_disable_regulators;
816 }
817
818retry:
819 ret = lt9611uxc_read_version(lt9611uxc);
820 if (ret < 0) {
821 dev_err(dev, "failed to read FW version\n");
822 goto err_disable_regulators;
823 } else if (ret == 0) {
824 if (!fw_updated) {
825 fw_updated = true;
826 dev_err(dev, "FW version 0, enforcing firmware update\n");
827 ret = lt9611uxc_firmware_update(lt9611uxc);
828 if (ret < 0)
829 goto err_disable_regulators;
830 else
831 goto retry;
832 } else {
833 dev_err(dev, "FW version 0, update failed\n");
834 ret = -EOPNOTSUPP;
835 goto err_disable_regulators;
836 }
837 } else if (ret < 0x40) {
838 dev_info(dev, "FW version 0x%x, HPD not supported\n", ret);
839 } else {
840 lt9611uxc->hpd_supported = true;
841 }
842 lt9611uxc->fw_version = ret;
843
844 init_waitqueue_head(<9611uxc->wq);
845 INIT_WORK(<9611uxc->work, lt9611uxc_hpd_work);
846
847 ret = request_threaded_irq(client->irq, NULL,
848 lt9611uxc_irq_thread_handler,
849 IRQF_ONESHOT, "lt9611uxc", lt9611uxc);
850 if (ret) {
851 dev_err(dev, "failed to request irq\n");
852 goto err_disable_regulators;
853 }
854
855 i2c_set_clientdata(client, lt9611uxc);
856
857 lt9611uxc->bridge.funcs = <9611uxc_bridge_funcs;
858 lt9611uxc->bridge.of_node = client->dev.of_node;
859 lt9611uxc->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID;
860 if (lt9611uxc->hpd_supported)
861 lt9611uxc->bridge.ops |= DRM_BRIDGE_OP_HPD;
862 lt9611uxc->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
863
864 drm_bridge_add(<9611uxc->bridge);
865
866 /* Attach primary DSI */
867 lt9611uxc->dsi0 = lt9611uxc_attach_dsi(lt9611uxc, lt9611uxc->dsi0_node);
868 if (IS_ERR(lt9611uxc->dsi0)) {
869 ret = PTR_ERR(lt9611uxc->dsi0);
870 goto err_remove_bridge;
871 }
872
873 /* Attach secondary DSI, if specified */
874 if (lt9611uxc->dsi1_node) {
875 lt9611uxc->dsi1 = lt9611uxc_attach_dsi(lt9611uxc, lt9611uxc->dsi1_node);
876 if (IS_ERR(lt9611uxc->dsi1)) {
877 ret = PTR_ERR(lt9611uxc->dsi1);
878 goto err_remove_bridge;
879 }
880 }
881
882 return lt9611uxc_audio_init(dev, lt9611uxc);
883
884err_remove_bridge:
885 free_irq(client->irq, lt9611uxc);
886 cancel_work_sync(<9611uxc->work);
887 drm_bridge_remove(<9611uxc->bridge);
888
889err_disable_regulators:
890 regulator_bulk_disable(ARRAY_SIZE(lt9611uxc->supplies), lt9611uxc->supplies);
891
892err_of_put:
893 of_node_put(lt9611uxc->dsi1_node);
894 of_node_put(lt9611uxc->dsi0_node);
895
896 return ret;
897}
898
899static void lt9611uxc_remove(struct i2c_client *client)
900{
901 struct lt9611uxc *lt9611uxc = i2c_get_clientdata(client);
902
903 free_irq(client->irq, lt9611uxc);
904 cancel_work_sync(<9611uxc->work);
905 lt9611uxc_audio_exit(lt9611uxc);
906 drm_bridge_remove(<9611uxc->bridge);
907
908 mutex_destroy(<9611uxc->ocm_lock);
909
910 regulator_bulk_disable(ARRAY_SIZE(lt9611uxc->supplies), lt9611uxc->supplies);
911
912 of_node_put(lt9611uxc->dsi1_node);
913 of_node_put(lt9611uxc->dsi0_node);
914}
915
916static struct i2c_device_id lt9611uxc_id[] = {
917 { "lontium,lt9611uxc", 0 },
918 { /* sentinel */ }
919};
920
921static const struct of_device_id lt9611uxc_match_table[] = {
922 { .compatible = "lontium,lt9611uxc" },
923 { /* sentinel */ }
924};
925MODULE_DEVICE_TABLE(of, lt9611uxc_match_table);
926
927static struct i2c_driver lt9611uxc_driver = {
928 .driver = {
929 .name = "lt9611uxc",
930 .of_match_table = lt9611uxc_match_table,
931 .dev_groups = lt9611uxc_attr_groups,
932 },
933 .probe = lt9611uxc_probe,
934 .remove = lt9611uxc_remove,
935 .id_table = lt9611uxc_id,
936};
937module_i2c_driver(lt9611uxc_driver);
938
939MODULE_AUTHOR("Dmitry Baryshkov <dmitry.baryshkov@linaro.org>");
940MODULE_DESCRIPTION("Lontium LT9611UXC DSI/HDMI bridge driver");
941MODULE_LICENSE("GPL v2");
942
943MODULE_FIRMWARE(FW_FILE);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2019-2020. Linaro Limited.
5 */
6
7#include <linux/firmware.h>
8#include <linux/gpio/consumer.h>
9#include <linux/i2c.h>
10#include <linux/interrupt.h>
11#include <linux/module.h>
12#include <linux/mutex.h>
13#include <linux/of_graph.h>
14#include <linux/platform_device.h>
15#include <linux/regmap.h>
16#include <linux/regulator/consumer.h>
17#include <linux/wait.h>
18#include <linux/workqueue.h>
19
20#include <sound/hdmi-codec.h>
21
22#include <drm/drm_atomic_helper.h>
23#include <drm/drm_bridge.h>
24#include <drm/drm_edid.h>
25#include <drm/drm_mipi_dsi.h>
26#include <drm/drm_print.h>
27#include <drm/drm_probe_helper.h>
28
29#define EDID_BLOCK_SIZE 128
30#define EDID_NUM_BLOCKS 2
31
32#define FW_FILE "lt9611uxc_fw.bin"
33
34struct lt9611uxc {
35 struct device *dev;
36 struct drm_bridge bridge;
37 struct drm_connector connector;
38
39 struct regmap *regmap;
40 /* Protects all accesses to registers by stopping the on-chip MCU */
41 struct mutex ocm_lock;
42
43 struct wait_queue_head wq;
44 struct work_struct work;
45
46 struct device_node *dsi0_node;
47 struct device_node *dsi1_node;
48 struct mipi_dsi_device *dsi0;
49 struct mipi_dsi_device *dsi1;
50 struct platform_device *audio_pdev;
51
52 struct gpio_desc *reset_gpio;
53 struct gpio_desc *enable_gpio;
54
55 struct regulator_bulk_data supplies[2];
56
57 struct i2c_client *client;
58
59 bool hpd_supported;
60 bool edid_read;
61 /* can be accessed from different threads, so protect this with ocm_lock */
62 bool hdmi_connected;
63 uint8_t fw_version;
64};
65
66#define LT9611_PAGE_CONTROL 0xff
67
68static const struct regmap_range_cfg lt9611uxc_ranges[] = {
69 {
70 .name = "register_range",
71 .range_min = 0,
72 .range_max = 0xd0ff,
73 .selector_reg = LT9611_PAGE_CONTROL,
74 .selector_mask = 0xff,
75 .selector_shift = 0,
76 .window_start = 0,
77 .window_len = 0x100,
78 },
79};
80
81static const struct regmap_config lt9611uxc_regmap_config = {
82 .reg_bits = 8,
83 .val_bits = 8,
84 .max_register = 0xffff,
85 .ranges = lt9611uxc_ranges,
86 .num_ranges = ARRAY_SIZE(lt9611uxc_ranges),
87};
88
89struct lt9611uxc_mode {
90 u16 hdisplay;
91 u16 vdisplay;
92 u8 vrefresh;
93};
94
95/*
96 * This chip supports only a fixed set of modes.
97 * Enumerate them here to check whether the mode is supported.
98 */
99static struct lt9611uxc_mode lt9611uxc_modes[] = {
100 { 1920, 1080, 60 },
101 { 1920, 1080, 30 },
102 { 1920, 1080, 25 },
103 { 1366, 768, 60 },
104 { 1360, 768, 60 },
105 { 1280, 1024, 60 },
106 { 1280, 800, 60 },
107 { 1280, 720, 60 },
108 { 1280, 720, 50 },
109 { 1280, 720, 30 },
110 { 1152, 864, 60 },
111 { 1024, 768, 60 },
112 { 800, 600, 60 },
113 { 720, 576, 50 },
114 { 720, 480, 60 },
115 { 640, 480, 60 },
116};
117
118static struct lt9611uxc *bridge_to_lt9611uxc(struct drm_bridge *bridge)
119{
120 return container_of(bridge, struct lt9611uxc, bridge);
121}
122
123static struct lt9611uxc *connector_to_lt9611uxc(struct drm_connector *connector)
124{
125 return container_of(connector, struct lt9611uxc, connector);
126}
127
128static void lt9611uxc_lock(struct lt9611uxc *lt9611uxc)
129{
130 mutex_lock(<9611uxc->ocm_lock);
131 regmap_write(lt9611uxc->regmap, 0x80ee, 0x01);
132}
133
134static void lt9611uxc_unlock(struct lt9611uxc *lt9611uxc)
135{
136 regmap_write(lt9611uxc->regmap, 0x80ee, 0x00);
137 msleep(50);
138 mutex_unlock(<9611uxc->ocm_lock);
139}
140
141static irqreturn_t lt9611uxc_irq_thread_handler(int irq, void *dev_id)
142{
143 struct lt9611uxc *lt9611uxc = dev_id;
144 unsigned int irq_status = 0;
145 unsigned int hpd_status = 0;
146
147 lt9611uxc_lock(lt9611uxc);
148
149 regmap_read(lt9611uxc->regmap, 0xb022, &irq_status);
150 regmap_read(lt9611uxc->regmap, 0xb023, &hpd_status);
151 if (irq_status)
152 regmap_write(lt9611uxc->regmap, 0xb022, 0);
153
154 if (irq_status & BIT(0)) {
155 lt9611uxc->edid_read = !!(hpd_status & BIT(0));
156 wake_up_all(<9611uxc->wq);
157 }
158
159 if (irq_status & BIT(1)) {
160 lt9611uxc->hdmi_connected = hpd_status & BIT(1);
161 schedule_work(<9611uxc->work);
162 }
163
164 lt9611uxc_unlock(lt9611uxc);
165
166 return IRQ_HANDLED;
167}
168
169static void lt9611uxc_hpd_work(struct work_struct *work)
170{
171 struct lt9611uxc *lt9611uxc = container_of(work, struct lt9611uxc, work);
172 bool connected;
173
174 if (lt9611uxc->connector.dev) {
175 if (lt9611uxc->connector.dev->mode_config.funcs)
176 drm_kms_helper_hotplug_event(lt9611uxc->connector.dev);
177 } else {
178
179 mutex_lock(<9611uxc->ocm_lock);
180 connected = lt9611uxc->hdmi_connected;
181 mutex_unlock(<9611uxc->ocm_lock);
182
183 drm_bridge_hpd_notify(<9611uxc->bridge,
184 connected ?
185 connector_status_connected :
186 connector_status_disconnected);
187 }
188}
189
190static void lt9611uxc_reset(struct lt9611uxc *lt9611uxc)
191{
192 gpiod_set_value_cansleep(lt9611uxc->reset_gpio, 1);
193 msleep(20);
194
195 gpiod_set_value_cansleep(lt9611uxc->reset_gpio, 0);
196 msleep(20);
197
198 gpiod_set_value_cansleep(lt9611uxc->reset_gpio, 1);
199 msleep(300);
200}
201
202static void lt9611uxc_assert_5v(struct lt9611uxc *lt9611uxc)
203{
204 if (!lt9611uxc->enable_gpio)
205 return;
206
207 gpiod_set_value_cansleep(lt9611uxc->enable_gpio, 1);
208 msleep(20);
209}
210
211static int lt9611uxc_regulator_init(struct lt9611uxc *lt9611uxc)
212{
213 int ret;
214
215 lt9611uxc->supplies[0].supply = "vdd";
216 lt9611uxc->supplies[1].supply = "vcc";
217
218 ret = devm_regulator_bulk_get(lt9611uxc->dev, 2, lt9611uxc->supplies);
219 if (ret < 0)
220 return ret;
221
222 return regulator_set_load(lt9611uxc->supplies[0].consumer, 200000);
223}
224
225static int lt9611uxc_regulator_enable(struct lt9611uxc *lt9611uxc)
226{
227 int ret;
228
229 ret = regulator_enable(lt9611uxc->supplies[0].consumer);
230 if (ret < 0)
231 return ret;
232
233 usleep_range(1000, 10000); /* 50000 according to dtsi */
234
235 ret = regulator_enable(lt9611uxc->supplies[1].consumer);
236 if (ret < 0) {
237 regulator_disable(lt9611uxc->supplies[0].consumer);
238 return ret;
239 }
240
241 return 0;
242}
243
244static struct lt9611uxc_mode *lt9611uxc_find_mode(const struct drm_display_mode *mode)
245{
246 int i;
247
248 for (i = 0; i < ARRAY_SIZE(lt9611uxc_modes); i++) {
249 if (lt9611uxc_modes[i].hdisplay == mode->hdisplay &&
250 lt9611uxc_modes[i].vdisplay == mode->vdisplay &&
251 lt9611uxc_modes[i].vrefresh == drm_mode_vrefresh(mode)) {
252 return <9611uxc_modes[i];
253 }
254 }
255
256 return NULL;
257}
258
259static struct mipi_dsi_device *lt9611uxc_attach_dsi(struct lt9611uxc *lt9611uxc,
260 struct device_node *dsi_node)
261{
262 const struct mipi_dsi_device_info info = { "lt9611uxc", 0, NULL };
263 struct mipi_dsi_device *dsi;
264 struct mipi_dsi_host *host;
265 struct device *dev = lt9611uxc->dev;
266 int ret;
267
268 host = of_find_mipi_dsi_host_by_node(dsi_node);
269 if (!host)
270 return ERR_PTR(dev_err_probe(dev, -EPROBE_DEFER, "failed to find dsi host\n"));
271
272 dsi = devm_mipi_dsi_device_register_full(dev, host, &info);
273 if (IS_ERR(dsi)) {
274 dev_err(dev, "failed to create dsi device\n");
275 return dsi;
276 }
277
278 dsi->lanes = 4;
279 dsi->format = MIPI_DSI_FMT_RGB888;
280 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
281 MIPI_DSI_MODE_VIDEO_HSE;
282
283 ret = devm_mipi_dsi_attach(dev, dsi);
284 if (ret < 0) {
285 dev_err(dev, "failed to attach dsi to host\n");
286 return ERR_PTR(ret);
287 }
288
289 return dsi;
290}
291
292static int lt9611uxc_connector_get_modes(struct drm_connector *connector)
293{
294 struct lt9611uxc *lt9611uxc = connector_to_lt9611uxc(connector);
295 const struct drm_edid *drm_edid;
296 int count;
297
298 drm_edid = drm_bridge_edid_read(<9611uxc->bridge, connector);
299 drm_edid_connector_update(connector, drm_edid);
300 count = drm_edid_connector_add_modes(connector);
301 drm_edid_free(drm_edid);
302
303 return count;
304}
305
306static enum drm_connector_status lt9611uxc_connector_detect(struct drm_connector *connector,
307 bool force)
308{
309 struct lt9611uxc *lt9611uxc = connector_to_lt9611uxc(connector);
310
311 return lt9611uxc->bridge.funcs->detect(<9611uxc->bridge);
312}
313
314static enum drm_mode_status lt9611uxc_connector_mode_valid(struct drm_connector *connector,
315 struct drm_display_mode *mode)
316{
317 struct lt9611uxc_mode *lt9611uxc_mode = lt9611uxc_find_mode(mode);
318
319 return lt9611uxc_mode ? MODE_OK : MODE_BAD;
320}
321
322static const struct drm_connector_helper_funcs lt9611uxc_bridge_connector_helper_funcs = {
323 .get_modes = lt9611uxc_connector_get_modes,
324 .mode_valid = lt9611uxc_connector_mode_valid,
325};
326
327static const struct drm_connector_funcs lt9611uxc_bridge_connector_funcs = {
328 .fill_modes = drm_helper_probe_single_connector_modes,
329 .detect = lt9611uxc_connector_detect,
330 .destroy = drm_connector_cleanup,
331 .reset = drm_atomic_helper_connector_reset,
332 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
333 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
334};
335
336static int lt9611uxc_connector_init(struct drm_bridge *bridge, struct lt9611uxc *lt9611uxc)
337{
338 int ret;
339
340 if (!bridge->encoder) {
341 DRM_ERROR("Parent encoder object not found");
342 return -ENODEV;
343 }
344
345 lt9611uxc->connector.polled = DRM_CONNECTOR_POLL_HPD;
346
347 drm_connector_helper_add(<9611uxc->connector,
348 <9611uxc_bridge_connector_helper_funcs);
349 ret = drm_connector_init(bridge->dev, <9611uxc->connector,
350 <9611uxc_bridge_connector_funcs,
351 DRM_MODE_CONNECTOR_HDMIA);
352 if (ret) {
353 DRM_ERROR("Failed to initialize connector with drm\n");
354 return ret;
355 }
356
357 return drm_connector_attach_encoder(<9611uxc->connector, bridge->encoder);
358}
359
360static int lt9611uxc_bridge_attach(struct drm_bridge *bridge,
361 enum drm_bridge_attach_flags flags)
362{
363 struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
364 int ret;
365
366 if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) {
367 ret = lt9611uxc_connector_init(bridge, lt9611uxc);
368 if (ret < 0)
369 return ret;
370 }
371
372 return 0;
373}
374
375static enum drm_mode_status
376lt9611uxc_bridge_mode_valid(struct drm_bridge *bridge,
377 const struct drm_display_info *info,
378 const struct drm_display_mode *mode)
379{
380 struct lt9611uxc_mode *lt9611uxc_mode;
381
382 lt9611uxc_mode = lt9611uxc_find_mode(mode);
383
384 return lt9611uxc_mode ? MODE_OK : MODE_BAD;
385}
386
387static void lt9611uxc_video_setup(struct lt9611uxc *lt9611uxc,
388 const struct drm_display_mode *mode)
389{
390 u32 h_total, hactive, hsync_len, hfront_porch;
391 u32 v_total, vactive, vsync_len, vfront_porch;
392
393 h_total = mode->htotal;
394 v_total = mode->vtotal;
395
396 hactive = mode->hdisplay;
397 hsync_len = mode->hsync_end - mode->hsync_start;
398 hfront_porch = mode->hsync_start - mode->hdisplay;
399
400 vactive = mode->vdisplay;
401 vsync_len = mode->vsync_end - mode->vsync_start;
402 vfront_porch = mode->vsync_start - mode->vdisplay;
403
404 regmap_write(lt9611uxc->regmap, 0xd00d, (u8)(v_total / 256));
405 regmap_write(lt9611uxc->regmap, 0xd00e, (u8)(v_total % 256));
406
407 regmap_write(lt9611uxc->regmap, 0xd00f, (u8)(vactive / 256));
408 regmap_write(lt9611uxc->regmap, 0xd010, (u8)(vactive % 256));
409
410 regmap_write(lt9611uxc->regmap, 0xd011, (u8)(h_total / 256));
411 regmap_write(lt9611uxc->regmap, 0xd012, (u8)(h_total % 256));
412
413 regmap_write(lt9611uxc->regmap, 0xd013, (u8)(hactive / 256));
414 regmap_write(lt9611uxc->regmap, 0xd014, (u8)(hactive % 256));
415
416 regmap_write(lt9611uxc->regmap, 0xd015, (u8)(vsync_len % 256));
417
418 regmap_update_bits(lt9611uxc->regmap, 0xd016, 0xf, (u8)(hsync_len / 256));
419 regmap_write(lt9611uxc->regmap, 0xd017, (u8)(hsync_len % 256));
420
421 regmap_update_bits(lt9611uxc->regmap, 0xd018, 0xf, (u8)(vfront_porch / 256));
422 regmap_write(lt9611uxc->regmap, 0xd019, (u8)(vfront_porch % 256));
423
424 regmap_update_bits(lt9611uxc->regmap, 0xd01a, 0xf, (u8)(hfront_porch / 256));
425 regmap_write(lt9611uxc->regmap, 0xd01b, (u8)(hfront_porch % 256));
426}
427
428static void lt9611uxc_bridge_mode_set(struct drm_bridge *bridge,
429 const struct drm_display_mode *mode,
430 const struct drm_display_mode *adj_mode)
431{
432 struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
433
434 lt9611uxc_lock(lt9611uxc);
435 lt9611uxc_video_setup(lt9611uxc, mode);
436 lt9611uxc_unlock(lt9611uxc);
437}
438
439static enum drm_connector_status lt9611uxc_bridge_detect(struct drm_bridge *bridge)
440{
441 struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
442 unsigned int reg_val = 0;
443 int ret;
444 bool connected = true;
445
446 lt9611uxc_lock(lt9611uxc);
447
448 if (lt9611uxc->hpd_supported) {
449 ret = regmap_read(lt9611uxc->regmap, 0xb023, ®_val);
450
451 if (ret)
452 dev_err(lt9611uxc->dev, "failed to read hpd status: %d\n", ret);
453 else
454 connected = reg_val & BIT(1);
455 }
456 lt9611uxc->hdmi_connected = connected;
457
458 lt9611uxc_unlock(lt9611uxc);
459
460 return connected ? connector_status_connected :
461 connector_status_disconnected;
462}
463
464static int lt9611uxc_wait_for_edid(struct lt9611uxc *lt9611uxc)
465{
466 return wait_event_interruptible_timeout(lt9611uxc->wq, lt9611uxc->edid_read,
467 msecs_to_jiffies(500));
468}
469
470static int lt9611uxc_get_edid_block(void *data, u8 *buf, unsigned int block, size_t len)
471{
472 struct lt9611uxc *lt9611uxc = data;
473 int ret;
474
475 if (len > EDID_BLOCK_SIZE)
476 return -EINVAL;
477
478 if (block >= EDID_NUM_BLOCKS)
479 return -EINVAL;
480
481 lt9611uxc_lock(lt9611uxc);
482
483 regmap_write(lt9611uxc->regmap, 0xb00b, 0x10);
484
485 regmap_write(lt9611uxc->regmap, 0xb00a, block * EDID_BLOCK_SIZE);
486
487 ret = regmap_noinc_read(lt9611uxc->regmap, 0xb0b0, buf, len);
488 if (ret)
489 dev_err(lt9611uxc->dev, "edid read failed: %d\n", ret);
490
491 lt9611uxc_unlock(lt9611uxc);
492
493 return 0;
494};
495
496static const struct drm_edid *lt9611uxc_bridge_edid_read(struct drm_bridge *bridge,
497 struct drm_connector *connector)
498{
499 struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
500 int ret;
501
502 ret = lt9611uxc_wait_for_edid(lt9611uxc);
503 if (ret < 0) {
504 dev_err(lt9611uxc->dev, "wait for EDID failed: %d\n", ret);
505 return NULL;
506 } else if (ret == 0) {
507 dev_err(lt9611uxc->dev, "wait for EDID timeout\n");
508 return NULL;
509 }
510
511 return drm_edid_read_custom(connector, lt9611uxc_get_edid_block, lt9611uxc);
512}
513
514static const struct drm_bridge_funcs lt9611uxc_bridge_funcs = {
515 .attach = lt9611uxc_bridge_attach,
516 .mode_valid = lt9611uxc_bridge_mode_valid,
517 .mode_set = lt9611uxc_bridge_mode_set,
518 .detect = lt9611uxc_bridge_detect,
519 .edid_read = lt9611uxc_bridge_edid_read,
520};
521
522static int lt9611uxc_parse_dt(struct device *dev,
523 struct lt9611uxc *lt9611uxc)
524{
525 lt9611uxc->dsi0_node = of_graph_get_remote_node(dev->of_node, 0, -1);
526 if (!lt9611uxc->dsi0_node) {
527 dev_err(lt9611uxc->dev, "failed to get remote node for primary dsi\n");
528 return -ENODEV;
529 }
530
531 lt9611uxc->dsi1_node = of_graph_get_remote_node(dev->of_node, 1, -1);
532
533 return 0;
534}
535
536static int lt9611uxc_gpio_init(struct lt9611uxc *lt9611uxc)
537{
538 struct device *dev = lt9611uxc->dev;
539
540 lt9611uxc->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
541 if (IS_ERR(lt9611uxc->reset_gpio)) {
542 dev_err(dev, "failed to acquire reset gpio\n");
543 return PTR_ERR(lt9611uxc->reset_gpio);
544 }
545
546 lt9611uxc->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
547 if (IS_ERR(lt9611uxc->enable_gpio)) {
548 dev_err(dev, "failed to acquire enable gpio\n");
549 return PTR_ERR(lt9611uxc->enable_gpio);
550 }
551
552 return 0;
553}
554
555static int lt9611uxc_read_device_rev(struct lt9611uxc *lt9611uxc)
556{
557 unsigned int rev0, rev1, rev2;
558 int ret;
559
560 lt9611uxc_lock(lt9611uxc);
561
562 ret = regmap_read(lt9611uxc->regmap, 0x8100, &rev0);
563 ret |= regmap_read(lt9611uxc->regmap, 0x8101, &rev1);
564 ret |= regmap_read(lt9611uxc->regmap, 0x8102, &rev2);
565 if (ret)
566 dev_err(lt9611uxc->dev, "failed to read revision: %d\n", ret);
567 else
568 dev_info(lt9611uxc->dev, "LT9611 revision: 0x%02x.%02x.%02x\n", rev0, rev1, rev2);
569
570 lt9611uxc_unlock(lt9611uxc);
571
572 return ret;
573}
574
575static int lt9611uxc_read_version(struct lt9611uxc *lt9611uxc)
576{
577 unsigned int rev;
578 int ret;
579
580 lt9611uxc_lock(lt9611uxc);
581
582 ret = regmap_read(lt9611uxc->regmap, 0xb021, &rev);
583 if (ret)
584 dev_err(lt9611uxc->dev, "failed to read revision: %d\n", ret);
585 else
586 dev_info(lt9611uxc->dev, "LT9611 version: 0x%02x\n", rev);
587
588 lt9611uxc_unlock(lt9611uxc);
589
590 return ret < 0 ? ret : rev;
591}
592
593static int lt9611uxc_hdmi_hw_params(struct device *dev, void *data,
594 struct hdmi_codec_daifmt *fmt,
595 struct hdmi_codec_params *hparms)
596{
597 /*
598 * LT9611UXC will automatically detect rate and sample size, so no need
599 * to setup anything here.
600 */
601 return 0;
602}
603
604static void lt9611uxc_audio_shutdown(struct device *dev, void *data)
605{
606}
607
608static int lt9611uxc_hdmi_i2s_get_dai_id(struct snd_soc_component *component,
609 struct device_node *endpoint)
610{
611 struct of_endpoint of_ep;
612 int ret;
613
614 ret = of_graph_parse_endpoint(endpoint, &of_ep);
615 if (ret < 0)
616 return ret;
617
618 /*
619 * HDMI sound should be located as reg = <2>
620 * Then, it is sound port 0
621 */
622 if (of_ep.port == 2)
623 return 0;
624
625 return -EINVAL;
626}
627
628static const struct hdmi_codec_ops lt9611uxc_codec_ops = {
629 .hw_params = lt9611uxc_hdmi_hw_params,
630 .audio_shutdown = lt9611uxc_audio_shutdown,
631 .get_dai_id = lt9611uxc_hdmi_i2s_get_dai_id,
632};
633
634static int lt9611uxc_audio_init(struct device *dev, struct lt9611uxc *lt9611uxc)
635{
636 struct hdmi_codec_pdata codec_data = {
637 .ops = <9611uxc_codec_ops,
638 .max_i2s_channels = 2,
639 .i2s = 1,
640 .data = lt9611uxc,
641 };
642
643 lt9611uxc->audio_pdev =
644 platform_device_register_data(dev, HDMI_CODEC_DRV_NAME,
645 PLATFORM_DEVID_AUTO,
646 &codec_data, sizeof(codec_data));
647
648 return PTR_ERR_OR_ZERO(lt9611uxc->audio_pdev);
649}
650
651static void lt9611uxc_audio_exit(struct lt9611uxc *lt9611uxc)
652{
653 if (lt9611uxc->audio_pdev) {
654 platform_device_unregister(lt9611uxc->audio_pdev);
655 lt9611uxc->audio_pdev = NULL;
656 }
657}
658
659#define LT9611UXC_FW_PAGE_SIZE 32
660static void lt9611uxc_firmware_write_page(struct lt9611uxc *lt9611uxc, u16 addr, const u8 *buf)
661{
662 struct reg_sequence seq_write_prepare[] = {
663 REG_SEQ0(0x805a, 0x04),
664 REG_SEQ0(0x805a, 0x00),
665
666 REG_SEQ0(0x805e, 0xdf),
667 REG_SEQ0(0x805a, 0x20),
668 REG_SEQ0(0x805a, 0x00),
669 REG_SEQ0(0x8058, 0x21),
670 };
671
672 struct reg_sequence seq_write_addr[] = {
673 REG_SEQ0(0x805b, (addr >> 16) & 0xff),
674 REG_SEQ0(0x805c, (addr >> 8) & 0xff),
675 REG_SEQ0(0x805d, addr & 0xff),
676 REG_SEQ0(0x805a, 0x10),
677 REG_SEQ0(0x805a, 0x00),
678 };
679
680 regmap_write(lt9611uxc->regmap, 0x8108, 0xbf);
681 msleep(20);
682 regmap_write(lt9611uxc->regmap, 0x8108, 0xff);
683 msleep(20);
684 regmap_multi_reg_write(lt9611uxc->regmap, seq_write_prepare, ARRAY_SIZE(seq_write_prepare));
685 regmap_noinc_write(lt9611uxc->regmap, 0x8059, buf, LT9611UXC_FW_PAGE_SIZE);
686 regmap_multi_reg_write(lt9611uxc->regmap, seq_write_addr, ARRAY_SIZE(seq_write_addr));
687 msleep(20);
688}
689
690static void lt9611uxc_firmware_read_page(struct lt9611uxc *lt9611uxc, u16 addr, char *buf)
691{
692 struct reg_sequence seq_read_page[] = {
693 REG_SEQ0(0x805a, 0xa0),
694 REG_SEQ0(0x805a, 0x80),
695 REG_SEQ0(0x805b, (addr >> 16) & 0xff),
696 REG_SEQ0(0x805c, (addr >> 8) & 0xff),
697 REG_SEQ0(0x805d, addr & 0xff),
698 REG_SEQ0(0x805a, 0x90),
699 REG_SEQ0(0x805a, 0x80),
700 REG_SEQ0(0x8058, 0x21),
701 };
702
703 regmap_multi_reg_write(lt9611uxc->regmap, seq_read_page, ARRAY_SIZE(seq_read_page));
704 regmap_noinc_read(lt9611uxc->regmap, 0x805f, buf, LT9611UXC_FW_PAGE_SIZE);
705}
706
707static char *lt9611uxc_firmware_read(struct lt9611uxc *lt9611uxc, size_t size)
708{
709 struct reg_sequence seq_read_setup[] = {
710 REG_SEQ0(0x805a, 0x84),
711 REG_SEQ0(0x805a, 0x80),
712 };
713
714 char *readbuf;
715 u16 offset;
716
717 readbuf = kzalloc(ALIGN(size, 32), GFP_KERNEL);
718 if (!readbuf)
719 return NULL;
720
721 regmap_multi_reg_write(lt9611uxc->regmap, seq_read_setup, ARRAY_SIZE(seq_read_setup));
722
723 for (offset = 0;
724 offset < size;
725 offset += LT9611UXC_FW_PAGE_SIZE)
726 lt9611uxc_firmware_read_page(lt9611uxc, offset, &readbuf[offset]);
727
728 return readbuf;
729}
730
731static int lt9611uxc_firmware_update(struct lt9611uxc *lt9611uxc)
732{
733 int ret;
734 u16 offset;
735 size_t remain;
736 char *readbuf;
737 const struct firmware *fw;
738
739 struct reg_sequence seq_setup[] = {
740 REG_SEQ0(0x805e, 0xdf),
741 REG_SEQ0(0x8058, 0x00),
742 REG_SEQ0(0x8059, 0x50),
743 REG_SEQ0(0x805a, 0x10),
744 REG_SEQ0(0x805a, 0x00),
745 };
746
747
748 struct reg_sequence seq_block_erase[] = {
749 REG_SEQ0(0x805a, 0x04),
750 REG_SEQ0(0x805a, 0x00),
751 REG_SEQ0(0x805b, 0x00),
752 REG_SEQ0(0x805c, 0x00),
753 REG_SEQ0(0x805d, 0x00),
754 REG_SEQ0(0x805a, 0x01),
755 REG_SEQ0(0x805a, 0x00),
756 };
757
758 ret = request_firmware(&fw, FW_FILE, lt9611uxc->dev);
759 if (ret < 0)
760 return ret;
761
762 dev_info(lt9611uxc->dev, "Updating firmware\n");
763 lt9611uxc_lock(lt9611uxc);
764
765 regmap_multi_reg_write(lt9611uxc->regmap, seq_setup, ARRAY_SIZE(seq_setup));
766
767 /*
768 * Need erase block 2 timess here. Sometimes, block erase can fail.
769 * This is a workaroud.
770 */
771 regmap_multi_reg_write(lt9611uxc->regmap, seq_block_erase, ARRAY_SIZE(seq_block_erase));
772 msleep(3000);
773 regmap_multi_reg_write(lt9611uxc->regmap, seq_block_erase, ARRAY_SIZE(seq_block_erase));
774 msleep(3000);
775
776 for (offset = 0, remain = fw->size;
777 remain >= LT9611UXC_FW_PAGE_SIZE;
778 offset += LT9611UXC_FW_PAGE_SIZE, remain -= LT9611UXC_FW_PAGE_SIZE)
779 lt9611uxc_firmware_write_page(lt9611uxc, offset, fw->data + offset);
780
781 if (remain > 0) {
782 char buf[LT9611UXC_FW_PAGE_SIZE];
783
784 memset(buf, 0xff, LT9611UXC_FW_PAGE_SIZE);
785 memcpy(buf, fw->data + offset, remain);
786 lt9611uxc_firmware_write_page(lt9611uxc, offset, buf);
787 }
788 msleep(20);
789
790 readbuf = lt9611uxc_firmware_read(lt9611uxc, fw->size);
791 if (!readbuf) {
792 ret = -ENOMEM;
793 goto out;
794 }
795
796 if (!memcmp(readbuf, fw->data, fw->size)) {
797 dev_err(lt9611uxc->dev, "Firmware update failed\n");
798 print_hex_dump(KERN_ERR, "fw: ", DUMP_PREFIX_OFFSET, 16, 1, readbuf, fw->size, false);
799 ret = -EINVAL;
800 } else {
801 dev_info(lt9611uxc->dev, "Firmware updates successfully\n");
802 ret = 0;
803 }
804 kfree(readbuf);
805
806out:
807 lt9611uxc_unlock(lt9611uxc);
808 lt9611uxc_reset(lt9611uxc);
809 release_firmware(fw);
810
811 return ret;
812}
813
814static ssize_t lt9611uxc_firmware_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
815{
816 struct lt9611uxc *lt9611uxc = dev_get_drvdata(dev);
817 int ret;
818
819 ret = lt9611uxc_firmware_update(lt9611uxc);
820 if (ret < 0)
821 return ret;
822 return len;
823}
824
825static ssize_t lt9611uxc_firmware_show(struct device *dev, struct device_attribute *attr, char *buf)
826{
827 struct lt9611uxc *lt9611uxc = dev_get_drvdata(dev);
828
829 return sysfs_emit(buf, "%02x\n", lt9611uxc->fw_version);
830}
831
832static DEVICE_ATTR_RW(lt9611uxc_firmware);
833
834static struct attribute *lt9611uxc_attrs[] = {
835 &dev_attr_lt9611uxc_firmware.attr,
836 NULL,
837};
838
839static const struct attribute_group lt9611uxc_attr_group = {
840 .attrs = lt9611uxc_attrs,
841};
842
843static const struct attribute_group *lt9611uxc_attr_groups[] = {
844 <9611uxc_attr_group,
845 NULL,
846};
847
848static int lt9611uxc_probe(struct i2c_client *client)
849{
850 struct lt9611uxc *lt9611uxc;
851 struct device *dev = &client->dev;
852 int ret;
853 bool fw_updated = false;
854
855 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
856 dev_err(dev, "device doesn't support I2C\n");
857 return -ENODEV;
858 }
859
860 lt9611uxc = devm_kzalloc(dev, sizeof(*lt9611uxc), GFP_KERNEL);
861 if (!lt9611uxc)
862 return -ENOMEM;
863
864 lt9611uxc->dev = dev;
865 lt9611uxc->client = client;
866 mutex_init(<9611uxc->ocm_lock);
867
868 lt9611uxc->regmap = devm_regmap_init_i2c(client, <9611uxc_regmap_config);
869 if (IS_ERR(lt9611uxc->regmap)) {
870 dev_err(lt9611uxc->dev, "regmap i2c init failed\n");
871 return PTR_ERR(lt9611uxc->regmap);
872 }
873
874 ret = lt9611uxc_parse_dt(dev, lt9611uxc);
875 if (ret) {
876 dev_err(dev, "failed to parse device tree\n");
877 return ret;
878 }
879
880 ret = lt9611uxc_gpio_init(lt9611uxc);
881 if (ret < 0)
882 goto err_of_put;
883
884 ret = lt9611uxc_regulator_init(lt9611uxc);
885 if (ret < 0)
886 goto err_of_put;
887
888 lt9611uxc_assert_5v(lt9611uxc);
889
890 ret = lt9611uxc_regulator_enable(lt9611uxc);
891 if (ret)
892 goto err_of_put;
893
894 lt9611uxc_reset(lt9611uxc);
895
896 ret = lt9611uxc_read_device_rev(lt9611uxc);
897 if (ret) {
898 dev_err(dev, "failed to read chip rev\n");
899 goto err_disable_regulators;
900 }
901
902retry:
903 ret = lt9611uxc_read_version(lt9611uxc);
904 if (ret < 0) {
905 dev_err(dev, "failed to read FW version\n");
906 goto err_disable_regulators;
907 } else if (ret == 0) {
908 if (!fw_updated) {
909 fw_updated = true;
910 dev_err(dev, "FW version 0, enforcing firmware update\n");
911 ret = lt9611uxc_firmware_update(lt9611uxc);
912 if (ret < 0)
913 goto err_disable_regulators;
914 else
915 goto retry;
916 } else {
917 dev_err(dev, "FW version 0, update failed\n");
918 ret = -EOPNOTSUPP;
919 goto err_disable_regulators;
920 }
921 } else if (ret < 0x40) {
922 dev_info(dev, "FW version 0x%x, HPD not supported\n", ret);
923 } else {
924 lt9611uxc->hpd_supported = true;
925 }
926 lt9611uxc->fw_version = ret;
927
928 init_waitqueue_head(<9611uxc->wq);
929 INIT_WORK(<9611uxc->work, lt9611uxc_hpd_work);
930
931 ret = request_threaded_irq(client->irq, NULL,
932 lt9611uxc_irq_thread_handler,
933 IRQF_ONESHOT, "lt9611uxc", lt9611uxc);
934 if (ret) {
935 dev_err(dev, "failed to request irq\n");
936 goto err_disable_regulators;
937 }
938
939 i2c_set_clientdata(client, lt9611uxc);
940
941 lt9611uxc->bridge.funcs = <9611uxc_bridge_funcs;
942 lt9611uxc->bridge.of_node = client->dev.of_node;
943 lt9611uxc->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID;
944 if (lt9611uxc->hpd_supported)
945 lt9611uxc->bridge.ops |= DRM_BRIDGE_OP_HPD;
946 lt9611uxc->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
947
948 drm_bridge_add(<9611uxc->bridge);
949
950 /* Attach primary DSI */
951 lt9611uxc->dsi0 = lt9611uxc_attach_dsi(lt9611uxc, lt9611uxc->dsi0_node);
952 if (IS_ERR(lt9611uxc->dsi0)) {
953 ret = PTR_ERR(lt9611uxc->dsi0);
954 goto err_remove_bridge;
955 }
956
957 /* Attach secondary DSI, if specified */
958 if (lt9611uxc->dsi1_node) {
959 lt9611uxc->dsi1 = lt9611uxc_attach_dsi(lt9611uxc, lt9611uxc->dsi1_node);
960 if (IS_ERR(lt9611uxc->dsi1)) {
961 ret = PTR_ERR(lt9611uxc->dsi1);
962 goto err_remove_bridge;
963 }
964 }
965
966 return lt9611uxc_audio_init(dev, lt9611uxc);
967
968err_remove_bridge:
969 free_irq(client->irq, lt9611uxc);
970 cancel_work_sync(<9611uxc->work);
971 drm_bridge_remove(<9611uxc->bridge);
972
973err_disable_regulators:
974 regulator_bulk_disable(ARRAY_SIZE(lt9611uxc->supplies), lt9611uxc->supplies);
975
976err_of_put:
977 of_node_put(lt9611uxc->dsi1_node);
978 of_node_put(lt9611uxc->dsi0_node);
979
980 return ret;
981}
982
983static void lt9611uxc_remove(struct i2c_client *client)
984{
985 struct lt9611uxc *lt9611uxc = i2c_get_clientdata(client);
986
987 free_irq(client->irq, lt9611uxc);
988 cancel_work_sync(<9611uxc->work);
989 lt9611uxc_audio_exit(lt9611uxc);
990 drm_bridge_remove(<9611uxc->bridge);
991
992 mutex_destroy(<9611uxc->ocm_lock);
993
994 regulator_bulk_disable(ARRAY_SIZE(lt9611uxc->supplies), lt9611uxc->supplies);
995
996 of_node_put(lt9611uxc->dsi1_node);
997 of_node_put(lt9611uxc->dsi0_node);
998}
999
1000static struct i2c_device_id lt9611uxc_id[] = {
1001 { "lontium,lt9611uxc", 0 },
1002 { /* sentinel */ }
1003};
1004
1005static const struct of_device_id lt9611uxc_match_table[] = {
1006 { .compatible = "lontium,lt9611uxc" },
1007 { /* sentinel */ }
1008};
1009MODULE_DEVICE_TABLE(of, lt9611uxc_match_table);
1010
1011static struct i2c_driver lt9611uxc_driver = {
1012 .driver = {
1013 .name = "lt9611uxc",
1014 .of_match_table = lt9611uxc_match_table,
1015 .dev_groups = lt9611uxc_attr_groups,
1016 },
1017 .probe = lt9611uxc_probe,
1018 .remove = lt9611uxc_remove,
1019 .id_table = lt9611uxc_id,
1020};
1021module_i2c_driver(lt9611uxc_driver);
1022
1023MODULE_AUTHOR("Dmitry Baryshkov <dmitry.baryshkov@linaro.org>");
1024MODULE_LICENSE("GPL v2");
1025
1026MODULE_FIRMWARE(FW_FILE);