aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/chargepump/lm3632/lm3632_driver.c
blob: 980bc8749faed5b80345915fe23831e980078a38 (plain) (blame)
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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
/*
* This software program is licensed subject to the GNU General Public License
* (GPL).Version 2,June 1991, available at http://www.fsf.org/copyleft/gpl.html

* (C) Copyright 2011 Bosch Sensortec GmbH
* All Rights Reserved
*/


/* file lm3632.c
brief This file contains all function implementations for the lm3632 in linux
this source file refer to MT6572 platform 
*/

#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#include <linux/kernel.h>
#include <linux/delay.h>

#include <mach/mt_typedefs.h>
#include <mach/mt_gpio.h>
#include <cust_gpio_usage.h>
#include <mach/mt_pm_ldo.h>

#include <linux/platform_device.h>
//#include <cust_acc.h>

//#include <linux/hwmsensor.h>
//#include <linux/hwmsen_dev.h>
//#include <linux/sensors_io.h>
//#include <linux/hwmsen_helper.h>

#include <linux/leds.h>

#define LM3632_DSV_VPOS_EN  GPIO_DSV_AVEE_EN
#define LM3632_DSV_VPOS_EN_MODE GPIO_DSV_AVEE_EN_M_GPIO

#define LM3632_DSV_VNEG_EN GPIO_DSV_AVDD_EN
#define LM3632_DSV_VNEG_EN_MODE GPIO_DSV_AVDD_EN_M_GPIO

//#define LCD_LED_MAX 0x7F
//#define LCD_LED_MIN 0

//#define DEFAULT_BRIGHTNESS 0x73 //for 20mA
#define LM3632_MIN_VALUE_SETTINGS 10 /* value leds_brightness_set*/
#define LM3632_MAX_VALUE_SETTINGS 255 /* value leds_brightness_set*/
#define MIN_MAX_SCALE(x) (((x)<LM3632_MIN_VALUE_SETTINGS) ? LM3632_MIN_VALUE_SETTINGS : (((x)>LM3632_MAX_VALUE_SETTINGS) ? LM3632_MAX_VALUE_SETTINGS:(x)))

#define BACKLIHGT_NAME "charge-pump"

#define LM3632_GET_BITSLICE(regvar, bitname)\
((regvar & bitname##__MSK) >> bitname##__POS)

#define LM3632_SET_BITSLICE(regvar, bitname, val)\
((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))

#define LM3632_DEV_NAME "charge-pump"

#define CPD_TAG                  "[chargepump] "
#define CPD_FUN(f)               printk(CPD_TAG"%s\n", __func__)
#define CPD_ERR(fmt, args...)    printk(CPD_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
#define CPD_LOG(fmt, args...)    printk(CPD_TAG fmt, ##args)

// I2C variable
static struct i2c_client *new_client = NULL;
static const struct i2c_device_id lm3632_i2c_id[] = {{LM3632_DEV_NAME,0},{}};
static struct i2c_board_info __initdata i2c_lm3632={ I2C_BOARD_INFO("charge-pump", 0x11)};

// Flash control
unsigned char strobe_ctrl;
unsigned char flash_ctrl=0; // flash_en register(0x0A) setting position change.
unsigned char lm3632_mapping_level; 
unsigned char bright_arr[] = {  // array index max 100, value under 255
        20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 22, 22, 22, 24, 24, 24,  // 19
        26, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 38, 38, 40, 42, 42, 44, 36, 48,  // 39
        48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 76, 78, 80, 82, 86, 88, 90,  // 59
        94, 96, 98, 102, 104, 108, 110, 114, 118, 120, 124, 128, 130, 134, 138, 142, 146, 148, 152, 156,  //79
        160, 164, 168, 172, 178, 182, 186, 190, 194, 200, 204, 208, 212, 218, 222, 228, 232, 238, 242, 248, 255  // 100
    };

static unsigned char current_brightness = 0;
static unsigned char is_suspend = 0;

struct semaphore lm3632_lock; // Add semaphore for lcd and flash i2c communication.

/* generic */
#define LM3632_MAX_RETRY_I2C_XFER (100)
#define LM3632_I2C_WRITE_DELAY_TIME 1

/* i2c read routine for API*/
static char lm3632_i2c_read(struct i2c_client *client, u8 reg_addr,
            u8 *data, u8 len)
{
        #if !defined BMA_USE_BASIC_I2C_FUNC
        s32 dummy;
        if (NULL == client)
            return -1;

        while (0 != len--) {
            #ifdef BMA_SMBUS
            dummy = i2c_smbus_read_byte_data(client, reg_addr);
            if (dummy < 0) {
                CPD_ERR("i2c bus read error\n");
                return -1;
            }
            *data = (u8)(dummy & 0xff);
            #else
            dummy = i2c_master_send(client, (char *)&reg_addr, 1);
            if (dummy < 0)
            {
                CPD_ERR("send dummy is %d\n", dummy);
                return -1;
            }

            dummy = i2c_master_recv(client, (char *)data, 1);
            if (dummy < 0)
            {
                CPD_ERR("recv dummy is %d\n", dummy);
                return -1;
            }
            #endif
            reg_addr++;
            data++;
        }
        return 0;
        #else
        int retry;

        struct i2c_msg msg[] = {
                {
                    .addr = client->addr,
                    .flags = 0,
                    .len = 1,
                    .buf = &reg_addr,
                },

                {
                    .addr = client->addr,
                    .flags = I2C_M_RD,
                    .len = len,
                    .buf = data,
                },
        };

        for (retry = 0; retry < LM3632_MAX_RETRY_I2C_XFER; retry++) {
            if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) > 0)
                break;
            else
                mdelay(LM3632_I2C_WRITE_DELAY_TIME);
        }

        if (LM3632_MAX_RETRY_I2C_XFER <= retry) {
            CPD_ERR("I2C xfer error\n");
            return -EIO;
        }

        return 0;
        #endif
}

