-#include <linux/kernel.h>
-#include <linux/platform_device.h>
-#include <linux/delay.h>
-#include <linux/dma-mapping.h>
-#include <linux/clk.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/of.h>
-#include <linux/err.h>
-#include <linux/io.h>
-#include <linux/of_gpio.h>
-#include <linux/of_device.h>
-#include <linux/gpio.h>
-#include <linux/wakelock.h>
-#include <linux/workqueue.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include "usbdev_grf_regs.h"
+
#include "usbdev_rk.h"
+#include "usbdev_grf_regs.h"
#include "dwc_otg_regs.h"
static struct dwc_otg_control_usb *control_usb;
-static int usb_get_chip_id(void)
-{
- return control_usb->chip_id;
-}
-
#ifdef CONFIG_USB20_OTG
static void usb20otg_hw_init(void)
/* other haredware init,include:
* DRV_VBUS GPIO init */
- gpio_direction_output(control_usb->otg_gpios->gpio, 0);
+ if(gpio_get_value(control_usb->otg_gpios->gpio)){
+ gpio_set_value(control_usb->otg_gpios->gpio, 0);
+ }
}
static void usb20otg_phy_suspend(void* pdata, int suspend)
struct dwc_otg_platform_data *usbpdata=pdata;
struct clk* ahbclk,*phyclk;
- ahbclk = devm_clk_get(usbpdata->dev, "hclk_otg0");
+ ahbclk = devm_clk_get(usbpdata->dev, "hclk_usb0");
if (IS_ERR(ahbclk)) {
- dev_err(usbpdata->dev, "Failed to get hclk_otg0\n");
+ dev_err(usbpdata->dev, "Failed to get hclk_usb0\n");
return;
}
- phyclk = devm_clk_get(usbpdata->dev, "otgphy0");
+ phyclk = devm_clk_get(usbpdata->dev, "clk_usbphy0");
if (IS_ERR(phyclk)) {
- dev_err(usbpdata->dev, "Failed to get otgphy0\n");
+ dev_err(usbpdata->dev, "Failed to get clk_usbphy0\n");
return;
}
// id in grf
ret = control_usb->grf_soc_status0_rk3188->otg_iddig;
break;
+ case USB_CHIP_ID:
+ ret = control_usb->chip_id;
+ break;
+ case USB_REMOTE_WAKEUP:
+ ret = control_usb->remote_wakeup;
+ break;
+ case USB_IRQ_WAKEUP:
+ ret = control_usb->usb_irq_wakeup;
+ break;
default:
break;
}
.clock_init = usb20otg_clock_init,
.clock_enable = usb20otg_clock_enable,
.get_status = usb20otg_get_status,
- .get_chip_id = usb_get_chip_id,
.power_enable = usb20otg_power_enable,
#ifdef CONFIG_RK_USB_UART
.dwc_otg_uart_mode = dwc_otg_uart_mode,
#endif
+ .bc_detect_cb=usb20otg_battery_charger_detect_cb,
};
#endif
/* other haredware init,include:
* DRV_VBUS GPIO init */
- gpio_direction_output(control_usb->host_gpios->gpio, 1);
-
+ if(!gpio_get_value(control_usb->host_gpios->gpio)){
+ gpio_set_value(control_usb->host_gpios->gpio, 1);
+ }
}
static void usb20host_phy_suspend(void* pdata, int suspend)
struct dwc_otg_platform_data *usbpdata=pdata;
struct clk* ahbclk,*phyclk;
- ahbclk = devm_clk_get(usbpdata->dev, "hclk_otg1");
+ ahbclk = devm_clk_get(usbpdata->dev, "hclk_usb1");
if (IS_ERR(ahbclk)) {
- dev_err(usbpdata->dev, "Failed to get hclk_otg1\n");
+ dev_err(usbpdata->dev, "Failed to get hclk_usb1\n");
return;
}
- phyclk = devm_clk_get(usbpdata->dev, "otgphy1");
+ phyclk = devm_clk_get(usbpdata->dev, "clk_usbphy1");
if (IS_ERR(phyclk)) {
- dev_err(usbpdata->dev, "Failed to get otgphy1\n");
+ dev_err(usbpdata->dev, "Failed to get clk_usbphy1\n");
return;
}
// id in grf
ret = control_usb->grf_soc_status0_rk3188->uhost_iddig;
break;
+ case USB_CHIP_ID:
+ ret = control_usb->chip_id;
+ break;
+ case USB_REMOTE_WAKEUP:
+ ret = control_usb->remote_wakeup;
+ break;
+ case USB_IRQ_WAKEUP:
+ ret = control_usb->usb_irq_wakeup;
+ break;
default:
break;
}
.clock_init = usb20host_clock_init,
.clock_enable = usb20host_clock_enable,
.get_status = usb20host_get_status,
- .get_chip_id = usb_get_chip_id,
.power_enable = usb20host_power_enable,
};
#endif
* to uart mode, otg phy 480MHz clk will be closed automatically
*/
struct rkehci_platform_data *usbpdata=pdata;
- struct clk *ahbclk, *phyclk480m_hsic, *phyclk12m_hsic, *phyclk_otgphy1;
+ struct clk *ahbclk, *phyclk480m_hsic, *phyclk12m_hsic, *phyclk_usbphy1;
- phyclk480m_hsic = devm_clk_get(usbpdata->dev, "hsicphy480m");
+ phyclk480m_hsic = devm_clk_get(usbpdata->dev, "hsicphy_480m");
if (IS_ERR(phyclk480m_hsic)) {
- dev_err(usbpdata->dev, "Failed to get hsicphy480m\n");
+ dev_err(usbpdata->dev, "Failed to get hsicphy_480m\n");
return;
}
- phyclk12m_hsic = devm_clk_get(usbpdata->dev, "hsicphy12m");
+ phyclk12m_hsic = devm_clk_get(usbpdata->dev, "hsicphy_12m");
if (IS_ERR(phyclk12m_hsic)) {
- dev_err(usbpdata->dev, "Failed to get hsicphy12m\n");
+ dev_err(usbpdata->dev, "Failed to get hsicphy_12m\n");
return;
}
- phyclk_otgphy1 = devm_clk_get(usbpdata->dev, "hsic_otgphy1");
- if (IS_ERR(phyclk_otgphy1)) {
- dev_err(usbpdata->dev, "Failed to get hsic_otgphy1\n");
+ phyclk_usbphy1 = devm_clk_get(usbpdata->dev, "hsic_usbphy1");
+ if (IS_ERR(phyclk_usbphy1)) {
+ dev_err(usbpdata->dev, "Failed to get hsic_usbphy1\n");
return;
}
return;
}
- clk_set_parent(phyclk480m_hsic, phyclk_otgphy1);
+ clk_set_parent(phyclk480m_hsic, phyclk_usbphy1);
usbpdata->hclk_hsic = ahbclk;
usbpdata->hsic_phy_480m = phyclk480m_hsic;
.clock_init = rk_hsic_clock_init,
.clock_enable = rk_hsic_clock_enable,
.soft_reset = rk_hsic_soft_reset,
- .get_chip_id = usb_get_chip_id,
};
#endif
-#ifdef CONFIG_RK_USB_DETECT_BY_OTG_BVALID
#define WAKE_LOCK_TIMEOUT (HZ * 10)
inline static void do_wakeup(struct work_struct *work)
{
// rk28_send_wakeup_key();
}
-#endif
/********** handler for bvalid irq **********/
static irqreturn_t bvalid_irq_handler(int irq, void *dev_id)
dwc_otg_uart_mode(NULL, PHY_USB_MODE);
#endif
-#ifdef CONFIG_RK_USB_DETECT_BY_OTG_BVALID
- wake_lock_timeout(&control_usb->usb_wakelock, WAKE_LOCK_TIMEOUT);
- schedule_delayed_work(&control_usb->usb_det_wakeup_work, HZ/10);
-#endif
+ if(control_usb->usb_irq_wakeup){
+ wake_lock_timeout(&control_usb->usb_wakelock, WAKE_LOCK_TIMEOUT);
+ schedule_delayed_work(&control_usb->usb_det_wakeup_work, HZ/10);
+ }
return IRQ_HANDLED;
}
int ret = 0;
int irq = 0;
-#ifdef CONFIG_RK_USB_DETECT_BY_OTG_BVALID
- wake_lock_init(&control_usb->usb_wakelock, WAKE_LOCK_SUSPEND, "usb_detect");
- INIT_DELAYED_WORK(&control_usb->usb_det_wakeup_work, do_wakeup);
-#endif
+ if(control_usb->usb_irq_wakeup){
+ wake_lock_init(&control_usb->usb_wakelock, WAKE_LOCK_SUSPEND, "usb_detect");
+ INIT_DELAYED_WORK(&control_usb->usb_det_wakeup_work, do_wakeup);
+ }
- irq = platform_get_irq_byname(pdev, "bvalid");
+ irq = platform_get_irq_byname(pdev, "otg_bvalid");
if (irq > 0) {
- ret = request_irq(irq, bvalid_irq_handler, 0, "bvalid", NULL);
+ ret = request_irq(irq, bvalid_irq_handler, 0, "otg_bvalid", NULL);
if(ret < 0){
dev_err(&pdev->dev, "request_irq %d failed!\n", irq);
return ret;
/* clear & enable bvalid irq */
control_usb->grf_uoc0_base->CON3 = (3 << 30) | (3 << 14);
-#ifdef CONFIG_RK_USB_DETECT_BY_OTG_BVALID
- enable_irq_wake(irq);
-#endif
+ if(control_usb->usb_irq_wakeup){
+ enable_irq_wake(irq);
+ }
}
return ret;
int ret = 0;
control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),GFP_KERNEL);
+
if (!control_usb) {
dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
ret = -ENOMEM;
}
control_usb->chip_id = RK3188_USB_CTLR;
+ control_usb->remote_wakeup = of_property_read_bool(np,
+ "rockchip,remote_wakeup");
+ control_usb->usb_irq_wakeup = of_property_read_bool(np,
+ "rockchip,usb_irq_wakeup");
hclk_usb_peri = devm_clk_get(&pdev->dev, "hclk_usb_peri");
if (IS_ERR(hclk_usb_peri)) {
goto err2;
}
+ /* init host gpio */
control_usb->host_gpios = devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL);
+ if(!control_usb->host_gpios){
+ dev_err(&pdev->dev, "unable to alloc memory for host_gpios\n");
+ ret = -ENOMEM;
+ goto err2;
+ }
gpio = of_get_named_gpio(np, "gpios", 0);
if(!gpio_is_valid(gpio)){
ret = -EINVAL;
goto err2;
}
+
control_usb->host_gpios->gpio = gpio;
+
err = devm_gpio_request(&pdev->dev, gpio, "host_drv_gpio");
if (err) {
dev_err(&pdev->dev,
ret = err;
goto err2;
}
+ gpio_direction_output(control_usb->host_gpios->gpio, 1);
+ /* init otg gpio */
control_usb->otg_gpios = devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL);
+ if(!control_usb->otg_gpios){
+ dev_err(&pdev->dev, "unable to alloc memory for otg_gpios\n");
+ ret = -ENOMEM;
+ goto err2;
+ }
gpio = of_get_named_gpio(np, "gpios", 1);
if(!gpio_is_valid(gpio)){
ret = err;
goto err2;
}
+ gpio_direction_output(control_usb->otg_gpios->gpio, 0);
ret = otg_irq_detect_init(pdev);
if (ret < 0)