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 <tomasz.bursztyka@linux.intel.com> Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
3587fe2fe3
commit
62b2cae2ae
4 changed files with 69 additions and 55 deletions
|
@ -200,15 +200,10 @@ static inline void gpio0_int_handler(struct device *port,
|
||||||
|
|
||||||
static void enable_gpio0_interrupt(struct cc1200_context *cc1200, bool enable)
|
static void enable_gpio0_interrupt(struct cc1200_context *cc1200, bool enable)
|
||||||
{
|
{
|
||||||
if (enable) {
|
gpio_pin_interrupt_configure(
|
||||||
gpio_pin_enable_callback(
|
cc1200->gpios[CC1200_GPIO_IDX_GPIO0].dev,
|
||||||
cc1200->gpios[CC1200_GPIO_IDX_GPIO0].dev,
|
cc1200->gpios[CC1200_GPIO_IDX_GPIO0].pin,
|
||||||
cc1200->gpios[CC1200_GPIO_IDX_GPIO0].pin);
|
enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE);
|
||||||
} else {
|
|
||||||
gpio_pin_disable_callback(
|
|
||||||
cc1200->gpios[CC1200_GPIO_IDX_GPIO0].dev,
|
|
||||||
cc1200->gpios[CC1200_GPIO_IDX_GPIO0].pin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_gpio_callback(struct device *dev)
|
static void setup_gpio_callback(struct device *dev)
|
||||||
|
@ -333,8 +328,8 @@ rf_install_settings(struct device *dev,
|
||||||
(void *)rf_settings->registers,
|
(void *)rf_settings->registers,
|
||||||
CC1200_RF_NON_EXT_SPACE_REGS, false, true) ||
|
CC1200_RF_NON_EXT_SPACE_REGS, false, true) ||
|
||||||
!z_cc1200_access_reg(cc1200, false, CC1200_REG_IF_MIX_CFG,
|
!z_cc1200_access_reg(cc1200, false, CC1200_REG_IF_MIX_CFG,
|
||||||
(void *)rf_settings->registers +
|
(u8_t *)rf_settings->registers
|
||||||
CC1200_RF_NON_EXT_SPACE_REGS,
|
+ CC1200_RF_NON_EXT_SPACE_REGS,
|
||||||
CC1200_RF_EXT_SPACE_REGS, true, true) ||
|
CC1200_RF_EXT_SPACE_REGS, true, true) ||
|
||||||
!write_reg_pkt_len(cc1200, 0xFF)) {
|
!write_reg_pkt_len(cc1200, 0xFF)) {
|
||||||
LOG_ERR("Could not install RF settings");
|
LOG_ERR("Could not install RF settings");
|
||||||
|
@ -732,37 +727,54 @@ static int power_on_and_setup(struct device *dev)
|
||||||
return rf_calibrate(cc1200);
|
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)
|
static int configure_spi(struct device *dev)
|
||||||
{
|
{
|
||||||
struct cc1200_context *cc1200 = dev->driver_data;
|
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) {
|
if (!cc1200->spi) {
|
||||||
LOG_ERR("Unable to get SPI device");
|
LOG_ERR("Unable to get SPI device");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_IEEE802154_CC1200_GPIO_SPI_CS)) {
|
#if defined(CONFIG_IEEE802154_CC1200_GPIO_SPI_CS)
|
||||||
cs_ctrl.gpio_dev = device_get_binding(
|
cs_ctrl.gpio_dev = device_get_binding(
|
||||||
DT_IEEE802154_CC1200_GPIO_SPI_CS_DRV_NAME);
|
DT_INST_0_TI_CC1200_CS_GPIOS_CONTROLLER);
|
||||||
if (!cs_ctrl.gpio_dev) {
|
if (!cs_ctrl.gpio_dev) {
|
||||||
LOG_ERR("Unable to get GPIO SPI CS device");
|
LOG_ERR("Unable to get GPIO SPI CS device");
|
||||||
return -ENODEV;
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.operation = SPI_WORD_SET(8);
|
||||||
cc1200->spi_cfg.frequency = DT_IEEE802154_CC1200_SPI_FREQ;
|
cc1200->spi_cfg.frequency = DT_INST_0_TI_CC1200_SPI_MAX_FREQUENCY;
|
||||||
cc1200->spi_cfg.slave = DT_IEEE802154_CC1200_SPI_SLAVE;
|
cc1200->spi_cfg.slave = DT_INST_0_TI_CC1200_BASE_ADDRESS;
|
||||||
|
|
||||||
return 0;
|
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->rx_lock, 0, 1);
|
||||||
k_sem_init(&cc1200->tx_sync, 0, 1);
|
k_sem_init(&cc1200->tx_sync, 0, 1);
|
||||||
|
|
||||||
cc1200->gpios = cc1200_configure_gpios();
|
if (!configure_gpios(dev)) {
|
||||||
if (!cc1200->gpios) {
|
|
||||||
LOG_ERR("Configuring GPIOS failed");
|
LOG_ERR("Configuring GPIOS failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,25 @@
|
||||||
|
|
||||||
#include <drivers/ieee802154/cc1200.h>
|
#include <drivers/ieee802154/cc1200.h>
|
||||||
|
|
||||||
|
/* 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
|
/* Runtime context structure
|
||||||
***************************
|
***************************
|
||||||
*/
|
*/
|
||||||
|
@ -22,7 +41,7 @@
|
||||||
struct cc1200_context {
|
struct cc1200_context {
|
||||||
struct net_if *iface;
|
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 gpio_callback rx_tx_cb;
|
||||||
struct device *spi;
|
struct device *spi;
|
||||||
struct spi_config spi_cfg;
|
struct spi_config spi_cfg;
|
||||||
|
|
|
@ -6,3 +6,8 @@ description: Texas Instruments CC1200 802.15.4 wireless transceiver
|
||||||
compatible: "ti,cc1200"
|
compatible: "ti,cc1200"
|
||||||
|
|
||||||
include: spi-device.yaml
|
include: spi-device.yaml
|
||||||
|
|
||||||
|
properties:
|
||||||
|
int-gpios:
|
||||||
|
type: phandle-array
|
||||||
|
required: true
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* extended address 0x00 to 0x39 included
|
* extended address 0x00 to 0x39 included
|
||||||
*
|
*
|
||||||
* If CONFIG_IEEE802154_CC1200_RF_PRESET is not used, one will need
|
* 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.
|
* 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;
|
extern const struct cc1200_rf_registers_set cc1200_rf_settings;
|
||||||
#endif
|
#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_ */
|
#endif /* ZEPHYR_INCLUDE_DRIVERS_IEEE802154_CC1200_H_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue