ARM: gta02: Add Button, LED and Vibrator support
Subsystems (2)
This patch series adds button, LED and vibrator support for the GTA02 Openmoko Freerunner smartphone.
PATCH 1/1 ARM: gta02: Add button support
The gta02 has two buttons which are connected to gpio pins and thus can get supported by using the generic gpio-keys driver.
--- arch/arm/mach-s3c2442/mach-gta02.c | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
arch/arm/mach-s3c2442/mach-gta02.c +33 -0
@@ -58,6 +58,8 @@#include <linux/mfd/pcf50633/gpio.h> #include <linux/mfd/pcf50633/pmic.h> +#include <linux/gpio_keys.h> +#include <asm/mach/arch.h> #include <asm/mach/map.h> #include <asm/mach/irq.h>
@@ -550,6 +552,36 @@ static struct s3c2410_hcd_info gta02_usb_info = { }, }; +/* Buttons */ +static struct gpio_keys_button gta02_buttons[] = { + { + .gpio =GTA02_GPIO_AUX_KEY , + .code =KEY_PHONE , + .desc ="Aux" , + .type =EV_KEY , + .debounce_interval =100 , + }, + { + .gpio =GTA02_GPIO_HOLD_KEY , + .code =KEY_PAUSE , + .desc ="Hold" , + .type =EV_KEY , + .debounce_interval =100 , + }, +}; + +static struct gpio_keys_platform_data gta02_buttons_pdata = { + .buttons = gta02_buttons, + .nbuttons =ARRAY_SIZE (gta02_buttons), +}; + +static struct platform_device gta02_buttons_device = { + .name ="gpio-keys" , + .id =-1 , + .dev = { + .platform_data = >a02_buttons_pdata, + }, +};static void __init gta02_map_io (void ) {
@@ -571,6 +603,7 @@ static struct platform_device *gta02_devices[] __initdata = { &s3c24xx_pwm_device, &s3c_device_iis, &s3c_device_i2c0, + >a02_buttons_device, };/* These guys DO need to be children of PMU. */
Signature · 1 line
1.5.6.5
PATCH 1/1 ARM: gta02: Add LED support
This patch adds support for the LEDs found on the gta02 smartphone. There are three leds in total. Two of the are going to be controlled by leds-pwm driver. One by the leds-gpio driver.
In theory all LEDs could be driven by the pwm driver, but one the pwm timers is needed for other purposes, so we stick to a simple gpio driven led here.
--- arch/arm/mach-s3c2442/mach-gta02.c | 70 ++++++++++++++++++++++++++++++++--- 1 files changed, 64 insertions(+), 6 deletions(-)
arch/arm/mach-s3c2442/mach-gta02.c +64 -6
@@ -60,6 +60,9 @@#include <linux/gpio_keys.h> +#include <linux/leds.h> +#include <linux/leds_pwm.h> +#include <asm/mach/arch.h> #include <asm/mach/map.h> #include <asm/mach/irq.h>
@@ -409,11 +412,6 @@ static struct platform_device gta02_nor_flash = { }; -struct platform_device s3c24xx_pwm_device = { - .name ="s3c24xx_pwm" , - .num_resources =0 , -}; -static struct i2c_board_info gta02_i2c_devs[]__initdata = { {I2C_BOARD_INFO ("pcf50633" ,0x73 ),
@@ -583,6 +581,61 @@ static struct platform_device gta02_buttons_device = { }, }; +/* LEDs */ +static struct gpio_led gta02_gpio_leds[] = { + { + .name ="gta02:red:aux" , + .gpio =GTA02_GPIO_AUX_LED , + }, +}; + +static struct gpio_led_platform_data gta02_gpio_leds_pdata = { + .leds = gta02_gpio_leds, + .num_leds =ARRAY_SIZE (gta02_gpio_leds), +}; + +static struct platform_device gta02_leds_device = { + .name ="leds-gpio" , + .id =-1 , + .dev = { + .platform_data = >a02_gpio_leds_pdata, + }, +}; + +static struct led_pwm gta02_pwm_leds[] = { + { + .name ="gta02:orange:power" , + .max_brightness =0xff , + .pwm_period_ns =1000000 , + .pwm_id =0 , + }, + { + .name ="gta02:blue:power" , + .max_brightness =0xff , + .pwm_period_ns =1000000 , + .pwm_id =1 , + }, +}; + +static struct led_pwm_platform_data gta02_pwm_leds_pdata = { + .num_leds =ARRAY_SIZE (gta02_pwm_leds), + .leds = gta02_pwm_leds, +}; + +static struct platform_device gta02_pwm_leds_device = { + .name ="leds_pwm" , + .id =-1 , + .dev = { + .platform_data = >a02_pwm_leds_pdata, + } +}; + +static void gta02_enable_pwm_pins (void ) +{ +s3c2410_gpio_cfgpin (GTA02_GPIO_PWR_LED1 ,S3C2410_GPB0_TOUT0 ); +s3c2410_gpio_cfgpin (GTA02_GPIO_PWR_LED2 ,S3C2410_GPB1_TOUT1 ); +} +static void __init gta02_map_io (void ) {s3c24xx_init_io (gta02_iodesc,ARRAY_SIZE (gta02_iodesc));
@@ -600,10 +653,13 @@ static struct platform_device *gta02_devices[] __initdata = { &s3c_device_usbgadget, &s3c_device_nand, >a02_nor_flash, - &s3c24xx_pwm_device, + &s3c_device_timer[0 ], + &s3c_device_timer[1 ], &s3c_device_iis, &s3c_device_i2c0, >a02_buttons_device, + >a02_leds_device, + >a02_pwm_leds_device, };/* These guys DO need to be children of PMU. */
@@ -662,6 +718,8 @@ static void __init gta02_machine_init(void)i2c_register_board_info (0 , gta02_i2c_devs,ARRAY_SIZE (gta02_i2c_devs));platform_add_devices (gta02_devices,ARRAY_SIZE (gta02_devices)); +gta02_enable_pwm_pins (); + pm_power_off = gta02_poweroff; }
Signature · 1 line
1.5.6.5
PATCH 1/1 ARM: gta02: Add vibrator support
The vibrator found on the gta02 is controlled by the s3c pwm controller. Instead of writing a special vibrator driver/class the vibrator is represented as a led device.
--- arch/arm/mach-s3c2442/mach-gta02.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
arch/arm/mach-s3c2442/mach-gta02.c +8 -0
@@ -615,6 +615,12 @@ static struct led_pwm gta02_pwm_leds[] = { .pwm_period_ns = 1000000, .pwm_id = 1, }, + { + .name = "gta02::vibrator", + .max_brightness = 0x3f, + .pwm_period_ns = 60000000, + .pwm_id = 3, + } }; static struct led_pwm_platform_data gta02_pwm_leds_pdata = {
@@ -634,6 +640,7 @@ static void gta02_enable_pwm_pins(void) {s3c2410_gpio_cfgpin (GTA02_GPIO_PWR_LED1 ,S3C2410_GPB0_TOUT0 );s3c2410_gpio_cfgpin (GTA02_GPIO_PWR_LED2 ,S3C2410_GPB1_TOUT1 ); +s3c2410_gpio_cfgpin (GTA02_GPIO_VIBRATOR_ON ,S3C2410_GPB3_TOUT3 ); }static void __init gta02_map_io (void )
@@ -655,6 +662,7 @@ static struct platform_device *gta02_devices[] __initdata = { >a02_nor_flash, &s3c_device_timer[0 ], &s3c_device_timer[1 ], + &s3c_device_timer[3 ], &s3c_device_iis, &s3c_device_i2c0, >a02_buttons_device,
Signature · 1 line
1.5.6.5
PATCH 1/1 ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier
On gta02 hardware revision 5 and earlier the basis resistors for transistors of the leds are missing and reading their gpio pin status will always return 0. So we have to shadow the led states in software. This is done by "hijacking" the gpio accessor functions for bank B.
--- arch/arm/mach-s3c2442/mach-gta02.c | 54 ++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-)
arch/arm/mach-s3c2442/mach-gta02.c +54 -0
@@ -90,6 +90,7 @@#include <plat/pm.h> #include <plat/udc.h> #include <plat/gpio-cfg.h> +#include <plat/gpio-core.h> #include <plat/iic.h> static struct pcf50633 *gta02_pcf;
@@ -706,11 +707,64 @@ static void gta02_poweroff(void)pcf50633_reg_set_bit_mask (gta02_pcf,PCF50633_REG_OOCSHDWN ,1 ,1 ); } +/* On hardware rev 5 and earlier the leds are missing a resistor and reading +* from their gpio pins will always return 0, so we have to shadow the +* led states software */ +static unsigned long gpb_shadow; +extern struct s3c_gpio_chip s3c24xx_gpios[]; + +static void gta02_gpb_set (struct gpio_chip *chip, +unsigned offset,int value) +{ +void __iomem *base =S3C24XX_GPIO_BASE (S3C2410_GPB (0 )); +unsigned long flags; +unsigned long dat; + +local_irq_save (flags); + + dat =__raw_readl (base +0x04 ) | gpb_shadow; + dat &= ~(1 << offset); + gpb_shadow &= ~(1 << offset); +if (value) { + dat |=1 << offset; +switch (offset) { + case 0 ... 2: + gpb_shadow |=1 << offset; +break ; +default : +break ; + } + } +__raw_writel (dat, base +0x04 ); + +local_irq_restore (flags); +} + +static int gta02_gpb_get (struct gpio_chip *chip,unsigned offset) +{ +void __iomem *base =S3C24XX_GPIO_BASE (S3C2410_GPB (0 )); +unsigned long val; + + val =__raw_readl (base +0x04 ) | gpb_shadow; + val >>= offset; + val &=1 ; + +return val; +} + +static void gta02_hijack_gpb (void ) +{ + s3c24xx_gpios[1 ].chip.set = gta02_gpb_set; + s3c24xx_gpios[1 ].chip.get = gta02_gpb_get; +} +static void __init gta02_machine_init (void ) {/* Set the panic callback to make AUX LED blink at ~5Hz. */ panic_blink = gta02_panic_blink; +gta02_hijack_gpb (); +s3c_pm_init ();#ifdef CONFIG_CHARGER_PCF50633
Signature · 1 line
1.5.6.5
PATCH 1/1 ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier
Hi!
Quoted 4 lines
On gta02 hardware revision 5 and earlier the basis resistors for transistors of the leds are missing and reading their gpio pin status will always return 0. So we have to shadow the led states in software. This is done by "hijacking" the gpio accessor functions for bank B.
Should that be done in LED driver, instead?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH 1/1 ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier
Quoted 9 lines · Pavel Machek
Hi!
Quoted 5 lines
On gta02 hardware revision 5 and earlier the basis resistors for transistors of the leds are missing and reading their gpio pin status will always return 0. So we have to shadow the led states in software. This is done by "hijacking" the gpio accessor functions for bank B.
Should that be done in LED driver, instead? Pave
Hi
Nope, that won't work. Every time a gpio on gpb is changed the leds will turn off. So we would have to ship a special version of each driver using a gpio pin form gpb. We certainly don't want to do that.
- Lars
PATCH 1/1 ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier
Quoted 9 lines · Lars-Peter Clausen
Quoted 8 lines · Pavel Machek
Hi!
Quoted 5 lines
On gta02 hardware revision 5 and earlier the basis resistors for transistors of the leds are missing and reading their gpio pin status will always return 0. So we have to shadow the led states in software. This is done by "hijacking" the gpio accessor functions for bank B.
Quoted 6 lines
Quoted 1 line
Should that be done in LED driver, instead? Pave
Hi
Nope, that won't work. Every time a gpio on gpb is changed the leds will turn off. So we would have to ship a special version of each driver using a gpio pin form gpb. We certainly don't want to do that.
_Any_ GPIO pin change will turn off the LED? Wow, the hardware is severely misdesigned then, ok. That means you do need to modify GPIO :-(. You probably should state it clearly in the comments.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH 1/1 ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier
Quoted 13 lines · Pavel Machek
Quoted 12 lines · Lars-Peter Clausen
Quoted 9 lines · Pavel Machek
Hi!
Quoted 5 lines
On gta02 hardware revision 5 and earlier the basis resistors for transistors of the leds are missing and reading their gpio pin status will always return 0. So we have to shadow the led states in software. This is done by "hijacking" the gpio accessor functions for bank B.
Should that be done in LED driver, instead? Pave
Hi
Quoted 7 lines
Quoted 3 lines
Nope, that won't work. Every time a gpio on gpb is changed the leds will turn off. So we would have to ship a special version of each driver using a gpio pin form gpb. We certainly don't want to do that.
_Any_ GPIO pin change will turn off the LED? Wow, the hardware is severely misdesigned then, ok. That means you do need to modify GPIO :-(. You probably should state it clearly in the comments.
I don't think it's necessarily a hardware misdesign if you can't read back the value of output-only GPIOs, even though it's inconvenient. But from the sound of that comment, I'd worry about the current consumed :-)
-- Jamie
PATCH 1/1 ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier
Quoted 18 lines · Jamie Lokier
Quoted 17 lines · Pavel Machek
Quoted 15 lines · Lars-Peter Clausen
Quoted 9 lines · Pavel Machek
Hi!
Quoted 5 lines
On gta02 hardware revision 5 and earlier the basis resistors for transistors of the leds are missing and reading their gpio pin status will always return 0. So we have to shadow the led states in software. This is done by "hijacking" the gpio accessor functions for bank B.
Should that be done in LED driver, instead? Pave
Hi
Nope, that won't work. Every time a gpio on gpb is changed the leds will turn off. So we would have to ship a special version of each driver using a gpio pin form gpb. We certainly don't want to do that.
Quoted 7 lines
Quoted 3 lines
_Any_ GPIO pin change will turn off the LED? Wow, the hardware is severely misdesigned then, ok. That means you do need to modify GPIO :-(. You probably should state it clearly in the comments.
I don't think it's necessarily a hardware misdesign if you can't read back the value of output-only GPIOs, even though it's inconvenient. But from the sound of that comment, I'd worry about the current consumed :-)
Well, in such case... does it make sense to have flag such as "GPIO_SHADOW", not special hacks? Or.... maybe we should be using "shadow" state, always, as it should be faster, anyway?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH 1/1 ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier
In reply to Lars-Peter ClausenQuoted 4 lines · Lars-Peter Clausen
On gta02 hardware revision 5 and earlier the basis resistors for transistors of the leds are missing and reading their gpio pin status will always return 0. So we have to shadow the led states in software. This is done by "hijacking" the gpio accessor functions for bank B.
I think it would be worth investigating the idea of having GPxDAT cached in our gpio chip structure for all banks, as it might even speed up changing the gpios as instead of read-modify-write an uncached memory area, we would change the read-cached,modify,write-cached,write-uncached.
I'll try this and see if there is any measurable GPIO performance increase from doing this.
Quoted 91 lines
Signed-off-by Lars-Peter Clausen <[email protected]>Acked-by Nelson Castillo <[email protected]>--- arch/arm/mach-s3c2442/mach-gta02.c | 54 ++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-)arch/arm/mach-s3c2442/mach-gta02.c +54
-0@@ -90,6 +90,7 @@#include <plat/pm.h> #include <plat/udc.h> #include <plat/gpio-cfg.h> +#include <plat/gpio-core.h> #include <plat/iic.h> static struct pcf50633 *gta02_pcf;@@ -706,11 +707,64 @@ static void gta02_poweroff(void)pcf50633_reg_set_bit_mask (gta02_pcf,PCF50633_REG_OOCSHDWN ,1 ,1 ); } +/* On hardware rev 5 and earlier the leds are missing a resistor and reading +* from their gpio pins will always return 0, so we have to shadow the +* led states software */ +static unsigned long gpb_shadow; +extern struct s3c_gpio_chip s3c24xx_gpios[]; + +static void gta02_gpb_set (struct gpio_chip *chip, +unsigned offset,int value) +{ +void __iomem *base =S3C24XX_GPIO_BASE (S3C2410_GPB (0 )); +unsigned long flags; +unsigned long dat; + +local_irq_save (flags); + + dat =__raw_readl (base +0x04 ) | gpb_shadow; + dat &= ~(1 << offset); + gpb_shadow &= ~(1 << offset); +if (value) { + dat |=1 << offset; +switch (offset) { + case 0 ... 2: + gpb_shadow |=1 << offset; +break ; +default : +break ; + } + } +__raw_writel (dat, base +0x04 ); + +local_irq_restore (flags); +} + +static int gta02_gpb_get (struct gpio_chip *chip,unsigned offset) +{ +void __iomem *base =S3C24XX_GPIO_BASE (S3C2410_GPB (0 )); +unsigned long val; + + val =__raw_readl (base +0x04 ) | gpb_shadow; + val >>= offset; + val &=1 ; + +return val; +} + +static void gta02_hijack_gpb (void ) +{ + s3c24xx_gpios[1 ].chip.set = gta02_gpb_set; + s3c24xx_gpios[1 ].chip.get = gta02_gpb_get; +} +static void __init gta02_machine_init (void ) {/* Set the panic callback to make AUX LED blink at ~5Hz. */ panic_blink = gta02_panic_blink; +gta02_hijack_gpb (); +s3c_pm_init ();#ifdef CONFIG_CHARGER_PCF50633 Signature · 7 lines
1.5.6.5 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 5 lines
-- Ben Q: What's a light-year? A: One-third less calories than a regular year.
PATCH 1/1 ARM: gta02: Add vibrator support
In reply to Lars-Peter ClausenHi!
Quoted 3 lines
The vibrator found on the gta02 is controlled by the s3c pwm controller. Instead of writing a special vibrator driver/class the vibrator is represented as a led device.
Maybe vibrator device will be needed after all?
1) it is getting very common
2) timed-gpio model makes more sense for vibrators -- send 200msec pulse
3) normal triggers make little sense. 'vibrate when battery charges' is cool hack, but
4) can vibrator motor survive running 24/7 ?
5) it is really force feedback; we have input handling for that. Is it unusable?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH 1/1 ARM: gta02: Add button support
In reply to Lars-Peter ClausenQuoted 5 lines · Lars-Peter Clausen
The gta02 has two buttons which are connected to gpio pins and thus can get supported by using the generic gpio-keys driver.
Signed-off-by Lars-Peter Clausen <[email protected]>Acked-by Nelson Castillo <[email protected]>
ACK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html