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
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
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