changeset 3877:17707fd0e782

efm32/driver/i2c: Fix I2C slave driver for EFM32 There was some issue in conditional code.
author Nicolas Pouillon <nipo@ssji.net>
date Mon, 16 Apr 2018 22:15:01 +0200
parents 0f0878646852
children 314be02153ca 08933f6eaff1
files arch/efm32/drivers/i2c/i2c_slave.c arch/efm32/include/arch/efm32/efm/leopard/clock.h
diffstat 2 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/arch/efm32/drivers/i2c/i2c_slave.c	Mon Apr 16 22:13:19 2018 +0200
+++ b/arch/efm32/drivers/i2c/i2c_slave.c	Mon Apr 16 22:15:01 2018 +0200
@@ -234,12 +234,12 @@
       logk_debug("%s state %d irq %04x mask %04x left %04x", __func__, pv->state,
                  rirq, mask, irq);
 
+      /* Reset interrupts flags */
+      cpu_mem_write_32(pv->addr + EFM32_I2C_IFC_ADDR, endian_le32(rirq));
+
       if (!irq)
         return;
 
-      /* Reset interrupts flags */
-      cpu_mem_write_32(pv->addr + EFM32_I2C_IFC_ADDR, endian_le32(rirq));
-
       /* End of data phase conditions */
       if (irq & (EFM32_I2C_IF_RSTART | EFM32_I2C_IF_SSTOP | EFM32_I2C_IF_ARBLOST))
         {
@@ -348,17 +348,19 @@
         {
           logk_debug(" nack");
 
-          assert(pv->state == STATE_TRANSMITTING);
+          if (pv->state == STATE_TRANSMITTING)
+            {
+              struct dev_i2c_slave_rq_s *rq
+                = dev_i2c_slave_rq_s_cast(dev_request_queue_head(&pv->queue));
 
-          struct dev_i2c_slave_rq_s *rq
-            = dev_i2c_slave_rq_s_cast(dev_request_queue_head(&pv->queue));
-
-          assert(rq);
-
-          rq->transfer.end_ack = 0;
-          efm32_i2c_slave_rq_end(pv, rq, 0);
-          efm32_i2c_slave_data_queue_cancel(pv);
-          efm32_i2c_slave_idle_setup(pv);
+              if (rq)
+                {
+                  rq->transfer.end_ack = 0;
+                  efm32_i2c_slave_rq_end(pv, rq, 0);
+                }
+              efm32_i2c_slave_data_queue_cancel(pv);
+              efm32_i2c_slave_idle_setup(pv);
+            }
         }
     }
  
@@ -480,7 +482,6 @@
 # ifdef CONFIG_DEVICE_CLOCK_GATING
       dev_clock_sink_gate(&pv->clk_ep, DEV_CLOCK_EP_POWER_CLOCK);
 # endif
-      efm32_i2c_slave_update_rate(pv, &chg->freq);
 # ifdef CONFIG_DEVICE_CLOCK_GATING
       if (dev->start_count == 0)
         dev_clock_sink_gate(&pv->clk_ep, DEV_CLOCK_EP_POWER);
--- a/arch/efm32/include/arch/efm32/efm/leopard/clock.h	Mon Apr 16 22:13:19 2018 +0200
+++ b/arch/efm32/include/arch/efm32/efm/leopard/clock.h	Mon Apr 16 22:15:01 2018 +0200
@@ -85,7 +85,7 @@
 # define EFM32_CLOCK_UART1 EFM32_CLOCK_UART1
 #endif
 
-#ifdef CONFIG_DRIVER_EFM32_I2C
+#if defined(CONFIG_DRIVER_EFM32_I2C) || defined(CONFIG_DRIVER_EFM32_I2C_SLAVE)
   EFM32_CLOCK_I2C0,
 # define EFM32_CLOCK_I2C0 EFM32_CLOCK_I2C0
   EFM32_CLOCK_I2C1,