bma255.c 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778
  1. /* BMA255 motion sensor driver
  2. *
  3. *
  4. * This software program is licensed subject to the GNU General Public License
  5. * (GPL).Version 2,June 1991, available at http://www.fsf.org/copyleft/gpl.html
  6. * (C) Copyright 2011 Bosch Sensortec GmbH
  7. * All Rights Reserved
  8. *
  9. * VERSION: V1.5
  10. * HISTORY: V1.0 --- Driver creation
  11. * V1.1 --- Add share I2C address function
  12. * V1.2 --- Fix the bug that sometimes sensor is stuck after system resume.
  13. * V1.3 --- Add FIFO interfaces.
  14. * V1.4 --- Use basic i2c function to read fifo data instead of i2c DMA mode.
  15. * V1.5 --- Add compensated value performed by MTK acceleration calibration process.
  16. */
  17. #include <linux/interrupt.h>
  18. #include <linux/i2c.h>
  19. #include <linux/slab.h>
  20. #include <linux/irq.h>
  21. #include <linux/miscdevice.h>
  22. #include <asm/uaccess.h>
  23. #include <linux/delay.h>
  24. #include <linux/input.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/kobject.h>
  27. #ifdef CONFIG_HAS_EARLYSUSPEND
  28. #include <linux/earlysuspend.h>
  29. #endif
  30. #include <linux/platform_device.h>
  31. #include <asm/atomic.h>
  32. #include <linux/module.h>
  33. #include <accel.h>
  34. #include <hwmsensor.h>
  35. #include <cust_acc.h>
  36. #include "bma255.h"
  37. /*----------------------------------------------------------------------------*/
  38. #define I2C_DRIVERID_BMA255 255
  39. /*----------------------------------------------------------------------------*/
  40. #define DEBUG 1
  41. /*----------------------------------------------------------------------------*/
  42. //#define CONFIG_BMA255_LOWPASS /*apply low pass filter on output*/
  43. #define SW_CALIBRATION
  44. #define CONFIG_I2C_BASIC_FUNCTION
  45. //tad3sgh add ++
  46. #define BMM050_DEFAULT_DELAY 100
  47. #define CALIBRATION_DATA_SIZE 12
  48. /*----------------------------------------------------------------------------*/
  49. /*
  50. * Enable the driver to block e-compass daemon on suspend
  51. */
  52. #define BMC050_BLOCK_DAEMON_ON_SUSPEND
  53. #undef BMC050_BLOCK_DAEMON_ON_SUSPEND
  54. /*
  55. * Enable gyroscope feature with BMC050
  56. */
  57. #define BMC050_M4G
  58. //#undef BMC050_M4G
  59. /*
  60. * Enable rotation vecter feature with BMC050
  61. */
  62. #define BMC050_VRV
  63. //#undef BMC050_VRV
  64. /*
  65. * Enable virtual linear accelerometer feature with BMC050
  66. */
  67. #define BMC050_VLA
  68. //#undef BMC050_VLA
  69. /*
  70. * Enable virtual gravity feature with BMC050
  71. */
  72. #define BMC050_VG
  73. //#undef BMC050_VG
  74. #ifdef BMC050_M4G
  75. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  76. #define ECOMPASS_IOC_GET_GFLAG _IOR(MSENSOR, 0x30, short)
  77. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  78. #define ECOMPASS_IOC_GET_GDELAY _IOR(MSENSOR, 0x31, int)
  79. #endif //BMC050_M4G
  80. #ifdef BMC050_VRV
  81. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  82. #define ECOMPASS_IOC_GET_VRVFLAG _IOR(MSENSOR, 0x32, short)
  83. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  84. #define ECOMPASS_IOC_GET_VRVDELAY _IOR(MSENSOR, 0x33, int)
  85. #endif //BMC050_VRV
  86. #ifdef BMC050_VLA
  87. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  88. #define ECOMPASS_IOC_GET_VLAFLAG _IOR(MSENSOR, 0x34, short)
  89. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  90. #define ECOMPASS_IOC_GET_VLADELAY _IOR(MSENSOR, 0x35, int)
  91. #endif //BMC050_VLA
  92. #ifdef BMC050_VG
  93. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  94. #define ECOMPASS_IOC_GET_VGFLAG _IOR(MSENSOR, 0x36, short)
  95. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  96. #define ECOMPASS_IOC_GET_VGDELAY _IOR(MSENSOR, 0x37, int)
  97. #endif //BMC050_VG
  98. /* !!! add a new definition in linux/sensors_io.h if possible !!! */
  99. #define BMM_IOC_GET_EVENT_FLAG ECOMPASS_IOC_GET_OPEN_STATUS
  100. //add for non-block
  101. #define BMM_IOC_GET_NONBLOCK_EVENT_FLAG _IOR(MSENSOR, 0x38, int)
  102. // calibration msensor and orientation data
  103. static int sensor_data[CALIBRATION_DATA_SIZE];
  104. #if defined(BMC050_M4G) || defined(BMC050_VRV)
  105. static int m4g_data[CALIBRATION_DATA_SIZE];
  106. #endif //BMC050_M4G || BMC050_VRV
  107. #if defined(BMC050_VLA)
  108. static int vla_data[CALIBRATION_DATA_SIZE];
  109. #endif //BMC050_VLA
  110. #if defined(BMC050_VG)
  111. static int vg_data[CALIBRATION_DATA_SIZE];
  112. #endif //BMC050_VG
  113. static struct mutex sensor_data_mutex;
  114. static DECLARE_WAIT_QUEUE_HEAD(uplink_event_flag_wq);
  115. static int bmm050d_delay = BMM050_DEFAULT_DELAY;
  116. #ifdef BMC050_M4G
  117. static int m4g_delay = BMM050_DEFAULT_DELAY;
  118. #endif //BMC050_M4G
  119. #ifdef BMC050_VRV
  120. static int vrv_delay = BMM050_DEFAULT_DELAY;
  121. #endif //BMC050_VRV
  122. #ifdef BMC050_VLA
  123. static int vla_delay = BMM050_DEFAULT_DELAY;
  124. #endif //BMC050_VRV
  125. #ifdef BMC050_VG
  126. static int vg_delay = BMM050_DEFAULT_DELAY;
  127. #endif //BMC050_VG
  128. static atomic_t m_flag = ATOMIC_INIT(0);
  129. static atomic_t o_flag = ATOMIC_INIT(0);
  130. #ifdef BMC050_M4G
  131. static atomic_t g_flag = ATOMIC_INIT(0);
  132. #endif //BMC050_M4G
  133. #ifdef BMC050_VRV
  134. static atomic_t vrv_flag = ATOMIC_INIT(0);
  135. #endif //BMC050_VRV
  136. #ifdef BMC050_VLA
  137. static atomic_t vla_flag = ATOMIC_INIT(0);
  138. #endif //BMC050_VLA
  139. #ifdef BMC050_VG
  140. static atomic_t vg_flag = ATOMIC_INIT(0);
  141. #endif //BMC050_VG
  142. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  143. static atomic_t driver_suspend_flag = ATOMIC_INIT(0);
  144. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  145. static struct mutex uplink_event_flag_mutex;
  146. /* uplink event flag */
  147. static volatile u32 uplink_event_flag = 0;
  148. /* uplink event flag bitmap */
  149. enum {
  150. /* active */
  151. BMMDRV_ULEVT_FLAG_O_ACTIVE = 0x0001,
  152. BMMDRV_ULEVT_FLAG_M_ACTIVE = 0x0002,
  153. BMMDRV_ULEVT_FLAG_G_ACTIVE = 0x0004,
  154. BMMDRV_ULEVT_FLAG_VRV_ACTIVE = 0x0008,/* Virtual Rotation Vector */
  155. BMMDRV_ULEVT_FLAG_FLIP_ACTIVE = 0x0010,
  156. BMMDRV_ULEVT_FLAG_VLA_ACTIVE = 0x0020,/* Virtual Linear Accelerometer */
  157. BMMDRV_ULEVT_FLAG_VG_ACTIVE = 0x0040,/* Virtual Gravity */
  158. /* delay */
  159. BMMDRV_ULEVT_FLAG_O_DELAY = 0x0100,
  160. BMMDRV_ULEVT_FLAG_M_DELAY = 0x0200,
  161. BMMDRV_ULEVT_FLAG_G_DELAY = 0x0400,
  162. BMMDRV_ULEVT_FLAG_VRV_DELAY = 0x0800,
  163. BMMDRV_ULEVT_FLAG_FLIP_DELAY = 0x1000,
  164. BMMDRV_ULEVT_FLAG_VLA_DELAY = 0x2000,
  165. BMMDRV_ULEVT_FLAG_VG_DELAY = 0x4000,
  166. /* all */
  167. BMMDRV_ULEVT_FLAG_ALL = 0xffff
  168. };
  169. //tad3sgh add --
  170. #define MAX_FIFO_F_LEVEL 32
  171. #define MAX_FIFO_F_BYTES 6
  172. /*----------------------------------------------------------------------------*/
  173. #define BMA255_AXIS_X 0
  174. #define BMA255_AXIS_Y 1
  175. #define BMA255_AXIS_Z 2
  176. #define BMA255_AXES_NUM 3
  177. #define BMA255_DATA_LEN 6
  178. #define BMA255_DEV_NAME "BMA255"
  179. #define BMA255_MODE_NORMAL 0
  180. #define BMA255_MODE_LOWPOWER 1
  181. #define BMA255_MODE_SUSPEND 2
  182. //for bma255 chip.
  183. #define BMA255_ACC_X_LSB__POS 4
  184. #define BMA255_ACC_X_LSB__LEN 4
  185. #define BMA255_ACC_X_LSB__MSK 0xC0//0xF0
  186. //#define BMA255_ACC_X_LSB__REG BMA255_X_AXIS_LSB_REG
  187. #define BMA255_ACC_X_MSB__POS 0
  188. #define BMA255_ACC_X_MSB__LEN 8
  189. #define BMA255_ACC_X_MSB__MSK 0xFF
  190. //#define BMA255_ACC_X_MSB__REG BMA255_X_AXIS_MSB_REG
  191. #define BMA255_ACC_Y_LSB__POS 4
  192. #define BMA255_ACC_Y_LSB__LEN 4
  193. #define BMA255_ACC_Y_LSB__MSK 0xC0//0xF0
  194. //#define BMA255_ACC_Y_LSB__REG BMA255_Y_AXIS_LSB_REG
  195. #define BMA255_ACC_Y_MSB__POS 0
  196. #define BMA255_ACC_Y_MSB__LEN 8
  197. #define BMA255_ACC_Y_MSB__MSK 0xFF
  198. //#define BMA255_ACC_Y_MSB__REG BMA255_Y_AXIS_MSB_REG
  199. #define BMA255_ACC_Z_LSB__POS 4
  200. #define BMA255_ACC_Z_LSB__LEN 4
  201. #define BMA255_ACC_Z_LSB__MSK 0xC0//0xF0
  202. //#define BMA255_ACC_Z_LSB__REG BMA255_Z_AXIS_LSB_REG
  203. #define BMA255_ACC_Z_MSB__POS 0
  204. #define BMA255_ACC_Z_MSB__LEN 8
  205. #define BMA255_ACC_Z_MSB__MSK 0xFF
  206. //#define BMA255_ACC_Z_MSB__REG BMA255_Z_AXIS_MSB_REG
  207. #define BMA255_EN_LOW_POWER__POS 6
  208. #define BMA255_EN_LOW_POWER__LEN 1
  209. #define BMA255_EN_LOW_POWER__MSK 0x40
  210. #define BMA255_EN_LOW_POWER__REG BMA255_REG_POWER_CTL
  211. #define BMA255_EN_SUSPEND__POS 7
  212. #define BMA255_EN_SUSPEND__LEN 1
  213. #define BMA255_EN_SUSPEND__MSK 0x80
  214. #define BMA255_EN_SUSPEND__REG BMA255_REG_POWER_CTL
  215. /* fifo mode*/
  216. #define BMA255_FIFO_MODE__POS 6
  217. #define BMA255_FIFO_MODE__LEN 2
  218. #define BMA255_FIFO_MODE__MSK 0xC0
  219. #define BMA255_FIFO_MODE__REG BMA255_FIFO_MODE_REG
  220. #define BMA255_FIFO_FRAME_COUNTER_S__POS 0
  221. #define BMA255_FIFO_FRAME_COUNTER_S__LEN 7
  222. #define BMA255_FIFO_FRAME_COUNTER_S__MSK 0x7F
  223. #define BMA255_FIFO_FRAME_COUNTER_S__REG BMA255_STATUS_FIFO_REG
  224. #define BMA255_GET_BITSLICE(regvar, bitname)\
  225. ((regvar & bitname##__MSK) >> bitname##__POS)
  226. #define BMA255_SET_BITSLICE(regvar, bitname, val)\
  227. ((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))
  228. /*----------------------------------------------------------------------------*/
  229. /*----------------------------------------------------------------------------*/
  230. static const struct i2c_device_id bma255_i2c_id[] = {{BMA255_DEV_NAME,0},{}};
  231. /*----------------------------------------------------------------------------*/
  232. static int bma255_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id);
  233. static int bma255_i2c_remove(struct i2c_client *client);
  234. /*----------------------------------------------------------------------------*/
  235. typedef enum {
  236. BMA_TRC_FILTER = 0x01,
  237. BMA_TRC_RAWDATA = 0x02,
  238. BMA_TRC_IOCTL = 0x04,
  239. BMA_TRC_CALI = 0X08,
  240. BMA_TRC_INFO = 0X10,
  241. } BMA_TRC;
  242. /*----------------------------------------------------------------------------*/
  243. struct scale_factor{
  244. u8 whole;
  245. u8 fraction;
  246. };
  247. /*----------------------------------------------------------------------------*/
  248. struct data_resolution {
  249. struct scale_factor scalefactor;
  250. int sensitivity;
  251. };
  252. /*----------------------------------------------------------------------------*/
  253. #define C_MAX_FIR_LENGTH (32)
  254. /*----------------------------------------------------------------------------*/
  255. struct data_filter {
  256. s16 raw[C_MAX_FIR_LENGTH][BMA255_AXES_NUM];
  257. int sum[BMA255_AXES_NUM];
  258. int num;
  259. int idx;
  260. };
  261. /*----------------------------------------------------------------------------*/
  262. struct bma255_i2c_data {
  263. struct i2c_client *client;
  264. struct acc_hw *hw;
  265. struct hwmsen_convert cvt;
  266. /*misc*/
  267. struct data_resolution *reso;
  268. atomic_t trace;
  269. atomic_t suspend;
  270. atomic_t selftest;
  271. atomic_t filter;
  272. s16 cali_sw[BMA255_AXES_NUM+1];
  273. struct mutex lock;
  274. /*data*/
  275. s8 offset[BMA255_AXES_NUM+1]; /*+1: for 4-byte alignment*/
  276. s16 data[BMA255_AXES_NUM+1];
  277. u8 fifo_count;
  278. #if defined(CONFIG_BMA255_LOWPASS)
  279. atomic_t firlen;
  280. atomic_t fir_en;
  281. struct data_filter fir;
  282. #endif
  283. /*early suspend*/
  284. #if defined(CONFIG_HAS_EARLYSUSPEND)
  285. struct early_suspend early_drv;
  286. #endif
  287. };
  288. #if !defined(CONFIG_HAS_EARLYSUSPEND)
  289. static int bma255_suspend(struct i2c_client *client, pm_message_t msg);
  290. static int bma255_resume(struct i2c_client *client);
  291. #endif
  292. /*----------------------------------------------------------------------------*/
  293. #ifdef CONFIG_OF
  294. static const struct of_device_id gsensor_of_match[] = {
  295. { .compatible = "mediatek,gsensor", },
  296. {},
  297. };
  298. #endif
  299. static struct i2c_driver bma255_i2c_driver = {
  300. .driver = {
  301. .name = BMA255_DEV_NAME,
  302. #ifdef CONFIG_OF
  303. .of_match_table = gsensor_of_match,
  304. #endif
  305. },
  306. .probe = bma255_i2c_probe,
  307. .remove = bma255_i2c_remove,
  308. #if !defined(CONFIG_HAS_EARLYSUSPEND)
  309. .suspend = bma255_suspend,
  310. .resume = bma255_resume,
  311. #endif
  312. .id_table = bma255_i2c_id,
  313. };
  314. /*----------------------------------------------------------------------------*/
  315. static struct i2c_client *bma255_i2c_client = NULL;
  316. static struct acc_init_info bma255_init_info;
  317. static struct bma255_i2c_data *obj_i2c_data = NULL;
  318. static bool sensor_power = true;
  319. static struct GSENSOR_VECTOR3D gsensor_gain;
  320. //static char selftestRes[8]= {0};
  321. static int bma255_init_flag =-1; // 0<==>OK -1 <==> fail
  322. /*----------------------------------------------------------------------------*/
  323. #define GSE_TAG "[Gsensor] "
  324. #define GSE_FUN(f) printk(GSE_TAG"%s\n", __FUNCTION__)
  325. #define GSE_ERR(fmt, args...) printk(GSE_TAG"%s %d : "fmt, __FUNCTION__, __LINE__, ##args)
  326. #define GSE_LOG(fmt, args...) printk(GSE_TAG fmt, ##args)
  327. #define COMPATIABLE_NAME "mediatek,bma255"
  328. struct acc_hw accel_cust;
  329. static struct acc_hw *hw = &accel_cust;
  330. struct acc_hw *get_cust_acc(void)
  331. {
  332. return &accel_cust;
  333. }
  334. /*----------------------------------------------------------------------------*/
  335. static struct data_resolution bma255_data_resolution[1] = {
  336. /* combination by {FULL_RES,RANGE}*/
  337. //for bma255 12bit
  338. {{ 1, 95}, 512}, // dataformat +/-4g in 12-bit resolution; { 1, 95} = 1.95 = (2*4*1000)/(2^12); 512 = (2^12)/(2*4)
  339. };
  340. /*----------------------------------------------------------------------------*/
  341. static struct data_resolution bma255_offset_resolution = {{ 1, 95}, 512};
  342. /* I2C operation functions */
  343. static int bma_i2c_read_block(struct i2c_client *client,
  344. u8 addr, u8 *data, u8 len)
  345. {
  346. #ifdef CONFIG_I2C_BASIC_FUNCTION
  347. u8 beg = addr;
  348. struct i2c_msg msgs[2] = {
  349. {
  350. .addr = client->addr, .flags = 0,
  351. .len = 1, .buf = &beg
  352. },
  353. {
  354. .addr = client->addr, .flags = I2C_M_RD,
  355. .len = len, .buf = data,
  356. }
  357. };
  358. int err;
  359. if (!client)
  360. return -EINVAL;
  361. else if (len > C_I2C_FIFO_SIZE) {
  362. GSE_ERR(" length %d exceeds %d\n", len, C_I2C_FIFO_SIZE);
  363. return -EINVAL;
  364. }
  365. err = i2c_transfer(client->adapter, msgs, sizeof(msgs)/sizeof(msgs[0]));
  366. if (err != 2) {
  367. GSE_ERR("i2c_transfer error: (%d %p %d) %d\n",
  368. addr, data, len, err);
  369. err = -EIO;
  370. } else {
  371. err = 0;/*no error*/
  372. }
  373. return err;
  374. #else
  375. int err = 0;
  376. err = i2c_smbus_read_i2c_block_data(client, addr, len, data);
  377. if (err < 0)
  378. return -1;
  379. return 0;
  380. #endif
  381. }
  382. #define I2C_BUFFER_SIZE 256
  383. static int bma_i2c_write_block(struct i2c_client *client, u8 addr,
  384. u8 *data, u8 len)
  385. {
  386. #ifdef CONFIG_I2C_BASIC_FUNCTION
  387. /*
  388. *because address also occupies one byte,
  389. *the maximum length for write is 7 bytes
  390. */
  391. int err, idx = 0, num = 0;
  392. char buf[32];
  393. if (!client)
  394. return -EINVAL;
  395. else if (len > C_I2C_FIFO_SIZE) {
  396. GSE_ERR(" length %d exceeds %d\n", len, C_I2C_FIFO_SIZE);
  397. return -EINVAL;
  398. }
  399. buf[num++] = addr;
  400. for (idx = 0; idx < len; idx++)
  401. buf[num++] = data[idx];
  402. err = i2c_master_send(client, buf, num);
  403. if (err < 0) {
  404. GSE_ERR("send command error!!\n");
  405. return -EFAULT;
  406. } else {
  407. err = 0;/*no error*/
  408. }
  409. return err;
  410. #else
  411. int err = 0;
  412. err = i2c_smbus_write_i2c_block_data(client, addr, len, data);
  413. if (err < 0)
  414. return -1;
  415. return 0;
  416. #endif
  417. }
  418. /*--------------------BMA255 power control function----------------------------------*/
  419. static void BMA255_power(struct acc_hw *hw, unsigned int on)
  420. {
  421. }
  422. /*----------------------------------------------------------------------------*/
  423. /*----------------------------------------------------------------------------*/
  424. static int BMA255_SetDataResolution(struct bma255_i2c_data *obj)
  425. {
  426. /*set g sensor dataresolution here*/
  427. /*BMA255 only can set to 10-bit dataresolution, so do nothing in bma255 driver here*/
  428. /*end of set dataresolution*/
  429. /*we set measure range from -2g to +2g in BMA255_SetDataFormat(client, BMA255_RANGE_2G),
  430. and set 10-bit dataresolution BMA255_SetDataResolution()*/
  431. /*so bma255_data_resolution[0] set value as {{ 3, 9}, 256} when declaration, and assign the value to obj->reso here*/
  432. obj->reso = &bma255_data_resolution[0];
  433. return 0;
  434. /*if you changed the measure range, for example call: BMA255_SetDataFormat(client, BMA255_RANGE_4G),
  435. you must set the right value to bma255_data_resolution*/
  436. }
  437. /*----------------------------------------------------------------------------*/
  438. static int BMA255_ReadData(struct i2c_client *client, s16 data[BMA255_AXES_NUM])
  439. {
  440. //struct bma255_i2c_data *priv = i2c_get_clientdata(client);
  441. u8 addr = BMA255_REG_DATAXLOW;
  442. u8 buf[BMA255_DATA_LEN] = {0};
  443. int err = 0;
  444. if(NULL == client)
  445. {
  446. err = -EINVAL;
  447. }
  448. else if((err = bma_i2c_read_block(client, addr, buf, BMA255_DATA_LEN)))
  449. {
  450. GSE_ERR("error: %d\n", err);
  451. }
  452. else
  453. {
  454. /* Convert sensor raw data to 16-bit integer */
  455. data[BMA255_AXIS_X] = BMA255_GET_BITSLICE(buf[0], BMA255_ACC_X_LSB)
  456. |(BMA255_GET_BITSLICE(buf[1],
  457. BMA255_ACC_X_MSB)<<BMA255_ACC_X_LSB__LEN);
  458. data[BMA255_AXIS_X] = data[BMA255_AXIS_X] << (sizeof(short)*8-(BMA255_ACC_X_LSB__LEN
  459. + BMA255_ACC_X_MSB__LEN));
  460. data[BMA255_AXIS_X] = data[BMA255_AXIS_X] >> (sizeof(short)*8-(BMA255_ACC_X_LSB__LEN
  461. + BMA255_ACC_X_MSB__LEN));
  462. data[BMA255_AXIS_Y] = BMA255_GET_BITSLICE(buf[2], BMA255_ACC_Y_LSB)
  463. | (BMA255_GET_BITSLICE(buf[3],
  464. BMA255_ACC_Y_MSB)<<BMA255_ACC_Y_LSB__LEN);
  465. data[BMA255_AXIS_Y] = data[BMA255_AXIS_Y] << (sizeof(short)*8-(BMA255_ACC_Y_LSB__LEN
  466. + BMA255_ACC_Y_MSB__LEN));
  467. data[BMA255_AXIS_Y] = data[BMA255_AXIS_Y] >> (sizeof(short)*8-(BMA255_ACC_Y_LSB__LEN
  468. + BMA255_ACC_Y_MSB__LEN));
  469. data[BMA255_AXIS_Z] = BMA255_GET_BITSLICE(buf[4], BMA255_ACC_Z_LSB)
  470. | (BMA255_GET_BITSLICE(buf[5],
  471. BMA255_ACC_Z_MSB)<<BMA255_ACC_Z_LSB__LEN);
  472. data[BMA255_AXIS_Z] = data[BMA255_AXIS_Z] << (sizeof(short)*8-(BMA255_ACC_Z_LSB__LEN
  473. + BMA255_ACC_Z_MSB__LEN));
  474. data[BMA255_AXIS_Z] = data[BMA255_AXIS_Z] >> (sizeof(short)*8-(BMA255_ACC_Z_LSB__LEN
  475. + BMA255_ACC_Z_MSB__LEN));
  476. #ifdef CONFIG_BMA255_LOWPASS
  477. if(atomic_read(&priv->filter))
  478. {
  479. if(atomic_read(&priv->fir_en) && !atomic_read(&priv->suspend))
  480. {
  481. int idx, firlen = atomic_read(&priv->firlen);
  482. if(priv->fir.num < firlen)
  483. {
  484. priv->fir.raw[priv->fir.num][BMA255_AXIS_X] = data[BMA255_AXIS_X];
  485. priv->fir.raw[priv->fir.num][BMA255_AXIS_Y] = data[BMA255_AXIS_Y];
  486. priv->fir.raw[priv->fir.num][BMA255_AXIS_Z] = data[BMA255_AXIS_Z];
  487. priv->fir.sum[BMA255_AXIS_X] += data[BMA255_AXIS_X];
  488. priv->fir.sum[BMA255_AXIS_Y] += data[BMA255_AXIS_Y];
  489. priv->fir.sum[BMA255_AXIS_Z] += data[BMA255_AXIS_Z];
  490. if(atomic_read(&priv->trace) & BMA_TRC_FILTER)
  491. {
  492. GSE_LOG("add [%2d] [%5d %5d %5d] => [%5d %5d %5d]\n", priv->fir.num,
  493. priv->fir.raw[priv->fir.num][BMA255_AXIS_X], priv->fir.raw[priv->fir.num][BMA255_AXIS_Y], priv->fir.raw[priv->fir.num][BMA255_AXIS_Z],
  494. priv->fir.sum[BMA255_AXIS_X], priv->fir.sum[BMA255_AXIS_Y], priv->fir.sum[BMA255_AXIS_Z]);
  495. }
  496. priv->fir.num++;
  497. priv->fir.idx++;
  498. }
  499. else
  500. {
  501. idx = priv->fir.idx % firlen;
  502. priv->fir.sum[BMA255_AXIS_X] -= priv->fir.raw[idx][BMA255_AXIS_X];
  503. priv->fir.sum[BMA255_AXIS_Y] -= priv->fir.raw[idx][BMA255_AXIS_Y];
  504. priv->fir.sum[BMA255_AXIS_Z] -= priv->fir.raw[idx][BMA255_AXIS_Z];
  505. priv->fir.raw[idx][BMA255_AXIS_X] = data[BMA255_AXIS_X];
  506. priv->fir.raw[idx][BMA255_AXIS_Y] = data[BMA255_AXIS_Y];
  507. priv->fir.raw[idx][BMA255_AXIS_Z] = data[BMA255_AXIS_Z];
  508. priv->fir.sum[BMA255_AXIS_X] += data[BMA255_AXIS_X];
  509. priv->fir.sum[BMA255_AXIS_Y] += data[BMA255_AXIS_Y];
  510. priv->fir.sum[BMA255_AXIS_Z] += data[BMA255_AXIS_Z];
  511. priv->fir.idx++;
  512. data[BMA255_AXIS_X] = priv->fir.sum[BMA255_AXIS_X]/firlen;
  513. data[BMA255_AXIS_Y] = priv->fir.sum[BMA255_AXIS_Y]/firlen;
  514. data[BMA255_AXIS_Z] = priv->fir.sum[BMA255_AXIS_Z]/firlen;
  515. if(atomic_read(&priv->trace) & BMA_TRC_FILTER)
  516. {
  517. GSE_LOG("add [%2d] [%5d %5d %5d] => [%5d %5d %5d] : [%5d %5d %5d]\n", idx,
  518. priv->fir.raw[idx][BMA255_AXIS_X], priv->fir.raw[idx][BMA255_AXIS_Y], priv->fir.raw[idx][BMA255_AXIS_Z],
  519. priv->fir.sum[BMA255_AXIS_X], priv->fir.sum[BMA255_AXIS_Y], priv->fir.sum[BMA255_AXIS_Z],
  520. data[BMA255_AXIS_X], data[BMA255_AXIS_Y], data[BMA255_AXIS_Z]);
  521. }
  522. }
  523. }
  524. }
  525. #endif
  526. }
  527. return err;
  528. }
  529. /*----------------------------------------------------------------------------*/
  530. static int BMA255_ReadOffset(struct i2c_client *client, s8 ofs[BMA255_AXES_NUM])
  531. {
  532. int err =0;
  533. #ifdef SW_CALIBRATION
  534. ofs[0]=ofs[1]=ofs[2]=0x0;
  535. #else
  536. if((err = bma_i2c_read_block(client, BMA255_REG_OFSX, ofs, BMA255_AXES_NUM)))
  537. {
  538. GSE_ERR("error: %d\n", err);
  539. }
  540. #endif
  541. //printk("offesx=%x, y=%x, z=%x",ofs[0],ofs[1],ofs[2]);
  542. return err;
  543. }
  544. /*----------------------------------------------------------------------------*/
  545. static int BMA255_ResetCalibration(struct i2c_client *client)
  546. {
  547. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  548. // u8 ofs[4]={0,0,0,0};
  549. int err=0;
  550. #ifdef SW_CALIBRATION
  551. #else
  552. if((err = bma_i2c_write_block(client, BMA255_REG_OFSX, ofs, 4)))
  553. {
  554. GSE_ERR("error: %d\n", err);
  555. }
  556. #endif
  557. memset(obj->cali_sw, 0x00, sizeof(obj->cali_sw));
  558. memset(obj->offset, 0x00, sizeof(obj->offset));
  559. return err;
  560. }
  561. /*----------------------------------------------------------------------------*/
  562. static int BMA255_ReadCalibration(struct i2c_client *client, int dat[BMA255_AXES_NUM])
  563. {
  564. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  565. int err = 0;
  566. int mul;
  567. #ifdef SW_CALIBRATION
  568. mul = 0;//only SW Calibration, disable HW Calibration
  569. #else
  570. if ((err = BMA255_ReadOffset(client, obj->offset))) {
  571. GSE_ERR("read offset fail, %d\n", err);
  572. return err;
  573. }
  574. mul = obj->reso->sensitivity/bma255_offset_resolution.sensitivity;
  575. #endif
  576. dat[obj->cvt.map[BMA255_AXIS_X]] = obj->cvt.sign[BMA255_AXIS_X]*(obj->offset[BMA255_AXIS_X]*mul + obj->cali_sw[BMA255_AXIS_X]);
  577. dat[obj->cvt.map[BMA255_AXIS_Y]] = obj->cvt.sign[BMA255_AXIS_Y]*(obj->offset[BMA255_AXIS_Y]*mul + obj->cali_sw[BMA255_AXIS_Y]);
  578. dat[obj->cvt.map[BMA255_AXIS_Z]] = obj->cvt.sign[BMA255_AXIS_Z]*(obj->offset[BMA255_AXIS_Z]*mul + obj->cali_sw[BMA255_AXIS_Z]);
  579. return err;
  580. }
  581. /*----------------------------------------------------------------------------*/
  582. static int BMA255_ReadCalibrationEx(struct i2c_client *client, int act[BMA255_AXES_NUM], int raw[BMA255_AXES_NUM])
  583. {
  584. /*raw: the raw calibration data; act: the actual calibration data*/
  585. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  586. // int err;
  587. int mul;
  588. #ifdef SW_CALIBRATION
  589. mul = 0;//only SW Calibration, disable HW Calibration
  590. #else
  591. if(err = BMA255_ReadOffset(client, obj->offset))
  592. {
  593. GSE_ERR("read offset fail, %d\n", err);
  594. return err;
  595. }
  596. mul = obj->reso->sensitivity/bma255_offset_resolution.sensitivity;
  597. #endif
  598. raw[BMA255_AXIS_X] = obj->offset[BMA255_AXIS_X]*mul + obj->cali_sw[BMA255_AXIS_X];
  599. raw[BMA255_AXIS_Y] = obj->offset[BMA255_AXIS_Y]*mul + obj->cali_sw[BMA255_AXIS_Y];
  600. raw[BMA255_AXIS_Z] = obj->offset[BMA255_AXIS_Z]*mul + obj->cali_sw[BMA255_AXIS_Z];
  601. act[obj->cvt.map[BMA255_AXIS_X]] = obj->cvt.sign[BMA255_AXIS_X]*raw[BMA255_AXIS_X];
  602. act[obj->cvt.map[BMA255_AXIS_Y]] = obj->cvt.sign[BMA255_AXIS_Y]*raw[BMA255_AXIS_Y];
  603. act[obj->cvt.map[BMA255_AXIS_Z]] = obj->cvt.sign[BMA255_AXIS_Z]*raw[BMA255_AXIS_Z];
  604. return 0;
  605. }
  606. /*----------------------------------------------------------------------------*/
  607. static int BMA255_WriteCalibration(struct i2c_client *client, int dat[BMA255_AXES_NUM])
  608. {
  609. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  610. int err = 0;
  611. int cali[BMA255_AXES_NUM], raw[BMA255_AXES_NUM];
  612. //int lsb = bma255_offset_resolution.sensitivity;
  613. //int divisor = obj->reso->sensitivity/lsb;
  614. if((err = BMA255_ReadCalibrationEx(client, cali, raw))) /*offset will be updated in obj->offset*/
  615. {
  616. GSE_ERR("read offset fail, %d\n", err);
  617. return err;
  618. }
  619. GSE_LOG("OLDOFF: (%+3d %+3d %+3d): (%+3d %+3d %+3d) / (%+3d %+3d %+3d)\n",
  620. raw[BMA255_AXIS_X], raw[BMA255_AXIS_Y], raw[BMA255_AXIS_Z],
  621. obj->offset[BMA255_AXIS_X], obj->offset[BMA255_AXIS_Y], obj->offset[BMA255_AXIS_Z],
  622. obj->cali_sw[BMA255_AXIS_X], obj->cali_sw[BMA255_AXIS_Y], obj->cali_sw[BMA255_AXIS_Z]);
  623. /*calculate the real offset expected by caller*/
  624. cali[BMA255_AXIS_X] += dat[BMA255_AXIS_X];
  625. cali[BMA255_AXIS_Y] += dat[BMA255_AXIS_Y];
  626. cali[BMA255_AXIS_Z] += dat[BMA255_AXIS_Z];
  627. GSE_LOG("UPDATE: (%+3d %+3d %+3d)\n",
  628. dat[BMA255_AXIS_X], dat[BMA255_AXIS_Y], dat[BMA255_AXIS_Z]);
  629. #ifdef SW_CALIBRATION
  630. obj->cali_sw[BMA255_AXIS_X] = obj->cvt.sign[BMA255_AXIS_X]*(cali[obj->cvt.map[BMA255_AXIS_X]]);
  631. obj->cali_sw[BMA255_AXIS_Y] = obj->cvt.sign[BMA255_AXIS_Y]*(cali[obj->cvt.map[BMA255_AXIS_Y]]);
  632. obj->cali_sw[BMA255_AXIS_Z] = obj->cvt.sign[BMA255_AXIS_Z]*(cali[obj->cvt.map[BMA255_AXIS_Z]]);
  633. #else
  634. obj->offset[BMA255_AXIS_X] = (s8)(obj->cvt.sign[BMA255_AXIS_X]*(cali[obj->cvt.map[BMA255_AXIS_X]])/(divisor));
  635. obj->offset[BMA255_AXIS_Y] = (s8)(obj->cvt.sign[BMA255_AXIS_Y]*(cali[obj->cvt.map[BMA255_AXIS_Y]])/(divisor));
  636. obj->offset[BMA255_AXIS_Z] = (s8)(obj->cvt.sign[BMA255_AXIS_Z]*(cali[obj->cvt.map[BMA255_AXIS_Z]])/(divisor));
  637. /*convert software calibration using standard calibration*/
  638. obj->cali_sw[BMA255_AXIS_X] = obj->cvt.sign[BMA255_AXIS_X]*(cali[obj->cvt.map[BMA255_AXIS_X]])%(divisor);
  639. obj->cali_sw[BMA255_AXIS_Y] = obj->cvt.sign[BMA255_AXIS_Y]*(cali[obj->cvt.map[BMA255_AXIS_Y]])%(divisor);
  640. obj->cali_sw[BMA255_AXIS_Z] = obj->cvt.sign[BMA255_AXIS_Z]*(cali[obj->cvt.map[BMA255_AXIS_Z]])%(divisor);
  641. GSE_LOG("NEWOFF: (%+3d %+3d %+3d): (%+3d %+3d %+3d) / (%+3d %+3d %+3d)\n",
  642. obj->offset[BMA255_AXIS_X]*divisor + obj->cali_sw[BMA255_AXIS_X],
  643. obj->offset[BMA255_AXIS_Y]*divisor + obj->cali_sw[BMA255_AXIS_Y],
  644. obj->offset[BMA255_AXIS_Z]*divisor + obj->cali_sw[BMA255_AXIS_Z],
  645. obj->offset[BMA255_AXIS_X], obj->offset[BMA255_AXIS_Y], obj->offset[BMA255_AXIS_Z],
  646. obj->cali_sw[BMA255_AXIS_X], obj->cali_sw[BMA255_AXIS_Y], obj->cali_sw[BMA255_AXIS_Z]);
  647. if(err = bma_i2c_write_block(obj->client, BMA255_REG_OFSX, obj->offset, BMA255_AXES_NUM))
  648. {
  649. GSE_ERR("write offset fail: %d\n", err);
  650. return err;
  651. }
  652. #endif
  653. return err;
  654. }
  655. /*----------------------------------------------------------------------------*/
  656. static int BMA255_CheckDeviceID(struct i2c_client *client)
  657. {
  658. u8 databuf[2];
  659. int res = 0;
  660. memset(databuf, 0, sizeof(u8)*2);
  661. res = bma_i2c_read_block(client, BMA255_REG_DEVID, databuf, 0x01);
  662. res = bma_i2c_read_block(client, BMA255_REG_DEVID, databuf, 0x01);
  663. if(res < 0)
  664. goto exit_BMA255_CheckDeviceID;
  665. if(databuf[0]!=BMA255_FIXED_DEVID)
  666. {
  667. printk("BMA255_CheckDeviceID %d failt!\n ", databuf[0]);
  668. return BMA255_ERR_IDENTIFICATION;
  669. }
  670. else
  671. {
  672. printk("BMA255_CheckDeviceID %d pass!\n ", databuf[0]);
  673. }
  674. exit_BMA255_CheckDeviceID:
  675. if (res < 0)
  676. {
  677. return BMA255_ERR_I2C;
  678. }
  679. return BMA255_SUCCESS;
  680. }
  681. /*----------------------------------------------------------------------------*/
  682. static int BMA255_SetPowerMode(struct i2c_client *client, bool enable)
  683. {
  684. u8 databuf[2] = {0};
  685. int res = 0;
  686. // u8 addr = BMA255_REG_POWER_CTL;
  687. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  688. u8 actual_power_mode = 0;
  689. if(enable == sensor_power )
  690. {
  691. GSE_LOG("Sensor power status is newest!\n");
  692. return BMA255_SUCCESS;
  693. }
  694. mutex_lock(&obj->lock);
  695. if(enable == true)
  696. {
  697. actual_power_mode = BMA255_MODE_NORMAL;
  698. }
  699. else
  700. {
  701. actual_power_mode = BMA255_MODE_SUSPEND;
  702. }
  703. res = bma_i2c_read_block(client,
  704. BMA255_MODE_CTRL_REG, &databuf[0], 1);
  705. res += bma_i2c_read_block(client,
  706. BMA255_LOW_POWER_CTRL_REG, &databuf[1], 1);
  707. switch (actual_power_mode) {
  708. case BMA255_MODE_NORMAL:
  709. databuf[0] = BMA255_SET_BITSLICE(databuf[0],
  710. BMA255_MODE_CTRL, 0);
  711. databuf[1] = BMA255_SET_BITSLICE(databuf[1],
  712. BMA255_LOW_POWER_MODE, 0);
  713. res += bma_i2c_write_block(client,
  714. BMA255_MODE_CTRL_REG, &databuf[0], 1);
  715. mdelay(1);
  716. res += bma_i2c_write_block(client,
  717. BMA255_LOW_POWER_CTRL_REG, &databuf[1], 1);
  718. mdelay(1);
  719. break;
  720. case BMA255_MODE_SUSPEND:
  721. databuf[0] = BMA255_SET_BITSLICE(databuf[0],
  722. BMA255_MODE_CTRL, 4);
  723. databuf[1] = BMA255_SET_BITSLICE(databuf[1],
  724. BMA255_LOW_POWER_MODE, 0);
  725. res += bma_i2c_write_block(client,
  726. BMA255_LOW_POWER_CTRL_REG, &databuf[1], 1);
  727. mdelay(1);
  728. res += bma_i2c_write_block(client,
  729. BMA255_MODE_CTRL_REG, &databuf[0], 1);
  730. mdelay(1);
  731. break;
  732. }
  733. if(res < 0)
  734. {
  735. GSE_ERR("set power mode failed, res = %d\n", res);
  736. mutex_unlock(&obj->lock);
  737. return BMA255_ERR_I2C;
  738. }
  739. sensor_power = enable;
  740. mutex_unlock(&obj->lock);
  741. return BMA255_SUCCESS;
  742. }
  743. /*----------------------------------------------------------------------------*/
  744. static int BMA255_SetDataFormat(struct i2c_client *client, u8 dataformat)
  745. {
  746. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  747. u8 databuf[2] = {0};
  748. int res = 0;
  749. mutex_lock(&obj->lock);
  750. res = bma_i2c_read_block(client,
  751. BMA255_RANGE_SEL_REG, &databuf[0], 1);
  752. databuf[0] = BMA255_SET_BITSLICE(databuf[0],
  753. BMA255_RANGE_SEL, dataformat);
  754. res += bma_i2c_write_block(client,
  755. BMA255_RANGE_SEL_REG, &databuf[0], 1);
  756. mdelay(1);
  757. if(res < 0)
  758. {
  759. GSE_ERR("set data format failed, res = %d\n", res);
  760. mutex_unlock(&obj->lock);
  761. return BMA255_ERR_I2C;
  762. }
  763. mutex_unlock(&obj->lock);
  764. return BMA255_SetDataResolution(obj);
  765. }
  766. /*----------------------------------------------------------------------------*/
  767. static int BMA255_SetBWRate(struct i2c_client *client, u8 bwrate)
  768. {
  769. u8 databuf[2] = {0};
  770. int res = 0;
  771. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  772. mutex_lock(&obj->lock);
  773. res = bma_i2c_read_block(client,
  774. BMA255_BANDWIDTH__REG, &databuf[0], 1);
  775. databuf[0] = BMA255_SET_BITSLICE(databuf[0],
  776. BMA255_BANDWIDTH, bwrate);
  777. res += bma_i2c_write_block(client,
  778. BMA255_BANDWIDTH__REG, &databuf[0], 1);
  779. mdelay(1);
  780. if(res < 0)
  781. {
  782. GSE_ERR("set bandwidth failed, res = %d\n", res);
  783. mutex_unlock(&obj->lock);
  784. return BMA255_ERR_I2C;
  785. }
  786. mutex_unlock(&obj->lock);
  787. return BMA255_SUCCESS;
  788. }
  789. /*----------------------------------------------------------------------------*/
  790. static int BMA255_SetIntEnable(struct i2c_client *client, u8 intenable)
  791. {
  792. int res = 0;
  793. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  794. mutex_lock(&obj->lock);
  795. res = bma_i2c_write_block(client, BMA255_INT_REG_1, &intenable, 0x01);
  796. mdelay(1);
  797. if(res != BMA255_SUCCESS)
  798. {
  799. mutex_unlock(&obj->lock);
  800. return res;
  801. }
  802. res = bma_i2c_write_block(client, BMA255_INT_REG_2, &intenable, 0x01);
  803. mdelay(1);
  804. if(res != BMA255_SUCCESS)
  805. {
  806. mutex_unlock(&obj->lock);
  807. return res;
  808. }
  809. mutex_unlock(&obj->lock);
  810. printk("BMA255 disable interrupt ...\n");
  811. /*for disable interrupt function*/
  812. return BMA255_SUCCESS;
  813. }
  814. /*----------------------------------------------------------------------------*/
  815. static int bma255_init_client(struct i2c_client *client, int reset_cali)
  816. {
  817. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  818. int res = 0;
  819. printk("bma255_init_client \n");
  820. res = BMA255_CheckDeviceID(client);
  821. if(res != BMA255_SUCCESS)
  822. {
  823. return res;
  824. }
  825. printk("BMA255_CheckDeviceID ok \n");
  826. res = BMA255_SetBWRate(client, BMA255_BW_100HZ);
  827. if(res != BMA255_SUCCESS )
  828. {
  829. return res;
  830. }
  831. printk("BMA255_SetBWRate OK!\n");
  832. res = BMA255_SetDataFormat(client, BMA255_RANGE_4G);
  833. if(res != BMA255_SUCCESS)
  834. {
  835. return res;
  836. }
  837. printk("BMA255_SetDataFormat OK!\n");
  838. gsensor_gain.x = gsensor_gain.y = gsensor_gain.z = obj->reso->sensitivity;
  839. res = BMA255_SetIntEnable(client, 0x00);
  840. if(res != BMA255_SUCCESS)
  841. {
  842. return res;
  843. }
  844. printk("BMA255 disable interrupt function!\n");
  845. res = BMA255_SetPowerMode(client, false);
  846. if(res != BMA255_SUCCESS)
  847. {
  848. return res;
  849. }
  850. printk("BMA255_SetPowerMode OK!\n");
  851. if(0 != reset_cali)
  852. {
  853. /*reset calibration only in power on*/
  854. res = BMA255_ResetCalibration(client);
  855. if(res != BMA255_SUCCESS)
  856. {
  857. return res;
  858. }
  859. }
  860. printk("bma255_init_client OK!\n");
  861. #ifdef CONFIG_BMA255_LOWPASS
  862. memset(&obj->fir, 0x00, sizeof(obj->fir));
  863. #endif
  864. mdelay(20);
  865. return BMA255_SUCCESS;
  866. }
  867. /*----------------------------------------------------------------------------*/
  868. static int BMA255_ReadChipInfo(struct i2c_client *client, char *buf, int bufsize)
  869. {
  870. u8 databuf[10];
  871. memset(databuf, 0, sizeof(u8)*10);
  872. if((NULL == buf)||(bufsize<=30))
  873. {
  874. return -1;
  875. }
  876. if(NULL == client)
  877. {
  878. *buf = 0;
  879. return -2;
  880. }
  881. sprintf(buf, "BMA255 Chip");
  882. return 0;
  883. }
  884. /*----------------------------------------------------------------------------*/
  885. static int BMA255_CompassReadData(struct i2c_client *client, char *buf, int bufsize)
  886. {
  887. struct bma255_i2c_data *obj = (struct bma255_i2c_data*)i2c_get_clientdata(client);
  888. //u8 databuf[20];
  889. int acc[BMA255_AXES_NUM];
  890. int res = 0;
  891. s16 databuf[BMA255_AXES_NUM];
  892. //memset(databuf, 0, sizeof(u8)*10);
  893. if(NULL == buf)
  894. {
  895. return -1;
  896. }
  897. if(NULL == client)
  898. {
  899. *buf = 0;
  900. return -2;
  901. }
  902. if(sensor_power == false)
  903. {
  904. res = BMA255_SetPowerMode(client, true);
  905. if(res)
  906. {
  907. GSE_ERR("Power on bma255 error %d!\n", res);
  908. }
  909. }
  910. if((res = BMA255_ReadData(client, databuf)))
  911. {
  912. GSE_ERR("I2C error: ret value=%d", res);
  913. return -3;
  914. }
  915. else
  916. {
  917. /* Add compensated value performed by MTK calibration process*/
  918. databuf[BMA255_AXIS_X] += obj->cali_sw[BMA255_AXIS_X];
  919. databuf[BMA255_AXIS_Y] += obj->cali_sw[BMA255_AXIS_Y];
  920. databuf[BMA255_AXIS_Z] += obj->cali_sw[BMA255_AXIS_Z];
  921. /*remap coordinate*/
  922. acc[obj->cvt.map[BMA255_AXIS_X]] = obj->cvt.sign[BMA255_AXIS_X]*databuf[BMA255_AXIS_X];
  923. acc[obj->cvt.map[BMA255_AXIS_Y]] = obj->cvt.sign[BMA255_AXIS_Y]*databuf[BMA255_AXIS_Y];
  924. acc[obj->cvt.map[BMA255_AXIS_Z]] = obj->cvt.sign[BMA255_AXIS_Z]*databuf[BMA255_AXIS_Z];
  925. //printk("cvt x=%d, y=%d, z=%d \n",obj->cvt.sign[BMA255_AXIS_X],obj->cvt.sign[BMA255_AXIS_Y],obj->cvt.sign[BMA255_AXIS_Z]);
  926. //GSE_LOG("Mapped gsensor data: %d, %d, %d!\n", acc[BMA255_AXIS_X], acc[BMA255_AXIS_Y], acc[BMA255_AXIS_Z]);
  927. sprintf(buf, "%d %d %d", (s16)acc[BMA255_AXIS_X], (s16)acc[BMA255_AXIS_Y], (s16)acc[BMA255_AXIS_Z]);
  928. if(atomic_read(&obj->trace) & BMA_TRC_IOCTL)
  929. {
  930. GSE_LOG("gsensor data for compass: %s!\n", buf);
  931. }
  932. }
  933. return 0;
  934. }
  935. /*----------------------------------------------------------------------------*/
  936. static int BMA255_ReadSensorData(struct i2c_client *client, char *buf, int bufsize)
  937. {
  938. struct bma255_i2c_data *obj = (struct bma255_i2c_data*)i2c_get_clientdata(client);
  939. //u8 databuf[20];
  940. int acc[BMA255_AXES_NUM];
  941. int res = 0;
  942. s16 databuf[BMA255_AXES_NUM];
  943. //memset(databuf, 0, sizeof(u8)*10);
  944. if(NULL == buf)
  945. {
  946. return -1;
  947. }
  948. if(NULL == client)
  949. {
  950. *buf = 0;
  951. return -2;
  952. }
  953. if(sensor_power == false)
  954. {
  955. res = BMA255_SetPowerMode(client, true);
  956. if(res)
  957. {
  958. GSE_ERR("Power on bma255 error %d!\n", res);
  959. }
  960. }
  961. if((res = BMA255_ReadData(client, databuf)))
  962. {
  963. GSE_ERR("I2C error: ret value=%d", res);
  964. return -3;
  965. }
  966. else
  967. {
  968. //printk("raw data x=%d, y=%d, z=%d \n",obj->data[BMA255_AXIS_X],obj->data[BMA255_AXIS_Y],obj->data[BMA255_AXIS_Z]);
  969. databuf[BMA255_AXIS_X] += obj->cali_sw[BMA255_AXIS_X];
  970. databuf[BMA255_AXIS_Y] += obj->cali_sw[BMA255_AXIS_Y];
  971. databuf[BMA255_AXIS_Z] += obj->cali_sw[BMA255_AXIS_Z];
  972. //printk("cali_sw x=%d, y=%d, z=%d \n",obj->cali_sw[BMA255_AXIS_X],obj->cali_sw[BMA255_AXIS_Y],obj->cali_sw[BMA255_AXIS_Z]);
  973. /*remap coordinate*/
  974. acc[obj->cvt.map[BMA255_AXIS_X]] = obj->cvt.sign[BMA255_AXIS_X]*databuf[BMA255_AXIS_X];
  975. acc[obj->cvt.map[BMA255_AXIS_Y]] = obj->cvt.sign[BMA255_AXIS_Y]*databuf[BMA255_AXIS_Y];
  976. acc[obj->cvt.map[BMA255_AXIS_Z]] = obj->cvt.sign[BMA255_AXIS_Z]*databuf[BMA255_AXIS_Z];
  977. //printk("cvt x=%d, y=%d, z=%d \n",obj->cvt.sign[BMA255_AXIS_X],obj->cvt.sign[BMA255_AXIS_Y],obj->cvt.sign[BMA255_AXIS_Z]);
  978. //GSE_LOG("Mapped gsensor data: %d, %d, %d!\n", acc[BMA255_AXIS_X], acc[BMA255_AXIS_Y], acc[BMA255_AXIS_Z]);
  979. //Out put the mg
  980. //printk("mg acc=%d, GRAVITY=%d, sensityvity=%d \n",acc[BMA255_AXIS_X],GRAVITY_EARTH_1000,obj->reso->sensitivity);
  981. acc[BMA255_AXIS_X] = acc[BMA255_AXIS_X] * GRAVITY_EARTH_1000 / obj->reso->sensitivity;
  982. acc[BMA255_AXIS_Y] = acc[BMA255_AXIS_Y] * GRAVITY_EARTH_1000 / obj->reso->sensitivity;
  983. acc[BMA255_AXIS_Z] = acc[BMA255_AXIS_Z] * GRAVITY_EARTH_1000 / obj->reso->sensitivity;
  984. sprintf(buf, "%04x %04x %04x", acc[BMA255_AXIS_X], acc[BMA255_AXIS_Y], acc[BMA255_AXIS_Z]);
  985. if(atomic_read(&obj->trace) & BMA_TRC_IOCTL)
  986. {
  987. GSE_LOG("gsensor data: %s!\n", buf);
  988. }
  989. }
  990. return 0;
  991. }
  992. /*----------------------------------------------------------------------------*/
  993. static int BMA255_ReadRawData(struct i2c_client *client, char *buf)
  994. {
  995. //struct bma255_i2c_data *obj = (struct bma255_i2c_data*)i2c_get_clientdata(client);
  996. int res = 0;
  997. s16 databuf[BMA255_AXES_NUM];
  998. if (!buf || !client)
  999. {
  1000. return EINVAL;
  1001. }
  1002. if((res = BMA255_ReadData(client, databuf)))
  1003. {
  1004. GSE_ERR("I2C error: ret value=%d", res);
  1005. return EIO;
  1006. }
  1007. else
  1008. {
  1009. sprintf(buf, "BMA255_ReadRawData %04x %04x %04x", databuf[BMA255_AXIS_X],
  1010. databuf[BMA255_AXIS_Y], databuf[BMA255_AXIS_Z]);
  1011. }
  1012. return 0;
  1013. }
  1014. /*----------------------------------------------------------------------------*/
  1015. static int bma255_set_mode(struct i2c_client *client, unsigned char mode)
  1016. {
  1017. int comres = 0;
  1018. unsigned char data[2] = {0};
  1019. struct bma255_i2c_data *obj = (struct bma255_i2c_data*)i2c_get_clientdata(client);
  1020. if ((client == NULL) || (mode >= 3))
  1021. {
  1022. return -1;
  1023. }
  1024. mutex_lock(&obj->lock);
  1025. comres = bma_i2c_read_block(client,
  1026. BMA255_EN_LOW_POWER__REG, &data[0], 1);
  1027. comres += bma_i2c_read_block(client,
  1028. BMA255_LOW_POWER_CTRL_REG, &data[1], 1);
  1029. switch (mode) {
  1030. case BMA255_MODE_NORMAL:
  1031. data[0] = BMA255_SET_BITSLICE(data[0],
  1032. BMA255_MODE_CTRL, 0);
  1033. data[1] = BMA255_SET_BITSLICE(data[1],
  1034. BMA255_LOW_POWER_MODE, 0);
  1035. comres += bma_i2c_write_block(client,
  1036. BMA255_MODE_CTRL_REG, &data[0], 0x01);
  1037. mdelay(1);
  1038. comres += bma_i2c_write_block(client,
  1039. BMA255_LOW_POWER_CTRL_REG, &data[1], 0x01);
  1040. break;
  1041. case BMA255_MODE_LOWPOWER:
  1042. data[0] = BMA255_SET_BITSLICE(data[0],
  1043. BMA255_MODE_CTRL, 2);
  1044. data[1] = BMA255_SET_BITSLICE(data[1],
  1045. BMA255_LOW_POWER_MODE, 0);
  1046. comres += bma_i2c_write_block(client,
  1047. BMA255_MODE_CTRL_REG, &data[0], 0x01);
  1048. mdelay(1);
  1049. comres += bma_i2c_write_block(client,
  1050. BMA255_LOW_POWER_CTRL_REG, &data[1], 0x01);
  1051. break;
  1052. case BMA255_MODE_SUSPEND:
  1053. data[0] = BMA255_SET_BITSLICE(data[0],
  1054. BMA255_MODE_CTRL, 4);
  1055. data[1] = BMA255_SET_BITSLICE(data[1],
  1056. BMA255_LOW_POWER_MODE, 0);
  1057. comres += bma_i2c_write_block(client,
  1058. BMA255_LOW_POWER_CTRL_REG, &data[1], 0x01);
  1059. mdelay(1);
  1060. comres += bma_i2c_write_block(client,
  1061. BMA255_MODE_CTRL_REG, &data[0], 0x01);
  1062. break;
  1063. default:
  1064. break;
  1065. }
  1066. mutex_unlock(&obj->lock);
  1067. if(comres <= 0)
  1068. {
  1069. return BMA255_ERR_I2C;
  1070. }
  1071. else
  1072. {
  1073. return comres;
  1074. }
  1075. }
  1076. /*----------------------------------------------------------------------------*/
  1077. static int bma255_get_mode(struct i2c_client *client, unsigned char *mode)
  1078. {
  1079. int comres = 0;
  1080. if (client == NULL)
  1081. {
  1082. return -1;
  1083. }
  1084. comres = bma_i2c_read_block(client,
  1085. BMA255_EN_LOW_POWER__REG, mode, 1);
  1086. *mode = (*mode) >> 6;
  1087. return comres;
  1088. }
  1089. /*----------------------------------------------------------------------------*/
  1090. static int bma255_set_range(struct i2c_client *client, unsigned char range)
  1091. {
  1092. int comres = 0;
  1093. unsigned char data[2] = {BMA255_RANGE_SEL__REG};
  1094. struct bma255_i2c_data *obj = (struct bma255_i2c_data*)i2c_get_clientdata(client);
  1095. if (client == NULL)
  1096. {
  1097. return -1;
  1098. }
  1099. mutex_lock(&obj->lock);
  1100. comres = bma_i2c_read_block(client,
  1101. BMA255_RANGE_SEL__REG, data+1, 1);
  1102. data[1] = BMA255_SET_BITSLICE(data[1],
  1103. BMA255_RANGE_SEL, range);
  1104. comres = i2c_master_send(client, data, 2);
  1105. mutex_unlock(&obj->lock);
  1106. if(comres <= 0)
  1107. {
  1108. return BMA255_ERR_I2C;
  1109. }
  1110. else
  1111. {
  1112. return comres;
  1113. }
  1114. }
  1115. /*----------------------------------------------------------------------------*/
  1116. static int bma255_get_range(struct i2c_client *client, unsigned char *range)
  1117. {
  1118. int comres = 0;
  1119. unsigned char data;
  1120. if (client == NULL)
  1121. {
  1122. return -1;
  1123. }
  1124. comres = bma_i2c_read_block(client, BMA255_RANGE_SEL__REG, &data, 1);
  1125. *range = BMA255_GET_BITSLICE(data, BMA255_RANGE_SEL);
  1126. return comres;
  1127. }
  1128. /*----------------------------------------------------------------------------*/
  1129. static int bma255_set_bandwidth(struct i2c_client *client, unsigned char bandwidth)
  1130. {
  1131. int comres = 0;
  1132. unsigned char data[2] = {BMA255_BANDWIDTH__REG};
  1133. struct bma255_i2c_data *obj = (struct bma255_i2c_data*)i2c_get_clientdata(client);
  1134. if (client == NULL)
  1135. {
  1136. return -1;
  1137. }
  1138. mutex_lock(&obj->lock);
  1139. comres = bma_i2c_read_block(client,
  1140. BMA255_BANDWIDTH__REG, data+1, 1);
  1141. data[1] = BMA255_SET_BITSLICE(data[1],
  1142. BMA255_BANDWIDTH, bandwidth);
  1143. comres = i2c_master_send(client, data, 2);
  1144. mutex_unlock(&obj->lock);
  1145. if(comres <= 0)
  1146. {
  1147. return BMA255_ERR_I2C;
  1148. }
  1149. else
  1150. {
  1151. return comres;
  1152. }
  1153. }
  1154. /*----------------------------------------------------------------------------*/
  1155. static int bma255_get_bandwidth(struct i2c_client *client, unsigned char *bandwidth)
  1156. {
  1157. int comres = 0;
  1158. unsigned char data;
  1159. if (client == NULL)
  1160. {
  1161. return -1;
  1162. }
  1163. comres = bma_i2c_read_block(client, BMA255_BANDWIDTH__REG, &data, 1);
  1164. data = BMA255_GET_BITSLICE(data, BMA255_BANDWIDTH);
  1165. if (data < 0x08) //7.81Hz
  1166. {
  1167. *bandwidth = 0x08;
  1168. }
  1169. else if (data > 0x0f) // 1000Hz
  1170. {
  1171. *bandwidth = 0x0f;
  1172. }
  1173. else
  1174. {
  1175. *bandwidth = data;
  1176. }
  1177. return comres;
  1178. }
  1179. /*----------------------------------------------------------------------------*/
  1180. static int bma255_set_fifo_mode(struct i2c_client *client, unsigned char fifo_mode)
  1181. {
  1182. int comres = 0;
  1183. unsigned char data[2] = {BMA255_FIFO_MODE__REG};
  1184. struct bma255_i2c_data *obj = (struct bma255_i2c_data*)i2c_get_clientdata(client);
  1185. if (client == NULL || fifo_mode >= 4)
  1186. {
  1187. return -1;
  1188. }
  1189. mutex_lock(&obj->lock);
  1190. comres = bma_i2c_read_block(client,
  1191. BMA255_FIFO_MODE__REG, data+1, 1);
  1192. data[1] = BMA255_SET_BITSLICE(data[1],
  1193. BMA255_FIFO_MODE, fifo_mode);
  1194. comres = i2c_master_send(client, data, 2);
  1195. mutex_unlock(&obj->lock);
  1196. if(comres <= 0)
  1197. {
  1198. return BMA255_ERR_I2C;
  1199. }
  1200. else
  1201. {
  1202. return comres;
  1203. }
  1204. }
  1205. /*----------------------------------------------------------------------------*/
  1206. static int bma255_get_fifo_mode(struct i2c_client *client, unsigned char *fifo_mode)
  1207. {
  1208. int comres = 0;
  1209. unsigned char data;
  1210. if (client == NULL)
  1211. {
  1212. return -1;
  1213. }
  1214. comres = bma_i2c_read_block(client, BMA255_FIFO_MODE__REG, &data, 1);
  1215. *fifo_mode = BMA255_GET_BITSLICE(data, BMA255_FIFO_MODE);
  1216. return comres;
  1217. }
  1218. static int bma255_get_fifo_framecount(struct i2c_client *client, unsigned char *framecount)
  1219. {
  1220. int comres = 0;
  1221. unsigned char data;
  1222. if (client == NULL)
  1223. {
  1224. return -1;
  1225. }
  1226. comres = bma_i2c_read_block(client, BMA255_FIFO_FRAME_COUNTER_S__REG, &data, 1);
  1227. *framecount = BMA255_GET_BITSLICE(data, BMA255_FIFO_FRAME_COUNTER_S);
  1228. return comres;
  1229. }
  1230. //tad3sgh add++
  1231. // Daemon application save the data
  1232. static int ECS_SaveData(int buf[CALIBRATION_DATA_SIZE])
  1233. {
  1234. #if DEBUG
  1235. struct bma255_i2c_data *data = i2c_get_clientdata(bma255_i2c_client);
  1236. #endif
  1237. mutex_lock(&sensor_data_mutex);
  1238. switch (buf[0])
  1239. {
  1240. case 2: /* SENSOR_HANDLE_MAGNETIC_FIELD */
  1241. memcpy(sensor_data+4, buf+1, 4*sizeof(int));
  1242. break;
  1243. case 3: /* SENSOR_HANDLE_ORIENTATION */
  1244. memcpy(sensor_data+8, buf+1, 4*sizeof(int));
  1245. break;
  1246. #ifdef BMC050_M4G
  1247. case 4: /* SENSOR_HANDLE_GYROSCOPE */
  1248. memcpy(m4g_data, buf+1, 4*sizeof(int));
  1249. break;
  1250. #endif //BMC050_M4G
  1251. #ifdef BMC050_VRV
  1252. case 11: /* SENSOR_HANDLE_ROTATION_VECTOR */
  1253. memcpy(m4g_data+4, buf+1, 4*sizeof(int));
  1254. break;
  1255. #endif //BMC050_VRV
  1256. #ifdef BMC050_VLA
  1257. case 10: /* SENSOR_HANDLE_LINEAR_ACCELERATION */
  1258. memcpy(vla_data, buf+1, 4*sizeof(int));
  1259. break;
  1260. #endif //BMC050_VLA
  1261. #ifdef BMC050_VG
  1262. case 9: /* SENSOR_HANDLE_GRAVITY */
  1263. memcpy(vg_data, buf+1, 4*sizeof(int));
  1264. break;
  1265. #endif //BMC050_VG
  1266. default:
  1267. break;
  1268. }
  1269. mutex_unlock(&sensor_data_mutex);
  1270. #if DEBUG
  1271. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  1272. {
  1273. GSE_LOG("Get daemon data: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d!\n",
  1274. sensor_data[0],sensor_data[1],sensor_data[2],sensor_data[3],
  1275. sensor_data[4],sensor_data[5],sensor_data[6],sensor_data[7],
  1276. sensor_data[8],sensor_data[9],sensor_data[10],sensor_data[11]);
  1277. #if defined(BMC050_M4G) || defined(BMC050_VRV)
  1278. GSE_LOG("Get m4g data: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d!\n",
  1279. m4g_data[0],m4g_data[1],m4g_data[2],m4g_data[3],
  1280. m4g_data[4],m4g_data[5],m4g_data[6],m4g_data[7],
  1281. m4g_data[8],m4g_data[9],m4g_data[10],m4g_data[11]);
  1282. #endif //BMC050_M4G || BMC050_VRV
  1283. #if defined(BMC050_VLA)
  1284. GSE_LOG("Get vla data: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d!\n",
  1285. vla_data[0],vla_data[1],vla_data[2],vla_data[3],
  1286. vla_data[4],vla_data[5],vla_data[6],vla_data[7],
  1287. vla_data[8],vla_data[9],vla_data[10],vla_data[11]);
  1288. #endif //BMC050_VLA
  1289. #if defined(BMC050_VG)
  1290. GSE_LOG("Get vg data: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d!\n",
  1291. vg_data[0],vg_data[1],vg_data[2],vg_data[3],
  1292. vg_data[4],vg_data[5],vg_data[6],vg_data[7],
  1293. vg_data[8],vg_data[9],vg_data[10],vg_data[11]);
  1294. #endif //BMC050_VG
  1295. }
  1296. #endif
  1297. return 0;
  1298. }
  1299. //tad3sgh add--
  1300. /*----------------------------------------------------------------------------*/
  1301. static ssize_t show_chipinfo_value(struct device_driver *ddri, char *buf)
  1302. {
  1303. struct i2c_client *client = bma255_i2c_client;
  1304. char strbuf[BMA255_BUFSIZE];
  1305. if(NULL == client)
  1306. {
  1307. GSE_ERR("i2c client is null!!\n");
  1308. return 0;
  1309. }
  1310. BMA255_ReadChipInfo(client, strbuf, BMA255_BUFSIZE);
  1311. return snprintf(buf, PAGE_SIZE, "%s\n", strbuf);
  1312. }
  1313. /*
  1314. static ssize_t gsensor_init(struct device_driver *ddri, char *buf, size_t count)
  1315. {
  1316. struct i2c_client *client = bma255_i2c_client;
  1317. char strbuf[BMA255_BUFSIZE];
  1318. if(NULL == client)
  1319. {
  1320. GSE_ERR("i2c client is null!!\n");
  1321. return 0;
  1322. }
  1323. bma255_init_client(client, 1);
  1324. return snprintf(buf, PAGE_SIZE, "%s\n", strbuf);
  1325. }
  1326. */
  1327. /*----------------------------------------------------------------------------*/
  1328. /*
  1329. g sensor opmode for compass tilt compensation
  1330. */
  1331. static ssize_t show_cpsopmode_value(struct device_driver *ddri, char *buf)
  1332. {
  1333. unsigned char data;
  1334. if (bma255_get_mode(bma255_i2c_client, &data) < 0)
  1335. {
  1336. return sprintf(buf, "Read error\n");
  1337. }
  1338. else
  1339. {
  1340. return sprintf(buf, "%d\n", data);
  1341. }
  1342. }
  1343. /*----------------------------------------------------------------------------*/
  1344. /*
  1345. g sensor opmode for compass tilt compensation
  1346. */
  1347. static ssize_t store_cpsopmode_value(struct device_driver *ddri, const char *buf, size_t count)
  1348. {
  1349. unsigned long data;
  1350. int error;
  1351. if ((error = kstrtoul(buf, 10, &data)))
  1352. {
  1353. return error;
  1354. }
  1355. if (data == BMA255_MODE_NORMAL)
  1356. {
  1357. BMA255_SetPowerMode(bma255_i2c_client, true);
  1358. }
  1359. else if (data == BMA255_MODE_SUSPEND)
  1360. {
  1361. BMA255_SetPowerMode(bma255_i2c_client, false);
  1362. }
  1363. else if (bma255_set_mode(bma255_i2c_client, (unsigned char) data) < 0)
  1364. {
  1365. GSE_ERR("invalid content: '%s', length = %d\n", buf, (int)count);
  1366. }
  1367. return count;
  1368. }
  1369. /*----------------------------------------------------------------------------*/
  1370. /*
  1371. g sensor range for compass tilt compensation
  1372. */
  1373. static ssize_t show_cpsrange_value(struct device_driver *ddri, char *buf)
  1374. {
  1375. unsigned char data;
  1376. if (bma255_get_range(bma255_i2c_client, &data) < 0)
  1377. {
  1378. return sprintf(buf, "Read error\n");
  1379. }
  1380. else
  1381. {
  1382. return sprintf(buf, "%d\n", data);
  1383. }
  1384. }
  1385. /*----------------------------------------------------------------------------*/
  1386. /*
  1387. g sensor range for compass tilt compensation
  1388. */
  1389. static ssize_t store_cpsrange_value(struct device_driver *ddri, const char *buf, size_t count)
  1390. {
  1391. unsigned long data;
  1392. int error;
  1393. if ((error = kstrtoul(buf, 10, &data)))
  1394. {
  1395. return error;
  1396. }
  1397. if (bma255_set_range(bma255_i2c_client, (unsigned char) data) < 0)
  1398. {
  1399. GSE_ERR("invalid content: '%s', length = %d\n", buf, (int)count);
  1400. }
  1401. return count;
  1402. }
  1403. /*----------------------------------------------------------------------------*/
  1404. /*
  1405. g sensor bandwidth for compass tilt compensation
  1406. */
  1407. static ssize_t show_cpsbandwidth_value(struct device_driver *ddri, char *buf)
  1408. {
  1409. unsigned char data;
  1410. if (bma255_get_bandwidth(bma255_i2c_client, &data) < 0)
  1411. {
  1412. return sprintf(buf, "Read error\n");
  1413. }
  1414. else
  1415. {
  1416. return sprintf(buf, "%d\n", data);
  1417. }
  1418. }
  1419. /*----------------------------------------------------------------------------*/
  1420. /*
  1421. g sensor bandwidth for compass tilt compensation
  1422. */
  1423. static ssize_t store_cpsbandwidth_value(struct device_driver *ddri, const char *buf, size_t count)
  1424. {
  1425. unsigned long data;
  1426. int error;
  1427. if ((error = kstrtoul(buf, 10, &data)))
  1428. {
  1429. return error;
  1430. }
  1431. if (bma255_set_bandwidth(bma255_i2c_client, (unsigned char) data) < 0)
  1432. {
  1433. GSE_ERR("invalid content: '%s', length = %d\n", buf, (int)count);
  1434. }
  1435. return count;
  1436. }
  1437. /*----------------------------------------------------------------------------*/
  1438. /*
  1439. g sensor data for compass tilt compensation
  1440. */
  1441. static ssize_t show_cpsdata_value(struct device_driver *ddri, char *buf)
  1442. {
  1443. struct i2c_client *client = bma255_i2c_client;
  1444. char strbuf[BMA255_BUFSIZE];
  1445. if(NULL == client)
  1446. {
  1447. GSE_ERR("i2c client is null!!\n");
  1448. return 0;
  1449. }
  1450. BMA255_CompassReadData(client, strbuf, BMA255_BUFSIZE);
  1451. return snprintf(buf, PAGE_SIZE, "%s\n", strbuf);
  1452. }
  1453. /*----------------------------------------------------------------------------*/
  1454. static ssize_t show_sensordata_value(struct device_driver *ddri, char *buf)
  1455. {
  1456. struct i2c_client *client = bma255_i2c_client;
  1457. char strbuf[BMA255_BUFSIZE];
  1458. if(NULL == client)
  1459. {
  1460. GSE_ERR("i2c client is null!!\n");
  1461. return 0;
  1462. }
  1463. BMA255_ReadSensorData(client, strbuf, BMA255_BUFSIZE);
  1464. //BMA255_ReadRawData(client, strbuf);
  1465. return snprintf(buf, PAGE_SIZE, "%s\n", strbuf);
  1466. }
  1467. /*----------------------------------------------------------------------------*/
  1468. static ssize_t show_cali_value(struct device_driver *ddri, char *buf)
  1469. {
  1470. struct i2c_client *client = bma255_i2c_client;
  1471. struct bma255_i2c_data *obj;
  1472. int err, len = 0, mul;
  1473. int tmp[BMA255_AXES_NUM];
  1474. if(NULL == client)
  1475. {
  1476. GSE_ERR("i2c client is null!!\n");
  1477. return 0;
  1478. }
  1479. obj = i2c_get_clientdata(client);
  1480. if((err = BMA255_ReadOffset(client, obj->offset)))
  1481. {
  1482. return -EINVAL;
  1483. }
  1484. else if((err = BMA255_ReadCalibration(client, tmp)))
  1485. {
  1486. return -EINVAL;
  1487. }
  1488. else
  1489. {
  1490. mul = obj->reso->sensitivity/bma255_offset_resolution.sensitivity;
  1491. len += snprintf(buf+len, PAGE_SIZE-len, "[HW ][%d] (%+3d, %+3d, %+3d) : (0x%02X, 0x%02X, 0x%02X)\n", mul,
  1492. obj->offset[BMA255_AXIS_X], obj->offset[BMA255_AXIS_Y], obj->offset[BMA255_AXIS_Z],
  1493. obj->offset[BMA255_AXIS_X], obj->offset[BMA255_AXIS_Y], obj->offset[BMA255_AXIS_Z]);
  1494. len += snprintf(buf+len, PAGE_SIZE-len, "[SW ][%d] (%+3d, %+3d, %+3d)\n", 1,
  1495. obj->cali_sw[BMA255_AXIS_X], obj->cali_sw[BMA255_AXIS_Y], obj->cali_sw[BMA255_AXIS_Z]);
  1496. len += snprintf(buf+len, PAGE_SIZE-len, "[ALL] (%+3d, %+3d, %+3d) : (%+3d, %+3d, %+3d)\n",
  1497. obj->offset[BMA255_AXIS_X]*mul + obj->cali_sw[BMA255_AXIS_X],
  1498. obj->offset[BMA255_AXIS_Y]*mul + obj->cali_sw[BMA255_AXIS_Y],
  1499. obj->offset[BMA255_AXIS_Z]*mul + obj->cali_sw[BMA255_AXIS_Z],
  1500. tmp[BMA255_AXIS_X], tmp[BMA255_AXIS_Y], tmp[BMA255_AXIS_Z]);
  1501. return len;
  1502. }
  1503. }
  1504. /*----------------------------------------------------------------------------*/
  1505. static ssize_t store_cali_value(struct device_driver *ddri, const char *buf, size_t count)
  1506. {
  1507. struct i2c_client *client = bma255_i2c_client;
  1508. int err, x, y, z;
  1509. int dat[BMA255_AXES_NUM];
  1510. if(!strncmp(buf, "rst", 3))
  1511. {
  1512. if((err = BMA255_ResetCalibration(client)))
  1513. {
  1514. GSE_ERR("reset offset err = %d\n", err);
  1515. }
  1516. }
  1517. else if(3 == sscanf(buf, "0x%02X 0x%02X 0x%02X", &x, &y, &z))
  1518. {
  1519. dat[BMA255_AXIS_X] = x;
  1520. dat[BMA255_AXIS_Y] = y;
  1521. dat[BMA255_AXIS_Z] = z;
  1522. if((err = BMA255_WriteCalibration(client, dat)))
  1523. {
  1524. GSE_ERR("write calibration err = %d\n", err);
  1525. }
  1526. }
  1527. else
  1528. {
  1529. GSE_ERR("invalid format\n");
  1530. }
  1531. return count;
  1532. }
  1533. /*----------------------------------------------------------------------------*/
  1534. static ssize_t show_firlen_value(struct device_driver *ddri, char *buf)
  1535. {
  1536. #ifdef CONFIG_BMA255_LOWPASS
  1537. struct i2c_client *client = bma255_i2c_client;
  1538. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  1539. if(atomic_read(&obj->firlen))
  1540. {
  1541. int idx, len = atomic_read(&obj->firlen);
  1542. GSE_LOG("len = %2d, idx = %2d\n", obj->fir.num, obj->fir.idx);
  1543. for(idx = 0; idx < len; idx++)
  1544. {
  1545. GSE_LOG("[%5d %5d %5d]\n", obj->fir.raw[idx][BMA255_AXIS_X], obj->fir.raw[idx][BMA255_AXIS_Y], obj->fir.raw[idx][BMA255_AXIS_Z]);
  1546. }
  1547. GSE_LOG("sum = [%5d %5d %5d]\n", obj->fir.sum[BMA255_AXIS_X], obj->fir.sum[BMA255_AXIS_Y], obj->fir.sum[BMA255_AXIS_Z]);
  1548. GSE_LOG("avg = [%5d %5d %5d]\n", obj->fir.sum[BMA255_AXIS_X]/len, obj->fir.sum[BMA255_AXIS_Y]/len, obj->fir.sum[BMA255_AXIS_Z]/len);
  1549. }
  1550. return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&obj->firlen));
  1551. #else
  1552. return snprintf(buf, PAGE_SIZE, "not support\n");
  1553. #endif
  1554. }
  1555. /*----------------------------------------------------------------------------*/
  1556. static ssize_t store_firlen_value(struct device_driver *ddri, const char *buf, size_t count)
  1557. {
  1558. #ifdef CONFIG_BMA255_LOWPASS
  1559. struct i2c_client *client = bma255_i2c_client;
  1560. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  1561. int firlen;
  1562. if(1 != sscanf(buf, "%d", &firlen))
  1563. {
  1564. GSE_ERR("invallid format\n");
  1565. }
  1566. else if(firlen > C_MAX_FIR_LENGTH)
  1567. {
  1568. GSE_ERR("exceeds maximum filter length\n");
  1569. }
  1570. else
  1571. {
  1572. atomic_set(&obj->firlen, firlen);
  1573. if(NULL == firlen)
  1574. {
  1575. atomic_set(&obj->fir_en, 0);
  1576. }
  1577. else
  1578. {
  1579. memset(&obj->fir, 0x00, sizeof(obj->fir));
  1580. atomic_set(&obj->fir_en, 1);
  1581. }
  1582. }
  1583. #endif
  1584. return count;
  1585. }
  1586. /*----------------------------------------------------------------------------*/
  1587. static ssize_t show_trace_value(struct device_driver *ddri, char *buf)
  1588. {
  1589. ssize_t res;
  1590. struct bma255_i2c_data *obj = obj_i2c_data;
  1591. if (obj == NULL)
  1592. {
  1593. GSE_ERR("i2c_data obj is null!!\n");
  1594. return 0;
  1595. }
  1596. res = snprintf(buf, PAGE_SIZE, "0x%04X\n", atomic_read(&obj->trace));
  1597. return res;
  1598. }
  1599. /*----------------------------------------------------------------------------*/
  1600. static ssize_t store_trace_value(struct device_driver *ddri, const char *buf, size_t count)
  1601. {
  1602. struct bma255_i2c_data *obj = obj_i2c_data;
  1603. int trace;
  1604. if (obj == NULL)
  1605. {
  1606. GSE_ERR("i2c_data obj is null!!\n");
  1607. return 0;
  1608. }
  1609. if(1 == sscanf(buf, "0x%x", &trace))
  1610. {
  1611. atomic_set(&obj->trace, trace);
  1612. }
  1613. else
  1614. {
  1615. GSE_ERR("invalid content: '%s', length = %d\n", buf, (int)count);
  1616. }
  1617. return count;
  1618. }
  1619. /*----------------------------------------------------------------------------*/
  1620. static ssize_t show_status_value(struct device_driver *ddri, char *buf)
  1621. {
  1622. ssize_t len = 0;
  1623. struct bma255_i2c_data *obj = obj_i2c_data;
  1624. if (obj == NULL)
  1625. {
  1626. GSE_ERR("i2c_data obj is null!!\n");
  1627. return 0;
  1628. }
  1629. if(obj->hw)
  1630. {
  1631. len += snprintf(buf+len, PAGE_SIZE-len, "CUST: %d %d (%d %d)\n",
  1632. obj->hw->i2c_num, obj->hw->direction, obj->hw->power_id, obj->hw->power_vol);
  1633. }
  1634. else
  1635. {
  1636. len += snprintf(buf+len, PAGE_SIZE-len, "CUST: NULL\n");
  1637. }
  1638. return len;
  1639. }
  1640. /*----------------------------------------------------------------------------*/
  1641. static ssize_t show_power_status_value(struct device_driver *ddri, char *buf)
  1642. {
  1643. if(sensor_power)
  1644. printk("G sensor is in work mode, sensor_power = %d\n", sensor_power);
  1645. else
  1646. printk("G sensor is in standby mode, sensor_power = %d\n", sensor_power);
  1647. return 0;
  1648. }
  1649. /*----------------------------------------------------------------------------*/
  1650. static ssize_t show_fifo_mode_value(struct device_driver *ddri, char *buf)
  1651. {
  1652. unsigned char data;
  1653. if (bma255_get_fifo_mode(bma255_i2c_client, &data) < 0)
  1654. {
  1655. return sprintf(buf, "Read error\n");
  1656. }
  1657. else
  1658. {
  1659. return sprintf(buf, "%d\n", data);
  1660. }
  1661. }
  1662. /*----------------------------------------------------------------------------*/
  1663. static ssize_t store_fifo_mode_value(struct device_driver *ddri, const char *buf, size_t count)
  1664. {
  1665. unsigned long data;
  1666. int error;
  1667. if ((error = kstrtoul(buf, 10, &data)))
  1668. {
  1669. return error;
  1670. }
  1671. if (bma255_set_fifo_mode(bma255_i2c_client, (unsigned char) data) < 0)
  1672. {
  1673. GSE_ERR("invalid content: '%s', length = %d\n", buf, (int)count);
  1674. }
  1675. return count;
  1676. }
  1677. /*----------------------------------------------------------------------------*/
  1678. static ssize_t show_fifo_framecount_value(struct device_driver *ddri, char *buf)
  1679. {
  1680. unsigned char data;
  1681. if (bma255_get_fifo_framecount(bma255_i2c_client, &data) < 0)
  1682. {
  1683. return sprintf(buf, "Read error\n");
  1684. }
  1685. else
  1686. {
  1687. return sprintf(buf, "%d\n", data);
  1688. }
  1689. }
  1690. /*----------------------------------------------------------------------------*/
  1691. static ssize_t store_fifo_framecount_value(struct device_driver *ddri, const char *buf, size_t count)
  1692. {
  1693. unsigned long data;
  1694. int error;
  1695. struct bma255_i2c_data *obj = obj_i2c_data;
  1696. if ((error = kstrtoul(buf, 10, &data)))
  1697. {
  1698. return error;
  1699. }
  1700. mutex_lock(&obj->lock);
  1701. obj->fifo_count = (unsigned char)data;
  1702. mutex_unlock(&obj->lock);
  1703. return count;
  1704. }
  1705. /*----------------------------------------------------------------------------*/
  1706. static ssize_t show_fifo_data_out_frame_value(struct device_driver *ddri, char *buf)
  1707. {
  1708. int err = 0, i, len = 0;
  1709. // int addr = 0;
  1710. u8 fifo_data_out[MAX_FIFO_F_BYTES] = {0};
  1711. /* Select X Y Z axis data output for every fifo frame, not single axis data */
  1712. unsigned char f_len = 6;/* FIXME: ONLY USE 3-AXIS */
  1713. struct bma255_i2c_data *obj = obj_i2c_data;
  1714. s16 acc[BMA255_AXES_NUM];
  1715. s16 databuf[BMA255_AXES_NUM];
  1716. if (obj->fifo_count == 0) {
  1717. return -EINVAL;
  1718. }
  1719. for (i = 0; i < obj->fifo_count; i++) {
  1720. if (bma_i2c_read_block(bma255_i2c_client,BMA255_FIFO_DATA_OUTPUT_REG, fifo_data_out, f_len) < 0)
  1721. {
  1722. GSE_ERR("[a]fatal error\n");
  1723. return sprintf(buf, "Read byte block error\n");
  1724. }
  1725. /*data combination*/
  1726. databuf[BMA255_AXIS_X] = ((s16)(((u16)fifo_data_out[1] << 8) |
  1727. (u16)fifo_data_out[0])) >> 6;
  1728. databuf[BMA255_AXIS_Y] = ((s16)(((u16)fifo_data_out[3] << 8) |
  1729. (u16)fifo_data_out[2])) >> 6;
  1730. databuf[BMA255_AXIS_Z] = ((s16)(((u16)fifo_data_out[5] << 8) |
  1731. (u16)fifo_data_out[4])) >> 6;
  1732. /*axis remap*/
  1733. acc[obj->cvt.map[BMA255_AXIS_X]] = obj->cvt.sign[BMA255_AXIS_X]*databuf[BMA255_AXIS_X];
  1734. acc[obj->cvt.map[BMA255_AXIS_Y]] = obj->cvt.sign[BMA255_AXIS_Y]*databuf[BMA255_AXIS_Y];
  1735. acc[obj->cvt.map[BMA255_AXIS_Z]] = obj->cvt.sign[BMA255_AXIS_Z]*databuf[BMA255_AXIS_Z];
  1736. len = sprintf(buf, "%d %d %d ", acc[BMA255_AXIS_X], acc[BMA255_AXIS_Y], acc[BMA255_AXIS_Z]);
  1737. buf += len;
  1738. err += len;
  1739. }
  1740. return err;
  1741. }
  1742. /*----------------------------------------------------------------------------*/
  1743. static DRIVER_ATTR(chipinfo, S_IWUSR | S_IRUGO, show_chipinfo_value, NULL);
  1744. static DRIVER_ATTR(cpsdata, S_IWUSR | S_IRUGO, show_cpsdata_value, NULL);
  1745. static DRIVER_ATTR(cpsopmode, S_IWUSR | S_IRUGO, show_cpsopmode_value, store_cpsopmode_value);
  1746. static DRIVER_ATTR(cpsrange, S_IWUSR | S_IRUGO, show_cpsrange_value, store_cpsrange_value);
  1747. static DRIVER_ATTR(cpsbandwidth, S_IWUSR | S_IRUGO, show_cpsbandwidth_value, store_cpsbandwidth_value);
  1748. static DRIVER_ATTR(sensordata, S_IWUSR | S_IRUGO, show_sensordata_value, NULL);
  1749. static DRIVER_ATTR(cali, S_IWUSR | S_IRUGO, show_cali_value, store_cali_value);
  1750. static DRIVER_ATTR(firlen, S_IWUSR | S_IRUGO, show_firlen_value, store_firlen_value);
  1751. static DRIVER_ATTR(trace, S_IWUSR | S_IRUGO, show_trace_value, store_trace_value);
  1752. static DRIVER_ATTR(status, S_IRUGO, show_status_value, NULL);
  1753. static DRIVER_ATTR(powerstatus, S_IRUGO, show_power_status_value, NULL);
  1754. static DRIVER_ATTR(fifo_mode, S_IWUSR | S_IRUGO, show_fifo_mode_value, store_fifo_mode_value);
  1755. static DRIVER_ATTR(fifo_framecount, S_IWUSR | S_IRUGO, show_fifo_framecount_value, store_fifo_framecount_value);
  1756. static DRIVER_ATTR(fifo_data_frame, S_IRUGO, show_fifo_data_out_frame_value, NULL);
  1757. /*----------------------------------------------------------------------------*/
  1758. static struct driver_attribute *bma255_attr_list[] = {
  1759. &driver_attr_chipinfo, /*chip information*/
  1760. &driver_attr_sensordata, /*dump sensor data*/
  1761. &driver_attr_cali, /*show calibration data*/
  1762. &driver_attr_firlen, /*filter length: 0: disable, others: enable*/
  1763. &driver_attr_trace, /*trace log*/
  1764. &driver_attr_status,
  1765. &driver_attr_powerstatus,
  1766. &driver_attr_cpsdata, /*g sensor data for compass tilt compensation*/
  1767. &driver_attr_cpsopmode, /*g sensor opmode for compass tilt compensation*/
  1768. &driver_attr_cpsrange, /*g sensor range for compass tilt compensation*/
  1769. &driver_attr_cpsbandwidth, /*g sensor bandwidth for compass tilt compensation*/
  1770. &driver_attr_fifo_mode,
  1771. &driver_attr_fifo_framecount,
  1772. &driver_attr_fifo_data_frame,
  1773. };
  1774. /*----------------------------------------------------------------------------*/
  1775. static int bma255_create_attr(struct device_driver *driver)
  1776. {
  1777. int idx, err = 0;
  1778. int num = (int)(sizeof(bma255_attr_list)/sizeof(bma255_attr_list[0]));
  1779. if (driver == NULL)
  1780. {
  1781. return -EINVAL;
  1782. }
  1783. for(idx = 0; idx < num; idx++)
  1784. {
  1785. if((err = driver_create_file(driver, bma255_attr_list[idx])))
  1786. {
  1787. GSE_ERR("driver_create_file (%s) = %d\n", bma255_attr_list[idx]->attr.name, err);
  1788. break;
  1789. }
  1790. }
  1791. return err;
  1792. }
  1793. /*----------------------------------------------------------------------------*/
  1794. static int bma255_delete_attr(struct device_driver *driver)
  1795. {
  1796. int idx ,err = 0;
  1797. int num = (int)(sizeof(bma255_attr_list)/sizeof(bma255_attr_list[0]));
  1798. if(driver == NULL)
  1799. {
  1800. return -EINVAL;
  1801. }
  1802. for(idx = 0; idx < num; idx++)
  1803. {
  1804. driver_remove_file(driver, bma255_attr_list[idx]);
  1805. }
  1806. return err;
  1807. }
  1808. /*----------------------------------------------------------------------------*/
  1809. #ifdef BMC050_M4G
  1810. int bmm050_m4g_operate(void* self, uint32_t command, void* buff_in, int size_in,
  1811. void* buff_out, int size_out, int* actualout)
  1812. {
  1813. int err = 0;
  1814. int value;
  1815. struct hwm_sensor_data* g_data;
  1816. #if DEBUG
  1817. //struct i2c_client *client = bma255_i2c_client;
  1818. struct bma255_i2c_data *data = i2c_get_clientdata(bma255_i2c_client);
  1819. #endif
  1820. #if DEBUG
  1821. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  1822. {
  1823. GSE_FUN();
  1824. }
  1825. #endif
  1826. switch (command)
  1827. {
  1828. case SENSOR_DELAY:
  1829. if((buff_in == NULL) || (size_in < sizeof(int)))
  1830. {
  1831. GSE_ERR( "Set delay parameter error!\n");
  1832. err = -EINVAL;
  1833. }
  1834. else
  1835. {
  1836. value = *(int *)buff_in;
  1837. m4g_delay = value;
  1838. /* set the flag */
  1839. mutex_lock(&uplink_event_flag_mutex);
  1840. uplink_event_flag |= BMMDRV_ULEVT_FLAG_G_DELAY;
  1841. mutex_unlock(&uplink_event_flag_mutex);
  1842. /* wake up the wait queue */
  1843. wake_up(&uplink_event_flag_wq);
  1844. }
  1845. break;
  1846. case SENSOR_ENABLE:
  1847. if((buff_in == NULL) || (size_in < sizeof(int)))
  1848. {
  1849. GSE_ERR( "Enable sensor parameter error!\n");
  1850. err = -EINVAL;
  1851. }
  1852. else
  1853. {
  1854. value = *(int *)buff_in;
  1855. if(value == 1)
  1856. {
  1857. atomic_set(&g_flag, 1);
  1858. }
  1859. else
  1860. {
  1861. atomic_set(&g_flag, 0);
  1862. }
  1863. /* set the flag */
  1864. mutex_lock(&uplink_event_flag_mutex);
  1865. uplink_event_flag |= BMMDRV_ULEVT_FLAG_G_ACTIVE;
  1866. mutex_unlock(&uplink_event_flag_mutex);
  1867. /* wake up the wait queue */
  1868. wake_up(&uplink_event_flag_wq);
  1869. }
  1870. break;
  1871. case SENSOR_GET_DATA:
  1872. if((buff_out == NULL) || (size_out< sizeof(struct hwm_sensor_data)))
  1873. {
  1874. GSE_ERR( "get sensor data parameter error!\n");
  1875. err = -EINVAL;
  1876. }
  1877. else
  1878. {
  1879. g_data = (struct hwm_sensor_data *)buff_out;
  1880. mutex_lock(&sensor_data_mutex);
  1881. g_data->values[0] = m4g_data[0];
  1882. g_data->values[1] = m4g_data[1];
  1883. g_data->values[2] = m4g_data[2];
  1884. g_data->status = m4g_data[3];
  1885. g_data->value_divide = CONVERT_G_DIV;
  1886. mutex_unlock(&sensor_data_mutex);
  1887. #if DEBUG
  1888. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  1889. {
  1890. GSE_LOG("Hwm get m4g data: %d, %d, %d. divide %d, status %d!\n",
  1891. g_data->values[0],g_data->values[1],g_data->values[2],
  1892. g_data->value_divide,g_data->status);
  1893. }
  1894. #endif
  1895. }
  1896. break;
  1897. default:
  1898. GSE_ERR( "m4g operate function no this parameter %d!\n", command);
  1899. err = -1;
  1900. break;
  1901. }
  1902. return err;
  1903. }
  1904. #endif //BMC050_M4G
  1905. /*----------------------------------------------------------------------------*/
  1906. #ifdef BMC050_VRV
  1907. int bmm050_vrv_operate(void* self, uint32_t command, void* buff_in, int size_in,
  1908. void* buff_out, int size_out, int* actualout)
  1909. {
  1910. int err = 0;
  1911. int value;
  1912. struct hwm_sensor_data* vrv_data;
  1913. #if DEBUG
  1914. // struct i2c_client *client = bma255_i2c_client;
  1915. struct bma255_i2c_data *data = i2c_get_clientdata(bma255_i2c_client);
  1916. #endif
  1917. #if DEBUG
  1918. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  1919. {
  1920. GSE_FUN();
  1921. }
  1922. #endif
  1923. switch (command)
  1924. {
  1925. case SENSOR_DELAY:
  1926. if((buff_in == NULL) || (size_in < sizeof(int)))
  1927. {
  1928. GSE_ERR( "Set delay parameter error!\n");
  1929. err = -EINVAL;
  1930. }
  1931. else
  1932. {
  1933. value = *(int *)buff_in;
  1934. vrv_delay = value;
  1935. /* set the flag */
  1936. mutex_lock(&uplink_event_flag_mutex);
  1937. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VRV_DELAY;
  1938. mutex_unlock(&uplink_event_flag_mutex);
  1939. /* wake up the wait queue */
  1940. wake_up(&uplink_event_flag_wq);
  1941. }
  1942. break;
  1943. case SENSOR_ENABLE:
  1944. if((buff_in == NULL) || (size_in < sizeof(int)))
  1945. {
  1946. GSE_ERR( "Enable sensor parameter error!\n");
  1947. err = -EINVAL;
  1948. }
  1949. else
  1950. {
  1951. value = *(int *)buff_in;
  1952. if(value == 1)
  1953. {
  1954. atomic_set(&vrv_flag, 1);
  1955. }
  1956. else
  1957. {
  1958. atomic_set(&vrv_flag, 0);
  1959. }
  1960. /* set the flag */
  1961. mutex_lock(&uplink_event_flag_mutex);
  1962. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VRV_ACTIVE;
  1963. mutex_unlock(&uplink_event_flag_mutex);
  1964. /* wake up the wait queue */
  1965. wake_up(&uplink_event_flag_wq);
  1966. }
  1967. break;
  1968. case SENSOR_GET_DATA:
  1969. if((buff_out == NULL) || (size_out< sizeof(struct hwm_sensor_data)))
  1970. {
  1971. GSE_ERR( "get sensor data parameter error!\n");
  1972. err = -EINVAL;
  1973. }
  1974. else
  1975. {
  1976. vrv_data = (struct hwm_sensor_data *)buff_out;
  1977. mutex_lock(&sensor_data_mutex);
  1978. vrv_data->values[0] = m4g_data[4];
  1979. vrv_data->values[1] = m4g_data[5];
  1980. vrv_data->values[2] = m4g_data[6];
  1981. vrv_data->status = m4g_data[7];
  1982. vrv_data->value_divide = CONVERT_VRV_DIV;
  1983. mutex_unlock(&sensor_data_mutex);
  1984. #if DEBUG
  1985. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  1986. {
  1987. GSE_LOG("Hwm get rotation vector data: %d, %d, %d. divide %d, status %d!\n",
  1988. vrv_data->values[0],vrv_data->values[1],vrv_data->values[2],
  1989. vrv_data->value_divide,vrv_data->status);
  1990. }
  1991. #endif
  1992. }
  1993. break;
  1994. default:
  1995. GSE_ERR( "rotation vector operate function no this parameter %d!\n", command);
  1996. err = -1;
  1997. break;
  1998. }
  1999. return err;
  2000. }
  2001. #endif //BMC050_VRV
  2002. /*----------------------------------------------------------------------------*/
  2003. #ifdef BMC050_VLA
  2004. int bmm050_vla_operate(void* self, uint32_t command, void* buff_in, int size_in,
  2005. void* buff_out, int size_out, int* actualout)
  2006. {
  2007. int err = 0;
  2008. int value;
  2009. struct hwm_sensor_data* vla_value;
  2010. #if DEBUG
  2011. // struct i2c_client *client = bma255_i2c_client;
  2012. struct bma255_i2c_data *data = i2c_get_clientdata(bma255_i2c_client);
  2013. #endif
  2014. #if DEBUG
  2015. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  2016. {
  2017. GSE_FUN();
  2018. }
  2019. #endif
  2020. switch (command)
  2021. {
  2022. case SENSOR_DELAY:
  2023. if((buff_in == NULL) || (size_in < sizeof(int)))
  2024. {
  2025. GSE_ERR( "Set delay parameter error!\n");
  2026. err = -EINVAL;
  2027. }
  2028. else
  2029. {
  2030. value = *(int *)buff_in;
  2031. vla_delay = value;
  2032. /* set the flag */
  2033. mutex_lock(&uplink_event_flag_mutex);
  2034. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VLA_DELAY;
  2035. mutex_unlock(&uplink_event_flag_mutex);
  2036. /* wake up the wait queue */
  2037. wake_up(&uplink_event_flag_wq);
  2038. }
  2039. break;
  2040. case SENSOR_ENABLE:
  2041. if((buff_in == NULL) || (size_in < sizeof(int)))
  2042. {
  2043. GSE_ERR( "Enable sensor parameter error!\n");
  2044. err = -EINVAL;
  2045. }
  2046. else
  2047. {
  2048. value = *(int *)buff_in;
  2049. if(value == 1)
  2050. {
  2051. atomic_set(&vla_flag, 1);
  2052. }
  2053. else
  2054. {
  2055. atomic_set(&vla_flag, 0);
  2056. }
  2057. /* set the flag */
  2058. mutex_lock(&uplink_event_flag_mutex);
  2059. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VLA_ACTIVE;
  2060. mutex_unlock(&uplink_event_flag_mutex);
  2061. /* wake up the wait queue */
  2062. wake_up(&uplink_event_flag_wq);
  2063. }
  2064. break;
  2065. case SENSOR_GET_DATA:
  2066. if((buff_out == NULL) || (size_out< sizeof(struct hwm_sensor_data)))
  2067. {
  2068. GSE_ERR( "get sensor data parameter error!\n");
  2069. err = -EINVAL;
  2070. }
  2071. else
  2072. {
  2073. vla_value = (struct hwm_sensor_data *)buff_out;
  2074. mutex_lock(&sensor_data_mutex);
  2075. vla_value->values[0] = vla_data[0];
  2076. vla_value->values[1] = vla_data[1];
  2077. vla_value->values[2] = vla_data[2];
  2078. vla_value->status = vla_data[3];
  2079. vla_value->value_divide = CONVERT_VLA_DIV;
  2080. mutex_unlock(&sensor_data_mutex);
  2081. #if DEBUG
  2082. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  2083. {
  2084. GSE_LOG("Hwm get virtual linear accelerometer data: %d, %d, %d. divide %d, status %d!\n",
  2085. vla_value->values[0],vla_value->values[1],vla_value->values[2],
  2086. vla_value->value_divide,vla_value->status);
  2087. }
  2088. #endif
  2089. }
  2090. break;
  2091. default:
  2092. GSE_ERR( "virtual linear accelerometer operate function no this parameter %d!\n", command);
  2093. err = -1;
  2094. break;
  2095. }
  2096. return err;
  2097. }
  2098. #endif //BMC050_VLA
  2099. /*----------------------------------------------------------------------------*/
  2100. #ifdef BMC050_VG
  2101. int bmm050_vg_operate(void* self, uint32_t command, void* buff_in, int size_in,
  2102. void* buff_out, int size_out, int* actualout)
  2103. {
  2104. int err = 0;
  2105. int value;
  2106. struct hwm_sensor_data* vg_value;
  2107. #if DEBUG
  2108. // struct i2c_client *client = bma255_i2c_client;
  2109. struct bma255_i2c_data *data = i2c_get_clientdata(bma255_i2c_client);
  2110. #endif
  2111. #if DEBUG
  2112. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  2113. {
  2114. GSE_FUN();
  2115. }
  2116. #endif
  2117. switch (command)
  2118. {
  2119. case SENSOR_DELAY:
  2120. if((buff_in == NULL) || (size_in < sizeof(int)))
  2121. {
  2122. GSE_ERR( "Set delay parameter error!\n");
  2123. err = -EINVAL;
  2124. }
  2125. else
  2126. {
  2127. value = *(int *)buff_in;
  2128. vg_delay = value;
  2129. /* set the flag */
  2130. mutex_lock(&uplink_event_flag_mutex);
  2131. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VG_DELAY;
  2132. mutex_unlock(&uplink_event_flag_mutex);
  2133. /* wake up the wait queue */
  2134. wake_up(&uplink_event_flag_wq);
  2135. }
  2136. break;
  2137. case SENSOR_ENABLE:
  2138. if((buff_in == NULL) || (size_in < sizeof(int)))
  2139. {
  2140. GSE_ERR( "Enable sensor parameter error!\n");
  2141. err = -EINVAL;
  2142. }
  2143. else
  2144. {
  2145. value = *(int *)buff_in;
  2146. if(value == 1)
  2147. {
  2148. atomic_set(&vg_flag, 1);
  2149. }
  2150. else
  2151. {
  2152. atomic_set(&vg_flag, 0);
  2153. }
  2154. /* set the flag */
  2155. mutex_lock(&uplink_event_flag_mutex);
  2156. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VG_ACTIVE;
  2157. mutex_unlock(&uplink_event_flag_mutex);
  2158. /* wake up the wait queue */
  2159. wake_up(&uplink_event_flag_wq);
  2160. }
  2161. break;
  2162. case SENSOR_GET_DATA:
  2163. if((buff_out == NULL) || (size_out< sizeof(struct hwm_sensor_data)))
  2164. {
  2165. GSE_ERR( "get sensor data parameter error!\n");
  2166. err = -EINVAL;
  2167. }
  2168. else
  2169. {
  2170. vg_value = (struct hwm_sensor_data *)buff_out;
  2171. mutex_lock(&sensor_data_mutex);
  2172. vg_value->values[0] = vg_data[0];
  2173. vg_value->values[1] = vg_data[1];
  2174. vg_value->values[2] = vg_data[2];
  2175. vg_value->status = vg_data[3];
  2176. vg_value->value_divide = CONVERT_VG_DIV;
  2177. mutex_unlock(&sensor_data_mutex);
  2178. #if DEBUG
  2179. if(atomic_read(&data->trace) & BMA_TRC_INFO)
  2180. {
  2181. GSE_LOG("Hwm get virtual gravity data: %d, %d, %d. divide %d, status %d!\n",
  2182. vg_value->values[0],vg_value->values[1],vg_value->values[2],
  2183. vg_value->value_divide,vg_value->status);
  2184. }
  2185. #endif
  2186. }
  2187. break;
  2188. default:
  2189. GSE_ERR( "virtual gravity operate function no this parameter %d!\n", command);
  2190. err = -1;
  2191. break;
  2192. }
  2193. return err;
  2194. }
  2195. #endif //BMC050_VG
  2196. //tad3sgh add --
  2197. /******************************************************************************
  2198. * Function Configuration
  2199. ******************************************************************************/
  2200. static int bma255_open(struct inode *inode, struct file *file)
  2201. {
  2202. file->private_data = bma255_i2c_client;
  2203. if(file->private_data == NULL)
  2204. {
  2205. GSE_ERR("null pointer!!\n");
  2206. return -EINVAL;
  2207. }
  2208. return nonseekable_open(inode, file);
  2209. }
  2210. /*----------------------------------------------------------------------------*/
  2211. static int bma255_release(struct inode *inode, struct file *file)
  2212. {
  2213. file->private_data = NULL;
  2214. return 0;
  2215. }
  2216. /*----------------------------------------------------------------------------*/
  2217. static long bma255_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  2218. {
  2219. struct i2c_client *client = (struct i2c_client*)file->private_data;
  2220. struct bma255_i2c_data *obj = (struct bma255_i2c_data*)i2c_get_clientdata(client);
  2221. char strbuf[BMA255_BUFSIZE];
  2222. void __user *data;
  2223. struct SENSOR_DATA sensor_data;
  2224. long err = 0;
  2225. int cali[3];
  2226. //tad3sgh add ++
  2227. int status; /* for OPEN/CLOSE_STATUS */
  2228. short sensor_status; /* for Orientation and Msensor status */
  2229. int value[CALIBRATION_DATA_SIZE]; /* for SET_YPR */
  2230. //tad3sgh add --
  2231. //GSE_FUN(f);
  2232. if(_IOC_DIR(cmd) & _IOC_READ)
  2233. {
  2234. err = !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd));
  2235. }
  2236. else if(_IOC_DIR(cmd) & _IOC_WRITE)
  2237. {
  2238. err = !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd));
  2239. }
  2240. if(err)
  2241. {
  2242. GSE_ERR("access error: %08X, (%2d, %2d)\n", cmd, _IOC_DIR(cmd), _IOC_SIZE(cmd));
  2243. return -EFAULT;
  2244. }
  2245. switch(cmd)
  2246. {
  2247. case GSENSOR_IOCTL_INIT:
  2248. bma255_init_client(client, 0);
  2249. break;
  2250. case GSENSOR_IOCTL_READ_CHIPINFO:
  2251. data = (void __user *) arg;
  2252. if(data == NULL)
  2253. {
  2254. err = -EINVAL;
  2255. break;
  2256. }
  2257. BMA255_ReadChipInfo(client, strbuf, BMA255_BUFSIZE);
  2258. if(copy_to_user(data, strbuf, strlen(strbuf)+1))
  2259. {
  2260. err = -EFAULT;
  2261. break;
  2262. }
  2263. break;
  2264. case GSENSOR_IOCTL_READ_SENSORDATA:
  2265. data = (void __user *) arg;
  2266. if(data == NULL)
  2267. {
  2268. err = -EINVAL;
  2269. break;
  2270. }
  2271. BMA255_ReadSensorData(client, strbuf, BMA255_BUFSIZE);
  2272. if(copy_to_user(data, strbuf, strlen(strbuf)+1))
  2273. {
  2274. err = -EFAULT;
  2275. break;
  2276. }
  2277. break;
  2278. case GSENSOR_IOCTL_READ_GAIN:
  2279. data = (void __user *) arg;
  2280. if(data == NULL)
  2281. {
  2282. err = -EINVAL;
  2283. break;
  2284. }
  2285. if(copy_to_user(data, &gsensor_gain, sizeof(struct GSENSOR_VECTOR3D)))
  2286. {
  2287. err = -EFAULT;
  2288. break;
  2289. }
  2290. break;
  2291. case GSENSOR_IOCTL_READ_RAW_DATA:
  2292. data = (void __user *) arg;
  2293. if(data == NULL)
  2294. {
  2295. err = -EINVAL;
  2296. break;
  2297. }
  2298. BMA255_ReadRawData(client, strbuf);
  2299. if(copy_to_user(data, &strbuf, strlen(strbuf)+1))
  2300. {
  2301. err = -EFAULT;
  2302. break;
  2303. }
  2304. break;
  2305. case GSENSOR_IOCTL_SET_CALI:
  2306. data = (void __user*)arg;
  2307. if(data == NULL)
  2308. {
  2309. err = -EINVAL;
  2310. break;
  2311. }
  2312. if(copy_from_user(&sensor_data, data, sizeof(sensor_data)))
  2313. {
  2314. err = -EFAULT;
  2315. break;
  2316. }
  2317. if(atomic_read(&obj->suspend))
  2318. {
  2319. GSE_ERR("Perform calibration in suspend state!!\n");
  2320. err = -EINVAL;
  2321. }
  2322. else
  2323. {
  2324. cali[BMA255_AXIS_X] = sensor_data.x * obj->reso->sensitivity / GRAVITY_EARTH_1000;
  2325. cali[BMA255_AXIS_Y] = sensor_data.y * obj->reso->sensitivity / GRAVITY_EARTH_1000;
  2326. cali[BMA255_AXIS_Z] = sensor_data.z * obj->reso->sensitivity / GRAVITY_EARTH_1000;
  2327. err = BMA255_WriteCalibration(client, cali);
  2328. }
  2329. break;
  2330. case GSENSOR_IOCTL_CLR_CALI:
  2331. err = BMA255_ResetCalibration(client);
  2332. break;
  2333. case GSENSOR_IOCTL_GET_CALI:
  2334. data = (void __user*)arg;
  2335. if(data == NULL)
  2336. {
  2337. err = -EINVAL;
  2338. break;
  2339. }
  2340. if((err = BMA255_ReadCalibration(client, cali)))
  2341. {
  2342. break;
  2343. }
  2344. sensor_data.x = cali[BMA255_AXIS_X] * GRAVITY_EARTH_1000 / obj->reso->sensitivity;
  2345. sensor_data.y = cali[BMA255_AXIS_Y] * GRAVITY_EARTH_1000 / obj->reso->sensitivity;
  2346. sensor_data.z = cali[BMA255_AXIS_Z] * GRAVITY_EARTH_1000 / obj->reso->sensitivity;
  2347. if(copy_to_user(data, &sensor_data, sizeof(sensor_data)))
  2348. {
  2349. err = -EFAULT;
  2350. break;
  2351. }
  2352. break;
  2353. //tad3sgh add ++
  2354. case BMM_IOC_GET_EVENT_FLAG: // used by daemon only
  2355. data = (void __user *) arg;
  2356. /* block if no event updated */
  2357. wait_event_interruptible(uplink_event_flag_wq, (uplink_event_flag != 0));
  2358. mutex_lock(&uplink_event_flag_mutex);
  2359. status = uplink_event_flag;
  2360. mutex_unlock(&uplink_event_flag_mutex);
  2361. if(copy_to_user(data, &status, sizeof(status)))
  2362. {
  2363. GSE_ERR("copy_to_user failed.");
  2364. return -EFAULT;
  2365. }
  2366. break;
  2367. case BMM_IOC_GET_NONBLOCK_EVENT_FLAG: // used by daemon only
  2368. data = (void __user *) arg;
  2369. /* nonblock daemon process */
  2370. //wait_event_interruptible(uplink_event_flag_wq, (uplink_event_flag != 0));
  2371. mutex_lock(&uplink_event_flag_mutex);
  2372. status = uplink_event_flag;
  2373. mutex_unlock(&uplink_event_flag_mutex);
  2374. if(copy_to_user(data, &status, sizeof(status)))
  2375. {
  2376. GSE_ERR("copy_to_user failed.");
  2377. return -EFAULT;
  2378. }
  2379. break;
  2380. case ECOMPASS_IOC_GET_DELAY: //used by daemon
  2381. data = (void __user *) arg;
  2382. if(copy_to_user(data, &bmm050d_delay, sizeof(bmm050d_delay)))
  2383. {
  2384. GSE_ERR("copy_to_user failed.");
  2385. return -EFAULT;
  2386. }
  2387. /* clear the flag */
  2388. mutex_lock(&uplink_event_flag_mutex);
  2389. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_M_DELAY) != 0)
  2390. {
  2391. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_M_DELAY;
  2392. }
  2393. else if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_O_DELAY) != 0)
  2394. {
  2395. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_O_DELAY;
  2396. }
  2397. mutex_unlock(&uplink_event_flag_mutex);
  2398. /* wake up the wait queue */
  2399. wake_up(&uplink_event_flag_wq);
  2400. break;
  2401. case ECOMPASS_IOC_SET_YPR: //used by daemon
  2402. data = (void __user *) arg;
  2403. if(data == NULL)
  2404. {
  2405. GSE_ERR("invalid argument.");
  2406. return -EINVAL;
  2407. }
  2408. if(copy_from_user(value, data, sizeof(value)))
  2409. {
  2410. GSE_ERR("copy_from_user failed.");
  2411. return -EFAULT;
  2412. }
  2413. ECS_SaveData(value);
  2414. break;
  2415. case ECOMPASS_IOC_GET_MFLAG: //used by daemon
  2416. data = (void __user *) arg;
  2417. sensor_status = atomic_read(&m_flag);
  2418. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2419. if ((sensor_status == 1) && (atomic_read(&driver_suspend_flag) == 1))
  2420. {
  2421. /* de-active m-channel when driver suspend regardless of m_flag*/
  2422. sensor_status = 0;
  2423. }
  2424. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2425. if(copy_to_user(data, &sensor_status, sizeof(sensor_status)))
  2426. {
  2427. GSE_ERR("copy_to_user failed.");
  2428. return -EFAULT;
  2429. }
  2430. /* clear the flag */
  2431. mutex_lock(&uplink_event_flag_mutex);
  2432. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_M_ACTIVE) != 0)
  2433. {
  2434. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_M_ACTIVE;
  2435. }
  2436. mutex_unlock(&uplink_event_flag_mutex);
  2437. /* wake up the wait queue */
  2438. wake_up(&uplink_event_flag_wq);
  2439. break;
  2440. case ECOMPASS_IOC_GET_OFLAG: //used by daemon
  2441. data = (void __user *) arg;
  2442. sensor_status = atomic_read(&o_flag);
  2443. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2444. if ((sensor_status == 1) && (atomic_read(&driver_suspend_flag) == 1))
  2445. {
  2446. /* de-active m-channel when driver suspend regardless of m_flag*/
  2447. sensor_status = 0;
  2448. }
  2449. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2450. if(copy_to_user(data, &sensor_status, sizeof(sensor_status)))
  2451. {
  2452. GSE_ERR("copy_to_user failed.");
  2453. return -EFAULT;
  2454. }
  2455. /* clear the flag */
  2456. mutex_lock(&uplink_event_flag_mutex);
  2457. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_O_ACTIVE) != 0)
  2458. {
  2459. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_O_ACTIVE;
  2460. }
  2461. mutex_unlock(&uplink_event_flag_mutex);
  2462. /* wake up the wait queue */
  2463. wake_up(&uplink_event_flag_wq);
  2464. break;
  2465. #ifdef BMC050_M4G
  2466. case ECOMPASS_IOC_GET_GDELAY: //used by daemon
  2467. data = (void __user *) arg;
  2468. if(copy_to_user(data, &m4g_delay, sizeof(m4g_delay)))
  2469. {
  2470. GSE_ERR("copy_to_user failed.");
  2471. return -EFAULT;
  2472. }
  2473. /* clear the flag */
  2474. mutex_lock(&uplink_event_flag_mutex);
  2475. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_G_DELAY) != 0)
  2476. {
  2477. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_G_DELAY;
  2478. }
  2479. mutex_unlock(&uplink_event_flag_mutex);
  2480. /* wake up the wait queue */
  2481. wake_up(&uplink_event_flag_wq);
  2482. break;
  2483. case ECOMPASS_IOC_GET_GFLAG: //used by daemon
  2484. data = (void __user *) arg;
  2485. sensor_status = atomic_read(&g_flag);
  2486. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2487. if ((sensor_status == 1) && (atomic_read(&driver_suspend_flag) == 1))
  2488. {
  2489. /* de-active g-channel when driver suspend regardless of g_flag*/
  2490. sensor_status = 0;
  2491. }
  2492. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2493. if(copy_to_user(data, &sensor_status, sizeof(sensor_status)))
  2494. {
  2495. GSE_ERR("copy_to_user failed.");
  2496. return -EFAULT;
  2497. }
  2498. /* clear the flag */
  2499. mutex_lock(&uplink_event_flag_mutex);
  2500. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_G_ACTIVE) != 0)
  2501. {
  2502. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_G_ACTIVE;
  2503. }
  2504. mutex_unlock(&uplink_event_flag_mutex);
  2505. /* wake up the wait queue */
  2506. wake_up(&uplink_event_flag_wq);
  2507. break;
  2508. #endif //BMC050_M4G
  2509. #ifdef BMC050_VRV
  2510. case ECOMPASS_IOC_GET_VRVDELAY: //used by daemon
  2511. data = (void __user *) arg;
  2512. if(copy_to_user(data, &vrv_delay, sizeof(vrv_delay)))
  2513. {
  2514. GSE_ERR("copy_to_user failed.");
  2515. return -EFAULT;
  2516. }
  2517. /* clear the flag */
  2518. mutex_lock(&uplink_event_flag_mutex);
  2519. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_VRV_DELAY) != 0)
  2520. {
  2521. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_VRV_DELAY;
  2522. }
  2523. mutex_unlock(&uplink_event_flag_mutex);
  2524. /* wake up the wait queue */
  2525. wake_up(&uplink_event_flag_wq);
  2526. break;
  2527. case ECOMPASS_IOC_GET_VRVFLAG: //used by daemon
  2528. data = (void __user *) arg;
  2529. sensor_status = atomic_read(&vrv_flag);
  2530. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2531. if ((sensor_status == 1) && (atomic_read(&driver_suspend_flag) == 1))
  2532. {
  2533. /* de-active vrv-channel when driver suspend regardless of vrv_flag*/
  2534. sensor_status = 0;
  2535. }
  2536. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2537. if(copy_to_user(data, &sensor_status, sizeof(sensor_status)))
  2538. {
  2539. GSE_ERR("copy_to_user failed.");
  2540. return -EFAULT;
  2541. }
  2542. /* clear the flag */
  2543. mutex_lock(&uplink_event_flag_mutex);
  2544. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_VRV_ACTIVE) != 0)
  2545. {
  2546. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_VRV_ACTIVE;
  2547. }
  2548. mutex_unlock(&uplink_event_flag_mutex);
  2549. /* wake up the wait queue */
  2550. wake_up(&uplink_event_flag_wq);
  2551. break;
  2552. #endif //BMC050_VRV
  2553. #ifdef BMC050_VLA
  2554. case ECOMPASS_IOC_GET_VLADELAY: //used by daemon
  2555. data = (void __user *) arg;
  2556. if(copy_to_user(data, &vla_delay, sizeof(vla_delay)))
  2557. {
  2558. GSE_ERR("copy_to_user failed.");
  2559. return -EFAULT;
  2560. }
  2561. /* clear the flag */
  2562. mutex_lock(&uplink_event_flag_mutex);
  2563. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_VLA_DELAY) != 0)
  2564. {
  2565. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_VLA_DELAY;
  2566. }
  2567. mutex_unlock(&uplink_event_flag_mutex);
  2568. /* wake up the wait queue */
  2569. wake_up(&uplink_event_flag_wq);
  2570. break;
  2571. case ECOMPASS_IOC_GET_VLAFLAG: //used by daemon
  2572. data = (void __user *) arg;
  2573. sensor_status = atomic_read(&vla_flag);
  2574. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2575. if ((sensor_status == 1) && (atomic_read(&driver_suspend_flag) == 1))
  2576. {
  2577. /* de-active vla-channel when driver suspend regardless of vla_flag*/
  2578. sensor_status = 0;
  2579. }
  2580. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2581. if(copy_to_user(data, &sensor_status, sizeof(sensor_status)))
  2582. {
  2583. GSE_ERR("copy_to_user failed.");
  2584. return -EFAULT;
  2585. }
  2586. /* clear the flag */
  2587. mutex_lock(&uplink_event_flag_mutex);
  2588. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_VLA_ACTIVE) != 0)
  2589. {
  2590. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_VLA_ACTIVE;
  2591. }
  2592. mutex_unlock(&uplink_event_flag_mutex);
  2593. /* wake up the wait queue */
  2594. wake_up(&uplink_event_flag_wq);
  2595. break;
  2596. #endif //BMC050_VLA
  2597. #ifdef BMC050_VG
  2598. case ECOMPASS_IOC_GET_VGDELAY: //used by daemon
  2599. data = (void __user *) arg;
  2600. if(copy_to_user(data, &vg_delay, sizeof(vg_delay)))
  2601. {
  2602. GSE_ERR("copy_to_user failed.");
  2603. return -EFAULT;
  2604. }
  2605. /* clear the flag */
  2606. mutex_lock(&uplink_event_flag_mutex);
  2607. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_VG_DELAY) != 0)
  2608. {
  2609. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_VG_DELAY;
  2610. }
  2611. mutex_unlock(&uplink_event_flag_mutex);
  2612. /* wake up the wait queue */
  2613. wake_up(&uplink_event_flag_wq);
  2614. break;
  2615. case ECOMPASS_IOC_GET_VGFLAG: //used by daemon
  2616. data = (void __user *) arg;
  2617. sensor_status = atomic_read(&vg_flag);
  2618. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2619. if ((sensor_status == 1) && (atomic_read(&driver_suspend_flag) == 1))
  2620. {
  2621. /* de-active vla-channel when driver suspend regardless of vla_flag*/
  2622. sensor_status = 0;
  2623. }
  2624. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2625. if(copy_to_user(data, &sensor_status, sizeof(sensor_status)))
  2626. {
  2627. GSE_ERR("copy_to_user failed.");
  2628. return -EFAULT;
  2629. }
  2630. /* clear the flag */
  2631. mutex_lock(&uplink_event_flag_mutex);
  2632. if ((uplink_event_flag & BMMDRV_ULEVT_FLAG_VG_ACTIVE) != 0)
  2633. {
  2634. uplink_event_flag &= ~BMMDRV_ULEVT_FLAG_VG_ACTIVE;
  2635. }
  2636. mutex_unlock(&uplink_event_flag_mutex);
  2637. /* wake up the wait queue */
  2638. wake_up(&uplink_event_flag_wq);
  2639. break;
  2640. #endif //BMC050_VG
  2641. //tad3sgh add --
  2642. default:
  2643. GSE_ERR("unknown IOCTL: 0x%08x\n", cmd);
  2644. err = -ENOIOCTLCMD;
  2645. break;
  2646. }
  2647. return err;
  2648. }
  2649. /*----------------------------------------------------------------------------*/
  2650. static struct file_operations bma255_fops = {
  2651. //.owner = THIS_MODULE,
  2652. .open = bma255_open,
  2653. .release = bma255_release,
  2654. .unlocked_ioctl = bma255_unlocked_ioctl,
  2655. };
  2656. /*----------------------------------------------------------------------------*/
  2657. static struct miscdevice bma255_device = {
  2658. .minor = MISC_DYNAMIC_MINOR,
  2659. .name = "gsensor",
  2660. .fops = &bma255_fops,
  2661. };
  2662. /*----------------------------------------------------------------------------*/
  2663. #ifndef CONFIG_HAS_EARLYSUSPEND
  2664. /*----------------------------------------------------------------------------*/
  2665. static int bma255_suspend(struct i2c_client *client, pm_message_t msg)
  2666. {
  2667. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  2668. int err = 0;
  2669. GSE_FUN();
  2670. if(msg.event == PM_EVENT_SUSPEND)
  2671. {
  2672. if(obj == NULL)
  2673. {
  2674. GSE_ERR("null pointer!!\n");
  2675. return -EINVAL;
  2676. }
  2677. atomic_set(&obj->suspend, 1);
  2678. //tad3sgh add ++
  2679. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2680. /* set driver suspend flag */
  2681. atomic_set(&driver_suspend_flag, 1);
  2682. if (atomic_read(&m_flag) == 1)
  2683. {
  2684. /* set the flag to block e-compass daemon*/
  2685. mutex_lock(&uplink_event_flag_mutex);
  2686. uplink_event_flag |= BMMDRV_ULEVT_FLAG_M_ACTIVE;
  2687. mutex_unlock(&uplink_event_flag_mutex);
  2688. }
  2689. if (atomic_read(&o_flag) == 1)
  2690. {
  2691. /* set the flag to block e-compass daemon*/
  2692. mutex_lock(&uplink_event_flag_mutex);
  2693. uplink_event_flag |= BMMDRV_ULEVT_FLAG_O_ACTIVE;
  2694. mutex_unlock(&uplink_event_flag_mutex);
  2695. }
  2696. #ifdef BMC050_M4G
  2697. if (atomic_read(&g_flag) == 1)
  2698. {
  2699. /* set the flag to block e-compass daemon*/
  2700. mutex_lock(&uplink_event_flag_mutex);
  2701. uplink_event_flag |= BMMDRV_ULEVT_FLAG_G_ACTIVE;
  2702. mutex_unlock(&uplink_event_flag_mutex);
  2703. }
  2704. #endif //BMC050_M4G
  2705. #ifdef BMC050_VRV
  2706. if (atomic_read(&vrv_flag) == 1)
  2707. {
  2708. /* set the flag to block e-compass daemon*/
  2709. mutex_lock(&uplink_event_flag_mutex);
  2710. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VRV_ACTIVE;
  2711. mutex_unlock(&uplink_event_flag_mutex);
  2712. }
  2713. #endif //BMC050_VRV
  2714. #ifdef BMC050_VLA
  2715. if (atomic_read(&vla_flag) == 1)
  2716. {
  2717. /* set the flag to block e-compass daemon*/
  2718. mutex_lock(&uplink_event_flag_mutex);
  2719. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VLA_ACTIVE;
  2720. mutex_unlock(&uplink_event_flag_mutex);
  2721. }
  2722. #endif //BMC050_VLA
  2723. #ifdef BMC050_VG
  2724. if (atomic_read(&vg_flag) == 1)
  2725. {
  2726. /* set the flag to block e-compass daemon*/
  2727. mutex_lock(&uplink_event_flag_mutex);
  2728. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VG_ACTIVE;
  2729. mutex_unlock(&uplink_event_flag_mutex);
  2730. }
  2731. #endif //BMC050_VG
  2732. /* wake up the wait queue */
  2733. wake_up(&uplink_event_flag_wq);
  2734. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2735. //tad3sgh add --
  2736. if((err = BMA255_SetPowerMode(obj->client, false)))
  2737. {
  2738. GSE_ERR("write power control fail!!\n");
  2739. return 0;
  2740. }
  2741. BMA255_power(obj->hw, 0);
  2742. }
  2743. return err;
  2744. }
  2745. /*----------------------------------------------------------------------------*/
  2746. static int bma255_resume(struct i2c_client *client)
  2747. {
  2748. struct bma255_i2c_data *obj = i2c_get_clientdata(client);
  2749. int err;
  2750. GSE_FUN();
  2751. if(obj == NULL)
  2752. {
  2753. GSE_ERR("null pointer!!\n");
  2754. return -EINVAL;
  2755. }
  2756. BMA255_power(obj->hw, 1);
  2757. if((err = bma255_init_client(client, 0)))
  2758. {
  2759. GSE_ERR("initialize client fail!!\n");
  2760. return err;
  2761. }
  2762. //tad3sgh add ++
  2763. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2764. /* clear driver suspend flag */
  2765. atomic_set(&driver_suspend_flag, 0);
  2766. if (atomic_read(&m_flag) == 1)
  2767. {
  2768. /* set the flag to unblock e-compass daemon*/
  2769. mutex_lock(&uplink_event_flag_mutex);
  2770. uplink_event_flag |= BMMDRV_ULEVT_FLAG_M_ACTIVE;
  2771. mutex_unlock(&uplink_event_flag_mutex);
  2772. }
  2773. if (atomic_read(&o_flag) == 1)
  2774. {
  2775. /* set the flag to unblock e-compass daemon*/
  2776. mutex_lock(&uplink_event_flag_mutex);
  2777. uplink_event_flag |= BMMDRV_ULEVT_FLAG_O_ACTIVE;
  2778. mutex_unlock(&uplink_event_flag_mutex);
  2779. }
  2780. #ifdef BMC050_M4G
  2781. if (atomic_read(&g_flag) == 1)
  2782. {
  2783. /* set the flag to unblock e-compass daemon*/
  2784. mutex_lock(&uplink_event_flag_mutex);
  2785. uplink_event_flag |= BMMDRV_ULEVT_FLAG_G_ACTIVE;
  2786. mutex_unlock(&uplink_event_flag_mutex);
  2787. }
  2788. #endif //BMC050_M4G
  2789. #ifdef BMC050_VRV
  2790. if (atomic_read(&vrv_flag) == 1)
  2791. {
  2792. /* set the flag to unblock e-compass daemon*/
  2793. mutex_lock(&uplink_event_flag_mutex);
  2794. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VRV_ACTIVE;
  2795. mutex_unlock(&uplink_event_flag_mutex);
  2796. }
  2797. #endif //BMC050_VRV
  2798. #ifdef BMC050_VG
  2799. if (atomic_read(&vg_flag) == 1)
  2800. {
  2801. /* set the flag to unblock e-compass daemon*/
  2802. mutex_lock(&uplink_event_flag_mutex);
  2803. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VG_ACTIVE;
  2804. mutex_unlock(&uplink_event_flag_mutex);
  2805. }
  2806. #endif //BMC050_VG
  2807. /* wake up the wait queue */
  2808. wake_up(&uplink_event_flag_wq);
  2809. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2810. //tad3sgh add --
  2811. atomic_set(&obj->suspend, 0);
  2812. return 0;
  2813. }
  2814. /*----------------------------------------------------------------------------*/
  2815. #else /*CONFIG_HAS_EARLY_SUSPEND is defined*/
  2816. /*----------------------------------------------------------------------------*/
  2817. static void bma255_early_suspend(struct early_suspend *h)
  2818. {
  2819. struct bma255_i2c_data *obj = container_of(h, struct bma255_i2c_data, early_drv);
  2820. int err;
  2821. GSE_FUN();
  2822. if(obj == NULL)
  2823. {
  2824. GSE_ERR("null pointer!!\n");
  2825. return;
  2826. }
  2827. atomic_set(&obj->suspend, 1);
  2828. //tad3sgh add ++
  2829. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2830. /* set driver suspend flag */
  2831. atomic_set(&driver_suspend_flag, 1);
  2832. if (atomic_read(&m_flag) == 1)
  2833. {
  2834. /* set the flag to block e-compass daemon*/
  2835. mutex_lock(&uplink_event_flag_mutex);
  2836. uplink_event_flag |= BMMDRV_ULEVT_FLAG_M_ACTIVE;
  2837. mutex_unlock(&uplink_event_flag_mutex);
  2838. }
  2839. if (atomic_read(&o_flag) == 1)
  2840. {
  2841. /* set the flag to block e-compass daemon*/
  2842. mutex_lock(&uplink_event_flag_mutex);
  2843. uplink_event_flag |= BMMDRV_ULEVT_FLAG_O_ACTIVE;
  2844. mutex_unlock(&uplink_event_flag_mutex);
  2845. }
  2846. #ifdef BMC050_M4G
  2847. if (atomic_read(&g_flag) == 1)
  2848. {
  2849. /* set the flag to block e-compass daemon*/
  2850. mutex_lock(&uplink_event_flag_mutex);
  2851. uplink_event_flag |= BMMDRV_ULEVT_FLAG_G_ACTIVE;
  2852. mutex_unlock(&uplink_event_flag_mutex);
  2853. }
  2854. #endif //BMC050_M4G
  2855. #ifdef BMC050_VRV
  2856. if (atomic_read(&vrv_flag) == 1)
  2857. {
  2858. /* set the flag to block e-compass daemon*/
  2859. mutex_lock(&uplink_event_flag_mutex);
  2860. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VRV_ACTIVE;
  2861. mutex_unlock(&uplink_event_flag_mutex);
  2862. }
  2863. #endif //BMC050_VRV
  2864. #ifdef BMC050_VLA
  2865. if (atomic_read(&vla_flag) == 1)
  2866. {
  2867. /* set the flag to block e-compass daemon*/
  2868. mutex_lock(&uplink_event_flag_mutex);
  2869. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VLA_ACTIVE;
  2870. mutex_unlock(&uplink_event_flag_mutex);
  2871. }
  2872. #endif //BMC050_VLA
  2873. #ifdef BMC050_VG
  2874. if (atomic_read(&vg_flag) == 1)
  2875. {
  2876. /* set the flag to block e-compass daemon*/
  2877. mutex_lock(&uplink_event_flag_mutex);
  2878. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VG_ACTIVE;
  2879. mutex_unlock(&uplink_event_flag_mutex);
  2880. }
  2881. #endif //BMC050_VG
  2882. /* wake up the wait queue */
  2883. wake_up(&uplink_event_flag_wq);
  2884. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2885. //tad3sgh add --
  2886. if(err = BMA255_SetPowerMode(obj->client, false))
  2887. {
  2888. GSE_ERR("write power control fail!!\n");
  2889. return;
  2890. }
  2891. BMA255_power(obj->hw, 0);
  2892. }
  2893. /*----------------------------------------------------------------------------*/
  2894. static void bma255_late_resume(struct early_suspend *h)
  2895. {
  2896. struct bma255_i2c_data *obj = container_of(h, struct bma255_i2c_data, early_drv);
  2897. int err;
  2898. GSE_FUN();
  2899. if(obj == NULL)
  2900. {
  2901. GSE_ERR("null pointer!!\n");
  2902. return;
  2903. }
  2904. BMA255_power(obj->hw, 1);
  2905. if(err = bma255_init_client(obj->client, 0))
  2906. {
  2907. GSE_ERR("initialize client fail!!\n");
  2908. return;
  2909. }
  2910. //tad3sgh add ++
  2911. #ifdef BMC050_BLOCK_DAEMON_ON_SUSPEND
  2912. /* clear driver suspend flag */
  2913. atomic_set(&driver_suspend_flag, 0);
  2914. if (atomic_read(&m_flag) == 1)
  2915. {
  2916. /* set the flag to unblock e-compass daemon*/
  2917. mutex_lock(&uplink_event_flag_mutex);
  2918. uplink_event_flag |= BMMDRV_ULEVT_FLAG_M_ACTIVE;
  2919. mutex_unlock(&uplink_event_flag_mutex);
  2920. }
  2921. if (atomic_read(&o_flag) == 1)
  2922. {
  2923. /* set the flag to unblock e-compass daemon*/
  2924. mutex_lock(&uplink_event_flag_mutex);
  2925. uplink_event_flag |= BMMDRV_ULEVT_FLAG_O_ACTIVE;
  2926. mutex_unlock(&uplink_event_flag_mutex);
  2927. }
  2928. #ifdef BMC050_M4G
  2929. if (atomic_read(&g_flag) == 1)
  2930. {
  2931. /* set the flag to unblock e-compass daemon*/
  2932. mutex_lock(&uplink_event_flag_mutex);
  2933. uplink_event_flag |= BMMDRV_ULEVT_FLAG_G_ACTIVE;
  2934. mutex_unlock(&uplink_event_flag_mutex);
  2935. }
  2936. #endif //BMC050_M4G
  2937. #ifdef BMC050_VRV
  2938. if (atomic_read(&vrv_flag) == 1)
  2939. {
  2940. /* set the flag to unblock e-compass daemon*/
  2941. mutex_lock(&uplink_event_flag_mutex);
  2942. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VRV_ACTIVE;
  2943. mutex_unlock(&uplink_event_flag_mutex);
  2944. }
  2945. #endif //BMC050_VRV
  2946. #ifdef BMC050_VG
  2947. if (atomic_read(&vg_flag) == 1)
  2948. {
  2949. /* set the flag to unblock e-compass daemon*/
  2950. mutex_lock(&uplink_event_flag_mutex);
  2951. uplink_event_flag |= BMMDRV_ULEVT_FLAG_VG_ACTIVE;
  2952. mutex_unlock(&uplink_event_flag_mutex);
  2953. }
  2954. #endif //BMC050_VG
  2955. /* wake up the wait queue */
  2956. wake_up(&uplink_event_flag_wq);
  2957. #endif //BMC050_BLOCK_DAEMON_ON_SUSPEND
  2958. //tad3sgh add --
  2959. atomic_set(&obj->suspend, 0);
  2960. }
  2961. /*----------------------------------------------------------------------------*/
  2962. #endif /*CONFIG_HAS_EARLYSUSPEND*/
  2963. // if use this typ of enable , Gsensor should report inputEvent(x, y, z ,stats, div) to HAL
  2964. static int bma255_open_report_data(int open)
  2965. {
  2966. //should queuq work to report event if is_report_input_direct=true
  2967. return 0;
  2968. }
  2969. // if use this typ of enable , Gsensor only enabled but not report inputEvent to HAL
  2970. static int bma255_enable_nodata(int en)
  2971. {
  2972. int err = 0;
  2973. if(((en == 0) && (sensor_power == false))
  2974. ||((en == 1) && (sensor_power == true))) {
  2975. GSE_LOG("Gsensor device have updated!\n");
  2976. } else {
  2977. err = BMA255_SetPowerMode(obj_i2c_data->client, !sensor_power);
  2978. }
  2979. return err;
  2980. }
  2981. static int bma255_set_delay(u64 ns)
  2982. {
  2983. int err = 0;
  2984. int value, sample_delay;
  2985. value = (int)ns/1000/1000;
  2986. if(value <= 5) {
  2987. sample_delay = BMA255_BW_200HZ;
  2988. } else if(value <= 10) {
  2989. sample_delay = BMA255_BW_100HZ;
  2990. } else {
  2991. sample_delay = BMA255_BW_50HZ;
  2992. }
  2993. //err = BMA255_SetBWRate(obj_i2c_data->client, sample_delay);
  2994. if(err != BMA255_SUCCESS ) {
  2995. GSE_ERR("Set delay parameter error!\n");
  2996. }
  2997. if(value >= 50) {
  2998. atomic_set(&obj_i2c_data->filter, 0);
  2999. } else {
  3000. #if defined(CONFIG_BMA255_LOWPASS)
  3001. obj_i2c_data->fir.num = 0;
  3002. obj_i2c_data->fir.idx = 0;
  3003. obj_i2c_data->fir.sum[BMA255_AXIS_X] = 0;
  3004. obj_i2c_data->fir.sum[BMA255_AXIS_Y] = 0;
  3005. obj_i2c_data->fir.sum[BMA255_AXIS_Z] = 0;
  3006. atomic_set(&obj_i2c_data->filter, 1);
  3007. #endif
  3008. }
  3009. return 0;
  3010. }
  3011. static int bma255_get_data(int* x ,int* y,int* z, int* status)
  3012. {
  3013. char buff[BMA255_BUFSIZE];
  3014. /* use acc raw data for gsensor */
  3015. BMA255_ReadSensorData(obj_i2c_data->client, buff, BMA255_BUFSIZE);
  3016. sscanf(buff, "%x %x %x", x, y, z);
  3017. *status = SENSOR_STATUS_ACCURACY_MEDIUM;
  3018. return 0;
  3019. }
  3020. int bsx_algo_m_enable(int en)
  3021. {
  3022. if(en == 1) {
  3023. atomic_set(&m_flag, 1);
  3024. } else {
  3025. atomic_set(&m_flag, 0);
  3026. }
  3027. /* set the flag */
  3028. mutex_lock(&uplink_event_flag_mutex);
  3029. uplink_event_flag |= BMMDRV_ULEVT_FLAG_M_ACTIVE;
  3030. mutex_unlock(&uplink_event_flag_mutex);
  3031. /* wake up the wait queue */
  3032. wake_up(&uplink_event_flag_wq);
  3033. return 0;
  3034. }
  3035. int bsx_algo_m_set_delay(u64 ns)
  3036. {
  3037. int value = (int)ns/1000/1000;
  3038. bmm050d_delay = value;
  3039. /* set the flag */
  3040. mutex_lock(&uplink_event_flag_mutex);
  3041. uplink_event_flag |= BMMDRV_ULEVT_FLAG_M_DELAY;
  3042. mutex_unlock(&uplink_event_flag_mutex);
  3043. /* wake up the wait queue */
  3044. wake_up(&uplink_event_flag_wq);
  3045. return 0;
  3046. }
  3047. int bsx_algo_m_open_report_data(int open)
  3048. {
  3049. return 0;
  3050. }
  3051. int bsx_algo_m_get_data(int* x ,int* y,int* z, int* status)
  3052. {
  3053. mutex_lock(&sensor_data_mutex);
  3054. *x = sensor_data[4];
  3055. *y = sensor_data[5];
  3056. *z = sensor_data[6];
  3057. *status = sensor_data[7];
  3058. mutex_unlock(&sensor_data_mutex);
  3059. return 0;
  3060. }
  3061. int bsx_algo_o_enable(int en)
  3062. {
  3063. if(en == 1) {
  3064. atomic_set(&o_flag, 1);
  3065. } else {
  3066. atomic_set(&o_flag, 0);
  3067. }
  3068. /* set the flag */
  3069. mutex_lock(&uplink_event_flag_mutex);
  3070. uplink_event_flag |= BMMDRV_ULEVT_FLAG_O_ACTIVE;
  3071. mutex_unlock(&uplink_event_flag_mutex);
  3072. /* wake up the wait queue */
  3073. wake_up(&uplink_event_flag_wq);
  3074. return 0;
  3075. }
  3076. int bsx_algo_o_set_delay(u64 ns)
  3077. {
  3078. int value = (int)ns/1000/1000;
  3079. bmm050d_delay = value;
  3080. /* set the flag */
  3081. mutex_lock(&uplink_event_flag_mutex);
  3082. uplink_event_flag |= BMMDRV_ULEVT_FLAG_O_DELAY;
  3083. mutex_unlock(&uplink_event_flag_mutex);
  3084. /* wake up the wait queue */
  3085. wake_up(&uplink_event_flag_wq);
  3086. return 0;
  3087. }
  3088. int bsx_algo_o_open_report_data(int open)
  3089. {
  3090. return 0;
  3091. }
  3092. int bsx_algo_o_get_data(int* x ,int* y,int* z, int* status)
  3093. {
  3094. mutex_lock(&sensor_data_mutex);
  3095. *x = sensor_data[8];
  3096. *y = sensor_data[9];
  3097. *z = sensor_data[10];
  3098. *status = sensor_data[11];
  3099. mutex_unlock(&sensor_data_mutex);
  3100. return 0;
  3101. }
  3102. // if use this typ of enable , Gsensor should report inputEvent(x, y, z ,stats, div) to HAL
  3103. int bsx_algo_gyro_open_report_data(int open)
  3104. {
  3105. //should queuq work to report event if is_report_input_direct=true
  3106. return 0;
  3107. }
  3108. // if use this typ of enable , Gsensor only enabled but not report inputEvent to HAL
  3109. int bsx_algo_gyro_enable_nodata(int en)
  3110. {
  3111. if(en == 1) {
  3112. atomic_set(&g_flag, 1);
  3113. } else {
  3114. atomic_set(&g_flag, 0);
  3115. }
  3116. /* set the flag */
  3117. mutex_lock(&uplink_event_flag_mutex);
  3118. uplink_event_flag |= BMMDRV_ULEVT_FLAG_G_ACTIVE;
  3119. mutex_unlock(&uplink_event_flag_mutex);
  3120. /* wake up the wait queue */
  3121. wake_up(&uplink_event_flag_wq);
  3122. return 0;
  3123. }
  3124. int bsx_algo_gyro_set_delay(u64 ns)
  3125. {
  3126. int value = (int)ns/1000/1000 ;
  3127. m4g_delay = value;
  3128. /* set the flag */
  3129. mutex_lock(&uplink_event_flag_mutex);
  3130. uplink_event_flag |= BMMDRV_ULEVT_FLAG_G_DELAY;
  3131. mutex_unlock(&uplink_event_flag_mutex);
  3132. /* wake up the wait queue */
  3133. wake_up(&uplink_event_flag_wq);
  3134. return 0;
  3135. }
  3136. int bsx_algo_gyro_get_data(int* x ,int* y,int* z, int* status)
  3137. {
  3138. mutex_lock(&sensor_data_mutex);
  3139. *x = m4g_data[0];
  3140. *y = m4g_data[1];
  3141. *z = m4g_data[2];
  3142. *status = m4g_data[3];
  3143. mutex_unlock(&sensor_data_mutex);
  3144. return 0;
  3145. }
  3146. /*----------------------------------------------------------------------------*/
  3147. static int bma255_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
  3148. {
  3149. struct i2c_client *new_client;
  3150. struct bma255_i2c_data *obj;
  3151. //tad3sgh add ++
  3152. struct acc_control_path ctl={0};
  3153. struct acc_data_path data={0};
  3154. #ifdef BMC050_M4G
  3155. struct hwmsen_object sobj_g;
  3156. #endif //BMC050_M4G
  3157. #ifdef BMC050_VRV
  3158. struct hwmsen_object sobj_vrv;
  3159. #endif //BMC050_VRV
  3160. #ifdef BMC050_VLA
  3161. struct hwmsen_object sobj_vla;
  3162. #endif //BMC050_VLA
  3163. #ifdef BMC050_VG
  3164. struct hwmsen_object sobj_vg;
  3165. #endif //BMC050_VG
  3166. //tad3sgh add --
  3167. int err = 0;
  3168. GSE_FUN();
  3169. if(!(obj = kzalloc(sizeof(*obj), GFP_KERNEL)))
  3170. {
  3171. err = -ENOMEM;
  3172. goto exit;
  3173. }
  3174. memset(obj, 0, sizeof(struct bma255_i2c_data));
  3175. obj->hw = hw;
  3176. if((err = hwmsen_get_convert(obj->hw->direction, &obj->cvt)))
  3177. {
  3178. GSE_ERR("invalid direction: %d\n", obj->hw->direction);
  3179. goto exit;
  3180. }
  3181. obj_i2c_data = obj;
  3182. obj->client = client;
  3183. new_client = obj->client;
  3184. i2c_set_clientdata(new_client,obj);
  3185. atomic_set(&obj->trace, 0);
  3186. atomic_set(&obj->suspend, 0);
  3187. mutex_init(&obj->lock);
  3188. //tad3sgh add ++
  3189. mutex_init(&sensor_data_mutex);
  3190. mutex_init(&uplink_event_flag_mutex);
  3191. init_waitqueue_head(&uplink_event_flag_wq);
  3192. //tad3sgh add --
  3193. #ifdef CONFIG_BMA255_LOWPASS
  3194. if(obj->hw->firlen > C_MAX_FIR_LENGTH)
  3195. {
  3196. atomic_set(&obj->firlen, C_MAX_FIR_LENGTH);
  3197. }
  3198. else
  3199. {
  3200. atomic_set(&obj->firlen, obj->hw->firlen);
  3201. }
  3202. if(atomic_read(&obj->firlen) > 0)
  3203. {
  3204. atomic_set(&obj->fir_en, 1);
  3205. }
  3206. #endif
  3207. bma255_i2c_client = new_client;
  3208. if((err = bma255_init_client(new_client, 1)))
  3209. {
  3210. goto exit_init_failed;
  3211. }
  3212. if((err = misc_register(&bma255_device)))
  3213. {
  3214. GSE_ERR("bma255_device register failed\n");
  3215. goto exit_misc_device_register_failed;
  3216. }
  3217. err = bma255_create_attr(&(bma255_init_info.platform_diver_addr->driver));
  3218. if(err) {
  3219. GSE_ERR("create attribute err = %d\n", err);
  3220. goto exit_create_attr_failed;
  3221. }
  3222. ctl.open_report_data= bma255_open_report_data;
  3223. ctl.enable_nodata = bma255_enable_nodata;
  3224. ctl.set_delay = bma255_set_delay;
  3225. ctl.is_report_input_direct = false;
  3226. err = acc_register_control_path(&ctl);
  3227. if(err)
  3228. {
  3229. GSE_ERR("register acc control path err\n");
  3230. goto exit_kfree;
  3231. }
  3232. data.get_data = bma255_get_data;
  3233. data.vender_div = 1000;
  3234. err = acc_register_data_path(&data);
  3235. if(err)
  3236. {
  3237. GSE_ERR("register acc data path err\n");
  3238. goto exit_kfree;
  3239. }
  3240. #ifdef BMC050_M4G
  3241. sobj_g.self = obj;
  3242. sobj_g.polling = 1;
  3243. sobj_g.sensor_operate = bmm050_m4g_operate;
  3244. if((err = hwmsen_attach(ID_GYROSCOPE, &sobj_g)))
  3245. {
  3246. GSE_ERR( "attach fail = %d\n", err);
  3247. goto exit_kfree;
  3248. }
  3249. #endif //BMC050_M4G
  3250. #ifdef BMC050_VRV
  3251. sobj_vrv.self = obj;
  3252. sobj_vrv.polling = 1;
  3253. sobj_vrv.sensor_operate = bmm050_vrv_operate;
  3254. if((err = hwmsen_attach(ID_ROTATION_VECTOR, &sobj_vrv)))
  3255. {
  3256. GSE_ERR( "attach fail = %d\n", err);
  3257. goto exit_kfree;
  3258. }
  3259. #endif //BMC050_VRV
  3260. #ifdef BMC050_VLA
  3261. sobj_vla.self = obj;
  3262. sobj_vla.polling = 1;
  3263. sobj_vla.sensor_operate = bmm050_vla_operate;
  3264. if((err = hwmsen_attach(ID_LINEAR_ACCELERATION, &sobj_vla)))
  3265. {
  3266. GSE_ERR( "attach fail = %d\n", err);
  3267. goto exit_kfree;
  3268. }
  3269. #endif //BMC050_VLA
  3270. #ifdef BMC050_VG
  3271. sobj_vg.self = obj;
  3272. sobj_vg.polling = 1;
  3273. sobj_vg.sensor_operate = bmm050_vg_operate;
  3274. if((err = hwmsen_attach(ID_GRAVITY, &sobj_vg)))
  3275. {
  3276. GSE_ERR( "attach fail = %d\n", err);
  3277. goto exit_kfree;
  3278. }
  3279. #endif //BMC050_VG
  3280. //tad3sgh add --
  3281. #ifdef CONFIG_HAS_EARLYSUSPEND
  3282. obj->early_drv.level = EARLY_SUSPEND_LEVEL_DISABLE_FB - 1,
  3283. obj->early_drv.suspend = bma255_early_suspend,
  3284. obj->early_drv.resume = bma255_late_resume,
  3285. register_early_suspend(&obj->early_drv);
  3286. #endif
  3287. bma255_init_flag =0;
  3288. GSE_LOG("%s: OK\n", __func__);
  3289. return 0;
  3290. exit_create_attr_failed:
  3291. misc_deregister(&bma255_device);
  3292. exit_misc_device_register_failed:
  3293. exit_init_failed:
  3294. //i2c_detach_client(new_client);
  3295. exit_kfree:
  3296. kfree(obj);
  3297. exit:
  3298. GSE_ERR("%s: err = %d\n", __func__, err);
  3299. bma255_init_flag =-1;
  3300. return err;
  3301. }
  3302. /*----------------------------------------------------------------------------*/
  3303. static int bma255_i2c_remove(struct i2c_client *client)
  3304. {
  3305. int err = 0;
  3306. err = bma255_delete_attr(&(bma255_init_info.platform_diver_addr->driver));
  3307. if(err) {
  3308. GSE_ERR("bma150_delete_attr fail: %d\n", err);
  3309. }
  3310. if((err = misc_deregister(&bma255_device)))
  3311. {
  3312. GSE_ERR("misc_deregister fail: %d\n", err);
  3313. }
  3314. bma255_i2c_client = NULL;
  3315. i2c_unregister_device(client);
  3316. kfree(i2c_get_clientdata(client));
  3317. return 0;
  3318. }
  3319. /*----------------------------------------------------------------------------*/
  3320. static int bma255_local_init(void)
  3321. {
  3322. GSE_FUN();
  3323. BMA255_power(hw, 1);
  3324. if(i2c_add_driver(&bma255_i2c_driver))
  3325. {
  3326. GSE_ERR("add driver error\n");
  3327. return -1;
  3328. }
  3329. if(-1 == bma255_init_flag)
  3330. {
  3331. return -1;
  3332. }
  3333. return 0;
  3334. }
  3335. /*----------------------------------------------------------------------------*/
  3336. static int bma255_remove(void)
  3337. {
  3338. GSE_FUN();
  3339. BMA255_power(hw, 0);
  3340. i2c_del_driver(&bma255_i2c_driver);
  3341. return 0;
  3342. }
  3343. static struct acc_init_info bma255_init_info = {
  3344. .name = "bma255",
  3345. .init = bma255_local_init,
  3346. .uninit = bma255_remove,
  3347. };
  3348. /*----------------------------------------------------------------------------*/
  3349. static int __init bma255_init(void)
  3350. {
  3351. const char * name = "mediatek,bma255";
  3352. GSE_FUN();
  3353. hw = get_accel_dts_func(name, hw);
  3354. acc_driver_add(&bma255_init_info);
  3355. return 0;
  3356. }
  3357. /*----------------------------------------------------------------------------*/
  3358. static void __exit bma255_exit(void)
  3359. {
  3360. GSE_FUN();
  3361. }
  3362. /*----------------------------------------------------------------------------*/
  3363. module_init(bma255_init);
  3364. module_exit(bma255_exit);
  3365. /*----------------------------------------------------------------------------*/
  3366. MODULE_LICENSE("GPL");
  3367. MODULE_DESCRIPTION("BMA255 I2C driver");
  3368. MODULE_AUTHOR("hongji.zhou@bosch-sensortec.com");