[PATCH 11/11] staging: typec: tcpm: Switch to PORT_RESET instead of SNK_UNATTACHED

2017-08-26 Thread Badhri Jagan Sridharan
When VBUS is not discovered within PD_T_PS_SOURCE_ON although Rp
is detected on CC, TCPM switches the port to SNK_UNATTACHED
state. SNK_UNATTACHED, however does not force TYPEC_CC_OPEN which
makes the partner(source) to think that it is connected.

To overcome this issue, force the port into PORT_RESET state
to make sure the CC lines are open.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 9e0111dea7c4..47b8fec5ea36 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -2380,7 +2380,7 @@ static void run_state_machine(struct tcpm_port *port)
   0);
else
/* Wait for VBUS, but not forever */
-   tcpm_set_state(port, SNK_UNATTACHED, PD_T_PS_SOURCE_ON);
+   tcpm_set_state(port, PORT_RESET, PD_T_PS_SOURCE_ON);
break;
 
case SRC_TRY:
-- 
2.14.1.342.g6490525c54-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/11] staging: typec: tcpm: Do not send PING msgs in TCPM

2017-08-26 Thread Badhri Jagan Sridharan
PING messages are used to monitor the connect/disconnect.
However, when PD is carried over CC, so this is not required.

Also, the spec does not clearly say if PD is possible when
Type-c is connected to Type-A/B. So, removing sending
PING messages altogether.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index a7da609006f5..9e0111dea7c4 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -2335,14 +2335,11 @@ static void run_state_machine(struct tcpm_port *port)
 * - The system is not operating in PD mode
 * or
 * - Both partners are connected using a Type-C connector
-*   XXX How do we know that ?
+*
+* There is no actual need to send PD messages since the local
+* port type-c and the spec does not clearly say whether PD is
+* possible when type-c is connected to Type-A/B
 */
-   if (port->pwr_opmode == TYPEC_PWR_MODE_PD &&
-   !port->op_vsafe5v) {
-   tcpm_pd_send_control(port, PD_CTRL_PING);
-   tcpm_set_state_cond(port, SRC_READY,
-   PD_T_SOURCE_ACTIVITY);
-   }
break;
case SRC_WAIT_NEW_CAPABILITIES:
/* Nothing to do... */
-- 
2.14.1.342.g6490525c54-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/11] staging: typec: tcpm: add cc change handling in src states

2017-08-26 Thread Badhri Jagan Sridharan
In the case that the lower layer driver reports a cc change directly
from SINK state to SOURCE state, TCPM doesn't handle these cc change
in SRC_SEND_CAPABILITIES, SRC_READY states. And with SRC_ATTACHED
state, the change is not handled as the port is still considered
connected.

[49606.131672] state change DRP_TOGGLING -> SRC_ATTACH_WAIT
[49606.131701] pending state change SRC_ATTACH_WAIT -> SRC_ATTACHED @
200 ms
[49606.329952] state change SRC_ATTACH_WAIT -> SRC_ATTACHED [delayed 200
ms]
[49606.329978] polarity 0
[49606.329989] Requesting mux mode 1, config 0, polarity 0
[49606.349416] vbus:=1 charge=0
[49606.372274] pending state change SRC_ATTACHED -> SRC_UNATTACHED @ 480
ms
[49606.372431] VBUS on
[49606.372488] state change SRC_ATTACHED -> SRC_STARTUP
...
(the lower layer driver reports a direct change from source to sink)
[49606.536927] pending state change SRC_SEND_CAPABILITIES ->
SRC_SEND_CAPABILITIES @ 150 ms
[49606.547244] CC1: 2 -> 5, CC2: 0 -> 0 [state SRC_SEND_CAPABILITIES,
polarity 0, connected]

This can happen when the lower layer driver and/or the hardware
handles a portion of the Type-C state machine work, and quietly goes
through the unattached state.

Originally-from: Yueyao Zhu 
Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 645f43ee83df..1f6827f32b29 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -2874,10 +2874,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, 
enum typec_cc_status cc1,
tcpm_set_state(port, SRC_ATTACH_WAIT, 0);
break;
case SRC_ATTACHED:
-   if (tcpm_port_is_disconnected(port))
+   case SRC_SEND_CAPABILITIES:
+   case SRC_READY:
+   if (tcpm_port_is_disconnected(port) ||
+   !tcpm_port_is_source(port))
tcpm_set_state(port, SRC_UNATTACHED, 0);
break;
-
case SNK_UNATTACHED:
if (tcpm_port_is_sink(port))
tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
-- 
2.14.1.342.g6490525c54-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/11 v2] staging: typec: tcpm: Follow Try.SRC exit requirements

2017-08-26 Thread Badhri Jagan Sridharan
According to spec:
" 4.5.2.2.9.2 Exiting from Try.SRC State:
The port shall transition to Attached.SRC when the SRC.Rd
state is detected on exactly one of the CC1 or CC2 pins for
at least tPDDebounce. The port shall transition to
TryWait.SNK after tDRPTry and the SRC.Rd state has not been
detected."

Signed-off-by: Badhri Jagan Sridharan 
---
hangelog since v1:
- Corrected  tag

 drivers/staging/typec/tcpm.c | 33 -
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 7eed04698ebe..fc179bdea7e4 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -112,6 +112,7 @@
S(SRC_TRYWAIT_UNATTACHED),  \
\
S(SRC_TRY), \
+   S(SRC_TRY_WAIT),\
S(SRC_TRY_DEBOUNCE),\
S(SNK_TRYWAIT), \
S(SNK_TRYWAIT_DEBOUNCE),\
@@ -2158,6 +2159,7 @@ static void run_state_machine(struct tcpm_port *port)
 {
int ret;
enum typec_pwr_opmode opmode;
+   unsigned int msecs;
 
port->enter_state = port->state;
switch (port->state) {
@@ -2379,7 +2381,22 @@ static void run_state_machine(struct tcpm_port *port)
case SRC_TRY:
port->try_src_count++;
tcpm_set_cc(port, tcpm_rp_cc(port));
-   tcpm_set_state(port, SNK_TRYWAIT, PD_T_DRP_TRY);
+   port->max_wait = 0;
+   tcpm_set_state(port, SRC_TRY_WAIT, 0);
+   break;
+   case SRC_TRY_WAIT:
+   if (port->max_wait == 0) {
+   port->max_wait = jiffies +
+msecs_to_jiffies(PD_T_DRP_TRY);
+   msecs = PD_T_DRP_TRY;
+   } else {
+   if (time_is_after_jiffies(port->max_wait))
+   msecs = jiffies_to_msecs(port->max_wait -
+jiffies);
+   else
+   msecs = 0;
+   }
+   tcpm_set_state(port, SNK_TRYWAIT, msecs);
break;
case SRC_TRY_DEBOUNCE:
tcpm_set_state(port, SRC_ATTACHED, PD_T_PD_DEBOUNCE);
@@ -2935,12 +2952,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, 
enum typec_cc_status cc1,
tcpm_set_state(port, SRC_TRYWAIT, 0);
}
break;
-   case SRC_TRY:
+   case SRC_TRY_WAIT:
if (tcpm_port_is_source(port))
tcpm_set_state(port, SRC_TRY_DEBOUNCE, 0);
break;
case SRC_TRY_DEBOUNCE:
-   tcpm_set_state(port, SRC_TRY, 0);
+   tcpm_set_state(port, SRC_TRY_WAIT, 0);
break;
case SNK_TRYWAIT_DEBOUNCE:
if (port->vbus_present) {
@@ -3015,7 +3032,10 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
case SNK_TRYWAIT:
tcpm_set_state(port, SNK_TRYWAIT_VBUS, 0);
break;
-
+   case SRC_TRY_WAIT:
+   case SRC_TRY_DEBOUNCE:
+   /* Do nothing, waiting for sink detection */
+   break;
default:
break;
}
@@ -3069,7 +3089,10 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
case PORT_RESET_WAIT_OFF:
tcpm_set_state(port, tcpm_default_state(port), 0);
break;
-
+   case SRC_TRY_WAIT:
+   case SRC_TRY_DEBOUNCE:
+   /* Do nothing, waiting for sink detection */
+   break;
default:
if (port->pwr_role == TYPEC_SINK &&
port->attached)
-- 
2.14.1.342.g6490525c54-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/11 v2] staging: typec: tcpm: Prevent TCPM from looping in SRC_TRYWAIT

2017-08-26 Thread Badhri Jagan Sridharan
According to the spec the following is the condition
for exiting TryWait.SRC:

"The port shall transition to Attached.SRC when V BUS is at vSafe0V
and the SRC.Rd state is detected on exactly one of the CC pins for at
least tCCDebounce. The port shall transition to Unattached.SNK after
tDRPTry if neither of the CC1 or CC2 pins are in the SRC.Rd state"

TCPM at present keeps re-entering the SRC_TRYWAIT and keeps restarting
tDRPTry if the CC presents Rp and disconnects within tCCDebounce.

For example:
[  447.164308] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms
[  447.164386] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.164406] state change SRC_TRYWAIT -> SRC_TRYWAIT
[  447.164573] cc:=3
[  447.191408] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 
ms
[  447.191478] CC1: 0 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.207261] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
connected]
[  447.207306] state change SRC_TRYWAIT -> SRC_TRYWAIT
[  447.207485] cc:=3
[  447.237283] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms
[  447.237357] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.237379] state change SRC_TRYWAIT -> SRC_TRYWAIT
[  447.237532] cc:=3
[  447.263219] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 
ms
[  447.263289] CC1: 0 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.280926] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
connected]
[  447.280970] state change SRC_TRYWAIT -> SRC_TRYWAIT
[  447.281158] cc:=3
[  447.307767] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms
[  447.307838] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.307858] state change SRC_TRYWAIT -> SRC_TRYWAIT

In TCPM, tDRPTry is set tp 100ms (min 75ms and max 150ms)
and tCCdebounce is set to 200ms (min 100ms and max 200ms).
To overcome the issue, record the time at which the port
enters TryWait.SRC(SRC_TRYWAIT) and re-enter SRC_TRYWAIT
only when CC keeps debouncing within tDRPTry.

