firesat_1394.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. * FireSAT DVB driver
  3. *
  4. * Copyright (c) 2004 Andreas Monitzer <andy@monitzer.com>
  5. * Copyright (c) 2007-2008 Ben Backx <ben@bbackx.com>
  6. * Copyright (c) 2008 Henrik Kurelid <henrik@kurelid.se>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/wait.h>
  16. #include <linux/module.h>
  17. #include <linux/delay.h>
  18. #include <linux/time.h>
  19. #include <linux/errno.h>
  20. #include <linux/interrupt.h>
  21. #include <ieee1394_hotplug.h>
  22. #include <nodemgr.h>
  23. #include <highlevel.h>
  24. #include <ohci1394.h>
  25. #include <hosts.h>
  26. #include <dvbdev.h>
  27. #include "firesat.h"
  28. #include "avc_api.h"
  29. #include "cmp.h"
  30. #include "firesat-rc.h"
  31. #include "firesat-ci.h"
  32. #define FIRESAT_Vendor_ID 0x001287
  33. static struct ieee1394_device_id firesat_id_table[] = {
  34. {
  35. /* FloppyDTV S/CI and FloppyDTV S2 */
  36. .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID,
  37. .model_id = 0x000024,
  38. .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
  39. },{
  40. /* FloppyDTV T/CI */
  41. .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID,
  42. .model_id = 0x000025,
  43. .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
  44. },{
  45. /* FloppyDTV C/CI */
  46. .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID,
  47. .model_id = 0x000026,
  48. .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
  49. },{
  50. /* FireDTV S/CI and FloppyDTV S2 */
  51. .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID,
  52. .model_id = 0x000034,
  53. .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
  54. },{
  55. /* FireDTV T/CI */
  56. .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID,
  57. .model_id = 0x000035,
  58. .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
  59. },{
  60. /* FireDTV C/CI */
  61. .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID,
  62. .model_id = 0x000036,
  63. .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
  64. }, { }
  65. };
  66. MODULE_DEVICE_TABLE(ieee1394, firesat_id_table);
  67. /* list of all firesat devices */
  68. LIST_HEAD(firesat_list);
  69. spinlock_t firesat_list_lock = SPIN_LOCK_UNLOCKED;
  70. static void firesat_add_host(struct hpsb_host *host);
  71. static void firesat_remove_host(struct hpsb_host *host);
  72. static void firesat_host_reset(struct hpsb_host *host);
  73. static void fcp_request(struct hpsb_host *host,
  74. int nodeid,
  75. int direction,
  76. int cts,
  77. u8 *data,
  78. size_t length);
  79. static struct hpsb_highlevel firesat_highlevel = {
  80. .name = "FireSAT",
  81. .add_host = firesat_add_host,
  82. .remove_host = firesat_remove_host,
  83. .host_reset = firesat_host_reset,
  84. .fcp_request = fcp_request,
  85. };
  86. static void firesat_add_host (struct hpsb_host *host)
  87. {
  88. struct ti_ohci *ohci = (struct ti_ohci *)host->hostdata;
  89. /* We only work with the OHCI-1394 driver */
  90. if (strcmp(host->driver->name, OHCI1394_DRIVER_NAME))
  91. return;
  92. if (!hpsb_create_hostinfo(&firesat_highlevel, host, 0)) {
  93. printk(KERN_ERR "Cannot allocate hostinfo\n");
  94. return;
  95. }
  96. hpsb_set_hostinfo(&firesat_highlevel, host, ohci);
  97. hpsb_set_hostinfo_key(&firesat_highlevel, host, ohci->host->id);
  98. }
  99. static void firesat_remove_host (struct hpsb_host *host)
  100. {
  101. }
  102. static void firesat_host_reset(struct hpsb_host *host)
  103. {
  104. printk(KERN_INFO "FireSAT host_reset (nodeid = 0x%x, hosts active = %d)\n",host->node_id,host->nodes_active);
  105. }
  106. static void fcp_request(struct hpsb_host *host,
  107. int nodeid,
  108. int direction,
  109. int cts,
  110. u8 *data,
  111. size_t length)
  112. {
  113. struct firesat *firesat = NULL;
  114. struct firesat *firesat_entry;
  115. unsigned long flags;
  116. if (length > 0 && ((data[0] & 0xf0) >> 4) == 0) {
  117. spin_lock_irqsave(&firesat_list_lock, flags);
  118. list_for_each_entry(firesat_entry,&firesat_list,list) {
  119. if (firesat_entry->host == host &&
  120. firesat_entry->nodeentry->nodeid == nodeid &&
  121. (firesat_entry->subunit == (data[1]&0x7) ||
  122. (firesat_entry->subunit == 0 &&
  123. (data[1]&0x7) == 0x7))) {
  124. firesat=firesat_entry;
  125. break;
  126. }
  127. }
  128. spin_unlock_irqrestore(&firesat_list_lock, flags);
  129. if (firesat)
  130. AVCRecv(firesat,data,length);
  131. else
  132. printk("%s: received fcp request from unknown source, ignored\n", __func__);
  133. }
  134. else
  135. printk("%s: received invalid fcp request, ignored\n", __func__);
  136. }
  137. static int firesat_probe(struct device *dev)
  138. {
  139. struct unit_directory *ud = container_of(dev, struct unit_directory, device);
  140. struct firesat *firesat;
  141. struct dvb_frontend *fe;
  142. unsigned long flags;
  143. unsigned char subunitcount = 0xff, subunit;
  144. struct firesat **firesats = kmalloc(sizeof (void*) * 2,GFP_KERNEL);
  145. int kv_len;
  146. char *kv_buf;
  147. if (!firesats) {
  148. printk("%s: couldn't allocate memory.\n", __func__);
  149. return -ENOMEM;
  150. }
  151. // printk(KERN_INFO "FireSAT: Detected device with GUID %08lx%04lx%04lx\n",(unsigned long)((ud->ne->guid)>>32),(unsigned long)(ud->ne->guid & 0xFFFF),(unsigned long)ud->ne->guid_vendor_id);
  152. printk(KERN_INFO "%s: loading device\n", __func__);
  153. firesats[0] = NULL;
  154. firesats[1] = NULL;
  155. ud->device.driver_data = firesats;
  156. for (subunit = 0; subunit < subunitcount; subunit++) {
  157. if (!(firesat = kmalloc(sizeof (struct firesat), GFP_KERNEL)) ||
  158. !(fe = kmalloc(sizeof (struct dvb_frontend), GFP_KERNEL))) {
  159. printk("%s: couldn't allocate memory.\n", __func__);
  160. kfree(firesats);
  161. return -ENOMEM;
  162. }
  163. memset(firesat, 0, sizeof (struct firesat));
  164. firesat->host = ud->ne->host;
  165. firesat->guid = ud->ne->guid;
  166. firesat->guid_vendor_id = ud->ne->guid_vendor_id;
  167. firesat->nodeentry = ud->ne;
  168. firesat->isochannel = -1;
  169. firesat->tone = 0xff;
  170. firesat->voltage = 0xff;
  171. firesat->fe = fe;
  172. if (!(firesat->respfrm = kmalloc(sizeof (AVCRspFrm), GFP_KERNEL))) {
  173. printk("%s: couldn't allocate memory.\n", __func__);
  174. kfree(firesat);
  175. return -ENOMEM;
  176. }
  177. sema_init(&firesat->avc_sem, 1);
  178. atomic_set(&firesat->avc_reply_received, 1);
  179. sema_init(&firesat->demux_sem, 1);
  180. atomic_set(&firesat->reschedule_remotecontrol, 0);
  181. spin_lock_irqsave(&firesat_list_lock, flags);
  182. INIT_LIST_HEAD(&firesat->list);
  183. list_add_tail(&firesat->list, &firesat_list);
  184. spin_unlock_irqrestore(&firesat_list_lock, flags);
  185. if (subunit == 0) {
  186. firesat->subunit = 0x7; // 0x7 = don't care
  187. if (AVCSubUnitInfo(firesat, &subunitcount)) {
  188. printk("%s: AVC subunit info command failed.\n",__func__);
  189. spin_lock_irqsave(&firesat_list_lock, flags);
  190. list_del(&firesat->list);
  191. spin_unlock_irqrestore(&firesat_list_lock, flags);
  192. kfree(firesat);
  193. return -EIO;
  194. }
  195. }
  196. printk(KERN_INFO "%s: subunit count = %d\n", __func__, subunitcount);
  197. firesat->subunit = subunit;
  198. /* Reading device model from ROM */
  199. kv_len = (ud->model_name_kv->value.leaf.len - 2) *
  200. sizeof(quadlet_t);
  201. kv_buf = kmalloc((sizeof(quadlet_t) * kv_len), GFP_KERNEL);
  202. memcpy(kv_buf,
  203. CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(ud->model_name_kv),
  204. kv_len);
  205. while ((kv_buf + kv_len - 1) == '\0') kv_len--;
  206. kv_buf[kv_len++] = '\0';
  207. /* Determining the device model */
  208. if (strcmp(kv_buf, "FireDTV S/CI") == 0) {
  209. printk(KERN_INFO "%s: found DVB/S\n", __func__);
  210. firesat->type = 1;
  211. } else if (strcmp(kv_buf, "FireDTV C/CI") == 0) {
  212. printk(KERN_INFO "%s: found DVB/C\n", __func__);
  213. firesat->type = 2;
  214. } else if (strcmp(kv_buf, "FireDTV T/CI") == 0) {
  215. printk(KERN_INFO "%s: found DVB/T\n", __func__);
  216. firesat->type = 3;
  217. } else if (strcmp(kv_buf, "FireDTV S2 ") == 0) {
  218. printk(KERN_INFO "%s: found DVB/S2\n", __func__);
  219. firesat->type = 4;
  220. }
  221. kfree(kv_buf);
  222. if (AVCIdentifySubunit(firesat, NULL, (int*)&firesat->type)) {
  223. printk("%s: cannot identify subunit %d\n", __func__, subunit);
  224. spin_lock_irqsave(&firesat_list_lock, flags);
  225. list_del(&firesat->list);
  226. spin_unlock_irqrestore(&firesat_list_lock, flags);
  227. kfree(firesat);
  228. continue;
  229. }
  230. // ----
  231. firesat_dvbdev_init(firesat, dev, fe);
  232. // ----
  233. firesats[subunit] = firesat;
  234. } // loop for all tuners
  235. //beta ;-) Disable remote control stuff to avoid crashing
  236. //if(firesats[0])
  237. // AVCRegisterRemoteControl(firesats[0]);
  238. return 0;
  239. }
  240. static int firesat_remove(struct device *dev)
  241. {
  242. struct unit_directory *ud = container_of(dev, struct unit_directory, device);
  243. struct firesat **firesats = ud->device.driver_data;
  244. int k;
  245. unsigned long flags;
  246. if (firesats) {
  247. for (k = 0; k < 2; k++)
  248. if (firesats[k]) {
  249. firesat_ca_release(firesats[k]);
  250. dvb_unregister_frontend(firesats[k]->fe);
  251. dvb_net_release(&firesats[k]->dvbnet);
  252. firesats[k]->demux.dmx.close(&firesats[k]->demux.dmx);
  253. firesats[k]->demux.dmx.remove_frontend(&firesats[k]->demux.dmx, &firesats[k]->frontend);
  254. dvb_dmxdev_release(&firesats[k]->dmxdev);
  255. dvb_dmx_release(&firesats[k]->demux);
  256. dvb_unregister_adapter(firesats[k]->adapter);
  257. spin_lock_irqsave(&firesat_list_lock, flags);
  258. list_del(&firesats[k]->list);
  259. spin_unlock_irqrestore(&firesat_list_lock, flags);
  260. kfree(firesats[k]->fe);
  261. kfree(firesats[k]->adapter);
  262. kfree(firesats[k]->respfrm);
  263. kfree(firesats[k]);
  264. }
  265. kfree(firesats);
  266. } else
  267. printk("%s: can't get firesat handle\n", __func__);
  268. printk(KERN_INFO "FireSAT: Removing device with vendor id 0x%x, model id 0x%x.\n",ud->vendor_id,ud->model_id);
  269. return 0;
  270. }
  271. static int firesat_update(struct unit_directory *ud)
  272. {
  273. struct firesat **firesats = ud->device.driver_data;
  274. int k;
  275. // loop over subunits
  276. for (k = 0; k < 2; k++)
  277. if (firesats[k]) {
  278. firesats[k]->nodeentry = ud->ne;
  279. if (firesats[k]->isochannel >= 0)
  280. try_CMPEstablishPPconnection(firesats[k], firesats[k]->subunit, firesats[k]->isochannel);
  281. }
  282. return 0;
  283. }
  284. static struct hpsb_protocol_driver firesat_driver = {
  285. .name = "FireSAT",
  286. .id_table = firesat_id_table,
  287. .update = firesat_update,
  288. .driver = {
  289. //.name and .bus are filled in for us in more recent linux versions
  290. //.name = "FireSAT",
  291. //.bus = &ieee1394_bus_type,
  292. .probe = firesat_probe,
  293. .remove = firesat_remove,
  294. },
  295. };
  296. static int __init firesat_init(void)
  297. {
  298. int ret;
  299. printk(KERN_INFO "FireSAT loaded\n");
  300. hpsb_register_highlevel(&firesat_highlevel);
  301. ret = hpsb_register_protocol(&firesat_driver);
  302. if (ret) {
  303. printk(KERN_ERR "FireSAT: failed to register protocol\n");
  304. hpsb_unregister_highlevel(&firesat_highlevel);
  305. return ret;
  306. }
  307. //Crash in this function, just disable RC for the time being...
  308. //Don't forget to uncomment in firesat_exit and firesat_probe when you enable this.
  309. /*if((ret=firesat_register_rc()))
  310. printk("%s: firesat_register_rc return error code %d (ignored)\n", __func__, ret);*/
  311. return 0;
  312. }
  313. static void __exit firesat_exit(void)
  314. {
  315. hpsb_unregister_protocol(&firesat_driver);
  316. hpsb_unregister_highlevel(&firesat_highlevel);
  317. printk(KERN_INFO "FireSAT quit\n");
  318. }
  319. module_init(firesat_init);
  320. module_exit(firesat_exit);
  321. MODULE_AUTHOR("Andreas Monitzer <andy@monitzer.com>");
  322. MODULE_AUTHOR("Ben Backx <ben@bbackx.com>");
  323. MODULE_DESCRIPTION("FireSAT DVB Driver");
  324. MODULE_LICENSE("GPL");
  325. MODULE_SUPPORTED_DEVICE("FireSAT DVB");