Commit 51503a23 authored by Tomasz Bursztyka's avatar Tomasz Bursztyka Committed by Anas Nashif
Browse files

cc2520: Using new GPIO API callbacks



Adapting CC2520 driver to use the new callback format. That way, cc2520
will work on boards where FIFOP and SFD are hooked to a different GPIO
controller.

Change-Id: Ia40b17867000de26f332f36422f84bb3f20be2aa
Signed-off-by: default avatarTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
parent 8386a499
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -332,9 +332,11 @@ static inline uint32_t get_cca(struct cc2520_context *cc2520)
	return pin_value;
}

static inline void sfd_int_handler(struct device *port, uint32_t pin)
static inline void sfd_int_handler(struct device *port,
				   struct gpio_callback *cb, uint32_t pins)
{
	struct cc2520_context *cc2520 = cc2520_sglt->driver_data;
	struct cc2520_context *cc2520 =
		CONTAINER_OF(cb, struct cc2520_context, sfd_cb);

	if (atomic_get(&cc2520->tx) == 1) {
		atomic_set(&cc2520->tx, 0);
@@ -342,9 +344,11 @@ static inline void sfd_int_handler(struct device *port, uint32_t pin)
	}
}

static inline void fifop_int_handler(struct device *port, uint32_t pin)
static inline void fifop_int_handler(struct device *port,
				     struct gpio_callback *cb, uint32_t pins)
{
	struct cc2520_context *cc2520 = cc2520_sglt->driver_data;
	struct cc2520_context *cc2520 =
		CONTAINER_OF(cb, struct cc2520_context, fifop_cb);

	/* Note: Errata document - 1.2 */
	if (!get_fifop(cc2520) && !get_fifop(cc2520)) {
@@ -358,15 +362,6 @@ static inline void fifop_int_handler(struct device *port, uint32_t pin)
	nano_isr_sem_give(&cc2520->rx_lock);
}

static void gpio_int_handler(struct device *port, uint32_t pin)
{
	if (pin == CONFIG_CC2520_GPIO_SFD) {
		sfd_int_handler(port, pin);
	} else if (pin == CONFIG_CC2520_GPIO_FIFOP) {
		fifop_int_handler(port, pin);
	}
}

static void enable_fifop_interrupt(struct cc2520_context *cc2520,
				   bool enable)
{
@@ -395,10 +390,15 @@ static inline void setup_gpio_callbacks(struct device *dev)
{
	struct cc2520_context *cc2520 = dev->driver_data;

	gpio_set_callback(cc2520->gpios[CC2520_GPIO_IDX_FIFOP],
			  gpio_int_handler);
	gpio_set_callback(cc2520->gpios[CC2520_GPIO_IDX_SFD],
			  gpio_int_handler);
	gpio_init_callback(&cc2520->sfd_cb,
			   sfd_int_handler, BIT(CONFIG_CC2520_GPIO_SFD));
	gpio_add_callback(cc2520->gpios[CC2520_GPIO_IDX_SFD],
			  &cc2520->sfd_cb);

	gpio_init_callback(&cc2520->fifop_cb,
			   fifop_int_handler, BIT(CONFIG_CC2520_GPIO_FIFOP));
	gpio_add_callback(cc2520->gpios[CC2520_GPIO_IDX_FIFOP],
			  &cc2520->fifop_cb);
}


+2 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ struct cc2520_spi {
struct cc2520_context {
	/**************************/
	struct device **gpios;
	struct gpio_callback sfd_cb;
	struct gpio_callback fifop_cb;
	struct cc2520_spi spi;
	uint8_t mac_addr[8];
	/************TX************/