From b388b178a045ebd5d858b012b15ce4e86acdaa86 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 7 Nov 2019 05:03:25 -0600 Subject: [PATCH] sensor: tmp112: Convert to DTS Convert tmp112 sensor driver and sample app to utilize device tree. Introduce a dts board overlay on the frdm_k64f board to ensure we at least have a single platform in which the sample gets built. Signed-off-by: Kumar Gala --- drivers/sensor/tmp112/Kconfig | 31 +------------------ drivers/sensor/tmp112/tmp112.c | 8 ++--- dts/bindings/sensor/ti,tmp112.yaml | 12 +++++++ .../sensor/tmp112/boards/frdm_k64f.overlay | 13 ++++++++ samples/sensor/tmp112/sample.yaml | 1 + tests/drivers/build_all/dts_fixup.h | 6 ++++ 6 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 dts/bindings/sensor/ti,tmp112.yaml create mode 100644 samples/sensor/tmp112/boards/frdm_k64f.overlay diff --git a/drivers/sensor/tmp112/Kconfig b/drivers/sensor/tmp112/Kconfig index 9db9bfff8b4..cce19e2c6cb 100644 --- a/drivers/sensor/tmp112/Kconfig +++ b/drivers/sensor/tmp112/Kconfig @@ -3,7 +3,7 @@ # Copyright (c) 2016 Firmwave # SPDX-License-Identifier: Apache-2.0 -menuconfig TMP112 +config TMP112 bool "TMP112 Temperature Sensor" depends on I2C help @@ -12,32 +12,3 @@ menuconfig TMP112 The TMP102 is compatible with the TMP112 but is less accurate and has been successfully tested with this driver. - -if TMP112 - -config TMP112_NAME - string "Driver name" - default "TMP112" - help - Device name with which the TMP112 sensor is identified. - -config TMP112_I2C_ADDR - hex "I2C address for TMP112" - default 0x48 - help - I2C address of the TMP112 sensor. - - 0x48: A0 connected GND and A1 connected to GND. - 0x49: A0 connected VDD and A1 connected to GND. - 0x4A: A0 connected SDA and A1 connected to GND. - 0x4B: A0 connected SCL and A1 connected to GND. - - -config TMP112_I2C_MASTER_DEV_NAME - string "I2C master where TMP112 is connected" - default "I2C_0" - help - Specify the device name of the I2C master device to which the - TMP112 chip is connected. - -endif # TMP112 diff --git a/drivers/sensor/tmp112/tmp112.c b/drivers/sensor/tmp112/tmp112.c index a57c3bd7eff..35bc251d317 100644 --- a/drivers/sensor/tmp112/tmp112.c +++ b/drivers/sensor/tmp112/tmp112.c @@ -15,7 +15,7 @@ LOG_MODULE_REGISTER(TMP112, CONFIG_SENSOR_LOG_LEVEL); -#define TMP112_I2C_ADDRESS CONFIG_TMP112_I2C_ADDR +#define TMP112_I2C_ADDRESS DT_INST_0_TI_TMP112_BASE_ADDRESS #define TMP112_REG_TEMPERATURE 0x00 #define TMP112_D0_BIT BIT(0) @@ -195,10 +195,10 @@ int tmp112_init(struct device *dev) { struct tmp112_data *drv_data = dev->driver_data; - drv_data->i2c = device_get_binding(CONFIG_TMP112_I2C_MASTER_DEV_NAME); + drv_data->i2c = device_get_binding(DT_INST_0_TI_TMP112_BUS_NAME); if (drv_data->i2c == NULL) { LOG_DBG("Failed to get pointer to %s device!", - CONFIG_TMP112_I2C_MASTER_DEV_NAME); + DT_INST_0_TI_TMP112_BUS_NAME); return -EINVAL; } @@ -207,5 +207,5 @@ int tmp112_init(struct device *dev) static struct tmp112_data tmp112_driver; -DEVICE_AND_API_INIT(tmp112, CONFIG_TMP112_NAME, tmp112_init, &tmp112_driver, +DEVICE_AND_API_INIT(tmp112, DT_INST_0_TI_TMP112_LABEL, tmp112_init, &tmp112_driver, NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &tmp112_driver_api); diff --git a/dts/bindings/sensor/ti,tmp112.yaml b/dts/bindings/sensor/ti,tmp112.yaml new file mode 100644 index 00000000000..d8e2e6f1e06 --- /dev/null +++ b/dts/bindings/sensor/ti,tmp112.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2019, Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +title: TI TMP112 Digital Temperature Sensor + +description: | + TMP112 Digital Temperature Sensor. See more info at + https://www.ti.com/product/TMP112 + +compatible: "ti,tmp112" + +include: i2c-device.yaml diff --git a/samples/sensor/tmp112/boards/frdm_k64f.overlay b/samples/sensor/tmp112/boards/frdm_k64f.overlay new file mode 100644 index 00000000000..2ee9a71bd15 --- /dev/null +++ b/samples/sensor/tmp112/boards/frdm_k64f.overlay @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2019, Linaro Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c0 { + tmp112@4a { + compatible = "ti,tmp112"; + reg = <0x4a>; + label = "TMP112"; + }; +}; diff --git a/samples/sensor/tmp112/sample.yaml b/samples/sensor/tmp112/sample.yaml index 21ff013f709..16e57d3933b 100644 --- a/samples/sensor/tmp112/sample.yaml +++ b/samples/sensor/tmp112/sample.yaml @@ -5,6 +5,7 @@ tests: harness: console tags: sensors depends_on: i2c + filter: dt_compat_enabled("ti,tmp112") harness_config: type: one_line regex: diff --git a/tests/drivers/build_all/dts_fixup.h b/tests/drivers/build_all/dts_fixup.h index f850a930835..ca9d008ed9d 100644 --- a/tests/drivers/build_all/dts_fixup.h +++ b/tests/drivers/build_all/dts_fixup.h @@ -318,6 +318,12 @@ #define DT_INST_0_HOPERF_TH02_BASE_ADDRESS 0 #endif +#ifndef DT_INST_0_TI_TMP112_LABEL +#define DT_INST_0_TI_TMP112_LABEL "" +#define DT_INST_0_TI_TMP112_BASE_ADDRESS 0 +#define DT_INST_0_TI_TMP112_BUS_NAME "" +#endif + #endif /* CONFIG_HAS_DTS_I2C */ #ifndef DT_ADXL372_DEV_NAME