+static int __devlock = 0;
+
+void device_lock(void)
+{
+ __devlock++;
+}
+
+void device_unlock(void)
+{
+ __devlock--;
+ if (!__devlock)
+ device_free_unused(NULL);
+}
+
+static int set_device_state(struct device *dev, bool state)
+{
+ if (state)
+ system_if_up(dev);
+ else
+ system_if_down(dev);
+
+ return 0;
+}
+
+static int
+simple_device_set_state(struct device *dev, bool state)
+{
+ struct device *pdev;
+ int ret = 0;
+
+ pdev = dev->parent.dev;
+ if (state && !pdev) {
+ pdev = system_if_get_parent(dev);
+ if (pdev)
+ device_add_user(&dev->parent, pdev);
+ }
+
+ if (pdev) {
+ if (state)
+ ret = device_claim(&dev->parent);
+ else
+ device_release(&dev->parent);
+
+ if (ret < 0)
+ return ret;
+ }
+ return set_device_state(dev, state);
+}
+