/* i2c write routine for */
static char lm3632_i2c_write(struct i2c_client *client, u8 reg_addr,
            u8 *data, u8 len)
{
        #if !defined BMA_USE_BASIC_I2C_FUNC
        s32 dummy;

        #ifndef BMA_SMBUS
        u8 buffer[2];
        #endif

        if (NULL == client)
            return -1;

        while (0 != len--) {
            #if 1
            dummy = i2c_smbus_write_byte_data(client, reg_addr, *data);
            #else
            buffer[0] = reg_addr;
            buffer[1] = *data;
            dummy = i2c_master_send(client, (char *)buffer, 2);
            #endif

            reg_addr++;
            data++;
            if (dummy < 0) {
                return -1;
            }
        }

        #else
        u8 buffer[2];
        int retry;
        struct i2c_msg msg[] = {
                {
                    .addr = client->addr,
                    .flags = 0,
                    .len = 2,
                    .buf = buffer,
                },
        };

        while (0 != len--) {
            buffer[0] = reg_addr;
            buffer[1] = *data;
            for (retry = 0; retry < LM3632_MAX_RETRY_I2C_XFER; retry++) {
                if (i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)) > 0) {
                    break;
                }
                else {
                    mdelay(LM3632_I2C_WRITE_DELAY_TIME);
                }
            }
            if (LM3632_MAX_RETRY_I2C_XFER <= retry) {
                return -EIO;
            }
            reg_addr++;
            data++;
        }
        #endif
        //CPD_LOG("lm3632_i2c_write \n");
        return 0;
}

static int lm3632_smbus_read_byte(struct i2c_client *client,
            unsigned char reg_addr, unsigned char *data)
{
        return lm3632_i2c_read(client,reg_addr,data,1);
}

static int lm3632_smbus_write_byte(struct i2c_client *client,
            unsigned char reg_addr, unsigned char *data)
{
        int ret_val = 0;
        int i = 0;

        ret_val = lm3632_i2c_write(client,reg_addr,data,1);

        for ( i = 0; i < 5; i++)
        {
            if (ret_val != 0)
                lm3632_i2c_write(client,reg_addr,data,1);
            else
                return ret_val;
        }
        return ret_val;
}

static int lm3632_smbus_read_byte_block(struct i2c_client *client,
unsigned char reg_addr, unsigned char *data, unsigned char len)
{
        return lm3632_i2c_read(client,reg_addr,data,len);
}

bool check_charger_pump_vendor()
{
        int err = 0;
        unsigned char data = 0;

        err = lm3632_smbus_read_byte(new_client,0x01,&data);

        if(err < 0)
            CPD_ERR("%s read charge-pump vendor id fail\n", __func__);

        CPD_ERR("%s vendor is 0x%x\n", __func__, data&0x03);

        if((data&0x03) == 0x03) //Richtek
            return FALSE;
        else
            return TRUE;
}

