// SPDX-License-Identifier: GPL-2.0
/*
 * Cadence USBSS DRD Driver.
 *
 * Copyright (C) 2018-2019 Cadence.
 * Copyright (C) 2017-2018 NXP
 * Copyright (C) 2019 Texas Instruments
 *
 * Author: Peter Chen <peter.chen@nxp.com>
 *         Pawel Laszczak <pawell@cadence.com>
 *         Roger Quadros <rogerq@ti.com>
 */

#include <common.h>
#include <dm.h>
#include <log.h>
#include <dm/device-internal.h>
#include <dm/device_compat.h>
#include <dm/devres.h>
#include <dm/lists.h>
#include <linux/bug.h>
#include <linux/kernel.h>
#include <linux/io.h>
#include <usb.h>
#include <usb/xhci.h>

#include "core.h"
#include "host-export.h"
#include "gadget-export.h"
#include "drd.h"

static int cdns3_idle_init(struct cdns3 *cdns);

struct cdns3_host_priv {
	struct xhci_ctrl xhci_ctrl;
	struct cdns3 cdns;
};

struct cdns3_gadget_priv {
	struct cdns3 cdns;
};

static inline
struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns)
{
	WARN_ON(!cdns->roles[cdns->role]);
	return cdns->roles[cdns->role];
}

static int cdns3_role_start(struct cdns3 *cdns, enum usb_role role)
{
	int ret;

	if (WARN_ON(role > USB_ROLE_DEVICE))
		return 0;

	mutex_lock(&cdns->mutex);
	cdns->role = role;
	mutex_unlock(&cdns->mutex);

	if (!cdns->roles[role])
		return -ENXIO;

	if (cdns->roles[role]->state == CDNS3_ROLE_STATE_ACTIVE)
		return 0;

	mutex_lock(&cdns->mutex);
	ret = cdns->roles[role]->start(cdns);
	if (!ret)
		cdns->roles[role]->state = CDNS3_ROLE_STATE_ACTIVE;
	mutex_unlock(&cdns->mutex);

	return ret;
}

static void cdns3_role_stop(struct cdns3 *cdns)
{
	enum usb_role role = cdns->role;

	if (WARN_ON(role > USB_ROLE_DEVICE))
		return;

	if (cdns->roles[role]->state == CDNS3_ROLE_STATE_INACTIVE)
		return;

	mutex_lock(&cdns->mutex);
	cdns->roles[role]->stop(cdns);
	cdns->roles[role]->state = CDNS3_ROLE_STATE_INACTIVE;
	mutex_unlock(&cdns->mutex);
}

static void cdns3_exit_roles(struct cdns3 *cdns)
{
	cdns3_role_stop(cdns);
	cdns3_drd_exit(cdns);
}

static enum usb_role cdsn3_hw_role_state_machine(struct cdns3 *cdns);

/**
 * cdns3_core_init_role - initialize role of operation
 * @cdns: Pointer to cdns3 structure
 *
 * Returns 0 on success otherwise negative errno
 */
static int cdns3_core_init_role(struct cdns3 *cdns)
{
	struct udevice *dev = cdns->dev;
	enum usb_dr_mode best_dr_mode;
	enum usb_dr_mode dr_mode;
	int ret = 0;

	dr_mode = usb_get_dr_mode(dev_ofnode(dev));
	cdns->role = USB_ROLE_NONE;

	/*
	 * If driver can't read mode by means of usb_get_dr_mode function then
	 * chooses mode according with Kernel configuration. This setting
	 * can be restricted later depending on strap pin configuration.
	 */
	if (dr_mode == USB_DR_MODE_UNKNOWN) {
		if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
		    IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
			dr_mode = USB_DR_MODE_OTG;
		else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
			dr_mode = USB_DR_MODE_HOST;
		else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
			dr_mode = USB_DR_MODE_PERIPHERAL;
	}

	/*
	 * At this point cdns->dr_mode contains strap configuration.
	 * Driver try update this setting considering kernel configuration
	 */
	best_dr_mode = cdns->dr_mode;

	ret = cdns3_idle_init(cdns);
	if (ret)
		return ret;

	if (dr_mode == USB_DR_MODE_OTG) {
		best_dr_mode = cdns->dr_mode;
	} else if (cdns->dr_mode == USB_DR_MODE_OTG) {
		best_dr_mode = dr_mode;
	} else if (cdns->dr_mode != dr_mode) {
		dev_err(dev, "Incorrect DRD configuration\n");
		return -EINVAL;
	}

	dr_mode = best_dr_mode;

#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)
	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
		ret = cdns3_host_init(cdns);
		if (ret) {
			dev_err(dev, "Host initialization failed with %d\n",
				ret);
			goto err;
		}
	}
#endif

#if CONFIG_IS_ENABLED(DM_USB_GADGET)
	if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
		ret = cdns3_gadget_init(cdns);
		if (ret) {
			dev_err(dev, "Device initialization failed with %d\n",
				ret);
			goto err;
		}
	}
