drivers: can: mcp2515: Switch to new GPIO API

Mark the INT signal to be active low and use the new functions to get
gpio state and configure the gpio interrupt flanks.

Signed-off-by: Karsten Koenig <karsten.koenig.030@gmail.com>
This commit is contained in:
Karsten Koenig 2019-11-07 20:16:06 +01:00 committed by Carles Cufí
commit 4897c95462
3 changed files with 16 additions and 10 deletions

View file

@ -11,7 +11,7 @@
can1: mcp2515@0 {
compatible = "microchip,mcp2515";
spi-max-frequency = <1000000>;
int-gpios = <&arduino_header 8 0>; /* D2 */
int-gpios = <&arduino_header 8 GPIO_ACTIVE_LOW>; /* D2 */
status = "okay";
label = "CAN_1";
reg = <0x0>;

View file

@ -639,11 +639,10 @@ static void mcp2515_handle_interrupts(struct device *dev)
{
const struct mcp2515_config *dev_cfg = DEV_CFG(dev);
struct mcp2515_data *dev_data = DEV_DATA(dev);
u32_t pin;
int ret;
u8_t canintf;
/* Loop until INT pin is high (all interrupt flags handled) */
/* Loop until INT pin is inactive (all interrupt flags handled) */
while (1) {
ret = mcp2515_cmd_read_reg(dev, MCP2515_ADDR_CANINTF,
&canintf, 1);
@ -693,11 +692,11 @@ static void mcp2515_handle_interrupts(struct device *dev)
canintf, ~canintf);
}
/* Break from loop if INT pin is no longer low */
ret = gpio_pin_read(dev_data->int_gpio, dev_cfg->int_pin, &pin);
if (ret != 0) {
/* Break from loop if INT pin is inactive */
ret = gpio_pin_get(dev_data->int_gpio, dev_cfg->int_pin);
if (ret < 0) {
LOG_ERR("Couldn't read INT pin");
} else if (pin != 0) {
} else if (ret == 0) {
/* All interrupt flags handled */
break;
}
@ -790,8 +789,8 @@ static int mcp2515_init(struct device *dev)
}
if (gpio_pin_configure(dev_data->int_gpio, dev_cfg->int_pin,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE
| GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE))) {
(GPIO_INPUT |
DT_INST_0_MICROCHIP_MCP2515_INT_GPIOS_FLAGS))) {
LOG_ERR("Unable to configure GPIO pin %u", dev_cfg->int_pin);
return -EINVAL;
}
@ -803,7 +802,8 @@ static int mcp2515_init(struct device *dev)
return -EINVAL;
}
if (gpio_pin_enable_callback(dev_data->int_gpio, dev_cfg->int_pin)) {
if (gpio_pin_interrupt_configure(dev_data->int_gpio, dev_cfg->int_pin,
GPIO_INT_EDGE_TO_ACTIVE)) {
return -EINVAL;
}

View file

@ -15,6 +15,12 @@ properties:
int-gpios:
type: phandle-array
required: true
description: >
Interrupt pin.
This pin signals active low when produced by the controller. The
property value should ensure the flags properly describe the signal
that is presented to the driver.
reg:
type: array
required: true