All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ralf Baechle <ralf@linux-mips.org>
To: Wu Zhangin <wuzhangjin@gmail.com>
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
Subject: Re: [PATCH v6 7/8] Loongson: YeeLoong: add suspend driver
Date: Tue, 1 Dec 2009 14:51:38 +0000	[thread overview]
Message-ID: <20091201145138.GF14064@linux-mips.org> (raw)
In-Reply-To: <2574dde59f2e54ef9fa80423a7f02ed32eab7ab4.1259664573.git.wuzhangjin@gmail.com>

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

  parent reply	other threads:[~2009-12-01 14:51 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-01 11:06 [PATCH v6 0/8] Loongson: YeeLoong: add platform specific drivers Wu Zhangin
2009-12-01 11:09 ` [lm-sensors] [PATCH v6 0/8] Loongson: YeeLoong: add platform 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 11:09     ` [lm-sensors] " Wu Zhangin
2009-12-01 14:27     ` Ralf Baechle
2009-12-01 14:27       ` [lm-sensors] " 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 11:11   ` Wu Zhangin
2009-12-01 12:24     ` Rafael J. Wysocki
2009-12-01 15:18       ` Ralf Baechle
2009-12-01 15:18       ` Ralf Baechle
2009-12-01 12:24     ` Rafael J. Wysocki
2009-12-01 14:51     ` Ralf Baechle
2009-12-01 14:51     ` Ralf Baechle [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091201145138.GF14064@linux-mips.org \
    --to=ralf@linux-mips.org \
    --cc=linux-mips@linux-mips.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=pavel@ucw.cz \
    --cc=rjw@sisk.pl \
    --cc=wuzhangjin@gmail.com \
    --cc=zhangfx@lemote.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.