h3600.c 11.1 KB
Newer Older
L
Linus Torvalds 已提交
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
/*
 * Hardware definitions for Compaq iPAQ H3xxx Handheld Computers
 *
 * Copyright 2000,1 Compaq Computer Corporation.
 *
 * Use consistent with the GNU GPL is permitted,
 * provided that this copyright notice is
 * preserved in its entirety in all copies and derived works.
 *
 * COMPAQ COMPUTER CORPORATION MAKES NO WARRANTIES, EXPRESSED OR IMPLIED,
 * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS
 * FITNESS FOR ANY PARTICULAR PURPOSE.
 *
 * Author: Jamey Hicks.
 *
 * History:
 *
 * 2001-10-??	Andrew Christian   Added support for iPAQ H3800
 *				   and abstracted EGPIO interface.
 *
 */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/tty.h>
#include <linux/pm.h>
#include <linux/device.h>
28
#include <linux/mfd/htc-egpio.h>
L
Linus Torvalds 已提交
29 30 31
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/serial_core.h>
32
#include <linux/gpio.h>
33
#include <linux/platform_device.h>
L
Linus Torvalds 已提交
34 35

#include <asm/irq.h>
36
#include <mach/hardware.h>
L
Linus Torvalds 已提交
37 38 39 40 41 42 43 44 45 46
#include <asm/mach-types.h>
#include <asm/setup.h>

#include <asm/mach/irq.h>
#include <asm/mach/arch.h>
#include <asm/mach/flash.h>
#include <asm/mach/irda.h>
#include <asm/mach/map.h>
#include <asm/mach/serial_sa1100.h>

47 48
#include <mach/h3600.h>
#include <mach/h3600_gpio.h>
L
Linus Torvalds 已提交
49 50 51

#include "generic.h"

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
struct gpio_default_state {
	int gpio;
	int mode;
	const char *name;
};

#define GPIO_MODE_IN	-1
#define GPIO_MODE_OUT0	0
#define GPIO_MODE_OUT1	1

static void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
{
	while (n--) {
		const char *name = s->name;
		int err;

		if (!name)
			name = "[init]";
		err = gpio_request(s->gpio, name);
		if (err) {
			printk(KERN_ERR "gpio%u: unable to request: %d\n",
				s->gpio, err);
			continue;
		}
		if (s->mode >= 0) {
			err = gpio_direction_output(s->gpio, s->mode);
		} else {
			err = gpio_direction_input(s->gpio);
		}
		if (err) {
			printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
				s->gpio, err);
			continue;
		}
		if (!s->name)
			gpio_free(s->gpio);
		s++;
	}
}


93 94 95
/*
 * H3xxx flash support
 */
L
Linus Torvalds 已提交
96 97 98 99 100 101 102
static struct mtd_partition h3xxx_partitions[] = {
	{
		.name		= "H3XXX boot firmware",
		.size		= 0x00040000,
		.offset		= 0,
		.mask_flags	= MTD_WRITEABLE,  /* force read-only */
	}, {
103
		.name		= "H3XXX rootfs",
L
Linus Torvalds 已提交
104 105 106 107 108 109 110
		.size		= MTDPART_SIZ_FULL,
		.offset		= 0x00040000,
	}
};

static void h3xxx_set_vpp(int vpp)
{
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
	gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
}

static int h3xxx_flash_init(void)
{
	int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
	if (err)
		return err;

	err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
	if (err)
		gpio_free(H3XXX_EGPIO_VPP_ON);

	return err;
}

static void h3xxx_flash_exit(void)
{
	gpio_free(H3XXX_EGPIO_VPP_ON);
L
Linus Torvalds 已提交
130 131 132 133 134
}

static struct flash_platform_data h3xxx_flash_data = {
	.map_name	= "cfi_probe",
	.set_vpp	= h3xxx_set_vpp,
135 136
	.init		= h3xxx_flash_init,
	.exit		= h3xxx_flash_exit,
L
Linus Torvalds 已提交
137 138 139 140 141 142 143 144 145 146 147 148
	.parts		= h3xxx_partitions,
	.nr_parts	= ARRAY_SIZE(h3xxx_partitions),
};

static struct resource h3xxx_flash_resource = {
	.start		= SA1100_CS0_PHYS,
	.end		= SA1100_CS0_PHYS + SZ_32M - 1,
	.flags		= IORESOURCE_MEM,
};


