public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Russell King <rmk@arm.linux.org.uk>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	Kay Sievers <kay.sievers@vrfy.org>, Greg KH <greg@kroah.com>
Subject: Re: [PATCH] wake up from a serial port
Date: Wed, 12 Sep 2007 15:36:10 -0700	[thread overview]
Message-ID: <20070912153610.11c4f5cb.akpm@linux-foundation.org> (raw)
In-Reply-To: <Pine.LNX.4.60.0709122019100.5909@poirot.grange>

On Wed, 12 Sep 2007 20:50:10 +0200 (CEST)
Guennadi Liakhovetski <g.liakhovetski@gmx.de> wrote:

> Enable wakeup from serial ports, make it run-time configurable over sysfs, 
> e.g.,
> 
> echo enabled > /sys/devices/platform/serial8250.0/tty/ttyS0/power/wakeup
> 
> Requires
> 
> # CONFIG_SYSFS_DEPRECATED is not set
> 
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> 
> ---
> 
> Following suggestions from Alan and Russell moved the may_wake_up checks 
> to serial_core.c. This time actually tested - it does even work. Could 
> someone, please, verify, that put_device after device_find_child is 
> correct?

Seems right to me, from reading device_find_child() and its associated
documentation.

> Also would be nice to test with a Natsemi UART, that can wake up 
> the system, if such systems exist.
>

It would help if you could provide simple-to-follow steps which a tester
should follow to perform this testing.

 > 
> diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
> index 9c57486..8a3d6ea 100644
> --- a/drivers/serial/serial_core.c
> +++ b/drivers/serial/serial_core.c
> @@ -1934,9 +1934,24 @@ static void uart_change_pm(struct uart_state *state, int pm_state)
>  	}
>  }
>  
> +struct uart_match {
> +	struct uart_port *port;
> +	struct uart_driver *driver;
> +};
> +
> +static int serial_match_port(struct device *dev, void *data)
> +{
> +	struct uart_match *match = data;
> +	dev_t devt = MKDEV(match->driver->major, match->driver->minor) + match->port->line;
> +
> +	return dev->devt == devt; /* Actually, only one tty per port */
> +}
> +
>  int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
>  {
>  	struct uart_state *state = drv->state + port->line;
> +	struct device *tty_dev;
> +	struct uart_match match = {port, drv};
>  
>  	mutex_lock(&state->mutex);
>  
> @@ -1947,6 +1962,15 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
>  	}
>  #endif
>  
> +	tty_dev = device_find_child(port->dev, &match, serial_match_port);
> +	if (device_may_wakeup(tty_dev)) {
> +		enable_irq_wake(port->irq);
> +		put_device(tty_dev);
> +		mutex_unlock(&state->mutex);
> +		return 0;
> +	}
> +	port->suspended = 1;
> +
>  	if (state->info && state->info->flags & UIF_INITIALIZED) {
>  		const struct uart_ops *ops = port->ops;
>  
> @@ -1995,6 +2019,13 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
>  	}
>  #endif
>  
> +	if (!port->suspended) {
> +		disable_irq_wake(port->irq);
> +		mutex_unlock(&state->mutex);
> +		return 0;
> +	}
> +	port->suspended = 0;
> +
>  	uart_change_pm(state, 0);
>  
>  	/*
> @@ -2266,6 +2297,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *port)
>  {
>  	struct uart_state *state;
>  	int ret = 0;
> +	struct device *tty_dev;
>  
>  	BUG_ON(in_interrupt());
>  
> @@ -2301,7 +2333,13 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *port)
>  	 * Register the port whether it's detected or not.  This allows
>  	 * setserial to be used to alter this ports parameters.
>  	 */
> -	tty_register_device(drv->tty_driver, port->line, port->dev);
> +	tty_dev = tty_register_device(drv->tty_driver, port->line, port->dev);
> +	if (likely(!IS_ERR(tty_dev))) {
> +		device_can_wakeup(tty_dev) = 1;
> +		device_set_wakeup_enable(tty_dev, 0);
> +	} else
> +		printk(KERN_ERR "Cannot register tty device on line %d\n",
> +		       port->line);
>  
>  	/*
>  	 * If this driver supports console, and it hasn't been
> diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
> index 773d8d8..60dedc0 100644
> --- a/include/linux/serial_core.h
> +++ b/include/linux/serial_core.h
> @@ -291,7 +291,8 @@ struct uart_port {
>  	unsigned long		mapbase;		/* for ioremap */
>  	struct device		*dev;			/* parent device */
>  	unsigned char		hub6;			/* this should be in the 8250 driver */
> -	unsigned char		unused[3];
> +	unsigned char		suspended;
> +	unsigned char		unused[2];
>  	void			*private_data;		/* generic platform data pointer */
>  };
>  

  parent reply	other threads:[~2007-09-12 22:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200709100831.l8A8VUH6015446@imap1.linux-foundation.org>
     [not found] ` <20070910132703.2dd92485@the-village.bc.nu>
     [not found]   ` <Pine.LNX.4.60.0709102251250.5200@poirot.grange>
     [not found]     ` <20070911081220.GA20847@flint.arm.linux.org.uk>
     [not found]       ` <Pine.LNX.4.60.0709111217470.19259@poirot.grange>
     [not found]         ` <20070911121057.34b9e066@the-village.bc.nu>
2007-09-12 18:50           ` [PATCH] wake up from a serial port Guennadi Liakhovetski
2007-09-12 21:06             ` Michael Mauch
2007-09-13 20:29               ` Guennadi Liakhovetski
2007-09-12 22:36             ` Andrew Morton [this message]
2007-09-13 23:21               ` [PATCH] " Greg KH
2007-09-14  8:34               ` Natsemi UART owner test request (was Re: [PATCH] wake up from a serial port) Guennadi Liakhovetski

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=20070912153610.11c4f5cb.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=g.liakhovetski@gmx.de \
    --cc=greg@kroah.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox