From patchwork Wed Jul 22 06:18:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Bhandari X-Patchwork-Id: 36714 Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6M7He09032619 for ; Wed, 22 Jul 2009 07:17:41 GMT Received: from dlep35.itg.ti.com ([157.170.170.118]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id n6M79Use025346; Wed, 22 Jul 2009 02:09:35 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by dlep35.itg.ti.com (8.13.7/8.13.7) with ESMTP id n6M79TC7007872; Wed, 22 Jul 2009 02:09:29 -0500 (CDT) Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 5D9DE80627; Wed, 22 Jul 2009 02:09:29 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp53.itg.ti.com (dflp53.itg.ti.com [128.247.5.6]) by linux.omap.com (Postfix) with ESMTP id DEB3F80626 for ; Wed, 22 Jul 2009 02:09:26 -0500 (CDT) Received: from tidmzi-ftp.india.ext.ti.com (localhost [127.0.0.1]) by dflp53.itg.ti.com (8.13.8/8.13.8) with SMTP id n6M79P6e022136 for ; Wed, 22 Jul 2009 02:09:25 -0500 (CDT) Received: from symphonyindia.ti.com (symphony-ftp [192.168.247.11]) by tidmzi-ftp.india.ext.ti.com (Postfix) with SMTP id F0DDA38878 for ; Wed, 22 Jul 2009 12:36:36 +0530 (IST) Received: from localhost.localdomain ([192.168.247.76]) by symphonyindia.ti.com (8.13.1/8.12.10) with ESMTP id n6M73sxm027413; Wed, 22 Jul 2009 12:33:54 +0530 From: Vipin Bhandari To: davinci-linux-open-source@linux.davincidsp.com Date: Wed, 22 Jul 2009 02:18:24 -0400 Message-Id: <1248243504-8384-1-git-send-email-vipin.bhandari@ti.com> X-Mailer: git-send-email 1.5.6 Cc: Subject: [PATCH] davinci: Correct ro and cd feature in DM355 X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.4 Precedence: list List-Id: davinci-linux-open-source.linux.davincidsp.com List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: davinci-linux-open-source-bounces@linux.davincidsp.com Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com This patch corrects the support for MMCSD card detection and read only feature for SoC DM355. Signed-off-by: Vipin Bhandari --- This patch has been tested on DM355 EVM. arch/arm/mach-davinci/board-dm355-evm.c | 107 +++++++++++++++++++++++------- 1 files changed, 82 insertions(+), 25 deletions(-) diff --git a/arch/arm/mach-davinci/board-dm355-evm.c b/arch/arm/mach-davinci/board-dm355-evm.c index ff55c52..92c3781 100644 --- a/arch/arm/mach-davinci/board-dm355-evm.c +++ b/arch/arm/mach-davinci/board-dm355-evm.c @@ -113,6 +113,37 @@ static struct platform_device davinci_nand_device = { }, }; + +/* + * MSP430 supports card detection and write protection checking + */ +static struct i2c_client *dm355evm_msp; + +static int dm355evm_msp_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + dm355evm_msp = client; + return 0; +} + +static int dm355evm_msp_remove(struct i2c_client *client) +{ + dm355evm_msp = NULL; + return 0; +} + +static const struct i2c_device_id dm355evm_msp_ids[] = { + { "dm355evm_msp", 0, }, + { /* end of list */ }, +}; + +static struct i2c_driver dm355evm_msp_driver = { + .driver.name = "dm355evm_msp", + .id_table = dm355evm_msp_ids, + .probe = dm355evm_msp_probe, + .remove = dm355evm_msp_remove, +}; + static struct davinci_i2c_platform_data i2c_pdata = { .bus_freq = 400 /* kHz */, .bus_delay = 0 /* usec */, @@ -120,25 +151,9 @@ static struct davinci_i2c_platform_data i2c_pdata = { static struct snd_platform_data dm355_evm_snd_data; -static int dm355evm_mmc_gpios = -EINVAL; - -static void dm355evm_mmcsd_gpios(unsigned gpio) -{ - gpio_request(gpio + 0, "mmc0_ro"); - gpio_request(gpio + 1, "mmc0_cd"); - gpio_request(gpio + 2, "mmc1_ro"); - gpio_request(gpio + 3, "mmc1_cd"); - /* we "know" these are input-only so we don't - * need to call gpio_direction_input() - */ - - dm355evm_mmc_gpios = gpio; -} - -static struct i2c_board_info dm355evm_i2c_info[] = { +static struct i2c_board_info __initdata dm355evm_i2c_info[] = { { I2C_BOARD_INFO("dm355evm_msp", 0x25), - .platform_data = dm355evm_mmcsd_gpios, /* plus irq */ }, /* { I2C_BOARD_INFO("tlv320aic3x", 0x1b), }, */ /* { I2C_BOARD_INFO("tvp5146", 0x5d), }, */ @@ -152,6 +167,8 @@ static void __init evm_init_i2c(void) gpio_direction_input(5); dm355evm_i2c_info[0].irq = gpio_to_irq(5); + i2c_add_driver(&dm355evm_msp_driver); + i2c_register_board_info(1, dm355evm_i2c_info, ARRAY_SIZE(dm355evm_i2c_info)); } @@ -194,20 +211,60 @@ static void __init dm355_evm_map_io(void) dm355_init(); } -static int dm355evm_mmc_get_cd(int module) +static int dm355evm_msp430_get_pins(void) { - if (!gpio_is_valid(dm355evm_mmc_gpios)) + static const char txbuf[1] = {0x06}; + char buf[1]; + struct i2c_msg msg[2] = { + { + .addr = dm355evm_msp->addr, + .flags = 0, + .len = 1, + .buf = (void __force *)txbuf, + }, + { + .addr = dm355evm_msp->addr, + .flags = I2C_M_RD, + .len = 1, + .buf = buf, + }, + }; + int status; + + if (!dm355evm_msp) return -ENXIO; - /* low == card present */ - return !gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 1); + + status = i2c_transfer(dm355evm_msp->adapter, msg, 2); + if (status < 0) + return status; + + return buf[0]; +} + +static int dm355evm_mmc_get_cd(int module) +{ + int status = dm355evm_msp430_get_pins(); + /* Bit value low == card present */ + /* Note: EVMDM355_ECP_VA4.pdf suggests that Bit 2 and 4 should + * be checked for card detection. However on the EVM bit 1 and 3 gives + * this status, respectively for 0 and 1 instance */ + if (module == 0) + return (status < 0) ? status : !(status & BIT(1)); + else + return (status < 0) ? status : !(status & BIT(3)); } static int dm355evm_mmc_get_ro(int module) { - if (!gpio_is_valid(dm355evm_mmc_gpios)) - return -ENXIO; - /* high == card's write protect switch active */ - return gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 0); + int status = dm355evm_msp430_get_pins(); + /* Bit value high == card's write protect switch active */ + /* Note: EVMDM355_ECP_VA4.pdf suggests that Bit 1 and 3 should + * be checked for card detection. However on the EVM bit 2 and 4 gives + * this status, respectively for 0 and 1 instance */ + if (module == 0) + return (status < 0) ? status : status & BIT(2); + else + return (status < 0) ? status : status & BIT(4); } static struct davinci_mmc_config dm355evm_mmc_config = {