libpayload: cmos: Move cmos access code out of libpayload.

Change-Id: Ib466d9f831e6cb6f677e57bc032b843d9e64593b
diff --git a/src/drivers/Kconfig b/src/drivers/Kconfig
index c66ac7d..740a082 100644
--- a/src/drivers/Kconfig
+++ b/src/drivers/Kconfig
@@ -26,6 +26,7 @@
 source src/drivers/gpio/Kconfig
 source src/drivers/keyboard/Kconfig
 source src/drivers/layout/Kconfig
+source src/drivers/misc/Kconfig
 source src/drivers/net/Kconfig
 source src/drivers/power/Kconfig
 source src/drivers/sound/Kconfig
diff --git a/src/drivers/Makefile.inc b/src/drivers/Makefile.inc
index cf0c4b1..95f0d5e 100644
--- a/src/drivers/Makefile.inc
+++ b/src/drivers/Makefile.inc
@@ -27,6 +27,7 @@
 subdirs-y += gpio
 subdirs-y += keyboard
 subdirs-y += layout
+subdirs-y += misc
 subdirs-y += net
 subdirs-y += power
 subdirs-y += ram
diff --git a/src/drivers/misc/Kconfig b/src/drivers/misc/Kconfig
new file mode 100644
index 0000000..cd8d7f0
--- /dev/null
+++ b/src/drivers/misc/Kconfig
@@ -0,0 +1,19 @@
+##
+## Copyright 2016 Google Inc.  All rights reserved.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; version 2 of the License.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+config DRIVER_MISC_CMOS
+	bool "Support for reading/writing CMOS bytes"
+	default n
diff --git a/src/drivers/misc/Makefile.inc b/src/drivers/misc/Makefile.inc
new file mode 100644
index 0000000..50e643e
--- /dev/null
+++ b/src/drivers/misc/Makefile.inc
@@ -0,0 +1,18 @@
+##
+## Copyright 2016 Google Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; version 2 of the License.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+##
+
+depthcharge-$(CONFIG_DRIVER_MISC_CMOS) += cmos.c
diff --git a/src/libpayload/drivers/nvram.c b/src/drivers/misc/cmos.c
similarity index 77%
rename from src/libpayload/drivers/nvram.c
rename to src/drivers/misc/cmos.c
index 88f6e0c..3c61193 100644
--- a/src/libpayload/drivers/nvram.c
+++ b/src/drivers/misc/cmos.c
@@ -38,7 +38,7 @@
  * http://www.bioscentral.com/misc/cmosmap.htm
  */
 
-#include <libpayload.h>
+#include <stdint.h>
 
 #include "base/io.h"
 
@@ -58,33 +58,24 @@
  * that coreboot has properly enabled access to the upper 128 bytes and
  * doesn't try to do this on its own.
  */
-#define RTC_PORT_STANDARD      0x70
-#define RTC_PORT_EXTENDED      0x72
 
-/**
- * Read a byte from the specified NVRAM address.
- *
- * @param addr The NVRAM address to read a byte from.
- * @return The byte at the given NVRAM address.
- */
-uint8_t nvram_read(uint8_t addr)
+enum {
+	Cmos_PortStandard = 0x70,
+	Cmos_PortExtended = 0x72,
+};
+
+uint8_t cmos_read(uint8_t addr)
 {
-	uint16_t rtc_port = addr < 128 ? RTC_PORT_STANDARD : RTC_PORT_EXTENDED;
+	uint16_t port = addr < 128 ? Cmos_PortStandard : Cmos_PortExtended;
 
-	outb(addr, rtc_port);
-	return inb(rtc_port + 1);
+	outb(addr, port);
+	return inb(port + 1);
 }
 
-/**
- * Write a byte to the specified NVRAM address.
- *
- * @param val The byte to write to NVRAM.
- * @param addr The NVRAM address to write to.
- */
-void nvram_write(uint8_t val, uint8_t addr)
+void cmos_write(uint8_t val, uint8_t addr)
 {
-	uint16_t rtc_port = addr < 128 ? RTC_PORT_STANDARD : RTC_PORT_EXTENDED;
+	uint16_t port = addr < 128 ? Cmos_PortStandard : Cmos_PortExtended;
 
-	outb(addr, rtc_port);
-	outb(val, rtc_port + 1);
+	outb(addr, port);
+	outb(val, port + 1);
 }
