swd: Remove DAP from parameter list
[fw/openocd] / src / jtag / drivers / jlink.c
index 1db1a711e7e9c9d4e48137bdf00e44849fed01c3..04297ca07406d1d46eb38c8b074690d85a5a9d1d 100644 (file)
@@ -87,11 +87,9 @@ static void jlink_runtest(int num_cycles);
 static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
                int scan_size, struct scan_command *command);
 static void jlink_reset(int trst, int srst);
-static int jlink_swd_run_queue(struct adiv5_dap *dap);
-static void jlink_swd_queue_cmd(struct adiv5_dap *dap, uint8_t cmd,
-               uint32_t *dst, uint32_t data);
-static int jlink_swd_switch_seq(struct adiv5_dap *dap,
-               enum swd_special_seq seq);
+static int jlink_swd_run_queue(void);
+static void jlink_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk);
+static int jlink_swd_switch_seq(enum swd_special_seq seq);
 
 /* J-Link tap buffer functions */
 static void jlink_tap_init(void);
@@ -216,11 +214,23 @@ static int jlink_execute_queue(void)
 static int jlink_speed(int speed)
 {
        int ret;
+       uint32_t freq;
+       uint16_t div;
+       int max_speed;
+
+       if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_GET_SPEEDS)) {
+               ret = jaylink_get_speeds(devh, &freq, &div);
+
+               if (ret != JAYLINK_OK) {
+                       LOG_ERROR("jaylink_get_speeds() failed: %s.",
+                               jaylink_strerror_name(ret));
+                       return ERROR_JTAG_DEVICE_ERROR;
+               }
 
-       if (speed > JLINK_MAX_SPEED) {
-               LOG_INFO("Reduce speed from %d kHz to %d kHz (maximum).", speed,
-                       JLINK_MAX_SPEED);
-               speed = JLINK_MAX_SPEED;
+               freq = freq / 1000;
+               max_speed = freq / div;
+       } else {
+               max_speed = JLINK_MAX_SPEED;
        }
 
        if (!speed) {
@@ -230,6 +240,10 @@ static int jlink_speed(int speed)
                }
 
                speed = JAYLINK_SPEED_ADAPTIVE_CLOCKING;
+       } else if (speed > max_speed) {
+               LOG_INFO("Reduced speed from %d kHz to %d kHz (maximum).", speed,
+                       max_speed);
+               speed = max_speed;
        }
 
        ret = jaylink_set_speed(devh, speed);
@@ -1552,22 +1566,19 @@ static int jlink_swd_init(void)
        return ERROR_OK;
 }
 
-static void jlink_swd_write_reg(struct adiv5_dap *dap, uint8_t cmd,
-               uint32_t value)
+static void jlink_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
 {
        assert(!(cmd & SWD_CMD_RnW));
-       jlink_swd_queue_cmd(dap, cmd, NULL, value);
+       jlink_swd_queue_cmd(cmd, NULL, value, ap_delay_clk);
 }
 
-static void jlink_swd_read_reg(struct adiv5_dap *dap, uint8_t cmd,
-               uint32_t *value)
+static void jlink_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
 {
        assert(cmd & SWD_CMD_RnW);
-       jlink_swd_queue_cmd(dap, cmd, value, 0);
+       jlink_swd_queue_cmd(cmd, value, 0, ap_delay_clk);
 }
 
-static int_least32_t jlink_swd_frequency(struct adiv5_dap *dap,
-               int_least32_t hz)
+static int_least32_t jlink_swd_frequency(int_least32_t hz)
 {
        if (hz > 0)
                jlink_speed(hz / 1000);
@@ -1746,7 +1757,7 @@ static void jlink_queue_data_in(uint32_t len)
        tap_length += len;
 }
 
-static int jlink_swd_switch_seq(struct adiv5_dap *dap, enum swd_special_seq seq)
+static int jlink_swd_switch_seq(enum swd_special_seq seq)
 {
        const uint8_t *s;
        unsigned int s_len;
@@ -1777,7 +1788,7 @@ static int jlink_swd_switch_seq(struct adiv5_dap *dap, enum swd_special_seq seq)
        return ERROR_OK;
 }
 
-static int jlink_swd_run_queue(struct adiv5_dap *dap)
+static int jlink_swd_run_queue(void)
 {
        int i;
        int ret;
@@ -1833,15 +1844,13 @@ skip:
        return ret;
 }
 
-static void jlink_swd_queue_cmd(struct adiv5_dap *dap, uint8_t cmd,
-               uint32_t *dst, uint32_t data)
+static void jlink_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
 {
        uint8_t data_parity_trn[DIV_ROUND_UP(32 + 1, 8)];
-
-       if (tap_length + 46 + 8 + dap->memaccess_tck >= swd_buffer_size * 8 ||
-               pending_scan_results_length == MAX_PENDING_SCAN_RESULTS) {
+       if (tap_length + 46 + 8 + ap_delay_clk >= sizeof(tdi_buffer) * 8 ||
+           pending_scan_results_length == MAX_PENDING_SCAN_RESULTS) {
                /* Not enough room in the queue. Run the queue. */
-               queued_retval = jlink_swd_run_queue(dap);
+               queued_retval = jlink_swd_run_queue();
        }
 
        if (queued_retval != ERROR_OK)
@@ -1874,7 +1883,7 @@ static void jlink_swd_queue_cmd(struct adiv5_dap *dap, uint8_t cmd,
 
        /* Insert idle cycles after AP accesses to avoid WAIT. */
        if (cmd & SWD_CMD_APnDP)
-               jlink_queue_data_out(NULL, dap->memaccess_tck);
+               jlink_queue_data_out(NULL, ap_delay_clk);
 }
 
 static const struct swd_driver jlink_swd = {