static int max98504_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max98504_priv *max98504; int ret; msg_maxim("\n"); #ifdef SUPPORT_DEVICE_TREE max98504_regulator_config(i2c, of_property_read_bool(i2c->dev.of_node, "max98504,i2c-pull-up"), 1); #endif max98504 = kzalloc(sizeof(struct max98504_priv), GFP_KERNEL); if (max98504 == NULL) return -ENOMEM; max98504->devtype = id->driver_data; i2c_set_clientdata(i2c, max98504); max98504->control_data = i2c; max98504->pdata = i2c->dev.platform_data; ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98504, max98504_dai, ARRAY_SIZE(max98504_dai)); msg_maxim("ret=%d\n", ret); if (ret < 0) kfree(max98504); return ret; }
static int __devinit max98504_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max98504_priv *max98504; struct max98504_pdata *pdata; int ret = 0; const char *of_class_name = DEFAULT_LOG_CLASS_NAME; #ifdef CONFIG_SND_SOC_MAXIM_DSM_A const char *class_name_log; #endif msg_maxim("\n"); max98504 = kzalloc(sizeof(struct max98504_priv), GFP_KERNEL); if (max98504 == NULL) return -ENOMEM; max98504->devtype = id->driver_data; i2c_set_clientdata(i2c, max98504); max98504->control_data = i2c; if (i2c->dev.of_node) { max98504->pdata = devm_kzalloc(&i2c->dev, sizeof(struct max98504_pdata), GFP_KERNEL); if (!max98504->pdata) { dev_err(&i2c->dev, "Failed to allocate memory\n"); return -ENOMEM; } else pdata = max98504->pdata; #ifdef USE_MAX98504_IRQ pdata->irq = of_get_named_gpio_flags(i2c->dev.of_node, "max98504,irq-gpio", 0, NULL); #endif ret = of_property_read_u32(i2c->dev.of_node, "max98504,rx_mode", &pdata->rx_mode); if (ret) { dev_err(&i2c->dev, "Failed to read rx_mode.\n"); return -EINVAL; } ret = of_property_read_u32(i2c->dev.of_node, "max98504,tx_mode", &pdata->tx_mode); if (ret) { dev_err(&i2c->dev, "Failed to read tx_mode.\n"); return -EINVAL; } ret = of_property_read_u32_array(i2c->dev.of_node, "max98504,cfg_data", (u32 *) &pdata->cfg_data, sizeof(struct max98504_cfg_data)/sizeof(u32)); if (ret) { dev_err(&i2c->dev, "Failed to read cfg_data.\n"); return -EINVAL; } #ifdef CONFIG_SND_SOC_MAXIM_DSM_A ret = of_property_read_string(i2c->dev.of_node, "max98504,log_class", &of_class_name); if (ret) { dev_err(&i2c->dev, "Failed to read log_class.\n"); of_class_name = DEFAULT_LOG_CLASS_NAME; } #endif msg_maxim("rx_mode:%d, tx_mode:%d, tx_dither_en:%d"\ ", rx_dither_en:%d, meas_dc_block_en:%d"\ ", rx_flt_mode:%d, rx_ch_en:%d\n", pdata->rx_mode, pdata->tx_mode, pdata->cfg_data.tx_dither_en, pdata->cfg_data.rx_dither_en, pdata->cfg_data.meas_dc_block_en, pdata->cfg_data.rx_flt_mode, pdata->cfg_data.rx_ch_en); msg_maxim("tx_ch_en:%d, tx_hiz_ch_en:%d"\ ", tx_ch_src:%d, auth_en:%d, wdog_time_out:%d\n", pdata->cfg_data.tx_ch_en, pdata->cfg_data.tx_hiz_ch_en, pdata->cfg_data.tx_ch_src, pdata->cfg_data.auth_en, pdata->cfg_data.wdog_time_out); } else { max98504->pdata = i2c->dev.platform_data; pdata = max98504->pdata; } max98504_regulator_config(i2c, of_property_read_bool(i2c->dev.of_node, "max98504,i2c-pull-up"), 1); max98504->regmap = regmap = regmap_init_i2c(i2c, &max98504_regmap); if (IS_ERR(max98504->regmap)) { ret = PTR_ERR(max98504->regmap); dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret); goto err_out; } max98504_probe(max98504); #ifdef CONFIG_SND_SOC_MAXIM_DSM_A class_name_log = of_class_name; max98504->dev_log_class = class_create(THIS_MODULE, class_name_log); if (max98504->dev_log_class == NULL) { pr_err("%s: class_create fail.\n", __func__); } else { max98504->dev_log = device_create(max98504->dev_log_class, NULL, 1, NULL, "max98504"); if (IS_ERR(max98504->dev_log)) { ret = sysfs_create_group(&i2c->dev.kobj, &max98504_attribute_group); if (ret) msg_maxim(\ "failed to create sysfs group [%d]", ret); } else { ret = sysfs_create_group(&max98504->dev_log->kobj, &max98504_attribute_group); if (ret) msg_maxim("failed to create sysfs group [%d]", ret); } } #endif #ifdef USE_MAX98504_IRQ if (pdata != NULL && gpio_is_valid(pdata->irq)) { ret = gpio_request(pdata->irq, "max98504_irq_gpio"); if (ret) { dev_err(&i2c->dev, "unable to request gpio [%d]\n", 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]\n", pdata->irq); goto err_irq_gpio_req; } i2c->irq = gpio_to_irq(pdata->irq); ret = request_threaded_irq(i2c->irq, NULL, max98504_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "max98504_interrupt", max98504); if (ret) dev_err(&i2c->dev, "Failed to register interrupt\n"); } else { dev_err(&i2c->dev, "irq gpio not provided\n"); } return 0; err_irq_gpio_req: if (gpio_is_valid(pdata->irq)) gpio_free(pdata->irq); return 0; #endif err_out: if (ret < 0) { if (max98504->regmap) regmap_exit(max98504->regmap); kfree(max98504); } return 0; }
static int __devinit max98504_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max98504_priv *max98504; struct max98504_pdata *pdata; int ret; msg_maxim("\n"); max98504 = kzalloc(sizeof(struct max98504_priv), GFP_KERNEL); if (max98504 == NULL) return -ENOMEM; max98504->devtype = id->driver_data; i2c_set_clientdata(i2c, max98504); max98504->control_data = i2c; if (i2c->dev.of_node) { max98504->pdata = devm_kzalloc(&i2c->dev, sizeof(struct max98504_pdata), GFP_KERNEL); if (!max98504->pdata) { dev_err(&i2c->dev, "Failed to allocate memory\n"); return -ENOMEM; } else pdata = max98504->pdata; #ifdef USE_MAX98504_IRQ pdata->irq = of_get_named_gpio_flags(i2c->dev.of_node, "max98504,irq-gpio", 0, NULL); #endif ret = of_property_read_u32(i2c->dev.of_node, "max98504,rx_mode", &pdata->rx_mode); if (ret) { dev_err(&i2c->dev, "Failed to read rx_mode.\n"); return -EINVAL; } ret = of_property_read_u32(i2c->dev.of_node, "max98504,tx_mode", &pdata->tx_mode); if (ret) { dev_err(&i2c->dev, "Failed to read tx_mode.\n"); return -EINVAL; } ret = of_property_read_u32_array(i2c->dev.of_node, "max98504,cfg_data", (u32*)&pdata->cfg_data, sizeof(struct max98504_cfg_data)/sizeof(u32)); if (ret) { dev_err(&i2c->dev, "Failed to read cfg_data.\n"); return -EINVAL; } msg_maxim("rx_mode:%d, tx_mode:%d, tx_dither_en:%d, rx_dither_en:%d, meas_dc_block_en:%d, rx_flt_mode:%d, rx_ch_en:%d\n", pdata->rx_mode, pdata->tx_mode, pdata->cfg_data.tx_dither_en, pdata->cfg_data.rx_dither_en, pdata->cfg_data.meas_dc_block_en, pdata->cfg_data.rx_flt_mode, pdata->cfg_data.rx_ch_en); msg_maxim("tx_ch_en:%d, tx_hiz_ch_en:%d, tx_ch_src:%d, auth_en:%d, wdog_time_out:%d\n", pdata->cfg_data.tx_ch_en, pdata->cfg_data.tx_hiz_ch_en, pdata->cfg_data.tx_ch_src, pdata->cfg_data.auth_en, pdata->cfg_data.wdog_time_out); } else max98504->pdata = i2c->dev.platform_data; max98504_regulator_config(i2c, of_property_read_bool(i2c->dev.of_node, "max98504,i2c-pull-up"), 1); max98504->regmap = regmap = regmap_init_i2c(i2c, &max98504_regmap); if (IS_ERR(max98504->regmap)) { ret = PTR_ERR(max98504->regmap); dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret); goto err_out; } max98504_probe(max98504); #ifdef USE_MAX98504_IRQ if (gpio_is_valid(pdata->irq)) { /* configure touchscreen irq gpio */ ret = gpio_request(pdata->irq, "max98504_irq_gpio"); if (ret) { dev_err(&i2c->dev, "unable to request gpio [%d]\n", 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]\n", pdata->irq); goto err_irq_gpio_req; } i2c->irq = gpio_to_irq(pdata->irq); } else { dev_err(&i2c->dev, "irq gpio not provided\n"); } ret = request_threaded_irq(i2c->irq, NULL, max98504_interrupt, IRQF_TRIGGER_FALLING, "max98504_interrupt", max98504); if (ret) { dev_err(&i2c->dev, "Failed to register interrupt\n"); } err_irq_gpio_req: if (gpio_is_valid(pdata->irq)) gpio_free(pdata->irq); #endif err_out: if (ret < 0) { if (max98504->regmap) regmap_exit(max98504->regmap); kfree(max98504); } return 0; }