Lines Matching +full:i2c +full:- +full:ocores
1 // SPDX-License-Identifier: GPL-2.0-only
13 #include <linux/clk-provider.h>
15 #include <linux/platform_data/i2c-xiic.h>
16 #include <linux/platform_data/i2c-ocores.h>
22 #include <linux/i2c.h>
24 #include <linux/nvmem-consumer.h>
437 (void *)((uintptr_t)(bp) + (map)->bp_offset); \
453 uintptr_t addr = (uintptr_t)(bp) + (res)->bp_offset; \
483 * 7: I2C controller
493 --
650 .name = "xiic-i2c",
700 .modalias = "spi-nor",
825 .modalias = "spi-nor",
834 .name = "ocores-i2c",
990 .modalias = "spi-nor",
999 .name = "ocores-i2c",
1005 .reg_io_width = 4, // 32-bit/4-byte
1006 .reg_shift = 2, // 32-bit addressing
1146 return bp->sma_op->init(bp); in ptp_ocp_sma_init()
1152 return bp->sma_op->get(bp, sma_nr); in ptp_ocp_sma_get()
1158 return bp->sma_op->set_inputs(bp, sma_nr, val); in ptp_ocp_sma_set_inputs()
1164 return bp->sma_op->set_output(bp, sma_nr, val); in ptp_ocp_sma_set_output()
1189 return -EINVAL; in ptp_ocp_select_val_from_name()
1202 count--; in ptp_ocp_select_table_show()
1217 iowrite32(ctrl, &bp->reg->ctrl); in __ptp_ocp_gettime_locked()
1220 ctrl = ioread32(&bp->reg->ctrl); in __ptp_ocp_gettime_locked()
1226 if (sts && bp->ts_window_adjust) { in __ptp_ocp_gettime_locked()
1227 s64 ns = timespec64_to_ns(&sts->post_ts); in __ptp_ocp_gettime_locked()
1229 sts->post_ts = ns_to_timespec64(ns - bp->ts_window_adjust); in __ptp_ocp_gettime_locked()
1232 time_ns = ioread32(&bp->reg->time_ns); in __ptp_ocp_gettime_locked()
1233 time_sec = ioread32(&bp->reg->time_sec); in __ptp_ocp_gettime_locked()
1235 ts->tv_sec = time_sec; in __ptp_ocp_gettime_locked()
1236 ts->tv_nsec = time_ns; in __ptp_ocp_gettime_locked()
1238 return ctrl & OCP_CTRL_READ_TIME_DONE ? 0 : -ETIMEDOUT; in __ptp_ocp_gettime_locked()
1249 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_gettimex()
1251 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_gettimex()
1262 time_ns = ts->tv_nsec; in __ptp_ocp_settime_locked()
1263 time_sec = ts->tv_sec; in __ptp_ocp_settime_locked()
1265 select = ioread32(&bp->reg->select); in __ptp_ocp_settime_locked()
1266 iowrite32(OCP_SELECT_CLK_REG, &bp->reg->select); in __ptp_ocp_settime_locked()
1268 iowrite32(time_ns, &bp->reg->adjust_ns); in __ptp_ocp_settime_locked()
1269 iowrite32(time_sec, &bp->reg->adjust_sec); in __ptp_ocp_settime_locked()
1272 iowrite32(ctrl, &bp->reg->ctrl); in __ptp_ocp_settime_locked()
1275 iowrite32(select >> 16, &bp->reg->select); in __ptp_ocp_settime_locked()
1284 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_settime()
1286 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_settime()
1296 select = ioread32(&bp->reg->select); in __ptp_ocp_adjtime_locked()
1297 iowrite32(OCP_SELECT_CLK_REG, &bp->reg->select); in __ptp_ocp_adjtime_locked()
1299 iowrite32(adj_val, &bp->reg->offset_ns); in __ptp_ocp_adjtime_locked()
1300 iowrite32(NSEC_PER_SEC, &bp->reg->offset_window_ns); in __ptp_ocp_adjtime_locked()
1303 iowrite32(ctrl, &bp->reg->ctrl); in __ptp_ocp_adjtime_locked()
1306 iowrite32(select >> 16, &bp->reg->select); in __ptp_ocp_adjtime_locked()
1316 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_adjtime_coarse()
1323 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_adjtime_coarse()
1333 if (delta_ns > NSEC_PER_SEC || -delta_ns > NSEC_PER_SEC) { in ptp_ocp_adjtime()
1339 adj_ns = sign ? -delta_ns : delta_ns; in ptp_ocp_adjtime()
1341 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_adjtime()
1343 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_adjtime()
1354 return -EOPNOTSUPP; in ptp_ocp_null_adjfine()
1366 return -EOPNOTSUPP; in ptp_ocp_null_adjphase()
1378 switch (rq->type) { in ptp_ocp_enable()
1381 switch (rq->extts.index) { in ptp_ocp_enable()
1383 ext = bp->ts0; in ptp_ocp_enable()
1386 ext = bp->ts1; in ptp_ocp_enable()
1389 ext = bp->ts2; in ptp_ocp_enable()
1392 ext = bp->ts3; in ptp_ocp_enable()
1395 ext = bp->ts4; in ptp_ocp_enable()
1398 ext = bp->pps; in ptp_ocp_enable()
1404 ext = bp->pps; in ptp_ocp_enable()
1407 switch (rq->perout.index) { in ptp_ocp_enable()
1412 if (on && (rq->perout.period.sec != 1 || in ptp_ocp_enable()
1413 rq->perout.period.nsec != 0)) in ptp_ocp_enable()
1414 return -EINVAL; in ptp_ocp_enable()
1420 req = rq->perout.index - 1; in ptp_ocp_enable()
1421 ext = bp->signal_out[req]; in ptp_ocp_enable()
1422 err = ptp_ocp_signal_from_perout(bp, req, &rq->perout); in ptp_ocp_enable()
1429 return -EOPNOTSUPP; in ptp_ocp_enable()
1432 err = -ENXIO; in ptp_ocp_enable()
1434 err = ext->info->enable(ext, req, on); in ptp_ocp_enable()
1463 return -EOPNOTSUPP; in ptp_ocp_verify()
1491 select = ioread32(&bp->reg->select); in __ptp_ocp_clear_drift_locked()
1492 iowrite32(OCP_SELECT_CLK_REG, &bp->reg->select); in __ptp_ocp_clear_drift_locked()
1494 iowrite32(0, &bp->reg->drift_ns); in __ptp_ocp_clear_drift_locked()
1497 iowrite32(ctrl, &bp->reg->ctrl); in __ptp_ocp_clear_drift_locked()
1500 iowrite32(select >> 16, &bp->reg->select); in __ptp_ocp_clear_drift_locked()
1508 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_utc_distribute()
1510 bp->utc_tai_offset = val; in ptp_ocp_utc_distribute()
1512 if (bp->irig_out) in ptp_ocp_utc_distribute()
1513 iowrite32(val, &bp->irig_out->adj_sec); in ptp_ocp_utc_distribute()
1514 if (bp->dcf_out) in ptp_ocp_utc_distribute()
1515 iowrite32(val, &bp->dcf_out->adj_sec); in ptp_ocp_utc_distribute()
1516 if (bp->nmea_out) in ptp_ocp_utc_distribute()
1517 iowrite32(val, &bp->nmea_out->adj_sec); in ptp_ocp_utc_distribute()
1519 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_utc_distribute()
1529 status = ioread32(&bp->pps_to_clk->status); in ptp_ocp_watchdog()
1532 iowrite32(status, &bp->pps_to_clk->status); in ptp_ocp_watchdog()
1533 if (!bp->gnss_lost) { in ptp_ocp_watchdog()
1534 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_watchdog()
1536 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_watchdog()
1537 bp->gnss_lost = ktime_get_real_seconds(); in ptp_ocp_watchdog()
1540 } else if (bp->gnss_lost) { in ptp_ocp_watchdog()
1541 bp->gnss_lost = 0; in ptp_ocp_watchdog()
1547 if (bp->tod) { in ptp_ocp_watchdog()
1548 status = ioread32(&bp->tod->utc_status); in ptp_ocp_watchdog()
1551 utc_offset != bp->utc_tai_offset) in ptp_ocp_watchdog()
1555 mod_timer(&bp->watchdog, jiffies + HZ); in ptp_ocp_watchdog()
1566 ctrl = ioread32(&bp->reg->ctrl); in ptp_ocp_estimate_pci_timing()
1569 iowrite32(ctrl, &bp->reg->ctrl); in ptp_ocp_estimate_pci_timing()
1573 ctrl = ioread32(&bp->reg->ctrl); in ptp_ocp_estimate_pci_timing()
1577 delay = min(delay, end - start); in ptp_ocp_estimate_pci_timing()
1579 bp->ts_window_adjust = (delay >> 5) * 3; in ptp_ocp_estimate_pci_timing()
1589 iowrite32(ctrl, &bp->reg->ctrl); in ptp_ocp_init_clock()
1592 iowrite32(servo_conf->servo_offset_p, &bp->reg->servo_offset_p); in ptp_ocp_init_clock()
1593 iowrite32(servo_conf->servo_offset_i, &bp->reg->servo_offset_i); in ptp_ocp_init_clock()
1594 iowrite32(servo_conf->servo_drift_p, &bp->reg->servo_drift_p); in ptp_ocp_init_clock()
1595 iowrite32(servo_conf->servo_drift_p, &bp->reg->servo_drift_i); in ptp_ocp_init_clock()
1599 iowrite32(ctrl, &bp->reg->ctrl); in ptp_ocp_init_clock()
1601 if ((ioread32(&bp->reg->ctrl) & OCP_CTRL_ENABLE) == 0) { in ptp_ocp_init_clock()
1602 dev_err(&bp->pdev->dev, "clock not enabled\n"); in ptp_ocp_init_clock()
1603 return -ENODEV; in ptp_ocp_init_clock()
1608 bp->sync = ioread32(&bp->reg->status) & OCP_STATUS_IN_SYNC; in ptp_ocp_init_clock()
1609 if (!bp->sync) { in ptp_ocp_init_clock()
1611 ptp_ocp_settime(&bp->ptp_info, &ts); in ptp_ocp_init_clock()
1615 if (bp->pps_to_clk) { in ptp_ocp_init_clock()
1616 timer_setup(&bp->watchdog, ptp_ocp_watchdog, 0); in ptp_ocp_init_clock()
1617 mod_timer(&bp->watchdog, jiffies + HZ); in ptp_ocp_init_clock()
1628 ctrl = ioread32(&bp->tod->ctrl); in ptp_ocp_tod_init()
1631 iowrite32(ctrl, &bp->tod->ctrl); in ptp_ocp_tod_init()
1633 reg = ioread32(&bp->tod->utc_status); in ptp_ocp_tod_init()
1656 idx = ARRAY_SIZE(gnss_name) - 1; in ptp_ocp_tod_gnss_name()
1679 dev = dev->parent; in ptp_ocp_nvmem_match()
1680 if (!i2c_verify_client(dev) || info->tag != dev->platform_data) in ptp_ocp_nvmem_match()
1683 while ((dev = dev->parent)) in ptp_ocp_nvmem_match()
1684 if (dev->driver && !strcmp(dev->driver->name, KBUILD_MODNAME)) in ptp_ocp_nvmem_match()
1685 return info->bp == dev_get_drvdata(dev); in ptp_ocp_nvmem_match()
1713 if (!bp->i2c_ctrl) in ptp_ocp_read_eeprom()
1719 for (map = bp->eeprom_map; map->len; map++) { in ptp_ocp_read_eeprom()
1720 if (map->tag != tag) { in ptp_ocp_read_eeprom()
1721 tag = map->tag; in ptp_ocp_read_eeprom()
1731 ret = nvmem_device_read(nvmem, map->off, map->len, in ptp_ocp_read_eeprom()
1733 if (ret != map->len) in ptp_ocp_read_eeprom()
1737 bp->has_eeprom_data = true; in ptp_ocp_read_eeprom()
1744 dev_err(&bp->pdev->dev, "could not read eeprom: %d\n", ret); in ptp_ocp_read_eeprom()
1754 dev = &bp->spi_flash->dev; in ptp_ocp_find_flash()
1776 hdr = (const struct ptp_ocp_firmware_header *)fw->data; in ptp_ocp_devlink_fw_image()
1777 if (memcmp(hdr->magic, OCP_FIRMWARE_MAGIC_HEADER, 4)) { in ptp_ocp_devlink_fw_image()
1781 return -EINVAL; in ptp_ocp_devlink_fw_image()
1784 if (be16_to_cpu(hdr->pci_vendor_id) != bp->pdev->vendor || in ptp_ocp_devlink_fw_image()
1785 be16_to_cpu(hdr->pci_device_id) != bp->pdev->device) { in ptp_ocp_devlink_fw_image()
1789 return -EINVAL; in ptp_ocp_devlink_fw_image()
1793 length = be32_to_cpu(hdr->image_size); in ptp_ocp_devlink_fw_image()
1794 if (length != (fw->size - offset)) { in ptp_ocp_devlink_fw_image()
1798 return -EINVAL; in ptp_ocp_devlink_fw_image()
1801 crc = crc16(0xffff, &fw->data[offset], length); in ptp_ocp_devlink_fw_image()
1802 if (be16_to_cpu(hdr->crc) != crc) { in ptp_ocp_devlink_fw_image()
1806 return -EINVAL; in ptp_ocp_devlink_fw_image()
1809 *data = &fw->data[offset]; in ptp_ocp_devlink_fw_image()
1832 base = bp->flash_start; in ptp_ocp_devlink_flash()
1853 resid -= len; in ptp_ocp_devlink_flash()
1871 dev_err(&bp->pdev->dev, "Can't find Flash SPI adapter\n"); in ptp_ocp_devlink_flash_update()
1872 return -ENODEV; in ptp_ocp_devlink_flash_update()
1878 err = ptp_ocp_devlink_flash(devlink, dev, params->fw); in ptp_ocp_devlink_flash_update()
1896 fw_image = bp->fw_loader ? "loader" : "fw"; in ptp_ocp_devlink_info_get()
1897 sprintf(buf, "%d.%d", bp->fw_tag, bp->fw_version); in ptp_ocp_devlink_info_get()
1902 if (!bp->has_eeprom_data) { in ptp_ocp_devlink_info_get()
1904 if (!bp->has_eeprom_data) in ptp_ocp_devlink_info_get()
1908 sprintf(buf, "%pM", bp->serial); in ptp_ocp_devlink_info_get()
1915 bp->board_id); in ptp_ocp_devlink_info_get()
1932 return devm_ioremap_resource(&bp->pdev->dev, &res); in __ptp_ocp_get_mem()
1940 start = pci_resource_start(bp->pdev, 0) + r->offset; in ptp_ocp_get_mem()
1941 return __ptp_ocp_get_mem(bp, start, r->size); in ptp_ocp_get_mem()
1948 struct pci_dev *pdev = bp->pdev; in ptp_ocp_register_spi()
1954 start = pci_resource_start(pdev, 0) + r->offset; in ptp_ocp_register_spi()
1955 res[0] = DEFINE_RES_MEM(start, r->size); in ptp_ocp_register_spi()
1956 res[1] = DEFINE_RES_IRQ(pci_irq_vector(pdev, r->irq_vec)); in ptp_ocp_register_spi()
1958 info = r->extra; in ptp_ocp_register_spi()
1960 id += info->pci_offset; in ptp_ocp_register_spi()
1962 p = platform_device_register_resndata(&pdev->dev, info->name, id, in ptp_ocp_register_spi()
1963 res, ARRAY_SIZE(res), info->data, in ptp_ocp_register_spi()
1964 info->data_size); in ptp_ocp_register_spi()
1980 info = r->extra; in ptp_ocp_i2c_bus()
1981 start = pci_resource_start(pdev, 0) + r->offset; in ptp_ocp_i2c_bus()
1982 res[0] = DEFINE_RES_MEM(start, r->size); in ptp_ocp_i2c_bus()
1983 res[1] = DEFINE_RES_IRQ(pci_irq_vector(pdev, r->irq_vec)); in ptp_ocp_i2c_bus()
1985 return platform_device_register_resndata(&pdev->dev, info->name, in ptp_ocp_i2c_bus()
1987 info->data, info->data_size); in ptp_ocp_i2c_bus()
1993 struct pci_dev *pdev = bp->pdev; in ptp_ocp_register_i2c()
2000 info = r->extra; in ptp_ocp_register_i2c()
2001 id = pci_dev_id(bp->pdev); in ptp_ocp_register_i2c()
2004 clk = clk_hw_register_fixed_rate(&pdev->dev, buf, NULL, 0, in ptp_ocp_register_i2c()
2005 info->fixed_rate); in ptp_ocp_register_i2c()
2008 bp->i2c_clk = clk; in ptp_ocp_register_i2c()
2010 sprintf(buf, "%s.%d", info->name, id); in ptp_ocp_register_i2c()
2011 devm_clk_hw_register_clkdev(&pdev->dev, clk, NULL, buf); in ptp_ocp_register_i2c()
2012 p = ptp_ocp_i2c_bus(bp->pdev, r, id); in ptp_ocp_register_i2c()
2026 struct signal_reg __iomem *reg = ext->mem; in ptp_ocp_signal_irq()
2027 struct ptp_ocp *bp = ext->bp; in ptp_ocp_signal_irq()
2031 gen = ext->info->index - 1; in ptp_ocp_signal_irq()
2033 enable = ioread32(®->enable); in ptp_ocp_signal_irq()
2034 status = ioread32(®->status); in ptp_ocp_signal_irq()
2038 iowrite32(0, ®->intr_mask); in ptp_ocp_signal_irq()
2039 iowrite32(0, ®->enable); in ptp_ocp_signal_irq()
2040 bp->signal[gen].running = false; in ptp_ocp_signal_irq()
2043 iowrite32(0, ®->intr); /* ack interrupt */ in ptp_ocp_signal_irq()
2056 if (!s->period) in ptp_ocp_signal_set()
2059 if (!s->pulse) in ptp_ocp_signal_set()
2060 s->pulse = ktime_divns(s->period * s->duty, 100); in ptp_ocp_signal_set()
2062 err = ptp_ocp_gettimex(&bp->ptp_info, &ts, &sts); in ptp_ocp_signal_set()
2067 if (!s->start) { in ptp_ocp_signal_set()
2068 /* roundup() does not work on 32-bit systems */ in ptp_ocp_signal_set()
2069 s->start = DIV64_U64_ROUND_UP(start_ns, s->period); in ptp_ocp_signal_set()
2070 s->start = ktime_add(s->start, s->phase); in ptp_ocp_signal_set()
2073 if (s->duty < 1 || s->duty > 99) in ptp_ocp_signal_set()
2074 return -EINVAL; in ptp_ocp_signal_set()
2076 if (s->pulse < 1 || s->pulse > s->period) in ptp_ocp_signal_set()
2077 return -EINVAL; in ptp_ocp_signal_set()
2079 if (s->start < start_ns) in ptp_ocp_signal_set()
2080 return -EINVAL; in ptp_ocp_signal_set()
2082 bp->signal[gen] = *s; in ptp_ocp_signal_set()
2093 s.polarity = bp->signal[gen].polarity; in ptp_ocp_signal_from_perout()
2094 s.period = ktime_set(req->period.sec, req->period.nsec); in ptp_ocp_signal_from_perout()
2098 if (req->flags & PTP_PEROUT_DUTY_CYCLE) { in ptp_ocp_signal_from_perout()
2099 s.pulse = ktime_set(req->on.sec, req->on.nsec); in ptp_ocp_signal_from_perout()
2103 if (req->flags & PTP_PEROUT_PHASE) in ptp_ocp_signal_from_perout()
2104 s.phase = ktime_set(req->phase.sec, req->phase.nsec); in ptp_ocp_signal_from_perout()
2106 s.start = ktime_set(req->start.sec, req->start.nsec); in ptp_ocp_signal_from_perout()
2115 struct signal_reg __iomem *reg = ext->mem; in ptp_ocp_signal_enable()
2116 struct ptp_ocp *bp = ext->bp; in ptp_ocp_signal_enable()
2120 gen = ext->info->index - 1; in ptp_ocp_signal_enable()
2122 iowrite32(0, ®->intr_mask); in ptp_ocp_signal_enable()
2123 iowrite32(0, ®->enable); in ptp_ocp_signal_enable()
2124 bp->signal[gen].running = false; in ptp_ocp_signal_enable()
2128 ts = ktime_to_timespec64(bp->signal[gen].start); in ptp_ocp_signal_enable()
2129 iowrite32(ts.tv_sec, ®->start_sec); in ptp_ocp_signal_enable()
2130 iowrite32(ts.tv_nsec, ®->start_ns); in ptp_ocp_signal_enable()
2132 ts = ktime_to_timespec64(bp->signal[gen].period); in ptp_ocp_signal_enable()
2133 iowrite32(ts.tv_sec, ®->period_sec); in ptp_ocp_signal_enable()
2134 iowrite32(ts.tv_nsec, ®->period_ns); in ptp_ocp_signal_enable()
2136 ts = ktime_to_timespec64(bp->signal[gen].pulse); in ptp_ocp_signal_enable()
2137 iowrite32(ts.tv_sec, ®->pulse_sec); in ptp_ocp_signal_enable()
2138 iowrite32(ts.tv_nsec, ®->pulse_ns); in ptp_ocp_signal_enable()
2140 iowrite32(bp->signal[gen].polarity, ®->polarity); in ptp_ocp_signal_enable()
2141 iowrite32(0, ®->repeat_count); in ptp_ocp_signal_enable()
2143 iowrite32(0, ®->intr); /* clear interrupt state */ in ptp_ocp_signal_enable()
2144 iowrite32(1, ®->intr_mask); /* enable interrupt */ in ptp_ocp_signal_enable()
2145 iowrite32(3, ®->enable); /* valid & enable */ in ptp_ocp_signal_enable()
2147 bp->signal[gen].running = true; in ptp_ocp_signal_enable()
2156 struct ts_reg __iomem *reg = ext->mem; in ptp_ocp_ts_irq()
2160 if (ext == ext->bp->pps) { in ptp_ocp_ts_irq()
2161 if (ext->bp->pps_req_map & OCP_REQ_PPS) { in ptp_ocp_ts_irq()
2163 ptp_clock_event(ext->bp->ptp, &ev); in ptp_ocp_ts_irq()
2166 if ((ext->bp->pps_req_map & ~OCP_REQ_PPS) == 0) in ptp_ocp_ts_irq()
2170 /* XXX should fix API - this converts s/ns -> ts -> s/ns */ in ptp_ocp_ts_irq()
2171 sec = ioread32(®->time_sec); in ptp_ocp_ts_irq()
2172 nsec = ioread32(®->time_ns); in ptp_ocp_ts_irq()
2175 ev.index = ext->info->index; in ptp_ocp_ts_irq()
2178 ptp_clock_event(ext->bp->ptp, &ev); in ptp_ocp_ts_irq()
2181 iowrite32(1, ®->intr); /* write 1 to ack */ in ptp_ocp_ts_irq()
2190 struct ts_reg __iomem *reg = ext->mem; in ptp_ocp_ts_enable()
2191 struct ptp_ocp *bp = ext->bp; in ptp_ocp_ts_enable()
2193 if (ext == bp->pps) { in ptp_ocp_ts_enable()
2194 u32 old_map = bp->pps_req_map; in ptp_ocp_ts_enable()
2197 bp->pps_req_map |= req; in ptp_ocp_ts_enable()
2199 bp->pps_req_map &= ~req; in ptp_ocp_ts_enable()
2202 if ((!!old_map ^ !!bp->pps_req_map) == 0) in ptp_ocp_ts_enable()
2207 iowrite32(1, ®->enable); in ptp_ocp_ts_enable()
2208 iowrite32(1, ®->intr_mask); in ptp_ocp_ts_enable()
2209 iowrite32(1, ®->intr); in ptp_ocp_ts_enable()
2211 iowrite32(0, ®->intr_mask); in ptp_ocp_ts_enable()
2212 iowrite32(0, ®->enable); in ptp_ocp_ts_enable()
2221 ext->info->enable(ext, ~0, false); in ptp_ocp_unregister_ext()
2222 pci_free_irq(ext->bp->pdev, ext->irq_vec, ext); in ptp_ocp_unregister_ext()
2229 struct pci_dev *pdev = bp->pdev; in ptp_ocp_register_ext()
2235 return -ENOMEM; in ptp_ocp_register_ext()
2237 ext->mem = ptp_ocp_get_mem(bp, r); in ptp_ocp_register_ext()
2238 if (IS_ERR(ext->mem)) { in ptp_ocp_register_ext()
2239 err = PTR_ERR(ext->mem); in ptp_ocp_register_ext()
2243 ext->bp = bp; in ptp_ocp_register_ext()
2244 ext->info = r->extra; in ptp_ocp_register_ext()
2245 ext->irq_vec = r->irq_vec; in ptp_ocp_register_ext()
2247 err = pci_request_irq(pdev, r->irq_vec, ext->info->irq_fcn, NULL, in ptp_ocp_register_ext()
2248 ext, "ocp%d.%s", bp->id, r->name); in ptp_ocp_register_ext()
2250 dev_err(&pdev->dev, "Could not get irq %d\n", r->irq_vec); in ptp_ocp_register_ext()
2266 struct pci_dev *pdev = bp->pdev; in ptp_ocp_serial_line()
2273 uart.port.dev = &pdev->dev; in ptp_ocp_serial_line()
2276 uart.port.mapbase = pci_resource_start(pdev, 0) + r->offset; in ptp_ocp_serial_line()
2277 uart.port.irq = pci_irq_vector(pdev, r->irq_vec); in ptp_ocp_serial_line()
2288 struct ptp_ocp_serial_port *p = (struct ptp_ocp_serial_port *)r->extra; in ptp_ocp_register_serial()
2296 port.baud = p->baud; in ptp_ocp_register_serial()
2320 if (!bp->nmea_out) in ptp_ocp_nmea_out_init()
2323 iowrite32(0, &bp->nmea_out->ctrl); /* disable */ in ptp_ocp_nmea_out_init()
2324 iowrite32(7, &bp->nmea_out->uart_baud); /* 115200 */ in ptp_ocp_nmea_out_init()
2325 iowrite32(1, &bp->nmea_out->ctrl); /* enable */ in ptp_ocp_nmea_out_init()
2333 iowrite32(0, ®->enable); /* disable */ in _ptp_ocp_signal_init()
2335 val = ioread32(®->polarity); in _ptp_ocp_signal_init()
2336 s->polarity = val ? true : false; in _ptp_ocp_signal_init()
2337 s->duty = 50; in _ptp_ocp_signal_init()
2346 if (bp->signal_out[i]) in ptp_ocp_signal_init()
2347 _ptp_ocp_signal_init(&bp->signal[i], in ptp_ocp_signal_init()
2348 bp->signal_out[i]->mem); in ptp_ocp_signal_init()
2354 sysfs_remove_groups(&bp->dev.kobj, bp->attr_group); in ptp_ocp_attr_group_del()
2355 kfree(bp->attr_group); in ptp_ocp_attr_group_del()
2367 if (attr_tbl[i].cap & bp->fw_cap) in ptp_ocp_attr_group_add()
2370 bp->attr_group = kcalloc(count + 1, sizeof(struct attribute_group *), in ptp_ocp_attr_group_add()
2372 if (!bp->attr_group) in ptp_ocp_attr_group_add()
2373 return -ENOMEM; in ptp_ocp_attr_group_add()
2377 if (attr_tbl[i].cap & bp->fw_cap) in ptp_ocp_attr_group_add()
2378 bp->attr_group[count++] = attr_tbl[i].group; in ptp_ocp_attr_group_add()
2380 err = sysfs_create_groups(&bp->dev.kobj, bp->attr_group); in ptp_ocp_attr_group_add()
2382 bp->attr_group[0] = NULL; in ptp_ocp_attr_group_add()
2405 return ptp_ocp_enable_fpga(&bp->irig_out->ctrl, in ptp_ocp_irig_out()
2412 return ptp_ocp_enable_fpga(&bp->irig_in->ctrl, in ptp_ocp_irig_in()
2419 return ptp_ocp_enable_fpga(&bp->dcf_out->ctrl, in ptp_ocp_dcf_out()
2426 return ptp_ocp_enable_fpga(&bp->dcf_in->ctrl, in ptp_ocp_dcf_in()
2450 if (bp->sma[sma_nr - 1].fixed_fcn) in ptp_ocp_sma_fb_get()
2451 return (sma_nr - 1) & 1; in ptp_ocp_sma_fb_get()
2453 if (bp->sma[sma_nr - 1].mode == SMA_MODE_IN) in ptp_ocp_sma_fb_get()
2454 gpio = sma_nr > 2 ? &bp->sma_map2->gpio1 : &bp->sma_map1->gpio1; in ptp_ocp_sma_fb_get()
2456 gpio = sma_nr > 2 ? &bp->sma_map1->gpio2 : &bp->sma_map2->gpio2; in ptp_ocp_sma_fb_get()
2469 gpio = sma_nr > 2 ? &bp->sma_map1->gpio2 : &bp->sma_map2->gpio2; in ptp_ocp_sma_fb_set_output()
2472 mask = 0xffff << (16 - shift); in ptp_ocp_sma_fb_set_output()
2474 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_sma_fb_set_output()
2483 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_sma_fb_set_output()
2495 gpio = sma_nr > 2 ? &bp->sma_map2->gpio1 : &bp->sma_map1->gpio1; in ptp_ocp_sma_fb_set_inputs()
2498 mask = 0xffff << (16 - shift); in ptp_ocp_sma_fb_set_inputs()
2500 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_sma_fb_set_inputs()
2509 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_sma_fb_set_inputs()
2530 bp->sma[i].default_fcn = i & 1; in ptp_ocp_sma_fb_init()
2531 bp->sma[i].dpll_prop = prop; in ptp_ocp_sma_fb_init()
2532 bp->sma[i].dpll_prop.board_label = in ptp_ocp_sma_fb_init()
2533 bp->ptp_info.pin_config[i].name; in ptp_ocp_sma_fb_init()
2535 bp->sma[0].mode = SMA_MODE_IN; in ptp_ocp_sma_fb_init()
2536 bp->sma[1].mode = SMA_MODE_IN; in ptp_ocp_sma_fb_init()
2537 bp->sma[2].mode = SMA_MODE_OUT; in ptp_ocp_sma_fb_init()
2538 bp->sma[3].mode = SMA_MODE_OUT; in ptp_ocp_sma_fb_init()
2540 if (!bp->sma_map1) { in ptp_ocp_sma_fb_init()
2542 bp->sma[i].fixed_fcn = true; in ptp_ocp_sma_fb_init()
2543 bp->sma[i].fixed_dir = true; in ptp_ocp_sma_fb_init()
2544 bp->sma[1].dpll_prop.capabilities &= in ptp_ocp_sma_fb_init()
2553 reg = ioread32(&bp->sma_map2->gpio2); in ptp_ocp_sma_fb_init()
2556 bp->sma[i].fixed_dir = true; in ptp_ocp_sma_fb_init()
2558 reg = ioread32(&bp->sma_map1->gpio1); in ptp_ocp_sma_fb_init()
2559 bp->sma[0].mode = reg & BIT(15) ? SMA_MODE_IN : SMA_MODE_OUT; in ptp_ocp_sma_fb_init()
2560 bp->sma[1].mode = reg & BIT(31) ? SMA_MODE_IN : SMA_MODE_OUT; in ptp_ocp_sma_fb_init()
2562 reg = ioread32(&bp->sma_map1->gpio2); in ptp_ocp_sma_fb_init()
2563 bp->sma[2].mode = reg & BIT(15) ? SMA_MODE_OUT : SMA_MODE_IN; in ptp_ocp_sma_fb_init()
2564 bp->sma[3].mode = reg & BIT(31) ? SMA_MODE_OUT : SMA_MODE_IN; in ptp_ocp_sma_fb_init()
2592 return -ENOMEM; in ptp_ocp_set_pins()
2599 bp->ptp_info.n_pins = 4; in ptp_ocp_set_pins()
2600 bp->ptp_info.pin_config = config; in ptp_ocp_set_pins()
2611 version = ioread32(&bp->image->version); in ptp_ocp_fb_set_version()
2616 bp->fw_loader = true; in ptp_ocp_fb_set_version()
2619 bp->fw_tag = version >> 15; in ptp_ocp_fb_set_version()
2620 bp->fw_version = version & 0x7fff; in ptp_ocp_fb_set_version()
2622 if (bp->fw_tag) { in ptp_ocp_fb_set_version()
2634 bp->fw_cap = cap; in ptp_ocp_fb_set_version()
2643 bp->flash_start = 1024 * 4096; in ptp_ocp_fb_board_init()
2644 bp->eeprom_map = fb_eeprom_map; in ptp_ocp_fb_board_init()
2645 bp->fw_version = ioread32(&bp->image->version); in ptp_ocp_fb_board_init()
2646 bp->sma_op = &ocp_fb_sma_op; in ptp_ocp_fb_board_init()
2663 return ptp_ocp_init_clock(bp, r->extra); in ptp_ocp_fb_board_init()
2669 bool allow = !r->irq_vec || r->irq_vec < bp->n_irqs; in ptp_ocp_allow_irq()
2672 dev_err(&bp->pdev->dev, "irq %d out of range, skipping %s\n", in ptp_ocp_allow_irq()
2673 r->irq_vec, r->name); in ptp_ocp_allow_irq()
2684 for (r = table; r->setup; r++) { in ptp_ocp_register_resources()
2687 err = r->setup(bp, r); in ptp_ocp_register_resources()
2689 dev_err(&bp->pdev->dev, in ptp_ocp_register_resources()
2691 r->name, err); in ptp_ocp_register_resources()
2713 bp->sma[0].mode = SMA_MODE_IN; in ptp_ocp_art_sma_init()
2714 bp->sma[1].mode = SMA_MODE_IN; in ptp_ocp_art_sma_init()
2715 bp->sma[2].mode = SMA_MODE_OUT; in ptp_ocp_art_sma_init()
2716 bp->sma[3].mode = SMA_MODE_OUT; in ptp_ocp_art_sma_init()
2718 bp->sma[0].default_fcn = 0x08; /* IN: 10Mhz */ in ptp_ocp_art_sma_init()
2719 bp->sma[1].default_fcn = 0x01; /* IN: PPS1 */ in ptp_ocp_art_sma_init()
2720 bp->sma[2].default_fcn = 0x10; /* OUT: 10Mhz */ in ptp_ocp_art_sma_init()
2721 bp->sma[3].default_fcn = 0x02; /* OUT: PHC */ in ptp_ocp_art_sma_init()
2725 bp->sma[i].dpll_prop = prop; in ptp_ocp_art_sma_init()
2726 bp->sma[i].dpll_prop.board_label = in ptp_ocp_art_sma_init()
2727 bp->ptp_info.pin_config[i].name; in ptp_ocp_art_sma_init()
2728 if (!bp->art_sma) { in ptp_ocp_art_sma_init()
2729 bp->sma[i].fixed_fcn = true; in ptp_ocp_art_sma_init()
2730 bp->sma[i].fixed_dir = true; in ptp_ocp_art_sma_init()
2733 reg = ioread32(&bp->art_sma->map[i].gpio); in ptp_ocp_art_sma_init()
2737 bp->sma[i].fixed_fcn = true; in ptp_ocp_art_sma_init()
2738 bp->sma[i].fixed_dir = true; in ptp_ocp_art_sma_init()
2742 bp->sma[i].mode = SMA_MODE_IN; in ptp_ocp_art_sma_init()
2743 bp->sma[i].dpll_prop.capabilities = in ptp_ocp_art_sma_init()
2747 bp->sma[i].mode = SMA_MODE_OUT; in ptp_ocp_art_sma_init()
2748 bp->sma[i].dpll_prop.capabilities = in ptp_ocp_art_sma_init()
2758 if (bp->sma[sma_nr - 1].fixed_fcn) in ptp_ocp_art_sma_get()
2759 return bp->sma[sma_nr - 1].default_fcn; in ptp_ocp_art_sma_get()
2761 return ioread32(&bp->art_sma->map[sma_nr - 1].gpio) & 0xff; in ptp_ocp_art_sma_get()
2775 return -EINVAL; in ptp_ocp_art_sma_set()
2777 gpio = &bp->art_sma->map[sma_nr - 1].gpio; in ptp_ocp_art_sma_set()
2779 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_art_sma_set()
2782 err = -EOPNOTSUPP; in ptp_ocp_art_sma_set()
2787 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_art_sma_set()
2806 bp->flash_start = 0x1000000; in ptp_ocp_art_board_init()
2807 bp->eeprom_map = art_eeprom_map; in ptp_ocp_art_board_init()
2808 bp->fw_cap = OCP_CAP_BASIC; in ptp_ocp_art_board_init()
2809 bp->fw_version = ioread32(&bp->reg->version); in ptp_ocp_art_board_init()
2810 bp->fw_tag = 2; in ptp_ocp_art_board_init()
2811 bp->sma_op = &ocp_art_sma_op; in ptp_ocp_art_board_init()
2814 iowrite32(1, &bp->board_config->mro50_serial_activate); in ptp_ocp_art_board_init()
2825 return ptp_ocp_init_clock(bp, r->extra); in ptp_ocp_art_board_init()
2835 bp->flash_start = 0xA00000; in ptp_ocp_adva_board_init()
2836 bp->eeprom_map = fb_eeprom_map; in ptp_ocp_adva_board_init()
2837 bp->sma_op = &ocp_adva_sma_op; in ptp_ocp_adva_board_init()
2839 version = ioread32(&bp->image->version); in ptp_ocp_adva_board_init()
2843 bp->fw_loader = true; in ptp_ocp_adva_board_init()
2845 bp->fw_tag = 3; in ptp_ocp_adva_board_init()
2846 bp->fw_version = version & 0xffff; in ptp_ocp_adva_board_init()
2847 bp->fw_cap = OCP_CAP_BASIC | OCP_CAP_SIGNAL | OCP_CAP_FREQ; in ptp_ocp_adva_board_init()
2862 return ptp_ocp_init_clock(bp, r->extra); in ptp_ocp_adva_board_init()
2900 count--; in ptp_ocp_show_inputs()
2915 return -ENOMEM; in sma_parse_inputs()
2917 ret = -EINVAL; in sma_parse_inputs()
2937 ret = -EINVAL; in sma_parse_inputs()
2948 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; in ptp_ocp_sma_show()
2952 tbl = bp->sma_op->tbl; in ptp_ocp_sma_show()
2955 if (sma->mode == SMA_MODE_IN) { in ptp_ocp_sma_show()
2956 if (sma->disabled) in ptp_ocp_sma_show()
2977 return ptp_ocp_sma_show(bp, 2, buf, -1, 1); in sma2_show()
2985 return ptp_ocp_sma_show(bp, 3, buf, -1, 0); in sma3_show()
2993 return ptp_ocp_sma_show(bp, 4, buf, -1, 1); in sma4_show()
2999 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; in ptp_ocp_sma_store_val()
3001 if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) in ptp_ocp_sma_store_val()
3002 return -EOPNOTSUPP; in ptp_ocp_sma_store_val()
3004 if (sma->fixed_fcn) { in ptp_ocp_sma_store_val()
3005 if (val != sma->default_fcn) in ptp_ocp_sma_store_val()
3006 return -EOPNOTSUPP; in ptp_ocp_sma_store_val()
3010 sma->disabled = !!(val & SMA_DISABLE); in ptp_ocp_sma_store_val()
3012 if (mode != sma->mode) { in ptp_ocp_sma_store_val()
3017 sma->mode = mode; in ptp_ocp_sma_store_val()
3020 if (!sma->fixed_dir) in ptp_ocp_sma_store_val()
3023 if (sma->disabled) in ptp_ocp_sma_store_val()
3037 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; in ptp_ocp_sma_store()
3041 mode = sma->mode; in ptp_ocp_sma_store()
3042 val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode); in ptp_ocp_sma_store()
3102 return ptp_ocp_select_table_show(bp->sma_op->tbl[0], buf); in available_sma_inputs_show()
3112 return ptp_ocp_select_table_show(bp->sma_op->tbl[1], buf); in available_sma_outputs_show()
3132 int gen = (uintptr_t)ea->var; in signal_store()
3138 return -ENOMEM; in signal_store()
3140 err = -EINVAL; in signal_store()
3141 s.duty = bp->signal[gen].duty; in signal_store()
3142 s.phase = bp->signal[gen].phase; in signal_store()
3143 s.period = bp->signal[gen].period; in signal_store()
3144 s.polarity = bp->signal[gen].polarity; in signal_store()
3148 argc--; in signal_store()
3154 argc--; in signal_store()
3160 argc--; in signal_store()
3166 argc--; in signal_store()
3179 err = ptp_ocp_signal_enable(bp->signal_out[gen], gen, s.period != 0); in signal_store()
3196 i = (uintptr_t)ea->var; in signal_show()
3197 signal = &bp->signal[i]; in signal_show()
3199 count = sysfs_emit(buf, "%llu %d %llu %d", signal->period, in signal_show()
3200 signal->duty, signal->phase, signal->polarity); in signal_show()
3202 ts = ktime_to_timespec64(signal->start); in signal_show()
3217 int i = (uintptr_t)ea->var; in duty_show()
3219 return sysfs_emit(buf, "%d\n", bp->signal[i].duty); in duty_show()
3231 int i = (uintptr_t)ea->var; in period_show()
3233 return sysfs_emit(buf, "%llu\n", bp->signal[i].period); in period_show()
3245 int i = (uintptr_t)ea->var; in phase_show()
3247 return sysfs_emit(buf, "%llu\n", bp->signal[i].phase); in phase_show()
3260 int i = (uintptr_t)ea->var; in polarity_show()
3262 return sysfs_emit(buf, "%d\n", bp->signal[i].polarity); in polarity_show()
3274 int i = (uintptr_t)ea->var; in running_show()
3276 return sysfs_emit(buf, "%d\n", bp->signal[i].running); in running_show()
3288 int i = (uintptr_t)ea->var; in start_show()
3291 ts = ktime_to_timespec64(bp->signal[i].start); in start_show()
3305 int idx = (uintptr_t)ea->var; in seconds_store()
3313 return -EINVAL; in seconds_store()
3318 iowrite32(val, &bp->freq_in[idx]->ctrl); in seconds_store()
3328 int idx = (uintptr_t)ea->var; in seconds_show()
3331 val = ioread32(&bp->freq_in[idx]->ctrl); in seconds_show()
3349 int idx = (uintptr_t)ea->var; in frequency_show()
3352 val = ioread32(&bp->freq_in[idx]->status); in frequency_show()
3372 return sysfs_emit(buf, "ttyS%d", bp->port[(uintptr_t)ea->var].line); in ptp_ocp_tty_show()
3383 if (strncmp(attr->name, "tty", 3)) in ptp_ocp_timecard_tty_is_visible()
3384 return attr->mode; in ptp_ocp_timecard_tty_is_visible()
3388 port = &bp->port[(uintptr_t)ea->var]; in ptp_ocp_timecard_tty_is_visible()
3389 return port->line == -1 ? 0 : 0444; in ptp_ocp_timecard_tty_is_visible()
3419 if (!bp->has_eeprom_data) in serialnum_show()
3422 return sysfs_emit(buf, "%pM\n", bp->serial); in serialnum_show()
3432 if (bp->gnss_lost) in gnss_sync_show()
3433 ret = sysfs_emit(buf, "LOST @ %ptT\n", &bp->gnss_lost); in gnss_sync_show()
3447 return sysfs_emit(buf, "%d\n", bp->utc_tai_offset); in utc_tai_offset_show()
3475 return sysfs_emit(buf, "%d\n", bp->ts_window_adjust); in ts_window_adjust_show()
3491 bp->ts_window_adjust = val; in ts_window_adjust_store()
3503 val = ioread32(&bp->irig_out->ctrl); in irig_b_mode_show()
3523 return -EINVAL; in irig_b_mode_store()
3527 spin_lock_irqsave(&bp->lock, flags); in irig_b_mode_store()
3528 iowrite32(0, &bp->irig_out->ctrl); /* disable */ in irig_b_mode_store()
3529 iowrite32(reg, &bp->irig_out->ctrl); /* change mode */ in irig_b_mode_store()
3530 iowrite32(reg | IRIG_M_CTRL_ENABLE, &bp->irig_out->ctrl); in irig_b_mode_store()
3531 spin_unlock_irqrestore(&bp->lock, flags); in irig_b_mode_store()
3544 select = ioread32(&bp->reg->select); in clock_source_show()
3562 spin_lock_irqsave(&bp->lock, flags); in clock_source_store()
3563 iowrite32(val, &bp->reg->select); in clock_source_store()
3564 spin_unlock_irqrestore(&bp->lock, flags); in clock_source_store()
3586 val = ioread32(&bp->reg->status_drift); in clock_status_drift_show()
3587 res = (val & ~INT_MAX) ? -1 : 1; in clock_status_drift_show()
3601 val = ioread32(&bp->reg->status_offset); in clock_status_offset_show()
3602 res = (val & ~INT_MAX) ? -1 : 1; in clock_status_offset_show()
3616 val = ioread32(&bp->tod->adj_sec); in tod_correction_show()
3617 res = (val & ~INT_MAX) ? -1 : 1; in tod_correction_show()
3635 res *= -1; in tod_correction_store()
3640 spin_lock_irqsave(&bp->lock, flags); in tod_correction_store()
3641 iowrite32(val, &bp->tod->adj_sec); in tod_correction_store()
3642 spin_unlock_irqrestore(&bp->lock, flags); in tod_correction_store()
3713 count = size - off; in disciplining_config_read()
3718 err = -EFAULT; in disciplining_config_read()
3739 return -EFAULT; in disciplining_config_write()
3747 err = -EFAULT; in disciplining_config_write()
3775 count = size - off; in temperature_table_read()
3780 err = -EFAULT; in temperature_table_read()
3801 return -EFAULT; in temperature_table_write()
3809 err = -EFAULT; in temperature_table_write()
3926 if (bp->sma[i].mode != SMA_MODE_IN) in gpio_input_map()
3934 def = "----"; in gpio_input_map()
3944 strcpy(ans, "----"); in gpio_output_map()
3946 if (bp->sma[i].mode != SMA_MODE_OUT) in gpio_output_map()
3956 struct signal_reg __iomem *reg = bp->signal_out[nr]->mem; in _signal_summary_show()
3957 struct ptp_ocp_signal *signal = &bp->signal[nr]; in _signal_summary_show()
3965 on = signal->running; in _signal_summary_show()
3969 signal->period, signal->duty, signal->phase, in _signal_summary_show()
3970 signal->polarity); in _signal_summary_show()
3972 val = ioread32(®->enable); in _signal_summary_show()
3974 val = ioread32(®->status); in _signal_summary_show()
3977 seq_printf(s, " start:%llu\n", signal->start); in _signal_summary_show()
3992 val = ioread32(®->ctrl); in _frequency_summary_show()
4000 val = ioread32(®->status); in _frequency_summary_show()
4013 struct device *dev = s->private; in ptp_ocp_summary_show()
4026 return -ENOMEM; in ptp_ocp_summary_show()
4030 seq_printf(s, "%7s: /dev/ptp%d\n", "PTP", ptp_clock_index(bp->ptp)); in ptp_ocp_summary_show()
4032 if (bp->port[i].line != -1) in ptp_ocp_summary_show()
4034 bp->port[i].line); in ptp_ocp_summary_show()
4038 if (bp->sma_map1) { in ptp_ocp_summary_show()
4041 reg = ioread32(&bp->sma_map1->gpio1); in ptp_ocp_summary_show()
4045 reg = ioread32(&bp->sma_map1->gpio2); in ptp_ocp_summary_show()
4049 reg = ioread32(&bp->sma_map2->gpio1); in ptp_ocp_summary_show()
4053 reg = ioread32(&bp->sma_map2->gpio2); in ptp_ocp_summary_show()
4074 if (bp->ts0) { in ptp_ocp_summary_show()
4075 ts_reg = bp->ts0->mem; in ptp_ocp_summary_show()
4076 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
4082 if (bp->ts1) { in ptp_ocp_summary_show()
4083 ts_reg = bp->ts1->mem; in ptp_ocp_summary_show()
4084 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
4090 if (bp->ts2) { in ptp_ocp_summary_show()
4091 ts_reg = bp->ts2->mem; in ptp_ocp_summary_show()
4092 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
4098 if (bp->ts3) { in ptp_ocp_summary_show()
4099 ts_reg = bp->ts3->mem; in ptp_ocp_summary_show()
4100 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
4106 if (bp->ts4) { in ptp_ocp_summary_show()
4107 ts_reg = bp->ts4->mem; in ptp_ocp_summary_show()
4108 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
4114 if (bp->pps) { in ptp_ocp_summary_show()
4115 ts_reg = bp->pps->mem; in ptp_ocp_summary_show()
4117 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
4118 map = !!(bp->pps_req_map & OCP_REQ_TIMESTAMP); in ptp_ocp_summary_show()
4122 map = !!(bp->pps_req_map & OCP_REQ_PPS); in ptp_ocp_summary_show()
4127 if (bp->fw_cap & OCP_CAP_SIGNAL) in ptp_ocp_summary_show()
4131 if (bp->fw_cap & OCP_CAP_FREQ) in ptp_ocp_summary_show()
4133 _frequency_summary_show(s, i, bp->freq_in[i]); in ptp_ocp_summary_show()
4135 if (bp->irig_out) { in ptp_ocp_summary_show()
4136 ctrl = ioread32(&bp->irig_out->ctrl); in ptp_ocp_summary_show()
4138 val = ioread32(&bp->irig_out->status); in ptp_ocp_summary_show()
4144 if (bp->irig_in) { in ptp_ocp_summary_show()
4145 on = ioread32(&bp->irig_in->ctrl) & IRIG_S_CTRL_ENABLE; in ptp_ocp_summary_show()
4146 val = ioread32(&bp->irig_in->status); in ptp_ocp_summary_show()
4152 if (bp->dcf_out) { in ptp_ocp_summary_show()
4153 on = ioread32(&bp->dcf_out->ctrl) & DCF_M_CTRL_ENABLE; in ptp_ocp_summary_show()
4154 val = ioread32(&bp->dcf_out->status); in ptp_ocp_summary_show()
4160 if (bp->dcf_in) { in ptp_ocp_summary_show()
4161 on = ioread32(&bp->dcf_in->ctrl) & DCF_S_CTRL_ENABLE; in ptp_ocp_summary_show()
4162 val = ioread32(&bp->dcf_in->status); in ptp_ocp_summary_show()
4168 if (bp->nmea_out) { in ptp_ocp_summary_show()
4169 on = ioread32(&bp->nmea_out->ctrl) & 1; in ptp_ocp_summary_show()
4170 val = ioread32(&bp->nmea_out->status); in ptp_ocp_summary_show()
4176 if (bp->pps_select) { in ptp_ocp_summary_show()
4177 val = ioread32(&bp->pps_select->gpio1); in ptp_ocp_summary_show()
4188 src = "----"; in ptp_ocp_summary_show()
4201 val = ioread32(&bp->reg->select); in ptp_ocp_summary_show()
4204 sprintf(buf, "----"); in ptp_ocp_summary_show()
4220 bp->sync ? "sync" : "unsynced"); in ptp_ocp_summary_show()
4222 if (!ptp_ocp_gettimex(&bp->ptp_info, &ts, &sts)) { in ptp_ocp_summary_show()
4229 ns += (s64)bp->utc_tai_offset * NSEC_PER_SEC; in ptp_ocp_summary_show()
4236 bp->utc_tai_offset); in ptp_ocp_summary_show()
4238 timespec64_to_ns(&ts) - ns, in ptp_ocp_summary_show()
4239 post_ns - pre_ns); in ptp_ocp_summary_show()
4250 struct device *dev = s->private; in ptp_ocp_tod_status_show()
4257 val = ioread32(&bp->tod->ctrl); in ptp_ocp_tod_status_show()
4271 val = ioread32(&bp->tod->version); in ptp_ocp_tod_status_show()
4275 val = ioread32(&bp->tod->status); in ptp_ocp_tod_status_show()
4278 val = ioread32(&bp->tod->adj_sec); in ptp_ocp_tod_status_show()
4279 idx = (val & ~INT_MAX) ? -1 : 1; in ptp_ocp_tod_status_show()
4283 val = ioread32(&bp->tod->utc_status); in ptp_ocp_tod_status_show()
4291 val = ioread32(&bp->tod->leap); in ptp_ocp_tod_status_show()
4305 d = debugfs_create_dir(dev_name(&bp->dev), ptp_ocp_debugfs_root); in ptp_ocp_debugfs_add_device()
4306 bp->debug_root = d; in ptp_ocp_debugfs_add_device()
4307 debugfs_create_file("summary", 0444, bp->debug_root, in ptp_ocp_debugfs_add_device()
4308 &bp->dev, &ptp_ocp_summary_fops); in ptp_ocp_debugfs_add_device()
4309 if (bp->tod) in ptp_ocp_debugfs_add_device()
4310 debugfs_create_file("tod_status", 0444, bp->debug_root, in ptp_ocp_debugfs_add_device()
4311 &bp->dev, &ptp_ocp_tod_status_fops); in ptp_ocp_debugfs_add_device()
4317 debugfs_remove_recursive(bp->debug_root); in ptp_ocp_debugfs_remove_device()
4338 idr_remove(&ptp_ocp_idr, bp->id); in ptp_ocp_dev_release()
4351 dev_err(&pdev->dev, "idr_alloc failed: %d\n", err); in ptp_ocp_device_init()
4354 bp->id = err; in ptp_ocp_device_init()
4356 bp->ptp_info = ptp_ocp_clock_info; in ptp_ocp_device_init()
4357 spin_lock_init(&bp->lock); in ptp_ocp_device_init()
4360 bp->port[i].line = -1; in ptp_ocp_device_init()
4362 bp->pdev = pdev; in ptp_ocp_device_init()
4364 device_initialize(&bp->dev); in ptp_ocp_device_init()
4365 dev_set_name(&bp->dev, "ocp%d", bp->id); in ptp_ocp_device_init()
4366 bp->dev.class = &timecard_class; in ptp_ocp_device_init()
4367 bp->dev.parent = &pdev->dev; in ptp_ocp_device_init()
4368 bp->dev.release = ptp_ocp_dev_release; in ptp_ocp_device_init()
4369 dev_set_drvdata(&bp->dev, bp); in ptp_ocp_device_init()
4371 err = device_add(&bp->dev); in ptp_ocp_device_init()
4373 dev_err(&bp->dev, "device add failed: %d\n", err); in ptp_ocp_device_init()
4382 put_device(&bp->dev); in ptp_ocp_device_init()
4389 struct device *dev = &bp->dev; in ptp_ocp_symlink()
4391 if (sysfs_create_link(&dev->kobj, &child->kobj, link)) in ptp_ocp_symlink()
4400 dev = &bp->pdev->dev; in ptp_ocp_link_child()
4418 sprintf(buf, "ptp%d", ptp_clock_index(bp->ptp)); in ptp_ocp_complete()
4421 pps = pps_lookup_dev(bp->ptp); in ptp_ocp_complete()
4423 ptp_ocp_symlink(bp, pps->dev, "pps"); in ptp_ocp_complete()
4436 version = ioread32(&bp->reg->version); in ptp_ocp_phc_info()
4437 select = ioread32(&bp->reg->select); in ptp_ocp_phc_info()
4438 dev_info(&bp->pdev->dev, "Version %d.%d.%d, clock %s, device ptp%d\n", in ptp_ocp_phc_info()
4441 ptp_clock_index(bp->ptp)); in ptp_ocp_phc_info()
4443 if (!ptp_ocp_gettimex(&bp->ptp_info, &ts, NULL)) in ptp_ocp_phc_info()
4444 dev_info(&bp->pdev->dev, "Time: %lld.%ld, %s\n", in ptp_ocp_phc_info()
4446 bp->sync ? "in-sync" : "UNSYNCED"); in ptp_ocp_phc_info()
4452 if (port != -1) in ptp_ocp_serial_info()
4453 dev_info(dev, "%5s: /dev/ttyS%-2d @ %6d\n", name, port, baud); in ptp_ocp_serial_info()
4464 struct device *dev = &bp->pdev->dev; in ptp_ocp_info()
4471 if (i == PORT_NMEA && bp->nmea_out && bp->port[PORT_NMEA].line != -1) { in ptp_ocp_info()
4472 bp->port[PORT_NMEA].baud = -1; in ptp_ocp_info()
4474 reg = ioread32(&bp->nmea_out->uart_baud); in ptp_ocp_info()
4476 bp->port[PORT_NMEA].baud = nmea_baud[reg]; in ptp_ocp_info()
4478 ptp_ocp_serial_info(dev, ptp_ocp_tty_port_name(i), bp->port[i].line, in ptp_ocp_info()
4479 bp->port[i].baud); in ptp_ocp_info()
4486 struct device *dev = &bp->dev; in ptp_ocp_detach_sysfs()
4488 sysfs_remove_link(&dev->kobj, "ptp"); in ptp_ocp_detach_sysfs()
4489 sysfs_remove_link(&dev->kobj, "pps"); in ptp_ocp_detach_sysfs()
4500 if (timer_pending(&bp->watchdog)) in ptp_ocp_detach()
4501 del_timer_sync(&bp->watchdog); in ptp_ocp_detach()
4502 if (bp->ts0) in ptp_ocp_detach()
4503 ptp_ocp_unregister_ext(bp->ts0); in ptp_ocp_detach()
4504 if (bp->ts1) in ptp_ocp_detach()
4505 ptp_ocp_unregister_ext(bp->ts1); in ptp_ocp_detach()
4506 if (bp->ts2) in ptp_ocp_detach()
4507 ptp_ocp_unregister_ext(bp->ts2); in ptp_ocp_detach()
4508 if (bp->ts3) in ptp_ocp_detach()
4509 ptp_ocp_unregister_ext(bp->ts3); in ptp_ocp_detach()
4510 if (bp->ts4) in ptp_ocp_detach()
4511 ptp_ocp_unregister_ext(bp->ts4); in ptp_ocp_detach()
4512 if (bp->pps) in ptp_ocp_detach()
4513 ptp_ocp_unregister_ext(bp->pps); in ptp_ocp_detach()
4515 if (bp->signal_out[i]) in ptp_ocp_detach()
4516 ptp_ocp_unregister_ext(bp->signal_out[i]); in ptp_ocp_detach()
4518 if (bp->port[i].line != -1) in ptp_ocp_detach()
4519 serial8250_unregister_port(bp->port[i].line); in ptp_ocp_detach()
4520 platform_device_unregister(bp->spi_flash); in ptp_ocp_detach()
4521 platform_device_unregister(bp->i2c_ctrl); in ptp_ocp_detach()
4522 if (bp->i2c_clk) in ptp_ocp_detach()
4523 clk_hw_unregister_fixed_rate(bp->i2c_clk); in ptp_ocp_detach()
4524 if (bp->n_irqs) in ptp_ocp_detach()
4525 pci_free_irq_vectors(bp->pdev); in ptp_ocp_detach()
4526 if (bp->ptp) in ptp_ocp_detach()
4527 ptp_clock_unregister(bp->ptp); in ptp_ocp_detach()
4528 kfree(bp->ptp_info.pin_config); in ptp_ocp_detach()
4529 device_unregister(&bp->dev); in ptp_ocp_detach()
4540 *status = bp->sync ? DPLL_LOCK_STATUS_LOCKED : DPLL_LOCK_STATUS_UNLOCKED; in ptp_ocp_dpll_lock_status_get()
4553 if (bp->pps_select) { in ptp_ocp_dpll_state_get()
4554 idx = ioread32(&bp->pps_select->gpio1); in ptp_ocp_dpll_state_get()
4555 *state = (&bp->sma[idx] == pin_priv) ? DPLL_PIN_STATE_CONNECTED : in ptp_ocp_dpll_state_get()
4560 return -EINVAL; in ptp_ocp_dpll_state_get()
4579 *direction = sma->mode == SMA_MODE_IN ? in ptp_ocp_dpll_direction_get()
4595 int sma_nr = (sma - bp->sma); in ptp_ocp_dpll_direction_set()
4597 if (sma->fixed_dir) in ptp_ocp_dpll_direction_set()
4598 return -EOPNOTSUPP; in ptp_ocp_dpll_direction_set()
4613 int sma_nr = (sma - bp->sma); in ptp_ocp_dpll_frequency_set()
4616 if (sma->fixed_fcn) in ptp_ocp_dpll_frequency_set()
4617 return -EOPNOTSUPP; in ptp_ocp_dpll_frequency_set()
4619 tbl = bp->sma_op->tbl[sma->mode]; in ptp_ocp_dpll_frequency_set()
4622 return ptp_ocp_sma_store_val(bp, i, sma->mode, sma_nr + 1); in ptp_ocp_dpll_frequency_set()
4623 return -EINVAL; in ptp_ocp_dpll_frequency_set()
4635 int sma_nr = (sma - bp->sma); in ptp_ocp_dpll_frequency_get()
4639 val = bp->sma_op->get(bp, sma_nr + 1); in ptp_ocp_dpll_frequency_get()
4640 tbl = bp->sma_op->tbl[sma->mode]; in ptp_ocp_dpll_frequency_get()
4647 return -EINVAL; in ptp_ocp_dpll_frequency_get()
4670 sync = !!(ioread32(&bp->reg->status) & OCP_STATUS_IN_SYNC); in ptp_ocp_sync_work()
4672 if (bp->sync != sync) in ptp_ocp_sync_work()
4673 dpll_device_change_ntf(bp->dpll); in ptp_ocp_sync_work()
4675 bp->sync = sync; in ptp_ocp_sync_work()
4677 queue_delayed_work(system_power_efficient_wq, &bp->sync_work, HZ); in ptp_ocp_sync_work()
4688 devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); in ptp_ocp_probe()
4690 dev_err(&pdev->dev, "devlink_alloc failed\n"); in ptp_ocp_probe()
4691 return -ENOMEM; in ptp_ocp_probe()
4696 dev_err(&pdev->dev, "pci_enable_device\n"); in ptp_ocp_probe()
4705 INIT_DELAYED_WORK(&bp->sync_work, ptp_ocp_sync_work); in ptp_ocp_probe()
4709 * allow this - if not all of the IRQ's are returned, skip the in ptp_ocp_probe()
4714 dev_err(&pdev->dev, "alloc_irq_vectors err: %d\n", err); in ptp_ocp_probe()
4717 bp->n_irqs = err; in ptp_ocp_probe()
4720 err = ptp_ocp_register_resources(bp, id->driver_data); in ptp_ocp_probe()
4724 bp->ptp = ptp_clock_register(&bp->ptp_info, &pdev->dev); in ptp_ocp_probe()
4725 if (IS_ERR(bp->ptp)) { in ptp_ocp_probe()
4726 err = PTR_ERR(bp->ptp); in ptp_ocp_probe()
4727 dev_err(&pdev->dev, "ptp_clock_register: %d\n", err); in ptp_ocp_probe()
4728 bp->ptp = NULL; in ptp_ocp_probe()
4740 bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE); in ptp_ocp_probe()
4741 if (IS_ERR(bp->dpll)) { in ptp_ocp_probe()
4742 err = PTR_ERR(bp->dpll); in ptp_ocp_probe()
4743 dev_err(&pdev->dev, "dpll_device_alloc failed\n"); in ptp_ocp_probe()
4747 err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp); in ptp_ocp_probe()
4752 bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, &bp->sma[i].dpll_prop); in ptp_ocp_probe()
4753 if (IS_ERR(bp->sma[i].dpll_pin)) { in ptp_ocp_probe()
4754 err = PTR_ERR(bp->sma[i].dpll_pin); in ptp_ocp_probe()
4758 err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, in ptp_ocp_probe()
4759 &bp->sma[i]); in ptp_ocp_probe()
4761 dpll_pin_put(bp->sma[i].dpll_pin); in ptp_ocp_probe()
4765 queue_delayed_work(system_power_efficient_wq, &bp->sync_work, HZ); in ptp_ocp_probe()
4770 --i; in ptp_ocp_probe()
4771 dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); in ptp_ocp_probe()
4772 dpll_pin_put(bp->sma[i].dpll_pin); in ptp_ocp_probe()
4774 dpll_device_put(bp->dpll); in ptp_ocp_probe()
4791 cancel_delayed_work_sync(&bp->sync_work); in ptp_ocp_remove()
4793 if (bp->sma[i].dpll_pin) { in ptp_ocp_remove()
4794 dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); in ptp_ocp_remove()
4795 dpll_pin_put(bp->sma[i].dpll_pin); in ptp_ocp_remove()
4798 dpll_device_unregister(bp->dpll, &dpll_ops, bp); in ptp_ocp_remove()
4799 dpll_device_put(bp->dpll); in ptp_ocp_remove()
4835 while ((dev = dev->parent)) in ptp_ocp_i2c_notifier_call()
4836 if (dev->driver && !strcmp(dev->driver->name, KBUILD_MODNAME)) in ptp_ocp_i2c_notifier_call()
4843 ptp_ocp_symlink(bp, child, "i2c"); in ptp_ocp_i2c_notifier_call()
4845 sysfs_remove_link(&bp->dev.kobj, "i2c"); in ptp_ocp_i2c_notifier_call()
4867 what = "i2c notifier"; in ptp_ocp_init()