diff --git a/src/drivers/misc/cmos.h b/src/drivers/misc/cmos.h
new file mode 100644
index 0000000..8dba9d7
--- /dev/null
+++ b/src/drivers/misc/cmos.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __DRIVERS_MISC_CMOS_H__
+#define __DRIVERS_MISC_CMOS_H__
+
+#include <stdint.h>
+
+uint8_t cmos_read(uint8_t addr);
+void cmos_write(uint8_t val, uint8_t addr);
+
+#endif /* __DRIVERS_MISC_CMOS_H__ */
diff --git a/src/libpayload/Kconfig b/src/libpayload/Kconfig
index f4c12d1..49c8990 100644
--- a/src/libpayload/Kconfig
+++ b/src/libpayload/Kconfig
@@ -47,10 +47,6 @@
 	depends on ARCH_X86 # for now
 	default y
 
-config NVRAM
-	bool "Support for reading/writing NVRAM bytes"
-	default n
-
 config USB
 	bool "USB Support"
 	default n
diff --git a/src/libpayload/drivers/Makefile.inc b/src/libpayload/drivers/Makefile.inc
index b700339..81f151b 100644
--- a/src/libpayload/drivers/Makefile.inc
+++ b/src/libpayload/drivers/Makefile.inc
@@ -29,8 +29,6 @@
 
 depthcharge-$(CONFIG_PCI) += pci.c
 
-depthcharge-$(CONFIG_NVRAM) += nvram.c
-
 # USB stack
 depthcharge-$(CONFIG_USB) += usb/usbinit.c
 depthcharge-$(CONFIG_USB) += usb/usb.c
diff --git a/src/libpayload/include/libpayload.h b/src/libpayload/include/libpayload.h
index 29b8af9..779ac63 100644
--- a/src/libpayload/include/libpayload.h
+++ b/src/libpayload/include/libpayload.h
@@ -30,10 +30,7 @@
 
 #include <arch/types.h>
 
-uint8_t nvram_read(uint8_t addr);
-void nvram_write(uint8_t val, uint8_t addr);
-
 int usb_initialize(void);
-int usb_exit (void);
+int usb_exit(void);
 
 #endif
diff --git a/src/vboot/Kconfig b/src/vboot/Kconfig
index f808bfa..869605f 100644
--- a/src/vboot/Kconfig
+++ b/src/vboot/Kconfig
@@ -66,7 +66,7 @@
 config NV_STORAGE_CMOS
 	bool "CMOS"
 	depends on ARCH_X86
-	select NVRAM
+	select DRIVER_MISC_CMOS
 	help
 	  The nonvolatile data is stored in CMOS.
 
diff --git a/src/vboot/callbacks/nvstorage_cmos.c b/src/vboot/callbacks/nvstorage_cmos.c
index f60c26c..67c08e3 100644
--- a/src/vboot/callbacks/nvstorage_cmos.c
+++ b/src/vboot/callbacks/nvstorage_cmos.c
@@ -20,11 +20,12 @@
  * MA 02111-1307 USA
  */
 
-#include <libpayload.h>
 #include <stdio.h>
 #include <sysinfo.h>
 #include <vboot_api.h>
 
+#include "drivers/misc/cmos.h"
+
 VbError_t VbExNvStorageRead(uint8_t* buf)
 {
 	if (get_sysinfo()->vbnv_start == (uint32_t)(-1)) {
@@ -34,7 +35,7 @@
 	}
 
 	for (int i = 0; i < get_sysinfo()->vbnv_size; i++)
-		buf[i] = nvram_read(get_sysinfo()->vbnv_start + i);
+		buf[i] = cmos_read(get_sysinfo()->vbnv_start + i);
 
 	return VBERROR_SUCCESS;
 }
@@ -48,7 +49,7 @@
 	}
 
 	for (int i = 0; i < get_sysinfo()->vbnv_size; i++)
-		nvram_write(buf[i], get_sysinfo()->vbnv_start + i);
+		cmos_write(buf[i], get_sysinfo()->vbnv_start + i);
 
 	return VBERROR_SUCCESS;
 }