LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 09-27-2017, 05:23 AM   #1
shafin.vahora
LQ Newbie
 
Registered: Sep 2017
Posts: 11

Rep: Reputation: Disabled
Linux usb Gadget driver for Arria 10 SOC


Hi,

I am working with linux usbgadget driver for Arria 10 soc device. I have developed it for uClinux distribution successfully, and now working with angstrom distribution with kernel 4.1.33.

I am facing issue of not registering gadget i.e. after successfully probed udc_start callback function is not calling by udc class driver. Another issue is not read/write any register on device address.

Please help if anyone has worked for SOC device.

Regards,
Shafin Vahora
Jr. Software Engineer,
System Level Solutions(India) Pvt. Ltd
 
Old 09-27-2017, 11:39 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by shafin.vahora View Post
Hi,
I am working with linux usbgadget driver for Arria 10 soc device. I have developed it for uClinux distribution successfully, and now working with angstrom distribution with kernel 4.1.33.

I am facing issue of not registering gadget i.e. after successfully probed udc_start callback function is not calling by udc class driver. Another issue is not read/write any register on device address. Please help if anyone has worked for SOC device.
We can try to help, but without seeing your code, what do you think we'll be able to tell you, based on what you posted? And it seems very odd that you developed this kernel module, programmed it, and got it working...but now cannot debug/modify that same code.
 
Old 09-27-2017, 11:18 PM   #3
shafin.vahora
LQ Newbie
 
Registered: Sep 2017
Posts: 11

Original Poster
Rep: Reputation: Disabled
here is my driver probe function code. probe gets successful but no udc_start is invoking. Even i am not able to write in custom ip core register.

Code:
DBG(DBG_FUNC, "usbs_udc_probe()\n");
	dev_info(&pdev->dev,"Entering in to usbs_udc_probe()\n");
	
  	struct usbs_platform_data *pdata = (struct usbs_platform_data *)pdev->dev.platform_data;
  	struct resource *regs, *res;
  	const struct of_device_id *match;
  	struct usbs_udc *udc;
  	//struct usbs_udc *udc = &the_udc;
  	int usb31sf_irq = -1, ret, i, dev_ctrl, val;
  	const char *name;	

  	struct device_node *np = pdev->dev.of_node;
///  	struct device_node *pp;

 
 	udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
	if (!udc)
		return -ENOMEM;
 
    regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);	
  	if((!regs))
  		return -ENXIO;
    	
	printk("regs->start: %x\t\tregs->end: %x\t\tSize_of_Res: %x\n",regs->start, regs->end, resource_size(regs));
 
 	udc->regs = devm_ioremap_resource(&pdev->dev, regs);
	if(IS_ERR(udc->regs))
	{
  		dev_err(&pdev->dev, "Unable to map I/O memory, aborting..\n");
  		goto err_map_regs;
  	}
  	
  	//printk("USBS_MAIN_INT_MASK: %x\tUSBS_DEVICE_CTRL: %x\n", USBS_MAIN_INT_MASK, USBS_DEVICE_CTRL);
 
	usbs_writel(udc, DEV_SCRATCH_REG, 0x5);       								//scratch reg
	printk("Scratch Reg:	%x\n",usbs_readl(udc, DEV_SCRATCH_REG));


	usbs_writel(udc, MAIN_INT_MASK, DEV_INT_EN);       //usbs_writel(udc, INT_MSK, USB_DETACH_MASK);		dev_int_en
	printk("Dev_int_en:	%x\n",usbs_readl(udc, MAIN_INT_MASK));
 
 	usb31sf_irq = platform_get_irq(pdev, 0);
	printk("IRQ: %x\n", usb31sf_irq);
	
	if(usb31sf_irq < 0)
	{
		dev_err(&pdev->dev, "IRQ number of USB30SR is invalid, aborting..\n");
  		return usb31sf_irq;
	}
 
 	ret = devm_request_irq(&pdev->dev, usb31sf_irq, usbs_udc_irq, 0, "sls_usbs_udc31", udc);
	
	printk("Req_irq: %x\n", ret);
  	if(ret)	
  	{//printk("1\n");
  		dev_err(&pdev->dev, "Cannot request USB irq %d (error %d)\n", usb31sf_irq, ret);
  		goto err_request_irq;
  	}	
  	udc->usb31sf_irq = usb31sf_irq;
 
	udc->gadget.ops = &usbs_udc_ops;
	udc->gadget.max_speed = USB_SPEED_SUPER;
	udc->gadget.speed = USB_SPEED_UNKNOWN;
	udc->gadget.name = driver_name;

	spin_lock_init(&udc->lock);
 
	// write ep info logic
	
	ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
	//printk("7\n");
	if(ret)	
	{//printk("8\n");
		dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
		goto err_device_add;
	}	
	
	dev_ctrl = usbs_readl(udc, DEVICE_CTRL);
	dev_ctrl = (dev_ctrl | 0x2);							//HS capable and connect bit 0
	dev_ctrl = dev_ctrl & 0xFFFFFFFE;
	printk("Dev_ctrl1:	%x\n",dev_ctrl);
	
	dev_ctrl = (dev_ctrl | 0xF);							//All capability and connect bit 1
	usbs_writel(udc, DEVICE_CTRL, dev_ctrl);
	printk("Dev_ctrl2:	%x\n",dev_ctrl);
	
	printk("Dev_int_src: %x\n",usbs_readl(udc, MAIN_INT_REG));
	
	udc->dev = &udc->gadget.dev;

	platform_set_drvdata(pdev, udc);

Last edited by onebuck; 09-29-2017 at 08:50 AM. Reason: [mod edit] clean up post with code tags since OP fails to use tags to clerify
 
Old 09-28-2017, 08:03 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by shafin.vahora View Post
here is my driver probe function code. probe gets successful but no udc_start is invoking. Even i am not able to write in custom ip core register.
Code:
DBG(DBG_FUNC, "usbs_udc_probe()\n");
	dev_info(&pdev->dev,"Entering in to usbs_udc_probe()\n");
	
  	struct usbs_platform_data *pdata = (struct usbs_platform_data *)pdev->dev.platform_data;
  	struct resource *regs, *res;
  	const struct of_device_id *match;
  	struct usbs_udc *udc;
  	//struct usbs_udc *udc = &the_udc;
  	int usb31sf_irq = -1, ret, i, dev_ctrl, val;
  	const char *name;	

  	struct device_node *np = pdev->dev.of_node;
///  	struct device_node *pp;

 
 	udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
	if (!udc)
		return -ENOMEM;
 
    regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);	
  	if((!regs))
  		return -ENXIO;
    	
	printk("regs->start: %x\t\tregs->end: %x\t\tSize_of_Res: %x\n",regs->start, regs->end, resource_size(regs));
 
 	udc->regs = devm_ioremap_resource(&pdev->dev, regs);
	if(IS_ERR(udc->regs))
	{
  		dev_err(&pdev->dev, "Unable to map I/O memory, aborting..\n");
  		goto err_map_regs;
  	}
  	
  	//printk("USBS_MAIN_INT_MASK: %x\tUSBS_DEVICE_CTRL: %x\n", USBS_MAIN_INT_MASK, USBS_DEVICE_CTRL);
 
	usbs_writel(udc, DEV_SCRATCH_REG, 0x5);       								//scratch reg
	printk("Scratch Reg:	%x\n",usbs_readl(udc, DEV_SCRATCH_REG));


	usbs_writel(udc, MAIN_INT_MASK, DEV_INT_EN);       //usbs_writel(udc, INT_MSK, USB_DETACH_MASK);		dev_int_en
	printk("Dev_int_en:	%x\n",usbs_readl(udc, MAIN_INT_MASK));
 
 	usb31sf_irq = platform_get_irq(pdev, 0);
	printk("IRQ: %x\n", usb31sf_irq);
	
	if(usb31sf_irq < 0)
	{
		dev_err(&pdev->dev, "IRQ number of USB30SR is invalid, aborting..\n");
  		return usb31sf_irq;
	}
 
 	ret = devm_request_irq(&pdev->dev, usb31sf_irq, usbs_udc_irq, 0, "sls_usbs_udc31", udc);
	
	printk("Req_irq: %x\n", ret);
  	if(ret)	
  	{//printk("1\n");
  		dev_err(&pdev->dev, "Cannot request USB irq %d (error %d)\n", usb31sf_irq, ret);
  		goto err_request_irq;
  	}	
  	udc->usb31sf_irq = usb31sf_irq;
 
	udc->gadget.ops = &usbs_udc_ops;
	udc->gadget.max_speed = USB_SPEED_SUPER;
	udc->gadget.speed = USB_SPEED_UNKNOWN;
	udc->gadget.name = driver_name;

	spin_lock_init(&udc->lock);
 
	// write ep info logic
	
	ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
	//printk("7\n");
	if(ret)	
	{//printk("8\n");
		dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
		goto err_device_add;
	}	
	
	dev_ctrl = usbs_readl(udc, DEVICE_CTRL);
	dev_ctrl = (dev_ctrl | 0x2);							//HS capable and connect bit 0
	dev_ctrl = dev_ctrl & 0xFFFFFFFE;
	printk("Dev_ctrl1:	%x\n",dev_ctrl);
	
	dev_ctrl = (dev_ctrl | 0xF);							//All capability and connect bit 1
	usbs_writel(udc, DEVICE_CTRL, dev_ctrl);
	printk("Dev_ctrl2:	%x\n",dev_ctrl);
	
	printk("Dev_int_src: %x\n",usbs_readl(udc, MAIN_INT_REG));
	
	udc->dev = &udc->gadget.dev;

	platform_set_drvdata(pdev, udc);
