/* sensorK.h - common definitions file for Kontron sensor drivers approach */

/* Copyright 2006-2008 Kontron Modular Computers GmbH */

/*
modification history
--------------------
01a,15jul10,kpn created
*/

#ifndef __INCw83627dhgK_h
#define __INCw83627dhgK_h

#ifdef __cplusplus
extern "C" {
#endif

#include "vxWorks.h"
#include "versionK.h"

/* defines */

KONTRON_VERSION(w83627dhg,01b)	/* version identifier */

#define SENSOR_NAME		"W83627dhgK"

#define VENDOR_ID 0x5CA3

#define IOREGION_ALIGNMENT	~7
#define IOREGION_OFFSET		5
#define IOREGION_LENGTH		2
#define ADDR_REG_OFFSET		0
#define DATA_REG_OFFSET		1

#define W83627EHF_REG_BANK		0x4E
#define W83627EHF_REG_CONFIG	0x40

/* The W83627EHF registers for nr=7,8,9 are in bank 5 */
#define W83627EHF_REG_IN_MAX(nr)	((nr < 7) ? (0x2b + (nr) * 2) : \
					 (0x554 + (((nr) - 7) * 2)))
#define W83627EHF_REG_IN_MIN(nr)	((nr < 7) ? (0x2c + (nr) * 2) : \
					 (0x555 + (((nr) - 7) * 2)))
#define W83627EHF_REG_IN(nr)		((nr < 7) ? (0x20 + (nr)) : \
					 (0x550 + (nr) - 7))

#define W83627EHF_REG_TEMP1		0x27									/*System temperature*/
#define W83627EHF_REG_TEMP1_HYST	0x3a
#define W83627EHF_REG_TEMP1_OVER	0x39

/* Fan clock dividers are spread over the following five registers */
#define W83627EHF_REG_FANDIV1		0x47
#define W83627EHF_REG_FANDIV2		0x4B
#define W83627EHF_REG_VBAT		0x5D
#define W83627EHF_REG_DIODE		0x59
#define W83627EHF_REG_SMI_OVT		0x4C

#define W83627EHF_REG_ALARM1		0x459
#define W83627EHF_REG_ALARM2		0x45A
#define W83627EHF_REG_ALARM3		0x45B

#define MAX_FAN_SPEED				1350000U

/*
 * Super-I/O constants and functions
 */

#define W83627EHF_LD_HWM	0x0b
#define W83667HG_LD_VID 	0x0d
#define HZ					200

#define SIO_REG_LDSEL		0x07	/* Logical device select */
#define SIO_REG_DEVID		0x20	/* Device ID (2 bytes) */
#define SIO_REG_EN_VRM10	0x2C	/* GPIO3, GPIO4 selection */
#define SIO_REG_ENABLE		0x30	/* Logical device enable */
#define SIO_REG_ADDR		0x60	/* Logical device address (2 bytes) */
#define SIO_REG_VID_CTRL	0xF0	/* VID control */
#define SIO_REG_VID_DATA	0xF1	/* VID data */


/* typedefs */

enum kinds { w83627ehf, w83627dhg, w83627dhg_p, w83667hg };

typedef struct w83627ehf_sio_data {
	int sioreg;
	enum kinds kind;
} SIO_DATA;

typedef struct w83627dhg_data {
	int addr;	/* IO base of hw monitor block */
	const char *name;

	struct device *hwmon_dev;

	char valid;		/* !=0 if following fields are valid */
	unsigned long last_updated;	/* In jiffies */

	/* Register values */
	UINT8 in_num;		/* number of in inputs we have */
	UINT8 in[10];		/* Register value */
	UINT8 in_max[10];		/* Register value */
	UINT8 in_min[10];		/* Register value */
	UINT8 fan[5];
	UINT8 fan_min[5];
	UINT8 fan_div[5];
	UINT8 has_fan;		/* some fan inputs can be disabled */
	UINT8 temp_type[3];
	INT8 temp1;
	INT8 temp1_max;
	INT8 temp1_max_hyst;
	INT16 temp[2];
	INT16 temp_max[2];
	INT16 temp_max_hyst[2];
	UINT32 alarms;

	UINT8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
	UINT8 pwm_enable[4]; /* 1->manual
			     2->thermal cruise (also called SmartFan I) */
	UINT8 pwm_num;		/* number of pwm */
	UINT8 pwm[4];
	UINT8 target_temp[4];
	UINT8 tolerance[4];

	UINT8 fan_min_output[4]; /* minimum fan speed */
	UINT8 fan_stop_time[4];

	UINT8 vid;
	UINT8 vrm;

	UINT8 temp3_disable;
	UINT8 in6_skip;
	SIO_DATA sio_data;
} W83627DHG_DATA;

METHOD_DECL(vxbTempGet);
METHOD_DECL(vxbTempGetMax);
METHOD_DECL(vxbTempGetHyst);
METHOD_DECL(sensorShow);
METHOD_DECL(vxbVoltageGet);
METHOD_DECL(vxbFanGet);
METHOD_DECL(vxbSetFanSpeed);

STATUS w83627dhgIoInit(void);



#ifdef __cplusplus
}
#endif

#endif /* __INCw83627dhgK_h */
