Dear all,
     Hello,everyone!I am working to use bcm4329 on FRX05 , but the dmesg
always output the error"mmc0: Data CRC error" after I insmod the dhd.ko.I
really can't figure out what is the matter.Could you do me a favor?Thanks!

    Here are the details:
1 .Environment: FRX05 From: http://xdandroid.com/,
http://files.xdandroid.com/..

2. Phone is the *p860*, but the wifi chip is the bcm4329.

3. Android and bcm4329 is from       git://
androidhtc.git.sourceforge.net/gitroot/androidhtc/manifest –b froyo. And *I
add my own "bcm_wlan_power_on" and "bcm_wlan_power_off"* in
the /arch/arm/mach-msm/mmc.c. "trout_wifi_power" is in the
board-htckaiser.c. For details,please see the attachments.

4. Kernel is linux 2.6.25, Compiler is arm-2009q3.

5. And the dmesg log is in the attachments.
    Thank you for any suggestion!

Best regards!
weihongcsu
8/13/2011

-- 
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting
/* linux/arch/arm/mach-msm/board-kaiser.c
 *
 * Author: Martin Johnson, Lukas Gorris <[email protected]> , Waylon Grange <[email protected]>
 * Based on board-halibut.c by Brian Swetland <[email protected]>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/i2c.h>
#include <linux/dma-mapping.h>
#include <linux/i2c/tsc2003.h>

#include <asm/hardware.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <asm/mach/flash.h>
#include <asm/mach/mmc.h>

#include <asm/arch/board.h>
#include <asm/arch/clock.h>
#include <asm/arch/msm_iomap.h>
#include <asm/arch/msm_fb.h>
#include <asm/arch/vreg.h>
#include <asm/setup.h>
#include <asm/arch/msm_serial_hs.h>
#include <asm/arch/dma.h>


#include <asm/io.h>
#include <asm/delay.h>
#include <linux/delay.h>

#include <linux/mtd/nand.h>
#include <linux/mtd/partitions.h>
#include <linux/mmc/sdio_ids.h>
#include <linux/msm_audio.h>

#include <asm/arch/gpio.h>
#include <linux/gpio_event.h>
#include "board-htckaiser.h"
#include "board-htcpolaris.h"
#include "htc_rfkill.h"
#include "vogue-hw.h"


#define MSM_SMI_BASE		0x00000000
#define MSM_SMI_SIZE		0x00900000

#define MSM_EBI_BASE		0x10000000
#define MSM_EBI_SIZE		0x08000000

#define MSM_LINUX_BASE		MSM_EBI_BASE
#define MSM_LINUX_SIZE		0x08000000

#define MSM_PMEM_CAMERA_BASE	MSM_CAMFB_PHYS
#define MSM_PMEM_CAMERA_SIZE	MSM_CAMFB_SIZE

#ifdef CONFIG_FROYO

#define MSM_PMEM_MDP_BASE	0x17300000
#define MSM_PMEM_MDP_SIZE	0x00100000
#define MSM_PMEM_ADSP_BASE	0x17400000
#define MSM_PMEM_ADSP_SIZE	0x00400000
#else
#define MSM_PMEM_MDP_BASE	0x16800000
#define MSM_PMEM_MDP_SIZE	0x00800000
#define MSM_PMEM_ADSP_BASE	0x17000000
#define MSM_PMEM_ADSP_SIZE	0x00800000
#endif

#define MSM_PMEM_GPU0_BASE  0x00100000
#define MSM_PMEM_GPU0_SIZE  0x00700000

#define MSM_PMEM_GPU1_BASE  0x17800000
#define MSM_PMEM_GPU1_SIZE  0x00800000

#define MSM_LOG_BASE  0x000e0000
#define MSM_LOG_SIZE  0x00020000

#define MSM_FB_BASE		0x00000000
#define MSM_FB_SIZE		0x000e0000

#ifdef CONFIG_FROYO
static int pmem_size=4;
static int pmem_adsp_size=1;
#else
static int pmem_size=8;
static int pmem_adsp_size=8;
#endif

static int panel_type=0;
module_param_named(panel_type, panel_type, int,
         S_IRUGO | S_IWUSR | S_IWGRP);

struct mddi_regs {
	int reg;
	int val;
	int time;
};

static void write_mddi_regs(struct mddi_panel_info *panel, const struct mddi_regs *regs) {
	
	while(regs->reg>=0) {
		//		printk("write reg %x to %x (was %x)\n",regs->reg, regs->val,mddi_remote_read(panel->mddi, regs->reg));
		mddi_remote_write(panel->mddi, regs->val, regs->reg);
		if(regs->time)
			mdelay(regs->time);
		regs++;
	}
}

int acpuclk_set_rate(struct clk *aclk, unsigned long rate, int for_power_collapse);

static const struct mddi_regs regs_on_toppoly[]={
		{0x1e0000,0x1770,0},
		{0x1e0010,0x300000,0},
		{0x1e0004,0x04d082,10},
		{0x1e000c,0x01,0},
		{0x1e0018,0x0,0},
		
		{0x180008,0x016e01,0},
		{0x18000c,0x070901,0},
		{0x180010,0x09f8ef,0},
		{0x180020,0x0,0},
		{0x180030,0x4b000,0},
		{0x180004,0xe0,0},
		{0x180000,0x08501c,10},
		
		{0x1c0008,0x2,0},
		{0x1c000c,0x1,0},
		{0x1c0000,0x18,0},
		
		{0x1d0004,0x40,0},
		{0x180000,0x08501f,0},
		{0x1e0018,0x10,0},
		{0x1d0004,0x0,2},
		
		{0x1c0008,0x0,0},
		{0x1c0010,0x4,0},
		{0x1c0010,0x0,0},
		{0x1c0008,0x2,170},
		{-1,-1}
};

static const struct mddi_regs regs_off_toppoly[]={
		{0x1e0018,0x10,2},
		{0x1d0004,0x40,0x4b},
		{0x1e0018,0,2},
		{0x1d0004,0},
		{-1,-1},
};

static const struct mddi_regs regs_on_toppoly1[]={
		{0x1e0000,0x1770,0},
		{0x1e0010,0x300000,0},
		{0x1e0004,0x04d082,10},
		{0x1e000c,0x01,0},
		{0x1e0018,0x0,0},
		
		{0x180008,0x016e01,0},
		{0x18000c,0x070901,0},
		{0x180010,0x09f8ef,0},
		{0x180020,0x0,0},
		{0x180030,0x4b000,0},
		{0x180004,0xe0,0},
		{0x180000,0x08501c,10},
		
		{0x1c0008,0x2,0},
		{0x1c000c,0x1,10},
		{0x1c0000,0x18,0},
		
		{0x1d0004,0x40,0},
		{0x180000,0x08501f,10},
		{0x1e0018,0x10,0},
		{0x1d0004,0x0,10},
		
		{0x1c0008,0x0,0},
		{0x1c0010,0x4,0},
		{0x1c0010,0x0,0},
		{0x1c0008,0x2,10},
		{-1,-1}
};

static const struct mddi_regs regs_off_sony[]={
		{0x1e0018,0,0x14},
		{-1,-1},
};


static const struct mddi_regs regs_on_sony[]={
		{0x1e0000,0x1770,0},
		{0x1e0010,0x300000,0},
		{0x1e0004,0x04d082,10},
		{0x1e000c,0x01,0},
		{0x1e0018,0x0,0},
		
		{0x180008,0x37701,0},
		{0x18000c,0x90103,0},
		{0x180010,0x09f8ef,0},
		{0x180020,0x0,0},
		{0x180030,0x4b000,0},
		{0x180004,0x60,0},
		{0x180000,0x08501c,10},
		{0x180000,0x08501f,50},
		{0x1e0018,0x10,70},
		{-1,-1}
	};

static struct mddi_panel_info *kaiser_panel_info=0;

void set_kaiser_backlight(int value) {
	if(!kaiser_panel_info)
		return;
	if (value) {
		mddi_remote_write(kaiser_panel_info->mddi,0x20,0x1d0004);
	} else {
		mddi_remote_write(kaiser_panel_info->mddi,0x0,0x1d0004);
	}
}

static void mddi0_client_power(struct mddi_panel_info *panel, int on) {
	printk("mddi0_client_power(%d) \n", on);
	if(!on) {
		gpio_set_value(KAISER_GPIO_MDDI_POWER,0);
		gpio_set_value(KAISER_GPIO_LCD_POWER,0);
		msm_proc_comm(0x16,0x800200); // vreg off
	} else {
		msm_proc_comm(0x15,0x800200); // vreg on
		gpio_set_value(KAISER_GPIO_MDDI_POWER,1);
		gpio_set_value(KAISER_GPIO_LCD_POWER,1);	
		mdelay(10);
	}
}

static void mddi0_panel_power(struct mddi_panel_info *panel, int on)
{
	int id;
	const int MSM_BACKLIGHT_POWER=MSM_CLK_CTL_BASE+0x58;
	printk("mddi0_panel_power(%d) type=%d\n", on, panel_type);
	kaiser_panel_info=panel;

	
//	mddi_remote_write(panel->mddi,0x0,0x1d0004);
//	mdelay(10);
//	id=mddi_remote_read(panel->mddi,0x1d0004);
//	printk("Panel ID=%d\n",id);

	if(!on) {
		writel(0xe0,MSM_BACKLIGHT_POWER);
		gpio_func(0x1b,0,1,0);

		// switch off the panel 
		if(panel_type) {
			msm_proc_comm(0x1d,0); // set arm9 low speed?
			
			if(panel_type==1)
				write_mddi_regs(panel,regs_off_sony);
			if(panel_type==2)
				write_mddi_regs(panel,regs_off_toppoly);
		}
		msm_proc_comm(0x16,0x200000);
	}
	else {
		if(panel_type) {
			
			//			write_mddi_regs(panel,(struct mddi_regs *)regs_mddi_bridge_init);
			//mdelay(10);
			if(panel_type==1)
				write_mddi_regs(panel,regs_on_sony);
			if(panel_type==2) 
				write_mddi_regs(panel,regs_on_toppoly);
			if(panel_type==3) 
				write_mddi_regs(panel,regs_on_toppoly1);
			msm_proc_comm(0x1d,0x1); // set arm9 high speed?
			udelay(100);
			
		}
		gpio_func(0x1b,4,1,1);
		writel(0xf8fa0b60,MSM_BACKLIGHT_POWER);
		msm_proc_comm(0x15,0x200000);
	}
	
}

static struct msm_mddi_platform_data msm_mddi0_pdata = {
	.panel_power	= mddi0_panel_power,
	.mddi_client_power = mddi0_client_power,
	.has_vsync_irq	= 1,
	.fb_base = MSM_FB_BASE,
	.fb_size = MSM_FB_SIZE,
};

static struct platform_device msm_mddi0_device = {
	.name	= "msm_mddi",
	.id	= 0,
	.dev	= {
		.platform_data = &msm_mddi0_pdata
	},
};

static struct android_pmem_platform_data android_pmem_camera_pdata = {
	.name = "pmem_camera",
	.start = MSM_PMEM_CAMERA_BASE,
	.size = MSM_PMEM_CAMERA_SIZE,
	.no_allocator = 1,
	.cached = 1,
};

static struct android_pmem_platform_data android_pmem_pdata = {
	.name = "pmem",
	.start = MSM_PMEM_MDP_BASE,
	.size = MSM_PMEM_MDP_SIZE,
	.no_allocator = 1,
	.cached = 1,
};

static struct android_pmem_platform_data android_pmem_adsp_pdata = {
	.name = "pmem_adsp",
	.start = MSM_PMEM_ADSP_BASE,
	.size = MSM_PMEM_ADSP_SIZE,
	.no_allocator = 0,
	.cached = 0,
};

static struct htc_rfkill_platform_data htc_rfkill_pdata = {
	.gpio=KAISER_GPIO_BT_CLOCK32K,
};

static struct platform_device htc_rfkill_device = {
	.name = "htc_rfkill",
	.id = 0,
	.dev = { .platform_data = &htc_rfkill_pdata },
};

static struct platform_device android_pmem_device = {
	.name = "android_pmem",
	.id = 0,
	.dev = { .platform_data = &android_pmem_pdata },
};


static struct android_pmem_platform_data android_pmem_gpu0_pdata = {
        .name = "pmem_gpu0",
        .start = MSM_PMEM_GPU0_BASE,
        .size = MSM_PMEM_GPU0_SIZE,
        .no_allocator = 1,
        .cached = 0,
        .buffered = 1,
};

static struct android_pmem_platform_data android_pmem_gpu1_pdata = {
 .name = "pmem_gpu1",
 .start = MSM_PMEM_GPU1_BASE,
 .size = MSM_PMEM_GPU1_SIZE,
 .no_allocator = 1,
 .cached = 0,
 .buffered = 1,
};

static struct platform_device android_pmem_gpu0_device = {
        .name = "android_pmem",
        .id = 1,
        .dev = { .platform_data = &android_pmem_gpu0_pdata },
};

static struct platform_device android_pmem_gpu1_device = {
	.name = "android_pmem",
	.id = 2,
	.dev = { .platform_data = &android_pmem_gpu1_pdata },
};

static struct platform_device android_pmem_camera_device = {
	.name = "android_pmem",
	.id = 3,
	.dev = { .platform_data = &android_pmem_camera_pdata },
};

static struct platform_device android_pmem_adsp_device = {
	.name = "android_pmem",
	.id = 4,
	.dev = { .platform_data = &android_pmem_adsp_pdata },
};

static struct resource ram_console_resource[] = {
	{
	  .start = MSM_LOG_BASE,
	  .end = MSM_LOG_BASE+MSM_LOG_SIZE-1,
	  .flags  = IORESOURCE_MEM,
	}
};

static struct platform_device ram_console_device = {
	.name = "ram_console",
	.id = -1,
	.num_resources  = ARRAY_SIZE(ram_console_resource),
	.resource       = ram_console_resource,
};


static struct platform_device msm_rtc_device = {
    .name = "msm_rtc",
};

static struct platform_device kaiser_hw_device = {
    .name = "vogue_hw",
};

static struct platform_device msm_smd2_device = {
   .name = "smd_channel_02",
};

static struct platform_device msm_rpc_device = {
   .name = "oncrpc_router",
};

static struct platform_device msm_adsp_device = {
   .name = "rs3000000a:00000000",
};

static struct platform_device kaiser_kbd_device = {
   .name = "kaiser_kbd",
};

static struct platform_device vogue_battery_device = {
   .name = "vogue_battery",
};

#define SND(num, desc) { .name = desc, .id = num }
static struct snd_endpoint snd_endpoints_list[] = {
	SND(0, "HANDSET"),
	SND(1, "SPEAKER"),
	SND(2, "HEADSET"),
	SND(3, "BT"),
	SND(44, "BT_EC_OFF"),
	SND(10, "HEADSET_AND_SPEAKER"),
	SND(256, "CURRENT"),

	/* Bluetooth accessories. */

	SND(12, "HTC BH S100"),
	SND(13, "HTC BH M100"),
	SND(14, "Motorola H500"),
	SND(15, "Nokia HS-36W"),
	SND(16, "PLT 510v.D"),
	SND(17, "M2500 by Plantronics"),
	SND(18, "Nokia HDW-3"),
	SND(19, "HBH-608"),
	SND(20, "HBH-DS970"),
	SND(21, "i.Tech BlueBAND"),
	SND(22, "Nokia BH-800"),
	SND(23, "Motorola H700"),
	SND(24, "HTC BH M200"),
	SND(25, "Jabra JX10"),
	SND(26, "320Plantronics"),
	SND(27, "640Plantronics"),
	SND(28, "Jabra BT500"),
	SND(29, "Motorola HT820"),
	SND(30, "HBH-IV840"),
	SND(31, "6XXPlantronics"),
	SND(32, "3XXPlantronics"),
	SND(33, "HBH-PV710"),
	SND(34, "Motorola H670"),
	SND(35, "HBM-300"),
	SND(36, "Nokia BH-208"),
	SND(37, "Samsung WEP410"),
	SND(38, "Jabra BT8010"),
	SND(39, "Motorola S9"),
	SND(40, "Jabra BT620s"),
	SND(41, "Nokia BH-902"),
	SND(42, "HBH-DS220"),
	SND(43, "HBH-DS980"),
};
#undef SND

