Ejemplo n.º 1
0
int set_otg_notify(struct otg_notify *n)
{
	int ret = 0;

    pr_info("%s\n",__func__);
	if (!u_notify) {
		ret = create_usb_notify();
		if (ret) {
			pr_err("unable create_usb_notify\n");
			goto err;
		}
	}

	if (u_notify->o_notify && n) {
		pr_err("error : already set o_notify\n");
		goto err;
	}

	pr_info("registered otg_notify +\n");
	if (!n) {
		pr_err("otg notify structure is null\n");
		ret = -EFAULT;
		goto err1;
	}
	u_notify->o_notify = n;

	ATOMIC_INIT_NOTIFIER_HEAD(&u_notify->o_notify->otg_notifier);
	u_notify->otg_nb.notifier_call = otg_notifier_callback;
	ret = atomic_notifier_chain_register(&u_notify->o_notify->otg_notifier,
				&u_notify->otg_nb);
	if (ret < 0) {
		pr_err("atomic_notifier_chain_register failed\n");
		goto err1;
	}

	BLOCKING_INIT_NOTIFIER_HEAD(&u_notify->o_notify->extra_notifier);
	u_notify->extra_nb.notifier_call = extra_notifier_callback;
	ret = blocking_notifier_chain_register
		(&u_notify->o_notify->extra_notifier, &u_notify->extra_nb);
	if (ret < 0) {
		pr_err("blocking_notifier_chain_register failed\n");
		goto err2;
	}

	if (!n->unsupport_host) {
		u_notify->ndev.name = "usb_otg";
		u_notify->ndev.set_booster = n->vbus_drive;
		ret = host_notify_dev_register(&u_notify->ndev);
		if (ret < 0) {
			pr_err("host_notify_dev_register is failed\n");
			goto err3;
		}

		if (!n->vbus_drive) {
			pr_err("vbus_drive is null\n");
			goto err4;
		}
	}

	if (gpio_is_valid(n->vbus_detect_gpio) ||
			gpio_is_valid(n->redriver_en_gpio)) {
		ret = register_gpios(n);
		if (ret < 0) {
			pr_err("register_gpios is failed\n");
			goto err4;
		}
	}

	if (n->is_wakelock)
		wake_lock_init(&u_notify->wlock,
			WAKE_LOCK_SUSPEND, "usb_notify");

	if (n->booting_delay_sec) {
		INIT_DELAYED_WORK(&u_notify->b_delay.booting_work,
				  reserve_state_check);
		schedule_delayed_work(&u_notify->b_delay.booting_work,
				n->booting_delay_sec*HZ);
	}
	register_usbdev_notify();

	pr_info("registered otg_notify -\n");
	return 0;
err4:
	if (!n->unsupport_host)
		host_notify_dev_unregister(&u_notify->ndev);
err3:
	blocking_notifier_chain_unregister(&u_notify->o_notify->extra_notifier,
				&u_notify->extra_nb);
err2:
	atomic_notifier_chain_unregister(&u_notify->o_notify->otg_notifier,
				&u_notify->otg_nb);
err1:
	u_notify->o_notify = NULL;
err:
	return ret;
}
Ejemplo n.º 2
0
static int s5pc110_start_otg(u32 regs)
{
	int ret_val = 0;
	u32 reg_val = 0;
	struct platform_device *pdev = g_pdev;
	struct sec_otghost *otghost = NULL;
	struct sec_otghost_data *otg_data = dev_get_platdata(&pdev->dev);

	otg_dbg(OTG_DBG_OTGHCDI_DRIVER, "s3c_otg_drv_probe\n");
	pr_info("otg probe start : 0x%x\n", regs);


	/*init for host mode*/
	/**
	Allocate memory for the base HCD &	Initialize the base HCD.
	*/
	g_pUsbHcd = usb_create_hcd(&s5pc110_otg_hc_driver, &pdev->dev,
					"s3cotg");/*pdev->dev.bus_id*/
	if (g_pUsbHcd == NULL) {
		ret_val = -ENOMEM;
		otg_err(OTG_DBG_OTGHCDI_DRIVER,
			"failed to usb_create_hcd\n");
		goto err_out_clk;
	}

#if 1
	pr_info("otg probe regs : 0x%p\n", otg_data->regs);

	if (!regs) {
		pr_info("otg mapping hcd resource\n");
		/* mapping hcd resource & device resource*/

		g_pUsbHcd->rsrc_start = pdev->resource[0].start;
		g_pUsbHcd->rsrc_len   = pdev->resource[0].end -
			pdev->resource[0].start + 1;

		if (!request_mem_region(g_pUsbHcd->rsrc_start,
					g_pUsbHcd->rsrc_len, gHcdName)) {
			otg_err(OTG_DBG_OTGHCDI_DRIVER,
					"failed to request_mem_region\n");
			ret_val = -EBUSY;
			goto err_out_create_hcd;
		}

		pr_info("otg rsrc_start %llu, ren %llu\n",
				g_pUsbHcd->rsrc_start,
				g_pUsbHcd->rsrc_len);

		pr_info("otg regs : %p\n", S3C_VA_HSOTG);

		/* Physical address => Virtual address */
		g_pUsbHcd->regs = S3C_VA_HSOTG;
		g_pUDCBase = (u8 *)g_pUsbHcd->regs;

	} else
		g_pUDCBase = (u8 *)regs;
#endif
	pr_info("otg g_pUDCBase 0x%p\n", g_pUDCBase);

	g_pUsbHcd->self.otg_port = 1;

	otghost = hcd_to_sec_otghost(g_pUsbHcd);

	if (otghost == NULL) {
		otg_err(true, "failed to get otghost hcd\n");
		ret_val = USB_ERR_FAIL;
		goto err_out_create_hcd;
	}
	otghost->otg_data = otg_data;

	INIT_WORK(&otghost->work, otg_power_work);
	otghost->wq = create_singlethread_workqueue("sec_otghostd");

	/* call others' init() */
	ret_val = otg_hcd_init_modules(otghost);
	if (ret_val != USB_ERR_SUCCESS) {
		otg_err(OTG_DBG_OTGHCDI_DRIVER,
			"failed to otg_hcd_init_modules\n");
		ret_val = USB_ERR_FAIL;
		goto err_out_create_hcd;
	}

	/**
	 * Attempt to ensure this device is really a s5pc110 USB-OTG Controller.
	 * Read and verify the SNPSID register contents. The value should be
	 * 0x45F42XXX, which corresponds to "OT2", as in "OTG version 2.XX".
	 */
	reg_val = read_reg_32(0x40);
	pr_info("otg reg 0x40 = %x\n", reg_val);
	if ((reg_val & 0xFFFFF000) != 0x4F542000) {
		otg_err(OTG_DBG_OTGHCDI_DRIVER,
			"Bad value for SNPSID: 0x%x\n", reg_val);
		ret_val = -EINVAL;
		goto err_out_create_hcd_init;
	}
#ifdef CONFIG_USB_HOST_NOTIFY
	if (otg_data->host_notify) {
		g_pUsbHcd->host_notify = otg_data->host_notify;
		g_pUsbHcd->ndev.name = dev_name(&pdev->dev);
		ret_val = host_notify_dev_register(&g_pUsbHcd->ndev);
		if (ret_val) {
			otg_err(OTG_DBG_OTGHCDI_DRIVER,
				"Failed to host_notify_dev_register\n");
			goto err_out_create_hcd_init;
		}
	}
#endif
#ifdef CONFIG_USB_SEC_WHITELIST
	if (otg_data->sec_whlist_table_num)
		g_pUsbHcd->sec_whlist_table_num =
			otg_data->sec_whlist_table_num;
#endif

	/*
	 * Finish generic HCD initialization and start the HCD. This function
	 * allocates the DMA buffer pool, registers the USB bus, requests the
	 * IRQ line, and calls s5pc110_otghcd_start method.
	 */
	ret_val = usb_add_hcd(g_pUsbHcd,
			pdev->resource[1].start, IRQF_DISABLED);
	if (ret_val < 0) {
		otg_err(OTG_DBG_OTGHCDI_DRIVER,
			"Failed to add hcd driver\n");
		goto err_out_host_notify_register;
	}

	otg_dbg(OTG_DBG_OTGHCDI_DRIVER,
		"OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
		"C110 OTG Controller", g_pUsbHcd->self.busnum);

	/* otg_print_registers(); */

	wake_lock_init(&otghost->wake_lock, WAKE_LOCK_SUSPEND, "usb_otg");
	wake_lock(&otghost->wake_lock);

	return USB_ERR_SUCCESS;

err_out_host_notify_register:
#ifdef CONFIG_USB_HOST_NOTIFY
	host_notify_dev_unregister(&g_pUsbHcd->ndev);
#endif

err_out_create_hcd_init:
	otg_hcd_deinit_modules(otghost);
	if (!regs)
		release_mem_region(g_pUsbHcd->rsrc_start, g_pUsbHcd->rsrc_len);

err_out_create_hcd:
	usb_put_hcd(g_pUsbHcd);

err_out_clk:

	return ret_val;
}