int __devinit arizona_dev_init(struct arizona *arizona) { struct device *dev = arizona->dev; const char *type_name; unsigned int reg, val; int ret, i; dev_set_drvdata(arizona->dev, arizona); mutex_init(&arizona->clk_lock); if (dev_get_platdata(arizona->dev)) memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), sizeof(arizona->pdata)); regcache_cache_only(arizona->regmap, true); switch (arizona->type) { case WM5102: case WM5110: for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++) arizona->core_supplies[i].supply = wm5102_core_supplies[i]; arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies); break; default: dev_err(arizona->dev, "Unknown device type %d\n", arizona->type); return -EINVAL; } ret = mfd_add_devices(arizona->dev, -1, early_devs, ARRAY_SIZE(early_devs), NULL, 0); if (ret != 0) { dev_err(dev, "Failed to add early children: %d\n", ret); return ret; } ret = regulator_bulk_get(dev, arizona->num_core_supplies, arizona->core_supplies); if (ret != 0) { dev_err(dev, "Failed to request core supplies: %d\n", ret); goto err_early; } ret = regulator_bulk_enable(arizona->num_core_supplies, arizona->core_supplies); if (ret != 0) { dev_err(dev, "Failed to enable core supplies: %d\n", ret); goto err_bulk_get; } if (arizona->pdata.reset) { /* Start out with /RESET low to put the chip into reset */ ret = gpio_request_one(arizona->pdata.reset, GPIOF_DIR_OUT | GPIOF_INIT_LOW, "arizona /RESET"); if (ret != 0) { dev_err(dev, "Failed to request /RESET: %d\n", ret); goto err_enable; } gpio_set_value_cansleep(arizona->pdata.reset, 1); } if (arizona->pdata.ldoena) { ret = gpio_request_one(arizona->pdata.ldoena, GPIOF_DIR_OUT | GPIOF_INIT_HIGH, "arizona LDOENA"); if (ret != 0) { dev_err(dev, "Failed to request LDOENA: %d\n", ret); goto err_reset; } } regcache_cache_only(arizona->regmap, false); ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®); if (ret != 0) { dev_err(dev, "Failed to read ID register: %d\n", ret); goto err_ldoena; } ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION, &arizona->rev); if (ret != 0) { dev_err(dev, "Failed to read revision register: %d\n", ret); goto err_ldoena; } arizona->rev &= ARIZONA_DEVICE_REVISION_MASK; switch (reg) { #ifdef CONFIG_MFD_WM5102 case 0x5102: type_name = "WM5102"; if (arizona->type != WM5102) { dev_err(arizona->dev, "WM5102 registered as %d\n", arizona->type); arizona->type = WM5102; } ret = wm5102_patch(arizona); break; #endif #ifdef CONFIG_MFD_WM5110 case 0x5110: type_name = "WM5110"; if (arizona->type != WM5110) { dev_err(arizona->dev, "WM5110 registered as %d\n", arizona->type); arizona->type = WM5110; } ret = wm5110_patch(arizona); break; #endif default: dev_err(arizona->dev, "Unknown device ID %x\n", reg); goto err_ldoena; } dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A'); if (ret != 0) dev_err(arizona->dev, "Failed to apply patch: %d\n", ret); /* If we have a /RESET GPIO we'll already be reset */ if (!arizona->pdata.reset) { ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0); if (ret != 0) { dev_err(dev, "Failed to reset device: %d\n", ret); goto err_ldoena; } } ret = arizona_wait_for_boot(arizona); if (ret != 0) { dev_err(arizona->dev, "Device failed initial boot: %d\n", ret); goto err_reset; } for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { if (!arizona->pdata.gpio_defaults[i]) continue; regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i, arizona->pdata.gpio_defaults[i]); } pm_runtime_set_autosuspend_delay(arizona->dev, 100); pm_runtime_use_autosuspend(arizona->dev); pm_runtime_enable(arizona->dev); /* Chip default */ if (!arizona->pdata.clk32k_src) arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2; switch (arizona->pdata.clk32k_src) { case ARIZONA_32KZ_MCLK1: case ARIZONA_32KZ_MCLK2: regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, ARIZONA_CLK_32K_SRC_MASK, arizona->pdata.clk32k_src - 1); break; case ARIZONA_32KZ_NONE: regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, ARIZONA_CLK_32K_SRC_MASK, 2); break; default: dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n", arizona->pdata.clk32k_src); ret = -EINVAL; goto err_ldoena; } for (i = 0; i < ARIZONA_MAX_INPUT; i++) { /* Default for both is 0 so noop with defaults */ val = arizona->pdata.dmic_ref[i] << ARIZONA_IN1_DMIC_SUP_SHIFT; val |= arizona->pdata.inmode[i] << ARIZONA_IN1_MODE_SHIFT; regmap_update_bits(arizona->regmap, ARIZONA_IN1L_CONTROL + (i * 8), ARIZONA_IN1_DMIC_SUP_MASK | ARIZONA_IN1_MODE_MASK, val); } for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) { /* Default is 0 so noop with defaults */ if (arizona->pdata.out_mono[i]) val = ARIZONA_OUT1_MONO; else val = 0; regmap_update_bits(arizona->regmap, ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8), ARIZONA_OUT1_MONO, val); } for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) { if (arizona->pdata.spk_mute[i]) regmap_update_bits(arizona->regmap, ARIZONA_PDM_SPK1_CTRL_1 + (i * 2), ARIZONA_SPK1_MUTE_ENDIAN_MASK | ARIZONA_SPK1_MUTE_SEQ1_MASK, arizona->pdata.spk_mute[i]); if (arizona->pdata.spk_fmt[i]) regmap_update_bits(arizona->regmap, ARIZONA_PDM_SPK1_CTRL_2 + (i * 2), ARIZONA_SPK1_FMT_MASK, arizona->pdata.spk_fmt[i]); } /* Set up for interrupts */ ret = arizona_irq_init(arizona); if (ret != 0) goto err_ldoena; arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error", arizona_clkgen_err, arizona); arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked", arizona_overclocked, arizona); arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked", arizona_underclocked, arizona); switch (arizona->type) { case WM5102: ret = mfd_add_devices(arizona->dev, -1, wm5102_devs, ARRAY_SIZE(wm5102_devs), NULL, 0); break; case WM5110: ret = mfd_add_devices(arizona->dev, -1, wm5110_devs, ARRAY_SIZE(wm5110_devs), NULL, 0); break; } if (ret != 0) { dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret); goto err_irq; } return 0; err_irq: arizona_irq_exit(arizona); err_ldoena: if (arizona->pdata.ldoena) { gpio_set_value_cansleep(arizona->pdata.ldoena, 0); gpio_free(arizona->pdata.ldoena); } err_reset: if (arizona->pdata.reset) { gpio_set_value_cansleep(arizona->pdata.reset, 1); gpio_free(arizona->pdata.reset); } err_enable: regulator_bulk_disable(ARRAY_SIZE(arizona->core_supplies), arizona->core_supplies); err_bulk_get: regulator_bulk_free(ARRAY_SIZE(arizona->core_supplies), arizona->core_supplies); err_early: mfd_remove_devices(dev); return ret; }
static int __devinit pm8038_probe(struct platform_device *pdev) { const struct pm8038_platform_data *pdata = pdev->dev.platform_data; const char *revision_name = "unknown"; struct pm8038 *pmic; enum pm8xxx_version version; int revision; int rc; u8 val; if (!pdata) { pr_err("missing platform data\n"); return -EINVAL; } pmic = kzalloc(sizeof(struct pm8038), GFP_KERNEL); if (!pmic) { pr_err("Cannot alloc pm8038 struct\n"); return -ENOMEM; } /* Read PMIC chip revision */ rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val)); if (rc) { pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc); goto err_read_rev; } pr_info("PMIC revision 1: PM8038 rev %02X\n", val); pmic->rev_registers = val; /* Read PMIC chip revision 2 */ rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val)); if (rc) { pr_err("Failed to read hw rev 2 reg %d:rc=%d\n", REG_HWREV_2, rc); goto err_read_rev; } pr_info("PMIC revision 2: PM8038 rev %02X\n", val); pmic->rev_registers |= val << BITS_PER_BYTE; pmic->dev = &pdev->dev; pm8038_drvdata.pm_chip_data = pmic; platform_set_drvdata(pdev, &pm8038_drvdata); /* Print out human readable version and revision names. */ version = pm8xxx_get_version(pmic->dev); if (version == PM8XXX_VERSION_8038) { revision = pm8xxx_get_revision(pmic->dev); if (revision >= 0 && revision < ARRAY_SIZE(pm8038_rev_names)) revision_name = pm8038_rev_names[revision]; pr_info("PMIC version: PM8038 ver %s\n", revision_name); } else { WARN_ON(version != PM8XXX_VERSION_8038); } /* Log human readable restart reason */ rc = msm_ssbi_read(pdev->dev.parent, REG_PM8038_PON_CNTRL_3, &val, 1); if (rc) { pr_err("Cannot read restart reason rc=%d\n", rc); goto err_read_rev; } val &= PM8038_RESTART_REASON_MASK; pr_info("PMIC Restart Reason: %s\n", pm8038_restart_reason[val]); rc = pm8038_add_subdevices(pdata, pmic); if (rc) { pr_err("Cannot add subdevices rc=%d\n", rc); goto err; } return 0; err: mfd_remove_devices(pmic->dev); platform_set_drvdata(pdev, NULL); kfree(pmic->mfd_regulators); kfree(pmic->regulator_cdata); err_read_rev: kfree(pmic); return rc; }
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; }
/* * 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); #if defined(CONFIG_ARCH_TEGRA) 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(20); #endif /* defined(CONFIG_ARCH_TEGRA) */ /* 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) * ARRAY_SIZE(wm8994_main_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, 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, "1st : Failed to read ID register\n"); msleep(10); } ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); if (ret < 0) { dev_err(wm8994->dev, "2nd : Failed to read ID register\n"); msleep(10); } ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); if (ret < 0) { dev_err(wm8994->dev, "3rd : 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]); } } } wm8994_set_bits(wm8994, WM8994_GPIO_1, 0xf,0x1); /* 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; }
static void __devexit rdc321x_sb_remove(struct pci_dev *pdev) { mfd_remove_devices(&pdev->dev); }
static int __devinit pm8921_probe(struct platform_device *pdev) { const struct pm8921_platform_data *pdata = pdev->dev.platform_data; const char *revision_name = "unknown"; struct pm8921 *pmic; #ifdef CONFIG_MACH_ACER_A9 struct kobject *dev_info_pmic_kobj; #else enum pm8xxx_version version; int revision; #endif int rc; u8 val; if (!pdata) { pr_err("missing platform data\n"); return -EINVAL; } pmic = kzalloc(sizeof(struct pm8921), GFP_KERNEL); if (!pmic) { pr_err("Cannot alloc pm8921 struct\n"); return -ENOMEM; } /* Read PMIC chip revision */ rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val)); if (rc) { pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc); goto err_read_rev; } pr_info("PMIC revision 1: %02X\n", val); pmic->rev_registers = val; /* Read PMIC chip revision 2 */ rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val)); if (rc) { pr_err("Failed to read hw rev 2 reg %d:rc=%d\n", REG_HWREV_2, rc); goto err_read_rev; } pr_info("PMIC revision 2: %02X\n", val); pmic->rev_registers |= val << BITS_PER_BYTE; pmic->dev = &pdev->dev; pm8921_drvdata.pm_chip_data = pmic; platform_set_drvdata(pdev, &pm8921_drvdata); /* Print out human readable version and revision names. */ version = pm8xxx_get_version(pmic->dev); revision = pm8xxx_get_revision(pmic->dev); if (version == PM8XXX_VERSION_8921) { if (revision >= 0 && revision < ARRAY_SIZE(pm8921_rev_names)) revision_name = pm8921_rev_names[revision]; pr_info("PMIC version: PM8921 rev %s\n", revision_name); } else if (version == PM8XXX_VERSION_8922) { if (revision >= 0 && revision < ARRAY_SIZE(pm8922_rev_names)) revision_name = pm8922_rev_names[revision]; pr_info("PMIC version: PM8922 rev %s\n", revision_name); } else if (version == PM8XXX_VERSION_8917) { if (revision >= 0 && revision < ARRAY_SIZE(pm8917_rev_names)) revision_name = pm8917_rev_names[revision]; pr_info("PMIC version: PM8917 rev %s\n", revision_name); } else { WARN_ON(version != PM8XXX_VERSION_8921 && version != PM8XXX_VERSION_8922 && version != PM8XXX_VERSION_8917); } #ifdef CONFIG_MACH_ACER_A9 dev_info_pmic_kobj = kobject_create_and_add("dev-info_pmic", NULL); if (dev_info_pmic_kobj == NULL) { pr_err("Failed to create dev-info_pmic kobject\n"); } rc = sysfs_create_group(dev_info_pmic_kobj, &pmic_attr_group); if(rc) { pr_err("Failed to create dev-info_pmic sysfs group\n"); } #endif /* Log human readable restart reason */ rc = msm_ssbi_read(pdev->dev.parent, REG_PM8921_PON_CNTRL_3, &val, 1); if (rc) { pr_err("Cannot read restart reason rc=%d\n", rc); goto err_read_rev; } val &= PM8921_RESTART_REASON_MASK; pr_info("PMIC Restart Reason: %s\n", pm8921_restart_reason[val]); rc = pm8921_add_subdevices(pdata, pmic); if (rc) { pr_err("Cannot add subdevices rc=%d\n", rc); goto err; } /* gpio might not work if no irq device is found */ WARN_ON(pmic->irq_chip == NULL); return 0; err: mfd_remove_devices(pmic->dev); platform_set_drvdata(pdev, NULL); kfree(pmic->mfd_regulators); kfree(pmic->regulator_cdata); err_read_rev: kfree(pmic); return rc; }
static int max77804k_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77804k_dev *max77804k; struct max77804k_platform_data *pdata; u8 reg_data; int ret = 0; dev_info(&i2c->dev, "%s\n", __func__); max77804k = kzalloc(sizeof(struct max77804k_dev), GFP_KERNEL); if (max77804k == NULL) return -ENOMEM; if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max77804k_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory \n"); ret = -ENOMEM; goto err; } ret = of_max77804k_dt(&i2c->dev, pdata); if (ret < 0){ dev_err(&i2c->dev, "Failed to get device of_node \n"); ret = -ENOMEM; goto err; } /*Filling the platform data*/ pdata->muic_data = &max77804k_muic; #ifdef CONFIG_REGULATOR_MAX77804K pdata->num_regulators = MAX77804K_REG_MAX; pdata->regulators = max77804k_regulators; #endif #ifdef CONFIG_LEDS_MAX77804K pdata->led_data = &max77804k_led_pdata; #endif /*pdata update to other modules*/ i2c->dev.platform_data = pdata; } else pdata = i2c->dev.platform_data; i2c_set_clientdata(i2c, max77804k); max77804k->dev = &i2c->dev; max77804k->i2c = i2c; max77804k->irq = i2c->irq; if (pdata) { max77804k->irq_base = pdata->irq_base; max77804k->irq_gpio = pdata->irq_gpio; max77804k->wakeup = pdata->wakeup; gpio_tlmm_config(GPIO_CFG(max77804k->irq_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE); } else { ret = -EINVAL; goto err; } mutex_init(&max77804k->iolock); if (max77804k_read_reg(i2c, MAX77804K_PMIC_REG_PMIC_ID2, ®_data) < 0) { dev_err(max77804k->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else { /* print rev */ max77804k->pmic_rev = (reg_data & 0x7); max77804k->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s: device found: rev.0x%x, ver.0x%x\n", __func__, max77804k->pmic_rev, max77804k->pmic_ver); } max77804k_update_reg(i2c, MAX77804K_CHG_REG_SAFEOUT_CTRL, 0x00, 0x30); max77804k->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77804k->muic, max77804k); max77804k->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); i2c_set_clientdata(max77804k->haptic, max77804k); ret = max77804k_irq_init(max77804k); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77804k->dev, -1, max77804k_devs, ARRAY_SIZE(max77804k_devs), NULL, 0); if (ret < 0) goto err_mfd; device_init_wakeup(max77804k->dev, pdata->wakeup); /* Set continuous mode */ max77804k_update_reg(max77804k->muic, MAX77804K_MUIC_REG_CTRL4, ADC_ALWAYS, CTRL4_ADCMODE_MASK); return ret; err_mfd: mfd_remove_devices(max77804k->dev); max77804k_irq_exit(max77804k); err_irq_init: i2c_unregister_device(max77804k->muic); i2c_unregister_device(max77804k->haptic); err: kfree(max77804k); return ret; }
static int max8998_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max8998_platform_data *pdata = dev_get_platdata(&i2c->dev); struct max8998_dev *max8998; int ret = 0; max8998 = devm_kzalloc(&i2c->dev, sizeof(struct max8998_dev), GFP_KERNEL); if (max8998 == NULL) return -ENOMEM; if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) { pdata = max8998_i2c_parse_dt_pdata(&i2c->dev); if (IS_ERR(pdata)) { ret = PTR_ERR(pdata); goto err; } } i2c_set_clientdata(i2c, max8998); max8998->dev = &i2c->dev; max8998->i2c = i2c; max8998->irq = i2c->irq; max8998->type = max8998_i2c_get_driver_data(i2c, id); max8998->pdata = pdata; if (pdata) { max8998->ono = pdata->ono; max8998->irq_base = pdata->irq_base; max8998->wakeup = pdata->wakeup; } mutex_init(&max8998->iolock); max8998->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR); if (!max8998->rtc) { dev_err(&i2c->dev, "Failed to allocate I2C device for RTC\n"); return -ENODEV; } i2c_set_clientdata(max8998->rtc, max8998); max8998_irq_init(max8998); pm_runtime_set_active(max8998->dev); switch (max8998->type) { case TYPE_LP3974: ret = mfd_add_devices(max8998->dev, -1, lp3974_devs, ARRAY_SIZE(lp3974_devs), NULL, 0, NULL); break; case TYPE_MAX8998: ret = mfd_add_devices(max8998->dev, -1, max8998_devs, ARRAY_SIZE(max8998_devs), NULL, 0, NULL); break; default: ret = -EINVAL; } if (ret < 0) goto err; device_init_wakeup(max8998->dev, max8998->wakeup); return ret; err: mfd_remove_devices(max8998->dev); max8998_irq_exit(max8998); i2c_unregister_device(max8998->rtc); return ret; }
static int max14577_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max14577_dev *max14577; struct max14577_platform_data *pdata = NULL; u8 reg_data; int ret = 0; max14577 = kzalloc(sizeof(struct max14577_dev), GFP_KERNEL); if (max14577 == NULL) return -ENOMEM; if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max14577_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory\n"); ret = -ENOMEM; goto err; } ret = of_max14577_dt(&i2c->dev, pdata); if (ret < 0) { dev_err(&i2c->dev, "Failed to get device of_node\n"); kfree(pdata); goto err; } /*pdata update to other modules*/ i2c->dev.platform_data = pdata; } else pdata = i2c->dev.platform_data; i2c_set_clientdata(i2c, max14577); max14577->dev = &i2c->dev; max14577->i2c = i2c; max14577->irq = i2c->irq; if (pdata) { max14577->pdata = pdata; } else { ret = -EIO; goto err; } pdata->set_cdetctrl1_reg = max14577_set_cdetctrl1_reg; pdata->get_cdetctrl1_reg = max14577_get_cdetctrl1_reg; pdata->set_control2_reg = max14577_set_control2_reg; pdata->get_control2_reg = max14577_get_control2_reg; #ifdef CONFIG_REGULATOR_MAX77836 pdata->regulators = max77836_reglator_pdata; pdata->num_regulators = MAX77836_LDO_MAX; #endif #ifdef CONFIG_CHARGER_MAX14577 pdata->charger_data = &sec_battery_pdata; #endif mutex_init(&max14577->i2c_lock); ret = max14577_read_reg(i2c, MAX14577_REG_DEVICEID, ®_data); if (ret < 0) { pr_err("%s:%s device not found on this channel(%d)\n", MFD_DEV_NAME, __func__, ret); goto err; } else { /* print Device Id */ max14577->vendor_id = (reg_data & 0x7); max14577->device_id = ((reg_data & 0xF8) >> 0x3); pr_info("%s:%s device found: vendor=0x%x, device_id=0x%x\n", MFD_DEV_NAME, __func__, max14577->vendor_id, max14577->device_id); } max14577->i2c_pmic = i2c_new_dummy(i2c->adapter, MAX77836_PMIC_ADDR); i2c_set_clientdata(max14577->i2c_pmic, max14577); ret = max14577_irq_init(max14577); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max14577->dev, -1, max14577_devs, ARRAY_SIZE(max14577_devs), NULL, 0); if (ret < 0) goto err_mfd; device_init_wakeup(max14577->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max14577->dev); err_irq_init: if (max14577->i2c_pmic) i2c_unregister_device(max14577->i2c_pmic); err: kfree(max14577); return ret; }
static int __devinit lpc_sch_probe(struct pci_dev *dev, const struct pci_device_id *id) { unsigned int base_addr_cfg; unsigned short base_addr; int i; int ret; pci_read_config_dword(dev, SMBASE, &base_addr_cfg); if (!(base_addr_cfg & (1 << 31))) { dev_err(&dev->dev, "Decode of the SMBus I/O range disabled\n"); return -ENODEV; } base_addr = (unsigned short)base_addr_cfg; if (base_addr == 0) { dev_err(&dev->dev, "I/O space for SMBus uninitialized\n"); return -ENODEV; } smbus_sch_resource.start = base_addr; smbus_sch_resource.end = base_addr + SMBUS_IO_SIZE - 1; pci_read_config_dword(dev, GPIOBASE, &base_addr_cfg); if (!(base_addr_cfg & (1 << 31))) { dev_err(&dev->dev, "Decode of the GPIO I/O range disabled\n"); return -ENODEV; } base_addr = (unsigned short)base_addr_cfg; if (base_addr == 0) { dev_err(&dev->dev, "I/O space for GPIO uninitialized\n"); return -ENODEV; } gpio_sch_resource.start = base_addr; gpio_sch_resource.end = base_addr + GPIO_IO_SIZE - 1; for (i=0; i < ARRAY_SIZE(lpc_sch_cells); i++) lpc_sch_cells[i].id = id->device; ret = mfd_add_devices(&dev->dev, 0, lpc_sch_cells, ARRAY_SIZE(lpc_sch_cells), NULL, 0); if (ret) goto out_dev; if (id->device == PCI_DEVICE_ID_INTEL_ITC_LPC) { pci_read_config_dword(dev, WDTBASE, &base_addr_cfg); if (!(base_addr_cfg & (1 << 31))) { dev_err(&dev->dev, "Decode of the WDT I/O range disabled\n"); ret = -ENODEV; goto out_dev; } base_addr = (unsigned short)base_addr_cfg; if (base_addr == 0) { dev_err(&dev->dev, "I/O space for WDT uninitialized\n"); ret = -ENODEV; goto out_dev; } wdt_sch_resource.start = base_addr; wdt_sch_resource.end = base_addr + WDT_IO_SIZE - 1; for (i = 0; i < ARRAY_SIZE(tunnelcreek_cells); i++) tunnelcreek_cells[i].id = id->device; ret = mfd_add_devices(&dev->dev, 0, tunnelcreek_cells, ARRAY_SIZE(tunnelcreek_cells), NULL, 0); } return ret; out_dev: mfd_remove_devices(&dev->dev); return ret; }
static __devexit void acx00_device_exit(struct acx00 *acx00) { mfd_remove_devices(acx00->dev); }
static void __devexit lpc_sch_remove(struct pci_dev *dev) { mfd_remove_devices(&dev->dev); }
static int __devinit pm8921_probe(struct platform_device *pdev) { const struct pm8921_platform_data *pdata = pdev->dev.platform_data; const char *revision_name = "unknown"; struct pm8921 *pmic; enum pm8xxx_version version; int revision; int rc; u8 val; u8 subrev = 0; if (!pdata) { pr_err("missing platform data\n"); return -EINVAL; } pmic = kzalloc(sizeof(struct pm8921), GFP_KERNEL); if (!pmic) { pr_err("Cannot alloc pm8921 struct\n"); return -ENOMEM; } rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val)); if (rc) { pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc); goto err_read_rev; } pr_info("PMIC revision 1: %02X\n", val); pmic->rev_registers = val; rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val)); if (rc) { pr_err("Failed to read hw rev 2 reg %d:rc=%d\n", REG_HWREV_2, rc); goto err_read_rev; } pr_info("PMIC revision 2: %02X\n", val); pmic->rev_registers |= val << BITS_PER_BYTE; pmic->dev = &pdev->dev; pm8921_drvdata.pm_chip_data = pmic; platform_set_drvdata(pdev, &pm8921_drvdata); version = pm8xxx_get_version(pmic->dev); revision = pm8xxx_get_revision(pmic->dev); rc = msm_ssbi_read(pdev->dev.parent, REG_HWSUBREV, &subrev, sizeof(subrev)); if (rc) pr_err("Failed to read hw subrev reg %d:rc=%d\n", REG_HWSUBREV, rc); if (version == PM8XXX_VERSION_8921) { if (revision >= 0 && revision < ARRAY_SIZE(pm8921_rev_names)) revision_name = pm8921_rev_names[revision]; if ((revision == PM8XXX_REVISION_8921_3p0) && (subrev & PM8921_SUBREV_MASK)) pr_info("PMIC version: PM8921 rev %s.1\n", revision_name); else pr_info("PMIC version: PM8921 rev %s\n", revision_name); } else if (version == PM8XXX_VERSION_8922) { if (revision >= 0 && revision < ARRAY_SIZE(pm8922_rev_names)) revision_name = pm8922_rev_names[revision]; pr_info("PMIC version: PM8922 rev %s\n", revision_name); } else if (version == PM8XXX_VERSION_8917) { if (revision >= 0 && revision < ARRAY_SIZE(pm8917_rev_names)) revision_name = pm8917_rev_names[revision]; pr_info("PMIC version: PM8917 rev %s\n", revision_name); } else { WARN_ON(version != PM8XXX_VERSION_8921 && version != PM8XXX_VERSION_8922 && version != PM8XXX_VERSION_8917); } rc = msm_ssbi_read(pdev->dev.parent, REG_PM8921_PON_CNTRL_3, &val, 1); if (rc) { pr_err("Cannot read restart reason rc=%d\n", rc); goto err_read_rev; } val &= PM8921_RESTART_REASON_MASK; pr_info("PMIC Restart Reason: %s\n", pm8921_restart_reason[val]); rc = pm8921_add_subdevices(pdata, pmic); if (rc) { pr_err("Cannot add subdevices rc=%d\n", rc); goto err; } WARN_ON(pmic->irq_chip == NULL); pmic8921_chip = pmic; register_syscore_ops(&pm8921_pm); return 0; err: mfd_remove_devices(pmic->dev); platform_set_drvdata(pdev, NULL); kfree(pmic->mfd_regulators); kfree(pmic->regulator_cdata); err_read_rev: kfree(pmic); return rc; }
static int max77828_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77828_dev *max77828; struct max77828_platform_data *pdata = i2c->dev.platform_data; u8 reg_data; int ret = 0; dev_info(&i2c->dev, "%s\n", __func__); max77828 = kzalloc(sizeof(struct max77828_dev), GFP_KERNEL); if (!max77828) { dev_err(&i2c->dev, "%s: Failed to alloc mem for max77828\n", __func__); return -ENOMEM; } if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max77828_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory \n"); ret = -ENOMEM; goto err; } ret = of_max77828_dt(&i2c->dev, pdata); if (ret < 0){ dev_err(&i2c->dev, "Failed to get device of_node \n"); return ret; } /*pdata update to other modules*/ pdata->muic_data = &max77828_muic; #ifdef CONFIG_LEDS_MAX77828 pdata->led_data = &max77828_led_pdata; #endif i2c->dev.platform_data = pdata; } else pdata = i2c->dev.platform_data; max77828->dev = &i2c->dev; max77828->i2c = i2c; max77828->irq = i2c->irq; if (pdata) { max77828->pdata = pdata; max77828->irq_base = pdata->irq_base; max77828->irq_gpio = pdata->irq_gpio; max77828->wakeup = pdata->wakeup; gpio_tlmm_config(GPIO_CFG(max77828->irq_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE); } else { ret = -EINVAL; goto err; } mutex_init(&max77828->iolock); i2c_set_clientdata(i2c, max77828); if (max77828_read_reg(i2c, MAX77828_PMIC_REG_PMICREV, ®_data) < 0) { dev_err(max77828->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else { /* print rev */ max77828->pmic_rev = (reg_data & 0x7); max77828->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s: device found: rev.0x%x, ver.0x%x\n", __func__, max77828->pmic_rev, max77828->pmic_ver); } max77828->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77828->muic, max77828); max77828->led = i2c_new_dummy(i2c->adapter, I2C_ADDR_LED); i2c_set_clientdata(max77828->led, max77828); ret = max77828_irq_init(max77828); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77828->dev, -1, max77828_devs, ARRAY_SIZE(max77828_devs), NULL, 0); if (ret < 0) goto err_mfd; device_init_wakeup(max77828->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max77828->dev); max77828_irq_exit(max77828); err_irq_init: i2c_unregister_device(max77828->muic); i2c_unregister_device(max77828->led); err: kfree(max77828); return ret; }
static int max8997_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max8997_dev *max8997; struct max8997_platform_data *pdata = dev_get_platdata(&i2c->dev); int ret = 0; max8997 = devm_kzalloc(&i2c->dev, sizeof(struct max8997_dev), GFP_KERNEL); if (max8997 == NULL) return -ENOMEM; i2c_set_clientdata(i2c, max8997); max8997->dev = &i2c->dev; max8997->i2c = i2c; max8997->type = max8997_i2c_get_driver_data(i2c, id); max8997->irq = i2c->irq; if (IS_ENABLED(CONFIG_OF) && max8997->dev->of_node) { pdata = max8997_i2c_parse_dt_pdata(max8997->dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); } if (!pdata) return ret; max8997->pdata = pdata; max8997->ono = pdata->ono; mutex_init(&max8997->iolock); max8997->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); i2c_set_clientdata(max8997->rtc, max8997); max8997->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); i2c_set_clientdata(max8997->haptic, max8997); max8997->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max8997->muic, max8997); pm_runtime_set_active(max8997->dev); max8997_irq_init(max8997); ret = mfd_add_devices(max8997->dev, -1, max8997_devs, ARRAY_SIZE(max8997_devs), NULL, 0, NULL); if (ret < 0) { dev_err(max8997->dev, "failed to add MFD devices %d\n", ret); goto err_mfd; } /* * TODO: enable others (flash, muic, rtc, battery, ...) and * check the return value */ /* MAX8997 has a power button input. */ device_init_wakeup(max8997->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max8997->dev); i2c_unregister_device(max8997->muic); i2c_unregister_device(max8997->haptic); i2c_unregister_device(max8997->rtc); return ret; }
void da9063_device_exit(struct da9063 *da9063) { mfd_remove_devices(da9063->dev); da9063_irq_exit(da9063); }
static int max77686_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77686_dev *max77686 = NULL; struct max77686_platform_data *pdata = i2c->dev.platform_data; unsigned int data; int ret = 0; if (i2c->dev.of_node) pdata = max77686_i2c_parse_dt_pdata(&i2c->dev); if (!pdata) { ret = -EIO; dev_err(&i2c->dev, "No platform data found.\n"); goto err; } max77686 = kzalloc(sizeof(struct max77686_dev), GFP_KERNEL); if (max77686 == NULL) return -ENOMEM; i2c_set_clientdata(i2c, max77686); max77686->dev = &i2c->dev; max77686->i2c = i2c; max77686->type = id->driver_data; max77686->wakeup = pdata->wakeup; max77686->irq_gpio = pdata->irq_gpio; max77686->irq = i2c->irq; max77686->regmap = devm_regmap_init_i2c(i2c, &max77686_regmap_config); if (IS_ERR(max77686->regmap)) { ret = PTR_ERR(max77686->regmap); dev_err(max77686->dev, "Failed to allocate register map: %d\n", ret); kfree(max77686); return ret; } if (regmap_read(max77686->regmap, MAX77686_REG_DEVICE_ID, &data) < 0) { dev_err(max77686->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else dev_info(max77686->dev, "device found\n"); max77686->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); i2c_set_clientdata(max77686->rtc, max77686); max77686_irq_init(max77686); ret = mfd_add_devices(max77686->dev, -1, max77686_devs, ARRAY_SIZE(max77686_devs), NULL, 0, NULL); if (ret < 0) goto err_mfd; return ret; err_mfd: mfd_remove_devices(max77686->dev); i2c_unregister_device(max77686->rtc); err: kfree(max77686); return ret; }
static int max77693_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77693_dev *max77693; struct max77693_platform_data *pdata = i2c->dev.platform_data; u8 reg_data; int ret = 0; max77693 = kzalloc(sizeof(struct max77693_dev), GFP_KERNEL); if (max77693 == NULL) return -ENOMEM; i2c_set_clientdata(i2c, max77693); max77693->dev = &i2c->dev; max77693->i2c = i2c; max77693->irq = i2c->irq; max77693->type = id->driver_data; if (pdata) { max77693->irq_base = pdata->irq_base; max77693->irq_gpio = pdata->irq_gpio; max77693->wakeup = pdata->wakeup; } else goto err; mutex_init(&max77693->iolock); if (max77693_read_reg(i2c, MAX77693_PMIC_REG_PMIC_ID2, ®_data) < 0) { dev_err(max77693->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else { /* print rev */ max77693->pmic_rev = (reg_data & 0x7); max77693->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s: device found: rev.0x%x, ver.0x%x\n", __func__, max77693->pmic_rev, max77693->pmic_ver); } #if 0 #if defined(CONFIG_MACH_JF_VZW) || defined(CONFIG_MACH_JF_LGT) if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) { pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET); max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x04); } else { pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET); max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x0c); } #else if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) { max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x04); } else { pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET); max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x0c); } #endif #endif #if defined(CONFIG_MACH_SERRANO_VZW) if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) { #if defined(CONFIG_SEC_DISABLE_HARDRESET) pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET); #endif max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x04); } else { pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET); max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x0c); } #endif max77693_update_reg(i2c, MAX77693_CHG_REG_SAFEOUT_CTRL, 0x00, 0x30); max77693->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77693->muic, max77693); max77693->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); i2c_set_clientdata(max77693->haptic, max77693); ret = max77693_irq_init(max77693); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77693->dev, -1, max77693_devs, ARRAY_SIZE(max77693_devs), NULL, 0); if (ret < 0) goto err_mfd; device_init_wakeup(max77693->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max77693->dev); err_irq_init: i2c_unregister_device(max77693->muic); i2c_unregister_device(max77693->haptic); err: kfree(max77693); return ret; }
int __devinit arizona_dev_init(struct arizona *arizona) { struct device *dev = arizona->dev; const char *type_name; unsigned int reg, val; int (*apply_patch)(struct arizona *) = NULL; int ret, i; dev_set_drvdata(arizona->dev, arizona); mutex_init(&arizona->clk_lock); mutex_init(&arizona->reg_setting_lock); if (dev_get_platdata(arizona->dev)) memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), sizeof(arizona->pdata)); regcache_cache_only(arizona->regmap, true); switch (arizona->type) { case WM5102: case WM5110: for (i = 0; i < ARRAY_SIZE(wm5102_core_supplies); i++) arizona->core_supplies[i].supply = wm5102_core_supplies[i]; arizona->num_core_supplies = ARRAY_SIZE(wm5102_core_supplies); break; default: dev_err(arizona->dev, "Unknown device type %d\n", arizona->type); return -EINVAL; } ret = mfd_add_devices(arizona->dev, -1, early_devs, ARRAY_SIZE(early_devs), NULL, 0); if (ret != 0) { dev_err(dev, "Failed to add early children: %d\n", ret); return ret; } ret = devm_regulator_bulk_get(dev, arizona->num_core_supplies, arizona->core_supplies); if (ret != 0) { dev_err(dev, "Failed to request core supplies: %d\n", ret); goto err_early; } arizona->dcvdd = devm_regulator_get(arizona->dev, "DCVDD"); if (IS_ERR(arizona->dcvdd)) { ret = PTR_ERR(arizona->dcvdd); dev_err(dev, "Failed to request DCVDD: %d\n", ret); goto err_early; } if (arizona->pdata.reset) { /* Start out with /RESET low to put the chip into reset */ ret = gpio_request_one(arizona->pdata.reset, GPIOF_DIR_OUT | GPIOF_INIT_LOW, "arizona /RESET"); if (ret != 0) { dev_err(dev, "Failed to request /RESET: %d\n", ret); goto err_early; } } ret = regulator_bulk_enable(arizona->num_core_supplies, arizona->core_supplies); if (ret != 0) { dev_err(dev, "Failed to enable core supplies: %d\n", ret); goto err_early; } ret = regulator_enable(arizona->dcvdd); if (ret != 0) { dev_err(dev, "Failed to enable DCVDD: %d\n", ret); goto err_enable; } if (arizona->pdata.control_init_time) msleep(arizona->pdata.control_init_time); if (arizona->pdata.reset) { gpio_set_value_cansleep(arizona->pdata.reset, 1); msleep(1); } regcache_cache_only(arizona->regmap, false); ret = regmap_read(arizona->regmap, ARIZONA_SOFTWARE_RESET, ®); if (ret != 0) { dev_err(dev, "Failed to read ID register: %d\n", ret); goto err_reset; } ret = regmap_read(arizona->regmap, ARIZONA_DEVICE_REVISION, &arizona->rev); if (ret != 0) { dev_err(dev, "Failed to read revision register: %d\n", ret); goto err_reset; } arizona->rev &= ARIZONA_DEVICE_REVISION_MASK; switch (reg) { #ifdef CONFIG_MFD_WM5102 case 0x5102: type_name = "WM5102"; if (arizona->type != WM5102) { dev_err(arizona->dev, "WM5102 registered as %d\n", arizona->type); arizona->type = WM5102; } apply_patch = wm5102_patch; arizona->rev &= 0x7; break; #endif #ifdef CONFIG_MFD_WM5110 case 0x5110: type_name = "WM5110"; if (arizona->type != WM5110) { dev_err(arizona->dev, "WM5110 registered as %d\n", arizona->type); arizona->type = WM5110; } apply_patch = wm5110_patch; break; #endif default: dev_err(arizona->dev, "Unknown device ID %x\n", reg); goto err_reset; } dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A'); /* If we have a /RESET GPIO we'll already be reset */ if (!arizona->pdata.reset) { ret = regmap_write(arizona->regmap, ARIZONA_SOFTWARE_RESET, 0); if (ret != 0) { dev_err(dev, "Failed to reset device: %d\n", ret); goto err_reset; } msleep(1); } switch (arizona->type) { case WM5102: ret = regmap_read(arizona->regmap, 0x19, &val); if (ret != 0) dev_err(dev, "Failed to check write sequencer state: %d\n", ret); else if (val & 0x01) break; /* Fall through */ default: ret = arizona_wait_for_boot(arizona); if (ret != 0) { dev_err(arizona->dev, "Device failed initial boot: %d\n", ret); goto err_reset; } break; } if (apply_patch) { ret = apply_patch(arizona); if (ret != 0) { dev_err(arizona->dev, "Failed to apply patch: %d\n", ret); goto err_reset; } switch (arizona->type) { case WM5102: ret = arizona_apply_hardware_patch(arizona); if (ret != 0) { dev_err(arizona->dev, "Failed to apply hardware patch: %d\n", ret); goto err_reset; } break; default: break; } } for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { if (!arizona->pdata.gpio_defaults[i]) continue; regmap_write(arizona->regmap, ARIZONA_GPIO1_CTRL + i, arizona->pdata.gpio_defaults[i]); } pm_runtime_enable(arizona->dev); /* Chip default */ if (!arizona->pdata.clk32k_src) arizona->pdata.clk32k_src = ARIZONA_32KZ_MCLK2; switch (arizona->pdata.clk32k_src) { case ARIZONA_32KZ_MCLK1: case ARIZONA_32KZ_MCLK2: regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, ARIZONA_CLK_32K_SRC_MASK, arizona->pdata.clk32k_src - 1); arizona_clk32k_enable(arizona); break; case ARIZONA_32KZ_NONE: regmap_update_bits(arizona->regmap, ARIZONA_CLOCK_32K_1, ARIZONA_CLK_32K_SRC_MASK, 2); break; default: dev_err(arizona->dev, "Invalid 32kHz clock source: %d\n", arizona->pdata.clk32k_src); ret = -EINVAL; goto err_reset; } for (i = 0; i < ARIZONA_MAX_MICBIAS; i++) { if (!arizona->pdata.micbias[i].mV && !arizona->pdata.micbias[i].bypass) continue; /* Apply default for bypass mode */ if (!arizona->pdata.micbias[i].mV) arizona->pdata.micbias[i].mV = 2800; val = (arizona->pdata.micbias[i].mV - 1500) / 100; val <<= ARIZONA_MICB1_LVL_SHIFT; if (arizona->pdata.micbias[i].ext_cap) val |= ARIZONA_MICB1_EXT_CAP; if (arizona->pdata.micbias[i].discharge) val |= ARIZONA_MICB1_DISCH; if (arizona->pdata.micbias[i].fast_start) val |= ARIZONA_MICB1_RATE; if (arizona->pdata.micbias[i].bypass) val |= ARIZONA_MICB1_BYPASS; regmap_update_bits(arizona->regmap, ARIZONA_MIC_BIAS_CTRL_1 + i, ARIZONA_MICB1_LVL_MASK | ARIZONA_MICB1_DISCH | ARIZONA_MICB1_BYPASS | ARIZONA_MICB1_RATE, val); } for (i = 0; i < ARIZONA_MAX_INPUT; i++) { /* Default for both is 0 so noop with defaults */ val = arizona->pdata.dmic_ref[i] << ARIZONA_IN1_DMIC_SUP_SHIFT; val |= arizona->pdata.inmode[i] << ARIZONA_IN1_MODE_SHIFT; regmap_update_bits(arizona->regmap, ARIZONA_IN1L_CONTROL + (i * 8), ARIZONA_IN1_DMIC_SUP_MASK | ARIZONA_IN1_MODE_MASK, val); } for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) { /* Default is 0 so noop with defaults */ if (arizona->pdata.out_mono[i]) val = ARIZONA_OUT1_MONO; else val = 0; regmap_update_bits(arizona->regmap, ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8), ARIZONA_OUT1_MONO, val); } for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) { if (arizona->pdata.spk_mute[i]) regmap_update_bits(arizona->regmap, ARIZONA_PDM_SPK1_CTRL_1 + (i * 2), ARIZONA_SPK1_MUTE_ENDIAN_MASK | ARIZONA_SPK1_MUTE_SEQ1_MASK, arizona->pdata.spk_mute[i]); if (arizona->pdata.spk_fmt[i]) regmap_update_bits(arizona->regmap, ARIZONA_PDM_SPK1_CTRL_2 + (i * 2), ARIZONA_SPK1_FMT_MASK, arizona->pdata.spk_fmt[i]); } /* set virtual IRQs */ arizona->virq[0] = arizona->pdata.irq_base; arizona->virq[1] = arizona->pdata.irq_base + ARIZONA_NUM_IRQ; switch (arizona->pdata.mic_spk_clamp) { case ARIZONA_MIC_CLAMP_SPKLN: regmap_update_bits(arizona->regmap, ARIZONA_SPK_CTRL_2, 0x3c, 0xc); break; case ARIZONA_MIC_CLAMP_SPKLP: regmap_update_bits(arizona->regmap, ARIZONA_SPK_CTRL_2, 0x3c, 0x1c); break; case ARIZONA_MIC_CLAMP_SPKRN: regmap_update_bits(arizona->regmap, ARIZONA_SPK_CTRL_3, 0x3c, 0xc); break; case ARIZONA_MIC_CLAMP_SPKRP: regmap_update_bits(arizona->regmap, ARIZONA_SPK_CTRL_3, 0x3c, 0x1c); break; default: break; } /* Set up for interrupts */ ret = arizona_irq_init(arizona); if (ret != 0) goto err_reset; arizona_request_irq(arizona, ARIZONA_IRQ_CLKGEN_ERR, "CLKGEN error", arizona_clkgen_err, arizona); arizona_request_irq(arizona, ARIZONA_IRQ_OVERCLOCKED, "Overclocked", arizona_overclocked, arizona); arizona_request_irq(arizona, ARIZONA_IRQ_UNDERCLOCKED, "Underclocked", arizona_underclocked, arizona); switch (arizona->type) { case WM5102: ret = mfd_add_devices(arizona->dev, -1, wm5102_devs, ARRAY_SIZE(wm5102_devs), NULL, 0); break; case WM5110: ret = mfd_add_devices(arizona->dev, -1, wm5110_devs, ARRAY_SIZE(wm5110_devs), NULL, 0); break; } if (ret != 0) { dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret); goto err_irq; } if (arizona->pdata.init_done) arizona->pdata.init_done(); #ifdef CONFIG_PM_RUNTIME regulator_disable(arizona->dcvdd); #endif return 0; err_irq: arizona_irq_exit(arizona); err_reset: if (arizona->pdata.reset) { gpio_set_value_cansleep(arizona->pdata.reset, 0); gpio_free(arizona->pdata.reset); } regulator_disable(arizona->dcvdd); err_enable: regulator_bulk_disable(arizona->num_core_supplies, arizona->core_supplies); err_early: mfd_remove_devices(dev); return ret; }
static void __devexit vx855_remove(struct pci_dev *pdev) { mfd_remove_devices(&pdev->dev); pci_disable_device(pdev); }
static int __devinit rt5033_mfd_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { int ret = 0; u8 data = 0; rt5033_mfd_chip_t *chip; rt5033_mfd_platform_data_t *pdata = i2c->dev.platform_data; pr_info("%s : RT5033 MFD Driver start probe\n", __func__); chip = kzalloc(sizeof(*chip), GFP_KERNEL); if (chip == NULL) { dev_err(chip->dev, "Memory is not enough.\n"); ret = -ENOMEM; goto err_mfd_nomem; } ret = i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_I2C_BLOCK); if (!ret) { ret = i2c_get_functionality(i2c->adapter); dev_err(chip->dev, "I2C functionality is not supported.\n"); ret = -ENOSYS; goto err_i2cfunc_not_support; } chip->dev = &i2c->dev; chip->i2c_client = i2c; chip->pdata = pdata; pdata->irq_base = irq_alloc_descs(-1, 0, RT5033_IRQS_NR, -1); if (pdata->irq_base < 0) { pr_err("%s:%s irq_alloc_descs Fail! ret(%d)\n", "rt5033-mfd", __func__, pdata->irq_base); ret = -EINVAL; goto irq_base_err; } else { chip->irq_base = pdata->irq_base; } i2c_set_clientdata(i2c, chip); mutex_init(&chip->io_lock); wake_lock_init(&(chip->irq_wake_lock), WAKE_LOCK_SUSPEND, "rt5033mfd_wakelock"); ret = rt5033_clr_bits(i2c, 0x47, 1<<3); pr_info("Diable MANUAL RESET (%d)\n", ret); ret = rt5033_init_irq(chip); if (ret < 0) { dev_err(chip->dev, "Error : can't initialize RT5033 MFD irq\n"); goto err_init_irq; } #ifdef CONFIG_REGULATOR_RT5033 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(3,6,0)) ret = mfd_add_devices(chip->dev, 0, &rt5033_regulator_devs[0], ARRAY_SIZE(rt5033_regulator_devs), NULL, chip->irq_base, NULL); #else ret = mfd_add_devices(chip->dev, 0, &rt5033_regulator_devs[0], ARRAY_SIZE(rt5033_regulator_devs), NULL, chip->irq_base); #endif if (ret < 0) { dev_err(chip->dev, "Error : can't add regulator\n"); goto err_add_regulator_devs; } #endif /*CONFIG_REGULATOR_RT5033*/ #ifdef CONFIG_FLED_RT5033 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(3,6,0)) ret = mfd_add_devices(chip->dev, 0, &rt5033_fled_devs[0], ARRAY_SIZE(rt5033_fled_devs), NULL, chip->irq_base, NULL); #else ret = mfd_add_devices(chip->dev, 0, &rt5033_fled_devs[0], ARRAY_SIZE(rt5033_fled_devs), NULL, chip->irq_base); #endif if (ret < 0) { dev_err(chip->dev,"Failed : add FlashLED devices"); goto err_add_fled_devs; } #endif /*CONFIG_FLED_RT5033*/ #ifdef CONFIG_CHARGER_RT5033 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(3,6,0)) ret = mfd_add_devices(chip->dev, 0, &rt5033_charger_devs[0], ARRAY_SIZE(rt5033_charger_devs), NULL, chip->irq_base, NULL); #else ret = mfd_add_devices(chip->dev, 0, &rt5033_charger_devs[0], ARRAY_SIZE(rt5033_charger_devs), NULL, chip->irq_base); #endif if (ret<0) { dev_err(chip->dev, "Failed : add charger devices\n"); goto err_add_chg_devs; } #endif /*CONFIG_CHARGER_RT5033*/ pr_info("%s : RT5033 MFD Driver Fin probe\n", __func__); return ret; #ifdef CONFIG_CHARGER_RT5033 err_add_chg_devs: #endif /*CONFIG_CHARGER_RT5033*/ #ifdef CONFIG_FLED_RT5033 err_add_fled_devs: #endif /*CONFIG_FLED_RT5033*/ mfd_remove_devices(chip->dev); #ifdef CONFIG_REGULATOR_RT5033 err_add_regulator_devs: #endif /*CONFIG_REGULATOR_RT5033*/ err_init_irq: wake_lock_destroy(&(chip->irq_wake_lock)); mutex_destroy(&chip->io_lock); kfree(chip); irq_base_err: err_mfd_nomem: err_i2cfunc_not_support: return ret; }
void tps65912_device_exit(struct tps65912 *tps65912) { mfd_remove_devices(tps65912->dev); kfree(tps65912); }
/* * Instantiate the generic non-control parts of the device. */ 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); /* 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 = 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: /* Revision C did not change the relevant layer */ 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; /* 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_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; }
int cros_ec_remove(struct cros_ec_device *ec_dev) { mfd_remove_devices(ec_dev->dev); return 0; }
static int mc13783_probe(struct spi_device *spi) { struct mc13783 *mc13783; struct mc13783_platform_data *pdata = dev_get_platdata(&spi->dev); int ret; mc13783 = kzalloc(sizeof(*mc13783), GFP_KERNEL); if (!mc13783) return -ENOMEM; dev_set_drvdata(&spi->dev, mc13783); spi->mode = SPI_MODE_0 | SPI_CS_HIGH; spi->bits_per_word = 32; spi_setup(spi); mc13783->spidev = spi; mutex_init(&mc13783->lock); mc13783_lock(mc13783); ret = mc13783_check_revision(mc13783); if (ret) goto err_revision; /* mask all irqs */ ret = mc13783_reg_write(mc13783, MC13783_IRQMASK0, 0x00ffffff); if (ret) goto err_mask; ret = mc13783_reg_write(mc13783, MC13783_IRQMASK1, 0x00ffffff); if (ret) goto err_mask; ret = request_threaded_irq(spi->irq, NULL, mc13783_irq_thread, IRQF_ONESHOT | IRQF_TRIGGER_HIGH, "mc13783", mc13783); if (ret) { err_mask: err_revision: mutex_unlock(&mc13783->lock); dev_set_drvdata(&spi->dev, NULL); kfree(mc13783); return ret; } /* This should go away (BEGIN) */ if (pdata) { mc13783->flags = pdata->flags; mc13783->regulators = pdata->regulators; mc13783->num_regulators = pdata->num_regulators; } /* This should go away (END) */ mc13783_unlock(mc13783); if (pdata->flags & MC13783_USE_ADC) mc13783_add_subdevice(mc13783, "mc13783-adc"); if (pdata->flags & MC13783_USE_CODEC) mc13783_add_subdevice(mc13783, "mc13783-codec"); if (pdata->flags & MC13783_USE_REGULATOR) { struct mc13783_regulator_platform_data regulator_pdata = { .num_regulators = pdata->num_regulators, .regulators = pdata->regulators, }; mc13783_add_subdevice_pdata(mc13783, "mc13783-regulator", ®ulator_pdata, sizeof(regulator_pdata)); } if (pdata->flags & MC13783_USE_RTC) mc13783_add_subdevice(mc13783, "mc13783-rtc"); if (pdata->flags & MC13783_USE_TOUCHSCREEN) mc13783_add_subdevice(mc13783, "mc13783-ts"); if (pdata->flags & MC13783_USE_LED) mc13783_add_subdevice_pdata(mc13783, "mc13783-led", pdata->leds, sizeof(*pdata->leds)); return 0; } static int __devexit mc13783_remove(struct spi_device *spi) { struct mc13783 *mc13783 = dev_get_drvdata(&spi->dev); free_irq(mc13783->spidev->irq, mc13783); mfd_remove_devices(&spi->dev); return 0; } static struct spi_driver mc13783_driver = { .driver = { .name = "mc13783", .bus = &spi_bus_type, .owner = THIS_MODULE, }, .probe = mc13783_probe, .remove = __devexit_p(mc13783_remove), };
int cros_ec_register(struct cros_ec_device *ec_dev) { struct device *dev = ec_dev->dev; int err = 0; BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->event_notifier); ec_dev->max_request = sizeof(struct ec_params_hello); ec_dev->max_response = sizeof(struct ec_response_get_protocol_info); ec_dev->max_passthru = 0; ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL); if (!ec_dev->din) return -ENOMEM; ec_dev->dout = devm_kzalloc(dev, ec_dev->dout_size, GFP_KERNEL); if (!ec_dev->dout) return -ENOMEM; mutex_init(&ec_dev->lock); cros_ec_query_all(ec_dev); if (ec_dev->irq) { err = request_threaded_irq(ec_dev->irq, NULL, ec_irq_thread, IRQF_TRIGGER_LOW | IRQF_ONESHOT, "chromeos-ec", ec_dev); if (err) { dev_err(dev, "Failed to request IRQ %d: %d", ec_dev->irq, err); return err; } } err = mfd_add_devices(ec_dev->dev, PLATFORM_DEVID_AUTO, &ec_cell, 1, NULL, ec_dev->irq, NULL); if (err) { dev_err(dev, "Failed to register Embedded Controller subdevice %d\n", err); goto fail_mfd; } if (ec_dev->max_passthru) { /* * Register a PD device as well on top of this device. * We make the following assumptions: * - behind an EC, we have a pd * - only one device added. * - the EC is responsive at init time (it is not true for a * sensor hub. */ err = mfd_add_devices(ec_dev->dev, PLATFORM_DEVID_AUTO, &ec_pd_cell, 1, NULL, ec_dev->irq, NULL); if (err) { dev_err(dev, "Failed to register Power Delivery subdevice %d\n", err); goto fail_mfd; } } if (IS_ENABLED(CONFIG_OF) && dev->of_node) { err = of_platform_populate(dev->of_node, NULL, NULL, dev); if (err) { mfd_remove_devices(dev); dev_err(dev, "Failed to register sub-devices\n"); goto fail_mfd; } } /* * Clear sleep event - this will fail harmlessly on platforms that * don't implement the sleep event host command. */ err = cros_ec_sleep_event(ec_dev, 0); if (err < 0) dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec", err); dev_info(dev, "Chrome EC device registered\n"); return 0; fail_mfd: if (ec_dev->irq) free_irq(ec_dev->irq, ec_dev); return err; }
void da9055_device_exit(struct da9055 *da9055) { regmap_del_irq_chip(da9055->chip_irq, da9055->irq_data); mfd_remove_devices(da9055->dev); }
static int max77804_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *dev_id) { struct max77804_dev *max77804; struct max77804_platform_data *pdata = i2c->dev.platform_data; u8 reg_data; int ret = 0; pr_info("%s:%s\n", MFD_DEV_NAME, __func__); max77804 = kzalloc(sizeof(struct max77804_dev), GFP_KERNEL); if (!max77804) { dev_err(&i2c->dev, "%s: Failed to alloc mem for max77804\n", __func__); return -ENOMEM; } if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max77804_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory \n"); ret = -ENOMEM; goto err; } ret = of_max77804_dt(&i2c->dev, pdata); if (ret < 0){ dev_err(&i2c->dev, "Failed to get device of_node \n"); return ret; } i2c->dev.platform_data = pdata; } else pdata = i2c->dev.platform_data; max77804->dev = &i2c->dev; max77804->i2c = i2c; max77804->irq = i2c->irq; if (pdata) { max77804->pdata = pdata; pdata->irq_base = irq_alloc_descs(-1, 0, MAX77804_IRQ_NR, -1); if (pdata->irq_base < 0) { pr_err("%s:%s irq_alloc_descs Fail! ret(%d)\n", MFD_DEV_NAME, __func__, pdata->irq_base); ret = -EINVAL; goto err; } else max77804->irq_base = pdata->irq_base; max77804->irq_gpio = pdata->irq_gpio; max77804->wakeup = pdata->wakeup; } else { ret = -EINVAL; goto err; } mutex_init(&max77804->i2c_lock); i2c_set_clientdata(i2c, max77804); if (max77804_read_reg(i2c, MAX77804_PMIC_REG_PMIC_ID2, ®_data) < 0) { dev_err(max77804->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else { /* print rev */ max77804->pmic_rev = (reg_data & 0x7); max77804->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s:%s device found: rev.0x%x, ver.0x%x\n", MFD_DEV_NAME, __func__, max77804->pmic_rev, max77804->pmic_ver); } /* No active discharge on safeout ldo 1,2 */ max77804_update_reg(i2c, MAX77804_CHG_REG_SAFEOUT_CTRL, 0x00, 0x30); max77804->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77804->muic, max77804); max77804->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); i2c_set_clientdata(max77804->haptic, max77804); #if defined(CONFIG_MFD_MAX77804) ret = max77804_irq_init(max77804); #elif defined(CONFIG_MFD_MAX77804K) ret = max77804k_irq_init(max77804); #endif if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77804->dev, -1, max77804_devs, ARRAY_SIZE(max77804_devs), NULL, 0, NULL); if (ret < 0) goto err_mfd; device_init_wakeup(max77804->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max77804->dev); err_irq_init: i2c_unregister_device(max77804->muic); i2c_unregister_device(max77804->haptic); err: kfree(max77804); return ret; }
/* * Instantiate the generic non-control parts of the device. */ int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) { struct wm831x_pdata *pdata = wm831x->dev->platform_data; int rev, wm831x_num; enum wm831x_parent parent; int ret, i; mutex_init(&wm831x->io_lock); mutex_init(&wm831x->key_lock); dev_set_drvdata(wm831x->dev, wm831x); ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID); if (ret < 0) { dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret); goto err; } switch (ret) { case 0x6204: case 0x6246: break; default: dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret); ret = -EINVAL; goto err; } ret = wm831x_reg_read(wm831x, WM831X_REVISION); if (ret < 0) { dev_err(wm831x->dev, "Failed to read revision: %d\n", ret); goto err; } rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT; ret = wm831x_reg_read(wm831x, WM831X_RESET_ID); if (ret < 0) { dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret); goto err; } /* Some engineering samples do not have the ID set, rely on * the device being registered correctly. */ if (ret == 0) { dev_info(wm831x->dev, "Device is an engineering sample\n"); ret = id; } switch (ret) { case WM8310: parent = WM8310; wm831x->num_gpio = 16; wm831x->charger_irq_wake = 1; if (rev > 0) { wm831x->has_gpio_ena = 1; wm831x->has_cs_sts = 1; } dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev); break; case WM8311: parent = WM8311; wm831x->num_gpio = 16; wm831x->charger_irq_wake = 1; if (rev > 0) { wm831x->has_gpio_ena = 1; wm831x->has_cs_sts = 1; } dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev); break; case WM8312: parent = WM8312; wm831x->num_gpio = 16; wm831x->charger_irq_wake = 1; if (rev > 0) { wm831x->has_gpio_ena = 1; wm831x->has_cs_sts = 1; } dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev); break; case WM8320: parent = WM8320; wm831x->num_gpio = 12; dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev); break; case WM8321: parent = WM8321; wm831x->num_gpio = 12; dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev); break; case WM8325: parent = WM8325; wm831x->num_gpio = 12; dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev); break; case WM8326: parent = WM8326; wm831x->num_gpio = 12; dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev); break; default: dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); ret = -EINVAL; goto err; } /* This will need revisiting in future but is OK for all * current parts. */ if (parent != id) dev_warn(wm831x->dev, "Device was registered as a WM%lx\n", id); /* Bootstrap the user key */ ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY); if (ret < 0) { dev_err(wm831x->dev, "Failed to read security key: %d\n", ret); goto err; } if (ret != 0) { dev_warn(wm831x->dev, "Security key had non-zero value %x\n", ret); wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0); } wm831x->locked = 1; if (pdata && pdata->pre_init) { ret = pdata->pre_init(wm831x); if (ret != 0) { dev_err(wm831x->dev, "pre_init() failed: %d\n", ret); goto err; } } if (pdata) { for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { if (!pdata->gpio_defaults[i]) continue; wm831x_reg_write(wm831x, WM831X_GPIO1_CONTROL + i, pdata->gpio_defaults[i] & 0xffff); } } /* Multiply by 10 as we have many subdevices of the same type */ if (pdata && pdata->wm831x_num) wm831x_num = pdata->wm831x_num * 10; else wm831x_num = -1; ret = wm831x_irq_init(wm831x, irq); if (ret != 0) goto err; wm831x_auxadc_init(wm831x); /* The core device is up, instantiate the subdevices. */ switch (parent) { case WM8310: ret = mfd_add_devices(wm831x->dev, wm831x_num, wm8310_devs, ARRAY_SIZE(wm8310_devs), NULL, wm831x->irq_base); break; case WM8311: ret = mfd_add_devices(wm831x->dev, wm831x_num, wm8311_devs, ARRAY_SIZE(wm8311_devs), NULL, wm831x->irq_base); if (!pdata || !pdata->disable_touch) mfd_add_devices(wm831x->dev, wm831x_num, touch_devs, ARRAY_SIZE(touch_devs), NULL, wm831x->irq_base); break; case WM8312: ret = mfd_add_devices(wm831x->dev, wm831x_num, wm8312_devs, ARRAY_SIZE(wm8312_devs), NULL, wm831x->irq_base); if (!pdata || !pdata->disable_touch) mfd_add_devices(wm831x->dev, wm831x_num, touch_devs, ARRAY_SIZE(touch_devs), NULL, wm831x->irq_base); break; case WM8320: case WM8321: case WM8325: case WM8326: ret = mfd_add_devices(wm831x->dev, wm831x_num, wm8320_devs, ARRAY_SIZE(wm8320_devs), NULL, wm831x->irq_base); break; default: /* If this happens the bus probe function is buggy */ BUG(); } if (ret != 0) { dev_err(wm831x->dev, "Failed to add children\n"); goto err_irq; } /* The RTC can only be used if the 32.768kHz crystal is * enabled; this can't be controlled by software at runtime. */ ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2); if (ret < 0) { dev_err(wm831x->dev, "Failed to read clock status: %d\n", ret); goto err_irq; } if (ret & WM831X_XTAL_ENA) { ret = mfd_add_devices(wm831x->dev, wm831x_num, rtc_devs, ARRAY_SIZE(rtc_devs), NULL, wm831x->irq_base); if (ret != 0) { dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret); goto err_irq; } } else { dev_info(wm831x->dev, "32.768kHz clock disabled, no RTC\n"); } if (pdata && pdata->backlight) { /* Treat errors as non-critical */ ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs, ARRAY_SIZE(backlight_devs), NULL, wm831x->irq_base); if (ret < 0) dev_err(wm831x->dev, "Failed to add backlight: %d\n", ret); } wm831x_otp_init(wm831x); if (pdata && pdata->post_init) { ret = pdata->post_init(wm831x); if (ret != 0) { dev_err(wm831x->dev, "post_init() failed: %d\n", ret); goto err_irq; } } return 0; err_irq: wm831x_irq_exit(wm831x); err: mfd_remove_devices(wm831x->dev); kfree(wm831x); return ret; }
static int rt5033_i2c_remove(struct i2c_client *i2c) { mfd_remove_devices(&i2c->dev); return 0; }