plat_driver与file_operations两种方法开发led驱动.doc_第1页
plat_driver与file_operations两种方法开发led驱动.doc_第2页
plat_driver与file_operations两种方法开发led驱动.doc_第3页
plat_driver与file_operations两种方法开发led驱动.doc_第4页
plat_driver与file_operations两种方法开发led驱动.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

platform_driver与file_operations两种方法开发led驱动分类:片内驱动开发(I2C、NAND Flash、LINUX内核)片外驱动开发(tuner、demod、ca、e2prom)2011-08-08 13:141538人阅读评论(0)收藏举报filestructmodulectableoutput下面是两个LED灯的驱动程序 一个用platform_driver 另一个用file_operationscppview plaincopy1. #include2. #include3. #include4. #include5. 6. #include7. #include8. #include9. 10. /*ourcontext*/11. 12. structs3c24xx_gpio_led13. structled_classdevcdev;14. structs3c24xx_led_platdata*pdata;15. ;16. 17. staticinlinestructs3c24xx_gpio_led*pdev_to_gpio(structplatform_device*dev)18. 19. returnplatform_get_drvdata(dev);20. 21. 22. staticinlinestructs3c24xx_gpio_led*to_gpio(structled_classdev*led_cdev)23. 24. returncontainer_of(led_cdev,structs3c24xx_gpio_led,cdev);25. 26. 27. staticvoids3c24xx_led_set(structled_classdev*led_cdev,28. enumled_brightnessvalue)29. 30. structs3c24xx_gpio_led*led=to_gpio(led_cdev);31. structs3c24xx_led_platdata*pd=led-pdata;32. 33. /*therewillbeashortdelaybetweensettingtheoutputand34. *goingfromoutputtoinputwhenusingtristate.*/35. 36. s3c2410_gpio_setpin(pd-gpio,(value?1:0)37. (pd-flags&S3C24XX_LEDF_ACTLOW);38. 39. if(pd-flags&S3C24XX_LEDF_TRISTATE)40. s3c2410_gpio_cfgpin(pd-gpio,41. value?S3C2410_GPIO_OUTPUT:S3C2410_GPIO_INPUT);42. 43. 44. 45. staticints3c24xx_led_remove(structplatform_device*dev)46. 47. structs3c24xx_gpio_led*led=pdev_to_gpio(dev);48. 49. led_classdev_unregister(&led-cdev);50. kfree(led);51. 52. return0;53. 54. 55. staticints3c24xx_led_probe(structplatform_device*dev)56. 57. structs3c24xx_led_platdata*pdata=dev-dev.platform_data;58. structs3c24xx_gpio_led*led;59. intret;60. 61. led=kzalloc(sizeof(structs3c24xx_gpio_led),GFP_KERNEL);62. if(led=NULL)63. dev_err(&dev-dev,Nomemoryfordevicen);64. return-ENOMEM;65. 66. 67. platform_set_drvdata(dev,led);68. 69. led-cdev.brightness_set=s3c24xx_led_set;70. led-cdev.default_trigger=pdata-def_trigger;71. =pdata-name;72. 73. led-pdata=pdata;74. 75. /*nopointinhavingapull-upifwearealwaysdriving*/76. 77. if(pdata-flags&S3C24XX_LEDF_TRISTATE)78. s3c2410_gpio_setpin(pdata-gpio,0);79. s3c2410_gpio_cfgpin(pdata-gpio,S3C2410_GPIO_INPUT);80. else81. s3c2410_gpio_pullup(pdata-gpio,0);82. s3c2410_gpio_setpin(pdata-gpio,0);83. s3c2410_gpio_cfgpin(pdata-gpio,S3C2410_GPIO_OUTPUT);84. 85. 86. /*registerournewleddevice*/87. 88. ret=led_classdev_register(&dev-dev,&led-cdev);89. if(retdev,led_classdev_registerfailedn);91. gotoexit_err1;92. 93. 94. return0;95. 96. exit_err1:97. kfree(led);98. returnret;99. 100. 101. 102. #ifdefCONFIG_PM103. staticints3c24xx_led_suspend(structplatform_device*dev,pm_message_tstate)104. 105. structs3c24xx_gpio_led*led=pdev_to_gpio(dev);106. 107. led_classdev_suspend(&led-cdev);108. return0;109. 110. 111. staticints3c24xx_led_resume(structplatform_device*dev)112. 113. structs3c24xx_gpio_led*led=pdev_to_gpio(dev);114. 115. led_classdev_resume(&led-cdev);116. return0;117. 118. #else119. #defines3c24xx_led_suspendNULL120. #defines3c24xx_led_resumeNULL121. #endif122. 123. staticstructplatform_drivers3c24xx_led_driver=124. .probe=s3c24xx_led_probe,125. .remove=s3c24xx_led_remove,126. .suspend=s3c24xx_led_suspend,127. .resume=s3c24xx_led_resume,128. .driver=129. .name=s3c24xx_led,130. .owner=THIS_MODULE,131. ,132. ;133. 134. staticint_inits3c24xx_led_init(void)135. 136. returnplatform_driver_register(&s3c24xx_led_driver);137. 138. 139. staticvoid_exits3c24xx_led_exit(void)140. 141. platform_driver_unregister(&s3c24xx_led_driver);142. 143. 144. module_init(s3c24xx_led_init);145. module_exit(s3c24xx_led_exit);146. 147. MODULE_AUTHOR(BenDooks);148. MODULE_DESCRIPTION(S3C24XXLEDdriver);149. MODULE_LICENSE(GPL);150. MODULE_ALIAS(platform:s3c24xx_led);151. 152. 153. 154. 155. 另一个如下:156. 157. #include158. #include159. #include160. 161. #defineDEVICE_NAMEleds162. 163. staticunsignedlongled_table=164. S3C2410_GPB5,165. 166. S3C2410_GPB6,167. S3C2410_GPB7,168. S3C2410_GPB8,169. ;170. 171. staticunsignedintled_cfg_table=172. S3C2410_GPB5_OUTP,173. 174. S3C2410_GPB6_OUTP,175. S3C2410_GPB7_OUTP,176. S3C2410_GPB8_OUTP,177. ;178. 179. staticintsbc2440_leds_ioctl(180. structinode*inode,181. structfile*file,182. unsignedintcmd,183. unsignedlongarg)184. 185. switch(cmd)186. case0:187. case1:188. if(arg4)189. return-EINVAL;190. 191. s3c2410_gpio_setpin(led_tablearg,!cmd);192. return0;193. default:194. return-EINVAL;195. 196. 197. 198. staticstructfile_operationsdev_fops=199. .owner=THIS_MODULE,200. .ioctl=sbc2440_leds_ioctl,201. ;202. 203. staticstructmiscdevicemisc=204. .minor=MISC_DYNAMIC_MINOR,205. .name=DEVICE_NAME,206. .fops=&dev_fops,207. ;208. 209. staticint_initdev_init(void)210. 211. intret;212. 213. inti;214. 215. for(i=0;i4;i+)216. s3c2410_gpio_cfgpin(led_tablei,led_cfg_tablei);217. s3c2410_gpio_setpin(led_tablei,0);218. 219. 220. ret=misc_register(&misc);221. 222. prin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论