common.c 9.2 KB
Newer Older
1 2 3
/*
 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
B
Ben Dooks 已提交
4 5 6
 *
 * Copyright 2008 Openmoko, Inc.
 * Copyright 2008 Simtec Electronics
7 8
 *	Ben Dooks <ben@simtec.co.uk>
 *	http://armlinux.simtec.co.uk/
B
Ben Dooks 已提交
9
 *
10
 * Common Codes for S3C64XX machines
B
Ben Dooks 已提交
11 12 13 14 15 16 17
 *
 * 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>
18 19
#include <linux/init.h>
#include <linux/module.h>
B
Ben Dooks 已提交
20
#include <linux/interrupt.h>
21 22 23
#include <linux/ioport.h>
#include <linux/serial_core.h>
#include <linux/platform_device.h>
B
Ben Dooks 已提交
24
#include <linux/io.h>
25 26 27
#include <linux/dma-mapping.h>
#include <linux/irq.h>
#include <linux/gpio.h>
B
Ben Dooks 已提交
28

29 30
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
B
Ben Dooks 已提交
31
#include <asm/hardware/vic.h>
32
#include <asm/system_misc.h>
B
Ben Dooks 已提交
33

34 35
#include <mach/map.h>
#include <mach/hardware.h>
36
#include <mach/regs-gpio.h>
B
Ben Dooks 已提交
37 38

#include <plat/cpu.h>
39 40
#include <plat/clock.h>
#include <plat/devs.h>
41
#include <plat/pm.h>
42 43 44 45 46
#include <plat/gpio-cfg.h>
#include <plat/irq-uart.h>
#include <plat/irq-vic-timer.h>
#include <plat/regs-irqtype.h>
#include <plat/regs-serial.h>
47
#include <plat/watchdog-reset.h>
48 49 50 51 52

#include "common.h"

/* uart registration process */

53
static void __init s3c64xx_init_uarts(struct s3c2410_uartcfg *cfg, int no)
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
{
	s3c24xx_init_uartdevs("s3c6400-uart", s3c64xx_uart_resources, cfg, no);
}

/* table of supported CPUs */

static const char name_s3c6400[] = "S3C6400";
static const char name_s3c6410[] = "S3C6410";

static struct cpu_table cpu_ids[] __initdata = {
	{
		.idcode		= S3C6400_CPU_ID,
		.idmask		= S3C64XX_CPU_MASK,
		.map_io		= s3c6400_map_io,
		.init_clocks	= s3c6400_init_clocks,
		.init_uarts	= s3c64xx_init_uarts,
		.init		= s3c6400_init,
		.name		= name_s3c6400,
	}, {
		.idcode		= S3C6410_CPU_ID,
		.idmask		= S3C64XX_CPU_MASK,
		.map_io		= s3c6410_map_io,
		.init_clocks	= s3c6410_init_clocks,
		.init_uarts	= s3c64xx_init_uarts,
		.init		= s3c6410_init,
		.name		= name_s3c6410,
	},
};

/* minimal IO mapping */

/* see notes on uart map in arch/arm/mach-s3c64xx/include/mach/debug-macro.S */
#define UART_OFFS (S3C_PA_UART & 0xfffff)

static struct map_desc s3c_iodesc[] __initdata = {
	{
		.virtual	= (unsigned long)S3C_VA_SYS,
		.pfn		= __phys_to_pfn(S3C64XX_PA_SYSCON),
		.length		= SZ_4K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)S3C_VA_MEM,
		.pfn		= __phys_to_pfn(S3C64XX_PA_SROM),
		.length		= SZ_4K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)(S3C_VA_UART + UART_OFFS),
		.pfn		= __phys_to_pfn(S3C_PA_UART),
		.length		= SZ_4K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)VA_VIC0,
		.pfn		= __phys_to_pfn(S3C64XX_PA_VIC0),
		.length		= SZ_16K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)VA_VIC1,
		.pfn		= __phys_to_pfn(S3C64XX_PA_VIC1),
		.length		= SZ_16K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)S3C_VA_TIMER,
		.pfn		= __phys_to_pfn(S3C_PA_TIMER),
		.length		= SZ_16K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)S3C64XX_VA_GPIO,
		.pfn		= __phys_to_pfn(S3C64XX_PA_GPIO),
		.length		= SZ_4K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)S3C64XX_VA_MODEM,
		.pfn		= __phys_to_pfn(S3C64XX_PA_MODEM),
		.length		= SZ_4K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)S3C_VA_WATCHDOG,
		.pfn		= __phys_to_pfn(S3C64XX_PA_WATCHDOG),
		.length		= SZ_4K,
		.type		= MT_DEVICE,
	}, {
		.virtual	= (unsigned long)S3C_VA_USB_HSPHY,
		.pfn		= __phys_to_pfn(S3C64XX_PA_USB_HSPHY),
		.length		= SZ_1K,
		.type		= MT_DEVICE,
	},
};

