Loading drivers/power/supply/qcom/qg-battery-profile.c +65 −47 Original line number Diff line number Diff line Loading @@ -57,6 +57,8 @@ static struct tables table[] = { static struct qg_battery_data *the_battery; static void qg_battery_profile_free(void); static int qg_battery_data_open(struct inode *inode, struct file *file) { struct qg_battery_data *battery = container_of(inode->i_cdev, Loading Loading @@ -427,34 +429,45 @@ int qg_batterydata_init(struct device_node *profile_node) int rc = 0; struct qg_battery_data *battery; /* * If a battery profile is already initialized, free the existing * profile data and re-allocate and load the new profile. This is * required for multi-profile load support. */ if (the_battery) { battery = the_battery; battery->profile_node = NULL; qg_battery_profile_free(); } else { battery = kzalloc(sizeof(*battery), GFP_KERNEL); if (!battery) return -ENOMEM; battery->profile_node = profile_node; /* char device to access battery-profile data */ rc = alloc_chrdev_region(&battery->dev_no, 0, 1, "qg_battery"); rc = alloc_chrdev_region(&battery->dev_no, 0, 1, "qg_battery"); if (rc < 0) { pr_err("Failed to allocate chrdev rc=%d\n", rc); goto free_battery; } cdev_init(&battery->battery_cdev, &qg_battery_data_fops); rc = cdev_add(&battery->battery_cdev, battery->dev_no, 1); rc = cdev_add(&battery->battery_cdev, battery->dev_no, 1); if (rc) { pr_err("Failed to add battery_cdev rc=%d\n", rc); goto unregister_chrdev; } battery->battery_class = class_create(THIS_MODULE, "qg_battery"); battery->battery_class = class_create(THIS_MODULE, "qg_battery"); if (IS_ERR_OR_NULL(battery->battery_class)) { pr_err("Failed to create qg-battery class\n"); rc = -ENODEV; goto delete_cdev; } battery->battery_device = device_create(battery->battery_class, battery->battery_device = device_create( battery->battery_class, NULL, battery->dev_no, NULL, "qg_battery"); if (IS_ERR_OR_NULL(battery->battery_device)) { Loading @@ -462,7 +475,10 @@ int qg_batterydata_init(struct device_node *profile_node) rc = -ENODEV; goto delete_cdev; } the_battery = battery; } battery->profile_node = profile_node; /* parse the battery profile */ rc = qg_parse_battery_profile(battery); if (rc < 0) { Loading @@ -470,9 +486,7 @@ int qg_batterydata_init(struct device_node *profile_node) goto destroy_device; } the_battery = battery; pr_info("QG Battery-profile loaded, '/dev/qg_battery' created!\n"); pr_info("QG Battery-profile loaded\n"); return 0; Loading @@ -487,16 +501,10 @@ int qg_batterydata_init(struct device_node *profile_node) return rc; } void qg_batterydata_exit(void) static void qg_battery_profile_free(void) { int i, j; if (the_battery) { /* unregister the device node */ device_destroy(the_battery->battery_class, the_battery->dev_no); cdev_del(&the_battery->battery_cdev); unregister_chrdev_region(the_battery->dev_no, 1); /* delete all the battery profile memory */ for (i = 0; i < TABLE_MAX; i++) { kfree(the_battery->profile[i].name); Loading @@ -510,6 +518,16 @@ void qg_batterydata_exit(void) } } void qg_batterydata_exit(void) { if (the_battery) { /* unregister the device node */ device_destroy(the_battery->battery_class, the_battery->dev_no); cdev_del(&the_battery->battery_cdev); unregister_chrdev_region(the_battery->dev_no, 1); qg_battery_profile_free(); } kfree(the_battery); the_battery = NULL; } drivers/power/supply/qcom/qg-core.h +4 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ struct qg_dt { bool qg_sleep_config; bool qg_fast_chg_cfg; bool fvss_enable; bool multi_profile_load; }; struct qg_esr_data { Loading @@ -85,10 +86,12 @@ struct qpnp_qg { struct pmic_revid_data *pmic_rev_id; struct regmap *regmap; struct qpnp_vadc_chip *vadc_dev; struct soh_profile *sp; struct power_supply *qg_psy; struct class *qg_class; struct device *qg_device; struct cdev qg_cdev; struct device_node *batt_node; struct dentry *dfs_root; dev_t dev_no; struct work_struct udata_work; Loading Loading @@ -170,6 +173,7 @@ struct qpnp_qg { int sys_soc; int last_adj_ssoc; int recharge_soc; int batt_age_level; struct alarm alarm_timer; u32 sdam_data[SDAM_MAX]; Loading drivers/power/supply/qcom/qg-reg.h +1 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,7 @@ #define QG_SDAM_ESR_DISCHARGE_DELTA_OFFSET 0x6E /* 4-byte 0x6E-0x71 */ #define QG_SDAM_ESR_CHARGE_SF_OFFSET 0x72 /* 2-byte 0x72-0x73 */ #define QG_SDAM_ESR_DISCHARGE_SF_OFFSET 0x74 /* 2-byte 0x74-0x75 */ #define QG_SDAM_BATT_AGE_LEVEL_OFFSET 0x76 /* 1-byte 0x76 */ #define QG_SDAM_MAGIC_OFFSET 0x80 /* 4-byte 0x80-0x83 */ #define QG_SDAM_MAX_OFFSET 0xA4 Loading drivers/power/supply/qcom/qg-sdam.c +5 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,11 @@ static struct qg_sdam_info sdam_info[] = { .offset = QG_SDAM_ESR_DISCHARGE_SF_OFFSET, .length = 2, }, [SDAM_BATT_AGE_LEVEL] = { .name = "SDAM_BATT_AGE_LEVEL_OFFSET", .offset = QG_SDAM_BATT_AGE_LEVEL_OFFSET, .length = 1, }, [SDAM_MAGIC] = { .name = "SDAM_MAGIC_OFFSET", .offset = QG_SDAM_MAGIC_OFFSET, Loading drivers/power/supply/qcom/qg-sdam.h +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ enum qg_sdam_param { SDAM_ESR_CHARGE_SF, SDAM_ESR_DISCHARGE_SF, SDAM_MAGIC, SDAM_BATT_AGE_LEVEL, SDAM_MAX, }; Loading Loading
drivers/power/supply/qcom/qg-battery-profile.c +65 −47 Original line number Diff line number Diff line Loading @@ -57,6 +57,8 @@ static struct tables table[] = { static struct qg_battery_data *the_battery; static void qg_battery_profile_free(void); static int qg_battery_data_open(struct inode *inode, struct file *file) { struct qg_battery_data *battery = container_of(inode->i_cdev, Loading Loading @@ -427,34 +429,45 @@ int qg_batterydata_init(struct device_node *profile_node) int rc = 0; struct qg_battery_data *battery; /* * If a battery profile is already initialized, free the existing * profile data and re-allocate and load the new profile. This is * required for multi-profile load support. */ if (the_battery) { battery = the_battery; battery->profile_node = NULL; qg_battery_profile_free(); } else { battery = kzalloc(sizeof(*battery), GFP_KERNEL); if (!battery) return -ENOMEM; battery->profile_node = profile_node; /* char device to access battery-profile data */ rc = alloc_chrdev_region(&battery->dev_no, 0, 1, "qg_battery"); rc = alloc_chrdev_region(&battery->dev_no, 0, 1, "qg_battery"); if (rc < 0) { pr_err("Failed to allocate chrdev rc=%d\n", rc); goto free_battery; } cdev_init(&battery->battery_cdev, &qg_battery_data_fops); rc = cdev_add(&battery->battery_cdev, battery->dev_no, 1); rc = cdev_add(&battery->battery_cdev, battery->dev_no, 1); if (rc) { pr_err("Failed to add battery_cdev rc=%d\n", rc); goto unregister_chrdev; } battery->battery_class = class_create(THIS_MODULE, "qg_battery"); battery->battery_class = class_create(THIS_MODULE, "qg_battery"); if (IS_ERR_OR_NULL(battery->battery_class)) { pr_err("Failed to create qg-battery class\n"); rc = -ENODEV; goto delete_cdev; } battery->battery_device = device_create(battery->battery_class, battery->battery_device = device_create( battery->battery_class, NULL, battery->dev_no, NULL, "qg_battery"); if (IS_ERR_OR_NULL(battery->battery_device)) { Loading @@ -462,7 +475,10 @@ int qg_batterydata_init(struct device_node *profile_node) rc = -ENODEV; goto delete_cdev; } the_battery = battery; } battery->profile_node = profile_node; /* parse the battery profile */ rc = qg_parse_battery_profile(battery); if (rc < 0) { Loading @@ -470,9 +486,7 @@ int qg_batterydata_init(struct device_node *profile_node) goto destroy_device; } the_battery = battery; pr_info("QG Battery-profile loaded, '/dev/qg_battery' created!\n"); pr_info("QG Battery-profile loaded\n"); return 0; Loading @@ -487,16 +501,10 @@ int qg_batterydata_init(struct device_node *profile_node) return rc; } void qg_batterydata_exit(void) static void qg_battery_profile_free(void) { int i, j; if (the_battery) { /* unregister the device node */ device_destroy(the_battery->battery_class, the_battery->dev_no); cdev_del(&the_battery->battery_cdev); unregister_chrdev_region(the_battery->dev_no, 1); /* delete all the battery profile memory */ for (i = 0; i < TABLE_MAX; i++) { kfree(the_battery->profile[i].name); Loading @@ -510,6 +518,16 @@ void qg_batterydata_exit(void) } } void qg_batterydata_exit(void) { if (the_battery) { /* unregister the device node */ device_destroy(the_battery->battery_class, the_battery->dev_no); cdev_del(&the_battery->battery_cdev); unregister_chrdev_region(the_battery->dev_no, 1); qg_battery_profile_free(); } kfree(the_battery); the_battery = NULL; }
drivers/power/supply/qcom/qg-core.h +4 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ struct qg_dt { bool qg_sleep_config; bool qg_fast_chg_cfg; bool fvss_enable; bool multi_profile_load; }; struct qg_esr_data { Loading @@ -85,10 +86,12 @@ struct qpnp_qg { struct pmic_revid_data *pmic_rev_id; struct regmap *regmap; struct qpnp_vadc_chip *vadc_dev; struct soh_profile *sp; struct power_supply *qg_psy; struct class *qg_class; struct device *qg_device; struct cdev qg_cdev; struct device_node *batt_node; struct dentry *dfs_root; dev_t dev_no; struct work_struct udata_work; Loading Loading @@ -170,6 +173,7 @@ struct qpnp_qg { int sys_soc; int last_adj_ssoc; int recharge_soc; int batt_age_level; struct alarm alarm_timer; u32 sdam_data[SDAM_MAX]; Loading
drivers/power/supply/qcom/qg-reg.h +1 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,7 @@ #define QG_SDAM_ESR_DISCHARGE_DELTA_OFFSET 0x6E /* 4-byte 0x6E-0x71 */ #define QG_SDAM_ESR_CHARGE_SF_OFFSET 0x72 /* 2-byte 0x72-0x73 */ #define QG_SDAM_ESR_DISCHARGE_SF_OFFSET 0x74 /* 2-byte 0x74-0x75 */ #define QG_SDAM_BATT_AGE_LEVEL_OFFSET 0x76 /* 1-byte 0x76 */ #define QG_SDAM_MAGIC_OFFSET 0x80 /* 4-byte 0x80-0x83 */ #define QG_SDAM_MAX_OFFSET 0xA4 Loading
drivers/power/supply/qcom/qg-sdam.c +5 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,11 @@ static struct qg_sdam_info sdam_info[] = { .offset = QG_SDAM_ESR_DISCHARGE_SF_OFFSET, .length = 2, }, [SDAM_BATT_AGE_LEVEL] = { .name = "SDAM_BATT_AGE_LEVEL_OFFSET", .offset = QG_SDAM_BATT_AGE_LEVEL_OFFSET, .length = 1, }, [SDAM_MAGIC] = { .name = "SDAM_MAGIC_OFFSET", .offset = QG_SDAM_MAGIC_OFFSET, Loading
drivers/power/supply/qcom/qg-sdam.h +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ enum qg_sdam_param { SDAM_ESR_CHARGE_SF, SDAM_ESR_DISCHARGE_SF, SDAM_MAGIC, SDAM_BATT_AGE_LEVEL, SDAM_MAX, }; Loading