GNU Linux-libre 4.14.266-gnu1
[releases.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                                 /*
180                                  * Check we are not in middle of irq thread
181                                  * already
182                                  */
183                                 if (arche_pdata->wake_detect_state !=
184                                                 WD_STATE_COLDBOOT_START) {
185                                         arche_platform_set_wake_detect_state(arche_pdata,
186                                                                              WD_STATE_COLDBOOT_TRIG);
187                                         spin_unlock_irqrestore(
188                                                 &arche_pdata->wake_lock,
189                                                 flags);
190                                         return IRQ_WAKE_THREAD;
191                                 }
192                         }
193                 }
194         } else {
195                 /* wake/detect falling */
196                 if (arche_pdata->wake_detect_state == WD_STATE_IDLE) {
197                         arche_pdata->wake_detect_start = jiffies;
198                         /*
199                          * In the beginning, when wake/detect goes low
200                          * (first time), we assume it is meant for coldboot
201                          * and set the flag. If wake/detect line stays low
202                          * beyond 30msec, then it is coldboot else fallback
203                          * to standby boot.
204                          */
205                         arche_platform_set_wake_detect_state(arche_pdata,
206                                                              WD_STATE_BOOT_INIT);
207                 }
208         }
209
210         spin_unlock_irqrestore(&arche_pdata->wake_lock, flags);
211
212         return IRQ_HANDLED;
213 }
214
215 /*
216  * Requires arche_pdata->platform_state_mutex to be held
217  */
218 static int
219 arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata)
220 {
221         int ret;
222
223         if (arche_pdata->state == ARCHE_PLATFORM_STATE_ACTIVE)
224                 return 0;
225
226         dev_info(arche_pdata->dev, "Booting from cold boot state\n");
227
228         svc_reset_onoff(arche_pdata->svc_reset_gpio,
229                         arche_pdata->is_reset_act_hi);
230
231         gpio_set_value(arche_pdata->svc_sysboot_gpio, 0);
232         usleep_range(100, 200);
233
234         ret = clk_prepare_enable(arche_pdata->svc_ref_clk);
235         if (ret) {
236                 dev_err(arche_pdata->dev, "failed to enable svc_ref_clk: %d\n",
237                                 ret);
238                 return ret;
239         }
240
241         /* bring SVC out of reset */
242         svc_reset_onoff(arche_pdata->svc_reset_gpio,
243                         !arche_pdata->is_reset_act_hi);
244
245         arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_ACTIVE);
246
247         return 0;
248 }
249
250 /*
251  * Requires arche_pdata->platform_state_mutex to be held
252  */
253 static int
254 arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata)
255 {
256         int ret;
257
258         if (arche_pdata->state == ARCHE_PLATFORM_STATE_FW_FLASHING)
259                 return 0;
260
261         dev_info(arche_pdata->dev, "Switching to FW flashing state\n");
262
263         svc_reset_onoff(arche_pdata->svc_reset_gpio,
264                         arche_pdata->is_reset_act_hi);
265
266         gpio_set_value(arche_pdata->svc_sysboot_gpio, 1);
267
268         usleep_range(100, 200);
269
270         ret = clk_prepare_enable(arche_pdata->svc_ref_clk);
271         if (ret) {
272                 dev_err(arche_pdata->dev, "failed to enable svc_ref_clk: %d\n",
273                                 ret);
274                 return ret;
275         }
276
277         svc_reset_onoff(arche_pdata->svc_reset_gpio,
278                         !arche_pdata->is_reset_act_hi);
279
280         arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_FW_FLASHING);
281
282         return 0;
283 }
284
285 /*
286  * Requires arche_pdata->platform_state_mutex to be held
287  */
288 static void
289 arche_platform_poweroff_seq(struct arche_platform_drvdata *arche_pdata)
290 {
291         unsigned long flags;
292
293         if (arche_pdata->state == ARCHE_PLATFORM_STATE_OFF)
294                 return;
295
296         /* If in fw_flashing mode, then no need to repeate things again */
297         if (arche_pdata->state != ARCHE_PLATFORM_STATE_FW_FLASHING) {
298                 disable_irq(arche_pdata->wake_detect_irq);
299
300                 spin_lock_irqsave(&arche_pdata->wake_lock, flags);
301                 arche_platform_set_wake_detect_state(arche_pdata,
302                                                      WD_STATE_IDLE);
303                 spin_unlock_irqrestore(&arche_pdata->wake_lock, flags);
304         }
305
306         clk_disable_unprepare(arche_pdata->svc_ref_clk);
307
308         /* As part of exit, put APB back in reset state */
309         svc_reset_onoff(arche_pdata->svc_reset_gpio,
310                         arche_pdata->is_reset_act_hi);
311
312         arche_platform_set_state(arche_pdata, ARCHE_PLATFORM_STATE_OFF);
313 }
314
315 static ssize_t state_store(struct device *dev,
316                 struct device_attribute *attr, 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", 0);
470         if (arche_pdata->svc_sysboot_gpio < 0) {
471                 dev_err(dev, "failed to get sysboot gpio\n");
472                 return arche_pdata->svc_sysboot_gpio;
473         }
474         ret = devm_gpio_request(dev, arche_pdata->svc_sysboot_gpio, "sysboot0");
475         if (ret) {
476                 dev_err(dev, "failed to request sysboot0 gpio:%d\n", ret);
477                 return ret;
478         }
479         ret = gpio_direction_output(arche_pdata->svc_sysboot_gpio, 0);
480         if (ret) {
481                 dev_err(dev, "failed to set svc-reset gpio dir:%d\n", ret);
482                 return ret;
483         }
484
485         /* setup the clock request gpio first */
486         arche_pdata->svc_refclk_req = of_get_named_gpio(np,
487                                         "svc,refclk-req-gpio", 0);
488         if (arche_pdata->svc_refclk_req < 0) {
489                 dev_err(dev, "failed to get svc clock-req gpio\n");
490                 return arche_pdata->svc_refclk_req;
491         }
492         ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req,
493                                 "svc-clk-req");
494         if (ret) {
495                 dev_err(dev, "failed to request svc-clk-req gpio: %d\n", ret);
496                 return ret;
497         }
498         ret = gpio_direction_input(arche_pdata->svc_refclk_req);
499         if (ret) {
500                 dev_err(dev, "failed to set svc-clk-req gpio dir :%d\n", ret);
501                 return ret;
502         }
503
504         /* setup refclk2 to follow the pin */
505         arche_pdata->svc_ref_clk = devm_clk_get(dev, "svc_ref_clk");
506         if (IS_ERR(arche_pdata->svc_ref_clk)) {
507                 ret = PTR_ERR(arche_pdata->svc_ref_clk);
508                 dev_err(dev, "failed to get svc_ref_clk: %d\n", ret);
509                 return ret;
510         }
511
512         platform_set_drvdata(pdev, arche_pdata);
513
514         arche_pdata->num_apbs = of_get_child_count(np);
515         dev_dbg(dev, "Number of APB's available - %d\n", arche_pdata->num_apbs);
516
517         arche_pdata->wake_detect_gpio = of_get_named_gpio(np,
518                                                           "svc,wake-detect-gpio",
519                                                           0);
520         if (arche_pdata->wake_detect_gpio < 0) {
521                 dev_err(dev, "failed to get wake detect gpio\n");
522                 return arche_pdata->wake_detect_gpio;
523         }
524
525         ret = devm_gpio_request(dev, arche_pdata->wake_detect_gpio,
526                                 "wake detect");
527         if (ret) {
528                 dev_err(dev, "Failed requesting wake_detect gpio %d\n",
529                                 arche_pdata->wake_detect_gpio);
530                 return ret;
531         }
532
533         arche_platform_set_wake_detect_state(arche_pdata, WD_STATE_IDLE);
534
535         arche_pdata->dev = &pdev->dev;
536
537         spin_lock_init(&arche_pdata->wake_lock);
538         mutex_init(&arche_pdata->platform_state_mutex);
539         arche_pdata->wake_detect_irq =
540                 gpio_to_irq(arche_pdata->wake_detect_gpio);
541
542         ret = devm_request_threaded_irq(dev, arche_pdata->wake_detect_irq,
543                                         arche_platform_wd_irq,
544                                         arche_platform_wd_irq_thread,
545                                         IRQF_TRIGGER_FALLING |
546                                         IRQF_TRIGGER_RISING | IRQF_ONESHOT,
547                                         dev_name(dev), arche_pdata);
548         if (ret) {
549                 dev_err(dev, "failed to request wake detect IRQ %d\n", ret);
550                 return ret;
551         }
552         disable_irq(arche_pdata->wake_detect_irq);
553
554         ret = device_create_file(dev, &dev_attr_state);
555         if (ret) {
556                 dev_err(dev, "failed to create state file in sysfs\n");
557                 return ret;
558         }
559
560         ret = of_platform_populate(np, NULL, NULL, dev);
561         if (ret) {
562                 dev_err(dev, "failed to populate child nodes %d\n", ret);
563                 goto err_device_remove;
564         }
565
566         arche_pdata->pm_notifier.notifier_call = arche_platform_pm_notifier;
567         ret = register_pm_notifier(&arche_pdata->pm_notifier);
568
569         if (ret) {
570                 dev_err(dev, "failed to register pm notifier %d\n", ret);
571                 goto err_device_remove;
572         }
573
574         /* Explicitly power off if requested */
575         if (!of_property_read_bool(pdev->dev.of_node, "arche,init-off")) {
576                 mutex_lock(&arche_pdata->platform_state_mutex);
577                 ret = arche_platform_coldboot_seq(arche_pdata);
578                 if (ret) {
579                         dev_err(dev, "Failed to cold boot svc %d\n", ret);
580                         goto err_coldboot;
581                 }
582                 arche_platform_wd_irq_en(arche_pdata);
583                 mutex_unlock(&arche_pdata->platform_state_mutex);
584         }
585
586         dev_info(dev, "Device registered successfully\n");
587         return 0;
588
589 err_coldboot:
590         mutex_unlock(&arche_pdata->platform_state_mutex);
591 err_device_remove:
592         device_remove_file(&pdev->dev, &dev_attr_state);
593         return ret;
594 }
595
596 static int arche_remove_child(struct device *dev, void *unused)
597 {
598         struct platform_device *pdev = to_platform_device(dev);
599
600         platform_device_unregister(pdev);
601
602         return 0;
603 }
604
605 static int arche_platform_remove(struct platform_device *pdev)
606 {
607         struct arche_platform_drvdata *arche_pdata = platform_get_drvdata(pdev);
608
609         unregister_pm_notifier(&arche_pdata->pm_notifier);
610         device_remove_file(&pdev->dev, &dev_attr_state);
611         device_for_each_child(&pdev->dev, NULL, arche_remove_child);
612         arche_platform_poweroff_seq(arche_pdata);
613
614         if (usb3613_hub_mode_ctrl(false))
615                 dev_warn(arche_pdata->dev, "failed to control hub device\n");
616                 /* TODO: Should we do anything more here ?? */
617         return 0;
618 }
619
620 static __maybe_unused int arche_platform_suspend(struct device *dev)
621 {
622         /*
623          * If timing profile premits, we may shutdown bridge
624          * completely
625          *
626          * TODO: sequence ??
627          *
628          * Also, need to make sure we meet precondition for unipro suspend
629          * Precondition: Definition ???
630          */
631         return 0;
632 }
633
634 static __maybe_unused int arche_platform_resume(struct device *dev)
635 {
636         /*
637          * Atleast for ES2 we have to meet the delay requirement between
638          * unipro switch and AP bridge init, depending on whether bridge is in
639          * OFF state or standby state.
640          *
641          * Based on whether bridge is in standby or OFF state we may have to
642          * assert multiple signals. Please refer to WDM spec, for more info.
643          *
644          */
645         return 0;
646 }
647
648 static void arche_platform_shutdown(struct platform_device *pdev)
649 {
650         struct arche_platform_drvdata *arche_pdata = platform_get_drvdata(pdev);
651
652         arche_platform_poweroff_seq(arche_pdata);
653
654         usb3613_hub_mode_ctrl(false);
655 }
656
657 static SIMPLE_DEV_PM_OPS(arche_platform_pm_ops,
658                         arche_platform_suspend,
659                         arche_platform_resume);
660
661 static const struct of_device_id arche_platform_of_match[] = {
662         /* Use PID/VID of SVC device */
663         { .compatible = "google,arche-platform", },
664         { },
665 };
666
667 static const struct of_device_id arche_combined_id[] = {
668         /* Use PID/VID of SVC device */
669         { .compatible = "google,arche-platform", },
670         { .compatible = "usbffff,2", },
671         { },
672 };
673 MODULE_DEVICE_TABLE(of, arche_combined_id);
674
675 static struct platform_driver arche_platform_device_driver = {
676         .probe          = arche_platform_probe,
677         .remove         = arche_platform_remove,
678         .shutdown       = arche_platform_shutdown,
679         .driver         = {
680                 .name   = "arche-platform-ctrl",
681                 .pm     = &arche_platform_pm_ops,
682                 .of_match_table = arche_platform_of_match,
683         }
684 };
685
686 static int __init arche_init(void)
687 {
688         int retval;
689
690         retval = platform_driver_register(&arche_platform_device_driver);
691         if (retval)
692                 return retval;
693
694         retval = arche_apb_init();
695         if (retval)
696                 platform_driver_unregister(&arche_platform_device_driver);
697
698         return retval;
699 }
700 module_init(arche_init);
701
702 static void __exit arche_exit(void)
703 {
704         arche_apb_exit();
705         platform_driver_unregister(&arche_platform_device_driver);
706 }
707 module_exit(arche_exit);
708
709 MODULE_LICENSE("GPL v2");
710 MODULE_AUTHOR("Vaibhav Hiremath <vaibhav.hiremath@linaro.org>");
711 MODULE_DESCRIPTION("Arche Platform Driver");