board-zoom-debugboard.c 3.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (C) 2009 Texas Instruments Inc.
 * Mikkel Christensen <mlc@ti.com>
 *
 * 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/kernel.h>
#include <linux/init.h>
#include <linux/gpio.h>
#include <linux/serial_8250.h>
#include <linux/smsc911x.h>
15
#include <linux/interrupt.h>
16

17
#include <plat/gpmc.h>
18

19 20 21 22
#define ZOOM_SMSC911X_CS	7
#define ZOOM_SMSC911X_GPIO	158
#define ZOOM_QUADUART_CS	3
#define ZOOM_QUADUART_GPIO	102
23 24
#define QUART_CLK		1843200
#define DEBUG_BASE		0x08000000
25
#define ZOOM_ETHR_START	DEBUG_BASE
26

27
static struct resource zoom_smsc911x_resources[] = {
28
	[0] = {
29 30
		.start	= ZOOM_ETHR_START,
		.end	= ZOOM_ETHR_START + SZ_4K,
31 32 33 34 35 36 37
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.flags	= IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
	},
};

38
static struct smsc911x_platform_config zoom_smsc911x_config = {
39 40 41 42 43 44
	.irq_polarity	= SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
	.irq_type	= SMSC911X_IRQ_TYPE_OPEN_DRAIN,
	.flags		= SMSC911X_USE_32BIT,
	.phy_interface	= PHY_INTERFACE_MODE_MII,
};

45
static struct platform_device zoom_smsc911x_device = {
46 47
	.name		= "smsc911x",
	.id		= -1,
48 49
	.num_resources	= ARRAY_SIZE(zoom_smsc911x_resources),
	.resource	= zoom_smsc911x_resources,
50
	.dev		= {
51
		.platform_data = &zoom_smsc911x_config,
52 53 54
	},
};

55
static inline void __init zoom_init_smsc911x(void)
56 57 58 59 60
{
	int eth_cs;
	unsigned long cs_mem_base;
	int eth_gpio = 0;

61
	eth_cs = ZOOM_SMSC911X_CS;
62 63 64 65 66 67

	if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
		printk(KERN_ERR "Failed to request GPMC mem for smsc911x\n");
		return;
	}

68 69
	zoom_smsc911x_resources[0].start = cs_mem_base + 0x0;
	zoom_smsc911x_resources[0].end   = cs_mem_base + 0xff;
70

71
	eth_gpio = ZOOM_SMSC911X_GPIO;
72

73
	zoom_smsc911x_resources[1].start = OMAP_GPIO_IRQ(eth_gpio);
74 75 76 77 78 79 80 81 82 83 84

	if (gpio_request(eth_gpio, "smsc911x irq") < 0) {
		printk(KERN_ERR "Failed to request GPIO%d for smsc911x IRQ\n",
				eth_gpio);
		return;
	}
	gpio_direction_input(eth_gpio);
}

static struct plat_serial8250_port serial_platform_data[] = {
	{
85
		.mapbase	= ZOOM_UART_BASE,
86 87
		.irq		= OMAP_GPIO_IRQ(102),
		.flags		= UPF_BOOT_AUTOCONF|UPF_IOREMAP|UPF_SHARE_IRQ,
88
		.irqflags	= IRQF_SHARED | IRQF_TRIGGER_RISING,
89 90 91 92 93 94 95 96
		.iotype		= UPIO_MEM,
		.regshift	= 1,
		.uartclk	= QUART_CLK,
	}, {
		.flags		= 0
	}
};

97
static struct platform_device zoom_debugboard_serial_device = {
98
	.name			= "serial8250",
99
	.id			= PLAT8250_DEV_PLATFORM,
100 101 102 103 104
	.dev			= {
		.platform_data	= serial_platform_data,
	},
};

105
static inline void __init zoom_init_quaduart(void)
106 107 108 109 110
{
	int quart_cs;
	unsigned long cs_mem_base;
	int quart_gpio = 0;

111
	quart_cs = ZOOM_QUADUART_CS;
112 113 114 115 116 117 118

	if (gpmc_cs_request(quart_cs, SZ_1M, &cs_mem_base) < 0) {
		printk(KERN_ERR "Failed to request GPMC mem"
				"for Quad UART(TL16CP754C)\n");
		return;
	}

119
	quart_gpio = ZOOM_QUADUART_GPIO;
120 121 122 123 124 125 126 127 128

	if (gpio_request(quart_gpio, "TL16CP754C GPIO") < 0) {
		printk(KERN_ERR "Failed to request GPIO%d for TL16CP754C\n",
								quart_gpio);
		return;
	}
	gpio_direction_input(quart_gpio);
}

129
static inline int omap_zoom_debugboard_detect(void)
130 131
{
	int debug_board_detect = 0;
132
	int ret = 1;
133

134
	debug_board_detect = ZOOM_SMSC911X_GPIO;
135

136 137
	if (gpio_request(debug_board_detect, "Zoom debug board detect") < 0) {
		printk(KERN_ERR "Failed to request GPIO%d for Zoom debug"
138 139 140 141 142 143
		"board detect\n", debug_board_detect);
		return 0;
	}
	gpio_direction_input(debug_board_detect);

	if (!gpio_get_value(debug_board_detect)) {
144
		ret = 0;
145
	}
146 147
	gpio_free(debug_board_detect);
	return ret;
148 149
}

150 151 152
static struct platform_device *zoom_devices[] __initdata = {
	&zoom_smsc911x_device,
	&zoom_debugboard_serial_device,
153 154
};

155
int __init zoom_debugboard_init(void)
156
{
157
	if (!omap_zoom_debugboard_detect())
158 159
		return 0;

160 161 162
	zoom_init_smsc911x();
	zoom_init_quaduart();
	return platform_add_devices(zoom_devices, ARRAY_SIZE(zoom_devices));
163
}