2013-05-06 12:33:30 +00:00
|
|
|
/*
|
|
|
|
* \brief Access to GPIO driver configuration
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2013-05-06
|
|
|
|
*
|
|
|
|
* Taken from the OMAP4 GPIO driver written by Ivan Loskutov.
|
|
|
|
*
|
|
|
|
* Configure GPIO
|
|
|
|
* Example:
|
|
|
|
* <config>
|
|
|
|
* <gpio num="123" mode="I"/>
|
|
|
|
* <gpio num="124" mode="O" value="0"/>
|
|
|
|
* </config>
|
|
|
|
*
|
|
|
|
* num - GPIO pin number
|
|
|
|
* mode - input(I) or output(O)
|
|
|
|
* value - output level (1 or 0), only for output mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2010-2017 Genode Labs GmbH
|
2013-05-06 12:33:30 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-05-06 12:33:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__GPIO__CONFIG_H_
|
|
|
|
#define _INCLUDE__GPIO__CONFIG_H_
|
|
|
|
|
2017-02-23 13:32:20 +00:00
|
|
|
/* Genode includes */
|
2013-05-06 12:33:30 +00:00
|
|
|
#include <base/exception.h>
|
|
|
|
#include <gpio/driver.h>
|
2017-02-23 13:32:20 +00:00
|
|
|
#include <util/xml_node.h>
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
namespace Gpio {
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2020-05-06 17:06:25 +00:00
|
|
|
class Invalid_mode : Genode::Exception {};
|
2013-05-06 12:33:30 +00:00
|
|
|
|
2017-02-23 13:32:20 +00:00
|
|
|
static void process_config(Genode::Xml_node const &config, Gpio::Driver &driver);
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-23 13:32:20 +00:00
|
|
|
void Gpio::process_config(Genode::Xml_node const &config, Gpio::Driver &driver)
|
2015-03-04 20:12:14 +00:00
|
|
|
{
|
2020-05-06 17:06:25 +00:00
|
|
|
if (!config.has_sub_node("gpio"))
|
|
|
|
Genode::warning("no GPIO config");
|
|
|
|
|
|
|
|
config.for_each_sub_node("gpio", [&] (Genode::Xml_node const &gpio_node) {
|
2013-05-06 12:33:30 +00:00
|
|
|
|
2020-05-06 17:06:25 +00:00
|
|
|
unsigned const num = gpio_node.attribute_value("num", 0U);
|
2020-10-05 07:17:58 +00:00
|
|
|
Pin gpio { num };
|
|
|
|
|
|
|
|
if (!driver.gpio_valid(gpio)) {
|
2020-05-06 17:06:25 +00:00
|
|
|
Genode::warning("invalid GPIO number ", num, ", ignore node");
|
|
|
|
return;
|
|
|
|
}
|
2013-05-06 12:33:30 +00:00
|
|
|
|
2020-05-06 17:06:25 +00:00
|
|
|
typedef Genode::String<2> Mode;
|
|
|
|
Mode const mode = gpio_node.attribute_value("mode", Mode());
|
2013-05-06 12:33:30 +00:00
|
|
|
|
2020-05-06 17:06:25 +00:00
|
|
|
unsigned value = 0;
|
2013-05-06 12:33:30 +00:00
|
|
|
|
2020-05-06 17:06:25 +00:00
|
|
|
if (mode == "O" || mode == "o") {
|
|
|
|
value = gpio_node.attribute_value("value", value);
|
2020-10-05 07:17:58 +00:00
|
|
|
driver.write(gpio, value);
|
|
|
|
driver.direction(Pin {num}, false);
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
2020-05-06 17:06:25 +00:00
|
|
|
else if (mode == "I" || mode == "i") {
|
2020-10-05 07:17:58 +00:00
|
|
|
driver.direction(Pin {num}, true);
|
2020-05-06 17:06:25 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Genode::error("gpio ", num, " has invalid mode, must be I or O");
|
|
|
|
throw Invalid_mode();
|
|
|
|
}
|
|
|
|
|
|
|
|
Genode::log("gpio ", num, " mode ", mode, " value=", value);
|
|
|
|
});
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__GPIO__CONFIG_H_ */
|