Merge tag 'gcc-plugins-v4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[platform/kernel/linux-rpi.git] / drivers / staging / greybus / arche-platform.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Arche Platform driver to enable Unipro link.
4  *
5  * Copyright 2014-2015 Google Inc.
6  * Copyright 2014-2015 Linaro Ltd.
7  */
8
9 #include <linux/clk.h>
10 #include <linux/delay.h>
11 #include <linux/gpio.h>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/of_gpio.h>
15 #include <linux/of_platform.h>
16 #include <linux/pinctrl/consumer.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm.h>
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/suspend.h>
22 #include <linux/time.h>
23 #include "arche_platform.h"
24 #include "greybus.h"
25
26 #if IS_ENABLED(CONFIG_USB_HSIC_USB3613)
27 #include <linux/usb/usb3613.h>
28 #else
29 static inline int usb3613_hub_mode_ctrl(bool unused)
30 {
31         return 0;
32 }
33 #endif
34
35 #define WD_COLDBOOT_PULSE_WIDTH_MS      30
36
37 enum svc_wakedetect_state {
38         WD_STATE_IDLE,                  /* Default state = pulled high/low */
39         WD_STATE_BOOT_INIT,             /* WD = falling edge (low) */
40         WD_STATE_COLDBOOT_TRIG,         /* WD = rising edge (high), > 30msec */
41         WD_STATE_STANDBYBOOT_TRIG,      /* As of now not used ?? */
42         WD_STATE_COLDBOOT_START,        /* Cold boot process started */
43         WD_STATE_STANDBYBOOT_START,     /* Not used */
44 };
45
46 struct arche_platform_drvdata {
47         /* Control GPIO signals to and from AP <=> SVC */
48         int svc_reset_gpio;
49         bool is_reset_act_hi;
50         int svc_sysboot_gpio;
51         int wake_detect_gpio; /* bi-dir,maps to WAKE_MOD & WAKE_FRAME signals */
52
53         enum arche_platform_state state;
54
55         int svc_refclk_req;
56         struct clk *svc_ref_clk;
57
58         struct pinctrl *pinctrl;
59         struct pinctrl_state *pin_default;
60
61         int num_apbs;
62
63         enum svc_wakedetect_state wake_detect_state;
64         int wake_detect_irq;
65         spinlock_t wake_lock;                   /* Protect wake_detect_state */
66         struct mutex platform_state_mutex;      /* Protect state */
67         unsigned long wake_detect_start;
68         struct notifier_block pm_notifier;
69
70         struct device *dev;
71 };
72
73 /* Requires calling context to hold arche_pdata->platform_state_mutex */
74 static void arche_platform_set_state(struct arche_platform_drvdata *arche_pdata,
75                                      enum arche_platform_state state)
76 {
77         arche_pdata->state = state;
78 }
79
80 /* Requires arche_pdata->wake_lock is held by calling context */
81 static void arche_platform_set_wake_detect_state(
82                                 struct arche_platform_drvdata *arche_pdata,
83                                 enum svc_wakedetect_state state)
84 {
85         arche_pdata->wake_detect_state = state;
86 }
87
88 static inline void svc_reset_onoff(unsigned int gpio, bool onoff)
89 {
90         gpio_set_value(gpio, onoff);
91 }
92
93 static int apb_cold_boot(struct device *dev, void *data)
94 {
95         int ret;
96
97         ret = apb_ctrl_coldboot(dev);
98         if (ret)
99                 dev_warn(dev, "failed to coldboot\n");
100
101         /*Child nodes are independent, so do not exit coldboot operation */
102         return 0;
103 }
104
105 static int apb_poweroff(struct device *dev, void *data)
106 {
107         apb_ctrl_poweroff(dev);
108
109         /* Enable HUB3613 into HUB mode. */
110         if (usb3613_hub_mode_ctrl(false))
111                 dev_warn(dev, "failed to control hub device\n");
112
113         return 0;
114 }
115
116 static void arche_platform_wd_irq_en(struct arche_platform_drvdata *arche_pdata)
117 {
118         /* Enable interrupt here, to read event back from SVC */
119         gpio_direction_input(arche_pdata->wake_detect_gpio);
120         enable_irq(arche_pdata->wake_detect_irq);
121 }
122
123 static irqreturn_t arche_platform_wd_irq_thread(int irq, void *devid)
124 {
125         struct arche_platform_drvdata *arche_pdata = devid;
126         unsigned long flags;
127
128         spin_lock_irqsave(&arche_pdata->wake_lock, flags);
129         if (arche_pdata->wake_detect_state != WD_STATE_COLDBOOT_TRIG) {
130                 /* Something is wrong */
131                 spin_unlock_irqrestore(&arche_pdata->wake_lock, flags);
132                 return IRQ_HANDLED;
133         }
134
135         arche_platform_set_wake_detect_state(arche_pdata,
136                                              WD_STATE_COLDBOOT_START);
137         spin_unlock_irqrestore(&arche_pdata->wake_lock, flags);
138
139         /* It should complete power cycle, so first make sure it is poweroff */
140         device_for_each_child(arche_pdata->dev, NULL, apb_poweroff);
141
142         /* Bring APB out of reset: cold boot sequence */
143         device_for_each_child(arche_pdata->dev, NULL, apb_cold_boot);
144
145         /* Enable HUB3613 into HUB mode. */
146         if (usb3613_hub_mode_ctrl(true))
147                 dev_warn(arche_pdata->dev, "failed to control hub device\n");
148
149         spin_lock_irqsave(&arche_pdata->wake_lock, flags);
150         arche_platform_set_wake_detect_state(arche_pdata, WD_STATE_IDLE);
151         spin_unlock_irqrestore(&arche_pdata->wake_lock, flags);
152
153         return IRQ_HANDLED;
154 }
155
156 static irqreturn_t arche_platform_wd_irq(int irq, void *devid)
157 {
158         struct arche_platform_drvdata *arche_pdata = devid;
159         unsigned long flags;
160
161         spin_lock_irqsave(&arche_pdata->wake_lock, flags);
162
163         if (gpio_get_value(arche_pdata->wake_detect_gpio)) {
164                 /* wake/detect rising */
165
166                 /*
167                  * If wake/detect line goes high after low, within less than
168                  * 30msec, then standby boot sequence is initiated, which is not
169                  * supported/implemented as of now. So ignore it.
170                  */
171                 if (arche_pdata->wake_detect_state == WD_STATE_BOOT_INIT) {
172                         if (time_before(jiffies,
173                                         arche_pdata->wake_detect_start +
174                                         msecs_to_jiffies(WD_COLDBOOT_PULSE_WIDTH_MS))) {
175                                 arche_platform_set_wake_detect_state(arche_pdata,
176                                                                      WD_STATE_IDLE);
177                         } else {
178                                 /*
179                                  * Check we are not in middle of irq thread
180                                  * already
181                                  */
182                                 if (arche_pdata->wake_detect_state !=
183                                                 WD_STATE_COLDBOOT_START) {
184                                         arche_platform_set_wake_detect_state(arche_pdata,
185                                                                              WD_STATE_COLDBOOT_TRIG);
186                                         spin_unlock_irqrestore(
187                                                 &arche_pdata->wake_lock,
188                                                 flags);
189                                         return IRQ_WAKE_THREAD;
190                                 }
191                         }
192                 }
193         } else {
194                 /* wake/detect falling */
195                 if (arche_pdata->wake_detect_state == WD_STATE_IDLE) {
196                         arche_pdata->wake_detect_start = jiffies;
197                         /*
198                          * In the beginning, when wake/detect goes low
199                          * (first time), we assume it is meant for coldboot
200                          * and set the flag. If wake/detect line stays low
201                          * beyond 30msec, then it is coldboot else fallback
202                          * to standby boot.
203                          */
204                         arche_platform_set_wake_detect_state(arche_pdata,
205                                                              WD_STATE_BOOT_INIT);
206                 }
207         }
208
209         spin_unlock_irqrestore(&arche_pdata->wake_lock, flags);
210
211         return IRQ_HANDLED;
212 }
213
214 /*
215  * Requires arche_pdata->platform_state_mutex to be held
216  */
217 static int
218 arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata)
219 {
220         int ret;
221
222         if (arche_pdata->state == ARCHE_PLATFORM_STATE_ACTIVE)
223                 return 0;
224
225         dev_info(arche_pdata->dev, "Booting from cold boot state\n");
226
227         svc_reset_onoff(arche_pdata->svc_reset_gpio,
228                         arche_pdata->is_reset_act_hi);
229
230         gpio_set_value(arche_pdata->svc_sysboot_gpio, 0);
231         usleep_range(100, 200);
232
233         ret = clk_prepare_enable(arche_pdata->svc_ref_clk);
234         if (ret) {
235                 dev_err(arche_pdata->dev, "failed to enable svc_ref_clk: %d\n",
236                         ret);
237                 return ret;
238         }
239
240         /* bring SVC out of reset */
241         svc_reset_onoff(arche_pdata->svc_reset_gpio,
242                         !arche_pdata->is_reset_act_hi);
243
244         arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_ACTIVE);
245
246         return 0;
247 }
248
249 /*
250  * Requires arche_pdata->platform_state_mutex to be held
251  */
252 static int
253 arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata)
254 {
255         int ret;
256
257         if (arche_pdata->state == ARCHE_PLATFORM_STATE_FW_FLASHING)
258                 return 0;
259
260         dev_info(arche_pdata->dev, "Switching to FW flashing state\n");
261
262         svc_reset_onoff(arche_pdata->svc_reset_gpio,
263                         arche_pdata->is_reset_act_hi);
264
265         gpio_set_value(arche_pdata->svc_sysboot_gpio, 1);
266
267         usleep_range(100, 200);
268
269         ret = clk_prepare_enable(arche_pdata->svc_ref_clk);
270         if (ret) {
271                 dev_err(arche_pdata->dev, "failed to enable svc_ref_clk: %d\n",
272                         ret);
273                 return ret;
274         }
275
276         svc_reset_onoff(arche_pdata->svc_reset_gpio,
277                         !arche_pdata->is_reset_act_hi);
278
279         arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_FW_FLASHING);
280
281         return 0;
282 }
283
284 /*
285  * Requires arche_pdata->platform_state_mutex to be held
286  */
287 static void
288 arche_platform_poweroff_seq(struct arche_platform_drvdata *arche_pdata)
289 {
290         unsigned long flags;
291
292         if (arche_pdata->state == ARCHE_PLATFORM_STATE_OFF)
293                 return;
294
295         /* If in fw_flashing mode, then no need to repeate things again */
296         if (arche_pdata->state != ARCHE_PLATFORM_STATE_FW_FLASHING) {
297                 disable_irq(arche_pdata->wake_detect_irq);
298
299                 spin_lock_irqsave(&arche_pdata->wake_lock, flags);
300                 arche_platform_set_wake_detect_state(arche_pdata,
301                                                      WD_STATE_IDLE);
302                 spin_unlock_irqrestore(&arche_pdata->wake_lock, flags);
303         }
304
305         clk_disable_unprepare(arche_pdata->svc_ref_clk);
306
307         /* As part of exit, put APB back in reset state */
308         svc_reset_onoff(arche_pdata->svc_reset_gpio,
309                         arche_pdata->is_reset_act_hi);
310
311         arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF);
312 }
313
314 static ssize_t state_store(struct device *dev,
315                            struct device_attribute *attr,
316                            const char *buf, size_t count)
317 {
318         struct platform_device *pdev = to_platform_device(dev);
319         struct arche_platform_drvdata *arche_pdata = platform_get_drvdata(pdev);
320         int ret = 0;
321
322         mutex_lock(&arche_pdata->platform_state_mutex);
323
324         if (sysfs_streq(buf, "off")) {
325                 if (arche_pdata->state == ARCHE_PLATFORM_STATE_OFF)
326                         goto exit;
327
328                 /*  If SVC goes down, bring down APB's as well */
329                 device_for_each_child(arche_pdata->dev, NULL, apb_poweroff);
330
331                 arche_platform_poweroff_seq(arche_pdata);
332
333         } else if (sysfs_streq(buf, "active")) {
334                 if (arche_pdata->state == ARCHE_PLATFORM_STATE_ACTIVE)
335                         goto exit;
336
337                 /* First we want to make sure we power off everything
338                  * and then activate back again
339                  */
340                 device_for_each_child(arche_pdata->dev, NULL, apb_poweroff);
341                 arche_platform_poweroff_seq(arche_pdata);
342
343                 arche_platform_wd_irq_en(arche_pdata);
344                 ret = arche_platform_coldboot_seq(arche_pdata);
345                 if (ret)
346                         goto exit;
347
348         } else if (sysfs_streq(buf, "standby")) {
349                 if (arche_pdata->state == ARCHE_PLATFORM_STATE_STANDBY)
350                         goto exit;
351
352                 dev_warn(arche_pdata->dev, "standby state not supported\n");
353         } else if (sysfs_streq(buf, "fw_flashing")) {
354                 if (arche_pdata->state == ARCHE_PLATFORM_STATE_FW_FLASHING)
355                         goto exit;
356
357                 /*
358                  * Here we only control SVC.
359                  *
360                  * In case of FW_FLASHING mode we do not want to control
361                  * APBs, as in case of V2, SPI bus is shared between both
362                  * the APBs. So let user chose which APB he wants to flash.
363                  */
364                 arche_platform_poweroff_seq(arche_pdata);
365
366                 ret = arche_platform_fw_flashing_seq(arche_pdata);
367                 if (ret)
368                         goto exit;
369         } else {
370                 dev_err(arche_pdata->dev, "unknown state\n");
371                 ret = -EINVAL;
372         }
373
374 exit:
375         mutex_unlock(&arche_pdata->platform_state_mutex);
376         return ret ? ret : count;
377 }
378
379 static ssize_t state_show(struct device *dev,
380                           struct device_attribute *attr, char *buf)
381 {
382         struct arche_platform_drvdata *arche_pdata = dev_get_drvdata(dev);
383
384         switch (arche_pdata->state) {
385         case ARCHE_PLATFORM_STATE_OFF:
386                 return sprintf(buf, "off\n");
387         case ARCHE_PLATFORM_STATE_ACTIVE:
388                 return sprintf(buf, "active\n");
389         case ARCHE_PLATFORM_STATE_STANDBY:
390                 return sprintf(buf, "standby\n");
391         case ARCHE_PLATFORM_STATE_FW_FLASHING:
392                 return sprintf(buf, "fw_flashing\n");
393         default:
394                 return sprintf(buf, "unknown state\n");
395         }
396 }
397
398 static DEVICE_ATTR_RW(state);
399
400 static int arche_platform_pm_notifier(struct notifier_block *notifier,
401                                       unsigned long pm_event, void *unused)
402 {
403         struct arche_platform_drvdata *arche_pdata =
404                 container_of(notifier, struct arche_platform_drvdata,
405                              pm_notifier);
406         int ret = NOTIFY_DONE;
407
408         mutex_lock(&arche_pdata->platform_state_mutex);
409         switch (pm_event) {
410         case PM_SUSPEND_PREPARE:
411                 if (arche_pdata->state != ARCHE_PLATFORM_STATE_ACTIVE) {
412                         ret = NOTIFY_STOP;
413                         break;
414                 }
415                 device_for_each_child(arche_pdata->dev, NULL, apb_poweroff);
416                 arche_platform_poweroff_seq(arche_pdata);
417                 break;
418         case PM_POST_SUSPEND:
419                 if (arche_pdata->state != ARCHE_PLATFORM_STATE_OFF)
420                         break;
421
422                 arche_platform_wd_irq_en(arche_pdata);
423                 arche_platform_coldboot_seq(arche_pdata);
424                 break;
425         default:
426                 break;
427         }
428         mutex_unlock(&arche_pdata->platform_state_mutex);
429
430         return ret;
431 }
432
433 static int arche_platform_probe(struct platform_device *pdev)
434 {
435         struct arche_platform_drvdata *arche_pdata;
436         struct device *dev = &pdev->dev;
437         struct device_node *np = dev->of_node;
438         int ret;
439
440         arche_pdata = devm_kzalloc(&pdev->dev, sizeof(*arche_pdata),
441                                    GFP_KERNEL);
442         if (!arche_pdata)
443                 return -ENOMEM;
444
445         /* setup svc reset gpio */
446         arche_pdata->is_reset_act_hi = of_property_read_bool(np,
447                                                              "svc,reset-active-high");
448         arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
449                                                         "svc,reset-gpio",
450                                                         0);
451         if (arche_pdata->svc_reset_gpio < 0) {
452                 dev_err(dev, "failed to get reset-gpio\n");
453                 return arche_pdata->svc_reset_gpio;
454         }
455         ret = devm_gpio_request(dev, arche_pdata->svc_reset_gpio, "svc-reset");
456         if (ret) {
457                 dev_err(dev, "failed to request svc-reset gpio:%d\n", ret);
458                 return ret;
459         }
460         ret = gpio_direction_output(arche_pdata->svc_reset_gpio,
461                                     arche_pdata->is_reset_act_hi);
462         if (ret) {
463                 dev_err(dev, "failed to set svc-reset gpio dir:%d\n", ret);
464                 return ret;
465         }
466         arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF);
467
468         arche_pdata->svc_sysboot_gpio = of_get_named_gpio(np,
469                                                           "svc,sysboot-gpio",
470                                                           0);
471         if (arche_pdata->svc_sysboot_gpio < 0) {
472                 dev_err(dev, "failed to get sysboot gpio\n");
473                 return arche_pdata->svc_sysboot_gpio;
474         }
475         ret = devm_gpio_request(dev, arche_pdata->svc_sysboot_gpio, "sysboot0");
476         if (ret) {
477                 dev_err(dev, "failed to request sysboot0 gpio:%d\n", ret);
478                 return ret;
479         }
480         ret = gpio_direction_output(arche_pdata->svc_sysboot_gpio, 0);
481         if (ret) {
482                 dev_err(dev, "failed to set svc-reset gpio dir:%d\n", ret);
483                 return ret;
484         }
485
486         /* setup the clock request gpio first */
487         arche_pdata->svc_refclk_req = of_get_named_gpio(np,
488                                                         "svc,refclk-req-gpio",
489                                                         0);
490         if (arche_pdata->svc_refclk_req < 0) {
491                 dev_err(dev, "failed to get svc clock-req gpio\n");
492                 return arche_pdata->svc_refclk_req;
493         }
494         ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req,
495                                 "svc-clk-req");
496         if (ret) {
497                 dev_err(dev, "failed to request svc-clk-req gpio: %d\n", ret);
498                 return ret;
499         }
500         ret = gpio_direction_input(arche_pdata->svc_refclk_req);
501         if (ret) {
502                 dev_err(dev, "failed to set svc-clk-req gpio dir :%d\n", ret);
503                 return ret;
504         }
505
506         /* setup refclk2 to follow the pin */
507         arche_pdata->svc_ref_clk = devm_clk_get(dev, "svc_ref_clk");
508         if (IS_ERR(arche_pdata->svc_ref_clk)) {
509                 ret = PTR_ERR(arche_pdata->svc_ref_clk);
510                 dev_err(dev, "failed to get svc_ref_clk: %d\n", ret);
511                 return ret;
512         }
513
514         platform_set_drvdata(pdev, arche_pdata);
515
516         arche_pdata->num_apbs = of_get_child_count(np);
517         dev_dbg(dev, "Number of APB's available - %d\n", arche_pdata->num_apbs);
518
519         arche_pdata->wake_detect_gpio = of_get_named_gpio(np,
520                                                           "svc,wake-detect-gpio",
521                                                           0);
522         if (arche_pdata->wake_detect_gpio < 0) {
523                 dev_err(dev, "failed to get wake detect gpio\n");
524                 return arche_pdata->wake_detect_gpio;
525         }
526
527         ret = devm_gpio_request(dev, arche_pdata->wake_detect_gpio,
528                                 "wake detect");
529         if (ret) {
530                 dev_err(dev, "Failed requesting wake_detect gpio %d\n",
531                         arche_pdata->wake_detect_gpio);
532                 return ret;
533         }
534
535         arche_platform_set_wake_detect_state(arche_pdata, WD_STATE_IDLE);
536
537         arche_pdata->dev = &pdev->dev;
538
539         spin_lock_init(&arche_pdata->wake_lock);
540         mutex_init(&arche_pdata->platform_state_mutex);
541         arche_pdata->wake_detect_irq =
542                 gpio_to_irq(arche_pdata->wake_detect_gpio);
543
544         ret = devm_request_threaded_irq(dev, arche_pdata->wake_detect_irq,
545                                         arche_platform_wd_irq,
546                                         arche_platform_wd_irq_thread,
547                                         IRQF_TRIGGER_FALLING |
548                                         IRQF_TRIGGER_RISING | IRQF_ONESHOT,
549                                         dev_name(dev), arche_pdata);
550         if (ret) {
551                 dev_err(dev, "failed to request wake detect IRQ %d\n", ret);
552                 return ret;
553         }
554         disable_irq(arche_pdata->wake_detect_irq);
555
556         ret = device_create_file(dev, &dev_attr_state);
557         if (ret) {
558                 dev_err(dev, "failed to create state file in sysfs\n");
559                 return ret;
560         }
561
562         ret = of_platform_populate(np, NULL, NULL, dev);
563         if (ret) {
564                 dev_err(dev, "failed to populate child nodes %d\n", ret);
565                 goto err_device_remove;
566         }
567
568         arche_pdata->pm_notifier.notifier_call = arche_platform_pm_notifier;
569         ret = register_pm_notifier(&arche_pdata->pm_notifier);
570
571         if (ret) {
572                 dev_err(dev, "failed to register pm notifier %d\n", ret);
573                 goto err_device_remove;
574         }
575
576         /* Explicitly power off if requested */
577         if (!of_property_read_bool(pdev->dev.of_node, "arche,init-off")) {
578                 mutex_lock(&arche_pdata->platform_state_mutex);
579                 ret = arche_platform_coldboot_seq(arche_pdata);
580                 if (ret) {
581                         dev_err(dev, "Failed to cold boot svc %d\n", ret);
582                         goto err_coldboot;
583                 }
584                 arche_platform_wd_irq_en(arche_pdata);
585                 mutex_unlock(&arche_pdata->platform_state_mutex);
586         }
587
588         dev_info(dev, "Device registered successfully\n");
589         return 0;
590
591 err_coldboot:
592         mutex_unlock(&arche_pdata->platform_state_mutex);
593 err_device_remove:
594         device_remove_file(&pdev->dev, &dev_attr_state);
595         return ret;
596 }
597
598 static int arche_remove_child(struct device *dev, void *unused)
599 {
600         struct platform_device *pdev = to_platform_device(dev);
601
602         platform_device_unregister(pdev);
603
604         return 0;
605 }
606
607 static int arche_platform_remove(struct platform_device *pdev)
608 {
609         struct arche_platform_drvdata *arche_pdata = platform_get_drvdata(pdev);
610
611         unregister_pm_notifier(&arche_pdata->pm_notifier);
612         device_remove_file(&pdev->dev, &dev_attr_state);
613         device_for_each_child(&pdev->dev, NULL, arche_remove_child);
614         arche_platform_poweroff_seq(arche_pdata);
615
616         if (usb3613_hub_mode_ctrl(false))
617                 dev_warn(arche_pdata->dev, "failed to control hub device\n");
618                 /* TODO: Should we do anything more here ?? */
619         return 0;
620 }
621
622 static __maybe_unused int arche_platform_suspend(struct device *dev)
623 {
624         /*
625          * If timing profile premits, we may shutdown bridge
626          * completely
627          *
628          * TODO: sequence ??
629          *
630          * Also, need to make sure we meet precondition for unipro suspend
631          * Precondition: Definition ???
632          */
633         return 0;
634 }
635
636 static __maybe_unused int arche_platform_resume(struct device *dev)
637 {
638         /*
639          * Atleast for ES2 we have to meet the delay requirement between
640          * unipro switch and AP bridge init, depending on whether bridge is in
641          * OFF state or standby state.
642          *
643          * Based on whether bridge is in standby or OFF state we may have to
644          * assert multiple signals. Please refer to WDM spec, for more info.
645          *
646          */
647         return 0;
648 }
649
650 static void arche_platform_shutdown(struct platform_device *pdev)
651 {
652         struct arche_platform_drvdata *arche_pdata = platform_get_drvdata(pdev);
653
654         arche_platform_poweroff_seq(arche_pdata);
655
656         usb3613_hub_mode_ctrl(false);
657 }
658
659 static SIMPLE_DEV_PM_OPS(arche_platform_pm_ops,
660                         arche_platform_suspend,
661                         arche_platform_resume);
662
663 static const struct of_device_id arche_platform_of_match[] = {
664         /* Use PID/VID of SVC device */
665         { .compatible = "google,arche-platform", },
666         { },
667 };
668
669 static const struct of_device_id arche_combined_id[] = {
670         /* Use PID/VID of SVC device */
671         { .compatible = "google,arche-platform", },
672         { .compatible = "usbffff,2", },
673         { },
674 };
675 MODULE_DEVICE_TABLE(of, arche_combined_id);
676
677 static struct platform_driver arche_platform_device_driver = {
678         .probe          = arche_platform_probe,
679         .remove         = arche_platform_remove,
680         .shutdown       = arche_platform_shutdown,
681         .driver         = {
682                 .name   = "arche-platform-ctrl",
683                 .pm     = &arche_platform_pm_ops,
684                 .of_match_table = arche_platform_of_match,
685         }
686 };
687
688 static int __init arche_init(void)
689 {
690         int retval;
691
692         retval = platform_driver_register(&arche_platform_device_driver);
693         if (retval)
694                 return retval;
695
696         retval = arche_apb_init();
697         if (retval)
698                 platform_driver_unregister(&arche_platform_device_driver);
699
700         return retval;
701 }
702 module_init(arche_init);
703
704 static void __exit arche_exit(void)
705 {
706         arche_apb_exit();
707         platform_driver_unregister(&arche_platform_device_driver);
708 }
709 module_exit(arche_exit);
710
711 MODULE_LICENSE("GPL v2");
712 MODULE_AUTHOR("Vaibhav Hiremath <vaibhav.hiremath@linaro.org>");
713 MODULE_DESCRIPTION("Arche Platform Driver");