Skip to content

Instantly share code, notes, and snippets.

@MaxLeiter
Created December 10, 2020 23:02
Show Gist options
  • Save MaxLeiter/48c8e63c42f9ba2f8eb2331a97d0ab69 to your computer and use it in GitHub Desktop.
Save MaxLeiter/48c8e63c42f9ba2f8eb2331a97d0ab69 to your computer and use it in GitHub Desktop.
--- apds9960.c 2020-12-10 14:51:49.347299912 -0800
+++ MSHW0184.c 2020-12-10 14:39:22.374241994 -0800
@@ -8,6 +8,7 @@
* TODO: gesture + proximity calib offsets
*/
+#include <linux/acpi.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
@@ -145,6 +146,9 @@
/* gesture buffer */
u8 buffer[4]; /* 4 8-bit channels */
+
+ /* proximity near level */
+ uint32_t near_level;
};
static const struct reg_default apds9960_reg_defaults[] = {
@@ -273,6 +277,21 @@
static const unsigned long apds9960_scan_masks[] = {0xf, 0};
+static ssize_t adps9960_read_near_level(struct iio_dev *indio_dev, uintptr_t priv, const struct iio_chan_spec *chan, char *buf) {
+ struct apds9960_data *data = iio_priv(indio_dev);
+
+ return sprintf(buf, "%u\n", data->near_level);
+}
+
+static const struct iio_chan_spec_ext_info adps9960_ext_info[] = {
+ {
+ .name = "near_level",
+ .shared = IIO_SEPARATE,
+ .read = adps9960_read_near_level,
+ },
+ {}
+};
+
static const struct iio_chan_spec apds9960_channels[] = {
{
.type = IIO_PROXIMITY,
@@ -282,9 +301,12 @@
.channel = 0,
.indexed = 0,
.scan_index = -1,
+ .ext_info = adps9960_ext_info,
.event_spec = apds9960_pxs_event_spec,
.num_event_specs = ARRAY_SIZE(apds9960_pxs_event_spec),
+
+
},
/* Gesture Sensor */
APDS9960_GESTURE_CHANNEL(UP, 0),
@@ -1018,6 +1040,10 @@
return PTR_ERR(data->regmap);
}
+ if (device_property_read_u32(&client->dev, "near-level", &data->near_level) < 0) {
+ data->near_level = 0;
+ }
+
data->client = client;
data->indio_dev = indio_dev;
mutex_init(&data->lock);
@@ -1119,11 +1145,18 @@
};
MODULE_DEVICE_TABLE(of, apds9960_of_match);
+static const struct acpi_device_id apds9960_acpi_match[] = {
+ { "MSHW0184" },
+ { }
+};
+MODULE_DEVICE_TABLE(acpi, apds9960_acpi_match);
+
static struct i2c_driver apds9960_driver = {
.driver = {
.name = APDS9960_DRV_NAME,
.of_match_table = apds9960_of_match,
.pm = &apds9960_pm_ops,
+ .acpi_match_table = apds9960_acpi_match,
},
.probe = apds9960_probe,
.remove = apds9960_remove,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment