Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
16 changes: 15 additions & 1 deletion apple-ib-als.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/version.h>

#include "apple-ibridge.h"

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions apple-ibridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions applespi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down
26 changes: 18 additions & 8 deletions dkms.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"