123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938 |
- /*
- * Synaptics TCM touchscreen driver
- *
- * Copyright (C) 2017-2019 Synaptics Incorporated. All rights reserved.
- *
- * Copyright (C) 2017-2019 Scott Lin <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS
- * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
- * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS.
- * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION
- * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED
- * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES
- * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS'
- * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S.
- * DOLLARS.
- */
- #include <linux/gpio.h>
- #include "synaptics_tcm_core.h"
- #include "synaptics_tcm_testing.h"
- #define SYSFS_DIR_NAME "testing"
- #define REPORT_TIMEOUT_MS 500
- #define testing_sysfs_show(t_name) \
- static ssize_t testing_sysfs_##t_name##_show(struct device *dev, \
- struct device_attribute *attr, char *buf) \
- { \
- int retval; \
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd; \
- \
- mutex_lock(&tcm_hcd->extif_mutex); \
- \
- retval = testing_##t_name(); \
- if (retval < 0) { \
- LOGE(tcm_hcd->pdev->dev.parent, \
- "Failed to do "#t_name" test\n"); \
- goto exit; \
- } \
- \
- retval = snprintf(buf, PAGE_SIZE, \
- "%s\n", \
- testing_hcd->result ? "Passed" : "Failed"); \
- \
- exit: \
- mutex_unlock(&tcm_hcd->extif_mutex); \
- \
- return retval; \
- }
- enum test_code {
- TEST_TRX_TRX_SHORTS = 0,
- TEST_TRX_SENSOR_OPENS = 1,
- TEST_TRX_GROUND_SHORTS = 2,
- TEST_DYNAMIC_RANGE = 7,
- TEST_OPEN_SHORT_DETECTOR = 8,
- TEST_NOISE = 10,
- TEST_PT11 = 11,
- TEST_PT12 = 12,
- TEST_PT13 = 13,
- TEST_DYNAMIC_RANGE_DOZE = 14,
- TEST_NOISE_DOZE = 15,
- };
- struct testing_hcd {
- bool result;
- unsigned char report_type;
- unsigned int report_index;
- unsigned int num_of_reports;
- struct kobject *sysfs_dir;
- struct syna_tcm_buffer out;
- struct syna_tcm_buffer resp;
- struct syna_tcm_buffer report;
- struct syna_tcm_buffer process;
- struct syna_tcm_buffer output;
- struct syna_tcm_hcd *tcm_hcd;
- int (*collect_reports)(enum report_type report_type,
- unsigned int num_of_reports);
- };
- DECLARE_COMPLETION(report_complete);
- DECLARE_COMPLETION(testing_remove_complete);
- static struct testing_hcd *testing_hcd;
- static int testing_dynamic_range(void);
- static int testing_dynamic_range_lpwg(void);
- static int testing_dynamic_range_doze(void);
- static int testing_noise(void);
- static int testing_noise_lpwg(void);
- static int testing_noise_doze(void);
- static int testing_open_short_detector(void);
- static int testing_pt11(void);
- static int testing_pt12(void);
- static int testing_pt13(void);
- static int testing_reset_open(void);
- static int testing_lockdown(void);
- static int testing_trx(enum test_code test_code);
- SHOW_PROTOTYPE(testing, dynamic_range);
- SHOW_PROTOTYPE(testing, dynamic_range_lpwg);
- SHOW_PROTOTYPE(testing, dynamic_range_doze);
- SHOW_PROTOTYPE(testing, noise);
- SHOW_PROTOTYPE(testing, noise_lpwg);
- SHOW_PROTOTYPE(testing, noise_doze);
- SHOW_PROTOTYPE(testing, open_short_detector);
- SHOW_PROTOTYPE(testing, pt11);
- SHOW_PROTOTYPE(testing, pt12);
- SHOW_PROTOTYPE(testing, pt13);
- SHOW_PROTOTYPE(testing, reset_open);
- SHOW_PROTOTYPE(testing, lockdown);
- SHOW_PROTOTYPE(testing, trx_trx_shorts);
- SHOW_PROTOTYPE(testing, trx_sensor_opens);
- SHOW_PROTOTYPE(testing, trx_ground_shorts);
- SHOW_PROTOTYPE(testing, size);
- static struct device_attribute *attrs[] = {
- ATTRIFY(dynamic_range),
- ATTRIFY(dynamic_range_lpwg),
- ATTRIFY(dynamic_range_doze),
- ATTRIFY(noise),
- ATTRIFY(noise_lpwg),
- ATTRIFY(noise_doze),
- ATTRIFY(open_short_detector),
- ATTRIFY(pt11),
- ATTRIFY(pt12),
- ATTRIFY(pt13),
- ATTRIFY(reset_open),
- ATTRIFY(lockdown),
- ATTRIFY(trx_trx_shorts),
- ATTRIFY(trx_sensor_opens),
- ATTRIFY(trx_ground_shorts),
- ATTRIFY(size),
- };
- static ssize_t testing_sysfs_data_show(struct file *data_file,
- struct kobject *kobj, struct bin_attribute *attributes,
- char *buf, loff_t pos, size_t count);
- static struct bin_attribute bin_attr = {
- .attr = {
- .name = "data",
- .mode = 0444,
- },
- .size = 0,
- .read = testing_sysfs_data_show,
- };
- testing_sysfs_show(dynamic_range)
- testing_sysfs_show(dynamic_range_lpwg)
- testing_sysfs_show(dynamic_range_doze)
- testing_sysfs_show(noise)
- testing_sysfs_show(noise_lpwg)
- testing_sysfs_show(noise_doze)
- testing_sysfs_show(open_short_detector)
- testing_sysfs_show(pt11)
- testing_sysfs_show(pt12)
- testing_sysfs_show(pt13)
- testing_sysfs_show(reset_open)
- testing_sysfs_show(lockdown)
- static ssize_t testing_sysfs_trx_trx_shorts_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- mutex_lock(&tcm_hcd->extif_mutex);
- retval = testing_trx(TEST_TRX_TRX_SHORTS);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do TRX-TRX shorts test\n");
- goto exit;
- }
- retval = snprintf(buf, PAGE_SIZE,
- "%s\n",
- testing_hcd->result ? "Passed" : "Failed");
- exit:
- mutex_unlock(&tcm_hcd->extif_mutex);
- return retval;
- }
- static ssize_t testing_sysfs_trx_sensor_opens_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- mutex_lock(&tcm_hcd->extif_mutex);
- retval = testing_trx(TEST_TRX_SENSOR_OPENS);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do TRX-sensor opens test\n");
- goto exit;
- }
- retval = snprintf(buf, PAGE_SIZE,
- "%s\n",
- testing_hcd->result ? "Passed" : "Failed");
- exit:
- mutex_unlock(&tcm_hcd->extif_mutex);
- return retval;
- }
- static ssize_t testing_sysfs_trx_ground_shorts_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- mutex_lock(&tcm_hcd->extif_mutex);
- retval = testing_trx(TEST_TRX_GROUND_SHORTS);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do TRX-ground shorts test\n");
- goto exit;
- }
- retval = snprintf(buf, PAGE_SIZE,
- "%s\n",
- testing_hcd->result ? "Passed" : "Failed");
- exit:
- mutex_unlock(&tcm_hcd->extif_mutex);
- return retval;
- }
- static ssize_t testing_sysfs_size_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- mutex_lock(&tcm_hcd->extif_mutex);
- LOCK_BUFFER(testing_hcd->output);
- retval = snprintf(buf, PAGE_SIZE,
- "%u\n",
- testing_hcd->output.data_length);
- UNLOCK_BUFFER(testing_hcd->output);
- mutex_unlock(&tcm_hcd->extif_mutex);
- return retval;
- }
- static ssize_t testing_sysfs_data_show(struct file *data_file,
- struct kobject *kobj, struct bin_attribute *attributes,
- char *buf, loff_t pos, size_t count)
- {
- int retval;
- unsigned int readlen;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- mutex_lock(&tcm_hcd->extif_mutex);
- LOCK_BUFFER(testing_hcd->output);
- readlen = MIN(count, testing_hcd->output.data_length - pos);
- retval = secure_memcpy(buf,
- count,
- &testing_hcd->output.buf[pos],
- testing_hcd->output.buf_size - pos,
- readlen);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy report data\n");
- } else {
- retval = readlen;
- }
- UNLOCK_BUFFER(testing_hcd->output);
- mutex_unlock(&tcm_hcd->extif_mutex);
- return retval;
- }
- static int testing_run_prod_test_item(enum test_code test_code)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- if (tcm_hcd->features.dual_firmware &&
- tcm_hcd->id_info.mode != MODE_PRODUCTION_TEST) {
- retval = tcm_hcd->switch_mode(tcm_hcd, FW_MODE_PRODUCTION_TEST);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run production test firmware\n");
- return retval;
- }
- } else if (tcm_hcd->id_info.mode != MODE_APPLICATION ||
- tcm_hcd->app_status != APP_STATUS_OK) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Application firmware not running\n");
- return -ENODEV;
- }
- LOCK_BUFFER(testing_hcd->out);
- retval = syna_tcm_alloc_mem(tcm_hcd,
- &testing_hcd->out,
- 1);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for testing_hcd->out.buf\n");
- UNLOCK_BUFFER(testing_hcd->out);
- return retval;
- }
- testing_hcd->out.buf[0] = test_code;
- LOCK_BUFFER(testing_hcd->resp);
- retval = tcm_hcd->write_message(tcm_hcd,
- CMD_PRODUCTION_TEST,
- testing_hcd->out.buf,
- 1,
- &testing_hcd->resp.buf,
- &testing_hcd->resp.buf_size,
- &testing_hcd->resp.data_length,
- NULL,
- 0);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to write command %s\n",
- STR(CMD_PRODUCTION_TEST));
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->out);
- return retval;
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->out);
- return 0;
- }
- static int testing_collect_reports(enum report_type report_type,
- unsigned int num_of_reports)
- {
- int retval;
- bool completed;
- unsigned int timeout;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- testing_hcd->report_index = 0;
- testing_hcd->report_type = report_type;
- testing_hcd->num_of_reports = num_of_reports;
- reinit_completion(&report_complete);
- LOCK_BUFFER(testing_hcd->out);
- retval = syna_tcm_alloc_mem(tcm_hcd,
- &testing_hcd->out,
- 1);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for testing_hcd->out.buf\n");
- UNLOCK_BUFFER(testing_hcd->out);
- goto exit;
- }
- testing_hcd->out.buf[0] = testing_hcd->report_type;
- LOCK_BUFFER(testing_hcd->resp);
- retval = tcm_hcd->write_message(tcm_hcd,
- CMD_ENABLE_REPORT,
- testing_hcd->out.buf,
- 1,
- &testing_hcd->resp.buf,
- &testing_hcd->resp.buf_size,
- &testing_hcd->resp.data_length,
- NULL,
- 0);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to write command %s\n",
- STR(CMD_ENABLE_REPORT));
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->out);
- goto exit;
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->out);
- completed = false;
- timeout = REPORT_TIMEOUT_MS * num_of_reports;
- retval = wait_for_completion_timeout(&report_complete,
- msecs_to_jiffies(timeout));
- if (retval == 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Timed out waiting for report collection\n");
- } else {
- completed = true;
- }
- LOCK_BUFFER(testing_hcd->out);
- testing_hcd->out.buf[0] = testing_hcd->report_type;
- LOCK_BUFFER(testing_hcd->resp);
- retval = tcm_hcd->write_message(tcm_hcd,
- CMD_DISABLE_REPORT,
- testing_hcd->out.buf,
- 1,
- &testing_hcd->resp.buf,
- &testing_hcd->resp.buf_size,
- &testing_hcd->resp.data_length,
- NULL,
- 0);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to write command %s\n",
- STR(CMD_DISABLE_REPORT));
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->out);
- goto exit;
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->out);
- if (completed)
- retval = 0;
- else
- retval = -EIO;
- exit:
- testing_hcd->report_type = 0;
- return retval;
- }
- static void testing_get_frame_size_words(unsigned int *size, bool image_only)
- {
- unsigned int rows;
- unsigned int cols;
- unsigned int hybrid;
- unsigned int buttons;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- rows = le2_to_uint(app_info->num_of_image_rows);
- cols = le2_to_uint(app_info->num_of_image_cols);
- hybrid = le2_to_uint(app_info->has_hybrid_data);
- buttons = le2_to_uint(app_info->num_of_buttons);
- *size = rows * cols;
- if (!image_only) {
- if (hybrid)
- *size += rows + cols;
- *size += buttons;
- }
- }
- static void testing_doze_frame_output(unsigned int rows, unsigned int cols)
- {
- int retval;
- unsigned int data_size;
- unsigned int header_size;
- unsigned int output_size;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- header_size = 2;
- data_size = rows * cols;
- if (le2_to_uint(app_info->num_of_buttons))
- data_size++;
- output_size = header_size + data_size * 2;
- LOCK_BUFFER(testing_hcd->output);
- retval = syna_tcm_alloc_mem(tcm_hcd,
- &testing_hcd->output,
- output_size);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for testing_hcd->output.buf\n");
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- testing_hcd->output.buf[0] = rows;
- testing_hcd->output.buf[1] = cols;
- output_size = header_size;
- LOCK_BUFFER(testing_hcd->resp);
- retval = secure_memcpy(testing_hcd->output.buf + header_size,
- testing_hcd->output.buf_size - header_size,
- testing_hcd->resp.buf,
- testing_hcd->resp.buf_size,
- testing_hcd->resp.data_length);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy test data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- output_size += testing_hcd->resp.data_length;
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_hcd->output.data_length = output_size;
- UNLOCK_BUFFER(testing_hcd->output);
- }
- static void testing_standard_frame_output(bool image_only)
- {
- int retval;
- unsigned int data_size;
- unsigned int header_size;
- unsigned int output_size;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- testing_get_frame_size_words(&data_size, image_only);
- header_size = sizeof(app_info->num_of_buttons) +
- sizeof(app_info->num_of_image_rows) +
- sizeof(app_info->num_of_image_cols) +
- sizeof(app_info->has_hybrid_data);
- output_size = header_size + data_size * 2;
- LOCK_BUFFER(testing_hcd->output);
- retval = syna_tcm_alloc_mem(tcm_hcd,
- &testing_hcd->output,
- output_size);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for testing_hcd->output.buf\n");
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- retval = secure_memcpy(testing_hcd->output.buf,
- testing_hcd->output.buf_size,
- &app_info->num_of_buttons[0],
- header_size,
- header_size);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy header data\n");
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- output_size = header_size;
- LOCK_BUFFER(testing_hcd->resp);
- retval = secure_memcpy(testing_hcd->output.buf + header_size,
- testing_hcd->output.buf_size - header_size,
- testing_hcd->resp.buf,
- testing_hcd->resp.buf_size,
- testing_hcd->resp.data_length);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy test data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- output_size += testing_hcd->resp.data_length;
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_hcd->output.data_length = output_size;
- UNLOCK_BUFFER(testing_hcd->output);
- }
- static int testing_dynamic_range_doze(void)
- {
- int retval;
- unsigned char *buf;
- unsigned int idx;
- unsigned int row;
- unsigned int col;
- unsigned int data;
- unsigned int rows;
- unsigned int cols;
- unsigned int data_size;
- unsigned int limits_rows;
- unsigned int limits_cols;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- cols = le2_to_uint(app_info->num_of_image_cols);
- retval = testing_run_prod_test_item(TEST_DYNAMIC_RANGE_DOZE);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- data_size = testing_hcd->resp.data_length / 2;
- if (le2_to_uint(app_info->num_of_buttons))
- data_size--;
- if (data_size % cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Invalid max number of rows per burst\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- rows = data_size / cols;
- limits_rows = ARRAY_SIZE(drt_hi_limits);
- limits_cols = ARRAY_SIZE(drt_hi_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- limits_rows = ARRAY_SIZE(drt_lo_limits);
- limits_cols = ARRAY_SIZE(drt_lo_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- idx = 0;
- buf = testing_hcd->resp.buf;
- testing_hcd->result = true;
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- data = le2_to_uint(&buf[idx * 2]);
- if (data > drt_hi_limits[row][col] ||
- data < drt_lo_limits[row][col]) {
- testing_hcd->result = false;
- break;
- }
- idx++;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_doze_frame_output(rows, cols);
- retval = 0;
- exit:
- if (tcm_hcd->features.dual_firmware) {
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- }
- return retval;
- }
- static int testing_dynamic_range_lpwg(void)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- retval = tcm_hcd->set_dynamic_config(tcm_hcd,
- DC_IN_WAKEUP_GESTURE_MODE,
- 1);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to enable wakeup gesture mode\n");
- return retval;
- }
- retval = testing_dynamic_range();
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do dynamic range test\n");
- return retval;
- }
- retval = tcm_hcd->set_dynamic_config(tcm_hcd,
- DC_IN_WAKEUP_GESTURE_MODE,
- 0);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to disable wakeup gesture mode\n");
- return retval;
- }
- return 0;
- }
- static int testing_dynamic_range(void)
- {
- int retval;
- unsigned char *buf;
- unsigned int idx;
- unsigned int row;
- unsigned int col;
- unsigned int data;
- unsigned int rows;
- unsigned int cols;
- unsigned int limits_rows;
- unsigned int limits_cols;
- unsigned int frame_size_words;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- rows = le2_to_uint(app_info->num_of_image_rows);
- cols = le2_to_uint(app_info->num_of_image_cols);
- testing_get_frame_size_words(&frame_size_words, false);
- retval = testing_run_prod_test_item(TEST_DYNAMIC_RANGE);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- if (frame_size_words != testing_hcd->resp.data_length / 2) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Frame size mismatch\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- limits_rows = ARRAY_SIZE(drt_hi_limits);
- limits_cols = ARRAY_SIZE(drt_hi_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- limits_rows = ARRAY_SIZE(drt_lo_limits);
- limits_cols = ARRAY_SIZE(drt_lo_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- idx = 0;
- buf = testing_hcd->resp.buf;
- testing_hcd->result = true;
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- data = le2_to_uint(&buf[idx * 2]);
- if (data > drt_hi_limits[row][col] ||
- data < drt_lo_limits[row][col]) {
- testing_hcd->result = false;
- break;
- }
- idx++;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_standard_frame_output(false);
- retval = 0;
- exit:
- if (tcm_hcd->features.dual_firmware) {
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- }
- return retval;
- }
- static int testing_noise_doze(void)
- {
- int retval;
- short data;
- unsigned char *buf;
- unsigned int idx;
- unsigned int row;
- unsigned int col;
- unsigned int rows;
- unsigned int cols;
- unsigned int data_size;
- unsigned int limits_rows;
- unsigned int limits_cols;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- cols = le2_to_uint(app_info->num_of_image_cols);
- retval = testing_run_prod_test_item(TEST_NOISE_DOZE);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- data_size = testing_hcd->resp.data_length / 2;
- if (le2_to_uint(app_info->num_of_buttons))
- data_size--;
- if (data_size % cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Invalid max number of rows per burst\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- rows = data_size / cols;
- limits_rows = ARRAY_SIZE(noise_limits);
- limits_cols = ARRAY_SIZE(noise_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- idx = 0;
- buf = testing_hcd->resp.buf;
- testing_hcd->result = true;
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- data = (short)le2_to_uint(&buf[idx * 2]);
- if (data > noise_limits[row][col]) {
- testing_hcd->result = false;
- break;
- }
- idx++;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_doze_frame_output(rows, cols);
- retval = 0;
- exit:
- if (tcm_hcd->features.dual_firmware) {
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- }
- return retval;
- }
- static int testing_noise_lpwg(void)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- retval = tcm_hcd->set_dynamic_config(tcm_hcd,
- DC_IN_WAKEUP_GESTURE_MODE,
- 1);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to enable wakeup gesture mode\n");
- return retval;
- }
- retval = testing_noise();
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do noise test\n");
- return retval;
- }
- retval = tcm_hcd->set_dynamic_config(tcm_hcd,
- DC_IN_WAKEUP_GESTURE_MODE,
- 0);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to disable wakeup gesture mode\n");
- return retval;
- }
- return 0;
- }
- static int testing_noise(void)
- {
- int retval;
- short data;
- unsigned char *buf;
- unsigned int idx;
- unsigned int row;
- unsigned int col;
- unsigned int rows;
- unsigned int cols;
- unsigned int limits_rows;
- unsigned int limits_cols;
- unsigned int frame_size_words;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- rows = le2_to_uint(app_info->num_of_image_rows);
- cols = le2_to_uint(app_info->num_of_image_cols);
- testing_get_frame_size_words(&frame_size_words, false);
- retval = testing_run_prod_test_item(TEST_NOISE);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- if (frame_size_words != testing_hcd->resp.data_length / 2) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Frame size mismatch\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- limits_rows = ARRAY_SIZE(noise_limits);
- limits_cols = ARRAY_SIZE(noise_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- idx = 0;
- buf = testing_hcd->resp.buf;
- testing_hcd->result = true;
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- data = (short)le2_to_uint(&buf[idx * 2]);
- if (data > noise_limits[row][col]) {
- testing_hcd->result = false;
- break;
- }
- idx++;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_standard_frame_output(false);
- retval = 0;
- exit:
- if (tcm_hcd->features.dual_firmware) {
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- }
- return retval;
- }
- static void testing_open_short_detector_output(void)
- {
- int retval;
- unsigned int rows;
- unsigned int cols;
- unsigned int data_size;
- unsigned int header_size;
- unsigned int output_size;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- rows = le2_to_uint(app_info->num_of_image_rows);
- cols = le2_to_uint(app_info->num_of_image_cols);
- data_size = (rows * cols + 7) / 8;
- header_size = sizeof(app_info->num_of_buttons) +
- sizeof(app_info->num_of_image_rows) +
- sizeof(app_info->num_of_image_cols) +
- sizeof(app_info->has_hybrid_data);
- output_size = header_size + data_size * 2;
- LOCK_BUFFER(testing_hcd->output);
- retval = syna_tcm_alloc_mem(tcm_hcd,
- &testing_hcd->output,
- output_size);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for output.buf\n");
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- retval = secure_memcpy(testing_hcd->output.buf,
- testing_hcd->output.buf_size,
- &app_info->num_of_buttons[0],
- header_size,
- header_size);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy header data\n");
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- output_size = header_size;
- LOCK_BUFFER(testing_hcd->resp);
- retval = secure_memcpy(testing_hcd->output.buf + header_size,
- testing_hcd->output.buf_size - header_size,
- testing_hcd->resp.buf,
- testing_hcd->resp.buf_size,
- testing_hcd->resp.data_length);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy test data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- output_size += testing_hcd->resp.data_length;
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_hcd->output.data_length = output_size;
- UNLOCK_BUFFER(testing_hcd->output);
- }
- static int testing_open_short_detector(void)
- {
- int retval;
- unsigned int bit;
- unsigned int byte;
- unsigned int row;
- unsigned int col;
- unsigned int rows;
- unsigned int cols;
- unsigned int data_size;
- unsigned char *data;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- rows = le2_to_uint(app_info->num_of_image_rows);
- cols = le2_to_uint(app_info->num_of_image_cols);
- data_size = (rows * cols + 7) / 8;
- retval = testing_run_prod_test_item(TEST_OPEN_SHORT_DETECTOR);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- if (data_size * 2 != testing_hcd->resp.data_length) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Data size mismatch\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- testing_hcd->result = true;
- bit = 0;
- byte = 0;
- data = &testing_hcd->resp.buf[0];
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- if (data[byte] & (1 << bit)) {
- testing_hcd->result = false;
- break;
- }
- if (bit++ > 7) {
- bit = 0;
- byte++;
- }
- }
- }
- if (testing_hcd->result == true) {
- bit = 0;
- byte = 0;
- data = &testing_hcd->resp.buf[data_size];
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- if (data[byte] & (1 << bit)) {
- testing_hcd->result = false;
- break;
- }
- if (bit++ > 7) {
- bit = 0;
- byte++;
- }
- }
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_open_short_detector_output();
- retval = 0;
- exit:
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- return retval;
- }
- static int testing_pt11(void)
- {
- int retval;
- short data;
- unsigned char *buf;
- unsigned int idx;
- unsigned int row;
- unsigned int col;
- unsigned int rows;
- unsigned int cols;
- unsigned int limits_rows;
- unsigned int limits_cols;
- unsigned int image_size_words;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- rows = le2_to_uint(app_info->num_of_image_rows);
- cols = le2_to_uint(app_info->num_of_image_cols);
- testing_get_frame_size_words(&image_size_words, true);
- retval = testing_run_prod_test_item(TEST_PT11);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- if (image_size_words != testing_hcd->resp.data_length / 2) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Image size mismatch\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- limits_rows = ARRAY_SIZE(pt11_hi_limits);
- limits_cols = ARRAY_SIZE(pt11_hi_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- limits_rows = ARRAY_SIZE(pt11_lo_limits);
- limits_cols = ARRAY_SIZE(pt11_lo_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- idx = 0;
- buf = testing_hcd->resp.buf;
- testing_hcd->result = true;
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- data = (short)le2_to_uint(&buf[idx * 2]);
- if (data > pt11_hi_limits[row][col] ||
- data < pt11_lo_limits[row][col]) {
- testing_hcd->result = false;
- break;
- }
- idx++;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_standard_frame_output(true);
- retval = 0;
- exit:
- if (tcm_hcd->features.dual_firmware) {
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- }
- return retval;
- }
- static int testing_pt12(void)
- {
- int retval;
- short data;
- unsigned char *buf;
- unsigned int idx;
- unsigned int row;
- unsigned int col;
- unsigned int rows;
- unsigned int cols;
- unsigned int limits_rows;
- unsigned int limits_cols;
- unsigned int image_size_words;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- rows = le2_to_uint(app_info->num_of_image_rows);
- cols = le2_to_uint(app_info->num_of_image_cols);
- testing_get_frame_size_words(&image_size_words, true);
- retval = testing_run_prod_test_item(TEST_PT12);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- if (image_size_words != testing_hcd->resp.data_length / 2) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Image size mismatch\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- limits_rows = ARRAY_SIZE(pt12_limits);
- limits_cols = ARRAY_SIZE(pt12_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- idx = 0;
- buf = testing_hcd->resp.buf;
- testing_hcd->result = true;
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- data = (short)le2_to_uint(&buf[idx * 2]);
- if (data < pt12_limits[row][col]) {
- testing_hcd->result = false;
- break;
- }
- idx++;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_standard_frame_output(true);
- retval = 0;
- exit:
- if (tcm_hcd->features.dual_firmware) {
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- }
- return retval;
- }
- static int testing_pt13(void)
- {
- int retval;
- short data;
- unsigned char *buf;
- unsigned int idx;
- unsigned int row;
- unsigned int col;
- unsigned int rows;
- unsigned int cols;
- unsigned int limits_rows;
- unsigned int limits_cols;
- unsigned int image_size_words;
- struct syna_tcm_app_info *app_info;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- app_info = &tcm_hcd->app_info;
- rows = le2_to_uint(app_info->num_of_image_rows);
- cols = le2_to_uint(app_info->num_of_image_cols);
- testing_get_frame_size_words(&image_size_words, true);
- retval = testing_run_prod_test_item(TEST_PT13);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- if (image_size_words != testing_hcd->resp.data_length / 2) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Image size mismatch\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- limits_rows = ARRAY_SIZE(pt13_limits);
- limits_cols = ARRAY_SIZE(pt13_limits[0]);
- if (rows > limits_rows || cols > limits_cols) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- retval = -EINVAL;
- goto exit;
- }
- idx = 0;
- buf = testing_hcd->resp.buf;
- testing_hcd->result = true;
- for (row = 0; row < rows; row++) {
- for (col = 0; col < cols; col++) {
- data = (short)le2_to_uint(&buf[idx * 2]);
- if (data < pt13_limits[row][col]) {
- testing_hcd->result = false;
- break;
- }
- idx++;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_standard_frame_output(true);
- retval = 0;
- exit:
- if (tcm_hcd->features.dual_firmware) {
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- }
- return retval;
- }
- static int testing_reset_open(void)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- const struct syna_tcm_board_data *bdata = tcm_hcd->hw_if->bdata;
- if (bdata->reset_gpio < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Hardware reset unavailable\n");
- return -EINVAL;
- }
- mutex_lock(&tcm_hcd->reset_mutex);
- tcm_hcd->update_watchdog(tcm_hcd, false);
- gpio_set_value(bdata->reset_gpio, bdata->reset_on_state);
- msleep(bdata->reset_active_ms);
- gpio_set_value(bdata->reset_gpio, !bdata->reset_on_state);
- msleep(bdata->reset_delay_ms);
- tcm_hcd->update_watchdog(tcm_hcd, true);
- mutex_unlock(&tcm_hcd->reset_mutex);
- if (tcm_hcd->id_info.mode == MODE_APPLICATION) {
- retval = tcm_hcd->switch_mode(tcm_hcd, FW_MODE_BOOTLOADER);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to enter bootloader mode\n");
- return retval;
- }
- } else {
- retval = tcm_hcd->identify(tcm_hcd, false);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do identification\n");
- goto run_app_firmware;
- }
- }
- if (tcm_hcd->boot_info.last_reset_reason == reset_open_limit)
- testing_hcd->result = true;
- else
- testing_hcd->result = false;
- retval = 0;
- run_app_firmware:
- if (tcm_hcd->switch_mode(tcm_hcd, FW_MODE_APPLICATION) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run application firmware\n");
- }
- return retval;
- }
- static void testing_lockdown_output(void)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- LOCK_BUFFER(testing_hcd->output);
- LOCK_BUFFER(testing_hcd->resp);
- retval = syna_tcm_alloc_mem(tcm_hcd,
- &testing_hcd->output,
- testing_hcd->resp.data_length);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for output.buf\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- retval = secure_memcpy(testing_hcd->output.buf,
- testing_hcd->output.buf_size,
- testing_hcd->resp.buf,
- testing_hcd->resp.buf_size,
- testing_hcd->resp.data_length);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy test data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- testing_hcd->output.data_length = testing_hcd->resp.data_length;
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- }
- static int testing_lockdown(void)
- {
- int retval;
- unsigned int idx;
- unsigned int lockdown_size;
- unsigned int limits_size;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- if (tcm_hcd->read_flash_data == NULL) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Unable to read from flash\n");
- return -EINVAL;
- }
- LOCK_BUFFER(testing_hcd->resp);
- retval = tcm_hcd->read_flash_data(CUSTOM_OTP, true, &testing_hcd->resp);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to read lockdown data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- return retval;
- }
- lockdown_size = testing_hcd->resp.data_length;
- limits_size = sizeof(lockdown_limits) / sizeof(*lockdown_limits);
- if (lockdown_size != limits_size) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Mismatching limits data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- return -EINVAL;
- }
- testing_hcd->result = true;
- for (idx = 0; idx < lockdown_size; idx++) {
- if (testing_hcd->resp.buf[idx] != lockdown_limits[idx]) {
- testing_hcd->result = false;
- break;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_lockdown_output();
- return 0;
- }
- static void testing_trx_output(void)
- {
- int retval;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- LOCK_BUFFER(testing_hcd->output);
- LOCK_BUFFER(testing_hcd->resp);
- retval = syna_tcm_alloc_mem(tcm_hcd,
- &testing_hcd->output,
- testing_hcd->resp.data_length);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for output.buf\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- retval = secure_memcpy(testing_hcd->output.buf,
- testing_hcd->output.buf_size,
- testing_hcd->resp.buf,
- testing_hcd->resp.buf_size,
- testing_hcd->resp.data_length);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy test data\n");
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- return;
- }
- testing_hcd->output.data_length = testing_hcd->resp.data_length;
- UNLOCK_BUFFER(testing_hcd->resp);
- UNLOCK_BUFFER(testing_hcd->output);
- }
- static int testing_trx(enum test_code test_code)
- {
- int retval;
- unsigned char pass_vector;
- unsigned int idx;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- switch (test_code) {
- case TEST_TRX_TRX_SHORTS:
- case TEST_TRX_GROUND_SHORTS:
- pass_vector = 0xff;
- break;
- case TEST_TRX_SENSOR_OPENS:
- pass_vector = 0x00;
- break;
- default:
- return -EINVAL;
- }
- retval = testing_run_prod_test_item(test_code);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to run test\n");
- goto exit;
- }
- LOCK_BUFFER(testing_hcd->resp);
- testing_hcd->result = true;
- for (idx = 0; idx < testing_hcd->resp.data_length; idx++) {
- if (testing_hcd->resp.buf[idx] != pass_vector) {
- testing_hcd->result = false;
- break;
- }
- }
- UNLOCK_BUFFER(testing_hcd->resp);
- testing_trx_output();
- retval = 0;
- exit:
- if (tcm_hcd->features.dual_firmware) {
- if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to do reset\n");
- }
- }
- return retval;
- }
- static void testing_report(void)
- {
- int retval;
- unsigned int offset;
- unsigned int report_size;
- struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
- report_size = tcm_hcd->report.buffer.data_length;
- LOCK_BUFFER(testing_hcd->report);
- if (testing_hcd->report_index == 0) {
- retval = syna_tcm_alloc_mem(tcm_hcd,
- &testing_hcd->report,
- report_size * testing_hcd->num_of_reports);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for report.buf\n");
- UNLOCK_BUFFER(testing_hcd->report);
- return;
- }
- }
- if (testing_hcd->report_index < testing_hcd->num_of_reports) {
- offset = report_size * testing_hcd->report_index;
- retval = secure_memcpy(testing_hcd->report.buf + offset,
- testing_hcd->report.buf_size - offset,
- tcm_hcd->report.buffer.buf,
- tcm_hcd->report.buffer.buf_size,
- tcm_hcd->report.buffer.data_length);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to copy report data\n");
- UNLOCK_BUFFER(testing_hcd->report);
- return;
- }
- testing_hcd->report_index++;
- testing_hcd->report.data_length += report_size;
- }
- UNLOCK_BUFFER(testing_hcd->report);
- if (testing_hcd->report_index == testing_hcd->num_of_reports)
- complete(&report_complete);
- }
- static int testing_init(struct syna_tcm_hcd *tcm_hcd)
- {
- int retval;
- int idx;
- testing_hcd = kzalloc(sizeof(*testing_hcd), GFP_KERNEL);
- if (!testing_hcd) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to allocate memory for testing_hcd\n");
- return -ENOMEM;
- }
- testing_hcd->tcm_hcd = tcm_hcd;
- testing_hcd->collect_reports = testing_collect_reports;
- INIT_BUFFER(testing_hcd->out, false);
- INIT_BUFFER(testing_hcd->resp, false);
- INIT_BUFFER(testing_hcd->report, false);
- INIT_BUFFER(testing_hcd->process, false);
- INIT_BUFFER(testing_hcd->output, false);
- testing_hcd->sysfs_dir = kobject_create_and_add(SYSFS_DIR_NAME,
- tcm_hcd->sysfs_dir);
- if (!testing_hcd->sysfs_dir) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to create sysfs directory\n");
- retval = -EINVAL;
- goto err_sysfs_create_dir;
- }
- for (idx = 0; idx < ARRAY_SIZE(attrs); idx++) {
- retval = sysfs_create_file(testing_hcd->sysfs_dir,
- &(*attrs[idx]).attr);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to create sysfs file\n");
- goto err_sysfs_create_file;
- }
- }
- retval = sysfs_create_bin_file(testing_hcd->sysfs_dir, &bin_attr);
- if (retval < 0) {
- LOGE(tcm_hcd->pdev->dev.parent,
- "Failed to create sysfs bin file\n");
- goto err_sysfs_create_bin_file;
- }
- return 0;
- err_sysfs_create_bin_file:
- err_sysfs_create_file:
- for (idx--; idx >= 0; idx--)
- sysfs_remove_file(testing_hcd->sysfs_dir, &(*attrs[idx]).attr);
- kobject_put(testing_hcd->sysfs_dir);
- err_sysfs_create_dir:
- RELEASE_BUFFER(testing_hcd->output);
- RELEASE_BUFFER(testing_hcd->process);
- RELEASE_BUFFER(testing_hcd->report);
- RELEASE_BUFFER(testing_hcd->resp);
- RELEASE_BUFFER(testing_hcd->out);
- kfree(testing_hcd);
- testing_hcd = NULL;
- return retval;
- }
- static int testing_remove(struct syna_tcm_hcd *tcm_hcd)
- {
- int idx;
- if (!testing_hcd)
- goto exit;
- sysfs_remove_bin_file(testing_hcd->sysfs_dir, &bin_attr);
- for (idx = 0; idx < ARRAY_SIZE(attrs); idx++)
- sysfs_remove_file(testing_hcd->sysfs_dir, &(*attrs[idx]).attr);
- kobject_put(testing_hcd->sysfs_dir);
- RELEASE_BUFFER(testing_hcd->output);
- RELEASE_BUFFER(testing_hcd->process);
- RELEASE_BUFFER(testing_hcd->report);
- RELEASE_BUFFER(testing_hcd->resp);
- RELEASE_BUFFER(testing_hcd->out);
- kfree(testing_hcd);
- testing_hcd = NULL;
- exit:
- complete(&testing_remove_complete);
- return 0;
- }
- static int testing_reset(struct syna_tcm_hcd *tcm_hcd)
- {
- int retval;
- if (!testing_hcd) {
- retval = testing_init(tcm_hcd);
- return retval;
- }
- return 0;
- }
- static int testing_syncbox(struct syna_tcm_hcd *tcm_hcd)
- {
- if (!testing_hcd)
- return 0;
- if (tcm_hcd->report.id == testing_hcd->report_type)
- testing_report();
- return 0;
- }
- static struct syna_tcm_module_cb testing_module = {
- .type = TCM_TESTING,
- .init = testing_init,
- .remove = testing_remove,
- .syncbox = testing_syncbox,
- .asyncbox = NULL,
- .reset = testing_reset,
- .suspend = NULL,
- .resume = NULL,
- .early_suspend = NULL,
- };
- static int __init testing_module_init(void)
- {
- return syna_tcm_add_module(&testing_module, true);
- }
- static void __exit testing_module_exit(void)
- {
- syna_tcm_add_module(&testing_module, false);
- wait_for_completion(&testing_remove_complete);
- }
- module_init(testing_module_init);
- module_exit(testing_module_exit);
- MODULE_AUTHOR("Synaptics, Inc.");
- MODULE_DESCRIPTION("Synaptics TCM Testing Module");
- MODULE_LICENSE("GPL v2");
|