.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * KXCJK-1013 3-axis accelerometer driver |
---|
3 | 4 | * Copyright (c) 2014, Intel Corporation. |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify it |
---|
6 | | - * under the terms and conditions of the GNU General Public License, |
---|
7 | | - * version 2, as published by the Free Software Foundation. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
---|
10 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
11 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
12 | | - * more details. |
---|
13 | 5 | */ |
---|
14 | 6 | |
---|
15 | 7 | #include <linux/module.h> |
---|
.. | .. |
---|
151 | 143 | struct i2c_client *client; |
---|
152 | 144 | struct iio_trigger *dready_trig; |
---|
153 | 145 | struct iio_trigger *motion_trig; |
---|
| 146 | + struct iio_mount_matrix orientation; |
---|
154 | 147 | struct mutex mutex; |
---|
155 | 148 | /* Ensure timestamp naturally aligned */ |
---|
156 | 149 | struct { |
---|
.. | .. |
---|
494 | 487 | } |
---|
495 | 488 | if (ret < 0) { |
---|
496 | 489 | dev_err(&data->client->dev, |
---|
497 | | - "Failed: kxcjk1013_set_power_state for %d\n", on); |
---|
| 490 | + "Failed: %s for %d\n", __func__, on); |
---|
498 | 491 | if (on) |
---|
499 | 492 | pm_runtime_put_noidle(&data->client->dev); |
---|
500 | 493 | return ret; |
---|
.. | .. |
---|
1034 | 1027 | BIT(IIO_EV_INFO_PERIOD) |
---|
1035 | 1028 | }; |
---|
1036 | 1029 | |
---|
| 1030 | +static const struct iio_mount_matrix * |
---|
| 1031 | +kxcjk1013_get_mount_matrix(const struct iio_dev *indio_dev, |
---|
| 1032 | + const struct iio_chan_spec *chan) |
---|
| 1033 | +{ |
---|
| 1034 | + struct kxcjk1013_data *data = iio_priv(indio_dev); |
---|
| 1035 | + |
---|
| 1036 | + return &data->orientation; |
---|
| 1037 | +} |
---|
| 1038 | + |
---|
| 1039 | +static const struct iio_chan_spec_ext_info kxcjk1013_ext_info[] = { |
---|
| 1040 | + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, kxcjk1013_get_mount_matrix), |
---|
| 1041 | + { } |
---|
| 1042 | +}; |
---|
| 1043 | + |
---|
1037 | 1044 | #define KXCJK1013_CHANNEL(_axis) { \ |
---|
1038 | 1045 | .type = IIO_ACCEL, \ |
---|
1039 | 1046 | .modified = 1, \ |
---|
.. | .. |
---|
1050 | 1057 | .endianness = IIO_LE, \ |
---|
1051 | 1058 | }, \ |
---|
1052 | 1059 | .event_spec = &kxcjk1013_event, \ |
---|
| 1060 | + .ext_info = kxcjk1013_ext_info, \ |
---|
1053 | 1061 | .num_event_specs = 1 \ |
---|
1054 | 1062 | } |
---|
1055 | 1063 | |
---|
.. | .. |
---|
1062 | 1070 | |
---|
1063 | 1071 | static const struct iio_buffer_setup_ops kxcjk1013_buffer_setup_ops = { |
---|
1064 | 1072 | .preenable = kxcjk1013_buffer_preenable, |
---|
1065 | | - .postenable = iio_triggered_buffer_postenable, |
---|
1066 | 1073 | .postdisable = kxcjk1013_buffer_postdisable, |
---|
1067 | | - .predisable = iio_triggered_buffer_predisable, |
---|
1068 | 1074 | }; |
---|
1069 | 1075 | |
---|
1070 | 1076 | static const struct iio_info kxcjk1013_info = { |
---|
.. | .. |
---|
1320 | 1326 | data->client = client; |
---|
1321 | 1327 | |
---|
1322 | 1328 | pdata = dev_get_platdata(&client->dev); |
---|
1323 | | - if (pdata) |
---|
| 1329 | + if (pdata) { |
---|
1324 | 1330 | data->active_high_intr = pdata->active_high_intr; |
---|
1325 | | - else |
---|
| 1331 | + data->orientation = pdata->orientation; |
---|
| 1332 | + } else { |
---|
1326 | 1333 | data->active_high_intr = true; /* default polarity */ |
---|
| 1334 | + |
---|
| 1335 | + ret = iio_read_mount_matrix(&client->dev, "mount-matrix", |
---|
| 1336 | + &data->orientation); |
---|
| 1337 | + if (ret) |
---|
| 1338 | + return ret; |
---|
| 1339 | + } |
---|
1327 | 1340 | |
---|
1328 | 1341 | if (id) { |
---|
1329 | 1342 | data->chipset = (enum kx_chipset)(id->driver_data); |
---|
.. | .. |
---|
1341 | 1354 | |
---|
1342 | 1355 | mutex_init(&data->mutex); |
---|
1343 | 1356 | |
---|
1344 | | - indio_dev->dev.parent = &client->dev; |
---|
1345 | 1357 | indio_dev->channels = kxcjk1013_channels; |
---|
1346 | 1358 | indio_dev->num_channels = ARRAY_SIZE(kxcjk1013_channels); |
---|
1347 | 1359 | indio_dev->available_scan_masks = kxcjk1013_scan_masks; |
---|
.. | .. |
---|
1417 | 1429 | ret = iio_device_register(indio_dev); |
---|
1418 | 1430 | if (ret < 0) { |
---|
1419 | 1431 | dev_err(&client->dev, "unable to register iio device\n"); |
---|
1420 | | - goto err_buffer_cleanup; |
---|
| 1432 | + goto err_pm_cleanup; |
---|
1421 | 1433 | } |
---|
1422 | 1434 | |
---|
1423 | 1435 | return 0; |
---|
1424 | 1436 | |
---|
| 1437 | +err_pm_cleanup: |
---|
| 1438 | + pm_runtime_dont_use_autosuspend(&client->dev); |
---|
| 1439 | + pm_runtime_disable(&client->dev); |
---|
1425 | 1440 | err_buffer_cleanup: |
---|
1426 | 1441 | iio_triggered_buffer_cleanup(indio_dev); |
---|
1427 | 1442 | err_trigger_unregister: |
---|
.. | .. |
---|
1535 | 1550 | {"KXCJ1013", KXCJK1013}, |
---|
1536 | 1551 | {"KXCJ1008", KXCJ91008}, |
---|
1537 | 1552 | {"KXCJ9000", KXCJ91008}, |
---|
| 1553 | + {"KIOX0008", KXCJ91008}, |
---|
| 1554 | + {"KIOX0009", KXTJ21009}, |
---|
1538 | 1555 | {"KIOX000A", KXCJ91008}, |
---|
1539 | | - {"KIOX010A", KXCJ91008}, /* KXCJ91008 inside the display of a 2-in-1 */ |
---|
| 1556 | + {"KIOX010A", KXCJ91008}, /* KXCJ91008 in the display of a yoga 2-in-1 */ |
---|
| 1557 | + {"KIOX020A", KXCJ91008}, /* KXCJ91008 in the base of a yoga 2-in-1 */ |
---|
1540 | 1558 | {"KXTJ1009", KXTJ21009}, |
---|
| 1559 | + {"KXJ2109", KXTJ21009}, |
---|
1541 | 1560 | {"SMO8500", KXCJ91008}, |
---|
1542 | 1561 | { }, |
---|
1543 | 1562 | }; |
---|
.. | .. |
---|
1554 | 1573 | |
---|
1555 | 1574 | MODULE_DEVICE_TABLE(i2c, kxcjk1013_id); |
---|
1556 | 1575 | |
---|
| 1576 | +static const struct of_device_id kxcjk1013_of_match[] = { |
---|
| 1577 | + { .compatible = "kionix,kxcjk1013", }, |
---|
| 1578 | + { .compatible = "kionix,kxcj91008", }, |
---|
| 1579 | + { .compatible = "kionix,kxtj21009", }, |
---|
| 1580 | + { .compatible = "kionix,kxtf9", }, |
---|
| 1581 | + { } |
---|
| 1582 | +}; |
---|
| 1583 | +MODULE_DEVICE_TABLE(of, kxcjk1013_of_match); |
---|
| 1584 | + |
---|
1557 | 1585 | static struct i2c_driver kxcjk1013_driver = { |
---|
1558 | 1586 | .driver = { |
---|
1559 | 1587 | .name = KXCJK1013_DRV_NAME, |
---|
1560 | 1588 | .acpi_match_table = ACPI_PTR(kx_acpi_match), |
---|
| 1589 | + .of_match_table = kxcjk1013_of_match, |
---|
1561 | 1590 | .pm = &kxcjk1013_pm_ops, |
---|
1562 | 1591 | }, |
---|
1563 | 1592 | .probe = kxcjk1013_probe, |
---|