/*
149
 * H3xxx uart support
L
Linus Torvalds 已提交
150
 */
151
static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
L
Linus Torvalds 已提交
152 153
{
	if (port->mapbase == _Ser3UTCR0) {
154
		gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
L
Linus Torvalds 已提交
155 156 157
	}
}

158
static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
L
Linus Torvalds 已提交
159 160 161 162
{
	u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;

	if (port->mapbase == _Ser3UTCR0) {
163 164 165 166
		/*
		 * DCD and CTS bits are inverted in GPLR by RS232 transceiver
		 */
		if (gpio_get_value(H3XXX_GPIO_COM_DCD))
L
Linus Torvalds 已提交
167
			ret &= ~TIOCM_CD;
168
		if (gpio_get_value(H3XXX_GPIO_COM_CTS))
L
Linus Torvalds 已提交
169 170 171 172 173 174
			ret &= ~TIOCM_CTS;
	}

	return ret;
}

175
static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
L
Linus Torvalds 已提交
176
{
177
	if (port->mapbase == _Ser3UTCR0)
178 179 180 181
		if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
			gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
			gpio_free(H3XXX_EGPIO_RS232_ON);
		}
L
Linus Torvalds 已提交
182 183 184 185 186 187
}

/*
 * Enable/Disable wake up events for this serial port.
 * Obviously, we only support this on the normal COM port.
 */
188
static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
L
Linus Torvalds 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201
{
	int err = -EINVAL;

	if (port->mapbase == _Ser3UTCR0) {
		if (enable)
			PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
		else
			PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
		err = 0;
	}
	return err;
}

202 203 204 205 206
static struct sa1100_port_fns h3xxx_port_fns __initdata = {
	.set_mctrl	= h3xxx_uart_set_mctrl,
	.get_mctrl	= h3xxx_uart_get_mctrl,
	.pm		= h3xxx_uart_pm,
	.set_wake	= h3xxx_uart_set_wake,
L
Linus Torvalds 已提交
207 208
};

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
/*
 * EGPIO
 */

static struct resource egpio_resources[] = {
	[0] = {
		.start	= H3600_EGPIO_PHYS,
		.end	= H3600_EGPIO_PHYS + 0x4 - 1,
		.flags	= IORESOURCE_MEM,
	},
};

static struct htc_egpio_chip egpio_chips[] = {
	[0] = {
		.reg_start	= 0,
		.gpio_base	= H3XXX_EGPIO_BASE,
		.num_gpios	= 16,
		.direction	= HTC_EGPIO_OUTPUT,
		.initial_values	= 0x0080, /* H3XXX_EGPIO_RS232_ON */
	},
};

static struct htc_egpio_platform_data egpio_info = {
	.reg_width	= 16,
	.bus_width	= 16,
	.chip		= egpio_chips,
	.num_chips	= ARRAY_SIZE(egpio_chips),
};

static struct platform_device h3xxx_egpio = {
	.name		= "htc-egpio",
	.id		= -1,
	.resource	= egpio_resources,
	.num_resources	= ARRAY_SIZE(egpio_resources),
	.dev		= {
		.platform_data = &egpio_info,
	},
};

static struct platform_device *h3xxx_devices[] = {
	&h3xxx_egpio,
};
251

252
static void __init h3xxx_mach_init(void)
253 254 255
{
	sa1100_register_uart_fns(&h3xxx_port_fns);
	sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
256
	platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
257 258
}

L
Linus Torvalds 已提交
259
static struct map_desc h3600_io_desc[] __initdata = {
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
  	{	/* static memory bank 2  CS#2 */
		.virtual	=  H3600_BANK_2_VIRT,
		.pfn		= __phys_to_pfn(SA1100_CS2_PHYS),
		.length		= 0x02800000,
		.type		= MT_DEVICE
	}, {	/* static memory bank 4  CS#4 */
		.virtual	=  H3600_BANK_4_VIRT,
		.pfn		= __phys_to_pfn(SA1100_CS4_PHYS),
		.length		= 0x00800000,
		.type		= MT_DEVICE
	}, {	/* EGPIO 0		CS#5 */
		.virtual	=  H3600_EGPIO_VIRT,
		.pfn		= __phys_to_pfn(H3600_EGPIO_PHYS),
		.length		= 0x01000000,
		.type		= MT_DEVICE
	}
L
Linus Torvalds 已提交
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
};

/*
 * Common map_io initialization
 */

static void __init h3xxx_map_io(void)
{
	sa1100_map_io();
	iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));

	sa1100_register_uart(0, 3); /* Common serial port */
//	sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */

	/* Ensure those pins are outputs and driving low  */
	PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
	PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);

	/* Configure suspend conditions */
	PGSR = 0;
R
Russell King 已提交
296
	PWER = PWER_GPIO0;
L
Linus Torvalds 已提交
297 298 299
	PCFR = PCFR_OPDE;
	PSDR = 0;

300 301
	GPCR = 0x0fffffff;	/* All outputs are set low by default */
	GPDR = 0;		/* Configure all GPIOs as input */
L
Linus Torvalds 已提交
302 303 304 305 306 307
}

/************************* H3100 *************************/

#ifdef CONFIG_SA1100_H3100

308 309 310 311 312
/*
 * helper for sa1100fb
 */
static void h3100_lcd_power(int enable)
{
313 314 315 316 317
	if (!gpio_request(H3XXX_EGPIO_LCD_ON, "LCD ON")) {
		gpio_set_value(H3100_GPIO_LCD_3V_ON, enable);
		gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
		gpio_free(H3XXX_EGPIO_LCD_ON);
	}
318 319
}

L
Linus Torvalds 已提交
320 321 322 323 324

static void __init h3100_map_io(void)
{
	h3xxx_map_io();

325 326
	sa1100fb_lcd_power = h3100_lcd_power;

L
Linus Torvalds 已提交
327 328
	/* Older bootldrs put GPIO2-9 in alternate mode on the
	   assumption that they are used for video */
329
	GAFR &= ~0x000001fb;
L
Linus Torvalds 已提交
330 331
}

332 333 334 335 336
/*
 * This turns the IRDA power on or off on the Compaq H3100
 */
static int h3100_irda_set_power(struct device *dev, unsigned int state)
{
337
	gpio_set_value(H3100_GPIO_IR_ON, state);
338 339 340 341 342
	return 0;
}

static void h3100_irda_set_speed(struct device *dev, unsigned int speed)
{
343
	gpio_set_value(H3100_GPIO_IR_FSEL, !(speed < 4000000));
344 345 346 347 348 349 350
}

static struct irda_platform_data h3100_irda_data = {
	.set_power	= h3100_irda_set_power,
	.set_speed	= h3100_irda_set_speed,
};

351 352 353
static struct gpio_default_state h3100_default_gpio[] = {
	{ H3100_GPIO_IR_ON,	GPIO_MODE_OUT0, "IrDA power" },
	{ H3100_GPIO_IR_FSEL,	GPIO_MODE_OUT0, "IrDA fsel" },
354 355 356
	{ H3XXX_GPIO_COM_DCD,	GPIO_MODE_IN,	"COM DCD" },
	{ H3XXX_GPIO_COM_CTS,	GPIO_MODE_IN,	"COM CTS" },
	{ H3XXX_GPIO_COM_RTS,	GPIO_MODE_OUT0,	"COM RTS" },
357
	{ H3100_GPIO_LCD_3V_ON,	GPIO_MODE_OUT0,	"LCD 3v" },
358 359
};

360
static void __init h3100_mach_init(void)
361
{
362
	h3xxx_init_gpio(h3100_default_gpio, ARRAY_SIZE(h3100_default_gpio));
363
	h3xxx_mach_init();
364
	sa11x0_register_irda(&h3100_irda_data);
365 366
}

L
Linus Torvalds 已提交
367
MACHINE_START(H3100, "Compaq iPAQ H3100")
368 369 370 371 372
	.phys_io	= 0x80000000,
	.io_pg_offst	= ((0xf8000000) >> 18) & 0xfffc,
	.boot_params	= 0xc0000100,
	.map_io		= h3100_map_io,
	.init_irq	= sa1100_init_irq,
L
Linus Torvalds 已提交
373
	.timer		= &sa1100_timer,
374
	.init_machine	= h3100_mach_init,
L
Linus Torvalds 已提交
375 376 377 378 379 380 381 382
MACHINE_END

#endif /* CONFIG_SA1100_H3100 */

/************************* H3600 *************************/

#ifdef CONFIG_SA1100_H3600

383 384 385 386 387
/*
 * helper for sa1100fb
 */
static void h3600_lcd_power(int enable)
{
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
	if (gpio_request(H3XXX_EGPIO_LCD_ON, "LCD power"))
		goto err1;
	if (gpio_request(H3600_EGPIO_LCD_PCI, "LCD control"))
		goto err2;
	if (gpio_request(H3600_EGPIO_LCD_5V_ON, "LCD 5v"))
		goto err3;
	if (gpio_request(H3600_EGPIO_LVDD_ON, "LCD 9v/-6.5v"))
		goto err4;

	gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
	gpio_direction_output(H3600_EGPIO_LCD_PCI, enable);
	gpio_direction_output(H3600_EGPIO_LCD_5V_ON, enable);
	gpio_direction_output(H3600_EGPIO_LVDD_ON, enable);

	gpio_free(H3600_EGPIO_LVDD_ON);
err4:	gpio_free(H3600_EGPIO_LCD_5V_ON);
err3:	gpio_free(H3600_EGPIO_LCD_PCI);
err2:	gpio_free(H3XXX_EGPIO_LCD_ON);
err1:	return;
407 408
}

L
Linus Torvalds 已提交
409 410 411 412
static void __init h3600_map_io(void)
{
	h3xxx_map_io();

413
	sa1100fb_lcd_power = h3600_lcd_power;
L
Linus Torvalds 已提交
414 415
}

416 417 418 419 420
/*
 * This turns the IRDA power on or off on the Compaq H3600
 */
static int h3600_irda_set_power(struct device *dev, unsigned int state)
{
421
	gpio_set_value(H3600_EGPIO_IR_ON, state);
422 423 424 425 426
	return 0;
}

static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
{
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
	gpio_set_value(H3600_EGPIO_IR_FSEL, !(speed < 4000000));
}

static int h3600_irda_startup(struct device *dev)
{
	int err = gpio_request(H3600_EGPIO_IR_ON, "IrDA power");
	if (err)
		goto err1;
	err = gpio_direction_output(H3600_EGPIO_IR_ON, 0);
	if (err)
		goto err2;
	err = gpio_request(H3600_EGPIO_IR_FSEL, "IrDA fsel");
	if (err)
		goto err2;
	err = gpio_direction_output(H3600_EGPIO_IR_FSEL, 0);
	if (err)
		goto err3;
	return 0;

err3:	gpio_free(H3600_EGPIO_IR_FSEL);
err2:	gpio_free(H3600_EGPIO_IR_ON);
err1:	return err;
}

static void h3600_irda_shutdown(struct device *dev)
{
	gpio_free(H3600_EGPIO_IR_ON);
	gpio_free(H3600_EGPIO_IR_FSEL);
455 456 457 458 459
}

static struct irda_platform_data h3600_irda_data = {
	.set_power	= h3600_irda_set_power,
	.set_speed	= h3600_irda_set_speed,
460 461
	.startup	= h3600_irda_startup,
	.shutdown	= h3600_irda_shutdown,
462 463
};

464 465 466 467 468 469
static struct gpio_default_state h3600_default_gpio[] = {
	{ H3XXX_GPIO_COM_DCD,	GPIO_MODE_IN,	"COM DCD" },
	{ H3XXX_GPIO_COM_CTS,	GPIO_MODE_IN,	"COM CTS" },
	{ H3XXX_GPIO_COM_RTS,	GPIO_MODE_OUT0,	"COM RTS" },
};

470
static void __init h3600_mach_init(void)
471
{
472
	h3xxx_init_gpio(h3600_default_gpio, ARRAY_SIZE(h3600_default_gpio));
473
	h3xxx_mach_init();
474
	sa11x0_register_irda(&h3600_irda_data);
475 476
}

L
Linus Torvalds 已提交
477
MACHINE_START(H3600, "Compaq iPAQ H3600")
478 479 480 481 482
	.phys_io	= 0x80000000,
	.io_pg_offst	= ((0xf8000000) >> 18) & 0xfffc,
	.boot_params	= 0xc0000100,
	.map_io		= h3600_map_io,
	.init_irq	= sa1100_init_irq,
L
Linus Torvalds 已提交
483
	.timer		= &sa1100_timer,
484
	.init_machine	= h3600_mach_init,
L
Linus Torvalds 已提交
485 486 487 488
MACHINE_END

#endif /* CONFIG_SA1100_H3600 */