summaryrefslogtreecommitdiff
path: root/drivers/nfc/trf7970a.c
AgeCommit message (Collapse)Author
2016-07-04NFC: trf7970a: add TI recommended write of zero to Register 0x18Geoff Lansberry
Signed-off-by: Geoff Lansberry <geoff@kuvee.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-12-29NFC: trf7970a: use to_spi_deviceGeliang Tang
Use to_spi_device() instead of open-coding it. Signed-off-by: Geliang Tang <geliangtang@163.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-11-05Merge tag 'spi-v4.4' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi Pull spi updates from Mark Brown: "Quite a lot of activity in SPI this cycle, almost all of it in drivers with a few minor improvements and tweaks in the core. - Updates to pxa2xx to support Intel Broxton and multiple chip selects. - Support for big endian in the bcm63xx driver. - Multiple slave support for the mt8173 - New driver for the auxiliary SPI controller in bcm2835 SoCs. - Support for Layerscale SoCs in the Freescale DSPI driver" * tag 'spi-v4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (87 commits) spi: pxa2xx: Rework self-initiated platform data creation for non-ACPI spi: pxa2xx: Add support for Intel Broxton spi: pxa2xx: Detect number of enabled Intel LPSS SPI chip select signals spi: pxa2xx: Add output control for multiple Intel LPSS chip selects spi: pxa2xx: Use LPSS prefix for defines that are Intel LPSS specific spi: Add DSPI support for layerscape family spi: ti-qspi: improve ->remove() callback spi/spi-xilinx: Fix race condition on last word read spi: Drop owner assignment from spi_drivers spi: Add THIS_MODULE to spi_driver in SPI core spi: Setup the master controller driver before setting the chipselect spi: dw: replace magic constant by DW_SPI_DR spi: mediatek: mt8173 spi multiple devices support spi: mediatek: handle controller_data in mtk_spi_setup spi: mediatek: remove mtk_spi_config spi: mediatek: Update document devicetree bindings to support multiple devices spi: fix kernel-doc warnings about missing return desc in spi.c spi: fix kernel-doc warnings about missing return desc in spi.h spi: pxa2xx: Align a few defines spi: pxa2xx: Save other reg_cs_ctrl bits when configuring chip select ...
2015-10-28spi: Drop owner assignment from spi_driversAndrew F. Davis
An spi_driver does not need to set an owner, it will be populated by the driver core. Signed-off-by: Andrew F. Davis <afd@ti.com> Acked-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Mark Brown <broonie@kernel.org>
2015-10-19NFC: trf7970a: Add OF match tableJavier Martinez Canillas
The Documentation/devicetree/bindings/net/nfc/trf7970a.txt DT binding doc lists "ti,trf7970a" as a compatible string but the corresponding driver does not have an OF match table. Add the table to the driver so the SPI core can do an OF style match. Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-08-19NFC: trf7970a: Add NULL check to clear up smatch warningMark Greer
Although it should be unnecessary, add a NULL pointer check to trf7970a_send_upstream() to eliminate a smatch warning. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Mark Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-08-19NFC: trf7970a: SDD_EN is bit 5 not bit 3Mark Greer
The SDD_EN bit in the NFC Target Detection Level Register is bit 5 not bit 3 so change the TRF7970A_NFC_TARGET_LEVEL_SDD_EN macro accordingly. Reported-by: Raymond Lei <Raymond.Lei@ecolab.com> Signed-off-by: Mark Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-06-08NFC: trf7970a: Handle extra byte in response to Type 5 RMB commandsMark A. Greer
The current versions of the trf7970a has an erratum where it returns an extra byte in the response to 'Read Multiple Block' (RMB) commands. This command is issued to Type 5 tags (i.e., ISO/IEC 15693 tags) by the neard daemon. To handle this, define a new Device Tree property, 't5t-rmb-extra-byte-quirk', which indicates that the associated trf7970a device has this erratum. The trf7970a device driver will then ensure that the response length to RMB commands is reduced by one byte (for devices with the erratum). Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-12-15NFC / PM: Replace CONFIG_PM_RUNTIME with CONFIG_PMRafael J. Wysocki
After commit b2b49ccbdd54 (PM: Kconfig: Set PM_RUNTIME if PM_SLEEP is selected) PM_RUNTIME is always set if PM is set, so #ifdef blocks depending on CONFIG_PM_RUNTIME may now be changed to depend on CONFIG_PM. Replace CONFIG_PM_RUNTIME with CONFIG_PM in drivers/nfc/trf7970a.c. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2014-09-24NFC: trf7970a: Unlock mutex before exiting _trf7970a_tg_listen()Mark A. Greer
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-24NFC: trf7970a: Unlock mutex before exiting trf7970a_irq()Mark A. Greer
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-24NFC: trf7970a: Remove unnecessary local variable initializationMark A. Greer
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-24NFC: trf7970a: Remove useless local variableMark A. Greer
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-07NFC: trf7970a: Add Target Mode Detection SupportMark A. Greer
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-07NFC: trf7970a: Add Target Mode SupportMark A. Greer
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-07NFC: trf7970a: Handle timeout values of zeroMark A. Greer
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-07NFC: trf7970a: Cancel timer when error encounteredMark A. Greer
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-07NFC: trf7970a: Don't turn on RF if there is already an RF fieldMark A. Greer
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-07NFC: trf7970a: trf7970a_init() turns off the RF transmitterMark A. Greer
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-07NFC: trf7970a: Don't turn off RF if its already offMark A. Greer
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-07NFC: trf7970a: Add '_in_' to initiator routinesMark A. Greer
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-07NFC: trf7970a: Delay after initializationMark A. Greer
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-07NFC: trf7970a: Add System Suspend/Resume supportMark A. Greer
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-07NFC: trf7970a: Create startup and shutdown routinesMark A. Greer
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-07NFC: trf7970a: Don't assume CONFIG_PM_RUNTIME is enabledMark A. Greer
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-07NFC: trf7970a: Rename TRF7970A_ST_OFF to TRF7970A_ST_RF_OFFMark A. Greer
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-07NFC: trf7970a: Return error code when turning on RF failsMark A. Greer
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-07NFC: trf7970a: Ensure no more RX data before completing receiveMark A. Greer
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-07NFC: trf7970a: Reread FIFO Status Register when draining FIFOMark A. Greer
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-07NFC: trf7970a: Handle low-watermark IRQ when transmittingMark A. Greer
Commit 4dd836e46c3d ("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-07NFC: trf7970a: Only fill FIFO if there is spaceMark A. Greer
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-07NFC: trf7970a: Prefix TX data when refilling FIFOMark A. Greer
When refilling the FIFO with more TX data (using a new SPI transaction), the driver must prefix the TX data with a write to the FIFO I/O Register. This tells the trf7970a that the following data is destined for the FIFO so it can be transmitted. To accomplish this, the driver cannot simply push the prefix data just before the next set of TX data that is to be transmitted because that will overwrite part of the TX data provided by the digital layer. Instead, separate the prefix data and the TX data when calling trf7970a_transmit(). trf7970a_transmit() can then send the prefix and TX data from different memory locations with one spi_sync() operation. This also means that the driver doesn't require any skb "tx_headroom" as provided by the digital layer (see nfc_digital_allocate_device() and digital_skb_alloc()). Also ensure that the prefix is of type 'u8' and not 'char'. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Remove unnecessary FIFO reset & RSSI readMark A. Greer
It is no longer necessary to reset the FIFO and read the 'RSSI Levels and Oscillator Status Register' so remove that code. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Clear possible spurious interrupt before transmittingMark A. Greer
The trf7970a occasionally generates spurious interrupts which can confuse the driver. To help alleviate this, clear any interrupts by reading the 'IRQ Status Register' before starting a new transaction. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Recalculate driver timeout valuesMark A. Greer
Some of the timeout values used in the driver are not long enough to handle worst-case scenarios so they need to be recalculated. The time to wait for the FIFO to drain past the low-watermark is now 20 ms because it can take around 14.35 ms to send 95 bytes (127 bytes in full FIFO minus 32 bytes where the low-watermark interrupt will fire). 95 bytes will take around 14.35 ms at 6.62 kbps (the lowest supported bit rate used by ISO/IEC 15693) so 20 ms should be a safe value. The time to wait before issuing an EOF to complete an ISO/IEC 15693 write or lock command is 40 ms-- 20 ms to drain the FIFO and another 20 ms to ensure the wait is long enough before sending an EOF. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Add RF technology specific guard timesMark A. Greer
When turning on the RF field, the driver must wait an RF-technology-specific amount of time (known as the guard time) before modulating the field. Currently, the driver waits 5 ms but that is too short for NFCF and too long for ISO/IEC 15693. Fix this by determining the guard time when the RF technology is set and delaying that amount of time when turning on the RF field. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Initialize when enabling RFMark A. Greer
Currently, the trf7970a is reset & initialized only when the pm_runtime resume hook is called. Instead, initialize it every time the RF is enabled to ensure that the trf7970a is quiesced and in a known state before being set up for another RF technology. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Disable SYS_CLK OutputMark A. Greer
Currently, support for providing the external SYS_CLK signal on pin 27 is not supported so turn it off by writing to the 'Modulator and SYS_CLK Control' register immediately after reset. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Remove unnecessary sleepMark A. Greer
There is no need to sleep for 1-2 ms before transmitting a new command. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: FIFO Size is really 127 bytesMark A. Greer
Despite what the manual says, the FIFO size on the trf7970a is really 127 bytes so make the code respect that. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Ignore Overflow bit in FIFO Status RegisterMark A. Greer
The Overflow bit in the 'FIFO Status Register' has proven to be untrustworthy so ignore it. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Use spi_sync() instead of spi_write_then_read()Mark A. Greer
To more efficiently handle long continuous reads, use spi_sync() instead of spi_write_then_read(). Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Call spi_setup() to configure SPI communicationMark A. Greer
Call spi_setup() to configure SPI communication with the trf7970a. This will ensure that the correct SPI parameters are used. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Remove trf7970a_tg_listen_mdaa()Mark A. Greer
Currently, the digital layer 'tg_listen_mdaa' hook is not used and it isn't necessary to have a stub routine so remove it. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-07NFC: trf7970a: Remove incorrect of_node_put() callMark A. Greer
of_property_read_u32() does not take a reference to the specified OF node so don't call of_node_put() in trf7970a_get_autosuspend_delay(). Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-01NFC: trf7970a: Make gpio labels more readableMark A. Greer
Make the labels for the two gpio enable lines more user friendly by prefixing them with the driver name. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-01NFC: trf7970a: Add quirk to keep EN2 lowMark A. Greer
A bug has been discovered in the trf7970a where it will generate an RF field even in passive target mode when EN2 is asserted. To work around this, add support for the 'en2-rf-quirk' device tree property which indicates that EN2 must remain low. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-01NFC: trf7970a: Move IRQ Status Read quirk to device treeMark A. Greer
The quirk indicating whether the trf7970a has the "IRQ Status Read" erratum or not is currently implemented using the 'driver_data' member of the 'spi_device_id' structure. That requires the driver to be modified to turn the quirk off when a version of the trf7970a that doesn't have the erratum is being used. To fix that, create a new device tree property called 'irq-status-read-quirk' that indicates that the trf7970a being used has the erratum. While at it, rename 'TRF7970A_QUIRK_IRQ_STATUS_READ_ERRATA' to 'TRF7970A_QUIRK_IRQ_STATUS_READ' to make it less of an eyesore. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-09-01NFC: trf7970a: Add VIN voltage override supportMark A. Greer
The trf7970a driver uses the voltage from the power/regulator subsystem to determine what the voltage on the VIN pin is. Normally, this is the right thing to do but sometimes the board that the trf7970a is on may change the voltage. This is the case for the trf7970atb board from Texas Instruments where it boosts the VIN voltage from 3.3V to 5V (see http://www.ti.com/tool/trf7970atb). To handle this, add support for the 'vin-voltage-override' device tree property which overrides the voltage value given by the regulator subsystem. When the DT property is not present, the value from the regulator subsystem is used. The value of 'vin-voltage-override' is in uVolts. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2014-05-26NFC: trf7970a: Add support for Felica Type 3 tagsMark A. Greer
Add support for the Felica protocol and Type 3 tags. Both 212 and 424 kbps are supported. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>