Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d94832a authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: pmic-voter: Add API to override votes"

parents 3bde71a3 50888a8a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1117,7 +1117,7 @@ static int get_time_to_full_locked(struct ttf *ttf, int *val)

			/* Calculate OCV for each window */
			if (power_approx) {
				i_step = pbatt_avg / max((u32)MILLI_UNIT,
				i_step = pbatt_avg / max(MILLI_UNIT,
					(step_chg_cfg[i].high_threshold /
						MILLI_UNIT));
			} else {
+74 −4
Original line number Diff line number Diff line
@@ -28,12 +28,14 @@ struct client_vote {

struct votable {
	const char		*name;
	const char		*override_client;
	struct list_head	list;
	struct client_vote	votes[NUM_MAX_CLIENTS];
	int			num_clients;
	int			type;
	int			effective_client_id;
	int			effective_result;
	int			override_result;
	struct mutex		vote_lock;
	void			*data;
	int			(*callback)(struct votable *votable,
@@ -270,6 +272,9 @@ int get_effective_result_locked(struct votable *votable)
	if (votable->force_active)
		return votable->force_val;

	if (votable->override_result != -EINVAL)
		return votable->override_result;

	return votable->effective_result;
}

@@ -306,6 +311,9 @@ const char *get_effective_client_locked(struct votable *votable)
	if (votable->force_active)
		return DEBUG_FORCE_CLIENT;

	if (votable->override_result != -EINVAL)
		return votable->override_client;

	return get_client_str(votable, votable->effective_client_id);
}

@@ -416,7 +424,8 @@ int vote(struct votable *votable, const char *client_str, bool enabled, int val)
			votable->name, effective_result,
			get_client_str(votable, effective_id),
			effective_id);
		if (votable->callback && !votable->force_active)
		if (votable->callback && !votable->force_active
				&& (votable->override_result == -EINVAL))
			rc = votable->callback(votable, votable->data,
					effective_result,
					get_client_str(votable, effective_id));
@@ -428,6 +437,57 @@ int vote(struct votable *votable, const char *client_str, bool enabled, int val)
	return rc;
}

/**
 * vote_override() -
 *
 * @votable:		The votable object
 * @override_client:	The voting client that will override other client's
 *			votes, that are already present. When force_active
 *			and override votes are set on a votable, force_active's
 *			client will have the higher priority and it's vote will
 *			be the effective one.
 * @enabled:		This provides a means for the override client to exclude
 *			itself from election. This client's vote
 *			(the next argument) will be considered only when
 *			it has enabled its participation. When this is
 *			set true, this will force a value on a MIN/MAX votable
 *			irrespective of its current value.
 * @val:		The vote value. This will be effective only if enabled
 *			is set true.
 * Returns:
 *	The result of vote. 0 is returned if the vote
 *	is successfully set by the overriding client, when enabled is set.
 */
int vote_override(struct votable *votable, const char *override_client,
		  bool enabled, int val)
{
	int rc = 0;

	lock_votable(votable);
	if (votable->force_active) {
		votable->override_result = enabled ? val : -EINVAL;
		goto out;
	}

	if (enabled) {
		rc = votable->callback(votable, votable->data,
					val, override_client);
		if (!rc) {
			votable->override_client = override_client;
			votable->override_result = val;
		}
	} else {
		rc = votable->callback(votable, votable->data,
			votable->effective_result,
			get_client_str(votable, votable->effective_client_id));
		votable->override_result = -EINVAL;
	}

out:
	unlock_votable(votable);
	return rc;
}

int rerun_election(struct votable *votable)
{
	int rc = 0;
@@ -482,6 +542,8 @@ static int force_active_set(void *data, u64 val)
{
	struct votable *votable = data;
	int rc = 0;
	int effective_result;
	const char *client;

	lock_votable(votable);
	votable->force_active = !!val;
@@ -494,9 +556,16 @@ static int force_active_set(void *data, u64 val)
			votable->force_val,
			DEBUG_FORCE_CLIENT);
	} else {
		rc = votable->callback(votable, votable->data,
			votable->effective_result,
			get_client_str(votable, votable->effective_client_id));
		if (votable->override_result != -EINVAL) {
			effective_result = votable->override_result;
			client = votable->override_client;
		} else {
			effective_result = votable->effective_result;
			client = get_client_str(votable,
					votable->effective_client_id);
		}
		rc = votable->callback(votable, votable->data, effective_result,
					client);
	}
out:
	unlock_votable(votable);
@@ -604,6 +673,7 @@ struct votable *create_votable(const char *name,
	votable->callback = callback;
	votable->type = votable_type;
	votable->data = data;
	votable->override_result = -EINVAL;
	mutex_init(&votable->vote_lock);

	/*
+7 −3
Original line number Diff line number Diff line
@@ -3912,12 +3912,16 @@ static int get_rp_based_dcp_current(struct smb_charger *chg, int typec_mode)
int smblib_set_prop_pd_current_max(struct smb_charger *chg,
				    const union power_supply_propval *val)
{
	int rc;
	int rc, icl;

	if (chg->pd_active)
	if (chg->pd_active) {
		icl = get_client_vote(chg->usb_icl_votable, PD_VOTER);
		rc = vote(chg->usb_icl_votable, PD_VOTER, true, val->intval);
	else
		if (val->intval != icl)
			power_supply_changed(chg->usb_psy);
	} else {
		rc = -EPERM;
	}

	return rc;
}
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ static bool is_input_present(struct step_chg_info *chip)

int read_range_data_from_node(struct device_node *node,
		const char *prop_str, struct range_data *ranges,
		u32 max_threshold, u32 max_value)
		int max_threshold, u32 max_value)
{
	int rc = 0, i, length, per_tuple_length, tuples;

+3 −3
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@ struct step_chg_jeita_param {
};

struct range_data {
	u32 low_threshold;
	u32 high_threshold;
	int low_threshold;
	int high_threshold;
	u32 value;
};

@@ -26,5 +26,5 @@ int qcom_step_chg_init(struct device *dev,
void qcom_step_chg_deinit(void);
int read_range_data_from_node(struct device_node *node,
		const char *prop_str, struct range_data *ranges,
		u32 max_threshold, u32 max_value);
		int max_threshold, u32 max_value);
#endif /* __STEP_CHG_H__ */
Loading