Skip to content

Commit d8fec1f

Browse files
juhosgralfbaechle
authored andcommitted
MIPS: ath79: add common GPIO LEDs device
Almost all boards have one or more LEDs connected to GPIO lines. This patch adds common code to register a platform_device for them. The patch also adds support for the LEDs on the PB44 board. Signed-off-by: Gabor Juhos <juhosg@openwrt.org> Signed-off-by: Imre Kaloz <kaloz@openwrt.org> Cc: linux-mips@linux-mips.org Cc: Luis R. Rodriguez <lrodriguez@atheros.com> Cc: Cliff Holden <Cliff.Holden@Atheros.com> Cc: Kathy Giori <Kathy.Giori@Atheros.com> Patchwork: https://patchwork.linux-mips.org/patch/1953/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 0cde722 commit d8fec1f

5 files changed

Lines changed: 100 additions & 0 deletions

File tree

‎arch/mips/ath79/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ menu "Atheros AR71XX/AR724X/AR913X machine selection"
55
config ATH79_MACH_PB44
66
bool "Atheros PB44 reference board"
77
select SOC_AR71XX
8+
select ATH79_DEV_LEDS_GPIO
89
help
910
Say 'Y' here if you want your kernel to support the
1011
Atheros PB44 reference board.
@@ -20,4 +21,7 @@ config SOC_AR724X
2021
config SOC_AR913X
2122
def_bool n
2223

24+
config ATH79_DEV_LEDS_GPIO
25+
def_bool n
26+
2327
endif

‎arch/mips/ath79/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
1616
# Devices
1717
#
1818
obj-y += dev-common.o
19+
obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o
1920

2021
#
2122
# Machines

‎arch/mips/ath79/dev-leds-gpio.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Atheros AR71XX/AR724X/AR913X common GPIO LEDs support
3+
*
4+
* Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5+
* Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6+
*
7+
* This program is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU General Public License version 2 as published
9+
* by the Free Software Foundation.
10+
*/
11+
12+
#include <linux/init.h>
13+
#include <linux/slab.h>
14+
#include <linux/platform_device.h>
15+
16+
#include "dev-leds-gpio.h"
17+
18+
void __init ath79_register_leds_gpio(int id,
19+
unsigned num_leds,
20+
struct gpio_led *leds)
21+
{
22+
struct platform_device *pdev;
23+
struct gpio_led_platform_data pdata;
24+
struct gpio_led *p;
25+
int err;
26+
27+
p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
28+
if (!p)
29+
return;
30+
31+
memcpy(p, leds, num_leds * sizeof(*p));
32+
33+
pdev = platform_device_alloc("leds-gpio", id);
34+
if (!pdev)
35+
goto err_free_leds;
36+
37+
memset(&pdata, 0, sizeof(pdata));
38+
pdata.num_leds = num_leds;
39+
pdata.leds = p;
40+
41+
err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
42+
if (err)
43+
goto err_put_pdev;
44+
45+
err = platform_device_add(pdev);
46+
if (err)
47+
goto err_put_pdev;
48+
49+
return;
50+
51+
err_put_pdev:
52+
platform_device_put(pdev);
53+
54+
err_free_leds:
55+
kfree(p);
56+
}

‎arch/mips/ath79/dev-leds-gpio.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Atheros AR71XX/AR724X/AR913X common GPIO LEDs support
3+
*
4+
* Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5+
* Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6+
*
7+
* This program is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU General Public License version 2 as published
9+
* by the Free Software Foundation.
10+
*/
11+
12+
#ifndef _ATH79_DEV_LEDS_GPIO_H
13+
#define _ATH79_DEV_LEDS_GPIO_H
14+
15+
#include <linux/leds.h>
16+
17+
void ath79_register_leds_gpio(int id,
18+
unsigned num_leds,
19+
struct gpio_led *leds);
20+
21+
#endif /* _ATH79_DEV_LEDS_GPIO_H */

‎arch/mips/ath79/mach-pb44.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
#include <linux/i2c/pcf857x.h>
1616

1717
#include "machtypes.h"
18+
#include "dev-leds-gpio.h"
1819

1920
#define PB44_GPIO_I2C_SCL 0
2021
#define PB44_GPIO_I2C_SDA 1
2122

2223
#define PB44_GPIO_EXP_BASE 16
24+
#define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + 9)
25+
#define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + 10)
2326

2427
static struct i2c_gpio_platform_data pb44_i2c_gpio_data = {
2528
.sda_pin = PB44_GPIO_I2C_SDA,
@@ -45,11 +48,26 @@ static struct i2c_board_info pb44_i2c_board_info[] __initdata = {
4548
},
4649
};
4750

51+
static struct gpio_led pb44_leds_gpio[] __initdata = {
52+
{
53+
.name = "pb44:amber:jump1",
54+
.gpio = PB44_GPIO_LED_JUMP1,
55+
.active_low = 1,
56+
}, {
57+
.name = "pb44:green:jump2",
58+
.gpio = PB44_GPIO_LED_JUMP2,
59+
.active_low = 1,
60+
},
61+
};
62+
4863
static void __init pb44_init(void)
4964
{
5065
i2c_register_board_info(0, pb44_i2c_board_info,
5166
ARRAY_SIZE(pb44_i2c_board_info));
5267
platform_device_register(&pb44_i2c_gpio_device);
68+
69+
ath79_register_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio),
70+
pb44_leds_gpio);
5371
}
5472

5573
MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board",

0 commit comments

Comments
 (0)