Beispiel #1
0
static int max98925_i2c_probe(struct i2c_client *i2c_l,
			     const struct i2c_device_id *id)
{
	struct max98925_priv *max98925;
	int ret;

	msg_maxim("%s: enter, device '%s'\n", __func__, id->name);

	max98925 = kzalloc(sizeof(struct max98925_priv), GFP_KERNEL);
	if (max98925 == NULL)
		return -ENOMEM;

	max98925->devtype = id->driver_data;
	i2c_set_clientdata(i2c_l, max98925);
	max98925->control_data = i2c_l;
	max98925->pdata = i2c_l->dev.platform_data;

	max98925->regmap = regmap_init_i2c(i2c_l, &max98925_regmap);
	if (IS_ERR(max98925->regmap)) {
		ret = PTR_ERR(max98925->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_max98925,
			max98925_dai, ARRAY_SIZE(max98925_dai));

err_out:

	if (ret < 0) {
		if (max98925->regmap)
			regmap_exit(max98925->regmap);
		kfree(max98925);
	}

#ifdef CONFIG_SND_SOC_MAXIM_DSM
	maxdsm_init();
#endif

	msg_maxim("%s: ret %d\n", __func__, ret);

	return ret;
}
static int max98506_i2c_probe(struct i2c_client *i2c,
			     const struct i2c_device_id *id)
{
	struct max98506_priv *max98506;
	struct max98506_pdata *pdata;
	struct max98506_volume_step_info *vstep;
	int ret;
	int pinfo_status = 0;

	msg_maxim("enter, device '%s'", id->name);

	max98506 = devm_kzalloc(&i2c->dev,
			sizeof(struct max98506_priv), GFP_KERNEL);
	if (!max98506) {
		ret = -ENOMEM;
		goto err_allocate_priv;
	}

	max98506->pdata = devm_kzalloc(&i2c->dev,
			sizeof(struct max98506_pdata), GFP_KERNEL);
	if (!max98506->pdata) {
		ret = -ENOMEM;
		goto err_allocate_pdata;
	}

	i2c_set_clientdata(i2c, max98506);
	pdata = max98506->pdata;
	vstep = &max98506->vstep;

	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-gain", &pdata->spk_gain);
		if (ret) {
			dev_err(&i2c->dev, "There is no spk_gain property.");
			pdata->spk_gain = 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)
			max98506_regulator_config(&i2c->dev);

#ifdef USE_MAX98506_IRQ
		pdata->irq = of_get_named_gpio_flags(
				i2c->dev.of_node, "maxim,irq-gpio", 0, NULL);
#endif /* USE_MAX98506_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 *) &vstep->boost_step,
			sizeof(vstep->boost_step)/sizeof(uint32_t));
		if (ret) {
			dev_err(&i2c->dev, "There is no boost_step property.\n");
			for (ret = 0; ret < MAX98506_VSTEP_14; ret++)
				vstep->boost_step[ret] = 0x0F;
			vstep->boost_step[MAX98506_VSTEP_14] = 0x02;
			vstep->boost_step[MAX98506_VSTEP_15] = 0x00;
		}

		ret = of_property_read_u32(i2c->dev.of_node,
				"maxim,adc_threshold", &vstep->adc_thres);
		if (ret) {
			dev_err(&i2c->dev, "There is no adc_threshold property.");
			vstep->adc_thres = MAX98506_VSTEP_7;
		}

		pdata->reg_arr = of_get_property(i2c->dev.of_node,
				"maxim,registers-of-amp", &pdata->reg_arr_len);
		if (pdata->reg_arr == NULL)
			dev_err(&i2c->dev, "There is no registers-diff property.");

#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_gain = 0x14;
		pdata->vmon_slot = 0;
	}

#ifdef USE_MAX98506_IRQ
	if (pdata != NULL && gpio_is_valid(pdata->irq)) {
		ret = gpio_request(pdata->irq, "max98506_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, max98506_interrupt,
				IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
				"max98506_interrupt", max98506);
		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 max98506");
	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_MAX98506_IRQ */

#ifdef CONFIG_SND_SOC_MAXIM_DSM
	maxdsm_init();
	if (pinfo_status)
#ifdef CONFIG_MACH_KACTIVELTE_KOR
		maxdsm_update_info(pdata->pinfo);
#else
		dev_info(&i2c->dev, "pinfo will be ignored.\n");
#endif /* CONFIG_MACH_KACTIVELTE_KOR */
#endif /* CONFIG_SND_SOC_MAXIM_DSM */

	ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98506,
			max98506_dai, ARRAY_SIZE(max98506_dai));
	if (ret) {
		dev_err(&i2c->dev, "Failed to register codec");
		goto err_register_codec;
	}

	max98506->regmap = regmap_init_i2c(i2c, &max98506_regmap);
	if (IS_ERR(max98506->regmap)) {
		ret = PTR_ERR(max98506->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 (max98506->regmap)
		regmap_exit(max98506->regmap);

err_register_codec:
#ifdef CONFIG_SND_SOC_MAXIM_DSM
	maxdsm_deinit();
#endif /* CONFIG_SND_SOC_MAXIM_DSM */
	devm_kfree(&i2c->dev, max98506->pdata);

err_allocate_pdata:
	devm_kfree(&i2c->dev, max98506);

err_allocate_priv:
	msg_maxim("exit with errors. ret=%d", ret);

	return ret;
}