Read the LQ Rules and "Question Guidelines"...post your code in CODE tags to make it easy to read. There are barely any comments in any of this to let anyone know what it's doing...can you elaborate? Post the message(s)/error(s) you're getting from the command line when you try to run it?

And again...if YOU are the one who wrote this code for the original device/hardware, it seems VERY ODD that you are totally unable to debug it or make changes to it.
 
Old 09-28-2017, 11:46 PM   #5
shafin.vahora
LQ Newbie
 
Registered: Sep 2017
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Read the LQ Rules and "Question Guidelines"...post your code in CODE tags to make it easy to read. There are barely any comments in any of this to let anyone know what it's doing...can you elaborate? Post the message(s)/error(s) you're getting from the command line when you try to run it?

And again...if YOU are the one who wrote this code for the original device/hardware, it seems VERY ODD that you are totally unable to debug it or make changes to it.
Hi,

Above code is just a simple driver probe function. Output of above code for my usb device controller driver is as below.

//////////////////////////// O/P Message ////////////////////////////////
1.902857] udc: usbs_udc_probe()
[ 1.906160] sls_usbs_udc31 ff200000.serial: Entering in to usbs_udc_probe()
[ 1.913100] regs->start: ff200000 regs->end: ff200fff Size_of_Res: 1000
[ 1.919869] Scratch Reg: 0
[ 1.922568] Dev_int_en: 0
[ 1.925185] IRQ: 12
[ 1.927299] Req_irq: 0
[ 1.929777] Dev_ctrl1: 2
[ 1.932307] Dev_ctrl2: f
[ 1.934826] Dev_int_src: 0
[ 1.937518] udc: usbs_udc_probe() success
/////////////////////////////////////////////////////////////////////////

Now my question is after successful probing of a driver udc class driver invokes udc_start callback function to register gadget to udc. Here, scratch register value shows zero means i am not able to write for a given base address (regs->start: ff200000). This device start address information is getting from socfpga_arria10.dtsi file.

Please help, if any one has developed for Arria 10 soc device.
 