142 143 144
static struct bus_type s3c64xx_subsys = {
	.name		= "s3c64xx-core",
	.dev_name	= "s3c64xx-core",
145 146
};

147 148
static struct device s3c64xx_dev = {
	.bus	= &s3c64xx_subsys,
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
};

/* read cpu identification code */

void __init s3c64xx_init_io(struct map_desc *mach_desc, int size)
{
	/* initialise the io descriptors we need for initialisation */
	iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc));
	iotable_init(mach_desc, size);
	init_consistent_dma_size(SZ_8M);

	/* detect cpu id */
	s3c64xx_init_cpu();

	s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
}

166
static __init int s3c64xx_dev_init(void)
167
{
168 169
	subsys_system_register(&s3c64xx_subsys, NULL);
	return device_register(&s3c64xx_dev);
170
}
171
core_initcall(s3c64xx_dev_init);
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195

/*
 * setup the sources the vic should advertise resume
 * for, even though it is not doing the wake
 * (set_irq_wake needs to be valid)
 */
#define IRQ_VIC0_RESUME (1 << (IRQ_RTC_TIC - IRQ_VIC0_BASE))
#define IRQ_VIC1_RESUME (1 << (IRQ_RTC_ALARM - IRQ_VIC1_BASE) |	\
			 1 << (IRQ_PENDN - IRQ_VIC1_BASE) |	\
			 1 << (IRQ_HSMMC0 - IRQ_VIC1_BASE) |	\
			 1 << (IRQ_HSMMC1 - IRQ_VIC1_BASE) |	\
			 1 << (IRQ_HSMMC2 - IRQ_VIC1_BASE))

void __init s3c64xx_init_irq(u32 vic0_valid, u32 vic1_valid)
{
	printk(KERN_DEBUG "%s: initialising interrupts\n", __func__);

	/* initialise the pair of VICs */
	vic_init(VA_VIC0, IRQ_VIC0_BASE, vic0_valid, IRQ_VIC0_RESUME);
	vic_init(VA_VIC1, IRQ_VIC1_BASE, vic1_valid, IRQ_VIC1_RESUME);

	/* add the timer sub-irqs */
	s3c_init_vic_timer_irq(5, IRQ_TIMER0);
}
B
Ben Dooks 已提交
196 197

#define eint_offset(irq)	((irq) - IRQ_EINT(0))
198
#define eint_irq_to_bit(irq)	((u32)(1 << eint_offset(irq)))
B
Ben Dooks 已提交
199

200
static inline void s3c_irq_eint_mask(struct irq_data *data)
B
Ben Dooks 已提交
201 202 203 204
{
	u32 mask;

	mask = __raw_readl(S3C64XX_EINT0MASK);
205
	mask |= (u32)data->chip_data;
B
Ben Dooks 已提交
206 207 208
	__raw_writel(mask, S3C64XX_EINT0MASK);
}

209
static void s3c_irq_eint_unmask(struct irq_data *data)
B
Ben Dooks 已提交
210 211 212 213
{
	u32 mask;

	mask = __raw_readl(S3C64XX_EINT0MASK);
214
	mask &= ~((u32)data->chip_data);
B
Ben Dooks 已提交
215 216 217
	__raw_writel(mask, S3C64XX_EINT0MASK);
}

218
static inline void s3c_irq_eint_ack(struct irq_data *data)
B
Ben Dooks 已提交
219
{
220
	__raw_writel((u32)data->chip_data, S3C64XX_EINT0PEND);
B
Ben Dooks 已提交
221 222
}

223
static void s3c_irq_eint_maskack(struct irq_data *data)
B
Ben Dooks 已提交
224 225
{
	/* compiler should in-line these */
226 227
	s3c_irq_eint_mask(data);
	s3c_irq_eint_ack(data);
B
Ben Dooks 已提交
228 229
}

