platform_driver与file_operations两种方法开发led驱动

上传人:第*** 文档编号:31317555 上传时间:2018-02-06 格式:DOC 页数:8 大小:68.50KB
返回 下载 相关 举报
platform_driver与file_operations两种方法开发led驱动_第1页
第1页 / 共8页
platform_driver与file_operations两种方法开发led驱动_第2页
第2页 / 共8页
platform_driver与file_operations两种方法开发led驱动_第3页
第3页 / 共8页
platform_driver与file_operations两种方法开发led驱动_第4页
第4页 / 共8页
platform_driver与file_operations两种方法开发led驱动_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《platform_driver与file_operations两种方法开发led驱动》由会员分享,可在线阅读,更多相关《platform_driver与file_operations两种方法开发led驱动(8页珍藏版)》请在金锄头文库上搜索。

1、 platform_driver 与 file_operations 两种方法开发 led 驱动分类: 片内驱动开发(I2C、NAND Flash、LINUX 内核) 片外驱动开发(tuner、demod、ca、e2prom)2011-08-08 13:141538 人阅读 评论(0)收藏 举报filestructmodulectableoutput下面是两个 LED 灯的驱动程序 一个用 platform_driver 另一个用 file_operationscpp view plaincopy1.#include 2.#include 3.#include 4.#include 5. 6.

2、#include 7.#include 8.#include 9. 10./* our context */ 11. 12.struct s3c24xx_gpio_led 13.struct led_classdev cdev; 14.struct s3c24xx_led_platdata *pdata; 15.; 16. 17.static inline struct s3c24xx_gpio_led *pdev_to_gpio(struct platform_device *dev) 18. 19.return platform_get_drvdata(dev); 20. 21. 22.s

3、tatic inline struct s3c24xx_gpio_led *to_gpio(struct led_classdev *led_cdev) 23. 24.return container_of(led_cdev, struct s3c24xx_gpio_led, cdev); 25. 26. 27.static void s3c24xx_led_set(struct led_classdev*led_cdev, 28.enum led_brightness value) 29. 30.struct s3c24xx_gpio_led *led = to_gpio(led_cdev)

4、;31.struct s3c24xx_led_platdata *pd = led-pdata; 32. 33./* there will be a short delay between setting the output and 34.* going from output to input when using tristate. */ 35. 36.s3c2410_gpio_setpin(pd-gpio, (value ? 1 : 0) 37.(pd-flags 38. 39.if (pd-flags & S3C24XX_LEDF_TRISTATE) 40.s3c2410_gpio_

5、cfgpin(pd-gpio, 41.value ? S3C2410_GPIO_OUTPUT : S3C2410_GPIO_INPUT); 42. 43. 44. 45.static int s3c24xx_led_remove(struct platform_device *dev) 46. 47.struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);48. 49.led_classdev_unregister( 50.kfree(led); 51. 52.return 0; 53. 54. 55.static int s3c24xx_led_pr

6、obe(struct platform_device *dev) 56. 57.struct s3c24xx_led_platdata *pdata = dev-dev.platform_data; 58.struct s3c24xx_gpio_led *led; 59.int ret; 60. 61.led = kzalloc(sizeof(struct s3c24xx_gpio_led), GFP_KERNEL); 62.if (led = NULL) 63.dev_err( 64.return -ENOMEM; 65. 66. 67.platform_set_drvdata(dev, l

7、ed); 68. 69.led-cdev.brightness_set = s3c24xx_led_set; 70.led-cdev.default_trigger = pdata-def_trigger; 71.led-cdev.name = pdata-name; 72. 73.led-pdata = pdata; 74. 75./* no point in having a pull-up if we are always driving */ 76. 77.if (pdata-flags & S3C24XX_LEDF_TRISTATE) 78.s3c2410_gpio_setpin(p

8、data-gpio, 0); 79.s3c2410_gpio_cfgpin(pdata-gpio, S3C2410_GPIO_INPUT); 80. else 81.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./* register our new led device */ 87. 88.ret = led_classdev_register(&dev-

9、dev, &led-cdev); 89.if (ret dev, led_classdev_register failedn); 91.goto exit_err1; 92. 93. 94.return 0; 95. 96. exit_err1: 97.kfree(led); 98.return ret; 99. 100. 101. 102. #ifdef CONFIG_PM 103. static int s3c24xx_led_suspend(struct platform_device *dev, pm_message_t state) 104. 105. struct s3c24xx_

10、gpio_led *led = pdev_to_gpio(dev); 106. 107. led_classdev_suspend( 108. return 0; 109. 110. 111. static int s3c24xx_led_resume(struct platform_device *dev) 112. 113. struct s3c24xx_gpio_led *led = pdev_to_gpio(dev); 114. 115. led_classdev_resume( 116. return 0; 117. 118. #else 119. #define s3c24xx_l

11、ed_suspend NULL 120. #define s3c24xx_led_resume NULL 121. #endif 122. 123. static struct platform_driver s3c24xx_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 = s3c24x

12、x_led, 130. .owner = THIS_MODULE, 131. , 132. ; 133. 134. static int _init s3c24xx_led_init(void) 135. 136. return platform_driver_register(&s3c24xx_led_driver); 137. 138. 139. static void _exit s3c24xx_led_exit(void) 140. 141. platform_driver_unregister(&s3c24xx_led_driver); 142. 143. 144. module_i

13、nit(s3c24xx_led_init); 145. module_exit(s3c24xx_led_exit); 146. 147. MODULE_AUTHOR(Ben Dooks ); 148. MODULE_DESCRIPTION(S3C24XX LED driver); 149. MODULE_LICENSE(GPL); 150. MODULE_ALIAS(platform:s3c24xx_led); 151. 152. 153. 154. 155. 另一个如下: 156. 157. #include 158. #include 159. #include 160. 161. #de

14、fine DEVICE_NAME leds 162. 163. static unsigned long led_table = 164. S3C2410_GPB5, 165. 166. S3C2410_GPB6, 167. S3C2410_GPB7, 168. S3C2410_GPB8, 169. ; 170. 171. static unsigned int led_cfg_table = 172. S3C2410_GPB5_OUTP, 173. 174. S3C2410_GPB6_OUTP, 175. S3C2410_GPB7_OUTP, 176. S3C2410_GPB8_OUTP,

15、177. ; 178. 179. static int sbc2440_leds_ioctl( 180. struct inode *inode, 181. struct file *file, 182. unsigned int cmd, 183. unsigned long arg) 184. 185. switch(cmd) 186. case 0: 187. case 1: 188. if (arg 4) 189. return -EINVAL; 190. 191. s3c2410_gpio_setpin(led_tablearg, !cmd); 192. return 0; 193. default: 194. return -EINVAL; 195. 196.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 工程造价

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号