| 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 | extern char _end; |
| 24 | #define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK) |
| 25 | |
| 26 | static struct resource uart_resources[] = { |
| 27 | { |
| 28 | .start = ADM8668_UART0_BASE, |
| 29 | .end = ADM8668_UART0_BASE + 0xF, |
| 30 | .flags = IORESOURCE_MEM, |
| 31 | }, |
| 32 | { |
| 33 | .start = INT_LVL_UART0, |
| 34 | .flags = IORESOURCE_IRQ, |
| 35 | }, |
| 36 | }; |
| 37 | |
| 38 | static struct platform_device adm8668_uart_device = { |
| 39 | .name = "adm8668_uart", |
| 40 | .id = 0, |
| 41 | .resource = uart_resources, |
| 42 | .num_resources = ARRAY_SIZE(uart_resources), |
| 43 | }; |
| 44 | |
| 45 | static struct resource eth0_resources[] = { |
| 46 | { |
| 47 | .start = ADM8668_LAN_BASE, |
| 48 | .end = ADM8668_LAN_BASE + 256, |
| 49 | .flags = IORESOURCE_MEM, |
| 50 | }, |
| 51 | { |
| 52 | .start = INT_LVL_LAN, |
| 53 | .flags = IORESOURCE_IRQ, |
| 54 | }, |
| 55 | }; |
| 56 | |
| 57 | static struct platform_device adm8668_eth0_device = { |
| 58 | .name = "adm8668_eth", |
| 59 | .id = 0, |
| 60 | .resource = eth0_resources, |
| 61 | .num_resources = ARRAY_SIZE(eth0_resources), |
| 62 | }; |
| 63 | |
| 64 | static struct resource eth1_resources[] = { |
| 65 | { |
| 66 | .start = ADM8668_WAN_BASE, |
| 67 | .end = ADM8668_WAN_BASE + 256, |
| 68 | .flags = IORESOURCE_MEM, |
| 69 | }, |
| 70 | { |
| 71 | .start = INT_LVL_WAN, |
| 72 | .flags = IORESOURCE_IRQ, |
| 73 | }, |
| 74 | }; |
| 75 | |
| 76 | static struct platform_device adm8668_eth1_device = { |
| 77 | .name = "adm8668_eth", |
| 78 | .id = 1, |
| 79 | .resource = eth1_resources, |
| 80 | .num_resources = ARRAY_SIZE(eth1_resources), |
| 81 | }; |
| 82 | |
| 83 | static void adm8668_restart(char *cmd) |
| 84 | { |
| 85 | int i; |
| 86 | |
| 87 | /* stop eth0 and eth1 */ |
| 88 | ADM8668_LAN_REG(NETCSR6) = (1 << 13) | (1 << 1); |
| 89 | ADM8668_LAN_REG(NETCSR7) = 0; |
| 90 | ADM8668_WAN_REG(NETCSR6) = (1 << 13) | (1 << 1); |
| 91 | ADM8668_WAN_REG(NETCSR7) = 0; |
| 92 | |
| 93 | /* reset PHY */ |
| 94 | ADM8668_WAN_REG(NETCSR37) = 0x20; |
| 95 | for (i = 0; i < 10000; i++) |
| 96 | ; |
| 97 | ADM8668_WAN_REG(NETCSR37) = 0; |
| 98 | for (i = 0; i < 10000; i++) |
| 99 | ; |
| 100 | |
| 101 | *(volatile unsigned int *)0xB1600000 = 1; /* reset eth0 mac */ |
| 102 | *(volatile unsigned int *)0xB1A00000 = 1; /* reset eth1 mac */ |
| 103 | *(volatile unsigned int *)0xB1800000 = 1; /* reset wlan0 mac */ |
| 104 | |
| 105 | /* the real deal */ |
| 106 | for (i = 0; i < 1000; i++) |
| 107 | ; |
| 108 | ADM8668_CONFIG_REG(ADM8668_CR1) = 1; |
| 109 | } |
| 110 | |
| 111 | int __devinit adm8668_devs_register(void) |
| 112 | { |
| 113 | _machine_restart = adm8668_restart; |
| 114 | platform_device_register(&adm8668_uart_device); |
| 115 | platform_device_register(&adm8668_eth0_device); |
| 116 | platform_device_register(&adm8668_eth1_device); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | void __init plat_time_init(void) |
| 122 | { |
| 123 | int adj = (ADM8668_CONFIG_REG(ADM8668_CR3) >> 11) & 0xf; |
| 124 | |
| 125 | /* adjustable clock selection |
| 126 | CR3 bit 14~11, 0000 -> 175MHz, 0001 -> 180MHz, etc... */ |
| 127 | |
| 128 | mips_hpt_frequency = (SYS_CLOCK + adj * 5000000) / 2; |
| 129 | printk("ADM8668 CPU clock: %d MHz\n", 2*mips_hpt_frequency / 1000000); |
| 130 | } |
| 131 | |
| 132 | void __init plat_mem_setup(void) |
| 133 | { |
| 134 | /* prom_init seemed like easier place for this. it's tooo simple */ |
| 135 | } |
| 136 | |
| 137 | const char *get_system_type(void) |
| 138 | { |
| 139 | unsigned long chipid = ADM8668_CONFIG_REG(ADM8668_CR0); |
| 140 | int adj = (ADM8668_CONFIG_REG(ADM8668_CR3) >> 11) & 0xf; |
| 141 | int product, revision, mhz; |
| 142 | static char ret[32]; |
| 143 | |
| 144 | product = chipid >> 16; |
| 145 | revision = chipid & 0xffff; |
| 146 | mhz = (SYS_CLOCK/1000000) + (adj * 5); |
| 147 | |
| 148 | /* i getting fancy :\ */ |
| 149 | snprintf(ret, sizeof(ret), "ADM%xr%x %dMHz", product, revision, mhz); |
| 150 | |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | arch_initcall(adm8668_devs_register); |
| 155 | |