Root/target/linux/ramips/files/arch/mips/ralink/rt3883/mach-dir-645.c

1/*
2 * D-Link DIR-645 board support
3 *
4 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11#include <linux/init.h>
12#include <linux/platform_device.h>
13#include <linux/rtl8367.h>
14#include <linux/ethtool.h>
15#include <linux/rt2x00_platform.h>
16#include <linux/spi/spi.h>
17#include <linux/gpio.h>
18
19#include <asm/mach-ralink/machine.h>
20#include <asm/mach-ralink/dev-gpio-buttons.h>
21#include <asm/mach-ralink/dev-gpio-leds.h>
22#include <asm/mach-ralink/rt3883.h>
23#include <asm/mach-ralink/rt3883_regs.h>
24#include <asm/mach-ralink/ramips_eth_platform.h>
25
26#include "devices.h"
27
28#define DIR_645_GPIO_LED_INET 0
29#define DIR_645_GPIO_LED_WPS 26
30
31#define DIR_645_GPIO_BUTTON_RESET 9
32#define DIR_645_GPIO_BUTTON_WPS 14
33
34#define DIR_645_GPIO_USB_POWER 30
35
36#define DIR_645_GPIO_RTL8367_SCK 2
37#define DIR_645_GPIO_RTL8367_SDA 1
38
39#define DIR_645_KEYS_POLL_INTERVAL 20
40#define DIR_645_KEYS_DEBOUNCE_INTERVAL (3 * DIR_645_KEYS_POLL_INTERVAL)
41
42static struct gpio_led dir_645_leds_gpio[] __initdata = {
43    {
44        .name = "d-link:green:inet",
45        .gpio = DIR_645_GPIO_LED_INET,
46        .active_low = 1,
47    },
48    {
49        .name = "d-link:green:wps",
50        .gpio = DIR_645_GPIO_LED_WPS,
51        .active_low = 1,
52    },
53};
54
55static struct gpio_keys_button dir_645_gpio_buttons[] __initdata = {
56    {
57        .desc = "reset",
58        .type = EV_KEY,
59        .code = KEY_RESTART,
60        .debounce_interval = DIR_645_KEYS_DEBOUNCE_INTERVAL,
61        .gpio = DIR_645_GPIO_BUTTON_RESET,
62        .active_low = 1,
63    },
64    {
65        .desc = "wps",
66        .type = EV_KEY,
67        .code = KEY_WPS_BUTTON,
68        .debounce_interval = DIR_645_KEYS_DEBOUNCE_INTERVAL,
69        .gpio = DIR_645_GPIO_BUTTON_WPS,
70        .active_low = 1,
71    }
72};
73
74static struct rtl8367_extif_config dir_645_rtl8367_extif1_cfg = {
75    .txdelay = 1,
76    .rxdelay = 0,
77    .mode = RTL8367_EXTIF_MODE_RGMII,
78    .ability = {
79        .force_mode = 1,
80        .txpause = 1,
81        .rxpause = 1,
82        .link = 1,
83        .duplex = 1,
84        .speed = RTL8367_PORT_SPEED_1000,
85    }
86};
87
88static struct rtl8367_platform_data dir_645_rtl8367_data = {
89    .gpio_sda = DIR_645_GPIO_RTL8367_SDA,
90    .gpio_sck = DIR_645_GPIO_RTL8367_SCK,
91    .extif1_cfg = &dir_645_rtl8367_extif1_cfg,
92};
93
94static struct platform_device dir_645_rtl8367_device = {
95    .name = RTL8367B_DRIVER_NAME,
96    .id = -1,
97    .dev = {
98        .platform_data = &dir_645_rtl8367_data,
99    }
100};
101
102static struct spi_board_info dir_645_spi_info[] = {
103    {
104        .bus_num = 0,
105        .chip_select = 0,
106        .max_speed_hz = 25000000,
107        .modalias = "m25p80",
108    }
109};
110
111static void __init dir_645_gpio_init(void)
112{
113    rt3883_gpio_init(RT3883_GPIO_MODE_I2C |
114             RT3883_GPIO_MODE_UART0(RT3883_GPIO_MODE_GPIO) |
115             RT3883_GPIO_MODE_JTAG |
116             RT3883_GPIO_MODE_PCI(RT3883_GPIO_MODE_PCI_FNC));
117
118    gpio_request_one(DIR_645_GPIO_USB_POWER,
119             GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
120             "USB power");
121}
122
123static void __init dir_645_init(void)
124{
125    dir_645_gpio_init();
126
127    rt3883_register_spi(dir_645_spi_info,
128                ARRAY_SIZE(dir_645_spi_info));
129
130    ramips_register_gpio_leds(-1, ARRAY_SIZE(dir_645_leds_gpio),
131                  dir_645_leds_gpio);
132
133    ramips_register_gpio_buttons(-1, DIR_645_KEYS_POLL_INTERVAL,
134                     ARRAY_SIZE(dir_645_gpio_buttons),
135                     dir_645_gpio_buttons);
136
137    platform_device_register(&dir_645_rtl8367_device);
138
139    rt3883_wlan_data.disable_5ghz = 1;
140    rt3883_register_wlan();
141
142    rt3883_eth_data.speed = SPEED_1000;
143    rt3883_eth_data.duplex = DUPLEX_FULL;
144    rt3883_eth_data.tx_fc = 1;
145    rt3883_eth_data.rx_fc = 1;
146    rt3883_register_ethernet();
147
148    rt3883_register_wdt(false);
149    rt3883_register_usbhost();
150}
151
152MIPS_MACHINE(RAMIPS_MACH_DIR_645, "DIR-645", "D-Link DIR-645", dir_645_init);
153

Archive Download this file



interactive