Skip to contentSkip to conversation

Loongson: YeeLoong: add platform specific driver

PATCH Superseded Wu Zhangjin 2 participants 19 messages Dec 4, 2009 – Dec 8, 2009

Subsystems (2)

v7 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v7 cover Loongson: YeeLoong: add platform specific driver

From: Wu Zhangjin <[email protected]>

This patchset adds platform specific drivers for YeeLoong netbook. including the backlight, battery, hwmon, video output, suspend and hotkey(input) subdrivers. These drivers provide standard interfaces to the user-space applications to manage the related devices:

Subdrivers Applicatioins.

- backlight
/sys/class/backlight/ kpowersave, gnome-power-manager
- battery
/proc/apm kpowersave, gnome-power-manager
- hwmon
/sys/class/hwmon/ lm-sensors, sensors-applet...
- video output
/sys/class/video_output ?
- hotkey
/sys/class/input/ gnome-settings-daemon ?
- platform(suspend)
/sys/power/state kpowersave, gnome-power-manager

Changes from v6:

- Move the whole stuff back to drivers/platform/mips/

It's very difficult to find a good place to put it in, so, just did what the folks have done under drivers/platform/x86/

- Rebase the hotkey driver on the sparse keymap library from Dmitry Torokhov.

- Load this module automatically
Register a platform device, bind it with this module.

- Fixup of battery subdriver
Ensure apm_get_power_status is NULL when exit.

Wu Zhangjin (8):
MIPS: add subdirectory for platform extension drivers
Loongson: YeeLoong: add platform driver
Loongson: YeeLoong: add backlight driver
Loongson: YeeLoong: add battery driver
Loongson: YeeLoong: add hardware monitoring driver
Loongson: YeeLoong: add video output driver
Loongson: YeeLoong: add suspend support
Loongson: YeeLoong: add input/hotkey driver

 arch/mips/include/asm/mach-loongson/ec_kb3310b.h |  191 ++++
 arch/mips/include/asm/mach-loongson/loongson.h   |    6 +
 arch/mips/loongson/common/cmdline.c              |    8 +
 arch/mips/loongson/lemote-2f/Makefile            |    2 +-
 arch/mips/loongson/lemote-2f/ec_kb3310b.c        |   12 +-
 arch/mips/loongson/lemote-2f/ec_kb3310b.h        |  188 ----
 arch/mips/loongson/lemote-2f/platform.c          |   40 +
 arch/mips/loongson/lemote-2f/pm.c                |    4 +-
 arch/mips/loongson/lemote-2f/reset.c             |    2 +-
 drivers/platform/Kconfig                         |    4 +
 drivers/platform/Makefile                        |    1 +
 drivers/platform/mips/Kconfig                    |   33 +
 drivers/platform/mips/Makefile                   |    5 +
 drivers/platform/mips/yeeloong_laptop.c          | 1067 ++++++++++++++++++++++
 14 files changed, 1363 insertions(+), 200 deletions(-)
 create mode 100644 arch/mips/include/asm/mach-loongson/ec_kb3310b.h
 delete mode 100644 arch/mips/loongson/lemote-2f/ec_kb3310b.h
 create mode 100644 arch/mips/loongson/lemote-2f/platform.c
 create mode 100644 drivers/platform/mips/Kconfig
 create mode 100644 drivers/platform/mips/Makefile
 create mode 100644 drivers/platform/mips/yeeloong_laptop.c
#1 lore raw

PATCH v7 1/8 MIPS: add subdirectory for platform extension drivers

From: Wu Zhangjin <[email protected]>

It is really hard to split the platform specific subdrivers into different subsystems, which will generate lots of duplicated source code, break the whole support into several pieces and also will make the users be difficult to choose the suitable subdrivers in different places.

So, I did like the forks have done under drivers/platform/x86, created the drivers/platform/mips/ for putting the future MIPS netbook/laptop/pc extension drivers in.

---
 drivers/platform/Kconfig      |    4 ++++
 drivers/platform/mips/Kconfig |   18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 drivers/platform/mips/Kconfig
drivers/platform/Kconfig +4 -0
index 9652c3f..2319c0b 100644
@@ -3,3 +3,7 @@
 if X86
 source "drivers/platform/x86/Kconfig"
 endif
+
+if MIPS
+source "drivers/platform/mips/Kconfig"
+endif
drivers/platform/mips/Kconfig new file +18 -0
new file mode 100644
index 0000000..2f77693
@@ -0,0 +1,18 @@
+#
+# MIPS Platform Specific Drivers
+#
+
+menuconfig MIPS_PLATFORM_DEVICES
+	bool "MIPS Platform Specific Device Drivers"
+	default y
+	help
+	  Say Y here to get to see options for device drivers of various
+	  MIPS platforms, including vendor-specific netbook/laptop/pc extension
+	  drivers.  This option alone does not add any kernel code.
+
+	  If you say N, all options in this submenu will be skipped and disabled.
+
+if MIPS_PLATFORM_DEVICES
+
+
+endif # MIPS_PLATFORM_DEVICES
Signature · 1 line
1.6.2.1
#2 lore raw

PATCH v7 2/8 Loongson: YeeLoong: add platform driver

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds platform driver for YeeLoong, Currently, This driver is "empty", the subdrivers will be added in the coming patches.

---
 arch/mips/include/asm/mach-loongson/ec_kb3310b.h |  191 ++++++++++++++++++++++
 arch/mips/loongson/lemote-2f/Makefile            |    2 +-
 arch/mips/loongson/lemote-2f/ec_kb3310b.c        |   12 +-
 arch/mips/loongson/lemote-2f/ec_kb3310b.h        |  188 ---------------------
 arch/mips/loongson/lemote-2f/platform.c          |   40 +++++
 arch/mips/loongson/lemote-2f/pm.c                |    4 +-
 arch/mips/loongson/lemote-2f/reset.c             |    2 +-
 drivers/platform/Makefile                        |    1 +
 drivers/platform/mips/Kconfig                    |    9 +
 drivers/platform/mips/Makefile                   |    5 +
 drivers/platform/mips/yeeloong_laptop.c          |   60 +++++++
 11 files changed, 314 insertions(+), 200 deletions(-)
 create mode 100644 arch/mips/include/asm/mach-loongson/ec_kb3310b.h
 delete mode 100644 arch/mips/loongson/lemote-2f/ec_kb3310b.h
 create mode 100644 arch/mips/loongson/lemote-2f/platform.c
 create mode 100644 drivers/platform/mips/Makefile
 create mode 100644 drivers/platform/mips/yeeloong_laptop.c