static struct msm_snd_endpoints kaiser_snd_endpoints = {
        .endpoints = snd_endpoints_list,
        .num = ARRAY_SIZE(snd_endpoints_list),
};

static struct platform_device kaiser_snd_device = {
	.name = "msm_snd",
	.id = -1,
	.dev	= {
		.platform_data = &kaiser_snd_endpoints,
	},
};
static struct resource resources_hw3d[] = {
        {
                .start  = 0xA0000000,
                .end    = 0xA00fffff,
                .flags  = IORESOURCE_MEM,
                .name   = "regs",
        },
        {
                .flags  = IORESOURCE_MEM,
                .start  = MSM_PMEM_GPU0_BASE,
                .end    = MSM_PMEM_GPU0_BASE+MSM_PMEM_GPU0_SIZE-1,
                .name   = "smi",
        },
        {
                .flags  = IORESOURCE_MEM,
                .start  = MSM_PMEM_GPU1_BASE,
                .end    = MSM_PMEM_GPU1_BASE+MSM_PMEM_GPU1_SIZE-1,
                .name   = "ebi",
        },
        {
                .start  = INT_GRAPHICS,
                .end    = INT_GRAPHICS,
                .flags  = IORESOURCE_IRQ,
                .name   = "gfx",
        },
};

static struct platform_device hw3d_device = {
        .name           = "msm_hw3d",
        .id             = 0,
        .num_resources  = ARRAY_SIZE(resources_hw3d),
        .resource       = resources_hw3d,
};

