All of lore.kernel.org
 help / color / mirror / Atom feed
* [libgpiod][PATCH] build: allow building with pre-v5.5 kernel headers
@ 2020-11-20 14:15 Bartosz Golaszewski
  2020-11-20 14:42 ` Michael Nosthoff
  0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2020-11-20 14:15 UTC (permalink / raw)
  To: Kent Gibson
  Cc: linux-gpio, Bartosz Golaszewski, Thomas Petazzoni, Michael Nosthoff

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

libgpiod v1.6 requires at least v5.5 linux kernel headers to build. This
is because several new symbols have been defined in linux v5.5. In order
to allow building with kernel headers v4.6 and on, let's check the
presence of the new symbols and redefine them if needed.

The new features won't work on kernels pre v5.5 but the build won't fail
anymore.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Michael Nosthoff <buildroot@heine.tech>
---
Downstream complains a lot about libgpiod v1.6 not building with kernel
headers pre-v5.5. We've had a discussion on that over at buildroot[1].

For libgpiod v2.0 we need to figure out a better way of dealing with new
kernel features added after the release of v2.0 but for v1.6 let's just
redefine the symbols if needed.

[1] http://lists.busybox.net/pipermail/buildroot/2020-October/295314.html

 configure.ac | 10 +++++++++-
 lib/core.c   | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index cd337ff..6aef289 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,13 +95,21 @@ AC_CHECK_HEADERS([sys/sysmacros.h], [], [HEADER_NOT_FOUND_LIB([sys/sysmacros.h])
 AC_CHECK_HEADERS([linux/gpio.h], [], [HEADER_NOT_FOUND_LIB([linux/gpio.h])])
 AC_CHECK_HEADERS([linux/version.h], [], [HEADER_NOT_FOUND_LIB([linux/version.h])])
 
+AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
+#error
+#endif
+)],
+[], [AC_MSG_ERROR(["libgpiod needs linux headers version >= v4.6.0"])])
+
 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
 #include <linux/version.h>
 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0)
 #error
 #endif
 )],
-[], [AC_MSG_ERROR(["libgpiod needs linux headers version >= v5.5.0"])])
+[], [AC_DEFINE([KERNEL_PRE_5_5], [], [We need to define symbols added in linux v5.5])])
 
 AC_ARG_ENABLE([tools],
 	[AC_HELP_STRING([--enable-tools],
diff --git a/lib/core.c b/lib/core.c
index b964272..f49743b 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -22,6 +22,24 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#ifdef KERNEL_PRE_5_5
+#define GPIOLINE_FLAG_BIAS_PULL_UP		(1UL << 5)
+#define GPIOLINE_FLAG_BIAS_PULL_DOWN		(1UL << 6)
+#define GPIOLINE_FLAG_BIAS_DISABLE		(1UL << 7)
+
+#define GPIOHANDLE_REQUEST_BIAS_PULL_UP		(1UL << 5)
+#define GPIOHANDLE_REQUEST_BIAS_PULL_DOWN	(1UL << 6)
+#define GPIOHANDLE_REQUEST_BIAS_DISABLE		(1UL << 7)
+
+struct gpiohandle_config {
+	__u32 flags;
+	__u8 default_values[GPIOHANDLES_MAX];
+	__u32 padding[4]; /* padding for future use */
+};
+
+#define GPIOHANDLE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0a, struct gpiohandle_config)
+#endif /* KERNEL_PRE_5_5 */
+
 enum {
 	LINE_FREE = 0,
 	LINE_REQUESTED_VALUES,
-- 
2.29.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [libgpiod][PATCH] build: allow building  with pre-v5.5 kernel headers
  2020-11-20 14:15 [libgpiod][PATCH] build: allow building with pre-v5.5 kernel headers Bartosz Golaszewski
@ 2020-11-20 14:42 ` Michael Nosthoff
  2020-11-20 15:37   ` Bartosz Golaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Nosthoff @ 2020-11-20 14:42 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Kent Gibson, linux-gpio, Bartosz Golaszewski, Thomas Petazzoni

Hi Bartosz,

On Friday, November 20, 2020 15:15 CET, Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> libgpiod v1.6 requires at least v5.5 linux kernel headers to build. This
> is because several new symbols have been defined in linux v5.5. In order
> to allow building with kernel headers v4.6 and on, let's check the
> presence of the new symbols and redefine them if needed.
>

In the Buildroot Package (for 1.4.x) you set the dependency for headers to be at least 4.8. [1]
Could this then be lowered or is there a mixup?

Regards,
Michael

[1] https://git.busybox.net/buildroot/tree/package/libgpiod/Config.in


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [libgpiod][PATCH] build: allow building with pre-v5.5 kernel headers
  2020-11-20 14:42 ` Michael Nosthoff
@ 2020-11-20 15:37   ` Bartosz Golaszewski
  0 siblings, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2020-11-20 15:37 UTC (permalink / raw)
  To: Michael Nosthoff
  Cc: Kent Gibson, open list:GPIO SUBSYSTEM, Bartosz Golaszewski,
	Thomas Petazzoni

On Fri, Nov 20, 2020 at 3:42 PM Michael Nosthoff <buildroot@heine.tech> wrote:
>
> Hi Bartosz,
>
> On Friday, November 20, 2020 15:15 CET, Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > libgpiod v1.6 requires at least v5.5 linux kernel headers to build. This
> > is because several new symbols have been defined in linux v5.5. In order
> > to allow building with kernel headers v4.6 and on, let's check the
> > presence of the new symbols and redefine them if needed.
> >
>
> In the Buildroot Package (for 1.4.x) you set the dependency for headers to be at least 4.8. [1]
> Could this then be lowered or is there a mixup?
>
> Regards,
> Michael
>
> [1] https://git.busybox.net/buildroot/tree/package/libgpiod/Config.in
>

No, it's my mistake - it should say v4.8 in the patch, not v4.6.

Bartosz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-20 15:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 14:15 [libgpiod][PATCH] build: allow building with pre-v5.5 kernel headers Bartosz Golaszewski
2020-11-20 14:42 ` Michael Nosthoff
2020-11-20 15:37   ` Bartosz Golaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.