/
cmos.go
49 lines (41 loc) · 1.1 KB
/
cmos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2012-2020 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64 || 386
// +build amd64 386
package cmos
import (
"github.com/u-root/u-root/pkg/memio"
)
const (
regPort = 0x70
dataPort = 0x71
)
type Chip struct {
memio.PortReadWriter
}
// Read reads a register reg from CMOS into data.
func (c *Chip) Read(reg memio.Uint8, data memio.UintN) error {
if err := c.PortReadWriter.Out(regPort, ®); err != nil {
return err
}
return c.PortReadWriter.In(dataPort, data)
}
// Write writes value data into CMOS register reg.
func (c *Chip) Write(reg memio.Uint8, data memio.UintN) error {
if err := c.PortReadWriter.Out(regPort, ®); err != nil {
return err
}
return c.PortReadWriter.Out(dataPort, data)
}
// GetCMOS() returns the struct to call Read and Write functions for CMOS
// associated with the correct functions of memio.In and memio.Out
func New() (*Chip, error) {
pr, err := memio.NewPort()
if err != nil {
return nil, err
}
return &Chip{
PortReadWriter: pr,
}, nil
}