From patchwork Fri Oct 21 10:49:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sangwon Jee X-Patchwork-Id: 9388687 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 586AB607D0 for ; Fri, 21 Oct 2016 10:49:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A65E2A016 for ; Fri, 21 Oct 2016 10:49:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F2EA2A01A; Fri, 21 Oct 2016 10:49:31 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 CDBCD2A016 for ; Fri, 21 Oct 2016 10:49:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754798AbcJUKta (ORCPT ); Fri, 21 Oct 2016 06:49:30 -0400 Received: from sbs.melfas.com ([39.118.242.30]:17505 "EHLO sbs.melfas.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754525AbcJUKt3 (ORCPT ); Fri, 21 Oct 2016 06:49:29 -0400 Received: from unknown (HELO localhost.localdomain) (jeesw@melfas.com@172.16.10.138) by 172.16.0.30 with ESMTP; 21 Oct 2016 19:49:16 +0900 X-Original-SENDERIP: 172.16.10.138 X-Original-MAILFROM: jeesw@melfas.com X-Original-RCPTTO: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org, jeesw@melfas.com From: Sangwon Jee To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, jeesw@melfas.com Subject: [2/2] Input: melfas_mip4 - add fw_name sysfs attribute Date: Fri, 21 Oct 2016 19:49:26 +0900 Message-Id: <1477046966-9385-1-git-send-email-jeesw@melfas.com> X-Mailer: git-send-email 1.9.1 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 To support user firmware file name, add fw_name sysfs attribute and modify to use fw_name variable instead of predefined value. Signed-off-by: Sangwon Jee --- drivers/input/touchscreen/melfas_mip4.c | 46 +++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/melfas_mip4.c b/drivers/input/touchscreen/melfas_mip4.c index 8739cb7..ae9c428 100644 --- a/drivers/input/touchscreen/melfas_mip4.c +++ b/drivers/input/touchscreen/melfas_mip4.c @@ -162,6 +162,7 @@ struct mip4_ts { char product_name[16]; u16 product_id; char ic_name[4]; + char *fw_name; unsigned int max_x; unsigned int max_y; @@ -1285,11 +1286,11 @@ static ssize_t mip4_sysfs_fw_update(struct device *dev, const struct firmware *fw; int error; - error = request_firmware(&fw, MIP4_FW_NAME, dev); + error = request_firmware(&fw, ts->fw_name, dev); if (error) { dev_err(&ts->client->dev, "Failed to retrieve firmware %s: %d\n", - MIP4_FW_NAME, error); + ts->fw_name, error); return error; } @@ -1403,11 +1404,51 @@ static ssize_t mip4_sysfs_read_ic_name(struct device *dev, static DEVICE_ATTR(ic_name, S_IRUGO, mip4_sysfs_read_ic_name, NULL); +static ssize_t mip4_sysfs_read_fw_name(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct mip4_ts *ts = i2c_get_clientdata(client); + size_t count; + + mutex_lock(&ts->input->mutex); + + count = snprintf(buf, PAGE_SIZE, "%s\n", ts->fw_name); + + mutex_unlock(&ts->input->mutex); + + return count; +} + +static ssize_t mip4_sysfs_write_fw_name(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct mip4_ts *ts = i2c_get_clientdata(client); + char *filename; + + filename = devm_kzalloc(dev, count - 1, GFP_KERNEL); + memcpy(filename, buf, count - 1); + + ts->fw_name = devm_kstrdup(dev, filename, GFP_KERNEL); + + devm_kfree(dev, filename); + + return count; +} + +static DEVICE_ATTR(fw_name, S_IRUGO | S_IWUSR, + mip4_sysfs_read_fw_name, mip4_sysfs_write_fw_name); + static struct attribute *mip4_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_product_id.attr, &dev_attr_ic_name.attr, + &dev_attr_fw_name.attr, &dev_attr_update_fw.attr, NULL, }; @@ -1444,6 +1485,7 @@ static int mip4_probe(struct i2c_client *client, const struct i2c_device_id *id) ts->client = client; ts->input = input; + ts->fw_name = devm_kstrdup(&client->dev, MIP4_FW_NAME, GFP_KERNEL); snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&client->dev));