File: getMB-smb.c

package info (click to toggle)
xmbmon 2.05-8
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 928 kB
  • ctags: 910
  • sloc: ansic: 6,089; sh: 2,151; perl: 87; makefile: 79
file content (114 lines) | stat: -rw-r--r-- 2,016 bytes parent folder | download | duplicates (5)
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

/* SMBus method for accessing Hardware Monitor Chip */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#if !defined(LINUX) && defined(HAVE_SMBUS) && defined(SMBUS_IOCTL)

/* Using SMBus ioctl, need "xxxpm" driver !! */
#include "getMB-smb_ioctl.c"

#else		/* SMBus direct access routines */

#include "methods.h"
#include "smbuses.h"

/* smbus io routine, global */
extern SMBUS_IO *smbus;

/* SMBus Base Address, global */
int smb_base	= -1;
int smb_slave	= LM_ADDR;
int smb_wbtemp1_flag = 1;	/* = 0 if enable */
int smb_wbtemp2_flag = 1;	/* = 0 if eaable */
int smb_wbtemp1	= WBtemp1_ADDR;
int smb_wbtemp2	= WBtemp2_ADDR;
int smb_wbt1reg	= 0x00;
int smb_wbt2reg	= 0x00;

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>

#include "io_static.c"


static int ReadByte(int addr)
{
	int ret;
	ret = smbus->ReadB(smb_base, smb_slave, addr);
	if (ret == -1) {
/*	perror("SMBus ReadB");
		exit(-1); */
		ret = 0xFF;
	}
	return (ret & 0xFF);
}

static void WriteByte(int addr, int value)
{
	if(smbus->WriteB(smb_base, smb_slave, addr, value) == -1) {
		perror("SMBus WriteB");
		exit(-1);
	}
}

static int ReadWord(int addr)
{
	int ret;
	ret = smbus->ReadW(smb_base, smb_slave, addr);
	if (ret == -1) {
/*	perror("SMBus ReadW");
		exit(-1); */
		ret = 0xFFFF;
	}
	return (ret & 0xFFFF);
}

static void WriteWord(int addr, int value)
{
	if(smbus->WriteW(smb_base, smb_slave, addr, value) == -1) {
		perror("SMBus WriteW");
		exit(-1);
	}
}

static int ReadTemp1()
{
	int ret;
	ret = smbus->ReadW(smb_base, smb_wbtemp1, smb_wbt1reg);
	if (ret == -1) {
/*		perror("SMBus ReadW");
		exit(-1); */
		ret = 0xFFFF;
	}
	return (ret & 0xFFFF);
}
static int ReadTemp2()
{
	int ret;
	ret = smbus->ReadW(smb_base, smb_wbtemp2, smb_wbt2reg);
	if (ret == -1) {
/*		perror("SMBus ReadW");
		exit(-1); */
		ret = 0xFFFF;
	}
	return (ret & 0xFFFF);
}

struct lm_methods method_smb = {
	OpenIO,
	CloseIO,
	ReadByte,
	WriteByte,
	ReadWord,
	WriteWord,
	ReadTemp1,
	ReadTemp2
};

#endif