FreeNOS
SunxiSystemControl.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 "SunxiSystemControl.h"
20 
22 {
23  if (m_io.map(IOBase & ~0xfff, PAGESIZE,
26  {
27  ERROR("failed to map I/O memory");
28  return IOError;
29  }
30 
31  m_io.setBase(m_io.getBase() + (IOBase & 0xfff));
32  return Success;
33 }
34 
36 {
37  DEBUG("phyAddr = " << (void *)phyAddr);
38 
39  u32 val = m_io.read(EmacClock);
40  val &= ~(u32)(EmacClockMask);
41  val |= EmacClockDefault;
42  val |= phyAddr << EmacClockPhyShift;
43  val |= EmacClockLedPoll;
44  val &= ~(u32)(EmacClockShutdown);
45  val |= EmacClockSelect;
46  val &= ~(u32)(EmacClockRmiiEn);
47  m_io.write(EmacClock, val);
48 
49  return Success;
50 }
SunxiSystemControl::Success
@ Success
Definition: SunxiSystemControl.h:76
SunxiSystemControl::EmacClockMask
@ EmacClockMask
Definition: SunxiSystemControl.h:61
SunxiSystemControl::EmacClockShutdown
@ EmacClockShutdown
Definition: SunxiSystemControl.h:64
SunxiSystemControl::EmacClockRmiiEn
@ EmacClockRmiiEn
Definition: SunxiSystemControl.h:66
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
SunxiSystemControl::IOError
@ IOError
Definition: SunxiSystemControl.h:77
ARMIO::write
void write(u32 reg, u32 data)
write to memory mapped I/O register
Definition: ARMIO.h:46
SunxiSystemControl::EmacClockLedPoll
@ EmacClockLedPoll
Definition: SunxiSystemControl.h:63
PAGESIZE
#define PAGESIZE
ARM uses 4K pages.
Definition: ARMConstant.h:97
Memory::Device
@ Device
Definition: Memory.h:48
SunxiSystemControl.h
Memory::Readable
@ Readable
Definition: Memory.h:41
Log.h
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
SunxiSystemControl::EmacClockSelect
@ EmacClockSelect
Definition: SunxiSystemControl.h:65
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
SunxiSystemControl::m_io
Arch::IO m_io
Memory I/O object.
Definition: SunxiSystemControl.h:100
ARMIO::read
u32 read(u32 reg) const
read from memory mapped I/O register
Definition: ARMIO.h:62
SunxiSystemControl::IOBase
static const Address IOBase
Physical base memory address of the SYSCON module.
Definition: SunxiSystemControl.h:43
IO::Success
@ Success
Definition: IO.h:44
SunxiSystemControl::setupEmac
Result setupEmac(const uint phyAddr)
Setup EMAC mode.
Definition: SunxiSystemControl.cpp:35
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
SunxiSystemControl::EmacClockDefault
@ EmacClockDefault
Definition: SunxiSystemControl.h:60
SunxiSystemControl::Result
Result
Result codes.
Definition: SunxiSystemControl.h:74
SunxiSystemControl::initialize
Result initialize()
Perform initialization.
Definition: SunxiSystemControl.cpp:21
SunxiSystemControl::EmacClock
@ EmacClock
Definition: SunxiSystemControl.h:52
IO::getBase
Address getBase() const
Get memory I/O base offset.
Definition: IO.cpp:28
SunxiSystemControl::EmacClockPhyShift
@ EmacClockPhyShift
Definition: SunxiSystemControl.h:62