Skip to content

Commit

Permalink
ARM: S3C2410: H1940: Use leds-gpio driver for LEDs managing
Browse files Browse the repository at this point in the history
We can use generic leds-gpio driver, as latch api was converted
to gpiolib.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
  • Loading branch information
Vasily Khoruzhick authored and Ben Dooks committed Mar 20, 2011
1 parent 4119242 commit 50e2d10
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 3 deletions.
8 changes: 7 additions & 1 deletion arch/arm/mach-s3c2410/h1940-bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
#include <linux/leds.h>
#include <linux/gpio.h>
#include <linux/rfkill.h>
#include <linux/leds.h>

#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <mach/h1940-latch.h>
#include <mach/h1940.h>

#define DRV_NAME "h1940-bt"
#define DRV_NAME "h1940-bt"

/* Bluetooth control */
static void h1940bt_enable(int on)
Expand All @@ -37,13 +39,17 @@ static void h1940bt_enable(int on)
gpio_set_value(S3C2410_GPH(1), 1);
mdelay(10);
gpio_set_value(S3C2410_GPH(1), 0);

h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
}
else {
gpio_set_value(S3C2410_GPH(1), 1);
mdelay(10);
gpio_set_value(S3C2410_GPH(1), 0);
mdelay(10);
gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);

h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
}
}

Expand Down
3 changes: 3 additions & 0 deletions arch/arm/mach-s3c2410/include/mach/h1940.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
#define H1940_SUSPEND_CHECK (0x30080000)

extern void h1940_pm_return(void);
extern int h1940_led_blink_set(unsigned gpio, int state,
unsigned long *delay_on, unsigned long *delay_off);


#endif /* __ASM_ARCH_H1940_H */
93 changes: 91 additions & 2 deletions arch/arm/mach-s3c2410/mach-h1940.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <linux/gpio_keys.h>
#include <linux/pwm_backlight.h>
#include <linux/i2c.h>
#include <linux/leds.h>

#include <video/platform_lcd.h>

#include <linux/mmc/host.h>
Expand Down Expand Up @@ -216,9 +218,87 @@ static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
.gpdup_mask= 0xffffffff,
};

DEFINE_SPINLOCK(h1940_blink_spin);

int h1940_led_blink_set(unsigned gpio, int state,
unsigned long *delay_on, unsigned long *delay_off)
{
int blink_gpio, check_gpio1, check_gpio2;

switch (gpio) {
case H1940_LATCH_LED_GREEN:
blink_gpio = S3C2410_GPA(7);
check_gpio1 = S3C2410_GPA(1);
check_gpio2 = S3C2410_GPA(3);
break;
case H1940_LATCH_LED_RED:
blink_gpio = S3C2410_GPA(1);
check_gpio1 = S3C2410_GPA(7);
check_gpio2 = S3C2410_GPA(3);
break;
default:
blink_gpio = S3C2410_GPA(3);
check_gpio1 = S3C2410_GPA(1);
check_gpio1 = S3C2410_GPA(7);
break;
}

if (delay_on && delay_off && !*delay_on && !*delay_off)
*delay_on = *delay_off = 500;

spin_lock(&h1940_blink_spin);

switch (state) {
case GPIO_LED_NO_BLINK_LOW:
case GPIO_LED_NO_BLINK_HIGH:
if (!gpio_get_value(check_gpio1) &&
!gpio_get_value(check_gpio2))
gpio_set_value(H1940_LATCH_LED_FLASH, 0);
gpio_set_value(blink_gpio, 0);
if (gpio_is_valid(gpio))
gpio_set_value(gpio, state);
break;
case GPIO_LED_BLINK:
if (gpio_is_valid(gpio))
gpio_set_value(gpio, 0);
gpio_set_value(H1940_LATCH_LED_FLASH, 1);
gpio_set_value(blink_gpio, 1);
break;
}

spin_unlock(&h1940_blink_spin);

return 0;
}
EXPORT_SYMBOL(h1940_led_blink_set);

static struct gpio_led h1940_leds_desc[] = {
{
.name = "Green",
.default_trigger = "main-battery-charging-or-full",
.gpio = H1940_LATCH_LED_GREEN,
.retain_state_suspended = 1,
},
{
.name = "Red",
.default_trigger = "main-battery-full",
.gpio = H1940_LATCH_LED_RED,
.retain_state_suspended = 1,
},
};

static struct gpio_led_platform_data h1940_leds_pdata = {
.num_leds = ARRAY_SIZE(h1940_leds_desc),
.leds = h1940_leds_desc,
.gpio_blink_set = h1940_led_blink_set,
};

static struct platform_device h1940_device_leds = {
.name = "h1940-leds",
.id = -1,
.name = "leds-gpio",
.id = -1,
.dev = {
.platform_data = &h1940_leds_pdata,
},
};

static struct platform_device h1940_device_bluetooth = {
Expand Down Expand Up @@ -500,6 +580,15 @@ static void __init h1940_init(void)

platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));

gpio_request(S3C2410_GPA(1), "Red LED blink");
gpio_request(S3C2410_GPA(3), "Blue LED blink");
gpio_request(S3C2410_GPA(7), "Green LED blink");
gpio_request(H1940_LATCH_LED_FLASH, "LED blink");
gpio_direction_output(S3C2410_GPA(1), 0);
gpio_direction_output(S3C2410_GPA(3), 0);
gpio_direction_output(S3C2410_GPA(7), 0);
gpio_direction_output(H1940_LATCH_LED_FLASH, 0);

i2c_register_board_info(0, h1940_i2c_devices,
ARRAY_SIZE(h1940_i2c_devices));
}
Expand Down

0 comments on commit 50e2d10

Please sign in to comment.