hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/i2c/busses/i2c-piix4.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and
34 Philip Edelbrock <phil@netroedge.com>
45
5
- This program is free software; you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation; either version 2 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
146 */
157
168 /*
....@@ -19,6 +11,7 @@
1911 Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100
2012 ATI IXP200, IXP300, IXP400, SB600, SB700/SP5100, SB800
2113 AMD Hudson-2, ML, CZ
14
+ Hygon CZ
2215 SMSC Victory66
2316
2417 Note: we assume there can only be one device, with one or more
....@@ -79,7 +72,8 @@
7972 #define PIIX4_BLOCK_DATA 0x14
8073
8174 /* Multi-port constants */
82
-#define PIIX4_MAX_ADAPTERS 4
75
+#define PIIX4_MAX_ADAPTERS 4
76
+#define HUDSON2_MAIN_PORTS 2 /* HUDSON2, KERNCZ reserves ports 3, 4 */
8377
8478 /* SB800 constants */
8579 #define SB800_PIIX4_SMB_IDX 0xcd6
....@@ -289,7 +283,9 @@
289283 PIIX4_dev->revision >= 0x41) ||
290284 (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD &&
291285 PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS &&
292
- PIIX4_dev->revision >= 0x49))
286
+ PIIX4_dev->revision >= 0x49) ||
287
+ (PIIX4_dev->vendor == PCI_VENDOR_ID_HYGON &&
288
+ PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS))
293289 smb_en = 0x00;
294290 else
295291 smb_en = (aux) ? 0x28 : 0x2c;
....@@ -361,7 +357,8 @@
361357 piix4_smba, i2ccfg >> 4);
362358
363359 /* Find which register is used for port selection */
364
- if (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD) {
360
+ if (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD ||
361
+ PIIX4_dev->vendor == PCI_VENDOR_ID_HYGON) {
365362 if (PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS ||
366363 (PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS &&
367364 PIIX4_dev->revision >= 0x1F)) {
....@@ -792,6 +789,7 @@
792789 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) },
793790 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) },
794791 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) },
792
+ { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) },
795793 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
796794 PCI_DEVICE_ID_SERVERWORKS_OSB4) },
797795 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
....@@ -809,10 +807,12 @@
809807
810808 static struct i2c_adapter *piix4_main_adapters[PIIX4_MAX_ADAPTERS];
811809 static struct i2c_adapter *piix4_aux_adapter;
810
+static int piix4_adapter_count;
812811
813812 static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba,
814813 bool sb800_main, u8 port, bool notify_imc,
815
- const char *name, struct i2c_adapter **padap)
814
+ u8 hw_port_nr, const char *name,
815
+ struct i2c_adapter **padap)
816816 {
817817 struct i2c_adapter *adap;
818818 struct i2c_piix4_adapdata *adapdata;
....@@ -844,6 +844,12 @@
844844 /* set up the sysfs linkage to our parent device */
845845 adap->dev.parent = &dev->dev;
846846
847
+ if (has_acpi_companion(&dev->dev)) {
848
+ acpi_preset_companion(&adap->dev,
849
+ ACPI_COMPANION(&dev->dev),
850
+ hw_port_nr);
851
+ }
852
+
847853 snprintf(adap->name, sizeof(adap->name),
848854 "SMBus PIIX4 adapter%s at %04x", name, smba);
849855
....@@ -868,8 +874,19 @@
868874 int port;
869875 int retval;
870876
871
- for (port = 0; port < PIIX4_MAX_ADAPTERS; port++) {
877
+ if (dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS ||
878
+ (dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS &&
879
+ dev->revision >= 0x1F)) {
880
+ piix4_adapter_count = HUDSON2_MAIN_PORTS;
881
+ } else {
882
+ piix4_adapter_count = PIIX4_MAX_ADAPTERS;
883
+ }
884
+
885
+ for (port = 0; port < piix4_adapter_count; port++) {
886
+ u8 hw_port_nr = port == 0 ? 0 : port + 1;
887
+
872888 retval = piix4_add_adapter(dev, smba, true, port, notify_imc,
889
+ hw_port_nr,
873890 piix4_main_port_names_sb800[port],
874891 &piix4_main_adapters[port]);
875892 if (retval < 0)
....@@ -902,11 +919,13 @@
902919 if ((dev->vendor == PCI_VENDOR_ID_ATI &&
903920 dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
904921 dev->revision >= 0x40) ||
905
- dev->vendor == PCI_VENDOR_ID_AMD) {
922
+ dev->vendor == PCI_VENDOR_ID_AMD ||
923
+ dev->vendor == PCI_VENDOR_ID_HYGON) {
906924 bool notify_imc = false;
907925 is_sb800 = true;
908926
909
- if (dev->vendor == PCI_VENDOR_ID_AMD &&
927
+ if ((dev->vendor == PCI_VENDOR_ID_AMD ||
928
+ dev->vendor == PCI_VENDOR_ID_HYGON) &&
910929 dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) {
911930 u8 imc;
912931
....@@ -938,10 +957,11 @@
938957 return retval;
939958
940959 /* Try to register main SMBus adapter, give up if we can't */
941
- retval = piix4_add_adapter(dev, retval, false, 0, false, "",
942
- &piix4_main_adapters[0]);
960
+ retval = piix4_add_adapter(dev, retval, false, 0, false, 0,
961
+ "", &piix4_main_adapters[0]);
943962 if (retval < 0)
944963 return retval;
964
+ piix4_adapter_count = 1;
945965 }
946966
947967 /* Check for auxiliary SMBus on some AMD chipsets */
....@@ -966,7 +986,7 @@
966986 if (retval > 0) {
967987 /* Try to add the aux adapter if it exists,
968988 * piix4_add_adapter will clean up if this fails */
969
- piix4_add_adapter(dev, retval, false, 0, false,
989
+ piix4_add_adapter(dev, retval, false, 0, false, 1,
970990 is_sb800 ? piix4_aux_port_name_sb800 : "",
971991 &piix4_aux_adapter);
972992 }
....@@ -989,7 +1009,7 @@
9891009
9901010 static void piix4_remove(struct pci_dev *dev)
9911011 {
992
- int port = PIIX4_MAX_ADAPTERS;
1012
+ int port = piix4_adapter_count;
9931013
9941014 while (--port >= 0) {
9951015 if (piix4_main_adapters[port]) {
....@@ -1013,7 +1033,7 @@
10131033
10141034 module_pci_driver(piix4_driver);
10151035
1016
-MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
1017
- "Philip Edelbrock <phil@netroedge.com>");
1036
+MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
1037
+MODULE_AUTHOR("Philip Edelbrock <phil@netroedge.com>");
10181038 MODULE_DESCRIPTION("PIIX4 SMBus driver");
10191039 MODULE_LICENSE("GPL");