Commit d8fec1fc80cd8639449e2b5012688f5be109eeaf

Authored by Gabor Juhos
Committed by Ralf Baechle
1 parent 0cde72284c

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>

Showing 5 changed files with 100 additions and 0 deletions Side-by-side Diff

arch/mips/ath79/Kconfig
... ... @@ -5,6 +5,7 @@
5 5 config ATH79_MACH_PB44
6 6 bool "Atheros PB44 reference board"
7 7 select SOC_AR71XX
  8 + select ATH79_DEV_LEDS_GPIO
8 9 help
9 10 Say 'Y' here if you want your kernel to support the
10 11 Atheros PB44 reference board.
... ... @@ -18,6 +19,9 @@
18 19 def_bool n
19 20  
20 21 config SOC_AR913X
  22 + def_bool n
  23 +
  24 +config ATH79_DEV_LEDS_GPIO
21 25 def_bool n
22 26  
23 27 endif
arch/mips/ath79/Makefile
... ... @@ -16,6 +16,7 @@
16 16 # Devices
17 17 #
18 18 obj-y += dev-common.o
  19 +obj-$(CONFIG_ATH79_DEV_LEDS_GPIO) += dev-leds-gpio.o
19 20  
20 21 #
21 22 # Machines
arch/mips/ath79/dev-leds-gpio.c
  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
  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
... ... @@ -15,11 +15,14 @@
15 15 #include <linux/i2c/pcf857x.h>
16 16  
17 17 #include "machtypes.h"
  18 +#include "dev-leds-gpio.h"
18 19  
19 20 #define PB44_GPIO_I2C_SCL 0
20 21 #define PB44_GPIO_I2C_SDA 1
21 22  
22 23 #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)
23 26  
24 27 static struct i2c_gpio_platform_data pb44_i2c_gpio_data = {
25 28 .sda_pin = PB44_GPIO_I2C_SDA,
26 29  
... ... @@ -45,11 +48,26 @@
45 48 },
46 49 };
47 50  
  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 +
48 63 static void __init pb44_init(void)
49 64 {
50 65 i2c_register_board_info(0, pb44_i2c_board_info,
51 66 ARRAY_SIZE(pb44_i2c_board_info));
52 67 platform_device_register(&pb44_i2c_gpio_device);
  68 +
  69 + ath79_register_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio),
  70 + pb44_leds_gpio);
53 71 }
54 72  
55 73 MIPS_MACHINE(ATH79_MACH_PB44, "PB44", "Atheros PB44 reference board",