arch/mips/include/asm/mach-loongson/ec_kb3310b.h new file +191 -0
new file mode 100644
index 0000000..4fccb5d
@@ -0,0 +1,191 @@
+/*
+ * KB3310B Embedded Controller
+ *
+ *  Copyright (C) 2008 Lemote Inc.
+ *  Author: liujl <[email protected]>, 2008-03-14
+ *  Copyright (C) 2009 Lemote Inc.
+ *  Author: Wu Zhangjin <[email protected]>
+ *
+ * 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 _EC_KB3310B_H
+#define _EC_KB3310B_H
+
+extern unsigned char ec_read(unsigned short addr);
+extern void ec_write(unsigned short addr, unsigned char val);
+extern int ec_query_seq(unsigned char cmd);
+extern int ec_query_event_num(void);
+extern int ec_get_event_num(void);
+
+typedef int (*sci_handler) (int status);
+extern sci_handler yeeloong_report_lid_status;
+
+#define SCI_IRQ_NUM 0x0A
+
+/*
+ * The following registers are determined by the EC index configuration.
+ * 1, fill the PORT_HIGH as EC register high part.
+ * 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
+
+/*
+ * EC delay time is 500us for register and status access
+ */
+#define	EC_REG_DELAY	500	/* unit : us */
+#define	EC_CMD_TIMEOUT	0x1000
+
+/*
+ * EC access port for SCI communication
+ */
+#define	EC_CMD_PORT		0x66
+#define	EC_STS_PORT		0x66
+#define	EC_DAT_PORT		0x62
+#define	CMD_INIT_IDLE_MODE	0xdd
+#define	CMD_EXIT_IDLE_MODE	0xdf
+#define	CMD_INIT_RESET_MODE	0xd8
+#define	CMD_REBOOT_SYSTEM	0x8c
+#define	CMD_GET_EVENT_NUM	0x84
+#define	CMD_PROGRAM_PIECE	0xda
+
+/* Temperature & Fan registers */
+#define	REG_TEMPERATURE_VALUE	0xF458
+#define	REG_FAN_AUTO_MAN_SWITCH 0xF459
+#define	BIT_FAN_AUTO		0
+#define	BIT_FAN_MANUAL		1
+#define	REG_FAN_CONTROL		0xF4D2
+#define	BIT_FAN_CONTROL_ON	(1 << 0)
+#define	BIT_FAN_CONTROL_OFF	(0 << 0)
+#define	REG_FAN_STATUS		0xF4DA
+#define	BIT_FAN_STATUS_ON	(1 << 0)
+#define	BIT_FAN_STATUS_OFF	(0 << 0)
+#define	REG_FAN_SPEED_HIGH	0xFE22
+#define	REG_FAN_SPEED_LOW	0xFE23
+#define	REG_FAN_SPEED_LEVEL	0xF4CC
+/* Fan speed divider */
+#define	FAN_SPEED_DIVIDER	480000	/* (60*1000*1000/62.5/2)*/
+
+/* Battery registers */
+#define	REG_BAT_DESIGN_CAP_HIGH		0xF77D
+#define	REG_BAT_DESIGN_CAP_LOW		0xF77E
+#define	REG_BAT_FULLCHG_CAP_HIGH	0xF780
+#define	REG_BAT_FULLCHG_CAP_LOW		0xF781
+#define	REG_BAT_DESIGN_VOL_HIGH		0xF782
+#define	REG_BAT_DESIGN_VOL_LOW		0xF783
+#define	REG_BAT_CURRENT_HIGH		0xF784
+#define	REG_BAT_CURRENT_LOW		0xF785
+#define	REG_BAT_VOLTAGE_HIGH		0xF786
+#define	REG_BAT_VOLTAGE_LOW		0xF787
+#define	REG_BAT_TEMPERATURE_HIGH	0xF788
+#define	REG_BAT_TEMPERATURE_LOW		0xF789
+#define	REG_BAT_RELATIVE_CAP_HIGH	0xF492
+#define	REG_BAT_RELATIVE_CAP_LOW	0xF493
+#define	REG_BAT_VENDOR			0xF4C4
+#define	FLAG_BAT_VENDOR_SANYO		0x01
+#define	FLAG_BAT_VENDOR_SIMPLO		0x02
+#define	REG_BAT_CELL_COUNT		0xF4C6
+#define	FLAG_BAT_CELL_3S1P		0x03
+#define	FLAG_BAT_CELL_3S2P		0x06
+#define	REG_BAT_CHARGE			0xF4A2
+#define	FLAG_BAT_CHARGE_DISCHARGE	0x01
+#define	FLAG_BAT_CHARGE_CHARGE		0x02
+#define	FLAG_BAT_CHARGE_ACPOWER		0x00
+#define	REG_BAT_STATUS			0xF4B0
+#define	BIT_BAT_STATUS_LOW		(1 << 5)
+#define	BIT_BAT_STATUS_DESTROY		(1 << 2)
+#define	BIT_BAT_STATUS_FULL		(1 << 1)
+#define	BIT_BAT_STATUS_IN		(1 << 0)
+#define	REG_BAT_CHARGE_STATUS		0xF4B1
+#define	BIT_BAT_CHARGE_STATUS_OVERTEMP	(1 << 2)
+#define	BIT_BAT_CHARGE_STATUS_PRECHG	(1 << 1)
+#define	REG_BAT_STATE			0xF482
+#define	BIT_BAT_STATE_CHARGING		(1 << 1)
+#define	BIT_BAT_STATE_DISCHARGING	(1 << 0)
+#define	REG_BAT_POWER			0xF440
+#define	BIT_BAT_POWER_S3		(1 << 2)
+#define	BIT_BAT_POWER_ON		(1 << 1)
+#define	BIT_BAT_POWER_ACIN		(1 << 0)
+
+/* Audio: rd/wr */
+#define	REG_AUDIO_VOLUME	0xF46C
+#define	REG_AUDIO_MUTE		0xF4E7
+#define	REG_AUDIO_BEEP		0xF4D0
+/* USB port power or not: rd/wr */
+#define	REG_USB0_FLAG		0xF461
+#define	REG_USB1_FLAG		0xF462
+#define	REG_USB2_FLAG		0xF463
+#define	BIT_USB_FLAG_ON		1
+#define	BIT_USB_FLAG_OFF	0
+/* LID */
+#define	REG_LID_DETECT		0xF4BD
+#define	BIT_LID_DETECT_ON	1
+#define	BIT_LID_DETECT_OFF	0
+/* CRT */
+#define	REG_CRT_DETECT		0xF4AD
+#define	BIT_CRT_DETECT_PLUG	1
+#define	BIT_CRT_DETECT_UNPLUG	0
+/* LCD backlight brightness adjust: 9 levels */
+#define	REG_DISPLAY_BRIGHTNESS	0xF4F5
+/* Black screen Status */
+#define	BIT_DISPLAY_LCD_ON	1
+#define	BIT_DISPLAY_LCD_OFF	0
+/* LCD backlight control: off/restore */
+#define	REG_BACKLIGHT_CTRL	0xF7BD
+#define	BIT_BACKLIGHT_ON	1
+#define	BIT_BACKLIGHT_OFF	0
+/* Reset the machine auto-clear: rd/wr */
+#define	REG_RESET		0xF4EC
+#define	BIT_RESET_ON		1
+/* Light the led: rd/wr */
+#define	REG_LED			0xF4C8
+#define	BIT_LED_RED_POWER	(1 << 0)
+#define	BIT_LED_ORANGE_POWER	(1 << 1)
+#define	BIT_LED_GREEN_CHARGE	(1 << 2)
+#define	BIT_LED_RED_CHARGE	(1 << 3)
+#define	BIT_LED_NUMLOCK		(1 << 4)
+/* Test led mode, all led on/off */
+#define	REG_LED_TEST		0xF4C2
+#define	BIT_LED_TEST_IN		1
+#define	BIT_LED_TEST_OUT	0
+/* Camera on/off */
+#define	REG_CAMERA_STATUS	0xF46A
+#define	BIT_CAMERA_STATUS_ON	1
+#define	BIT_CAMERA_STATUS_OFF	0
+#define	REG_CAMERA_CONTROL	0xF7B7
+#define	BIT_CAMERA_CONTROL_OFF	0
+#define	BIT_CAMERA_CONTROL_ON	1
+/* Wlan Status */
+#define	REG_WLAN		0xF4FA
+#define	BIT_WLAN_ON		1
+#define	BIT_WLAN_OFF		0
+#define	REG_DISPLAY_LCD		0xF79F
+
+/* SCI Event Number from EC */
+enum {
+	EVENT_LID = 0x23,	/*  Turn on/off LID */
+	EVENT_DISPLAY_TOGGLE,	/*  Fn+F3 for display switch */
+	EVENT_SLEEP,		/*  Fn+F1 for entering sleep mode */
+	EVENT_OVERTEMP,		/*  Over-temperature happened */
+	EVENT_CRT_DETECT,	/*  CRT is connected */
+	EVENT_CAMERA,		/*  Camera on/off */
+	EVENT_USB_OC2,		/*  USB2 Over Current occurred */
+	EVENT_USB_OC0,		/*  USB0 Over Current occurred */
+	EVENT_BLACK_SCREEN,	/*  Turn on/off backlight */
+	EVENT_AUDIO_MUTE,	/*  Mute on/off */
+	EVENT_DISPLAY_BRIGHTNESS,/* LCD backlight brightness adjust */
+	EVENT_AC_BAT,		/*  AC & Battery relative issue */
+	EVENT_AUDIO_VOLUME,	/*  Volume adjust */
+	EVENT_WLAN,		/*  Wlan on/off */
+};
+
+#define EVENT_START	EVENT_LID
+#define EVENT_END	EVENT_WLAN
+
+#endif /* !_EC_KB3310B_H */
arch/mips/loongson/lemote-2f/Makefile +1 -1
index 4d84b27..470156e 100644
@@ -2,7 +2,7 @@
 # Makefile for lemote loongson2f family machines
 #
 
