msm8974_pwm_vibrator: Use the dedicated workqueue

Use the dedicated workqueue for quick response. There may be some delay
for the other workitem schedule when we use the system workqueue.

Change-Id: I0ba7269f6dfd12b177a2fe1b1329cbef169f6859
Signed-off-by: Devin Kim <dojip.kim@lge.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm8974_pwm_vibrator: Clean up codes

Change-Id: I5ef3bb3bf21f438712de7fe7e63e368707bc890c
Signed-off-by: Devin Kim <dojip.kim@lge.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm8974_pwm_vibrator: rework for vibration start/stop

To be flexible, we use the delayed workqueue instead of usleep.
And the driver already support for vibrator stop. So We don't need to stop
it repeatedly. We need a force stop only when upperlayer send a stop signal
during vibing.

Change-Id: I6940119924f6b6919453fde60dc56cb7eb46aa39
Signed-off-by: Devin Kim <dojip.kim@lge.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm8974_pwm_vibrator: Enhance the feedback feeling

Add the braking/driving force feature to enhance the feedback feeling.
The braking avoid the residual vibration. The driving force enhance
the feedback feeling.

Change-Id: I0f7c40f5579f9ce014057a481d128d4f7d830a9a
Signed-off-by: Devin Kim <dojip.kim@lge.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm8974_pwm_vibrator: Add sysfs for vibrator tuning

Change-Id: I6ca3326523fe4e3c6505985f77cf1b91c41fb8b8
Signed-off-by: Devin Kim <dojip.kim@lge.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm8974_pwm_vibrator: Fix the negative remaining timeout

It's possible that hrtimer_get_remaining() returns the nagative value.
It causes the unintended behavior in the delayed workqueue scheduling.
So if the value is native, it means the timer has been already expired.
We just set the delay to 0 in this case.

And use the monotonic timer for the time stamp.

Change-Id: Ia16433d6c2715875f2d6f9da14e8e39824c15aa7
Signed-off-by: Devin Kim <dojip.kim@lge.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm8974_pwm_vibrator: Improve the accuracy for duration

When you press 2 more touches simultaneously, vibration would be weak.
This is the reason why the driving state is not gauranteed.
If the vibrator is already in the driving state. just keep going
for the driving force.

Change-Id: Iea3f1b4895d0798b0465eaa16b83381c6f4ae914
Signed-off-by: Devin Kim <dojip.kim@lge.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Ensure incoming "app_name" does not corrupt the kernel stack

Printing a string with that does not have null terminated character,
would lead to overflow, as the print continues until it finds a null
terminated character.
Avoid this issue by explicitly assigning a string with null termination.

Change-Id: I9528db2ba046c514d829097d08c09540588bb1a2
Signed-off-by: Hariprasad Dhalinarasimha <hnamgund@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Change __copy_from_user to copy_from_user

__copy_from_user does not do address check, so use
copy_from_user instead.

Change-Id: I575c0f3c44b55a521c0d42828988c518c0640a29
Signed-off-by: Hariprasad Dhalinarasimha <hnamgund@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Validate the incoming length from user space

Check if there is no Integer overflow before using req_len and
resp_len (received from user space). If an overflow is detected
then exit the operation.

Change-Id: I0459a6992bb3b280db42be63a275c55fa6105b1c
Signed-off-by: Hariprasad Dhalinarasimha <hnamgund@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
misc: isa1200: Change mutex for isa1200 vibrator

Change i2c client device mutex to local driver mutex
for isa1200 vibrator which is used while enabling and
disabling the clock.

CRs-Fixed: 545512
Change-Id: I4f61c629c503c658410b5c14da2e1612b82ec201
Signed-off-by: Shantanu Jain <shjain@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Add NULL pointer check in qseecom_ioctl

NULL pointer check is added to the qseecom driver in qseecom_ioctl,
which is required to validate the data pointer before executing any
other code from ioctl's.

Change-Id: I6fecf13769b4d7e94eebd4dc075a5ece79b18e1b
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Rename & unifiy some enum definitions.

Move the key management enum values into unified enum
Rename RPMB related enum definitions as per existing pattern.

Change-Id: I542f934ffc399563a587d5016e974a7ce585f0dc
Signed-off-by: Hariprasad Dhalinarasimha <hnamgund@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Fix QSEECOM_IOCTL_UNLOAD_EXTERNAL_ELF_REQ kernel crash

Fixes the kernel crash occuring with IOCTL_UNLOAD_EXTERNAL_ELF_REQ
ioctl by adding unavailable client type to qseecom_client_handle_type
enum, which is required in the driver during qseecom_release().

Change-Id: I73b817255149ffc4a808852feb2954a0ba3c317f
CRs-fixed: 508253
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Check for invalid registration of secapp region

Check the validity of response result field returned by QSEE
when issuing a request to register the secure app region
information.

Change-Id: Idc5ee7cf3c0a25ca37f23ef9d1718fdb05af6533
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Add frequency scaling in send_service_cmd()

Addes DFAB and SFAB bus frequency scaling in qseecom send_service
command function. This is required for RPMB listener services

Change-Id: I7496dfafe1fa571de68b30529ee6db49c8200232
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Add new IOCTLs to support secure UI feature

User space sends the buffer to TZ to use it for secure UI features.
Buffer shall be protected based on the use case, two APIs are
introduced to support this feature.

- QSEECOM_IOCTL_SEND_MODFD_RESP: is called to modify the listener
response data with physical address replaced at a mentioned offset,
so as to be usable by TZ. Option to protect &/ unprotect the buffer
is provided from user space (based on use case).

- QSEECOM_IOCTL_UNPROTECT_BUF: is called to explicitly unprotect the
protected buffer (use case specific).

Change-Id: If129e7bc0131eee4ec361923c6c1c74de37be130
Signed-off-by: Hariprasad Dhalinarasimha <hnamgund@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom:  Validate inputs from user space

Validate send_cmd, send_modfd_cmd and send_mdfd_resp
input parameters: cmd and response pointers and buffer
lengths and offsets  issued to modify data.

Change-Id: I381836d08aaa48357486fbdc6a122eb5b42bfa0b
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom: Remove debug  messages

Remove unnecessary debug  messages.

Change-Id: Ida80fbc1376f15753f8329c44550b14d8f4de163
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
qseecom:  Check for case where listener service is not found

When listerner service is not in the list of registered listeners,
the resulting ptr will a NULL. Check for this case of NULL ptr
to indicate missing listener service.

Change-Id: I0d2c7b01143c40711f71bf434493ac5301314cf2
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>