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/device.h>
6#include <ddk/io-buffer.h>
7#include <ddk/protocol/ethernet_board.h>
8#include <ddk/protocol/gpio.h>
9#include <ddk/protocol/i2c.h>
10#include <ddk/protocol/platform-device.h>
11#include <ddktl/device.h>
12#include <fbl/atomic.h>
13#include <fbl/unique_ptr.h>
14#include <threads.h>
15
16namespace eth {
17
18class AmlEthernet {
19public:
20    // GPIO Indexes.
21    enum {
22        PHY_RESET,
23        PHY_INTR,
24        GPIO_COUNT,
25    };
26
27    zx_device_t* device_;
28    gpio_protocol_t gpios_[GPIO_COUNT];
29    DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(AmlEthernet);
30    AmlEthernet(){};
31    static zx_status_t Create(zx_device_t* device);
32
33    // DDK Hooks.
34    void DdkRelease(void* ctx);
35    void DdkUnbind(void* ctx);
36    void ReleaseBuffers();
37
38    // ETH_BOARD protocol.
39    static void ResetPhy(void* ctx);
40
41private:
42    // MMIO Indexes
43    enum {
44        MMIO_PERIPH,
45        MMIO_HHI,
46    };
47
48    zx_status_t InitPdev(zx_device_t* parent);
49
50    platform_device_protocol_t pdev_;
51
52    i2c_protocol_t i2c_;
53
54    io_buffer_t periph_regs_iobuff_;
55    io_buffer_t hhi_regs_iobuff_;
56};
57
58} // namespace eth
59