aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/samsung/fm_si4709/Si4709_i2c_drv.c
blob: 4f921970771e9006689dfc3ec2aa07125e90335e (plain)
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

#include <linux/kernel.h>
#include <linux/i2c.h>

#include "Si4709_dev.h"
#include "Si4709_common.h"
#include "Si4709_i2c_drv.h"

/*static functions*/
static int Si4709_probe(struct i2c_client *);
static int Si4709_remove(struct i2c_client *);
static int Si4709_suspend(struct i2c_client *, pm_message_t mesg);
static int Si4709_resume(struct i2c_client *);

static struct i2c_client *Si4709_i2c_client;

struct si4709_data {
	struct i2c_client *client;
};

/*I2C Setting*/

static struct i2c_driver Si4709_i2c_driver;

#if 0
static unsigned short Si4709_normal_i2c[] = { I2C_CLIENT_END };
static unsigned short Si4709_ignore[] = { I2C_CLIENT_END };

static unsigned short Si4709_i2c_probe[] = {
	8, SI4709_I2C_ADDRESS >> 1, I2C_CLIENT_END
};

static struct i2c_client_address_data Si4709_addr_data = {
	.normal_i2c = Si4709_normal_i2c,
	.ignore = Si4709_ignore,
	.probe = Si4709_i2c_probe,
};
#endif

static const struct i2c_device_id si4709_id[] = {
	{"Si4709", 0},
	{}
};

static int Si4709_probe(struct i2c_client *client)
{
	int ret = 0;

	debug("Si4709 i2c driver Si4709_probe called");

	if (strcmp(client->name, "Si4709") != 0) {
		ret = -1;
		error("Si4709_probe: device not supported");
	} else {
		ret = Si4709_dev_init(client);
		if (ret < 0)
			error("Si4709_dev_init failed");
	}

	return ret;
}

static int Si4709_remove(struct i2c_client *client)
{
	int ret = 0;

	debug("Si4709 i2c driver Si4709_remove called");

	if (strcmp(client->name, "Si4709") != 0) {
		ret = -1;
		error("Si4709_remove: device not supported");
	} else {
		ret = Si4709_dev_exit();
		if (ret < 0)
			error("Si4709_dev_exit failed");
	}

	return ret;
}

static int si4709_i2c_probe(struct i2c_client *client,
			    const struct i2c_device_id *id)
{
	int err = 0;
	struct si4709_data *si4709_dev;

	debug("----- %s %d\n", __func__, __LINE__);

	si4709_dev = kzalloc(sizeof(struct si4709_data), GFP_KERNEL);

	if (!si4709_dev) {
		err = -ENOMEM;
		return err;
	}

	Si4709_i2c_client = client;
	i2c_set_clientdata(client, si4709_dev);

	if (Si4709_i2c_client == NULL) {
		error("Si4709 i2c_client is NULL");
		return -ENODEV;
	}

	Si4709_probe(Si4709_i2c_client);

	return 0;
}

static int __exit si4709_i2c_remove(struct i2c_client *client)
{
	struct si4709_data *si4709_dev = i2c_get_clientdata(client);

	debug("----- %s %d\n", __func__, __LINE__);

	Si4709_remove(Si4709_i2c_client);
	kfree(si4709_dev);
	kfree(client);
	si4709_dev = NULL;
	Si4709_i2c_client = NULL;

	return 0;
}

MODULE_DEVICE_TABLE(i2c, si4709_id);

static struct i2c_driver Si4709_i2c_driver = {
	.driver = {
		   .owner = THIS_MODULE,
		   .name = "Si4709",
		   },
	.id_table = si4709_id,
	.probe = si4709_i2c_probe,
	.remove = __devexit_p(si4709_i2c_remove),
	.suspend = Si4709_suspend,
	.resume = Si4709_resume,
};

static int Si4709_suspend(struct i2c_client *client, pm_message_t mesg)
{
	int ret = 0;

	debug("Si4709 i2c driver Si4709_suspend called");

	if (strcmp(client->name, "Si4709") != 0) {
		ret = -1;
		error("Si4709_suspend: device not supported");
	} else {
		ret = Si4709_dev_suspend();
		if (ret < 0)
			error("Si4709_dev_disable failed");
	}

	return 0;
}

static int Si4709_resume(struct i2c_client *client)
{
	int ret = 0;

	/* debug("Si4709 i2c driver Si4709_resume called"); */

	if (strcmp(client->name, "Si4709") != 0) {
		ret = -1;
		error("Si4709_resume: device not supported");
	} else {
		ret = Si4709_dev_resume();
		if (ret < 0)
			error("Si4709_dev_enable failed");
	}

	return 0;
}

int Si4709_i2c_drv_init(void)
{
	int ret = 0;

	debug("Si4709 i2c driver Si4709_i2c_driver_init called");

	ret = i2c_add_driver(&Si4709_i2c_driver);
	if (ret < 0)
		error("Si4709 i2c_add_driver failed");

	return ret;
}

void Si4709_i2c_drv_exit(void)
{
	debug("Si4709 i2c driver Si4709_i2c_driver_exit called");

	i2c_del_driver(&Si4709_i2c_driver);
}