static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) { struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); struct wm8994 *wm8994 = wm8994_gpio->wm8994; int i; for (i = 0; i < chip->ngpio; i++) { int gpio = i + chip->base; int reg; const char *label; /* We report the GPIO even if it's not requested since * we're also reporting things like alternate * functions which apply even when the GPIO is not in * use as a GPIO. */ label = gpiochip_is_requested(chip, i); if (!label) label = "Unrequested"; seq_printf(s, " gpio-%-3d (%-20.20s) ", gpio, label); reg = wm8994_reg_read(wm8994, WM8994_GPIO_1 + i); if (reg < 0) { dev_err(wm8994->dev, "GPIO control %d read failed: %d\n", gpio, reg); seq_printf(s, "\n"); continue; } if (reg & WM8994_GPN_DIR) seq_printf(s, "in "); else seq_printf(s, "out "); if (reg & WM8994_GPN_PU) seq_printf(s, "pull up "); if (reg & WM8994_GPN_PD) seq_printf(s, "pull down "); if (reg & WM8994_GPN_POL) seq_printf(s, "inverted "); else seq_printf(s, "noninverted "); if (reg & WM8994_GPN_OP_CFG) seq_printf(s, "open drain "); else seq_printf(s, "push-pull "); seq_printf(s, "%s (%x)\n", wm8994_gpio_fn(reg & WM8994_GPN_FN_MASK), reg); } }
static int wm8994_ldo1_get_voltage_sel(struct regulator_dev *rdev) { struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); int val; val = wm8994_reg_read(ldo->wm8994, WM8994_LDO_1); if (val < 0) return val; return (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT; }
static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev) { struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); int val; val = wm8994_reg_read(ldo->wm8994, WM8994_LDO_2); if (val < 0) return val; val = (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT; return wm8994_ldo2_list_voltage(rdev, val); }
static int wm8994_gpio_get(struct gpio_chip *chip, unsigned offset) { struct wm8994_gpio *wm8994_gpio = gpiochip_get_data(chip); struct wm8994 *wm8994 = wm8994_gpio->wm8994; int ret; ret = wm8994_reg_read(wm8994, WM8994_GPIO_1 + offset); if (ret < 0) return ret; if (ret & WM8994_GPN_LVL) return 1; else return 0; }
static int wm8994_suspend(struct device *dev) { struct wm8994 *wm8994 = dev_get_drvdata(dev); int ret; /* Don't actually go through with the suspend if the CODEC is * still active (eg, for audio passthrough from CP. */ ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_1); if (ret < 0) { dev_err(dev, "Failed to read power status: %d\n", ret); } else if (ret & WM8994_VMID_SEL_MASK) { dev_dbg(dev, "CODEC still active, ignoring suspend\n"); return 0; } /* 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. */ ret = wm8994_read(wm8994, WM8994_GPIO_1, WM8994_NUM_GPIO_REGS * 2, &wm8994->gpio_regs); if (ret < 0) dev_err(dev, "Failed to save GPIO registers: %d\n", ret); /* For similar reasons we also stash the regulator states */ ret = wm8994_read(wm8994, WM8994_LDO_1, WM8994_NUM_LDO_REGS * 2, &wm8994->ldo_regs); if (ret < 0) dev_err(dev, "Failed to save LDO registers: %d\n", ret); /* Explicitly put the device into reset in case regulators * don't get disabled in order to ensure consistent restart. */ wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, 0x8994); wm8994->suspended = true; ret = regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(dev, "Failed to disable supplies: %d\n", ret); return ret; } return 0; }
/* * Instantiate the generic non-control parts of the device. */ static int wm8994_device_init(struct wm8994 *wm8994, int irq) { struct wm8994_pdata *pdata = wm8994->dev->platform_data; const char *devname; int ret, i; mutex_init(&wm8994->io_lock); dev_set_drvdata(wm8994->dev, wm8994); // ret = gpio_request(GPIO_WM8994_LDO_EN, "wm8994_ldo"); if (ret < 0) { printk(KERN_ERR "Can't request gpio%d for wm8994_ldo: %d\n", GPIO_WM8994_LDO_EN, ret); goto err; } tegra_gpio_enable(GPIO_WM8994_LDO_EN); ret = gpio_direction_output(GPIO_WM8994_LDO_EN, 1); if (ret < 0) { printk(KERN_ERR "Can't set gpio%d direction to output: %d\n", GPIO_WM8994_LDO_EN, ret); goto err; } gpio_set_value(GPIO_WM8994_LDO_EN, 1); msleep(10); // // /* Add the on-chip regulators first for bootstrapping */ ret = mfd_add_devices(wm8994->dev, -1, wm8994_regulator_devs, ARRAY_SIZE(wm8994_regulator_devs), NULL, 0); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err; } switch (wm8994->type) { case WM8994: wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); break; case WM8958: wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); break; default: BUG(); return -EINVAL; } wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * wm8994->num_supplies, GFP_KERNEL); if (!wm8994->supplies) { ret = -ENOMEM; goto err; } switch (wm8994->type) { case WM8994: for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) wm8994->supplies[i].supply = wm8994_main_supplies[i]; break; case WM8958: for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++) wm8994->supplies[i].supply = wm8958_main_supplies[i]; break; default: BUG(); return -EINVAL; } ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); goto err_supplies; } ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); goto err_get; } ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); if (ret < 0) { dev_err(wm8994->dev, "Failed to read ID register\n"); goto err_enable; } switch (ret) { case 0x8994: devname = "WM8994"; if (wm8994->type != WM8994) dev_warn(wm8994->dev, "Device registered as type %d\n", wm8994->type); wm8994->type = WM8994; break; case 0x8958: devname = "WM8958"; if (wm8994->type != WM8958) dev_warn(wm8994->dev, "Device registered as type %d\n", wm8994->type); wm8994->type = WM8958; break; default: dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", ret); ret = -EINVAL; goto err_enable; } ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); if (ret < 0) { dev_err(wm8994->dev, "Failed to read revision register: %d\n", ret); goto err_enable; } switch (ret) { case 0: case 1: if (wm8994->type == WM8994) dev_warn(wm8994->dev, "revision %c not fully supported\n", 'A' + ret); break; default: break; } dev_info(wm8994->dev, "%s revision %c\n", devname, 'A' + ret); if (pdata) { wm8994->irq_base = pdata->irq_base; wm8994->gpio_base = pdata->gpio_base; /* GPIO configuration is only applied if it's non-zero */ for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { if (pdata->gpio_defaults[i]) { wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, 0xffff, pdata->gpio_defaults[i]); } } } /* 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 * LDOs are enabled, it only affects cases where the LDOs were * in operation and are then disabled. */ for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { if (wm8994_ldo_in_use(pdata, i)) wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); else wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, 0); } wm8994_irq_init(wm8994); ret = mfd_add_devices(wm8994->dev, -1, wm8994_devs, ARRAY_SIZE(wm8994_devs), NULL, 0); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err_irq; } #if !defined(CONFIG_ARCH_TEGRA) pm_runtime_enable(wm8994->dev); pm_runtime_resume(wm8994->dev); #endif return 0; err_irq: wm8994_irq_exit(wm8994); err_enable: regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); err_get: regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); err_supplies: kfree(wm8994->supplies); err: mfd_remove_devices(wm8994->dev); kfree(wm8994); return ret; }
static int wm8994_suspend(struct device *dev) { struct wm8994 *wm8994 = dev_get_drvdata(dev); int ret; #if defined(CONFIG_MACH_STAR) || defined(CONFIG_MACH_BSSQ) if(in_call_state() // || is_fmradio_state() // ) return 0; #endif /* MOBII LP1 sleep */ /* Don't actually go through with the suspend if the CODEC is * still active (eg, for audio passthrough from CP. */ // #if 0 ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_1); if (ret < 0) { printk("[chahee.kim] Failed to read power status: %d\n", ret); } else if (ret & WM8994_VMID_SEL_MASK) { printk("[chahee.kim] CODEC still active, ignoring suspend\n"); return 0; } #endif // /* 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. */ ret = wm8994_bulk_read(wm8994, WM8994_GPIO_1, WM8994_NUM_GPIO_REGS, &wm8994->gpio_regs); if (ret < 0) printk("Failed to save GPIO registers: %d\n", ret); /* For similar reasons we also stash the regulator states */ ret = wm8994_bulk_read(wm8994, WM8994_LDO_1, WM8994_NUM_LDO_REGS, &wm8994->ldo_regs); if (ret < 0) printk("Failed to save LDO registers: %d\n", ret); /* Explicitly put the device into reset in case regulators * don't get disabled in order to ensure consistent restart. */ wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, 0x8994); wm8994->suspended = true; // printk("[chahee.kim] wm8994_suspend in wm8994-core.c END !!\n"); // ret = regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(dev, "Failed to disable supplies: %d\n", ret); return ret; } return 0; }
static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq) { struct wm8994_pdata *pdata = wm8994->dev->platform_data; int ret, i; mutex_init(&wm8994->io_lock); dev_set_drvdata(wm8994->dev, wm8994); /* Add the on-chip regulators first for bootstrapping */ ret = mfd_add_devices(wm8994->dev, -1, wm8994_regulator_devs, ARRAY_SIZE(wm8994_regulator_devs), NULL, 0); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err; } wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * ARRAY_SIZE(wm8994_main_supplies), GFP_KERNEL); if (!wm8994->supplies) goto err; for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) wm8994->supplies[i].supply = wm8994_main_supplies[i]; ret = regulator_bulk_get(wm8994->dev, ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); goto err_supplies; } ret = regulator_bulk_enable(ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); goto err_get; } ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); if (ret < 0) { dev_err(wm8994->dev, "Failed to read ID register\n"); goto err_enable; } if (ret != 0x8994) { dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", ret); ret = -EINVAL; goto err_enable; } ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); if (ret < 0) { dev_err(wm8994->dev, "Failed to read revision register: %d\n", ret); goto err_enable; } switch (ret) { case 0: case 1: dev_warn(wm8994->dev, "revision %c not fully supported\n", 'A' + ret); break; default: dev_info(wm8994->dev, "revision %c\n", 'A' + ret); break; } if (pdata) { wm8994->irq_base = pdata->irq_base; wm8994->gpio_base = pdata->gpio_base; /* GPIO configuration is only applied if it's non-zero */ for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { if (pdata->gpio_defaults[i]) { wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, 0xffff, pdata->gpio_defaults[i]); } } } /* 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 * LDOs are enabled, it only affects cases where the LDOs were * in operation and are then disabled. */ for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { if (wm8994_ldo_in_use(pdata, i)) wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); else wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, 0); } wm8994_irq_init(wm8994); ret = mfd_add_devices(wm8994->dev, -1, wm8994_devs, ARRAY_SIZE(wm8994_devs), NULL, 0); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err_irq; } return 0; err_irq: wm8994_irq_exit(wm8994); err_enable: regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies); err_get: regulator_bulk_free(ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies); err_supplies: kfree(wm8994->supplies); err: mfd_remove_devices(wm8994->dev); kfree(wm8994); return ret; }
/* * Instantiate the generic non-control parts of the device. */ static int wm8994_device_init(struct wm8994 *wm8994, int irq) { struct wm8994_pdata *pdata; struct regmap_config *regmap_config; const struct reg_default *regmap_patch = NULL; const char *devname; int ret, i, patch_regs = 0; int pulls = 0; if (dev_get_platdata(wm8994->dev)) { pdata = dev_get_platdata(wm8994->dev); wm8994->pdata = *pdata; } pdata = &wm8994->pdata; ret = wm8994_set_pdata_from_of(wm8994); if (ret != 0) return ret; dev_set_drvdata(wm8994->dev, wm8994); /* Add the on-chip regulators first for bootstrapping */ ret = mfd_add_devices(wm8994->dev, -1, wm8994_regulator_devs, ARRAY_SIZE(wm8994_regulator_devs), NULL, 0, NULL); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err; } 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; case WM8958: wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); break; default: BUG(); goto err; } wm8994->supplies = devm_kzalloc(wm8994->dev, sizeof(struct regulator_bulk_data) * wm8994->num_supplies, GFP_KERNEL); if (!wm8994->supplies) { ret = -ENOMEM; goto err; } 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]; break; case WM8958: for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++) wm8994->supplies[i].supply = wm8958_main_supplies[i]; break; default: BUG(); goto err; } ret = devm_regulator_bulk_get(wm8994->dev, wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); goto err; } ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); goto err; } ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); if (ret < 0) { dev_err(wm8994->dev, "Failed to read ID register\n"); goto err_enable; } 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; break; case 0x8994: devname = "WM8994"; if (wm8994->type != WM8994) dev_warn(wm8994->dev, "Device registered as type %d\n", wm8994->type); wm8994->type = WM8994; break; case 0x8958: devname = "WM8958"; if (wm8994->type != WM8958) dev_warn(wm8994->dev, "Device registered as type %d\n", wm8994->type); wm8994->type = WM8958; break; default: dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", ret); ret = -EINVAL; goto err_enable; } ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); if (ret < 0) { dev_err(wm8994->dev, "Failed to read revision register: %d\n", ret); goto err_enable; } 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' + wm8994->revision); break; case 2: case 3: default: regmap_patch = wm8994_revc_patch; patch_regs = ARRAY_SIZE(wm8994_revc_patch); break; } break; case WM8958: switch (wm8994->revision) { case 0: regmap_patch = wm8958_reva_patch; patch_regs = ARRAY_SIZE(wm8958_reva_patch); break; default: break; } break; case WM1811: /* Revision C did not change the relevant layer */ if (wm8994->revision > 1) wm8994->revision++; regmap_patch = wm1811_reva_patch; patch_regs = ARRAY_SIZE(wm1811_reva_patch); break; default: break; } dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname, 'A' + wm8994->revision, wm8994->cust_id); switch (wm8994->type) { case WM1811: regmap_config = &wm1811_regmap_config; break; case WM8994: regmap_config = &wm8994_regmap_config; break; case WM8958: regmap_config = &wm8958_regmap_config; break; default: dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type); return -EINVAL; } ret = regmap_reinit_cache(wm8994->regmap, regmap_config); if (ret != 0) { dev_err(wm8994->dev, "Failed to reinit register cache: %d\n", ret); return ret; } /* Explicitly put the device into reset in case regulators * don't get disabled in order to ensure we know the device * state. */ ret = wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); if (ret != 0) { dev_err(wm8994->dev, "Failed to reset device: %d\n", ret); return ret; } if (regmap_patch) { ret = regmap_register_patch(wm8994->regmap, regmap_patch, patch_regs); if (ret != 0) { dev_err(wm8994->dev, "Failed to register patch: %d\n", ret); goto err; } } wm8994->irq_base = pdata->irq_base; wm8994->gpio_base = pdata->gpio_base; /* GPIO configuration is only applied if it's non-zero */ for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { if (pdata->gpio_defaults[i]) { wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, 0xffff, 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 * LDOs are enabled, it only affects cases where the LDOs were * in operation and are then disabled. */ for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { if (wm8994_ldo_in_use(pdata, i)) wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); else wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, 0); } wm8994_irq_init(wm8994); ret = mfd_add_devices(wm8994->dev, -1, wm8994_devs, ARRAY_SIZE(wm8994_devs), NULL, 0, NULL); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err_irq; } pm_runtime_enable(wm8994->dev); pm_runtime_idle(wm8994->dev); return 0; err_irq: wm8994_irq_exit(wm8994); err_enable: regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); err: mfd_remove_devices(wm8994->dev); return ret; }
static int wm8994_suspend(struct device *dev) { struct wm8994 *wm8994 = dev_get_drvdata(dev); int ret; /* Don't actually go through with the suspend if the CODEC is * still active for accessory detect. */ 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; } /* 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); /* Explicitly put the device into reset in case regulators * don't get disabled in order to ensure consistent restart. */ wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); regcache_mark_dirty(wm8994->regmap); /* Restore GPIO registers to prevent problems with mismatched * pin configurations. */ ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1, WM8994_GPIO_11); if (ret != 0) dev_err(dev, "Failed to restore GPIO registers: %d\n", ret); /* In case one of the GPIOs is used as a wake input. */ ret = regcache_sync_region(wm8994->regmap, WM8994_INTERRUPT_STATUS_1_MASK, WM8994_INTERRUPT_STATUS_1_MASK); if (ret != 0) dev_err(dev, "Failed to restore interrupt mask: %d\n", ret); regcache_cache_only(wm8994->regmap, true); wm8994->suspended = true; ret = regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(dev, "Failed to disable supplies: %d\n", ret); return ret; } return 0; }
static int wm8994_suspend(struct device *dev) { struct wm8994 *wm8994 = dev_get_drvdata(dev); int ret; /* Don't actually go through with the suspend if the CODEC is * still active (eg, for audio passthrough from CP. */ ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_1); if (ret < 0) { dev_err(dev, "Failed to read power status: %d\n", ret); } else if (ret & WM8994_VMID_SEL_MASK) { dev_dbg(dev, "CODEC still active, ignoring suspend\n"); 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; } 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); /* Explicitly put the device into reset in case regulators * don't get disabled in order to ensure consistent restart. */ wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); regcache_cache_only(wm8994->regmap, true); regcache_mark_dirty(wm8994->regmap); wm8994->suspended = true; ret = regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(dev, "Failed to disable supplies: %d\n", ret); return ret; } return 0; }
/* * Instantiate the generic non-control parts of the device. */ 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); /* Add the on-chip regulators first for bootstrapping */ ret = mfd_add_devices(wm8994->dev, -1, wm8994_regulator_devs, ARRAY_SIZE(wm8994_regulator_devs), NULL, 0); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err; } 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; case WM8958: wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); break; default: BUG(); goto err; } wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * wm8994->num_supplies, GFP_KERNEL); if (!wm8994->supplies) { ret = -ENOMEM; goto err; } 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]; break; case WM8958: for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++) wm8994->supplies[i].supply = wm8958_main_supplies[i]; break; default: BUG(); goto err_supplies; } ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); goto err_supplies; } ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); goto err_get; } ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); 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; break; case 0x8994: devname = "WM8994"; if (wm8994->type != WM8994) dev_warn(wm8994->dev, "Device registered as type %d\n", wm8994->type); wm8994->type = WM8994; break; case 0x8958: devname = "WM8958"; if (wm8994->type != WM8958) dev_warn(wm8994->dev, "Device registered as type %d\n", wm8994->type); wm8994->type = WM8958; break; default: dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", ret); ret = -EINVAL; goto err_enable; } ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); if (ret < 0) { dev_err(wm8994->dev, "Failed to read revision register: %d\n", ret); goto err_enable; } switch (wm8994->type) { case WM8994: switch (ret) { case 0: case 1: dev_warn(wm8994->dev, "revision %c not fully supported\n", 'A' + ret); break; default: break; } break; default: break; } dev_info(wm8994->dev, "%s revision %c\n", devname, 'A' + ret); if (pdata) { wm8994->irq_base = pdata->irq_base; wm8994->gpio_base = pdata->gpio_base; /* GPIO configuration is only applied if it's non-zero */ for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { if (pdata->gpio_defaults[i]) { wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, 0xffff, 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 * LDOs are enabled, it only affects cases where the LDOs were * in operation and are then disabled. */ for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { if (wm8994_ldo_in_use(pdata, i)) wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); else wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, 0); } wm8994_irq_init(wm8994); ret = mfd_add_devices(wm8994->dev, -1, wm8994_devs, ARRAY_SIZE(wm8994_devs), NULL, 0); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err_irq; } pm_runtime_enable(wm8994->dev); pm_runtime_resume(wm8994->dev); mclk_gpio = pdata->mclk_pin; set_mclk(1); return 0; err_irq: wm8994_irq_exit(wm8994); err_enable: regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); err_get: regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); err_supplies: kfree(wm8994->supplies); err: mfd_remove_devices(wm8994->dev); return ret; }
static int wm8994_device_suspend(struct device *dev) { struct wm8994 *wm8994 = dev_get_drvdata(dev); int ret; /* Don't actually go through with the suspend if the CODEC is * still active (eg, for audio passthrough from CP. */ ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_1); if (ret < 0) { dev_err(dev, "Failed to read power status: %d\n", ret); } else if (ret & WM8994_VMID_SEL_MASK) { dev_dbg(dev, "CODEC still active, ignoring suspend\n"); 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. */ ret = wm8994_read(wm8994, WM8994_GPIO_1, WM8994_NUM_GPIO_REGS * 2, &wm8994->gpio_regs); if (ret < 0) dev_err(dev, "Failed to save GPIO registers: %d\n", ret); /* For similar reasons we also stash the regulator states */ ret = wm8994_read(wm8994, WM8994_LDO_1, WM8994_NUM_LDO_REGS * 2, &wm8994->ldo_regs); if (ret < 0) dev_err(dev, "Failed to save LDO registers: %d\n", ret); /* Explicitly put the device into reset in case regulators * don't get disabled in order to ensure consistent restart. */ wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, 0x8994); wm8994->suspended = true; ret = regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(dev, "Failed to disable supplies: %d\n", ret); return ret; } set_mclk(0); return 0; }
static __devinit int wm8994_device_init(struct wm8994 *wm8994, int irq) { struct wm8994_pdata *pdata = wm8994->dev->platform_data; struct regmap_config *regmap_config; const struct reg_default *regmap_patch = NULL; const char *devname; int ret, i, patch_regs; int pulls = 0; dev_set_drvdata(wm8994->dev, wm8994); ret = mfd_add_devices(wm8994->dev, -1, wm8994_regulator_devs, ARRAY_SIZE(wm8994_regulator_devs), NULL, 0); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err; } 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; case WM8958: wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); break; default: BUG(); goto err; } wm8994->supplies = devm_kzalloc(wm8994->dev, sizeof(struct regulator_bulk_data) * wm8994->num_supplies, GFP_KERNEL); if (!wm8994->supplies) { ret = -ENOMEM; goto err; } 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]; break; case WM8958: for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++) wm8994->supplies[i].supply = wm8958_main_supplies[i]; break; default: BUG(); goto err; } ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); goto err; } ret = regulator_bulk_enable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); goto err_get; } ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); if (ret < 0) { dev_err(wm8994->dev, "Failed to read ID register\n"); goto err_enable; } 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; break; case 0x8994: devname = "WM8994"; if (wm8994->type != WM8994) dev_warn(wm8994->dev, "Device registered as type %d\n", wm8994->type); wm8994->type = WM8994; break; case 0x8958: devname = "WM8958"; if (wm8994->type != WM8958) dev_warn(wm8994->dev, "Device registered as type %d\n", wm8994->type); wm8994->type = WM8958; break; default: dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", ret); ret = -EINVAL; goto err_enable; } ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); if (ret < 0) { dev_err(wm8994->dev, "Failed to read revision register: %d\n", ret); goto err_enable; } wm8994->revision = ret; switch (wm8994->type) { case WM8994: switch (wm8994->revision) { case 0: case 1: dev_warn(wm8994->dev, "revision %c not fully supported\n", 'A' + wm8994->revision); break; case 2: case 3: regmap_patch = wm8994_revc_patch; patch_regs = ARRAY_SIZE(wm8994_revc_patch); break; default: break; } break; case WM8958: switch (wm8994->revision) { case 0: regmap_patch = wm8958_reva_patch; patch_regs = ARRAY_SIZE(wm8958_reva_patch); break; default: break; } break; case WM1811: if (wm8994->revision > 1) wm8994->revision++; switch (wm8994->revision) { case 0: case 1: case 2: case 3: case 4: regmap_patch = wm1811_reva_patch; patch_regs = ARRAY_SIZE(wm1811_reva_patch); break; default: break; } break; default: break; } dev_info(wm8994->dev, "%s revision %c\n", devname, 'A' + wm8994->revision); switch (wm8994->type) { case WM1811: regmap_config = &wm1811_regmap_config; break; case WM8994: regmap_config = &wm8994_regmap_config; break; case WM8958: regmap_config = &wm8958_regmap_config; break; default: dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type); return -EINVAL; } ret = regmap_reinit_cache(wm8994->regmap, regmap_config); if (ret != 0) { dev_err(wm8994->dev, "Failed to reinit register cache: %d\n", ret); return ret; } if (regmap_patch) { ret = regmap_register_patch(wm8994->regmap, regmap_patch, patch_regs); if (ret != 0) { dev_err(wm8994->dev, "Failed to register patch: %d\n", ret); goto err; } } if (pdata) { wm8994->irq_base = pdata->irq_base; wm8994->gpio_base = pdata->gpio_base; for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { if (pdata->gpio_defaults[i]) { wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, 0xffff, pdata->gpio_defaults[i]); } } wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven; if (pdata->spkmode_pu) pulls |= WM8994_SPKMODE_PU; } wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD | WM8994_SPKMODE_PU | WM8994_CSNADDR_PD, pulls); for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { if (wm8994_ldo_in_use(pdata, i)) wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); else wm8994_set_bits(wm8994, WM8994_LDO_1 + i, WM8994_LDO1_DISCH, 0); } wm8994_irq_init(wm8994); ret = mfd_add_devices(wm8994->dev, -1, wm8994_devs, ARRAY_SIZE(wm8994_devs), NULL, 0); if (ret != 0) { dev_err(wm8994->dev, "Failed to add children: %d\n", ret); goto err_irq; } pm_runtime_enable(wm8994->dev); pm_runtime_idle(wm8994->dev); return 0; err_irq: wm8994_irq_exit(wm8994); err_enable: regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); err_get: regulator_bulk_free(wm8994->num_supplies, wm8994->supplies); err: mfd_remove_devices(wm8994->dev); return ret; }
static int wm8994_suspend(struct device *dev) { struct wm8994 *wm8994 = dev_get_drvdata(dev); int ret; ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_1); if (ret < 0) { dev_err(dev, "Failed to read power status: %d\n", ret); } else if (ret & WM8994_VMID_SEL_MASK) { dev_dbg(dev, "CODEC still active, ignoring suspend\n"); 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; } 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; } 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); wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); regcache_cache_only(wm8994->regmap, true); regcache_mark_dirty(wm8994->regmap); wm8994->suspended = true; ret = regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); if (ret != 0) { dev_err(dev, "Failed to disable supplies: %d\n", ret); return ret; } return 0; }