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}
void set(Address addr, u32 data)
Set bits in memory mapped register.
Definition ARMIO.h:109
void setBase(const Address base)
Set memory I/O base offset.
Definition IO.cpp:33
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
Address getBase() const
Get memory I/O base offset.
Definition IO.cpp:28
@ Success
Definition IO.h:44
Result deassert(const Reset reset)
De-assert a reset signal.
Result initialize()
Perform initialization.
Arch::IO m_io
Memory I/O object.
Result enable(const Clock clock)
Enable a clock.
Clock
Clock identifiers.
Reset
Reset signal identifiers.
static const Address IOBase
Physical base memory address of the CCU module.
#define PAGESIZE
ARM uses 4K pages.
Definition ARMConstant.h:97
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
#define ERROR(msg)
Output an error message.
Definition Log.h:61
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
@ User
Definition Memory.h:44
@ Readable
Definition Memory.h:41
@ Device
Definition Memory.h:48
@ Writable
Definition Memory.h:42