aboutsummaryrefslogtreecommitdiff
path: root/daemon/peripheral_manager.cc
diff options
context:
space:
mode:
authorLee Campbell <leecam@google.com>2016-03-08 16:00:55 -0800
committerLee Campbell <leecam@google.com>2016-03-08 17:07:56 -0800
commitc589f9dc35abbd00601d50f732a4d7e0c83dccc1 (patch)
tree1a5d47d9d03b6ca294bc0258291dc17c6edf77a8 /daemon/peripheral_manager.cc
parente1adeba7ee43e6c609655c764d5dc8a7748d0126 (diff)
downloadperipheralmanager-c589f9dc35abbd00601d50f732a4d7e0c83dccc1.tar.gz
Hook up the SPI HAL to the SPI manager
Implement the backend IOCTLS for SPI BUG: 27555414 Change-Id: I4be6b9e33dd7b6d2483a04f368289a3229df0439 TEST: Tested with an RGB led
Diffstat (limited to 'daemon/peripheral_manager.cc')
-rw-r--r--daemon/peripheral_manager.cc40
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,