sensor: isl29035: Convert to DTS

Convert isl29035 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 09:38:21 -06:00 committed by Maureen Helm
commit c2aa25b358
6 changed files with 41 additions and 39 deletions

View file

@ -11,19 +11,6 @@ menuconfig ISL29035
if ISL29035
config ISL29035_NAME
string "Driver name"
default "ISL29035"
help
Device name with which the ISL29035 sensor is identified.
config ISL29035_I2C_MASTER_DEV_NAME
string "I2C Master"
default "I2C_0"
help
The device name of the I2C master device to which the ISL29035
chip is connected.
config ISL29035_THREAD_PRIORITY
int "Thread priority"
default 10
@ -117,22 +104,6 @@ endchoice
config ISL29035_TRIGGER
bool
config ISL29035_GPIO_DEV_NAME
string "GPIO device"
default "GPIO_0"
depends on ISL29035_TRIGGER
help
The device name of the GPIO device to which the ISL29035 interrupt
pin is connected.
config ISL29035_GPIO_PIN_NUM
int "GPIO pin number"
default 0
depends on ISL29035_TRIGGER
help
The number of the GPIO pin to which the ISL29035 interrupt pin is
connected.
config ISL29035_THREAD_PRIORITY
int "Thread priority"
depends on ISL29035_TRIGGER_OWN_THREAD

View file

@ -74,7 +74,7 @@ static int isl29035_init(struct device *dev)
{
struct isl29035_driver_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(CONFIG_ISL29035_I2C_MASTER_DEV_NAME);
drv_data->i2c = device_get_binding(DT_INST_0_ISIL_ISL29035_BUS_NAME);
if (drv_data->i2c == NULL) {
LOG_DBG("Failed to get I2C device.");
return -EINVAL;
@ -141,6 +141,6 @@ static int isl29035_init(struct device *dev)
struct isl29035_driver_data isl29035_data;
DEVICE_AND_API_INIT(isl29035_dev, CONFIG_ISL29035_NAME, &isl29035_init,
DEVICE_AND_API_INIT(isl29035_dev, DT_INST_0_ISIL_ISL29035_LABEL, &isl29035_init,
&isl29035_data, NULL, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &isl29035_api);

View file

@ -14,7 +14,7 @@
#include <drivers/sensor.h>
#include <drivers/gpio.h>
#define ISL29035_I2C_ADDRESS 0x44
#define ISL29035_I2C_ADDRESS DT_INST_0_ISIL_ISL29035_BASE_ADDRESS
#define ISL29035_COMMAND_I_REG 0x00
#define ISL29035_OPMODE_SHIFT 5

View file

@ -67,7 +67,7 @@ static void isl29035_gpio_callback(struct device *dev,
ARG_UNUSED(pins);
gpio_pin_disable_callback(dev, CONFIG_ISL29035_GPIO_PIN_NUM);
gpio_pin_disable_callback(dev, DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
#if defined(CONFIG_ISL29035_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem);
@ -92,7 +92,8 @@ static void isl29035_thread_cb(struct device *dev)
drv_data->th_handler(dev, &drv_data->th_trigger);
}
gpio_pin_enable_callback(drv_data->gpio, CONFIG_ISL29035_GPIO_PIN_NUM);
gpio_pin_enable_callback(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
}
#ifdef CONFIG_ISL29035_TRIGGER_OWN_THREAD
@ -127,13 +128,15 @@ int isl29035_trigger_set(struct device *dev,
struct isl29035_driver_data *drv_data = dev->driver_data;
/* disable interrupt callback while changing parameters */
gpio_pin_disable_callback(drv_data->gpio, CONFIG_ISL29035_GPIO_PIN_NUM);
gpio_pin_disable_callback(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
drv_data->th_handler = handler;
drv_data->th_trigger = *trig;
/* enable interrupt callback */
gpio_pin_enable_callback(drv_data->gpio, CONFIG_ISL29035_GPIO_PIN_NUM);
gpio_pin_enable_callback(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN);
return 0;
}
@ -152,19 +155,21 @@ int isl29035_init_interrupt(struct device *dev)
}
/* setup gpio interrupt */
drv_data->gpio = device_get_binding(CONFIG_ISL29035_GPIO_DEV_NAME);
drv_data->gpio =
device_get_binding(DT_INST_0_ISIL_ISL29035_INT_GPIOS_CONTROLLER);
if (drv_data->gpio == NULL) {
LOG_DBG("Failed to get GPIO device.");
return -EINVAL;
}
gpio_pin_configure(drv_data->gpio, CONFIG_ISL29035_GPIO_PIN_NUM,
gpio_pin_configure(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL |
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
gpio_init_callback(&drv_data->gpio_cb,
isl29035_gpio_callback,
BIT(CONFIG_ISL29035_GPIO_PIN_NUM));
BIT(DT_INST_0_ISIL_ISL29035_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: Intersil ISL29035 Light Sensor
description: |
Intersil ISL29035 Light Sensor. See datasheet at
https://www.renesas.com/us/en/www/doc/datasheet/isl29035.pdf
compatible: "isil,isl29035"
include: i2c-device.yaml
properties:
int-gpios:
type: phandle-array
required: false

View file

@ -360,6 +360,15 @@
#define DT_INST_0_MAXIM_MAX44009_INT_GPIOS_PIN 0
#endif
#ifndef DT_INST_0_ISIL_ISL29035_LABEL
#define DT_INST_0_ISIL_ISL29035_LABEL ""
#define DT_INST_0_ISIL_ISL29035_BASE_ADDRESS 0
#define DT_INST_0_ISIL_ISL29035_BUS_NAME ""
#define DT_INST_0_ISIL_ISL29035_INT_GPIOS_CONTROLLER ""
#define DT_INST_0_ISIL_ISL29035_INT_GPIOS_FLAGS 0
#define DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN 0
#endif
#endif /* CONFIG_HAS_DTS_I2C */
#ifndef DT_ADXL372_DEV_NAME