12b27bdccSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 209d6292bSJin Park /* 309d6292bSJin Park * linux/drivers/mfd/aat2870-core.c 409d6292bSJin Park * 509d6292bSJin Park * Copyright (c) 2011, NVIDIA Corporation. 609d6292bSJin Park * Author: Jin Park <jinyoungp@nvidia.com> 709d6292bSJin Park */ 809d6292bSJin Park 909d6292bSJin Park #include <linux/kernel.h> 1009d6292bSJin Park #include <linux/init.h> 1109d6292bSJin Park #include <linux/debugfs.h> 1209d6292bSJin Park #include <linux/slab.h> 1309d6292bSJin Park #include <linux/uaccess.h> 1409d6292bSJin Park #include <linux/i2c.h> 1509d6292bSJin Park #include <linux/delay.h> 1609d6292bSJin Park #include <linux/gpio.h> 1709d6292bSJin Park #include <linux/mfd/core.h> 1809d6292bSJin Park #include <linux/mfd/aat2870.h> 1909d6292bSJin Park #include <linux/regulator/machine.h> 2009d6292bSJin Park 2109d6292bSJin Park static struct aat2870_register aat2870_regs[AAT2870_REG_NUM] = { 2209d6292bSJin Park /* readable, writeable, value */ 2309d6292bSJin Park { 0, 1, 0x00 }, /* 0x00 AAT2870_BL_CH_EN */ 2409d6292bSJin Park { 0, 1, 0x16 }, /* 0x01 AAT2870_BLM */ 2509d6292bSJin Park { 0, 1, 0x16 }, /* 0x02 AAT2870_BLS */ 2609d6292bSJin Park { 0, 1, 0x56 }, /* 0x03 AAT2870_BL1 */ 2709d6292bSJin Park { 0, 1, 0x56 }, /* 0x04 AAT2870_BL2 */ 2809d6292bSJin Park { 0, 1, 0x56 }, /* 0x05 AAT2870_BL3 */ 2909d6292bSJin Park { 0, 1, 0x56 }, /* 0x06 AAT2870_BL4 */ 3009d6292bSJin Park { 0, 1, 0x56 }, /* 0x07 AAT2870_BL5 */ 3109d6292bSJin Park { 0, 1, 0x56 }, /* 0x08 AAT2870_BL6 */ 3209d6292bSJin Park { 0, 1, 0x56 }, /* 0x09 AAT2870_BL7 */ 3309d6292bSJin Park { 0, 1, 0x56 }, /* 0x0A AAT2870_BL8 */ 3409d6292bSJin Park { 0, 1, 0x00 }, /* 0x0B AAT2870_FLR */ 3509d6292bSJin Park { 0, 1, 0x03 }, /* 0x0C AAT2870_FM */ 3609d6292bSJin Park { 0, 1, 0x03 }, /* 0x0D AAT2870_FS */ 3709d6292bSJin Park { 0, 1, 0x10 }, /* 0x0E AAT2870_ALS_CFG0 */ 3809d6292bSJin Park { 0, 1, 0x06 }, /* 0x0F AAT2870_ALS_CFG1 */ 3909d6292bSJin Park { 0, 1, 0x00 }, /* 0x10 AAT2870_ALS_CFG2 */ 4009d6292bSJin Park { 1, 0, 0x00 }, /* 0x11 AAT2870_AMB */ 4109d6292bSJin Park { 0, 1, 0x00 }, /* 0x12 AAT2870_ALS0 */ 4209d6292bSJin Park { 0, 1, 0x00 }, /* 0x13 AAT2870_ALS1 */ 4309d6292bSJin Park { 0, 1, 0x00 }, /* 0x14 AAT2870_ALS2 */ 4409d6292bSJin Park { 0, 1, 0x00 }, /* 0x15 AAT2870_ALS3 */ 4509d6292bSJin Park { 0, 1, 0x00 }, /* 0x16 AAT2870_ALS4 */ 4609d6292bSJin Park { 0, 1, 0x00 }, /* 0x17 AAT2870_ALS5 */ 4709d6292bSJin Park { 0, 1, 0x00 }, /* 0x18 AAT2870_ALS6 */ 4809d6292bSJin Park { 0, 1, 0x00 }, /* 0x19 AAT2870_ALS7 */ 4909d6292bSJin Park { 0, 1, 0x00 }, /* 0x1A AAT2870_ALS8 */ 5009d6292bSJin Park { 0, 1, 0x00 }, /* 0x1B AAT2870_ALS9 */ 5109d6292bSJin Park { 0, 1, 0x00 }, /* 0x1C AAT2870_ALSA */ 5209d6292bSJin Park { 0, 1, 0x00 }, /* 0x1D AAT2870_ALSB */ 5309d6292bSJin Park { 0, 1, 0x00 }, /* 0x1E AAT2870_ALSC */ 5409d6292bSJin Park { 0, 1, 0x00 }, /* 0x1F AAT2870_ALSD */ 5509d6292bSJin Park { 0, 1, 0x00 }, /* 0x20 AAT2870_ALSE */ 5609d6292bSJin Park { 0, 1, 0x00 }, /* 0x21 AAT2870_ALSF */ 5709d6292bSJin Park { 0, 1, 0x00 }, /* 0x22 AAT2870_SUB_SET */ 5809d6292bSJin Park { 0, 1, 0x00 }, /* 0x23 AAT2870_SUB_CTRL */ 5909d6292bSJin Park { 0, 1, 0x00 }, /* 0x24 AAT2870_LDO_AB */ 6009d6292bSJin Park { 0, 1, 0x00 }, /* 0x25 AAT2870_LDO_CD */ 6109d6292bSJin Park { 0, 1, 0x00 }, /* 0x26 AAT2870_LDO_EN */ 6209d6292bSJin Park }; 6309d6292bSJin Park 6409d6292bSJin Park static struct mfd_cell aat2870_devs[] = { 6509d6292bSJin Park { 6609d6292bSJin Park .name = "aat2870-backlight", 6709d6292bSJin Park .id = AAT2870_ID_BL, 6809d6292bSJin Park .pdata_size = sizeof(struct aat2870_bl_platform_data), 6909d6292bSJin Park }, 7009d6292bSJin Park { 7109d6292bSJin Park .name = "aat2870-regulator", 7209d6292bSJin Park .id = AAT2870_ID_LDOA, 7309d6292bSJin Park .pdata_size = sizeof(struct regulator_init_data), 7409d6292bSJin Park }, 7509d6292bSJin Park { 7609d6292bSJin Park .name = "aat2870-regulator", 7709d6292bSJin Park .id = AAT2870_ID_LDOB, 7809d6292bSJin Park .pdata_size = sizeof(struct regulator_init_data), 7909d6292bSJin Park }, 8009d6292bSJin Park { 8109d6292bSJin Park .name = "aat2870-regulator", 8209d6292bSJin Park .id = AAT2870_ID_LDOC, 8309d6292bSJin Park .pdata_size = sizeof(struct regulator_init_data), 8409d6292bSJin Park }, 8509d6292bSJin Park { 8609d6292bSJin Park .name = "aat2870-regulator", 8709d6292bSJin Park .id = AAT2870_ID_LDOD, 8809d6292bSJin Park .pdata_size = sizeof(struct regulator_init_data), 8909d6292bSJin Park }, 9009d6292bSJin Park }; 9109d6292bSJin Park 9209d6292bSJin Park static int __aat2870_read(struct aat2870_data *aat2870, u8 addr, u8 *val) 9309d6292bSJin Park { 9409d6292bSJin Park int ret; 9509d6292bSJin Park 9609d6292bSJin Park if (addr >= AAT2870_REG_NUM) { 9709d6292bSJin Park dev_err(aat2870->dev, "Invalid address, 0x%02x\n", addr); 9809d6292bSJin Park return -EINVAL; 9909d6292bSJin Park } 10009d6292bSJin Park 10109d6292bSJin Park if (!aat2870->reg_cache[addr].readable) { 10209d6292bSJin Park *val = aat2870->reg_cache[addr].value; 10309d6292bSJin Park goto out; 10409d6292bSJin Park } 10509d6292bSJin Park 10609d6292bSJin Park ret = i2c_master_send(aat2870->client, &addr, 1); 10709d6292bSJin Park if (ret < 0) 10809d6292bSJin Park return ret; 10909d6292bSJin Park if (ret != 1) 11009d6292bSJin Park return -EIO; 11109d6292bSJin Park 11209d6292bSJin Park ret = i2c_master_recv(aat2870->client, val, 1); 11309d6292bSJin Park if (ret < 0) 11409d6292bSJin Park return ret; 11509d6292bSJin Park if (ret != 1) 11609d6292bSJin Park return -EIO; 11709d6292bSJin Park 11809d6292bSJin Park out: 11909d6292bSJin Park dev_dbg(aat2870->dev, "read: addr=0x%02x, val=0x%02x\n", addr, *val); 12009d6292bSJin Park return 0; 12109d6292bSJin Park } 12209d6292bSJin Park 12309d6292bSJin Park static int __aat2870_write(struct aat2870_data *aat2870, u8 addr, u8 val) 12409d6292bSJin Park { 12509d6292bSJin Park u8 msg[2]; 12609d6292bSJin Park int ret; 12709d6292bSJin Park 12809d6292bSJin Park if (addr >= AAT2870_REG_NUM) { 12909d6292bSJin Park dev_err(aat2870->dev, "Invalid address, 0x%02x\n", addr); 13009d6292bSJin Park return -EINVAL; 13109d6292bSJin Park } 13209d6292bSJin Park 13309d6292bSJin Park if (!aat2870->reg_cache[addr].writeable) { 13409d6292bSJin Park dev_err(aat2870->dev, "Address 0x%02x is not writeable\n", 13509d6292bSJin Park addr); 13609d6292bSJin Park return -EINVAL; 13709d6292bSJin Park } 13809d6292bSJin Park 13909d6292bSJin Park msg[0] = addr; 14009d6292bSJin Park msg[1] = val; 14109d6292bSJin Park ret = i2c_master_send(aat2870->client, msg, 2); 14209d6292bSJin Park if (ret < 0) 14309d6292bSJin Park return ret; 14409d6292bSJin Park if (ret != 2) 14509d6292bSJin Park return -EIO; 14609d6292bSJin Park 14709d6292bSJin Park aat2870->reg_cache[addr].value = val; 14809d6292bSJin Park 14909d6292bSJin Park dev_dbg(aat2870->dev, "write: addr=0x%02x, val=0x%02x\n", addr, val); 15009d6292bSJin Park return 0; 15109d6292bSJin Park } 15209d6292bSJin Park 15309d6292bSJin Park static int aat2870_read(struct aat2870_data *aat2870, u8 addr, u8 *val) 15409d6292bSJin Park { 15509d6292bSJin Park int ret; 15609d6292bSJin Park 15709d6292bSJin Park mutex_lock(&aat2870->io_lock); 15809d6292bSJin Park ret = __aat2870_read(aat2870, addr, val); 15909d6292bSJin Park mutex_unlock(&aat2870->io_lock); 16009d6292bSJin Park 16109d6292bSJin Park return ret; 16209d6292bSJin Park } 16309d6292bSJin Park 16409d6292bSJin Park static int aat2870_write(struct aat2870_data *aat2870, u8 addr, u8 val) 16509d6292bSJin Park { 16609d6292bSJin Park int ret; 16709d6292bSJin Park 16809d6292bSJin Park mutex_lock(&aat2870->io_lock); 16909d6292bSJin Park ret = __aat2870_write(aat2870, addr, val); 17009d6292bSJin Park mutex_unlock(&aat2870->io_lock); 17109d6292bSJin Park 17209d6292bSJin Park return ret; 17309d6292bSJin Park } 17409d6292bSJin Park 17509d6292bSJin Park static int aat2870_update(struct aat2870_data *aat2870, u8 addr, u8 mask, 17609d6292bSJin Park u8 val) 17709d6292bSJin Park { 17809d6292bSJin Park int change; 17909d6292bSJin Park u8 old_val, new_val; 18009d6292bSJin Park int ret; 18109d6292bSJin Park 18209d6292bSJin Park mutex_lock(&aat2870->io_lock); 18309d6292bSJin Park 18409d6292bSJin Park ret = __aat2870_read(aat2870, addr, &old_val); 18509d6292bSJin Park if (ret) 18609d6292bSJin Park goto out_unlock; 18709d6292bSJin Park 18809d6292bSJin Park new_val = (old_val & ~mask) | (val & mask); 18909d6292bSJin Park change = old_val != new_val; 19009d6292bSJin Park if (change) 19109d6292bSJin Park ret = __aat2870_write(aat2870, addr, new_val); 19209d6292bSJin Park 19309d6292bSJin Park out_unlock: 19409d6292bSJin Park mutex_unlock(&aat2870->io_lock); 19509d6292bSJin Park 19609d6292bSJin Park return ret; 19709d6292bSJin Park } 19809d6292bSJin Park 19909d6292bSJin Park static inline void aat2870_enable(struct aat2870_data *aat2870) 20009d6292bSJin Park { 20109d6292bSJin Park if (aat2870->en_pin >= 0) 20209d6292bSJin Park gpio_set_value(aat2870->en_pin, 1); 20309d6292bSJin Park 20409d6292bSJin Park aat2870->is_enable = 1; 20509d6292bSJin Park } 20609d6292bSJin Park 20709d6292bSJin Park static inline void aat2870_disable(struct aat2870_data *aat2870) 20809d6292bSJin Park { 20909d6292bSJin Park if (aat2870->en_pin >= 0) 21009d6292bSJin Park gpio_set_value(aat2870->en_pin, 0); 21109d6292bSJin Park 21209d6292bSJin Park aat2870->is_enable = 0; 21309d6292bSJin Park } 21409d6292bSJin Park 21509d6292bSJin Park #ifdef CONFIG_DEBUG_FS 21609d6292bSJin Park static ssize_t aat2870_dump_reg(struct aat2870_data *aat2870, char *buf) 21709d6292bSJin Park { 21809d6292bSJin Park u8 addr, val; 21909d6292bSJin Park ssize_t count = 0; 22009d6292bSJin Park int ret; 22109d6292bSJin Park 22209d6292bSJin Park count += sprintf(buf, "aat2870 registers\n"); 22309d6292bSJin Park for (addr = 0; addr < AAT2870_REG_NUM; addr++) { 224c2b5fdfbSTakashi Iwai count += snprintf(buf + count, PAGE_SIZE - count, "0x%02x: ", addr); 22509d6292bSJin Park if (count >= PAGE_SIZE - 1) 22609d6292bSJin Park break; 22709d6292bSJin Park 22809d6292bSJin Park ret = aat2870->read(aat2870, addr, &val); 22909d6292bSJin Park if (ret == 0) 23009d6292bSJin Park count += snprintf(buf + count, PAGE_SIZE - count, 23109d6292bSJin Park "0x%02x", val); 23209d6292bSJin Park else 23309d6292bSJin Park count += snprintf(buf + count, PAGE_SIZE - count, 23409d6292bSJin Park "<read fail: %d>", ret); 23509d6292bSJin Park 23609d6292bSJin Park if (count >= PAGE_SIZE - 1) 23709d6292bSJin Park break; 23809d6292bSJin Park 23909d6292bSJin Park count += snprintf(buf + count, PAGE_SIZE - count, "\n"); 24009d6292bSJin Park if (count >= PAGE_SIZE - 1) 24109d6292bSJin Park break; 24209d6292bSJin Park } 24309d6292bSJin Park 24409d6292bSJin Park /* Truncate count; min() would cause a warning */ 24509d6292bSJin Park if (count >= PAGE_SIZE) 24609d6292bSJin Park count = PAGE_SIZE - 1; 24709d6292bSJin Park 24809d6292bSJin Park return count; 24909d6292bSJin Park } 25009d6292bSJin Park 25109d6292bSJin Park static ssize_t aat2870_reg_read_file(struct file *file, char __user *user_buf, 25209d6292bSJin Park size_t count, loff_t *ppos) 25309d6292bSJin Park { 25409d6292bSJin Park struct aat2870_data *aat2870 = file->private_data; 25509d6292bSJin Park char *buf; 25609d6292bSJin Park ssize_t ret; 25709d6292bSJin Park 25809d6292bSJin Park buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 25909d6292bSJin Park if (!buf) 26009d6292bSJin Park return -ENOMEM; 26109d6292bSJin Park 26209d6292bSJin Park ret = aat2870_dump_reg(aat2870, buf); 26309d6292bSJin Park if (ret >= 0) 26409d6292bSJin Park ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 26509d6292bSJin Park 26609d6292bSJin Park kfree(buf); 26709d6292bSJin Park 26809d6292bSJin Park return ret; 26909d6292bSJin Park } 27009d6292bSJin Park 27109d6292bSJin Park static ssize_t aat2870_reg_write_file(struct file *file, 27209d6292bSJin Park const char __user *user_buf, size_t count, 27309d6292bSJin Park loff_t *ppos) 27409d6292bSJin Park { 27509d6292bSJin Park struct aat2870_data *aat2870 = file->private_data; 27609d6292bSJin Park char buf[32]; 277c38d66acSJin Park ssize_t buf_size; 27809d6292bSJin Park char *start = buf; 27909d6292bSJin Park unsigned long addr, val; 28009d6292bSJin Park int ret; 28109d6292bSJin Park 282ecf67ac3SSachin Kamat buf_size = min(count, (size_t)(sizeof(buf)-1)); 28309d6292bSJin Park if (copy_from_user(buf, user_buf, buf_size)) { 28409d6292bSJin Park dev_err(aat2870->dev, "Failed to copy from user\n"); 28509d6292bSJin Park return -EFAULT; 28609d6292bSJin Park } 28709d6292bSJin Park buf[buf_size] = 0; 28809d6292bSJin Park 28909d6292bSJin Park while (*start == ' ') 29009d6292bSJin Park start++; 29109d6292bSJin Park 2920ebc1c25SLee Jones ret = kstrtoul(start, 16, &addr); 2930ebc1c25SLee Jones if (ret) 2940ebc1c25SLee Jones return ret; 2950ebc1c25SLee Jones 29609d6292bSJin Park if (addr >= AAT2870_REG_NUM) { 29709d6292bSJin Park dev_err(aat2870->dev, "Invalid address, 0x%lx\n", addr); 29809d6292bSJin Park return -EINVAL; 29909d6292bSJin Park } 30009d6292bSJin Park 30109d6292bSJin Park while (*start == ' ') 30209d6292bSJin Park start++; 30309d6292bSJin Park 3048420a241SJingoo Han ret = kstrtoul(start, 16, &val); 3058420a241SJingoo Han if (ret) 3068420a241SJingoo Han return ret; 30709d6292bSJin Park 30809d6292bSJin Park ret = aat2870->write(aat2870, (u8)addr, (u8)val); 30909d6292bSJin Park if (ret) 31009d6292bSJin Park return ret; 31109d6292bSJin Park 31209d6292bSJin Park return buf_size; 31309d6292bSJin Park } 31409d6292bSJin Park 31509d6292bSJin Park static const struct file_operations aat2870_reg_fops = { 316234e3405SStephen Boyd .open = simple_open, 31709d6292bSJin Park .read = aat2870_reg_read_file, 31809d6292bSJin Park .write = aat2870_reg_write_file, 31909d6292bSJin Park }; 32009d6292bSJin Park 32109d6292bSJin Park static void aat2870_init_debugfs(struct aat2870_data *aat2870) 32209d6292bSJin Park { 32309d6292bSJin Park aat2870->dentry_root = debugfs_create_dir("aat2870", NULL); 32409d6292bSJin Park 325dc607f6bSGreg Kroah-Hartman debugfs_create_file("regs", 0644, aat2870->dentry_root, aat2870, 326dc607f6bSGreg Kroah-Hartman &aat2870_reg_fops); 32709d6292bSJin Park } 32809d6292bSJin Park 32909d6292bSJin Park #else 33009d6292bSJin Park static inline void aat2870_init_debugfs(struct aat2870_data *aat2870) 33109d6292bSJin Park { 33209d6292bSJin Park } 33309d6292bSJin Park #endif /* CONFIG_DEBUG_FS */ 33409d6292bSJin Park 335*fb53f666SUwe Kleine-König static int aat2870_i2c_probe(struct i2c_client *client) 33609d6292bSJin Park { 337334a41ceSJingoo Han struct aat2870_platform_data *pdata = dev_get_platdata(&client->dev); 33809d6292bSJin Park struct aat2870_data *aat2870; 33909d6292bSJin Park int i, j; 34009d6292bSJin Park int ret = 0; 34109d6292bSJin Park 3420287714bSJingoo Han aat2870 = devm_kzalloc(&client->dev, sizeof(struct aat2870_data), 3430287714bSJingoo Han GFP_KERNEL); 3444374b20cSLee Jones if (!aat2870) 3450287714bSJingoo Han return -ENOMEM; 34609d6292bSJin Park 34709d6292bSJin Park aat2870->dev = &client->dev; 34809d6292bSJin Park dev_set_drvdata(aat2870->dev, aat2870); 34909d6292bSJin Park 35009d6292bSJin Park aat2870->client = client; 35109d6292bSJin Park i2c_set_clientdata(client, aat2870); 35209d6292bSJin Park 35309d6292bSJin Park aat2870->reg_cache = aat2870_regs; 35409d6292bSJin Park 35509d6292bSJin Park if (pdata->en_pin < 0) 35609d6292bSJin Park aat2870->en_pin = -1; 35709d6292bSJin Park else 35809d6292bSJin Park aat2870->en_pin = pdata->en_pin; 35909d6292bSJin Park 36009d6292bSJin Park aat2870->init = pdata->init; 36109d6292bSJin Park aat2870->uninit = pdata->uninit; 36209d6292bSJin Park aat2870->read = aat2870_read; 36309d6292bSJin Park aat2870->write = aat2870_write; 36409d6292bSJin Park aat2870->update = aat2870_update; 36509d6292bSJin Park 36609d6292bSJin Park mutex_init(&aat2870->io_lock); 36709d6292bSJin Park 36809d6292bSJin Park if (aat2870->init) 36909d6292bSJin Park aat2870->init(aat2870); 37009d6292bSJin Park 37109d6292bSJin Park if (aat2870->en_pin >= 0) { 3720287714bSJingoo Han ret = devm_gpio_request_one(&client->dev, aat2870->en_pin, 3730287714bSJingoo Han GPIOF_OUT_INIT_HIGH, "aat2870-en"); 37409d6292bSJin Park if (ret < 0) { 37509d6292bSJin Park dev_err(&client->dev, 37609d6292bSJin Park "Failed to request GPIO %d\n", aat2870->en_pin); 3770287714bSJingoo Han return ret; 37809d6292bSJin Park } 37909d6292bSJin Park } 38009d6292bSJin Park 38109d6292bSJin Park aat2870_enable(aat2870); 38209d6292bSJin Park 38309d6292bSJin Park for (i = 0; i < pdata->num_subdevs; i++) { 38409d6292bSJin Park for (j = 0; j < ARRAY_SIZE(aat2870_devs); j++) { 38509d6292bSJin Park if ((pdata->subdevs[i].id == aat2870_devs[j].id) && 38609d6292bSJin Park !strcmp(pdata->subdevs[i].name, 38709d6292bSJin Park aat2870_devs[j].name)) { 38809d6292bSJin Park aat2870_devs[j].platform_data = 38909d6292bSJin Park pdata->subdevs[i].platform_data; 39009d6292bSJin Park break; 39109d6292bSJin Park } 39209d6292bSJin Park } 39309d6292bSJin Park } 39409d6292bSJin Park 39509d6292bSJin Park ret = mfd_add_devices(aat2870->dev, 0, aat2870_devs, 3960848c94fSMark Brown ARRAY_SIZE(aat2870_devs), NULL, 0, NULL); 39709d6292bSJin Park if (ret != 0) { 39809d6292bSJin Park dev_err(aat2870->dev, "Failed to add subdev: %d\n", ret); 39909d6292bSJin Park goto out_disable; 40009d6292bSJin Park } 40109d6292bSJin Park 40209d6292bSJin Park aat2870_init_debugfs(aat2870); 40309d6292bSJin Park 40409d6292bSJin Park return 0; 40509d6292bSJin Park 40609d6292bSJin Park out_disable: 40709d6292bSJin Park aat2870_disable(aat2870); 40809d6292bSJin Park return ret; 40909d6292bSJin Park } 41009d6292bSJin Park 4115214e565SMark Brown #ifdef CONFIG_PM_SLEEP 4125214e565SMark Brown static int aat2870_i2c_suspend(struct device *dev) 41309d6292bSJin Park { 4145214e565SMark Brown struct i2c_client *client = to_i2c_client(dev); 41509d6292bSJin Park struct aat2870_data *aat2870 = i2c_get_clientdata(client); 41609d6292bSJin Park 41709d6292bSJin Park aat2870_disable(aat2870); 41809d6292bSJin Park 41909d6292bSJin Park return 0; 42009d6292bSJin Park } 42109d6292bSJin Park 4225214e565SMark Brown static int aat2870_i2c_resume(struct device *dev) 42309d6292bSJin Park { 4245214e565SMark Brown struct i2c_client *client = to_i2c_client(dev); 42509d6292bSJin Park struct aat2870_data *aat2870 = i2c_get_clientdata(client); 42609d6292bSJin Park struct aat2870_register *reg = NULL; 42709d6292bSJin Park int i; 42809d6292bSJin Park 42909d6292bSJin Park aat2870_enable(aat2870); 43009d6292bSJin Park 43109d6292bSJin Park /* restore registers */ 43209d6292bSJin Park for (i = 0; i < AAT2870_REG_NUM; i++) { 43309d6292bSJin Park reg = &aat2870->reg_cache[i]; 43409d6292bSJin Park if (reg->writeable) 43509d6292bSJin Park aat2870->write(aat2870, i, reg->value); 43609d6292bSJin Park } 43709d6292bSJin Park 43809d6292bSJin Park return 0; 43909d6292bSJin Park } 4405214e565SMark Brown #endif /* CONFIG_PM_SLEEP */ 4415214e565SMark Brown 4425214e565SMark Brown static SIMPLE_DEV_PM_OPS(aat2870_pm_ops, aat2870_i2c_suspend, 4435214e565SMark Brown aat2870_i2c_resume); 44409d6292bSJin Park 445d4e94863SAxel Lin static const struct i2c_device_id aat2870_i2c_id_table[] = { 44609d6292bSJin Park { "aat2870", 0 }, 44709d6292bSJin Park { } 44809d6292bSJin Park }; 44909d6292bSJin Park 45009d6292bSJin Park static struct i2c_driver aat2870_i2c_driver = { 45109d6292bSJin Park .driver = { 45209d6292bSJin Park .name = "aat2870", 4535214e565SMark Brown .pm = &aat2870_pm_ops, 45417f808a7SPaul Gortmaker .suppress_bind_attrs = true, 45509d6292bSJin Park }, 456*fb53f666SUwe Kleine-König .probe_new = aat2870_i2c_probe, 45709d6292bSJin Park .id_table = aat2870_i2c_id_table, 45809d6292bSJin Park }; 45909d6292bSJin Park 46009d6292bSJin Park static int __init aat2870_init(void) 46109d6292bSJin Park { 46209d6292bSJin Park return i2c_add_driver(&aat2870_i2c_driver); 46309d6292bSJin Park } 46409d6292bSJin Park subsys_initcall(aat2870_init); 465