2015-03-08 04:17:15 -06:00
|
|
|
/*
|
|
|
|
* STMicroelectronics TPM SPI Linux driver for TPM ST33ZP24
|
2016-02-13 08:15:31 -07:00
|
|
|
* Copyright (C) 2009 - 2016 STMicroelectronics
|
2015-03-08 04:17:15 -06:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <linux/gpio.h>
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
#include <linux/gpio/consumer.h>
|
2015-03-08 04:17:15 -06:00
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/of_gpio.h>
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
#include <linux/acpi.h>
|
2015-03-08 04:17:15 -06:00
|
|
|
#include <linux/tpm.h>
|
|
|
|
#include <linux/platform_data/st33zp24.h>
|
|
|
|
|
2016-03-31 14:57:00 -06:00
|
|
|
#include "../tpm.h"
|
2015-03-08 04:17:15 -06:00
|
|
|
#include "st33zp24.h"
|
|
|
|
|
|
|
|
#define TPM_DATA_FIFO 0x24
|
|
|
|
#define TPM_INTF_CAPABILITY 0x14
|
|
|
|
|
|
|
|
#define TPM_DUMMY_BYTE 0x00
|
|
|
|
|
|
|
|
#define MAX_SPI_LATENCY 15
|
|
|
|
#define LOCALITY0 0
|
|
|
|
|
|
|
|
#define ST33ZP24_OK 0x5A
|
|
|
|
#define ST33ZP24_UNDEFINED_ERR 0x80
|
|
|
|
#define ST33ZP24_BADLOCALITY 0x81
|
|
|
|
#define ST33ZP24_TISREGISTER_UKNOWN 0x82
|
|
|
|
#define ST33ZP24_LOCALITY_NOT_ACTIVATED 0x83
|
|
|
|
#define ST33ZP24_HASH_END_BEFORE_HASH_START 0x84
|
|
|
|
#define ST33ZP24_BAD_COMMAND_ORDER 0x85
|
|
|
|
#define ST33ZP24_INCORECT_RECEIVED_LENGTH 0x86
|
|
|
|
#define ST33ZP24_TPM_FIFO_OVERFLOW 0x89
|
|
|
|
#define ST33ZP24_UNEXPECTED_READ_FIFO 0x8A
|
|
|
|
#define ST33ZP24_UNEXPECTED_WRITE_FIFO 0x8B
|
|
|
|
#define ST33ZP24_CMDRDY_SET_WHEN_PROCESSING_HASH_END 0x90
|
|
|
|
#define ST33ZP24_DUMMY_BYTES 0x00
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TPM command can be up to 2048 byte, A TPM response can be up to
|
|
|
|
* 1024 byte.
|
|
|
|
* Between command and response, there are latency byte (up to 15
|
|
|
|
* usually on st33zp24 2 are enough).
|
|
|
|
*
|
|
|
|
* Overall when sending a command and expecting an answer we need if
|
|
|
|
* worst case:
|
|
|
|
* 2048 (for the TPM command) + 1024 (for the TPM answer). We need
|
|
|
|
* some latency byte before the answer is available (max 15).
|
|
|
|
* We have 2048 + 1024 + 15.
|
|
|
|
*/
|
|
|
|
#define ST33ZP24_SPI_BUFFER_SIZE (TPM_BUFSIZE + (TPM_BUFSIZE / 2) +\
|
|
|
|
MAX_SPI_LATENCY)
|
|
|
|
|
|
|
|
|
|
|
|
struct st33zp24_spi_phy {
|
|
|
|
struct spi_device *spi_device;
|
2016-02-13 08:15:27 -07:00
|
|
|
|
2015-03-08 04:17:15 -06:00
|
|
|
u8 tx_buf[ST33ZP24_SPI_BUFFER_SIZE];
|
|
|
|
u8 rx_buf[ST33ZP24_SPI_BUFFER_SIZE];
|
|
|
|
|
|
|
|
int io_lpcpd;
|
|
|
|
int latency;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int st33zp24_status_to_errno(u8 code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case ST33ZP24_OK:
|
|
|
|
return 0;
|
|
|
|
case ST33ZP24_UNDEFINED_ERR:
|
|
|
|
case ST33ZP24_BADLOCALITY:
|
|
|
|
case ST33ZP24_TISREGISTER_UKNOWN:
|
|
|
|
case ST33ZP24_LOCALITY_NOT_ACTIVATED:
|
|
|
|
case ST33ZP24_HASH_END_BEFORE_HASH_START:
|
|
|
|
case ST33ZP24_BAD_COMMAND_ORDER:
|
|
|
|
case ST33ZP24_UNEXPECTED_READ_FIFO:
|
|
|
|
case ST33ZP24_UNEXPECTED_WRITE_FIFO:
|
|
|
|
case ST33ZP24_CMDRDY_SET_WHEN_PROCESSING_HASH_END:
|
|
|
|
return -EPROTO;
|
|
|
|
case ST33ZP24_INCORECT_RECEIVED_LENGTH:
|
|
|
|
case ST33ZP24_TPM_FIFO_OVERFLOW:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
case ST33ZP24_DUMMY_BYTES:
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* st33zp24_spi_send
|
|
|
|
* Send byte to the TIS register according to the ST33ZP24 SPI protocol.
|
|
|
|
* @param: phy_id, the phy description
|
|
|
|
* @param: tpm_register, the tpm tis register where the data should be written
|
|
|
|
* @param: tpm_data, the tpm_data to write inside the tpm_register
|
|
|
|
* @param: tpm_size, The length of the data
|
|
|
|
* @return: should be zero if success else a negative error code.
|
|
|
|
*/
|
|
|
|
static int st33zp24_spi_send(void *phy_id, u8 tpm_register, u8 *tpm_data,
|
|
|
|
int tpm_size)
|
|
|
|
{
|
2016-02-13 08:15:24 -07:00
|
|
|
int total_length = 0, ret = 0;
|
2015-03-08 04:17:15 -06:00
|
|
|
struct st33zp24_spi_phy *phy = phy_id;
|
|
|
|
struct spi_device *dev = phy->spi_device;
|
2016-02-13 08:15:27 -07:00
|
|
|
struct spi_transfer spi_xfer = {
|
|
|
|
.tx_buf = phy->tx_buf,
|
|
|
|
.rx_buf = phy->rx_buf,
|
|
|
|
};
|
2015-03-08 04:17:15 -06:00
|
|
|
|
|
|
|
/* Pre-Header */
|
2016-02-13 08:15:27 -07:00
|
|
|
phy->tx_buf[total_length++] = TPM_WRITE_DIRECTION | LOCALITY0;
|
|
|
|
phy->tx_buf[total_length++] = tpm_register;
|
2015-03-08 04:17:15 -06:00
|
|
|
|
|
|
|
if (tpm_size > 0 && tpm_register == TPM_DATA_FIFO) {
|
2016-02-13 08:15:27 -07:00
|
|
|
phy->tx_buf[total_length++] = tpm_size >> 8;
|
|
|
|
phy->tx_buf[total_length++] = tpm_size;
|
2015-03-08 04:17:15 -06:00
|
|
|
}
|
|
|
|
|
2016-02-13 08:15:27 -07:00
|
|
|
memcpy(&phy->tx_buf[total_length], tpm_data, tpm_size);
|
2015-03-08 04:17:15 -06:00
|
|
|
total_length += tpm_size;
|
|
|
|
|
2016-02-13 08:15:27 -07:00
|
|
|
memset(&phy->tx_buf[total_length], TPM_DUMMY_BYTE, phy->latency);
|
2015-03-08 04:17:15 -06:00
|
|
|
|
2016-02-13 08:15:27 -07:00
|
|
|
spi_xfer.len = total_length + phy->latency;
|
2015-03-08 04:17:15 -06:00
|
|
|
|
2016-02-13 08:15:27 -07:00
|
|
|
ret = spi_sync_transfer(dev, &spi_xfer, 1);
|
2015-03-08 04:17:15 -06:00
|
|
|
if (ret == 0)
|
2016-02-13 08:15:27 -07:00
|
|
|
ret = phy->rx_buf[total_length + phy->latency - 1];
|
2015-03-08 04:17:15 -06:00
|
|
|
|
|
|
|
return st33zp24_status_to_errno(ret);
|
|
|
|
} /* st33zp24_spi_send() */
|
|
|
|
|
|
|
|
/*
|
2016-02-13 08:15:25 -07:00
|
|
|
* st33zp24_spi_read8_recv
|
2015-03-08 04:17:15 -06:00
|
|
|
* Recv byte from the TIS register according to the ST33ZP24 SPI protocol.
|
|
|
|
* @param: phy_id, the phy description
|
|
|
|
* @param: tpm_register, the tpm tis register where the data should be read
|
|
|
|
* @param: tpm_data, the TPM response
|
|
|
|
* @param: tpm_size, tpm TPM response size to read.
|
|
|
|
* @return: should be zero if success else a negative error code.
|
|
|
|
*/
|
2016-02-13 08:15:25 -07:00
|
|
|
static int st33zp24_spi_read8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data,
|
|
|
|
int tpm_size)
|
2015-03-08 04:17:15 -06:00
|
|
|
{
|
2016-02-13 08:15:24 -07:00
|
|
|
int total_length = 0, ret;
|
2015-03-08 04:17:15 -06:00
|
|
|
struct st33zp24_spi_phy *phy = phy_id;
|
|
|
|
struct spi_device *dev = phy->spi_device;
|
2016-02-13 08:15:27 -07:00
|
|
|
struct spi_transfer spi_xfer = {
|
|
|
|
.tx_buf = phy->tx_buf,
|
|
|
|
.rx_buf = phy->rx_buf,
|
|
|
|
};
|
2015-03-08 04:17:15 -06:00
|
|
|
|
|
|
|
/* Pre-Header */
|
2016-02-13 08:15:27 -07:00
|
|
|
phy->tx_buf[total_length++] = LOCALITY0;
|
|
|
|
phy->tx_buf[total_length++] = tpm_register;
|
2016-02-13 08:15:24 -07:00
|
|
|
|
2016-02-13 08:15:27 -07:00
|
|
|
memset(&phy->tx_buf[total_length], TPM_DUMMY_BYTE,
|
2016-02-13 08:15:24 -07:00
|
|
|
phy->latency + tpm_size);
|
2015-03-08 04:17:15 -06:00
|
|
|
|
2016-02-13 08:15:27 -07:00
|
|
|
spi_xfer.len = total_length + phy->latency + tpm_size;
|
2015-03-08 04:17:15 -06:00
|
|
|
|
|
|
|
/* header + status byte + size of the data + status byte */
|
2016-02-13 08:15:27 -07:00
|
|
|
ret = spi_sync_transfer(dev, &spi_xfer, 1);
|
2015-03-08 04:17:15 -06:00
|
|
|
if (tpm_size > 0 && ret == 0) {
|
2016-02-13 08:15:27 -07:00
|
|
|
ret = phy->rx_buf[total_length + phy->latency - 1];
|
2015-03-08 04:17:15 -06:00
|
|
|
|
2016-02-13 08:15:27 -07:00
|
|
|
memcpy(tpm_data, phy->rx_buf + total_length + phy->latency,
|
2015-03-08 04:17:15 -06:00
|
|
|
tpm_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2016-02-13 08:15:25 -07:00
|
|
|
} /* st33zp24_spi_read8_reg() */
|
2015-03-08 04:17:15 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* st33zp24_spi_recv
|
|
|
|
* Recv byte from the TIS register according to the ST33ZP24 SPI protocol.
|
|
|
|
* @param: phy_id, the phy description
|
|
|
|
* @param: tpm_register, the tpm tis register where the data should be read
|
|
|
|
* @param: tpm_data, the TPM response
|
|
|
|
* @param: tpm_size, tpm TPM response size to read.
|
|
|
|
* @return: number of byte read successfully: should be one if success.
|
|
|
|
*/
|
|
|
|
static int st33zp24_spi_recv(void *phy_id, u8 tpm_register, u8 *tpm_data,
|
|
|
|
int tpm_size)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-02-13 08:15:25 -07:00
|
|
|
ret = st33zp24_spi_read8_reg(phy_id, tpm_register, tpm_data, tpm_size);
|
2015-03-08 04:17:15 -06:00
|
|
|
if (!st33zp24_status_to_errno(ret))
|
|
|
|
return tpm_size;
|
|
|
|
return ret;
|
|
|
|
} /* st33zp24_spi_recv() */
|
|
|
|
|
2016-02-13 08:15:25 -07:00
|
|
|
static int st33zp24_spi_evaluate_latency(void *phy_id)
|
2015-03-08 04:17:15 -06:00
|
|
|
{
|
|
|
|
struct st33zp24_spi_phy *phy = phy_id;
|
|
|
|
int latency = 1, status = 0;
|
|
|
|
u8 data = 0;
|
|
|
|
|
|
|
|
while (!status && latency < MAX_SPI_LATENCY) {
|
|
|
|
phy->latency = latency;
|
2016-02-13 08:15:25 -07:00
|
|
|
status = st33zp24_spi_read8_reg(phy_id, TPM_INTF_CAPABILITY,
|
|
|
|
&data, 1);
|
2015-03-08 04:17:15 -06:00
|
|
|
latency++;
|
|
|
|
}
|
2016-02-13 08:15:30 -07:00
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
if (latency == MAX_SPI_LATENCY)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2015-03-08 04:17:15 -06:00
|
|
|
return latency - 1;
|
|
|
|
} /* evaluate_latency() */
|
|
|
|
|
|
|
|
static const struct st33zp24_phy_ops spi_phy_ops = {
|
|
|
|
.send = st33zp24_spi_send,
|
|
|
|
.recv = st33zp24_spi_recv,
|
|
|
|
};
|
|
|
|
|
2016-02-23 14:25:51 -07:00
|
|
|
static int st33zp24_spi_acpi_request_resources(struct spi_device *spi_dev)
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
{
|
2016-03-31 14:57:00 -06:00
|
|
|
struct tpm_chip *chip = spi_get_drvdata(spi_dev);
|
|
|
|
struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
|
|
|
|
struct st33zp24_spi_phy *phy = tpm_dev->phy_id;
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
struct gpio_desc *gpiod_lpcpd;
|
2016-03-23 01:55:33 -06:00
|
|
|
struct device *dev = &spi_dev->dev;
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
|
|
|
|
/* Get LPCPD GPIO from ACPI */
|
|
|
|
gpiod_lpcpd = devm_gpiod_get_index(dev, "TPM IO LPCPD", 1,
|
|
|
|
GPIOD_OUT_HIGH);
|
|
|
|
if (IS_ERR(gpiod_lpcpd)) {
|
|
|
|
dev_err(dev, "Failed to retrieve lpcpd-gpios from acpi.\n");
|
|
|
|
phy->io_lpcpd = -1;
|
|
|
|
/*
|
|
|
|
* lpcpd pin is not specified. This is not an issue as
|
|
|
|
* power management can be also managed by TPM specific
|
|
|
|
* commands. So leave with a success status code.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
phy->io_lpcpd = desc_to_gpio(gpiod_lpcpd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:25:51 -07:00
|
|
|
static int st33zp24_spi_of_request_resources(struct spi_device *spi_dev)
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
{
|
2016-03-31 14:57:00 -06:00
|
|
|
struct tpm_chip *chip = spi_get_drvdata(spi_dev);
|
|
|
|
struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
|
|
|
|
struct st33zp24_spi_phy *phy = tpm_dev->phy_id;
|
2015-03-08 04:17:15 -06:00
|
|
|
struct device_node *pp;
|
|
|
|
int gpio;
|
|
|
|
int ret;
|
|
|
|
|
2016-02-23 14:25:51 -07:00
|
|
|
pp = spi_dev->dev.of_node;
|
2015-03-08 04:17:15 -06:00
|
|
|
if (!pp) {
|
2016-02-23 14:25:51 -07:00
|
|
|
dev_err(&spi_dev->dev, "No platform data\n");
|
2015-03-08 04:17:15 -06:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get GPIO from device tree */
|
|
|
|
gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0);
|
|
|
|
if (gpio < 0) {
|
2016-02-23 14:25:51 -07:00
|
|
|
dev_err(&spi_dev->dev,
|
2015-03-08 04:17:15 -06:00
|
|
|
"Failed to retrieve lpcpd-gpios from dts.\n");
|
|
|
|
phy->io_lpcpd = -1;
|
|
|
|
/*
|
|
|
|
* lpcpd pin is not specified. This is not an issue as
|
|
|
|
* power management can be also managed by TPM specific
|
|
|
|
* commands. So leave with a success status code.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* GPIO request and configuration */
|
2016-02-23 14:25:51 -07:00
|
|
|
ret = devm_gpio_request_one(&spi_dev->dev, gpio,
|
2015-03-08 04:17:15 -06:00
|
|
|
GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD");
|
|
|
|
if (ret) {
|
2016-02-23 14:25:51 -07:00
|
|
|
dev_err(&spi_dev->dev, "Failed to request lpcpd pin\n");
|
2015-03-08 04:17:15 -06:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
phy->io_lpcpd = gpio;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-23 14:25:51 -07:00
|
|
|
static int st33zp24_spi_request_resources(struct spi_device *dev)
|
2015-03-08 04:17:15 -06:00
|
|
|
{
|
2016-03-31 14:57:00 -06:00
|
|
|
struct tpm_chip *chip = spi_get_drvdata(dev);
|
|
|
|
struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
|
|
|
|
struct st33zp24_spi_phy *phy = tpm_dev->phy_id;
|
2015-03-08 04:17:15 -06:00
|
|
|
struct st33zp24_platform_data *pdata;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pdata = dev->dev.platform_data;
|
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&dev->dev, "No platform data\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store for late use */
|
|
|
|
phy->io_lpcpd = pdata->io_lpcpd;
|
|
|
|
|
|
|
|
if (gpio_is_valid(pdata->io_lpcpd)) {
|
|
|
|
ret = devm_gpio_request_one(&dev->dev,
|
|
|
|
pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH,
|
|
|
|
"TPM IO_LPCPD");
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&dev->dev, "%s : reset gpio_request failed\n",
|
|
|
|
__FILE__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-02-13 08:15:25 -07:00
|
|
|
* st33zp24_spi_probe initialize the TPM device
|
2015-03-08 04:17:15 -06:00
|
|
|
* @param: dev, the spi_device drescription (TPM SPI description).
|
|
|
|
* @return: 0 in case of success.
|
|
|
|
* or a negative value describing the error.
|
|
|
|
*/
|
2016-02-13 08:15:25 -07:00
|
|
|
static int st33zp24_spi_probe(struct spi_device *dev)
|
2015-03-08 04:17:15 -06:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct st33zp24_platform_data *pdata;
|
|
|
|
struct st33zp24_spi_phy *phy;
|
|
|
|
|
|
|
|
/* Check SPI platform functionnalities */
|
|
|
|
if (!dev) {
|
|
|
|
pr_info("%s: dev is NULL. Device is not accessible.\n",
|
|
|
|
__func__);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
phy = devm_kzalloc(&dev->dev, sizeof(struct st33zp24_spi_phy),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!phy)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
phy->spi_device = dev;
|
2016-02-23 14:25:51 -07:00
|
|
|
|
2015-03-08 04:17:15 -06:00
|
|
|
pdata = dev->dev.platform_data;
|
|
|
|
if (!pdata && dev->dev.of_node) {
|
2016-02-23 14:25:51 -07:00
|
|
|
ret = st33zp24_spi_of_request_resources(dev);
|
2015-03-08 04:17:15 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
} else if (pdata) {
|
2016-02-23 14:25:51 -07:00
|
|
|
ret = st33zp24_spi_request_resources(dev);
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
} else if (ACPI_HANDLE(&dev->dev)) {
|
2016-02-23 14:25:51 -07:00
|
|
|
ret = st33zp24_spi_acpi_request_resources(dev);
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-03-08 04:17:15 -06:00
|
|
|
}
|
|
|
|
|
2016-02-13 08:15:25 -07:00
|
|
|
phy->latency = st33zp24_spi_evaluate_latency(phy);
|
2015-03-08 04:17:15 -06:00
|
|
|
if (phy->latency <= 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return st33zp24_probe(phy, &spi_phy_ops, &dev->dev, dev->irq,
|
|
|
|
phy->io_lpcpd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-02-13 08:15:25 -07:00
|
|
|
* st33zp24_spi_remove remove the TPM device
|
2015-03-08 04:17:15 -06:00
|
|
|
* @param: client, the spi_device drescription (TPM SPI description).
|
|
|
|
* @return: 0 in case of success.
|
|
|
|
*/
|
2016-02-13 08:15:25 -07:00
|
|
|
static int st33zp24_spi_remove(struct spi_device *dev)
|
2015-03-08 04:17:15 -06:00
|
|
|
{
|
|
|
|
struct tpm_chip *chip = spi_get_drvdata(dev);
|
|
|
|
|
|
|
|
return st33zp24_remove(chip);
|
|
|
|
}
|
|
|
|
|
2015-03-23 15:29:58 -06:00
|
|
|
static const struct spi_device_id st33zp24_spi_id[] = {
|
|
|
|
{TPM_ST33_SPI, 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(spi, st33zp24_spi_id);
|
|
|
|
|
2015-03-08 04:17:15 -06:00
|
|
|
static const struct of_device_id of_st33zp24_spi_match[] = {
|
|
|
|
{ .compatible = "st,st33zp24-spi", },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, of_st33zp24_spi_match);
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
static const struct acpi_device_id st33zp24_spi_acpi_match[] = {
|
|
|
|
{"SMO3324"},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, st33zp24_spi_acpi_match);
|
|
|
|
|
2015-03-08 04:17:15 -06:00
|
|
|
static SIMPLE_DEV_PM_OPS(st33zp24_spi_ops, st33zp24_pm_suspend,
|
|
|
|
st33zp24_pm_resume);
|
|
|
|
|
2016-02-13 08:15:25 -07:00
|
|
|
static struct spi_driver st33zp24_spi_driver = {
|
2015-03-08 04:17:15 -06:00
|
|
|
.driver = {
|
|
|
|
.name = TPM_ST33_SPI,
|
|
|
|
.pm = &st33zp24_spi_ops,
|
|
|
|
.of_match_table = of_match_ptr(of_st33zp24_spi_match),
|
tpm: st33zp24: Add support for acpi probing for spi device.
Add support for acpi probing. SMO3324 is used for st33zp24.
It has been tested with the following acpi node on Minnowboard:
Device (TPM1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO3324") // _HID: Hardware ID
Name (_CID, "SMO3324") // _CID: Compatible ID
Name (_DDN, "SMO TPM") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
SpiSerialBus (0, PolarityLow, FourWireMode, 8,
ControllerInitiated, 4000000, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.SPI1.TPM1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
2016-02-23 14:25:49 -07:00
|
|
|
.acpi_match_table = ACPI_PTR(st33zp24_spi_acpi_match),
|
2015-03-08 04:17:15 -06:00
|
|
|
},
|
2016-02-13 08:15:25 -07:00
|
|
|
.probe = st33zp24_spi_probe,
|
|
|
|
.remove = st33zp24_spi_remove,
|
2015-03-23 15:29:58 -06:00
|
|
|
.id_table = st33zp24_spi_id,
|
2015-03-08 04:17:15 -06:00
|
|
|
};
|
|
|
|
|
2016-02-13 08:15:25 -07:00
|
|
|
module_spi_driver(st33zp24_spi_driver);
|
2015-03-08 04:17:15 -06:00
|
|
|
|
|
|
|
MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)");
|
|
|
|
MODULE_DESCRIPTION("STM TPM 1.2 SPI ST33 Driver");
|
|
|
|
MODULE_VERSION("1.3.0");
|
|
|
|
MODULE_LICENSE("GPL");
|