-obj-y += irq.o reset.o ec_kb3310b.o
+obj-y += irq.o reset.o ec_kb3310b.o platform.o
 
 #
 # Suspend Support
arch/mips/loongson/lemote-2f/ec_kb3310b.c +4 -8
index 4d84111..734d2d0 100644
@@ -14,7 +14,7 @@
 #include <linux/spinlock.h>
 #include <linux/delay.h>
 
-#include "ec_kb3310b.h"
+#include <ec_kb3310b.h>
 
 static DEFINE_SPINLOCK(index_access_lock);
 static DEFINE_SPINLOCK(port_access_lock);
@@ -76,12 +76,9 @@ int ec_query_seq(unsigned char cmd)
 	}
 
 	if (timeout <= 0) {
-		printk(KERN_ERR "%s: deadable error : timeout...\n", __func__);
+		pr_err("%s: deadable error : timeout...\n", __func__);
 		ret = -EINVAL;
-	} else
-		printk(KERN_INFO
-			   "(%x/%d)ec issued command %d status : 0x%x\n",
-			   timeout, EC_CMD_TIMEOUT - timeout, cmd, status);
+	}
 
 	spin_unlock_irqrestore(&port_access_lock, flags);
 
@@ -118,8 +115,7 @@ int ec_get_event_num(void)
 		udelay(EC_REG_DELAY);
 	}
 	if (timeout <= 0) {
-		pr_info("%s: get event number timeout.\n", __func__);
-
+		pr_err("%s: get event number timeout.\n", __func__);
 		return -EINVAL;
 	}
 	value = inb(EC_DAT_PORT);
arch/mips/loongson/lemote-2f/ec_kb3310b.h deleted +0 -188

188 lines not on this page · raw message

arch/mips/loongson/lemote-2f/platform.c new file +40 -0
new file mode 100644
index 0000000..0e7b27d
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2009 Lemote Inc.
+ * Author: Wu Zhangjin, [email protected]
+ *
+ * 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 <linux/err.h>
+#include <linux/platform_device.h>
+
+#include <asm/bootinfo.h>
+
+static struct platform_device yeeloong_pdev = {
+	.name = "yeeloong_laptop",
+	.id = -1,
+};
+
+static int __init lemote2f_platform_init(void)
+{
+	struct platform_device *pdev = NULL;
+
+	switch (mips_machtype) {
+	case MACH_LEMOTE_YL2F89:
+		pdev = &yeeloong_pdev;
+		break;
+	default:
+		break;
+
+	}
+
+	if (pdev != NULL)
+		return platform_device_register(pdev);
+
+	return -ENODEV;
+}
+
+arch_initcall(lemote2f_platform_init);
arch/mips/loongson/lemote-2f/pm.c +2 -2
index d7af2e6..0d5698a 100644
@@ -23,7 +23,7 @@
 #include <loongson.h>
 
 #include <cs5536/cs5536_mfgpt.h>
-#include "ec_kb3310b.h"
+#include <ec_kb3310b.h>
 
 #define I8042_KBD_IRQ		1
 #define I8042_CTR_KBDINT	0x01
@@ -100,7 +100,7 @@ int wakeup_loongson(void)
 	if (irq < 0)
 		return 0;
 
-	printk(KERN_INFO "%s: irq = %d\n", __func__, irq);
+	pr_info("%s: irq = %d\n", __func__, irq);
 
 	if (irq == I8042_KBD_IRQ)
 		return 1;
