static int st_gyro_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct iio_dev *indio_dev; struct st_sensor_data *gdata; int err; indio_dev = iio_device_alloc(sizeof(*gdata)); if (indio_dev == NULL) { err = -ENOMEM; goto iio_device_alloc_error; } gdata = iio_priv(indio_dev); gdata->dev = &client->dev; st_sensors_i2c_configure(indio_dev, client, gdata); err = st_gyro_common_probe(indio_dev); if (err < 0) goto st_gyro_common_probe_error; return 0; st_gyro_common_probe_error: iio_device_free(indio_dev); iio_device_alloc_error: return err; }
static int st_press_spi_probe(struct spi_device *spi) { struct iio_dev *indio_dev; struct st_sensor_data *pdata; int err; indio_dev = iio_device_alloc(sizeof(*pdata)); if (indio_dev == NULL) { err = -ENOMEM; goto iio_device_alloc_error; } pdata = iio_priv(indio_dev); pdata->dev = &spi->dev; st_sensors_spi_configure(indio_dev, spi, pdata); err = st_press_common_probe(indio_dev); if (err < 0) goto st_press_common_probe_error; return 0; st_press_common_probe_error: iio_device_free(indio_dev); iio_device_alloc_error: return err; }
static int ade7854_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; struct ade7854_state *st; struct iio_dev *indio_dev; indio_dev = iio_device_alloc(sizeof(*st)); if (indio_dev == NULL) return -ENOMEM; st = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); st->read_reg_8 = ade7854_i2c_read_reg_8; st->read_reg_16 = ade7854_i2c_read_reg_16; st->read_reg_24 = ade7854_i2c_read_reg_24; st->read_reg_32 = ade7854_i2c_read_reg_32; st->write_reg_8 = ade7854_i2c_write_reg_8; st->write_reg_16 = ade7854_i2c_write_reg_16; st->write_reg_24 = ade7854_i2c_write_reg_24; st->write_reg_32 = ade7854_i2c_write_reg_32; st->i2c = client; st->irq = client->irq; ret = ade7854_probe(indio_dev, &client->dev); if (ret) iio_device_free(indio_dev); return ret; }
static int ad5930_probe(struct spi_device *spi) { struct ad5930_state *st; struct iio_dev *idev; int ret = 0; idev = iio_device_alloc(sizeof(*st)); if (idev == NULL) { ret = -ENOMEM; goto error_ret; } spi_set_drvdata(spi, idev); st = iio_priv(idev); mutex_init(&st->lock); st->sdev = spi; idev->dev.parent = &spi->dev; idev->info = &ad5930_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 = 16; spi_setup(spi); return 0; error_free_dev: iio_device_free(idev); error_ret: return ret; }
static int st_hub_step_detector_probe(struct platform_device *pdev) { int err; struct iio_dev *indio_dev; struct st_hub_pdata_info *info; struct st_hub_sensor_data *adata; struct st_sensor_hub_callbacks callback; indio_dev = iio_device_alloc(sizeof(*adata)); if (!indio_dev) return -ENOMEM; platform_set_drvdata(pdev, indio_dev); indio_dev->channels = st_hub_step_detector_ch; indio_dev->num_channels = ARRAY_SIZE(st_hub_step_detector_ch); indio_dev->dev.parent = &pdev->dev; indio_dev->info = &st_hub_step_detector_info; indio_dev->name = pdev->name; indio_dev->modes = INDIO_DIRECT_MODE; adata = iio_priv(indio_dev); info = pdev->dev.platform_data; st_hub_get_common_data(info->hdata, info->index, &adata->cdata); err = st_hub_set_default_values(adata, info, indio_dev); if (err < 0) goto st_hub_deallocate_device; err = iio_triggered_buffer_setup(indio_dev, NULL, NULL, &st_hub_buffer_setup_ops); if (err) goto st_hub_deallocate_device; err = st_hub_setup_trigger_sensor(indio_dev, adata); if (err < 0) goto st_hub_clear_buffer; err = iio_device_register(indio_dev); if (err) goto st_hub_remove_trigger; callback.pdev = pdev; callback.push_data = &st_hub_step_detector_push_data; callback.push_event = &st_hub_step_detector_push_event; st_hub_register_callback(info->hdata, &callback, info->index); return 0; st_hub_remove_trigger: st_hub_remove_trigger(adata); st_hub_clear_buffer: iio_triggered_buffer_cleanup(indio_dev); st_hub_deallocate_device: iio_device_free(indio_dev); return err; }
static int mcp3422_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct iio_dev *iio; struct mcp3422 *adc; int err; u8 config; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; iio = iio_device_alloc(sizeof(*adc)); if (!iio) return -ENOMEM; adc = iio_priv(iio); adc->i2c = client; mutex_init(&adc->lock); iio->dev.parent = &client->dev; iio->name = dev_name(&client->dev); iio->modes = INDIO_DIRECT_MODE; iio->info = &mcp3422_info; switch ((unsigned int)(id->driver_data)) { case 2: case 3: iio->channels = mcp3422_channels; iio->num_channels = ARRAY_SIZE(mcp3422_channels); break; case 4: iio->channels = mcp3424_channels; iio->num_channels = ARRAY_SIZE(mcp3424_channels); break; } /* meaningful default configuration */ config = (MCP3422_CONT_SAMPLING | MCP3422_CHANNEL_VALUE(1) | MCP3422_PGA_VALUE(MCP3422_PGA_1) | MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240)); mcp3422_update_config(adc, config); err = iio_device_register(iio); if (err < 0) goto iio_free; i2c_set_clientdata(client, iio); return 0; iio_free: iio_device_free(iio); return err; }
static int isl29018_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl29018_chip *chip; struct iio_dev *indio_dev; int err; indio_dev = iio_device_alloc(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->dev = &client->dev; mutex_init(&chip->lock); chip->lux_scale = 1; chip->range = 1000; chip->adc_bit = 16; chip->suspended = false; chip->regmap = devm_regmap_init_i2c(client, &isl29018_regmap_config); if (IS_ERR(chip->regmap)) { err = PTR_ERR(chip->regmap); dev_err(chip->dev, "regmap initialization failed: %d\n", err); goto exit; } err = isl29018_chip_init(chip); if (err) goto exit_iio_free; indio_dev->info = &isl29108_info; indio_dev->channels = isl29018_channels; indio_dev->num_channels = ARRAY_SIZE(isl29018_channels); indio_dev->name = id->name; 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_iio_free; } return 0; exit_iio_free: iio_device_free(indio_dev); exit: return err; }
static int max517_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct max517_data *data; struct iio_dev *indio_dev; struct max517_platform_data *platform_data = client->dev.platform_data; int err; indio_dev = iio_device_alloc(sizeof(*data)); if (indio_dev == NULL) { err = -ENOMEM; goto exit; } data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client = client; /* establish that the iio_dev is a child of the i2c device */ indio_dev->dev.parent = &client->dev; /* reduced channel set for MAX517 */ if (id->driver_data == ID_MAX517) indio_dev->num_channels = 1; else indio_dev->num_channels = 2; indio_dev->channels = max517_channels; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &max517_info; /* * 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(indio_dev); if (err) goto exit_free_device; dev_info(&client->dev, "DAC registered\n"); return 0; exit_free_device: iio_device_free(indio_dev); exit: return err; }
static int __devinit tiadc_probe(struct platform_device *pdev) { struct iio_dev *indio_dev; struct tiadc_device *adc_dev; struct ti_tscadc_dev *tscadc_dev = pdev->dev.platform_data; struct mfd_tscadc_board *pdata; int err; pdata = tscadc_dev->dev->platform_data; if (!pdata || !pdata->adc_init) { dev_err(&pdev->dev, "Could not find platform data\n"); return -EINVAL; } indio_dev = iio_device_alloc(sizeof(struct tiadc_device)); if (indio_dev == NULL) { dev_err(&pdev->dev, "failed to allocate iio device\n"); err = -ENOMEM; goto err_ret; } adc_dev = iio_priv(indio_dev); adc_dev->mfd_tscadc = tscadc_dev; adc_dev->channels = pdata->adc_init->adc_channels; indio_dev->dev.parent = &pdev->dev; indio_dev->name = dev_name(&pdev->dev); indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &tiadc_info; tiadc_step_config(adc_dev); err = tiadc_channel_init(indio_dev, adc_dev); if (err < 0) goto err_free_device; err = iio_device_register(indio_dev); if (err) goto err_free_channels; platform_set_drvdata(pdev, indio_dev); dev_info(&pdev->dev, "Initialized\n"); return 0; err_free_channels: tiadc_channels_remove(indio_dev); err_free_device: iio_device_free(indio_dev); err_ret: return err; }
static int adis16400_probe(struct spi_device *spi) { struct adis16400_state *st; struct iio_dev *indio_dev; int ret; indio_dev = iio_device_alloc(sizeof(*st)); if (indio_dev == NULL) return -ENOMEM; st = iio_priv(indio_dev); /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); /* setup the industrialio driver allocated elements */ st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data]; indio_dev->dev.parent = &spi->dev; indio_dev->name = spi_get_device_id(spi)->name; indio_dev->channels = st->variant->channels; indio_dev->num_channels = st->variant->num_channels; indio_dev->info = &adis16400_info; indio_dev->modes = INDIO_DIRECT_MODE; if (!(st->variant->flags & ADIS16400_NO_BURST)) indio_dev->available_scan_masks = adis16400_burst_scan_mask; ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data); if (ret) goto error_free_dev; ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, adis16400_trigger_handler); if (ret) goto error_free_dev; /* Get the device into a sane initial state */ ret = adis16400_initial_setup(indio_dev); if (ret) goto error_cleanup_buffer; ret = iio_device_register(indio_dev); if (ret) goto error_cleanup_buffer; adis16400_debugfs_init(indio_dev); return 0; error_cleanup_buffer: adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); error_free_dev: iio_device_free(indio_dev); return ret; }
static int isl29028_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct isl29028_chip *chip; struct iio_dev *indio_dev; int ret; indio_dev = iio_device_alloc(sizeof(*chip)); if (!indio_dev) { dev_err(&client->dev, "iio allocation fails\n"); return -ENOMEM; } chip = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); chip->dev = &client->dev; mutex_init(&chip->lock); chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config); if (IS_ERR(chip->regmap)) { ret = PTR_ERR(chip->regmap); dev_err(chip->dev, "regmap initialization failed: %d\n", ret); goto exit_iio_free; } ret = isl29028_chip_init(chip); if (ret < 0) { dev_err(chip->dev, "chip initialization failed: %d\n", ret); goto exit_iio_free; } indio_dev->info = &isl29028_info; indio_dev->channels = isl29028_channels; indio_dev->num_channels = ARRAY_SIZE(isl29028_channels); indio_dev->name = id->name; indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(indio_dev); if (ret < 0) { dev_err(chip->dev, "iio registration fails with error %d\n", ret); goto exit_iio_free; } return 0; exit_iio_free: iio_device_free(indio_dev); return ret; }
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_device_alloc(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_device_free(indio_dev); error_ret: return ret; }
static int m4pas_probe(struct platform_device *pdev) { struct m4pas_driver_data *dd = NULL; struct iio_dev *iio = NULL; int err = 0; iio = iio_device_alloc(sizeof(dd)); if (iio == NULL) { m4pas_err("%s: Failed to allocate IIO data.\n", __func__); err = -ENOMEM; goto m4pas_probe_fail_noiio; } dd = iio_priv(iio); dd->pdev = pdev; mutex_init(&(dd->mutex)); platform_set_drvdata(pdev, iio); dd->samplerate = -1; /* We always start disabled */ dd->latest_samplerate = dd->samplerate; err = m4pas_create_iiodev(iio); /* iio and dd are freed on fail */ if (err < 0) { m4pas_err("%s: Failed to create IIO device.\n", __func__); goto m4pas_probe_fail_noiio; } err = m4sensorhub_register_initcall(m4pas_driver_init, iio); if (err < 0) { m4pas_err("%s: Failed to register initcall.\n", __func__); goto m4pas_probe_fail; } return 0; m4pas_probe_fail: m4pas_remove_iiodev(iio); /* iio and dd are freed here */ m4pas_probe_fail_noiio: m4pas_err("%s: Probe failed with error code %d.\n", __func__, err); return err; }
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_device_alloc(sizeof(*data)); if (indio_dev == NULL) { err = -ENOMEM; goto exit; } /* default settings at probe */ data = iio_priv(indio_dev); data->meas_conf = HMC5843_MEAS_CONF_NORMAL; data->range = HMC5843_RANGE_GAIN_DEFAULT; data->operating_mode = HMC5843_MODE_CONVERSION_CONTINUOUS; i2c_set_clientdata(client, indio_dev); hmc5843_init_client(client, id); indio_dev->info = &hmc5843_info; indio_dev->name = id->name; 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_device_free(indio_dev); exit: return err; }
static int adis16080_probe(struct spi_device *spi) { int ret; struct adis16080_state *st; struct iio_dev *indio_dev; /* setup the industrialio driver allocated elements */ indio_dev = iio_device_alloc(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->channels = adis16080_channels; indio_dev->num_channels = ARRAY_SIZE(adis16080_channels); 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; return 0; error_free_dev: iio_device_free(indio_dev); error_ret: return ret; }
static int vprbrd_adc_probe(struct platform_device *pdev) { struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent); struct vprbrd_adc *adc; struct iio_dev *indio_dev; int ret; /* registering iio */ indio_dev = iio_device_alloc(sizeof(*adc)); if (!indio_dev) { dev_err(&pdev->dev, "failed allocating iio device\n"); return -ENOMEM; } adc = iio_priv(indio_dev); adc->vb = vb; indio_dev->name = "viperboard adc"; indio_dev->dev.parent = &pdev->dev; indio_dev->info = &vprbrd_adc_iio_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = vprbrd_adc_iio_channels; indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels); ret = iio_device_register(indio_dev); if (ret) { dev_err(&pdev->dev, "could not register iio (adc)"); goto error; } platform_set_drvdata(pdev, indio_dev); return 0; error: iio_device_free(indio_dev); return ret; }
static int ak8975_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ak8975_data *data; struct iio_dev *indio_dev; int eoc_gpio; int err; /* Grab and set up the supplied GPIO. */ if (client->dev.platform_data == NULL) eoc_gpio = -1; else eoc_gpio = *(int *)(client->dev.platform_data); /* We may not have a GPIO based IRQ to scan, that is fine, we will poll if so */ if (gpio_is_valid(eoc_gpio)) { err = gpio_request_one(eoc_gpio, GPIOF_IN, "ak_8975"); if (err < 0) { dev_err(&client->dev, "failed to request GPIO %d, error %d\n", eoc_gpio, err); goto exit; } } /* Register with IIO */ indio_dev = iio_device_alloc(sizeof(*data)); if (indio_dev == NULL) { err = -ENOMEM; goto exit_gpio; } data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); /* 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_free_iio; } data->client = client; mutex_init(&data->lock); data->eoc_gpio = eoc_gpio; indio_dev->dev.parent = &client->dev; indio_dev->channels = ak8975_channels; indio_dev->num_channels = ARRAY_SIZE(ak8975_channels); indio_dev->info = &ak8975_info; indio_dev->modes = INDIO_DIRECT_MODE; err = iio_device_register(indio_dev); if (err < 0) goto exit_free_iio; return 0; exit_free_iio: iio_device_free(indio_dev); exit_gpio: if (gpio_is_valid(eoc_gpio)) gpio_free(eoc_gpio); exit: return err; }
static int ad5504_probe(struct spi_device *spi) { struct ad5504_platform_data *pdata = spi->dev.platform_data; struct iio_dev *indio_dev; struct ad5504_state *st; struct regulator *reg; int ret, voltage_uv = 0; indio_dev = iio_device_alloc(sizeof(*st)); if (indio_dev == NULL) { ret = -ENOMEM; goto error_ret; } reg = regulator_get(&spi->dev, "vcc"); if (!IS_ERR(reg)) { ret = regulator_enable(reg); if (ret) goto error_put_reg; ret = regulator_get_voltage(reg); if (ret < 0) goto error_disable_reg; voltage_uv = ret; } spi_set_drvdata(spi, indio_dev); st = iio_priv(indio_dev); if (voltage_uv) st->vref_mv = voltage_uv / 1000; else if (pdata) st->vref_mv = pdata->vref_mv; else dev_warn(&spi->dev, "reference voltage unspecified\n"); st->reg = reg; st->spi = spi; indio_dev->dev.parent = &spi->dev; indio_dev->name = spi_get_device_id(st->spi)->name; indio_dev->info = &ad5504_info; if (spi_get_device_id(st->spi)->driver_data == ID_AD5501) indio_dev->num_channels = 1; else indio_dev->num_channels = 4; indio_dev->channels = ad5504_channels; indio_dev->modes = INDIO_DIRECT_MODE; if (spi->irq) { ret = request_threaded_irq(spi->irq, NULL, &ad5504_event_handler, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, spi_get_device_id(st->spi)->name, indio_dev); if (ret) goto error_disable_reg; } ret = iio_device_register(indio_dev); if (ret) goto error_free_irq; return 0; error_free_irq: if (spi->irq) free_irq(spi->irq, indio_dev); error_disable_reg: if (!IS_ERR(reg)) regulator_disable(reg); error_put_reg: if (!IS_ERR(reg)) regulator_put(reg); iio_device_free(indio_dev); error_ret: return ret; }
static int nuc970_adc_probe(struct platform_device *pdev) { struct iio_dev *indio_dev; struct nuc970_adc_device *info = NULL; int ret = -ENODEV; struct resource *res; int irq; indio_dev = iio_device_alloc(sizeof(struct nuc970_adc_device)); if (indio_dev == NULL) { dev_err(&pdev->dev, "failed to allocate iio device\n"); ret = -ENOMEM; goto err_ret; } info = iio_priv(indio_dev); /* map the registers */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { dev_err(&pdev->dev, "cannot find IO resource\n"); ret = -ENOENT; goto err_ret; } info->regs = ioremap(res->start, resource_size(res)); if (info->regs == NULL) { dev_err(&pdev->dev, "cannot map IO\n"); ret = -ENXIO; goto err_ret; } indio_dev->dev.parent = &pdev->dev; indio_dev->name = dev_name(&pdev->dev); indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &nuc970_adc_info; #ifdef CONFIG_BOARD_TOMATO indio_dev->num_channels = 4; #else indio_dev->num_channels = 8; #endif indio_dev->channels = nuc970_adc_iio_channels; indio_dev->masklength = indio_dev->num_channels - 1; /* find the clock and enable it */ info->eclk=clk_get(NULL, "adc_eclk"); clk_prepare(info->eclk); clk_enable(info->eclk); info->clk=clk_get(NULL, "adc"); clk_prepare(info->clk); clk_enable(info->clk); clk_set_rate(info->eclk, 1000000); irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "no irq resource?\n"); ret = irq; goto err_ret; } info->irq = irq; init_completion(&info->completion); ret = request_irq(info->irq, nuc970_adc_isr, 0, dev_name(&pdev->dev), info); if (ret < 0) { dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", info->irq); goto err_ret; } #ifdef CONFIG_NUC970_NADC_BANDGAP writel(3, info->regs + CTL); //enable AD_EN #endif #ifdef CONFIG_NUC970_NADC_VREF writel(1, info->regs + CTL); //enable AD_EN #endif #ifdef CONFIG_NUC970_NADC_I33V writel(0x3<<6, info->regs + CONF); //select AGND33 vs AVDD33 writel(1, info->regs + CTL); //enable AD_EN, disable bandgap #endif writel(1, info->regs + IER); //enable M_IEN ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, &nuc970_trigger_handler, &nuc970_ring_setup_ops); if (ret) goto err_free_channels; ret = iio_device_register(indio_dev); if (ret < 0) { printk("Couldn't register NC970 ADC..\n"); goto err_free_channels; } platform_set_drvdata(pdev, indio_dev); writel((readl(info->regs + CONF) | 1<<2), info->regs + CONF); //enable NACEN printk("%s: nuc970 Normal ADC adapter\n", indio_dev->name); return 0; err_free_channels: nuc970_adc_channels_remove(indio_dev); iio_device_free(indio_dev); err_ret: return ret; }
static int yas_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct yas_state *st; struct iio_dev *indio_dev; int ret, i; u8 temp; pr_info("[SENSOR]: %s - Probe Start!\n", __func__); this_client = client; /* Check if the device is there or not. */ ret = yas_device_read(YAS_TYPE_MAG, REG_DIDR, &temp, 1); if (ret < 0) { ret = -ENODEV; goto error_check_dev; } indio_dev = iio_device_alloc(sizeof(*st)); if (!indio_dev) { ret = -ENOMEM; goto error_ret; } st = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); st->client = client; /* IIO device init */ indio_dev->name = "magnetic_sensor"; indio_dev->channels = yas_channels; indio_dev->num_channels = ARRAY_SIZE(yas_channels); indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &yas_info; 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 for (i = 0; i < 3; i++) st->compass_data[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_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 = yas_parse_dt(st, &client->dev); if (ret < 0) { pr_err("%s of_node error\n", __func__); ret = -ENODEV; goto error_of_node; } ret= st->mag.set_position(st->chip_pos); if (ret < 0) { ret = -EFAULT; goto error_of_node; } spin_lock_init(&st->spin_lock); ret = sensors_register(st->factory_dev, st, mag_sensor_attrs, MODULE_NAME); if (ret < 0) { pr_err("[SENSOR] %s: cound not register mag device(%d).\n", __func__, ret); goto err_mag_sensor_register_failed; } pr_info("[SENSOR]: %s - Probe done!\n", __func__); return 0; err_mag_sensor_register_failed: error_of_node: 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 i2c_set_clientdata(client, NULL); error_ret: error_check_dev: this_client = NULL; pr_err("[SENSOR]: %s - Probe fail!\n", __func__); return ret; }
static int adc1x8s102_probe(struct spi_device *spi) { struct adc1x8s102_platform_data *pdata = spi->dev.platform_data; struct adc1x8s102_state *st; struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); int ret; if (NULL == indio_dev) { dev_crit(&spi->dev, "Cannot allocate memory for indio_dev\n"); return -ENOMEM; } st = iio_priv(indio_dev); if (NULL == pdata) { dev_err(&spi->dev, "Cannot get adc1x8s102 platform data\n"); return -EFAULT; } st->ext_vin = pdata->ext_vin; /* Use regulator, if available. */ st->reg = regulator_get(&spi->dev, "vref"); if (IS_ERR(st->reg)) { ret = PTR_ERR(st->reg); dev_warn(&spi->dev, "Cannot get 'vref' regulator\n"); goto error_free; } ret = regulator_enable(st->reg); if (ret < 0) { dev_warn(&spi->dev, "Cannot enable vref regulator\n"); 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 = adc1x8s102_channels; indio_dev->num_channels = ARRAY_SIZE(adc1x8s102_channels); indio_dev->info = &adc1x8s102_info; /* Setup default message */ st->scan_single_xfer.tx_buf = st->tx_buf; st->scan_single_xfer.rx_buf = st->rx_buf; st->scan_single_xfer.len = 2 * sizeof(__be16); st->scan_single_xfer.cs_change = 0; spi_message_init(&st->scan_single_msg); spi_message_add_tail(&st->scan_single_xfer, &st->scan_single_msg); ret = iio_triggered_buffer_setup(indio_dev, NULL, &adc1x8s102_trigger_handler, NULL); if (ret) goto error_disable_reg; ret = iio_device_register(indio_dev); if (ret) { dev_err(&spi->dev, "Failed to register IIO device\n"); goto error_cleanup_ring; } return 0; error_cleanup_ring: iio_triggered_buffer_cleanup(indio_dev); error_disable_reg: regulator_disable(st->reg); error_put_reg: regulator_put(st->reg); error_free: iio_device_free(indio_dev); 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_device_alloc(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_device_free(iodev); errout1: return retval; }
static int bcove_gpadc_probe(struct platform_device *pdev) { int err; struct gpadc_info *info; struct iio_dev *indio_dev; struct intel_basincove_gpadc_platform_data *pdata = pdev->dev.platform_data; if (!pdata) { dev_err(&pdev->dev, "no platform data supplied\n"); err = -EINVAL; goto out; } indio_dev = iio_device_alloc(sizeof(struct gpadc_info)); if (indio_dev == NULL) { dev_err(&pdev->dev, "allocating iio device failed\n"); err = -ENOMEM; goto out; } info = iio_priv(indio_dev); mutex_init(&info->lock); init_waitqueue_head(&info->wait); info->dev = &pdev->dev; info->irq = platform_get_irq(pdev, 0); info->intr = ioremap_nocache(pdata->intr, 1); if (!info->intr) { dev_err(&pdev->dev, "ioremap of ADCIRQ failed\n"); err = -ENOMEM; goto err_free; } info->intr_mask = pdata->intr_mask; info->channel_num = pdata->channel_num; info->gpadc_regmaps = pdata->gpadc_regmaps; info->gpadc_regs = pdata->gpadc_regs; err = request_threaded_irq(info->irq, gpadc_isr, gpadc_threaded_isr, IRQF_ONESHOT, "adc", indio_dev); if (err) { gpadc_dump(info); dev_err(&pdev->dev, "unable to register irq %d\n", info->irq); goto err_iounmap; } platform_set_drvdata(pdev, indio_dev); indio_dev->dev.parent = &pdev->dev; indio_dev->name = pdev->name; indio_dev->channels = pdata->gpadc_channels; indio_dev->num_channels = pdata->channel_num; indio_dev->info = &basincove_adc_info; indio_dev->modes = INDIO_DIRECT_MODE; err = iio_map_array_register(indio_dev, pdata->gpadc_iio_maps); if (err) goto err_release_irq; err = iio_device_register(indio_dev); if (err < 0) goto err_array_unregister; err = sysfs_create_group(&pdev->dev.kobj, &intel_basincove_gpadc_attr_group); if (err) { dev_err(&pdev->dev, "Unable to export sysfs interface, error: %d\n", err); goto err_iio_device_unregister; } info->initialized = 1; dev_info(&pdev->dev, "bcove adc probed\n"); return 0; err_iio_device_unregister: iio_device_unregister(indio_dev); err_array_unregister: iio_map_array_unregister(indio_dev); err_release_irq: free_irq(info->irq, info); err_iounmap: iounmap(info->intr); err_free: iio_device_free(indio_dev); out: return err; }
static int ad7298_probe(struct spi_device *spi) { struct ad7298_platform_data *pdata = spi->dev.platform_data; struct ad7298_state *st; struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); int ret; if (indio_dev == NULL) return -ENOMEM; st = iio_priv(indio_dev); if (pdata && pdata->ext_ref) st->ext_ref = AD7298_EXTREF; if (st->ext_ref) { st->reg = regulator_get(&spi->dev, "vref"); if (IS_ERR(st->reg)) { ret = PTR_ERR(st->reg); goto error_free; } 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); ret = iio_triggered_buffer_setup(indio_dev, NULL, &ad7298_trigger_handler, NULL); if (ret) goto error_disable_reg; ret = iio_device_register(indio_dev); if (ret) goto error_cleanup_ring; return 0; error_cleanup_ring: iio_triggered_buffer_cleanup(indio_dev); error_disable_reg: if (st->ext_ref) regulator_disable(st->reg); error_put_reg: if (st->ext_ref) regulator_put(st->reg); error_free: iio_device_free(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, i; int position; pr_err("%s : PROBE START\n", __func__); this_client = i2c; indio_dev = iio_device_alloc(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; 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 for (i = 0; i < 3; i++) st->compass_data[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_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 = yas_parse_dt(&i2c->dev, st); if(!ret){ position = st->position; ret = st->mag.set_position(position); pr_info("[SENSOR] set_position (%d)\n", position); } spin_lock_init(&st->spin_lock); ret = sensors_register(factory_dev, indio_dev, mag_sensor_attrs, MODULE_NAME_MAG); if (ret < 0) { pr_err("%s: cound not register mag sensor device(%d).\n", __func__, ret); goto err_mag_sensor_register_failed; } pr_err("%s : PROBE END\n", __func__); return 0; err_mag_sensor_register_failed: 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_device_free(indio_dev); error_ret: i2c_set_clientdata(i2c, NULL); this_client = NULL; 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, i; s8 *bias; struct yas_acc_platform_data *pdata; I("%s\n", __func__); this_client = i2c; indio_dev = iio_device_alloc(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; st->indio_dev = indio_dev; INIT_DELAYED_WORK(&st->work, yas_work_func); INIT_WORK(&st->resume_work, yas_resume_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_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; } pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); if (pdata == NULL) E("%s: memory allocation for pdata failed.", __func__); else yas_parse_dt(&i2c->dev, pdata); for (i = 0; i < 3; i++) { st->accel_data[i] = 0; bias = (s8 *)&pdata->gs_kvalue; st->calib_bias[i] = -(bias[2-i] * YAS_GRAVITY_EARTH / 256); I("%s: calib_bias[%d] = %d\n", __func__, i, st->calib_bias[i]); } mutex_lock(&st->lock); if ((pdata->placement < 8) && (pdata->placement >= 0)) { ret = st->acc.set_position(pdata->placement); I("%s: set position = %d\n", __func__, pdata->placement); } else { ret = st->acc.set_position(5); D("%s: set default position = 5\n", __func__); } mutex_unlock(&st->lock); #ifdef CONFIG_CIR_ALWAYS_READY module.IRQ = pdata->intr; I("%s: IRQ = %d\n", __func__, module.IRQ); ret = request_irq(module.IRQ, kxtj2_irq_handler, IRQF_TRIGGER_RISING, "kxtj2", &module); enable_irq_wake(module.IRQ); if (ret) E("%s: Could not request irq = %d\n", __func__, module.IRQ); module.kxtj2_wq = create_singlethread_workqueue("kxtj2_wq"); if (!module.kxtj2_wq) { E("%s: Can't create workqueue\n", __func__); ret = -ENOMEM; goto error_create_singlethread_workqueue; } #endif init_irq_work(&st->iio_irq_work, iio_trigger_work); g_st = st; ret = create_sysfs_interfaces(st); if (ret) { E("%s: create_sysfs_interfaces fail, ret = %d\n", __func__, ret); goto err_create_fixed_sysfs; } I("%s: Successfully probe\n", __func__); return 0; err_create_fixed_sysfs: #ifdef CONFIG_CIR_ALWAYS_READY if (module.kxtj2_wq) destroy_workqueue(module.kxtj2_wq); error_create_singlethread_workqueue: #endif kfree(pdata); 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_device_free(indio_dev); error_ret: i2c_set_clientdata(i2c, NULL); this_client = NULL; 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, i; struct yas_acc_platform_data *pdata; this_client = i2c; printk("%s: yas_kionix_accel_probe start ---\n", __FUNCTION__); indio_dev = iio_device_alloc(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; st->indio_dev = indio_dev; 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; } init_irq_work(&st->iio_irq_work, iio_trigger_work); g_st = st; ret = create_sysfs_interfaces(st); if (ret) { printk(KERN_ERR"%s: create_sysfs_interfaces fail, ret = %d\n", __func__, ret); goto err_create_fixed_sysfs; } return 0; err_create_fixed_sysfs: kfree(pdata); 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_device_free(indio_dev); error_ret: i2c_set_clientdata(i2c, NULL); this_client = NULL; return ret; }
static int palmas_gpadc_probe(struct platform_device *pdev) { struct palmas_gpadc *adc; struct palmas_platform_data *pdata; struct palmas_gpadc_platform_data *gpadc_pdata = NULL; struct iio_dev *iodev; int ret, i; pdata = dev_get_platdata(pdev->dev.parent); if (pdata && pdata->gpadc_pdata) gpadc_pdata = pdata->gpadc_pdata; if (!gpadc_pdata && pdev->dev.of_node) { ret = palmas_gpadc_get_adc_dt_data(pdev, &gpadc_pdata); if (ret < 0) return ret; } if (!gpadc_pdata) { dev_err(&pdev->dev, "No platform data\n"); return -ENODEV; } iodev = iio_device_alloc(sizeof(*adc)); if (!iodev) { dev_err(&pdev->dev, "iio_device_alloc failed\n"); return -ENOMEM; } if (gpadc_pdata->iio_maps) { ret = iio_map_array_register(iodev, gpadc_pdata->iio_maps); if (ret < 0) { dev_err(&pdev->dev, "iio_map_array_register failed\n"); goto out; } } adc = iio_priv(iodev); adc->dev = &pdev->dev; adc->palmas = dev_get_drvdata(pdev->dev.parent); adc->adc_info = palmas_gpadc_info; init_completion(&adc->conv_completion); dev_set_drvdata(&pdev->dev, iodev); adc->auto_conversion_period = gpadc_pdata->auto_conversion_period_ms; adc->irq = palmas_irq_get_virq(adc->palmas, PALMAS_GPADC_EOC_SW_IRQ); ret = request_threaded_irq(adc->irq, NULL, palmas_gpadc_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_unregister_map; } if (gpadc_pdata->adc_wakeup1_data) { memcpy(&adc->wakeup1_data, gpadc_pdata->adc_wakeup1_data, sizeof(adc->wakeup1_data)); adc->wakeup1_enable = true; adc->irq_auto_0 = platform_get_irq(pdev, 1); ret = request_threaded_irq(adc->irq_auto_0, NULL, palmas_gpadc_irq_auto, IRQF_ONESHOT | IRQF_EARLY_RESUME, "palmas-adc-auto-0", adc); if (ret < 0) { dev_err(adc->dev, "request auto0 irq %d failed: %dn", adc->irq_auto_0, ret); goto out_irq_free; } } if (gpadc_pdata->adc_wakeup2_data) { memcpy(&adc->wakeup2_data, gpadc_pdata->adc_wakeup2_data, sizeof(adc->wakeup2_data)); adc->wakeup2_enable = true; adc->irq_auto_1 = platform_get_irq(pdev, 2); ret = request_threaded_irq(adc->irq_auto_1, NULL, palmas_gpadc_irq_auto, IRQF_ONESHOT | IRQF_EARLY_RESUME, "palmas-adc-auto-1", adc); if (ret < 0) { dev_err(adc->dev, "request auto1 irq %d failed: %dn", adc->irq_auto_1, ret); goto out_irq_auto0_free; } } if (gpadc_pdata->ch0_current == 0) adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_0; else if (gpadc_pdata->ch0_current <= 5) adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_5; else if (gpadc_pdata->ch0_current <= 15) adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_15; else adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_20; if (gpadc_pdata->ch3_current == 0) adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_0; else if (gpadc_pdata->ch3_current <= 10) adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_10; else if (gpadc_pdata->ch3_current <= 400) adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_400; else adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_800; /* If ch3_dual_current is true, it will measure ch3 input signal with * ch3_current and the next current of ch3_current. */ adc->ch3_dual_current = gpadc_pdata->ch3_dual_current; if (adc->ch3_dual_current && (adc->ch3_current == PALMAS_ADC_CH3_CURRENT_SRC_800)) { dev_warn(adc->dev, "Disable ch3_dual_current by wrong current setting\n"); adc->ch3_dual_current = false; } adc->extended_delay = gpadc_pdata->extended_delay; iodev->name = MOD_NAME; iodev->dev.parent = &pdev->dev; iodev->info = &palmas_gpadc_iio_info; iodev->modes = INDIO_DIRECT_MODE; iodev->channels = palmas_gpadc_iio_channel; iodev->num_channels = ARRAY_SIZE(palmas_gpadc_iio_channel); ret = iio_device_register(iodev); if (ret < 0) { dev_err(adc->dev, "iio_device_register() failed: %d\n", ret); goto out_irq_auto1_free; } device_set_wakeup_capable(&pdev->dev, 1); for (i = 0; i < PALMAS_ADC_CH_MAX; i++) { if (!(adc->adc_info[i].is_correct_code)) palmas_gpadc_calibrate(adc, i); } if (adc->wakeup1_enable || adc->wakeup2_enable) device_wakeup_enable(&pdev->dev); return 0; out_irq_auto1_free: if (gpadc_pdata->adc_wakeup2_data) free_irq(adc->irq_auto_1, adc); out_irq_auto0_free: if (gpadc_pdata->adc_wakeup1_data) free_irq(adc->irq_auto_0, adc); out_irq_free: free_irq(adc->irq, adc); out_unregister_map: if (gpadc_pdata->iio_maps) iio_map_array_unregister(iodev); out: iio_device_free(iodev); return ret; }
static int spear_adc_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; struct spear_adc_info *info; struct iio_dev *iodev = NULL; int ret = -ENODEV; int irq; iodev = iio_device_alloc(sizeof(struct spear_adc_info)); if (!iodev) { dev_err(dev, "failed allocating iio device\n"); ret = -ENOMEM; goto errout1; } info = iio_priv(iodev); info->np = np; /* * SPEAr600 has a different register layout than other SPEAr SoC's * (e.g. SPEAr3xx). Let's provide two register base addresses * to support multi-arch kernels. */ info->adc_base_spear6xx = of_iomap(np, 0); if (!info->adc_base_spear6xx) { dev_err(dev, "failed mapping memory\n"); ret = -ENOMEM; goto errout2; } info->adc_base_spear3xx = (struct adc_regs_spear3xx *)info->adc_base_spear6xx; info->clk = clk_get(dev, NULL); if (IS_ERR(info->clk)) { dev_err(dev, "failed getting clock\n"); goto errout3; } ret = clk_prepare_enable(info->clk); if (ret) { dev_err(dev, "failed enabling clock\n"); goto errout4; } irq = platform_get_irq(pdev, 0); if ((irq < 0) || (irq >= NR_IRQS)) { dev_err(dev, "failed getting interrupt resource\n"); ret = -EINVAL; goto errout5; } ret = devm_request_irq(dev, irq, spear_adc_isr, 0, MOD_NAME, info); if (ret < 0) { dev_err(dev, "failed requesting interrupt\n"); goto errout5; } if (of_property_read_u32(np, "sampling-frequency", &info->sampling_freq)) { dev_err(dev, "sampling-frequency missing in DT\n"); ret = -EINVAL; goto errout5; } /* * Optional avg_samples defaults to 0, resulting in single data * conversion */ of_property_read_u32(np, "average-samples", &info->avg_samples); /* * Optional vref_external defaults to 0, resulting in internal vref * selection */ of_property_read_u32(np, "vref-external", &info->vref_external); spear_adc_configure(info); platform_set_drvdata(pdev, iodev); init_completion(&info->completion); iodev->name = MOD_NAME; iodev->dev.parent = dev; iodev->info = &spear_adc_iio_info; iodev->modes = INDIO_DIRECT_MODE; iodev->channels = spear_adc_iio_channels; iodev->num_channels = ARRAY_SIZE(spear_adc_iio_channels); ret = iio_device_register(iodev); if (ret) goto errout5; dev_info(dev, "SPEAR ADC driver loaded, IRQ %d\n", irq); return 0; errout5: clk_disable_unprepare(info->clk); errout4: clk_put(info->clk); errout3: iounmap(info->adc_base_spear6xx); errout2: iio_device_free(iodev); errout1: return ret; }
static int ltr558_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = 0; struct ltr558_chip *chip; struct iio_dev *indio_dev; /* data memory allocation */ indio_dev = iio_device_alloc(sizeof(*chip)); if (indio_dev == NULL) { dev_err(&client->dev, "iio allocation fails\n"); ret = -ENOMEM; goto exit; } chip = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); chip->client = client; chip->irq = client->irq; if (chip->irq > 0) { ret = request_threaded_irq(chip->irq, NULL, threshold_isr, IRQF_SHARED, "LTR558_ALS", chip); if (ret) { dev_err(&client->dev, "Unable to register irq %d; " "ret %d\n", chip->irq, ret); goto exit_iio_free; } } mutex_init(&chip->lock); ret = ltr558_chip_init(client); if (ret) goto exit_irq; indio_dev->info = <r558_info; indio_dev->dev.parent = &client->dev; indio_dev->modes = INDIO_DIRECT_MODE; ret = iio_device_register(indio_dev); if (ret) { dev_err(&client->dev, "iio registration fails\n"); goto exit_irq; } chip->supply[VDD] = regulator_get(&client->dev, "vdd"); if (IS_ERR(chip->supply[VDD])) { dev_err(&client->dev, "could not get vdd regulator\n"); ret = PTR_ERR(chip->supply[VDD]); goto exit_irq; } chip->supply[LED] = regulator_get(&client->dev, "vled"); if (IS_ERR(chip->supply[LED])) { dev_err(&client->dev, "could not get vled regulator\n"); ret = PTR_ERR(chip->supply[LED]); goto exit_irq; } ret = regulator_enable(chip->supply[VDD]); if (ret) { dev_err(&client->dev, "func:%s regulator enable failed\n", __func__); goto exit_irq; } ret = i2c_smbus_read_byte_data(client, LTR558_MANUFACTURER_ID); if (ret < 0) { dev_err(&client->dev, "Err in reading register %d, error %d\n", LTR558_MANUFACTURER_ID, ret); goto exit_irq; } if (ret != LTR_MANUFACTURER_ID) { dev_err(&client->dev, "sensor not found\n"); goto exit_irq; } ret = regulator_disable(chip->supply[VDD]); if (ret) { dev_err(&client->dev, "func:%s regulator disable failed\n", __func__); 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: iio_device_free(indio_dev); exit: return ret; }