summaryrefslogtreecommitdiffstats
path: root/kernel/drivers/cpuidle/cpuidle-powernv.c
blob: 845bafcfa7929fd66cbb5eb966b16e0f3320de7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
 *  cpuidle-powernv - idle state cpuidle driver.
 *  Adapted from drivers/cpuidle/cpuidle-pseries
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/cpuidle.h>
#include <linux/cpu.h>
#include <linux/notifier.h>
#include <linux/clockchips.h>
#include <linux/of.h>
#include <linux/slab.h>

#include <asm/machdep.h>
#include <asm/firmware.h>
#include <asm/opal.h>
#include <asm/runlatch.h>

#define MAX_POWERNV_IDLE_STATES	8

struct cpuidle_driver powernv_idle_driver = {
	.name             = "powernv_idle",
	.owner            = THIS_MODULE,
};

static int max_idle_state;
static struct cpuidle_state *cpuidle_state_table;
static u64 snooze_timeout;
static bool snooze_timeout_en;

static int snooze_loop(struct cpuidle_device *dev,
			struct cpuidle_driver *drv,
			int index)
{
	u64 snooze_exit_time;

	local_irq_enable();
	set_thread_flag(TIF_POLLING_NRFLAG);

	snooze_exit_time = get_tb() + snooze_timeout;
	ppc64_runlatch_off();
	while (!need_resched()) {
		HMT_low();
		HMT_very_low();
		if (snooze_timeout_en && get_tb() > snooze_exit_time)
			break;
	}

	HMT_medium();
	ppc64_runlatch_on();
	clear_thread_flag(TIF_POLLING_NRFLAG);
	smp_mb();
	return index;
}

static int nap_loop(struct cpuidle_device *dev,
			struct cpuidle_driver *drv,
			int index)
{
	ppc64_runlatch_off();
	power7_idle();
	ppc64_runlatch_on();
	return index;
}

/* Register for fastsleep only in oneshot mode of broadcast */
#ifdef CONFIG_TICK_ONESHOT
static int fastsleep_loop(struct cpuidle_device *dev,
				struct cpuidle_driver *drv,
				int index)
{
	unsigned long old_lpcr = mfspr(SPRN_LPCR);
	unsigned long new_lpcr;

	if (unlikely(system_state < SYSTEM_RUNNING))
		return index;

	new_lpcr = old_lpcr;
	/* Do not exit powersave upon decrementer as we've setup the timer
	 * offload.
	 */
	new_lpcr &= ~LPCR_PECE1;

	mtspr(SPRN_LPCR, new_lpcr);
	power7_sleep();

	mtspr(SPRN_LPCR, old_lpcr);

	return index;
}
#endif
/*
 * States for dedicated partition case.
 */
static struct cpuidle_state powernv_states[MAX_POWERNV_IDLE_STATES] = {
	{ /* Snooze */
		.name = "snooze",
		.desc = "snooze",
		.exit_latency = 0,
		.target_residency = 0,
		.enter = &snooze_loop },
};

static int powernv_cpuidle_add_cpu_notifier(struct notifier_block *n,
			unsigned long action, void *hcpu)
{
	int hotcpu = (unsigned long)hcpu;
	struct cpuidle_device *dev =
				per_cpu(cpuidle_devices, hotcpu);

	if (dev && cpuidle_get_driver()) {
		switch (action) {
		case CPU_ONLINE:
		case CPU_ONLINE_FROZEN:
			cpuidle_pause_and_lock();
			cpuidle_enable_device(dev);
			cpuidle_resume_and_unlock();
			break;

		case CPU_DEAD:
		case CPU_DEAD_FROZEN:
			cpuidle_pause_and_lock();
			cpuidle_disable_device(dev);
			cpuidle_resume_and_unlock();
			break;

		default:
			return NOTIFY_DONE;
		}
	}
	return NOTIFY_OK;
}

static struct notifier_block setup_hotplug_notifier = {
	.notifier_call = powernv_cpuidle_add_cpu_notifier,
};

/*
 * powernv_cpuidle_driver_init()
 */
static int powernv_cpuidle_driver_init(void)
{
	int idle_state;
	struct cpuidle_driver *drv = &powernv_idle_driver;

	drv->state_count = 0;

	for (idle_state = 0; idle_state < max_idle_state; ++idle_state) {
		/* Is the state not enabled? */
		if (cpuidle_state_table[idle_state].enter == NULL)
			continue;

		drv->states[drv->state_count] =	/* structure copy */
			cpuidle_state_table[idle_state];

		drv->state_count += 1;
	}

	return 0;
}

