[U-Boot] [PATCH 0/3] net2big_v2: initialize fan and LEDs at startup

Hi Prafulla,
This patch series allows to initialize the fan and the LEDs found on the net2big_v2.
Regards,
Simon
Simon Guinot (3): net2big_v2: initialize I2C fan at startup LaCie/common: add support for the GPIO extension bus net2big_v2: initialize LEDs at startup
board/LaCie/common/gpio-ext.c | 47 ++++++++++++ board/LaCie/common/gpio-ext.h | 24 ++++++ board/LaCie/net2big_v2/Makefile | 3 + board/LaCie/net2big_v2/net2big_v2.c | 140 ++++++++++++++++++++++++++++++++++- board/LaCie/net2big_v2/net2big_v2.h | 5 ++ include/configs/lacie_kw.h | 9 ++- 6 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 board/LaCie/common/gpio-ext.c create mode 100644 board/LaCie/common/gpio-ext.h

This patch ensures minimal cooling for the net2big_v2 by automatically starting the I2C fan (GMT G762) at low speed (2800 RPM).
Signed-off-by: Simon Guinot simon.guinot@sequanux.org --- board/LaCie/net2big_v2/net2big_v2.c | 54 ++++++++++++++++++++++++++++++++++- board/LaCie/net2big_v2/net2big_v2.h | 5 ++++ include/configs/lacie_kw.h | 9 +++++- 3 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/board/LaCie/net2big_v2/net2big_v2.c b/board/LaCie/net2big_v2/net2big_v2.c index e524f35..6cca4fb 100644 --- a/board/LaCie/net2big_v2/net2big_v2.c +++ b/board/LaCie/net2big_v2/net2big_v2.c @@ -22,6 +22,7 @@
#include <common.h> #include <command.h> +#include <i2c.h> #include <asm/arch/cpu.h> #include <asm/arch/kirkwood.h> #include <asm/arch/mpp.h> @@ -92,8 +93,59 @@ int board_init(void) }
#if defined(CONFIG_MISC_INIT_R) + +#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR) +/* + * Start I2C fan (GMT G762 controller) + */ +static void init_fan(void) +{ + u8 data; + + i2c_set_bus_num(0); + + /* Enable open-loop and PWM modes */ + data = 0x20; + if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, + G762_REG_FAN_CMD1, 1, &data, 1) != 0) + goto err; + data = 0; + if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, + G762_REG_SET_CNT, 1, &data, 1) != 0) + goto err; + /* + * RPM to PWM (set_out register) fan speed conversion array: + * 0 0x00 + * 1500 0x04 + * 2800 0x08 + * 3400 0x0C + * 3700 0x10 + * 4400 0x20 + * 4700 0x30 + * 4800 0x50 + * 5200 0x80 + * 5400 0xC0 + * 5500 0xFF + * + * Start fan at low speed (2800 RPM): + */ + data = 0x08; + if (i2c_write(CONFIG_SYS_I2C_G762_ADDR, + G762_REG_SET_OUT, 1, &data, 1) != 0) + goto err; + + return; +err: + printf("Error: failed to start I2C fan @%02x\n", + CONFIG_SYS_I2C_G762_ADDR); +} +#else +static void init_fan(void) {} +#endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */ + int misc_init_r(void) { + init_fan(); #if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) if (!getenv("ethaddr")) { uchar mac[6]; @@ -103,7 +155,7 @@ int misc_init_r(void) #endif return 0; } -#endif +#endif /* CONFIG_MISC_INIT_R */
#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R) /* Configure and initialize PHY */ diff --git a/board/LaCie/net2big_v2/net2big_v2.h b/board/LaCie/net2big_v2/net2big_v2.h index f9778f4..83537d6 100644 --- a/board/LaCie/net2big_v2/net2big_v2.h +++ b/board/LaCie/net2big_v2/net2big_v2.h @@ -32,4 +32,9 @@ /* Buttons */ #define NET2BIG_V2_GPIO_PUSH_BUTTON 34
+/* GMT G762 registers (I2C fan controller) */ +#define G762_REG_SET_CNT 0x00 +#define G762_REG_SET_OUT 0x03 +#define G762_REG_FAN_CMD1 0x04 + #endif /* NET2BIG_V2_H */ diff --git a/include/configs/lacie_kw.h b/include/configs/lacie_kw.h index 09b5798..e2b3b21 100644 --- a/include/configs/lacie_kw.h +++ b/include/configs/lacie_kw.h @@ -120,10 +120,14 @@ #endif
/* + * Enable platform initialisation via misc_init_r() function + */ +#define CONFIG_MISC_INIT_R + +/* * Ethernet Driver configuration */ #ifdef CONFIG_CMD_NET -#define CONFIG_MISC_INIT_R /* Call misc_init_r() to initialize MAC address */ #define CONFIG_MVGBE_PORTS {1, 0} /* enable port 0 only */ #define CONFIG_NETCONSOLE #endif @@ -153,6 +157,9 @@ #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 4 /* 16-byte page size */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1 /* 8-bit device address */ +#if defined(CONFIG_NET2BIG_V2) +#define CONFIG_SYS_I2C_G762_ADDR 0x3e +#endif #endif /* CONFIG_CMD_I2C */
/*

-----Original Message----- From: Simon Guinot [mailto:simon.guinot@sequanux.org] Sent: 18 June 2013 02:28 To: Prafulla Wadaskar Cc: Albert ARIBAUD; u-boot@lists.denx.de Subject: [PATCH 1/3] net2big_v2: initialize I2C fan at startup
This patch ensures minimal cooling for the net2big_v2 by automatically starting the I2C fan (GMT G762) at low speed (2800 RPM).
Signed-off-by: Simon Guinot simon.guinot@sequanux.org
board/LaCie/net2big_v2/net2big_v2.c | 54 ++++++++++++++++++++++++++++++++++- board/LaCie/net2big_v2/net2big_v2.h | 5 ++++ include/configs/lacie_kw.h | 9 +++++- 3 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/board/LaCie/net2big_v2/net2big_v2.c b/board/LaCie/net2big_v2/net2big_v2.c index e524f35..6cca4fb 100644 --- a/board/LaCie/net2big_v2/net2big_v2.c +++ b/board/LaCie/net2big_v2/net2big_v2.c @@ -22,6 +22,7 @@
#include <common.h> #include <command.h> +#include <i2c.h> #include <asm/arch/cpu.h> #include <asm/arch/kirkwood.h> #include <asm/arch/mpp.h> @@ -92,8 +93,59 @@ int board_init(void) }
#if defined(CONFIG_MISC_INIT_R)
+#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_G762_ADDR) +/*
- Start I2C fan (GMT G762 controller)
- */
+static void init_fan(void) +{
- u8 data;
- i2c_set_bus_num(0);
- /* Enable open-loop and PWM modes */
- data = 0x20;
- if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
G762_REG_FAN_CMD1, 1, &data, 1) != 0)
goto err;
- data = 0;
- if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
G762_REG_SET_CNT, 1, &data, 1) != 0)
goto err;
- /*
* RPM to PWM (set_out register) fan speed
conversion array:
* 0 0x00
* 1500 0x04
* 2800 0x08
* 3400 0x0C
* 3700 0x10
* 4400 0x20
* 4700 0x30
* 4800 0x50
* 5200 0x80
* 5400 0xC0
* 5500 0xFF
*
* Start fan at low speed (2800 RPM):
*/
- data = 0x08;
- if (i2c_write(CONFIG_SYS_I2C_G762_ADDR,
G762_REG_SET_OUT, 1, &data, 1) != 0)
goto err;
- return;
+err:
- printf("Error: failed to start I2C fan @%02x\n",
CONFIG_SYS_I2C_G762_ADDR);
+} +#else +static void init_fan(void) {} +#endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */
int misc_init_r(void) {
- init_fan();
#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) if (!getenv("ethaddr")) { uchar mac[6]; @@ -103,7 +155,7 @@ int misc_init_r(void) #endif return 0; } -#endif +#endif /* CONFIG_MISC_INIT_R */
#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R) /* Configure and initialize PHY */ diff --git a/board/LaCie/net2big_v2/net2big_v2.h b/board/LaCie/net2big_v2/net2big_v2.h index f9778f4..83537d6 100644 --- a/board/LaCie/net2big_v2/net2big_v2.h +++ b/board/LaCie/net2big_v2/net2big_v2.h @@ -32,4 +32,9 @@ /* Buttons */ #define NET2BIG_V2_GPIO_PUSH_BUTTON 34
+/* GMT G762 registers (I2C fan controller) */ +#define G762_REG_SET_CNT 0x00 +#define G762_REG_SET_OUT 0x03 +#define G762_REG_FAN_CMD1 0x04
#endif /* NET2BIG_V2_H */ diff --git a/include/configs/lacie_kw.h b/include/configs/lacie_kw.h index 09b5798..e2b3b21 100644 --- a/include/configs/lacie_kw.h +++ b/include/configs/lacie_kw.h @@ -120,10 +120,14 @@ #endif
/*
- Enable platform initialisation via misc_init_r()
function
- */
+#define CONFIG_MISC_INIT_R
+/*
- Ethernet Driver configuration
*/ #ifdef CONFIG_CMD_NET -#define CONFIG_MISC_INIT_R /* Call misc_init_r() to initialize MAC address */ #define CONFIG_MVGBE_PORTS {1, 0} /* enable port 0 only */ #define CONFIG_NETCONSOLE #endif @@ -153,6 +157,9 @@ #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 4 /* 16- byte page size */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1 /* 8-bit device address */ +#if defined(CONFIG_NET2BIG_V2) +#define CONFIG_SYS_I2C_G762_ADDR 0x3e +#endif #endif /* CONFIG_CMD_I2C */
Acked-by: Prafulla Wadaskar prafulla@marvell.com
Regards... Prafulla . . .

This patch adds support for the GPIO extension bus found on some LaCie boards (as the 2Big/5Big Network v2 and the 2Big NAS). This bus allows to configure the devices (mostly the LEDs) connected to a CPLD via two GPIO-based registers (address and data).
Signed-off-by: Simon Guinot simon.guinot@sequanux.org --- board/LaCie/common/gpio-ext.c | 47 +++++++++++++++++++++++++++++++++++++++++ board/LaCie/common/gpio-ext.h | 24 +++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 board/LaCie/common/gpio-ext.c create mode 100644 board/LaCie/common/gpio-ext.h
diff --git a/board/LaCie/common/gpio-ext.c b/board/LaCie/common/gpio-ext.c new file mode 100644 index 0000000..1e1b7ff --- /dev/null +++ b/board/LaCie/common/gpio-ext.c @@ -0,0 +1,47 @@ +/* + * gpio-ext.c: provides support for the GPIO extension bus found on some + * LaCie boards (as the 2Big/5Big Network v2 and the 2Big NAS). This bus + * allows to configure the devices (mostly the LEDs) connected to a CPLD + * via two GPIO-based registers (address and data). + * + * Copyright (C) 2013 Simon Guinot simon.guinot@sequanux.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#include <asm/arch/gpio.h> +#include "gpio-ext.h" + +static void gpio_ext_set_addr(struct gpio_ext *gpio_ext, unsigned addr) +{ + int pin; + + for (pin = 0; pin < gpio_ext->num_addr; pin++) + kw_gpio_set_value(gpio_ext->addr[pin], (addr >> pin) & 1); +} + +static void gpio_ext_set_data(struct gpio_ext *gpio_ext, unsigned data) +{ + int pin; + + for (pin = 0; pin < gpio_ext->num_data; pin++) + kw_gpio_set_value(gpio_ext->data[pin], (data >> pin) & 1); +} + +static void gpio_ext_enable_select(struct gpio_ext *gpio_ext) +{ + /* The transfer is enabled on the raising edge. */ + kw_gpio_set_value(gpio_ext->enable, 0); + kw_gpio_set_value(gpio_ext->enable, 1); +} + +void gpio_ext_set_value(struct gpio_ext *gpio_ext, + unsigned addr, unsigned value) +{ + gpio_ext_set_addr(gpio_ext, addr); + gpio_ext_set_data(gpio_ext, value); + gpio_ext_enable_select(gpio_ext); +} diff --git a/board/LaCie/common/gpio-ext.h b/board/LaCie/common/gpio-ext.h new file mode 100644 index 0000000..09fa271 --- /dev/null +++ b/board/LaCie/common/gpio-ext.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2013 Simon Guinot simon.guinot@sequanux.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + */ + +#ifndef _LACIE_GPIO_EXT_H +#define _LACIE_GPIO_EXT_H + +struct gpio_ext { + unsigned *addr; + unsigned num_addr; + unsigned *data; + unsigned num_data; + unsigned enable; +}; + +void gpio_ext_set_value(struct gpio_ext *gpio_ext, + unsigned addr, unsigned value); + +#endif /* _LACIE_GPIO_EXT_H */

