]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
sh: pfc: Verify pin type encoding size at build time.
authorPaul Mundt <lethal@linux-sh.org>
Wed, 20 Jun 2012 15:03:41 +0000 (00:03 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Wed, 20 Jun 2012 15:03:41 +0000 (00:03 +0900)
The encoding is tightly packed, and future changes (such as
pinconf-generic support) can easily lead to a situation where we violate
the encoding constraints and trample data bit/reg bits. This plugs in
some sanity checks by way of a BUILD_BUG_ON() to blow up if we fail to
fit.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
drivers/sh/pfc.c
include/linux/sh_pfc.h

index 8a9ae09603d6978ad2c4c2f29db7d60256da4198..ce4579ebd602b7e4f778e04f9d276cb607adfffe 100644 (file)
@@ -549,6 +549,11 @@ int register_sh_pfc(struct sh_pfc *pfc)
        int (*initroutine)(struct sh_pfc *) = NULL;
        int ret;
 
+       /*
+        * Ensure that the type encoding fits
+        */
+       BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1));
+
        if (sh_pfc)
                return -EBUSY;
 
index c06a47313a25ac4a27b81c6e727f19fa036a1914..ed1d8234f6ae57d78b3b17faee52b98191098739 100644 (file)
 typedef unsigned short pinmux_enum_t;
 typedef unsigned short pinmux_flag_t;
 
-#define PINMUX_TYPE_NONE            0
-#define PINMUX_TYPE_FUNCTION        1
-#define PINMUX_TYPE_GPIO            2
-#define PINMUX_TYPE_OUTPUT          3
-#define PINMUX_TYPE_INPUT           4
-#define PINMUX_TYPE_INPUT_PULLUP    5
-#define PINMUX_TYPE_INPUT_PULLDOWN  6
+enum {
+       PINMUX_TYPE_NONE,
 
-#define PINMUX_FLAG_TYPE            (0x7)
+       PINMUX_TYPE_FUNCTION,
+       PINMUX_TYPE_GPIO,
+       PINMUX_TYPE_OUTPUT,
+       PINMUX_TYPE_INPUT,
+       PINMUX_TYPE_INPUT_PULLUP,
+       PINMUX_TYPE_INPUT_PULLDOWN,
+
+       PINMUX_FLAG_TYPE,       /* must be last */
+};
 
 #define PINMUX_FLAG_DBIT_SHIFT      5
 #define PINMUX_FLAG_DBIT            (0x1f << PINMUX_FLAG_DBIT_SHIFT)
@@ -36,7 +39,9 @@ struct pinmux_gpio {
        pinmux_flag_t flags;
 };
 
-#define PINMUX_GPIO(gpio, data_or_mark) [gpio] = { data_or_mark }
+#define PINMUX_GPIO(gpio, data_or_mark) \
+       [gpio] = { .enum_id = data_or_mark, .flags = PINMUX_TYPE_NONE }
+
 #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
 
 struct pinmux_cfg_reg {