linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/8] Loongson: YeeLoong: add platform specific drivers
@ 2009-12-01 11:06 Wu Zhangin
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
  2009-12-01 11:16 ` [PATCH v6 0/8] Loongson: YeeLoong: add platform specific drivers Wu Zhangjin
  0 siblings, 2 replies; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:06 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: Dmitry Torokhov, Pavel Machek, Rafael J. Wysocki, linux-mips,
	zhangfx, Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

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

	- 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	?
	- suspend
	  /sys/power/state		kpowersave, gnome-power-manager
	- hotkey
	  /sys/class/input/		gnome-settings-daemon ?

To utilize the above interfaces, you are recommended to install the latest hal,
dbus.

This v6 revision incorporates with the feedbacks from Ralf, Pavel Machek,
Rafael J. Wysocki and Dmitry Torokhov.

Changes from the old v5 revision:

	- Cleanup the "select" and "depend" of the options
	  Replace some "select"s by "depend"s to avoid potential compiling
	  errors.

	- Cleanup the hotkey(input) driver
	  Merge several functions, Cleanup the comments, Use Switch...Case
	  instead of the array.

	- Fixup of the video output driver  
	  Seems the video output subsystem doesn't handle the input value, we
	  handle it outselves via !!od->request_state.

	- Append the yl_ prefix to the file names
	  yl_ prefix is needed to distinguish it with the next patchset for
	  lynloong pc platform drivers.

All changes have been tested again.

Best Regards,
     Wu Zhangjin

Wu Zhangjin (8):
  Loongson: Lemote-2F: add platform specific submenu
  Loongson: YeeLoong: add platform specific option
  Loongson: YeeLoong: add backlight driver
  Loongson: YeeLoong: add battery driver
  Loongson: YeeLoong: add hwmon driver
  Loongson: YeeLoong: add video output driver
  Loongson: YeeLoong: add suspend driver
  Loongson: YeeLoong: add hotkey driver

 arch/mips/kernel/setup.c                           |    1 +
 arch/mips/loongson/Kconfig                         |   21 +
 arch/mips/loongson/lemote-2f/Makefile              |    7 +-
 arch/mips/loongson/lemote-2f/ec_kb3310b.c          |  130 ------
 arch/mips/loongson/lemote-2f/ec_kb3310b.h          |  188 --------
 arch/mips/loongson/lemote-2f/pm.c                  |    4 +-
 arch/mips/loongson/lemote-2f/reset.c               |    2 +-
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |   65 +++
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |   10 +
 .../lemote-2f/yeeloong_laptop/ec_kb3310b.c         |  126 ++++++
 .../lemote-2f/yeeloong_laptop/ec_kb3310b.h         |  193 +++++++++
 .../lemote-2f/yeeloong_laptop/yl_backlight.c       |   93 ++++
 .../lemote-2f/yeeloong_laptop/yl_battery.c         |  127 ++++++
 .../loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c |  452 ++++++++++++++++++++
 .../loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c  |  239 +++++++++++
 .../lemote-2f/yeeloong_laptop/yl_suspend.c         |  135 ++++++
 .../loongson/lemote-2f/yeeloong_laptop/yl_vo.c     |  164 +++++++
 17 files changed, 1635 insertions(+), 322 deletions(-)
 delete mode 100644 arch/mips/loongson/lemote-2f/ec_kb3310b.c
 delete mode 100644 arch/mips/loongson/lemote-2f/ec_kb3310b.h
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.c
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_battery.c
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_vo.c

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
@ 2009-12-01 11:07   ` Wu Zhangin
  2009-12-01 13:32     ` Ralf Baechle
  2009-12-01 11:07   ` [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option Wu Zhangin
                     ` (6 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:07 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 arch/mips/loongson/Kconfig |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/arch/mips/loongson/Kconfig b/arch/mips/loongson/Kconfig
index 3df1967..a34dfcc 100644
--- a/arch/mips/loongson/Kconfig
+++ b/arch/mips/loongson/Kconfig
@@ -83,3 +83,23 @@ config LOONGSON_UART_BASE
 	bool
 	default y
 	depends on EARLY_PRINTK || SERIAL_8250
+
+#
+# Loongson Platform Specific Drivers
+#
+
+menuconfig LOONGSON_PLATFORM_DEVICES
+	bool "Loongson Platform Drivers"
+	default y
+	help
+	  Say Y here to get to see options for device drivers of various
+	  loongson platforms, including vendor-specific 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 LOONGSON_PLATFORM_DEVICES
+# Put platform specific stuff here
+
+
+endif # LOONGSON_PLATFORM_DEVICES
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
  2009-12-01 11:07   ` [PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu Wu Zhangin
@ 2009-12-01 11:07   ` Wu Zhangin
  2009-12-01 13:34     ` Ralf Baechle
  2009-12-01 11:08   ` [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver Wu Zhangin
                     ` (5 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:07 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

This patch add a new LEMOTE_YEELOONG2F option, a yeeloong_laptop/
directory for the coming yeeloong specific support, and for the
ec_kb3310b belongs to yeeloong, so, move it to yeeloong_laptop/ too.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 arch/mips/loongson/Kconfig                         |    1 +
 arch/mips/loongson/lemote-2f/Makefile              |    7 +-
 arch/mips/loongson/lemote-2f/ec_kb3310b.c          |  130 --------------
 arch/mips/loongson/lemote-2f/ec_kb3310b.h          |  188 --------------------
 arch/mips/loongson/lemote-2f/pm.c                  |    4 +-
 arch/mips/loongson/lemote-2f/reset.c               |    2 +-
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |   15 ++
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    3 +
 .../lemote-2f/yeeloong_laptop/ec_kb3310b.c         |  126 +++++++++++++
 .../lemote-2f/yeeloong_laptop/ec_kb3310b.h         |  187 +++++++++++++++++++
 10 files changed, 341 insertions(+), 322 deletions(-)
 delete mode 100644 arch/mips/loongson/lemote-2f/ec_kb3310b.c
 delete mode 100644 arch/mips/loongson/lemote-2f/ec_kb3310b.h
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.c
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h

diff --git a/arch/mips/loongson/Kconfig b/arch/mips/loongson/Kconfig
index a34dfcc..d440c32 100644
--- a/arch/mips/loongson/Kconfig
+++ b/arch/mips/loongson/Kconfig
@@ -101,5 +101,6 @@ menuconfig LOONGSON_PLATFORM_DEVICES
 if LOONGSON_PLATFORM_DEVICES
 # Put platform specific stuff here
 
+source "arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig"
 
 endif # LOONGSON_PLATFORM_DEVICES
diff --git a/arch/mips/loongson/lemote-2f/Makefile b/arch/mips/loongson/lemote-2f/Makefile
index 4d84b27..0ada6c9 100644
--- a/arch/mips/loongson/lemote-2f/Makefile
+++ b/arch/mips/loongson/lemote-2f/Makefile
@@ -2,10 +2,15 @@
 # Makefile for lemote loongson2f family machines
 #
 
-obj-y += irq.o reset.o ec_kb3310b.o
+obj-y += irq.o reset.o
 
 #
 # Suspend Support
 #
 
 obj-$(CONFIG_LOONGSON_SUSPEND) += pm.o
+
+#
+# Platform Drivers
+#
+obj-y += yeeloong_laptop/
diff --git a/arch/mips/loongson/lemote-2f/ec_kb3310b.c b/arch/mips/loongson/lemote-2f/ec_kb3310b.c
deleted file mode 100644
index 4d84111..0000000
--- a/arch/mips/loongson/lemote-2f/ec_kb3310b.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Basic KB3310B Embedded Controller support for the YeeLoong 2F netbook
- *
- *  Copyright (C) 2008 Lemote Inc.
- *  Author: liujl <liujl@lemote.com>, 2008-04-20
- *
- * 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/module.h>
-#include <linux/spinlock.h>
-#include <linux/delay.h>
-
-#include "ec_kb3310b.h"
-
-static DEFINE_SPINLOCK(index_access_lock);
-static DEFINE_SPINLOCK(port_access_lock);
-
-unsigned char ec_read(unsigned short addr)
-{
-	unsigned char value;
-	unsigned long flags;
-
-	spin_lock_irqsave(&index_access_lock, flags);
-	outb((addr & 0xff00) >> 8, EC_IO_PORT_HIGH);
-	outb((addr & 0x00ff), EC_IO_PORT_LOW);
-	value = inb(EC_IO_PORT_DATA);
-	spin_unlock_irqrestore(&index_access_lock, flags);
-
-	return value;
-}
-EXPORT_SYMBOL_GPL(ec_read);
-
-void ec_write(unsigned short addr, unsigned char val)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&index_access_lock, flags);
-	outb((addr & 0xff00) >> 8, EC_IO_PORT_HIGH);
-	outb((addr & 0x00ff), EC_IO_PORT_LOW);
-	outb(val, EC_IO_PORT_DATA);
-	/*  flush the write action */
-	inb(EC_IO_PORT_DATA);
-	spin_unlock_irqrestore(&index_access_lock, flags);
-
-	return;
-}
-EXPORT_SYMBOL_GPL(ec_write);
-
-/*
- * This function is used for EC command writes and corresponding status queries.
- */
-int ec_query_seq(unsigned char cmd)
-{
-	int timeout;
-	unsigned char status;
-	unsigned long flags;
-	int ret = 0;
-
-	spin_lock_irqsave(&port_access_lock, flags);
-
-	/* make chip goto reset mode */
-	udelay(EC_REG_DELAY);
-	outb(cmd, EC_CMD_PORT);
-	udelay(EC_REG_DELAY);
-
-	/* check if the command is received by ec */
-	timeout = EC_CMD_TIMEOUT;
-	status = inb(EC_STS_PORT);
-	while (timeout-- && (status & (1 << 1))) {
-		status = inb(EC_STS_PORT);
-		udelay(EC_REG_DELAY);
-	}
-
-	if (timeout <= 0) {
-		printk(KERN_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);
-
-	return ret;
-}
-EXPORT_SYMBOL_GPL(ec_query_seq);
-
-/*
- * Send query command to EC to get the proper event number
- */
-int ec_query_event_num(void)
-{
-	return ec_query_seq(CMD_GET_EVENT_NUM);
-}
-EXPORT_SYMBOL(ec_query_event_num);
-
-/*
- * Get event number from EC
- *
- * NOTE: This routine must follow the query_event_num function in the
- * interrupt.
- */
-int ec_get_event_num(void)
-{
-	int timeout = 100;
-	unsigned char value;
-	unsigned char status;
-
-	udelay(EC_REG_DELAY);
-	status = inb(EC_STS_PORT);
-	udelay(EC_REG_DELAY);
-	while (timeout-- && !(status & (1 << 0))) {
-		status = inb(EC_STS_PORT);
-		udelay(EC_REG_DELAY);
-	}
-	if (timeout <= 0) {
-		pr_info("%s: get event number timeout.\n", __func__);
-
-		return -EINVAL;
-	}
-	value = inb(EC_DAT_PORT);
-	udelay(EC_REG_DELAY);
-
-	return value;
-}
-EXPORT_SYMBOL(ec_get_event_num);
diff --git a/arch/mips/loongson/lemote-2f/ec_kb3310b.h b/arch/mips/loongson/lemote-2f/ec_kb3310b.h
deleted file mode 100644
index 1595a21..0000000
--- a/arch/mips/loongson/lemote-2f/ec_kb3310b.h
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * KB3310B Embedded Controller
- *
- *  Copyright (C) 2008 Lemote Inc.
- *  Author: liujl <liujl@lemote.com>, 2008-03-14
- *
- * 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)
-
-/* other registers */
-/* 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,	/*  LID open/close */
-	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 */
-	EVENT_END
-};
-
-#endif /* !_EC_KB3310B_H */
diff --git a/arch/mips/loongson/lemote-2f/pm.c b/arch/mips/loongson/lemote-2f/pm.c
index d7af2e6..a3947aa 100644
--- a/arch/mips/loongson/lemote-2f/pm.c
+++ b/arch/mips/loongson/lemote-2f/pm.c
@@ -23,7 +23,7 @@
 #include <loongson.h>
 
 #include <cs5536/cs5536_mfgpt.h>
