summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f66fa93)
raw | patch | inline | side by side (parent: f66fa93)
author | Hao Zhang <hzhang@ti.com> | |
Thu, 4 Dec 2014 20:17:51 +0000 (15:17 -0500) | ||
committer | Hao Zhang <hzhang@ti.com> | |
Thu, 4 Dec 2014 20:17:51 +0000 (15:17 -0500) |
The log info is saved to /var/log/srss.log.
Signed-off-by: Hao Zhang <hzhang@ti.com>
Signed-off-by: Hao Zhang <hzhang@ti.com>
src/srss_tc.c | patch | blob | history |
diff --git a/src/srss_tc.c b/src/srss_tc.c
index ddbb8e7a5501a44d76a1a0e2477b33ea7fc489db..6dcc614528a45f24e1ac65e56bc1614b6cfdd01f 100644 (file)
--- a/src/srss_tc.c
+++ b/src/srss_tc.c
*
*/
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
if (++i == argc || ((arg = argv[i])[0] == '-' && \
!isdigit ((int)arg[1]) )) \
{ \
- fprintf (stderr, "missing argument to option '%s'\n", A); \
+ srss_log(LOG_STDOUT | LOG_FILE, "missing argument to option '%s'\n", A); \
exit (1); \
}
+/* SRSS logging definitions */
+
+/* log type */
+#define LOG_STDOUT 1
+#define LOG_FILE 2
+
+#define MAX_PRE_LOG_BUF_LEN 4096
+#define DEFAULT_LOG_LEN 0x800000
+#define SRSS_LOG_FILE_NAME "/var/log/srss.log"
+
static int debug = 0;
+/* srss logging utility */
+static char srss_log_buf[MAX_PRE_LOG_BUF_LEN];
+static FILE *srss_log_fp = NULL;
+void srss_log(int log_type, const char* format, ...)
+{
+ int len;
+ va_list args;
+ struct stat fbuf;
+
+ srss_log_buf[0] = 0;
+
+ len = MAX_PRE_LOG_BUF_LEN - strlen(srss_log_buf);
+ if (len <= 0)
+ return;
+
+ va_start(args, format);
+ vsnprintf(&srss_log_buf[strlen(srss_log_buf)], len, format, args);
+ va_end(args);
+
+ if (srss_log_fp && (log_type & LOG_FILE)) {
+ /* logfile reset if going over max_len */
+ fstat(fileno(srss_log_fp), &fbuf);
+ if ((fbuf.st_size + strlen(srss_log_buf)) > DEFAULT_LOG_LEN)
+ freopen(SRSS_LOG_FILE_NAME, "w+", srss_log_fp);
+
+ fprintf(srss_log_fp, "%s", srss_log_buf);
+ fflush(srss_log_fp);
+ }
+ if (log_type & LOG_STDOUT) {
+ fprintf(stdout, "%s", srss_log_buf);
+ fflush(stdout);
+ }
+}
+
inline uint32_t srss_read_reg(int fd, uint32_t addr)
{
uint32_t data;
#define PMBUS_VOUT_COMMAND 0x21
#define PMBUS_READ_VOUT 0x8b
static uint32_t vout_wr = 0;
- /* Vout in PMBus format, Vout (Volt) = vout_pmbus[vid]/512,
- * e.g. vid = 0, Vout = 0x0166 / 512 = 0.699 (Volt) */
+/* Vout in PMBus format, Vout (Volt) = vout_pmbus[vid]/512,
+ * e.g. vid = 0, Vout = 0x0166 / 512 = 0.699 (Volt) */
static int srss_c0_tc_isr(int fd_srss, uint32_t addr, int fd_i2c)
{
uint32_t vid, srss_event, data, i;
};
srss_event = srss_read_reg(fd_srss, addr + SRSS_EVENT_FLAG);
- if (debug) {
- fprintf(stdout, "\n SRSS Event flag reg 0x%x\n", srss_event);
- fflush(stdout);
- }
+ if (debug)
+ srss_log(LOG_STDOUT | LOG_FILE, "\n SRSS Event flag reg 0x%x\n", srss_event);
if (srss_event & SRSS_EVENT_THRPT) {
/* temperature thresh point interrupt event */
vid = (srss_read_reg(fd_srss, addr + SRSS_TEMP_STAT1) >> 24)
& 0x3f;
- if (debug) {
- fprintf(stdout, "\n SRSS temp stat0 0x%x, stat1 0x%x.\n",
+ if (debug)
+ srss_log(LOG_STDOUT | LOG_FILE, "\n SRSS temp stat0 0x%x, stat1 0x%x.\n",
srss_read_reg(fd_srss, addr + SRSS_TEMP_STAT0),
srss_read_reg(fd_srss, addr + SRSS_TEMP_STAT1));
- fflush(stdout);
- }
+
for (i = 0; i < I2C_RETRY_COUNT; i++) {
if (i2c_smbus_write_i2c_block_data(fd_i2c,
PMBUS_VOUT_COMMAND, 2, vout_pmbus[vid]) == 0)
break;
}
if (i == I2C_RETRY_COUNT) {
- fprintf(stderr, "\n Error sending VOUT_COMMAND "
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error sending VOUT_COMMAND "
"PMBus command.\n");
- fflush(stderr);
return -1;
}
+
if (debug) {
- fprintf(stdout, "\n Vout write: %x %x, vid: 0x%x\n",
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Vout write: %x %x, vid: 0x%x\n",
vout_pmbus[vid][0], vout_pmbus[vid][1], vid);
- vout_wr = (vout_pmbus[vid][1] << 8) + \
- vout_pmbus[vid][0];
+ vout_wr = (vout_pmbus[vid][1] << 8) + vout_pmbus[vid][0];
}
/* clear the temperature thresh point interrupt event */
fpr = fopen(filename, "r");
if (!fpr) {
- fprintf(stderr, "\n Error opening file %s (%s)",
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error opening file %s (%s)",
filename, strerror(errno));
- fflush(stderr);
goto close_n_exit;
}
if (!fgets(str, str_len, fpr)) {
- fprintf(stderr, "\n Error reading file %s (%s)",
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error reading file %s (%s)",
filename, strerror(errno));
- fflush(stderr);
goto close_n_exit;
}
fp = fopen(file_name, "rb");
if (!fp) {
- fprintf(stderr, "\n Error opening file %s (%s)",
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error opening file %s (%s)",
file_name, strerror(errno));
- fflush(stderr);
return -1;
}
if (!fread(buf, sizeof(int), size, fp)) {
- fprintf(stderr, "\n Error reading file %s (%s)",
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error reading file %s (%s)",
file_name, strerror(errno));
- fflush(stderr);
fclose(fp);
return -1;
}
@@ -319,15 +356,13 @@ int uioutil_get_device (char *uio_name, char *class_name, int class_name_length)
char *name_ptr;
if (!uio_name || !class_name || !strlen(uio_name)) {
- fprintf(stderr, "\n Error in call to function");
- fflush(stderr);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error in call to function");
goto close_n_exit;
}
dir = opendir("/sys/class/uio");
if (!dir) {
- fprintf(stdout, "\n readdir /sys/class/uio");
- fflush(stdout);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n readdir /sys/class/uio");
goto close_n_exit;
}
{
char *mesg = "%s %s\n";
- fprintf (stdout, mesg, prog_name, SRSS_TC_VERSION);
+ srss_log(LOG_STDOUT, mesg, prog_name, SRSS_TC_VERSION);
exit(1);
}
" -p, --pc_addr N external power controller I2C slave device address\n"
"Example: %s --i2c 2 --pc_addr 9 --verbose\n\n";
- fprintf (stdout, mesg, prog_name, prog_name, prog_name);
+ srss_log(LOG_STDOUT, mesg, prog_name, prog_name, prog_name);
exit(1);
}
slave_addr = atoi(arg);
}
else {
- fprintf(stderr, "unrecognized option: %s\n", arg);
- fflush(stderr);
+ srss_log(LOG_STDOUT, "unrecognized option: %s\n", arg);
exit (-1);
}
}
- fprintf(stdout, "\n SoC I2C bus number: %d", i2c_num);
- fprintf(stdout, "\n External power controller I2C slave address: %d",
+
+ srss_log_fp = fopen(SRSS_LOG_FILE_NAME, "w+");
+ if (!srss_log_fp)
+ printf("Error in opening log file %s (%s)", SRSS_LOG_FILE_NAME, strerror(errno));
+
+ srss_log(LOG_STDOUT | LOG_FILE, "\n SoC I2C bus number: %d", i2c_num);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n External power controller I2C slave address: %d",
slave_addr);
- fflush(stdout);
/* Open the UIO SRSS device */
snprintf(dev_name, MAX_NAME_LENGTH, "/dev/%s", srss_dev);
fd_srss = open (dev_name, (O_RDWR | O_SYNC));
if (fd_srss < 0) {
- fprintf(stderr, "\n Error opening SRSS device %s", dev_name);
- fflush(stderr);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error opening SRSS device %s", dev_name);
goto end_close;
}
- if (debug) {
- fprintf(stdout, "\n Opened device %s, fd: %d\n", dev_name, fd_srss);
- fflush(stdout);
- }
+ if (debug)
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Opened device %s, fd: %d\n", dev_name, fd_srss);
ret = uioutil_get_device(srss_dev, class_name, 32);
if ( ret < 0 ) {
- fprintf(stderr, "\n Error getting uio device %s", srss_dev);
- fflush(stderr);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error getting uio device %s", srss_dev);
goto end_close1;
}
- if (debug) {
- fprintf(stdout, "\n Class name: %s\n", class_name);
- fflush(stdout);
- }
+ if (debug)
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Class name: %s\n", class_name);
snprintf(dev_name, MAX_NAME_LENGTH, "/dev/%s", class_name);
fd_uio = open (dev_name, (O_RDWR | O_SYNC));
if (fd_uio < 0) {
- fprintf(stderr, "\n Error opening uio device %s", dev_name);
- fflush(stderr);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error opening uio device %s", dev_name);
goto end_close1;
}
- if (debug) {
- fprintf(stdout, "\n Opened device %s, fd: %d\n", dev_name, fd_uio);
- fflush(stdout);
- }
+ if (debug)
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Opened device %s, fd: %d\n", dev_name, fd_uio);
FD_ZERO(&fds);
FD_SET(fd_uio, &fds);
snprintf(dev_name, MAX_LINE_LENGTH, "/dev/i2c-%d", i2c_num);
fd_i2c = open(dev_name, O_RDWR);
if (fd_i2c < 0) {
- fprintf(stderr, "\n Error opening i2c device %s", dev_name);
- fflush(stderr);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error opening i2c device %s", dev_name);
goto end_close2;
}
- if (debug) {
- fprintf(stdout, "\n Opened device %s, fd: %d\n", dev_name, fd_i2c);
- fflush(stdout);
- }
+ if (debug)
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Opened device %s, fd: %d\n", dev_name, fd_i2c);
/* Set the I2C slave device address */
if(ioctl(fd_i2c, I2C_SLAVE, slave_addr) < 0) {
- fprintf(stderr, "\n Failed to set slave address: %d, error: %s\n",
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Failed to set slave address: %d, error: %s\n",
slave_addr, strerror(errno));
- fflush(stderr);
goto end_close3;
}
/* Enable I2C checksum */
if(ioctl(fd_i2c, I2C_PEC, 1) < 0) {
- fprintf(stderr, "\n Failed to enable I2C PEC");
- fflush(stderr);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Failed to enable I2C PEC");
goto end_close3;
}
/* Check if SRSS C0 TC is enabled during boot-up */
if (!srss_c0_tc_enabled(fd_srss, base_addr)) {
- fprintf(stdout, "\n SRSS Class 0 TC disabled, "
+ srss_log(LOG_STDOUT | LOG_FILE, "\n SRSS Class 0 TC disabled, "
"no temperature compensation.\n");
- fflush(stdout);
goto end_close3;
}
value = 1;
ret = write(fd_uio, &value, sizeof(uint32_t));
if (ret != sizeof(uint32_t)) {
- fprintf(stderr, "\n unable to enable interrupt ");
- fflush(stderr);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n unable to enable interrupt ");
goto end_close3;
}
for(;;) {
if (debug) {
- fprintf(stdout, "\n waiting for interrupt...\n");
- fflush(stdout);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n waiting for interrupt...\n");
if (vout_wr) {
usleep(1000000); /* wait for 1 sec to read
back Vout */
break;
}
if (i == I2C_RETRY_COUNT) {
- fprintf(stderr, "\n Error sending READ_VOUT "
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Error sending READ_VOUT "
"PMBus command.\n");
- fflush(stderr);
goto end_close4;
}
- fprintf(stdout, "\n Vout read: %x %x\n",
+ srss_log(LOG_STDOUT | LOG_FILE, "\n Vout read: %x %x\n",
vout_rb[0], vout_rb[1]);
vout_rd = (vout_rb[1] << 8) + vout_rb[0];
if (vout_wr > vout_rd)
vout_diff = vout_wr - vout_rd;
else
vout_diff = vout_rd - vout_wr;
- if (vout_diff < 3) {
- fprintf (stdout, "\n PMBus Vout write value "
+ if (vout_diff < 3)
+ srss_log(LOG_STDOUT | LOG_FILE, "\n PMBus Vout write value "
"matches with Vout read value!\n");
- fflush(stdout);
- }
+
}
}
ret = select(FD_SETSIZE, &fds, NULL, NULL, NULL);
if (ret == -1) {
- fprintf(stderr, "\n select failed for monitor (error: %s)",
+ srss_log(LOG_STDOUT | LOG_FILE, "\n select failed for monitor (error: %s)",
strerror(errno));
- fflush(stderr);
goto end_close4;
}
if (debug)
if (debug) {
clock_gettime(CLOCK_MONOTONIC, &tp_end2);
delta_time = clock_diff(&tp_end1, &tp_end2);
- fprintf(stdout, "\n interrupt response time %d ns",delta_time);
- fflush(stdout);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n interrupt response time %d ns",delta_time);
}
}
value = 0;
ret = write(fd_uio, &value, sizeof(uint32_t));
if (ret != sizeof(uint32_t)) {
- fprintf(stderr, "\n unable to disable interrupt ");
- fflush(stderr);
+ srss_log(LOG_STDOUT | LOG_FILE, "\n unable to disable interrupt ");
}
end_close3:
close(fd_i2c);