title: writing an acpi driver in Linux
body: <p>I need to write a kernel module that uses an acpi method to communicate to a hardware device.  </p>
  
  <p>At this point I just want to load the driver and enumerate the devices on the bus.</p>
  
  <p>I found a fairly old but reasonable example on line, below is the basic outline. I pretty much took the example verbatim just changing names, I used acpidump to find the dsdt table get the correct device ID etc.</p>
  
  <p>The driver loads fine, but my add functions are not being called.  My suspicion is that I am missing a step to stimulate scanning the bus after I register it. The example assumes the driver is loaded on boot. Is there a way to request the bus be scanned after registering it such that any devices attached to a registered bus will be added? Understand that my suspicion may be wrong so if my assumptions are wrong please correct me. </p>
  
  <p>below is the source:</p>
  
  <pre><code>static int viking_acpi_add(struct acpi_device *device);
  static int viking_acpi_remove(struct acpi_device *device);
  static void viking_acpi_notify(struct acpi_device *adev, u32 event);
  
  static const struct acpi_device_id nv_device_ids[] = {
      { "ACPI0012", 0},
      { "", 0},
  };
  MODULE_DEVICE_TABLE(acpi, nv_device_ids);
  
  static struct acpi_driver nv_acpi_driver = {
      .name =         "NV NVDR",
      .class =        "NV",
      .ids =          nv_device_ids,
      .ops =          {
                              .add =          nv_acpi_add,
                              .remove =       nv_acpi_remove,
                              .notify =       nv_acpi_notify,
                      },
  .owner =    THIS_MODULE,
  };
  
  //static struct acpi_device acpi_dev;
  
  static int nv_acpi_add(struct acpi_device *device)
  {
      printk("NV: acpi bus add\n");
      return 0;
  }
  
  static int nv_remove(struct acpi_device *device)
  {
      printk("NV: acpi bus remove\n");
      return 0;
  }
  
  static void nv_acpi_notify(struct acpi_device *adev, u32 event)
  {
      device_lock(&amp;adev-&gt;dev);
      printk("notification detected\n");
      device_unlock(&amp;adev-&gt;dev);
  }
  
  static int __init nv_init(void)
  {
      int result = 0;
  
      result = acpi_bus_register_driver(&amp;nvt_driver);
      if (result &lt; 0) {
          printk("Error registering driver\n");
          return -ENODEV;
      }
  
      return 0;
  }
  
  static void __exit nv_exit(void)
  {
      acpi_bus_unregister_driver(&amp;nv_driver);
  }
  
  module_init(nv_init);
  module_exit(nv_exit);
  </code></pre>