[loongson-PATCH-v3 16/25] enable halt command for yeeloong-7inch laptop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Wu Zhangjin <wuzj@xxxxxxxxxx>

the only differences between yeeloong-7inch and yeeloong-8.9inc are the
screen size and shutdown logic. here only focus on the shutdown logic,
the screen size handling will be fixed later.

currently, I add two new kernel config options LEMOTE_YEELOONG_7INCH and
LEMOTE_YEELOONG_89INCH to let user select a suitable kernel for his
yeeloong laptop.

Signed-off-by: Wu Zhangjin <wuzj@xxxxxxxxxx>
---
 arch/mips/include/asm/mach-loongson/loongson.h |    7 +++++
 arch/mips/include/asm/mach-loongson/machine.h  |   18 ++++++++++--
 arch/mips/loongson/Kconfig                     |   12 ++++++++
 arch/mips/loongson/yeeloong-2f/reset.c         |   34 +++++++++++++++++++++--
 4 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/arch/mips/include/asm/mach-loongson/loongson.h b/arch/mips/include/asm/mach-loongson/loongson.h
index cd6668b..ea99209 100644
--- a/arch/mips/include/asm/mach-loongson/loongson.h
+++ b/arch/mips/include/asm/mach-loongson/loongson.h
@@ -44,6 +44,13 @@ extern void mach_irq_dispatch(unsigned int pending);
 extern void mach_prepare_reboot(void);
 extern void mach_prepare_shutdown(void);
 
+/* We need this in some places... */
+#define delay()	({			\
+	int x;					\
+	for (x = 0; x < 100000; x++)  \
+		__asm__ __volatile__(""); \
+})
+
 #define LOONGSON_REG(x) \
 	(*(u32 *)((char *)CKSEG1ADDR(LOONGSON_REG_BASE) + (x)))
 #define LOONGSON_IRQ_BASE	32
diff --git a/arch/mips/include/asm/mach-loongson/machine.h b/arch/mips/include/asm/mach-loongson/machine.h
index c920d39..15d8b93 100644
--- a/arch/mips/include/asm/mach-loongson/machine.h
+++ b/arch/mips/include/asm/mach-loongson/machine.h
@@ -50,13 +50,25 @@
  * 2, fill the PORT_LOW as EC register low part.
  * 3, fill the PORT_DATA as EC register write data or get the data from it.
  */
-#define	EC_IO_PORT_HIGH	0x0381
-#define	EC_IO_PORT_LOW	0x0382
-#define	EC_IO_PORT_DATA	0x0383
+#define	EC_RESET_IO_PORT_HIGH	0x0381
+#define	EC_RESET_IO_PORT_LOW	0x0382
+#define	EC_RESET_IO_PORT_DATA	0x0383
 #define	REG_RESET_HIGH	0xF4	/* reset the machine auto-clear : rd/wr */
 #define REG_RESET_LOW	0xEC
 #define	BIT_RESET_ON	(1 << 0)
 
+/* 7inch yeeloong have the different shutdown hardware logic from 8.9inch */
+#ifdef CONFIG_LEMOTE_YEELOONG2F_7INCH
+
+#define	EC_SHUTDOWN_IO_PORT_HIGH	0xff2d
+#define	EC_SHUTDOWN_IO_PORT_LOW		0xff2e
+#define	EC_SHUTDOWN_IO_PORT_DATA	0xff2f
+#define	REG_SHUTDOWN_HIGH	0xFC
+#define REG_SHUTDOWN_LOW	0x29
+#define	BIT_SHUTDOWN_ON	(1 << 1)
+
+#endif
+
 #endif	/* !CONFIG_LEMOTE_FULOONG2E */
 
 /* fuloong2f and yeeloong2f have the same IRQ control interface */
diff --git a/arch/mips/loongson/Kconfig b/arch/mips/loongson/Kconfig
index 9cc817f..63d00c1 100644
--- a/arch/mips/loongson/Kconfig
+++ b/arch/mips/loongson/Kconfig
@@ -93,6 +93,18 @@ config LEMOTE_YEELOONG2F
 
 endchoice
 
+choice
+	prompt "YeeLoong Type"
+	depends on LEMOTE_YEELOONG2F
+
+config LEMOTE_YEELOONG2F_89INCH
+	bool "8.9 inch"
+
+config LEMOTE_YEELOONG2F_7INCH
+	bool "7 inch"
+
+endchoice
+
 config CS5536
 	bool
 
diff --git a/arch/mips/loongson/yeeloong-2f/reset.c b/arch/mips/loongson/yeeloong-2f/reset.c
index a3719a4..294592f 100644
--- a/arch/mips/loongson/yeeloong-2f/reset.c
+++ b/arch/mips/loongson/yeeloong-2f/reset.c
@@ -24,17 +24,45 @@ void mach_prepare_reboot(void)
 	LOONGSON_CHIPCFG0 |= 0x7;
 
 	/* sending an reset signal to EC(embedded controller) */
-	writeb(REG_RESET_HIGH, (u8 *) (mips_io_port_base + EC_IO_PORT_HIGH));
-	writeb(REG_RESET_LOW, (u8 *) (mips_io_port_base + EC_IO_PORT_LOW));
+	writeb(REG_RESET_HIGH,
+	       (u8 *) (mips_io_port_base + EC_RESET_IO_PORT_HIGH));
+	writeb(REG_RESET_LOW,
+	       (u8 *) (mips_io_port_base + EC_RESET_IO_PORT_LOW));
 	mmiowb();
-	writeb(BIT_RESET_ON, (u8 *) (mips_io_port_base + EC_IO_PORT_DATA));
+	writeb(BIT_RESET_ON,
+	       (u8 *) (mips_io_port_base + EC_RESET_IO_PORT_DATA));
 	mmiowb();
 }
 
 void mach_prepare_shutdown(void)
 {
+#ifdef CONFIG_LEMOTE_YEELOONG2F_7INCH
+	{
+		u8 val;
+		u64 i;
+
+		writeb(REG_SHUTDOWN_HIGH,
+		       (u8 *) (mips_io_port_base + EC_SHUTDOWN_IO_PORT_HIGH));
+		writeb(REG_SHUTDOWN_LOW,
+		       (u8 *) (mips_io_port_base + EC_SHUTDOWN_IO_PORT_LOW));
+		mmiowb();
+		val =
+		    readb((u8 *) (mips_io_port_base +
+				  EC_SHUTDOWN_IO_PORT_DATA));
+		writeb(val & (~BIT_SHUTDOWN_ON),
+		       (u8 *) (mips_io_port_base + EC_SHUTDOWN_IO_PORT_DATA));
+		mmiowb();
+		/* need enough wait here... how many microseconds needs? */
+		for (i = 0; i < 0x10000; i++)
+			delay();
+		writeb(val | BIT_SHUTDOWN_ON,
+		       (u8 *) (mips_io_port_base + EC_SHUTDOWN_IO_PORT_DATA));
+		mmiowb();
+	}
+#else
 	/* cpu-gpio0 output low */
 	LOONGSON_GPIODATA &= ~0x00000001;
 	/* cpu-gpio0 as output */
 	LOONGSON_GPIOIE &= ~0x00000001;
+#endif
 }
-- 
1.6.0.4



[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux