Skip to content

Commit

Permalink
Keys on 7885
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic011gamer committed Oct 16, 2023
1 parent 5e93cde commit ba7fcbb
Show file tree
Hide file tree
Showing 14 changed files with 704 additions and 2 deletions.
1 change: 1 addition & 0 deletions Platform/Samsung/exynos7885/exynos7885.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
gSimpleInitTokenSpaceGuid.PcdLoggerdUseConsole|FALSE

[LibraryClasses.common]
KeypadDeviceImplLib|Silicon/Samsung/Exynos7885Pkg/Library/KeypadDeviceImplLib/KeypadDeviceImplLib.inf
PlatformMemoryMapLib|Silicon/Samsung/Exynos7885Pkg/Library/PlatformMemoryMapLib/PlatformMemoryMapLib.inf
PlatformPeiLib|Silicon/Samsung/Exynos7885Pkg/Library/PlatformPeiLib/PlatformPeiLib.inf
PlatformPrePiLib|Silicon/Samsung/Exynos7885Pkg/Library/PlatformPrePiLib/PlatformPrePiLib.inf
Expand Down
3 changes: 3 additions & 0 deletions Platform/Samsung/exynos7885/exynos7885.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ READ_LOCK_STATUS = TRUE

INF Silicon/Samsung/ExynosPkg/Drivers/SimpleFbDxe/SimpleFbDxe.inf

INF Silicon/Samsung/ExynosPkg/Drivers/KeypadDxe/KeypadDxe.inf
INF Silicon/Samsung/ExynosPkg/Drivers/GenericKeypadDeviceDxe/GenericKeypadDeviceDxe.inf

#
# USB Host Support
#
Expand Down
62 changes: 62 additions & 0 deletions Silicon/Samsung/Exynos7885Pkg/Include/Library copy/AtomicLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2008-2014 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_ATOMIC_H
#define __LIB_ATOMIC_H

#include <Library/UefiBootServicesTableLib.h>

STATIC inline INTN AtomicAnd(volatile INTN *Address, INTN Value)
{
EFI_TPL OriginalTPL;
INTN OldValue;

OriginalTPL = gBS->RaiseTPL(TPL_HIGH_LEVEL);
OldValue = *Address;
*Address &= Value;
gBS->RestoreTPL(OriginalTPL);

return OldValue;
}

STATIC inline INTN AtomicOr(volatile INTN *Address, INTN Value)
{
EFI_TPL OriginalTPL;
INTN OldValue;

OriginalTPL = gBS->RaiseTPL(TPL_HIGH_LEVEL);
OldValue = *Address;
*Address |= Value;
gBS->RestoreTPL(OriginalTPL);

return OldValue;
}

STATIC inline INTN AtomicRead(volatile INTN *Address) { return *Address; }

STATIC inline VOID AtomicSet(volatile INTN *Address, INTN Value)
{
*Address = Value;
}

#endif

65 changes: 65 additions & 0 deletions Silicon/Samsung/Exynos7885Pkg/Include/Library copy/BitmapLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_BITMAP_H
#define __LIB_BITMAP_H

#include <Library/AtomicLib.h>

#define BIT_SHIFT(x, bit) (((x) >> (bit)) & 1)
#define BITS_SHIFT(x, high, low) \
(((x) >> (low)) & ((1 << ((high) - (low) + 1)) - 1))
#define BIT_SET(x, bit) (((x) & (1UL << (bit))) ? 1 : 0)

#define BITMAP_BITS_PER_WORD (sizeof(UINTN) * 8)
#define BITMAP_NUM_WORDS(x) \
(((x) + BITMAP_BITS_PER_WORD - 1) / BITMAP_BITS_PER_WORD)
#define BITMAP_WORD(x) ((x) / BITMAP_BITS_PER_WORD)
#define BITMAP_BIT_IN_WORD(x) ((x) & (BITMAP_BITS_PER_WORD - 1))

#define BITMAP_BITS_PER_INT (sizeof(UINTN) * 8)
#define BITMAP_BIT_IN_INT(x) ((x) & (BITMAP_BITS_PER_INT - 1))
#define BITMAP_INT(x) ((x) / BITMAP_BITS_PER_INT)