static struct resource msm_uart1_dm_resources[] = {
	{
		.start = MSM_UART1DM_PHYS,
		.end   = MSM_UART1DM_PHYS + PAGE_SIZE - 1,
		.flags = IORESOURCE_MEM,
	},
	{
		.start = INT_UART1DM_IRQ,
		.end   = INT_UART1DM_IRQ,
		.name  = "uartdm_irq",
		.flags = IORESOURCE_IRQ,
	},
	{
		.start = INT_UART1DM_RX,
		.end   = INT_UART1DM_RX,
		.flags = IORESOURCE_IRQ,
	},
	{
		.start = DMOV_HSUART1_TX_CHAN,
		.end   = DMOV_HSUART1_RX_CHAN,
		.name  = "uartdm_channels",
		.flags = IORESOURCE_DMA,
	},
	{
		.start = DMOV_HSUART1_TX_CRCI,
		.end   = DMOV_HSUART1_RX_CRCI,
		.name  = "uartdm_crci",
		.flags = IORESOURCE_DMA,
	},
};

static u64 msm_uart_dm1_dma_mask = 0xffffffff;
/*
static struct msm_serial_hs_platform_data msm_uart_dm1_pdata = {
        .wakeup_irq = MSM_GPIO_TO_INT(45),
        .inject_rx_on_wakeup = 1,
        .rx_to_inject = 0x32,
};
*/

static struct platform_device msm_device_uart_dm1 = {
	.name = "msm_serial_hs",
	.id = 0,
	.num_resources = ARRAY_SIZE(msm_uart1_dm_resources),
	.resource = msm_uart1_dm_resources,
	.dev            = {
//		.platform_data=&msm_uart_dm1_pdata,
		.dma_mask = &msm_uart_dm1_dma_mask,
		.coherent_dma_mask = 0xffffffff,
	},
};

static struct platform_device *devices[] __initdata = {

	&ram_console_device,
	&msm_mddi0_device,
	&msm_rtc_device,
	&msm_rpc_device,
	&msm_adsp_device,
	&msm_smd2_device,
	&android_pmem_device,
	&android_pmem_gpu0_device,
	&android_pmem_gpu1_device,
	&android_pmem_camera_device,
	&kaiser_hw_device,
	&kaiser_kbd_device,
	&vogue_battery_device,
	&kaiser_snd_device,
	&hw3d_device,
	&htc_rfkill_device,
	&msm_device_uart_dm1,
	&android_pmem_adsp_device,

};

static int get_pendown(void) {
	return 1-gpio_get_value(KAISER_GPIO_PENDOWN);
}

static struct tsc2003_platform_data tsc2003_data= {
	.model=2003,
	.x_plate_ohms=2000,
	.get_pendown_state=get_pendown,
	.xmin=288,
	.ymin=320,
	.xmax=3652,
	.ymax=3565,
	.sensitivity=3072,
	.invertx=1,
};


static struct i2c_board_info __initdata kaiser_i2c_board_info[] = {
		{	I2C_BOARD_INFO("tsc2003", 0x48),.irq=KAISER_GPIO_TO_INT(KAISER_GPIO_PENDOWN_INT),.platform_data=&tsc2003_data },
//        {	I2C_BOARD_INFO("kaiser-ts", 0x48),
//		.irq            = MSM_GPIO_TO_INT(99), },
	{	I2C_BOARD_INFO("ds2746-battery", 0x36) },
	{	I2C_BOARD_INFO("s5k3c1fx", 0x11), },
	{	I2C_BOARD_INFO("focus", 0x0c), },
};


static unsigned int kaiser_sdcc_slot_status(struct device *dev)
{
	int slot=1-gpio_get_value(94);
	//  printk("sdcc_slot_status=%d\n",slot);
	return slot;
}
 
static int trout_wifi_cd = 0;		/* WIFI virtual 'card detect' status */

static void (*wifi_status_cb)(int card_present, void *dev_id)=NULL;
static void *wifi_status_cb_devid;

static int trout_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
{
	if (wifi_status_cb)
		return -EAGAIN;
	wifi_status_cb = callback;
	wifi_status_cb_devid = dev_id;
	return 0;
}

static unsigned int trout_wifi_status(struct device *dev)
{
	return trout_wifi_cd;
}

int trout_wifi_set_carddetect(int val)
{
	printk("%s: %d\n", __func__, val);
	trout_wifi_cd = val;
	if (wifi_status_cb) {
		wifi_status_cb(val, wifi_status_cb_devid);
	} else
		printk(KERN_WARNING "%s: Nobody to notify\n", __func__);
	return 0;
}
#ifndef CONFIG_WIFI_CONTROL_FUNC
EXPORT_SYMBOL(trout_wifi_set_carddetect);
#endif

static int trout_wifi_power_state;

void trout_pwrsink_set(int i, int j) {
	return;
}

EXPORT_SYMBOL(trout_pwrsink_set);

extern void gpio_func(int gpio, int func, int oe, int op);

int trout_wifi_power(int on) {
	if(on) {
		
		gpio_func(51,4,1,0);
		gpio_func(52,4,1,0);
		gpio_func(53,4,1,0);
		gpio_func(54,0xc4,1,0);
		gpio_func(55,0x7,1,0);
		gpio_func(56,4,1,0);

#if 0

		gpio_func(51,0,1,0);
		gpio_func(52,0,1,0);
		gpio_func(53,0,1,0);
		gpio_func(54,0,1,0);
		gpio_func(55,0,1,0);
		gpio_func(56,0,1,0);//added by liweihong
#endif

		msm_proc_comm(0x15,0x00100000); // pmic enable wlan vreg
		if (machine_is_htckaiser()){ 
			gpio_set_value(KAISER_GPIO_WIFI_PWR1,1);
			mdelay(100);
			gpio_set_value(KAISER_GPIO_WIFI_PWR2,1);
			mdelay(100);
		}
		else if (machine_is_htcpolaris()){
			gpio_set_value(HTCPOLARIS_GPIO_WIFI_PWR1,1);
			mdelay(100);
			gpio_set_value(HTCPOLARIS_GPIO_WIFI_PWR2,1);
			mdelay(100);
		}
						
		//		gpio_set_value(KAISER_GPIO_WIFI_RESET,1);
		//gpio_func(0x1d,3,0,0); // wlan irq
		//gpio_func(0x1d,3,0,0); // wlan irq
		//gpio_func(0x12,0,0,0); // wlan irq	/added by liweihong
		gpio_func(0x12,3,0,0); // wlan irq	/added by liweihong
		//io_func(0x1d,0,0,0); // wlan irq //added by liweihong
		//io_func(0x17,3,0,0); // wlan irq	/added by liweihong
		
	} else {
		gpio_func(0x1d,0,0,0);
		//		gpio_set_value(KAISER_GPIO_WIFI_RESET,0);
		if (machine_is_htckaiser()){ 
			gpio_set_value(KAISER_GPIO_WIFI_PWR2,0);
			mdelay(100);
			gpio_set_value(KAISER_GPIO_WIFI_PWR1,0);
			mdelay(100);
		}
		else if (machine_is_htcpolaris()){
			gpio_set_value(HTCPOLARIS_GPIO_WIFI_PWR2,0);
			mdelay(100);
			gpio_set_value(HTCPOLARIS_GPIO_WIFI_PWR1,0);
			mdelay(100);
		}
		msm_proc_comm(0x16,0x00100000); // pmic disable wlan vreg
		gpio_func(51,0,0,0);
		gpio_func(52,0,0,0);
		gpio_func(53,0,0,0);
		gpio_func(54,0,0,0);
		gpio_func(55,0,0,0);
		gpio_func(56,0,0,0);
	}
	
	
	printk("%s: %d\n", __func__, on);
	trout_wifi_power_state = on;
	return 0;
}
EXPORT_SYMBOL(trout_wifi_power);

static int trout_wifi_reset_state;
int trout_wifi_reset(int on)
{
	printk("%s: %d\n", __func__, on);
	if (machine_is_htckaiser()){ 
		gpio_set_value( KAISER_GPIO_WIFI_RESET, !on );
	}
	else if (machine_is_htcpolaris()){
		gpio_set_value( HTCPOLARIS_GPIO_WIFI_RESET, !on );
	}
	trout_wifi_reset_state = on;
	mdelay(50);
	return 0;
}
//#ifndef CONFIG_WIFI_CONTROL_FUNC
EXPORT_SYMBOL(trout_wifi_reset);

static unsigned int sdslot_vdd = 0xffffffff;
static unsigned int sdslot_vreg_enabled;

static uint32_t msm7200_sdslot_switchvdd(struct device *dev, unsigned int vdd) {
//	int i;

	if (vdd == sdslot_vdd)
		return 0;
	printk("set sdcc vdd to %d\n",vdd);
	sdslot_vdd = vdd;
	if(vdd==0) {
	//                msm_proc_comm(PCOM_SD_OFF,0);
		msm_proc_comm(PCOM_PMIC_REG_OFF,0x2000000);
		sdslot_vreg_enabled = 0;
		gpio_func(0x3e,0,1,0); // these are for sd2
		gpio_func(0x3f,0,1,0);
		gpio_func(0x40,0,1,0);
		gpio_func(0x41,0,1,0);
		gpio_func(0x42,0,1,0);
		gpio_func(0x43,0,1,0);
		msm_proc_comm(PCOM_PMIC_REG_OFF,0x20000);
		msm_proc_comm(PCOM_PMIC_REG_OFF,0x200000);
		gpio_set_value(KAISER_GPIO_SD_POWER,0);
		return 0;
	}
	msm_proc_comm(PCOM_PMIC_REG_ON,0x2000000);
	msm_proc_comm(PCOM_PMIC_REG_ON,0x20000); // MegaSIM (whatever that is!)
	msm_proc_comm(PCOM_PMIC_REG_ON,0x200000); // same
	gpio_set_value(KAISER_GPIO_SD_POWER,1);
	mdelay(50);
	gpio_func(0x3e,0x48,1,0);
	gpio_func(0x3f,0x48,1,0);
	gpio_func(0x40,0x48,1,0);
	gpio_func(0x41,0x48,1,0);
	gpio_func(0x42,0x48,1,0);
	gpio_func(0x43,0x48,1,0);

	return 0;
}

extern uint32_t msm7200_sdslot_switchvdd(struct device *dev, unsigned int vdd); // defined in polaris board file

static struct mmc_platform_data kaiser_sdcc_data = {
	.ocr_mask	= MMC_VDD_28_29,
	.status		= kaiser_sdcc_slot_status,
	.translate_vdd  = msm7200_sdslot_switchvdd,
};

static struct sdio_embedded_func wifi_func = {
	.f_class	= SDIO_CLASS_WLAN,
//	.f_maxblksize	= 512,
};

static struct embedded_sdio_data kaiser_wifi_emb_data = {
	.cis	= {
		.vendor		= 0x104c,
		.device		= 0x9066,
		.blksize	= 512,
		/*.max_dtr	= 24000000,  Max of chip - no worky on Trout */
		//.max_dtr	= 20000000,
		.max_dtr	= 32000000,//added by liweihong
	},
	.cccr	= {
		.multi_block	= 0,
		.low_speed	= 0,
		.wide_bus	= 1,
		.high_power	= 0,
		.high_speed	= 0,
	},
	.funcs	= &wifi_func,
	.num_funcs = 1,
};

