Commit graph

468576 commits

Author SHA1 Message Date
Christophe Ricard
941ec5c6b0 NFC: st21nfcb: Add ISO15693 Reader/Writer support
Add support for ISO/IEC 15693 RF technology and Type 5 tags.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 02:02:24 +02:00
Christophe Ricard
9e87f9a9c4 NFC: nci: Add support for proprietary RF Protocols
In NFC Forum NCI specification, some RF Protocol values are
reserved for proprietary use (from 0x80 to 0xfe).
Some CLF vendor may need to use one value within this range
for specific technology.
Furthermore, some CLF may not becompliant with NFC Froum NCI
specification 2.0 and therefore will not support RF Protocol
value 0x06 for PROTOCOL_T5T as mention in a draft specification
and in a recent push.

Adding get_rf_protocol handle to the nci_ops structure will
help to set the correct technology to target.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 02:02:24 +02:00
Christophe Ricard
fa0daa02fb NFC: st21nfcb: Fix improper ndlc T2 management
T2 was never started when sending a command.
Start it when sending a command for the first attempt
and stop it once we receive the answer.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 02:02:23 +02:00
Christophe Ricard
4294e32040 NFC: st21nfcb: Fix improper management of -EREMOTEIO error code.
On st21nfcb the irq line might be kept to active state because of other
interfaces activity. This may generate i2c read tentative resulting in
i2c NACK.

This fix will currently let NDLC upper layer to decide when it is relevent
to signal to the physical layer when the chip as muted.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 02:02:23 +02:00
Christophe Ricard
f06d87a5b5 NFC: dts: st21nfcb_i2c: Fix invalid interrupts polarity.
St21nfcb has a reverse polarity compare to st21nfca.
In st21nfcb case, the irq pin is active high.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 02:02:23 +02:00
Christophe Ricard
90d5f81afc NFC: st21nfca: Fix recursive fault when doing p2p in target mode.
This patch fix a previous patch introduce by commit	0a91e8ac24

