[Skiboot] [PATCH 11/15] libstb/drivers: Add I2C nuvoton driver for TPM 2.0

Stewart Smith stewart at linux.vnet.ibm.com
Thu Sep 15 20:22:22 AEST 2016


Claudio Carvalho <cclaudio at linux.vnet.ibm.com> writes:
> --- /dev/null
> +++ b/libstb/drivers/tpm_i2c_nuvoton.c
> @@ -0,0 +1,653 @@
> +/* Copyright 2013-2016 IBM Corp.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> + * implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +/****************************************************************************
> + * THIS DRIVER WAS PORTED AND ADAPTED FROM:
> + * https://github.com/open-power/hostboot/blob/master-p8/src/usr/i2c/tpmdd.C
> + ****************************************************************************/
> +
> +#include <string.h>
> +#include <timebase.h>
> +#include <timer.h>
> +#include <i2c.h>
> +#include <skiboot.h>
> +#include <opal-api.h>
> +#include <device.h>
> +
> +#include "../status_codes.h"
> +#include "../tpm.h"
> +#include "tpm_i2c_nuvoton.h"
> +
> +//#define DBG(fmt, ...) prlog(PR_DEBUG, fmt, ##__VA_ARGS__)
> +#define DBG(fmt, ...)
> +
> +#define DRIVER_NAME "i2c_tpm_nuvoton"
> +
> +/**
> + * Timings between various states or transitions within
> + * the interface protocol. See PTP spec for details.
> + */
> +#define TCG_PTP_TIMEOUT_A	750
> +#define TCG_PTP_TIMEOUT_B	2000
> +#define TCG_PTP_TIMEOUT_C	200
> +#define TCG_PTP_TIMEOUT_D	30
> +
> +/* I2C interface offsets */
> +#define NUVOTON_TPM_STS			0x00
> +#define NUVOTON_TPM_BURST_COUNT		0x01
> +#define NUVOTON_TPM_DATA_FIFO_W		0x20
> +#define NUVOTON_TPM_DATA_FIFO_R		0x40
> +#define NUVOTON_TPM_VID_DID_RID		0x60
> +
> +/* Bit masks for the TPM STATUS register */
> +#define TCG_PTP_STS_VALID		0x80
> +#define TCG_PTP_STS_COMMAND_READY	0x40
> +#define TCG_PTP_STS_GO			0x20
> +#define TCG_PTP_STS_DATA_AVAIL		0x10
> +#define TCG_PTP_STS_EXPECT		0x08
> +#define TCG_PTP_STS_RESPONSE_RETRY	0x02
> +#define TCG_PTP_STS_ERR_VAL		0x07
> +
> +/* from hw/p8-i2c.c */
> +#define I2C_TIMEOUT_POLL_MS	4000  /* 4s/byte timeout */
> +
> +/* TPM Driver values */
> +#define MAX_STSVALID_POLLS 	5   /* Max poll of 50ms (5*10ms) */
> +#define TPM_TIMEOUT_INTERVAL	10
> +#define TPM_MAX_NACK_RETRIES	2
> +
> +static struct tpm_dev *tpm_device = NULL;
> +static const char* compat = "nuvoton,npct650";

For compat, just code it in here:

> +void i2c_nuvoton_probe(void)
> +{
> +	struct tpm_chip *tpm = NULL;
> +	struct tpm_dev *tpm_device = NULL;
> +	struct dt_node *node = NULL;
> +
> +	dt_for_each_compatible(dt_root, node, compat) {

rather than a const.
-- 
Stewart Smith
OPAL Architect, IBM.



More information about the Skiboot mailing list