From patchwork Thu Jul 7 16:39:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jeffrey.lin" X-Patchwork-Id: 9219175 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 0D99660467 for ; Thu, 7 Jul 2016 16:40:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F10D42837F for ; Thu, 7 Jul 2016 16:40:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E38A728387; Thu, 7 Jul 2016 16:40:54 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 5C1542837F for ; Thu, 7 Jul 2016 16:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752604AbcGGQkx (ORCPT ); Thu, 7 Jul 2016 12:40:53 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33734 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752138AbcGGQkt (ORCPT ); Thu, 7 Jul 2016 12:40:49 -0400 Received: by mail-pf0-f195.google.com with SMTP id c74so2254690pfb.0; Thu, 07 Jul 2016 09:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=pn+ufrHSLhB13z26rNm0l3LIj+IHJdDayTcoCMuRIoI=; b=tO6vRW7PJmqGl5WX/uIIETpUGAYnWNttCJ+QOkAbKfRMP5mQJ5ImdHTtMluG2VOo8S 8p5rbdLTdIpgxAuiNtmwv35XhrAKqlmSaD/VmuHdDF8B/nqm8H31UOavU68ATmSm5ysR TLcwUY9lEAn+mPDEURYdSZJMCV2ug4XAARRqWITdiSR/tLeCGjaA9i9tEzPA42RuK22q GYILgKDHrhe/iHIZn36N41287B/8bkDl6AgoLgsxFTXemuneboj9KLetT//d7/xpMUU8 EQ4xbdgDWvm83xK3N7++H1xJ3VCCfum1MDvGigNkrdV7Pp79ZCCGMtpVMDKBMNDZn4cX Ipuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pn+ufrHSLhB13z26rNm0l3LIj+IHJdDayTcoCMuRIoI=; b=YkYBy3hzHi8M+Vu2dq+ND0ueN3ZD4zDP7Ym9AlCNBJuckr/YWozYQtt5rnED63yZzV oiZpbyY97phh+Wer2upEG+Pt46K/OBik2E2+wy9rZJ34FCNYmObbKbYs8sQlRKo92IVy oQqXb1PE3x/MW7DeivC2vK6iItJ1sOzF9hV+Z/7PXCMZCpF+bjQxOPxCbJOnik/J/UB9 V1pMqIUkSAb5H8K+zRA5LE0Ehl16ccyuwUoCq2AqSZYvMtDnJYyNUjVE0IWtYwpRKMIG e1e92XiYKknUXg0YBcyAgoNMsc1E2C1T5Ql8R4SXtGudzVK6O0o7WVznxvxcDzTX/RBL uT0w== X-Gm-Message-State: ALyK8tLZdXldQ4mLhEqy409ayKcNv/w4ZHMIX1gimfSkWmAwXp3/FVuj7j8HuVS2E6KZmA== X-Received: by 10.98.62.220 with SMTP id y89mr1866674pfj.9.1467909629159; Thu, 07 Jul 2016 09:40:29 -0700 (PDT) Received: from localhost.localdomain (220-132-61-75.HINET-IP.hinet.net. [220.132.61.75]) by smtp.gmail.com with ESMTPSA id p187sm4843267pfg.67.2016.07.07.09.40.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jul 2016 09:40:28 -0700 (PDT) From: "jeffrey.lin" X-Google-Original-From: "jeffrey.lin" To: dmitry.torokhov@gmail.com, rydberg@euromail.se, groeck@chromium.org, robh@kernel.org Cc: jeffrey.lin@rad-ic.com, ealin.chiu@rad-ic.com, jason.yeh@rad-ic.com, KP.li@rad-ic.com, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH] [v1.1 3/3] modify raydium firmware update rule Date: Thu, 7 Jul 2016 09:39:38 -0700 Message-Id: <1467909578-43578-1-git-send-email-jeffrey.lin@rad-ic.com> X-Mailer: git-send-email 2.1.2 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 modify raydium touch firmware update rule. Signed-off-by: jeffrey.lin --- drivers/input/touchscreen/raydium_i2c_ts.c | 112 ++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 19 deletions(-) diff --git a/drivers/input/touchscreen/raydium_i2c_ts.c b/drivers/input/touchscreen/raydium_i2c_ts.c index f3076d9..004c5a6 100644 --- a/drivers/input/touchscreen/raydium_i2c_ts.c +++ b/drivers/input/touchscreen/raydium_i2c_ts.c @@ -34,6 +34,9 @@ #include #include +/* Firmware */ +#define RAYDIUM_FW_NAME "raydium.fw" + /* Slave I2C mode */ #define RM_BOOT_BLDR 0x02 #define RM_BOOT_MAIN 0x03 @@ -78,7 +81,7 @@ #define RM_MAX_FW_RETRIES 30 #define RM_MAX_FW_SIZE 0xD000 -#define RM_POWERON_DELAY_USEC 500 +#define RM_POWERON_DELAY_MSEC 20 #define RM_RESET_DELAY_MSEC 50 enum raydium_bl_cmd { @@ -97,6 +100,7 @@ enum raydium_bl_ack { enum raydium_boot_mode { RAYDIUM_TS_MAIN = 0, RAYDIUM_TS_BLDR, + INVALID_REGION, }; /* Response to RM_CMD_DATA_BANK request */ @@ -141,6 +145,8 @@ struct raydium_data { enum raydium_boot_mode boot_mode; bool wake_irq_enabled; + + char *fw_file; }; static int raydium_i2c_send(struct i2c_client *client, @@ -318,16 +324,23 @@ static int raydium_i2c_check_fw_status(struct raydium_data *ts) struct i2c_client *client = ts->client; static const u8 bl_ack = 0x62; static const u8 main_ack = 0x66; - u8 buf[4]; + u8 buf[5]; int error; error = raydium_i2c_read(client, RM_CMD_BOOT_READ, buf, sizeof(buf)); if (!error) { - if (buf[0] == bl_ack) - ts->boot_mode = RAYDIUM_TS_BLDR; - else if (buf[0] == main_ack) + if (buf[0] == main_ack) ts->boot_mode = RAYDIUM_TS_MAIN; - return 0; + else if (buf[0] == bl_ack) { + ts->boot_mode = RAYDIUM_TS_BLDR; + ts->info.main_ver = buf[4] >> 4; + ts->info.sub_ver = buf[4] & 0x0F; + } else { + ts->boot_mode = INVALID_REGION; + error = -EINVAL; + dev_err(&client->dev, + "invalid fw status: %x\n", buf[0]); + } } return error; @@ -358,13 +371,10 @@ static int raydium_i2c_initialize(struct raydium_data *ts) if (error) ts->boot_mode = RAYDIUM_TS_BLDR; - if (ts->boot_mode == RAYDIUM_TS_BLDR) { + if (ts->boot_mode == RAYDIUM_TS_BLDR) ts->info.hw_ver = cpu_to_le32(0xffffffffUL); - ts->info.main_ver = 0xff; - ts->info.sub_ver = 0xff; - } else { + else raydium_i2c_query_ts_info(ts); - } return error; } @@ -739,12 +749,12 @@ static int raydium_i2c_fw_update(struct raydium_data *ts) { struct i2c_client *client = ts->client; const struct firmware *fw = NULL; - const char *fw_file = "raydium.fw"; int error; - error = request_firmware(&fw, fw_file, &client->dev); + error = request_firmware(&fw, ts->fw_file, &client->dev); if (error) { - dev_err(&client->dev, "Unable to open firmware %s\n", fw_file); + dev_err(&client->dev, "Unable to open firmware %s\n", + ts->fw_file); return error; } @@ -900,18 +910,75 @@ static ssize_t raydium_i2c_calibrate_store(struct device *dev, return error ?: count; } +static int raydium_update_file_name(struct device *dev, char **file_name, + const char *buf, size_t count) +{ + char *new_file_name; + + /* Simple sanity check */ + if (count > 64) { + dev_warn(dev, "File name too long\n"); + return -EINVAL; + } + + new_file_name = devm_kmalloc(dev, count + 1, GFP_KERNEL); + if (!new_file_name) + return -ENOMEM; + + memcpy(new_file_name, buf, count + 1); + + /* Echo into the sysfs entry may append newline at the end of buf */ + if (new_file_name[count - 1] == '\n') + count--; + + new_file_name[count] = '\0'; + + if (*file_name) + devm_kfree(dev, *file_name); + + *file_name = new_file_name; + + return 0; +} + +static ssize_t raydium_fw_file_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct raydium_data *ts = i2c_get_clientdata(client); + + return scnprintf(buf, PAGE_SIZE, "%s\n", ts->fw_file); +} + +static ssize_t raydium_fw_file_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct raydium_data *ts = i2c_get_clientdata(client); + int ret; + + ret = raydium_update_file_name(dev, &ts->fw_file, buf, count); + if (ret) + return ret; + + return count; +} + static DEVICE_ATTR(fw_version, S_IRUGO, raydium_i2c_fw_ver_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, raydium_i2c_hw_ver_show, NULL); static DEVICE_ATTR(boot_mode, S_IRUGO, raydium_i2c_boot_mode_show, NULL); static DEVICE_ATTR(update_fw, S_IWUSR, NULL, raydium_i2c_update_fw_store); static DEVICE_ATTR(calibrate, S_IWUSR, NULL, raydium_i2c_calibrate_store); - +static DEVICE_ATTR(fw_file, S_IRUGO | S_IWUSR, raydium_fw_file_show, + raydium_fw_file_store); static struct attribute *raydium_i2c_attributes[] = { &dev_attr_update_fw.attr, &dev_attr_boot_mode.attr, &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_calibrate.attr, + &dev_attr_fw_file.attr, NULL }; @@ -933,7 +1000,7 @@ static int raydium_i2c_power_on(struct raydium_data *ts) if (!ts->reset_gpio) return 0; - gpiod_set_value_cansleep(ts->reset_gpio, 1); + gpiod_set_value_cansleep(ts->reset_gpio, 0); error = regulator_enable(ts->avdd); if (error) { @@ -950,10 +1017,10 @@ static int raydium_i2c_power_on(struct raydium_data *ts) goto release_reset_gpio; } - udelay(RM_POWERON_DELAY_USEC); + msleep(RM_POWERON_DELAY_MSEC); release_reset_gpio: - gpiod_set_value_cansleep(ts->reset_gpio, 0); + gpiod_set_value_cansleep(ts->reset_gpio, 1); if (error) return error; @@ -968,7 +1035,6 @@ static void raydium_i2c_power_off(void *_data) struct raydium_data *ts = _data; if (ts->reset_gpio) { - gpiod_set_value_cansleep(ts->reset_gpio, 1); regulator_disable(ts->vccio); regulator_disable(ts->avdd); } @@ -1043,6 +1109,14 @@ static int raydium_i2c_probe(struct i2c_client *client, return -ENXIO; } + error = raydium_update_file_name(&client->dev, &ts->fw_file, + RAYDIUM_FW_NAME, strlen(RAYDIUM_FW_NAME)); + if (error) { + dev_err(&client->dev, "failed to set firmware file name: %d\n", + error); + return error; + } + error = raydium_i2c_initialize(ts); if (error) { dev_err(&client->dev, "failed to initialize: %d\n", error);