1/* Copyright (c) 2015, The Linux Foundataion. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 *     * Redistributions of source code must retain the above copyright
7 *       notice, this list of conditions and the following disclaimer.
8 *     * Redistributions in binary form must reproduce the above
9 *       copyright notice, this list of conditions and the following
10 *       disclaimer in the documentation and/or other materials provided
11 *       with the distribution.
12 *     * Neither the name of The Linux Foundation nor the names of its
13 *       contributors may be used to endorse or promote products derived
14 *       from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#ifndef __QCAMERAPERF_H__
31#define __QCAMERAPERF_H__
32
33#include <dlfcn.h>
34#include <utils/Mutex.h>
35#include <hardware/power.h>
36
37typedef enum {
38    ALL_CORES_ONLINE = 0x7FE,
39    ALL_CPUS_PWR_CLPS_DIS = 0x101,
40    CPU0_MIN_FREQ_TURBO_MAX = 0x2FE,
41    CPU4_MIN_FREQ_TURBO_MAX = 0x1FFE,
42}perf_lock_params_t;
43
44/* Time related macros */
45#define ONE_SEC 1000
46typedef int64_t nsecs_t;
47#define NSEC_PER_SEC 1000000000LLU
48
49using namespace android;
50
51namespace qcamera {
52
53class QCameraPerfLock {
54public:
55    QCameraPerfLock();
56    ~QCameraPerfLock();
57
58    void    lock_init();
59    void    lock_deinit();
60    int32_t lock_rel();
61    int32_t lock_acq();
62    int32_t lock_acq_timed(int32_t timer_val);
63    int32_t lock_rel_timed();
64    bool    isTimerReset();
65    void    powerHintInternal(power_hint_t hint, uint32_t enable);
66    void    powerHint(power_hint_t hint, uint32_t enable);
67
68private:
69    int32_t        (*perf_lock_acq)(int, int, int[], int);
70    int32_t        (*perf_lock_rel)(int);
71    void            startTimer(uint32_t timer_val);
72    void           *mDlHandle;
73    uint32_t        mPerfLockEnable;
74    Mutex           mLock;
75    int32_t         mPerfLockHandle;  // Performance lock library handle
76    int32_t         mPerfLockHandleTimed;  // Performance lock library handle
77    power_module_t *m_pPowerModule;   // power module Handle
78    power_hint_t    mCurrentPowerHint;
79    uint32_t        mCurrentPowerHintEnable;
80    uint32_t        mTimerSet;
81    uint32_t        mPerfLockTimeout;
82    nsecs_t         mStartTimeofLock;
83};
84
85}; // namespace qcamera
86
87#endif /* __QCAMREAPERF_H__ */
88