rrc_drv.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. #include <linux/kernel.h>
  2. #include <linux/mm.h>
  3. #include <linux/mm_types.h>
  4. #include <linux/module.h>
  5. #include <generated/autoconf.h>
  6. #include <linux/init.h>
  7. #include <linux/types.h>
  8. #include <linux/cdev.h>
  9. #include <linux/kdev_t.h>
  10. #include <linux/delay.h>
  11. #include <linux/ioport.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/device.h>
  15. #include <linux/fs.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/wait.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/param.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/sched.h>
  22. #include <linux/slab.h>
  23. #include <linux/fb.h>
  24. #include <linux/kthread.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/semaphore.h>
  27. #include <linux/mutex.h>
  28. #include <linux/suspend.h>
  29. #include <linux/of_fdt.h>
  30. #include <linux/of.h>
  31. #include <linux/of_address.h>
  32. #include <linux/dma-buf.h>
  33. #include <linux/atomic.h>
  34. #include <asm/cacheflush.h>
  35. #include <linux/io.h>
  36. #include <linux/compat.h>
  37. #include <linux/rtpm_prio.h>
  38. #include <linux/ktime.h>
  39. #include <linux/of_irq.h>
  40. #include <asm/io.h>
  41. #include <linux/timer.h>
  42. #include <linux/ioctl.h>
  43. #if IS_ENABLED(CONFIG_COMPAT)
  44. #include <linux/uaccess.h>
  45. #endif
  46. #include "rrc_def.h"
  47. #include "rrc_drv.h"
  48. #define RRC_DEVNAME "mtk_rrc"
  49. #define RRC_PROCESS 0x2
  50. /* -------------------------------------------------------------------------- */
  51. /* */
  52. /* -------------------------------------------------------------------------- */
  53. /* global function */
  54. static unsigned int _rrc_int_status;
  55. /* device and driver */
  56. static dev_t rrc_devno;
  57. static struct cdev *rrc_cdev;
  58. static struct class *rrc_class;
  59. /* static wait_queue_head_t enc_wait_queue; */
  60. static spinlock_t rrc_lock;
  61. static int rrc_status;
  62. static int scenario_back_status[RRC_DRV_TYPE_MAX_SIZE];
  63. static int scenario_status[RRC_DRV_TYPE_MAX_SIZE];
  64. static int new_event_flag;
  65. /* static int scenario_status_next = 1; */
  66. static int is_touch_event;
  67. static int is_video_scenario;
  68. #if 0
  69. static int _rrc_sample_cnt;
  70. #endif
  71. #define RRC_TOUCH_120HZ_MONITOR_WINDOW (500)
  72. #define RRC_TOUCH_120HZ_MONITOR_FPS_COUNT (30)
  73. #define RRC_DRV_LOW_SAMPLE_COUNT (5*3)
  74. #define RRC_SAMPLE_INTERVAL (200)
  75. static wait_queue_head_t set_refresh_rate_wq;
  76. static struct task_struct *set_refresh_rate_task;
  77. static int set_refresh_rate_task_wakeup;
  78. static wait_queue_head_t set_low_refresh_rate_wq;
  79. static struct task_struct *set_low_refresh_rate_task;
  80. static int set_low_refresh_rate_task_wakeup;
  81. static int rrc_curr_refresh_rate;
  82. static int _rrc_avg_fps_range;
  83. static int _is_new_change_refresh_event;
  84. static int _is_new_change_set_low_refresh_now;
  85. static int _is_video_120hz_en;
  86. static int _rrc_refresh_state = RRC_STATE_NORMAL;
  87. static int rrc_set_refresh_state(int state)
  88. {
  89. _rrc_refresh_state = state;
  90. return _rrc_refresh_state;
  91. }
  92. static int rrc_get_refresh_state(void)
  93. {
  94. return _rrc_refresh_state;
  95. }
  96. #if 0
  97. static int rrc_get_ddp_fps(void)
  98. {
  99. int avg_fps;
  100. /* get avg FPS API */
  101. RRC_WRN("[RRC] get ddp fps !!\n");
  102. avg_fps = primary_display_get_hwc_refresh_rate();
  103. return avg_fps;
  104. }
  105. static int rrc_get_ddp_refresh_rate(void)
  106. {
  107. int refresh_rate;
  108. /* get refresh_rate API */
  109. RRC_WRN("[RRC] get ddp refresh rate !!\n");
  110. refresh_rate = primary_display_get_lcm_refresh_rate();
  111. return refresh_rate;
  112. }
  113. #endif
  114. static int rrc_set_ddp_refresh_rate(int refresh_rate)
  115. {
  116. /* set refresh_rate API */
  117. int target_rate = 60;
  118. if (refresh_rate == RRC_DRV_120Hz)
  119. target_rate = 120;
  120. else
  121. target_rate = 60;
  122. RRC_WRN("[RRC] set ddp refresh rate %d(%d)!!\n", target_rate, refresh_rate);
  123. primary_display_set_lcm_refresh_rate(target_rate);
  124. return 0;
  125. }
  126. static int rrc_set_curr_refresh_rate(int refresh_rate)
  127. {
  128. rrc_curr_refresh_rate = refresh_rate;
  129. /* call ddp to switch refresh rate */
  130. rrc_set_ddp_refresh_rate(refresh_rate);
  131. return rrc_curr_refresh_rate;
  132. }
  133. static int rrc_get_curr_refresh_rate(void)
  134. {
  135. int state = rrc_get_refresh_state();
  136. int refresh;
  137. /* get display refresh_rate */
  138. switch (state) {
  139. case RRC_STATE_HIGH_120Hz:
  140. case RRC_STATE_VIDEO_120Hz:
  141. refresh = RRC_DRV_120Hz;
  142. break;
  143. case RRC_STATE_NORMAL:
  144. case RRC_STATE_VIDEO:
  145. case RRC_STATE_HIGH_60Hz:
  146. default:
  147. refresh = RRC_DRV_60Hz;
  148. break;
  149. }
  150. return refresh;
  151. }
  152. static int rrc_get_avg_fps_range(void)
  153. {
  154. int fps_range = _rrc_avg_fps_range;
  155. /* check if avg FPS is lower than 60FPS */
  156. return fps_range;
  157. }
  158. static int rrc_sample_scenario_state(void)
  159. {
  160. int i = 0;
  161. if (new_event_flag) {
  162. for (i = 0; i < RRC_DRV_TYPE_MAX_SIZE; i++)
  163. scenario_status[i] = scenario_back_status[i];
  164. new_event_flag = 0;
  165. }
  166. return 0;
  167. }
  168. static int rrc_get_next_refresh_rate(void)
  169. {
  170. int i = 0;
  171. int video_state = 0;
  172. int touch_state = 0;
  173. /* int j = scenario_status_next & 0x1; */
  174. for (i = RRC_DRV_TYPE_CAMERA_PREVIEW; i <= RRC_DRV_TYPE_VIDEO_WIFI_DISPLAY; i++) {
  175. if (scenario_status[i] > 0) {
  176. video_state++;
  177. if (_is_video_120hz_en
  178. && (i == RRC_DRV_TYPE_VIDEO_SWDEC_PLAYBACK || i == RRC_DRV_TYPE_VIDEO_PLAYBACK)) {
  179. _is_new_change_set_low_refresh_now = 0;
  180. rrc_set_refresh_state(RRC_STATE_VIDEO_120Hz);
  181. break;
  182. }
  183. _is_new_change_set_low_refresh_now = 1;
  184. rrc_set_refresh_state(RRC_STATE_VIDEO);
  185. }
  186. }
  187. if (video_state == 0) {
  188. touch_state = scenario_status[RRC_DRV_TYPE_TOUCH_EVENT];
  189. if (touch_state > 0) {
  190. /* if avg fps can exceed 120FPS, will change to 60Hz */
  191. if (rrc_get_avg_fps_range() == RRC_DRV_120Hz)
  192. rrc_set_refresh_state(RRC_STATE_HIGH_120Hz);
  193. else
  194. rrc_set_refresh_state(RRC_STATE_HIGH_60Hz);
  195. } else {
  196. rrc_set_refresh_state(RRC_STATE_NORMAL);
  197. }
  198. }
  199. return rrc_get_curr_refresh_rate();
  200. }
  201. #if 0
  202. static int rrc_is_touch_event(void)
  203. {
  204. return scenario_status[RRC_DRV_TYPE_TOUCH_EVENT];
  205. }
  206. static int rrc_monitor_fps_kthread_func(void *data)
  207. {
  208. struct sched_param param = { .sched_priority = RTPM_PRIO_SCRN_UPDATE };
  209. sched_setscheduler(current, SCHED_RR, &param);
  210. while (1) {
  211. wait_event_interruptible(set_refresh_rate_wq, set_refresh_rate_task_wakeup);
  212. set_refresh_rate_task_wakeup = 0;
  213. /* TODO: monitor FPS to change refresh range (while user is keep touching) */
  214. }
  215. return 0;
  216. }
  217. #endif
  218. static int rrc_set_low_refresh_rate_kthread_func(void *data)
  219. {
  220. int rrc_low_sample_cnt = 0;
  221. int curr_refresh;
  222. int state;
  223. struct sched_param param = { .sched_priority = RTPM_PRIO_SCRN_UPDATE };
  224. sched_setscheduler(current, SCHED_RR, &param);
  225. while (1) {
  226. RRC_WRN("[RRC_DRV] kthread_func : rrc_set_low_refresh_rate_kthread_func %d (sleep)!!\n",
  227. set_low_refresh_rate_task_wakeup);
  228. wait_event_interruptible(set_low_refresh_rate_wq, set_low_refresh_rate_task_wakeup);
  229. set_low_refresh_rate_task_wakeup = 0;
  230. RRC_WRN("[RRC_DRV] kthread_func : rrc_set_low_refresh_rate_kthread_func %d (wake)!!\n",
  231. set_low_refresh_rate_task_wakeup);
  232. /* reset new change event */
  233. /* _is_new_change_refresh_event = 0; */
  234. while (1) {
  235. /* sleep for a while*/
  236. msleep_interruptible(RRC_SAMPLE_INTERVAL);
  237. /* check if still low state */
  238. if (_is_new_change_refresh_event && _is_new_change_set_low_refresh_now == 0) {
  239. _is_new_change_refresh_event = 0;
  240. curr_refresh = rrc_get_curr_refresh_rate();
  241. /* RRC_WRN("[RRC_DRV] kthread_func : set_low_refresh curr %d, sample_cnt %d !!\n",
  242. curr_refresh, rrc_low_sample_cnt); */
  243. if (curr_refresh == RRC_DRV_120Hz) {
  244. /* go back to sleep for next touch DOWN event */
  245. RRC_WRN("[RRC_DRV] sample new 120Hz event, skip set low refresh rate!!\n");
  246. break;
  247. }
  248. rrc_low_sample_cnt = 0;
  249. }
  250. /* increment low sample count */
  251. if (++rrc_low_sample_cnt == RRC_DRV_LOW_SAMPLE_COUNT || _is_new_change_set_low_refresh_now) {
  252. rrc_low_sample_cnt = 0;
  253. state = rrc_get_refresh_state();
  254. if (RRC_STATE_VIDEO_120Hz != state) {
  255. RRC_WRN("[RRC_DRV] state %d, now %d, set low refresh rate!!\n",
  256. state, _is_new_change_set_low_refresh_now);
  257. rrc_set_curr_refresh_rate(RRC_DRV_60Hz);
  258. }
  259. _is_new_change_set_low_refresh_now = 0;
  260. break;
  261. }
  262. }
  263. }
  264. return 0;
  265. }
  266. static int rrc_set_refresh_rate_kthread_func(void *data)
  267. {
  268. int target_refresh = 0;
  269. int curr_refresh = 0;
  270. /* int event; */
  271. /* int enable; */
  272. struct sched_param param = { .sched_priority = RTPM_PRIO_SCRN_UPDATE };
  273. sched_setscheduler(current, SCHED_RR, &param);
  274. while (1) {
  275. RRC_WRN("[RRC_DRV] kthread_func : set_refresh_rate_task_wakeup %d (sleep)!!\n",
  276. set_refresh_rate_task_wakeup);
  277. wait_event_interruptible(set_refresh_rate_wq, set_refresh_rate_task_wakeup);
  278. set_refresh_rate_task_wakeup = 0;
  279. RRC_WRN("[RRC_DRV] kthread_func : set_refresh_rate_task_wakeup %d (wake)!!\n",
  280. set_refresh_rate_task_wakeup);
  281. /* get current refresh state */
  282. curr_refresh = rrc_get_curr_refresh_rate();
  283. /* sample event change scenario state */
  284. rrc_sample_scenario_state();
  285. /* check if need to change next refresh rate */
  286. target_refresh = rrc_get_next_refresh_rate();
  287. RRC_WRN("[RRC_DRV] kthread_func : curr %d, target %d!!\n", curr_refresh, target_refresh);
  288. _is_new_change_refresh_event = 1;
  289. if (target_refresh != RRC_DRV_NONE && target_refresh != curr_refresh) {
  290. if (target_refresh == RRC_DRV_60Hz) {
  291. /* trigger set low refresh rate thread */
  292. set_low_refresh_rate_task_wakeup = 1;
  293. wake_up_interruptible(&set_low_refresh_rate_wq);
  294. } else {
  295. /* update current refresh rate */
  296. rrc_set_curr_refresh_rate(target_refresh);
  297. }
  298. /* TODO: 60Hz->120Hz wake up FPS monitor to check FPS capability */
  299. /* TODO: 120Hz->60Hz disable FPS monitor to check FPS capability */
  300. }
  301. }
  302. return 0;
  303. }
  304. #if 0
  305. static int rrc_reset_sample_count(void)
  306. {
  307. _rrc_sample_cnt = 0;
  308. return _rrc_sample_cnt;
  309. }
  310. static int rrc_get_sample_count(void)
  311. {
  312. return _rrc_sample_cnt;
  313. }
  314. static int rrc_inc_sample_count(void)
  315. {
  316. _rrc_sample_cnt++;
  317. return _rrc_sample_cnt;
  318. }
  319. #endif
  320. static int rrc_set_scenario_state(int scenario, int enable)
  321. {
  322. int switch_flag = 0;
  323. /* int j = scenario_status_next & 0x1; */
  324. int status = 0;
  325. if (enable) {
  326. if (scenario == RRC_DRV_TYPE_TOUCH_EVENT) {
  327. status = scenario_back_status[scenario] = 1;
  328. } else {
  329. status = ++scenario_back_status[scenario];
  330. if (enable == 2 &&
  331. (scenario == RRC_DRV_TYPE_VIDEO_SWDEC_PLAYBACK ||
  332. scenario == RRC_DRV_TYPE_VIDEO_PLAYBACK)) {
  333. _is_video_120hz_en = 1;
  334. switch_flag = 1;
  335. new_event_flag = 1;
  336. }
  337. }
  338. if (status == 1) {
  339. switch_flag = 1;
  340. new_event_flag = 1;
  341. }
  342. } else {
  343. status = scenario_back_status[scenario];
  344. if (_is_video_120hz_en &&
  345. (scenario == RRC_DRV_TYPE_VIDEO_SWDEC_PLAYBACK || scenario == RRC_DRV_TYPE_VIDEO_PLAYBACK)) {
  346. _is_video_120hz_en = 0;
  347. switch_flag = 1;
  348. new_event_flag = 1;
  349. }
  350. if (status > 0) {
  351. if (--scenario_back_status[scenario] == 0) {
  352. switch_flag = 1;
  353. new_event_flag = 1;
  354. }
  355. }
  356. }
  357. RRC_WRN("[RRC_DRV]set_scenario: scenario %d, status %d, enable %d, switch %d, new_event %d!!\n",
  358. scenario, status, enable, switch_flag, new_event_flag);
  359. return switch_flag;
  360. }
  361. static int rrc_notify_scenario_event(int scenario, int enable)
  362. {
  363. /* int next_rate; */
  364. /* int curr_rate; */
  365. if (scenario > RRC_DRV_TYPE_NONE && scenario < RRC_DRV_TYPE_MAX_SIZE) {
  366. if (rrc_set_scenario_state(scenario, enable)) {
  367. set_refresh_rate_task_wakeup = 1;
  368. wake_up_interruptible(&set_refresh_rate_wq);
  369. }
  370. /* reset fps count */
  371. /* rrc_reset_sample_count(); */
  372. return 0;
  373. }
  374. return -1;
  375. }
  376. static long rrc_ioctl(unsigned int cmd, unsigned long arg, struct file *file)
  377. {
  378. RRC_DRV_DATA drv_data;
  379. /* unsigned int max_safe_size; */
  380. unsigned int result;
  381. unsigned int *pStatus;
  382. pStatus = (unsigned int *)file->private_data;
  383. if (NULL == pStatus) {
  384. RRC_WRN("[RRC_DRV] Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n");
  385. return -EFAULT;
  386. }
  387. /* RRC_DBG("[RRC_DRV] RRC Driver rrc_ioctl cmd %d, set_type %lx, 64data %lx, 32data %lx!!\n",
  388. cmd, RRC_IOCTL_CMD_SET_SCENARIO_TYPE,sizeof(RRC_DRV_DATA), sizeof(RRC_DRV_COMPAT_DATA)); */
  389. switch (cmd) {
  390. /* initial and reset RRC */
  391. case RRC_IOCTL_CMD_INIT:
  392. RRC_DBG("[RRC_DRV] RRC Driver Initial and Lock\n");
  393. *pStatus = RRC_PROCESS;
  394. break;
  395. case RRC_IOCTL_CMD_SET_SCENARIO_TYPE:
  396. RRC_DBG("[RRC_DRV] RRC Driver SET scenario type!!\n");
  397. if (*pStatus != RRC_PROCESS) {
  398. RRC_WRN("Permission Denied! This process can not access RRC Driver");
  399. return -EFAULT;
  400. }
  401. /* RRC_DBG("[RRC_DRV] RRC Driver SET scenario type copy_from_user!!\n"); */
  402. if (copy_from_user(&drv_data, (void *)arg, sizeof(RRC_DRV_DATA))) {
  403. RRC_WRN("[RRC_DRV] RRC Driver : Copy from user error\n");
  404. return -EFAULT;
  405. }
  406. RRC_DBG("[RRC_DRV] RRC Driver SET scenario type rrc_notify_scenario_event!!\n");
  407. result = rrc_notify_scenario_event(drv_data.scenario, drv_data.enable);
  408. if (result < 0) {
  409. RRC_DBG("[RRC_DRV] RRC Driver SET scenario type error %d!!\n", result);
  410. return -EFAULT;
  411. }
  412. /*
  413. RRC_DBG("[RRC_DRV] RRC Driver SET scenario type copy_to_user!!\n");
  414. if (copy_to_user(drv_data.result, &result, sizeof(unsigned int)))
  415. {
  416. RRC_WRN("[RRC_DRV] RRC Driver : Copy to user error (result)\n");
  417. return -EFAULT;
  418. }
  419. */
  420. break;
  421. case RRC_IOCTL_CMD_DEINIT:
  422. /* copy input parameters */
  423. RRC_DBG("[RRC_DRV] RRC Driver Deinit!!\n");
  424. if (*pStatus != RRC_PROCESS) {
  425. RRC_WRN("[RRC_DRV] Permission Denied! This process can not access RRC Driver");
  426. return -EFAULT;
  427. }
  428. *pStatus = 0;
  429. return 0L;
  430. }
  431. return 0L;
  432. }
  433. /* static int rrc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) */
  434. static long rrc_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  435. {
  436. switch (cmd) {
  437. case RRC_IOCTL_CMD_INIT:
  438. case RRC_IOCTL_CMD_SET_SCENARIO_TYPE:
  439. case RRC_IOCTL_CMD_DEINIT:
  440. return rrc_ioctl(cmd, arg, file);
  441. default:
  442. break;
  443. }
  444. return -EINVAL;
  445. }
  446. #if IS_ENABLED(CONFIG_COMPAT)
  447. typedef struct {
  448. compat_uint_t scenario;
  449. compat_uint_t enable;
  450. /* compat_uptr_t *result; */
  451. } RRC_DRV_COMPAT_DATA;
  452. #define COMPAT_RRC_IOCTL_CMD_SET_SCENARIO_TYPE _IOWR(RRC_IOCTL_MAGIC, 12, RRC_DRV_COMPAT_DATA)
  453. static int compat_get_scenario_type_data(
  454. RRC_DRV_COMPAT_DATA __user *data32,
  455. RRC_DRV_DATA __user *data)
  456. {
  457. compat_uint_t i;
  458. int err;
  459. err = get_user(i, &data32->scenario);
  460. err |= put_user(i, &data->scenario);
  461. err |= get_user(i, &data32->enable);
  462. err |= put_user(i, &data->enable);
  463. /* err |= get_user(i, &data32->result); */
  464. /* err |= put_user(compat_ptr(i), &data->result); */
  465. return err;
  466. }
  467. long compat_rrc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  468. {
  469. long ret;
  470. RRC_WRN("compat_rrc_ioctl go L:%d, cmd %x, SCENTYPE %lx!!\n",
  471. __LINE__, cmd, COMPAT_RRC_IOCTL_CMD_SET_SCENARIO_TYPE);
  472. if (!filp->f_op || !filp->f_op->unlocked_ioctl) {
  473. RRC_WRN("compat_rrc_ioctl go L:%d!!\n", __LINE__);
  474. return -ENOTTY;
  475. }
  476. switch (cmd) {
  477. /*
  478. case COMPAT_MTK_IOC_SMI_BWC_CONFIG:
  479. {
  480. if (COMPAT_MTK_IOC_SMI_BWC_CONFIG == MTK_IOC_SMI_BWC_CONFIG)
  481. {
  482. SMIMSG("COMPAT_MTK_IOC_SMI_BWC_CONFIG\n");
  483. return filp->f_op->unlocked_ioctl(filp, cmd,(unsigned long)compat_ptr(arg));
  484. } else{
  485. MTK_SMI_COMPAT_BWC_CONFIG __user *data32;
  486. MTK_SMI_BWC_CONFIG __user *data;
  487. int err;
  488. data32 = compat_ptr(arg);
  489. data = compat_alloc_user_space(sizeof(MTK_SMI_BWC_CONFIG));
  490. if (data == NULL)
  491. return -EFAULT;
  492. err = compat_get_smi_bwc_config_struct(data32, data);
  493. if (err)
  494. return err;
  495. ret = filp->f_op->unlocked_ioctl(filp, MTK_IOC_SMI_BWC_CONFIG,
  496. (unsigned long)data);
  497. return ret;
  498. }
  499. }
  500. case COMPAT_JPEG_DEC_IOCTL_WAIT:
  501. {
  502. compat_JPEG_DEC_DRV_OUT __user *data32;
  503. JPEG_DEC_DRV_OUT __user *data;
  504. int err;
  505. data32 = compat_ptr(arg);
  506. data = compat_alloc_user_space(sizeof(*data));
  507. if (data == NULL)
  508. return -EFAULT;
  509. err = compat_get_jpeg_dec_ioctl_wait_data(data32, data);
  510. if (err)
  511. return err;
  512. ret = filp->f_op->unlocked_ioctl(filp, JPEG_DEC_IOCTL_WAIT,(unsigned long)data);
  513. err = compat_put_jpeg_dec_ioctl_wait_data(data32, data);
  514. return ret ? ret : err;
  515. }
  516. */
  517. case COMPAT_RRC_IOCTL_CMD_SET_SCENARIO_TYPE:
  518. {
  519. RRC_DRV_COMPAT_DATA __user *data32;
  520. RRC_DRV_DATA __user *data;
  521. int err;
  522. if (COMPAT_RRC_IOCTL_CMD_SET_SCENARIO_TYPE == RRC_IOCTL_CMD_SET_SCENARIO_TYPE) {
  523. RRC_WRN("COMPAT_RRC_IOCTL_CMD_SET_SCENARIO_TYPE equl\n");
  524. return filp->f_op->unlocked_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
  525. }
  526. RRC_WRN("COMPAT_RRC_IOCTL_CMD_SET_SCENARIO_TYPE go!!\n");
  527. data32 = compat_ptr(arg);
  528. data = compat_alloc_user_space(sizeof(*data));
  529. if (data == NULL)
  530. return -EFAULT;
  531. err = compat_get_scenario_type_data(data32, data);
  532. if (err)
  533. return err;
  534. ret = filp->f_op->unlocked_ioctl(filp, RRC_IOCTL_CMD_SET_SCENARIO_TYPE, (unsigned long)data);
  535. /* err = compat_put_jpeg_dec_ioctl_wait_data(data32, data); */
  536. return ret;
  537. }
  538. case RRC_IOCTL_CMD_INIT:
  539. case RRC_IOCTL_CMD_DEINIT:
  540. return filp->f_op->unlocked_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
  541. default:
  542. return -ENOIOCTLCMD;
  543. }
  544. }
  545. #endif
  546. static int rrc_open(struct inode *inode, struct file *file)
  547. {
  548. unsigned int *pStatus;
  549. /* Allocate and initialize private data */
  550. file->private_data = kmalloc(sizeof(unsigned int) , GFP_ATOMIC);
  551. if (NULL == file->private_data) {
  552. RRC_WRN("Not enough entry for RRC open operation\n");
  553. return -ENOMEM;
  554. }
  555. pStatus = (unsigned int *)file->private_data;
  556. *pStatus = 0;
  557. return 0;
  558. }
  559. static ssize_t rrc_read(struct file *file, char __user *data, size_t len, loff_t *ppos)
  560. {
  561. RRC_DBG("RRC driver read\n");
  562. return 0;
  563. }
  564. static int rrc_release(struct inode *inode, struct file *file)
  565. {
  566. if (NULL != file->private_data) {
  567. kfree(file->private_data);
  568. file->private_data = NULL;
  569. }
  570. return 0;
  571. }
  572. static int rrc_flush(struct file *a_pstFile , fl_owner_t a_id)
  573. {
  574. unsigned int *pStatus;
  575. pStatus = (unsigned int *)a_pstFile->private_data;
  576. if (NULL == pStatus) {
  577. RRC_WRN("Private data is null in flush operation. HOW COULD THIS HAPPEN ??\n");
  578. return -EFAULT;
  579. }
  580. return 0;
  581. }
  582. /* Kernel interface */
  583. static const struct file_operations rrc_fops = {
  584. .owner = THIS_MODULE,
  585. /* .ioctl = rrc_ioctl, */
  586. .unlocked_ioctl = rrc_unlocked_ioctl,
  587. #if IS_ENABLED(CONFIG_COMPAT)
  588. .compat_ioctl = compat_rrc_ioctl,
  589. #endif
  590. .open = rrc_open,
  591. .release = rrc_release,
  592. .flush = rrc_flush,
  593. .read = rrc_read,
  594. };
  595. static int rrc_probe(struct platform_device *pdev)
  596. {
  597. struct class_device;
  598. int ret;
  599. struct class_device *class_dev = NULL;
  600. int i = 0;
  601. RRC_DBG("-------------rrc driver probe-------\n");
  602. ret = alloc_chrdev_region(&rrc_devno, 0, 1, RRC_DEVNAME);
  603. if (ret)
  604. RRC_ERR("Error: Can't Get Major number for RRC Device\n");
  605. else
  606. RRC_DBG("Get RRC Device Major number (%d)\n", rrc_devno);
  607. rrc_cdev = cdev_alloc();
  608. rrc_cdev->owner = THIS_MODULE;
  609. rrc_cdev->ops = &rrc_fops;
  610. ret = cdev_add(rrc_cdev, rrc_devno, 1);
  611. rrc_class = class_create(THIS_MODULE, RRC_DEVNAME);
  612. class_dev = (struct class_device *)device_create(rrc_class, NULL, rrc_devno, NULL, RRC_DEVNAME);
  613. spin_lock_init(&rrc_lock);
  614. /* initial driver, register driver ISR */
  615. rrc_status = 0;
  616. _rrc_int_status = 0;
  617. for (i = 0; i < RRC_DRV_TYPE_MAX_SIZE-1; i++) {
  618. scenario_back_status[i] = 0;
  619. scenario_status[i] = 0;
  620. new_event_flag = 0;
  621. }
  622. is_touch_event = 0;
  623. is_video_scenario = 0;
  624. RRC_DBG("RRC Probe Done\n");
  625. /* NOT_REFERENCED(class_dev); */
  626. return 0;
  627. }
  628. static int rrc_remove(struct platform_device *pdev)
  629. {
  630. RRC_DBG("RRC driver remove\n");
  631. RRC_DBG("Done\n");
  632. return 0;
  633. }
  634. static void rrc_shutdown(struct platform_device *pdev)
  635. {
  636. RRC_DBG("RRC driver shutdown\n");
  637. /* Nothing yet */
  638. }
  639. /* PM suspend */
  640. static int rrc_suspend(struct platform_device *pdev, pm_message_t mesg)
  641. {
  642. /* rrc_drv_dec_deinit(); */
  643. /* rrc_drv_enc_deinit(); */
  644. return 0;
  645. }
  646. /* PM resume */
  647. static int rrc_resume(struct platform_device *pdev)
  648. {
  649. return 0;
  650. }
  651. static struct platform_driver rrc_driver = {
  652. .probe = rrc_probe,
  653. .remove = rrc_remove,
  654. .shutdown = rrc_shutdown,
  655. .suspend = rrc_suspend,
  656. .resume = rrc_resume,
  657. .driver = {
  658. .name = RRC_DEVNAME,
  659. },
  660. };
  661. static void rrc_device_release(struct device *dev)
  662. {
  663. /* Nothing to release? */
  664. }
  665. static u64 rrc_dmamask = ~(u32)0;
  666. static struct platform_device rrc_device = {
  667. .name = RRC_DEVNAME,
  668. .id = 0,
  669. .dev = {
  670. .release = rrc_device_release,
  671. .dma_mask = &rrc_dmamask,
  672. .coherent_dma_mask = 0xffffffff,
  673. },
  674. .num_resources = 0,
  675. };
  676. static int __init rrc_init(void)
  677. {
  678. int ret;
  679. RRC_DBG("RRC driver initialize\n");
  680. RRC_DBG("Register the RRC driver device\n");
  681. if (platform_device_register(&rrc_device)) {
  682. RRC_ERR("failed to register rrc driver device\n");
  683. ret = -ENODEV;
  684. return ret;
  685. }
  686. RRC_DBG("Register the RRC driver\n");
  687. if (platform_driver_register(&rrc_driver)) {
  688. RRC_ERR("failed to register rrc driver\n");
  689. platform_device_unregister(&rrc_device);
  690. ret = -ENODEV;
  691. return ret;
  692. }
  693. /* change refresh rate */
  694. init_waitqueue_head(&set_refresh_rate_wq);
  695. set_refresh_rate_task = kthread_create(
  696. rrc_set_refresh_rate_kthread_func, NULL, "rrc_set_refresh_rate_kthread_func");
  697. if (IS_ERR(set_refresh_rate_task)) {
  698. RRC_WRN("RRC: Cannot create rrc_set_refresh_rate_kthread_func!!\n");
  699. ret = -ENODEV;
  700. return ret;
  701. }
  702. wake_up_process(set_refresh_rate_task);
  703. /* set low frame rate */
  704. init_waitqueue_head(&set_low_refresh_rate_wq);
  705. set_low_refresh_rate_task = kthread_create(
  706. rrc_set_low_refresh_rate_kthread_func, NULL, "rrc_set_low_refresh_rate_kthread_func");
  707. if (IS_ERR(set_low_refresh_rate_task)) {
  708. RRC_WRN("RRC: Cannot create rrc_set_low_refresh_rate_kthread_func!!\n");
  709. ret = -ENODEV;
  710. return ret;
  711. }
  712. wake_up_process(set_low_refresh_rate_task);
  713. return 0;
  714. }
  715. static void __exit rrc_exit(void)
  716. {
  717. cdev_del(rrc_cdev);
  718. unregister_chrdev_region(rrc_devno, 1);
  719. /* RRC_WRN("Unregistering driver\n"); */
  720. platform_driver_unregister(&rrc_driver);
  721. platform_device_unregister(&rrc_device);
  722. device_destroy(rrc_class, rrc_devno);
  723. class_destroy(rrc_class);
  724. RRC_DBG("Done\n");
  725. }
  726. module_init(rrc_init);
  727. module_exit(rrc_exit);
  728. MODULE_AUTHOR("Otis, Huang <otis.huang@mediatek.com>");
  729. MODULE_DESCRIPTION("RRC driver");
  730. MODULE_LICENSE("GPL");