Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h3xxx.c
Go to the documentation of this file.
1 /*
2  * Support for Compaq iPAQ H3100 and H3600 handheld computers (common code)
3  *
4  * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
5  * Copyright (c) 2009 Dmitry Artamonow <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  */
12 
13 #include <linux/kernel.h>
14 #include <linux/gpio.h>
15 #include <linux/gpio_keys.h>
16 #include <linux/input.h>
17 #include <linux/mfd/htc-egpio.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/partitions.h>
20 #include <linux/platform_device.h>
21 #include <linux/serial_core.h>
22 
23 #include <asm/mach/flash.h>
24 #include <asm/mach/map.h>
25 #include <asm/mach/serial_sa1100.h>
26 
27 #include <mach/h3xxx.h>
28 
29 #include "generic.h"
30 
31 void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
32 {
33  while (n--) {
34  const char *name = s->name;
35  int err;
36 
37  if (!name)
38  name = "[init]";
39  err = gpio_request(s->gpio, name);
40  if (err) {
41  printk(KERN_ERR "gpio%u: unable to request: %d\n",
42  s->gpio, err);
43  continue;
44  }
45  if (s->mode >= 0) {
46  err = gpio_direction_output(s->gpio, s->mode);
47  } else {
48  err = gpio_direction_input(s->gpio);
49  }
50  if (err) {
51  printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
52  s->gpio, err);
53  continue;
54  }
55  if (!s->name)
56  gpio_free(s->gpio);
57  s++;
58  }
59 }
60 
61 
62 /*
63  * H3xxx flash support
64  */
65 static struct mtd_partition h3xxx_partitions[] = {
66  {
67  .name = "H3XXX boot firmware",
68  .size = 0x00040000,
69  .offset = 0,
70  .mask_flags = MTD_WRITEABLE, /* force read-only */
71  }, {
72  .name = "H3XXX rootfs",
73  .size = MTDPART_SIZ_FULL,
74  .offset = 0x00040000,
75  }
76 };
77 
78 static void h3xxx_set_vpp(int vpp)
79 {
81 }
82 
83 static int h3xxx_flash_init(void)
84 {
85  int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
86  if (err) {
87  pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__);
88  return err;
89  }
90 
92  if (err)
94 
95  return err;
96 }
97 
98 static void h3xxx_flash_exit(void)
99 {
101 }
102 
103 static struct flash_platform_data h3xxx_flash_data = {
104  .map_name = "cfi_probe",
105  .set_vpp = h3xxx_set_vpp,
106  .init = h3xxx_flash_init,
107  .exit = h3xxx_flash_exit,
108  .parts = h3xxx_partitions,
109  .nr_parts = ARRAY_SIZE(h3xxx_partitions),
110 };
111 
112 static struct resource h3xxx_flash_resource =
114 
115 
116 /*
117  * H3xxx uart support
118  */
119 static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
120 {
121  if (port->mapbase == _Ser3UTCR0) {
123  }
124 }
125 
126 static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
127 {
129 
130  if (port->mapbase == _Ser3UTCR0) {
131  /*
132  * DCD and CTS bits are inverted in GPLR by RS232 transceiver
133  */
135  ret &= ~TIOCM_CD;
137  ret &= ~TIOCM_CTS;
138  }
139 
140  return ret;
141 }
142 
143 static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
144 {
145  if (port->mapbase == _Ser3UTCR0) {
146  if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
149  } else {
150  pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
151  __func__);
152  }
153  }
154 }
155 
156 /*
157  * Enable/Disable wake up events for this serial port.
158  * Obviously, we only support this on the normal COM port.
159  */
160 static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
161 {
162  int err = -EINVAL;
163 
164  if (port->mapbase == _Ser3UTCR0) {
165  if (enable)
166  PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
167  else
168  PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
169  err = 0;
170  }
171  return err;
172 }
173 
174 static struct sa1100_port_fns h3xxx_port_fns __initdata = {
175  .set_mctrl = h3xxx_uart_set_mctrl,
176  .get_mctrl = h3xxx_uart_get_mctrl,
177  .pm = h3xxx_uart_pm,
178  .set_wake = h3xxx_uart_set_wake,
179 };
180 
181 /*
182  * EGPIO
183  */
184 
185 static struct resource egpio_resources[] = {
186  [0] = DEFINE_RES_MEM(H3600_EGPIO_PHYS, 0x4),
187 };
188 
189 static struct htc_egpio_chip egpio_chips[] = {
190  [0] = {
191  .reg_start = 0,
192  .gpio_base = H3XXX_EGPIO_BASE,
193  .num_gpios = 16,
194  .direction = HTC_EGPIO_OUTPUT,
195  .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
196  },
197 };
198 
199 static struct htc_egpio_platform_data egpio_info = {
200  .reg_width = 16,
201  .bus_width = 16,
202  .chip = egpio_chips,
203  .num_chips = ARRAY_SIZE(egpio_chips),
204 };
205 
206 static struct platform_device h3xxx_egpio = {
207  .name = "htc-egpio",
208  .id = -1,
209  .resource = egpio_resources,
210  .num_resources = ARRAY_SIZE(egpio_resources),
211  .dev = {
212  .platform_data = &egpio_info,
213  },
214 };
215 
216 /*
217  * GPIO keys
218  */
219 
220 static struct gpio_keys_button h3xxx_button_table[] = {
221  {
222  .code = KEY_POWER,
223  .gpio = H3XXX_GPIO_PWR_BUTTON,
224  .desc = "Power Button",
225  .active_low = 1,
226  .type = EV_KEY,
227  .wakeup = 1,
228  }, {
229  .code = KEY_ENTER,
230  .gpio = H3XXX_GPIO_ACTION_BUTTON,
231  .active_low = 1,
232  .desc = "Action button",
233  .type = EV_KEY,
234  .wakeup = 0,
235  },
236 };
237 
238 static struct gpio_keys_platform_data h3xxx_keys_data = {
239  .buttons = h3xxx_button_table,
240  .nbuttons = ARRAY_SIZE(h3xxx_button_table),
241 };
242 
243 static struct platform_device h3xxx_keys = {
244  .name = "gpio-keys",
245  .id = -1,
246  .dev = {
247  .platform_data = &h3xxx_keys_data,
248  },
249 };
250 
251 static struct platform_device *h3xxx_devices[] = {
252  &h3xxx_egpio,
253  &h3xxx_keys,
254 };
255 
257 {
258  sa1100_register_uart_fns(&h3xxx_port_fns);
259  sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
260  platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
261 }
262 
263 static struct map_desc h3600_io_desc[] __initdata = {
264  { /* static memory bank 2 CS#2 */
265  .virtual = H3600_BANK_2_VIRT,
267  .length = 0x02800000,
268  .type = MT_DEVICE
269  }, { /* static memory bank 4 CS#4 */
270  .virtual = H3600_BANK_4_VIRT,
272  .length = 0x00800000,
273  .type = MT_DEVICE
274  }, { /* EGPIO 0 CS#5 */
275  .virtual = H3600_EGPIO_VIRT,
277  .length = 0x01000000,
278  .type = MT_DEVICE
279  }
280 };
281 
282 /*
283  * Common map_io initialization
284  */
285 
287 {
288  sa1100_map_io();
289  iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
290 
291  sa1100_register_uart(0, 3); /* Common serial port */
292 // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
293 
294  /* Ensure those pins are outputs and driving low */
296  PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
297 
298  /* Configure suspend conditions */
299  PGSR = 0;
300  PCFR = PCFR_OPDE;
301  PSDR = 0;
302 
303  GPCR = 0x0fffffff; /* All outputs are set low by default */
304  GPDR = 0; /* Configure all GPIOs as input */
305 }
306