summaryrefslogtreecommitdiff
path: root/drivers/nfc/st95hf/spi.h
blob: 552d220747cdca72db613e65c7e1b393ef99df1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * ---------------------------------------------------------------------------
 * drivers/nfc/st95hf/spi.h functions declarations for SPI communication
 * ---------------------------------------------------------------------------
 * Copyright (C) 2015 STMicroelectronics – All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __LINUX_ST95HF_SPI_H
#define __LINUX_ST95HF_SPI_H

#include <linux/spi/spi.h>

/* Basic ST95HF SPI CMDs */
#define ST95HF_COMMAND_SEND	0x0
#define ST95HF_COMMAND_RESET	0x1
#define ST95HF_COMMAND_RECEIVE	0x2

#define ST95HF_RESET_CMD_LEN	0x1

/*
 * structure to contain st95hf spi communication specific information.
 * @req_issync: true for synchronous calls.
 * @spidev: st95hf spi device object.
 * @done: completion structure to wait for st95hf response
 *	for synchronous calls.
 * @spi_lock: mutex to allow only one spi transfer at a time.
 */
struct st95hf_spi_context {
	bool req_issync;
	struct spi_device *spidev;
	struct completion done;
	struct mutex spi_lock;
};

/* flag to differentiate synchronous & asynchronous spi request */
enum req_type {
	SYNC,
	ASYNC,
};

int st95hf_spi_send(struct st95hf_spi_context *spicontext,
		    unsigned char *buffertx,
		    int datalen,
		    enum req_type reqtype);

int st95hf_spi_recv_response(struct st95hf_spi_context *spicontext,
			     unsigned char *receivebuff);

int st95hf_spi_recv_echo_res(struct st95hf_spi_context *spicontext,
			     unsigned char *receivebuff);

#endif