Skip to content

Commit

Permalink
Use correct offset for gpiochip0 on flat
Browse files Browse the repository at this point in the history
Until kernel version 6.6 the first gpio chip's offset started at 0 due to a
downstream patch of RPi. This patch was removed with 6.6 and the kernel now
follows the mainline behavior whereas the offset starts as 512 ([1]).

Unfortunately we rely on indexed gpio access in revpi_flat.c for the relay
and button, as there is no platform device we can query. Thus keep the
current implementation at least for now and add a version macro, which
takes care of the offset calculation.

[1] raspberrypi/linux#6037 (comment)

Signed-off-by: Nicolai Buchwitz <n.buchwitz@kunbus.com>
  • Loading branch information
nbuchwitz committed Jul 10, 2024
1 parent 6ffbfb3 commit ecffddc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/revpi_flat.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@
#include <linux/sched.h>
#include <linux/thermal.h>
#include <linux/types.h>
#include <linux/version.h>

#include "piControlMain.h"
#include "process_image.h"
#include "revpi_common.h"
#include "revpi_flat.h"
#include "RevPiDevice.h"

#if KERNEL_VERSION(6, 6, 0) > LINUX_VERSION_CODE
/* kernel before 6.6 has a custom RPi patch, so offset started at 0 */
#define GPIOCHIP0_OFFSET 0
#else
#define GPIOCHIP0_OFFSET 512
#endif

/* relais gpio num */
#define REVPI_FLAT_RELAIS_GPIO 28
#define REVPI_FLAT_RELAIS_GPIO (28 + GPIOCHIP0_OFFSET)

/* button gpio num */
#define REVPI_FLAT_BUTTON_GPIO 13
#define REVPI_FLAT_S_BUTTON_GPIO 23
#define REVPI_FLAT_BUTTON_GPIO (13 + GPIOCHIP0_OFFSET)
#define REVPI_FLAT_S_BUTTON_GPIO (23 + GPIOCHIP0_OFFSET)

#define REVPI_FLAT_DOUT_THREAD_PRIO (MAX_RT_PRIO / 2 + 8)
#define REVPI_FLAT_AIN_THREAD_PRIO (MAX_RT_PRIO / 2 + 6)
Expand Down

0 comments on commit ecffddc

Please sign in to comment.