Skip to contentSkip to conversation

lsxl: support power switch

PATCH New Michael Walle 2 participants 7 messages Jul 30, 2012 – Sep 3, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lsxl: support power switch

This patch restores the Linkstation's original behaviour when powering off. Once the (soft) power switch is turned off, linux will reboot and the bootloader turns off HDD and USB power. Then it loops as long as the switch is in the off position, before continuing the boot process again.

Additionally, this patch fixes the board function set_led(LED_OFF).

Cc Prafulla Wadaskar <[email protected]>
---
 board/buffalo/lsxl/lsxl.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
board/buffalo/lsxl/lsxl.c +21 -1
index fe15511..b3f31d6 100644
@@ -158,7 +158,7 @@ static void set_led(int state)
 {
 	switch (state) {
 	case LED_OFF:
-		__set_led(0, 0, 0, 0, 0, 0);
+		__set_led(0, 0, 0, 1, 1, 1);
 		break;
 	case LED_ALARM_ON:
 		__set_led(0, 0, 0, 0, 1, 1);
@@ -192,6 +192,25 @@ int board_init(void)
 }
 
 #ifdef CONFIG_MISC_INIT_R
+static void check_power_switch(void)
+{
+	if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
+		/* turn off HDD and USB power */
+		kw_gpio_set_value(GPIO_HDD_POWER, 0);
+		kw_gpio_set_value(GPIO_USB_VBUS, 0);
+		set_led(LED_OFF);
+
+		/* loop until released */
+		while (kw_gpio_get_value(GPIO_POWER_SWITCH))
+			;
+
+		/* turn power on again */
+		kw_gpio_set_value(GPIO_HDD_POWER, 1);
+		kw_gpio_set_value(GPIO_USB_VBUS, 1);
+		set_led(LED_POWER_BLINKING);
+	}
+}
+
 void check_enetaddr(void)
 {
 	uchar enetaddr[6];
@@ -261,6 +280,7 @@ static void check_push_button(void)
 
 int misc_init_r(void)
 {
+	check_power_switch();
 	check_enetaddr();
 	check_push_button();
 
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH 1/1 lsxl: support power switch

Quoted 42 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 02:17
To: u-boot at lists.denx.de
Cc: Michael Walle; Prafulla Wadaskar
Subject: [PATCH] lsxl: support power switch

This patch restores the Linkstation's original behaviour when powering off.
Once the (soft) power switch is turned off, linux will reboot and the bootloader turns off HDD and USB power. Then it loops as long as the switch
is in the off position, before continuing the boot process again.

Additionally, this patch fixes the board function set_led(LED_OFF).

Cc Prafulla Wadaskar <[email protected]>
---
 board/buffalo/lsxl/lsxl.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
board/buffalo/lsxl/lsxl.c +2 -1
index fe15511..b3f31d6 100644
@@ -158,7 +158,7 @@ static void set_led(int state)
 {
 	switch (state) {
 	case LED_OFF:
-		__set_led(0, 0, 0, 0, 0, 0);
+		__set_led(0, 0, 0, 1, 1, 1);
 		break;
 	case LED_ALARM_ON:
 		__set_led(0, 0, 0, 0, 1, 1);
@@ -192,6 +192,25 @@ int board_init(void)
 }
 
 #ifdef CONFIG_MISC_INIT_R
+static void check_power_switch(void)

board/buffalo/lsxl/lsxl.c int board_init(void) · line 205

Quoted 10 lines
board/buffalo/lsxl/lsxl.c +10 -0
+{
+	if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
+		/* turn off HDD and USB power */
+		kw_gpio_set_value(GPIO_HDD_POWER, 0);
+		kw_gpio_set_value(GPIO_USB_VBUS, 0);
+		set_led(LED_OFF);
+
+		/* loop until released */
+		while (kw_gpio_get_value(GPIO_POWER_SWITCH))
+			;

Please avoid infinite loop, may you introduce timeout?

Quoted 12 lines
board/buffalo/lsxl/lsxl.c +8 -0
+
+		/* turn power on again */
+		kw_gpio_set_value(GPIO_HDD_POWER, 1);
+		kw_gpio_set_value(GPIO_USB_VBUS, 1);
+		set_led(LED_POWER_BLINKING);
+	}
+}
+
 void check_enetaddr(void)
 {
 	uchar enetaddr[6];

board/buffalo/lsxl/lsxl.c static void check_push_button(void) · line 285

Quoted 6 lines
board/buffalo/lsxl/lsxl.c +1 -0
@@ -261,6 +280,7 @@ static void check_push_button(void)
 
 int misc_init_r(void)
 {
+	check_power_switch();
 	check_enetaddr();
 	check_push_button();

Ack for rest of the code.

Regards...
Prafulla . . .

#2 lore raw

PATCH 1/1 lsxl: support power switch

Quoted 40 lines · Prafulla Wadaskar
Quoted 40 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 02:17
To: u-boot at lists.denx.de
Cc: Michael Walle; Prafulla Wadaskar
Subject: [PATCH] lsxl: support power switch

This patch restores the Linkstation's original behaviour when powering off.
Once the (soft) power switch is turned off, linux will reboot and the bootloader turns off HDD and USB power. Then it loops as long as the switch
is in the off position, before continuing the boot process again.

Additionally, this patch fixes the board function set_led(LED_OFF).

Cc Prafulla Wadaskar <[email protected]>
---
 board/buffalo/lsxl/lsxl.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
board/buffalo/lsxl/lsxl.c +1 -1
index fe15511..b3f31d6 100644
@@ -158,7 +158,7 @@ static void set_led(int state)
 {
 	switch (state) {
 	case LED_OFF:
-		__set_led(0, 0, 0, 0, 0, 0);
+		__set_led(0, 0, 0, 1, 1, 1);
 		break;
 	case LED_ALARM_ON:
 		__set_led(0, 0, 0, 0, 1, 1);
@@ -192,6 +192,25 @@ int board_init(void)
 }
 
Quoted 14 lines

board/buffalo/lsxl/lsxl.c int board_init(void) · line 205

Quoted 12 lines
board/buffalo/lsxl/lsxl.c +11 -0
 #ifdef CONFIG_MISC_INIT_R
+static void check_power_switch(void)
+{
+	if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
+		/* turn off HDD and USB power */
+		kw_gpio_set_value(GPIO_HDD_POWER, 0);
+		kw_gpio_set_value(GPIO_USB_VBUS, 0);
+		set_led(LED_OFF);
+
+		/* loop until released */
+		while (kw_gpio_get_value(GPIO_POWER_SWITCH))
+			;

Please avoid infinite loop, may you introduce timeout?

actually, thats the use case, to loop indefinitely ;) See the commit message. The GPIO is a switch not a button. As long as it is switched to "Power Off" uboot should loop.

Quoted 14 lines
Quoted 14 lines
board/buffalo/lsxl/lsxl.c +8 -0
+
+		/* turn power on again */
+		kw_gpio_set_value(GPIO_HDD_POWER, 1);
+		kw_gpio_set_value(GPIO_USB_VBUS, 1);
+		set_led(LED_POWER_BLINKING);
+	}
+}
+
 void check_enetaddr(void)
 {
 	uchar enetaddr[6];
@@ -261,6 +280,7 @@ static void check_push_button(void)
 
Quoted 7 lines

board/buffalo/lsxl/lsxl.c static void check_push_button(void) · line 285

Quoted 5 lines
board/buffalo/lsxl/lsxl.c +1 -0
 int misc_init_r(void)
 {
+	check_power_switch();
 	check_enetaddr();
 	check_push_button();

Ack for rest of the code.

Thanks for the review.

Signature · 1 line
michael
#3 lore raw

PATCH 1/1 lsxl: support power switch

Quoted 68 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 16:22
To: Prafulla Wadaskar
Cc: Michael Walle; u-boot at lists.denx.de
Subject: RE: [PATCH] lsxl: support power switch

Quoted 10 lines · Prafulla Wadaskar
Quoted 10 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 02:17
To: u-boot at lists.denx.de
Cc: Michael Walle; Prafulla Wadaskar
Subject: [PATCH] lsxl: support power switch

This patch restores the Linkstation's original behaviour when

powering

Quoted 2 lines
Quoted 2 lines

off.
Once the (soft) power switch is turned off, linux will reboot and

the

Quoted 1 line
Quoted 1 line

bootloader turns off HDD and USB power. Then it loops as long as

the

Quoted 27 lines
Quoted 27 lines

switch
is in the off position, before continuing the boot process again.

Additionally, this patch fixes the board function set_led(LED_OFF).

Cc Prafulla Wadaskar <[email protected]>
---
 board/buffalo/lsxl/lsxl.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
board/buffalo/lsxl/lsxl.c +1 -1
index fe15511..b3f31d6 100644
@@ -158,7 +158,7 @@ static void set_led(int state)
 {
 	switch (state) {
 	case LED_OFF:
-		__set_led(0, 0, 0, 0, 0, 0);
+		__set_led(0, 0, 0, 1, 1, 1);
 		break;
 	case LED_ALARM_ON:
 		__set_led(0, 0, 0, 0, 1, 1);
@@ -192,6 +192,25 @@ int board_init(void)
 }
 
Quoted 14 lines

board/buffalo/lsxl/lsxl.c int board_init(void) · line 205

Quoted 12 lines
board/buffalo/lsxl/lsxl.c +11 -0
 #ifdef CONFIG_MISC_INIT_R
+static void check_power_switch(void)
+{
+	if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
+		/* turn off HDD and USB power */
+		kw_gpio_set_value(GPIO_HDD_POWER, 0);
+		kw_gpio_set_value(GPIO_USB_VBUS, 0);
+		set_led(LED_OFF);
+
+		/* loop until released */
+		while (kw_gpio_get_value(GPIO_POWER_SWITCH))
+			;

Please avoid infinite loop, may you introduce timeout?

Quoted 4 lines

actually, thats the use case, to loop indefinitely ;) See the commit message. The GPIO is a switch not a button. As long as it is switched to
"Power Off" uboot should loop.

Okay got it.
Ack for this patch.

Regards...
Prafulla . . .

#4 lore raw

PATCH 1/1 lsxl: support power switch

Am Dienstag 31 Juli 2012, 13:12:19 schrieb Prafulla Wadaskar:

Quoted 79 lines
Quoted 79 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 16:22
To: Prafulla Wadaskar
Cc: Michael Walle; u-boot at lists.denx.de
Subject: RE: [PATCH] lsxl: support power switch

Quoted 8 lines · Prafulla Wadaskar
Quoted 8 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 02:17
To: u-boot at lists.denx.de
Cc: Michael Walle; Prafulla Wadaskar
Subject: [PATCH] lsxl: support power switch

This patch restores the Linkstation's original behaviour when

powering

Quoted 2 lines
Quoted 2 lines

off.
Once the (soft) power switch is turned off, linux will reboot and

the

Quoted 1 line
Quoted 1 line

bootloader turns off HDD and USB power. Then it loops as long as

the

Quoted 50 lines
Quoted 38 lines

switch
is in the off position, before continuing the boot process again.

Additionally, this patch fixes the board function set_led(LED_OFF).

Cc Prafulla Wadaskar <[email protected]>

---

 board/buffalo/lsxl/lsxl.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
board/buffalo/lsxl/lsxl.c +1 -1
index fe15511..b3f31d6 100644
@@ -158,7 +158,7 @@ static void set_led(int state)
 
 {
 
 	switch (state) {
 
 	case LED_OFF:
-		__set_led(0, 0, 0, 0, 0, 0);
+		__set_led(0, 0, 0, 1, 1, 1);
board/buffalo/lsxl/lsxl.c +1 -0
 		break;
 
 	case LED_ALARM_ON:
 		__set_led(0, 0, 0, 0, 1, 1);
@@ -192,6 +192,25 @@ int board_init(void)
 
 }
 
 #ifdef CONFIG_MISC_INIT_R
 
+static void check_power_switch(void)

board/buffalo/lsxl/lsxl.c int board_init(void) · line 207

Quoted 10 lines
board/buffalo/lsxl/lsxl.c +10 -0
+{
+	if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
+		/* turn off HDD and USB power */
+		kw_gpio_set_value(GPIO_HDD_POWER, 0);
+		kw_gpio_set_value(GPIO_USB_VBUS, 0);
+		set_led(LED_OFF);
+
+		/* loop until released */
+		while (kw_gpio_get_value(GPIO_POWER_SWITCH))
+			;

Please avoid infinite loop, may you introduce timeout?

Quoted 7 lines
Quoted 4 lines

actually, thats the use case, to loop indefinitely ;) See the commit message. The GPIO is a switch not a button. As long as it is switched to
"Power Off" uboot should loop.

Okay got it.
Ack for this patch.

ok thanks, can you apply it to your repository?

Signature · 1 line
michael
#5 lore raw

PATCH 1/1 lsxl: support power switch

Quoted 97 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 01 August 2012 01:58
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de
Subject: Re: [PATCH] lsxl: support power switch

Am Dienstag 31 Juli 2012, 13:12:19 schrieb Prafulla Wadaskar:

Quoted 15 lines
Quoted 15 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 16:22
To: Prafulla Wadaskar
Cc: Michael Walle; u-boot at lists.denx.de
Subject: RE: [PATCH] lsxl: support power switch

Quoted 7 lines · Prafulla Wadaskar
Quoted 7 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 02:17
To: u-boot at lists.denx.de
Cc: Michael Walle; Prafulla Wadaskar
Subject: [PATCH] lsxl: support power switch

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

This patch restores the Linkstation's original behaviour when

powering

Quoted 2 lines
Quoted 2 lines

off.
Once the (soft) power switch is turned off, linux will reboot

and

Quoted 4 lines
Quoted 4 lines

the

Quoted 1 line
Quoted 1 line

bootloader turns off HDD and USB power. Then it loops as long

as

Quoted 5 lines
Quoted 5 lines

the

Quoted 2 lines
Quoted 2 lines

switch
is in the off position, before continuing the boot process

again.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Additionally, this patch fixes the board function

set_led(LED_OFF).

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
Cc Prafulla Wadaskar <[email protected]>

---

 board/buffalo/lsxl/lsxl.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/board/buffalo/lsxl/lsxl.c

Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 25 lines

index fe15511..b3f31d6 100644

board/buffalo/lsxl/lsxl.c +1 -1
@@ -158,7 +158,7 @@ static void set_led(int state)
 
 {
 
 	switch (state) {
 
 	case LED_OFF:
-		__set_led(0, 0, 0, 0, 0, 0);
+		__set_led(0, 0, 0, 1, 1, 1);
board/buffalo/lsxl/lsxl.c +1 -0
 		break;
 
 	case LED_ALARM_ON:
 		__set_led(0, 0, 0, 0, 1, 1);
@@ -192,6 +192,25 @@ int board_init(void)
 
 }
 
 #ifdef CONFIG_MISC_INIT_R
 
+static void check_power_switch(void)

board/buffalo/lsxl/lsxl.c int board_init(void) · line 207

Quoted 10 lines
board/buffalo/lsxl/lsxl.c +10 -0
+{
+	if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
+		/* turn off HDD and USB power */
+		kw_gpio_set_value(GPIO_HDD_POWER, 0);
+		kw_gpio_set_value(GPIO_USB_VBUS, 0);
+		set_led(LED_OFF);
+
+		/* loop until released */
+		while (kw_gpio_get_value(GPIO_POWER_SWITCH))
+			;

Please avoid infinite loop, may you introduce timeout?

Quoted 1 line
Quoted 1 line

actually, thats the use case, to loop indefinitely ;) See the

commit

Quoted 1 line
Quoted 1 line

message. The GPIO is a switch not a button. As long as it is

Quoted 9 lines

switched

Quoted 5 lines
Quoted 2 lines

to
"Power Off" uboot should loop.

Okay got it.
Ack for this patch.

ok thanks, can you apply it to your repository?

Sure..

Regards...
Prafulla . . .

#6 lore raw

PATCH 1/1 lsxl: support power switch

In reply to Michael Walle
Quoted 110 lines

-----Original Message-----
From: Prafulla Wadaskar
Sent: 01 August 2012 12:58
To: 'Michael Walle'
Cc: u-boot at lists.denx.de
Subject: RE: [PATCH] lsxl: support power switch

Quoted 99 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 01 August 2012 01:58
To: Prafulla Wadaskar
Cc: u-boot at lists.denx.de
Subject: Re: [PATCH] lsxl: support power switch

Am Dienstag 31 Juli 2012, 13:12:19 schrieb Prafulla Wadaskar:

Quoted 15 lines
Quoted 15 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 16:22
To: Prafulla Wadaskar
Cc: Michael Walle; u-boot at lists.denx.de
Subject: RE: [PATCH] lsxl: support power switch

Quoted 7 lines · Prafulla Wadaskar
Quoted 7 lines

-----Original Message-----
From: Michael Walle [mailto:michael at walle.cc]
Sent: 31 July 2012 02:17
To: u-boot at lists.denx.de
Cc: Michael Walle; Prafulla Wadaskar
Subject: [PATCH] lsxl: support power switch

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

This patch restores the Linkstation's original behaviour when

powering

Quoted 2 lines
Quoted 2 lines

off.
Once the (soft) power switch is turned off, linux will reboot

and

Quoted 4 lines
Quoted 4 lines

the

Quoted 1 line
Quoted 1 line

bootloader turns off HDD and USB power. Then it loops as long

as

Quoted 5 lines
Quoted 5 lines

the

Quoted 2 lines
Quoted 2 lines

switch
is in the off position, before continuing the boot process

again.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Additionally, this patch fixes the board function

set_led(LED_OFF).

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
Cc Prafulla Wadaskar <[email protected]>

---

 board/buffalo/lsxl/lsxl.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/board/buffalo/lsxl/lsxl.c

Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 25 lines

index fe15511..b3f31d6 100644

board/buffalo/lsxl/lsxl.c +1 -1
@@ -158,7 +158,7 @@ static void set_led(int state)
 
 {
 
 	switch (state) {
 
 	case LED_OFF:
-		__set_led(0, 0, 0, 0, 0, 0);
+		__set_led(0, 0, 0, 1, 1, 1);
board/buffalo/lsxl/lsxl.c +1 -0
 		break;
 
 	case LED_ALARM_ON:
 		__set_led(0, 0, 0, 0, 1, 1);
@@ -192,6 +192,25 @@ int board_init(void)
 
 }
 
 #ifdef CONFIG_MISC_INIT_R
 
+static void check_power_switch(void)

board/buffalo/lsxl/lsxl.c int board_init(void) · line 207

Quoted 10 lines
board/buffalo/lsxl/lsxl.c +10 -0
+{
+	if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
+		/* turn off HDD and USB power */
+		kw_gpio_set_value(GPIO_HDD_POWER, 0);
+		kw_gpio_set_value(GPIO_USB_VBUS, 0);
+		set_led(LED_OFF);
+
+		/* loop until released */
+		while (kw_gpio_get_value(GPIO_POWER_SWITCH))
+			;

Please avoid infinite loop, may you introduce timeout?

Quoted 1 line
Quoted 1 line

actually, thats the use case, to loop indefinitely ;) See the

commit

Quoted 1 line
Quoted 1 line

message. The GPIO is a switch not a button. As long as it is

switched

Quoted 3 lines
Quoted 2 lines

to
"Power Off" uboot should loop.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Okay got it.
Ack for this patch.

ok thanks, can you apply it to your repository?

Sure..

Applied to u-boot-marvell.git master branch

Regards...
Prafulla . . .