v3/ec: convert all printk to LOG or shell

Replace all calls to printk with either LOG_ERR or shell_fprintf, as
appropriate to the context.
Clean up order of includes.
Clean up formatting/indentation.

BUG=b:170980487
TEST=build and run

Change-Id: I05c484333204b93f623bd7d74f4bab6c5e578909
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/chameleon/+/2840687
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
diff --git a/v3/ec/src/fpgaboot.c b/v3/ec/src/fpgaboot.c
index 8034e6f..b10a6a5 100644
--- a/v3/ec/src/fpgaboot.c
+++ b/v3/ec/src/fpgaboot.c
@@ -9,13 +9,15 @@
 #include <device.h>
 #include <devicetree.h>
 #include <drivers/gpio.h>
+#include <logging/log.h>
 #include <shell/shell.h>
 #include <sys/__assert.h>
-#include <sys/printk.h>
 #include "io.h"
 #include "fpgaboot.h"
 #include "fpgaboot_sm.h"
 
+LOG_MODULE_REGISTER(fpgaboot);
+
 /**
  * FPGA state
  */
@@ -239,8 +241,8 @@
 					   gpio_get_pin(pwr_good),
 					   GPIO_INT_EDGE_BOTH);
 	if (ret != 0) {
-		printk("Error %d: failed to configure interrupt on PWR_GOOD\n",
-		       ret);
+		LOG_ERR("Error %d: failed to configure interrupt on PWR_GOOD\n",
+			ret);
 		return ret;
 	}
 	gpio_init_callback(&pwr_good_cb_data, pwr_good_cb,
@@ -252,8 +254,8 @@
 					   gpio_get_pin(fpga_done),
 					   GPIO_INT_EDGE_BOTH);
 	if (ret != 0) {
-		printk("Error %d: failed to configure interrupt on FPGA_DONE\n",
-		       ret);
+		LOG_ERR("Error %d: failed to configure interrupt on FPGA_DONE\n",
+			ret);
 		return ret;
 	}
 	gpio_init_callback(&fpga_done_cb_data, fpga_done_cb,
diff --git a/v3/ec/src/hotplug.c b/v3/ec/src/hotplug.c
index bee6b9a..d9ef398 100644
--- a/v3/ec/src/hotplug.c
+++ b/v3/ec/src/hotplug.c
@@ -13,7 +13,6 @@
 #include <drivers/i2c.h>
 #include <shell/shell.h>
 #include <sys/__assert.h>
-#include <sys/printk.h>
 #include "io.h"
 
 static int cmd_get(const struct shell *shell, size_t argc, char **argv)
diff --git a/v3/ec/src/i2c_switch.c b/v3/ec/src/i2c_switch.c
index 75137cf..ac66639 100644
--- a/v3/ec/src/i2c_switch.c
+++ b/v3/ec/src/i2c_switch.c
@@ -11,12 +11,14 @@
 #include <stdlib.h>
 #include <drivers/gpio.h>
 #include <drivers/i2c.h>
+#include <logging/log.h>
 #include <shell/shell.h>
 #include <sys/__assert.h>
-#include <sys/printk.h>
 #include "io.h"
 #include "i2c_switch.h"
 
+LOG_MODULE_REGISTER(i2c_switch);
+
 #define MAX7367_ADDR 0x73
 #define NUM_BUS 4
 
@@ -60,7 +62,7 @@
 
 	ret = gpio_set_level(exp_reset, val);
 	if (ret < 0) {
-		printk("gpio_set_level(exp_reset) failed, ret = %d\n", ret);
+		LOG_ERR("gpio_set_level(exp_reset) failed, ret = %d\n", ret);
 	}
 	return ret;
 }
@@ -112,7 +114,7 @@
 	i2c_dev = device_get_binding("I2C_1");
 
 	if (!i2c_dev) {
-		printk("%s: I2C_1 device not found.\n", __func__);
+		LOG_ERR("%s: I2C_1 device not found.\n", __func__);
 		return -ENODEV;
 	}
 
