Skip to content

Commit d628617

Browse files
committed
misc: amd-apml: Integrate SBTSI with common device registration framework
Add device registration/unregistration calls to SBTSI drivers. This enables Alert_L driver to discover and safely access registered TSI devices for processing temperature alerts. Remove device tree matching functions from SBTSI drivers that are no longer needed after migrating Alert_L driver to use the global device registry from apml_common framework. The legacy Alert_L module used *_match_i2c/*_match_i3c functions to retrieve device node information from device tree nodes. With the new design, Alert_L module devices are now registered during each module's probe function, making the old matching functions obsolete. Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com> Signed-off-by: sathya priya kumar <SathyaPriya.K@amd.com> Signed-off-by: Akshay Gupta <akshay.gupta@amd.com>
1 parent e7d2266 commit d628617

3 files changed

Lines changed: 32 additions & 29 deletions

File tree

drivers/misc/amd-apml/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ config APML_SBRMI
2929
config APML_SBTSI
3030
tristate "Emulated SB-TSI interface driver over i3c bus"
3131
depends on I3C && !SENSORS_SBTSI
32+
depends on APML_COMMON
3233
select REGMAP_I3C if I3C
3334
help
3435
If you say yes here you get support for emulated TSI

drivers/misc/amd-apml/apml_sbtsi.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
#include <linux/of.h>
2424
#include <linux/regmap.h>
2525
#include <linux/version.h>
26-
#include <linux/amd-apml.h>
2726

28-
#include "sbtsi-common.h"
27+
#include <linux/amd-apml.h>
28+
#include "apml_common.h"
29+
2930
/*
3031
* SB-TSI registers only support SMBus byte data access. "_INT" registers are
3132
* the integer part of a temperature value or limit, and "_DEC" registers are
@@ -475,6 +476,7 @@ static int sbtsi_i3c_probe(struct i3c_device *i3cdev)
475476
};
476477
struct regmap *regmap;
477478
const char *hwmon_dev_name;
479+
int ret;
478480

479481
dev_err(dev, "SBTSI: PID: %llx\n", i3cdev->desc->info.pid);
480482
if (!(I3C_PID_INSTANCE_ID(i3cdev->desc->info.pid) == 0 ||
@@ -524,7 +526,16 @@ static int sbtsi_i3c_probe(struct i3c_device *i3cdev)
524526
return PTR_ERR_OR_ZERO(hwmon_dev);
525527
}
526528

527-
return create_misc_tsi_device(tsi_dev, dev);
529+
ret = create_misc_tsi_device(tsi_dev, dev);
530+
if (ret)
531+
return ret;
532+
533+
/* Register with ALERT_L common system */
534+
ret = apml_register_sbtsi_device(tsi_dev);
535+
if (ret)
536+
dev_warn(dev, "Failed to register with ALERT_L common system: %d\n", ret);
537+
538+
return 0;
528539
}
529540

530541
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0)
@@ -542,6 +553,7 @@ static int sbtsi_i2c_probe(struct i2c_client *client)
542553
.val_bits = 8,
543554
};
544555
const char *hwmon_dev_name;
556+
int ret;
545557

546558
tsi_dev = devm_kzalloc(dev, sizeof(struct apml_sbtsi_device), GFP_KERNEL);
547559
if (!tsi_dev)
@@ -568,7 +580,16 @@ static int sbtsi_i2c_probe(struct i2c_client *client)
568580
if (!hwmon_dev)
569581
return PTR_ERR_OR_ZERO(hwmon_dev);
570582

571-
return create_misc_tsi_device(tsi_dev, dev);
583+
ret = create_misc_tsi_device(tsi_dev, dev);
584+
if (ret)
585+
return ret;
586+
587+
/* Register with ALERT_L common system */
588+
ret = apml_register_sbtsi_device(tsi_dev);
589+
if (ret)
590+
dev_warn(dev, "Failed to register with ALERT_L common system: %d\n", ret);
591+
592+
return 0;
572593
}
573594

574595
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0)
@@ -579,8 +600,10 @@ static void sbtsi_i3c_remove(struct i3c_device *i3cdev)
579600
{
580601
struct apml_sbtsi_device *tsi_dev = dev_get_drvdata(&i3cdev->dev);
581602

582-
if (tsi_dev)
603+
if (tsi_dev) {
604+
apml_unregister_sbtsi_device(tsi_dev);
583605
misc_deregister(&tsi_dev->sbtsi_misc_dev);
606+
}
584607

585608
dev_info(&i3cdev->dev, "Removed sbtsi-i3c driver\n");
586609
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0)
@@ -596,8 +619,10 @@ static void sbtsi_i2c_remove(struct i2c_client *client)
596619
{
597620
struct apml_sbtsi_device *tsi_dev = dev_get_drvdata(&client->dev);
598621

599-
if (tsi_dev)
622+
if (tsi_dev) {
623+
apml_unregister_sbtsi_device(tsi_dev);
600624
misc_deregister(&tsi_dev->sbtsi_misc_dev);
625+
}
601626

602627
dev_info(&client->dev, "Removed sbtsi driver\n");
603628
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
@@ -657,26 +682,6 @@ static struct i2c_driver sbtsi_driver = {
657682

658683
module_i3c_i2c_driver(sbtsi_i3c_driver, &sbtsi_driver)
659684

660-
int sbtsi_match_i3c(struct device *dev, const void *data)
661-
{
662-
const struct device_node *node = (const struct device_node *)data;
663-
664-
if (dev->of_node == node && dev->driver == &sbtsi_i3c_driver.driver)
665-
return 1;
666-
return 0;
667-
}
668-
EXPORT_SYMBOL_GPL(sbtsi_match_i3c);
669-
670-
int sbtsi_match_i2c(struct device *dev, const void *data)
671-
{
672-
const struct device_node *node = (const struct device_node *)data;
673-
674-
if (dev->of_node == node && dev->driver == &sbtsi_driver.driver)
675-
return 1;
676-
return 0;
677-
}
678-
EXPORT_SYMBOL_GPL(sbtsi_match_i2c);
679-
680685
MODULE_AUTHOR("Kun Yi <kunyi@google.com>");
681686
MODULE_DESCRIPTION("Hwmon driver for AMD SB-TSI emulated sensor");
682687
MODULE_LICENSE("GPL");

drivers/misc/amd-apml/sbtsi-common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,4 @@ struct apml_sbtsi_device {
2121
u8 dev_static_addr;
2222
} __packed;
2323

24-
int sbtsi_match_i2c(struct device *dev, const void *data);
25-
int sbtsi_match_i3c(struct device *dev, const void *data);
26-
2724
#endif

0 commit comments

Comments
 (0)