230
static int s3c_irq_eint_set_type(struct irq_data *data, unsigned int type)
B
Ben Dooks 已提交
231
{
232
	int offs = eint_offset(data->irq);
233
	int pin, pin_val;
B
Ben Dooks 已提交
234 235 236 237 238 239 240 241
	int shift;
	u32 ctrl, mask;
	u32 newvalue = 0;
	void __iomem *reg;

	if (offs > 27)
		return -EINVAL;

242
	if (offs <= 15)
B
Ben Dooks 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
		reg = S3C64XX_EINT0CON0;
	else
		reg = S3C64XX_EINT0CON1;

	switch (type) {
	case IRQ_TYPE_NONE:
		printk(KERN_WARNING "No edge setting!\n");
		break;

	case IRQ_TYPE_EDGE_RISING:
		newvalue = S3C2410_EXTINT_RISEEDGE;
		break;

	case IRQ_TYPE_EDGE_FALLING:
		newvalue = S3C2410_EXTINT_FALLEDGE;
		break;

	case IRQ_TYPE_EDGE_BOTH:
		newvalue = S3C2410_EXTINT_BOTHEDGE;
		break;

	case IRQ_TYPE_LEVEL_LOW:
		newvalue = S3C2410_EXTINT_LOWLEV;
		break;

	case IRQ_TYPE_LEVEL_HIGH:
		newvalue = S3C2410_EXTINT_HILEV;
		break;

	default:
		printk(KERN_ERR "No such irq type %d", type);
		return -1;
	}

277 278 279 280
	if (offs <= 15)
		shift = (offs / 2) * 4;
	else
		shift = ((offs - 16) / 2) * 4;
B
Ben Dooks 已提交
281 282 283 284 285 286 287
	mask = 0x7 << shift;

	ctrl = __raw_readl(reg);
	ctrl &= ~mask;
	ctrl |= newvalue << shift;
	__raw_writel(ctrl, reg);

288 289
	/* set the GPIO pin appropriately */

290
	if (offs < 16) {
291
		pin = S3C64XX_GPN(offs);
292 293 294 295 296
		pin_val = S3C_GPIO_SFN(2);
	} else if (offs < 23) {
		pin = S3C64XX_GPL(offs + 8 - 16);
		pin_val = S3C_GPIO_SFN(3);
	} else {
297
		pin = S3C64XX_GPM(offs - 23);
298 299
		pin_val = S3C_GPIO_SFN(3);
	}
300

301
	s3c_gpio_cfgpin(pin, pin_val);
302

B
Ben Dooks 已提交
303 304 305 306 307
	return 0;
}

static struct irq_chip s3c_irq_eint = {
	.name		= "s3c-eint",
308 309 310 311 312
	.irq_mask	= s3c_irq_eint_mask,
	.irq_unmask	= s3c_irq_eint_unmask,
	.irq_mask_ack	= s3c_irq_eint_maskack,
	.irq_ack	= s3c_irq_eint_ack,
	.irq_set_type	= s3c_irq_eint_set_type,
313
	.irq_set_wake	= s3c_irqext_wake,
B
Ben Dooks 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
};

/* s3c_irq_demux_eint
 *
 * This function demuxes the IRQ from the group0 external interrupts,
 * from IRQ_EINT(0) to IRQ_EINT(27). It is designed to be inlined into
 * the specific handlers s3c_irq_demux_eintX_Y.
 */
static inline void s3c_irq_demux_eint(unsigned int start, unsigned int end)
{
	u32 status = __raw_readl(S3C64XX_EINT0PEND);
	u32 mask = __raw_readl(S3C64XX_EINT0MASK);
	unsigned int irq;

	status &= ~mask;
	status >>= start;
	status &= (1 << (end - start + 1)) - 1;

	for (irq = IRQ_EINT(start); irq <= IRQ_EINT(end); irq++) {
		if (status & 1)
			generic_handle_irq(irq);

		status >>= 1;
	}
}

static void s3c_irq_demux_eint0_3(unsigned int irq, struct irq_desc *desc)
{
	s3c_irq_demux_eint(0, 3);
}

static void s3c_irq_demux_eint4_11(unsigned int irq, struct irq_desc *desc)
{
	s3c_irq_demux_eint(4, 11);
}

static void s3c_irq_demux_eint12_19(unsigned int irq, struct irq_desc *desc)
{
	s3c_irq_demux_eint(12, 19);
}

static void s3c_irq_demux_eint20_27(unsigned int irq, struct irq_desc *desc)
{
	s3c_irq_demux_eint(20, 27);
}

360
static int __init s3c64xx_init_irq_eint(void)
B
Ben Dooks 已提交
361 362 363 364
{
	int irq;

	for (irq = IRQ_EINT(0); irq <= IRQ_EINT(27); irq++) {
365
		irq_set_chip_and_handler(irq, &s3c_irq_eint, handle_level_irq);
366
		irq_set_chip_data(irq, (void *)eint_irq_to_bit(irq));
B
Ben Dooks 已提交
367 368 369
		set_irq_flags(irq, IRQF_VALID);
	}

T
Thomas Gleixner 已提交
370 371 372 373
	irq_set_chained_handler(IRQ_EINT0_3, s3c_irq_demux_eint0_3);
	irq_set_chained_handler(IRQ_EINT4_11, s3c_irq_demux_eint4_11);
	irq_set_chained_handler(IRQ_EINT12_19, s3c_irq_demux_eint12_19);
	irq_set_chained_handler(IRQ_EINT20_27, s3c_irq_demux_eint20_27);
B
Ben Dooks 已提交
374 375 376 377

	return 0;
}
arch_initcall(s3c64xx_init_irq_eint);
378 379 380 381 382 383 384 385 386

void s3c64xx_restart(char mode, const char *cmd)
{
	if (mode != 's')
		arch_wdt_reset();

	/* if all else fails, or mode was for soft, jump to 0 */
	soft_restart(0);
}
387 388 389 390 391

void __init s3c64xx_init_late(void)
{
	s3c64xx_pm_late_initcall();
}