fc8300.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /*****************************************************************************
  2. Copyright(c) 2013 FCI Inc. All Rights Reserved
  3. File name : fc8300.c
  4. Description : Driver source file
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. History :
  17. ----------------------------------------------------------------------
  18. *******************************************************************************/
  19. #include <linux/module.h>
  20. #include <linux/miscdevice.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/kthread.h>
  23. #include <linux/poll.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/irq.h>
  26. #include <linux/delay.h>
  27. #include <linux/slab.h>
  28. #include <linux/gpio.h>
  29. #include <linux/spmi.h>
  30. #include <linux/io.h>
  31. #include <mach/isdbt_tuner_pdata.h>
  32. #include <mach/sec_debug.h>
  33. #include <linux/regulator/machine.h>
  34. #include <mach/gpio.h>
  35. #include <linux/platform_device.h>
  36. #include <linux/wakelock.h>
  37. #include <linux/input.h>
  38. #include <mach/gpiomux.h>
  39. #include <linux/of_gpio.h>
  40. #include "fc8300.h"
  41. #include "fc8300_i2c.h"
  42. #include "bbm.h"
  43. #include "fci_oal.h"
  44. #include "fci_tun.h"
  45. #include "fc8300_regs.h"
  46. #include "fc8300_isr.h"
  47. #include "fci_hal.h"
  48. #include <asm/system_info.h>
  49. struct ISDBT_INIT_INFO_T *hInit;
  50. int bbm_xtal_freq;
  51. unsigned int fc8300_xtal_freq;
  52. #ifndef BBM_I2C_TSIF
  53. #define RING_BUFFER_SIZE (188 * 320 * 17)
  54. #endif
  55. /* GPIO(RESET & INTRRUPT) Setting */
  56. #define FC8300_NAME "isdbt"
  57. static struct isdbt_platform_data *isdbt_pdata;
  58. #define TS0_5PKT_LENGTH (188 * 5)
  59. #define TS0_32PKT_LENGTH (188 * 32)
  60. #ifndef BBM_I2C_TSIF
  61. u8 static_ringbuffer[RING_BUFFER_SIZE];
  62. #endif
  63. enum ISDBT_MODE driver_mode = ISDBT_POWEROFF;
  64. static DEFINE_MUTEX(ringbuffer_lock);
  65. static DECLARE_WAIT_QUEUE_HEAD(isdbt_isr_wait);
  66. static long open_cnt = 0; /* OPEN counter */
  67. static long moni_cnt = 0; /* Monitor counter */
  68. extern unsigned int system_rev;
  69. #ifdef CONFIG_ISDBT_SPMI
  70. static unsigned int spmi_addr;
  71. #endif
  72. #ifndef BBM_I2C_TSIF
  73. static u8 isdbt_isr_sig;
  74. static struct task_struct *isdbt_kthread;
  75. static irqreturn_t isdbt_irq(int irq, void *dev_id)
  76. {
  77. isdbt_isr_sig = 1;
  78. wake_up_interruptible(&isdbt_isr_wait);
  79. return IRQ_HANDLED;
  80. }
  81. #endif
  82. #ifdef CONFIG_ISDBT_SPMI
  83. struct isdbt_qpnp_data
  84. {
  85. struct spmi_device *spmi;
  86. };
  87. static struct isdbt_qpnp_data *isdbt_spmi;
  88. static int qpnp_isdbt_clk_probe(struct spmi_device *spmi)
  89. {
  90. int rc;
  91. u8 reg = 0x00;
  92. struct isdbt_qpnp_data *spmi_data;
  93. pr_info("%s called\n", __func__);
  94. spmi_data = devm_kzalloc(&spmi->dev, sizeof(struct isdbt_qpnp_data), GFP_KERNEL); //CID 25032
  95. if(!spmi_data)
  96. return -ENOMEM;
  97. spmi_data->spmi = spmi;
  98. isdbt_spmi = spmi_data;
  99. spmi_addr = 0x5546;
  100. rc = spmi_ext_register_readl(spmi->ctrl, spmi->sid, spmi_addr, &reg, 1);
  101. if (rc) {
  102. pr_err("Unable to read from addr=0x%x, rc(%d)\n", spmi_addr, rc);
  103. }
  104. pr_info("%s Register 0x%x contains 0x%x\n", __func__,spmi_addr, reg);
  105. return 0;
  106. }
  107. static int qpnp_isdbt_clk_remove(struct spmi_device *spmi)
  108. {
  109. u8 reg = 0x00;
  110. int rc = spmi_ext_register_writel(spmi->ctrl, spmi->sid, spmi_addr,&reg, 1);
  111. if (rc) {
  112. pr_err("Unable to write from addr=%x, rc(%d)\n", spmi_addr, rc);
  113. }
  114. return 0;
  115. }
  116. static struct of_device_id spmi_match_table[] = {
  117. {
  118. .compatible = "qcom,qpnp-clkrf2"
  119. },
  120. {}
  121. };
  122. static struct spmi_driver qpnp_isdbt_clk_driver = {
  123. .driver = {
  124. .name = "qcom,qpnp-isdbclk",
  125. .of_match_table = spmi_match_table,
  126. },
  127. .probe = qpnp_isdbt_clk_probe,
  128. .remove = qpnp_isdbt_clk_remove,
  129. };
  130. #endif
  131. static int tuner_ioctl_set_monitor_mode ( struct file* FIle,
  132. unsigned int cmd,
  133. unsigned long arg )
  134. {
  135. int ret = 0;
  136. pr_info ("tuner_ioctl_set_monitor_mode << Start >> ");
  137. if ( 1 == arg )
  138. {
  139. /* Monitor Mode Start */
  140. moni_cnt++;
  141. }
  142. else
  143. {
  144. /* Monitor Mode Stop */
  145. moni_cnt--;
  146. if ( 0 > moni_cnt )
  147. {
  148. pr_info (" tuner_ioctl_set_monitor_mode under counter = %ld => 0", moni_cnt );
  149. moni_cnt = 0;
  150. }
  151. }
  152. pr_info ("tuner_ioctl_set_monitor_mode << End >> : moni_cnt = %ld",
  153. moni_cnt );
  154. return ( ret );
  155. }
  156. static int tuner_ioctl_get_open_count ( struct file* FIle,
  157. unsigned int cmd,
  158. unsigned long arg )
  159. {
  160. TUNER_STS_DATA *arg_data;
  161. int ret = 0;
  162. unsigned long temp_open = 0;
  163. pr_info ("tuner_ioctl_get_open_count << Start >> : open = %ld",
  164. ( open_cnt - moni_cnt ));
  165. /* Parameter check */
  166. arg_data = (TUNER_STS_DATA*)arg;
  167. if ( NULL == arg_data )
  168. {
  169. pr_err("Parameter Error : arg = NULL");
  170. return ( -1 );
  171. }
  172. /* state check */
  173. if ( open_cnt < moni_cnt )
  174. {
  175. pr_err("tuner_ioctl_get_open_count Error : open = %ld, moni = %ld",
  176. open_cnt, moni_cnt );
  177. return ( -1 );
  178. }
  179. temp_open = (open_cnt - moni_cnt);
  180. /* Copy to User Area */
  181. ret = put_user ( temp_open, (unsigned long __user *)&(arg_data->open_cnt) );
  182. if ( 0 != ret )
  183. {
  184. pr_err("tuner_ioctl_get_open_count put_user(arg_data->open_cnt) Error : ret = %d", ret );
  185. return ( -1 );
  186. }
  187. /* Copy to User Area */
  188. ret = put_user ( moni_cnt, (unsigned long __user *)&(arg_data->moni_cnt) );
  189. if ( 0 != ret )
  190. {
  191. pr_err("tuner_ioctl_get_open_count put_user(arg_data->moni_cnt) Error : ret = %d", ret );
  192. return ( -1 );
  193. }
  194. pr_info("tuner_ioctl_get_open_count << End >>");
  195. pr_info(" Open Count Result : %ld", open_cnt );
  196. pr_info(" Monitor Count Result : %ld", moni_cnt );
  197. return ( 0 );
  198. }
  199. int isdbt_hw_setting(void)
  200. {
  201. int err;
  202. pr_info("isdbt_hw_setting \n");
  203. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  204. err = gpio_request(isdbt_pdata->gpio_tmm_sw, "isdbt_tmm_sw");
  205. if (err) {
  206. pr_info("isdbt_hw_setting: Couldn't request isdbt_tmm_sw\n");
  207. goto ISDBT_TMM_SW_ERR;
  208. }
  209. gpio_direction_output(isdbt_pdata->gpio_tmm_sw, 0);
  210. #endif
  211. err = gpio_request(isdbt_pdata->gpio_en, "isdbt_en");
  212. if (err) {
  213. pr_info("isdbt_hw_setting: Couldn't request isdbt_en\n");
  214. goto ISBT_EN_ERR;
  215. }
  216. gpio_direction_output(isdbt_pdata->gpio_en, 0);
  217. err = gpio_request(isdbt_pdata->gpio_rst, "isdbt_rst");
  218. if (err) {
  219. pr_info("isdbt_hw_setting: Couldn't request isdbt_rst\n");
  220. goto ISDBT_RST_ERR;
  221. }
  222. gpio_direction_output(isdbt_pdata->gpio_rst, 0);
  223. #ifndef BBM_I2C_TSIF
  224. err = gpio_request(isdbt_pdata->gpio_int, "isdbt_irq");
  225. if (err) {
  226. pr_info("isdbt_hw_setting: Couldn't request isdbt_irq\n");
  227. goto ISDBT_INT_ERR;
  228. }
  229. gpio_direction_input(isdbt_pdata->gpio_int);
  230. err = request_irq(gpio_to_irq(isdbt_pdata->gpio_int), isdbt_irq
  231. , IRQF_DISABLED | IRQF_TRIGGER_FALLING, FC8300_NAME, NULL);
  232. if (err < 0) {
  233. print_log(0,
  234. "isdbt_hw_setting: couldn't request gpio \
  235. interrupt %d reason(%d)\n"
  236. , gpio_to_irq(isdbt_pdata->gpio_int), err);
  237. goto request_isdbt_irq;
  238. }
  239. #endif
  240. return 0;
  241. #ifndef BBM_I2C_TSIF
  242. request_isdbt_irq:
  243. gpio_free(isdbt_pdata->gpio_int);
  244. ISDBT_INT_ERR:
  245. gpio_free(isdbt_pdata->gpio_rst);
  246. #endif
  247. ISDBT_RST_ERR:
  248. gpio_free(isdbt_pdata->gpio_en);
  249. ISBT_EN_ERR:
  250. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  251. ISDBT_TMM_SW_ERR:
  252. gpio_free(isdbt_pdata->gpio_tmm_sw);
  253. #endif
  254. return err;
  255. }
  256. static void isdbt_gpio_init(void)
  257. {
  258. pr_info("%s\n",__func__);
  259. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  260. gpio_tlmm_config(GPIO_CFG(isdbt_pdata->gpio_tmm_sw, GPIOMUX_FUNC_GPIO,
  261. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
  262. GPIO_CFG_ENABLE);
  263. #endif
  264. #ifdef CONFIG_MACH_KLIMT_LTE_DCM
  265. gpio_tlmm_config(GPIO_CFG(isdbt_pdata->gpio_en, GPIOMUX_FUNC_GPIO,
  266. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
  267. GPIO_CFG_ENABLE);
  268. #else
  269. gpio_tlmm_config(GPIO_CFG(isdbt_pdata->gpio_en, GPIOMUX_FUNC_GPIO,
  270. GPIO_CFG_OUTPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
  271. GPIO_CFG_ENABLE);
  272. #endif
  273. #ifdef CONFIG_MACH_CHAGALL_KDI
  274. gpio_tlmm_config(GPIO_CFG(isdbt_pdata->gpio_rst, GPIOMUX_FUNC_GPIO,
  275. GPIO_CFG_OUTPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
  276. GPIO_CFG_ENABLE);
  277. #else
  278. gpio_tlmm_config(GPIO_CFG(isdbt_pdata->gpio_rst, GPIOMUX_FUNC_GPIO,
  279. GPIO_CFG_OUTPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA),
  280. GPIO_CFG_ENABLE);
  281. #endif
  282. #ifdef BBM_I2C_TSIF
  283. gpio_tlmm_config(GPIO_CFG(isdbt_pdata->gpio_int, GPIOMUX_FUNC_GPIO,
  284. GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA),
  285. GPIO_CFG_ENABLE);
  286. #else
  287. gpio_tlmm_config(GPIO_CFG(isdbt_pdata->gpio_int, GPIOMUX_FUNC_GPIO,
  288. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA),
  289. GPIO_CFG_ENABLE);
  290. #endif
  291. isdbt_hw_setting();
  292. }
  293. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  294. void isdbt_sw_ldo_on(void)
  295. {
  296. int ret=0;
  297. struct regulator *max77826_ldo9;
  298. pr_info("%s set ldo ON\n", __func__);
  299. max77826_ldo9 = regulator_get(NULL, "max77826_ldo9");
  300. if(max77826_ldo9)
  301. {
  302. if (regulator_is_enabled(max77826_ldo9) > 0)
  303. {
  304. pr_info("%s LDO already ON\n", __func__);
  305. return;
  306. }
  307. ret = regulator_set_voltage(max77826_ldo9,2100000, 2100000);
  308. if (unlikely(ret < 0)){
  309. pr_err("ISDBT ERROR max77826_ldo9 set voltage failed.\n");
  310. }
  311. regulator_enable(max77826_ldo9);
  312. regulator_put(max77826_ldo9);
  313. }
  314. else
  315. {
  316. pr_err("%s ERROR !! LDO not found!!\n", __func__);
  317. }
  318. }
  319. void isdbt_sw_ldo_off(void)
  320. {
  321. struct regulator *max77826_ldo9;
  322. pr_info("%s set ldo OFF\n", __func__);
  323. max77826_ldo9 = regulator_get(NULL, "max77826_ldo9");
  324. if(max77826_ldo9)
  325. {
  326. if (regulator_is_enabled(max77826_ldo9) > 0)
  327. {
  328. regulator_disable(max77826_ldo9);
  329. regulator_put(max77826_ldo9);
  330. }
  331. }
  332. }
  333. #endif
  334. /*POWER_ON & HW_RESET & INTERRUPT_CLEAR */
  335. void isdbt_hw_init(void)
  336. {
  337. int i = 0;
  338. #ifdef CONFIG_ISDBT_SPMI
  339. u8 reg = 0x00;
  340. #endif
  341. while (driver_mode == ISDBT_DATAREAD) {
  342. msWait(100);
  343. if (i++ > 5)
  344. break;
  345. }
  346. pr_info("isdbt_hw_init \n");
  347. gpio_set_value(isdbt_pdata->gpio_rst, 0);
  348. gpio_set_value(isdbt_pdata->gpio_en, 1);
  349. msleep(2); /* fc8300 chipspec is 1ms */
  350. #ifdef CONFIG_ISDBT_SPMI
  351. pr_info("%s, Enabling ISDBT_CLK\n", __func__);
  352. reg = 0x80;
  353. if (isdbt_spmi) {
  354. int rc = spmi_ext_register_writel(isdbt_spmi->spmi->ctrl, isdbt_spmi->spmi->sid, spmi_addr,&reg, 1);
  355. if (rc)
  356. pr_err("%s, Unable to write from addr=0x%x, rc(%d)\n", __func__, spmi_addr, rc);
  357. } else {
  358. pr_err("%s ERROR !! isdbt_spmi is NULL !!\n", __func__);
  359. }
  360. #endif
  361. msleep(1); /* fc8300 chipspec is 360us */
  362. gpio_set_value(isdbt_pdata->gpio_rst, 1);
  363. driver_mode = ISDBT_POWERON;
  364. }
  365. /*POWER_OFF */
  366. void isdbt_hw_deinit(void)
  367. {
  368. #ifdef CONFIG_ISDBT_SPMI
  369. u8 reg = 0x00;
  370. #endif
  371. pr_info("isdbt_hw_deinit \n");
  372. driver_mode = ISDBT_POWEROFF;
  373. #ifdef CONFIG_ISDBT_SPMI
  374. pr_info("%s, Turning ISDBT_CLK off\n", __func__);
  375. reg = 0x00;
  376. if(isdbt_spmi) {
  377. int rc = spmi_ext_register_writel(isdbt_spmi->spmi->ctrl, isdbt_spmi->spmi->sid, spmi_addr,&reg, 1);
  378. if (rc) {
  379. pr_err("%s, Unable to write from addr=%x, rc(%d)\n", __func__, spmi_addr, rc );
  380. }
  381. }
  382. else {
  383. pr_err("%s ERROR !! isdbt_spmi is NULL !!\n", __func__);
  384. }
  385. #endif
  386. gpio_set_value(isdbt_pdata->gpio_en, 0);
  387. gpio_set_value(isdbt_pdata->gpio_rst, 0);
  388. }
  389. #ifndef BBM_I2C_TSIF
  390. int data_callback(u32 hDevice, u8 bufid, u8 *data, int len)
  391. {
  392. struct ISDBT_INIT_INFO_T *hInit;
  393. struct list_head *temp;
  394. hInit = (struct ISDBT_INIT_INFO_T *)hDevice;
  395. list_for_each(temp, &(hInit->hHead))
  396. {
  397. struct ISDBT_OPEN_INFO_T *hOpen;
  398. hOpen = list_entry(temp, struct ISDBT_OPEN_INFO_T, hList);
  399. if (hOpen->isdbttype == TS_TYPE) {
  400. mutex_lock(&ringbuffer_lock);
  401. if (fci_ringbuffer_free(&hOpen->RingBuffer) < len) {
  402. /*print_log(hDevice, "f"); */
  403. /* return 0 */;
  404. FCI_RINGBUFFER_SKIP(&hOpen->RingBuffer, len);
  405. }
  406. fci_ringbuffer_write(&hOpen->RingBuffer, data, len);
  407. wake_up_interruptible(&(hOpen->RingBuffer.queue));
  408. mutex_unlock(&ringbuffer_lock);
  409. }
  410. }
  411. return 0;
  412. }
  413. static int isdbt_thread(void *hDevice)
  414. {
  415. struct ISDBT_INIT_INFO_T *hInit = (struct ISDBT_INIT_INFO_T *)hDevice;
  416. set_user_nice(current, -20);
  417. pr_info("isdbt_kthread enter\n");
  418. bbm_com_ts_callback_register((u32)hInit, data_callback);
  419. while (1) {
  420. wait_event_interruptible(isdbt_isr_wait,
  421. isdbt_isr_sig || kthread_should_stop());
  422. if (driver_mode == ISDBT_POWERON) {
  423. driver_mode = ISDBT_DATAREAD;
  424. bbm_com_isr(hInit);
  425. driver_mode = ISDBT_POWERON;
  426. }
  427. isdbt_isr_sig = 0;
  428. if (kthread_should_stop())
  429. break;
  430. }
  431. bbm_com_ts_callback_deregister();
  432. pr_info("isdbt_kthread exit\n");
  433. return 0;
  434. }
  435. #endif
  436. const struct file_operations isdbt_fops = {
  437. .owner = THIS_MODULE,
  438. .unlocked_ioctl = isdbt_ioctl,
  439. .open = isdbt_open,
  440. #ifndef BBM_I2C_TSIF
  441. .read = isdbt_read,
  442. #endif
  443. .release = isdbt_release,
  444. };
  445. static struct miscdevice fc8300_misc_device = {
  446. .minor = MISC_DYNAMIC_MINOR,
  447. .name = FC8300_NAME,
  448. .fops = &isdbt_fops,
  449. };
  450. int isdbt_open(struct inode *inode, struct file *filp)
  451. {
  452. struct ISDBT_OPEN_INFO_T *hOpen;
  453. pr_info("isdbt open\n");
  454. open_cnt++;
  455. hOpen = kmalloc(sizeof(struct ISDBT_OPEN_INFO_T), GFP_KERNEL);
  456. if(!hOpen)
  457. {
  458. pr_err("hOpen malloc failed ENOMEM\n");
  459. return -ENOMEM;
  460. }
  461. #ifndef BBM_I2C_TSIF
  462. hOpen->buf = &static_ringbuffer[0];
  463. /*kmalloc(RING_BUFFER_SIZE, GFP_KERNEL);*/
  464. #endif
  465. hOpen->isdbttype = 0;
  466. list_add(&(hOpen->hList), &(hInit->hHead));
  467. hOpen->hInit = (HANDLE *)hInit;
  468. #ifndef BBM_I2C_TSIF
  469. if (hOpen->buf == NULL) {
  470. pr_info("ring buffer malloc error\n");
  471. return -ENOMEM;
  472. }
  473. fci_ringbuffer_init(&hOpen->RingBuffer, hOpen->buf, RING_BUFFER_SIZE);
  474. #endif
  475. filp->private_data = hOpen;
  476. return 0;
  477. }
  478. #ifndef BBM_I2C_TSIF
  479. ssize_t isdbt_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
  480. {
  481. s32 avail;
  482. s32 non_blocking = filp->f_flags & O_NONBLOCK;
  483. struct ISDBT_OPEN_INFO_T *hOpen
  484. = (struct ISDBT_OPEN_INFO_T *)filp->private_data;
  485. struct fci_ringbuffer *cibuf = &hOpen->RingBuffer;
  486. ssize_t len, read_len = 0;
  487. if (!cibuf->data || !count) {
  488. /*pr_info(" return 0\n"); */
  489. return 0;
  490. }
  491. if (non_blocking && (fci_ringbuffer_empty(cibuf))) {
  492. /*pr_info("return EWOULDBLOCK\n"); */
  493. return -EWOULDBLOCK;
  494. }
  495. if (wait_event_interruptible(cibuf->queue,
  496. !fci_ringbuffer_empty(cibuf))) {
  497. pr_info("return ERESTARTSYS\n");
  498. return -ERESTARTSYS;
  499. }
  500. mutex_lock(&ringbuffer_lock);
  501. avail = fci_ringbuffer_avail(cibuf);
  502. if (count >= avail)
  503. len = avail;
  504. else
  505. len = count - (count % 188);
  506. read_len = fci_ringbuffer_read_user(cibuf, buf, len);
  507. mutex_unlock(&ringbuffer_lock);
  508. return read_len;
  509. }
  510. #endif
  511. int isdbt_release(struct inode *inode, struct file *filp)
  512. {
  513. struct ISDBT_OPEN_INFO_T *hOpen;
  514. pr_info("isdbt_release\n");
  515. if( open_cnt <= 0 )
  516. {
  517. printk("tuner_module_entry_close: close error\n");
  518. open_cnt = 0;
  519. return -1;
  520. }
  521. else
  522. {
  523. open_cnt--;
  524. }
  525. /* close all open */
  526. if( open_cnt == 0 )
  527. {
  528. hOpen = filp->private_data;
  529. if (hOpen != NULL)
  530. {
  531. hOpen->isdbttype = 0;
  532. list_del(&(hOpen->hList));
  533. pr_info("isdbt_release hList\n");
  534. // if(hOpen->buf)
  535. // kfree(hOpen->buf);
  536. pr_info("isdbt_release buf\n");
  537. kfree(hOpen);
  538. }
  539. }
  540. return 0;
  541. }
  542. #ifndef BBM_I2C_TSIF
  543. void isdbt_isr_check(HANDLE hDevice)
  544. {
  545. u8 isr_time = 0;
  546. bbm_com_write(hDevice, DIV_BROADCAST, BBM_BUF_INT_ENABLE, 0x00);
  547. while (isr_time < 10) {
  548. if (!isdbt_isr_sig)
  549. break;
  550. msWait(10);
  551. isr_time++;
  552. }
  553. }
  554. #endif
  555. long isdbt_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  556. {
  557. s32 res = BBM_NOK;
  558. s32 err = 0;
  559. s32 size = 0;
  560. struct ISDBT_OPEN_INFO_T *hOpen;
  561. struct ioctl_info info;
  562. if (_IOC_TYPE(cmd) != IOCTL_MAGIC)
  563. return -EINVAL;
  564. if (_IOC_NR(cmd) >= IOCTL_MAXNR)
  565. return -EINVAL;
  566. hOpen = filp->private_data;
  567. size = _IOC_SIZE(cmd);
  568. switch (cmd) {
  569. case IOCTL_ISDBT_RESET:
  570. //pr_info("[FC8300] IOCTL_ISDBT_RESET \n");
  571. res = bbm_com_reset(hInit, DIV_BROADCAST);
  572. pr_info("[FC8300] IOCTL_ISDBT_RESET \n");
  573. break;
  574. case IOCTL_ISDBT_INIT:
  575. pr_info("[FC8300] IOCTL_ISDBT_INIT \n");
  576. res = bbm_com_i2c_init(hInit, FCI_HPI_TYPE);
  577. pr_info("[FC8300] IOCTL_ISDBT_INIT bbm_com_i2c_init res =%d \n",res);
  578. res |= bbm_com_probe(hInit, DIV_BROADCAST);
  579. if (res) {
  580. pr_info("FC8300 Initialize Fail \n");
  581. break;
  582. }
  583. pr_info("[FC8300] IOCTL_ISDBT_INIT bbm_com_probe success \n");
  584. res |= bbm_com_init(hInit, DIV_BROADCAST);
  585. pr_info("[FC8300] IOCTL_ISDBT_INITbbm_com_init \n");
  586. #if 0
  587. res |= bbm_com_tuner_select(hInit
  588. , DIV_BROADCAST, FC8300_TUNER, ISDBT_13SEG);
  589. #endif
  590. break;
  591. case IOCTL_ISDBT_BYTE_READ:
  592. pr_info("[FC8300] IOCTL_ISDBT_BYTE_READ \n");
  593. err = copy_from_user((void *)&info, (void *)arg, size);
  594. res = bbm_com_byte_read(hInit, DIV_BROADCAST, (u16)info.buff[0]
  595. , (u8 *)(&info.buff[1]));
  596. err |= copy_to_user((void *)arg, (void *)&info, size);
  597. break;
  598. case IOCTL_ISDBT_WORD_READ:
  599. err = copy_from_user((void *)&info, (void *)arg, size);
  600. res = bbm_com_word_read(hInit, DIV_BROADCAST, (u16)info.buff[0]
  601. , (u16 *)(&info.buff[1]));
  602. err |= copy_to_user((void *)arg, (void *)&info, size);
  603. break;
  604. case IOCTL_ISDBT_LONG_READ:
  605. err = copy_from_user((void *)&info, (void *)arg, size);
  606. res = bbm_com_long_read(hInit, DIV_BROADCAST, (u16)info.buff[0]
  607. , (u32 *)(&info.buff[1]));
  608. err |= copy_to_user((void *)arg, (void *)&info, size);
  609. break;
  610. case IOCTL_ISDBT_BULK_READ:
  611. err = copy_from_user((void *)&info, (void *)arg, size);
  612. res = bbm_com_bulk_read(hInit, DIV_BROADCAST, (u16)info.buff[0]
  613. , (u8 *)(&info.buff[2]), info.buff[1]);
  614. err |= copy_to_user((void *)arg, (void *)&info, size);
  615. break;
  616. case IOCTL_ISDBT_BYTE_WRITE:
  617. err = copy_from_user((void *)&info, (void *)arg, size);
  618. res = bbm_com_byte_write(hInit, DIV_BROADCAST, (u16)info.buff[0]
  619. , (u8)info.buff[1]);
  620. break;
  621. case IOCTL_ISDBT_WORD_WRITE:
  622. err = copy_from_user((void *)&info, (void *)arg, size);
  623. res = bbm_com_word_write(hInit, DIV_BROADCAST, (u16)info.buff[0]
  624. , (u16)info.buff[1]);
  625. break;
  626. case IOCTL_ISDBT_LONG_WRITE:
  627. err = copy_from_user((void *)&info, (void *)arg, size);
  628. res = bbm_com_long_write(hInit, DIV_BROADCAST, (u16)info.buff[0]
  629. , (u32)info.buff[1]);
  630. break;
  631. case IOCTL_ISDBT_BULK_WRITE:
  632. err = copy_from_user((void *)&info, (void *)arg, size);
  633. res = bbm_com_bulk_write(hInit, DIV_BROADCAST, (u16)info.buff[0]
  634. , (u8 *)(&info.buff[2]), info.buff[1]);
  635. break;
  636. case IOCTL_ISDBT_TUNER_READ:
  637. err = copy_from_user((void *)&info, (void *)arg, size);
  638. res = bbm_com_tuner_read(hInit, DIV_BROADCAST, (u8)info.buff[0]
  639. , (u8)info.buff[1], (u8 *)(&info.buff[3])
  640. , (u8)info.buff[2]);
  641. err |= copy_to_user((void *)arg, (void *)&info, size);
  642. break;
  643. case IOCTL_ISDBT_TUNER_WRITE:
  644. err = copy_from_user((void *)&info, (void *)arg, size);
  645. res = bbm_com_tuner_write(hInit, DIV_BROADCAST, (u8)info.buff[0]
  646. , (u8)info.buff[1], (u8 *)(&info.buff[3])
  647. , (u8)info.buff[2]);
  648. break;
  649. case IOCTL_ISDBT_TUNER_SET_FREQ:
  650. {
  651. u32 f_rf;
  652. u8 subch;
  653. err = copy_from_user((void *)&info, (void *)arg, size);
  654. f_rf = (u32)info.buff[0];
  655. subch = (u8)info.buff[1];
  656. pr_info("[FC8300] IOCTL_ISDBT_TUNER_SET_FREQ freq=%d subch=%d\n",f_rf,subch);
  657. #ifndef BBM_I2C_TSIF
  658. isdbt_isr_check(hInit);
  659. #endif
  660. res = bbm_com_tuner_set_freq(hInit
  661. , DIV_BROADCAST, f_rf, subch);
  662. #ifndef BBM_I2C_TSIF
  663. mutex_lock(&ringbuffer_lock);
  664. fci_ringbuffer_flush(&hOpen->RingBuffer);
  665. mutex_unlock(&ringbuffer_lock);
  666. bbm_com_write(hInit
  667. , DIV_BROADCAST, BBM_BUF_INT_ENABLE, 0x01);
  668. #endif
  669. }
  670. break;
  671. case IOCTL_ISDBT_TUNER_SELECT:
  672. pr_info("[FC8300] IOCTL_ISDBT_TUNER_SELECT \n");
  673. err = copy_from_user((void *)&info, (void *)arg, size);
  674. res = bbm_com_tuner_select(hInit
  675. , DIV_BROADCAST, (u32)info.buff[0], (u32)info.buff[1]);
  676. if (((u32)info.buff[1] == ISDBTMM_13SEG) || ((u32)info.buff[1] == ISDBT_13SEG)) {
  677. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_START, 0);
  678. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_END
  679. , TS0_32PKT_LENGTH - 1);
  680. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_THR
  681. , TS0_32PKT_LENGTH / 2 - 1);
  682. print_log(hInit, "[FC8300] TUNER THRESHOLD: %d \n"
  683. , TS0_32PKT_LENGTH / 2 - 1);
  684. }
  685. else
  686. {
  687. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_START, 0);
  688. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_END
  689. , TS0_5PKT_LENGTH - 1);
  690. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_THR
  691. , TS0_5PKT_LENGTH / 2 - 1);
  692. print_log(hInit, "[FC8300] TUNER THRESHOLD: %d \n"
  693. , TS0_5PKT_LENGTH / 2 - 1);
  694. }
  695. print_log(hInit, "[FC8300] IOCTL_ISDBT_TUNER_SELECT %d \n"
  696. , (u32)info.buff[1]);
  697. break;
  698. case IOCTL_ISDBT_TS_START:
  699. pr_info("[FC8300] IOCTL_ISDBT_TS_START \n");
  700. hOpen->isdbttype = TS_TYPE;
  701. break;
  702. case IOCTL_ISDBT_TS_STOP:
  703. pr_info("[FC8300] IOCTL_ISDBT_TS_STOP \n");
  704. hOpen->isdbttype = 0;
  705. break;
  706. case IOCTL_ISDBT_POWER_ON:
  707. pr_info("[FC8300] IOCTL_ISDBT_POWER_ON \n");
  708. isdbt_hw_init();
  709. res = bbm_com_probe(hInit, DIV_BROADCAST);
  710. if (res) {
  711. pr_info("FC8300 IOCTL_ISDBT_POWER_ON FAIL \n");
  712. isdbt_hw_deinit();
  713. } else {
  714. pr_info("FC8300 IOCTL_ISDBT_POWER_ON SUCCESS\n");
  715. }
  716. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  717. isdbt_sw_ldo_on();
  718. #endif
  719. break;
  720. case IOCTL_ISDBT_POWER_OFF:
  721. pr_info("[FC8300] IOCTL_ISDBT_POWER_OFF \n");
  722. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  723. isdbt_sw_ldo_off();
  724. #endif
  725. isdbt_hw_deinit();
  726. break;
  727. case IOCTL_ISDBT_SCAN_STATUS:
  728. pr_info("[FC8300] IOCTL_ISDBT_SCAN_STATUS \n");
  729. res = bbm_com_scan_status(hInit, DIV_BROADCAST);
  730. break;
  731. case IOCTL_ISDBT_TUNER_GET_RSSI:
  732. err = copy_from_user((void *)&info, (void *)arg, size);
  733. res = bbm_com_tuner_get_rssi(hInit
  734. , DIV_BROADCAST, (s32 *)&info.buff[0]);
  735. err |= copy_to_user((void *)arg, (void *)&info, size);
  736. break;
  737. case TUNER_IOCTL_VALGET_OPENCNT:
  738. res = tuner_ioctl_get_open_count ( filp->private_data,
  739. cmd,
  740. arg );
  741. break;
  742. case TUNER_IOCTL_VALSET_MONICNT:
  743. res = tuner_ioctl_set_monitor_mode ( filp->private_data,
  744. cmd,
  745. arg );
  746. break;
  747. case IOCTL_ISDBT_TUNER_PKT_MODE:
  748. pr_info("[FC8300] IOCTL_ISDBT_TUNER_PKT_MODE \n");
  749. err = copy_from_user((void *)&info, (void *)arg, size);
  750. if (!err) {
  751. bbm_byte_write(hInit, DIV_MASTER, BBM_BUF_ENABLE, 0x00); // buffer disable
  752. if ((u32)info.buff[0] == ISDBT_INTERRUPT_32_PKT) {
  753. pr_info("[FC8300] IOCTL_ISDBT_TUNER_PKT_MODE ISDBT_INTERRUPT_32_PKT\n");
  754. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_START, 0);
  755. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_END
  756. , TS0_32PKT_LENGTH - 1);
  757. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_THR
  758. , TS0_32PKT_LENGTH / 2 - 1);
  759. print_log(hInit, "[FC8300] TUNER THRESHOLD: %d \n"
  760. , TS0_32PKT_LENGTH / 2 - 1);
  761. }
  762. else
  763. {
  764. pr_info("[FC8300] IOCTL_ISDBT_TUNER_PKT_MODE ISDBT_INTERRUPT_5_PKT\n");
  765. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_START, 0);
  766. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_END
  767. , TS0_5PKT_LENGTH - 1);
  768. bbm_com_word_write(hInit, DIV_BROADCAST, BBM_BUF_TS0_THR
  769. , TS0_5PKT_LENGTH / 2 - 1);
  770. print_log(hInit, "[FC8300] TUNER THRESHOLD: %d \n"
  771. , TS0_5PKT_LENGTH / 2 - 1);
  772. }
  773. bbm_byte_write(hInit, DIV_MASTER, BBM_BUF_ENABLE, 0x01); // buffer enable
  774. print_log(hInit, "[FC8300] IOCTL_ISDBT_TUNER_PKT_MODE %lu \n"
  775. , info.buff[0]);
  776. }
  777. res = err;
  778. break;
  779. default:
  780. pr_info("isdbt ioctl error!\n");
  781. res = BBM_NOK;
  782. break;
  783. }
  784. if (err < 0) {
  785. pr_info("copy to/from user fail : %d", err);
  786. res = BBM_NOK;
  787. }
  788. return res;
  789. }
  790. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  791. static struct device isdbt_sysfs_dev = {
  792. .init_name = "isdbt",
  793. };
  794. static ssize_t isdbt_signal_source_store(struct device *dev,
  795. struct device_attribute *attr, const char *buf, size_t size)
  796. {
  797. unsigned int state;
  798. if (sscanf(buf, "%u", &state) != 1) {
  799. pr_info("%s: invalid state:%u\n", __func__, state);
  800. return -EINVAL;
  801. }
  802. pr_info("%s: state:%u system_rev:%u\n", __func__, state, system_rev);
  803. /*0: F-type cable, 1: Antenna */
  804. if(system_rev <= 2) /*Rev 0.2 gpio: F-type cable:0, Antenna:1 */
  805. {
  806. if (state == 0) {
  807. pr_info("%s: state:%u Enabling F type cable by setting TMM_SW to LOW\n", __func__, state);
  808. gpio_set_value_cansleep(isdbt_pdata->gpio_tmm_sw, 0);
  809. } else if (state == 1) {
  810. pr_info("%s: state:%u Enabling antenna by setting TMM_SW to HIGH\n", __func__, state);
  811. gpio_set_value_cansleep(isdbt_pdata->gpio_tmm_sw, 1);
  812. } else {
  813. return -EINVAL;
  814. }
  815. }
  816. else /*Rev 0.3 gpio: F-type cable:1, Antenna:0 */
  817. {
  818. if (state == 0) {
  819. pr_info("%s: state:%u Enabling F type cable by setting TMM_SW to HIGH\n", __func__, state);
  820. gpio_set_value_cansleep(isdbt_pdata->gpio_tmm_sw, 1);
  821. } else if (state == 1) {
  822. pr_info("%s: state:%u Enabling antenna by setting TMM_SW to LOW\n", __func__, state);
  823. gpio_set_value_cansleep(isdbt_pdata->gpio_tmm_sw, 0);
  824. } else {
  825. return -EINVAL;
  826. }
  827. }
  828. return size;
  829. }
  830. /*
  831. static ssize_t isdbt_signal_source_show(struct device *dev,
  832. struct device_attribute *devattr, char *buf)
  833. {
  834. int ret;
  835. ret = gpio_get_value_cansleep(isdbt_pdata->gpio_tmm_sw);
  836. pr_info("%s: gpio_tmm_sw state:%d\n", __func__, ret);
  837. return snprintf(buf, PAGE_SIZE, "%d\n", ret);
  838. }
  839. */
  840. static DEVICE_ATTR(isdbt_signal_source, (S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP), NULL, isdbt_signal_source_store);
  841. #endif
  842. static struct isdbt_platform_data *isdbt_populate_dt_pdata(struct device *dev)
  843. {
  844. struct isdbt_platform_data *pdata;
  845. pr_info("%s\n", __func__);
  846. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  847. if (!pdata) {
  848. pr_err("%s : could not allocate memory for platform data\n", __func__);
  849. goto err;
  850. }
  851. of_property_read_u32(dev->of_node, "qcom,isdb-bbm-xtal-freq", &bbm_xtal_freq);
  852. if (bbm_xtal_freq < 0)
  853. {
  854. pr_err("%s : can not find the isdbt-bbmxtal-freq in the dt, set to : 26000\n", __func__);
  855. bbm_xtal_freq = 26000;
  856. }
  857. pdata->gpio_en = of_get_named_gpio(dev->of_node, "qcom,isdb-gpio-pwr-en", 0);
  858. if (pdata->gpio_en < 0)
  859. of_property_read_u32(dev->of_node, "qcom,isdb-gpio-pwr-en", &pdata->gpio_en );
  860. if (pdata->gpio_en < 0)
  861. {
  862. pr_err("%s : can not find the isdbt-detect-gpio gpio_en in the dt\n", __func__);
  863. goto alloc_err;
  864. } else {
  865. pr_info("%s : isdbt-detect-gpio gpio_en =%d\n", __func__, pdata->gpio_en);
  866. }
  867. pdata->gpio_rst = of_get_named_gpio(dev->of_node, "qcom,isdb-gpio-rst", 0);
  868. if (pdata->gpio_rst < 0)
  869. of_property_read_u32(dev->of_node, "qcom,isdb-gpio-rst", &pdata->gpio_rst);
  870. if (pdata->gpio_rst < 0) {
  871. pr_err("%s : can not find the isdbt-detect-gpio gpio_rst in the dt\n", __func__);
  872. goto alloc_err;
  873. } else {
  874. pr_info("%s : isdbt-detect-gpio gpio_rst =%d\n", __func__, pdata->gpio_rst);
  875. }
  876. pdata->gpio_int = of_get_named_gpio(dev->of_node, "qcom,isdb-gpio-irq", 0);
  877. if (pdata->gpio_int < 0)
  878. of_property_read_u32(dev->of_node, "qcom,isdb-gpio-irq", &pdata->gpio_int);
  879. if (pdata->gpio_int < 0) {
  880. pr_err("%s : can not find the isdbt-detect-gpio in the gpio_int dt\n", __func__);
  881. goto alloc_err;
  882. } else {
  883. pr_info("%s : isdbt-detect-gpio gpio_int =%d\n", __func__, pdata->gpio_int);
  884. }
  885. pdata->gpio_i2c_sda = of_get_named_gpio(dev->of_node, "qcom,isdb-gpio-i2c_sda", 0);
  886. if (pdata->gpio_i2c_sda < 0)
  887. of_property_read_u32(dev->of_node, "qcom,isdb-gpio-i2c_sda", &pdata->gpio_i2c_sda);
  888. if (pdata->gpio_i2c_sda < 0) {
  889. pr_err("%s : can not find the isdbt-detect-gpio gpio_i2c_sda in the dt\n", __func__);
  890. goto alloc_err;
  891. } else {
  892. pr_info("%s : isdbt-detect-gpio gpio_i2c_sda=%d\n", __func__, pdata->gpio_i2c_sda);
  893. }
  894. pdata->gpio_i2c_scl = of_get_named_gpio(dev->of_node, "qcom,isdb-gpio-i2c_scl", 0);
  895. if (pdata->gpio_i2c_scl < 0)
  896. of_property_read_u32(dev->of_node, "qcom,isdb-gpio-i2c_scl", &pdata->gpio_i2c_scl);
  897. if (pdata->gpio_i2c_scl < 0) {
  898. pr_err("%s : can not find the isdbt-detect-gpio gpio_i2c_scl in the dt\n", __func__);
  899. goto alloc_err;
  900. } else {
  901. pr_info("%s : isdbt-detect-gpio gpio_i2c_scl=%d\n", __func__, pdata->gpio_i2c_scl);
  902. }
  903. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  904. pdata->gpio_tmm_sw = of_get_named_gpio(dev->of_node, "qcom,isdb-gpio-tmm_sw", 0);
  905. if (pdata->gpio_tmm_sw < 0)
  906. of_property_read_u32(dev->of_node, "qcom,isdb-gpio-tmm_sw", &pdata->gpio_tmm_sw);
  907. if (pdata->gpio_tmm_sw < 0) {
  908. pr_err("%s : can not find the isdbt-detect-gpio gpio_tmm_sw in the dt\n", __func__);
  909. goto alloc_err;
  910. } else {
  911. pr_info("%s : isdbt-detect-gpio gpio_tmm_sw=%d\n", __func__, pdata->gpio_tmm_sw);
  912. }
  913. #endif
  914. return pdata;
  915. alloc_err:
  916. devm_kfree(dev, pdata);
  917. err:
  918. return NULL;
  919. }
  920. static int isdbt_probe(struct platform_device *pdev)
  921. {
  922. int res=0;
  923. pr_info("%s\n", __func__);
  924. open_cnt = 0;
  925. isdbt_pdata = isdbt_populate_dt_pdata(&pdev->dev);
  926. if (!isdbt_pdata) {
  927. pr_err("%s : isdbt_pdata is NULL.\n", __func__);
  928. return -ENODEV;
  929. }
  930. isdbt_gpio_init();
  931. fc8300_xtal_freq = bbm_xtal_freq;
  932. res = misc_register(&fc8300_misc_device);
  933. if (res < 0) {
  934. pr_info("isdbt init fail : %d\n", res);
  935. return res;
  936. }
  937. hInit = kmalloc(sizeof(struct ISDBT_INIT_INFO_T), GFP_KERNEL);
  938. #if defined(BBM_I2C_TSIF) || defined(BBM_I2C_SPI)
  939. res = bbm_com_hostif_select(hInit, BBM_I2C);
  940. pr_info("isdbt host interface select BBM_I2C!\n");
  941. #else
  942. pr_info("isdbt host interface select BBM_SPI !\n");
  943. res = bbm_com_hostif_select(hInit, BBM_SPI);
  944. #endif
  945. if (res)
  946. pr_info("isdbt host interface select fail!\n");
  947. #ifndef BBM_I2C_TSIF
  948. if (!isdbt_kthread) {
  949. pr_info("kthread run\n");
  950. isdbt_kthread = kthread_run(isdbt_thread
  951. , (void *)hInit, "isdbt_thread");
  952. }
  953. #endif
  954. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  955. res = device_register(&isdbt_sysfs_dev);
  956. if(res){
  957. pr_err("[W1] error register isdbt_sysfs_dev device\n");
  958. } else {
  959. res = sysfs_create_file(&isdbt_sysfs_dev.kobj, &dev_attr_isdbt_signal_source.attr);
  960. if(res < 0)
  961. pr_info("couldn't create sysfs for F-type cable\n");
  962. else
  963. pr_info("created sysfs for F-type cable\n");
  964. }
  965. #endif
  966. INIT_LIST_HEAD(&(hInit->hHead));
  967. return 0;
  968. }
  969. static int isdbt_remove(struct platform_device *pdev)
  970. {
  971. pr_info("ISDBT remove\n");
  972. return 0;
  973. }
  974. static int isdbt_suspend(struct platform_device *pdev, pm_message_t mesg)
  975. {
  976. int value;
  977. #ifdef CONFIG_ISDBT_SPMI
  978. u8 reg = 0x00;
  979. pr_info("%s, Turning ISDBT_CLK off\n", __func__);
  980. if(isdbt_spmi) {
  981. int rc = spmi_ext_register_writel(isdbt_spmi->spmi->ctrl, isdbt_spmi->spmi->sid, spmi_addr,&reg, 1);
  982. if (rc) {
  983. pr_err("%s, Unable to write from addr=%x, rc(%d)\n", __func__, spmi_addr, rc );
  984. }
  985. }
  986. else {
  987. pr_err("%s ERROR !! isdbt_spmi is NULL !!\n", __func__);
  988. }
  989. #endif
  990. value = gpio_get_value_cansleep(isdbt_pdata->gpio_en);
  991. pr_info("%s value = %d\n",__func__,value);
  992. if(value == 1)
  993. {
  994. gpio_set_value(isdbt_pdata->gpio_en, 0);
  995. }
  996. return 0;
  997. }
  998. static int isdbt_resume(struct platform_device *pdev)
  999. {
  1000. return 0;
  1001. }
  1002. static const struct of_device_id isdbt_match_table[] = {
  1003. { .compatible = "isdb_fc8300_pdata",
  1004. },
  1005. {}
  1006. };
  1007. static struct platform_driver isdb_fc8300_driver = {
  1008. .driver = {
  1009. .owner = THIS_MODULE,
  1010. .name = "isdbt",
  1011. .of_match_table = isdbt_match_table,
  1012. },
  1013. .probe = isdbt_probe,
  1014. .remove = isdbt_remove,
  1015. .suspend = isdbt_suspend,
  1016. .resume = isdbt_resume,
  1017. };
  1018. int isdbt_init(void)
  1019. {
  1020. s32 res;
  1021. pr_info("isdbt_fc8300_init started\n");
  1022. #ifdef CONFIG_ISDBT_SPMI
  1023. res = spmi_driver_register(&qpnp_isdbt_clk_driver);
  1024. if(res < 0){
  1025. pr_err("Error : qpnp isdbt clk init fail : %d\n", res);
  1026. }
  1027. #endif
  1028. // res = misc_register(&fc8300_misc_device);
  1029. res = platform_driver_register(&isdb_fc8300_driver);
  1030. if (res < 0) {
  1031. pr_info("isdbt init fail : %d\n", res);
  1032. return res;
  1033. }
  1034. return 0;
  1035. }
  1036. void isdbt_exit(void)
  1037. {
  1038. pr_info("isdb_fc8300_exit \n");
  1039. #ifndef BBM_I2C_TSIF
  1040. free_irq(gpio_to_irq(isdbt_pdata->gpio_int), NULL);
  1041. gpio_free(isdbt_pdata->gpio_int);
  1042. #endif
  1043. gpio_free(isdbt_pdata->gpio_rst);
  1044. gpio_free(isdbt_pdata->gpio_en);
  1045. // gpio_free(isdbt_pdata->gpio_i2c_sda);
  1046. // gpio_free(isdbt_pdata->gpio_i2c_scl);
  1047. #ifndef BBM_I2C_TSIF
  1048. if (isdbt_kthread)
  1049. kthread_stop(isdbt_kthread);
  1050. isdbt_kthread = NULL;
  1051. #endif
  1052. #ifdef CONFIG_ISDBT_F_TYPE_ANTENNA
  1053. gpio_free(isdbt_pdata->gpio_tmm_sw);
  1054. sysfs_remove_file(&isdbt_sysfs_dev.kobj, &dev_attr_isdbt_signal_source.attr);
  1055. device_unregister(&isdbt_sysfs_dev);
  1056. #endif
  1057. bbm_com_hostif_deselect(hInit);
  1058. isdbt_hw_deinit();
  1059. platform_driver_unregister(&isdb_fc8300_driver);
  1060. misc_deregister(&fc8300_misc_device);
  1061. if (hInit != NULL)
  1062. kfree(hInit);
  1063. #ifdef CONFIG_ISDBT_SPMI
  1064. spmi_driver_unregister(&qpnp_isdbt_clk_driver);
  1065. #endif
  1066. }
  1067. module_init(isdbt_init);
  1068. module_exit(isdbt_exit);
  1069. MODULE_LICENSE("Dual BSD/GPL");