aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/accdet/mt6735/ts3a225e.c
blob: cd0b8b641ad598349cd6d45ae9e12fc3d5aaf3e0 (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
/* drivers/hwmon/mt6516/amit/IQS128.c - IQS128/PS driver
 * 
 * Author: MingHsien Hsieh <minghsien.hsieh@mediatek.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/miscdevice.h>
#include <linux/uaccess.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <linux/workqueue.h>
#include <linux/kobject.h>
#include <linux/earlysuspend.h>
#include <linux/platform_device.h>
#include <asm/atomic.h>

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

#include <linux/hwmsensor.h>
#include <linux/hwmsen_dev.h>
#include <linux/sensors_io.h>
#include <asm/io.h>
#include <cust_eint.h>
#include "ts3a225e.h"

/******************************************************************************
 * configuration
*******************************************************************************/
#define TS3A225E_DEV_NAME     "TS3A225E"

struct i2c_client *ts3a225e_i2c_client = NULL;
static const struct i2c_device_id ts3a225e_i2c_id[] = {{"TS3A225E",0},{}};
static struct i2c_board_info __initdata i2c_TS3A225E= { I2C_BOARD_INFO("TS3A225E", (0X76>>1))};

static int ts3a225e_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	kal_uint8 devicve_id[1];
	
	printk("ts3a225e_i2c_probe \n");

	ts3a225e_i2c_client = client;

	ts3a225e_read_byte(0x01, &devicve_id[0]);
	printk("ts3a225e_i2c_probe ID=%x \n", devicve_id[0]);

	return 0;
}

static int ts3a225e_i2c_remove(struct i2c_client *client)
{
	printk("TS3A225E_i2c_remove \n");
	
	ts3a225e_i2c_client = NULL;

	return 0;
}

static int ts3a225e_i2c_suspend(struct i2c_client *client, pm_message_t msg)
{
	printk("TS3A225E_i2c_suspend \n");
	
	return 0;
}

static int ts3a225e_i2c_resume(struct i2c_client *client)
{
	printk("TS3A225E_i2c_resume \n");

	return 0;
}

static struct i2c_driver ts3a225e_i2c_driver =
{
    .probe      = ts3a225e_i2c_probe,
    .remove     = ts3a225e_i2c_remove,
    .suspend    = ts3a225e_i2c_suspend,
    .resume     = ts3a225e_i2c_resume,
    .id_table   = ts3a225e_i2c_id,
    .driver = {
        .name           = TS3A225E_DEV_NAME,
    },
};

static DEFINE_MUTEX(ts3a225e_i2c_access);

int ts3a225e_read_byte(kal_uint8 cmd, kal_uint8 *returnData)
{
    char     cmd_buf[1]={0x00};
    char     readData = 0;
    int      ret=0;

    mutex_lock(&ts3a225e_i2c_access);
    
    //new_client->addr = ((new_client->addr) & I2C_MASK_FLAG) | I2C_WR_FLAG;    
    ts3a225e_i2c_client->ext_flag=((ts3a225e_i2c_client->ext_flag ) & I2C_MASK_FLAG ) | I2C_WR_FLAG | I2C_DIRECTION_FLAG;

    cmd_buf[0] = cmd;
    ret = i2c_master_send(ts3a225e_i2c_client, &cmd_buf[0], (1<<8 | 1));
    if (ret < 0) 
    {    
        //new_client->addr = new_client->addr & I2C_MASK_FLAG;
        ts3a225e_i2c_client->ext_flag=0;
		
        mutex_unlock(&ts3a225e_i2c_access);
        return 0;
    }
    
    readData = cmd_buf[0];
    *returnData = readData;

    //new_client->addr = new_client->addr & I2C_MASK_FLAG;
    ts3a225e_i2c_client->ext_flag=0;
	
    mutex_unlock(&ts3a225e_i2c_access);    
    return 1;
}

int ts3a225e_write_byte(kal_uint8 cmd, kal_uint8 writeData)
{
    char    write_data[2] = {0};
    int     ret=0;
    
    mutex_lock(&ts3a225e_i2c_access);
    
    write_data[0] = cmd;
    write_data[1] = writeData;

    ts3a225e_i2c_client->ext_flag=((ts3a225e_i2c_client->ext_flag ) & I2C_MASK_FLAG ) | I2C_DIRECTION_FLAG;
	
    ret = i2c_master_send(ts3a225e_i2c_client, write_data, 2);
    if (ret < 0) 
    {
        ts3a225e_i2c_client->ext_flag=0;    
        mutex_unlock(&ts3a225e_i2c_access);
        return 0;
    }

    ts3a225e_i2c_client->ext_flag=0;    
    mutex_unlock(&ts3a225e_i2c_access);
    return 1;
}

/******************************************************************************
 * extern functions
*******************************************************************************/
/*----------------------------------------------------------------------------*/
static int ts3a225e_probe(struct platform_device *pdev)
{
	printk("ts3a225e_probe \n");

	if(i2c_add_driver(&ts3a225e_i2c_driver))
	{
		printk("ts3a225e add driver error\n");
		return -1;
	}

	return 0;
}
/*----------------------------------------------------------------------------*/
static int ts3a225e_remove(struct platform_device *pdev)
{
	printk("ts3a225e remove \n");

	i2c_del_driver(&ts3a225e_i2c_driver);

	return 0;
}

/*----------------------------------------------------------------------------*/
#ifdef CONFIG_OF
static const struct of_device_id audio_switch_of_match[] = {
	{ .compatible = "mediatek,audio_switch", },
	{},
};
#endif

static struct platform_driver ts3a225e_audio_switch_driver =
{
	.probe      = ts3a225e_probe,
	.remove     = ts3a225e_remove,    
	.driver     = 
	{
		.name = "audio_switch",
	#ifdef CONFIG_OF
		.of_match_table = audio_switch_of_match,
	#endif
	}
};
/*----------------------------------------------------------------------------*/
static int __init ts3a225e_init(void)
{
	printk("ts3a225e_init \n");
	
	i2c_register_board_info(3, &i2c_TS3A225E, 1);

	if(platform_driver_register(&ts3a225e_audio_switch_driver))
	{
		printk("ts3a225e failed to register driver");
		return -ENODEV;
	}
	
	return 0;
}
/*----------------------------------------------------------------------------*/
static void __exit ts3a225e_exit(void)
{
	printk("ts3a225e_exit \n");
}
/*----------------------------------------------------------------------------*/
module_init(ts3a225e_init);
module_exit(ts3a225e_exit);
/*----------------------------------------------------------------------------*/
MODULE_AUTHOR("Dexiang Liu");
MODULE_DESCRIPTION("TS3A225E driver");
MODULE_LICENSE("GPL");