#endif

	cdns->dr_mode = dr_mode;

	ret = cdns3_drd_update_mode(cdns);
	if (ret)
		goto err;

	if (cdns->dr_mode != USB_DR_MODE_OTG) {
		ret = cdns3_hw_role_switch(cdns);
		if (ret)
			goto err;
	}

	return ret;
err:
	cdns3_exit_roles(cdns);
	return ret;
}

/**
 * cdsn3_hw_role_state_machine - role switch state machine based on hw events
 * @cdns: Pointer to controller structure.
 *
 * Returns next role to be entered based on hw events.
 */
static enum usb_role cdsn3_hw_role_state_machine(struct cdns3 *cdns)
{
	enum usb_role role;
	int id, vbus;

	if (cdns->dr_mode != USB_DR_MODE_OTG)
		goto not_otg;

	id = cdns3_get_id(cdns);
	vbus = cdns3_get_vbus(cdns);

	/*
	 * Role change state machine
	 * Inputs: ID, VBUS
	 * Previous state: cdns->role
	 * Next state: role
	 */
	role = cdns->role;

	switch (role) {
	case USB_ROLE_NONE:
		/*
		 * Driver treats USB_ROLE_NONE synonymous to IDLE state from
		 * controller specification.
		 */
		if (!id)
			role = USB_ROLE_HOST;
		else if (vbus)
			role = USB_ROLE_DEVICE;
		break;
	case USB_ROLE_HOST: /* from HOST, we can only change to NONE */
		if (id)
			role = USB_ROLE_NONE;
		break;
	case USB_ROLE_DEVICE: /* from GADGET, we can only change to NONE*/
		if (!vbus)
			role = USB_ROLE_NONE;
		break;
	}

	dev_dbg(cdns->dev, "role %d -> %d\n", cdns->role, role);

	return role;

not_otg:
	if (cdns3_is_host(cdns))
		role = USB_ROLE_HOST;
	if (cdns3_is_device(cdns))
		role = USB_ROLE_DEVICE;

	return role;
}

static int cdns3_idle_role_start(struct cdns3 *cdns)
{
	return 0;
}

static void cdns3_idle_role_stop(struct cdns3 *cdns)
{
	/* Program Lane swap and bring PHY out of RESET */
	generic_phy_reset(&cdns->usb3_phy);
}

static int cdns3_idle_init(struct cdns3 *cdns)
{
	struct cdns3_role_driver *rdrv;

	rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
	if (!rdrv)
		return -ENOMEM;

	rdrv->start = cdns3_idle_role_start;
	rdrv->stop = cdns3_idle_role_stop;
	rdrv->state = CDNS3_ROLE_STATE_INACTIVE;
	rdrv->suspend = NULL;
	rdrv->resume = NULL;
	rdrv->name = "idle";

	cdns->roles[USB_ROLE_NONE] = rdrv;

	return 0;
}

/**
 * cdns3_hw_role_switch - switch roles based on HW state
 * @cdns3: controller
 */
int cdns3_hw_role_switch(struct cdns3 *cdns)
{
	enum usb_role real_role, current_role;
	int ret = 0;

	/* Do nothing if role based on syfs. */
	if (cdns->role_override)
		return 0;

	current_role = cdns->role;
	real_role = cdsn3_hw_role_state_machine(cdns);

	/* Do nothing if nothing changed */
	if (current_role == real_role)
		goto exit;

	cdns3_role_stop(cdns);

	dev_dbg(cdns->dev, "Switching role %d -> %d", current_role, real_role);

	ret = cdns3_role_start(cdns, real_role);
	if (ret) {
		/* Back to current role */
		dev_err(cdns->dev, "set %d has failed, back to %d\n",
			real_role, current_role);
		ret = cdns3_role_start(cdns, current_role);
		if (ret)
			dev_err(cdns->dev, "back to %d failed too\n",
				current_role);
	}
exit:
	return ret;
}

static int cdns3_probe(struct cdns3 *cdns)
{
	struct udevice *dev = cdns->dev;
	int ret;

	cdns->xhci_regs = dev_remap_addr_name(dev, "xhci");
	if (!cdns->xhci_regs)
		return -EINVAL;

	cdns->dev_regs = dev_remap_addr_name(dev, "dev");
	if (!cdns->dev_regs)
		return -EINVAL;

	mutex_init(&cdns->mutex);

	ret = generic_phy_get_by_name(dev, "cdns3,usb2-phy", &cdns->usb2_phy);
	if (!ret) {
		ret = generic_phy_init(&cdns->usb2_phy);
		if (ret) {
			dev_err(dev, "USB2 PHY init failed: %d\n", ret);
			return ret;
		}
	} else if (ret != -ENOENT && ret != -ENODATA) {
		dev_err(dev, "Couldn't get USB2 PHY:  %d\n", ret);
		return ret;
	}

	ret = generic_phy_get_by_name(dev, "cdns3,usb3-phy", &cdns->usb3_phy);
	if (!ret) {
		ret = generic_phy_init(&cdns->usb3_phy);
		if (ret) {
			dev_err(dev, "USB3 PHY init failed: %d\n", ret);
			return ret;
		}
	} else if (ret != -ENOENT && ret != -ENODATA) {
		dev_err(dev, "Couldn't get USB3 PHY:  %d\n", ret);
		return ret;
	}

	ret = generic_phy_power_on(&cdns->usb2_phy);
	if (ret)
		return ret;

	ret = generic_phy_power_on(&cdns->usb3_phy);
	if (ret)
		return ret;

	ret = cdns3_drd_init(cdns);
	if (ret)
		return ret;

	ret = cdns3_core_init_role(cdns);
	if (ret)
		return ret;

	dev_dbg(dev, "Cadence USB3 core: probe succeed\n");

	return 0;
}

