static int max97236_probe(struct snd_soc_codec *codec)
{
	struct max97236_priv *max97236 = snd_soc_codec_get_drvdata(codec);
	unsigned int reg;
	int ret;

#ifdef MAX97236_AUTOMODE1_JACK_DETECTION
	dev_info(codec->dev, "built on %s at %s, mode is DETECT1\n",
		__DATE__,
		__TIME__);
#else
	dev_info(codec->dev, "built on %s at %s, mode is DETECT0\n",
		__DATE__,
		__TIME__);
#endif

	dev_info(codec->dev, "build number %s\n", MAX97236_REVISION);

	max97236->codec = codec;
	codec->control_data = max97236->regmap;
	codec->dapm.idle_bias_off = 1;
	codec->cache_sync = 1;
	max97236->jack_state = M97236_JACK_STATE_UNKNOWN;
	clk_cdev1 = clk_get_sys("extern1", NULL);

	ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
	if (ret != 0) {
		dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
		goto err_access;
	}

	/* Disable all interrupts until we're ready to handle them */
	regmap_write(max97236->regmap, M97236_REG_04_IRQ_MASK1, 0x00);
	regmap_write(max97236->regmap, M97236_REG_05_IRQ_MASK2, 0x00);
	regmap_write(max97236->regmap, M97236_REG_09_MICROPHONE,
		M97236_BIAS_MASK);
	regmap_write(max97236->regmap, M97236_REG_16_KEYSCAN_DELAY, 0x18);

	ret = regmap_read(max97236->regmap, M97236_REG_0B_REV_ID, &reg);
	if (ret < 0) {
		dev_err(codec->dev, "Cannot read device version: %d\n", ret);
		goto err_access;
	}

	reg >>= M97236_ID_SHIFT;
	dev_info(codec->dev, "MAX97236 Vendor ID = 0x%02x\n", reg);

	if (reg == M97236_REVA) {
		max97236->devtype = MAX97236;
	} else {
		dev_err(codec->dev, "Unrecognized device 0x%02X\n", reg);
		ret = -1;
		goto err_access;
	}

	/* configure clock divider registers */
	max97236_set_clk_dividers(max97236);

	dev_info(codec->dev, "gpio = %d\n", max97236->irq);
	/* Register for interrupts */
	if (max97236->irq) {
		ret = gpio_request(max97236->irq, "max97236_hs_irq");
		if (ret)
			dev_err(codec->dev, "failed to allocate gpio\n");

		gpio_direction_input(max97236->irq);
		/* register an audio interrupt */
		ret = request_threaded_irq(gpio_to_irq(max97236->irq), NULL,
					max97236_interrupt,
					IRQF_TRIGGER_FALLING,
					"max97236_interrupt", codec);
		if (ret)
			dev_err(codec->dev, "Failed to request IRQ: %d\n", ret);
	}

	max97236->ignore_int = 0;

	INIT_DELAYED_WORK(&max97236->jack_work, max97236_jack_work);
	wake_lock_init(&jack_key_lock , WAKE_LOCK_SUSPEND, "jack key wake lock" );

	/* Clear any interrupts then enable jack detection */
	regmap_read(max97236->regmap, M97236_REG_00_STATUS1,
			&reg);
	regmap_read(max97236->regmap, M97236_REG_01_STATUS2,
			&reg);
#ifdef MAX97236_AUTOMODE1_JACK_DETECTION
	max97236_configure_for_detection(max97236,
			M97236_AUTO_MODE_1);
#else
	max97236_configure_for_detection(max97236,
			M97236_AUTO_MODE_0);
#endif

	max97236_handle_pdata(codec);
	max97236_add_widgets(codec);
	wake_lock_init(&wakelock, WAKE_LOCK_SUSPEND, "headset detect");
	wake_lock_init(&wakelock_h, WAKE_LOCK_SUSPEND, "headset event detect");

err_access:
	return ret;
}
Exemple #2
0
static int max97236_probe(struct snd_soc_codec *codec)
{
	struct max97236_priv *max97236 = snd_soc_codec_get_drvdata(codec);
	struct max97236_pdata *pdata = max97236->pdata;
	unsigned int reg;
	int ret;

#ifdef MAX97236_AUTOMODE1_JACK_DETECTION
	dev_info(codec->dev, "built on %s at %s, mode is DETECT1\n",
		__DATE__,
		__TIME__);
#else
	dev_info(codec->dev, "built on %s at %s, mode is DETECT0\n",
		__DATE__,
		__TIME__);
#endif

	dev_info(codec->dev, "build number %s\n", MAX97236_REVISION);

	codec->cache_bypass = 1;
	max97236->codec = codec;
	codec->control_data = max97236->regmap;

	ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
	if (ret != 0) {
		dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
		goto err_access;
	}

	/* Disable all interrupts until we're ready to handle them */
	regmap_write(max97236->regmap, M97236_REG_04_IRQ_MASK1, 0x00);
	regmap_write(max97236->regmap, M97236_REG_05_IRQ_MASK2, 0x00);
	regmap_write(max97236->regmap, M97236_REG_09_MICROPHONE,
		M97236_BIAS_MASK);
	regmap_write(max97236->regmap, M97236_REG_16_KEYSCAN_DELAY, 0x18);

	ret = regmap_read(max97236->regmap, M97236_REG_0B_REV_ID, &reg);
	if (ret < 0) {
		dev_err(codec->dev, "Cannot read device version: %d\n", ret);
		goto err_access;
	}

	reg >>= M97236_ID_SHIFT;
	dev_info(codec->dev, "MAX97236 ID = 0x%02x\n", reg);

	if (reg == M97236_REVA) {
		max97236->devtype = MAX97236;
	} else {
		dev_err(codec->dev, "Unrecognized device 0x%02X\n", reg);
		ret = -1;
		goto err_access;
	}

	/* configure clock divider registers */
	max97236_set_clk_dividers(max97236, extclk_freq);

        if (gpio_is_valid(pdata->irq_gpio)) {
                ret = gpio_request(pdata->irq_gpio, "max97236_interrupt");
                if (ret) {
                        dev_err(codec->dev,
                                "%s: Failed to request max97236_interrupt GPIO, rc=%d\n",
                                __func__, ret);
                }

                ret = gpio_direction_input(pdata->irq_gpio);
                if (ret) {
                        dev_err(codec->dev,
                                "%s: Failed to configure max97236_interrupt GPIO, rc=%d\n",
                                __func__, ret);
			gpio_free(pdata->irq_gpio);
                }

                max97236->irq = gpio_to_irq(pdata->irq_gpio);
                dev_info(codec->dev,"Setting irq: GPIO %d -> irq %d\n",
                                 pdata->irq_gpio, max97236->irq);

	        if ((request_threaded_irq(max97236->irq, NULL, max97236_interrupt,
	        	IRQF_TRIGGER_FALLING|IRQF_ONESHOT, "max97236_interrupt", codec)) < 0) {
	        	dev_err(codec->dev, "request_irq failed\n");
	        	ret = -1;
	        	goto err_access;
	        }
        }

	max97236->ignore_int = 0;

	INIT_DELAYED_WORK(&max97236->jack_work, max97236_jack_work);

        if (pdata->vreg) {
                ret = regulator_set_voltage(pdata->vreg, 2850000, 2850000);
                if (ret) {
                         dev_err(codec->dev, "Setting regulator voltage failed for "
                                 "regulator err = %d\n", ret);
                 }

                 ret = regulator_set_optimum_mode(pdata->vreg, 150);
                 if (ret < 0) {
                         dev_err(codec->dev, "Setting regulator optimum mode failed for "
                                 "regulator err = %d\n", ret);
                 }

                 ret = regulator_enable(pdata->vreg);
                 if (ret) {
                           dev_err(codec->dev, "failed to enable supply err = %d\n", ret);
                 }
        }

	max97236_handle_pdata(codec);
	max97236_add_widgets(codec);

err_access:
	return ret;
}