22 #include <linux/kernel.h>
23 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <linux/i2c.h>
78 static struct mfd_cell aat2870_devs[] = {
80 .name =
"aat2870-backlight",
85 .name =
"aat2870-regulator",
90 .name =
"aat2870-regulator",
95 .name =
"aat2870-regulator",
100 .name =
"aat2870-regulator",
111 dev_err(aat2870->
dev,
"Invalid address, 0x%02x\n", addr);
115 if (!aat2870->
reg_cache[addr].readable) {
133 dev_dbg(aat2870->
dev,
"read: addr=0x%02x, val=0x%02x\n", addr, *val);
143 dev_err(aat2870->
dev,
"Invalid address, 0x%02x\n", addr);
147 if (!aat2870->
reg_cache[addr].writeable) {
148 dev_err(aat2870->
dev,
"Address 0x%02x is not writeable\n",
163 dev_dbg(aat2870->
dev,
"write: addr=0x%02x, val=0x%02x\n", addr, val);
172 ret = __aat2870_read(aat2870, addr, val);
183 ret = __aat2870_write(aat2870, addr, val);
198 ret = __aat2870_read(aat2870, addr, &old_val);
202 new_val = (old_val & ~mask) | (val & mask);
203 change = old_val != new_val;
205 ret = __aat2870_write(aat2870, addr, new_val);
213 static inline void aat2870_enable(
struct aat2870_data *aat2870)
221 static inline void aat2870_disable(
struct aat2870_data *aat2870)
229 #ifdef CONFIG_DEBUG_FS
236 count +=
sprintf(buf,
"aat2870 registers\n");
238 count +=
sprintf(buf + count,
"0x%02x: ", addr);
242 ret = aat2870->
read(aat2870, addr, &val);
248 "<read fail: %d>", ret);
265 static ssize_t aat2870_reg_read_file(
struct file *
file,
char __user *user_buf,
266 size_t count, loff_t *ppos)
276 ret = aat2870_dump_reg(aat2870, buf);
285 static ssize_t aat2870_reg_write_file(
struct file *file,
286 const char __user *user_buf,
size_t count,
296 buf_size =
min(count, (
sizeof(buf)-1));
298 dev_err(aat2870->
dev,
"Failed to copy from user\n");
303 while (*start ==
' ')
307 if (addr >= AAT2870_REG_NUM) {
308 dev_err(aat2870->
dev,
"Invalid address, 0x%lx\n", addr);
312 while (*start ==
' ')
318 ret = aat2870->
write(aat2870, (
u8)addr, (
u8)val);
327 .read = aat2870_reg_read_file,
328 .write = aat2870_reg_write_file,
331 static void aat2870_init_debugfs(
struct aat2870_data *aat2870)
336 "Failed to create debugfs root directory\n");
342 aat2870, &aat2870_reg_fops);
345 "Failed to create debugfs register file\n");
348 static void aat2870_uninit_debugfs(
struct aat2870_data *aat2870)
353 static inline void aat2870_init_debugfs(
struct aat2870_data *aat2870)
357 static inline void aat2870_uninit_debugfs(
struct aat2870_data *aat2870)
373 "Failed to allocate memory for aat2870\n");
378 aat2870->
dev = &client->
dev;
382 i2c_set_clientdata(client, aat2870);
393 aat2870->
read = aat2870_read;
394 aat2870->
write = aat2870_write;
395 aat2870->
update = aat2870_update;
400 aat2870->
init(aat2870);
402 if (aat2870->
en_pin >= 0) {
407 "Failed to request GPIO %d\n", aat2870->
en_pin);
412 aat2870_enable(aat2870);
415 for (j = 0; j <
ARRAY_SIZE(aat2870_devs); j++) {
416 if ((pdata->
subdevs[i].id == aat2870_devs[j].
id) &&
418 aat2870_devs[j].
name)) {
429 dev_err(aat2870->
dev,
"Failed to add subdev: %d\n", ret);
433 aat2870_init_debugfs(aat2870);
438 aat2870_disable(aat2870);
447 static int aat2870_i2c_remove(
struct i2c_client *client)
449 struct aat2870_data *aat2870 = i2c_get_clientdata(client);
451 aat2870_uninit_debugfs(aat2870);
454 aat2870_disable(aat2870);
464 #ifdef CONFIG_PM_SLEEP
465 static int aat2870_i2c_suspend(
struct device *
dev)
468 struct aat2870_data *aat2870 = i2c_get_clientdata(client);
470 aat2870_disable(aat2870);
475 static int aat2870_i2c_resume(
struct device *
dev)
478 struct aat2870_data *aat2870 = i2c_get_clientdata(client);
482 aat2870_enable(aat2870);
504 static struct i2c_driver aat2870_i2c_driver = {
508 .pm = &aat2870_pm_ops,
510 .probe = aat2870_i2c_probe,
511 .remove = aat2870_i2c_remove,
512 .id_table = aat2870_i2c_id_table,
515 static int __init aat2870_init(
void)
517 return i2c_add_driver(&aat2870_i2c_driver);
521 static void __exit aat2870_exit(
void)