2014-04-22 15:51:28 +01:00
|
|
|
/*
|
|
|
|
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
2014-05-01 16:55:23 +01:00
|
|
|
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
2014-04-22 15:51:28 +01:00
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-04-29 15:01:24 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2014-04-10 11:04:02 +01:00
|
|
|
#include "maa.h"
|
2014-05-01 16:55:23 +01:00
|
|
|
#include "intel_galileo_rev_d.h"
|
2014-04-29 15:01:24 +01:00
|
|
|
#include "gpio.h"
|
2014-04-28 00:29:14 +01:00
|
|
|
#include "version.h"
|
2014-04-08 18:43:26 +01:00
|
|
|
|
2014-05-01 16:55:23 +01:00
|
|
|
static maa_pininfo_t* pindata;
|
|
|
|
|
static maa_board_t* plat;
|
2014-04-29 15:01:24 +01:00
|
|
|
|
2014-04-28 00:29:14 +01:00
|
|
|
const char *
|
2014-04-27 21:17:54 +01:00
|
|
|
maa_get_version()
|
2014-04-08 18:43:26 +01:00
|
|
|
{
|
2014-04-28 00:29:14 +01:00
|
|
|
return gVERSION;
|
2014-04-08 18:43:26 +01:00
|
|
|
}
|
2014-04-29 15:01:24 +01:00
|
|
|
|
|
|
|
|
maa_result_t
|
|
|
|
|
maa_init()
|
|
|
|
|
{
|
2014-05-01 16:55:23 +01:00
|
|
|
plat = maa_intel_galileo_rev_d();
|
|
|
|
|
return MAA_SUCCESS;
|
2014-04-29 15:01:24 +01:00
|
|
|
}
|
|
|
|
|
|
2014-04-30 11:13:36 +01:00
|
|
|
static maa_result_t
|
2014-05-01 16:55:23 +01:00
|
|
|
maa_setup_mux_mapped(maa_pininfo_t meta)
|
2014-04-30 11:13:36 +01:00
|
|
|
{
|
|
|
|
|
int mi;
|
|
|
|
|
for(mi = 0; mi < meta.mux_total; mi++) {
|
|
|
|
|
maa_gpio_context* mux_i;
|
|
|
|
|
mux_i = maa_gpio_init_raw(meta.mux[mi].pin);
|
2014-05-01 16:55:23 +01:00
|
|
|
if(mux_i == NULL)
|
|
|
|
|
return MAA_ERROR_INVALID_HANDLE;
|
|
|
|
|
if(maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
|
|
|
|
|
return MAA_ERROR_INVALID_RESOURCE;
|
|
|
|
|
if(maa_gpio_write(mux_i, meta.mux[mi].value) != MAA_SUCCESS)
|
|
|
|
|
return MAA_ERROR_INVALID_RESOURCE;
|
2014-04-30 11:13:36 +01:00
|
|
|
}
|
2014-05-01 16:55:23 +01:00
|
|
|
return MAA_SUCCESS;
|
2014-04-30 11:13:36 +01:00
|
|
|
}
|
|
|
|
|
|
2014-04-29 15:01:24 +01:00
|
|
|
unsigned int
|
2014-05-01 16:55:23 +01:00
|
|
|
maa_check_gpio(int pin)
|
|
|
|
|
{
|
|
|
|
|
if(plat == NULL)
|
|
|
|
|
return -1;
|
2014-04-29 15:01:24 +01:00
|
|
|
|
2014-05-01 16:55:23 +01:00
|
|
|
if(pin < 0 || pin > plat->gpio_count)
|
2014-04-29 15:01:24 +01:00
|
|
|
return -1;
|
2014-05-01 16:55:23 +01:00
|
|
|
if(plat->pins[pin].mux_total > 0)
|
|
|
|
|
if(maa_setup_mux_mapped(plat->pins[pin]) != MAA_SUCCESS)
|
2014-04-30 11:13:36 +01:00
|
|
|
return -1;
|
2014-05-01 16:55:23 +01:00
|
|
|
return plat->pins[pin].pin;
|
2014-04-29 15:01:24 +01:00
|
|
|
}
|
|
|
|
|
|