Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2009 - 2016 STMicroelectronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/tpm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/platform_data/st33zp24.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "../tpm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "st33zp24.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define TPM_DUMMY_BYTE			0xAA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct st33zp24_i2c_phy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	u8 buf[ST33ZP24_BUFSIZE + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int io_lpcpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * write8_reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * @param: tpm_register, the tpm tis register where the data should be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * @param: tpm_data, the tpm_data to write inside the tpm_register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * @param: tpm_size, The length of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * @return: Returns negative errno, or else the number of bytes written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int write8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct st33zp24_i2c_phy *phy = phy_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	phy->buf[0] = tpm_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	memcpy(phy->buf + 1, tpm_data, tpm_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return i2c_master_send(phy->client, phy->buf, tpm_size + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) } /* write8_reg() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * read8_reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @param: tpm_register, the tpm tis register where the data should be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @param: tpm_data, the TPM response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * @param: tpm_size, tpm TPM response size to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * @return: number of byte read successfully: should be one if success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int read8_reg(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct st33zp24_i2c_phy *phy = phy_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u8 status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u8 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	data = TPM_DUMMY_BYTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	status = write8_reg(phy, tpm_register, &data, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (status == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		status = i2c_master_recv(phy->client, tpm_data, tpm_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) } /* read8_reg() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * st33zp24_i2c_send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * Send byte to the TIS register according to the ST33ZP24 I2C protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * @param: phy_id, the phy description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * @param: tpm_register, the tpm tis register where the data should be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * @param: tpm_data, the tpm_data to write inside the tpm_register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * @param: tpm_size, the length of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * @return: number of byte written successfully: should be one if success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static int st33zp24_i2c_send(void *phy_id, u8 tpm_register, u8 *tpm_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			     int tpm_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return write8_reg(phy_id, tpm_register | TPM_WRITE_DIRECTION, tpm_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			  tpm_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * st33zp24_i2c_recv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * Recv byte from the TIS register according to the ST33ZP24 I2C protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * @param: phy_id, the phy description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * @param: tpm_register, the tpm tis register where the data should be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * @param: tpm_data, the TPM response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * @param: tpm_size, tpm TPM response size to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * @return: number of byte read successfully: should be one if success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int st33zp24_i2c_recv(void *phy_id, u8 tpm_register, u8 *tpm_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			     int tpm_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return read8_reg(phy_id, tpm_register, tpm_data, tpm_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static const struct st33zp24_phy_ops i2c_phy_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	.send = st33zp24_i2c_send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	.recv = st33zp24_i2c_recv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static const struct acpi_gpio_params lpcpd_gpios = { 1, 0, false };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct acpi_gpio_mapping acpi_st33zp24_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	{ "lpcpd-gpios", &lpcpd_gpios, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int st33zp24_i2c_acpi_request_resources(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct tpm_chip *chip = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct st33zp24_i2c_phy *phy = tpm_dev->phy_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct gpio_desc *gpiod_lpcpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	ret = devm_acpi_dev_add_driver_gpios(dev, acpi_st33zp24_gpios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	/* Get LPCPD GPIO from ACPI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	gpiod_lpcpd = devm_gpiod_get(dev, "lpcpd", GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (IS_ERR(gpiod_lpcpd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			"Failed to retrieve lpcpd-gpios from acpi.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		phy->io_lpcpd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		 * lpcpd pin is not specified. This is not an issue as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		 * power management can be also managed by TPM specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		 * commands. So leave with a success status code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	phy->io_lpcpd = desc_to_gpio(gpiod_lpcpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int st33zp24_i2c_of_request_resources(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct tpm_chip *chip = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct st33zp24_i2c_phy *phy = tpm_dev->phy_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct device_node *pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	pp = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!pp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		dev_err(&client->dev, "No platform data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/* Get GPIO from device tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (gpio < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			"Failed to retrieve lpcpd-gpios from dts.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		phy->io_lpcpd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		 * lpcpd pin is not specified. This is not an issue as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		 * power management can be also managed by TPM specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		 * commands. So leave with a success status code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* GPIO request and configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	ret = devm_gpio_request_one(&client->dev, gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		dev_err(&client->dev, "Failed to request lpcpd pin\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	phy->io_lpcpd = gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int st33zp24_i2c_request_resources(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct tpm_chip *chip = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct st33zp24_i2c_phy *phy = tpm_dev->phy_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct st33zp24_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	pdata = client->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		dev_err(&client->dev, "No platform data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	/* store for late use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	phy->io_lpcpd = pdata->io_lpcpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (gpio_is_valid(pdata->io_lpcpd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		ret = devm_gpio_request_one(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 				"TPM IO_LPCPD");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			dev_err(&client->dev, "Failed to request lpcpd pin\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * st33zp24_i2c_probe initialize the TPM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * @param: client, the i2c_client description (TPM I2C description).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * @param: id, the i2c_device_id struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * @return: 0 in case of success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  *	 -1 in other case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static int st33zp24_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			      const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct st33zp24_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct st33zp24_i2c_phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (!client) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		pr_info("%s: i2c client is NULL. Device not accessible.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		dev_info(&client->dev, "client not i2c capable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	phy = devm_kzalloc(&client->dev, sizeof(struct st33zp24_i2c_phy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (!phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	phy->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	pdata = client->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (!pdata && client->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		ret = st33zp24_i2c_of_request_resources(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	} else if (pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		ret = st33zp24_i2c_request_resources(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	} else if (ACPI_HANDLE(&client->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		ret = st33zp24_i2c_acpi_request_resources(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return st33zp24_probe(phy, &i2c_phy_ops, &client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			      phy->io_lpcpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * st33zp24_i2c_remove remove the TPM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * @param: client, the i2c_client description (TPM I2C description).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * @return: 0 in case of success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static int st33zp24_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct tpm_chip *chip = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	ret = st33zp24_remove(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static const struct i2c_device_id st33zp24_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	{TPM_ST33_I2C, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) MODULE_DEVICE_TABLE(i2c, st33zp24_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static const struct of_device_id of_st33zp24_i2c_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	{ .compatible = "st,st33zp24-i2c", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) MODULE_DEVICE_TABLE(of, of_st33zp24_i2c_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static const struct acpi_device_id st33zp24_i2c_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	{"SMO3324"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) MODULE_DEVICE_TABLE(acpi, st33zp24_i2c_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static SIMPLE_DEV_PM_OPS(st33zp24_i2c_ops, st33zp24_pm_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			 st33zp24_pm_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static struct i2c_driver st33zp24_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		.name = TPM_ST33_I2C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		.pm = &st33zp24_i2c_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		.of_match_table = of_match_ptr(of_st33zp24_i2c_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		.acpi_match_table = ACPI_PTR(st33zp24_i2c_acpi_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	.probe = st33zp24_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	.remove = st33zp24_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	.id_table = st33zp24_i2c_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) module_i2c_driver(st33zp24_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) MODULE_AUTHOR("TPM support (TPMsupport@list.st.com)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) MODULE_DESCRIPTION("STM TPM 1.2 I2C ST33 Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) MODULE_VERSION("1.3.0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) MODULE_LICENSE("GPL");