aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/adm8668/files/arch/mips/adm8668/platform.c
blob: 803af09aab3382900210cb7cdec58d49c0cb9ae4 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * Copyright (C) 2010 Scott Nicholas <neutronscott@scottn.us>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/mtd/physmap.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <asm/reboot.h>
#include <asm/time.h>
#include <asm/addrspace.h>
#include <asm/bootinfo.h>
#include <asm/io.h>
#include <adm8668.h>

static struct resource uart_resources[] = {
	{
		.start		= ADM8668_UART0_BASE,
		.end		= ADM8668_UART0_BASE + 0xF,
		.flags		= IORESOURCE_MEM,
	},
	{
		.start		= INT_LVL_UART0,
		.flags		= IORESOURCE_IRQ,
	},
};

static struct platform_device adm8668_uart_device = {
	.name		= "adm8668_uart",
	.id		= 0,
	.resource	= uart_resources,
	.num_resources	= ARRAY_SIZE(uart_resources),
};

static struct resource eth0_resources[] = {
	{
		.start		= ADM8668_LAN_BASE,
		.end		= ADM8668_LAN_BASE + 256,
		.flags		= IORESOURCE_MEM,
	},
	{
		.start		= INT_LVL_LAN,
		.flags		= IORESOURCE_IRQ,
	},
};

static struct platform_device adm8668_eth0_device = {
	.name		= "adm8668_eth",
	.id		= 0,
	.resource	= eth0_resources,
	.num_resources	= ARRAY_SIZE(eth0_resources),
};

static struct resource eth1_resources[] = {
	{
		.start		= ADM8668_WAN_BASE,
		.end		= ADM8668_WAN_BASE + 256,
		.flags		= IORESOURCE_MEM,
	},
	{
		.start		= INT_LVL_WAN,
		.flags		= IORESOURCE_IRQ,
	},
};

static struct platform_device adm8668_eth1_device = {
	.name		= "adm8668_eth",
	.id		= 1,
	.resource	= eth1_resources,
	.num_resources	= ARRAY_SIZE(eth1_resources),
};

static void adm8668_restart(char *cmd)
{
	int i;

	/* stop eth0 and eth1 */
	ADM8668_LAN_REG(NETCSR6) = (1 << 13) | (1 << 1);
	ADM8668_LAN_REG(NETCSR7) = 0;
	ADM8668_WAN_REG(NETCSR6) = (1 << 13) | (1 << 1);
	ADM8668_WAN_REG(NETCSR7) = 0;

	/* reset PHY */
	ADM8668_WAN_REG(NETCSR37) = 0x20;
	for (i = 0; i < 10000; i++)
		;
	ADM8668_WAN_REG(NETCSR37) = 0;
	for (i = 0; i < 10000; i++)
		;

	*(volatile unsigned int *)0xB1600000 = 1;	/* reset eth0 mac */
	*(volatile unsigned int *)0xB1A00000 = 1;	/* reset eth1 mac */
	*(volatile unsigned int *)0xB1800000 = 1;	/* reset wlan0 mac */

	/* the real deal */
	for (i = 0; i < 1000; i++)
		;
	ADM8668_CONFIG_REG(ADM8668_CR1) = 1;
}

int __devinit adm8668_devs_register(void)
{
	_machine_restart = adm8668_restart;
	platform_device_register(&adm8668_uart_device);
	platform_device_register(&adm8668_eth0_device);
	platform_device_register(&adm8668_eth1_device);

	return 0;
}

void __init plat_time_init(void)
{
	int adj = (ADM8668_CONFIG_REG(ADM8668_CR3) >> 11) & 0xf;

	/* adjustable clock selection
	   CR3 bit 14~11, 0000 -> 175MHz, 0001 -> 180MHz, etc... */

	mips_hpt_frequency = (SYS_CLOCK + adj * 5000000) / 2;
	printk("ADM8668 CPU clock: %d MHz\n", 2*mips_hpt_frequency / 1000000);
}

void __init plat_mem_setup(void)
{
	/* prom_init seemed like easier place for this. it's tooo simple */
}

const char *get_system_type(void)
{
        unsigned long chipid = ADM8668_CONFIG_REG(ADM8668_CR0);
        int adj = (ADM8668_CONFIG_REG(ADM8668_CR3) >> 11) & 0xf;
        int product, revision, mhz;
	static char ret[32];

        product = chipid >> 16;
        revision = chipid & 0xffff;
	mhz = (SYS_CLOCK/1000000) + (adj * 5);

	/* i getting fancy :\ */
	snprintf(ret, sizeof(ret), "ADM%xr%x %dMHz", product, revision, mhz);

	return ret;
}

arch_initcall(adm8668_devs_register);