* [PATCH v6 1/8] i2c: piix4: Change the parameter list of piix4_transaction function
2024-09-19 17:59 [PATCH v6 0/8] Introduce initial AMD ASF Controller driver support Shyam Sundar S K
@ 2024-09-19 17:59 ` Shyam Sundar S K
2024-09-19 17:59 ` [PATCH v6 2/8] i2c: piix4: Move i2c_piix4 macros and structures to common header Shyam Sundar S K
` (6 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-19 17:59 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti
Cc: linux-i2c, Sanket.Goswami, Andy Shevchenko, Patil.Reddy,
Shyam Sundar S K
Currently, `piix4_transaction()` accepts only one parameter, which is the
`i2c_adapter` information. This approach works well as long as SB800 SMBus
port accesses are confined to the piix4 driver. However, with the
implementation of a separate ASF driver and the varying address spaces
across drivers, it is necessary to change the function parameter list of
`piix4_transaction()` to include the port address. This modification
allows other drivers that use piix4 to pass the specific port details they
need to operate on.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Co-developed-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
drivers/i2c/busses/i2c-piix4.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 4e32d57ae0bf..69b362db6d0c 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -536,10 +536,8 @@ static int piix4_setup_aux(struct pci_dev *PIIX4_dev,
return piix4_smba;
}
-static int piix4_transaction(struct i2c_adapter *piix4_adapter)
+static int piix4_transaction(struct i2c_adapter *piix4_adapter, unsigned short piix4_smba)
{
- struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(piix4_adapter);
- unsigned short piix4_smba = adapdata->smba;
int temp;
int result = 0;
int timeout = 0;
@@ -675,7 +673,7 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
- status = piix4_transaction(adap);
+ status = piix4_transaction(adap, piix4_smba);
if (status)
return status;
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH v6 2/8] i2c: piix4: Move i2c_piix4 macros and structures to common header
2024-09-19 17:59 [PATCH v6 0/8] Introduce initial AMD ASF Controller driver support Shyam Sundar S K
2024-09-19 17:59 ` [PATCH v6 1/8] i2c: piix4: Change the parameter list of piix4_transaction function Shyam Sundar S K
@ 2024-09-19 17:59 ` Shyam Sundar S K
2024-09-19 19:51 ` Andy Shevchenko
2024-09-19 17:59 ` [PATCH v6 3/8] i2c: piix4: Export i2c_piix4 driver functions as library Shyam Sundar S K
` (5 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-19 17:59 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti
Cc: linux-i2c, Sanket.Goswami, Andy Shevchenko, Patil.Reddy,
Shyam Sundar S K
Add a separate header file to relocate the common code from the i2c_piix4
driver, allowing the AMD ASF driver to utilize the same code.
Update the MAINTAINERS file to include information about the new common
header file.
Co-developed-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
MAINTAINERS | 2 +-
drivers/i2c/busses/i2c-piix4.c | 21 +-----------------
drivers/i2c/busses/i2c-piix4.h | 39 ++++++++++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 21 deletions(-)
create mode 100644 drivers/i2c/busses/i2c-piix4.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 9278c30ef1d5..815f46948c1b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10684,7 +10684,7 @@ F: drivers/i2c/busses/i2c-i801.c
F: drivers/i2c/busses/i2c-isch.c
F: drivers/i2c/busses/i2c-nforce2-s4985.c
F: drivers/i2c/busses/i2c-nforce2.c
-F: drivers/i2c/busses/i2c-piix4.c
+F: drivers/i2c/busses/i2c-piix4.*
F: drivers/i2c/busses/i2c-sis5595.c
F: drivers/i2c/busses/i2c-sis630.c
F: drivers/i2c/busses/i2c-sis96x.c
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 69b362db6d0c..4f070863a2cc 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -35,20 +35,7 @@
#include <linux/acpi.h>
#include <linux/io.h>
-
-/* PIIX4 SMBus address offsets */
-#define SMBHSTSTS (0 + piix4_smba)
-#define SMBHSLVSTS (1 + piix4_smba)
-#define SMBHSTCNT (2 + piix4_smba)
-#define SMBHSTCMD (3 + piix4_smba)
-#define SMBHSTADD (4 + piix4_smba)
-#define SMBHSTDAT0 (5 + piix4_smba)
-#define SMBHSTDAT1 (6 + piix4_smba)
-#define SMBBLKDAT (7 + piix4_smba)
-#define SMBSLVCNT (8 + piix4_smba)
-#define SMBSHDWCMD (9 + piix4_smba)
-#define SMBSLVEVT (0xA + piix4_smba)
-#define SMBSLVDAT (0xC + piix4_smba)
+#include "i2c-piix4.h"
/* count for request_region */
#define SMBIOSIZE 9
@@ -70,7 +57,6 @@
#define PIIX4_BYTE 0x04
#define PIIX4_BYTE_DATA 0x08
#define PIIX4_WORD_DATA 0x0C
-#define PIIX4_BLOCK_DATA 0x14
/* Multi-port constants */
#define PIIX4_MAX_ADAPTERS 4
@@ -160,11 +146,6 @@ static const char *piix4_main_port_names_sb800[PIIX4_MAX_ADAPTERS] = {
};
static const char *piix4_aux_port_name_sb800 = " port 1";
-struct sb800_mmio_cfg {
- void __iomem *addr;
- bool use_mmio;
-};
-
struct i2c_piix4_adapdata {
unsigned short smba;
diff --git a/drivers/i2c/busses/i2c-piix4.h b/drivers/i2c/busses/i2c-piix4.h
new file mode 100644
index 000000000000..32da914109ba
--- /dev/null
+++ b/drivers/i2c/busses/i2c-piix4.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * PIIX4/SB800 SMBus Interfaces
+ *
+ * Copyright (c) 2024, Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
+ * Sanket Goswami <Sanket.Goswami@amd.com>
+ */
+
+#ifndef I2C_PIIX4_H
+#define I2C_PIIX4_H
+
+#include <linux/types.h>
+
+/* PIIX4 SMBus address offsets */
+#define SMBHSTSTS (0x00 + piix4_smba)
+#define SMBHSLVSTS (0x01 + piix4_smba)
+#define SMBHSTCNT (0x02 + piix4_smba)
+#define SMBHSTCMD (0x03 + piix4_smba)
+#define SMBHSTADD (0x04 + piix4_smba)
+#define SMBHSTDAT0 (0x05 + piix4_smba)
+#define SMBHSTDAT1 (0x06 + piix4_smba)
+#define SMBBLKDAT (0x07 + piix4_smba)
+#define SMBSLVCNT (0x08 + piix4_smba)
+#define SMBSHDWCMD (0x09 + piix4_smba)
+#define SMBSLVEVT (0x0A + piix4_smba)
+#define SMBSLVDAT (0x0C + piix4_smba)
+
+/* PIIX4 constants */
+#define PIIX4_BLOCK_DATA 0x14
+
+struct sb800_mmio_cfg {
+ void __iomem *addr;
+ bool use_mmio;
+};
+
+#endif /* I2C_PIIX4_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v6 2/8] i2c: piix4: Move i2c_piix4 macros and structures to common header
2024-09-19 17:59 ` [PATCH v6 2/8] i2c: piix4: Move i2c_piix4 macros and structures to common header Shyam Sundar S K
@ 2024-09-19 19:51 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2024-09-19 19:51 UTC (permalink / raw)
To: Shyam Sundar S K
Cc: Jean Delvare, Andi Shyti, linux-i2c, Sanket.Goswami, Patil.Reddy
On Thu, Sep 19, 2024 at 11:29:07PM +0530, Shyam Sundar S K wrote:
> Add a separate header file to relocate the common code from the i2c_piix4
> driver, allowing the AMD ASF driver to utilize the same code.
>
> Update the MAINTAINERS file to include information about the new common
> header file.
FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v6 3/8] i2c: piix4: Export i2c_piix4 driver functions as library
2024-09-19 17:59 [PATCH v6 0/8] Introduce initial AMD ASF Controller driver support Shyam Sundar S K
2024-09-19 17:59 ` [PATCH v6 1/8] i2c: piix4: Change the parameter list of piix4_transaction function Shyam Sundar S K
2024-09-19 17:59 ` [PATCH v6 2/8] i2c: piix4: Move i2c_piix4 macros and structures to common header Shyam Sundar S K
@ 2024-09-19 17:59 ` Shyam Sundar S K
2024-09-20 16:24 ` Andy Shevchenko
2024-09-19 17:59 ` [PATCH v6 4/8] i2c: amd-asf: Add ACPI support for AMD ASF Controller Shyam Sundar S K
` (4 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-19 17:59 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti
Cc: linux-i2c, Sanket.Goswami, Andy Shevchenko, Patil.Reddy,
Shyam Sundar S K
Export the following i2c_piix4 driver functions as a library so that the
AMD ASF driver can utilize these core functionalities from the i2c_piix4
driver:
- piix4_sb800_region_request(): Request access to a specific SMBus region
on the SB800 chipset.
- piix4_sb800_region_release(): Release the previously requested SMBus
region on the SB800 chipset.
- piix4_transaction(): Handle SMBus transactions between the SMBus
controller and connected devices.
- piix4_sb800_port_sel(): Select the appropriate SMBus port on the SB800
chipset.
By making these functions available as a library, enable the AMD ASF
driver to leverage the established mechanisms in the i2c_piix4 driver,
promoting code reuse and consistency across different drivers.
Co-developed-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
Note that the git diff view is presented in two separate lines in order to
suppress the checkpatch.pl "CHECKS".
drivers/i2c/busses/i2c-piix4.c | 16 ++++++++++------
drivers/i2c/busses/i2c-piix4.h | 5 +++++
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 4f070863a2cc..c289edc0a6fa 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -156,8 +156,8 @@ struct i2c_piix4_adapdata {
struct sb800_mmio_cfg mmio_cfg;
};
-static int piix4_sb800_region_request(struct device *dev,
- struct sb800_mmio_cfg *mmio_cfg)
+int piix4_sb800_region_request(struct device *dev,
+ struct sb800_mmio_cfg *mmio_cfg)
{
if (mmio_cfg->use_mmio) {
void __iomem *addr;
@@ -195,9 +195,10 @@ static int piix4_sb800_region_request(struct device *dev,
return 0;
}
+EXPORT_SYMBOL_NS_GPL(piix4_sb800_region_request, PIIX4_SMBUS);
-static void piix4_sb800_region_release(struct device *dev,
- struct sb800_mmio_cfg *mmio_cfg)
+void piix4_sb800_region_release(struct device *dev,
+ struct sb800_mmio_cfg *mmio_cfg)
{
if (mmio_cfg->use_mmio) {
iounmap(mmio_cfg->addr);
@@ -208,6 +209,7 @@ static void piix4_sb800_region_release(struct device *dev,
release_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE);
}
+EXPORT_SYMBOL_NS_GPL(piix4_sb800_region_release, PIIX4_SMBUS);
static bool piix4_sb800_use_mmio(struct pci_dev *PIIX4_dev)
{
@@ -517,7 +519,7 @@ static int piix4_setup_aux(struct pci_dev *PIIX4_dev,
return piix4_smba;
}
-static int piix4_transaction(struct i2c_adapter *piix4_adapter, unsigned short piix4_smba)
+int piix4_transaction(struct i2c_adapter *piix4_adapter, unsigned short piix4_smba)
{
int temp;
int result = 0;
@@ -590,6 +592,7 @@ static int piix4_transaction(struct i2c_adapter *piix4_adapter, unsigned short p
inb_p(SMBHSTDAT1));
return result;
}
+EXPORT_SYMBOL_NS_GPL(piix4_transaction, PIIX4_SMBUS);
/* Return negative errno on error. */
static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
@@ -743,7 +746,7 @@ static void piix4_imc_wakeup(void)
release_region(KERNCZ_IMC_IDX, 2);
}
-static int piix4_sb800_port_sel(u8 port, struct sb800_mmio_cfg *mmio_cfg)
+int piix4_sb800_port_sel(u8 port, struct sb800_mmio_cfg *mmio_cfg)
{
u8 smba_en_lo, val;
@@ -765,6 +768,7 @@ static int piix4_sb800_port_sel(u8 port, struct sb800_mmio_cfg *mmio_cfg)
return (smba_en_lo & piix4_port_mask_sb800);
}
+EXPORT_SYMBOL_NS_GPL(piix4_sb800_port_sel, PIIX4_SMBUS);
/*
* Handles access to multiple SMBus ports on the SB800.
diff --git a/drivers/i2c/busses/i2c-piix4.h b/drivers/i2c/busses/i2c-piix4.h
index 32da914109ba..36bc6ce82a27 100644
--- a/drivers/i2c/busses/i2c-piix4.h
+++ b/drivers/i2c/busses/i2c-piix4.h
@@ -36,4 +36,9 @@ struct sb800_mmio_cfg {
bool use_mmio;
};
+int piix4_sb800_port_sel(u8 port, struct sb800_mmio_cfg *mmio_cfg);
+int piix4_transaction(struct i2c_adapter *piix4_adapter, unsigned short piix4_smba);
+int piix4_sb800_region_request(struct device *dev, struct sb800_mmio_cfg *mmio_cfg);
+void piix4_sb800_region_release(struct device *dev, struct sb800_mmio_cfg *mmio_cfg);
+
#endif /* I2C_PIIX4_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v6 3/8] i2c: piix4: Export i2c_piix4 driver functions as library
2024-09-19 17:59 ` [PATCH v6 3/8] i2c: piix4: Export i2c_piix4 driver functions as library Shyam Sundar S K
@ 2024-09-20 16:24 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2024-09-20 16:24 UTC (permalink / raw)
To: Shyam Sundar S K
Cc: Jean Delvare, Andi Shyti, linux-i2c, Sanket.Goswami, Patil.Reddy
On Thu, Sep 19, 2024 at 11:29:08PM +0530, Shyam Sundar S K wrote:
> Export the following i2c_piix4 driver functions as a library so that the
> AMD ASF driver can utilize these core functionalities from the i2c_piix4
> driver:
>
> - piix4_sb800_region_request(): Request access to a specific SMBus region
> on the SB800 chipset.
>
> - piix4_sb800_region_release(): Release the previously requested SMBus
> region on the SB800 chipset.
>
> - piix4_transaction(): Handle SMBus transactions between the SMBus
> controller and connected devices.
>
> - piix4_sb800_port_sel(): Select the appropriate SMBus port on the SB800
> chipset.
>
> By making these functions available as a library, enable the AMD ASF
> driver to leverage the established mechanisms in the i2c_piix4 driver,
> promoting code reuse and consistency across different drivers.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
...
> -static int piix4_sb800_region_request(struct device *dev,
> - struct sb800_mmio_cfg *mmio_cfg)
> +int piix4_sb800_region_request(struct device *dev,
> + struct sb800_mmio_cfg *mmio_cfg)
Now can be one line.
...
> -static void piix4_sb800_region_release(struct device *dev,
> - struct sb800_mmio_cfg *mmio_cfg)
> +void piix4_sb800_region_release(struct device *dev,
> + struct sb800_mmio_cfg *mmio_cfg)
Ditto.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v6 4/8] i2c: amd-asf: Add ACPI support for AMD ASF Controller
2024-09-19 17:59 [PATCH v6 0/8] Introduce initial AMD ASF Controller driver support Shyam Sundar S K
` (2 preceding siblings ...)
2024-09-19 17:59 ` [PATCH v6 3/8] i2c: piix4: Export i2c_piix4 driver functions as library Shyam Sundar S K
@ 2024-09-19 17:59 ` Shyam Sundar S K
2024-09-20 16:27 ` Andy Shevchenko
2024-09-19 17:59 ` [PATCH v6 5/8] i2c: amd-asf: Add i2c_algorithm operations to support AMD ASF with SMBus Shyam Sundar S K
` (3 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-19 17:59 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti
Cc: linux-i2c, Sanket.Goswami, Andy Shevchenko, Patil.Reddy,
Shyam Sundar S K
The AMD ASF controller is presented to the operating system as an ACPI
device. The AMD ASF driver can use ACPI to obtain information about the
ASF controller's attributes, such as the ASF address space and interrupt
number, and to handle ASF interrupts.
Currently, the piix4 driver assumes that a specific port address is
designated for AUX operations. However, with the introduction of ASF, the
same port address may also be used by the ASF controller. Therefore, a
check needs to be added to ensure that if ASF is advertised and enabled in
ACPI, the AUX port should not be configured.
Co-developed-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
drivers/i2c/busses/Kconfig | 16 +++++++
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-amd-asf-plat.c | 69 +++++++++++++++++++++++++++
drivers/i2c/busses/i2c-piix4.c | 12 ++++-
4 files changed, 97 insertions(+), 1 deletion(-)
create mode 100644 drivers/i2c/busses/i2c-amd-asf-plat.c
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index a22f9125322a..03afcdbff209 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -95,6 +95,22 @@ config I2C_AMD_MP2
This driver can also be built as modules. If so, the modules will
be called i2c-amd-mp2-pci and i2c-amd-mp2-plat.
+config I2C_AMD_ASF
+ tristate "AMD ASF I2C Controller Support"
+ depends on I2C_PIIX4
+ help
+ This option enables support for the AMD ASF (Alert Standard Format)
+ I2C controller. The AMD ASF controller is an SMBus controller with
+ built-in ASF functionality, allowing it to issue generic SMBus
+ packets and communicate with the DASH controller using MCTP over
+ ASF.
+
+ If you have an AMD system with ASF support and want to enable this
+ functionality, say Y or M here. If unsure, say N.
+
+ To compile this driver as a module, choose M here: the module will
+ be called i2c_amd_asf_plat.
+
config I2C_HIX5HD2
tristate "Hix5hd2 high-speed I2C driver"
depends on ARCH_HISI || ARCH_HIX5HD2 || COMPILE_TEST
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 78d0561339e5..74920380a337 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
# Embedded system I2C/SMBus host controller drivers
obj-$(CONFIG_I2C_ALTERA) += i2c-altera.o
obj-$(CONFIG_I2C_AMD_MP2) += i2c-amd-mp2-pci.o i2c-amd-mp2-plat.o
+obj-$(CONFIG_I2C_AMD_ASF) += i2c-amd-asf-plat.o
obj-$(CONFIG_I2C_ASPEED) += i2c-aspeed.o
obj-$(CONFIG_I2C_AT91) += i2c-at91.o
i2c-at91-objs := i2c-at91-core.o i2c-at91-master.o
diff --git a/drivers/i2c/busses/i2c-amd-asf-plat.c b/drivers/i2c/busses/i2c-amd-asf-plat.c
new file mode 100644
index 000000000000..56e2d9ba6cfa
--- /dev/null
+++ b/drivers/i2c/busses/i2c-amd-asf-plat.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * AMD Alert Standard Format Platform Driver
+ *
+ * Copyright (c) 2024, Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
+ * Sanket Goswami <Sanket.Goswami@amd.com>
+ */
+
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/gfp_types.h>
+#include <linux/i2c.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/sprintf.h>
+
+#include "i2c-piix4.h"
+
+struct amd_asf_dev {
+ struct i2c_adapter adap;
+ struct sb800_mmio_cfg mmio_cfg;
+ struct resource *port_addr;
+};
+
+static int amd_asf_probe(struct platform_device *pdev)
+{
+ struct amd_asf_dev *asf_dev;
+
+ asf_dev = devm_kzalloc(&pdev->dev, sizeof(*asf_dev), GFP_KERNEL);
+ if (!asf_dev)
+ return dev_err_probe(&pdev->dev, -ENOMEM, "Failed to allocate memory\n");
+
+ asf_dev->mmio_cfg.use_mmio = true;
+ asf_dev->port_addr = platform_get_resource(pdev, IORESOURCE_IO, 0);
+ if (!asf_dev->port_addr)
+ return dev_err_probe(&pdev->dev, -EINVAL, "missing IO resources\n");
+
+ asf_dev->adap.owner = THIS_MODULE;
+ asf_dev->adap.dev.parent = &pdev->dev;
+
+ i2c_set_adapdata(&asf_dev->adap, asf_dev);
+ snprintf(asf_dev->adap.name, sizeof(asf_dev->adap.name), "AMD ASF adapter");
+
+ return devm_i2c_add_adapter(&pdev->dev, &asf_dev->adap);
+}
+
+static const struct acpi_device_id amd_asf_acpi_ids[] = {
+ { "AMDI001A" },
+ { }
+};
+MODULE_DEVICE_TABLE(acpi, amd_asf_acpi_ids);
+
+static struct platform_driver amd_asf_driver = {
+ .driver = {
+ .name = "i2c-amd-asf",
+ .acpi_match_table = amd_asf_acpi_ids,
+ },
+ .probe = amd_asf_probe,
+};
+module_platform_driver(amd_asf_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("AMD Alert Standard Format Driver");
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index c289edc0a6fa..f2c16b06393f 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -87,6 +87,7 @@
#define SB800_PIIX4_FCH_PM_ADDR 0xFED80300
#define SB800_PIIX4_FCH_PM_SIZE 8
+#define SB800_ASF_ACPI_PATH "\\_SB.ASFC"
/* insmod parameters */
@@ -1026,6 +1027,9 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
{
int retval;
bool is_sb800 = false;
+ bool is_asf = false;
+ acpi_status status;
+ acpi_handle handle;
if ((dev->vendor == PCI_VENDOR_ID_ATI &&
dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
@@ -1088,10 +1092,16 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
}
}
+ status = acpi_get_handle(NULL, (acpi_string)SB800_ASF_ACPI_PATH, &handle);
+ if (ACPI_SUCCESS(status))
+ is_asf = true;
+
if (dev->vendor == PCI_VENDOR_ID_AMD &&
(dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS ||
dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS)) {
- retval = piix4_setup_sb800(dev, id, 1);
+ /* Do not setup AUX port if ASF is enabled */
+ if (!is_asf)
+ retval = piix4_setup_sb800(dev, id, 1);
}
if (retval > 0) {
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v6 4/8] i2c: amd-asf: Add ACPI support for AMD ASF Controller
2024-09-19 17:59 ` [PATCH v6 4/8] i2c: amd-asf: Add ACPI support for AMD ASF Controller Shyam Sundar S K
@ 2024-09-20 16:27 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2024-09-20 16:27 UTC (permalink / raw)
To: Shyam Sundar S K
Cc: Jean Delvare, Andi Shyti, linux-i2c, Sanket.Goswami, Patil.Reddy
On Thu, Sep 19, 2024 at 11:29:09PM +0530, Shyam Sundar S K wrote:
> The AMD ASF controller is presented to the operating system as an ACPI
> device. The AMD ASF driver can use ACPI to obtain information about the
> ASF controller's attributes, such as the ASF address space and interrupt
> number, and to handle ASF interrupts.
>
> Currently, the piix4 driver assumes that a specific port address is
> designated for AUX operations. However, with the introduction of ASF, the
> same port address may also be used by the ASF controller. Therefore, a
> check needs to be added to ensure that if ASF is advertised and enabled in
> ACPI, the AUX port should not be configured.
Okay,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v6 5/8] i2c: amd-asf: Add i2c_algorithm operations to support AMD ASF with SMBus
2024-09-19 17:59 [PATCH v6 0/8] Introduce initial AMD ASF Controller driver support Shyam Sundar S K
` (3 preceding siblings ...)
2024-09-19 17:59 ` [PATCH v6 4/8] i2c: amd-asf: Add ACPI support for AMD ASF Controller Shyam Sundar S K
@ 2024-09-19 17:59 ` Shyam Sundar S K
2024-09-20 17:39 ` Andy Shevchenko
2024-09-19 17:59 ` [PATCH v6 6/8] i2c: amd-asf: Add routine to handle the ASF slave process Shyam Sundar S K
` (2 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-19 17:59 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti
Cc: linux-i2c, Sanket.Goswami, Andy Shevchenko, Patil.Reddy,
Shyam Sundar S K
Implement the i2c_algorithm operations to enable support for AMD ASF
(Alert Standard Format) with SMBus. This enhancement includes:
- Adding functionality to identify and select the supported ASF functions.
- Implementing mechanisms for registering and deregistering I2C slave
devices.
- Providing support for data transfer operations over ASF.
Additionally, include a 'select' Kconfig entry as the current patch
utilizes reg_slave and unreg_slave callbacks, which are controlled by
IS_ENABLED(CONFIG_I2C_SLAVE).
Co-developed-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
drivers/i2c/busses/Kconfig | 1 +
drivers/i2c/busses/i2c-amd-asf-plat.c | 181 ++++++++++++++++++++++++++
2 files changed, 182 insertions(+)
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 03afcdbff209..9353946882db 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -98,6 +98,7 @@ config I2C_AMD_MP2
config I2C_AMD_ASF
tristate "AMD ASF I2C Controller Support"
depends on I2C_PIIX4
+ select I2C_SLAVE
help
This option enables support for the AMD ASF (Alert Standard Format)
I2C controller. The AMD ASF controller is an SMBus controller with
diff --git a/drivers/i2c/busses/i2c-amd-asf-plat.c b/drivers/i2c/busses/i2c-amd-asf-plat.c
index 56e2d9ba6cfa..45e54122fa28 100644
--- a/drivers/i2c/busses/i2c-amd-asf-plat.c
+++ b/drivers/i2c/busses/i2c-amd-asf-plat.c
@@ -9,6 +9,7 @@
* Sanket Goswami <Sanket.Goswami@amd.com>
*/
+#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/gfp_types.h>
@@ -22,12 +23,190 @@
#include "i2c-piix4.h"
+/* ASF register bits */
+#define ASF_SLV_LISTN 0
+#define ASF_SLV_INTR 1
+#define ASF_SLV_RST 4
+#define ASF_PEC_SP 5
+#define ASF_DATA_EN 7
+#define ASF_MSTR_EN 16
+#define ASF_CLK_EN 17
+
+/* ASF address offsets */
+#define ASFLISADDR (0x09 + piix4_smba)
+#define ASFSTA (0x0A + piix4_smba)
+#define ASFSLVSTA (0x0D + piix4_smba)
+#define ASFDATABNKSEL (0x13 + piix4_smba)
+#define ASFSLVEN (0x15 + piix4_smba)
+
+#define ASF_BLOCK_MAX_BYTES 72
+
struct amd_asf_dev {
struct i2c_adapter adap;
+ struct i2c_client *target;
struct sb800_mmio_cfg mmio_cfg;
struct resource *port_addr;
};
+static void amd_asf_update_ioport_target(unsigned short piix4_smba, u8 bit,
+ unsigned long offset, bool set)
+{
+ unsigned long reg;
+
+ reg = inb_p(offset);
+ __assign_bit(bit, ®, set);
+ outb_p(reg, offset);
+}
+
+static void amd_asf_update_mmio_target(struct amd_asf_dev *dev, u8 bit, bool set)
+{
+ unsigned long reg;
+
+ reg = ioread32(dev->mmio_cfg.addr);
+ __assign_bit(bit, ®, set);
+ iowrite32(reg, dev->mmio_cfg.addr);
+}
+
+static void amd_asf_setup_target(struct amd_asf_dev *dev)
+{
+ unsigned short piix4_smba = dev->port_addr->start;
+
+ /* Reset both host and target before setting up */
+ outb_p(0, SMBHSTSTS);
+ outb_p(0, ASFSLVSTA);
+ outb_p(0, ASFSTA);
+
+ /* Update target address */
+ amd_asf_update_ioport_target(piix4_smba, ASF_SLV_LISTN, ASFLISADDR, true);
+ /* Enable target and set the clock */
+ amd_asf_update_mmio_target(dev, ASF_MSTR_EN, false);
+ amd_asf_update_mmio_target(dev, ASF_CLK_EN, true);
+ /* Enable target interrupt */
+ amd_asf_update_ioport_target(piix4_smba, ASF_SLV_INTR, ASFSLVEN, true);
+ amd_asf_update_ioport_target(piix4_smba, ASF_SLV_RST, ASFSLVEN, false);
+ /* Enable PEC and PEC append */
+ amd_asf_update_ioport_target(piix4_smba, ASF_DATA_EN, SMBHSTCNT, true);
+ amd_asf_update_ioport_target(piix4_smba, ASF_PEC_SP, SMBHSTCNT, true);
+}
+
+static int amd_asf_access(struct i2c_adapter *adap, u16 addr, u8 command, u8 *data)
+{
+ struct amd_asf_dev *dev = i2c_get_adapdata(adap);
+ unsigned short piix4_smba = dev->port_addr->start;
+ u8 i, len;
+
+ outb_p((addr << 1), SMBHSTADD);
+ outb_p(command, SMBHSTCMD);
+ len = data[0];
+ if (len == 0 || len > ASF_BLOCK_MAX_BYTES)
+ return -EINVAL;
+
+ outb_p(len, SMBHSTDAT0);
+ /* Reset SMBBLKDAT */
+ inb_p(SMBHSTCNT);
+ for (i = 1; i <= len; i++)
+ outb_p(data[i], SMBBLKDAT);
+
+ outb_p(PIIX4_BLOCK_DATA, SMBHSTCNT);
+ /* Enable PEC and PEC append */
+ amd_asf_update_ioport_target(piix4_smba, ASF_DATA_EN, SMBHSTCNT, true);
+ amd_asf_update_ioport_target(piix4_smba, ASF_PEC_SP, SMBHSTCNT, true);
+
+ return piix4_transaction(adap, piix4_smba);
+}
+
+static int amd_asf_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
+{
+ struct amd_asf_dev *dev = i2c_get_adapdata(adap);
+ unsigned short piix4_smba = dev->port_addr->start;
+ u8 asf_data[ASF_BLOCK_MAX_BYTES];
+ struct i2c_msg *dev_msgs = msgs;
+ u8 prev_port;
+ int ret;
+
+ if (msgs->flags & I2C_M_RD) {
+ dev_err(&adap->dev, "ASF: Read not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ /* Exclude the receive header and PEC */
+ if (msgs->len > ASF_BLOCK_MAX_BYTES - 3) {
+ dev_warn(&adap->dev, "ASF: max message length exceeded\n");
+ return -EOPNOTSUPP;
+ }
+
+ asf_data[0] = dev_msgs->len;
+ memcpy(asf_data + 1, dev_msgs[0].buf, dev_msgs->len);
+
+ ret = piix4_sb800_region_request(&adap->dev, &dev->mmio_cfg);
+ if (ret)
+ return ret;
+
+ amd_asf_update_ioport_target(piix4_smba, ASF_SLV_RST, ASFSLVEN, true);
+ amd_asf_update_ioport_target(piix4_smba, ASF_SLV_LISTN, ASFLISADDR, false);
+ /* Clear ASF target status */
+ outb_p(0, ASFSLVSTA);
+
+ /* Enable ASF SMBus controller function */
+ amd_asf_update_mmio_target(dev, ASF_MSTR_EN, true);
+ prev_port = piix4_sb800_port_sel(0, &dev->mmio_cfg);
+ ret = amd_asf_access(adap, msgs->addr, msgs[0].buf[0], asf_data);
+ piix4_sb800_port_sel(prev_port, &dev->mmio_cfg);
+ amd_asf_setup_target(dev);
+ piix4_sb800_region_release(&adap->dev, &dev->mmio_cfg);
+ return ret;
+}
+
+static int amd_asf_reg_target(struct i2c_client *target)
+{
+ struct amd_asf_dev *dev = i2c_get_adapdata(target->adapter);
+ unsigned short piix4_smba = dev->port_addr->start;
+ int ret;
+ u8 reg;
+
+ if (dev->target)
+ return -EBUSY;
+
+ ret = piix4_sb800_region_request(&target->dev, &dev->mmio_cfg);
+ if (ret)
+ return ret;
+
+ reg = (target->addr << 1) | I2C_M_RD;
+ outb_p(reg, ASFLISADDR);
+
+ amd_asf_setup_target(dev);
+ dev->target = target;
+ amd_asf_update_ioport_target(piix4_smba, ASF_DATA_EN, ASFDATABNKSEL, false);
+ piix4_sb800_region_release(&target->dev, &dev->mmio_cfg);
+
+ return 0;
+}
+
+static int amd_asf_unreg_target(struct i2c_client *target)
+{
+ struct amd_asf_dev *dev = i2c_get_adapdata(target->adapter);
+ unsigned short piix4_smba = dev->port_addr->start;
+
+ amd_asf_update_ioport_target(piix4_smba, ASF_SLV_INTR, ASFSLVEN, false);
+ amd_asf_update_ioport_target(piix4_smba, ASF_SLV_RST, ASFSLVEN, true);
+ dev->target = NULL;
+
+ return 0;
+}
+
+static u32 amd_asf_func(struct i2c_adapter *adapter)
+{
+ return I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_BYTE |
+ I2C_FUNC_SLAVE | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | I2C_FUNC_SMBUS_PEC;
+}
+
+static const struct i2c_algorithm amd_asf_smbus_algorithm = {
+ .master_xfer = amd_asf_xfer,
+ .reg_slave = amd_asf_reg_target,
+ .unreg_slave = amd_asf_unreg_target,
+ .functionality = amd_asf_func,
+};
+
static int amd_asf_probe(struct platform_device *pdev)
{
struct amd_asf_dev *asf_dev;
@@ -42,6 +221,7 @@ static int amd_asf_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, -EINVAL, "missing IO resources\n");
asf_dev->adap.owner = THIS_MODULE;
+ asf_dev->adap.algo = &amd_asf_smbus_algorithm;
asf_dev->adap.dev.parent = &pdev->dev;
i2c_set_adapdata(&asf_dev->adap, asf_dev);
@@ -65,5 +245,6 @@ static struct platform_driver amd_asf_driver = {
};
module_platform_driver(amd_asf_driver);
+MODULE_IMPORT_NS(PIIX4_SMBUS);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("AMD Alert Standard Format Driver");
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v6 5/8] i2c: amd-asf: Add i2c_algorithm operations to support AMD ASF with SMBus
2024-09-19 17:59 ` [PATCH v6 5/8] i2c: amd-asf: Add i2c_algorithm operations to support AMD ASF with SMBus Shyam Sundar S K
@ 2024-09-20 17:39 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2024-09-20 17:39 UTC (permalink / raw)
To: Shyam Sundar S K
Cc: Jean Delvare, Andi Shyti, linux-i2c, Sanket.Goswami, Patil.Reddy
On Thu, Sep 19, 2024 at 11:29:10PM +0530, Shyam Sundar S K wrote:
> Implement the i2c_algorithm operations to enable support for AMD ASF
> (Alert Standard Format) with SMBus. This enhancement includes:
>
> - Adding functionality to identify and select the supported ASF functions.
> - Implementing mechanisms for registering and deregistering I2C slave
> devices.
> - Providing support for data transfer operations over ASF.
>
> Additionally, include a 'select' Kconfig entry as the current patch
> utilizes reg_slave and unreg_slave callbacks, which are controlled by
> IS_ENABLED(CONFIG_I2C_SLAVE).
utilizes .reg_slave() and .unreg_slave() callbacks, which are controlled
by CONFIG_I2C_SLAVE.
...
> +static u32 amd_asf_func(struct i2c_adapter *adapter)
> +{
> + return I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_BYTE |
> + I2C_FUNC_SLAVE | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | I2C_FUNC_SMBUS_PEC;
Second line is not indented properly. Also I would suggest to use more logical
grouping and line wrap.
return I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | I2C_FUNC_SMBUS_BLOCK_DATA |
I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_PEC | I2C_FUNC_SLAVE;
> +}
...
With the above changes being applied,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v6 6/8] i2c: amd-asf: Add routine to handle the ASF slave process
2024-09-19 17:59 [PATCH v6 0/8] Introduce initial AMD ASF Controller driver support Shyam Sundar S K
` (4 preceding siblings ...)
2024-09-19 17:59 ` [PATCH v6 5/8] i2c: amd-asf: Add i2c_algorithm operations to support AMD ASF with SMBus Shyam Sundar S K
@ 2024-09-19 17:59 ` Shyam Sundar S K
2024-09-20 17:57 ` Andy Shevchenko
2024-09-19 17:59 ` [PATCH v6 7/8] i2c: amd-asf: Clear remote IRR bit to get successive interrupt Shyam Sundar S K
2024-09-19 17:59 ` [PATCH v6 8/8] MAINTAINERS: Add AMD ASF driver entry Shyam Sundar S K
7 siblings, 1 reply; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-19 17:59 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti
Cc: linux-i2c, Sanket.Goswami, Andy Shevchenko, Patil.Reddy,
Shyam Sundar S K
Add support for handling ASF slave process events as described in the AMD
ASF databook. This involves implementing the correct programming sequence
to manage each ASF packet appropriately.
Co-developed-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
drivers/i2c/busses/i2c-amd-asf-plat.c | 102 ++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/drivers/i2c/busses/i2c-amd-asf-plat.c b/drivers/i2c/busses/i2c-amd-asf-plat.c
index 45e54122fa28..fe6cffa2fba4 100644
--- a/drivers/i2c/busses/i2c-amd-asf-plat.c
+++ b/drivers/i2c/busses/i2c-amd-asf-plat.c
@@ -11,6 +11,7 @@
#include <linux/bitops.h>
#include <linux/device.h>
+#include <linux/devm-helpers.h>
#include <linux/errno.h>
#include <linux/gfp_types.h>
#include <linux/i2c.h>
@@ -33,21 +34,90 @@
#define ASF_CLK_EN 17
/* ASF address offsets */
+#define ASFINDEX (0x07 + piix4_smba)
#define ASFLISADDR (0x09 + piix4_smba)
#define ASFSTA (0x0A + piix4_smba)
#define ASFSLVSTA (0x0D + piix4_smba)
+#define ASFDATARWPTR (0x11 + piix4_smba)
+#define ASFSETDATARDPTR (0x12 + piix4_smba)
#define ASFDATABNKSEL (0x13 + piix4_smba)
#define ASFSLVEN (0x15 + piix4_smba)
#define ASF_BLOCK_MAX_BYTES 72
+#define ASF_ERROR_STATUS GENMASK(3, 1)
struct amd_asf_dev {
struct i2c_adapter adap;
struct i2c_client *target;
+ struct delayed_work work_buf;
struct sb800_mmio_cfg mmio_cfg;
struct resource *port_addr;
};
+static void amd_asf_process_target(struct work_struct *work)
+{
+ struct amd_asf_dev *dev = container_of(work, struct amd_asf_dev, work_buf.work);
+ unsigned short piix4_smba = dev->port_addr->start;
+ u8 data[ASF_BLOCK_MAX_BYTES];
+ u8 bank, reg, cmd;
+ u8 len, idx, val;
+
+ /* Read target status register */
+ reg = inb_p(ASFSLVSTA);
+
+ /* Check if no error bits are set in target status register */
+ if (reg & ASF_ERROR_STATUS) {
+ /* Set bank as full */
+ cmd = 0;
+ reg = reg | GENMASK(3, 2);
+ outb_p(reg, ASFDATABNKSEL);
+ } else {
+ /* Read data bank */
+ reg = inb_p(ASFDATABNKSEL);
+ bank = (reg & BIT(3)) ? 1 : 0;
+
+ /* Set read data bank */
+ if (bank) {
+ reg = reg | BIT(4);
+ reg = reg & ~BIT(3);
+ } else {
+ reg = reg & ~BIT(4);
+ reg = reg & ~BIT(2);
+ }
+
+ /* Read command register */
+ outb_p(reg, ASFDATABNKSEL);
+ cmd = inb_p(ASFINDEX);
+ len = inb_p(ASFDATARWPTR);
+ for (idx = 0; idx < len; idx++)
+ data[idx] = inb_p(ASFINDEX);
+
+ /* Clear data bank status */
+ if (bank) {
+ reg = reg | BIT(3);
+ outb_p(reg, ASFDATABNKSEL);
+ } else {
+ reg = reg | BIT(2);
+ outb_p(reg, ASFDATABNKSEL);
+ }
+ }
+
+ outb_p(0, ASFSETDATARDPTR);
+ if (cmd & BIT(0))
+ return;
+
+ /*
+ * Although i2c_slave_event() returns an appropriate error code, we
+ * don't check it here because we're operating in the workqueue context.
+ */
+ i2c_slave_event(dev->target, I2C_SLAVE_WRITE_REQUESTED, &val);
+ for (idx = 0; idx < len; idx++) {
+ val = data[idx];
+ i2c_slave_event(dev->target, I2C_SLAVE_WRITE_RECEIVED, &val);
+ }
+ i2c_slave_event(dev->target, I2C_SLAVE_STOP, &val);
+}
+
static void amd_asf_update_ioport_target(unsigned short piix4_smba, u8 bit,
unsigned long offset, bool set)
{
@@ -207,9 +277,28 @@ static const struct i2c_algorithm amd_asf_smbus_algorithm = {
.functionality = amd_asf_func,
};
+static irqreturn_t amd_asf_irq_handler(int irq, void *ptr)
+{
+ struct amd_asf_dev *dev = ptr;
+ unsigned short piix4_smba = dev->port_addr->start;
+ u8 target_int = inb_p(ASFSTA);
+
+ if (target_int & BIT(6)) {
+ /* Target Interrupt */
+ outb_p(target_int | BIT(6), ASFSTA);
+ schedule_delayed_work(&dev->work_buf, HZ);
+ } else {
+ /* Controller Interrupt */
+ amd_asf_update_ioport_target(piix4_smba, ASF_SLV_INTR, SMBHSTSTS, true);
+ }
+
+ return IRQ_HANDLED;
+}
+
static int amd_asf_probe(struct platform_device *pdev)
{
struct amd_asf_dev *asf_dev;
+ int ret, irq;
asf_dev = devm_kzalloc(&pdev->dev, sizeof(*asf_dev), GFP_KERNEL);
if (!asf_dev)
@@ -220,6 +309,19 @@ static int amd_asf_probe(struct platform_device *pdev)
if (!asf_dev->port_addr)
return dev_err_probe(&pdev->dev, -EINVAL, "missing IO resources\n");
+ ret = devm_delayed_work_autocancel(&pdev->dev, &asf_dev->work_buf, amd_asf_process_target);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "failed to create work queue\n");
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0)
+ return dev_err_probe(&pdev->dev, irq, "missing IRQ resources\n");
+
+ ret = devm_request_irq(&pdev->dev, irq, amd_asf_irq_handler, IRQF_SHARED,
+ "amd_asf", asf_dev);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Unable to request irq: %d for use\n", irq);
+
asf_dev->adap.owner = THIS_MODULE;
asf_dev->adap.algo = &amd_asf_smbus_algorithm;
asf_dev->adap.dev.parent = &pdev->dev;
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v6 6/8] i2c: amd-asf: Add routine to handle the ASF slave process
2024-09-19 17:59 ` [PATCH v6 6/8] i2c: amd-asf: Add routine to handle the ASF slave process Shyam Sundar S K
@ 2024-09-20 17:57 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2024-09-20 17:57 UTC (permalink / raw)
To: Shyam Sundar S K
Cc: Jean Delvare, Andi Shyti, linux-i2c, Sanket.Goswami, Patil.Reddy
On Thu, Sep 19, 2024 at 11:29:11PM +0530, Shyam Sundar S K wrote:
> Add support for handling ASF slave process events as described in the AMD
> ASF databook. This involves implementing the correct programming sequence
> to manage each ASF packet appropriately.
...
> +static void amd_asf_process_target(struct work_struct *work)
> +{
> + struct amd_asf_dev *dev = container_of(work, struct amd_asf_dev, work_buf.work);
> + unsigned short piix4_smba = dev->port_addr->start;
> + u8 data[ASF_BLOCK_MAX_BYTES];
> + u8 bank, reg, cmd;
> + u8 len, idx, val;
> +
> + /* Read target status register */
> + reg = inb_p(ASFSLVSTA);
> +
> + /* Check if no error bits are set in target status register */
> + if (reg & ASF_ERROR_STATUS) {
> + /* Set bank as full */
> + cmd = 0;
> + reg = reg | GENMASK(3, 2);
reg |= ...
> + outb_p(reg, ASFDATABNKSEL);
> + } else {
> + /* Read data bank */
> + reg = inb_p(ASFDATABNKSEL);
> + bank = (reg & BIT(3)) ? 1 : 0;
> + /* Set read data bank */
> + if (bank) {
> + reg = reg | BIT(4);
> + reg = reg & ~BIT(3);
> + } else {
> + reg = reg & ~BIT(4);
> + reg = reg & ~BIT(2);
> + }
/* Set read data bank */
if (bank) {
reg |= BIT(4);
reg &= ~BIT(3);
} else {
reg &= ~BIT(4);
reg &= ~BIT(2);
}
> + /* Read command register */
> + outb_p(reg, ASFDATABNKSEL);
> + cmd = inb_p(ASFINDEX);
> + len = inb_p(ASFDATARWPTR);
> + for (idx = 0; idx < len; idx++)
> + data[idx] = inb_p(ASFINDEX);
> + /* Clear data bank status */
> + if (bank) {
> + reg = reg | BIT(3);
> + outb_p(reg, ASFDATABNKSEL);
> + } else {
> + reg = reg | BIT(2);
> + outb_p(reg, ASFDATABNKSEL);
> + }
/* Clear data bank status */
if (bank) {
reg |= BIT(3);
outb_p(reg, ASFDATABNKSEL);
} else {
reg |= BIT(2);
outb_p(reg, ASFDATABNKSEL);
}
> + }
> +
> + outb_p(0, ASFSETDATARDPTR);
> + if (cmd & BIT(0))
> + return;
> +
> + /*
> + * Although i2c_slave_event() returns an appropriate error code, we
> + * don't check it here because we're operating in the workqueue context.
> + */
> + i2c_slave_event(dev->target, I2C_SLAVE_WRITE_REQUESTED, &val);
> + for (idx = 0; idx < len; idx++) {
> + val = data[idx];
> + i2c_slave_event(dev->target, I2C_SLAVE_WRITE_RECEIVED, &val);
> + }
> + i2c_slave_event(dev->target, I2C_SLAVE_STOP, &val);
> +}
...
Perhaps it's time to have
struct device *dev = &pdev->dev;
> + ret = devm_delayed_work_autocancel(&pdev->dev, &asf_dev->work_buf, amd_asf_process_target);
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "failed to create work queue\n");
...and this, in particular, becomes shorter.
ret = devm_delayed_work_autocancel(dev, &asf_dev->work_buf, amd_asf_process_target);
if (ret)
return dev_err_probe(dev, ret, "failed to create work queue\n");
> + irq = platform_get_irq(pdev, 0);
> + if (irq < 0)
> + return dev_err_probe(&pdev->dev, irq, "missing IRQ resources\n");
> +
> + ret = devm_request_irq(&pdev->dev, irq, amd_asf_irq_handler, IRQF_SHARED,
> + "amd_asf", asf_dev);
This even can be one line after proposed change.
> + if (ret)
> + return dev_err_probe(&pdev->dev, ret, "Unable to request irq: %d for use\n", irq);
...
With the above changes being applied
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v6 7/8] i2c: amd-asf: Clear remote IRR bit to get successive interrupt
2024-09-19 17:59 [PATCH v6 0/8] Introduce initial AMD ASF Controller driver support Shyam Sundar S K
` (5 preceding siblings ...)
2024-09-19 17:59 ` [PATCH v6 6/8] i2c: amd-asf: Add routine to handle the ASF slave process Shyam Sundar S K
@ 2024-09-19 17:59 ` Shyam Sundar S K
2024-09-20 17:59 ` Andy Shevchenko
2024-09-19 17:59 ` [PATCH v6 8/8] MAINTAINERS: Add AMD ASF driver entry Shyam Sundar S K
7 siblings, 1 reply; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-19 17:59 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti
Cc: linux-i2c, Sanket.Goswami, Andy Shevchenko, Patil.Reddy,
Shyam Sundar S K
To ensure successive interrupts upon packet reception, it is necessary to
clear the remote IRR bit by writing the interrupt number to the EOI
register. The base address for this operation is provided by the BIOS and
retrieved by the driver by traversing the ASF object's namespace.
Co-developed-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
drivers/i2c/busses/i2c-amd-asf-plat.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/i2c/busses/i2c-amd-asf-plat.c b/drivers/i2c/busses/i2c-amd-asf-plat.c
index fe6cffa2fba4..35a1ad0012ec 100644
--- a/drivers/i2c/busses/i2c-amd-asf-plat.c
+++ b/drivers/i2c/busses/i2c-amd-asf-plat.c
@@ -48,6 +48,7 @@
struct amd_asf_dev {
struct i2c_adapter adap;
+ void __iomem *eoi_base;
struct i2c_client *target;
struct delayed_work work_buf;
struct sb800_mmio_cfg mmio_cfg;
@@ -292,12 +293,14 @@ static irqreturn_t amd_asf_irq_handler(int irq, void *ptr)
amd_asf_update_ioport_target(piix4_smba, ASF_SLV_INTR, SMBHSTSTS, true);
}
+ iowrite32(irq, dev->eoi_base);
return IRQ_HANDLED;
}
static int amd_asf_probe(struct platform_device *pdev)
{
struct amd_asf_dev *asf_dev;
+ struct resource *eoi_addr;
int ret, irq;
asf_dev = devm_kzalloc(&pdev->dev, sizeof(*asf_dev), GFP_KERNEL);
@@ -309,6 +312,21 @@ static int amd_asf_probe(struct platform_device *pdev)
if (!asf_dev->port_addr)
return dev_err_probe(&pdev->dev, -EINVAL, "missing IO resources\n");
+ /*
+ * The resource obtained via ACPI might not belong to the ASF device address space. Instead,
+ * it could be within other IP blocks of the ASIC, which are crucial for generating
+ * subsequent interrupts. Therefore, we avoid using devm_platform_ioremap_resource() and
+ * instead use platform_get_resource() and devm_ioremap() separately to prevent any address
+ * space conflicts.
+ */
+ eoi_addr = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!eoi_addr)
+ return dev_err_probe(&pdev->dev, -EINVAL, "missing MEM resources\n");
+
+ asf_dev->eoi_base = devm_ioremap(&pdev->dev, eoi_addr->start, resource_size(eoi_addr));
+ if (!asf_dev->eoi_base)
+ return dev_err_probe(&pdev->dev, -EBUSY, "failed mapping IO region\n");
+
ret = devm_delayed_work_autocancel(&pdev->dev, &asf_dev->work_buf, amd_asf_process_target);
if (ret)
return dev_err_probe(&pdev->dev, ret, "failed to create work queue\n");
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v6 7/8] i2c: amd-asf: Clear remote IRR bit to get successive interrupt
2024-09-19 17:59 ` [PATCH v6 7/8] i2c: amd-asf: Clear remote IRR bit to get successive interrupt Shyam Sundar S K
@ 2024-09-20 17:59 ` Andy Shevchenko
0 siblings, 0 replies; 17+ messages in thread
From: Andy Shevchenko @ 2024-09-20 17:59 UTC (permalink / raw)
To: Shyam Sundar S K
Cc: Jean Delvare, Andi Shyti, linux-i2c, Sanket.Goswami, Patil.Reddy
On Thu, Sep 19, 2024 at 11:29:12PM +0530, Shyam Sundar S K wrote:
> To ensure successive interrupts upon packet reception, it is necessary to
> clear the remote IRR bit by writing the interrupt number to the EOI
> register. The base address for this operation is provided by the BIOS and
> retrieved by the driver by traversing the ASF object's namespace.
...
> + /*
> + * The resource obtained via ACPI might not belong to the ASF device address space. Instead,
> + * it could be within other IP blocks of the ASIC, which are crucial for generating
> + * subsequent interrupts. Therefore, we avoid using devm_platform_ioremap_resource() and
> + * instead use platform_get_resource() and devm_ioremap() separately to prevent any address
s/instead//
> + * space conflicts.
> + */
> + eoi_addr = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!eoi_addr)
> + return dev_err_probe(&pdev->dev, -EINVAL, "missing MEM resources\n");
> +
> + asf_dev->eoi_base = devm_ioremap(&pdev->dev, eoi_addr->start, resource_size(eoi_addr));
> + if (!asf_dev->eoi_base)
> + return dev_err_probe(&pdev->dev, -EBUSY, "failed mapping IO region\n");
...
With the above change being applied,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v6 8/8] MAINTAINERS: Add AMD ASF driver entry
2024-09-19 17:59 [PATCH v6 0/8] Introduce initial AMD ASF Controller driver support Shyam Sundar S K
` (6 preceding siblings ...)
2024-09-19 17:59 ` [PATCH v6 7/8] i2c: amd-asf: Clear remote IRR bit to get successive interrupt Shyam Sundar S K
@ 2024-09-19 17:59 ` Shyam Sundar S K
2024-09-20 15:06 ` Andy Shevchenko
7 siblings, 1 reply; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-19 17:59 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti
Cc: linux-i2c, Sanket.Goswami, Andy Shevchenko, Patil.Reddy,
Shyam Sundar S K
Update the MAINTAINERS file with AMD ASF driver details.
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---
MAINTAINERS | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 815f46948c1b..9d49a5d366aa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1101,6 +1101,12 @@ L: linux-i2c@vger.kernel.org
S: Maintained
F: drivers/i2c/busses/i2c-amd-mp2*
+AMD ASF I2C DRIVER
+M: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
+L: linux-i2c@vger.kernel.org
+S: Maintained
+F: drivers/i2c/busses/i2c-amd-asf-plat.c
+
AMD PDS CORE DRIVER
M: Shannon Nelson <shannon.nelson@amd.com>
M: Brett Creeley <brett.creeley@amd.com>
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH v6 8/8] MAINTAINERS: Add AMD ASF driver entry
2024-09-19 17:59 ` [PATCH v6 8/8] MAINTAINERS: Add AMD ASF driver entry Shyam Sundar S K
@ 2024-09-20 15:06 ` Andy Shevchenko
2024-09-23 7:31 ` Shyam Sundar S K
0 siblings, 1 reply; 17+ messages in thread
From: Andy Shevchenko @ 2024-09-20 15:06 UTC (permalink / raw)
To: Shyam Sundar S K
Cc: Jean Delvare, Andi Shyti, linux-i2c, Sanket.Goswami, Patil.Reddy
On Thu, Sep 19, 2024 at 11:29:13PM +0530, Shyam Sundar S K wrote:
> Update the MAINTAINERS file with AMD ASF driver details.
...
> +AMD ASF I2C DRIVER
> +M: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
> +L: linux-i2c@vger.kernel.org
> +S: Maintained
> +F: drivers/i2c/busses/i2c-amd-asf-plat.c
Just to be sure that people at AMD understand the difference between
Maintained and Supported in S: line.
The first one more for volunteers, while the second one for paid job.
Maybe someone should go through the entire MAINTAINERS database and
revisit AMD related records?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v6 8/8] MAINTAINERS: Add AMD ASF driver entry
2024-09-20 15:06 ` Andy Shevchenko
@ 2024-09-23 7:31 ` Shyam Sundar S K
0 siblings, 0 replies; 17+ messages in thread
From: Shyam Sundar S K @ 2024-09-23 7:31 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jean Delvare, Andi Shyti, linux-i2c, Sanket.Goswami, Patil.Reddy
On 9/20/2024 20:36, Andy Shevchenko wrote:
> On Thu, Sep 19, 2024 at 11:29:13PM +0530, Shyam Sundar S K wrote:
>> Update the MAINTAINERS file with AMD ASF driver details.
>
> ...
>
>> +AMD ASF I2C DRIVER
>> +M: Shyam Sundar S K <shyam-sundar.s-k@amd.com>
>> +L: linux-i2c@vger.kernel.org
>> +S: Maintained
>> +F: drivers/i2c/busses/i2c-amd-asf-plat.c
>
> Just to be sure that people at AMD understand the difference between
> Maintained and Supported in S: line.
>
> The first one more for volunteers, while the second one for paid job.
> Maybe someone should go through the entire MAINTAINERS database and
> revisit AMD related records?
>
That's right. Thanks for bringing this up. I do see a bit of odds out
there and will bring this up in the next internal summit.
Thanks,
Shyam
^ permalink raw reply [flat|nested] 17+ messages in thread