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