staticint lan743x_get_channel(u32 ch_map)
{ int idx;
for (idx = 0; idx < 32; idx++) { if (ch_map & (0x1 << idx)) return idx;
}
return -EINVAL;
}
int lan743x_gpio_init(struct lan743x_adapter *adapter)
{ struct lan743x_gpio *gpio = &adapter->gpio;
spin_lock_init(&gpio->gpio_lock);
gpio->gpio_cfg0 = 0; /* set all direction to input, data = 0 */
gpio->gpio_cfg1 = 0x0FFF0000;/* disable all gpio, set to open drain */
gpio->gpio_cfg2 = 0;/* set all to 1588 low polarity level */
gpio->gpio_cfg3 = 0;/* disable all 1588 output */
lan743x_csr_write(adapter, GPIO_CFG0, gpio->gpio_cfg0);
lan743x_csr_write(adapter, GPIO_CFG1, gpio->gpio_cfg1);
lan743x_csr_write(adapter, GPIO_CFG2, gpio->gpio_cfg2);
lan743x_csr_write(adapter, GPIO_CFG3, gpio->gpio_cfg3);
return 0;
}
staticvoid lan743x_ptp_wait_till_cmd_done(struct lan743x_adapter *adapter,
u32 bit_mask)
{ int timeout = PTP_CMD_CTL_TIMEOUT_CNT;
u32 data = 0;
while (timeout &&
(data = (lan743x_csr_read(adapter, PTP_CMD_CTL) &
bit_mask))) {
usleep_range(1000, 20000);
timeout--;
} if (data) {
netif_err(adapter, drv, adapter->netdev, "timeout waiting for cmd to be done, cmd = 0x%08X\n",
bit_mask);
}
}
/* assign pin to GPIO function */
lan743x_led_mux_enable(adapter, pin, false);
/* set as output, and zero initial value */
gpio->gpio_cfg0 |= GPIO_CFG0_GPIO_DIR_BIT_(pin);
gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DATA_BIT_(pin);
lan743x_csr_write(adapter, GPIO_CFG0, gpio->gpio_cfg0);
/* enable gpio, and set buffer type to push pull */
gpio->gpio_cfg1 &= ~GPIO_CFG1_GPIOEN_BIT_(pin);
gpio->gpio_cfg1 |= GPIO_CFG1_GPIOBUF_BIT_(pin);
lan743x_csr_write(adapter, GPIO_CFG1, gpio->gpio_cfg1);
/* set 1588 polarity to high */
gpio->gpio_cfg2 |= GPIO_CFG2_1588_POL_BIT_(pin);
lan743x_csr_write(adapter, GPIO_CFG2, gpio->gpio_cfg2);
if (event_channel == 0) { /* use channel A */
gpio->gpio_cfg3 &= ~GPIO_CFG3_1588_CH_SEL_BIT_(pin);
} else { /* use channel B */
gpio->gpio_cfg3 |= GPIO_CFG3_1588_CH_SEL_BIT_(pin);
}
gpio->gpio_cfg3 |= GPIO_CFG3_1588_OE_BIT_(pin);
lan743x_csr_write(adapter, GPIO_CFG3, gpio->gpio_cfg3);
ret = pin;
}
spin_unlock_irqrestore(&gpio->gpio_lock, irq_flags); return ret;
}
staticvoid lan743x_gpio_release(struct lan743x_adapter *adapter, int pin)
{ struct lan743x_gpio *gpio = &adapter->gpio; unsignedlong irq_flags = 0; int bit_mask = BIT(pin);
spin_lock_irqsave(&gpio->gpio_lock, irq_flags); if (gpio->used_bits & bit_mask) {
gpio->used_bits &= ~bit_mask; if (gpio->output_bits & bit_mask) {
gpio->output_bits &= ~bit_mask;
if (perout->event_ch >= 0) { /* set target to far in the future, effectively disabling it */
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_SEC_X(perout->event_ch),
0xFFFF0000);
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_NS_X(perout->event_ch),
0);
if (period64 < 200) {
netif_warn(adapter, drv, adapter->netdev, "perout period too small, minimum is 200nS\n");
ret = -EOPNOTSUPP; goto failed;
} if (wf_high >= period64) {
netif_warn(adapter, drv, adapter->netdev, "pulse width must be smaller than period\n");
ret = -EINVAL; goto failed;
}
/* Check if we can do 50% toggle on an even value of period. * If the period number is odd, then check if the requested * pulse width is the same as one of pre-defined width values. * Otherwise, return failure.
*/
half = div_s64_rem(period64, 2, &reminder); if (!reminder) { if (half == wf_high) { /* It's 50% match. Use the toggle option */
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_TOGGLE_; /* In this case, divide period value by 2 */
ts_period = ns_to_timespec64(div_s64(period64, 2));
period_sec = ts_period.tv_sec;
period_nsec = ts_period.tv_nsec;
goto program;
}
} /* if we can't do toggle, then the width option needs to be the exact match */ if (wf_high == 200000000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_200MS_;
} elseif (wf_high == 10000000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_10MS_;
} elseif (wf_high == 1000000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_1MS_;
} elseif (wf_high == 100000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_100US_;
} elseif (wf_high == 10000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_10US_;
} elseif (wf_high == 100) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_100NS_;
} else {
netif_warn(adapter, drv, adapter->netdev, "duty cycle specified is not supported\n");
ret = -EOPNOTSUPP; goto failed;
}
} else { if (period_sec == 0) { if (period_nsec >= 400000000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_200MS_;
} elseif (period_nsec >= 20000000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_10MS_;
} elseif (period_nsec >= 2000000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_1MS_;
} elseif (period_nsec >= 200000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_100US_;
} elseif (period_nsec >= 20000) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_10US_;
} elseif (period_nsec >= 200) {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_100NS_;
} else {
netif_warn(adapter, drv, adapter->netdev, "perout period too small, minimum is 200nS\n");
ret = -EOPNOTSUPP; goto failed;
}
} else {
pulse_width = PTP_GENERAL_CONFIG_CLOCK_EVENT_200MS_;
}
}
program:
/* turn off by setting target far in future */
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_SEC_X(perout->event_ch),
0xFFFF0000);
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_NS_X(perout->event_ch), 0);
/* Configure to pulse every period */
general_config = lan743x_csr_read(adapter, PTP_GENERAL_CONFIG);
general_config &= ~(PTP_GENERAL_CONFIG_CLOCK_EVENT_X_MASK_
(perout->event_ch));
general_config |= PTP_GENERAL_CONFIG_CLOCK_EVENT_X_SET_
(perout->event_ch, pulse_width);
general_config &= ~PTP_GENERAL_CONFIG_RELOAD_ADD_X_
(perout->event_ch);
lan743x_csr_write(adapter, PTP_GENERAL_CONFIG, general_config);
/* set the reload to one toggle cycle */
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_RELOAD_SEC_X(perout->event_ch),
period_sec);
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_RELOAD_NS_X(perout->event_ch),
period_nsec);
/* set the start time */
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_SEC_X(perout->event_ch),
start_sec);
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_NS_X(perout->event_ch),
start_nsec);
staticvoid lan743x_ptp_io_perout_off(struct lan743x_adapter *adapter,
u32 index)
{ struct lan743x_ptp *ptp = &adapter->ptp; int perout_pin; int event_ch;
u32 gen_cfg; int val;
event_ch = ptp->ptp_io_perout[index]; if (event_ch >= 0) { /* set target to far in the future, effectively disabling it */
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_SEC_X(event_ch),
0xFFFF0000);
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_NS_X(event_ch),
0);
/* Deselect Event output */
val = lan743x_csr_read(adapter, PTP_IO_EVENT_OUTPUT_CFG);
/* Disables the output of Local Time Target compare events */
val &= ~PTP_IO_EVENT_OUTPUT_CFG_EN_(perout_pin);
lan743x_csr_write(adapter, PTP_IO_EVENT_OUTPUT_CFG, val);
/* Configured as an opendrain driver*/
val = lan743x_csr_read(adapter, PTP_IO_PIN_CFG);
val &= ~PTP_IO_PIN_CFG_OBUF_TYPE_(perout_pin);
lan743x_csr_write(adapter, PTP_IO_PIN_CFG, val); /* Dummy read to make sure write operation success */
val = lan743x_csr_read(adapter, PTP_IO_PIN_CFG);
}
staticint lan743x_ptp_io_perout(struct lan743x_adapter *adapter, int on, struct ptp_perout_request *perout_request)
{ struct lan743x_ptp *ptp = &adapter->ptp;
u32 period_sec, period_nsec;
u32 start_sec, start_nsec;
u32 pulse_sec, pulse_nsec; int pulse_width; int perout_pin; int event_ch;
u32 gen_cfg;
u32 index; int val;
index = perout_request->index;
event_ch = ptp->ptp_io_perout[index];
/* turn off by setting target far in future */
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_SEC_X(event_ch),
0xFFFF0000);
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_NS_X(event_ch), 0);
/* Configure to pulse every period */
gen_cfg = lan743x_csr_read(adapter, HS_PTP_GENERAL_CONFIG);
gen_cfg &= ~(HS_PTP_GENERAL_CONFIG_CLOCK_EVENT_X_MASK_(event_ch));
gen_cfg |= HS_PTP_GENERAL_CONFIG_CLOCK_EVENT_X_SET_
(event_ch, pulse_width);
gen_cfg |= HS_PTP_GENERAL_CONFIG_EVENT_POL_X_(event_ch);
gen_cfg &= ~(HS_PTP_GENERAL_CONFIG_RELOAD_ADD_X_(event_ch));
lan743x_csr_write(adapter, HS_PTP_GENERAL_CONFIG, gen_cfg);
/* set the reload to one toggle cycle */
period_sec = perout_request->period.sec;
period_sec += perout_request->period.nsec / 1000000000;
period_nsec = perout_request->period.nsec % 1000000000;
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_RELOAD_SEC_X(event_ch),
period_sec);
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_RELOAD_NS_X(event_ch),
period_nsec);
/* set the start time */
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_SEC_X(event_ch),
start_sec);
lan743x_csr_write(adapter,
PTP_CLOCK_TARGET_NS_X(event_ch),
start_nsec);
/* Enable LTC Target Read */
val = lan743x_csr_read(adapter, PTP_CMD_CTL);
val |= PTP_CMD_CTL_PTP_LTC_TARGET_READ_;
lan743x_csr_write(adapter, PTP_CMD_CTL, val);
/* Configure as an push/pull driver */
val = lan743x_csr_read(adapter, PTP_IO_PIN_CFG);
val |= PTP_IO_PIN_CFG_OBUF_TYPE_(perout_pin);
lan743x_csr_write(adapter, PTP_IO_PIN_CFG, val);
/* Select Event output */
val = lan743x_csr_read(adapter, PTP_IO_EVENT_OUTPUT_CFG); if (event_ch) /* Channel B as the output */
val |= PTP_IO_EVENT_OUTPUT_CFG_SEL_(perout_pin); else /* Channel A as the output */
val &= ~PTP_IO_EVENT_OUTPUT_CFG_SEL_(perout_pin);
/* Enables the output of Local Time Target compare events */
val |= PTP_IO_EVENT_OUTPUT_CFG_EN_(perout_pin);
lan743x_csr_write(adapter, PTP_IO_EVENT_OUTPUT_CFG, val);
if ((flags & PTP_EXTTS_EDGES) == PTP_EXTTS_EDGES) return -EOPNOTSUPP;
mutex_lock(&ptp->command_lock); /* PTP-IO Event Capture Enable */
val = lan743x_csr_read(adapter, PTP_IO_CAP_CONFIG); if (flags & PTP_FALLING_EDGE) {
val &= ~PTP_IO_CAP_CONFIG_LOCK_RE_(channel);
val &= ~PTP_IO_CAP_CONFIG_RE_CAP_EN_(channel);
val |= PTP_IO_CAP_CONFIG_LOCK_FE_(channel);
val |= PTP_IO_CAP_CONFIG_FE_CAP_EN_(channel);
} else { /* Rising eventing as Default */
val &= ~PTP_IO_CAP_CONFIG_LOCK_FE_(channel);
val &= ~PTP_IO_CAP_CONFIG_FE_CAP_EN_(channel);
val |= PTP_IO_CAP_CONFIG_LOCK_RE_(channel);
val |= PTP_IO_CAP_CONFIG_RE_CAP_EN_(channel);
}
lan743x_csr_write(adapter, PTP_IO_CAP_CONFIG, val);
/* PTP-IO Select */
val = lan743x_csr_read(adapter, PTP_IO_SEL);
val &= ~PTP_IO_SEL_MASK_;
val |= channel << PTP_IO_SEL_SHIFT_;
lan743x_csr_write(adapter, PTP_IO_SEL, val);
/* PTP Interrupt Enable Register */ if (flags & PTP_FALLING_EDGE)
val = PTP_INT_EN_FE_EN_SET_(channel); else
val = PTP_INT_EN_RE_EN_SET_(channel);
lan743x_csr_write(adapter, PTP_INT_EN_SET, val);
mutex_unlock(&ptp->command_lock);
return 0;
}
staticint lan743x_ptp_io_extts(struct lan743x_adapter *adapter, int on, struct ptp_extts_request *extts_request)
{ struct lan743x_ptp *ptp = &adapter->ptp;
u32 flags = extts_request->flags;
u32 index = extts_request->index; struct lan743x_extts *extts; int extts_pin; int ret = 0;
extts = &ptp->extts[index];
if (on) {
extts_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, index); if (extts_pin < 0) return -EBUSY;
ret = lan743x_ptp_io_event_cap_en(adapter, flags, index); if (!ret)
extts->flags = flags;
} else {
lan743x_ptp_io_extts_off(adapter, index);
}
/* Confirm the requested function is supported. Parameter * validation is done by the caller.
*/ switch (func) { case PTP_PF_NONE: case PTP_PF_PEROUT: break; case PTP_PF_EXTTS: if (!adapter->is_pci11x1x)
result = -1; break; case PTP_PF_PHYSYNC: default:
result = -1; break;
} return result;
}
if (ptp_int_sts & PTP_INT_BIT_TX_TS_) {
ptp_schedule_worker(ptp->ptp_clock, 0);
enable_flag = 0;/* tasklet will re-enable later */
} if (ptp_int_sts & PTP_INT_BIT_TX_SWTS_ERR_) {
netif_err(adapter, drv, adapter->netdev, "PTP TX Software Timestamp Error\n"); /* clear int status bit */
lan743x_csr_write(adapter, PTP_INT_STS,
PTP_INT_BIT_TX_SWTS_ERR_);
} if (ptp_int_sts & PTP_INT_BIT_TIMER_B_) { /* clear int status bit */
lan743x_csr_write(adapter, PTP_INT_STS,
PTP_INT_BIT_TIMER_B_);
} if (ptp_int_sts & PTP_INT_BIT_TIMER_A_) { /* clear int status bit */
lan743x_csr_write(adapter, PTP_INT_STS,
PTP_INT_BIT_TIMER_A_);
}
spin_lock_bh(&ptp->tx_ts_lock); if (ptp->tx_ts_skb_queue_size < LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS) {
ptp->tx_ts_skb_queue[ptp->tx_ts_skb_queue_size] = skb; if (ignore_sync)
ptp->tx_ts_ignore_sync_queue |=
BIT(ptp->tx_ts_skb_queue_size);
ptp->tx_ts_skb_queue_size++;
} else { /* this should never happen, so long as the tx channel * calls and honors the result from * lan743x_ptp_request_tx_timestamp
*/
netif_err(adapter, drv, adapter->netdev, "tx ts skb queue overflow\n");
dev_kfree_skb(skb);
}
spin_unlock_bh(&ptp->tx_ts_lock);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.