#define BIT_MASK(x) \
(((x) >= sizeof(UINTN) * 8) ? (0UL - 1) : ((1UL << (x)) - 1))

STATIC inline INTN BitmapSet(UINTN *bitmap, INTN bit)
{
UINTN mask = 1UL << BITMAP_BIT_IN_INT(bit);
return AtomicOr(&((INTN *)bitmap)[BITMAP_INT(bit)], mask) & mask ? 1 : 0;
}

STATIC inline INTN BitmapClear(UINTN *bitmap, INTN bit)
{
UINTN mask = 1UL << BITMAP_BIT_IN_INT(bit);

return AtomicAnd(&((INTN *)bitmap)[BITMAP_INT(bit)], ~mask) & mask ? 1 : 0;
}

STATIC inline INTN BitmapTest(UINTN *bitmap, INTN bit)
{
return BIT_SET(bitmap[BITMAP_WORD(bit)], BITMAP_BIT_IN_WORD(bit));
}

#endif

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef __LIBRARY_KEYPAD_DEVICE_IMPL_H__
#define __LIBRARY_KEYPAD_DEVICE_IMPL_H__

#include <Protocol/KeypadDevice.h>

EFI_STATUS EFIAPI KeypadDeviceImplReset(KEYPAD_DEVICE_PROTOCOL *This);
EFI_STATUS KeypadDeviceImplGetKeys(
KEYPAD_DEVICE_PROTOCOL *This, KEYPAD_RETURN_API *KeypadReturnApi,
UINT64 Delta);


typedef enum {
KEYSTATE_RELEASED,
KEYSTATE_PRESSED,
KEYSTATE_LONGPRESS_RELEASE,
} KEY_STATE;

typedef struct {
// keydata to be send to the driver
EFI_KEY_DATA KeyData;

// the time the current action has been running
UINT64 Time;

// the current state of the key
KEY_STATE State;

// the current key has to repeat sending events
BOOLEAN Repeat;

// the user did a longpress
BOOLEAN Longpress;
} KEY_CONTEXT;

#endif

62 changes: 62 additions & 0 deletions Silicon/Samsung/Exynos7885Pkg/Include/Library/AtomicLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2008-2014 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_ATOMIC_H
#define __LIB_ATOMIC_H

#include <Library/UefiBootServicesTableLib.h>

STATIC inline INTN AtomicAnd(volatile INTN *Address, INTN Value)
{
EFI_TPL OriginalTPL;
INTN OldValue;

OriginalTPL = gBS->RaiseTPL(TPL_HIGH_LEVEL);
OldValue = *Address;
*Address &= Value;
gBS->RestoreTPL(OriginalTPL);

return OldValue;
}

STATIC inline INTN AtomicOr(volatile INTN *Address, INTN Value)
{
EFI_TPL OriginalTPL;
INTN OldValue;

OriginalTPL = gBS->RaiseTPL(TPL_HIGH_LEVEL);
OldValue = *Address;
*Address |= Value;
gBS->RestoreTPL(OriginalTPL);

return OldValue;
}

STATIC inline INTN AtomicRead(volatile INTN *Address) { return *Address; }

STATIC inline VOID AtomicSet(volatile INTN *Address, INTN Value)
{
*Address = Value;
}

#endif

65 changes: 65 additions & 0 deletions Silicon/Samsung/Exynos7885Pkg/Include/Library/BitmapLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_BITMAP_H
#define __LIB_BITMAP_H

#include <Library/AtomicLib.h>

#define BIT_SHIFT(x, bit) (((x) >> (bit)) & 1)
#define BITS_SHIFT(x, high, low) \
(((x) >> (low)) & ((1 << ((high) - (low) + 1)) - 1))
#define BIT_SET(x, bit) (((x) & (1UL << (bit))) ? 1 : 0)

#define BITMAP_BITS_PER_WORD (sizeof(UINTN) * 8)
#define BITMAP_NUM_WORDS(x) \
(((x) + BITMAP_BITS_PER_WORD - 1) / BITMAP_BITS_PER_WORD)
#define BITMAP_WORD(x) ((x) / BITMAP_BITS_PER_WORD)
#define BITMAP_BIT_IN_WORD(x) ((x) & (BITMAP_BITS_PER_WORD - 1))

#define BITMAP_BITS_PER_INT (sizeof(UINTN) * 8)
#define BITMAP_BIT_IN_INT(x) ((x) & (BITMAP_BITS_PER_INT - 1))
#define BITMAP_INT(x) ((x) / BITMAP_BITS_PER_INT)

#define BIT_MASK(x) \
(((x) >= sizeof(UINTN) * 8) ? (0UL - 1) : ((1UL << (x)) - 1))

STATIC inline INTN BitmapSet(UINTN *bitmap, INTN bit)
{
UINTN mask = 1UL << BITMAP_BIT_IN_INT(bit);
return AtomicOr(&((INTN *)bitmap)[BITMAP_INT(bit)], mask) & mask ? 1 : 0;
}

STATIC inline INTN BitmapClear(UINTN *bitmap, INTN bit)
{
UINTN mask = 1UL << BITMAP_BIT_IN_INT(bit);

return AtomicAnd(&((INTN *)bitmap)[BITMAP_INT(bit)], ~mask) & mask ? 1 : 0;
}

STATIC inline INTN BitmapTest(UINTN *bitmap, INTN bit)
{
return BIT_SET(bitmap[BITMAP_WORD(bit)], BITMAP_BIT_IN_WORD(bit));
}

#endif

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef __LIBRARY_KEYPAD_DEVICE_IMPL_H__
#define __LIBRARY_KEYPAD_DEVICE_IMPL_H__

#include <Protocol/KeypadDevice.h>

EFI_STATUS EFIAPI KeypadDeviceImplReset(KEYPAD_DEVICE_PROTOCOL *This);
EFI_STATUS KeypadDeviceImplGetKeys(
KEYPAD_DEVICE_PROTOCOL *This, KEYPAD_RETURN_API *KeypadReturnApi,
UINT64 Delta);


typedef enum {
KEYSTATE_RELEASED,
KEYSTATE_PRESSED,
KEYSTATE_LONGPRESS_RELEASE,
} KEY_STATE;

typedef struct {
// keydata to be send to the driver
EFI_KEY_DATA KeyData;

// the time the current action has been running
UINT64 Time;

// the current state of the key
KEY_STATE State;

// the current key has to repeat sending events
BOOLEAN Repeat;

// the user did a longpress
BOOLEAN Longpress;
} KEY_CONTEXT;

#endif

37 changes: 37 additions & 0 deletions Silicon/Samsung/Exynos7885Pkg/Include/Protocol copy/KeypadDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef __PROTOCOL_KEYPAD_DEVICE_H__
#define __PROTOCOL_KEYPAD_DEVICE_H__

#include <Protocol/SimpleTextInEx.h>

#define KEYPAD_DEVICE_PROTOCOL_GUID \
{ \
0xb27625b5, 0x0b6c, 0x4614, \
{ \
0xaa, 0x3c, 0x33, 0x13, 0xb5, 0x1d, 0x36, 0x46 \
} \
}

typedef struct _KEYPAD_DEVICE_PROTOCOL KEYPAD_DEVICE_PROTOCOL;
typedef struct _KEYPAD_RETURN_API KEYPAD_RETURN_API;

typedef VOID(EFIAPI *PUSH_EFI_KEY_BUF_TAIL)(
KEYPAD_RETURN_API *This, EFI_KEY_DATA *KeyData);

struct _KEYPAD_RETURN_API {
PUSH_EFI_KEY_BUF_TAIL PushEfikeyBufTail;
};

typedef EFI_STATUS(EFIAPI *KEYPAD_RESET)(KEYPAD_DEVICE_PROTOCOL *This);
typedef EFI_STATUS(EFIAPI *KEYPAD_GET_KEYS)(
KEYPAD_DEVICE_PROTOCOL *This, KEYPAD_RETURN_API *KeypadReturnApi,
UINT64 Delta);

struct _KEYPAD_DEVICE_PROTOCOL {
KEYPAD_RESET Reset;
KEYPAD_GET_KEYS GetKeys;
};

extern EFI_GUID gExynosKeypadDeviceProtocolGuid;

#endif

Loading

0 comments on commit ba7fcbb

Please sign in to comment.