{"id":8332,"date":"2022-03-11T08:54:01","date_gmt":"2022-03-11T08:54:01","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=8332"},"modified":"2023-08-12T15:44:45","modified_gmt":"2023-08-12T10:14:45","slug":"pcd-driver-with-multiple-devices-code-implementation-part-3","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/","title":{"rendered":"Linux Device Driver Programming Lecture 51- Pcd driver with multiple devices code implementation part-3"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; line-height: 50px;\"><span style=\"color: #000080;\"><strong>Pcd driver with multiple devices code implementation part-3<\/strong><\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">In this article, let&#8217;s implement the pcd_driver_init function. Let&#8217;s shift <\/span><b>#if 0<\/b><span style=\"font-weight: 400;\"> to somewhere below.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">First of all, we have to dynamically allocate device_numbers. We are going to use the alloc_chrdev region. Here, this device number you have to get from the driver&#8217;s data structure. This would be pcdrv_data. Its address you have to give &amp;pcdrv_data.device_number. And this is a first minor. First minor we can start from 0 and next is NO_OF_DEVICES.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, now we have four devices. That&#8217;s why we want four device_numbers whose base is stored in this device_number variable.<\/span><\/p>\n<figure id=\"attachment_8335\" aria-describedby=\"caption-attachment-8335\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-8335\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-1-23.png\" alt=\"Figure 1. Dynamically allovate the device number for 4 devices\" width=\"660\" height=\"372\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23.png 660w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23-300x169.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23-600x338.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23-120x68.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23-500x282.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23-200x113.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23-400x225.png 400w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><figcaption id=\"caption-attachment-8335\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Dynamically allocate the device number for 4 devices<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The alloc_chrdev_region now actually allocates device_numbers dynamically for four devices. Please note that all those four device_numbers will not get stored inside this device_number variable. Only the base is stored.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s assume this function returns the major number dynamically. Let&#8217;s say it is 127. That&#8217;s why this device_number variable actually it has two parts. It has major number section and the minor number section. In the major number section, 127 will be stored. And by changing the minor section number, you can derive the next device.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For example, if 127:0 is stored in this variable, then by changing this a minor number to next one, that is 127:1, you get the device number for the next device like that. That&#8217;s why the driver distinguishes between different devices using these minor numbers.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Then we are printing device_number information, but we have got four devices. Now, let&#8217;s use a loop to print it four times. So, now let me declare&nbsp; &#8216;i&#8217; above. device_number you can extract the major number by using MAJOR macro. For this, you have to pass device_number+i. Because to print the next device number, you have to increment the minor count. That&#8217;s why I&#8217;m using +i&nbsp; device_number+i. And this device_number now it should be modified, you have to write pcdrv_data.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Our next task is to do cdev_init and cdev_add. This we have to do for every device. We have got four devices. So, we have to write all these codes in a loop, as shown below.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\"><span style=\"color: #00ccff;\">\/*create device class under \/sys\/class\/ *\/<\/span>\r\npcdrv_data.class_pcd = class_create(THIS_MODULE,\"pcd_class\");\r\n<span style=\"color: #ff99cc;\">if<\/span>(IS_ERR(pcdrv_data.class_pcd)){\r\n&nbsp; &nbsp; &nbsp; &nbsp;pr_err(\"Class creation failed\\n\");\r\n&nbsp; &nbsp; &nbsp; &nbsp;ret = PTR_ERR(pcdrv_data.class_pcd);\r\n&nbsp; &nbsp; &nbsp; goto unreg_chrdev;\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">for<\/span>(i=0;i&lt;NO_OF_DEVICES;i++){\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pr_info(\"Device number &lt;major&gt;:&lt;minor&gt; = %d:%d\\n\",MAJOR(pcdrv_data.device_number+i),MINOR(pcdrv_data.device_number+i));\r\n\r\n&nbsp; &nbsp; <span style=\"color: #00ccff;\">&nbsp; \/*Initialize the cdev structure with fops*\/<\/span>\r\n&nbsp; &nbsp; &nbsp; cdev_init(&amp;pcdrv_data.pcdev_data[i].cdev,&amp;pcd_fops);\r\n\r\n&nbsp; <span style=\"color: #00ccff;\">&nbsp; &nbsp;\/* Register a device (cdev structure) with VFS *\/<\/span>\r\n&nbsp; &nbsp; &nbsp;pcdrv_data.pcdev_data[i].cdev.owner = THIS_MODULE;\r\n&nbsp; &nbsp; &nbsp;ret = cdev_add(&amp;pcdrv_data.pcdev_data[i].cdev,pcdrv_data.device_number+i,1);\r\n&nbsp; &nbsp; &nbsp;<span style=\"color: #ff99cc;\">if<\/span>(ret &lt; 0){\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pr_err(\"Cdev add failed\\n\");\r\n&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff99cc;\">&nbsp;goto<\/span> cdev_del;\r\n&nbsp; &nbsp; &nbsp; }<\/pre>\n<p class=\"\" style=\"text-align: center;\"><span style=\"color: #000000;\"> Cdev_init and cdev_add<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And the class_create. The class_create need not be in a loop because only one time we create the class_create.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, device_create has to be in loop. Anyway, we have this loop for printing device number. So, now let&#8217;s open the loop here, and let&#8217;s put cdev_init and cdev_add&nbsp; codes inside the loop , And let\u2019s close the loop here.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">First, I do the alloc_chrdev_region, and after that, I do the class_create.&nbsp;<\/span><span style=\"font-weight: 400;\">So, the code must be pcdrv_data.class_pcd = class_create(THIS_MODULE, &#8220;pcd_class&#8221;);<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 29px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, error checking should be same. And after that, PTR_ERR macro should take pcdrv_data.class_pcd.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s check codes inside the for loop. Here, initialize the cdev structure with fops. Here, for the cdev_init, the first argument is address of the cdev structure, but the cdev is per device basis in this exercise. That&#8217;s why I&#8217;ll be writing this like you know pcdrv_data.pcdev_data [i].cdev. I hope this line is clear, and this will be the file operations. So, that means every cdev structure is initialized with file operation structure.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, register a&nbsp; device with VFS. Here pcdev_owner, so this will be&nbsp; pcdrv_data.pcdev_data[i].cdev.owner.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">After that, cdev_add. So, here also you should write something like this&nbsp;<\/span><span style=\"font-weight: 400;\">pcdrv_data.pcdev_data[i].cdev. And here, you have to mention the device_number. So, the device number is pcdrv_data.device_number. And we are adding one device.&nbsp; After is a error checking.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Now let&#8217;s go to the next one&nbsp; populate the sysfs with device information.&nbsp;<\/span><span style=\"font-weight: 400;\">So, device_pcd.&nbsp; This will be pcdrv_data.device_pcd. device_create(class_pcd). class_pcd will be&nbsp; pcdrv_data.NULL, device&nbsp; number will be a pcdrv_data.device_number, NULL. Now, here you have to create different device file names for different devices. So, it should be PCDDEV1, 2,3,4.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s look at device tree API once again. Let&#8217;s look at its implementation shown in Figure 2. So, here I have a reference device_create. And look at the last argument. This actually takes a formatted string. A string for the device_name, so this is a formatted string. That&#8217;s why you can a write something like this.<\/span><\/p>\n<figure id=\"attachment_8337\" aria-describedby=\"caption-attachment-8337\" style=\"width: 725px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-8337\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-3-19.png\" alt=\"Figure 3. Device tree API\" width=\"725\" height=\"407\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-3-19.png 725w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-3-19-300x168.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-3-19-600x337.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-3-19-120x67.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-3-19-500x281.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-3-19-200x112.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-3-19-400x225.png 400w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><figcaption id=\"caption-attachment-8337\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Device tree API<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s get back to the code. I will write this as &#8220;pcdev-%d&#8221;, and here you can mention i as shown in Figure 3.<\/span><\/p>\n<figure id=\"attachment_8338\" aria-describedby=\"caption-attachment-8338\" style=\"width: 723px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-8338 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-4-18.png\" alt=\"Pcd driver with multiple devices code\" width=\"723\" height=\"406\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-4-18.png 723w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-4-18-300x168.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-4-18-600x337.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-4-18-120x67.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-4-18-500x281.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-4-18-200x112.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-4-18-400x225.png 400w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><figcaption id=\"caption-attachment-8338\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. device_create<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">When this loop runs for the first time,&nbsp; this will be replaced by pcdev- this value i, that will be 0 like that. It creates a pcdev 0,1,2,3.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And after that, pcdrv_data.device_pcd. And in the error checking,&nbsp;<\/span><span style=\"font-weight: 400;\">this will be pcdrv_data.device_pcd. Our loop ends here.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let&#8217;s remove if 0. We have almost reached the end. Remove <\/span><b>#endif<\/b><span style=\"font-weight: 400;\"> as well. Let me remove this return zero. If everything goes well here, then it would print &#8220;Module init was successful&#8221; and it returns zero. Otherwise, you have to do some cleanups.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Before that, let&#8217;s fix variables as shown below. So, this will be pcdrv_data.pcd (in class_destroy), and you have to delete the cdev structure. Actually, this you have to do it in a loop.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pr_info(\"Module init was successful\\n\");\r\n\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #ff99cc;\">return<\/span> 0;\r\n\r\n<span style=\"color: #ff99cc;\">class_de<\/span>l:\r\n          class_destroy(pcdrv_data.class_pcd);\r\n<span style=\"color: #ff99cc;\">cdev_del<\/span>:\r\n  &nbsp; &nbsp; &nbsp; &nbsp; cdev_del(&amp;pcdrv_data.pcdev_data[i].cdev);\r\n<span style=\"color: #ff99cc;\">unreg_chrdev<\/span>:\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unregister_chrdev_region(pcdrv_data.device_number,NO_OF_DEVICES);\r\n<span style=\"color: #ff99cc;\">out<\/span>:\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pr_info(\"Module insertion failed\\n\");\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #ff99cc;\"> return<\/span> ret;<\/pre>\n<p class=\"\" style=\"text-align: center;\"><span style=\"color: #000000;\">Fixing code for class_del, cdev_del, unreg_chrdev, out<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">But before that,&nbsp; This cdev should be &amp;pcdrv_data.pcdev_data[i].cdev. Unregister_chrdev_region. You will be unregistering 4 devices. Here,&nbsp;<\/span><span style=\"font-weight: 400;\">you have to mention the number of devices, so let&#8217;s use the macro&nbsp; NO_OF_DEVICES. And you print &#8220;model insertion failed,&#8221; and you just return the error code. And cleanup is incomplete actually, we will code this later.&nbsp;<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">But let&#8217;s make host, and we have one error at 232, as shown in Figure 4.<\/span><\/p>\n<figure id=\"attachment_8340\" aria-describedby=\"caption-attachment-8340\" style=\"width: 723px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8340 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-6-17.png\" alt=\"Pcd driver with multiple devices code\" width=\"723\" height=\"402\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-17.png 723w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-17-300x167.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-17-600x334.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-17-120x67.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-17-500x278.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-17-200x111.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-17-400x222.png 400w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><figcaption id=\"caption-attachment-8340\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Make host<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s check that this is pcdrv_data as shown in Figure 5.<\/span><\/p>\n<figure id=\"attachment_8341\" aria-describedby=\"caption-attachment-8341\" style=\"width: 721px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8341 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-7-15.png\" alt=\"Pcd driver with multiple devices code\" width=\"721\" height=\"407\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-15.png 721w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-15-300x169.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-15-600x339.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-15-120x68.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-15-500x282.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-15-200x113.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-15-400x226.png 400w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><figcaption id=\"caption-attachment-8341\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Corrections in the code<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So here, one more mistake. cdev_init is fine. In the cdev_add,&nbsp; for the next pass, it has to be the next device number. That&#8217;s why you have to do +i.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And in the device_create, for the next pass, it has to be the next device. That&#8217;s why you have to do&nbsp; +i here as well. Save and exit and compile the code.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">In the next article, we will fix this cleanup procedure. Because we now have got multiple devices. So, that&#8217;s why here the cleanup procedure is a little different&nbsp;<\/span><span style=\"font-weight: 400;\">And we will cover that in the next article.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 28px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span>&nbsp;<\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Pcd driver with multiple devices code implementation part-3 &nbsp; &nbsp; In this article, let&#8217;s implement the pcd_driver_init function. Let&#8217;s shift #if 0 to somewhere below. First of all, we have to dynamically allocate device_numbers. We are going to use the alloc_chrdev region. Here, this device number you have to get from the driver&#8217;s data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8335,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[18],"class_list":["post-8332","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-linux-device-driver-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pcd driver with multiple devices code implementation part-3 | LDD1<\/title>\n<meta name=\"description\" content=\"Pcd driver with multiple devices code implementation part-3. In this article, let&#039;s implement the pcd_driver_init function. Let&#039;s shift #if 0\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pcd driver with multiple devices code implementation part-3 | LDD1\" \/>\n<meta property=\"og:description\" content=\"Pcd driver with multiple devices code implementation part-3. In this article, let&#039;s implement the pcd_driver_init function. Let&#039;s shift #if 0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-11T08:54:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-12T10:14:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23.png\" \/>\n\t<meta property=\"og:image:width\" content=\"660\" \/>\n\t<meta property=\"og:image:height\" content=\"372\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Linux Device Driver Programming Lecture 51- Pcd driver with multiple devices code implementation part-3\",\"datePublished\":\"2022-03-11T08:54:01+00:00\",\"dateModified\":\"2023-08-12T10:14:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/\"},\"wordCount\":1262,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/Figure-1-23.png\",\"keywords\":[\"Linux Device Driver Programming Tutorial\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/\",\"name\":\"Pcd driver with multiple devices code implementation part-3 | LDD1\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/Figure-1-23.png\",\"datePublished\":\"2022-03-11T08:54:01+00:00\",\"dateModified\":\"2023-08-12T10:14:45+00:00\",\"description\":\"Pcd driver with multiple devices code implementation part-3. In this article, let's implement the pcd_driver_init function. Let's shift #if 0\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/Figure-1-23.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/Figure-1-23.png\",\"width\":660,\"height\":372,\"caption\":\"Figure 1. Dynamically allovate the device number for 4 devices\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/pcd-driver-with-multiple-devices-code-implementation-part-3\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Device Driver Programming Lecture 51- Pcd driver with multiple devices code implementation part-3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pcd driver with multiple devices code implementation part-3 | LDD1","description":"Pcd driver with multiple devices code implementation part-3. In this article, let's implement the pcd_driver_init function. Let's shift #if 0","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/","og_locale":"en_US","og_type":"article","og_title":"Pcd driver with multiple devices code implementation part-3 | LDD1","og_description":"Pcd driver with multiple devices code implementation part-3. In this article, let's implement the pcd_driver_init function. Let's shift #if 0","og_url":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-03-11T08:54:01+00:00","article_modified_time":"2023-08-12T10:14:45+00:00","og_image":[{"width":660,"height":372,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Linux Device Driver Programming Lecture 51- Pcd driver with multiple devices code implementation part-3","datePublished":"2022-03-11T08:54:01+00:00","dateModified":"2023-08-12T10:14:45+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/"},"wordCount":1262,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23.png","keywords":["Linux Device Driver Programming Tutorial"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/","url":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/","name":"Pcd driver with multiple devices code implementation part-3 | LDD1","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23.png","datePublished":"2022-03-11T08:54:01+00:00","dateModified":"2023-08-12T10:14:45+00:00","description":"Pcd driver with multiple devices code implementation part-3. In this article, let's implement the pcd_driver_init function. Let's shift #if 0","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-23.png","width":660,"height":372,"caption":"Figure 1. Dynamically allovate the device number for 4 devices"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/pcd-driver-with-multiple-devices-code-implementation-part-3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux Device Driver Programming Lecture 51- Pcd driver with multiple devices code implementation part-3"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/8332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=8332"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/8332\/revisions"}],"predecessor-version":[{"id":15438,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/8332\/revisions\/15438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/8335"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=8332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=8332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=8332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}