0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/kernel.h>
0010 #include <linux/gpio/machine.h>
0011 #include <linux/gpio.h>
0012 #include <linux/gpio_keys.h>
0013 #include <linux/input.h>
0014 #include <linux/mtd/mtd.h>
0015 #include <linux/mtd/partitions.h>
0016 #include <linux/platform_data/gpio-htc-egpio.h>
0017 #include <linux/platform_data/sa11x0-serial.h>
0018 #include <linux/platform_device.h>
0019 #include <linux/serial_core.h>
0020
0021 #include <asm/mach/flash.h>
0022 #include <asm/mach/map.h>
0023
0024 #include <mach/h3xxx.h>
0025 #include <mach/irqs.h>
0026
0027 #include "generic.h"
0028
0029
0030
0031
0032 static struct mtd_partition h3xxx_partitions[] = {
0033 {
0034 .name = "H3XXX boot firmware",
0035 .size = 0x00040000,
0036 .offset = 0,
0037 .mask_flags = MTD_WRITEABLE,
0038 }, {
0039 .name = "H3XXX rootfs",
0040 .size = MTDPART_SIZ_FULL,
0041 .offset = 0x00040000,
0042 }
0043 };
0044
0045 static void h3xxx_set_vpp(int vpp)
0046 {
0047 gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
0048 }
0049
0050 static int h3xxx_flash_init(void)
0051 {
0052 int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
0053 if (err) {
0054 pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__);
0055 return err;
0056 }
0057
0058 err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
0059 if (err)
0060 gpio_free(H3XXX_EGPIO_VPP_ON);
0061
0062 return err;
0063 }
0064
0065 static void h3xxx_flash_exit(void)
0066 {
0067 gpio_free(H3XXX_EGPIO_VPP_ON);
0068 }
0069
0070 static struct flash_platform_data h3xxx_flash_data = {
0071 .map_name = "cfi_probe",
0072 .set_vpp = h3xxx_set_vpp,
0073 .init = h3xxx_flash_init,
0074 .exit = h3xxx_flash_exit,
0075 .parts = h3xxx_partitions,
0076 .nr_parts = ARRAY_SIZE(h3xxx_partitions),
0077 };
0078
0079 static struct resource h3xxx_flash_resource =
0080 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M);
0081
0082
0083
0084
0085
0086 static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
0087 {
0088 if (port->mapbase == _Ser3UTCR0) {
0089 if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
0090 gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
0091 gpio_free(H3XXX_EGPIO_RS232_ON);
0092 } else {
0093 pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
0094 __func__);
0095 }
0096 }
0097 }
0098
0099
0100
0101
0102
0103 static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
0104 {
0105 int err = -EINVAL;
0106
0107 if (port->mapbase == _Ser3UTCR0) {
0108 if (enable)
0109 PWER |= PWER_GPIO23 | PWER_GPIO25;
0110 else
0111 PWER &= ~(PWER_GPIO23 | PWER_GPIO25);
0112 err = 0;
0113 }
0114 return err;
0115 }
0116
0117 static struct sa1100_port_fns h3xxx_port_fns __initdata = {
0118 .pm = h3xxx_uart_pm,
0119 .set_wake = h3xxx_uart_set_wake,
0120 };
0121
0122 static struct gpiod_lookup_table h3xxx_uart3_gpio_table = {
0123 .dev_id = "sa11x0-uart.3",
0124 .table = {
0125 GPIO_LOOKUP("gpio", H3XXX_GPIO_COM_DCD, "dcd", GPIO_ACTIVE_LOW),
0126 GPIO_LOOKUP("gpio", H3XXX_GPIO_COM_CTS, "cts", GPIO_ACTIVE_LOW),
0127 GPIO_LOOKUP("gpio", H3XXX_GPIO_COM_RTS, "rts", GPIO_ACTIVE_LOW),
0128 { },
0129 },
0130 };
0131
0132
0133
0134
0135
0136 static struct resource egpio_resources[] = {
0137 [0] = DEFINE_RES_MEM(H3600_EGPIO_PHYS, 0x4),
0138 };
0139
0140 static struct htc_egpio_chip egpio_chips[] = {
0141 [0] = {
0142 .reg_start = 0,
0143 .gpio_base = H3XXX_EGPIO_BASE,
0144 .num_gpios = 16,
0145 .direction = HTC_EGPIO_OUTPUT,
0146 .initial_values = 0x0080,
0147 },
0148 };
0149
0150 static struct htc_egpio_platform_data egpio_info = {
0151 .reg_width = 16,
0152 .bus_width = 16,
0153 .chip = egpio_chips,
0154 .num_chips = ARRAY_SIZE(egpio_chips),
0155 };
0156
0157 static struct platform_device h3xxx_egpio = {
0158 .name = "htc-egpio",
0159 .id = -1,
0160 .resource = egpio_resources,
0161 .num_resources = ARRAY_SIZE(egpio_resources),
0162 .dev = {
0163 .platform_data = &egpio_info,
0164 },
0165 };
0166
0167
0168
0169
0170
0171 static struct gpio_keys_button h3xxx_button_table[] = {
0172 {
0173 .code = KEY_POWER,
0174 .gpio = H3XXX_GPIO_PWR_BUTTON,
0175 .desc = "Power Button",
0176 .active_low = 1,
0177 .type = EV_KEY,
0178 .wakeup = 1,
0179 }, {
0180 .code = KEY_ENTER,
0181 .gpio = H3XXX_GPIO_ACTION_BUTTON,
0182 .active_low = 1,
0183 .desc = "Action button",
0184 .type = EV_KEY,
0185 .wakeup = 0,
0186 },
0187 };
0188
0189 static struct gpio_keys_platform_data h3xxx_keys_data = {
0190 .buttons = h3xxx_button_table,
0191 .nbuttons = ARRAY_SIZE(h3xxx_button_table),
0192 };
0193
0194 static struct platform_device h3xxx_keys = {
0195 .name = "gpio-keys",
0196 .id = -1,
0197 .dev = {
0198 .platform_data = &h3xxx_keys_data,
0199 },
0200 };
0201
0202 static struct resource h3xxx_micro_resources[] = {
0203 DEFINE_RES_MEM(0x80010000, SZ_4K),
0204 DEFINE_RES_MEM(0x80020000, SZ_4K),
0205 DEFINE_RES_IRQ(IRQ_Ser1UART),
0206 };
0207
0208 struct platform_device h3xxx_micro_asic = {
0209 .name = "ipaq-h3xxx-micro",
0210 .id = -1,
0211 .resource = h3xxx_micro_resources,
0212 .num_resources = ARRAY_SIZE(h3xxx_micro_resources),
0213 };
0214
0215 static struct platform_device *h3xxx_devices[] = {
0216 &h3xxx_egpio,
0217 &h3xxx_keys,
0218 &h3xxx_micro_asic,
0219 };
0220
0221 static struct gpiod_lookup_table h3xxx_pcmcia_gpio_table = {
0222 .dev_id = "sa11x0-pcmcia",
0223 .table = {
0224 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD0,
0225 "pcmcia0-detect", GPIO_ACTIVE_LOW),
0226 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ0,
0227 "pcmcia0-ready", GPIO_ACTIVE_HIGH),
0228 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD1,
0229 "pcmcia1-detect", GPIO_ACTIVE_LOW),
0230 GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ1,
0231 "pcmcia1-ready", GPIO_ACTIVE_HIGH),
0232 { },
0233 },
0234 };
0235
0236 void __init h3xxx_mach_init(void)
0237 {
0238 gpiod_add_lookup_table(&h3xxx_pcmcia_gpio_table);
0239 gpiod_add_lookup_table(&h3xxx_uart3_gpio_table);
0240 sa1100_register_uart_fns(&h3xxx_port_fns);
0241 sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
0242 platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
0243 }
0244
0245 static struct map_desc h3600_io_desc[] __initdata = {
0246 {
0247 .virtual = H3600_BANK_2_VIRT,
0248 .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
0249 .length = 0x02800000,
0250 .type = MT_DEVICE
0251 }, {
0252 .virtual = H3600_BANK_4_VIRT,
0253 .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
0254 .length = 0x00800000,
0255 .type = MT_DEVICE
0256 }, {
0257 .virtual = H3600_EGPIO_VIRT,
0258 .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
0259 .length = 0x01000000,
0260 .type = MT_DEVICE
0261 }
0262 };
0263
0264
0265
0266
0267
0268 void __init h3xxx_map_io(void)
0269 {
0270 sa1100_map_io();
0271 iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
0272
0273 sa1100_register_uart(0, 3);
0274
0275
0276
0277 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
0278 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
0279
0280
0281 PGSR = 0;
0282 PCFR = PCFR_OPDE;
0283 PSDR = 0;
0284
0285 GPCR = 0x0fffffff;
0286 GPDR = 0;
0287 }
0288