For devices on buses like I2C or SPI its possible that a sensor might
support being on either bus type. In the dts we can tell this by
looking at the parent bus of the device. Its useful for a driver to
know this so can we build support into the driver accordingly.
For example if the LSM6DSL sensor ("st,lsm6dsl") is in the dts on a spi
bus we now generate:
#define DT_ST_LPS22HB_PRESS_BUS_SPI 1
Its possible that a system exists in which multiple of the same sensor
exist but on different busses, so drivers should handle that case
accordingly. For the LSM6DSL example we'd end up with:
#define DT_ST_LPS22HB_PRESS_BUS_I2C 1
#define DT_ST_LPS22HB_PRESS_BUS_SPI 1
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
#
|
|
# Copyright (c) 2018 Bobby Noelte
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
from extract.globals import *
|
|
from extract.directive import DTDirective
|
|
|
|
##
|
|
# @brief Manage compatible directives.
|
|
#
|
|
# Handles:
|
|
# - compatible
|
|
#
|
|
class DTCompatible(DTDirective):
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
##
|
|
# @brief Extract compatible
|
|
#
|
|
# @param node_address Address of node owning the
|
|
# compatible definition.
|
|
# @param prop compatible property name
|
|
# @param def_label Define label string of node owning the
|
|
# compatible definition.
|
|
#
|
|
def extract(self, node_address, prop, def_label):
|
|
|
|
# compatible definition
|
|
binding = get_binding(node_address)
|
|
compatible = reduced[node_address]['props'][prop]
|
|
if not isinstance(compatible, list):
|
|
compatible = [compatible, ]
|
|
|
|
for i, comp in enumerate(compatible):
|
|
# Generate #define's
|
|
compat_label = convert_string_to_label(str(comp))
|
|
compat_defs = 'DT_COMPAT_' + compat_label
|
|
load_defs = {
|
|
compat_defs: "1",
|
|
}
|
|
insert_defs(node_address, load_defs, {})
|
|
# Generate #define for BUS a "sensor" might be on
|
|
# for example:
|
|
# #define DT_ST_LPS22HB_PRESS_BUS_SPI 1
|
|
if 'parent' in binding:
|
|
bus = binding['parent']['bus']
|
|
compat_defs = 'DT_' + compat_label + '_BUS_' + bus.upper()
|
|
load_defs = {
|
|
compat_defs: "1",
|
|
}
|
|
insert_defs(node_address, load_defs, {})
|
|
|
|
|
|
##
|
|
# @brief Management information for compatible.
|
|
compatible = DTCompatible()
|