static int ad7152_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { struct ad7152_chip_info *chip = iio_priv(indio_dev); int ret, i; mutex_lock(&indio_dev->mlock); switch (mask) { case IIO_CHAN_INFO_CALIBSCALE: if (val != 1) { ret = -EINVAL; goto out; } val = (val2 * 1024) / 15625; ret = i2c_smbus_write_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_GAIN], swab16(val)); if (ret < 0) goto out; ret = 0; break; case IIO_CHAN_INFO_CALIBBIAS: if ((val < 0) | (val > 0xFFFF)) { ret = -EINVAL; goto out; } ret = i2c_smbus_write_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_OFFS], swab16(val)); if (ret < 0) goto out; ret = 0; break; case IIO_CHAN_INFO_SCALE: if (val != 0) { ret = -EINVAL; goto out; } for (i = 0; i < ARRAY_SIZE(ad7152_scale_table); i++) if (val2 == ad7152_scale_table[i]) break; chip->setup[chan->channel] &= ~AD7152_SETUP_RANGE_4pF; chip->setup[chan->channel] |= AD7152_SETUP_RANGE(i); ret = i2c_smbus_write_byte_data(chip->client, ad7152_addresses[chan->channel][AD7152_SETUP], chip->setup[chan->channel]); if (ret < 0) goto out; ret = 0; break; default: ret = -EINVAL; } out: mutex_unlock(&indio_dev->mlock); 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 ade7854_spi_write_reg_8(struct device *dev, u16 reg_address, u8 value) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); struct spi_transfer xfer = { .tx_buf = st->tx, .bits_per_word = 8, .len = 4, }; mutex_lock(&st->buf_lock); st->tx[0] = ADE7854_WRITE_REG; st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; st->tx[3] = value & 0xFF; ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); return ret; } static int ade7854_spi_write_reg_16(struct device *dev, u16 reg_address, u16 value) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); struct spi_transfer xfer = { .tx_buf = st->tx, .bits_per_word = 8, .len = 5, }; mutex_lock(&st->buf_lock); st->tx[0] = ADE7854_WRITE_REG; st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; st->tx[3] = (value >> 8) & 0xFF; st->tx[4] = value & 0xFF; ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); return ret; } static int ade7854_spi_write_reg_24(struct device *dev, u16 reg_address, u32 value) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); struct spi_transfer xfer = { .tx_buf = st->tx, .bits_per_word = 8, .len = 6, }; mutex_lock(&st->buf_lock); st->tx[0] = ADE7854_WRITE_REG; st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; st->tx[3] = (value >> 16) & 0xFF; st->tx[4] = (value >> 8) & 0xFF; st->tx[5] = value & 0xFF; ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); return ret; } static int ade7854_spi_write_reg_32(struct device *dev, u16 reg_address, u32 value) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); struct spi_transfer xfer = { .tx_buf = st->tx, .bits_per_word = 8, .len = 7, }; mutex_lock(&st->buf_lock); st->tx[0] = ADE7854_WRITE_REG; st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; st->tx[3] = (value >> 24) & 0xFF; st->tx[4] = (value >> 16) & 0xFF; st->tx[5] = (value >> 8) & 0xFF; st->tx[6] = value & 0xFF; ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); return ret; } static int ade7854_spi_read_reg_8(struct device *dev, u16 reg_address, u8 *val) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); int ret; struct spi_transfer xfers[] = { { .tx_buf = st->tx, .bits_per_word = 8, .len = 3, }, { .rx_buf = st->rx, .bits_per_word = 8, .len = 1, } };
static int rockchip_saradc_probe(struct platform_device *pdev) { struct rockchip_saradc *info = NULL; struct device_node *np = pdev->dev.of_node; struct iio_dev *indio_dev = NULL; struct resource *mem; const struct of_device_id *match; int ret; int irq; if (!np) return -ENODEV; indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); if (!indio_dev) { dev_err(&pdev->dev, "failed allocating iio device\n"); return -ENOMEM; } info = iio_priv(indio_dev); match = of_match_device(rockchip_saradc_match, &pdev->dev); info->data = match->data; 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); /* * The reset should be an optional property, as it should work * with old devicetrees as well */ info->reset = devm_reset_control_get(&pdev->dev, "saradc-apb"); if (IS_ERR(info->reset)) { ret = PTR_ERR(info->reset); if (ret != -ENOENT) return ret; dev_dbg(&pdev->dev, "no reset control found\n"); info->reset = NULL; } init_completion(&info->completion); irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "no irq resource?\n"); return irq; } ret = devm_request_irq(&pdev->dev, irq, rockchip_saradc_isr, 0, dev_name(&pdev->dev), info); if (ret < 0) { dev_err(&pdev->dev, "failed requesting irq %d\n", irq); return ret; } info->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); if (IS_ERR(info->pclk)) { dev_err(&pdev->dev, "failed to get pclk\n"); return PTR_ERR(info->pclk); } info->clk = devm_clk_get(&pdev->dev, "saradc"); if (IS_ERR(info->clk)) { dev_err(&pdev->dev, "failed to get adc clock\n"); return PTR_ERR(info->clk); } info->vref = devm_regulator_get(&pdev->dev, "vref"); if (IS_ERR(info->vref)) { dev_err(&pdev->dev, "failed to get regulator, %ld\n", PTR_ERR(info->vref)); return PTR_ERR(info->vref); } if (info->reset) rockchip_saradc_reset_controller(info->reset); /* * Use a default value for the converter clock. * This may become user-configurable in the future. */ ret = clk_set_rate(info->clk, info->data->clk_rate); if (ret < 0) { dev_err(&pdev->dev, "failed to set adc clk rate, %d\n", ret); return ret; } ret = regulator_enable(info->vref); if (ret < 0) { dev_err(&pdev->dev, "failed to enable vref regulator\n"); return ret; } ret = clk_prepare_enable(info->pclk); if (ret < 0) { dev_err(&pdev->dev, "failed to enable pclk\n"); goto err_reg_voltage; } ret = clk_prepare_enable(info->clk); if (ret < 0) { dev_err(&pdev->dev, "failed to enable converter clock\n"); goto err_pclk; } platform_set_drvdata(pdev, indio_dev); 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 = &rockchip_saradc_iio_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = info->data->channels; indio_dev->num_channels = info->data->num_channels; ret = iio_device_register(indio_dev); if (ret) goto err_clk; return 0; err_clk: clk_disable_unprepare(info->clk); err_pclk: clk_disable_unprepare(info->pclk); err_reg_voltage: regulator_disable(info->vref); return ret; }
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; }
} return 0; } static const int max1363_event_codes[] = { IIO_EVENT_CODE_IN_LOW_THRESH(3), IIO_EVENT_CODE_IN_HIGH_THRESH(3), IIO_EVENT_CODE_IN_LOW_THRESH(2), IIO_EVENT_CODE_IN_HIGH_THRESH(2), IIO_EVENT_CODE_IN_LOW_THRESH(1), IIO_EVENT_CODE_IN_HIGH_THRESH(1), IIO_EVENT_CODE_IN_LOW_THRESH(0), IIO_EVENT_CODE_IN_HIGH_THRESH(0) }; static irqreturn_t max1363_event_handler(int irq, void *private) { struct iio_dev *indio_dev = private; struct max1363_state *st = iio_priv(indio_dev); s64 timestamp = iio_get_time_ns(); unsigned long mask, loc; u8 rx; u8 tx[2] = { st->setupbyte, MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0 }; i2c_master_recv(st->client, &rx, 1); mask = rx; for_each_set_bit(loc, &mask, 8) iio_push_event(indio_dev, 0, max1363_event_codes[loc], timestamp); i2c_master_send(st->client, tx, 2); return IRQ_HANDLED; }
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; 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; }
IIO_EV_DIR_RISING) | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)), }, { .type = IIO_INTENSITY, .channel = 1, .channel2 = IIO_MOD_LIGHT_IR, .indexed = true, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), }, }; static irqreturn_t apds9300_interrupt_handler(int irq, void *private) { struct iio_dev *dev_info = private; struct apds9300_data *data = iio_priv(dev_info); iio_push_event(dev_info, IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0, IIO_EV_TYPE_THRESH, IIO_EV_DIR_EITHER), iio_get_time_ns()); apds9300_clear_intr(data); return IRQ_HANDLED; } static int apds9300_probe(struct i2c_client *client, const struct i2c_device_id *id) {
static int ad5504_spi_read(struct spi_device *spi, u8 addr, u16 *val) { u16 tmp = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr)); int ret; struct spi_transfer t = { .tx_buf = &tmp, .rx_buf = val, .len = 2, }; struct spi_message m; spi_message_init(&m); spi_message_add_tail(&t, &m); ret = spi_sync(spi, &m); *val = be16_to_cpu(*val) & AD5504_RES_MASK; return ret; } static ssize_t ad5504_write_dac(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); long readin; int ret; ret = strict_strtol(buf, 10, &readin); if (ret) return ret; ret = ad5504_spi_write(st->spi, this_attr->address, readin); return ret ? ret : len; } static ssize_t ad5504_read_dac(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int ret; u16 val; ret = ad5504_spi_read(st->spi, this_attr->address, &val); if (ret) return ret; return sprintf(buf, "%d\n", val); } static ssize_t ad5504_read_powerdown_mode(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); const char mode[][14] = {"20kohm_to_gnd", "three_state"}; return sprintf(buf, "%s\n", mode[st->pwr_down_mode]); } static ssize_t ad5504_write_powerdown_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); int ret; if (sysfs_streq(buf, "20kohm_to_gnd")) st->pwr_down_mode = AD5504_DAC_PWRDN_20K; else if (sysfs_streq(buf, "three_state")) st->pwr_down_mode = AD5504_DAC_PWRDN_3STATE; else ret = -EINVAL; return ret ? ret : len; } static ssize_t ad5504_read_dac_powerdown(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); return sprintf(buf, "%d\n", !(st->pwr_down_mask & (1 << this_attr->address))); } static ssize_t ad5504_write_dac_powerdown(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { long readin; int ret; struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); ret = strict_strtol(buf, 10, &readin); if (ret) return ret; if (readin == 0) st->pwr_down_mask |= (1 << this_attr->address); else if (readin == 1) st->pwr_down_mask &= ~(1 << this_attr->address); else ret = -EINVAL; ret = ad5504_spi_write(st->spi, AD5504_ADDR_CTRL, AD5504_DAC_PWRDWN_MODE(st->pwr_down_mode) | AD5504_DAC_PWR(st->pwr_down_mask)); /* writes to the CTRL register must be followed by a NOOP */ ad5504_spi_write(st->spi, AD5504_ADDR_NOOP, 0); return ret ? ret : len; }
static unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev) { struct st_sensor_data *sdata = iio_priv(indio_dev); return to_spi_device(sdata->dev)->irq; }
static int mlx90614_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *channel, int *val, int *val2, long mask) { struct mlx90614_data *data = iio_priv(indio_dev); u8 cmd; s32 ret; switch (mask) { case IIO_CHAN_INFO_RAW: /* 0.02K / LSB */ switch (channel->channel2) { case IIO_MOD_TEMP_AMBIENT: cmd = MLX90614_TA; break; case IIO_MOD_TEMP_OBJECT: switch (channel->channel) { case 0: cmd = MLX90614_TOBJ1; break; case 1: cmd = MLX90614_TOBJ2; break; default: return -EINVAL; } break; default: return -EINVAL; } ret = mlx90614_power_get(data, true); if (ret < 0) return ret; ret = i2c_smbus_read_word_data(data->client, cmd); mlx90614_power_put(data); if (ret < 0) return ret; /* MSB is an error flag */ if (ret & 0x8000) return -EIO; *val = ret; return IIO_VAL_INT; case IIO_CHAN_INFO_OFFSET: *val = MLX90614_CONST_OFFSET_DEC; *val2 = MLX90614_CONST_OFFSET_REM; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_SCALE: *val = MLX90614_CONST_SCALE; return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/65535 / LSB */ mlx90614_power_get(data, false); mutex_lock(&data->lock); ret = i2c_smbus_read_word_data(data->client, MLX90614_EMISSIVITY); mutex_unlock(&data->lock); mlx90614_power_put(data); if (ret < 0) return ret; if (ret == MLX90614_CONST_RAW_EMISSIVITY_MAX) { *val = 1; *val2 = 0; } else { *val = 0; *val2 = ret * MLX90614_CONST_EMISSIVITY_RESOLUTION; } return IIO_VAL_INT_PLUS_NANO; case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR setting with FIR = 1024 */ mlx90614_power_get(data, false); mutex_lock(&data->lock); ret = i2c_smbus_read_word_data(data->client, MLX90614_CONFIG); mutex_unlock(&data->lock); mlx90614_power_put(data); if (ret < 0) return ret; *val = mlx90614_iir_values[ret & MLX90614_CONFIG_IIR_MASK] / 100; *val2 = (mlx90614_iir_values[ret & MLX90614_CONFIG_IIR_MASK] % 100) * 10000; return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } }
static int isl29018_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { int ret = -EINVAL; struct isl29018_chip *chip = iio_priv(indio_dev); mutex_lock(&chip->lock); if (chip->suspended) { mutex_unlock(&chip->lock); return -EBUSY; } switch (mask) { case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_LIGHT: ret = isl29018_read_lux(chip, val); break; case IIO_INTENSITY: ret = isl29018_read_ir(chip, val); break; case IIO_PROXIMITY: ret = isl29018_read_proximity_ir(chip, chip->prox_scheme, val); break; default: break; } if (!ret) ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_INT_TIME: if (chan->type == IIO_LIGHT) { *val = 0; *val2 = isl29018_int_utimes[chip->type][chip->int_time]; ret = IIO_VAL_INT_PLUS_MICRO; } break; case IIO_CHAN_INFO_SCALE: if (chan->type == IIO_LIGHT) { *val = chip->scale.scale; *val2 = chip->scale.uscale; ret = IIO_VAL_INT_PLUS_MICRO; } break; case IIO_CHAN_INFO_CALIBSCALE: if (chan->type == IIO_LIGHT) { *val = chip->calibscale; *val2 = chip->ucalibscale; ret = IIO_VAL_INT_PLUS_MICRO; } break; default: break; } mutex_unlock(&chip->lock); return ret; }
static int ad7152_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { struct ad7152_chip_info *chip = iio_priv(indio_dev); int ret; u8 regval = 0; mutex_lock(&indio_dev->mlock); switch (mask) { case 0: /* First set whether in differential mode */ regval = chip->setup[chan->channel]; if (chan->differential) chip->setup[chan->channel] |= AD7152_SETUP_CAPDIFF; else chip->setup[chan->channel] &= ~AD7152_SETUP_CAPDIFF; if (regval != chip->setup[chan->channel]) { ret = i2c_smbus_write_byte_data(chip->client, ad7152_addresses[chan->channel][AD7152_SETUP], chip->setup[chan->channel]); if (ret < 0) goto out; } /* Make sure the channel is enabled */ if (chan->channel == 0) regval = AD7152_CONF_CH1EN; else regval = AD7152_CONF_CH2EN; /* Trigger a single read */ regval |= AD7152_CONF_MODE_SINGLE_CONV; ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, regval); if (ret < 0) goto out; msleep(ad7152_filter_rate_table[chip->filter_rate_setup][1]); /* Now read the actual register */ ret = i2c_smbus_read_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_DATA]); if (ret < 0) goto out; *val = swab16(ret); if (chan->differential) *val -= 0x8000; ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_CALIBSCALE: ret = i2c_smbus_read_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_GAIN]); if (ret < 0) goto out; /* 1 + gain_val / 2^16 */ *val = 1; *val2 = (15625 * swab16(ret)) / 1024; ret = IIO_VAL_INT_PLUS_MICRO; break; case IIO_CHAN_INFO_CALIBBIAS: ret = i2c_smbus_read_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_OFFS]); if (ret < 0) goto out; *val = swab16(ret); ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_SCALE: ret = i2c_smbus_read_byte_data(chip->client, ad7152_addresses[chan->channel][AD7152_SETUP]); if (ret < 0) goto out; *val = 0; *val2 = ad7152_scale_table[ret >> 6]; ret = IIO_VAL_INT_PLUS_NANO; break; default: ret = -EINVAL; }; out: mutex_unlock(&indio_dev->mlock); return ret; }
int hmc5843_common_suspend(struct device *dev) { return hmc5843_set_mode(iio_priv(dev_get_drvdata(dev)), HMC5843_MODE_SLEEP); }
return st->pwr_down_mode - 1; } static const struct iio_enum ad5446_powerdown_mode_enum = { .items = ad5446_powerdown_modes, .num_items = ARRAY_SIZE(ad5446_powerdown_modes), .get = ad5446_get_powerdown_mode, .set = ad5446_set_powerdown_mode, }; static ssize_t ad5446_read_dac_powerdown(struct iio_dev *indio_dev, uintptr_t private, const struct iio_chan_spec *chan, char *buf) { struct ad5446_state *st = iio_priv(indio_dev); return sprintf(buf, "%d\n", st->pwr_down); } static ssize_t ad5446_write_dac_powerdown(struct iio_dev *indio_dev, uintptr_t private, const struct iio_chan_spec *chan, const char *buf, size_t len) { struct ad5446_state *st = iio_priv(indio_dev); unsigned int shift; unsigned int val; bool powerdown; int ret;
int hmc5843_common_resume(struct device *dev) { return hmc5843_set_mode(iio_priv(dev_get_drvdata(dev)), HMC5843_MODE_CONVERSION_CONTINUOUS); }
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 = devm_iio_device_alloc(dev, sizeof(struct spear_adc_info)); if (!iodev) { dev_err(dev, "failed allocating iio device\n"); return -ENOMEM; } 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"); return -ENOMEM; } info->adc_base_spear3xx = (struct adc_regs_spear3xx __iomem *)info->adc_base_spear6xx; info->clk = clk_get(dev, NULL); if (IS_ERR(info->clk)) { dev_err(dev, "failed getting clock\n"); goto errout1; } ret = clk_prepare_enable(info->clk); if (ret) { dev_err(dev, "failed enabling clock\n"); goto errout2; } irq = platform_get_irq(pdev, 0); if (irq <= 0) { dev_err(dev, "failed getting interrupt resource\n"); ret = -EINVAL; goto errout3; } ret = devm_request_irq(dev, irq, spear_adc_isr, 0, MOD_NAME, info); if (ret < 0) { dev_err(dev, "failed requesting interrupt\n"); goto errout3; } if (of_property_read_u32(np, "sampling-frequency", &info->sampling_freq)) { dev_err(dev, "sampling-frequency missing in DT\n"); ret = -EINVAL; goto errout3; } /* * 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 errout3; dev_info(dev, "SPEAR ADC driver loaded, IRQ %d\n", irq); return 0; errout3: clk_disable_unprepare(info->clk); errout2: clk_put(info->clk); errout1: iounmap(info->adc_base_spear6xx); return ret; }
static int max1363_read_single_chan(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, long m) { int ret = 0; s32 data; char rxbuf[2]; long mask; struct max1363_state *st = iio_priv(indio_dev); struct i2c_client *client = st->client; mutex_lock(&indio_dev->mlock); /* * If monitor mode is enabled, the method for reading a single * channel will have to be rather different and has not yet * been implemented. */ if (st->monitor_on) { ret = -EBUSY; goto error_ret; } /* If ring buffer capture is occurring, query the buffer */ if (iio_ring_enabled(indio_dev)) { mask = max1363_mode_table[chan->address].modemask; data = max1363_single_channel_from_ring(mask, st); if (data < 0) { ret = data; goto error_ret; } } else { /* Check to see if current scan mode is correct */ if (st->current_mode != &max1363_mode_table[chan->address]) { /* Update scan mode if needed */ st->current_mode = &max1363_mode_table[chan->address]; ret = max1363_set_scan_mode(st); if (ret < 0) goto error_ret; } if (st->chip_info->bits != 8) { /* Get reading */ data = i2c_master_recv(client, rxbuf, 2); if (data < 0) { ret = data; goto error_ret; } data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8; } else { /* Get reading */ data = i2c_master_recv(client, rxbuf, 1); if (data < 0) { ret = data; goto error_ret; } data = rxbuf[0]; } } *val = data; error_ret: mutex_unlock(&indio_dev->mlock); return ret; }
iio_push_to_buffers(idev, (u8 *)st->buffer); iio_trigger_notify_done(idev->trig); /* Needed to ACK the DRDY interruption */ at91_adc_readl(st, AT91_ADC_LCDR); enable_irq(st->irq); return IRQ_HANDLED; } static irqreturn_t at91_adc_eoc_trigger(int irq, void *private) { struct iio_dev *idev = private; struct at91_adc_state *st = iio_priv(idev); u32 status = at91_adc_readl(st, st->registers->status_register); if (!(status & st->registers->drdy_mask)) return IRQ_HANDLED; if (iio_buffer_enabled(idev)) { disable_irq_nosync(irq); iio_trigger_poll(idev->trig, iio_get_time_ns()); } else { st->last_value = at91_adc_readl(st, AT91_ADC_LCDR); st->done = true; wake_up_interruptible(&st->wq_data_avail); } return IRQ_HANDLED;
* combine_8_to_16() utility function to munge to u8s into u16 **/ static inline u16 combine_8_to_16(u8 lower, u8 upper) { u16 _lower = lower; u16 _upper = upper; return _lower | (_upper << 8); } /** * lis3l02dq_data_rdy_trig_poll() the event handler for the data rdy trig **/ irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private) { struct iio_dev *indio_dev = private; struct lis3l02dq_state *st = iio_priv(indio_dev); if (st->trigger_on) { iio_trigger_poll(st->trig, iio_get_time_ns()); return IRQ_HANDLED; } else return IRQ_WAKE_THREAD; } static const u8 read_all_tx_array[] = { LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_X_L_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_X_H_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Y_L_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Y_H_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Z_L_ADDR), 0, LIS3L02DQ_READ_REG(LIS3L02DQ_REG_OUT_Z_H_ADDR), 0,
int st_accel_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *adata = iio_priv(indio_dev); int irq = adata->get_irq_data_ready(indio_dev); int err; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &accel_info; mutex_init(&adata->tb.buf_lock); err = st_sensors_power_enable(indio_dev); if (err) return err; err = st_sensors_check_device_support(indio_dev, ARRAY_SIZE(st_accel_sensors_settings), st_accel_sensors_settings); if (err < 0) goto st_accel_power_off; adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; adata->multiread_bit = adata->sensor_settings->multi_read_bit; indio_dev->channels = adata->sensor_settings->ch; indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; adata->current_fullscale = (struct st_sensor_fullscale_avl *) &adata->sensor_settings->fs.fs_avl[0]; adata->odr = adata->sensor_settings->odr.odr_avl[0].hz; if (!adata->dev->platform_data) adata->dev->platform_data = (struct st_sensors_platform_data *)&default_accel_pdata; err = st_sensors_init_sensor(indio_dev, adata->dev->platform_data); if (err < 0) goto st_accel_power_off; err = st_accel_allocate_ring(indio_dev); if (err < 0) goto st_accel_power_off; if (irq > 0) { err = st_sensors_allocate_trigger(indio_dev, ST_ACCEL_TRIGGER_OPS); if (err < 0) goto st_accel_probe_trigger_error; } err = iio_device_register(indio_dev); if (err) goto st_accel_device_register_error; dev_info(&indio_dev->dev, "registered accelerometer %s\n", indio_dev->name); return 0; st_accel_device_register_error: if (irq > 0) st_sensors_deallocate_trigger(indio_dev); st_accel_probe_trigger_error: st_accel_deallocate_ring(indio_dev); st_accel_power_off: st_sensors_power_disable(indio_dev); return err; }
{ int ret; ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); if (ret < 0) return ret; ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, ret | NAU7802_PUCTRL_CS_BIT); return ret; } static irqreturn_t nau7802_eoc_trigger(int irq, void *private) { struct iio_dev *indio_dev = private; struct nau7802_state *st = iio_priv(indio_dev); int status; status = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); if (status < 0) return IRQ_HANDLED; if (!(status & NAU7802_PUCTRL_CR_BIT)) return IRQ_NONE; if (nau7802_read_conversion(st) < 0) return IRQ_HANDLED; /* * Because there is actually only one ADC for both channels, we have to * wait for enough conversions to happen before getting a significant
static int exynos_adc_probe(struct platform_device *pdev) { struct exynos_adc *info = NULL; struct device_node *np = pdev->dev.of_node; struct s3c2410_ts_mach_info *pdata = dev_get_platdata(&pdev->dev); struct iio_dev *indio_dev = NULL; struct resource *mem; bool has_ts = false; int ret = -ENODEV; int irq; indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct exynos_adc)); if (!indio_dev) { dev_err(&pdev->dev, "failed allocating iio device\n"); return -ENOMEM; } info = iio_priv(indio_dev); info->data = exynos_adc_get_data(pdev); if (!info->data) { dev_err(&pdev->dev, "failed getting exynos_adc_data\n"); return -EINVAL; } 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); if (info->data->needs_adc_phy) { info->pmu_map = syscon_regmap_lookup_by_phandle( pdev->dev.of_node, "samsung,syscon-phandle"); if (IS_ERR(info->pmu_map)) { dev_err(&pdev->dev, "syscon regmap lookup failed.\n"); return PTR_ERR(info->pmu_map); } } irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "no irq resource?\n"); return irq; } info->irq = irq; irq = platform_get_irq(pdev, 1); if (irq == -EPROBE_DEFER) return irq; info->tsirq = irq; info->dev = &pdev->dev; init_completion(&info->completion); 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); } if (info->data->needs_sclk) { info->sclk = devm_clk_get(&pdev->dev, "sclk"); if (IS_ERR(info->sclk)) { dev_err(&pdev->dev, "failed getting sclk clock, err = %ld\n", PTR_ERR(info->sclk)); return PTR_ERR(info->sclk); } } info->vdd = devm_regulator_get(&pdev->dev, "vdd"); if (IS_ERR(info->vdd)) { dev_err(&pdev->dev, "failed getting regulator, err = %ld\n", PTR_ERR(info->vdd)); return PTR_ERR(info->vdd); } ret = regulator_enable(info->vdd); if (ret) return ret; ret = exynos_adc_prepare_clk(info); if (ret) goto err_disable_reg; ret = exynos_adc_enable_clk(info); if (ret) goto err_unprepare_clk; platform_set_drvdata(pdev, indio_dev); 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 = &exynos_adc_iio_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = exynos_adc_iio_channels; indio_dev->num_channels = info->data->num_channels; ret = request_irq(info->irq, exynos_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_disable_clk; } ret = iio_device_register(indio_dev); if (ret) goto err_irq; if (info->data->init_hw) info->data->init_hw(info); /* leave out any TS related code if unreachable */ if (IS_REACHABLE(CONFIG_INPUT)) { has_ts = of_property_read_bool(pdev->dev.of_node, "has-touchscreen") || pdata; } if (pdata) info->delay = pdata->delay; else info->delay = 10000; if (has_ts) ret = exynos_adc_ts_init(info); if (ret) goto err_iio; ret = of_platform_populate(np, exynos_adc_match, NULL, &indio_dev->dev); if (ret < 0) { dev_err(&pdev->dev, "failed adding child nodes\n"); goto err_of_populate; } return 0; err_of_populate: device_for_each_child(&indio_dev->dev, NULL, exynos_adc_remove_devices); if (has_ts) { input_unregister_device(info->input); free_irq(info->tsirq, info); } err_iio: iio_device_unregister(indio_dev); err_irq: free_irq(info->irq, info); err_disable_clk: if (info->data->exit_hw) info->data->exit_hw(info); exynos_adc_disable_clk(info); err_unprepare_clk: exynos_adc_unprepare_clk(info); err_disable_reg: regulator_disable(info->vdd); return ret; }
/** * inv_mpu_probe() - probe function. * @client: i2c client. * @id: i2c device id. * * Returns 0 on success, a negative error code otherwise. */ static int inv_mpu_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct inv_mpu6050_state *st; int result, chip_type; struct regmap *regmap; const char *name; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) return -EOPNOTSUPP; if (id) { chip_type = (int)id->driver_data; name = id->name; } else if (ACPI_HANDLE(&client->dev)) { name = inv_mpu_match_acpi_device(&client->dev, &chip_type); if (!name) return -ENODEV; } else { return -ENOSYS; } regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); if (IS_ERR(regmap)) { dev_err(&client->dev, "Failed to register i2c regmap %d\n", (int)PTR_ERR(regmap)); return PTR_ERR(regmap); } result = inv_mpu_core_probe(regmap, client->irq, name, NULL, chip_type); if (result < 0) return result; st = iio_priv(dev_get_drvdata(&client->dev)); st->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, I2C_MUX_LOCKED | I2C_MUX_GATE, inv_mpu6050_select_bypass, inv_mpu6050_deselect_bypass); if (!st->muxc) { result = -ENOMEM; goto out_unreg_device; } st->muxc->priv = dev_get_drvdata(&client->dev); result = i2c_mux_add_adapter(st->muxc, 0, 0, 0); if (result) goto out_unreg_device; result = inv_mpu_acpi_create_mux_client(client); if (result) goto out_del_mux; return 0; out_del_mux: i2c_mux_del_adapters(st->muxc); out_unreg_device: inv_mpu_core_remove(&client->dev); return result; }
static int yas_data_rdy_trig_poll(struct iio_dev *indio_dev) { struct yas_state *st = iio_priv(indio_dev); iio_trigger_poll(st->trig, iio_get_time_ns()); return 0; }
static int adis16209_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { struct adis *st = iio_priv(indio_dev); int ret; int bits; u8 addr; s16 val16; switch (mask) { case IIO_CHAN_INFO_RAW: return adis_single_conversion(indio_dev, chan, ADIS16209_ERROR_ACTIVE, val); case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: *val = 0; switch (chan->channel) { case 0: *val2 = 305180; /* 0.30518 mV */ break; case 1: *val2 = 610500; /* 0.6105 mV */ break; default: return -EINVAL; } return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP: *val = -470; *val2 = 0; return IIO_VAL_INT_PLUS_MICRO; case IIO_ACCEL: /* * IIO base unit for sensitivity of accelerometer * is milli g. * 1 LSB represents 0.244 mg. */ *val = 0; *val2 = IIO_G_TO_M_S_2(244140); return IIO_VAL_INT_PLUS_NANO; case IIO_INCLI: case IIO_ROT: /* * IIO base units for rotation are degrees. * 1 LSB represents 0.025 milli degrees. */ *val = 0; *val2 = 25000; return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } break; case IIO_CHAN_INFO_OFFSET: /* * The raw ADC value is 0x4FE when the temperature * is 25 degrees and the scale factor per milli * degree celcius is -470. */ *val = 25000 / -470 - 0x4FE; return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBBIAS: switch (chan->type) { case IIO_ACCEL: bits = 14; break; default: return -EINVAL; } addr = adis16209_addresses[chan->scan_index][0]; ret = adis_read_reg_16(st, addr, &val16); if (ret) return ret; *val = sign_extend32(val16, bits - 1); return IIO_VAL_INT; } return -EINVAL; }
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; }
int st_press_common_probe(struct iio_dev *indio_dev) { struct st_sensor_data *press_data = iio_priv(indio_dev); int irq = press_data->get_irq_data_ready(indio_dev); int err; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &press_info; mutex_init(&press_data->tb.buf_lock); err = st_sensors_power_enable(indio_dev); if (err) return err; err = st_sensors_check_device_support(indio_dev, ARRAY_SIZE(st_press_sensors_settings), st_press_sensors_settings); if (err < 0) goto st_press_power_off; /* * Skip timestamping channel while declaring available channels to * common st_sensor layer. Look at st_sensors_get_buffer_element() to * see how timestamps are explicitly pushed as last samples block * element. */ press_data->num_data_channels = press_data->sensor_settings->num_ch - 1; press_data->multiread_bit = press_data->sensor_settings->multi_read_bit; indio_dev->channels = press_data->sensor_settings->ch; indio_dev->num_channels = press_data->sensor_settings->num_ch; press_data->current_fullscale = (struct st_sensor_fullscale_avl *) &press_data->sensor_settings->fs.fs_avl[0]; press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz; /* Some devices don't support a data ready pin. */ if (!press_data->dev->platform_data && press_data->sensor_settings->drdy_irq.addr) press_data->dev->platform_data = (struct st_sensors_platform_data *)&default_press_pdata; err = st_sensors_init_sensor(indio_dev, press_data->dev->platform_data); if (err < 0) goto st_press_power_off; err = st_press_allocate_ring(indio_dev); if (err < 0) goto st_press_power_off; if (irq > 0) { err = st_sensors_allocate_trigger(indio_dev, ST_PRESS_TRIGGER_OPS); if (err < 0) goto st_press_probe_trigger_error; } err = iio_device_register(indio_dev); if (err) goto st_press_device_register_error; dev_info(&indio_dev->dev, "registered pressure sensor %s\n", indio_dev->name); return err; st_press_device_register_error: if (irq > 0) st_sensors_deallocate_trigger(indio_dev); st_press_probe_trigger_error: st_press_deallocate_ring(indio_dev); st_press_power_off: st_sensors_power_disable(indio_dev); return err; }
static int isl29018_chip_init(struct i2c_client *client) { struct isl29018_chip *chip = iio_priv(i2c_get_clientdata(client)); int status; int new_adc_bit; unsigned int new_range; memset(chip->reg_cache, 0, sizeof(chip->reg_cache)); /* Code added per Intersil Application Note 1534: * When VDD sinks to approximately 1.8V or below, some of * the part's registers may change their state. When VDD * recovers to 2.25V (or greater), the part may thus be in an * unknown mode of operation. The user can return the part to * a known mode of operation either by (a) setting VDD = 0V for * 1 second or more and then powering back up with a slew rate * of 0.5V/ms or greater, or (b) via I2C disable all ALS/PROX * conversions, clear the test registers, and then rewrite all * registers to the desired values. * ... * FOR ISL29011, ISL29018, ISL29021, ISL29023 * 1. Write 0x00 to register 0x08 (TEST) * 2. Write 0x00 to register 0x00 (CMD1) * 3. Rewrite all registers to the desired values * * ISL29018 Data Sheet (FN6619.1, Feb 11, 2010) essentially says * the same thing EXCEPT the data sheet asks for a 1ms delay after * writing the CMD1 register. */ status = isl29018_write_data(client, ISL29018_REG_TEST, 0, ISL29018_TEST_MASK, ISL29018_TEST_SHIFT); if (status < 0) { dev_err(&client->dev, "Failed to clear isl29018 TEST reg." "(%d)\n", status); return status; } /* See Intersil AN1534 comments above. * "Operating Mode" (COMMAND1) register is reprogrammed when * data is read from the device. */ status = isl29018_write_data(client, ISL29018_REG_ADD_COMMAND1, 0, 0xff, 0); if (status < 0) { dev_err(&client->dev, "Failed to clear isl29018 CMD1 reg." "(%d)\n", status); return status; } msleep(1); /* per data sheet, page 10 */ /* set defaults */ status = isl29018_set_range(client, chip->range, &new_range); if (status < 0) { dev_err(&client->dev, "Init of isl29018 fails\n"); return status; } status = isl29018_set_resolution(client, chip->adc_bit, &new_adc_bit); return 0; }