2222#include <linux/version.h>
2323
2424#include "sbrmi-common.h"
25+ #include "apml_common.h"
2526
2627/* Do not allow setting negative power limit */
2728#define SBRMI_PWR_MIN 0
@@ -491,6 +492,7 @@ static int sbrmi_i2c_probe(struct i2c_client *client)
491492 struct device * hwmon_dev ;
492493 struct apml_sbrmi_device * rmi_dev ;
493494 const char * hwmon_dev_name ;
495+ int ret = 0 ;
494496
495497 rmi_dev = devm_kzalloc (dev , sizeof (struct apml_sbrmi_device ), GFP_KERNEL );
496498 if (!rmi_dev )
@@ -517,7 +519,17 @@ static int sbrmi_i2c_probe(struct i2c_client *client)
517519 return PTR_ERR_OR_ZERO (hwmon_dev );
518520
519521 init_completion (& rmi_dev -> misc_fops_done );
520- return create_misc_rmi_device (rmi_dev , dev );
522+ ret = create_misc_rmi_device (rmi_dev , dev );
523+ if (ret )
524+ return ret ;
525+ /* Register with ALERT_L common system */
526+ ret = apml_register_sbrmi_device (rmi_dev );
527+ if (ret ) {
528+ dev_warn (dev , "Failed to register with ALERT_L common system: %d\n" , ret );
529+ misc_deregister (& rmi_dev -> sbrmi_misc_dev );
530+ return - ENODEV ;
531+ }
532+ return ret ;
521533}
522534
523535static int sbrmi_i3c_reg_read (struct i3c_device * i3cdev , int reg_size , u32 * val )
@@ -713,7 +725,17 @@ static int sbrmi_i3c_probe(struct i3c_device *i3cdev)
713725 }
714726
715727 init_completion (& rmi_dev -> misc_fops_done );
716- return create_misc_rmi_device (rmi_dev , dev );
728+ ret = create_misc_rmi_device (rmi_dev , dev );
729+ if (ret )
730+ return ret ;
731+ /* Register with ALERT_L common system */
732+ ret = apml_register_sbrmi_device (rmi_dev );
733+ if (ret ) {
734+ dev_warn (dev , "Failed to register with ALERT_L common system: %d\n" , ret );
735+ misc_deregister (& rmi_dev -> sbrmi_misc_dev );
736+ return - ENODEV ;
737+ }
738+ return ret ;
717739}
718740
719741#if LINUX_VERSION_CODE < KERNEL_VERSION (6 , 1 , 0 )
@@ -730,7 +752,8 @@ static void sbrmi_i2c_remove(struct i2c_client *client)
730752#else
731753 return ;
732754#endif
733-
755+ /* Unregister from APML common system */
756+ apml_unregister_sbrmi_device (rmi_dev );
734757 /*
735758 * Set the no_new_trans so no new transaction can
736759 * occur in sbrmi_ioctl
@@ -770,7 +793,8 @@ static void sbrmi_i3c_remove(struct i3c_device *i3cdev)
770793#else
771794 return ;
772795#endif
773-
796+ /* Unregister from APML common system */
797+ apml_unregister_sbrmi_device (rmi_dev );
774798 /*
775799 * Set the no_new_trans so no new transaction can
776800 * occur in sbrmi_ioctl
0 commit comments