sensor: tmp007: Convert to DTS

Convert tmp007 sensor driver to utilize device tree.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-11-07 05:30:26 -06:00 committed by Maureen Helm
commit c7fae66952
6 changed files with 39 additions and 56 deletions

View file

@ -11,34 +11,6 @@ menuconfig TMP007
if TMP007
config TMP007_NAME
string "Driver name"
default "TMP007"
help
Device name with which the TMP007 sensor is identified.
config TMP007_I2C_ADDR
hex "I2C address for TMP006 Sensor"
default "0x40"
help
I2C address of the TMP007 sensor.
0x40: A0 connected GND and A1 connected to GND.
0x41: A0 connected VDD and A1 connected to GND.
0x42: A0 connected SDA and A1 connected to GND.
0x43: A0 connected SCL and A1 connected to GND.
0x44: A0 connected GND and A1 connected to VDD.
0x45: A0 connected VDD and A1 connected to VDD.
0x46: A0 connected SDA and A1 connected to VDD.
0x47: A0 connected SCL and A1 connected to VDD.
config TMP007_I2C_MASTER_DEV_NAME
string "I2C master where TMP007 is connected"
default "I2C_0"
help
Specify the device name of the I2C master device to which the
TMP007 chip is connected.
choice
prompt "Trigger mode"
default TMP007_TRIGGER_NONE
@ -63,22 +35,6 @@ endchoice
config TMP007_TRIGGER
bool
config TMP007_GPIO_DEV_NAME
string "GPIO device"
default "GPIO_0"
depends on TMP007_TRIGGER
help
The device name of the GPIO device to which the TMP007 interrupt
(alert) pin is connected.
config TMP007_GPIO_PIN_NUM
int "Interrupt GPIO pin number"
default 0
depends on TMP007_TRIGGER
help
The number of the GPIO pin on which the interrupt signal from the
TMP007 chip will be received.
config TMP007_THREAD_PRIORITY
int "Thread priority"
depends on TMP007_TRIGGER_OWN_THREAD

View file

