1 /*
2 * Copyright (c) 2022 Intel Corporation
3 * Copyright (c) 2023 SILA Embedded Solutions GmbH
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "smbus_utils.h"
8
9 #include <zephyr/logging/log.h>
10
11 LOG_MODULE_REGISTER(smbus_utils, CONFIG_SMBUS_LOG_LEVEL);
12
smbus_loop_alert_devices(const struct device * dev,sys_slist_t * callbacks)13 void smbus_loop_alert_devices(const struct device *dev, sys_slist_t *callbacks)
14 {
15 int result;
16 uint8_t address;
17
18 /**
19 * There might be several peripheral devices which could have triggered the alert and
20 * the one with the highest priority (lowest address) device wins the arbitration. In
21 * any case, we will have to loop through all of them.
22 *
23 * The format of the transaction is:
24 *
25 * 0 1 2
26 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
27 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 * |S| Alert Addr |R|A| Address |X|N|P|
29 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 */
31 while (true) {
32 result = smbus_byte_read(dev, SMBUS_ADDRESS_ARA, &address);
33 if (result != 0) {
34 LOG_DBG("%s: no more peripheral devices left which triggered an alert",
35 dev->name);
36 return;
37 }
38
39 LOG_DBG("%s: address 0x%02X triggered an alert", dev->name, address);
40
41 smbus_fire_callbacks(callbacks, dev, address);
42 }
43 }
44