Blame view
drivers/hwmon/hwmon.c
3.03 KB
1236441f3
|
1 |
/* |
5ed04880a
|
2 3 4 5 6 7 8 9 10 11 |
* hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring * * This file defines the sysfs class "hwmon", for use by sensors drivers. * * Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. */ |
1236441f3
|
12 |
|
c95df1ae6
|
13 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1236441f3
|
14 15 16 17 18 19 |
#include <linux/module.h> #include <linux/device.h> #include <linux/err.h> #include <linux/kdev_t.h> #include <linux/idr.h> #include <linux/hwmon.h> |
8c65b4a60
|
20 |
#include <linux/gfp.h> |
ded2b6661
|
21 |
#include <linux/spinlock.h> |
2958b1ec6
|
22 |
#include <linux/pci.h> |
1236441f3
|
23 24 25 26 27 |
#define HWMON_ID_PREFIX "hwmon" #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" static struct class *hwmon_class; |
4ca5f468c
|
28 |
static DEFINE_IDA(hwmon_ida); |
1236441f3
|
29 30 |
/** |
1beeffe43
|
31 |
* hwmon_device_register - register w/ hwmon |
1236441f3
|
32 33 |
* @dev: the device to register * |
1beeffe43
|
34 |
* hwmon_device_unregister() must be called when the device is no |
1236441f3
|
35 36 |
* longer needed. * |
1beeffe43
|
37 |
* Returns the pointer to the new device. |
1236441f3
|
38 |
*/ |
1beeffe43
|
39 |
struct device *hwmon_device_register(struct device *dev) |
1236441f3
|
40 |
{ |
1beeffe43
|
41 |
struct device *hwdev; |
4ca5f468c
|
42 |
int id; |
ded2b6661
|
43 |
|
4ca5f468c
|
44 45 46 |
id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL); if (id < 0) return ERR_PTR(id); |
1236441f3
|
47 |
|
a9b12619f
|
48 49 |
hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL, HWMON_ID_FORMAT, id); |
1236441f3
|
50 |
|
4ca5f468c
|
51 52 |
if (IS_ERR(hwdev)) ida_simple_remove(&hwmon_ida, id); |
1236441f3
|
53 |
|
1beeffe43
|
54 |
return hwdev; |
1236441f3
|
55 |
} |
839a9eefc
|
56 |
EXPORT_SYMBOL_GPL(hwmon_device_register); |
1236441f3
|
57 58 59 60 |
/** * hwmon_device_unregister - removes the previously registered class device * |
1beeffe43
|
61 |
* @dev: the class device to destroy |
1236441f3
|
62 |
*/ |
1beeffe43
|
63 |
void hwmon_device_unregister(struct device *dev) |
1236441f3
|
64 65 |
{ int id; |
739cf3a26
|
66 |
if (likely(sscanf(dev_name(dev), HWMON_ID_FORMAT, &id) == 1)) { |
1beeffe43
|
67 |
device_unregister(dev); |
4ca5f468c
|
68 |
ida_simple_remove(&hwmon_ida, id); |
1236441f3
|
69 |
} else |
1beeffe43
|
70 |
dev_dbg(dev->parent, |
1236441f3
|
71 72 73 |
"hwmon_device_unregister() failed: bad class ID! "); } |
839a9eefc
|
74 |
EXPORT_SYMBOL_GPL(hwmon_device_unregister); |
1236441f3
|
75 |
|
2958b1ec6
|
76 77 78 79 80 81 82 83 84 |
static void __init hwmon_pci_quirks(void) { #if defined CONFIG_X86 && defined CONFIG_PCI struct pci_dev *sb; u16 base; u8 enable; /* Open access to 0x295-0x296 on MSI MS-7031 */ sb = pci_get_device(PCI_VENDOR_ID_ATI, 0x436c, NULL); |
d6dab7dd1
|
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
if (sb) { if (sb->subsystem_vendor == 0x1462 && /* MSI */ sb->subsystem_device == 0x0031) { /* MS-7031 */ pci_read_config_byte(sb, 0x48, &enable); pci_read_config_word(sb, 0x64, &base); if (base == 0 && !(enable & BIT(2))) { dev_info(&sb->dev, "Opening wide generic port at 0x295 "); pci_write_config_word(sb, 0x64, 0x295); pci_write_config_byte(sb, 0x48, enable | BIT(2)); } |
2958b1ec6
|
99 |
} |
d6dab7dd1
|
100 |
pci_dev_put(sb); |
2958b1ec6
|
101 102 103 |
} #endif } |
1236441f3
|
104 105 |
static int __init hwmon_init(void) { |
2958b1ec6
|
106 |
hwmon_pci_quirks(); |
1236441f3
|
107 108 |
hwmon_class = class_create(THIS_MODULE, "hwmon"); if (IS_ERR(hwmon_class)) { |
c95df1ae6
|
109 110 |
pr_err("couldn't create sysfs class "); |
1236441f3
|
111 112 113 114 115 116 117 118 119 |
return PTR_ERR(hwmon_class); } return 0; } static void __exit hwmon_exit(void) { class_destroy(hwmon_class); } |
37f54ee54
|
120 |
subsys_initcall(hwmon_init); |
1236441f3
|
121 |
module_exit(hwmon_exit); |
1236441f3
|
122 123 124 |
MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); MODULE_DESCRIPTION("hardware monitoring sysfs/class support"); MODULE_LICENSE("GPL"); |