From patchwork Tue Jun 16 12:11:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 49960 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4F0BE205DE for ; Tue, 16 Jun 2015 12:11:43 +0000 (UTC) Received: by wgez8 with SMTP id z8sf3886019wge.2 for ; Tue, 16 Jun 2015 05:11:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:content-type :content-transfer-encoding:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=xBbocqmITs/oNKsVX/pcryVEs94UTbHnXf44D6rf9/g=; b=WNfsPUJUr5DAQg1fTTLUvmx3iCC4uAZ3GWYCkMV7Od5r00GPjvi8o3U6Wx2aEXqWd9 4MJcfmZP/jdmH9fijfYikWX8MHXuKSWRoJ6pExcLwLEpFTdaNRWPL/7vqfTdSxCgWjGi ke1v8sq2w+PBKj+1VPiyoIz0beTxB/TqHF2pAg45lvcQ+bFLE27/pkFreEg+w4yYMY0q fJx94n74LQTeFiJH8H8su3sCEGS+FhLq3fhxG4Ou2YGDg9XjDfwoF1PkDiDto9l7pUgS Sk1/wQE35dXmaGzEeHLudEel7RvjaqKkUyxFJYCXQqlu3RZ0QgfX+EmEt+EEZ1J4VVye 4TmA== X-Gm-Message-State: ALoCoQm+Msa+1pV3i4qRjztKEu1pruZvapBBCVsKYQlVc2FXbnl2OSmGlr+zDTXSi/mCIbUmHUky X-Received: by 10.112.42.236 with SMTP id r12mr88047lbl.2.1434456701486; Tue, 16 Jun 2015 05:11:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.1 with SMTP id o1ls97539lao.12.gmail; Tue, 16 Jun 2015 05:11:41 -0700 (PDT) X-Received: by 10.152.225.166 with SMTP id rl6mr120483lac.36.1434456701338; Tue, 16 Jun 2015 05:11:41 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id gk6si611185lbc.173.2015.06.16.05.11.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jun 2015 05:11:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbbti3 with SMTP id ti3so9448265lbb.1 for ; Tue, 16 Jun 2015 05:11:40 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr71156lbc.112.1434456700897; Tue, 16 Jun 2015 05:11:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2074354lbb; Tue, 16 Jun 2015 05:11:39 -0700 (PDT) X-Received: by 10.70.127.231 with SMTP id nj7mr3833pdb.63.1434456698834; Tue, 16 Jun 2015 05:11:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dg11si1157795pac.81.2015.06.16.05.11.38; Tue, 16 Jun 2015 05:11:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751207AbbFPMLh (ORCPT + 1 other); Tue, 16 Jun 2015 08:11:37 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:35203 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752124AbbFPMLg (ORCPT ); Tue, 16 Jun 2015 08:11:36 -0400 Received: by pdbnf5 with SMTP id nf5so13246372pdb.2 for ; Tue, 16 Jun 2015 05:11:36 -0700 (PDT) X-Received: by 10.68.179.228 with SMTP id dj4mr57094732pbc.141.1434456695966; Tue, 16 Jun 2015 05:11:35 -0700 (PDT) Received: from [192.168.0.100] ([202.62.77.106]) by mx.google.com with ESMTPSA id ho2sm1229369pbb.14.2015.06.16.05.11.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jun 2015 05:11:34 -0700 (PDT) Message-ID: <55801272.1040006@linaro.org> Date: Tue, 16 Jun 2015 17:41:30 +0530 From: Vaibhav Hiremath User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Wolfram Sang CC: linux-i2c@vger.kernel.org Subject: Re: [RFC]: Supporting PIO mode of operation in i2c_msg->flags References: <5562EF9D.1090403@linaro.org> <20150611234118.GA1534@katana> <557D6FAF.1050408@linaro.org> <557FE4A9.5030004@linaro.org> <20150616091815.GA1595@katana> In-Reply-To: <20150616091815.GA1595@katana> Sender: linux-i2c-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-i2c@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: vaibhav.hiremath@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On Tuesday 16 June 2015 02:48 PM, Wolfram Sang wrote: > >> Any update on this? > > Not yet. > > a) there was no code to look at > Actually its simple question, whether we can call i2c_transfer in pm_power_off fn, where interupts are disabled and i2c_transfer fn may sleep. Just to illustrate my point, I just quickly created something for you. Correct me if I am wrong here. pm_power_off Usecase: __u8 *buf; /* pointer to msg data */ }; --- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ===== File: arch/arm64/kernel/process.c void machine_power_off(void) { local_irq_disable(); smp_send_stop(); if (pm_power_off) pm_power_off(); } Dummy pm_power_off Implementation: ===== diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 03b70f8..e364a2a 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1170,7 +1170,10 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num i2c_pxa_enable(i2c, true); for (i = adap->retries; i >= 0; i--) { - ret = i2c_pxa_do_xfer(i2c, msgs, num); + if (msgs[0].flags & I2C_M_PIO) + ret = i2c_pxa_do_pio_xfer(i2c, msgs, num); + else + ret = i2c_pxa_do_xfer(i2c, msgs, num); if (ret != I2C_RETRY) goto out; diff --git a/drivers/mfd/88pm800.c b/drivers/mfd/88pm800.c index 0464e2d..2d7b11b 100644 --- a/drivers/mfd/88pm800.c +++ b/drivers/mfd/88pm800.c @@ -488,6 +488,52 @@ static void pm800_pages_exit(struct pm80x_chip *chip) i2c_unregister_device(subchip->gpadc_page); } +static struct pm80x_chip *pm80x_chip_g; + +#define PM800_SW_PDOWN (1 << 5) + +static void pm800_power_off(void) +{ + u8 data, buf[2]; + struct i2c_msg msgs[2]; + struct i2c_client *client = pm80x_chip_g->client; + + pr_info("turning off power....\n"); + + /* + * pm_power_off fn get called at the end of machine_power_off(), + * so at this stage the irqs are disabled, so we have to use + * PIO mode of I2C transaction for both read and write. + */ + /* Read register first */ + msgs[0].addr = client->addr; + msgs[0].flags = I2C_M_PIO; + msgs[0].len = 1; + msgs[0].buf = buf; + + msgs[1].addr = client->addr; + msgs[1].flags = I2C_M_RD | I2C_M_PIO; + msgs[1].len = 1; + msgs[1].buf = &data; + + buf[0] = PM800_WAKEUP1; + if ( __i2c_transfer(client->adapter, msgs, 2) < 0) { + pr_err("%s read register fails...\n", __func__); + WARN_ON(1); + } + + /* issue SW power down */ + msgs[0].addr = client->addr; + msgs[0].flags = I2C_M_PIO; + msgs[0].len = 2; + msgs[0].buf[0] = PM800_WAKEUP1; + msgs[0].buf[1] = data | PM800_SW_PDOWN; + if (__i2c_transfer(client->adapter, msgs, 1) < 0) { + pr_err("%s write data fails...\n", __func__); + WARN_ON(1); + } +} + static int device_800_init(struct pm80x_chip *chip, struct pm80x_platform_data *pdata) { @@ -612,6 +658,10 @@ static int pm800_probe(struct i2c_client *client, if (pdata && pdata->plat_config) pdata->plat_config(chip, pdata); + /* keep global copy, required in power_off fn */ + pm80x_chip_g = chip; + pm_power_off = pm800_power_off; + return 0; err_device_init: diff --git a/include/uapi/linux/i2c.h b/include/uapi/linux/i2c.h index 0e949cb..22fda83 100644 --- a/include/uapi/linux/i2c.h +++ b/include/uapi/linux/i2c.h @@ -76,6 +76,7 @@ struct i2c_msg { #define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */ #define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */ #define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */ +#define I2C_M_PIO 0x0200 /* pio mode of transaction */ __u16 len; /* msg length */