-#include "ec_kb3310b.h"
+#include "yeeloong_laptop/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;
diff --git a/arch/mips/loongson/lemote-2f/reset.c b/arch/mips/loongson/lemote-2f/reset.c
index 51d1a60..d996a55 100644
--- a/arch/mips/loongson/lemote-2f/reset.c
+++ b/arch/mips/loongson/lemote-2f/reset.c
@@ -20,7 +20,7 @@
 #include <loongson.h>
 
 #include <cs5536/cs5536.h>
-#include "ec_kb3310b.h"
+#include "yeeloong_laptop/ec_kb3310b.h"
 
 static void reset_cpu(void)
 {
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
new file mode 100644
index 0000000..d6df9b7
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
@@ -0,0 +1,15 @@
+menuconfig LEMOTE_YEELOONG2F
+	bool "Lemote YeeLoong Laptop"
+	depends on LEMOTE_MACH2F
+	default y
+	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.
+
+if LEMOTE_YEELOONG2F
+
+
+
+endif
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
new file mode 100644
index 0000000..90c4ce5
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
@@ -0,0 +1,3 @@
+# YeeLoong Specific
+
+obj-y += ec_kb3310b.o
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.c
new file mode 100644
index 0000000..cefcc72
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.c
@@ -0,0 +1,126 @@
+/*
+ * Basic KB3310B Embedded Controller support for the YeeLoong 2F netbook
+ *
+ *  Copyright (C) 2008 Lemote Inc.
+ *  Author: liujl <liujl@lemote.com>, 2008-04-20
+ *
+ * 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/module.h>
+#include <linux/spinlock.h>
+#include <linux/delay.h>
+
+#include "ec_kb3310b.h"
+
+static DEFINE_SPINLOCK(index_access_lock);
+static DEFINE_SPINLOCK(port_access_lock);
+
+unsigned char ec_read(unsigned short addr)
+{
+	unsigned char value;
+	unsigned long flags;
+
+	spin_lock_irqsave(&index_access_lock, flags);
+	outb((addr & 0xff00) >> 8, EC_IO_PORT_HIGH);
+	outb((addr & 0x00ff), EC_IO_PORT_LOW);
+	value = inb(EC_IO_PORT_DATA);
+	spin_unlock_irqrestore(&index_access_lock, flags);
+
+	return value;
+}
+EXPORT_SYMBOL_GPL(ec_read);
+
+void ec_write(unsigned short addr, unsigned char val)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&index_access_lock, flags);
+	outb((addr & 0xff00) >> 8, EC_IO_PORT_HIGH);
+	outb((addr & 0x00ff), EC_IO_PORT_LOW);
+	outb(val, EC_IO_PORT_DATA);
+	/*  flush the write action */
+	inb(EC_IO_PORT_DATA);
+	spin_unlock_irqrestore(&index_access_lock, flags);
+
+	return;
+}
+EXPORT_SYMBOL_GPL(ec_write);
+
+/*
+ * This function is used for EC command writes and corresponding status queries.
+ */
+int ec_query_seq(unsigned char cmd)
+{
+	int timeout;
+	unsigned char status;
+	unsigned long flags;
+	int ret = 0;
+
+	spin_lock_irqsave(&port_access_lock, flags);
+
+	/* make chip goto reset mode */
+	udelay(EC_REG_DELAY);
+	outb(cmd, EC_CMD_PORT);
+	udelay(EC_REG_DELAY);
+
+	/* check if the command is received by ec */
+	timeout = EC_CMD_TIMEOUT;
+	status = inb(EC_STS_PORT);
+	while (timeout-- && (status & (1 << 1))) {
+		status = inb(EC_STS_PORT);
+		udelay(EC_REG_DELAY);
+	}
+
+	if (timeout <= 0) {
+		pr_err("%s: deadable error : timeout...\n", __func__);
+		ret = -EINVAL;
+	}
+
+	spin_unlock_irqrestore(&port_access_lock, flags);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ec_query_seq);
+
+/*
+ * Send query command to EC to get the proper event number
+ */
+int ec_query_event_num(void)
+{
+	return ec_query_seq(CMD_GET_EVENT_NUM);
+}
+EXPORT_SYMBOL(ec_query_event_num);
+
+/*
+ * Get event number from EC
+ *
+ * NOTE: This routine must follow the query_event_num function in the
+ * interrupt.
+ */
+int ec_get_event_num(void)
+{
+	int timeout = 100;
+	unsigned char value;
+	unsigned char status;
+
+	udelay(EC_REG_DELAY);
+	status = inb(EC_STS_PORT);
+	udelay(EC_REG_DELAY);
+	while (timeout-- && !(status & (1 << 0))) {
+		status = inb(EC_STS_PORT);
+		udelay(EC_REG_DELAY);
+	}
+	if (timeout <= 0) {
+		pr_err("%s: get event number timeout.\n", __func__);
+		return -EINVAL;
+	}
+	value = inb(EC_DAT_PORT);
+	udelay(EC_REG_DELAY);
+
+	return value;
+}
+EXPORT_SYMBOL(ec_get_event_num);
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
new file mode 100644
index 0000000..762d888
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
@@ -0,0 +1,187 @@
+/*
+ * KB3310B Embedded Controller
+ *
+ *  Copyright (C) 2008 Lemote Inc.
+ *  Author: liujl <liujl@lemote.com>, 2008-03-14
+ *
+ * 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 */
+	EVENT_END
+};
+
+#endif /* !_EC_KB3310B_H */
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
  2009-12-01 11:07   ` [PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu Wu Zhangin
  2009-12-01 11:07   ` [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option Wu Zhangin
@ 2009-12-01 11:08   ` Wu Zhangin
  2009-12-01 14:06     ` Ralf Baechle
  2009-12-01 11:09   ` [PATCH v6 4/8] Loongson: YeeLoong: add battery driver Wu Zhangin
                     ` (4 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:08 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, Richard Purdie, Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

This patch adds YeeLoong Backlight Driver, which provides standard
interface for user-space applications to control the brightness of the
backlight.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    9 ++-
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    2 +
 .../lemote-2f/yeeloong_laptop/ec_kb3310b.h         |    1 +
 .../lemote-2f/yeeloong_laptop/yl_backlight.c       |   93 ++++++++++++++++++++
 4 files changed, 104 insertions(+), 1 deletions(-)
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c

diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
index d6df9b7..02d36d8 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
@@ -10,6 +10,13 @@ menuconfig LEMOTE_YEELOONG2F
 
 if LEMOTE_YEELOONG2F
 
-
+config YEELOONG_BACKLIGHT
+	tristate "Backlight Driver"
+	select BACKLIGHT_CLASS_DEVICE
+	default y
+	help
+	  This option adds YeeLoong Backlight Driver, which provides standard
+	  interface for user-space applications to control the brightness of
+	  the backlight.
 
 endif
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
index 90c4ce5..6c3d3dc 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
@@ -1,3 +1,5 @@
 # YeeLoong Specific
 
 obj-y += ec_kb3310b.o
+
+obj-$(CONFIG_YEELOONG_BACKLIGHT) += yl_backlight.o
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
index 762d888..0e3b5ad 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
@@ -23,6 +23,7 @@ typedef int (*sci_handler) (int status);
 extern sci_handler yeeloong_report_lid_status;
 
 #define SCI_IRQ_NUM 0x0A
+#define MAX_BRIGHTNESS 8
 
 /*
  * The following registers are determined by the EC index configuration.
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c
new file mode 100644
index 0000000..481d2ca
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c
@@ -0,0 +1,93 @@
+/*
+ * YeeLoong Backlight Driver
+ *
+ *  Copyright (C) 2009 Lemote Inc.
+ *  Author: Wu Zhangjin <wuzj@lemote.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+#include <linux/backlight.h>
+#include <linux/err.h>
+#include <linux/fb.h>
+
+#include <asm/bootinfo.h>
+
+#include "ec_kb3310b.h"
+
+MODULE_AUTHOR("Wu Zhangjin <wuzj@lemote.com>");
+MODULE_DESCRIPTION("YeeLoong laptop backlight driver");
+MODULE_LICENSE("GPL");
+
+static int yeeloong_set_brightness(struct backlight_device *bd)
+{
+	unsigned int level, current_level;
+	static unsigned int old_level;
+
+	level = (bd->props.fb_blank == FB_BLANK_UNBLANK &&
+		 bd->props.power == FB_BLANK_UNBLANK) ?
+	    bd->props.brightness : 0;
+
+	if (level > MAX_BRIGHTNESS)
+		level = MAX_BRIGHTNESS;
+	else if (level < 0)
+		level = 0;
+
+	/* Avoid to modify the brightness when EC is tuning it */
+	current_level = ec_read(REG_DISPLAY_BRIGHTNESS);
+	if ((old_level == current_level) && (old_level != level))
+		ec_write(REG_DISPLAY_BRIGHTNESS, level);
+	old_level = level;
+
+	return 0;
+}
+
+static int yeeloong_get_brightness(struct backlight_device *bd)
+{
+	return (int)ec_read(REG_DISPLAY_BRIGHTNESS);
+}
+
+static struct backlight_ops backlight_ops = {
+	.get_brightness = yeeloong_get_brightness,
+	.update_status = yeeloong_set_brightness,
+};
+
+static struct backlight_device *yeeloong_backlight_dev;
+
+static int __init yeeloong_backlight_init(void)
+{
+	int ret;
+
+	if (mips_machtype != MACH_LEMOTE_YL2F89) {
+		pr_err("This Driver is only for YeeLoong laptop\n");
+		return -EFAULT;
+	}
+
+	yeeloong_backlight_dev = backlight_device_register("backlight0", NULL,
+			NULL, &backlight_ops);
+
+	if (IS_ERR(yeeloong_backlight_dev)) {
+		ret = PTR_ERR(yeeloong_backlight_dev);
+		yeeloong_backlight_dev = NULL;
+		return ret;
+	}
+
+	yeeloong_backlight_dev->props.max_brightness = MAX_BRIGHTNESS;
+	yeeloong_backlight_dev->props.brightness =
+		yeeloong_get_brightness(yeeloong_backlight_dev);
+	backlight_update_status(yeeloong_backlight_dev);
+
+	return 0;
+}
+
+static void __exit yeeloong_backlight_exit(void)
+{
+	if (yeeloong_backlight_dev) {
+		backlight_device_unregister(yeeloong_backlight_dev);
+		yeeloong_backlight_dev = NULL;
+	}
+}
+
+module_init(yeeloong_backlight_init);
+module_exit(yeeloong_backlight_exit);
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 4/8] Loongson: YeeLoong: add battery driver
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
                     ` (2 preceding siblings ...)
  2009-12-01 11:08   ` [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver Wu Zhangin
@ 2009-12-01 11:09   ` Wu Zhangin
  2009-12-01 14:20     ` Ralf Baechle
  2009-12-01 11:09   ` [PATCH v6 5/8] Loongson: YeeLoong: add hwmon driver Wu Zhangin
                     ` (3 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:09 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, Stephen Rothwell, Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

This patch adds APM_EMULATION based Battery Driver, which provides
standard interface for user-space applications to manage the battery.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    9 ++
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    1 +
 .../lemote-2f/yeeloong_laptop/yl_battery.c         |  127 ++++++++++++++++++++
 3 files changed, 137 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_battery.c

diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
index 02d36d8..2401ed6 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
@@ -1,6 +1,7 @@
 menuconfig LEMOTE_YEELOONG2F
 	bool "Lemote YeeLoong Laptop"
 	depends on LEMOTE_MACH2F
+	select SYS_SUPPORTS_APM_EMULATION
 	default y
 	help
 	  YeeLoong netbook is a mini laptop made by Lemote, which is basically
@@ -19,4 +20,12 @@ config YEELOONG_BACKLIGHT
 	  interface for user-space applications to control the brightness of
 	  the backlight.
 
+config YEELOONG_BATTERY
+	tristate "Battery Driver"
+	depends on APM_EMULATION
+	default y
+	help
+	  This option adds APM emulated Battery Driver, which provides standard
+	  interface for user-space applications to manage the battery.
+
 endif
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
index 6c3d3dc..31e2145 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
@@ -3,3 +3,4 @@
 obj-y += ec_kb3310b.o
 
 obj-$(CONFIG_YEELOONG_BACKLIGHT) += yl_backlight.o
+obj-$(CONFIG_YEELOONG_BATTERY) += yl_battery.o
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_battery.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_battery.c
new file mode 100644
index 0000000..2a94292
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_battery.c
@@ -0,0 +1,127 @@
+/*
+ * YeeLoong Battery Driver: APM emulated support
+ *
+ *  Copyright (C) 2009 Lemote Inc.
+ *  Author: Liu Junliang <liujl@lemote.com>
+ *          Wu Zhangjin <wuzj@lemote.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/apm-emulation.h>
+#include <linux/err.h>
+#include <linux/module.h>
+
+#include <asm/bootinfo.h>
+
+#include "ec_kb3310b.h"
+
+MODULE_AUTHOR("Liu Junliang <liujl@lemote.com>; Wu Zhangjin <wuzj@lemote.com>");
+MODULE_DESCRIPTION("YeeLoong laptop battery driver");
+MODULE_LICENSE("GPL");
+
+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 __init yeeloong_battery_init(void)
+{
+	if (mips_machtype != MACH_LEMOTE_YL2F89) {
+		pr_err("This Driver is only for YeeLoong laptop\n");
+		return -EFAULT;
+	}
+
+	get_fixed_battery_info();
+
+	apm_get_power_status = get_power_status;
+
+	return 0;
+}
+
+static void __exit yeeloong_battery_exit(void)
+{
+}
+
+module_init(yeeloong_battery_init);
+module_exit(yeeloong_battery_exit);
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 5/8] Loongson: YeeLoong: add hwmon driver
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
                     ` (3 preceding siblings ...)
  2009-12-01 11:09   ` [PATCH v6 4/8] Loongson: YeeLoong: add battery driver Wu Zhangin
@ 2009-12-01 11:09   ` Wu Zhangin
  2009-12-01 14:27     ` Ralf Baechle
  2009-12-01 11:10   ` [PATCH v6 6/8] Loongson: YeeLoong: add video output driver Wu Zhangin
                     ` (2 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:09 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, lm-sensors, Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

This patch adds hwmon driver for managing the temperature of battery,
cpu and controlling the fan.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    9 +
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    1 +
 .../loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c  |  239 ++++++++++++++++++++
 3 files changed, 249 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c

diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
index 2401ed6..d13e1ab 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
@@ -28,4 +28,13 @@ config YEELOONG_BATTERY
 	  This option adds APM emulated Battery Driver, which provides standard
 	  interface for user-space applications to manage the battery.
 
+config YEELOONG_HWMON
+	tristate "Hardware Monitor Driver"
+	select HWMON
+	default y
+	help
+	  This option adds hardware monitor driver, which provides standard
+	  interface for lm-sensors to monitor the temperatures of CPU and
+	  battery, the PWM of fan, the current, voltage of battery.
+
 endif
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
index 31e2145..b38fb2a 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
@@ -4,3 +4,4 @@ obj-y += ec_kb3310b.o
 
 obj-$(CONFIG_YEELOONG_BACKLIGHT) += yl_backlight.o
 obj-$(CONFIG_YEELOONG_BATTERY) += yl_battery.o
+obj-$(CONFIG_YEELOONG_HWMON) += yl_hwmon.o
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c
new file mode 100644
index 0000000..ed8b705
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c
@@ -0,0 +1,239 @@
+/*
+ * YeeLoong Hwmon Driver
+ *
+ *  Copyright (C) 2009 Lemote Inc.
+ *  Author: Wu Zhangjin <wuzj@lemote.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+#include <linux/err.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+
+#include <asm/bootinfo.h>
+
+#include "ec_kb3310b.h"
+
+MODULE_AUTHOR("Wu Zhangjin <wuzj@lemote.com>");
+MODULE_DESCRIPTION("YeeLoong laptop hwmon driver");
+MODULE_LICENSE("GPL");
+
+/* pwm(auto/manual) enable or not */
+static int get_fan_pwm_enable(void)
+{
+	return ec_read(REG_FAN_AUTO_MAN_SWITCH);
+}
+
+static void set_fan_pwm_enable(int manual)
+{
+	ec_write(REG_FAN_AUTO_MAN_SWITCH, !!manual);
+}
+
+static int get_fan_pwm(void)
+{
+	return ec_read(REG_FAN_SPEED_LEVEL);
+}
+
+static void set_fan_pwm(int value)
+{
+	int status;
+
+	value = SENSORS_LIMIT(value, 0, 3);
+
+	/* If value is not ZERO, We should ensure it is on */
+	if (value != 0) {
+		status = ec_read(REG_FAN_STATUS);
+		if (status == 0)
+			ec_write(REG_FAN_CONTROL, BIT_FAN_CONTROL_ON);
+	}
+	ec_write(REG_FAN_SPEED_LEVEL, value);
+}
+
+static int get_fan_rpm(void)
+{
+	int value = 0;
+
+	value = FAN_SPEED_DIVIDER /
+	    (((ec_read(REG_FAN_SPEED_HIGH) & 0x0f) << 8) |
+	     ec_read(REG_FAN_SPEED_LOW));
+
+	return value;
+}
+
+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;
+
+	return value * 1000;
+}
+
+static int get_battery_temp(void)
+{
+	int value;
+
+	value = (ec_read(REG_BAT_TEMPERATURE_HIGH) << 8) |
+		(ec_read(REG_BAT_TEMPERATURE_LOW));
+
+	return value * 1000;
+}
+
+static int get_battery_temp_alarm(void)
+{
+	int status;
+
+	status = (ec_read(REG_BAT_CHARGE_STATUS) &
+			BIT_BAT_CHARGE_STATUS_OVERTEMP);
+
+	return !!status;
+}
+
+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;
+
+	return value;
+}
+
+static int get_battery_voltage(void)
+{
+	int value;
+
+	value = (ec_read(REG_BAT_VOLTAGE_HIGH) << 8) |
+		(ec_read(REG_BAT_VOLTAGE_LOW));
+
+	return value;
+}
+
+
+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;
+}
+
+static ssize_t store_sys_hwmon(void (*set) (int), const char *buf, size_t count)
+{
+	int rv, value;
+
+	rv = parse_arg(buf, count, &value);
+	if (rv > 0)
+		set(value);
+	return rv;
+}
+
+static ssize_t show_sys_hwmon(int (*get) (void), char *buf)
+{
+	return sprintf(buf, "%d\n", get());
+}
+
+#define CREATE_SENSOR_ATTR(_name, _mode, _set, _get)		\
+	static ssize_t show_##_name(struct device *dev,			\
+				    struct device_attribute *attr,	\
+				    char *buf)				\
+	{								\
+		return show_sys_hwmon(_set, buf);			\
+	}								\
+	static ssize_t store_##_name(struct device *dev,		\
+				     struct device_attribute *attr,	\
+				     const char *buf, size_t count)	\
+	{								\
+		return store_sys_hwmon(_get, buf, count);		\
+	}								\
+	static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
+
+CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, get_fan_rpm, NULL);
+CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR, get_fan_pwm, set_fan_pwm);
+CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, get_fan_pwm_enable,
+		set_fan_pwm_enable);
+CREATE_SENSOR_ATTR(temp1_input, S_IRUGO, get_cpu_temp, NULL);
+CREATE_SENSOR_ATTR(temp2_input, S_IRUGO, get_battery_temp, NULL);
+CREATE_SENSOR_ATTR(temp2_max_alarm, S_IRUGO, get_battery_temp_alarm, NULL);
+CREATE_SENSOR_ATTR(curr1_input, S_IRUGO, get_battery_current, NULL);
+CREATE_SENSOR_ATTR(in1_input, S_IRUGO, get_battery_voltage, NULL);
+
+static ssize_t
+show_name(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "yeeloong\n");
+}
+
+static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
+
+static struct attribute *hwmon_attributes[] = {
+	&sensor_dev_attr_pwm1.dev_attr.attr,
+	&sensor_dev_attr_pwm1_enable.dev_attr.attr,
+	&sensor_dev_attr_fan1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp2_input.dev_attr.attr,
+	&sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
+	&sensor_dev_attr_curr1_input.dev_attr.attr,
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_name.dev_attr.attr,
+	NULL
+};
+
+static struct attribute_group hwmon_attribute_group = {
+	.attrs = hwmon_attributes
+};
+
+struct device *yeeloong_hwmon_dev;
+
+static int __init yeeloong_hwmon_init(void)
+{
+	int ret;
+
+	if (mips_machtype != MACH_LEMOTE_YL2F89) {
+		pr_err("This Driver is only for YeeLoong laptop\n");
+		return -EFAULT;
+	}
+
+	yeeloong_hwmon_dev = hwmon_device_register(NULL);
+	if (IS_ERR(yeeloong_hwmon_dev)) {
+		pr_err("Fail to register yeeloong hwmon device\n");
+		yeeloong_hwmon_dev = NULL;
+		return PTR_ERR(yeeloong_hwmon_dev);
+	}
+	ret = sysfs_create_group(&yeeloong_hwmon_dev->kobj,
+				 &hwmon_attribute_group);
+	if (ret) {
+		sysfs_remove_group(&yeeloong_hwmon_dev->kobj,
+				   &hwmon_attribute_group);
+		hwmon_device_unregister(yeeloong_hwmon_dev);
+		yeeloong_hwmon_dev = NULL;
+	}
+	/* ensure fan is set to auto mode */
+	set_fan_pwm_enable(BIT_FAN_AUTO);
+
+	return 0;
+}
+
+static void __exit yeeloong_hwmon_exit(void)
+{
+	if (yeeloong_hwmon_dev) {
+		sysfs_remove_group(&yeeloong_hwmon_dev->kobj,
+				   &hwmon_attribute_group);
+		hwmon_device_unregister(yeeloong_hwmon_dev);
+		yeeloong_hwmon_dev = NULL;
+	}
+}
+
+module_init(yeeloong_hwmon_init);
+module_exit(yeeloong_hwmon_exit);
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 6/8] Loongson: YeeLoong: add video output driver
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
                     ` (4 preceding siblings ...)
  2009-12-01 11:09   ` [PATCH v6 5/8] Loongson: YeeLoong: add hwmon driver Wu Zhangin
