blob: 9175647c9c4d39f9dfbc078b3b282cd9382ed886 (
plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package pm
/*
* Chip represents an Embedded Controller IC, where
* pin names can be used to lookup various types of
* pin usages such as I2C buses, GPIOs etc.
* The pins are referenced as physical pin names such as "A4" etc.
*/
type Chip interface {
/*
* Name returns the name of the chip
*/
Name() string
/*
* EnabledNodes returns a list of names of DTS nodes that
* require enabling i.e adding 'status = "okay"' on the nodes.
*/
EnabledNodes() []string
/*
* Adc will return a DTS reference to the appropriate ADC
* that is connected to this pin.
*/
Adc(pin string) string
/*
* Gpio will return a gpio controller and a pin number for
* the appropriate GPIO that is connected to this pin.
*/
Gpio(pin string) (string, int)
/*
* I2C will return a DTS reference to the appropriate I2C
* bus that is connected to this pin. The pin is assumed to be
* the I2C clock pin of the 2 wire bus.
*/
I2c(pin string) string
}
// chipList contains a list of registered chips.
// Each chip has a unique name that is used to match it.
var chipList []Chip
// RegisterChip adds this chip into the list of registered chips.
func RegisterChip(chip Chip) {
chipList = append(chipList, chip)
}
// FindChip returns the registered chip matching this name, or nil
// if none are found.
func FindChip(name string) Chip {
for _, c := range chipList {
if c.Name() == name {
return c
}
}
return nil
}
// Chips returns the list of names of the registered chips.
func Chips() []string {
var l []string
for _, c := range chipList {
l = append(l, c.Name())
}
return l
}
|