summaryrefslogtreecommitdiffstats
path: root/arch/arm/boards/solidrun-microsom/board.c
blob: 155199ff7828ddd50525ab0c1c89a04e23e8490e (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (C) 2013 Lucas Stach <l.stach@pengutronix.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <asm/armlinux.h>
#include <asm/io.h>
#include <bootsource.h>
#include <common.h>
#include <environment.h>
#include <envfs.h>
#include <gpio.h>
#include <init.h>
#include <mach/bbu.h>
#include <mach/generic.h>
#include <mach/imx6-regs.h>
#include <mach/imx6.h>
#include <mfd/imx6q-iomuxc-gpr.h>
#include <linux/clk.h>
#include <linux/sizes.h>
#include <linux/phy.h>

static int ar8035_phy_fixup(struct phy_device *dev)
{
	u16 val;

	/* Ar803x phy SmartEEE feature cause link status generates glitch,
	 * which cause ethernet link down/up issue, so disable SmartEEE
	 */
	phy_write(dev, 0xd, 0x3);
	phy_write(dev, 0xe, 0x805d);
	phy_write(dev, 0xd, 0x4003);

	val = phy_read(dev, 0xe);
	phy_write(dev, 0xe, val & ~(1 << 8));

	/* To enable AR8031 ouput a 125MHz clk from CLK_25M */
	phy_write(dev, 0xd, 0x7);
	phy_write(dev, 0xe, 0x8016);
	phy_write(dev, 0xd, 0x4007);

	val = phy_read(dev, 0xe);
	val &= 0xffe3;
	val |= 0x18;
	phy_write(dev, 0xe, val);

	/* introduce tx clock delay */
	phy_write(dev, 0x1d, 0x5);
	val = phy_read(dev, 0x1e);
	val |= 0x0100;
	phy_write(dev, 0x1e, val);

	return 0;
}

static void microsom_eth_init(void)
{
	void __iomem *iomux = (void *)MX6_IOMUXC_BASE_ADDR;
	u32 val;

	clk_set_rate(clk_lookup("enet_ref"), 25000000);

	val = readl(iomux + IOMUXC_GPR1);
	val |= IMX6Q_GPR1_ENET_CLK_SEL_ANATOP;
	writel(val, iomux + IOMUXC_GPR1);

	phy_register_fixup_for_uid(0x004dd072, 0xffffffef, ar8035_phy_fixup);
}
static int hummingboard_device_init(void)
{
	if (!of_machine_is_compatible("solidrun,hummingboard/dl") &&
	    !of_machine_is_compatible("solidrun,hummingboard/q") &&
	    !of_machine_is_compatible("solidrun,hummingboard2/dl") &&
	    !of_machine_is_compatible("solidrun,hummingboard2/q"))
		return 0;

	microsom_eth_init();

	/* enable USB VBUS */
	gpio_direction_output(IMX_GPIO_NR(3, 22), 1);
	gpio_direction_output(IMX_GPIO_NR(1, 0), 1);

	barebox_set_hostname("hummingboard");

	return 0;
}
device_initcall(hummingboard_device_init);

static int h100_device_init(void)
{
	if (!of_machine_is_compatible("auvidea,h100"))
		return 0;

	microsom_eth_init();

	barebox_set_hostname("h100");

	return 0;
}
device_initcall(h100_device_init);

static int hummingboard_late_init(void)
{
	bool emmc_present = false;

	if (!of_machine_is_compatible("solidrun,hummingboard/dl") &&
	    !of_machine_is_compatible("solidrun,hummingboard/q") &&
	    !of_machine_is_compatible("solidrun,hummingboard2/dl") &&
	    !of_machine_is_compatible("solidrun,hummingboard2/q") &&
	    !of_machine_is_compatible("auvidea,h100"))
		return 0;

	if (of_machine_is_compatible("solidrun,hummingboard2/dl") ||
	    of_machine_is_compatible("solidrun,hummingboard2/q"))
		emmc_present = true;

	imx6_bbu_internal_mmc_register_handler("sdcard", "/dev/mmc1.barebox",
		emmc_present ? 0 : BBU_HANDLER_FLAG_DEFAULT);

	if (emmc_present) {
		imx6_bbu_internal_mmc_register_handler("emmc",
			"/dev/mmc2.barebox", BBU_HANDLER_FLAG_DEFAULT);
	}

	return 0;
}
late_initcall(hummingboard_late_init);