static int powernv_add_idle_states(void)
{
	struct device_node *power_mgt;
	int nr_idle_states = 1; /* Snooze */
	int dt_idle_states;
	u32 *latency_ns, *residency_ns, *flags;
	int i, rc;

	/* Currently we have snooze statically defined */

	power_mgt = of_find_node_by_path("/ibm,opal/power-mgt");
	if (!power_mgt) {
		pr_warn("opal: PowerMgmt Node not found\n");
		goto out;
	}

	/* Read values of any property to determine the num of idle states */
	dt_idle_states = of_property_count_u32_elems(power_mgt, "ibm,cpu-idle-state-flags");
	if (dt_idle_states < 0) {
		pr_warn("cpuidle-powernv: no idle states found in the DT\n");
		goto out;
	}

	flags = kzalloc(sizeof(*flags) * dt_idle_states, GFP_KERNEL);
	if (of_property_read_u32_array(power_mgt,
			"ibm,cpu-idle-state-flags", flags, dt_idle_states)) {
		pr_warn("cpuidle-powernv : missing ibm,cpu-idle-state-flags in DT\n");
		goto out_free_flags;
	}

	latency_ns = kzalloc(sizeof(*latency_ns) * dt_idle_states, GFP_KERNEL);
	rc = of_property_read_u32_array(power_mgt,
		"ibm,cpu-idle-state-latencies-ns", latency_ns, dt_idle_states);
	if (rc) {
		pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-latencies-ns in DT\n");
		goto out_free_latency;
	}

	residency_ns = kzalloc(sizeof(*residency_ns) * dt_idle_states, GFP_KERNEL);
	rc = of_property_read_u32_array(power_mgt,
		"ibm,cpu-idle-state-residency-ns", residency_ns, dt_idle_states);

	for (i = 0; i < dt_idle_states; i++) {

		/*
		 * Cpuidle accepts exit_latency and target_residency in us.
		 * Use default target_residency values if f/w does not expose it.
		 */
		if (flags[i] & OPAL_PM_NAP_ENABLED) {
			/* Add NAP state */
			strcpy(powernv_states[nr_idle_states].name, "Nap");
			strcpy(powernv_states[nr_idle_states].desc, "Nap");
			powernv_states[nr_idle_states].flags = 0;
			powernv_states[nr_idle_states].target_residency = 100;
			powernv_states[nr_idle_states].enter = &nap_loop;
		}

		/*
		 * All cpuidle states with CPUIDLE_FLAG_TIMER_STOP set must come
		 * within this config dependency check.
		 */
#ifdef CONFIG_TICK_ONESHOT
		if (flags[i] & OPAL_PM_SLEEP_ENABLED ||
			flags[i] & OPAL_PM_SLEEP_ENABLED_ER1) {
			/* Add FASTSLEEP state */
			strcpy(powernv_states[nr_idle_states].name, "FastSleep");
			strcpy(powernv_states[nr_idle_states].desc, "FastSleep");
			powernv_states[nr_idle_states].flags = CPUIDLE_FLAG_TIMER_STOP;
			powernv_states[nr_idle_states].target_residency = 300000;
			powernv_states[nr_idle_states].enter = &fastsleep_loop;
		}
#endif
		powernv_states[nr_idle_states].exit_latency =
				((unsigned int)latency_ns[i]) / 1000;

		if (!rc) {
			powernv_states[nr_idle_states].target_residency =
				((unsigned int)residency_ns[i]) / 1000;
		}

		nr_idle_states++;
	}

	kfree(residency_ns);
out_free_latency:
	kfree(latency_ns);
out_free_flags:
	kfree(flags);
out:
	return nr_idle_states;
}

/*
 * powernv_idle_probe()
 * Choose state table for shared versus dedicated partition
 */
static int powernv_idle_probe(void)
{
	if (cpuidle_disable != IDLE_NO_OVERRIDE)
		return -ENODEV;

	if (firmware_has_feature(FW_FEATURE_OPALv3)) {
		cpuidle_state_table = powernv_states;
		/* Device tree can indicate more idle states */
		max_idle_state = powernv_add_idle_states();
		if (max_idle_state > 1) {
			snooze_timeout_en = true;
			snooze_timeout = powernv_states[1].target_residency *
					 tb_ticks_per_usec;
		}
 	} else
 		return -ENODEV;

	return 0;
}

