2012-07-16 15:13:35 +02:00
|
|
|
/*
|
|
|
|
* \brief Gpio driver for the OMAP4
|
|
|
|
* \author Ivan Loskutov <ivan.loskutov@ksyslabs.org>
|
2013-05-06 14:33:30 +02:00
|
|
|
* \author Stefan Kalkowski <stefan.kalkowski@genode-labs.com>
|
2012-07-16 15:13:35 +02:00
|
|
|
* \date 2012-06-23
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Ksys Labs LLC
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2012-2017 Genode Labs GmbH
|
2012-07-16 15:13:35 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2012-07-16 15:13:35 +02:00
|
|
|
*/
|
|
|
|
|
2015-09-03 14:55:05 +02:00
|
|
|
#ifndef _DRIVERS__GPIO__SPEC__OMAP4__DRIVER_H_
|
|
|
|
#define _DRIVERS__GPIO__SPEC__OMAP4__DRIVER_H_
|
2012-07-16 15:13:35 +02:00
|
|
|
|
|
|
|
/* Genode includes */
|
2017-04-28 15:27:26 +02:00
|
|
|
#include <drivers/defs/panda.h>
|
2013-05-06 14:33:30 +02:00
|
|
|
#include <gpio/driver.h>
|
|
|
|
#include <irq_session/connection.h>
|
2012-07-16 15:13:35 +02:00
|
|
|
#include <timer_session/connection.h>
|
|
|
|
|
|
|
|
/* local includes */
|
|
|
|
#include "gpio.h"
|
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
|
|
|
|
class Omap4_driver : public Gpio::Driver
|
2012-07-16 15:13:35 +02:00
|
|
|
{
|
2013-05-06 14:33:30 +02:00
|
|
|
private:
|
|
|
|
|
2012-07-16 15:13:35 +02:00
|
|
|
enum {
|
2015-04-14 13:56:26 +02:00
|
|
|
PIN_SHIFT = 5,
|
2013-05-06 14:33:30 +02:00
|
|
|
MAX_BANKS = 6,
|
|
|
|
MAX_PINS = 32
|
2012-07-16 15:13:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-04-14 13:56:26 +02:00
|
|
|
class Gpio_bank
|
2012-07-16 15:13:35 +02:00
|
|
|
{
|
2013-05-06 14:33:30 +02:00
|
|
|
private:
|
|
|
|
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg _reg;
|
|
|
|
Genode::Irq_connection _irq;
|
2017-02-23 14:32:20 +01:00
|
|
|
Genode::Signal_handler<Gpio_bank> _dispatcher;
|
2015-04-14 13:56:26 +02:00
|
|
|
Genode::Signal_context_capability _sig_cap[MAX_PINS];
|
|
|
|
bool _irq_enabled[MAX_PINS];
|
|
|
|
|
2017-02-23 14:32:20 +01:00
|
|
|
void _handle()
|
2015-04-14 13:56:26 +02:00
|
|
|
{
|
|
|
|
_reg.write<Gpio_reg::Irqstatus_0>(0xffffffff);
|
|
|
|
|
|
|
|
unsigned long status = _reg.read<Gpio_reg::Irqstatus_0>();
|
|
|
|
|
|
|
|
for(unsigned i = 0; i < MAX_PINS; i++) {
|
|
|
|
if ((status & (1 << i)) && _irq_enabled[i] &&
|
|
|
|
_sig_cap[i].valid())
|
|
|
|
Genode::Signal_transmitter(_sig_cap[i]).submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
_irq.ack_irq();
|
|
|
|
}
|
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-02-23 14:32:20 +01:00
|
|
|
Gpio_bank(Genode::Env &env,
|
2015-04-14 13:56:26 +02:00
|
|
|
Genode::addr_t base, Genode::size_t size,
|
2013-05-06 14:33:30 +02:00
|
|
|
unsigned irq)
|
2017-02-23 14:32:20 +01:00
|
|
|
: _reg(env, base, size), _irq(env, irq),
|
|
|
|
_dispatcher(env.ep(), *this, &Gpio_bank::_handle)
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < MAX_PINS; i++)
|
|
|
|
_irq_enabled[i] = false;
|
|
|
|
|
2015-04-14 13:56:26 +02:00
|
|
|
_irq.sigh(_dispatcher);
|
|
|
|
_irq.ack_irq();
|
2013-05-06 14:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Gpio_reg* regs() { return &_reg; }
|
|
|
|
|
|
|
|
void irq(int pin, bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
_reg.write<Gpio_reg::Irqstatus_0>(1 << pin);
|
|
|
|
_reg.write<Gpio_reg::Irqstatus_set_0>(1 << pin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_reg.write<Gpio_reg::Irqstatus_clr_0>(1 << pin);
|
|
|
|
_irq_enabled[pin] = enable;
|
|
|
|
}
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
void ack_irq(int) { Genode::warning(__func__, " not implemented"); }
|
2015-04-14 13:56:26 +02:00
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
void sigh(int pin, Genode::Signal_context_capability cap) {
|
|
|
|
_sig_cap[pin] = cap; }
|
|
|
|
};
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_bank _gpio_bank_0;
|
|
|
|
Gpio_bank _gpio_bank_1;
|
|
|
|
Gpio_bank _gpio_bank_2;
|
|
|
|
Gpio_bank _gpio_bank_3;
|
|
|
|
Gpio_bank _gpio_bank_4;
|
|
|
|
Gpio_bank _gpio_bank_5;
|
|
|
|
|
|
|
|
Gpio_bank *_gpio_bank(int gpio)
|
|
|
|
{
|
|
|
|
switch (gpio >> PIN_SHIFT) {
|
|
|
|
case 0:
|
|
|
|
return &_gpio_bank_0;
|
|
|
|
case 1:
|
|
|
|
return &_gpio_bank_1;
|
|
|
|
case 2:
|
|
|
|
return &_gpio_bank_2;
|
|
|
|
case 3:
|
|
|
|
return &_gpio_bank_3;
|
|
|
|
case 4:
|
|
|
|
return &_gpio_bank_4;
|
|
|
|
case 5:
|
|
|
|
return &_gpio_bank_5;
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("no Gpio_bank for pin ", gpio, " available");
|
2015-04-14 13:56:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
int _gpio_index(int gpio) { return gpio & 0x1f; }
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2017-02-23 14:32:20 +01:00
|
|
|
Omap4_driver(Genode::Env &env)
|
2015-04-14 13:56:26 +02:00
|
|
|
:
|
2017-04-28 15:27:26 +02:00
|
|
|
_gpio_bank_0(env, Panda::GPIO1_MMIO_BASE, Panda::GPIO1_MMIO_SIZE,
|
|
|
|
Panda::GPIO1_IRQ),
|
|
|
|
_gpio_bank_1(env, Panda::GPIO2_MMIO_BASE, Panda::GPIO2_MMIO_SIZE,
|
|
|
|
Panda::GPIO2_IRQ),
|
|
|
|
_gpio_bank_2(env, Panda::GPIO3_MMIO_BASE, Panda::GPIO3_MMIO_SIZE,
|
|
|
|
Panda::GPIO3_IRQ),
|
|
|
|
_gpio_bank_3(env, Panda::GPIO4_MMIO_BASE, Panda::GPIO4_MMIO_SIZE,
|
|
|
|
Panda::GPIO4_IRQ),
|
|
|
|
_gpio_bank_4(env, Panda::GPIO5_MMIO_BASE, Panda::GPIO5_MMIO_SIZE,
|
|
|
|
Panda::GPIO5_IRQ),
|
|
|
|
_gpio_bank_5(env, Panda::GPIO6_MMIO_BASE, Panda::GPIO6_MMIO_SIZE,
|
|
|
|
Panda::GPIO6_IRQ)
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
{ }
|
2015-04-14 13:56:26 +02:00
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
public:
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2017-02-23 14:32:20 +01:00
|
|
|
static Omap4_driver& factory(Genode::Env &env);
|
2012-07-16 15:13:35 +02:00
|
|
|
|
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
/******************************
|
|
|
|
** Gpio::Driver interface **
|
|
|
|
******************************/
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void direction(unsigned gpio, bool input) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2013-05-06 14:33:30 +02:00
|
|
|
gpio_reg->write<Gpio_reg::Oe>(input ? 1 : 0, _gpio_index(gpio));
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void write(unsigned gpio, bool level) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
if (level)
|
|
|
|
gpio_reg->write<Gpio_reg::Setdataout>(1 << _gpio_index(gpio));
|
|
|
|
else
|
|
|
|
gpio_reg->write<Gpio_reg::Cleardataout>(1 << _gpio_index(gpio));
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
bool read(unsigned gpio) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2013-05-06 14:33:30 +02:00
|
|
|
return gpio_reg->read<Gpio_reg::Datain>(_gpio_index(gpio));
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void debounce_enable(unsigned gpio, bool enable) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2013-05-06 14:33:30 +02:00
|
|
|
gpio_reg->write<Gpio_reg::Debounceenable>(enable ? 1 : 0,
|
|
|
|
_gpio_index(gpio));
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void debounce_time(unsigned gpio, unsigned long us) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
|
|
|
unsigned char debounce;
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
if (us < 32)
|
|
|
|
debounce = 0x01;
|
|
|
|
else if (us > 7936)
|
|
|
|
debounce = 0xff;
|
|
|
|
else
|
|
|
|
debounce = (us / 0x1f) - 1;
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2013-05-06 14:33:30 +02:00
|
|
|
gpio_reg->write<Gpio_reg::Debouncingtime::Time>(debounce);
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void falling_detect(unsigned gpio) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2013-05-06 14:33:30 +02:00
|
|
|
gpio_reg->write<Gpio_reg::Leveldetect0> (0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Leveldetect1> (0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Fallingdetect>(1, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Risingdetect> (0, _gpio_index(gpio));
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void rising_detect(unsigned gpio) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2013-05-06 14:33:30 +02:00
|
|
|
gpio_reg->write<Gpio_reg::Leveldetect0> (0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Leveldetect1> (0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Fallingdetect>(0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Risingdetect> (1, _gpio_index(gpio));
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void high_detect(unsigned gpio) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2013-05-06 14:33:30 +02:00
|
|
|
gpio_reg->write<Gpio_reg::Leveldetect0> (0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Leveldetect1> (1, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Fallingdetect>(0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Risingdetect> (0, _gpio_index(gpio));
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void low_detect(unsigned gpio) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
Gpio_reg *gpio_reg = _gpio_bank(gpio)->regs();
|
2013-05-06 14:33:30 +02:00
|
|
|
gpio_reg->write<Gpio_reg::Leveldetect0> (1, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Leveldetect1> (0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Fallingdetect>(0, _gpio_index(gpio));
|
|
|
|
gpio_reg->write<Gpio_reg::Risingdetect> (0, _gpio_index(gpio));
|
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void irq_enable(unsigned gpio, bool enable) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
_gpio_bank(gpio)->irq(_gpio_index(gpio), enable);
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void ack_irq(unsigned gpio) override
|
2015-04-14 13:56:26 +02:00
|
|
|
{
|
|
|
|
_gpio_bank(gpio)->ack_irq(_gpio_index(gpio));
|
2013-05-06 14:33:30 +02:00
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2013-05-06 14:33:30 +02:00
|
|
|
void register_signal(unsigned gpio,
|
2019-02-14 22:39:08 +01:00
|
|
|
Genode::Signal_context_capability cap) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
2015-04-14 13:56:26 +02:00
|
|
|
_gpio_bank(gpio)->sigh(_gpio_index(gpio), cap); }
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void unregister_signal(unsigned gpio) override
|
2013-05-06 14:33:30 +02:00
|
|
|
{
|
|
|
|
Genode::Signal_context_capability cap;
|
2015-04-14 13:56:26 +02:00
|
|
|
_gpio_bank(gpio)->sigh(_gpio_index(gpio), cap);
|
2013-05-06 14:33:30 +02:00
|
|
|
}
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
bool gpio_valid(unsigned gpio) override { return gpio < (MAX_PINS*MAX_BANKS); }
|
2013-05-06 14:33:30 +02:00
|
|
|
};
|
2012-07-16 15:13:35 +02:00
|
|
|
|
2015-09-03 14:55:05 +02:00
|
|
|
#endif /* _DRIVERS__GPIO__SPEC__OMAP4__DRIVER_H_ */
|