@@ -123,8 +125,8 @@
 					   gpio_get_pin(exp_irq),
 					   GPIO_INT_EDGE_FALLING);
 	if (ret != 0) {
-		printk("Error %d: failed to configure interrupt on exp_irq\n",
-		       ret);
+		LOG_ERR("Error %d: failed to configure interrupt on exp_irq\n",
+			ret);
 		return ret;
 	}
 	gpio_init_callback(&exp_irq_cb_data, exp_irq_cb,
diff --git a/v3/ec/src/io.c b/v3/ec/src/io.c
index abb6807..4baf479 100644
--- a/v3/ec/src/io.c
+++ b/v3/ec/src/io.c
@@ -9,12 +9,14 @@
 #include <device.h>
 #include <devicetree.h>
 #include <drivers/gpio.h>
+#include <logging/log.h>
 #include <shell/shell.h>
 #include <sys/__assert.h>
-#include <sys/printk.h>
 
 #include "io.h"
 
+LOG_MODULE_REGISTER(io);
+
 struct gpio_info {
 	const char *const label;
 	const char *const dev_name;
@@ -171,9 +173,9 @@
 		/* Look up the device by name. */
 		gpios[idx].dev = device_get_binding(gpios[idx].dev_name);
 		if (!gpios[idx].dev) {
-			printk("io_init_devices: "
-			       "device_get_binding(%s) failed!\n",
-			       gpios[idx].dev_name);
+			LOG_ERR("io_init_devices: "
+				"device_get_binding(%s) failed!\n",
+				gpios[idx].dev_name);
 			continue;
 		}
 
@@ -181,13 +183,13 @@
 		int ret = gpio_pin_configure(gpios[idx].dev, gpios[idx].pin,
 					     gpios[idx].flags);
 		if (ret != 0) {
-			printk("io_init_devices: "
-			       "gpio_pin_configure(%s(*%p), %d(\"%s\"), 0x%x) "
-			       "failed, ret = %d\n",
-			       gpios[idx].dev_name, gpios[idx].dev,
-			       gpios[idx].pin, gpios[idx].label,
-			       gpios[idx].flags, ret);
-                }
+			LOG_ERR("io_init_devices: "
+				"gpio_pin_configure(%s(*%p), %d(\"%s\"), 0x%x) "
+				"failed, ret = %d\n",
+				gpios[idx].dev_name, gpios[idx].dev,
+				gpios[idx].pin, gpios[idx].label,
+				gpios[idx].flags, ret);
+		}
 	}
 
 	/* Zephyr dynamic shell commands require a sorted list. */
@@ -262,19 +264,16 @@
 	if (argc == 1) {
 		/* No pin selected, do all */
 		for (enum gpio_signal signal = 0;
-		     signal < sizeof(gpios) / sizeof(gpios[0]);
-		     signal++) {
+		     signal < sizeof(gpios) / sizeof(gpios[0]); signal++) {
 			int alignment;
 			shell_fprintf(shell, SHELL_VT100_COLOR_DEFAULT,
-			              "(%s.%d)%n", // %s = %d
-			              gpios[signal].dev_name,
-			              gpios[signal].pin,
-			              &alignment);
+				      "(%s.%d)%n", // %s = %d
+				      gpios[signal].dev_name, gpios[signal].pin,
+				      &alignment);
 			shell_fprintf(shell, SHELL_VT100_COLOR_DEFAULT,
-			              "%*s = %d\n",
-			              40 - alignment,
-			              gpios[signal].label,
-			              gpio_get_level(signal));
+				      "%*s = %d\n", 40 - alignment,
+				      gpios[signal].label,
+				      gpio_get_level(signal));
 		}
 		return 0;
 	}
diff --git a/v3/ec/src/main.c b/v3/ec/src/main.c
index d7d5215..fe28b6f 100644
--- a/v3/ec/src/main.c
+++ b/v3/ec/src/main.c
@@ -6,16 +6,18 @@
  */
 
 #include <zephyr.h>
-#include <sys/printk.h>
+#include <logging/log.h>
 
 #include "io.h"
 
+LOG_MODULE_REGISTER(main);
+
 void main(void)
 {
 	int ret;
 
 	ret = gpio_set_level(power_good_led, 1);
 	if (ret < 0) {
-		printk("Failed to turn on POWER_GOOD, ret = %d.\n", ret);
+		LOG_ERR("Failed to turn on POWER_GOOD, ret = %d.\n", ret);
 	}
 }
diff --git a/v3/ec/src/sd.c b/v3/ec/src/sd.c
index 187b9bd..cab97d9 100644
--- a/v3/ec/src/sd.c
+++ b/v3/ec/src/sd.c
@@ -9,12 +9,14 @@
 #include <device.h>
 #include <devicetree.h>
 #include <drivers/gpio.h>
+#include <logging/log.h>
 #include <shell/shell.h>
 #include <sys/__assert.h>
-#include <sys/printk.h>
 #include "io.h"
 #include "sd.h"
 
+LOG_MODULE_REGISTER(sd);
+
 enum sd_state mux_state; /**< Currently selected state */
 
 int sd_mux_set(enum sd_state state)
@@ -46,25 +48,25 @@
 
 	ret = gpio_set_level(sd_mux_sel, mux_sel);
 	if (ret < 0) {
-		printk("gpio_set_level(sd_mux_sel) failed, ret = %d\n", ret);
+		LOG_ERR("gpio_set_level(sd_mux_sel) failed, ret = %d\n", ret);
 		return ret;
 	}
 
 	ret = gpio_set_level(sd_mux_en_l, mux_en);
 	if (ret < 0) {
-		printk("gpio_set_level(sd_mux_en+l) failed, ret = %d\n", ret);
+		LOG_ERR("gpio_set_level(sd_mux_en+l) failed, ret = %d\n", ret);
 		return ret;
 	}
 
 	ret = gpio_set_level(usd_pwr_sel, pwr_sel);
 	if (ret < 0) {
-		printk("gpio_set_level(usd_pwr_sel) failed, ret = %d\n", ret);
+		LOG_ERR("gpio_set_level(usd_pwr_sel) failed, ret = %d\n", ret);
 		return ret;
 	}
 
 	ret = gpio_set_level(usd_pwr_en, pwr_en);
 	if (ret < 0) {
-		printk("gpio_set_level(usd_pwr_en) failed, ret = %d\n", ret);
+		LOG_ERR("gpio_set_level(usd_pwr_en) failed, ret = %d\n", ret);
 		return ret;
 	}
 
@@ -140,22 +142,23 @@
 	ARG_UNUSED(argc);
 	ARG_UNUSED(argv);
 
-	printk("The SD mux is set to ");
+	shell_fprintf(shell, SHELL_NORMAL, "The SD mux is set to ");
 	switch (sd_mux_get()) {
 	case SD_MUX_OFF:
-		printk("disconnected\n");
+		shell_fprintf(shell, SHELL_NORMAL, "disconnected\n");
 		break;
 	case SD_MUX_FPGA:
-		printk("FPGA\n");
+		shell_fprintf(shell, SHELL_NORMAL, "FPGA\n");
 		break;
 	case SD_MUX_USB:
-		printk("USB\n");
+		shell_fprintf(shell, SHELL_NORMAL, "USB\n");
 		break;
 	default:
-		printk("invalid value, %d\n", (int)mux_state);
+		shell_fprintf(shell, SHELL_NORMAL, "invalid value, %d\n",
+			      (int)mux_state);
 	}
 
-	printk("CD_DET = %d\n", sd_get_cd_det());
+	shell_fprintf(shell, SHELL_NORMAL, "CD_DET = %d\n", sd_get_cd_det());
 
 	return 0;
 }
diff --git a/v3/ec/src/si5338.c b/v3/ec/src/si5338.c
index 1e7adcf..5ef634b 100644
--- a/v3/ec/src/si5338.c
+++ b/v3/ec/src/si5338.c
@@ -11,7 +11,9 @@
 #include <zephyr.h>
 #include <device.h>
 #include <drivers/i2c.h>
-#include <sys/printk.h>
+#include <logging/log.h>
+
+LOG_MODULE_REGISTER(si5338);
 
 /*
  * The generated header uses a non-standard keyword "code" to place the
@@ -99,7 +101,7 @@
 	const struct device *i2c_dev = device_get_binding("I2C_2");
 
 	if (!i2c_dev) {
-		printk("%s: I2C_2 device not found.\n", __func__);
+		LOG_ERR("%s: I2C_2 device not found.\n", __func__);
 		return -ENODEV;
 	}
 
diff --git a/v3/ec/src/sysmon.c b/v3/ec/src/sysmon.c
index 3a62fbe..7b144f6 100644
--- a/v3/ec/src/sysmon.c
+++ b/v3/ec/src/sysmon.c
@@ -10,11 +10,13 @@
 #include <devicetree.h>
 #include <drivers/adc.h>
 #include <drivers/gpio.h>
+#include <logging/log.h>
 #include <shell/shell.h>
-#include <sys/printk.h>
 #include "io.h"
 #include "sysmon.h"
 
+LOG_MODULE_REGISTER(sysmon);
+
 /**
  * Define the interval for the sysmon timer. Every SYSMON_INTERVAL, the
  * sysmon task will read the next ADC input in the sequence.
@@ -187,20 +189,20 @@
 				 .scale_factor = 1.0,
 				 .name = "SOM_VMON_C8" },
 	[SYSMON_SOM_VREF_CS1] = { .sel = SYSMON_SEL_SOM,
-				 .adc_num = 1,
-				 .channel = 6,
-				 .scale_factor = 1.0,
-				 .name = "VREF_CS1" },
+				  .adc_num = 1,
+				  .channel = 6,
+				  .scale_factor = 1.0,
+				  .name = "VREF_CS1" },
 	[SYSMON_SOM_VREF_CS2] = { .sel = SYSMON_SEL_SOM,
-				 .adc_num = 1,
-				 .channel = 7,
-				 .scale_factor = 1.0,
-				 .name = "VREF_CS2" },
+				  .adc_num = 1,
+				  .channel = 7,
+				  .scale_factor = 1.0,
+				  .name = "VREF_CS2" },
 	[SYSMON_SOM_VREF_CS3] = { .sel = SYSMON_SEL_SOM,
-				 .adc_num = 1,
-				 .channel = 8,
-				 .scale_factor = 1.0,
-				 .name = "VREF_CS3" },
+				  .adc_num = 1,
+				  .channel = 8,
+				  .scale_factor = 1.0,
+				  .name = "VREF_CS3" },
 
 };
 
@@ -331,8 +333,8 @@
 			sysmon_sel,
 			(scan_table[idx].sel == SYSMON_SEL_REGULATORS) ? 1 : 0);
 		if (ret < 0) {
-			printk("gpio_set_level(sysmon_sel) failed, ret = %d\n",
-			       ret);
+			LOG_ERR("gpio_set_level(sysmon_sel) failed, ret = %d\n",
+				ret);
 			continue;
 		}
 		if (adc_read(adc_list[scan_table[idx].adc_num].dev, &seq) < 0) {
@@ -386,15 +388,15 @@
 		adc_list[idx].dev =
 			device_get_binding(adc_list[idx].device_name);
 		if (adc_list[idx].dev == NULL) {
-			printk("Cannot get device %s\n",
-			       adc_list[idx].device_name);
+			LOG_ERR("Cannot get device %s\n",
+				adc_list[idx].device_name);
 			return -ENODEV;
 		}
 
 		ret = adc_channel_setup(adc_list[idx].dev,
 					&adc_list[idx].channel_config);
 		if (ret < 0) {
-			printk("adc_channel_setup failed, ret = %d\n", ret);
+			LOG_ERR("adc_channel_setup failed, ret = %d\n", ret);
 			return ret;
 		}
 	}
diff --git a/v3/ec/src/uart_tunnel.c b/v3/ec/src/uart_tunnel.c
index 120b4e4..84500b4 100644
--- a/v3/ec/src/uart_tunnel.c
+++ b/v3/ec/src/uart_tunnel.c
@@ -6,9 +6,8 @@
  */
 
 #include <zephyr.h>
-#include <shell/shell.h>
-#include <sys/printk.h>
 #include <drivers/uart.h>
+#include <shell/shell.h>
 
 const char *DEFAULT_UART = "UART_2";
 
@@ -18,7 +17,9 @@
 static int cmd_uart(const struct shell *shell, size_t argc, char **argv)
 {
 	const char **chosen_uart = &DEFAULT_UART;
-	if (argc > 1) *chosen_uart = argv[1];
+	if (argc > 1) {
+		*chosen_uart = argv[1];
+	}
 
 	const struct device *uart_device = device_get_binding(*chosen_uart);
 	if (!uart_device) {
@@ -27,20 +28,20 @@
 		return -EINVAL;
 	}
 
-	uint32_t baudrate=0;
+	uint32_t baudrate = 0;
 	uart_line_ctrl_get(uart_device, UART_LINE_CTRL_BAUD_RATE, &baudrate);
 	shell_fprintf(shell, SHELL_NORMAL,
 		      "Monitoring %s, baud %d (Press TODO to exit)...\n",
 		      *chosen_uart, baudrate);
 
 	char buf[16];
-	while(1) {
+	while (1) {
 		/*
 		 * TODO: Calling uart_fifo_read outside of an ISR might be bad
 		 * according to the docs, but I don't care enough to fix it
 		 * and it seems to work for now.
 		 */
-		int bytes = uart_fifo_read(uart_device, buf, sizeof(buf)-1);
+		int bytes = uart_fifo_read(uart_device, buf, sizeof(buf) - 1);
 		buf[bytes] = '\0';
 		shell_fprintf(shell, SHELL_NORMAL, "%s", buf);
 
diff --git a/v3/ec/src/videomux.c b/v3/ec/src/videomux.c
index 1191b08..97507c4 100644
--- a/v3/ec/src/videomux.c
+++ b/v3/ec/src/videomux.c
@@ -9,10 +9,13 @@
 #include <device.h>
 #include <devicetree.h>
 #include <drivers/gpio.h>
+#include <logging/log.h>
 #include <shell/shell.h>
 #include "io.h"
 #include "videomux.h"
 
+LOG_MODULE_REGISTER(videomux);
+
 int videomux_select(enum video_source_t src, enum video_dest_t dest)
 {
 	/* Check `sel` for validity. */
@@ -167,8 +170,8 @@
 				 gpio_get_pin(dp1_hdmi_rst_l),
 				 GPIO_OUTPUT_HIGH | GPIO_OPEN_DRAIN);
 	if (ret != 0) {
-		printk("Error %d: failed to configure dp1_hdmi_rst_l for open-drain\n",
-		       ret);
+		LOG_ERR("Error %d: failed to configure dp1_hdmi_rst_l for open-drain\n",
+			ret);
 		return ret;
 	}
 
@@ -176,8 +179,8 @@
 				 gpio_get_pin(dp2_hdmi_rst_l),
 				 GPIO_OUTPUT_HIGH | GPIO_OPEN_DRAIN);
 	if (ret != 0) {
-		printk("Error %d: failed to configure dp2_hdmi_rst_l for open-drain\n",
-		       ret);
+		LOG_ERR("Error %d: failed to configure dp2_hdmi_rst_l for open-drain\n",
+			ret);
 		return ret;
 	}
 
@@ -220,7 +223,8 @@
 		src = DP2;
 		shell_fprintf(shell, SHELL_NORMAL, "Connect DP2");
 	} else {
-		printk("Invalid source: '%s'\n", argv[-1]);
+		shell_fprintf(shell, SHELL_NORMAL, "Invalid source: '%s'\n",
+			      argv[-1]);
 		return -EINVAL;
 	}
 
@@ -231,7 +235,8 @@
 		dest = FPGA_MGT;
 		shell_fprintf(shell, SHELL_NORMAL, " to FPGA\n");
 	} else {
-		printk("Invalid destination: '%s'\n", argv[0]);
+		shell_fprintf(shell, SHELL_NORMAL,
+			      "Invalid destination: '%s'\n", argv[0]);
 		return -EINVAL;
 	}