1 /* Board support file for Samsung Tuna Board.
3 * Copyright (C) 2011 Google, Inc.
4 * Copyright (C) 2010 Texas Instruments
6 * Based on mach-omap2/board-omap4panda.c
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/gpio.h>
22 #include <linux/input.h>
23 #include <linux/i2c/twl6030-madc.h>
24 #include <linux/sec_jack.h>
27 #include "board-tuna.h"
29 #define GPIO_EAR_MICBIAS_EN 49
31 #define GPIO_EAR_SEND_END 1
33 #define ADC_CHANNEL_JACK 2
35 static void sec_jack_set_micbias_state(bool on
)
37 gpio_set_value(GPIO_EAR_MICBIAS_EN
, on
);
40 static struct sec_jack_zone sec_jack_zones
[] = {
42 /* adc < 50, unstable zone, default to 3pole if it stays
43 * in this range for a half second (20ms delays, 25 samples)
48 .jack_type
= SEC_HEADSET_3POLE
,
51 /* 50 < adc <= 490, unstable zone, default to 3pole if it stays
52 * in this range for a second (10ms delays, 100 samples)
57 .jack_type
= SEC_HEADSET_3POLE
,
60 /* 490 < adc <= 900, unstable zone, default to 4pole if it
61 * stays in this range for a second (10ms delays, 100 samples)
66 .jack_type
= SEC_HEADSET_4POLE
,
69 /* 900 < adc <= 1500, 4 pole zone, default to 4pole if it
70 * stays in this range for 200ms (20ms delays, 10 samples)
75 .jack_type
= SEC_HEADSET_4POLE
,
78 /* adc > 1500, unstable zone, default to 3pole if it stays
79 * in this range for a second (10ms delays, 100 samples)
81 .adc_high
= 0x7fffffff,
84 .jack_type
= SEC_HEADSET_3POLE
,
88 /* To support 3-buttons earjack */
89 static struct sec_jack_buttons_zone sec_jack_buttons_zones
[] = {
91 /* 0 <= adc <= 93, stable zone */
97 /* 94 <= adc <= 167, stable zone */
98 .code
= KEY_PREVIOUSSONG
,
103 /* 168 <= adc <= 370, stable zone */
104 .code
= KEY_NEXTSONG
,
110 static int sec_jack_get_adc_value(void)
114 value
= twl6030_get_madc_conversion(ADC_CHANNEL_JACK
);
115 return (int)(1800*value
) / 1024;
118 struct sec_jack_platform_data sec_jack_pdata
= {
119 .set_micbias_state
= sec_jack_set_micbias_state
,
120 .get_adc_value
= sec_jack_get_adc_value
,
121 .zones
= sec_jack_zones
,
122 .num_zones
= ARRAY_SIZE(sec_jack_zones
),
123 .buttons_zones
= sec_jack_buttons_zones
,
124 .num_buttons_zones
= ARRAY_SIZE(sec_jack_buttons_zones
),
125 .det_gpio
= GPIO_DET_35
,
126 .send_end_gpio
= GPIO_EAR_SEND_END
,
129 static struct platform_device sec_device_jack
= {
131 .id
= 1, /* will be used also for gpio_event id */
132 .dev
.platform_data
= &sec_jack_pdata
,
135 void __init
omap4_tuna_jack_init(void)
137 omap_mux_init_signal("sim_io.gpio_wk0", OMAP_PIN_INPUT
);
138 gpio_request(GPIO_DET_35
, "det_35_en");
139 gpio_direction_input(GPIO_DET_35
);
141 omap_mux_init_signal("sim_clk.gpio_wk1", OMAP_PIN_INPUT
);
142 gpio_request(GPIO_EAR_SEND_END
, "ear_send_end");
143 gpio_direction_input(GPIO_EAR_SEND_END
);
145 omap_mux_init_signal("gpmc_a25.gpio_49", OMAP_PIN_OUTPUT
| OMAP_MUX_MODE3
);
146 gpio_request(GPIO_EAR_MICBIAS_EN
, "ear_micbias_en");
147 gpio_direction_output(GPIO_EAR_MICBIAS_EN
, 0);
149 gpio_free(GPIO_DET_35
);
150 gpio_free(GPIO_EAR_SEND_END
);
151 platform_device_register(&sec_device_jack
);