Skip to contentSkip to conversation

input: pcspkr device and driver separation

PATCH In review Michael Neuling 2 participants 3 messages Feb 21, 2006 – Feb 28, 2006 7 messages not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

PATCH 1/1 input: pcspkr device and driver separation

The current pcspkr code combines the device and driver registration. This patch splits these, putting the device registration in the arch specific code.

It seems opinion is divided as how much error checking needs to be done when registering the device at boot. This patch does a BUG_ON on any device allocation failures for all architectures touched. The PowerPC guys are happy with this.

Mikey

Split the pcskpr device and driver registration. Adds device registration for Alpha, MIPS and x86. Also added for PowerPC which is dependant on the pcspkr existing in the device-tree.

---
 arch/alpha/kernel/setup.c          |   12 ++++++++++++
 arch/i386/kernel/setup.c           |   12 ++++++++++++
 arch/mips/kernel/setup.c           |   12 ++++++++++++
 arch/powerpc/kernel/setup-common.c |   18 ++++++++++++++++++
 drivers/input/misc/pcspkr.c        |   27 +--------------------------
 5 files changed, 55 insertions(+), 26 deletions(-)
arch/i386/kernel/setup.c +12 -0
Index: linux-2.6-linus/arch/i386/kernel/setup.c
===================================================================
@@ -1630,6 +1630,18 @@ void __init setup_arch(char **cmdline_p)
 #endif
 }
 