static int __init powernv_processor_idle_init(void)
{
	int retval;

	retval = powernv_idle_probe();
	if (retval)
		return retval;

	powernv_cpuidle_driver_init();
	retval = cpuidle_register(&powernv_idle_driver, NULL);
	if (retval) {
		printk(KERN_DEBUG "Registration of powernv driver failed.\n");
		return retval;
	}

	register_cpu_notifier(&setup_hotplug_notifier);
	printk(KERN_DEBUG "powernv_idle_driver registered\n");
	return 0;
}

device_initcall(powernv_processor_idle_init);
pan class="kt">int bit); static inline int superio_enter(int base); static inline void superio_select(int base, int ld); static inline void superio_exit(int base); struct watchdog_data { unsigned short sioaddr; enum chips type; unsigned long opened; struct mutex lock; char expect_close; struct watchdog_info ident; unsigned short timeout; u8 timer_val; /* content for the wd_time register */ char minutes_mode; u8 pulse_val; /* pulse width flag */ char pulse_mode; /* enable pulse output mode? */ char caused_reboot; /* last reboot was by the watchdog */ }; static struct watchdog_data watchdog = { .lock = __MUTEX_INITIALIZER(watchdog.lock), }; /* Super I/O functions */ static inline int superio_inb(int base, int reg) { outb(reg, base); return inb(base + 1); } static int superio_inw(int base, int reg) { int val; val = superio_inb(base, reg) << 8; val |= superio_inb(base, reg + 1); return val; } static inline void superio_outb(int base, int reg, u8 val) { outb(reg, base); outb(val, base + 1); } static inline void superio_set_bit(int base, int reg, int bit) { unsigned long val = superio_inb(base, reg); __set_bit(bit, &val); superio_outb(base, reg, val); } static inline void superio_clear_bit(int base, int reg, int bit) { unsigned long val = superio_inb(base, reg); __clear_bit(bit, &val); superio_outb(base, reg, val); } static inline int superio_enter(int base) { /* Don't step on other drivers' I/O space by accident */ if (!request_muxed_region(base, 2, DRVNAME)) { pr_err("I/O address 0x%04x already in use\n", (int)base); return -EBUSY; } /* according to the datasheet the key must be sent twice! */ outb(SIO_UNLOCK_KEY, base); outb(SIO_UNLOCK_KEY, base); return 0; } static inline void superio_select(int base, int ld) { outb(SIO_REG_LDSEL, base); outb(ld, base + 1); } static inline void superio_exit(int base) { outb(SIO_LOCK_KEY, base); release_region(base, 2); } static int watchdog_set_timeout(int timeout) { if (timeout <= 0 || timeout > max_timeout) { pr_err("watchdog timeout out of range\n"); return -EINVAL; } mutex_lock(&watchdog.lock); watchdog.timeout = timeout; if (timeout > 0xff) { watchdog.timer_val = DIV_ROUND_UP(timeout, 60); watchdog.minutes_mode = true; } else { watchdog.timer_val = timeout; watchdog.minutes_mode = false; } mutex_unlock(&watchdog.lock); return 0; } static int watchdog_set_pulse_width(unsigned int pw) { int err = 0; mutex_lock(&watchdog.lock); if (pw <= 1) { watchdog.pulse_val = 0; } else if (pw <= 25) { watchdog.pulse_val = 1; } else if (pw <= 125) { watchdog.pulse_val = 2; } else if (pw <= 5000) { watchdog.pulse_val = 3; } else { pr_err("pulse width out of range\n"); err = -EINVAL; goto exit_unlock; } watchdog.pulse_mode = pw; exit_unlock: mutex_unlock(&watchdog.lock); return err; } static int watchdog_keepalive(void) { int err = 0; mutex_lock(&watchdog.lock); err = superio_enter(watchdog.sioaddr); if (err) goto exit_unlock; superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT); if (watchdog.minutes_mode) /* select minutes for timer units */ superio_set_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF, F71808FG_FLAG_WD_UNIT); else /* select seconds for timer units */ superio_clear_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF, F71808FG_FLAG_WD_UNIT); /* Set timer value */ superio_outb(watchdog.sioaddr, F71808FG_REG_WD_TIME, watchdog.timer_val); superio_exit(watchdog.sioaddr); exit_unlock: mutex_unlock(&watchdog.lock); return err; } static int f71862fg_pin_configure(unsigned short ioaddr) { /* When ioaddr is non-zero the calling function has to take care of mutex handling and superio preparation! */ if (f71862fg_pin == 63) { if (ioaddr) { /* SPI must be disabled first to use this pin! */ superio_clear_bit(ioaddr, SIO_REG_ROM_ADDR_SEL, 6); superio_set_bit(ioaddr, SIO_REG_MFUNCT3, 4); } } else if (f71862fg_pin == 56) { if (ioaddr) superio_set_bit(ioaddr, SIO_REG_MFUNCT1, 1); } else { pr_err("Invalid argument f71862fg_pin=%d\n", f71862fg_pin); return -EINVAL; } return 0; } static int watchdog_start(void) { /* Make sure we don't die as soon as the watchdog is enabled below */ int err = watchdog_keepalive(); if (err) return err; mutex_lock(&watchdog.lock); err = superio_enter(watchdog.sioaddr); if (err) goto exit_unlock; superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT); /* Watchdog pin configuration */ switch (watchdog.type) { case f71808fg: /* Set pin 21 to GPIO23/WDTRST#, then to WDTRST# */ superio_clear_bit(watchdog.sioaddr, SIO_REG_MFUNCT2, 3); superio_clear_bit(watchdog.sioaddr, SIO_REG_MFUNCT3, 3); break; case f71862fg: err = f71862fg_pin_configure(watchdog.sioaddr); if (err) goto exit_superio; break; case f71869: /* GPIO14 --> WDTRST# */ superio_clear_bit(watchdog.sioaddr, SIO_REG_MFUNCT1, 4); break; case f71882fg: /* Set pin 56 to WDTRST# */ superio_set_bit(watchdog.sioaddr, SIO_REG_MFUNCT1, 1); break; case f71889fg: /* set pin 40 to WDTRST# */ superio_outb(watchdog.sioaddr, SIO_REG_MFUNCT3, superio_inb(watchdog.sioaddr, SIO_REG_MFUNCT3) & 0xcf); break; default: /* * 'default' label to shut up the compiler and catch * programmer errors */ err = -ENODEV; goto exit_superio; } superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT); superio_set_bit(watchdog.sioaddr, SIO_REG_ENABLE, 0); superio_set_bit(watchdog.sioaddr, F71808FG_REG_WDO_CONF, F71808FG_FLAG_WDOUT_EN); superio_set_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF, F71808FG_FLAG_WD_EN); if (watchdog.pulse_mode) { /* Select "pulse" output mode with given duration */ u8 wdt_conf = superio_inb(watchdog.sioaddr, F71808FG_REG_WDT_CONF); /* Set WD_PSWIDTH bits (1:0) */ wdt_conf = (wdt_conf & 0xfc) | (watchdog.pulse_val & 0x03); /* Set WD_PULSE to "pulse" mode */ wdt_conf |= BIT(F71808FG_FLAG_WD_PULSE); superio_outb(watchdog.sioaddr, F71808FG_REG_WDT_CONF, wdt_conf); } else { /* Select "level" output mode */ superio_clear_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF, F71808FG_FLAG_WD_PULSE); } exit_superio: superio_exit(watchdog.sioaddr); exit_unlock: mutex_unlock(&watchdog.lock); return err; } static int watchdog_stop(void) { int err = 0; mutex_lock(&watchdog.lock); err = superio_enter(watchdog.sioaddr); if (err) goto exit_unlock; superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT); superio_clear_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF, F71808FG_FLAG_WD_EN); superio_exit(watchdog.sioaddr); exit_unlock: mutex_unlock(&watchdog.lock); return err; } static int watchdog_get_status(void) { int status = 0; mutex_lock(&watchdog.lock); status = (watchdog.caused_reboot) ? WDIOF_CARDRESET : 0; mutex_unlock(&watchdog.lock); return status; } static bool watchdog_is_running(void) { /* * if we fail to determine the watchdog's status assume it to be * running to be on the safe side */ bool is_running = true; mutex_lock(&watchdog.lock); if (superio_enter(watchdog.sioaddr)) goto exit_unlock; superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT); is_running = (superio_inb(watchdog.sioaddr, SIO_REG_ENABLE) & BIT(0)) && (superio_inb(watchdog.sioaddr, F71808FG_REG_WDT_CONF) & F71808FG_FLAG_WD_EN); superio_exit(watchdog.sioaddr); exit_unlock: mutex_unlock(&watchdog.lock); return is_running; } /* /dev/watchdog api */ static int watchdog_open(struct inode *inode, struct file *file) { int err; /* If the watchdog is alive we don't need to start it again */ if (test_and_set_bit(0, &watchdog.opened)) return -EBUSY; err = watchdog_start(); if (err) { clear_bit(0, &watchdog.opened); return err; } if (nowayout) __module_get(THIS_MODULE); watchdog.expect_close = 0; return nonseekable_open(inode, file); } static int watchdog_release(struct inode *inode, struct file *file) { clear_bit(0, &watchdog.opened); if (!watchdog.expect_close) { watchdog_keepalive(); pr_crit("Unexpected close, not stopping watchdog!\n"); } else if (!nowayout) { watchdog_stop(); } return 0; } /* * watchdog_write: * @file: file handle to the watchdog * @buf: buffer to write * @count: count of bytes * @ppos: pointer to the position to write. No seeks allowed * * A write to a watchdog device is defined as a keepalive signal. Any * write of data will do, as we we don't define content meaning. */ static ssize_t watchdog_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { if (count) { if (!nowayout) { size_t i; /* In case it was set long ago */ bool expect_close = false; for (i = 0; i != count; i++) { char c; if (get_user(c, buf + i)) return -EFAULT; expect_close = (c == 'V'); } /* Properly order writes across fork()ed processes */ mutex_lock(&watchdog.lock); watchdog.expect_close = expect_close; mutex_unlock(&watchdog.lock); } /* someone wrote to us, we should restart timer */ watchdog_keepalive(); } return count; } /* * watchdog_ioctl: * @inode: inode of the device * @file: file handle to the device * @cmd: watchdog command * @arg: argument pointer * * The watchdog API defines a common set of functions for all watchdogs * according to their available features. */ static long watchdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int status; int new_options; int new_timeout; union { struct watchdog_info __user *ident; int __user *i; } uarg; uarg.i = (int __user *)arg; switch (cmd) { case WDIOC_GETSUPPORT: return copy_to_user(uarg.ident, &watchdog.ident, sizeof(watchdog.ident)) ? -EFAULT : 0; case WDIOC_GETSTATUS: status = watchdog_get_status(); if (status < 0) return status; return put_user(status, uarg.i); case WDIOC_GETBOOTSTATUS: return put_user(0, uarg.i); case WDIOC_SETOPTIONS: if (get_user(new_options, uarg.i)) return -EFAULT; if (new_options & WDIOS_DISABLECARD) watchdog_stop(); if (new_options & WDIOS_ENABLECARD) return watchdog_start(); case WDIOC_KEEPALIVE: watchdog_keepalive(); return 0; case WDIOC_SETTIMEOUT: if (get_user(new_timeout, uarg.i)) return -EFAULT; if (watchdog_set_timeout(new_timeout)) return -EINVAL; watchdog_keepalive(); /* Fall */ case WDIOC_GETTIMEOUT: return put_user(watchdog.timeout, uarg.i); default: return -ENOTTY; } } static int watchdog_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { if (code == SYS_DOWN || code == SYS_HALT) watchdog_stop(); return NOTIFY_DONE; } static const struct file_operations watchdog_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .open = watchdog_open, .release = watchdog_release, .write = watchdog_write, .unlocked_ioctl = watchdog_ioctl, }; static struct miscdevice watchdog_miscdev = { .minor = WATCHDOG_MINOR, .name = "watchdog", .fops = &watchdog_fops, }; static struct notifier_block watchdog_notifier = { .notifier_call = watchdog_notify_sys, }; static int __init watchdog_init(int sioaddr) { int wdt_conf, err = 0; /* No need to lock watchdog.lock here because no entry points * into the module have been registered yet. */ watchdog.sioaddr = sioaddr; watchdog.ident.options = WDIOC_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING; snprintf(watchdog.ident.identity, sizeof(watchdog.ident.identity), "%s watchdog", f71808e_names[watchdog.type]); err = superio_enter(sioaddr); if (err) return err; superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT); wdt_conf = superio_inb(sioaddr, F71808FG_REG_WDT_CONF); watchdog.caused_reboot = wdt_conf & F71808FG_FLAG_WDTMOUT_STS; superio_exit(sioaddr); err = watchdog_set_timeout(timeout); if (err) return err; err = watchdog_set_pulse_width(pulse_width); if (err) return err; err = register_reboot_notifier(&watchdog_notifier); if (err) return err; err = misc_register(&watchdog_miscdev); if (err) { pr_err("cannot register miscdev on minor=%d\n", watchdog_miscdev.minor); goto exit_reboot; } if (start_withtimeout) { if (start_withtimeout <= 0 || start_withtimeout > max_timeout) { pr_err("starting timeout out of range\n"); err = -EINVAL; goto exit_miscdev; } err = watchdog_start(); if (err) { pr_err("cannot start watchdog timer\n"); goto exit_miscdev; } mutex_lock(&watchdog.lock); err = superio_enter(sioaddr); if (err) goto exit_unlock; superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT); if (start_withtimeout > 0xff) { /* select minutes for timer units */ superio_set_bit(sioaddr, F71808FG_REG_WDT_CONF, F71808FG_FLAG_WD_UNIT); superio_outb(sioaddr, F71808FG_REG_WD_TIME, DIV_ROUND_UP(start_withtimeout, 60)); } else { /* select seconds for timer units */ superio_clear_bit(sioaddr, F71808FG_REG_WDT_CONF, F71808FG_FLAG_WD_UNIT); superio_outb(sioaddr, F71808FG_REG_WD_TIME, start_withtimeout); } superio_exit(sioaddr); mutex_unlock(&watchdog.lock); if (nowayout) __module_get(THIS_MODULE); pr_info("watchdog started with initial timeout of %u sec\n", start_withtimeout); } return 0; exit_unlock: mutex_unlock(&watchdog.lock); exit_miscdev: misc_deregister(&watchdog_miscdev); exit_reboot: unregister_reboot_notifier(&watchdog_notifier); return err; } static int __init f71808e_find(int sioaddr) { u16 devid; int err = superio_enter(sioaddr); if (err) return err; devid = superio_inw(sioaddr, SIO_REG_MANID); if (devid != SIO_FINTEK_ID) { pr_debug("Not a Fintek device\n"); err = -ENODEV; goto exit; } devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID); switch (devid) { case SIO_F71808_ID: watchdog.type = f71808fg; break; case SIO_F71862_ID: watchdog.type = f71862fg; err = f71862fg_pin_configure(0); /* validate module parameter */ break; case SIO_F71869_ID: case SIO_F71869A_ID: watchdog.type = f71869; break; case SIO_F71882_ID: watchdog.type = f71882fg; break; case SIO_F71889_ID: watchdog.type = f71889fg; break; case SIO_F71858_ID: /* Confirmed (by datasheet) not to have a watchdog. */ err = -ENODEV; goto exit; default: pr_info("Unrecognized Fintek device: %04x\n", (unsigned int)devid); err = -ENODEV; goto exit; } pr_info("Found %s watchdog chip, revision %d\n", f71808e_names[watchdog.type], (int)superio_inb(sioaddr, SIO_REG_DEVREV)); exit: superio_exit(sioaddr); return err; } static int __init f71808e_init(void) { static const unsigned short addrs[] = { 0x2e, 0x4e }; int err = -ENODEV; int i; for (i = 0; i < ARRAY_SIZE(addrs); i++) { err = f71808e_find(addrs[i]); if (err == 0) break; } if (i == ARRAY_SIZE(addrs)) return err; return watchdog_init(addrs[i]); } static void __exit f71808e_exit(void) { if (watchdog_is_running()) { pr_warn("Watchdog timer still running, stopping it\n"); watchdog_stop(); } misc_deregister(&watchdog_miscdev); unregister_reboot_notifier(&watchdog_notifier); } MODULE_DESCRIPTION("F71808E Watchdog Driver"); MODULE_AUTHOR("Giel van Schijndel <me@mortis.eu>"); MODULE_LICENSE("GPL"); module_init(f71808e_init); module_exit(f71808e_exit);