[no subject]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I don't think these need to be in the dt -- you can set sane defaults
and then have something under sysfs to change them dynamically later if
necessary.

> +
> +Example:
> +
> +bma180@40 {
> +       compatible = "bosch,bma180";
> +       reg = <0x40>;
> +       interrupt-parent = <&gpio6>;
> +       interrupts = <18 (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING)>;
> +       bosch,bandwidth = <300>;
> +       bosch,resolution = <250>;
> +       bosch,mode = <0>;
> +};

[...]

> +static int bma180_probe(struct i2c_client *client,
> +               const struct i2c_device_id *id)
> +{
> +       struct bma180_data *data;
> +       struct iio_dev *indio_dev;
> +       struct iio_trigger *trig;
> +       struct device_node *np = client->dev.of_node;
> +       int ret;
> +
> +       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> +       if (!indio_dev)
> +               return -ENOMEM;
> +
> +       data = iio_priv(indio_dev);
> +       i2c_set_clientdata(client, indio_dev);
> +       data->client = client;
> +
> +       if (of_property_read_u32(np, "bosch,bandwidth", &data->bw))
> +               data->bw = BMA180_DEF_BW;
> +       if (of_property_read_u32(np, "bosch,resolution", &data->scale))
> +               data->scale = BMA180_DEF_SCALE;
> +       of_property_read_u32(np, "bosch,mode", &data->mode);

What if bosch,mode isn't decribed? It looks like it'll have an
uninitialised value.

> +
> +       ret = bma180_chip_init(data);
> +       if (ret < 0)
> +               goto err_1;
> +
> +       mutex_init(&data->mutex);
> +
> +       indio_dev->dev.parent = &client->dev;
> +       indio_dev->channels = bma180_channels;
> +       indio_dev->num_channels = ARRAY_SIZE(bma180_channels);
> +       indio_dev->name = BMA180_DRV_NAME;
> +       indio_dev->modes = INDIO_DIRECT_MODE;
> +       indio_dev->info = &bma180_info;
> +
> +       trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, indio_dev->id);
> +       if (!trig) {
> +               ret = -ENOMEM;
> +               goto err_1;
> +       }
> +
> +       ret = devm_request_irq(&client->dev, client->irq,
> +                       iio_trigger_generic_data_rdy_poll,
> +                       IRQF_TRIGGER_RISING, BMA180_IRQ_NAME, trig);
> +       if (ret) {
> +               dev_err(&client->dev, "unable to request IRQ\n");
> +               goto err_2;
> +       }
> +
> +       trig->dev.parent = &client->dev;
> +       trig->ops = &bma180_trigger_ops;
> +       iio_trigger_set_drvdata(trig, indio_dev);
> +       data->trig = trig;
> +       indio_dev->trig = trig;
> +
> +       ret = iio_trigger_register(trig);
> +       if (ret)
> +               goto err_2;
> +
> +       ret = iio_triggered_buffer_setup(indio_dev, NULL,
> +                       bma180_trigger_handler, NULL);
> +       if (ret < 0) {
> +               dev_err(&client->dev, "unable to setup iio triggered buffer\n");
> +               goto err_3;
> +       }
> +
> +       ret = iio_device_register(indio_dev);
> +       if (ret < 0) {
> +               dev_err(&client->dev, "unable to register iio device\n");
> +               goto err_4;
> +       }
> +
> +       return 0;
> +
> +err_4:
> +       iio_triggered_buffer_cleanup(indio_dev);
> +err_3:
> +       iio_trigger_unregister(trig);
> +err_2:
> +       iio_trigger_free(trig);
> +err_1:
> +       bma180_chip_disable(data);

It would be nice to have (slightly) clearer labels here, e.g.
err_chip, err_trigger.

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux