1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef __FMR_H__ 18#define __FMR_H__ 19 20#include <jni.h> 21#include <utils/Log.h> 22#include <stdio.h> 23#include <stdlib.h> 24#include <string.h> 25#include <sys/ioctl.h> 26#include <sys/types.h> 27#include <sys/stat.h> 28#include <fcntl.h> 29#include <unistd.h> 30#include <termios.h> 31#include <pthread.h> 32#include <signal.h> 33#include <errno.h> 34#include <dlfcn.h> 35 36#include "fm.h" 37 38#undef FM_LIB_USE_XLOG 39 40#ifdef FM_LIB_USE_XLOG 41#include <cutils/xlog.h> 42#undef LOGV 43#define LOGV(...) XLOGV(__VA_ARGS__) 44#undef LOGD 45#define LOGD(...) XLOGD(__VA_ARGS__) 46#undef LOGI 47#define LOGI(...) XLOGI(__VA_ARGS__) 48#undef LOGW 49#define LOGW(...) XLOGW(__VA_ARGS__) 50#undef LOGE 51#define LOGE(...) XLOGE(__VA_ARGS__) 52#else 53#undef LOGV 54#define LOGV(...) ALOGV(__VA_ARGS__) 55#undef LOGD 56#define LOGD(...) ALOGD(__VA_ARGS__) 57#undef LOGI 58#define LOGI(...) ALOGI(__VA_ARGS__) 59#undef LOGW 60#define LOGW(...) ALOGW(__VA_ARGS__) 61#undef LOGE 62#define LOGE(...) ALOGE(__VA_ARGS__) 63#endif 64 65#define CUST_LIB_NAME "libfmcust.so" 66#define FM_DEV_NAME "/dev/fm" 67 68#define FM_RDS_PS_LEN 8 69 70struct fm_fake_channel 71{ 72 int freq; 73 int rssi_th; 74 int reserve; 75}; 76 77struct fm_fake_channel_t 78{ 79 int size; 80 struct fm_fake_channel *chan; 81}; 82 83struct CUST_cfg_ds 84{ 85 int16_t chip; 86 int32_t band; 87 int32_t low_band; 88 int32_t high_band; 89 int32_t seek_space; 90 int32_t max_scan_num; 91 int32_t seek_lev; 92 int32_t scan_sort; 93 int32_t short_ana_sup; 94 int32_t rssi_th_l2; 95 struct fm_fake_channel_t *fake_chan; 96}; 97 98struct fm_cbk_tbl { 99 //Basic functions. 100 int (*open_dev)(const char *pname, int *fd); 101 int (*close_dev)(int fd); 102 int (*pwr_up)(int fd, int band, int freq); 103 int (*pwr_down)(int fd, int type); 104 int (*seek)(int fd, int *freq, int band, int dir, int lev); 105 int (*scan)(int fd, uint16_t *tbl, int *num, int band, int sort); 106 int (*stop_scan)(int fd); 107 int (*tune)(int fd, int freq, int band); 108 int (*set_mute)(int fd, int mute); 109 int (*is_rdsrx_support)(int fd, int *supt); 110 int (*turn_on_off_rds)(int fd, int onoff); 111 int (*get_chip_id)(int fd, int *chipid); 112 //FOR RDS RX. 113 int (*read_rds_data)(int fd, RDSData_Struct *rds, uint16_t *rds_status); 114 int (*get_ps)(int fd, RDSData_Struct *rds, uint8_t **ps, int *ps_len); 115 int (*get_rt)(int fd, RDSData_Struct *rds, uint8_t **rt, int *rt_len); 116 int (*active_af)(int fd, RDSData_Struct *rds, int band, uint16_t cur_freq, uint16_t *ret_freq); 117 //FM long/short antenna switch 118 int (*ana_switch)(int fd, int antenna); 119 int (*soft_mute_tune)(int fd, fm_softmute_tune_t *para); 120 int (*desense_check)(int fd, int freq, int rssi); 121 int (*pre_search)(int fd); 122 int (*restore_search)(int fd); 123}; 124 125typedef int (*CUST_func_type)(struct CUST_cfg_ds *); 126typedef void (*init_func_type)(struct fm_cbk_tbl *); 127 128struct fmr_ds { 129 int fd; 130 int err; 131 uint16_t cur_freq; 132 uint16_t backup_freq; 133 void *priv; 134 void *custom_handler; 135 struct CUST_cfg_ds cfg_data; 136 struct fm_cbk_tbl tbl; 137 CUST_func_type get_cfg; 138 void *init_handler; 139 init_func_type init_func; 140 RDSData_Struct rds; 141 struct fm_hw_info hw_info; 142 fm_bool scan_stop; 143}; 144 145enum fmr_err_em { 146 ERR_SUCCESS = 1000, // kernel error begin at here 147 ERR_INVALID_BUF, 148 ERR_INVALID_PARA, 149 ERR_STP, 150 ERR_GET_MUTEX, 151 ERR_FW_NORES, 152 ERR_RDS_CRC, 153 ERR_INVALID_FD, // native error begin at here 154 ERR_UNSUPPORT_CHIP, 155 ERR_LD_LIB, 156 ERR_FIND_CUST_FNUC, 157 ERR_UNINIT, 158 ERR_NO_MORE_IDX, 159 ERR_RDS_NO_DATA, 160 ERR_UNSUPT_SHORTANA, 161 ERR_MAX 162}; 163 164enum fmr_rds_onoff { 165 FMR_RDS_ON, 166 FMR_RDS_OFF, 167 FMR_MAX 168}; 169 170typedef enum { 171 FM_LONG_ANA = 0, 172 FM_SHORT_ANA 173} fm_antenna_type; 174 175 176#define CQI_CH_NUM_MAX 255 177#define CQI_CH_NUM_MIN 0 178 179 180/****************** Function declaration ******************/ 181//fmr_err.cpp 182char *FMR_strerr(); 183void FMR_seterr(int err); 184 185//fmr_core.cpp 186int FMR_init(void); 187int FMR_get_cfgs(int idx); 188int FMR_open_dev(int idx); 189int FMR_close_dev(int idx); 190int FMR_pwr_up(int idx, int freq); 191int FMR_pwr_down(int idx, int type); 192int FMR_seek(int idx, int start_freq, int dir, int *ret_freq); 193int FMR_scan(int idx, uint16_t *tbl, int *num); 194int FMR_stop_scan(int idx); 195int FMR_tune(int idx, int freq); 196int FMR_set_mute(int idx, int mute); 197int FMR_is_rdsrx_support(int idx, int *supt); 198int FMR_turn_on_off_rds(int idx, int onoff); 199int FMR_get_chip_id(int idx, int *chipid); 200int FMR_read_rds_data(int idx, uint16_t *rds_status); 201int FMR_get_ps(int idx, uint8_t **ps, int *ps_len); 202int FMR_get_rssi(int idx, int *rssi); 203int FMR_get_rt(int idx, uint8_t **rt, int *rt_len); 204int FMR_active_af(int idx, uint16_t *ret_freq); 205 206int FMR_ana_switch(int idx, int antenna); 207int FMR_Pre_Search(int idx); 208int FMR_Restore_Search(int idx); 209 210//common part 211int COM_open_dev(const char *pname, int *fd); 212int COM_close_dev(int fd); 213int COM_pwr_up(int fd, int band, int freq); 214int COM_pwr_down(int fd, int type); 215int COM_seek(int fd, int *freq, int band, int dir, int lev); 216int COM_Soft_Mute_Tune(int fd, fm_softmute_tune_t *para); 217 218int COM_stop_scan(int fd); 219int COM_tune(int fd, int freq, int band); 220int COM_set_mute(int fd, int mute); 221int COM_is_rdsrx_support(int fd, int *supt); 222int COM_turn_on_off_rds(int fd, int onoff); 223int COM_get_chip_id(int fd, int *chipid); 224int COM_read_rds_data(int fd, RDSData_Struct *rds, uint16_t *rds_status); 225int COM_get_ps(int fd, RDSData_Struct *rds, uint8_t **ps, int *ps_len); 226int COM_get_rt(int fd, RDSData_Struct *rds, uint8_t **rt, int *rt_len); 227int COM_active_af(int fd, RDSData_Struct *rds, int band, uint16_t cur_freq, uint16_t *ret_freq); 228 229int COM_ana_switch(int fd, int antenna); 230int COM_desense_check(int fd, int freq, int rssi); 231int COM_pre_search(int fd); 232int COM_restore_search(int fd); 233void FM_interface_init(struct fm_cbk_tbl *cbk_tbl); 234 235#define FMR_ASSERT(a) { \ 236 if ((a) == NULL) { \ 237 LOGE("%s,invalid buf\n", __func__);\ 238 return -ERR_INVALID_BUF; \ 239 } \ 240} 241#endif 242 243