xref: /linux/arch/arm/mach-orion5x/board-d2net.c (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
10fdebc5eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
294b0bd36SThomas Petazzoni /*
394b0bd36SThomas Petazzoni  * arch/arm/mach-orion5x/board-d2net.c
494b0bd36SThomas Petazzoni  *
594b0bd36SThomas Petazzoni  * LaCie d2Network and Big Disk Network NAS setup
694b0bd36SThomas Petazzoni  *
794b0bd36SThomas Petazzoni  * Copyright (C) 2009 Simon Guinot <sguinot@lacie.com>
894b0bd36SThomas Petazzoni  */
994b0bd36SThomas Petazzoni 
1094b0bd36SThomas Petazzoni #include <linux/kernel.h>
1194b0bd36SThomas Petazzoni #include <linux/init.h>
1294b0bd36SThomas Petazzoni #include <linux/platform_device.h>
1394b0bd36SThomas Petazzoni #include <linux/pci.h>
1494b0bd36SThomas Petazzoni #include <linux/irq.h>
1594b0bd36SThomas Petazzoni #include <linux/leds.h>
1694b0bd36SThomas Petazzoni #include <linux/gpio.h>
17*79f46f68SLinus Walleij #include <linux/gpio/machine.h>
1894b0bd36SThomas Petazzoni #include <asm/mach-types.h>
1994b0bd36SThomas Petazzoni #include <asm/mach/arch.h>
2094b0bd36SThomas Petazzoni #include <asm/mach/pci.h>
2194b0bd36SThomas Petazzoni #include <plat/orion-gpio.h>
2294b0bd36SThomas Petazzoni #include "common.h"
23c22c2c60SArnd Bergmann #include "orion5x.h"
2494b0bd36SThomas Petazzoni 
2594b0bd36SThomas Petazzoni /*****************************************************************************
2694b0bd36SThomas Petazzoni  * LaCie d2 Network Info
2794b0bd36SThomas Petazzoni  ****************************************************************************/
2894b0bd36SThomas Petazzoni 
2994b0bd36SThomas Petazzoni /*****************************************************************************
3094b0bd36SThomas Petazzoni  * GPIO LED's
3194b0bd36SThomas Petazzoni  ****************************************************************************/
3294b0bd36SThomas Petazzoni 
3394b0bd36SThomas Petazzoni /*
3494b0bd36SThomas Petazzoni  * The blue front LED is wired to the CPLD and can blink in relation with the
3594b0bd36SThomas Petazzoni  * SATA activity.
3694b0bd36SThomas Petazzoni  *
3794b0bd36SThomas Petazzoni  * The following array detail the different LED registers and the combination
3894b0bd36SThomas Petazzoni  * of their possible values:
3994b0bd36SThomas Petazzoni  *
4094b0bd36SThomas Petazzoni  * led_off   | blink_ctrl | SATA active | LED state
4194b0bd36SThomas Petazzoni  *           |            |             |
4294b0bd36SThomas Petazzoni  *    1      |     x      |      x      |  off
4394b0bd36SThomas Petazzoni  *    0      |     0      |      0      |  off
4494b0bd36SThomas Petazzoni  *    0      |     1      |      0      |  blink (rate 300ms)
4594b0bd36SThomas Petazzoni  *    0      |     x      |      1      |  on
4694b0bd36SThomas Petazzoni  *
4794b0bd36SThomas Petazzoni  * Notes: The blue and the red front LED's can't be on at the same time.
4894b0bd36SThomas Petazzoni  *        Red LED have priority.
4994b0bd36SThomas Petazzoni  */
5094b0bd36SThomas Petazzoni 
5194b0bd36SThomas Petazzoni #define D2NET_GPIO_RED_LED		6
5294b0bd36SThomas Petazzoni #define D2NET_GPIO_BLUE_LED_BLINK_CTRL	16
5394b0bd36SThomas Petazzoni #define D2NET_GPIO_BLUE_LED_OFF		23
5494b0bd36SThomas Petazzoni 
5594b0bd36SThomas Petazzoni static struct gpio_led d2net_leds[] = {
5694b0bd36SThomas Petazzoni 	{
5794b0bd36SThomas Petazzoni 		.name = "d2net:blue:sata",
5894b0bd36SThomas Petazzoni 		.default_trigger = "default-on",
5994b0bd36SThomas Petazzoni 	},
6094b0bd36SThomas Petazzoni 	{
6194b0bd36SThomas Petazzoni 		.name = "d2net:red:fail",
6294b0bd36SThomas Petazzoni 	},
6394b0bd36SThomas Petazzoni };
6494b0bd36SThomas Petazzoni 
6594b0bd36SThomas Petazzoni static struct gpio_led_platform_data d2net_led_data = {
6694b0bd36SThomas Petazzoni 	.num_leds = ARRAY_SIZE(d2net_leds),
6794b0bd36SThomas Petazzoni 	.leds = d2net_leds,
6894b0bd36SThomas Petazzoni };
6994b0bd36SThomas Petazzoni 
7094b0bd36SThomas Petazzoni static struct platform_device d2net_gpio_leds = {
7194b0bd36SThomas Petazzoni 	.name           = "leds-gpio",
7294b0bd36SThomas Petazzoni 	.id             = -1,
7394b0bd36SThomas Petazzoni 	.dev            = {
7494b0bd36SThomas Petazzoni 		.platform_data  = &d2net_led_data,
7594b0bd36SThomas Petazzoni 	},
7694b0bd36SThomas Petazzoni };
7794b0bd36SThomas Petazzoni 
78*79f46f68SLinus Walleij static struct gpiod_lookup_table d2net_leds_gpio_table = {
79*79f46f68SLinus Walleij 	.dev_id = "leds-gpio",
80*79f46f68SLinus Walleij 	.table = {
81*79f46f68SLinus Walleij 		GPIO_LOOKUP_IDX("orion_gpio0", D2NET_GPIO_BLUE_LED_OFF, NULL,
82*79f46f68SLinus Walleij 				0, GPIO_ACTIVE_LOW),
83*79f46f68SLinus Walleij 		GPIO_LOOKUP_IDX("orion_gpio0", D2NET_GPIO_RED_LED, NULL,
84*79f46f68SLinus Walleij 				1, GPIO_ACTIVE_HIGH),
85*79f46f68SLinus Walleij 		{ },
86*79f46f68SLinus Walleij 	},
87*79f46f68SLinus Walleij };
88*79f46f68SLinus Walleij 
d2net_gpio_leds_init(void)8994b0bd36SThomas Petazzoni static void __init d2net_gpio_leds_init(void)
9094b0bd36SThomas Petazzoni {
9194b0bd36SThomas Petazzoni 	int err;
9294b0bd36SThomas Petazzoni 
9394b0bd36SThomas Petazzoni 	/* Configure register blink_ctrl to allow SATA activity LED blinking. */
9494b0bd36SThomas Petazzoni 	err = gpio_request(D2NET_GPIO_BLUE_LED_BLINK_CTRL, "blue LED blink");
9594b0bd36SThomas Petazzoni 	if (err == 0) {
9694b0bd36SThomas Petazzoni 		err = gpio_direction_output(D2NET_GPIO_BLUE_LED_BLINK_CTRL, 1);
9794b0bd36SThomas Petazzoni 		if (err)
9894b0bd36SThomas Petazzoni 			gpio_free(D2NET_GPIO_BLUE_LED_BLINK_CTRL);
9994b0bd36SThomas Petazzoni 	}
10094b0bd36SThomas Petazzoni 	if (err)
10194b0bd36SThomas Petazzoni 		pr_err("d2net: failed to configure blue LED blink GPIO\n");
10294b0bd36SThomas Petazzoni 
103*79f46f68SLinus Walleij 	gpiod_add_lookup_table(&d2net_leds_gpio_table);
10494b0bd36SThomas Petazzoni 	platform_device_register(&d2net_gpio_leds);
10594b0bd36SThomas Petazzoni }
10694b0bd36SThomas Petazzoni 
10794b0bd36SThomas Petazzoni /*****************************************************************************
10894b0bd36SThomas Petazzoni  * General Setup
10994b0bd36SThomas Petazzoni  ****************************************************************************/
11094b0bd36SThomas Petazzoni 
d2net_init(void)11194b0bd36SThomas Petazzoni void __init d2net_init(void)
11294b0bd36SThomas Petazzoni {
11394b0bd36SThomas Petazzoni 	d2net_gpio_leds_init();
11494b0bd36SThomas Petazzoni 
11594b0bd36SThomas Petazzoni 	pr_notice("d2net: Flash write are not yet supported.\n");
11694b0bd36SThomas Petazzoni }
117