static int cdns3_remove(struct cdns3 *cdns)
{
	cdns3_exit_roles(cdns);
	generic_phy_power_off(&cdns->usb2_phy);
	generic_phy_power_off(&cdns->usb3_phy);
	generic_phy_exit(&cdns->usb2_phy);
	generic_phy_exit(&cdns->usb3_phy);
	return 0;
}

static const struct udevice_id cdns3_ids[] = {
	{ .compatible = "cdns,usb3" },
	{ },
};

int cdns3_bind(struct udevice *parent)
{
	enum usb_dr_mode dr_mode;
	struct udevice *dev;
	const char *driver;
	const char *name;
	ofnode node;
	int ret;

	node = ofnode_by_compatible(dev_ofnode(parent), "cdns,usb3");
	if (!ofnode_valid(node)) {
		ret = -ENODEV;
		goto fail;
	}

	name = ofnode_get_name(node);
	dr_mode = usb_get_dr_mode(node);

	switch (dr_mode) {
#if defined(CONFIG_SPL_USB_HOST) || \
	(!defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_HOST))
	case USB_DR_MODE_HOST:
		debug("%s: dr_mode: HOST\n", __func__);
		driver = "cdns-usb3-host";
		break;
#endif
#if CONFIG_IS_ENABLED(DM_USB_GADGET)
	case USB_DR_MODE_PERIPHERAL:
		debug("%s: dr_mode: PERIPHERAL\n", __func__);
		driver = "cdns-usb3-peripheral";
		break;
#endif
	default:
		printf("%s: unsupported dr_mode\n", __func__);
		ret = -ENODEV;
		goto fail;
	};

	ret = device_bind_driver_to_node(parent, driver, name, node, &dev);
	if (ret) {
		printf("%s: not able to bind usb device mode\n",
		       __func__);
		goto fail;
	}

	return 0;

fail:
	/* do not return an error: failing to bind would hang the board */
	return 0;
}

#if CONFIG_IS_ENABLED(DM_USB_GADGET)
static int cdns3_gadget_probe(struct udevice *dev)
{
	struct cdns3_gadget_priv *priv = dev_get_priv(dev);
	struct cdns3 *cdns = &priv->cdns;

	cdns->dev = dev;

	return cdns3_probe(cdns);
}

static int cdns3_gadget_remove(struct udevice *dev)
{
	struct cdns3_gadget_priv *priv = dev_get_priv(dev);
	struct cdns3 *cdns = &priv->cdns;

	return cdns3_remove(cdns);
}

U_BOOT_DRIVER(cdns_usb3_peripheral) = {
	.name	= "cdns-usb3-peripheral",
	.id	= UCLASS_USB_GADGET_GENERIC,
	.of_match = cdns3_ids,
	.probe = cdns3_gadget_probe,
	.remove = cdns3_gadget_remove,
	.priv_auto	= sizeof(struct cdns3_gadget_priv),
	.flags = DM_FLAG_ALLOC_PRIV_DMA,
};
#endif

#if defined(CONFIG_SPL_USB_HOST) || \
	(!defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_HOST))
static int cdns3_host_probe(struct udevice *dev)
{
	struct cdns3_host_priv *priv = dev_get_priv(dev);
	struct cdns3 *cdns = &priv->cdns;

	cdns->dev = dev;

	return cdns3_probe(cdns);
}

static int cdns3_host_remove(struct udevice *dev)
{
	struct cdns3_host_priv *priv = dev_get_priv(dev);
	struct cdns3 *cdns = &priv->cdns;

	return cdns3_remove(cdns);
}

U_BOOT_DRIVER(cdns_usb3_host) = {
	.name	= "cdns-usb3-host",
	.id	= UCLASS_USB,
	.of_match = cdns3_ids,
	.probe = cdns3_host_probe,
	.remove = cdns3_host_remove,
	.priv_auto	= sizeof(struct cdns3_host_priv),
	.ops = &xhci_usb_ops,
	.flags = DM_FLAG_ALLOC_PRIV_DMA,
};
#endif
