From ddddbf9f84e718fbe07c7fdaa2b86b1ef2aeca8d Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 7 Nov 2019 06:26:52 -0600 Subject: [PATCH] sensor: max44009: Convert to DTS Convert max44009 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/max44009/Kconfig | 29 +------------------ drivers/sensor/max44009/max44009.c | 6 ++-- drivers/sensor/max44009/max44009.h | 2 +- dts/bindings/sensor/maxim,max44009.yaml | 17 +++++++++++ .../sensor/max44009/boards/frdm_k64f.overlay | 14 +++++++++ samples/sensor/max44009/sample.yaml | 1 + tests/drivers/build_all/dts_fixup.h | 9 ++++++ 7 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 dts/bindings/sensor/maxim,max44009.yaml create mode 100644 samples/sensor/max44009/boards/frdm_k64f.overlay diff --git a/drivers/sensor/max44009/Kconfig b/drivers/sensor/max44009/Kconfig index 9721e17f26e..02f6d2b781d 100644 --- a/drivers/sensor/max44009/Kconfig +++ b/drivers/sensor/max44009/Kconfig @@ -3,35 +3,8 @@ # Copyright (c) 2016 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -menuconfig MAX44009 +config MAX44009 bool "MAX44009 Light Sensor" depends on I2C help Enable driver for MAX44009 light sensors. - -if MAX44009 - -config MAX44009_DRV_NAME - string "Driver name" - default "MAX44009" - help - Device name with which the MAX44009 light is identified. - - -config MAX44009_I2C_ADDR - hex "MAX44009 I2C address" - default "0x4a" - help - I2C address of the MAX44009 sensor. Possible configurations: - - 0x4a: A0 connected to GND. - 0x4b: A0 connected to VCC. - -config MAX44009_I2C_DEV_NAME - string "I2C master where MAX44009 is connected" - default "I2C_0" - help - Specify the device name of the I2C master device to which the - MAX44009 chip is connected. - -endif # MAX44009 diff --git a/drivers/sensor/max44009/max44009.c b/drivers/sensor/max44009/max44009.c index e60876d9cf9..982f93d3a1e 100644 --- a/drivers/sensor/max44009/max44009.c +++ b/drivers/sensor/max44009/max44009.c @@ -171,10 +171,10 @@ int max44009_init(struct device *dev) { struct max44009_data *drv_data = dev->driver_data; - drv_data->i2c = device_get_binding(CONFIG_MAX44009_I2C_DEV_NAME); + drv_data->i2c = device_get_binding(DT_INST_0_MAXIM_MAX44009_BUS_NAME); if (drv_data->i2c == NULL) { LOG_DBG("Failed to get pointer to %s device!", - CONFIG_MAX44009_I2C_DEV_NAME); + DT_INST_0_MAXIM_MAX44009_BUS_NAME); return -EINVAL; } @@ -183,6 +183,6 @@ int max44009_init(struct device *dev) static struct max44009_data max44009_drv_data; -DEVICE_AND_API_INIT(max44009, CONFIG_MAX44009_DRV_NAME, max44009_init, +DEVICE_AND_API_INIT(max44009, DT_INST_0_MAXIM_MAX44009_LABEL, max44009_init, &max44009_drv_data, NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &max44009_driver_api); diff --git a/drivers/sensor/max44009/max44009.h b/drivers/sensor/max44009/max44009.h index 820fac7bdff..a9f74d9d835 100644 --- a/drivers/sensor/max44009/max44009.h +++ b/drivers/sensor/max44009/max44009.h @@ -9,7 +9,7 @@ #include -#define MAX44009_I2C_ADDRESS CONFIG_MAX44009_I2C_ADDR +#define MAX44009_I2C_ADDRESS DT_INST_0_MAXIM_MAX44009_BASE_ADDRESS #define MAX44009_SAMPLING_CONTROL_BIT BIT(7) #define MAX44009_CONTINUOUS_SAMPLING BIT(7) diff --git a/dts/bindings/sensor/maxim,max44009.yaml b/dts/bindings/sensor/maxim,max44009.yaml new file mode 100644 index 00000000000..19626564ef2 --- /dev/null +++ b/dts/bindings/sensor/maxim,max44009.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2019, Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +title: Maxim MAX44009 Ambient Light Sensor + +description: | + Maxim MAX44009 Ambient Light Sensor. See datasheet at + https://datasheets.maximintegrated.com/en/ds/MAX44009.pdf + +compatible: "maxim,max44009" + +include: i2c-device.yaml + +properties: + int-gpios: + type: phandle-array + required: false diff --git a/samples/sensor/max44009/boards/frdm_k64f.overlay b/samples/sensor/max44009/boards/frdm_k64f.overlay new file mode 100644 index 00000000000..fb13ccb7b49 --- /dev/null +++ b/samples/sensor/max44009/boards/frdm_k64f.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019, Linaro Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c0 { + max44009@4a { + compatible = "maxim,max44009"; + reg = <0x4a>; + int-gpios = <&gpioc 6 0>; + label = "MAX44009"; + }; +}; diff --git a/samples/sensor/max44009/sample.yaml b/samples/sensor/max44009/sample.yaml index 252de02aa2f..142f39aaa92 100644 --- a/samples/sensor/max44009/sample.yaml +++ b/samples/sensor/max44009/sample.yaml @@ -12,3 +12,4 @@ tests: - "MAX44009 light sensor application" - "sensor: lum reading: (.*)" fixture: fixture_i2c_max44009 + filter: dt_compat_enabled("maxim,max44009") diff --git a/tests/drivers/build_all/dts_fixup.h b/tests/drivers/build_all/dts_fixup.h index b0756761343..d2467268fb2 100644 --- a/tests/drivers/build_all/dts_fixup.h +++ b/tests/drivers/build_all/dts_fixup.h @@ -351,6 +351,15 @@ #define DT_INST_0_MICROCHIP_MCP9808_INT_GPIOS_PIN 0 #endif +#ifndef DT_INST_0_MAXIM_MAX44009_LABEL +#define DT_INST_0_MAXIM_MAX44009_LABEL "" +#define DT_INST_0_MAXIM_MAX44009_BASE_ADDRESS 0 +#define DT_INST_0_MAXIM_MAX44009_BUS_NAME "" +#define DT_INST_0_MAXIM_MAX44009_INT_GPIOS_CONTROLLER "" +#define DT_INST_0_MAXIM_MAX44009_INT_GPIOS_FLAGS 0 +#define DT_INST_0_MAXIM_MAX44009_INT_GPIOS_PIN 0 +#endif + #endif /* CONFIG_HAS_DTS_I2C */ #ifndef DT_ADXL372_DEV_NAME