static struct mmc_platform_data kaiser_wifi_data = {
	.ocr_mask		= MMC_VDD_28_29,
	.status			= trout_wifi_status,
	.register_status_notify	= trout_wifi_status_register,
	//.embedded_sdio		= &kaiser_wifi_emb_data,
	.embedded_sdio		= NULL,//added by liweihong
};


extern struct sys_timer msm_timer;

static void __init kaiser_init_irq(void)
{
	msm_init_irq();
}

static struct msm_clock_platform_data kaiser_clock_data = {
	.acpu_switch_time_us = 50,
	.max_speed_delta_khz = 256000,
	.vdd_switch_time_us = 62,
};

void msm_serial_debug_init(unsigned int base, int irq, 
			   const char *clkname, int signal_irq);

static void __init kaiser_init_mmc(void)
{
	msm_add_sdcc(1, &kaiser_wifi_data);
	msm_add_sdcc(2, &kaiser_sdcc_data);
}

void __init polaris_init_wifi_mmc(void)
{
    msm_add_sdcc(1, &kaiser_wifi_data);
}

extern int kaiser_init_gpio(void);
extern int trout_init_mmc_wifi(int);

static void __init kaiser_init(void)
{
	// kaiser gpios:
	// op 0: ?
	// op 1: b2a00c00 00000800 27
	// oe 1: b2a00c08 000fcc80
	// op2:
	// op 3: b2b00808 00024000 82,85
	// op 3: 
	// oe 3: b2b00818 02ba4400
	unsigned *gpio1=(unsigned *)(MSM_GPIO1_BASE+0x800);
	unsigned *gpio2=(unsigned *)(MSM_GPIO2_BASE+0xC00);
	
	printk("%x %x %x %x %x\n",gpio1[0],gpio2[0],gpio1[1],gpio1[2],gpio1[3]);
	printk("%x %x %x %x %x\n",gpio1[4],gpio2[2],gpio1[5],gpio1[6],gpio1[7]);
	
	msm_init_gpio();
	
	kaiser_init_gpio();
	

	gpio_func(0x1b,4,1,1);
	gpio_func(0,0,1,1);
	gpio_func(1,0,0,0);
	gpio_func(2,1,0,0);
	gpio_func(3,1,0,0);
	gpio_func(4,1,0,0);
	gpio_func(5,1,0,0);
	gpio_func(6,1,0,0);
	gpio_func(7,1,0,0);
	gpio_func(8,1,0,0);
	gpio_func(9,1,0,0);
	gpio_func(10,1,0,0);
	gpio_func(11,1,0,0);
	gpio_func(12,1,0,0);
	gpio_func(13,1,0,0);
	gpio_func(14,1,0,0);
	gpio_func(15,0x1c0,1,0);
	
	gpio_func(26,0,1,0); // cam power is on for wince?
//	gpio_func(16,0,1,0);
	gpio_func(17,0,0,0);
	gpio_func(18,0,0,0);
	gpio_func(19,0,0,0);

	gpio_func(20,3,0,0);
	gpio_func(21,0,0,0);
//	gpio_func(22,0,1,0);
	gpio_func(23,0,1,0);
//	gpio_func(24,0,0,0);
//	gpio_func(25,0,1,1);
	gpio_func(26,0,1,0);
	gpio_func(27,0,1,0);
	gpio_func(28,0,0,0);
	gpio_func(29,0,0,0);
	gpio_func(30,0,1,0);
	gpio_func(31,0,1,0);
	gpio_func(32,0,1,0);
	gpio_func(33,0,1,0);
	gpio_func(34,0,1,0);
	gpio_func(35,0,1,0);

	gpio_func(36,3,0,0);
	gpio_func(37,3,0,0);
	gpio_func(38,3,0,0);
	gpio_func(39,3,0,0);
	gpio_func(40,3,0,0);
	gpio_func(41,3,0,0);
	gpio_func(42,3,0,0);

	gpio_func(43,0,0,0);
	gpio_func(44,0,0,0);
	gpio_func(45,0,0,0);
	gpio_func(46,0,0,0);

//	gpio_func(47,0,1,0);
//	gpio_func(48,0,1,0);
	gpio_func(49,0,0,0);
//	gpio_func(50,0,1,0);
	gpio_func(51,0,0,0);
	gpio_func(52,0,0,0);
	gpio_func(53,0,0,0);
	gpio_func(54,0,0,0);
	gpio_func(55,0,0,0);

	gpio_func(56,0,1,0);
//	gpio_func(57,0,1,0);
//	gpio_func(58,0,1,0);
//	gpio_func(59,0,1,0);
	
	gpio_func(60,4,1,1); // i2c
	gpio_func(61,4,1,1);
	
	gpio_func(62,0x48,1,0);
	gpio_func(63,0x48,1,0);
	gpio_func(64,0x48,1,0);
	gpio_func(65,0x48,1,0);
	gpio_func(66,0x48,1,0);
	gpio_func(67,0x48,1,0);

	gpio_func(68,0,0,0);
	gpio_func(69,0,0,0);
	gpio_func(70,0,0,0);
	gpio_func(71,0,0,0);
	
//	gpio_func(72,0,1,0);
//	gpio_func(73,0,1,0);
//	gpio_func(74,0,1,0);
//	gpio_func(75,0,1,0);
//	gpio_func(76,0,1,0);
//	gpio_func(77,0,1,0);
	gpio_func(78,0,1,0);
//	gpio_func(79,0,1,0);
//	gpio_func(80,0,1,0);

	gpio_func(81,3,0,0);
	gpio_func(83,0,0,0);
	gpio_func(84,0,0,0);
	gpio_func(85,0,1,1);
	gpio_func(86,0,0,0);
	gpio_func(87,0,1,0);
	gpio_func(88,0,1,0);
	gpio_func(89,0,1,0);
	gpio_func(90,0,0,0);
	gpio_func(91,0,1,0);
	gpio_func(92,0,0,0);
	gpio_func(93,0,1,0);
	gpio_func(94,0,0,0);
//	gpio_func(95,1,0,0);
//	gpio_func(96,1,0,0);

	gpio_func(97,1,0,0);

	gpio_func(100,4,1,0);
	gpio_func(101,0,1,0);
	gpio_func(102,0,0,0);
	gpio_func(103,0,0,0);

	gpio_func(98,3,0,0);
	gpio_func(99,0,0,0);

	gpio_func(104,0,1,0);
	

	printk("%x %x %x %x %x\n",gpio1[0],gpio2[0],gpio1[1],gpio1[2],gpio1[3]);
	printk("%x %x %x %x %x\n",gpio1[4],gpio2[2],gpio1[5],gpio1[6],gpio1[7]);

	/*
	acpuclk_set_rate(0, 400000000, 0);
	// vibrate
	for (i=0; i<2; i++) {
		while(msm_proc_comm(0x4,0,0xb22)==-EAGAIN);
		mdelay(150);
		while(msm_proc_comm(0x5,0,0xb22)==-EAGAIN);
		mdelay(75);
	}
	*/

       android_pmem_adsp_pdata.start=android_pmem_gpu1_pdata.start-0x100000*pmem_adsp_size;
       android_pmem_adsp_pdata.size=0x100000*pmem_adsp_size;
       android_pmem_pdata.start=android_pmem_adsp_pdata.start-0x100000*pmem_size;
       android_pmem_pdata.size=0x100000*pmem_size;
       if(pmem_adsp_size) // only add pmem_adsp if it's not zero sized
               platform_add_devices(devices, ARRAY_SIZE(devices));
       else
               platform_add_devices(devices, ARRAY_SIZE(devices)-1);

	msm_add_devices();
	kaiser_init_mmc();
	//	trout_init_mmc_wifi(0);
	i2c_register_board_info(0, kaiser_i2c_board_info,
                ARRAY_SIZE(kaiser_i2c_board_info));
}