@ -117,10 +117,10 @@ int tmp007_init(struct device *dev)
{
struct tmp007_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(CONFIG_TMP007_I2C_MASTER_DEV_NAME);
drv_data->i2c = device_get_binding(DT_INST_0_TI_TMP007_BUS_NAME);
if (drv_data->i2c == NULL) {
LOG_DBG("Failed to get pointer to %s device!",
CONFIG_TMP007_I2C_MASTER_DEV_NAME);
DT_INST_0_TI_TMP007_BUS_NAME);
return -EINVAL;
}
@ -136,6 +136,7 @@ int tmp007_init(struct device *dev)
struct tmp007_data tmp007_driver;
DEVICE_AND_API_INIT(tmp007, CONFIG_TMP007_NAME, tmp007_init, &tmp007_driver,
DEVICE_AND_API_INIT(tmp007, DT_INST_0_TI_TMP007_LABEL, tmp007_init,
&tmp007_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&tmp007_driver_api);

View file

@ -11,7 +11,7 @@
#include <drivers/gpio.h>
#include <sys/util.h>
#define TMP007_I2C_ADDRESS CONFIG_TMP007_I2C_ADDR
#define TMP007_I2C_ADDRESS DT_INST_0_TI_TMP007_BASE_ADDRESS
#define TMP007_REG_CONFIG 0x02
#define TMP007_ALERT_EN_BIT BIT(8)

View file

@ -55,7 +55,7 @@ static void tmp007_gpio_callback(struct device *dev,
struct tmp007_data *drv_data =
CONTAINER_OF(cb, struct tmp007_data, gpio_cb);
gpio_pin_disable_callback(dev, CONFIG_TMP007_GPIO_PIN_NUM);
gpio_pin_disable_callback(dev, DT_INST_0_TI_TMP007_INT_GPIOS_PIN);
#if defined(CONFIG_TMP007_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem);
@ -84,7 +84,7 @@ static void tmp007_thread_cb(void *arg)
drv_data->th_handler(dev, &drv_data->th_trigger);
}
gpio_pin_enable_callback(drv_data->gpio, CONFIG_TMP007_GPIO_PIN_NUM);
gpio_pin_enable_callback(drv_data->gpio, DT_INST_0_TI_TMP007_INT_GPIOS_PIN);
}
#ifdef CONFIG_TMP007_TRIGGER_OWN_THREAD
@ -118,7 +118,7 @@ int tmp007_trigger_set(struct device *dev,
{
struct tmp007_data *drv_data = dev->driver_data;
gpio_pin_disable_callback(drv_data->gpio, CONFIG_TMP007_GPIO_PIN_NUM);
gpio_pin_disable_callback(drv_data->gpio, DT_INST_0_TI_TMP007_INT_GPIOS_PIN);
if (trig->type == SENSOR_TRIG_DATA_READY) {
drv_data->drdy_handler = handler;
@ -128,7 +128,7 @@ int tmp007_trigger_set(struct device *dev,
drv_data->th_trigger = *trig;
}
gpio_pin_enable_callback(drv_data->gpio, CONFIG_TMP007_GPIO_PIN_NUM);
gpio_pin_enable_callback(drv_data->gpio, DT_INST_0_TI_TMP007_INT_GPIOS_PIN);
return 0;
}
@ -144,20 +144,20 @@ int tmp007_init_interrupt(struct device *dev)
}
/* setup gpio interrupt */
drv_data->gpio = device_get_binding(CONFIG_TMP007_GPIO_DEV_NAME);
drv_data->gpio = device_get_binding(DT_INST_0_TI_TMP007_INT_GPIOS_CONTROLLER);
if (drv_data->gpio == NULL) {
LOG_DBG("Failed to get pointer to %s device!",
CONFIG_TMP007_GPIO_DEV_NAME);
DT_INST_0_TI_TMP007_INT_GPIOS_CONTROLLER);
return -EINVAL;
}
gpio_pin_configure(drv_data->gpio, CONFIG_TMP007_GPIO_PIN_NUM,
gpio_pin_configure(drv_data->gpio, DT_INST_0_TI_TMP007_INT_GPIOS_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL |
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
gpio_init_callback(&drv_data->gpio_cb,
tmp007_gpio_callback,
BIT(CONFIG_TMP007_GPIO_PIN_NUM));
BIT(DT_INST_0_TI_TMP007_INT_GPIOS_PIN));
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
LOG_DBG("Failed to set gpio callback!");

View file

@ -0,0 +1,17 @@
# Copyright (c) 2019, Linaro Limited
# SPDX-License-Identifier: Apache-2.0
title: TI TMP007 Digital Temperature Sensor
description: |
TMP007 Digital Temperature Sensor. See datasheet at
https://cdn-shop.adafruit.com/datasheets/tmp007.pdf
compatible: "ti,tmp007"
include: i2c-device.yaml
properties:
int-gpios:
type: phandle-array
required: false

View file

@ -324,6 +324,15 @@
#define DT_INST_0_TI_TMP112_BUS_NAME ""
#endif
#ifndef DT_INST_0_TI_TMP007_LABEL
#define DT_INST_0_TI_TMP007_LABEL ""
#define DT_INST_0_TI_TMP007_BASE_ADDRESS 0
#define DT_INST_0_TI_TMP007_BUS_NAME ""
#define DT_INST_0_TI_TMP007_INT_GPIOS_CONTROLLER ""
#define DT_INST_0_TI_TMP007_INT_GPIOS_FLAGS 0
#define DT_INST_0_TI_TMP007_INT_GPIOS_PIN 0
#endif
#endif /* CONFIG_HAS_DTS_I2C */
#ifndef DT_ADXL372_DEV_NAME