From 937eb4bb00588571f223eade260f9b509bf223ab Mon Sep 17 00:00:00 2001 From: Janusz Krzysztofik Date: Tue, 20 Dec 2011 03:24:21 +0100 Subject: ARM: OMAP1: ams-delta: convert latches to basic_mmio_gpio Once ready, ams-delta specific device drivers currently calling custom ams_delta_latch[12]_write() functions can be updated to call generic gpio_set_value() instead, which will make them less platform dependent. Even more, some custom ams-delta only drivers can perhaps be dropped from the tree after converting selected ams-delta platform devices to follow generic GPIO based device models. The latch_gpios[] table is initially filled with all latch1 and latch2 GPIO pins in order to register and initialize them from the board file until those are handled by respective existing device drivers (leds, nand, lcd, serio, asoc, serial). That table will get almost empty after the transision process is completed, holding only pins not used by any drivers / connected to unused devices, in order to initialize them from the board file for power saving purposes. The new ams_delta_latch_write() function is a unified replacement for those removed ams_delta_latch[12]_write(), and serves as a temporary wrapper over gpio_set_value(), providing the old API for those not yet updated device drivers, and will be removed after all custom drivers are converted or replaced. Signed-off-by: Janusz Krzysztofik Signed-off-by: Tony Lindgren --- arch/arm/mach-omap1/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'arch/arm/mach-omap1/Kconfig') diff --git a/arch/arm/mach-omap1/Kconfig b/arch/arm/mach-omap1/Kconfig index 4f8d66f044e7..e14532f236a0 100644 --- a/arch/arm/mach-omap1/Kconfig +++ b/arch/arm/mach-omap1/Kconfig @@ -155,6 +155,7 @@ config MACH_AMS_DELTA bool "Amstrad E3 (Delta)" depends on ARCH_OMAP1 && ARCH_OMAP15XX select FIQ + select GPIO_GENERIC_PLATFORM help Support for the Amstrad E3 (codename Delta) videophone. Say Y here if you have such a device. -- cgit v1.2.3-55-g7522 From 5ca6180fa6d7333fb5fabf30420b0e3cc32dd731 Mon Sep 17 00:00:00 2001 From: Janusz Krzysztofik Date: Tue, 20 Dec 2011 00:08:53 +0100 Subject: ARM: OMAP1: ams-delta: supersede custom led device by leds-gpio Now that the Amstrad Delta on-board latches have been converted to GPIO devices, use the generic driver to control on-board LEDs which hang off those latches. Signed-off-by: Janusz Krzysztofik Signed-off-by: Tony Lindgren --- arch/arm/mach-omap1/Kconfig | 1 + arch/arm/mach-omap1/board-ams-delta.c | 87 +++++++++++++---------- arch/arm/plat-omap/include/plat/board-ams-delta.h | 19 ----- 3 files changed, 49 insertions(+), 58 deletions(-) (limited to 'arch/arm/mach-omap1/Kconfig') diff --git a/arch/arm/mach-omap1/Kconfig b/arch/arm/mach-omap1/Kconfig index e14532f236a0..5b1edbae6893 100644 --- a/arch/arm/mach-omap1/Kconfig +++ b/arch/arm/mach-omap1/Kconfig @@ -156,6 +156,7 @@ config MACH_AMS_DELTA depends on ARCH_OMAP1 && ARCH_OMAP15XX select FIQ select GPIO_GENERIC_PLATFORM + select LEDS_GPIO_REGISTER help Support for the Amstrad E3 (codename Delta) videophone. Say Y here if you have such a device. diff --git a/arch/arm/mach-omap1/board-ams-delta.c b/arch/arm/mach-omap1/board-ams-delta.c index cff2711dc259..034d0094e93a 100644 --- a/arch/arm/mach-omap1/board-ams-delta.c +++ b/arch/arm/mach-omap1/board-ams-delta.c @@ -164,18 +164,21 @@ static struct omap_board_config_kernel ams_delta_config[] __initdata = { { OMAP_TAG_LCD, &ams_delta_lcd_config }, }; +#define LATCH1_GPIO_BASE 232 +#define LATCH1_NGPIO 8 + static struct resource latch1_resources[] __initconst = { [0] = { .name = "dat", .start = LATCH1_PHYS, - .end = LATCH1_PHYS + (AMS_DELTA_LATCH1_NGPIO - 1) / 8, + .end = LATCH1_PHYS + (LATCH1_NGPIO - 1) / 8, .flags = IORESOURCE_MEM, }, }; static struct bgpio_pdata latch1_pdata __initconst = { - .base = AMS_DELTA_LATCH1_GPIO_BASE, - .ngpio = AMS_DELTA_LATCH1_NGPIO, + .base = LATCH1_GPIO_BASE, + .ngpio = LATCH1_NGPIO, }; static struct platform_device latch1_gpio_device = { @@ -214,42 +217,12 @@ static struct platform_device latch2_gpio_device = { static struct gpio latch_gpios[] __initconst = { { - .gpio = AMS_DELTA_GPIO_PIN_LED_CAMERA, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led_camera", - }, - { - .gpio = AMS_DELTA_GPIO_PIN_LED_ADVERT, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led_advert", - }, - { - .gpio = AMS_DELTA_GPIO_PIN_LED_EMAIL, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led_email", - }, - { - .gpio = AMS_DELTA_GPIO_PIN_LED_HANDSFREE, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led_handsfree", - }, - { - .gpio = AMS_DELTA_GPIO_PIN_LED_VOICEMAIL, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led_voicemail", - }, - { - .gpio = AMS_DELTA_GPIO_PIN_LED_VOICE, - .flags = GPIOF_OUT_INIT_LOW, - .label = "led_voice", - }, - { - .gpio = AMS_DELTA_LATCH1_GPIO_BASE + 6, + .gpio = LATCH1_GPIO_BASE + 6, .flags = GPIOF_OUT_INIT_LOW, .label = "dockit1", }, { - .gpio = AMS_DELTA_LATCH1_GPIO_BASE + 7, + .gpio = LATCH1_GPIO_BASE + 7, .flags = GPIOF_OUT_INIT_LOW, .label = "dockit2", }, @@ -399,9 +372,45 @@ static struct platform_device ams_delta_lcd_device = { .id = -1, }; -static struct platform_device ams_delta_led_device = { - .name = "ams-delta-led", - .id = -1 +static struct gpio_led gpio_leds[] __initconst = { + { + .name = "camera", + .gpio = LATCH1_GPIO_BASE + 0, + .default_state = LEDS_GPIO_DEFSTATE_OFF, +#ifdef CONFIG_LEDS_TRIGGERS + .default_trigger = "ams_delta_camera", +#endif + }, + { + .name = "advert", + .gpio = LATCH1_GPIO_BASE + 1, + .default_state = LEDS_GPIO_DEFSTATE_OFF, + }, + { + .name = "email", + .gpio = LATCH1_GPIO_BASE + 2, + .default_state = LEDS_GPIO_DEFSTATE_OFF, + }, + { + .name = "handsfree", + .gpio = LATCH1_GPIO_BASE + 3, + .default_state = LEDS_GPIO_DEFSTATE_OFF, + }, + { + .name = "voicemail", + .gpio = LATCH1_GPIO_BASE + 4, + .default_state = LEDS_GPIO_DEFSTATE_OFF, + }, + { + .name = "voice", + .gpio = LATCH1_GPIO_BASE + 5, + .default_state = LEDS_GPIO_DEFSTATE_OFF, + }, +}; + +static struct gpio_led_platform_data leds_pdata __initconst = { + .leds = gpio_leds, + .num_leds = ARRAY_SIZE(gpio_leds), }; static struct i2c_board_info ams_delta_camera_board_info[] = { @@ -459,7 +468,6 @@ static struct platform_device *ams_delta_devices[] __initdata = { static struct platform_device *late_devices[] __initconst = { &ams_delta_nand_device, &ams_delta_lcd_device, - &ams_delta_led_device, }; static void __init ams_delta_init(void) @@ -493,6 +501,7 @@ static void __init ams_delta_init(void) led_trigger_register_simple("ams_delta_camera", &ams_delta_camera_led_trigger); #endif + gpio_led_register_device(-1, &leds_pdata); platform_add_devices(ams_delta_devices, ARRAY_SIZE(ams_delta_devices)); ams_delta_init_fiq(); diff --git a/arch/arm/plat-omap/include/plat/board-ams-delta.h b/arch/arm/plat-omap/include/plat/board-ams-delta.h index 68ffe328a777..a0f86ca75ddc 100644 --- a/arch/arm/plat-omap/include/plat/board-ams-delta.h +++ b/arch/arm/plat-omap/include/plat/board-ams-delta.h @@ -28,13 +28,6 @@ #if defined (CONFIG_MACH_AMS_DELTA) -#define AMS_DELTA_LATCH1_LED_CAMERA 0x01 -#define AMS_DELTA_LATCH1_LED_ADVERT 0x02 -#define AMS_DELTA_LATCH1_LED_EMAIL 0x04 -#define AMS_DELTA_LATCH1_LED_HANDSFREE 0x08 -#define AMS_DELTA_LATCH1_LED_VOICEMAIL 0x10 -#define AMS_DELTA_LATCH1_LED_VOICE 0x20 - #define AMS_DELTA_LATCH2_LCD_VBLEN 0x0001 #define AMS_DELTA_LATCH2_LCD_NDISP 0x0002 #define AMS_DELTA_LATCH2_NAND_NCE 0x0004 @@ -59,13 +52,6 @@ #define AMS_DELTA_GPIO_PIN_CONFIG 11 #define AMS_DELTA_GPIO_PIN_NAND_RB 12 -#define AMS_DELTA_GPIO_PIN_LED_CAMERA 232 -#define AMS_DELTA_GPIO_PIN_LED_ADVERT 233 -#define AMS_DELTA_GPIO_PIN_LED_EMAIL 234 -#define AMS_DELTA_GPIO_PIN_LED_HANDSFREE 235 -#define AMS_DELTA_GPIO_PIN_LED_VOICEMAIL 236 -#define AMS_DELTA_GPIO_PIN_LED_VOICE 237 - #define AMS_DELTA_GPIO_PIN_LCD_VBLEN 240 #define AMS_DELTA_GPIO_PIN_LCD_NDISP 241 #define AMS_DELTA_GPIO_PIN_NAND_NCE 242 @@ -81,16 +67,11 @@ #define AMS_DELTA_GPIO_PIN_MODEM_NRESET 252 #define AMS_DELTA_GPIO_PIN_MODEM_CODEC 253 -#define AMS_DELTA_LATCH1_GPIO_BASE AMS_DELTA_GPIO_PIN_LED_CAMERA -#define AMS_DELTA_LATCH1_NGPIO 8 #define AMS_DELTA_LATCH2_GPIO_BASE AMS_DELTA_GPIO_PIN_LCD_VBLEN #define AMS_DELTA_LATCH2_NGPIO 16 #ifndef __ASSEMBLY__ void ams_delta_latch_write(int base, int ngpio, u16 mask, u16 value); -#define ams_delta_latch1_write(mask, value) \ - ams_delta_latch_write(AMS_DELTA_LATCH1_GPIO_BASE, \ - AMS_DELTA_LATCH1_NGPIO, (mask), (value)) #define ams_delta_latch2_write(mask, value) \ ams_delta_latch_write(AMS_DELTA_LATCH2_GPIO_BASE, \ AMS_DELTA_LATCH2_NGPIO, (mask), (value)) -- cgit v1.2.3-55-g7522 From ac2885df30e2597d627ad619c01b6fc55ac540a7 Mon Sep 17 00:00:00 2001 From: Janusz Krzysztofik Date: Mon, 5 Mar 2012 17:05:10 +0100 Subject: ARM: OMAP1: ams-delta: set up regulator over modem reset GPIO pin The Amstrad Delta on-board latch2 bit named MODEM_NRESET, now available as a GPIO pin AMS_DELTA_GPIO_PIN_NMODEM_RESET, is used to power up/down (bring into/out of a reset state) two distinct on-board devices simultaneously: the modem, and the voice codec. As a consequence, that bit is, or can be, manipulated concurrently by two drivers, or their platform provided hooks. Instead of updating those drivers to use the gpiolib API as a new method of controlling the MODEM_NRESET pin state, like it was done to other drivers accessing latch2 pins, and still being vulnerable to potential concurrency conflicts, or trying to solve that sharing issue with a custom piece of code, set up a fixed regulator device on top of that GPIO pin, with the intention of updating both drivers to manipulate that regulator, not the GPIO pin directly. Before the ASoC driver is updated and the modem platform data expanded with a power management callback for switching its power, the ams_delta_latch_write() function, which still provides the old API for accessing latch2 functionality from not updated drivers, is modified to toggle the regulator instead of the MODEM_NRESET GPIO pin. A helper function provided for balancing the regulator enable/disable operations, together with the consumer data needed for tracking the regulator state, will be removed once the drivers are updated. Depends on patch series "ARM: OMAP1: ams-delta: replace custom I/O with GPIO". Signed-off-by: Janusz Krzysztofik Signed-off-by: Tony Lindgren --- arch/arm/mach-omap1/Kconfig | 2 + arch/arm/mach-omap1/board-ams-delta.c | 104 ++++++++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 6 deletions(-) (limited to 'arch/arm/mach-omap1/Kconfig') diff --git a/arch/arm/mach-omap1/Kconfig b/arch/arm/mach-omap1/Kconfig index 5b1edbae6893..4b6a774606cb 100644 --- a/arch/arm/mach-omap1/Kconfig +++ b/arch/arm/mach-omap1/Kconfig @@ -157,6 +157,8 @@ config MACH_AMS_DELTA select FIQ select GPIO_GENERIC_PLATFORM select LEDS_GPIO_REGISTER + select REGULATOR + select REGULATOR_FIXED_VOLTAGE help Support for the Amstrad E3 (codename Delta) videophone. Say Y here if you have such a device. diff --git a/arch/arm/mach-omap1/board-ams-delta.c b/arch/arm/mach-omap1/board-ams-delta.c index ce50fe137269..949997c35707 100644 --- a/arch/arm/mach-omap1/board-ams-delta.c +++ b/arch/arm/mach-omap1/board-ams-delta.c @@ -18,7 +18,11 @@ #include #include #include +#include #include +#include +#include +#include #include #include @@ -236,11 +240,6 @@ static const struct gpio latch_gpios[] __initconst = { .flags = GPIOF_OUT_INIT_LOW, .label = "scard_cmdvcc", }, - { - .gpio = AMS_DELTA_GPIO_PIN_MODEM_NRESET, - .flags = GPIOF_OUT_INIT_LOW, - .label = "modem_nreset", - }, { .gpio = AMS_DELTA_GPIO_PIN_MODEM_CODEC, .flags = GPIOF_OUT_INIT_LOW, @@ -258,6 +257,71 @@ static const struct gpio latch_gpios[] __initconst = { }, }; +static struct regulator_consumer_supply modem_nreset_consumers[] = { + REGULATOR_SUPPLY("RESET#", "serial8250.1"), + REGULATOR_SUPPLY("POR", "cx20442-codec"), +}; + +static struct regulator_init_data modem_nreset_data = { + .constraints = { + .valid_ops_mask = REGULATOR_CHANGE_STATUS, + .boot_on = 1, + }, + .num_consumer_supplies = ARRAY_SIZE(modem_nreset_consumers), + .consumer_supplies = modem_nreset_consumers, +}; + +static struct fixed_voltage_config modem_nreset_config = { + .supply_name = "modem_nreset", + .microvolts = 3300000, + .gpio = AMS_DELTA_GPIO_PIN_MODEM_NRESET, + .startup_delay = 25000, + .enable_high = 1, + .enabled_at_boot = 1, + .init_data = &modem_nreset_data, +}; + +static struct platform_device modem_nreset_device = { + .name = "reg-fixed-voltage", + .id = -1, + .dev = { + .platform_data = &modem_nreset_config, + }, +}; + +struct modem_private_data { + struct regulator *regulator; + struct { + struct mutex lock; + bool enabled; + } consumer; +}; + +static int regulator_toggle(struct modem_private_data *priv, bool enable) +{ + int err = 0; + + mutex_lock(&priv->consumer.lock); + if (IS_ERR(priv->regulator)) { + err = PTR_ERR(priv->regulator); + } else if (enable) { + if (!priv->consumer.enabled) { + err = regulator_enable(priv->regulator); + priv->consumer.enabled = true; + } + } else { + if (priv->consumer.enabled) { + err = regulator_disable(priv->regulator); + priv->consumer.enabled = false; + } + } + mutex_unlock(&priv->consumer.lock); + + return err; +} + +static struct modem_private_data modem_priv; + void ams_delta_latch_write(int base, int ngpio, u16 mask, u16 value) { int bit = 0; @@ -266,7 +330,10 @@ void ams_delta_latch_write(int base, int ngpio, u16 mask, u16 value) for (; bit < ngpio; bit++, bitpos = bitpos << 1) { if (!(mask & bitpos)) continue; - gpio_set_value(base + bit, (value & bitpos) != 0); + else if (base + bit == AMS_DELTA_GPIO_PIN_MODEM_NRESET) + regulator_toggle(&modem_priv, (value & bitpos) != 0); + else + gpio_set_value(base + bit, (value & bitpos) != 0); } } EXPORT_SYMBOL(ams_delta_latch_write); @@ -496,6 +563,12 @@ static int __init late_init(void) platform_add_devices(late_devices, ARRAY_SIZE(late_devices)); + err = platform_device_register(&modem_nreset_device); + if (err) { + pr_err("Couldn't register the modem regulator device\n"); + return err; + } + omap_cfg_reg(M14_1510_GPIO2); ams_delta_modem_ports[0].irq = gpio_to_irq(AMS_DELTA_GPIO_PIN_MODEM_IRQ); @@ -507,6 +580,10 @@ static int __init late_init(void) } gpio_direction_input(AMS_DELTA_GPIO_PIN_MODEM_IRQ); + /* Initialize the modem_nreset regulator consumer before use */ + mutex_init(&modem_priv.consumer.lock); + modem_priv.regulator = ERR_PTR(-ENODEV); + ams_delta_latch2_write( AMS_DELTA_LATCH2_MODEM_NRESET | AMS_DELTA_LATCH2_MODEM_CODEC, AMS_DELTA_LATCH2_MODEM_NRESET | AMS_DELTA_LATCH2_MODEM_CODEC); @@ -514,8 +591,23 @@ static int __init late_init(void) err = platform_device_register(&ams_delta_modem_device); if (err) goto gpio_free; + + /* + * Once the modem device is registered, the modem_nreset + * regulator can be requested on behalf of that device. + * The regulator is used via ams_delta_latch_write() + * by the modem and ASoC drivers until updated. + */ + modem_priv.regulator = regulator_get(&ams_delta_modem_device.dev, + "RESET#"); + if (IS_ERR(modem_priv.regulator)) { + err = PTR_ERR(modem_priv.regulator); + goto unregister; + } return 0; +unregister: + platform_device_unregister(&ams_delta_modem_device); gpio_free: gpio_free(AMS_DELTA_GPIO_PIN_MODEM_IRQ); return err; -- cgit v1.2.3-55-g7522