Exynos5: Pinmux: Add fdt for pinmux
Subsystems (3)
PATCH 1/1 Exynos5: Pinmux: Add fdt for pinmux
This patch adds fdt nodes for peripherals which require pin muxing and configuration. Existing pinmux code modified to retrieve gpio range and function related info from fdt.
--- arch/arm/cpu/armv7/exynos/pinmux.c | 287 ++++++++++++++++++++--------- arch/arm/dts/exynos5250.dtsi | 197 ++++++++++++++++++++ arch/arm/include/asm/arch-exynos/pinmux.h | 9 + include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 5 files changed, 405 insertions(+), 90 deletions(-)
arch/arm/cpu/armv7/exynos/pinmux.c +197 -90
@@ -27,87 +27,136 @@#include <asm/arch/pinmux.h> #include <asm/arch/sromc.h> -static void exynos5_uart_config (int peripheral) +DECLARE_GLOBAL_DATA_PTR ; + +static int get_fdt_values (struct pinmux_dev *pdev) +{ +int node, subnode; +int depthp =0 ; + +/* Get the node from FDT for pinmux */ + node =fdtdec_next_compatible (gd->fdt_blob,0 , +COMPAT_SAMSUNG_PINMUX ); +if (node <0 ) { +printf ("PINMUX: No node for pinmux in device tree\n" ); +return -1 ; + } + +/* Trace subnodes for the given peripheral's node */ +for (subnode =fdtdec_next_compatible_subnode (gd->fdt_blob, node, +COMPAT_SAMSUNG_PINMUX , &depthp); subnode >0 ; + subnode =fdtdec_next_compatible_subnode (gd->fdt_blob, subnode, +COMPAT_SAMSUNG_PINMUX , &depthp)) { + +int len; +char *periph_name = (char *)fdt_get_name (gd->fdt_blob, + subnode, &len); + +/* If peripheral name matches to the node name */ +if (!(strcmp (periph_name, pdev->dev_name))) { + pdev->start =fdtdec_get_int (gd->fdt_blob, + subnode,"samsung,pin-base" ,-1 ); + pdev->count =fdtdec_get_int (gd->fdt_blob, + subnode,"samsung,pin-count" ,-1 ); + pdev->start_ext =fdtdec_get_int (gd->fdt_blob, + subnode,"samsung,pin-ext" ,-1 ); + pdev->function =fdtdec_get_int (gd->fdt_blob, + subnode,"samsung,pin-function" ,-1 ); +break ; + } + } + +return 0 ; +} + +static int exynos5_uart_config (int peripheral) { -int i, start, count; +int i; +struct pinmux_dev pdev;switch (peripheral) {case PERIPH_ID_UART0 : - start =GPIO_A00 ; - count =4 ; + pdev.dev_name ="pingrp-uart0" ;break ;case PERIPH_ID_UART1 : - start =GPIO_D00 ; - count =4 ; + pdev.dev_name ="pingrp-uart1" ;break ;case PERIPH_ID_UART2 : - start =GPIO_A10 ; - count =4 ; + pdev.dev_name ="pingrp-uart2" ;break ;case PERIPH_ID_UART3 : - start =GPIO_A14 ; - count =2 ; + pdev.dev_name ="pingrp-uart3" ;break ; } -for (i = start; i < start + count; i++) { -gpio_set_pull (i,GPIO_PULL_NONE ); -gpio_cfg_pin (i,GPIO_FUNC (0x2 )); + +/* Retrieve gpio range and base for this UART */ +if (get_fdt_values (&pdev)) +return -1 ; + +/* Apply pin configurations */ +for (i =0 ; i < pdev.count; i++) { +gpio_set_pull (pdev.start + i,GPIO_PULL_NONE ); +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (pdev.function)); } + +return 0 ; }static int exynos5_mmc_config (int peripheral,int flags) { -int i, start, start_ext, gpio_func =0 ; +int i; +struct pinmux_dev pdev;switch (peripheral) {case PERIPH_ID_SDMMC0 : - start =GPIO_C00 ; - start_ext =GPIO_C10 ; - gpio_func =GPIO_FUNC (0x2 ); + pdev.dev_name ="pingrp-sdmmc0" ;break ;case PERIPH_ID_SDMMC1 : - start =GPIO_C20 ; - start_ext =0 ; + pdev.dev_name ="pingrp-sdmmc1" ;break ;case PERIPH_ID_SDMMC2 : - start =GPIO_C30 ; - start_ext =GPIO_C43 ; - gpio_func =GPIO_FUNC (0x3 ); + pdev.dev_name ="pingrp-sdmmc2" ;break ;case PERIPH_ID_SDMMC3 : - start =GPIO_C40 ; - start_ext =0 ; + pdev.dev_name ="pingrp-sdmmc3" ;break ; } -if ((flags &PINMUX_FLAG_8BIT_MODE ) && !start_ext) { + +/* Retrieve gpio range and base for this SDMMC */ +if (get_fdt_values (&pdev)) +return -1 ; + +/* Apply pin configurations */ +if ((flags &PINMUX_FLAG_8BIT_MODE ) && !(pdev.start_ext)) {debug ("SDMMC device %d does not support 8bit mode" , peripheral);return -1 ; }if (flags &PINMUX_FLAG_8BIT_MODE ) { -for (i = start_ext; i <= (start_ext +3 ); i++) { -gpio_cfg_pin (i, gpio_func); +for (i = pdev.start_ext; i <= (pdev.start_ext +3 ); i++) { +gpio_cfg_pin (i,GPIO_FUNC (pdev.function));gpio_set_pull (i,GPIO_PULL_UP );gpio_set_drv (i,GPIO_DRV_4X ); } }for (i =0 ; i <2 ; i++) { -gpio_cfg_pin (start + i,GPIO_FUNC (0x2 )); -gpio_set_pull (start + i,GPIO_PULL_NONE ); -gpio_set_drv (start + i,GPIO_DRV_4X ); +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (0x2 )); +gpio_set_pull (pdev.start + i,GPIO_PULL_NONE ); +gpio_set_drv (pdev.start + i,GPIO_DRV_4X ); }for (i =3 ; i <=6 ; i++) { -gpio_cfg_pin (start + i,GPIO_FUNC (0x2 )); -gpio_set_pull (start + i,GPIO_PULL_UP ); -gpio_set_drv (start + i,GPIO_DRV_4X ); +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (0x2 )); +gpio_set_pull (pdev.start + i,GPIO_PULL_UP ); +gpio_set_drv (pdev.start + i,GPIO_DRV_4X ); }return 0 ; } -static void exynos5_sromc_config (int flags) +static int exynos5_sromc_config (int flags) {int i; +struct pinmux_dev pdev;/* * SROM:CS1 and EBI
@@ -124,13 +173,27 @@ static void exynos5_sromc_config(int flags)* GPY1[2] SROM_WAIT(2) * GPY1[3] EBI_DATA_RDn(2) */ -gpio_cfg_pin (GPIO_Y00 + (flags &PINMUX_FLAG_BANK ), -GPIO_FUNC (2 )); -gpio_cfg_pin (GPIO_Y04 ,GPIO_FUNC (2 )); -gpio_cfg_pin (GPIO_Y05 ,GPIO_FUNC (2 )); + pdev.dev_name ="pingrp-sromc" ; + +/* Retrieve gpio range and base for SROM CS1 */ +if (get_fdt_values (&pdev)) +return -1 ; + +/* Apply pin configurations */ +gpio_cfg_pin (pdev.start + (flags &PINMUX_FLAG_BANK ), +GPIO_FUNC (pdev.function)); +gpio_cfg_pin (pdev.start +4 ,GPIO_FUNC (pdev.function)); +gpio_cfg_pin (pdev.start +5 ,GPIO_FUNC (pdev.function)); + + pdev.dev_name ="pingrp-srom-ebi" ; + +/* Retrieve gpio range and base for SROM EBI */ +if (get_fdt_values (&pdev)) +return -1 ; -for (i =0 ; i <4 ; i++) -gpio_cfg_pin (GPIO_Y10 + i,GPIO_FUNC (2 )); +/* Apply pin configurations */ +for (i =0 ; i < pdev.count; i++) +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (pdev.function));/* * EBI: 8 Addrss Lines
@@ -164,97 +227,143 @@ static void exynos5_sromc_config(int flags)* GPY6[6] EBI_DATA[14](2) * GPY6[7] EBI_DATA[15](2) */ -for (i =0 ; i <8 ; i++) { -gpio_cfg_pin (GPIO_Y30 + i,GPIO_FUNC (2 )); -gpio_set_pull (GPIO_Y30 + i,GPIO_PULL_UP ); + pdev.dev_name ="pingrp-srom-ebiaddr" ; -gpio_cfg_pin (GPIO_Y50 + i,GPIO_FUNC (2 )); -gpio_set_pull (GPIO_Y50 + i,GPIO_PULL_UP ); +/* Retrieve gpio range and base for SROM EBI address lines */ +if (get_fdt_values (&pdev)) +return -1 ; -gpio_cfg_pin (GPIO_Y60 + i,GPIO_FUNC (2 )); -gpio_set_pull (GPIO_Y60 + i,GPIO_PULL_UP ); +/* Apply pin configurations */ +for (i =0 ; i < pdev.count; i++) { +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (pdev.function)); +gpio_set_pull (pdev.start + i,GPIO_PULL_UP ); } + + pdev.dev_name ="pingrp-srom-ebidata" ; + +/* Retrieve gpio range and base for SROM EBI data lines */ +if (get_fdt_values (&pdev)) +return -1 ; + +/* Apply pin configurations */ +for (i =0 ; i < pdev.count; i++) { +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (pdev.function)); +gpio_set_pull (pdev.start + i,GPIO_PULL_UP ); + } + +return 0 ; } -static void exynos5_i2c_config (int peripheral,int flags) +static int exynos5_i2c_config (int peripheral,int flags) { +struct pinmux_dev pdev;switch (peripheral) {case PERIPH_ID_I2C0 : -gpio_cfg_pin (GPIO_B30 ,GPIO_FUNC (0x2 )); -gpio_cfg_pin (GPIO_B31 ,GPIO_FUNC (0x2 )); + pdev.dev_name ="pingrp-i2c0" ;break ;case PERIPH_ID_I2C1 : -gpio_cfg_pin (GPIO_B32 ,GPIO_FUNC (0x2 )); -gpio_cfg_pin (GPIO_B33 ,GPIO_FUNC (0x2 )); + pdev.dev_name ="pingrp-i2c1" ;break ;case PERIPH_ID_I2C2 : -gpio_cfg_pin (GPIO_A06 ,GPIO_FUNC (0x3 )); -gpio_cfg_pin (GPIO_A07 ,GPIO_FUNC (0x3 )); + pdev.dev_name ="pingrp-i2c2" ;break ;case PERIPH_ID_I2C3 : -gpio_cfg_pin (GPIO_A12 ,GPIO_FUNC (0x3 )); -gpio_cfg_pin (GPIO_A13 ,GPIO_FUNC (0x3 )); + pdev.dev_name ="pingrp-i2c3" ;break ;case PERIPH_ID_I2C4 : -gpio_cfg_pin (GPIO_A20 ,GPIO_FUNC (0x3 )); -gpio_cfg_pin (GPIO_A21 ,GPIO_FUNC (0x3 )); + pdev.dev_name ="pingrp-i2c4" ;break ;case PERIPH_ID_I2C5 : -gpio_cfg_pin (GPIO_A22 ,GPIO_FUNC (0x3 )); -gpio_cfg_pin (GPIO_A23 ,GPIO_FUNC (0x3 )); + pdev.dev_name ="pingrp-i2c5" ;break ;case PERIPH_ID_I2C6 : -gpio_cfg_pin (GPIO_B13 ,GPIO_FUNC (0x4 )); -gpio_cfg_pin (GPIO_B14 ,GPIO_FUNC (0x4 )); + pdev.dev_name ="pingrp-i2c6" ;break ;case PERIPH_ID_I2C7 : -gpio_cfg_pin (GPIO_B22 ,GPIO_FUNC (0x3 )); -gpio_cfg_pin (GPIO_B23 ,GPIO_FUNC (0x3 )); + pdev.dev_name ="pingrp-i2c7" ;break ; } + +/* Retrieve gpio range and base for this I2C */ +if (get_fdt_values (&pdev)) +return -1 ; + +/* Apply pin configurations */ +gpio_cfg_pin (pdev.start,GPIO_FUNC (pdev.function)); +gpio_cfg_pin (pdev.start +1 ,GPIO_FUNC (pdev.function)); + +return 0 ; } -static void exynos5_i2s_config (int peripheral) +static int exynos5_i2s_config (int peripheral) {int i; +struct pinmux_dev pdev; -for (i =0 ; i <5 ; i++) -gpio_cfg_pin (GPIO_B00 +i,GPIO_FUNC (0x02 )); + pdev.dev_name ="pingrp-i2s" ; + +/* Retrieve gpio range and base for I2S */ +if (get_fdt_values (&pdev)) +return -1 ; + +/* Apply pin configurations */ +for (i =0 ; i < pdev.count; i++) +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (pdev.function)); + +return 0 ; } -void exynos5_spi_config (int peripheral) +int exynos5_spi_config (int peripheral) { -int cfg =0 , pin =0 , i; +int i; +struct pinmux_dev pdev, pdev1;switch (peripheral) {case PERIPH_ID_SPI0 : - cfg =GPIO_FUNC (0x2 ); - pin =GPIO_A20 ; + pdev.dev_name ="pingrp-spi0" ;break ;case PERIPH_ID_SPI1 : - cfg =GPIO_FUNC (0x2 ); - pin =GPIO_A24 ; + pdev.dev_name ="pingrp-spi1" ;break ;case PERIPH_ID_SPI2 : - cfg =GPIO_FUNC (0x5 ); - pin =GPIO_B11 ; + pdev.dev_name ="pingrp-spi2" ;break ;case PERIPH_ID_SPI3 : - cfg =GPIO_FUNC (0x2 ); - pin =GPIO_F10 ; + pdev.dev_name ="pingrp-spi3" ;break ;case PERIPH_ID_SPI4 : -for (i =0 ; i <2 ; i++) { -gpio_cfg_pin (GPIO_F02 + i,GPIO_FUNC (0x4 )); -gpio_cfg_pin (GPIO_E04 + i,GPIO_FUNC (0x4 )); - } + pdev.dev_name ="pingrp-spi4-0" ; + pdev1.dev_name ="pingrp-spi4-1" ;break ; } +if (peripheral !=PERIPH_ID_SPI4 ) { -for (i = pin; i < pin +4 ; i++) -gpio_cfg_pin (i, cfg); +/* Retrieve gpio range and base for this SPI */ +if (get_fdt_values (&pdev)) +return -1 ; + +/* Apply pin configurations */ +for (i =0 ; i < pdev.count; i++) +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (pdev.function)); + }else { +/* Retrieve gpio range and base for spi-4 first group */ +if (get_fdt_values (&pdev)) +return -1 ; + +/* Retrieve gpio range and base for spi-4 second group */ +if (get_fdt_values (&pdev1)) +return -1 ; + +/* Apply pin configurations */ +for (i =0 ; i < pdev.count; i++) { +gpio_cfg_pin (pdev.start + i,GPIO_FUNC (pdev.function)); +gpio_cfg_pin (pdev1.start + i, +GPIO_FUNC (pdev1.function)); + } } + +return 0 ; }static int exynos5_pinmux_config (int peripheral,int flags)
@@ -264,7 +373,7 @@ static int exynos5_pinmux_config(int peripheral, int flags)case PERIPH_ID_UART1 :case PERIPH_ID_UART2 :case PERIPH_ID_UART3 : -exynos5_uart_config (peripheral); +return exynos5_uart_config (peripheral);break ;case PERIPH_ID_SDMMC0 :case PERIPH_ID_SDMMC1 :
@@ -272,7 +381,7 @@ static int exynos5_pinmux_config(int peripheral, int flags)case PERIPH_ID_SDMMC3 :return exynos5_mmc_config (peripheral, flags);case PERIPH_ID_SROMC : -exynos5_sromc_config (flags); +return exynos5_sromc_config (flags);break ;case PERIPH_ID_I2C0 :case PERIPH_ID_I2C1 :
@@ -282,24 +391,22 @@ static int exynos5_pinmux_config(int peripheral, int flags)case PERIPH_ID_I2C5 :case PERIPH_ID_I2C6 :case PERIPH_ID_I2C7 : -exynos5_i2c_config (peripheral, flags); +return exynos5_i2c_config (peripheral, flags);break ;case PERIPH_ID_I2S1 : -exynos5_i2s_config (peripheral); +return exynos5_i2s_config (peripheral);break ;case PERIPH_ID_SPI0 :case PERIPH_ID_SPI1 :case PERIPH_ID_SPI2 :case PERIPH_ID_SPI3 :case PERIPH_ID_SPI4 : -exynos5_spi_config (peripheral); +return exynos5_spi_config (peripheral);break ;default :debug ("%s: invalid peripheral %d" , __func__, peripheral);return -1 ; } - -return 0 ; }static void exynos4_i2c_config (int peripheral,int flags)
arch/arm/dts/exynos5250.dtsi +197 -0
201 lines not on this page · raw message
arch/arm/include/asm/arch-exynos/pinmux.h +9 -0
@@ -26,6 +26,15 @@#include "periph.h" +/* Struct for storing pin function and gpio related info */ +struct pinmux_dev { +char *dev_name; +int start; +int count; +int start_ext; +int function; +}; +/* * Flags for setting specific configarations of peripherals. * List will grow with support for more devices getting added.
include/fdtdec.h +1 -0
@@ -81,6 +81,7 @@ enum fdt_compat_id {COMPAT_SAMSUNG_EXYNOS_EHCI ,/* Exynos EHCI controller */ COMPAT_SAMSUNG_EXYNOS_USB_PHY ,/* Exynos phy controller for usb2.0 */ COMPAT_MAXIM_MAX77686_PMIC ,/* MAX77686 PMIC */ +COMPAT_SAMSUNG_PINMUX ,/* PINMUX */ COMPAT_COUNT, };
lib/fdtdec.c +1 -0
@@ -56,6 +56,7 @@ static const char * const compat_names[COMPAT_COUNT] = {COMPAT (SAMSUNG_EXYNOS_EHCI ,"samsung,exynos-ehci" ),COMPAT (SAMSUNG_EXYNOS_USB_PHY ,"samsung,exynos-usb-phy" ),COMPAT (MAXIM_MAX77686_PMIC ,"maxim,max77686_pmic" ), + COMPAT(SAMSUNG_PINMUX, "samsung,pinmux"), };const char *fdtdec_get_compatible (enum fdt_compat_id id)
Signature · 1 line
1.7.9.5
PATCH 1/1 Exynos5: Pinmux: Add fdt for pinmux
+Doug
Hi Akshay,
Quoted 5 lines · Akshay Saraswat
This patch adds fdt nodes for peripherals which require pin muxing and configuration. Existing pinmux code modified to retrieve gpio range and function related info from fdt.
Signed-off-by Akshay Saraswat <[email protected]>
Thanks for sending this patch which is most welcome. However, Doug pointed me to the kernel's binding document in Documentation/devicetree/bindings/pinctrl/samsung-pinctrl.txt
The binding seems similar but perhaps not the same. Can you please check it? We should really use the same binding unless there is a big reason why we can't in some particular case. Also please copy that binding document into U-Boot as part of your patch, since there is no central place for bindings right now.
Regards,
Simon
PATCH 1/1 Exynos5: Pinmux: Add fdt for pinmux
In reply to Akshay SaraswatQuoted 3 lines · Akshay Saraswat
This patch adds fdt nodes for peripherals which require pin muxing and configuration. Existing pinmux code modified to retrieve gpio range and function related info from fdt.
Is this the same DT binding that the Linux kernel uses; has it been reviewed/implemented by the kernel pinctrl maintainers and device tree maintainers? Where is the DT binding documentation file that describes the binding?