import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / lcm / cpt_clap070wp03xg_sn65dsi83 / sn65dsi83_i2c.c
1 #ifndef BUILD_LK
2 #include <linux/interrupt.h>
3 #include <linux/i2c.h>
4 #include <linux/slab.h>
5 #include <linux/irq.h>
6 #include <linux/miscdevice.h>
7 #include <asm/uaccess.h>
8 #include <linux/delay.h>
9 #include <linux/input.h>
10 #include <linux/workqueue.h>
11 #include <linux/kobject.h>
12 #include <linux/earlysuspend.h>
13 #include <linux/platform_device.h>
14 #include <asm/atomic.h>
15
16 #include <cust_acc.h>
17 #include <linux/hwmsensor.h>
18 #include <linux/hwmsen_dev.h>
19 #include <linux/sensors_io.h>
20 #include <linux/hwmsen_helper.h>
21 #include <linux/xlog.h>
22
23
24 #include <mach/mt_typedefs.h>
25 #include <mach/mt_gpio.h>
26 #include <mach/mt_pm_ldo.h>
27
28 //#include "sn65dsi83_i2c.h"
29 //#include "cust_charging.h"
30 //#include <mach/charging.h>
31
32
33 /**********************************************************
34 *
35 * [I2C Slave Setting]
36 *
37 *********************************************************/
38 #define sn65dsi83_SLAVE_ADDR_WRITE 0x58 //0xD4
39 #define sn65dsi83_SLAVE_ADDR_Read 0x59 //0xD5
40 #define sn65dsi83_SLAVE_ADDR 0x58
41
42
43 static struct i2c_client *new_client = NULL;
44 static const struct i2c_device_id sn65dsi83_i2c_id[] = {{"sn65dsi83",0},{}};
45 //kal_bool chargin_hw_init_done = KAL_FALSE;
46 static int sn65dsi83_driver_probe(struct i2c_client *client, const struct i2c_device_id *id);
47
48 static struct i2c_driver sn65dsi83_driver = {
49 .driver = {
50 .name = "sn65dsi83",
51 },
52 .probe = sn65dsi83_driver_probe,
53 .id_table = sn65dsi83_i2c_id,
54 };
55
56 /**********************************************************
57 *
58 * [Global Variable]
59 *
60 *********************************************************/
61 //kal_uint8 sn65dsi83_reg[sn65dsi83_REG_NUM] = {0};
62
63 static DEFINE_MUTEX(sn65dsi83_i2c_access);
64 /**********************************************************
65 *
66 * [I2C Function For Read/Write fan5405]
67 *
68 *********************************************************/
69
70
71 int sn65dsi83_read_byte(kal_uint8 cmd, kal_uint8 *returnData)
72 {
73 char cmd_buf[1]={0x00};
74 char readData = 0;
75 int ret=0;
76
77 mutex_lock(&sn65dsi83_i2c_access);
78
79 //new_client->addr = ((new_client->addr) & I2C_MASK_FLAG) | I2C_WR_FLAG;
80 new_client->ext_flag=((new_client->ext_flag ) & I2C_MASK_FLAG ) | I2C_WR_FLAG | I2C_DIRECTION_FLAG;
81
82 cmd_buf[0] = cmd;
83 ret = i2c_master_send(new_client, &cmd_buf[0], (1<<8 | 1));
84 if (ret < 0)
85 {
86 //new_client->addr = new_client->addr & I2C_MASK_FLAG;
87 new_client->ext_flag=0;
88
89 mutex_unlock(&sn65dsi83_i2c_access);
90 return 0;
91 }
92
93 readData = cmd_buf[0];
94 *returnData = readData;
95
96 // new_client->addr = new_client->addr & I2C_MASK_FLAG;
97 new_client->ext_flag=0;
98
99 mutex_unlock(&sn65dsi83_i2c_access);
100 return 1;
101 }
102
103 int sn65dsi83_write_byte(kal_uint8 cmd, kal_uint8 writeData)
104 {
105 char write_data[2] = {0};
106 int ret=0;
107
108 mutex_lock(&sn65dsi83_i2c_access);
109
110 write_data[0] = cmd;
111 write_data[1] = writeData;
112
113 new_client->ext_flag=((new_client->ext_flag ) & I2C_MASK_FLAG ) | I2C_DIRECTION_FLAG;
114
115 ret = i2c_master_send(new_client, write_data, 2);
116 if (ret < 0)
117 {
118
119 new_client->ext_flag=0;
120 mutex_unlock(&sn65dsi83_i2c_access);
121 return 0;
122 }
123
124 new_client->ext_flag=0;
125 mutex_unlock(&sn65dsi83_i2c_access);
126 return 1;
127 }
128
129
130 static int sn65dsi83_driver_probe(struct i2c_client *client, const struct i2c_device_id *id)
131 {
132 int err=0;
133
134 //battery_xlog_printk(BAT_LOG_CRTI,"[sn65dsi83_driver_probe] \n");
135 printk("[sn65dsi83_driver_probe] \n");
136 if (!(new_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
137 err = -ENOMEM;
138 goto exit;
139 }
140 memset(new_client, 0, sizeof(struct i2c_client));
141
142 new_client = client;
143
144 //---------------------
145 // sn65dsi83_hw_init();
146 //fan5405_dump_register();
147 //chargin_hw_init_done = KAL_TRUE;
148
149 return 0;
150
151 exit:
152 return err;
153
154 }
155
156 #define SN65DSI83_BUSNUM 0
157
158 static struct i2c_board_info __initdata i2c_sn65dsi83 = { I2C_BOARD_INFO("sn65dsi83", /*sn65dsi83_SLAVE_ADDR_WRITE*/(sn65dsi83_SLAVE_ADDR_WRITE>>1))};
159
160 static int __init sn65dsi83_init(void)
161 {
162 // int ret=0; //fixed for build warning
163
164 //battery_xlog_printk(BAT_LOG_CRTI,"[sn65dsi83_init] init start\n");
165 printk("[sn65dsi83_init] init start\n");
166
167 i2c_register_board_info(SN65DSI83_BUSNUM, &i2c_sn65dsi83, 1);
168
169 if(i2c_add_driver(&sn65dsi83_driver)!=0)
170 {
171 //battery_xlog_printk(BAT_LOG_CRTI,"[sn65dsi83_init] failed to register sn65dsi83 i2c driver.\n");
172 printk("[sn65dsi83_init] failed to register sn65dsi83 i2c driver.\n");
173 }
174 else
175 {
176 //battery_xlog_printk(BAT_LOG_CRTI,"[sn65dsi83_init] Success to register sn65dsi83 i2c driver.\n");
177 printk("[sn65dsi83_init] Success to register sn65dsi83 i2c driver.\n");
178 }
179
180 return 0;
181 }
182
183 static void __exit sn65dsi83_exit(void)
184 {
185 i2c_del_driver(&sn65dsi83_driver);
186 }
187
188 module_init(sn65dsi83_init);
189 module_exit(sn65dsi83_exit);
190
191 MODULE_LICENSE("GPL");
192 MODULE_DESCRIPTION("I2C sn65dsi83 Driver");
193 MODULE_AUTHOR("James Lo<james.lo@mediatek.com>");
194 #endif