From patchwork Wed Mar 13 23:50:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benson Leung X-Patchwork-Id: 2266861 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id AAAFAE00E6 for ; Wed, 13 Mar 2013 23:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934468Ab3CMXvS (ORCPT ); Wed, 13 Mar 2013 19:51:18 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:60348 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932532Ab3CMXvJ (ORCPT ); Wed, 13 Mar 2013 19:51:09 -0400 Received: by mail-pb0-f46.google.com with SMTP id uo15so1511710pbc.5 for ; Wed, 13 Mar 2013 16:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=MDs1JfX50PllhzAU5BCA8339DOCJd4Eh3Q4oB+/wbPo=; b=WDpRub3JgSqgZm7/xTGSDYsM7rspgsnHVurybJ1ZZxBz9+WRZ0cA2GmxxJIBfzaJWh jqcPdk4Vtso+EmZeiD/AxCsFWr7B3reoRUUZmmukEsEZL+zMFv3VUevzysKX/hCXxSgf m7b/LGFsn/KIQ9qOixcqedqw/lezAixGSREa8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=MDs1JfX50PllhzAU5BCA8339DOCJd4Eh3Q4oB+/wbPo=; b=RN4+Q76rSFRV6pgwUMLkzOVkS2sBTn2Zd3zjHxqKi9yRcnTkYHP+1DCrx0fAI1vXOM 0nO9BWqDbnAqSq0DGFDVwDDrQIsY42oy8oo4lgcWABnxTrzGLEF1/1KzpgIyMBecoSZJ sDfsNnghRVy+5Llpstp+OysYlY6dP/J7h+gzHs3Hbwh4xu2YTmH+s6En24u1bFU0KbdF js8OJ0tVj0TvMjbG26h1BPgd+6bnXPJIHwDst5J2ApS+VbAYwnhyw8MmcjqfdUa13Y+7 Tr3Xb6rHBdm+AjkM/3nd5FuvZ52/fcDAZ0p2EwLWXzW9koFJZLNCWq6n8/9z6imy4CRL xgAw== X-Received: by 10.68.179.67 with SMTP id de3mr618733pbc.130.1363218669270; Wed, 13 Mar 2013 16:51:09 -0700 (PDT) Received: from laughingman.mtv.corp.google.com (laughingman.mtv.corp.google.com [172.22.73.99]) by mx.google.com with ESMTPS id kb3sm420254pbc.21.2013.03.13.16.51.07 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Mar 2013 16:51:08 -0700 (PDT) From: Benson Leung To: rydberg@euromail.se, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.torokhov@gmail.com Cc: bleung@chromium.org, olofj@chromium.org, djkurtz@chromium.org, dudl@cypress.com Subject: [PATCH 1/4] Input: cyapa - Move common initialization to cyapa_detect Date: Wed, 13 Mar 2013 16:50:48 -0700 Message-Id: <1363218651-22457-2-git-send-email-bleung@chromium.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1363218651-22457-1-git-send-email-bleung@chromium.org> References: <1363218651-22457-1-git-send-email-bleung@chromium.org> X-Gm-Message-State: ALoCoQlLkciOa3mqlGJ2mih8xmktMuP51yvDMlX570ZOpFIEkbQI3eFLrqT9jaVX3DcCq2+Pxgpm Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org cyapa_check_is_operational and cyapa_create_input_dev are common to the probe and firmware update paths. Pull those out into cyapa_detect. Signed-off-by: Benson Leung --- drivers/input/mouse/cyapa.c | 57 +++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c index b409c3d..a631aca 100644 --- a/drivers/input/mouse/cyapa.c +++ b/drivers/input/mouse/cyapa.c @@ -823,6 +823,40 @@ err_free_device: return ret; } +static void cyapa_detect(struct cyapa *cyapa) +{ + struct device *dev = &cyapa->client->dev; + int ret; + + ret = cyapa_check_is_operational(cyapa); + if (ret == -ETIMEDOUT) + dev_err(dev, "no device detected, %d\n", ret); + else if (ret) + dev_err(dev, "device detected, but not operational, %d\n", ret); + + if (!cyapa->input) { + ret = cyapa_create_input_dev(cyapa); + if (ret) + dev_err(dev, "create input_dev instance failed, %d\n", + ret); + + enable_irq(cyapa->irq); + /* + * On some systems, a system crash / warm boot does not reset + * the device's current power mode to FULL_ACTIVE. + * If such an event happens during suspend, after the device + * has been put in a low power mode, the device will still be + * in low power mode on a subsequent boot, since there was + * never a matching resume(). + * Handle this by always forcing full power here, when a + * device is first detected to be in operational mode. + */ + ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE); + if (ret) + dev_warn(dev, "set active power failed, %d\n", ret); + } +} + static int cyapa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id) { @@ -853,23 +887,8 @@ static int cyapa_probe(struct i2c_client *client, if (adapter_func == CYAPA_ADAPTER_FUNC_SMBUS) cyapa->smbus = true; cyapa->state = CYAPA_STATE_NO_DEVICE; - ret = cyapa_check_is_operational(cyapa); - if (ret) { - dev_err(dev, "device not operational, %d\n", ret); - goto err_mem_free; - } - ret = cyapa_create_input_dev(cyapa); - if (ret) { - dev_err(dev, "create input_dev instance failed, %d\n", ret); - goto err_mem_free; - } - - ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE); - if (ret) { - dev_err(dev, "set active power failed, %d\n", ret); - goto err_unregister_device; - } + cyapa_detect(cyapa); cyapa->irq = client->irq; ret = request_threaded_irq(cyapa->irq, @@ -886,8 +905,8 @@ static int cyapa_probe(struct i2c_client *client, return 0; err_unregister_device: - input_unregister_device(cyapa->input); -err_mem_free: + if (cyapa->input) + input_unregister_device(cyapa->input); kfree(cyapa); return ret; @@ -937,6 +956,8 @@ static int cyapa_resume(struct device *dev) if (device_may_wakeup(dev) && cyapa->irq_wake) disable_irq_wake(cyapa->irq); + cyapa_detect(cyapa); + ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE); if (ret) dev_warn(dev, "resume active power failed, %d\n", ret);