public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: Alessandro Zummo <alessandro.zummo@towertech.it>,
	rtc-linux@googlegroups.com,
	Linux Kernel list <linux-kernel@vger.kernel.org>
Subject: [patch 2.6.20-rc3 2/3] create rtc-cmos platform device on x86_pc
Date: Fri, 5 Jan 2007 10:02:47 -0800	[thread overview]
Message-ID: <200701051002.48554.david-b@pacbell.net> (raw)

Update X86_PC platforms (i386, x86_64) to create an "rtc_cmos" platform device
when PNPACPI won't be creating a corresponding PNP node for us.  We know those
platforms always have such a "cmos RTC" device, it's in the hardware spec.

Note that this switches over to using the table based registration API that's
widely used on e.g. ARM.  There may be other platform devices that should get
added to these tables, to help get rid of some legacy ISA probing logic.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>

===
 i386/kernel/setup.c   |   60 +++++++++++++++++++++++++++++++++++----------
 x86_64/kernel/setup.c |   66 ++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 98 insertions(+), 28 deletions(-)

Random note:  x86_64 only creates pcspkr if it's configured,
while x86_32 creates it always.  Not changed by this patch,
but it'd make more sense that it always be conditional.

Index: g26/arch/x86_64/kernel/setup.c
===================================================================
--- g26.orig/arch/x86_64/kernel/setup.c	2006-12-07 23:00:17.000000000 -0800
+++ g26/arch/x86_64/kernel/setup.c	2006-12-08 00:56:39.000000000 -0800
@@ -1220,22 +1220,58 @@ struct seq_operations cpuinfo_op = {
 	.show =	show_cpuinfo,
 };
 
-#if defined(CONFIG_INPUT_PCSPKR) || defined(CONFIG_INPUT_PCSPKR_MODULE)
+
+#ifdef CONFIG_X86_PC
+
 #include <linux/platform_device.h>
-static __init int add_pcspkr(void)
-{
-	struct platform_device *pd;
-	int ret;
+#include <asm/mc146818rtc.h>
+
+#if defined(CONFIG_INPUT_PCSPKR) || defined(CONFIG_INPUT_PCSPKR_MODULE)
+static struct platform_device pcspkr_dev = {
+	.name		= "pcspkr",
+	.id		= -1,
+};
+#endif	/* PCSPKR */
 
-	pd = platform_device_alloc("pcspkr", -1);
-	if (!pd)
-		return -ENOMEM;
-
-	ret = platform_device_add(pd);
-	if (ret)
-		platform_device_put(pd);
+#ifndef	CONFIG_PNPACPI
+struct resource rtc_platform_resources[] = { {
+	.flags		= IORESOURCE_IO,
+	.start		= RTC_PORT(0),
+	.end		= RTC_PORT(1),
+}, {
+	.flags		= IORESOURCE_IRQ,
+	.start		= RTC_IRQ
+} };
 
-	return ret;
-}
-device_initcall(add_pcspkr);
+struct platform_device rtc_dev = {
+	.name		= "rtc_cmos",
+	.id		= -1,
+	.resource	= rtc_platform_resources,
+	.num_resources	= ARRAY_SIZE(rtc_platform_resources),
+};
+#endif	/* !PNPACPI */
+
+static struct platform_device *x86_pc_devs[] __initdata = {
+#if defined(CONFIG_INPUT_PCSPKR) || defined(CONFIG_INPUT_PCSPKR_MODULE)
+	&pcspkr_dev,
+#endif
+#ifndef	CONFIG_PNPACPI
+	&rtc_dev,
+#endif
+};
+
+static __init int add_devices(void)
+{
+#ifndef	CONFIG_PNPACPI
+	/* On most motherboards starting with ATX (1995+),
+	 * RTC alarms can wake the system
+	 */
+	device_init_wakeup(&rtc_dev.dev, 1);
 #endif
+
+	return platform_add_devices(x86_pc_devs, ARRAY_SIZE(x86_pc_devs));
+}
+arch_initcall(add_devices);
+
+#endif	/* X86_PC */
+
Index: g26/arch/i386/kernel/setup.c
===================================================================
--- g26.orig/arch/i386/kernel/setup.c	2006-12-07 23:00:12.000000000 -0800
+++ g26/arch/i386/kernel/setup.c	2006-12-08 00:56:39.000000000 -0800
@@ -652,22 +652,56 @@ void __init setup_arch(char **cmdline_p)
 	tsc_init();
 }
 
-static __init int add_pcspkr(void)
-{
-	struct platform_device *pd;
-	int ret;
 
-	pd = platform_device_alloc("pcspkr", -1);
-	if (!pd)
-		return -ENOMEM;
-
-	ret = platform_device_add(pd);
-	if (ret)
-		platform_device_put(pd);
+#ifdef CONFIG_X86_PC
+
+#include <linux/platform_device.h>
+#include <asm/mc146818rtc.h>
+
+static struct platform_device pcspkr_dev = {
+	.name		= "pcspkr",
+	.id		= -1,
+};
+
+#ifndef	CONFIG_PNPACPI
+struct resource rtc_platform_resources[] = { {
+	.flags		= IORESOURCE_IO,
+	.start		= RTC_PORT(0),
+	.end		= RTC_PORT(1),
+}, {
+	.flags		= IORESOURCE_IRQ,
+	.start		= RTC_IRQ
+} };
+
+struct platform_device rtc_dev = {
+	.name		= "rtc_cmos",
+	.id		= -1,
+	.resource	= rtc_platform_resources,
+	.num_resources	= ARRAY_SIZE(rtc_platform_resources),
+};
+#endif	/* !PNPACPI */
 
-	return ret;
+static struct platform_device *x86_pc_devs[] __initdata = {
+	&pcspkr_dev,
+#ifndef	CONFIG_PNPACPI
+	&rtc_dev,
+#endif
+};
+
+static __init int add_devices(void)
+{
+#ifndef	CONFIG_PNPACPI
+	/* On most motherboards starting with ATX (1995+),
+	 * RTC alarms can wake the system
+	 */
+	device_init_wakeup(&rtc_dev.dev, 1);
+#endif
+
+	return platform_add_devices(x86_pc_devs, ARRAY_SIZE(x86_pc_devs));
 }
-device_initcall(add_pcspkr);
+arch_initcall(add_devices);
+
+#endif	/* X86_PC */
 
 /*
  * Local Variables:

                 reply	other threads:[~2007-01-05 18:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=200701051002.48554.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=alessandro.zummo@towertech.it \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rtc-linux@googlegroups.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox