forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/iio/accel/kxcjk-1013.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * KXCJK-1013 3-axis accelerometer driver
34 * 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.
135 */
146
157 #include <linux/module.h>
....@@ -151,6 +143,7 @@
151143 struct i2c_client *client;
152144 struct iio_trigger *dready_trig;
153145 struct iio_trigger *motion_trig;
146
+ struct iio_mount_matrix orientation;
154147 struct mutex mutex;
155148 /* Ensure timestamp naturally aligned */
156149 struct {
....@@ -494,7 +487,7 @@
494487 }
495488 if (ret < 0) {
496489 dev_err(&data->client->dev,
497
- "Failed: kxcjk1013_set_power_state for %d\n", on);
490
+ "Failed: %s for %d\n", __func__, on);
498491 if (on)
499492 pm_runtime_put_noidle(&data->client->dev);
500493 return ret;
....@@ -1034,6 +1027,20 @@
10341027 BIT(IIO_EV_INFO_PERIOD)
10351028 };
10361029
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
+
10371044 #define KXCJK1013_CHANNEL(_axis) { \
10381045 .type = IIO_ACCEL, \
10391046 .modified = 1, \
....@@ -1050,6 +1057,7 @@
10501057 .endianness = IIO_LE, \
10511058 }, \
10521059 .event_spec = &kxcjk1013_event, \
1060
+ .ext_info = kxcjk1013_ext_info, \
10531061 .num_event_specs = 1 \
10541062 }
10551063
....@@ -1062,9 +1070,7 @@
10621070
10631071 static const struct iio_buffer_setup_ops kxcjk1013_buffer_setup_ops = {
10641072 .preenable = kxcjk1013_buffer_preenable,
1065
- .postenable = iio_triggered_buffer_postenable,
10661073 .postdisable = kxcjk1013_buffer_postdisable,
1067
- .predisable = iio_triggered_buffer_predisable,
10681074 };
10691075
10701076 static const struct iio_info kxcjk1013_info = {
....@@ -1320,10 +1326,17 @@
13201326 data->client = client;
13211327
13221328 pdata = dev_get_platdata(&client->dev);
1323
- if (pdata)
1329
+ if (pdata) {
13241330 data->active_high_intr = pdata->active_high_intr;
1325
- else
1331
+ data->orientation = pdata->orientation;
1332
+ } else {
13261333 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
+ }
13271340
13281341 if (id) {
13291342 data->chipset = (enum kx_chipset)(id->driver_data);
....@@ -1341,7 +1354,6 @@
13411354
13421355 mutex_init(&data->mutex);
13431356
1344
- indio_dev->dev.parent = &client->dev;
13451357 indio_dev->channels = kxcjk1013_channels;
13461358 indio_dev->num_channels = ARRAY_SIZE(kxcjk1013_channels);
13471359 indio_dev->available_scan_masks = kxcjk1013_scan_masks;
....@@ -1417,11 +1429,14 @@
14171429 ret = iio_device_register(indio_dev);
14181430 if (ret < 0) {
14191431 dev_err(&client->dev, "unable to register iio device\n");
1420
- goto err_buffer_cleanup;
1432
+ goto err_pm_cleanup;
14211433 }
14221434
14231435 return 0;
14241436
1437
+err_pm_cleanup:
1438
+ pm_runtime_dont_use_autosuspend(&client->dev);
1439
+ pm_runtime_disable(&client->dev);
14251440 err_buffer_cleanup:
14261441 iio_triggered_buffer_cleanup(indio_dev);
14271442 err_trigger_unregister:
....@@ -1535,9 +1550,13 @@
15351550 {"KXCJ1013", KXCJK1013},
15361551 {"KXCJ1008", KXCJ91008},
15371552 {"KXCJ9000", KXCJ91008},
1553
+ {"KIOX0008", KXCJ91008},
1554
+ {"KIOX0009", KXTJ21009},
15381555 {"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 */
15401558 {"KXTJ1009", KXTJ21009},
1559
+ {"KXJ2109", KXTJ21009},
15411560 {"SMO8500", KXCJ91008},
15421561 { },
15431562 };
....@@ -1554,10 +1573,20 @@
15541573
15551574 MODULE_DEVICE_TABLE(i2c, kxcjk1013_id);
15561575
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
+
15571585 static struct i2c_driver kxcjk1013_driver = {
15581586 .driver = {
15591587 .name = KXCJK1013_DRV_NAME,
15601588 .acpi_match_table = ACPI_PTR(kx_acpi_match),
1589
+ .of_match_table = kxcjk1013_of_match,
15611590 .pm = &kxcjk1013_pm_ops,
15621591 },
15631592 .probe = kxcjk1013_probe,