[PATCH] ARM: gta02: Add button support

12 messages Options
Embed this post
Permalink
Lars-Peter Clausen

[PATCH] ARM: gta02: Add button support

Reply Threaded More More options
Print post
Permalink
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 <[hidden email]>
---
 arch/arm/mach-s3c2442/mach-gta02.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-s3c2442/mach-gta02.c b/arch/arm/mach-s3c2442/mach-gta02.c
index 0fb385b..0f0c619 100644
--- a/arch/arm/mach-s3c2442/mach-gta02.c
+++ b/arch/arm/mach-s3c2442/mach-gta02.c
@@ -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. */
--
1.5.6.5


Lars-Peter Clausen

[PATCH] ARM: gta02: Add LED support

Reply Threaded More More options
Print post
Permalink
The gta02 has three leds which are connected though gpio pins and thus can get
supported by using the generic leds-gpio driver.

Signed-off-by: Lars-Peter Clausen <[hidden email]>
---
 arch/arm/mach-s3c2442/mach-gta02.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-s3c2442/mach-gta02.c b/arch/arm/mach-s3c2442/mach-gta02.c
index 0f0c619..7629371 100644
--- a/arch/arm/mach-s3c2442/mach-gta02.c
+++ b/arch/arm/mach-s3c2442/mach-gta02.c
@@ -60,6 +60,8 @@
 
 #include <linux/gpio_keys.h>
 
+#include <linux/leds.h>
+
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
 #include <asm/mach/irq.h>
@@ -583,6 +585,35 @@ static struct platform_device gta02_buttons_device = {
  },
 };
 
+/* LEDs */
+static struct gpio_led gta02_gpio_leds[] = {
+ {
+ .name = "gta02-power:orange",
+ .gpio = GTA02_GPIO_PWR_LED1,
+ },
+ {
+ .name = "gta02-power:blue",
+ .gpio = GTA02_GPIO_PWR_LED2,
+ },
+ {
+ .name = "gta02-aux:red",
+ .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 void __init gta02_map_io(void)
 {
  s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
@@ -604,6 +635,7 @@ static struct platform_device *gta02_devices[] __initdata = {
  &s3c_device_iis,
  &s3c_device_i2c0,
  >a02_buttons_device,
+ >a02_leds_device,
 };
 
 /* These guys DO need to be children of PMU. */
--
1.5.6.5


Lars-Peter Clausen

[PATCH] ARM: gta02: Add gpio bank B quirk for hardware revision 5 and earlier

Reply Threaded More More options
Print post
Permalink
On hardware revision 5 and earlier the leds found on the gta02 are missing a
resistor 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.

Signed-off-by: Lars-Peter Clausen <[hidden email]>
---
 arch/arm/mach-s3c2442/mach-gta02.c |   64 ++++++++++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-s3c2442/mach-gta02.c b/arch/arm/mach-s3c2442/mach-gta02.c
index 7629371..baba72e 100644
--- a/arch/arm/mach-s3c2442/mach-gta02.c
+++ b/arch/arm/mach-s3c2442/mach-gta02.c
@@ -89,6 +89,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;
@@ -607,8 +608,8 @@ static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
 };
 
 static struct platform_device gta02_leds_device = {
- .name = "leds-gpio",
- .id   = -1,
+ .name = "leds-gpio",
+ .id = -1,
  .dev = {
  .platform_data = >a02_gpio_leds_pdata,
  },
@@ -674,11 +675,70 @@ 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)
+{
+/* Uncomment this, once support for S3C_SYSTEM_REV_ATAG has been merged
+ * upstream.
+ if (S3C_SYSTEM_REV_ATAG > GTA02v5_SYSTEM_REV)
+ return;
+*/
+
+ 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
--
1.5.6.5


Nelson Castillo-2

Re: [PATCH] ARM: gta02: Add button support

Reply Threaded More More options
Print post
Permalink
In reply to this post by Lars-Peter Clausen
Hello Lars.

I tested with Linux 2.6.31.

> +#include <linux/gpio_keys.h>

I think we need this also:

#include <linux/input.h>


root@om-gta02 /sys/class/input $ ls
event0  input0  mice

event0 is power button (PCF50633 PMU event).

What do I have to enable to see the input events?
I am missing something?

Michael Trimarchi

Re: [PATCH] ARM: gta02: Add button support

Reply Threaded More More options
Print post
Permalink
Nelson Castillo wrote:

> Hello Lars.
>
> I tested with Linux 2.6.31.
>
>  
>> +#include <linux/gpio_keys.h>
>>    
>
> I think we need this also:
>
> #include <linux/input.h>
>
>
> root@om-gta02 /sys/class/input $ ls
> event0  input0  mice
>
> event0 is power button (PCF50633 PMU event).
>
> What do I have to enable to see the input events?
> I am missing something?
>
>
>  
Hi Nelson
I have prepare a linux-2.6.31 tree and I would like to commit somenthig.
Can we prepare a clean linux-2.6 branch?

Do you include gpio-keys driver?

Michael



Nelson Castillo-2

Re: [PATCH] ARM: gta02: Add button support

Reply Threaded More More options
Print post
Permalink
> Hi Nelson
> I have prepare a linux-2.6.31 tree and I would like to commit somenthig. Can
> we prepare a clean linux-2.6 branch?
>
> Do you include gpio-keys driver?

I had CONFIG_KEYBOARD_GPIO as a module :-/

Thanks.

Nelson Castillo-2

Re: [PATCH] ARM: gta02: Add button support

Reply Threaded More More options
Print post
Permalink
In reply to this post by Lars-Peter Clausen
>  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. */

BTW the buttons worked as children of the PMU. I guess we will need
them to be there later.

Michael 'Mickey' Lauer-2

Re: [PATCH] ARM: gta02: Add LED support

Reply Threaded More More options
Print post
Permalink
In reply to this post by Lars-Peter Clausen
Am Donnerstag, den 24.09.2009, 19:41 +0200 schrieb Lars-Peter Clausen:
> The gta02 has three leds which are connected though gpio pins and thus can get
> supported by using the generic leds-gpio driver.

Will anyone bring us back the PWM support that we lost very early in the
02 kernel cycle? I'd love to have my dimming LEDs back...

Thanks for all your upstream work,

:M:



Lars-Peter Clausen

Re: [PATCH] ARM: gta02: Add button support

Reply Threaded More More options
Print post
Permalink
In reply to this post by Nelson Castillo-2
>
>>  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. */
>>    
>
> BTW the buttons worked as children of the PMU. I guess we will need
> them to be there later.
>  
I don't get why that would be necessary. Both buttons are not related or
connected to the PMU in any way. Or am I missing something?

- Lars

Lars-Peter Clausen

Re: [PATCH] ARM: gta02: Add LED support

Reply Threaded More More options
Print post
Permalink
In reply to this post by Michael 'Mickey' Lauer-2
>
> Am Donnerstag, den 24.09.2009, 19:41 +0200 schrieb Lars-Peter Clausen:
>  
>> The gta02 has three leds which are connected though gpio pins and thus can get
>> supported by using the generic leds-gpio driver.
>>    
>
> Will anyone bring us back the PWM support that we lost very early in the
> 02 kernel cycle? I'd love to have my dimming LEDs back...
>
> Thanks for all your upstream work,
>
> :M:
>
>
>  
Do you know why support for hardware pwm was dropped? Cause if
everything works properly it should be as easy as using the the leds-pwm
platform driver instead of the leds-gpio platform driver.

In the meantime you can of course do software pwm using the led-trigger
framework.

- Lars

Timo Juhani Lindfors

Re: [PATCH] ARM: gta02: Add button support

Reply Threaded More More options
Print post
Permalink
In reply to this post by Lars-Peter Clausen
Lars-Peter Clausen <[hidden email]> writes:
> The gta02 has two buttons which are connected to gpio pins and thus can get
> supported by using the generic gpio-keys driver.

I'm bit confused about how kernel development is done
currently. Should I find this patch already in some git tree?

If yes, does that tree have

#define PCF50633_ONKEY1S_TIMEOUT 8

set in drivers/mfd/pcf50633-core.c? If yes, we probably should
document that the power button can not be used as a general purpose
button since the system will do an emergency shutdown if it is held
down for 8 seconds?  (Very annoying if you want to use the phone for
making audio notes when power button is held. You can't use AUX since
the phone won't wake from suspend with AUX.)




Lars-Peter Clausen

Re: [PATCH] ARM: gta02: Add button support

Reply Threaded More More options
Print post
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Timo Juhani Lindfors wrote:

> Lars-Peter Clausen <[hidden email]> writes:
>> The gta02 has two buttons which are connected to gpio pins and
>> thus can get supported by using the generic gpio-keys driver.
>
> I'm bit confused about how kernel development is done currently.
> Should I find this patch already in some git tree?
>
> If yes, does that tree have
>
> #define PCF50633_ONKEY1S_TIMEOUT 8
>
> set in drivers/mfd/pcf50633-core.c? If yes, we probably should
> document that the power button can not be used as a general purpose
>  button since the system will do an emergency shutdown if it is
> held down for 8 seconds?  (Very annoying if you want to use the
> phone for making audio notes when power button is held. You can't
> use AUX since the phone won't wake from suspend with AUX.)
This patch is about AUX and Play button support. The power button is
handled through the pcf50633.

- - Lars
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrHe2IACgkQBX4mSR26RiNTAwCfQzWHWJWLUyrGe0AaAYKUlJOf
mtEAn3ZIyiw6j5nzfJ4my7hg3gjLizmM
=HduN
-----END PGP SIGNATURE-----