-----Original Message----- From: Simon Guinot [mailto:simon.guinot@sequanux.org] Sent: 18 June 2013 02:28 To: Prafulla Wadaskar Cc: Albert ARIBAUD; u-boot@lists.denx.de Subject: [PATCH 2/3] LaCie/common: add support for the GPIO extension bus
This patch adds support for the GPIO extension bus found on some LaCie boards (as the 2Big/5Big Network v2 and the 2Big NAS). This bus allows to configure the devices (mostly the LEDs) connected to a CPLD via two GPIO-based registers (address and data).
Hi Simon The name given here for the patch as well as files "gpio-ext" is confusing for me.
As you stated here those are the IOs generated by CPLD on your board which can be programmed using bit-banging on two GPIOs.
So to me it those are "cpld_ios".
May you please rename these files accordingly and resend the patch series for better understanding?
To me "gpio-ext" is generic term application for "General purpose IOs"
Regards... Prafulla . . .

On Mon, Jun 17, 2013 at 11:53:53PM -0700, Prafulla Wadaskar wrote:
-----Original Message----- From: Simon Guinot [mailto:simon.guinot@sequanux.org] Sent: 18 June 2013 02:28 To: Prafulla Wadaskar Cc: Albert ARIBAUD; u-boot@lists.denx.de Subject: [PATCH 2/3] LaCie/common: add support for the GPIO extension bus
This patch adds support for the GPIO extension bus found on some LaCie boards (as the 2Big/5Big Network v2 and the 2Big NAS). This bus allows to configure the devices (mostly the LEDs) connected to a CPLD via two GPIO-based registers (address and data).
Hi Simon
Hi Prafulla,
Thanks for your quick answer.
The name given here for the patch as well as files "gpio-ext" is confusing for me.
As you stated here those are the IOs generated by CPLD on your board which can be programmed using bit-banging on two GPIOs.
Not really bit-banging. Here we have 3 GPIOs used as a kind of address register and 3 other GPIOs used as a kind of data register. An another GPIO is used to notify the CPLD than the registers have been updated. I will update the patch description to make clear that a register may include several GPIOs.
At LaCie, this kind of bus is called a "GPIO extension bus". It is like a cheap GPIO expander.
So to me it those are "cpld_ios".
I am not sure that behind this kind of bus we always have a CPLD. I will check this. If it is the case, what do you think about cpld-gpio-bus ?
Moreover as this "bus" is really a lacie specific stuff, should I prepend a "lacie-" prefix ?
Regards,
Simon
May you please rename these files accordingly and resend the patch series for better understanding?
To me "gpio-ext" is generic term application for "General purpose IOs"
Regards... Prafulla . . .

