Re: [PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
On Tue, Mar 10, 2015 at 4:08 PM, Arnd Bergmann wrote: > On Friday 20 February 2015 19:01:10 Maxime Coquelin wrote: >> +/* Pull-Up/Down */ >> +#define NO_PULL0 >> +#define PULL_UP1 >> +#define PULL_DOWN 2 >> + >> +/* Type */ >> +#define PUSH_PULL (0 << 2) >> +#define OPEN_DRAIN (1 << 2) >> + > > These should probably not be stm32 specific at all, they sound > rather generic, so maybe put the definitions into a common file. It's part of what GENERIC_PINCONF does and it has bindings in Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt Yours, Linus Walleij -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
On Tue, Mar 10, 2015 at 4:08 PM, Arnd Bergmann a...@arndb.de wrote: On Friday 20 February 2015 19:01:10 Maxime Coquelin wrote: +/* Pull-Up/Down */ +#define NO_PULL0 +#define PULL_UP1 +#define PULL_DOWN 2 + +/* Type */ +#define PUSH_PULL (0 2) +#define OPEN_DRAIN (1 2) + These should probably not be stm32 specific at all, they sound rather generic, so maybe put the definitions into a common file. It's part of what GENERIC_PINCONF does and it has bindings in Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt Yours, Linus Walleij -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
On Friday 20 February 2015 19:01:10 Maxime Coquelin wrote: > --- /dev/null > +++ b/include/dt-bindings/pinctrl/pinctrl-stm32.h > @@ -0,0 +1,43 @@ > +#ifndef _DT_BINDINGS_PINCTRL_STM32_H > +#define _DT_BINDINGS_PINCTRL_STM32_H > + > +/* Modes */ > +#define IN 0 > +#define OUT1 > +#define ALT2 > +#define ANALOG 3 I think it's better to prefix all the names with a string to identify what they are for, otherwise these are way too generic. > +/* Alternate functions */ > +#define ALT0 ((0 << 2) | ALT) > +#define ALT1 ((1 << 2) | ALT) > +#define ALT2 ((2 << 2) | ALT) > +#define ALT3 ((3 << 2) | ALT) > +#define ALT4 ((4 << 2) | ALT) > +#define ALT5 ((5 << 2) | ALT) > +#define ALT6 ((6 << 2) | ALT) > +#define ALT7 ((7 << 2) | ALT) > +#define ALT8 ((8 << 2) | ALT) > +#define ALT9 ((9 << 2) | ALT) > +#define ALT10 ((10 << 2) | ALT) > +#define ALT11 ((11 << 2) | ALT) > +#define ALT12 ((12 << 2) | ALT) > +#define ALT13 ((13 << 2) | ALT) > +#define ALT14 ((14 << 2) | ALT) > +#define ALT15 ((15 << 2) | ALT) You can have a single macro for these like #define STM32_PIN_ALT(x) ((x << 2) | ALT) > +/* Pull-Up/Down */ > +#define NO_PULL0 > +#define PULL_UP1 > +#define PULL_DOWN 2 > + > +/* Type */ > +#define PUSH_PULL (0 << 2) > +#define OPEN_DRAIN (1 << 2) > + These should probably not be stm32 specific at all, they sound rather generic, so maybe put the definitions into a common file. Arnd -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
On Friday 20 February 2015 19:01:10 Maxime Coquelin wrote: --- /dev/null +++ b/include/dt-bindings/pinctrl/pinctrl-stm32.h @@ -0,0 +1,43 @@ +#ifndef _DT_BINDINGS_PINCTRL_STM32_H +#define _DT_BINDINGS_PINCTRL_STM32_H + +/* Modes */ +#define IN 0 +#define OUT1 +#define ALT2 +#define ANALOG 3 I think it's better to prefix all the names with a string to identify what they are for, otherwise these are way too generic. +/* Alternate functions */ +#define ALT0 ((0 2) | ALT) +#define ALT1 ((1 2) | ALT) +#define ALT2 ((2 2) | ALT) +#define ALT3 ((3 2) | ALT) +#define ALT4 ((4 2) | ALT) +#define ALT5 ((5 2) | ALT) +#define ALT6 ((6 2) | ALT) +#define ALT7 ((7 2) | ALT) +#define ALT8 ((8 2) | ALT) +#define ALT9 ((9 2) | ALT) +#define ALT10 ((10 2) | ALT) +#define ALT11 ((11 2) | ALT) +#define ALT12 ((12 2) | ALT) +#define ALT13 ((13 2) | ALT) +#define ALT14 ((14 2) | ALT) +#define ALT15 ((15 2) | ALT) You can have a single macro for these like #define STM32_PIN_ALT(x) ((x 2) | ALT) +/* Pull-Up/Down */ +#define NO_PULL0 +#define PULL_UP1 +#define PULL_DOWN 2 + +/* Type */ +#define PUSH_PULL (0 2) +#define OPEN_DRAIN (1 2) + These should probably not be stm32 specific at all, they sound rather generic, so maybe put the definitions into a common file. Arnd -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
2015-03-06 10:24 GMT+01:00 Linus Walleij : > On Fri, Feb 20, 2015 at 7:01 PM, Maxime Coquelin > wrote: > >> This driver adds pinctrl and GPIO support to STMicrolectronic's >> STM32 family of MCUs. >> >> Pin muxing and GPIO handling have been tested on STM32F429 >> based Discovery board. >> >> Signed-off-by: Maxime Coquelin > > (...) >> +config PINCTRL_STM32 >> + bool "STMicroelectronics STM32 pinctrl driver" >> + depends on OF >> + depends on ARCH_STM32 || COMPILE_TEST >> + select PINMUX >> + select PINCONF >> + select GPIOLIB_IRQCHIP >> + help >> + This selects the device tree based generic pinctrl driver for >> STM32. > > Good start! Especially that you use GPIOLIB_IRQCHIP. > > But this (as discussed earlier) should select GENERIC_PINCONF > > Stopping review here so you can reengineer it a bit using GENERIC_PINCONF > for next submission. > > Also think about pinmux in single registers, whether you want to do this > with a single value for a register or using strings to identify groups > and functions. Thanks for the review. I will digest all this, and come back with another solution :) Best regards, Maxime > > Yours, > Linus Walleij -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
On Fri, Feb 20, 2015 at 7:01 PM, Maxime Coquelin wrote: > This driver adds pinctrl and GPIO support to STMicrolectronic's > STM32 family of MCUs. > > Pin muxing and GPIO handling have been tested on STM32F429 > based Discovery board. > > Signed-off-by: Maxime Coquelin (...) > +config PINCTRL_STM32 > + bool "STMicroelectronics STM32 pinctrl driver" > + depends on OF > + depends on ARCH_STM32 || COMPILE_TEST > + select PINMUX > + select PINCONF > + select GPIOLIB_IRQCHIP > + help > + This selects the device tree based generic pinctrl driver for STM32. Good start! Especially that you use GPIOLIB_IRQCHIP. But this (as discussed earlier) should select GENERIC_PINCONF Stopping review here so you can reengineer it a bit using GENERIC_PINCONF for next submission. Also think about pinmux in single registers, whether you want to do this with a single value for a register or using strings to identify groups and functions. Yours, Linus Walleij -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
2015-03-06 10:24 GMT+01:00 Linus Walleij linus.wall...@linaro.org: On Fri, Feb 20, 2015 at 7:01 PM, Maxime Coquelin mcoquelin.st...@gmail.com wrote: This driver adds pinctrl and GPIO support to STMicrolectronic's STM32 family of MCUs. Pin muxing and GPIO handling have been tested on STM32F429 based Discovery board. Signed-off-by: Maxime Coquelin mcoquelin.st...@gmail.com (...) +config PINCTRL_STM32 + bool STMicroelectronics STM32 pinctrl driver + depends on OF + depends on ARCH_STM32 || COMPILE_TEST + select PINMUX + select PINCONF + select GPIOLIB_IRQCHIP + help + This selects the device tree based generic pinctrl driver for STM32. Good start! Especially that you use GPIOLIB_IRQCHIP. But this (as discussed earlier) should select GENERIC_PINCONF Stopping review here so you can reengineer it a bit using GENERIC_PINCONF for next submission. Also think about pinmux in single registers, whether you want to do this with a single value for a register or using strings to identify groups and functions. Thanks for the review. I will digest all this, and come back with another solution :) Best regards, Maxime Yours, Linus Walleij -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
On Fri, Feb 20, 2015 at 7:01 PM, Maxime Coquelin mcoquelin.st...@gmail.com wrote: This driver adds pinctrl and GPIO support to STMicrolectronic's STM32 family of MCUs. Pin muxing and GPIO handling have been tested on STM32F429 based Discovery board. Signed-off-by: Maxime Coquelin mcoquelin.st...@gmail.com (...) +config PINCTRL_STM32 + bool STMicroelectronics STM32 pinctrl driver + depends on OF + depends on ARCH_STM32 || COMPILE_TEST + select PINMUX + select PINCONF + select GPIOLIB_IRQCHIP + help + This selects the device tree based generic pinctrl driver for STM32. Good start! Especially that you use GPIOLIB_IRQCHIP. But this (as discussed earlier) should select GENERIC_PINCONF Stopping review here so you can reengineer it a bit using GENERIC_PINCONF for next submission. Also think about pinmux in single registers, whether you want to do this with a single value for a register or using strings to identify groups and functions. Yours, Linus Walleij -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
This driver adds pinctrl and GPIO support to STMicrolectronic's STM32 family of MCUs. Pin muxing and GPIO handling have been tested on STM32F429 based Discovery board. Signed-off-by: Maxime Coquelin --- drivers/pinctrl/Kconfig | 10 + drivers/pinctrl/Makefile| 1 + drivers/pinctrl/pinctrl-stm32.c | 779 include/dt-bindings/pinctrl/pinctrl-stm32.h | 43 ++ 4 files changed, 833 insertions(+) create mode 100644 drivers/pinctrl/pinctrl-stm32.c create mode 100644 include/dt-bindings/pinctrl/pinctrl-stm32.h diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index d014f22..84cd081 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig @@ -125,6 +125,16 @@ config PINCTRL_ST select PINCONF select GPIOLIB_IRQCHIP +config PINCTRL_STM32 + bool "STMicroelectronics STM32 pinctrl driver" + depends on OF + depends on ARCH_STM32 || COMPILE_TEST + select PINMUX + select PINCONF + select GPIOLIB_IRQCHIP + help + This selects the device tree based generic pinctrl driver for STM32. + config PINCTRL_TEGRA bool select PINMUX diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index c030b3d..06ef8ab 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile @@ -35,6 +35,7 @@ obj-$(CONFIG_PINCTRL_XWAY)+= pinctrl-xway.o obj-$(CONFIG_PINCTRL_LANTIQ) += pinctrl-lantiq.o obj-$(CONFIG_PINCTRL_TB10X)+= pinctrl-tb10x.o obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o +obj-$(CONFIG_PINCTRL_STM32)+= pinctrl-stm32.o obj-$(CONFIG_ARCH_BERLIN) += berlin/ obj-y += freescale/ diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c new file mode 100644 index 000..5c474b0 --- /dev/null +++ b/drivers/pinctrl/pinctrl-stm32.c @@ -0,0 +1,779 @@ +/* + * Copyright (C) Maxime Coquelin 2015 + * Author: Maxime Coquelin + * License terms: GNU General Public License (GPL), version 2 + * + * Heavily based on pinctrl-st.c from Srinivas Kandagatla + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "core.h" + +#define STM32_GPIO_MODER 0x00 +#define STM32_GPIO_TYPER 0x04 +#define STM32_GPIO_SPEEDR 0x08 +#define STM32_GPIO_PUPDR 0x0c +#define STM32_GPIO_IDR 0x10 +#define STM32_GPIO_ODR 0x14 +#define STM32_GPIO_BSRR0x18 +#define STM32_GPIO_LCKR0x1c +#define STM32_GPIO_AFRL0x20 +#define STM32_GPIO_AFRH0x24 + +#define STM32_GPIO_PINS_PER_BANK 16 +#define OF_GPIO_ARGS_MIN 4 + +#define STM32_PINCONF_UNPACK(conf, param)\ + ((conf >> STM32_PINCONF_ ##param ##_SHIFT) \ + & STM32_PINCONF_ ##param ##_MASK) + +#define STM32_PINCONF_PACK(conf, val, param) (conf |=\ + ((val & STM32_PINCONF_ ##param ##_MASK) << \ + STM32_PINCONF_ ##param ##_SHIFT)) + +#define STM32_PINCONF_SPEED_MASK 0x3 +#define STM32_PINCONF_SPEED_SHIFT 3 +#define STM32_PINCONF_UNPACK_SPEED(conf)\ + STM32_PINCONF_UNPACK(conf, SPEED) +#define STM32_PINCONF_PACK_SPEED(conf, val)\ + STM32_PINCONF_PACK(conf, val, SPEED) + +#define STM32_PINCONF_TYPE_MASK0x1 +#define STM32_PINCONF_TYPE_SHIFT 2 +#define STM32_PINCONF_UNPACK_TYPE(conf)\ + STM32_PINCONF_UNPACK(conf, TYPE) +#define STM32_PINCONF_PACK_TYPE(conf, val)\ + STM32_PINCONF_PACK(conf, val, TYPE) + +#define STM32_PINCONF_PUPD_MASK0x3 +#define STM32_PINCONF_PUPD_SHIFT 0 +#define STM32_PINCONF_UNPACK_PUPD(conf)\ + STM32_PINCONF_UNPACK(conf, PUPD) +#define STM32_PINCONF_PACK_PUPD(conf, val)\ + STM32_PINCONF_PACK(conf, val, PUPD) + + +#define STM32_PINCONF_ALT_MASK 0xf +#define STM32_PINCONF_ALT_SHIFT2 +#define STM32_PINCONF_UNPACK_ALT(conf)\ + STM32_PINCONF_UNPACK(conf, ALT) +#define STM32_PINCONF_PACK_ALT(conf, val)\ + STM32_PINCONF_PACK(conf, val, ALT) + +#define STM32_PINCONF_MODE_MASK0x3 +#define STM32_PINCONF_MODE_SHIFT 0 +#define STM32_PINCONF_UNPACK_MODE(conf)\ + STM32_PINCONF_UNPACK(conf, MODE) +#define STM32_PINCONF_PACK_MODE(conf, val)\ + STM32_PINCONF_PACK(conf, val, MODE) + + + +#define gpio_range_to_bank(chip) \ + container_of(chip, struct stm32_gpio_bank, range) + +#define gpio_chip_to_bank(chip) \ + container_of(chip,
[PATCH v2 11/18] pinctrl: Add pinctrl driver for STM32 MCUs
This driver adds pinctrl and GPIO support to STMicrolectronic's STM32 family of MCUs. Pin muxing and GPIO handling have been tested on STM32F429 based Discovery board. Signed-off-by: Maxime Coquelin mcoquelin.st...@gmail.com --- drivers/pinctrl/Kconfig | 10 + drivers/pinctrl/Makefile| 1 + drivers/pinctrl/pinctrl-stm32.c | 779 include/dt-bindings/pinctrl/pinctrl-stm32.h | 43 ++ 4 files changed, 833 insertions(+) create mode 100644 drivers/pinctrl/pinctrl-stm32.c create mode 100644 include/dt-bindings/pinctrl/pinctrl-stm32.h diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index d014f22..84cd081 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig @@ -125,6 +125,16 @@ config PINCTRL_ST select PINCONF select GPIOLIB_IRQCHIP +config PINCTRL_STM32 + bool STMicroelectronics STM32 pinctrl driver + depends on OF + depends on ARCH_STM32 || COMPILE_TEST + select PINMUX + select PINCONF + select GPIOLIB_IRQCHIP + help + This selects the device tree based generic pinctrl driver for STM32. + config PINCTRL_TEGRA bool select PINMUX diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index c030b3d..06ef8ab 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile @@ -35,6 +35,7 @@ obj-$(CONFIG_PINCTRL_XWAY)+= pinctrl-xway.o obj-$(CONFIG_PINCTRL_LANTIQ) += pinctrl-lantiq.o obj-$(CONFIG_PINCTRL_TB10X)+= pinctrl-tb10x.o obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o +obj-$(CONFIG_PINCTRL_STM32)+= pinctrl-stm32.o obj-$(CONFIG_ARCH_BERLIN) += berlin/ obj-y += freescale/ diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c new file mode 100644 index 000..5c474b0 --- /dev/null +++ b/drivers/pinctrl/pinctrl-stm32.c @@ -0,0 +1,779 @@ +/* + * Copyright (C) Maxime Coquelin 2015 + * Author: Maxime Coquelin mcoquelin.st...@gmail.com + * License terms: GNU General Public License (GPL), version 2 + * + * Heavily based on pinctrl-st.c from Srinivas Kandagatla + */ + +#include linux/init.h +#include linux/module.h +#include linux/slab.h +#include linux/err.h +#include linux/io.h +#include linux/of.h +#include linux/of_gpio.h +#include linux/of_address.h +#include linux/pinctrl/pinctrl.h +#include linux/pinctrl/pinmux.h +#include linux/pinctrl/pinconf.h +#include linux/platform_device.h +#include linux/reset.h +#include core.h + +#define STM32_GPIO_MODER 0x00 +#define STM32_GPIO_TYPER 0x04 +#define STM32_GPIO_SPEEDR 0x08 +#define STM32_GPIO_PUPDR 0x0c +#define STM32_GPIO_IDR 0x10 +#define STM32_GPIO_ODR 0x14 +#define STM32_GPIO_BSRR0x18 +#define STM32_GPIO_LCKR0x1c +#define STM32_GPIO_AFRL0x20 +#define STM32_GPIO_AFRH0x24 + +#define STM32_GPIO_PINS_PER_BANK 16 +#define OF_GPIO_ARGS_MIN 4 + +#define STM32_PINCONF_UNPACK(conf, param)\ + ((conf STM32_PINCONF_ ##param ##_SHIFT) \ +STM32_PINCONF_ ##param ##_MASK) + +#define STM32_PINCONF_PACK(conf, val, param) (conf |=\ + ((val STM32_PINCONF_ ##param ##_MASK) \ + STM32_PINCONF_ ##param ##_SHIFT)) + +#define STM32_PINCONF_SPEED_MASK 0x3 +#define STM32_PINCONF_SPEED_SHIFT 3 +#define STM32_PINCONF_UNPACK_SPEED(conf)\ + STM32_PINCONF_UNPACK(conf, SPEED) +#define STM32_PINCONF_PACK_SPEED(conf, val)\ + STM32_PINCONF_PACK(conf, val, SPEED) + +#define STM32_PINCONF_TYPE_MASK0x1 +#define STM32_PINCONF_TYPE_SHIFT 2 +#define STM32_PINCONF_UNPACK_TYPE(conf)\ + STM32_PINCONF_UNPACK(conf, TYPE) +#define STM32_PINCONF_PACK_TYPE(conf, val)\ + STM32_PINCONF_PACK(conf, val, TYPE) + +#define STM32_PINCONF_PUPD_MASK0x3 +#define STM32_PINCONF_PUPD_SHIFT 0 +#define STM32_PINCONF_UNPACK_PUPD(conf)\ + STM32_PINCONF_UNPACK(conf, PUPD) +#define STM32_PINCONF_PACK_PUPD(conf, val)\ + STM32_PINCONF_PACK(conf, val, PUPD) + + +#define STM32_PINCONF_ALT_MASK 0xf +#define STM32_PINCONF_ALT_SHIFT2 +#define STM32_PINCONF_UNPACK_ALT(conf)\ + STM32_PINCONF_UNPACK(conf, ALT) +#define STM32_PINCONF_PACK_ALT(conf, val)\ + STM32_PINCONF_PACK(conf, val, ALT) + +#define STM32_PINCONF_MODE_MASK0x3 +#define STM32_PINCONF_MODE_SHIFT 0 +#define STM32_PINCONF_UNPACK_MODE(conf)\ + STM32_PINCONF_UNPACK(conf, MODE) +#define STM32_PINCONF_PACK_MODE(conf, val)\ +