116 files changed, 25845 insertions, 36303 deletions
diff --git a/drivers/stream_input/parser/demux/hw_demux/frontend.c b/drivers/stream_input/parser/demux/hw_demux/frontend.c index 2e40179..90a70c4 100644 --- a/drivers/stream_input/parser/demux/hw_demux/frontend.c +++ b/drivers/stream_input/parser/demux/hw_demux/frontend.c @@ -38,6 +38,7 @@ #include <linux/string.h> #include <linux/pinctrl/consumer.h> #include <linux/reset.h> +#include <linux/of_gpio.h> #include <linux/amlogic/media/utils/amstream.h> //#include <linux/clk.h> #include "c_stb_define.h" @@ -45,94 +46,16 @@ #include "../aml_dvb.h" #include "dvb_reg.h" -#include "../../../tv_frontend/aml_fe.h" #include "demod_gt.h" #include "../../../../common/media_clock/switch/amports_gate.h" #define pr_error(fmt, args...) printk("DVB: " fmt, ## args) #define pr_inf(fmt, args...) printk("DVB: " fmt, ## args) -typedef enum __demod_type -{ - DEMOD_INVALID, - DEMOD_INTERNAL, - DEMOD_ATBM8881, - DEMOD_MAX_NUM -}demod_type; - -typedef enum __tuner_type -{ - TUNER_INVALID, - TUNER_SI2151, - TUNER_MXL661, - TUNER_SI2159, - TUNER_R842, - TUNER_R840, - TUNER_MAX_NUM -}tuner_type; - static struct dvb_frontend *frontend[FE_DEV_COUNT] = {NULL, NULL}; -static demod_type s_demod_type[FE_DEV_COUNT] = {DEMOD_INVALID, DEMOD_INVALID}; -static tuner_type s_tuner_type[FE_DEV_COUNT] = {TUNER_INVALID, TUNER_INVALID}; - -static int dvb_attach_tuner(struct dvb_frontend *fe, struct aml_tuner *tuner, tuner_type *type) -{ - struct tuner_config *cfg = &tuner->cfg; - struct i2c_adapter *i2c_adap = tuner->i2c_adp; - - switch (cfg->id) { - case AM_TUNER_R840: - if (!dvb_attach(r840_attach, fe, i2c_adap, cfg)) { - pr_error("dvb attach r840_attach tuner error\n"); - return -1; - } else { - pr_inf("r840_attach attach sucess\n"); - *type = TUNER_R840; - } - break; - case AM_TUNER_R842: - if (!dvb_attach(r842_attach, fe, i2c_adap, cfg)) { - pr_error("dvb attach r842_attach tuner error\n"); - return -1; - } else { - pr_inf("r842_attach attach sucess\n"); - *type = TUNER_R842; - } - break; - case AM_TUNER_SI2151: - if (!dvb_attach(si2151_attach, fe, i2c_adap, cfg)) { - pr_error("dvb attach tuner error\n"); - return -1; - } else { - pr_inf("si2151 attach sucess\n"); - *type = TUNER_SI2151; - } - break; - case AM_TUNER_SI2159: - if (!dvb_attach(si2159_attach, fe, i2c_adap, cfg)) { - pr_error("dvb attach si2159_attach tuner error\n"); - return -1; - } else { - pr_inf("si2159_attach attach sucess\n"); - *type = TUNER_SI2159; - } - break; - case AM_TUNER_MXL661: - if (!dvb_attach(mxl661_attach, fe, i2c_adap, cfg)) { - pr_error("dvb attach mxl661_attach tuner error\n"); - return -1; - } else { - pr_inf("mxl661_attach attach sucess\n"); - *type = TUNER_MXL661; - } - break; - default: - pr_error("can't support tuner type: %d\n", cfg->id); - break; - } +static enum dtv_demod_type s_demod_type[FE_DEV_COUNT] = {AM_DTV_DEMOD_NONE, AM_DTV_DEMOD_NONE}; +static enum tuner_type s_tuner_type[FE_DEV_COUNT] = {AM_TUNER_NONE, AM_TUNER_NONE}; - return 0; -} ssize_t stb_show_tuner_setting(struct class *class, struct class_attribute *attr, char *buf) @@ -196,9 +119,13 @@ ssize_t stb_store_tuner_setting(struct class *class, if (frontend[i] == NULL) continue; - if (dvb_attach_tuner(frontend[i], tuner, &s_tuner_type[i]) < 0) { - pr_error("attach tuner %d failed\n", dvb->tuner_cur); + if (aml_attach_tuner(tuner->cfg.id, frontend[i], &tuner->cfg) == NULL) { + s_tuner_type[i] = AM_TUNER_NONE; + pr_error("tuner[%d] [type = %d] attach error.\n", dvb->tuner_cur, tuner->cfg.id); goto EXIT; + } else { + s_tuner_type[i] = tuner->cfg.id; + pr_error("tuner[%d] [type = %d] attach sucess.\n", dvb->tuner_cur, tuner->cfg.id); } } @@ -213,13 +140,13 @@ EXIT: int frontend_probe(struct platform_device *pdev) { - struct amlfe_exp_config config; + struct demod_config config; + struct tuner_config *tuner_cfg = NULL; char buf[32]; const char *str = NULL; struct device_node *node_tuner = NULL; struct device_node *node_i2c = NULL; u32 i2c_addr = 0xFFFFFFFF; - struct tuner_config *cfg = NULL; u32 value = 0; int i = 0; int ret =0; @@ -227,25 +154,28 @@ int frontend_probe(struct platform_device *pdev) struct aml_dvb *advb = aml_get_dvb_device(); for (i=0; i<FE_DEV_COUNT; i++) { + memset(&config, 0, sizeof(struct demod_config)); + memset(buf, 0, 32); snprintf(buf, sizeof(buf), "fe%d_mode", i); ret = of_property_read_string(pdev->dev.of_node, buf, &str); if (ret) { continue; } - if (!strcmp(str,"internal")) - { - config.set_mode = 0; - frontend[i] = dvb_attach(aml_dtvdm_attach,&config); + + if (!strcmp(str, "internal")) { + config.mode = 0; + config.id = AM_DTV_DEMOD_AMLDTV; + frontend[i] = aml_attach_dtvdemod(config.id, &config); if (frontend[i] == NULL) { - pr_error("dvb attach demod error\n"); + s_demod_type[i] = AM_DTV_DEMOD_NONE; + pr_error("internal dtvdemod [type = %d] attach error.\n", config.id); goto error_fe; } else { - pr_inf("dtvdemod attatch sucess\n"); - s_demod_type[i] = DEMOD_INTERNAL; + s_demod_type[i] = config.id; + pr_error("internal dtvdemod [type = %d] attach success.\n", config.id); } - memset(&cfg, 0, sizeof(struct tuner_config)); memset(buf, 0, 32); snprintf(buf, sizeof(buf), "fe%d_tuner",i); node_tuner = of_parse_phandle(pdev->dev.of_node, buf, 0); @@ -281,20 +211,9 @@ int frontend_probe(struct platform_device *pdev) ret = 0; continue; } else { - if (!strncmp(str, "mxl661_tuner", 12)) - advb->tuners[j].cfg.id = AM_TUNER_MXL661; - else if (!strncmp(str, "si2151_tuner", 12)) - advb->tuners[j].cfg.id = AM_TUNER_SI2151; - else if (!strncmp(str, "si2159_tuner", 12)) - advb->tuners[j].cfg.id = AM_TUNER_SI2159; - else if (!strncmp(str, "r840_tuner", 10)) - advb->tuners[j].cfg.id = AM_TUNER_R840; - else if (!strncmp(str, "r842_tuner", 10)) - advb->tuners[j].cfg.id = AM_TUNER_R842; - else { - pr_err("nonsupport tuner: %s.\n", str); - advb->tuners[j].cfg.id = AM_TUNER_NONE; - } + advb->tuners[j].cfg.id = aml_get_tuner_type(str); + if (advb->tuners[j].cfg.id == AM_TUNER_NONE) + pr_err("can't support tuner: %s.\n", str); } snprintf(buf, sizeof(buf), "tuner_i2c_adap_%d", j); @@ -302,9 +221,9 @@ int frontend_probe(struct platform_device *pdev) if (!node_i2c) { pr_error("tuner_i2c_adap_id error\n"); } else { - advb->tuners[j].i2c_adp = of_find_i2c_adapter_by_node(node_i2c); + advb->tuners[j].cfg.i2c_adap = of_find_i2c_adapter_by_node(node_i2c); of_node_put(node_i2c); - if (advb->tuners[j].i2c_adp == NULL) { + if (advb->tuners[j].cfg.i2c_adap == NULL) { pr_error("i2c_get_adapter error\n"); of_node_put(node_tuner); goto error_fe; @@ -347,9 +266,14 @@ int frontend_probe(struct platform_device *pdev) frontend[i]->callback = NULL; if (advb->tuner_cur >= 0) { - if (dvb_attach_tuner(frontend[i], &advb->tuners[advb->tuner_cur], &s_tuner_type[i]) < 0) { - pr_error("attach tuner failed\n"); + tuner_cfg = &advb->tuners[advb->tuner_cur].cfg; + if (aml_attach_tuner(tuner_cfg->id, frontend[i], tuner_cfg) == NULL) { + s_tuner_type[i] = AM_TUNER_NONE; + pr_error("tuner [type = %d] attach error.\n", tuner_cfg->id); goto error_fe; + } else { + s_tuner_type[i] = tuner_cfg->id; + pr_error("tuner [type = %d] attach sucess.\n", tuner_cfg->id); } } @@ -358,81 +282,36 @@ int frontend_probe(struct platform_device *pdev) pr_error("register dvb frontend failed\n"); goto error_fe; } - } else if(!strcmp(str,"external")) { - const char *name = NULL; - struct amlfe_demod_config config; - - config.dev_id = i; - memset(buf, 0, 32); - snprintf(buf, sizeof(buf), "fe%d_demod",i); - ret = of_property_read_string(pdev->dev.of_node, buf, &name); + } else if(!strcmp(str, "external")) { + config.mode = 1; + config.id = AM_DTV_DEMOD_NONE; + ret = aml_get_dts_demod_config(pdev->dev.of_node, &config, i); if (ret) { - ret = 0; + pr_err("can't find demod %d.\n", i); continue; } memset(buf, 0, 32); - snprintf(buf, sizeof(buf), "fe%d_i2c_adap_id",i); - node_i2c = of_parse_phandle(pdev->dev.of_node,buf,0); - if (!node_i2c) { - pr_error("demod%d_i2c_adap_id error\n", i); - } else { - config.i2c_adap = of_find_i2c_adapter_by_node(node_i2c); - of_node_put(node_i2c); - if (config.i2c_adap == NULL) { - pr_error("i2c_get_adapter error\n"); - goto error_fe; - } - } + snprintf(buf, sizeof(buf), "fe%d_tuner", i); + node_tuner = of_parse_phandle(pdev->dev.of_node, buf, 0); + if (node_tuner) { + aml_get_dts_tuner_config(node_tuner, &config.tuner0, 0); + aml_get_dts_tuner_config(node_tuner, &config.tuner1, 1); + } else + pr_err("can't find %s.\n", buf); - memset(buf, 0, 32); - snprintf(buf, sizeof(buf), "fe%d_demod_i2c_addr",i); - ret = of_property_read_u32(pdev->dev.of_node, buf,&config.i2c_addr); - if (ret) { - pr_error("i2c_addr error\n"); - goto error_fe; - } + of_node_put(node_tuner); - memset(buf, 0, 32); - snprintf(buf, sizeof(buf), "fe%d_ts",i); - ret = of_property_read_u32(pdev->dev.of_node, buf,&config.ts); - if (ret) { - pr_error("ts error\n"); + frontend[i] = aml_attach_dtvdemod(config.id, &config); + if (frontend[i] == NULL) { + s_demod_type[i] = AM_DTV_DEMOD_NONE; + pr_error("external dtvdemod [type = %d] attach error.\n", config.id); goto error_fe; - } - - memset(buf, 0, 32); - snprintf(buf, sizeof(buf), "fe%d_reset_gpio",i); - ret = of_property_read_string(pdev->dev.of_node, buf, &str); - if (!ret) { - config.reset_gpio = - of_get_named_gpio_flags(pdev->dev.of_node, - buf, 0, NULL); - pr_inf("%s: %d\n", buf, config.reset_gpio); } else { - config.reset_gpio = -1; - pr_error("cannot find resource \"%s\"\n", buf); - goto error_fe; - } - - memset(buf, 0, 32); - snprintf(buf, sizeof(buf), "fe%d_reset_value",i); - ret = of_property_read_u32(pdev->dev.of_node, buf,&config.reset_value); - if (ret) { - pr_error("reset_value error\n"); - goto error_fe; + s_demod_type[i] = config.id; + pr_error("external dtvdemod [type = %d] attach success.\n", config.id); } - if (!strcmp(name,"Atbm8881")) { - frontend[i] = dvb_attach(atbm8881_attach,&config); - if (frontend[i] == NULL) { - pr_error("dvb attach demod error\n"); - goto error_fe; - } else { - pr_inf("dtvdemod attatch sucess\n"); - s_demod_type[i] = DEMOD_ATBM8881; - } - } if (frontend[i]) { ret = dvb_register_frontend(&advb->dvb_adapter, frontend[i]); if (ret) { @@ -447,31 +326,12 @@ int frontend_probe(struct platform_device *pdev) return 0; error_fe: for (i=0; i<FE_DEV_COUNT; i++) { - if (s_demod_type[i] == DEMOD_INTERNAL) { - dvb_detach(aml_dtvdm_attach); - frontend[i] = NULL; - s_demod_type[i] = DEMOD_INVALID; - }else if (s_demod_type[i] == DEMOD_ATBM8881) { - dvb_detach(atbm8881_attach); - frontend[i] = NULL; - s_demod_type[i] = DEMOD_INVALID; - } - if (s_tuner_type[i] == TUNER_SI2151) { - dvb_detach(si2151_attach); - s_tuner_type[i] = TUNER_INVALID; - }else if (s_tuner_type[i] == TUNER_MXL661) { - dvb_detach(mxl661_attach); - s_tuner_type[i] = TUNER_INVALID; - }else if (s_tuner_type[i] == TUNER_SI2159) { - dvb_detach(si2159_attach); - s_tuner_type[i] = TUNER_INVALID; - }else if (s_tuner_type[i] == TUNER_R842) { - dvb_detach(r842_attach); - s_tuner_type[i] = TUNER_INVALID; - }else if (s_tuner_type[i] == TUNER_R840) { - dvb_detach(r840_attach); - s_tuner_type[i] = TUNER_INVALID; - } + aml_detach_dtvdemod(s_demod_type[i]); + frontend[i] = NULL; + s_demod_type[i] = AM_DTV_DEMOD_NONE; + + aml_detach_tuner(s_tuner_type[i]); + s_tuner_type[i] = AM_TUNER_NONE; } if (advb->tuners) @@ -485,33 +345,24 @@ int frontend_remove(void) int i; for (i=0; i<FE_DEV_COUNT; i++) { - if (s_demod_type[i] == DEMOD_INTERNAL) { - dvb_detach(aml_dtvdm_attach); - }else if (s_demod_type[i] == DEMOD_ATBM8881) { - dvb_detach(atbm8881_attach); - } - if (s_tuner_type[i] == TUNER_SI2151) { - dvb_detach(si2151_attach); - }else if (s_tuner_type[i] == TUNER_MXL661) { - dvb_detach(mxl661_attach); - }else if (s_tuner_type[i] == TUNER_SI2159) { - dvb_detach(si2159_attach); - }else if (s_tuner_type[i] == TUNER_R842) { - dvb_detach(r842_attach); - }else if (s_tuner_type[i] == TUNER_R840) { - dvb_detach(r840_attach); - } + aml_detach_dtvdemod(s_demod_type[i]); + + aml_detach_tuner(s_tuner_type[i]); - if (frontend[i] && \ - ( (s_tuner_type[i] == TUNER_SI2151) || (s_tuner_type[i] == TUNER_MXL661) || (s_tuner_type[i] == TUNER_SI2159) || (s_tuner_type[i] == TUNER_R842) || (s_tuner_type[i] == TUNER_R840)) \ - ) - { + if (frontend[i] && + ((s_tuner_type[i] == AM_TUNER_SI2151) + || (s_tuner_type[i] == AM_TUNER_MXL661) + || (s_tuner_type[i] == AM_TUNER_SI2159) + || (s_tuner_type[i] == AM_TUNER_R842) + || (s_tuner_type[i] == AM_TUNER_R840) + || (s_tuner_type[i] == AM_TUNER_ATBM2040))) { dvb_unregister_frontend(frontend[i]); dvb_frontend_detach(frontend[i]); } + frontend[i] = NULL; - s_demod_type[i] = DEMOD_INVALID; - s_tuner_type[i] = TUNER_INVALID; + s_demod_type[i] = AM_DTV_DEMOD_NONE; + s_tuner_type[i] = AM_TUNER_NONE; } return 0; |