static void hall_device_irq_work_n(struct work_struct *work) { struct hall_device_chip *chip = container_of(work, struct hall_device_chip, irq_work_n); mutex_lock(&chip->lock); //SENSOR_LOG_INFO("enter\n"); if (0 == gpio_get_value(chip->irq_n.irq_pin)) { SENSOR_LOG_INFO("MAGNETIC_DEVICE NEAR\n"); input_report_rel(chip->idev, REL_RX, MAGNETIC_DEVICE_NEAR); hall_device_wakelock_ops(&(chip->wakeup_wakelock),false); } else { SENSOR_LOG_INFO("MAGNETIC_DEVICE FAR\n"); input_report_rel(chip->idev, REL_RX, MAGNETIC_DEVICE_FAR); hrtimer_start(&chip->unlock_wakelock_timer, ktime_set(3, 0), HRTIMER_MODE_REL); } input_sync(chip->idev); chip->on_irq_working = false; hall_device_irq_enable(&(chip->irq_n), true, true); //SENSOR_LOG_INFO("exit\n"); mutex_unlock(&chip->lock); };
static void hall_device_irq_work_n(struct work_struct *work) { struct hall_device_chip *chip = container_of(work, struct hall_device_chip, irq_work_n); unsigned int hall_device_state; mutex_lock(&chip->lock); hall_device_state = gpio_get_value(chip->irq_n.irq_pin) ? MAGNETIC_DEVICE_FAR : MAGNETIC_DEVICE_NEAR; if (hall_device_state==chip->state_n) { SENSOR_LOG_INFO("MAGNETIC_DEVICE N [%s] same state\n",hall_device_state==1? "NEAR" : "FAR"); } else { chip->state_n = hall_device_state; chip->state_s = gpio_get_value(chip->irq_s.irq_pin) ? MAGNETIC_DEVICE_FAR : MAGNETIC_DEVICE_NEAR; SENSOR_LOG_INFO("N is %s, S is %s\n",chip->state_n==1? "NEAR" : "FAR",chip->state_s==1? "NEAR" : "FAR"); input_report_rel(chip->idev, REL_RX, chip->state_s); input_report_rel(chip->idev, REL_RY, chip->state_n); input_sync(chip->idev); } if (chip->state_n==MAGNETIC_DEVICE_NEAR) { hall_device_wakelock_ops(&(chip->wakeup_wakelock),false); } else { hrtimer_start(&chip->unlock_wakelock_timer, ktime_set(3, 0), HRTIMER_MODE_REL); } chip->on_irq_working = false; hall_device_irq_enable(&(chip->irq_n), true, true); mutex_unlock(&chip->lock); };
static enum hrtimer_restart hall_device_unlock_wakelock_work_func(struct hrtimer *timer) { struct hall_device_chip *chip = container_of(timer, struct hall_device_chip, unlock_wakelock_timer); if (false == chip->on_irq_working ) { hall_device_wakelock_ops(&(chip->wakeup_wakelock),false); } return HRTIMER_NORESTART; }
static irqreturn_t hall_device_irq_n(int irq, void *handle) { struct hall_device_chip *chip = handle; //SENSOR_LOG_INFO("enter\n"); hall_device_irq_enable(&(chip->irq_n), false, false); chip->on_irq_working = true; hrtimer_cancel(&chip->unlock_wakelock_timer); if (true == chip->enabled) { hall_device_wakelock_ops(&(chip->wakeup_wakelock),true); } if (0==schedule_work(&chip->irq_work_n)) { SENSOR_LOG_INFO("schedule_work failed!\n"); } //SENSOR_LOG_INFO("exit\n"); return IRQ_HANDLED; }