[XPERIA X1 Android Development] sp3dev:
BT

ok, let me post it here before i've forgotten. This is a refactoring of the rfkill in the gitorious tree, it also adds support for bluetooth to kovsky. And a bit of kovsky cleanup on top of that. Will commit this patch later.

--- htc/linux-msm/arch/arm/mach-msm/board-htcraphael-rfkill.c	2010-01-24 01:08:38.000000000 +0300
+++ linux-xperia/arch/arm/mach-msm/board-htcraphael-rfkill.c	2010-07-04 01:44:08.000000000 +0400
@@ -26,6 +26,7 @@
#include <asm/mach-types.h>

#include "board-htcraphael.h"
+#include "board-htckovsky.h"
#include "proc_comm_wince.h" /* ?? GPIO ?? */

void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state);
@@ -60,12 +61,12 @@
static int bluetooth_set_power(void *data, enum rfkill_state state)
{
int rc;
-	switch (state) {
-	case RFKILL_STATE_ON:
+	if (state == RFKILL_STATE_ON) {
printk(" bluetooth rfkill state ON\n");
-
config_gpio_table(bt_on_gpio_table_raph100,ARRAY_SIZE(bt_on_gpio_table_raph100));
-	if(machine_is_htcrhodium()) {
+
+	switch(__machine_arch_type){
+	case MACH_TYPE_HTCRHODIUM:
gpio_configure(91, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_HIGH);
gpio_set_value(91, 1);
mdelay(50);
@@ -76,8 +77,8 @@
gpio_set_value(31, 0);
mdelay(100);
gpio_set_value(31, 1);
-
-	} else if(machine_is_htctopaz()) {
+	break;
+	case MACH_TYPE_HTCTOPAZ:
rc = vreg_enable(vreg_bt);	// Don't use on Rhod, disables the display!
if(rc) {
printk(KERN_ERR "BT VREG Activate Error %d\n", rc);
@@ -88,10 +89,16 @@
gpio_set_value(RAPH100_BT_RST, 0);
mdelay(50);
gpio_set_value(RAPH100_BT_RST, 1);
-	} else if(machine_is_htcraphael_cdma() || machine_is_htcraphael_cdma500() || machine_is_htcdiamond_cdma()) {
+	break;
+	case MACH_TYPE_HTCRAPHAEL_CDMA500:
+	case MACH_TYPE_HTCRAPHAEL_CDMA:
+	case MACH_TYPE_HTCDIAMOND_CDMA:
gpio_configure(0x52, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_LOW);
gpio_set_value(0x52, 1);
-	} else {
+	break;
+	case MACH_TYPE_HTCDIAMOND:
+	case MACH_TYPE_HTCRAPHAEL:
+	case MACH_TYPE_HTCBLACKSTONE:
gpio_configure(RAPH100_WIFI_BT_PWR2, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_HIGH);
gpio_set_value(RAPH100_WIFI_BT_PWR2, 1);
mdelay(50);
@@ -99,29 +106,52 @@
gpio_set_value(RAPH100_BT_RST, 0);
mdelay(50);
gpio_set_value(RAPH100_BT_RST, 1);
-	}
break;
-	case RFKILL_STATE_OFF:
+	case MACH_TYPE_HTCVENUS:
+	gpio_configure(KOVS_GPIO_BT_ROUTER, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_LOW);
+	gpio_set_value(KOVS_GPIO_BT_ROUTER, 1);
+	mdelay(50);
+	gpio_configure(KOVS_GPIO_BT_POWER, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_LOW);
+	gpio_set_value(KOVS_GPIO_BT_POWER, 0);
+	mdelay(50);
+	gpio_set_value(KOVS_GPIO_BT_POWER, 1);
+	break;
+	default:
+	printk("RFKILL: unknown device!\n");
+	}
+	}
+	else if (state == RFKILL_STATE_OFF) {
printk(" bluetooth rfkill state OFF\n");
-#if 1
config_gpio_table(bt_off_gpio_table_raph100,ARRAY_SIZE(bt_off_gpio_table_raph100));
-#endif
-	if(machine_is_htcrhodium()) {
+	switch(__machine_arch_type) {
+	case MACH_TYPE_HTCRHODIUM:
gpio_configure(91, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_LOW);
gpio_set_value(91, 0);
-
-	} else if(machine_is_htctopaz()) {
+	break;
+	case MACH_TYPE_HTCTOPAZ:
gpio_configure(RAPH100_BT_RST, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_LOW);
vreg_set_level(vreg_bt, 0);
vreg_disable(vreg_bt);
-	} else if(machine_is_htcraphael_cdma() || machine_is_htcraphael_cdma500() || machine_is_htcdiamond_cdma()) {
+	break;
+	case MACH_TYPE_HTCRAPHAEL_CDMA500:
+	case MACH_TYPE_HTCRAPHAEL_CDMA:
+	case MACH_TYPE_HTCDIAMOND_CDMA:
gpio_set_value(0x52, 0);
-	} else {
+	break;
+	case MACH_TYPE_HTCDIAMOND:
+	case MACH_TYPE_HTCRAPHAEL:
+	case MACH_TYPE_HTCBLACKSTONE:
gpio_configure(RAPH100_BT_RST, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_LOW);
gpio_set_value(RAPH100_WIFI_BT_PWR2, 0);
-	}
+	case MACH_TYPE_HTCVENUS:
+	gpio_configure(KOVS_GPIO_BT_POWER, GPIOF_DRIVE_OUTPUT | GPIOF_OUTPUT_LOW);
+	gpio_set_value(KOVS_GPIO_BT_POWER, 0);
break;
-	default:
+	default:
+	printk("RFKILL: unknown device!\n");
+	}
+	}
+	else {
printk(KERN_ERR "bad bluetooth rfkill state %d\n", state);
}
return 0;
--- htc/linux-msm/arch/arm/mach-msm/board-htckovsky.c	2010-06-27 18:26:40.000000000 +0400
+++ linux-xperia/arch/arm/mach-msm/board-htckovsky.c	2010-07-04 01:54:23.000000000 +0400
@@ -1,4 +1,4 @@
-/* linux/arch/arm/mach-msm/board-htcraphael.c
+/* linux/arch/arm/mach-msm/board-htckovsky.c
*
* Copyright (C) 2007 Google, Inc.
* Author: Brian Swetland <swetland@google.com>,
@@ -49,6 +49,9 @@
#include <linux/delay.h>

#include <linux/microp-keypad.h>
+#ifdef CONFIG_HTC_HEADSET
+#include <mach/htc_headset.h>
+#endif

#include "proc_comm_wince.h"
#include "devices.h"
@@ -57,7 +60,7 @@

extern int init_mmc(void);

-static struct resource raphael_keypad_resources[] = {
+static struct resource kovsky_keypad_resources[] = {
{
.start = MSM_GPIO_TO_INT(38),
.end = MSM_GPIO_TO_INT(38),
@@ -65,20 +68,19 @@
},
};

-static struct microp_keypad_platform_data raphael_keypad_data = {
+static struct microp_keypad_platform_data kovsky_keypad_data = {
.backlight_gpio = 86,
};

static struct platform_device keypad_device = {
.name = "microp-keypad",
.id = 0,
-	.num_resources = ARRAY_SIZE(raphael_keypad_resources),
-	.resource = raphael_keypad_resources,
-	.dev = { .platform_data = &raphael_keypad_data, },
+	.num_resources = ARRAY_SIZE(kovsky_keypad_resources),
+	.resource = kovsky_keypad_resources,
+	.dev = { .platform_data = &kovsky_keypad_data, },
};

-
-static int usb_phy_init_seq_raph100[] = {
+static int usb_phy_init_seq_kovs100[] = {
0x40, 0x31, /* Leave this pair out for USB Host Mode */
0x1D, 0x0D,
0x1D, 0x10,
@@ -87,10 +89,16 @@

static void usb_phy_reset(void)
{
+ gpio_set_value(0x69, 1);
gpio_set_value(0x64, 0);
-	mdelay(1);
+	msleep(3);
gpio_set_value(0x64, 1);
-	mdelay(3);
+	msleep(3);
+}
+
+static void usb_phy_disable(void) {
+ gpio_set_value(0x64, 0);
+	gpio_set_value(0x69, 0);
}

static struct i2c_board_info i2c_devices[] = {
@@ -104,20 +112,20 @@
},
{
I2C_BOARD_INFO("mt9t013", 0x6c>>1),
-	/* .irq = TROUT_GPIO_TO_INT(TROUT_GPIO_CAM_BTN_STEP1_N), */
+	/* .irq = KOVS_GPIO_TO_INT(KOVS_GPIO_CAM_BTN_STEP1_N), */
},
};

static smem_batt_t msm_battery_pdata = {
-	.gpio_battery_detect = RAPH100_BAT_IRQ,
-	.gpio_charger_enable = RAPH100_CHARGE_EN_N,
-	.gpio_charger_current_select = RAPH100_USB_AC_PWR,
-	.gpio_ac_detect = KOVS110_AC_DETECT,
+	.gpio_battery_detect = KOVS_GPIO_BAT_IRQ,
+	.gpio_charger_enable = KOVS_GPIO_CHARGE_EN_N,
+	.gpio_charger_current_select = KOVS_GPIO_USB_AC_PWR,
+	.gpio_ac_detect = KOVS_GPIO_AC_DETECT,
.smem_offset = 0xfc110,
.smem_field_size = 2,
};

-static struct platform_device raphael_rfkill = {
+static struct platform_device kovsky_rfkill = {
.name = "htcraphael_rfkill",
.id = -1,
};
@@ -169,23 +177,67 @@
};
#undef SND

-static struct msm_snd_endpoints raphael_snd_endpoints = {
+static struct msm_snd_endpoints kovsky_snd_endpoints = {
.endpoints = snd_endpoints_list,
.num = ARRAY_SIZE(snd_endpoints_list),
};

-static struct platform_device raphael_snd = {
+static struct platform_device kovsky_snd = {
.name = "msm_snd",
.id = -1,
.dev	= {
-	.platform_data = &raphael_snd_endpoints,
+	.platform_data = &kovsky_snd_endpoints,
},
};

-static struct platform_device raphael_gps = {
+static struct platform_device kovsky_gps = {
.name = "raphael_gps",
};

+#ifdef CONFIG_HTC_HEADSET
+
+static void h2w_config_cpld(int route);
+static void h2w_init_cpld(void);
+static struct h2w_platform_data kovsky_h2w_data = {
+	.cable_in1 = KOVS_GPIO_CABLE_IN1,
+ .cable_in2 = KOVS_GPIO_CABLE_IN2,
+ .h2w_clk = KOVS_GPIO_H2W_CLK,
+	.h2w_data = KOVS_GPIO_H2W_DATA,
+	.debug_uart = H2W_UART3,
+	.config_cpld = h2w_config_cpld,
+	.init_cpld = h2w_init_cpld,
+	.headset_mic_35mm = 17,
+	.jack_inverted	= 1,
+};
+
+static void h2w_config_cpld(int route)
+{
+	switch (route) {
+	case H2W_UART3:
+	gpio_set_value(0, 1);
+	break;
+	case H2W_GPIO:
+	gpio_set_value(0, 0);
+	break;
+	}
+}
+
+static void h2w_init_cpld(void)
+{
+	h2w_config_cpld(H2W_UART3);
+	gpio_set_value(kovsky_h2w_data.h2w_clk, 0);
+	gpio_set_value(kovsky_h2w_data.h2w_data, 0);
+}
+
+static struct platform_device kovsky_h2w = {
+	.name = "h2w",
+	.id = -1,
+	.dev = {
+	.platform_data = &kovsky_h2w_data,
+	},
+};
+#endif
+
static struct platform_device touchscreen = {
.name	= "tssc-manager",
.id	= -1,
@@ -193,7 +245,7 @@

static struct platform_device *devices[] __initdata = {
&keypad_device,
-	&raphael_rfkill,
+	&kovsky_rfkill,
&msm_device_smd,
&msm_device_nand,
&msm_device_i2c,
@@ -206,9 +258,13 @@
&msm_device_uart_dm2,
#endif
&msm_device_htc_battery,
-	&raphael_snd,
-	&raphael_gps,
+	&kovsky_snd,
+	&kovsky_gps,
&touchscreen,
+#ifdef CONFIG_HTC_HEADSET
+	&kovsky_h2w,
+#endif
+
};

extern struct sys_timer msm_timer;
@@ -237,11 +293,11 @@
};
#endif

-static void htcraphael_reset(void)
+static void htckovsky_reset(void)
{
//	struct msm_dex_command dex = { .cmd = PCOM_RESET_ARM9 };
-	struct msm_dex_command dex = { .cmd = PCOM_POWER_OFF };
-//	struct msm_dex_command dex = { .cmd = PCOM_NOTIFY_ARM9_REBOOT };
+//	struct msm_dex_command dex = { .cmd = PCOM_POWER_OFF };
+	struct msm_dex_command dex = { .cmd = PCOM_NOTIFY_ARM9_REBOOT };
msm_proc_comm_wince(&dex, 0);
msleep(0x15e);
gpio_configure(25, GPIOF_OWNER_ARM11);
@@ -249,7 +305,7 @@
printk(KERN_INFO "%s: Soft reset done.\n", __func__);
}

-static void htcraphael_set_vibrate(uint32_t val)
+static void htckovsky_set_vibrate(uint32_t val)
{
struct msm_dex_command vibra;

@@ -266,7 +322,7 @@
}

static htc_hw_pdata_t msm_htc_hw_pdata = {
-	.set_vibrate = htcraphael_set_vibrate,
+	.set_vibrate = htckovsky_set_vibrate,
.battery_smem_offset = 0xfc140, //XXX: raph800
.battery_smem_field_size = 4,
};
@@ -281,12 +337,11 @@
msm_proc_comm_wince_init();

// Register hardware reset hook
-	msm_hw_reset_hook = htcraphael_reset;
+	msm_hw_reset_hook = htckovsky_reset;

// Device pdata overrides
msm_device_htc_hw.dev.platform_data = &msm_htc_hw_pdata;
msm_device_htc_battery.dev.platform_data = &msm_battery_pdata;
-	msm_add_usb_devices(usb_phy_reset, NULL, usb_phy_init_seq_raph100);

#ifdef CONFIG_SERIAL_MSM_HS
msm_device_uart_dm2.dev.platform_data = &msm_uart_dm2_pdata;
@@ -301,7 +356,7 @@

// Initialize SD controllers
init_mmc();
-
+	msm_add_usb_devices(usb_phy_reset, usb_phy_disable, usb_phy_init_seq_kovs100);
/* TODO: detect vbus and correctly notify USB about its presence
* For now we just declare that VBUS is present at boot and USB
* copes, but this is not ideal.
@@ -310,9 +365,9 @@

/* A little vibrating welcome */
for (i=0; i<2; i++) {
-	htcraphael_set_vibrate(1);
+	htckovsky_set_vibrate(1);
mdelay(150);
-	htcraphael_set_vibrate(0);
+	htckovsky_set_vibrate(0);
mdelay(75);
}
}
@@ -333,7 +388,7 @@
mi->nr_banks++;
mi->bank[1].start = PAGE_ALIGN(PHYS_OFFSET + 0x10000000);
mi->bank[1].node = PHYS_TO_NID(mi->bank[1].start);
-	mi->bank[1].size = (128-51)*1024*1024;
+	mi->bank[1].size = (128-34)*1024*1024;
printk(KERN_INFO "fixup: nr_banks = %d\n", mi->nr_banks);
printk(KERN_INFO "fixup: bank0 start=%08lx, node=%08x, size=%08lx\n", mi->bank[0].start, mi->bank[0].node, mi->bank[0].size);
if (mi->nr_banks > 1)
--- htc/linux-msm/arch/arm/mach-msm/board-htckovsky.h	2010-06-27 18:26:40.000000000 +0400
+++ linux-xperia/arch/arm/mach-msm/board-htckovsky.h	2010-07-04 01:31:58.000000000 +0400
@@ -1,126 +1,29 @@
/* linux/arch/arm/mach-msm/board-htckovsky.h
*/
-#ifndef __ARCH_ARM_MACH_MSM_BOARD_HTCKOVSKY_H
-#define __ARCH_ARM_MACH_MSM_BOARD_HTCKOVSKY_H
+#ifndef __ARCH_ARM_MACH_MSM_BOARD_HTCVENUS_H
+#define __ARCH_ARM_MACH_MSM_BOARD_HTCVENUS_H

#include <mach/board.h>

-/* GPIO */
-
-#define RAPH100_H2W_PWR	0
-#define RAPH100_USB_AC_PWR	1
-
-#define RAPH100_CAM_DAT2	2
-#define RAPH100_CAM_DAT3	3
-#define RAPH100_CAM_DAT4	4
-#define RAPH100_CAM_DAT5	5
-#define RAPH100_CAM_DAT6	6
-#define RAPH100_CAM_DAT7	7
-#define RAPH100_CAM_DAT8	8
-#define RAPH100_CAM_DAT9	9
-#define RAPH100_CAM_DAT10	10
-#define RAPH100_CAM_DAT11	11
-#define RAPH100_CAM_PCLK	12
-#define RAPH100_CAM_HSYNC_IN	13
-#define RAPH100_CAM_VSYNC_N	14
-#define RAPH100_CAM_MCLK	15
-/*	16*/
-#define RAPH100_EXTMIC_IRQ	17
-#define RAPH100_CABLE_IN_IRQ	18
-#define RAPH100_UART2DM_RTS	19	/* BT */
-#define RAPH100_UART2DM_CTS	20	/* BT */
-#define RAPH100_UART2DM_RX	21	/* BT*/
-/*	22*/
-#define RAPH100_SD_DETECT	23
-/*	24*/
-#define RAPH100_ARM9_SOFTRST	25
-/*	26*/
-#define RAPH100_KPD_IRQ	27
-#define RAPH100_BAT_IRQ	28
-#define RAPH100_WIFI_IRQ	29
-#define RAPH100_CAM_PWR1	30
-/*	H2W	31*/
-#define RAPH100_KPD_ROW0	32
-#define RAPH100_KPD_ROW1	33
-#define RAPH100_KPD_ROW2	34
-#define RAPH100_KPD_ROW3	35
-#define RAPH100_RST_IRQ	36
-#define KOVS110_AC_DETECT	37
-#define RAPH100_CLAMSHELL_IRQ	38
-#define RAPH800_CLAMSHELL_IRQ	39
-/*	unused	39*/
-#define RAPH100_KPD_COL0	40
-#define RAPH100_KPD_COL1	41
-#define RAPH100_KPD_COL2	42
-/*	region_id something	43*/
-#define RAPH100_CHARGE_EN_N	44
-#define RAPH100_UART1_TX	45	/* DBG */
-#define RAPH100_UART1_RX	46	/* DBG */
-/*	47*/
-/*	48*/
-/*	49*/
-/*	50*/
-#define RAPH100_WIFI_DAT3	51
-#define RAPH100_WIFI_DAT2	52
-#define RAPH100_WIFI_DAT1	53
-#define RAPH100_WIFI_DAT0	54
-#define RAPH100_WIFI_CMD	55
-#define RAPH100_WIFI_CLK	56
-#define RAPH100_TVOUT	57
-#define RAPH100_FLASHLIGHT	58
-/*	59*/
-#define RAPH100_I2C_SCL	60
-#define RAPH100_I2C_SDA	61
-#define RAPH100_SD_CLK	62
-#define RAPH100_SD_CMD	63
-#define RAPH100_SD_DAT3	64
-#define RAPH100_SD_DAT2	65
-#define RAPH100_SD_DAT1	66
-#define RAPH100_SD_DAT0	67
-#define RAPH100_PCM_DOUT	68
-#define RAPH100_PCM_DIN	69
-#define RAPH100_PCM_SYNC	70
-#define RAPH100_PCM_CLK	71
-
-#define RAPH100_LCD_PWR4	76
-#define RAPH100_USBCHARGE_EN	77
-
-#define RAPH100_LCD_PWR3	82
-#define RAPH100_PWR_BTN	83
-
-#define RAPH100_BKL_PWR	86
-
-#define RAPH100_HP_PWR	89
-#define RAPH100_USB_ID	90
-#define RAPH100_CAM_VCMPDP	91
-#define RAPH100_CAM1_RST	92
-#define RAPH100_CAM2_RST	93
-#define RAPH100_NAVI_IRQ	94
-
-#define RAPH100_LCD_VSYNC	97 /* FIXME! hardcoded */
-#define RAPH100_LCD_PWR1	98
-#define RAPH100_LCD_PWR2	99
-
-#define RAPH100_USBPHY_RST	100
-#define RAPH100_BT_RST	101
-#define RAPH100_WIFI_PWR1	102
-#define RAPH100_WIFI_BT_PWR2	103
-
-#define RAPH100_UART2DM_TX	108
-#define RAPH100_VGACAM_PWR	109
-
-#define RAPH100_ULPI_DATA0	111
-#define RAPH100_ULPI_DATA1	112
-#define RAPH100_ULPI_DATA2	113
-#define RAPH100_ULPI_DATA3	114
-#define RAPH100_ULPI_DATA4	115
-#define RAPH100_ULPI_DATA5	116
-#define RAPH100_ULPI_DATA6	117
-#define RAPH100_ULPI_DATA7	118
-#define RAPH100_ULPI_DIR	119
-#define RAPH100_ULPI_NEXT	120
-#define RAPH100_ULPI_STOP	121
-
-/* 111 - 121 USB OTG */
+/* Power Subsystem */
+#define KOVS_GPIO_USB_AC_PWR 1
+#define KOVS_GPIO_BAT_IRQ 28
+#define KOVS_GPIO_AC_DETECT 37
+#define KOVS_GPIO_CHARGE_EN_N 44
+
+/* H2W */
+#define KOVS_GPIO_HEADSET_MIC 17
+#define KOVS_GPIO_CABLE_IN1_XAXB 18
+#define KOVS_GPIO_CABLE_IN2 31
+#define KOVS_GPIO_CABLE_IN1 30
+#define KOVS_GPIO_AUD_EXTMIC_SEL 82
+#define KOVS_GPIO_UART3_RX 86
+#define KOVS_GPIO_UART3_TX 87
+#define KOVS_GPIO_H2W_DATA 86
+#define KOVS_GPIO_H2W_CLK 87
+
+/* BT */
+#define KOVS_GPIO_BT_POWER	32
+#define KOVS_GPIO_BT_ROUTER	63

#endif /* GUARD */

2ultrashot can we add your patch for front keys to our linux tree?