+static __init int add_pcspkr(void)
+{
+	struct platform_device *pd;
+
+	pd = platform_device_alloc("pcspkr", -1);
+	BUG_ON(!pd);
+	BUG_ON(platform_device_add(pd));
+
+	return 0;
+}
+device_initcall(add_pcspkr);
+
 #include "setup_arch_post.h"
 /*
  * Local Variables:
arch/powerpc/kernel/setup-common.c +18 -0
Index: linux-2.6-linus/arch/powerpc/kernel/setup-common.c
===================================================================
@@ -469,3 +469,21 @@ static int __init early_xmon(char *p)
 }
 early_param("xmon", early_xmon);
 #endif
+
+static __init int add_pcspkr(void)
+{
+	struct device_node *np;
+	struct platform_device *pd;
+
+	np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
+	of_node_put(np);
+	if (!np)
+		return -ENODEV;
+
+	pd = platform_device_alloc("pcspkr", -1);
+	BUG_ON(!pd);
+	BUG_ON(platform_device_add(pd));
+
+	return 0;
+}
+device_initcall(add_pcspkr);
drivers/input/misc/pcspkr.c +1 -26
Index: linux-2.6-linus/drivers/input/misc/pcspkr.c
===================================================================
@@ -24,7 +24,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@u
 MODULE_DESCRIPTION("PC Speaker beeper driver");
 MODULE_LICENSE("GPL");
 
-static struct platform_device *pcspkr_platform_device;
 static DEFINE_SPINLOCK(i8253_beep_lock);
 
 static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
@@ -135,35 +134,11 @@ static struct platform_driver pcspkr_pla
 
 static int __init pcspkr_init(void)
 {
-	int err;
-
-	err = platform_driver_register(&pcspkr_platform_driver);
-	if (err)
-		return err;
-
-	pcspkr_platform_device = platform_device_alloc("pcspkr", -1);
-	if (!pcspkr_platform_device) {
-		err = -ENOMEM;
-		goto err_unregister_driver;
-	}
-
-	err = platform_device_add(pcspkr_platform_device);
-	if (err)
-		goto err_free_device;
-
-	return 0;
-
- err_free_device:
-	platform_device_put(pcspkr_platform_device);
- err_unregister_driver:
-	platform_driver_unregister(&pcspkr_platform_driver);
-
-	return err;
+	return platform_driver_register(&pcspkr_platform_driver);
 }
 
 static void __exit pcspkr_exit(void)
 {
-	platform_device_unregister(pcspkr_platform_device);
 	platform_driver_unregister(&pcspkr_platform_driver);
 }
 
arch/mips/kernel/setup.c +12 -0
Index: linux-2.6-linus/arch/mips/kernel/setup.c
===================================================================
@@ -559,3 +559,15 @@ int __init dsp_disable(char *s)
 }
 
 __setup("nodsp", dsp_disable);
+
+static __init int add_pcspkr(void)
+{
+	struct platform_device *pd;
+
+	pd = platform_device_alloc("pcspkr", -1);
+	BUG_ON(!pd);
+	BUG_ON(platform_device_add(pd));
+
+	return 0;
+}
+device_initcall(add_pcspkr);
arch/alpha/kernel/setup.c +12 -0
Index: linux-2.6-linus/arch/alpha/kernel/setup.c
===================================================================
@@ -1484,3 +1484,15 @@ alpha_panic_event(struct notifier_block 
 #endif
         return NOTIFY_DONE;
 }
+
+static __init int add_pcspkr(void)
+{
+	struct platform_device *pd;
+
+	pd = platform_device_alloc("pcspkr", -1);
+	BUGON(!pd);
+	BUGON(platform_device_add(pd));
+
+	return 0;
+}
+device_initcall(add_pcspkr);
#8 lore raw
Quoted 9 lines · Michael Neuling

The current pcspkr code combines the device and driver registration. This patch splits these, putting the device registration in the arch specific code.

It seems opinion is divided as how much error checking needs to be done when registering the device at boot. This patch does a BUG_ON on any device allocation failures for all architectures touched. The PowerPC guys are happy with this.

Argh! I mean to write this reply earlier...

As I said I like the patch overall, however I do not agree that BUG_ON is appropriate here. Whatever issues with speaker device there is they do not warrant OOPS at boot time. Speaker is not critical device so just clean up after failure an move on. If you compare code cleaning up with code using BUG_ON they are about the same in the end.

Signature · 1 line
Dmitry
#9 lore raw

PATCH 1/1 input: pcspkr device and driver separation

In reply to a message not in the archive

Retransmission with updates from Ralf on MIPS.

The current pcspkr code combines the device and driver registration. This patch splits these, putting the device registration in the arch specific code.

It seems opinion is divided as how much error checking needs to be done when registering the device at boot. This patch does a BUG_ON on any device allocation failures for all architectures touched. The PowerPC guys are happy with this.

PowerPC and MIPS only have the pcspkr present sometimes.

---
 arch/alpha/kernel/setup.c          |   12 ++++++++++++
 arch/i386/kernel/setup.c           |   12 ++++++++++++
 arch/mips/Kconfig                  |    6 ++++++
 arch/mips/kernel/Makefile          |    2 ++
 arch/mips/kernel/i8253.c           |   23 +++++++++++++++++++++++
 arch/powerpc/kernel/setup-common.c |   18 ++++++++++++++++++
 drivers/input/misc/pcspkr.c        |   27 +--------------------------
 7 files changed, 74 insertions(+), 26 deletions(-)
arch/alpha/kernel/setup.c +12 -0
Index: linux-2.6-linus/arch/alpha/kernel/setup.c
===================================================================
@@ -1484,3 +1484,15 @@ alpha_panic_event(struct notifier_block 
 #endif
         return NOTIFY_DONE;
 }
+
+static __init int add_pcspkr(void)
+{
+	struct platform_device *pd;
+
+	pd = platform_device_alloc("pcspkr", -1);
+	BUGON(!pd);
+	BUGON(platform_device_add(pd));
+
+	return 0;
+}
+device_initcall(add_pcspkr);
arch/i386/kernel/setup.c +12 -0
Index: linux-2.6-linus/arch/i386/kernel/setup.c
===================================================================
@@ -1630,6 +1630,18 @@ void __init setup_arch(char **cmdline_p)
 #endif
 }
 
+static __init int add_pcspkr(void)
+{
+	struct platform_device *pd;
+
+	pd = platform_device_alloc("pcspkr", -1);
+	BUG_ON(!pd);
+	BUG_ON(platform_device_add(pd));
+
+	return 0;
+}
+device_initcall(add_pcspkr);
+
 #include "setup_arch_post.h"
 /*
  * Local Variables:
arch/mips/Kconfig +6 -0
Index: linux-2.6-linus/arch/mips/Kconfig
===================================================================
@@ -233,6 +233,7 @@ config MACH_JAZZ
 	select ARC32
 	select ARCH_MAY_HAVE_PC_FDC
 	select GENERIC_ISA_DMA
+	select I8253
 	select I8259
 	select ISA
 	select SYS_HAS_CPU_R4X00
@@ -530,6 +531,7 @@ config QEMU
 	select DMA_COHERENT
 	select GENERIC_ISA_DMA
 	select HAVE_STD_PC_SERIAL_PORT
+	select I8253
 	select I8259
 	select ISA
 	select SWAP_IO_SPACE
@@ -714,6 +716,7 @@ config SNI_RM200_PCI
 	select HAVE_STD_PC_SERIAL_PORT
 	select HW_HAS_EISA
 	select HW_HAS_PCI
+	select I8253
 	select I8259
 	select ISA
 	select SYS_HAS_CPU_R4X00
@@ -1707,6 +1710,9 @@ config MMU
 	bool
 	default y
 
+config I8253
+	bool
+
 source "drivers/pcmcia/Kconfig"
 
 source "drivers/pci/hotplug/Kconfig"
arch/mips/kernel/Makefile +2 -0
Index: linux-2.6-linus/arch/mips/kernel/Makefile
===================================================================
@@ -59,6 +59,8 @@ obj-$(CONFIG_PROC_FS)		+= proc.o
 
 obj-$(CONFIG_64BIT)		+= cpu-bugs64.o
 
+obj-$(CONFIG_I8253)		+= i8253.o
+
 CFLAGS_cpu-bugs64.o	= $(shell if $(CC) $(CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi)
 
 EXTRA_AFLAGS := $(CFLAGS)
arch/mips/kernel/i8253.c new file +23 -0
Index: linux-2.6-linus/arch/mips/kernel/i8253.c
===================================================================
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2006 IBM Corporation
+ *
+ * Implements device information for i8253 timer chip
+ *
+ * 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/platform_device.h>
+
+static __init int add_pcspkr(void)
+{
+	struct platform_device *pd;
+
+	pd = platform_device_alloc("pcspkr", -1);
+	BUG_ON(!pd);
+	BUG_ON(platform_device_add(pd));
+
+	return 0;
+}
+device_initcall(add_pcspkr);
arch/powerpc/kernel/setup-common.c +18 -0
Index: linux-2.6-linus/arch/powerpc/kernel/setup-common.c
===================================================================
@@ -469,3 +469,21 @@ static int __init early_xmon(char *p)
 }
 early_param("xmon", early_xmon);
 #endif
+
+static __init int add_pcspkr(void)
+{
+	struct device_node *np;
+	struct platform_device *pd;
+
+	np = of_find_compatible_node(NULL, NULL, "pnpPNP,100");
+	of_node_put(np);
+	if (!np)
+		return -ENODEV;
+
+	pd = platform_device_alloc("pcspkr", -1);
+	BUG_ON(!pd);
+	BUG_ON(platform_device_add(pd));
+
+	return 0;
+}
+device_initcall(add_pcspkr);
drivers/input/misc/pcspkr.c +1 -26
Index: linux-2.6-linus/drivers/input/misc/pcspkr.c
===================================================================
@@ -24,7 +24,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@u
 MODULE_DESCRIPTION("PC Speaker beeper driver");
 MODULE_LICENSE("GPL");
 
-static struct platform_device *pcspkr_platform_device;
 static DEFINE_SPINLOCK(i8253_beep_lock);
 
 static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
@@ -135,35 +134,11 @@ static struct platform_driver pcspkr_pla
 
 static int __init pcspkr_init(void)
 {
-	int err;
-
-	err = platform_driver_register(&pcspkr_platform_driver);
-	if (err)
-		return err;
-
-	pcspkr_platform_device = platform_device_alloc("pcspkr", -1);
-	if (!pcspkr_platform_device) {
-		err = -ENOMEM;
-		goto err_unregister_driver;
-	}
-
-	err = platform_device_add(pcspkr_platform_device);
-	if (err)
-		goto err_free_device;
-
-	return 0;
-
- err_free_device:
-	platform_device_put(pcspkr_platform_device);
- err_unregister_driver:
-	platform_driver_unregister(&pcspkr_platform_driver);
-
-	return err;
+	return platform_driver_register(&pcspkr_platform_driver);
 }
 
 static void __exit pcspkr_exit(void)
 {
-	platform_device_unregister(pcspkr_platform_device);
 	platform_driver_unregister(&pcspkr_platform_driver);
 }