@ 2009-12-01 11:10   ` Wu Zhangin
  2009-12-01 14:55     ` Ralf Baechle
  2009-12-01 11:11   ` [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver Wu Zhangin
  2009-12-01 11:12   ` [PATCH v6 8/8] Loongson: YeeLoong: add hotkey driver Wu Zhangin
  7 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:10 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, luming.yu, Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

This patch adds Video Output Driver, which provides standard interface
to turn on/off the video output of LCD, CRT.

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    8 +
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    1 +
 .../lemote-2f/yeeloong_laptop/ec_kb3310b.h         |    3 +
 .../loongson/lemote-2f/yeeloong_laptop/yl_vo.c     |  168 ++++++++++++++++++++
 4 files changed, 180 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_vo.c

diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
index d13e1ab..7cf6071 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
@@ -37,4 +37,12 @@ config YEELOONG_HWMON
 	  interface for lm-sensors to monitor the temperatures of CPU and
 	  battery, the PWM of fan, the current, voltage of battery.
 
+config YEELOONG_VO
+	tristate "Video Output Driver"
+	select VIDEO_OUTPUT_CONTROL
+	default y
+	help
+	  This option adds Video Output Driver, which provides standard
+	  interface to turn on/off the video output of LCD, CRT.
+
 endif
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
index b38fb2a..aa01140 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
@@ -5,3 +5,4 @@ obj-y += ec_kb3310b.o
 obj-$(CONFIG_YEELOONG_BACKLIGHT) += yl_backlight.o
 obj-$(CONFIG_YEELOONG_BATTERY) += yl_battery.o
 obj-$(CONFIG_YEELOONG_HWMON) += yl_hwmon.o
+obj-$(CONFIG_YEELOONG_VO) += yl_vo.o
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
index 0e3b5ad..9d06ad8 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
@@ -22,6 +22,9 @@ extern int ec_get_event_num(void);
 typedef int (*sci_handler) (int status);
 extern sci_handler yeeloong_report_lid_status;
 
+extern void yeeloong_lcd_vo_set(int status);
+extern void yeeloong_crt_vo_set(int status);
+
 #define SCI_IRQ_NUM 0x0A
 #define MAX_BRIGHTNESS 8
 
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_vo.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_vo.c
new file mode 100644
index 0000000..db19a25
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_vo.c
@@ -0,0 +1,168 @@
+/*
+ * YeeLoong Video Output Driver
+ *
+ *  Copyright (C) 2009 Lemote Inc.
+ *  Author: Wu Zhangjin <wuzj@lemote.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/err.h>
+#include <linux/video_output.h>
+
+#include <asm/bootinfo.h>
+
+#include "ec_kb3310b.h"
+
+MODULE_AUTHOR("Wu Zhangjin <wuzj@lemote.com>");
+MODULE_DESCRIPTION("YeeLoong laptop video output driver");
+MODULE_LICENSE("GPL");
+
+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;
+
+void yeeloong_lcd_vo_set(int status)
+{
+	lcd_output_dev->request_state = status;
+	lcd_video_output_set(lcd_output_dev);
+}
+EXPORT_SYMBOL(yeeloong_lcd_vo_set);
+
+void yeeloong_crt_vo_set(int status)
+{
+	crt_output_dev->request_state = status;
+	crt_video_output_set(crt_output_dev);
+}
+EXPORT_SYMBOL(yeeloong_crt_vo_set);
+
+static int __init yeeloong_vo_init(void)
+{
+	int ret;
+
+	if (mips_machtype != MACH_LEMOTE_YL2F89) {
+		pr_err("This Driver is only for YeeLoong laptop\n");
+		return -EFAULT;
+	}
+
+
+	/* 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 __exit 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;
+	}
+}
+
+module_init(yeeloong_vo_init);
+module_exit(yeeloong_vo_exit);
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
                     ` (5 preceding siblings ...)
  2009-12-01 11:10   ` [PATCH v6 6/8] Loongson: YeeLoong: add video output driver Wu Zhangin
@ 2009-12-01 11:11   ` Wu Zhangin
  2009-12-01 12:24     ` Rafael J. Wysocki
  2009-12-01 14:51     ` Ralf Baechle
  2009-12-01 11:12   ` [PATCH v6 8/8] Loongson: YeeLoong: add hotkey driver Wu Zhangin
  7 siblings, 2 replies; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:11 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: linux-mips, zhangfx, Pavel Machek, Rafael J. Wysocki, linux-pm,
	Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

This patch adds Suspend Driver, which will suspend the YeeLoong Platform
specific devices.

Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    8 +
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    1 +
 .../lemote-2f/yeeloong_laptop/yl_suspend.c         |  135 ++++++++++++++++++++
 3 files changed, 144 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c

diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
index 7cf6071..f1211b4 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
@@ -45,4 +45,12 @@ config YEELOONG_VO
 	  This option adds Video Output Driver, which provides standard
 	  interface to turn on/off the video output of LCD, CRT.
 
+config YEELOONG_SUSPEND
+	tristate "Suspend Driver"
+	depends on YEELOONG_VO && LOONGSON_SUSPEND
+	default y
+	help
+	  This option adds Suspend Driver, which will suspend the YeeLoong
+	  Platform specific devices.
+
 endif
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
index aa01140..29f8050 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_YEELOONG_BACKLIGHT) += yl_backlight.o
 obj-$(CONFIG_YEELOONG_BATTERY) += yl_battery.o
 obj-$(CONFIG_YEELOONG_HWMON) += yl_hwmon.o
 obj-$(CONFIG_YEELOONG_VO) += yl_vo.o
+obj-$(CONFIG_YEELOONG_SUSPEND) += yl_suspend.o
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
new file mode 100644
index 0000000..9f53a69
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
@@ -0,0 +1,135 @@
+/*
+ * YeeLoong Platform Specific Suspend Driver
+ *
+ *  Copyright (C) 2009 Lemote Inc.
+ *  Author: Wu Zhangjin <wuzj@lemote.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/err.h>
+#include <linux/platform_device.h>
+
+#include <asm/bootinfo.h>
+
+#include "ec_kb3310b.h"
+
+MODULE_AUTHOR("Wu Zhangjin <wuzj@lemote.com>");
+MODULE_DESCRIPTION("YeeLoong laptop suspend driver");
+MODULE_LICENSE("GPL");
+
+static struct platform_device *yeeloong_pdev;
+
+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 *pdev,
+		pm_message_t state)
+{
+	pr_info("yeeloong specific suspend\n");
+
+	/* 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)
+{
+	pr_info("yeeloong specific resume\n");
+
+	/* 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;
+}
+
+static struct platform_driver platform_driver = {
+	.driver = {
+		   .name = "yeeloong-laptop",
+		   .owner = THIS_MODULE,
+		   },
+	.suspend = yeeloong_suspend,
+	.resume = yeeloong_resume,
+};
+
+static ssize_t yeeloong_pdev_name_show(struct device *dev,
+				       struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "yeeloong laptop\n");
+}
+
+static struct device_attribute dev_attr_yeeloong_pdev_name =
+__ATTR(name, S_IRUGO, yeeloong_pdev_name_show, NULL);
+
+static int __init yeeloong_suspend_init(void)
+{
+	int ret;
+
+	if (mips_machtype != MACH_LEMOTE_YL2F89) {
+		pr_err("This Driver is only for YeeLoong laptop\n");
+		return -EFAULT;
+	}
+
+	/* Register platform stuff */
+	ret = platform_driver_register(&platform_driver);
+	if (ret)
+		return ret;
+
+	yeeloong_pdev = platform_device_alloc("yeeloong-laptop", -1);
+	if (!yeeloong_pdev) {
+		ret = -ENOMEM;
+		platform_driver_unregister(&platform_driver);
+		return ret;
+	}
+
+	ret = platform_device_add(yeeloong_pdev);
+	if (ret) {
+		platform_device_put(yeeloong_pdev);
+		return ret;
+	}
+
+	if (IS_ERR(yeeloong_pdev)) {
+		ret = PTR_ERR(yeeloong_pdev);
+		yeeloong_pdev = NULL;
+		pr_err("Fail to register platform device\n");
+		return ret;
+	}
+
+	ret = device_create_file(&yeeloong_pdev->dev,
+				 &dev_attr_yeeloong_pdev_name);
+	if (ret) {
+		pr_err("Fail to create sysfs device attributes\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static void __exit yeeloong_suspend_exit(void)
+{
+	if (yeeloong_pdev) {
+		platform_device_unregister(yeeloong_pdev);
+		yeeloong_pdev = NULL;
+		platform_driver_unregister(&platform_driver);
+	}
+}
+
+module_init(yeeloong_suspend_init);
+module_exit(yeeloong_suspend_exit);
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 8/8] Loongson: YeeLoong: add hotkey driver
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
                     ` (6 preceding siblings ...)
  2009-12-01 11:11   ` [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver Wu Zhangin
@ 2009-12-01 11:12   ` Wu Zhangin
  2009-12-01 15:40     ` Ralf Baechle
  7 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangin @ 2009-12-01 11:12 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, Dmitry Torokhov, Wu Zhangjin

From: Wu Zhangjin <wuzhangjin@gmail.com>

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

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
 arch/mips/kernel/setup.c                           |    1 +
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    9 +
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    1 +
 .../lemote-2f/yeeloong_laptop/ec_kb3310b.h         |    4 +-
 .../loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c |  448 ++++++++++++++++++++
 5 files changed, 462 insertions(+), 1 deletions(-)
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index bd55f71..b1e1272 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -60,6 +60,7 @@ struct boot_mem_map boot_mem_map;
 
 static char command_line[COMMAND_LINE_SIZE];
        char arcs_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
+EXPORT_SYMBOL(arcs_cmdline);
 
 /*
  * mips_io_port_base is the begin of the address space to which x86 style
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
index f1211b4..7a8084e 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
@@ -53,4 +53,13 @@ config YEELOONG_SUSPEND
 	  This option adds Suspend Driver, which will suspend the YeeLoong
 	  Platform specific devices.
 
+config YEELOONG_HOTKEY
+	tristate "Hotkey Driver"
+	depends on YEELOONG_VO && INPUT
+	default y
+	help
+	  This option adds Hotkey Driver, which will do relative actions for
+	  The hotkey event and report the corresponding input keys to the
+	  user-space applications.
+
 endif
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
index 29f8050..31bfda6 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_YEELOONG_BATTERY) += yl_battery.o
 obj-$(CONFIG_YEELOONG_HWMON) += yl_hwmon.o
 obj-$(CONFIG_YEELOONG_VO) += yl_vo.o
 obj-$(CONFIG_YEELOONG_SUSPEND) += yl_suspend.o
+obj-$(CONFIG_YEELOONG_HOTKEY) += yl_hotkey.o
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
index 9d06ad8..021ce11 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
@@ -185,7 +185,9 @@ enum {
 	EVENT_AC_BAT,		/*  AC & Battery relative issue */
 	EVENT_AUDIO_VOLUME,	/*  Volume adjust */
 	EVENT_WLAN,		/*  Wlan on/off */
-	EVENT_END
 };
 
+#define EVENT_START	EVENT_LID
+#define EVENT_END	EVENT_WLAN
+
 #endif /* !_EC_KB3310B_H */
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c
new file mode 100644
index 0000000..7a178b9
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c
@@ -0,0 +1,448 @@
+/*
+ * YeeLoong Hotkey Driver
+ *
+ *  Copyright (C) 2009 Lemote Inc.
+ *  Author: Wu Zhangjin <wuzj@lemote.com>
+ *          Liu Junliang <liujl@lemote.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+
+#include <asm/bootinfo.h>	/* for arcs_cmdline */
+
+#include <cs5536/cs5536.h>
+#include "ec_kb3310b.h"
+
+MODULE_AUTHOR("Wu Zhangjin <wuzj@lemote.com>; Liu Junliang <liujl@lemote.com>");
+MODULE_DESCRIPTION("YeeLoong laptop hotkey driver");
+MODULE_LICENSE("GPL");
+
+static struct input_dev *yeeloong_hotkey_dev;
+static int event, status;
+
+struct key_entry {
+	char type;		/* See KE_* below */
+	int event;		/* event from SCI */
+	u16 keycode;		/* KEY_* or SW_* */
+};
+
+enum { KE_KEY, KE_SW, KE_END };
+
+#define EVENT_UNKNOWN	0
+
+static struct key_entry yeeloong_keymap[] = {
+	{KE_SW, EVENT_LID, SW_LID},
+	{KE_KEY, EVENT_CAMERA, KEY_CAMERA},	/* Fn + ESC */
+	{KE_KEY, EVENT_SLEEP, KEY_SLEEP},	/* Fn + F1 */
+	{KE_KEY, EVENT_DISPLAY_TOGGLE, KEY_SWITCHVIDEOMODE},	/* Fn + F3 */
+	{KE_KEY, EVENT_AUDIO_MUTE, KEY_MUTE},	/* Fn + F4 */
+	{KE_KEY, EVENT_WLAN, KEY_WLAN},	/* Fn + F5 */
+	{KE_KEY, EVENT_DISPLAY_BRIGHTNESS, KEY_BRIGHTNESSUP},	/* Fn + up */
+	{KE_KEY, EVENT_DISPLAY_BRIGHTNESS, KEY_BRIGHTNESSDOWN},	/* Fn + down */
+	{KE_KEY, EVENT_AUDIO_VOLUME, KEY_VOLUMEUP},	/* Fn + right */
+	{KE_KEY, EVENT_AUDIO_VOLUME, KEY_VOLUMEDOWN},	/* Fn + left */
+	{KE_END, EVENT_UNKNOWN, KEY_UNKNOWN}
+};
+
+static int get_event_keycode(void)
+{
+	struct key_entry *key;
+
+	for (key = yeeloong_keymap; key->type != KE_END; key++) {
+		if (key->event != event)
+			continue;
+		else {
+			if (EVENT_DISPLAY_BRIGHTNESS == event) {
+				static int old_brightness_status = -1;
+				/* current status > old one, means up */
+				if ((status < old_brightness_status)
+				    || (0 == status))
+					key++;
+				old_brightness_status = status;
+			} else if (EVENT_AUDIO_VOLUME == event) {
+				static int old_volume_status = -1;
+				if ((status < old_volume_status)
+				    || (0 == status))
+					key++;
+				old_volume_status = status;
+			}
+			break;
+		}
+	}
+	return key->keycode;
+}
+
+static int report_lid_switch(int status)
+{
+	input_report_switch(yeeloong_hotkey_dev, SW_LID, !status);
+	input_sync(yeeloong_hotkey_dev);
+
+	return status;
+}
+
+void report_key(int keycode)
+{
+	if (keycode == SW_LID)
+		report_lid_switch(status);
+	else {
+		input_report_key(yeeloong_hotkey_dev, keycode, 1);
+		input_sync(yeeloong_hotkey_dev);
+		input_report_key(yeeloong_hotkey_dev, keycode, 0);
+		input_sync(yeeloong_hotkey_dev);
+	}
+}
+
+static int crt_detect_handler(int status)
+{
+	if (status == BIT_CRT_DETECT_PLUG) {
+		yeeloong_crt_vo_set(BIT_CRT_DETECT_PLUG);
+		yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_OFF);
+	} else {
+		yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
+		yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
+	}
+	return status;
+}
+
+#define EC_VER_LEN 64
+
+static int black_screen_handler(int status)
+{
+	char *p, ec_ver[EC_VER_LEN];
+
+	p = strstr(arcs_cmdline, "EC_VER=");
+	if (!p)
+		memset(ec_ver, 0, EC_VER_LEN);
+	else {
+		strncpy(ec_ver, p, EC_VER_LEN);
+		p = strstr(ec_ver, " ");
+		if (p)
+			*p = '\0';
+	}
+
+	/* Seems EC(>=PQ1D26) does this job for us, we can not do it again,
+	 * otherwise, the brightness will not resume to the normal level! */
+	if (strncasecmp(ec_ver, "EC_VER=PQ1D26", 64) < 0)
+		yeeloong_lcd_vo_set(status);
+
+	return status;
+}
+
+static int display_toggle_handler(int status)
+{
+	static int video_output_status;
+
+	/* Only enable switch video output button
+	 * when CRT is connected */
+	if (ec_read(REG_CRT_DETECT) == BIT_CRT_DETECT_UNPLUG)
+		return 0;
+	/* 0. no CRT connected: LCD on, CRT off
+	 * 1. BOTH on
+	 * 2. LCD off, CRT on
+	 * 3. BOTH off
+	 * 4. LCD on, CRT off
+	 */
+	video_output_status++;
+	if (video_output_status > 4)
+		video_output_status = 1;
+
+	switch (video_output_status) {
+	case 1:
+		yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
+		yeeloong_crt_vo_set(BIT_CRT_DETECT_PLUG);
+		break;
+	case 2:
+		yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_OFF);
+		yeeloong_crt_vo_set(BIT_CRT_DETECT_PLUG);
+		break;
+	case 3:
+		yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_OFF);
+		yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
+		break;
+	case 4:
+		yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
+		yeeloong_crt_vo_set(BIT_CRT_DETECT_UNPLUG);
+		break;
+	default:
+		/* Ensure LCD is on */
+		yeeloong_lcd_vo_set(BIT_DISPLAY_LCD_ON);
+		break;
+	}
+	return video_output_status;
+}
+
+static int camera_handler(int status)
+{
+	int value;
+
+	value = ec_read(REG_CAMERA_CONTROL);
+	ec_write(REG_CAMERA_CONTROL, value | (1 << 1));
+
+	return status;
+}
+
+static int usb2_handler(int status)
+{
+	pr_emerg("USB2 Over Current occurred\n");
+
+	return status;
+}
+
+static int usb0_handler(int status)
+{
+	pr_emerg("USB0 Over Current occurred\n");
+
+	return status;
+}
+
+/* yeeloong_wifi_handler may be implemented in the wifi driver */
+sci_handler yeeloong_wifi_handler;
+EXPORT_SYMBOL(yeeloong_wifi_handler);
+
+#define NO_REG		0
+#define NO_HANDLER	NULL
+/* 2 maybe used to indicate the key as a switch button, such as EVENT_WLAN */
+#define NO_STATUS	2
+
+static void do_event_action(void)
+{
+	sci_handler handler;
+	int reg, keycode;
+
+	reg = NO_REG;
+	handler = NO_HANDLER;
+	status = NO_STATUS;
+
+	switch (event) {
+	case EVENT_LID:
+		reg = REG_LID_DETECT;
+		break;
+	case EVENT_DISPLAY_TOGGLE:
+		handler = display_toggle_handler;
+		break;
+	case EVENT_CRT_DETECT:
+		reg = REG_CRT_DETECT;
+		handler = crt_detect_handler;
+		break;
+	case EVENT_CAMERA:
+		reg = REG_CAMERA_STATUS;
+		handler = camera_handler;
+		break;
+	case EVENT_USB_OC2:
+		reg = REG_USB2_FLAG;
+		handler = usb2_handler;
+		break;
+	case EVENT_USB_OC0:
+		reg = REG_USB0_FLAG;
+		handler = usb0_handler;
+		break;
+	case EVENT_BLACK_SCREEN:
+		reg = REG_DISPLAY_LCD;
+		handler = black_screen_handler;
+		break;
+	case EVENT_AUDIO_MUTE:
+		reg = REG_AUDIO_MUTE;
+		break;
+	case EVENT_DISPLAY_BRIGHTNESS:
+		reg = REG_DISPLAY_BRIGHTNESS;
+		break;
+	case EVENT_AUDIO_VOLUME:
+		reg = REG_AUDIO_VOLUME;
+		break;
+	case EVENT_WLAN:
+		handler = yeeloong_wifi_handler;
+		break;
+	default:
+		break;
+	}
+
+	if (reg != NO_REG)
+		status = ec_read(reg);
+
+	if (handler != NO_HANDLER)
+		status = handler(status);
+
+	/* Report current key to user-space */
+	keycode = get_event_keycode();
+	if (keycode != KEY_UNKNOWN)
+		report_key(keycode);
+}
+
+/*
+ * SCI(system control interrupt) main interrupt routine
+ *
+ * We will do the query and get event number together so the interrupt routine
+ * should be longer than 120us now at least 3ms elpase for it.
+ */
+static irqreturn_t sci_irq_handler(int irq, void *dev_id)
+{
+	int ret;
+
+	if (SCI_IRQ_NUM != irq)
+		return IRQ_NONE;
+
+	/* Query the event number */
+	ret = ec_query_event_num();
+	if (ret < 0)
+		return IRQ_NONE;
+
+	event = ec_get_event_num();
+	if (event < EVENT_START || event > EVENT_END)
+		return IRQ_NONE;
+
+	/* Execute corresponding actions */
+	do_event_action();
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * Config and init some msr and gpio register properly.
+ */
+static int sci_irq_init(void)
+{
+	u32 hi, lo;
+	u32 gpio_base;
+	unsigned long flags;
+	int ret;
+
+	/* Get gpio base */
+	_rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_GPIO), &hi, &lo);
+	gpio_base = lo & 0xff00;
+
+	/* Filter the former kb3310 interrupt for security */
+	ret = ec_query_event_num();
+	if (ret)
+		return ret;
+
+	/* For filtering next number interrupt */
+	udelay(10000);
+
+	/* Set gpio native registers and msrs for GPIO27 SCI EVENT PIN
+	 * gpio :
+	 *      input, pull-up, no-invert, event-count and value 0,
+	 *      no-filter, no edge mode
+	 *      gpio27 map to Virtual gpio0
+	 * msr :
+	 *      no primary and lpc
+	 *      Unrestricted Z input to IG10 from Virtual gpio 0.
+	 */
+	local_irq_save(flags);
+	_rdmsr(0x80000024, &hi, &lo);
+	lo &= ~(1 << 10);
+	_wrmsr(0x80000024, hi, lo);
+	_rdmsr(0x80000025, &hi, &lo);
+	lo &= ~(1 << 10);
+	_wrmsr(0x80000025, hi, lo);
+	_rdmsr(0x80000023, &hi, &lo);
+	lo |= (0x0a << 0);
+	_wrmsr(0x80000023, hi, lo);
+	local_irq_restore(flags);
+
+	/* Set gpio27 as sci interrupt
+	 *
+	 * input, pull-up, no-fliter, no-negedge, invert
+	 * the sci event is just about 120us
+	 */
+	asm(".set noreorder\n");
+	/*  input enable */
+	outl(0x00000800, (gpio_base | 0xA0));
+	/*  revert the input */
+	outl(0x00000800, (gpio_base | 0xA4));
+	/*  event-int enable */
+	outl(0x00000800, (gpio_base | 0xB8));
+	asm(".set reorder\n");
+
+	return 0;
+}
+
+static struct irqaction sci_irqaction = {
+	.handler = sci_irq_handler,
+	.name = "sci",
+	.flags = IRQF_SHARED,
+};
+
+static int __init yeeloong_hotkey_init(void)
+{
+	int ret;
+	struct key_entry *key;
+
+	if (mips_machtype != MACH_LEMOTE_YL2F89) {
+		pr_err("This Driver is only for YeeLoong laptop\n");
+		return -EFAULT;
+	}
+
+	ret = sci_irq_init();
+	if (ret)
+		return -EFAULT;
+
+	ret = setup_irq(SCI_IRQ_NUM, &sci_irqaction);
+	if (ret)
+		return -EFAULT;
+
+	yeeloong_hotkey_dev = input_allocate_device();
+
+	if (!yeeloong_hotkey_dev) {
+		remove_irq(SCI_IRQ_NUM, &sci_irqaction);
+		return -ENOMEM;
+	}
+
+	yeeloong_hotkey_dev->name = "HotKeys";
+	yeeloong_hotkey_dev->phys = "button/input0";
+	yeeloong_hotkey_dev->id.bustype = BUS_HOST;
+	yeeloong_hotkey_dev->dev.parent = NULL;
+
+	for (key = yeeloong_keymap; key->type != KE_END; key++) {
+		switch (key->type) {
+		case KE_KEY:
+			set_bit(EV_KEY, yeeloong_hotkey_dev->evbit);
+			set_bit(key->keycode, yeeloong_hotkey_dev->keybit);
+			break;
+		case KE_SW:
+			set_bit(EV_SW, yeeloong_hotkey_dev->evbit);
+			set_bit(key->keycode, yeeloong_hotkey_dev->swbit);
+			break;
+		}
+	}
+
+	ret = input_register_device(yeeloong_hotkey_dev);
+	if (ret) {
+		input_free_device(yeeloong_hotkey_dev);
+		return ret;
+	}
+
+	/* Update the current status of LID */
+	report_lid_switch(BIT_LID_DETECT_ON);
+
+#ifdef CONFIG_LOONGSON_SUSPEND
+	/* Install the real yeeloong_report_lid_status for pm.c */
+	yeeloong_report_lid_status = report_lid_switch;
+#endif
+
+	return 0;
+}
+
+static void __exit yeeloong_hotkey_exit(void)
+{
+	/* Free irq */
+	remove_irq(SCI_IRQ_NUM, &sci_irqaction);
+
+#ifdef CONFIG_LOONGSON_SUSPEND
+	/* Uninstall yeeloong_report_lid_status for pm.c */
+	yeeloong_report_lid_status = NULL;
+#endif
+
+	if (yeeloong_hotkey_dev) {
+		input_unregister_device(yeeloong_hotkey_dev);
+		yeeloong_hotkey_dev = NULL;
+	}
+}
+
+module_init(yeeloong_hotkey_init);
+module_exit(yeeloong_hotkey_exit);
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 0/8] Loongson: YeeLoong: add platform specific drivers
  2009-12-01 11:06 [PATCH v6 0/8] Loongson: YeeLoong: add platform specific drivers Wu Zhangin
       [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
@ 2009-12-01 11:16 ` Wu Zhangjin
  1 sibling, 0 replies; 30+ messages in thread
From: Wu Zhangjin @ 2009-12-01 11:16 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: Dmitry Torokhov, Pavel Machek, Rafael J. Wysocki, linux-mips, zhangfx

Sorry, I have sent this stuff 8 times, forgive me ;(

On Tue, 2009-12-01 at 19:06 +0800, Wu Zhangin wrote:
> From: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> This patchset adds platform specific drivers for YeeLoong netbook. including
> the backlight, battery, hwmon, video output, suspend and hotkey(input) drivers.
> These drivers provide standard interfaces to the user-space applications to
> manage the relative devices:
> 	
>  	 Modules			Tools
> 
> 	- 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	?
> 	- suspend
> 	  /sys/power/state		kpowersave, gnome-power-manager
> 	- hotkey
> 	  /sys/class/input/		gnome-settings-daemon ?
> 
> To utilize the above interfaces, you are recommended to install the latest hal,
> dbus.
> 
> This v6 revision incorporates with the feedbacks from Ralf, Pavel Machek,
> Rafael J. Wysocki and Dmitry Torokhov.
> 
> Changes from the old v5 revision:
> 
> 	- Cleanup the "select" and "depend" of the options
> 	  Replace some "select"s by "depend"s to avoid potential compiling
> 	  errors.
> 
> 	- Cleanup the hotkey(input) driver
> 	  Merge several functions, Cleanup the comments, Use Switch...Case
> 	  instead of the array.
> 
> 	- Fixup of the video output driver  
> 	  Seems the video output subsystem doesn't handle the input value, we
> 	  handle it outselves via !!od->request_state.
> 
> 	- Append the yl_ prefix to the file names
> 	  yl_ prefix is needed to distinguish it with the next patchset for
> 	  lynloong pc platform drivers.
> 
> All changes have been tested again.
> 
> Best Regards,
>      Wu Zhangjin
> 
> Wu Zhangjin (8):
>   Loongson: Lemote-2F: add platform specific submenu
>   Loongson: YeeLoong: add platform specific option
>   Loongson: YeeLoong: add backlight driver
>   Loongson: YeeLoong: add battery driver
>   Loongson: YeeLoong: add hwmon driver
>   Loongson: YeeLoong: add video output driver
>   Loongson: YeeLoong: add suspend driver
>   Loongson: YeeLoong: add hotkey driver
> 
>  arch/mips/kernel/setup.c                           |    1 +
>  arch/mips/loongson/Kconfig                         |   21 +
>  arch/mips/loongson/lemote-2f/Makefile              |    7 +-
>  arch/mips/loongson/lemote-2f/ec_kb3310b.c          |  130 ------
>  arch/mips/loongson/lemote-2f/ec_kb3310b.h          |  188 --------
>  arch/mips/loongson/lemote-2f/pm.c                  |    4 +-
>  arch/mips/loongson/lemote-2f/reset.c               |    2 +-
>  .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |   65 +++
>  .../loongson/lemote-2f/yeeloong_laptop/Makefile    |   10 +
>  .../lemote-2f/yeeloong_laptop/ec_kb3310b.c         |  126 ++++++
>  .../lemote-2f/yeeloong_laptop/ec_kb3310b.h         |  193 +++++++++
>  .../lemote-2f/yeeloong_laptop/yl_backlight.c       |   93 ++++
>  .../lemote-2f/yeeloong_laptop/yl_battery.c         |  127 ++++++
>  .../loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c |  452 ++++++++++++++++++++
>  .../loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c  |  239 +++++++++++
>  .../lemote-2f/yeeloong_laptop/yl_suspend.c         |  135 ++++++
>  .../loongson/lemote-2f/yeeloong_laptop/yl_vo.c     |  164 +++++++
>  17 files changed, 1635 insertions(+), 322 deletions(-)
>  delete mode 100644 arch/mips/loongson/lemote-2f/ec_kb3310b.c
>  delete mode 100644 arch/mips/loongson/lemote-2f/ec_kb3310b.h
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.c
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_battery.c
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hotkey.c
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_hwmon.c
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_vo.c
> 

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver
  2009-12-01 11:11   ` [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver Wu Zhangin
@ 2009-12-01 12:24     ` Rafael J. Wysocki
  2009-12-01 15:18       ` Ralf Baechle
  2009-12-01 14:51     ` Ralf Baechle
  1 sibling, 1 reply; 30+ messages in thread
From: Rafael J. Wysocki @ 2009-12-01 12:24 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: Ralf Baechle, linux-mips, zhangfx, Pavel Machek, linux-pm

On Tuesday 01 December 2009, Wu Zhangin wrote:
> From: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> This patch adds Suspend Driver, which will suspend the YeeLoong Platform
> specific devices.
> 
> Acked-by: Pavel Machek <pavel@ucw.cz>
> Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>

I'm still not sure how useful it is to build it as a module, but otherwise

Acked-by: Rafael J. Wysocki <rjw@sisk.pl>

> ---
>  .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    8 +
>  .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    1 +
>  .../lemote-2f/yeeloong_laptop/yl_suspend.c         |  135 ++++++++++++++++++++
>  3 files changed, 144 insertions(+), 0 deletions(-)
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
> 
> diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
> index 7cf6071..f1211b4 100644
> --- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
> +++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
> @@ -45,4 +45,12 @@ config YEELOONG_VO
>  	  This option adds Video Output Driver, which provides standard
>  	  interface to turn on/off the video output of LCD, CRT.
>  
> +config YEELOONG_SUSPEND
> +	tristate "Suspend Driver"
> +	depends on YEELOONG_VO && LOONGSON_SUSPEND
> +	default y
> +	help
> +	  This option adds Suspend Driver, which will suspend the YeeLoong
> +	  Platform specific devices.
> +
>  endif
> diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
> index aa01140..29f8050 100644
> --- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
> +++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
> @@ -6,3 +6,4 @@ obj-$(CONFIG_YEELOONG_BACKLIGHT) += yl_backlight.o
>  obj-$(CONFIG_YEELOONG_BATTERY) += yl_battery.o
>  obj-$(CONFIG_YEELOONG_HWMON) += yl_hwmon.o
>  obj-$(CONFIG_YEELOONG_VO) += yl_vo.o
> +obj-$(CONFIG_YEELOONG_SUSPEND) += yl_suspend.o
> diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
> new file mode 100644
> index 0000000..9f53a69
> --- /dev/null
> +++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
> @@ -0,0 +1,135 @@
> +/*
> + * YeeLoong Platform Specific Suspend Driver
> + *
> + *  Copyright (C) 2009 Lemote Inc.
> + *  Author: Wu Zhangjin <wuzj@lemote.com>
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2 as
> + *  published by the Free Software Foundation.
> + */
> +
> +#include <linux/err.h>
> +#include <linux/platform_device.h>
> +
> +#include <asm/bootinfo.h>
> +
> +#include "ec_kb3310b.h"
> +
> +MODULE_AUTHOR("Wu Zhangjin <wuzj@lemote.com>");
> +MODULE_DESCRIPTION("YeeLoong laptop suspend driver");
> +MODULE_LICENSE("GPL");
> +
> +static struct platform_device *yeeloong_pdev;
> +
> +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 *pdev,
> +		pm_message_t state)
> +{
> +	pr_info("yeeloong specific suspend\n");
> +
> +	/* 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)
> +{
> +	pr_info("yeeloong specific resume\n");
> +
> +	/* 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;
> +}
> +
> +static struct platform_driver platform_driver = {
> +	.driver = {
> +		   .name = "yeeloong-laptop",
> +		   .owner = THIS_MODULE,
> +		   },
> +	.suspend = yeeloong_suspend,
> +	.resume = yeeloong_resume,
> +};
> +
> +static ssize_t yeeloong_pdev_name_show(struct device *dev,
> +				       struct device_attribute *attr, char *buf)
> +{
> +	return sprintf(buf, "yeeloong laptop\n");
> +}
> +
> +static struct device_attribute dev_attr_yeeloong_pdev_name =
> +__ATTR(name, S_IRUGO, yeeloong_pdev_name_show, NULL);
> +
> +static int __init yeeloong_suspend_init(void)
> +{
> +	int ret;
> +
> +	if (mips_machtype != MACH_LEMOTE_YL2F89) {
> +		pr_err("This Driver is only for YeeLoong laptop\n");
> +		return -EFAULT;
> +	}
> +
> +	/* Register platform stuff */
> +	ret = platform_driver_register(&platform_driver);
> +	if (ret)
> +		return ret;
> +
> +	yeeloong_pdev = platform_device_alloc("yeeloong-laptop", -1);
> +	if (!yeeloong_pdev) {
> +		ret = -ENOMEM;
> +		platform_driver_unregister(&platform_driver);
> +		return ret;
> +	}
> +
> +	ret = platform_device_add(yeeloong_pdev);
> +	if (ret) {
> +		platform_device_put(yeeloong_pdev);
> +		return ret;
> +	}
> +
> +	if (IS_ERR(yeeloong_pdev)) {
> +		ret = PTR_ERR(yeeloong_pdev);
> +		yeeloong_pdev = NULL;
> +		pr_err("Fail to register platform device\n");
> +		return ret;
> +	}
> +
> +	ret = device_create_file(&yeeloong_pdev->dev,
> +				 &dev_attr_yeeloong_pdev_name);
> +	if (ret) {
> +		pr_err("Fail to create sysfs device attributes\n");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static void __exit yeeloong_suspend_exit(void)
> +{
> +	if (yeeloong_pdev) {
> +		platform_device_unregister(yeeloong_pdev);
> +		yeeloong_pdev = NULL;
> +		platform_driver_unregister(&platform_driver);
> +	}
> +}
> +
> +module_init(yeeloong_suspend_init);
> +module_exit(yeeloong_suspend_exit);
> 

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu
  2009-12-01 11:07   ` [PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu Wu Zhangin
@ 2009-12-01 13:32     ` Ralf Baechle
  2009-12-01 13:35       ` Wu Zhangjin
  0 siblings, 1 reply; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 13:32 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: linux-mips, zhangfx

On Tue, Dec 01, 2009 at 07:07:23PM +0800, Wu Zhangin wrote:

>  arch/mips/loongson/Kconfig |   20 ++++++++++++++++++++
>  1 files changed, 20 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/mips/loongson/Kconfig b/arch/mips/loongson/Kconfig
> index 3df1967..a34dfcc 100644
> --- a/arch/mips/loongson/Kconfig
> +++ b/arch/mips/loongson/Kconfig
> @@ -83,3 +83,23 @@ config LOONGSON_UART_BASE
>  	bool
>  	default y
>  	depends on EARLY_PRINTK || SERIAL_8250
> +
> +#
> +# Loongson Platform Specific Drivers
> +#
> +
> +menuconfig LOONGSON_PLATFORM_DEVICES
> +	bool "Loongson Platform Drivers"
> +	default y
> +	help
> +	  Say Y here to get to see options for device drivers of various
> +	  loongson platforms, including vendor-specific 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 LOONGSON_PLATFORM_DEVICES
> +# Put platform specific stuff here

Useless comment.  LOONGSON_PLATFORM_DEVICES already says exactly that.

> +
> +
> +endif # LOONGSON_PLATFORM_DEVICES

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option
  2009-12-01 11:07   ` [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option Wu Zhangin
@ 2009-12-01 13:34     ` Ralf Baechle
  2009-12-01 13:39       ` Wu Zhangjin
  0 siblings, 1 reply; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 13:34 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: linux-mips, zhangfx

On Tue, Dec 01, 2009 at 07:07:45PM +0800, Wu Zhangin wrote:

> This patch add a new LEMOTE_YEELOONG2F option, a yeeloong_laptop/
> directory for the coming yeeloong specific support, and for the
> ec_kb3310b belongs to yeeloong, so, move it to yeeloong_laptop/ too.
> 
> Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>

I suggest you fold this patch into patch 2/8.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu
  2009-12-01 13:32     ` Ralf Baechle
@ 2009-12-01 13:35       ` Wu Zhangjin
  0 siblings, 0 replies; 30+ messages in thread
From: Wu Zhangjin @ 2009-12-01 13:35 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx

On Tue, 2009-12-01 at 13:32 +0000, Ralf Baechle wrote:
> On Tue, Dec 01, 2009 at 07:07:23PM +0800, Wu Zhangin wrote:
> 
> >  arch/mips/loongson/Kconfig |   20 ++++++++++++++++++++
> >  1 files changed, 20 insertions(+), 0 deletions(-)
> > 
> > diff --git a/arch/mips/loongson/Kconfig b/arch/mips/loongson/Kconfig
> > index 3df1967..a34dfcc 100644
> > --- a/arch/mips/loongson/Kconfig
> > +++ b/arch/mips/loongson/Kconfig
> > @@ -83,3 +83,23 @@ config LOONGSON_UART_BASE
> >  	bool
> >  	default y
> >  	depends on EARLY_PRINTK || SERIAL_8250
> > +
> > +#
> > +# Loongson Platform Specific Drivers
> > +#
> > +
> > +menuconfig LOONGSON_PLATFORM_DEVICES
> > +	bool "Loongson Platform Drivers"
> > +	default y
> > +	help
> > +	  Say Y here to get to see options for device drivers of various
> > +	  loongson platforms, including vendor-specific 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 LOONGSON_PLATFORM_DEVICES
> > +# Put platform specific stuff here
> 
> Useless comment.  LOONGSON_PLATFORM_DEVICES already says exactly that.
> 

Yep, Need to remove it  ;)

Thanks!
	Wu Zhangjin

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option
  2009-12-01 13:34     ` Ralf Baechle
@ 2009-12-01 13:39       ` Wu Zhangjin
  2009-12-01 14:17         ` Ralf Baechle
  0 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangjin @ 2009-12-01 13:39 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx

On Tue, 2009-12-01 at 13:34 +0000, Ralf Baechle wrote:
> On Tue, Dec 01, 2009 at 07:07:45PM +0800, Wu Zhangin wrote:
> 
> > This patch add a new LEMOTE_YEELOONG2F option, a yeeloong_laptop/
> > directory for the coming yeeloong specific support, and for the
> > ec_kb3310b belongs to yeeloong, so, move it to yeeloong_laptop/ too.
> > 
> > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> I suggest you fold this patch into patch 2/8.

Sorry, do you mean merging the following two? for this patch itself is
2/8?

[PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu
[PATCH v6 2/8] Loongson: YeeLoong: add platform specific option

Regards,
	Wu Zhangjin

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver
  2009-12-01 11:08   ` [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver Wu Zhangin
@ 2009-12-01 14:06     ` Ralf Baechle
  2009-12-01 14:52       ` Wu Zhangjin
  0 siblings, 1 reply; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 14:06 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: linux-mips, zhangfx, Richard Purdie

On Tue, Dec 01, 2009 at 07:08:42PM +0800, Wu Zhangin wrote:

> From: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> This patch adds YeeLoong Backlight Driver, which provides standard
> interface for user-space applications to control the brightness of the
> backlight.
> 
> Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>

You split old, big driver into several individual drivers - good.

Now we can actually move things to their rightf place and for a backlight
drivers that should be drivers/video/backlight/.  Convert it to a platform
driver.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option
  2009-12-01 13:39       ` Wu Zhangjin
@ 2009-12-01 14:17         ` Ralf Baechle
  0 siblings, 0 replies; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 14:17 UTC (permalink / raw)
  To: Wu Zhangjin; +Cc: linux-mips, zhangfx

On Tue, Dec 01, 2009 at 09:39:11PM +0800, Wu Zhangjin wrote:

> On Tue, 2009-12-01 at 13:34 +0000, Ralf Baechle wrote:
> > On Tue, Dec 01, 2009 at 07:07:45PM +0800, Wu Zhangin wrote:
> > 
> > > This patch add a new LEMOTE_YEELOONG2F option, a yeeloong_laptop/
> > > directory for the coming yeeloong specific support, and for the
> > > ec_kb3310b belongs to yeeloong, so, move it to yeeloong_laptop/ too.
> > > 
> > > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> > 
> > I suggest you fold this patch into patch 2/8.
> 
> Sorry, do you mean merging the following two? for this patch itself is
> 2/8?
> 
> [PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu
> [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option

Yes.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 4/8] Loongson: YeeLoong: add battery driver
  2009-12-01 11:09   ` [PATCH v6 4/8] Loongson: YeeLoong: add battery driver Wu Zhangin
@ 2009-12-01 14:20     ` Ralf Baechle
  0 siblings, 0 replies; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 14:20 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: linux-mips, zhangfx, Stephen Rothwell

On Tue, Dec 01, 2009 at 07:09:19PM +0800, Wu Zhangin wrote:

> From: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> This patch adds APM_EMULATION based Battery Driver, which provides
> standard interface for user-space applications to manage the battery.

This one as well is a candidate to become a platform driver.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 5/8] Loongson: YeeLoong: add hwmon driver
  2009-12-01 11:09   ` [PATCH v6 5/8] Loongson: YeeLoong: add hwmon driver Wu Zhangin
@ 2009-12-01 14:27     ` Ralf Baechle
  0 siblings, 0 replies; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 14:27 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: linux-mips, zhangfx, lm-sensors

On Tue, Dec 01, 2009 at 07:09:59PM +0800, Wu Zhangin wrote:

> From: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> This patch adds hwmon driver for managing the temperature of battery,
> cpu and controlling the fan.

And this one should now go to drivers/hwmon and become a platform driver
as well.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver
  2009-12-01 11:11   ` [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver Wu Zhangin
  2009-12-01 12:24     ` Rafael J. Wysocki
@ 2009-12-01 14:51     ` Ralf Baechle
  1 sibling, 0 replies; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 14:51 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: linux-mips, zhangfx, Pavel Machek, Rafael J. Wysocki, linux-pm

On Tue, Dec 01, 2009 at 07:11:55PM +0800, Wu Zhangin wrote:
> From: Wu Zhangin <wuzhangjin@gmail.com>
> Date:   Tue,  1 Dec 2009 19:11:55 +0800
> To: Ralf Baechle <ralf@linux-mips.org>
> Cc: linux-mips@linux-mips.org, zhangfx@lemote.com,
> 	Pavel Machek <pavel@ucw.cz>, "Rafael J. Wysocki" <rjw@sisk.pl>,
> 	linux-pm@lists.linux-foundation.org,
> 	Wu Zhangjin <wuzhangjin@gmail.com>
> Subject: [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver
> 
> From: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> This patch adds Suspend Driver, which will suspend the YeeLoong Platform
> specific devices.
> 
> Acked-by: Pavel Machek <pavel@ucw.cz>
> Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> ---
>  .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    8 +
>  .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    1 +
>  .../lemote-2f/yeeloong_laptop/yl_suspend.c         |  135 ++++++++++++++++++++
>  3 files changed, 144 insertions(+), 0 deletions(-)
>  create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
> 
> diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
> index 7cf6071..f1211b4 100644
> --- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
> +++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
> @@ -45,4 +45,12 @@ config YEELOONG_VO
>  	  This option adds Video Output Driver, which provides standard
>  	  interface to turn on/off the video output of LCD, CRT.
>  
> +config YEELOONG_SUSPEND
> +	tristate "Suspend Driver"
> +	depends on YEELOONG_VO && LOONGSON_SUSPEND
> +	default y
> +	help
> +	  This option adds Suspend Driver, which will suspend the YeeLoong
> +	  Platform specific devices.
> +
>  endif
> diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
> index aa01140..29f8050 100644
> --- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
> +++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
> @@ -6,3 +6,4 @@ obj-$(CONFIG_YEELOONG_BACKLIGHT) += yl_backlight.o
>  obj-$(CONFIG_YEELOONG_BATTERY) += yl_battery.o
>  obj-$(CONFIG_YEELOONG_HWMON) += yl_hwmon.o
>  obj-$(CONFIG_YEELOONG_VO) += yl_vo.o
> +obj-$(CONFIG_YEELOONG_SUSPEND) += yl_suspend.o
> diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
> new file mode 100644
> index 0000000..9f53a69
> --- /dev/null
> +++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_suspend.c
> @@ -0,0 +1,135 @@
> +/*
> + * YeeLoong Platform Specific Suspend Driver
> + *
> + *  Copyright (C) 2009 Lemote Inc.
> + *  Author: Wu Zhangjin <wuzj@lemote.com>
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2 as
> + *  published by the Free Software Foundation.
> + */
> +
> +#include <linux/err.h>
> +#include <linux/platform_device.h>
> +
> +#include <asm/bootinfo.h>
> +
> +#include "ec_kb3310b.h"
> +
> +MODULE_AUTHOR("Wu Zhangjin <wuzj@lemote.com>");
> +MODULE_DESCRIPTION("YeeLoong laptop suspend driver");
> +MODULE_LICENSE("GPL");
> +
> +static struct platform_device *yeeloong_pdev;
> +
> +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 *pdev,
> +		pm_message_t state)
> +{
> +	pr_info("yeeloong specific suspend\n");
> +
> +	/* 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)
> +{
> +	pr_info("yeeloong specific resume\n");
> +
> +	/* 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;
> +}
> +
> +static struct platform_driver platform_driver = {
> +	.driver = {
> +		   .name = "yeeloong-laptop",
> +		   .owner = THIS_MODULE,
> +		   },
> +	.suspend = yeeloong_suspend,
> +	.resume = yeeloong_resume,
> +};
> +
> +static ssize_t yeeloong_pdev_name_show(struct device *dev,
> +				       struct device_attribute *attr, char *buf)
> +{
> +	return sprintf(buf, "yeeloong laptop\n");
> +}
> +
> +static struct device_attribute dev_attr_yeeloong_pdev_name =
> +__ATTR(name, S_IRUGO, yeeloong_pdev_name_show, NULL);
> +
> +static int __init yeeloong_suspend_init(void)
> +{
> +	int ret;
> +
> +	if (mips_machtype != MACH_LEMOTE_YL2F89) {
> +		pr_err("This Driver is only for YeeLoong laptop\n");
> +		return -EFAULT;
> +	}

No need to signal an error here.  A platform device should only be
registered on a platform that actually has the device.  If you handle
all that registration business in a central platform.c file which
always is compiled into the YeeLoong kernel, this check can go away and
you at the same time assure the actual driver module can only be loaded
into the right kernel.

> +
> +	/* Register platform stuff */
> +	ret = platform_driver_register(&platform_driver);
> +	if (ret)
> +		return ret;
> +
> +	yeeloong_pdev = platform_device_alloc("yeeloong-laptop", -1);
> +	if (!yeeloong_pdev) {
> +		ret = -ENOMEM;
> +		platform_driver_unregister(&platform_driver);
> +		return ret;
> +	}
> +
> +	ret = platform_device_add(yeeloong_pdev);
> +	if (ret) {
> +		platform_device_put(yeeloong_pdev);
> +		return ret;
> +	}
> +
> +	if (IS_ERR(yeeloong_pdev)) {
> +		ret = PTR_ERR(yeeloong_pdev);
> +		yeeloong_pdev = NULL;
> +		pr_err("Fail to register platform device\n");
> +		return ret;
> +	}
> +
> +	ret = device_create_file(&yeeloong_pdev->dev,
> +				 &dev_attr_yeeloong_pdev_name);
> +	if (ret) {
> +		pr_err("Fail to create sysfs device attributes\n");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static void __exit yeeloong_suspend_exit(void)
> +{
> +	if (yeeloong_pdev) {
> +		platform_device_unregister(yeeloong_pdev);
> +		yeeloong_pdev = NULL;
> +		platform_driver_unregister(&platform_driver);
> +	}
> +}
> +
> +module_init(yeeloong_suspend_init);
> +module_exit(yeeloong_suspend_exit);
> -- 
> 1.6.2.1

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver
  2009-12-01 14:06     ` Ralf Baechle
@ 2009-12-01 14:52       ` Wu Zhangjin
  2009-12-01 14:57         ` Ralf Baechle
  0 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangjin @ 2009-12-01 14:52 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, Richard Purdie

On Tue, 2009-12-01 at 14:06 +0000, Ralf Baechle wrote:
> On Tue, Dec 01, 2009 at 07:08:42PM +0800, Wu Zhangin wrote:
> 
> > From: Wu Zhangjin <wuzhangjin@gmail.com>
> > 
> > This patch adds YeeLoong Backlight Driver, which provides standard
> > interface for user-space applications to control the brightness of the
> > backlight.
> > 
> > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> You split old, big driver into several individual drivers - good.
> 
> Now we can actually move things to their rightf place and for a backlight
> drivers that should be drivers/video/backlight/.  Convert it to a platform
> driver.

Okay, but for these drivers need the ec_kb3310b.h, so, we also need to
move it from arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
to arch/mips/include/asm/mach-loongson/ec_kb3310b.h.

and seems some subsystem have no maintainer, such as the hwmon driver:

HARDWARE MONITORING
L:      lm-sensors@lm-sensors.org
W:      http://www.lm-sensors.org/
S:      Orphan
F:      drivers/hwmon/

So, who should I send this patch to?

Best Regards,
	Wu Zhangjin

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 6/8] Loongson: YeeLoong: add video output driver
  2009-12-01 11:10   ` [PATCH v6 6/8] Loongson: YeeLoong: add video output driver Wu Zhangin
@ 2009-12-01 14:55     ` Ralf Baechle
  0 siblings, 0 replies; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 14:55 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: linux-mips, zhangfx, luming.yu

On Tue, Dec 01, 2009 at 07:10:38PM +0800, Wu Zhangin wrote:

> From: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> This patch adds Video Output Driver, which provides standard interface
> to turn on/off the video output of LCD, CRT.

This one also should become a platform driver.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver
  2009-12-01 14:52       ` Wu Zhangjin
@ 2009-12-01 14:57         ` Ralf Baechle
  2009-12-01 15:01           ` Wu Zhangjin
  0 siblings, 1 reply; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 14:57 UTC (permalink / raw)
  To: Wu Zhangjin; +Cc: linux-mips, zhangfx, Richard Purdie

On Tue, Dec 01, 2009 at 10:52:17PM +0800, Wu Zhangjin wrote:

> On Tue, 2009-12-01 at 14:06 +0000, Ralf Baechle wrote:
> > On Tue, Dec 01, 2009 at 07:08:42PM +0800, Wu Zhangin wrote:
> > 
> > > From: Wu Zhangjin <wuzhangjin@gmail.com>
> > > 
> > > This patch adds YeeLoong Backlight Driver, which provides standard
> > > interface for user-space applications to control the brightness of the
> > > backlight.
> > > 
> > > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> > 
> > You split old, big driver into several individual drivers - good.
> > 
> > Now we can actually move things to their rightf place and for a backlight
> > drivers that should be drivers/video/backlight/.  Convert it to a platform
> > driver.
> 
> Okay, but for these drivers need the ec_kb3310b.h, so, we also need to
> move it from arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
> to arch/mips/include/asm/mach-loongson/ec_kb3310b.h.
> 
> and seems some subsystem have no maintainer, such as the hwmon driver:

Which is true and sometimes a bit of a nuisance but one we can live with.

> HARDWARE MONITORING
> L:      lm-sensors@lm-sensors.org
> W:      http://www.lm-sensors.org/
> S:      Orphan
> F:      drivers/hwmon/
> 
> So, who should I send this patch to?

I suggest you add Andrew Morton <akpm@linux-foundation.org> and linux-kernel
to the To: list.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver
  2009-12-01 14:57         ` Ralf Baechle
@ 2009-12-01 15:01           ` Wu Zhangjin
  2009-12-01 15:23             ` Ralf Baechle
  0 siblings, 1 reply; 30+ messages in thread
From: Wu Zhangjin @ 2009-12-01 15:01 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, zhangfx, Richard Purdie

On Tue, 2009-12-01 at 14:57 +0000, Ralf Baechle wrote:
> On Tue, Dec 01, 2009 at 10:52:17PM +0800, Wu Zhangjin wrote:
> 
> > On Tue, 2009-12-01 at 14:06 +0000, Ralf Baechle wrote:
> > > On Tue, Dec 01, 2009 at 07:08:42PM +0800, Wu Zhangin wrote:
> > > 
> > > > From: Wu Zhangjin <wuzhangjin@gmail.com>
> > > > 
> > > > This patch adds YeeLoong Backlight Driver, which provides standard
> > > > interface for user-space applications to control the brightness of the
> > > > backlight.
> > > > 
> > > > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> > > 
> > > You split old, big driver into several individual drivers - good.
> > > 
> > > Now we can actually move things to their rightf place and for a backlight
> > > drivers that should be drivers/video/backlight/.  Convert it to a platform
> > > driver.
> > 
> > Okay, but for these drivers need the ec_kb3310b.h, so, we also need to
> > move it from arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
> > to arch/mips/include/asm/mach-loongson/ec_kb3310b.h.
> > 
> > and seems some subsystem have no maintainer, such as the hwmon driver:
> 
> Which is true and sometimes a bit of a nuisance but one we can live with.
> 

This time, I like the folks did under drivers/platform/x86/ ;) which
will be better to maintain. for all of these drivers are really only
YeeLoong platform specific ;)

> > HARDWARE MONITORING
> > L:      lm-sensors@lm-sensors.org
> > W:      http://www.lm-sensors.org/
> > S:      Orphan
> > F:      drivers/hwmon/
> > 
> > So, who should I send this patch to?
> 
> I suggest you add Andrew Morton <akpm@linux-foundation.org> and linux-kernel
> to the To: list.
> 

Okay, later, thanks!

Regards,
	Wu Zhangjin

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver
  2009-12-01 12:24     ` Rafael J. Wysocki
@ 2009-12-01 15:18       ` Ralf Baechle
  0 siblings, 0 replies; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 15:18 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Wu Zhangin, linux-mips, zhangfx, Pavel Machek, linux-pm

On Tue, Dec 01, 2009 at 01:24:29PM +0100, Rafael J. Wysocki wrote:

> On Tuesday 01 December 2009, Wu Zhangin wrote:
> > From: Wu Zhangjin <wuzhangjin@gmail.com>
> > 
> > This patch adds Suspend Driver, which will suspend the YeeLoong Platform
> > specific devices.
> > 
> > Acked-by: Pavel Machek <pavel@ucw.cz>
> > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> I'm still not sure how useful it is to build it as a module, but otherwise

I think I agree with that.  Maybe even one step further and just build
this code depending on CONFIG_PM or similar?

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver
  2009-12-01 15:01           ` Wu Zhangjin
@ 2009-12-01 15:23             ` Ralf Baechle
       [not found]               ` <1259681303.13403.4.camel@falcon.domain.org>
  0 siblings, 1 reply; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 15:23 UTC (permalink / raw)
  To: Wu Zhangjin; +Cc: linux-mips, zhangfx, Richard Purdie

On Tue, Dec 01, 2009 at 11:01:33PM +0800, Wu Zhangjin wrote:

> This time, I like the folks did under drivers/platform/x86/ ;) which
> will be better to maintain. for all of these drivers are really only
> YeeLoong platform specific ;)

Experience has shown that drivers for a particular subsystem are best
combined in a single menu, in a single directory.  Otherwise any changes
to subsystem's internal APIs will become a major pain.  Which in the
end means arch/ is usually the place for drivers that don't fit into
any established cathegory.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 8/8] Loongson: YeeLoong: add hotkey driver
  2009-12-01 11:12   ` [PATCH v6 8/8] Loongson: YeeLoong: add hotkey driver Wu Zhangin
@ 2009-12-01 15:40     ` Ralf Baechle
  2009-12-01 18:03       ` Dmitry Torokhov
  0 siblings, 1 reply; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 15:40 UTC (permalink / raw)
  To: Wu Zhangin; +Cc: linux-mips, zhangfx, Dmitry Torokhov

On Tue, Dec 01, 2009 at 07:12:37PM +0800, Wu Zhangin wrote:

> From: Wu Zhangjin <wuzhangjin@gmail.com>
> 
> This patch adds Hotkey Driver, which will do relative actions for The
> hotkey event and report the corresponding input keys to the user-space
> applications.

This one also should become a platform driver.  And is probably a
candidate for drivers/input/keyboard.

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver
       [not found]               ` <1259681303.13403.4.camel@falcon.domain.org>
@ 2009-12-01 15:41                 ` Ralf Baechle
  0 siblings, 0 replies; 30+ messages in thread
From: Ralf Baechle @ 2009-12-01 15:41 UTC (permalink / raw)
  To: Wu Zhangjin; +Cc: linux-mips, zhangfx, Richard Purdie

On Tue, Dec 01, 2009 at 11:28:23PM +0800, Wu Zhangjin wrote:

> > any established cathegory.
> 
> Get it, thanks ;)
> 
> I will do it tomorrow, Good night!

I thought you never sleep :-)

  Ralf

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 8/8] Loongson: YeeLoong: add hotkey driver
  2009-12-01 15:40     ` Ralf Baechle
@ 2009-12-01 18:03       ` Dmitry Torokhov
  2009-12-02  9:43         ` Wu Zhangjin
  0 siblings, 1 reply; 30+ messages in thread
From: Dmitry Torokhov @ 2009-12-01 18:03 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Wu Zhangin, linux-mips, zhangfx

On Tue, Dec 01, 2009 at 03:40:50PM +0000, Ralf Baechle wrote:
> On Tue, Dec 01, 2009 at 07:12:37PM +0800, Wu Zhangin wrote:
> 
> > From: Wu Zhangjin <wuzhangjin@gmail.com>
> > 
> > This patch adds Hotkey Driver, which will do relative actions for The
> > hotkey event and report the corresponding input keys to the user-space
> > applications.
> 
> This one also should become a platform driver.  And is probably a
> candidate for drivers/input/keyboard.
> 

Umm, it still mixes up bunch of stuff not directly related to input. I'd
vote for drivers/platform/mips (since we have a few of kitchen-sink
style drivers for x86-based laptops in drivers/platform/x86).

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 8/8] Loongson: YeeLoong: add hotkey driver
  2009-12-01 18:03       ` Dmitry Torokhov
@ 2009-12-02  9:43         ` Wu Zhangjin
  0 siblings, 0 replies; 30+ messages in thread
From: Wu Zhangjin @ 2009-12-02  9:43 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Ralf Baechle, linux-mips, zhangfx

On Tue, 2009-12-01 at 10:03 -0800, Dmitry Torokhov wrote: 
> On Tue, Dec 01, 2009 at 03:40:50PM +0000, Ralf Baechle wrote:
> > On Tue, Dec 01, 2009 at 07:12:37PM +0800, Wu Zhangin wrote:
> > 
> > > From: Wu Zhangjin <wuzhangjin@gmail.com>
> > > 
> > > This patch adds Hotkey Driver, which will do relative actions for The
> > > hotkey event and report the corresponding input keys to the user-space
> > > applications.
> > 
> > This one also should become a platform driver.  And is probably a
> > candidate for drivers/input/keyboard.
> > 
> 
> Umm, it still mixes up bunch of stuff not directly related to input. I'd
> vote for drivers/platform/mips (since we have a few of kitchen-sink
> style drivers for x86-based laptops in drivers/platform/x86).
> 

Hello,

Do you mean we go back to drivers/platform/mips/yeeloong_laptop.c? (or
split the input stuff into yeeloong_input.c)

For considering the next platform support of LynLoong PC and the future
other MIPS netbooks/PC(e.g. gdium), perhaps drivers/platform/mips is
really the good place to put them in. and benefit from it, we maybe
easier to share the functions, variables. of course, the problem about
the API modification will also be there:

"Experience has shown that drivers for a particular subsystem are best
combined in a single menu, in a single directory.  Otherwise any changes
to subsystem's internal APIs will become a major pain.  Which in the end
means arch/ is usually the place for drivers that don't fit into any
established cathegory." -- Ralf

Best Regards,
	Wu Zhangjin

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2009-12-02 10:54 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-01 11:06 [PATCH v6 0/8] Loongson: YeeLoong: add platform specific drivers Wu Zhangin
     [not found] ` <cover.1259664573.git.wuzhangjin@gmail.com>
2009-12-01 11:07   ` [PATCH v6 1/8] Loongson: Lemote-2F: add platform specific submenu Wu Zhangin
2009-12-01 13:32     ` Ralf Baechle
2009-12-01 13:35       ` Wu Zhangjin
2009-12-01 11:07   ` [PATCH v6 2/8] Loongson: YeeLoong: add platform specific option Wu Zhangin
2009-12-01 13:34     ` Ralf Baechle
2009-12-01 13:39       ` Wu Zhangjin
2009-12-01 14:17         ` Ralf Baechle
2009-12-01 11:08   ` [PATCH v6 3/8] Loongson: YeeLoong: add backlight driver Wu Zhangin
2009-12-01 14:06     ` Ralf Baechle
2009-12-01 14:52       ` Wu Zhangjin
2009-12-01 14:57         ` Ralf Baechle
2009-12-01 15:01           ` Wu Zhangjin
2009-12-01 15:23             ` Ralf Baechle
     [not found]               ` <1259681303.13403.4.camel@falcon.domain.org>
2009-12-01 15:41                 ` Ralf Baechle
2009-12-01 11:09   ` [PATCH v6 4/8] Loongson: YeeLoong: add battery driver Wu Zhangin
2009-12-01 14:20     ` Ralf Baechle
2009-12-01 11:09   ` [PATCH v6 5/8] Loongson: YeeLoong: add hwmon driver Wu Zhangin
2009-12-01 14:27     ` Ralf Baechle
2009-12-01 11:10   ` [PATCH v6 6/8] Loongson: YeeLoong: add video output driver Wu Zhangin
2009-12-01 14:55     ` Ralf Baechle
2009-12-01 11:11   ` [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver Wu Zhangin
2009-12-01 12:24     ` Rafael J. Wysocki
2009-12-01 15:18       ` Ralf Baechle
2009-12-01 14:51     ` Ralf Baechle
2009-12-01 11:12   ` [PATCH v6 8/8] Loongson: YeeLoong: add hotkey driver Wu Zhangin
2009-12-01 15:40     ` Ralf Baechle
2009-12-01 18:03       ` Dmitry Torokhov
2009-12-02  9:43         ` Wu Zhangjin
2009-12-01 11:16 ` [PATCH v6 0/8] Loongson: YeeLoong: add platform specific drivers Wu Zhangjin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).