11ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
24c336e4bSJason Gunthorpe /******************************************************************************
382cc1a49SJason Gunthorpe * Nuvoton TPM I2C Device Driver Interface for WPCT301/NPCT501/NPCT6XX,
44c336e4bSJason Gunthorpe * based on the TCG TPM Interface Spec version 1.2.
54c336e4bSJason Gunthorpe * Specifications at www.trustedcomputinggroup.org
64c336e4bSJason Gunthorpe *
74c336e4bSJason Gunthorpe * Copyright (C) 2011, Nuvoton Technology Corporation.
84c336e4bSJason Gunthorpe * Dan Morav <dan.morav@nuvoton.com>
94c336e4bSJason Gunthorpe * Copyright (C) 2013, Obsidian Research Corp.
104c336e4bSJason Gunthorpe * Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
114c336e4bSJason Gunthorpe *
124c336e4bSJason Gunthorpe * Nuvoton contact information: APC.Support@nuvoton.com
134c336e4bSJason Gunthorpe *****************************************************************************/
144c336e4bSJason Gunthorpe
154c336e4bSJason Gunthorpe #include <linux/init.h>
164c336e4bSJason Gunthorpe #include <linux/module.h>
174c336e4bSJason Gunthorpe #include <linux/moduleparam.h>
184c336e4bSJason Gunthorpe #include <linux/slab.h>
194c336e4bSJason Gunthorpe #include <linux/interrupt.h>
204c336e4bSJason Gunthorpe #include <linux/wait.h>
214c336e4bSJason Gunthorpe #include <linux/i2c.h>
2282cc1a49SJason Gunthorpe #include <linux/of_device.h>
234c336e4bSJason Gunthorpe #include "tpm.h"
244c336e4bSJason Gunthorpe
254c336e4bSJason Gunthorpe /* I2C interface offsets */
264c336e4bSJason Gunthorpe #define TPM_STS 0x00
274c336e4bSJason Gunthorpe #define TPM_BURST_COUNT 0x01
284c336e4bSJason Gunthorpe #define TPM_DATA_FIFO_W 0x20
294c336e4bSJason Gunthorpe #define TPM_DATA_FIFO_R 0x40
304c336e4bSJason Gunthorpe #define TPM_VID_DID_RID 0x60
318ab547a2SJarkko Sakkinen #define TPM_I2C_RETRIES 5
324c336e4bSJason Gunthorpe /*
334c336e4bSJason Gunthorpe * I2C bus device maximum buffer size w/o counting I2C address or command
344c336e4bSJason Gunthorpe * i.e. max size required for I2C write is 34 = addr, command, 32 bytes data
354c336e4bSJason Gunthorpe */
364c336e4bSJason Gunthorpe #define TPM_I2C_MAX_BUF_SIZE 32
374c336e4bSJason Gunthorpe #define TPM_I2C_RETRY_COUNT 32
38a233a028SNayna Jain #define TPM_I2C_BUS_DELAY 1000 /* usec */
39a233a028SNayna Jain #define TPM_I2C_RETRY_DELAY_SHORT (2 * 1000) /* usec */
40a233a028SNayna Jain #define TPM_I2C_RETRY_DELAY_LONG (10 * 1000) /* usec */
41a233a028SNayna Jain #define TPM_I2C_DELAY_RANGE 300 /* usec */
424c336e4bSJason Gunthorpe
4382cc1a49SJason Gunthorpe #define OF_IS_TPM2 ((void *)1)
4482cc1a49SJason Gunthorpe #define I2C_IS_TPM2 1
454c336e4bSJason Gunthorpe
464c336e4bSJason Gunthorpe struct priv_data {
47570a3609SChristophe Ricard int irq;
484c336e4bSJason Gunthorpe unsigned int intrs;
496e599f6fSChristophe Ricard wait_queue_head_t read_queue;
504c336e4bSJason Gunthorpe };
514c336e4bSJason Gunthorpe
i2c_nuvoton_read_buf(struct i2c_client * client,u8 offset,u8 size,u8 * data)524c336e4bSJason Gunthorpe static s32 i2c_nuvoton_read_buf(struct i2c_client *client, u8 offset, u8 size,
534c336e4bSJason Gunthorpe u8 *data)
544c336e4bSJason Gunthorpe {
554c336e4bSJason Gunthorpe s32 status;
564c336e4bSJason Gunthorpe
574c336e4bSJason Gunthorpe status = i2c_smbus_read_i2c_block_data(client, offset, size, data);
584c336e4bSJason Gunthorpe dev_dbg(&client->dev,
594c336e4bSJason Gunthorpe "%s(offset=%u size=%u data=%*ph) -> sts=%d\n", __func__,
604c336e4bSJason Gunthorpe offset, size, (int)size, data, status);
614c336e4bSJason Gunthorpe return status;
624c336e4bSJason Gunthorpe }
634c336e4bSJason Gunthorpe
i2c_nuvoton_write_buf(struct i2c_client * client,u8 offset,u8 size,u8 * data)644c336e4bSJason Gunthorpe static s32 i2c_nuvoton_write_buf(struct i2c_client *client, u8 offset, u8 size,
654c336e4bSJason Gunthorpe u8 *data)
664c336e4bSJason Gunthorpe {
674c336e4bSJason Gunthorpe s32 status;
684c336e4bSJason Gunthorpe
694c336e4bSJason Gunthorpe status = i2c_smbus_write_i2c_block_data(client, offset, size, data);
704c336e4bSJason Gunthorpe dev_dbg(&client->dev,
714c336e4bSJason Gunthorpe "%s(offset=%u size=%u data=%*ph) -> sts=%d\n", __func__,
724c336e4bSJason Gunthorpe offset, size, (int)size, data, status);
734c336e4bSJason Gunthorpe return status;
744c336e4bSJason Gunthorpe }
754c336e4bSJason Gunthorpe
764c336e4bSJason Gunthorpe #define TPM_STS_VALID 0x80
774c336e4bSJason Gunthorpe #define TPM_STS_COMMAND_READY 0x40
784c336e4bSJason Gunthorpe #define TPM_STS_GO 0x20
794c336e4bSJason Gunthorpe #define TPM_STS_DATA_AVAIL 0x10
804c336e4bSJason Gunthorpe #define TPM_STS_EXPECT 0x08
814c336e4bSJason Gunthorpe #define TPM_STS_RESPONSE_RETRY 0x02
824c336e4bSJason Gunthorpe #define TPM_STS_ERR_VAL 0x07 /* bit2...bit0 reads always 0 */
834c336e4bSJason Gunthorpe
844c336e4bSJason Gunthorpe #define TPM_I2C_SHORT_TIMEOUT 750 /* ms */
854c336e4bSJason Gunthorpe #define TPM_I2C_LONG_TIMEOUT 2000 /* 2 sec */
864c336e4bSJason Gunthorpe
874c336e4bSJason Gunthorpe /* read TPM_STS register */
i2c_nuvoton_read_status(struct tpm_chip * chip)884c336e4bSJason Gunthorpe static u8 i2c_nuvoton_read_status(struct tpm_chip *chip)
894c336e4bSJason Gunthorpe {
908cfffc9dSJason Gunthorpe struct i2c_client *client = to_i2c_client(chip->dev.parent);
914c336e4bSJason Gunthorpe s32 status;
924c336e4bSJason Gunthorpe u8 data;
934c336e4bSJason Gunthorpe
944c336e4bSJason Gunthorpe status = i2c_nuvoton_read_buf(client, TPM_STS, 1, &data);
954c336e4bSJason Gunthorpe if (status <= 0) {
968cfffc9dSJason Gunthorpe dev_err(&chip->dev, "%s() error return %d\n", __func__,
974c336e4bSJason Gunthorpe status);
984c336e4bSJason Gunthorpe data = TPM_STS_ERR_VAL;
994c336e4bSJason Gunthorpe }
1004c336e4bSJason Gunthorpe
1014c336e4bSJason Gunthorpe return data;
1024c336e4bSJason Gunthorpe }
1034c336e4bSJason Gunthorpe
1044c336e4bSJason Gunthorpe /* write byte to TPM_STS register */
i2c_nuvoton_write_status(struct i2c_client * client,u8 data)1054c336e4bSJason Gunthorpe static s32 i2c_nuvoton_write_status(struct i2c_client *client, u8 data)
1064c336e4bSJason Gunthorpe {
1074c336e4bSJason Gunthorpe s32 status;
1084c336e4bSJason Gunthorpe int i;
1094c336e4bSJason Gunthorpe
1104c336e4bSJason Gunthorpe /* this causes the current command to be aborted */
1114c336e4bSJason Gunthorpe for (i = 0, status = -1; i < TPM_I2C_RETRY_COUNT && status < 0; i++) {
1124c336e4bSJason Gunthorpe status = i2c_nuvoton_write_buf(client, TPM_STS, 1, &data);
1130afb7118SNayna Jain if (status < 0)
114a233a028SNayna Jain usleep_range(TPM_I2C_BUS_DELAY, TPM_I2C_BUS_DELAY
115a233a028SNayna Jain + TPM_I2C_DELAY_RANGE);
1164c336e4bSJason Gunthorpe }
1174c336e4bSJason Gunthorpe return status;
1184c336e4bSJason Gunthorpe }
1194c336e4bSJason Gunthorpe
1204c336e4bSJason Gunthorpe /* write commandReady to TPM_STS register */
i2c_nuvoton_ready(struct tpm_chip * chip)1214c336e4bSJason Gunthorpe static void i2c_nuvoton_ready(struct tpm_chip *chip)
1224c336e4bSJason Gunthorpe {
1238cfffc9dSJason Gunthorpe struct i2c_client *client = to_i2c_client(chip->dev.parent);
1244c336e4bSJason Gunthorpe s32 status;
1254c336e4bSJason Gunthorpe
1264c336e4bSJason Gunthorpe /* this causes the current command to be aborted */
1274c336e4bSJason Gunthorpe status = i2c_nuvoton_write_status(client, TPM_STS_COMMAND_READY);
1284c336e4bSJason Gunthorpe if (status < 0)
1298cfffc9dSJason Gunthorpe dev_err(&chip->dev,
1304c336e4bSJason Gunthorpe "%s() fail to write TPM_STS.commandReady\n", __func__);
1314c336e4bSJason Gunthorpe }
1324c336e4bSJason Gunthorpe
1334c336e4bSJason Gunthorpe /* read burstCount field from TPM_STS register
1344c336e4bSJason Gunthorpe * return -1 on fail to read */
i2c_nuvoton_get_burstcount(struct i2c_client * client,struct tpm_chip * chip)1354c336e4bSJason Gunthorpe static int i2c_nuvoton_get_burstcount(struct i2c_client *client,
1364c336e4bSJason Gunthorpe struct tpm_chip *chip)
1374c336e4bSJason Gunthorpe {
138af782f33SChristophe Ricard unsigned long stop = jiffies + chip->timeout_d;
1394c336e4bSJason Gunthorpe s32 status;
1404c336e4bSJason Gunthorpe int burst_count = -1;
1414c336e4bSJason Gunthorpe u8 data;
1424c336e4bSJason Gunthorpe
1434c336e4bSJason Gunthorpe /* wait for burstcount to be non-zero */
1444c336e4bSJason Gunthorpe do {
1454c336e4bSJason Gunthorpe /* in I2C burstCount is 1 byte */
1464c336e4bSJason Gunthorpe status = i2c_nuvoton_read_buf(client, TPM_BURST_COUNT, 1,
1474c336e4bSJason Gunthorpe &data);
1484c336e4bSJason Gunthorpe if (status > 0 && data > 0) {
1494c336e4bSJason Gunthorpe burst_count = min_t(u8, TPM_I2C_MAX_BUF_SIZE, data);
1504c336e4bSJason Gunthorpe break;
1514c336e4bSJason Gunthorpe }
152a233a028SNayna Jain usleep_range(TPM_I2C_BUS_DELAY, TPM_I2C_BUS_DELAY
153a233a028SNayna Jain + TPM_I2C_DELAY_RANGE);
1544c336e4bSJason Gunthorpe } while (time_before(jiffies, stop));
1554c336e4bSJason Gunthorpe
1564c336e4bSJason Gunthorpe return burst_count;
1574c336e4bSJason Gunthorpe }
1584c336e4bSJason Gunthorpe
1594c336e4bSJason Gunthorpe /*
16082cc1a49SJason Gunthorpe * WPCT301/NPCT501/NPCT6XX SINT# supports only dataAvail
1614c336e4bSJason Gunthorpe * any call to this function which is not waiting for dataAvail will
1624c336e4bSJason Gunthorpe * set queue to NULL to avoid waiting for interrupt
1634c336e4bSJason Gunthorpe */
i2c_nuvoton_check_status(struct tpm_chip * chip,u8 mask,u8 value)1644c336e4bSJason Gunthorpe static bool i2c_nuvoton_check_status(struct tpm_chip *chip, u8 mask, u8 value)
1654c336e4bSJason Gunthorpe {
1664c336e4bSJason Gunthorpe u8 status = i2c_nuvoton_read_status(chip);
1674c336e4bSJason Gunthorpe return (status != TPM_STS_ERR_VAL) && ((status & mask) == value);
1684c336e4bSJason Gunthorpe }
1694c336e4bSJason Gunthorpe
i2c_nuvoton_wait_for_stat(struct tpm_chip * chip,u8 mask,u8 value,u32 timeout,wait_queue_head_t * queue)1704c336e4bSJason Gunthorpe static int i2c_nuvoton_wait_for_stat(struct tpm_chip *chip, u8 mask, u8 value,
1714c336e4bSJason Gunthorpe u32 timeout, wait_queue_head_t *queue)
1724c336e4bSJason Gunthorpe {
173570a3609SChristophe Ricard if ((chip->flags & TPM_CHIP_FLAG_IRQ) && queue) {
1744c336e4bSJason Gunthorpe s32 rc;
1759e0d39d8SChristophe Ricard struct priv_data *priv = dev_get_drvdata(&chip->dev);
1764c336e4bSJason Gunthorpe unsigned int cur_intrs = priv->intrs;
1774c336e4bSJason Gunthorpe
178570a3609SChristophe Ricard enable_irq(priv->irq);
1794c336e4bSJason Gunthorpe rc = wait_event_interruptible_timeout(*queue,
1804c336e4bSJason Gunthorpe cur_intrs != priv->intrs,
1814c336e4bSJason Gunthorpe timeout);
1824c336e4bSJason Gunthorpe if (rc > 0)
1834c336e4bSJason Gunthorpe return 0;
1844c336e4bSJason Gunthorpe /* At this point we know that the SINT pin is asserted, so we
1854c336e4bSJason Gunthorpe * do not need to do i2c_nuvoton_check_status */
1864c336e4bSJason Gunthorpe } else {
1874c336e4bSJason Gunthorpe unsigned long ten_msec, stop;
1884c336e4bSJason Gunthorpe bool status_valid;
1894c336e4bSJason Gunthorpe
1904c336e4bSJason Gunthorpe /* check current status */
1914c336e4bSJason Gunthorpe status_valid = i2c_nuvoton_check_status(chip, mask, value);
1924c336e4bSJason Gunthorpe if (status_valid)
1934c336e4bSJason Gunthorpe return 0;
1944c336e4bSJason Gunthorpe
1954c336e4bSJason Gunthorpe /* use polling to wait for the event */
196a233a028SNayna Jain ten_msec = jiffies + usecs_to_jiffies(TPM_I2C_RETRY_DELAY_LONG);
1974c336e4bSJason Gunthorpe stop = jiffies + timeout;
1984c336e4bSJason Gunthorpe do {
1994c336e4bSJason Gunthorpe if (time_before(jiffies, ten_msec))
200a233a028SNayna Jain usleep_range(TPM_I2C_RETRY_DELAY_SHORT,
201a233a028SNayna Jain TPM_I2C_RETRY_DELAY_SHORT
202a233a028SNayna Jain + TPM_I2C_DELAY_RANGE);
2034c336e4bSJason Gunthorpe else
204a233a028SNayna Jain usleep_range(TPM_I2C_RETRY_DELAY_LONG,
205a233a028SNayna Jain TPM_I2C_RETRY_DELAY_LONG
206a233a028SNayna Jain + TPM_I2C_DELAY_RANGE);
2074c336e4bSJason Gunthorpe status_valid = i2c_nuvoton_check_status(chip, mask,
2084c336e4bSJason Gunthorpe value);
2094c336e4bSJason Gunthorpe if (status_valid)
2104c336e4bSJason Gunthorpe return 0;
2114c336e4bSJason Gunthorpe } while (time_before(jiffies, stop));
2124c336e4bSJason Gunthorpe }
2138cfffc9dSJason Gunthorpe dev_err(&chip->dev, "%s(%02x, %02x) -> timeout\n", __func__, mask,
2144c336e4bSJason Gunthorpe value);
2154c336e4bSJason Gunthorpe return -ETIMEDOUT;
2164c336e4bSJason Gunthorpe }
2174c336e4bSJason Gunthorpe
2184c336e4bSJason Gunthorpe /* wait for dataAvail field to be set in the TPM_STS register */
i2c_nuvoton_wait_for_data_avail(struct tpm_chip * chip,u32 timeout,wait_queue_head_t * queue)2194c336e4bSJason Gunthorpe static int i2c_nuvoton_wait_for_data_avail(struct tpm_chip *chip, u32 timeout,
2204c336e4bSJason Gunthorpe wait_queue_head_t *queue)
2214c336e4bSJason Gunthorpe {
2224c336e4bSJason Gunthorpe return i2c_nuvoton_wait_for_stat(chip,
2234c336e4bSJason Gunthorpe TPM_STS_DATA_AVAIL | TPM_STS_VALID,
2244c336e4bSJason Gunthorpe TPM_STS_DATA_AVAIL | TPM_STS_VALID,
2254c336e4bSJason Gunthorpe timeout, queue);
2264c336e4bSJason Gunthorpe }
2274c336e4bSJason Gunthorpe
2284c336e4bSJason Gunthorpe /* Read @count bytes into @buf from TPM_RD_FIFO register */
i2c_nuvoton_recv_data(struct i2c_client * client,struct tpm_chip * chip,u8 * buf,size_t count)2294c336e4bSJason Gunthorpe static int i2c_nuvoton_recv_data(struct i2c_client *client,
2304c336e4bSJason Gunthorpe struct tpm_chip *chip, u8 *buf, size_t count)
2314c336e4bSJason Gunthorpe {
2329e0d39d8SChristophe Ricard struct priv_data *priv = dev_get_drvdata(&chip->dev);
2334c336e4bSJason Gunthorpe s32 rc;
2344c336e4bSJason Gunthorpe int burst_count, bytes2read, size = 0;
2354c336e4bSJason Gunthorpe
2364c336e4bSJason Gunthorpe while (size < count &&
2374c336e4bSJason Gunthorpe i2c_nuvoton_wait_for_data_avail(chip,
238af782f33SChristophe Ricard chip->timeout_c,
2396e599f6fSChristophe Ricard &priv->read_queue) == 0) {
2404c336e4bSJason Gunthorpe burst_count = i2c_nuvoton_get_burstcount(client, chip);
2414c336e4bSJason Gunthorpe if (burst_count < 0) {
2428cfffc9dSJason Gunthorpe dev_err(&chip->dev,
2434c336e4bSJason Gunthorpe "%s() fail to read burstCount=%d\n", __func__,
2444c336e4bSJason Gunthorpe burst_count);
2454c336e4bSJason Gunthorpe return -EIO;
2464c336e4bSJason Gunthorpe }
2474c336e4bSJason Gunthorpe bytes2read = min_t(size_t, burst_count, count - size);
2484c336e4bSJason Gunthorpe rc = i2c_nuvoton_read_buf(client, TPM_DATA_FIFO_R,
2494c336e4bSJason Gunthorpe bytes2read, &buf[size]);
2504c336e4bSJason Gunthorpe if (rc < 0) {
2518cfffc9dSJason Gunthorpe dev_err(&chip->dev,
2524c336e4bSJason Gunthorpe "%s() fail on i2c_nuvoton_read_buf()=%d\n",
2534c336e4bSJason Gunthorpe __func__, rc);
2544c336e4bSJason Gunthorpe return -EIO;
2554c336e4bSJason Gunthorpe }
2568cfffc9dSJason Gunthorpe dev_dbg(&chip->dev, "%s(%d):", __func__, bytes2read);
2574c336e4bSJason Gunthorpe size += bytes2read;
2584c336e4bSJason Gunthorpe }
2594c336e4bSJason Gunthorpe
2604c336e4bSJason Gunthorpe return size;
2614c336e4bSJason Gunthorpe }
2624c336e4bSJason Gunthorpe
2634c336e4bSJason Gunthorpe /* Read TPM command results */
i2c_nuvoton_recv(struct tpm_chip * chip,u8 * buf,size_t count)2644c336e4bSJason Gunthorpe static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)
2654c336e4bSJason Gunthorpe {
2669e0d39d8SChristophe Ricard struct priv_data *priv = dev_get_drvdata(&chip->dev);
2678cfffc9dSJason Gunthorpe struct device *dev = chip->dev.parent;
2684c336e4bSJason Gunthorpe struct i2c_client *client = to_i2c_client(dev);
2694c336e4bSJason Gunthorpe s32 rc;
270f9d4d9b5SJeremy Boone int status;
271f9d4d9b5SJeremy Boone int burst_count;
272f9d4d9b5SJeremy Boone int retries;
273f9d4d9b5SJeremy Boone int size = 0;
274f9d4d9b5SJeremy Boone u32 expected;
2754c336e4bSJason Gunthorpe
2764c336e4bSJason Gunthorpe if (count < TPM_HEADER_SIZE) {
2774c336e4bSJason Gunthorpe i2c_nuvoton_ready(chip); /* return to idle */
2784c336e4bSJason Gunthorpe dev_err(dev, "%s() count < header size\n", __func__);
2794c336e4bSJason Gunthorpe return -EIO;
2804c336e4bSJason Gunthorpe }
2818ab547a2SJarkko Sakkinen for (retries = 0; retries < TPM_I2C_RETRIES; retries++) {
2824c336e4bSJason Gunthorpe if (retries > 0) {
2834c336e4bSJason Gunthorpe /* if this is not the first trial, set responseRetry */
2844c336e4bSJason Gunthorpe i2c_nuvoton_write_status(client,
2854c336e4bSJason Gunthorpe TPM_STS_RESPONSE_RETRY);
2864c336e4bSJason Gunthorpe }
2874c336e4bSJason Gunthorpe /*
2884c336e4bSJason Gunthorpe * read first available (> 10 bytes), including:
2894c336e4bSJason Gunthorpe * tag, paramsize, and result
2904c336e4bSJason Gunthorpe */
2914c336e4bSJason Gunthorpe status = i2c_nuvoton_wait_for_data_avail(
292af782f33SChristophe Ricard chip, chip->timeout_c, &priv->read_queue);
2934c336e4bSJason Gunthorpe if (status != 0) {
2944c336e4bSJason Gunthorpe dev_err(dev, "%s() timeout on dataAvail\n", __func__);
2954c336e4bSJason Gunthorpe size = -ETIMEDOUT;
2964c336e4bSJason Gunthorpe continue;
2974c336e4bSJason Gunthorpe }
2984c336e4bSJason Gunthorpe burst_count = i2c_nuvoton_get_burstcount(client, chip);
2994c336e4bSJason Gunthorpe if (burst_count < 0) {
3004c336e4bSJason Gunthorpe dev_err(dev, "%s() fail to get burstCount\n", __func__);
3014c336e4bSJason Gunthorpe size = -EIO;
3024c336e4bSJason Gunthorpe continue;
3034c336e4bSJason Gunthorpe }
3044c336e4bSJason Gunthorpe size = i2c_nuvoton_recv_data(client, chip, buf,
3054c336e4bSJason Gunthorpe burst_count);
3064c336e4bSJason Gunthorpe if (size < TPM_HEADER_SIZE) {
3074c336e4bSJason Gunthorpe dev_err(dev, "%s() fail to read header\n", __func__);
3084c336e4bSJason Gunthorpe size = -EIO;
3094c336e4bSJason Gunthorpe continue;
3104c336e4bSJason Gunthorpe }
3114c336e4bSJason Gunthorpe /*
3124c336e4bSJason Gunthorpe * convert number of expected bytes field from big endian 32 bit
3134c336e4bSJason Gunthorpe * to machine native
3144c336e4bSJason Gunthorpe */
3154c336e4bSJason Gunthorpe expected = be32_to_cpu(*(__be32 *) (buf + 2));
316f9d4d9b5SJeremy Boone if (expected > count || expected < size) {
3174c336e4bSJason Gunthorpe dev_err(dev, "%s() expected > count\n", __func__);
3184c336e4bSJason Gunthorpe size = -EIO;
3194c336e4bSJason Gunthorpe continue;
3204c336e4bSJason Gunthorpe }
3214c336e4bSJason Gunthorpe rc = i2c_nuvoton_recv_data(client, chip, &buf[size],
3224c336e4bSJason Gunthorpe expected - size);
3234c336e4bSJason Gunthorpe size += rc;
3244c336e4bSJason Gunthorpe if (rc < 0 || size < expected) {
3254c336e4bSJason Gunthorpe dev_err(dev, "%s() fail to read remainder of result\n",
3264c336e4bSJason Gunthorpe __func__);
3274c336e4bSJason Gunthorpe size = -EIO;
3284c336e4bSJason Gunthorpe continue;
3294c336e4bSJason Gunthorpe }
3304c336e4bSJason Gunthorpe if (i2c_nuvoton_wait_for_stat(
3314c336e4bSJason Gunthorpe chip, TPM_STS_VALID | TPM_STS_DATA_AVAIL,
332af782f33SChristophe Ricard TPM_STS_VALID, chip->timeout_c,
3334c336e4bSJason Gunthorpe NULL)) {
3344c336e4bSJason Gunthorpe dev_err(dev, "%s() error left over data\n", __func__);
3354c336e4bSJason Gunthorpe size = -ETIMEDOUT;
3364c336e4bSJason Gunthorpe continue;
3374c336e4bSJason Gunthorpe }
3384c336e4bSJason Gunthorpe break;
3394c336e4bSJason Gunthorpe }
3404c336e4bSJason Gunthorpe i2c_nuvoton_ready(chip);
3418cfffc9dSJason Gunthorpe dev_dbg(&chip->dev, "%s() -> %d\n", __func__, size);
3424c336e4bSJason Gunthorpe return size;
3434c336e4bSJason Gunthorpe }
3444c336e4bSJason Gunthorpe
3454c336e4bSJason Gunthorpe /*
3464c336e4bSJason Gunthorpe * Send TPM command.
3474c336e4bSJason Gunthorpe *
3484c336e4bSJason Gunthorpe * If interrupts are used (signaled by an irq set in the vendor structure)
3494c336e4bSJason Gunthorpe * tpm.c can skip polling for the data to be available as the interrupt is
3504c336e4bSJason Gunthorpe * waited for here
3514c336e4bSJason Gunthorpe */
i2c_nuvoton_send(struct tpm_chip * chip,u8 * buf,size_t len)3524c336e4bSJason Gunthorpe static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
3534c336e4bSJason Gunthorpe {
3549e0d39d8SChristophe Ricard struct priv_data *priv = dev_get_drvdata(&chip->dev);
3558cfffc9dSJason Gunthorpe struct device *dev = chip->dev.parent;
3564c336e4bSJason Gunthorpe struct i2c_client *client = to_i2c_client(dev);
3574c336e4bSJason Gunthorpe u32 ordinal;
3582ba5780cSTomas Winkler unsigned long duration;
3594c336e4bSJason Gunthorpe size_t count = 0;
3604c336e4bSJason Gunthorpe int burst_count, bytes2write, retries, rc = -EIO;
3614c336e4bSJason Gunthorpe
3624c336e4bSJason Gunthorpe for (retries = 0; retries < TPM_RETRY; retries++) {
3634c336e4bSJason Gunthorpe i2c_nuvoton_ready(chip);
3644c336e4bSJason Gunthorpe if (i2c_nuvoton_wait_for_stat(chip, TPM_STS_COMMAND_READY,
3654c336e4bSJason Gunthorpe TPM_STS_COMMAND_READY,
366af782f33SChristophe Ricard chip->timeout_b, NULL)) {
3674c336e4bSJason Gunthorpe dev_err(dev, "%s() timeout on commandReady\n",
3684c336e4bSJason Gunthorpe __func__);
3694c336e4bSJason Gunthorpe rc = -EIO;
3704c336e4bSJason Gunthorpe continue;
3714c336e4bSJason Gunthorpe }
3724c336e4bSJason Gunthorpe rc = 0;
3734c336e4bSJason Gunthorpe while (count < len - 1) {
3744c336e4bSJason Gunthorpe burst_count = i2c_nuvoton_get_burstcount(client,
3754c336e4bSJason Gunthorpe chip);
3764c336e4bSJason Gunthorpe if (burst_count < 0) {
3774c336e4bSJason Gunthorpe dev_err(dev, "%s() fail get burstCount\n",
3784c336e4bSJason Gunthorpe __func__);
3794c336e4bSJason Gunthorpe rc = -EIO;
3804c336e4bSJason Gunthorpe break;
3814c336e4bSJason Gunthorpe }
3824c336e4bSJason Gunthorpe bytes2write = min_t(size_t, burst_count,
3834c336e4bSJason Gunthorpe len - 1 - count);
3844c336e4bSJason Gunthorpe rc = i2c_nuvoton_write_buf(client, TPM_DATA_FIFO_W,
3854c336e4bSJason Gunthorpe bytes2write, &buf[count]);
3864c336e4bSJason Gunthorpe if (rc < 0) {
3874c336e4bSJason Gunthorpe dev_err(dev, "%s() fail i2cWriteBuf\n",
3884c336e4bSJason Gunthorpe __func__);
3894c336e4bSJason Gunthorpe break;
3904c336e4bSJason Gunthorpe }
3914c336e4bSJason Gunthorpe dev_dbg(dev, "%s(%d):", __func__, bytes2write);
3924c336e4bSJason Gunthorpe count += bytes2write;
3934c336e4bSJason Gunthorpe rc = i2c_nuvoton_wait_for_stat(chip,
3944c336e4bSJason Gunthorpe TPM_STS_VALID |
3954c336e4bSJason Gunthorpe TPM_STS_EXPECT,
3964c336e4bSJason Gunthorpe TPM_STS_VALID |
3974c336e4bSJason Gunthorpe TPM_STS_EXPECT,
398af782f33SChristophe Ricard chip->timeout_c,
3994c336e4bSJason Gunthorpe NULL);
4004c336e4bSJason Gunthorpe if (rc < 0) {
4014c336e4bSJason Gunthorpe dev_err(dev, "%s() timeout on Expect\n",
4024c336e4bSJason Gunthorpe __func__);
4034c336e4bSJason Gunthorpe rc = -ETIMEDOUT;
4044c336e4bSJason Gunthorpe break;
4054c336e4bSJason Gunthorpe }
4064c336e4bSJason Gunthorpe }
4074c336e4bSJason Gunthorpe if (rc < 0)
4084c336e4bSJason Gunthorpe continue;
4094c336e4bSJason Gunthorpe
4104c336e4bSJason Gunthorpe /* write last byte */
4114c336e4bSJason Gunthorpe rc = i2c_nuvoton_write_buf(client, TPM_DATA_FIFO_W, 1,
4124c336e4bSJason Gunthorpe &buf[count]);
4134c336e4bSJason Gunthorpe if (rc < 0) {
4144c336e4bSJason Gunthorpe dev_err(dev, "%s() fail to write last byte\n",
4154c336e4bSJason Gunthorpe __func__);
4164c336e4bSJason Gunthorpe rc = -EIO;
4174c336e4bSJason Gunthorpe continue;
4184c336e4bSJason Gunthorpe }
4194c336e4bSJason Gunthorpe dev_dbg(dev, "%s(last): %02x", __func__, buf[count]);
4204c336e4bSJason Gunthorpe rc = i2c_nuvoton_wait_for_stat(chip,
4214c336e4bSJason Gunthorpe TPM_STS_VALID | TPM_STS_EXPECT,
4224c336e4bSJason Gunthorpe TPM_STS_VALID,
423af782f33SChristophe Ricard chip->timeout_c, NULL);
4244c336e4bSJason Gunthorpe if (rc) {
4254c336e4bSJason Gunthorpe dev_err(dev, "%s() timeout on Expect to clear\n",
4264c336e4bSJason Gunthorpe __func__);
4274c336e4bSJason Gunthorpe rc = -ETIMEDOUT;
4284c336e4bSJason Gunthorpe continue;
4294c336e4bSJason Gunthorpe }
4304c336e4bSJason Gunthorpe break;
4314c336e4bSJason Gunthorpe }
4324c336e4bSJason Gunthorpe if (rc < 0) {
4334c336e4bSJason Gunthorpe /* retries == TPM_RETRY */
4344c336e4bSJason Gunthorpe i2c_nuvoton_ready(chip);
4354c336e4bSJason Gunthorpe return rc;
4364c336e4bSJason Gunthorpe }
4374c336e4bSJason Gunthorpe /* execute the TPM command */
4384c336e4bSJason Gunthorpe rc = i2c_nuvoton_write_status(client, TPM_STS_GO);
4394c336e4bSJason Gunthorpe if (rc < 0) {
4404c336e4bSJason Gunthorpe dev_err(dev, "%s() fail to write Go\n", __func__);
4414c336e4bSJason Gunthorpe i2c_nuvoton_ready(chip);
4424c336e4bSJason Gunthorpe return rc;
4434c336e4bSJason Gunthorpe }
4444c336e4bSJason Gunthorpe ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
445d856c00fSTomas Winkler duration = tpm_calc_ordinal_duration(chip, ordinal);
4462ba5780cSTomas Winkler
4472ba5780cSTomas Winkler rc = i2c_nuvoton_wait_for_data_avail(chip, duration, &priv->read_queue);
4484c336e4bSJason Gunthorpe if (rc) {
449b2d6e6deSTomas Winkler dev_err(dev, "%s() timeout command duration %ld\n",
450b2d6e6deSTomas Winkler __func__, duration);
4514c336e4bSJason Gunthorpe i2c_nuvoton_ready(chip);
4524c336e4bSJason Gunthorpe return rc;
4534c336e4bSJason Gunthorpe }
4544c336e4bSJason Gunthorpe
4554c336e4bSJason Gunthorpe dev_dbg(dev, "%s() -> %zd\n", __func__, len);
456f5595f5bSJarkko Sakkinen return 0;
4574c336e4bSJason Gunthorpe }
4584c336e4bSJason Gunthorpe
i2c_nuvoton_req_canceled(struct tpm_chip * chip,u8 status)4594c336e4bSJason Gunthorpe static bool i2c_nuvoton_req_canceled(struct tpm_chip *chip, u8 status)
4604c336e4bSJason Gunthorpe {
4614c336e4bSJason Gunthorpe return (status == TPM_STS_COMMAND_READY);
4624c336e4bSJason Gunthorpe }
4634c336e4bSJason Gunthorpe
46401ad1fa7SJason Gunthorpe static const struct tpm_class_ops tpm_i2c = {
465cae8b441SJason Gunthorpe .flags = TPM_OPS_AUTO_STARTUP,
4664c336e4bSJason Gunthorpe .status = i2c_nuvoton_read_status,
4674c336e4bSJason Gunthorpe .recv = i2c_nuvoton_recv,
4684c336e4bSJason Gunthorpe .send = i2c_nuvoton_send,
4694c336e4bSJason Gunthorpe .cancel = i2c_nuvoton_ready,
4704c336e4bSJason Gunthorpe .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
4714c336e4bSJason Gunthorpe .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
4724c336e4bSJason Gunthorpe .req_canceled = i2c_nuvoton_req_canceled,
4734c336e4bSJason Gunthorpe };
4744c336e4bSJason Gunthorpe
4754c336e4bSJason Gunthorpe /* The only purpose for the handler is to signal to any waiting threads that
4764c336e4bSJason Gunthorpe * the interrupt is currently being asserted. The driver does not do any
4774c336e4bSJason Gunthorpe * processing triggered by interrupts, and the chip provides no way to mask at
4784c336e4bSJason Gunthorpe * the source (plus that would be slow over I2C). Run the IRQ as a one-shot,
4794c336e4bSJason Gunthorpe * this means it cannot be shared. */
i2c_nuvoton_int_handler(int dummy,void * dev_id)4804c336e4bSJason Gunthorpe static irqreturn_t i2c_nuvoton_int_handler(int dummy, void *dev_id)
4814c336e4bSJason Gunthorpe {
4824c336e4bSJason Gunthorpe struct tpm_chip *chip = dev_id;
4839e0d39d8SChristophe Ricard struct priv_data *priv = dev_get_drvdata(&chip->dev);
4844c336e4bSJason Gunthorpe
4854c336e4bSJason Gunthorpe priv->intrs++;
4866e599f6fSChristophe Ricard wake_up(&priv->read_queue);
487570a3609SChristophe Ricard disable_irq_nosync(priv->irq);
4884c336e4bSJason Gunthorpe return IRQ_HANDLED;
4894c336e4bSJason Gunthorpe }
4904c336e4bSJason Gunthorpe
get_vid(struct i2c_client * client,u32 * res)4914c336e4bSJason Gunthorpe static int get_vid(struct i2c_client *client, u32 *res)
4924c336e4bSJason Gunthorpe {
4934c336e4bSJason Gunthorpe static const u8 vid_did_rid_value[] = { 0x50, 0x10, 0xfe };
4944c336e4bSJason Gunthorpe u32 temp;
4954c336e4bSJason Gunthorpe s32 rc;
4964c336e4bSJason Gunthorpe
4974c336e4bSJason Gunthorpe if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
4984c336e4bSJason Gunthorpe return -ENODEV;
4994c336e4bSJason Gunthorpe rc = i2c_nuvoton_read_buf(client, TPM_VID_DID_RID, 4, (u8 *)&temp);
5004c336e4bSJason Gunthorpe if (rc < 0)
5014c336e4bSJason Gunthorpe return rc;
5024c336e4bSJason Gunthorpe
5034c336e4bSJason Gunthorpe /* check WPCT301 values - ignore RID */
5044c336e4bSJason Gunthorpe if (memcmp(&temp, vid_did_rid_value, sizeof(vid_did_rid_value))) {
5054c336e4bSJason Gunthorpe /*
5064c336e4bSJason Gunthorpe * f/w rev 2.81 has an issue where the VID_DID_RID is not
5074c336e4bSJason Gunthorpe * reporting the right value. so give it another chance at
5084c336e4bSJason Gunthorpe * offset 0x20 (FIFO_W).
5094c336e4bSJason Gunthorpe */
5104c336e4bSJason Gunthorpe rc = i2c_nuvoton_read_buf(client, TPM_DATA_FIFO_W, 4,
5114c336e4bSJason Gunthorpe (u8 *) (&temp));
5124c336e4bSJason Gunthorpe if (rc < 0)
5134c336e4bSJason Gunthorpe return rc;
5144c336e4bSJason Gunthorpe
5154c336e4bSJason Gunthorpe /* check WPCT301 values - ignore RID */
5164c336e4bSJason Gunthorpe if (memcmp(&temp, vid_did_rid_value,
5174c336e4bSJason Gunthorpe sizeof(vid_did_rid_value)))
5184c336e4bSJason Gunthorpe return -ENODEV;
5194c336e4bSJason Gunthorpe }
5204c336e4bSJason Gunthorpe
5214c336e4bSJason Gunthorpe *res = temp;
5224c336e4bSJason Gunthorpe return 0;
5234c336e4bSJason Gunthorpe }
5244c336e4bSJason Gunthorpe
i2c_nuvoton_probe(struct i2c_client * client)5258f3fb73bSUwe Kleine-König static int i2c_nuvoton_probe(struct i2c_client *client)
5264c336e4bSJason Gunthorpe {
5278f3fb73bSUwe Kleine-König const struct i2c_device_id *id = i2c_client_get_device_id(client);
5284c336e4bSJason Gunthorpe int rc;
5294c336e4bSJason Gunthorpe struct tpm_chip *chip;
5304c336e4bSJason Gunthorpe struct device *dev = &client->dev;
531570a3609SChristophe Ricard struct priv_data *priv;
5324c336e4bSJason Gunthorpe u32 vid = 0;
5334c336e4bSJason Gunthorpe
5344c336e4bSJason Gunthorpe rc = get_vid(client, &vid);
5354c336e4bSJason Gunthorpe if (rc)
5364c336e4bSJason Gunthorpe return rc;
5374c336e4bSJason Gunthorpe
5384c336e4bSJason Gunthorpe dev_info(dev, "VID: %04X DID: %02X RID: %02X\n", (u16) vid,
5394c336e4bSJason Gunthorpe (u8) (vid >> 16), (u8) (vid >> 24));
5404c336e4bSJason Gunthorpe
541afb5abc2SJarkko Sakkinen chip = tpmm_chip_alloc(dev, &tpm_i2c);
542afb5abc2SJarkko Sakkinen if (IS_ERR(chip))
543afb5abc2SJarkko Sakkinen return PTR_ERR(chip);
5444c336e4bSJason Gunthorpe
545570a3609SChristophe Ricard priv = devm_kzalloc(dev, sizeof(struct priv_data), GFP_KERNEL);
546570a3609SChristophe Ricard if (!priv)
547afb5abc2SJarkko Sakkinen return -ENOMEM;
548bb95cd34SKiran Padwal
54982cc1a49SJason Gunthorpe if (dev->of_node) {
55082cc1a49SJason Gunthorpe const struct of_device_id *of_id;
55182cc1a49SJason Gunthorpe
55282cc1a49SJason Gunthorpe of_id = of_match_device(dev->driver->of_match_table, dev);
55382cc1a49SJason Gunthorpe if (of_id && of_id->data == OF_IS_TPM2)
55482cc1a49SJason Gunthorpe chip->flags |= TPM_CHIP_FLAG_TPM2;
55582cc1a49SJason Gunthorpe } else
55682cc1a49SJason Gunthorpe if (id->driver_data == I2C_IS_TPM2)
55782cc1a49SJason Gunthorpe chip->flags |= TPM_CHIP_FLAG_TPM2;
55882cc1a49SJason Gunthorpe
5596e599f6fSChristophe Ricard init_waitqueue_head(&priv->read_queue);
5604c336e4bSJason Gunthorpe
5614c336e4bSJason Gunthorpe /* Default timeouts */
562af782f33SChristophe Ricard chip->timeout_a = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
563af782f33SChristophe Ricard chip->timeout_b = msecs_to_jiffies(TPM_I2C_LONG_TIMEOUT);
564af782f33SChristophe Ricard chip->timeout_c = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
565af782f33SChristophe Ricard chip->timeout_d = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
5664c336e4bSJason Gunthorpe
5679e0d39d8SChristophe Ricard dev_set_drvdata(&chip->dev, priv);
5689e0d39d8SChristophe Ricard
5694c336e4bSJason Gunthorpe /*
5704c336e4bSJason Gunthorpe * I2C intfcaps (interrupt capabilitieis) in the chip are hard coded to:
5714c336e4bSJason Gunthorpe * TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
5724c336e4bSJason Gunthorpe * The IRQ should be set in the i2c_board_info (which is done
5734c336e4bSJason Gunthorpe * automatically in of_i2c_register_devices, for device tree users */
574570a3609SChristophe Ricard priv->irq = client->irq;
575fa7539b2SAndrew Zamansky if (client->irq) {
576570a3609SChristophe Ricard dev_dbg(dev, "%s() priv->irq\n", __func__);
577570a3609SChristophe Ricard rc = devm_request_irq(dev, client->irq,
5784c336e4bSJason Gunthorpe i2c_nuvoton_int_handler,
5794c336e4bSJason Gunthorpe IRQF_TRIGGER_LOW,
5803635e2ecSJason Gunthorpe dev_name(&chip->dev),
5814c336e4bSJason Gunthorpe chip);
5824c336e4bSJason Gunthorpe if (rc) {
5834c336e4bSJason Gunthorpe dev_err(dev, "%s() Unable to request irq: %d for use\n",
584570a3609SChristophe Ricard __func__, priv->irq);
585570a3609SChristophe Ricard priv->irq = 0;
5864c336e4bSJason Gunthorpe } else {
587fa7539b2SAndrew Zamansky chip->flags |= TPM_CHIP_FLAG_IRQ;
5884c336e4bSJason Gunthorpe /* Clear any pending interrupt */
5894c336e4bSJason Gunthorpe i2c_nuvoton_ready(chip);
5904c336e4bSJason Gunthorpe /* - wait for TPM_STS==0xA0 (stsValid, commandReady) */
5914c336e4bSJason Gunthorpe rc = i2c_nuvoton_wait_for_stat(chip,
5924c336e4bSJason Gunthorpe TPM_STS_COMMAND_READY,
5934c336e4bSJason Gunthorpe TPM_STS_COMMAND_READY,
594af782f33SChristophe Ricard chip->timeout_b,
5954c336e4bSJason Gunthorpe NULL);
5964c336e4bSJason Gunthorpe if (rc == 0) {
5974c336e4bSJason Gunthorpe /*
5984c336e4bSJason Gunthorpe * TIS is in ready state
5994c336e4bSJason Gunthorpe * write dummy byte to enter reception state
6004c336e4bSJason Gunthorpe * TPM_DATA_FIFO_W <- rc (0)
6014c336e4bSJason Gunthorpe */
6024c336e4bSJason Gunthorpe rc = i2c_nuvoton_write_buf(client,
6034c336e4bSJason Gunthorpe TPM_DATA_FIFO_W,
6044c336e4bSJason Gunthorpe 1, (u8 *) (&rc));
6054c336e4bSJason Gunthorpe if (rc < 0)
606afb5abc2SJarkko Sakkinen return rc;
6074c336e4bSJason Gunthorpe /* TPM_STS <- 0x40 (commandReady) */
6084c336e4bSJason Gunthorpe i2c_nuvoton_ready(chip);
6094c336e4bSJason Gunthorpe } else {
6104c336e4bSJason Gunthorpe /*
6114c336e4bSJason Gunthorpe * timeout_b reached - command was
6124c336e4bSJason Gunthorpe * aborted. TIS should now be in idle state -
6134c336e4bSJason Gunthorpe * only TPM_STS_VALID should be set
6144c336e4bSJason Gunthorpe */
6154c336e4bSJason Gunthorpe if (i2c_nuvoton_read_status(chip) !=
616afb5abc2SJarkko Sakkinen TPM_STS_VALID)
617afb5abc2SJarkko Sakkinen return -EIO;
6184c336e4bSJason Gunthorpe }
6194c336e4bSJason Gunthorpe }
6204c336e4bSJason Gunthorpe }
6214c336e4bSJason Gunthorpe
622afb5abc2SJarkko Sakkinen return tpm_chip_register(chip);
6234c336e4bSJason Gunthorpe }
6244c336e4bSJason Gunthorpe
i2c_nuvoton_remove(struct i2c_client * client)625ed5c2f5fSUwe Kleine-König static void i2c_nuvoton_remove(struct i2c_client *client)
6264c336e4bSJason Gunthorpe {
6279e0d39d8SChristophe Ricard struct tpm_chip *chip = i2c_get_clientdata(client);
6289e0d39d8SChristophe Ricard
629afb5abc2SJarkko Sakkinen tpm_chip_unregister(chip);
6304c336e4bSJason Gunthorpe }
6314c336e4bSJason Gunthorpe
6324c336e4bSJason Gunthorpe static const struct i2c_device_id i2c_nuvoton_id[] = {
63382cc1a49SJason Gunthorpe {"tpm_i2c_nuvoton"},
63482cc1a49SJason Gunthorpe {"tpm2_i2c_nuvoton", .driver_data = I2C_IS_TPM2},
6354c336e4bSJason Gunthorpe {}
6364c336e4bSJason Gunthorpe };
6374c336e4bSJason Gunthorpe MODULE_DEVICE_TABLE(i2c, i2c_nuvoton_id);
6384c336e4bSJason Gunthorpe
6394c336e4bSJason Gunthorpe #ifdef CONFIG_OF
6404c336e4bSJason Gunthorpe static const struct of_device_id i2c_nuvoton_of_match[] = {
6414c336e4bSJason Gunthorpe {.compatible = "nuvoton,npct501"},
6424c336e4bSJason Gunthorpe {.compatible = "winbond,wpct301"},
64382cc1a49SJason Gunthorpe {.compatible = "nuvoton,npct601", .data = OF_IS_TPM2},
6444c336e4bSJason Gunthorpe {},
6454c336e4bSJason Gunthorpe };
6464c336e4bSJason Gunthorpe MODULE_DEVICE_TABLE(of, i2c_nuvoton_of_match);
6474c336e4bSJason Gunthorpe #endif
6484c336e4bSJason Gunthorpe
6494c336e4bSJason Gunthorpe static SIMPLE_DEV_PM_OPS(i2c_nuvoton_pm_ops, tpm_pm_suspend, tpm_pm_resume);
6504c336e4bSJason Gunthorpe
6514c336e4bSJason Gunthorpe static struct i2c_driver i2c_nuvoton_driver = {
6524c336e4bSJason Gunthorpe .id_table = i2c_nuvoton_id,
653*be6f48a7SUwe Kleine-König .probe = i2c_nuvoton_probe,
6544c336e4bSJason Gunthorpe .remove = i2c_nuvoton_remove,
6554c336e4bSJason Gunthorpe .driver = {
65682cc1a49SJason Gunthorpe .name = "tpm_i2c_nuvoton",
6574c336e4bSJason Gunthorpe .pm = &i2c_nuvoton_pm_ops,
6584c336e4bSJason Gunthorpe .of_match_table = of_match_ptr(i2c_nuvoton_of_match),
6594c336e4bSJason Gunthorpe },
6604c336e4bSJason Gunthorpe };
6614c336e4bSJason Gunthorpe
6624c336e4bSJason Gunthorpe module_i2c_driver(i2c_nuvoton_driver);
6634c336e4bSJason Gunthorpe
6644c336e4bSJason Gunthorpe MODULE_AUTHOR("Dan Morav (dan.morav@nuvoton.com)");
6654c336e4bSJason Gunthorpe MODULE_DESCRIPTION("Nuvoton TPM I2C Driver");
6664c336e4bSJason Gunthorpe MODULE_LICENSE("GPL");
667