1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <ddk/debug.h>
6 #include <ddk/device.h>
7 #include <ddk/platform-defs.h>
8 #include <ddk/protocol/platform/bus.h>
9
10 #include <soc/mt8167/mt8167-hw.h>
11
12 #include "mt8167.h"
13
14 namespace board_mt8167 {
15
GpioInit()16 zx_status_t Mt8167::GpioInit() {
17
18 const pbus_mmio_t gpio_mmios[] = {
19 {
20 .base = MT8167_GPIO_BASE,
21 .length = MT8167_GPIO_SIZE,
22 },
23 {
24 .base = MT8167_IOCFG_BASE,
25 .length = MT8167_IOCFG_SIZE,
26 },
27 {
28 .base = MT8167_EINT_BASE,
29 .length = MT8167_EINT_SIZE,
30 },
31 };
32
33 const pbus_irq_t gpio_irqs[] = {
34 {
35 .irq = MT8167_IRQ_ARM_EINT,
36 .mode = ZX_INTERRUPT_MODE_LEVEL_HIGH,
37 },
38 };
39
40 pbus_dev_t gpio_dev = {};
41 gpio_dev.name = "gpio";
42 gpio_dev.vid = PDEV_VID_MEDIATEK;
43 gpio_dev.did = PDEV_DID_MEDIATEK_GPIO;
44 gpio_dev.mmio_list = gpio_mmios;
45 gpio_dev.mmio_count = countof(gpio_mmios);
46 gpio_dev.irq_list = gpio_irqs;
47 gpio_dev.irq_count = countof(gpio_irqs);
48
49 zx_status_t status = pbus_.ProtocolDeviceAdd(ZX_PROTOCOL_GPIO_IMPL, &gpio_dev);
50 if (status != ZX_OK) {
51 zxlogf(ERROR, "%s: ProtocolDeviceAdd failed %d\n", __FUNCTION__, status);
52 return status;
53 }
54 //#define GPIO_TEST
55 #ifdef GPIO_TEST
56 const pbus_gpio_t gpio_test_gpios[] = {
57 {
58 .gpio = 60, // SDA2, to test gpio_write()
59 },
60 {
61 .gpio = 40, // EINT KPROW0 (key matrix) to test gpio_get_interrupt()
62 },
63 };
64
65 pbus_dev_t gpio_test_dev = {};
66 gpio_test_dev.name = "imx8mevk-gpio-test";
67 gpio_test_dev.vid = PDEV_VID_GENERIC;
68 gpio_test_dev.pid = PDEV_PID_GENERIC;
69 gpio_test_dev.did = PDEV_DID_GPIO_TEST;
70 gpio_test_dev.gpio_list = gpio_test_gpios;
71 gpio_test_dev.gpio_count = countof(gpio_test_gpios);
72 if ((status = pbus_.DeviceAdd(&gpio_test_dev)) != ZX_OK) {
73 zxlogf(ERROR, "%s: Could not add gpio_test_dev %d\n", __FUNCTION__, status);
74 return status;
75 }
76 #endif
77
78 return ZX_OK;
79 }
80
81 } // namespace board_mt8167
82