arch/mips/loongson/lemote-2f/reset.c +1 -1
index 51d1a60..4627659 100644
@@ -20,7 +20,7 @@
 #include <loongson.h>
 
 #include <cs5536/cs5536.h>
-#include "ec_kb3310b.h"
+#include <ec_kb3310b.h>
 
 static void reset_cpu(void)
 {
drivers/platform/Makefile +1 -0
index 782953a..8bdc97c 100644
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_X86)		+= x86/
+obj-$(CONFIG_MIPS)		+= mips/
drivers/platform/mips/Kconfig +9 -0
index 2f77693..76f0250 100644
@@ -14,5 +14,14 @@ menuconfig MIPS_PLATFORM_DEVICES
 
 if MIPS_PLATFORM_DEVICES
 
+config LEMOTE_YEELOONG2F
+	tristate "Lemote YeeLoong Laptop"
+	depends on LEMOTE_MACH2F
+	default m
+	help
+	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
+	  compatible to FuLoong2F mini PC, but it has an extra Embedded
+	  Controller(kb3310b) for battery, hotkey, backlight, temperature and
+	  fan management.
 
 endif # MIPS_PLATFORM_DEVICES
drivers/platform/mips/Makefile new file +5 -0
new file mode 100644
index 0000000..506f920
@@ -0,0 +1,5 @@
+#
+# Makefile for MIPS Platform-Specific Drivers
+#
+
+obj-$(CONFIG_LEMOTE_YEELOONG2F)	+= yeeloong_laptop.o
drivers/platform/mips/yeeloong_laptop.c new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#3 lore raw

PATCH v7 3/8 Loongson: YeeLoong: add backlight driver

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds YeeLoong Backlight Driver, it provides standard interface(/sys/class/backlight/) for user-space applications(e.g. kpowersave, gnome-power-manager) to control the brightness of the backlight.

---
 drivers/platform/mips/Kconfig           |    1 +
 drivers/platform/mips/yeeloong_laptop.c |   79 +++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 0 deletions(-)
drivers/platform/mips/Kconfig +1 -0
index 76f0250..f7a3705 100644
@@ -17,6 +17,7 @@ if MIPS_PLATFORM_DEVICES
 config LEMOTE_YEELOONG2F
 	tristate "Lemote YeeLoong Laptop"
 	depends on LEMOTE_MACH2F
+	select BACKLIGHT_CLASS_DEVICE
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
drivers/platform/mips/yeeloong_laptop.c +79 -0

96 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#4 lore raw

PATCH v7 4/8 Loongson: YeeLoong: add battery driver

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds APM emulated Battery Driver, it provides standard interface(/proc/apm) for user-space applications(e.g. kpowersave, gnome-power-manager) to manage the battery.

---
 drivers/platform/mips/Kconfig           |    2 +
 drivers/platform/mips/yeeloong_laptop.c |  104 +++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 0 deletions(-)
drivers/platform/mips/Kconfig +2 -0
index f7a3705..0c6b5ad 100644
@@ -18,6 +18,8 @@ config LEMOTE_YEELOONG2F
 	tristate "Lemote YeeLoong Laptop"
 	depends on LEMOTE_MACH2F
 	select BACKLIGHT_CLASS_DEVICE
+	select SYS_SUPPORTS_APM_EMULATION
+	select APM_EMULATION
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
drivers/platform/mips/yeeloong_laptop.c +104 -0

127 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#5 lore raw

Re: [PATCH v7 4/8] Loongson: YeeLoong: add battery driver

Quoted 5 lines · Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds APM emulated Battery Driver, it provides standard interface(/proc/apm) for user-space applications(e.g. kpowersave, gnome-power-manager) to manage the battery.

It would be nicer if this went to drivers/power, and used its interface -- providing not only percentage but also other values.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw

Re: [PATCH v7 4/8] Loongson: YeeLoong: add battery driver

Quoted 9 lines · Pavel Machek
Quoted 5 lines · Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds APM emulated Battery Driver, it provides standard interface(/proc/apm) for user-space applications(e.g. kpowersave, gnome-power-manager) to manage the battery.

It would be nicer if this went to drivers/power, and used its interface -- providing not only percentage but also other values.

There is a version basic on the power supply interface, but it is buggy.

Regards,
Wu Zhangjin

#7 lore raw

Re: [PATCH v7 4/8] Loongson: YeeLoong: add battery driver

In reply to Wu Zhangjin

Hi, Pavel

Seems you have reviewed this patch, can I get your Acked-by:?

Thanks!
Wu Zhangjin

Quoted 159 lines · Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds APM emulated Battery Driver, it provides standard interface(/proc/apm) for user-space applications(e.g. kpowersave, gnome-power-manager) to manage the battery.

---
 drivers/platform/mips/Kconfig           |    2 +
 drivers/platform/mips/yeeloong_laptop.c |  104 +++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 0 deletions(-)
drivers/platform/mips/Kconfig +2 -0
index f7a3705..0c6b5ad 100644
@@ -18,6 +18,8 @@ config LEMOTE_YEELOONG2F
 	tristate "Lemote YeeLoong Laptop"
 	depends on LEMOTE_MACH2F
 	select BACKLIGHT_CLASS_DEVICE
+	select SYS_SUPPORTS_APM_EMULATION
+	select APM_EMULATION
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
drivers/platform/mips/yeeloong_laptop.c +104 -0
index fbc4ebb..729e368 100644
@@ -13,6 +13,7 @@
 #include <linux/platform_device.h>
 #include <linux/backlight.h>	/* for backlight subdriver */
 #include <linux/fb.h>
+#include <linux/apm-emulation.h>/* for battery subdriver */
 
 #include <ec_kb3310b.h>
 
@@ -83,6 +84,106 @@ static void yeeloong_backlight_exit(void)
 	}
 }
 
+/* battery subdriver */
+
+static void get_fixed_battery_info(void)
+{
+	int design_cap, full_charged_cap, design_vol, vendor, cell_count;
+
+	design_cap = (ec_read(REG_BAT_DESIGN_CAP_HIGH) << 8)
+	    | ec_read(REG_BAT_DESIGN_CAP_LOW);
+	full_charged_cap = (ec_read(REG_BAT_FULLCHG_CAP_HIGH) << 8)
+	    | ec_read(REG_BAT_FULLCHG_CAP_LOW);
+	design_vol = (ec_read(REG_BAT_DESIGN_VOL_HIGH) << 8)
+	    | ec_read(REG_BAT_DESIGN_VOL_LOW);
+	vendor = ec_read(REG_BAT_VENDOR);
+	cell_count = ec_read(REG_BAT_CELL_COUNT);
+
+	if (vendor != 0) {
+		pr_info("battery vendor(%s), cells count(%d), "
+		       "with designed capacity(%d),designed voltage(%d),"
+		       " full charged capacity(%d)\n",
+		       (vendor ==
+			FLAG_BAT_VENDOR_SANYO) ? "SANYO" : "SIMPLO",
+		       (cell_count == FLAG_BAT_CELL_3S1P) ? 3 : 6,
+		       design_cap, design_vol,
+		       full_charged_cap);
+	}
+}
+
+#define APM_CRITICAL		5
+
+static void get_power_status(struct apm_power_info *info)
+{
+	unsigned char bat_status;
+
+	info->battery_status = APM_BATTERY_STATUS_UNKNOWN;
+	info->battery_flag = APM_BATTERY_FLAG_UNKNOWN;
+	info->units = APM_UNITS_MINS;
+
+	info->battery_life = (ec_read(REG_BAT_RELATIVE_CAP_HIGH) << 8) |
+		(ec_read(REG_BAT_RELATIVE_CAP_LOW));
+
+	info->ac_line_status = (ec_read(REG_BAT_POWER) & BIT_BAT_POWER_ACIN) ?
+		APM_AC_ONLINE : APM_AC_OFFLINE;
+
+	bat_status = ec_read(REG_BAT_STATUS);
+
+	if (!(bat_status & BIT_BAT_STATUS_IN)) {
+		/* no battery inserted */
+		info->battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
+		info->battery_flag = APM_BATTERY_FLAG_NOT_PRESENT;
+		info->time = 0x00;
+		return;
+	}
+
+	/* adapter inserted */
+	if (info->ac_line_status == APM_AC_ONLINE) {
+		if (!(bat_status & BIT_BAT_STATUS_FULL)) {
+			/* battery is not fully charged */
+			info->battery_status = APM_BATTERY_STATUS_CHARGING;
+			info->battery_flag = APM_BATTERY_FLAG_CHARGING;
+		} else {
+			/* battery is fully charged */
+			info->battery_status = APM_BATTERY_STATUS_HIGH;
+			info->battery_flag = APM_BATTERY_FLAG_HIGH;
+			info->battery_life = 100;
+		}
+	} else {
+		/* battery is too low */
+		if (bat_status & BIT_BAT_STATUS_LOW) {
+			info->battery_status = APM_BATTERY_STATUS_LOW;
+			info->battery_flag = APM_BATTERY_FLAG_LOW;
+			if (info->battery_life <= APM_CRITICAL) {
+				/* we should power off the system now */
+				info->battery_status =
+					APM_BATTERY_STATUS_CRITICAL;
+				info->battery_flag = APM_BATTERY_FLAG_CRITICAL;
+			}
+		} else {
+			/* assume the battery is high enough. */
+			info->battery_status = APM_BATTERY_STATUS_HIGH;
+			info->battery_flag = APM_BATTERY_FLAG_HIGH;
+		}
+	}
+	info->time = ((info->battery_life - 3) * 54 + 142) / 60;
+}
+
+static int yeeloong_battery_init(void)
+{
+	get_fixed_battery_info();
+
+	apm_get_power_status = get_power_status;
+
+	return 0;
+}
+
+static void yeeloong_battery_exit(void)
+{
+	if (apm_get_power_status == get_power_status)
+		apm_get_power_status = NULL;
+}
+
 static struct platform_device_id platform_device_ids[] = {
 	{
 		.name = "yeeloong_laptop",
@@ -120,11 +221,14 @@ static int __init yeeloong_init(void)
 		return ret;
 	}
 
+	yeeloong_battery_init();
+
 	return 0;
 }
 
 static void __exit yeeloong_exit(void)
 {
+	yeeloong_battery_exit();
 	yeeloong_backlight_exit();
 	platform_driver_unregister(&platform_driver);
 
#8 lore raw

PATCH v7 5/8 Loongson: YeeLoong: add hardware monitoring driver

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds hardware monitoring driver, it provides standard interface(/sys/class/hwmon/) for lm-sensors/sensors-applet to monitor the temperatures of CPU and battery, the PWM of fan, the current, voltage of battery.

---
 drivers/platform/mips/Kconfig           |    1 +
 drivers/platform/mips/yeeloong_laptop.c |  221 +++++++++++++++++++++++++++++++
 2 files changed, 222 insertions(+), 0 deletions(-)
drivers/platform/mips/Kconfig +1 -0
index 0c6b5ad..9c8385c 100644
@@ -20,6 +20,7 @@ config LEMOTE_YEELOONG2F
 	select BACKLIGHT_CLASS_DEVICE
 	select SYS_SUPPORTS_APM_EMULATION
 	select APM_EMULATION
+	select HWMON
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
drivers/platform/mips/yeeloong_laptop.c +221 -0

244 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#9 lore raw

Re: [PATCH v7 5/8] Loongson: YeeLoong: add hardware monitoring driver

Hi!

drivers/platform/mips/yeeloong_laptop.c static void yeeloong_battery_exit(void) · line 242

Quoted 10 lines
drivers/platform/mips/yeeloong_laptop.c +10 -0
+static int get_cpu_temp(void)
+{
+	int value;
+
+	value = ec_read(REG_TEMPERATURE_VALUE);
+
+	if (value & (1 << 7))
+		value = (value & 0x7f) - 128;
+	else
+		value = value & 0xff;

wtf?

Maybe value should be 's8'?

drivers/platform/mips/yeeloong_laptop.c static void yeeloong_battery_exit(void) · line 275

Quoted 9 lines
drivers/platform/mips/yeeloong_laptop.c +9 -0
+static int get_battery_current(void)
+{
+	int value;
+
+	value = (ec_read(REG_BAT_CURRENT_HIGH) << 8) |
+		(ec_read(REG_BAT_CURRENT_LOW));
+
+	if (value & 0x8000)
+		value = 0xffff - value;

Another version of pair-complement conversion; this one is broken -- off by 1.

drivers/platform/mips/yeeloong_laptop.c static void yeeloong_battery_exit(void) · line 298

Quoted 8 lines
drivers/platform/mips/yeeloong_laptop.c +8 -0
+static int parse_arg(const char *buf, unsigned long count, int *val)
+{
+	if (!count)
+		return 0;
+	if (sscanf(buf, "%i", val) != 1)
+		return -EINVAL;
+	return count;
+}

We have strict_strtoul for a reason...

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#10 lore raw

Re: [PATCH v7 5/8] Loongson: YeeLoong: add hardware monitoring driver

Quoted 30 lines · Pavel Machek

Hi!

drivers/platform/mips/yeeloong_laptop.c static void yeeloong_battery_exit(void) · line 242

Quoted 10 lines
drivers/platform/mips/yeeloong_laptop.c +10 -0
+static int get_cpu_temp(void)
+{
+	int value;
+
+	value = ec_read(REG_TEMPERATURE_VALUE);
+
+	if (value & (1 << 7))
+		value = (value & 0x7f) - 128;
+	else
+		value = value & 0xff;

wtf?

Maybe value should be 's8'?

drivers/platform/mips/yeeloong_laptop.c static void yeeloong_battery_exit(void) · line 275

Quoted 9 lines
drivers/platform/mips/yeeloong_laptop.c +9 -0
+static int get_battery_current(void)
+{
+	int value;
+
+	value = (ec_read(REG_BAT_CURRENT_HIGH) << 8) |
+		(ec_read(REG_BAT_CURRENT_LOW));
+
+	if (value & 0x8000)
+		value = 0xffff - value;

Another version of pair-complement conversion; this one is broken -- off by 1.

Quoted 11 lines

drivers/platform/mips/yeeloong_laptop.c static void yeeloong_battery_exit(void) · line 298

Quoted 8 lines
drivers/platform/mips/yeeloong_laptop.c +8 -0
+static int parse_arg(const char *buf, unsigned long count, int *val)
+{
+	if (!count)
+		return 0;
+	if (sscanf(buf, "%i", val) != 1)
+		return -EINVAL;
+	return count;
+}

We have strict_strtoul for a reason...

Done, thanks!

Regards,
Wu Zhangjin

#11 lore raw

PATCH v7 6/8 Loongson: YeeLoong: add video output driver

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds Video Output Driver, it provides standard interface(/sys/class/video_output) to turn on/off the video output of LCD, CRT.

---
 drivers/platform/mips/Kconfig           |    1 +
 drivers/platform/mips/yeeloong_laptop.c |  147 +++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+), 0 deletions(-)
drivers/platform/mips/Kconfig +1 -0
index 9c8385c..4a89c01 100644
@@ -21,6 +21,7 @@ config LEMOTE_YEELOONG2F
 	select SYS_SUPPORTS_APM_EMULATION
 	select APM_EMULATION
 	select HWMON
+	select VIDEO_OUTPUT_CONTROL
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
drivers/platform/mips/yeeloong_laptop.c +147 -0

170 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#12 lore raw

Re: [PATCH v7 6/8] Loongson: YeeLoong: add video output driver

Quoted 12 lines · Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds Video Output Driver, it provides standard interface(/sys/class/video_output) to turn on/off the video output of LCD, CRT.

drivers/platform/mips/Kconfig +0 -0
index 9c8385c..4a89c01 100644

drivers/platform/mips/Kconfig config LEMOTE_YEELOONG2F · line 27

Quoted 7 lines
drivers/platform/mips/Kconfig +1 -0
@@ -21,6 +21,7 @@ config LEMOTE_YEELOONG2F
 	select SYS_SUPPORTS_APM_EMULATION
 	select APM_EMULATION
 	select HWMON
+	select VIDEO_OUTPUT_CONTROL
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically

default m is evil.

Quoted 9 lines
drivers/platform/mips/Kconfig +9 -0
+	if (status == BIT_DISPLAY_LCD_ON) {
+		/* Turn on LCD */
+		outb(0x31, 0x3c4);
+		value = inb(0x3c5);
+		value = (value & 0xf8) | 0x03;
+		outb(0x31, 0x3c4);
+		outb(value, 0x3c5);
+		/* Turn on backlight */
+		ec_write(REG_BACKLIGHT_CTRL, BIT_BACKLIGHT_ON);

drivers/platform/mips/Kconfig

Quoted 10 lines
drivers/platform/mips/Kconfig +10 -0
+	} else {
+		/* Turn off backlight */
+		ec_write(REG_BACKLIGHT_CTRL, BIT_BACKLIGHT_OFF);
+		/* Turn off LCD */
+		outb(0x31, 0x3c4);
+		value = inb(0x3c5);
+		value = (value & 0xf8) | 0x02;
+		outb(0x31, 0x3c4);
+		outb(value, 0x3c5);
+	}

IIRC this is opencoded in suspend support; should that get common helpers?

Quoted 7 lines
drivers/platform/mips/Kconfig +7 -0
+	if (status == BIT_CRT_DETECT_PLUG) {
+		if (ec_read(REG_CRT_DETECT) == BIT_CRT_DETECT_PLUG) {
+			/* Turn on CRT */
+			outb(0x21, 0x3c4);
+			value = inb(0x3c5);
+			value &= ~(1 << 7);
+			outb(0x21, 0x3c4);

drivers/platform/mips/Kconfig

Quoted 10 lines
drivers/platform/mips/Kconfig +10 -0
+			outb(value, 0x3c5);
+		}
+	} else {
+		/* Turn off CRT */
+		outb(0x21, 0x3c4);
+		value = inb(0x3c5);
+		value |= (1 << 7);
+		outb(0x21, 0x3c4);
+		outb(value, 0x3c5);
+	}

This looks suspiciously similar to one another and to code above. Perhaps some more helpers?

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#13 lore raw

Re: [PATCH v7 6/8] Loongson: YeeLoong: add video output driver

Quoted 8 lines · Pavel Machek
Quoted 6 lines · Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds Video Output Driver, it provides standard interface(/sys/class/video_output) to turn on/off the video output of LCD, CRT.

Quoted 15 lines

drivers/platform/mips/Kconfig config LEMOTE_YEELOONG2F · line 27

Quoted 12 lines
drivers/platform/mips/Kconfig +1 -0
index 9c8385c..4a89c01 100644
@@ -21,6 +21,7 @@ config LEMOTE_YEELOONG2F
 	select SYS_SUPPORTS_APM_EMULATION
 	select APM_EMULATION
 	select HWMON
+	select VIDEO_OUTPUT_CONTROL
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically

default m is evil.

why? this module can be loaded automatically, so, I let it be a module by default.

Quoted 35 lines
Quoted 9 lines
drivers/platform/mips/Kconfig +9 -0
+	if (status == BIT_DISPLAY_LCD_ON) {
+		/* Turn on LCD */
+		outb(0x31, 0x3c4);
+		value = inb(0x3c5);
+		value = (value & 0xf8) | 0x03;
+		outb(0x31, 0x3c4);
+		outb(value, 0x3c5);
+		/* Turn on backlight */
+		ec_write(REG_BACKLIGHT_CTRL, BIT_BACKLIGHT_ON);

drivers/platform/mips/Kconfig

Quoted 10 lines
drivers/platform/mips/Kconfig +10 -0
+	} else {
+		/* Turn off backlight */
+		ec_write(REG_BACKLIGHT_CTRL, BIT_BACKLIGHT_OFF);
+		/* Turn off LCD */
+		outb(0x31, 0x3c4);
+		value = inb(0x3c5);
+		value = (value & 0xf8) | 0x02;
+		outb(0x31, 0x3c4);
+		outb(value, 0x3c5);
+	}

IIRC this is opencoded in suspend support; should that get common helpers?

Quoted 12 lines
drivers/platform/mips/Kconfig +12 -0
+	if (status == BIT_CRT_DETECT_PLUG) {
+		if (ec_read(REG_CRT_DETECT) == BIT_CRT_DETECT_PLUG) {
+			/* Turn on CRT */
+			outb(0x21, 0x3c4);
+			value = inb(0x3c5);
+			value &= ~(1 << 7);
+			outb(0x21, 0x3c4);
+			outb(value, 0x3c5);
+		}
+	} else {
+		/* Turn off CRT */
+		outb(0x21, 0x3c4);
Quoted 9 lines

drivers/platform/mips/Kconfig

Quoted 5 lines
drivers/platform/mips/Kconfig +5 -0
+		value = inb(0x3c5);
+		value |= (1 << 7);
+		outb(0x21, 0x3c4);
+		outb(value, 0x3c5);
+	}

This looks suspiciously similar to one another and to code above. Perhaps some more helpers?

Yes, lots of duplicated source code above, thanks!

Regards,
Wu Zhangjin

#14 lore raw

Re: [PATCH v7 6/8] Loongson: YeeLoong: add video output driver

In reply to Wu Zhangjin

Hi, Pavel

Can I get your Acked-by: for this patch?

Thanks!
Wu Zhangjin

Quoted 201 lines · Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds Video Output Driver, it provides standard interface(/sys/class/video_output) to turn on/off the video output of LCD, CRT.

---
 drivers/platform/mips/Kconfig           |    1 +
 drivers/platform/mips/yeeloong_laptop.c |  147 +++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+), 0 deletions(-)
drivers/platform/mips/Kconfig +1 -0
index 9c8385c..4a89c01 100644
@@ -21,6 +21,7 @@ config LEMOTE_YEELOONG2F
 	select SYS_SUPPORTS_APM_EMULATION
 	select APM_EMULATION
 	select HWMON
+	select VIDEO_OUTPUT_CONTROL
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
drivers/platform/mips/yeeloong_laptop.c +147 -0
index 644aaa7..8378926 100644
@@ -16,6 +16,7 @@
 #include <linux/apm-emulation.h>/* for battery subdriver */
 #include <linux/hwmon.h>	/* for hwmon subdriver */
 #include <linux/hwmon-sysfs.h>
+#include <linux/video_output.h>	/* for video output subdriver */
 
 #include <ec_kb3310b.h>
 
@@ -397,6 +398,144 @@ static void yeeloong_hwmon_exit(void)
 	}
 }
 
+/* video output subdriver */
+
+static int lcd_video_output_get(struct output_device *od)
+{
+	return ec_read(REG_DISPLAY_LCD);
+}
+
+static int lcd_video_output_set(struct output_device *od)
+{
+	int value;
+	unsigned long status;
+
+	status = !!od->request_state;
+
+	if (status == BIT_DISPLAY_LCD_ON) {
+		/* Turn on LCD */
+		outb(0x31, 0x3c4);
+		value = inb(0x3c5);
+		value = (value & 0xf8) | 0x03;
+		outb(0x31, 0x3c4);
+		outb(value, 0x3c5);
+		/* Turn on backlight */
+		ec_write(REG_BACKLIGHT_CTRL, BIT_BACKLIGHT_ON);
+	} else {
+		/* Turn off backlight */
+		ec_write(REG_BACKLIGHT_CTRL, BIT_BACKLIGHT_OFF);
+		/* Turn off LCD */
+		outb(0x31, 0x3c4);
+		value = inb(0x3c5);
+		value = (value & 0xf8) | 0x02;
+		outb(0x31, 0x3c4);
+		outb(value, 0x3c5);
+	}
+
+	return 0;
+}
+
+static struct output_properties lcd_output_properties = {
+	.set_state = lcd_video_output_set,
+	.get_status = lcd_video_output_get,
+};
+
+static int crt_video_output_get(struct output_device *od)
+{
+	return ec_read(REG_CRT_DETECT);
+}
+
+static int crt_video_output_set(struct output_device *od)
+{
+	int value;
+	unsigned long status;
+
+	status = !!od->request_state;
+
+	if (status == BIT_CRT_DETECT_PLUG) {
+		if (ec_read(REG_CRT_DETECT) == BIT_CRT_DETECT_PLUG) {
+			/* Turn on CRT */
+			outb(0x21, 0x3c4);
+			value = inb(0x3c5);
+			value &= ~(1 << 7);
+			outb(0x21, 0x3c4);
+			outb(value, 0x3c5);
+		}
+	} else {
+		/* Turn off CRT */
+		outb(0x21, 0x3c4);
+		value = inb(0x3c5);
+		value |= (1 << 7);
+		outb(0x21, 0x3c4);
+		outb(value, 0x3c5);
+	}
+
+	return 0;
+}
+
+static struct output_properties crt_output_properties = {
+	.set_state = crt_video_output_set,
+	.get_status = crt_video_output_get,
+};
+
+static struct output_device *lcd_output_dev, *crt_output_dev;
+
+static void yeeloong_lcd_vo_set(int status)
+{
+	lcd_output_dev->request_state = status;
+	lcd_video_output_set(lcd_output_dev);
+}
+
+static void yeeloong_crt_vo_set(int status)
+{
+	crt_output_dev->request_state = status;
+	crt_video_output_set(crt_output_dev);
+}
+
+static int yeeloong_vo_init(void)
+{
+	int ret;
+
+	/* Register video output device: lcd, crt */
+	lcd_output_dev = video_output_register("LCD", NULL, NULL,
+			&lcd_output_properties);
+
+	if (IS_ERR(lcd_output_dev)) {
+		ret = PTR_ERR(lcd_output_dev);
+		lcd_output_dev = NULL;
+		return ret;
+	}
+	/* Ensure LCD is on by default */
+	yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
+
+	crt_output_dev = video_output_register("CRT", NULL, NULL,
+			&crt_output_properties);
+
+	if (IS_ERR(crt_output_dev)) {
+		ret = PTR_ERR(crt_output_dev);
+		crt_output_dev = NULL;
+		return ret;
+	}
+
+	/* Turn off CRT by default, and will be enabled when the CRT
+	 * connectting event reported by SCI */
+	yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
+
+	return 0;
+}
+
+static void yeeloong_vo_exit(void)
+{
+	if (lcd_output_dev) {
+		video_output_unregister(lcd_output_dev);
+		lcd_output_dev = NULL;
+	}
+	if (crt_output_dev) {
+		video_output_unregister(crt_output_dev);
+		crt_output_dev = NULL;
+	}
+}
+
 static struct platform_device_id platform_device_ids[] = {
 	{
 		.name = "yeeloong_laptop",
@@ -443,11 +582,19 @@ static int __init yeeloong_init(void)
 		return ret;
 	}
 
+	ret = yeeloong_vo_init();
+	if (ret) {
+		pr_err("Fail to register yeeloong video output driver.\n");
+		yeeloong_vo_exit();
+		return ret;
+	}
+
 	return 0;
 }
 
 static void __exit yeeloong_exit(void)
 {
+	yeeloong_vo_exit();
 	yeeloong_hwmon_exit();
 	yeeloong_battery_exit();
 	yeeloong_backlight_exit();
#15 lore raw

PATCH v7 7/8 Loongson: YeeLoong: add suspend support

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch add support to suspend the yeeloong platform specific devices(LCD, CRT, USB...).

---
 drivers/platform/mips/yeeloong_laptop.c |   41 +++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
drivers/platform/mips/yeeloong_laptop.c +41 -0
index 8378926..d31824b 100644
@@ -536,6 +536,45 @@ static void yeeloong_vo_exit(void)
 	}
 }
 
