1515 *
1616 */
1717#include <linux/err.h>
18+ #include <linux/gpio.h>
1819#include <linux/io.h>
1920#include <linux/module.h>
2021#include <linux/pm_runtime.h>
2122#include <linux/slab.h>
2223#include <linux/sysfs.h>
2324#include "common.h"
25+ #include "rcar2.h"
2426
2527/*
2628 * image of renesas_usbhs
@@ -284,6 +286,8 @@ static void usbhsc_set_buswait(struct usbhs_priv *priv)
284286/*
285287 * platform default param
286288 */
289+
290+ /* commonly used on old SH-Mobile SoCs */
287291static u32 usbhsc_default_pipe_type [] = {
288292 USB_ENDPOINT_XFER_CONTROL ,
289293 USB_ENDPOINT_XFER_ISOC ,
@@ -297,6 +301,26 @@ static u32 usbhsc_default_pipe_type[] = {
297301 USB_ENDPOINT_XFER_INT ,
298302};
299303
304+ /* commonly used on newer SH-Mobile and R-Car SoCs */
305+ static u32 usbhsc_new_pipe_type [] = {
306+ USB_ENDPOINT_XFER_CONTROL ,
307+ USB_ENDPOINT_XFER_ISOC ,
308+ USB_ENDPOINT_XFER_ISOC ,
309+ USB_ENDPOINT_XFER_BULK ,
310+ USB_ENDPOINT_XFER_BULK ,
311+ USB_ENDPOINT_XFER_BULK ,
312+ USB_ENDPOINT_XFER_INT ,
313+ USB_ENDPOINT_XFER_INT ,
314+ USB_ENDPOINT_XFER_INT ,
315+ USB_ENDPOINT_XFER_BULK ,
316+ USB_ENDPOINT_XFER_BULK ,
317+ USB_ENDPOINT_XFER_BULK ,
318+ USB_ENDPOINT_XFER_BULK ,
319+ USB_ENDPOINT_XFER_BULK ,
320+ USB_ENDPOINT_XFER_BULK ,
321+ USB_ENDPOINT_XFER_BULK ,
322+ };
323+
300324/*
301325 * power control
302326 */
@@ -423,8 +447,7 @@ static int usbhs_probe(struct platform_device *pdev)
423447 int ret ;
424448
425449 /* check platform information */
426- if (!info ||
427- !info -> platform_callback .get_id ) {
450+ if (!info ) {
428451 dev_err (& pdev -> dev , "no platform information\n" );
429452 return - EINVAL ;
430453 }
@@ -451,13 +474,32 @@ static int usbhs_probe(struct platform_device *pdev)
451474 /*
452475 * care platform info
453476 */
454- memcpy (& priv -> pfunc ,
455- & info -> platform_callback ,
456- sizeof (struct renesas_usbhs_platform_callback ));
477+
457478 memcpy (& priv -> dparam ,
458479 & info -> driver_param ,
459480 sizeof (struct renesas_usbhs_driver_param ));
460481
482+ switch (priv -> dparam .type ) {
483+ case USBHS_TYPE_R8A7790 :
484+ case USBHS_TYPE_R8A7791 :
485+ priv -> pfunc = usbhs_rcar2_ops ;
486+ if (!priv -> dparam .pipe_type ) {
487+ priv -> dparam .pipe_type = usbhsc_new_pipe_type ;
488+ priv -> dparam .pipe_size =
489+ ARRAY_SIZE (usbhsc_new_pipe_type );
490+ }
491+ break ;
492+ default :
493+ if (!info -> platform_callback .get_id ) {
494+ dev_err (& pdev -> dev , "no platform callbacks" );
495+ return - EINVAL ;
496+ }
497+ memcpy (& priv -> pfunc ,
498+ & info -> platform_callback ,
499+ sizeof (struct renesas_usbhs_platform_callback ));
500+ break ;
501+ }
502+
461503 /* set driver callback functions for platform */
462504 dfunc = & info -> driver_callback ;
463505 dfunc -> notify_hotplug = usbhsc_drvcllbck_notify_hotplug ;
@@ -507,6 +549,20 @@ static int usbhs_probe(struct platform_device *pdev)
507549 */
508550 usbhs_sys_clock_ctrl (priv , 0 );
509551
552+ /* check GPIO determining if USB function should be enabled */
553+ if (priv -> dparam .enable_gpio ) {
554+ gpio_request_one (priv -> dparam .enable_gpio , GPIOF_IN , NULL );
555+ ret = !gpio_get_value (priv -> dparam .enable_gpio );
556+ gpio_free (priv -> dparam .enable_gpio );
557+ if (ret ) {
558+ dev_warn (& pdev -> dev ,
559+ "USB function not selected (GPIO %d)\n" ,
560+ priv -> dparam .enable_gpio );
561+ ret = - ENOTSUPP ;
562+ goto probe_end_mod_exit ;
563+ }
564+ }
565+
510566 /*
511567 * platform call
512568 *
0 commit comments