Lines Matching refs:card

19 static int _softing_fct_cmd(struct softing *card, int16_t cmd, uint16_t vector,  in _softing_fct_cmd()  argument
25 iowrite16(cmd, &card->dpram[DPRAM_FCT_PARAM]); in _softing_fct_cmd()
26 iowrite8(vector >> 8, &card->dpram[DPRAM_FCT_HOST + 1]); in _softing_fct_cmd()
27 iowrite8(vector, &card->dpram[DPRAM_FCT_HOST]); in _softing_fct_cmd()
34 ret = ioread8(&card->dpram[DPRAM_FCT_HOST]) + in _softing_fct_cmd()
35 (ioread8(&card->dpram[DPRAM_FCT_HOST + 1]) << 8); in _softing_fct_cmd()
40 return ioread16(&card->dpram[DPRAM_FCT_RESULT]); in _softing_fct_cmd()
49 dev_alert(&card->pdev->dev, "firmware %s failed (%i)\n", msg, ret); in _softing_fct_cmd()
53 static int softing_fct_cmd(struct softing *card, int16_t cmd, const char *msg) in softing_fct_cmd() argument
57 ret = _softing_fct_cmd(card, cmd, 0, msg); in softing_fct_cmd()
59 dev_alert(&card->pdev->dev, "%s returned %u\n", msg, ret); in softing_fct_cmd()
65 int softing_bootloader_command(struct softing *card, int16_t cmd, in softing_bootloader_command() argument
71 iowrite16(RES_NONE, &card->dpram[DPRAM_RECEIPT]); in softing_bootloader_command()
72 iowrite16(cmd, &card->dpram[DPRAM_COMMAND]); in softing_bootloader_command()
78 ret = ioread16(&card->dpram[DPRAM_RECEIPT]); in softing_bootloader_command()
90 dev_alert(&card->pdev->dev, "bootloader %s failed (%i)\n", msg, ret); in softing_bootloader_command()
133 int softing_load_fw(const char *file, struct softing *card, in softing_load_fw() argument
145 ret = request_firmware(&fw, file, &card->pdev->dev); in softing_load_fw()
148 dev_dbg(&card->pdev->dev, "%s, firmware(%s) got %u bytes" in softing_load_fw()
150 card->pdat->name, file, (unsigned int)fw->size, in softing_load_fw()
201 dev_alert(&card->pdev->dev, "DPRAM readback failed\n"); in softing_load_fw()
214 dev_info(&card->pdev->dev, "firmware %s failed\n", file); in softing_load_fw()
218 int softing_load_app_fw(const char *file, struct softing *card) in softing_load_app_fw() argument
228 ret = request_firmware(&fw, file, &card->pdev->dev); in softing_load_app_fw()
230 dev_alert(&card->pdev->dev, "request_firmware(%s) got %i\n", in softing_load_app_fw()
234 dev_dbg(&card->pdev->dev, "firmware(%s) got %lu bytes\n", in softing_load_app_fw()
245 dev_alert(&card->pdev->dev, "firmware starts with type 0x%x\n", in softing_load_app_fw()
250 dev_alert(&card->pdev->dev, "firmware string '%.*s' fault\n", in softing_load_app_fw()
270 dev_alert(&card->pdev->dev, in softing_load_app_fw()
282 memcpy_toio(&card->dpram[card->pdat->app.offs], dat, len); in softing_load_app_fw()
283 iowrite32(card->pdat->app.offs + card->pdat->app.addr, in softing_load_app_fw()
284 &card->dpram[DPRAM_COMMAND + 2]); in softing_load_app_fw()
285 iowrite32(addr, &card->dpram[DPRAM_COMMAND + 6]); in softing_load_app_fw()
286 iowrite16(len, &card->dpram[DPRAM_COMMAND + 10]); in softing_load_app_fw()
287 iowrite8(1, &card->dpram[DPRAM_COMMAND + 12]); in softing_load_app_fw()
288 ret = softing_bootloader_command(card, 1, "loading app."); in softing_load_app_fw()
292 rx_sum = ioread16(&card->dpram[DPRAM_RECEIPT + 2]); in softing_load_app_fw()
294 dev_alert(&card->pdev->dev, "SRAM seems to be damaged" in softing_load_app_fw()
303 iowrite32(start_addr, &card->dpram[DPRAM_COMMAND + 2]); in softing_load_app_fw()
304 iowrite8(1, &card->dpram[DPRAM_COMMAND + 6]); in softing_load_app_fw()
305 ret = softing_bootloader_command(card, 3, "start app."); in softing_load_app_fw()
312 dev_info(&card->pdev->dev, "firmware %s failed\n", file); in softing_load_app_fw()
316 static int softing_reset_chip(struct softing *card) in softing_reset_chip() argument
322 iowrite8(0, &card->dpram[DPRAM_RESET_RX_FIFO]); in softing_reset_chip()
323 iowrite8(0, &card->dpram[DPRAM_RESET_RX_FIFO+1]); in softing_reset_chip()
324 iowrite8(1, &card->dpram[DPRAM_RESET]); in softing_reset_chip()
325 iowrite8(0, &card->dpram[DPRAM_RESET+1]); in softing_reset_chip()
327 ret = softing_fct_cmd(card, 0, "reset_can"); in softing_reset_chip()
334 card->tx.pending = 0; in softing_reset_chip()
338 int softing_chip_poweron(struct softing *card) in softing_chip_poweron() argument
342 ret = _softing_fct_cmd(card, 99, 0x55, "sync-a"); in softing_chip_poweron()
346 ret = _softing_fct_cmd(card, 99, 0xaa, "sync-b"); in softing_chip_poweron()
350 ret = softing_reset_chip(card); in softing_chip_poweron()
354 ret = softing_fct_cmd(card, 43, "get_serial_number"); in softing_chip_poweron()
357 card->id.serial = ioread32(&card->dpram[DPRAM_FCT_PARAM]); in softing_chip_poweron()
359 ret = softing_fct_cmd(card, 12, "get_version"); in softing_chip_poweron()
362 card->id.fw_version = ioread16(&card->dpram[DPRAM_FCT_PARAM + 2]); in softing_chip_poweron()
363 card->id.hw_version = ioread16(&card->dpram[DPRAM_FCT_PARAM + 4]); in softing_chip_poweron()
364 card->id.license = ioread16(&card->dpram[DPRAM_FCT_PARAM + 6]); in softing_chip_poweron()
365 card->id.chip[0] = ioread16(&card->dpram[DPRAM_FCT_PARAM + 8]); in softing_chip_poweron()
366 card->id.chip[1] = ioread16(&card->dpram[DPRAM_FCT_PARAM + 10]); in softing_chip_poweron()
372 static void softing_initialize_timestamp(struct softing *card) in softing_initialize_timestamp() argument
376 card->ts_ref = ktime_get(); in softing_initialize_timestamp()
380 do_div(ovf, card->pdat->freq ?: 16); in softing_initialize_timestamp()
382 card->ts_overflow = ktime_add_us(0, ovf); in softing_initialize_timestamp()
385 ktime_t softing_raw2ktime(struct softing *card, u32 raw) in softing_raw2ktime() argument
397 do_div(rawl, card->pdat->freq ?: 16); in softing_raw2ktime()
398 target = ktime_add_us(card->ts_ref, rawl); in softing_raw2ktime()
400 tmp = ktime_add(target, card->ts_overflow); in softing_raw2ktime()
402 card->ts_ref = ktime_add(card->ts_ref, card->ts_overflow); in softing_raw2ktime()
404 tmp = ktime_add(target, card->ts_overflow); in softing_raw2ktime()
420 struct softing *card; in softing_startstop() local
429 card = priv->card; in softing_startstop()
431 if (!card->fw.up) in softing_startstop()
434 ret = mutex_lock_interruptible(&card->fw.lock); in softing_startstop()
443 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_startstop()
444 netdev = card->net[j]; in softing_startstop()
470 card->tx.pending = 0; in softing_startstop()
472 softing_enable_irq(card, 0); in softing_startstop()
473 ret = softing_reset_chip(card); in softing_startstop()
481 && (softing_error_reporting(card->net[0]) in softing_startstop()
482 != softing_error_reporting(card->net[1]))) { in softing_startstop()
483 dev_alert(&card->pdev->dev, in softing_startstop()
489 netdev = card->net[0]; in softing_startstop()
494 iowrite16(bt->brp, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
495 iowrite16(bt->sjw, &card->dpram[DPRAM_FCT_PARAM + 4]); in softing_startstop()
497 &card->dpram[DPRAM_FCT_PARAM + 6]); in softing_startstop()
498 iowrite16(bt->phase_seg2, &card->dpram[DPRAM_FCT_PARAM + 8]); in softing_startstop()
500 &card->dpram[DPRAM_FCT_PARAM + 10]); in softing_startstop()
501 ret = softing_fct_cmd(card, 1, "initialize_chip[0]"); in softing_startstop()
505 iowrite16(0, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
506 iowrite16(0, &card->dpram[DPRAM_FCT_PARAM + 4]); in softing_startstop()
507 ret = softing_fct_cmd(card, 3, "set_mode[0]"); in softing_startstop()
512 iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
513 iowrite16(0x07ff, &card->dpram[DPRAM_FCT_PARAM + 4]); in softing_startstop()
515 iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 6]); in softing_startstop()
516 iowrite16(0xffff, &card->dpram[DPRAM_FCT_PARAM + 8]); in softing_startstop()
517 iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 10]); in softing_startstop()
518 iowrite16(0x1fff, &card->dpram[DPRAM_FCT_PARAM + 12]); in softing_startstop()
519 ret = softing_fct_cmd(card, 7, "set_filter[0]"); in softing_startstop()
523 iowrite16(priv->output, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
524 ret = softing_fct_cmd(card, 5, "set_output[0]"); in softing_startstop()
529 netdev = card->net[1]; in softing_startstop()
534 iowrite16(bt->brp, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
535 iowrite16(bt->sjw, &card->dpram[DPRAM_FCT_PARAM + 4]); in softing_startstop()
537 &card->dpram[DPRAM_FCT_PARAM + 6]); in softing_startstop()
538 iowrite16(bt->phase_seg2, &card->dpram[DPRAM_FCT_PARAM + 8]); in softing_startstop()
540 &card->dpram[DPRAM_FCT_PARAM + 10]); in softing_startstop()
541 ret = softing_fct_cmd(card, 2, "initialize_chip[1]"); in softing_startstop()
545 iowrite16(0, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
546 iowrite16(0, &card->dpram[DPRAM_FCT_PARAM + 4]); in softing_startstop()
547 ret = softing_fct_cmd(card, 4, "set_mode[1]"); in softing_startstop()
552 iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
553 iowrite16(0x07ff, &card->dpram[DPRAM_FCT_PARAM + 4]); in softing_startstop()
555 iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 6]); in softing_startstop()
556 iowrite16(0xffff, &card->dpram[DPRAM_FCT_PARAM + 8]); in softing_startstop()
557 iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 10]); in softing_startstop()
558 iowrite16(0x1fff, &card->dpram[DPRAM_FCT_PARAM + 12]); in softing_startstop()
559 ret = softing_fct_cmd(card, 8, "set_filter[1]"); in softing_startstop()
563 iowrite16(priv->output, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
564 ret = softing_fct_cmd(card, 6, "set_output[1]"); in softing_startstop()
576 ret = softing_fct_cmd(card, 51, "enable_error_frame"); in softing_startstop()
582 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
583 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 4]); in softing_startstop()
584 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 6]); in softing_startstop()
585 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 8]); in softing_startstop()
586 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 10]); in softing_startstop()
587 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 12]); in softing_startstop()
588 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 14]); in softing_startstop()
589 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 16]); in softing_startstop()
590 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 18]); in softing_startstop()
591 iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 20]); in softing_startstop()
592 ret = softing_fct_cmd(card, 17, "initialize_interface"); in softing_startstop()
596 ret = softing_fct_cmd(card, 36, "enable_fifo"); in softing_startstop()
600 ret = softing_fct_cmd(card, 13, "fifo_tx_ack[0]"); in softing_startstop()
604 ret = softing_fct_cmd(card, 14, "fifo_tx_ack[1]"); in softing_startstop()
608 ret = softing_fct_cmd(card, 11, "start_chip"); in softing_startstop()
611 iowrite8(0, &card->dpram[DPRAM_INFO_BUSSTATE]); in softing_startstop()
612 iowrite8(0, &card->dpram[DPRAM_INFO_BUSSTATE2]); in softing_startstop()
613 if (card->pdat->generation < 2) { in softing_startstop()
614 iowrite8(0, &card->dpram[DPRAM_V2_IRQ_TOHOST]); in softing_startstop()
619 softing_initialize_timestamp(card); in softing_startstop()
629 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_startstop()
632 netdev = card->net[j]; in softing_startstop()
647 ret = softing_enable_irq(card, 1); in softing_startstop()
651 mutex_unlock(&card->fw.lock); in softing_startstop()
656 softing_enable_irq(card, 0); in softing_startstop()
657 softing_reset_chip(card); in softing_startstop()
658 mutex_unlock(&card->fw.lock); in softing_startstop()
660 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_startstop()
661 netdev = card->net[j]; in softing_startstop()
672 struct softing *card = priv->card; in softing_default_output() local
676 return (card->pdat->generation < 2) ? 0xfb : 0xfa; in softing_default_output()