mirror of
https://github.com/t2linux/linux-t2-patches.git
synced 2026-08-16 05:18:17 -07:00
214 lines
5.6 KiB
Diff
214 lines
5.6 KiB
Diff
From 30b552988cfe144de89fb100997084b57e75c24a Mon Sep 17 00:00:00 2001
|
|
From: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
|
|
Date: Fri, 24 Apr 2026 18:01:21 +0530
|
|
Subject: [PATCH 03/12] light
|
|
|
|
Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
|
|
---
|
|
MAINTAINERS | 1 +
|
|
drivers/iio/light/Kconfig | 10 +++
|
|
drivers/iio/light/Makefile | 1 +
|
|
drivers/iio/light/macsmc-light.c | 132 +++++++++++++++++++++++++++++++
|
|
drivers/mfd/macsmc-core.c | 1 +
|
|
5 files changed, 145 insertions(+)
|
|
create mode 100644 drivers/iio/light/macsmc-light.c
|
|
|
|
diff --git a/MAINTAINERS b/MAINTAINERS
|
|
index 0a51ff99e7f9..03917e410dd5 100644
|
|
--- a/MAINTAINERS
|
|
+++ b/MAINTAINERS
|
|
@@ -1940,6 +1940,7 @@ F: drivers/hwmon/applesmc.c
|
|
MACSMC SUPPORT FOR INTEL MACS
|
|
M: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
|
|
S: Odd fixes
|
|
+F: drivers/iio/light/macsmc-light.c
|
|
F: drivers/platform/x86/macsmc-acpi.c
|
|
|
|
APPLETALK NETWORK LAYER
|
|
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
|
|
index ac1408d374c9..1b9e4394a966 100644
|
|
--- a/drivers/iio/light/Kconfig
|
|
+++ b/drivers/iio/light/Kconfig
|
|
@@ -440,6 +440,16 @@ config LV0104CS
|
|
To compile this driver as a module, choose M here:
|
|
the module will be called lv0104cs.
|
|
|
|
+config MACSMC_LIGHT
|
|
+ tristate "Apple SMC Light Sensor"
|
|
+ depends on MACSMC_ACPI
|
|
+ help
|
|
+ Say Y here if you have a Intel-based Mac. and you
|
|
+ want support for light sensors.
|
|
+
|
|
+ To compile this driver as a module, choose M here:
|
|
+ the module will be called macsmc_light
|
|
+
|
|
config MAX44000
|
|
tristate "MAX44000 Ambient and Infrared Proximity Sensor"
|
|
depends on I2C
|
|
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
|
|
index c0048e0d5ca8..2ef7048a100e 100644
|
|
--- a/drivers/iio/light/Makefile
|
|
+++ b/drivers/iio/light/Makefile
|
|
@@ -39,6 +39,7 @@ obj-$(CONFIG_LTR390) += ltr390.o
|
|
obj-$(CONFIG_LTR501) += ltr501.o
|
|
obj-$(CONFIG_LTRF216A) += ltrf216a.o
|
|
obj-$(CONFIG_LV0104CS) += lv0104cs.o
|
|
+obj-$(CONFIG_MACSMC_LIGHT) += macsmc-light.o
|
|
obj-$(CONFIG_MAX44000) += max44000.o
|
|
obj-$(CONFIG_MAX44009) += max44009.o
|
|
obj-$(CONFIG_NOA1305) += noa1305.o
|
|
diff --git a/drivers/iio/light/macsmc-light.c b/drivers/iio/light/macsmc-light.c
|
|
new file mode 100644
|
|
index 000000000000..26f22b22d97c
|
|
--- /dev/null
|
|
+++ b/drivers/iio/light/macsmc-light.c
|
|
@@ -0,0 +1,132 @@
|
|
+// SPDX-License-Identifier: GPL-2.0 OR MIT
|
|
+/*
|
|
+ * Apple SMC Light Sensor Driver
|
|
+ *
|
|
+ * Copyright (C) 2026 Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
|
|
+ */
|
|
+
|
|
+#include <linux/iio/iio.h>
|
|
+#include <linux/byteorder/generic.h>
|
|
+#include <linux/mfd/macsmc.h>
|
|
+#include <linux/platform_device.h>
|
|
+#include <linux/unaligned.h>
|
|
+
|
|
+#define LEFT_KEY SMC_KEY(ALV0)
|
|
+#define RIGHT_KEY SMC_KEY(ALV1)
|
|
+
|
|
+enum {
|
|
+ LEFT_LIGHT = 0,
|
|
+ RIGHT_LIGHT
|
|
+};
|
|
+
|
|
+struct macsmc_light {
|
|
+ struct apple_smc *smc;
|
|
+ u8 size;
|
|
+};
|
|
+
|
|
+static int macsmc_light_read_raw(struct iio_dev *indio_dev,
|
|
+ const struct iio_chan_spec *chan,
|
|
+ int *val, int *val2, long mask)
|
|
+
|
|
+{
|
|
+ struct macsmc_light *drv = iio_priv(indio_dev);
|
|
+ u8 buffer[10];
|
|
+ int ret;
|
|
+
|
|
+ if (mask != IIO_CHAN_INFO_RAW)
|
|
+ return -EINVAL;
|
|
+
|
|
+ switch (chan->channel) {
|
|
+ case LEFT_LIGHT:
|
|
+ ret = apple_smc_read(drv->smc, LEFT_KEY, buffer, drv->size);
|
|
+ if (ret < 0)
|
|
+ return ret;
|
|
+
|
|
+ if (drv->size == 10)
|
|
+ *val = be16_to_cpu(get_unaligned_be16(buffer + 6)) >> 10;
|
|
+ else
|
|
+ *val = buffer[2];
|
|
+
|
|
+ break;
|
|
+ case RIGHT_LIGHT:
|
|
+ if (drv->size == 10) {
|
|
+ *val = 0;
|
|
+ break;
|
|
+ }
|
|
+ ret = apple_smc_read(drv->smc, RIGHT_KEY, buffer, drv->size);
|
|
+ if (ret < 0)
|
|
+ return ret;
|
|
+
|
|
+ *val = buffer[2];
|
|
+ break;
|
|
+ default:
|
|
+ return -EINVAL;
|
|
+ }
|
|
+
|
|
+ return IIO_VAL_INT;
|
|
+}
|
|
+
|
|
+static const struct iio_chan_spec macsmc_light_channels[] = {
|
|
+ {
|
|
+ .type = IIO_LIGHT,
|
|
+ .channel = LEFT_LIGHT,
|
|
+ .extend_name = "left",
|
|
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
|
+ },
|
|
+ {
|
|
+ .type = IIO_LIGHT,
|
|
+ .channel = RIGHT_LIGHT,
|
|
+ .extend_name = "right",
|
|
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
|
+ },
|
|
+};
|
|
+
|
|
+static const struct iio_info macsmc_light_info = {
|
|
+ .read_raw = macsmc_light_read_raw,
|
|
+};
|
|
+
|
|
+static int macsmc_light_probe(struct platform_device *pdev)
|
|
+{
|
|
+ struct iio_dev *indio_dev;
|
|
+ struct macsmc_light *drv;
|
|
+ struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
|
|
+ struct apple_smc_key_info info;
|
|
+ int ret;
|
|
+
|
|
+ indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*drv));
|
|
+ if (!indio_dev)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ drv = iio_priv(indio_dev);
|
|
+ drv->smc = smc;
|
|
+
|
|
+ if (!drv->smc)
|
|
+ return -ENODEV;
|
|
+
|
|
+ ret = apple_smc_get_key_info(smc, LEFT_KEY, &info);
|
|
+ if (ret < 0)
|
|
+ return -ENODEV;
|
|
+
|
|
+ drv->size = info.size;
|
|
+
|
|
+ indio_dev->name = "macsmc-light";
|
|
+ indio_dev->modes = INDIO_DIRECT_MODE;
|
|
+ indio_dev->info = &macsmc_light_info;
|
|
+ indio_dev->channels = macsmc_light_channels;
|
|
+ indio_dev->num_channels = ARRAY_SIZE(macsmc_light_channels);
|
|
+
|
|
+ return devm_iio_device_register(&pdev->dev, indio_dev);
|
|
+}
|
|
+
|
|
+static struct platform_driver macsmc_light_driver = {
|
|
+ .probe = macsmc_light_probe,
|
|
+ .driver = {
|
|
+ .name = "macsmc-light",
|
|
+ },
|
|
+};
|
|
+module_platform_driver(macsmc_light_driver);
|
|
+
|
|
+MODULE_AUTHOR("Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>");
|
|
+MODULE_LICENSE("Dual MIT/GPL");
|
|
+MODULE_DESCRIPTION("Apple SMC Light Sensor Driver");
|
|
+MODULE_ALIAS("platform:macsmc-light");
|
|
diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
|
|
index e5d3e66223e2..814bfb3ae0ec 100644
|
|
--- a/drivers/mfd/macsmc-core.c
|
|
+++ b/drivers/mfd/macsmc-core.c
|
|
@@ -22,6 +22,7 @@ static const struct mfd_cell apple_smc_devs[] = {
|
|
|
|
static const struct mfd_cell apple_smc_acpi_devs[] = {
|
|
MFD_CELL_NAME("macsmc-hwmon"),
|
|
+ MFD_CELL_NAME("macsmc-light"),
|
|
MFD_CELL_NAME("macsmc-power"),
|
|
MFD_CELL_NAME("macsmc-rtc"),
|
|
};
|
|
--
|
|
2.43.0
|
|
|