| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 3-axis accelerometer driver supporting following Bosch-Sensortec chips: |
|---|
| 3 | 4 | * - BMC150 |
|---|
| .. | .. |
|---|
| 8 | 9 | * - BMA280 |
|---|
| 9 | 10 | * |
|---|
| 10 | 11 | * Copyright (c) 2014, Intel Corporation. |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 13 | | - * under the terms and conditions of the GNU General Public License, |
|---|
| 14 | | - * version 2, as published by the Free Software Foundation. |
|---|
| 15 | | - * |
|---|
| 16 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 17 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 18 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 19 | | - * more details. |
|---|
| 20 | 12 | */ |
|---|
| 21 | 13 | |
|---|
| 22 | 14 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 212 | 204 | int ev_enable_state; |
|---|
| 213 | 205 | int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */ |
|---|
| 214 | 206 | const struct bmc150_accel_chip_info *chip_info; |
|---|
| 207 | + struct iio_mount_matrix orientation; |
|---|
| 215 | 208 | }; |
|---|
| 216 | 209 | |
|---|
| 217 | 210 | static const struct { |
|---|
| .. | .. |
|---|
| 401 | 394 | |
|---|
| 402 | 395 | if (ret < 0) { |
|---|
| 403 | 396 | dev_err(dev, |
|---|
| 404 | | - "Failed: bmc150_accel_set_power_state for %d\n", on); |
|---|
| 397 | + "Failed: %s for %d\n", __func__, on); |
|---|
| 405 | 398 | if (on) |
|---|
| 406 | 399 | pm_runtime_put_noidle(dev); |
|---|
| 407 | 400 | |
|---|
| .. | .. |
|---|
| 804 | 797 | return sprintf(buf, "%d\n", state); |
|---|
| 805 | 798 | } |
|---|
| 806 | 799 | |
|---|
| 800 | +static const struct iio_mount_matrix * |
|---|
| 801 | +bmc150_accel_get_mount_matrix(const struct iio_dev *indio_dev, |
|---|
| 802 | + const struct iio_chan_spec *chan) |
|---|
| 803 | +{ |
|---|
| 804 | + struct bmc150_accel_data *data = iio_priv(indio_dev); |
|---|
| 805 | + |
|---|
| 806 | + return &data->orientation; |
|---|
| 807 | +} |
|---|
| 808 | + |
|---|
| 809 | +static const struct iio_chan_spec_ext_info bmc150_accel_ext_info[] = { |
|---|
| 810 | + IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, bmc150_accel_get_mount_matrix), |
|---|
| 811 | + { } |
|---|
| 812 | +}; |
|---|
| 813 | + |
|---|
| 807 | 814 | static IIO_CONST_ATTR(hwfifo_watermark_min, "1"); |
|---|
| 808 | 815 | static IIO_CONST_ATTR(hwfifo_watermark_max, |
|---|
| 809 | 816 | __stringify(BMC150_ACCEL_FIFO_LENGTH)); |
|---|
| .. | .. |
|---|
| 987 | 994 | .shift = 16 - (bits), \ |
|---|
| 988 | 995 | .endianness = IIO_LE, \ |
|---|
| 989 | 996 | }, \ |
|---|
| 997 | + .ext_info = bmc150_accel_ext_info, \ |
|---|
| 990 | 998 | .event_spec = &bmc150_accel_event, \ |
|---|
| 991 | 999 | .num_event_specs = 1 \ |
|---|
| 992 | 1000 | } |
|---|
| .. | .. |
|---|
| 1412 | 1420 | int ret = 0; |
|---|
| 1413 | 1421 | |
|---|
| 1414 | 1422 | if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) |
|---|
| 1415 | | - return iio_triggered_buffer_postenable(indio_dev); |
|---|
| 1423 | + return 0; |
|---|
| 1416 | 1424 | |
|---|
| 1417 | 1425 | mutex_lock(&data->mutex); |
|---|
| 1418 | 1426 | |
|---|
| .. | .. |
|---|
| 1444 | 1452 | struct bmc150_accel_data *data = iio_priv(indio_dev); |
|---|
| 1445 | 1453 | |
|---|
| 1446 | 1454 | if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) |
|---|
| 1447 | | - return iio_triggered_buffer_predisable(indio_dev); |
|---|
| 1455 | + return 0; |
|---|
| 1448 | 1456 | |
|---|
| 1449 | 1457 | mutex_lock(&data->mutex); |
|---|
| 1450 | 1458 | |
|---|
| .. | .. |
|---|
| 1564 | 1572 | |
|---|
| 1565 | 1573 | data->regmap = regmap; |
|---|
| 1566 | 1574 | |
|---|
| 1575 | + ret = iio_read_mount_matrix(dev, "mount-matrix", |
|---|
| 1576 | + &data->orientation); |
|---|
| 1577 | + if (ret) |
|---|
| 1578 | + return ret; |
|---|
| 1579 | + |
|---|
| 1567 | 1580 | ret = bmc150_accel_chip_init(data); |
|---|
| 1568 | 1581 | if (ret < 0) |
|---|
| 1569 | 1582 | return ret; |
|---|
| 1570 | 1583 | |
|---|
| 1571 | 1584 | mutex_init(&data->mutex); |
|---|
| 1572 | 1585 | |
|---|
| 1573 | | - indio_dev->dev.parent = dev; |
|---|
| 1574 | 1586 | indio_dev->channels = data->chip_info->channels; |
|---|
| 1575 | 1587 | indio_dev->num_channels = data->chip_info->num_channels; |
|---|
| 1576 | 1588 | indio_dev->name = name ? name : data->chip_info->name; |
|---|
| .. | .. |
|---|
| 1636 | 1648 | ret = iio_device_register(indio_dev); |
|---|
| 1637 | 1649 | if (ret < 0) { |
|---|
| 1638 | 1650 | dev_err(dev, "Unable to register iio device\n"); |
|---|
| 1639 | | - goto err_trigger_unregister; |
|---|
| 1651 | + goto err_pm_cleanup; |
|---|
| 1640 | 1652 | } |
|---|
| 1641 | 1653 | |
|---|
| 1642 | 1654 | return 0; |
|---|
| 1643 | 1655 | |
|---|
| 1656 | +err_pm_cleanup: |
|---|
| 1657 | + pm_runtime_dont_use_autosuspend(dev); |
|---|
| 1658 | + pm_runtime_disable(dev); |
|---|
| 1644 | 1659 | err_trigger_unregister: |
|---|
| 1645 | 1660 | bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1); |
|---|
| 1646 | 1661 | err_buffer_cleanup: |
|---|