Old 09-29-2017, 07:38 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by shafin.vahora View Post
Hi,
Above code is just a simple driver probe function. Output of above code for my usb device controller driver is as below.
Code:
//////////////////////////// O/P Message ////////////////////////////////
1.902857] udc: usbs_udc_probe()
[    1.906160] sls_usbs_udc31 ff200000.serial: Entering in to usbs_udc_probe()
[    1.913100] regs->start: ff200000            regs->end: ff200fff             Size_of_Res: 1000
[    1.919869] Scratch Reg:     0
[    1.922568] Dev_int_en:      0
[    1.925185] IRQ: 12
[    1.927299] Req_irq: 0
[    1.929777] Dev_ctrl1:       2
[    1.932307] Dev_ctrl2:       f
[    1.934826] Dev_int_src: 0
[    1.937518] udc: usbs_udc_probe() success
/////////////////////////////////////////////////////////////////////////
Now my question is after successful probing of a driver udc class driver invokes udc_start callback function to register gadget to udc. Here, scratch register value shows zero means i am not able to write for a given base address (regs->start: ff200000). This device start address information is getting from socfpga_arria10.dtsi file.
AGAIN, you need to post code in CODE tags. And unless you answer questions, there is not much point in posting. You were told that your code had no comments, so (aside from someone here debugging it for you, which probably isn't ever going to happen), we have no idea on how it works. You now mention it's getting info from some other file (which you didn't mention before now), and also do not post details of IT either.

And AGAIN...you said that YOU wrote this code, so AGAIN...WHY CAN YOU NOT DEBUG YOUR OWN CODE????
 
Old 10-02-2017, 12:27 AM   #7
shafin.vahora
LQ Newbie
 
Registered: Sep 2017
Posts: 11

Original Poster
Rep: Reputation: Disabled
Arria 10 soc linux gadget driver udc_start issue

Quote:
Originally Posted by TB0ne View Post
AGAIN, you need to post code in CODE tags. And unless you answer questions, there is not much point in posting. You were told that your code had no comments, so (aside from someone here debugging it for you, which probably isn't ever going to happen), we have no idea on how it works. You now mention it's getting info from some other file (which you didn't mention before now), and also do not post details of IT either.

And AGAIN...you said that YOU wrote this code, so AGAIN...WHY CAN YOU NOT DEBUG YOUR OWN CODE????

Quote:
Here is my probe function code. After successful probe completion, no udc_start callback function is invoking.

Code:
static int usbs_udc_probe(struct platform_device *pdev)
{
	DBG(DBG_FUNC, "usbs_udc_probe()\n");
	dev_info(&pdev->dev,"Entering in to usbs_udc_probe()\n");
	
  	struct usbs_platform_data *pdata = (struct usbs_platform_data *)pdev->dev.platform_data;
  	struct resource *regs, *res;
  	const struct of_device_id *match;
  	struct usbs_udc *udc;
  
  	int usb31sf_irq = -1, ret, i, dev_ctrl, val;
  	const char *name;	

  	struct device_node *np = pdev->dev.of_node;
///  	struct device_node *pp;

 
 	udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
	if (!udc)
		return -ENOMEM;
 
    regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);	
  	if((!regs))
  		return -ENXIO;
    	
 	udc->regs = devm_ioremap_resource(&pdev->dev, regs);
	if(IS_ERR(udc->regs))
	{
  		dev_err(&pdev->dev, "Unable to map I/O memory, aborting..\n");
  		goto err_map_regs;
  	}
  	 
	usbs_writel(udc, DEV_SCRATCH_REG, 0x5);       								//scratch reg
	printk("Scratch Reg:	%x\n",usbs_readl(udc, DEV_SCRATCH_REG));


	usbs_writel(udc, MAIN_INT_MASK, DEV_INT_EN);       //usbs_writel(udc, INT_MSK, USB_DETACH_MASK);		dev_int_en
	printk("Dev_int_en:	%x\n",usbs_readl(udc, MAIN_INT_MASK));
 
 	usb31sf_irq = platform_get_irq(pdev, 0);
	
	if(usb31sf_irq < 0)
	{
		dev_err(&pdev->dev, "IRQ number of USB30SR is invalid, aborting..\n");
  		return usb31sf_irq;
	}
 
 	ret = devm_request_irq(&pdev->dev, usb31sf_irq, usbs_udc_irq, 0, "sls_usbs_udc31", udc);
	
  	if(ret)	
  	{
  		dev_err(&pdev->dev, "Cannot request USB irq %d (error %d)\n", usb31sf_irq, ret);
  		goto err_request_irq;
  	}	
  	udc->usb31sf_irq = usb31sf_irq;
 
	udc->gadget.ops = &usbs_udc_ops;
	udc->gadget.max_speed = USB_SPEED_SUPER;
	udc->gadget.speed = USB_SPEED_UNKNOWN;
	udc->gadget.name = driver_name;

	spin_lock_init(&udc->lock);
 
	
	ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
	
	if(ret)	
	{
		dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
		goto err_device_add;
	}	
	
	dev_ctrl = usbs_readl(udc, DEVICE_CTRL);
	dev_ctrl = (dev_ctrl | 0x2);							
	dev_ctrl = dev_ctrl & 0xFFFFFFFE;
	printk("Dev_ctrl1:	%x\n",dev_ctrl);
	
	dev_ctrl = (dev_ctrl | 0xF);							
	usbs_writel(udc, DEVICE_CTRL, dev_ctrl);
	
			
	udc->dev = &udc->gadget.dev;

	platform_set_drvdata(pdev, udc);
	
  	return 0;

	err_device_add:
		free_irq(usb31sf_irq, udc);
		//free_irq(usb20sr_irq, udc);
		
	err_request_irq:
		kfree(usbs_ep);
		
	err_alloc_ep:
		DBG(DBG_ERR, "Memory allocation failed for endpoints\n");
		
	err_map_regs:
		iounmap(udc->regs);
		//iounmap(udc->regs_u20);

	platform_set_drvdata(pdev, NULL);

	return ret;
}

Quote:
Here, i saw output of above probe function
Output:
1.902857] udc: usbs_udc_probe()
[ 1.906160] sls_usbs_udc31 ff200000.serial: Entering in to usbs_udc_probe()
[ 1.913100] regs->start: ff200000 regs->end: ff200fff Size_of_Res: 1000
[ 1.919869] Scratch Reg: 0
[ 1.922568] Dev_int_en: 0
[ 1.925185] IRQ: 12
[ 1.927299] Req_irq: 0
[ 1.929777] Dev_ctrl1: 2
[ 1.932307] Dev_ctrl2: f
[ 1.934826] Dev_int_src: 0
[ 1.937518] udc: usbs_udc_probe() success
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: ARM/FPGA module runs Debian on Arria 10 SoC LXer Syndicated Linux News 0 03-12-2017 09:17 PM
LXer: ARM/FPGA module runs Linux on Arria 10 SoC LXer Syndicated Linux News 0 10-25-2016 06:34 AM
[gadget driver] HOST turns unresponsive to gadget driver niroop Linux - Embedded & Single-board computer 4 04-22-2015 08:30 AM
set feature halt endpoint fails always USB linux driver usb gadget serial dot c sarmads1 Linux - Kernel 0 08-14-2012 10:06 PM
Linux usb gadget HID driver problem Sebteams69 Linux - Newbie 7 06-12-2012 02:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 02:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration