From patchwork Fri Oct 6 02:53:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaki Ota <012nexus@gmail.com> X-Patchwork-Id: 9988315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E636760216 for ; Fri, 6 Oct 2017 02:54:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D287E28C9D for ; Fri, 6 Oct 2017 02:54:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C520B28CCA; Fri, 6 Oct 2017 02:54:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,FROM_STARTS_WITH_NUMS,RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49B0428C9D for ; Fri, 6 Oct 2017 02:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751694AbdJFCxc (ORCPT ); Thu, 5 Oct 2017 22:53:32 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34882 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751663AbdJFCxb (ORCPT ); Thu, 5 Oct 2017 22:53:31 -0400 Received: by mail-pg0-f68.google.com with SMTP id p5so14740190pgn.2; Thu, 05 Oct 2017 19:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Cvz7Nhi1YuvyfXoU0rbht9n4DOoNMptHK+YRZGlFT+E=; b=F//ilzcQ6uhPV3hytQOdONPiyUtxA00uRQCz29NPyfIFaed18hzLR4PhJ+RYPime10 wLwWhmEAOWvpCx4rZkEuSeQbRv/ntjSAmCAe1kto3pUlN7brwxyiPLLihzzVgbuD5pbc DMEBUuld77iUJepEGpA0ajHV+/L5DQpNpMiGzuKKwXTeaxsKNuL7PlV3Y1a4A7P45uPa 7OLDwjlWc9z48pzUZl6KMlpe1fyWjuNDSQCwrHNHhlFoMiNFgPJL5GZhKdaSqJPjDu1o 37KSTH8e5QUSHxEopB3ExbhdJ37cQH9S+yG1gzlRM4Qf1w/KlNNSai+uPTiEfq/FpuuN E4Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Cvz7Nhi1YuvyfXoU0rbht9n4DOoNMptHK+YRZGlFT+E=; b=IB1uhqT9WUpKjgu19VJ97Mgt1lW/Cy+lET/YYCA4bO7aEE3RfdIlC9Moq8sssuYGCX gaYnDWQRd2kGHRIN3vG3cFfKg2y4/Gp0XXO67SS6OdYtRDZ6IIN6FY/Ru29NtLvrRXRw 4x9T3QZ0O/x/pz8h2yNYc+Cf37eHuCjwQ/qUAQkozmpvcOFxR5rko6kqPsFKEFuZ66NG Hpra7KdPzcrui38SJsxCZnsc6QQ4qj3ZBLXWzKuamf9buvUWPJ7ZxpETufe4BeDlIaQ3 9WKEMGgbHwbLyLlxj6OgqVnydR9g86MqEETYrpz0z9uEPbUp0pDa+8QdNK6L9Me6Z7hl Mvxg== X-Gm-Message-State: AMCzsaWc14g0fmNsRfDea14957EZzXmb19ZPElfbGA8gQ9WNN33Ngtz1 UmJXikyLJswtuogqJ++QIUM= X-Google-Smtp-Source: AOwi7QAXfCVQn8twOjz3MfcW2fBLvROmf9qKW3CXRfwSGT49Q68XuI3wrlEI6R6CgjUynT0NAER6lQ== X-Received: by 10.98.201.1 with SMTP id k1mr664884pfg.335.1507258411018; Thu, 05 Oct 2017 19:53:31 -0700 (PDT) Received: from localhost (p2218-ipad303aobadori.miyagi.ocn.ne.jp. [123.216.73.218]) by smtp.gmail.com with ESMTPSA id h125sm505178pfg.84.2017.10.05.19.53.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Oct 2017 19:53:30 -0700 (PDT) From: Masaki Ota <012nexus@gmail.com> X-Google-Original-From: Masaki Ota To: jikos@kernel.org, benjamin.tissoires@redhat.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, masaki.ota@jp.alps.com Subject: [PATCH 2/7] Separate U1 device code Date: Fri, 6 Oct 2017 11:53:14 +0900 Message-Id: <20171006025319.2505-3-masaki.ota@jp.alps.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171006025319.2505-1-masaki.ota@jp.alps.com> References: <20171006025319.2505-1-masaki.ota@jp.alps.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Masaki Ota -Create "static int u1_init()" function for separate U1 device initialization code from Main initialization. -Create "has_sp" variable for checking whether it has SP device or not. Signed-off-by: Masaki Ota --- drivers/hid/hid-alps.c | 120 +++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 53 deletions(-) diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c index 519bfcf9eaf0..c4ea5c6c9be9 100644 --- a/drivers/hid/hid-alps.c +++ b/drivers/hid/hid-alps.c @@ -75,6 +75,7 @@ * @y_max: maximum y coordinate value * @btn_cnt: number of buttons * @sp_btn_cnt: number of stick buttons + * @has_sp: boolean of sp existense */ struct u1_dev { struct input_dev *input; @@ -96,6 +97,7 @@ struct u1_dev { u32 y_max; u32 btn_cnt; u32 sp_btn_cnt; + u8 has_sp; }; static int u1_read_write_register(struct hid_device *hdev, u32 address, @@ -255,99 +257,130 @@ static int alps_post_resume(struct hid_device *hdev) } #endif /* CONFIG_PM */ -static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) +static int u1_init(struct hid_device *hdev, struct u1_dev *pri_data) { - struct u1_dev *data = hid_get_drvdata(hdev); - struct input_dev *input = hi->input, *input2; int ret; - int res_x, res_y, i; - - data->input = input; - - hid_dbg(hdev, "Opening low level driver\n"); - ret = hid_hw_open(hdev); - if (ret) - return ret; - - /* Allow incoming hid reports */ - hid_device_io_start(hdev); /* Device initialization */ ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, - &data->dev_ctrl, 0, true); + &pri_data->dev_ctrl, 0, true); if (ret < 0) { dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret); goto exit; } - data->dev_ctrl &= ~U1_DISABLE_DEV; - data->dev_ctrl |= U1_TP_ABS_MODE; + pri_data->dev_ctrl &= ~U1_DISABLE_DEV; + pri_data->dev_ctrl |= U1_TP_ABS_MODE; ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, - NULL, data->dev_ctrl, false); + NULL, pri_data->dev_ctrl, false); if (ret < 0) { dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret); goto exit; } ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X, - &data->sen_line_num_x, 0, true); + &pri_data->sen_line_num_x, 0, true); if (ret < 0) { dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret); goto exit; } ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y, - &data->sen_line_num_y, 0, true); + &pri_data->sen_line_num_y, 0, true); if (ret < 0) { dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret); goto exit; } ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X, - &data->pitch_x, 0, true); + &pri_data->pitch_x, 0, true); if (ret < 0) { dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret); goto exit; } ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y, - &data->pitch_y, 0, true); + &pri_data->pitch_y, 0, true); if (ret < 0) { dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret); goto exit; } ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS, - &data->resolution, 0, true); + &pri_data->resolution, 0, true); if (ret < 0) { dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret); goto exit; } + pri_data->x_active_len_mm = + (pri_data->pitch_x * (pri_data->sen_line_num_x - 1)) / 10; + pri_data->y_active_len_mm = + (pri_data->pitch_y * (pri_data->sen_line_num_y - 1)) / 10; + + pri_data->x_max = + (pri_data->resolution << 2) * (pri_data->sen_line_num_x - 1); + pri_data->y_max = + (pri_data->resolution << 2) * (pri_data->sen_line_num_y - 1); ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN, - &data->btn_info, 0, true); + &pri_data->btn_info, 0, true); if (ret < 0) { dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret); goto exit; } + pri_data->has_sp = 0; /* Check StickPointer device */ ret = u1_read_write_register(hdev, ADDRESS_U1_DEVICE_TYP, - &data->dev_type, 0, true); + &pri_data->dev_type, 0, true); if (ret < 0) { dev_err(&hdev->dev, "failed U1_DEVICE_TYP (%d)\n", ret); goto exit; } - data->x_active_len_mm = - (data->pitch_x * (data->sen_line_num_x - 1)) / 10; - data->y_active_len_mm = - (data->pitch_y * (data->sen_line_num_y - 1)) / 10; + if (pri_data->dev_type & U1_DEVTYPE_SP_SUPPORT) { + pri_data->dev_ctrl |= U1_SP_ABS_MODE; + ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, + NULL, pri_data->dev_ctrl, false); + if (ret < 0) { + dev_err(&hdev->dev, "failed SP mode (%d)\n", ret); + goto exit; + } + + ret = u1_read_write_register(hdev, ADDRESS_U1_SP_BTN, + &pri_data->sp_btn_info, 0, true); + if (ret < 0) { + dev_err(&hdev->dev, "failed U1_SP_BTN (%d)\n", ret); + goto exit; + } + pri_data->has_sp = 1; + } - data->x_max = - (data->resolution << 2) * (data->sen_line_num_x - 1); - data->y_max = - (data->resolution << 2) * (data->sen_line_num_y - 1); +exit: + return ret; +} + +static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) +{ + struct u1_dev *data = hid_get_drvdata(hdev); + struct input_dev *input = hi->input, *input2; + int ret; + int res_x, res_y, i; + + data->input = input; + + hid_dbg(hdev, "Opening low level driver\n"); + ret = hid_hw_open(hdev); + if (ret) + return ret; + + /* Allow incoming hid reports */ + hid_device_io_start(hdev); + + ret = u1_init(hdev, data); + + if (ret) + goto exit; __set_bit(EV_ABS, input->evbit); input_set_abs_params(input, ABS_MT_POSITION_X, 1, data->x_max, 0, 0); @@ -379,8 +412,7 @@ static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) /* Stick device initialization */ - if (data->dev_type & U1_DEVTYPE_SP_SUPPORT) { - + if (data->has_sp) { input2 = input_allocate_device(); if (!input2) { ret = -ENOMEM; @@ -388,24 +420,6 @@ static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi) } data->input2 = input2; - - data->dev_ctrl |= U1_SP_ABS_MODE; - ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1, - NULL, data->dev_ctrl, false); - if (ret < 0) { - dev_err(&hdev->dev, "failed SP mode (%d)\n", ret); - input_free_device(input2); - goto exit; - } - - ret = u1_read_write_register(hdev, ADDRESS_U1_SP_BTN, - &data->sp_btn_info, 0, true); - if (ret < 0) { - dev_err(&hdev->dev, "failed U1_SP_BTN (%d)\n", ret); - input_free_device(input2); - goto exit; - } - input2->phys = input->phys; input2->name = "DualPoint Stick"; input2->id.bustype = BUS_I2C;