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

Unverified Commit 5b1b9a5b authored by derfelot's avatar derfelot
Browse files

regulator: Add Sony over current protection function

Taken from Sony 47.2.A.10.107 stock kernel
parent 626ae1f0
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -88,11 +88,11 @@ LAB subnode required properties:
					50, 60, 70 and 80.
- interrupts:				Specify the interrupts as per the interrupt
					encoding.
					Currently "lab-vreg-ok" is required and "lab-sc_err"
					is optional for LCD mode in pmi8998.
					For AMOLED mode, "lab-vreg-ok" is required
					only when SWIRE control is enabled and skipping
					2nd SWIRE pulse is required in pmi8952/8996.
					Currently "lab-vreg-ok" is required for
					LCD mode in pmi8998. For AMOLED mode,
					"lab-vreg-ok" is required only when SWIRE
					control is enabled and skipping 2nd SWIRE
					pulse is required in pmi8952/8996.
- interrupt-names:			Interrupt names to match up 1-to-1 with
					the interrupts specified in 'interrupts'
					property.
@@ -213,14 +213,6 @@ IBB subnode required properties:

IBB subnode optional properties:

- interrupts:				Specify the interrupts as per the interrupt
					encoding.
					Currently "ibb-sc-err" could be used for LCD mode
					in pmi8998 to detect the short circuit fault.
- interrupt-names:			Interrupt names to match up 1-to-1 with
					the interrupts specified in 'interrupts'
					property.

- qcom,qpnp-ibb-discharge-resistor:	The discharge resistor in Kilo Ohms which
					controls the soft start time. Supported values
					are 300, 64, 32 and 16.
+4 −0
Original line number Diff line number Diff line
@@ -1003,5 +1003,9 @@ config REGULATOR_STUB
	  Clients can use the real regulator device names with proper
	  constraint checking while the real driver is being developed.

config SOMC_LCD_OCP_ENABLED
	bool "enable SoMC LCD OCP function"
	help
	  Select this to enable SoMC LCD Over current protection function.
endif
+32 −0
Original line number Diff line number Diff line
@@ -12,6 +12,11 @@
 *  option) any later version.
 *
 */
/*
 * NOTE: This file has been modified by Sony Mobile Communications Inc.
 * Modifications are Copyright (c) 2013 Sony Mobile Communications Inc,
 * and licensed under the license of the file.
 */

#include <linux/kernel.h>
#include <linux/init.h>
@@ -3454,6 +3459,33 @@ int regulator_allow_bypass(struct regulator *regulator, bool enable)
}
EXPORT_SYMBOL_GPL(regulator_allow_bypass);

/*
 * regulator_register_ocp_notification - register ocp notification
 * @regulator: regulator source
 * @notification: pointer of client ocp_notification
 *
 */
int regulator_register_ocp_notification(struct regulator *regulator,
			struct regulator_ocp_notification *notification)
{
	struct regulator_dev *rdev = regulator->rdev;
	int ret;

	mutex_lock(&rdev->mutex);

	/* sanity check */
	if (!rdev->desc->ops->register_ocp_notification) {
		ret = -EINVAL;
		goto out;
	}

	ret = rdev->desc->ops->register_ocp_notification(rdev, notification);
out:
	mutex_unlock(&rdev->mutex);
	return ret;
}
EXPORT_SYMBOL_GPL(regulator_register_ocp_notification);

/**
 * regulator_register_notifier - register regulator event notifier
 * @regulator: regulator source
+1133 −340

File changed.

Preview size limit exceeded, changes collapsed.

+47 −0
Original line number Diff line number Diff line
@@ -10,6 +10,11 @@
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
/*
 * NOTE: This file has been modified by Sony Mobile Communications Inc.
 * Modifications are Copyright (c) 2013 Sony Mobile Communications Inc,
 * and licensed under the license of the file.
 */

#define pr_fmt(fmt) "%s: " fmt, __func__

@@ -350,6 +355,8 @@ struct qpnp_regulator {
	int					ocp_count;
	int					ocp_max_retries;
	int					ocp_retry_delay_ms;
	struct regulator_ocp_notification	ocp_notification;
	spinlock_t				ocp_lock;
	int					system_load;
	int					hpm_min_load;
	int					slew_rate;
@@ -1255,6 +1262,34 @@ static int qpnp_regulator_common_enable_time(struct regulator_dev *rdev)
	return vreg->enable_time;
}

static int qpnp_regulator_vs_register_ocp_notification(
				struct regulator_dev *rdev,
				struct regulator_ocp_notification *notification)
{
	unsigned long flags;
	struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);

	spin_lock_irqsave(&vreg->ocp_lock, flags);
	if (notification) {
		/* register ocp notification */
		vreg->ocp_notification = *notification;
	} else {
		/* unregister ocp notification */
		memset(&vreg->ocp_notification, 0,
			sizeof(vreg->ocp_notification));
	}
	spin_unlock_irqrestore(&vreg->ocp_lock, flags);

	if (qpnp_vreg_debug_mask & QPNP_VREG_DEBUG_OCP) {
		pr_info("%s: registered ocp notification(notify=%p, ctxt=%p)\n",
			vreg->rdesc.name,
			vreg->ocp_notification.notify,
			vreg->ocp_notification.ctxt);
	}

	return 0;
}

static int qpnp_regulator_vs_clear_ocp(struct qpnp_regulator *vreg)
{
	int rc;
@@ -1328,8 +1363,14 @@ static irqreturn_t qpnp_regulator_vs_ocp_isr(int irq, void *data)
		schedule_delayed_work(&vreg->ocp_work,
			msecs_to_jiffies(vreg->ocp_retry_delay_ms) + 1);
	} else {
		unsigned long flags;
		vreg_err(vreg, "OCP triggered %d times; no further retries\n",
			vreg->ocp_count);
		spin_lock_irqsave(&vreg->ocp_lock, flags);
		if (vreg->ocp_notification.notify)
			vreg->ocp_notification.notify(
				vreg->ocp_notification.ctxt);
		spin_unlock_irqrestore(&vreg->ocp_lock, flags);
	}

	return IRQ_HANDLED;
@@ -1560,6 +1601,8 @@ static struct regulator_ops qpnp_vs_ops = {
	.disable		= qpnp_regulator_common_disable,
	.is_enabled		= qpnp_regulator_common_is_enabled,
	.enable_time		= qpnp_regulator_common_enable_time,
	.register_ocp_notification
		= qpnp_regulator_vs_register_ocp_notification,
};

static struct regulator_ops qpnp_boost_ops = {
@@ -2336,6 +2379,10 @@ static int qpnp_regulator_probe(struct platform_device *pdev)
	if (vreg->ocp_retry_delay_ms == 0)
		vreg->ocp_retry_delay_ms = QPNP_VS_OCP_DEFAULT_RETRY_DELAY_MS;

	memset(&vreg->ocp_notification, 0,
		sizeof(vreg->ocp_notification));
	spin_lock_init(&vreg->ocp_lock);

	rdesc			= &vreg->rdesc;
	rdesc->id		= to_spmi_device(pdev->dev.parent)->ctrl->nr;
	rdesc->owner		= THIS_MODULE;
Loading