int current_level;
int chargepump_set_backlight_level(unsigned int level)
{
        unsigned char data = 0;
        unsigned char data1 = 0;
        unsigned int bright_per = 0;

        CPD_LOG("chargepump_set_backlight_level  [%d]\n",level);
        if (level == 0)  
        {
            if(is_suspend == false)
            {
                CPD_LOG( "backlight off\n");
                down_interruptible(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
                data1 = 0x00; //backlight2 brightness 0
                lm3632_smbus_write_byte(new_client, 0x04, &data1);  // LSB 3bit all 0		
                lm3632_smbus_write_byte(new_client, 0x05, &data1);  // MSB 3bit all 0
                lm3632_smbus_read_byte(new_client, 0x0A, &data1);
                data1 &= 0x16;  // BLED1_EN, FLASH_MODE, FLASH Enable, AND operation
                lm3632_smbus_write_byte(new_client, 0x0A, &data1);

                is_suspend = true;// Move backlight suspend setting position into semaphore

                up(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
            }
        }
        else 
        {
            level = MIN_MAX_SCALE(level);
            //CPD_LOG("level = %d\n", level);
            bright_per = (level - (unsigned int)20) *(unsigned int)100 / (unsigned int)235;		
            data = bright_arr[bright_per];
            current_level = bright_per;
            CPD_LOG("%s bright_per = %d, data = %d\n", __func__, bright_per, data);
            lm3632_mapping_level = data;
            if (is_suspend == true) 
            {
                //printk( "------	 backlight_level resume-----\n");
                mdelay(10);
                down_interruptible(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.

                data1 = 0x70;// OVP 29V, Linear mapping mode
                lm3632_smbus_write_byte(new_client, 0x02, &data1);

                data1 = 0x07;  // Backlight brightness LSB 3bits, 0b111
                lm3632_smbus_write_byte(new_client, 0x04, &data1);

                lm3632_smbus_write_byte(new_client, 0x05, &data);  // MSB 8 bit control
                CPD_LOG("backlight brightness Setting[reg0x05][value:0x%x]\n",data);

                lm3632_smbus_read_byte(new_client, 0x0A, &data1);
                data1 |= 0x11;  // BLED1_EN, BL_EN enable
                lm3632_smbus_write_byte(new_client, 0x0A, &data1);

                is_suspend = 0; // Move backlight suspend setting position into semaphore
                up(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
            }

            if (level != 0)	// Move backlight suspend setting position into semaphore
            {
                down_interruptible(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
                if(0)  // blocking useless code
                {
                    unsigned char read_data = 0;

                    lm3632_smbus_read_byte(new_client, 0x02, &read_data);
                    CPD_LOG("is_suspend[0x%x]\n",read_data);
                }			

                CPD_LOG("backlight Setting[reg0x05][value:0x%x]\n",data);
                lm3632_smbus_write_byte(new_client, 0x05, &data);
                up(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
            } // Move backlight suspend setting position into semaphore
        }

        return 0;
}

int chargepump_backlight_level_test(unsigned int level)
{
        unsigned char data = 0;

        if(level > 255)
        {
                level = 255;
        }

        data = 0x70;// OVP 29V, Linear mapping mode
        lm3632_smbus_write_byte(new_client, 0x02, &data);

        data = 0x07;  // Backlight brightness LSB 3bits, 0b111
        lm3632_smbus_write_byte(new_client, 0x04, &data);

        data = level;
        lm3632_smbus_write_byte(new_client, 0x05, &data);  // MSB 8 bit control
        CPD_LOG("backlight brightness Test[reg0x05][value:0x%x]\n",data);

        lm3632_smbus_read_byte(new_client, 0x0A, &data);
        data |= 0x11;  // BLED1_EN, BL_EN enable
        lm3632_smbus_write_byte(new_client, 0x0A, &data);

        return 0;
}

unsigned char get_lm3632_backlight_level(void)
{
        return lm3632_mapping_level;
}


void chargepump_DSV_on()
{
        //CPD_FUN();        
        mt_set_gpio_out(LM3632_DSV_VPOS_EN, GPIO_OUT_ONE);
        mdelay(1);
        mt_set_gpio_out(LM3632_DSV_VNEG_EN, GPIO_OUT_ONE);
}

void chargepump_DSV_off()
{
        //CPD_FUN();
        mt_set_gpio_out(LM3632_DSV_VPOS_EN, GPIO_OUT_ZERO);
        mdelay(1);
        mt_set_gpio_out(LM3632_DSV_VNEG_EN, GPIO_OUT_ZERO);
}

static int lm3632_probe(struct i2c_client *client,
        const struct i2c_device_id *id)
{   
        int ret;
        new_client = client;
        int err;

        CPD_FUN();
        if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
            CPD_LOG("i2c_check_functionality error\n");
            return -1;
        }

        sema_init(&lm3632_lock, 1); // Add semaphore for lcd and flash i2c communication.

        if (client == NULL) 
            printk("%s client is NULL\n", __func__);
        else
        {
            //CPD_LOG("%s %x %x %x\n", __func__, client->adapter, client->addr, client->flags);
            CPD_LOG("%s is OK\n", __func__);
        }
        return 0;
}

static int lm3632_remove(struct i2c_client *client)
{
        new_client = NULL;
        return 0;
}


static int lm3632_detect(struct i2c_client *client, int kind, struct i2c_board_info *info) 
{ 
    return 0;
}

static struct i2c_driver lm3632_i2c_driver = {
        .driver = {
        //		.owner	= THIS_MODULE,
        .name	= LM3632_DEV_NAME,
        },
        .probe		= lm3632_probe,
        .remove		= lm3632_remove,
        //	.detect		= lm3632_detect,
        .id_table	= lm3632_i2c_id,
        //	.address_data = &lm3632250_i2c_addr_data,
};

static int lm3632_pd_probe(struct platform_device *pdev) 
{
        if(i2c_add_driver(&lm3632_i2c_driver))
        {
            CPD_ERR("add driver error\n");
            return -1;
        }
        else
        {
            CPD_LOG("i2c_add_driver OK\n");       
        }
        return 0;
}

static int lm3632_pd_remove(struct platform_device *pdev)
{
        CPD_FUN();
        i2c_del_driver(&lm3632_i2c_driver);
        return 0;
}

#ifdef CONFIG_HAS_EARLYSUSPEND
static void lm3632_early_suspend(struct early_suspend *h)
{
        int err = 0;
        unsigned char data;
        down_interruptible(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
        data = 0x00; //backlight2 brightness 0
        err = lm3632_smbus_write_byte(new_client, 0x04, &data);	
        err = lm3632_smbus_write_byte(new_client, 0x05, &data);

        err = lm3632_smbus_read_byte(new_client, 0x0A, &data);
        data &= 0x06;  // FLASH_MODE, FLASH Enable, AND operation    

        err = lm3632_smbus_write_byte(new_client, 0x0A, &data);
        up(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
        CPD_LOG("early_suspend  [%d]",data);
        //mt_set_gpio_out(GPIO_LCM_BL_EN,GPIO_OUT_ZERO);
}

void lm3632_flash_strobe_prepare(char OnOff,char ActiveHigh)
{
        int err = 0;

        down_interruptible(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.

        err = lm3632_smbus_read_byte(new_client, 0x09, &strobe_ctrl);        

        // flash_en register(0x0A) setting position change.
        strobe_ctrl &= 0xF3;
        flash_ctrl = OnOff;

        if(ActiveHigh)
        {
            strobe_ctrl |= 0x20;
        }
        else
        {
            strobe_ctrl &= 0xDF;
        }

        if(OnOff == 1)
        {
            CPD_LOG("Strobe mode On\n");
            strobe_ctrl |= 0x10;		
        }
        else if(OnOff == 2)
        {
            CPD_LOG("Torch mode On\n");
            strobe_ctrl |= 0x10;
        }
        else
        {
            CPD_LOG("Flash Off\n");
            strobe_ctrl &= 0xEF;
        }
        // flash_en register(0x0A) setting position change.
        err = lm3632_smbus_write_byte(new_client, 0x09, &strobe_ctrl);

        up(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
}

//strobe enable
void lm3632_flash_strobe_en()
{
        // flash_en register(0x0A) setting position change.
        int err = 0;
        int flash_OnOff=0;

        down_interruptible(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
        err = lm3632_smbus_read_byte(new_client, 0x0A, &flash_OnOff);
        if(flash_ctrl == 1)
            flash_OnOff |= 0x66;
        else if(flash_ctrl == 2)
            flash_OnOff |= 0x62;
        else
            flash_OnOff &= 0x99;
            
        err = lm3632_smbus_write_byte(new_client, 0x0A, &flash_OnOff);
        up(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
        // flash_en register(0x0A) setting position change.
}

//strobe level
void lm3632_flash_strobe_level(char level)
{
        int err = 0;
        unsigned char data1=0;
        unsigned char data2=0;
        unsigned char torch_level;
        unsigned char strobe_timeout = 0x1F;

        down_interruptible(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
        #if 0 // Add Main Flash current(4 Step)
        if( level == 1) 
        {
            torch_level = 0x20;
        }
        else
        {
            torch_level = 0x50;
        }

        err = lm3632_smbus_read_byte(new_client, 0x06, &data1);

        if(31 < level)
        {    
            data1= torch_level | 0x0A;
            strobe_timeout = 0x0F;
        }
        else if(level < 0)
        {
            data1= torch_level ;
        }
        else
        {
            data1= torch_level | level; 
        }
        // Add Main Flash current(4 Step)
        #else
        torch_level = 0x50;

        err = lm3632_smbus_read_byte(new_client, 0x06, &data1);

        strobe_timeout = 0x1F; // Flash Timing Tuning
        if(level < 0)
            data1= torch_level;
        else if(level == 1)
            data1= torch_level | 0x03;
        else if(level == 2)
            data1= torch_level | 0x05;
        else if(level == 3)
            data1= torch_level | 0x08;
        else if(level == 4)
            data1= torch_level | 0x0A;
        else
            data1= torch_level | level;

        #endif
         // Add Main Flash current(4 Step)
         /*
       if(0)
       {
            CPD_LOG("Batt temp=%d\n", BMT_status.temperature );

            torch_level = 0xF0 & data1;
            level = 0x0F & data1;
            torch_level = 0xF0 & (torch_level >> 2);
            level = 0x0F & (level >> 2);

            data1 = torch_level | level;
        }
        */
        CPD_LOG("Flash Level =0x%x\n", data1);
        err = lm3632_smbus_write_byte(new_client, 0x06, &data1);

        data2 = 0x40 | strobe_timeout;
        CPD_LOG("Storbe Timeout =0x%x\n", data2);
        err |= lm3632_smbus_write_byte(new_client, 0x07, &data2);
        up(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
}

static void lm3632_late_resume(struct early_suspend *h)
{
        int err = 0;
        unsigned char data1;

        //mt_set_gpio_out(GPIO_LCM_BL_EN, GPIO_OUT_ONE);
        mdelay(50);
        down_interruptible(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.

        data1 = 0x07;  // Backlight brightness LSB 3bits, 0b111
        lm3632_smbus_write_byte(new_client, 0x04, &data1);        	
        err = lm3632_smbus_write_byte(new_client, 0x05, &current_brightness);

        err = lm3632_smbus_read_byte(new_client, 0x0A, &data1);
        data1 |= 0x11;  // BLED1_EN, BL_EN enable        

        err = lm3632_smbus_write_byte(new_client, 0x0A, &data1);
        up(&lm3632_lock); // Add semaphore for lcd and flash i2c communication.
        CPD_LOG("lm3632_late_resume  [%d]",data1);
}

static struct early_suspend lm3632_early_suspend_desc = {
        .level		= EARLY_SUSPEND_LEVEL_BLANK_SCREEN,
        .suspend	= lm3632_early_suspend,
        .resume		= lm3632_late_resume,
};
#endif

static struct platform_driver lm3632_backlight_driver = {
        .probe      = lm3632_pd_probe,
        .remove     = lm3632_pd_remove,
        .driver     = {
                .name  = "charge-pump",
                .owner = THIS_MODULE,
        }
};      

static int __init lm3632_init(void)
{
        CPD_FUN();

        i2c_register_board_info(2, &i2c_lm3632, 1); 
        CPD_LOG("lm3632_i2c_master_addr = 2\n");

        #ifndef	CONFIG_MTK_LEDS
        register_early_suspend(&lm3632_early_suspend_desc);
        #endif	

        if(platform_driver_register(&lm3632_backlight_driver))
        {
            CPD_ERR("failed to register driver");
            return -1;
        }
        return 0;
}

static void __exit lm3632_exit(void)
{
        platform_driver_unregister(&lm3632_backlight_driver);
}

EXPORT_SYMBOL(lm3632_flash_strobe_en);
EXPORT_SYMBOL(lm3632_flash_strobe_prepare);
EXPORT_SYMBOL(lm3632_flash_strobe_level);
MODULE_AUTHOR("Albert Zhang <xu.zhang@bosch-sensortec.com>");
MODULE_DESCRIPTION("lm3632 driver");
MODULE_LICENSE("GPL");

module_init(lm3632_init);
module_exit(lm3632_exit);