+#ifdef CONFIG_LOONGSON_SUSPEND
+static void usb_ports_set(int status)
+{
+	status = !!status;
+
+	ec_write(REG_USB0_FLAG, status);
+	ec_write(REG_USB1_FLAG, status);
+	ec_write(REG_USB2_FLAG, status);
+}
+
+static int yeeloong_suspend(struct platform_device *dev, pm_message_t state)
+
+{
+	/* Turn off LCD */
+	yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_OFF);
+	/* Turn off CRT */
+	yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
+	/* Poweroff three usb ports */
+	usb_ports_set(BIT_USB_FLAG_OFF);
+
+	return 0;
+}
+
+static int yeeloong_resume(struct platform_device *pdev)
+{
+	/* Resume the status of lcd & crt */
+	yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
+	yeeloong_crt_vo_set(BIT_CRT_DETECT_PLUG);
+
+	/* Poweron three usb ports */
+	usb_ports_set(BIT_USB_FLAG_ON);
+
+	return 0;
+}
+#else	/* !CONFIG_LOONGSON_SUSPEND */
+#define yeeloong_suspend NULL
+#define yeeloong_resume NULL
+#endif
+
 static struct platform_device_id platform_device_ids[] = {
 	{
 		.name = "yeeloong_laptop",
@@ -551,6 +590,8 @@ static struct platform_driver platform_driver = {
 		   .owner = THIS_MODULE,
 		   },
 	.id_table = platform_device_ids,
+	.suspend = yeeloong_suspend,
+	.resume = yeeloong_resume,
 };
 
 static int __init yeeloong_init(void)
Signature · 1 line
1.6.2.1
#16 lore raw

PATCH v7 8/8 Loongson: YeeLoong: add input/hotkey driver

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch adds Hotkey Driver, which will do relative actions for The hotkey event(/sys/class/input) and report the corresponding input keys to the user-space applications.

Changes from the old revision:
- Rebase on the sparse keymap library from Dmitry Torokhov.

---
 arch/mips/include/asm/mach-loongson/loongson.h |    6 +
 arch/mips/loongson/common/cmdline.c            |    8 +
 drivers/platform/mips/Kconfig                  |    1 +
 drivers/platform/mips/yeeloong_laptop.c        |  415 ++++++++++++++++++++++++
 4 files changed, 430 insertions(+), 0 deletions(-)
arch/mips/include/asm/mach-loongson/loongson.h +6 -0
index ee8bc83..13e208e 100644
@@ -43,6 +43,12 @@ static inline void prom_init_uart_base(void)
 #endif
 }
 
