FreeNOS
SunxiClockControl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <Log.h>
19 #include "SunxiClockControl.h"
20 
22 {
23  DEBUG("");
24 
25  if (m_io.map(IOBase & ~0xfff, PAGESIZE,
28  {
29  ERROR("failed to map I/O memory");
30  return IOError;
31  }
32 
33  m_io.setBase(m_io.getBase() + (IOBase & 0xfff));
34  return Success;
35 }
36 
38 {
39  DEBUG("clock = " << (int) clock);
40 
41  u32 offset = 0x0;
42  u32 bit;
43 
44  switch (clock)
45  {
46  case ClockEmacTx:
47  offset = 0x060;
48  bit = 17;
49  break;
50 
51  case ClockEphy:
52  offset = 0x070;
53  bit = 0;
54  break;
55 
56  default:
57  ERROR("unsupported clock: " << (int) clock);
58  return InvalidArgument;
59  }
60 
61  m_io.set(offset, (1 << bit));
62  return Success;
63 }
64 
66 {
67  DEBUG("reset = " << (int) reset);
68 
69  u32 offset = 0x0;
70  u32 bit;
71 
72  switch (reset)
73  {
74  case ResetEmacTx:
75  offset = 0x2c0;
76  bit = 17;
77  break;
78 
79  case ResetEphy:
80  offset = 0x2c8;
81  bit = 2;
82  break;
83 
84  default:
85  ERROR("unsupported reset: " << (int) reset);
86  return InvalidArgument;
87  }
88 
89  m_io.set(offset, (1 << bit));
90  return Success;
91 }
SunxiClockControl::ResetEmacTx
@ ResetEmacTx
Definition: SunxiClockControl.h:70
SunxiClockControl::initialize
Result initialize()
Perform initialization.
Definition: SunxiClockControl.cpp:21
SunxiClockControl::InvalidArgument
@ InvalidArgument
Definition: SunxiClockControl.h:81
Memory::Writable
@ Writable
Definition: Memory.h:42
IO::map
Result map(Address phys, Size size=4096, Memory::Access access=Memory::Readable|Memory::Writable|Memory::User)
Map I/O address space.
Definition: IO.cpp:38
Memory::User
@ User
Definition: Memory.h:44
PAGESIZE
#define PAGESIZE
ARM uses 4K pages.
Definition: ARMConstant.h:97
SunxiClockControl::enable
Result enable(const Clock clock)
Enable a clock.
Definition: SunxiClockControl.cpp:37
Memory::Device
@ Device
Definition: Memory.h:48
SunxiClockControl::IOError
@ IOError
Definition: SunxiClockControl.h:80
SunxiClockControl::Success
@ Success
Definition: SunxiClockControl.h:79
Memory::Readable
@ Readable
Definition: Memory.h:41
Log.h
SunxiClockControl::IOBase
static const Address IOBase
Physical base memory address of the CCU module.
Definition: SunxiClockControl.h:43
SunxiClockControl::ClockEphy
@ ClockEphy
Definition: SunxiClockControl.h:62
IO::setBase
void setBase(const Address base)
Set memory I/O base offset.
Definition: IO.cpp:33
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
SunxiClockControl::Reset
Reset
Reset signal identifiers.
Definition: SunxiClockControl.h:68
SunxiClockControl::ResetEphy
@ ResetEphy
Definition: SunxiClockControl.h:71
SunxiClockControl::Clock
Clock
Clock identifiers.
Definition: SunxiClockControl.h:59
SunxiClockControl::Result
Result
Result codes.
Definition: SunxiClockControl.h:77
IO::Success
@ Success
Definition: IO.h:44
SunxiClockControl::deassert
Result deassert(const Reset reset)
De-assert a reset signal.
Definition: SunxiClockControl.cpp:65
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
ARMIO::set
void set(Address addr, u32 data)
Set bits in memory mapped register.
Definition: ARMIO.h:109
SunxiClockControl.h
IO::getBase
Address getBase() const
Get memory I/O base offset.
Definition: IO.cpp:28
SunxiClockControl::ClockEmacTx
@ ClockEmacTx
Definition: SunxiClockControl.h:61
SunxiClockControl::m_io
Arch::IO m_io
Memory I/O object.
Definition: SunxiClockControl.h:114