static int max98505_i2c_probe(struct i2c_client *i2c_l, const struct i2c_device_id *id) { struct max98505_priv *max98505; int ret; pr_info("%s: enter, device '%s'\n", __func__, id->name); #ifdef SUPPORT_DEVICE_TREE max98505_regulator_config(i2c_l, of_property_read_bool(i2c_l->dev.of_node, "max98505,i2c-pull-up"), 1); #endif max98505 = kzalloc(sizeof(struct max98505_priv), GFP_KERNEL); if (max98505 == NULL) return -ENOMEM; max98505->devtype = id->driver_data; i2c_set_clientdata(i2c_l, max98505); max98505->control_data = i2c_l; max98505->pdata = i2c_l->dev.platform_data; max98505->regmap = regmap_init_i2c(i2c_l, &max98505_regmap); if (IS_ERR(max98505->regmap)) { ret = PTR_ERR(max98505->regmap); dev_err(&i2c_l->dev, "Failed to allocate regmap: %d\n", ret); goto err_out; } ret = snd_soc_register_codec(&i2c_l->dev, &soc_codec_dev_max98505, max98505_dai, ARRAY_SIZE(max98505_dai)); err_out: if (ret < 0) { if (max98505->regmap) regmap_exit(max98505->regmap); kfree(max98505); } dsm_misc_device_init(); pr_info("%s: ret %d\n", __func__, ret); return ret; }
static int max98505_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max98505_priv *max98505; struct max98505_pdata *pdata; int ret; int pinfo_status = 0; msg_maxim("enter, device '%s'", id->name); max98505 = devm_kzalloc(&i2c->dev, sizeof(struct max98505_priv), GFP_KERNEL); if (!max98505) { ret = -ENOMEM; goto err_allocate_priv; } max98505->pdata = devm_kzalloc(&i2c->dev, sizeof(struct max98505_pdata), GFP_KERNEL); if (!max98505->pdata) { ret = -ENOMEM; goto err_allocate_pdata; } i2c_set_clientdata(i2c, max98505); pdata = max98505->pdata; if (i2c->dev.of_node) { /* Read system clock */ ret = of_property_read_u32(i2c->dev.of_node, "maxim,sysclk", &pdata->sysclk); if (ret) { dev_err(&i2c->dev, "There is no sysclk property."); pdata->sysclk = 12288000; } /* Read speaker volume */ ret = of_property_read_u32(i2c->dev.of_node, "maxim,spk_vol", &pdata->spk_vol); if (ret) { dev_err(&i2c->dev, "There is no spk_vol property."); pdata->spk_vol = 0x14; } /* Read VMON slot info.*/ ret = of_property_read_u32(i2c->dev.of_node, "maxim,vmon_slot", &pdata->vmon_slot); if (ret) { dev_err(&i2c->dev, "There is no vmon_slot property."); pdata->vmon_slot = 0; } /* Regulator status */ pdata->i2c_pull_up = of_property_read_bool( i2c->dev.of_node, "maxim,i2c-pull-up"); if (pdata->i2c_pull_up) max98505_regulator_config(&i2c->dev); #ifdef USE_MAX98505_IRQ pdata->irq = of_get_named_gpio_flags( i2c->dev.of_node, "maxim,irq-gpio", 0, NULL); #endif /* USE_MAX98505_IRQ */ /* Read information related to DSM */ ret = of_property_read_u32_array(i2c->dev.of_node, "maxim,platform_info", (u32 *) &pdata->pinfo, sizeof(pdata->pinfo)/sizeof(uint32_t)); if (ret) dev_err(&i2c->dev, "There is no platform info. property.\n"); else pinfo_status = 1; ret = of_property_read_u32_array(i2c->dev.of_node, "maxim,boost_step", (uint32_t *) &pdata->vstep.boost_step, sizeof(pdata->vstep.boost_step)/sizeof(uint32_t)); if (ret) { dev_err(&i2c->dev, "There is no boost_step property.\n"); for (ret = 0; ret < MAX98505_VSTEP_14; ret++) pdata->vstep.boost_step[ret] = 0x0F; pdata->vstep.boost_step[MAX98505_VSTEP_14] = 0x02; pdata->vstep.boost_step[MAX98505_VSTEP_15] = 0x00; } ret = of_property_read_u32(i2c->dev.of_node, "maxim,adc_threshold", &pdata->vstep.adc_thres); if (ret) { dev_err(&i2c->dev, "There is no adc_threshold property."); pdata->vstep.adc_thres = MAX98505_VSTEP_7; } #ifdef USE_DSM_LOG ret = of_property_read_string(i2c->dev.of_node, "maxim,log_class", &class_name_log); if (ret) { dev_err(&i2c->dev, "There is no log_class property.\n"); class_name_log = DEFAULT_LOG_CLASS_NAME; } #endif /* USE_DSM_LOG */ } else { pdata->sysclk = 12288000; pdata->spk_vol = 0x14; pdata->vmon_slot = 0; } #ifdef USE_MAX98505_IRQ if (pdata != NULL && gpio_is_valid(pdata->irq)) { ret = gpio_request(pdata->irq, "max98505_irq_gpio"); if (ret) { dev_err(&i2c->dev, "unable to request gpio [%d]", pdata->irq); goto err_irq_gpio_req; } ret = gpio_direction_input(pdata->irq); if (ret) { dev_err(&i2c->dev, "unable to set direction for gpio [%d]", pdata->irq); goto err_irq_gpio_req; } i2c->irq = gpio_to_irq(pdata->irq); ret = request_threaded_irq(i2c->irq, NULL, max98505_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "max98505_interrupt", max98505); if (ret) dev_err(&i2c->dev, "Failed to register interrupt"); } else { dev_err(&i2c->dev, "irq gpio not provided\n"); } dev_dbg(&i2c->dev, "requested irq for max98505"); goto go_ahead_next_step; err_irq_gpio_req: if (gpio_is_valid(pdata->irq)) gpio_free(pdata->irq); go_ahead_next_step: #endif /* USE_MAX98505_IRQ */ #ifdef CONFIG_SND_SOC_MAXIM_DSM maxdsm_init(); if (pinfo_status) maxdsm_update_info(pdata->pinfo); #endif /* CONFIG_SND_SOC_MAXIM_DSM */ ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98505, max98505_dai, ARRAY_SIZE(max98505_dai)); if (ret) { dev_err(&i2c->dev, "Failed to register codec"); goto err_register_codec; } max98505->regmap = regmap_init_i2c(i2c, &max98505_regmap); if (IS_ERR(max98505->regmap)) { ret = PTR_ERR(max98505->regmap); dev_err(&i2c->dev, "Failed to initialize regmap: %d", ret); goto err_regmap; } msg_maxim("exit, device '%s'", id->name); return 0; err_regmap: snd_soc_unregister_codec(&i2c->dev); if (max98505->regmap) regmap_exit(max98505->regmap); err_register_codec: #ifdef CONFIG_SND_SOC_MAXIM_DSM maxdsm_deinit(); #endif /* CONFIG_SND_SOC_MAXIM_DSM */ devm_kfree(&i2c->dev, max98505->pdata); err_allocate_pdata: devm_kfree(&i2c->dev, max98505); err_allocate_priv: msg_maxim("exit with errors. ret=%d", ret); return ret; }