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 #pragma once 6 7 #include <ddk/debug.h> 8 #include <ddktl/pdev.h> 9 #include <fbl/unique_ptr.h> 10 11 namespace audio { 12 namespace astro { 13 14 static constexpr uint8_t SW_RESET = 0x01; //sw reset 15 static constexpr uint8_t PWR_CTL = 0x02; //power control 16 static constexpr uint8_t PB_CFG2 = 0x05; //pcm gain register 17 static constexpr uint8_t TDM_CFG0 = 0x0a; 18 static constexpr uint8_t TDM_CFG1 = 0x0b; 19 static constexpr uint8_t TDM_CFG2 = 0x0c; 20 static constexpr uint8_t TDM_CFG3 = 0x0d; 21 static constexpr uint8_t TDM_CFG4 = 0x0e; 22 static constexpr uint8_t TDM_CFG5 = 0x0f; 23 static constexpr uint8_t TDM_CFG6 = 0x10; 24 static constexpr uint8_t TDM_CFG7 = 0x11; 25 static constexpr uint8_t TDM_CFG8 = 0x12; 26 static constexpr uint8_t TDM_CFG9 = 0x13; 27 static constexpr uint8_t TDM_CFG10 = 0x14; 28 static constexpr uint8_t CLOCK_CFG = 0x3c; //Clock Config 29 30 class Tas27xx : public fbl::unique_ptr<Tas27xx> { 31 public: 32 static fbl::unique_ptr<Tas27xx> Create(ddk::I2cChannel&& i2c); 33 bool ValidGain(float gain); 34 zx_status_t SetGain(float gain); GetGain()35 float GetGain() const { return current_gain_; } GetMinGain()36 float GetMinGain() const { return kMinGain; } GetMaxGain()37 float GetMaxGain() const { return kMaxGain; } GetGainStep()38 float GetGainStep() const { return kGainStep; } 39 40 zx_status_t Init(); 41 zx_status_t Reset(); 42 zx_status_t Standby(); 43 zx_status_t ExitStandby(); 44 45 private: 46 friend class fbl::unique_ptr<Tas27xx>; 47 static constexpr float kMaxGain = 0; 48 static constexpr float kMinGain = -100.0; 49 static constexpr float kGainStep = 0.5; 50 Tas27xx(ddk::I2cChannel && i2c)51 Tas27xx(ddk::I2cChannel&& i2c) : i2c_(i2c) {} 52 ~Tas27xx() = default; 53 54 zx_status_t WriteReg(uint8_t reg, uint8_t value); 55 uint8_t ReadReg(uint8_t reg); 56 57 zx_status_t SetStandby(bool stdby); 58 59 ddk::I2cChannel i2c_; 60 61 float current_gain_ = 0; 62 }; 63 } // namespace astro 64 } // namespace audio 65