static struct map_desc kaiser_io_desc[] __initdata = {
        {
                .virtual = KAISER_CPLD_BASE,
                .pfn     = __phys_to_pfn(KAISER_CPLD_START),
                .length  = KAISER_CPLD_SIZE,
                .type    = MT_DEVICE_NONSHARED
        }
};


static void __init kaiser_map_io(void)
{
	msm_map_common_io();
	iotable_init(kaiser_io_desc, ARRAY_SIZE(kaiser_io_desc));
	msm_clock_init(&kaiser_clock_data);
}
static void __init kaiser_fixup(struct machine_desc *desc, struct tag *tags,
                               char **cmdline, struct meminfo *mi)
{
	// there's a big hole in the middle of the EBI address space,
	// did the modem steal some of our memory!

	mi->nr_banks=2;
	mi->bank[0].start = 0x10000000;
	mi->bank[0].node  = 0;
	mi->bank[0].size  = 0x03800000;
	mi->bank[1].start = 0x14000000;
	mi->bank[1].node  = 0;
#ifdef CONFIG_FROYO
	mi->bank[1].size  = 0x03300000;
#else
	mi->bank[1].size  = 0x02800000;
#endif
}

MACHINE_START(HTCKAISER, "HTC Kaiser")
/* Maintainer: Lukas Gorris*/
        /* UART for LL DEBUG */
	.phys_io	= MSM_UART1_PHYS,
	.io_pg_offst	= ((MSM_UART1_BASE) >> 18) & 0xfffc,
	.fixup        = kaiser_fixup,
	.boot_params	= 0x10000100,
	.map_io		= kaiser_map_io,
	.init_irq	= kaiser_init_irq,
	.init_machine	= kaiser_init,
	.timer		= &msm_timer,
MACHINE_END
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/mmc/host.h>
#include <linux/mmc/sdio_ids.h>
#include <linux/err.h>
#include <linux/debugfs.h>

#include <asm/mach-types.h>
#include <asm/gpio.h>

#include <asm/io.h>
//#include <arch/arm/mach-msm/include/mach/gpio.h>
//#include <mach/gpio.h>
#include "gpio.h"
#include <mach/vreg.h>
#include <mach/htc_pwrsink.h>

#include <asm/mach/mmc.h>
#include "board-htckaiser.h"


//#include "devices.h"

#include "proc_comm_wince.h"

#define DEBUG_SDSLOT_VDD 1


extern int trout_wifi_set_carddetect(int val);
extern int trout_wifi_power(int on);
extern int htcpolaris_wifi_set_carddetect(int val);



struct msm_gpio_config {
	unsigned gpio:10;
	unsigned dir:1;
	unsigned out_op:1;
	unsigned pull:2;
	unsigned func:4;
	unsigned drvstr:4;
	unsigned ignore:11;
} __attribute__((__packed__));



/* This struct holds the device-specific numbers and tables */
static struct mmc_dev_data {
	unsigned sdcard_status_gpio;
	char sdcard_device_id:3;
	unsigned wifi_power_gpio1;
	unsigned wifi_power_gpio2;
	struct msm_gpio_config *sdcard_on_gpio_table;
	struct msm_gpio_config *sdcard_off_gpio_table;
	int sdcard_on_gpio_table_size;
	int sdcard_off_gpio_table_size;
	struct msm_gpio_config *wifi_on_gpio_table;
	struct msm_gpio_config *wifi_off_gpio_table;
	int wifi_on_gpio_table_size;
	int wifi_off_gpio_table_size;
} mmc_pdata;


static void (*wifi_status_cb)(int card_present, void *dev_id);
static void *wifi_status_cb_devid;
static struct vreg *vreg_wifi_osc;	/* WIFI 32khz oscilator */
static struct vreg *vreg_wifi_2;	/* WIFI foo? */
static struct vreg *vreg_wifi_3;	/* WIFI tre? */


