core.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. /*
  2. * --------------------------------------------------------------------
  3. * Driver for ST NFC Transceiver ST95HF
  4. * --------------------------------------------------------------------
  5. * Copyright (C) 2015 STMicroelectronics Pvt. Ltd. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/err.h>
  20. #include <linux/gpio.h>
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/module.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/nfc.h>
  27. #include <linux/of_gpio.h>
  28. #include <linux/of.h>
  29. #include <linux/of_irq.h>
  30. #include <linux/property.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/wait.h>
  33. #include <net/nfc/digital.h>
  34. #include <net/nfc/nfc.h>
  35. #include "spi.h"
  36. /* supported protocols */
  37. #define ST95HF_SUPPORTED_PROT (NFC_PROTO_ISO14443_MASK | \
  38. NFC_PROTO_ISO14443_B_MASK | \
  39. NFC_PROTO_ISO15693_MASK)
  40. /* driver capabilities */
  41. #define ST95HF_CAPABILITIES NFC_DIGITAL_DRV_CAPS_IN_CRC
  42. /* Command Send Interface */
  43. /* ST95HF_COMMAND_SEND CMD Ids */
  44. #define ECHO_CMD 0x55
  45. #define WRITE_REGISTER_CMD 0x9
  46. #define PROTOCOL_SELECT_CMD 0x2
  47. #define SEND_RECEIVE_CMD 0x4
  48. /* Select protocol codes */
  49. #define ISO15693_PROTOCOL_CODE 0x1
  50. #define ISO14443A_PROTOCOL_CODE 0x2
  51. #define ISO14443B_PROTOCOL_CODE 0x3
  52. /*
  53. * head room len is 3
  54. * 1 byte for control byte
  55. * 1 byte for cmd
  56. * 1 byte for size
  57. */
  58. #define ST95HF_HEADROOM_LEN 3
  59. /*
  60. * tailroom is 1 for ISO14443A
  61. * and 0 for ISO14443B/ISO15693,
  62. * hence the max value 1 should be
  63. * taken.
  64. */
  65. #define ST95HF_TAILROOM_LEN 1
  66. /* Command Response interface */
  67. #define MAX_RESPONSE_BUFFER_SIZE 280
  68. #define ECHORESPONSE 0x55
  69. #define ST95HF_ERR_MASK 0xF
  70. #define ST95HF_TIMEOUT_ERROR 0x87
  71. #define ST95HF_NFCA_CRC_ERR_MASK 0x20
  72. #define ST95HF_NFCB_CRC_ERR_MASK 0x01
  73. /* ST95HF transmission flag values */
  74. #define TRFLAG_NFCA_SHORT_FRAME 0x07
  75. #define TRFLAG_NFCA_STD_FRAME 0x08
  76. #define TRFLAG_NFCA_STD_FRAME_CRC 0x28
  77. /* Misc defs */
  78. #define HIGH 1
  79. #define LOW 0
  80. #define ISO14443A_RATS_REQ 0xE0
  81. #define RATS_TB1_PRESENT_MASK 0x20
  82. #define RATS_TA1_PRESENT_MASK 0x10
  83. #define TB1_FWI_MASK 0xF0
  84. #define WTX_REQ_FROM_TAG 0xF2
  85. #define MAX_CMD_LEN 0x7
  86. #define MAX_CMD_PARAMS 4
  87. struct cmd {
  88. int cmd_len;
  89. unsigned char cmd_id;
  90. unsigned char no_cmd_params;
  91. unsigned char cmd_params[MAX_CMD_PARAMS];
  92. enum req_type req;
  93. };
  94. struct param_list {
  95. int param_offset;
  96. int new_param_val;
  97. };
  98. /*
  99. * List of top-level cmds to be used internally by the driver.
  100. * All these commands are build on top of ST95HF basic commands
  101. * such as SEND_RECEIVE_CMD, PROTOCOL_SELECT_CMD, etc.
  102. * These top level cmds are used internally while implementing various ops of
  103. * digital layer/driver probe or extending the digital framework layer for
  104. * features that are not yet implemented there, for example, WTX cmd handling.
  105. */
  106. enum st95hf_cmd_list {
  107. CMD_ECHO,
  108. CMD_ISO14443A_CONFIG,
  109. CMD_ISO14443A_DEMOGAIN,
  110. CMD_ISO14443B_DEMOGAIN,
  111. CMD_ISO14443A_PROTOCOL_SELECT,
  112. CMD_ISO14443B_PROTOCOL_SELECT,
  113. CMD_WTX_RESPONSE,
  114. CMD_FIELD_OFF,
  115. CMD_ISO15693_PROTOCOL_SELECT,
  116. };
  117. static const struct cmd cmd_array[] = {
  118. [CMD_ECHO] = {
  119. .cmd_len = 0x2,
  120. .cmd_id = ECHO_CMD,
  121. .no_cmd_params = 0,
  122. .req = SYNC,
  123. },
  124. [CMD_ISO14443A_CONFIG] = {
  125. .cmd_len = 0x7,
  126. .cmd_id = WRITE_REGISTER_CMD,
  127. .no_cmd_params = 0x4,
  128. .cmd_params = {0x3A, 0x00, 0x5A, 0x04},
  129. .req = SYNC,
  130. },
  131. [CMD_ISO14443A_DEMOGAIN] = {
  132. .cmd_len = 0x7,
  133. .cmd_id = WRITE_REGISTER_CMD,
  134. .no_cmd_params = 0x4,
  135. .cmd_params = {0x68, 0x01, 0x01, 0xDF},
  136. .req = SYNC,
  137. },
  138. [CMD_ISO14443B_DEMOGAIN] = {
  139. .cmd_len = 0x7,
  140. .cmd_id = WRITE_REGISTER_CMD,
  141. .no_cmd_params = 0x4,
  142. .cmd_params = {0x68, 0x01, 0x01, 0x51},
  143. .req = SYNC,
  144. },
  145. [CMD_ISO14443A_PROTOCOL_SELECT] = {
  146. .cmd_len = 0x7,
  147. .cmd_id = PROTOCOL_SELECT_CMD,
  148. .no_cmd_params = 0x4,
  149. .cmd_params = {ISO14443A_PROTOCOL_CODE, 0x00, 0x01, 0xA0},
  150. .req = SYNC,
  151. },
  152. [CMD_ISO14443B_PROTOCOL_SELECT] = {
  153. .cmd_len = 0x7,
  154. .cmd_id = PROTOCOL_SELECT_CMD,
  155. .no_cmd_params = 0x4,
  156. .cmd_params = {ISO14443B_PROTOCOL_CODE, 0x01, 0x03, 0xFF},
  157. .req = SYNC,
  158. },
  159. [CMD_WTX_RESPONSE] = {
  160. .cmd_len = 0x6,
  161. .cmd_id = SEND_RECEIVE_CMD,
  162. .no_cmd_params = 0x3,
  163. .cmd_params = {0xF2, 0x00, TRFLAG_NFCA_STD_FRAME_CRC},
  164. .req = ASYNC,
  165. },
  166. [CMD_FIELD_OFF] = {
  167. .cmd_len = 0x5,
  168. .cmd_id = PROTOCOL_SELECT_CMD,
  169. .no_cmd_params = 0x2,
  170. .cmd_params = {0x0, 0x0},
  171. .req = SYNC,
  172. },
  173. [CMD_ISO15693_PROTOCOL_SELECT] = {
  174. .cmd_len = 0x5,
  175. .cmd_id = PROTOCOL_SELECT_CMD,
  176. .no_cmd_params = 0x2,
  177. .cmd_params = {ISO15693_PROTOCOL_CODE, 0x0D},
  178. .req = SYNC,
  179. },
  180. };
  181. /* st95_digital_cmd_complete_arg stores client context */
  182. struct st95_digital_cmd_complete_arg {
  183. struct sk_buff *skb_resp;
  184. nfc_digital_cmd_complete_t complete_cb;
  185. void *cb_usrarg;
  186. bool rats;
  187. };
  188. /*
  189. * structure containing ST95HF driver specific data.
  190. * @spicontext: structure containing information required
  191. * for spi communication between st95hf and host.
  192. * @ddev: nfc digital device object.
  193. * @nfcdev: nfc device object.
  194. * @enable_gpio: gpio used to enable st95hf transceiver.
  195. * @complete_cb_arg: structure to store various context information
  196. * that is passed from nfc requesting thread to the threaded ISR.
  197. * @st95hf_supply: regulator "consumer" for NFC device.
  198. * @sendrcv_trflag: last byte of frame send by sendrecv command
  199. * of st95hf. This byte contains transmission flag info.
  200. * @exchange_lock: semaphore used for signaling the st95hf_remove
  201. * function that the last outstanding async nfc request is finished.
  202. * @rm_lock: mutex for ensuring safe access of nfc digital object
  203. * from threaded ISR. Usage of this mutex avoids any race between
  204. * deletion of the object from st95hf_remove() and its access from
  205. * the threaded ISR.
  206. * @nfcdev_free: flag to have the state of nfc device object.
  207. * [alive | died]
  208. * @current_protocol: current nfc protocol.
  209. * @current_rf_tech: current rf technology.
  210. * @fwi: frame waiting index, received in reply of RATS according to
  211. * digital protocol.
  212. */
  213. struct st95hf_context {
  214. struct st95hf_spi_context spicontext;
  215. struct nfc_digital_dev *ddev;
  216. struct nfc_dev *nfcdev;
  217. unsigned int enable_gpio;
  218. struct st95_digital_cmd_complete_arg complete_cb_arg;
  219. struct regulator *st95hf_supply;
  220. unsigned char sendrcv_trflag;
  221. struct semaphore exchange_lock;
  222. struct mutex rm_lock;
  223. bool nfcdev_free;
  224. u8 current_protocol;
  225. u8 current_rf_tech;
  226. int fwi;
  227. };
  228. /*
  229. * st95hf_send_recv_cmd() is for sending commands to ST95HF
  230. * that are described in the cmd_array[]. It can optionally
  231. * receive the response if the cmd request is of type
  232. * SYNC. For that to happen caller must pass true to recv_res.
  233. * For ASYNC request, recv_res is ignored and the
  234. * function will never try to receive the response on behalf
  235. * of the caller.
  236. */
  237. static int st95hf_send_recv_cmd(struct st95hf_context *st95context,
  238. enum st95hf_cmd_list cmd,
  239. int no_modif,
  240. struct param_list *list_array,
  241. bool recv_res)
  242. {
  243. unsigned char spi_cmd_buffer[MAX_CMD_LEN];
  244. int i, ret;
  245. struct device *dev = &st95context->spicontext.spidev->dev;
  246. if (cmd_array[cmd].cmd_len > MAX_CMD_LEN)
  247. return -EINVAL;
  248. if (cmd_array[cmd].no_cmd_params < no_modif)
  249. return -EINVAL;
  250. if (no_modif && !list_array)
  251. return -EINVAL;
  252. spi_cmd_buffer[0] = ST95HF_COMMAND_SEND;
  253. spi_cmd_buffer[1] = cmd_array[cmd].cmd_id;
  254. spi_cmd_buffer[2] = cmd_array[cmd].no_cmd_params;
  255. memcpy(&spi_cmd_buffer[3], cmd_array[cmd].cmd_params,
  256. spi_cmd_buffer[2]);
  257. for (i = 0; i < no_modif; i++) {
  258. if (list_array[i].param_offset >= cmd_array[cmd].no_cmd_params)
  259. return -EINVAL;
  260. spi_cmd_buffer[3 + list_array[i].param_offset] =
  261. list_array[i].new_param_val;
  262. }
  263. ret = st95hf_spi_send(&st95context->spicontext,
  264. spi_cmd_buffer,
  265. cmd_array[cmd].cmd_len,
  266. cmd_array[cmd].req);
  267. if (ret) {
  268. dev_err(dev, "st95hf_spi_send failed with error %d\n", ret);
  269. return ret;
  270. }
  271. if (cmd_array[cmd].req == SYNC && recv_res) {
  272. unsigned char st95hf_response_arr[2];
  273. ret = st95hf_spi_recv_response(&st95context->spicontext,
  274. st95hf_response_arr);
  275. if (ret < 0) {
  276. dev_err(dev, "spi error from st95hf_spi_recv_response(), err = 0x%x\n",
  277. ret);
  278. return ret;
  279. }
  280. if (st95hf_response_arr[0]) {
  281. dev_err(dev, "st95hf error from st95hf_spi_recv_response(), err = 0x%x\n",
  282. st95hf_response_arr[0]);
  283. return -EIO;
  284. }
  285. }
  286. return 0;
  287. }
  288. static int st95hf_echo_command(struct st95hf_context *st95context)
  289. {
  290. int result = 0;
  291. unsigned char echo_response;
  292. result = st95hf_send_recv_cmd(st95context, CMD_ECHO, 0, NULL, false);
  293. if (result)
  294. return result;
  295. /* If control reached here, response can be taken */
  296. result = st95hf_spi_recv_echo_res(&st95context->spicontext,
  297. &echo_response);
  298. if (result) {
  299. dev_err(&st95context->spicontext.spidev->dev,
  300. "err: echo response receieve error = 0x%x\n", result);
  301. return result;
  302. }
  303. if (echo_response == ECHORESPONSE)
  304. return 0;
  305. dev_err(&st95context->spicontext.spidev->dev, "err: echo res is 0x%x\n",
  306. echo_response);
  307. return -EIO;
  308. }
  309. static int secondary_configuration_type4a(struct st95hf_context *stcontext)
  310. {
  311. int result = 0;
  312. struct device *dev = &stcontext->nfcdev->dev;
  313. /* 14443A config setting after select protocol */
  314. result = st95hf_send_recv_cmd(stcontext,
  315. CMD_ISO14443A_CONFIG,
  316. 0,
  317. NULL,
  318. true);
  319. if (result) {
  320. dev_err(dev, "type a config cmd, err = 0x%x\n", result);
  321. return result;
  322. }
  323. /* 14443A demo gain setting */
  324. result = st95hf_send_recv_cmd(stcontext,
  325. CMD_ISO14443A_DEMOGAIN,
  326. 0,
  327. NULL,
  328. true);
  329. if (result)
  330. dev_err(dev, "type a demogain cmd, err = 0x%x\n", result);
  331. return result;
  332. }
  333. static int secondary_configuration_type4b(struct st95hf_context *stcontext)
  334. {
  335. int result = 0;
  336. struct device *dev = &stcontext->nfcdev->dev;
  337. result = st95hf_send_recv_cmd(stcontext,
  338. CMD_ISO14443B_DEMOGAIN,
  339. 0,
  340. NULL,
  341. true);
  342. if (result)
  343. dev_err(dev, "type b demogain cmd, err = 0x%x\n", result);
  344. return result;
  345. }
  346. static int st95hf_select_protocol(struct st95hf_context *stcontext, int type)
  347. {
  348. int result = 0;
  349. struct device *dev;
  350. dev = &stcontext->nfcdev->dev;
  351. switch (type) {
  352. case NFC_DIGITAL_RF_TECH_106A:
  353. stcontext->current_rf_tech = NFC_DIGITAL_RF_TECH_106A;
  354. result = st95hf_send_recv_cmd(stcontext,
  355. CMD_ISO14443A_PROTOCOL_SELECT,
  356. 0,
  357. NULL,
  358. true);
  359. if (result) {
  360. dev_err(dev, "protocol sel, err = 0x%x\n",
  361. result);
  362. return result;
  363. }
  364. /* secondary config. for 14443Type 4A after protocol select */
  365. result = secondary_configuration_type4a(stcontext);
  366. if (result) {
  367. dev_err(dev, "type a secondary config, err = 0x%x\n",
  368. result);
  369. return result;
  370. }
  371. break;
  372. case NFC_DIGITAL_RF_TECH_106B:
  373. stcontext->current_rf_tech = NFC_DIGITAL_RF_TECH_106B;
  374. result = st95hf_send_recv_cmd(stcontext,
  375. CMD_ISO14443B_PROTOCOL_SELECT,
  376. 0,
  377. NULL,
  378. true);
  379. if (result) {
  380. dev_err(dev, "protocol sel send, err = 0x%x\n",
  381. result);
  382. return result;
  383. }
  384. /*
  385. * delay of 5-6 ms is required after select protocol
  386. * command in case of ISO14443 Type B
  387. */
  388. usleep_range(50000, 60000);
  389. /* secondary config. for 14443Type 4B after protocol select */
  390. result = secondary_configuration_type4b(stcontext);
  391. if (result) {
  392. dev_err(dev, "type b secondary config, err = 0x%x\n",
  393. result);
  394. return result;
  395. }
  396. break;
  397. case NFC_DIGITAL_RF_TECH_ISO15693:
  398. stcontext->current_rf_tech = NFC_DIGITAL_RF_TECH_ISO15693;
  399. result = st95hf_send_recv_cmd(stcontext,
  400. CMD_ISO15693_PROTOCOL_SELECT,
  401. 0,
  402. NULL,
  403. true);
  404. if (result) {
  405. dev_err(dev, "protocol sel send, err = 0x%x\n",
  406. result);
  407. return result;
  408. }
  409. break;
  410. default:
  411. return -EINVAL;
  412. }
  413. return 0;
  414. }
  415. static void st95hf_send_st95enable_negativepulse(struct st95hf_context *st95con)
  416. {
  417. /* First make irq_in pin high */
  418. gpio_set_value(st95con->enable_gpio, HIGH);
  419. /* wait for 1 milisecond */
  420. usleep_range(1000, 2000);
  421. /* Make irq_in pin low */
  422. gpio_set_value(st95con->enable_gpio, LOW);
  423. /* wait for minimum interrupt pulse to make st95 active */
  424. usleep_range(1000, 2000);
  425. /* At end make it high */
  426. gpio_set_value(st95con->enable_gpio, HIGH);
  427. }
  428. /*
  429. * Send a reset sequence over SPI bus (Reset command + wait 3ms +
  430. * negative pulse on st95hf enable gpio
  431. */
  432. static int st95hf_send_spi_reset_sequence(struct st95hf_context *st95context)
  433. {
  434. int result = 0;
  435. unsigned char reset_cmd = ST95HF_COMMAND_RESET;
  436. result = st95hf_spi_send(&st95context->spicontext,
  437. &reset_cmd,
  438. ST95HF_RESET_CMD_LEN,
  439. ASYNC);
  440. if (result) {
  441. dev_err(&st95context->spicontext.spidev->dev,
  442. "spi reset sequence cmd error = %d", result);
  443. return result;
  444. }
  445. /* wait for 3 milisecond to complete the controller reset process */
  446. usleep_range(3000, 4000);
  447. /* send negative pulse to make st95hf active */
  448. st95hf_send_st95enable_negativepulse(st95context);
  449. /* wait for 10 milisecond : HFO setup time */
  450. usleep_range(10000, 20000);
  451. return result;
  452. }
  453. static int st95hf_por_sequence(struct st95hf_context *st95context)
  454. {
  455. int nth_attempt = 1;
  456. int result;
  457. st95hf_send_st95enable_negativepulse(st95context);
  458. usleep_range(5000, 6000);
  459. do {
  460. /* send an ECHO command and checks ST95HF response */
  461. result = st95hf_echo_command(st95context);
  462. dev_dbg(&st95context->spicontext.spidev->dev,
  463. "response from echo function = 0x%x, attempt = %d\n",
  464. result, nth_attempt);
  465. if (!result)
  466. return 0;
  467. /* send an pulse on IRQ in case of the chip is on sleep state */
  468. if (nth_attempt == 2)
  469. st95hf_send_st95enable_negativepulse(st95context);
  470. else
  471. st95hf_send_spi_reset_sequence(st95context);
  472. /* delay of 50 milisecond */
  473. usleep_range(50000, 51000);
  474. } while (nth_attempt++ < 3);
  475. return -ETIMEDOUT;
  476. }
  477. static int iso14443_config_fdt(struct st95hf_context *st95context, int wtxm)
  478. {
  479. int result = 0;
  480. struct device *dev = &st95context->spicontext.spidev->dev;
  481. struct nfc_digital_dev *nfcddev = st95context->ddev;
  482. unsigned char pp_typeb;
  483. struct param_list new_params[2];
  484. pp_typeb = cmd_array[CMD_ISO14443B_PROTOCOL_SELECT].cmd_params[2];
  485. if (nfcddev->curr_protocol == NFC_PROTO_ISO14443 &&
  486. st95context->fwi < 4)
  487. st95context->fwi = 4;
  488. new_params[0].param_offset = 2;
  489. if (nfcddev->curr_protocol == NFC_PROTO_ISO14443)
  490. new_params[0].new_param_val = st95context->fwi;
  491. else if (nfcddev->curr_protocol == NFC_PROTO_ISO14443_B)
  492. new_params[0].new_param_val = pp_typeb;
  493. new_params[1].param_offset = 3;
  494. new_params[1].new_param_val = wtxm;
  495. switch (nfcddev->curr_protocol) {
  496. case NFC_PROTO_ISO14443:
  497. result = st95hf_send_recv_cmd(st95context,
  498. CMD_ISO14443A_PROTOCOL_SELECT,
  499. 2,
  500. new_params,
  501. true);
  502. if (result) {
  503. dev_err(dev, "WTX type a sel proto, err = 0x%x\n",
  504. result);
  505. return result;
  506. }
  507. /* secondary config. for 14443Type 4A after protocol select */
  508. result = secondary_configuration_type4a(st95context);
  509. if (result) {
  510. dev_err(dev, "WTX type a second. config, err = 0x%x\n",
  511. result);
  512. return result;
  513. }
  514. break;
  515. case NFC_PROTO_ISO14443_B:
  516. result = st95hf_send_recv_cmd(st95context,
  517. CMD_ISO14443B_PROTOCOL_SELECT,
  518. 2,
  519. new_params,
  520. true);
  521. if (result) {
  522. dev_err(dev, "WTX type b sel proto, err = 0x%x\n",
  523. result);
  524. return result;
  525. }
  526. /* secondary config. for 14443Type 4B after protocol select */
  527. result = secondary_configuration_type4b(st95context);
  528. if (result) {
  529. dev_err(dev, "WTX type b second. config, err = 0x%x\n",
  530. result);
  531. return result;
  532. }
  533. break;
  534. default:
  535. return -EINVAL;
  536. }
  537. return 0;
  538. }
  539. static int st95hf_handle_wtx(struct st95hf_context *stcontext,
  540. bool new_wtx,
  541. int wtx_val)
  542. {
  543. int result = 0;
  544. unsigned char val_mm = 0;
  545. struct param_list new_params[1];
  546. struct nfc_digital_dev *nfcddev = stcontext->ddev;
  547. struct device *dev = &stcontext->nfcdev->dev;
  548. if (new_wtx) {
  549. result = iso14443_config_fdt(stcontext, wtx_val & 0x3f);
  550. if (result) {
  551. dev_err(dev, "Config. setting error on WTX req, err = 0x%x\n",
  552. result);
  553. return result;
  554. }
  555. /* Send response of wtx with ASYNC as no response expected */
  556. new_params[0].param_offset = 1;
  557. new_params[0].new_param_val = wtx_val;
  558. result = st95hf_send_recv_cmd(stcontext,
  559. CMD_WTX_RESPONSE,
  560. 1,
  561. new_params,
  562. false);
  563. if (result)
  564. dev_err(dev, "WTX response send, err = 0x%x\n", result);
  565. return result;
  566. }
  567. /* if no new wtx, cofigure with default values */
  568. if (nfcddev->curr_protocol == NFC_PROTO_ISO14443)
  569. val_mm = cmd_array[CMD_ISO14443A_PROTOCOL_SELECT].cmd_params[3];
  570. else if (nfcddev->curr_protocol == NFC_PROTO_ISO14443_B)
  571. val_mm = cmd_array[CMD_ISO14443B_PROTOCOL_SELECT].cmd_params[3];
  572. result = iso14443_config_fdt(stcontext, val_mm);
  573. if (result)
  574. dev_err(dev, "Default config. setting error after WTX processing, err = 0x%x\n",
  575. result);
  576. return result;
  577. }
  578. static int st95hf_error_handling(struct st95hf_context *stcontext,
  579. struct sk_buff *skb_resp,
  580. int res_len)
  581. {
  582. int result = 0;
  583. unsigned char error_byte;
  584. struct device *dev = &stcontext->nfcdev->dev;
  585. /* First check ST95HF specific error */
  586. if (skb_resp->data[0] & ST95HF_ERR_MASK) {
  587. if (skb_resp->data[0] == ST95HF_TIMEOUT_ERROR)
  588. result = -ETIMEDOUT;
  589. else
  590. result = -EIO;
  591. return result;
  592. }
  593. /* Check for CRC err only if CRC is present in the tag response */
  594. switch (stcontext->current_rf_tech) {
  595. case NFC_DIGITAL_RF_TECH_106A:
  596. if (stcontext->sendrcv_trflag == TRFLAG_NFCA_STD_FRAME_CRC) {
  597. error_byte = skb_resp->data[res_len - 3];
  598. if (error_byte & ST95HF_NFCA_CRC_ERR_MASK) {
  599. /* CRC error occurred */
  600. dev_err(dev, "CRC error, byte received = 0x%x\n",
  601. error_byte);
  602. result = -EIO;
  603. }
  604. }
  605. break;
  606. case NFC_DIGITAL_RF_TECH_106B:
  607. case NFC_DIGITAL_RF_TECH_ISO15693:
  608. error_byte = skb_resp->data[res_len - 1];
  609. if (error_byte & ST95HF_NFCB_CRC_ERR_MASK) {
  610. /* CRC error occurred */
  611. dev_err(dev, "CRC error, byte received = 0x%x\n",
  612. error_byte);
  613. result = -EIO;
  614. }
  615. break;
  616. }
  617. return result;
  618. }
  619. static int st95hf_response_handler(struct st95hf_context *stcontext,
  620. struct sk_buff *skb_resp,
  621. int res_len)
  622. {
  623. int result = 0;
  624. int skb_len;
  625. unsigned char val_mm;
  626. struct nfc_digital_dev *nfcddev = stcontext->ddev;
  627. struct device *dev = &stcontext->nfcdev->dev;
  628. struct st95_digital_cmd_complete_arg *cb_arg;
  629. cb_arg = &stcontext->complete_cb_arg;
  630. /* Process the response */
  631. skb_put(skb_resp, res_len);
  632. /* Remove st95 header */
  633. skb_pull(skb_resp, 2);
  634. skb_len = skb_resp->len;
  635. /* check if it is case of RATS request reply & FWI is present */
  636. if (nfcddev->curr_protocol == NFC_PROTO_ISO14443 && cb_arg->rats &&
  637. (skb_resp->data[1] & RATS_TB1_PRESENT_MASK)) {
  638. if (skb_resp->data[1] & RATS_TA1_PRESENT_MASK)
  639. stcontext->fwi =
  640. (skb_resp->data[3] & TB1_FWI_MASK) >> 4;
  641. else
  642. stcontext->fwi =
  643. (skb_resp->data[2] & TB1_FWI_MASK) >> 4;
  644. val_mm = cmd_array[CMD_ISO14443A_PROTOCOL_SELECT].cmd_params[3];
  645. result = iso14443_config_fdt(stcontext, val_mm);
  646. if (result) {
  647. dev_err(dev, "error in config_fdt to handle fwi of ATS, error=%d\n",
  648. result);
  649. return result;
  650. }
  651. }
  652. cb_arg->rats = false;
  653. /* Remove CRC bytes only if received frames data has an eod (CRC) */
  654. switch (stcontext->current_rf_tech) {
  655. case NFC_DIGITAL_RF_TECH_106A:
  656. if (stcontext->sendrcv_trflag == TRFLAG_NFCA_STD_FRAME_CRC)
  657. skb_trim(skb_resp, (skb_len - 5));
  658. else
  659. skb_trim(skb_resp, (skb_len - 3));
  660. break;
  661. case NFC_DIGITAL_RF_TECH_106B:
  662. case NFC_DIGITAL_RF_TECH_ISO15693:
  663. skb_trim(skb_resp, (skb_len - 3));
  664. break;
  665. }
  666. return result;
  667. }
  668. static irqreturn_t st95hf_irq_handler(int irq, void *st95hfcontext)
  669. {
  670. struct st95hf_context *stcontext =
  671. (struct st95hf_context *)st95hfcontext;
  672. if (stcontext->spicontext.req_issync) {
  673. complete(&stcontext->spicontext.done);
  674. stcontext->spicontext.req_issync = false;
  675. return IRQ_HANDLED;
  676. }
  677. return IRQ_WAKE_THREAD;
  678. }
  679. static irqreturn_t st95hf_irq_thread_handler(int irq, void *st95hfcontext)
  680. {
  681. int result = 0;
  682. int res_len;
  683. static bool wtx;
  684. struct device *dev;
  685. struct device *spidevice;
  686. struct nfc_digital_dev *nfcddev;
  687. struct sk_buff *skb_resp;
  688. struct st95hf_context *stcontext =
  689. (struct st95hf_context *)st95hfcontext;
  690. struct st95_digital_cmd_complete_arg *cb_arg;
  691. spidevice = &stcontext->spicontext.spidev->dev;
  692. /*
  693. * check semaphore, if not down() already, then we don't
  694. * know in which context the ISR is called and surely it
  695. * will be a bug. Note that down() of the semaphore is done
  696. * in the corresponding st95hf_in_send_cmd() and then
  697. * only this ISR should be called. ISR will up() the
  698. * semaphore before leaving. Hence when the ISR is called
  699. * the correct behaviour is down_trylock() should always
  700. * return 1 (indicating semaphore cant be taken and hence no
  701. * change in semaphore count).
  702. * If not, then we up() the semaphore and crash on
  703. * a BUG() !
  704. */
  705. if (!down_trylock(&stcontext->exchange_lock)) {
  706. up(&stcontext->exchange_lock);
  707. WARN(1, "unknown context in ST95HF ISR");
  708. return IRQ_NONE;
  709. }
  710. cb_arg = &stcontext->complete_cb_arg;
  711. skb_resp = cb_arg->skb_resp;
  712. mutex_lock(&stcontext->rm_lock);
  713. res_len = st95hf_spi_recv_response(&stcontext->spicontext,
  714. skb_resp->data);
  715. if (res_len < 0) {
  716. dev_err(spidevice, "TISR spi response err = 0x%x\n", res_len);
  717. result = res_len;
  718. goto end;
  719. }
  720. /* if stcontext->nfcdev_free is true, it means remove already ran */
  721. if (stcontext->nfcdev_free) {
  722. result = -ENODEV;
  723. goto end;
  724. }
  725. dev = &stcontext->nfcdev->dev;
  726. nfcddev = stcontext->ddev;
  727. if (skb_resp->data[2] == WTX_REQ_FROM_TAG) {
  728. /* Request for new FWT from tag */
  729. result = st95hf_handle_wtx(stcontext, true, skb_resp->data[3]);
  730. if (result)
  731. goto end;
  732. wtx = true;
  733. mutex_unlock(&stcontext->rm_lock);
  734. return IRQ_HANDLED;
  735. }
  736. result = st95hf_error_handling(stcontext, skb_resp, res_len);
  737. if (result)
  738. goto end;
  739. result = st95hf_response_handler(stcontext, skb_resp, res_len);
  740. if (result)
  741. goto end;
  742. /*
  743. * If select protocol is done on wtx req. do select protocol
  744. * again with default values
  745. */
  746. if (wtx) {
  747. wtx = false;
  748. result = st95hf_handle_wtx(stcontext, false, 0);
  749. if (result)
  750. goto end;
  751. }
  752. /* call digital layer callback */
  753. cb_arg->complete_cb(stcontext->ddev, cb_arg->cb_usrarg, skb_resp);
  754. /* up the semaphore before returning */
  755. up(&stcontext->exchange_lock);
  756. mutex_unlock(&stcontext->rm_lock);
  757. return IRQ_HANDLED;
  758. end:
  759. kfree_skb(skb_resp);
  760. wtx = false;
  761. cb_arg->rats = false;
  762. skb_resp = ERR_PTR(result);
  763. /* call of callback with error */
  764. cb_arg->complete_cb(stcontext->ddev, cb_arg->cb_usrarg, skb_resp);
  765. /* up the semaphore before returning */
  766. up(&stcontext->exchange_lock);
  767. mutex_unlock(&stcontext->rm_lock);
  768. return IRQ_HANDLED;
  769. }
  770. /* NFC ops functions definition */
  771. static int st95hf_in_configure_hw(struct nfc_digital_dev *ddev,
  772. int type,
  773. int param)
  774. {
  775. struct st95hf_context *stcontext = nfc_digital_get_drvdata(ddev);
  776. if (type == NFC_DIGITAL_CONFIG_RF_TECH)
  777. return st95hf_select_protocol(stcontext, param);
  778. if (type == NFC_DIGITAL_CONFIG_FRAMING) {
  779. switch (param) {
  780. case NFC_DIGITAL_FRAMING_NFCA_SHORT:
  781. stcontext->sendrcv_trflag = TRFLAG_NFCA_SHORT_FRAME;
  782. break;
  783. case NFC_DIGITAL_FRAMING_NFCA_STANDARD:
  784. stcontext->sendrcv_trflag = TRFLAG_NFCA_STD_FRAME;
  785. break;
  786. case NFC_DIGITAL_FRAMING_NFCA_T4T:
  787. case NFC_DIGITAL_FRAMING_NFCA_NFC_DEP:
  788. case NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A:
  789. stcontext->sendrcv_trflag = TRFLAG_NFCA_STD_FRAME_CRC;
  790. break;
  791. case NFC_DIGITAL_FRAMING_NFCB:
  792. case NFC_DIGITAL_FRAMING_ISO15693_INVENTORY:
  793. case NFC_DIGITAL_FRAMING_ISO15693_T5T:
  794. break;
  795. }
  796. }
  797. return 0;
  798. }
  799. static int rf_off(struct st95hf_context *stcontext)
  800. {
  801. int rc;
  802. struct device *dev;
  803. dev = &stcontext->nfcdev->dev;
  804. rc = st95hf_send_recv_cmd(stcontext, CMD_FIELD_OFF, 0, NULL, true);
  805. if (rc)
  806. dev_err(dev, "protocol sel send field off, err = 0x%x\n", rc);
  807. return rc;
  808. }
  809. static int st95hf_in_send_cmd(struct nfc_digital_dev *ddev,
  810. struct sk_buff *skb,
  811. u16 timeout,
  812. nfc_digital_cmd_complete_t cb,
  813. void *arg)
  814. {
  815. struct st95hf_context *stcontext = nfc_digital_get_drvdata(ddev);
  816. int rc;
  817. struct sk_buff *skb_resp;
  818. int len_data_to_tag = 0;
  819. skb_resp = nfc_alloc_recv_skb(MAX_RESPONSE_BUFFER_SIZE, GFP_KERNEL);
  820. if (!skb_resp) {
  821. rc = -ENOMEM;
  822. goto error;
  823. }
  824. switch (stcontext->current_rf_tech) {
  825. case NFC_DIGITAL_RF_TECH_106A:
  826. len_data_to_tag = skb->len + 1;
  827. *skb_put(skb, 1) = stcontext->sendrcv_trflag;
  828. break;
  829. case NFC_DIGITAL_RF_TECH_106B:
  830. case NFC_DIGITAL_RF_TECH_ISO15693:
  831. len_data_to_tag = skb->len;
  832. break;
  833. default:
  834. rc = -EINVAL;
  835. goto free_skb_resp;
  836. }
  837. skb_push(skb, 3);
  838. skb->data[0] = ST95HF_COMMAND_SEND;
  839. skb->data[1] = SEND_RECEIVE_CMD;
  840. skb->data[2] = len_data_to_tag;
  841. stcontext->complete_cb_arg.skb_resp = skb_resp;
  842. stcontext->complete_cb_arg.cb_usrarg = arg;
  843. stcontext->complete_cb_arg.complete_cb = cb;
  844. if ((skb->data[3] == ISO14443A_RATS_REQ) &&
  845. ddev->curr_protocol == NFC_PROTO_ISO14443)
  846. stcontext->complete_cb_arg.rats = true;
  847. /*
  848. * down the semaphore to indicate to remove func that an
  849. * ISR is pending, note that it will not block here in any case.
  850. * If found blocked, it is a BUG!
  851. */
  852. rc = down_killable(&stcontext->exchange_lock);
  853. if (rc) {
  854. WARN(1, "Semaphore is not found up in st95hf_in_send_cmd\n");
  855. return rc;
  856. }
  857. rc = st95hf_spi_send(&stcontext->spicontext, skb->data,
  858. skb->len,
  859. ASYNC);
  860. if (rc) {
  861. dev_err(&stcontext->nfcdev->dev,
  862. "Error %d trying to perform data_exchange", rc);
  863. /* up the semaphore since ISR will never come in this case */
  864. up(&stcontext->exchange_lock);
  865. goto free_skb_resp;
  866. }
  867. kfree_skb(skb);
  868. return rc;
  869. free_skb_resp:
  870. kfree_skb(skb_resp);
  871. error:
  872. return rc;
  873. }
  874. /* p2p will be supported in a later release ! */
  875. static int st95hf_tg_configure_hw(struct nfc_digital_dev *ddev,
  876. int type,
  877. int param)
  878. {
  879. return 0;
  880. }
  881. static int st95hf_tg_send_cmd(struct nfc_digital_dev *ddev,
  882. struct sk_buff *skb,
  883. u16 timeout,
  884. nfc_digital_cmd_complete_t cb,
  885. void *arg)
  886. {
  887. return 0;
  888. }
  889. static int st95hf_tg_listen(struct nfc_digital_dev *ddev,
  890. u16 timeout,
  891. nfc_digital_cmd_complete_t cb,
  892. void *arg)
  893. {
  894. return 0;
  895. }
  896. static int st95hf_tg_get_rf_tech(struct nfc_digital_dev *ddev, u8 *rf_tech)
  897. {
  898. return 0;
  899. }
  900. static int st95hf_switch_rf(struct nfc_digital_dev *ddev, bool on)
  901. {
  902. u8 rf_tech;
  903. struct st95hf_context *stcontext = nfc_digital_get_drvdata(ddev);
  904. rf_tech = ddev->curr_rf_tech;
  905. if (on)
  906. /* switch on RF field */
  907. return st95hf_select_protocol(stcontext, rf_tech);
  908. /* switch OFF RF field */
  909. return rf_off(stcontext);
  910. }
  911. /* TODO st95hf_abort_cmd */
  912. static void st95hf_abort_cmd(struct nfc_digital_dev *ddev)
  913. {
  914. }
  915. static struct nfc_digital_ops st95hf_nfc_digital_ops = {
  916. .in_configure_hw = st95hf_in_configure_hw,
  917. .in_send_cmd = st95hf_in_send_cmd,
  918. .tg_listen = st95hf_tg_listen,
  919. .tg_configure_hw = st95hf_tg_configure_hw,
  920. .tg_send_cmd = st95hf_tg_send_cmd,
  921. .tg_get_rf_tech = st95hf_tg_get_rf_tech,
  922. .switch_rf = st95hf_switch_rf,
  923. .abort_cmd = st95hf_abort_cmd,
  924. };
  925. static const struct spi_device_id st95hf_id[] = {
  926. { "st95hf", 0 },
  927. {}
  928. };
  929. MODULE_DEVICE_TABLE(spi, st95hf_id);
  930. static int st95hf_probe(struct spi_device *nfc_spi_dev)
  931. {
  932. int ret;
  933. struct st95hf_context *st95context;
  934. struct st95hf_spi_context *spicontext;
  935. nfc_info(&nfc_spi_dev->dev, "ST95HF driver probe called.\n");
  936. st95context = devm_kzalloc(&nfc_spi_dev->dev,
  937. sizeof(struct st95hf_context),
  938. GFP_KERNEL);
  939. if (!st95context)
  940. return -ENOMEM;
  941. spicontext = &st95context->spicontext;
  942. spicontext->spidev = nfc_spi_dev;
  943. st95context->fwi =
  944. cmd_array[CMD_ISO14443A_PROTOCOL_SELECT].cmd_params[2];
  945. if (device_property_present(&nfc_spi_dev->dev, "st95hfvin")) {
  946. st95context->st95hf_supply =
  947. devm_regulator_get(&nfc_spi_dev->dev,
  948. "st95hfvin");
  949. if (IS_ERR(st95context->st95hf_supply)) {
  950. dev_err(&nfc_spi_dev->dev, "failed to acquire regulator\n");
  951. return PTR_ERR(st95context->st95hf_supply);
  952. }
  953. ret = regulator_enable(st95context->st95hf_supply);
  954. if (ret) {
  955. dev_err(&nfc_spi_dev->dev, "failed to enable regulator\n");
  956. return ret;
  957. }
  958. }
  959. init_completion(&spicontext->done);
  960. mutex_init(&spicontext->spi_lock);
  961. /*
  962. * Store spicontext in spi device object for using it in
  963. * remove function
  964. */
  965. dev_set_drvdata(&nfc_spi_dev->dev, spicontext);
  966. st95context->enable_gpio =
  967. of_get_named_gpio(nfc_spi_dev->dev.of_node,
  968. "enable-gpio",
  969. 0);
  970. if (!gpio_is_valid(st95context->enable_gpio)) {
  971. dev_err(&nfc_spi_dev->dev, "No valid enable gpio\n");
  972. ret = st95context->enable_gpio;
  973. goto err_disable_regulator;
  974. }
  975. ret = devm_gpio_request_one(&nfc_spi_dev->dev, st95context->enable_gpio,
  976. GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
  977. "enable_gpio");
  978. if (ret)
  979. goto err_disable_regulator;
  980. if (nfc_spi_dev->irq > 0) {
  981. if (devm_request_threaded_irq(&nfc_spi_dev->dev,
  982. nfc_spi_dev->irq,
  983. st95hf_irq_handler,
  984. st95hf_irq_thread_handler,
  985. IRQF_TRIGGER_FALLING,
  986. "st95hf",
  987. (void *)st95context) < 0) {
  988. dev_err(&nfc_spi_dev->dev, "err: irq request for st95hf is failed\n");
  989. ret = -EINVAL;
  990. goto err_disable_regulator;
  991. }
  992. } else {
  993. dev_err(&nfc_spi_dev->dev, "not a valid IRQ associated with ST95HF\n");
  994. ret = -EINVAL;
  995. goto err_disable_regulator;
  996. }
  997. /*
  998. * First reset SPI to handle warm reset of the system.
  999. * It will put the ST95HF device in Power ON state
  1000. * which make the state of device identical to state
  1001. * at the time of cold reset of the system.
  1002. */
  1003. ret = st95hf_send_spi_reset_sequence(st95context);
  1004. if (ret) {
  1005. dev_err(&nfc_spi_dev->dev, "err: spi_reset_sequence failed\n");
  1006. goto err_disable_regulator;
  1007. }
  1008. /* call PowerOnReset sequence of ST95hf to activate it */
  1009. ret = st95hf_por_sequence(st95context);
  1010. if (ret) {
  1011. dev_err(&nfc_spi_dev->dev, "err: por seq failed for st95hf\n");
  1012. goto err_disable_regulator;
  1013. }
  1014. /* create NFC dev object and register with NFC Subsystem */
  1015. st95context->ddev = nfc_digital_allocate_device(&st95hf_nfc_digital_ops,
  1016. ST95HF_SUPPORTED_PROT,
  1017. ST95HF_CAPABILITIES,
  1018. ST95HF_HEADROOM_LEN,
  1019. ST95HF_TAILROOM_LEN);
  1020. if (!st95context->ddev) {
  1021. ret = -ENOMEM;
  1022. goto err_disable_regulator;
  1023. }
  1024. st95context->nfcdev = st95context->ddev->nfc_dev;
  1025. nfc_digital_set_parent_dev(st95context->ddev, &nfc_spi_dev->dev);
  1026. ret = nfc_digital_register_device(st95context->ddev);
  1027. if (ret) {
  1028. dev_err(&st95context->nfcdev->dev, "st95hf registration failed\n");
  1029. goto err_free_digital_device;
  1030. }
  1031. /* store st95context in nfc device object */
  1032. nfc_digital_set_drvdata(st95context->ddev, st95context);
  1033. sema_init(&st95context->exchange_lock, 1);
  1034. mutex_init(&st95context->rm_lock);
  1035. return ret;
  1036. err_free_digital_device:
  1037. nfc_digital_free_device(st95context->ddev);
  1038. err_disable_regulator:
  1039. if (st95context->st95hf_supply)
  1040. regulator_disable(st95context->st95hf_supply);
  1041. return ret;
  1042. }
  1043. static int st95hf_remove(struct spi_device *nfc_spi_dev)
  1044. {
  1045. int result = 0;
  1046. unsigned char reset_cmd = ST95HF_COMMAND_RESET;
  1047. struct st95hf_spi_context *spictx = dev_get_drvdata(&nfc_spi_dev->dev);
  1048. struct st95hf_context *stcontext = container_of(spictx,
  1049. struct st95hf_context,
  1050. spicontext);
  1051. mutex_lock(&stcontext->rm_lock);
  1052. nfc_digital_unregister_device(stcontext->ddev);
  1053. nfc_digital_free_device(stcontext->ddev);
  1054. stcontext->nfcdev_free = true;
  1055. mutex_unlock(&stcontext->rm_lock);
  1056. /* if last in_send_cmd's ISR is pending, wait for it to finish */
  1057. result = down_killable(&stcontext->exchange_lock);
  1058. if (result == -EINTR)
  1059. dev_err(&spictx->spidev->dev, "sleep for semaphore interrupted by signal\n");
  1060. /* next reset the ST95HF controller */
  1061. result = st95hf_spi_send(&stcontext->spicontext,
  1062. &reset_cmd,
  1063. ST95HF_RESET_CMD_LEN,
  1064. ASYNC);
  1065. if (result) {
  1066. dev_err(&spictx->spidev->dev,
  1067. "ST95HF reset failed in remove() err = %d\n", result);
  1068. return result;
  1069. }
  1070. /* wait for 3 ms to complete the controller reset process */
  1071. usleep_range(3000, 4000);
  1072. /* disable regulator */
  1073. if (stcontext->st95hf_supply)
  1074. regulator_disable(stcontext->st95hf_supply);
  1075. return result;
  1076. }
  1077. /* Register as SPI protocol driver */
  1078. static struct spi_driver st95hf_driver = {
  1079. .driver = {
  1080. .name = "st95hf",
  1081. .owner = THIS_MODULE,
  1082. },
  1083. .id_table = st95hf_id,
  1084. .probe = st95hf_probe,
  1085. .remove = st95hf_remove,
  1086. };
  1087. module_spi_driver(st95hf_driver);
  1088. MODULE_AUTHOR("Shikha Singh <shikha.singh@st.com>");
  1089. MODULE_DESCRIPTION("ST NFC Transceiver ST95HF driver");
  1090. MODULE_LICENSE("GPL v2");