linux pwm 应用

原创:kylin_zeng  http://blog.chinaunix.net/uid/23795897.html

lcd 背光灯 pwm  board配置。

点击(此处)折叠或打开

  1. #ifdef CONFIG_BACKLIGHT_RK29_BL
  2. #define PWM_ID 3
  3. #define PWM_MODE     PWM3
  4. #define PWM_EFFECT_VALUE 1

  5. static struct platform_device rk29_device_backlight = {
  6.     .name    = "rk29_backlight",
  7.     .id     = -1,
  8.     .dev    = {
  9.         .platform_data = &rk29_bl_info,
  10.     }
  11. };


  12. static struct rk29_bl_info rk29_bl_info = {
  13.         .min_brightness = 120,//65, //value must between 0~255
  14.         .max_brightness = 255,//150, //value must between 0~255
  15.         .brightness_mode =BRIGHTNESS_MODE_CONIC,
  16.     .pre_div = 30 * 1000, // pwm output clk: 30k;
  17.     .pwm_id = PWM_ID, //3
  18.     .bl_ref = PWM_EFFECT_VALUE, //1
  19.     .io_init = rk29_backlight_io_init,
  20.     .io_deinit = rk29_backlight_io_deinit,
  21.     .pwm_suspend = rk29_backlight_pwm_suspend,
  22.     .pwm_resume = rk29_backlight_pwm_resume,
  23. };


  24. static int rk29_backlight_io_init(void)
  25. {
  26.     int ret = 0;
  27.     iomux_set(PWM_MODE);
  28.     return ret;
  29. }

  30. static int rk29_backlight_io_deinit(void)
  31. {
  32.     int ret = 0, pwm_gpio;
  33.     pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
  34.     gpio_request(pwm_gpio, NULL);
  35.     gpio_direction_output(pwm_gpio, GPIO_LOW);
  36.     return ret;
  37. }


  38. static int rk29_backlight_pwm_suspend(void)
  39. {
  40.     int ret = 0, pwm_gpio;
  41.     pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
  42.     if (gpio_request(pwm_gpio, NULL)) {
  43.         printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
  44.         return -1;
  45.     }
  46.     gpio_direction_output(pwm_gpio, GPIO_LOW);
  47.     return ret;
  48. }

  49. static int rk29_backlight_pwm_resume(void)
  50. {
  51.     int pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
  52.     gpio_free(pwm_gpio);
  53.     iomux_set(PWM_MODE);
  54.     return 0;
  55. }

  56. int iomux_mode_to_gpio(unsigned int mode)
  57. {
  58.         struct union_mode m;

  59.     if(!mode_is_valid(mode)){
  60.         INFO("<%s> mode(0x%x) is invalid\n", __func__, mode);
  61.         return INVALID_GPIO;
  62.     }

  63.         m.mode = mode;
  64.         return PIN_BASE + m.mux.bank * 32 + (m.mux.goff - 0x0A) * 8 + m.mux.off;
  65. }

阅读(3) | 评论(0) | 转发(0) |
0

上一篇:android 网络下载文件 和 读写sdcard 方法

下一篇:ContentProvider 用法

相关热门文章
  • 仿迅雷之Anroid版开始
  • linux常用命令
  • linux常用命令详解
  • linux线程浅析
  • 优质的广州PHP程序开发培训课...
  • linux 常见服务端口
  • 【ROOTFS搭建】busybox的httpd...
  • xmanager 2.0 for linux配置
  • 什么是shell
  • linux socket的bug??
  • 请问Linux默认shell的是什么 ...
  • 谁能够帮我解决LINUX 2.6 10...
  • 现在的博客积分不会更新了吗?...
  • shell怎么读取网页内容...
  • ssh等待连接的超时问题...
给主人留下些什么吧!~~
评论热议

你可能感兴趣的:(linux)