aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Jun <B47624@freescale.com>2013-12-31 08:36:51 -0500
committerNitin Garg <nitin.garg@freescale.com>2014-04-16 12:02:32 -0400
commit3767c8168a3dee9032b9e77c6a12e919e0a7a514 (patch)
tree1b9b47e42549c1cd08922c2f80661bc21770ef84
parentfc47c6565c363633165e9099f5a985c74e0dc3b0 (diff)
ENGR00307558-1 usb: chipidea: usb OTG fsm initialization.
This patch adds OTG fsm related initialization when do otg init, add a seperate file for OTG fsm related utilities. Signed-off-by: Li Jun <b47624@freescale.com>
-rw-r--r--drivers/usb/chipidea/Makefile1
-rw-r--r--drivers/usb/chipidea/ci.h17
-rw-r--r--drivers/usb/chipidea/otg.c4
-rw-r--r--drivers/usb/chipidea/otg_fsm.c65
-rw-r--r--drivers/usb/chipidea/otg_fsm.h29
5 files changed, 116 insertions, 0 deletions
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index 7345d2115af2..5e1ecc51603f 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -6,6 +6,7 @@ ci_hdrc-y := core.o otg.o
6ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o 6ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o
7ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o 7ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o
8ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o 8ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o
9ci_hdrc-$(CONFIG_USB_OTG_FSM) += otg_fsm.o
9 10
10# Glue/Bridge layers go here 11# Glue/Bridge layers go here
11 12
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index 30f13b414ecf..2120e6dc1ef7 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -17,6 +17,7 @@
17#include <linux/irqreturn.h> 17#include <linux/irqreturn.h>
18#include <linux/usb.h> 18#include <linux/usb.h>
19#include <linux/usb/gadget.h> 19#include <linux/usb/gadget.h>
20#include <linux/usb/otg-fsm.h>
20 21
21/****************************************************************************** 22/******************************************************************************
22 * DEFINE 23 * DEFINE
@@ -110,6 +111,7 @@ struct hw_bank {
110 * @roles: array of supported roles for this controller 111 * @roles: array of supported roles for this controller
111 * @role: current role 112 * @role: current role
112 * @is_otg: if the device is otg-capable 113 * @is_otg: if the device is otg-capable
114 * @fsm: otg finite state machine
113 * @work: work for role changing 115 * @work: work for role changing
114 * @wq: workqueue thread 116 * @wq: workqueue thread
115 * @qh_pool: allocation pool for queue heads 117 * @qh_pool: allocation pool for queue heads
@@ -149,6 +151,7 @@ struct ci_hdrc {
149 struct ci_role_driver *roles[CI_ROLE_END]; 151 struct ci_role_driver *roles[CI_ROLE_END];
150 enum ci_role role; 152 enum ci_role role;
151 bool is_otg; 153 bool is_otg;
154 struct otg_fsm fsm;
152 struct work_struct work; 155 struct work_struct work;
153 struct workqueue_struct *wq; 156 struct workqueue_struct *wq;
154 157
@@ -331,6 +334,20 @@ static inline u32 hw_test_and_write(struct ci_hdrc *ci, enum ci_hw_regs reg,
331 return (val & mask) >> __ffs(mask); 334 return (val & mask) >> __ffs(mask);
332} 335}
333 336
337/**
338 * ci_otg_is_fsm_mode: runtime check if otg controller
339 * is in otg fsm mode.
340 */
341static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci)
342{
343#ifdef CONFIG_USB_OTG_FSM
344 return ci->is_otg && ci->roles[CI_ROLE_HOST] &&
345 ci->roles[CI_ROLE_GADGET];
346#else
347 return false;
348#endif
349}
350
334u32 hw_read_intr_enable(struct ci_hdrc *ci); 351u32 hw_read_intr_enable(struct ci_hdrc *ci);
335 352
336u32 hw_read_intr_status(struct ci_hdrc *ci); 353u32 hw_read_intr_status(struct ci_hdrc *ci);
diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
index 31cc81bb7806..dc7ad4096385 100644
--- a/drivers/usb/chipidea/otg.c
+++ b/drivers/usb/chipidea/otg.c
@@ -23,6 +23,7 @@
23#include "ci.h" 23#include "ci.h"
24#include "bits.h" 24#include "bits.h"
25#include "otg.h" 25#include "otg.h"
26#include "otg_fsm.h"
26 27
27/** 28/**
28 * hw_read_otgsc returns otgsc register bits value. 29 * hw_read_otgsc returns otgsc register bits value.
@@ -150,6 +151,9 @@ int ci_hdrc_otg_init(struct ci_hdrc *ci)
150 return -ENODEV; 151 return -ENODEV;
151 } 152 }
152 153
154 if (ci_otg_is_fsm_mode(ci))
155 return ci_hdrc_otg_fsm_init(ci);
156
153 return 0; 157 return 0;
154} 158}
155 159
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
new file mode 100644
index 000000000000..f4bb7c83b708
--- /dev/null
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -0,0 +1,65 @@
1/*
2 * otg_fsm.c - ChipIdea USB IP core OTG FSM driver
3 *
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
5 *
6 * Author: Jun Li
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13/*
14 * This file mainly handles OTG fsm, it includes OTG fsm operations
15 * for HNP and SRP.
16 */
17
18#include <linux/usb/otg.h>
19#include <linux/usb/gadget.h>
20#include <linux/usb/hcd.h>
21#include <linux/usb/chipidea.h>
22
23#include "ci.h"
24#include "bits.h"
25#include "otg.h"
26#include "otg_fsm.h"
27
28int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
29{
30 struct usb_otg *otg;
31
32 otg = devm_kzalloc(ci->dev,
33 sizeof(struct usb_otg), GFP_KERNEL);
34 if (!otg) {
35 dev_err(ci->dev,
36 "Failed to allocate usb_otg structure for ci hdrc otg!\n");
37 return -ENOMEM;
38 }
39
40 otg->phy = ci->transceiver;
41 otg->gadget = &ci->gadget;
42 if (ci->hcd)
43 otg->host = &ci->hcd->self;
44 ci->fsm.otg = otg;
45 ci->transceiver->otg = ci->fsm.otg;
46 ci->fsm.power_up = 1;
47 ci->fsm.id = hw_read_otgsc(ci, OTGSC_ID) ? 1 : 0;
48 ci->transceiver->state = OTG_STATE_UNDEFINED;
49
50 mutex_init(&ci->fsm.lock);
51
52 /* Enable A vbus valid irq */
53 hw_write_otgsc(ci, OTGSC_AVVIE, OTGSC_AVVIE);
54
55 if (ci->fsm.id) {
56 ci->fsm.b_ssend_srp =
57 hw_read_otgsc(ci, OTGSC_BSV) ? 0 : 1;
58 ci->fsm.b_sess_vld =
59 hw_read_otgsc(ci, OTGSC_BSV) ? 1 : 0;
60 /* Enable BSV irq */
61 hw_write_otgsc(ci, OTGSC_BSVIE, OTGSC_BSVIE);
62 }
63
64 return 0;
65}
diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h
new file mode 100644
index 000000000000..bf20a851b601
--- /dev/null
+++ b/drivers/usb/chipidea/otg_fsm.h
@@ -0,0 +1,29 @@
1/*
2 * Copyright (C) 2014 Freescale Semiconductor, Inc.
3 *
4 * Author: Jun Li
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef __DRIVERS_USB_CHIPIDEA_OTG_FSM_H
12#define __DRIVERS_USB_CHIPIDEA_OTG_FSM_H
13
14#include <linux/usb/otg-fsm.h>
15
16#ifdef CONFIG_USB_OTG_FSM
17
18int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci);
19
20#else
21
22static inline int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
23{
24 return 0;
25}
26
27#endif
28
29#endif /* __DRIVERS_USB_CHIPIDEA_OTG_FSM_H */