hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2023 Rockchip Electronics Co. Ltd.
 */
 
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/notifier.h>
#include <linux/fb.h>
#include <linux/regmap.h>
#include <linux/clk.h>
#include "lt7911d-fw.h"
 
struct lt7911d {
   struct device *dev;
   struct regmap *regmap;
   struct serdes_init_seq *serdes_init_seq;
   struct gpio_desc *reset_gpio;
   struct gpio_desc *enable_gpio;
   struct notifier_block fb_notif;
   int fb_blank;
};
 
static int Datalen = 17594;
/*to save hdcp key */
static unsigned char HdcpKey[286];
/*the buffer to read flash, its size should be equal the size of bin, max size is 24KB*/
static unsigned char ReadFirmware[17594];
/*The buffer to read flash, hex->bin->txt*/
//static unsigned char FirmwareData[17594];
 
static int I2C_Write_Byte(struct lt7911d *lt7911d, unsigned char reg, unsigned char val)
{
   int ret;
 
   ret = regmap_write(lt7911d->regmap, reg, val);
   if (ret < 0) {
       pr_info("failed to write lt7911d register 0x%x: %d\n", reg, ret);
       return ret;
   }
   return 0;
}
 
static unsigned char I2C_Read_Byte(struct lt7911d *lt7911d, unsigned char reg)
{
   int ret;
   unsigned int val;
 
   ret = regmap_read(lt7911d->regmap, reg, &val);
   if (ret < 0) {
       pr_info("failed to read lt7911d register 0x%x: %d\n", reg, ret);
       return ret;
   }
 
   return (unsigned char)val;
}
 
static bool lt7911d_check_chip_id(struct lt7911d *lt7911d)
{
   unsigned char id_h, id_l;
 
   /*0x80ee=0x01 to enable i2c interface*/
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x01);
   /*write bank 0xa0, read 0xa000 and 0xa001*/
   I2C_Write_Byte(lt7911d, 0xFF, 0xA0);
   id_h = I2C_Read_Byte(lt7911d, 0x00);
   id_l = I2C_Read_Byte(lt7911d, 0x01);
 
   /*chip id=0x1605*/
   if ((id_h == 0x16) && (id_l == 0x05)) {
       pr_info("%s chip id =0x1605\n", __func__);
       /*0x80ee=0x00 to disable i2c*/
       I2C_Write_Byte(lt7911d, 0xFF, 0x80);
       I2C_Write_Byte(lt7911d, 0xEE, 0x00);
       return true;
   } else {
       pr_info("%s chip id 0x%x is not 0x1605\n", __func__, (id_h << 8) | id_l);
       /*0x80ee=0x00 to disable i2c*/
       I2C_Write_Byte(lt7911d, 0xFF, 0x80);
       I2C_Write_Byte(lt7911d, 0xEE, 0x00);
       return false;
   }
}
 
static int lt7911d_check_fw_version(struct lt7911d *lt7911d)
{
   unsigned char fw;
 
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x01);
 
   /*read 0xD211*/
   I2C_Write_Byte(lt7911d, 0xFF, 0xD2);
   fw = I2C_Read_Byte(lt7911d, 0x11);
 
   /*fw version address is 0x1dfb*/
   if (fw < FirmwareData[0x1dfb]) {
       pr_info("%s fw %d<%d, need to upgrade\n", __func__, fw, FirmwareData[0x1dfb]);
       I2C_Write_Byte(lt7911d, 0xFF, 0x80);
       I2C_Write_Byte(lt7911d, 0xEE, 0x00);
       return 0;
   } else {
       pr_info("%s fw %d>=%d, no need upgrade\n", __func__, fw, FirmwareData[0x1dfb]);
       I2C_Write_Byte(lt7911d, 0xFF, 0x80);
       I2C_Write_Byte(lt7911d, 0xEE, 0x00);
       return -1;
   }
}
 
static void lt7911d_config_para(struct lt7911d *lt7911d)
{
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x01);
   I2C_Write_Byte(lt7911d, 0x5A, 0x82);
   I2C_Write_Byte(lt7911d, 0x5E, 0xC0);
   I2C_Write_Byte(lt7911d, 0x58, 0x00);
   I2C_Write_Byte(lt7911d, 0x59, 0x51);
   I2C_Write_Byte(lt7911d, 0x5A, 0x92);
   I2C_Write_Byte(lt7911d, 0x5A, 0x82);
}
 
static void lt7911d_block_erase(struct lt7911d *lt7911d)
{
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x01);
   I2C_Write_Byte(lt7911d, 0x5A, 0x86);
   I2C_Write_Byte(lt7911d, 0x5A, 0x82);
   I2C_Write_Byte(lt7911d, 0x5B, 0x00);
   I2C_Write_Byte(lt7911d, 0x5C, 0x00);
   I2C_Write_Byte(lt7911d, 0x5D, 0x00);
   I2C_Write_Byte(lt7911d, 0x5A, 0x83);
   I2C_Write_Byte(lt7911d, 0x5A, 0x82);
 
   /*The time to waiting for earse flash*/
   msleep(500);
}
 
/*If earse flash will erase the hdcp key, so need to backup firstly*/
static void SaveHdcpKeyFromFlash(struct lt7911d *lt7911d)
{
   unsigned int StartAddr;
   unsigned int npage, i, j;
   unsigned char npagelen = 0;
   unsigned char addr[3] = {0};
 
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x01);
   I2C_Write_Byte(lt7911d, 0xFF, 0x90);
   I2C_Write_Byte(lt7911d, 0x02, 0xdf);
   I2C_Write_Byte(lt7911d, 0x02, 0xff);
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0x5a, 0x86);
   I2C_Write_Byte(lt7911d, 0x5a, 0x82);
 
   /*The first address of HDCP KEY*/
   StartAddr = 0x006000;
   addr[0] = (StartAddr & 0xFF0000) >> 16;
   addr[1] = (StartAddr & 0xFF00) >> 8;
   addr[2] = StartAddr & 0xFF;
 
   /*hdcp key size is 286 byte*/
   npage = 18;
   npagelen = 16;
 
   for (i = 0; i < npage; i++) {
       I2C_Write_Byte(lt7911d, 0x5E, 0x6f);
       I2C_Write_Byte(lt7911d, 0x5A, 0xA2);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
       I2C_Write_Byte(lt7911d, 0x5B, addr[0]);
       I2C_Write_Byte(lt7911d, 0x5C, addr[1]);
       I2C_Write_Byte(lt7911d, 0x5D, addr[2]);
       I2C_Write_Byte(lt7911d, 0x5A, 0x92);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
       I2C_Write_Byte(lt7911d, 0x58, 0x01);
 
       if (i == 17)
           npagelen = 14;
 
       for (j = 0; j < npagelen; j++)
           HdcpKey[i * 16 + j] = I2C_Read_Byte(lt7911d, 0x5F);
 
       StartAddr += 16;
       addr[0] = (StartAddr & 0xFF0000) >> 16;
       addr[1] = (StartAddr & 0xFF00) >> 8;
       addr[2] = StartAddr & 0xFF;
   }
 
   I2C_Write_Byte(lt7911d, 0x5a, 0x8a);
   I2C_Write_Byte(lt7911d, 0x5a, 0x82);
}
 
static void lt7911d_write_firmware_to_flash(struct lt7911d *lt7911d)
{
   unsigned int StartAddr;
   unsigned int npage, i, j;
   unsigned char npagelen = 0;
   unsigned char addr[3] = {0};
 
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x01);
   I2C_Write_Byte(lt7911d, 0xFF, 0x90);
   I2C_Write_Byte(lt7911d, 0x02, 0xdf);
   I2C_Write_Byte(lt7911d, 0x02, 0xff);
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0x5a, 0x86);
   I2C_Write_Byte(lt7911d, 0x5a, 0x82);
 
   /*The first address of flash£¬Max Size 24K*/
   StartAddr = 0x000000;
   addr[0] = (StartAddr & 0xFF0000) >> 16;
   addr[1] = (StartAddr & 0xFF00) >> 8;
   addr[2] = StartAddr & 0xFF;
 
   if (Datalen % 16) {
       /*Datalen is the length of the firmware.*/
       npage = Datalen / 16 + 1;
   } else {
       npage = Datalen / 16;
   }
   npagelen = 16;
 
   for (i = 0; i < npage; i++) {
       I2C_Write_Byte(lt7911d, 0x5A, 0x86);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
 
       I2C_Write_Byte(lt7911d, 0x5E, 0xef);
       I2C_Write_Byte(lt7911d, 0x5A, 0xA2);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
       I2C_Write_Byte(lt7911d, 0x58, 0x01);
 
       if ((Datalen - i * 16) < 16)
           npagelen = Datalen - i*16;
 
       for (j = 0; j < npagelen; j++) {
           /*please just continue to write data to 0x59,*/
           /*and lt7911d will increase the address auto use 0xff*/
           /*as insufficient data if datelen%16 is not zero*/
           I2C_Write_Byte(lt7911d, 0x59, FirmwareData[i*16 + j]);
       }
 
       /*change the first address*/
       I2C_Write_Byte(lt7911d, 0x5B, addr[0]);
       I2C_Write_Byte(lt7911d, 0x5C, addr[1]);
       I2C_Write_Byte(lt7911d, 0x5D, addr[2]);
       I2C_Write_Byte(lt7911d, 0x5E, 0xE0);
       I2C_Write_Byte(lt7911d, 0x5A, 0x92);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
 
       StartAddr += 16;
       addr[0] = (StartAddr & 0xFF0000) >> 16;
       addr[1] = (StartAddr & 0xFF00) >> 8;
       addr[2] = StartAddr & 0xFF;
   }
 
   I2C_Write_Byte(lt7911d, 0x5a, 0x8a);
   I2C_Write_Byte(lt7911d, 0x5a, 0x82);
 
   /*reset fifo*/
   I2C_Write_Byte(lt7911d, 0xFF, 0x90);
   I2C_Write_Byte(lt7911d, 0x02, 0xDF);
   I2C_Write_Byte(lt7911d, 0x02, 0xFF);
   msleep(20);
}
 
