diff options
Diffstat (limited to 'drivers/mfd/wm8994-core.c')
-rw-r--r-- | drivers/mfd/wm8994-core.c | 242 |
1 files changed, 224 insertions, 18 deletions
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c index e198d40..95f9c0e 100644 --- a/drivers/mfd/wm8994-core.c +++ b/drivers/mfd/wm8994-core.c @@ -243,6 +243,18 @@ static struct mfd_cell wm8994_devs[] = { * and should be handled via the standard regulator API supply * management. */ +static const char *wm1811_main_supplies[] = { + "DBVDD1", + "DBVDD2", + "DBVDD3", + "DCVDD", + "AVDD1", + "AVDD2", + "CPVDD", + "SPKVDD1", + "SPKVDD2", +}; + static const char *wm8994_main_supplies[] = { "DBVDD", "DCVDD", @@ -281,6 +293,62 @@ static int wm8994_suspend(struct device *dev) return 0; } + ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_4); + if (ret < 0) { + dev_err(dev, "Failed to read power status: %d\n", ret); + } else if (ret & (WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA | + WM8994_AIF1ADC2L_ENA | WM8994_AIF1ADC2R_ENA | + WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC1R_ENA)) { + dev_dbg(dev, "CODEC still active, ignoring suspend\n"); + return 0; + } + + ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_5); + if (ret < 0) { + dev_err(dev, "Failed to read power status: %d\n", ret); + } else if (ret & (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA | + WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA | + WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA)) { + dev_dbg(dev, "CODEC still active, ignoring suspend\n"); + return 0; + } + + switch (wm8994->type) { + case WM8958: + case WM1811: + ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1); + if (ret < 0) { + dev_err(dev, "Failed to read power status: %d\n", ret); + } else if (ret & WM8958_MICD_ENA) { + dev_dbg(dev, "CODEC still active, ignoring suspend\n"); + return 0; + } + break; + default: + break; + } + + switch (wm8994->type) { + case WM1811: + ret = wm8994_reg_read(wm8994, WM8994_ANTIPOP_2); + if (ret < 0) { + dev_err(dev, "Failed to read jackdet: %d\n", ret); + } else if (ret & WM1811_JACKDET_MODE_MASK) { + dev_dbg(dev, "CODEC still active, ignoring suspend\n"); + return 0; + } + break; + default: + break; + } + + /* Disable LDO pulldowns while the device is suspended if we + * don't know that something will be driving them. */ + if (!wm8994->ldo_ena_always_driven) + wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, + WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD, + WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD); + /* GPIO configuration state is saved here since we may be configuring * the GPIO alternate functions even if we're not using the gpiolib * driver for them. @@ -316,7 +384,7 @@ static int wm8994_suspend(struct device *dev) static int wm8994_resume(struct device *dev) { struct wm8994 *wm8994 = dev_get_drvdata(dev); - int ret; + int ret, i; /* We may have lied to the PM core about suspending */ if (!wm8994->suspended) @@ -329,10 +397,16 @@ static int wm8994_resume(struct device *dev) return ret; } - ret = wm8994_write(wm8994, WM8994_INTERRUPT_STATUS_1_MASK, - WM8994_NUM_IRQ_REGS * 2, &wm8994->irq_masks_cur); - if (ret < 0) - dev_err(dev, "Failed to restore interrupt masks: %d\n", ret); + /* Write register at a time as we use the cache on the CPU so store + * it in native endian. + */ + for (i = 0; i < ARRAY_SIZE(wm8994->irq_masks_cur); i++) { + ret = wm8994_reg_write(wm8994, WM8994_INTERRUPT_STATUS_1_MASK + + i, wm8994->irq_masks_cur[i]); + if (ret < 0) + dev_err(dev, "Failed to restore interrupt masks: %d\n", + ret); + } ret = wm8994_write(wm8994, WM8994_LDO_1, WM8994_NUM_LDO_REGS * 2, &wm8994->ldo_regs); @@ -344,6 +418,11 @@ static int wm8994_resume(struct device *dev) if (ret < 0) dev_err(dev, "Failed to restore GPIO registers: %d\n", ret); + /* Disable LDO pulldowns while the device is active */ + wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, + WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD, + 0); + wm8994->suspended = false; return 0; @@ -380,6 +459,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) struct wm8994_pdata *pdata = wm8994->dev->platform_data; const char *devname; int ret, i; + int pulls = 0; mutex_init(&wm8994->io_lock); dev_set_drvdata(wm8994->dev, wm8994); @@ -395,6 +475,9 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) } switch (wm8994->type) { + case WM1811: + wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies); + break; case WM8994: wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); break; @@ -403,7 +486,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) break; default: BUG(); - return -EINVAL; + goto err; } wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * @@ -415,6 +498,10 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) } switch (wm8994->type) { + case WM1811: + for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++) + wm8994->supplies[i].supply = wm1811_main_supplies[i]; + break; case WM8994: for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) wm8994->supplies[i].supply = wm8994_main_supplies[i]; @@ -425,9 +512,9 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) break; default: BUG(); - return -EINVAL; + goto err; } - + ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, wm8994->supplies); if (ret != 0) { @@ -446,8 +533,29 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) if (ret < 0) { dev_err(wm8994->dev, "Failed to read ID register\n"); goto err_enable; - } + } else + dev_info(wm8994->dev, "Succeeded to read ID register\n"); + switch (ret) { + case 0x1811: + devname = "WM1811"; + if (wm8994->type != WM1811) + dev_warn(wm8994->dev, "Device registered as type %d\n", + wm8994->type); + wm8994->type = WM1811; + + /* Samsung-specific customization of MICBIAS levels */ + wm8994_reg_write(wm8994, 0x102, 0x3); + wm8994_reg_write(wm8994, 0xcb, 0x5151); + wm8994_reg_write(wm8994, 0xd3, 0x3f3f); + wm8994_reg_write(wm8994, 0xd4, 0x3f3f); + wm8994_reg_write(wm8994, 0xd5, 0x3f3f); + wm8994_reg_write(wm8994, 0xd6, 0x3226); + wm8994_reg_write(wm8994, 0x102, 0x0); + wm8994_reg_write(wm8994, 0xd1, 0x87); + wm8994_reg_write(wm8994, 0x3b, 0x9); + wm8994_reg_write(wm8994, 0x3c, 0x2); + break; case 0x8994: devname = "WM8994"; if (wm8994->type != WM8994) @@ -476,19 +584,28 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) goto err_enable; } - switch (ret) { - case 0: - case 1: - if (wm8994->type == WM8994) + wm8994->revision = ret & WM8994_CHIP_REV_MASK; + wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT; + + switch (wm8994->type) { + case WM8994: + switch (wm8994->revision) { + case 0: + case 1: dev_warn(wm8994->dev, "revision %c not fully supported\n", - 'A' + ret); + 'A' + wm8994->revision); + break; + default: + break; + } break; default: break; } - dev_info(wm8994->dev, "%s revision %c\n", devname, 'A' + ret); + dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname, + 'A' + wm8994->revision, wm8994->cust_id); if (pdata) { wm8994->irq_base = pdata->irq_base; @@ -502,8 +619,19 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) pdata->gpio_defaults[i]); } } + + wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven; + + if (pdata->spkmode_pu) + pulls |= WM8994_SPKMODE_PU; } + /* Disable unneeded pulls */ + wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, + WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD | + WM8994_SPKMODE_PU | WM8994_CSNADDR_PD, + pulls); + /* In some system designs where the regulators are not in use, * we can achieve a small reduction in leakage currents by * floating LDO outputs. This bit makes no difference if the @@ -529,8 +657,10 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq) goto err_irq; } +#if 0 /* To do */ pm_runtime_enable(wm8994->dev); pm_runtime_resume(wm8994->dev); +#endif return 0; @@ -545,7 +675,6 @@ err_supplies: kfree(wm8994->supplies); err: mfd_remove_devices(wm8994->dev); - kfree(wm8994); return ret; } @@ -582,13 +711,24 @@ static int wm8994_i2c_read_device(struct wm8994 *wm8994, unsigned short reg, return 0; } -static int wm8994_i2c_write_device(struct wm8994 *wm8994, unsigned short reg, +static int wm8994_i2c_gather_write_device(struct wm8994 *wm8994, unsigned short reg, int bytes, const void *src) { struct i2c_client *i2c = wm8994->control_data; struct i2c_msg xfer[2]; int ret; + if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_PROTOCOL_MANGLING)) { + dev_vdbg(wm8994->dev, + "%s: I2C Controller does _NOT_ support block/gather\n", + __func__); + return -ENOTSUPP; + } + + dev_vdbg(wm8994->dev, + "%s: gather write - Reg = 0x%04x, bytes = 0x%x\n", + __func__, reg, bytes); + reg = cpu_to_be16(reg); xfer[0].addr = i2c->addr; @@ -610,6 +750,66 @@ static int wm8994_i2c_write_device(struct wm8994 *wm8994, unsigned short reg, return 0; } +static int wm8994_i2c_write_device(struct wm8994 *wm8994, unsigned short reg, + int bytes, const void *src) +{ + struct i2c_client *i2c = wm8994->control_data; + int ret; + + unsigned char msg[2 + 2]; + void *buf; + + /* If we're doing a single register write we can probably just + * send the work_buf directly, otherwise try to do a gather + * write. + */ + if (bytes == 2) { + dev_vdbg(wm8994->dev, + "%s: Single register write - Reg = 0x%04x, bytes = 0x%x\n", + __func__, reg, bytes); + + reg = cpu_to_be16(reg); + memcpy(&msg[0], ®, 2); + memcpy(&msg[2], src, bytes); + + ret = i2c_master_send(i2c, msg, bytes + 2); + if (ret < 0) + return ret; + if (ret < bytes + 2) + return -EIO; + + return 0; + } else { + ret = wm8994_i2c_gather_write_device(wm8994, reg, bytes, src); + } + + if (ret == -ENOTSUPP) { + dev_vdbg(wm8994->dev, + "%s: Manual group write - Reg = 0x%04x, bytes = 0x%x\n", + __func__, reg, bytes); + + buf = kmalloc(2 + bytes, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + reg = cpu_to_be16(reg); + memcpy(buf, ®, 2); + memcpy(buf + 2, src, bytes); + + ret = i2c_master_send(i2c, buf, bytes + 2); + + kfree(buf); + + if (ret < 0) + return ret; + if (ret < bytes + 2) + return -EIO; + + return 0; + } + return ret; +} + static int wm8994_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -627,7 +827,12 @@ static int wm8994_i2c_probe(struct i2c_client *i2c, wm8994->irq = i2c->irq; wm8994->type = id->driver_data; - return wm8994_device_init(wm8994, i2c->irq); + if (wm8994_device_init(wm8994, i2c->irq) < 0) { + kfree(wm8994); + return -ENODEV; + } + + return 0; } static int wm8994_i2c_remove(struct i2c_client *i2c) @@ -640,6 +845,7 @@ static int wm8994_i2c_remove(struct i2c_client *i2c) } static const struct i2c_device_id wm8994_i2c_id[] = { + { "wm1811", WM1811 }, { "wm8994", WM8994 }, { "wm8958", WM8958 }, { } |