aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/tools/fan-limits.c
blob: 4000d5832b18d1c17c5cc36b40efdb8bdcba425e (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
//
// Copyright 2017 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0
//

#include "eeprom.h"
#include <stdio.h>
#include <stdlib.h>

void usage(char *argv[])
{
	printf("-- Usage -- \n");
	printf("%s fan0_min fan0_max fan1_min fan1_max\n\n", argv[0]);
	printf("Example:\n");
	printf("$ %s 3800 13000 3800 1300\n", argv[0]);
}

int main(int argc, char *argv[])
{
	struct usrp_sulfur_eeprom *ep;
	uint8_t fan0_max, fan0_min, fan1_max, fan1_min;
	uint32_t new_flags = 0;

	if (argc != 5) {
		usage(argv);
		return EXIT_FAILURE;
	}

	fan0_min = atoi(argv[1]) / 100;
	fan0_max = atoi(argv[2]) / 100;
	fan1_min = atoi(argv[3]) / 100;
	fan1_max = atoi(argv[4]) / 100;

	printf("Writing: %d/%d/%d/%d\n", fan0_min, fan0_max, fan1_min, fan1_max);

	ep = usrp_sulfur_eeprom_from_file(NVMEM_PATH_MB);
	ep->mcu_flags[0] = 0;
	ep->mcu_flags[1] = htonl(fan1_max << 24 | fan1_min << 16 | fan0_max << 8 | fan0_min);
	usrp_sulfur_eeprom_recrc(ep);
	usrp_sulfur_eeprom_to_i2c(ep, "/dev/i2c-2");


	free(ep);

	return 0;
}