| 1 | /* |
| 2 | * drivers/usb/musb/ubi32_usb.c |
| 3 | * Ubicom32 usb controller driver. |
| 4 | * |
| 5 | * (C) Copyright 2009, Ubicom, Inc. |
| 6 | * Copyright (C) 2005-2006 by Texas Instruments |
| 7 | * |
| 8 | * Derived from the Texas Instruments Inventra Controller Driver for Linux. |
| 9 | * |
| 10 | * This file is part of the Ubicom32 Linux Kernel Port. |
| 11 | * |
| 12 | * The Ubicom32 Linux Kernel Port is free software: you can redistribute |
| 13 | * it and/or modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation, either version 2 of the |
| 15 | * License, or (at your option) any later version. |
| 16 | * |
| 17 | * The Ubicom32 Linux Kernel Port is distributed in the hope that it |
| 18 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 19 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 20 | * the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with the Ubicom32 Linux Kernel Port. If not, |
| 24 | * see <http://www.gnu.org/licenses/>. |
| 25 | * |
| 26 | * Ubicom32 implementation derived from (with many thanks): |
| 27 | * arch/m68knommu |
| 28 | * arch/blackfin |
| 29 | * arch/parisc |
| 30 | */ |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/sched.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/list.h> |
| 37 | #include <linux/clk.h> |
| 38 | #include <linux/io.h> |
| 39 | |
| 40 | #include <asm/io.h> |
| 41 | #include <asm/ip5000.h> |
| 42 | #include "musb_core.h" |
| 43 | |
| 44 | void musb_platform_enable(struct musb *musb) |
| 45 | { |
| 46 | } |
| 47 | void musb_platform_disable(struct musb *musb) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | int musb_platform_set_mode(struct musb *musb, u8 musb_mode) { |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static void ip5k_usb_hcd_vbus_power(struct musb *musb, int is_on, int sleeping) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | static void ip5k_usb_hcd_set_vbus(struct musb *musb, int is_on) |
| 60 | { |
| 61 | u8 devctl; |
| 62 | /* HDRC controls CPEN, but beware current surges during device |
| 63 | * connect. They can trigger transient overcurrent conditions |
| 64 | * that must be ignored. |
| 65 | */ |
| 66 | |
| 67 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 68 | |
| 69 | if (is_on) { |
| 70 | musb->is_active = 1; |
| 71 | musb->xceiv.default_a = 1; |
| 72 | musb->xceiv.state = OTG_STATE_A_WAIT_VRISE; |
| 73 | devctl |= MUSB_DEVCTL_SESSION; |
| 74 | |
| 75 | MUSB_HST_MODE(musb); |
| 76 | } else { |
| 77 | musb->is_active = 0; |
| 78 | |
| 79 | /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and |
| 80 | * jumping right to B_IDLE... |
| 81 | */ |
| 82 | |
| 83 | musb->xceiv.default_a = 0; |
| 84 | musb->xceiv.state = OTG_STATE_B_IDLE; |
| 85 | devctl &= ~MUSB_DEVCTL_SESSION; |
| 86 | |
| 87 | MUSB_DEV_MODE(musb); |
| 88 | } |
| 89 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
| 90 | |
| 91 | DBG(1, "VBUS %s, devctl %02x " |
| 92 | /* otg %3x conf %08x prcm %08x */ "\n", |
| 93 | otg_state_string(musb), |
| 94 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
| 95 | } |
| 96 | static int ip5k_usb_hcd_set_power(struct otg_transceiver *x, unsigned mA) |
| 97 | { |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static int musb_platform_resume(struct musb *musb); |
| 102 | |
| 103 | int __init musb_platform_init(struct musb *musb) |
| 104 | { |
| 105 | |
| 106 | #ifdef CONFIG_UBICOM32_V4 |
| 107 | u32_t chip_id; |
| 108 | asm volatile ( |
| 109 | "move.4 %0, CHIP_ID \n\t" |
| 110 | : "=r" (chip_id) |
| 111 | ); |
| 112 | if (chip_id == 0x30001) { |
| 113 | *((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_TEST)) &= ~(1 << 30); |
| 114 | udelay(1); |
| 115 | *((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_TEST)) &= ~(1 << 31); |
| 116 | } else { |
| 117 | *((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_TEST)) &= ~(1 << 17); |
| 118 | udelay(1); |
| 119 | *((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_TEST)) &= ~(1 << 14); |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | *((u32_t *)(GENERAL_CFG_BASE + GEN_USB_PHY_CFG)) |= ((1 << 14) | (1 <<15)); |
| 124 | |
| 125 | /* The i-clk is AUTO gated. Hence there is no need |
| 126 | * to disable it until the driver is shutdown */ |
| 127 | |
| 128 | clk_enable(musb->clock); |
| 129 | musb_platform_resume(musb); |
| 130 | |
| 131 | ip5k_usb_hcd_vbus_power(musb, musb->board_mode == MUSB_HOST, 1); |
| 132 | |
| 133 | if (is_host_enabled(musb)) |
| 134 | musb->board_set_vbus = ip5k_usb_hcd_set_vbus; |
| 135 | if (is_peripheral_enabled(musb)) |
| 136 | musb->xceiv.set_power = ip5k_usb_hcd_set_power; |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | int musb_platform_suspend(struct musb *musb) |
| 143 | { |
| 144 | return 0; |
| 145 | } |
| 146 | int musb_platform_resume(struct musb *musb) |
| 147 | { |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | int musb_platform_exit(struct musb *musb) |
| 152 | { |
| 153 | ip5k_usb_hcd_vbus_power(musb, 0 /*off*/, 1); |
| 154 | musb_platform_suspend(musb); |
| 155 | return 0; |
| 156 | } |
| 157 | |