-----Original Message----- From: Simon Guinot [mailto:simon.guinot@sequanux.org] Sent: 18 June 2013 15:59 To: Prafulla Wadaskar Cc: Albert ARIBAUD; u-boot@lists.denx.de Subject: Re: [PATCH 2/3] LaCie/common: add support for the GPIO extension bus
On Mon, Jun 17, 2013 at 11:53:53PM -0700, Prafulla Wadaskar wrote:
-----Original Message----- From: Simon Guinot
[mailto:simon.guinot@sequanux.org]
Sent: 18 June 2013 02:28 To: Prafulla Wadaskar Cc: Albert ARIBAUD; u-boot@lists.denx.de Subject: [PATCH 2/3] LaCie/common: add support for
the
GPIO extension bus
...snip...
At LaCie, this kind of bus is called a "GPIO extension bus". It is like a cheap GPIO expander.
So to me it those are "cpld_ios".
I am not sure that behind this kind of bus we always have a CPLD. I will check this. If it is the case, what do you think about cpld-gpio-bus ?
Even this sounds good to me, better than my suggestion earlier :).
Moreover as this "bus" is really a lacie specific stuff, should I prepend a "lacie-" prefix ?
This is not necessary I think.
Regards... Prafulla . . .

This patch allows to configure the net2big_v2 LEDs at startup (through the GPIO extension bus). The front blue LED is enabled and the SATA rear LEDs are configured to blink in relation with the SATA activity.
Signed-off-by: Simon Guinot simon.guinot@sequanux.org --- board/LaCie/net2big_v2/Makefile | 3 ++ board/LaCie/net2big_v2/net2big_v2.c | 86 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+)
diff --git a/board/LaCie/net2big_v2/Makefile b/board/LaCie/net2big_v2/Makefile index fbae48e..eca25e7 100644 --- a/board/LaCie/net2big_v2/Makefile +++ b/board/LaCie/net2big_v2/Makefile @@ -28,6 +28,9 @@ endif LIB = $(obj)lib$(BOARD).o
COBJS := $(BOARD).o ../common/common.o +ifneq ($(and $(CONFIG_KIRKWOOD_GPIO),$(CONFIG_NET2BIG_V2)),) +COBJS += ../common/gpio-ext.o +endif
SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(COBJS)) diff --git a/board/LaCie/net2big_v2/net2big_v2.c b/board/LaCie/net2big_v2/net2big_v2.c index 6cca4fb..caa9f64 100644 --- a/board/LaCie/net2big_v2/net2big_v2.c +++ b/board/LaCie/net2big_v2/net2big_v2.c @@ -30,6 +30,7 @@
#include "net2big_v2.h" #include "../common/common.h" +#include "../common/gpio-ext.h"
DECLARE_GLOBAL_DATA_PTR;
@@ -143,6 +144,89 @@ err: static void init_fan(void) {} #endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_G762_ADDR */
+#if defined(CONFIG_NET2BIG_V2) && defined(CONFIG_KIRKWOOD_GPIO) +/* + * GPIO extension bus: + * + * - address register : bit [0-2] -> GPIO [47-49] + * - data register : bit [0-2] -> GPIO [44-46] + * - enable register : GPIO 29 + */ +static unsigned gpio_ext_addr[] = { 47, 48, 49 }; +static unsigned gpio_ext_data[] = { 44, 45, 46 }; + +static struct gpio_ext gpio_ext = { + .addr = gpio_ext_addr, + .num_addr = ARRAY_SIZE(gpio_ext_addr), + .data = gpio_ext_data, + .num_data = ARRAY_SIZE(gpio_ext_data), + .enable = 29, +}; + +/* + * LEDs configuration: + * + * The LEDs are controlled by a CPLD and can be configured through + * the GPIO extension bus. + * + * Address register selection: + * + * addr | register + * ---------------------------- + * 0 | front LED + * 1 | front LED brightness + * 2 | SATA LED brightness + * 3 | SATA0 LED + * 4 | SATA1 LED + * 5 | SATA2 LED + * 6 | SATA3 LED + * 7 | SATA4 LED + * + * Data register configuration: + * + * data | LED brightness + * ------------------------------------------------- + * 0 | min (off) + * - | - + * 7 | max + * + * data | front LED mode + * ------------------------------------------------- + * 0 | fix off + * 1 | fix blue on + * 2 | fix red on + * 3 | blink blue on=1 sec and blue off=1 sec + * 4 | blink red on=1 sec and red off=1 sec + * 5 | blink blue on=2.5 sec and red on=0.5 sec + * 6 | blink blue on=1 sec and red on=1 sec + * 7 | blink blue on=0.5 sec and blue off=2.5 sec + * + * data | SATA LED mode + * ------------------------------------------------- + * 0 | fix off + * 1 | SATA activity blink + * 2 | fix red on + * 3 | blink blue on=1 sec and blue off=1 sec + * 4 | blink red on=1 sec and red off=1 sec + * 5 | blink blue on=2.5 sec and red on=0.5 sec + * 6 | blink blue on=1 sec and red on=1 sec + * 7 | fix blue on + */ +static void init_leds(void) +{ + /* Enable the front blue LED */ + gpio_ext_set_value(&gpio_ext, 0, 1); + gpio_ext_set_value(&gpio_ext, 1, 3); + + /* Configure SATA LEDs to blink in relation with the SATA activity */ + gpio_ext_set_value(&gpio_ext, 3, 1); + gpio_ext_set_value(&gpio_ext, 4, 1); + gpio_ext_set_value(&gpio_ext, 2, 3); +} +#else +static void init_leds(void) {} +#endif /* CONFIG_NET2BIG_V2 && CONFIG_KIRKWOOD_GPIO */ + int misc_init_r(void) { init_fan(); @@ -153,6 +237,8 @@ int misc_init_r(void) eth_setenv_enetaddr("ethaddr", mac); } #endif + init_leds(); + return 0; } #endif /* CONFIG_MISC_INIT_R */
participants (2)
-
Prafulla Wadaskar
-
Simon Guinot