blob: 04be16a806a8c6fd2d5926e0e50d02a32d07ee8e [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <assert.h>
#include <memory>
#include <utility>
#include <ddktl/mmio.h>
class MtAudioInDevice {
public:
enum MtI2sCh {
I2S3, // Primary.
I2S1, // Secondary. Documention some times calls I2S1 "I2S".
};
DISALLOW_COPY_ASSIGN_AND_MOVE(MtAudioInDevice);
static std::unique_ptr<MtAudioInDevice> Create(ddk::MmioBuffer mmio, MtI2sCh ch);
// Sets the buffer/length pointers for the DMA engine,
// must reside in the lower 32-bits of the address space.
zx_status_t SetBuffer(zx_paddr_t buf, size_t len);
// Returns offset of dma pointer in the ring buffer.
uint32_t GetRingPosition();
// Starts clocking data with data fetched from the beginning of the buffer.
uint64_t Start();
// Stops clocking data out (physical bus signals remain active).
void Stop();
// Stops clocking data and quiets output signals.
void Shutdown();
uint32_t fifo_depth() const { return fifo_depth_; };
private:
const uint32_t fifo_depth_; // in bytes.
ddk::MmioBuffer mmio_;
// TODO(andresoportus): Add more configuration options.
MtAudioInDevice(ddk::MmioBuffer mmio, uint32_t fifo_depth)
: fifo_depth_(fifo_depth),
mmio_(std::move(mmio)){};
void InitRegs();
};