summaryrefslogtreecommitdiffstats
path: root/board/bct-brettl2/bct-brettl2.c
blob: 1f0dfb4d403e6dc97194ff4ad3f97fb49d89885a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * U-boot - main board file for BCT brettl2
 *
 * Copyright (c) 2010 BCT Electronic GmbH
 *
 * Licensed under the GPL-2 or later.
 */

#include <common.h>
#include <config.h>
#include <command.h>
#include <asm/blackfin.h>
#include <asm/portmux.h>
#include <asm/gpio.h>
#include <net.h>
#include <netdev.h>
#include <miiphy.h>

#include "../cm-bf537e/gpio_cfi_flash.h"
#include "smsc9303.h"

DECLARE_GLOBAL_DATA_PTR;

int checkboard(void)
{
	printf("Board: bct-brettl2 board\n");
	printf("       Support: http://www.bct-electronic.com/\n");
	return 0;
}

#ifdef CONFIG_BFIN_MAC
static void board_init_enetaddr(uchar *mac_addr)
{
	puts("Warning: Generating 'random' MAC address\n");
	net_random_ethaddr(mac_addr);
	eth_setenv_enetaddr("ethaddr", mac_addr);
}

int board_eth_init(bd_t *bis)
{
	int retry = 3;
	int ret;

	ret = bfin_EMAC_initialize(bis);

	uchar enetaddr[6];
	if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
		printf("setting MAC %pM\n", enetaddr);
	}
	puts("       ");

	puts("initialize SMSC LAN9303i ethernet switch\n");

	while (retry-- > 0) {
		if (init_smsc9303i_mii())
			return ret;
	}

	return ret;
}
#endif

static void init_tlv320aic31(void)
{
	puts("Audio: setup TIMER0 to enable 16.384 MHz clock for tlv320aic31\n");
	peripheral_request(P_TMR0, "tlv320aic31 clock");
	bfin_write_TIMER0_CONFIG(0x020d);
	bfin_write_TIMER0_PERIOD(0x0008);
	bfin_write_TIMER0_WIDTH(0x0008/2);
	bfin_write_TIMER_ENABLE(bfin_read_TIMER_ENABLE() | 1);
	SSYNC();
	udelay(10000);

	puts("       resetting tlv320aic31\n");

	gpio_request(GPIO_PF2, "tlv320aic31");
	gpio_direction_output(GPIO_PF2, 0);
	udelay(10000);
	gpio_direction_output(GPIO_PF2, 1);
	udelay(10000);
	gpio_free(GPIO_PF2);
}

static void init_mute_pin(void)
{
	printf("       unmute class D amplifier\n");

	gpio_request(GPIO_PF5, "mute");
	gpio_direction_output(GPIO_PF5, 1);
	gpio_free(GPIO_PF5);
}

/* sometimes LEDs (speech, status) are still on after reboot, turn 'em off */
static void turn_leds_off(void)
{
	printf("       turn LEDs off\n");

	gpio_request(GPIO_PF6, "led");
	gpio_direction_output(GPIO_PF6, 0);
	gpio_free(GPIO_PF6);

	gpio_request(GPIO_PF15, "led");
	gpio_direction_output(GPIO_PF15, 0);
	gpio_free(GPIO_PF15);
}

/* miscellaneous platform dependent initialisations */
int misc_init_r(void)
{
#ifdef CONFIG_BFIN_MAC
	uchar enetaddr[6];
	if (!eth_getenv_enetaddr("ethaddr", enetaddr))
		board_init_enetaddr(enetaddr);
#endif

	gpio_cfi_flash_init();
	init_tlv320aic31();
	init_mute_pin();
	turn_leds_off();

	return 0;
}