summaryrefslogtreecommitdiff
path: root/drivers/misc/fsl_dcm.h
blob: 722ac28a4d3aa56e2d9f132bb2d335b0c73470bc (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef _FSL_DCM_H
#define _FSL_DCM_H

/* sysfs commands for 'control' */
#define SYSFS_DCM_CMD_STOP	0
#define SYSFS_DCM_CMD_START	1

#define MAX_NAME_LEN		10
#define MAX_FREQUENCY		48		/* max freq the DCM supports */
#define DATA_ADDR			0x20	/* data address in DCM SRAM */
#define CHAN_MASK			0x1FF	/* 9 channel is enabled */

/* PIXIS register status bits */
#define PX_OCMD_MSG	(1 << 0)
#define PX_OACK_ERR	(1 << 1)
#define PX_OACK_ACK	(1 << 0)	/* OACK is sometimes called MACK */

/* DCM commands */
#define OM_END			0x00
#define OM_SETDLY		0x01
#define OM_RST0			0x02
#define OM_RST1			0x03
#define OM_CHKDLY		0x04
#define OM_PWR			0x05
#define OM_WAKE			0x07
#define OM_GETMEM		0x08
#define OM_SETMEM		0x09
#define OM_SCLR			0x10
#define OM_START		0x11
#define OM_STOP			0x12
#define OM_GET			0x13
#define OM_ENABLE		0x14
#define OM_TIMER		0x15
#define OM_SNAP			0x16
#define OM_GETMEMX		0x18
#define OM_AVGOFF		0x19
#define OM_AVGON		0x1A
#define OM_SETV			0x30
#define OM_INFO			0x31
#define OM_XINFO		0x32

/* Support definitions */
#define CRCTLBIT_ENA        (7)	/* Set to enable collection */
#define CRCTLBIT_IGNORE     (6)	/* Ignore record for voltage mangement */
#define CRCTLBIT_FILTER     (5)	/* Set to enable data filtering */
#define CRCTLBIT_GET_V2     (4)	/* Record type: voltage via INA220 */
#define CRCTLBIT_GET_I2     (3)	/* Record type: current via INA220 */
#define CRCTLBIT_GET_T      (2)	/* Record type: temperature via ADT7461 */
#define CRCTLBIT_GET_I      (1)	/* Record type: current via PMBus device */
#define CRCTLBIT_GET_V      (0)	/* Record type: voltage via PMBus device */

/* Bitmasks */
#define CRCTL_ENA           (1 << CRCTLBIT_ENA)
#define CRCTL_IGNORE        (1 << CRCTLBIT_IGNORE)
#define CRCTL_FILTER        (1 << CRCTLBIT_FILTER)
#define CRCTL_GET_V2        (1 << CRCTLBIT_GET_V2)
#define CRCTL_GET_I2        (1 << CRCTLBIT_GET_I2)
#define CRCTL_GET_T         (1 << CRCTLBIT_GET_T)
#define CRCTL_GET_I         (1 << CRCTLBIT_GET_I)
#define CRCTL_GET_V         (1 << CRCTLBIT_GET_V)

/* Handy definitions */
#define CR_VOLT_PMB         (CRCTL_ENA|CRCTL_FILTER|CRCTL_GET_V)
#define CR_VOLT_PMB_X       (CRCTL_ENA|CRCTL_FILTER|CRCTL_GET_V|CRCTL_IGNORE)
#define CR_CURR_PMB         (CRCTL_ENA|CRCTL_FILTER|CRCTL_GET_I)
#define CR_VOLT_INA         (CRCTL_ENA|CRCTL_GET_V2)
#define CR_CURR_INA         (CRCTL_ENA|CRCTL_GET_I2)
#define CR_TEMP             (CRCTL_ENA|CRCTL_FILTER|CRCTL_GET_T)

struct crecord {
	u8		ctl;			/* enabled, data type */
	u8		i2c_addr;		/* target i2c address */
	u8		port;			/* target port(channel) */
	__be16	curr;			/* most recent sample */
	__be16	max;			/* maximum value */
	__be16	num1;			/* number of samples taken */
	u8		num2;
	__be32	accum;			/* sum of samples */
	__be16	xinfo_addr;		/* pointer to XINFO structure */
} __packed;

struct om_info {
	__be16	ver;			/* DCM version number */
	u8		prescale;		/* prescale value used */
	u8		timer;			/* timer */
	u8		count;			/* number of CRECORDS */
	__be16	addr;			/* address of CRECORD array in SRAM */
	u8		res[3];
} __packed;

struct om_xinfo {
	__be16	name_addr;		/* descriptive name */
	__be16	def;			/* SW-defined default */
	__be16	curr;			/* SW-obtained value */
	__be16	cal;			/* calibration factor */
	u8		flags;
	u8		method;
	__be16	get;			/* get current value */
	__be16	set;			/* set voltage to value */
	__be16	init;			/* initialize device */
} __packed;

struct record {
	char	*name;			/* record name */
	char	*unit;			/* record unit */
};

struct dcm_board {
	struct	om_info info;
	struct	record *rec;	/* per record struct */
	struct	crecord *crec;	/* all the collected records */
	u32		shunt;			/* shunt for ina220 current */
	u32		mask;			/* channel mask */
};

struct fsl_dcm_data {
	void __iomem	*base;	/* PIXIS/QIXIS base address */
	struct device	*dev;
	u8 __iomem		*addr;	/* SRAM address */
	u8 __iomem		*data;	/* SRAM data */
	u8 __iomem		*ocmd;	/* DCM command/status */
	u8 __iomem		*omsg;	/* DCM message */
	u8 __iomem		*mack;	/* DCM acknowledge */
	u8				timer;
	int				running;
	struct dcm_board board;
};

#endif