x86: baytrail: Add SIO HS-UART clock setup
PATCH 1/1 x86: baytrail: Add SIO HS-UART clock setup
To support the BayTrail internal SIO HS UART, the internal UART clock needs to get configured. This patch adds support for this clock configuration which will be done, if the PCI device(s) are found.
Signed-off-by Stefan Roese <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
--- arch/x86/cpu/baytrail/cpu.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
arch/x86/cpu/baytrail/cpu.c +52 -0
@@ -9,12 +9,64 @@#include <common.h> #include <cpu.h> #include <dm.h> +#include <pci.h> #include <asm/cpu.h> #include <asm/cpu_x86.h> +#include <asm/io.h> #include <asm/lapic.h> #include <asm/msr.h> #include <asm/turbo.h> +#define BYT_PRV_CLK 0x800 +#define BYT_PRV_CLK_EN (1 << 0) +#define BYT_PRV_CLK_M_VAL_SHIFT 1 +#define BYT_PRV_CLK_N_VAL_SHIFT 16 +#define BYT_PRV_CLK_UPDATE (1 << 31) + +#define BYT_HSUART0 PCI_BDF(0, 0x1e, 0x3) +#define BYT_HSUART1 PCI_BDF(0, 0x1e, 0x4) + +static void hsuart_clock_set (void *base) +{ +u32 m, n, reg; + +/* +* Configure the BayTrail UART clock for the internal HS UARTs +* (PCI devices) to 58982400 Hz +*/ + m =0x2400 ; + n =0x3d09 ; + reg = (m <<BYT_PRV_CLK_M_VAL_SHIFT ) | (n <<BYT_PRV_CLK_N_VAL_SHIFT ); +writel (reg, base +BYT_PRV_CLK ); + reg |=BYT_PRV_CLK_EN |BYT_PRV_CLK_UPDATE ; +writel (reg, base +BYT_PRV_CLK ); +} + +/* +* Configure the internal clock of both SIO HS-UARTs, if they are enabled +* via FSP +*/ +int arch_cpu_init_dm (void ) +{ +struct udevice *dev; +void *base; +int ret; + + ret =dm_pci_bus_find_bdf (BYT_HSUART0 , &dev); +if (!ret) { + base =dm_pci_map_bar (dev,PCI_BASE_ADDRESS_0 ,PCI_REGION_MEM ); +hsuart_clock_set (base); + } + + ret =dm_pci_bus_find_bdf (BYT_HSUART1 , &dev); +if (!ret) { + base =dm_pci_map_bar (dev,PCI_BASE_ADDRESS_0 ,PCI_REGION_MEM ); +hsuart_clock_set (base); + } + +return 0 ; +} +static void set_max_freq (void ) {msr_t perf_ctl;
Signature · 1 line
2.9.2
PATCH 1/1 x86: baytrail: Add SIO HS-UART clock setup
Hi Stefan,
Quoted 7 lines · Stefan Roese
To support the BayTrail internal SIO HS UART, the internal UART clock needs to get configured. This patch adds support for this clock configuration which will be done, if the PCI device(s) are found.
Signed-off-by Stefan Roese <[email protected]>Cc Simon Glass <[email protected]>Cc Bin Meng <[email protected]>
Looks good to me.
Reviewed-by Bin Meng <[email protected]>
One comments below:
Quoted 56 lines
--- arch/x86/cpu/baytrail/cpu.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)arch/x86/cpu/baytrail/cpu.c +38
-0@@ -9,12 +9,64 @@#include <common.h> #include <cpu.h> #include <dm.h> +#include <pci.h> #include <asm/cpu.h> #include <asm/cpu_x86.h> +#include <asm/io.h> #include <asm/lapic.h> #include <asm/msr.h> #include <asm/turbo.h> +#define BYT_PRV_CLK 0x800 +#define BYT_PRV_CLK_EN (1 << 0) +#define BYT_PRV_CLK_M_VAL_SHIFT 1 +#define BYT_PRV_CLK_N_VAL_SHIFT 16 +#define BYT_PRV_CLK_UPDATE (1 << 31) + +#define BYT_HSUART0 PCI_BDF(0, 0x1e, 0x3) +#define BYT_HSUART1 PCI_BDF(0, 0x1e, 0x4) + +static void hsuart_clock_set (void *base) +{ +u32 m, n, reg; + +/* +* Configure the BayTrail UART clock for the internal HS UARTs +* (PCI devices) to 58982400 Hz +*/ + m =0x2400 ; + n =0x3d09 ; + reg = (m <<BYT_PRV_CLK_M_VAL_SHIFT ) | (n <<BYT_PRV_CLK_N_VAL_SHIFT ); +writel (reg, base +BYT_PRV_CLK ); + reg |=BYT_PRV_CLK_EN |BYT_PRV_CLK_UPDATE ; +writel (reg, base +BYT_PRV_CLK ); +} + +/* +* Configure the internal clock of both SIO HS-UARTs, if they are enabled +* via FSP +*/ +int arch_cpu_init_dm (void ) +{ +struct udevice *dev; +void *base; +int ret; + + ret =dm_pci_bus_find_bdf (BYT_HSUART0 , &dev);
arch/x86/cpu/baytrail/cpu.c line 65
Quoted 10 lines
arch/x86/cpu/baytrail/cpu.c +10
-0+if (!ret) { + base =dm_pci_map_bar (dev,PCI_BASE_ADDRESS_0 ,PCI_REGION_MEM ); +hsuart_clock_set (base); + } + + ret =dm_pci_bus_find_bdf (BYT_HSUART1 , &dev); +if (!ret) { + base =dm_pci_map_bar (dev,PCI_BASE_ADDRESS_0 ,PCI_REGION_MEM ); +hsuart_clock_set (base); + }
Maybe we can just use a loop to save some duplication? like:
for (i =0; i < 2; i++) {
ret = dm_pci_bus_find_bdf(PCI_BDF(0, 0x1e, 3 + i), &dev);
if (!ret) {
base = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
hsuart_clock_set(base);
}
}arch/x86/cpu/baytrail/cpu.c
Quoted 8 lines
arch/x86/cpu/baytrail/cpu.c +4
-1+ +return 0 ; +} +static void set_max_freq (void ) {msr_t perf_ctl; --
Regards,
Bin