]>
Commit | Line | Data |
---|---|---|
28ff2f7a | 1 | /*************************************************************************** |
312869ec | 2 | * Copyright (C) 2010-2012 Hans de Goede <hdegoede@redhat.com> * |
28ff2f7a HG |
3 | * * |
4 | * This program is free software; you can redistribute it and/or modify * | |
5 | * it under the terms of the GNU General Public License as published by * | |
6 | * the Free Software Foundation; either version 2 of the License, or * | |
7 | * (at your option) any later version. * | |
8 | * * | |
9 | * This program is distributed in the hope that it will be useful, * | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
12 | * GNU General Public License for more details. * | |
13 | * * | |
14 | * You should have received a copy of the GNU General Public License * | |
15 | * along with this program; if not, write to the * | |
16 | * Free Software Foundation, Inc., * | |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
18 | ***************************************************************************/ | |
19 | ||
20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
21 | ||
22 | #include <linux/module.h> | |
23 | #include <linux/init.h> | |
24 | #include <linux/platform_device.h> | |
25 | #include <linux/err.h> | |
26 | #include <linux/io.h> | |
27 | #include <linux/acpi.h> | |
28 | #include <linux/delay.h> | |
312869ec HG |
29 | #include <linux/fs.h> |
30 | #include <linux/watchdog.h> | |
31 | #include <linux/miscdevice.h> | |
32 | #include <linux/uaccess.h> | |
33 | #include <linux/kref.h> | |
34 | #include <linux/slab.h> | |
28ff2f7a HG |
35 | #include "sch56xx-common.h" |
36 | ||
312869ec HG |
37 | /* Insmod parameters */ |
38 | static int nowayout = WATCHDOG_NOWAYOUT; | |
39 | module_param(nowayout, int, 0); | |
40 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" | |
41 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | |
42 | ||
28ff2f7a HG |
43 | #define SIO_SCH56XX_LD_EM 0x0C /* Embedded uController Logical Dev */ |
44 | #define SIO_UNLOCK_KEY 0x55 /* Key to enable Super-I/O */ | |
45 | #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */ | |
46 | ||
47 | #define SIO_REG_LDSEL 0x07 /* Logical device select */ | |
48 | #define SIO_REG_DEVID 0x20 /* Device ID */ | |
49 | #define SIO_REG_ENABLE 0x30 /* Logical device enable */ | |
50 | #define SIO_REG_ADDR 0x66 /* Logical device address (2 bytes) */ | |
51 | ||
52 | #define SIO_SCH5627_ID 0xC6 /* Chipset ID */ | |
0772a640 | 53 | #define SIO_SCH5636_ID 0xC7 /* Chipset ID */ |
28ff2f7a | 54 | |
312869ec | 55 | #define REGION_LENGTH 10 |
28ff2f7a HG |
56 | |
57 | #define SCH56XX_CMD_READ 0x02 | |
58 | #define SCH56XX_CMD_WRITE 0x03 | |
59 | ||
312869ec HG |
60 | /* Watchdog registers */ |
61 | #define SCH56XX_REG_WDOG_PRESET 0x58B | |
62 | #define SCH56XX_REG_WDOG_CONTROL 0x58C | |
63 | #define SCH56XX_WDOG_TIME_BASE_SEC 0x01 | |
64 | #define SCH56XX_REG_WDOG_OUTPUT_ENABLE 0x58E | |
65 | #define SCH56XX_WDOG_OUTPUT_ENABLE 0x02 | |
66 | ||
67 | struct sch56xx_watchdog_data { | |
68 | u16 addr; | |
312869ec | 69 | struct mutex *io_lock; |
fb551405 HG |
70 | struct watchdog_info wdinfo; |
71 | struct watchdog_device wddev; | |
312869ec HG |
72 | u8 watchdog_preset; |
73 | u8 watchdog_control; | |
74 | u8 watchdog_output_enable; | |
75 | }; | |
76 | ||
28ff2f7a HG |
77 | static struct platform_device *sch56xx_pdev; |
78 | ||
79 | /* Super I/O functions */ | |
80 | static inline int superio_inb(int base, int reg) | |
81 | { | |
82 | outb(reg, base); | |
83 | return inb(base + 1); | |
84 | } | |
85 | ||
86 | static inline int superio_enter(int base) | |
87 | { | |
88 | /* Don't step on other drivers' I/O space by accident */ | |
89 | if (!request_muxed_region(base, 2, "sch56xx")) { | |
90 | pr_err("I/O address 0x%04x already in use\n", base); | |
91 | return -EBUSY; | |
92 | } | |
93 | ||
94 | outb(SIO_UNLOCK_KEY, base); | |
95 | ||
96 | return 0; | |
97 | } | |
98 | ||
99 | static inline void superio_select(int base, int ld) | |
100 | { | |
101 | outb(SIO_REG_LDSEL, base); | |
102 | outb(ld, base + 1); | |
103 | } | |
104 | ||
105 | static inline void superio_exit(int base) | |
106 | { | |
107 | outb(SIO_LOCK_KEY, base); | |
108 | release_region(base, 2); | |
109 | } | |
110 | ||
111 | static int sch56xx_send_cmd(u16 addr, u8 cmd, u16 reg, u8 v) | |
112 | { | |
113 | u8 val; | |
114 | int i; | |
115 | /* | |
116 | * According to SMSC for the commands we use the maximum time for | |
117 | * the EM to respond is 15 ms, but testing shows in practice it | |
118 | * responds within 15-32 reads, so we first busy poll, and if | |
119 | * that fails sleep a bit and try again until we are way past | |
120 | * the 15 ms maximum response time. | |
121 | */ | |
122 | const int max_busy_polls = 64; | |
123 | const int max_lazy_polls = 32; | |
124 | ||
125 | /* (Optional) Write-Clear the EC to Host Mailbox Register */ | |
126 | val = inb(addr + 1); | |
127 | outb(val, addr + 1); | |
128 | ||
129 | /* Set Mailbox Address Pointer to first location in Region 1 */ | |
130 | outb(0x00, addr + 2); | |
131 | outb(0x80, addr + 3); | |
132 | ||
133 | /* Write Request Packet Header */ | |
134 | outb(cmd, addr + 4); /* VREG Access Type read:0x02 write:0x03 */ | |
135 | outb(0x01, addr + 5); /* # of Entries: 1 Byte (8-bit) */ | |
136 | outb(0x04, addr + 2); /* Mailbox AP to first data entry loc. */ | |
137 | ||
138 | /* Write Value field */ | |
139 | if (cmd == SCH56XX_CMD_WRITE) | |
140 | outb(v, addr + 4); | |
141 | ||
142 | /* Write Address field */ | |
143 | outb(reg & 0xff, addr + 6); | |
144 | outb(reg >> 8, addr + 7); | |
145 | ||
146 | /* Execute the Random Access Command */ | |
147 | outb(0x01, addr); /* Write 01h to the Host-to-EC register */ | |
148 | ||
149 | /* EM Interface Polling "Algorithm" */ | |
150 | for (i = 0; i < max_busy_polls + max_lazy_polls; i++) { | |
151 | if (i >= max_busy_polls) | |
152 | msleep(1); | |
153 | /* Read Interrupt source Register */ | |
154 | val = inb(addr + 8); | |
155 | /* Write Clear the interrupt source bits */ | |
156 | if (val) | |
157 | outb(val, addr + 8); | |
158 | /* Command Completed ? */ | |
159 | if (val & 0x01) | |
160 | break; | |
161 | } | |
162 | if (i == max_busy_polls + max_lazy_polls) { | |
163 | pr_err("Max retries exceeded reading virtual " | |
164 | "register 0x%04hx (%d)\n", reg, 1); | |
165 | return -EIO; | |
166 | } | |
167 | ||
168 | /* | |
169 | * According to SMSC we may need to retry this, but sofar I've always | |
170 | * seen this succeed in 1 try. | |
171 | */ | |
172 | for (i = 0; i < max_busy_polls; i++) { | |
173 | /* Read EC-to-Host Register */ | |
174 | val = inb(addr + 1); | |
175 | /* Command Completed ? */ | |
176 | if (val == 0x01) | |
177 | break; | |
178 | ||
179 | if (i == 0) | |
180 | pr_warn("EC reports: 0x%02x reading virtual register " | |
181 | "0x%04hx\n", (unsigned int)val, reg); | |
182 | } | |
183 | if (i == max_busy_polls) { | |
184 | pr_err("Max retries exceeded reading virtual " | |
185 | "register 0x%04hx (%d)\n", reg, 2); | |
186 | return -EIO; | |
187 | } | |
188 | ||
189 | /* | |
190 | * According to the SMSC app note we should now do: | |
191 | * | |
192 | * Set Mailbox Address Pointer to first location in Region 1 * | |
193 | * outb(0x00, addr + 2); | |
194 | * outb(0x80, addr + 3); | |
195 | * | |
196 | * But if we do that things don't work, so let's not. | |
197 | */ | |
198 | ||
199 | /* Read Value field */ | |
200 | if (cmd == SCH56XX_CMD_READ) | |
201 | return inb(addr + 4); | |
202 | ||
203 | return 0; | |
204 | } | |
205 | ||
206 | int sch56xx_read_virtual_reg(u16 addr, u16 reg) | |
207 | { | |
208 | return sch56xx_send_cmd(addr, SCH56XX_CMD_READ, reg, 0); | |
209 | } | |
210 | EXPORT_SYMBOL(sch56xx_read_virtual_reg); | |
211 | ||
212 | int sch56xx_write_virtual_reg(u16 addr, u16 reg, u8 val) | |
213 | { | |
214 | return sch56xx_send_cmd(addr, SCH56XX_CMD_WRITE, reg, val); | |
215 | } | |
216 | EXPORT_SYMBOL(sch56xx_write_virtual_reg); | |
217 | ||
218 | int sch56xx_read_virtual_reg16(u16 addr, u16 reg) | |
219 | { | |
220 | int lsb, msb; | |
221 | ||
222 | /* Read LSB first, this will cause the matching MSB to be latched */ | |
223 | lsb = sch56xx_read_virtual_reg(addr, reg); | |
224 | if (lsb < 0) | |
225 | return lsb; | |
226 | ||
227 | msb = sch56xx_read_virtual_reg(addr, reg + 1); | |
228 | if (msb < 0) | |
229 | return msb; | |
230 | ||
231 | return lsb | (msb << 8); | |
232 | } | |
233 | EXPORT_SYMBOL(sch56xx_read_virtual_reg16); | |
234 | ||
235 | int sch56xx_read_virtual_reg12(u16 addr, u16 msb_reg, u16 lsn_reg, | |
236 | int high_nibble) | |
237 | { | |
238 | int msb, lsn; | |
239 | ||
240 | /* Read MSB first, this will cause the matching LSN to be latched */ | |
241 | msb = sch56xx_read_virtual_reg(addr, msb_reg); | |
242 | if (msb < 0) | |
243 | return msb; | |
244 | ||
245 | lsn = sch56xx_read_virtual_reg(addr, lsn_reg); | |
246 | if (lsn < 0) | |
247 | return lsn; | |
248 | ||
249 | if (high_nibble) | |
250 | return (msb << 4) | (lsn >> 4); | |
251 | else | |
252 | return (msb << 4) | (lsn & 0x0f); | |
253 | } | |
254 | EXPORT_SYMBOL(sch56xx_read_virtual_reg12); | |
255 | ||
312869ec HG |
256 | /* |
257 | * Watchdog routines | |
258 | */ | |
259 | ||
fb551405 HG |
260 | static int watchdog_set_timeout(struct watchdog_device *wddev, |
261 | unsigned int timeout) | |
312869ec | 262 | { |
fb551405 HG |
263 | struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev); |
264 | unsigned int resolution; | |
312869ec | 265 | u8 control; |
fb551405 | 266 | int ret; |
312869ec HG |
267 | |
268 | /* 1 second or 60 second resolution? */ | |
269 | if (timeout <= 255) | |
270 | resolution = 1; | |
271 | else | |
272 | resolution = 60; | |
273 | ||
274 | if (timeout < resolution || timeout > (resolution * 255)) | |
275 | return -EINVAL; | |
276 | ||
312869ec HG |
277 | if (resolution == 1) |
278 | control = data->watchdog_control | SCH56XX_WDOG_TIME_BASE_SEC; | |
279 | else | |
280 | control = data->watchdog_control & ~SCH56XX_WDOG_TIME_BASE_SEC; | |
281 | ||
282 | if (data->watchdog_control != control) { | |
283 | mutex_lock(data->io_lock); | |
284 | ret = sch56xx_write_virtual_reg(data->addr, | |
285 | SCH56XX_REG_WDOG_CONTROL, | |
286 | control); | |
287 | mutex_unlock(data->io_lock); | |
288 | if (ret) | |
fb551405 | 289 | return ret; |
312869ec HG |
290 | |
291 | data->watchdog_control = control; | |
292 | } | |
293 | ||
294 | /* | |
295 | * Remember new timeout value, but do not write as that (re)starts | |
296 | * the watchdog countdown. | |
297 | */ | |
298 | data->watchdog_preset = DIV_ROUND_UP(timeout, resolution); | |
fb551405 | 299 | wddev->timeout = data->watchdog_preset * resolution; |
312869ec | 300 | |
fb551405 | 301 | return 0; |
312869ec HG |
302 | } |
303 | ||
fb551405 | 304 | static int watchdog_start(struct watchdog_device *wddev) |
312869ec | 305 | { |
fb551405 | 306 | struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev); |
312869ec HG |
307 | int ret; |
308 | u8 val; | |
309 | ||
312869ec HG |
310 | /* |
311 | * The sch56xx's watchdog cannot really be started / stopped | |
312 | * it is always running, but we can avoid the timer expiring | |
313 | * from causing a system reset by clearing the output enable bit. | |
314 | * | |
315 | * The sch56xx's watchdog will set the watchdog event bit, bit 0 | |
316 | * of the second interrupt source register (at base-address + 9), | |
317 | * when the timer expires. | |
318 | * | |
319 | * This will only cause a system reset if the 0-1 flank happens when | |
320 | * output enable is true. Setting output enable after the flank will | |
321 | * not cause a reset, nor will the timer expiring a second time. | |
322 | * This means we must clear the watchdog event bit in case it is set. | |
323 | * | |
324 | * The timer may still be running (after a recent watchdog_stop) and | |
325 | * mere milliseconds away from expiring, so the timer must be reset | |
326 | * first! | |
327 | */ | |
328 | ||
329 | mutex_lock(data->io_lock); | |
330 | ||
331 | /* 1. Reset the watchdog countdown counter */ | |
332 | ret = sch56xx_write_virtual_reg(data->addr, SCH56XX_REG_WDOG_PRESET, | |
333 | data->watchdog_preset); | |
334 | if (ret) | |
335 | goto leave; | |
336 | ||
85a2e40c HG |
337 | /* 2. Enable output */ |
338 | val = data->watchdog_output_enable | SCH56XX_WDOG_OUTPUT_ENABLE; | |
339 | ret = sch56xx_write_virtual_reg(data->addr, | |
340 | SCH56XX_REG_WDOG_OUTPUT_ENABLE, val); | |
341 | if (ret) | |
342 | goto leave; | |
312869ec | 343 | |
85a2e40c | 344 | data->watchdog_output_enable = val; |
312869ec HG |
345 | |
346 | /* 3. Clear the watchdog event bit if set */ | |
347 | val = inb(data->addr + 9); | |
348 | if (val & 0x01) | |
349 | outb(0x01, data->addr + 9); | |
350 | ||
351 | leave: | |
352 | mutex_unlock(data->io_lock); | |
312869ec HG |
353 | return ret; |
354 | } | |
355 | ||
fb551405 | 356 | static int watchdog_trigger(struct watchdog_device *wddev) |
312869ec | 357 | { |
fb551405 | 358 | struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev); |
312869ec HG |
359 | int ret; |
360 | ||
312869ec HG |
361 | /* Reset the watchdog countdown counter */ |
362 | mutex_lock(data->io_lock); | |
363 | ret = sch56xx_write_virtual_reg(data->addr, SCH56XX_REG_WDOG_PRESET, | |
364 | data->watchdog_preset); | |
365 | mutex_unlock(data->io_lock); | |
fb551405 | 366 | |
312869ec HG |
367 | return ret; |
368 | } | |
369 | ||
fb551405 | 370 | static int watchdog_stop(struct watchdog_device *wddev) |
312869ec | 371 | { |
fb551405 | 372 | struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev); |
312869ec HG |
373 | int ret = 0; |
374 | u8 val; | |
375 | ||
85a2e40c HG |
376 | val = data->watchdog_output_enable & ~SCH56XX_WDOG_OUTPUT_ENABLE; |
377 | mutex_lock(data->io_lock); | |
378 | ret = sch56xx_write_virtual_reg(data->addr, | |
379 | SCH56XX_REG_WDOG_OUTPUT_ENABLE, val); | |
380 | mutex_unlock(data->io_lock); | |
381 | if (ret) | |
382 | return ret; | |
312869ec | 383 | |
85a2e40c HG |
384 | data->watchdog_output_enable = val; |
385 | return 0; | |
312869ec HG |
386 | } |
387 | ||
fb551405 HG |
388 | static const struct watchdog_ops watchdog_ops = { |
389 | .owner = THIS_MODULE, | |
390 | .start = watchdog_start, | |
391 | .stop = watchdog_stop, | |
392 | .ping = watchdog_trigger, | |
393 | .set_timeout = watchdog_set_timeout, | |
312869ec HG |
394 | }; |
395 | ||
fb551405 | 396 | struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent, |
312869ec HG |
397 | u16 addr, u32 revision, struct mutex *io_lock, int check_enabled) |
398 | { | |
399 | struct sch56xx_watchdog_data *data; | |
fb551405 | 400 | int err, control, output_enable; |
312869ec HG |
401 | |
402 | /* Cache the watchdog registers */ | |
403 | mutex_lock(io_lock); | |
404 | control = | |
405 | sch56xx_read_virtual_reg(addr, SCH56XX_REG_WDOG_CONTROL); | |
406 | output_enable = | |
407 | sch56xx_read_virtual_reg(addr, SCH56XX_REG_WDOG_OUTPUT_ENABLE); | |
408 | mutex_unlock(io_lock); | |
409 | ||
410 | if (control < 0) | |
411 | return NULL; | |
412 | if (output_enable < 0) | |
413 | return NULL; | |
414 | if (check_enabled && !(output_enable & SCH56XX_WDOG_OUTPUT_ENABLE)) { | |
415 | pr_warn("Watchdog not enabled by BIOS, not registering\n"); | |
416 | return NULL; | |
417 | } | |
418 | ||
419 | data = kzalloc(sizeof(struct sch56xx_watchdog_data), GFP_KERNEL); | |
420 | if (!data) | |
421 | return NULL; | |
422 | ||
423 | data->addr = addr; | |
312869ec | 424 | data->io_lock = io_lock; |
312869ec | 425 | |
fb551405 HG |
426 | strlcpy(data->wdinfo.identity, "sch56xx watchdog", |
427 | sizeof(data->wdinfo.identity)); | |
428 | data->wdinfo.firmware_version = revision; | |
429 | data->wdinfo.options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT; | |
430 | if (!nowayout) | |
431 | data->wdinfo.options |= WDIOF_MAGICCLOSE; | |
432 | ||
433 | data->wddev.info = &data->wdinfo; | |
434 | data->wddev.ops = &watchdog_ops; | |
435 | data->wddev.parent = parent; | |
436 | data->wddev.timeout = 60; | |
437 | data->wddev.min_timeout = 1; | |
438 | data->wddev.max_timeout = 255 * 60; | |
439 | if (nowayout) | |
440 | data->wddev.status |= WDOG_NO_WAY_OUT; | |
441 | if (output_enable & SCH56XX_WDOG_OUTPUT_ENABLE) | |
442 | data->wddev.status |= WDOG_ACTIVE; | |
443 | ||
444 | /* Since the watchdog uses a downcounter there is no register to read | |
445 | the BIOS set timeout from (if any was set at all) -> | |
446 | Choose a preset which will give us a 1 minute timeout */ | |
447 | if (control & SCH56XX_WDOG_TIME_BASE_SEC) | |
448 | data->watchdog_preset = 60; /* seconds */ | |
449 | else | |
450 | data->watchdog_preset = 1; /* minute */ | |
312869ec | 451 | |
fb551405 HG |
452 | data->watchdog_control = control; |
453 | data->watchdog_output_enable = output_enable; | |
312869ec | 454 | |
fb551405 HG |
455 | watchdog_set_drvdata(&data->wddev, data); |
456 | err = watchdog_register_device(&data->wddev); | |
312869ec HG |
457 | if (err) { |
458 | pr_err("Registering watchdog chardev: %d\n", err); | |
fb551405 HG |
459 | kfree(data); |
460 | return NULL; | |
312869ec HG |
461 | } |
462 | ||
463 | return data; | |
312869ec HG |
464 | } |
465 | EXPORT_SYMBOL(sch56xx_watchdog_register); | |
466 | ||
467 | void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data) | |
468 | { | |
fb551405 HG |
469 | watchdog_unregister_device(&data->wddev); |
470 | kfree(data); | |
312869ec HG |
471 | } |
472 | EXPORT_SYMBOL(sch56xx_watchdog_unregister); | |
473 | ||
474 | /* | |
475 | * platform dev find, add and remove functions | |
476 | */ | |
477 | ||
28ff2f7a HG |
478 | static int __init sch56xx_find(int sioaddr, unsigned short *address, |
479 | const char **name) | |
480 | { | |
481 | u8 devid; | |
482 | int err; | |
483 | ||
484 | err = superio_enter(sioaddr); | |
485 | if (err) | |
486 | return err; | |
487 | ||
488 | devid = superio_inb(sioaddr, SIO_REG_DEVID); | |
489 | switch (devid) { | |
490 | case SIO_SCH5627_ID: | |
491 | *name = "sch5627"; | |
492 | break; | |
0772a640 HG |
493 | case SIO_SCH5636_ID: |
494 | *name = "sch5636"; | |
495 | break; | |
28ff2f7a HG |
496 | default: |
497 | pr_debug("Unsupported device id: 0x%02x\n", | |
498 | (unsigned int)devid); | |
499 | err = -ENODEV; | |
500 | goto exit; | |
501 | } | |
502 | ||
503 | superio_select(sioaddr, SIO_SCH56XX_LD_EM); | |
504 | ||
505 | if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { | |
506 | pr_warn("Device not activated\n"); | |
507 | err = -ENODEV; | |
508 | goto exit; | |
509 | } | |
510 | ||
511 | /* | |
512 | * Warning the order of the low / high byte is the other way around | |
513 | * as on most other superio devices!! | |
514 | */ | |
515 | *address = superio_inb(sioaddr, SIO_REG_ADDR) | | |
516 | superio_inb(sioaddr, SIO_REG_ADDR + 1) << 8; | |
517 | if (*address == 0) { | |
518 | pr_warn("Base address not set\n"); | |
519 | err = -ENODEV; | |
520 | goto exit; | |
521 | } | |
522 | ||
523 | exit: | |
524 | superio_exit(sioaddr); | |
525 | return err; | |
526 | } | |
527 | ||
528 | static int __init sch56xx_device_add(unsigned short address, const char *name) | |
529 | { | |
530 | struct resource res = { | |
531 | .start = address, | |
532 | .end = address + REGION_LENGTH - 1, | |
533 | .flags = IORESOURCE_IO, | |
534 | }; | |
535 | int err; | |
536 | ||
537 | sch56xx_pdev = platform_device_alloc(name, address); | |
538 | if (!sch56xx_pdev) | |
539 | return -ENOMEM; | |
540 | ||
541 | res.name = sch56xx_pdev->name; | |
542 | err = acpi_check_resource_conflict(&res); | |
543 | if (err) | |
544 | goto exit_device_put; | |
545 | ||
546 | err = platform_device_add_resources(sch56xx_pdev, &res, 1); | |
547 | if (err) { | |
548 | pr_err("Device resource addition failed\n"); | |
549 | goto exit_device_put; | |
550 | } | |
551 | ||
552 | err = platform_device_add(sch56xx_pdev); | |
553 | if (err) { | |
554 | pr_err("Device addition failed\n"); | |
555 | goto exit_device_put; | |
556 | } | |
557 | ||
558 | return 0; | |
559 | ||
560 | exit_device_put: | |
561 | platform_device_put(sch56xx_pdev); | |
562 | ||
563 | return err; | |
564 | } | |
565 | ||
566 | static int __init sch56xx_init(void) | |
567 | { | |
568 | int err; | |
569 | unsigned short address; | |
570 | const char *name; | |
571 | ||
572 | err = sch56xx_find(0x4e, &address, &name); | |
573 | if (err) | |
574 | err = sch56xx_find(0x2e, &address, &name); | |
575 | if (err) | |
576 | return err; | |
577 | ||
578 | return sch56xx_device_add(address, name); | |
579 | } | |
580 | ||
581 | static void __exit sch56xx_exit(void) | |
582 | { | |
583 | platform_device_unregister(sch56xx_pdev); | |
584 | } | |
585 | ||
586 | MODULE_DESCRIPTION("SMSC SCH56xx Hardware Monitoring Common Code"); | |
587 | MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); | |
588 | MODULE_LICENSE("GPL"); | |
589 | ||
590 | module_init(sch56xx_init); | |
591 | module_exit(sch56xx_exit); |