static void lt7911d_write_hdcpkey_to_flash(struct lt7911d *lt7911d)
{
   unsigned int StartAddr;
   unsigned int npage, i, j;
   unsigned char npagelen = 0;
   unsigned char addr[3] = {0};
 
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x01);
   I2C_Write_Byte(lt7911d, 0xFF, 0x90);
   I2C_Write_Byte(lt7911d, 0x02, 0xdf);
   I2C_Write_Byte(lt7911d, 0x02, 0xff);
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0x5a, 0x86);
   I2C_Write_Byte(lt7911d, 0x5a, 0x82);
 
   /*hdcp key first address*/
   StartAddr = 0x006000;
   addr[0] = (StartAddr & 0xFF0000) >> 16;
   addr[1] = (StartAddr & 0xFF00) >> 8;
   addr[2] = StartAddr & 0xFF;
 
   npage = 18;
   npagelen = 16;
 
   for (i = 0; i < npage; i++) {
       I2C_Write_Byte(lt7911d, 0x5A, 0x86);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
 
       I2C_Write_Byte(lt7911d, 0x5E, 0xef);
       I2C_Write_Byte(lt7911d, 0x5A, 0xA2);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
       I2C_Write_Byte(lt7911d, 0x58, 0x01);
 
       if (i == 17)
           npagelen = 14;
 
       for (j = 0; j < npagelen; j++) {
           /*please just continue to write data to 0x59,*/
           /*and lt7911d will increase the address auto use 0xff*/
           /*as insufficient data if datelen%16 is not zero .*/
           I2C_Write_Byte(lt7911d, 0x59, HdcpKey[i*16 + j]);
       }
 
       if (npagelen == 14) {
           I2C_Write_Byte(lt7911d, 0x59, 0xFF);
           I2C_Write_Byte(lt7911d, 0x59, 0xFF);
       }
 
       /*change the first address*/
       I2C_Write_Byte(lt7911d, 0x5B, addr[0]);
       I2C_Write_Byte(lt7911d, 0x5C, addr[1]);
       I2C_Write_Byte(lt7911d, 0x5D, addr[2]);
       I2C_Write_Byte(lt7911d, 0x5E, 0xE0);
       I2C_Write_Byte(lt7911d, 0x5A, 0x92);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
 
       StartAddr += 16;
       addr[0] = (StartAddr & 0xFF0000) >> 16;
       addr[1] = (StartAddr & 0xFF00) >> 8;
       addr[2] = StartAddr & 0xFF;
   }
 
   I2C_Write_Byte(lt7911d, 0x5a, 0x8a);
   I2C_Write_Byte(lt7911d, 0x5a, 0x82);
 
   /*reset fifo*/
   I2C_Write_Byte(lt7911d, 0xFF, 0x90);
   I2C_Write_Byte(lt7911d, 0x02, 0xDF);
   I2C_Write_Byte(lt7911d, 0x02, 0xFF);
   msleep(20);
}
 
static void lt7911d_read_firmware_from_flash(struct lt7911d *lt7911d)
{
   unsigned int StartAddr;
   unsigned int npage, i, j;
   unsigned char npagelen = 0;
   unsigned char addr[3] = {0};
 
   memset(ReadFirmware, 0, sizeof(ReadFirmware));
 
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x01);
   I2C_Write_Byte(lt7911d, 0xFF, 0x90);
   I2C_Write_Byte(lt7911d, 0x02, 0xdf);
   I2C_Write_Byte(lt7911d, 0x02, 0xff);
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0x5a, 0x86);
   I2C_Write_Byte(lt7911d, 0x5a, 0x82);
 
   /*the first address of firmware*/
   StartAddr = 0x000000;
   addr[0] = (StartAddr & 0xFF0000) >> 16;
   addr[1] = (StartAddr & 0xFF00) >> 8;
   addr[2] = StartAddr & 0xFF;
 
   if (Datalen % 16)
       npage = Datalen / 16 + 1;
   else
       npage = Datalen / 16;
 
   npagelen = 16;
 
   for (i = 0; i < npage; i++) {
       I2C_Write_Byte(lt7911d, 0x5E, 0x6f);
       I2C_Write_Byte(lt7911d, 0x5A, 0xA2);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
       I2C_Write_Byte(lt7911d, 0x5B, addr[0]);
       I2C_Write_Byte(lt7911d, 0x5C, addr[1]);
       I2C_Write_Byte(lt7911d, 0x5D, addr[2]);
       I2C_Write_Byte(lt7911d, 0x5A, 0x92);
       I2C_Write_Byte(lt7911d, 0x5A, 0x82);
       I2C_Write_Byte(lt7911d, 0x58, 0x01);
 
       if ((Datalen - i * 16) < 16)
           npagelen = Datalen - i*16;
 
       for (j = 0; j < npagelen; j++) {
           /*please just continue to read data from 0x5f*/
           /*lt7911d will increase the address auto*/
           ReadFirmware[i*16 + j] = I2C_Read_Byte(lt7911d, 0x5F);
       }
 
       StartAddr += 16;
       /*change the first address*/
       addr[0] = (StartAddr & 0xFF0000) >> 16;
       addr[1] = (StartAddr & 0xFF00) >> 8;
       addr[2] = StartAddr & 0xFF;
   }
 
   I2C_Write_Byte(lt7911d, 0x5a, 0x8a);
   I2C_Write_Byte(lt7911d, 0x5a, 0x82);
}
 
static int lt7911_compare_firmware(struct lt7911d *lt7911d)
{
   unsigned int len;
 
   for (len = 0; len < Datalen; len++) {
       if (ReadFirmware[len] != FirmwareData[len]) {
           pr_info("%s: ReadFirmware[%d] 0x%x !=  0x%x FirmwareData[%d]\n",
                   __func__, len, ReadFirmware[len], FirmwareData[len], len);
           return -1;
       }
   }
   return 0;
}
 
static int lt7911d_firmware_upgrade(struct lt7911d *lt7911d)
{
   int ret = 0;
 
   if (lt7911d_check_chip_id(lt7911d)) {
       if (lt7911d_check_fw_version(lt7911d) == 0) {
           lt7911d_config_para(lt7911d);
           SaveHdcpKeyFromFlash(lt7911d);
           lt7911d_block_erase(lt7911d);
           lt7911d_write_firmware_to_flash(lt7911d);
           lt7911d_write_hdcpkey_to_flash(lt7911d);
           lt7911d_read_firmware_from_flash(lt7911d);
 
           if (!lt7911_compare_firmware(lt7911d)) {
               pr_info("%s: upgrade success\n", __func__);
               ret = 0;
           } else {
               pr_info("%s: upgrade Fail\n", __func__);
               ret = -1;
           }
       }
   } else {
       pr_info("the chip lt7911d is offline\n");
       ret = 0;
   }
 
   I2C_Write_Byte(lt7911d, 0xFF, 0x80);
   I2C_Write_Byte(lt7911d, 0xEE, 0x00);
 
   return ret;
}
 
static const struct regmap_config lt7911d_regmap_config = {
   .name = "lt7911d",
   .reg_bits = 8,
   .val_bits = 8,
   .max_register = 0x100,
};
 
