Lines Matching +full:serial +full:- +full:dat +full:- +full:low
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2008-2010
5 * - Kurt Van Dijck, EIA Electronics
16 * low level DPRAM command.
17 * Make sure that card->dpram[DPRAM_FCT_HOST] is preset
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()
39 /* read return-value now */ in _softing_fct_cmd()
40 return ioread16(&card->dpram[DPRAM_FCT_RESULT]); in _softing_fct_cmd()
48 ret = (ret == RES_NONE) ? -ETIMEDOUT : -ECANCELED; in _softing_fct_cmd()
49 dev_alert(&card->pdev->dev, "firmware %s failed (%i)\n", msg, ret); in _softing_fct_cmd()
59 dev_alert(&card->pdev->dev, "%s returned %u\n", msg, ret); in softing_fct_cmd()
60 ret = -EIO; in softing_fct_cmd()
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()
89 ret = (ret == RES_NONE) ? -ETIMEDOUT : -ECANCELED; in softing_bootloader_command()
90 dev_alert(&card->pdev->dev, "bootloader %s failed (%i)\n", msg, ret); in softing_bootloader_command()
106 * uint8_t dat[len]; in fw_parse()
127 return -EINVAL; in fw_parse()
138 const uint8_t *mem, *end, *dat; in softing_load_fw() local
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()
151 (offset >= 0) ? '+' : '-', (unsigned int)abs(offset)); in softing_load_fw()
153 mem = fw->data; in softing_load_fw()
154 end = &mem[fw->size]; in softing_load_fw()
156 ret = fw_parse(&mem, &type, &addr, &len, &dat); in softing_load_fw()
161 if (strncmp("Structured Binary Format, Softing GmbH" , dat, len)) { in softing_load_fw()
162 ret = -EINVAL; in softing_load_fw()
167 ret = fw_parse(&mem, &type, &addr, &len, &dat); in softing_load_fw()
178 ret = -EINVAL; in softing_load_fw()
184 memcpy_toio(&dpram[addr + offset], dat, len); in softing_load_fw()
189 buflen = (len + (1024-1)) & ~(1024-1); in softing_load_fw()
192 ret = -ENOMEM; in softing_load_fw()
199 if (memcmp(buf, dat, len)) { in softing_load_fw()
201 dev_alert(&card->pdev->dev, "DPRAM readback failed\n"); in softing_load_fw()
202 ret = -EIO; in softing_load_fw()
214 dev_info(&card->pdev->dev, "firmware %s failed\n", file); in softing_load_fw()
221 const uint8_t *mem, *end, *dat; in softing_load_app_fw() local
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()
235 file, (unsigned long)fw->size); in softing_load_app_fw()
237 mem = fw->data; in softing_load_app_fw()
238 end = &mem[fw->size]; in softing_load_app_fw()
240 ret = fw_parse(&mem, &type, &addr, &len, &dat); in softing_load_app_fw()
243 ret = -EINVAL; in softing_load_app_fw()
245 dev_alert(&card->pdev->dev, "firmware starts with type 0x%x\n", in softing_load_app_fw()
249 if (strncmp("Structured Binary Format, Softing GmbH", dat, len)) { in softing_load_app_fw()
250 dev_alert(&card->pdev->dev, "firmware string '%.*s' fault\n", in softing_load_app_fw()
251 len, dat); in softing_load_app_fw()
256 ret = fw_parse(&mem, &type, &addr, &len, &dat); in softing_load_app_fw()
270 dev_alert(&card->pdev->dev, in softing_load_app_fw()
272 ret = -EINVAL; in softing_load_app_fw()
278 sum += dat[j]; 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()
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()
296 ret = -EIO; 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()
312 dev_info(&card->pdev->dev, "firmware %s failed\n", file); in softing_load_app_fw()
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()
334 card->tx.pending = 0; in softing_reset_chip()
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()
357 card->id.serial = ioread32(&card->dpram[DPRAM_FCT_PARAM]); 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()
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()
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()
413 return (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) in softing_error_reporting()
429 card = priv->card; in softing_startstop()
431 if (!card->fw.up) in softing_startstop()
432 return -EIO; in softing_startstop()
434 ret = mutex_lock_interruptible(&card->fw.lock); in softing_startstop()
441 bus_bitmask_start |= (1 << priv->index); in softing_startstop()
443 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_startstop()
444 netdev = card->net[j]; in softing_startstop()
455 priv->tx.pending = 0; in softing_startstop()
456 priv->tx.echo_put = 0; in softing_startstop()
457 priv->tx.echo_get = 0; in softing_startstop()
468 priv->can.state = CAN_STATE_STOPPED; in softing_startstop()
470 card->tx.pending = 0; 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()
493 bt = &priv->can.bittiming; 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()
496 iowrite16(bt->phase_seg1 + bt->prop_seg, 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()
499 iowrite16((priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) ? 1 : 0, in softing_startstop()
500 &card->dpram[DPRAM_FCT_PARAM + 10]); 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()
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()
523 iowrite16(priv->output, &card->dpram[DPRAM_FCT_PARAM + 2]); in softing_startstop()
529 netdev = card->net[1]; in softing_startstop()
533 bt = &priv->can.bittiming; 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()
536 iowrite16(bt->phase_seg1 + bt->prop_seg, 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()
539 iowrite16((priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) ? 1 : 0, in softing_startstop()
540 &card->dpram[DPRAM_FCT_PARAM + 10]); 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()
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()
563 iowrite16(priv->output, &card->dpram[DPRAM_FCT_PARAM + 2]); 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()
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()
629 for (j = 0; j < ARRAY_SIZE(card->net); ++j) { in softing_startstop()
632 netdev = card->net[j]; in softing_startstop()
636 priv->can.state = CAN_STATE_ERROR_ACTIVE; in softing_startstop()
641 ++priv->can.can_stats.restarts; in softing_startstop()
651 mutex_unlock(&card->fw.lock); in softing_startstop()
654 ret = -EINVAL; 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()
674 switch (priv->chip) { in softing_default_output()
676 return (card->pdat->generation < 2) ? 0xfb : 0xfa; in softing_default_output()