ci_hdrc_msm.c 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
/* Copyright (c) 2010, Code Aurora Forum. 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
 * only version 2 as published by the Free Software Foundation.
 */

#include <linux/module.h>
#include <linux/platform_device.h>
10
#include <linux/pm_runtime.h>
11 12
#include <linux/usb/msm_hsusb_hw.h>
#include <linux/usb/ulpi.h>
13
#include <linux/usb/gadget.h>
14
#include <linux/usb/chipidea.h>
15

16
#include "ci.h"
17

18
#define MSM_USB_BASE	(ci->hw_bank.abs)
19

20
static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
21
{
22
	struct device *dev = ci->gadget.dev.parent;
23 24 25
	int val;

	switch (event) {
26 27
	case CI_HDRC_CONTROLLER_RESET_EVENT:
		dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n");
28 29 30
		writel(0, USB_AHBBURST);
		writel(0, USB_AHBMODE);
		break;
31 32
	case CI_HDRC_CONTROLLER_STOPPED_EVENT:
		dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n");
33 34 35 36
		/*
		 * Put the transceiver in non-driving mode. Otherwise host
		 * may not detect soft-disconnection.
		 */
37
		val = usb_phy_io_read(ci->transceiver, ULPI_FUNC_CTRL);
38 39
		val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
		val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
40
		usb_phy_io_write(ci->transceiver, val, ULPI_FUNC_CTRL);
41 42
		break;
	default:
43
		dev_dbg(dev, "unknown ci_hdrc event\n");
44 45 46 47
		break;
	}
}

48 49 50 51 52 53
static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
	.name			= "ci_hdrc_msm",
	.flags			= CI_HDRC_REGS_SHARED |
				  CI_HDRC_REQUIRE_TRANSCEIVER |
				  CI_HDRC_PULLUP_ON_VBUS |
				  CI_HDRC_DISABLE_STREAMING,
54

55
	.notify_event		= ci_hdrc_msm_notify_event,
56 57
};

58
static int ci_hdrc_msm_probe(struct platform_device *pdev)
59
{
60
	struct platform_device *plat_ci;
61

62
	dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n");
63

64
	plat_ci = ci_hdrc_add_device(&pdev->dev,
65
				pdev->resource, pdev->num_resources,
66
				&ci_hdrc_msm_platdata);
67
	if (IS_ERR(plat_ci)) {
68
		dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
69
		return PTR_ERR(plat_ci);
70 71
	}

72 73
	platform_set_drvdata(pdev, plat_ci);

74 75 76
	pm_runtime_no_callbacks(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

77 78 79
	return 0;
}

80
static int ci_hdrc_msm_remove(struct platform_device *pdev)
81 82 83 84
{
	struct platform_device *plat_ci = platform_get_drvdata(pdev);

	pm_runtime_disable(&pdev->dev);
85
	ci_hdrc_remove_device(plat_ci);
86 87 88 89

	return 0;
}

90 91 92
static struct platform_driver ci_hdrc_msm_driver = {
	.probe = ci_hdrc_msm_probe,
	.remove = ci_hdrc_msm_remove,
93 94 95
	.driver = { .name = "msm_hsusb", },
};

96
module_platform_driver(ci_hdrc_msm_driver);
97

98
MODULE_ALIAS("platform:msm_hsusb");
99
MODULE_ALIAS("platform:ci13xxx_msm");
100
MODULE_LICENSE("GPL v2");