rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 MediaTek Inc. |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include "ondiemet.h" |
| 15 | |
| 16 | /* record enabled modules */ |
| 17 | unsigned int ondiemet_module[ONDIEMET_NUM]; |
| 18 | EXPORT_SYMBOL(ondiemet_module); |
| 19 | |
| 20 | void (*scp_start[ONDIEMET_NUM]) (void) = { |
| 21 | sspm_start, NULL, NULL}; |
| 22 | |
| 23 | void (*scp_stop[ONDIEMET_NUM]) (void) = { |
| 24 | sspm_stop, NULL, NULL}; |
| 25 | |
| 26 | void (*scp_extract[ONDIEMET_NUM]) (void) = { |
| 27 | sspm_extract, NULL, NULL}; |
| 28 | |
| 29 | /* record which MCU is started to generate data */ |
| 30 | int ondiemet_module_started[ONDIEMET_NUM]; |
| 31 | |
| 32 | int ondiemet_attr_init(struct device *dev) |
| 33 | { |
| 34 | int ret; |
| 35 | |
| 36 | ret = sspm_attr_init(dev); |
| 37 | if (ret != 0) { |
| 38 | pr_debug("can not create device file: sspm related\n"); |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | |
| 44 | } |
| 45 | |
| 46 | int ondiemet_attr_uninit(struct device *dev) |
| 47 | { |
| 48 | int ret; |
| 49 | |
| 50 | ret = sspm_attr_uninit(dev); |
| 51 | if (ret != 0) { |
| 52 | pr_debug("can not delete device file: sspm related\n"); |
| 53 | return ret; |
| 54 | } |
| 55 | |
| 56 | return 0; |
| 57 | |
| 58 | } |
| 59 | |
| 60 | void ondiemet_start(void) |
| 61 | { |
| 62 | int i; |
| 63 | |
| 64 | for (i = 0; i < ONDIEMET_NUM; i++) { |
| 65 | if (ondiemet_module[i] != 0) { |
| 66 | ondiemet_module_started[i] = 1; |
| 67 | (*scp_start[i]) (); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void ondiemet_stop(void) |
| 73 | { |
| 74 | int i; |
| 75 | |
| 76 | for (i = 0; i < ONDIEMET_NUM; i++) { |
| 77 | if (ondiemet_module[i] != 0) { |
| 78 | (*scp_stop[i]) (); |
| 79 | ondiemet_module_started[i] = 0; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void ondiemet_extract(void) |
| 85 | { |
| 86 | int i; |
| 87 | |
| 88 | for (i = 0; i < ONDIEMET_NUM; i++) { |
| 89 | if (ondiemet_module[i] != 0) |
| 90 | (*scp_extract[i]) (); |
| 91 | } |
| 92 | } |