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

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

Merge "serial: msm_geni_serial: Allow clock_on/off ioctl to be optional"

parents ee8c074a 8ad13ea5
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ Required properties:

Optional properties:
- qcom,wakeup-byte: Byte to be injected in the tty layer during wakeup isr.

- qcom,auto-suspend-disable: Disable PM runtime API's and make vote clock on/off
		    optional and rely on system suspend/resume.
Example:
qupv3_uart11: qcom,qup_uart@0xa88000 {
	compatible = "qcom,msm-geni-uart";
+67 −16
Original line number Diff line number Diff line
/*
 * Copyright (c) 2017-2019, The Linux foundation. All rights reserved.
 * Copyright (c) 2017-2020, The Linux foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -180,6 +180,7 @@ struct msm_geni_serial_port {
	struct msm_geni_serial_ver_info ver_info;
	u32 cur_tx_remaining;
	bool startup_in_progress;
	bool pm_auto_suspend_disable;
};

static const struct uart_ops msm_geni_serial_pops;
@@ -387,8 +388,12 @@ static int vote_clock_off(struct uart_port *uport)
static int msm_geni_serial_ioctl(struct uart_port *uport, unsigned int cmd,
						unsigned long arg)
{
	struct msm_geni_serial_port *port = GET_DEV_PORT(uport);
	int ret = -ENOIOCTLCMD;

	if (port->pm_auto_suspend_disable)
		return ret;

	switch (cmd) {
	case TIOCPMGET: {
		ret = vote_clock_on(uport);
@@ -561,9 +566,12 @@ static void msm_geni_serial_power_off(struct uart_port *uport)
								__func__);
		return;
	}

	if (pm_runtime_enabled(uport->dev)) {
		pm_runtime_mark_last_busy(uport->dev);
		pm_runtime_put_autosuspend(uport->dev);
	}
}

static int msm_geni_serial_poll_bit(struct uart_port *uport,
				int offset, int bit_field, bool set)
@@ -962,7 +970,7 @@ static void msm_geni_serial_start_tx(struct uart_port *uport)
		goto exit_start_tx;
	}

	if (!uart_console(uport)) {
	if (!uart_console(uport) && pm_runtime_enabled(uport->dev)) {
		IPC_LOG_MSG(msm_port->ipc_log_misc,
				"%s.Power on.\n", __func__);
		pm_runtime_get(uport->dev);
@@ -1771,11 +1779,13 @@ static void msm_geni_serial_shutdown(struct uart_port *uport)
			msm_port->ioctl_count = 0;
		}

		if (pm_runtime_enabled(uport->dev)) {
			ret = pm_runtime_put_sync_suspend(uport->dev);
			if (ret) {
				IPC_LOG_MSG(msm_port->ipc_log_pwr,
				"%s: Failed to suspend:%d\n", __func__, ret);
			}
		}

		if (msm_port->wakeup_irq > 0) {
			irq_set_irq_wake(msm_port->wakeup_irq, 0);
@@ -2488,9 +2498,32 @@ static void msm_geni_serial_cons_pm(struct uart_port *uport,
{
	struct msm_geni_serial_port *msm_port = GET_DEV_PORT(uport);

	if (unlikely(!uart_console(uport)))
	if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF)
		se_geni_resources_on(&msm_port->serial_rsc);
	else if (new_state == UART_PM_STATE_OFF &&
			old_state == UART_PM_STATE_ON)
		se_geni_resources_off(&msm_port->serial_rsc);
}

static void msm_geni_serial_hs_pm(struct uart_port *uport,
		unsigned int new_state, unsigned int old_state)
{
	struct msm_geni_serial_port *msm_port = GET_DEV_PORT(uport);

	/*
	 * This will get call for system suspend/resume and
	 * Applicable for hs-uart without runtime pm framework support.
	 */
	if (pm_runtime_enabled(uport->dev))
		return;

	/*
	 * Default PM State is UNDEFINED Setting it to OFF State.
	 * This will allow add one port to do resources on and off during probe
	 */
	if (old_state == UART_PM_STATE_UNDEFINED)
		old_state = UART_PM_STATE_OFF;

	if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF)
		se_geni_resources_on(&msm_port->serial_rsc);
	else if (new_state == UART_PM_STATE_OFF &&
@@ -2532,6 +2565,8 @@ static const struct uart_ops msm_geni_serial_pops = {
	.break_ctl = msm_geni_serial_break_ctl,
	.flush_buffer = NULL,
	.ioctl = msm_geni_serial_ioctl,
	/* For HSUART nodes without IOCTL support */
	.pm = msm_geni_serial_hs_pm,
};

static const struct of_device_id msm_geni_device_tbl[] = {
@@ -2788,16 +2823,29 @@ static int msm_geni_serial_probe(struct platform_device *pdev)

	uport->private_data = (void *)drv;
	platform_set_drvdata(pdev, dev_port);
	/*
	 * To Disable PM runtime API that will make ioctl based
	 * vote_clock_on/off optional and rely on system PM
	 */
	dev_port->pm_auto_suspend_disable =
		of_property_read_bool(pdev->dev.of_node,
		"qcom,auto-suspend-disable");

	if (is_console) {
		dev_port->handle_rx = handle_rx_console;
		dev_port->rx_fifo = devm_kzalloc(uport->dev, sizeof(u32),
								GFP_KERNEL);
	} else {
		if (dev_port->pm_auto_suspend_disable) {
			pm_runtime_set_active(&pdev->dev);
			pm_runtime_forbid(&pdev->dev);
		} else {
			pm_runtime_set_suspended(&pdev->dev);
			pm_runtime_set_autosuspend_delay(&pdev->dev, 150);
			pm_runtime_use_autosuspend(&pdev->dev);
			pm_runtime_enable(&pdev->dev);
		}
	}

	dev_info(&pdev->dev, "Serial port%d added.FifoSize %d is_console%d\n",
				line, uport->fifosize, is_console);
@@ -2830,6 +2878,8 @@ static int msm_geni_serial_remove(struct platform_device *pdev)
	struct uart_driver *drv =
			(struct uart_driver *)port->uport.private_data;

	if (port->pm_auto_suspend_disable)
		pm_runtime_allow(&pdev->dev);
	wakeup_source_trash(&port->geni_wake);
	uart_remove_one_port(drv, &port->uport);
	return 0;
@@ -2914,7 +2964,7 @@ static int msm_geni_serial_sys_suspend_noirq(struct device *dev)
	struct msm_geni_serial_port *port = platform_get_drvdata(pdev);
	struct uart_port *uport = &port->uport;

	if (uart_console(uport)) {
	if (uart_console(uport) || !pm_runtime_enabled(uport->dev)) {
		uart_suspend_port((struct uart_driver *)uport->private_data,
					uport);
	} else {
@@ -2943,8 +2993,9 @@ static int msm_geni_serial_sys_resume_noirq(struct device *dev)
	struct msm_geni_serial_port *port = platform_get_drvdata(pdev);
	struct uart_port *uport = &port->uport;

	if (uart_console(uport) &&
	    console_suspend_enabled && uport->suspended) {
	if ((uart_console(uport) &&
	    console_suspend_enabled && uport->suspended) ||
		!pm_runtime_enabled(uport->dev)) {
		uart_resume_port((struct uart_driver *)uport->private_data,
									uport);
		disable_irq(uport->irq);