+/*
+ * Copy kernel command line from arcs_cmdline
+ */
+#include <asm/setup.h>
+extern char loongson_cmdline[COMMAND_LINE_SIZE];
+
 /* irq operation functions */
 extern void bonito_irqdispatch(void);
 extern void __init bonito_irq_init(void);
arch/mips/loongson/common/cmdline.c +8 -0
index 7ad47f2..617faee 100644
@@ -17,6 +17,7 @@
  * Free Software Foundation;  either version 2 of the  License, or (at your
  * option) any later version.
  */
+#include <linux/module.h>
 #include <asm/bootinfo.h>
 
 #include <loongson.h>
@@ -25,6 +26,10 @@ int prom_argc;
 /* pmon passes arguments in 32bit pointers */
 int *_prom_argv;
 
+/* the kernel command line copied from arcs_cmdline */
+char loongson_cmdline[COMMAND_LINE_SIZE];
+EXPORT_SYMBOL(loongson_cmdline);
+
 void __init prom_init_cmdline(void)
 {
 	int i;
@@ -51,4 +56,7 @@ void __init prom_init_cmdline(void)
 		strcat(arcs_cmdline, " root=/dev/hda1");
 
 	prom_init_machtype();
+
+	/* copy arcs_cmdline into loongson_cmdline */
+	strncpy(loongson_cmdline, arcs_cmdline, COMMAND_LINE_SIZE);
 }
