From 21ead31928f7db7dd729e0d582828d747d378759 Mon Sep 17 00:00:00 2001 From: lyx Date: Sat, 7 Aug 2010 01:20:35 -0700 Subject: [PATCH] add cs select for dm9000 and move io set function to board-XXXX.c file --- arch/arm/mach-rk2818/board-midsdk.c | 114 +++++++++++++++++++++++++- arch/arm/mach-rk2818/board-phonesdk.c | 113 ++++++++++++++++++++++++- arch/arm/mach-rk2818/board-raho.c | 113 ++++++++++++++++++++++++- arch/arm/mach-rk2818/devices.c | 28 +++---- arch/arm/mach-rk2818/devices.h | 1 + drivers/net/Kconfig | 8 ++ drivers/net/dm9000.c | 15 +++- include/linux/dm9000.h | 6 ++ 8 files changed, 370 insertions(+), 28 deletions(-) diff --git a/arch/arm/mach-rk2818/board-midsdk.c b/arch/arm/mach-rk2818/board-midsdk.c index 7d42cd4fb0d7..527c226a2b87 100644 --- a/arch/arm/mach-rk2818/board-midsdk.c +++ b/arch/arm/mach-rk2818/board-midsdk.c @@ -37,6 +37,7 @@ #include #include +#include #include "devices.h" @@ -442,11 +443,114 @@ struct rk2818bl_info rk2818_bl_info = { .pw_iomux = GPIOA23_UART2_SEL_NAME, }; -static struct platform_device *devices[] __initdata = { - &rk2818_device_uart1, #ifdef CONFIG_DM9000 - &rk2818_device_dm9k, +#define NET_INT_PIN RK2818_PIN_PE2 +/*dm9000 gpio set*/ +int dm9k_gpio_set(void) +{ + //cs +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1); + break; + case 2: + rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2); + break; + case 3: + rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3); + break; + case 4: + case 5: + rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45); + break; + case 6: + case 7: + rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL_NAME, IOMUXA_FLASH_CS67); + break; + default: + break; + } #endif + + //int + rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_GPIO1_A12); + if (gpio_request(NET_INT_PIN, "dm9000 interrupt")) { + gpio_free(NET_INT_PIN); + rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME); + printk("[fun:%s line:%d], request gpio for net interrupt fail\n", __func__,__LINE__); + goto err; + return -1; + } + gpio_pull_updown(NET_INT_PIN, GPIOPullDown); + gpio_direction_input(NET_INT_PIN); + return 0; +err: + +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME); + break; + case 2: + rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME); + break; + case 3: + rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME); + break; + case 4: + case 5: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); + break; + case 6: + case 7: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME); + break; + default: + break; + } +#endif + return -1; +} +void dm9k_gpio_free(void) +{ + gpio_free(NET_INT_PIN); + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME); + break; + case 2: + rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME); + break; + case 3: + rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME); + break; + case 4: + case 5: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); + break; + case 6: + case 7: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME); + break; + default: + break; + } +#endif +} + +struct dm9000_plat_data dm9k_platdata = { + .flags = DM9000_PLATF_8BITONLY, + .pin_int = NET_INT_PIN, + .net_gpio_set = dm9k_gpio_set, + .net_gpio_free = dm9k_gpio_free, +}; +#endif + +static struct platform_device *devices[] __initdata = { + &rk2818_device_uart1, #ifdef CONFIG_I2C0_RK2818 &rk2818_device_i2c0, #endif @@ -474,6 +578,10 @@ static struct platform_device *devices[] __initdata = { #ifdef CONFIG_MTD_NAND_RK2818 &rk2818_nand_device, #endif +#ifdef CONFIG_DM9000 + &rk2818_device_dm9k, +#endif + #ifdef CONFIG_DWC_OTG &rk2818_device_dwc_otg, #endif diff --git a/arch/arm/mach-rk2818/board-phonesdk.c b/arch/arm/mach-rk2818/board-phonesdk.c index 707cd3ce0da1..01be1f09d66d 100755 --- a/arch/arm/mach-rk2818/board-phonesdk.c +++ b/arch/arm/mach-rk2818/board-phonesdk.c @@ -37,6 +37,7 @@ #include #include +#include #include "devices.h" @@ -448,11 +449,113 @@ struct rk2818bl_info rk2818_bl_info = { .pw_iomux = GPIOF34_UART3_SEL_NAME, }; -static struct platform_device *devices[] __initdata = { - &rk2818_device_uart1, #ifdef CONFIG_DM9000 - &rk2818_device_dm9k, +#define NET_INT_PIN RK2818_PIN_PA1 +/*dm9000 gpio set*/ +int dm9k_gpio_set(void) +{ + //cs +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1); + break; + case 2: + rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2); + break; + case 3: + rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3); + break; + case 4: + case 5: + rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45); + break; + case 6: + case 7: + rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL_NAME, IOMUXA_FLASH_CS67); + break; + default: + break; + } #endif + + //int + rk2818_mux_api_set(GPIOA1_HOSTDATA17_SEL_NAME, IOMUXB_GPIO0_A1); + if (gpio_request(NET_INT_PIN, "dm9000 interrupt")) { + gpio_free(NET_INT_PIN); + rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME); + printk("[fun:%s line:%d], request gpio for net interrupt fail\n", __func__,__LINE__); + goto err; + } + gpio_pull_updown(NET_INT_PIN, GPIOPullDown); + gpio_direction_input(NET_INT_PIN); + return 0; + +err: +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME); + break; + case 2: + rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME); + break; + case 3: + rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME); + break; + case 4: + case 5: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); + break; + case 6: + case 7: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME); + break; + default: + break; + } +#endif + return -1; +} +void dm9k_gpio_free(void) +{ + gpio_free(NET_INT_PIN); + rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME); +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME); + break; + case 2: + rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME); + break; + case 3: + rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME); + break; + case 4: + case 5: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); + break; + case 6: + case 7: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME); + break; + default: + break; + } +#endif +} + +struct dm9000_plat_data dm9k_platdata = { + .flags = DM9000_PLATF_8BITONLY, + .pin_int = NET_INT_PIN, + .net_gpio_set = dm9k_gpio_set, + .net_gpio_free = dm9k_gpio_free, +}; +#endif + +static struct platform_device *devices[] __initdata = { + &rk2818_device_uart1, #ifdef CONFIG_I2C0_RK2818 &rk2818_device_i2c0, #endif @@ -480,6 +583,10 @@ static struct platform_device *devices[] __initdata = { #ifdef CONFIG_MTD_NAND_RK2818 &rk2818_nand_device, #endif +#ifdef CONFIG_DM9000 + &rk2818_device_dm9k, +#endif + #ifdef CONFIG_DWC_OTG &rk2818_device_dwc_otg, #endif diff --git a/arch/arm/mach-rk2818/board-raho.c b/arch/arm/mach-rk2818/board-raho.c index 8e186e8dd1ce..fc4b4281815a 100755 --- a/arch/arm/mach-rk2818/board-raho.c +++ b/arch/arm/mach-rk2818/board-raho.c @@ -41,6 +41,7 @@ #include #include +#include #include /* ddl@rock-chips.com : camera support */ @@ -615,11 +616,113 @@ struct rk2818bl_info rk2818_bl_info = { .pw_iomux = GPIOF34_UART3_SEL_NAME, }; -static struct platform_device *devices[] __initdata = { - &rk2818_device_uart1, #ifdef CONFIG_DM9000 - &rk2818_device_dm9k, +#define NET_INT_PIN RK2818_PIN_PA1 +/*dm9000 gpio set*/ +int dm9k_gpio_set(void) +{ + //cs +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1); + break; + case 2: + rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2); + break; + case 3: + rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3); + break; + case 4: + case 5: + rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45); + break; + case 6: + case 7: + rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL_NAME, IOMUXA_FLASH_CS67); + break; + default: + break; + } +#endif + + //int + rk2818_mux_api_set(GPIOA1_HOSTDATA17_SEL_NAME, IOMUXB_GPIO0_A1); + if (gpio_request(NET_INT_PIN, "dm9000 interrupt")) { + gpio_free(NET_INT_PIN); + rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME); + printk("[fun:%s line:%d], request gpio for net interrupt fail\n", __func__,__LINE__); + goto err; + } + gpio_pull_updown(NET_INT_PIN, GPIOPullDown); + gpio_direction_input(NET_INT_PIN); + return 0; +err: + +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME); + break; + case 2: + rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME); + break; + case 3: + rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME); + break; + case 4: + case 5: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); + break; + case 6: + case 7: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME); + break; + default: + break; + } +#endif + return -1; +} +void dm9k_gpio_free(void) +{ + gpio_free(NET_INT_PIN); + rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME); +#ifdef CONFIG_DM9000_CHIP_SELECT + switch (CONFIG_DM9000_CHIP_SELECT) { + case 1: + rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME); + break; + case 2: + rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME); + break; + case 3: + rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME); + break; + case 4: + case 5: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); + break; + case 6: + case 7: + rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME); + break; + default: + break; + } +#endif +} + +struct dm9000_plat_data dm9k_platdata = { + .flags = DM9000_PLATF_8BITONLY, + .pin_int = NET_INT_PIN, + .net_gpio_set = dm9k_gpio_set, + .net_gpio_free = dm9k_gpio_free, +}; #endif + +static struct platform_device *devices[] __initdata = { + &rk2818_device_uart1, #ifdef CONFIG_I2C0_RK2818 &rk2818_device_i2c0, #endif @@ -653,6 +756,10 @@ static struct platform_device *devices[] __initdata = { #ifdef CONFIG_MTD_NAND_RK2818 &rk2818_nand_device, #endif +#ifdef CONFIG_DM9000 + &rk2818_device_dm9k, +#endif + #ifdef CONFIG_DWC_OTG &rk2818_device_dwc_otg, #endif diff --git a/arch/arm/mach-rk2818/devices.c b/arch/arm/mach-rk2818/devices.c index 60719ac16928..3e76ca5c11f1 100755 --- a/arch/arm/mach-rk2818/devices.c +++ b/arch/arm/mach-rk2818/devices.c @@ -325,40 +325,32 @@ struct platform_device rk2818_soc_camera_pdrv = { //net device /* DM9000 */ #ifdef CONFIG_DM9000 +#ifdef CONFIG_DM9000_CHIP_SELECT +#define DM9000_CS CONFIG_DM9000_CHIP_SELECT +#else +#define DM9000_CS 1 +#endif static struct resource dm9k_resource[] = { [0] = { - .start = RK2818_NANDC_PHYS + 0x800 + (1*0x100 + 0x8), //nand_cs1+nand_cmd - .end = RK2818_NANDC_PHYS + 0x800 + (1*0x100 + 0x8) + 3, + .start = RK2818_NANDC_PHYS + 0x800 + (DM9000_CS*0x100 + 0x8), //nand_cs1+nand_cmd + .end = RK2818_NANDC_PHYS + 0x800 + (DM9000_CS*0x100 + 0x8) + 3, .flags = IORESOURCE_MEM, }, [1] = { - .start = RK2818_NANDC_PHYS + 0x800 + (1*0x100 + 0x4), //nand_cs1+nand_data - .end = RK2818_NANDC_PHYS + 0x800 + (1*0x100 + 0x4) + 3, + .start = RK2818_NANDC_PHYS + 0x800 + (DM9000_CS*0x100 + 0x4), //nand_cs1+nand_data + .end = RK2818_NANDC_PHYS + 0x800 + (DM9000_CS*0x100 + 0x4) + 3, .flags = IORESOURCE_MEM, }, - #ifdef CONFIG_MACH_RK2818MID - [2] = { - .start = RK2818_PIN_PE2, //use pe2 as interrupt - .end = RK2818_PIN_PE2, - .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL, - } - #else [2] = { - .start = RK2818_PIN_PA1, //use pa1 as interrupt - .end = RK2818_PIN_PA1, .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL, } - #endif - }; /* for the moment we limit ourselves to 8bit IO until some * better IO routines can be written and tested */ -static struct dm9000_plat_data dm9k_platdata = { - .flags = DM9000_PLATF_8BITONLY, -}; +//dm9k_platdata.flags = DM9000_PLATF_8BITONLY; struct platform_device rk2818_device_dm9k = { .name = "dm9000", diff --git a/arch/arm/mach-rk2818/devices.h b/arch/arm/mach-rk2818/devices.h index 776170c0add2..85cc7dc5833a 100755 --- a/arch/arm/mach-rk2818/devices.h +++ b/arch/arm/mach-rk2818/devices.h @@ -38,6 +38,7 @@ extern struct platform_device rk2818_device_sdmmc1; extern struct rk2818_sdmmc_platform_data default_sdmmc0_data; extern struct rk2818_sdmmc_platform_data default_sdmmc1_data; extern struct platform_device rk2818_device_dm9k; +extern struct dm9000_plat_data dm9k_platdata; extern struct platform_device rk2818_device_i2s; extern struct platform_device rk2818_device_pmem; extern struct platform_device rk2818_device_pmem_dsp; diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 41a3405c6fe3..2ccf896d55a7 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -957,6 +957,14 @@ choice tristate "DM9000 with NOR Interface" endchoice endif + +config DM9000_CHIP_SELECT + int "the number of nandc chip select for DM9000" + depends on DM9000_USE_NAND_CONTROL + default 1 + help + select the cs for dm9000 + config DM9000_FORCE_SIMPLE_PHY_POLL bool "Force simple NSR based PHY polling" diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c index 509493d3c41d..5247ac01581b 100755 --- a/drivers/net/dm9000.c +++ b/drivers/net/dm9000.c @@ -1515,6 +1515,9 @@ dm9000_probe(struct platform_device *pdev) /* fill in parameters for net-dev structure */ ndev->base_addr = (unsigned long)db->io_addr; +#if 0 + rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1); + #ifdef CONFIG_MACH_RK2818MID rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_GPIO1_A12); ndev->irq = gpio_to_irq(db->irq_res->start); @@ -1529,7 +1532,17 @@ dm9000_probe(struct platform_device *pdev) gpio_pull_updown(db->irq_res->start, GPIOPullDown); ndev->irq = gpio_to_irq(db->irq_res->start); #endif - +#endif + + if (pdata->net_gpio_set) { + if (pdata->net_gpio_set()) { + ret = -EINVAL; + goto out; + } + } + + ndev->irq = gpio_to_irq(pdata->pin_int); + /* ensure at least we have a default set of IO routines */ dm9000_set_io(db, iosize); diff --git a/include/linux/dm9000.h b/include/linux/dm9000.h index c30879cf93bc..15ace65f982b 100644 --- a/include/linux/dm9000.h +++ b/include/linux/dm9000.h @@ -29,6 +29,12 @@ struct dm9000_plat_data { unsigned int flags; unsigned char dev_addr[6]; + unsigned int pin_int; + //gpio init&deinit + int (*net_gpio_set)(void); + void (*net_gpio_free)(void); + + /* allow replacement IO routines */ void (*inblk)(void __iomem *reg, void *data, int len); -- 2.34.1