3737#include <linux/err.h>
3838#include <linux/delay.h>
3939#include <linux/usb/musb-omap.h>
40+ #include <linux/usb/omap_control_usb.h>
4041
4142#include "musb_core.h"
4243#include "omap2430.h"
@@ -46,34 +47,14 @@ struct omap2430_glue {
4647 struct platform_device * musb ;
4748 enum omap_musb_vbus_id_status status ;
4849 struct work_struct omap_musb_mailbox_work ;
49- u32 __iomem * control_otghs ;
50+ struct device * control_otghs ;
5051};
5152#define glue_to_musb (g ) platform_get_drvdata(g->musb)
5253
5354struct omap2430_glue * _glue ;
5455
5556static struct timer_list musb_idle_timer ;
5657
57- /**
58- * omap4_usb_phy_mailbox - write to usb otg mailbox
59- * @glue: struct omap2430_glue *
60- * @val: the value to be written to the mailbox
61- *
62- * On detection of a device (ID pin is grounded), this API should be called
63- * to set AVALID, VBUSVALID and ID pin is grounded.
64- *
65- * When OMAP is connected to a host (OMAP in device mode), this API
66- * is called to set AVALID, VBUSVALID and ID pin in high impedance.
67- *
68- * XXX: This function will be removed once we have a seperate driver for
69- * control module
70- */
71- static void omap4_usb_phy_mailbox (struct omap2430_glue * glue , u32 val )
72- {
73- if (glue -> control_otghs )
74- writel (val , glue -> control_otghs );
75- }
76-
7758static void musb_do_idle (unsigned long _musb )
7859{
7960 struct musb * musb = (void * )_musb ;
@@ -269,7 +250,6 @@ EXPORT_SYMBOL_GPL(omap_musb_mailbox);
269250
270251static void omap_musb_set_mailbox (struct omap2430_glue * glue )
271252{
272- u32 val ;
273253 struct musb * musb = glue_to_musb (glue );
274254 struct device * dev = musb -> controller ;
275255 struct musb_hdrc_platform_data * pdata = dev -> platform_data ;
@@ -285,8 +265,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
285265 musb -> xceiv -> last_event = USB_EVENT_ID ;
286266 if (musb -> gadget_driver ) {
287267 pm_runtime_get_sync (dev );
288- val = AVALID | VBUSVALID ;
289- omap4_usb_phy_mailbox ( glue , val );
268+ omap_control_usb_set_mode ( glue -> control_otghs ,
269+ USB_MODE_HOST );
290270 omap2430_musb_set_vbus (musb , 1 );
291271 }
292272 break ;
@@ -299,8 +279,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
299279 musb -> xceiv -> last_event = USB_EVENT_VBUS ;
300280 if (musb -> gadget_driver )
301281 pm_runtime_get_sync (dev );
302- val = IDDIG | AVALID | VBUSVALID ;
303- omap4_usb_phy_mailbox (glue , val );
282+ omap_control_usb_set_mode (glue -> control_otghs , USB_MODE_DEVICE );
304283 break ;
305284
306285 case OMAP_MUSB_ID_FLOAT :
@@ -317,8 +296,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
317296 if (musb -> xceiv -> otg -> set_vbus )
318297 otg_set_vbus (musb -> xceiv -> otg , 0 );
319298 }
320- val = SESSEND | IDDIG ;
321- omap4_usb_phy_mailbox ( glue , val );
299+ omap_control_usb_set_mode ( glue -> control_otghs ,
300+ USB_MODE_DISCONNECT );
322301 break ;
323302 default :
324303 dev_dbg (dev , "ID float\n" );
@@ -415,7 +394,6 @@ static int omap2430_musb_init(struct musb *musb)
415394static void omap2430_musb_enable (struct musb * musb )
416395{
417396 u8 devctl ;
418- u32 val ;
419397 unsigned long timeout = jiffies + msecs_to_jiffies (1000 );
420398 struct device * dev = musb -> controller ;
421399 struct omap2430_glue * glue = dev_get_drvdata (dev -> parent );
@@ -425,8 +403,7 @@ static void omap2430_musb_enable(struct musb *musb)
425403 switch (glue -> status ) {
426404
427405 case OMAP_MUSB_ID_GROUND :
428- val = AVALID | VBUSVALID ;
429- omap4_usb_phy_mailbox (glue , val );
406+ omap_control_usb_set_mode (glue -> control_otghs , USB_MODE_HOST );
430407 if (data -> interface_type != MUSB_INTERFACE_UTMI )
431408 break ;
432409 devctl = musb_readb (musb -> mregs , MUSB_DEVCTL );
@@ -445,8 +422,7 @@ static void omap2430_musb_enable(struct musb *musb)
445422 break ;
446423
447424 case OMAP_MUSB_VBUS_VALID :
448- val = IDDIG | AVALID | VBUSVALID ;
449- omap4_usb_phy_mailbox (glue , val );
425+ omap_control_usb_set_mode (glue -> control_otghs , USB_MODE_DEVICE );
450426 break ;
451427
452428 default :
@@ -456,14 +432,12 @@ static void omap2430_musb_enable(struct musb *musb)
456432
457433static void omap2430_musb_disable (struct musb * musb )
458434{
459- u32 val ;
460435 struct device * dev = musb -> controller ;
461436 struct omap2430_glue * glue = dev_get_drvdata (dev -> parent );
462437
463- if (glue -> status != OMAP_MUSB_UNKNOWN ) {
464- val = SESSEND | IDDIG ;
465- omap4_usb_phy_mailbox (glue , val );
466- }
438+ if (glue -> status != OMAP_MUSB_UNKNOWN )
439+ omap_control_usb_set_mode (glue -> control_otghs ,
440+ USB_MODE_DISCONNECT );
467441}
468442
469443static int omap2430_musb_exit (struct musb * musb )
@@ -498,7 +472,6 @@ static int omap2430_probe(struct platform_device *pdev)
498472 struct omap2430_glue * glue ;
499473 struct device_node * np = pdev -> dev .of_node ;
500474 struct musb_hdrc_config * config ;
501- struct resource * res ;
502475 int ret = - ENOMEM ;
503476
504477 glue = devm_kzalloc (& pdev -> dev , sizeof (* glue ), GFP_KERNEL );
@@ -521,12 +494,6 @@ static int omap2430_probe(struct platform_device *pdev)
521494 glue -> musb = musb ;
522495 glue -> status = OMAP_MUSB_UNKNOWN ;
523496
524- res = platform_get_resource (pdev , IORESOURCE_MEM , 1 );
525-
526- glue -> control_otghs = devm_request_and_ioremap (& pdev -> dev , res );
527- if (glue -> control_otghs == NULL )
528- dev_dbg (& pdev -> dev , "Failed to obtain control memory\n" );
529-
530497 if (np ) {
531498 pdata = devm_kzalloc (& pdev -> dev , sizeof (* pdata ), GFP_KERNEL );
532499 if (!pdata ) {
@@ -558,11 +525,22 @@ static int omap2430_probe(struct platform_device *pdev)
558525 of_property_read_u32 (np , "ram_bits" , (u32 * )& config -> ram_bits );
559526 of_property_read_u32 (np , "power" , (u32 * )& pdata -> power );
560527 config -> multipoint = of_property_read_bool (np , "multipoint" );
528+ pdata -> has_mailbox = of_property_read_bool (np ,
529+ "ti,has-mailbox" );
561530
562531 pdata -> board_data = data ;
563532 pdata -> config = config ;
564533 }
565534
535+ if (pdata -> has_mailbox ) {
536+ glue -> control_otghs = omap_get_control_dev ();
537+ if (IS_ERR (glue -> control_otghs )) {
538+ dev_vdbg (& pdev -> dev , "Failed to get control device\n" );
539+ return - ENODEV ;
540+ }
541+ } else {
542+ glue -> control_otghs = ERR_PTR (- ENODEV );
543+ }
566544 pdata -> platform_ops = & omap2430_ops ;
567545
568546 platform_set_drvdata (pdev , glue );
0 commit comments