コード例 #1
0
ファイル: vf610_adc.c プロジェクト: 020gzh/linux
static int vf610_set_conversion_mode(struct iio_dev *indio_dev,
				     const struct iio_chan_spec *chan,
				     unsigned int mode)
{
	struct vf610_adc *info = iio_priv(indio_dev);

	mutex_lock(&indio_dev->mlock);
	info->adc_feature.conv_mode = mode;
	vf610_adc_calculate_rates(info);
	vf610_adc_hw_init(info);
	mutex_unlock(&indio_dev->mlock);

	return 0;
}
コード例 #2
0
ファイル: vf610_adc.c プロジェクト: stevezilla/dplive-linux
static int vf610_adc_resume(struct device *dev)
{
    struct iio_dev *indio_dev = dev_get_drvdata(dev);
    struct vf610_adc *info = iio_priv(indio_dev);
    int ret;

    ret = regulator_enable(info->vref);
    if (ret)
        return ret;

    ret = clk_prepare_enable(info->clk);
    if (ret)
        return ret;

    vf610_adc_hw_init(info);

    return 0;
}
コード例 #3
0
ファイル: vf610_adc.c プロジェクト: 020gzh/linux
static int vf610_adc_probe(struct platform_device *pdev)
{
	struct vf610_adc *info;
	struct iio_dev *indio_dev;
	struct resource *mem;
	int irq;
	int ret;

	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc));
	if (!indio_dev) {
		dev_err(&pdev->dev, "Failed allocating iio device\n");
		return -ENOMEM;
	}

	info = iio_priv(indio_dev);
	info->dev = &pdev->dev;

	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	info->regs = devm_ioremap_resource(&pdev->dev, mem);
	if (IS_ERR(info->regs))
		return PTR_ERR(info->regs);

	irq = platform_get_irq(pdev, 0);
	if (irq < 0) {
		dev_err(&pdev->dev, "no irq resource?\n");
		return irq;
	}

	ret = devm_request_irq(info->dev, irq,
				vf610_adc_isr, 0,
				dev_name(&pdev->dev), indio_dev);
	if (ret < 0) {
		dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
		return ret;
	}

	info->clk = devm_clk_get(&pdev->dev, "adc");
	if (IS_ERR(info->clk)) {
		dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
						PTR_ERR(info->clk));
		return PTR_ERR(info->clk);
	}

	info->vref = devm_regulator_get(&pdev->dev, "vref");
	if (IS_ERR(info->vref))
		return PTR_ERR(info->vref);

	ret = regulator_enable(info->vref);
	if (ret)
		return ret;

	info->vref_uv = regulator_get_voltage(info->vref);

	of_property_read_u32_array(pdev->dev.of_node, "fsl,adck-max-frequency",
			info->max_adck_rate, 3);

	ret = of_property_read_u32(pdev->dev.of_node, "min-sample-time",
			&info->adc_feature.default_sample_time);
	if (ret)
		info->adc_feature.default_sample_time = DEFAULT_SAMPLE_TIME;

	platform_set_drvdata(pdev, indio_dev);

	init_completion(&info->completion);

	indio_dev->name = dev_name(&pdev->dev);
	indio_dev->dev.parent = &pdev->dev;
	indio_dev->dev.of_node = pdev->dev.of_node;
	indio_dev->info = &vf610_adc_iio_info;
	indio_dev->modes = INDIO_DIRECT_MODE;
	indio_dev->channels = vf610_adc_iio_channels;
	indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels);

	ret = clk_prepare_enable(info->clk);
	if (ret) {
		dev_err(&pdev->dev,
			"Could not prepare or enable the clock.\n");
		goto error_adc_clk_enable;
	}

	vf610_adc_cfg_init(info);
	vf610_adc_hw_init(info);

	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
					NULL, &iio_triggered_buffer_setup_ops);
	if (ret < 0) {
		dev_err(&pdev->dev, "Couldn't initialise the buffer\n");
		goto error_iio_device_register;
	}

	ret = iio_device_register(indio_dev);
	if (ret) {
		dev_err(&pdev->dev, "Couldn't register the device.\n");
		goto error_adc_buffer_init;
	}

	return 0;

error_adc_buffer_init:
	iio_triggered_buffer_cleanup(indio_dev);
error_iio_device_register:
	clk_disable_unprepare(info->clk);
error_adc_clk_enable:
	regulator_disable(info->vref);

	return ret;
}
コード例 #4
0
ファイル: vf610_adc.c プロジェクト: stevezilla/dplive-linux
static int vf610_adc_probe(struct platform_device *pdev)
{
    struct vf610_adc *info;
    struct iio_dev *indio_dev;
    struct resource *mem;
    int irq;
    int ret;
    u32 channels;

    indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc));
    if (!indio_dev) {
        dev_err(&pdev->dev, "Failed allocating iio device\n");
        return -ENOMEM;
    }

    info = iio_priv(indio_dev);
    info->dev = &pdev->dev;

    mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    info->regs = devm_ioremap_resource(&pdev->dev, mem);
    if (IS_ERR(info->regs))
        return PTR_ERR(info->regs);

    irq = platform_get_irq(pdev, 0);
    if (irq <= 0) {
        dev_err(&pdev->dev, "no irq resource?\n");
        return -EINVAL;
    }

    ret = devm_request_irq(info->dev, irq,
                           vf610_adc_isr, 0,
                           dev_name(&pdev->dev), info);
    if (ret < 0) {
        dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
        return ret;
    }

    info->clk = devm_clk_get(&pdev->dev, "adc");
    if (IS_ERR(info->clk)) {
        dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
                PTR_ERR(info->clk));
        ret = PTR_ERR(info->clk);
        return ret;
    }

    info->vref = devm_regulator_get(&pdev->dev, "vref");
    if (IS_ERR(info->vref))
        return PTR_ERR(info->vref);

    ret = regulator_enable(info->vref);
    if (ret)
        return ret;

    info->vref_uv = regulator_get_voltage(info->vref);

    platform_set_drvdata(pdev, indio_dev);

    init_completion(&info->completion);

    ret  = of_property_read_u32(pdev->dev.of_node,
                                "num-channels", &channels);
    if (ret)
        channels = ARRAY_SIZE(vf610_adc_iio_channels);

    indio_dev->name = dev_name(&pdev->dev);
    indio_dev->dev.parent = &pdev->dev;
    indio_dev->dev.of_node = pdev->dev.of_node;
    indio_dev->info = &vf610_adc_iio_info;
    indio_dev->modes = INDIO_DIRECT_MODE;
    indio_dev->channels = vf610_adc_iio_channels;
    indio_dev->num_channels = (int)channels;

    ret = clk_prepare_enable(info->clk);
    if (ret) {
        dev_err(&pdev->dev,
                "Could not prepare or enable the clock.\n");
        goto error_adc_clk_enable;
    }

    vf610_adc_cfg_init(info);
    vf610_adc_hw_init(info);

    ret = iio_device_register(indio_dev);
    if (ret) {
        dev_err(&pdev->dev, "Couldn't register the device.\n");
        goto error_iio_device_register;
    }

    return 0;


error_iio_device_register:
    clk_disable_unprepare(info->clk);
error_adc_clk_enable:
    regulator_disable(info->vref);

    return ret;
}