免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2961 | 回复: 1
打印 上一主题 下一主题

为按键申请中断失败。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-11 15:54 |只看该作者 |倒序浏览
linux 2.6.29
修改的gpio_keys.c

  1. static int __devinit gpio_keys_probe(struct platform_device *pdev)
  2. {
  3.         struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
  4.         struct input_dev *input;
  5.         int i, error;
  6.         int wakeup = 0;

  7.         input = input_allocate_device();
  8.         if (!input)
  9.                 return -ENOMEM;

  10.         platform_set_drvdata(pdev, input);

  11.         input->evbit[0] = BIT_MASK(EV_KEY);

  12.         input->name = pdev->name;
  13.         input->phys = "gpio-keys/input0";
  14.         input->dev.parent = &pdev->dev;

  15.         input->id.bustype = BUS_HOST;
  16.         input->id.vendor = 0x0001;
  17.         input->id.product = 0x0001;
  18.         input->id.version = 0x0100;

  19.         for (i = 0; i < pdata->nbuttons; i++) {
  20.                 struct gpio_keys_button *button = &pdata->buttons[i];
  21.                 int irq;
  22.                 unsigned int type = button->type ?: EV_KEY;

  23.                 error = gpio_request(button->gpio, button->desc ?: "gpio_keys");
  24.                 if (error < 0) {
  25.                         pr_err("gpio-keys: failed to request GPIO %d,"
  26.                                 " error %d\n", button->gpio, error);
  27.                         goto fail;
  28.                 }

  29.                 error = gpio_direction_input(button->gpio);
  30.                 if (error < 0) {
  31.                         pr_err("gpio-keys: failed to configure input"
  32.                                 " direction for GPIO %d, error %d\n",
  33.                                 button->gpio, error);
  34.                         gpio_free(button->gpio);
  35.                         goto fail;
  36.                 }

  37.                 irq = gpio_to_irq(button->gpio);
  38.                 if (irq < 0) {
  39.                         error = irq;
  40. ==================这里申请中断失败了===================================================
  41.                         pr_err("gpio-keys: Unable to get irq number"
  42.                                 " for GPIO %d, error %d\n",
  43.                                 button->gpio, error);
  44.                         gpio_free(button->gpio);
  45. ======================================================================
  46.                         goto fail;
  47.                 }

  48.                 error = request_irq(irq, gpio_keys_isr,
  49.                                     IRQF_SHARED | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  50. //                                    IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_RISING |
  51. //                                        IRQF_TRIGGER_FALLING,

  52.                                     button->desc ? button->desc : "gpio_keys",
  53.                                     pdev);
  54.                 if (error) {
  55.                         pr_err("gpio-keys: Unable to claim irq %d; error %d\n",
  56.                                 irq, error);
  57.                         gpio_free(button->gpio);
  58.                         goto fail;
  59.                 }

  60.                 if (button->wakeup)
  61.                         wakeup = 1;

  62.                 input_set_capability(input, type, button->code);
  63.         }

  64.         error = input_register_device(input);
  65.         if (error) {
  66.                 pr_err("gpio-keys: Unable to register input device, "
  67.                         "error: %d\n", error);
  68.                 goto fail;
  69.         }

  70.         device_init_wakeup(&pdev->dev, wakeup);

  71.         return 0;

  72. fail:
  73.         while (--i >= 0) {
  74.                 free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev);
  75.                 gpio_free(pdata->buttons[i].gpio);
  76.         }

  77.         platform_set_drvdata(pdev, NULL);
  78.         input_free_device(input);

  79.         return error;
  80. }
复制代码
我在arch/arm/mach-s5pc100/mach-smdks5pc100.c里加入的

  1. static struct gpio_keys_button gpio_keys_button[] = {
  2.         [0] = {
  3.                 .desc   = "ENTER",
  4.                 .code   = KEY_ENTER,
  5.                 .type   = EV_KEY,
  6.                 .gpio   = S5PC1XX_GPH0(1),
  7.                 .wakeup = 0,
  8.                 .active_low = 0,
  9.         },
  10.         [1] = {
  11.                 .desc   = "DOWN",
  12.                 .code   = KEY_DOWN,
  13.                 .type   = EV_KEY,
  14.                 .gpio   = S5PC1XX_GPH0(2),
  15.                 .wakeup = 0,
  16.         },
  17.         [2] = {
  18.                 .desc   = "RIGHT",
  19.                 .code   = KEY_RIGHT,
  20.                 .type   = EV_KEY,
  21.                 .gpio   = S5PC1XX_GPH0(3),
  22.                 .wakeup = 0,
  23.         },
  24.         [3] = {
  25.                 .desc   = "LEFT",
  26.                 .code   = KEY_LEFT,
  27.                 .type   = EV_KEY,
  28.                 .gpio   = S5PC1XX_GPH0(4),
  29.                 .wakeup = 0,
  30.         },
  31.         [4] = {
  32.                 .desc   = "ESCAPE",
  33.                 .code   = KEY_ESC,
  34.                 .type   = EV_KEY,
  35.                 .gpio   = S5PC1XX_GPH0(6),
  36.                 .wakeup = 0,
  37.         },
  38.         [5] = {
  39.                 .desc   = "SPACE",
  40.                 .code   = KEY_SPACE,
  41.                 .type   = EV_KEY,
  42.                 .gpio   = S5PC1XX_GPH0(7),
  43.                 .wakeup = 0,
  44.         },
  45.         [6] = {
  46.                 .desc   = "UP",
  47.                 .code   = KEY_UP,
  48.                 .type   = EV_KEY,
  49.                 .gpio   = S5PC1XX_GPH1(3),
  50.                 .wakeup = 0,
  51.         },

  52. };

  53. static struct gpio_keys_platform_data pixstar_gpio_keys = {
  54.         .buttons        = gpio_keys_button,
  55.         .nbuttons       = 7,
  56. };

  57. static struct platform_device pix_gpio_keys_device = {
  58.         .name           = "gpio-keys",
  59.         .id             = -1,
  60.         .dev            = {
  61.                 .platform_data  = &pixstar_gpio_keys,
  62.         },
  63. };
复制代码
请问各位我还有哪里没有改对?

论坛徽章:
0
2 [报告]
发表于 2011-01-12 14:50 |只看该作者
结贴
没有对应gpio_to_irq的头文件,没有对应关系
gpio_to_irq()
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP