static int __devinit ad9910_probe(struct spi_device *spi) { struct ad9910_state *st; int ret = 0; st = kzalloc(sizeof(*st), GFP_KERNEL); if (st == NULL) { ret = -ENOMEM; goto error_ret; } spi_set_drvdata(spi, st); mutex_init(&st->lock); st->sdev = spi; st->idev = iio_allocate_device(0); if (st->idev == NULL) { ret = -ENOMEM; goto error_free_st; } st->idev->dev.parent = &spi->dev; st->idev->info = &ad9910_info; st->idev->dev_data = (void *)(st); st->idev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(st->idev); if (ret) goto error_free_dev; spi->max_speed_hz = 2000000; spi->mode = SPI_MODE_3; spi->bits_per_word = 8; spi_setup(spi); ad9910_init(st); return 0; error_free_dev: iio_free_device(st->idev); error_free_st: kfree(st); error_ret: return ret; }
static int hmc5843_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct hmc5843_data *data; int err = 0; data = kzalloc(sizeof(struct hmc5843_data), GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; } /* default settings at probe */ data->meas_conf = CONF_NORMAL; data->range = RANGE_1_0; data->operating_mode = MODE_CONVERSION_CONTINUOUS; i2c_set_clientdata(client, data); /* Initialize the HMC5843 chip */ hmc5843_init_client(client); data->indio_dev = iio_allocate_device(0); if (!data->indio_dev) { err = -ENOMEM; goto exit_free1; } data->indio_dev->info = &hmc5843_info; data->indio_dev->dev.parent = &client->dev; data->indio_dev->dev_data = (void *)(data); data->indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(data->indio_dev); if (err) goto exit_free2; return 0; exit_free2: iio_free_device(data->indio_dev); exit_free1: kfree(data); exit: return err; }
static int yas_remove(struct i2c_client *i2c) { struct iio_dev *indio_dev = i2c_get_clientdata(i2c); struct yas_state *st; if (indio_dev) { st = iio_priv(indio_dev); #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&st->sus); #endif yas_pseudo_irq_disable(indio_dev); st->mag.term(); iio_device_unregister(indio_dev); yas_remove_trigger(indio_dev); yas_remove_buffer(indio_dev); iio_free_device(indio_dev); this_client = NULL; } return 0; }
static int __devinit ad7152_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = 0; struct ad7152_chip_info *chip; struct iio_dev *indio_dev; indio_dev = iio_allocate_device(sizeof(*chip)); if (indio_dev == NULL) { ret = -ENOMEM; goto error_ret; } chip = iio_priv(indio_dev); /* this is only used for device removal purposes */ i2c_set_clientdata(client, indio_dev); chip->client = client; /* Establish that the iio_dev is a child of the i2c device */ indio_dev->name = id->name; indio_dev->dev.parent = &client->dev; indio_dev->info = &ad7152_info; indio_dev->channels = ad7152_channels; if (id->driver_data == 0) indio_dev->num_channels = ARRAY_SIZE(ad7152_channels); else indio_dev->num_channels = 2; indio_dev->num_channels = ARRAY_SIZE(ad7152_channels); indio_dev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(indio_dev); if (ret) goto error_free_dev; dev_err(&client->dev, "%s capacitive sensor registered\n", id->name); return 0; error_free_dev: iio_free_device(indio_dev); error_ret: return ret; }
static int __devinit adis16080_probe(struct spi_device *spi) { int ret, regdone = 0; struct adis16080_state *st; struct iio_dev *indio_dev; /* setup the industrialio driver allocated elements */ indio_dev = iio_allocate_device(sizeof(*st)); if (indio_dev == NULL) { ret = -ENOMEM; goto error_ret; } st = iio_priv(indio_dev); /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); /* Allocate the comms buffers */ st->us = spi; mutex_init(&st->buf_lock); indio_dev->name = spi->dev.driver->name; indio_dev->dev.parent = &spi->dev; indio_dev->info = &adis16080_info; indio_dev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(indio_dev); if (ret) goto error_free_dev; regdone = 1; return 0; error_free_dev: if (regdone) iio_device_unregister(indio_dev); else iio_free_device(indio_dev); error_ret: return ret; }
static int hmc5843_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct hmc5843_data *data; struct iio_dev *indio_dev; int err = 0; indio_dev = iio_allocate_device(sizeof(*data)); if (indio_dev == NULL) { err = -ENOMEM; goto exit; } data = iio_priv(indio_dev); /* default settings at probe */ data->meas_conf = CONF_NORMAL; data->range = RANGE_1_0; data->operating_mode = MODE_CONVERSION_CONTINUOUS; i2c_set_clientdata(client, indio_dev); /* Initialize the HMC5843 chip */ hmc5843_init_client(client); indio_dev->info = &hmc5843_info; indio_dev->name = id->name; indio_dev->channels = hmc5843_channels; indio_dev->num_channels = ARRAY_SIZE(hmc5843_channels); indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(indio_dev); if (err) goto exit_free2; return 0; exit_free2: iio_free_device(indio_dev); exit: return err; }
static int __devinit adis16130_probe(struct spi_device *spi) { int ret; struct adis16130_state *st = kzalloc(sizeof *st, GFP_KERNEL); if (!st) { ret = -ENOMEM; goto error_ret; } /* this is only used for removal purposes */ spi_set_drvdata(spi, st); st->us = spi; mutex_init(&st->buf_lock); /* setup the industrialio driver allocated elements */ st->indio_dev = iio_allocate_device(); if (st->indio_dev == NULL) { ret = -ENOMEM; goto error_free_st; } st->indio_dev->dev.parent = &spi->dev; st->indio_dev->attrs = &adis16130_attribute_group; st->indio_dev->dev_data = (void *)(st); st->indio_dev->driver_module = THIS_MODULE; st->indio_dev->modes = INDIO_DIRECT_MODE; st->mode = 1; ret = iio_device_register(st->indio_dev); if (ret) goto error_free_dev; return 0; error_free_dev: iio_free_device(st->indio_dev); error_free_st: kfree(st); error_ret: return ret; }
static int __devinit ad9852_probe(struct spi_device *spi) { struct ad9852_state *st; struct iio_dev *idev; int ret = 0; idev = iio_allocate_device(sizeof(*st)); if (idev == NULL) { ret = -ENOMEM; goto error_ret; } st = iio_priv(idev); spi_set_drvdata(spi, idev); mutex_init(&st->lock); st->sdev = spi; idev->dev.parent = &spi->dev; idev->info = &ad9852_info; idev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(idev); if (ret) goto error_free_dev; spi->max_speed_hz = 2000000; spi->mode = SPI_MODE_3; spi->bits_per_word = 8; spi_setup(spi); ad9852_init(st); return 0; error_free_dev: iio_free_device(idev); error_ret: return ret; }
static int __devinit lpc32xx_adc_probe(struct platform_device *pdev) { struct lpc32xx_adc_info *info = NULL; struct resource *res; int retval = -ENODEV; struct iio_dev *iodev = NULL; int irq; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "failed to get platform I/O memory\n"); retval = -EBUSY; goto errout1; } iodev = iio_allocate_device(sizeof(struct lpc32xx_adc_info)); if (!iodev) { dev_err(&pdev->dev, "failed allocating iio device\n"); retval = -ENOMEM; goto errout1; } info = iio_priv(iodev); info->adc_base = ioremap(res->start, res->end - res->start + 1); if (!info->adc_base) { dev_err(&pdev->dev, "failed mapping memory\n"); retval = -EBUSY; goto errout2; } info->clk = clk_get(&pdev->dev, NULL); if (IS_ERR(info->clk)) { dev_err(&pdev->dev, "failed getting clock\n"); goto errout3; } irq = platform_get_irq(pdev, 0); if ((irq < 0) || (irq >= NR_IRQS)) { dev_err(&pdev->dev, "failed getting interrupt resource\n"); retval = -EINVAL; goto errout4; } retval = request_irq(irq, lpc32xx_adc_isr, 0, MOD_NAME, info); if (retval < 0) { dev_err(&pdev->dev, "failed requesting interrupt\n"); goto errout4; } platform_set_drvdata(pdev, iodev); init_completion(&info->completion); iodev->name = MOD_NAME; iodev->dev.parent = &pdev->dev; iodev->info = &lpc32xx_adc_iio_info; iodev->modes = INDIO_DIRECT_MODE; iodev->channels = lpc32xx_adc_iio_channels; iodev->num_channels = ARRAY_SIZE(lpc32xx_adc_iio_channels); retval = iio_device_register(iodev); if (retval) goto errout5; dev_info(&pdev->dev, "LPC32XX ADC driver loaded, IRQ %d\n", irq); return 0; errout5: free_irq(irq, iodev); errout4: clk_put(info->clk); errout3: iounmap(info->adc_base); errout2: iio_free_device(iodev); errout1: return retval; }
static int __devinit max77660_adc_probe(struct platform_device *pdev) { struct max77660_adc *adc; struct max77660_platform_data *pdata; struct max77660_adc_platform_data *adc_pdata; struct iio_dev *iodev; int ret; pdata = dev_get_platdata(pdev->dev.parent); if (!pdata || !pdata->adc_pdata) { dev_err(&pdev->dev, "No platform data\n"); return -ENODEV; } adc_pdata = pdata->adc_pdata; iodev = iio_allocate_device(sizeof(*adc)); if (!iodev) { dev_err(&pdev->dev, "iio_device_alloc failed\n"); return -ENOMEM; } adc = iio_priv(iodev); adc->dev = &pdev->dev; adc->parent = pdev->dev.parent; adc->adc_info = max77660_adc_info; init_completion(&adc->conv_completion); dev_set_drvdata(&pdev->dev, iodev); adc->irq = platform_get_irq(pdev, 0); ret = request_threaded_irq(adc->irq, NULL, max77660_adc_irq, IRQF_ONESHOT | IRQF_EARLY_RESUME, dev_name(adc->dev), adc); if (ret < 0) { dev_err(adc->dev, "request irq %d failed: %dn", adc->irq, ret); goto out; } if (adc_pdata->adc_ref_enabled) adc->adc_control |= MAX77660_ADCCTRL_ADCREFEN; if (adc_pdata->adc_avg_sample <= 1) adc->adc_control |= MAX77660_ADCCTRL_ADCAVG(0); else if (adc_pdata->adc_avg_sample <= 2) adc->adc_control |= MAX77660_ADCCTRL_ADCAVG(1); else if (adc_pdata->adc_avg_sample <= 16) adc->adc_control |= MAX77660_ADCCTRL_ADCAVG(2); else adc->adc_control |= MAX77660_ADCCTRL_ADCAVG(3); if (adc_pdata->adc_current_uA == 0) adc->iadc_val = 0; else if (adc_pdata->adc_current_uA <= 10) adc->iadc_val = 1; else if (adc_pdata->adc_current_uA <= 50) adc->iadc_val = 2; else adc->iadc_val = 3; iodev->name = MOD_NAME; iodev->dev.parent = &pdev->dev; iodev->info = &max77660_adc_iio_info; iodev->modes = INDIO_DIRECT_MODE; iodev->channels = max77660_adc_iio_channel; iodev->num_channels = ARRAY_SIZE(max77660_adc_iio_channel); ret = iio_device_register(iodev); if (ret < 0) { dev_err(adc->dev, "iio_device_register() failed: %d\n", ret); goto out_irq_free; } if (adc_pdata->channel_mapping) { ret = iio_map_array_register(iodev, adc_pdata->channel_mapping); if (ret < 0) { dev_err(adc->dev, "iio_map_array_register() failed: %d\n", ret); goto out_irq_free; } } device_set_wakeup_capable(&pdev->dev, 1); if (adc_pdata->adc_wakeup_data) { memcpy(&adc->adc_wake_props, adc_pdata->adc_wakeup_data, sizeof(struct max77660_adc_wakeup_property)); adc->wakeup_props_available = true; device_wakeup_enable(&pdev->dev); } return 0; out_irq_free: free_irq(adc->irq, adc); out: iio_free_device(iodev); return ret; }
static int __devinit isl29028_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl29028_chip *chip; struct iio_dev *indio_dev; struct regulator *isl_reg = regulator_get(&client->dev, "vdd"); int err; dev_dbg(&client->dev, "%s() called\n", __func__); if (IS_ERR_OR_NULL(isl_reg)) { dev_info(&client->dev, "no regulator found," \ "continue without regulator\n"); isl_reg = NULL; } indio_dev = iio_allocate_device(sizeof(*chip)); if (indio_dev == NULL) { dev_err(&client->dev, "iio allocation fails\n"); err = -ENOMEM; goto exit; } chip = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); chip->client = client; chip->irq = client->irq; chip->isl_reg = isl_reg; mutex_init(&chip->lock); err = isl29028_chip_init(client); if (err) goto exit_iio_free; init_completion(&chip->prox_completion); init_completion(&chip->als_completion); if (chip->irq > 0) { err = request_threaded_irq(chip->irq, NULL, threshold_isr, IRQF_SHARED, "ISL29028", chip); if (err) { dev_err(&client->dev, "Unable to register irq %d; " "error %d\n", chip->irq, err); goto exit_iio_free; } chip->is_int_enable = true; } indio_dev->info = &isl29028_info; indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(indio_dev); if (err) { dev_err(&client->dev, "iio registration fails\n"); goto exit_irq; } dev_dbg(&client->dev, "%s() success\n", __func__); return 0; exit_irq: if (chip->irq > 0) free_irq(chip->irq, chip); exit_iio_free: if (chip->isl_reg) regulator_put(chip->isl_reg); iio_free_device(indio_dev); exit: return err; }
static int yas_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct yas_state *st; struct iio_dev *indio_dev; struct yas53x_platform_data *pdata; int ret; D("%s", __func__); this_client = i2c; indio_dev = iio_allocate_device(sizeof(*st)); if (!indio_dev) { ret = -ENOMEM; goto error_ret; } i2c_set_clientdata(i2c, indio_dev); indio_dev->name = YAS_MAG_NAME; indio_dev->dev.parent = &i2c->dev; indio_dev->info = &yas_info; indio_dev->channels = yas_channels; indio_dev->num_channels = ARRAY_SIZE(yas_channels); indio_dev->modes = INDIO_DIRECT_MODE; printk("YAMAHA id->name[%s]\n", id->name); st = iio_priv(indio_dev); st->client = i2c; st->sampling_frequency = 20; st->mag.callback.device_open = yas_device_open; st->mag.callback.device_close = yas_device_close; st->mag.callback.device_read = yas_device_read; st->mag.callback.device_write = yas_device_write; st->mag.callback.usleep = yas_usleep; st->mag.callback.current_time = yas_current_time; INIT_DELAYED_WORK(&st->work, yas_work_func); mutex_init(&st->lock); #ifdef CONFIG_HAS_EARLYSUSPEND st->sus.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; st->sus.suspend = yas_early_suspend; st->sus.resume = yas_late_resume; register_early_suspend(&st->sus); #endif ret = yas_probe_buffer(indio_dev); if (ret) goto error_free_dev; ret = yas_probe_trigger(indio_dev); if (ret) goto error_remove_buffer; ret = iio_device_register(indio_dev); if (ret) goto error_remove_trigger; ret = yas_mag_driver_init(&st->mag); if (ret < 0) { ret = -EFAULT; goto error_unregister_iio; } ret = st->mag.init(); if (ret < 0) { ret = -EFAULT; goto error_unregister_iio; } ret = st->mag.set_enable(1); if (ret < 0) { ret = -EFAULT; goto error_driver_term; } pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); if (pdata == NULL) { D("%s: memory allocation for pdata failed.", __func__); } else { yas53x_parse_dt(&i2c->dev , pdata); } mutex_lock(&st->lock); if (pdata->chip_layout<8 && pdata->chip_layout>=0) { ret = st->mag.set_position(pdata->chip_layout); D("%s: set position to %d\n", __func__, pdata->chip_layout); } else { ret = st->mag.set_position(5); D("%s: set default position: 5\n", __func__); } mutex_unlock(&st->lock); return 0; error_driver_term: st->mag.term(); error_unregister_iio: iio_device_unregister(indio_dev); error_remove_trigger: yas_remove_trigger(indio_dev); error_remove_buffer: yas_remove_buffer(indio_dev); error_free_dev: #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&st->sus); #endif iio_free_device(indio_dev); error_ret: i2c_set_clientdata(i2c, NULL); this_client = NULL; return ret; }
static int __devinit ad7298_probe(struct spi_device *spi) { struct ad7298_platform_data *pdata = spi->dev.platform_data; struct ad7298_state *st; int ret, regdone = 0; struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); if (indio_dev == NULL) return -ENOMEM; st = iio_priv(indio_dev); st->reg = regulator_get(&spi->dev, "vcc"); if (!IS_ERR(st->reg)) { ret = regulator_enable(st->reg); if (ret) goto error_put_reg; } spi_set_drvdata(spi, indio_dev); st->spi = spi; indio_dev->name = spi_get_device_id(spi)->name; indio_dev->dev.parent = &spi->dev; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = ad7298_channels; indio_dev->num_channels = ARRAY_SIZE(ad7298_channels); indio_dev->info = &ad7298_info; /* Setup default message */ st->scan_single_xfer[0].tx_buf = &st->tx_buf[0]; st->scan_single_xfer[0].len = 2; st->scan_single_xfer[0].cs_change = 1; st->scan_single_xfer[1].tx_buf = &st->tx_buf[1]; st->scan_single_xfer[1].len = 2; st->scan_single_xfer[1].cs_change = 1; st->scan_single_xfer[2].rx_buf = &st->rx_buf[0]; st->scan_single_xfer[2].len = 2; spi_message_init(&st->scan_single_msg); spi_message_add_tail(&st->scan_single_xfer[0], &st->scan_single_msg); spi_message_add_tail(&st->scan_single_xfer[1], &st->scan_single_msg); spi_message_add_tail(&st->scan_single_xfer[2], &st->scan_single_msg); if (pdata && pdata->vref_mv) { st->int_vref_mv = pdata->vref_mv; st->ext_ref = AD7298_EXTREF; } else { st->int_vref_mv = AD7298_INTREF_mV; } ret = ad7298_register_ring_funcs_and_init(indio_dev); if (ret) goto error_disable_reg; ret = iio_device_register(indio_dev); if (ret) goto error_disable_reg; regdone = 1; ret = iio_ring_buffer_register_ex(indio_dev->ring, 0, &ad7298_channels[1], /* skip temp0 */ ARRAY_SIZE(ad7298_channels) - 1); if (ret) goto error_cleanup_ring; return 0; error_cleanup_ring: ad7298_ring_cleanup(indio_dev); error_disable_reg: if (!IS_ERR(st->reg)) regulator_disable(st->reg); error_put_reg: if (!IS_ERR(st->reg)) regulator_put(st->reg); if (regdone) iio_device_unregister(indio_dev); else iio_free_device(indio_dev); return ret; }
static int yas_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct yas_state *st; struct iio_dev *indio_dev; int ret; pr_info("[SENSOR] %s is called!!\n", __func__); this_client = i2c; indio_dev = iio_allocate_device(sizeof(*st)); if (!indio_dev) { ret = -ENOMEM; goto error_ret; } i2c_set_clientdata(i2c, indio_dev); indio_dev->name = id->name; indio_dev->dev.parent = &i2c->dev; indio_dev->info = &yas_info; indio_dev->channels = yas_channels; indio_dev->num_channels = ARRAY_SIZE(yas_channels); indio_dev->modes = INDIO_DIRECT_MODE; st = iio_priv(indio_dev); st->client = i2c; st->sampling_frequency = 20; st->mag.callback.device_open = yas_device_open; st->mag.callback.device_close = yas_device_close; st->mag.callback.device_read = yas_device_read; st->mag.callback.device_write = yas_device_write; st->mag.callback.usleep = yas_usleep; st->mag.callback.current_time = yas_current_time; INIT_DELAYED_WORK(&st->work, yas_work_func); mutex_init(&st->lock); #ifdef CONFIG_HAS_EARLYSUSPEND st->sus.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; st->sus.suspend = yas_early_suspend; st->sus.resume = yas_late_resume; register_early_suspend(&st->sus); #endif #ifdef CONFIG_SENSORS ret = sensors_register(st->yas_device, st, sensor_attrs, "magnetic_sensor"); if (ret) { pr_err("%s: cound not register gyro sensor device(%d).\n", __func__, ret); goto err_yas_sensor_register_failed; } #endif ret = yas_probe_buffer(indio_dev); if (ret) goto error_free_dev; ret = yas_probe_trigger(indio_dev); if (ret) goto error_remove_buffer; ret = iio_device_register(indio_dev); if (ret) goto error_remove_trigger; ret = yas_mag_driver_init(&st->mag); if (ret < 0) { ret = -EFAULT; goto error_unregister_iio; } ret = st->mag.init(); if (ret < 0) { ret = -EFAULT; goto error_unregister_iio; } ret = st->mag.set_enable(1); if (ret < 0) { ret = -EFAULT; goto error_driver_term; } pr_info("[SENSOR] %s is finished!!\n", __func__); return 0; error_driver_term: st->mag.term(); error_unregister_iio: iio_device_unregister(indio_dev); error_remove_trigger: yas_remove_trigger(indio_dev); error_remove_buffer: yas_remove_buffer(indio_dev); error_free_dev: #ifdef CONFIG_SENSORS sensors_unregister(st->yas_device, sensor_attrs); err_yas_sensor_register_failed: #endif #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&st->sus); #endif iio_free_device(indio_dev); error_ret: i2c_set_clientdata(i2c, NULL); this_client = NULL; return ret; }
static int optical_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct iio_dev *indio_dev = NULL; struct optical_data *adata = NULL; int err = 0; printk (KERN_ALERT "[%s]\n", __FUNCTION__); //indio_dev = iio_device_alloc(sizeof(*adata));//vungGV indio_dev=iio_allocate_device(sizeof(*adata)); if (NULL != indio_dev) { adata = iio_priv(indio_dev); //adata=indio_dev->dev_data; printk("vungv optical_i2c_probe"); adata->dev = &client->dev; optical_i2c_configure(indio_dev, client, adata); printk (KERN_ALERT "\t %s - Enabled VDD_IO", __FUNCTION__); if (adata->vdd_io) { err = regulator_enable(adata->vdd_io);//VungGV if (!err) { mdelay(3); } else { dev_err(&client->dev, "error enabling vdd_io, %d\n", err); } } printk (KERN_ALERT "\t %s - Enabled VDD_ANA", __FUNCTION__); if (adata->vdd_ana && !err) { err = regulator_enable(adata->vdd_ana); if (!err) { mdelay(3); } else { dev_err(&client->dev, "error enabling vdd_ana, %d\n", err); } } if (!err) { printk (KERN_ALERT "\t %s - Test PRESS Chip", __FUNCTION__); err = optical_common_probe(indio_dev); if (0 <= err) { return 0; } } } else { err = -ENOMEM; } /* if (adata && adata->vdd_io) { regulator_disable(adata->vdd_io); } */ /* if (adata && adata->vdd_ana) { regulator_disable(adata->vdd_ana); } */ if (indio_dev) { //iio_device_free(indio_dev); iio_free_device(indio_dev); } return err; }
static int ak8975_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ak8975_data *data; int err; /* Allocate our device context. */ data = kzalloc(sizeof(struct ak8975_data), GFP_KERNEL); if (!data) { dev_err(&client->dev, "Memory allocation fails\n"); err = -ENOMEM; goto exit; } i2c_set_clientdata(client, data); data->client = client; mutex_init(&data->lock); /* Grab and set up the supplied GPIO. */ data->eoc_irq = client->irq; data->eoc_gpio = irq_to_gpio(client->irq); /* We may not have a GPIO based IRQ to scan, that is fine, we will poll if so */ if (data->eoc_gpio > 0) { err = gpio_request(data->eoc_gpio, "ak_8975"); if (err < 0) { dev_err(&client->dev, "failed to request GPIO %d, error %d\n", data->eoc_gpio, err); goto exit_free; } err = gpio_direction_input(data->eoc_gpio); if (err < 0) { dev_err(&client->dev, "Failed to configure input direction for GPIO %d, error %d\n", data->eoc_gpio, err); goto exit_gpio; } } else data->eoc_gpio = 0; /* No GPIO available */ /* Perform some basic start-of-day setup of the device. */ err = ak8975_setup(client); if (err < 0) { dev_err(&client->dev, "AK8975 initialization fails\n"); goto exit_gpio; } /* Register with IIO */ data->indio_dev = iio_allocate_device(0); if (data->indio_dev == NULL) { err = -ENOMEM; goto exit_gpio; } data->indio_dev->dev.parent = &client->dev; data->indio_dev->info = &ak8975_info; data->indio_dev->dev_data = (void *)(data); data->indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(data->indio_dev); if (err < 0) goto exit_free_iio; return 0; exit_free_iio: iio_free_device(data->indio_dev); exit_gpio: if (data->eoc_gpio) gpio_free(data->eoc_gpio); exit_free: kfree(data); exit: return err; }
static int yas_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct yas_state *st; struct iio_dev *indio_dev; int ret, i; this_client = i2c; indio_dev = iio_allocate_device(sizeof(*st)); if (!indio_dev) { ret = -ENOMEM; goto error_ret; } i2c_set_clientdata(i2c, indio_dev); indio_dev->name = id->name; indio_dev->dev.parent = &i2c->dev; indio_dev->info = &yas_info; indio_dev->channels = yas_channels; indio_dev->num_channels = ARRAY_SIZE(yas_channels); indio_dev->modes = INDIO_DIRECT_MODE; st = iio_priv(indio_dev); st->client = i2c; st->sampling_frequency = 20; st->acc.callback.device_open = yas_device_open; st->acc.callback.device_close = yas_device_close; st->acc.callback.device_read = yas_device_read; st->acc.callback.device_write = yas_device_write; st->acc.callback.usleep = yas_usleep; st->acc.callback.current_time = yas_current_time; INIT_DELAYED_WORK(&st->work, yas_work_func); mutex_init(&st->lock); #ifdef CONFIG_HAS_EARLYSUSPEND st->sus.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; st->sus.suspend = yas_early_suspend; st->sus.resume = yas_late_resume; register_early_suspend(&st->sus); #endif for (i = 0; i < 3; i++) { st->compass_data[i] = 0; st->calib_bias[i] = 0; } ret = yas_probe_buffer(indio_dev); if (ret) goto error_free_dev; ret = yas_probe_trigger(indio_dev); if (ret) goto error_remove_buffer; ret = iio_device_register(indio_dev); if (ret) goto error_remove_trigger; ret = yas_acc_driver_init(&st->acc); if (ret < 0) { ret = -EFAULT; goto error_unregister_iio; } ret = st->acc.init(); if (ret < 0) { ret = -EFAULT; goto error_unregister_iio; } ret = st->acc.set_enable(1); if (ret < 0) { ret = -EFAULT; goto error_driver_term; } return 0; error_driver_term: st->acc.term(); error_unregister_iio: iio_device_unregister(indio_dev); error_remove_trigger: yas_remove_trigger(indio_dev); error_remove_buffer: yas_remove_buffer(indio_dev); error_free_dev: #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&st->sus); #endif iio_free_device(indio_dev); error_ret: i2c_set_clientdata(i2c, NULL); this_client = NULL; return ret; }
static int lsm303dlh_a_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct lsm303dlh_a_data *data; int err = 0; data = kzalloc(sizeof(struct lsm303dlh_a_data), GFP_KERNEL); if (!data) { dev_err(&client->dev, "memory allocation failed\n"); err = -ENOMEM; goto exit; } /* check for valid platform data */ if (!client->dev.platform_data) { dev_err(&client->dev, "Invalid platform data\n"); err = -ENOMEM; goto exit1; } data->pdata = client->dev.platform_data; data->mode = MODE_OFF; data->range = RANGE_2G; data->rate = RATE_50; data->device_status = DEVICE_OFF; data->client = client; i2c_set_clientdata(client, data); data->regulator = regulator_get(&client->dev, "vdd"); if (IS_ERR(data->regulator)) { err = PTR_ERR(data->regulator); dev_err(&client->dev, "failed to get regulator = %d\n", err); goto exit1; } /* Enable regulator */ lsm303dlh_a_enable(data); err = i2c_smbus_read_byte_data(client, CHIP_ID); if (err < 0) { dev_err(&client->dev, "failed to read of the chip\n"); goto exit2; } dev_info(&client->dev, "3-Axis Accelerometer, ID : %d\n", err); data->chip_id = err; lsm303dlh_a_setup(client); mutex_init(&data->lock); data->indio_dev = iio_allocate_device(0); if (!data->indio_dev) { dev_err(&client->dev, "iio allocation failed\n"); err = -ENOMEM; goto exit2; } data->indio_dev->info = &lsmdlh303a_info; data->indio_dev->dev.parent = &client->dev; data->indio_dev->dev_data = (void *)data; data->indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(data->indio_dev); if (err) goto exit3; #ifdef CONFIG_HAS_EARLYSUSPEND data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; data->early_suspend.suspend = lsm303dlh_a_early_suspend; data->early_suspend.resume = lsm303dlh_a_late_resume; register_early_suspend(&data->early_suspend); #endif /* Disable regulator */ lsm303dlh_a_disable(data); return 0; exit3: iio_free_device(data->indio_dev); exit2: regulator_disable(data->regulator); regulator_put(data->regulator); exit1: kfree(data); exit: return err; }
static int max517_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct max517_data *data; struct max517_platform_data *platform_data = client->dev.platform_data; int err; data = kzalloc(sizeof(struct max517_data), GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; } i2c_set_clientdata(client, data); data->client = client; data->indio_dev = iio_allocate_device(); if (data->indio_dev == NULL) { err = -ENOMEM; goto exit_free_data; } /* establish that the iio_dev is a child of the i2c device */ data->indio_dev->dev.parent = &client->dev; /* reduced attribute set for MAX517 */ if (id->driver_data == ID_MAX517) data->indio_dev->attrs = &max517_attribute_group; else data->indio_dev->attrs = &max518_attribute_group; data->indio_dev->dev_data = (void *)(data); data->indio_dev->driver_module = THIS_MODULE; data->indio_dev->modes = INDIO_DIRECT_MODE; /* * Reference voltage on MAX518 and default is 5V, else take vref_mv * from platform_data */ if (id->driver_data == ID_MAX518 || !platform_data) { data->vref_mv[0] = data->vref_mv[1] = 5000; /* mV */ } else { data->vref_mv[0] = platform_data->vref_mv[0]; data->vref_mv[1] = platform_data->vref_mv[1]; } err = iio_device_register(data->indio_dev); if (err) goto exit_free_device; dev_info(&client->dev, "DAC registered\n"); return 0; exit_free_device: iio_free_device(data->indio_dev); exit_free_data: kfree(data); exit: return err; }
/** * inv_ak89xx_probe() - probe function. */ static int inv_ak89xx_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct inv_ak89xx_state_s *st; struct iio_dev *indio_dev; int result; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { result = -ENODEV; goto out_no_free; } indio_dev = iio_allocate_device(sizeof(*st)); if (indio_dev == NULL) { result = -ENOMEM; goto out_no_free; } st = iio_priv(indio_dev); st->i2c = client; st->sl_handle = client->adapter; st->plat_data = *(struct mpu_platform_data *)dev_get_platdata(&client->dev); st->i2c_addr = client->addr; st->delay = AK89XX_DEFAULT_DELAY; st->compass_id = id->driver_data; st->compass_scale = 0; i2c_set_clientdata(client, indio_dev); result = ak89xx_init(st); if (result) goto out_free; indio_dev->dev.parent = &client->dev; indio_dev->name = id->name; indio_dev->channels = compass_channels; indio_dev->num_channels = ARRAY_SIZE(compass_channels); indio_dev->info = &ak89xx_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->currentmode = INDIO_DIRECT_MODE; result = inv_ak89xx_configure_ring(indio_dev); if (result) goto out_free; result = iio_buffer_register(indio_dev, indio_dev->channels, indio_dev->num_channels); if (result) goto out_unreg_ring; result = inv_ak89xx_probe_trigger(indio_dev); if (result) goto out_remove_ring; result = iio_device_register(indio_dev); if (result) goto out_remove_trigger; INIT_DELAYED_WORK(&st->work, ak89xx_work_func); pr_info("%s: Probe name %s\n", __func__, id->name); return 0; out_remove_trigger: if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) inv_ak89xx_remove_trigger(indio_dev); out_remove_ring: iio_buffer_unregister(indio_dev); out_unreg_ring: inv_ak89xx_unconfigure_ring(indio_dev); out_free: iio_free_device(indio_dev); out_no_free: dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result); return -EIO; }
static int __devinit ad9834_probe(struct spi_device *spi) { struct ad9834_platform_data *pdata = spi->dev.platform_data; struct ad9834_state *st; struct iio_dev *indio_dev; struct regulator *reg; int ret; if (!pdata) { dev_dbg(&spi->dev, "no platform data?\n"); return -ENODEV; } reg = regulator_get(&spi->dev, "vcc"); if (!IS_ERR(reg)) { ret = regulator_enable(reg); if (ret) goto error_put_reg; } indio_dev = iio_allocate_device(sizeof(*st)); if (indio_dev == NULL) { ret = -ENOMEM; goto error_disable_reg; } spi_set_drvdata(spi, indio_dev); st = iio_priv(indio_dev); st->mclk = pdata->mclk; st->spi = spi; st->devid = spi_get_device_id(spi)->driver_data; st->reg = reg; indio_dev->dev.parent = &spi->dev; indio_dev->name = spi_get_device_id(spi)->name; switch (st->devid) { case ID_AD9833: case ID_AD9837: indio_dev->info = &ad9833_info; break; default: indio_dev->info = &ad9834_info; break; } indio_dev->modes = INDIO_DIRECT_MODE; /* Setup default messages */ st->xfer.tx_buf = &st->data; st->xfer.len = 2; spi_message_init(&st->msg); spi_message_add_tail(&st->xfer, &st->msg); st->freq_xfer[0].tx_buf = &st->freq_data[0]; st->freq_xfer[0].len = 2; st->freq_xfer[0].cs_change = 1; st->freq_xfer[1].tx_buf = &st->freq_data[1]; st->freq_xfer[1].len = 2; spi_message_init(&st->freq_msg); spi_message_add_tail(&st->freq_xfer[0], &st->freq_msg); spi_message_add_tail(&st->freq_xfer[1], &st->freq_msg); st->control = AD9834_B28 | AD9834_RESET; if (!pdata->en_div2) st->control |= AD9834_DIV2; if (!pdata->en_signbit_msb_out && (st->devid == ID_AD9834)) st->control |= AD9834_SIGN_PIB; st->data = cpu_to_be16(AD9834_REG_CMD | st->control); ret = spi_sync(st->spi, &st->msg); if (ret) { dev_err(&spi->dev, "device init failed\n"); goto error_free_device; } ret = ad9834_write_frequency(st, AD9834_REG_FREQ0, pdata->freq0); if (ret) goto error_free_device; ret = ad9834_write_frequency(st, AD9834_REG_FREQ1, pdata->freq1); if (ret) goto error_free_device; ret = ad9834_write_phase(st, AD9834_REG_PHASE0, pdata->phase0); if (ret) goto error_free_device; ret = ad9834_write_phase(st, AD9834_REG_PHASE1, pdata->phase1); if (ret) goto error_free_device; ret = iio_device_register(indio_dev); if (ret) goto error_free_device; return 0; error_free_device: iio_free_device(indio_dev); error_disable_reg: if (!IS_ERR(reg)) regulator_disable(reg); error_put_reg: if (!IS_ERR(reg)) regulator_put(reg); return ret; }
static int __devinit ad5624r_probe(struct spi_device *spi) { struct ad5624r_state *st; int ret, voltage_uv = 0; st = kzalloc(sizeof(*st), GFP_KERNEL); if (st == NULL) { ret = -ENOMEM; goto error_ret; } spi_set_drvdata(spi, st); st->reg = regulator_get(&spi->dev, "vcc"); if (!IS_ERR(st->reg)) { ret = regulator_enable(st->reg); if (ret) goto error_put_reg; voltage_uv = regulator_get_voltage(st->reg); } st->chip_info = &ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data]; if (voltage_uv) st->vref_mv = voltage_uv / 1000; else st->vref_mv = st->chip_info->int_vref_mv; st->us = spi; st->indio_dev = iio_allocate_device(0); if (st->indio_dev == NULL) { ret = -ENOMEM; goto error_disable_reg; } st->indio_dev->dev.parent = &spi->dev; st->indio_dev->name = spi_get_device_id(spi)->name; st->indio_dev->info = &ad5624r_info; st->indio_dev->dev_data = (void *)(st); st->indio_dev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(st->indio_dev); if (ret) goto error_free_dev; ret = ad5624r_spi_write(spi, AD5624R_CMD_INTERNAL_REFER_SETUP, 0, !!voltage_uv, 16); if (ret) goto error_free_dev; return 0; error_free_dev: iio_free_device(st->indio_dev); error_disable_reg: if (!IS_ERR(st->reg)) regulator_disable(st->reg); error_put_reg: if (!IS_ERR(st->reg)) regulator_put(st->reg); kfree(st); error_ret: return ret; }
static int __devinit ad7887_probe(struct spi_device *spi) { struct ad7887_platform_data *pdata = spi->dev.platform_data; struct ad7887_state *st; int ret, voltage_uv = 0; st = kzalloc(sizeof(*st), GFP_KERNEL); if (st == NULL) { ret = -ENOMEM; goto error_ret; } st->reg = regulator_get(&spi->dev, "vcc"); if (!IS_ERR(st->reg)) { ret = regulator_enable(st->reg); if (ret) goto error_put_reg; voltage_uv = regulator_get_voltage(st->reg); } st->chip_info = &ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data]; spi_set_drvdata(spi, st); atomic_set(&st->protect_ring, 0); st->spi = spi; st->indio_dev = iio_allocate_device(); if (st->indio_dev == NULL) { ret = -ENOMEM; goto error_disable_reg; } /* Estabilish that the iio_dev is a child of the spi device */ st->indio_dev->dev.parent = &spi->dev; st->indio_dev->attrs = &ad7887_attribute_group; st->indio_dev->dev_data = (void *)(st); st->indio_dev->driver_module = THIS_MODULE; st->indio_dev->modes = INDIO_DIRECT_MODE; /* Setup default message */ st->tx_cmd_buf[0] = AD7887_CH_AIN0 | AD7887_PM_MODE4 | ((pdata && pdata->use_onchip_ref) ? 0 : AD7887_REF_DIS); st->xfer[0].rx_buf = &st->data[0]; st->xfer[0].tx_buf = &st->tx_cmd_buf[0]; st->xfer[0].len = 2; spi_message_init(&st->msg[AD7887_CH0]); spi_message_add_tail(&st->xfer[0], &st->msg[AD7887_CH0]); if (pdata && pdata->en_dual) { st->tx_cmd_buf[0] |= AD7887_DUAL | AD7887_REF_DIS; st->tx_cmd_buf[2] = AD7887_CH_AIN1 | AD7887_DUAL | AD7887_REF_DIS | AD7887_PM_MODE4; st->tx_cmd_buf[4] = AD7887_CH_AIN0 | AD7887_DUAL | AD7887_REF_DIS | AD7887_PM_MODE4; st->tx_cmd_buf[6] = AD7887_CH_AIN1 | AD7887_DUAL | AD7887_REF_DIS | AD7887_PM_MODE4; st->xfer[1].rx_buf = &st->data[0]; st->xfer[1].tx_buf = &st->tx_cmd_buf[2]; st->xfer[1].len = 2; st->xfer[2].rx_buf = &st->data[2]; st->xfer[2].tx_buf = &st->tx_cmd_buf[4]; st->xfer[2].len = 2; spi_message_init(&st->msg[AD7887_CH0_CH1]); spi_message_add_tail(&st->xfer[1], &st->msg[AD7887_CH0_CH1]); spi_message_add_tail(&st->xfer[2], &st->msg[AD7887_CH0_CH1]); st->xfer[3].rx_buf = &st->data[0]; st->xfer[3].tx_buf = &st->tx_cmd_buf[6]; st->xfer[3].len = 2; spi_message_init(&st->msg[AD7887_CH1]); spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]); st->en_dual = true; if (pdata && pdata->vref_mv) st->int_vref_mv = pdata->vref_mv; else if (voltage_uv) st->int_vref_mv = voltage_uv / 1000; else dev_warn(&spi->dev, "reference voltage unspecified\n"); } else { if (pdata && pdata->vref_mv) st->int_vref_mv = pdata->vref_mv; else if (pdata && pdata->use_onchip_ref) st->int_vref_mv = st->chip_info->int_vref_mv; else dev_warn(&spi->dev, "reference voltage unspecified\n"); } ret = ad7887_register_ring_funcs_and_init(st->indio_dev); if (ret) goto error_free_device; ret = iio_device_register(st->indio_dev); if (ret) goto error_free_device; ret = iio_ring_buffer_register(st->indio_dev->ring, 0); if (ret) goto error_cleanup_ring; return 0; error_cleanup_ring: ad7887_ring_cleanup(st->indio_dev); iio_device_unregister(st->indio_dev); error_free_device: iio_free_device(st->indio_dev); error_disable_reg: if (!IS_ERR(st->reg)) regulator_disable(st->reg); error_put_reg: if (!IS_ERR(st->reg)) regulator_put(st->reg); kfree(st); error_ret: return ret; }