summaryrefslogtreecommitdiffstats
path: root/target/linux/ar71xx/files/arch/mips/ar71xx/mach-rb-4xx.c
blob: 7504c349a6a9ec074b836bc8baf0ed00a93d7647 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
 *  MikroTik RouterBOARD 4xx series support
 *
 *  Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
 *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License version 2 as published
 *  by the Free Software Foundation.
 */

#include <linux/platform_device.h>
#include <linux/irq.h>
#include <linux/mmc/host.h>
#include <linux/spi/spi.h>
#include <linux/spi/flash.h>
#include <linux/spi/mmc_spi.h>
#include <linux/leds.h>

#include <asm/mips_machine.h>
#include <asm/mach-ar71xx/ar71xx.h>
#include <asm/mach-ar71xx/pci.h>
#include <asm/mach-ar71xx/platform.h>

#define RB4XX_GPIO_USER_LED	4

static struct gpio_led rb4xx_leds_gpio[] = {
	{
		.name		= "rb4xx:yellow:user",
		.gpio		= RB4XX_GPIO_USER_LED,
		.active_low	= 0,
	},
};

static struct gpio_led_platform_data rb4xx_leds_gpio_data = {
	.leds		= rb4xx_leds_gpio,
	.num_leds	= ARRAY_SIZE(rb4xx_leds_gpio),
};

static struct platform_device rb4xx_leds_gpio_device = {
	.name	= "leds-gpio",
	.id	= -1,
	.dev = {
		.platform_data = &rb4xx_leds_gpio_data,
	}
};

static struct platform_device rb4xx_nand_device = {
	.name	= "rb4xx-nand",
	.id	= -1,
};

static struct ar71xx_pci_irq rb4xx_pci_irqs[] __initdata = {
	{
		.slot	= 1,
		.pin	= 1,
		.irq	= AR71XX_PCI_IRQ_DEV0,
	}, {
		.slot	= 1,
		.pin	= 2,
		.irq	= AR71XX_PCI_IRQ_DEV1,
	}, {
		.slot	= 2,
		.pin	= 1,
		.irq	= AR71XX_PCI_IRQ_DEV1,
	}, {
		.slot	= 3,
		.pin	= 1,
		.irq	= AR71XX_PCI_IRQ_DEV2,
	}
};

#if 0
/*
 * SPI device support is experimental
 */
static struct flash_platform_data rb4xx_flash_data = {
	.type	= "pm25lv512",
};

static struct spi_board_info rb4xx_spi_info[] = {
	{
		.bus_num	= 0,
		.chip_select	= 0,
		.max_speed_hz	= 25000000,
		.modalias	= "m25p80",
		.platform_data	= &rb4xx_flash_data,
	}
};

static struct mmc_spi_platform_data rb433_mmc_data = {
	.ocr_mask	= MMC_VDD_32_33 | MMC_VDD_33_34,
};

static struct spi_board_info rb433_spi_info[] = {
	{
		.bus_num	= 0,
		.chip_select	= 0,
		.max_speed_hz	= 25000000,
		.modalias	= "m25p80",
		.platform_data	= &rb433_flash_data,
	}, {
		.bus_num	= 0,
		.chip_select	= 2,
		.max_speed_hz	= 25000000,
		.modalias	= "mmc_spi",
		.platform_data	= &rb433_mmc_data,
	}
};

static u32 rb433_spi_get_ioc_base(u8 chip_select, int cs_high, int is_on)
{
	u32 ret;

	if (is_on == AR71XX_SPI_CS_INACTIVE) {
		ret = SPI_IOC_CS0 | SPI_IOC_CS1;
	} else {
		if (cs_high) {
			ret = SPI_IOC_CS0 | SPI_IOC_CS1;
		} else {
			if ((chip_select ^ 2) == 0)
				ret = SPI_IOC_CS1 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
			else
				ret = SPI_IOC_CS0 ^ (SPI_IOC_CS0 | SPI_IOC_CS1);
		}
	}

	return ret;
}

struct ar71xx_spi_platform_data rb433_spi_data = {
	.bus_num		= 0,
	.num_chipselect		= 3,
	.get_ioc_base		= rb433_spi_get_ioc_base,
};

static void rb4xx_add_device_spi(void)
{
	ar71xx_add_device_spi(NULL, rb4xx_spi_info, ARRAY_SIZE(rb4xx_spi_info));
}

static void rb433_add_device_spi(void)
{
	ar71xx_add_device_spi(&rb433_spi_data, rb433_spi_info,
				ARRAY_SIZE(rb433_spi_info));
}
#else
static inline void rb4xx_add_device_spi(void) {}
static inline void rb433_add_device_spi(void) {}
#endif

static void __init rb411_setup(void)
{
	rb4xx_add_device_spi();

	ar71xx_add_device_eth(0, PHY_INTERFACE_MODE_MII, 0x00000001);

	platform_device_register(&rb4xx_leds_gpio_device);
	platform_device_register(&rb4xx_nand_device);

	ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
}

MIPS_MACHINE(MACH_AR71XX_RB_411, "MikroTik RouterBOARD 411/A/AH", rb411_setup);

static void __init rb433_setup(void)
{
	rb433_add_device_spi();

	ar71xx_add_device_eth(0, PHY_INTERFACE_MODE_MII, 0x00000001);
	ar71xx_add_device_eth(1, PHY_INTERFACE_MODE_RMII, 0xffffffff);

	platform_device_register(&rb4xx_leds_gpio_device);
	platform_device_register(&rb4xx_nand_device);

	ar71xx_pci_init(ARRAY_SIZE(rb4xx_pci_irqs), rb4xx_pci_irqs);
}

MIPS_MACHINE(MACH_AR71XX_RB_433, "MikroTik RouterBOARD 433/AH", rb433_setup);

static void __init rb450_setup(void)
{
	rb4xx_add_device_spi();

	ar71xx_add_device_eth(0, PHY_INTERFACE_MODE_MII, 0x00000001);
	ar71xx_add_device_eth(1, PHY_INTERFACE_MODE_RMII, 0xffffffff);

	platform_device_register(&rb4xx_leds_gpio_device);
	platform_device_register(&rb4xx_nand_device);
}

MIPS_MACHINE(MACH_AR71XX_RB_450, "MikroTik RouterBOARD 450", rb450_setup);