[adm8668] remove unused variables and defines
[openwrt.git] / target / linux / adm8668 / files / arch / mips / adm8668 / platform.c
1 /*
2  * Copyright (C) 2010 Scott Nicholas <neutronscott@scottn.us>
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  */
8
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <linux/mtd/physmap.h>
13 #include <linux/pci.h>
14 #include <linux/slab.h>
15 #include <linux/ioport.h>
16 #include <asm/reboot.h>
17 #include <asm/time.h>
18 #include <asm/addrspace.h>
19 #include <asm/bootinfo.h>
20 #include <asm/io.h>
21 #include <adm8668.h>
22
23 static struct resource uart_resources[] = {
24         {
25                 .start          = ADM8668_UART0_BASE,
26                 .end            = ADM8668_UART0_BASE + 0xF,
27                 .flags          = IORESOURCE_MEM,
28         },
29         {
30                 .start          = INT_LVL_UART0,
31                 .flags          = IORESOURCE_IRQ,
32         },
33 };
34
35 static struct platform_device adm8668_uart_device = {
36         .name           = "adm8668_uart",
37         .id             = 0,
38         .resource       = uart_resources,
39         .num_resources  = ARRAY_SIZE(uart_resources),
40 };
41
42 static struct resource eth0_resources[] = {
43         {
44                 .start          = ADM8668_LAN_BASE,
45                 .end            = ADM8668_LAN_BASE + 256,
46                 .flags          = IORESOURCE_MEM,
47         },
48         {
49                 .start          = INT_LVL_LAN,
50                 .flags          = IORESOURCE_IRQ,
51         },
52 };
53
54 static struct platform_device adm8668_eth0_device = {
55         .name           = "adm8668_eth",
56         .id             = 0,
57         .resource       = eth0_resources,
58         .num_resources  = ARRAY_SIZE(eth0_resources),
59 };
60
61 static struct resource eth1_resources[] = {
62         {
63                 .start          = ADM8668_WAN_BASE,
64                 .end            = ADM8668_WAN_BASE + 256,
65                 .flags          = IORESOURCE_MEM,
66         },
67         {
68                 .start          = INT_LVL_WAN,
69                 .flags          = IORESOURCE_IRQ,
70         },
71 };
72
73 static struct platform_device adm8668_eth1_device = {
74         .name           = "adm8668_eth",
75         .id             = 1,
76         .resource       = eth1_resources,
77         .num_resources  = ARRAY_SIZE(eth1_resources),
78 };
79
80 static void adm8668_restart(char *cmd)
81 {
82         int i;
83
84         /* stop eth0 and eth1 */
85         ADM8668_LAN_REG(NETCSR6) = (1 << 13) | (1 << 1);
86         ADM8668_LAN_REG(NETCSR7) = 0;
87         ADM8668_WAN_REG(NETCSR6) = (1 << 13) | (1 << 1);
88         ADM8668_WAN_REG(NETCSR7) = 0;
89
90         /* reset PHY */
91         ADM8668_WAN_REG(NETCSR37) = 0x20;
92         for (i = 0; i < 10000; i++)
93                 ;
94         ADM8668_WAN_REG(NETCSR37) = 0;
95         for (i = 0; i < 10000; i++)
96                 ;
97
98         *(volatile unsigned int *)0xB1600000 = 1;       /* reset eth0 mac */
99         *(volatile unsigned int *)0xB1A00000 = 1;       /* reset eth1 mac */
100         *(volatile unsigned int *)0xB1800000 = 1;       /* reset wlan0 mac */
101
102         /* the real deal */
103         for (i = 0; i < 1000; i++)
104                 ;
105         ADM8668_CONFIG_REG(ADM8668_CR1) = 1;
106 }
107
108 int __devinit adm8668_devs_register(void)
109 {
110         _machine_restart = adm8668_restart;
111         platform_device_register(&adm8668_uart_device);
112         platform_device_register(&adm8668_eth0_device);
113         platform_device_register(&adm8668_eth1_device);
114
115         return 0;
116 }
117
118 void __init plat_time_init(void)
119 {
120         int adj = (ADM8668_CONFIG_REG(ADM8668_CR3) >> 11) & 0xf;
121
122         /* adjustable clock selection
123            CR3 bit 14~11, 0000 -> 175MHz, 0001 -> 180MHz, etc... */
124
125         mips_hpt_frequency = (SYS_CLOCK + adj * 5000000) / 2;
126         printk("ADM8668 CPU clock: %d MHz\n", 2*mips_hpt_frequency / 1000000);
127 }
128
129 void __init plat_mem_setup(void)
130 {
131         /* prom_init seemed like easier place for this. it's tooo simple */
132 }
133
134 const char *get_system_type(void)
135 {
136         unsigned long chipid = ADM8668_CONFIG_REG(ADM8668_CR0);
137         int adj = (ADM8668_CONFIG_REG(ADM8668_CR3) >> 11) & 0xf;
138         int product, revision, mhz;
139         static char ret[32];
140
141         product = chipid >> 16;
142         revision = chipid & 0xffff;
143         mhz = (SYS_CLOCK/1000000) + (adj * 5);
144
145         /* i getting fancy :\ */
146         snprintf(ret, sizeof(ret), "ADM%xr%x %dMHz", product, revision, mhz);
147
148         return ret;
149 }
150
151 arch_initcall(adm8668_devs_register);