drivers/platform/mips/Kconfig +1 -0
index 4a89c01..7c81c4c 100644
@@ -22,6 +22,7 @@ config LEMOTE_YEELOONG2F
 	select APM_EMULATION
 	select HWMON
 	select VIDEO_OUTPUT_CONTROL
+	select INPUT_SPARSEKMAP
 	default m
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
drivers/platform/mips/yeeloong_laptop.c +415 -0

439 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#17 lore raw

Re: [PATCH v7 8/8] Loongson: YeeLoong: add input/hotkey driver

Hi!

drivers/platform/mips/yeeloong_laptop.c static void yeeloong_vo_exit(void) · line 709

Quoted 2 lines
drivers/platform/mips/yeeloong_laptop.c +2 -0
+#define NO_REG		0
+#define NO_HANDLER	NULL

Don't obfuscate code like that.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#18 lore raw

Re: [PATCH v7 8/8] Loongson: YeeLoong: add input/hotkey driver

Quoted 7 lines · Pavel Machek

Hi!

drivers/platform/mips/yeeloong_laptop.c static void yeeloong_vo_exit(void) · line 709

Quoted 2 lines
drivers/platform/mips/yeeloong_laptop.c +2 -0
+#define NO_REG		0
+#define NO_HANDLER	NULL

Don't obfuscate code like that.

Will remove it later, thanks!