It is actually fixing a double free mistake in all st21nfca_tm_* function.
We decide to return directly in case of successful execution because skb
got already freed. In st21nfca_tm_recv_dep_req it got freed by nfc_tm_data_received.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 02:02:23 +02:00
Christophe Ricard
ecc6522b08 NFC: st21nfca: Fix potential skb leaks in NFC-DEP code
After a unsuccessful call to nfc_hci_send_event the skb was not
freed and might lead to memory leak.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 02:02:23 +02:00
Christophe Ricard
cc3faac9d8 NFC: st21nfca: Fix few coding style issue
Fix few conding style issue such as useless line return or tab.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 02:02:23 +02:00
Mark A. Greer
fc0ae24386 NFC: trf7970a: Unlock mutex before exiting _trf7970a_tg_listen()
The recently added _trf7970a_tg_listen() routine
has some return paths that don't unlock the mutex
that is locked when the routine is entered.  Fix
this by always unlocking the mutex before returning.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 00:28:23 +02:00
Mark A. Greer
b9e3016a53 NFC: trf7970a: Unlock mutex before exiting trf7970a_irq()
Recent changes to trf7970a_irq() added a couple return
paths that don't unlock the mutex that is locked when
the routine is entered.  Fix this by ensuring the mutex
is always unlocked before returning.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 00:28:23 +02:00
Mark A. Greer
55ef2e75cc NFC: trf7970a: Remove unnecessary local variable initialization
There is no need to initialize the 'ret' variable
in trf7970a_resume().

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 00:28:23 +02:00
Mark A. Greer
671970f531 NFC: trf7970a: Remove useless local variable
The trf7970a_suspend() routine always returns
zero so don't use a local return variable to
hold the return value.  This fixes up a smatch
warning.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-24 00:28:22 +02:00
Christophe Ricard
890c165261 NFC: st21nfcb: Remove useless headers
Remove some headers as they are:
- not relevent for st21nfcb.
- called multiple times for no reason: example st21nfcb.h already include
ndlc.h.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:31:51 +02:00
Christophe Ricard
0a91e8ac24 NFC: st21nfca: fix "WARNING: else is not generally useful after a break or return"
scripts/checkpatch.pl -f drivers/nfc/st21nfca.c is throwing the following:
WARNING: else is not generally useful after a break or return
#866: FILE: drivers/nfc/st21nfca/st21nfca.c:866:
+			return 0;
+		} else {

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:31:38 +02:00
Christophe Ricard
efaf956ad6 NFC: st21nfca: Clean up macros alignment
Align every macros on the same column.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:30:20 +02:00
Christophe Ricard
cebe222442 NFC: st21nfca: Clean up st21nfca.h macros
Clean up st21nfca.h macros and move the one only used in st21nfca.c.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:30:15 +02:00
Christophe Ricard
ac633ba6ac NFC: st21nfcb: Fix logic when running into i2c read retry
When retrying to read the NCI header, the CLF might not be
available the first time. However it may not be successful
the second time and this may cause an error in the function.
Enforce the retrieve data length is as expected.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:29:50 +02:00
Christophe Ricard
56f1ffcccd NFC: st21nfca: Add condition to make sure atr_req->length is valid.
gb_len in st21nfca_tm_send_atr_res can be negative. Not checking for
that could lead to a potential kernel oops.
We now make sure that atr_req->length > sizeof(struct st21nfca_atr_req)
to avoid such situation.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:07:44 +02:00
Christophe Ricard
a51577c9e3 NFC: st21nfca: Remove useless IS_ERR(skb) conditions
skb is already verified to be not null from the below hci layer.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:04:22 +02:00
Christophe Ricard
32b41d8f75 NFC: st21nfca: Remove useless err == 0 condition
On top of st21nfca_im_recv_atr_res_cb and st21nfca_im_recv_dep_res_cb a
condition if (err != 0) is present. Because err is never modified in the
code err will always be 0 at the end.

The condition can be removed.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:04:22 +02:00
Christophe Ricard
72030a2eeb NFC: st21nfca: Change nfcid3 generation
nfcid3 is based on sensf_res value. target->sensf is never NULL
as it is a table.
Check the sensf_res_len instead to make sure sensf_res is set or not.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-08 00:04:21 +02:00
Christophe Ricard
06ed3d607b NFC: st21nfca: Remove useless new line in nfc_err call
Remove a useless new line in nfc_err call.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:49 +02:00
Christophe Ricard
9ec1f58b9a NFC: st21nfca: Fix logic when setting session_id
If dev_num >= ST21NFCA_NUM_DEVICES, the driver was returning an incorrect
success return code.

Once dev_num is set, it was not stated as busy.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:49 +02:00
Christophe Ricard
df2566fe37 NFC: st21nfcb: Remove inappropriate kfree on a previously devm_kzalloc pointer
In case of an error during driver probe, info pointer was freed with kfree.
No need to free anything when using devm_kzalloc.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:48 +02:00
Christophe Ricard
2c376a9e3c NFC: st21nfcb: Remove useless new line in nfc_err call
Remove a uselss new line in nfc_err call.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:48 +02:00
Christophe Ricard
d363d7d0a5 NFC: st21nfcb: Remove double assignment of .owner in struct device_driver
The .owner member of struct device_driver is assigned THIS_MODULE twice.

Introduced by:

commit 35630df68d
NFC: st21nfcb: Add driver for STMicroelectronics ST21NFCB NFC chip

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:48 +02:00
Christophe Ricard
56ee645e30 NFC: st21nfcb: Convert to use devm_gpio_request_one
Simplify the code a bit as mention by Axel Lin in a previous patch for
st21nfca.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:47 +02:00
Christophe Ricard
361325e21d NFC: st21nfcb: Fix scripts/checkpatch.pl error "code indent should use tabs where possible"
Fixing scripts/checkpatch.pl error "code indent should use tabs where possible" in:
- i2c.c in st21nfcb_nci_irq_thread_fn function.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:47 +02:00
Christophe Ricard
3e6df9191a NFC: st21nfca: Fix scripts/checkpatch.pl warnings "Missing a blank line after declarations"
Fixing scripts/checkpatch.pl warning "Missing a blank line after declarations" in:
- st21nfca.c:
	- check_presence after fwi variable declaration.
	- get_frame_size after len variable declaration.
	- st21nfca_hci_i2c_repack after "i, j, r, size" variable declaration.

- st21nfca_dep.c st21nfca_tx_work after skb pointer declaration.

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:46 +02:00
Christophe Ricard
6ae3ed1c52 NFC: st21nfca: Fix sparse: cast to restricted __be32
Fixing "sparse: cast to restricted __be32" message when building with
make C=1 CF=-D__CHECK_ENDIAN__

Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:46 +02:00
Axel Lin
0be8ce737c NFC: st21nfca: Convert to use devm_gpio_request_one
This simplifies the code a bit.

Acked-by: Christophe RICARD <christophe-h.ricard@st.com>
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:46 +02:00
Emil Goode
ce3a5de7f5 NFC: st21nfca: Remove double assignment of .owner in struct device_driver
The .owner member of struct device_driver is assigned THIS_MODULE twice.

Introduced by:

commit c44cb2edd0
("NFC: dts: st21nfca: Add device-tree (Open Firmware) support to st21nfca")

Acked-by: Christophe RICARD <christophe-h.ricard@st.com>
Signed-off-by: Emil Goode <emilgoode@gmail.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:56:45 +02:00
Mark A. Greer
cb174aba86 NFC: trf7970a: Add Target Mode Detection Support
Add the ability to detect the mode (i.e., RF technology)
used by the initiator.  The RF technology that was
detected can be retrieved by calling the 'tg_get_rf_tech'
driver hook.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:45 +02:00
Mark A. Greer
13b4272a82 NFC: trf7970a: Add Target Mode Support
Add target mode support to the trf7970a
NFC driver.  This effectively enables full
Peer-to-Peer support.

To handle changing framing between sending
a response frame and receiving the subsequent
request frame, most of the framing changes
take effect in the interrupt handler and not
in trf7970a_tg_config_framing().

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:45 +02:00
Mark A. Greer
1961843cee NFC: trf7970a: Handle timeout values of zero
The digital layer can try to send a command with a
timeout value of zero (e.g., digital_tg_send_psl_res().
The zero value is used as a flag to indicate that
the driver should not expect a response.  To handle
this, the driver sets an internal timer because it
should still get an interrupt with the TX bit set
in the IRQ Status Register.  When it gets that
interrupt, it returns a return value of '0'.
If it doesn't get the interrupt before timing out,
it returns ETIMEDOUT as usual.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:45 +02:00
Mark A. Greer
6fb9edcb43 NFC: trf7970a: Cancel timer when error encountered
Some paths leave a timer still running when
trf7970a_send_err_upstream() is called.  This
can cause a timeout to occur in a subsequent
transaction making it fail.  Fix this by ensuring
there is no timer running before sending an error
upstream.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:45 +02:00
Mark A. Greer
851ee3cbf8 NFC: trf7970a: Don't turn on RF if there is already an RF field
Currently, the trf7970a driver blindly turns on its
RF field when configuring its framing.  This isn't
a good idea if there is already a device generating
an RF field.  Instead, check if there is already an
RF field present before turning on this device's RF
field and, if there is, return EBUSY.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:45 +02:00
Mark A. Greer
7149d6bfec NFC: trf7970a: trf7970a_init() turns off the RF transmitter
When trf7970a_init() initializes the trf7970a it
implicitly turns off the RF transmitter.  Track
this by clearing the TRF7970A_CHIP_STATUS_RF_ON
bit in the cached trf->chip_status_ctrl.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:45 +02:00
Mark A. Greer
cfc708dbe4 NFC: trf7970a: Don't turn off RF if its already off
Don't try to turn off of RF transmitter is its
already off.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:45 +02:00
Mark A. Greer
307e5caf6f NFC: trf7970a: Add '_in_' to initiator routines
Rename trf7970a_config_rf_tech() and trf7970a_config_framing()
to trf7970a_in_config_rf_tech() and trf7970a_in_config_framing(),
respectively to avoid confusion when target support is added.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:45 +02:00
Mark A. Greer
4e007f8106 NFC: trf7970a: Delay after initialization
The trf7970a should be given at least 1 ms to
completely initialize after the 'Software Init'
and 'Idle' commands have been issued.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
77c9539dc1 NFC: trf7970a: Add System Suspend/Resume support
Add system suspend/resume support by gracefully
shutting things down when suspending and bringing
the device back to full power when resuming.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
b528281b8b NFC: trf7970a: Create startup and shutdown routines
Encapsulate the code to start up and gracefully
shutdown the driver and trf7970a device.  Doing
this makes adding system suspend/resume support
easier and the resulting code cleaner.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
ceccd6aa50 NFC: trf7970a: Don't assume CONFIG_PM_RUNTIME is enabled
The current code assumes that CONFIG_PM_RUNTIME
is always defined so it won't power up the trf7970a
when it isn't enabled.  Fix this by moving the power
up/down code from the pm_runtime_resume/suspend
routines into their own routines and calling the
power up function from the probe routine.  This
ensures the device is powered up even when
CONFIG_PM_RUNTIME is not defined.

In order to not power on/off a device that is
already powered on/off, create a new state to
indicate that the power is off (TRF7970A_ST_PWR_OFF).

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
b5e17d9b5b NFC: trf7970a: Rename TRF7970A_ST_OFF to TRF7970A_ST_RF_OFF
Rename the 'TRF7970A_ST_OFF' state to 'TRF7970A_ST_RF_OFF'
to make it clear that this state means that the RF is
off and not the entire device.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
0a1de84205 NFC: trf7970a: Return error code when turning on RF fails
trf7970a_switch_rf_on() is currently a void function
but turning on the RF could fail so it should return
a return code.  That return code should also be
propagated back to the entity that initiated the
action.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
afa5b5f13e NFC: trf7970a: Ensure no more RX data before completing receive
Depending on the interrupt status value given by the
trf7970a, the driver may not know when a receive operation
is complete.  To handle this, the driver waits for a period
of time in case the trf7970a interrupts it again indicating
there are more RX data in the FIFO.  It is possible that the
timeout will occur when there are RX data in the FIFO but
before the trf7970a has generated an interrupt to tell the
driver about it.  Handle this by calling trf7970a_drain_fifo()
(instead of trf7970a_send_upstream() which just passes up the
data gathered to far) to check if there are more data in the
FIFO.  If so, gather that data into the receive buffer.  If
not, pass the data collected so far upstream as before.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
5d8f759424 NFC: trf7970a: Reread FIFO Status Register when draining FIFO
Receiving an interrupt whose Interrupt Status Register
value has only the SRX bit set is supposed to mean that
all of the data from the tag has been received.  That
turns out to not be true so we need to reread the FIFO
Status Register to tell if there are any new bytes in
the FIFO.  If there are, continue receiving them; if
there aren't, assume that the receive is complete and
pass the data up.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
bece3c544f NFC: trf7970a: Handle low-watermark IRQ when transmitting
Commit 4dd836e46c ("NFC: trf7970a: Reset FIFO when
'End of TX' Interrupt Occurs") fixes the issue that
it was meant to fix but adds the unfortunate side
effect of causing the driver to report an error
when the TX low-watermark level is passed during
transmits.  This can be fixed by checking whether
the IRQ status indicates that the low-watermark
has been passed when transmitting.  If it has been
passed and the FIFO is empty, then its safe to reset
the FIFO.  Otherwise, silently continue since another
TX interrupt will be generated and the FIFO will be
reset then.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:44 +02:00
Mark A. Greer
0e840ed59b NFC: trf7970a: Only fill FIFO if there is space
Handle the case where trf7970a_fill_fifo() is
called but there is no room in the FIFO for
more TX data.  When this happens, wait for
another interrupt indicating that there is
now space (and set a timer in case that
interrupt never occurs).

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07 23:13:43 +02:00