/* * dm355evm_msp.c - driver for MSP430 firmware on DM355EVM board * * Copyright (C) 2008 David Brownell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include #include #include #include #include #include #include #include #include #include /* * The DM355 is a DaVinci chip with video support but no C64+ DSP. Its * EVM board has an MSP430 programmed with firmware for various board * support functions. This driver exposes some of them directly, and * supports other drivers (e.g. RTC, input) for more complex access. * * Because this firmware is entirely board-specific, this file embeds * knowledge that would be passed as platform_data in a generic driver. * * This driver was tested with firmware revision A4. */ #if defined(CONFIG_INPUT_DM355EVM) || defined(CONFIG_INPUT_DM355EVM_MODULE) #define msp_has_keyboard() true #else #define msp_has_keyboard() false #endif #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) #define msp_has_leds() true #else #define msp_has_leds() false #endif #if defined(CONFIG_RTC_DRV_DM355EVM) || defined(CONFIG_RTC_DRV_DM355EVM_MODULE) #define msp_has_rtc() true #else #define msp_has_rtc() false #endif #if defined(CONFIG_VIDEO_TVP514X) || defined(CONFIG_VIDEO_TVP514X_MODULE) #define msp_has_tvp() true #else #define msp_has_tvp() false #endif /*----------------------------------------------------------------------*/ /* REVISIT for paranoia's sake, retry reads/writes on error */ static struct i2c_client *msp430; /** * dm355evm_msp_write - Writes a register in dm355evm_msp * @value: the value to be written * @reg: register address * * Returns result of operation - 0 is success, else negative errno */ int dm355evm_msp_write(u8 value, u8 reg) { return i2c_smbus_write_byte_data(msp430, reg, value); } EXPORT_SYMBOL(dm355evm_msp_write); /** * dm355evm_msp_read - Reads a register from dm355evm_msp * @reg: register address * * Returns result of operation - value, or negative errno */ int dm355evm_msp_read(u8 reg) { return i2c_smbus_read_byte_data(msp430, reg); } EXPORT_SYMBOL(dm355evm_msp_read); /*----------------------------------------------------------------------*/ /* * Many of the msp430 pins are just used as fixed-direction GPIOs. * We could export a few more of them this way, if we wanted. */ #define MSP_GPIO(bit, reg) ((DM355EVM_MSP_ ## reg) << 3 | (bit)) static const u8 msp_gpios[] = { /* eight leds */ MSP_GPIO(0, LED), MSP_GPIO(1, LED), MSP_GPIO(2, LED), MSP_GPIO(3, LED), MSP_GPIO(4, LED), MSP_GPIO(5, LED), MSP_GPIO(6, LED), MSP_GPIO(7, LED), /* SW6 and the NTSC/nPAL jumper */ MSP_GPIO(0, SWITCH1), MSP_GPIO(1, SWITCH1), MSP_GPIO(2, SWITCH1), MSP_GPIO(3, SWITCH1), MSP_GPIO(4, SWITCH1), /* switches on MMC/SD sockets */ /* * 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, for 0 and 1 instance respectively. The pdf also * suggests that Bit 1 and 3 should be checked for write protection. * However on the EVM bit 2 and 4 gives this status,for 0 and 1 * instance respectively. */ MSP_GPIO(2, SDMMC), MSP_GPIO(1, SDMMC), /* mmc0 WP, nCD */ MSP_GPIO(4, SDMMC), MSP_GPIO(3, SDMMC), /* mmc1 WP, nCD */ }; #define MSP_GPIO_REG(offset) (msp_gpios[(offset)] >> 3) #define MSP_GPIO_MASK(offset) BIT(msp_gpios[(offset)] & 0x07) static int msp_gpio_in(struct gpio_chip *chip, unsigned offset) { switch (MSP_GPIO_REG(offset)) { case DM355EVM_MSP_SWITCH1: case DM355EVM_MSP_SWITCH2: case DM355EVM_MSP_SDMMC: return 0; default: return -EINVAL; } } static u8 msp_led_cache; static int msp_gpio_get(struct gpio_chip *chip, unsigned offset) { int reg, status; reg = MSP_GPIO_REG(offset); status = dm355evm_msp_read(reg); if (status < 0) return status; if (reg == DM355EVM_MSP_LED) msp_led_cache = status; return status & MSP_GPIO_MASK(offset); } static int msp_gpio_out(struct gpio_chip *chip, unsigned offset, int value) { int mask, bits; /* NOTE: there are some other signals that could be * packaged as output GPIOs, but they aren't as useful * as the LEDs ... so for now we don't. */ if (MSP_GPIO_REG(offset) != DM355EVM_MSP_LED) return -EINVAL; mask = MSP_GPIO_MASK(offset); bits = msp_led_cache; bits &= ~mask; if (value) bits |= mask; msp_led_cache = bits; return dm355evm_msp_write(bits, DM355EVM_MSP_LED); } static void msp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { msp_gpio_out(chip, offset, value); }