From 62b2cae2ae2c3ec96dc7afc905be5a9a1a78edb0 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Mon, 27 Jan 2020 15:29:13 +0100 Subject: [PATCH] drivers/ieee802154: Adapt cc1200 driver to new GPIO API Update to use new API for GPIO pin configuration and operation. Fix invalid arithmetic on void pointer. Convert to support devicetree. Signed-off-by: Tomasz Bursztyka Signed-off-by: Peter Bigot --- drivers/ieee802154/ieee802154_cc1200.c | 75 +++++++++++++++----------- drivers/ieee802154/ieee802154_cc1200.h | 21 +++++++- dts/bindings/ieee802154/ti,cc1200.yaml | 5 ++ include/drivers/ieee802154/cc1200.h | 23 +------- 4 files changed, 69 insertions(+), 55 deletions(-) diff --git a/drivers/ieee802154/ieee802154_cc1200.c b/drivers/ieee802154/ieee802154_cc1200.c index fa90eca45c8..483d312e65c 100644 --- a/drivers/ieee802154/ieee802154_cc1200.c +++ b/drivers/ieee802154/ieee802154_cc1200.c @@ -200,15 +200,10 @@ static inline void gpio0_int_handler(struct device *port, static void enable_gpio0_interrupt(struct cc1200_context *cc1200, bool enable) { - if (enable) { - gpio_pin_enable_callback( - cc1200->gpios[CC1200_GPIO_IDX_GPIO0].dev, - cc1200->gpios[CC1200_GPIO_IDX_GPIO0].pin); - } else { - gpio_pin_disable_callback( - cc1200->gpios[CC1200_GPIO_IDX_GPIO0].dev, - cc1200->gpios[CC1200_GPIO_IDX_GPIO0].pin); - } + gpio_pin_interrupt_configure( + cc1200->gpios[CC1200_GPIO_IDX_GPIO0].dev, + cc1200->gpios[CC1200_GPIO_IDX_GPIO0].pin, + enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE); } static void setup_gpio_callback(struct device *dev) @@ -333,8 +328,8 @@ rf_install_settings(struct device *dev, (void *)rf_settings->registers, CC1200_RF_NON_EXT_SPACE_REGS, false, true) || !z_cc1200_access_reg(cc1200, false, CC1200_REG_IF_MIX_CFG, - (void *)rf_settings->registers + - CC1200_RF_NON_EXT_SPACE_REGS, + (u8_t *)rf_settings->registers + + CC1200_RF_NON_EXT_SPACE_REGS, CC1200_RF_EXT_SPACE_REGS, true, true) || !write_reg_pkt_len(cc1200, 0xFF)) { LOG_ERR("Could not install RF settings"); @@ -732,37 +727,54 @@ static int power_on_and_setup(struct device *dev) return rf_calibrate(cc1200); } +static struct cc1200_gpio_configuration *configure_gpios(struct device *dev) +{ + struct cc1200_context *cc1200 = dev->driver_data; + struct device *gpio = device_get_binding(DT_INST_0_TI_CC1200_INT_GPIOS_CONTROLLER); + + if (!gpio) { + return NULL; + } + + cc1200->gpios[CC1200_GPIO_IDX_GPIO0].pin = DT_INST_0_TI_CC1200_INT_GPIOS_PIN; + gpio_pin_configure(gpio, cc1200->gpios[CC1200_GPIO_IDX_GPIO0].pin, + GPIO_INPUT | DT_INST_0_TI_CC1200_INT_GPIOS_FLAGS); + cc1200->gpios[CC1200_GPIO_IDX_GPIO0].dev = gpio; + + return cc1200->gpios; +} + static int configure_spi(struct device *dev) { struct cc1200_context *cc1200 = dev->driver_data; - cc1200->spi = device_get_binding(DT_IEEE802154_CC1200_SPI_DRV_NAME); + cc1200->spi = device_get_binding(DT_INST_0_TI_CC1200_BUS_NAME); if (!cc1200->spi) { LOG_ERR("Unable to get SPI device"); return -ENODEV; } - if (IS_ENABLED(CONFIG_IEEE802154_CC1200_GPIO_SPI_CS)) { - cs_ctrl.gpio_dev = device_get_binding( - DT_IEEE802154_CC1200_GPIO_SPI_CS_DRV_NAME); - if (!cs_ctrl.gpio_dev) { - LOG_ERR("Unable to get GPIO SPI CS device"); - return -ENODEV; - } - - cs_ctrl.gpio_pin = DT_IEEE802154_CC1200_GPIO_SPI_CS_PIN; - cs_ctrl.delay = 0U; - - cc1200->spi_cfg.cs = &cs_ctrl; - - LOG_DBG("SPI GPIO CS configured on %s:%u", - DT_IEEE802154_CC1200_GPIO_SPI_CS_DRV_NAME, - DT_IEEE802154_CC1200_GPIO_SPI_CS_PIN); +#if defined(CONFIG_IEEE802154_CC1200_GPIO_SPI_CS) + cs_ctrl.gpio_dev = device_get_binding( + DT_INST_0_TI_CC1200_CS_GPIOS_CONTROLLER); + if (!cs_ctrl.gpio_dev) { + LOG_ERR("Unable to get GPIO SPI CS device"); + return -ENODEV; } + cs_ctrl.gpio_pin = DT_INST_0_TI_CC1200_CS_GPIOS_PIN; + cs_ctrl.delay = 0U; + + cc1200->spi_cfg.cs = &cs_ctrl; + + LOG_DBG("SPI GPIO CS configured on %s:%u", + DT_INST_0_TI_CC1200_CS_GPIOS_CONTROLLER, + DT_INST_0_TI_CC1200_CS_GPIOS_PIN); +#endif /* CONFIG_IEEE802154_CC1200_GPIO_SPI_CS */ + cc1200->spi_cfg.operation = SPI_WORD_SET(8); - cc1200->spi_cfg.frequency = DT_IEEE802154_CC1200_SPI_FREQ; - cc1200->spi_cfg.slave = DT_IEEE802154_CC1200_SPI_SLAVE; + cc1200->spi_cfg.frequency = DT_INST_0_TI_CC1200_SPI_MAX_FREQUENCY; + cc1200->spi_cfg.slave = DT_INST_0_TI_CC1200_BASE_ADDRESS; return 0; } @@ -777,8 +789,7 @@ static int cc1200_init(struct device *dev) k_sem_init(&cc1200->rx_lock, 0, 1); k_sem_init(&cc1200->tx_sync, 0, 1); - cc1200->gpios = cc1200_configure_gpios(); - if (!cc1200->gpios) { + if (!configure_gpios(dev)) { LOG_ERR("Configuring GPIOS failed"); return -EIO; } diff --git a/drivers/ieee802154/ieee802154_cc1200.h b/drivers/ieee802154/ieee802154_cc1200.h index 82464fe6a3c..70271f93969 100644 --- a/drivers/ieee802154/ieee802154_cc1200.h +++ b/drivers/ieee802154/ieee802154_cc1200.h @@ -15,6 +15,25 @@ #include +/* Note for EMK & EM adapter booster pack users: + * SPI pins are easy, RESET as well, but when it comes to GPIO: + * CHIP -> EM adapter + * GPIO0 -> GPIOA + * GPIO1 -> reserved (it's SPI MISO) + * GPIO2 -> GPIOB + * GPIO3 -> GPIO3 + */ + +enum cc1200_gpio_index { + CC1200_GPIO_IDX_GPIO0, + CC1200_GPIO_IDX_MAX, +}; + +struct cc1200_gpio_configuration { + struct device *dev; + u32_t pin; +}; + /* Runtime context structure *************************** */ @@ -22,7 +41,7 @@ struct cc1200_context { struct net_if *iface; /**************************/ - struct cc1200_gpio_configuration *gpios; + struct cc1200_gpio_configuration gpios[CC1200_GPIO_IDX_MAX]; struct gpio_callback rx_tx_cb; struct device *spi; struct spi_config spi_cfg; diff --git a/dts/bindings/ieee802154/ti,cc1200.yaml b/dts/bindings/ieee802154/ti,cc1200.yaml index 03184f9cdb7..492d82dda39 100644 --- a/dts/bindings/ieee802154/ti,cc1200.yaml +++ b/dts/bindings/ieee802154/ti,cc1200.yaml @@ -6,3 +6,8 @@ description: Texas Instruments CC1200 802.15.4 wireless transceiver compatible: "ti,cc1200" include: spi-device.yaml + +properties: + int-gpios: + type: phandle-array + required: true diff --git a/include/drivers/ieee802154/cc1200.h b/include/drivers/ieee802154/cc1200.h index 6a1fe9e02e8..3c14e8b3e32 100644 --- a/include/drivers/ieee802154/cc1200.h +++ b/include/drivers/ieee802154/cc1200.h @@ -17,7 +17,7 @@ * extended address 0x00 to 0x39 included * * If CONFIG_IEEE802154_CC1200_RF_PRESET is not used, one will need - * no provide 'cc1200_rf_settings' with proper settings. These can + * to provide 'cc1200_rf_settings' with proper settings. These can * be generated through TI's SmartRF application. * */ @@ -35,25 +35,4 @@ struct cc1200_rf_registers_set { extern const struct cc1200_rf_registers_set cc1200_rf_settings; #endif -/* Note for EMK & EM adapter booster pack users: - * SPI pins are easy, RESET as well, but when it comes to GPIO: - * CHIP -> EM adapter - * GPIO0 -> GPIOA - * GPIO1 -> reserved (it's SPI MISO) - * GPIO2 -> GPIOB - * GPIO3 -> GPIO3 - */ - -enum cc1200_gpio_index { - CC1200_GPIO_IDX_GPIO0, - CC1200_GPIO_IDX_MAX, -}; - -struct cc1200_gpio_configuration { - struct device *dev; - u32_t pin; -}; - -struct cc1200_gpio_configuration *cc1200_configure_gpios(void); - #endif /* ZEPHYR_INCLUDE_DRIVERS_IEEE802154_CC1200_H_ */