Signed-off-by: Badhri Jagan Sridharan 
---
Changelog since v1:
- Corrected  tag

 drivers/staging/typec/tcpm.c | 45 
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 1219e3bc13ef..d45ffa8f2cfd 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,7 @@
S(SNK_TRY), \
S(SNK_TRY_WAIT),\
S(SRC_TRYWAIT), \
+   S(SRC_TRYWAIT_DEBOUNCE),\
S(SRC_TRYWAIT_UNATTACHED),  \
\
S(SRC_TRY), \
@@ -284,6 +286,9 @@ struct tcpm_port {
struct typec_altmode *partner_altmode[SVID_DISCOVERY_MAX];
struct typec_altmode *port_altmode[SVID_DISCOVERY_MAX];
 
+   /* Deadline in jiffies to exit src_try_wait state */
+   unsigned long max_wait;
+
 #ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
struct mutex logbuffer_lock;/* log buffer access lock */
@@ -2204,6 +2209,7 @@ static void run_state_machine(struct tcpm_port *port)
if (!tcpm_port_is_sink(port)) {
tcpm_set_state(port, SRC_TRYWAIT,
   PD_T_PD_DEBOUNCE);
+   port->max_wait = 0;
break;
}
/* No vbus, cc state is sink or open */
@@ -2211,11 +2217,22 @@ static void run_state_machine(struct tcpm_port *port)
break;
case SRC_TRYWAIT:
tcpm_set_cc(port, tcpm_rp_cc(port));
-   if (!port->vbus_present && tcpm_port_is_source(port))
-   tcpm_set_state(port, SRC_ATTACHED, PD_T_CC_DEBOUNCE);
-   else
+   if (port->max_wait == 0) {
+   port->max_wait = jiffies +
+msecs_to_jiffies(PD_T_DRP_TRY);
tcpm_set_state(port, SRC_TRYWAIT_UNATTACHED,
   PD_T_DRP_TRY);
+   } else {
+   if (time_is_after_jiffies(port->max_wait))
+   tcpm_set_state(port, SRC_TRYWAIT_UNATTACHED,
+  jiffies_to_msecs(port->max_wait -
+   jiffies));
+   else
+   tcpm_set_state(port, SNK_UNATTACHED, 0);
+   }
+   break;
+   case SRC_TRYWAIT_DEBOUNCE:
+   tcpm_set_state(port, SRC_ATTACHED, PD_T_CC_DEBOUNCE);
 

[PATCH 01/11 v2] staging: typec: tcpm: set port type callback

2017-08-26 Thread Badhri Jagan Sridharan
The port type callback call enquires the tcpc_dev if
the requested port type is supported. If supported, then
performs a tcpm reset if required after setting the tcpm
internal port_type variable.

Check against the tcpm port_type instead of checking
against caps.type as port_type reflects the current
configuration.

Signed-off-by: Badhri Jagan Sridharan 
---
Changelog since v1:
- Corrected  tag

 drivers/staging/typec/tcpm.c | 52 ++--
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index a911cad41a59..6c045ac9c42a 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -197,6 +197,7 @@ struct tcpm_port {
 
bool attached;
bool connected;
+   enum typec_port_type port_type;
bool vbus_present;
bool vbus_never_low;
bool vbus_source;
@@ -334,7 +335,7 @@ struct pd_rx_event {
 
 static enum tcpm_state tcpm_default_state(struct tcpm_port *port)
 {
-   if (port->typec_caps.type == TYPEC_PORT_DRP) {
+   if (port->port_type == TYPEC_PORT_DRP) {
if (port->try_role == TYPEC_SINK)
return SNK_UNATTACHED;
else if (port->try_role == TYPEC_SOURCE)
@@ -342,7 +343,7 @@ static enum tcpm_state tcpm_default_state(struct tcpm_port 
*port)
else if (port->tcpc->config->default_role == TYPEC_SINK)
return SNK_UNATTACHED;
/* Fall through to return SRC_UNATTACHED */
-   } else if (port->typec_caps.type == TYPEC_PORT_UFP) {
+   } else if (port->port_type == TYPEC_PORT_UFP) {
return SNK_UNATTACHED;
}
return SRC_UNATTACHED;
@@ -1458,7 +1459,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
tcpm_set_state(port, SOFT_RESET, 0);
break;
case PD_CTRL_DR_SWAP:
-   if (port->typec_caps.type != TYPEC_PORT_DRP) {
+   if (port->port_type != TYPEC_PORT_DRP) {
tcpm_queue_message(port, PD_MSG_CTRL_REJECT);
break;
}
@@ -1478,7 +1479,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
}
break;
case PD_CTRL_PR_SWAP:
-   if (port->typec_caps.type != TYPEC_PORT_DRP) {
+   if (port->port_type != TYPEC_PORT_DRP) {
tcpm_queue_message(port, PD_MSG_CTRL_REJECT);
break;
}
@@ -1853,7 +1854,7 @@ static bool tcpm_start_drp_toggling(struct tcpm_port 
*port)
int ret;
 
if (port->tcpc->start_drp_toggling &&
-   port->typec_caps.type == TYPEC_PORT_DRP) {
+   port->port_type == TYPEC_PORT_DRP) {
tcpm_log_force(port, "Start DRP toggling");
ret = port->tcpc->start_drp_toggling(port->tcpc,
 tcpm_rp_cc(port));
@@ -2163,7 +2164,7 @@ static void run_state_machine(struct tcpm_port *port)
break;
}
tcpm_set_cc(port, tcpm_rp_cc(port));
-   if (port->typec_caps.type == TYPEC_PORT_DRP)
+   if (port->port_type == TYPEC_PORT_DRP)
tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK);
break;
case SRC_ATTACH_WAIT:
@@ -2320,7 +2321,7 @@ static void run_state_machine(struct tcpm_port *port)
break;
}
tcpm_set_cc(port, TYPEC_CC_RD);
-   if (port->typec_caps.type == TYPEC_PORT_DRP)
+   if (port->port_type == TYPEC_PORT_DRP)
tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
break;
case SNK_ATTACH_WAIT:
@@ -2411,7 +2412,7 @@ static void run_state_machine(struct tcpm_port *port)
 * see USB power delivery specification, section 8.3.3.6.1.5.1).
 */
tcpm_set_state(port, hard_reset_state(port),
-  port->typec_caps.type == TYPEC_PORT_DRP ?
+  port->port_type == TYPEC_PORT_DRP ?
PD_T_DB_DETECT : PD_T_NO_RESPONSE);
break;
case SNK_DISCOVERY_DEBOUNCE:
@@ -3167,7 +3168,7 @@ static int tcpm_dr_set(const struct typec_capability *cap,
mutex_lock(&port->swap_lock);
mutex_lock(&port->lock);
 
-   if (port->typec_caps.type != TYPEC_PORT_DRP) {
+   if (port->port_type != TYPEC_PORT_DRP) {
ret = -EINVAL;
goto port_unlock;
}
@@ -3235,7 +3236,7 @@ static int tcpm_pr_set(const struct typec_capability *cap,
mutex_lock(&port->swap_lock);
mutex_lock(&port->lock);
 
-   if (port->typec_caps.type != TYPEC_PORT_DRP) {
+   if (port->port_type != TYPEC_PORT_DRP) {
ret = -EINVAL;

[PATCH 07/11] staging: typec: tcpm: Consider port_type while determining unattached_state

2017-08-26 Thread Badhri Jagan Sridharan
While performing PORT_RESET, upon receiving the cc disconnect
signal from the underlaying tcpc device, TCPM transitions into
unattached state. Consider, the current type of port while determining
the unattached state.

In the below logs, although the port_type was set to sink, TCPM
transitioned into SRC_UNATTACHED.

[  762.290654] state change SRC_READY -> PORT_RESET
[  762.324531] Setting voltage/current limit 0 mV 0 mA
[  762.327912] polarity 0
[  762.334864] cc:=0
[  762.347193] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms
[  762.347200] VBUS off
[  762.347203] CC1: 2 -> 0, CC2: 0 -> 0 [state PORT_RESET, polarity 0, 
disconnected]
[  762.347206] state change PORT_RESET -> SRC_UNATTACHED

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 0ae0a5c7..645f43ee83df 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -2117,10 +2117,16 @@ static inline enum tcpm_state ready_state(struct 
tcpm_port *port)
 
 static inline enum tcpm_state unattached_state(struct tcpm_port *port)
 {
-   if (port->pwr_role == TYPEC_SOURCE)
+   if (port->port_type == TYPEC_PORT_DRP) {
+   if (port->pwr_role == TYPEC_SOURCE)
+   return SRC_UNATTACHED;
+   else
+   return SNK_UNATTACHED;
+   } else if (port->port_type == TYPEC_PORT_DFP) {
return SRC_UNATTACHED;
-   else
-   return SNK_UNATTACHED;
+   }
+
+   return SNK_UNATTACHED;
 }
 
 static void tcpm_check_send_discover(struct tcpm_port *port)
-- 
2.14.1.342.g6490525c54-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: lustre: constify cl_lock_operations

2017-08-26 Thread Arvind Yadav
cl_lock_operations are not supposed to change at runtime.
cl_lock_slice_add is working with const cl_lock_operations.
So mark the non-const cl_lock_operations structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/staging/lustre/lustre/obdecho/echo_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c 
b/drivers/staging/lustre/lustre/obdecho/echo_client.c
index 1c4a8fe..b3fbc3c 100644
--- a/drivers/staging/lustre/lustre/obdecho/echo_client.c
+++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c
@@ -319,7 +319,7 @@ static void echo_lock_fini(const struct lu_env *env,
kmem_cache_free(echo_lock_kmem, ecl);
 }
 
-static struct cl_lock_operations echo_lock_ops = {
+static const struct cl_lock_operations echo_lock_ops = {
.clo_fini  = echo_lock_fini,
 };
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: atomisp: constify v4l2_subdev_sensor_ops

2017-08-26 Thread Arvind Yadav
v4l2_subdev_sensor_ops are not supposed to change at runtime.
v4l2_subdev_sensor_ops are working with const 'sensor' field of
sturct v4l2_subdev_ops. So mark the non-const v4l2_subdev_sensor_ops
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/staging/media/atomisp/i2c/mt9m114.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/atomisp/i2c/mt9m114.c 
b/drivers/staging/media/atomisp/i2c/mt9m114.c
index 3fa9153..2c9b752 100644
--- a/drivers/staging/media/atomisp/i2c/mt9m114.c
+++ b/drivers/staging/media/atomisp/i2c/mt9m114.c
@@ -1806,7 +1806,7 @@ static const struct v4l2_subdev_video_ops 
mt9m114_video_ops = {
.g_frame_interval = mt9m114_g_frame_interval,
 };
 
-static struct v4l2_subdev_sensor_ops mt9m114_sensor_ops = {
+static const struct v4l2_subdev_sensor_ops mt9m114_sensor_ops = {
.g_skip_frames  = mt9m114_g_skip_frames,
 };
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 6/6] staging: usb: tcpm: Comply with TryWait.SNK State

2017-08-26 Thread Badhri Jagan Sridharan
According to the spec:
"4.5.2.2.10.2 Exiting from TryWait.SNK State
The port shall transition to Attached.SNK after tCCDebounce if or when VBUS
is detected. Note the Source may initiate USB PD communications which will
cause brief periods of the SNK.Open state on both the CC1 and CC2 pins,
but this event will not exceed tPDDebounce. The port shall transition to
Unattached.SNK when the state of both of the CC1 and CC2 pins is SNK.Open
for at least tPDDebounce."

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 58 +++-
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index fc179bdea7e4..0ae0a5c7 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -2403,26 +2403,24 @@ static void run_state_machine(struct tcpm_port *port)
break;
case SNK_TRYWAIT:
tcpm_set_cc(port, TYPEC_CC_RD);
-   tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, PD_T_CC_DEBOUNCE);
+   tcpm_set_state(port, SNK_TRYWAIT_VBUS, PD_T_CC_DEBOUNCE);
break;
-   case SNK_TRYWAIT_DEBOUNCE:
-   if (port->vbus_present) {
+   case SNK_TRYWAIT_VBUS:
+   /*
+* TCPM stays in this state indefinitely until VBUS
+* is detected as long as Rp is not detected for
+* more than a time period of tPDDebounce.
+*/
+   if (port->vbus_present && tcpm_port_is_sink(port)) {
tcpm_set_state(port, SNK_ATTACHED, 0);
break;
}
-   if (tcpm_port_is_disconnected(port)) {
-   tcpm_set_state(port, SNK_UNATTACHED,
-  PD_T_PD_DEBOUNCE);
-   break;
-   }
-   if (tcpm_port_is_source(port))
-   tcpm_set_state(port, SRC_ATTACHED, 0);
-   /* XXX Are we supposed to stay in this state ? */
+   if (!tcpm_port_is_sink(port))
+   tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, 0);
break;
-   case SNK_TRYWAIT_VBUS:
-   tcpm_set_state(port, SNK_ATTACHED, PD_T_CC_DEBOUNCE);
+   case SNK_TRYWAIT_DEBOUNCE:
+   tcpm_set_state(port, SNK_UNATTACHED, PD_T_PD_DEBOUNCE);
break;
-
case SNK_ATTACHED:
ret = tcpm_snk_attach(port);
if (ret < 0)
@@ -2960,19 +2958,16 @@ static void _tcpm_cc_change(struct tcpm_port *port, 
enum typec_cc_status cc1,
tcpm_set_state(port, SRC_TRY_WAIT, 0);
break;
case SNK_TRYWAIT_DEBOUNCE:
-   if (port->vbus_present) {
-   tcpm_set_state(port, SNK_ATTACHED, 0);
-   break;
-   }
-   if (tcpm_port_is_source(port)) {
-   tcpm_set_state(port, SRC_ATTACHED, 0);
-   break;
-   }
-   if (tcpm_port_is_disconnected(port) &&
-   port->delayed_state != SNK_UNATTACHED)
+   if (tcpm_port_is_sink(port))
+   tcpm_set_state(port, SNK_TRYWAIT_VBUS, 0);
+   break;
+   case SNK_TRYWAIT_VBUS:
+   if (!tcpm_port_is_sink(port))
tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, 0);
break;
-
+   case SNK_TRYWAIT:
+   /* Do nothing, waiting for tCCDebounce */
+   break;
case PR_SWAP_SNK_SRC_SINK_OFF:
case PR_SWAP_SRC_SNK_TRANSITION_OFF:
case PR_SWAP_SRC_SNK_SOURCE_OFF:
@@ -3030,7 +3025,14 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
/* Do nothing, waiting for PD_DEBOUNCE to do be done */
break;
case SNK_TRYWAIT:
-   tcpm_set_state(port, SNK_TRYWAIT_VBUS, 0);
+   /* Do nothing, waiting for tCCDebounce */
+   break;
+   case SNK_TRYWAIT_VBUS:
+   if (tcpm_port_is_sink(port))
+   tcpm_set_state(port, SNK_ATTACHED, 0);
+   break;
+   case SNK_TRYWAIT_DEBOUNCE:
+   /* Do nothing, waiting for Rp */
break;
case SRC_TRY_WAIT:
case SRC_TRY_DEBOUNCE:
@@ -3067,10 +3069,10 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
case SNK_TRY_WAIT_DEBOUNCE:
/* Do nothing, waiting for PD_DEBOUNCE to do be done */
break;
+   case SNK_TRYWAIT:
case SNK_TRYWAIT_VBUS:
-   tcpm_set_state(port, SNK_TRYWAIT, 0);
+   case SNK_TRYWAIT_DEBOUNCE:
break;
-
case SNK_ATTACH_WAIT:
tcpm_set_state(port, SNK_UNATTACHED, 0);
break;
-- 
2.14.1.342.g6490525c54-goog

___
devel mailin

[PATCH 5/6] staging: usb: tcpm: usb: typec: tcpm: Follow Try.SRC exit requirements

2017-08-26 Thread Badhri Jagan Sridharan
According to spec:
" 4.5.2.2.9.2 Exiting from Try.SRC State:
The port shall transition to Attached.SRC when the SRC.Rd
state is detected on exactly one of the CC1 or CC2 pins for
at least tPDDebounce. The port shall transition to
TryWait.SNK after tDRPTry and the SRC.Rd state has not been
detected."

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 33 -
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 7eed04698ebe..fc179bdea7e4 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -112,6 +112,7 @@
S(SRC_TRYWAIT_UNATTACHED),  \
\
S(SRC_TRY), \
+   S(SRC_TRY_WAIT),\
S(SRC_TRY_DEBOUNCE),\
S(SNK_TRYWAIT), \
S(SNK_TRYWAIT_DEBOUNCE),\
@@ -2158,6 +2159,7 @@ static void run_state_machine(struct tcpm_port *port)
 {
int ret;
enum typec_pwr_opmode opmode;
+   unsigned int msecs;
 
port->enter_state = port->state;
switch (port->state) {
@@ -2379,7 +2381,22 @@ static void run_state_machine(struct tcpm_port *port)
case SRC_TRY:
port->try_src_count++;
tcpm_set_cc(port, tcpm_rp_cc(port));
-   tcpm_set_state(port, SNK_TRYWAIT, PD_T_DRP_TRY);
+   port->max_wait = 0;
+   tcpm_set_state(port, SRC_TRY_WAIT, 0);
+   break;
+   case SRC_TRY_WAIT:
+   if (port->max_wait == 0) {
+   port->max_wait = jiffies +
+msecs_to_jiffies(PD_T_DRP_TRY);
+   msecs = PD_T_DRP_TRY;
+   } else {
+   if (time_is_after_jiffies(port->max_wait))
+   msecs = jiffies_to_msecs(port->max_wait -
+jiffies);
+   else
+   msecs = 0;
+   }
+   tcpm_set_state(port, SNK_TRYWAIT, msecs);
break;
case SRC_TRY_DEBOUNCE:
tcpm_set_state(port, SRC_ATTACHED, PD_T_PD_DEBOUNCE);
@@ -2935,12 +2952,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, 
enum typec_cc_status cc1,
tcpm_set_state(port, SRC_TRYWAIT, 0);
}
break;
-   case SRC_TRY:
+   case SRC_TRY_WAIT:
if (tcpm_port_is_source(port))
tcpm_set_state(port, SRC_TRY_DEBOUNCE, 0);
break;
case SRC_TRY_DEBOUNCE:
-   tcpm_set_state(port, SRC_TRY, 0);
+   tcpm_set_state(port, SRC_TRY_WAIT, 0);
break;
case SNK_TRYWAIT_DEBOUNCE:
if (port->vbus_present) {
@@ -3015,7 +3032,10 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
case SNK_TRYWAIT:
tcpm_set_state(port, SNK_TRYWAIT_VBUS, 0);
break;
-
+   case SRC_TRY_WAIT:
+   case SRC_TRY_DEBOUNCE:
+   /* Do nothing, waiting for sink detection */
+   break;
default:
break;
}
@@ -3069,7 +3089,10 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
case PORT_RESET_WAIT_OFF:
tcpm_set_state(port, tcpm_default_state(port), 0);
break;
-
+   case SRC_TRY_WAIT:
+   case SRC_TRY_DEBOUNCE:
+   /* Do nothing, waiting for sink detection */
+   break;
default:
if (port->pwr_role == TYPEC_SINK &&
port->attached)
-- 
2.14.1.342.g6490525c54-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/6] staging: usb: tcpm: usb: type-c: tcpm: Check for Rp for tPDDebounce

2017-08-26 Thread Badhri Jagan Sridharan
According the spec, the following is the conditions for exiting Try.SNK
state:
"The port shall wait for tDRPTry and only then begin monitoring the CC1 and
CC2 pins for the SNK.Rp state. The port shall then transition to
Attached.SNK when the SNK.Rp state is detected on exactly one of the CC1
or CC2 pins for at least tPDDebounce and V BUS is detected. Alternatively,
the port shall transition to TryWait.SRC if SNK.Rp state is not detected
for tPDDebounce."

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 68 
 1 file changed, 24 insertions(+), 44 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index d45ffa8f2cfd..7eed04698ebe 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -105,6 +105,8 @@
\
S(SNK_TRY), \
S(SNK_TRY_WAIT),\
+   S(SNK_TRY_WAIT_DEBOUNCE),   \
+   S(SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS),\
S(SRC_TRYWAIT), \
S(SRC_TRYWAIT_DEBOUNCE),\
S(SRC_TRYWAIT_UNATTACHED),  \
@@ -2202,18 +2204,24 @@ static void run_state_machine(struct tcpm_port *port)
tcpm_set_state(port, SNK_TRY_WAIT, PD_T_DRP_TRY);
break;
case SNK_TRY_WAIT:
+   if (tcpm_port_is_sink(port)) {
+   tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE, 0);
+   } else {
+   tcpm_set_state(port, SRC_TRYWAIT, 0);
+   port->max_wait = 0;
+   }
+   break;
+   case SNK_TRY_WAIT_DEBOUNCE:
+   tcpm_set_state(port, SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS,
+  PD_T_PD_DEBOUNCE);
+   break;
+   case SNK_TRY_WAIT_DEBOUNCE_CHECK_VBUS:
if (port->vbus_present && tcpm_port_is_sink(port)) {
tcpm_set_state(port, SNK_ATTACHED, 0);
-   break;
-   }
-   if (!tcpm_port_is_sink(port)) {
-   tcpm_set_state(port, SRC_TRYWAIT,
-  PD_T_PD_DEBOUNCE);
+   } else {
+   tcpm_set_state(port, SRC_TRYWAIT, 0);
port->max_wait = 0;
-   break;
}
-   /* No vbus, cc state is sink or open */
-   tcpm_set_state(port, SRC_TRYWAIT_UNATTACHED, PD_T_DRP_TRYWAIT);
break;
case SRC_TRYWAIT:
tcpm_set_cc(port, tcpm_rp_cc(port));
@@ -2921,20 +2929,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, 
enum typec_cc_status cc1,
if (port->vbus_present || !tcpm_port_is_source(port))
tcpm_set_state(port, SRC_TRYWAIT, 0);
break;
-   case SNK_TRY_WAIT:
-   if (port->vbus_present && tcpm_port_is_sink(port)) {
-   tcpm_set_state(port, SNK_ATTACHED, 0);
-   break;
+   case SNK_TRY_WAIT_DEBOUNCE:
+   if (!tcpm_port_is_sink(port)) {
+   port->max_wait = 0;
+   tcpm_set_state(port, SRC_TRYWAIT, 0);
}
-   if (!tcpm_port_is_sink(port))
-   new_state = SRC_TRYWAIT;
-   else
-   new_state = SRC_TRYWAIT_UNATTACHED;
-
-   if (new_state != port->delayed_state)
-   tcpm_set_state(port, SNK_TRY_WAIT, 0);
break;
-
case SRC_TRY:
if (tcpm_port_is_source(port))
tcpm_set_state(port, SRC_TRY_DEBOUNCE, 0);
@@ -2974,8 +2974,6 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum 
typec_cc_status cc1,
 
 static void _tcpm_pd_vbus_on(struct tcpm_port *port)
 {
-   enum tcpm_state new_state;
-
tcpm_log_force(port, "VBUS on");
port->vbus_present = true;
switch (port->state) {
@@ -3011,18 +3009,8 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
case SRC_TRYWAIT_DEBOUNCE:
tcpm_set_state(port, SRC_TRYWAIT, 0);
break;
-   case SNK_TRY_WAIT:
-   if (tcpm_port_is_sink(port)) {
-   tcpm_set_state(port, SNK_ATTACHED, 0);
-   break;
-   }
-   if (!tcpm_port_is_sink(port))
-   new_state = SRC_TRYWAIT;
-   else
-   new_state = SRC_TRYWAIT_UNATTACHED;
-
-   if (new_state != port->delayed_state)
-   tcpm_set_state(port, SNK_TRY_WAIT, 0);
+   case SNK_TRY_WAIT_DEBOUNCE:
+   /* Do nothing, waiting for PD_DEBOUNCE to do be done */
break;
case SNK_TRYWAIT:
tcpm_set_state(port, SNK_TRY

[PATCH 2/6] staging: usb: typec: Check for port type for Try.SRC/Try.SNK

2017-08-26 Thread Badhri Jagan Sridharan
Enable Try.SRC or Try.SNK only when port_type is
DRP. Try.SRC or Try.SNK state machines are not
valid for SRC only or SNK only ports.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 6c045ac9c42a..1219e3bc13ef 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -328,10 +328,12 @@ struct pd_rx_event {
 (tcpm_cc_is_audio((port)->cc2) && tcpm_cc_is_open((port)->cc1)))
 
 #define tcpm_try_snk(port) \
-   ((port)->try_snk_count == 0 && (port)->try_role == TYPEC_SINK)
+   ((port)->try_snk_count == 0 && (port)->try_role == TYPEC_SINK && \
+   (port)->port_type == TYPEC_PORT_DRP)
 
 #define tcpm_try_src(port) \
-   ((port)->try_src_count == 0 && (port)->try_role == TYPEC_SOURCE)
+   ((port)->try_src_count == 0 && (port)->try_role == TYPEC_SOURCE && \
+   (port)->port_type == TYPEC_PORT_DRP)
 
 static enum tcpm_state tcpm_default_state(struct tcpm_port *port)
 {
-- 
2.14.1.342.g6490525c54-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/6] staging: usb: tcpm: usb: typec: tcpm: Prevent TCPM from looping in SRC_TRYWAIT

2017-08-26 Thread Badhri Jagan Sridharan
According to the spec the following is the condition
for exiting TryWait.SRC:

"The port shall transition to Attached.SRC when V BUS is at vSafe0V
and the SRC.Rd state is detected on exactly one of the CC pins for at
least tCCDebounce. The port shall transition to Unattached.SNK after
tDRPTry if neither of the CC1 or CC2 pins are in the SRC.Rd state"

TCPM at present keeps re-entering the SRC_TRYWAIT and keeps restarting
tDRPTry if the CC presents Rp and disconnects within tCCDebounce.

For example:
[  447.164308] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms
[  447.164386] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.164406] state change SRC_TRYWAIT -> SRC_TRYWAIT
[  447.164573] cc:=3
[  447.191408] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 
ms
[  447.191478] CC1: 0 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.207261] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
connected]
[  447.207306] state change SRC_TRYWAIT -> SRC_TRYWAIT
[  447.207485] cc:=3
[  447.237283] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms
[  447.237357] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.237379] state change SRC_TRYWAIT -> SRC_TRYWAIT
[  447.237532] cc:=3
[  447.263219] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 
ms
[  447.263289] CC1: 0 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.280926] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
connected]
[  447.280970] state change SRC_TRYWAIT -> SRC_TRYWAIT
[  447.281158] cc:=3
[  447.307767] pending state change SRC_TRYWAIT -> SRC_ATTACHED @ 200 ms
[  447.307838] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, 
disconnected]
[  447.307858] state change SRC_TRYWAIT -> SRC_TRYWAIT

In TCPM, tDRPTry is set tp 100ms (min 75ms and max 150ms)
and tCCdebounce is set to 200ms (min 100ms and max 200ms).
To overcome the issue, record the time at which the port
enters TryWait.SRC(SRC_TRYWAIT) and re-enter SRC_TRYWAIT
only when CC keeps debouncing within tDRPTry.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 45 
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 1219e3bc13ef..d45ffa8f2cfd 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,6 +106,7 @@
S(SNK_TRY), \
S(SNK_TRY_WAIT),\
S(SRC_TRYWAIT), \
+   S(SRC_TRYWAIT_DEBOUNCE),\
S(SRC_TRYWAIT_UNATTACHED),  \
\
S(SRC_TRY), \
@@ -284,6 +286,9 @@ struct tcpm_port {
struct typec_altmode *partner_altmode[SVID_DISCOVERY_MAX];
struct typec_altmode *port_altmode[SVID_DISCOVERY_MAX];
 
+   /* Deadline in jiffies to exit src_try_wait state */
+   unsigned long max_wait;
+
 #ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
struct mutex logbuffer_lock;/* log buffer access lock */
@@ -2204,6 +2209,7 @@ static void run_state_machine(struct tcpm_port *port)
if (!tcpm_port_is_sink(port)) {
tcpm_set_state(port, SRC_TRYWAIT,
   PD_T_PD_DEBOUNCE);
+   port->max_wait = 0;
break;
}
/* No vbus, cc state is sink or open */
@@ -2211,11 +2217,22 @@ static void run_state_machine(struct tcpm_port *port)
break;
case SRC_TRYWAIT:
tcpm_set_cc(port, tcpm_rp_cc(port));
-   if (!port->vbus_present && tcpm_port_is_source(port))
-   tcpm_set_state(port, SRC_ATTACHED, PD_T_CC_DEBOUNCE);
-   else
+   if (port->max_wait == 0) {
+   port->max_wait = jiffies +
+msecs_to_jiffies(PD_T_DRP_TRY);
tcpm_set_state(port, SRC_TRYWAIT_UNATTACHED,
   PD_T_DRP_TRY);
+   } else {
+   if (time_is_after_jiffies(port->max_wait))
+   tcpm_set_state(port, SRC_TRYWAIT_UNATTACHED,
+  jiffies_to_msecs(port->max_wait -
+   jiffies));
+   else
+   tcpm_set_state(port, SNK_UNATTACHED, 0);
+   }
+   break;
+   case SRC_TRYWAIT_DEBOUNCE:
+   tcpm_set_state(port, SRC_ATTACHED, PD_T_CC_DEBOUNCE);
break;
case SRC_TRYWAIT_UNA

[PATCH 1/6] staging: usb: typec: tcpm set port type callback

2017-08-26 Thread Badhri Jagan Sridharan
The port type callback call enquires the tcpc_dev if
the requested port type is supported. If supported, then
performs a tcpm reset if required after setting the tcpm
internal port_type variable.

Check against the tcpm port_type instead of checking
against caps.type as port_type reflects the current
configuration.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/staging/typec/tcpm.c | 52 ++--
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index a911cad41a59..6c045ac9c42a 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -197,6 +197,7 @@ struct tcpm_port {
 
bool attached;
bool connected;
+   enum typec_port_type port_type;
bool vbus_present;
bool vbus_never_low;
bool vbus_source;
@@ -334,7 +335,7 @@ struct pd_rx_event {
 
 static enum tcpm_state tcpm_default_state(struct tcpm_port *port)
 {
-   if (port->typec_caps.type == TYPEC_PORT_DRP) {
+   if (port->port_type == TYPEC_PORT_DRP) {
if (port->try_role == TYPEC_SINK)
return SNK_UNATTACHED;
else if (port->try_role == TYPEC_SOURCE)
@@ -342,7 +343,7 @@ static enum tcpm_state tcpm_default_state(struct tcpm_port 
*port)
else if (port->tcpc->config->default_role == TYPEC_SINK)
return SNK_UNATTACHED;
/* Fall through to return SRC_UNATTACHED */
-   } else if (port->typec_caps.type == TYPEC_PORT_UFP) {
+   } else if (port->port_type == TYPEC_PORT_UFP) {
return SNK_UNATTACHED;
}
return SRC_UNATTACHED;
@@ -1458,7 +1459,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
tcpm_set_state(port, SOFT_RESET, 0);
break;
case PD_CTRL_DR_SWAP:
-   if (port->typec_caps.type != TYPEC_PORT_DRP) {
+   if (port->port_type != TYPEC_PORT_DRP) {
tcpm_queue_message(port, PD_MSG_CTRL_REJECT);
break;
}
@@ -1478,7 +1479,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
}
break;
case PD_CTRL_PR_SWAP:
-   if (port->typec_caps.type != TYPEC_PORT_DRP) {
+   if (port->port_type != TYPEC_PORT_DRP) {
tcpm_queue_message(port, PD_MSG_CTRL_REJECT);
break;
}
@@ -1853,7 +1854,7 @@ static bool tcpm_start_drp_toggling(struct tcpm_port 
*port)
int ret;
 
if (port->tcpc->start_drp_toggling &&
-   port->typec_caps.type == TYPEC_PORT_DRP) {
+   port->port_type == TYPEC_PORT_DRP) {
tcpm_log_force(port, "Start DRP toggling");
ret = port->tcpc->start_drp_toggling(port->tcpc,
 tcpm_rp_cc(port));
@@ -2163,7 +2164,7 @@ static void run_state_machine(struct tcpm_port *port)
break;
}
tcpm_set_cc(port, tcpm_rp_cc(port));
-   if (port->typec_caps.type == TYPEC_PORT_DRP)
+   if (port->port_type == TYPEC_PORT_DRP)
tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK);
break;
case SRC_ATTACH_WAIT:
@@ -2320,7 +2321,7 @@ static void run_state_machine(struct tcpm_port *port)
break;
}
tcpm_set_cc(port, TYPEC_CC_RD);
-   if (port->typec_caps.type == TYPEC_PORT_DRP)
+   if (port->port_type == TYPEC_PORT_DRP)
tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
break;
case SNK_ATTACH_WAIT:
@@ -2411,7 +2412,7 @@ static void run_state_machine(struct tcpm_port *port)
 * see USB power delivery specification, section 8.3.3.6.1.5.1).
 */
tcpm_set_state(port, hard_reset_state(port),
-  port->typec_caps.type == TYPEC_PORT_DRP ?
+  port->port_type == TYPEC_PORT_DRP ?
PD_T_DB_DETECT : PD_T_NO_RESPONSE);
break;
case SNK_DISCOVERY_DEBOUNCE:
@@ -3167,7 +3168,7 @@ static int tcpm_dr_set(const struct typec_capability *cap,
mutex_lock(&port->swap_lock);
mutex_lock(&port->lock);
 
-   if (port->typec_caps.type != TYPEC_PORT_DRP) {
+   if (port->port_type != TYPEC_PORT_DRP) {
ret = -EINVAL;
goto port_unlock;
}
@@ -3235,7 +3236,7 @@ static int tcpm_pr_set(const struct typec_capability *cap,
mutex_lock(&port->swap_lock);
mutex_lock(&port->lock);
 
-   if (port->typec_caps.type != TYPEC_PORT_DRP) {
+   if (port->port_type != TYPEC_PORT_DRP) {
ret = -EINVAL;
goto port_unlock;

[PATCH v1] staging: most: hdm_usb: Driver registration with module_driver macro

2017-08-26 Thread Alex Briskin
Register with module_driver macro instead of module_init/module_exit.

Signed-off-by: Alex Briskin 
---
 drivers/staging/most/hdm-usb/hdm_usb.c | 20 +---
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c 
b/drivers/staging/most/hdm-usb/hdm_usb.c
index a9c3785d19ae..85775da293fb 100644
--- a/drivers/staging/most/hdm-usb/hdm_usb.c
+++ b/drivers/staging/most/hdm-usb/hdm_usb.c
@@ -1301,25 +1301,7 @@ static struct usb_driver hdm_usb = {
.disconnect = hdm_disconnect,
 };
 
-static int __init hdm_usb_init(void)
-{
-   pr_info("hdm_usb_init()\n");
-   if (usb_register(&hdm_usb)) {
-   pr_err("could not register hdm_usb driver\n");
-   return -EIO;
-   }
-
-   return 0;
-}
-
-static void __exit hdm_usb_exit(void)
-{
-   pr_info("hdm_usb_exit()\n");
-   usb_deregister(&hdm_usb);
-}
-
-module_init(hdm_usb_init);
-module_exit(hdm_usb_exit);
+module_usb_driver(hdm_usb);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Christian Gromm ");
 MODULE_DESCRIPTION("HDM_4_USB");
-- 
2.11.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] [media] atomisp2: Remove null check before kfree

2017-08-26 Thread Himanshu Jha
Kfree on NULL pointer is a no-op and therefore checking is redundant.

Signed-off-by: Himanshu Jha 
---
 .../staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c| 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
index 6358216..451c76e 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
@@ -295,10 +295,8 @@ void sh_css_unload_firmware(void)
}
 
memset(&sh_css_sp_fw, 0, sizeof(sh_css_sp_fw));
-   if (sh_css_blob_info) {
-   kfree(sh_css_blob_info);
-   sh_css_blob_info = NULL;
-   }
+   kfree(sh_css_blob_info);
+   sh_css_blob_info = NULL;
sh_css_num_binaries = 0;
 }
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8723bs: remove null check before kfree

2017-08-26 Thread Himanshu Jha
Kfree on NULL pointer is a no-op and therefore checking is redundant.

Signed-off-by: Himanshu Jha 
---
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c 
b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index c7bad64..d5e5f83 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -4120,10 +4120,8 @@ static int rtw_set_wps_beacon(struct net_device *dev, 
struct ieee_param *param,
ie_len = len-12-2;/*  12 = param header, 2:no packed */
 
 
-   if (pmlmepriv->wps_beacon_ie) {
-   kfree(pmlmepriv->wps_beacon_ie);
-   pmlmepriv->wps_beacon_ie = NULL;
-   }
+   kfree(pmlmepriv->wps_beacon_ie);
+   pmlmepriv->wps_beacon_ie = NULL;
 
if (ie_len>0) {
pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len);
@@ -4160,10 +4158,8 @@ static int rtw_set_wps_probe_resp(struct net_device 
*dev, struct ieee_param *par
ie_len = len-12-2;/*  12 = param header, 2:no packed */
 
 
-   if (pmlmepriv->wps_probe_resp_ie) {
-   kfree(pmlmepriv->wps_probe_resp_ie);
-   pmlmepriv->wps_probe_resp_ie = NULL;
-   }
+   kfree(pmlmepriv->wps_probe_resp_ie);
+   pmlmepriv->wps_probe_resp_ie = NULL;
 
if (ie_len>0) {
pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len);
@@ -4195,10 +4191,8 @@ static int rtw_set_wps_assoc_resp(struct net_device 
*dev, struct ieee_param *par
ie_len = len-12-2;/*  12 = param header, 2:no packed */
 
 
-   if (pmlmepriv->wps_assoc_resp_ie) {
-   kfree(pmlmepriv->wps_assoc_resp_ie);
-   pmlmepriv->wps_assoc_resp_ie = NULL;
-   }
+   kfree(pmlmepriv->wps_assoc_resp_ie);
+   pmlmepriv->wps_assoc_resp_ie = NULL;
 
if (ie_len>0) {
pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: netlogic: Delete an error message for a failed memory allocation in xlr_config_spill()

2017-08-26 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 26 Aug 2017 18:44:12 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/staging/netlogic/xlr_net.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/netlogic/xlr_net.c 
b/drivers/staging/netlogic/xlr_net.c
index e05ae4645d91..04cdcf3f329f 100644
--- a/drivers/staging/netlogic/xlr_net.c
+++ b/drivers/staging/netlogic/xlr_net.c
@@ -423,10 +423,8 @@ static void *xlr_config_spill(struct xlr_net_priv *priv, 
int reg_start_0,
base = priv->base_addr;
spill_size = size;
spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
-   if (!spill) {
-   pr_err("Unable to allocate memory for spill area!\n");
+   if (!spill)
return ZERO_SIZE_PTR;
-   }
 
spill = PTR_ALIGN(spill, SMP_CACHE_BYTES);
phys_addr = virt_to_phys(spill);
-- 
2.14.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: fsl-mc: Delete an error message for a failed memory allocation in fsl_mc_resource_pool_add_device()

2017-08-26 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 26 Aug 2017 18:23:52 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c 
b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
index b37a6f48225f..53312e32d94a 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
@@ -66,8 +66,6 @@ static int __must_check 
fsl_mc_resource_pool_add_device(struct fsl_mc_bus
GFP_KERNEL);
if (!resource) {
error = -ENOMEM;
-   dev_err(&mc_bus_dev->dev,
-   "Failed to allocate memory for fsl_mc_resource\n");
goto out_unlock;
}
 
-- 
2.14.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Staging rtlwifi efuse fix up a warning kzalloc

2017-08-26 Thread Joe Perches
On Sat, 2017-08-26 at 09:48 -0500, Larry Finger wrote:
> I will NACK every 
> patch that tries to force code that I maintain to use kcalloc over kzalloc.

Your choice.

The concept behind the kzalloc with multiply vs kcalloc
is protection against multiplication overflow.

It's unlikely to solve any real problem with a
sizeof(foo) * small known number of entries.

It does have application when number of entries is
a user specified value.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Staging rtlwifi efuse fix up a warning kzalloc

2017-08-26 Thread Larry Finger

On 08/26/2017 08:01 AM, Yurii Pavlenko wrote:

Hello,

I have attached a small patch to fix a warning "Prefer kcalloc over kzalloc with 
multiply"
for efuse.c as part of challenge 10 of Eudyptula.

Best regards,
Yurii Pavlenko


Signed-off-by: Yurii Pavlenko 


Before you waste any more of our time, please read the material about patch 
submission at Documentation/process/submitting-patches.rst in your source tree. 
In its present form, this patch is not usable!


I also disagree with the checkpatch warning. To me, there is no difference 
between specifying the size of the allocation as "EFUSE_MAX_WORD_UNIT, 
sizeof(u16 *)" or "EFUSE_MAX_WORD_UNIT * sizeof(u16 *)". In  fact, the only real 
difference is that the source is ONE character larger with the kzalloc version! 
Is that important? Certainly not to me! One thing that is readily apparent is 
that kzalloc() zeros the allocated space. Of course, so does kcalloc(), but it 
is not apparent from the name.


Most of the checkpatch warnings improve readability of the source, and do find 
real or potential errors. This particular one does not, and I will NACK every 
patch that tries to force code that I maintain to use kcalloc over kzalloc.


Larry
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging rtlwifi efuse fix up a warning kzalloc

2017-08-26 Thread Yurii Pavlenko
Hello,

I have attached a small patch to fix a warning "Prefer kcalloc over kzalloc 
with multiply"
for efuse.c as part of challenge 10 of Eudyptula. 

Best regards,
Yurii Pavlenko


Signed-off-by: Yurii Pavlenko 
---
 drivers/staging/rtlwifi/efuse.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtlwifi/efuse.c b/drivers/staging/rtlwifi/efuse.c
index 6d5e657..520d4f2 100644
--- a/drivers/staging/rtlwifi/efuse.c
+++ b/drivers/staging/rtlwifi/efuse.c
@@ -248,15 +248,15 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 
_size_byte, u8 *pbuf)
}
 
/* allocate memory for efuse_tbl and efuse_word */
-   efuse_tbl = kzalloc(rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE] *
+   efuse_tbl = kcalloc(rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE],
sizeof(u8), GFP_ATOMIC);
if (!efuse_tbl)
return;
-   efuse_word = kzalloc(EFUSE_MAX_WORD_UNIT * sizeof(u16 *), GFP_ATOMIC);
+   efuse_word = kcalloc(EFUSE_MAX_WORD_UNIT, sizeof(u16 *), GFP_ATOMIC);
if (!efuse_word)
goto out;
for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
-   efuse_word[i] = kzalloc(efuse_max_section * sizeof(u16),
+   efuse_word[i] = kcalloc(efuse_max_section, sizeof(u16),
GFP_ATOMIC);
if (!efuse_word[i])
goto done;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] [media] Staging: media: radio-bcm2048: make video_device const

2017-08-26 Thread Bhumika Goyal
Make this const as it is only used in a copy operation.

Signed-off-by: Bhumika Goyal 
---
 drivers/staging/media/bcm2048/radio-bcm2048.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c 
b/drivers/staging/media/bcm2048/radio-bcm2048.c
index 86d7fc2..58adaea 100644
--- a/drivers/staging/media/bcm2048/radio-bcm2048.c
+++ b/drivers/staging/media/bcm2048/radio-bcm2048.c
@@ -2564,7 +2564,7 @@ static int bcm2048_vidioc_s_hw_freq_seek(struct file 
*file, void *priv,
 /*
  * bcm2048_viddev_template - video device interface
  */
-static struct video_device bcm2048_viddev_template = {
+static const struct video_device bcm2048_viddev_template = {
.fops   = &bcm2048_fops,
.name   = BCM2048_DRIVER_NAME,
.release= video_device_release_empty,
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: bcm2835-camera: make video_device const

2017-08-26 Thread Bhumika Goyal
Make this const as it is only used in a copy operation.

Signed-off-by: Bhumika Goyal 
---
 drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c 
b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index 5af758a..be936b8 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -1456,7 +1456,7 @@ static int vidioc_s_parm(struct file *file, void *priv,
.mmap = vb2_fop_mmap,
 };
 
-static struct video_device vdev_template = {
+static const struct video_device vdev_template = {
.name = "camera0",
.fops = &camera0_fops,
.ioctl_ops = &camera0_ioctl_ops,
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 00/14] VME: Adjustments for several function implementations

2017-08-26 Thread Greg Kroah-Hartman
On Fri, Aug 25, 2017 at 10:50:19PM +0100, Martyn Welch wrote:
> On Fri, Aug 25, 2017 at 05:41:13PM +0200, SF Markus Elfring wrote:
> > From: Markus Elfring 
> > Date: Fri, 25 Aug 2017 13:15:43 +0200
> > 
> > Several update suggestions were taken into account
> > from static source code analysis.
> > 
> > Markus Elfring (14):
> >   Delete 11 error messages for a failed memory allocation
> >   Improve 11 size determinations
> >   Move an assignment in vme_new_dma_list()
> >   Adjust 48 checks for null pointers
> >   Return directly in two functions
> >   fake: Delete an error message for a failed memory allocation in 
> > fake_init()
> >   fake: Improve five size determinations in fake_init()
> >   fake: Adjust 11 checks for null pointers
> >   ca91cx42: Delete eight error messages for a failed memory allocation
> >   ca91cx42: Improve 12 size determinations
> >   ca91cx42: Adjust 14 checks for null pointers
> >   tsi148: Delete nine error messages for a failed memory allocation
> >   tsi148: Improve 17 size determinations
> >   tsi148: Adjust 14 checks for null pointers
> > 
> 
> Hi Markus,
> 
> Thanks for the patches. Other than the minor tweak needed to patch 13,
> these are looking good to me.

You do know this developer is in my kill-file and I refuse to take
patches from them, and strongly recommend that everyone else just ignore
them, right?  Also many other maintainers/developers have done the same
to them over time due to their past history.

It's up to you what you want to do, but the only way I'll ever accept
patches from them is if they come through someone else (i.e. you resend
them to me...)

good luck!

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 13/14] vme: tsi148: Improve 17 size determinations

2017-08-26 Thread SF Markus Elfring
>> @@ -2363,5 +2364,5 @@ static int tsi148_probe(struct pci_dev *pdev, const 
>> struct pci_device_id *id)
>>  master_num--;
>>  
>>  tsi148_device->flush_image =
>> -kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL);
>> +kmalloc(sizeof(*tsi148_device->flush_image), 
>> GFP_KERNEL);
> 
> This line is now a tiny bit too long

Can you eventually tolerate a line length of 81 characters at such a source 
code place?


> and needs to be broken over two lines.

How would like to achieve this?

* It seems that you would not like to perform such a tweak yourself.

* Do you expect a resend for the complete patch series?

* Will it be sufficient to send another patch only for the requested 
reformatting
  of a single line?

Regards,
Markus
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel