diff options
Diffstat (limited to 'daemon/peripheral_manager.cc')
-rw-r--r-- | daemon/peripheral_manager.cc | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/daemon/peripheral_manager.cc b/daemon/peripheral_manager.cc index 0ab602d..2a1e038 100644 --- a/daemon/peripheral_manager.cc +++ b/daemon/peripheral_manager.cc @@ -24,6 +24,7 @@ #include "gpio_driver_sysfs.h" #include "gpio_manager.h" #include "pin_mux_manager.h" +#include "spi_driver_spidev.h" namespace android { namespace { @@ -37,6 +38,15 @@ static int SetGpioPinMux(const char* name, const char* source) { return GpioManager::GetGpioManager()->SetPinMux(name, source); } +// Spi callbacks +static int RegisterSpiDevBus(const char* name, uint32_t bus, uint32_t cs) { + return SpiManager::GetSpiManager()->RegisterSpiDevBus(name, bus, cs); +} + +static int SetSpiPinMux(const char* name, const char* source) { + return SpiManager::GetSpiManager()->SetPinMux(name, source); +} + // Pin Mux callbacks. static int RegisterPin(const char* name, int gpio, @@ -58,7 +68,9 @@ static int RegisterSource(const char* name, char** groups, size_t nr_groups) { return PinMuxManager::GetPinMuxManager()->RegisterSource(name, groups_set); } -static int RegisterSimpleSource(const char* name, char** pins, size_t nr_pins) { +static int RegisterSimpleSource(const char* name, + const char** pins, + size_t nr_pins) { std::set<std::string> pins_set; for (size_t i = 0; i < nr_pins; i++) pins_set.emplace(pins[i]); @@ -73,7 +85,7 @@ PeripheralManager::PeripheralManager() {} PeripheralManager::~PeripheralManager() = default; bool PeripheralManager::Init() { - if(!RegisterDrivers()) + if (!RegisterDrivers()) return false; if (!InitHal()) @@ -101,10 +113,20 @@ void PeripheralManager::binderDied(const wp<IBinder>& who) { } bool PeripheralManager::RegisterDrivers() { - // Register GPIO Sysfs driver. - return GpioManager::GetGpioManager()->RegisterDriver( - std::unique_ptr<GpioDriverInfoBase>( - new GpioDriverInfo<GpioDriverSysfs, void*>(nullptr))); + if (!SpiManager::GetSpiManager()->RegisterDriver( + std::unique_ptr<SpiDriverInfoBase>( + new SpiDriverInfo<SpiDriverSpiDev, CharDeviceFactory*>( + nullptr)))) { + LOG(ERROR) << "Failed to load driver: SpiDriverSpiDev"; + return false; + } + if (!GpioManager::GetGpioManager()->RegisterDriver( + std::unique_ptr<GpioDriverInfoBase>( + new GpioDriverInfo<GpioDriverSysfs, void*>(nullptr)))) { + LOG(ERROR) << "Failed to load driver: GpioDriverSysfs"; + return false; + } + return true; } bool PeripheralManager::InitHal() { @@ -118,9 +140,15 @@ bool PeripheralManager::InitHal() { reinterpret_cast<const peripheral_io_module_t*>(module); struct peripheral_registration_cb_t callbacks = { + // Gpio .register_gpio_sysfs = RegisterGpioSysfs, .set_gpio_pin_mux = SetGpioPinMux, + // Spi + .register_spi_dev_bus = RegisterSpiDevBus, + .set_spi_pin_mux = SetSpiPinMux, + + // Pin Mux .register_pin = RegisterPin, .register_pin_group = RegisterPinGroup, .register_source = RegisterSource, |