genode/repos/os/src/drivers/platform/spec/odroid_x2/pmu.h

168 lines
3.9 KiB
C
Raw Normal View History

2015-04-28 14:04:37 +02:00
/*
* \brief Regulator driver for power management unit of Exynos4412 SoC
* \author Alexy Gallardo Segura <alexy@uclv.cu>
* \author Humberto Lopez Leon <humberto@uclv.cu>
* \author Reinier Millo Sanchez <rmillo@uclv.cu>
2015-07-08 22:35:22 +02:00
* \date 2015-07-08
2015-04-28 14:04:37 +02:00
*/
/*
* Copyright (C) 2015-2017 Genode Labs GmbH
2015-04-28 14:04:37 +02:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
2015-04-28 14:04:37 +02:00
*/
#ifndef _DRIVERS__PLATFORM__SPEC__ODROID_X2__PMU_H_
#define _DRIVERS__PLATFORM__SPEC__ODROID_X2__PMU_H_
2015-04-28 14:04:37 +02:00
#include <base/log.h>
2015-04-28 14:04:37 +02:00
#include <regulator/consts.h>
#include <regulator/driver.h>
#include <drivers/defs/odroid_x2.h>
2015-04-28 14:04:37 +02:00
#include <os/attached_mmio.h>
using Genode::warning;
2015-04-28 14:04:37 +02:00
using namespace Regulator;
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
class Pmu : public Regulator::Driver,
private Genode::Attached_mmio
2015-04-28 14:04:37 +02:00
{
private:
template <unsigned OFFSET>
struct Control : Register <OFFSET, 32>
{
struct Enable : Register<OFFSET, 32>::template Bitfield<0, 1> { };
};
template <unsigned OFFSET>
struct Configuration : Register <OFFSET, 32>
{
struct Local_pwr_cfg : Register<OFFSET, 32>::template Bitfield<0, 3> { };
};
template <unsigned OFFSET>
struct Status : Register <OFFSET, 32>
{
struct Stat : Register<OFFSET, 32>::template Bitfield<0, 3> { };
};
template <unsigned OFFSET>
struct Sysclk_configuration : Register <OFFSET, 32>
{
struct Local_pwr_cfg : Register<OFFSET, 32>::template Bitfield<0, 1> { };
};
template <unsigned OFFSET>
struct Sysclk_status : Register <OFFSET, 32>
{
struct Stat : Register<OFFSET, 32>::template Bitfield<0, 1> { };
};
struct Hdmi_phy_control : Register<0x700, 32>
{
struct Enable : Bitfield<0, 1> { };
struct Div_ratio : Bitfield<16, 10> { };
};
2015-07-08 22:35:22 +02:00
typedef Control<0x0704> Usbdrd_phy_control;
typedef Control<0x0708> Usbhost_phy1_control;
typedef Control<0x70c> Usbhost_phy2_control;
2015-04-28 14:04:37 +02:00
void _enable(unsigned long id)
{
switch (id) {
case PWR_USB20:
2015-07-08 22:35:22 +02:00
write<Usbdrd_phy_control::Enable>(1);
write<Usbhost_phy1_control::Enable>(1);
write<Usbhost_phy2_control::Enable>(1);
2015-04-28 14:04:37 +02:00
break;
case PWR_HDMI: {
Hdmi_phy_control::access_t hpc = read<Hdmi_phy_control>();
Hdmi_phy_control::Div_ratio::set(hpc, 150);
Hdmi_phy_control::Enable::set(hpc, 1);
write<Hdmi_phy_control>(hpc);
break; }
2015-04-28 14:04:37 +02:00
default:
warning("Unsupported for ", names[id].name);
2015-04-28 14:04:37 +02:00
}
}
void _disable(unsigned long id)
{
switch (id) {
case PWR_USB20:
2015-07-08 22:35:22 +02:00
write<Usbdrd_phy_control::Enable>(0);
write<Usbhost_phy1_control::Enable>(0);
write<Usbhost_phy2_control::Enable>(0);
2015-04-28 14:04:37 +02:00
break;
case PWR_HDMI:
write<Hdmi_phy_control::Enable>(0);
break;
2015-04-28 14:04:37 +02:00
default:
warning("Unsupported for ", names[id].name);
2015-04-28 14:04:37 +02:00
}
}
public:
/**
* Constructor
*/
Pmu(Genode::Env &env)
: Genode::Attached_mmio(env, Odroid_x2::PMU_MMIO_BASE,
Odroid_x2::PMU_MMIO_SIZE)
2015-04-28 14:04:37 +02:00
{
write<Usbdrd_phy_control::Enable>(0);
2015-07-08 22:35:22 +02:00
write<Usbhost_phy1_control::Enable>(0);
write<Usbhost_phy2_control::Enable>(0);
write<Hdmi_phy_control::Enable>(0);
2015-04-28 14:04:37 +02:00
}
/********************************
** Regulator driver interface **
********************************/
void level(Regulator_id id, unsigned long /* level */) override
2015-04-28 14:04:37 +02:00
{
switch (id) {
default:
warning("Unsupported for ", names[id].name);
2015-04-28 14:04:37 +02:00
}
}
unsigned long level(Regulator_id id) override
2015-04-28 14:04:37 +02:00
{
switch (id) {
default:
warning("Unsupported for ", names[id].name);
2015-04-28 14:04:37 +02:00
}
return 0;
}
void state(Regulator_id id, bool enable) override
2015-04-28 14:04:37 +02:00
{
if (enable)
_enable(id);
else
_disable(id);
}
bool state(Regulator_id id) override
2015-04-28 14:04:37 +02:00
{
switch (id) {
case PWR_USB20:
2015-07-08 22:35:22 +02:00
return read<Usbdrd_phy_control::Enable>();
2015-04-28 14:04:37 +02:00
default:
warning("Unsupported for ", names[id].name);
2015-04-28 14:04:37 +02:00
}
return true;
}
};
#endif /* _DRIVERS__PLATFORM__SPEC__ODROID_X2__PMU_H_ */