softing_cs.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * Copyright (C) 2008-2010
  3. *
  4. * - Kurt Van Dijck, EIA Electronics
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the version 2 of the GNU General Public License
  8. * as published by the Free Software Foundation
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/kernel.h>
  20. #include <linux/slab.h>
  21. #include <pcmcia/cistpl.h>
  22. #include <pcmcia/ds.h>
  23. #include "softing_platform.h"
  24. static int softingcs_index;
  25. static DEFINE_SPINLOCK(softingcs_index_lock);
  26. static int softingcs_reset(struct platform_device *pdev, int v);
  27. static int softingcs_enable_irq(struct platform_device *pdev, int v);
  28. /*
  29. * platform_data descriptions
  30. */
  31. #define MHZ (1000*1000)
  32. static const struct softing_platform_data softingcs_platform_data[] = {
  33. {
  34. .name = "CANcard",
  35. .manf = 0x0168, .prod = 0x001,
  36. .generation = 1,
  37. .nbus = 2,
  38. .freq = 16 * MHZ, .max_brp = 32, .max_sjw = 4,
  39. .dpram_size = 0x0800,
  40. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  41. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  42. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  43. .reset = softingcs_reset,
  44. .enable_irq = softingcs_enable_irq,
  45. }, {
  46. .name = "CANcard-NEC",
  47. .manf = 0x0168, .prod = 0x002,
  48. .generation = 1,
  49. .nbus = 2,
  50. .freq = 16 * MHZ, .max_brp = 32, .max_sjw = 4,
  51. .dpram_size = 0x0800,
  52. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  53. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  54. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  55. .reset = softingcs_reset,
  56. .enable_irq = softingcs_enable_irq,
  57. }, {
  58. .name = "CANcard-SJA",
  59. .manf = 0x0168, .prod = 0x004,
  60. .generation = 1,
  61. .nbus = 2,
  62. .freq = 20 * MHZ, .max_brp = 32, .max_sjw = 4,
  63. .dpram_size = 0x0800,
  64. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  65. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  66. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  67. .reset = softingcs_reset,
  68. .enable_irq = softingcs_enable_irq,
  69. }, {
  70. .name = "CANcard-2",
  71. .manf = 0x0168, .prod = 0x005,
  72. .generation = 2,
  73. .nbus = 2,
  74. .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4,
  75. .dpram_size = 0x1000,
  76. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  77. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  78. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  79. .reset = softingcs_reset,
  80. .enable_irq = NULL,
  81. }, {
  82. .name = "Vector-CANcard",
  83. .manf = 0x0168, .prod = 0x081,
  84. .generation = 1,
  85. .nbus = 2,
  86. .freq = 16 * MHZ, .max_brp = 64, .max_sjw = 4,
  87. .dpram_size = 0x0800,
  88. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  89. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  90. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  91. .reset = softingcs_reset,
  92. .enable_irq = softingcs_enable_irq,
  93. }, {
  94. .name = "Vector-CANcard-SJA",
  95. .manf = 0x0168, .prod = 0x084,
  96. .generation = 1,
  97. .nbus = 2,
  98. .freq = 20 * MHZ, .max_brp = 32, .max_sjw = 4,
  99. .dpram_size = 0x0800,
  100. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  101. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  102. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  103. .reset = softingcs_reset,
  104. .enable_irq = softingcs_enable_irq,
  105. }, {
  106. .name = "Vector-CANcard-2",
  107. .manf = 0x0168, .prod = 0x085,
  108. .generation = 2,
  109. .nbus = 2,
  110. .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4,
  111. .dpram_size = 0x1000,
  112. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  113. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  114. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  115. .reset = softingcs_reset,
  116. .enable_irq = NULL,
  117. }, {
  118. .name = "EDICcard-NEC",
  119. .manf = 0x0168, .prod = 0x102,
  120. .generation = 1,
  121. .nbus = 2,
  122. .freq = 16 * MHZ, .max_brp = 64, .max_sjw = 4,
  123. .dpram_size = 0x0800,
  124. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  125. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  126. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  127. .reset = softingcs_reset,
  128. .enable_irq = softingcs_enable_irq,
  129. }, {
  130. .name = "EDICcard-2",
  131. .manf = 0x0168, .prod = 0x105,
  132. .generation = 2,
  133. .nbus = 2,
  134. .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4,
  135. .dpram_size = 0x1000,
  136. .boot = {0x0000, 0x000000, fw_dir "/*(DEBLOBBED)*/",},
  137. .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
  138. .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
  139. .reset = softingcs_reset,
  140. .enable_irq = NULL,
  141. }, {
  142. 0, 0,
  143. },
  144. };
  145. /*(DEBLOBBED)*/
  146. static const struct softing_platform_data
  147. *softingcs_find_platform_data(unsigned int manf, unsigned int prod)
  148. {
  149. const struct softing_platform_data *lp;
  150. for (lp = softingcs_platform_data; lp->manf; ++lp) {
  151. if ((lp->manf == manf) && (lp->prod == prod))
  152. return lp;
  153. }
  154. return NULL;
  155. }
  156. /*
  157. * platformdata callbacks
  158. */
  159. static int softingcs_reset(struct platform_device *pdev, int v)
  160. {
  161. struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent);
  162. dev_dbg(&pdev->dev, "pcmcia config [2] %02x\n", v ? 0 : 0x20);
  163. return pcmcia_write_config_byte(pcmcia, 2, v ? 0 : 0x20);
  164. }
  165. static int softingcs_enable_irq(struct platform_device *pdev, int v)
  166. {
  167. struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent);
  168. dev_dbg(&pdev->dev, "pcmcia config [0] %02x\n", v ? 0x60 : 0);
  169. return pcmcia_write_config_byte(pcmcia, 0, v ? 0x60 : 0);
  170. }
  171. /*
  172. * pcmcia check
  173. */
  174. static int softingcs_probe_config(struct pcmcia_device *pcmcia, void *priv_data)
  175. {
  176. struct softing_platform_data *pdat = priv_data;
  177. struct resource *pres;
  178. int memspeed = 0;
  179. WARN_ON(!pdat);
  180. pres = pcmcia->resource[PCMCIA_IOMEM_0];
  181. if (resource_size(pres) < 0x1000)
  182. return -ERANGE;
  183. pres->flags |= WIN_MEMORY_TYPE_CM | WIN_ENABLE;
  184. if (pdat->generation < 2) {
  185. pres->flags |= WIN_USE_WAIT | WIN_DATA_WIDTH_8;
  186. memspeed = 3;
  187. } else {
  188. pres->flags |= WIN_DATA_WIDTH_16;
  189. }
  190. return pcmcia_request_window(pcmcia, pres, memspeed);
  191. }
  192. static void softingcs_remove(struct pcmcia_device *pcmcia)
  193. {
  194. struct platform_device *pdev = pcmcia->priv;
  195. /* free bits */
  196. platform_device_unregister(pdev);
  197. /* release pcmcia stuff */
  198. pcmcia_disable_device(pcmcia);
  199. }
  200. /*
  201. * platform_device wrapper
  202. * pdev->resource has 2 entries: io & irq
  203. */
  204. static void softingcs_pdev_release(struct device *dev)
  205. {
  206. struct platform_device *pdev = to_platform_device(dev);
  207. kfree(pdev);
  208. }
  209. static int softingcs_probe(struct pcmcia_device *pcmcia)
  210. {
  211. int ret;
  212. struct platform_device *pdev;
  213. const struct softing_platform_data *pdat;
  214. struct resource *pres;
  215. struct dev {
  216. struct platform_device pdev;
  217. struct resource res[2];
  218. } *dev;
  219. /* find matching platform_data */
  220. pdat = softingcs_find_platform_data(pcmcia->manf_id, pcmcia->card_id);
  221. if (!pdat)
  222. return -ENOTTY;
  223. /* setup pcmcia device */
  224. pcmcia->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IOMEM |
  225. CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
  226. ret = pcmcia_loop_config(pcmcia, softingcs_probe_config, (void *)pdat);
  227. if (ret)
  228. goto pcmcia_failed;
  229. ret = pcmcia_enable_device(pcmcia);
  230. if (ret < 0)
  231. goto pcmcia_failed;
  232. pres = pcmcia->resource[PCMCIA_IOMEM_0];
  233. if (!pres) {
  234. ret = -EBADF;
  235. goto pcmcia_bad;
  236. }
  237. /* create softing platform device */
  238. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  239. if (!dev) {
  240. ret = -ENOMEM;
  241. goto mem_failed;
  242. }
  243. dev->pdev.resource = dev->res;
  244. dev->pdev.num_resources = ARRAY_SIZE(dev->res);
  245. dev->pdev.dev.release = softingcs_pdev_release;
  246. pdev = &dev->pdev;
  247. pdev->dev.platform_data = (void *)pdat;
  248. pdev->dev.parent = &pcmcia->dev;
  249. pcmcia->priv = pdev;
  250. /* platform device resources */
  251. pdev->resource[0].flags = IORESOURCE_MEM;
  252. pdev->resource[0].start = pres->start;
  253. pdev->resource[0].end = pres->end;
  254. pdev->resource[1].flags = IORESOURCE_IRQ;
  255. pdev->resource[1].start = pcmcia->irq;
  256. pdev->resource[1].end = pdev->resource[1].start;
  257. /* platform device setup */
  258. spin_lock(&softingcs_index_lock);
  259. pdev->id = softingcs_index++;
  260. spin_unlock(&softingcs_index_lock);
  261. pdev->name = "softing";
  262. dev_set_name(&pdev->dev, "softingcs.%i", pdev->id);
  263. ret = platform_device_register(pdev);
  264. if (ret < 0)
  265. goto platform_failed;
  266. dev_info(&pcmcia->dev, "created %s\n", dev_name(&pdev->dev));
  267. return 0;
  268. platform_failed:
  269. kfree(dev);
  270. mem_failed:
  271. pcmcia_bad:
  272. pcmcia_failed:
  273. pcmcia_disable_device(pcmcia);
  274. pcmcia->priv = NULL;
  275. return ret ?: -ENODEV;
  276. }
  277. static const struct pcmcia_device_id softingcs_ids[] = {
  278. /* softing */
  279. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0001),
  280. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0002),
  281. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0004),
  282. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0005),
  283. /* vector, manufacturer? */
  284. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0081),
  285. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0084),
  286. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0085),
  287. /* EDIC */
  288. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0102),
  289. PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0105),
  290. PCMCIA_DEVICE_NULL,
  291. };
  292. MODULE_DEVICE_TABLE(pcmcia, softingcs_ids);
  293. static struct pcmcia_driver softingcs_driver = {
  294. .owner = THIS_MODULE,
  295. .name = "softingcs",
  296. .id_table = softingcs_ids,
  297. .probe = softingcs_probe,
  298. .remove = softingcs_remove,
  299. };
  300. module_pcmcia_driver(softingcs_driver);
  301. MODULE_DESCRIPTION("softing CANcard driver"
  302. ", links PCMCIA card to softing driver");
  303. MODULE_LICENSE("GPL v2");