xref: /openbmc/dbus-sensors/README.md (revision 00b305b90dbf56b92ba28c17f8ccf98f2910ace4)
12a408b94SJames Feist# dbus-sensors
22a408b94SJames Feist
32a408b94SJames Feistdbus-sensors is a collection of sensor applications that provide the
42a408b94SJames Feistxyz.openbmc_project.Sensor collection of interfaces. They read sensor values
52a408b94SJames Feistfrom hwmon, d-bus, or direct driver access to provide readings. Some advance
62a408b94SJames Feistnon-sensor features such as fan presence, pwm control, and automatic cpu
72a408b94SJames Feistdetection (x86) are also supported.
82a408b94SJames Feist
92a408b94SJames Feist## key features
102a408b94SJames Feist
112a408b94SJames Feist- runtime re-configurable from d-bus (entity-manager or the like)
122a408b94SJames Feist
132a408b94SJames Feist- isolated: each sensor type is isolated into its own daemon, so a bug in one
142a408b94SJames Feist  sensor is unlikely to affect another, and single sensor modifications are
152a408b94SJames Feist  possible
162a408b94SJames Feist
172a408b94SJames Feist- async single-threaded: uses sdbusplus/asio bindings
182a408b94SJames Feist
192a408b94SJames Feist- multiple data inputs: hwmon, d-bus, direct driver access
200947d7c1SJosh Lehan
21e1a18f3eSZhikui Ren## dbus interfaces
22e1a18f3eSZhikui Ren
23e1a18f3eSZhikui RenA typical dbus-sensors object support the following dbus interfaces:
24e1a18f3eSZhikui Ren
25084daf31SGeorge Liu```text
26e1a18f3eSZhikui RenPath        /xyz/openbmc_project/sensors/<type>/<sensor_name>
27e1a18f3eSZhikui Ren
28e1a18f3eSZhikui RenInterfaces  xyz.openbmc_project.Sensor.Value
29e1a18f3eSZhikui Ren            xyz.openbmc_project.Sensor.Threshold.Critical
30e1a18f3eSZhikui Ren            xyz.openbmc_project.Sensor.Threshold.Warning
31e1a18f3eSZhikui Ren            xyz.openbmc_project.State.Decorator.Availability
32e1a18f3eSZhikui Ren            xyz.openbmc_project.State.Decorator.OperationalStatus
33e1a18f3eSZhikui Ren            xyz.openbmc_project.Association.Definitions
34e1a18f3eSZhikui Ren
35e1a18f3eSZhikui Ren```
36e1a18f3eSZhikui Ren
371e384254SPatrick WilliamsSensor interfaces collection are described
381e384254SPatrick Williams[here](https://github.com/openbmc/phosphor-dbus-interfaces/tree/master/yaml/xyz/openbmc_project/Sensor).
391e384254SPatrick Williams
401e384254SPatrick WilliamsConsumer examples of these interfaces are
411e384254SPatrick Williams[Redfish](https://github.com/openbmc/bmcweb/blob/master/redfish-core/lib/sensors.hpp),
421e384254SPatrick Williams[Phosphor-Pid-Control](https://github.com/openbmc/phosphor-pid-control),
431e384254SPatrick Williams[IPMI SDR](https://github.com/openbmc/phosphor-host-ipmid/blob/master/dbus-sdr/sensorcommands.cpp).
441e384254SPatrick Williams
45e1a18f3eSZhikui Ren## Reactor
461e384254SPatrick Williams
47e1a18f3eSZhikui Rendbus-sensor daemons are [reactors](https://github.com/openbmc/entity-manager)
481e384254SPatrick Williamsthat dynamically create and update sensors configuration when system
491e384254SPatrick Williamsconfiguration gets updated.
50e1a18f3eSZhikui Ren
511e384254SPatrick WilliamsUsing asio timers and async calls, dbus-sensor daemons read sensor values and
521e384254SPatrick Williamscheck thresholds periodically. PropertiesChanged signals will be broadcasted for
531e384254SPatrick Williamsother services to consume when value or threshold status change. OperationStatus
541e384254SPatrick Williamsis set to false if the sensor is determined to be faulty.
55e1a18f3eSZhikui Ren
561e384254SPatrick WilliamsA simple sensor example can be found
571e384254SPatrick Williams[here](https://github.com/openbmc/entity-manager/blob/master/docs/my_first_sensors.md).
58e1a18f3eSZhikui Ren
59e1a18f3eSZhikui Ren## configuration
601e384254SPatrick Williams
611e384254SPatrick WilliamsSensor devices are described using Exposes records in configuration file. Name
621e384254SPatrick Williamsand Type fields are required. Different sensor types have different fields.
631e384254SPatrick WilliamsRefer to entity manager
641e384254SPatrick Williams[schema](https://github.com/openbmc/entity-manager/blob/master/schemas/legacy.json)
651e384254SPatrick Williamsfor complete list.
661e384254SPatrick Williams
670947d7c1SJosh Lehan## sensor documentation
680947d7c1SJosh Lehan
690947d7c1SJosh Lehan- [ExternalSensor](https://github.com/openbmc/docs/blob/master/designs/external-sensor.md)
700947d7c1SJosh Lehan  virtual sensor
71be53d6b9SAndrew Geissler
72*00b305b9SGeorge Liu## Sensor Type Documentation
73be53d6b9SAndrew Geissler
74*00b305b9SGeorge Liu### ADC Sensors
75be53d6b9SAndrew Geissler
76be53d6b9SAndrew GeisslerADC sensors are sensors based on an Analog to Digital Converter. They are read
77be53d6b9SAndrew Geisslervia the Linux kernel Industrial I/O subsystem (IIO).
78be53d6b9SAndrew Geissler
79be53d6b9SAndrew GeisslerOne of the more common use cases within OpenBMC is for reading these sensors
80be53d6b9SAndrew Geisslerfrom the ADC on the Aspeed ASTXX cards.
81be53d6b9SAndrew Geissler
82be53d6b9SAndrew GeisslerTo utilize ADC sensors feature within OpenBMC you must first define and enable
83be53d6b9SAndrew Geisslerit within the kernel device tree.
84be53d6b9SAndrew Geissler
85be53d6b9SAndrew GeisslerWhen using a common OpenBMC device like the AST2600 you will find a "adc0" and
86be53d6b9SAndrew Geissler"adc1" section in the aspeed-g6.dtsi file. These are disabled by default so in
87be53d6b9SAndrew Geissleryour system-specific dts you would enable and configure what you want with
88be53d6b9SAndrew Geisslersomething like this:
89be53d6b9SAndrew Geissler
90084daf31SGeorge Liu```text
91be53d6b9SAndrew Geissleriio-hwmon {
92be53d6b9SAndrew Geissler    compatible = "iio-hwmon";
93be53d6b9SAndrew Geissler    io-channels = <&adc0 0>;
94be53d6b9SAndrew Geissler    ...
95be53d6b9SAndrew Geissler}
96be53d6b9SAndrew Geissler
97be53d6b9SAndrew Geissler&adc0 {
98be53d6b9SAndrew Geissler    status = "okay";
99be53d6b9SAndrew Geissler    ...
100be53d6b9SAndrew Geissler};
101be53d6b9SAndrew Geissler
102be53d6b9SAndrew Geissler&adc1 {
103be53d6b9SAndrew Geissler    status = "okay";
104be53d6b9SAndrew Geissler    ...
105be53d6b9SAndrew Geissler};
106be53d6b9SAndrew Geissler```
107be53d6b9SAndrew Geissler
108be53d6b9SAndrew Geissler**Note** that this is not meant to be an exhaustive list on the nuances of
109be53d6b9SAndrew Geisslerconfiguring a device tree but really to point users in the general direction.
110be53d6b9SAndrew Geissler
111be53d6b9SAndrew GeisslerYou will then create an entity-manager configuration file that is of type "ADC"
112be53d6b9SAndrew GeisslerA very simple example would like look this:
113be53d6b9SAndrew Geissler
114084daf31SGeorge Liu```text
115be53d6b9SAndrew Geissler            "Index": 0,
116be53d6b9SAndrew Geissler            "Name": "P12V",
117be53d6b9SAndrew Geissler            "PowerState": "Always",
118be53d6b9SAndrew Geissler            "ScaleFactor": 1.0,
119be53d6b9SAndrew Geissler            "Type": "ADC"
120be53d6b9SAndrew Geissler```
121be53d6b9SAndrew Geissler
122be53d6b9SAndrew GeisslerWhen your system is booted, a "in0_input" file will be created within the hwmon
123be53d6b9SAndrew Geisslersubsystem (/sys/class/hwmon/hwmonX). The adcsensor application will scan d-bus
124be53d6b9SAndrew Geisslerfor any ADC entity-manager objects, look up their "Index" value, and try to
125be53d6b9SAndrew Geisslermatch that with the hwmon inY_input files. When it finds a match it will create
126be53d6b9SAndrew Geisslera d-bus sensor under the xyz.openbmc_project.ADCSensor service. The sensor will
127be53d6b9SAndrew Geisslerbe periodically updated based on readings from the hwmon file.
128