static int wifi_cd = 0;	/* WIFI virtual 'card detect' status */

/* ---- SDCARD ---- */
static struct msm_gpio_config sdcard_on_gpio_table_gsm[] = {
/*               num,alt                                                   */
	DEX_GPIO_CFG( 62, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* CLK */
	DEX_GPIO_CFG( 63, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* CMD */
	DEX_GPIO_CFG( 64, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT3 */
	DEX_GPIO_CFG( 65, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT2 */
	DEX_GPIO_CFG( 66, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT1 */
	DEX_GPIO_CFG( 67, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT0 */
};

static struct msm_gpio_config sdcard_off_gpio_table_gsm[] = {
/*                   num,alt                                                   */
	DEX_GPIO_CFG( 62, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* CLK */
	DEX_GPIO_CFG( 63, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* CMD */
	DEX_GPIO_CFG( 64, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT3 */
	DEX_GPIO_CFG( 65, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT2 */
	DEX_GPIO_CFG( 66, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT1 */
	DEX_GPIO_CFG( 67, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT0 */
};
/* ---- WIFI ---- */

static struct msm_gpio_config wifi_on_gpio_table_gsm[] = {
	DEX_GPIO_CFG( 51, 1, GPIO_INPUT , GPIO_PULL_UP, GPIO_2MA, 0 ), /* DAT3 */
	DEX_GPIO_CFG( 52, 1, GPIO_INPUT , GPIO_PULL_UP, GPIO_2MA, 0 ), /* DAT2 */
	DEX_GPIO_CFG( 53, 1, GPIO_INPUT , GPIO_PULL_UP, GPIO_2MA, 0 ), /* DAT1 */
	DEX_GPIO_CFG( 54, 1, GPIO_INPUT , GPIO_PULL_UP, GPIO_2MA, 0 ), /* DAT0 */
	DEX_GPIO_CFG( 55, 1, GPIO_INPUT , GPIO_PULL_UP, GPIO_2MA, 0 ), /* CMD */
	DEX_GPIO_CFG( 56, 1, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* CLK */

	DEX_GPIO_CFG( 29, 0, GPIO_INPUT , GPIO_PULL_UP, GPIO_2MA, 0 ), /* WLAN IRQ */
};

static struct msm_gpio_config wifi_off_gpio_table_gsm[] = {
	DEX_GPIO_CFG( 51, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT3 */
	DEX_GPIO_CFG( 52, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT2 */
	DEX_GPIO_CFG( 53, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT1 */
	DEX_GPIO_CFG( 54, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* DAT0 */
	DEX_GPIO_CFG( 55, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* CMD */
	DEX_GPIO_CFG( 56, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_2MA, 0 ), /* CLK */

	DEX_GPIO_CFG( 29, 0, GPIO_INPUT , GPIO_NO_PULL, GPIO_2MA, 0 ), /* WLAN IRQ */
};




static struct mmc_dev_data gsm_mmc_pdata = {
	.sdcard_status_gpio = 23,
	.sdcard_device_id = 2,
	//.wifi_power_gpio1 = 102,
	.wifi_power_gpio1 = 93,//added by liweihong
	.wifi_power_gpio2 = 103,
	// gpio config tables
	.sdcard_on_gpio_table = sdcard_on_gpio_table_gsm,
	.sdcard_off_gpio_table = sdcard_off_gpio_table_gsm,
	.wifi_on_gpio_table = wifi_on_gpio_table_gsm,
	.wifi_off_gpio_table = wifi_off_gpio_table_gsm,
	// table sizes
	.sdcard_on_gpio_table_size = ARRAY_SIZE(sdcard_on_gpio_table_gsm),
	.sdcard_off_gpio_table_size = ARRAY_SIZE(sdcard_off_gpio_table_gsm),
	.wifi_on_gpio_table_size = ARRAY_SIZE(wifi_on_gpio_table_gsm),
	.wifi_off_gpio_table_size = ARRAY_SIZE(wifi_off_gpio_table_gsm),
};

/* bcm_wlan_power_ hardcoded in bcm4329 driver */
void bcm_wlan_power_off(unsigned power_mode)
{
	printk ("%s: power_mode %d\n", __FUNCTION__, power_mode);

	switch (power_mode) {
		case 1:
			/* Unload driver */
			trout_wifi_power(0);
			trout_wifi_set_carddetect(0);
			msleep_interruptible(100);
			printk("\n%s:liweihong!!!Unload driver\n\n",__FUNCTION__);
			break;
		case 2:
			/* Stop driver */
			trout_wifi_power(0);
			printk("\n%s:liweihong!!!trout_wifi_power(0);\n\n",__FUNCTION__);
			break;
		default:
			printk ("%s: ERROR unsupported power_mode %d\n", __FUNCTION__, power_mode);
			break;
	}
}
EXPORT_SYMBOL(bcm_wlan_power_off);

void bcm_wlan_power_on(unsigned power_mode)
{
	printk ("%s: power_mode %d\n", __FUNCTION__, power_mode);// 1

	switch (power_mode) {
		case 1:
			/*Load driver  */
			//htcpolaris_wifi_power(1);
			//htcpolaris_wifi_set_carddetect(1);
			trout_wifi_power(1);
			trout_wifi_set_carddetect(1);
			msleep_interruptible(100);
			printk("\n%s:liweihong!!!Load driver.\n\n",__FUNCTION__);
			break;
		case 2:
			/* Start driver */
			printk("\n%s:liweihong!!!trout_wifi_power(1);Start driver\n\n",__FUNCTION__);
			trout_wifi_power(1);
			//htcpolaris_wifi_power(1);
			break;
		default:
			printk ("%s: ERROR unsupported power_mode %d\n", __FUNCTION__, power_mode);
			break;
	}
}
EXPORT_SYMBOL(bcm_wlan_power_on);

Reply via email to