ARM:STiH41x: Add STiH41x platform and board support
Subsystems (10)
cover ARM:STiH41x: Add STiH41x platform and board support
From: Srinivas Kandagatla <[email protected]>
This patch-set adds basic support for STMicroelectronics STiH41x SOCs which includes STiH415 and STiH416 with B2000 and B2020 board support.
STiH415 and STiH416 are dual-core ARM Cortex-A9 CPU, designed for use in Set-top-boxes.
The SOC support is divided into two parts which is plat-stixxxx and mach-stih41x. plat-stixxxx contains code which is common across all STMicroelectronics CE chips, and mach-stih41x contains support code for STiH415 and STiH416 SOCs.
Only device drivers included in this patch set are UART and pinctrl, other drivers will be added in future.
The reason for adding two SOCs at this patch set is to show that no new C code is required for second SOC(STiH416) support.
In the process of adding support to these SOCs we have added new code into sycon and also added support for a9 global-timer.
I would appreciate any feedback on these patches.
Thanks,
srini
Srinivas Kandagatla (8):
serial:st-asc: Add ST ASC driver. mfd:syscon: Introduce claim/read/write/release APIs pinctrl:stixxxx: Add pinctrl and pinconf support. ARM:stih41x: Add STiH415 SOC support ARM:stih41x: Add STiH416 SOC support ARM:stih41x: Add B2000 board support ARM:stih41x: Add B2020 board support
Stuart Menefy (1):
ARM:global_timer: Add ARM global timer support.
Documentation/arm/STiH41x/overview.txt | 39 + Documentation/arm/STiH41x/stih415-overview.txt | 12 + Documentation/arm/STiH41x/stih416-overview.txt | 12 + Documentation/devicetree/bindings/arm/gt.txt | 21 + .../bindings/pinctrl/pinctrl-stixxxx.txt | 160 +++ .../devicetree/bindings/tty/serial/st-asc.txt | 18 + arch/arm/Kconfig | 9 + arch/arm/Kconfig.debug | 38 + arch/arm/Makefile | 2 + arch/arm/boot/dts/Makefile | 4 + arch/arm/boot/dts/stih415-b2000.dtsp | 15 + arch/arm/boot/dts/stih415-b2020.dtsp | 15 + arch/arm/boot/dts/stih415-clock.dtsi | 38 + arch/arm/boot/dts/stih415-pinctrl.dtsi | 480 ++++++++ arch/arm/boot/dts/stih415.dtsi | 94 ++ arch/arm/boot/dts/stih415.h | 20 + arch/arm/boot/dts/stih416-b2000.dtsp | 16 + arch/arm/boot/dts/stih416-b2020.dtsp | 16 + arch/arm/boot/dts/stih416-clock.dtsi | 41 + arch/arm/boot/dts/stih416-pinctrl.dtsi | 718 ++++++++++++ arch/arm/boot/dts/stih416.dtsi | 103 ++ arch/arm/boot/dts/stih416.h | 24 + arch/arm/boot/dts/stih41x-b2000.dtsi | 41 + arch/arm/boot/dts/stih41x-b2020.dtsi | 42 + arch/arm/boot/dts/stih41x.dtsi | 30 + arch/arm/boot/dts/stixxxx-pincfg.h | 95 ++ arch/arm/configs/stih41x_defconfig | 95 ++ arch/arm/include/asm/global_timer.h | 12 + arch/arm/include/debug/stixxxx.S | 61 + arch/arm/kernel/Makefile | 1 + arch/arm/kernel/global_timer.c | 325 ++++++ arch/arm/mach-stih41x/Kconfig | 44 + arch/arm/mach-stih41x/Makefile | 4 + arch/arm/mach-stih41x/board-dt.c | 80 ++ arch/arm/mach-stih41x/stih41x.c | 82 ++ arch/arm/mach-stih41x/stih41x.h | 7 + arch/arm/plat-stixxxx/Kconfig | 2 + arch/arm/plat-stixxxx/Makefile | 2 + arch/arm/plat-stixxxx/headsmp.S | 44 + arch/arm/plat-stixxxx/include/plat/hardware.h | 20 + arch/arm/plat-stixxxx/include/plat/smp.h | 19 + arch/arm/plat-stixxxx/platsmp.c | 144 +++ drivers/mfd/syscon.c | 199 ++++ drivers/pinctrl/Kconfig | 13 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-stixxxx.c | 1151 ++++++++++++++++++++ drivers/pinctrl/pinctrl-stixxxx.h | 197 ++++ drivers/tty/serial/Kconfig | 19 + drivers/tty/serial/Makefile | 1 + drivers/tty/serial/st-asc.c | 821 ++++++++++++++ drivers/tty/serial/st-asc.h | 146 +++ include/linux/mfd/syscon.h | 43 + include/uapi/linux/serial_core.h | 3 + 53 files changed, 5639 insertions(+), 0 deletions(-) create mode 100644 Documentation/arm/STiH41x/overview.txt create mode 100644 Documentation/arm/STiH41x/stih415-overview.txt create mode 100644 Documentation/arm/STiH41x/stih416-overview.txt create mode 100644 Documentation/devicetree/bindings/arm/gt.txt create mode 100644 Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt create mode 100644 Documentation/devicetree/bindings/tty/serial/st-asc.txt create mode 100644 arch/arm/boot/dts/stih415-b2000.dtsp create mode 100644 arch/arm/boot/dts/stih415-b2020.dtsp create mode 100644 arch/arm/boot/dts/stih415-clock.dtsi create mode 100644 arch/arm/boot/dts/stih415-pinctrl.dtsi create mode 100644 arch/arm/boot/dts/stih415.dtsi create mode 100644 arch/arm/boot/dts/stih415.h create mode 100644 arch/arm/boot/dts/stih416-b2000.dtsp create mode 100644 arch/arm/boot/dts/stih416-b2020.dtsp create mode 100644 arch/arm/boot/dts/stih416-clock.dtsi create mode 100644 arch/arm/boot/dts/stih416-pinctrl.dtsi create mode 100644 arch/arm/boot/dts/stih416.dtsi create mode 100644 arch/arm/boot/dts/stih416.h create mode 100644 arch/arm/boot/dts/stih41x-b2000.dtsi create mode 100644 arch/arm/boot/dts/stih41x-b2020.dtsi create mode 100644 arch/arm/boot/dts/stih41x.dtsi create mode 100644 arch/arm/boot/dts/stixxxx-pincfg.h create mode 100644 arch/arm/configs/stih41x_defconfig create mode 100644 arch/arm/include/asm/global_timer.h create mode 100644 arch/arm/include/debug/stixxxx.S create mode 100644 arch/arm/kernel/global_timer.c create mode 100644 arch/arm/mach-stih41x/Kconfig create mode 100644 arch/arm/mach-stih41x/Makefile create mode 100644 arch/arm/mach-stih41x/board-dt.c create mode 100644 arch/arm/mach-stih41x/stih41x.c create mode 100644 arch/arm/mach-stih41x/stih41x.h create mode 100644 arch/arm/plat-stixxxx/Kconfig create mode 100644 arch/arm/plat-stixxxx/Makefile create mode 100644 arch/arm/plat-stixxxx/headsmp.S create mode 100644 arch/arm/plat-stixxxx/include/plat/hardware.h create mode 100644 arch/arm/plat-stixxxx/include/plat/smp.h create mode 100644 arch/arm/plat-stixxxx/platsmp.c create mode 100644 drivers/pinctrl/pinctrl-stixxxx.c create mode 100644 drivers/pinctrl/pinctrl-stixxxx.h create mode 100644 drivers/tty/serial/st-asc.c create mode 100644 drivers/tty/serial/st-asc.h
Signature · 1 line
1.7.6.5
A message that is not in the archive (sent off-list or not yet received): 1368022187-1633-1-git-send-email-srinivas.kandagatla-qxv4g6HH51o@public.gmane.org
RFC 1/8 serial:st-asc: Add ST ASC driver.
From: Srinivas Kandagatla <[email protected]>
This patch adds support to ASC (asynchronous serial controller) driver, which is basically a standard serial driver. This IP is common across all the ST parts for settop box platforms.
ASC is embedded in ST COMMS IP block. It supports Rx & Tx functionality. It support all industry standard baud rates.
--- .../devicetree/bindings/tty/serial/st-asc.txt | 18 + drivers/tty/serial/Kconfig | 19 + drivers/tty/serial/Makefile | 1 + drivers/tty/serial/st-asc.c | 821 ++++++++++++++++++++ drivers/tty/serial/st-asc.h | 146 ++++ include/uapi/linux/serial_core.h | 3 + 6 files changed, 1008 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/tty/serial/st-asc.txt create mode 100644 drivers/tty/serial/st-asc.c create mode 100644 drivers/tty/serial/st-asc.h
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +18 -0
@@ -0,0 +1,18 @@ +*st-asc(Serial Port) + +Required properties: +- compatible : Should be "st,asc". +- reg, reg-names, interrupts, interrupt-names : Standard way to define device + resources with names. look in + Documentation/devicetree/bindings/resource-names.txt + +Optional properties: +- st,hw-flow-ctrl bool flag to enable hardware flow control. +- st,force-m1 bool flat to force asc to be in Mode-1 recommeded + for high bit rates (above 19.2K) +Example: +serial@fe440000{ + compatible = "st,asc"; + reg = <0xfe440000 0x2c>; + interrupts = <0 209 0>; +};
drivers/tty/serial/Kconfig +19 -0
@@ -1484,6 +1484,25 @@ config SERIAL_RP2_NR_UARTS If multiple cards are present, the default limit of 32 ports may need to be increased. +config SERIAL_ST_ASC + tristate "ST ASC serial port support" + depends on PLAT_STIXXXX + default y + select SERIAL_CORE + help + This driver is for the on-chip Asychronous Serial Controller on + STMicroelectronics STixxxx SoCs. + ASC is embedded in ST COMMS IP block. It supports Rx & Tx functionality. + It support all industry standard baud rates. + + If unsure, say N. + +config SERIAL_ST_ASC_CONSOLE + bool "Support for console on ST ASC" + depends on SERIAL_ST_ASC + default y + select SERIAL_CORE_CONSOLE + endmenu endif # TTY
drivers/tty/serial/Makefile +1 -0
@@ -65,6 +65,7 @@ obj-$(CONFIG_SERIAL_KGDB_NMI) += kgdb_nmi.o obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o +obj-$(CONFIG_SERIAL_ST_ASC) += st-asc.o obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o obj-$(CONFIG_SERIAL_QE) += ucc_uart.o obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o
drivers/tty/serial/st-asc.c new file +821 -0
821 lines not on this page · raw message
drivers/tty/serial/st-asc.h new file +146 -0
146 lines not on this page · raw message
include/uapi/linux/serial_core.h +3 -0
@@ -226,4 +226,7 @@/* Rocketport EXPRESS/INFINITY */ #define PORT_RP2 102 +/* ST ASC type numbers */ +#define PORT_ASC 103 +#endif /* _UAPILINUX_SERIAL_CORE_H */
Signature · 1 line
1.7.6.5
Arnd Bergmann
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Documentation/devicetree/bindings/tty/serial/st-asc.txt line 4
Quoted 6 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +4
-0+*st-asc(Serial Port) + +Required properties: +- compatible : Should be "st,asc".
Are there any hardware revision numbers for the asc? If there are potentially incompatible or backwards-compatible variants, it would be good to include the version in this string.
Quoted 4 lines
+- reg, reg-names, interrupts, interrupt-names : Standard way to define device
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +3
-0+ resources with names. look in + Documentation/devicetree/bindings/resource-names.txt +
Documentation/devicetree/bindings/tty/serial/st-asc.txt line 18
Quoted 10 lines
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +10
-0+Optional properties: +- st,hw-flow-ctrl bool flag to enable hardware flow control. +- st,force-m1 bool flat to force asc to be in Mode-1 recommeded + for high bit rates (above 19.2K) +Example: +serial at fe440000{ + compatible = "st,asc"; + reg = <0xfe440000 0x2c>; + interrupts = <0 209 0>; +};
I would also recommed adding a way to set the default baud rate through a property. Following the example of the 8250 driver, you should probably call that "current-speed".
Quoted 10 lines
drivers/tty/serial/Kconfig +2
-0@@ -1484,6 +1484,25 @@ config SERIAL_RP2_NR_UARTS If multiple cards are present, the default limit of 32 ports may need to be increased. +config SERIAL_ST_ASC + tristate "ST ASC serial port support"
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS · line 1498
Quoted 10 lines
drivers/tty/serial/Kconfig +10
-0+ depends on PLAT_STIXXXX + default y + select SERIAL_CORE + help + This driver is for the on-chip Asychronous Serial Controller on + STMicroelectronics STixxxx SoCs. + ASC is embedded in ST COMMS IP block. It supports Rx & Tx functionality. + It support all industry standard baud rates. + + If unsure, say N.
I would not make it "default y".
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS · line 1506
Quoted 7 lines
drivers/tty/serial/Kconfig +6
-0+config SERIAL_ST_ASC_CONSOLE + bool "Support for console on ST ASC" + depends on SERIAL_ST_ASC + default y + select SERIAL_CORE_CONSOLE + endmenu
This needs to be "depends on SERIAL_ST_ASC=y". You would get a link error if you try to make SERIAL_ST_ASC a loadable module and SERIAL_ST_ASC_CONSOLE built-in.
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS
Quoted 9 lines
drivers/tty/serial/Kconfig +9
-0+ +static struct asc_port asc_ports[ASC_MAX_PORTS]; +static struct uart_driver asc_uart_driver; + +/*---- Forward function declarations---------------------------*/ +static irqreturn_t asc_interrupt(int irq, void *ptr); +static void asc_transmit_chars(struct uart_port *); +static int asc_set_baud(struct asc_port *ascport, int baud); +
Please remove all forward declarations, by reordering the functions in the way they are called.
Quoted 8 lines
drivers/tty/serial/st-asc.h new file +3
-0+#ifndef _ST_ASC_H +#define _ST_ASC_H +
drivers/tty/serial/st-asc.h line 25
Quoted 10 lines
drivers/tty/serial/st-asc.h new file +10
-0+#include <linux/serial_core.h> +#include <linux/clk.h> + +struct asc_port { +struct uart_port port; +struct clk *clk; +unsigned int hw_flow_control:1 ; +unsigned int check_parity:1 ; +unsigned int force_m1:1 ; +};
Since this header file is only used in one place, just merge it into the driver itself.
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40
I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
Documentation/devices.txt lists the ones that are officially assigned. Can't you use dynamic allocation here?
Arnd
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 11 lines · Arnd Bergmann
Documentation/devicetree/bindings/tty/serial/st-asc.txt line 4
Quoted 6 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +4
-0+*st-asc(Serial Port) + +Required properties: +- compatible : Should be "st,asc".Are there any hardware revision numbers for the asc? If there are potentially incompatible or backwards-compatible variants, it would be good to include the version in this string.
The st,asc come from st20 or st200 IIRC which was not ARM but a ST arch and then used on st40 series
an the st,asc for st200 and st40 are not compatible completly
Quoted 11 lines
Quoted 11 lines
+- reg, reg-names, interrupts, interrupt-names : Standard way to define device
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +9
-0+ resources with names. look in + Documentation/devicetree/bindings/resource-names.txt + +Optional properties: +- st,hw-flow-ctrl bool flag to enable hardware flow control. +- st,force-m1 bool flat to force asc to be in Mode-1 recommeded + for high bit rates (above 19.2K) +Example: +serial at fe440000{
Quoted 8 lines
Documentation/devicetree/bindings/tty/serial/st-asc.txt line 18
Quoted 4 lines
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +4
-0+ compatible = "st,asc"; + reg = <0xfe440000 0x2c>; + interrupts = <0 209 0>; +};I would also recommed adding a way to set the default baud rate through a property. Following the example of the 8250 driver, you should probably call that "current-speed".
on st it has always be 38k
Quoted 9 lines
Quoted 9 lines
drivers/tty/serial/Kconfig +0
-0@@ -1484,6 +1484,25 @@ config SERIAL_RP2_NR_UARTS If multiple cards are present, the default limit of 32 ports may need to be increased.
Quoted 14 lines
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS · line 1498
Quoted 12 lines
drivers/tty/serial/Kconfig +12
-0+config SERIAL_ST_ASC + tristate "ST ASC serial port support" + depends on PLAT_STIXXXX + default y + select SERIAL_CORE + help + This driver is for the on-chip Asychronous Serial Controller on + STMicroelectronics STixxxx SoCs. + ASC is embedded in ST COMMS IP block. It supports Rx & Tx functionality. + It support all industry standard baud rates. + + If unsure, say N.I would not make it "default y".
me too
Quoted 13 lines
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS · line 1506
Quoted 8 lines
drivers/tty/serial/Kconfig +6
-0+config SERIAL_ST_ASC_CONSOLE + bool "Support for console on ST ASC" + depends on SERIAL_ST_ASC + default y + select SERIAL_CORE_CONSOLE + endmenuThis needs to be "depends on SERIAL_ST_ASC=y". You would get a link error if you try to make
SERIAL_ST_ASCa loadable module andSERIAL_ST_ASC_CONSOLEbuilt-in.
Quoted 13 lines
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS
Quoted 9 lines
drivers/tty/serial/Kconfig +9
-0+ +static struct asc_port asc_ports[ASC_MAX_PORTS]; +static struct uart_driver asc_uart_driver; + +/*---- Forward function declarations---------------------------*/ +static irqreturn_t asc_interrupt(int irq, void *ptr); +static void asc_transmit_chars(struct uart_port *); +static int asc_set_baud(struct asc_port *ascport, int baud); +Please remove all forward declarations, by reordering the functions in the way they are called.
and drop the dummy functions
Quoted 37 lines
Quoted 9 lines
drivers/tty/serial/st-asc.h new file +3
-0+#ifndef _ST_ASC_H +#define _ST_ASC_H +drivers/tty/serial/st-asc.h line 25
Quoted 10 lines
drivers/tty/serial/st-asc.h new file +10
-0+#include <linux/serial_core.h> +#include <linux/clk.h> + +struct asc_port { +struct uart_port port; +struct clk *clk; +unsigned int hw_flow_control:1 ; +unsigned int check_parity:1 ; +unsigned int force_m1:1 ; +};Since this header file is only used in one place, just merge it into the driver itself.
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
Documentation/devices.txtlists the ones that are officially assigned. Can't you use dynamic allocation here?Arnd
_______________________________________________
devicetree-discuss mailing list
devicetree-discuss at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines
Quoted 5 lines
+
Please remove all forward declarations, by reordering the functions in the way they are called.
and drop the dummy functions
We can not remove the dummy functions, as the serial-core does not check it before using them.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/tty/serial/st-asc.h new file +0
-0
Arnd Bergmann
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 11 lines · Srinivas KANDAGATLA
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines
Quoted 5 lines
+
Please remove all forward declarations, by reordering the functions in the way they are called.
and drop the dummy functions
We can not remove the dummy functions, as the serial-core does not check it before using them.
None of them seem performance critical, so it sounds reasonable to change this in the core so you don't have to provide them. It's up to Greg to decide whether he'd like that change or not.
Arnd
Greg KH
maintainerRFC 1/8 serial:st-asc: Add ST ASC driver.
In reply to Arnd BergmannQuoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
thanks,
greg k-h
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 10 lines · Greg KH
Quoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
Greg on ST STB for more than 10 years we use ttyASC I'll prefer ttySx
on the DTB SoC you have one one IP present the st,asc
Best Regards,
J.
Quoted 8 lines
thanks,
greg k-h
_______________________________________________
devicetree-discuss mailing list
devicetree-discuss at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss
Greg KH
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 8 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 7 lines · Greg KH
Quoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
Quoted 5 lines
Quoted 3 lines
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
Greg on ST STB for more than 10 years we use ttyASC I'll prefer ttySx
For 10+ years you have had an out-of-tree serial driver? What major/minor numbers did you use for it?
Quoted 1 line
on the DTB SoC you have one one IP present the st,asc
I don't understand, what do you mean by this?
confused,
greg k-h
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 9 lines · Greg KH
Quoted 8 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 7 lines · Greg KH
Quoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
Greg on ST STB for more than 10 years we use ttyASC I'll prefer ttySx
For 10+ years you have had an out-of-tree serial driver?
yes ST have it out of tree for very long time even I puts them to come mainline
Quoted 2 lines
What
major/minor numbers did you use for it?
52 #define ASC_MAJOR 204
53 #define ASC_MINOR_START 40
same as in this patch
Quoted 6 lines
Quoted 2 lines
on the DTB SoC you have one one IP present the st,asc
I don't understand, what do you mean by this?
confused,
just mention there is not hardware reason to not use the generic ttySx in place of ttyAS as we have only one IP that handle serial on this family of SoC
personally I'll switch to ttySx
Best Regards,
J.
Greg KH
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 12 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 9 lines · Greg KH
Quoted 8 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 7 lines · Greg KH
Quoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
Greg on ST STB for more than 10 years we use ttyASC I'll prefer ttySx
For 10+ years you have had an out-of-tree serial driver?
yes ST have it out of tree for very long time even I puts them to come mainline
Crazy...
Quoted 9 lines
Quoted 2 lines
What
major/minor numbers did you use for it?52 #define
ASC_MAJOR204
53 #defineASC_MINOR_START40same as in this patch
Ok, but just because you have been using an out-of-tree name, and non-reserved major/minor, doesn't mean we have to accept it. As you are probably using a tool like udev/devtmpfs on your systems, the major/minor number shouldn't matter, only the name.
And I'd argue that we should change the name as well.
Quoted 11 lines
Quoted 5 lines
Quoted 1 line
on the DTB SoC you have one one IP present the st,asc
I don't understand, what do you mean by this?
confused,
just mention there is not hardware reason to not use the generic ttySx in place of ttyAS as we have only one IP that handle serial on this family of SoC
personally I'll switch to ttySx
Great, then you can use the same major/minor range as well, so there's no more objection from me about this :)
thanks,
greg k-h
Arnd Bergmann
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 8 lines · Greg KH
Quoted 5 lines
just mention there is not hardware reason to not use the generic ttySx in place of ttyAS as we have only one IP that handle serial on this family of SoC
personally I'll switch to ttySx
Great, then you can use the same major/minor range as well, so there's no more objection from me about this :)
Does that work these days when you have kernel with multiple built-in uart drivers?
I think it would be good if all uarts were using the same name space and major/minor numbers, but I think the mess we currently have is the result of the tty_register_driver() interface reserving the device number range at driver load time, independent of the presence of devices. I would assume that normal distro kernels always ship with an 8250 driver built-in to allow using that as the console, and if I read the code correctly, that currently prevents another uart driver from registering the same major/minor numbers.
Arnd
Greg KH
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Greg KH
Quoted 4 lines
just mention there is not hardware reason to not use the generic ttySx in place of ttyAS as we have only one IP that handle serial on this family of SoC
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
personally I'll switch to ttySx
Great, then you can use the same major/minor range as well, so there's no more objection from me about this :)
Does that work these days when you have kernel with multiple built-in uart drivers?
It "should", as the major/minor registration should only happen when the hardware is found, but I haven't tested it out, so I can't say for sure.
Quoted 8 lines
I think it would be good if all uarts were using the same name space and major/minor numbers, but I think the mess we currently have is the result of the
tty_register_driver()interface reserving the device number range at driver load time, independent of the presence of devices. I would assume that normal distro kernels always ship with an 8250 driver built-in to allow using that as the console, and if I read the code correctly, that currently prevents another uart driver from registering the same major/minor numbers.
We can always fix this if needed :)
thanks,
greg k-h
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 8 lines · Greg KH
Quoted 7 lines · Arnd Bergmann
Quoted 6 lines · Greg KH
Quoted 5 lines
just mention there is not hardware reason to not use the generic ttySx in place of ttyAS as we have only one IP that handle serial on this family of SoC
personally I'll switch to ttySx
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Great, then you can use the same major/minor range as well, so there's no more objection from me about this :)
Does that work these days when you have kernel with multiple built-in uart drivers?
It "should", as the major/minor registration should only happen when the hardware is found, but I haven't tested it out, so I can't say for sure.
serial stuff has never operated like that. More specifically, it's a limitation with the tty stuff that the way stuff works is that a tty driver can only drive a single bunch of contiguous minor numbers. No interleaving is allowed.
That limitation has existed for years, and I don't see it going away. As long as that limitation exists, you can only ever have one serial driver driving a set of contiguous minor numbers.
There has been an attempt to "work around" this by making the 8250 driver "special" which was a complete hack to get it to work. That was while I maintained this stuff and I outright refused to make one serial driver magically special.
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
In reply to Arnd BergmannQuoted 5 lines · Arnd Bergmann
Quoted 4 lines · Greg KH
Quoted 4 lines
just mention there is not hardware reason to not use the generic ttySx in place of ttyAS as we have only one IP that handle serial on this family of SoC
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
personally I'll switch to ttySx
Great, then you can use the same major/minor range as well, so there's no more objection from me about this :)
Does that work these days when you have kernel with multiple built-in uart drivers?
not for very long time and no this family
Quoted 9 lines
I think it would be good if all uarts were using the same name space and major/minor numbers, but I think the mess we currently have is the result of the
tty_register_driver()interface reserving the device number range at driver load time, independent of the presence of devices. I would assume that normal distro kernels always ship with an 8250 driver built-in to allow using that as the console, and if I read the code correctly, that currently prevents another uart driver from registering the same major/minor numbers.
so we need to fix this
Quoted 7 lines
Arnd
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
In reply to Arnd BergmannQuoted 13 lines · Arnd Bergmann
Quoted 8 lines · Greg KH
Quoted 5 lines
just mention there is not hardware reason to not use the generic ttySx in place of ttyAS as we have only one IP that handle serial on this family of SoC
personally I'll switch to ttySx
Great, then you can use the same major/minor range as well, so there's no more objection from me about this :)
Does that work these days when you have kernel with multiple built-in uart drivers?
Quoted 8 lines
I think it would be good if all uarts were using the same name space and major/minor numbers, but I think the mess we currently have is the result of the
tty_register_driver()interface reserving the device number range at driver load time, independent of the presence of devices. I would assume that normal distro kernels always ship with an 8250 driver built-in to allow using that as the console, and if I read the code correctly, that currently prevents another uart driver from registering the same major/minor numbers.
I tried to fix this up over 10 years ago. RMK tried as well. This failed because X86 people insisted on always having COM1 as /dev/ttyS0, COM3 as /dev/ttyS2 and so on, even when some of them weren't present.
A common and dynamic namespace eventually succeeded for hard disks. Maybe people are ready to accept it for serial ports as well now?
Nicolas
Arnd Bergmann
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 6 lines · Nicolas Pitre
I tried to fix this up over 10 years ago. RMK tried as well. This failed because X86 people insisted on always having COM1 as
/dev/ttyS0, COM3 as/dev/ttyS2and so on, even when some of them weren't present.A common and dynamic namespace eventually succeeded for hard disks. Maybe people are ready to accept it for serial ports as well now?
Unfortunately it only worked for hard disks because the old name space was abandoned entirely. It also caused a lot of surprises for people upgrading their kernels, which is something we probably don't want to repeat.
Now we could add a new dynamic registration facility to the tty layer for drivers that don't already have a name and dev_t associated with the driver, and then use it for all new drivers as well as those that intentionally want to convert.
With DT aliases, we already have a way to enumerate serial ports across device drivers, so if we are going to do something new, we should make sure it works with the numbers defined there.
Arnd
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 13 lines · Arnd Bergmann
Quoted 6 lines · Nicolas Pitre
I tried to fix this up over 10 years ago. RMK tried as well. This failed because X86 people insisted on always having COM1 as
/dev/ttyS0, COM3 as/dev/ttyS2and so on, even when some of them weren't present.A common and dynamic namespace eventually succeeded for hard disks. Maybe people are ready to accept it for serial ports as well now?
Unfortunately it only worked for hard disks because the old name space was abandoned entirely. It also caused a lot of surprises for people upgrading their kernels, which is something we probably don't want to repeat.
Quoted 4 lines
Now we could add a new dynamic registration facility to the tty layer for drivers that don't already have a name and
dev_tassociated with the driver, and then use it for all new drivers as well as those that intentionally want to convert.
specially that we use devtmpfs and udev
we do not care much about minor/major
Quoted 6 lines
With DT aliases, we already have a way to enumerate serial ports across device drivers, so if we are going to do something new, we should make sure it works with the numbers defined there.
Arnd
RE: [RFC 1/8] serial:st-asc: Add ST ASC driver.
In reply to Greg KHQuoted 7 lines · Arnd Bergmann
Quoted 5 lines
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
First, our apologies, this issue was raised internally and then got forgotten about, there's always something I guess.
Quoted 2 lines
Quoted 2 lines
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
That is an interesting question Greg; I believe it probably stems from historic ST SoCs that had two different types of serial devices, something that is no longer the case. We will review our approach to this again, although we are not sure we can use the existing ttyS major/minor (even if that is an acceptable thing to do) because of the (remote) possibility of someone using a standard PCIe attached serial card.
Regards,
-stephen
RE: [RFC 1/8] serial:st-asc: Add ST ASC driver.
In reply to Greg KHQuoted 9 lines · Arnd Bergmann
Quoted 5 lines
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
First, our apologies, this issue was raised internally and then got forgotten about, there's always something I guess.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
I agree, why are you trying to create a new tty device name? Can't
you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?That is an interesting question Greg; I believe it probably stems from historic ST SoCs that had two different types of serial devices, something that is no longer the case. We will review our approach to this again, although we are not sure we can use the existing ttyS major/minor (even if that is an acceptable thing to do) because of the (remote) possibility of someone using a standard PCIe attached serial card.
Greg, having looked at this we have concluded that we should just go dynamic, as others have mentioned with udev on a full system or devtmpfs on a minimal initramfs system there is no reason to use a static major/minor. However the view here is that we would prefer to keep the unique name, as for example the lantiq driver which is also dynamic does, for the reason previously mentioned regarding PCIe cards.
Is that acceptable?
Regards,
-stephen
Greg KH
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 7 lines · Stephen GALLIMORE
Greg, having looked at this we have concluded that we should just go dynamic, as others have mentioned with udev on a full system or devtmpfs on a minimal initramfs system there is no reason to use a static major/minor. However the view here is that we would prefer to keep the unique name, as for example the lantiq driver which is also dynamic does, for the reason previously mentioned regarding PCIe cards.
Why do you want your own name?
Quoted 1 line
Is that acceptable?
I would prefer not to use a new serial port name, as this is only going to make it harder for me to delete that name in the next year :)
Sorry,
greg k-h
RFC 1/8 serial:st-asc: Add ST ASC driver.
In reply to Greg KHQuoted 10 lines · Greg KH
Quoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
This would be an issue on systems that either accept plug-in cards such as PCMCIA/CardBus/PCI or have additional off SoC IO spaces where 8250 compatible UARTS could live.
Signature · 2 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius
Greg KH
maintainerRFC 1/8 serial:st-asc: Add ST ASC driver.
Quoted 8 lines · Ben Dooks
Quoted 7 lines · Greg KH
Quoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
Quoted 7 lines
Quoted 3 lines
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
This would be an issue on systems that either accept plug-in cards such as PCMCIA/CardBus/PCI or have additional off SoC IO spaces where 8250 compatible UARTS could live.
I thought these were set-top box systems that couldn't accept any plug-in cards or anything else? This is a SoC, right?
thanks,
greg k-h
RFC 1/8 serial:st-asc: Add ST ASC driver.
Quoted 13 lines · Greg KH
Quoted 12 lines · Ben Dooks
Quoted 10 lines · Greg KH
Quoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
Quoted 6 lines
Quoted 3 lines
This would be an issue on systems that either accept plug-in cards such as PCMCIA/CardBus/PCI or have additional off SoC IO spaces where 8250 compatible UARTS could live.
I thought these were set-top box systems that couldn't accept any plug-in cards or anything else? This is a SoC, right?
The comment covers more than just this particular instance.
A lot of SoC devices have expansion interfaces which would accept such UARTs.
Signature · 2 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius
RFC 1/8 serial:st-asc: Add ST ASC driver.
In reply to Greg KHQuoted 13 lines · Greg KH
Quoted 12 lines · Ben Dooks
Quoted 10 lines · Greg KH
Quoted 5 lines · Arnd Bergmann
drivers/tty/serial/st-asc.h line 28
Quoted 2 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
I agree, why are you trying to create a new tty device name? Can't you use the existing ttyS name and minor number as you will not have any other type of serial device on this system?
Quoted 6 lines
Quoted 3 lines
This would be an issue on systems that either accept plug-in cards such as PCMCIA/CardBus/PCI or have additional off SoC IO spaces where 8250 compatible UARTS could live.
I thought these were set-top box systems that couldn't accept any plug-in cards or anything else? This is a SoC, right?
Correct, it is a SoC intended for set-top-box systems. But they are also expandable and have a PCIe root complex. In the final system this would normally be used for things like WiFi, but in development boards these are brought out to generic PCIe slots where pretty much anything can be plugged in.
We've also had systems in the dim and distant past which used memory mapped external super I/O controllers which had 8250 compatible serial ports.
So while its not usual, we have had systems with both ASC and 8250 compatible serial ports, which is why we'd like to keep the option open.
Stuart
Re: [RFC 1/8] serial:st-asc: Add ST ASC driver.
In reply to Arnd BergmannThankyou for the comments.
Quoted 9 lines · Arnd Bergmann
Documentation/devicetree/bindings/tty/serial/st-asc.txt line 4
Quoted 5 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +4
-0+*st-asc(Serial Port) + +Required properties: +- compatible : Should be "st,asc".Are there any hardware revision numbers for the asc? If there are potentially incompatible or backwards-compatible variants, it would be good to include the version in this string.
Unfortunately, there is no version numbering for this IP.
Quoted 10 lines
Quoted 10 lines
+- reg, reg-names, interrupts, interrupt-names : Standard way to define device
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +8
-0+ resources with names. look in + Documentation/devicetree/bindings/resource-names.txt + +Optional properties: +- st,hw-flow-ctrl bool flag to enable hardware flow control. +- st,force-m1 bool flat to force asc to be in Mode-1 recommeded + for high bit rates (above 19.2K) +Example:
Quoted 8 lines
Documentation/devicetree/bindings/tty/serial/st-asc.txt line 18
Quoted 5 lines
Documentation/devicetree/bindings/tty/serial/st-asc.txt new file +5
-0+serial at fe440000{ + compatible = "st,asc"; + reg = <0xfe440000 0x2c>; + interrupts = <0 209 0>; +};I would also recommed adding a way to set the default baud rate through a property. Following the example of the 8250 driver, you should probably call that "current-speed".
Yes, I will add this in the next version.
Quoted 9 lines
Quoted 9 lines
drivers/tty/serial/Kconfig +0
-0@@ -1484,6 +1484,25 @@ config SERIAL_RP2_NR_UARTS If multiple cards are present, the default limit of 32 ports may need to be increased.
Quoted 13 lines
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS · line 1498
Quoted 12 lines
drivers/tty/serial/Kconfig +12
-0+config SERIAL_ST_ASC + tristate "ST ASC serial port support" + depends on PLAT_STIXXXX + default y + select SERIAL_CORE + help + This driver is for the on-chip Asychronous Serial Controller on + STMicroelectronics STixxxx SoCs. + ASC is embedded in ST COMMS IP block. It supports Rx & Tx functionality. + It support all industry standard baud rates. + + If unsure, say N.I would not make it "default y".
Yep.
Quoted 10 lines
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS · line 1506
Quoted 7 lines
drivers/tty/serial/Kconfig +6
-0+config SERIAL_ST_ASC_CONSOLE + bool "Support for console on ST ASC" + depends on SERIAL_ST_ASC + default y + select SERIAL_CORE_CONSOLE + endmenuThis needs to be "depends on SERIAL_ST_ASC=y". You would get a link error if you try to make
SERIAL_ST_ASCa loadable module andSERIAL_ST_ASC_CONSOLEbuilt-in.
Ok, got it.
Quoted 12 lines
drivers/tty/serial/Kconfig config SERIAL_RP2_NR_UARTS
Quoted 10 lines
drivers/tty/serial/Kconfig +9
-0+ +static struct asc_port asc_ports[ASC_MAX_PORTS]; +static struct uart_driver asc_uart_driver; + +/*---- Forward function declarations---------------------------*/ +static irqreturn_t asc_interrupt(int irq, void *ptr); +static void asc_transmit_chars(struct uart_port *); +static int asc_set_baud(struct asc_port *ascport, int baud); +Please remove all forward declarations, by reordering the functions in the way they are called.
Will do.
Quoted 14 lines
Quoted 14 lines
drivers/tty/serial/st-asc.h new file +7
-0+#ifndef _ST_ASC_H +#define _ST_ASC_H + +#include <linux/serial_core.h> +#include <linux/clk.h> + +struct asc_port {
Quoted 8 lines
drivers/tty/serial/st-asc.h line 25
Quoted 6 lines
drivers/tty/serial/st-asc.h new file +6
-0+struct uart_port port; +struct clk *clk; + unsigned int hw_flow_control:1; + unsigned int check_parity:1; + unsigned int force_m1:1; +};Since this header file is only used in one place, just merge it into the driver itself.
Ok, will do it.
Quoted 11 lines
drivers/tty/serial/st-asc.h line 28
Quoted 3 lines
drivers/tty/serial/st-asc.h new file +2
-0+#define ASC_MAJOR 204 +#define ASC_MINOR_START 40I don't know what the current policy is on allocating major/minor numbers, but I'm sure you cannot just reuse one that is already used.
Documentation/devices.txtlists the ones that are officially assigned. Can't you use dynamic allocation here?Arnd
RE: [RFC 1/8] serial:st-asc: Add ST ASC driver.
In reply to Arnd BergmannHi Arnd,
We have pretty much completed reworking the patch set we sent recently, but there is one comment you made which seemed to make perfect sense but after investigating it has left me totally confused, which was:
Quoted 3 lines
I would also recommed adding a way to set the default baud rate through a property. Following the example of the 8250 driver, you should probably call that "current-speed".
I note that you are listed as the author of of_serial.c so I was assuming that looking at this would make sense, but it doesn't at all, and I would be really grateful if you could explain what you were trying to achieve and how you thought it worked. The code does:
/* If current-speed was set, then try not to change it. */
if (of_property_read_u32(np, "current-speed", &spd) == 0)
port->custom_divisor = clk / (16 * spd);The "spd" variable is not used again and I do not understand why you thought setting port->custom_divisor would have any impact on the default or current baud rate of the UART, or that this information was useful to any other part of the system. A search has only revealed that this port field has only one purpose, which is to provide a "custom" speed (unsurprisingly) when the user requests 38.4K _and_ the port flag UPF_SPD_CUST has been set through a TIOCSSERIAL ioctl call, instead of actually getting 38.4K. The key part of that assessment being the implementation of uart_get_divisor() :
if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
quot = port->custom_divisor;
else
quot = DIV_ROUND_CLOSEST(port->uartclk, 16 * baud);Also all of the custom_divisor functionality is basically commented as "old" or has a kernel warning saying it is deprecated (see uart_set_info), so as far as I can see for our (and I suspect most) hardware it is completely irrelevant functionality.
If you really wanted to specify a default rate for a TTY then surely you need to change the driver's init_termios, or change the termios on a per port basis after they get registered. Only a handful of drivers do not use the default uart_register_driver() and change the init_termios (statically) to something other than 9600 8N1. I have been unable so far to find any evidence of drivers changing the termios after a port has been registered based on either platform data or OF attributes. So I do not see why we would want to provide that functionality explicitly in the ASC driver if nobody else does; if you want to change the TTY speed, use the tty IOCTL interfaces (or stty).
So I don't see why you think the concept of a default or current speed belongs in the device tree description of the uart at all, unless there is something special about the hardware. One possible example of that seems to be the ARC driver which only appears to support one serial speed and uses "current-speed" attribute to specify that speed; or the ARC driver is broken and they have made a mistake in their set_termios implementation, we cannot quite work out which of those two things is true. But that isn't the case for the ASC hardware so it again would not be relevant in this driver.
So basically we would like some help understanding what it is you would really like us to do. Clearly we can just duplicate what you did in of_serial.c for the 8250 and move on, but we would like to understand why that wouldn't just be adding redundant code.
Regards,
-stephen
Arnd Bergmann
maintainerRe: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 32 lines · Stephen GALLIMORE
We have pretty much completed reworking the patch set we sent recently, but there is one comment you made which seemed to make perfect sense but after investigating it has left me totally confused, which was:
Quoted 3 lines
I would also recommed adding a way to set the default baud rate through a property. Following the example of the 8250 driver, you should probably call that "current-speed".
I note that you are listed as the author of
of_serial.cso I was assuming that looking at this would make sense, but it doesn't at all, and I would be really grateful if you could explain what you were trying to achieve and how you thought it worked. The code does:/* If current-speed was set, then try not to change it. */ if (of_property_read_u32(np, "current-speed", &spd) == 0) port->custom_divisor = clk / (16 * spd);The "spd" variable is not used again and I do not understand why you thought setting
port->custom_divisorwould have any impact on the default or current baud rate of the UART, or that this information was useful to any other part of the system. A search has only revealed that this port field has only one purpose, which is to provide a "custom" speed (unsurprisingly) when the user requests 38.4K and the port flagUPF_SPD_CUSThas been set through a TIOCSSERIAL ioctl call, instead of actually getting 38.4K. The key part of that assessment being the implementation ofuart_get_divisor():if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) quot = port->custom_divisor; else quot = DIV_ROUND_CLOSEST(port->uartclk, 16 * baud);
Quoted 4 lines
Also all of the
custom_divisorfunctionality is basically commented as "old" or has a kernel warning saying it is deprecated (seeuart_set_info), so as far as I can see for our (and I suspect most) hardware it is completely irrelevant functionality.
What may have happened here is that custom_divisor was used in a different way when I added that code than it is today, and the change was not propagated into the of_serial driver. However, going back to 2.6.20 shows no different code than what we have today in this regard. It may simply have been a mistake on my side.
Quoted 3 lines
So I don't see why you think the concept of a default or current speed belongs in the device tree description of the uart at all, unless there is something special about the hardware.
I looked it up in the original serial port binding at
http://www.openfirmware.org/1275/bindings/devices/html/serial.html, which does not specify the property, and in ePAPR, which does have it in the section about "serial class devices":
18 6.2.1.2 current-speed
19 Property: current-speed
20 Value type: <u32>
21 Description:
22 Specifies the current speed of a serial device in bits per second. A boot program should set 23 this property if it has initialized the serial device.
24 Example:
25 current - speed = <115200>; # 115200 baud
The reason you want this is so that the driver can initialize the hardware from scratch more easily and get back to the same settings. Why they only specified the baud rate but not also start/stop bits and flow control I don't understand though.
I guess you can ignore my original comment.
Arnd
RE: [RFC 1/8] serial:st-asc: Add ST ASC driver.
Quoted 10 lines · Arnd Bergmann
Quoted 4 lines
Also all of the
custom_divisorfunctionality is basically commented as "old" or has a kernel warning saying it is deprecated (seeuart_set_info), so as far as I can see for our (and I suspect most) hardware it is completely irrelevant functionality.What may have happened here is that
custom_divisorwas used in a different way when I added that code than it is today, and the change was not propagated into theof_serialdriver. However, going back to 2.6.20 shows no different code than what we have today in this regard. It may simply have been a mistake on my side.
Thanks for looking into this and digging around in the history. At least I didn't miss something really obvious.
Quoted 17 lines
I looked it up in the original serial port binding at
http://www.openfirmware.org/1275/bindings/devices/html/serial.ht
ml, which does
not specify the property, and in ePAPR, which does have it in the section about
"serial class devices":18 6.2.1.2 current-speed
19 Property: current-speed
20 Value type: <u32>
21 Description:
22 Specifies the current speed of a serial device in bits per second. A boot program should set
23 this property if it has initialized the serial device.
24 Example:
25 current - speed = <115200>; # 115200 baud
Quoted 4 lines
The reason you want this is so that the driver can initialize the hardware from scratch more easily and get back to the same settings. Why they only specified the baud rate but not also start/stop bits and flow control I don't understand though.
Yes, I had been made aware of the ePAPR definition by Srini after I sent the post. In fact I had exactly the same question in my head about the other settings as well.
Quoted 3 lines
I guess you can ignore my original comment.
OK.
Thanks again for your time.
Regards,
-stephen
RFC 4/8 pinctrl:stixxxx: Add pinctrl and pinconf support.
In reply to a message not in the archiveFrom: Srinivas Kandagatla <[email protected]>
This patch add pinctrl support to ST SoCs.
About hardware:
ST Set-Top-Box parts have two blocks called PIO and PIO-mux which handle pin configurations.
Each multi-function pin is controlled, driven and routed through the PIO multiplexing block. Each pin supports GPIO functionality (ALT0) and multiple alternate functions(ALT1 - ALTx) that directly connect the pin to different hardware blocks. When a pin is in GPIO mode, Output Enable (OE), Open Drain(OD), and Pull Up (PU) are driven by the related PIO block. Otherwise the PIO multiplexing block configures these parameters and retiming the signal.
About driver:
This pinctrl driver manages both PIO and PIO-mux block using pinctrl, pinconf, pinmux, gpio subsystems. All the pinctrl related config information can only come from device trees.
--- .../bindings/pinctrl/pinctrl-stixxxx.txt | 160 +++ drivers/pinctrl/Kconfig | 13 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-stixxxx.c | 1151 ++++++++++++++++++++ drivers/pinctrl/pinctrl-stixxxx.h | 197 ++++ 5 files changed, 1522 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt create mode 100644 drivers/pinctrl/pinctrl-stixxxx.c create mode 100644 drivers/pinctrl/pinctrl-stixxxx.h
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +160 -0
@@ -0,0 +1,160 @@ +*ST pin controller. + +Each multi-function pin is controlled, driven and routed through the +PIO multiplexing block. Each pin supports GPIO functionality (ALT0) +and multiple alternate functions(ALT1 - ALTx) that directly connect +the pin to different hardware blocks. + +When a pin is in GPIO mode, Output Enable (OE), Open Drain(OD), and +Pull Up (PU) are driven by the related PIO block. + +ST pinctrl driver controls PIO multiplexing block and also interacts with +gpio driver to configure a pin. + +Required properties: (PIO multiplexing block) +- compatible : should be "st,stixxxx-pinctrl" + each subnode should set "st,stixxxx-gpio" + as compatible for each gpio-controller bank. +- gpio-controller : Indicates this device is a GPIO controller +- #gpio-cells : Should be one. The first cell is the pin number. +- #retime-delay-cells : Should be number of possible retime delays. +- st,retime-in-delay : Should be array of delays in nsecs. +- st,retime-out-delay : Should be array of delays in nsecs. +- retime-style : Should indicate which type of retime is used. + possible values are "none", "packed" and "dedicated". +- st,retime-offset : phandle to retime offsets in retime registers. + These are not necessary for "dedicated" retime-style registers. + - clk1notclk0 : Should define offset for clk1not clk0 in retime register. + - delay-lsb : Should define offset for delay-lsb in retime register. + - delay-msb : Should define offset for delay msb in retime register. + - invertclk : Should define offset for invertclk in retime register. + - retime : Should define offset for retime in retime register. + - clknotdata : Should define offset for clknotdata in retime register. + - double_edge : Should define offset for double edge in retime register. +- st,alt-control : Should be sysconf to control alternate function on pio. +- st,oe-control : Should be sysconf to control output enable on pio. +- st,pu-control : Should be sysconf to control pull up on pio. +- st,od-control : Should be sysconf to control open drain on pio. +- st,retime-style : Should indicate which type of retime is used. + possible values are "none", "packed" and "dedicated". +- st,retime-pin-mask : Should be mask to specify which pins can be retimed. +- retime-control[0...N]: These properties point to sysconfs which control retime. + Depending on retime-style the number of retime-controls + vary: 2 for "packed"; 8 for "dedicated". +- st,bank-name : Should be a name string for this bank. + +Example: + pio_retime_offset: pio-retime-offset { + clk1notclk0 = <0>; + delay-lsb = <2>; + delay-msb = <3>; + invertclk = <4>; + retime = <5>; + clknotdata = <6>; + double-edge = <7>; + }; + + pin-controller { + #retime-delay-cells = <4>; + compatible = "st,stixxxx-pinctrl", "simple-bus"; + st,retime-offset = <&pio_retime_offset>; + st,retime-in-delay = <0 500 1000 1500>; + st,retime-out-delay = <0 1000 2000 3000>; + ranges; + PIO0: pinctrl@fe610000 { + gpio-controller; + #gpio-cells = <1>; + compatible = "st,stixxxx-gpio"; + reg = <0xfe610000 0x100>; + st,bank-name = "PIO0"; + st,alt-control = <&SYSCONF_SBC(0) 0 31>; + st,oe-control = <&SYSCONF_SBC(5) 0 7>; + st,pu-control = <&SYSCONF_SBC(7) 0 7>; + st,od-control = <&SYSCONF_SBC(9) 0 7>; + st,retime-style = "packed"; + st,retime-pin-mask = <0xff>; + st,retime-control0 = <&SYSCONF_SBC(16) 0 31>; + st,retime-control1 = <&SYSCONF_SBC(17) 0 31>; + }; + ... + pin-functions nodes follow... + }; + + +Contents of function subnode node: +---------------------- +Required properties for pin configuration node: +- st,function : Should be alternate function number associated + with this set of pins. + possible altfunction values: + ALT1 + ALT2 + ALT3 + ALT4 + ALT5 + ALT6 + ALT7 + +- st,pins : Child node with list of pins with configuration. + +Below is the format of how each pin conf should look like. + +<bank offset mode rt_type rt_delay rt_clk> + +Every PIO is represented with 4-7 parameters depending on retime configuration. +Each parameter is explained as below. + +-bank : Should be bank phandle to which this PIO belongs. +-offset : Offset in the PIO bank. +-mode :pin configuration is selected from one of the below values. + IN + IN_PU + OUT + BIDIR + BIDIR_PU + +-rt_type Retiming Configuration for the pin. + Possible retime configuration are: + + ------- ------------- + value args + ------- ------------- + NICLK <delay> <clk> + ICLK_IO <delay> <clk> + BYPASS <delay> + DE_IO <delay> <clk> + SE_ICLK_IO <delay> <clk> + SE_NICLK_IO <delay> <clk> + +- delay is retime delay in pico seconds. + Possible values are: refer to retime-in/out-delays + +- rt_clk :clk to be use for retime. + Possible values are: + CLK_A + CLK_B + CLK_C + CLK_D + +Example of mmcclk pin which is a bi-direction pull pu with retime config +as non inverted clock retimed with CLK_B and delay of 0 pico seconds: + +pin-controller { + ... + mmc0 { + pinctrl_mmc: mmc { + st,function = <ALT4>; + st,pins { + mmcclk = <&PIO13 4 BIDIR_PU NICLK 0 CLK_B>; + ... + }; + }; + ... + }; +}; + +sdhci0:sdhci@fe810000{ + ... + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_mmc>; +};
drivers/pinctrl/Kconfig +13 -0
@@ -179,6 +179,19 @@ config PINCTRL_SUNXI select PINMUX select GENERIC_PINCONF +config PINCTRL_STIXXXX + bool "ST Microelectronics pin controller driver for STixxxx SoCs" + depends on PLAT_STIXXXX + select PINMUX + select PINCONF + select MFD_SYSCON + help + Say yes here to support pinctrl interface on STixxxx SOCs. + This driver is used to control both PIO block and PIO-mux + block to configure a pin. + + If unsure, say N. + config PINCTRL_TEGRA bool select PINMUX
drivers/pinctrl/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_PINCTRL_EXYNOS) += pinctrl-exynos.o obj-$(CONFIG_PINCTRL_EXYNOS5440) += pinctrl-exynos5440.o obj-$(CONFIG_PINCTRL_XWAY) += pinctrl-xway.o obj-$(CONFIG_PINCTRL_LANTIQ) += pinctrl-lantiq.o +obj-$(CONFIG_PINCTRL_STIXXXX) += pinctrl-stixxxx.o obj-$(CONFIG_PLAT_ORION) += mvebu/ obj-$(CONFIG_ARCH_SHMOBILE) += sh-pfc/
drivers/pinctrl/pinctrl-stixxxx.c new file +1151 -0
1,151 lines not on this page · raw message
drivers/pinctrl/pinctrl-stixxxx.h new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
1.7.6.5
Re: [RFC 4/8] pinctrl:stixxxx: Add pinctrl and pinconf support.
Quoted 8 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
This patch add pinctrl support to ST SoCs.
About hardware:
ST Set-Top-Box parts have two blocks called PIO and PIO-mux which handle pin configurations.
Quoted 8 lines
Each multi-function pin is controlled, driven and routed through the PIO multiplexing block. Each pin supports GPIO functionality (ALT0) and multiple alternate functions(ALT1 - ALTx) that directly connect the pin to different hardware blocks. When a pin is in GPIO mode, Output Enable (OE), Open Drain(OD), and Pull Up (PU) are driven by the related PIO block. Otherwise the PIO multiplexing block configures these parameters and retiming the signal.
g> About driver:
Quoted 7 lines
This pinctrl driver manages both PIO and PIO-mux block using pinctrl, pinconf, pinmux, gpio subsystems. All the pinctrl related config information can only come from device trees.
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stephen Gallimore <[email protected]>CC Stuart Menefy <[email protected]>
Quoted 6 lines
--- .../bindings/pinctrl/pinctrl-stixxxx.txt | 160 +++ drivers/pinctrl/Kconfig | 13 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-stixxxx.c | 1151 ++++++++++++++++++++ drivers/pinctrl/pinctrl-stixxxx.h | 197 ++++
the pinctrl is present in older SoC ST40 not only stixxx
and you must provide a proper name not stixxxx
Quoted 11 lines
5 files changed, 1522 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt create mode 100644 drivers/pinctrl/pinctrl-stixxxx.c create mode 100644 drivers/pinctrl/pinctrl-stixxxx.hDocumentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +0
-0
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 9
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +9
-0@@ -0,0 +1,160 @@ +*ST pin controller. + +Each multi-function pin is controlled, driven and routed through the +PIO multiplexing block. Each pin supports GPIO functionality (ALT0) +and multiple alternate functions(ALT1 - ALTx) that directly connect +the pin to different hardware blocks. + +When a pin is in GPIO mode, Output Enable (OE), Open Drain(OD), and +Pull Up (PU) are driven by the related PIO block.
HighZ too
this driver look very similar with AT91 we should consolidate at binding and C level
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 17
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +8
-1--- + +ST pinctrl driver controls PIO multiplexing block and also interacts with +gpio driver to configure a pin. + +Required properties: (PIO multiplexing block) +- compatible : should be "st,stixxxx-pinctrl" + each subnode should set "st,stixxxx-gpio" + as compatible for each gpio-controller bank.
first soc where the IP is present
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt
Quoted 7 lines
+- gpio-controller : Indicates this device is a GPIO controller +- #gpio-cells : Should be one. The first cell is the pin number. +- #retime-delay-cells : Should be number of possible retime delays. +- st,retime-in-delay : Should be array of delays in nsecs. +- st,retime-out-delay : Should be array of delays in nsecs. +- retime-style : Should indicate which type of retime is used.Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +1
-0+ possible values are "none", "packed" and "dedicated".
always prefix st, when specific property
st,
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 33
Quoted 9 lines
+- st,retime-offset : phandle to retime offsets in retime registers.
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +8
-0+ These are not necessary for "dedicated" retime-style registers. + - clk1notclk0 : Should define offset for clk1not clk0 in retime register. + - delay-lsb : Should define offset for delay-lsb in retime register. + - delay-msb : Should define offset for delay msb in retime register. + - invertclk : Should define offset for invertclk in retime register. + - retime : Should define offset for retime in retime register. + - clknotdata : Should define offset for clknotdata in retime register. + - double_edge : Should define offset for double edge in retime register.
As much as I like to describe the IP in the DT, I think it's too much this time move this to C and use the compatible or detect it on the hardware to handle this
Quoted 55 lines
+- st,alt-control : Should be sysconf to control alternate function on pio. +- st,oe-control : Should be sysconf to control output enable on pio. +- st,pu-control : Should be sysconf to control pull up on pio. +- st,od-control : Should be sysconf to control open drain on pio. +- st,retime-style : Should indicate which type of retime is used.Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +48
-0+ possible values are "none", "packed" and "dedicated". +- st,retime-pin-mask : Should be mask to specify which pins can be retimed. +- retime-control[0...N]: These properties point to sysconfs which control retime. + Depending on retime-style the number of retime-controls + vary: 2 for "packed"; 8 for "dedicated". +- st,bank-name : Should be a name string for this bank. + +Example: + pio_retime_offset: pio-retime-offset { + clk1notclk0 = <0>; + delay-lsb = <2>; + delay-msb = <3>; + invertclk = <4>; + retime = <5>; + clknotdata = <6>; + double-edge = <7>; + }; + + pin-controller { + #retime-delay-cells = <4>; + compatible = "st,stixxxx-pinctrl", "simple-bus"; + st,retime-offset = <&pio_retime_offset>; + st,retime-in-delay = <0 500 1000 1500>; + st,retime-out-delay = <0 1000 2000 3000>; + ranges; + PIO0: pinctrl at fe610000 { + gpio-controller; + #gpio-cells = <1>; + compatible = "st,stixxxx-gpio"; + reg = <0xfe610000 0x100>; + st,bank-name = "PIO0"; + st,alt-control = <&SYSCONF_SBC(0) 0 31>; + st,oe-control = <&SYSCONF_SBC(5) 0 7>; + st,pu-control = <&SYSCONF_SBC(7) 0 7>; + st,od-control = <&SYSCONF_SBC(9) 0 7>; + st,retime-style = "packed"; + st,retime-pin-mask = <0xff>; + st,retime-control0 = <&SYSCONF_SBC(16) 0 31>; + st,retime-control1 = <&SYSCONF_SBC(17) 0 31>; + }; + ... + pin-functions nodes follow... + }; + + +Contents of function subnode node: +---------------------- +Required properties for pin configuration node:
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 96
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +10
-0+- st,function : Should be alternate function number associated + with this set of pins. + possible altfunction values: + ALT1 + ALT2 + ALT3 + ALT4 + ALT5 + ALT6 + ALT7
use number in the DoC
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +8
-0+ +- st,pins : Child node with list of pins with configuration. + +Below is the format of how each pin conf should look like. + +<bank offset mode rt_type rt_delay rt_clk> + +Every PIO is represented with 4-7 parameters depending on retime configuration.
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 114
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +10
-0+Each parameter is explained as below. + +-bank : Should be bank phandle to which this PIO belongs. +-offset : Offset in the PIO bank. +-mode :pin configuration is selected from one of the below values. + IN + IN_PU + OUT + BIDIR + BIDIR_PU
ditto
Quoted 1,449 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +46
-0+ +-rt_type Retiming Configuration for the pin. + Possible retime configuration are: + + ------- ------------- + value args + ------- ------------- + NICLK <delay> <clk> + ICLK_IO <delay> <clk> + BYPASS <delay> + DE_IO <delay> <clk> + SE_ICLK_IO <delay> <clk> + SE_NICLK_IO <delay> <clk> + +- delay is retime delay in pico seconds. + Possible values are: refer to retime-in/out-delays + +- rt_clk :clk to be use for retime. + Possible values are: + CLK_A + CLK_B + CLK_C + CLK_D + +Example of mmcclk pin which is a bi-direction pull pu with retime config +as non inverted clock retimed with CLK_B and delay of 0 pico seconds: + +pin-controller { + ... + mmc0 { + pinctrl_mmc: mmc { + st,function = <ALT4>; + st,pins { + mmcclk = <&PIO13 4 BIDIR_PU NICLK 0 CLK_B>; + ... + }; + }; + ... + }; +}; + +sdhci0:sdhci at fe810000{ + ... + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_mmc>; +};drivers/pinctrl/Kconfig +13
-0@@ -179,6 +179,19 @@ config PINCTRL_SUNXI select PINMUX select GENERIC_PINCONF +config PINCTRL_STIXXXX + bool "ST Microelectronics pin controller driver for STixxxx SoCs" + depends on PLAT_STIXXXX + select PINMUX + select PINCONF + select MFD_SYSCON + help + Say yes here to support pinctrl interface on STixxxx SOCs. + This driver is used to control both PIO block and PIO-mux + block to configure a pin. + + If unsure, say N. + config PINCTRL_TEGRA bool select PINMUXdrivers/pinctrl/Makefile +1
-0@@ -47,6 +47,7 @@ obj-$(CONFIG_PINCTRL_EXYNOS) += pinctrl-exynos.o obj-$(CONFIG_PINCTRL_EXYNOS5440) += pinctrl-exynos5440.o obj-$(CONFIG_PINCTRL_XWAY) += pinctrl-xway.o obj-$(CONFIG_PINCTRL_LANTIQ) += pinctrl-lantiq.o +obj-$(CONFIG_PINCTRL_STIXXXX) += pinctrl-stixxxx.o obj-$(CONFIG_PLAT_ORION) += mvebu/ obj-$(CONFIG_ARCH_SHMOBILE) += sh-pfc/drivers/pinctrl/pinctrl-stixxxx.c new file +1151
-0@@ -0,0 +1,1151 @@ +/* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Authors: +* Srinivas Kandagatla <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#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/mfd/syscon.h> +#include <linux/pinctrl/pinctrl.h> +#include <linux/pinctrl/pinmux.h> +#include <linux/pinctrl/pinconf.h> +#include <linux/platform_device.h> +#include "core.h" +#include "pinctrl-stixxxx.h" + +struct stixxxx_pinconf { +int pin; +const char *name; +unsigned long config; +}; + +struct stixxxx_pmx_func { +const char *name; +const char **groups; +unsigned ngroups; +}; + +struct stixxxx_pctl_group { +const char *name; +unsigned int *pins; +unsigned npins; +int altfunc; +struct stixxxx_pinconf *pin_conf; +}; + +#define to_stixxxx_gpio_port (chip) \ + container_of(chip, struct stixxxx_gpio_port, gpio_chip) + +struct stixxxx_gpio_port { +struct gpio_chip gpio_chip; +struct pinctrl_gpio_range range; +void __iomem *base; +struct device_node *of_node; +const char *bank_name; +}; + +static struct stixxxx_gpio_port *gpio_ports[STIXXXX_MAX_GPIO_BANKS ]; + +struct stixxxx_pinctrl { +struct device *dev; +struct pinctrl_dev *pctl; +int nbanks; +struct stixxxx_pmx_func *functions; +int nfunctions; +struct stixxxx_pctl_group *groups; +int ngroups; +struct stixxxx_pio_control *pio_controls; +}; + +/* Low level functions.. */ +static void stixxxx_pinconf_set_direction (struct stixxxx_pio_control *pc, +int pin_id,unsigned long config) +{ +struct syscon_field *output_enable; +struct syscon_field *pull_up; +struct syscon_field *open_drain; +unsigned long oe_value, pu_value, od_value; +unsigned long mask; +int pin =stixxxx_gpio_pin (pin_id); + + output_enable = pc->oe; + pull_up = pc->pu; + open_drain = pc->od; + + mask =BIT (pin); + + oe_value =syscon_read (output_enable); + pu_value =syscon_read (pull_up); + od_value =syscon_read (open_drain); + +/* Clear old values */ + oe_value &= ~mask; + pu_value &= ~mask; + od_value &= ~mask; + +if (config &STIXXXX_PINCONF_OE ) + oe_value |= mask; +if (config &STIXXXX_PINCONF_PU ) + pu_value |= mask; +if (config &STIXXXX_PINCONF_OD ) + od_value |= mask; + +syscon_write (output_enable, oe_value); +syscon_write (pull_up, pu_value); +syscon_write (open_drain, od_value); +} + +static void stixxxx_pctl_set_function (struct stixxxx_pio_control *pc, +int pin_id,int function) +{ +struct syscon_field *selector; +int offset; +unsigned long val; +int pin =stixxxx_gpio_pin (pin_id); + + selector = pc->alt; + offset = pin *4 ; + val =syscon_read (selector); + val &= ~(0xf << offset); + val |= function << offset; +syscon_write (selector, val); +} + +static unsigned long stixxxx_pinconf_delay_to_bit (unsigned int delay, +const struct stixxxx_retime_params *rt_params, +unsigned long config) +{ +unsigned int *delay_times; +int num_delay_times, i, closest_index =-1 ; +unsigned int closest_divergence =UINT_MAX ; + +if (STIXXXX_PINCONF_UNPACK_OE (config)) { + delay_times = rt_params->delay_times_out; + num_delay_times = rt_params->num_delay_times_out; + }else { + delay_times = rt_params->delay_times_in; + num_delay_times = rt_params->num_delay_times_in; + } + +for (i =0 ; i < num_delay_times; i++) { +unsigned int divergence =abs (delay - delay_times[i]); + +if (divergence ==0 ) +return i; + +if (divergence < closest_divergence) { + closest_divergence = divergence; + closest_index = i; + } + } + +pr_warn ("Attempt to set delay %d, closest available %d\n" , + delay, delay_times[closest_index]); + +return closest_index; +} + +static unsigned long stixxxx_pinconf_bit_to_delay (unsigned int index, +const struct stixxxx_retime_params *rt_params, +unsigned long output) +{ +unsigned int *delay_times; +int num_delay_times; + +if (output) { + delay_times = rt_params->delay_times_out; + num_delay_times = rt_params->num_delay_times_out; + }else { + delay_times = rt_params->delay_times_in; + num_delay_times = rt_params->num_delay_times_in; + } + +if (index < num_delay_times) { +return delay_times[index]; + }else { +pr_warn ("Delay not found in/out delay list\n" ); +return 0 ; + } +} + +static void stixxxx_pinconf_set_retime_packed ( +struct stixxxx_pio_control *pc, +unsigned long config,int pin) +{ +const struct stixxxx_retime_params *rt_params = pc->rt_params; +const struct stixxxx_retime_offset *offset = rt_params->retime_offset; +struct syscon_field **regs; +unsigned long values[2 ]; +unsigned long mask; +int i, j; +int clk =STIXXXX_PINCONF_UNPACK_RT_CLK (config); +int clknotdata =STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config); +int double_edge =STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config); +int invertclk =STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config); +int retime =STIXXXX_PINCONF_UNPACK_RT (config); +unsigned long delay =stixxxx_pinconf_delay_to_bit ( +STIXXXX_PINCONF_UNPACK_RT_DELAY (config), + pc->rt_params, config); + +unsigned long rt_cfg = + ((clk &1 ) << offset->clk1notclk0_offset) | + ((clknotdata &1 ) << offset->clknotdata_offset) | + ((delay &1 ) << offset->delay_lsb_offset) | + (((delay >>1 ) &1 ) << offset->delay_msb_offset) | + ((double_edge &1 ) << offset->double_edge_offset) | + ((invertclk &1 ) << offset->invertclk_offset) | + ((retime &1 ) << offset->retime_offset); + + regs = pc->retiming; + values[0 ] =syscon_read (regs[0 ]); + values[1 ] =syscon_read (regs[1 ]); + +for (i =0 ; i <2 ; i++) { + mask =BIT (pin); +for (j =0 ; j <4 ; j++) { +if (rt_cfg &1 ) + values[i] |= mask; +else + values[i] &= ~mask; + mask <<=8 ; + rt_cfg >>=1 ; + } + } + +syscon_write (regs[0 ], values[0 ]); +syscon_write (regs[1 ], values[1 ]); +} + +static void stixxxx_pinconf_set_retime_dedicated ( +struct stixxxx_pio_control *pc, +unsigned long config,int pin) +{ +struct syscon_field *reg; +int input =STIXXXX_PINCONF_UNPACK_OE (config) ?0 :1 ; +int clk =STIXXXX_PINCONF_UNPACK_RT_CLK (config); +int clknotdata =STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config); +int double_edge =STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config); +int invertclk =STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config); +int retime =STIXXXX_PINCONF_UNPACK_RT (config); +unsigned long delay =stixxxx_pinconf_delay_to_bit ( +STIXXXX_PINCONF_UNPACK_RT_DELAY (config), + pc->rt_params, config); + +unsigned long retime_config = + ((clk &0x3 ) <<0 ) | + ((clknotdata &0x1 ) <<2 ) | + ((delay &0xf ) <<3 ) | + ((input &0x1 ) <<7 ) | + ((double_edge &0x1 ) <<8 ) | + ((invertclk &0x1 ) <<9 ) | + ((retime &0x1 ) <<10 ); + + reg = pc->retiming[pin]; +syscon_write (reg, retime_config); +} + +static void stixxxx_pinconf_get_direction (struct stixxxx_pio_control *pc, +int pin_id,unsigned long *config) +{ +unsigned long oe_value, pu_value, od_value; +int pin =stixxxx_gpio_pin (pin_id); + + oe_value = (syscon_read (pc->oe) >> pin) &1 ; + pu_value = (syscon_read (pc->pu) >> pin) &1 ; + od_value = (syscon_read (pc->od) >> pin) &1 ; + +STIXXXX_PINCONF_PACK_OE (*config, oe_value); +STIXXXX_PINCONF_PACK_PU (*config, pu_value); +STIXXXX_PINCONF_PACK_OD (*config, od_value); +} + +static int stixxxx_pinconf_get_retime_packed ( +struct stixxxx_pio_control *pc, +int pin,unsigned long *config) +{ +const struct stixxxx_retime_params *rt_params = pc->rt_params; +const struct stixxxx_retime_offset *offset = rt_params->retime_offset; +unsigned long delay_bits, delay, rt_reduced; +unsigned long rt_value[2 ]; +int i, j; +int output =STIXXXX_PINCONF_UNPACK_OE (*config); + + rt_value[0 ] =syscon_read (pc->retiming[0 ]); + rt_value[1 ] =syscon_read (pc->retiming[1 ]); + + rt_reduced =0 ; +for (i =0 ; i <2 ; i++) { +for (j =0 ; j <4 ; j++) { +if (rt_value[i] & (1 <<((8 *j)+pin))) + rt_reduced |=1 << ((i*4 )+j); + } + } + +STIXXXX_PINCONF_PACK_RT (*config, + (rt_reduced >> offset->retime_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_CLK (*config, + (rt_reduced >> offset->clk1notclk0_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (*config, + (rt_reduced >> offset->clknotdata_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (*config, + (rt_reduced >> offset->double_edge_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_INVERTCLK (*config, + (rt_reduced >> offset->invertclk_offset) &1 ); + + delay_bits = (((rt_reduced >> offset->delay_msb_offset) &1 )<<1 ) | + ((rt_reduced >> offset->delay_lsb_offset) &1 ); + delay =stixxxx_pinconf_bit_to_delay (delay_bits, rt_params, output); +STIXXXX_PINCONF_PACK_RT_DELAY (*config, delay); +return 0 ; +} + +static int stixxxx_pinconf_get_retime_dedicated ( +struct stixxxx_pio_control *pc, +int pin,unsigned long *config) +{ +unsigned long value; +unsigned long delay_bits, delay; +const struct stixxxx_retime_params *rt_params = pc->rt_params; +int output =STIXXXX_PINCONF_UNPACK_OE (*config); + + value =syscon_read (pc->retiming[pin]); +STIXXXX_PINCONF_PACK_RT_CLK (*config, ((value >>0 ) &0x3 )); +STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (*config, ((value >>2 ) &0x1 )); + delay_bits = ((value >>3 ) &0xf ); + delay =stixxxx_pinconf_bit_to_delay (delay_bits, rt_params, output); +STIXXXX_PINCONF_PACK_RT_DELAY (*config, delay); +STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (*config, ((value >>8 ) &0x1 )); +STIXXXX_PINCONF_PACK_RT_INVERTCLK (*config, ((value >>9 ) &0x1 )); +STIXXXX_PINCONF_PACK_RT (*config, ((value >>10 ) &0x1 )); + +return 0 ; +} + +/* GPIO related functions */ + +static inline void __stixxxx_gpio_set (struct stixxxx_gpio_port *port, +unsigned offset,int value) +{ +if (value) +writel (BIT (offset), port->base +REG_PIO_SET_POUT ); +else +writel (BIT (offset), port->base +REG_PIO_CLR_POUT ); +} + +static void stixxxx_gpio_direction (unsigned int gpio,unsigned int direction) +{ +int port_num =stixxxx_gpio_port (gpio); +int offset =stixxxx_gpio_pin (gpio); +struct stixxxx_gpio_port *port = gpio_ports[port_num]; +int i =0 ; + +for (i =0 ; i <=2 ; i++) { +if (direction &BIT (i)) +writel (BIT (offset), port->base +REG_PIO_SET_PC (i)); +else +writel (BIT (offset), port->base +REG_PIO_CLR_PC (i)); + } +} + +static int stixxxx_gpio_request (struct gpio_chip *chip,unsigned offset) +{ +return pinctrl_request_gpio (chip->base + offset); +} + +static void stixxxx_gpio_free (struct gpio_chip *chip,unsigned offset) +{ +pinctrl_free_gpio (chip->base + offset); +} + +static int stixxxx_gpio_get (struct gpio_chip *chip,unsigned offset) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); + +return (readl (port->base +REG_PIO_PIN ) >> offset) &1 ; +} + +static void stixxxx_gpio_set (struct gpio_chip *chip,unsigned offset,int value) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); +__stixxxx_gpio_set (port, offset, value); +} + +static int stixxxx_gpio_direction_input (struct gpio_chip *chip,unsigned offset) +{ +pinctrl_gpio_direction_input (chip->base + offset); +return 0 ; +} + +static int stixxxx_gpio_direction_output (struct gpio_chip *chip, +unsigned offset,int value) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); + +__stixxxx_gpio_set (port, offset, value); +pinctrl_gpio_direction_output (chip->base + offset); + +return 0 ; +} + +static int stixxxx_gpio_xlate (struct gpio_chip *gc, +const struct of_phandle_args *gpiospec,u32 *flags) +{ +if (WARN_ON (gc->of_gpio_n_cells <1 )) +return -EINVAL ; + +if (WARN_ON (gpiospec->args_count < gc->of_gpio_n_cells)) +return -EINVAL ; + +if (gpiospec->args[0 ] > gc->ngpio) +return -EINVAL ; + +return gpiospec->args[0 ]; +} + +/* Pinctrl Groups */ +static int stixxxx_pctl_get_groups_count (struct pinctrl_dev *pctldev) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->ngroups; +} + +static const char *stixxxx_pctl_get_group_name (struct pinctrl_dev *pctldev, +unsigned selector) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->groups[selector].name; +} + +static int stixxxx_pctl_get_group_pins (struct pinctrl_dev *pctldev, +unsigned selector,const unsigned **pins,unsigned *npins) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +if (selector >= info->ngroups) +return -EINVAL ; + + *pins = info->groups[selector].pins; + *npins = info->groups[selector].npins; + +return 0 ; +} + +static const inline struct stixxxx_pctl_group *stixxxx_pctl_find_group_by_name ( +const struct stixxxx_pinctrl *info,const char *name) +{ +int i; + +for (i =0 ; i < info->ngroups; i++) { +if (!strcmp (info->groups[i].name, name)) +return &info->groups[i]; + } + +return NULL ; +} + +static int stixxxx_pctl_dt_node_to_map (struct pinctrl_dev *pctldev, +struct device_node *np,struct pinctrl_map **map,unsigned *num_maps) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +const struct stixxxx_pctl_group *grp; +struct pinctrl_map *new_map; +struct device_node *parent; +int map_num, i; + + grp =stixxxx_pctl_find_group_by_name (info, np->name); +if (!grp) { +dev_err (info->dev,"unable to find group for node %s\n" , + np->name); +return -EINVAL ; + } + + map_num = grp->npins +1 ; + new_map =devm_kzalloc (pctldev->dev, +sizeof (*new_map) * map_num,GFP_KERNEL ); +if (!new_map) +return -ENOMEM ; + + parent =of_get_parent (np); +if (!parent) { +devm_kfree (pctldev->dev, new_map); +return -EINVAL ; + } + + *map = new_map; + *num_maps = map_num; + new_map[0 ].type =PIN_MAP_TYPE_MUX_GROUP ; + new_map[0 ].data.mux.function = parent->name; + new_map[0 ].data.mux.group = np->name; +of_node_put (parent); + +/* create config map per pin */ + new_map++; +for (i =0 ; i < grp->npins; i++) { + new_map[i].type =PIN_MAP_TYPE_CONFIGS_PIN ; + new_map[i].data.configs.group_or_pin = +pin_get_name (pctldev, grp->pins[i]); + new_map[i].data.configs.configs = &grp->pin_conf[i].config; + new_map[i].data.configs.num_configs =1 ; + } +dev_info (pctldev->dev,"maps: function %s group %s num %d\n" , + (*map)->data.mux.function, grp->name, map_num); + +return 0 ; +} + +static void stixxxx_pctl_dt_free_map (struct pinctrl_dev *pctldev, +struct pinctrl_map *map,unsigned num_maps) +{ +} + +static struct pinctrl_ops stixxxx_pctlops = { + .get_groups_count = stixxxx_pctl_get_groups_count, + .get_group_pins = stixxxx_pctl_get_group_pins, + .get_group_name = stixxxx_pctl_get_group_name, + .dt_node_to_map = stixxxx_pctl_dt_node_to_map, + .dt_free_map = stixxxx_pctl_dt_free_map, +}; + +/* Pinmux */ +static int stixxxx_pmx_get_funcs_count (struct pinctrl_dev *pctldev) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->nfunctions; +} + +const char *stixxxx_pmx_get_fname (struct pinctrl_dev *pctldev, +unsigned selector) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->functions[selector].name; +} + +static int stixxxx_pmx_get_groups (struct pinctrl_dev *pctldev, +unsigned selector,const char *const **grps,unsigned *const ngrps) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + *grps = info->functions[selector].groups; + *ngrps = info->functions[selector].ngroups; + +return 0 ; +} + +static struct stixxxx_pio_control *stixxxx_get_pio_control ( +struct stixxxx_pinctrl *info,int pin_id) +{ +int port =stixxxx_gpio_port (pin_id); +return &info->pio_controls[port]; +} + +static int stixxxx_pmx_enable (struct pinctrl_dev *pctldev,unsigned fselector, +unsigned group) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pinconf *conf = info->groups[group].pin_conf; +struct stixxxx_pio_control *pc; +int i; + +for (i =0 ; i < info->groups[group].npins; i++) { + pc =stixxxx_get_pio_control (info, conf[i].pin); +stixxxx_pctl_set_function (pc, conf[i].pin, + info->groups[group].altfunc); + } + +return 0 ; +} + +static void stixxxx_pmx_disable (struct pinctrl_dev *pctldev,unsigned selector, +unsigned group) +{ +} + +static int stixxxx_pmx_set_gpio_direction (struct pinctrl_dev *pctldev, +struct pinctrl_gpio_range *range,unsigned gpio, +bool input) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc = &info->pio_controls[range->id]; +/* +* When a PIO port is used in its primary function mode (altfunc = 0) +* Output Enable (OE), Open Drain(OD), and Pull Up (PU) +* for the primary PIO functions are driven by the related PIO block +*/ +stixxxx_pctl_set_function (pc, gpio,0 ); +stixxxx_gpio_direction (gpio, input ? +STIXXXX_GPIO_DIRECTION_IN :STIXXXX_GPIO_DIRECTION_OUT ); + +return 0 ; +} + +static struct pinmux_ops stixxxx_pmxops = { + .get_functions_count = stixxxx_pmx_get_funcs_count, + .get_function_name = stixxxx_pmx_get_fname, + .get_function_groups = stixxxx_pmx_get_groups, + .enable = stixxxx_pmx_enable, + .disable = stixxxx_pmx_disable, + .gpio_set_direction = stixxxx_pmx_set_gpio_direction, +}; + +/* Pinconf */ +static void stixxxx_pinconf_get_retime (struct stixxxx_pio_control *pc, +int pin_id,unsigned long *config) +{ +int pin =stixxxx_gpio_pin (pin_id); +if (pc->rt_style == stixxxx_retime_style_packed) +stixxxx_pinconf_get_retime_packed (pc, pin, config); +else if (pc->rt_style == stixxxx_retime_style_dedicated) +if ((BIT (pin) & pc->rt_pin_mask)) +stixxxx_pinconf_get_retime_dedicated (pc, pin, config); +} + +static void stixxxx_pinconf_set_retime (struct stixxxx_pio_control *pc, +int pin_id,unsigned long config) +{ +int pin =stixxxx_gpio_pin (pin_id); + +if (pc->rt_style == stixxxx_retime_style_packed) +stixxxx_pinconf_set_retime_packed (pc, config, pin); +else if (pc->rt_style == stixxxx_retime_style_dedicated) +if ((BIT (pin) & pc->rt_pin_mask)) +stixxxx_pinconf_set_retime_dedicated (pc, config, pin); +} + +static int stixxxx_pinconf_set (struct pinctrl_dev *pctldev, +unsigned pin_id,unsigned long config) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc =stixxxx_get_pio_control (info, pin_id); + +stixxxx_pinconf_set_direction (pc, pin_id, config); +stixxxx_pinconf_set_retime (pc, pin_id, config); +return 0 ; +} + +static int stixxxx_pinconf_get (struct pinctrl_dev *pctldev, +unsigned pin_id,unsigned long *config) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc =stixxxx_get_pio_control (info, pin_id); + + *config =0 ; +stixxxx_pinconf_get_direction (pc, pin_id, config); +stixxxx_pinconf_get_retime (pc, pin_id, config); + +return 0 ; +} + +static void stixxxx_pinconf_dbg_show (struct pinctrl_dev *pctldev, +struct seq_file *s,unsigned pin_id) +{ +unsigned long config; +stixxxx_pinconf_get (pctldev, pin_id, &config); + +seq_printf (s,"[OE:%ld,PU:%ld,OD:%ld]\n" +"\t\t[retime:%ld,invclk:%ld,clknotdat:%ld," +"de:%ld,rt-clk:%ld,rt-delay:%ld]" , +STIXXXX_PINCONF_UNPACK_OE (config), +STIXXXX_PINCONF_UNPACK_PU (config), +STIXXXX_PINCONF_UNPACK_OD (config), +STIXXXX_PINCONF_UNPACK_RT (config), +STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config), +STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config), +STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config), +STIXXXX_PINCONF_UNPACK_RT_CLK (config), +STIXXXX_PINCONF_UNPACK_RT_DELAY (config)); +} + +static struct pinconf_ops stixxxx_confops = { + .pin_config_get = stixxxx_pinconf_get, + .pin_config_set = stixxxx_pinconf_set, + .pin_config_dbg_show = stixxxx_pinconf_dbg_show, +}; + +/* pinctrl */ +static struct pinctrl_desc stixxxx_pctl_desc = { + .owner =THIS_MODULE , + .pctlops = &stixxxx_pctlops, + .pmxops = &stixxxx_pmxops, + .confops = &stixxxx_confops, +}; + +static int stixxxx_pinconf_dt_parse_rt_params (struct stixxxx_pinctrl *info, +struct device_node *np,struct stixxxx_retime_params *params) +{ +const __be32 *ip; +struct device_node *offset_np; +struct stixxxx_retime_offset *rt_offset; +int delay_count =0 ; + + ip =of_get_property (np,"#retime-delay-cells" ,NULL ); +if (ip) + delay_count =be32_to_cpup (ip); +else +pr_warn ("No #retime-delay-cells specified\n" ); + + params->num_delay_times_out = delay_count; + params->num_delay_times_in = delay_count; + params->delay_times_in =devm_kzalloc (info->dev, +sizeof (u32) * delay_count,GFP_KERNEL ); + params->delay_times_out =devm_kzalloc (info->dev, +sizeof (u32) * delay_count,GFP_KERNEL ); + +if (!params->delay_times_in || !params->delay_times_out) +return -ENOMEM ; + +of_property_read_u32_array (np,"st,retime-in-delay" , + (u32 *)params->delay_times_in, delay_count); +of_property_read_u32_array (np,"st,retime-out-delay" , + (u32 *)params->delay_times_out, delay_count); + + offset_np =of_parse_phandle (np,"st,retime-offset" ,0 ); + +if (offset_np) { + rt_offset =devm_kzalloc (info->dev, +sizeof (*rt_offset),GFP_KERNEL ); +if (!rt_offset) +return -ENOMEM ; + + params->retime_offset = rt_offset; +WARN_ON (of_property_read_u32 (offset_np,"retime" , + &rt_offset->retime_offset)); +WARN_ON (of_property_read_u32 (offset_np,"clk1notclk0" , + &rt_offset->clk1notclk0_offset)); +WARN_ON (of_property_read_u32 (offset_np,"clknotdata" , + &rt_offset->clknotdata_offset)); +WARN_ON (of_property_read_u32 (offset_np,"double-edge" , + &rt_offset->double_edge_offset)); +WARN_ON (of_property_read_u32 (offset_np,"invertclk" , + &rt_offset->invertclk_offset)); +WARN_ON (of_property_read_u32 (offset_np,"delay-lsb" , + &rt_offset->delay_lsb_offset)); +WARN_ON (of_property_read_u32 (offset_np,"delay-msb" , + &rt_offset->delay_msb_offset)); + } + +return 0 ; +} + +static const char *gpio_compat ="st,stixxxx-gpio" ; + +static void stixxxx_pctl_dt_child_count (struct stixxxx_pinctrl *info, +struct device_node *np) +{ +struct device_node *child; +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { + info->nbanks++; + }else { + info->nfunctions++; + info->ngroups +=of_get_child_count (child); + } + } +} + +static int stixxxx_pctl_dt_get_retime_conf (struct device_node *np, +struct stixxxx_pio_control *pc) +{ +const char *style; +char name[20 ]; +unsigned int j; +of_property_read_string (np,"st,retime-style" , &style); + +if (strcmp (style,"packed" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_packed; +for (j =0 ; j <2 ; j++) { +snprintf (name,sizeof (name),"st,retime-control%d" , j); + pc->retiming[j] =syscon_claim (np, name); +if (!pc->retiming[j]) +return -ENODATA ; + } + }else if (strcmp (style,"dedicated" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_dedicated; +for (j =0 ; j <8 ; j++) { +if ((1 <<j) & pc->rt_pin_mask) { +snprintf (name,sizeof (name), +"st,retime-control%d" , j); + pc->retiming[j] =syscon_claim (np, name); +if (!pc->retiming[j]) +return -ENODATA ; + } + } + }else if (strcmp (style,"none" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_none; + } + +return 0 ; +} + +static int stixxxx_pctl_dt_init (struct stixxxx_pinctrl *info, +struct device_node *np) +{ +struct stixxxx_pio_control *pc; +struct stixxxx_retime_params *rt_params; +struct device *dev = info->dev; +unsigned int i =0 ; +struct device_node *child =NULL ; + + pc =devm_kzalloc (dev,sizeof (*pc) * info->nbanks,GFP_KERNEL ); + rt_params =devm_kzalloc (dev,sizeof (*rt_params),GFP_KERNEL ); + +if (!pc || !rt_params) +return -ENOMEM ; + + info->pio_controls = pc; +if (stixxxx_pinconf_dt_parse_rt_params (info, np, rt_params)) +return -ENOMEM ; + +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { + pc[i].rt_params = rt_params; + + pc[i].alt =syscon_claim (child,"st,alt-control" ); +if (!pc[i].alt) + goto failed; + + pc[i].oe =syscon_claim (child,"st,oe-control" ); +if (!pc[i].oe) + goto failed; + + pc[i].pu =syscon_claim (child,"st,pu-control" ); +if (!pc[i].pu) + goto failed; + + pc[i].od =syscon_claim (child,"st,od-control" ); +if (!pc[i].od) + goto failed; + +of_property_read_u32 (child,"st,retime-pin-mask" , + &pc[i].rt_pin_mask); + +stixxxx_pctl_dt_get_retime_conf (child, &pc[i]); + i++; + } + } + +return 0 ; +failed: +return -ENODATA ; +} + +#define OF_GPIO_ARGS_MIN (3) +/* +* Each pin is represented in of the below forms. +* <bank offset direction func rt_type rt_delay rt_clk> +*/ +static int stixxxx_pctl_dt_parse_groups (struct device_node *np, +struct stixxxx_pctl_group *grp,struct stixxxx_pinctrl *info,int idx) +{ +/* bank pad direction val altfunction */ +const __be32 *list; +struct property *pp; +struct stixxxx_pinconf *conf; +phandle phandle; +struct device_node *pins; +u32 pin; +int i =0 , npins =0 , nr_props; + + pins =of_get_child_by_name (np,"st,pins" ); +if (!pins) +return -ENODATA ; + +for_each_property_of_node (pins, pp) { +/* Skip those we do not want to proceed */ +if (!strcmp (pp->name,"name" )) +continue ; + +if (pp && (pp->length/sizeof (__be32)) >=OF_GPIO_ARGS_MIN ) { + npins++; + }else { +pr_warn ("Invalid st,pins in %s node\n" , np->name); +return -EINVAL ; + } + } + + grp->npins = npins; + grp->name = np->name; + grp->pins =devm_kzalloc (info->dev, npins *sizeof (u32),GFP_KERNEL ); + grp->pin_conf =devm_kzalloc (info->dev, + npins *sizeof (*conf),GFP_KERNEL ); +of_property_read_u32 (np,"st,function" , &grp->altfunc); + +if (!grp->pins || !grp->pin_conf) +return -ENOMEM ; + +/* <bank offset direction func rt_type rt_delay rt_clk> */ +for_each_property_of_node (pins, pp) { +if (!strcmp (pp->name,"name" )) +continue ; + nr_props = pp->length/sizeof (u32); + list = pp->value; + conf = &grp->pin_conf[i]; + +/* bank & offset */ + phandle =be32_to_cpup (list++); + pin =be32_to_cpup (list++); + conf->pin =of_get_named_gpio (pins, pp->name,0 ); + conf->name = pp->name; + grp->pins[i] = conf->pin; + + conf->config =0 ; +/* direction */ + conf->config |=be32_to_cpup (list++); +/* rt_type rt_delay rt_clk */ +if (nr_props >=OF_GPIO_ARGS_MIN +2 ) { +/* rt_type */ + conf->config |=be32_to_cpup (list++); +/* rt_delay */ + conf->config |=be32_to_cpup (list++); +/* rt_clk */ +if (nr_props >OF_GPIO_ARGS_MIN +2 ) + conf->config |=be32_to_cpup (list++); + } + i++; + } +of_node_put (pins); + +return 0 ; +} + +static int stixxxx_pctl_parse_functions (struct device_node *np, +struct stixxxx_pinctrl *info,u32 index,int *grp_index) +{ +struct device_node *child; +struct stixxxx_pmx_func *func; +struct stixxxx_pctl_group *grp; +int ret, i; + + func = &info->functions[index]; + func->name = np->name; + func->ngroups =of_get_child_count (np); +if (func->ngroups <=0 ) { +dev_err (info->dev,"No groups defined\n" ); +return -EINVAL ; + } + func->groups =devm_kzalloc (info->dev, + func->ngroups *sizeof (char *),GFP_KERNEL ); +if (!func->groups) +return -ENOMEM ; + + i =0 ; +for_each_child_of_node (np, child) { + func->groups[i] = child->name; + grp = &info->groups[*grp_index]; + *grp_index +=1 ; + ret =stixxxx_pctl_dt_parse_groups (child, grp, info, i++); +if (ret) +return ret; + } +dev_info (info->dev,"Function[%d\t name:%s,\tgroups:%d]\n" , + index, func->name, func->ngroups); + +return 0 ; +} + +static int stixxxx_pctl_probe_dt (struct platform_device *pdev, +struct stixxxx_pinctrl *info) +{ +int ret =0 ; +int i =0 , j =0 , k =0 ; +struct pinctrl_pin_desc *pdesc; +struct device_node *np = pdev->dev.of_node; +struct device_node *child; +int grp_index =0 ; + +stixxxx_pctl_dt_child_count (info, np); +if (info->nbanks <1 ) { +dev_err (&pdev->dev,"you need atleast one gpio bank\n" ); +return -EINVAL ; + } + + ret =stixxxx_pctl_dt_init (info, np); +if (ret) +return ret; + +dev_info (&pdev->dev,"nbanks = %d\n" , info->nbanks); +dev_info (&pdev->dev,"nfunctions = %d\n" , info->nfunctions); +dev_info (&pdev->dev,"ngroups = %d\n" , info->ngroups); + info->functions =devm_kzalloc (&pdev->dev, + info->nfunctions *sizeof (*info->functions),GFP_KERNEL ); + + info->groups =devm_kzalloc (&pdev->dev, + info->ngroups *sizeof (*info->groups) ,GFP_KERNEL ); + +if (!info->functions || !info->groups) +return -ENOMEM ; + + stixxxx_pctl_desc.npins = info->nbanks *STIXXXX_GPIO_PINS_PER_PORT ; + pdesc =devm_kzalloc (&pdev->dev, +sizeof (*pdesc) * stixxxx_pctl_desc.npins,GFP_KERNEL ); +if (!pdesc) +return -ENOMEM ; + + stixxxx_pctl_desc.pins = pdesc; + +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { +for (j =0 ; j <STIXXXX_GPIO_PINS_PER_PORT ; j++, k++) { +const char *port_name =NULL ; + pdesc->number = k; +of_property_read_string (child,"st,bank-name" , + &port_name); + pdesc->name =kasprintf (GFP_KERNEL ,"%s[%d]" , + port_name ? :"PIO" , + port_name ? j : k); + pdesc++; + } + }else { + ret =stixxxx_pctl_parse_functions (child, info, + i++, &grp_index); +if (ret) { +dev_err (&pdev->dev,"No functions found.\n" ); +return ret; + } + } + } + +return 0 ; +} + +static int stixxxx_pctl_probe (struct platform_device *pdev) +{ +struct stixxxx_pinctrl *info; +int ret, i; + +if (!pdev->dev.of_node) { +dev_err (&pdev->dev,"device node not found.\n" ); +return -EINVAL ; + } + + info =devm_kzalloc (&pdev->dev,sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + info->dev = &pdev->dev; +platform_set_drvdata (pdev, info); + ret =stixxxx_pctl_probe_dt (pdev, info); +if (ret) +return ret; + + stixxxx_pctl_desc.name =dev_name (&pdev->dev); + info->pctl =pinctrl_register (&stixxxx_pctl_desc, &pdev->dev, info); +if (IS_ERR (info->pctl)) { +dev_err (&pdev->dev,"Failed pinctrl registration\n" ); +return PTR_ERR (info->pctl); + } + +for (i =0 ; i < info->nbanks; i++) +pinctrl_add_gpio_range (info->pctl, &gpio_ports[i]->range); + +return 0 ; +} + +static struct gpio_chip stixxxx_gpio_template = { + .request = stixxxx_gpio_request, + .free = stixxxx_gpio_free, + .get = stixxxx_gpio_get, + .set = stixxxx_gpio_set, + .direction_input = stixxxx_gpio_direction_input, + .direction_output = stixxxx_gpio_direction_output, + .ngpio =STIXXXX_GPIO_PINS_PER_PORT , + .of_gpio_n_cells =1 , + .of_xlate = stixxxx_gpio_xlate, +}; + +static int stixxxx_gpio_probe (struct platform_device *pdev) +{ +struct stixxxx_gpio_port *port; +struct pinctrl_gpio_range *range; +struct device_node *np = pdev->dev.of_node; +int port_num =of_alias_get_id (np,"gpio" ); +struct resource *res; +int err; + + port =devm_kzalloc (&pdev->dev,sizeof (*port),GFP_KERNEL ); +if (!port) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + port->base =devm_request_and_ioremap (&pdev->dev, res); +if (!port->base) { +dev_err (&pdev->dev,"Can't get IO memory mapping!\n" ); +return -ENODEV ; + } + +of_property_read_string (np,"st,bank-name" , &port->bank_name); + port->of_node = np; + + port->gpio_chip = stixxxx_gpio_template; + port->gpio_chip.base = port_num *STIXXXX_GPIO_PINS_PER_PORT ; + port->gpio_chip.ngpio =STIXXXX_GPIO_PINS_PER_PORT ; + port->gpio_chip.of_node = np; + port->gpio_chip.label =dev_name (&pdev->dev); + +dev_set_drvdata (&pdev->dev, port); + range = &port->range; + range->name = port->gpio_chip.label; + range->id = port_num; + range->pin_base = range->base = range->id *STIXXXX_GPIO_PINS_PER_PORT ; + range->npins = port->gpio_chip.ngpio; + range->gc = &port->gpio_chip; + gpio_ports[port_num] = port; + err =gpiochip_add (&port->gpio_chip); +if (err) { +dev_err (&pdev->dev,"Failed to add gpiochip(%d)!\n" , port_num); +return err; + } +dev_info (&pdev->dev,"gpioport[%s] Added as bank%d\n" , + port->bank_name, port_num); +return 0 ; +} + +static struct of_device_id stixxxx_gpio_of_match[] = { + { .compatible ="st,stixxxx-gpio" , }, + {/* sentinel */ } +}; + +static struct platform_driver stixxxx_gpio_driver = { + .driver = { + .name ="st-gpio" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (stixxxx_gpio_of_match), + }, + .probe = stixxxx_gpio_probe, +}; + +static struct of_device_id stixxxx_pctl_of_match[] = { + { .compatible ="st,stixxxx-pinctrl" ,}, + {/* sentinel */ } +}; + +static struct platform_driver stixxxx_pctl_driver = { + .driver = { + .name ="st-pinctrl" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (stixxxx_pctl_of_match), + }, + .probe = stixxxx_pctl_probe, +}; + +static int __init stixxxx_pctl_init (void ) +{ +int ret =platform_driver_register (&stixxxx_gpio_driver); +if (ret) +return ret; +return platform_driver_register (&stixxxx_pctl_driver); +} +arch_initcall (stixxxx_pctl_init);drivers/pinctrl/pinctrl-stixxxx.h new file +197
-0@@ -0,0 +1,197 @@ + +/* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Authors: +* Srinivas Kandagatla <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ + +#ifndef __LINUX_DRIVERS_PINCTRL_STIXXXX_H +#define __LINUX_DRIVERS_PINCTRL_STIXXXX_H + +enum stixxxx_retime_style { + stixxxx_retime_style_none, + stixxxx_retime_style_packed, + stixxxx_retime_style_dedicated, +}; + +/* Byte positions in 2 syscon words, starts from 0 */ +struct stixxxx_retime_offset { +int retime_offset; +int clk1notclk0_offset; +int clknotdata_offset; +int double_edge_offset; +int invertclk_offset; +int delay_lsb_offset; +int delay_msb_offset; +}; + +struct stixxxx_retime_params { +const struct stixxxx_retime_offset *retime_offset; +unsigned int *delay_times_in; +int num_delay_times_in; +unsigned int *delay_times_out; +int num_delay_times_out; +}; + +struct stixxxx_pio_control { +enum stixxxx_retime_style rt_style; +u32 rt_pin_mask; +const struct stixxxx_retime_params *rt_params; +struct syscon_field *alt; +struct syscon_field *oe, *pu, *od; +struct syscon_field *retiming[8 ]; +}; + +/* PIO Block registers */ +/* PIO output */ +#define REG_PIO_POUT 0x00 +/* Set bits of POUT */ +#define REG_PIO_SET_POUT 0x04 +/* Clear bits of POUT */ +#define REG_PIO_CLR_POUT 0x08 +/* PIO input */ +#define REG_PIO_PIN 0x10 +/* PIO configuration */ +#define REG_PIO_PC (n) (0x20 + (n) * 0x10) +/* Set bits of PC[2:0] */ +#define REG_PIO_SET_PC (n) (0x24 + (n) * 0x10) +/* Clear bits of PC[2:0] */ +#define REG_PIO_CLR_PC (n) (0x28 + (n) * 0x10) +/* PIO input comparison */ +#define REG_PIO_PCOMP 0x50 +/* Set bits of PCOMP */ +#define REG_PIO_SET_PCOMP 0x54 +/* Clear bits of PCOMP */ +#define REG_PIO_CLR_PCOMP 0x58 +/* PIO input comparison mask */ +#define REG_PIO_PMASK 0x60 +/* Set bits of PMASK */ +#define REG_PIO_SET_PMASK 0x64 +/* Clear bits of PMASK */ +#define REG_PIO_CLR_PMASK 0x68 + +#define STIXXXX_MAX_GPIO_BANKS 32 + +#define STIXXXX_GPIO_DIRECTION_BIDIR 0x1 +#define STIXXXX_GPIO_DIRECTION_OUT 0x2 +#define STIXXXX_GPIO_DIRECTION_IN 0x4 + +#define STIXXXX_GPIO_PINS_PER_PORT 8 +#define stixxxx_gpio_port (gpio) ((gpio) / STIXXXX_GPIO_PINS_PER_PORT) +#define stixxxx_gpio_pin (gpio) ((gpio) % STIXXXX_GPIO_PINS_PER_PORT) + +/* pinconf */ +/* +* Pinconf is represented in an opaque unsigned long variable. +* Below is the bit allocation details for each possible configuration. +* All the bit fields can be encapsulated into four variables +* (direction, retime-type, retime-clk, retime-delay) +* +* +----------------+ +*[31:28]| reserved-3 | +* +----------------+------------- +*[27] | oe | | +* +----------------+ v +*[26] | pu | [Direction ] +* +----------------+ ^ +*[25] | od | | +* +----------------+------------- +*[24] | reserved-2 | +* +----------------+------------- +*[23] | retime | | +* +----------------+ | +*[22] | retime-invclk | | +* +----------------+ v +*[21] |retime-clknotdat| [Retime-type ] +* +----------------+ ^ +*[20] | retime-de | | +* +----------------+------------- +*[19:18]| retime-clk |------>[Retime-Clk ] +* +----------------+ +*[17:16]| reserved-1 | +* +----------------+ +*[15..0]| retime-delay |------>[Retime Delay] +* +----------------+ +*/ + +#define STIXXXX_PINCONF_UNPACK (conf, param)\ + ((conf >> STIXXXX_PINCONF_ ##param ##_SHIFT) \ + & STIXXXX_PINCONF_ ##param ##_MASK) + +#define STIXXXX_PINCONF_PACK (conf, val, param) (conf |=\ + ((val & STIXXXX_PINCONF_ ##param ##_MASK) << \ + STIXXXX_PINCONF_ ##param ##_SHIFT)) + +/* Output enable */ +#define STIXXXX_PINCONF_OE_MASK 0x1 +#define STIXXXX_PINCONF_OE_SHIFT 27 +#define STIXXXX_PINCONF_OE BIT(27) +#define STIXXXX_PINCONF_UNPACK_OE (conf) STIXXXX_PINCONF_UNPACK(conf, OE) +#define STIXXXX_PINCONF_PACK_OE (conf, val) STIXXXX_PINCONF_PACK(conf, val, OE) + +/* Pull Up */ +#define STIXXXX_PINCONF_PU_MASK 0x1 +#define STIXXXX_PINCONF_PU_SHIFT 26 +#define STIXXXX_PINCONF_PU BIT(26) +#define STIXXXX_PINCONF_UNPACK_PU (conf) STIXXXX_PINCONF_UNPACK(conf, PU) +#define STIXXXX_PINCONF_PACK_PU (conf, val) STIXXXX_PINCONF_PACK(conf, val, PU) + +/* Open Drain */ +#define STIXXXX_PINCONF_OD_MASK 0x1 +#define STIXXXX_PINCONF_OD_SHIFT 25 +#define STIXXXX_PINCONF_OD BIT(25) +#define STIXXXX_PINCONF_UNPACK_OD (conf) STIXXXX_PINCONF_UNPACK(conf, OD) +#define STIXXXX_PINCONF_PACK_OD (conf, val) STIXXXX_PINCONF_PACK(conf, val, OD) + +#define STIXXXX_PINCONF_RT_MASK 0x1 +#define STIXXXX_PINCONF_RT_SHIFT 23 +#define STIXXXX_PINCONF_RT BIT(23) +#define STIXXXX_PINCONF_UNPACK_RT (conf) STIXXXX_PINCONF_UNPACK(conf, RT) +#define STIXXXX_PINCONF_PACK_RT (conf, val) STIXXXX_PINCONF_PACK(conf, val, RT) + +#define STIXXXX_PINCONF_RT_INVERTCLK_MASK 0x1 +#define STIXXXX_PINCONF_RT_INVERTCLK_SHIFT 22 +#define STIXXXX_PINCONF_RT_INVERTCLK BIT(22) +#define STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_INVERTCLK) +#define STIXXXX_PINCONF_PACK_RT_INVERTCLK (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_INVERTCLK) + +#define STIXXXX_PINCONF_RT_CLKNOTDATA_MASK 0x1 +#define STIXXXX_PINCONF_RT_CLKNOTDATA_SHIFT 21 +#define STIXXXX_PINCONF_RT_CLKNOTDATA BIT(21) +#define STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_CLKNOTDATA) +#define STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_CLKNOTDATA) + +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE_MASK 0x1 +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE_SHIFT 20 +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE BIT(20) +#define STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_DOUBLE_EDGE) +#define STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_DOUBLE_EDGE) + +#define STIXXXX_PINCONF_RT_CLK_MASK 0x3 +#define STIXXXX_PINCONF_RT_CLK_SHIFT 18 +#define STIXXXX_PINCONF_RT_CLK BIT(18) +#define STIXXXX_PINCONF_UNPACK_RT_CLK (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_CLK) +#define STIXXXX_PINCONF_PACK_RT_CLK (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_CLK) + +/* RETIME_DELAY in Pico Secs */ +#define STIXXXX_PINCONF_RT_DELAY_MASK 0xffff +#define STIXXXX_PINCONF_RT_DELAY_SHIFT 0 +#define STIXXXX_PINCONF_UNPACK_RT_DELAY (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_DELAY) +#define STIXXXX_PINCONF_PACK_RT_DELAY (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_DELAY) + +#endif /* __LINUX_DRIVERS_PINCTRL_STIXXXX_H */ Signature · 6 lines
1.7.6.5 _______________________________________________ devicetree-discuss mailing list devicetree-discuss at lists.ozlabs.org https://lists.ozlabs.org/listinfo/devicetree-discuss
Re: [RFC 4/8] pinctrl:stixxxx: Add pinctrl and pinconf support.
Thankyou for the comments.
Quoted 31 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 8 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
This patch add pinctrl support to ST SoCs.
About hardware:
ST Set-Top-Box parts have two blocks called PIO and PIO-mux which handle pin configurations.Quoted 8 lines
Each multi-function pin is controlled, driven and routed through the PIO multiplexing block. Each pin supports GPIO functionality (ALT0) and multiple alternate functions(ALT1 - ALTx) that directly connect the pin to different hardware blocks. When a pin is in GPIO mode, Output Enable (OE), Open Drain(OD), and Pull Up (PU) are driven by the related PIO block. Otherwise the PIO multiplexing block configures these parameters and retiming the signal.
g> About driver:
Quoted 7 lines
This pinctrl driver manages both PIO and PIO-mux block using pinctrl, pinconf, pinmux, gpio subsystems. All the pinctrl related config information can only come from device trees.
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stephen Gallimore <[email protected]>CC Stuart Menefy <[email protected]>Quoted 6 lines
--- .../bindings/pinctrl/pinctrl-stixxxx.txt | 160 +++ drivers/pinctrl/Kconfig | 13 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-stixxxx.c | 1151 ++++++++++++++++++++ drivers/pinctrl/pinctrl-stixxxx.h | 197 ++++
Quoted 3 lines
the pinctrl is present in older SoC ST40 not only stixxx
and you must provide a proper name not stixxxx
The reason for giving it stixxxx name is all the set-top-box based SOCs have the naming convention of stixxxx like stih7108, stih415, stih416 and stig125.. and so on..
Quoted 22 lines
Quoted 11 lines
5 files changed, 1522 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt create mode 100644 drivers/pinctrl/pinctrl-stixxxx.c create mode 100644 drivers/pinctrl/pinctrl-stixxxx.hDocumentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +0
-0Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 9
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +9
-0@@ -0,0 +1,160 @@ +*ST pin controller. + +Each multi-function pin is controlled, driven and routed through the +PIO multiplexing block. Each pin supports GPIO functionality (ALT0) +and multiple alternate functions(ALT1 - ALTx) that directly connect +the pin to different hardware blocks. + +When a pin is in GPIO mode, Output Enable (OE), Open Drain(OD), and +Pull Up (PU) are driven by the related PIO block.HighZ too
Quoted 2 lines
this driver look very similar with AT91 we should consolidate at binding and C level
Yes, it look very similar to at91, however they are very much different w.r.t pinconf.
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 17
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +8
-1--- + +ST pinctrl driver controls PIO multiplexing block and also interacts with +gpio driver to configure a pin. + +Required properties: (PIO multiplexing block) +- compatible : should be "st,stixxxx-pinctrl" + each subnode should set "st,stixxxx-gpio" + as compatible for each gpio-controller bank.first soc where the IP is present
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt
Quoted 7 lines
+- gpio-controller : Indicates this device is a GPIO controller +- #gpio-cells : Should be one. The first cell is the pin number. +- #retime-delay-cells : Should be number of possible retime delays. +- st,retime-in-delay : Should be array of delays in nsecs. +- st,retime-out-delay : Should be array of delays in nsecs. +- retime-style : Should indicate which type of retime is used.Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +1
-0+ possible values are "none", "packed" and "dedicated".always prefix st, when specific property
st,
Its a typo, will fix it.
Quoted 4 lines
Quoted 4 lines
+- st,retime-offset : phandle to retime offsets in retime registers.
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +3
-0+ These are not necessary for "dedicated" retime-style registers. + - clk1notclk0 : Should define offset for clk1not clk0 in retime register. + - delay-lsb : Should define offset for delay-lsb in retime register.
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 33
Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +5
-0+ - delay-msb : Should define offset for delay msb in retime register. + - invertclk : Should define offset for invertclk in retime register. + - retime : Should define offset for retime in retime register. + - clknotdata : Should define offset for clknotdata in retime register. + - double_edge : Should define offset for double edge in retime register.As much as I like to describe the IP in the DT, I think it's too much this time move this to C and use the compatible or detect it on the hardware to handle this
That is a good idea.
Quoted 58 lines
Quoted 58 lines
+- st,alt-control : Should be sysconf to control alternate function on pio. +- st,oe-control : Should be sysconf to control output enable on pio. +- st,pu-control : Should be sysconf to control pull up on pio. +- st,od-control : Should be sysconf to control open drain on pio. +- st,retime-style : Should indicate which type of retime is used.Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +51
-0+ possible values are "none", "packed" and "dedicated". +- st,retime-pin-mask : Should be mask to specify which pins can be retimed. +- retime-control[0...N]: These properties point to sysconfs which control retime. + Depending on retime-style the number of retime-controls + vary: 2 for "packed"; 8 for "dedicated". +- st,bank-name : Should be a name string for this bank. + +Example: + pio_retime_offset: pio-retime-offset { + clk1notclk0 = <0>; + delay-lsb = <2>; + delay-msb = <3>; + invertclk = <4>; + retime = <5>; + clknotdata = <6>; + double-edge = <7>; + }; + + pin-controller { + #retime-delay-cells = <4>; + compatible = "st,stixxxx-pinctrl", "simple-bus"; + st,retime-offset = <&pio_retime_offset>; + st,retime-in-delay = <0 500 1000 1500>; + st,retime-out-delay = <0 1000 2000 3000>; + ranges; + PIO0: pinctrl at fe610000 { + gpio-controller; + #gpio-cells = <1>; + compatible = "st,stixxxx-gpio"; + reg = <0xfe610000 0x100>; + st,bank-name = "PIO0"; + st,alt-control = <&SYSCONF_SBC(0) 0 31>; + st,oe-control = <&SYSCONF_SBC(5) 0 7>; + st,pu-control = <&SYSCONF_SBC(7) 0 7>; + st,od-control = <&SYSCONF_SBC(9) 0 7>; + st,retime-style = "packed"; + st,retime-pin-mask = <0xff>; + st,retime-control0 = <&SYSCONF_SBC(16) 0 31>; + st,retime-control1 = <&SYSCONF_SBC(17) 0 31>; + }; + ... + pin-functions nodes follow... + }; + + +Contents of function subnode node: +---------------------- +Required properties for pin configuration node: +- st,function : Should be alternate function number associated + with this set of pins. + possible altfunction values:
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 96
Quoted 7 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +7
-0+ ALT1 + ALT2 + ALT3 + ALT4 + ALT5 + ALT6 + ALT7use number in the DoC
Ok.
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +11
-0+ +- st,pins : Child node with list of pins with configuration. + +Below is the format of how each pin conf should look like. + +<bank offset mode rt_type rt_delay rt_clk> + +Every PIO is represented with 4-7 parameters depending on retime configuration. +Each parameter is explained as below. + +-bank : Should be bank phandle to which this PIO belongs.
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 114
Quoted 7 lines
+-offset : Offset in the PIO bank. +-mode :pin configuration is selected from one of the below values.Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +5
-0+ IN + IN_PU + OUT + BIDIR + BIDIR_PUditto
Actually these modes are top level defines of three different variables, OE, PU, OD used in the registers.
Its very common that driver might just be interested in one of listed modes.
Quoted 1,449 lines
Quoted 1,449 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +46
-0+ +-rt_type Retiming Configuration for the pin. + Possible retime configuration are: + + ------- ------------- + value args + ------- ------------- + NICLK <delay> <clk> + ICLK_IO <delay> <clk> + BYPASS <delay> + DE_IO <delay> <clk> + SE_ICLK_IO <delay> <clk> + SE_NICLK_IO <delay> <clk> + +- delay is retime delay in pico seconds. + Possible values are: refer to retime-in/out-delays + +- rt_clk :clk to be use for retime. + Possible values are: + CLK_A + CLK_B + CLK_C + CLK_D + +Example of mmcclk pin which is a bi-direction pull pu with retime config +as non inverted clock retimed with CLK_B and delay of 0 pico seconds: + +pin-controller { + ... + mmc0 { + pinctrl_mmc: mmc { + st,function = <ALT4>; + st,pins { + mmcclk = <&PIO13 4 BIDIR_PU NICLK 0 CLK_B>; + ... + }; + }; + ... + }; +}; + +sdhci0:sdhci at fe810000{ + ... + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_mmc>; +};drivers/pinctrl/Kconfig +13
-0@@ -179,6 +179,19 @@ config PINCTRL_SUNXI select PINMUX select GENERIC_PINCONF +config PINCTRL_STIXXXX + bool "ST Microelectronics pin controller driver for STixxxx SoCs" + depends on PLAT_STIXXXX + select PINMUX + select PINCONF + select MFD_SYSCON + help + Say yes here to support pinctrl interface on STixxxx SOCs. + This driver is used to control both PIO block and PIO-mux + block to configure a pin. + + If unsure, say N. + config PINCTRL_TEGRA bool select PINMUXdrivers/pinctrl/Makefile +1
-0@@ -47,6 +47,7 @@ obj-$(CONFIG_PINCTRL_EXYNOS) += pinctrl-exynos.o obj-$(CONFIG_PINCTRL_EXYNOS5440) += pinctrl-exynos5440.o obj-$(CONFIG_PINCTRL_XWAY) += pinctrl-xway.o obj-$(CONFIG_PINCTRL_LANTIQ) += pinctrl-lantiq.o +obj-$(CONFIG_PINCTRL_STIXXXX) += pinctrl-stixxxx.o obj-$(CONFIG_PLAT_ORION) += mvebu/ obj-$(CONFIG_ARCH_SHMOBILE) += sh-pfc/drivers/pinctrl/pinctrl-stixxxx.c new file +1151
-0@@ -0,0 +1,1151 @@ +/* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Authors: +* Srinivas Kandagatla <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#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/mfd/syscon.h> +#include <linux/pinctrl/pinctrl.h> +#include <linux/pinctrl/pinmux.h> +#include <linux/pinctrl/pinconf.h> +#include <linux/platform_device.h> +#include "core.h" +#include "pinctrl-stixxxx.h" + +struct stixxxx_pinconf { +int pin; +const char *name; +unsigned long config; +}; + +struct stixxxx_pmx_func { +const char *name; +const char **groups; +unsigned ngroups; +}; + +struct stixxxx_pctl_group { +const char *name; +unsigned int *pins; +unsigned npins; +int altfunc; +struct stixxxx_pinconf *pin_conf; +}; + +#define to_stixxxx_gpio_port (chip) \ + container_of(chip, struct stixxxx_gpio_port, gpio_chip) + +struct stixxxx_gpio_port { +struct gpio_chip gpio_chip; +struct pinctrl_gpio_range range; +void __iomem *base; +struct device_node *of_node; +const char *bank_name; +}; + +static struct stixxxx_gpio_port *gpio_ports[STIXXXX_MAX_GPIO_BANKS ]; + +struct stixxxx_pinctrl { +struct device *dev; +struct pinctrl_dev *pctl; +int nbanks; +struct stixxxx_pmx_func *functions; +int nfunctions; +struct stixxxx_pctl_group *groups; +int ngroups; +struct stixxxx_pio_control *pio_controls; +}; + +/* Low level functions.. */ +static void stixxxx_pinconf_set_direction (struct stixxxx_pio_control *pc, +int pin_id,unsigned long config) +{ +struct syscon_field *output_enable; +struct syscon_field *pull_up; +struct syscon_field *open_drain; +unsigned long oe_value, pu_value, od_value; +unsigned long mask; +int pin =stixxxx_gpio_pin (pin_id); + + output_enable = pc->oe; + pull_up = pc->pu; + open_drain = pc->od; + + mask =BIT (pin); + + oe_value =syscon_read (output_enable); + pu_value =syscon_read (pull_up); + od_value =syscon_read (open_drain); + +/* Clear old values */ + oe_value &= ~mask; + pu_value &= ~mask; + od_value &= ~mask; + +if (config &STIXXXX_PINCONF_OE ) + oe_value |= mask; +if (config &STIXXXX_PINCONF_PU ) + pu_value |= mask; +if (config &STIXXXX_PINCONF_OD ) + od_value |= mask; + +syscon_write (output_enable, oe_value); +syscon_write (pull_up, pu_value); +syscon_write (open_drain, od_value); +} + +static void stixxxx_pctl_set_function (struct stixxxx_pio_control *pc, +int pin_id,int function) +{ +struct syscon_field *selector; +int offset; +unsigned long val; +int pin =stixxxx_gpio_pin (pin_id); + + selector = pc->alt; + offset = pin *4 ; + val =syscon_read (selector); + val &= ~(0xf << offset); + val |= function << offset; +syscon_write (selector, val); +} + +static unsigned long stixxxx_pinconf_delay_to_bit (unsigned int delay, +const struct stixxxx_retime_params *rt_params, +unsigned long config) +{ +unsigned int *delay_times; +int num_delay_times, i, closest_index =-1 ; +unsigned int closest_divergence =UINT_MAX ; + +if (STIXXXX_PINCONF_UNPACK_OE (config)) { + delay_times = rt_params->delay_times_out; + num_delay_times = rt_params->num_delay_times_out; + }else { + delay_times = rt_params->delay_times_in; + num_delay_times = rt_params->num_delay_times_in; + } + +for (i =0 ; i < num_delay_times; i++) { +unsigned int divergence =abs (delay - delay_times[i]); + +if (divergence ==0 ) +return i; + +if (divergence < closest_divergence) { + closest_divergence = divergence; + closest_index = i; + } + } + +pr_warn ("Attempt to set delay %d, closest available %d\n" , + delay, delay_times[closest_index]); + +return closest_index; +} + +static unsigned long stixxxx_pinconf_bit_to_delay (unsigned int index, +const struct stixxxx_retime_params *rt_params, +unsigned long output) +{ +unsigned int *delay_times; +int num_delay_times; + +if (output) { + delay_times = rt_params->delay_times_out; + num_delay_times = rt_params->num_delay_times_out; + }else { + delay_times = rt_params->delay_times_in; + num_delay_times = rt_params->num_delay_times_in; + } + +if (index < num_delay_times) { +return delay_times[index]; + }else { +pr_warn ("Delay not found in/out delay list\n" ); +return 0 ; + } +} + +static void stixxxx_pinconf_set_retime_packed ( +struct stixxxx_pio_control *pc, +unsigned long config,int pin) +{ +const struct stixxxx_retime_params *rt_params = pc->rt_params; +const struct stixxxx_retime_offset *offset = rt_params->retime_offset; +struct syscon_field **regs; +unsigned long values[2 ]; +unsigned long mask; +int i, j; +int clk =STIXXXX_PINCONF_UNPACK_RT_CLK (config); +int clknotdata =STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config); +int double_edge =STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config); +int invertclk =STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config); +int retime =STIXXXX_PINCONF_UNPACK_RT (config); +unsigned long delay =stixxxx_pinconf_delay_to_bit ( +STIXXXX_PINCONF_UNPACK_RT_DELAY (config), + pc->rt_params, config); + +unsigned long rt_cfg = + ((clk &1 ) << offset->clk1notclk0_offset) | + ((clknotdata &1 ) << offset->clknotdata_offset) | + ((delay &1 ) << offset->delay_lsb_offset) | + (((delay >>1 ) &1 ) << offset->delay_msb_offset) | + ((double_edge &1 ) << offset->double_edge_offset) | + ((invertclk &1 ) << offset->invertclk_offset) | + ((retime &1 ) << offset->retime_offset); + + regs = pc->retiming; + values[0 ] =syscon_read (regs[0 ]); + values[1 ] =syscon_read (regs[1 ]); + +for (i =0 ; i <2 ; i++) { + mask =BIT (pin); +for (j =0 ; j <4 ; j++) { +if (rt_cfg &1 ) + values[i] |= mask; +else + values[i] &= ~mask; + mask <<=8 ; + rt_cfg >>=1 ; + } + } + +syscon_write (regs[0 ], values[0 ]); +syscon_write (regs[1 ], values[1 ]); +} + +static void stixxxx_pinconf_set_retime_dedicated ( +struct stixxxx_pio_control *pc, +unsigned long config,int pin) +{ +struct syscon_field *reg; +int input =STIXXXX_PINCONF_UNPACK_OE (config) ?0 :1 ; +int clk =STIXXXX_PINCONF_UNPACK_RT_CLK (config); +int clknotdata =STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config); +int double_edge =STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config); +int invertclk =STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config); +int retime =STIXXXX_PINCONF_UNPACK_RT (config); +unsigned long delay =stixxxx_pinconf_delay_to_bit ( +STIXXXX_PINCONF_UNPACK_RT_DELAY (config), + pc->rt_params, config); + +unsigned long retime_config = + ((clk &0x3 ) <<0 ) | + ((clknotdata &0x1 ) <<2 ) | + ((delay &0xf ) <<3 ) | + ((input &0x1 ) <<7 ) | + ((double_edge &0x1 ) <<8 ) | + ((invertclk &0x1 ) <<9 ) | + ((retime &0x1 ) <<10 ); + + reg = pc->retiming[pin]; +syscon_write (reg, retime_config); +} + +static void stixxxx_pinconf_get_direction (struct stixxxx_pio_control *pc, +int pin_id,unsigned long *config) +{ +unsigned long oe_value, pu_value, od_value; +int pin =stixxxx_gpio_pin (pin_id); + + oe_value = (syscon_read (pc->oe) >> pin) &1 ; + pu_value = (syscon_read (pc->pu) >> pin) &1 ; + od_value = (syscon_read (pc->od) >> pin) &1 ; + +STIXXXX_PINCONF_PACK_OE (*config, oe_value); +STIXXXX_PINCONF_PACK_PU (*config, pu_value); +STIXXXX_PINCONF_PACK_OD (*config, od_value); +} + +static int stixxxx_pinconf_get_retime_packed ( +struct stixxxx_pio_control *pc, +int pin,unsigned long *config) +{ +const struct stixxxx_retime_params *rt_params = pc->rt_params; +const struct stixxxx_retime_offset *offset = rt_params->retime_offset; +unsigned long delay_bits, delay, rt_reduced; +unsigned long rt_value[2 ]; +int i, j; +int output =STIXXXX_PINCONF_UNPACK_OE (*config); + + rt_value[0 ] =syscon_read (pc->retiming[0 ]); + rt_value[1 ] =syscon_read (pc->retiming[1 ]); + + rt_reduced =0 ; +for (i =0 ; i <2 ; i++) { +for (j =0 ; j <4 ; j++) { +if (rt_value[i] & (1 <<((8 *j)+pin))) + rt_reduced |=1 << ((i*4 )+j); + } + } + +STIXXXX_PINCONF_PACK_RT (*config, + (rt_reduced >> offset->retime_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_CLK (*config, + (rt_reduced >> offset->clk1notclk0_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (*config, + (rt_reduced >> offset->clknotdata_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (*config, + (rt_reduced >> offset->double_edge_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_INVERTCLK (*config, + (rt_reduced >> offset->invertclk_offset) &1 ); + + delay_bits = (((rt_reduced >> offset->delay_msb_offset) &1 )<<1 ) | + ((rt_reduced >> offset->delay_lsb_offset) &1 ); + delay =stixxxx_pinconf_bit_to_delay (delay_bits, rt_params, output); +STIXXXX_PINCONF_PACK_RT_DELAY (*config, delay); +return 0 ; +} + +static int stixxxx_pinconf_get_retime_dedicated ( +struct stixxxx_pio_control *pc, +int pin,unsigned long *config) +{ +unsigned long value; +unsigned long delay_bits, delay; +const struct stixxxx_retime_params *rt_params = pc->rt_params; +int output =STIXXXX_PINCONF_UNPACK_OE (*config); + + value =syscon_read (pc->retiming[pin]); +STIXXXX_PINCONF_PACK_RT_CLK (*config, ((value >>0 ) &0x3 )); +STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (*config, ((value >>2 ) &0x1 )); + delay_bits = ((value >>3 ) &0xf ); + delay =stixxxx_pinconf_bit_to_delay (delay_bits, rt_params, output); +STIXXXX_PINCONF_PACK_RT_DELAY (*config, delay); +STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (*config, ((value >>8 ) &0x1 )); +STIXXXX_PINCONF_PACK_RT_INVERTCLK (*config, ((value >>9 ) &0x1 )); +STIXXXX_PINCONF_PACK_RT (*config, ((value >>10 ) &0x1 )); + +return 0 ; +} + +/* GPIO related functions */ + +static inline void __stixxxx_gpio_set (struct stixxxx_gpio_port *port, +unsigned offset,int value) +{ +if (value) +writel (BIT (offset), port->base +REG_PIO_SET_POUT ); +else +writel (BIT (offset), port->base +REG_PIO_CLR_POUT ); +} + +static void stixxxx_gpio_direction (unsigned int gpio,unsigned int direction) +{ +int port_num =stixxxx_gpio_port (gpio); +int offset =stixxxx_gpio_pin (gpio); +struct stixxxx_gpio_port *port = gpio_ports[port_num]; +int i =0 ; + +for (i =0 ; i <=2 ; i++) { +if (direction &BIT (i)) +writel (BIT (offset), port->base +REG_PIO_SET_PC (i)); +else +writel (BIT (offset), port->base +REG_PIO_CLR_PC (i)); + } +} + +static int stixxxx_gpio_request (struct gpio_chip *chip,unsigned offset) +{ +return pinctrl_request_gpio (chip->base + offset); +} + +static void stixxxx_gpio_free (struct gpio_chip *chip,unsigned offset) +{ +pinctrl_free_gpio (chip->base + offset); +} + +static int stixxxx_gpio_get (struct gpio_chip *chip,unsigned offset) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); + +return (readl (port->base +REG_PIO_PIN ) >> offset) &1 ; +} + +static void stixxxx_gpio_set (struct gpio_chip *chip,unsigned offset,int value) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); +__stixxxx_gpio_set (port, offset, value); +} + +static int stixxxx_gpio_direction_input (struct gpio_chip *chip,unsigned offset) +{ +pinctrl_gpio_direction_input (chip->base + offset); +return 0 ; +} + +static int stixxxx_gpio_direction_output (struct gpio_chip *chip, +unsigned offset,int value) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); + +__stixxxx_gpio_set (port, offset, value); +pinctrl_gpio_direction_output (chip->base + offset); + +return 0 ; +} + +static int stixxxx_gpio_xlate (struct gpio_chip *gc, +const struct of_phandle_args *gpiospec,u32 *flags) +{ +if (WARN_ON (gc->of_gpio_n_cells <1 )) +return -EINVAL ; + +if (WARN_ON (gpiospec->args_count < gc->of_gpio_n_cells)) +return -EINVAL ; + +if (gpiospec->args[0 ] > gc->ngpio) +return -EINVAL ; + +return gpiospec->args[0 ]; +} + +/* Pinctrl Groups */ +static int stixxxx_pctl_get_groups_count (struct pinctrl_dev *pctldev) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->ngroups; +} + +static const char *stixxxx_pctl_get_group_name (struct pinctrl_dev *pctldev, +unsigned selector) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->groups[selector].name; +} + +static int stixxxx_pctl_get_group_pins (struct pinctrl_dev *pctldev, +unsigned selector,const unsigned **pins,unsigned *npins) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +if (selector >= info->ngroups) +return -EINVAL ; + + *pins = info->groups[selector].pins; + *npins = info->groups[selector].npins; + +return 0 ; +} + +static const inline struct stixxxx_pctl_group *stixxxx_pctl_find_group_by_name ( +const struct stixxxx_pinctrl *info,const char *name) +{ +int i; + +for (i =0 ; i < info->ngroups; i++) { +if (!strcmp (info->groups[i].name, name)) +return &info->groups[i]; + } + +return NULL ; +} + +static int stixxxx_pctl_dt_node_to_map (struct pinctrl_dev *pctldev, +struct device_node *np,struct pinctrl_map **map,unsigned *num_maps) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +const struct stixxxx_pctl_group *grp; +struct pinctrl_map *new_map; +struct device_node *parent; +int map_num, i; + + grp =stixxxx_pctl_find_group_by_name (info, np->name); +if (!grp) { +dev_err (info->dev,"unable to find group for node %s\n" , + np->name); +return -EINVAL ; + } + + map_num = grp->npins +1 ; + new_map =devm_kzalloc (pctldev->dev, +sizeof (*new_map) * map_num,GFP_KERNEL ); +if (!new_map) +return -ENOMEM ; + + parent =of_get_parent (np); +if (!parent) { +devm_kfree (pctldev->dev, new_map); +return -EINVAL ; + } + + *map = new_map; + *num_maps = map_num; + new_map[0 ].type =PIN_MAP_TYPE_MUX_GROUP ; + new_map[0 ].data.mux.function = parent->name; + new_map[0 ].data.mux.group = np->name; +of_node_put (parent); + +/* create config map per pin */ + new_map++; +for (i =0 ; i < grp->npins; i++) { + new_map[i].type =PIN_MAP_TYPE_CONFIGS_PIN ; + new_map[i].data.configs.group_or_pin = +pin_get_name (pctldev, grp->pins[i]); + new_map[i].data.configs.configs = &grp->pin_conf[i].config; + new_map[i].data.configs.num_configs =1 ; + } +dev_info (pctldev->dev,"maps: function %s group %s num %d\n" , + (*map)->data.mux.function, grp->name, map_num); + +return 0 ; +} + +static void stixxxx_pctl_dt_free_map (struct pinctrl_dev *pctldev, +struct pinctrl_map *map,unsigned num_maps) +{ +} + +static struct pinctrl_ops stixxxx_pctlops = { + .get_groups_count = stixxxx_pctl_get_groups_count, + .get_group_pins = stixxxx_pctl_get_group_pins, + .get_group_name = stixxxx_pctl_get_group_name, + .dt_node_to_map = stixxxx_pctl_dt_node_to_map, + .dt_free_map = stixxxx_pctl_dt_free_map, +}; + +/* Pinmux */ +static int stixxxx_pmx_get_funcs_count (struct pinctrl_dev *pctldev) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->nfunctions; +} + +const char *stixxxx_pmx_get_fname (struct pinctrl_dev *pctldev, +unsigned selector) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->functions[selector].name; +} + +static int stixxxx_pmx_get_groups (struct pinctrl_dev *pctldev, +unsigned selector,const char *const **grps,unsigned *const ngrps) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + *grps = info->functions[selector].groups; + *ngrps = info->functions[selector].ngroups; + +return 0 ; +} + +static struct stixxxx_pio_control *stixxxx_get_pio_control ( +struct stixxxx_pinctrl *info,int pin_id) +{ +int port =stixxxx_gpio_port (pin_id); +return &info->pio_controls[port]; +} + +static int stixxxx_pmx_enable (struct pinctrl_dev *pctldev,unsigned fselector, +unsigned group) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pinconf *conf = info->groups[group].pin_conf; +struct stixxxx_pio_control *pc; +int i; + +for (i =0 ; i < info->groups[group].npins; i++) { + pc =stixxxx_get_pio_control (info, conf[i].pin); +stixxxx_pctl_set_function (pc, conf[i].pin, + info->groups[group].altfunc); + } + +return 0 ; +} + +static void stixxxx_pmx_disable (struct pinctrl_dev *pctldev,unsigned selector, +unsigned group) +{ +} + +static int stixxxx_pmx_set_gpio_direction (struct pinctrl_dev *pctldev, +struct pinctrl_gpio_range *range,unsigned gpio, +bool input) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc = &info->pio_controls[range->id]; +/* +* When a PIO port is used in its primary function mode (altfunc = 0) +* Output Enable (OE), Open Drain(OD), and Pull Up (PU) +* for the primary PIO functions are driven by the related PIO block +*/ +stixxxx_pctl_set_function (pc, gpio,0 ); +stixxxx_gpio_direction (gpio, input ? +STIXXXX_GPIO_DIRECTION_IN :STIXXXX_GPIO_DIRECTION_OUT ); + +return 0 ; +} + +static struct pinmux_ops stixxxx_pmxops = { + .get_functions_count = stixxxx_pmx_get_funcs_count, + .get_function_name = stixxxx_pmx_get_fname, + .get_function_groups = stixxxx_pmx_get_groups, + .enable = stixxxx_pmx_enable, + .disable = stixxxx_pmx_disable, + .gpio_set_direction = stixxxx_pmx_set_gpio_direction, +}; + +/* Pinconf */ +static void stixxxx_pinconf_get_retime (struct stixxxx_pio_control *pc, +int pin_id,unsigned long *config) +{ +int pin =stixxxx_gpio_pin (pin_id); +if (pc->rt_style == stixxxx_retime_style_packed) +stixxxx_pinconf_get_retime_packed (pc, pin, config); +else if (pc->rt_style == stixxxx_retime_style_dedicated) +if ((BIT (pin) & pc->rt_pin_mask)) +stixxxx_pinconf_get_retime_dedicated (pc, pin, config); +} + +static void stixxxx_pinconf_set_retime (struct stixxxx_pio_control *pc, +int pin_id,unsigned long config) +{ +int pin =stixxxx_gpio_pin (pin_id); + +if (pc->rt_style == stixxxx_retime_style_packed) +stixxxx_pinconf_set_retime_packed (pc, config, pin); +else if (pc->rt_style == stixxxx_retime_style_dedicated) +if ((BIT (pin) & pc->rt_pin_mask)) +stixxxx_pinconf_set_retime_dedicated (pc, config, pin); +} + +static int stixxxx_pinconf_set (struct pinctrl_dev *pctldev, +unsigned pin_id,unsigned long config) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc =stixxxx_get_pio_control (info, pin_id); + +stixxxx_pinconf_set_direction (pc, pin_id, config); +stixxxx_pinconf_set_retime (pc, pin_id, config); +return 0 ; +} + +static int stixxxx_pinconf_get (struct pinctrl_dev *pctldev, +unsigned pin_id,unsigned long *config) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc =stixxxx_get_pio_control (info, pin_id); + + *config =0 ; +stixxxx_pinconf_get_direction (pc, pin_id, config); +stixxxx_pinconf_get_retime (pc, pin_id, config); + +return 0 ; +} + +static void stixxxx_pinconf_dbg_show (struct pinctrl_dev *pctldev, +struct seq_file *s,unsigned pin_id) +{ +unsigned long config; +stixxxx_pinconf_get (pctldev, pin_id, &config); + +seq_printf (s,"[OE:%ld,PU:%ld,OD:%ld]\n" +"\t\t[retime:%ld,invclk:%ld,clknotdat:%ld," +"de:%ld,rt-clk:%ld,rt-delay:%ld]" , +STIXXXX_PINCONF_UNPACK_OE (config), +STIXXXX_PINCONF_UNPACK_PU (config), +STIXXXX_PINCONF_UNPACK_OD (config), +STIXXXX_PINCONF_UNPACK_RT (config), +STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config), +STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config), +STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config), +STIXXXX_PINCONF_UNPACK_RT_CLK (config), +STIXXXX_PINCONF_UNPACK_RT_DELAY (config)); +} + +static struct pinconf_ops stixxxx_confops = { + .pin_config_get = stixxxx_pinconf_get, + .pin_config_set = stixxxx_pinconf_set, + .pin_config_dbg_show = stixxxx_pinconf_dbg_show, +}; + +/* pinctrl */ +static struct pinctrl_desc stixxxx_pctl_desc = { + .owner =THIS_MODULE , + .pctlops = &stixxxx_pctlops, + .pmxops = &stixxxx_pmxops, + .confops = &stixxxx_confops, +}; + +static int stixxxx_pinconf_dt_parse_rt_params (struct stixxxx_pinctrl *info, +struct device_node *np,struct stixxxx_retime_params *params) +{ +const __be32 *ip; +struct device_node *offset_np; +struct stixxxx_retime_offset *rt_offset; +int delay_count =0 ; + + ip =of_get_property (np,"#retime-delay-cells" ,NULL ); +if (ip) + delay_count =be32_to_cpup (ip); +else +pr_warn ("No #retime-delay-cells specified\n" ); + + params->num_delay_times_out = delay_count; + params->num_delay_times_in = delay_count; + params->delay_times_in =devm_kzalloc (info->dev, +sizeof (u32) * delay_count,GFP_KERNEL ); + params->delay_times_out =devm_kzalloc (info->dev, +sizeof (u32) * delay_count,GFP_KERNEL ); + +if (!params->delay_times_in || !params->delay_times_out) +return -ENOMEM ; + +of_property_read_u32_array (np,"st,retime-in-delay" , + (u32 *)params->delay_times_in, delay_count); +of_property_read_u32_array (np,"st,retime-out-delay" , + (u32 *)params->delay_times_out, delay_count); + + offset_np =of_parse_phandle (np,"st,retime-offset" ,0 ); + +if (offset_np) { + rt_offset =devm_kzalloc (info->dev, +sizeof (*rt_offset),GFP_KERNEL ); +if (!rt_offset) +return -ENOMEM ; + + params->retime_offset = rt_offset; +WARN_ON (of_property_read_u32 (offset_np,"retime" , + &rt_offset->retime_offset)); +WARN_ON (of_property_read_u32 (offset_np,"clk1notclk0" , + &rt_offset->clk1notclk0_offset)); +WARN_ON (of_property_read_u32 (offset_np,"clknotdata" , + &rt_offset->clknotdata_offset)); +WARN_ON (of_property_read_u32 (offset_np,"double-edge" , + &rt_offset->double_edge_offset)); +WARN_ON (of_property_read_u32 (offset_np,"invertclk" , + &rt_offset->invertclk_offset)); +WARN_ON (of_property_read_u32 (offset_np,"delay-lsb" , + &rt_offset->delay_lsb_offset)); +WARN_ON (of_property_read_u32 (offset_np,"delay-msb" , + &rt_offset->delay_msb_offset)); + } + +return 0 ; +} + +static const char *gpio_compat ="st,stixxxx-gpio" ; + +static void stixxxx_pctl_dt_child_count (struct stixxxx_pinctrl *info, +struct device_node *np) +{ +struct device_node *child; +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { + info->nbanks++; + }else { + info->nfunctions++; + info->ngroups +=of_get_child_count (child); + } + } +} + +static int stixxxx_pctl_dt_get_retime_conf (struct device_node *np, +struct stixxxx_pio_control *pc) +{ +const char *style; +char name[20 ]; +unsigned int j; +of_property_read_string (np,"st,retime-style" , &style); + +if (strcmp (style,"packed" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_packed; +for (j =0 ; j <2 ; j++) { +snprintf (name,sizeof (name),"st,retime-control%d" , j); + pc->retiming[j] =syscon_claim (np, name); +if (!pc->retiming[j]) +return -ENODATA ; + } + }else if (strcmp (style,"dedicated" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_dedicated; +for (j =0 ; j <8 ; j++) { +if ((1 <<j) & pc->rt_pin_mask) { +snprintf (name,sizeof (name), +"st,retime-control%d" , j); + pc->retiming[j] =syscon_claim (np, name); +if (!pc->retiming[j]) +return -ENODATA ; + } + } + }else if (strcmp (style,"none" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_none; + } + +return 0 ; +} + +static int stixxxx_pctl_dt_init (struct stixxxx_pinctrl *info, +struct device_node *np) +{ +struct stixxxx_pio_control *pc; +struct stixxxx_retime_params *rt_params; +struct device *dev = info->dev; +unsigned int i =0 ; +struct device_node *child =NULL ; + + pc =devm_kzalloc (dev,sizeof (*pc) * info->nbanks,GFP_KERNEL ); + rt_params =devm_kzalloc (dev,sizeof (*rt_params),GFP_KERNEL ); + +if (!pc || !rt_params) +return -ENOMEM ; + + info->pio_controls = pc; +if (stixxxx_pinconf_dt_parse_rt_params (info, np, rt_params)) +return -ENOMEM ; + +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { + pc[i].rt_params = rt_params; + + pc[i].alt =syscon_claim (child,"st,alt-control" ); +if (!pc[i].alt) + goto failed; + + pc[i].oe =syscon_claim (child,"st,oe-control" ); +if (!pc[i].oe) + goto failed; + + pc[i].pu =syscon_claim (child,"st,pu-control" ); +if (!pc[i].pu) + goto failed; + + pc[i].od =syscon_claim (child,"st,od-control" ); +if (!pc[i].od) + goto failed; + +of_property_read_u32 (child,"st,retime-pin-mask" , + &pc[i].rt_pin_mask); + +stixxxx_pctl_dt_get_retime_conf (child, &pc[i]); + i++; + } + } + +return 0 ; +failed: +return -ENODATA ; +} + +#define OF_GPIO_ARGS_MIN (3) +/* +* Each pin is represented in of the below forms. +* <bank offset direction func rt_type rt_delay rt_clk> +*/ +static int stixxxx_pctl_dt_parse_groups (struct device_node *np, +struct stixxxx_pctl_group *grp,struct stixxxx_pinctrl *info,int idx) +{ +/* bank pad direction val altfunction */ +const __be32 *list; +struct property *pp; +struct stixxxx_pinconf *conf; +phandle phandle; +struct device_node *pins; +u32 pin; +int i =0 , npins =0 , nr_props; + + pins =of_get_child_by_name (np,"st,pins" ); +if (!pins) +return -ENODATA ; + +for_each_property_of_node (pins, pp) { +/* Skip those we do not want to proceed */ +if (!strcmp (pp->name,"name" )) +continue ; + +if (pp && (pp->length/sizeof (__be32)) >=OF_GPIO_ARGS_MIN ) { + npins++; + }else { +pr_warn ("Invalid st,pins in %s node\n" , np->name); +return -EINVAL ; + } + } + + grp->npins = npins; + grp->name = np->name; + grp->pins =devm_kzalloc (info->dev, npins *sizeof (u32),GFP_KERNEL ); + grp->pin_conf =devm_kzalloc (info->dev, + npins *sizeof (*conf),GFP_KERNEL ); +of_property_read_u32 (np,"st,function" , &grp->altfunc); + +if (!grp->pins || !grp->pin_conf) +return -ENOMEM ; + +/* <bank offset direction func rt_type rt_delay rt_clk> */ +for_each_property_of_node (pins, pp) { +if (!strcmp (pp->name,"name" )) +continue ; + nr_props = pp->length/sizeof (u32); + list = pp->value; + conf = &grp->pin_conf[i]; + +/* bank & offset */ + phandle =be32_to_cpup (list++); + pin =be32_to_cpup (list++); + conf->pin =of_get_named_gpio (pins, pp->name,0 ); + conf->name = pp->name; + grp->pins[i] = conf->pin; + + conf->config =0 ; +/* direction */ + conf->config |=be32_to_cpup (list++); +/* rt_type rt_delay rt_clk */ +if (nr_props >=OF_GPIO_ARGS_MIN +2 ) { +/* rt_type */ + conf->config |=be32_to_cpup (list++); +/* rt_delay */ + conf->config |=be32_to_cpup (list++); +/* rt_clk */ +if (nr_props >OF_GPIO_ARGS_MIN +2 ) + conf->config |=be32_to_cpup (list++); + } + i++; + } +of_node_put (pins); + +return 0 ; +} + +static int stixxxx_pctl_parse_functions (struct device_node *np, +struct stixxxx_pinctrl *info,u32 index,int *grp_index) +{ +struct device_node *child; +struct stixxxx_pmx_func *func; +struct stixxxx_pctl_group *grp; +int ret, i; + + func = &info->functions[index]; + func->name = np->name; + func->ngroups =of_get_child_count (np); +if (func->ngroups <=0 ) { +dev_err (info->dev,"No groups defined\n" ); +return -EINVAL ; + } + func->groups =devm_kzalloc (info->dev, + func->ngroups *sizeof (char *),GFP_KERNEL ); +if (!func->groups) +return -ENOMEM ; + + i =0 ; +for_each_child_of_node (np, child) { + func->groups[i] = child->name; + grp = &info->groups[*grp_index]; + *grp_index +=1 ; + ret =stixxxx_pctl_dt_parse_groups (child, grp, info, i++); +if (ret) +return ret; + } +dev_info (info->dev,"Function[%d\t name:%s,\tgroups:%d]\n" , + index, func->name, func->ngroups); + +return 0 ; +} + +static int stixxxx_pctl_probe_dt (struct platform_device *pdev, +struct stixxxx_pinctrl *info) +{ +int ret =0 ; +int i =0 , j =0 , k =0 ; +struct pinctrl_pin_desc *pdesc; +struct device_node *np = pdev->dev.of_node; +struct device_node *child; +int grp_index =0 ; + +stixxxx_pctl_dt_child_count (info, np); +if (info->nbanks <1 ) { +dev_err (&pdev->dev,"you need atleast one gpio bank\n" ); +return -EINVAL ; + } + + ret =stixxxx_pctl_dt_init (info, np); +if (ret) +return ret; + +dev_info (&pdev->dev,"nbanks = %d\n" , info->nbanks); +dev_info (&pdev->dev,"nfunctions = %d\n" , info->nfunctions); +dev_info (&pdev->dev,"ngroups = %d\n" , info->ngroups); + info->functions =devm_kzalloc (&pdev->dev, + info->nfunctions *sizeof (*info->functions),GFP_KERNEL ); + + info->groups =devm_kzalloc (&pdev->dev, + info->ngroups *sizeof (*info->groups) ,GFP_KERNEL ); + +if (!info->functions || !info->groups) +return -ENOMEM ; + + stixxxx_pctl_desc.npins = info->nbanks *STIXXXX_GPIO_PINS_PER_PORT ; + pdesc =devm_kzalloc (&pdev->dev, +sizeof (*pdesc) * stixxxx_pctl_desc.npins,GFP_KERNEL ); +if (!pdesc) +return -ENOMEM ; + + stixxxx_pctl_desc.pins = pdesc; + +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { +for (j =0 ; j <STIXXXX_GPIO_PINS_PER_PORT ; j++, k++) { +const char *port_name =NULL ; + pdesc->number = k; +of_property_read_string (child,"st,bank-name" , + &port_name); + pdesc->name =kasprintf (GFP_KERNEL ,"%s[%d]" , + port_name ? :"PIO" , + port_name ? j : k); + pdesc++; + } + }else { + ret =stixxxx_pctl_parse_functions (child, info, + i++, &grp_index); +if (ret) { +dev_err (&pdev->dev,"No functions found.\n" ); +return ret; + } + } + } + +return 0 ; +} + +static int stixxxx_pctl_probe (struct platform_device *pdev) +{ +struct stixxxx_pinctrl *info; +int ret, i; + +if (!pdev->dev.of_node) { +dev_err (&pdev->dev,"device node not found.\n" ); +return -EINVAL ; + } + + info =devm_kzalloc (&pdev->dev,sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + info->dev = &pdev->dev; +platform_set_drvdata (pdev, info); + ret =stixxxx_pctl_probe_dt (pdev, info); +if (ret) +return ret; + + stixxxx_pctl_desc.name =dev_name (&pdev->dev); + info->pctl =pinctrl_register (&stixxxx_pctl_desc, &pdev->dev, info); +if (IS_ERR (info->pctl)) { +dev_err (&pdev->dev,"Failed pinctrl registration\n" ); +return PTR_ERR (info->pctl); + } + +for (i =0 ; i < info->nbanks; i++) +pinctrl_add_gpio_range (info->pctl, &gpio_ports[i]->range); + +return 0 ; +} + +static struct gpio_chip stixxxx_gpio_template = { + .request = stixxxx_gpio_request, + .free = stixxxx_gpio_free, + .get = stixxxx_gpio_get, + .set = stixxxx_gpio_set, + .direction_input = stixxxx_gpio_direction_input, + .direction_output = stixxxx_gpio_direction_output, + .ngpio =STIXXXX_GPIO_PINS_PER_PORT , + .of_gpio_n_cells =1 , + .of_xlate = stixxxx_gpio_xlate, +}; + +static int stixxxx_gpio_probe (struct platform_device *pdev) +{ +struct stixxxx_gpio_port *port; +struct pinctrl_gpio_range *range; +struct device_node *np = pdev->dev.of_node; +int port_num =of_alias_get_id (np,"gpio" ); +struct resource *res; +int err; + + port =devm_kzalloc (&pdev->dev,sizeof (*port),GFP_KERNEL ); +if (!port) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + port->base =devm_request_and_ioremap (&pdev->dev, res); +if (!port->base) { +dev_err (&pdev->dev,"Can't get IO memory mapping!\n" ); +return -ENODEV ; + } + +of_property_read_string (np,"st,bank-name" , &port->bank_name); + port->of_node = np; + + port->gpio_chip = stixxxx_gpio_template; + port->gpio_chip.base = port_num *STIXXXX_GPIO_PINS_PER_PORT ; + port->gpio_chip.ngpio =STIXXXX_GPIO_PINS_PER_PORT ; + port->gpio_chip.of_node = np; + port->gpio_chip.label =dev_name (&pdev->dev); + +dev_set_drvdata (&pdev->dev, port); + range = &port->range; + range->name = port->gpio_chip.label; + range->id = port_num; + range->pin_base = range->base = range->id *STIXXXX_GPIO_PINS_PER_PORT ; + range->npins = port->gpio_chip.ngpio; + range->gc = &port->gpio_chip; + gpio_ports[port_num] = port; + err =gpiochip_add (&port->gpio_chip); +if (err) { +dev_err (&pdev->dev,"Failed to add gpiochip(%d)!\n" , port_num); +return err; + } +dev_info (&pdev->dev,"gpioport[%s] Added as bank%d\n" , + port->bank_name, port_num); +return 0 ; +} + +static struct of_device_id stixxxx_gpio_of_match[] = { + { .compatible ="st,stixxxx-gpio" , }, + {/* sentinel */ } +}; + +static struct platform_driver stixxxx_gpio_driver = { + .driver = { + .name ="st-gpio" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (stixxxx_gpio_of_match), + }, + .probe = stixxxx_gpio_probe, +}; + +static struct of_device_id stixxxx_pctl_of_match[] = { + { .compatible ="st,stixxxx-pinctrl" ,}, + {/* sentinel */ } +}; + +static struct platform_driver stixxxx_pctl_driver = { + .driver = { + .name ="st-pinctrl" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (stixxxx_pctl_of_match), + }, + .probe = stixxxx_pctl_probe, +}; + +static int __init stixxxx_pctl_init (void ) +{ +int ret =platform_driver_register (&stixxxx_gpio_driver); +if (ret) +return ret; +return platform_driver_register (&stixxxx_pctl_driver); +} +arch_initcall (stixxxx_pctl_init);drivers/pinctrl/pinctrl-stixxxx.h new file +197
-0@@ -0,0 +1,197 @@ + +/* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Authors: +* Srinivas Kandagatla <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ + +#ifndef __LINUX_DRIVERS_PINCTRL_STIXXXX_H +#define __LINUX_DRIVERS_PINCTRL_STIXXXX_H + +enum stixxxx_retime_style { + stixxxx_retime_style_none, + stixxxx_retime_style_packed, + stixxxx_retime_style_dedicated, +}; + +/* Byte positions in 2 syscon words, starts from 0 */ +struct stixxxx_retime_offset { +int retime_offset; +int clk1notclk0_offset; +int clknotdata_offset; +int double_edge_offset; +int invertclk_offset; +int delay_lsb_offset; +int delay_msb_offset; +}; + +struct stixxxx_retime_params { +const struct stixxxx_retime_offset *retime_offset; +unsigned int *delay_times_in; +int num_delay_times_in; +unsigned int *delay_times_out; +int num_delay_times_out; +}; + +struct stixxxx_pio_control { +enum stixxxx_retime_style rt_style; +u32 rt_pin_mask; +const struct stixxxx_retime_params *rt_params; +struct syscon_field *alt; +struct syscon_field *oe, *pu, *od; +struct syscon_field *retiming[8 ]; +}; + +/* PIO Block registers */ +/* PIO output */ +#define REG_PIO_POUT 0x00 +/* Set bits of POUT */ +#define REG_PIO_SET_POUT 0x04 +/* Clear bits of POUT */ +#define REG_PIO_CLR_POUT 0x08 +/* PIO input */ +#define REG_PIO_PIN 0x10 +/* PIO configuration */ +#define REG_PIO_PC (n) (0x20 + (n) * 0x10) +/* Set bits of PC[2:0] */ +#define REG_PIO_SET_PC (n) (0x24 + (n) * 0x10) +/* Clear bits of PC[2:0] */ +#define REG_PIO_CLR_PC (n) (0x28 + (n) * 0x10) +/* PIO input comparison */ +#define REG_PIO_PCOMP 0x50 +/* Set bits of PCOMP */ +#define REG_PIO_SET_PCOMP 0x54 +/* Clear bits of PCOMP */ +#define REG_PIO_CLR_PCOMP 0x58 +/* PIO input comparison mask */ +#define REG_PIO_PMASK 0x60 +/* Set bits of PMASK */ +#define REG_PIO_SET_PMASK 0x64 +/* Clear bits of PMASK */ +#define REG_PIO_CLR_PMASK 0x68 + +#define STIXXXX_MAX_GPIO_BANKS 32 + +#define STIXXXX_GPIO_DIRECTION_BIDIR 0x1 +#define STIXXXX_GPIO_DIRECTION_OUT 0x2 +#define STIXXXX_GPIO_DIRECTION_IN 0x4 + +#define STIXXXX_GPIO_PINS_PER_PORT 8 +#define stixxxx_gpio_port (gpio) ((gpio) / STIXXXX_GPIO_PINS_PER_PORT) +#define stixxxx_gpio_pin (gpio) ((gpio) % STIXXXX_GPIO_PINS_PER_PORT) + +/* pinconf */ +/* +* Pinconf is represented in an opaque unsigned long variable. +* Below is the bit allocation details for each possible configuration. +* All the bit fields can be encapsulated into four variables +* (direction, retime-type, retime-clk, retime-delay) +* +* +----------------+ +*[31:28]| reserved-3 | +* +----------------+------------- +*[27] | oe | | +* +----------------+ v +*[26] | pu | [Direction ] +* +----------------+ ^ +*[25] | od | | +* +----------------+------------- +*[24] | reserved-2 | +* +----------------+------------- +*[23] | retime | | +* +----------------+ | +*[22] | retime-invclk | | +* +----------------+ v +*[21] |retime-clknotdat| [Retime-type ] +* +----------------+ ^ +*[20] | retime-de | | +* +----------------+------------- +*[19:18]| retime-clk |------>[Retime-Clk ] +* +----------------+ +*[17:16]| reserved-1 | +* +----------------+ +*[15..0]| retime-delay |------>[Retime Delay] +* +----------------+ +*/ + +#define STIXXXX_PINCONF_UNPACK (conf, param)\ + ((conf >> STIXXXX_PINCONF_ ##param ##_SHIFT) \ + & STIXXXX_PINCONF_ ##param ##_MASK) + +#define STIXXXX_PINCONF_PACK (conf, val, param) (conf |=\ + ((val & STIXXXX_PINCONF_ ##param ##_MASK) << \ + STIXXXX_PINCONF_ ##param ##_SHIFT)) + +/* Output enable */ +#define STIXXXX_PINCONF_OE_MASK 0x1 +#define STIXXXX_PINCONF_OE_SHIFT 27 +#define STIXXXX_PINCONF_OE BIT(27) +#define STIXXXX_PINCONF_UNPACK_OE (conf) STIXXXX_PINCONF_UNPACK(conf, OE) +#define STIXXXX_PINCONF_PACK_OE (conf, val) STIXXXX_PINCONF_PACK(conf, val, OE) + +/* Pull Up */ +#define STIXXXX_PINCONF_PU_MASK 0x1 +#define STIXXXX_PINCONF_PU_SHIFT 26 +#define STIXXXX_PINCONF_PU BIT(26) +#define STIXXXX_PINCONF_UNPACK_PU (conf) STIXXXX_PINCONF_UNPACK(conf, PU) +#define STIXXXX_PINCONF_PACK_PU (conf, val) STIXXXX_PINCONF_PACK(conf, val, PU) + +/* Open Drain */ +#define STIXXXX_PINCONF_OD_MASK 0x1 +#define STIXXXX_PINCONF_OD_SHIFT 25 +#define STIXXXX_PINCONF_OD BIT(25) +#define STIXXXX_PINCONF_UNPACK_OD (conf) STIXXXX_PINCONF_UNPACK(conf, OD) +#define STIXXXX_PINCONF_PACK_OD (conf, val) STIXXXX_PINCONF_PACK(conf, val, OD) + +#define STIXXXX_PINCONF_RT_MASK 0x1 +#define STIXXXX_PINCONF_RT_SHIFT 23 +#define STIXXXX_PINCONF_RT BIT(23) +#define STIXXXX_PINCONF_UNPACK_RT (conf) STIXXXX_PINCONF_UNPACK(conf, RT) +#define STIXXXX_PINCONF_PACK_RT (conf, val) STIXXXX_PINCONF_PACK(conf, val, RT) + +#define STIXXXX_PINCONF_RT_INVERTCLK_MASK 0x1 +#define STIXXXX_PINCONF_RT_INVERTCLK_SHIFT 22 +#define STIXXXX_PINCONF_RT_INVERTCLK BIT(22) +#define STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_INVERTCLK) +#define STIXXXX_PINCONF_PACK_RT_INVERTCLK (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_INVERTCLK) + +#define STIXXXX_PINCONF_RT_CLKNOTDATA_MASK 0x1 +#define STIXXXX_PINCONF_RT_CLKNOTDATA_SHIFT 21 +#define STIXXXX_PINCONF_RT_CLKNOTDATA BIT(21) +#define STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_CLKNOTDATA) +#define STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_CLKNOTDATA) + +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE_MASK 0x1 +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE_SHIFT 20 +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE BIT(20) +#define STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_DOUBLE_EDGE) +#define STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_DOUBLE_EDGE) + +#define STIXXXX_PINCONF_RT_CLK_MASK 0x3 +#define STIXXXX_PINCONF_RT_CLK_SHIFT 18 +#define STIXXXX_PINCONF_RT_CLK BIT(18) +#define STIXXXX_PINCONF_UNPACK_RT_CLK (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_CLK) +#define STIXXXX_PINCONF_PACK_RT_CLK (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_CLK) + +/* RETIME_DELAY in Pico Secs */ +#define STIXXXX_PINCONF_RT_DELAY_MASK 0xffff +#define STIXXXX_PINCONF_RT_DELAY_SHIFT 0 +#define STIXXXX_PINCONF_UNPACK_RT_DELAY (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_DELAY) +#define STIXXXX_PINCONF_PACK_RT_DELAY (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_DELAY) + +#endif /* __LINUX_DRIVERS_PINCTRL_STIXXXX_H */ Signature · 6 lines
1.7.6.5 _______________________________________________ devicetree-discuss mailing list devicetree-discuss at lists.ozlabs.org https://lists.ozlabs.org/listinfo/devicetree-discuss
Re: [RFC 4/8] pinctrl:stixxxx: Add pinctrl and pinconf support.
Quoted 33 lines · Srinivas KANDAGATLA
Thankyou for the comments.
Quoted 31 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 8 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
This patch add pinctrl support to ST SoCs.
About hardware:
ST Set-Top-Box parts have two blocks called PIO and PIO-mux which handle pin configurations.Quoted 8 lines
Each multi-function pin is controlled, driven and routed through the PIO multiplexing block. Each pin supports GPIO functionality (ALT0) and multiple alternate functions(ALT1 - ALTx) that directly connect the pin to different hardware blocks. When a pin is in GPIO mode, Output Enable (OE), Open Drain(OD), and Pull Up (PU) are driven by the related PIO block. Otherwise the PIO multiplexing block configures these parameters and retiming the signal.
g> About driver:
Quoted 13 lines
This pinctrl driver manages both PIO and PIO-mux block using pinctrl, pinconf, pinmux, gpio subsystems. All the pinctrl related config information can only come from device trees.
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stephen Gallimore <[email protected]>CC Stuart Menefy <[email protected]>---
.../bindings/pinctrl/pinctrl-stixxxx.txt | 160 +++ drivers/pinctrl/Kconfig | 13 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-stixxxx.c | 1151 ++++++++++++++++++++ drivers/pinctrl/pinctrl-stixxxx.h | 197 ++++
Quoted 6 lines
Quoted 3 lines
the pinctrl is present in older SoC ST40 not only stixxx
and you must provide a proper name not stixxxx
The reason for giving it stixxxx name is all the set-top-box based SOCs have the naming convention of stixxxx like stih7108, stih415, stih416 and stig125.. and so on..
I known perfectly the ST SoCs for years (st20/st200 & co)
no you need to use the name of the first SoC using the IP
cf ePAR
Quoted 23 lines
Quoted 23 lines
Quoted 12 lines
5 files changed, 1522 insertions(+), 0 deletions(-)create mode 100644
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txtcreate mode 100644drivers/pinctrl/pinctrl-stixxxx.c
create mode 100644drivers/pinctrl/pinctrl-stixxxx.hDocumentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +0
-0Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 9
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +9
-0@@ -0,0 +1,160 @@ +*ST pin controller. + +Each multi-function pin is controlled, driven and routed through the +PIO multiplexing block. Each pin supports GPIO functionality (ALT0) +and multiple alternate functions(ALT1 - ALTx) that directly connect +the pin to different hardware blocks. + +When a pin is in GPIO mode, Output Enable (OE), Open Drain(OD), and +Pull Up (PU) are driven by the related PIO block.HighZ too
Quoted 4 lines
Quoted 2 lines
this driver look very similar with AT91 we should consolidate at binding and C level
Yes, it look very similar to at91, however they are very much different w.r.t pinconf.
that's why I said we need to consolidate
Quoted 32 lines
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 17
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +8
-1--- + +ST pinctrl driver controls PIO multiplexing block and also interacts with +gpio driver to configure a pin. + +Required properties: (PIO multiplexing block) +- compatible : should be "st,stixxxx-pinctrl" + each subnode should set "st,stixxxx-gpio" + as compatible for each gpio-controller bank.first soc where the IP is present
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt
Quoted 7 lines
+- gpio-controller : Indicates this device is a GPIO controller +- #gpio-cells : Should be one. The first cell is the pin number. +- #retime-delay-cells : Should be number of possible retime delays. +- st,retime-in-delay : Should be array of delays in nsecs. +- st,retime-out-delay : Should be array of delays in nsecs. +- retime-style : Should indicate which type of retime is used.Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +1
-0+ possible values are "none", "packed" and "dedicated".always prefix st, when specific property
st,Its a typo, will fix it.
Quoted 4 lines
Quoted 4 lines
+- st,retime-offset : phandle to retime offsets in retime registers.
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +3
-0+ These are not necessary for "dedicated" retime-style registers. + - clk1notclk0 : Should define offset for clk1not clk0 in retime register. + - delay-lsb : Should define offset for delay-lsb in retime register.Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 33
Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +5
-0+ - delay-msb : Should define offset for delay msb in retime register. + - invertclk : Should define offset for invertclk in retime register. + - retime : Should define offset for retime in retime register. + - clknotdata : Should define offset for clknotdata in retime register. + - double_edge : Should define offset for double edge in retime register.As much as I like to describe the IP in the DT, I think it's too much this time move this to C and use the compatible or detect it on the hardware to handle this
Quoted 1 line
That is a good idea.
cf at91 pinctrl
Quoted 87 lines
Quoted 58 lines
Quoted 58 lines
+- st,alt-control : Should be sysconf to control alternate function on pio. +- st,oe-control : Should be sysconf to control output enable on pio. +- st,pu-control : Should be sysconf to control pull up on pio. +- st,od-control : Should be sysconf to control open drain on pio. +- st,retime-style : Should indicate which type of retime is used.Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +51
-0+ possible values are "none", "packed" and "dedicated". +- st,retime-pin-mask : Should be mask to specify which pins can be retimed. +- retime-control[0...N]: These properties point to sysconfs which control retime. + Depending on retime-style the number of retime-controls + vary: 2 for "packed"; 8 for "dedicated". +- st,bank-name : Should be a name string for this bank. + +Example: + pio_retime_offset: pio-retime-offset { + clk1notclk0 = <0>; + delay-lsb = <2>; + delay-msb = <3>; + invertclk = <4>; + retime = <5>; + clknotdata = <6>; + double-edge = <7>; + }; + + pin-controller { + #retime-delay-cells = <4>; + compatible = "st,stixxxx-pinctrl", "simple-bus"; + st,retime-offset = <&pio_retime_offset>; + st,retime-in-delay = <0 500 1000 1500>; + st,retime-out-delay = <0 1000 2000 3000>; + ranges; + PIO0: pinctrl at fe610000 { + gpio-controller; + #gpio-cells = <1>; + compatible = "st,stixxxx-gpio"; + reg = <0xfe610000 0x100>; + st,bank-name = "PIO0"; + st,alt-control = <&SYSCONF_SBC(0) 0 31>; + st,oe-control = <&SYSCONF_SBC(5) 0 7>; + st,pu-control = <&SYSCONF_SBC(7) 0 7>; + st,od-control = <&SYSCONF_SBC(9) 0 7>; + st,retime-style = "packed"; + st,retime-pin-mask = <0xff>; + st,retime-control0 = <&SYSCONF_SBC(16) 0 31>; + st,retime-control1 = <&SYSCONF_SBC(17) 0 31>; + }; + ... + pin-functions nodes follow... + }; + + +Contents of function subnode node: +---------------------- +Required properties for pin configuration node: +- st,function : Should be alternate function number associated + with this set of pins. + possible altfunction values:Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 96
Quoted 7 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +7
-0+ ALT1 + ALT2 + ALT3 + ALT4 + ALT5 + ALT6 + ALT7use number in the DoC
Ok.
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +11
-0+ +- st,pins : Child node with list of pins with configuration. + +Below is the format of how each pin conf should look like. + +<bank offset mode rt_type rt_delay rt_clk> + +Every PIO is represented with 4-7 parameters depending on retime configuration. +Each parameter is explained as below. + +-bank : Should be bank phandle to which this PIO belongs.Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt line 114
Quoted 7 lines
+-offset : Offset in the PIO bank. +-mode :pin configuration is selected from one of the below values.Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +5
-0+ IN + IN_PU + OUT + BIDIR + BIDIR_PUditto
Quoted 3 lines
Actually these modes are top level defines of three different variables, OE, PU, OD used in the registers.
Its very common that driver might just be interested in one of listed modes.
we need to represent the value in the doc as the Macro was just introduce recently for the Kernel only It's not DT spec
Quoted 1,450 lines
Quoted 1,449 lines
Quoted 1,449 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-stixxxx.txt new file +46
-0+ +-rt_type Retiming Configuration for the pin. + Possible retime configuration are: + + ------- ------------- + value args + ------- ------------- + NICLK <delay> <clk> + ICLK_IO <delay> <clk> + BYPASS <delay> + DE_IO <delay> <clk> + SE_ICLK_IO <delay> <clk> + SE_NICLK_IO <delay> <clk> + +- delay is retime delay in pico seconds. + Possible values are: refer to retime-in/out-delays + +- rt_clk :clk to be use for retime. + Possible values are: + CLK_A + CLK_B + CLK_C + CLK_D + +Example of mmcclk pin which is a bi-direction pull pu with retime config +as non inverted clock retimed with CLK_B and delay of 0 pico seconds: + +pin-controller { + ... + mmc0 { + pinctrl_mmc: mmc { + st,function = <ALT4>; + st,pins { + mmcclk = <&PIO13 4 BIDIR_PU NICLK 0 CLK_B>; + ... + }; + }; + ... + }; +}; + +sdhci0:sdhci at fe810000{ + ... + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_mmc>; +};drivers/pinctrl/Kconfig +13
-0@@ -179,6 +179,19 @@ config PINCTRL_SUNXI select PINMUX select GENERIC_PINCONF +config PINCTRL_STIXXXX + bool "ST Microelectronics pin controller driver for STixxxx SoCs" + depends on PLAT_STIXXXX + select PINMUX + select PINCONF + select MFD_SYSCON + help + Say yes here to support pinctrl interface on STixxxx SOCs. + This driver is used to control both PIO block and PIO-mux + block to configure a pin. + + If unsure, say N. +config
PINCTRL_TEGRA
bool
select PINMUXdrivers/pinctrl/Makefile +0
-0@@ -47,6 +47,7 @@ obj-$(CONFIG_PINCTRL_EXYNOS) += pinctrl-exynos.oobj-$(CONFIG_PINCTRL_EXYNOS5440) += pinctrl-exynos5440.o
obj-$(CONFIG_PINCTRL_XWAY) += pinctrl-xway.o
obj-$(CONFIG_PINCTRL_LANTIQ) += pinctrl-lantiq.o
+obj-$(CONFIG_PINCTRL_STIXXXX) += pinctrl-stixxxx.oobj-$(CONFIG_PLAT_ORION) += mvebu/
obj-$(CONFIG_ARCH_SHMOBILE) += sh-pfc/drivers/pinctrl/pinctrl-stixxxx.c new file +1151
-0@@ -0,0 +1,1151 @@ +/* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Authors: +* Srinivas Kandagatla <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#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/mfd/syscon.h> +#include <linux/pinctrl/pinctrl.h> +#include <linux/pinctrl/pinmux.h> +#include <linux/pinctrl/pinconf.h> +#include <linux/platform_device.h> +#include "core.h" +#include "pinctrl-stixxxx.h" + +struct stixxxx_pinconf { +int pin; +const char *name; +unsigned long config; +}; + +struct stixxxx_pmx_func { +const char *name; +const char **groups; +unsigned ngroups; +}; + +struct stixxxx_pctl_group { +const char *name; +unsigned int *pins; +unsigned npins; +int altfunc; +struct stixxxx_pinconf *pin_conf; +}; + +#define to_stixxxx_gpio_port (chip) \ + container_of(chip, struct stixxxx_gpio_port, gpio_chip) + +struct stixxxx_gpio_port { +struct gpio_chip gpio_chip; +struct pinctrl_gpio_range range; +void __iomem *base; +struct device_node *of_node; +const char *bank_name; +}; + +static struct stixxxx_gpio_port *gpio_ports[STIXXXX_MAX_GPIO_BANKS ]; + +struct stixxxx_pinctrl { +struct device *dev; +struct pinctrl_dev *pctl; +int nbanks; +struct stixxxx_pmx_func *functions; +int nfunctions; +struct stixxxx_pctl_group *groups; +int ngroups; +struct stixxxx_pio_control *pio_controls; +}; + +/* Low level functions.. */ +static void stixxxx_pinconf_set_direction (struct stixxxx_pio_control *pc, +int pin_id,unsigned long config) +{ +struct syscon_field *output_enable; +struct syscon_field *pull_up; +struct syscon_field *open_drain; +unsigned long oe_value, pu_value, od_value; +unsigned long mask; +int pin =stixxxx_gpio_pin (pin_id); + + output_enable = pc->oe; + pull_up = pc->pu; + open_drain = pc->od; + + mask =BIT (pin); + + oe_value =syscon_read (output_enable); + pu_value =syscon_read (pull_up); + od_value =syscon_read (open_drain); + +/* Clear old values */ + oe_value &= ~mask; + pu_value &= ~mask; + od_value &= ~mask; + +if (config &STIXXXX_PINCONF_OE ) + oe_value |= mask; +if (config &STIXXXX_PINCONF_PU ) + pu_value |= mask; +if (config &STIXXXX_PINCONF_OD ) + od_value |= mask; + +syscon_write (output_enable, oe_value); +syscon_write (pull_up, pu_value); +syscon_write (open_drain, od_value); +} + +static void stixxxx_pctl_set_function (struct stixxxx_pio_control *pc, +int pin_id,int function) +{ +struct syscon_field *selector; +int offset; +unsigned long val; +int pin =stixxxx_gpio_pin (pin_id); + + selector = pc->alt; + offset = pin *4 ; + val =syscon_read (selector); + val &= ~(0xf << offset); + val |= function << offset; +syscon_write (selector, val); +} + +static unsigned long stixxxx_pinconf_delay_to_bit (unsigned int delay, +const struct stixxxx_retime_params *rt_params, +unsigned long config) +{ +unsigned int *delay_times; +int num_delay_times, i, closest_index =-1 ; +unsigned int closest_divergence =UINT_MAX ; + +if (STIXXXX_PINCONF_UNPACK_OE (config)) { + delay_times = rt_params->delay_times_out; + num_delay_times = rt_params->num_delay_times_out; + }else { + delay_times = rt_params->delay_times_in; + num_delay_times = rt_params->num_delay_times_in; + } + +for (i =0 ; i < num_delay_times; i++) { +unsigned int divergence =abs (delay - delay_times[i]); + +if (divergence ==0 ) +return i; + +if (divergence < closest_divergence) { + closest_divergence = divergence; + closest_index = i; + } + } + +pr_warn ("Attempt to set delay %d, closest available %d\n" , + delay, delay_times[closest_index]); + +return closest_index; +} + +static unsigned long stixxxx_pinconf_bit_to_delay (unsigned int index, +const struct stixxxx_retime_params *rt_params, +unsigned long output) +{ +unsigned int *delay_times; +int num_delay_times; + +if (output) { + delay_times = rt_params->delay_times_out; + num_delay_times = rt_params->num_delay_times_out; + }else { + delay_times = rt_params->delay_times_in; + num_delay_times = rt_params->num_delay_times_in; + } + +if (index < num_delay_times) { +return delay_times[index]; + }else { +pr_warn ("Delay not found in/out delay list\n" ); +return 0 ; + } +} + +static void stixxxx_pinconf_set_retime_packed ( +struct stixxxx_pio_control *pc, +unsigned long config,int pin) +{ +const struct stixxxx_retime_params *rt_params = pc->rt_params; +const struct stixxxx_retime_offset *offset = rt_params->retime_offset; +struct syscon_field **regs; +unsigned long values[2 ]; +unsigned long mask; +int i, j; +int clk =STIXXXX_PINCONF_UNPACK_RT_CLK (config); +int clknotdata =STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config); +int double_edge =STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config); +int invertclk =STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config); +int retime =STIXXXX_PINCONF_UNPACK_RT (config); +unsigned long delay =stixxxx_pinconf_delay_to_bit ( +STIXXXX_PINCONF_UNPACK_RT_DELAY (config), + pc->rt_params, config); + +unsigned long rt_cfg = + ((clk &1 ) << offset->clk1notclk0_offset) | + ((clknotdata &1 ) << offset->clknotdata_offset) | + ((delay &1 ) << offset->delay_lsb_offset) | + (((delay >>1 ) &1 ) << offset->delay_msb_offset) | + ((double_edge &1 ) << offset->double_edge_offset) | + ((invertclk &1 ) << offset->invertclk_offset) | + ((retime &1 ) << offset->retime_offset); + + regs = pc->retiming; + values[0 ] =syscon_read (regs[0 ]); + values[1 ] =syscon_read (regs[1 ]); + +for (i =0 ; i <2 ; i++) { + mask =BIT (pin); +for (j =0 ; j <4 ; j++) { +if (rt_cfg &1 ) + values[i] |= mask; +else + values[i] &= ~mask; + mask <<=8 ; + rt_cfg >>=1 ; + } + } + +syscon_write (regs[0 ], values[0 ]); +syscon_write (regs[1 ], values[1 ]); +} + +static void stixxxx_pinconf_set_retime_dedicated ( +struct stixxxx_pio_control *pc, +unsigned long config,int pin) +{ +struct syscon_field *reg; +int input =STIXXXX_PINCONF_UNPACK_OE (config) ?0 :1 ; +int clk =STIXXXX_PINCONF_UNPACK_RT_CLK (config); +int clknotdata =STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config); +int double_edge =STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config); +int invertclk =STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config); +int retime =STIXXXX_PINCONF_UNPACK_RT (config); +unsigned long delay =stixxxx_pinconf_delay_to_bit ( +STIXXXX_PINCONF_UNPACK_RT_DELAY (config), + pc->rt_params, config); + +unsigned long retime_config = + ((clk &0x3 ) <<0 ) | + ((clknotdata &0x1 ) <<2 ) | + ((delay &0xf ) <<3 ) | + ((input &0x1 ) <<7 ) | + ((double_edge &0x1 ) <<8 ) | + ((invertclk &0x1 ) <<9 ) | + ((retime &0x1 ) <<10 ); + + reg = pc->retiming[pin]; +syscon_write (reg, retime_config); +} + +static void stixxxx_pinconf_get_direction (struct stixxxx_pio_control *pc, +int pin_id,unsigned long *config) +{ +unsigned long oe_value, pu_value, od_value; +int pin =stixxxx_gpio_pin (pin_id); + + oe_value = (syscon_read (pc->oe) >> pin) &1 ; + pu_value = (syscon_read (pc->pu) >> pin) &1 ; + od_value = (syscon_read (pc->od) >> pin) &1 ; + +STIXXXX_PINCONF_PACK_OE (*config, oe_value); +STIXXXX_PINCONF_PACK_PU (*config, pu_value); +STIXXXX_PINCONF_PACK_OD (*config, od_value); +} + +static int stixxxx_pinconf_get_retime_packed ( +struct stixxxx_pio_control *pc, +int pin,unsigned long *config) +{ +const struct stixxxx_retime_params *rt_params = pc->rt_params; +const struct stixxxx_retime_offset *offset = rt_params->retime_offset; +unsigned long delay_bits, delay, rt_reduced; +unsigned long rt_value[2 ]; +int i, j; +int output =STIXXXX_PINCONF_UNPACK_OE (*config); + + rt_value[0 ] =syscon_read (pc->retiming[0 ]); + rt_value[1 ] =syscon_read (pc->retiming[1 ]); + + rt_reduced =0 ; +for (i =0 ; i <2 ; i++) { +for (j =0 ; j <4 ; j++) { +if (rt_value[i] & (1 <<((8 *j)+pin))) + rt_reduced |=1 << ((i*4 )+j); + } + } + +STIXXXX_PINCONF_PACK_RT (*config, + (rt_reduced >> offset->retime_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_CLK (*config, + (rt_reduced >> offset->clk1notclk0_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (*config, + (rt_reduced >> offset->clknotdata_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (*config, + (rt_reduced >> offset->double_edge_offset) &1 ); +STIXXXX_PINCONF_PACK_RT_INVERTCLK (*config, + (rt_reduced >> offset->invertclk_offset) &1 ); + + delay_bits = (((rt_reduced >> offset->delay_msb_offset) &1 )<<1 ) | + ((rt_reduced >> offset->delay_lsb_offset) &1 ); + delay =stixxxx_pinconf_bit_to_delay (delay_bits, rt_params, output); +STIXXXX_PINCONF_PACK_RT_DELAY (*config, delay); +return 0 ; +} + +static int stixxxx_pinconf_get_retime_dedicated ( +struct stixxxx_pio_control *pc, +int pin,unsigned long *config) +{ +unsigned long value; +unsigned long delay_bits, delay; +const struct stixxxx_retime_params *rt_params = pc->rt_params; +int output =STIXXXX_PINCONF_UNPACK_OE (*config); + + value =syscon_read (pc->retiming[pin]); +STIXXXX_PINCONF_PACK_RT_CLK (*config, ((value >>0 ) &0x3 )); +STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (*config, ((value >>2 ) &0x1 )); + delay_bits = ((value >>3 ) &0xf ); + delay =stixxxx_pinconf_bit_to_delay (delay_bits, rt_params, output); +STIXXXX_PINCONF_PACK_RT_DELAY (*config, delay); +STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (*config, ((value >>8 ) &0x1 )); +STIXXXX_PINCONF_PACK_RT_INVERTCLK (*config, ((value >>9 ) &0x1 )); +STIXXXX_PINCONF_PACK_RT (*config, ((value >>10 ) &0x1 )); + +return 0 ; +} + +/* GPIO related functions */ + +static inline void __stixxxx_gpio_set (struct stixxxx_gpio_port *port, +unsigned offset,int value) +{ +if (value) +writel (BIT (offset), port->base +REG_PIO_SET_POUT ); +else +writel (BIT (offset), port->base +REG_PIO_CLR_POUT ); +} + +static void stixxxx_gpio_direction (unsigned int gpio,unsigned int direction) +{ +int port_num =stixxxx_gpio_port (gpio); +int offset =stixxxx_gpio_pin (gpio); +struct stixxxx_gpio_port *port = gpio_ports[port_num]; +int i =0 ; + +for (i =0 ; i <=2 ; i++) { +if (direction &BIT (i)) +writel (BIT (offset), port->base +REG_PIO_SET_PC (i)); +else +writel (BIT (offset), port->base +REG_PIO_CLR_PC (i)); + } +} + +static int stixxxx_gpio_request (struct gpio_chip *chip,unsigned offset) +{ +return pinctrl_request_gpio (chip->base + offset); +} + +static void stixxxx_gpio_free (struct gpio_chip *chip,unsigned offset) +{ +pinctrl_free_gpio (chip->base + offset); +} + +static int stixxxx_gpio_get (struct gpio_chip *chip,unsigned offset) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); + +return (readl (port->base +REG_PIO_PIN ) >> offset) &1 ; +} + +static void stixxxx_gpio_set (struct gpio_chip *chip,unsigned offset,int value) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); +__stixxxx_gpio_set (port, offset, value); +} + +static int stixxxx_gpio_direction_input (struct gpio_chip *chip,unsigned offset) +{ +pinctrl_gpio_direction_input (chip->base + offset); +return 0 ; +} + +static int stixxxx_gpio_direction_output (struct gpio_chip *chip, +unsigned offset,int value) +{ +struct stixxxx_gpio_port *port =to_stixxxx_gpio_port (chip); + +__stixxxx_gpio_set (port, offset, value); +pinctrl_gpio_direction_output (chip->base + offset); + +return 0 ; +} + +static int stixxxx_gpio_xlate (struct gpio_chip *gc, +const struct of_phandle_args *gpiospec,u32 *flags) +{ +if (WARN_ON (gc->of_gpio_n_cells <1 )) +return -EINVAL ; + +if (WARN_ON (gpiospec->args_count < gc->of_gpio_n_cells)) +return -EINVAL ; + +if (gpiospec->args[0 ] > gc->ngpio) +return -EINVAL ; + +return gpiospec->args[0 ]; +} + +/* Pinctrl Groups */ +static int stixxxx_pctl_get_groups_count (struct pinctrl_dev *pctldev) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->ngroups; +} + +static const char *stixxxx_pctl_get_group_name (struct pinctrl_dev *pctldev, +unsigned selector) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->groups[selector].name; +} + +static int stixxxx_pctl_get_group_pins (struct pinctrl_dev *pctldev, +unsigned selector,const unsigned **pins,unsigned *npins) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +if (selector >= info->ngroups) +return -EINVAL ; + + *pins = info->groups[selector].pins; + *npins = info->groups[selector].npins; + +return 0 ; +} + +static const inline struct stixxxx_pctl_group *stixxxx_pctl_find_group_by_name ( +const struct stixxxx_pinctrl *info,const char *name) +{ +int i; + +for (i =0 ; i < info->ngroups; i++) { +if (!strcmp (info->groups[i].name, name)) +return &info->groups[i]; + } + +return NULL ; +} + +static int stixxxx_pctl_dt_node_to_map (struct pinctrl_dev *pctldev, +struct device_node *np,struct pinctrl_map **map,unsigned *num_maps) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +const struct stixxxx_pctl_group *grp; +struct pinctrl_map *new_map; +struct device_node *parent; +int map_num, i; + + grp =stixxxx_pctl_find_group_by_name (info, np->name); +if (!grp) { +dev_err (info->dev,"unable to find group for node %s\n" , + np->name); +return -EINVAL ; + } + + map_num = grp->npins +1 ; + new_map =devm_kzalloc (pctldev->dev, +sizeof (*new_map) * map_num,GFP_KERNEL ); +if (!new_map) +return -ENOMEM ; + + parent =of_get_parent (np); +if (!parent) { +devm_kfree (pctldev->dev, new_map); +return -EINVAL ; + } + + *map = new_map; + *num_maps = map_num; + new_map[0 ].type =PIN_MAP_TYPE_MUX_GROUP ; + new_map[0 ].data.mux.function = parent->name; + new_map[0 ].data.mux.group = np->name; +of_node_put (parent); + +/* create config map per pin */ + new_map++; +for (i =0 ; i < grp->npins; i++) { + new_map[i].type =PIN_MAP_TYPE_CONFIGS_PIN ; + new_map[i].data.configs.group_or_pin = +pin_get_name (pctldev, grp->pins[i]); + new_map[i].data.configs.configs = &grp->pin_conf[i].config; + new_map[i].data.configs.num_configs =1 ; + } +dev_info (pctldev->dev,"maps: function %s group %s num %d\n" , + (*map)->data.mux.function, grp->name, map_num); + +return 0 ; +} + +static void stixxxx_pctl_dt_free_map (struct pinctrl_dev *pctldev, +struct pinctrl_map *map,unsigned num_maps) +{ +} + +static struct pinctrl_ops stixxxx_pctlops = { + .get_groups_count = stixxxx_pctl_get_groups_count, + .get_group_pins = stixxxx_pctl_get_group_pins, + .get_group_name = stixxxx_pctl_get_group_name, + .dt_node_to_map = stixxxx_pctl_dt_node_to_map, + .dt_free_map = stixxxx_pctl_dt_free_map, +}; + +/* Pinmux */ +static int stixxxx_pmx_get_funcs_count (struct pinctrl_dev *pctldev) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->nfunctions; +} + +const char *stixxxx_pmx_get_fname (struct pinctrl_dev *pctldev, +unsigned selector) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + +return info->functions[selector].name; +} + +static int stixxxx_pmx_get_groups (struct pinctrl_dev *pctldev, +unsigned selector,const char *const **grps,unsigned *const ngrps) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); + *grps = info->functions[selector].groups; + *ngrps = info->functions[selector].ngroups; + +return 0 ; +} + +static struct stixxxx_pio_control *stixxxx_get_pio_control ( +struct stixxxx_pinctrl *info,int pin_id) +{ +int port =stixxxx_gpio_port (pin_id); +return &info->pio_controls[port]; +} + +static int stixxxx_pmx_enable (struct pinctrl_dev *pctldev,unsigned fselector, +unsigned group) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pinconf *conf = info->groups[group].pin_conf; +struct stixxxx_pio_control *pc; +int i; + +for (i =0 ; i < info->groups[group].npins; i++) { + pc =stixxxx_get_pio_control (info, conf[i].pin); +stixxxx_pctl_set_function (pc, conf[i].pin, + info->groups[group].altfunc); + } + +return 0 ; +} + +static void stixxxx_pmx_disable (struct pinctrl_dev *pctldev,unsigned selector, +unsigned group) +{ +} + +static int stixxxx_pmx_set_gpio_direction (struct pinctrl_dev *pctldev, +struct pinctrl_gpio_range *range,unsigned gpio, +bool input) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc = &info->pio_controls[range->id]; +/* +* When a PIO port is used in its primary function mode (altfunc = 0) +* Output Enable (OE), Open Drain(OD), and Pull Up (PU) +* for the primary PIO functions are driven by the related PIO block +*/ +stixxxx_pctl_set_function (pc, gpio,0 ); +stixxxx_gpio_direction (gpio, input ? +STIXXXX_GPIO_DIRECTION_IN :STIXXXX_GPIO_DIRECTION_OUT ); + +return 0 ; +} + +static struct pinmux_ops stixxxx_pmxops = { + .get_functions_count = stixxxx_pmx_get_funcs_count, + .get_function_name = stixxxx_pmx_get_fname, + .get_function_groups = stixxxx_pmx_get_groups, + .enable = stixxxx_pmx_enable, + .disable = stixxxx_pmx_disable, + .gpio_set_direction = stixxxx_pmx_set_gpio_direction, +}; + +/* Pinconf */ +static void stixxxx_pinconf_get_retime (struct stixxxx_pio_control *pc, +int pin_id,unsigned long *config) +{ +int pin =stixxxx_gpio_pin (pin_id); +if (pc->rt_style == stixxxx_retime_style_packed) +stixxxx_pinconf_get_retime_packed (pc, pin, config); +else if (pc->rt_style == stixxxx_retime_style_dedicated) +if ((BIT (pin) & pc->rt_pin_mask)) +stixxxx_pinconf_get_retime_dedicated (pc, pin, config); +} + +static void stixxxx_pinconf_set_retime (struct stixxxx_pio_control *pc, +int pin_id,unsigned long config) +{ +int pin =stixxxx_gpio_pin (pin_id); + +if (pc->rt_style == stixxxx_retime_style_packed) +stixxxx_pinconf_set_retime_packed (pc, config, pin); +else if (pc->rt_style == stixxxx_retime_style_dedicated) +if ((BIT (pin) & pc->rt_pin_mask)) +stixxxx_pinconf_set_retime_dedicated (pc, config, pin); +} + +static int stixxxx_pinconf_set (struct pinctrl_dev *pctldev, +unsigned pin_id,unsigned long config) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc =stixxxx_get_pio_control (info, pin_id); + +stixxxx_pinconf_set_direction (pc, pin_id, config); +stixxxx_pinconf_set_retime (pc, pin_id, config); +return 0 ; +} + +static int stixxxx_pinconf_get (struct pinctrl_dev *pctldev, +unsigned pin_id,unsigned long *config) +{ +struct stixxxx_pinctrl *info =pinctrl_dev_get_drvdata (pctldev); +struct stixxxx_pio_control *pc =stixxxx_get_pio_control (info, pin_id); + + *config =0 ; +stixxxx_pinconf_get_direction (pc, pin_id, config); +stixxxx_pinconf_get_retime (pc, pin_id, config); + +return 0 ; +} + +static void stixxxx_pinconf_dbg_show (struct pinctrl_dev *pctldev, +struct seq_file *s,unsigned pin_id) +{ +unsigned long config; +stixxxx_pinconf_get (pctldev, pin_id, &config); + +seq_printf (s,"[OE:%ld,PU:%ld,OD:%ld]\n" +"\t\t[retime:%ld,invclk:%ld,clknotdat:%ld," +"de:%ld,rt-clk:%ld,rt-delay:%ld]" , +STIXXXX_PINCONF_UNPACK_OE (config), +STIXXXX_PINCONF_UNPACK_PU (config), +STIXXXX_PINCONF_UNPACK_OD (config), +STIXXXX_PINCONF_UNPACK_RT (config), +STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (config), +STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (config), +STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (config), +STIXXXX_PINCONF_UNPACK_RT_CLK (config), +STIXXXX_PINCONF_UNPACK_RT_DELAY (config)); +} + +static struct pinconf_ops stixxxx_confops = { + .pin_config_get = stixxxx_pinconf_get, + .pin_config_set = stixxxx_pinconf_set, + .pin_config_dbg_show = stixxxx_pinconf_dbg_show, +}; + +/* pinctrl */ +static struct pinctrl_desc stixxxx_pctl_desc = { + .owner =THIS_MODULE , + .pctlops = &stixxxx_pctlops, + .pmxops = &stixxxx_pmxops, + .confops = &stixxxx_confops, +}; + +static int stixxxx_pinconf_dt_parse_rt_params (struct stixxxx_pinctrl *info, +struct device_node *np,struct stixxxx_retime_params *params) +{ +const __be32 *ip; +struct device_node *offset_np; +struct stixxxx_retime_offset *rt_offset; +int delay_count =0 ; + + ip =of_get_property (np,"#retime-delay-cells" ,NULL ); +if (ip) + delay_count =be32_to_cpup (ip); +else +pr_warn ("No #retime-delay-cells specified\n" ); + + params->num_delay_times_out = delay_count; + params->num_delay_times_in = delay_count; + params->delay_times_in =devm_kzalloc (info->dev, +sizeof (u32) * delay_count,GFP_KERNEL ); + params->delay_times_out =devm_kzalloc (info->dev, +sizeof (u32) * delay_count,GFP_KERNEL ); + +if (!params->delay_times_in || !params->delay_times_out) +return -ENOMEM ; + +of_property_read_u32_array (np,"st,retime-in-delay" , + (u32 *)params->delay_times_in, delay_count); +of_property_read_u32_array (np,"st,retime-out-delay" , + (u32 *)params->delay_times_out, delay_count); + + offset_np =of_parse_phandle (np,"st,retime-offset" ,0 ); + +if (offset_np) { + rt_offset =devm_kzalloc (info->dev, +sizeof (*rt_offset),GFP_KERNEL ); +if (!rt_offset) +return -ENOMEM ; + + params->retime_offset = rt_offset; +WARN_ON (of_property_read_u32 (offset_np,"retime" , + &rt_offset->retime_offset)); +WARN_ON (of_property_read_u32 (offset_np,"clk1notclk0" , + &rt_offset->clk1notclk0_offset)); +WARN_ON (of_property_read_u32 (offset_np,"clknotdata" , + &rt_offset->clknotdata_offset)); +WARN_ON (of_property_read_u32 (offset_np,"double-edge" , + &rt_offset->double_edge_offset)); +WARN_ON (of_property_read_u32 (offset_np,"invertclk" , + &rt_offset->invertclk_offset)); +WARN_ON (of_property_read_u32 (offset_np,"delay-lsb" , + &rt_offset->delay_lsb_offset)); +WARN_ON (of_property_read_u32 (offset_np,"delay-msb" , + &rt_offset->delay_msb_offset)); + } + +return 0 ; +} + +static const char *gpio_compat ="st,stixxxx-gpio" ; + +static void stixxxx_pctl_dt_child_count (struct stixxxx_pinctrl *info, +struct device_node *np) +{ +struct device_node *child; +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { + info->nbanks++; + }else { + info->nfunctions++; + info->ngroups +=of_get_child_count (child); + } + } +} + +static int stixxxx_pctl_dt_get_retime_conf (struct device_node *np, +struct stixxxx_pio_control *pc) +{ +const char *style; +char name[20 ]; +unsigned int j; +of_property_read_string (np,"st,retime-style" , &style); + +if (strcmp (style,"packed" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_packed; +for (j =0 ; j <2 ; j++) { +snprintf (name,sizeof (name),"st,retime-control%d" , j); + pc->retiming[j] =syscon_claim (np, name); +if (!pc->retiming[j]) +return -ENODATA ; + } + }else if (strcmp (style,"dedicated" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_dedicated; +for (j =0 ; j <8 ; j++) { +if ((1 <<j) & pc->rt_pin_mask) { +snprintf (name,sizeof (name), +"st,retime-control%d" , j); + pc->retiming[j] =syscon_claim (np, name); +if (!pc->retiming[j]) +return -ENODATA ; + } + } + }else if (strcmp (style,"none" ) ==0 ) { + pc->rt_style = stixxxx_retime_style_none; + } + +return 0 ; +} + +static int stixxxx_pctl_dt_init (struct stixxxx_pinctrl *info, +struct device_node *np) +{ +struct stixxxx_pio_control *pc; +struct stixxxx_retime_params *rt_params; +struct device *dev = info->dev; +unsigned int i =0 ; +struct device_node *child =NULL ; + + pc =devm_kzalloc (dev,sizeof (*pc) * info->nbanks,GFP_KERNEL ); + rt_params =devm_kzalloc (dev,sizeof (*rt_params),GFP_KERNEL ); + +if (!pc || !rt_params) +return -ENOMEM ; + + info->pio_controls = pc; +if (stixxxx_pinconf_dt_parse_rt_params (info, np, rt_params)) +return -ENOMEM ; + +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { + pc[i].rt_params = rt_params; + + pc[i].alt =syscon_claim (child,"st,alt-control" ); +if (!pc[i].alt) + goto failed; + + pc[i].oe =syscon_claim (child,"st,oe-control" ); +if (!pc[i].oe) + goto failed; + + pc[i].pu =syscon_claim (child,"st,pu-control" ); +if (!pc[i].pu) + goto failed; + + pc[i].od =syscon_claim (child,"st,od-control" ); +if (!pc[i].od) + goto failed; + +of_property_read_u32 (child,"st,retime-pin-mask" , + &pc[i].rt_pin_mask); + +stixxxx_pctl_dt_get_retime_conf (child, &pc[i]); + i++; + } + } + +return 0 ; +failed: +return -ENODATA ; +} + +#define OF_GPIO_ARGS_MIN (3) +/* +* Each pin is represented in of the below forms. +* <bank offset direction func rt_type rt_delay rt_clk> +*/ +static int stixxxx_pctl_dt_parse_groups (struct device_node *np, +struct stixxxx_pctl_group *grp,struct stixxxx_pinctrl *info,int idx) +{ +/* bank pad direction val altfunction */ +const __be32 *list; +struct property *pp; +struct stixxxx_pinconf *conf; +phandle phandle; +struct device_node *pins; +u32 pin; +int i =0 , npins =0 , nr_props; + + pins =of_get_child_by_name (np,"st,pins" ); +if (!pins) +return -ENODATA ; + +for_each_property_of_node (pins, pp) { +/* Skip those we do not want to proceed */ +if (!strcmp (pp->name,"name" )) +continue ; + +if (pp && (pp->length/sizeof (__be32)) >=OF_GPIO_ARGS_MIN ) { + npins++; + }else { +pr_warn ("Invalid st,pins in %s node\n" , np->name); +return -EINVAL ; + } + } + + grp->npins = npins; + grp->name = np->name; + grp->pins =devm_kzalloc (info->dev, npins *sizeof (u32),GFP_KERNEL ); + grp->pin_conf =devm_kzalloc (info->dev, + npins *sizeof (*conf),GFP_KERNEL ); +of_property_read_u32 (np,"st,function" , &grp->altfunc); + +if (!grp->pins || !grp->pin_conf) +return -ENOMEM ; + +/* <bank offset direction func rt_type rt_delay rt_clk> */ +for_each_property_of_node (pins, pp) { +if (!strcmp (pp->name,"name" )) +continue ; + nr_props = pp->length/sizeof (u32); + list = pp->value; + conf = &grp->pin_conf[i]; + +/* bank & offset */ + phandle =be32_to_cpup (list++); + pin =be32_to_cpup (list++); + conf->pin =of_get_named_gpio (pins, pp->name,0 ); + conf->name = pp->name; + grp->pins[i] = conf->pin; + + conf->config =0 ; +/* direction */ + conf->config |=be32_to_cpup (list++); +/* rt_type rt_delay rt_clk */ +if (nr_props >=OF_GPIO_ARGS_MIN +2 ) { +/* rt_type */ + conf->config |=be32_to_cpup (list++); +/* rt_delay */ + conf->config |=be32_to_cpup (list++); +/* rt_clk */ +if (nr_props >OF_GPIO_ARGS_MIN +2 ) + conf->config |=be32_to_cpup (list++); + } + i++; + } +of_node_put (pins); + +return 0 ; +} + +static int stixxxx_pctl_parse_functions (struct device_node *np, +struct stixxxx_pinctrl *info,u32 index,int *grp_index) +{ +struct device_node *child; +struct stixxxx_pmx_func *func; +struct stixxxx_pctl_group *grp; +int ret, i; + + func = &info->functions[index]; + func->name = np->name; + func->ngroups =of_get_child_count (np); +if (func->ngroups <=0 ) { +dev_err (info->dev,"No groups defined\n" ); +return -EINVAL ; + } + func->groups =devm_kzalloc (info->dev, + func->ngroups *sizeof (char *),GFP_KERNEL ); +if (!func->groups) +return -ENOMEM ; + + i =0 ; +for_each_child_of_node (np, child) { + func->groups[i] = child->name; + grp = &info->groups[*grp_index]; + *grp_index +=1 ; + ret =stixxxx_pctl_dt_parse_groups (child, grp, info, i++); +if (ret) +return ret; + } +dev_info (info->dev,"Function[%d\t name:%s,\tgroups:%d]\n" , + index, func->name, func->ngroups); + +return 0 ; +} + +static int stixxxx_pctl_probe_dt (struct platform_device *pdev, +struct stixxxx_pinctrl *info) +{ +int ret =0 ; +int i =0 , j =0 , k =0 ; +struct pinctrl_pin_desc *pdesc; +struct device_node *np = pdev->dev.of_node; +struct device_node *child; +int grp_index =0 ; + +stixxxx_pctl_dt_child_count (info, np); +if (info->nbanks <1 ) { +dev_err (&pdev->dev,"you need atleast one gpio bank\n" ); +return -EINVAL ; + } + + ret =stixxxx_pctl_dt_init (info, np); +if (ret) +return ret; + +dev_info (&pdev->dev,"nbanks = %d\n" , info->nbanks); +dev_info (&pdev->dev,"nfunctions = %d\n" , info->nfunctions); +dev_info (&pdev->dev,"ngroups = %d\n" , info->ngroups); + info->functions =devm_kzalloc (&pdev->dev, + info->nfunctions *sizeof (*info->functions),GFP_KERNEL ); + + info->groups =devm_kzalloc (&pdev->dev, + info->ngroups *sizeof (*info->groups) ,GFP_KERNEL ); + +if (!info->functions || !info->groups) +return -ENOMEM ; + + stixxxx_pctl_desc.npins = info->nbanks *STIXXXX_GPIO_PINS_PER_PORT ; + pdesc =devm_kzalloc (&pdev->dev, +sizeof (*pdesc) * stixxxx_pctl_desc.npins,GFP_KERNEL ); +if (!pdesc) +return -ENOMEM ; + + stixxxx_pctl_desc.pins = pdesc; + +for_each_child_of_node (np, child) { +if (of_device_is_compatible (child, gpio_compat)) { +for (j =0 ; j <STIXXXX_GPIO_PINS_PER_PORT ; j++, k++) { +const char *port_name =NULL ; + pdesc->number = k; +of_property_read_string (child,"st,bank-name" , + &port_name); + pdesc->name =kasprintf (GFP_KERNEL ,"%s[%d]" , + port_name ? :"PIO" , + port_name ? j : k); + pdesc++; + } + }else { + ret =stixxxx_pctl_parse_functions (child, info, + i++, &grp_index); +if (ret) { +dev_err (&pdev->dev,"No functions found.\n" ); +return ret; + } + } + } + +return 0 ; +} + +static int stixxxx_pctl_probe (struct platform_device *pdev) +{ +struct stixxxx_pinctrl *info; +int ret, i; + +if (!pdev->dev.of_node) { +dev_err (&pdev->dev,"device node not found.\n" ); +return -EINVAL ; + } + + info =devm_kzalloc (&pdev->dev,sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + info->dev = &pdev->dev; +platform_set_drvdata (pdev, info); + ret =stixxxx_pctl_probe_dt (pdev, info); +if (ret) +return ret; + + stixxxx_pctl_desc.name =dev_name (&pdev->dev); + info->pctl =pinctrl_register (&stixxxx_pctl_desc, &pdev->dev, info); +if (IS_ERR (info->pctl)) { +dev_err (&pdev->dev,"Failed pinctrl registration\n" ); +return PTR_ERR (info->pctl); + } + +for (i =0 ; i < info->nbanks; i++) +pinctrl_add_gpio_range (info->pctl, &gpio_ports[i]->range); + +return 0 ; +} + +static struct gpio_chip stixxxx_gpio_template = { + .request = stixxxx_gpio_request, + .free = stixxxx_gpio_free, + .get = stixxxx_gpio_get, + .set = stixxxx_gpio_set, + .direction_input = stixxxx_gpio_direction_input, + .direction_output = stixxxx_gpio_direction_output, + .ngpio =STIXXXX_GPIO_PINS_PER_PORT , + .of_gpio_n_cells =1 , + .of_xlate = stixxxx_gpio_xlate, +}; + +static int stixxxx_gpio_probe (struct platform_device *pdev) +{ +struct stixxxx_gpio_port *port; +struct pinctrl_gpio_range *range; +struct device_node *np = pdev->dev.of_node; +int port_num =of_alias_get_id (np,"gpio" ); +struct resource *res; +int err; + + port =devm_kzalloc (&pdev->dev,sizeof (*port),GFP_KERNEL ); +if (!port) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + port->base =devm_request_and_ioremap (&pdev->dev, res); +if (!port->base) { +dev_err (&pdev->dev,"Can't get IO memory mapping!\n" ); +return -ENODEV ; + } + +of_property_read_string (np,"st,bank-name" , &port->bank_name); + port->of_node = np; + + port->gpio_chip = stixxxx_gpio_template; + port->gpio_chip.base = port_num *STIXXXX_GPIO_PINS_PER_PORT ; + port->gpio_chip.ngpio =STIXXXX_GPIO_PINS_PER_PORT ; + port->gpio_chip.of_node = np; + port->gpio_chip.label =dev_name (&pdev->dev); + +dev_set_drvdata (&pdev->dev, port); + range = &port->range; + range->name = port->gpio_chip.label; + range->id = port_num; + range->pin_base = range->base = range->id *STIXXXX_GPIO_PINS_PER_PORT ; + range->npins = port->gpio_chip.ngpio; + range->gc = &port->gpio_chip; + gpio_ports[port_num] = port; + err =gpiochip_add (&port->gpio_chip); +if (err) { +dev_err (&pdev->dev,"Failed to add gpiochip(%d)!\n" , port_num); +return err; + } +dev_info (&pdev->dev,"gpioport[%s] Added as bank%d\n" , + port->bank_name, port_num); +return 0 ; +} + +static struct of_device_id stixxxx_gpio_of_match[] = { + { .compatible ="st,stixxxx-gpio" , }, + {/* sentinel */ } +}; + +static struct platform_driver stixxxx_gpio_driver = { + .driver = { + .name ="st-gpio" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (stixxxx_gpio_of_match), + }, + .probe = stixxxx_gpio_probe, +}; + +static struct of_device_id stixxxx_pctl_of_match[] = { + { .compatible ="st,stixxxx-pinctrl" ,}, + {/* sentinel */ } +}; + +static struct platform_driver stixxxx_pctl_driver = { + .driver = { + .name ="st-pinctrl" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (stixxxx_pctl_of_match), + }, + .probe = stixxxx_pctl_probe, +}; + +static int __init stixxxx_pctl_init (void ) +{ +int ret =platform_driver_register (&stixxxx_gpio_driver); +if (ret) +return ret; +return platform_driver_register (&stixxxx_pctl_driver); +} +arch_initcall (stixxxx_pctl_init);drivers/pinctrl/pinctrl-stixxxx.h new file +197
-0@@ -0,0 +1,197 @@ + +/* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Authors: +* Srinivas Kandagatla <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +*/ + +#ifndef __LINUX_DRIVERS_PINCTRL_STIXXXX_H +#define __LINUX_DRIVERS_PINCTRL_STIXXXX_H + +enum stixxxx_retime_style { + stixxxx_retime_style_none, + stixxxx_retime_style_packed, + stixxxx_retime_style_dedicated, +}; + +/* Byte positions in 2 syscon words, starts from 0 */ +struct stixxxx_retime_offset { +int retime_offset; +int clk1notclk0_offset; +int clknotdata_offset; +int double_edge_offset; +int invertclk_offset; +int delay_lsb_offset; +int delay_msb_offset; +}; + +struct stixxxx_retime_params { +const struct stixxxx_retime_offset *retime_offset; +unsigned int *delay_times_in; +int num_delay_times_in; +unsigned int *delay_times_out; +int num_delay_times_out; +}; + +struct stixxxx_pio_control { +enum stixxxx_retime_style rt_style; +u32 rt_pin_mask; +const struct stixxxx_retime_params *rt_params; +struct syscon_field *alt; +struct syscon_field *oe, *pu, *od; +struct syscon_field *retiming[8 ]; +}; + +/* PIO Block registers */ +/* PIO output */ +#define REG_PIO_POUT 0x00 +/* Set bits of POUT */ +#define REG_PIO_SET_POUT 0x04 +/* Clear bits of POUT */ +#define REG_PIO_CLR_POUT 0x08 +/* PIO input */ +#define REG_PIO_PIN 0x10 +/* PIO configuration */ +#define REG_PIO_PC (n) (0x20 + (n) * 0x10) +/* Set bits of PC[2:0] */ +#define REG_PIO_SET_PC (n) (0x24 + (n) * 0x10) +/* Clear bits of PC[2:0] */ +#define REG_PIO_CLR_PC (n) (0x28 + (n) * 0x10) +/* PIO input comparison */ +#define REG_PIO_PCOMP 0x50 +/* Set bits of PCOMP */ +#define REG_PIO_SET_PCOMP 0x54 +/* Clear bits of PCOMP */ +#define REG_PIO_CLR_PCOMP 0x58 +/* PIO input comparison mask */ +#define REG_PIO_PMASK 0x60 +/* Set bits of PMASK */ +#define REG_PIO_SET_PMASK 0x64 +/* Clear bits of PMASK */ +#define REG_PIO_CLR_PMASK 0x68 + +#define STIXXXX_MAX_GPIO_BANKS 32 + +#define STIXXXX_GPIO_DIRECTION_BIDIR 0x1 +#define STIXXXX_GPIO_DIRECTION_OUT 0x2 +#define STIXXXX_GPIO_DIRECTION_IN 0x4 + +#define STIXXXX_GPIO_PINS_PER_PORT 8 +#define stixxxx_gpio_port (gpio) ((gpio) / STIXXXX_GPIO_PINS_PER_PORT) +#define stixxxx_gpio_pin (gpio) ((gpio) % STIXXXX_GPIO_PINS_PER_PORT) + +/* pinconf */ +/* +* Pinconf is represented in an opaque unsigned long variable. +* Below is the bit allocation details for each possible configuration. +* All the bit fields can be encapsulated into four variables +* (direction, retime-type, retime-clk, retime-delay) +* +* +----------------+ +*[31:28]| reserved-3 | +* +----------------+------------- +*[27] | oe | | +* +----------------+ v +*[26] | pu | [Direction ] +* +----------------+ ^ +*[25] | od | | +* +----------------+------------- +*[24] | reserved-2 | +* +----------------+------------- +*[23] | retime | | +* +----------------+ | +*[22] | retime-invclk | | +* +----------------+ v +*[21] |retime-clknotdat| [Retime-type ] +* +----------------+ ^ +*[20] | retime-de | | +* +----------------+------------- +*[19:18]| retime-clk |------>[Retime-Clk ] +* +----------------+ +*[17:16]| reserved-1 | +* +----------------+ +*[15..0]| retime-delay |------>[Retime Delay] +* +----------------+ +*/ + +#define STIXXXX_PINCONF_UNPACK (conf, param)\ + ((conf >> STIXXXX_PINCONF_ ##param ##_SHIFT) \ + & STIXXXX_PINCONF_ ##param ##_MASK) + +#define STIXXXX_PINCONF_PACK (conf, val, param) (conf |=\ + ((val & STIXXXX_PINCONF_ ##param ##_MASK) << \ + STIXXXX_PINCONF_ ##param ##_SHIFT)) + +/* Output enable */ +#define STIXXXX_PINCONF_OE_MASK 0x1 +#define STIXXXX_PINCONF_OE_SHIFT 27 +#define STIXXXX_PINCONF_OE BIT(27) +#define STIXXXX_PINCONF_UNPACK_OE (conf) STIXXXX_PINCONF_UNPACK(conf, OE) +#define STIXXXX_PINCONF_PACK_OE (conf, val) STIXXXX_PINCONF_PACK(conf, val, OE) + +/* Pull Up */ +#define STIXXXX_PINCONF_PU_MASK 0x1 +#define STIXXXX_PINCONF_PU_SHIFT 26 +#define STIXXXX_PINCONF_PU BIT(26) +#define STIXXXX_PINCONF_UNPACK_PU (conf) STIXXXX_PINCONF_UNPACK(conf, PU) +#define STIXXXX_PINCONF_PACK_PU (conf, val) STIXXXX_PINCONF_PACK(conf, val, PU) + +/* Open Drain */ +#define STIXXXX_PINCONF_OD_MASK 0x1 +#define STIXXXX_PINCONF_OD_SHIFT 25 +#define STIXXXX_PINCONF_OD BIT(25) +#define STIXXXX_PINCONF_UNPACK_OD (conf) STIXXXX_PINCONF_UNPACK(conf, OD) +#define STIXXXX_PINCONF_PACK_OD (conf, val) STIXXXX_PINCONF_PACK(conf, val, OD) + +#define STIXXXX_PINCONF_RT_MASK 0x1 +#define STIXXXX_PINCONF_RT_SHIFT 23 +#define STIXXXX_PINCONF_RT BIT(23) +#define STIXXXX_PINCONF_UNPACK_RT (conf) STIXXXX_PINCONF_UNPACK(conf, RT) +#define STIXXXX_PINCONF_PACK_RT (conf, val) STIXXXX_PINCONF_PACK(conf, val, RT) + +#define STIXXXX_PINCONF_RT_INVERTCLK_MASK 0x1 +#define STIXXXX_PINCONF_RT_INVERTCLK_SHIFT 22 +#define STIXXXX_PINCONF_RT_INVERTCLK BIT(22) +#define STIXXXX_PINCONF_UNPACK_RT_INVERTCLK (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_INVERTCLK) +#define STIXXXX_PINCONF_PACK_RT_INVERTCLK (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_INVERTCLK) + +#define STIXXXX_PINCONF_RT_CLKNOTDATA_MASK 0x1 +#define STIXXXX_PINCONF_RT_CLKNOTDATA_SHIFT 21 +#define STIXXXX_PINCONF_RT_CLKNOTDATA BIT(21) +#define STIXXXX_PINCONF_UNPACK_RT_CLKNOTDATA (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_CLKNOTDATA) +#define STIXXXX_PINCONF_PACK_RT_CLKNOTDATA (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_CLKNOTDATA) + +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE_MASK 0x1 +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE_SHIFT 20 +#define STIXXXX_PINCONF_RT_DOUBLE_EDGE BIT(20) +#define STIXXXX_PINCONF_UNPACK_RT_DOUBLE_EDGE (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_DOUBLE_EDGE) +#define STIXXXX_PINCONF_PACK_RT_DOUBLE_EDGE (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_DOUBLE_EDGE) + +#define STIXXXX_PINCONF_RT_CLK_MASK 0x3 +#define STIXXXX_PINCONF_RT_CLK_SHIFT 18 +#define STIXXXX_PINCONF_RT_CLK BIT(18) +#define STIXXXX_PINCONF_UNPACK_RT_CLK (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_CLK) +#define STIXXXX_PINCONF_PACK_RT_CLK (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_CLK) + +/* RETIME_DELAY in Pico Secs */ +#define STIXXXX_PINCONF_RT_DELAY_MASK 0xffff +#define STIXXXX_PINCONF_RT_DELAY_SHIFT 0 +#define STIXXXX_PINCONF_UNPACK_RT_DELAY (conf) \ + STIXXXX_PINCONF_UNPACK(conf, RT_DELAY) +#define STIXXXX_PINCONF_PACK_RT_DELAY (conf, val) \ + STIXXXX_PINCONF_PACK(conf, val, RT_DELAY) + +#endif /* __LINUX_DRIVERS_PINCTRL_STIXXXX_H */ Signature · 6 lines
1.7.6.5 _______________________________________________ devicetree-discuss mailing list devicetree-discuss at lists.ozlabs.org https://lists.ozlabs.org/listinfo/devicetree-discuss
RFC 2/8 ARM:global_timer: Add ARM global timer support.
In reply to Srinivas KANDAGATLAFrom: Stuart Menefy <[email protected]>
This is a simple driver for the global timer module found in the Cortex A9-MP cores from revision r1p0 onwards. This should be able to perform the functions of the system timer and the local timer in an SMP system.
The global timer has the following features:
The global timer is a 64-bit incrementing counter with an
auto-incrementing feature. It continues incrementing after sending interrupts. The global timer is memory mapped in the private memory region.
The global timer is accessible to all Cortex-A9 processors in the
cluster. Each Cortex-A9 processor has a private 64-bit comparator that is used to assert a private interrupt when the global timer has reached the comparator value. All the Cortex-A9 processors in a design use the banked ID, ID27, for this interrupt. ID27 is sent to the Interrupt Controller as a Private Peripheral Interrupt. The global timer is clocked by PERIPHCLK.
--- Documentation/devicetree/bindings/arm/gt.txt | 21 ++ arch/arm/Kconfig | 6 + arch/arm/include/asm/global_timer.h | 12 + arch/arm/kernel/Makefile | 1 + arch/arm/kernel/global_timer.c | 325 ++++++++++++++++++++++++++ 5 files changed, 365 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/gt.txt create mode 100644 arch/arm/include/asm/global_timer.h create mode 100644 arch/arm/kernel/global_timer.c
Documentation/devicetree/bindings/arm/gt.txt new file +21 -0
@@ -0,0 +1,21 @@ + +* ARM Global Timer + Cortex-A9 are often associated with a per-core Global timer. + +** Timer node required properties: + +- compatible : Should be one of: + "arm,cortex-a9-global-timer" + +- interrupts : One interrupt to each core + +- reg : Specify the base address and the size of the GT timer + register window. + +Example: + + gt-timer@2c000600 { + compatible = "arm,cortex-a9-global-timer"; + reg = <0x2c000600 0x20>; + interrupts = <1 13 0xf01>; + };
arch/arm/Kconfig +6 -0
@@ -1606,6 +1606,12 @@ config HAVE_ARM_TWD help This options enables support for the ARM timer and watchdog unit +config HAVE_ARM_GT + bool + select CLKSRC_OF if OF + help + This options enables support for the ARM global timer unit + choice prompt "Memory split" default VMSPLIT_3G
arch/arm/include/asm/global_timer.h new file +12 -0
@@ -0,0 +1,12 @@ +/* +* arch/arm/include/asm/global_timer.h +* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Author: Stuart Menefy <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +int __init global_timer_init (void __iomem *base,unsigned int timer_irq);
arch/arm/kernel/Makefile +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_ARM_CPU_SUSPEND) += sleep.o suspend.o obj-$(CONFIG_SMP) += smp.o smp_tlb.o obj-$(CONFIG_HAVE_ARM_SCU) += smp_scu.o obj-$(CONFIG_HAVE_ARM_TWD) += smp_twd.o +obj-$(CONFIG_HAVE_ARM_GT) += global_timer.o obj-$(CONFIG_ARM_ARCH_TIMER) += arch_timer.o obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o insn.o obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o insn.o
arch/arm/kernel/global_timer.c new file +325 -0
325 lines not on this page · raw message
Signature · 1 line
1.7.6.5
Re: [RFC 2/8] ARM:global_timer: Add ARM global timer support.
Quoted 6 lines · Srinivas KANDAGATLA
From: Stuart Menefy <[email protected]>
This is a simple driver for the global timer module found in the Cortex A9-MP cores from revision r1p0 onwards. This should be able to perform the functions of the system timer and the local timer in an SMP system.
Quoted 12 lines
The global timer has the following features:
The global timer is a 64-bit incrementing counter with an
auto-incrementing feature. It continues incrementing after sending interrupts. The global timer is memory mapped in the private memory region.
The global timer is accessible to all Cortex-A9 processors in the
cluster. Each Cortex-A9 processor has a private 64-bit comparator that is used to assert a private interrupt when the global timer has reached the comparator value. All the Cortex-A9 processors in a design use the banked ID, ID27, for this interrupt. ID27 is sent to the Interrupt Controller as a Private Peripheral Interrupt. The global timer is clocked by PERIPHCLK.
PERIPHCLK scales with cpu clock typically so the global timer is not a suitable clocksource if you use cpufreq. You can deal with the scaling on clockevents, but not a clocksource. I imagine the global timers is also typically power-gated in some low power modes. This is why no one has added support already. Are neither of those an issue or going to be an issue for you?
Rob
Quoted 420 lines
Signed-off-by Stuart Menefy <[email protected]>Signed-off-by Srinivas Kandagatla <[email protected]>--- Documentation/devicetree/bindings/arm/gt.txt | 21 ++ arch/arm/Kconfig | 6 + arch/arm/include/asm/global_timer.h | 12 + arch/arm/kernel/Makefile | 1 + arch/arm/kernel/global_timer.c | 325 ++++++++++++++++++++++++++ 5 files changed, 365 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/gt.txt create mode 100644 arch/arm/include/asm/global_timer.h create mode 100644 arch/arm/kernel/global_timer.cDocumentation/devicetree/bindings/arm/gt.txt new file +21
-0@@ -0,0 +1,21 @@ + +* ARM Global Timer + Cortex-A9 are often associated with a per-core Global timer. + +** Timer node required properties: + +- compatible : Should be one of: + "arm,cortex-a9-global-timer" + +- interrupts : One interrupt to each core + +- reg : Specify the base address and the size of the GT timer + register window. + +Example: + + gt-timer at 2c000600 { + compatible = "arm,cortex-a9-global-timer"; + reg = <0x2c000600 0x20>; + interrupts = <1 13 0xf01>; + };arch/arm/Kconfig +6
-0@@ -1606,6 +1606,12 @@ config HAVE_ARM_TWD help This options enables support for the ARM timer and watchdog unit +config HAVE_ARM_GT + bool + select CLKSRC_OF if OF + help + This options enables support for the ARM global timer unit + choice prompt "Memory split" default VMSPLIT_3Garch/arm/include/asm/global_timer.h new file +12
-0@@ -0,0 +1,12 @@ +/* +* arch/arm/include/asm/global_timer.h +* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Author: Stuart Menefy <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +int __init global_timer_init (void __iomem *base,unsigned int timer_irq);arch/arm/kernel/Makefile +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_ARM_CPU_SUSPEND) += sleep.o suspend.o obj-$(CONFIG_SMP) += smp.o smp_tlb.o obj-$(CONFIG_HAVE_ARM_SCU) += smp_scu.o obj-$(CONFIG_HAVE_ARM_TWD) += smp_twd.o +obj-$(CONFIG_HAVE_ARM_GT) += global_timer.o obj-$(CONFIG_ARM_ARCH_TIMER) += arch_timer.o obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o insn.o obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o insn.oarch/arm/kernel/global_timer.c new file +325
-0@@ -0,0 +1,325 @@ +/* +* linux/arch/arm/kernel/global_timer.c +* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Author: Stuart Menefy <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/clocksource.h> +#include <linux/clockchips.h> +#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> + +#include <asm/mach/irq.h> +#include <asm/global_timer.h> +#include <asm/localtimer.h> + +#define GT_COUNTER0 0x00 +#define GT_COUNTER1 0x04 + +#define GT_CONTROL 0x08 +#define GT_CONTROL_TIMER_ENABLE BIT(0) +#define GT_CONTROL_COMP_ENABLE BIT(1)/* banked */ +#define GT_CONTROL_IRQ_ENABLE BIT(2)/* banked */ +#define GT_CONTROL_AUTO_INC BIT(3)/* banked */ + +#define GT_INT_STATUS 0x0c +#define GT_INT_STATUS_EVENT_FLAG BIT(0) + +#define GT_COMP0 0x10 +#define GT_COMP1 0x14 +#define GT_AUTO_INC 0x18 + +/* +* We are expecting to be clocked by the ARM peripheral clock. +* +* Note: it is assumed we are using a prescaler value of zero, so this is +* the units for all operations. +*/ +static void __iomem *gt_base; +static struct clk *gt_clk; +static unsigned long gt_clk_rate; +static int gt_ppi; +static struct clock_event_device __percpu **gt_evt; +static DEFINE_PER_CPU(bool, percpu_init_called); +static DEFINE_PER_CPU(struct clock_event_device, gt_clockevent); + +union gt_counter { +cycle_t cycles; +struct { +uint32_t lower; +uint32_t upper; + }; +}; + +static union gt_counter gt_counter_read (void ) +{ +union gt_counter res; +uint32_t upper; + + upper =readl (gt_base +GT_COUNTER1 ); +do { + res.upper = upper; + res.lower =readl (gt_base +GT_COUNTER0 ); + upper =readl (gt_base +GT_COUNTER1 ); + }while (upper != res.upper); + +return res; +} + +static void gt_compare_set (unsigned long delta,int periodic) +{ +union gt_counter counter =gt_counter_read (); +unsigned long ctrl =readl (gt_base +GT_CONTROL ); + +BUG_ON (!(ctrl >_CONTROL_TIMER_ENABLE )); +BUG_ON (ctrl & (GT_CONTROL_COMP_ENABLE | +GT_CONTROL_IRQ_ENABLE | +GT_CONTROL_AUTO_INC )); + + counter.cycles += delta; +writel (counter.lower, gt_base +GT_COMP0 ); +writel (counter.upper, gt_base +GT_COMP1 ); + + ctrl |=GT_CONTROL_COMP_ENABLE |GT_CONTROL_IRQ_ENABLE ; + +if (periodic) { +writel (delta, gt_base +GT_AUTO_INC ); + ctrl |=GT_CONTROL_AUTO_INC ; + } + +writel (ctrl, gt_base +GT_CONTROL ); +} + +static void gt_clockevent_set_mode (enum clock_event_mode mode, +struct clock_event_device *clk) +{ +switch (mode) { +case CLOCK_EVT_MODE_PERIODIC : +gt_compare_set (gt_clk_rate/HZ ,1 ); +break ; +case CLOCK_EVT_MODE_ONESHOT : +/* period set, and timer enabled in 'next_event' hook */ +BUG_ON (readl (gt_base +GT_CONTROL ) & + (GT_CONTROL_COMP_ENABLE | +GT_CONTROL_IRQ_ENABLE | +GT_CONTROL_AUTO_INC )); +/* Fall through */ +case CLOCK_EVT_MODE_UNUSED : +case CLOCK_EVT_MODE_SHUTDOWN : +default : +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); +break ; + } +} + +static int gt_clockevent_set_next_event (unsigned long evt, +struct clock_event_device *unused) +{ +gt_compare_set (evt,0 ); +return 0 ; +} + +static irqreturn_t gt_clockevent_interrupt (int irq,void *dev_id) +{ +struct clock_event_device *evt = *(struct clock_event_device **)dev_id; + +writel (GT_INT_STATUS_EVENT_FLAG , gt_base +GT_INT_STATUS ); + evt->event_handler (evt); + +return IRQ_HANDLED ; +} + +static int __cpuinit gt_clockevents_init (struct clock_event_device *clk) +{ +struct clock_event_device **this_cpu_clk; +int cpu =smp_processor_id (); + + clk->name ="Global Timer CE" ; + clk->features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT ; + clk->set_mode = gt_clockevent_set_mode; + clk->set_next_event = gt_clockevent_set_next_event; + this_cpu_clk =__this_cpu_ptr (gt_evt); + *this_cpu_clk = clk; + clk->irq = gt_ppi; +clockevents_config_and_register (clk, gt_clk_rate, +0xf ,0xffffffff ); +per_cpu (percpu_init_called, cpu) = true; +enable_percpu_irq (clk->irq,IRQ_TYPE_NONE ); +return 0 ; +} + +static void gt_clockevents_stop (struct clock_event_device *clk) +{ +gt_clockevent_set_mode (CLOCK_EVT_MODE_UNUSED , clk); +disable_percpu_irq (clk->irq); +} + +static int __cpuinit gt_clockevents_setup (struct clock_event_device *clk) +{ +int cpu =smp_processor_id (); + +/* Use existing clock_event for boot cpu */ +if (per_cpu (percpu_init_called, cpu)) +return 0 ; + +writel (0 , gt_base +GT_CONTROL ); +writel (0 , gt_base +GT_COUNTER0 ); +writel (0 , gt_base +GT_COUNTER1 ); +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); + +return gt_clockevents_init (clk); +} + +static cycle_t gt_clocksource_read (struct clocksource *cs) +{ +union gt_counter res =gt_counter_read (); +return res.cycles; +} + +static struct clocksource gt_clocksource = { + .name ="Global Timer CS" , + .rating =300 , + .read = gt_clocksource_read, + .mask =CLOCKSOURCE_MASK (64 ), + .flags =CLOCK_SOURCE_IS_CONTINUOUS , +}; + +static void __init gt_clocksource_init (void ) +{ +writel (0 , gt_base +GT_CONTROL ); +writel (0 , gt_base +GT_COUNTER0 ); +writel (0 , gt_base +GT_COUNTER1 ); +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); + + gt_clocksource.shift =20 ; + gt_clocksource.mult = +clocksource_hz2mult (gt_clk_rate, gt_clocksource.shift); +clocksource_register (>_clocksource); +} + +static struct clk *gt_get_clock (void ) +{ +struct clk *clk; +int err; + + clk =clk_get_sys ("gt" ,NULL ); +if (IS_ERR (clk)) { +pr_err ("global-timer: clock not found: %ld\n" ,PTR_ERR (clk)); +return clk; + } + + err =clk_prepare_enable (clk); +if (err) { +pr_err ("global-timer: clock prepare+enable failed: %d\n" , err); +clk_put (clk); +return ERR_PTR (err); + } + +return clk; +} + +static struct local_timer_ops gt_lt_ops__cpuinitdata = { + .setup = gt_clockevents_setup, + .stop = gt_clockevents_stop, +}; + +int __init global_timer_init (void __iomem *base,unsigned int timer_irq) +{ +unsigned int cpu =smp_processor_id (); +struct clock_event_device *evt = &per_cpu (gt_clockevent, cpu); +int err =0 ; + +if (gt_base) { +pr_warn ("global-timer: invalid base address\n" ); +return -EINVAL ; + } + + gt_clk =gt_get_clock (); +if (IS_ERR (gt_clk)) { +pr_warn ("global-timer: clk not found\n" ); +return -EINVAL ; + } + + gt_evt = alloc_percpu(struct clock_event_device *); +if (!gt_evt) { +pr_warn ("global-timer: can't allocate memory\n" ); +return -ENOMEM ; + } + + err =request_percpu_irq (timer_irq, gt_clockevent_interrupt, +"gt" , gt_evt); +if (err) { +pr_warn ("global-timer: can't register interrupt %d (%d)\n" , + timer_irq, err); + goto out_free; + } + + gt_base = base; + gt_clk_rate =clk_get_rate (gt_clk); + + evt->irq = timer_irq; + gt_ppi = timer_irq; + evt->cpumask =cpumask_of (cpu); + +gt_clocksource_init (); +gt_clockevents_init (evt); + err =local_timer_register (>_lt_ops); +if (err) { +pr_warn ("global-timer: unable to register local timer.\n" ); + goto out_irq; + } + +return 0 ; + +out_irq: +free_percpu_irq (timer_irq, gt_evt); +out_free: +free_percpu (gt_evt); +return err; +} + +#ifdef CONFIG_OF +static void __init global_timer_of_register (struct device_node *np) +{ +struct clk *clk; +int err =0 ; +int gt_ppi; +static void __iomem *gt_base; + + gt_ppi =irq_of_parse_and_map (np,0 ); +if (!gt_ppi) { + err = -EINVAL ; + goto out; + } + + gt_base =of_iomap (np,0 ); +if (!gt_base) { + err = -ENOMEM ; + goto out; + } + + clk =of_clk_get (np,0 ); +if (!IS_ERR (clk)) +clk_register_clkdev (clk,NULL ,"gt" ); + +global_timer_init (gt_base, gt_ppi); + +out: +WARN (err,"Global timer register failed (%d)\n" , err); +} + +CLOCKSOURCE_OF_DECLARE (arm_gt_a9,"arm,cortex-a9-global-timer" , + global_timer_of_register); +#endif
Re: [RFC 2/8] ARM:global_timer: Add ARM global timer support.
Quoted 20 lines · Rob Herring
Quoted 6 lines · Srinivas KANDAGATLA
From: Stuart Menefy <[email protected]>
This is a simple driver for the global timer module found in the Cortex A9-MP cores from revision r1p0 onwards. This should be able to perform the functions of the system timer and the local timer in an SMP system.
Quoted 12 lines
The global timer has the following features:
The global timer is a 64-bit incrementing counter with an
auto-incrementing feature. It continues incrementing after sending interrupts. The global timer is memory mapped in the private memory region.
The global timer is accessible to all Cortex-A9 processors in the
cluster. Each Cortex-A9 processor has a private 64-bit comparator that is used to assert a private interrupt when the global timer has reached the comparator value. All the Cortex-A9 processors in a design use the banked ID, ID27, for this interrupt. ID27 is sent to the Interrupt Controller as a Private Peripheral Interrupt. The global timer is clocked by PERIPHCLK.
Quoted 6 lines
PERIPHCLK scales with cpu clock typically so the global timer is not a suitable clocksource if you use cpufreq. You can deal with the scaling on clockevents, but not a clocksource. I imagine the global timers is also typically power-gated in some low power modes. This is why no one has added support already. Are neither of those an issue or going to be an issue for you?
I agree but we're limited by the available hardware, the SoC designers didn't put down any general purpose timers unfortunately, so we have to use the global timer as a clocksource.
The full version of this code has a cpufreq notifier to try and cope with changes, but we didn't include that as the rest of the cpufreq code is missing in this first post. There will be inaccuracies of course, but its the best we can do.
There is no power gating on these devices, and clock gating only occurs at the clock input to the A9 subsystem including the cores and timers, so we don't have that issue.
Stuart
Quoted 420 lines
Quoted 419 lines
Signed-off-by Stuart Menefy <[email protected]>Signed-off-by Srinivas Kandagatla <[email protected]>--- Documentation/devicetree/bindings/arm/gt.txt | 21 ++ arch/arm/Kconfig | 6 + arch/arm/include/asm/global_timer.h | 12 + arch/arm/kernel/Makefile | 1 + arch/arm/kernel/global_timer.c | 325 ++++++++++++++++++++++++++ 5 files changed, 365 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/gt.txt create mode 100644 arch/arm/include/asm/global_timer.h create mode 100644 arch/arm/kernel/global_timer.cDocumentation/devicetree/bindings/arm/gt.txt new file +21
-0@@ -0,0 +1,21 @@ + +* ARM Global Timer + Cortex-A9 are often associated with a per-core Global timer. + +** Timer node required properties: + +- compatible : Should be one of: + "arm,cortex-a9-global-timer" + +- interrupts : One interrupt to each core + +- reg : Specify the base address and the size of the GT timer + register window. + +Example: + + gt-timer at 2c000600 { + compatible = "arm,cortex-a9-global-timer"; + reg = <0x2c000600 0x20>; + interrupts = <1 13 0xf01>; + };arch/arm/Kconfig +6
-0@@ -1606,6 +1606,12 @@ config HAVE_ARM_TWD help This options enables support for the ARM timer and watchdog unit +config HAVE_ARM_GT + bool + select CLKSRC_OF if OF + help + This options enables support for the ARM global timer unit + choice prompt "Memory split" default VMSPLIT_3Garch/arm/include/asm/global_timer.h new file +12
-0@@ -0,0 +1,12 @@ +/* +* arch/arm/include/asm/global_timer.h +* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Author: Stuart Menefy <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +int __init global_timer_init (void __iomem *base,unsigned int timer_irq);arch/arm/kernel/Makefile +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_ARM_CPU_SUSPEND) += sleep.o suspend.o obj-$(CONFIG_SMP) += smp.o smp_tlb.o obj-$(CONFIG_HAVE_ARM_SCU) += smp_scu.o obj-$(CONFIG_HAVE_ARM_TWD) += smp_twd.o +obj-$(CONFIG_HAVE_ARM_GT) += global_timer.o obj-$(CONFIG_ARM_ARCH_TIMER) += arch_timer.o obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o insn.o obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o insn.oarch/arm/kernel/global_timer.c new file +325
-0@@ -0,0 +1,325 @@ +/* +* linux/arch/arm/kernel/global_timer.c +* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* Author: Stuart Menefy <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/clocksource.h> +#include <linux/clockchips.h> +#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> + +#include <asm/mach/irq.h> +#include <asm/global_timer.h> +#include <asm/localtimer.h> + +#define GT_COUNTER0 0x00 +#define GT_COUNTER1 0x04 + +#define GT_CONTROL 0x08 +#define GT_CONTROL_TIMER_ENABLE BIT(0) +#define GT_CONTROL_COMP_ENABLE BIT(1)/* banked */ +#define GT_CONTROL_IRQ_ENABLE BIT(2)/* banked */ +#define GT_CONTROL_AUTO_INC BIT(3)/* banked */ + +#define GT_INT_STATUS 0x0c +#define GT_INT_STATUS_EVENT_FLAG BIT(0) + +#define GT_COMP0 0x10 +#define GT_COMP1 0x14 +#define GT_AUTO_INC 0x18 + +/* +* We are expecting to be clocked by the ARM peripheral clock. +* +* Note: it is assumed we are using a prescaler value of zero, so this is +* the units for all operations. +*/ +static void __iomem *gt_base; +static struct clk *gt_clk; +static unsigned long gt_clk_rate; +static int gt_ppi; +static struct clock_event_device __percpu **gt_evt; +static DEFINE_PER_CPU(bool, percpu_init_called); +static DEFINE_PER_CPU(struct clock_event_device, gt_clockevent); + +union gt_counter { +cycle_t cycles; +struct { +uint32_t lower; +uint32_t upper; + }; +}; + +static union gt_counter gt_counter_read (void ) +{ +union gt_counter res; +uint32_t upper; + + upper =readl (gt_base +GT_COUNTER1 ); +do { + res.upper = upper; + res.lower =readl (gt_base +GT_COUNTER0 ); + upper =readl (gt_base +GT_COUNTER1 ); + }while (upper != res.upper); + +return res; +} + +static void gt_compare_set (unsigned long delta,int periodic) +{ +union gt_counter counter =gt_counter_read (); +unsigned long ctrl =readl (gt_base +GT_CONTROL ); + +BUG_ON (!(ctrl >_CONTROL_TIMER_ENABLE )); +BUG_ON (ctrl & (GT_CONTROL_COMP_ENABLE | +GT_CONTROL_IRQ_ENABLE | +GT_CONTROL_AUTO_INC )); + + counter.cycles += delta; +writel (counter.lower, gt_base +GT_COMP0 ); +writel (counter.upper, gt_base +GT_COMP1 ); + + ctrl |=GT_CONTROL_COMP_ENABLE |GT_CONTROL_IRQ_ENABLE ; + +if (periodic) { +writel (delta, gt_base +GT_AUTO_INC ); + ctrl |=GT_CONTROL_AUTO_INC ; + } + +writel (ctrl, gt_base +GT_CONTROL ); +} + +static void gt_clockevent_set_mode (enum clock_event_mode mode, +struct clock_event_device *clk) +{ +switch (mode) { +case CLOCK_EVT_MODE_PERIODIC : +gt_compare_set (gt_clk_rate/HZ ,1 ); +break ; +case CLOCK_EVT_MODE_ONESHOT : +/* period set, and timer enabled in 'next_event' hook */ +BUG_ON (readl (gt_base +GT_CONTROL ) & + (GT_CONTROL_COMP_ENABLE | +GT_CONTROL_IRQ_ENABLE | +GT_CONTROL_AUTO_INC )); +/* Fall through */ +case CLOCK_EVT_MODE_UNUSED : +case CLOCK_EVT_MODE_SHUTDOWN : +default : +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); +break ; + } +} + +static int gt_clockevent_set_next_event (unsigned long evt, +struct clock_event_device *unused) +{ +gt_compare_set (evt,0 ); +return 0 ; +} + +static irqreturn_t gt_clockevent_interrupt (int irq,void *dev_id) +{ +struct clock_event_device *evt = *(struct clock_event_device **)dev_id; + +writel (GT_INT_STATUS_EVENT_FLAG , gt_base +GT_INT_STATUS ); + evt->event_handler (evt); + +return IRQ_HANDLED ; +} + +static int __cpuinit gt_clockevents_init (struct clock_event_device *clk) +{ +struct clock_event_device **this_cpu_clk; +int cpu =smp_processor_id (); + + clk->name ="Global Timer CE" ; + clk->features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT ; + clk->set_mode = gt_clockevent_set_mode; + clk->set_next_event = gt_clockevent_set_next_event; + this_cpu_clk =__this_cpu_ptr (gt_evt); + *this_cpu_clk = clk; + clk->irq = gt_ppi; +clockevents_config_and_register (clk, gt_clk_rate, +0xf ,0xffffffff ); +per_cpu (percpu_init_called, cpu) = true; +enable_percpu_irq (clk->irq,IRQ_TYPE_NONE ); +return 0 ; +} + +static void gt_clockevents_stop (struct clock_event_device *clk) +{ +gt_clockevent_set_mode (CLOCK_EVT_MODE_UNUSED , clk); +disable_percpu_irq (clk->irq); +} + +static int __cpuinit gt_clockevents_setup (struct clock_event_device *clk) +{ +int cpu =smp_processor_id (); + +/* Use existing clock_event for boot cpu */ +if (per_cpu (percpu_init_called, cpu)) +return 0 ; + +writel (0 , gt_base +GT_CONTROL ); +writel (0 , gt_base +GT_COUNTER0 ); +writel (0 , gt_base +GT_COUNTER1 ); +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); + +return gt_clockevents_init (clk); +} + +static cycle_t gt_clocksource_read (struct clocksource *cs) +{ +union gt_counter res =gt_counter_read (); +return res.cycles; +} + +static struct clocksource gt_clocksource = { + .name ="Global Timer CS" , + .rating =300 , + .read = gt_clocksource_read, + .mask =CLOCKSOURCE_MASK (64 ), + .flags =CLOCK_SOURCE_IS_CONTINUOUS , +}; + +static void __init gt_clocksource_init (void ) +{ +writel (0 , gt_base +GT_CONTROL ); +writel (0 , gt_base +GT_COUNTER0 ); +writel (0 , gt_base +GT_COUNTER1 ); +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); + + gt_clocksource.shift =20 ; + gt_clocksource.mult = +clocksource_hz2mult (gt_clk_rate, gt_clocksource.shift); +clocksource_register (>_clocksource); +} + +static struct clk *gt_get_clock (void ) +{ +struct clk *clk; +int err; + + clk =clk_get_sys ("gt" ,NULL ); +if (IS_ERR (clk)) { +pr_err ("global-timer: clock not found: %ld\n" ,PTR_ERR (clk)); +return clk; + } + + err =clk_prepare_enable (clk); +if (err) { +pr_err ("global-timer: clock prepare+enable failed: %d\n" , err); +clk_put (clk); +return ERR_PTR (err); + } + +return clk; +} + +static struct local_timer_ops gt_lt_ops__cpuinitdata = { + .setup = gt_clockevents_setup, + .stop = gt_clockevents_stop, +}; + +int __init global_timer_init (void __iomem *base,unsigned int timer_irq) +{ +unsigned int cpu =smp_processor_id (); +struct clock_event_device *evt = &per_cpu (gt_clockevent, cpu); +int err =0 ; + +if (gt_base) { +pr_warn ("global-timer: invalid base address\n" ); +return -EINVAL ; + } + + gt_clk =gt_get_clock (); +if (IS_ERR (gt_clk)) { +pr_warn ("global-timer: clk not found\n" ); +return -EINVAL ; + } + + gt_evt = alloc_percpu(struct clock_event_device *); +if (!gt_evt) { +pr_warn ("global-timer: can't allocate memory\n" ); +return -ENOMEM ; + } + + err =request_percpu_irq (timer_irq, gt_clockevent_interrupt, +"gt" , gt_evt); +if (err) { +pr_warn ("global-timer: can't register interrupt %d (%d)\n" , + timer_irq, err); + goto out_free; + } + + gt_base = base; + gt_clk_rate =clk_get_rate (gt_clk); + + evt->irq = timer_irq; + gt_ppi = timer_irq; + evt->cpumask =cpumask_of (cpu); + +gt_clocksource_init (); +gt_clockevents_init (evt); + err =local_timer_register (>_lt_ops); +if (err) { +pr_warn ("global-timer: unable to register local timer.\n" ); + goto out_irq; + } + +return 0 ; + +out_irq: +free_percpu_irq (timer_irq, gt_evt); +out_free: +free_percpu (gt_evt); +return err; +} + +#ifdef CONFIG_OF +static void __init global_timer_of_register (struct device_node *np) +{ +struct clk *clk; +int err =0 ; +int gt_ppi; +static void __iomem *gt_base; + + gt_ppi =irq_of_parse_and_map (np,0 ); +if (!gt_ppi) { + err = -EINVAL ; + goto out; + } + + gt_base =of_iomap (np,0 ); +if (!gt_base) { + err = -ENOMEM ; + goto out; + } + + clk =of_clk_get (np,0 ); +if (!IS_ERR (clk)) +clk_register_clkdev (clk,NULL ,"gt" ); + +global_timer_init (gt_base, gt_ppi); + +out: +WARN (err,"Global timer register failed (%d)\n" , err); +} + +CLOCKSOURCE_OF_DECLARE (arm_gt_a9,"arm,cortex-a9-global-timer" , + global_timer_of_register); +#endif
Arnd Bergmann
maintainerRe: [RFC 2/8] ARM:global_timer: Add ARM global timer support.
In reply to Srinivas KANDAGATLAQuoted 19 lines · Srinivas KANDAGATLA
From: Stuart Menefy <[email protected]>
This is a simple driver for the global timer module found in the Cortex A9-MP cores from revision r1p0 onwards. This should be able to perform the functions of the system timer and the local timer in an SMP system.
The global timer has the following features:
The global timer is a 64-bit incrementing counter with an
auto-incrementing feature. It continues incrementing after sending interrupts. The global timer is memory mapped in the private memory region.
The global timer is accessible to all Cortex-A9 processors in the
cluster. Each Cortex-A9 processor has a private 64-bit comparator that is used to assert a private interrupt when the global timer has reached the comparator value. All the Cortex-A9 processors in a design use the banked ID, ID27, for this interrupt. ID27 is sent to the Interrupt Controller as a Private Peripheral Interrupt. The global timer is clocked by PERIPHCLK.
Quoted 3 lines
Signed-off-by Stuart Menefy <[email protected]>Signed-off-by Srinivas Kandagatla <[email protected]>
Are you sure we don't already have a driver for this? It sounds unlikely that you are the first one to do this when the hardware is so common.
Quoted 9 lines
Documentation/devicetree/bindings/arm/gt.txt | 21 ++ arch/arm/Kconfig | 6 + arch/arm/include/asm/global_timer.h | 12 + arch/arm/kernel/Makefile | 1 + arch/arm/kernel/global_timer.c | 325 ++++++++++++++++++++++++++ 5 files changed, 365 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/gt.txt create mode 100644 arch/arm/include/asm/global_timer.h create mode 100644 arch/arm/kernel/global_timer.c
Move it into drivers/clocksource?
arch/arm/include/asm/global_timer.h line 1
Quoted 7 lines
arch/arm/include/asm/global_timer.h new file +1
-0@@ -0,0 +1,12 @@ +int __init global_timer_init (void __iomem *base,unsigned int timer_irq);
I don't see a need to call this from platform code for non-DT platforms, it can easily be used with CLOCKSOURCE_OF_DECLARE() all the time I think.
Arnd
RFC 2/8 ARM:global_timer: Add ARM global timer support.
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Srinivas KANDAGATLA
From: Stuart Menefy <[email protected]>
This is a simple driver for the global timer module found in the Cortex A9-MP cores from revision r1p0 onwards. This should be able to perform the functions of the system timer and the local timer in an SMP system.
The global timer has the following features:
The global timer is a 64-bit incrementing counter with an
auto-incrementing feature. It continues incrementing after sending interrupts. The global timer is memory mapped in the private memory region.
The global timer is accessible to all Cortex-A9 processors in the
cluster. Each Cortex-A9 processor has a private 64-bit comparator that is used to assert a private interrupt when the global timer has reached the comparator value. All the Cortex-A9 processors in a design use the banked ID, ID27, for this interrupt. ID27 is sent to the Interrupt Controller as a Private Peripheral Interrupt. The global timer is clocked by PERIPHCLK.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Stuart Menefy <[email protected]>Signed-off-by Srinivas Kandagatla <[email protected]>Are you sure we don't already have a driver for this? It sounds unlikely that you are the first one to do this when the hardware is so common.
An additional reason why people don't make use of this timer (on top of the power domain concerns raised by Rob) is due to the following from the A9 TRM:
`From r2p0 the comparators for each processor with the global timer fire
when the timer value is greater than or equal to. In previous revisions the comparators fired when the timer value was equal to.'
So you'll get into all sorts of horrible races on those older revisions if you're not careful.
Will
RFC 2/8 ARM:global_timer: Add ARM global timer support.
Quoted 32 lines · Will Deacon
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Srinivas KANDAGATLA
From: Stuart Menefy <[email protected]>
This is a simple driver for the global timer module found in the Cortex A9-MP cores from revision r1p0 onwards. This should be able to perform the functions of the system timer and the local timer in an SMP system.
The global timer has the following features:
The global timer is a 64-bit incrementing counter with an
auto-incrementing feature. It continues incrementing after sending interrupts. The global timer is memory mapped in the private memory region.
The global timer is accessible to all Cortex-A9 processors in the
cluster. Each Cortex-A9 processor has a private 64-bit comparator that is used to assert a private interrupt when the global timer has reached the comparator value. All the Cortex-A9 processors in a design use the banked ID, ID27, for this interrupt. ID27 is sent to the Interrupt Controller as a Private Peripheral Interrupt. The global timer is clocked by PERIPHCLK.Quoted 6 lines
Quoted 3 lines
Signed-off-by Stuart Menefy <[email protected]>Signed-off-by Srinivas Kandagatla <[email protected]>Are you sure we don't already have a driver for this? It sounds unlikely that you are the first one to do this when the hardware is so common.
An additional reason why people don't make use of this timer (on top of the power domain concerns raised by Rob) is due to the following from the A9 TRM:
Quoted 6 lines
`From r2p0 the comparators for each processor with the global timer fire
when the timer value is greater than or equal to. In previous revisions the comparators fired when the timer value was equal to.'So you'll get into all sorts of horrible races on those older revisions if you're not careful.
Fortunately the earliest version of these SoCs uses r2p2, so we avoided that particular issue. But as the code doesn't attempt to work around these problems a check on the version number might be a good idea to prevent other people accidentally hitting it.
Stuart
Arnd Bergmann
maintainerRFC 2/8 ARM:global_timer: Add ARM global timer support.
Quoted 5 lines · Stuart MENEFY
Fortunately the earliest version of these SoCs uses r2p2, so we avoided that particular issue. But as the code doesn't attempt to work around these problems a check on the version number might be a good idea to prevent other people accidentally hitting it.
Yes, good idea. I would put the version number in the compatible property and document both the working and non-working versions in the binding, but put a comment explaining the situation into the driver.
Arnd
Re: [RFC 2/8] ARM:global_timer: Add ARM global timer support.
In reply to Arnd BergmannQuoted 20 lines · Arnd Bergmann
Quoted 19 lines · Srinivas KANDAGATLA
From: Stuart Menefy <[email protected]>
This is a simple driver for the global timer module found in the Cortex A9-MP cores from revision r1p0 onwards. This should be able to perform the functions of the system timer and the local timer in an SMP system.
The global timer has the following features:
The global timer is a 64-bit incrementing counter with an
auto-incrementing feature. It continues incrementing after sending interrupts. The global timer is memory mapped in the private memory region.
The global timer is accessible to all Cortex-A9 processors in the
cluster. Each Cortex-A9 processor has a private 64-bit comparator that is used to assert a private interrupt when the global timer has reached the comparator value. All the Cortex-A9 processors in a design use the banked ID, ID27, for this interrupt. ID27 is sent to the Interrupt Controller as a Private Peripheral Interrupt. The global timer is clocked by PERIPHCLK.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Stuart Menefy <[email protected]>Signed-off-by Srinivas Kandagatla <[email protected]>Are you sure we don't already have a driver for this? It sounds unlikely that you are the first one to do this when the hardware is so common.
Isn't this the same as arch/arm/kernel/smp_twd.c ?
That is atleast the timer I used with Cortex-A9. I don't think the core has another one. But maybe I'm wrong.
Quoted 12 lines
Quoted 9 lines
Documentation/devicetree/bindings/arm/gt.txt | 21 ++ arch/arm/Kconfig | 6 + arch/arm/include/asm/global_timer.h | 12 + arch/arm/kernel/Makefile | 1 + arch/arm/kernel/global_timer.c | 325 ++++++++++++++++++++++++++ 5 files changed, 365 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/gt.txt create mode 100644 arch/arm/include/asm/global_timer.h create mode 100644 arch/arm/kernel/global_timer.cMove it into
drivers/clocksource?
Quoted 11 lines
arch/arm/include/asm/global_timer.h line 1
Quoted 7 lines
arch/arm/include/asm/global_timer.h new file +1
-0@@ -0,0 +1,12 @@ +int __init global_timer_init (void __iomem *base,unsigned int timer_irq);I don't see a need to call this from platform code for non-DT platforms, it can easily be used with
CLOCKSOURCE_OF_DECLARE()all the time I think.
Regards,
Steffen
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [RFC 2/8] ARM:global_timer: Add ARM global timer support.
In reply to Arnd BergmannQuoted 20 lines · Arnd Bergmann
Quoted 19 lines · Srinivas KANDAGATLA
From: Stuart Menefy <[email protected]>
This is a simple driver for the global timer module found in the Cortex A9-MP cores from revision r1p0 onwards. This should be able to perform the functions of the system timer and the local timer in an SMP system.
The global timer has the following features:
The global timer is a 64-bit incrementing counter with an
auto-incrementing feature. It continues incrementing after sending interrupts. The global timer is memory mapped in the private memory region.
The global timer is accessible to all Cortex-A9 processors in the
cluster. Each Cortex-A9 processor has a private 64-bit comparator that is used to assert a private interrupt when the global timer has reached the comparator value. All the Cortex-A9 processors in a design use the banked ID, ID27, for this interrupt. ID27 is sent to the Interrupt Controller as a Private Peripheral Interrupt. The global timer is clocked by PERIPHCLK.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Stuart Menefy <[email protected]>Signed-off-by Srinivas Kandagatla <[email protected]>Are you sure we don't already have a driver for this? It sounds unlikely that you are the first one to do this when the hardware is so common.
Yes, in mainline we do not have support to this.
Quoted 11 lines
Quoted 10 lines
Documentation/devicetree/bindings/arm/gt.txt | 21 ++ arch/arm/Kconfig | 6 + arch/arm/include/asm/global_timer.h | 12 + arch/arm/kernel/Makefile | 1 + arch/arm/kernel/global_timer.c | 325 ++++++++++++++++++++++++++ 5 files changed, 365 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/gt.txt create mode 100644 arch/arm/include/asm/global_timer.h create mode 100644 arch/arm/kernel/global_timer.c
Quoted 1 line
Move it into
drivers/clocksource?
Sure, I will move this in the next version.
Quoted 11 lines
arch/arm/include/asm/global_timer.h line 1
Quoted 8 lines
arch/arm/include/asm/global_timer.h new file +1
-0@@ -0,0 +1,12 @@ +int __init global_timer_init (void __iomem *base,unsigned int timer_irq);I don't see a need to call this from platform code for non-DT platforms, it can easily be used with
CLOCKSOURCE_OF_DECLARE()all the time I think.
sorry Am confused here.
How would this work for non-DT?
Looking at the code in clocksource_of_init it just goes through the of_device_id table, which is not used in case of non-DT.
Quoted 9 lines
Arnd
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Arnd Bergmann
maintainerRe: [RFC 2/8] ARM:global_timer: Add ARM global timer support.
Quoted 11 lines · Srinivas KANDAGATLA
Quoted 10 lines
arch/arm/include/asm/global_timer.h line 1
Quoted 7 lines
arch/arm/include/asm/global_timer.h new file +1
-0@@ -0,0 +1,12 @@ +int __init global_timer_init (void __iomem *base,unsigned int timer_irq);I don't see a need to call this from platform code for non-DT platforms, it can easily be used with
CLOCKSOURCE_OF_DECLARE()all the time I think.
Quoted 2 lines
sorry Am confused here.
How would this work for non-DT?
It won't.
Quoted 2 lines
Looking at the code in
clocksource_of_initit just goes through theof_device_idtable, which is not used in case of non-DT.
All new platforms are DT-only, and none of the old platforms use this driver, so it does not matter.
Arnd
Re: [RFC 2/8] ARM:global_timer: Add ARM global timer support.
Quoted 7 lines · Arnd Bergmann
It won't.
Quoted 2 lines
Quoted 2 lines
Looking at the code in
clocksource_of_initit just goes through theof_device_idtable, which is not used in case of non-DT.All new platforms are DT-only, and none of the old platforms use this driver, so it does not matter.
It makes sense, I will remove the header file.
Quoted 2 lines
Arnd
RFC 2/8 ARM:global_timer: Add ARM global timer support.
In reply to Srinivas KANDAGATLAOn Wed, May 8, 2013 at 4:11 PM, Srinivas KANDAGATLA <[email protected]> wrote:
Thomas Gleixner and John Stultz should always be included on timer code review.
This is one reason I really like to move the clocksource/clockevent/etc code out of arch/arm, so that people can get their To: line right from MAINTAINERS. (Whether it goes to drivers/clocksource or not is another issue.)
arch/arm/include/asm/global_timer.h
Quoted 1 line
arch/arm/include/asm/global_timer.h +0
-0
Using CLKSRC_OF_INIT() this header goes away entirely I guess.
arch/arm/kernel/global_timer.c line 29
Quoted 4 lines
arch/arm/kernel/global_timer.c +2
-0+#define GT_COUNTER0 0x00 +#define GT_COUNTER1 0x04
So two counters, nice.
arch/arm/kernel/global_timer.c line 62
Quoted 5 lines
arch/arm/kernel/global_timer.c +5
-0+union gt_counter { +cycle_t cycles; +struct { +uint32_t lower; +uint32_t upper;
Just u32 is fine.
arch/arm/kernel/global_timer.c line 69
Quoted 7 lines
arch/arm/kernel/global_timer.c +7
-0+ }; +}; + +static union gt_counter gt_counter_read (void ) +{ +union gt_counter res; +uint32_t upper;
u32
arch/arm/kernel/global_timer.c line 79
Quoted 10 lines
arch/arm/kernel/global_timer.c +10
-0+ + upper =readl (gt_base +GT_COUNTER1 ); +do { + res.upper = upper; + res.lower =readl (gt_base +GT_COUNTER0 ); + upper =readl (gt_base +GT_COUNTER1 ); + }while (upper != res.upper); + +return res; +}
I guess this is some cleverness to avoid wrap-around... A comment stating what's going on wouldn't hurt.
But why on earth do you need this complicated union to hold the result? Have two local u32 variables and return a u64 from this function.
Since this will be performance critical, isn't readl_relaxed() suffient here, or what's the rationale for just using readl()?
arch/arm/kernel/global_timer.c line 83
Quoted 3 lines
arch/arm/kernel/global_timer.c +3
-0+static void gt_compare_set (unsigned long delta,int periodic) +{ +union gt_counter counter =gt_counter_read ();
So here you get something easy to read like
u64 counter = gt_counter_read();
arch/arm/kernel/global_timer.c line 89
Quoted 6 lines
arch/arm/kernel/global_timer.c +6
-0+unsigned long ctrl =readl (gt_base +GT_CONTROL ); + +BUG_ON (!(ctrl >_CONTROL_TIMER_ENABLE )); +BUG_ON (ctrl & (GT_CONTROL_COMP_ENABLE | +GT_CONTROL_IRQ_ENABLE | +GT_CONTROL_AUTO_INC ));
Do you really have to check this *whenever the counter is set*?
Will it not suffice to do this once during initialization?
It looks like some leftover debug code. It also looks kind of clock dangerous, can you explain exactly why this check is here?
arch/arm/kernel/global_timer.c line 93
Quoted 4 lines
arch/arm/kernel/global_timer.c +4
-0+ + counter.cycles += delta; +writel (counter.lower, gt_base +GT_COMP0 ); +writel (counter.upper, gt_base +GT_COMP1 );
This is another instance of the union struct making things complicated. With a u64 just:
counter += delta; writel(lower_32_bits(counter), gt_base + GT_COMP0); writel(upper_32_bits(counter), gt_base + GT_COMP1);
As you can see <linux/kernel.h> has really nice helpers in place to deal with 64 bit arithmetics.
Quoted 7 lines
arch/arm/kernel/global_timer.c +7
-0+ + ctrl |=GT_CONTROL_COMP_ENABLE |GT_CONTROL_IRQ_ENABLE ; + +if (periodic) { +writel (delta, gt_base +GT_AUTO_INC ); + ctrl |=GT_CONTROL_AUTO_INC ; + }
arch/arm/kernel/global_timer.c line 110
Quoted 10 lines
arch/arm/kernel/global_timer.c +10
-0+ +writel (ctrl, gt_base +GT_CONTROL ); +} + +static void gt_clockevent_set_mode (enum clock_event_mode mode, +struct clock_event_device *clk) +{ +switch (mode) { +case CLOCK_EVT_MODE_PERIODIC : +gt_compare_set (gt_clk_rate/HZ ,1 );
Use gt_compare_set(DIV_ROUND_CLOSEST(gt_clk_rate, HZ), 1); to get integer arithmetics right.
arch/arm/kernel/global_timer.c line 117
Quoted 7 lines
arch/arm/kernel/global_timer.c +7
-0+break ; +case CLOCK_EVT_MODE_ONESHOT : +/* period set, and timer enabled in 'next_event' hook */ +BUG_ON (readl (gt_base +GT_CONTROL ) & + (GT_CONTROL_COMP_ENABLE | +GT_CONTROL_IRQ_ENABLE | +GT_CONTROL_AUTO_INC ));
Here is another one of these checks. Why aren't you just zeroing these flags if you don't want them, especially since you're writing the register at the end of the function? Now it looks like instead of setting up the timer the way you want it you bug out if it isn't already set up as you want it (hint, the name of this function).
arch/arm/kernel/global_timer.c line 122
Quoted 5 lines
arch/arm/kernel/global_timer.c +5
-0+/* Fall through */ +case CLOCK_EVT_MODE_UNUSED : +case CLOCK_EVT_MODE_SHUTDOWN : +default : +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL );
Why are you enabling the timer in unused and shutdown mode?
This doesn't make sense.
Quoted 6 lines
arch/arm/kernel/global_timer.c +6
-0+break ; + } +} + +static int gt_clockevent_set_next_event (unsigned long evt, +struct clock_event_device *unused)
arch/arm/kernel/global_timer.c line 138
Quoted 10 lines
arch/arm/kernel/global_timer.c +10
-0+{ +gt_compare_set (evt,0 ); +return 0 ; +} + +static irqreturn_t gt_clockevent_interrupt (int irq,void *dev_id) +{ +struct clock_event_device *evt = *(struct clock_event_device **)dev_id; + +writel (GT_INT_STATUS_EVENT_FLAG , gt_base +GT_INT_STATUS );
You're clearing the flag before checking if it was set. What happens if this was a spurious interrupt that should be disregarded?
arch/arm/kernel/global_timer.c line 149
Quoted 11 lines
arch/arm/kernel/global_timer.c +11
-0+ evt->event_handler (evt); + +return IRQ_HANDLED ; +} + +static int __cpuinit gt_clockevents_init (struct clock_event_device *clk) +{ +struct clock_event_device **this_cpu_clk; +int cpu =smp_processor_id (); + + clk->name ="Global Timer CE" ;
Name it after the hardware feature. "ARM global timer clock event" there is no need to abbreviate randomly.
arch/arm/kernel/global_timer.c line 157
Quoted 8 lines
arch/arm/kernel/global_timer.c +8
-0+ clk->features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT ; + clk->set_mode = gt_clockevent_set_mode; + clk->set_next_event = gt_clockevent_set_next_event; + this_cpu_clk =__this_cpu_ptr (gt_evt); + *this_cpu_clk = clk; + clk->irq = gt_ppi; +clockevents_config_and_register (clk, gt_clk_rate, +0xf ,0xffffffff );
Why can't this clock event handle anything lower than 0xf? Does that come from the datasheet or have you just copied some code?
Further, since this clock event hardware *most definately* supports using a delta upper bound *beyond* 32 bits, I think the clock event core code should be altered to allow for registereing such clock events, but TGLX may have some idea here. This will work but will not expose the full potential of this 64-bit counter hardware.
Quoted 25 lines
arch/arm/kernel/global_timer.c +25
-0+per_cpu (percpu_init_called, cpu) = true; +enable_percpu_irq (clk->irq,IRQ_TYPE_NONE ); +return 0 ; +} + +static void gt_clockevents_stop (struct clock_event_device *clk) +{ +gt_clockevent_set_mode (CLOCK_EVT_MODE_UNUSED , clk); +disable_percpu_irq (clk->irq); +} + +static int __cpuinit gt_clockevents_setup (struct clock_event_device *clk) +{ +int cpu =smp_processor_id (); + +/* Use existing clock_event for boot cpu */ +if (per_cpu (percpu_init_called, cpu)) +return 0 ; + +writel (0 , gt_base +GT_CONTROL ); +writel (0 , gt_base +GT_COUNTER0 ); +writel (0 , gt_base +GT_COUNTER1 ); +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); + +return gt_clockevents_init (clk);
arch/arm/kernel/global_timer.c line 192
Quoted 10 lines
arch/arm/kernel/global_timer.c +10
-0+} + +static cycle_t gt_clocksource_read (struct clocksource *cs) +{ +union gt_counter res =gt_counter_read (); +return res.cycles; +} + +static struct clocksource gt_clocksource = { + .name ="Global Timer CS" ,
"ARM global timer clock source"
Quoted 4 lines
arch/arm/kernel/global_timer.c +4
-0+ .rating = 300, + .read = gt_clocksource_read, + .mask = CLOCKSOURCE_MASK(64), + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
arch/arm/kernel/global_timer.c line 206
Quoted 10 lines
arch/arm/kernel/global_timer.c +10
-0+}; + +static void __init gt_clocksource_init (void ) +{ +writel (0 , gt_base +GT_CONTROL ); +writel (0 , gt_base +GT_COUNTER0 ); +writel (0 , gt_base +GT_COUNTER1 ); +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); + + gt_clocksource.shift =20 ;
So how did you come up with that?
arch/arm/kernel/global_timer.c line 209
Quoted 3 lines
arch/arm/kernel/global_timer.c +3
-0+ gt_clocksource.mult = +clocksource_hz2mult (gt_clk_rate, gt_clocksource.shift); +clocksource_register (>_clocksource);
Why don't you just replace all of this hazzle with:
clocksource_register_hz(>_clocksource, gt_clk_rate);
That will calculate mult and shift for you? (Leave these unassigned.)
Since the hpet timer does this it's pretty well tested...
No more comments right now...
Yours,
Linus Walleij
RFC 2/8 ARM:global_timer: Add ARM global timer support.
Quoted 14 lines · Linus Walleij
On Wed, May 8, 2013 at 4:11 PM, Srinivas KANDAGATLA
arch/arm/kernel/global_timer.c line 157
Quoted 8 lines
arch/arm/kernel/global_timer.c new file +8
-0+ clk->features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT ; + clk->set_mode = gt_clockevent_set_mode; + clk->set_next_event = gt_clockevent_set_next_event; + this_cpu_clk =__this_cpu_ptr (gt_evt); + *this_cpu_clk = clk; + clk->irq = gt_ppi; +clockevents_config_and_register (clk, gt_clk_rate, +0xf ,0xffffffff );Why can't this clock event handle anything lower than
0xf? Does that come from the datasheet or have you just copied some code?
Quoted 5 lines
Further, since this clock event hardware *most definately* supports using a delta upper bound *beyond* 32 bits, I think the clock event core code should be altered to allow for registereing such clock events, but TGLX may have some idea here. This will work but will not expose the full potential of this 64-bit counter hardware.
That requires a full source tree sweep to change all set_next_event callbacks in one go. Easy to do with coccinelle, but that needs the proper timing, i.e. right after a -rc1.
Thanks,
tglx
RFC 2/8 ARM:global_timer: Add ARM global timer support.
In reply to Linus WalleijThankyou for the comments.
Quoted 20 lines · Linus Walleij
On Wed, May 8, 2013 at 4:11 PM, Srinivas KANDAGATLA <[email protected]> wrote:
Thomas Gleixner and John Stultz should always be included on timer code review.
This is one reason I really like to move the clocksource/clockevent/etc code out of
arch/arm, so that people can get their To: line right fromMAINTAINERS. (Whether it goes todrivers/clocksourceor not is another issue.)arch/arm/include/asm/global_timer.h
Quoted 1 line
arch/arm/include/asm/global_timer.h +0
-0Using
CLKSRC_OF_INIT()this header goes away entirely I guess.arch/arm/kernel/global_timer.c line 29
Quoted 4 lines
arch/arm/kernel/global_timer.c +2
-0+#define GT_COUNTER0 0x00 +#define GT_COUNTER1 0x04So two counters, nice.
Quoted 7 lines
arch/arm/kernel/global_timer.c line 62
Quoted 5 lines
arch/arm/kernel/global_timer.c +5
-0+union gt_counter { +cycle_t cycles; +struct { +uint32_t lower; +uint32_t upper;Just u32 is fine.
It makes sense to remove this struct totally and use u64 as suggested.
Quoted 11 lines
arch/arm/kernel/global_timer.c line 69
Quoted 8 lines
arch/arm/kernel/global_timer.c +7
-0+ }; +}; + +static union gt_counter gt_counter_read (void ) +{ +union gt_counter res; +uint32_t upper;u32
Quoted 13 lines
arch/arm/kernel/global_timer.c line 79
Quoted 10 lines
arch/arm/kernel/global_timer.c +10
-0+ + upper =readl (gt_base +GT_COUNTER1 ); +do { + res.upper = upper; + res.lower =readl (gt_base +GT_COUNTER0 ); + upper =readl (gt_base +GT_COUNTER1 ); + }while (upper != res.upper); + +return res; +}I guess this is some cleverness to avoid wrap-around... A comment stating what's going on wouldn't hurt.
This cleverness is defined in the datasheet
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0407i/CIHGECHJ.html
I will add a comment here.
Quoted 7 lines
But why on earth do you need this complicated union to hold the result? Have two local u32 variables and return a u64 from this function.
Since this will be performance critical, isn't
readl_relaxed()suffient here, or what's the rationale for just usingreadl()?
Yes, it makes sense to go for readl_relaxed here as it is device-memory type.
Quoted 16 lines
arch/arm/kernel/global_timer.c line 83
Quoted 4 lines
arch/arm/kernel/global_timer.c +3
-0+static void gt_compare_set (unsigned long delta,int periodic) +{ +union gt_counter counter =gt_counter_read ();So here you get something easy to read like
u64 counter =
gt_counter_read();arch/arm/kernel/global_timer.c line 89
Quoted 6 lines
arch/arm/kernel/global_timer.c +6
-0+unsigned long ctrl =readl (gt_base +GT_CONTROL ); + +BUG_ON (!(ctrl >_CONTROL_TIMER_ENABLE )); +BUG_ON (ctrl & (GT_CONTROL_COMP_ENABLE | +GT_CONTROL_IRQ_ENABLE | +GT_CONTROL_AUTO_INC ));
Quoted 6 lines
Do you really have to check this *whenever the counter is set*?
Will it not suffice to do this once during initialization?
It looks like some leftover debug code. It also looks kind of clock dangerous, can you explain exactly why this check is here?
I will get this debug out of here.
Quoted 9 lines
arch/arm/kernel/global_timer.c line 93
Quoted 5 lines
arch/arm/kernel/global_timer.c +4
-0+ + counter.cycles += delta; +writel (counter.lower, gt_base +GT_COMP0 ); +writel (counter.upper, gt_base +GT_COMP1 );This is another instance of the union struct making things complicated. With a u64 just:
Quoted 6 lines
counter += delta;
writel(lower_32_bits(counter), gt_base + GT_COMP0);writel(upper_32_bits(counter), gt_base + GT_COMP1);As you can see <
linux/kernel.h> has really nice helpers in place to deal with 64 bit arithmetics.
Same as first comment.
Quoted 14 lines
Quoted 14 lines
arch/arm/kernel/global_timer.c +13
-0+ + ctrl |=GT_CONTROL_COMP_ENABLE |GT_CONTROL_IRQ_ENABLE ; + +if (periodic) { +writel (delta, gt_base +GT_AUTO_INC ); + ctrl |=GT_CONTROL_AUTO_INC ; + } + +writel (ctrl, gt_base +GT_CONTROL ); +} + +static void gt_clockevent_set_mode (enum clock_event_mode mode, +struct clock_event_device *clk)
Quoted 8 lines
arch/arm/kernel/global_timer.c line 110
Quoted 4 lines
arch/arm/kernel/global_timer.c +4
-0+{ +switch (mode) { +case CLOCK_EVT_MODE_PERIODIC : +gt_compare_set (gt_clk_rate/HZ ,1 );Use
gt_compare_set(DIV_ROUND_CLOSEST(gt_clk_rate, HZ), 1); to get integer arithmetics right.
Will move to use DIV_ROUND_CLOSEST.
Quoted 22 lines
arch/arm/kernel/global_timer.c line 117
Quoted 8 lines
arch/arm/kernel/global_timer.c +7
-0+break ; +case CLOCK_EVT_MODE_ONESHOT : +/* period set, and timer enabled in 'next_event' hook */ +BUG_ON (readl (gt_base +GT_CONTROL ) & + (GT_CONTROL_COMP_ENABLE | +GT_CONTROL_IRQ_ENABLE | +GT_CONTROL_AUTO_INC ));Here is another one of these checks. Why aren't you just zeroing these flags if you don't want them, especially since you're writing the register at the end of the function? Now it looks like instead of setting up the timer the way you want it you bug out if it isn't already set up as you want it (hint, the name of this function).
arch/arm/kernel/global_timer.c line 122
Quoted 5 lines
arch/arm/kernel/global_timer.c +5
-0+/* Fall through */ +case CLOCK_EVT_MODE_UNUSED : +case CLOCK_EVT_MODE_SHUTDOWN : +default : +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL );
Quoted 3 lines
Why are you enabling the timer in unused and shutdown mode?
This doesn't make sense.
It is because we are using the global-timer block for both clocksource and clockevents and we do not want the clocksource to disappear when clockevent is unused/shutdown.
Quoted 12 lines
Quoted 12 lines
arch/arm/kernel/global_timer.c +11
-0+break ; + } +} + +static int gt_clockevent_set_next_event (unsigned long evt, +struct clock_event_device *unused) +{ +gt_compare_set (evt,0 ); +return 0 ; +} +
Quoted 8 lines
arch/arm/kernel/global_timer.c line 138
Quoted 5 lines
arch/arm/kernel/global_timer.c +5
-0+static irqreturn_t gt_clockevent_interrupt (int irq,void *dev_id) +{ +struct clock_event_device *evt = *(struct clock_event_device **)dev_id; + +writel (GT_INT_STATUS_EVENT_FLAG , gt_base +GT_INT_STATUS );You're clearing the flag before checking if it was set. What happens if this was a spurious interrupt that should be disregarded?
Makes sense, I will add a check here.
Quoted 15 lines
arch/arm/kernel/global_timer.c line 149
Quoted 12 lines
arch/arm/kernel/global_timer.c +11
-0+ evt->event_handler (evt); + +return IRQ_HANDLED ; +} + +static int __cpuinit gt_clockevents_init (struct clock_event_device *clk) +{ +struct clock_event_device **this_cpu_clk; +int cpu =smp_processor_id (); + + clk->name ="Global Timer CE" ;Name it after the hardware feature. "ARM global timer clock event" there is no need to abbreviate randomly.
Yes, will change all such instances.
Quoted 10 lines
arch/arm/kernel/global_timer.c line 157
Quoted 9 lines
arch/arm/kernel/global_timer.c +8
-0+ clk->features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT ; + clk->set_mode = gt_clockevent_set_mode; + clk->set_next_event = gt_clockevent_set_next_event; + this_cpu_clk =__this_cpu_ptr (gt_evt); + *this_cpu_clk = clk; + clk->irq = gt_ppi; +clockevents_config_and_register (clk, gt_clk_rate, +0xf ,0xffffffff );
Quoted 3 lines
Why can't this clock event handle anything lower than
0xf? Does that come from the datasheet or have you just copied some code?
There is no such limitation on the minimum clock ticks, I think it was copied.
Will fix it in next version.
Quoted 45 lines
Further, since this clock event hardware *most definately* supports using a delta upper bound *beyond* 32 bits, I think the clock event core code should be altered to allow for registereing such clock events, but TGLX may have some idea here. This will work but will not expose the full potential of this 64-bit counter hardware.
Quoted 25 lines
arch/arm/kernel/global_timer.c +25
-0+per_cpu (percpu_init_called, cpu) = true; +enable_percpu_irq (clk->irq,IRQ_TYPE_NONE ); +return 0 ; +} + +static void gt_clockevents_stop (struct clock_event_device *clk) +{ +gt_clockevent_set_mode (CLOCK_EVT_MODE_UNUSED , clk); +disable_percpu_irq (clk->irq); +} + +static int __cpuinit gt_clockevents_setup (struct clock_event_device *clk) +{ +int cpu =smp_processor_id (); + +/* Use existing clock_event for boot cpu */ +if (per_cpu (percpu_init_called, cpu)) +return 0 ; + +writel (0 , gt_base +GT_CONTROL ); +writel (0 , gt_base +GT_COUNTER0 ); +writel (0 , gt_base +GT_COUNTER1 ); +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); + +return gt_clockevents_init (clk);arch/arm/kernel/global_timer.c line 192
Quoted 10 lines
arch/arm/kernel/global_timer.c +10
-0+} + +static cycle_t gt_clocksource_read (struct clocksource *cs) +{ +union gt_counter res =gt_counter_read (); +return res.cycles; +} + +static struct clocksource gt_clocksource = { + .name ="Global Timer CS" ,"ARM global timer clock source"
Quoted 16 lines
Quoted 4 lines
arch/arm/kernel/global_timer.c +4
-0+ .rating = 300, + .read = gt_clocksource_read, + .mask = CLOCKSOURCE_MASK(64), + .flags = CLOCK_SOURCE_IS_CONTINUOUS,arch/arm/kernel/global_timer.c line 206
Quoted 10 lines
arch/arm/kernel/global_timer.c +10
-0+}; + +static void __init gt_clocksource_init (void ) +{ +writel (0 , gt_base +GT_CONTROL ); +writel (0 , gt_base +GT_COUNTER0 ); +writel (0 , gt_base +GT_COUNTER1 ); +writel (GT_CONTROL_TIMER_ENABLE , gt_base +GT_CONTROL ); + + gt_clocksource.shift =20 ;So how did you come up with that?
Hmm..
You are right, this should not be a constant here, I will use clocksource_register_hz instead.
-srini
Quoted 20 lines
arch/arm/kernel/global_timer.c line 209
Quoted 4 lines
arch/arm/kernel/global_timer.c +3
-0+ gt_clocksource.mult = +clocksource_hz2mult (gt_clk_rate, gt_clocksource.shift); +clocksource_register (>_clocksource);Why don't you just replace all of this hazzle with:
clocksource_register_hz(>_clocksource, gt_clk_rate);That will calculate mult and shift for you? (Leave these unassigned.)
Since the hpet timer does this it's pretty well tested...
No more comments right now...
Yours,
Linus Walleij
RFC 2/8 ARM:global_timer: Add ARM global timer support.
Quoted 9 lines · Srinivas KANDAGATLA
Quoted 3 lines · Linus Walleij
Why are you enabling the timer in unused and shutdown mode?
This doesn't make sense.
It is because we are using the global-timer block for both clocksource and clockevents and we do not want the clocksource to disappear when clockevent is unused/shutdown.
As this is clearly a per-cpu timer (correct? atleast the driver is written that way) and say you have 4 CPUs, why would you not shut down the timer on cores 1,2,3 and only leave the timer on core 0 on?
The kernel will by necessity not shut down the clock event on core 0 anyway.
On a related note: don't you want to use the counter in this block as sched_clock() as well? (I guess so, as you do not seem to have anything else on this system.) It'd probably need to be a separate Kconfig option and can surely be done later but keep it in mind.
Yours,
Linus Walleij
RFC 2/8 ARM:global_timer: Add ARM global timer support.
Quoted 8 lines · Linus Walleij
Quoted 6 lines · Srinivas KANDAGATLA
Quoted 3 lines · Linus Walleij
Why are you enabling the timer in unused and shutdown mode?
This doesn't make sense.
Quoted 8 lines
Quoted 3 lines
It is because we are using the global-timer block for both clocksource and clockevents and we do not want the clocksource to disappear when clockevent is unused/shutdown.
As this is clearly a per-cpu timer (correct? atleast the driver is written that way) and say you have 4 CPUs, why would you not shut down the timer on cores 1,2,3 and only leave the timer on core 0 on?
I think it makes sense to shutdown the timer on other cores on request. I will fix this.
Quoted 7 lines
The kernel will by necessity not shut down the clock event on core 0 anyway.
On a related note: don't you want to use the counter in this block as
sched_clock()as well? (I guess so, as you do not seem to have anything else on this system.) It'd probably need to be a separateKconfigoption and can surely be done later but keep it in mind.
Thankyou for the advice,
I will definitely try to implement this.
Thanks,
srini
Quoted 4 lines
Yours,
Linus Walleij
RFC 3/8 mfd:syscon: Introduce claim/read/write/release APIs
In reply to Srinivas KANDAGATLAFrom: Srinivas Kandagatla <[email protected]>
This patch introduces syscon_claim, syscon_read, syscon_write, syscon_release APIs to help drivers to use syscon registers in much more flexible way.
With this patch, a driver can claim few/all bits in the syscon registers and do read/write and then release them when its totally finished with them, in the mean time if another driver requests same bits or registers the API will detect conflit and return error to the second request.
Reason to introduce this API.
System configuration/control registers are very basic configuration registers arranged in groups across ST Settop Box parts. These registers are independent of IP itself. Many IPs, clock, pad and other functions are wired up to these registers.
In many cases a single syconf register contains bits related to multiple devices, and therefore it need to be shared across multiple drivers at bit level. The same IP block can have different syscon mappings on different SOCs.
Typically in a SOC there will be more than hundreds of these registers, which are again divided into groups.
--- drivers/mfd/syscon.c | 199 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 43 ++++++++++ 2 files changed, 242 insertions(+), 0 deletions(-)
drivers/mfd/syscon.c +199 -0
@@ -16,6 +16,7 @@#include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/slab.h> #include <linux/of_address.h> #include <linux/of_platform.h> #include <linux/platform_device.h>
@@ -28,8 +29,23 @@ struct syscon {struct device *dev;void __iomem *base;struct regmap *regmap; +struct device_node *of_node; +struct list_head list; +struct list_head fields; +spinlock_t fields_lock; }; +struct syscon_field { +struct syscon *syscon; +u16 num; +u8 lsb, msb; +unsigned int offset; +const char *owner; +struct list_head list; +}; + +static LIST_HEAD (syscons); +static int syscon_match (struct device *dev,void *data) {struct syscon *syscon =dev_get_drvdata (dev);
@@ -87,6 +103,185 @@ struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np, }EXPORT_SYMBOL_GPL (syscon_regmap_lookup_by_phandle); +static int syscon_add_field (struct syscon_field *field) +{ +struct syscon_field *entry; +enum { + status_not_found, + status_found_register, + status_add_field_here, + } status = status_not_found; +int bit_avail =0 ; +struct syscon *syscon = field->syscon; +int rval =0 ; +int num = field->num; +int lsb = field->lsb; +int msb = field->msb; + +spin_lock (&syscon->fields_lock); +/* +* The list is always in syscon->num->lsb/msb order, so it's easy to +* find a place to insert a new field (and to detect conflicts) +*/ +list_for_each_entry (entry, &syscon->fields, list) { +if (entry->num == num) { + status = status_found_register; +/* +* Someone already claimed a field from this +* register - let's try to find some space for +* requested bits... +*/ +if (bit_avail <= lsb && msb < entry->lsb) { + status = status_add_field_here; +break ; + } + bit_avail = entry->msb +1 ; + }else if (entry->num > num) { +/* +* There is no point of looking further - +* the num values are bigger then +* the ones we are looking for +*/ +if ((status == status_found_register && + bit_avail <= lsb) || + status == status_not_found) +/* +* A remainder of the given register is not +* used or the register wasn't used at all +*/ + status = status_add_field_here; +else +/* +* Apparently some bits of the claimed field +* are already in use... +*/ + rval = -EBUSY ; +break ; + } + } + +if ((status == status_not_found) || (status == status_found_register)) +list_add_tail (&field->list, &syscon->fields); +else if (status == status_add_field_here) +list_add (&field->list, entry->list.prev); + +spin_unlock (&syscon->fields_lock); +return rval; +} + +static struct syscon *find_syscon (struct device_node *np) +{ +struct syscon *syscon; + +list_for_each_entry (syscon, &syscons, list) { +if (syscon->of_node == np) +return syscon; + } +return NULL ; +} + +#define MIN_SYSCON_CELLS (4) + +struct syscon_field *syscon_claim (struct device_node *np, +const char *prop) +{ +const __be32 *list; +const struct property *pp; +struct syscon_field *field; +phandle phandle; +struct device_node *syscon_np; +u32 syscon_num; + + pp =of_find_property (np, prop,NULL ); +if (!pp) +return NULL ; + +if (pp->length < ((MIN_SYSCON_CELLS ) *sizeof (*list))) +return NULL ; + + list = pp->value; + +/* syscon */ + phandle =be32_to_cpup (list++); + syscon_np =of_find_node_by_phandle (phandle); +if (!syscon_np) { +pr_warn ("No syscon found for %s syscon\n" , prop); +return NULL ; + } + + field =kzalloc (sizeof (struct syscon_field ),GFP_KERNEL ); +if (!field) +return NULL ; + + field->syscon =find_syscon (syscon_np); +if (!field->syscon) { +pr_warn ("No syscon registered for %s syscon\n" , prop); + goto error; + } + +of_node_put (syscon_np); + syscon_num =be32_to_cpup (list++); + field->offset = (syscon_num) *4 ; + field->lsb =be32_to_cpup (list++); + field->msb =be32_to_cpup (list++); + field->num = syscon_num; + field->owner = pp->name; + +if (syscon_add_field (field)) + goto error; + +return field; +error: +kfree (field); +return NULL ; +} +EXPORT_SYMBOL (syscon_claim); + +void syscon_release (struct syscon_field *field) +{ +struct syscon *syscon; +if (field) { + syscon = field->syscon; +spin_lock (&syscon->fields_lock); +list_del (&field->list); +spin_unlock (&syscon->fields_lock); +kfree (field); + } +} +EXPORT_SYMBOL (syscon_release); + +void syscon_write (struct syscon_field *field,unsigned long value) +{ +int field_bits; +struct syscon *syscon = field->syscon; + + field_bits = field->msb - field->lsb +1 ; +if (field_bits ==32 ) { +regmap_write (syscon->regmap, field->offset, value); + }else { +u32 reg_mask; + reg_mask = (((1 << field_bits) -1 ) << field->lsb); +regmap_update_bits (syscon->regmap, field->offset, + reg_mask, value << field->lsb); + } +} +EXPORT_SYMBOL (syscon_write); + +unsigned long syscon_read (struct syscon_field *field) +{ +int field_bits; +u32 result; +struct syscon *syscon = field->syscon; + +regmap_read (syscon->regmap, field->offset, &result); + field_bits = field->msb - field->lsb +1 ; + result >>= field->lsb; + result &= (1 << field_bits) -1 ; + +return result; +} +EXPORT_SYMBOL (syscon_read); +static const struct of_device_id of_syscon_match[] = { { .compatible ="syscon" , }, { },
@@ -122,6 +317,10 @@ static int syscon_probe(struct platform_device *pdev)if (ret)return ret; +list_add_tail (&syscon->list, &syscons); +INIT_LIST_HEAD (&syscon->fields); + syscon->of_node = np; + syscon_regmap_config.max_register = res.end - res.start -3 ; syscon->regmap =devm_regmap_init_mmio (dev, syscon->base, &syscon_regmap_config);
include/linux/mfd/syscon.h +43 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.6.5
Arnd Bergmann
maintainerRe: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 22 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
This patch introduces
syscon_claim,syscon_read,syscon_write,syscon_releaseAPIs to help drivers to use syscon registers in much more flexible way.With this patch, a driver can claim few/all bits in the syscon registers and do read/write and then release them when its totally finished with them, in the mean time if another driver requests same bits or registers the API will detect conflit and return error to the second request.
Reason to introduce this API.
System configuration/control registers are very basic configuration registers arranged in groups across ST Settop Box parts. These registers are independent of IP itself. Many IPs, clock, pad and other functions are wired up to these registers.In many cases a single syconf register contains bits related to multiple devices, and therefore it need to be shared across multiple drivers at bit level. The same IP block can have different syscon mappings on different SOCs.
Quoted 5 lines
Typically in a SOC there will be more than hundreds of these registers, which are again divided into groups.
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stuart Menefy <[email protected]>
My feeling is that syscon is the wrong place for this functionality, since regmap already handles (some of?) these issues. If you need additional synchronization, it's probably best to extend regmap as needed so other code besides syscon can take advantage of that as well.
Arnd
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 10 lines · Arnd Bergmann
Quoted 4 lines
In many cases a single syconf register contains bits related to multiple devices, and therefore it need to be shared across multiple drivers at bit level. The same IP block can have different syscon mappings on different SOCs.
My feeling is that syscon is the wrong place for this functionality, since regmap already handles (some of?) these issues. If you need additional synchronization, it's probably best to extend regmap as needed so other code besides syscon can take advantage of that as well.
This sounds like regmap_update_bits() ought to be all that's needed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130508/7fc89de4/attachment.sig>
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Thankyou for the comments.
Quoted 6 lines · Mark Brown
Quoted 4 lines · Arnd Bergmann
Quoted 4 lines
In many cases a single syconf register contains bits related to multiple devices, and therefore it need to be shared across multiple drivers at bit level. The same IP block can have different syscon mappings on different SOCs.
Quoted 6 lines
Quoted 5 lines
My feeling is that syscon is the wrong place for this functionality, since regmap already handles (some of?) these issues. If you need additional synchronization, it's probably best to extend regmap as needed so other code besides syscon can take advantage of that as well.
This sounds like
regmap_update_bits()ought to be all that's needed.
Ultimately the syscon_write use the regmap_update_bits, however we really want is the flexibility in using/referring the syscon registers/bits in both device-trees and non-device tree cases.
The reason for these APIs, is the extent of syscon usage is very high in ST set-top-box parts.
Without these new APIs, its very difficult to pass this information to the drivers.
Thanks,
srini
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
On Wed, May 08, 2013 at 06:42:04PM +0100, Srinivas KANDAGATLA wrote:
Fix your mailer to word wrap within paragraphs.
Quoted 3 lines
Ultimately the
syscon_writeuse theregmap_update_bits, however we really want is the flexibility in using/referring the syscon registers/bits in both device-trees and non-device tree cases.
So what you're looking for here is some way to offload discovery of register fields from the driver?
Quoted 5 lines
The reason for these APIs, is the extent of syscon usage is very high in ST set-top-box parts.
Without these new APIs, its very difficult to pass this information to the drivers.
I'm not 100% convinced that putting all this information into DT is a
good idea, and to the extent that it is sensible it feels like something
which might be useful with any device using register maps, not just
syscon. For example many MFDs have similar needs - essentially the
system controllers are just a particular kind of MFD. To me that says
that this should be outside syscon so other things can use it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130509/204dd9d8/attachment.sig>
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 4 lines · Mark Brown
On Wed, May 08, 2013 at 06:42:04PM +0100, Srinivas KANDAGATLA wrote:
Fix your mailer to word wrap within paragraphs.
Sorry about that.
Quoted 6 lines
Quoted 3 lines
Ultimately the
syscon_writeuse theregmap_update_bits, however we really want is the flexibility in using/referring the syscon registers/bits in both device-trees and non-device tree cases.So what you're looking for here is some way to offload discovery of register fields from the driver?
Exactly,
As the System configuration registers change per each SOC, and the logic/code to drive still remain same across SOCs.
It makes sense to abstract the information of sysconf register and its offsets from the driver, as we do not want to change the driver per each SOC.
Quoted 9 lines
Quoted 6 lines
The reason for these APIs, is the extent of syscon usage is very high in ST set-top-box parts.
Without these new APIs, its very difficult to pass this information to the drivers.
I'm not 100% convinced that putting all this information into DT is a good idea,
Currently, we have two bits of information which come from device trees. 1> The syscon bank/group definition itself.
2> syscon register offsets and bits information to the drivers.
These are the 2 things which keep changing per each SOC.
There is no other way to pass this information to the drivers other than passing them as part of their own device node and syscon node.
Quoted 3 lines
and to the extent that it is sensible it feels like something
which might be useful with any device using register maps, not just syscon.
If you think this is going to be useful for other drivers, Am happy to
move this out of syscon to regmap something like adding of_regmap_field_claim/regmap_field_claim/regmap_field_read/regmap_field_write/regmap_field_release functions.
so any exiting drivers can still use the old syscon API to get the regmap instance.
Alternatively they can use the new regmap APIs directly.
regmap_field_claim to claim bits of the register of_regmap_field_claim DT version of reg_map_field_claim. regmap_field_write to write to bits of register regmap_field_read to bit of the register. regmap_field_release to release the bits of the register.
For DT version it might involve adding new member to struct regmap_config to lookup regmap by phandle, so that regmap can get hold of regmap instance from device tree phandle.
syscon driver already does this in syscon_regmap_lookup_by_phandle()
On the device tree side it will look like:
syscfg_sbc:syscon at fe600000{
compatible = "syscon";
reg = <0xfe600000 0x1000>;
};node {
property-1 = <&syscfg_sbc 10 0 31>;
};property has "phandle", register_offset, lsb, msb.
On the driver side, it can just use the API's like
field = of_regmap_field_claim(np, "property-1");regmap_field_write(field, val);regmap_field_release(field);
All this involves is very minimal code change in syscon and a new APIs and DT awareness into regmap.
What do you think?
Thanks,
srini
Quoted 5 lines
For example many MFDs have similar needs - essentially the
system controllers are just a particular kind of MFD. To me that says that this should be outside syscon so other things can use it.
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 8 lines · Srinivas KANDAGATLA
Currently, we have two bits of information which come from device trees. 1> The syscon bank/group definition itself.
2> syscon register offsets and bits information to the drivers.These are the 2 things which keep changing per each SOC.
There is no other way to pass this information to the drivers other than passing them as part of their own device node and syscon node.
Sure there is, for example the drivers could have this information internally as part of knowing which device they're working with or they could take advantage of some patterns in the register map to store some higher level information that they use to configure.
Quoted 4 lines
Quoted 3 lines
and to the extent that it is sensible it feels like something
which might be useful with any device using register maps, not just syscon.
Quoted 8 lines
If you think this is going to be useful for other drivers, Am happy to
move this out of syscon to regmap something like adding of_regmap_field_claim/regmap_field_claim/regmap_field_read/regmap_field_write/regmap_field_release functions.so any exiting drivers can still use the old syscon API to get the regmap instance.
Alternatively they can use the new regmap APIs directly.
Well, I'd need to see the code to decide if it was sane but I do think
that if this is a good approach it's not syscon specific. Anything like
this needs to be independent of DT too since not all architectures use
DT.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130509/4d182b81/attachment.sig>
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 8 lines · Mark Brown
Quoted 5 lines · Srinivas KANDAGATLA
Currently, we have two bits of information which come from device trees. 1> The syscon bank/group definition itself.
2> syscon register offsets and bits information to the drivers.These are the 2 things which keep changing per each SOC.
Quoted 8 lines
Quoted 2 lines
There is no other way to pass this information to the drivers other than passing them as part of their own device node and syscon node.
Sure there is, for example the drivers could have this information internally as part of knowing which device they're working with or they could take advantage of some patterns in the register map to store some higher level information that they use to configure.
Some of layouts of the sysconf registers are totally changed for each SOC.
Looking at driver by driver maybe some drivers can take advantage of the patterns, but Am not sure if this will be a sustainable solution for all the drivers.
The big disadvantage of this approach is that
- Every driver has to be touched for new SOC,
- Secondly the drivers will end up having more of such information than code over a time.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
and to the extent that it is sensible it feels like something
which might be useful with any device using register maps, not just syscon.If you think this is going to be useful for other drivers, Am happy to
move this out of syscon to regmap something like adding of_regmap_field_claim/regmap_field_claim/regmap_field_read/regmap_field_write/regmap_field_release functions.
Quoted 8 lines
Quoted 3 lines
so any exiting drivers can still use the old syscon API to get the regmap instance.
Alternatively they can use the new regmap APIs directly.Well, I'd need to see the code to decide if it was sane but I do think that if this is a good approach it's not syscon specific. Anything like this needs to be independent of DT too since not all architectures use DT.
In the suggested approach, the API supports, both DT and non-DT style.
for DT style user can use.of_regmap_field_claim -> regmap_field_read -> regmap_field_write- ->regmap_field_release
and for NON-DT user can useregmap_field_claim -> regmap_field_read -> regmap_field_write- ->regmap_field_release
thanks,
srini
Quoted 1 line
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 5 lines · Srinivas KANDAGATLA
Some of layouts of the sysconf registers are totally changed for each SOC.
Looking at driver by driver maybe some drivers can take advantage of the patterns, but Am not sure if this will be a sustainable solution for all the drivers.
So what exactly is the driver doing then? If the register maps look
nothing like each other then what's the common functionality the driver
is providing?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130509/3a2e6598/attachment.sig>
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 3 lines · Mark Brown
So what exactly is the driver doing then? If the register maps look nothing like each other then what's the common functionality the driver is providing?
What I meant here is that, sysconf registers are reassigned per SOC, so the sysconf register definitions change per SOC, not the register map of the device itself.
The register map of the device itself still looks the same, however few bits of the IP are wired up to the global sysconf registers, which is what keeps changing, w.r.t sysconf number or bits of the sysconf itself.
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
In reply to Mark BrownHi Marc,
I would like to explain you bit more about "ST System Configuration registers".
The SOCs are assembled from existing IP blocks, which don't change very often. However these blocks are assembled in different configurations to meet the device requirements. So most IP blocks as well as having a bus interface through which their own registers are accessible, will also have a number of bristles(wires) which are signals that are going in and out of the IP for configuration and status. To make these signals accessible to software they are wired to "System Configuration Registers".
Drivers target the IP blocks, which don't change much. Where as the mapping of IP specific bristles(wires) to "System Configuration Registers" do change per each SOC, and therefore we do not want this information to be part of the driver.
Having a System Configuration infrastructure gives much flexibility and abstraction to drivers to configure them.
Given the comments on the patch, I am inclined not to use syscon for ST specific "System Configuration Registers", alternatively I would like to create a separate mfd system configuration driver specific to ST.
This is how we did it initially in the out-of-tree kernel.
http://git.stlinux.com/?p=stm/linux-stm.git;a=blob;f=drivers/stm/sysconf.c
Any suggestions?
thanks,
srini
Quoted 24 lines · Mark Brown
On Wed, May 08, 2013 at 06:42:04PM +0100, Srinivas KANDAGATLA wrote:
Fix your mailer to word wrap within paragraphs.
Quoted 3 lines
Ultimately the
syscon_writeuse theregmap_update_bits, however we really want is the flexibility in using/referring the syscon registers/bits in both device-trees and non-device tree cases.So what you're looking for here is some way to offload discovery of register fields from the driver?
Quoted 5 lines
The reason for these APIs, is the extent of syscon usage is very high in ST set-top-box parts.
Without these new APIs, its very difficult to pass this information to the drivers.
I'm not 100% convinced that putting all this information into DT is a good idea, and to the extent that it is sensible it feels like something which might be useful with any device using register maps, not just syscon. For example many MFDs have similar needs - essentially the system controllers are just a particular kind of MFD. To me that says that this should be outside syscon so other things can use it.
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
In reply to Arnd BergmannThankyou for your comments.
Quoted 26 lines · Arnd Bergmann
Quoted 25 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
This patch introduces
syscon_claim,syscon_read,syscon_write,syscon_releaseAPIs to help drivers to use syscon registers in much more flexible way.With this patch, a driver can claim few/all bits in the syscon registers and do read/write and then release them when its totally finished with them, in the mean time if another driver requests same bits or registers the API will detect conflit and return error to the second request.
Reason to introduce this API.
System configuration/control registers are very basic configuration registers arranged in groups across ST Settop Box parts. These registers are independent of IP itself. Many IPs, clock, pad and other functions are wired up to these registers.In many cases a single syconf register contains bits related to multiple devices, and therefore it need to be shared across multiple drivers at bit level. The same IP block can have different syscon mappings on different SOCs.
Typically in a SOC there will be more than hundreds of these registers, which are again divided into groups.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stuart Menefy <[email protected]>My feeling is that syscon is the wrong place for this functionality, since regmap already handles (some of?) these issues. If you need additional synchronization, it's probably best to extend regmap as needed so other code besides syscon can take advantage of that as well.
Its not just synchronisation that we are looking for. It also the usability, drivers want to just refer to a syscon register/bits of it from device trees/non-devicetrees.
The extent of syscon usage is very high in ST set-top-box parts. As example, ST pinctrl driver uses use bits of the syscon register to control alternate functions, and many other parameters of pinconf.
In device tree we do something like:
syscfg_sbc: syscon at fe600000{
compatible = "syscon";
reg = <0xfe600000 0xb4>;
};
and in pinctrl dts file
st,alt-control = <&syscfg_sbc 0 0 31>;
st,od-control = <&syscfg_sbc 9 0 7>;the pinctrl driver calls syconf_claim(np, "st,alt-control) to get a field and then do a read/write on the field.
Just in pinctrl driver we use around 50-100 sysconf registers scatters across different groups.
Without these new APIs, its very difficult to pass this information to the drivers.
Thanks,
srini
Quoted 3 lines
Arnd
Arnd Bergmann
maintainerRe: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 8 lines · Srinivas KANDAGATLA
the pinctrl driver calls
syconf_claim(np, "st,alt-control)to get a field and then do a read/write on the field.Just in pinctrl driver we use around 50-100 sysconf registers scatters across different groups.
Without these new APIs, its very difficult to pass this information to the drivers.
But are those necessarily things you would configure using DT?
If there are so many registers that are shared between mutliple subsystems, maybe using drivers/mfd/syscon for that is taking things further than you should, since it is unlike what any of the other SoC families need from syscon.
Can you describe how your syscon registers are laid out? Which subsystems beside pinctrl need to directly interact with it? Is there any logical structure in it or do you just have tons of bits scattered around an MMIO area?
Arnd
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Hi Arnd,
Thankyou for extending the discussion.
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · Srinivas KANDAGATLA
the pinctrl driver calls
syconf_claim(np, "st,alt-control)to get a field and then do a read/write on the field.Just in pinctrl driver we use around 50-100 sysconf registers scatters across different groups.
Without these new APIs, its very difficult to pass this information to the drivers.
But are those necessarily things you would configure using DT?
In last comment.
Quoted 5 lines
If there are so many registers that are shared between mutliple subsystems, maybe using
drivers/mfd/sysconfor that is taking things further than you should, since it is unlike what any of the other SoC families need from syscon.
I agree, my initial approach was having a dedicated driver specific to ST syscon, however syscon seems to do things very much similar to what we want, so I have integrated those 3 functions in syscon. Am happy to go back with my first approach of adding ST specific syscon driver if no one is actually going to benefit with such a change to syscon driver.
Quoted 2 lines
Can you describe how your syscon registers are laid out?
On STiH416 SOC we have 9 SYSCONF(aka System Configuration Registers)named banks/groups, each bank has its own memory map. Each sysconf bank has number of 32 bit registers which vary from bank to bank, like sysconf bank "sbc" has range from SYSTEM_CONFIG0 to SYSTEM_CONFIG999 where as sysconf bank "front" has range of SYSTEM_CONFIG1000 to SYSTEM_CONFIG1999 and so on.
Each register is assigned with a unique SYCONF number, example:SYSTEM_CONFIG100, SYSTEM_CONFIG101 , .. and so on.
Each sysconf contains bits of the IP configurations wired-up to the sysconf register bits.
As example:
- Each pinctrl entry for set of 8 pins uses around 8-10 sysconfig register to control pinconf and pin functions.
- IPs like Ethernet have few bit like Ethernet-Mode selection external or internal phyclk wired up to bits in sysconf registers,
- Few clocks are controlled by sysconf registers.
- Reset to IPs are wired up to bits of sysconf same registers.
- ARM core soft reset is wired up to the sysconf registers... And most of the IPs have similar requirements ......
Total layout of the sysconf changes per SOC, and the bit arrangements aswell, however the core IP(pinctrl, etherenet ...) and logic to drive those bits remains exactly same.
As the code remains the same, the information about the hardware configuration and offsets to the registers are passed by device trees using the node properties.
In general the requirements of the sysconf support to the SOC/driver support is.
1> It should be able to read/write a sysconf register bits without having to "if" each SOC in the code. So that code is totally abstracted. Which is currently achieved by passing the information from the device trees and the driver just uses the property to get it.
2> The infrastructure should protect the claimed registers from over-writing by other drivers. We do this by claim-read/write-release style API.
3> The driver should be able to set a group of sysconf registers bits to a particular values before initialises the IP. I was thinking of doing this in a same way as pinctrl state.
Any suggestion is most appreciated?
Thanks,
srini
Quoted 6 lines
Which subsystems beside pinctrl need to directly interact with it? Is there any logical structure in it or do you just have tons of bits scattered around an MMIO area?
Arnd
Arnd Bergmann
maintainerRe: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 7 lines · Srinivas KANDAGATLA
On 08/05/13 20:48, Arnd Bergmann wrote:
I agree, my initial approach was having a dedicated driver specific to ST syscon, however syscon seems to do things very much similar to what we want, so I have integrated those 3 functions in syscon. Am happy to go back with my first approach of adding ST specific syscon driver if no one is actually going to benefit with such a change to syscon driver.
That would at least be less controversial.
Quoted 8 lines
Quoted 1 line
Can you describe how your syscon registers are laid out?
On STiH416 SOC we have 9 SYSCONF(aka System Configuration Registers)named banks/groups, each bank has its own memory map. Each sysconf bank has number of 32 bit registers which vary from bank to bank, like sysconf bank "sbc" has range from
SYSTEM_CONFIG0toSYSTEM_CONFIG999where as sysconf bank "front" has range ofSYSTEM_CONFIG1000toSYSTEM_CONFIG1999and so on.
Quoted 4 lines
Each register is assigned with a unique SYCONF number, example:
SYSTEM_CONFIG100,SYSTEM_CONFIG101, .. and so on.
Each sysconf contains bits of the IP configurations wired-up to the sysconf register bits.
Ok.
Quoted 11 lines
As example:
- Each pinctrl entry for set of 8 pins uses around 8-10 sysconfig register to control pinconf and pin functions.
- IPs like Ethernet have few bit like Ethernet-Mode selection external or internal phyclk wired up to bits in sysconf registers,
- Few clocks are controlled by sysconf registers.
- Reset to IPs are wired up to bits of sysconf same registers.
- ARM core soft reset is wired up to the sysconf registers... And most of the IPs have similar requirements ......
Quoted 3 lines
Total layout of the sysconf changes per SOC, and the bit arrangements aswell, however the core
IP(pinctrl, etherenet ...)and logic to drive those bits remains exactly same.
It sounds like you really need a driver with high-level interfaces for the bits that change by each core and are needed by otherwise identical drivers, like the Ethernet driver you mention.
I would not go as far as you did describing the individual bits in the device node using these however. That driver can be layered on top of the existing syscon driver, but hardcode the bits for each SoC it knows of.
For drivers that are essentially just wrappers around sysconf, I would make them one driver per SoC and use a low-level interface but still hardcode the offsets in the driver instead of using DT to find the registers.
The pinctrl and reset drivers are examples of this.
Quoted 6 lines
In general the requirements of the sysconf support to the SOC/driver support is.
1> It should be able to read/write a sysconf register bits without having to "if" each SOC in the code. So that code is totally abstracted. Which is currently achieved by passing the information from the device trees and the driver just uses the property to get it.
The goal sounds fine, just the method is a bit more complex than necessary here I think.
Quoted 3 lines
2> The infrastructure should protect the claimed registers from over-writing by other drivers. We do this by claim-read/write-release style API.
I don't understand this part. Is it about atomicity of accesses to 32-bit registers when you only want to change a bit? That is something the regmap interface handles already.
If this is about drivers touching registers they should not touch in the first place, I think it should not be needed at all, because that would be a driver bug, and you can't really protect yourself from broken drivers anyway.
Quoted 3 lines
3> The driver should be able to set a group of sysconf registers bits to a particular values before initialises the IP. I was thinking of doing this in a same way as pinctrl state.
That does not fit well with the model we use for other subsystems. If possible, try to use the existing abstractions for clock, regulator, pinctrl, reset, etc. and call generic interfaces from the driver. When that does not work, create a high-level function call from your sysconf driver to do a particular thing (e.g. stih_sysconf_ethernet_set_phy_mode()) rather than set up random bits from the driver.
Arnd
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Hi Arnd,
Thankyou for the comments.
Quoted 10 lines · Arnd Bergmann
Quoted 7 lines · Srinivas KANDAGATLA
On 08/05/13 20:48, Arnd Bergmann wrote:
I agree, my initial approach was having a dedicated driver specific to ST syscon, however syscon seems to do things very much similar to what we want, so I have integrated those 3 functions in syscon. Am happy to go back with my first approach of adding ST specific syscon driver if no one is actually going to benefit with such a change to syscon driver.That would at least be less controversial.
yes I agree.
Quoted 5 lines
Quoted 4 lines
Total layout of the sysconf changes per SOC, and the bit arrangements aswell, however the core
IP(pinctrl, etherenet ...)and logic to drive those bits remains exactly same.
Quoted 8 lines
It sounds like you really need a driver with high-level interfaces for the bits that change by each core and are needed by otherwise identical drivers, like the Ethernet driver you mention.
I would not go as far as you did describing the individual bits in the device node using these however. That driver can be layered on top of the existing syscon driver, but hardcode the bits for each SoC it knows of.
Some of the drivers like Ethernet already provide higher level interfaces via callbacks. We did implement such a callbacks per each SOC in non-DT case, and ended up having code duplicated for each SOC.
On the other hand using device trees to describe the HW configuration(sysconfs) made more sense and got rid of SOC specific callbacks.
Quoted 7 lines
For drivers that are essentially just wrappers around sysconf, I would make them one driver per SoC and use a low-level interface but still hardcode the offsets in the driver instead of using DT to find the registers.
The pinctrl and reset drivers are examples of this.
In pinctrl bindings case, I think we could do better job by replacing the existing bindings of sysconfs for a group of banks with just two integer offsets. This would mean that, we can still use the a common driver across the SOCs.
And w.r.t to reset, we are planning on using sysconf based reset-controller API sitting underneath the reset-controller subsystem. Passing the information from device trees would be much clear and flexible than adding new driver per/SOC.
Quoted 7 lines
Quoted 3 lines
2> The infrastructure should protect the claimed registers from over-writing by other drivers. We do this by claim-read/write-release style API.
I don't understand this part. Is it about atomicity of accesses to 32-bit registers when you only want to change a bit? That is something the regmap interface handles already.
I forget to mention a important point here, the protection is at bit level for the sysconfs. Some of sysconfs have bits shared across IPs, so protecting them while the IP is still using it is what we are trying to achieve with sysconf-claim/release apis.
While it may be overkill, but In past it has found bugs and been helpful with a meaning full debug output.
Quoted 10 lines
Quoted 3 lines
3> The driver should be able to set a group of sysconf registers bits to a particular values before initialises the IP. I was thinking of doing this in a same way as pinctrl state.
That does not fit well with the model we use for other subsystems. If possible, try to use the existing abstractions for clock, regulator, pinctrl, reset, etc. and call generic interfaces from the driver. When that does not work, create a high-level function call from your sysconf driver to do a particular thing (e.g.
stih_sysconf_ethernet_set_phy_mode()) rather than set up random bits from the driver.
I agree going for a higher level api in this case makes sense.
Thanks,
srini
Quoted 4 lines
Arnd
Arnd Bergmann
maintainerRe: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 9 lines · Srinivas KANDAGATLA
On 17/05/13 15:36, Arnd Bergmann wrote:
Some of the drivers like Ethernet already provide higher level interfaces via callbacks. We did implement such a callbacks per each SOC in non-DT case, and ended up having code duplicated for each SOC.
On the other hand using device trees to describe the HW configuration(sysconfs) made more sense and got rid of SOC specific callbacks.
I'm sure it's possible to reduce the duplication without going all the way to describing every bit in DT.
Quoted 12 lines
Quoted 6 lines
For drivers that are essentially just wrappers around sysconf, I would make them one driver per SoC and use a low-level interface but still hardcode the offsets in the driver instead of using DT to find the registers.
The pinctrl and reset drivers are examples of this.
In pinctrl bindings case, I think we could do better job by replacing the existing bindings of sysconfs for a group of banks with just two integer offsets. This would mean that, we can still use the a common driver across the SOCs.
Quoted 4 lines
And w.r.t to reset, we are planning on using sysconf based reset-controller API sitting underneath the reset-controller subsystem. Passing the information from device trees would be much clear and flexible than adding new driver per/SOC.
Ok
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
2> The infrastructure should protect the claimed registers from over-writing by other drivers. We do this by claim-read/write-release style API.
I don't understand this part. Is it about atomicity of accesses to 32-bit registers when you only want to change a bit? That is something the regmap interface handles already.
Quoted 6 lines
I forget to mention a important point here, the protection is at bit level for the sysconfs. Some of sysconfs have bits shared across IPs, so protecting them while the IP is still using it is what we are trying to achieve with sysconf-claim/release apis.
While it may be overkill, but In past it has found bugs and been helpful with a meaning full debug output.
Can you give an example of something that is shared across multiple IPs?
Are those always done in the way that you have e.g. the ethernet pinctrl in the same register as the usb pinctrl, or could you have an ethernet pinctrl setting mixed together with the usb clock setting for instance?
If the hardware has been designed in a sensible way rather than just grown by randomly adding bits in open spaces, I would assume that it's possible to have high-level interfaces built around ranges of registers rather than arbitrary subsets of registers.
Arnd
Re: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
On 23/05/13 22:44, Arnd Bergmann wrote:
Thankyou Arnd for extending this discussion.
Quoted 9 lines · Srinivas KANDAGATLA
Quoted 5 lines · Arnd Bergmann
On the other hand using device trees to describe the HW configuration(sysconfs) made more sense and got rid of SOC specific callbacks.
I'm sure it's possible to reduce the duplication without going all the way to describing every bit in DT.
Yes, I agree with you. I think just passing the offset information from DT would enough in cases like Ethernet or USB where the sysconf registers tend to be mostly standard. And the generic higher level function should be able to do the rest.
Quoted 9 lines
Quoted 6 lines
I forget to mention a important point here, the protection is at bit level for the sysconfs. Some of sysconfs have bits shared across IPs, so protecting them while the IP is still using it is what we are trying to achieve with sysconf-claim/release apis.
While it may be overkill, but In past it has found bugs and been helpful with a meaning full debug output.Can you give an example of something that is shared across multiple IPs?
Quoted 8 lines
Are those always done in the way that you have e.g. the ethernet pinctrl in the same register as the usb pinctrl, or could you have an ethernet pinctrl setting mixed together with the usb clock setting for instance?
If the hardware has been designed in a sensible way rather than just grown by randomly adding bits in open spaces, I would assume that it's possible to have high-level interfaces built around ranges of registers rather than arbitrary subsets of registers.
We have decided to go with using higher level functions as you suggested, hopefully based on regmap with some helper functions on top of it.
System configuration registers in the past used to very much shared across IPs, However with the new chips they seems be mostly dedicated registers for specific IP configurations.
As we have no plans to support very old chips, So I think I can move this out bit level information from device tree and add a higher level functions to be accessed by the drivers.
As an example the below sysconf register for a STi7105 chip(Very old SOC) looks like:SYSTEM_CONFIG7 Comms/Ethernet config control register
[31:28] RESERVED
[27] ENMII:
1: MII mode 0: Reverse MII mode
[26:25] PHY_INTF_SELECT: Selects the type of Ethernet mode
00: MII mode (Default)
01: Reserved
1x: Reserved
[23] GLOBAL_POWER_DOWN:
1: Activate low power
[24] RESERVED
0: Normal mode
[22] DAA_CONFIG_CTRL: DAA configuration control
[21] RESERVED
[20] MAC_SPEED_SEL:
1: Indicates that the MAC is running at 100 Mbps speed 0: Indicates that the MAC is running at 10 Mbps speed
[19] RESERVED
[18] RMII_MODE:
1: RMII interface activated
0: MII interface activated
[17] MIIM_DIO_SELECT:
1: MIIM_DIO from external input, else from GMAC 0: All MII pads in input mode
[16] ETHERNET_INTERFACE_ON:
1: Ethernet on (pads enables controlled by MAC)
[15:13] RESERVED
[12] DAA_SERIAL_MODE: DAA serial interface mode select pin
[11] SC1_COND_VCC_ENABLE: Enables control of smart card VCC upon bit in the PDES.
[10] SC_DETECT_VPP_POL:
1: Output pin SC_NOT_SETVPP is inverted of PDES_SC_SETVPP 0: Output pin SC_NOT_SETVPP is PDES_SC_SETVPP
[9] IRB_DATA_OUT_POL_OD: Selection of polarity of IRB output signal routed as alternate function
...
...
Thanks,
srini
Quoted 4 lines
Arnd
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re[2]: [RFC 3/8] mfd:syscon: Introduce claim/read/write/release APIs
Quoted 26 lines · Srinivas KANDAGATLA
Quoted 25 lines
From: Srinivas Kandagatla <[email protected]>
This patch introduces
syscon_claim,syscon_read,syscon_write,syscon_releaseAPIs to help drivers to use syscon registers in much more flexible way.With this patch, a driver can claim few/all bits in the syscon registers and do read/write and then release them when its totally finished with them, in the mean time if another driver requests same bits or registers the API will detect conflit and return error to the second request.
Reason to introduce this API.
System configuration/control registers are very basic configuration registers arranged in groups across ST Settop Box parts. These registers are independent of IP itself. Many IPs, clock, pad and other functions are wired up to these registers.In many cases a single syconf register contains bits related to multiple devices, and therefore it need to be shared across multiple drivers at bit level. The same IP block can have different syscon mappings on different SOCs.
Typically in a SOC there will be more than hundreds of these registers, which are again divided into groups.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stuart Menefy <[email protected]>My feeling is that syscon is the wrong place for this functionality, since regmap already handles (some of?) these issues. If you need additional synchronization, it's probably best to extend regmap as needed so other code besides syscon can take advantage of that as well.
+1
---
=?y?q?=5BRFC=205/8=5D=20ARM=3Astih41x=3A=20Add=20STiH415=20SOC=20support?=
In reply to Srinivas KANDAGATLAFrom: Srinivas Kandagatla <[email protected]>
The STiH415 is the next generation of HD, AVC set-top box processors for satellite, cable, terrestrial and IP-STB markets. It is an ARM Cortex-A9 1.0 GHz, dual-core CPU.
--- Documentation/arm/STiH41x/overview.txt | 39 ++ Documentation/arm/STiH41x/stih415-overview.txt | 12 + arch/arm/Kconfig | 3 + arch/arm/Kconfig.debug | 38 ++ arch/arm/Makefile | 2 + arch/arm/boot/dts/stih415-clock.dtsi | 38 ++ arch/arm/boot/dts/stih415-pinctrl.dtsi | 480 ++++++++++++++++++++++++ arch/arm/boot/dts/stih415.dtsi | 94 +++++ arch/arm/boot/dts/stih415.h | 20 + arch/arm/boot/dts/stih41x.dtsi | 30 ++ arch/arm/boot/dts/stixxxx-pincfg.h | 95 +++++ arch/arm/configs/stih41x_defconfig | 94 +++++ arch/arm/include/debug/stixxxx.S | 61 +++ arch/arm/mach-stih41x/Kconfig | 35 ++ arch/arm/mach-stih41x/Makefile | 4 + arch/arm/mach-stih41x/board-dt.c | 76 ++++ arch/arm/mach-stih41x/stih41x.c | 82 ++++ arch/arm/mach-stih41x/stih41x.h | 7 + arch/arm/plat-stixxxx/Kconfig | 2 + arch/arm/plat-stixxxx/Makefile | 2 + arch/arm/plat-stixxxx/headsmp.S | 44 +++ arch/arm/plat-stixxxx/include/plat/hardware.h | 20 + arch/arm/plat-stixxxx/include/plat/smp.h | 19 + arch/arm/plat-stixxxx/platsmp.c | 144 +++++++ 24 files changed, 1441 insertions(+), 0 deletions(-) create mode 100644 Documentation/arm/STiH41x/overview.txt create mode 100644 Documentation/arm/STiH41x/stih415-overview.txt create mode 100644 arch/arm/boot/dts/stih415-clock.dtsi create mode 100644 arch/arm/boot/dts/stih415-pinctrl.dtsi create mode 100644 arch/arm/boot/dts/stih415.dtsi create mode 100644 arch/arm/boot/dts/stih415.h create mode 100644 arch/arm/boot/dts/stih41x.dtsi create mode 100644 arch/arm/boot/dts/stixxxx-pincfg.h create mode 100644 arch/arm/configs/stih41x_defconfig create mode 100644 arch/arm/include/debug/stixxxx.S create mode 100644 arch/arm/mach-stih41x/Kconfig create mode 100644 arch/arm/mach-stih41x/Makefile create mode 100644 arch/arm/mach-stih41x/board-dt.c create mode 100644 arch/arm/mach-stih41x/stih41x.c create mode 100644 arch/arm/mach-stih41x/stih41x.h create mode 100644 arch/arm/plat-stixxxx/Kconfig create mode 100644 arch/arm/plat-stixxxx/Makefile create mode 100644 arch/arm/plat-stixxxx/headsmp.S create mode 100644 arch/arm/plat-stixxxx/include/plat/hardware.h create mode 100644 arch/arm/plat-stixxxx/include/plat/smp.h create mode 100644 arch/arm/plat-stixxxx/platsmp.c
Documentation/arm/STiH41x/overview.txt new file +39 -0
@@ -0,0 +1,39 @@ + STiH41x ARM Linux Overview + ========================== + +Introduction +------------ + + The ST Microelectronics Multimedia and Application Processors range of + CortexA9 System-on-Chip are supported by the 'STixxxx' platform of + ARM Linux. Currently STiH415, STiH416 SOCs are supported with both + B2000 and B2020 Reference boards. + + + configuration + ------------- + + A generic configuration is provided for both STiH415/416, and can be used as the + default by + make stih41x_defconfig + + Layout + ------ + The common files for multiple machine families (STiH415, STiH416, and STiG125) + are located in the platform code contained in arch/arm/plat-stixxxx + with headers in plat/. + - common files to support Stixxxx SoCs which includes things + like platsmp. + + Each machine series have a directory with name arch/arm/mach-sti followed by + series name. Like mach-stih41x to support stih415 and stih416. + + There is a generic board board-dt.c in each mach folder which support + Flattened Device Tree, which means, It works with any compatible board with + Device Trees. + + + Document Author + --------------- + + Srinivas Kandagatla <[email protected]>, (c) 2013 ST Microelectronics
Documentation/arm/STiH41x/stih415-overview.txt new file +12 -0
@@ -0,0 +1,12 @@ + STiH415 Overview + ================ + +Introduction +------------ + + The STiH415 is the next generation of HD, AVC set-top box processors + for satellite, cable, terrestrial and IP-STB markets. + + Features + - ARM Cortex-A9 1.0 GHz, dual-core CPU + - SATA2×2,USB 2.0×3, PCIe, Gbit Ethernet MAC×2
arch/arm/Kconfig +3 -0
@@ -1106,6 +1106,9 @@ source "arch/arm/mach-socfpga/Kconfig" source "arch/arm/plat-spear/Kconfig" +source "arch/arm/mach-stih41x/Kconfig" +source "arch/arm/plat-stixxxx/Kconfig" + source "arch/arm/mach-s3c24xx/Kconfig" if ARCH_S3C64XX
arch/arm/Kconfig.debug +38 -0
@@ -447,6 +447,16 @@ choice This option selects UART0 on VIA/Wondermedia System-on-a-chip devices, including VT8500, WM8505, WM8650 and WM8850. + config DEBUG_STIH41X_UART + depends on ARCH_STIH41X + bool "Use StiH415/416 ASC for low-level debug" + help + Say Y here if you want kernel low-level debugging support + on StiH415/416 based platforms like B2000, B2020. + It support UART2 and SBC_UART1. + + If unsure, say N. + config DEBUG_LL_UART_NONE bool "No low-level debugging UART" depends on !ARCH_MULTIPLATFORM
@@ -578,6 +588,33 @@ choice endchoice +choice + prompt "Low-level debug console UART" + depends on DEBUG_LL && DEBUG_STIH41X_UART + + config STIH41X_DEBUG_ASC2 + bool "ASC2 UART" + help + Say Y here if you want kernel low-level debugging support + on STiH415/416 based platforms like b2000, which has + default UART wired up to ASC2. + + If unsure, say N. + + config STIH41X_DEBUG_SBC_ASC1 + bool "SBC ASC1 UART" + help + Say Y here if you want kernel low-level debugging support + on STiH415/416 based platforms like b2020. which has + default UART wired up to SBC ASC1. + + If unsure, say N. + +endchoice + + + + config DEBUG_LL_INCLUDE string default "debug/icedcc.S" if DEBUG_ICEDCC
@@ -600,6 +637,7 @@ config DEBUG_LL_INCLUDE default "debug/vt8500.S" if DEBUG_VT8500_UART0 default "debug/tegra.S" if DEBUG_TEGRA_UART default "debug/zynq.S" if DEBUG_ZYNQ_UART0 || DEBUG_ZYNQ_UART1 + default "debug/stixxxx.S" if DEBUG_STIH41X_UART default "mach/debug-macro.S" config EARLY_PRINTK
arch/arm/Makefile +2 -0
@@ -194,6 +194,7 @@ machine-$(CONFIG_ARCH_SOCFPGA) += socfpga machine-$(CONFIG_ARCH_SPEAR13XX) += spear13xx machine-$(CONFIG_ARCH_SPEAR3XX) += spear3xx machine-$(CONFIG_MACH_SPEAR600) += spear6xx +machine-$(CONFIG_ARCH_STIH41X) += stih41x machine-$(CONFIG_ARCH_VIRT) += virt machine-$(CONFIG_ARCH_ZYNQ) += zynq machine-$(CONFIG_ARCH_SUNXI) += sunxi
@@ -207,6 +208,7 @@ plat-$(CONFIG_PLAT_ORION) += orion plat-$(CONFIG_PLAT_PXA) += pxa plat-$(CONFIG_PLAT_S3C24XX) += samsung plat-$(CONFIG_PLAT_S5P) += samsung +plat-$(CONFIG_PLAT_STIXXXX) += stixxxx plat-$(CONFIG_PLAT_SPEAR) += spear plat-$(CONFIG_PLAT_VERSATILE) += versatile
arch/arm/boot/dts/stih415-clock.dtsi new file +38 -0
@@ -0,0 +1,38 @@ +/* + * Copyright (C) 2013 STMicroelectronics (R&D) Limited + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +/ { + clocks { + /* + * Fixed 30MHz oscillator input to SoC + */ + CLK_SYSIN: CLK_SYSIN { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <30000000>; + }; + + /* + * ARM Peripheral clock for timers + */ + arm_periph_clk: arm_periph_clk { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <500000000>; + }; + + /* + * Bootloader initialized system infrastructure clock for + * serial devices. + */ + CLKS_ICN_REG_0: CLKS_ICN_REG_0 { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <100000000>; + }; + }; +};
arch/arm/boot/dts/stih415-pinctrl.dtsi new file +480 -0
480 lines not on this page · raw message
arch/arm/boot/dts/stih415.dtsi new file +94 -0
94 lines not on this page · raw message
arch/arm/boot/dts/stih415.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef __STIH415_H_ +#define __STIH415_H_ + +#define CONFIG_SBC (num) (num) +#define CONFIG_FRONT (num) (num - 100) +#define CONFIG_REAR (num) (num - 300) +#define CONFIG_LEFT (num) (num - 400) +#define CONFIG_RIGHT (num) (num - 500) +#define CONFIG_SYSTEM (num) (num - 600) +#define CONFIG_LPM (num) (num) + +#define SYSCFG_SBC (num) syscfg_sbc CONFIG_SBC(num) +#define SYSCFG_FRONT (num) syscfg_front CONFIG_FRONT(num) +#define SYSCFG_REAR (num) syscfg_rear CONFIG_REAR(num) +#define SYSCFG_LEFT (num) syscfg_left CONFIG_LEFT(num) +#define SYSCFG_RIGHT (num) syscfg_right CONFIG_RIGHT(num) +#define SYSCFG_SYSTEM (num) syscfg_system CONFIG_SYSTEM(num) +#define SYSCFG_LPM (num) syscfg_lpm CONFIG_LPM(num) + +#endif /* __STIH415_H_ */
arch/arm/boot/dts/stih41x.dtsi new file +30 -0
@@ -0,0 +1,30 @@ +/ { + #address-cells = <1>; + #size-cells = <1>; + + cpus { + cpu@0 { + compatible = "arm,cortex-a9"; + }; + cpu@1 { + compatible = "arm,cortex-a9"; + }; + }; + + intc: interrupt-controller@fffe1000 { + compatible = "arm,cortex-a9-gic"; + #interrupt-cells = <3>; + interrupt-controller; + reg = <0xfffe1000 0x1000>, + <0xfffe0100 0x100>; + }; + + timer@fffe0200 { + #interrupt-cells = <3>; + interrupt-parent = <&intc>; + compatible = "arm,cortex-a9-global-timer"; + reg = <0xfffe0200 0x100>; + interrupts = <1 11 0x04>; + clocks = <&arm_periph_clk>; + }; +};
arch/arm/boot/dts/stixxxx-pincfg.h new file +95 -0
95 lines not on this page · raw message
arch/arm/configs/stih41x_defconfig new file +94 -0
94 lines not on this page · raw message
arch/arm/include/debug/stixxxx.S new file +61 -0
61 lines not on this page · raw message
arch/arm/mach-stih41x/Kconfig new file +35 -0
@@ -0,0 +1,35 @@ +config ARCH_STIH41X + bool "STMicroelectronics STiH41x SOCs with Flattened Device Tree" if ARCH_MULTI_V7 + select GENERIC_CLOCKEVENTS + select CLKDEV_LOOKUP + select ARM_GIC + select HAVE_ARM_GT + select PINCTRL + select PINCTRL_STIXXXX + select MIGHT_HAVE_CACHE_L2X0 + select HAVE_SMP + select GPIOLIB + select MACH_STIH41X_GENERIC + help + Include support for STiH41x SOCs like STiH415/416 using the device tree + for discovery + More information at Documentation/arm/STiH41x and + at Documentation/devicetree + +config MACH_STIH41X_GENERIC + bool + +if ARCH_STIH41X +menu "STMicroelectronics Consumer Electronics SOCs" + +config SOC_STIH415 + bool "STiH415 STMicroelectronics Consumer Electronics family" + select PLAT_STIXXXX + help + This enables support for STMicroelectronics Digital Consumer + Electronics family StiH415 parts, primarily targetted at set-top-box + and other digital audio/video applications using Flattned Device + Trees. + +endmenu +endif
arch/arm/mach-stih41x/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \ + -I$(srctree)/arch/arm/plat-stixxxx/include +obj-y := stih41x.o +obj-$(CONFIG_MACH_STIH41X_GENERIC) += board-dt.o
arch/arm/mach-stih41x/board-dt.c new file +76 -0
76 lines not on this page · raw message
arch/arm/mach-stih41x/stih41x.c new file +82 -0
82 lines not on this page · raw message
arch/arm/mach-stih41x/stih41x.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __STIH41X_H_ +#define __STIH41X_H_ + +void stih41x_map_io (void ); +void stih41x_l2x0_init (void ); + +#endif /* __STIH41X_H_ */
arch/arm/plat-stixxxx/Kconfig new file +2 -0
@@ -0,0 +1,2 @@ +config PLAT_STIXXXX + bool
arch/arm/plat-stixxxx/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include +obj-$(CONFIG_SMP) += platsmp.o headsmp.o
arch/arm/plat-stixxxx/headsmp.S new file +44 -0
44 lines not on this page · raw message
arch/arm/plat-stixxxx/include/plat/hardware.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* arch/arm/plat-stixxxx/include/mach/hardware.h +* +* Copyright (C) 2013 STMicroelectronics Limited. +* Author: Stuart Menefy <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __PLAT_HARDWARE_H +#define __PLAT_HARDWARE_H +/* +* Statically mapped addresses: +* +* fc000000 to ffffffff (physical) -> fb000000 to feffffff (virtual) +*/ +#define IO_ADDRESS (x) (((x) & 0x03ffffff) + 0xfb000000) +#endif
arch/arm/plat-stixxxx/include/plat/smp.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* arch/arm/plat-stixxxx/platsmp.c +* +* Copyright (C) 2013 STMicroelectronics (R&D) Limited. +* http://www.st.com +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __PLAT_SMP_H +#define __PLAT_SMP_H + +extern struct smp_operations stixxxx_smp_ops; +extern void __iomem *stixxxx_scu_base_addr; +extern void stixxxx_secondary_startup (void ); + +#endif
arch/arm/plat-stixxxx/platsmp.c new file +144 -0
144 lines not on this page · raw message
Signature · 6 lines
1.7.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Arnd Bergmann
maintainerRe: [RFC 5/8] ARM:stih41x: Add STiH415 SOC support
Quoted 26 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
The STiH415 is the next generation of HD, AVC set-top box processors for satellite, cable, terrestrial and IP-STB markets. It is an ARM Cortex-A9 1.0 GHz, dual-core CPU.
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stephen Gallimore <[email protected]>CC Stuart Menefy <[email protected]>--- Documentation/arm/STiH41x/overview.txt | 39 ++ Documentation/arm/STiH41x/stih415-overview.txt | 12 + arch/arm/Kconfig | 3 + arch/arm/Kconfig.debug | 38 ++ arch/arm/Makefile | 2 + arch/arm/boot/dts/stih415-clock.dtsi | 38 ++ arch/arm/boot/dts/stih415-pinctrl.dtsi | 480 ++++++++++++++++++++++++ arch/arm/boot/dts/stih415.dtsi | 94 +++++ arch/arm/boot/dts/stih415.h | 20 + arch/arm/boot/dts/stih41x.dtsi | 30 ++ arch/arm/boot/dts/stixxxx-pincfg.h | 95 +++++ arch/arm/configs/stih41x_defconfig | 94 +++++ arch/arm/include/debug/stixxxx.S | 61 +++ arch/arm/mach-stih41x/Kconfig | 35 ++ arch/arm/mach-stih41x/Makefile | 4 + arch/arm/mach-stih41x/board-dt.c | 76 ++++
Quoted 8 lines
arch/arm/mach-stih41x/stih41x.c | 82 ++++ arch/arm/mach-stih41x/stih41x.h | 7 + arch/arm/plat-stixxxx/Kconfig | 2 + arch/arm/plat-stixxxx/Makefile | 2 + arch/arm/plat-stixxxx/headsmp.S | 44 +++ arch/arm/plat-stixxxx/include/plat/hardware.h | 20 + arch/arm/plat-stixxxx/include/plat/smp.h | 19 + arch/arm/plat-stixxxx/platsmp.c | 144 +++++++
I think there is no point in having a separate mach- and plat- directory here, given that modern machines require very little code. You can probably fold the three files in mach-stih41x (board-dt.c, stih41x.c and stih41x.h) into a single file and rename plat-stixxxx to mach-stixxxx
Quoted 11 lines
arch/arm/Kconfig.debug +3
-0@@ -447,6 +447,16 @@ choice This option selects UART0 on VIA/Wondermedia System-on-a-chip devices, including VT8500, WM8505, WM8650 and WM8850. + config DEBUG_STIH41X_UART + depends on ARCH_STIH41X + bool "Use StiH415/416 ASC for low-level debug"
arch/arm/Kconfig.debug choice · line 462
Quoted 10 lines
arch/arm/Kconfig.debug +7
-0+ help + Say Y here if you want kernel low-level debugging support + on StiH415/416 based platforms like B2000, B2020. + It support UART2 and SBC_UART1. + + If unsure, say N. + config DEBUG_LL_UART_NONE bool "No low-level debugging UART" depends on !ARCH_MULTIPLATFORM
I would split out the debug code into a separate patch though.
arch/arm/Kconfig.debug config DEBUG_LL_INCLUDE · line 641
Quoted 6 lines
arch/arm/Kconfig.debug +1
-0@@ -600,6 +637,7 @@ config DEBUG_LL_INCLUDE default "debug/vt8500.S" if DEBUG_VT8500_UART0 default "debug/tegra.S" if DEBUG_TEGRA_UART default "debug/zynq.S" if DEBUG_ZYNQ_UART0 || DEBUG_ZYNQ_UART1 + default "debug/stixxxx.S" if DEBUG_STIH41X_UART default "mach/debug-macro.S"
Please keep this in alphabetical order.
arch/arm/Kconfig.debug config DEBUG_LL_INCLUDE
Quoted 5 lines
arch/arm/Kconfig.debug +5
-0+ soc { + #address-cells = <1>; + #size-cells = <1>; + #interrupt-cells = <3>; + interrupt-parent = <&intc>;
The "#interrupt-cells" property doesn't belong here I think.
Quoted 12 lines
arch/arm/Kconfig.debug +12
-0+ + uart2: uart at fed32000 { + compatible = "st,asc"; + status = "disabled"; + reg = <0xfed32000 0x2c>; + interrupts = <0 197 0>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_uart2>; + clocks = <&CLKS_ICN_REG_0>; + }; + + /* SBC comms block ASCs in SASG1 */
arch/arm/Kconfig.debug
Quoted 10 lines
arch/arm/Kconfig.debug +10
-0+ sbc_uart1: uart at fe531000 { + compatible = "st,asc"; + status = "disabled"; + reg = <0xfe531000 0x2c>; + interrupts = <0 210 0>; + clocks = <&CLK_SYSIN>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_sbc_uart1>; + }; + };
Please name these devices "serial", not "uart".
arch/arm/configs/stih41x_defconfig
Quoted 5 lines
arch/arm/configs/stih41x_defconfig new file +0
-0
I would prefer to have this be part of multi_v7_defconfig, unless you have strong reason why it can't be.
Quoted 6 lines
arch/arm/mach-stih41x/Kconfig new file +0
-0
arch/arm/mach-stih41x/Kconfig line 23
Quoted 9 lines
arch/arm/mach-stih41x/Kconfig new file +7
-0@@ -0,0 +1,35 @@ +config ARCH_STIH41X + bool "STMicroelectronics STiH41x SOCs with Flattened Device Tree" if ARCH_MULTI_V7 + select GENERIC_CLOCKEVENTS + select CLKDEV_LOOKUP + select ARM_GIC +if ARCH_STIH41X +menu "STMicroelectronics Consumer Electronics SOCs"
You can use 'menuconfig' to combine these two.
arch/arm/mach-stih41x/Kconfig
Quoted 6 lines
arch/arm/mach-stih41x/Kconfig new file +6
-0+static void __init stih41x_timer_init(void) +{ + of_clk_init(NULL); + clocksource_of_init(); + stih41x_l2x0_init(); +}
I'm hoping we can kill make the clk and l2x0 init work by default in 3.11, as clocksource_of_init already does, so you won't need this function any more.
Quoted 15 lines
arch/arm/mach-stih41x/Kconfig new file +15
-0+/* + * A basic implementation of irq_set_wake that ensures wakeup source + * interrupts are not disabled during PM_SUSPEND_FREEZE. + */ +static int stih41x_set_wake(struct irq_data *d, unsigned int on) +{ + struct irq_desc *desc = irq_to_desc(d->irq); + + if (on) { + if (desc->action) + desc->action->flags |= IRQF_NO_SUSPEND; + } else { + if (desc->action) + desc->action->flags &= ~IRQF_NO_SUSPEND; + }
arch/arm/mach-stih41x/Kconfig
Quoted 10 lines
arch/arm/mach-stih41x/Kconfig new file +10
-0+ return 0; +} + +static void __init stih41x_irq_init(void) +{ + gic_arch_extn.irq_set_wake = stih41x_set_wake; + gic_arch_extn.flags = IRQCHIP_MASK_ON_SUSPEND; + + irqchip_init(); +}
This looks like it should be generic. Why do you need this?
arch/arm/mach-stih41x/Kconfig
Quoted 6 lines
arch/arm/mach-stih41x/Kconfig new file +6
-0+void __init stih41x_dt_init(void) +{ + of_platform_populate(NULL, of_default_bus_match_table, + NULL, NULL); + return; +}
This is already not needed in 3.10.
Quoted 7 lines
arch/arm/mach-stih41x/Kconfig new file +7
-0+static struct map_desc stih41x_io_desc[] __initdata = { +#ifdef CONFIG_SMP + { + .virtual = IO_ADDRESS(MPE41_SCU_BASE), + .pfn = __phys_to_pfn(MPE41_SCU_BASE), + .length = SZ_4K, + .type = MT_DEVICE,
arch/arm/mach-stih41x/Kconfig
Quoted 10 lines
arch/arm/mach-stih41x/Kconfig new file +9
-0+ }, +#endif +void __init stih41x_map_io(void) +{ +#ifdef CONFIG_SMP + stixxxx_scu_base_addr = ((void __iomem *)IO_ADDRESS(MPE41_SCU_BASE)); +#endif + iotable_init(stih41x_io_desc, ARRAY_SIZE(stih41x_io_desc)); +}
IIRC the SCU no longer needs to be mapped this early, so you can use ioremap these days.
arch/arm/mach-stih41x/Kconfig
Quoted 12 lines
arch/arm/mach-stih41x/Kconfig new file +12
-0+void __init stih41x_l2x0_init(void) +{ + u32 way_size = 0x4; + u32 aux_ctrl; + + aux_ctrl = (0x1 << L2X0_AUX_CTRL_SHARE_OVERRIDE_SHIFT) | + (0x1 << L2X0_AUX_CTRL_DATA_PREFETCH_SHIFT) | + (0x1 << L2X0_AUX_CTRL_INSTR_PREFETCH_SHIFT) | + (way_size << L2X0_AUX_CTRL_WAY_SIZE_SHIFT); + + l2x0_of_init(aux_ctrl, L2X0_AUX_CTRL_MASK); +}
I don't know where we stand on this, but I think we should kill all calls like these.
Arnd
Re: [RFC 5/8] ARM:stih41x: Add STiH415 SOC support
Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
The STiH415 is the next generation of HD, AVC set-top box processors for satellite, cable, terrestrial and IP-STB markets. It is an ARM Cortex-A9 1.0 GHz, dual-core CPU.
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stephen Gallimore <[email protected]>CC Stuart Menefy <[email protected]>---
patch no receive on the ML
please resend
Best Regards,
J.
RE: [RFC 5/8] ARM:stih41x: Add STiH415 SOC support
In reply to Arnd BergmannHi Arnd,
Thank you for the feedback so far.
Quoted 24 lines
arch/arm/mach-stih41x/board-dt.c new file +23
-0+/* +* A basic implementation of irq_set_wake that ensures wakeup source +* interrupts are not disabled during PM_SUSPEND_FREEZE. +*/ +static int stih41x_set_wake (struct irq_data *d,unsigned int on) { +struct irq_desc *desc =irq_to_desc (d->irq); + +if (on) { +if (desc->action) + desc->action->flags |=IRQF_NO_SUSPEND ; + }else { +if (desc->action) + desc->action->flags &= ~IRQF_NO_SUSPEND ; + } +return 0 ; +} + +static void __init stih41x_irq_init (void ) { + gic_arch_extn.irq_set_wake = stih41x_set_wake; + gic_arch_extn.flags =IRQCHIP_MASK_ON_SUSPEND ; + +irqchip_init (); +}
Quoted 1 line
This looks like it should be generic. Why do you need this?
On this point, I wrote it so I am happy to take some advice. Basically this was to allow us to wakeup from the new PM_SUSPEND_FREEZE state that was added at the beginning of the year, without having to pollute individual drivers (particularly the serial driver) with having to somehow change the IRQ flags, or uninstall/re-install the interrupt handler on suspend/resume when marked as a wakeup source with different flags. Those approaches all seemed too messy and not really the driver's responsibility and installing the interrupt handlers of all possible wakeup sources with IRQF_NO_SUSPEND regardless of if they are currently activated as a wakeup source or not also seemed wrong. The code I ended up with was inspired by the existing mach-mmp (mmp2) PM support which does the same thing, so it is not without precedent.
If you have a better solution, or a way to generalize this that would make sense for the ARM architecture as a whole, then we are more than happy to change.
Regards,
-stephen
Arnd Bergmann
maintainerRe: [RFC 5/8] ARM:stih41x: Add STiH415 SOC support
Quoted 3 lines · Stephen GALLIMORE
If you have a better solution, or a way to generalize this that would make sense for the ARM architecture as a whole, then we are more than happy to change.
No idea, sorry. Upon closer inspection I wonder if your code actually does anything to the hardware that causes it to wake up on an interrupt.
Arnd
RE: [RFC 5/8] ARM:stih41x: Add STiH415 SOC support
Quoted 5 lines
If you have a better solution, or a way to generalize this that would make sense for the ARM architecture as a whole, then we are more than happy to change.
No idea, sorry. Upon closer inspection I wonder if your code actually does anything to the hardware that causes it to wake up on an interrupt.
You are correct that it does not affect the hardware and as such it may be entirely the wrong approach to put this code here. However, as drivers or subsystems are expected to call enable/disable_irq_ wake() when appropriate it seemed a reasonable place to do it and of course in the future when we add in support for the other suspend states this is also expected to do something with the system standby controller, as is the case on other platforms. But we concede that in this first minimal version that it may look a little out of place.
To quickly summarize the issue we were trying to address, the new freeze state suspends the drivers but then rather than calling the arch suspend code simply goes to sleep on a wake queue. It is relying on wakeup source interrupt handlers actually being run (this is not the case in the other "traditional" suspend states) and that the driver or some subsystem code called as part of the driver's interrupt processing will call pm_wakeup_event() which signals the freeze wake queue and causes the generic suspend code to start going through its wakeup path. But the driver suspend code will suspend the calling of IRQ handlers, dpm_suspend_noirq() calls suspend_device_irqs(), except for those with the NO_SUSPEND flag set.
Now it is possible that we have simply tried to finesse the solution too much and that using the ASC serial device as a wakeup source was an unfortunate place to start, because most wakeup devices on a set top box have a single instance, e.g. the IR device for the remote control and you probably always want them to be a wakeup source. Maybe it would not have really mattered that much in the end if the ASC driver simply installed the interrupts for all UART ports with the flag, regardless of if the port was going to be used to wake up or not; but as I said in my previous response that solution left us feeling a bit uncomfortable which is why we went looking for another approach that was independent of the device driver and hooking into enable/disable_irq_wake() at the architecture level seemed more appropriate once we noticed it being used elsewhere. However, until you put it out there for comment it is hard to know if you have backed the right horse.
Regards,
-stephen
Re: [RFC 5/8] ARM:stih41x: Add STiH415 SOC support
In reply to Arnd BergmannThankyou for the comments.
Quoted 35 lines · Arnd Bergmann
Quoted 26 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
The STiH415 is the next generation of HD, AVC set-top box processors for satellite, cable, terrestrial and IP-STB markets. It is an ARM Cortex-A9 1.0 GHz, dual-core CPU.
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stephen Gallimore <[email protected]>CC Stuart Menefy <[email protected]>--- Documentation/arm/STiH41x/overview.txt | 39 ++ Documentation/arm/STiH41x/stih415-overview.txt | 12 + arch/arm/Kconfig | 3 + arch/arm/Kconfig.debug | 38 ++ arch/arm/Makefile | 2 + arch/arm/boot/dts/stih415-clock.dtsi | 38 ++ arch/arm/boot/dts/stih415-pinctrl.dtsi | 480 ++++++++++++++++++++++++ arch/arm/boot/dts/stih415.dtsi | 94 +++++ arch/arm/boot/dts/stih415.h | 20 + arch/arm/boot/dts/stih41x.dtsi | 30 ++ arch/arm/boot/dts/stixxxx-pincfg.h | 95 +++++ arch/arm/configs/stih41x_defconfig | 94 +++++ arch/arm/include/debug/stixxxx.S | 61 +++ arch/arm/mach-stih41x/Kconfig | 35 ++ arch/arm/mach-stih41x/Makefile | 4 + arch/arm/mach-stih41x/board-dt.c | 76 ++++Quoted 8 lines
arch/arm/mach-stih41x/stih41x.c | 82 ++++ arch/arm/mach-stih41x/stih41x.h | 7 + arch/arm/plat-stixxxx/Kconfig | 2 + arch/arm/plat-stixxxx/Makefile | 2 + arch/arm/plat-stixxxx/headsmp.S | 44 +++ arch/arm/plat-stixxxx/include/plat/hardware.h | 20 + arch/arm/plat-stixxxx/include/plat/smp.h | 19 + arch/arm/plat-stixxxx/platsmp.c | 144 +++++++
Quoted 4 lines
I think there is no point in having a separate mach- and plat- directory here, given that modern machines require very little code. You can probably fold the three files in mach-stih41x (
board-dt.c,stih41x.candstih41x.h) into a single file and rename plat-stixxxx to mach-stixxxx
Yep, sounds good.
Quoted 9 lines
Quoted 9 lines
arch/arm/Kconfig.debug +0
-0@@ -447,6 +447,16 @@ choice This option selects UART0 on VIA/Wondermedia System-on-a-chip devices, including VT8500, WM8505, WM8650 and WM8850.
Quoted 14 lines
arch/arm/Kconfig.debug choice · line 462
Quoted 13 lines
arch/arm/Kconfig.debug +10
-0+ config DEBUG_STIH41X_UART + depends on ARCH_STIH41X + bool "Use StiH415/416 ASC for low-level debug" + help + Say Y here if you want kernel low-level debugging support + on StiH415/416 based platforms like B2000, B2020. + It support UART2 and SBC_UART1. + + If unsure, say N. + config DEBUG_LL_UART_NONE bool "No low-level debugging UART" depends on !ARCH_MULTIPLATFORMI would split out the debug code into a separate patch though.
Will do this in next version.
Quoted 8 lines
arch/arm/Kconfig.debug config DEBUG_LL_INCLUDE · line 641
Quoted 7 lines
arch/arm/Kconfig.debug +1
-0@@ -600,6 +637,7 @@ config DEBUG_LL_INCLUDE default "debug/vt8500.S" if DEBUG_VT8500_UART0 default "debug/tegra.S" if DEBUG_TEGRA_UART default "debug/zynq.S" if DEBUG_ZYNQ_UART0 || DEBUG_ZYNQ_UART1 + default "debug/stixxxx.S" if DEBUG_STIH41X_UART default "mach/debug-macro.S"Please keep this in alphabetical order.
Yes.
Quoted 23 lines
arch/arm/Kconfig.debug config DEBUG_LL_INCLUDE
Quoted 6 lines
arch/arm/Kconfig.debug +5
-0+ soc { + #address-cells = <1>; + #size-cells = <1>; + #interrupt-cells = <3>; + interrupt-parent = <&intc>;The "#interrupt-cells" property doesn't belong here I think.
Quoted 15 lines
arch/arm/Kconfig.debug +15
-0+ + uart2: uart at fed32000 { + compatible = "st,asc"; + status = "disabled"; + reg = <0xfed32000 0x2c>; + interrupts = <0 197 0>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_uart2>; + clocks = <&CLKS_ICN_REG_0>; + }; + + /* SBC comms block ASCs in SASG1 */ + sbc_uart1: uart at fe531000 { + compatible = "st,asc"; + status = "disabled";
Quoted 8 lines
arch/arm/Kconfig.debug
Quoted 7 lines
arch/arm/Kconfig.debug +7
-0+ reg = <0xfe531000 0x2c>; + interrupts = <0 210 0>; + clocks = <&CLK_SYSIN>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_sbc_uart1>; + }; + };Please name these devices "serial", not "uart".
Ok, I will rename them to serial.
Quoted 7 lines
arch/arm/configs/stih41x_defconfig
Quoted 5 lines
arch/arm/configs/stih41x_defconfig new file +0
-0I would prefer to have this be part of
multi_v7_defconfig, unless you have strong reason why it can't be.
I think we can move this to multi_v7_defconfig.
Quoted 12 lines
Quoted 11 lines
arch/arm/mach-stih41x/Kconfig new file +5
-0@@ -0,0 +1,35 @@ +config ARCH_STIH41X + bool "STMicroelectronics STiH41x SOCs with Flattened Device Tree" if ARCH_MULTI_V7 + select GENERIC_CLOCKEVENTS + select CLKDEV_LOOKUP + select ARM_GIC
Quoted 3 lines
arch/arm/mach-stih41x/Kconfig line 23
Quoted 2 lines
arch/arm/mach-stih41x/Kconfig new file +2
-0+if ARCH_STIH41X +menu "STMicroelectronics Consumer Electronics SOCs"You can use 'menuconfig' to combine these two.
Thats a nice one.. Will use it.
Quoted 9 lines
arch/arm/mach-stih41x/Kconfig line 13
Quoted 6 lines
arch/arm/mach-stih41x/Kconfig new file +6
-0+static void __init stih41x_timer_init(void) +{ + of_clk_init(NULL); + clocksource_of_init(); + stih41x_l2x0_init(); +}I'm hoping we can kill make the clk and l2x0 init work by default in 3.11, as
clocksource_of_initalready does, so you won't need this function any more.
Ok.
Quoted 29 lines
Quoted 16 lines
arch/arm/mach-stih41x/Kconfig new file +15
-0+/* + * A basic implementation of irq_set_wake that ensures wakeup source + * interrupts are not disabled during PM_SUSPEND_FREEZE. + */ +static int stih41x_set_wake(struct irq_data *d, unsigned int on) +{ + struct irq_desc *desc = irq_to_desc(d->irq); + + if (on) { + if (desc->action) + desc->action->flags |= IRQF_NO_SUSPEND; + } else { + if (desc->action) + desc->action->flags &= ~IRQF_NO_SUSPEND; + }arch/arm/mach-stih41x/Kconfig
Quoted 10 lines
arch/arm/mach-stih41x/Kconfig new file +10
-0+ return 0; +} + +static void __init stih41x_irq_init(void) +{ + gic_arch_extn.irq_set_wake = stih41x_set_wake; + gic_arch_extn.flags = IRQCHIP_MASK_ON_SUSPEND; + + irqchip_init(); +}This looks like it should be generic. Why do you need this?
Quoted 7 lines
arch/arm/mach-stih41x/Kconfig
Quoted 6 lines
arch/arm/mach-stih41x/Kconfig new file +6
-0+void __init stih41x_dt_init(void) +{ + of_platform_populate(NULL, of_default_bus_match_table, + NULL, NULL); + return; +}This is already not needed in 3.10.
Ok, cool... will get rid of this..
Quoted 11 lines
Quoted 11 lines
arch/arm/mach-stih41x/Kconfig new file +10
-0+static struct map_desc stih41x_io_desc[] __initdata = { +#ifdef CONFIG_SMP + { + .virtual = IO_ADDRESS(MPE41_SCU_BASE), + .pfn = __phys_to_pfn(MPE41_SCU_BASE), + .length = SZ_4K, + .type = MT_DEVICE, + }, +#endif +void __init stih41x_map_io(void)
Quoted 8 lines
arch/arm/mach-stih41x/Kconfig
Quoted 6 lines
arch/arm/mach-stih41x/Kconfig new file +6
-0+{ +#ifdef CONFIG_SMP + stixxxx_scu_base_addr = ((void __iomem *)IO_ADDRESS(MPE41_SCU_BASE)); +#endif + iotable_init(stih41x_io_desc, ARRAY_SIZE(stih41x_io_desc)); +}IIRC the SCU no longer needs to be mapped this early, so you can use ioremap these days.
yep, I agree.
Quoted 15 lines
arch/arm/mach-stih41x/Kconfig
Quoted 13 lines
arch/arm/mach-stih41x/Kconfig new file +12
-0+void __init stih41x_l2x0_init(void) +{ + u32 way_size = 0x4; + u32 aux_ctrl; + + aux_ctrl = (0x1 << L2X0_AUX_CTRL_SHARE_OVERRIDE_SHIFT) | + (0x1 << L2X0_AUX_CTRL_DATA_PREFETCH_SHIFT) | + (0x1 << L2X0_AUX_CTRL_INSTR_PREFETCH_SHIFT) | + (way_size << L2X0_AUX_CTRL_WAY_SIZE_SHIFT); + + l2x0_of_init(aux_ctrl, L2X0_AUX_CTRL_MASK); +}I don't know where we stand on this, but I think we should kill all calls like these.
I agree, but we don't have other ways as of today..
Quoted 3 lines
Arnd
RFC 6/8 ARM:stih41x: Add STiH416 SOC support
In reply to Srinivas KANDAGATLAFrom: Srinivas Kandagatla <[email protected]>
The STiH416 is advanced HD AVC processor with 3D graphics acceleration and 1.2-GHz ARM Cortex-A9 SMP CPU.
--- Documentation/arm/STiH41x/stih416-overview.txt | 12 + arch/arm/boot/dts/stih416-clock.dtsi | 41 ++ arch/arm/boot/dts/stih416-pinctrl.dtsi | 718 ++++++++++++++++++++++++ arch/arm/boot/dts/stih416.dtsi | 103 ++++ arch/arm/boot/dts/stih416.h | 24 + arch/arm/configs/stih41x_defconfig | 1 + arch/arm/mach-stih41x/Kconfig | 9 + arch/arm/mach-stih41x/board-dt.c | 2 +- 8 files changed, 909 insertions(+), 1 deletions(-) create mode 100644 Documentation/arm/STiH41x/stih416-overview.txt create mode 100644 arch/arm/boot/dts/stih416-clock.dtsi create mode 100644 arch/arm/boot/dts/stih416-pinctrl.dtsi create mode 100644 arch/arm/boot/dts/stih416.dtsi create mode 100644 arch/arm/boot/dts/stih416.h
Documentation/arm/STiH41x/stih416-overview.txt new file +12 -0
@@ -0,0 +1,12 @@ + STiH416 Overview + ================ + +Introduction +------------ + + The STiH416 is the next generation of HD, AVC set-top box processors + for satellite, cable, terrestrial and IP-STB markets. + + Features + - ARM Cortex-A9 1.2 GHz dual core CPU + - SATA2×2,USB 2.0×3, PCIe, Gbit Ethernet MAC×2
arch/arm/boot/dts/stih416-clock.dtsi new file +41 -0
41 lines not on this page · raw message
arch/arm/boot/dts/stih416-pinctrl.dtsi new file +718 -0
718 lines not on this page · raw message
arch/arm/boot/dts/stih416.dtsi new file +103 -0
103 lines not on this page · raw message
arch/arm/boot/dts/stih416.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef __STIH416_H_ +#define __STIH416_H_ + +#define CONFIG_SBC (num) num +#define CONFIG_FRONT (num) (num - 1000) +#define CONFIG_REAR (num) (num - 2000) +#define CONFIG_FVDP_FE (num) (num - 5000) +#define CONFIG_FVDP_LITE (num) (num - 6000) +#define CONFIG_CPU (num) (num - 7000) +#define CONFIG_COMPO (num) (num - 8000) +#define CONFIG_TRANSPORT (num) (num - 9000) +#define CONFIG_LPM (num) num + +#define SYSCFG_SBC (num) syscfg_sbc CONFIG_SBC(num) +#define SYSCFG_FRONT (num) syscfg_front CONFIG_FRONT(num) +#define SYSCFG_REAR (num) syscfg_rear CONFIG_REAR(num) +#define SYSCFG_FVDP_FE (num) syscfg_fvdp_fe CONFIG_FVDP_FE(num) +#define SYSCFG_FVDP_LITE (num) syscfg_fvdp_lite CONFIG_FVDP_LITE(num) +#define SYSCFG_CPU (num) syscfg_cpu CONFIG_CPU(num) +#define SYSCFG_COMPO (num) syscfg_compo CONFIG_COMPO(num) +#define SYSCFG_TRANSPORT (num) syscfg_transport CONFIG_TRANSPORT(num) +#define SYSCFG_LPM (num) syscfg_lpm CONFIG_LPM(num) + +#endif /* __STIH416_H_ */
arch/arm/configs/stih41x_defconfig +1 -0
@@ -24,6 +24,7 @@ CONFIG_MODULE_SRCVERSION_ALL=y CONFIG_BLK_DEV_INTEGRITY=y CONFIG_ARCH_STIH41X=y CONFIG_SOC_STIH415=y +CONFIG_SOC_STIH416=y # CONFIG_ARCH_VEXPRESS_CORTEX_A5_A9_ERRATA is not set # CONFIG_SWP_EMULATE is not set CONFIG_ARM_ERRATA_720789=y
arch/arm/mach-stih41x/Kconfig +9 -0
@@ -31,5 +31,14 @@ config SOC_STIH415 and other digital audio/video applications using Flattned Device Trees. +config SOC_STIH416 + bool "STiH416 STMicroelectronics Consumer Electronics family" + select PLAT_STIXXXX + help + This enables support for STMicroelectronics Digital Consumer + Electronics family StiH416 parts, primarily targetted at set-top-box + and other digital audio/video applications using Flattened Device + Trees. + endmenu endif
arch/arm/mach-stih41x/board-dt.c +1 -1
@@ -66,7 +66,7 @@ static const char *stih41x_dt_match[] __initdata = {NULL }; -DT_MACHINE_START (STM ,"STiH415 SoC with Flattened Device Tree" ) +DT_MACHINE_START (STM ,"STiH415/416 SoC with Flattened Device Tree" ) .map_io = stih41x_map_io, .init_time = stih41x_timer_init, .init_machine = stih41x_dt_init,
Signature · 1 line
1.7.6.5
RFC 6/8 ARM:stih41x: Add STiH416 SOC support
Quoted 8 lines · Srinivas KANDAGATLA
From: Srinivas Kandagatla <[email protected]>
The STiH416 is advanced HD AVC processor with 3D graphics acceleration and 1.2-GHz ARM Cortex-A9 SMP CPU.
Signed-off-by Srinivas Kandagatla <[email protected]>CC Stephen Gallimore <[email protected]>CC Stuart Menefy <[email protected]>
(...)
This stuff is looking really good.
arch/arm/boot/dts/stih416.dtsi line 11
Quoted 13 lines
+++
b/arch/arm/boot/dts/stih416.dtsiarch/arm/boot/dts/stih416.dtsi new file +11
-0@@ -0,0 +1,103 @@ +/* + * Copyright (C) 2012 STMicroelectronics Limited. + * Author: Srinivas Kandagatla <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * publishhed by the Free Software Foundation. + */ +#include "stih41x.dtsi" +#include "stih416-clock.dtsi" +#include "stih416-pinctrl.dtsi"
Nice layering here!
arch/arm/boot/dts/stih416.h
Quoted 5 lines
arch/arm/boot/dts/stih416.h new file +0
-0
I've seen that people start to put these into:include/dt-bindings/
With one include per driver subsystem. I suggest you follow this pattern.
Yours,
Linus Walleij
RFC 7/8 ARM:stih41x: Add B2000 board support
In reply to Srinivas KANDAGATLAFrom: Srinivas Kandagatla <[email protected]>
B2000 board is reference board for STIH415/416 SOCs, it has 2 x UART, 4x USB, 2 x Ethernet, 1 x SATA, 1 x PCIe, and 1GB RAM.
This patch add initial support to b2000 with STiH415/416 with UART2 as console and a heard beat LED.
--- arch/arm/boot/dts/Makefile | 2 + arch/arm/boot/dts/stih415-b2000.dtsp | 15 ++++++++++++ arch/arm/boot/dts/stih416-b2000.dtsp | 16 +++++++++++++ arch/arm/boot/dts/stih41x-b2000.dtsi | 41 ++++++++++++++++++++++++++++++++++ arch/arm/mach-stih41x/board-dt.c | 2 + 5 files changed, 76 insertions(+), 0 deletions(-) create mode 100644 arch/arm/boot/dts/stih415-b2000.dtsp create mode 100644 arch/arm/boot/dts/stih416-b2000.dtsp create mode 100644 arch/arm/boot/dts/stih41x-b2000.dtsi
arch/arm/boot/dts/Makefile +2 -0
@@ -147,6 +147,8 @@ dtb-$(CONFIG_ARCH_SPEAR3XX)+= spear300-evb.dtb \ spear320-evb.dtb \ spear320-hmi.dtb dtb-$(CONFIG_ARCH_SPEAR6XX)+= spear600-evb.dtb +dtb-$(CONFIG_ARCH_STIH41X)+= stih415-b2000.dtb \ + stih416-b2000.dtb dtb-$(CONFIG_ARCH_SUNXI) += sun4i-a10-cubieboard.dtb \ sun4i-a10-hackberry.dtb \ sun5i-a13-olinuxino.dtb
arch/arm/boot/dts/stih415-b2000.dtsp new file +15 -0
@@ -0,0 +1,15 @@ +/* + * Copyright (C) 2013 STMicroelectronics (R&D) Limited. + * Author: Srinivas Kandagatla <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * publishhed by the Free Software Foundation. + */ +/dts-v1/; +#include "stih415.dtsi" +#include "stih41x-b2000.dtsi" +/ { + model = "STiH415 B2000 Board"; + compatible = "st,stih415", "st,stih415-b2000"; +};
arch/arm/boot/dts/stih416-b2000.dtsp new file +16 -0
@@ -0,0 +1,16 @@ +/* + * Copyright (C) 2013 STMicroelectronics (R&D) Limited. + * Author: Srinivas Kandagatla <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * publishhed by the Free Software Foundation. + */ +/dts-v1/; +#include "stih416.dtsi" +#include "stih41x-b2000.dtsi" + +/ { + compatible = "st,stih416", "st,stih416-b2000"; + model = "STiH416 B2000"; +};
arch/arm/boot/dts/stih41x-b2000.dtsi new file +41 -0
41 lines not on this page · raw message
arch/arm/mach-stih41x/board-dt.c +2 -0
@@ -63,6 +63,8 @@ void __init stih41x_dt_init(void) }static const char *stih41x_dt_match[]__initdata = { +"st,stih415-b2000" , +"st,stih416-b2000" ,NULL };
Signature · 1 line
1.7.6.5
Arnd Bergmann
maintainerRe: [RFC 7/8] ARM:stih41x: Add B2000 board support
arch/arm/mach-stih41x/board-dt.c void __init stih41x_dt_init(void) · line 69
Quoted 12 lines · Srinivas KANDAGATLA
arch/arm/mach-stih41x/board-dt.c +2
-0@@ -63,6 +63,8 @@ void __init stih41x_dt_init(void) }static const char *stih41x_dt_match[]__initdata = { +"st,stih415-b2000" , +"st,stih416-b2000" ,NULL };
I probably wouldn't bother listing all the boards here. Just make sure the .dts file lists both the name of the board and of the soc in its compatible property, and list all the SoCs here that you can boot on.
Arnd
Re: [RFC 7/8] ARM:stih41x: Add B2000 board support
Quoted 8 lines · Arnd Bergmann
Quoted 7 lines · Srinivas KANDAGATLA
arch/arm/mach-stih41x/board-dt.c +0
-0@@ -63,6 +63,8 @@ void __init stih41x_dt_init(void) }
Quoted 9 lines
arch/arm/mach-stih41x/board-dt.c void __init stih41x_dt_init(void) · line 69
Quoted 5 lines
arch/arm/mach-stih41x/board-dt.c +2
-0static const char *stih41x_dt_match[]__initdata = { +"st,stih415-b2000" , +"st,stih416-b2000" ,NULL };I probably wouldn't bother listing all the boards here. Just make sure the .dts file lists both the name of the board and of the soc in its compatible property, and list all the SoCs here that you can boot on.
was going to do the same comment
Best Regards,
J.
Quoted 6 lines
Arnd
_______________________________________________
devicetree-discuss mailing list
devicetree-discuss at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss
Re: [RFC 7/8] ARM:stih41x: Add B2000 board support
In reply to Arnd BergmannQuoted 8 lines · Arnd Bergmann
Quoted 7 lines · Srinivas KANDAGATLA
arch/arm/mach-stih41x/board-dt.c +0
-0@@ -63,6 +63,8 @@ void __init stih41x_dt_init(void) }
Quoted 8 lines
arch/arm/mach-stih41x/board-dt.c void __init stih41x_dt_init(void) · line 69
Quoted 5 lines
arch/arm/mach-stih41x/board-dt.c +2
-0static const char *stih41x_dt_match[]__initdata = { +"st,stih415-b2000" , +"st,stih416-b2000" ,NULL };I probably wouldn't bother listing all the boards here. Just make sure the .dts file lists both the name of the board and of the soc in its compatible property, and list all the SoCs here that you can boot on.
I like that approach. Will change in the next version.
Quoted 3 lines
Arnd
RFC 8/8 ARM:stih41x: Add B2020 board support
In reply to Srinivas KANDAGATLAFrom: Srinivas Kandagatla <[email protected]>
B2020 ADI board is reference board for STIH415/416 SOCs, it has 2 x UART, 4x USB, 1 x Ethernet, 1 x SATA, 1 x PCIe, and 2GB RAM with standard set-top box IPs.
This patch adds initial support to B2020 with STiH415/416 with SBC_UART1 as console and a heard beat LED.
--- arch/arm/boot/dts/Makefile | 4 ++- arch/arm/boot/dts/stih415-b2020.dtsp | 15 ++++++++++++ arch/arm/boot/dts/stih416-b2020.dtsp | 16 +++++++++++++ arch/arm/boot/dts/stih41x-b2020.dtsi | 42 ++++++++++++++++++++++++++++++++++ arch/arm/mach-stih41x/board-dt.c | 2 + 5 files changed, 78 insertions(+), 1 deletions(-) create mode 100644 arch/arm/boot/dts/stih415-b2020.dtsp create mode 100644 arch/arm/boot/dts/stih416-b2020.dtsp create mode 100644 arch/arm/boot/dts/stih41x-b2020.dtsi
arch/arm/boot/dts/Makefile +3 -1
@@ -148,7 +148,9 @@ dtb-$(CONFIG_ARCH_SPEAR3XX)+= spear300-evb.dtb \ spear320-hmi.dtb dtb-$(CONFIG_ARCH_SPEAR6XX)+= spear600-evb.dtb dtb-$(CONFIG_ARCH_STIH41X)+= stih415-b2000.dtb \ - stih416-b2000.dtb + stih416-b2000.dtb \ + stih415-b2020.dtb \ + stih416-b2020.dtb dtb-$(CONFIG_ARCH_SUNXI) += sun4i-a10-cubieboard.dtb \ sun4i-a10-hackberry.dtb \ sun5i-a13-olinuxino.dtb
arch/arm/boot/dts/stih415-b2020.dtsp new file +15 -0
@@ -0,0 +1,15 @@ +/* + * Copyright (C) 2013 STMicroelectronics (R&D) Limited. + * Author: Srinivas Kandagatla <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * publishhed by the Free Software Foundation. + */ +/dts-v1/; +#include "stih415.dtsi" +#include "stih41x-b2020.dtsi" +/ { + model = "STiH415 B2020 Board"; + compatible = "st,stih415", "st,stih415-b2020"; +};
arch/arm/boot/dts/stih416-b2020.dtsp new file +16 -0
@@ -0,0 +1,16 @@ +/* + * Copyright (C) 2013 STMicroelectronics (R&D) Limited. + * Author: Srinivas Kandagatla <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * publishhed by the Free Software Foundation. + */ +/dts-v1/; +#include "stih416.dtsi" +#include "stih41x-b2020.dtsi" +/ { + model = "STiH416 B2020"; + compatible = "st,stih416", "st,stih416-b2020"; + +};
arch/arm/boot/dts/stih41x-b2020.dtsi new file +42 -0
42 lines not on this page · raw message
arch/arm/mach-stih41x/board-dt.c +2 -0
@@ -65,6 +65,8 @@ void __init stih41x_dt_init(void)static const char *stih41x_dt_match[]__initdata = {"st,stih415-b2000" ,"st,stih416-b2000" , +"st,stih415-b2020" , +"st,stih416-b2020" ,NULL };
Signature · 1 line
1.7.6.5