Add device dependency for services

In Mihawk /dev/input/by-path/platform-gpio-keys-event is not created
by udev while phospho-gpio-monitor@id_button.service is running.
In Mihawk it takes much more time for udev to create device files
because there are more devices in Mihawk. Other platforms may hit the
same issue in the future  This patch adds the dependency of
platform-gpio-keys and platform-gpio-keys-polled to
phosphor-gpio-monitor@.service and phosphor-gpio-presence@.service to
fix the issue in Mihawk.

The timing of kernel, udev and id_button service. The
platform-gpio-keys-event is created at 09:32 while id_button service
in running at 09:31

Nov 01 09:31:11 mihawk kernel: input: gpio-keys as /devices/platform
/gpio-keys/input/input2

Nov 01 09:31:11 mihawk systemd[1]: Started udev Kernel Device Manager.

Nov 01 09:31:17 mihawk systemd[1]: Started udev Coldplug all Devices.

Nov 01 09:31:46 mihawk systemd[1]: phosphor-gpio-monitor@id_button.
service: Main process exited, code=killed, status=6/ABRT
Nov 01 09:31:46 mihawk systemd[1]: phosphor-gpio-monitor@id_button.
service: Failed with result 'signal'.

lrwxrwxrwx    1 root     root             9 Nov  1 09:32
/dev/input/by-path/platform-gpio-keys-event

Tested: The phosphor-gpio-monitor@id_button.service can be started
        successfully.

Signed-off-by: Alvin Wang <alvinwang@msn.com>
Change-Id: I3fd3422e06f39175cc7c5321dcfadc9ad184b9ae
diff --git a/99-gpio-keys.rules b/99-gpio-keys.rules
new file mode 100644
index 0000000..b4a346f
--- /dev/null
+++ b/99-gpio-keys.rules
@@ -0,0 +1,2 @@
+SUBSYSTEM=="input", ENV{ID_PATH}=="platform-gpio-keys", SYMLINK+="platform_gpio_keys", TAG+="systemd"
+SUBSYSTEM=="input", ENV{ID_PATH}=="platform-gpio-keys-polled", SYMLINK+="platform_gpio_keys_polled", TAG+="systemd"
\ No newline at end of file
diff --git a/meson.build b/meson.build
index b5e6529..60b140f 100644
--- a/meson.build
+++ b/meson.build
@@ -53,6 +53,24 @@
     output: 'phosphor-gpio-presence@.service'
 )
 
+udev = dependency('udev')
+udev_rules_dir = join_paths(
+    udev.get_pkgconfig_variable(
+        'udevdir',
+        define_variable: ['prefix', get_option('prefix')],
+    ),
+    'rules.d',
+)
+
+configure_file(
+    copy: true,
+    input: '99-gpio-keys.rules',
+    install: true,
+    install_dir: udev_rules_dir,
+    output: '99-gpio-keys.rules'
+)
+
+
 configure_file(
     copy: true,
     input: 'phosphor-multi-gpio-monitor.json',
diff --git a/phosphor-gpio-monitor@.service b/phosphor-gpio-monitor@.service
index 02572a2..e279169 100644
--- a/phosphor-gpio-monitor@.service
+++ b/phosphor-gpio-monitor@.service
@@ -1,5 +1,9 @@
 [Unit]
 Description=Phosphor GPIO %I monitor
+Requires=dev-platform_gpio_keys.device
+After=dev-platform_gpio_keys.device
+Requires=dev-platform_gpio_keys_polled.device
+After=dev-platform_gpio_keys_polled.device
 
 [Service]
 Restart=no
diff --git a/phosphor-gpio-presence@.service b/phosphor-gpio-presence@.service
index 5f806d9..d6a64e4 100644
--- a/phosphor-gpio-presence@.service
+++ b/phosphor-gpio-presence@.service
@@ -2,6 +2,10 @@
 Description=Phosphor GPIO %I Presence
 Wants=mapper-wait@-xyz-openbmc_project-inventory.service
 After=mapper-wait@-xyz-openbmc_project-inventory.service
+Requires=dev-platform_gpio_keys.device
+After=dev-platform_gpio_keys.device
+Requires=dev-platform_gpio_keys_polled.device
+After=dev-platform_gpio_keys_polled.device
 ConditionPathExists=/etc/default/obmc/gpio/phosphor-power-supply-%i.conf
 
 [Service]