123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700 |
- /*
- * Synaptics RMI4 touchscreen driver
- *
- * Copyright (C) 2012 Synaptics Incorporated
- *
- * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com>
- * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com>
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
- *
- * 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.
- */
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/slab.h>
- #include <linux/i2c.h>
- #include <linux/interrupt.h>
- #include <linux/delay.h>
- #include <linux/input.h>
- #include <linux/gpio.h>
- #include <linux/regulator/consumer.h>
- #include <linux/input/synaptics_dsx.h>
- #include <linux/of_gpio.h>
- #include "synaptics_i2c_rmi4.h"
- #include <linux/input/mt.h>
- #define DRIVER_NAME "synaptics_rmi4_i2c"
- #define INPUT_PHYS_NAME "synaptics_rmi4_i2c/input0"
- #define RESET_DELAY 100
- #define TYPE_B_PROTOCOL
- #define NO_0D_WHILE_2D
- /*
- #define REPORT_2D_Z
- */
- #define REPORT_2D_W
- #define RPT_TYPE (1 << 0)
- #define RPT_X_LSB (1 << 1)
- #define RPT_X_MSB (1 << 2)
- #define RPT_Y_LSB (1 << 3)
- #define RPT_Y_MSB (1 << 4)
- #define RPT_Z (1 << 5)
- #define RPT_WX (1 << 6)
- #define RPT_WY (1 << 7)
- #define RPT_DEFAULT (RPT_TYPE | RPT_X_LSB | RPT_X_MSB | RPT_Y_LSB | RPT_Y_MSB)
- #define EXP_FN_DET_INTERVAL 1000 /* ms */
- #define POLLING_PERIOD 1 /* ms */
- #define SYN_I2C_RETRY_TIMES 10
- #define MAX_ABS_MT_TOUCH_MAJOR 15
- #define F01_STD_QUERY_LEN 21
- #define F01_BUID_ID_OFFSET 18
- #define F11_STD_QUERY_LEN 9
- #define F11_STD_CTRL_LEN 10
- #define F11_STD_DATA_LEN 12
- #define NORMAL_OPERATION (0 << 0)
- #define SENSOR_SLEEP (1 << 0)
- #define NO_SLEEP_OFF (0 << 2)
- #define NO_SLEEP_ON (1 << 2)
- enum device_status {
- STATUS_NO_ERROR = 0x00,
- STATUS_RESET_OCCURED = 0x01,
- STATUS_INVALID_CONFIG = 0x02,
- STATUS_DEVICE_FAILURE = 0x03,
- STATUS_CONFIG_CRC_FAILURE = 0x04,
- STATUS_FIRMWARE_CRC_FAILURE = 0x05,
- STATUS_CRC_IN_PROGRESS = 0x06
- };
- #define RMI4_VTG_MIN_UV 2700000
- #define RMI4_VTG_MAX_UV 3300000
- #define RMI4_ACTIVE_LOAD_UA 15000
- #define RMI4_LPM_LOAD_UA 10
- #define RMI4_I2C_VTG_MIN_UV 1800000
- #define RMI4_I2C_VTG_MAX_UV 1800000
- #define RMI4_I2C_LOAD_UA 10000
- #define RMI4_I2C_LPM_LOAD_UA 10
- #define RMI4_GPIO_SLEEP_LOW_US 10000
- static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
- unsigned short addr, unsigned char *data,
- unsigned short length);
- static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
- unsigned short addr, unsigned char *data,
- unsigned short length);
- static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data);
- #ifdef CONFIG_PM
- static int synaptics_rmi4_suspend(struct device *dev);
- static int synaptics_rmi4_resume(struct device *dev);
- #ifdef CONFIG_HAS_EARLYSUSPEND
- static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count);
- static void synaptics_rmi4_early_suspend(struct early_suspend *h);
- static void synaptics_rmi4_late_resume(struct early_suspend *h);
- #endif
- #endif
- static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count);
- static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count);
- static ssize_t synaptics_rmi4_flipx_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t synaptics_rmi4_flipx_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count);
- static ssize_t synaptics_rmi4_flipy_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t synaptics_rmi4_flipy_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count);
- struct synaptics_rmi4_f01_device_status {
- union {
- struct {
- unsigned char status_code:4;
- unsigned char reserved:2;
- unsigned char flash_prog:1;
- unsigned char unconfigured:1;
- } __packed;
- unsigned char data[1];
- };
- };
- struct synaptics_rmi4_f1a_query {
- union {
- struct {
- unsigned char max_button_count:3;
- unsigned char reserved:5;
- unsigned char has_general_control:1;
- unsigned char has_interrupt_enable:1;
- unsigned char has_multibutton_select:1;
- unsigned char has_tx_rx_map:1;
- unsigned char has_perbutton_threshold:1;
- unsigned char has_release_threshold:1;
- unsigned char has_strongestbtn_hysteresis:1;
- unsigned char has_filter_strength:1;
- } __packed;
- unsigned char data[2];
- };
- };
- struct synaptics_rmi4_f1a_control_0 {
- union {
- struct {
- unsigned char multibutton_report:2;
- unsigned char filter_mode:2;
- unsigned char reserved:4;
- } __packed;
- unsigned char data[1];
- };
- };
- struct synaptics_rmi4_f1a_control_3_4 {
- unsigned char transmitterbutton;
- unsigned char receiverbutton;
- };
- struct synaptics_rmi4_f1a_control {
- struct synaptics_rmi4_f1a_control_0 general_control;
- unsigned char *button_int_enable;
- unsigned char *multi_button;
- struct synaptics_rmi4_f1a_control_3_4 *electrode_map;
- unsigned char *button_threshold;
- unsigned char button_release_threshold;
- unsigned char strongest_button_hysteresis;
- unsigned char filter_strength;
- };
- struct synaptics_rmi4_f1a_handle {
- int button_bitmask_size;
- unsigned char button_count;
- unsigned char valid_button_count;
- unsigned char *button_data_buffer;
- unsigned char *button_map;
- struct synaptics_rmi4_f1a_query button_query;
- struct synaptics_rmi4_f1a_control button_control;
- };
- struct synaptics_rmi4_exp_fn {
- enum exp_fn fn_type;
- bool inserted;
- int (*func_init)(struct synaptics_rmi4_data *rmi4_data);
- void (*func_remove)(struct synaptics_rmi4_data *rmi4_data);
- void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
- unsigned char intr_mask);
- struct list_head link;
- };
- static struct device_attribute attrs[] = {
- #ifdef CONFIG_HAS_EARLYSUSPEND
- __ATTR(full_pm_cycle, (S_IRUGO | S_IWUGO),
- synaptics_rmi4_full_pm_cycle_show,
- synaptics_rmi4_full_pm_cycle_store),
- #endif
- __ATTR(reset, S_IWUGO,
- synaptics_rmi4_show_error,
- synaptics_rmi4_f01_reset_store),
- __ATTR(productinfo, S_IRUGO,
- synaptics_rmi4_f01_productinfo_show,
- synaptics_rmi4_store_error),
- __ATTR(buildid, S_IRUGO,
- synaptics_rmi4_f01_buildid_show,
- synaptics_rmi4_store_error),
- __ATTR(flashprog, S_IRUGO,
- synaptics_rmi4_f01_flashprog_show,
- synaptics_rmi4_store_error),
- __ATTR(0dbutton, (S_IRUGO | S_IWUGO),
- synaptics_rmi4_0dbutton_show,
- synaptics_rmi4_0dbutton_store),
- __ATTR(flipx, (S_IRUGO | S_IWUGO),
- synaptics_rmi4_flipx_show,
- synaptics_rmi4_flipx_store),
- __ATTR(flipy, (S_IRUGO | S_IWUGO),
- synaptics_rmi4_flipy_show,
- synaptics_rmi4_flipy_store),
- };
- static bool exp_fn_inited;
- static struct mutex exp_fn_list_mutex;
- static struct list_head exp_fn_list;
- #ifdef CONFIG_HAS_EARLYSUSPEND
- static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "%u\n",
- rmi4_data->full_pm_cycle);
- }
- static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- unsigned int input;
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- if (sscanf(buf, "%u", &input) != 1)
- return -EINVAL;
- rmi4_data->full_pm_cycle = input > 0 ? 1 : 0;
- return count;
- }
- #endif
- static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int retval;
- unsigned int reset;
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- if (sscanf(buf, "%u", &reset) != 1)
- return -EINVAL;
- if (reset != 1)
- return -EINVAL;
- retval = synaptics_rmi4_reset_device(rmi4_data);
- if (retval < 0) {
- dev_err(dev,
- "%s: Failed to issue reset command, error = %d\n",
- __func__, retval);
- return retval;
- }
- return count;
- }
- static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n",
- (rmi4_data->rmi4_mod_info.product_info[0]),
- (rmi4_data->rmi4_mod_info.product_info[1]));
- }
- static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- unsigned int build_id;
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- struct synaptics_rmi4_device_info *rmi;
- rmi = &(rmi4_data->rmi4_mod_info);
- build_id = (unsigned int)rmi->build_id[0] +
- (unsigned int)rmi->build_id[1] * 0x100 +
- (unsigned int)rmi->build_id[2] * 0x10000;
- return snprintf(buf, PAGE_SIZE, "%u\n",
- build_id);
- }
- static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int retval;
- struct synaptics_rmi4_f01_device_status device_status;
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_data_base_addr,
- device_status.data,
- sizeof(device_status.data));
- if (retval < 0) {
- dev_err(dev,
- "%s: Failed to read device status, error = %d\n",
- __func__, retval);
- return retval;
- }
- return snprintf(buf, PAGE_SIZE, "%u\n",
- device_status.flash_prog);
- }
- static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "%u\n",
- rmi4_data->button_0d_enabled);
- }
- static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int retval;
- unsigned int input;
- unsigned char ii;
- unsigned char intr_enable;
- struct synaptics_rmi4_fn *fhandler;
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- struct synaptics_rmi4_device_info *rmi;
- rmi = &(rmi4_data->rmi4_mod_info);
- if (sscanf(buf, "%u", &input) != 1)
- return -EINVAL;
- input = input > 0 ? 1 : 0;
- if (rmi4_data->button_0d_enabled == input)
- return count;
- if (!list_empty(&rmi->support_fn_list)) {
- list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
- if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) {
- ii = fhandler->intr_reg_num;
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_ctrl_base_addr +
- 1 + ii,
- &intr_enable,
- sizeof(intr_enable));
- if (retval < 0)
- return retval;
- if (input == 1)
- intr_enable |= fhandler->intr_mask;
- else
- intr_enable &= ~fhandler->intr_mask;
- retval = synaptics_rmi4_i2c_write(rmi4_data,
- rmi4_data->f01_ctrl_base_addr +
- 1 + ii,
- &intr_enable,
- sizeof(intr_enable));
- if (retval < 0)
- return retval;
- }
- }
- }
- rmi4_data->button_0d_enabled = input;
- return count;
- }
- static ssize_t synaptics_rmi4_flipx_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "%u\n",
- rmi4_data->flip_x);
- }
- static ssize_t synaptics_rmi4_flipx_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- unsigned int input;
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- if (sscanf(buf, "%u", &input) != 1)
- return -EINVAL;
- rmi4_data->flip_x = input > 0 ? 1 : 0;
- return count;
- }
- static ssize_t synaptics_rmi4_flipy_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- return snprintf(buf, PAGE_SIZE, "%u\n",
- rmi4_data->flip_y);
- }
- static ssize_t synaptics_rmi4_flipy_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- unsigned int input;
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- if (sscanf(buf, "%u", &input) != 1)
- return -EINVAL;
- rmi4_data->flip_y = input > 0 ? 1 : 0;
- return count;
- }
- /**
- * synaptics_rmi4_set_page()
- *
- * Called by synaptics_rmi4_i2c_read() and synaptics_rmi4_i2c_write().
- *
- * This function writes to the page select register to switch to the
- * assigned page.
- */
- static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *rmi4_data,
- unsigned int address)
- {
- int retval = 0;
- unsigned char retry;
- unsigned char buf[PAGE_SELECT_LEN];
- unsigned char page;
- struct i2c_client *i2c = rmi4_data->i2c_client;
- page = ((address >> 8) & MASK_8BIT);
- if (page != rmi4_data->current_page) {
- buf[0] = MASK_8BIT;
- buf[1] = page;
- for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
- retval = i2c_master_send(i2c, buf, PAGE_SELECT_LEN);
- if (retval != PAGE_SELECT_LEN) {
- dev_err(&i2c->dev,
- "%s: I2C retry %d\n",
- __func__, retry + 1);
- msleep(20);
- } else {
- rmi4_data->current_page = page;
- break;
- }
- }
- } else
- return PAGE_SELECT_LEN;
- return (retval == PAGE_SELECT_LEN) ? retval : -EIO;
- }
- /**
- * synaptics_rmi4_i2c_read()
- *
- * Called by various functions in this driver, and also exported to
- * other expansion Function modules such as rmi_dev.
- *
- * This function reads data of an arbitrary length from the sensor,
- * starting from an assigned register address of the sensor, via I2C
- * with a retry mechanism.
- */
- static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
- unsigned short addr, unsigned char *data, unsigned short length)
- {
- int retval;
- unsigned char retry;
- unsigned char buf;
- struct i2c_msg msg[] = {
- {
- .addr = rmi4_data->i2c_client->addr,
- .flags = 0,
- .len = 1,
- .buf = &buf,
- },
- {
- .addr = rmi4_data->i2c_client->addr,
- .flags = I2C_M_RD,
- .len = length,
- .buf = data,
- },
- };
- buf = addr & MASK_8BIT;
- mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex));
- retval = synaptics_rmi4_set_page(rmi4_data, addr);
- if (retval != PAGE_SELECT_LEN)
- goto exit;
- for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
- if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 2) == 2) {
- retval = length;
- break;
- }
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: I2C retry %d\n",
- __func__, retry + 1);
- msleep(20);
- }
- if (retry == SYN_I2C_RETRY_TIMES) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: I2C read over retry limit\n",
- __func__);
- retval = -EIO;
- }
- exit:
- mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex));
- return retval;
- }
- /**
- * synaptics_rmi4_i2c_write()
- *
- * Called by various functions in this driver, and also exported to
- * other expansion Function modules such as rmi_dev.
- *
- * This function writes data of an arbitrary length to the sensor,
- * starting from an assigned register address of the sensor, via I2C with
- * a retry mechanism.
- */
- static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
- unsigned short addr, unsigned char *data, unsigned short length)
- {
- int retval;
- unsigned char retry;
- unsigned char buf[length + 1];
- struct i2c_msg msg[] = {
- {
- .addr = rmi4_data->i2c_client->addr,
- .flags = 0,
- .len = length + 1,
- .buf = buf,
- }
- };
- mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex));
- retval = synaptics_rmi4_set_page(rmi4_data, addr);
- if (retval != PAGE_SELECT_LEN)
- goto exit;
- buf[0] = addr & MASK_8BIT;
- memcpy(&buf[1], &data[0], length);
- for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
- if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 1) == 1) {
- retval = length;
- break;
- }
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: I2C retry %d\n",
- __func__, retry + 1);
- msleep(20);
- }
- if (retry == SYN_I2C_RETRY_TIMES) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: I2C write over retry limit\n",
- __func__);
- retval = -EIO;
- }
- exit:
- mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex));
- return retval;
- }
- /**
- * synaptics_rmi4_f11_abs_report()
- *
- * Called by synaptics_rmi4_report_touch() when valid Function $11
- * finger data has been detected.
- *
- * This function reads the Function $11 data registers, determines the
- * status of each finger supported by the Function, processes any
- * necessary coordinate manipulation, reports the finger data to
- * the input subsystem, and returns the number of fingers detected.
- */
- static int synaptics_rmi4_f11_abs_report(struct synaptics_rmi4_data *rmi4_data,
- struct synaptics_rmi4_fn *fhandler)
- {
- int retval;
- unsigned char touch_count = 0; /* number of touch points */
- unsigned char reg_index;
- unsigned char finger;
- unsigned char fingers_supported;
- unsigned char num_of_finger_status_regs;
- unsigned char finger_shift;
- unsigned char finger_status;
- unsigned char data_reg_blk_size;
- unsigned char finger_status_reg[3];
- unsigned char data[F11_STD_DATA_LEN];
- unsigned short data_addr;
- unsigned short data_offset;
- int x;
- int y;
- int wx;
- int wy;
- int z;
- /*
- * The number of finger status registers is determined by the
- * maximum number of fingers supported - 2 bits per finger. So
- * the number of finger status registers to read is:
- * register_count = ceil(max_num_of_fingers / 4)
- */
- fingers_supported = fhandler->num_of_data_points;
- num_of_finger_status_regs = (fingers_supported + 3) / 4;
- data_addr = fhandler->full_addr.data_base;
- data_reg_blk_size = fhandler->size_of_data_register_block;
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- data_addr,
- finger_status_reg,
- num_of_finger_status_regs);
- if (retval < 0)
- return 0;
- for (finger = 0; finger < fingers_supported; finger++) {
- reg_index = finger / 4;
- finger_shift = (finger % 4) * 2;
- finger_status = (finger_status_reg[reg_index] >> finger_shift)
- & MASK_2BIT;
- /*
- * Each 2-bit finger status field represents the following:
- * 00 = finger not present
- * 01 = finger present and data accurate
- * 10 = finger present but data may be inaccurate
- * 11 = reserved
- */
- #ifdef TYPE_B_PROTOCOL
- input_mt_slot(rmi4_data->input_dev, finger);
- input_mt_report_slot_state(rmi4_data->input_dev,
- MT_TOOL_FINGER, finger_status != 0);
- #endif
- if (finger_status) {
- data_offset = data_addr +
- num_of_finger_status_regs +
- (finger * data_reg_blk_size);
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- data_offset,
- data,
- data_reg_blk_size);
- if (retval < 0)
- return 0;
- x = (data[0] << 4) | (data[2] & MASK_4BIT);
- y = (data[1] << 4) | ((data[2] >> 4) & MASK_4BIT);
- wx = (data[3] & MASK_4BIT);
- wy = (data[3] >> 4) & MASK_4BIT;
- z = data[4];
- if (rmi4_data->flip_x)
- x = rmi4_data->sensor_max_x - x;
- if (rmi4_data->flip_y)
- y = rmi4_data->sensor_max_y - y;
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Finger %d:\n"
- "status = 0x%02x\n"
- "x = %d\n"
- "y = %d\n"
- "wx = %d\n"
- "wy = %d\n",
- __func__, finger,
- finger_status,
- x, y, wx, wy);
- input_report_abs(rmi4_data->input_dev,
- ABS_MT_POSITION_X, x);
- input_report_abs(rmi4_data->input_dev,
- ABS_MT_POSITION_Y, y);
- input_report_abs(rmi4_data->input_dev,
- ABS_MT_PRESSURE, z);
- #ifdef REPORT_2D_W
- input_report_abs(rmi4_data->input_dev,
- ABS_MT_TOUCH_MAJOR, max(wx, wy));
- input_report_abs(rmi4_data->input_dev,
- ABS_MT_TOUCH_MINOR, min(wx, wy));
- #endif
- #ifndef TYPE_B_PROTOCOL
- input_mt_sync(rmi4_data->input_dev);
- #endif
- touch_count++;
- }
- }
- input_report_key(rmi4_data->input_dev, BTN_TOUCH, touch_count > 0);
- input_report_key(rmi4_data->input_dev,
- BTN_TOOL_FINGER, touch_count > 0);
- #ifndef TYPE_B_PROTOCOL
- if (!touch_count)
- input_mt_sync(rmi4_data->input_dev);
- #else
- /* sync after groups of events */
- #ifdef KERNEL_ABOVE_3_7
- input_mt_sync_frame(rmi4_data->input_dev);
- #endif
- #endif
- input_sync(rmi4_data->input_dev);
- return touch_count;
- }
- static void synaptics_rmi4_f1a_report(struct synaptics_rmi4_data *rmi4_data,
- struct synaptics_rmi4_fn *fhandler)
- {
- int retval;
- unsigned char button;
- unsigned char index;
- unsigned char shift;
- unsigned char status;
- unsigned char *data;
- unsigned short data_addr = fhandler->full_addr.data_base;
- struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
- static unsigned char do_once = 1;
- static bool current_status[MAX_NUMBER_OF_BUTTONS];
- #ifdef NO_0D_WHILE_2D
- static bool before_2d_status[MAX_NUMBER_OF_BUTTONS];
- static bool while_2d_status[MAX_NUMBER_OF_BUTTONS];
- #endif
- if (do_once) {
- memset(current_status, 0, sizeof(current_status));
- #ifdef NO_0D_WHILE_2D
- memset(before_2d_status, 0, sizeof(before_2d_status));
- memset(while_2d_status, 0, sizeof(while_2d_status));
- #endif
- do_once = 0;
- }
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- data_addr,
- f1a->button_data_buffer,
- f1a->button_bitmask_size);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read button data registers\n",
- __func__);
- return;
- }
- data = f1a->button_data_buffer;
- for (button = 0; button < f1a->valid_button_count; button++) {
- index = button / 8;
- shift = button % 8;
- status = ((data[index] >> shift) & MASK_1BIT);
- if (current_status[button] == status)
- continue;
- else
- current_status[button] = status;
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Button %d (code %d) ->%d\n",
- __func__, button,
- f1a->button_map[button],
- status);
- #ifdef NO_0D_WHILE_2D
- if (rmi4_data->fingers_on_2d == false) {
- if (status == 1) {
- before_2d_status[button] = 1;
- } else {
- if (while_2d_status[button] == 1) {
- while_2d_status[button] = 0;
- continue;
- } else {
- before_2d_status[button] = 0;
- }
- }
- input_report_key(rmi4_data->input_dev,
- f1a->button_map[button],
- status);
- } else {
- if (before_2d_status[button] == 1) {
- before_2d_status[button] = 0;
- input_report_key(rmi4_data->input_dev,
- f1a->button_map[button],
- status);
- } else {
- if (status == 1)
- while_2d_status[button] = 1;
- else
- while_2d_status[button] = 0;
- }
- }
- #else
- input_report_key(rmi4_data->input_dev,
- f1a->button_map[button],
- status);
- #endif
- }
- input_sync(rmi4_data->input_dev);
- return;
- }
- /**
- * synaptics_rmi4_report_touch()
- *
- * Called by synaptics_rmi4_sensor_report().
- *
- * This function calls the appropriate finger data reporting function
- * based on the function handler it receives and returns the number of
- * fingers detected.
- */
- static void synaptics_rmi4_report_touch(struct synaptics_rmi4_data *rmi4_data,
- struct synaptics_rmi4_fn *fhandler,
- unsigned char *touch_count)
- {
- unsigned char touch_count_2d;
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Function %02x reporting\n",
- __func__, fhandler->fn_number);
- switch (fhandler->fn_number) {
- case SYNAPTICS_RMI4_F11:
- touch_count_2d = synaptics_rmi4_f11_abs_report(rmi4_data,
- fhandler);
- *touch_count += touch_count_2d;
- if (touch_count_2d)
- rmi4_data->fingers_on_2d = true;
- else
- rmi4_data->fingers_on_2d = false;
- break;
- case SYNAPTICS_RMI4_F1A:
- synaptics_rmi4_f1a_report(rmi4_data, fhandler);
- break;
- default:
- break;
- }
- return;
- }
- /**
- * synaptics_rmi4_sensor_report()
- *
- * Called by synaptics_rmi4_irq().
- *
- * This function determines the interrupt source(s) from the sensor
- * and calls synaptics_rmi4_report_touch() with the appropriate
- * function handler for each function with valid data inputs.
- */
- static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- unsigned char touch_count = 0;
- unsigned char intr[MAX_INTR_REGISTERS];
- struct synaptics_rmi4_fn *fhandler;
- struct synaptics_rmi4_exp_fn *exp_fhandler;
- struct synaptics_rmi4_device_info *rmi;
- rmi = &(rmi4_data->rmi4_mod_info);
- /*
- * Get interrupt status information from F01 Data1 register to
- * determine the source(s) that are flagging the interrupt.
- */
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_data_base_addr + 1,
- intr,
- rmi4_data->num_of_intr_regs);
- if (retval < 0)
- return retval;
- /*
- * Traverse the function handler list and service the source(s)
- * of the interrupt accordingly.
- */
- if (!list_empty(&rmi->support_fn_list)) {
- list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
- if (fhandler->num_of_data_sources) {
- if (fhandler->intr_mask &
- intr[fhandler->intr_reg_num]) {
- synaptics_rmi4_report_touch(rmi4_data,
- fhandler, &touch_count);
- }
- }
- }
- }
- mutex_lock(&exp_fn_list_mutex);
- if (!list_empty(&exp_fn_list)) {
- list_for_each_entry(exp_fhandler, &exp_fn_list, link) {
- if (exp_fhandler->inserted &&
- (exp_fhandler->func_attn != NULL))
- exp_fhandler->func_attn(rmi4_data, intr[0]);
- }
- }
- mutex_unlock(&exp_fn_list_mutex);
- return touch_count;
- }
- /**
- * synaptics_rmi4_irq()
- *
- * Called by the kernel when an interrupt occurs (when the sensor
- * asserts the attention irq).
- *
- * This function is the ISR thread and handles the acquisition
- * and the reporting of finger data when the presence of fingers
- * is detected.
- */
- static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
- {
- struct synaptics_rmi4_data *rmi4_data = data;
- synaptics_rmi4_sensor_report(rmi4_data);
- return IRQ_HANDLED;
- }
- static int synaptics_rmi4_parse_dt(struct device *dev,
- struct synaptics_rmi4_platform_data *rmi4_pdata)
- {
- struct device_node *np = dev->of_node;
- struct property *prop;
- u32 temp_val, num_buttons;
- u32 button_map[MAX_NUMBER_OF_BUTTONS];
- int rc, i;
- rmi4_pdata->i2c_pull_up = of_property_read_bool(np,
- "synaptics,i2c-pull-up");
- rmi4_pdata->regulator_en = of_property_read_bool(np,
- "synaptics,reg-en");
- rmi4_pdata->x_flip = of_property_read_bool(np, "synaptics,x-flip");
- rmi4_pdata->y_flip = of_property_read_bool(np, "synaptics,y-flip");
- rc = of_property_read_u32(np, "synaptics,panel-x", &temp_val);
- if (rc && (rc != -EINVAL)) {
- dev_err(dev, "Unable to read panel X dimension\n");
- return rc;
- } else {
- rmi4_pdata->panel_x = temp_val;
- }
- rc = of_property_read_u32(np, "synaptics,panel-y", &temp_val);
- if (rc && (rc != -EINVAL)) {
- dev_err(dev, "Unable to read panel Y dimension\n");
- return rc;
- } else {
- rmi4_pdata->panel_y = temp_val;
- }
- rc = of_property_read_string(np, "synaptics,fw-image-name",
- &rmi4_pdata->fw_image_name);
- if (rc && (rc != -EINVAL)) {
- dev_err(dev, "Unable to read fw image name\n");
- return rc;
- }
- /* reset, irq gpio info */
- rmi4_pdata->reset_gpio = of_get_named_gpio_flags(np,
- "synaptics,reset-gpio", 0, &rmi4_pdata->reset_flags);
- rmi4_pdata->irq_gpio = of_get_named_gpio_flags(np,
- "synaptics,irq-gpio", 0, &rmi4_pdata->irq_flags);
- prop = of_find_property(np, "synaptics,button-map", NULL);
- if (prop) {
- num_buttons = prop->length / sizeof(temp_val);
- rmi4_pdata->capacitance_button_map = devm_kzalloc(dev,
- sizeof(*rmi4_pdata->capacitance_button_map),
- GFP_KERNEL);
- if (!rmi4_pdata->capacitance_button_map)
- return -ENOMEM;
- rmi4_pdata->capacitance_button_map->map = devm_kzalloc(dev,
- sizeof(*rmi4_pdata->capacitance_button_map->map) *
- MAX_NUMBER_OF_BUTTONS, GFP_KERNEL);
- if (!rmi4_pdata->capacitance_button_map->map)
- return -ENOMEM;
- if (num_buttons <= MAX_NUMBER_OF_BUTTONS) {
- rc = of_property_read_u32_array(np,
- "synaptics,button-map", button_map,
- num_buttons);
- if (rc) {
- dev_err(dev, "Unable to read key codes\n");
- return rc;
- }
- for (i = 0; i < num_buttons; i++)
- rmi4_pdata->capacitance_button_map->map[i] =
- button_map[i];
- rmi4_pdata->capacitance_button_map->nbuttons =
- num_buttons;
- } else {
- return -EINVAL;
- }
- }
- return 0;
- }
- /**
- * synaptics_rmi4_irq_enable()
- *
- * Called by synaptics_rmi4_probe() and the power management functions
- * in this driver and also exported to other expansion Function modules
- * such as rmi_dev.
- *
- * This function handles the enabling and disabling of the attention
- * irq including the setting up of the ISR thread.
- */
- static int synaptics_rmi4_irq_enable(struct synaptics_rmi4_data *rmi4_data,
- bool enable)
- {
- int retval = 0;
- unsigned char *intr_status;
- if (enable) {
- if (rmi4_data->irq_enabled)
- return retval;
- intr_status = kzalloc(rmi4_data->num_of_intr_regs, GFP_KERNEL);
- if (!intr_status) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc memory\n",
- __func__);
- return -ENOMEM;
- }
- /* Clear interrupts first */
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_data_base_addr + 1,
- intr_status,
- rmi4_data->num_of_intr_regs);
- kfree(intr_status);
- if (retval < 0)
- return retval;
- enable_irq(rmi4_data->irq);
- rmi4_data->irq_enabled = true;
- } else {
- if (rmi4_data->irq_enabled) {
- disable_irq(rmi4_data->irq);
- rmi4_data->irq_enabled = false;
- }
- }
- return retval;
- }
- /**
- * synaptics_rmi4_f11_init()
- *
- * Called by synaptics_rmi4_query_device().
- *
- * This funtion parses information from the Function 11 registers
- * and determines the number of fingers supported, x and y data ranges,
- * offset to the associated interrupt status register, interrupt bit
- * mask, and gathers finger data acquisition capabilities from the query
- * registers.
- */
- static int synaptics_rmi4_f11_init(struct synaptics_rmi4_data *rmi4_data,
- struct synaptics_rmi4_fn *fhandler,
- struct synaptics_rmi4_fn_desc *fd,
- unsigned int intr_count)
- {
- int retval;
- unsigned char ii;
- unsigned char intr_offset;
- unsigned char abs_data_size;
- unsigned char abs_data_blk_size;
- unsigned char query[F11_STD_QUERY_LEN];
- unsigned char control[F11_STD_CTRL_LEN];
- fhandler->fn_number = fd->fn_number;
- fhandler->num_of_data_sources = fd->intr_src_count;
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- fhandler->full_addr.query_base,
- query,
- sizeof(query));
- if (retval < 0)
- return retval;
- /* Maximum number of fingers supported */
- if ((query[1] & MASK_3BIT) <= 4)
- fhandler->num_of_data_points = (query[1] & MASK_3BIT) + 1;
- else if ((query[1] & MASK_3BIT) == 5)
- fhandler->num_of_data_points = 10;
- rmi4_data->num_of_fingers = fhandler->num_of_data_points;
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- fhandler->full_addr.ctrl_base,
- control,
- sizeof(control));
- if (retval < 0)
- return retval;
- /* Maximum x and y */
- rmi4_data->sensor_max_x = ((control[6] & MASK_8BIT) << 0) |
- ((control[7] & MASK_4BIT) << 8);
- rmi4_data->sensor_max_y = ((control[8] & MASK_8BIT) << 0) |
- ((control[9] & MASK_4BIT) << 8);
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Function %02x max x = %d max y = %d\n",
- __func__, fhandler->fn_number,
- rmi4_data->sensor_max_x,
- rmi4_data->sensor_max_y);
- fhandler->intr_reg_num = (intr_count + 7) / 8;
- if (fhandler->intr_reg_num != 0)
- fhandler->intr_reg_num -= 1;
- /* Set an enable bit for each data source */
- intr_offset = intr_count % 8;
- fhandler->intr_mask = 0;
- for (ii = intr_offset;
- ii < ((fd->intr_src_count & MASK_3BIT) +
- intr_offset);
- ii++)
- fhandler->intr_mask |= 1 << ii;
- abs_data_size = query[5] & MASK_2BIT;
- abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
- fhandler->size_of_data_register_block = abs_data_blk_size;
- return retval;
- }
- static int synaptics_rmi4_f1a_alloc_mem(struct synaptics_rmi4_data *rmi4_data,
- struct synaptics_rmi4_fn *fhandler)
- {
- int retval;
- struct synaptics_rmi4_f1a_handle *f1a;
- f1a = kzalloc(sizeof(*f1a), GFP_KERNEL);
- if (!f1a) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for function handle\n",
- __func__);
- return -ENOMEM;
- }
- fhandler->data = (void *)f1a;
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- fhandler->full_addr.query_base,
- f1a->button_query.data,
- sizeof(f1a->button_query.data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read query registers\n",
- __func__);
- return retval;
- }
- f1a->button_count = f1a->button_query.max_button_count + 1;
- f1a->button_bitmask_size = (f1a->button_count + 7) / 8;
- f1a->button_data_buffer = kcalloc(f1a->button_bitmask_size,
- sizeof(*(f1a->button_data_buffer)), GFP_KERNEL);
- if (!f1a->button_data_buffer) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for data buffer\n",
- __func__);
- return -ENOMEM;
- }
- f1a->button_map = kcalloc(f1a->button_count,
- sizeof(*(f1a->button_map)), GFP_KERNEL);
- if (!f1a->button_map) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for button map\n",
- __func__);
- return -ENOMEM;
- }
- return 0;
- }
- static int synaptics_rmi4_capacitance_button_map(
- struct synaptics_rmi4_data *rmi4_data,
- struct synaptics_rmi4_fn *fhandler)
- {
- unsigned char ii;
- struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
- const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
- if (!pdata->capacitance_button_map) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: capacitance_button_map is" \
- "NULL in board file\n",
- __func__);
- return -ENODEV;
- } else if (!pdata->capacitance_button_map->map) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Button map is missing in board file\n",
- __func__);
- return -ENODEV;
- } else {
- if (pdata->capacitance_button_map->nbuttons !=
- f1a->button_count) {
- f1a->valid_button_count = min(f1a->button_count,
- pdata->capacitance_button_map->nbuttons);
- } else {
- f1a->valid_button_count = f1a->button_count;
- }
- for (ii = 0; ii < f1a->valid_button_count; ii++)
- f1a->button_map[ii] =
- pdata->capacitance_button_map->map[ii];
- }
- return 0;
- }
- static void synaptics_rmi4_f1a_kfree(struct synaptics_rmi4_fn *fhandler)
- {
- struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
- if (f1a) {
- kfree(f1a->button_data_buffer);
- kfree(f1a->button_map);
- kfree(f1a);
- fhandler->data = NULL;
- }
- return;
- }
- static int synaptics_rmi4_f1a_init(struct synaptics_rmi4_data *rmi4_data,
- struct synaptics_rmi4_fn *fhandler,
- struct synaptics_rmi4_fn_desc *fd,
- unsigned int intr_count)
- {
- int retval;
- unsigned char ii;
- unsigned short intr_offset;
- fhandler->fn_number = fd->fn_number;
- fhandler->num_of_data_sources = fd->intr_src_count;
- fhandler->intr_reg_num = (intr_count + 7) / 8;
- if (fhandler->intr_reg_num != 0)
- fhandler->intr_reg_num -= 1;
- /* Set an enable bit for each data source */
- intr_offset = intr_count % 8;
- fhandler->intr_mask = 0;
- for (ii = intr_offset;
- ii < ((fd->intr_src_count & MASK_3BIT) +
- intr_offset);
- ii++)
- fhandler->intr_mask |= 1 << ii;
- retval = synaptics_rmi4_f1a_alloc_mem(rmi4_data, fhandler);
- if (retval < 0)
- goto error_exit;
- retval = synaptics_rmi4_capacitance_button_map(rmi4_data, fhandler);
- if (retval < 0)
- goto error_exit;
- rmi4_data->button_0d_enabled = 1;
- return 0;
- error_exit:
- synaptics_rmi4_f1a_kfree(fhandler);
- return retval;
- }
- static int synaptics_rmi4_alloc_fh(struct synaptics_rmi4_fn **fhandler,
- struct synaptics_rmi4_fn_desc *rmi_fd, int page_number)
- {
- *fhandler = kzalloc(sizeof(**fhandler), GFP_KERNEL);
- if (!(*fhandler))
- return -ENOMEM;
- (*fhandler)->full_addr.data_base =
- (rmi_fd->data_base_addr |
- (page_number << 8));
- (*fhandler)->full_addr.ctrl_base =
- (rmi_fd->ctrl_base_addr |
- (page_number << 8));
- (*fhandler)->full_addr.cmd_base =
- (rmi_fd->cmd_base_addr |
- (page_number << 8));
- (*fhandler)->full_addr.query_base =
- (rmi_fd->query_base_addr |
- (page_number << 8));
- (*fhandler)->fn_number = rmi_fd->fn_number;
- return 0;
- }
- /**
- * synaptics_rmi4_query_device_info()
- *
- * Called by synaptics_rmi4_query_device().
- *
- */
- static int synaptics_rmi4_query_device_info(
- struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- unsigned char f01_query[F01_STD_QUERY_LEN];
- struct synaptics_rmi4_device_info *rmi = &(rmi4_data->rmi4_mod_info);
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_query_base_addr,
- f01_query,
- sizeof(f01_query));
- if (retval < 0)
- return retval;
- /* RMI Version 4.0 currently supported */
- rmi->version_major = 4;
- rmi->version_minor = 0;
- rmi->manufacturer_id = f01_query[0];
- rmi->product_props = f01_query[1];
- rmi->product_info[0] = f01_query[2] & MASK_7BIT;
- rmi->product_info[1] = f01_query[3] & MASK_7BIT;
- rmi->date_code[0] = f01_query[4] & MASK_5BIT;
- rmi->date_code[1] = f01_query[5] & MASK_4BIT;
- rmi->date_code[2] = f01_query[6] & MASK_5BIT;
- rmi->tester_id = ((f01_query[7] & MASK_7BIT) << 8) |
- (f01_query[8] & MASK_7BIT);
- rmi->serial_number = ((f01_query[9] & MASK_7BIT) << 8) |
- (f01_query[10] & MASK_7BIT);
- memcpy(rmi->product_id_string, &f01_query[11], 10);
- if (rmi->manufacturer_id != 1) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Non-Synaptics device found, manufacturer ID = %d\n",
- __func__, rmi->manufacturer_id);
- }
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_query_base_addr + F01_BUID_ID_OFFSET,
- rmi->build_id,
- sizeof(rmi->build_id));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read firmware build id (code %d)\n",
- __func__, retval);
- return retval;
- }
- return 0;
- }
- /**
- * synaptics_rmi4_query_device()
- *
- * Called by synaptics_rmi4_probe().
- *
- * This funtion scans the page description table, records the offsets
- * to the register types of Function $01, sets up the function handlers
- * for Function $11 and Function $12, determines the number of interrupt
- * sources from the sensor, adds valid Functions with data inputs to the
- * Function linked list, parses information from the query registers of
- * Function $01, and enables the interrupt sources from the valid Functions
- * with data inputs.
- */
- static int synaptics_rmi4_query_device(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- unsigned char ii;
- unsigned char page_number;
- unsigned char intr_count = 0;
- unsigned char data_sources = 0;
- unsigned short pdt_entry_addr;
- unsigned short intr_addr;
- struct synaptics_rmi4_f01_device_status status;
- struct synaptics_rmi4_fn_desc rmi_fd;
- struct synaptics_rmi4_fn *fhandler;
- struct synaptics_rmi4_device_info *rmi;
- rmi = &(rmi4_data->rmi4_mod_info);
- INIT_LIST_HEAD(&rmi->support_fn_list);
- /* Scan the page description tables of the pages to service */
- for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) {
- for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END;
- pdt_entry_addr -= PDT_ENTRY_SIZE) {
- pdt_entry_addr |= (page_number << 8);
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- pdt_entry_addr,
- (unsigned char *)&rmi_fd,
- sizeof(rmi_fd));
- if (retval < 0)
- return retval;
- fhandler = NULL;
- if (rmi_fd.fn_number == 0) {
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Reached end of PDT\n",
- __func__);
- break;
- }
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: F%02x found (page %d)\n",
- __func__, rmi_fd.fn_number,
- page_number);
- switch (rmi_fd.fn_number) {
- case SYNAPTICS_RMI4_F01:
- rmi4_data->f01_query_base_addr =
- rmi_fd.query_base_addr;
- rmi4_data->f01_ctrl_base_addr =
- rmi_fd.ctrl_base_addr;
- rmi4_data->f01_data_base_addr =
- rmi_fd.data_base_addr;
- rmi4_data->f01_cmd_base_addr =
- rmi_fd.cmd_base_addr;
- retval =
- synaptics_rmi4_query_device_info(rmi4_data);
- if (retval < 0)
- return retval;
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_data_base_addr,
- status.data,
- sizeof(status.data));
- if (retval < 0)
- return retval;
- while (status.status_code == STATUS_CRC_IN_PROGRESS) {
- msleep(1);
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_data_base_addr,
- status.data,
- sizeof(status.data));
- if (retval < 0)
- return retval;
- }
- if (status.flash_prog == 1) {
- pr_notice("%s: In flash prog mode, status = 0x%02x\n",
- __func__,
- status.status_code);
- goto flash_prog_mode;
- }
- break;
- case SYNAPTICS_RMI4_F11:
- if (rmi_fd.intr_src_count == 0)
- break;
- retval = synaptics_rmi4_alloc_fh(&fhandler,
- &rmi_fd, page_number);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc for F%d\n",
- __func__,
- rmi_fd.fn_number);
- return retval;
- }
- retval = synaptics_rmi4_f11_init(rmi4_data,
- fhandler, &rmi_fd, intr_count);
- if (retval < 0)
- return retval;
- break;
- case SYNAPTICS_RMI4_F1A:
- if (rmi_fd.intr_src_count == 0)
- break;
- retval = synaptics_rmi4_alloc_fh(&fhandler,
- &rmi_fd, page_number);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc for F%d\n",
- __func__,
- rmi_fd.fn_number);
- return retval;
- }
- retval = synaptics_rmi4_f1a_init(rmi4_data,
- fhandler, &rmi_fd, intr_count);
- if (retval < 0)
- return retval;
- break;
- }
- /* Accumulate the interrupt count */
- intr_count += (rmi_fd.intr_src_count & MASK_3BIT);
- if (fhandler && rmi_fd.intr_src_count) {
- list_add_tail(&fhandler->link,
- &rmi->support_fn_list);
- }
- }
- }
- flash_prog_mode:
- rmi4_data->num_of_intr_regs = (intr_count + 7) / 8;
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Number of interrupt registers = %d\n",
- __func__, rmi4_data->num_of_intr_regs);
- memset(rmi4_data->intr_mask, 0x00, sizeof(rmi4_data->intr_mask));
- /*
- * Map out the interrupt bit masks for the interrupt sources
- * from the registered function handlers.
- */
- if (!list_empty(&rmi->support_fn_list)) {
- list_for_each_entry(fhandler, &rmi->support_fn_list, link)
- data_sources += fhandler->num_of_data_sources;
- }
- if (data_sources) {
- if (!list_empty(&rmi->support_fn_list)) {
- list_for_each_entry(fhandler,
- &rmi->support_fn_list, link) {
- if (fhandler->num_of_data_sources) {
- rmi4_data->intr_mask[fhandler->intr_reg_num] |=
- fhandler->intr_mask;
- }
- }
- }
- }
- /* Enable the interrupt sources */
- for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) {
- if (rmi4_data->intr_mask[ii] != 0x00) {
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Interrupt enable mask %d = 0x%02x\n",
- __func__, ii, rmi4_data->intr_mask[ii]);
- intr_addr = rmi4_data->f01_ctrl_base_addr + 1 + ii;
- retval = synaptics_rmi4_i2c_write(rmi4_data,
- intr_addr,
- &(rmi4_data->intr_mask[ii]),
- sizeof(rmi4_data->intr_mask[ii]));
- if (retval < 0)
- return retval;
- }
- }
- return 0;
- }
- static int synaptics_rmi4_reset_command(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- int page_number;
- unsigned char command = 0x01;
- unsigned short pdt_entry_addr;
- struct synaptics_rmi4_fn_desc rmi_fd;
- bool done = false;
- /* Scan the page description tables of the pages to service */
- for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) {
- for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END;
- pdt_entry_addr -= PDT_ENTRY_SIZE) {
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- pdt_entry_addr,
- (unsigned char *)&rmi_fd,
- sizeof(rmi_fd));
- if (retval < 0)
- return retval;
- if (rmi_fd.fn_number == 0)
- break;
- switch (rmi_fd.fn_number) {
- case SYNAPTICS_RMI4_F01:
- rmi4_data->f01_cmd_base_addr =
- rmi_fd.cmd_base_addr;
- done = true;
- break;
- }
- }
- if (done) {
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: Find F01 in page description table 0x%x\n",
- __func__, rmi4_data->f01_cmd_base_addr);
- break;
- }
- }
- if (!done) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Cannot find F01 in page description table\n",
- __func__);
- return -EINVAL;
- }
- retval = synaptics_rmi4_i2c_write(rmi4_data,
- rmi4_data->f01_cmd_base_addr,
- &command,
- sizeof(command));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to issue reset command, error = %d\n",
- __func__, retval);
- return retval;
- }
- msleep(RESET_DELAY);
- return retval;
- };
- static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- struct synaptics_rmi4_fn *fhandler;
- struct synaptics_rmi4_device_info *rmi;
- rmi = &(rmi4_data->rmi4_mod_info);
- retval = synaptics_rmi4_reset_command(rmi4_data);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to send command reset\n",
- __func__);
- return retval;
- }
- if (!list_empty(&rmi->support_fn_list)) {
- list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
- if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
- synaptics_rmi4_f1a_kfree(fhandler);
- else
- kfree(fhandler->data);
- kfree(fhandler);
- }
- }
- retval = synaptics_rmi4_query_device(rmi4_data);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to query device\n",
- __func__);
- return retval;
- }
- return 0;
- }
- /**
- * synaptics_rmi4_detection_work()
- *
- * Called by the kernel at the scheduled time.
- *
- * This function is a self-rearming work thread that checks for the
- * insertion and removal of other expansion Function modules such as
- * rmi_dev and calls their initialization and removal callback functions
- * accordingly.
- */
- static void synaptics_rmi4_detection_work(struct work_struct *work)
- {
- struct synaptics_rmi4_exp_fn *exp_fhandler, *next_list_entry;
- struct synaptics_rmi4_data *rmi4_data =
- container_of(work, struct synaptics_rmi4_data,
- det_work.work);
- mutex_lock(&exp_fn_list_mutex);
- if (!list_empty(&exp_fn_list)) {
- list_for_each_entry_safe(exp_fhandler,
- next_list_entry,
- &exp_fn_list,
- link) {
- if ((exp_fhandler->func_init != NULL) &&
- (exp_fhandler->inserted == false)) {
- exp_fhandler->func_init(rmi4_data);
- exp_fhandler->inserted = true;
- } else if ((exp_fhandler->func_init == NULL) &&
- (exp_fhandler->inserted == true)) {
- exp_fhandler->func_remove(rmi4_data);
- list_del(&exp_fhandler->link);
- kfree(exp_fhandler);
- }
- }
- }
- mutex_unlock(&exp_fn_list_mutex);
- return;
- }
- /**
- * synaptics_rmi4_new_function()
- *
- * Called by other expansion Function modules in their module init and
- * module exit functions.
- *
- * This function is used by other expansion Function modules such as
- * rmi_dev to register themselves with the driver by providing their
- * initialization and removal callback function pointers so that they
- * can be inserted or removed dynamically at module init and exit times,
- * respectively.
- */
- void synaptics_rmi4_new_function(enum exp_fn fn_type, bool insert,
- int (*func_init)(struct synaptics_rmi4_data *rmi4_data),
- void (*func_remove)(struct synaptics_rmi4_data *rmi4_data),
- void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
- unsigned char intr_mask))
- {
- struct synaptics_rmi4_exp_fn *exp_fhandler;
- if (!exp_fn_inited) {
- mutex_init(&exp_fn_list_mutex);
- INIT_LIST_HEAD(&exp_fn_list);
- exp_fn_inited = 1;
- }
- mutex_lock(&exp_fn_list_mutex);
- if (insert) {
- exp_fhandler = kzalloc(sizeof(*exp_fhandler), GFP_KERNEL);
- if (!exp_fhandler) {
- pr_err("%s: Failed to alloc mem for expansion function\n",
- __func__);
- goto exit;
- }
- exp_fhandler->fn_type = fn_type;
- exp_fhandler->func_init = func_init;
- exp_fhandler->func_attn = func_attn;
- exp_fhandler->func_remove = func_remove;
- exp_fhandler->inserted = false;
- list_add_tail(&exp_fhandler->link, &exp_fn_list);
- } else {
- if (!list_empty(&exp_fn_list)) {
- list_for_each_entry(exp_fhandler, &exp_fn_list, link) {
- if (exp_fhandler->func_init == func_init) {
- exp_fhandler->inserted = false;
- exp_fhandler->func_init = NULL;
- exp_fhandler->func_attn = NULL;
- goto exit;
- }
- }
- }
- }
- exit:
- mutex_unlock(&exp_fn_list_mutex);
- return;
- }
- EXPORT_SYMBOL(synaptics_rmi4_new_function);
- static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA)
- {
- return (regulator_count_voltages(reg) > 0) ?
- regulator_set_optimum_mode(reg, load_uA) : 0;
- }
- static int synaptics_rmi4_regulator_configure(struct synaptics_rmi4_data
- *rmi4_data, bool on)
- {
- int retval;
- if (on == false)
- goto hw_shutdown;
- if (rmi4_data->board->regulator_en) {
- rmi4_data->vdd = regulator_get(&rmi4_data->i2c_client->dev,
- "vdd");
- if (IS_ERR(rmi4_data->vdd)) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to get vdd regulator\n",
- __func__);
- return PTR_ERR(rmi4_data->vdd);
- }
- if (regulator_count_voltages(rmi4_data->vdd) > 0) {
- retval = regulator_set_voltage(rmi4_data->vdd,
- RMI4_VTG_MIN_UV, RMI4_VTG_MAX_UV);
- if (retval) {
- dev_err(&rmi4_data->i2c_client->dev,
- "regulator set_vtg failed retval =%d\n",
- retval);
- goto err_set_vtg_vdd;
- }
- }
- }
- if (rmi4_data->board->i2c_pull_up) {
- rmi4_data->vcc_i2c = regulator_get(&rmi4_data->i2c_client->dev,
- "vcc_i2c");
- if (IS_ERR(rmi4_data->vcc_i2c)) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to get i2c regulator\n",
- __func__);
- retval = PTR_ERR(rmi4_data->vcc_i2c);
- goto err_get_vtg_i2c;
- }
- if (regulator_count_voltages(rmi4_data->vcc_i2c) > 0) {
- retval = regulator_set_voltage(rmi4_data->vcc_i2c,
- RMI4_I2C_VTG_MIN_UV, RMI4_I2C_VTG_MAX_UV);
- if (retval) {
- dev_err(&rmi4_data->i2c_client->dev,
- "reg set i2c vtg failed retval =%d\n",
- retval);
- goto err_set_vtg_i2c;
- }
- }
- }
- return 0;
- err_set_vtg_i2c:
- if (rmi4_data->board->i2c_pull_up)
- regulator_put(rmi4_data->vcc_i2c);
- err_get_vtg_i2c:
- if (rmi4_data->board->regulator_en)
- if (regulator_count_voltages(rmi4_data->vdd) > 0)
- regulator_set_voltage(rmi4_data->vdd, 0,
- RMI4_VTG_MAX_UV);
- err_set_vtg_vdd:
- if (rmi4_data->board->regulator_en)
- regulator_put(rmi4_data->vdd);
- return retval;
- hw_shutdown:
- if (rmi4_data->board->regulator_en) {
- if (regulator_count_voltages(rmi4_data->vdd) > 0)
- regulator_set_voltage(rmi4_data->vdd, 0,
- RMI4_VTG_MAX_UV);
- regulator_put(rmi4_data->vdd);
- }
- if (rmi4_data->board->i2c_pull_up) {
- if (regulator_count_voltages(rmi4_data->vcc_i2c) > 0)
- regulator_set_voltage(rmi4_data->vcc_i2c, 0,
- RMI4_I2C_VTG_MAX_UV);
- regulator_put(rmi4_data->vcc_i2c);
- }
- return 0;
- };
- static int synaptics_rmi4_power_on(struct synaptics_rmi4_data *rmi4_data,
- bool on) {
- int retval;
- if (on == false)
- goto power_off;
- if (rmi4_data->board->regulator_en) {
- retval = reg_set_optimum_mode_check(rmi4_data->vdd,
- RMI4_ACTIVE_LOAD_UA);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "Regulator vdd set_opt failed rc=%d\n",
- retval);
- return retval;
- }
- retval = regulator_enable(rmi4_data->vdd);
- if (retval) {
- dev_err(&rmi4_data->i2c_client->dev,
- "Regulator vdd enable failed rc=%d\n",
- retval);
- goto error_reg_en_vdd;
- }
- }
- if (rmi4_data->board->i2c_pull_up) {
- retval = reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
- RMI4_I2C_LOAD_UA);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "Regulator vcc_i2c set_opt failed rc=%d\n",
- retval);
- goto error_reg_opt_i2c;
- }
- retval = regulator_enable(rmi4_data->vcc_i2c);
- if (retval) {
- dev_err(&rmi4_data->i2c_client->dev,
- "Regulator vcc_i2c enable failed rc=%d\n",
- retval);
- goto error_reg_en_vcc_i2c;
- }
- }
- return 0;
- error_reg_en_vcc_i2c:
- if (rmi4_data->board->i2c_pull_up)
- reg_set_optimum_mode_check(rmi4_data->vdd, 0);
- error_reg_opt_i2c:
- if (rmi4_data->board->regulator_en)
- regulator_disable(rmi4_data->vdd);
- error_reg_en_vdd:
- if (rmi4_data->board->regulator_en)
- reg_set_optimum_mode_check(rmi4_data->vdd, 0);
- return retval;
- power_off:
- if (rmi4_data->board->regulator_en) {
- reg_set_optimum_mode_check(rmi4_data->vdd, 0);
- regulator_disable(rmi4_data->vdd);
- }
- if (rmi4_data->board->i2c_pull_up) {
- reg_set_optimum_mode_check(rmi4_data->vcc_i2c, 0);
- regulator_disable(rmi4_data->vcc_i2c);
- }
- return 0;
- }
- /**
- * synaptics_rmi4_probe()
- *
- * Called by the kernel when an association with an I2C device of the
- * same name is made (after doing i2c_add_driver).
- *
- * This funtion allocates and initializes the resources for the driver
- * as an input driver, turns on the power to the sensor, queries the
- * sensor for its supported Functions and characteristics, registers
- * the driver to the input subsystem, sets up the interrupt, handles
- * the registration of the early_suspend and late_resume functions,
- * and creates a work queue for detection of other expansion Function
- * modules.
- */
- static int __devinit synaptics_rmi4_probe(struct i2c_client *client,
- const struct i2c_device_id *dev_id)
- {
- int retval = 0;
- unsigned char ii;
- unsigned char attr_count;
- struct synaptics_rmi4_f1a_handle *f1a;
- struct synaptics_rmi4_fn *fhandler;
- struct synaptics_rmi4_data *rmi4_data;
- struct synaptics_rmi4_device_info *rmi;
- struct synaptics_rmi4_platform_data *platform_data =
- client->dev.platform_data;
- if (!i2c_check_functionality(client->adapter,
- I2C_FUNC_SMBUS_BYTE_DATA)) {
- dev_err(&client->dev,
- "%s: SMBus byte data not supported\n",
- __func__);
- return -EIO;
- }
- if (client->dev.of_node) {
- platform_data = devm_kzalloc(&client->dev,
- sizeof(*platform_data),
- GFP_KERNEL);
- if (!platform_data) {
- dev_err(&client->dev, "Failed to allocate memory\n");
- return -ENOMEM;
- }
- retval = synaptics_rmi4_parse_dt(&client->dev, platform_data);
- if (retval)
- return retval;
- } else {
- platform_data = client->dev.platform_data;
- }
- if (!platform_data) {
- dev_err(&client->dev,
- "%s: No platform data found\n",
- __func__);
- return -EINVAL;
- }
- rmi4_data = kzalloc(sizeof(*rmi4_data) * 2, GFP_KERNEL);
- if (!rmi4_data) {
- dev_err(&client->dev,
- "%s: Failed to alloc mem for rmi4_data\n",
- __func__);
- return -ENOMEM;
- }
- rmi = &(rmi4_data->rmi4_mod_info);
- rmi4_data->input_dev = input_allocate_device();
- if (rmi4_data->input_dev == NULL) {
- dev_err(&client->dev,
- "%s: Failed to allocate input device\n",
- __func__);
- retval = -ENOMEM;
- goto err_input_device;
- }
- rmi4_data->i2c_client = client;
- rmi4_data->current_page = MASK_8BIT;
- rmi4_data->board = platform_data;
- rmi4_data->touch_stopped = false;
- rmi4_data->sensor_sleep = false;
- rmi4_data->irq_enabled = false;
- rmi4_data->i2c_read = synaptics_rmi4_i2c_read;
- rmi4_data->i2c_write = synaptics_rmi4_i2c_write;
- rmi4_data->irq_enable = synaptics_rmi4_irq_enable;
- rmi4_data->reset_device = synaptics_rmi4_reset_device;
- rmi4_data->flip_x = rmi4_data->board->x_flip;
- rmi4_data->flip_y = rmi4_data->board->y_flip;
- rmi4_data->fw_image_name = rmi4_data->board->fw_image_name;
- rmi4_data->input_dev->name = DRIVER_NAME;
- rmi4_data->input_dev->phys = INPUT_PHYS_NAME;
- rmi4_data->input_dev->id.bustype = BUS_I2C;
- rmi4_data->input_dev->id.product = SYNAPTICS_DSX_DRIVER_PRODUCT;
- rmi4_data->input_dev->id.version = SYNAPTICS_DSX_DRIVER_VERSION;
- rmi4_data->input_dev->dev.parent = &client->dev;
- input_set_drvdata(rmi4_data->input_dev, rmi4_data);
- set_bit(EV_SYN, rmi4_data->input_dev->evbit);
- set_bit(EV_KEY, rmi4_data->input_dev->evbit);
- set_bit(EV_ABS, rmi4_data->input_dev->evbit);
- set_bit(BTN_TOUCH, rmi4_data->input_dev->keybit);
- set_bit(BTN_TOOL_FINGER, rmi4_data->input_dev->keybit);
- #ifdef INPUT_PROP_DIRECT
- set_bit(INPUT_PROP_DIRECT, rmi4_data->input_dev->propbit);
- #endif
- retval = synaptics_rmi4_regulator_configure(rmi4_data, true);
- if (retval < 0) {
- dev_err(&client->dev, "Failed to configure regulators\n");
- goto err_reg_configure;
- }
- retval = synaptics_rmi4_power_on(rmi4_data, true);
- if (retval < 0) {
- dev_err(&client->dev, "Failed to power on\n");
- goto err_power_device;
- }
- if (gpio_is_valid(platform_data->irq_gpio)) {
- /* configure touchscreen irq gpio */
- retval = gpio_request(platform_data->irq_gpio, "rmi4_irq_gpio");
- if (retval) {
- dev_err(&client->dev, "unable to request gpio [%d]\n",
- platform_data->irq_gpio);
- goto err_irq_gpio_req;
- }
- retval = gpio_direction_input(platform_data->irq_gpio);
- if (retval) {
- dev_err(&client->dev,
- "unable to set direction for gpio [%d]\n",
- platform_data->irq_gpio);
- goto err_irq_gpio_dir;
- }
- } else {
- dev_err(&client->dev, "irq gpio not provided\n");
- goto err_irq_gpio_req;
- }
- if (gpio_is_valid(platform_data->reset_gpio)) {
- /* configure touchscreen reset out gpio */
- retval = gpio_request(platform_data->reset_gpio,
- "rmi4_reset_gpio");
- if (retval) {
- dev_err(&client->dev, "unable to request gpio [%d]\n",
- platform_data->reset_gpio);
- goto err_irq_gpio_dir;
- }
- retval = gpio_direction_output(platform_data->reset_gpio, 1);
- if (retval) {
- dev_err(&client->dev,
- "unable to set direction for gpio [%d]\n",
- platform_data->reset_gpio);
- goto err_reset_gpio_dir;
- }
- gpio_set_value(platform_data->reset_gpio, 0);
- usleep(RMI4_GPIO_SLEEP_LOW_US);
- gpio_set_value(platform_data->reset_gpio, 1);
- msleep(RESET_DELAY);
- } else
- synaptics_rmi4_reset_command(rmi4_data);
- init_waitqueue_head(&rmi4_data->wait);
- mutex_init(&(rmi4_data->rmi4_io_ctrl_mutex));
- retval = synaptics_rmi4_query_device(rmi4_data);
- if (retval < 0) {
- dev_err(&client->dev,
- "%s: Failed to query device\n",
- __func__);
- goto err_reset_gpio_dir;
- }
- input_set_abs_params(rmi4_data->input_dev,
- ABS_MT_POSITION_X, 0,
- rmi4_data->sensor_max_x, 0, 0);
- input_set_abs_params(rmi4_data->input_dev,
- ABS_MT_POSITION_Y, 0,
- rmi4_data->sensor_max_y, 0, 0);
- input_set_abs_params(rmi4_data->input_dev,
- ABS_PRESSURE, 0, 255, 0, 0);
- #ifdef REPORT_2D_W
- input_set_abs_params(rmi4_data->input_dev,
- ABS_MT_TOUCH_MAJOR, 0,
- MAX_ABS_MT_TOUCH_MAJOR, 0, 0);
- #endif
- #ifdef TYPE_B_PROTOCOL
- input_mt_init_slots(rmi4_data->input_dev,
- rmi4_data->num_of_fingers);
- #endif
- i2c_set_clientdata(client, rmi4_data);
- f1a = NULL;
- if (!list_empty(&rmi->support_fn_list)) {
- list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
- if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
- f1a = fhandler->data;
- }
- }
- if (f1a) {
- for (ii = 0; ii < f1a->valid_button_count; ii++) {
- set_bit(f1a->button_map[ii],
- rmi4_data->input_dev->keybit);
- input_set_capability(rmi4_data->input_dev,
- EV_KEY, f1a->button_map[ii]);
- }
- }
- retval = input_register_device(rmi4_data->input_dev);
- if (retval) {
- dev_err(&client->dev,
- "%s: Failed to register input device\n",
- __func__);
- goto err_register_input;
- }
- #ifdef CONFIG_HAS_EARLYSUSPEND
- rmi4_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
- rmi4_data->early_suspend.suspend = synaptics_rmi4_early_suspend;
- rmi4_data->early_suspend.resume = synaptics_rmi4_late_resume;
- register_early_suspend(&rmi4_data->early_suspend);
- #endif
- if (!exp_fn_inited) {
- mutex_init(&exp_fn_list_mutex);
- INIT_LIST_HEAD(&exp_fn_list);
- exp_fn_inited = 1;
- }
- rmi4_data->det_workqueue =
- create_singlethread_workqueue("rmi_det_workqueue");
- INIT_DELAYED_WORK(&rmi4_data->det_work,
- synaptics_rmi4_detection_work);
- queue_delayed_work(rmi4_data->det_workqueue,
- &rmi4_data->det_work,
- msecs_to_jiffies(EXP_FN_DET_INTERVAL));
- rmi4_data->irq = gpio_to_irq(platform_data->irq_gpio);
- retval = request_threaded_irq(rmi4_data->irq, NULL,
- synaptics_rmi4_irq, platform_data->irq_flags,
- DRIVER_NAME, rmi4_data);
- rmi4_data->irq_enabled = true;
- if (retval < 0) {
- dev_err(&client->dev,
- "%s: Failed to create irq thread\n",
- __func__);
- goto err_enable_irq;
- }
- for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
- retval = sysfs_create_file(&rmi4_data->input_dev->dev.kobj,
- &attrs[attr_count].attr);
- if (retval < 0) {
- dev_err(&client->dev,
- "%s: Failed to create sysfs attributes\n",
- __func__);
- goto err_sysfs;
- }
- }
- retval = synaptics_rmi4_irq_enable(rmi4_data, true);
- if (retval < 0) {
- dev_err(&client->dev,
- "%s: Failed to enable attention interrupt\n",
- __func__);
- goto err_sysfs;
- }
- return retval;
- err_sysfs:
- for (attr_count--; attr_count >= 0; attr_count--) {
- sysfs_remove_file(&rmi4_data->input_dev->dev.kobj,
- &attrs[attr_count].attr);
- }
- err_enable_irq:
- cancel_delayed_work_sync(&rmi4_data->det_work);
- flush_workqueue(rmi4_data->det_workqueue);
- destroy_workqueue(rmi4_data->det_workqueue);
- input_unregister_device(rmi4_data->input_dev);
- err_register_input:
- if (!list_empty(&rmi->support_fn_list)) {
- list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
- if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
- synaptics_rmi4_f1a_kfree(fhandler);
- else
- kfree(fhandler->data);
- kfree(fhandler);
- }
- }
- err_reset_gpio_dir:
- if (gpio_is_valid(platform_data->reset_gpio))
- gpio_free(platform_data->reset_gpio);
- err_irq_gpio_dir:
- if (gpio_is_valid(platform_data->irq_gpio))
- gpio_free(platform_data->irq_gpio);
- err_irq_gpio_req:
- synaptics_rmi4_power_on(rmi4_data, false);
- err_power_device:
- synaptics_rmi4_regulator_configure(rmi4_data, false);
- err_reg_configure:
- input_free_device(rmi4_data->input_dev);
- rmi4_data->input_dev = NULL;
- err_input_device:
- kfree(rmi4_data);
- return retval;
- }
- /**
- * synaptics_rmi4_remove()
- *
- * Called by the kernel when the association with an I2C device of the
- * same name is broken (when the driver is unloaded).
- *
- * This funtion terminates the work queue, stops sensor data acquisition,
- * frees the interrupt, unregisters the driver from the input subsystem,
- * turns off the power to the sensor, and frees other allocated resources.
- */
- static int __devexit synaptics_rmi4_remove(struct i2c_client *client)
- {
- unsigned char attr_count;
- struct synaptics_rmi4_fn *fhandler;
- struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
- struct synaptics_rmi4_device_info *rmi;
- rmi = &(rmi4_data->rmi4_mod_info);
- cancel_delayed_work_sync(&rmi4_data->det_work);
- flush_workqueue(rmi4_data->det_workqueue);
- destroy_workqueue(rmi4_data->det_workqueue);
- rmi4_data->touch_stopped = true;
- wake_up(&rmi4_data->wait);
- free_irq(rmi4_data->irq, rmi4_data);
- for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
- sysfs_remove_file(&rmi4_data->input_dev->dev.kobj,
- &attrs[attr_count].attr);
- }
- input_unregister_device(rmi4_data->input_dev);
- if (!list_empty(&rmi->support_fn_list)) {
- list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
- if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
- synaptics_rmi4_f1a_kfree(fhandler);
- else
- kfree(fhandler->data);
- kfree(fhandler);
- }
- }
- if (gpio_is_valid(rmi4_data->board->reset_gpio))
- gpio_free(rmi4_data->board->reset_gpio);
- if (gpio_is_valid(rmi4_data->board->irq_gpio))
- gpio_free(rmi4_data->board->irq_gpio);
- synaptics_rmi4_power_on(rmi4_data, false);
- synaptics_rmi4_regulator_configure(rmi4_data, false);
- kfree(rmi4_data);
- return 0;
- }
- #ifdef CONFIG_PM
- /**
- * synaptics_rmi4_sensor_sleep()
- *
- * Called by synaptics_rmi4_early_suspend() and synaptics_rmi4_suspend().
- *
- * This function stops finger data acquisition and puts the sensor to sleep.
- */
- static void synaptics_rmi4_sensor_sleep(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- unsigned char device_ctrl;
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_ctrl_base_addr,
- &device_ctrl,
- sizeof(device_ctrl));
- if (retval < 0) {
- dev_err(&(rmi4_data->input_dev->dev),
- "%s: Failed to enter sleep mode\n",
- __func__);
- rmi4_data->sensor_sleep = false;
- return;
- }
- device_ctrl = (device_ctrl & ~MASK_3BIT);
- device_ctrl = (device_ctrl | NO_SLEEP_OFF | SENSOR_SLEEP);
- retval = synaptics_rmi4_i2c_write(rmi4_data,
- rmi4_data->f01_ctrl_base_addr,
- &device_ctrl,
- sizeof(device_ctrl));
- if (retval < 0) {
- dev_err(&(rmi4_data->input_dev->dev),
- "%s: Failed to enter sleep mode\n",
- __func__);
- rmi4_data->sensor_sleep = false;
- return;
- } else {
- rmi4_data->sensor_sleep = true;
- }
- return;
- }
- /**
- * synaptics_rmi4_sensor_wake()
- *
- * Called by synaptics_rmi4_resume() and synaptics_rmi4_late_resume().
- *
- * This function wakes the sensor from sleep.
- */
- static void synaptics_rmi4_sensor_wake(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- unsigned char device_ctrl;
- retval = synaptics_rmi4_i2c_read(rmi4_data,
- rmi4_data->f01_ctrl_base_addr,
- &device_ctrl,
- sizeof(device_ctrl));
- if (retval < 0) {
- dev_err(&(rmi4_data->input_dev->dev),
- "%s: Failed to wake from sleep mode\n",
- __func__);
- rmi4_data->sensor_sleep = true;
- return;
- }
- device_ctrl = (device_ctrl & ~MASK_3BIT);
- device_ctrl = (device_ctrl | NO_SLEEP_OFF | NORMAL_OPERATION);
- retval = synaptics_rmi4_i2c_write(rmi4_data,
- rmi4_data->f01_ctrl_base_addr,
- &device_ctrl,
- sizeof(device_ctrl));
- if (retval < 0) {
- dev_err(&(rmi4_data->input_dev->dev),
- "%s: Failed to wake from sleep mode\n",
- __func__);
- rmi4_data->sensor_sleep = true;
- return;
- } else {
- rmi4_data->sensor_sleep = false;
- }
- return;
- }
- #ifdef CONFIG_HAS_EARLYSUSPEND
- /**
- * synaptics_rmi4_early_suspend()
- *
- * Called by the kernel during the early suspend phase when the system
- * enters suspend.
- *
- * This function calls synaptics_rmi4_sensor_sleep() to stop finger
- * data acquisition and put the sensor to sleep.
- */
- static void synaptics_rmi4_early_suspend(struct early_suspend *h)
- {
- struct synaptics_rmi4_data *rmi4_data =
- container_of(h, struct synaptics_rmi4_data,
- early_suspend);
- rmi4_data->touch_stopped = true;
- wake_up(&rmi4_data->wait);
- synaptics_rmi4_irq_enable(rmi4_data, false);
- synaptics_rmi4_sensor_sleep(rmi4_data);
- if (rmi4_data->full_pm_cycle)
- synaptics_rmi4_suspend(&(rmi4_data->input_dev->dev));
- return;
- }
- /**
- * synaptics_rmi4_late_resume()
- *
- * Called by the kernel during the late resume phase when the system
- * wakes up from suspend.
- *
- * This function goes through the sensor wake process if the system wakes
- * up from early suspend (without going into suspend).
- */
- static void synaptics_rmi4_late_resume(struct early_suspend *h)
- {
- struct synaptics_rmi4_data *rmi4_data =
- container_of(h, struct synaptics_rmi4_data,
- early_suspend);
- if (rmi4_data->full_pm_cycle)
- synaptics_rmi4_resume(&(rmi4_data->input_dev->dev));
- if (rmi4_data->sensor_sleep == true) {
- synaptics_rmi4_sensor_wake(rmi4_data);
- rmi4_data->touch_stopped = false;
- synaptics_rmi4_irq_enable(rmi4_data, true);
- }
- return;
- }
- #endif
- static int synaptics_rmi4_regulator_lpm(struct synaptics_rmi4_data *rmi4_data,
- bool on)
- {
- int retval;
- if (on == false)
- goto regulator_hpm;
- retval = reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_LPM_LOAD_UA);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "Regulator vcc_ana set_opt failed rc=%d\n",
- retval);
- goto fail_regulator_lpm;
- }
- if (rmi4_data->board->i2c_pull_up) {
- retval = reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
- RMI4_I2C_LOAD_UA);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "Regulator vcc_i2c set_opt failed rc=%d\n",
- retval);
- goto fail_regulator_lpm;
- }
- }
- return 0;
- regulator_hpm:
- retval = reg_set_optimum_mode_check(rmi4_data->vdd,
- RMI4_ACTIVE_LOAD_UA);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "Regulator vcc_ana set_opt failed rc=%d\n",
- retval);
- goto fail_regulator_hpm;
- }
- if (rmi4_data->board->i2c_pull_up) {
- retval = reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
- RMI4_I2C_LOAD_UA);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "Regulator vcc_i2c set_opt failed rc=%d\n",
- retval);
- goto fail_regulator_hpm;
- }
- }
- return 0;
- fail_regulator_lpm:
- reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_ACTIVE_LOAD_UA);
- if (rmi4_data->board->i2c_pull_up)
- reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
- RMI4_I2C_LOAD_UA);
- return retval;
- fail_regulator_hpm:
- reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_LPM_LOAD_UA);
- if (rmi4_data->board->i2c_pull_up)
- reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
- RMI4_I2C_LPM_LOAD_UA);
- return retval;
- }
- /**
- * synaptics_rmi4_suspend()
- *
- * Called by the kernel during the suspend phase when the system
- * enters suspend.
- *
- * This function stops finger data acquisition and puts the sensor to
- * sleep (if not already done so during the early suspend phase),
- * disables the interrupt, and turns off the power to the sensor.
- */
- static int synaptics_rmi4_suspend(struct device *dev)
- {
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- int retval;
- if (!rmi4_data->sensor_sleep) {
- rmi4_data->touch_stopped = true;
- wake_up(&rmi4_data->wait);
- synaptics_rmi4_irq_enable(rmi4_data, false);
- synaptics_rmi4_sensor_sleep(rmi4_data);
- }
- retval = synaptics_rmi4_regulator_lpm(rmi4_data, true);
- if (retval < 0) {
- dev_err(dev, "failed to enter low power mode\n");
- return retval;
- }
- return 0;
- }
- /**
- * synaptics_rmi4_resume()
- *
- * Called by the kernel during the resume phase when the system
- * wakes up from suspend.
- *
- * This function turns on the power to the sensor, wakes the sensor
- * from sleep, enables the interrupt, and starts finger data
- * acquisition.
- */
- static int synaptics_rmi4_resume(struct device *dev)
- {
- struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
- int retval;
- retval = synaptics_rmi4_regulator_lpm(rmi4_data, false);
- if (retval < 0) {
- dev_err(dev, "failed to enter active power mode\n");
- return retval;
- }
- synaptics_rmi4_sensor_wake(rmi4_data);
- rmi4_data->touch_stopped = false;
- synaptics_rmi4_irq_enable(rmi4_data, true);
- return 0;
- }
- static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = {
- .suspend = synaptics_rmi4_suspend,
- .resume = synaptics_rmi4_resume,
- };
- #endif
- static const struct i2c_device_id synaptics_rmi4_id_table[] = {
- {DRIVER_NAME, 0},
- {},
- };
- MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table);
- #ifdef CONFIG_OF
- static struct of_device_id rmi4_match_table[] = {
- { .compatible = "synaptics,rmi4",},
- { },
- };
- #else
- #define rmi4_match_table NULL
- #endif
- static struct i2c_driver synaptics_rmi4_driver = {
- .driver = {
- .name = DRIVER_NAME,
- .owner = THIS_MODULE,
- .of_match_table = rmi4_match_table,
- #ifdef CONFIG_PM
- .pm = &synaptics_rmi4_dev_pm_ops,
- #endif
- },
- .probe = synaptics_rmi4_probe,
- .remove = __devexit_p(synaptics_rmi4_remove),
- .id_table = synaptics_rmi4_id_table,
- };
- /**
- * synaptics_rmi4_init()
- *
- * Called by the kernel during do_initcalls (if built-in)
- * or when the driver is loaded (if a module).
- *
- * This function registers the driver to the I2C subsystem.
- *
- */
- static int __init synaptics_rmi4_init(void)
- {
- return i2c_add_driver(&synaptics_rmi4_driver);
- }
- /**
- * synaptics_rmi4_exit()
- *
- * Called by the kernel when the driver is unloaded.
- *
- * This funtion unregisters the driver from the I2C subsystem.
- *
- */
- static void __exit synaptics_rmi4_exit(void)
- {
- i2c_del_driver(&synaptics_rmi4_driver);
- }
- module_init(synaptics_rmi4_init);
- module_exit(synaptics_rmi4_exit);
- MODULE_AUTHOR("Synaptics, Inc.");
- MODULE_DESCRIPTION("Synaptics RMI4 I2C Touch Driver");
- MODULE_LICENSE("GPL v2");
|