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 <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-11-07 06:26:52 -06:00 committed by Maureen Helm
commit ddddbf9f84
7 changed files with 46 additions and 32 deletions

View file

@ -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

View file

@ -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);

View file

@ -9,7 +9,7 @@
#include <sys/util.h>
#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)

View file

@ -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

View file

@ -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";
};
};

View file

@ -12,3 +12,4 @@ tests:
- "MAX44009 light sensor application"
- "sensor: lum reading: (.*)"
fixture: fixture_i2c_max44009
filter: dt_compat_enabled("maxim,max44009")

View file

@ -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