diff --git a/Makefile b/Makefile index 7d45462..c70535a 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,28 @@ -obj-m += applespi.o -obj-m += apple-ibridge.o -obj-m += apple-ib-tb.o -obj-m += apple-ib-als.o - CFLAGS_applespi.o = -I$(src) # for tracing +CONFIG_MODULE_SIG=n +CONFIG_MODULE_SIG_ALL=n +# CONFIG_MODULE_SIG_FORCE is not set +# CONFIG_MODULE_SIG_SHA1 is not set +# CONFIG_MODULE_SIG_SHA224 is not set +# CONFIG_MODULE_SIG_SHA256 is not set +# CONFIG_MODULE_SIG_SHA384 is not set + KVERSION := $(KERNELRELEASE) ifeq ($(origin KERNELRELEASE), undefined) KVERSION := $(shell uname -r) endif + +ifneq ($(KVERSION),) + ifeq ($(shell expr $(KVERSION) \< 5.3), 1) + obj-m += applespi.o + endif +endif + +obj-m += apple-ibridge.o +obj-m += apple-ib-tb.o +obj-m += apple-ib-als.o + KDIR := /lib/modules/$(KVERSION)/build PWD := $(shell pwd) diff --git a/README.md b/README.md index 0884742..8419979 100644 --- a/README.md +++ b/README.md @@ -89,3 +89,4 @@ Some useful threads: -------------------- * https://bugzilla.kernel.org/show_bug.cgi?id=108331 * https://bugzilla.kernel.org/show_bug.cgi?id=99891 +* https://gist.github.com/almas/5f75adb61bccf604b6572f763ce63e3e (Ubuntu LTS on MacBook Pro 2017 (A1707, MBP 14,3)) diff --git a/apple-ib-als.c b/apple-ib-als.c index 6c2949d..9cb4347 100644 --- a/apple-ib-als.c +++ b/apple-ib-als.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "apple-ibridge.h" @@ -459,8 +460,11 @@ static int appleals_config_iio(struct appleals_device *als_dev) struct iio_trigger *iio_trig; struct appleals_device **priv; int rc; - +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 9, 0) iio_dev = iio_device_alloc(sizeof(als_dev)); +#else + iio_dev = iio_device_alloc(&als_dev->hid_dev->dev, sizeof(als_dev)); +#endif if (!iio_dev) return -ENOMEM; @@ -469,7 +473,9 @@ static int appleals_config_iio(struct appleals_device *als_dev) iio_dev->channels = appleals_channels; iio_dev->num_channels = ARRAY_SIZE(appleals_channels); +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 9, 0) iio_dev->dev.parent = &als_dev->hid_dev->dev; +#endif iio_dev->info = &appleals_info; iio_dev->name = "als"; iio_dev->modes = INDIO_DIRECT_MODE; @@ -482,7 +488,15 @@ static int appleals_config_iio(struct appleals_device *als_dev) goto free_iio_dev; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0) + iio_trig = iio_trigger_alloc(&iio_dev->dev, "%s-dev%d", iio_dev->name, + iio_device_id(iio_dev)); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 13, 0) + iio_trig = iio_trigger_alloc(&iio_dev->dev, "%s-dev%d", iio_dev->name, + iio_dev->id); +#else iio_trig = iio_trigger_alloc("%s-dev%d", iio_dev->name, iio_dev->id); +#endif if (!iio_trig) { rc = -ENOMEM; goto clean_trig_buf; diff --git a/apple-ibridge.c b/apple-ibridge.c index b6983e6..b176e32 100644 --- a/apple-ibridge.c +++ b/apple-ibridge.c @@ -843,13 +843,13 @@ static int appleib_probe(struct acpi_device *acpi) return 0; } -static int appleib_remove(struct acpi_device *acpi) +static void appleib_remove(struct acpi_device *acpi) { struct appleib_device *ib_dev = acpi_driver_data(acpi); hid_unregister_driver(&ib_dev->ib_driver); - return 0; + return; } static int appleib_suspend(struct device *dev) diff --git a/applespi.c b/applespi.c index cafc461..d250d18 100644 --- a/applespi.c +++ b/applespi.c @@ -587,7 +587,11 @@ static void applespi_setup_read_txfrs(struct applespi_data *applespi) memset(dl_t, 0, sizeof(*dl_t)); memset(rd_t, 0, sizeof(*rd_t)); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 13, 0) + dl_t->delay.value = applespi->spi_settings.spi_cs_delay; +#else dl_t->delay_usecs = applespi->spi_settings.spi_cs_delay; +#endif rd_t->rx_buf = applespi->rx_buffer; rd_t->len = APPLESPI_PACKET_SIZE; @@ -616,14 +620,26 @@ static void applespi_setup_write_txfrs(struct applespi_data *applespi) * end up with an extra unnecessary (but harmless) cs assertion and * deassertion. */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 13, 0) + wt_t->delay.value = SPI_RW_CHG_DELAY_US; +#else wt_t->delay_usecs = SPI_RW_CHG_DELAY_US; +#endif wt_t->cs_change = 1; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 13, 0) + dl_t->delay.value = applespi->spi_settings.spi_cs_delay; +#else dl_t->delay_usecs = applespi->spi_settings.spi_cs_delay; +#endif wr_t->tx_buf = applespi->tx_buffer; wr_t->len = APPLESPI_PACKET_SIZE; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 13, 0) + wr_t->delay.value = SPI_RW_CHG_DELAY_US; +#else wr_t->delay_usecs = SPI_RW_CHG_DELAY_US; +#endif st_t->rx_buf = applespi->tx_status; st_t->len = APPLESPI_STATUS_SIZE; @@ -2109,7 +2125,11 @@ static void applespi_drain_reads(struct applespi_data *applespi) spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 1) +static void applespi_remove(struct spi_device *spi) +#else static int applespi_remove(struct spi_device *spi) +#endif { struct applespi_data *applespi = spi_get_drvdata(spi); @@ -2123,7 +2143,9 @@ static int applespi_remove(struct spi_device *spi) debugfs_remove_recursive(applespi->debugfs_root); +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 1) return 0; +#endif } static void applespi_shutdown(struct spi_device *spi) diff --git a/dkms.conf b/dkms.conf index 9c72046..cb98b8e 100644 --- a/dkms.conf +++ b/dkms.conf @@ -2,13 +2,23 @@ PACKAGE_NAME="applespi" PACKAGE_VERSION="0.1" CLEAN="make clean" MAKE="make" -BUILT_MODULE_NAME[0]="applespi" -BUILT_MODULE_NAME[1]="apple-ibridge" -BUILT_MODULE_NAME[2]="apple-ib-tb" -BUILT_MODULE_NAME[3]="apple-ib-als" -DEST_MODULE_LOCATION[0]="/updates" -DEST_MODULE_LOCATION[1]="/updates" -DEST_MODULE_LOCATION[2]="/updates" -DEST_MODULE_LOCATION[3]="/updates" +if [ "$(uname -r | cut -d. -f1-2)" \< "5.3" ]; then + BUILT_MODULE_NAME[0]="applespi" + BUILT_MODULE_NAME[1]="apple-ibridge" + BUILT_MODULE_NAME[2]="apple-ib-tb" + BUILT_MODULE_NAME[3]="apple-ib-als" + DEST_MODULE_LOCATION[0]="/updates" + DEST_MODULE_LOCATION[1]="/updates" + DEST_MODULE_LOCATION[2]="/updates" + DEST_MODULE_LOCATION[3]="/updates" +else + BUILT_MODULE_NAME[0]="apple-ibridge" + BUILT_MODULE_NAME[1]="apple-ib-tb" + BUILT_MODULE_NAME[2]="apple-ib-als" + DEST_MODULE_LOCATION[0]="/updates" + DEST_MODULE_LOCATION[1]="/updates" + DEST_MODULE_LOCATION[2]="/updates" +fi + AUTOINSTALL="yes" REMAKE_INITRD="yes"