]>
Commit | Line | Data |
---|---|---|
c4dc8ddb MG |
1 | /* |
2 | * Provide kernel console on headphone jack | |
8eb83dc7 MG |
3 | * |
4 | * Copyright (C) 2011 Michael Gernoth <michael@gernoth.net> | |
5 | * | |
6 | * This file is subject to the terms and conditions of the GNU General Public | |
7 | * License. See the file "COPYING" in the main directory of this archive | |
8 | * for more details. | |
c4dc8ddb MG |
9 | */ |
10 | ||
11 | #include <linux/module.h> | |
12 | #include <linux/gpio_mapping.h> | |
13 | #include <linux/gpio.h> | |
8eb83dc7 MG |
14 | #include <linux/platform_device.h> |
15 | #include <linux/serial_reg.h> | |
16 | #include <linux/clk.h> | |
17 | ||
18 | #include <plat/board.h> | |
19 | #include <plat/control.h> | |
20 | #include <asm/mach/serial_omap.h> | |
21 | ||
22 | #include "prm.h" | |
23 | #include "prm-regbits-34xx.h" | |
c4dc8ddb | 24 | |
81799b4e MG |
25 | static int hs_switch = -1; |
26 | ||
c4dc8ddb MG |
27 | /* |
28 | * int add_preferred_console(char *name, int idx, char *options) | |
29 | * c0069208 T add_preferred_console | |
30 | */ | |
31 | ||
32 | static int (*add_preferred_console)(char *, int, char*) = (int (*)(char*, int, char*))0xc0069208; | |
33 | ||
8eb83dc7 MG |
34 | void my_omap_serial_init(int wake_gpio_strobe, unsigned int wake_strobe_enable_mask); |
35 | int my_omap_hs_init(void); | |
a18588b1 | 36 | void activate_emu_uart(void); |
8eb83dc7 MG |
37 | |
38 | #define MAPPHONE_BPWAKE_STROBE_GPIO 157 | |
39 | ||
47984ac7 MG |
40 | static int find_ms2_dev(struct device *dev, void *data) |
41 | { | |
42 | if (!strncmp((char*)data, dev_name(dev), strlen((char*)data))) { | |
43 | printk(KERN_INFO "Found it\n"); | |
44 | return 1; | |
45 | } | |
46 | return 0; | |
47 | } | |
48 | ||
c4dc8ddb MG |
49 | static int __init headphone_cons_init(void) |
50 | { | |
47984ac7 MG |
51 | int bpwake_strobe_gpio; |
52 | struct device *uart3 = NULL; | |
53 | ||
54 | /* Remove old uart3 device which was disabled... */ | |
55 | printk(KERN_INFO "Searching for omap-uart.3...\n"); | |
56 | ||
57 | uart3 = device_find_child(&platform_bus, "omap-uart.3", find_ms2_dev); | |
58 | if (uart3 == NULL) | |
59 | return-ENODEV; | |
60 | ||
61 | printk(KERN_INFO "Deleting old device...\n"); | |
62 | device_del(uart3); | |
63 | ||
c4dc8ddb MG |
64 | /* Get the headset switch gpio number from devtree */ |
65 | hs_switch = get_gpio_by_name("headset_uart_switch"); | |
66 | if (hs_switch < 0) | |
67 | return -EINVAL; | |
68 | ||
66526df8 | 69 | printk(KERN_INFO "headset_uart_switch: %d, value: %d\n", hs_switch, gpio_get_value(hs_switch)); |
81799b4e | 70 | |
8eb83dc7 | 71 | if (!gpio_get_value(hs_switch)) |
81799b4e | 72 | return -ENODEV; |
8eb83dc7 | 73 | |
47984ac7 MG |
74 | printk(KERN_INFO "Activating emu_uart on mini-usb port\n"); |
75 | activate_emu_uart(); | |
e14c6eae | 76 | |
8eb83dc7 | 77 | printk(KERN_INFO "Enabling UART3...\n"); |
47984ac7 MG |
78 | bpwake_strobe_gpio = get_gpio_by_name("ipc_bpwake_strobe"); |
79 | if (bpwake_strobe_gpio < 0) | |
80 | bpwake_strobe_gpio = MAPPHONE_BPWAKE_STROBE_GPIO; | |
81 | printk("Serial init with strobe pin %d\n", bpwake_strobe_gpio); | |
82 | my_omap_serial_init(bpwake_strobe_gpio, 0x01); | |
8eb83dc7 | 83 | my_omap_hs_init(); |
c4dc8ddb MG |
84 | |
85 | /* route kernel uart out headset jack */ | |
a18588b1 | 86 | gpio_set_value(hs_switch, 0); |
66526df8 | 87 | printk(KERN_INFO "headset_uart_switch: %d, value: %d\n", hs_switch, gpio_get_value(hs_switch)); |
c4dc8ddb | 88 | |
47984ac7 | 89 | add_preferred_console("ttyS", 2, "115200"); |
c4dc8ddb MG |
90 | return 0; |
91 | } | |
92 | ||
8eb83dc7 | 93 | #if 0 |
81799b4e MG |
94 | static void __exit headphone_cons_exit(void) |
95 | { | |
96 | if (hs_switch < 0) | |
97 | return; | |
98 | ||
99 | printk(KERN_INFO "value: %d\n", gpio_get_value(hs_switch)); | |
100 | gpio_direction_output(hs_switch, 1); | |
101 | printk(KERN_INFO "value: %d\n", gpio_get_value(hs_switch)); | |
102 | } | |
8eb83dc7 | 103 | #endif |
81799b4e MG |
104 | |
105 | ||
c4dc8ddb | 106 | module_init(headphone_cons_init); |
8eb83dc7 | 107 | #if 0 |
81799b4e | 108 | module_exit(headphone_cons_exit); |
8eb83dc7 | 109 | #endif |
c4dc8ddb MG |
110 | |
111 | MODULE_LICENSE("GPL"); | |
112 | MODULE_AUTHOR("Michael Gernoth <michael@gernoth.net>"); |