static ssize_t hmc5843_set_measurement_configuration(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); struct hmc5843_data *data = iio_priv(indio_dev); unsigned long meas_conf = 0; int error; error = kstrtoul(buf, 10, &meas_conf); if (error) return error; if (meas_conf >= HMC5843_MEAS_CONF_NOT_USED) return -EINVAL; mutex_lock(&data->lock); dev_dbg(dev, "set measurement configuration to %lu\n", meas_conf); if (hmc5843_set_meas_conf(client, meas_conf)) { count = -EINVAL; goto exit; } data->meas_conf = meas_conf; exit: mutex_unlock(&data->lock); return count; }
static ssize_t hmc5843_set_measurement_configuration(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); struct hmc5843_data *data = i2c_get_clientdata(client); unsigned long meas_conf = 0; int error = strict_strtoul(buf, 10, &meas_conf); if (error) return error; mutex_lock(&data->lock); dev_dbg(dev, "set mode to %lu\n", meas_conf); if (hmc5843_set_meas_conf(client, meas_conf)) { count = -EINVAL; goto exit; } data->meas_conf = meas_conf; exit: mutex_unlock(&data->lock); return count; }
static int hmc5843_init(struct hmc5843_data *data) { int ret; u8 id[3]; ret = regmap_bulk_read(data->regmap, HMC5843_ID_REG, id, ARRAY_SIZE(id)); if (ret < 0) return ret; if (id[0] != 'H' || id[1] != '4' || id[2] != '3') { dev_err(data->dev, "no HMC5843/5883/5883L/5983 sensor\n"); return -ENODEV; } ret = hmc5843_set_meas_conf(data, HMC5843_MEAS_CONF_NORMAL); if (ret < 0) return ret; ret = hmc5843_set_samp_freq(data, HMC5843_RATE_DEFAULT); if (ret < 0) return ret; ret = hmc5843_set_range_gain(data, HMC5843_RANGE_GAIN_DEFAULT); if (ret < 0) return ret; return hmc5843_set_mode(data, HMC5843_MODE_CONVERSION_CONTINUOUS); }
static int hmc5843_set_measurement_configuration(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, unsigned int meas_conf) { struct hmc5843_data *data = iio_priv(indio_dev); return hmc5843_set_meas_conf(data, meas_conf); }
/* Called when we have found a new HMC5843. */ static void hmc5843_init_client(struct i2c_client *client) { struct hmc5843_data *data = i2c_get_clientdata(client); hmc5843_set_meas_conf(client, data->meas_conf); hmc5843_set_rate(client, data->rate); hmc5843_configure(client, data->operating_mode); i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_B, data->range); mutex_init(&data->lock); pr_info("HMC5843 initialized\n"); }
/* Called when we have found a new HMC58X3 */ static void hmc5843_init_client(struct i2c_client *client, const struct i2c_device_id *id) { struct iio_dev *indio_dev = i2c_get_clientdata(client); struct hmc5843_data *data = iio_priv(indio_dev); data->variant = &hmc5843_chip_info_tbl[id->driver_data]; indio_dev->channels = data->variant->channels; indio_dev->num_channels = 3; hmc5843_set_meas_conf(client, data->meas_conf); hmc5843_set_rate(client, data->rate); hmc5843_configure(client, data->operating_mode); i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_B, data->range); mutex_init(&data->lock); pr_info("%s initialized\n", id->name); }
static ssize_t hmc5843_set_measurement_configuration(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct hmc5843_data *data = iio_priv(dev_to_iio_dev(dev)); unsigned long meas_conf = 0; int ret; ret = kstrtoul(buf, 10, &meas_conf); if (ret) return ret; if (meas_conf >= HMC5843_MEAS_CONF_MASK) return -EINVAL; ret = hmc5843_set_meas_conf(data, meas_conf); return (ret < 0) ? ret : count; }