[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bsp/lk/dev/class/block_api.c b/src/bsp/lk/dev/class/block_api.c
new file mode 100644
index 0000000..014eaba
--- /dev/null
+++ b/src/bsp/lk/dev/class/block_api.c
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+#include <err.h>
+#include <dev/class/block.h>
+
+ssize_t class_block_get_size(struct device *dev)
+{
+ struct block_ops *ops = device_get_driver_ops(dev, struct block_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->get_block_size)
+ return ops->get_block_size(dev);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+ssize_t class_block_get_count(struct device *dev)
+{
+ struct block_ops *ops = device_get_driver_ops(dev, struct block_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->get_block_count)
+ return ops->get_block_count(dev);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+ssize_t class_block_write(struct device *dev, off_t offset, const void *buf, size_t count)
+{
+ struct block_ops *ops = device_get_driver_ops(dev, struct block_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->write)
+ return ops->write(dev, offset, buf, count);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+ssize_t class_block_read(struct device *dev, off_t offset, void *buf, size_t count)
+{
+ struct block_ops *ops = device_get_driver_ops(dev, struct block_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->read)
+ return ops->read(dev, offset, buf, count);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_block_flush(struct device *dev)
+{
+ struct block_ops *ops = device_get_driver_ops(dev, struct block_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->flush)
+ return ops->flush(dev);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
diff --git a/src/bsp/lk/dev/class/fb_api.c b/src/bsp/lk/dev/class/fb_api.c
new file mode 100644
index 0000000..314442e
--- /dev/null
+++ b/src/bsp/lk/dev/class/fb_api.c
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#include <err.h>
+#include <dev/class/fb.h>
+
+status_t class_fb_set_mode(struct device *dev, size_t width, size_t height, size_t bpp)
+{
+ struct fb_ops *ops = device_get_driver_ops(dev, struct fb_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->set_mode)
+ return ops->set_mode(dev, width, height, bpp);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_fb_get_info(struct device *dev, struct fb_info *info)
+{
+ struct fb_ops *ops = device_get_driver_ops(dev, struct fb_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->get_info)
+ return ops->get_info(dev, info);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_fb_update(struct device *dev)
+{
+ struct fb_ops *ops = device_get_driver_ops(dev, struct fb_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->update)
+ return ops->update(dev);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_fb_update_region(struct device *dev, size_t x, size_t y, size_t width, size_t height)
+{
+ struct fb_ops *ops = device_get_driver_ops(dev, struct fb_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->update_region)
+ return ops->update_region(dev, x, y, width, height);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
diff --git a/src/bsp/lk/dev/class/i2c_api.c b/src/bsp/lk/dev/class/i2c_api.c
new file mode 100644
index 0000000..60e2a8a
--- /dev/null
+++ b/src/bsp/lk/dev/class/i2c_api.c
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#include <err.h>
+#include <dev/class/i2c.h>
+
+status_t class_i2c_write(struct device *dev, uint8_t addr, const void *buf, size_t len)
+{
+ struct i2c_ops *ops = device_get_driver_ops(dev, struct i2c_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->write)
+ return ops->write(dev, addr, buf, len);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_i2c_read(struct device *dev, uint8_t addr, void *buf, size_t len)
+{
+ struct i2c_ops *ops = device_get_driver_ops(dev, struct i2c_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->read)
+ return ops->read(dev, addr, buf, len);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_i2c_write_reg(struct device *dev, uint8_t addr, uint8_t reg, uint8_t value)
+{
+ struct i2c_ops *ops = device_get_driver_ops(dev, struct i2c_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->write_reg)
+ return ops->write_reg(dev, addr, reg, value);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_i2c_read_reg(struct device *dev, uint8_t addr, uint8_t reg, void *value)
+{
+ struct i2c_ops *ops = device_get_driver_ops(dev, struct i2c_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->read_reg)
+ return ops->read_reg(dev, addr, reg, value);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
diff --git a/src/bsp/lk/dev/class/netif_api.c b/src/bsp/lk/dev/class/netif_api.c
new file mode 100644
index 0000000..87d617b
--- /dev/null
+++ b/src/bsp/lk/dev/class/netif_api.c
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+#include <err.h>
+#include <dev/class/netif.h>
+
+status_t class_netif_set_state(struct device *dev, struct netstack_state *state)
+{
+ struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->set_state)
+ return ops->set_state(dev, state);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+ssize_t class_netif_get_hwaddr(struct device *dev, void *buf, size_t max_len)
+{
+ struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->get_hwaddr)
+ return ops->get_hwaddr(dev, buf, max_len);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+ssize_t class_netif_get_mtu(struct device *dev)
+{
+ struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->get_mtu)
+ return ops->get_mtu(dev);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_netif_set_status(struct device *dev, bool up)
+{
+ struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->set_status)
+ return ops->set_status(dev, up);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_netif_output(struct device *dev, struct pbuf *p)
+{
+ struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->output)
+ return ops->output(dev, p);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+status_t class_netif_mcast_filter(struct device *dev, const uint8_t *mac, int action)
+{
+ struct netif_ops *ops = device_get_driver_ops(dev, struct netif_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->mcast_filter)
+ return ops->mcast_filter(dev, mac, action);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
diff --git a/src/bsp/lk/dev/class/spi_api.c b/src/bsp/lk/dev/class/spi_api.c
new file mode 100644
index 0000000..9453dc3
--- /dev/null
+++ b/src/bsp/lk/dev/class/spi_api.c
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+#include <err.h>
+#include <dev/class/spi.h>
+
+ssize_t class_spi_transaction(struct device *dev, struct spi_transaction *txn, size_t count)
+{
+ struct spi_ops *ops = device_get_driver_ops(dev, struct spi_ops, std);
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->transaction)
+ return ops->transaction(dev, txn, count);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
diff --git a/src/bsp/lk/dev/class/uart_api.c b/src/bsp/lk/dev/class/uart_api.c
new file mode 100644
index 0000000..31e2c9d
--- /dev/null
+++ b/src/bsp/lk/dev/class/uart_api.c
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+#include <err.h>
+#include <dev/class/uart.h>
+
+ssize_t class_uart_read(struct device *dev, void *buf, size_t len)
+{
+ struct uart_ops *ops = device_get_driver_ops(dev, struct uart_ops, std);
+
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->read)
+ return ops->read(dev, buf, len);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+
+ssize_t class_uart_write(struct device *dev, const void *buf, size_t len)
+{
+ struct uart_ops *ops = device_get_driver_ops(dev, struct uart_ops, std);
+
+ if (!ops)
+ return ERR_NOT_CONFIGURED;
+
+ if (ops->write)
+ return ops->write(dev, buf, len);
+ else
+ return ERR_NOT_SUPPORTED;
+}
+