int arizona_dev_init(struct arizona *arizona) { struct device *dev = arizona->dev; const char *type_name = "Unknown"; unsigned int reg, val; int (*apply_patch)(struct arizona *) = NULL; int ret, i; char revision_char; dev_set_drvdata(arizona->dev, arizona); mutex_init(&arizona->clk_lock); init_completion(&arizona->gpio_allocated); if (dev_get_platdata(arizona->dev)) memcpy(&arizona->pdata, dev_get_platdata(arizona->dev), sizeof(arizona->pdata)); else arizona_of_get_core_pdata(arizona); regcache_cache_only(arizona->regmap, true); switch (arizona->type) { case WM5102: case WM5110: case WM8280: case WM8997: 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; } /* Mark DCVDD as external, LDO1 driver will clear if internal */ arizona->external_dcvdd = true; ret = mfd_add_devices(arizona->dev, -1, early_devs, ARRAY_SIZE(early_devs), NULL, 0, NULL); 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; } switch (arizona->type) { case WM5110: case WM8280: msleep(5); break; default: break; } if (arizona->pdata.reset) { gpio_set_value_cansleep(arizona->pdata.reset, 1); msleep(1); } regcache_cache_only(arizona->regmap, false); /* Verify that this is a chip we know about */ 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; } switch (reg) { case 0x5102: case 0x5110: case 0x8997: break; default: dev_err(arizona->dev, "Unknown device ID: %x\n", reg); goto err_reset; } /* If we have a /RESET GPIO we'll already be reset */ if (!arizona->pdata.reset) { regcache_mark_dirty(arizona->regmap); ret = arizona_soft_reset(arizona); if (ret != 0) goto err_reset; ret = regcache_sync(arizona->regmap); if (ret != 0) { dev_err(dev, "Failed to sync device: %d\n", ret); goto err_reset; } } /* Ensure device startup is complete */ 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; } /* Read the device ID information & do device specific stuff */ 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; revision_char = arizona->rev + 'A'; break; #endif #ifdef CONFIG_MFD_FLORIDA case 0x5110: switch (arizona->type) { case WM8280: if (arizona->rev >= 0x5) { type_name = "WM8281"; revision_char = arizona->rev + 60; } else { type_name = "WM8280"; revision_char = arizona->rev + 61; } break; case WM5110: type_name = "WM5110"; revision_char = arizona->rev + 'A'; break; default: dev_err(arizona->dev, "Florida codec registered as %d\n", arizona->type); arizona->type = WM8280; type_name = "Florida"; revision_char = arizona->rev + 61; break; } apply_patch = florida_patch; break; #endif #ifdef CONFIG_MFD_WM8997 case 0x8997: type_name = "WM8997"; revision_char = arizona->rev + 'A'; if (arizona->type != WM8997) { dev_err(arizona->dev, "WM8997 registered as %d\n", arizona->type); arizona->type = WM8997; } apply_patch = wm8997_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, revision_char); 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; case WM5110: case WM8280: ret = arizona_apply_sleep_patch(arizona); if (ret != 0) { dev_err(arizona->dev, "Failed to apply sleep 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_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); 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].soft_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 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, NULL); break; case WM8280: case WM5110: ret = mfd_add_devices(arizona->dev, -1, florida_devs, ARRAY_SIZE(florida_devs), NULL, 0, NULL); break; case WM8997: ret = mfd_add_devices(arizona->dev, -1, wm8997_devs, ARRAY_SIZE(wm8997_devs), NULL, 0, NULL); break; } if (ret != 0) { dev_err(arizona->dev, "Failed to add subdevices: %d\n", ret); goto err_irq; } #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 int cs53l30_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { const struct device_node *np = client->dev.of_node; struct device *dev = &client->dev; struct cs53l30_private *cs53l30; unsigned int devid = 0; unsigned int reg; int ret = 0, i; u8 val; cs53l30 = devm_kzalloc(dev, sizeof(*cs53l30), GFP_KERNEL); if (!cs53l30) return -ENOMEM; for (i = 0; i < ARRAY_SIZE(cs53l30->supplies); i++) cs53l30->supplies[i].supply = cs53l30_supply_names[i]; ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(cs53l30->supplies), cs53l30->supplies); if (ret) { dev_err(dev, "failed to get supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(cs53l30->supplies), cs53l30->supplies); if (ret) { dev_err(dev, "failed to enable supplies: %d\n", ret); return ret; } /* Reset the Device */ cs53l30->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(cs53l30->reset_gpio)) { ret = PTR_ERR(cs53l30->reset_gpio); goto error; } gpiod_set_value_cansleep(cs53l30->reset_gpio, 1); i2c_set_clientdata(client, cs53l30); cs53l30->mclk_rate = 0; cs53l30->regmap = devm_regmap_init_i2c(client, &cs53l30_regmap); if (IS_ERR(cs53l30->regmap)) { ret = PTR_ERR(cs53l30->regmap); dev_err(dev, "regmap_init() failed: %d\n", ret); goto error; } /* Initialize codec */ ret = regmap_read(cs53l30->regmap, CS53L30_DEVID_AB, ®); devid = reg << 12; ret = regmap_read(cs53l30->regmap, CS53L30_DEVID_CD, ®); devid |= reg << 4; ret = regmap_read(cs53l30->regmap, CS53L30_DEVID_E, ®); devid |= (reg & 0xF0) >> 4; if (devid != CS53L30_DEVID) { ret = -ENODEV; dev_err(dev, "Device ID (%X). Expected %X\n", devid, CS53L30_DEVID); goto error; } ret = regmap_read(cs53l30->regmap, CS53L30_REVID, ®); if (ret < 0) { dev_err(dev, "failed to get Revision ID: %d\n", ret); goto error; } /* Check if MCLK provided */ cs53l30->mclk = devm_clk_get(dev, "mclk"); if (IS_ERR(cs53l30->mclk)) { if (PTR_ERR(cs53l30->mclk) != -ENOENT) { ret = PTR_ERR(cs53l30->mclk); goto error; } /* Otherwise mark the mclk pointer to NULL */ cs53l30->mclk = NULL; } /* Fetch the MUTE control */ cs53l30->mute_gpio = devm_gpiod_get_optional(dev, "mute", GPIOD_OUT_HIGH); if (IS_ERR(cs53l30->mute_gpio)) { ret = PTR_ERR(cs53l30->mute_gpio); goto error; } if (cs53l30->mute_gpio) { /* Enable MUTE controls via MUTE pin */ regmap_write(cs53l30->regmap, CS53L30_MUTEP_CTL1, CS53L30_MUTEP_CTL1_MUTEALL); /* Flip the polarity of MUTE pin */ if (gpiod_is_active_low(cs53l30->mute_gpio)) regmap_update_bits(cs53l30->regmap, CS53L30_MUTEP_CTL2, CS53L30_MUTE_PIN_POLARITY, 0); } if (!of_property_read_u8(np, "cirrus,micbias-lvl", &val)) regmap_update_bits(cs53l30->regmap, CS53L30_MICBIAS_CTL, CS53L30_MIC_BIAS_CTRL_MASK, val); if (of_property_read_bool(np, "cirrus,use-sdout2")) cs53l30->use_sdout2 = true; dev_info(dev, "Cirrus Logic CS53L30, Revision: %02X\n", reg & 0xFF); ret = snd_soc_register_codec(dev, &cs53l30_driver, &cs53l30_dai, 1); if (ret) { dev_err(dev, "failed to register codec: %d\n", ret); goto error; } return 0; error: regulator_bulk_disable(ARRAY_SIZE(cs53l30->supplies), cs53l30->supplies); return ret; }
static int cs35l32_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { struct cs35l32_private *cs35l32; struct cs35l32_platform_data *pdata = dev_get_platdata(&i2c_client->dev); int ret, i; unsigned int devid = 0; unsigned int reg; cs35l32 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l32_private), GFP_KERNEL); if (!cs35l32) { dev_err(&i2c_client->dev, "could not allocate codec\n"); return -ENOMEM; } i2c_set_clientdata(i2c_client, cs35l32); cs35l32->regmap = devm_regmap_init_i2c(i2c_client, &cs35l32_regmap); if (IS_ERR(cs35l32->regmap)) { ret = PTR_ERR(cs35l32->regmap); dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); return ret; } if (pdata) { cs35l32->pdata = *pdata; } else { pdata = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l32_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c_client->dev, "could not allocate pdata\n"); return -ENOMEM; } if (i2c_client->dev.of_node) { ret = cs35l32_handle_of_data(i2c_client, &cs35l32->pdata); if (ret != 0) return ret; } } for (i = 0; i < ARRAY_SIZE(cs35l32->supplies); i++) cs35l32->supplies[i].supply = cs35l32_supply_names[i]; ret = devm_regulator_bulk_get(&i2c_client->dev, ARRAY_SIZE(cs35l32->supplies), cs35l32->supplies); if (ret != 0) { dev_err(&i2c_client->dev, "Failed to request supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(cs35l32->supplies), cs35l32->supplies); if (ret != 0) { dev_err(&i2c_client->dev, "Failed to enable supplies: %d\n", ret); return ret; } /* Reset the Device */ cs35l32->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(cs35l32->reset_gpio)) return PTR_ERR(cs35l32->reset_gpio); if (cs35l32->reset_gpio) gpiod_set_value_cansleep(cs35l32->reset_gpio, 1); /* initialize codec */ ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_AB, ®); devid = (reg & 0xFF) << 12; ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_CD, ®); devid |= (reg & 0xFF) << 4; ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_E, ®); devid |= (reg & 0xF0) >> 4; if (devid != CS35L32_CHIP_ID) { ret = -ENODEV; dev_err(&i2c_client->dev, "CS35L32 Device ID (%X). Expected %X\n", devid, CS35L32_CHIP_ID); return ret; } ret = regmap_read(cs35l32->regmap, CS35L32_REV_ID, ®); if (ret < 0) { dev_err(&i2c_client->dev, "Get Revision ID failed\n"); return ret; } ret = regmap_register_patch(cs35l32->regmap, cs35l32_monitor_patch, ARRAY_SIZE(cs35l32_monitor_patch)); if (ret < 0) { dev_err(&i2c_client->dev, "Failed to apply errata patch\n"); return ret; } dev_info(&i2c_client->dev, "Cirrus Logic CS35L32, Revision: %02X\n", reg & 0xFF); /* Setup VBOOST Management */ if (cs35l32->pdata.boost_mng) regmap_update_bits(cs35l32->regmap, CS35L32_AUDIO_LED_MNGR, CS35L32_BOOST_MASK, cs35l32->pdata.boost_mng); /* Setup ADSP Format Config */ if (cs35l32->pdata.sdout_share) regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL, CS35L32_ADSP_SHARE_MASK, cs35l32->pdata.sdout_share << 3); /* Setup ADSP Data Configuration */ if (cs35l32->pdata.sdout_datacfg) regmap_update_bits(cs35l32->regmap, CS35L32_ADSP_CTL, CS35L32_ADSP_DATACFG_MASK, cs35l32->pdata.sdout_datacfg << 4); /* Setup Low Battery Recovery */ if (cs35l32->pdata.batt_recov) regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD, CS35L32_BATT_REC_MASK, cs35l32->pdata.batt_recov << 1); /* Setup Low Battery Threshold */ if (cs35l32->pdata.batt_thresh) regmap_update_bits(cs35l32->regmap, CS35L32_BATT_THRESHOLD, CS35L32_BATT_THRESH_MASK, cs35l32->pdata.batt_thresh << 4); /* Power down the AMP */ regmap_update_bits(cs35l32->regmap, CS35L32_PWRCTL1, CS35L32_PDN_AMP, CS35L32_PDN_AMP); /* Clear MCLK Error Bit since we don't have the clock yet */ ret = regmap_read(cs35l32->regmap, CS35L32_INT_STATUS_1, ®); ret = snd_soc_register_codec(&i2c_client->dev, &soc_codec_dev_cs35l32, cs35l32_dai, ARRAY_SIZE(cs35l32_dai)); if (ret < 0) goto err_disable; return 0; err_disable: regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies), cs35l32->supplies); return ret; }
int hw_sensor_get_dt_data(struct platform_device *pdev, sensor_t *sensor) { struct device_node *of_node = pdev->dev.of_node; hwsensor_board_info_t *sensor_info = NULL; int rc = 0; u32 i, index = 0; char *gpio_tag = NULL; const char *gpio_ctrl_types[IO_MAX] = {"reset", "fsin", "pwdn", "vcm_pwdn", "suspend", "reset2"}; cam_debug("enter %s", __func__); sensor_info = kzalloc(sizeof(hwsensor_board_info_t), GFP_KERNEL); if (!sensor_info) { cam_err("%s failed %d\n", __func__, __LINE__); return -ENOMEM; } sensor->board_info= sensor_info; rc = of_property_read_string(of_node, "huawei,sensor_name", &sensor_info->name); cam_debug("%s huawei,sensor_name %s, rc %d\n", __func__, sensor_info->name, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,sensor_index", &sensor_info->sensor_index); cam_debug("%s huawei,sensor_index %d, rc %d\n", __func__, sensor_info->sensor_index, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,interface_type", &sensor_info->interface_type); cam_debug("%s huawei,interface_type %d, rc %d\n", __func__, sensor_info->interface_type, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,csi_lane", &sensor_info->csi_lane); cam_debug("%s huawei,csi_lane %d, rc %d\n", __func__, sensor_info->csi_lane, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,csi_mipi_clk", &sensor_info->csi_mipi_clk); cam_debug("%s huawei,csi_mipi_clk %d, rc %d\n", __func__, sensor_info->csi_mipi_clk, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,csi_index", &sensor_info->csi_index); cam_debug("%s huawei,csi_index %d, rc %d\n", __func__, sensor_info->csi_index, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,pd_valid", &sensor_info->power_conf.pd_valid); cam_debug("%s huawei,pd_valid %d, rc %d\n", __func__, sensor_info->power_conf.pd_valid, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,reset_valid", &sensor_info->power_conf.reset_valid); cam_debug("%s huawei,reset_valid %d, rc %d\n", __func__, sensor_info->power_conf.reset_valid, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,vcmpd_valid", &sensor_info->power_conf.vcmpd_valid); cam_debug("%s huawei,vcmpd_valid %d, rc %d\n", __func__, sensor_info->power_conf.vcmpd_valid, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,i2c-index", &sensor_info->i2c_config.index); cam_debug("%s huawei,i2c-index %d, rc %d\n", __func__, sensor_info->i2c_config.index, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,i2c-speed", &sensor_info->i2c_config.speed); cam_debug("%s huawei,i2c-speed %d, rc %d\n", __func__, sensor_info->i2c_config.speed, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,i2c-addr", &sensor_info->i2c_config.addr); cam_debug("%s huawei,i2c-addr 0x%x, rc %d\n", __func__, sensor_info->i2c_config.addr, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,i2c-addr_bits", &sensor_info->i2c_config.addr_bits); cam_debug("%s huawei,i2c-addr_bits %d, rc %d\n", __func__, sensor_info->i2c_config.addr_bits, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,i2c-val_bits", &sensor_info->i2c_config.val_bits); cam_debug("%s huawei,i2c-val_bits %d, rc %d\n", __func__, sensor_info->i2c_config.val_bits, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,sensor_chipid", &sensor_info->sensor_chipid); cam_debug("%s huawei,sensor_chipid 0x%x, rc %d\n", __func__, sensor_info->sensor_chipid, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,camif_id", &sensor_info->camif_id); cam_debug("%s huawei,camif_id 0x%x, rc %d\n", __func__, sensor_info->camif_id, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,vcm_enable", &sensor_info->vcm_enable); cam_debug("%s huawei,vcm_enable %d, rc %d\n", __func__, sensor_info->vcm_enable, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } rc = of_property_read_u32(of_node, "huawei,sensor_type", &sensor_info->sensor_type); cam_debug("%s huawei,sensor_type %d, rc %d\n", __func__, sensor_info->sensor_type, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } if (sensor_info->vcm_enable) { rc = of_property_read_string(of_node, "huawei,vcm_name", &sensor_info->vcm_name); cam_debug("%s huawei,vcm_name %s, rc %d\n", __func__, sensor_info->vcm_name, rc); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } } if (hw_is_fpga_board()) return rc; /* get ldo */ sensor_info->ldo_num = of_property_count_strings(of_node, "huawei,ldo-names"); if(sensor_info->ldo_num < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } cam_debug("ldo num = %d", sensor_info->ldo_num); for (i = 0; i < sensor_info->ldo_num; i++) { rc = of_property_read_string_index(of_node, "huawei,ldo-names", i, &sensor_info->ldo[i].supply); if(rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } } rc = devm_regulator_bulk_get(&(pdev->dev), sensor_info->ldo_num, sensor_info->ldo); if (rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } sensor_info->gpio_num = of_gpio_count(of_node); if(sensor_info->gpio_num < 0 ) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } for(i = 0; i < sensor_info->gpio_num; i++) { rc = of_property_read_string_index(of_node, "huawei,gpio-ctrl-types", i, (const char **)&gpio_tag); if(rc < 0) { cam_err("%s failed %d\n", __func__, __LINE__); goto fail; } for(index = 0; index < IO_MAX; index++) { if(!strcmp(gpio_ctrl_types[index], gpio_tag)) sensor_info->gpios[index].gpio = of_get_gpio(of_node, i); } cam_info("gpio ctrl types: %s\n", gpio_tag); } return rc; fail: cam_err("%s error exit.\n", __func__); kfree(sensor_info); sensor_info = NULL; return rc; }
static int twl6040_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device_node *node = client->dev.of_node; struct twl6040 *twl6040; struct mfd_cell *cell = NULL; int irq, ret, children = 0; if (!node) { dev_err(&client->dev, "of node is missing\n"); return -EINVAL; } /* In order to operate correctly we need valid interrupt config */ if (!client->irq) { dev_err(&client->dev, "Invalid IRQ configuration\n"); return -EINVAL; } twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040), GFP_KERNEL); if (!twl6040) return -ENOMEM; twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config); if (IS_ERR(twl6040->regmap)) return PTR_ERR(twl6040->regmap); i2c_set_clientdata(client, twl6040); twl6040->clk32k = devm_clk_get(&client->dev, "clk32k"); if (IS_ERR(twl6040->clk32k)) { if (PTR_ERR(twl6040->clk32k) == -EPROBE_DEFER) return -EPROBE_DEFER; dev_dbg(&client->dev, "clk32k is not handled\n"); twl6040->clk32k = NULL; } twl6040->mclk = devm_clk_get(&client->dev, "mclk"); if (IS_ERR(twl6040->mclk)) { if (PTR_ERR(twl6040->mclk) == -EPROBE_DEFER) return -EPROBE_DEFER; dev_dbg(&client->dev, "mclk is not handled\n"); twl6040->mclk = NULL; } twl6040->supplies[0].supply = "vio"; twl6040->supplies[1].supply = "v2v1"; ret = devm_regulator_bulk_get(&client->dev, TWL6040_NUM_SUPPLIES, twl6040->supplies); if (ret != 0) { dev_err(&client->dev, "Failed to get supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies); if (ret != 0) { dev_err(&client->dev, "Failed to enable supplies: %d\n", ret); return ret; } twl6040->dev = &client->dev; twl6040->irq = client->irq; mutex_init(&twl6040->mutex); init_completion(&twl6040->ready); regmap_register_patch(twl6040->regmap, twl6040_patch, ARRAY_SIZE(twl6040_patch)); twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); if (twl6040->rev < 0) { dev_err(&client->dev, "Failed to read revision register: %d\n", twl6040->rev); ret = twl6040->rev; goto gpio_err; } /* ERRATA: Automatic power-up is not possible in ES1.0 */ if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0) twl6040->audpwron = of_get_named_gpio(node, "ti,audpwron-gpio", 0); else twl6040->audpwron = -EINVAL; if (gpio_is_valid(twl6040->audpwron)) { ret = devm_gpio_request_one(&client->dev, twl6040->audpwron, GPIOF_OUT_INIT_LOW, "audpwron"); if (ret) goto gpio_err; /* Clear any pending interrupt */ twl6040_reg_read(twl6040, TWL6040_REG_INTID); } ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, IRQF_ONESHOT, 0, &twl6040_irq_chip, &twl6040->irq_data); if (ret < 0) goto gpio_err; twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_READY); twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_TH); ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_ready, NULL, twl6040_readyint_handler, IRQF_ONESHOT, "twl6040_irq_ready", twl6040); if (ret) { dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret); goto readyirq_err; } ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_th, NULL, twl6040_thint_handler, IRQF_ONESHOT, "twl6040_irq_th", twl6040); if (ret) { dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret); goto readyirq_err; } /* * The main functionality of twl6040 to provide audio on OMAP4+ systems. * We can add the ASoC codec child whenever this driver has been loaded. */ irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG); cell = &twl6040->cells[children]; cell->name = "twl6040-codec"; twl6040_codec_rsrc[0].start = irq; twl6040_codec_rsrc[0].end = irq; cell->resources = twl6040_codec_rsrc; cell->num_resources = ARRAY_SIZE(twl6040_codec_rsrc); children++; /* Vibra input driver support */ if (twl6040_has_vibra(node)) { irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB); cell = &twl6040->cells[children]; cell->name = "twl6040-vibra"; twl6040_vibra_rsrc[0].start = irq; twl6040_vibra_rsrc[0].end = irq; cell->resources = twl6040_vibra_rsrc; cell->num_resources = ARRAY_SIZE(twl6040_vibra_rsrc); children++; } /* GPO support */ cell = &twl6040->cells[children]; cell->name = "twl6040-gpo"; children++; /* PDM clock support */ cell = &twl6040->cells[children]; cell->name = "twl6040-pdmclk"; children++; /* The chip is powered down so mark regmap to cache only and dirty */ regcache_cache_only(twl6040->regmap, true); regcache_mark_dirty(twl6040->regmap); ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children, NULL, 0, NULL); if (ret) goto readyirq_err; return 0; readyirq_err: regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); gpio_err: regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); return ret; }
static int __devinit wm2000_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *i2c_id) { struct wm2000_priv *wm2000; struct wm2000_platform_data *pdata; const char *filename; const struct firmware *fw = NULL; int ret, i; int reg; u16 id; wm2000 = devm_kzalloc(&i2c->dev, sizeof(struct wm2000_priv), GFP_KERNEL); if (wm2000 == NULL) { dev_err(&i2c->dev, "Unable to allocate private data\n"); return -ENOMEM; } dev_set_drvdata(&i2c->dev, wm2000); wm2000->regmap = devm_regmap_init_i2c(i2c, &wm2000_regmap); if (IS_ERR(wm2000->regmap)) { ret = PTR_ERR(wm2000->regmap); dev_err(&i2c->dev, "Failed to allocate register map: %d\n", ret); goto out; } for (i = 0; i < WM2000_NUM_SUPPLIES; i++) wm2000->supplies[i].supply = wm2000_supplies[i]; ret = devm_regulator_bulk_get(&i2c->dev, WM2000_NUM_SUPPLIES, wm2000->supplies); if (ret != 0) { dev_err(&i2c->dev, "Failed to get supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(WM2000_NUM_SUPPLIES, wm2000->supplies); if (ret != 0) { dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); return ret; } /* Verify that this is a WM2000 */ reg = wm2000_read(i2c, WM2000_REG_ID1); id = reg << 8; reg = wm2000_read(i2c, WM2000_REG_ID2); id |= reg & 0xff; if (id != 0x2000) { dev_err(&i2c->dev, "Device is not a WM2000 - ID %x\n", id); ret = -ENODEV; goto err_supplies; } reg = wm2000_read(i2c, WM2000_REG_REVISON); dev_info(&i2c->dev, "revision %c\n", reg + 'A'); filename = "wm2000_anc.bin"; pdata = dev_get_platdata(&i2c->dev); if (pdata) { wm2000->mclk_div = pdata->mclkdiv2; wm2000->speech_clarity = !pdata->speech_enh_disable; if (pdata->download_file) filename = pdata->download_file; } ret = request_firmware(&fw, filename, &i2c->dev); if (ret != 0) goto err_supplies; /* Pre-cook the concatenation of the register address onto the image */ wm2000->anc_download_size = fw->size + 2; wm2000->anc_download = devm_kzalloc(&i2c->dev, wm2000->anc_download_size, GFP_KERNEL); if (wm2000->anc_download == NULL) { dev_err(&i2c->dev, "Out of memory\n"); ret = -ENOMEM; goto err_supplies; } wm2000->anc_download[0] = 0x80; wm2000->anc_download[1] = 0x00; memcpy(wm2000->anc_download + 2, fw->data, fw->size); wm2000->anc_eng_ena = 1; wm2000->anc_active = 1; wm2000->spk_ena = 1; wm2000->i2c = i2c; wm2000_reset(wm2000); ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm2000, NULL, 0); err_supplies: regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies); out: release_firmware(fw); return ret; }
static int tas5720_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; struct tas5720_data *data; const struct regmap_config *regmap_config; int ret; int i; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; data->tas5720_client = client; data->devtype = id->driver_data; switch (id->driver_data) { case TAS5720: regmap_config = &tas5720_regmap_config; break; case TAS5722: regmap_config = &tas5722_regmap_config; break; default: dev_err(dev, "unexpected private driver data\n"); return -EINVAL; } data->regmap = devm_regmap_init_i2c(client, regmap_config); if (IS_ERR(data->regmap)) { ret = PTR_ERR(data->regmap); dev_err(dev, "failed to allocate register map: %d\n", ret); return ret; } for (i = 0; i < ARRAY_SIZE(data->supplies); i++) data->supplies[i].supply = tas5720_supply_names[i]; ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies), data->supplies); if (ret != 0) { dev_err(dev, "failed to request supplies: %d\n", ret); return ret; } dev_set_drvdata(dev, data); switch (id->driver_data) { case TAS5720: ret = devm_snd_soc_register_component(&client->dev, &soc_component_dev_tas5720, tas5720_dai, ARRAY_SIZE(tas5720_dai)); break; case TAS5722: ret = devm_snd_soc_register_component(&client->dev, &soc_component_dev_tas5722, tas5720_dai, ARRAY_SIZE(tas5720_dai)); break; default: dev_err(dev, "unexpected private driver data\n"); return -EINVAL; } if (ret < 0) { dev_err(dev, "failed to register component: %d\n", ret); return ret; } return 0; }
static int silead_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct silead_ts_data *data; struct device *dev = &client->dev; int error; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | I2C_FUNC_SMBUS_READ_I2C_BLOCK | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { dev_err(dev, "I2C functionality check failed\n"); return -ENXIO; } data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; i2c_set_clientdata(client, data); data->client = client; error = silead_ts_set_default_fw_name(data, id); if (error) return error; silead_ts_read_props(client); /* We must have the IRQ provided by DT or ACPI subsytem */ if (client->irq <= 0) return -ENODEV; data->regulators[0].supply = "vddio"; data->regulators[1].supply = "avdd"; error = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->regulators), data->regulators); if (error) return error; /* * Enable regulators at probe and disable them at remove, we need * to keep the chip powered otherwise it forgets its firmware. */ error = regulator_bulk_enable(ARRAY_SIZE(data->regulators), data->regulators); if (error) return error; error = devm_add_action_or_reset(dev, silead_disable_regulator, data); if (error) return error; /* Power GPIO pin */ data->gpio_power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW); if (IS_ERR(data->gpio_power)) { if (PTR_ERR(data->gpio_power) != -EPROBE_DEFER) dev_err(dev, "Shutdown GPIO request failed\n"); return PTR_ERR(data->gpio_power); } error = silead_ts_setup(client); if (error) return error; error = silead_ts_request_input_dev(data); if (error) return error; error = devm_request_threaded_irq(dev, client->irq, NULL, silead_ts_threaded_irq_handler, IRQF_ONESHOT, client->name, data); if (error) { if (error != -EPROBE_DEFER) dev_err(dev, "IRQ request failed %d\n", error); return error; } return 0; }
int mpu3050_common_probe(struct device *dev, struct regmap *map, int irq, const char *name) { struct iio_dev *indio_dev; struct mpu3050 *mpu3050; unsigned int val; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*mpu3050)); if (!indio_dev) return -ENOMEM; mpu3050 = iio_priv(indio_dev); mpu3050->dev = dev; mpu3050->map = map; mutex_init(&mpu3050->lock); /* Default fullscale: 2000 degrees per second */ mpu3050->fullscale = FS_2000_DPS; /* 1 kHz, divide by 100, default frequency = 10 Hz */ mpu3050->lpf = MPU3050_DLPF_CFG_188HZ; mpu3050->divisor = 99; /* Read the mounting matrix, if present */ ret = of_iio_read_mount_matrix(dev, "mount-matrix", &mpu3050->orientation); if (ret) return ret; /* Fetch and turn on regulators */ mpu3050->regs[0].supply = mpu3050_reg_vdd; mpu3050->regs[1].supply = mpu3050_reg_vlogic; ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(mpu3050->regs), mpu3050->regs); if (ret) { dev_err(dev, "Cannot get regulators\n"); return ret; } ret = mpu3050_power_up(mpu3050); if (ret) return ret; ret = regmap_read(map, MPU3050_CHIP_ID_REG, &val); if (ret) { dev_err(dev, "could not read device ID\n"); ret = -ENODEV; goto err_power_down; } if ((val & MPU3050_CHIP_ID_MASK) != MPU3050_CHIP_ID) { dev_err(dev, "unsupported chip id %02x\n", (u8)(val & MPU3050_CHIP_ID_MASK)); ret = -ENODEV; goto err_power_down; } ret = regmap_read(map, MPU3050_PRODUCT_ID_REG, &val); if (ret) { dev_err(dev, "could not read device ID\n"); ret = -ENODEV; goto err_power_down; } dev_info(dev, "found MPU-3050 part no: %d, version: %d\n", ((val >> 4) & 0xf), (val & 0xf)); ret = mpu3050_hw_init(mpu3050); if (ret) goto err_power_down; indio_dev->dev.parent = dev; indio_dev->channels = mpu3050_channels; indio_dev->num_channels = ARRAY_SIZE(mpu3050_channels); indio_dev->info = &mpu3050_info; indio_dev->available_scan_masks = mpu3050_scan_masks; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->name = name; ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time, mpu3050_trigger_handler, &mpu3050_buffer_setup_ops); if (ret) { dev_err(dev, "triggered buffer setup failed\n"); goto err_power_down; } ret = iio_device_register(indio_dev); if (ret) { dev_err(dev, "device register failed\n"); goto err_cleanup_buffer; } dev_set_drvdata(dev, indio_dev); /* Check if we have an assigned IRQ to use as trigger */ if (irq) { ret = mpu3050_trigger_probe(indio_dev, irq); if (ret) dev_err(dev, "failed to register trigger\n"); } /* Enable runtime PM */ pm_runtime_get_noresume(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); /* * Set autosuspend to two orders of magnitude larger than the * start-up time. 100ms start-up time means 10000ms autosuspend, * i.e. 10 seconds. */ pm_runtime_set_autosuspend_delay(dev, 10000); pm_runtime_use_autosuspend(dev); pm_runtime_put(dev); return 0; err_cleanup_buffer: iio_triggered_buffer_cleanup(indio_dev); err_power_down: mpu3050_power_down(mpu3050); 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 tegra_ahci_probe(struct platform_device *pdev) { struct ahci_host_priv *hpriv; struct tegra_ahci_priv *tegra; struct resource *res; int ret; hpriv = ahci_platform_get_resources(pdev); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); if (!tegra) return -ENOMEM; hpriv->plat_data = tegra; tegra->pdev = pdev; res = platform_get_resource(pdev, IORESOURCE_MEM, 1); tegra->sata_regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(tegra->sata_regs)) return PTR_ERR(tegra->sata_regs); tegra->sata_rst = devm_reset_control_get(&pdev->dev, "sata"); if (IS_ERR(tegra->sata_rst)) { dev_err(&pdev->dev, "Failed to get sata reset\n"); return PTR_ERR(tegra->sata_rst); } tegra->sata_oob_rst = devm_reset_control_get(&pdev->dev, "sata-oob"); if (IS_ERR(tegra->sata_oob_rst)) { dev_err(&pdev->dev, "Failed to get sata-oob reset\n"); return PTR_ERR(tegra->sata_oob_rst); } tegra->sata_cold_rst = devm_reset_control_get(&pdev->dev, "sata-cold"); if (IS_ERR(tegra->sata_cold_rst)) { dev_err(&pdev->dev, "Failed to get sata-cold reset\n"); return PTR_ERR(tegra->sata_cold_rst); } tegra->sata_clk = devm_clk_get(&pdev->dev, "sata"); if (IS_ERR(tegra->sata_clk)) { dev_err(&pdev->dev, "Failed to get sata clock\n"); return PTR_ERR(tegra->sata_clk); } tegra->supplies[0].supply = "avdd"; tegra->supplies[1].supply = "hvdd"; tegra->supplies[2].supply = "vddio"; tegra->supplies[3].supply = "target-5v"; tegra->supplies[4].supply = "target-12v"; ret = devm_regulator_bulk_get(&pdev->dev, ARRAY_SIZE(tegra->supplies), tegra->supplies); if (ret) { dev_err(&pdev->dev, "Failed to get regulators\n"); return ret; } ret = tegra_ahci_controller_init(hpriv); if (ret) return ret; ret = ahci_platform_init_host(pdev, hpriv, &ahci_tegra_port_info); if (ret) goto deinit_controller; return 0; deinit_controller: tegra_ahci_controller_deinit(hpriv); return ret; };
static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg) { int i, ret; /* Set default UTMI width */ hsotg->phyif = GUSBCFG_PHYIF16; /* * Attempt to find a generic PHY, then look for an old style * USB PHY and then fall back to pdata */ hsotg->phy = devm_phy_get(hsotg->dev, "usb2-phy"); if (IS_ERR(hsotg->phy)) { ret = PTR_ERR(hsotg->phy); switch (ret) { case -ENODEV: case -ENOSYS: hsotg->phy = NULL; break; case -EPROBE_DEFER: return ret; default: dev_err(hsotg->dev, "error getting phy %d\n", ret); return ret; } } if (!hsotg->phy) { hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2); if (IS_ERR(hsotg->uphy)) { ret = PTR_ERR(hsotg->uphy); switch (ret) { case -ENODEV: case -ENXIO: hsotg->uphy = NULL; break; case -EPROBE_DEFER: return ret; default: dev_err(hsotg->dev, "error getting usb phy %d\n", ret); return ret; } } } hsotg->plat = dev_get_platdata(hsotg->dev); if (hsotg->phy) { /* * If using the generic PHY framework, check if the PHY bus * width is 8-bit and set the phyif appropriately. */ if (phy_get_bus_width(hsotg->phy) == 8) hsotg->phyif = GUSBCFG_PHYIF8; } /* Clock */ hsotg->clk = devm_clk_get(hsotg->dev, "otg"); if (IS_ERR(hsotg->clk)) { hsotg->clk = NULL; dev_dbg(hsotg->dev, "cannot get otg clock\n"); } /* Regulators */ for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) hsotg->supplies[i].supply = dwc2_hsotg_supply_names[i]; ret = devm_regulator_bulk_get(hsotg->dev, ARRAY_SIZE(hsotg->supplies), hsotg->supplies); if (ret) { dev_err(hsotg->dev, "failed to request supplies: %d\n", ret); return ret; } return 0; }
static int wm8523_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8523_priv *wm8523; unsigned int val; int ret, i; wm8523 = devm_kzalloc(&i2c->dev, sizeof(struct wm8523_priv), GFP_KERNEL); if (wm8523 == NULL) return -ENOMEM; wm8523->regmap = devm_regmap_init_i2c(i2c, &wm8523_regmap); if (IS_ERR(wm8523->regmap)) { ret = PTR_ERR(wm8523->regmap); dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret); return ret; } for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++) wm8523->supplies[i].supply = wm8523_supply_names[i]; ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8523->supplies), wm8523->supplies); if (ret != 0) { dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies); if (ret != 0) { dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); return ret; } ret = regmap_read(wm8523->regmap, WM8523_DEVICE_ID, &val); if (ret < 0) { dev_err(&i2c->dev, "Failed to read ID register\n"); goto err_enable; } if (val != 0x8523) { dev_err(&i2c->dev, "Device is not a WM8523, ID is %x\n", ret); ret = -EINVAL; goto err_enable; } ret = regmap_read(wm8523->regmap, WM8523_REVISION, &val); if (ret < 0) { dev_err(&i2c->dev, "Failed to read revision register\n"); goto err_enable; } dev_info(&i2c->dev, "revision %c\n", (val & WM8523_CHIP_REV_MASK) + 'A'); ret = regmap_write(wm8523->regmap, WM8523_DEVICE_ID, 0x8523); if (ret != 0) { dev_err(&i2c->dev, "Failed to reset device: %d\n", ret); goto err_enable; } regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies); i2c_set_clientdata(i2c, wm8523); ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm8523, &wm8523_dai, 1); return ret; err_enable: regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies); 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 int tas5086_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct tas5086_private *priv; struct device *dev = &i2c->dev; int gpio_nreset = -EINVAL; int i, ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; for (i = 0; i < ARRAY_SIZE(supply_names); i++) priv->supplies[i].supply = supply_names[i]; ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies), priv->supplies); if (ret < 0) { dev_err(dev, "Failed to get regulators: %d\n", ret); return ret; } priv->regmap = devm_regmap_init(dev, NULL, i2c, &tas5086_regmap); if (IS_ERR(priv->regmap)) { ret = PTR_ERR(priv->regmap); dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret); return ret; } i2c_set_clientdata(i2c, priv); if (of_match_device(of_match_ptr(tas5086_dt_ids), dev)) { struct device_node *of_node = dev->of_node; gpio_nreset = of_get_named_gpio(of_node, "reset-gpio", 0); } if (gpio_is_valid(gpio_nreset)) if (devm_gpio_request(dev, gpio_nreset, "TAS5086 Reset")) gpio_nreset = -EINVAL; priv->gpio_nreset = gpio_nreset; ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); if (ret < 0) { dev_err(dev, "Failed to enable regulators: %d\n", ret); return ret; } tas5086_reset(priv); /* The TAS5086 always returns 0x03 in its TAS5086_DEV_ID register */ ret = regmap_read(priv->regmap, TAS5086_DEV_ID, &i); if (ret == 0 && i != 0x3) { dev_err(dev, "Failed to identify TAS5086 codec (got %02x)\n", i); ret = -ENODEV; } /* * The chip has been identified, so we can turn off the power * again until the dai link is set up. */ regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); if (ret == 0) ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_tas5086, &tas5086_dai, 1); return ret; }
static int si476x_core_probe(struct i2c_client *client, const struct i2c_device_id *id) { int rval; struct si476x_core *core; struct si476x_platform_data *pdata; struct mfd_cell *cell; int cell_num; core = devm_kzalloc(&client->dev, sizeof(*core), GFP_KERNEL); if (!core) { dev_err(&client->dev, "failed to allocate 'struct si476x_core'\n"); return -ENOMEM; } core->client = client; core->regmap = devm_regmap_init_si476x(core); if (IS_ERR(core->regmap)) { rval = PTR_ERR(core->regmap); dev_err(&client->dev, "Failed to allocate register map: %d\n", rval); return rval; } i2c_set_clientdata(client, core); atomic_set(&core->is_alive, 0); core->power_state = SI476X_POWER_DOWN; pdata = dev_get_platdata(&client->dev); if (pdata) { memcpy(&core->power_up_parameters, &pdata->power_up_parameters, sizeof(core->power_up_parameters)); core->gpio_reset = -1; if (gpio_is_valid(pdata->gpio_reset)) { rval = gpio_request(pdata->gpio_reset, "si476x reset"); if (rval) { dev_err(&client->dev, "Failed to request gpio: %d\n", rval); return rval; } core->gpio_reset = pdata->gpio_reset; gpio_direction_output(core->gpio_reset, 0); } core->diversity_mode = pdata->diversity_mode; memcpy(&core->pinmux, &pdata->pinmux, sizeof(struct si476x_pinmux)); } else { dev_err(&client->dev, "No platform data provided\n"); return -EINVAL; } core->supplies[0].supply = "vd"; core->supplies[1].supply = "va"; core->supplies[2].supply = "vio1"; core->supplies[3].supply = "vio2"; rval = devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(core->supplies), core->supplies); if (rval) { dev_err(&client->dev, "Failet to gett all of the regulators\n"); goto free_gpio; } mutex_init(&core->cmd_lock); init_waitqueue_head(&core->command); init_waitqueue_head(&core->tuning); rval = kfifo_alloc(&core->rds_fifo, SI476X_DRIVER_RDS_FIFO_DEPTH * sizeof(struct v4l2_rds_data), GFP_KERNEL); if (rval) { dev_err(&client->dev, "Could not allocate the FIFO\n"); goto free_gpio; } mutex_init(&core->rds_drainer_status_lock); init_waitqueue_head(&core->rds_read_queue); INIT_WORK(&core->rds_fifo_drainer, si476x_core_drain_rds_fifo); if (client->irq) { rval = devm_request_threaded_irq(&client->dev, client->irq, NULL, si476x_core_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, client->name, core); if (rval < 0) { dev_err(&client->dev, "Could not request IRQ %d\n", client->irq); goto free_kfifo; } disable_irq(client->irq); dev_dbg(&client->dev, "IRQ requested.\n"); core->rds_fifo_depth = 20; } else { INIT_DELAYED_WORK(&core->status_monitor, si476x_core_poll_loop); dev_info(&client->dev, "No IRQ number specified, will use polling\n"); core->rds_fifo_depth = 5; } core->chip_id = id->driver_data; rval = si476x_core_get_revision_info(core); if (rval < 0) { rval = -ENODEV; goto free_kfifo; } cell_num = 0; cell = &core->cells[SI476X_RADIO_CELL]; cell->name = "si476x-radio"; cell_num++; #ifdef CONFIG_SND_SOC_SI476X if ((core->chip_id == SI476X_CHIP_SI4761 || core->chip_id == SI476X_CHIP_SI4764) && core->pinmux.dclk == SI476X_DCLK_DAUDIO && core->pinmux.dfs == SI476X_DFS_DAUDIO && core->pinmux.dout == SI476X_DOUT_I2S_OUTPUT && core->pinmux.xout == SI476X_XOUT_TRISTATE) { cell = &core->cells[SI476X_CODEC_CELL]; cell->name = "si476x-codec"; cell_num++; } #endif rval = mfd_add_devices(&client->dev, (client->adapter->nr << 8) + client->addr, core->cells, cell_num, NULL, 0, NULL); if (!rval) return 0; free_kfifo: kfifo_free(&core->rds_fifo); free_gpio: if (gpio_is_valid(core->gpio_reset)) gpio_free(core->gpio_reset); return rval; }
int pcm512x_probe(struct device *dev, struct regmap *regmap) { struct pcm512x_priv *pcm512x; int i, ret; pcm512x = devm_kzalloc(dev, sizeof(struct pcm512x_priv), GFP_KERNEL); if (!pcm512x) return -ENOMEM; dev_set_drvdata(dev, pcm512x); pcm512x->regmap = regmap; for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) pcm512x->supplies[i].supply = pcm512x_supply_names[i]; ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pcm512x->supplies), pcm512x->supplies); if (ret != 0) { dev_err(dev, "Failed to get supplies: %d\n", ret); return ret; } pcm512x->supply_nb[0].notifier_call = pcm512x_regulator_event_0; pcm512x->supply_nb[1].notifier_call = pcm512x_regulator_event_1; pcm512x->supply_nb[2].notifier_call = pcm512x_regulator_event_2; for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) { ret = regulator_register_notifier(pcm512x->supplies[i].consumer, &pcm512x->supply_nb[i]); if (ret != 0) { dev_err(dev, "Failed to register regulator notifier: %d\n", ret); } } ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies), pcm512x->supplies); if (ret != 0) { dev_err(dev, "Failed to enable supplies: %d\n", ret); return ret; } /* Reset the device, verifying I/O in the process for I2C */ ret = regmap_write(regmap, PCM512x_RESET, PCM512x_RSTM | PCM512x_RSTR); if (ret != 0) { dev_err(dev, "Failed to reset device: %d\n", ret); goto err; } ret = regmap_write(regmap, PCM512x_RESET, 0); if (ret != 0) { dev_err(dev, "Failed to reset device: %d\n", ret); goto err; } pcm512x->sclk = devm_clk_get(dev, NULL); if (IS_ERR(pcm512x->sclk)) { if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER) return -EPROBE_DEFER; dev_info(dev, "No SCLK, using BCLK: %ld\n", PTR_ERR(pcm512x->sclk)); /* Disable reporting of missing SCLK as an error */ regmap_update_bits(regmap, PCM512x_ERROR_DETECT, PCM512x_IDCH, PCM512x_IDCH); /* Switch PLL input to BCLK */ regmap_update_bits(regmap, PCM512x_PLL_REF, PCM512x_SREF, PCM512x_SREF); } else { ret = clk_prepare_enable(pcm512x->sclk); if (ret != 0) { dev_err(dev, "Failed to enable SCLK: %d\n", ret); return ret; } } /* Default to standby mode */ ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER, PCM512x_RQST, PCM512x_RQST); if (ret != 0) { dev_err(dev, "Failed to request standby: %d\n", ret); goto err_clk; } pm_runtime_set_active(dev); pm_runtime_enable(dev); pm_runtime_idle(dev); ret = snd_soc_register_codec(dev, &pcm512x_codec_driver, &pcm512x_dai, 1); if (ret != 0) { dev_err(dev, "Failed to register CODEC: %d\n", ret); goto err_pm; } return 0; err_pm: pm_runtime_disable(dev); err_clk: if (!IS_ERR(pcm512x->sclk)) clk_disable_unprepare(pcm512x->sclk); err: regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies), pcm512x->supplies); return ret; }
int pcm512x_probe(struct device *dev, struct regmap *regmap) { struct pcm512x_priv *pcm512x; int i, ret; pcm512x = devm_kzalloc(dev, sizeof(struct pcm512x_priv), GFP_KERNEL); if (!pcm512x) return -ENOMEM; dev_set_drvdata(dev, pcm512x); pcm512x->regmap = regmap; for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) pcm512x->supplies[i].supply = pcm512x_supply_names[i]; ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pcm512x->supplies), pcm512x->supplies); if (ret != 0) { dev_err(dev, "Failed to get supplies: %d\n", ret); return ret; } pcm512x->supply_nb[0].notifier_call = pcm512x_regulator_event_0; pcm512x->supply_nb[1].notifier_call = pcm512x_regulator_event_1; pcm512x->supply_nb[2].notifier_call = pcm512x_regulator_event_2; for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) { ret = regulator_register_notifier(pcm512x->supplies[i].consumer, &pcm512x->supply_nb[i]); if (ret != 0) { dev_err(dev, "Failed to register regulator notifier: %d\n", ret); } } ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies), pcm512x->supplies); if (ret != 0) { dev_err(dev, "Failed to enable supplies: %d\n", ret); return ret; } /* Reset the device, verifying I/O in the process for I2C */ ret = regmap_write(regmap, PCM512x_RESET, PCM512x_RSTM | PCM512x_RSTR); if (ret != 0) { dev_err(dev, "Failed to reset device: %d\n", ret); goto err; } ret = regmap_write(regmap, PCM512x_RESET, 0); if (ret != 0) { dev_err(dev, "Failed to reset device: %d\n", ret); goto err; } pcm512x->sclk = devm_clk_get(dev, NULL); if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER) return -EPROBE_DEFER; if (!IS_ERR(pcm512x->sclk)) { ret = clk_prepare_enable(pcm512x->sclk); if (ret != 0) { dev_err(dev, "Failed to enable SCLK: %d\n", ret); return ret; } } /* Default to standby mode */ ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER, PCM512x_RQST, PCM512x_RQST); if (ret != 0) { dev_err(dev, "Failed to request standby: %d\n", ret); goto err_clk; } pm_runtime_set_active(dev); pm_runtime_enable(dev); pm_runtime_idle(dev); #ifdef CONFIG_OF if (dev->of_node) { const struct device_node *np = dev->of_node; u32 val; if (of_property_read_u32(np, "pll-in", &val) >= 0) { if (val > 6) { dev_err(dev, "Invalid pll-in\n"); ret = -EINVAL; goto err_clk; } pcm512x->pll_in = val; } if (of_property_read_u32(np, "pll-out", &val) >= 0) { if (val > 6) { dev_err(dev, "Invalid pll-out\n"); ret = -EINVAL; goto err_clk; } pcm512x->pll_out = val; } if (!pcm512x->pll_in != !pcm512x->pll_out) { dev_err(dev, "Error: both pll-in and pll-out, or none\n"); ret = -EINVAL; goto err_clk; } if (pcm512x->pll_in && pcm512x->pll_in == pcm512x->pll_out) { dev_err(dev, "Error: pll-in == pll-out\n"); ret = -EINVAL; goto err_clk; } } #endif ret = snd_soc_register_codec(dev, &pcm512x_codec_driver, &pcm512x_dai, 1); if (ret != 0) { dev_err(dev, "Failed to register CODEC: %d\n", ret); goto err_pm; } return 0; err_pm: pm_runtime_disable(dev); err_clk: if (!IS_ERR(pcm512x->sclk)) clk_disable_unprepare(pcm512x->sclk); err: regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies), pcm512x->supplies); return ret; }
static int cs35l34_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { struct cs35l34_private *cs35l34; struct cs35l34_platform_data *pdata = dev_get_platdata(&i2c_client->dev); int i; int ret; unsigned int devid = 0; unsigned int reg; cs35l34 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l34_private), GFP_KERNEL); if (!cs35l34) { dev_err(&i2c_client->dev, "could not allocate codec\n"); return -ENOMEM; } i2c_set_clientdata(i2c_client, cs35l34); cs35l34->regmap = devm_regmap_init_i2c(i2c_client, &cs35l34_regmap); if (IS_ERR(cs35l34->regmap)) { ret = PTR_ERR(cs35l34->regmap); dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); return ret; } cs35l34->num_core_supplies = ARRAY_SIZE(cs35l34_core_supplies); for (i = 0; i < ARRAY_SIZE(cs35l34_core_supplies); i++) cs35l34->core_supplies[i].supply = cs35l34_core_supplies[i]; ret = devm_regulator_bulk_get(&i2c_client->dev, cs35l34->num_core_supplies, cs35l34->core_supplies); if (ret != 0) { dev_err(&i2c_client->dev, "Failed to request core supplies %d\n", ret); return ret; } ret = regulator_bulk_enable(cs35l34->num_core_supplies, cs35l34->core_supplies); if (ret != 0) { dev_err(&i2c_client->dev, "Failed to enable core supplies: %d\n", ret); return ret; } if (pdata) { cs35l34->pdata = *pdata; } else { pdata = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l34_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c_client->dev, "could not allocate pdata\n"); return -ENOMEM; } if (i2c_client->dev.of_node) { ret = cs35l34_handle_of_data(i2c_client, pdata); if (ret != 0) return ret; } cs35l34->pdata = *pdata; } ret = devm_request_threaded_irq(&i2c_client->dev, i2c_client->irq, NULL, cs35l34_irq_thread, IRQF_ONESHOT | IRQF_TRIGGER_LOW, "cs35l34", cs35l34); if (ret != 0) dev_err(&i2c_client->dev, "Failed to request IRQ: %d\n", ret); cs35l34->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, "reset-gpios", GPIOD_OUT_LOW); if (IS_ERR(cs35l34->reset_gpio)) return PTR_ERR(cs35l34->reset_gpio); gpiod_set_value_cansleep(cs35l34->reset_gpio, 1); msleep(CS35L34_START_DELAY); ret = regmap_read(cs35l34->regmap, CS35L34_DEVID_AB, ®); devid = (reg & 0xFF) << 12; ret = regmap_read(cs35l34->regmap, CS35L34_DEVID_CD, ®); devid |= (reg & 0xFF) << 4; ret = regmap_read(cs35l34->regmap, CS35L34_DEVID_E, ®); devid |= (reg & 0xF0) >> 4; if (devid != CS35L34_CHIP_ID) { dev_err(&i2c_client->dev, "CS35l34 Device ID (%X). Expected ID %X\n", devid, CS35L34_CHIP_ID); ret = -ENODEV; goto err_regulator; } ret = regmap_read(cs35l34->regmap, CS35L34_REV_ID, ®); if (ret < 0) { dev_err(&i2c_client->dev, "Get Revision ID failed\n"); goto err_regulator; } dev_info(&i2c_client->dev, "Cirrus Logic CS35l34 (%x), Revision: %02X\n", devid, reg & 0xFF); /* Unmask critical interrupts */ regmap_update_bits(cs35l34->regmap, CS35L34_INT_MASK_1, CS35L34_M_CAL_ERR | CS35L34_M_ALIVE_ERR | CS35L34_M_AMP_SHORT | CS35L34_M_OTW | CS35L34_M_OTE, 0); regmap_update_bits(cs35l34->regmap, CS35L34_INT_MASK_3, CS35L34_M_BST_HIGH | CS35L34_M_LBST_SHORT, 0); pm_runtime_set_autosuspend_delay(&i2c_client->dev, 100); pm_runtime_use_autosuspend(&i2c_client->dev); pm_runtime_set_active(&i2c_client->dev); pm_runtime_enable(&i2c_client->dev); ret = snd_soc_register_codec(&i2c_client->dev, &soc_codec_dev_cs35l34, &cs35l34_dai, 1); if (ret < 0) { dev_err(&i2c_client->dev, "%s: Register codec failed\n", __func__); goto err_regulator; } return 0; err_regulator: regulator_bulk_disable(cs35l34->num_core_supplies, cs35l34->core_supplies); return ret; }
/** * cs4270_i2c_probe - initialize the I2C interface of the CS4270 * @i2c_client: the I2C client object * @id: the I2C device ID (ignored) * * This function is called whenever the I2C subsystem finds a device that * matches the device ID given via a prior call to i2c_add_driver(). */ static int cs4270_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { struct device_node *np = i2c_client->dev.of_node; struct cs4270_private *cs4270; unsigned int val; int ret, i; cs4270 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4270_private), GFP_KERNEL); if (!cs4270) { dev_err(&i2c_client->dev, "could not allocate codec\n"); return -ENOMEM; } /* get the power supply regulators */ for (i = 0; i < ARRAY_SIZE(supply_names); i++) cs4270->supplies[i].supply = supply_names[i]; ret = devm_regulator_bulk_get(&i2c_client->dev, ARRAY_SIZE(cs4270->supplies), cs4270->supplies); if (ret < 0) return ret; /* See if we have a way to bring the codec out of reset */ if (np) { enum of_gpio_flags flags; int gpio = of_get_named_gpio_flags(np, "reset-gpio", 0, &flags); if (gpio_is_valid(gpio)) { ret = devm_gpio_request_one(&i2c_client->dev, gpio, flags & OF_GPIO_ACTIVE_LOW ? GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH, "cs4270 reset"); if (ret < 0) return ret; } } cs4270->regmap = devm_regmap_init_i2c(i2c_client, &cs4270_regmap); if (IS_ERR(cs4270->regmap)) return PTR_ERR(cs4270->regmap); /* Verify that we have a CS4270 */ ret = regmap_read(cs4270->regmap, CS4270_CHIPID, &val); if (ret < 0) { dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n", i2c_client->addr); return ret; } /* The top four bits of the chip ID should be 1100. */ if ((val & 0xF0) != 0xC0) { dev_err(&i2c_client->dev, "device at addr %X is not a CS4270\n", i2c_client->addr); return -ENODEV; } dev_info(&i2c_client->dev, "found device at i2c address %X\n", i2c_client->addr); dev_info(&i2c_client->dev, "hardware revision %X\n", val & 0xF); i2c_set_clientdata(i2c_client, cs4270); ret = snd_soc_register_codec(&i2c_client->dev, &soc_codec_device_cs4270, &cs4270_dai, 1); return ret; }
static int wm0010_spi_probe(struct spi_device *spi) { unsigned long gpio_flags; int ret; int trigger; int irq; struct wm0010_priv *wm0010; wm0010 = devm_kzalloc(&spi->dev, sizeof(*wm0010), GFP_KERNEL); if (!wm0010) return -ENOMEM; mutex_init(&wm0010->lock); spin_lock_init(&wm0010->irq_lock); spi_set_drvdata(spi, wm0010); wm0010->dev = &spi->dev; if (dev_get_platdata(&spi->dev)) memcpy(&wm0010->pdata, dev_get_platdata(&spi->dev), sizeof(wm0010->pdata)); init_completion(&wm0010->boot_completion); wm0010->core_supplies[0].supply = "AVDD"; wm0010->core_supplies[1].supply = "DCVDD"; ret = devm_regulator_bulk_get(wm0010->dev, ARRAY_SIZE(wm0010->core_supplies), wm0010->core_supplies); if (ret != 0) { dev_err(wm0010->dev, "Failed to obtain core supplies: %d\n", ret); return ret; } wm0010->dbvdd = devm_regulator_get(wm0010->dev, "DBVDD"); if (IS_ERR(wm0010->dbvdd)) { ret = PTR_ERR(wm0010->dbvdd); dev_err(wm0010->dev, "Failed to obtain DBVDD: %d\n", ret); return ret; } if (wm0010->pdata.gpio_reset) { wm0010->gpio_reset = wm0010->pdata.gpio_reset; if (wm0010->pdata.reset_active_high) wm0010->gpio_reset_value = 1; else wm0010->gpio_reset_value = 0; if (wm0010->gpio_reset_value) gpio_flags = GPIOF_OUT_INIT_HIGH; else gpio_flags = GPIOF_OUT_INIT_LOW; ret = devm_gpio_request_one(wm0010->dev, wm0010->gpio_reset, gpio_flags, "wm0010 reset"); if (ret < 0) { dev_err(wm0010->dev, "Failed to request GPIO for DSP reset: %d\n", ret); return ret; } } else { dev_err(wm0010->dev, "No reset GPIO configured\n"); return -EINVAL; } wm0010->state = WM0010_POWER_OFF; irq = spi->irq; if (wm0010->pdata.irq_flags) trigger = wm0010->pdata.irq_flags; else trigger = IRQF_TRIGGER_FALLING; trigger |= IRQF_ONESHOT; ret = request_threaded_irq(irq, NULL, wm0010_irq, trigger | IRQF_ONESHOT, "wm0010", wm0010); if (ret) { dev_err(wm0010->dev, "Failed to request IRQ %d: %d\n", irq, ret); return ret; } wm0010->irq = irq; ret = irq_set_irq_wake(irq, 1); if (ret) { dev_err(wm0010->dev, "Failed to set IRQ %d as wake source: %d\n", irq, ret); return ret; } if (spi->max_speed_hz) wm0010->board_max_spi_speed = spi->max_speed_hz; else wm0010->board_max_spi_speed = 0; ret = snd_soc_register_codec(&spi->dev, &soc_codec_dev_wm0010, wm0010_dai, ARRAY_SIZE(wm0010_dai)); if (ret < 0) return ret; return 0; }
static int sta32x_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct device *dev = &i2c->dev; struct sta32x_priv *sta32x; int ret, i; sta32x = devm_kzalloc(&i2c->dev, sizeof(struct sta32x_priv), GFP_KERNEL); if (!sta32x) return -ENOMEM; mutex_init(&sta32x->coeff_lock); sta32x->pdata = dev_get_platdata(dev); #ifdef CONFIG_OF if (dev->of_node) { ret = sta32x_probe_dt(dev, sta32x); if (ret < 0) return ret; } #endif /* GPIOs */ sta32x->gpiod_nreset = devm_gpiod_get(dev, "reset"); if (IS_ERR(sta32x->gpiod_nreset)) { ret = PTR_ERR(sta32x->gpiod_nreset); if (ret != -ENOENT && ret != -ENOSYS) return ret; sta32x->gpiod_nreset = NULL; } else { gpiod_direction_output(sta32x->gpiod_nreset, 0); } /* regulators */ for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++) sta32x->supplies[i].supply = sta32x_supply_names[i]; ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(sta32x->supplies), sta32x->supplies); if (ret != 0) { dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); return ret; } sta32x->regmap = devm_regmap_init_i2c(i2c, &sta32x_regmap); if (IS_ERR(sta32x->regmap)) { ret = PTR_ERR(sta32x->regmap); dev_err(dev, "Failed to init regmap: %d\n", ret); return ret; } i2c_set_clientdata(i2c, sta32x); ret = snd_soc_register_codec(dev, &sta32x_codec, &sta32x_dai, 1); if (ret < 0) dev_err(dev, "Failed to register codec (%d)\n", ret); return ret; }
static int bh1770_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct bh1770_chip *chip; int err; chip = devm_kzalloc(&client->dev, sizeof *chip, GFP_KERNEL); if (!chip) return -ENOMEM; i2c_set_clientdata(client, chip); chip->client = client; mutex_init(&chip->mutex); init_waitqueue_head(&chip->wait); INIT_DELAYED_WORK(&chip->prox_work, bh1770_prox_work); if (client->dev.platform_data == NULL) { dev_err(&client->dev, "platform data is mandatory\n"); return -EINVAL; } chip->pdata = client->dev.platform_data; chip->lux_calib = BH1770_LUX_NEUTRAL_CALIB_VALUE; chip->lux_rate_index = BH1770_LUX_DEFAULT_RATE; chip->lux_threshold_lo = BH1770_LUX_DEF_THRES; chip->lux_threshold_hi = BH1770_LUX_DEF_THRES; if (chip->pdata->glass_attenuation == 0) chip->lux_ga = BH1770_NEUTRAL_GA; else chip->lux_ga = chip->pdata->glass_attenuation; chip->prox_threshold = BH1770_PROX_DEF_THRES; chip->prox_led = chip->pdata->led_def_curr; chip->prox_abs_thres = BH1770_PROX_DEF_ABS_THRES; chip->prox_persistence = BH1770_DEFAULT_PERSISTENCE; chip->prox_rate_threshold = BH1770_PROX_DEF_RATE_THRESH; chip->prox_rate = BH1770_PROX_DEFAULT_RATE; chip->prox_data = 0; chip->regs[0].supply = reg_vcc; chip->regs[1].supply = reg_vleds; err = devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(chip->regs), chip->regs); if (err < 0) { dev_err(&client->dev, "Cannot get regulators\n"); return err; } err = regulator_bulk_enable(ARRAY_SIZE(chip->regs), chip->regs); if (err < 0) { dev_err(&client->dev, "Cannot enable regulators\n"); return err; } usleep_range(BH1770_STARTUP_DELAY, BH1770_STARTUP_DELAY * 2); err = bh1770_detect(chip); if (err < 0) goto fail0; /* Start chip */ bh1770_chip_on(chip); pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); chip->lux_corr = bh1770_get_corr_value(chip); if (chip->lux_corr == 0) { dev_err(&client->dev, "Improper correction values\n"); err = -EINVAL; goto fail0; } if (chip->pdata->setup_resources) { err = chip->pdata->setup_resources(); if (err) { err = -EINVAL; goto fail0; } } err = sysfs_create_group(&chip->client->dev.kobj, &bh1770_attribute_group); if (err < 0) { dev_err(&chip->client->dev, "Sysfs registration failed\n"); goto fail1; } /* * Chip needs level triggered interrupt to work. However, * level triggering doesn't work always correctly with power * management. Select both */ err = request_threaded_irq(client->irq, NULL, bh1770_irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_TRIGGER_LOW, "bh1770", chip); if (err) { dev_err(&client->dev, "could not get IRQ %d\n", client->irq); goto fail2; } regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); return err; fail2: sysfs_remove_group(&chip->client->dev.kobj, &bh1770_attribute_group); fail1: if (chip->pdata->release_resources) chip->pdata->release_resources(); fail0: regulator_bulk_disable(ARRAY_SIZE(chip->regs), chip->regs); return err; }
static int stm32_usbphyc_probe(struct platform_device *pdev) { struct stm32_usbphyc *usbphyc; struct device *dev = &pdev->dev; struct device_node *child, *np = dev->of_node; struct resource *res; struct phy_provider *phy_provider; u32 version; int ret, port = 0; usbphyc = devm_kzalloc(dev, sizeof(*usbphyc), GFP_KERNEL); if (!usbphyc) return -ENOMEM; usbphyc->dev = dev; dev_set_drvdata(dev, usbphyc); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); usbphyc->base = devm_ioremap_resource(dev, res); if (IS_ERR(usbphyc->base)) return PTR_ERR(usbphyc->base); usbphyc->clk = devm_clk_get(dev, 0); if (IS_ERR(usbphyc->clk)) { ret = PTR_ERR(usbphyc->clk); dev_err(dev, "clk get failed: %d\n", ret); return ret; } ret = clk_prepare_enable(usbphyc->clk); if (ret) { dev_err(dev, "clk enable failed: %d\n", ret); return ret; } usbphyc->rst = devm_reset_control_get(dev, 0); if (!IS_ERR(usbphyc->rst)) { reset_control_assert(usbphyc->rst); udelay(2); reset_control_deassert(usbphyc->rst); } usbphyc->switch_setup = -EINVAL; usbphyc->nphys = of_get_child_count(np); usbphyc->phys = devm_kcalloc(dev, usbphyc->nphys, sizeof(*usbphyc->phys), GFP_KERNEL); if (!usbphyc->phys) { ret = -ENOMEM; goto clk_disable; } for_each_child_of_node(np, child) { struct stm32_usbphyc_phy *usbphyc_phy; struct phy *phy; u32 index; int i; phy = devm_phy_create(dev, child, &stm32_usbphyc_phy_ops); if (IS_ERR(phy)) { ret = PTR_ERR(phy); if (ret != -EPROBE_DEFER) dev_err(dev, "failed to create phy%d: %d\n", port, ret); goto put_child; } usbphyc_phy = devm_kzalloc(dev, sizeof(*usbphyc_phy), GFP_KERNEL); if (!usbphyc_phy) { ret = -ENOMEM; goto put_child; } for (i = 0; i < NUM_SUPPLIES; i++) usbphyc_phy->supplies[i].supply = supplies_names[i]; ret = devm_regulator_bulk_get(&phy->dev, NUM_SUPPLIES, usbphyc_phy->supplies); if (ret) { if (ret != -EPROBE_DEFER) dev_err(&phy->dev, "failed to get regulators: %d\n", ret); goto put_child; } ret = of_property_read_u32(child, "reg", &index); if (ret || index > usbphyc->nphys) { dev_err(&phy->dev, "invalid reg property: %d\n", ret); goto put_child; } usbphyc->phys[port] = usbphyc_phy; phy_set_bus_width(phy, 8); phy_set_drvdata(phy, usbphyc_phy); usbphyc->phys[port]->phy = phy; usbphyc->phys[port]->usbphyc = usbphyc; usbphyc->phys[port]->index = index; usbphyc->phys[port]->active = false; port++; } phy_provider = devm_of_phy_provider_register(dev, stm32_usbphyc_of_xlate); if (IS_ERR(phy_provider)) { ret = PTR_ERR(phy_provider); dev_err(dev, "failed to register phy provider: %d\n", ret); goto clk_disable; } version = readl_relaxed(usbphyc->base + STM32_USBPHYC_VERSION); dev_info(dev, "registered rev:%lu.%lu\n", FIELD_GET(MAJREV, version), FIELD_GET(MINREV, version)); return 0; put_child: of_node_put(child); clk_disable: clk_disable_unprepare(usbphyc->clk); return ret; }
static int msm_otg_probe(struct platform_device *pdev) { struct regulator_bulk_data regs[3]; int ret = 0; struct device_node *np = pdev->dev.of_node; struct msm_otg_platform_data *pdata; struct resource *res; struct msm_otg *motg; struct usb_phy *phy; void __iomem *phy_select; motg = devm_kzalloc(&pdev->dev, sizeof(struct msm_otg), GFP_KERNEL); if (!motg) { dev_err(&pdev->dev, "unable to allocate msm_otg\n"); return -ENOMEM; } pdata = dev_get_platdata(&pdev->dev); if (!pdata) { if (!np) return -ENXIO; ret = msm_otg_read_dt(pdev, motg); if (ret) return ret; } motg->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), GFP_KERNEL); if (!motg->phy.otg) { dev_err(&pdev->dev, "unable to allocate msm_otg\n"); return -ENOMEM; } phy = &motg->phy; phy->dev = &pdev->dev; motg->phy_reset_clk = devm_clk_get(&pdev->dev, np ? "phy" : "usb_phy_clk"); if (IS_ERR(motg->phy_reset_clk)) { dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); return PTR_ERR(motg->phy_reset_clk); } motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); if (IS_ERR(motg->clk)) { dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); return PTR_ERR(motg->clk); } /* * If USB Core is running its protocol engine based on CORE CLK, * CORE CLK must be running at >55Mhz for correct HSUSB * operation and USB core cannot tolerate frequency changes on * CORE CLK. */ motg->pclk = devm_clk_get(&pdev->dev, np ? "iface" : "usb_hs_pclk"); if (IS_ERR(motg->pclk)) { dev_err(&pdev->dev, "failed to get usb_hs_pclk\n"); return PTR_ERR(motg->pclk); } /* * USB core clock is not present on all MSM chips. This * clock is introduced to remove the dependency on AXI * bus frequency. */ motg->core_clk = devm_clk_get(&pdev->dev, np ? "alt_core" : "usb_hs_core_clk"); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); motg->regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(motg->regs)) return PTR_ERR(motg->regs); /* * NOTE: The PHYs can be multiplexed between the chipidea controller * and the dwc3 controller, using a single bit. It is important that * the dwc3 driver does not set this bit in an incompatible way. */ if (motg->phy_number) { phy_select = devm_ioremap_nocache(&pdev->dev, USB2_PHY_SEL, 4); if (IS_ERR(phy_select)) return PTR_ERR(phy_select); /* Enable second PHY with the OTG port */ writel(0x1, phy_select); } dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); motg->irq = platform_get_irq(pdev, 0); if (motg->irq < 0) { dev_err(&pdev->dev, "platform_get_irq failed\n"); return motg->irq; } regs[0].supply = "vddcx"; regs[1].supply = "v3p3"; regs[2].supply = "v1p8"; ret = devm_regulator_bulk_get(motg->phy.dev, ARRAY_SIZE(regs), regs); if (ret) return ret; motg->vddcx = regs[0].consumer; motg->v3p3 = regs[1].consumer; motg->v1p8 = regs[2].consumer; clk_set_rate(motg->clk, 60000000); clk_prepare_enable(motg->clk); clk_prepare_enable(motg->pclk); if (!IS_ERR(motg->core_clk)) clk_prepare_enable(motg->core_clk); ret = msm_hsusb_init_vddcx(motg, 1); if (ret) { dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); goto disable_clks; } ret = msm_hsusb_ldo_init(motg, 1); if (ret) { dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); goto disable_vddcx; } ret = msm_hsusb_ldo_set_mode(motg, 1); if (ret) { dev_err(&pdev->dev, "hsusb vreg enable failed\n"); goto disable_ldo; } writel(0, USB_USBINTR); writel(0, USB_OTGSC); INIT_WORK(&motg->sm_work, msm_otg_sm_work); INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work); ret = devm_request_irq(&pdev->dev, motg->irq, msm_otg_irq, IRQF_SHARED, "msm_otg", motg); if (ret) { dev_err(&pdev->dev, "request irq failed\n"); goto disable_ldo; } phy->init = msm_phy_init; phy->set_power = msm_otg_set_power; phy->notify_disconnect = msm_phy_notify_disconnect; phy->type = USB_PHY_TYPE_USB2; phy->io_ops = &msm_otg_io_ops; phy->otg->phy = &motg->phy; phy->otg->set_host = msm_otg_set_host; phy->otg->set_peripheral = msm_otg_set_peripheral; msm_usb_reset(phy); ret = usb_add_phy_dev(&motg->phy); if (ret) { dev_err(&pdev->dev, "usb_add_phy failed\n"); goto disable_ldo; } platform_set_drvdata(pdev, motg); device_init_wakeup(&pdev->dev, 1); if (motg->pdata->mode == USB_DR_MODE_OTG && motg->pdata->otg_control == OTG_USER_CONTROL) { ret = msm_otg_debugfs_init(motg); if (ret) dev_dbg(&pdev->dev, "Can not create mode change file\n"); } pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); return 0; disable_ldo: msm_hsusb_ldo_init(motg, 0); disable_vddcx: msm_hsusb_init_vddcx(motg, 0); disable_clks: clk_disable_unprepare(motg->pclk); clk_disable_unprepare(motg->clk); if (!IS_ERR(motg->core_clk)) clk_disable_unprepare(motg->core_clk); return ret; }
static int cs35l33_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { struct cs35l33_private *cs35l33; struct cs35l33_pdata *pdata = dev_get_platdata(&i2c_client->dev); int ret, devid, i; unsigned int reg; cs35l33 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs35l33_private), GFP_KERNEL); if (!cs35l33) return -ENOMEM; i2c_set_clientdata(i2c_client, cs35l33); cs35l33->regmap = devm_regmap_init_i2c(i2c_client, &cs35l33_regmap); if (IS_ERR(cs35l33->regmap)) { ret = PTR_ERR(cs35l33->regmap); dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); return ret; } regcache_cache_only(cs35l33->regmap, true); for (i = 0; i < ARRAY_SIZE(cs35l33_core_supplies); i++) cs35l33->core_supplies[i].supply = cs35l33_core_supplies[i]; cs35l33->num_core_supplies = ARRAY_SIZE(cs35l33_core_supplies); ret = devm_regulator_bulk_get(&i2c_client->dev, cs35l33->num_core_supplies, cs35l33->core_supplies); if (ret != 0) { dev_err(&i2c_client->dev, "Failed to request core supplies: %d\n", ret); return ret; } if (pdata) { cs35l33->pdata = *pdata; } else { cs35l33_of_get_pdata(&i2c_client->dev, cs35l33); pdata = &cs35l33->pdata; } ret = devm_request_threaded_irq(&i2c_client->dev, i2c_client->irq, NULL, cs35l33_irq_thread, IRQF_ONESHOT | IRQF_TRIGGER_LOW, "cs35l33", cs35l33); if (ret != 0) dev_warn(&i2c_client->dev, "Failed to request IRQ: %d\n", ret); /* We could issue !RST or skip it based on AMP topology */ cs35l33->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, "reset-gpios", GPIOD_OUT_HIGH); if (IS_ERR(cs35l33->reset_gpio)) { dev_err(&i2c_client->dev, "%s ERROR: Can't get reset GPIO\n", __func__); return PTR_ERR(cs35l33->reset_gpio); } ret = regulator_bulk_enable(cs35l33->num_core_supplies, cs35l33->core_supplies); if (ret != 0) { dev_err(&i2c_client->dev, "Failed to enable core supplies: %d\n", ret); return ret; } if (cs35l33->reset_gpio) gpiod_set_value_cansleep(cs35l33->reset_gpio, 1); msleep(CS35L33_BOOT_DELAY); regcache_cache_only(cs35l33->regmap, false); /* initialize codec */ ret = regmap_read(cs35l33->regmap, CS35L33_DEVID_AB, ®); devid = (reg & 0xFF) << 12; ret = regmap_read(cs35l33->regmap, CS35L33_DEVID_CD, ®); devid |= (reg & 0xFF) << 4; ret = regmap_read(cs35l33->regmap, CS35L33_DEVID_E, ®); devid |= (reg & 0xF0) >> 4; if (devid != CS35L33_CHIP_ID) { dev_err(&i2c_client->dev, "CS35L33 Device ID (%X). Expected ID %X\n", devid, CS35L33_CHIP_ID); goto err_enable; } ret = regmap_read(cs35l33->regmap, CS35L33_REV_ID, ®); if (ret < 0) { dev_err(&i2c_client->dev, "Get Revision ID failed\n"); goto err_enable; } dev_info(&i2c_client->dev, "Cirrus Logic CS35L33, Revision: %02X\n", reg & 0xFF); ret = regmap_register_patch(cs35l33->regmap, cs35l33_patch, ARRAY_SIZE(cs35l33_patch)); if (ret < 0) { dev_err(&i2c_client->dev, "Error in applying regmap patch: %d\n", ret); goto err_enable; } /* disable mclk and tdm */ regmap_update_bits(cs35l33->regmap, CS35L33_CLK_CTL, CS35L33_MCLKDIS | CS35L33_SDOUT_3ST_TDM, CS35L33_MCLKDIS | CS35L33_SDOUT_3ST_TDM); pm_runtime_set_autosuspend_delay(&i2c_client->dev, 100); pm_runtime_use_autosuspend(&i2c_client->dev); pm_runtime_set_active(&i2c_client->dev); pm_runtime_enable(&i2c_client->dev); ret = snd_soc_register_codec(&i2c_client->dev, &soc_codec_dev_cs35l33, &cs35l33_dai, 1); if (ret < 0) { dev_err(&i2c_client->dev, "%s: Register codec failed\n", __func__); goto err_enable; } return 0; err_enable: regulator_bulk_disable(cs35l33->num_core_supplies, cs35l33->core_supplies); return ret; }