From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754917AbdCGIRU (ORCPT ); Tue, 7 Mar 2017 03:17:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52178 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752649AbdCGIRD (ORCPT ); Tue, 7 Mar 2017 03:17:03 -0500 To: Thomas Gleixner Cc: Linux Kernel Mailing List , linux-i2c@vger.kernel.org From: Hans de Goede Subject: Linux irq subsys i2c interaction question Message-ID: Date: Tue, 7 Mar 2017 09:16:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 07 Mar 2017 08:17:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thomas, I've an "interesting" irq problem. I've an i2c pmic (Intel Cherry Trail Whiskey Cove) which itself contains an i2c controller (adapter in Linux terms) and has a pin dedicated for raising irqs by the external battery charger ic attached to its i2c-adapter. To be able to use the irq for the external-charger, the driver for the PMIC needs to implement an irqchip and here things get interesting. This irqchip can NOT use handle_nested_irq, because the i2c-client driver's irq-handler will want to read/write to the external-charger which uses the i2c-controller embedded in the PMIC which requires handling of new (not arrived when started) PMIC irqs, which cannot be done if the client irq-handler is running in handle_nested_irq, because then the PMIC's irq handler is already / still running and blocked in the i2c-client's irq-handler which is waiting for the new interrupt(s) to get processed to signal completion of the i2c-transaction(s) it is doing. I've solved this the following way, which works but I wonder if it is the right way to solve this ? Note this sits inside the threaded interrupt handler for the PMIC irq (after reading and acking the irqs): /* * Do NOT use handle_nested_irq here, the client irq handler will * likely want to do i2c transfers and the i2c controller uses this * interrupt handler as well, so running the client irq handler from * this thread will cause things to lock up. */ if (reg & CHT_WC_EXTCHGRIRQ_CLIENT_IRQ) { /* * generic_handle_irq expects local irqs to be disabled * as normally it is called from interrupt context. */ local_irq_disable(); generic_handle_irq(adap->client_irq); local_irq_enable(); } Not really pretty, but it works well enough. I can live with this if you can live with it too :) Regards, Hans