{"id":602,"date":"2019-09-27T18:56:14","date_gmt":"2019-09-27T10:56:14","guid":{"rendered":"http:\/\/iqotom.com\/?p=602"},"modified":"2019-09-27T18:56:17","modified_gmt":"2019-09-27T10:56:17","slug":"linux-superio-cpu-fan%e8%bd%ac%e9%80%9f%e8%af%bb%e5%8f%96","status":"publish","type":"post","link":"http:\/\/iqotom.com\/?p=602","title":{"rendered":"Linux SuperIO CPU FAN\u8f6c\u901f\u8bfb\u53d6"},"content":{"rendered":"\n<p> \u4e0a\u4e00\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e86\u5728Linux\u7528\u6237\u7a7a\u95f4\u4f7f\u7528outb\u63a5\u53e3\uff0c\u76f4\u63a5\u8bbf\u95eeSuperio\u82af\u7247\uff0c\u64cd\u4f5cGPIO\u5bc4\u5b58\u5668\u7684\u6559\u7a0b\uff0c\u8fd9\u6b21\u7ee7\u7eed\u5229\u7528Superio\u8bfb\u53d6CPU\u98ce\u6247\u8f6c\u901f\u3002<br>CPU\u98ce\u6247\u5c5e\u4e8e\u73af\u5883\u63a7\u5236\u5668\uff08EC\uff09\uff0c\u5185\u7f6e\u5728IT8786E-I\u4e2d\uff0c\u5305\u62ec\u4e94\u4e2a\u7535\u538b\u8f93\u5165\uff0c\u4e09\u4e2a\u6e29\u5ea6\u4f20\u611f\u5668\u8f93\u5165\uff0c\u4e94\u4e2aFAN\u8f6c\u901f\u8ba1\u8f93\u5165\u548c\u4e94\u7ec4\u5148\u8fdb\u7684\u98ce\u6247\u63a7\u5236\u5668\u3002 EC\u76d1\u63a7\u786c\u4ef6\u73af\u5883\uff0c\u5b9e\u73b0\u4e2a\u4eba\u7535\u8111\u7684\u73af\u5883\u63a7\u5236\u3002 <\/p>\n\n\n\n<p>\u5148\u67e5\u770b\u82af\u7247\u624b\u518c\u627e\u5230EC\u63a7\u5236\u5668\u63a5\u53e3\u603b\u7ebf\u5730\u5740<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"284\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-00.png\" alt=\"\" class=\"wp-image-598\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-00.png 734w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-00-300x116.png 300w\" sizes=\"(max-width: 734px) 100vw, 734px\" \/><figcaption>IT9896E-I<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u5927\u81f4\u6d41\u7a0b<\/h3>\n\n\n\n<ol><li> \u8fdb\u5165MB PnP \u6a21\u5f0f\uff0887h, 01h, 55h, 55h;\uff09 <\/li><li> \u4f7f\u80fd EC\uff08LDN=04h, Index 30h=01\uff09 <\/li><li> \u83b7\u53d6EC Base Address <br> \u57fa\u5730\u5740\u7531\u903b\u8f91\u8bbe\u5907\u5bc4\u5b58\u5668\u786e\u5b9a\uff08index=60h, 61h\uff09 <br> \u6570\u636e\u7aef\u53e3\uff08Base+05h\uff09\uff1b\u6570\u636e\u7aef\u53e3\uff08Base+06h\uff09 <\/li><li> \u914d\u7f6e\u98ce\u6247\u8f6c\u901f\u5bc4\u5b58\u5668\uff08index=0Ch\uff0cdefault=00h\uff09 <\/li><li> \u8ba1\u7b97\u51fa\u98ce\u6247\u8f6c\u901f\uff08index=0Dh,18h\uff09 <\/li><\/ol>\n\n\n\n<p>CPU\u98ce\u6247\u8f6c\u901f\u8ba1\u7b97\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"183\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-01.png\" alt=\"\" class=\"wp-image-599\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-01.png 719w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-01-300x76.png 300w\" sizes=\"(max-width: 719px) 100vw, 719px\" \/><figcaption>\u98ce\u6247\u8f6c\u901f\u8ba1\u7b97\u516c\u5f0f<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ee3\u7801\u5982\u4e0b\uff1a<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;stdio.h>\n#include&lt;sys\/io.h>\n#include&lt;unistd.h>\n#include&lt;math.h>\n\n#define REG\t\t0x2e\n#define VAL\t\t0x2f\n#define CHIPID\t\t0x20\n#define CHIPREV\t\t0x22\n\nstatic int superio_inw(int reg)\n{\n\tint val;\n\toutb(reg++, REG);\n\tval = inb(VAL) &lt;&lt; 8;\n\toutb(reg, REG);\n\tval |= inb(VAL);\n\treturn val;\n}\n\nstatic void init_ec()\n{\n\t\/\/Enter MB PnP Mode\n\toutb(0x87, REG);\n\toutb(0x01, REG);\n\toutb(0x55, REG);\n\toutb(0x55, REG);\n\t\n\t\/\/\u4f7f\u80fdEC\u63a7\u5236\u5668\n\toutb(0x07, REG);\n\toutb(0x04, VAL);\n\toutb(0x30,REG);\n\toutb(0x01,VAL);\n}\n\nint main()\n{\n    unsigned int ec_base,addr_port,data_port,fan_speed,fan_rpm;\n\tint ret = iopl(3);\n\tif(ret == -1)\n\t{\n\t\tprintf(\"iopl error.\\n\");\n\t\treturn -1;\n\t}\n\t\/\/\u521d\u59cb\u5316\n\tinit_ec();\n\t\n\t\/\/\u83b7\u53d6EC\u63a7\u5236\u5668\u57fa\u5730\u5740\n\tec_base = superio_inw(0x60);\n\tprintf(\"ec_base addr:0x%x\\n\", ec_base);\n\taddr_port = ec_base+0x05;\n\tdata_port = ec_base+0x06;\n\tprintf(\"addr_port is 0x%x data_port is 0x%x\\n\",addr_port,data_port);\n\n\t\/\/\u914d\u7f6e\u98ce\u6247\u8f6c\u901f\u8ba1\u63a7\u5236\u5bc4\u5b58\u5668\n\toutb(0x0c, addr_port);\n\toutb(0x00, data_port);\n\n\t\/\/\u4e00\u8d77\u6709\u4e09\u7ec4\uff0c\u8fd9\u91cc\u4f7f\u7528\u7684\u7b2c\u4e00\u7ec4\uff0c\u4e5f\u5c31\u662fCPU_FAN\n\t\/\/1:CPU_FAN 2:SYS_FAN 3:PWR_FAN\n\t\/\/1-3 Reading Registers[7:0] (Index=0Dh-0Fh)\n\toutb(0x0d,addr_port);\n\tint lval = inb(data_port);\n\t\/\/1-3 Extended Reading Registers [15:8] (Index=18h-1Ah)\n\toutb(0x18,addr_port);\n\tint mval = inb(data_port);\n\t\/\/\u6bcf\u8f6c\u7684\u5185\u90e8\u65f6\u949f\u8ba1\u6570\uff0c\u8fd9\u91cc\u662f16\u4f4d\n\tfan_speed = (mval&lt;&lt;8) | lval;\n\tprintf(\"mval:%02x lval:%02x fan_speed is %d\\n\",mval, lval, fan_speed);\n\t\/\/\u6700\u540e\u6839\u636e\u82af\u7247\u624b\u518c\u7684\u516c\u5f0f\u8ba1\u7b97\u51fa\u98ce\u6247\u8f6c\u901f\n\tfan_rpm = 1.35*pow(10,6)\/(fan_speed*2);\n\tprintf(\"fan_rpm is %d\\n\",fan_rpm);\n\n\t\/\/\u8bfb\u53d6tmp1\u6e29\u5ea6\u5bc4\u5b58\u5668\n\toutb(0x29, addr_port);\n\tfloat tmpin1 = inb(data_port);\n\tprintf(\"tmpin1 is %.1f \u00b0C\\n\",tmpin1);\n\n\t\/\/Exit MB PnP Mode\n\toutb(0x02, REG);\n\toutb(0x02, VAL);\n\tiopl(0);\n\treturn 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6267\u884c\u7ed3\u679c<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"740\" height=\"268\" src=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-02.png\" alt=\"\" class=\"wp-image-600\" srcset=\"http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-02.png 740w, http:\/\/iqotom.com\/wp-content\/uploads\/2019\/09\/superio-cpufan-02-300x109.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><figcaption>CPU RPM<\/figcaption><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e86\u5728Linux\u7528\u6237\u7a7a\u95f4\u4f7f\u7528outb\u63a5\u53e3\uff0c\u76f4\u63a5\u8bbf\u95eeSuperio\u82af\u7247\uff0c\u64cd\u4f5cGPIO\u5bc4\u5b58\u5668\u7684\u6559\u7a0b\uff0c\u8fd9\u2026 <span class=\"read-more\"><a href=\"http:\/\/iqotom.com\/?p=602\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":601,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,49],"tags":[53],"_links":{"self":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/602"}],"collection":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=602"}],"version-history":[{"count":2,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions"}],"predecessor-version":[{"id":604,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions\/604"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=\/wp\/v2\/media\/601"}],"wp:attachment":[{"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iqotom.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}