Skip to content

Commit 328f5cc

Browse files
committed
ARM: Use struct syscore_ops instead of sysdevs for PM in common code
Convert some ARM architecture's common code to using struct syscore_ops objects for power management instead of sysdev classes and sysdevs. This simplifies the code and reduces the kernel's memory footprint. It also is necessary for removing sysdevs from the kernel entirely in the future. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 5dd12af commit 328f5cc

5 files changed

Lines changed: 58 additions & 94 deletions

File tree

‎arch/arm/common/vic.c‎

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@
2222
#include <linux/init.h>
2323
#include <linux/list.h>
2424
#include <linux/io.h>
25-
#include <linux/sysdev.h>
25+
#include <linux/syscore_ops.h>
2626
#include <linux/device.h>
2727
#include <linux/amba/bus.h>
2828

2929
#include <asm/mach/irq.h>
3030
#include <asm/hardware/vic.h>
3131

32-
#if defined(CONFIG_PM)
32+
#ifdef CONFIG_PM
3333
/**
3434
* struct vic_device - VIC PM device
35-
* @sysdev: The system device which is registered.
3635
* @irq: The IRQ number for the base of the VIC.
3736
* @base: The register base for the VIC.
3837
* @resume_sources: A bitmask of interrupts for resume.
@@ -43,8 +42,6 @@
4342
* @protect: Save for VIC_PROTECT.
4443
*/
4544
struct vic_device {
46-
struct sys_device sysdev;
47-
4845
void __iomem *base;
4946
int irq;
5047
u32 resume_sources;
@@ -59,11 +56,6 @@ struct vic_device {
5956
static struct vic_device vic_devices[CONFIG_ARM_VIC_NR];
6057

6158
static int vic_id;
62-
63-
static inline struct vic_device *to_vic(struct sys_device *sys)
64-
{
65-
return container_of(sys, struct vic_device, sysdev);
66-
}
6759
#endif /* CONFIG_PM */
6860

6961
/**
@@ -85,10 +77,9 @@ static void vic_init2(void __iomem *base)
8577
writel(32, base + VIC_PL190_DEF_VECT_ADDR);
8678
}
8779

88-
#if defined(CONFIG_PM)
89-
static int vic_class_resume(struct sys_device *dev)
80+
#ifdef CONFIG_PM
81+
static void resume_one_vic(struct vic_device *vic)
9082
{
91-
struct vic_device *vic = to_vic(dev);
9283
void __iomem *base = vic->base;
9384

9485
printk(KERN_DEBUG "%s: resuming vic at %p\n", __func__, base);
@@ -107,13 +98,18 @@ static int vic_class_resume(struct sys_device *dev)
10798

10899
writel(vic->soft_int, base + VIC_INT_SOFT);
109100
writel(~vic->soft_int, base + VIC_INT_SOFT_CLEAR);
101+
}
110102

111-
return 0;
103+
static void vic_resume(void)
104+
{
105+
int id;
106+
107+
for (id = vic_id - 1; id >= 0; id--)
108+
resume_one_vic(vic_devices + id);
112109
}
113110

114-
static int vic_class_suspend(struct sys_device *dev, pm_message_t state)
111+
static void suspend_one_vic(struct vic_device *vic)
115112
{
116-
struct vic_device *vic = to_vic(dev);
117113
void __iomem *base = vic->base;
118114

119115
printk(KERN_DEBUG "%s: suspending vic at %p\n", __func__, base);
@@ -128,14 +124,21 @@ static int vic_class_suspend(struct sys_device *dev, pm_message_t state)
128124

129125
writel(vic->resume_irqs, base + VIC_INT_ENABLE);
130126
writel(~vic->resume_irqs, base + VIC_INT_ENABLE_CLEAR);
127+
}
128+
129+
static int vic_suspend(void)
130+
{
131+
int id;
132+
133+
for (id = 0; id < vic_id; id++)
134+
suspend_one_vic(vic_devices + id);
131135

132136
return 0;
133137
}
134138

135-
struct sysdev_class vic_class = {
136-
.name = "vic",
137-
.suspend = vic_class_suspend,
138-
.resume = vic_class_resume,
139+
struct syscore_ops vic_syscore_ops = {
140+
.suspend = vic_suspend,
141+
.resume = vic_resume,
139142
};
140143

141144
/**
@@ -147,30 +150,8 @@ struct sysdev_class vic_class = {
147150
*/
148151
static int __init vic_pm_init(void)
149152
{
150-
struct vic_device *dev = vic_devices;
151-
int err;
152-
int id;
153-
154-
if (vic_id == 0)
155-
return 0;
156-
157-
err = sysdev_class_register(&vic_class);
158-
if (err) {
159-
printk(KERN_ERR "%s: cannot register class\n", __func__);
160-
return err;
161-
}
162-
163-
for (id = 0; id < vic_id; id++, dev++) {
164-
dev->sysdev.id = id;
165-
dev->sysdev.cls = &vic_class;
166-
167-
err = sysdev_register(&dev->sysdev);
168-
if (err) {
169-
printk(KERN_ERR "%s: failed to register device\n",
170-
__func__);
171-
return err;
172-
}
173-
}
153+
if (vic_id > 0)
154+
register_syscore_ops(&vic_syscore_ops);
174155

175156
return 0;
176157
}

‎arch/arm/include/asm/mach/time.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
* timer interrupt which may be pending.
3535
*/
3636
struct sys_timer {
37-
struct sys_device dev;
3837
void (*init)(void);
3938
void (*suspend)(void);
4039
void (*resume)(void);

‎arch/arm/kernel/leds.c‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/module.h>
1111
#include <linux/init.h>
1212
#include <linux/sysdev.h>
13+
#include <linux/syscore_ops.h>
1314

1415
#include <asm/leds.h>
1516

@@ -69,36 +70,37 @@ static ssize_t leds_store(struct sys_device *dev,
6970

7071
static SYSDEV_ATTR(event, 0200, NULL, leds_store);
7172

72-
static int leds_suspend(struct sys_device *dev, pm_message_t state)
73+
static struct sysdev_class leds_sysclass = {
74+
.name = "leds",
75+
};
76+
77+
static struct sys_device leds_device = {
78+
.id = 0,
79+
.cls = &leds_sysclass,
80+
};
81+
82+
static int leds_suspend(void)
7383
{
7484
leds_event(led_stop);
7585
return 0;
7686
}
7787

78-
static int leds_resume(struct sys_device *dev)
88+
static void leds_resume(void)
7989
{
8090
leds_event(led_start);
81-
return 0;
8291
}
8392

84-
static int leds_shutdown(struct sys_device *dev)
93+
static void leds_shutdown(void)
8594
{
8695
leds_event(led_halted);
87-
return 0;
8896
}
8997

90-
static struct sysdev_class leds_sysclass = {
91-
.name = "leds",
98+
static struct syscore_ops leds_syscore_ops = {
9299
.shutdown = leds_shutdown,
93100
.suspend = leds_suspend,
94101
.resume = leds_resume,
95102
};
96103

97-
static struct sys_device leds_device = {
98-
.id = 0,
99-
.cls = &leds_sysclass,
100-
};
101-
102104
static int __init leds_init(void)
103105
{
104106
int ret;
@@ -107,6 +109,8 @@ static int __init leds_init(void)
107109
ret = sysdev_register(&leds_device);
108110
if (ret == 0)
109111
ret = sysdev_create_file(&leds_device, &attr_event);
112+
if (ret == 0)
113+
register_syscore_ops(&leds_syscore_ops);
110114
return ret;
111115
}
112116

‎arch/arm/kernel/time.c‎

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <linux/timex.h>
2222
#include <linux/errno.h>
2323
#include <linux/profile.h>
24-
#include <linux/sysdev.h>
24+
#include <linux/syscore_ops.h>
2525
#include <linux/timer.h>
2626
#include <linux/irq.h>
2727

@@ -115,48 +115,37 @@ void timer_tick(void)
115115
#endif
116116

117117
#if defined(CONFIG_PM) && !defined(CONFIG_GENERIC_CLOCKEVENTS)
118-
static int timer_suspend(struct sys_device *dev, pm_message_t state)
118+
static int timer_suspend(void)
119119
{
120-
struct sys_timer *timer = container_of(dev, struct sys_timer, dev);
121-
122-
if (timer->suspend != NULL)
123-
timer->suspend();
120+
if (system_timer->suspend)
121+
system_timer->suspend();
124122

125123
return 0;
126124
}
127125

128-
static int timer_resume(struct sys_device *dev)
126+
static void timer_resume(void)
129127
{
130-
struct sys_timer *timer = container_of(dev, struct sys_timer, dev);
131-
132-
if (timer->resume != NULL)
133-
timer->resume();
134-
135-
return 0;
128+
if (system_timer->resume)
129+
system_timer->resume();
136130
}
137131
#else
138132
#define timer_suspend NULL
139133
#define timer_resume NULL
140134
#endif
141135

142-
static struct sysdev_class timer_sysclass = {
143-
.name = "timer",
136+
static struct syscore_ops timer_syscore_ops = {
144137
.suspend = timer_suspend,
145138
.resume = timer_resume,
146139
};
147140

148-
static int __init timer_init_sysfs(void)
141+
static int __init timer_init_syscore_ops(void)
149142
{
150-
int ret = sysdev_class_register(&timer_sysclass);
151-
if (ret == 0) {
152-
system_timer->dev.cls = &timer_sysclass;
153-
ret = sysdev_register(&system_timer->dev);
154-
}
143+
register_syscore_ops(&timer_syscore_ops);
155144

156-
return ret;
145+
return 0;
157146
}
158147

159-
device_initcall(timer_init_sysfs);
148+
device_initcall(timer_init_syscore_ops);
160149

161150
void __init time_init(void)
162151
{

‎arch/arm/vfp/vfpmodule.c‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ static void vfp_enable(void *unused)
398398
}
399399

400400
#ifdef CONFIG_PM
401-
#include <linux/sysdev.h>
401+
#include <linux/syscore_ops.h>
402402

403-
static int vfp_pm_suspend(struct sys_device *dev, pm_message_t state)
403+
static int vfp_pm_suspend(void)
404404
{
405405
struct thread_info *ti = current_thread_info();
406406
u32 fpexc = fmrx(FPEXC);
@@ -420,34 +420,25 @@ static int vfp_pm_suspend(struct sys_device *dev, pm_message_t state)
420420
return 0;
421421
}
422422

423-
static int vfp_pm_resume(struct sys_device *dev)
423+
static void vfp_pm_resume(void)
424424
{
425425
/* ensure we have access to the vfp */
426426
vfp_enable(NULL);
427427

428428
/* and disable it to ensure the next usage restores the state */
429429
fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN);
430-
431-
return 0;
432430
}
433431

434-
static struct sysdev_class vfp_pm_sysclass = {
435-
.name = "vfp",
432+
static struct syscore_ops vfp_pm_syscore_ops = {
436433
.suspend = vfp_pm_suspend,
437434
.resume = vfp_pm_resume,
438435
};
439436

440-
static struct sys_device vfp_pm_sysdev = {
441-
.cls = &vfp_pm_sysclass,
442-
};
443-
444437
static void vfp_pm_init(void)
445438
{
446-
sysdev_class_register(&vfp_pm_sysclass);
447-
sysdev_register(&vfp_pm_sysdev);
439+
register_syscore_ops(&vfp_pm_syscore_ops);
448440
}
449441

450-
451442
#else
452443
static inline void vfp_pm_init(void) { }
453444
#endif /* CONFIG_PM */

0 commit comments

Comments
 (0)