1
0

spi-vsc7385.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * SPI driver for the Vitesse VSC7385 ethernet switch
  3. *
  4. * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * Parts of this file are based on Atheros' 2.6.15 BSP
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/delay.h>
  17. #include <linux/device.h>
  18. #include <linux/bitops.h>
  19. #include <linux/firmware.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/spi/vsc7385.h>
  22. #define DRV_NAME "spi-vsc7385"
  23. #define DRV_DESC "Vitesse VSC7385 Gbit ethernet switch driver"
  24. #define DRV_VERSION "0.1.0"
  25. #define VSC73XX_BLOCK_MAC 0x1
  26. #define VSC73XX_BLOCK_2 0x2
  27. #define VSC73XX_BLOCK_MII 0x3
  28. #define VSC73XX_BLOCK_4 0x4
  29. #define VSC73XX_BLOCK_5 0x5
  30. #define VSC73XX_BLOCK_SYSTEM 0x7
  31. #define VSC73XX_SUBBLOCK_PORT_0 0
  32. #define VSC73XX_SUBBLOCK_PORT_1 1
  33. #define VSC73XX_SUBBLOCK_PORT_2 2
  34. #define VSC73XX_SUBBLOCK_PORT_3 3
  35. #define VSC73XX_SUBBLOCK_PORT_4 4
  36. #define VSC73XX_SUBBLOCK_PORT_MAC 6
  37. /* MAC Block registers */
  38. #define VSC73XX_MAC_CFG 0x0
  39. #define VSC73XX_ADVPORTM 0x19
  40. #define VSC73XX_RXOCT 0x50
  41. #define VSC73XX_TXOCT 0x51
  42. #define VSC73XX_C_RX0 0x52
  43. #define VSC73XX_C_RX1 0x53
  44. #define VSC73XX_C_RX2 0x54
  45. #define VSC73XX_C_TX0 0x55
  46. #define VSC73XX_C_TX1 0x56
  47. #define VSC73XX_C_TX2 0x57
  48. #define VSC73XX_C_CFG 0x58
  49. /* MAC_CFG register bits */
  50. #define VSC73XX_MAC_CFG_WEXC_DIS (1 << 31)
  51. #define VSC73XX_MAC_CFG_PORT_RST (1 << 29)
  52. #define VSC73XX_MAC_CFG_TX_EN (1 << 28)
  53. #define VSC73XX_MAC_CFG_SEED_LOAD (1 << 27)
  54. #define VSC73XX_MAC_CFG_FDX (1 << 18)
  55. #define VSC73XX_MAC_CFG_GIGE (1 << 17)
  56. #define VSC73XX_MAC_CFG_RX_EN (1 << 16)
  57. #define VSC73XX_MAC_CFG_VLAN_DBLAWR (1 << 15)
  58. #define VSC73XX_MAC_CFG_VLAN_AWR (1 << 14)
  59. #define VSC73XX_MAC_CFG_100_BASE_T (1 << 13)
  60. #define VSC73XX_MAC_CFG_TX_IPG(x) (((x) & 0x1f) << 6)
  61. #define VSC73XX_MAC_CFG_MAC_RX_RST (1 << 5)
  62. #define VSC73XX_MAC_CFG_MAC_TX_RST (1 << 4)
  63. #define VSC73XX_MAC_CFG_BIT2 (1 << 2)
  64. #define VSC73XX_MAC_CFG_CLK_SEL(x) ((x) & 0x3)
  65. /* ADVPORTM register bits */
  66. #define VSC73XX_ADVPORTM_IFG_PPM (1 << 7)
  67. #define VSC73XX_ADVPORTM_EXC_COL_CONT (1 << 6)
  68. #define VSC73XX_ADVPORTM_EXT_PORT (1 << 5)
  69. #define VSC73XX_ADVPORTM_INV_GTX (1 << 4)
  70. #define VSC73XX_ADVPORTM_ENA_GTX (1 << 3)
  71. #define VSC73XX_ADVPORTM_DDR_MODE (1 << 2)
  72. #define VSC73XX_ADVPORTM_IO_LOOPBACK (1 << 1)
  73. #define VSC73XX_ADVPORTM_HOST_LOOPBACK (1 << 0)
  74. /* MII Block registers */
  75. #define VSC73XX_MII_STAT 0x0
  76. #define VSC73XX_MII_CMD 0x1
  77. #define VSC73XX_MII_DATA 0x2
  78. /* System Block registers */
  79. #define VSC73XX_ICPU_SIPAD 0x01
  80. #define VSC73XX_ICPU_CLOCK_DELAY 0x05
  81. #define VSC73XX_ICPU_CTRL 0x10
  82. #define VSC73XX_ICPU_ADDR 0x11
  83. #define VSC73XX_ICPU_SRAM 0x12
  84. #define VSC73XX_ICPU_MBOX_VAL 0x15
  85. #define VSC73XX_ICPU_MBOX_SET 0x16
  86. #define VSC73XX_ICPU_MBOX_CLR 0x17
  87. #define VSC73XX_ICPU_CHIPID 0x18
  88. #define VSC73XX_ICPU_GPIO 0x34
  89. #define VSC73XX_ICPU_CTRL_CLK_DIV (1 << 8)
  90. #define VSC73XX_ICPU_CTRL_SRST_HOLD (1 << 7)
  91. #define VSC73XX_ICPU_CTRL_BOOT_EN (1 << 3)
  92. #define VSC73XX_ICPU_CTRL_EXT_ACC_EN (1 << 2)
  93. #define VSC73XX_ICPU_CTRL_CLK_EN (1 << 1)
  94. #define VSC73XX_ICPU_CTRL_SRST (1 << 0)
  95. #define VSC73XX_ICPU_CHIPID_ID_SHIFT 12
  96. #define VSC73XX_ICPU_CHIPID_ID_MASK 0xffff
  97. #define VSC73XX_ICPU_CHIPID_REV_SHIFT 28
  98. #define VSC73XX_ICPU_CHIPID_REV_MASK 0xf
  99. #define VSC73XX_ICPU_CHIPID_ID_7385 0x7385
  100. #define VSC73XX_ICPU_CHIPID_ID_7395 0x7395
  101. #define VSC73XX_CMD_MODE_READ 0
  102. #define VSC73XX_CMD_MODE_WRITE 1
  103. #define VSC73XX_CMD_MODE_SHIFT 4
  104. #define VSC73XX_CMD_BLOCK_SHIFT 5
  105. #define VSC73XX_CMD_BLOCK_MASK 0x7
  106. #define VSC73XX_CMD_SUBBLOCK_MASK 0xf
  107. #define VSC7385_CLOCK_DELAY ((3 << 4) | 3)
  108. #define VSC7385_CLOCK_DELAY_MASK ((3 << 4) | 3)
  109. #define VSC73XX_ICPU_CTRL_STOP (VSC73XX_ICPU_CTRL_SRST_HOLD | \
  110. VSC73XX_ICPU_CTRL_BOOT_EN | \
  111. VSC73XX_ICPU_CTRL_EXT_ACC_EN)
  112. #define VSC73XX_ICPU_CTRL_START (VSC73XX_ICPU_CTRL_CLK_DIV | \
  113. VSC73XX_ICPU_CTRL_BOOT_EN | \
  114. VSC73XX_ICPU_CTRL_CLK_EN | \
  115. VSC73XX_ICPU_CTRL_SRST)
  116. #define VSC7385_ADVPORTM_MASK (VSC73XX_ADVPORTM_IFG_PPM | \
  117. VSC73XX_ADVPORTM_EXC_COL_CONT | \
  118. VSC73XX_ADVPORTM_EXT_PORT | \
  119. VSC73XX_ADVPORTM_INV_GTX | \
  120. VSC73XX_ADVPORTM_ENA_GTX | \
  121. VSC73XX_ADVPORTM_DDR_MODE | \
  122. VSC73XX_ADVPORTM_IO_LOOPBACK | \
  123. VSC73XX_ADVPORTM_HOST_LOOPBACK)
  124. #define VSC7385_ADVPORTM_INIT (VSC73XX_ADVPORTM_EXT_PORT | \
  125. VSC73XX_ADVPORTM_ENA_GTX | \
  126. VSC73XX_ADVPORTM_DDR_MODE)
  127. #define VSC7385_MAC_CFG_RESET (VSC73XX_MAC_CFG_PORT_RST | \
  128. VSC73XX_MAC_CFG_MAC_RX_RST | \
  129. VSC73XX_MAC_CFG_MAC_TX_RST)
  130. #define VSC73XX_MAC_CFG_INIT (VSC73XX_MAC_CFG_TX_EN | \
  131. VSC73XX_MAC_CFG_FDX | \
  132. VSC73XX_MAC_CFG_GIGE | \
  133. VSC73XX_MAC_CFG_RX_EN)
  134. #define VSC73XX_RESET_DELAY 100
  135. struct vsc7385 {
  136. struct spi_device *spi;
  137. struct mutex lock;
  138. struct vsc7385_platform_data *pdata;
  139. };
  140. static int vsc7385_is_addr_valid(u8 block, u8 subblock)
  141. {
  142. switch (block) {
  143. case VSC73XX_BLOCK_MAC:
  144. switch (subblock) {
  145. case 0 ... 4:
  146. case 6:
  147. return 1;
  148. }
  149. break;
  150. case VSC73XX_BLOCK_2:
  151. case VSC73XX_BLOCK_SYSTEM:
  152. switch (subblock) {
  153. case 0:
  154. return 1;
  155. }
  156. break;
  157. case VSC73XX_BLOCK_MII:
  158. case VSC73XX_BLOCK_4:
  159. case VSC73XX_BLOCK_5:
  160. switch (subblock) {
  161. case 0 ... 1:
  162. return 1;
  163. }
  164. break;
  165. }
  166. return 0;
  167. }
  168. static inline u8 vsc7385_make_addr(u8 mode, u8 block, u8 subblock)
  169. {
  170. u8 ret;
  171. ret = (block & VSC73XX_CMD_BLOCK_MASK) << VSC73XX_CMD_BLOCK_SHIFT;
  172. ret |= (mode & 1) << VSC73XX_CMD_MODE_SHIFT;
  173. ret |= subblock & VSC73XX_CMD_SUBBLOCK_MASK;
  174. return ret;
  175. }
  176. static int vsc7385_read(struct vsc7385 *vsc, u8 block, u8 subblock, u8 reg,
  177. u32 *value)
  178. {
  179. u8 cmd[4];
  180. u8 buf[4];
  181. struct spi_transfer t[2];
  182. struct spi_message m;
  183. int err;
  184. if (!vsc7385_is_addr_valid(block, subblock))
  185. return -EINVAL;
  186. spi_message_init(&m);
  187. memset(&t, 0, sizeof(t));
  188. t[0].tx_buf = cmd;
  189. t[0].len = sizeof(cmd);
  190. spi_message_add_tail(&t[0], &m);
  191. t[1].rx_buf = buf;
  192. t[1].len = sizeof(buf);
  193. spi_message_add_tail(&t[1], &m);
  194. cmd[0] = vsc7385_make_addr(VSC73XX_CMD_MODE_READ, block, subblock);
  195. cmd[1] = reg;
  196. cmd[2] = 0;
  197. cmd[3] = 0;
  198. mutex_lock(&vsc->lock);
  199. err = spi_sync(vsc->spi, &m);
  200. mutex_unlock(&vsc->lock);
  201. if (err)
  202. return err;
  203. *value = (((u32) buf[0]) << 24) | (((u32) buf[1]) << 16) |
  204. (((u32) buf[2]) << 8) | ((u32) buf[3]);
  205. return 0;
  206. }
  207. static int vsc7385_write(struct vsc7385 *vsc, u8 block, u8 subblock, u8 reg,
  208. u32 value)
  209. {
  210. u8 cmd[2];
  211. u8 buf[4];
  212. struct spi_transfer t[2];
  213. struct spi_message m;
  214. int err;
  215. if (!vsc7385_is_addr_valid(block, subblock))
  216. return -EINVAL;
  217. spi_message_init(&m);
  218. memset(&t, 0, sizeof(t));
  219. t[0].tx_buf = cmd;
  220. t[0].len = sizeof(cmd);
  221. spi_message_add_tail(&t[0], &m);
  222. t[1].tx_buf = buf;
  223. t[1].len = sizeof(buf);
  224. spi_message_add_tail(&t[1], &m);
  225. cmd[0] = vsc7385_make_addr(VSC73XX_CMD_MODE_WRITE, block, subblock);
  226. cmd[1] = reg;
  227. buf[0] = (value >> 24) & 0xff;
  228. buf[1] = (value >> 16) & 0xff;
  229. buf[2] = (value >> 8) & 0xff;
  230. buf[3] = value & 0xff;
  231. mutex_lock(&vsc->lock);
  232. err = spi_sync(vsc->spi, &m);
  233. mutex_unlock(&vsc->lock);
  234. return err;
  235. }
  236. static inline int vsc7385_write_verify(struct vsc7385 *vsc, u8 block,
  237. u8 subblock, u8 reg, u32 value,
  238. u32 read_mask, u32 read_val)
  239. {
  240. struct spi_device *spi = vsc->spi;
  241. u32 t;
  242. int err;
  243. err = vsc7385_write(vsc, block, subblock, reg, value);
  244. if (err)
  245. return err;
  246. err = vsc7385_read(vsc, block, subblock, reg, &t);
  247. if (err)
  248. return err;
  249. if ((t & read_mask) != read_val) {
  250. dev_err(&spi->dev, "register write error\n");
  251. return -EIO;
  252. }
  253. return 0;
  254. }
  255. static inline int vsc7385_set_clock_delay(struct vsc7385 *vsc, u32 val)
  256. {
  257. return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  258. VSC73XX_ICPU_CLOCK_DELAY, val);
  259. }
  260. static inline int vsc7385_get_clock_delay(struct vsc7385 *vsc, u32 *val)
  261. {
  262. return vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  263. VSC73XX_ICPU_CLOCK_DELAY, val);
  264. }
  265. static inline int vsc7385_icpu_stop(struct vsc7385 *vsc)
  266. {
  267. return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_CTRL,
  268. VSC73XX_ICPU_CTRL_STOP);
  269. }
  270. static inline int vsc7385_icpu_start(struct vsc7385 *vsc)
  271. {
  272. return vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_CTRL,
  273. VSC73XX_ICPU_CTRL_START);
  274. }
  275. static inline int vsc7385_icpu_reset(struct vsc7385 *vsc)
  276. {
  277. int rc;
  278. rc = vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_ICPU_ADDR,
  279. 0x0000);
  280. if (rc)
  281. dev_err(&vsc->spi->dev,
  282. "could not reset microcode, err=%d\n", rc);
  283. return rc;
  284. }
  285. static int vsc7385_upload_ucode(struct vsc7385 *vsc)
  286. {
  287. struct spi_device *spi = vsc->spi;
  288. const struct firmware *firmware;
  289. char *ucode_name;
  290. unsigned char *dp;
  291. unsigned int curVal;
  292. int i;
  293. int diffs;
  294. int rc;
  295. ucode_name = (vsc->pdata->ucode_name) ? vsc->pdata->ucode_name
  296. : "vsc7385_ucode.bin";
  297. rc = request_firmware(&firmware, ucode_name, &spi->dev);
  298. if (rc) {
  299. dev_err(&spi->dev, "request_firmware failed, err=%d\n",
  300. rc);
  301. return rc;
  302. }
  303. rc = vsc7385_icpu_stop(vsc);
  304. if (rc)
  305. goto out;
  306. rc = vsc7385_icpu_reset(vsc);
  307. if (rc)
  308. goto out;
  309. dev_info(&spi->dev, "uploading microcode...\n");
  310. dp = (unsigned char *) firmware->data;
  311. for (i = 0; i < firmware->size; i++) {
  312. rc = vsc7385_write(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  313. VSC73XX_ICPU_SRAM, *dp++);
  314. if (rc) {
  315. dev_err(&spi->dev, "could not load microcode, err=%d\n",
  316. rc);
  317. goto out;
  318. }
  319. }
  320. rc = vsc7385_icpu_reset(vsc);
  321. if (rc)
  322. goto out;
  323. dev_info(&spi->dev, "verifying microcode...\n");
  324. dp = (unsigned char *) firmware->data;
  325. diffs = 0;
  326. for (i = 0; i < firmware->size; i++) {
  327. rc = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  328. VSC73XX_ICPU_SRAM, &curVal);
  329. if (rc) {
  330. dev_err(&spi->dev, "could not read microcode %d\n",
  331. rc);
  332. goto out;
  333. }
  334. if (curVal > 0xff) {
  335. dev_err(&spi->dev, "bad val read: %04x : %02x %02x\n",
  336. i, *dp, curVal);
  337. rc = -EIO;
  338. goto out;
  339. }
  340. if ((curVal & 0xff) != *dp) {
  341. diffs++;
  342. dev_err(&spi->dev, "verify error: %04x : %02x %02x\n",
  343. i, *dp, curVal);
  344. if (diffs > 4)
  345. break;
  346. }
  347. dp++;
  348. }
  349. if (diffs) {
  350. dev_err(&spi->dev, "microcode verification failed\n");
  351. rc = -EIO;
  352. goto out;
  353. }
  354. dev_info(&spi->dev, "microcode uploaded\n");
  355. rc = vsc7385_icpu_start(vsc);
  356. out:
  357. release_firmware(firmware);
  358. return rc;
  359. }
  360. static int vsc7385_setup(struct vsc7385 *vsc)
  361. {
  362. struct vsc7385_platform_data *pdata = vsc->pdata;
  363. u32 t;
  364. int err;
  365. err = vsc7385_write_verify(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  366. VSC73XX_ICPU_CLOCK_DELAY,
  367. VSC7385_CLOCK_DELAY,
  368. VSC7385_CLOCK_DELAY_MASK,
  369. VSC7385_CLOCK_DELAY);
  370. if (err)
  371. goto err;
  372. err = vsc7385_write_verify(vsc, VSC73XX_BLOCK_MAC,
  373. VSC73XX_SUBBLOCK_PORT_MAC, VSC73XX_ADVPORTM,
  374. VSC7385_ADVPORTM_INIT,
  375. VSC7385_ADVPORTM_MASK,
  376. VSC7385_ADVPORTM_INIT);
  377. if (err)
  378. goto err;
  379. err = vsc7385_write(vsc, VSC73XX_BLOCK_MAC, VSC73XX_SUBBLOCK_PORT_MAC,
  380. VSC73XX_MAC_CFG, VSC7385_MAC_CFG_RESET);
  381. if (err)
  382. goto err;
  383. t = VSC73XX_MAC_CFG_INIT;
  384. t |= VSC73XX_MAC_CFG_TX_IPG(pdata->mac_cfg.tx_ipg);
  385. t |= VSC73XX_MAC_CFG_CLK_SEL(pdata->mac_cfg.clk_sel);
  386. if (pdata->mac_cfg.bit2)
  387. t |= VSC73XX_MAC_CFG_BIT2;
  388. err = vsc7385_write(vsc, VSC73XX_BLOCK_MAC, VSC73XX_SUBBLOCK_PORT_MAC,
  389. VSC73XX_MAC_CFG, t);
  390. if (err)
  391. goto err;
  392. return 0;
  393. err:
  394. return err;
  395. }
  396. static int vsc7385_detect(struct vsc7385 *vsc)
  397. {
  398. struct spi_device *spi = vsc->spi;
  399. u32 t;
  400. u32 id;
  401. u32 rev;
  402. int err;
  403. err = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  404. VSC73XX_ICPU_MBOX_VAL, &t);
  405. if (err) {
  406. dev_err(&spi->dev, "unable to read mailbox, err=%d\n", err);
  407. return err;
  408. }
  409. if (t == 0xffffffff) {
  410. dev_dbg(&spi->dev, "assert chip reset\n");
  411. if (vsc->pdata->reset)
  412. vsc->pdata->reset();
  413. }
  414. err = vsc7385_read(vsc, VSC73XX_BLOCK_SYSTEM, 0,
  415. VSC73XX_ICPU_CHIPID, &t);
  416. if (err) {
  417. dev_err(&spi->dev, "unable to read chip id, err=%d\n", err);
  418. return err;
  419. }
  420. id = (t >> VSC73XX_ICPU_CHIPID_ID_SHIFT) & VSC73XX_ICPU_CHIPID_ID_MASK;
  421. switch (id) {
  422. case VSC73XX_ICPU_CHIPID_ID_7385:
  423. case VSC73XX_ICPU_CHIPID_ID_7395:
  424. break;
  425. default:
  426. dev_err(&spi->dev, "unsupported chip, id=%04x\n", id);
  427. return -ENODEV;
  428. }
  429. rev = (t >> VSC73XX_ICPU_CHIPID_REV_SHIFT) &
  430. VSC73XX_ICPU_CHIPID_REV_MASK;
  431. dev_info(&spi->dev, "VSC%04X (rev. %d) switch found\n", id, rev);
  432. return 0;
  433. }
  434. static int vsc7385_probe(struct spi_device *spi)
  435. {
  436. struct vsc7385 *vsc;
  437. struct vsc7385_platform_data *pdata;
  438. int err;
  439. printk(KERN_INFO DRV_DESC " version " DRV_VERSION"\n");
  440. pdata = spi->dev.platform_data;
  441. if (!pdata) {
  442. dev_err(&spi->dev, "no platform data specified\n");
  443. return -ENODEV;
  444. }
  445. vsc = kzalloc(sizeof(*vsc), GFP_KERNEL);
  446. if (!vsc) {
  447. dev_err(&spi->dev, "no memory for private data\n");
  448. return -ENOMEM;
  449. }
  450. mutex_init(&vsc->lock);
  451. vsc->pdata = pdata;
  452. vsc->spi = spi_dev_get(spi);
  453. dev_set_drvdata(&spi->dev, vsc);
  454. spi->mode = SPI_MODE_0;
  455. spi->bits_per_word = 8;
  456. err = spi_setup(spi);
  457. if (err) {
  458. dev_err(&spi->dev, "spi_setup failed, err=%d\n", err);
  459. goto err_drvdata;
  460. }
  461. err = vsc7385_detect(vsc);
  462. if (err) {
  463. dev_err(&spi->dev, "no chip found, err=%d\n", err);
  464. goto err_drvdata;
  465. }
  466. err = vsc7385_upload_ucode(vsc);
  467. if (err)
  468. goto err_drvdata;
  469. err = vsc7385_setup(vsc);
  470. if (err)
  471. goto err_drvdata;
  472. return 0;
  473. err_drvdata:
  474. dev_set_drvdata(&spi->dev, NULL);
  475. kfree(vsc);
  476. return err;
  477. }
  478. static int vsc7385_remove(struct spi_device *spi)
  479. {
  480. struct vsc7385_data *vsc;
  481. vsc = dev_get_drvdata(&spi->dev);
  482. dev_set_drvdata(&spi->dev, NULL);
  483. kfree(vsc);
  484. return 0;
  485. }
  486. static struct spi_driver vsc7385_driver = {
  487. .driver = {
  488. .name = DRV_NAME,
  489. .bus = &spi_bus_type,
  490. .owner = THIS_MODULE,
  491. },
  492. .probe = vsc7385_probe,
  493. .remove = vsc7385_remove,
  494. };
  495. static int __init vsc7385_init(void)
  496. {
  497. return spi_register_driver(&vsc7385_driver);
  498. }
  499. module_init(vsc7385_init);
  500. static void __exit vsc7385_exit(void)
  501. {
  502. spi_unregister_driver(&vsc7385_driver);
  503. }
  504. module_exit(vsc7385_exit);
  505. MODULE_DESCRIPTION(DRV_DESC);
  506. MODULE_VERSION(DRV_VERSION);
  507. MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  508. MODULE_LICENSE("GPL v2");