162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * envctrl.h: Definitions for access to the i2c environment
562306a36Sopenharmony_ci *            monitoring on Ultrasparc systems.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
862306a36Sopenharmony_ci * Copyright (C) 2000  Vinh Truong  (vinh.truong@eng.sun.com)
962306a36Sopenharmony_ci * VT - Add all ioctl commands and environment status definitions
1062306a36Sopenharmony_ci * VT - Add application note
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci#ifndef _SPARC64_ENVCTRL_H
1362306a36Sopenharmony_ci#define _SPARC64_ENVCTRL_H 1
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <linux/ioctl.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* Application note:
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * The driver supports 4 operations: open(), close(), ioctl(), read()
2062306a36Sopenharmony_ci * The device name is /dev/envctrl.
2162306a36Sopenharmony_ci * Below is sample usage:
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci *	fd = open("/dev/envtrl", O_RDONLY);
2462306a36Sopenharmony_ci *	if (ioctl(fd, ENVCTRL_READ_SHUTDOWN_TEMPERATURE, 0) < 0)
2562306a36Sopenharmony_ci *		printf("error\n");
2662306a36Sopenharmony_ci *	ret = read(fd, buf, 10);
2762306a36Sopenharmony_ci *	close(fd);
2862306a36Sopenharmony_ci *
2962306a36Sopenharmony_ci * Notice in the case of cpu voltage and temperature, the default is
3062306a36Sopenharmony_ci * cpu0.  If we need to know the info of cpu1, cpu2, cpu3, we need to
3162306a36Sopenharmony_ci * pass in cpu number in ioctl() last parameter.  For example, to
3262306a36Sopenharmony_ci * get the voltage of cpu2:
3362306a36Sopenharmony_ci *
3462306a36Sopenharmony_ci *	ioctlbuf[0] = 2;
3562306a36Sopenharmony_ci *	if (ioctl(fd, ENVCTRL_READ_CPU_VOLTAGE, ioctlbuf) < 0)
3662306a36Sopenharmony_ci *		printf("error\n");
3762306a36Sopenharmony_ci *	ret = read(fd, buf, 10);
3862306a36Sopenharmony_ci *
3962306a36Sopenharmony_ci * All the return values are in ascii.  So check read return value
4062306a36Sopenharmony_ci * and do appropriate conversions in your application.
4162306a36Sopenharmony_ci */
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/* IOCTL commands */
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/* Note: these commands reflect possible monitor features.
4662306a36Sopenharmony_ci * Some boards choose to support some of the features only.
4762306a36Sopenharmony_ci */
4862306a36Sopenharmony_ci#define ENVCTRL_RD_CPU_TEMPERATURE	_IOR('p', 0x40, int)
4962306a36Sopenharmony_ci#define ENVCTRL_RD_CPU_VOLTAGE		_IOR('p', 0x41, int)
5062306a36Sopenharmony_ci#define ENVCTRL_RD_FAN_STATUS		_IOR('p', 0x42, int)
5162306a36Sopenharmony_ci#define ENVCTRL_RD_WARNING_TEMPERATURE	_IOR('p', 0x43, int)
5262306a36Sopenharmony_ci#define ENVCTRL_RD_SHUTDOWN_TEMPERATURE	_IOR('p', 0x44, int)
5362306a36Sopenharmony_ci#define ENVCTRL_RD_VOLTAGE_STATUS	_IOR('p', 0x45, int)
5462306a36Sopenharmony_ci#define ENVCTRL_RD_SCSI_TEMPERATURE	_IOR('p', 0x46, int)
5562306a36Sopenharmony_ci#define ENVCTRL_RD_ETHERNET_TEMPERATURE	_IOR('p', 0x47, int)
5662306a36Sopenharmony_ci#define ENVCTRL_RD_MTHRBD_TEMPERATURE	_IOR('p', 0x48, int)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define ENVCTRL_RD_GLOBALADDRESS	_IOR('p', 0x49, int)
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci/* Read return values for a voltage status request. */
6162306a36Sopenharmony_ci#define ENVCTRL_VOLTAGE_POWERSUPPLY_GOOD	0x01
6262306a36Sopenharmony_ci#define ENVCTRL_VOLTAGE_BAD			0x02
6362306a36Sopenharmony_ci#define ENVCTRL_POWERSUPPLY_BAD			0x03
6462306a36Sopenharmony_ci#define ENVCTRL_VOLTAGE_POWERSUPPLY_BAD		0x04
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci/* Read return values for a fan status request.
6762306a36Sopenharmony_ci * A failure match means either the fan fails or
6862306a36Sopenharmony_ci * the fan is not connected.  Some boards have optional
6962306a36Sopenharmony_ci * connectors to connect extra fans.
7062306a36Sopenharmony_ci *
7162306a36Sopenharmony_ci * There are maximum 8 monitor fans.  Some are cpu fans
7262306a36Sopenharmony_ci * some are system fans.  The mask below only indicates
7362306a36Sopenharmony_ci * fan by order number.
7462306a36Sopenharmony_ci * Below is a sample application:
7562306a36Sopenharmony_ci *
7662306a36Sopenharmony_ci *	if (ioctl(fd, ENVCTRL_READ_FAN_STATUS, 0) < 0) {
7762306a36Sopenharmony_ci *		printf("ioctl fan failed\n");
7862306a36Sopenharmony_ci *	}
7962306a36Sopenharmony_ci *	if (read(fd, rslt, 1) <= 0) {
8062306a36Sopenharmony_ci *		printf("error or fan not monitored\n");
8162306a36Sopenharmony_ci *	} else {
8262306a36Sopenharmony_ci *		if (rslt[0] == ENVCTRL_ALL_FANS_GOOD) {
8362306a36Sopenharmony_ci *			printf("all fans good\n");
8462306a36Sopenharmony_ci *	} else if (rslt[0] == ENVCTRL_ALL_FANS_BAD) {
8562306a36Sopenharmony_ci *		printf("all fans bad\n");
8662306a36Sopenharmony_ci *	} else {
8762306a36Sopenharmony_ci *		if (rslt[0] & ENVCTRL_FAN0_FAILURE_MASK) {
8862306a36Sopenharmony_ci *			printf("fan 0 failed or not connected\n");
8962306a36Sopenharmony_ci *	}
9062306a36Sopenharmony_ci *	......
9162306a36Sopenharmony_ci */
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci#define ENVCTRL_ALL_FANS_GOOD			0x00
9462306a36Sopenharmony_ci#define ENVCTRL_FAN0_FAILURE_MASK		0x01
9562306a36Sopenharmony_ci#define ENVCTRL_FAN1_FAILURE_MASK		0x02
9662306a36Sopenharmony_ci#define ENVCTRL_FAN2_FAILURE_MASK		0x04
9762306a36Sopenharmony_ci#define ENVCTRL_FAN3_FAILURE_MASK		0x08
9862306a36Sopenharmony_ci#define ENVCTRL_FAN4_FAILURE_MASK		0x10
9962306a36Sopenharmony_ci#define ENVCTRL_FAN5_FAILURE_MASK		0x20
10062306a36Sopenharmony_ci#define ENVCTRL_FAN6_FAILURE_MASK		0x40
10162306a36Sopenharmony_ci#define ENVCTRL_FAN7_FAILURE_MASK		0x80
10262306a36Sopenharmony_ci#define ENVCTRL_ALL_FANS_BAD 			0xFF
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#endif /* !(_SPARC64_ENVCTRL_H) */
105