Merge tag 'mips-pull-2020-06-29' of https://gitlab.denx.de/u-boot/custodians/u-boot...
[platform/kernel/u-boot.git] / board / toradex / colibri_pxa270 / colibri_pxa270.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Toradex Colibri PXA270 Support
4  *
5  * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
6  * Copyright (C) 2016-2019 Marcel Ziswiler <marcel.ziswiler@toradex.com>
7  */
8
9 #include <common.h>
10 #include <cpu_func.h>
11 #include <dm.h>
12 #include <init.h>
13 #include <net.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/arch/pxa.h>
16 #include <asm/arch/regs-mmc.h>
17 #include <asm/arch/regs-uart.h>
18 #include <asm/io.h>
19 #include <dm/platdata.h>
20 #include <dm/platform_data/pxa_mmc_gen.h>
21 #include <dm/platform_data/serial_pxa.h>
22 #include <netdev.h>
23 #include <serial.h>
24 #include <usb.h>
25 #include <asm/mach-types.h>
26 #include <linux/delay.h>
27 #include "../common/tdx-common.h"
28
29 DECLARE_GLOBAL_DATA_PTR;
30
31 int board_init(void)
32 {
33         /* We have RAM, disable cache */
34         dcache_disable();
35         icache_disable();
36
37         /* arch number of Toradex Colibri PXA270 */
38         gd->bd->bi_arch_number = MACH_TYPE_COLIBRI;
39
40         /* address of boot parameters */
41         gd->bd->bi_boot_params = 0xa0000100;
42
43         return 0;
44 }
45
46 int checkboard(void)
47 {
48         puts("Model: Toradex Colibri PXA270\n");
49
50         return 0;
51 }
52
53 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
54 int ft_board_setup(void *blob, bd_t *bd)
55 {
56         return ft_common_board_setup(blob, bd);
57 }
58 #endif
59
60 int dram_init(void)
61 {
62         pxa2xx_dram_init();
63         gd->ram_size = PHYS_SDRAM_1_SIZE;
64         return 0;
65 }
66
67 #ifdef  CONFIG_CMD_USB
68 int board_usb_init(int index, enum usb_init_type init)
69 {
70         writel((readl(UHCHR) | UHCHR_PCPL | UHCHR_PSPL) &
71                 ~(UHCHR_SSEP0 | UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE),
72                 UHCHR);
73
74         writel(readl(UHCHR) | UHCHR_FSBIR, UHCHR);
75
76         while (UHCHR & UHCHR_FSBIR)
77                 ;
78
79         writel(readl(UHCHR) & ~UHCHR_SSE, UHCHR);
80         writel((UHCHIE_UPRIE | UHCHIE_RWIE), UHCHIE);
81
82         /* Clear any OTG Pin Hold */
83         if (readl(PSSR) & PSSR_OTGPH)
84                 writel(readl(PSSR) | PSSR_OTGPH, PSSR);
85
86         writel(readl(UHCRHDA) & ~(0x200), UHCRHDA);
87         writel(readl(UHCRHDA) | 0x100, UHCRHDA);
88
89         /* Set port power control mask bits, only 3 ports. */
90         writel(readl(UHCRHDB) | (0x7 << 17), UHCRHDB);
91
92         /* enable port 2 */
93         writel(readl(UP2OCR) | UP2OCR_HXOE | UP2OCR_HXS |
94                 UP2OCR_DMPDE | UP2OCR_DPPDE, UP2OCR);
95
96         return 0;
97 }
98
99 int board_usb_cleanup(int index, enum usb_init_type init)
100 {
101         return 0;
102 }
103
104 void usb_board_stop(void)
105 {
106         writel(readl(UHCHR) | UHCHR_FHR, UHCHR);
107         udelay(11);
108         writel(readl(UHCHR) & ~UHCHR_FHR, UHCHR);
109
110         writel(readl(UHCCOMS) | 1, UHCCOMS);
111         udelay(10);
112
113         writel(readl(CKEN) & ~CKEN10_USBHOST, CKEN);
114 }
115 #endif
116
117 #ifdef CONFIG_DRIVER_DM9000
118 int board_eth_init(bd_t *bis)
119 {
120         return dm9000_initialize(bis);
121 }
122 #endif
123
124 #ifdef  CONFIG_CMD_MMC
125 #if !CONFIG_IS_ENABLED(DM_MMC)
126 int board_mmc_init(bd_t *bis)
127 {
128         pxa_mmc_register(0);
129         return 0;
130 }
131 #else /* !CONFIG_IS_ENABLED(DM_MMC) */
132 static const struct pxa_mmc_plat mmc_platdata = {
133         .base = (struct pxa_mmc_regs *)MMC0_BASE,
134 };
135
136 U_BOOT_DEVICE(pxa_mmcs) = {
137         .name = "pxa_mmc",
138         .platdata = &mmc_platdata,
139 };
140 #endif /* !CONFIG_IS_ENABLED(DM_MMC) */
141 #endif
142
143 static const struct pxa_serial_platdata serial_platdata = {
144         .base = (struct pxa_uart_regs *)FFUART_BASE,
145         .port = FFUART_INDEX,
146         .baudrate = CONFIG_BAUDRATE,
147 };
148
149 U_BOOT_DEVICE(pxa_serials) = {
150         .name = "serial_pxa",
151         .platdata = &serial_platdata,
152 };