static int lt7911d_fb_notifier_callback(struct notifier_block *self,
                   unsigned long event, void *data)
{
   struct lt7911d *lt7911d = container_of(self, struct lt7911d, fb_notif);
   struct fb_event *evdata = data;
   int fb_blank = *(int *)evdata->data;
 
   if (event != FB_EVENT_BLANK)
       return 0;
 
   if (lt7911d->fb_blank == fb_blank)
       return 0;
 
   if (fb_blank == FB_BLANK_UNBLANK) {
       if (lt7911d->reset_gpio) {
           gpiod_direction_output(lt7911d->reset_gpio, 1);
           msleep(20);
           gpiod_direction_output(lt7911d->reset_gpio, 0);
           msleep(400);
       }
   }
 
   lt7911d->fb_blank = fb_blank;
 
   return 0;
}
 
static int lt7911d_i2c_probe(struct i2c_client *client,
                 const struct i2c_device_id *id)
{
   struct device *dev = &client->dev;
   struct lt7911d *lt7911d;
   int ret = 0, i = 0;
 
   lt7911d = devm_kzalloc(dev, sizeof(*lt7911d), GFP_KERNEL);
   if (!lt7911d)
       return -ENOMEM;
 
   lt7911d->dev = dev;
   i2c_set_clientdata(client, lt7911d);
 
   lt7911d->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
   if (IS_ERR(lt7911d->reset_gpio))
       return dev_err_probe(dev, PTR_ERR(lt7911d->reset_gpio),
                    "failed to acquire reset gpio\n");
 
   gpiod_set_consumer_name(lt7911d->reset_gpio, "lt7911d-reset");
 
   lt7911d->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
   if (IS_ERR(lt7911d->enable_gpio))
       return dev_err_probe(dev, PTR_ERR(lt7911d->enable_gpio),
                    "failed to acquire enable gpio\n");
 
   lt7911d->regmap = devm_regmap_init_i2c(client, &lt7911d_regmap_config);
   if (IS_ERR(lt7911d->regmap))
       return dev_err_probe(dev, PTR_ERR(lt7911d->regmap),
                    "failed to initialize regmap\n");
 
   lt7911d->fb_blank = FB_BLANK_UNBLANK;
   lt7911d->fb_notif.notifier_call = lt7911d_fb_notifier_callback;
   ret = fb_register_client(&lt7911d->fb_notif);
   if (ret)
       return dev_err_probe(dev, ret, "failed to register fb client\n");
 
   for (i = 0; i < 3; i++) {
       if (!lt7911d_firmware_upgrade(lt7911d))
           break;
   }
 
   dev_info(dev, "%s end\n", __func__);
 
   return 0;
}
 
static void lt7911d_i2c_shutdown(struct i2c_client *client)
{
   struct lt7911d *lt7911d = i2c_get_clientdata(client);
 
   gpiod_direction_output(lt7911d->reset_gpio, 1);
   msleep(20);
}
 
static int lt7911d_i2c_remove(struct i2c_client *client)
{
   struct lt7911d *lt7911d = i2c_get_clientdata(client);
 
   fb_unregister_client(&lt7911d->fb_notif);
 
   return 0;
}
 
static const struct i2c_device_id lt7911d_i2c_table[] = {
   { "lt7911d", 0 },
   {}
};
MODULE_DEVICE_TABLE(i2c, lt7911d_i2c_table);
 
static const struct of_device_id lt7911d_of_match[] = {
   { .compatible = "lontium,lt7911d-fb-notifier" },
   {}
};
MODULE_DEVICE_TABLE(of, lt7911d_of_match);
 
static struct i2c_driver lt7911d_i2c_driver = {
   .driver = {
       .name = "lt7911d",
       .of_match_table = lt7911d_of_match,
   },
   .probe = lt7911d_i2c_probe,
   .remove = lt7911d_i2c_remove,
   .shutdown = lt7911d_i2c_shutdown,
   .id_table = lt7911d_i2c_table,
};
 
static int __init lt7911d_i2c_driver_init(void)
{
   i2c_add_driver(&lt7911d_i2c_driver);
 
   return 0;
}
subsys_initcall_sync(lt7911d_i2c_driver_init);
 
static void __exit lt7911d_i2c_driver_exit(void)
{
   i2c_del_driver(&lt7911d_i2c_driver);
}
module_exit(lt7911d_i2c_driver_exit);
 
MODULE_DESCRIPTION("Lontium lt7911dD driver");
MODULE_LICENSE("GPL");