diff options
author | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2014-12-23 10:48:07 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-02-02 10:16:01 -0500 |
commit | 2b0aac3011bc7a9db27791bed4978554263ef079 (patch) | |
tree | 23d391366a7f190d533dddc6d848e2e42a091a7b /drivers/media/pci | |
parent | 05439b1a36935992785c4f28f6693e73820321cb (diff) |
[media] cx23885: move CI/MAC registration to a separate function
As reported by smatch:
drivers/media/pci/cx23885/cx23885-dvb.c:2080 dvb_register() Function too hairy. Giving up.
This is indeed a too complex function, with lots of stuff inside.
Breaking this into two functions makes it a little bit less hairy.
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/pci')
-rw-r--r-- | drivers/media/pci/cx23885/cx23885-dvb.c | 272 |
1 files changed, 135 insertions, 137 deletions
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c index 351fa952f210..45fbe1e4d2d0 100644 --- a/drivers/media/pci/cx23885/cx23885-dvb.c +++ b/drivers/media/pci/cx23885/cx23885-dvb.c | |||
@@ -1069,6 +1069,116 @@ static struct dib7000p_config dib7070p_dib7000p_config = { | |||
1069 | .hostbus_diversity = 1, | 1069 | .hostbus_diversity = 1, |
1070 | }; | 1070 | }; |
1071 | 1071 | ||
1072 | static int dvb_register_ci_mac(struct cx23885_tsport *port) | ||
1073 | { | ||
1074 | struct cx23885_dev *dev = port->dev; | ||
1075 | struct i2c_client *client_ci = NULL; | ||
1076 | struct vb2_dvb_frontend *fe0; | ||
1077 | |||
1078 | fe0 = vb2_dvb_get_frontend(&port->frontends, 1); | ||
1079 | if (!fe0) | ||
1080 | return -EINVAL; | ||
1081 | |||
1082 | switch (dev->board) { | ||
1083 | case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: { | ||
1084 | static struct netup_card_info cinfo; | ||
1085 | |||
1086 | netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo); | ||
1087 | memcpy(port->frontends.adapter.proposed_mac, | ||
1088 | cinfo.port[port->nr - 1].mac, 6); | ||
1089 | printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n", | ||
1090 | port->nr, port->frontends.adapter.proposed_mac); | ||
1091 | |||
1092 | netup_ci_init(port); | ||
1093 | return 0; | ||
1094 | } | ||
1095 | case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: { | ||
1096 | struct altera_ci_config netup_ci_cfg = { | ||
1097 | .dev = dev,/* magic number to identify*/ | ||
1098 | .adapter = &port->frontends.adapter,/* for CI */ | ||
1099 | .demux = &fe0->dvb.demux,/* for hw pid filter */ | ||
1100 | .fpga_rw = netup_altera_fpga_rw, | ||
1101 | }; | ||
1102 | |||
1103 | altera_ci_init(&netup_ci_cfg, port->nr); | ||
1104 | return 0; | ||
1105 | } | ||
1106 | case CX23885_BOARD_TEVII_S470: { | ||
1107 | u8 eeprom[256]; /* 24C02 i2c eeprom */ | ||
1108 | |||
1109 | if (port->nr != 1) | ||
1110 | return 0; | ||
1111 | |||
1112 | /* Read entire EEPROM */ | ||
1113 | dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; | ||
1114 | tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom)); | ||
1115 | printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0); | ||
1116 | memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6); | ||
1117 | return 0; | ||
1118 | } | ||
1119 | case CX23885_BOARD_DVBSKY_T9580: | ||
1120 | case CX23885_BOARD_DVBSKY_S950: | ||
1121 | case CX23885_BOARD_DVBSKY_S952: | ||
1122 | case CX23885_BOARD_DVBSKY_T982: { | ||
1123 | u8 eeprom[256]; /* 24C02 i2c eeprom */ | ||
1124 | |||
1125 | if (port->nr > 2) | ||
1126 | return 0; | ||
1127 | |||
1128 | /* Read entire EEPROM */ | ||
1129 | dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; | ||
1130 | tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, | ||
1131 | sizeof(eeprom)); | ||
1132 | printk(KERN_INFO "%s port %d MAC address: %pM\n", | ||
1133 | cx23885_boards[dev->board].name, port->nr, | ||
1134 | eeprom + 0xc0 + (port->nr-1) * 8); | ||
1135 | memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 + | ||
1136 | (port->nr-1) * 8, 6); | ||
1137 | return 0; | ||
1138 | } | ||
1139 | case CX23885_BOARD_DVBSKY_S950C: | ||
1140 | case CX23885_BOARD_DVBSKY_T980C: | ||
1141 | case CX23885_BOARD_TT_CT2_4500_CI: { | ||
1142 | u8 eeprom[256]; /* 24C02 i2c eeprom */ | ||
1143 | struct sp2_config sp2_config; | ||
1144 | struct i2c_board_info info; | ||
1145 | struct cx23885_i2c *i2c_bus2 = &dev->i2c_bus[1]; | ||
1146 | |||
1147 | /* attach CI */ | ||
1148 | memset(&sp2_config, 0, sizeof(sp2_config)); | ||
1149 | sp2_config.dvb_adap = &port->frontends.adapter; | ||
1150 | sp2_config.priv = port; | ||
1151 | sp2_config.ci_control = cx23885_sp2_ci_ctrl; | ||
1152 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
1153 | strlcpy(info.type, "sp2", I2C_NAME_SIZE); | ||
1154 | info.addr = 0x40; | ||
1155 | info.platform_data = &sp2_config; | ||
1156 | request_module(info.type); | ||
1157 | client_ci = i2c_new_device(&i2c_bus2->i2c_adap, &info); | ||
1158 | if (client_ci == NULL || client_ci->dev.driver == NULL) | ||
1159 | return -ENODEV; | ||
1160 | if (!try_module_get(client_ci->dev.driver->owner)) { | ||
1161 | i2c_unregister_device(client_ci); | ||
1162 | return -ENODEV; | ||
1163 | } | ||
1164 | port->i2c_client_ci = client_ci; | ||
1165 | |||
1166 | if (port->nr != 1) | ||
1167 | return 0; | ||
1168 | |||
1169 | /* Read entire EEPROM */ | ||
1170 | dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; | ||
1171 | tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, | ||
1172 | sizeof(eeprom)); | ||
1173 | printk(KERN_INFO "%s MAC address: %pM\n", | ||
1174 | cx23885_boards[dev->board].name, eeprom + 0xc0); | ||
1175 | memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6); | ||
1176 | return 0; | ||
1177 | } | ||
1178 | } | ||
1179 | return 0; | ||
1180 | } | ||
1181 | |||
1072 | static int dvb_register(struct cx23885_tsport *port) | 1182 | static int dvb_register(struct cx23885_tsport *port) |
1073 | { | 1183 | { |
1074 | struct dib7000p_ops dib7000p_ops; | 1184 | struct dib7000p_ops dib7000p_ops; |
@@ -1077,11 +1187,10 @@ static int dvb_register(struct cx23885_tsport *port) | |||
1077 | struct vb2_dvb_frontend *fe0, *fe1 = NULL; | 1187 | struct vb2_dvb_frontend *fe0, *fe1 = NULL; |
1078 | struct si2168_config si2168_config; | 1188 | struct si2168_config si2168_config; |
1079 | struct si2157_config si2157_config; | 1189 | struct si2157_config si2157_config; |
1080 | struct sp2_config sp2_config; | ||
1081 | struct m88ts2022_config m88ts2022_config; | 1190 | struct m88ts2022_config m88ts2022_config; |
1082 | struct i2c_board_info info; | 1191 | struct i2c_board_info info; |
1083 | struct i2c_adapter *adapter; | 1192 | struct i2c_adapter *adapter; |
1084 | struct i2c_client *client_demod = NULL, *client_tuner = NULL, *client_ci = NULL; | 1193 | struct i2c_client *client_demod = NULL, *client_tuner = NULL; |
1085 | const struct m88ds3103_config *p_m88ds3103_config = NULL; | 1194 | const struct m88ds3103_config *p_m88ds3103_config = NULL; |
1086 | int (*p_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage) = NULL; | 1195 | int (*p_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage) = NULL; |
1087 | int mfe_shared = 0; /* bus not shared by default */ | 1196 | int mfe_shared = 0; /* bus not shared by default */ |
@@ -1812,17 +1921,11 @@ static int dvb_register(struct cx23885_tsport *port) | |||
1812 | request_module(info.type); | 1921 | request_module(info.type); |
1813 | client_tuner = i2c_new_device(adapter, &info); | 1922 | client_tuner = i2c_new_device(adapter, &info); |
1814 | if (client_tuner == NULL || | 1923 | if (client_tuner == NULL || |
1815 | client_tuner->dev.driver == NULL) { | 1924 | client_tuner->dev.driver == NULL) |
1816 | module_put(client_demod->dev.driver->owner); | ||
1817 | i2c_unregister_device(client_demod); | ||
1818 | port->i2c_client_demod = NULL; | ||
1819 | goto frontend_detach; | 1925 | goto frontend_detach; |
1820 | } | 1926 | |
1821 | if (!try_module_get(client_tuner->dev.driver->owner)) { | 1927 | if (!try_module_get(client_tuner->dev.driver->owner)) { |
1822 | i2c_unregister_device(client_tuner); | 1928 | i2c_unregister_device(client_tuner); |
1823 | module_put(client_demod->dev.driver->owner); | ||
1824 | i2c_unregister_device(client_demod); | ||
1825 | port->i2c_client_demod = NULL; | ||
1826 | goto frontend_detach; | 1929 | goto frontend_detach; |
1827 | } | 1930 | } |
1828 | port->i2c_client_tuner = client_tuner; | 1931 | port->i2c_client_tuner = client_tuner; |
@@ -1862,17 +1965,11 @@ static int dvb_register(struct cx23885_tsport *port) | |||
1862 | info.platform_data = &si2157_config; | 1965 | info.platform_data = &si2157_config; |
1863 | request_module(info.type); | 1966 | request_module(info.type); |
1864 | client_tuner = i2c_new_device(adapter, &info); | 1967 | client_tuner = i2c_new_device(adapter, &info); |
1865 | if (client_tuner == NULL || client_tuner->dev.driver == NULL) { | 1968 | if (client_tuner == NULL || |
1866 | module_put(client_demod->dev.driver->owner); | 1969 | client_tuner->dev.driver == NULL) |
1867 | i2c_unregister_device(client_demod); | ||
1868 | port->i2c_client_demod = NULL; | ||
1869 | goto frontend_detach; | 1970 | goto frontend_detach; |
1870 | } | ||
1871 | if (!try_module_get(client_tuner->dev.driver->owner)) { | 1971 | if (!try_module_get(client_tuner->dev.driver->owner)) { |
1872 | i2c_unregister_device(client_tuner); | 1972 | i2c_unregister_device(client_tuner); |
1873 | module_put(client_demod->dev.driver->owner); | ||
1874 | i2c_unregister_device(client_demod); | ||
1875 | port->i2c_client_demod = NULL; | ||
1876 | goto frontend_detach; | 1973 | goto frontend_detach; |
1877 | } | 1974 | } |
1878 | port->i2c_client_tuner = client_tuner; | 1975 | port->i2c_client_tuner = client_tuner; |
@@ -2006,17 +2103,11 @@ static int dvb_register(struct cx23885_tsport *port) | |||
2006 | info.platform_data = &si2157_config; | 2103 | info.platform_data = &si2157_config; |
2007 | request_module(info.type); | 2104 | request_module(info.type); |
2008 | client_tuner = i2c_new_device(adapter, &info); | 2105 | client_tuner = i2c_new_device(adapter, &info); |
2009 | if (client_tuner == NULL || client_tuner->dev.driver == NULL) { | 2106 | if (client_tuner == NULL || |
2010 | module_put(client_demod->dev.driver->owner); | 2107 | client_tuner->dev.driver == NULL) |
2011 | i2c_unregister_device(client_demod); | ||
2012 | port->i2c_client_demod = NULL; | ||
2013 | goto frontend_detach; | 2108 | goto frontend_detach; |
2014 | } | ||
2015 | if (!try_module_get(client_tuner->dev.driver->owner)) { | 2109 | if (!try_module_get(client_tuner->dev.driver->owner)) { |
2016 | i2c_unregister_device(client_tuner); | 2110 | i2c_unregister_device(client_tuner); |
2017 | module_put(client_demod->dev.driver->owner); | ||
2018 | i2c_unregister_device(client_demod); | ||
2019 | port->i2c_client_demod = NULL; | ||
2020 | goto frontend_detach; | 2111 | goto frontend_detach; |
2021 | } | 2112 | } |
2022 | port->i2c_client_tuner = client_tuner; | 2113 | port->i2c_client_tuner = client_tuner; |
@@ -2144,122 +2235,29 @@ static int dvb_register(struct cx23885_tsport *port) | |||
2144 | if (ret) | 2235 | if (ret) |
2145 | goto frontend_detach; | 2236 | goto frontend_detach; |
2146 | 2237 | ||
2147 | /* init CI & MAC */ | 2238 | ret = dvb_register_ci_mac(port); |
2148 | switch (dev->board) { | 2239 | if (ret) |
2149 | case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: { | 2240 | goto frontend_detach; |
2150 | static struct netup_card_info cinfo; | ||
2151 | |||
2152 | netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo); | ||
2153 | memcpy(port->frontends.adapter.proposed_mac, | ||
2154 | cinfo.port[port->nr - 1].mac, 6); | ||
2155 | printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n", | ||
2156 | port->nr, port->frontends.adapter.proposed_mac); | ||
2157 | |||
2158 | netup_ci_init(port); | ||
2159 | break; | ||
2160 | } | ||
2161 | case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: { | ||
2162 | struct altera_ci_config netup_ci_cfg = { | ||
2163 | .dev = dev,/* magic number to identify*/ | ||
2164 | .adapter = &port->frontends.adapter,/* for CI */ | ||
2165 | .demux = &fe0->dvb.demux,/* for hw pid filter */ | ||
2166 | .fpga_rw = netup_altera_fpga_rw, | ||
2167 | }; | ||
2168 | |||
2169 | altera_ci_init(&netup_ci_cfg, port->nr); | ||
2170 | break; | ||
2171 | } | ||
2172 | case CX23885_BOARD_TEVII_S470: { | ||
2173 | u8 eeprom[256]; /* 24C02 i2c eeprom */ | ||
2174 | |||
2175 | if (port->nr != 1) | ||
2176 | break; | ||
2177 | |||
2178 | /* Read entire EEPROM */ | ||
2179 | dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; | ||
2180 | tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom)); | ||
2181 | printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0); | ||
2182 | memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6); | ||
2183 | break; | ||
2184 | } | ||
2185 | case CX23885_BOARD_DVBSKY_T9580: | ||
2186 | case CX23885_BOARD_DVBSKY_S950: | ||
2187 | case CX23885_BOARD_DVBSKY_S952: | ||
2188 | case CX23885_BOARD_DVBSKY_T982: { | ||
2189 | u8 eeprom[256]; /* 24C02 i2c eeprom */ | ||
2190 | |||
2191 | if (port->nr > 2) | ||
2192 | break; | ||
2193 | |||
2194 | /* Read entire EEPROM */ | ||
2195 | dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; | ||
2196 | tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, | ||
2197 | sizeof(eeprom)); | ||
2198 | printk(KERN_INFO "%s port %d MAC address: %pM\n", | ||
2199 | cx23885_boards[dev->board].name, port->nr, | ||
2200 | eeprom + 0xc0 + (port->nr-1) * 8); | ||
2201 | memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 + | ||
2202 | (port->nr-1) * 8, 6); | ||
2203 | break; | ||
2204 | } | ||
2205 | case CX23885_BOARD_DVBSKY_S950C: | ||
2206 | case CX23885_BOARD_DVBSKY_T980C: | ||
2207 | case CX23885_BOARD_TT_CT2_4500_CI: { | ||
2208 | u8 eeprom[256]; /* 24C02 i2c eeprom */ | ||
2209 | |||
2210 | /* attach CI */ | ||
2211 | memset(&sp2_config, 0, sizeof(sp2_config)); | ||
2212 | sp2_config.dvb_adap = &port->frontends.adapter; | ||
2213 | sp2_config.priv = port; | ||
2214 | sp2_config.ci_control = cx23885_sp2_ci_ctrl; | ||
2215 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
2216 | strlcpy(info.type, "sp2", I2C_NAME_SIZE); | ||
2217 | info.addr = 0x40; | ||
2218 | info.platform_data = &sp2_config; | ||
2219 | request_module(info.type); | ||
2220 | client_ci = i2c_new_device(&i2c_bus2->i2c_adap, &info); | ||
2221 | if (client_ci == NULL || client_ci->dev.driver == NULL) { | ||
2222 | if (client_tuner) { | ||
2223 | module_put(client_tuner->dev.driver->owner); | ||
2224 | i2c_unregister_device(client_tuner); | ||
2225 | } | ||
2226 | if (client_demod) { | ||
2227 | module_put(client_demod->dev.driver->owner); | ||
2228 | i2c_unregister_device(client_demod); | ||
2229 | } | ||
2230 | goto frontend_detach; | ||
2231 | } | ||
2232 | if (!try_module_get(client_ci->dev.driver->owner)) { | ||
2233 | i2c_unregister_device(client_ci); | ||
2234 | if (client_tuner) { | ||
2235 | module_put(client_tuner->dev.driver->owner); | ||
2236 | i2c_unregister_device(client_tuner); | ||
2237 | } | ||
2238 | if (client_demod) { | ||
2239 | module_put(client_demod->dev.driver->owner); | ||
2240 | i2c_unregister_device(client_demod); | ||
2241 | } | ||
2242 | goto frontend_detach; | ||
2243 | } | ||
2244 | port->i2c_client_ci = client_ci; | ||
2245 | 2241 | ||
2246 | if (port->nr != 1) | 2242 | return 0; |
2247 | break; | ||
2248 | 2243 | ||
2249 | /* Read entire EEPROM */ | 2244 | frontend_detach: |
2250 | dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; | 2245 | /* remove I2C client for tuner */ |
2251 | tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, | 2246 | client_tuner = port->i2c_client_tuner; |
2252 | sizeof(eeprom)); | 2247 | if (client_tuner) { |
2253 | printk(KERN_INFO "%s MAC address: %pM\n", | 2248 | module_put(client_tuner->dev.driver->owner); |
2254 | cx23885_boards[dev->board].name, eeprom + 0xc0); | 2249 | i2c_unregister_device(client_tuner); |
2255 | memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6); | 2250 | port->i2c_client_tuner = NULL; |
2256 | break; | ||
2257 | } | ||
2258 | } | 2251 | } |
2259 | 2252 | ||
2260 | return ret; | 2253 | /* remove I2C client for demodulator */ |
2254 | client_demod = port->i2c_client_demod; | ||
2255 | if (client_demod) { | ||
2256 | module_put(client_demod->dev.driver->owner); | ||
2257 | i2c_unregister_device(client_demod); | ||
2258 | port->i2c_client_demod = NULL; | ||
2259 | } | ||
2261 | 2260 | ||
2262 | frontend_detach: | ||
2263 | port->gate_ctrl = NULL; | 2261 | port->gate_ctrl = NULL; |
2264 | vb2_dvb_dealloc_frontends(&port->frontends); | 2262 | vb2_dvb_dealloc_frontends(&port->frontends); |
2265 | return -EINVAL; | 2263 | return -EINVAL; |