Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.13-rc7 300 lines 8.0 kB view raw
1/* 2 * omap-control-usb.c - The USB part of control module. 3 * 4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * Author: Kishon Vijay Abraham I <kishon@ti.com> 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 */ 18 19#include <linux/module.h> 20#include <linux/platform_device.h> 21#include <linux/slab.h> 22#include <linux/of.h> 23#include <linux/of_device.h> 24#include <linux/err.h> 25#include <linux/io.h> 26#include <linux/clk.h> 27#include <linux/usb/omap_control_usb.h> 28 29/** 30 * omap_control_usb_phy_power - power on/off the phy using control module reg 31 * @dev: the control module device 32 * @on: 0 or 1, based on powering on or off the PHY 33 */ 34void omap_control_usb_phy_power(struct device *dev, int on) 35{ 36 u32 val; 37 unsigned long rate; 38 struct omap_control_usb *control_usb; 39 40 if (IS_ERR(dev) || !dev) { 41 pr_err("%s: invalid device\n", __func__); 42 return; 43 } 44 45 control_usb = dev_get_drvdata(dev); 46 if (!control_usb) { 47 dev_err(dev, "%s: invalid control usb device\n", __func__); 48 return; 49 } 50 51 if (control_usb->type == OMAP_CTRL_TYPE_OTGHS) 52 return; 53 54 val = readl(control_usb->power); 55 56 switch (control_usb->type) { 57 case OMAP_CTRL_TYPE_USB2: 58 if (on) 59 val &= ~OMAP_CTRL_DEV_PHY_PD; 60 else 61 val |= OMAP_CTRL_DEV_PHY_PD; 62 break; 63 64 case OMAP_CTRL_TYPE_PIPE3: 65 rate = clk_get_rate(control_usb->sys_clk); 66 rate = rate/1000000; 67 68 if (on) { 69 val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK | 70 OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK); 71 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON << 72 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT; 73 val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT; 74 } else { 75 val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK; 76 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF << 77 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT; 78 } 79 break; 80 81 case OMAP_CTRL_TYPE_DRA7USB2: 82 if (on) 83 val &= ~OMAP_CTRL_USB2_PHY_PD; 84 else 85 val |= OMAP_CTRL_USB2_PHY_PD; 86 break; 87 default: 88 dev_err(dev, "%s: type %d not recognized\n", 89 __func__, control_usb->type); 90 break; 91 } 92 93 writel(val, control_usb->power); 94} 95EXPORT_SYMBOL_GPL(omap_control_usb_phy_power); 96 97/** 98 * omap_control_usb_host_mode - set AVALID, VBUSVALID and ID pin in grounded 99 * @ctrl_usb: struct omap_control_usb * 100 * 101 * Writes to the mailbox register to notify the usb core that a usb 102 * device has been connected. 103 */ 104static void omap_control_usb_host_mode(struct omap_control_usb *ctrl_usb) 105{ 106 u32 val; 107 108 val = readl(ctrl_usb->otghs_control); 109 val &= ~(OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_SESSEND); 110 val |= OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID; 111 writel(val, ctrl_usb->otghs_control); 112} 113 114/** 115 * omap_control_usb_device_mode - set AVALID, VBUSVALID and ID pin in high 116 * impedance 117 * @ctrl_usb: struct omap_control_usb * 118 * 119 * Writes to the mailbox register to notify the usb core that it has been 120 * connected to a usb host. 121 */ 122static void omap_control_usb_device_mode(struct omap_control_usb *ctrl_usb) 123{ 124 u32 val; 125 126 val = readl(ctrl_usb->otghs_control); 127 val &= ~OMAP_CTRL_DEV_SESSEND; 128 val |= OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_AVALID | 129 OMAP_CTRL_DEV_VBUSVALID; 130 writel(val, ctrl_usb->otghs_control); 131} 132 133/** 134 * omap_control_usb_set_sessionend - Enable SESSIONEND and IDIG to high 135 * impedance 136 * @ctrl_usb: struct omap_control_usb * 137 * 138 * Writes to the mailbox register to notify the usb core it's now in 139 * disconnected state. 140 */ 141static void omap_control_usb_set_sessionend(struct omap_control_usb *ctrl_usb) 142{ 143 u32 val; 144 145 val = readl(ctrl_usb->otghs_control); 146 val &= ~(OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID); 147 val |= OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_SESSEND; 148 writel(val, ctrl_usb->otghs_control); 149} 150 151/** 152 * omap_control_usb_set_mode - Calls to functions to set USB in one of host mode 153 * or device mode or to denote disconnected state 154 * @dev: the control module device 155 * @mode: The mode to which usb should be configured 156 * 157 * This is an API to write to the mailbox register to notify the usb core that 158 * a usb device has been connected. 159 */ 160void omap_control_usb_set_mode(struct device *dev, 161 enum omap_control_usb_mode mode) 162{ 163 struct omap_control_usb *ctrl_usb; 164 165 if (IS_ERR(dev) || !dev) 166 return; 167 168 ctrl_usb = dev_get_drvdata(dev); 169 170 if (!ctrl_usb) { 171 dev_err(dev, "Invalid control usb device\n"); 172 return; 173 } 174 175 if (ctrl_usb->type != OMAP_CTRL_TYPE_OTGHS) 176 return; 177 178 switch (mode) { 179 case USB_MODE_HOST: 180 omap_control_usb_host_mode(ctrl_usb); 181 break; 182 case USB_MODE_DEVICE: 183 omap_control_usb_device_mode(ctrl_usb); 184 break; 185 case USB_MODE_DISCONNECT: 186 omap_control_usb_set_sessionend(ctrl_usb); 187 break; 188 default: 189 dev_vdbg(dev, "invalid omap control usb mode\n"); 190 } 191} 192EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); 193 194#ifdef CONFIG_OF 195 196static const enum omap_control_usb_type otghs_data = OMAP_CTRL_TYPE_OTGHS; 197static const enum omap_control_usb_type usb2_data = OMAP_CTRL_TYPE_USB2; 198static const enum omap_control_usb_type pipe3_data = OMAP_CTRL_TYPE_PIPE3; 199static const enum omap_control_usb_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2; 200 201static const struct of_device_id omap_control_usb_id_table[] = { 202 { 203 .compatible = "ti,control-phy-otghs", 204 .data = &otghs_data, 205 }, 206 { 207 .compatible = "ti,control-phy-usb2", 208 .data = &usb2_data, 209 }, 210 { 211 .compatible = "ti,control-phy-pipe3", 212 .data = &pipe3_data, 213 }, 214 { 215 .compatible = "ti,control-phy-dra7usb2", 216 .data = &dra7usb2_data, 217 }, 218 {}, 219}; 220MODULE_DEVICE_TABLE(of, omap_control_usb_id_table); 221#endif 222 223 224static int omap_control_usb_probe(struct platform_device *pdev) 225{ 226 struct resource *res; 227 const struct of_device_id *of_id; 228 struct omap_control_usb *control_usb; 229 230 of_id = of_match_device(of_match_ptr(omap_control_usb_id_table), 231 &pdev->dev); 232 if (!of_id) 233 return -EINVAL; 234 235 control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb), 236 GFP_KERNEL); 237 if (!control_usb) { 238 dev_err(&pdev->dev, "unable to alloc memory for control usb\n"); 239 return -ENOMEM; 240 } 241 242 control_usb->dev = &pdev->dev; 243 control_usb->type = *(enum omap_control_usb_type *)of_id->data; 244 245 if (control_usb->type == OMAP_CTRL_TYPE_OTGHS) { 246 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 247 "otghs_control"); 248 control_usb->otghs_control = devm_ioremap_resource( 249 &pdev->dev, res); 250 if (IS_ERR(control_usb->otghs_control)) 251 return PTR_ERR(control_usb->otghs_control); 252 } else { 253 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 254 "power"); 255 control_usb->power = devm_ioremap_resource(&pdev->dev, res); 256 if (IS_ERR(control_usb->power)) { 257 dev_err(&pdev->dev, "Couldn't get power register\n"); 258 return PTR_ERR(control_usb->power); 259 } 260 } 261 262 if (control_usb->type == OMAP_CTRL_TYPE_PIPE3) { 263 control_usb->sys_clk = devm_clk_get(control_usb->dev, 264 "sys_clkin"); 265 if (IS_ERR(control_usb->sys_clk)) { 266 pr_err("%s: unable to get sys_clkin\n", __func__); 267 return -EINVAL; 268 } 269 } 270 271 dev_set_drvdata(control_usb->dev, control_usb); 272 273 return 0; 274} 275 276static struct platform_driver omap_control_usb_driver = { 277 .probe = omap_control_usb_probe, 278 .driver = { 279 .name = "omap-control-usb", 280 .owner = THIS_MODULE, 281 .of_match_table = of_match_ptr(omap_control_usb_id_table), 282 }, 283}; 284 285static int __init omap_control_usb_init(void) 286{ 287 return platform_driver_register(&omap_control_usb_driver); 288} 289subsys_initcall(omap_control_usb_init); 290 291static void __exit omap_control_usb_exit(void) 292{ 293 platform_driver_unregister(&omap_control_usb_driver); 294} 295module_exit(omap_control_usb_exit); 296 297MODULE_ALIAS("platform: omap_control_usb"); 298MODULE_AUTHOR("Texas Instruments Inc."); 299MODULE_DESCRIPTION("OMAP Control Module USB Driver"); 300MODULE_LICENSE("GPL v2");