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+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2017 Hisilicon Limited, All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Author: Zhichang Yuan <yuanzhichang@hisilicon.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author: Zou Rongrong <zourongrong@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: John Garry <john.garry@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/logic_pio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/serial_8250.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DRV_NAME "hisi-lpc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Setting this bit means each IO operation will target a different port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * address; 0 means repeated IO operations will use the same port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * such as BT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define FG_INCRADDR_LPC		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct lpc_cycle_para {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	unsigned int opflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned int csize; /* data length of each operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) struct hisi_lpc_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	spinlock_t cycle_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	void __iomem  *membase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct logic_pio_hwaddr *io_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* The max IO cycle counts supported is four per operation at maximum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define LPC_MAX_DWIDTH	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define LPC_REG_STARTUP_SIGNAL		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define LPC_REG_STARTUP_SIGNAL_START	BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define LPC_REG_OP_STATUS		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define LPC_REG_OP_STATUS_IDLE		BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define LPC_REG_OP_STATUS_FINISHED	BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define LPC_REG_OP_LEN			0x10 /* LPC cycles count per start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define LPC_REG_CMD			0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define LPC_REG_CMD_OP			BIT(0) /* 0: read, 1: write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define LPC_REG_CMD_SAMEADDR		BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define LPC_REG_ADDR			0x20 /* target address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define LPC_REG_WDATA			0x24 /* write FIFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define LPC_REG_RDATA			0x28 /* read FIFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /* The minimal nanosecond interval for each query on LPC cycle status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define LPC_NSEC_PERWAIT	100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * The maximum waiting time is about 128us.  It is specific for stream I/O,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * such as ins.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * The fastest IO cycle time is about 390ns, but the worst case will wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * for extra 256 lpc clocks, so (256 + 13) * 30ns = 8 us. The maximum burst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * cycles is 16. So, the maximum waiting time is about 128us under worst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * Choose 1300 as the maximum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define LPC_MAX_WAITCNT		1300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /* About 10us. This is specific for single IO operations, such as inb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define LPC_PEROP_WAITCNT	100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static int wait_lpc_idle(void __iomem *mbase, unsigned int waitcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		status = readl(mbase + LPC_REG_OP_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (status & LPC_REG_OP_STATUS_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			return (status & LPC_REG_OP_STATUS_FINISHED) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		ndelay(LPC_NSEC_PERWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	} while (--waitcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return -ETIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * hisi_lpc_target_in - trigger a series of LPC cycles for read operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * @lpcdev: pointer to hisi lpc device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * @para: some parameters used to control the lpc I/O operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * @addr: the lpc I/O target port address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @buf: where the read back data is stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * @opcnt: how many I/O operations required, i.e. data width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * Returns 0 on success, non-zero on fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int hisi_lpc_target_in(struct hisi_lpc_dev *lpcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			      struct lpc_cycle_para *para, unsigned long addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			      unsigned char *buf, unsigned long opcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	unsigned int cmd_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	unsigned int waitcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!buf || !opcnt || !para || !para->csize || !lpcdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	cmd_word = 0; /* IO mode, Read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	waitcnt = LPC_PEROP_WAITCNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!(para->opflags & FG_INCRADDR_LPC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		cmd_word |= LPC_REG_CMD_SAMEADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		waitcnt = LPC_MAX_WAITCNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* whole operation must be atomic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	spin_lock_irqsave(&lpcdev->cycle_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	writel_relaxed(opcnt, lpcdev->membase + LPC_REG_OP_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	writel_relaxed(cmd_word, lpcdev->membase + LPC_REG_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	writel_relaxed(addr, lpcdev->membase + LPC_REG_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	writel(LPC_REG_STARTUP_SIGNAL_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	       lpcdev->membase + LPC_REG_STARTUP_SIGNAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* whether the operation is finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	ret = wait_lpc_idle(lpcdev->membase, waitcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		spin_unlock_irqrestore(&lpcdev->cycle_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	readsb(lpcdev->membase + LPC_REG_RDATA, buf, opcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	spin_unlock_irqrestore(&lpcdev->cycle_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * hisi_lpc_target_out - trigger a series of LPC cycles for write operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * @lpcdev: pointer to hisi lpc device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * @para: some parameters used to control the lpc I/O operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * @addr: the lpc I/O target port address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * @buf: where the data to be written is stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * @opcnt: how many I/O operations required, i.e. data width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * Returns 0 on success, non-zero on fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int hisi_lpc_target_out(struct hisi_lpc_dev *lpcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			       struct lpc_cycle_para *para, unsigned long addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			       const unsigned char *buf, unsigned long opcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	unsigned int waitcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	u32 cmd_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (!buf || !opcnt || !para || !lpcdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* default is increasing address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	cmd_word = LPC_REG_CMD_OP; /* IO mode, write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	waitcnt = LPC_PEROP_WAITCNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (!(para->opflags & FG_INCRADDR_LPC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		cmd_word |= LPC_REG_CMD_SAMEADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		waitcnt = LPC_MAX_WAITCNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	spin_lock_irqsave(&lpcdev->cycle_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	writel_relaxed(opcnt, lpcdev->membase + LPC_REG_OP_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	writel_relaxed(cmd_word, lpcdev->membase + LPC_REG_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	writel_relaxed(addr, lpcdev->membase + LPC_REG_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	writesb(lpcdev->membase + LPC_REG_WDATA, buf, opcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	writel(LPC_REG_STARTUP_SIGNAL_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	       lpcdev->membase + LPC_REG_STARTUP_SIGNAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* whether the operation is finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	ret = wait_lpc_idle(lpcdev->membase, waitcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	spin_unlock_irqrestore(&lpcdev->cycle_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static unsigned long hisi_lpc_pio_to_addr(struct hisi_lpc_dev *lpcdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 					  unsigned long pio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	return pio - lpcdev->io_host->io_start + lpcdev->io_host->hw_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * hisi_lpc_comm_in - input the data in a single operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * @hostdata: pointer to the device information relevant to LPC controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * @pio: the target I/O port address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * @dwidth: the data length required to read from the target I/O port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * When success, data is returned. Otherwise, ~0 is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static u32 hisi_lpc_comm_in(void *hostdata, unsigned long pio, size_t dwidth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct hisi_lpc_dev *lpcdev = hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct lpc_cycle_para iopara;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	__le32 rd_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (!lpcdev || !dwidth || dwidth > LPC_MAX_DWIDTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	addr = hisi_lpc_pio_to_addr(lpcdev, pio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	iopara.opflags = FG_INCRADDR_LPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	iopara.csize = dwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	ret = hisi_lpc_target_in(lpcdev, &iopara, addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				 (unsigned char *)&rd_data, dwidth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		return ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	return le32_to_cpu(rd_data);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * hisi_lpc_comm_out - output the data in a single operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * @hostdata: pointer to the device information relevant to LPC controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * @pio: the target I/O port address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * @val: a value to be output from caller, maximum is four bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * @dwidth: the data width required writing to the target I/O port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * This function corresponds to out(b,w,l) only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static void hisi_lpc_comm_out(void *hostdata, unsigned long pio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			      u32 val, size_t dwidth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct hisi_lpc_dev *lpcdev = hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct lpc_cycle_para iopara;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	const unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	__le32 _val = cpu_to_le32(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (!lpcdev || !dwidth || dwidth > LPC_MAX_DWIDTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	buf = (const unsigned char *)&_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	addr = hisi_lpc_pio_to_addr(lpcdev, pio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	iopara.opflags = FG_INCRADDR_LPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	iopara.csize = dwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	hisi_lpc_target_out(lpcdev, &iopara, addr, buf, dwidth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^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)  * hisi_lpc_comm_ins - input the data in the buffer in multiple operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * @hostdata: pointer to the device information relevant to LPC controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * @pio: the target I/O port address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * @buffer: a buffer where read/input data bytes are stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * @dwidth: the data width required writing to the target I/O port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * @count: how many data units whose length is dwidth will be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * When success, the data read back is stored in buffer pointed by buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * Returns 0 on success, -errno otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static u32 hisi_lpc_comm_ins(void *hostdata, unsigned long pio, void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			     size_t dwidth, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct hisi_lpc_dev *lpcdev = hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	unsigned char *buf = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct lpc_cycle_para iopara;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (!lpcdev || !buf || !count || !dwidth || dwidth > LPC_MAX_DWIDTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	iopara.opflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (dwidth > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		iopara.opflags |= FG_INCRADDR_LPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	iopara.csize = dwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	addr = hisi_lpc_pio_to_addr(lpcdev, pio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		ret = hisi_lpc_target_in(lpcdev, &iopara, addr, buf, dwidth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		buf += dwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	} while (--count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * hisi_lpc_comm_outs - output the data in the buffer in multiple operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * @hostdata: pointer to the device information relevant to LPC controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * @pio: the target I/O port address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * @buffer: a buffer where write/output data bytes are stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * @dwidth: the data width required writing to the target I/O port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * @count: how many data units whose length is dwidth will be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static void hisi_lpc_comm_outs(void *hostdata, unsigned long pio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			       const void *buffer, size_t dwidth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			       unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct hisi_lpc_dev *lpcdev = hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct lpc_cycle_para iopara;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	const unsigned char *buf = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (!lpcdev || !buf || !count || !dwidth || dwidth > LPC_MAX_DWIDTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	iopara.opflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (dwidth > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		iopara.opflags |= FG_INCRADDR_LPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	iopara.csize = dwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	addr = hisi_lpc_pio_to_addr(lpcdev, pio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		if (hisi_lpc_target_out(lpcdev, &iopara, addr, buf, dwidth))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		buf += dwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	} while (--count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static const struct logic_pio_host_ops hisi_lpc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	.in = hisi_lpc_comm_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	.out = hisi_lpc_comm_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	.ins = hisi_lpc_comm_ins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	.outs = hisi_lpc_comm_outs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static int hisi_lpc_acpi_xlat_io_res(struct acpi_device *adev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				     struct acpi_device *host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 				     struct resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	unsigned long sys_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	resource_size_t len = resource_size(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	sys_port = logic_pio_trans_hwaddr(&host->fwnode, res->start, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (sys_port == ~0UL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	res->start = sys_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	res->end = sys_port + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  * Released firmware describes the IO port max address as 0x3fff, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  * the max host bus address. Fixup to a proper range. This will probably
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  * never be fixed in firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static void hisi_lpc_acpi_fixup_child_resource(struct device *hostdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 					       struct resource *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (r->end != 0x3fff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (r->start == 0xe4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		r->end = 0xe4 + 0x04 - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	else if (r->start == 0x2f8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		r->end = 0x2f8 + 0x08 - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		dev_warn(hostdev, "unrecognised resource %pR to fixup, ignoring\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			 r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * hisi_lpc_acpi_set_io_res - set the resources for a child
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * @child: the device node to be updated the I/O resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  * @hostdev: the device node associated with host controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  * @res: double pointer to be set to the address of translated resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  * @num_res: pointer to variable to hold the number of translated resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  * Returns 0 when successful, and a negative value for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  * For a given host controller, each child device will have an associated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  * host-relative address resource.  This function will return the translated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  * logical PIO addresses for each child devices resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static int hisi_lpc_acpi_set_io_res(struct device *child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 				    struct device *hostdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 				    const struct resource **res, int *num_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct acpi_device *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct resource_entry *rentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	LIST_HEAD(resource_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct resource *resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (!child || !hostdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	host = to_acpi_device(hostdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	adev = to_acpi_device(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	if (!adev->status.present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		dev_dbg(child, "device is not present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	if (acpi_device_enumerated(adev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		dev_dbg(child, "has been enumerated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	 * The following code segment to retrieve the resources is common to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	 * acpi_create_platform_device(), so consider a common helper function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	 * in future.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	if (count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		dev_dbg(child, "failed to get resources\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		return count ? count : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	resources = devm_kcalloc(hostdev, count, sizeof(*resources),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 				 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (!resources) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		dev_warn(hostdev, "could not allocate memory for %d resources\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			 count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		acpi_dev_free_resource_list(&resource_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	list_for_each_entry(rentry, &resource_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		resources[count] = *rentry->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		hisi_lpc_acpi_fixup_child_resource(hostdev, &resources[count]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	acpi_dev_free_resource_list(&resource_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	/* translate the I/O resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		if (!(resources[i].flags & IORESOURCE_IO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		ret = hisi_lpc_acpi_xlat_io_res(adev, host, &resources[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			dev_err(child, "translate IO range %pR failed (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 				&resources[i], ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	*res = resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	*num_res = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static int hisi_lpc_acpi_remove_subdev(struct device *dev, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	platform_device_unregister(to_platform_device(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct hisi_lpc_acpi_cell {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	const char *hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	void *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	size_t pdata_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static void hisi_lpc_acpi_remove(struct device *hostdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	struct acpi_device *adev = ACPI_COMPANION(hostdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	struct acpi_device *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	device_for_each_child(hostdev, NULL, hisi_lpc_acpi_remove_subdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	list_for_each_entry(child, &adev->children, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		acpi_device_clear_enumerated(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)  * hisi_lpc_acpi_probe - probe children for ACPI FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)  * @hostdev: LPC host device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)  * Returns 0 when successful, and a negative value for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)  * Create a platform device per child, fixing up the resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)  * from bus addresses to Logical PIO addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static int hisi_lpc_acpi_probe(struct device *hostdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	struct acpi_device *adev = ACPI_COMPANION(hostdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	struct acpi_device *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	/* Only consider the children of the host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	list_for_each_entry(child, &adev->children, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		const char *hid = acpi_device_hid(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		const struct hisi_lpc_acpi_cell *cell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		const struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		int num_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		ret = hisi_lpc_acpi_set_io_res(&child->dev, &adev->dev, &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 					       &num_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			dev_warn(hostdev, "set resource fail (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		cell = (struct hisi_lpc_acpi_cell []){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			/* ipmi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 				.hid = "IPI0001",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 				.name = "hisi-lpc-ipmi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 			/* 8250-compatible uart */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 				.hid = "HISI1031",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 				.name = "serial8250",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 				.pdata = (struct plat_serial8250_port []) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 					{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 						.iobase = res->start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 						.uartclk = 1843200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 						.iotype = UPIO_PORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 						.flags = UPF_BOOT_AUTOCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 					},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 					{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 				},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 				.pdata_size = 2 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 					sizeof(struct plat_serial8250_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 			{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		for (; cell && cell->name; cell++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			if (!strcmp(cell->hid, hid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 				found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			dev_warn(hostdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 				 "could not find cell for child device (%s), discarding\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 				 hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		pdev = platform_device_alloc(cell->name, PLATFORM_DEVID_AUTO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		if (!pdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 			ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		pdev->dev.parent = hostdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		ACPI_COMPANION_SET(&pdev->dev, child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		ret = platform_device_add_resources(pdev, res, num_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		ret = platform_device_add_data(pdev, cell->pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 					       cell->pdata_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		ret = platform_device_add(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		acpi_device_set_enumerated(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	hisi_lpc_acpi_remove(hostdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static const struct acpi_device_id hisi_lpc_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	{"HISI0191"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) static int hisi_lpc_acpi_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static void hisi_lpc_acpi_remove(struct device *hostdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) #endif // CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)  * hisi_lpc_probe - the probe callback function for hisi lpc host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)  *		   will finish all the initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)  * @pdev: the platform device corresponding to hisi lpc host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)  * Returns 0 on success, non-zero on fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) static int hisi_lpc_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	struct acpi_device *acpi_device = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	struct logic_pio_hwaddr *range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	struct hisi_lpc_dev *lpcdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	resource_size_t io_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	lpcdev = devm_kzalloc(dev, sizeof(*lpcdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	if (!lpcdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	spin_lock_init(&lpcdev->cycle_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	lpcdev->membase = devm_ioremap_resource(dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	if (IS_ERR(lpcdev->membase))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		return PTR_ERR(lpcdev->membase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	if (!range)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	range->fwnode = dev->fwnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	range->flags = LOGIC_PIO_INDIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	range->size = PIO_INDIRECT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	range->hostdata = lpcdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	range->ops = &hisi_lpc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	lpcdev->io_host = range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	ret = logic_pio_register_range(range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		dev_err(dev, "register IO range failed (%d)!\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	/* register the LPC host PIO resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	if (acpi_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		ret = hisi_lpc_acpi_probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		logic_pio_unregister_range(range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	dev_set_drvdata(dev, lpcdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	io_end = lpcdev->io_host->io_start + lpcdev->io_host->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	dev_info(dev, "registered range [%pa - %pa]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		 &lpcdev->io_host->io_start, &io_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static int hisi_lpc_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	struct acpi_device *acpi_device = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	struct hisi_lpc_dev *lpcdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	struct logic_pio_hwaddr *range = lpcdev->io_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	if (acpi_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		hisi_lpc_acpi_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		of_platform_depopulate(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	logic_pio_unregister_range(range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) static const struct of_device_id hisi_lpc_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	{ .compatible = "hisilicon,hip06-lpc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	{ .compatible = "hisilicon,hip07-lpc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) static struct platform_driver hisi_lpc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		.name           = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 		.of_match_table = hisi_lpc_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		.acpi_match_table = ACPI_PTR(hisi_lpc_acpi_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	.probe = hisi_lpc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	.remove = hisi_lpc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) builtin_platform_driver(hisi_lpc_driver);