• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018 Microchip Technology Inc. and its subsidiaries
4  */
5 
6 #include <common.h>
7 #include <asm/arch/at91_common.h>
8 #include <asm/arch/clk.h>
9 #include <asm/arch/gpio.h>
10 #include <asm/io.h>
11 
get_chip_id(void)12 unsigned int get_chip_id(void)
13 {
14 	/* The 0x40 is the offset of cidr in DBGU */
15 	return readl(ATMEL_BASE_DBGU + 0x40) & ~ARCH_ID_VERSION_MASK;
16 }
17 
get_extension_chip_id(void)18 unsigned int get_extension_chip_id(void)
19 {
20 	/* The 0x44 is the offset of exid in DBGU */
21 	return readl(ATMEL_BASE_DBGU + 0x44);
22 }
23 
has_emac1(void)24 unsigned int has_emac1(void)
25 {
26 	return cpu_is_sam9x60();
27 }
28 
has_emac0(void)29 unsigned int has_emac0(void)
30 {
31 	return cpu_is_sam9x60();
32 }
33 
has_lcdc(void)34 unsigned int has_lcdc(void)
35 {
36 	return cpu_is_sam9x60();
37 }
38 
get_cpu_name(void)39 char *get_cpu_name(void)
40 {
41 	unsigned int extension_id = get_extension_chip_id();
42 
43 	if (cpu_is_sam9x60()) {
44 		switch (extension_id) {
45 		case ARCH_EXID_SAM9X60:
46 			return "SAM9X60";
47 		default:
48 			return "Unknown CPU type";
49 		}
50 	} else {
51 		return "Unknown CPU type";
52 	}
53 }
54 
at91_seriald_hw_init(void)55 void at91_seriald_hw_init(void)
56 {
57 	at91_pio3_set_a_periph(AT91_PIO_PORTA, 9, 1);	/* DRXD */
58 	at91_pio3_set_a_periph(AT91_PIO_PORTA, 10, 1);	/* DTXD */
59 
60 	at91_periph_clk_enable(ATMEL_ID_DBGU);
61 }
62 
at91_mci_hw_init(void)63 void at91_mci_hw_init(void)
64 {
65 	/* Initialize the SDMMC0 */
66 	at91_pio3_set_a_periph(AT91_PIO_PORTA, 17, 1);	/* CLK */
67 	at91_pio3_set_a_periph(AT91_PIO_PORTA, 16, 1);	/* CMD */
68 	at91_pio3_set_a_periph(AT91_PIO_PORTA, 15, 1);	/* DAT0 */
69 	at91_pio3_set_a_periph(AT91_PIO_PORTA, 18, 1);	/* DAT1 */
70 	at91_pio3_set_a_periph(AT91_PIO_PORTA, 19, 1);	/* DAT2 */
71 	at91_pio3_set_a_periph(AT91_PIO_PORTA, 20, 1);	/* DAT3 */
72 
73 	at91_periph_clk_enable(ATMEL_ID_SDMMC0);
74 }
75 
76 #ifdef CONFIG_MACB
at91_macb_hw_init(void)77 void at91_macb_hw_init(void)
78 {
79 	if (has_emac0()) {
80 		/* Enable EMAC0 clock */
81 		at91_periph_clk_enable(ATMEL_ID_EMAC0);
82 		/* EMAC0 pins setup */
83 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 4, 0);	/* ETXCK */
84 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 3, 0);	/* ERXDV */
85 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0);	/* ERX0 */
86 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 1, 0);	/* ERX1 */
87 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0);	/* ERXER */
88 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0);	/* ETXEN */
89 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0);	/* ETX0 */
90 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 10, 0);	/* ETX1 */
91 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 5, 0);	/* EMDIO */
92 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0);	/* EMDC */
93 	}
94 
95 	if (has_emac1()) {
96 		/* Enable EMAC1 clock */
97 		at91_periph_clk_enable(ATMEL_ID_EMAC1);
98 		/* EMAC1 pins setup */
99 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 29, 0);	/* ETXCK */
100 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 28, 0);	/* ECRSDV */
101 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 20, 0);	/* ERXO */
102 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 21, 0);	/* ERX1 */
103 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 16, 0);	/* ERXER */
104 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 27, 0);	/* ETXEN */
105 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 18, 0);	/* ETX0 */
106 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 19, 0);	/* ETX1 */
107 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 31, 0);	/* EMDIO */
108 		at91_pio3_set_b_periph(AT91_PIO_PORTC, 30, 0);	/* EMDC */
109 	}
110 
111 #ifndef CONFIG_RMII
112 	/* Only emac0 support MII */
113 	if (has_emac0()) {
114 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0);	/* ECRS */
115 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0);	/* ECOL */
116 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0);	/* ERX2 */
117 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 14, 0);	/* ERX3 */
118 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 15, 0);	/* ERXCK */
119 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 11, 0);	/* ETX2 */
120 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0);	/* ETX3 */
121 		at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0);	/* ETXER */
122 	}
123 #endif
124 }
125 #endif
126