[Feature]add MT2731_MP2_MR2_SVN388 baseline version

Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bsp/lk/include/dev/accelerometer.h b/src/bsp/lk/include/dev/accelerometer.h
new file mode 100644
index 0000000..343a68c
--- /dev/null
+++ b/src/bsp/lk/include/dev/accelerometer.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015 Eric Holland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_ACCELEROMETER_H
+#define __DEV_ACCELEROMETER_H
+typedef struct
+{
+        double x;
+        double y;
+        double z;
+} position_vector_t;
+
+status_t acc_read_xyz(position_vector_t * pos_vector);
+
+#endif
diff --git a/src/bsp/lk/include/dev/class/block.h b/src/bsp/lk/include/dev/class/block.h
new file mode 100644
index 0000000..240699d
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/block.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_BLOCK_H
+#define __DEV_CLASS_BLOCK_H
+
+#include <compiler.h>
+#include <dev/driver.h>
+
+/* block interface */
+struct block_ops {
+	struct driver_ops std;
+
+	ssize_t (*get_block_size)(struct device *dev);
+	ssize_t (*get_block_count)(struct device *dev);
+
+	ssize_t (*write)(struct device *dev, off_t offset, const void *buf, size_t count);
+	ssize_t (*read)(struct device *dev, off_t offset, void *buf, size_t count);
+	
+	status_t (*flush)(struct device *dev);
+};
+
+__BEGIN_CDECLS
+
+ssize_t class_block_get_size(struct device *dev);
+ssize_t class_block_get_count(struct device *dev);
+ssize_t class_block_write(struct device *dev, off_t offset, const void *buf, size_t count);
+ssize_t class_block_read(struct device *dev, off_t offset, void *buf, size_t count);
+status_t class_block_flush(struct device *dev);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/class/fb.h b/src/bsp/lk/include/dev/class/fb.h
new file mode 100644
index 0000000..e29b266
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/fb.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_FB_H
+#define __DEV_CLASS_FB_H
+
+#include <compiler.h>
+#include <dev/driver.h>
+
+struct fb_info {
+	void *addr;
+	size_t line_width;
+	size_t width;
+	size_t height;
+	size_t bpp;
+};
+
+/* fb interface */
+struct fb_ops {
+	struct driver_ops std;
+
+	status_t (*set_mode)(struct device *dev, size_t width, size_t height, size_t bpp);
+	status_t (*get_info)(struct device *dev, struct fb_info *info);
+	status_t (*update)(struct device *dev);
+	status_t (*update_region)(struct device *dev, size_t x, size_t y, size_t width, size_t height);
+};
+
+__BEGIN_CDECLS
+
+status_t class_fb_set_mode(struct device *dev, size_t width, size_t height, size_t bpp);
+status_t class_fb_get_info(struct device *dev, struct fb_info *info);
+status_t class_fb_update(struct device *dev);
+status_t class_fb_update_region(struct device *dev, size_t x, size_t y, size_t width, size_t height);
+
+__END_CDECLS
+
+#endif
+
+
diff --git a/src/bsp/lk/include/dev/class/i2c.h b/src/bsp/lk/include/dev/class/i2c.h
new file mode 100644
index 0000000..d38fbcb
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/i2c.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_I2C_H
+#define __DEV_CLASS_I2C_H
+
+#include <compiler.h>
+#include <dev/driver.h>
+
+/* i2c interface */
+struct i2c_ops {
+	struct driver_ops std;
+
+	status_t (*write)(struct device *dev, uint8_t addr, const void *buf, size_t len);
+	status_t (*read)(struct device *dev, uint8_t addr, void *buf, size_t len);
+
+	status_t (*write_reg)(struct device *dev, uint8_t addr, uint8_t reg, uint8_t value);
+	status_t (*read_reg)(struct device *dev, uint8_t addr, uint8_t reg, void *value);
+};
+
+__BEGIN_CDECLS
+
+status_t class_i2c_write(struct device *dev, uint8_t addr, const void *buf, size_t len);
+status_t class_i2c_read(struct device *dev, uint8_t addr, void *buf, size_t len);
+status_t class_i2c_write_reg(struct device *dev, uint8_t addr, uint8_t reg, uint8_t value);
+status_t class_i2c_read_reg(struct device *dev, uint8_t addr, uint8_t reg, void *value);
+
+__END_CDECLS
+
+#endif
diff --git a/src/bsp/lk/include/dev/class/netif.h b/src/bsp/lk/include/dev/class/netif.h
new file mode 100644
index 0000000..099b40c
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/netif.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_NETIF_H
+#define __DEV_CLASS_NETIF_H
+
+#include <list.h>
+#include <compiler.h>
+#include <dev/driver.h>
+
+struct netstack_state;
+struct pbuf;
+
+/* netif interface */
+struct netif_ops {
+	struct driver_ops std;
+
+	status_t (*set_state)(struct device *dev, struct netstack_state *state);
+	ssize_t (*get_hwaddr)(struct device *dev, void *buf, size_t max_len);
+	ssize_t (*get_mtu)(struct device *dev);
+
+	status_t (*set_status)(struct device *dev, bool up);
+	status_t (*output)(struct device *dev, struct pbuf *p);
+	status_t (*mcast_filter)(struct device *dev, const uint8_t *mac, int action);
+};
+
+__BEGIN_CDECLS
+
+/* netif API */
+status_t class_netif_set_state(struct device *dev, struct netstack_state *state);
+ssize_t class_netif_get_hwaddr(struct device *dev, void *buf, size_t max_len);
+ssize_t class_netif_get_mtu(struct device *dev);
+status_t class_netif_set_status(struct device *dev, bool up);
+status_t class_netif_output(struct device *dev, struct pbuf *p);
+status_t class_netif_mcast_filter(struct device *dev, const uint8_t *mac, int action);
+
+status_t class_netif_add(struct device *dev);
+
+/* network stack API - called by drivers */
+status_t class_netstack_input(struct device *dev, struct netstack_state *state, struct pbuf *p);
+
+status_t class_netstack_wait_for_network(lk_time_t timeout);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/class/spi.h b/src/bsp/lk/include/dev/class/spi.h
new file mode 100644
index 0000000..dad8959
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/spi.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_SPI_H
+#define __DEV_CLASS_SPI_H
+
+#include <compiler.h>
+#include <dev/driver.h>
+
+/* spi transaction flags */
+enum spi_flags {
+	SPI_READ        = (1<<0),
+	SPI_WRITE       = (1<<1),
+	SPI_CS_ASSERT   = (1<<2),
+	SPI_CS_DEASSERT = (1<<3),
+};
+
+/* spi transaction */
+struct spi_transaction {
+	enum spi_flags flags;
+	void *tx_buf;
+	void *rx_buf;
+	size_t len;
+};
+
+/* spi interface */
+struct spi_ops {
+	struct driver_ops std;
+
+	ssize_t (*transaction)(struct device *dev, struct spi_transaction *txn, size_t count);
+};
+
+__BEGIN_CDECLS
+
+ssize_t class_spi_transaction(struct device *dev, struct spi_transaction *txn, size_t count);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/class/uart.h b/src/bsp/lk/include/dev/class/uart.h
new file mode 100644
index 0000000..aabf101
--- /dev/null
+++ b/src/bsp/lk/include/dev/class/uart.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_CLASS_UART_H
+#define __DEV_CLASS_UART_H
+
+#include <dev/driver.h>
+
+/* uart interface */
+struct uart_ops {
+	struct driver_ops std;
+
+	ssize_t (*read)(struct device *dev, void *buf, size_t len);
+	ssize_t (*write)(struct device *dev, const void *buf, size_t len);
+};
+
+
+ssize_t class_uart_read(struct device *dev, void *buf, size_t len);
+ssize_t class_uart_write(struct device *dev, const void *buf, size_t len);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/display.h b/src/bsp/lk/include/dev/display.h
new file mode 100644
index 0000000..5da46b8
--- /dev/null
+++ b/src/bsp/lk/include/dev/display.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008-2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_DISPLAY_H
+#define __DEV_DISPLAY_H
+
+#include <stdbool.h>
+#include <lib/gfx.h>
+
+int display_init(void *framebuffer);
+int display_enable(bool enable);
+void display_pre_freq_change(void);
+void display_post_freq_change(void);
+
+struct display_info {
+	void *framebuffer;
+	gfx_format format;
+	uint width;
+	uint height;
+	uint stride;
+
+	// Update function
+	void (*flush)(uint starty, uint endy);
+};
+
+status_t display_get_info(struct display_info *info);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/driver.h b/src/bsp/lk/include/dev/driver.h
new file mode 100644
index 0000000..787a593
--- /dev/null
+++ b/src/bsp/lk/include/dev/driver.h
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2012 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_DRIVER_H
+#define __DEV_DRIVER_H
+
+#include <sys/types.h>
+#include <list.h> // for containerof
+#include <compiler.h>
+
+struct driver;
+
+/*
+ * Contains the data pertaining to an instance of a device. More than one
+ * instance may exist for a given driver type (i.e. uart0, uart1, etc..).
+ */
+struct device {
+	const char *name;
+	const struct driver *driver;
+
+	/* instance specific config data populated at instantiation */
+	const void *config;
+
+	/* instance specific data populated by the driver at init */
+	void *state;
+	
+	// TODO: add generic state, such as suspend/resume state, etc...
+};
+
+/* device class, mainly used as a unique magic pointer to validate ops */
+struct device_class {
+	const char *name;
+};
+
+/* standard driver ops; extensions should contain this ops structure */
+struct driver_ops {
+	const struct device_class *device_class;
+
+	status_t (*init)(struct device *dev);
+	status_t (*fini)(struct device *dev);
+
+	status_t (*suspend)(struct device *dev);
+	status_t (*resume)(struct device *dev);
+};
+
+/* describes a driver, one per driver type */
+struct driver {
+	const char *type;
+	const struct driver_ops *ops;
+};
+
+#define DRIVER_EXPORT(type_, ops_) \
+	const struct driver concat(__driver_, type_) \
+		__ALIGNED(sizeof(void *)) __SECTION(".drivers") = { \
+		.type = #type_, \
+		.ops = ops_, \
+	}
+
+#define DEVICE_INSTANCE(type_, name_, config_) \
+	extern struct driver concat(__driver_, type_); \
+	struct device concat(__device_, concat(type_, concat(_, name_))) \
+		__ALIGNED(sizeof(void *)) __SECTION(".devices") = { \
+		.name = #name_, \
+		.driver = &concat(__driver_, type_), \
+		.config = config_, \
+	}
+
+/*
+ * returns the driver specific ops pointer given the device instance, specifc
+ * ops type, and generic ops member name within the specific ops structure.
+ */
+#define device_get_driver_ops(dev, type, member) ({ \
+	type *__ops = NULL; \
+	if (dev && dev->driver && dev->driver->ops) \
+		__ops = containerof(dev->driver->ops, type, member); \
+	__ops; \
+})
+
+#define device_get_by_name(type_, name_) ({ \
+	extern struct device concat(__device_, concat(type_, concat(_, name_))); \
+	&concat(__device_, concat(type_, concat(_, name_))); \
+})
+
+status_t device_init_all(void);
+status_t device_fini_all(void);
+
+status_t device_init(struct device *dev);
+status_t device_fini(struct device *dev);
+
+status_t device_suspend(struct device *dev);
+status_t device_resume(struct device *dev);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/ethernet.h b/src/bsp/lk/include/dev/ethernet.h
new file mode 100644
index 0000000..7042cea
--- /dev/null
+++ b/src/bsp/lk/include/dev/ethernet.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_ETHERNET_H
+#define __DEV_ETHERNET_H
+
+#include <sys/types.h>
+
+/* Queue an ethernet frame for send.
+**
+** CRC and minimum length padding are handled by the driver.
+**
+** Data is malloc()'d and ownership is transfered to the ethernet
+** device which will free() it once the packet is transmitted.
+**
+*/
+int ethernet_send(void *data, unsigned length);
+
+status_t ethernet_init(void); /* initialize the ethernet device */
+
+#endif
diff --git a/src/bsp/lk/include/dev/fbcon.h b/src/bsp/lk/include/dev/fbcon.h
new file mode 100644
index 0000000..131f093
--- /dev/null
+++ b/src/bsp/lk/include/dev/fbcon.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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 __DEV_FBCON_H
+#define __DEV_FBCON_H
+
+#define FB_FORMAT_RGB565 0
+
+struct fbcon_config {
+	void        *base;
+	unsigned    width;
+	unsigned    height;
+	unsigned    stride;
+	unsigned    bpp;
+	unsigned    format;
+
+	void        (*update_start)(void);
+	int     (*update_done)(void);
+};
+
+void fbcon_setup(struct fbcon_config *cfg);
+void fbcon_putc(char c);
+
+#endif /* __DEV_FBCON_H */
diff --git a/src/bsp/lk/include/dev/flash_nor.h b/src/bsp/lk/include/dev/flash_nor.h
new file mode 100644
index 0000000..5d74636
--- /dev/null
+++ b/src/bsp/lk/include/dev/flash_nor.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_FLASH_NOR_H
+#define __DEV_FLASH_NOR_H
+
+#include <sys/types.h>
+
+struct flash_nor_bank {
+	addr_t base;
+	size_t len;
+	size_t page_size;
+	uint flags;
+};
+
+#define FLASH_NOR_FLAG_NONE 0
+
+const struct flash_nor_bank *flash_nor_get_bank(unsigned int bank);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/gpio.h b/src/bsp/lk/include/dev/gpio.h
new file mode 100644
index 0000000..0f2c972
--- /dev/null
+++ b/src/bsp/lk/include/dev/gpio.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * Copyright (c) 2012, Travis Geiselbrecht
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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 __DEV_GPIO_H
+#define __DEV_GPIO_H
+
+enum gpio_flags {
+    GPIO_INPUT      = (1 << 0),
+    GPIO_OUTPUT     = (1 << 1),
+    GPIO_LEVEL      = (1 << 2),
+    GPIO_EDGE       = (1 << 3),
+    GPIO_RISING     = (1 << 4),
+    GPIO_FALLING    = (1 << 5),
+    GPIO_HIGH       = (1 << 6),
+    GPIO_LOW        = (1 << 7),
+    GPIO_PULLUP     = (1 << 8),
+    GPIO_PULLDOWN   = (1 << 9),
+};
+
+/* top 16 bits of the gpio flags are platform specific */
+#define GPIO_PLATFORM_MASK 0xffff0000
+
+int gpio_config(unsigned nr, unsigned flags);
+void gpio_set(unsigned nr, unsigned on);
+int gpio_get(unsigned nr);
+
+#endif
diff --git a/src/bsp/lk/include/dev/gpio_i2c.h b/src/bsp/lk/include/dev/gpio_i2c.h
new file mode 100644
index 0000000..59403be
--- /dev/null
+++ b/src/bsp/lk/include/dev/gpio_i2c.h
@@ -0,0 +1,57 @@
+/* vim: set expandtab ts=4 sw=4 tw=100: */
+/*
+ * Copyright (c) 2013 Google Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __GPIO_I2C__
+#define __GPIO_I2C__
+
+#include <stdint.h>
+#include <dev/i2c.h>
+
+typedef struct gpio_i2c_info {
+    const int sda;
+    const int scl;
+    uint32_t  hcd;  /* 1/2 I2C clock delay in cpu cycles */
+    uint32_t  qcd;  /* 1/4 I2C clock delay in cpu cycles */
+} gpio_i2c_info_t;
+
+#define DEFINE_GPIO_I2C(_name,                 \
+                        _sda_gpio_id,          \
+                        _scl_gpio_id,          \
+                        _clk_ticks)            \
+static const gpio_i2c_info_t _name = {         \
+    .sda            = _sda_gpio_id,            \
+    .scl            = _scl_gpio_id,            \
+    .hcd            = ((_clk_ticks + 1) >> 1), \
+    .qcd            = ((_clk_ticks + 3) >> 2), \
+}
+
+void gpio_i2c_add_bus(uint32_t bus_id, const gpio_i2c_info_t* info);
+
+void gpio_i2c_init_early(void);
+void gpio_i2c_init(void);
+status_t gpio_i2c_transmit(int, uint8_t, const void*, size_t);
+status_t gpio_i2c_receive(int, uint8_t, void*, size_t);
+status_t gpio_i2c_write_reg_bytes(int, uint8_t, uint8_t, const uint8_t*, size_t);
+status_t gpio_i2c_read_reg_bytes(int, uint8_t, uint8_t, uint8_t*, size_t);
+
+#endif  // __GPIO_I2C__
diff --git a/src/bsp/lk/include/dev/gpio_keypad.h b/src/bsp/lk/include/dev/gpio_keypad.h
new file mode 100644
index 0000000..445e65a
--- /dev/null
+++ b/src/bsp/lk/include/dev/gpio_keypad.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *  * Neither the name of Google, Inc. nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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 __DEV_GPIO_KEYPAD_H
+#define __DEV_GPIO_KEYPAD_H
+
+#include <sys/types.h>
+
+/* unset: drive active output low, set: drive active output high */
+#define GPIOKPF_ACTIVE_HIGH     (1U << 0)
+#define GPIOKPF_DRIVE_INACTIVE      (1U << 1)
+
+struct gpio_keypad_info {
+	/* size must be ninputs * noutputs */
+	const uint16_t *keymap;
+	unsigned *input_gpios;
+	unsigned *output_gpios;
+	int ninputs;
+	int noutputs;
+	/* time to wait before reading inputs after driving each output */
+	time_t settle_time;
+	time_t poll_time;
+	unsigned flags;
+};
+
+void gpio_keypad_init(struct gpio_keypad_info *kpinfo);
+
+#endif /* __DEV_GPIO_KEYPAD_H */
diff --git a/src/bsp/lk/include/dev/i2c.h b/src/bsp/lk/include/dev/i2c.h
new file mode 100644
index 0000000..68ed008
--- /dev/null
+++ b/src/bsp/lk/include/dev/i2c.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_I2C_H
+#define __DEV_I2C_H
+
+#include <stdint.h>
+
+#include <stddef.h>		// size_t
+#include <sys/types.h>	// status_t
+
+void i2c_init(void);
+void i2c_init_early(void);
+
+/* Notes about I2C addresses
+ * + Currently, there is no API support for 10-bit I2C addresses.  7-bit only.
+ * + Addresses should be supplied as the actual 7-bit address of the device.
+ *   The platform driver is responsible for left shifting this address by 1 and
+ *   suppling the appropriate value for the R/W bit.
+ */
+
+/* send and receive blocks of data */
+status_t i2c_transmit(int bus, uint8_t address, const void *buf, size_t count);
+status_t i2c_receive(int bus, uint8_t address, void *buf, size_t count);
+
+/* A few convenience routines based on the usual way of accessing registers on
+ * i2c slave devices.
+ */
+status_t i2c_write_reg_bytes(int bus, uint8_t address, uint8_t reg, const uint8_t* val, size_t cnt);
+status_t i2c_read_reg_bytes(int bus, uint8_t address, uint8_t reg, uint8_t *val, size_t cnt);
+
+static inline status_t i2c_write_reg(int bus, uint8_t address, uint8_t reg, uint8_t val)
+{
+	return i2c_write_reg_bytes(bus, address, reg, &val, 1);
+}
+
+static inline status_t i2c_read_reg(int bus, uint8_t address, uint8_t reg, uint8_t *val)
+{
+	return i2c_read_reg_bytes(bus, address, reg, val, 1);
+}
+#endif
+
diff --git a/src/bsp/lk/include/dev/keys.h b/src/bsp/lk/include/dev/keys.h
new file mode 100644
index 0000000..165505a
--- /dev/null
+++ b/src/bsp/lk/include/dev/keys.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *  * Neither the name of Google, Inc. nor the names of its contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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 __DEV_KEYS_H
+#define __DEV_KEYS_H
+
+#include <sys/types.h>
+
+/* these are just the ascii values for the chars */
+#define KEY_0       0x30
+#define KEY_1       0x31
+#define KEY_2       0x32
+#define KEY_3       0x33
+#define KEY_4       0x34
+#define KEY_5       0x35
+#define KEY_6       0x36
+#define KEY_7       0x37
+#define KEY_8       0x38
+#define KEY_9       0x39
+
+#define KEY_A       0x61
+
+#define KEY_ESC     0x100
+#define KEY_F1      0x101
+#define KEY_F2      0x102
+#define KEY_F3      0x103
+#define KEY_F4      0x104
+#define KEY_F5      0x105
+#define KEY_F6      0x106
+#define KEY_F7      0x107
+#define KEY_F8      0x108
+#define KEY_F9      0x109
+
+#define KEY_LEFT    0x110
+#define KEY_RIGHT   0x111
+#define KEY_UP      0x112
+#define KEY_DOWN    0x113
+#define KEY_CENTER  0x114
+
+#define KEY_VOLUMEUP    0x115
+#define KEY_VOLUMEDOWN  0x116
+#define KEY_MUTE    0x117
+
+#define KEY_SOFT1   0x11a
+#define KEY_SOFT2   0x11b
+#define KEY_STAR    0x11c
+#define KEY_SHARP   0x11d
+#define KEY_MAIL    0x11e
+
+#define KEY_SEND    0x120
+#define KEY_CLEAR   0x121
+#define KEY_HOME    0x122
+#define KEY_BACK    0x123
+
+#define MAX_KEYS    0x1ff
+
+void keys_init(void);
+void keys_post_event(uint16_t code, int16_t value);
+int keys_get_state(uint16_t code);
+
+#endif /* __DEV_KEYS_H */
diff --git a/src/bsp/lk/include/dev/pci.h b/src/bsp/lk/include/dev/pci.h
new file mode 100644
index 0000000..ec64d147
--- /dev/null
+++ b/src/bsp/lk/include/dev/pci.h
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2009 Corey Tabaka
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __PCI_H
+#define __PCI_H
+
+#include <sys/types.h>
+#include <compiler.h>
+
+/*
+ * PCI access return codes
+ */
+#define _PCI_SUCCESSFUL             0x00
+#define _PCI_FUNC_NOT_SUPPORTED     0x81
+#define _PCI_BAD_VENDOR_ID          0x83
+#define _PCI_DEVICE_NOT_FOUND       0x86
+#define _PCI_BAD_REGISTER_NUMBER    0x87
+#define _PCI_SET_FAILED             0x88
+#define _PCI_BUFFER_TOO_SMALL       0x89
+
+/*
+ * PCI configuration space offsets
+ */
+#define PCI_CONFIG_VENDOR_ID        0x00
+#define PCI_CONFIG_DEVICE_ID        0x02
+#define PCI_CONFIG_COMMAND          0x04
+#define PCI_CONFIG_STATUS           0x06
+#define PCI_CONFIG_REVISION_ID      0x08
+#define PCI_CONFIG_CLASS_CODE       0x09
+#define PCI_CONFIG_CLASS_CODE_INTR  0x09
+#define PCI_CONFIG_CLASS_CODE_SUB   0x0a
+#define PCI_CONFIG_CLASS_CODE_BASE  0x0b
+#define PCI_CONFIG_CACHE_LINE_SIZE  0x0c
+#define PCI_CONFIG_LATENCY_TIMER    0x0d
+#define PCI_CONFIG_HEADER_TYPE      0x0e
+#define PCI_CONFIG_BIST             0x0f
+#define PCI_CONFIG_BASE_ADDRESSES   0x10
+#define PCI_CONFIG_CARDBUS_CIS_PTR  0x28
+#define PCI_CONFIG_SUBSYS_VENDOR_ID 0x2c
+#define PCI_CONFIG_SUBSYS_ID        0x2e
+#define PCI_CONFIG_EXP_ROM_ADDRESS  0x30
+#define PCI_CONFIG_CAPABILITIES     0x34
+#define PCI_CONFIG_INTERRUPT_LINE   0x3c
+#define PCI_CONFIG_INTERRUPT_PIN    0x3d
+#define PCI_CONFIG_MIN_GRANT        0x3e
+#define PCI_CONFIG_MAX_LATENCY      0x3f
+
+/*
+ * PCI header type register bits
+ */
+#define PCI_HEADER_TYPE_MASK        0x7f
+#define PCI_HEADER_TYPE_MULTI_FN    0x80
+
+/*
+ * PCI header types
+ */
+#define PCI_HEADER_TYPE_STANDARD    0x00
+#define PCI_HEADER_TYPE_PCI_BRIDGE  0x01
+#define PCI_HEADER_TYPE_CARD_BUS    0x02
+
+/*
+ * PCI command register bits
+ */
+#define PCI_COMMAND_IO_EN           0x0001
+#define PCI_COMMAND_MEM_EN          0x0002
+#define PCI_COMMAND_BUS_MASTER_EN   0x0004
+#define PCI_COMMAND_SPECIAL_EN      0x0008
+#define PCI_COMMAND_MEM_WR_INV_EN   0x0010
+#define PCI_COMMAND_PAL_SNOOP_EN    0x0020
+#define PCI_COMMAND_PERR_RESP_EN    0x0040
+#define PCI_COMMAND_AD_STEP_EN      0x0080
+#define PCI_COMMAND_SERR_EN         0x0100
+#define PCI_COMMAND_FAST_B2B_EN     0x0200
+
+/*
+ * PCI status register bits
+ */
+#define PCI_STATUS_NEW_CAPS         0x0010
+#define PCI_STATUS_66_MHZ           0x0020
+#define PCI_STATUS_FAST_B2B         0x0080
+#define PCI_STATUS_MSTR_PERR        0x0100
+#define PCI_STATUS_DEVSEL_MASK      0x0600
+#define PCI_STATUS_TARG_ABORT_SIG   0x0800
+#define PCI_STATUS_TARG_ABORT_RCV   0x1000
+#define PCI_STATUS_MSTR_ABORT_RCV   0x2000
+#define PCI_STATUS_SERR_SIG         0x4000
+#define PCI_STATUS_PERR             0x8000
+
+typedef struct {
+	uint16_t vendor_id;
+	uint16_t device_id;
+	uint16_t command;
+	uint16_t status;
+	uint8_t revision_id_0;
+	uint8_t program_interface;
+	uint8_t sub_class;
+	uint8_t base_class;
+	uint8_t cache_line_size;
+	uint8_t latency_timer;
+	uint8_t header_type;
+	uint8_t bist;
+	uint32_t base_addresses[6];
+	uint32_t cardbus_cis_ptr;
+	uint16_t subsystem_vendor_id;
+	uint16_t subsystem_id;
+	uint32_t expansion_rom_address;
+	uint8_t capabilities_ptr;
+	uint8_t reserved_0[3];
+	uint32_t reserved_1;
+	uint8_t interrupt_line;
+	uint8_t interrupt_pin;
+	uint8_t min_grant;
+	uint8_t max_latency;
+} __PACKED pci_config_t;
+
+/*
+ * PCI address structure
+ */
+typedef struct {
+	uint8_t bus;
+	uint8_t dev_fn;
+} pci_location_t;
+
+typedef struct {
+	uint8_t id;
+	uint8_t next;
+} __PACKED pci_capability_t;
+
+typedef struct {
+	uint8_t bus;
+	uint8_t device;
+	uint8_t link_int_a;
+	uint16_t irq_int_a;
+	uint8_t link_int_b;
+	uint16_t irq_int_b;
+	uint8_t link_int_c;
+	uint16_t irq_int_c;
+	uint8_t link_int_d;
+	uint16_t irq_int_d;
+	uint8_t slot;
+	uint8_t reserved;
+} __PACKED irq_routing_entry;
+
+void pci_init(void);
+
+int pci_get_last_bus(void);
+
+int pci_find_pci_device(pci_location_t *state, uint16_t device_id, uint16_t vendor_id, uint16_t index);
+int pci_find_pci_class_code(pci_location_t *state, uint32_t class_code, uint16_t index);
+
+int pci_read_config_byte(const pci_location_t *state, uint32_t reg, uint8_t *value);
+int pci_read_config_half(const pci_location_t *state, uint32_t reg, uint16_t *value);
+int pci_read_config_word(const pci_location_t *state, uint32_t reg, uint32_t *value);
+
+int pci_write_config_byte(const pci_location_t *state, uint32_t reg, uint8_t value);
+int pci_write_config_half(const pci_location_t *state, uint32_t reg, uint16_t value);
+int pci_write_config_word(const pci_location_t *state, uint32_t reg, uint32_t value);
+
+int pci_get_irq_routing_options(irq_routing_entry *entries, uint16_t *count, uint16_t *pci_irqs);
+int pci_set_irq_hw_int(const pci_location_t *state, uint8_t int_pin, uint8_t irq);
+
+#endif
diff --git a/src/bsp/lk/include/dev/uart.h b/src/bsp/lk/include/dev/uart.h
new file mode 100644
index 0000000..db35ee1
--- /dev/null
+++ b/src/bsp/lk/include/dev/uart.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008-2015 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_UART_H
+#define __DEV_UART_H
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+void uart_init_early(void);
+
+int uart_putc(int port, char c);
+int uart_getc(int port, bool wait);
+void uart_flush_tx(int port);
+void uart_flush_rx(int port);
+void uart_init_port(int port, uint baud);
+
+/* panic-time uart accessors, intended to be run with interrupts disabled */
+int uart_pputc(int port, char c);
+int uart_pgetc(int port);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/udc.h b/src/bsp/lk/include/dev/udc.h
new file mode 100644
index 0000000..84d4783
--- /dev/null
+++ b/src/bsp/lk/include/dev/udc.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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 __DEV_UDC_H
+#define __DEV_UDC_H
+
+#include <stdint.h>
+
+typedef struct udc_request udc_request_t;
+typedef struct udc_gadget udc_gadget_t;
+typedef struct udc_device udc_device_t;
+
+/* endpoints are opaque handles specific to the particular device controller */
+typedef struct udc_endpoint udc_endpoint_t;
+
+/* USB Device Controller Transfer Request */
+struct udc_request {
+	void *buffer;
+	unsigned length;
+	void (*complete)(udc_request_t *req, unsigned actual, int status);
+	void *context;
+};
+
+udc_request_t *udc_request_alloc(void);
+void udc_request_free(udc_request_t *req);
+int udc_request_queue(udc_endpoint_t *ept, udc_request_t *req);
+int udc_request_cancel(udc_endpoint_t *ept, udc_request_t *req);
+
+#define UDC_BULK_IN    0x82
+#define UDC_BULK_OUT   0x02
+
+udc_endpoint_t *udc_endpoint_alloc(unsigned type, unsigned maxpkt);
+void udc_endpoint_free(udc_endpoint_t *ept);
+
+#define UDC_EVENT_ONLINE    1
+#define UDC_EVENT_OFFLINE   2
+
+struct udc_gadget {
+	void (*notify)(udc_gadget_t *gadget, unsigned event);
+	void *context;
+
+	struct udc_gadget *next; // do not modify
+
+	uint8_t ifc_class;
+	uint8_t ifc_subclass;
+	uint8_t ifc_protocol;
+	uint8_t ifc_endpoints;
+	const char *ifc_string;
+	unsigned flags;
+
+	udc_endpoint_t **ept;
+};
+
+struct udc_device {
+	uint16_t vendor_id;
+	uint16_t product_id;
+	uint16_t version_id;
+
+	const char *manufacturer;
+	const char *product;
+	const char *serialno;
+};
+
+int udc_init(udc_device_t *devinfo);
+int udc_register_gadget(udc_gadget_t *gadget);
+int udc_start(void);
+int udc_stop(void);
+
+#endif
diff --git a/src/bsp/lk/include/dev/usb.h b/src/bsp/lk/include/dev/usb.h
new file mode 100644
index 0000000..de91da7
--- /dev/null
+++ b/src/bsp/lk/include/dev/usb.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_USB_H
+#define __DEV_USB_H
+
+#include <sys/types.h>
+#include <compiler.h>
+
+/* top level initialization for usb client, abstracts away the interfaces */
+typedef struct {
+    void *desc;
+    size_t len;
+    uint flags;
+} usb_descriptor __ALIGNED(2);
+
+#define USB_DESC_FLAG_STATIC (0x1)
+
+#define USB_DESC_STATIC(x) { .desc = (void *)(x), .len = sizeof(x), .flags = USB_DESC_FLAG_STATIC }
+
+typedef struct {
+    usb_descriptor string;
+    uint8_t id;
+} usb_string;
+
+/* complete usb config struct, passed in to usb_setup() */
+typedef struct {
+    struct usb_descriptor_speed {
+        usb_descriptor device;
+        usb_descriptor device_qual;
+        usb_descriptor config;
+    } lowspeed, highspeed;
+    usb_descriptor langid;
+} usb_config;
+
+/* external code needs to set up the usb stack via the following calls */
+status_t usb_setup(usb_config *config);
+
+/* apped new interface descriptors to the existing config if desired */
+status_t usb_append_interface_highspeed(const uint8_t *int_descr, size_t len);
+status_t usb_append_interface_lowspeed(const uint8_t *int_descr, size_t len);
+
+status_t usb_add_string(const char *string, uint8_t id);
+
+status_t usb_start(void);
+status_t usb_stop(void);
+
+/* callbacks from usbc and usb layers */
+typedef enum {
+    USB_CB_RESET,
+    USB_CB_SUSPEND,
+    USB_CB_RESUME,
+    USB_CB_DISCONNECT,
+    USB_CB_ONLINE,
+    USB_CB_OFFLINE,
+    USB_CB_SETUP_MSG,
+} usb_callback_op_t;
+
+/* setup arg is valid during CB_SETUP_MSG */
+union usb_callback_args {
+    const struct usb_setup *setup;
+};
+
+typedef status_t (*usb_callback_t)(void *cookie, usb_callback_op_t op, const union usb_callback_args *args);
+
+/* callback api the usbc driver uses */
+status_t usbc_callback(usb_callback_op_t op, const union usb_callback_args *args);
+
+/* callback api that anyone can register for */
+status_t usb_register_callback(usb_callback_t, void *cookie);
+
+#endif
+
diff --git a/src/bsp/lk/include/dev/usbc.h b/src/bsp/lk/include/dev/usbc.h
new file mode 100644
index 0000000..7a12280
--- /dev/null
+++ b/src/bsp/lk/include/dev/usbc.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __DEV_USBC_H
+#define __DEV_USBC_H
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <hw/usb.h>
+
+void usbc_init(void);
+
+typedef uint ep_t;
+
+typedef enum {
+    USB_IN = 0,
+    USB_OUT
+} ep_dir_t;
+
+struct usbc_transfer;
+typedef status_t (*ep_callback)(ep_t endpoint, struct usbc_transfer *transfer);
+
+typedef struct usbc_transfer {
+    ep_callback callback;
+    status_t result;
+    void *buf;
+    size_t buflen;
+    uint bufpos;
+    void *extra; // extra pointer to store whatever you want
+} usbc_transfer_t;
+
+enum {
+    USB_TRANSFER_RESULT_OK = 0,
+    USB_TRANSFER_RESULT_ERR = -1,
+    USB_TRANSFER_RESULT_CANCELLED = -2,
+};
+
+status_t usbc_setup_endpoint(ep_t ep, ep_dir_t dir, uint width);
+status_t usbc_queue_rx(ep_t ep, usbc_transfer_t *transfer);
+status_t usbc_queue_tx(ep_t ep, usbc_transfer_t *transfer);
+
+status_t usbc_set_active(bool active);
+void usbc_set_address(uint8_t address);
+
+/* called back from within a callback to handle setup responses */
+void usbc_ep0_ack(void);
+void usbc_ep0_stall(void);
+void usbc_ep0_send(const void *buf, size_t len, size_t maxlen);
+void usbc_ep0_recv(void *buf, size_t len, ep_callback);
+
+bool usbc_is_highspeed(void);
+
+static inline void usbc_dump_transfer(const usbc_transfer_t *t)
+{
+    printf("usb transfer %p: cb %p buf %p, buflen %zd, bufpos %u, result %d\n", t, t->callback, t->buf, t->buflen, t->bufpos, t->result);
+}
+
+#endif
+