Lines Matching +full:gpio +full:- +full:out +full:- +full:pol
1 // SPDX-License-Identifier: GPL-2.0-only
13 #include <linux/clk-provider.h>
15 #include <linux/platform_data/i2c-xiic.h>
22 #include <linux/nvmem-consumer.h>
383 (void *)((uintptr_t)(bp) + (map)->bp_offset); \
393 uintptr_t addr = (uintptr_t)(bp) + (res)->bp_offset; \
583 .name = "xiic-i2c",
623 .modalias = "spi-nor",
728 return bp->sma_op->init(bp); in ptp_ocp_sma_init()
734 return bp->sma_op->get(bp, sma_nr); in ptp_ocp_sma_get()
740 return bp->sma_op->set_inputs(bp, sma_nr, val); in ptp_ocp_sma_set_inputs()
746 return bp->sma_op->set_output(bp, sma_nr, val); in ptp_ocp_sma_set_output()
771 return -EINVAL; in ptp_ocp_select_val_from_name()
784 count--; in ptp_ocp_select_table_show()
799 iowrite32(ctrl, &bp->reg->ctrl); in __ptp_ocp_gettime_locked()
802 ctrl = ioread32(&bp->reg->ctrl); in __ptp_ocp_gettime_locked()
808 if (sts && bp->ts_window_adjust) { in __ptp_ocp_gettime_locked()
809 s64 ns = timespec64_to_ns(&sts->post_ts); in __ptp_ocp_gettime_locked()
811 sts->post_ts = ns_to_timespec64(ns - bp->ts_window_adjust); in __ptp_ocp_gettime_locked()
814 time_ns = ioread32(&bp->reg->time_ns); in __ptp_ocp_gettime_locked()
815 time_sec = ioread32(&bp->reg->time_sec); in __ptp_ocp_gettime_locked()
817 ts->tv_sec = time_sec; in __ptp_ocp_gettime_locked()
818 ts->tv_nsec = time_ns; in __ptp_ocp_gettime_locked()
820 return ctrl & OCP_CTRL_READ_TIME_DONE ? 0 : -ETIMEDOUT; in __ptp_ocp_gettime_locked()
831 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_gettimex()
833 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_gettimex()
844 time_ns = ts->tv_nsec; in __ptp_ocp_settime_locked()
845 time_sec = ts->tv_sec; in __ptp_ocp_settime_locked()
847 select = ioread32(&bp->reg->select); in __ptp_ocp_settime_locked()
848 iowrite32(OCP_SELECT_CLK_REG, &bp->reg->select); in __ptp_ocp_settime_locked()
850 iowrite32(time_ns, &bp->reg->adjust_ns); in __ptp_ocp_settime_locked()
851 iowrite32(time_sec, &bp->reg->adjust_sec); in __ptp_ocp_settime_locked()
854 iowrite32(ctrl, &bp->reg->ctrl); in __ptp_ocp_settime_locked()
857 iowrite32(select >> 16, &bp->reg->select); in __ptp_ocp_settime_locked()
866 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_settime()
868 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_settime()
878 select = ioread32(&bp->reg->select); in __ptp_ocp_adjtime_locked()
879 iowrite32(OCP_SELECT_CLK_REG, &bp->reg->select); in __ptp_ocp_adjtime_locked()
881 iowrite32(adj_val, &bp->reg->offset_ns); in __ptp_ocp_adjtime_locked()
882 iowrite32(NSEC_PER_SEC, &bp->reg->offset_window_ns); in __ptp_ocp_adjtime_locked()
885 iowrite32(ctrl, &bp->reg->ctrl); in __ptp_ocp_adjtime_locked()
888 iowrite32(select >> 16, &bp->reg->select); in __ptp_ocp_adjtime_locked()
898 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_adjtime_coarse()
905 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_adjtime_coarse()
915 if (delta_ns > NSEC_PER_SEC || -delta_ns > NSEC_PER_SEC) { in ptp_ocp_adjtime()
921 adj_ns = sign ? -delta_ns : delta_ns; in ptp_ocp_adjtime()
923 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_adjtime()
925 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_adjtime()
936 return -EOPNOTSUPP; in ptp_ocp_null_adjfine()
942 return -EOPNOTSUPP; in ptp_ocp_null_adjphase()
954 switch (rq->type) { in ptp_ocp_enable()
957 switch (rq->extts.index) { in ptp_ocp_enable()
959 ext = bp->ts0; in ptp_ocp_enable()
962 ext = bp->ts1; in ptp_ocp_enable()
965 ext = bp->ts2; in ptp_ocp_enable()
968 ext = bp->ts3; in ptp_ocp_enable()
971 ext = bp->ts4; in ptp_ocp_enable()
974 ext = bp->pps; in ptp_ocp_enable()
980 ext = bp->pps; in ptp_ocp_enable()
983 switch (rq->perout.index) { in ptp_ocp_enable()
988 if (on && (rq->perout.period.sec != 1 || in ptp_ocp_enable()
989 rq->perout.period.nsec != 0)) in ptp_ocp_enable()
990 return -EINVAL; in ptp_ocp_enable()
996 req = rq->perout.index - 1; in ptp_ocp_enable()
997 ext = bp->signal_out[req]; in ptp_ocp_enable()
998 err = ptp_ocp_signal_from_perout(bp, req, &rq->perout); in ptp_ocp_enable()
1005 return -EOPNOTSUPP; in ptp_ocp_enable()
1008 err = -ENXIO; in ptp_ocp_enable()
1010 err = ext->info->enable(ext, req, on); in ptp_ocp_enable()
1034 snprintf(buf, sizeof(buf), "OUT: GEN%d", chan); in ptp_ocp_verify()
1036 snprintf(buf, sizeof(buf), "OUT: PHC"); in ptp_ocp_verify()
1039 return -EOPNOTSUPP; in ptp_ocp_verify()
1066 select = ioread32(&bp->reg->select); in __ptp_ocp_clear_drift_locked()
1067 iowrite32(OCP_SELECT_CLK_REG, &bp->reg->select); in __ptp_ocp_clear_drift_locked()
1069 iowrite32(0, &bp->reg->drift_ns); in __ptp_ocp_clear_drift_locked()
1072 iowrite32(ctrl, &bp->reg->ctrl); in __ptp_ocp_clear_drift_locked()
1075 iowrite32(select >> 16, &bp->reg->select); in __ptp_ocp_clear_drift_locked()
1083 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_utc_distribute()
1085 bp->utc_tai_offset = val; in ptp_ocp_utc_distribute()
1087 if (bp->irig_out) in ptp_ocp_utc_distribute()
1088 iowrite32(val, &bp->irig_out->adj_sec); in ptp_ocp_utc_distribute()
1089 if (bp->dcf_out) in ptp_ocp_utc_distribute()
1090 iowrite32(val, &bp->dcf_out->adj_sec); in ptp_ocp_utc_distribute()
1091 if (bp->nmea_out) in ptp_ocp_utc_distribute()
1092 iowrite32(val, &bp->nmea_out->adj_sec); in ptp_ocp_utc_distribute()
1094 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_utc_distribute()
1104 status = ioread32(&bp->pps_to_clk->status); in ptp_ocp_watchdog()
1107 iowrite32(status, &bp->pps_to_clk->status); in ptp_ocp_watchdog()
1108 if (!bp->gnss_lost) { in ptp_ocp_watchdog()
1109 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_watchdog()
1111 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_watchdog()
1112 bp->gnss_lost = ktime_get_real_seconds(); in ptp_ocp_watchdog()
1115 } else if (bp->gnss_lost) { in ptp_ocp_watchdog()
1116 bp->gnss_lost = 0; in ptp_ocp_watchdog()
1122 if (bp->tod) { in ptp_ocp_watchdog()
1123 status = ioread32(&bp->tod->utc_status); in ptp_ocp_watchdog()
1126 utc_offset != bp->utc_tai_offset) in ptp_ocp_watchdog()
1130 mod_timer(&bp->watchdog, jiffies + HZ); in ptp_ocp_watchdog()
1140 ctrl = ioread32(&bp->reg->ctrl); in ptp_ocp_estimate_pci_timing()
1143 iowrite32(ctrl, &bp->reg->ctrl); in ptp_ocp_estimate_pci_timing()
1147 ctrl = ioread32(&bp->reg->ctrl); in ptp_ocp_estimate_pci_timing()
1151 delay = end - start; in ptp_ocp_estimate_pci_timing()
1152 bp->ts_window_adjust = (delay >> 5) * 3; in ptp_ocp_estimate_pci_timing()
1163 iowrite32(ctrl, &bp->reg->ctrl); in ptp_ocp_init_clock()
1167 iowrite32(0x2000, &bp->reg->servo_offset_p); in ptp_ocp_init_clock()
1168 iowrite32(0x1000, &bp->reg->servo_offset_i); in ptp_ocp_init_clock()
1169 iowrite32(0, &bp->reg->servo_drift_p); in ptp_ocp_init_clock()
1170 iowrite32(0, &bp->reg->servo_drift_i); in ptp_ocp_init_clock()
1174 iowrite32(ctrl, &bp->reg->ctrl); in ptp_ocp_init_clock()
1176 if ((ioread32(&bp->reg->ctrl) & OCP_CTRL_ENABLE) == 0) { in ptp_ocp_init_clock()
1177 dev_err(&bp->pdev->dev, "clock not enabled\n"); in ptp_ocp_init_clock()
1178 return -ENODEV; in ptp_ocp_init_clock()
1183 sync = ioread32(&bp->reg->status) & OCP_STATUS_IN_SYNC; in ptp_ocp_init_clock()
1186 ptp_ocp_settime(&bp->ptp_info, &ts); in ptp_ocp_init_clock()
1190 if (bp->pps_to_clk) { in ptp_ocp_init_clock()
1191 timer_setup(&bp->watchdog, ptp_ocp_watchdog, 0); in ptp_ocp_init_clock()
1192 mod_timer(&bp->watchdog, jiffies + HZ); in ptp_ocp_init_clock()
1203 ctrl = ioread32(&bp->tod->ctrl); in ptp_ocp_tod_init()
1206 iowrite32(ctrl, &bp->tod->ctrl); in ptp_ocp_tod_init()
1208 reg = ioread32(&bp->tod->utc_status); in ptp_ocp_tod_init()
1231 idx = ARRAY_SIZE(gnss_name) - 1; in ptp_ocp_tod_gnss_name()
1245 dev = dev->parent; in ptp_ocp_nvmem_match()
1246 if (!i2c_verify_client(dev) || info->tag != dev->platform_data) in ptp_ocp_nvmem_match()
1249 while ((dev = dev->parent)) in ptp_ocp_nvmem_match()
1250 if (dev->driver && !strcmp(dev->driver->name, KBUILD_MODNAME)) in ptp_ocp_nvmem_match()
1251 return info->bp == dev_get_drvdata(dev); in ptp_ocp_nvmem_match()
1279 if (!bp->i2c_ctrl) in ptp_ocp_read_eeprom()
1285 for (map = bp->eeprom_map; map->len; map++) { in ptp_ocp_read_eeprom()
1286 if (map->tag != tag) { in ptp_ocp_read_eeprom()
1287 tag = map->tag; in ptp_ocp_read_eeprom()
1297 ret = nvmem_device_read(nvmem, map->off, map->len, in ptp_ocp_read_eeprom()
1299 if (ret != map->len) in ptp_ocp_read_eeprom()
1303 bp->has_eeprom_data = true; in ptp_ocp_read_eeprom()
1305 out: in ptp_ocp_read_eeprom()
1310 dev_err(&bp->pdev->dev, "could not read eeprom: %d\n", ret); in ptp_ocp_read_eeprom()
1311 goto out; in ptp_ocp_read_eeprom()
1320 dev = &bp->spi_flash->dev; in ptp_ocp_find_flash()
1342 hdr = (const struct ptp_ocp_firmware_header *)fw->data; in ptp_ocp_devlink_fw_image()
1343 if (memcmp(hdr->magic, OCP_FIRMWARE_MAGIC_HEADER, 4)) { in ptp_ocp_devlink_fw_image()
1348 length = fw->size; in ptp_ocp_devlink_fw_image()
1349 goto out; in ptp_ocp_devlink_fw_image()
1352 if (be16_to_cpu(hdr->pci_vendor_id) != bp->pdev->vendor || in ptp_ocp_devlink_fw_image()
1353 be16_to_cpu(hdr->pci_device_id) != bp->pdev->device) { in ptp_ocp_devlink_fw_image()
1357 return -EINVAL; in ptp_ocp_devlink_fw_image()
1361 length = be32_to_cpu(hdr->image_size); in ptp_ocp_devlink_fw_image()
1362 if (length != (fw->size - offset)) { in ptp_ocp_devlink_fw_image()
1366 return -EINVAL; in ptp_ocp_devlink_fw_image()
1369 crc = crc16(0xffff, &fw->data[offset], length); in ptp_ocp_devlink_fw_image()
1370 if (be16_to_cpu(hdr->crc) != crc) { in ptp_ocp_devlink_fw_image()
1374 return -EINVAL; in ptp_ocp_devlink_fw_image()
1377 out: in ptp_ocp_devlink_fw_image()
1378 *data = &fw->data[offset]; in ptp_ocp_devlink_fw_image()
1398 goto out; in ptp_ocp_devlink_flash()
1401 base = bp->flash_start; in ptp_ocp_devlink_flash()
1415 goto out; in ptp_ocp_devlink_flash()
1419 goto out; in ptp_ocp_devlink_flash()
1422 resid -= len; in ptp_ocp_devlink_flash()
1424 out: in ptp_ocp_devlink_flash()
1440 dev_err(&bp->pdev->dev, "Can't find Flash SPI adapter\n"); in ptp_ocp_devlink_flash_update()
1441 return -ENODEV; in ptp_ocp_devlink_flash_update()
1447 err = ptp_ocp_devlink_flash(devlink, dev, params->fw); in ptp_ocp_devlink_flash_update()
1469 fw_image = bp->fw_loader ? "loader" : "fw"; in ptp_ocp_devlink_info_get()
1470 sprintf(buf, "%d.%d", bp->fw_tag, bp->fw_version); in ptp_ocp_devlink_info_get()
1475 if (!bp->has_eeprom_data) { in ptp_ocp_devlink_info_get()
1477 if (!bp->has_eeprom_data) in ptp_ocp_devlink_info_get()
1481 sprintf(buf, "%pM", bp->serial); in ptp_ocp_devlink_info_get()
1488 bp->board_id); in ptp_ocp_devlink_info_get()
1505 return devm_ioremap_resource(&bp->pdev->dev, &res); in __ptp_ocp_get_mem()
1513 start = pci_resource_start(bp->pdev, 0) + r->offset; in ptp_ocp_get_mem()
1514 return __ptp_ocp_get_mem(bp, start, r->size); in ptp_ocp_get_mem()
1535 struct pci_dev *pdev = bp->pdev; in ptp_ocp_register_spi()
1541 start = pci_resource_start(pdev, 0) + r->offset; in ptp_ocp_register_spi()
1542 ptp_ocp_set_mem_resource(&res[0], start, r->size); in ptp_ocp_register_spi()
1543 ptp_ocp_set_irq_resource(&res[1], pci_irq_vector(pdev, r->irq_vec)); in ptp_ocp_register_spi()
1545 info = r->extra; in ptp_ocp_register_spi()
1547 id += info->pci_offset; in ptp_ocp_register_spi()
1549 p = platform_device_register_resndata(&pdev->dev, info->name, id, in ptp_ocp_register_spi()
1550 res, 2, info->data, in ptp_ocp_register_spi()
1551 info->data_size); in ptp_ocp_register_spi()
1567 info = r->extra; in ptp_ocp_i2c_bus()
1568 start = pci_resource_start(pdev, 0) + r->offset; in ptp_ocp_i2c_bus()
1569 ptp_ocp_set_mem_resource(&res[0], start, r->size); in ptp_ocp_i2c_bus()
1570 ptp_ocp_set_irq_resource(&res[1], pci_irq_vector(pdev, r->irq_vec)); in ptp_ocp_i2c_bus()
1572 return platform_device_register_resndata(&pdev->dev, info->name, in ptp_ocp_i2c_bus()
1574 info->data, info->data_size); in ptp_ocp_i2c_bus()
1580 struct pci_dev *pdev = bp->pdev; in ptp_ocp_register_i2c()
1587 info = r->extra; in ptp_ocp_register_i2c()
1588 id = pci_dev_id(bp->pdev); in ptp_ocp_register_i2c()
1591 clk = clk_hw_register_fixed_rate(&pdev->dev, buf, NULL, 0, in ptp_ocp_register_i2c()
1592 info->fixed_rate); in ptp_ocp_register_i2c()
1595 bp->i2c_clk = clk; in ptp_ocp_register_i2c()
1597 sprintf(buf, "%s.%d", info->name, id); in ptp_ocp_register_i2c()
1598 devm_clk_hw_register_clkdev(&pdev->dev, clk, NULL, buf); in ptp_ocp_register_i2c()
1599 p = ptp_ocp_i2c_bus(bp->pdev, r, id); in ptp_ocp_register_i2c()
1613 struct signal_reg __iomem *reg = ext->mem; in ptp_ocp_signal_irq()
1614 struct ptp_ocp *bp = ext->bp; in ptp_ocp_signal_irq()
1618 gen = ext->info->index - 1; in ptp_ocp_signal_irq()
1620 enable = ioread32(®->enable); in ptp_ocp_signal_irq()
1621 status = ioread32(®->status); in ptp_ocp_signal_irq()
1625 iowrite32(0, ®->intr_mask); in ptp_ocp_signal_irq()
1626 iowrite32(0, ®->enable); in ptp_ocp_signal_irq()
1627 bp->signal[gen].running = false; in ptp_ocp_signal_irq()
1630 iowrite32(0, ®->intr); /* ack interrupt */ in ptp_ocp_signal_irq()
1643 if (!s->period) in ptp_ocp_signal_set()
1646 if (!s->pulse) in ptp_ocp_signal_set()
1647 s->pulse = ktime_divns(s->period * s->duty, 100); in ptp_ocp_signal_set()
1649 err = ptp_ocp_gettimex(&bp->ptp_info, &ts, &sts); in ptp_ocp_signal_set()
1654 if (!s->start) { in ptp_ocp_signal_set()
1655 /* roundup() does not work on 32-bit systems */ in ptp_ocp_signal_set()
1656 s->start = DIV64_U64_ROUND_UP(start_ns, s->period); in ptp_ocp_signal_set()
1657 s->start = ktime_add(s->start, s->phase); in ptp_ocp_signal_set()
1660 if (s->duty < 1 || s->duty > 99) in ptp_ocp_signal_set()
1661 return -EINVAL; in ptp_ocp_signal_set()
1663 if (s->pulse < 1 || s->pulse > s->period) in ptp_ocp_signal_set()
1664 return -EINVAL; in ptp_ocp_signal_set()
1666 if (s->start < start_ns) in ptp_ocp_signal_set()
1667 return -EINVAL; in ptp_ocp_signal_set()
1669 bp->signal[gen] = *s; in ptp_ocp_signal_set()
1680 s.polarity = bp->signal[gen].polarity; in ptp_ocp_signal_from_perout()
1681 s.period = ktime_set(req->period.sec, req->period.nsec); in ptp_ocp_signal_from_perout()
1685 if (req->flags & PTP_PEROUT_DUTY_CYCLE) { in ptp_ocp_signal_from_perout()
1686 s.pulse = ktime_set(req->on.sec, req->on.nsec); in ptp_ocp_signal_from_perout()
1690 if (req->flags & PTP_PEROUT_PHASE) in ptp_ocp_signal_from_perout()
1691 s.phase = ktime_set(req->phase.sec, req->phase.nsec); in ptp_ocp_signal_from_perout()
1693 s.start = ktime_set(req->start.sec, req->start.nsec); in ptp_ocp_signal_from_perout()
1702 struct signal_reg __iomem *reg = ext->mem; in ptp_ocp_signal_enable()
1703 struct ptp_ocp *bp = ext->bp; in ptp_ocp_signal_enable()
1707 gen = ext->info->index - 1; in ptp_ocp_signal_enable()
1709 iowrite32(0, ®->intr_mask); in ptp_ocp_signal_enable()
1710 iowrite32(0, ®->enable); in ptp_ocp_signal_enable()
1711 bp->signal[gen].running = false; in ptp_ocp_signal_enable()
1715 ts = ktime_to_timespec64(bp->signal[gen].start); in ptp_ocp_signal_enable()
1716 iowrite32(ts.tv_sec, ®->start_sec); in ptp_ocp_signal_enable()
1717 iowrite32(ts.tv_nsec, ®->start_ns); in ptp_ocp_signal_enable()
1719 ts = ktime_to_timespec64(bp->signal[gen].period); in ptp_ocp_signal_enable()
1720 iowrite32(ts.tv_sec, ®->period_sec); in ptp_ocp_signal_enable()
1721 iowrite32(ts.tv_nsec, ®->period_ns); in ptp_ocp_signal_enable()
1723 ts = ktime_to_timespec64(bp->signal[gen].pulse); in ptp_ocp_signal_enable()
1724 iowrite32(ts.tv_sec, ®->pulse_sec); in ptp_ocp_signal_enable()
1725 iowrite32(ts.tv_nsec, ®->pulse_ns); in ptp_ocp_signal_enable()
1727 iowrite32(bp->signal[gen].polarity, ®->polarity); in ptp_ocp_signal_enable()
1728 iowrite32(0, ®->repeat_count); in ptp_ocp_signal_enable()
1730 iowrite32(0, ®->intr); /* clear interrupt state */ in ptp_ocp_signal_enable()
1731 iowrite32(1, ®->intr_mask); /* enable interrupt */ in ptp_ocp_signal_enable()
1732 iowrite32(3, ®->enable); /* valid & enable */ in ptp_ocp_signal_enable()
1734 bp->signal[gen].running = true; in ptp_ocp_signal_enable()
1743 struct ts_reg __iomem *reg = ext->mem; in ptp_ocp_ts_irq()
1747 if (ext == ext->bp->pps) { in ptp_ocp_ts_irq()
1748 if (ext->bp->pps_req_map & OCP_REQ_PPS) { in ptp_ocp_ts_irq()
1750 ptp_clock_event(ext->bp->ptp, &ev); in ptp_ocp_ts_irq()
1753 if ((ext->bp->pps_req_map & ~OCP_REQ_PPS) == 0) in ptp_ocp_ts_irq()
1754 goto out; in ptp_ocp_ts_irq()
1757 /* XXX should fix API - this converts s/ns -> ts -> s/ns */ in ptp_ocp_ts_irq()
1758 sec = ioread32(®->time_sec); in ptp_ocp_ts_irq()
1759 nsec = ioread32(®->time_ns); in ptp_ocp_ts_irq()
1762 ev.index = ext->info->index; in ptp_ocp_ts_irq()
1765 ptp_clock_event(ext->bp->ptp, &ev); in ptp_ocp_ts_irq()
1767 out: in ptp_ocp_ts_irq()
1768 iowrite32(1, ®->intr); /* write 1 to ack */ in ptp_ocp_ts_irq()
1777 struct ts_reg __iomem *reg = ext->mem; in ptp_ocp_ts_enable()
1778 struct ptp_ocp *bp = ext->bp; in ptp_ocp_ts_enable()
1780 if (ext == bp->pps) { in ptp_ocp_ts_enable()
1781 u32 old_map = bp->pps_req_map; in ptp_ocp_ts_enable()
1784 bp->pps_req_map |= req; in ptp_ocp_ts_enable()
1786 bp->pps_req_map &= ~req; in ptp_ocp_ts_enable()
1789 if ((!!old_map ^ !!bp->pps_req_map) == 0) in ptp_ocp_ts_enable()
1794 iowrite32(1, ®->enable); in ptp_ocp_ts_enable()
1795 iowrite32(1, ®->intr_mask); in ptp_ocp_ts_enable()
1796 iowrite32(1, ®->intr); in ptp_ocp_ts_enable()
1798 iowrite32(0, ®->intr_mask); in ptp_ocp_ts_enable()
1799 iowrite32(0, ®->enable); in ptp_ocp_ts_enable()
1808 ext->info->enable(ext, ~0, false); in ptp_ocp_unregister_ext()
1809 pci_free_irq(ext->bp->pdev, ext->irq_vec, ext); in ptp_ocp_unregister_ext()
1816 struct pci_dev *pdev = bp->pdev; in ptp_ocp_register_ext()
1822 return -ENOMEM; in ptp_ocp_register_ext()
1824 ext->mem = ptp_ocp_get_mem(bp, r); in ptp_ocp_register_ext()
1825 if (IS_ERR(ext->mem)) { in ptp_ocp_register_ext()
1826 err = PTR_ERR(ext->mem); in ptp_ocp_register_ext()
1827 goto out; in ptp_ocp_register_ext()
1830 ext->bp = bp; in ptp_ocp_register_ext()
1831 ext->info = r->extra; in ptp_ocp_register_ext()
1832 ext->irq_vec = r->irq_vec; in ptp_ocp_register_ext()
1834 err = pci_request_irq(pdev, r->irq_vec, ext->info->irq_fcn, NULL, in ptp_ocp_register_ext()
1835 ext, "ocp%d.%s", bp->id, r->name); in ptp_ocp_register_ext()
1837 dev_err(&pdev->dev, "Could not get irq %d\n", r->irq_vec); in ptp_ocp_register_ext()
1838 goto out; in ptp_ocp_register_ext()
1845 out: in ptp_ocp_register_ext()
1853 struct pci_dev *pdev = bp->pdev; in ptp_ocp_serial_line()
1860 uart.port.dev = &pdev->dev; in ptp_ocp_serial_line()
1863 uart.port.mapbase = pci_resource_start(pdev, 0) + r->offset; in ptp_ocp_serial_line()
1864 uart.port.irq = pci_irq_vector(pdev, r->irq_vec); in ptp_ocp_serial_line()
1903 if (!bp->nmea_out) in ptp_ocp_nmea_out_init()
1906 iowrite32(0, &bp->nmea_out->ctrl); /* disable */ in ptp_ocp_nmea_out_init()
1907 iowrite32(7, &bp->nmea_out->uart_baud); /* 115200 */ in ptp_ocp_nmea_out_init()
1908 iowrite32(1, &bp->nmea_out->ctrl); /* enable */ in ptp_ocp_nmea_out_init()
1916 iowrite32(0, ®->enable); /* disable */ in _ptp_ocp_signal_init()
1918 val = ioread32(®->polarity); in _ptp_ocp_signal_init()
1919 s->polarity = val ? true : false; in _ptp_ocp_signal_init()
1920 s->duty = 50; in _ptp_ocp_signal_init()
1929 if (bp->signal_out[i]) in ptp_ocp_signal_init()
1930 _ptp_ocp_signal_init(&bp->signal[i], in ptp_ocp_signal_init()
1931 bp->signal_out[i]->mem); in ptp_ocp_signal_init()
1937 sysfs_remove_groups(&bp->dev.kobj, bp->attr_group); in ptp_ocp_attr_group_del()
1938 kfree(bp->attr_group); in ptp_ocp_attr_group_del()
1950 if (attr_tbl[i].cap & bp->fw_cap) in ptp_ocp_attr_group_add()
1953 bp->attr_group = kcalloc(count + 1, sizeof(struct attribute_group *), in ptp_ocp_attr_group_add()
1955 if (!bp->attr_group) in ptp_ocp_attr_group_add()
1956 return -ENOMEM; in ptp_ocp_attr_group_add()
1960 if (attr_tbl[i].cap & bp->fw_cap) in ptp_ocp_attr_group_add()
1961 bp->attr_group[count++] = attr_tbl[i].group; in ptp_ocp_attr_group_add()
1963 err = sysfs_create_groups(&bp->dev.kobj, bp->attr_group); in ptp_ocp_attr_group_add()
1965 bp->attr_group[0] = NULL; in ptp_ocp_attr_group_add()
1988 return ptp_ocp_enable_fpga(&bp->irig_out->ctrl, in ptp_ocp_irig_out()
1995 return ptp_ocp_enable_fpga(&bp->irig_in->ctrl, in ptp_ocp_irig_in()
2002 return ptp_ocp_enable_fpga(&bp->dcf_out->ctrl, in ptp_ocp_dcf_out()
2009 return ptp_ocp_enable_fpga(&bp->dcf_in->ctrl, in ptp_ocp_dcf_in()
2030 u32 __iomem *gpio; in ptp_ocp_sma_fb_get() local
2033 if (bp->sma[sma_nr - 1].fixed_fcn) in ptp_ocp_sma_fb_get()
2034 return (sma_nr - 1) & 1; in ptp_ocp_sma_fb_get()
2036 if (bp->sma[sma_nr - 1].mode == SMA_MODE_IN) in ptp_ocp_sma_fb_get()
2037 gpio = sma_nr > 2 ? &bp->sma_map2->gpio1 : &bp->sma_map1->gpio1; in ptp_ocp_sma_fb_get()
2039 gpio = sma_nr > 2 ? &bp->sma_map1->gpio2 : &bp->sma_map2->gpio2; in ptp_ocp_sma_fb_get()
2042 return (ioread32(gpio) >> shift) & 0xffff; in ptp_ocp_sma_fb_get()
2050 u32 __iomem *gpio; in ptp_ocp_sma_fb_set_output() local
2052 gpio = sma_nr > 2 ? &bp->sma_map1->gpio2 : &bp->sma_map2->gpio2; in ptp_ocp_sma_fb_set_output()
2055 mask = 0xffff << (16 - shift); in ptp_ocp_sma_fb_set_output()
2057 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_sma_fb_set_output()
2059 reg = ioread32(gpio); in ptp_ocp_sma_fb_set_output()
2064 iowrite32(reg, gpio); in ptp_ocp_sma_fb_set_output()
2066 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_sma_fb_set_output()
2076 u32 __iomem *gpio; in ptp_ocp_sma_fb_set_inputs() local
2078 gpio = sma_nr > 2 ? &bp->sma_map2->gpio1 : &bp->sma_map1->gpio1; in ptp_ocp_sma_fb_set_inputs()
2081 mask = 0xffff << (16 - shift); in ptp_ocp_sma_fb_set_inputs()
2083 spin_lock_irqsave(&bp->lock, flags); in ptp_ocp_sma_fb_set_inputs()
2085 reg = ioread32(gpio); in ptp_ocp_sma_fb_set_inputs()
2090 iowrite32(reg, gpio); in ptp_ocp_sma_fb_set_inputs()
2092 spin_unlock_irqrestore(&bp->lock, flags); in ptp_ocp_sma_fb_set_inputs()
2104 bp->sma[0].mode = SMA_MODE_IN; in ptp_ocp_sma_fb_init()
2105 bp->sma[1].mode = SMA_MODE_IN; in ptp_ocp_sma_fb_init()
2106 bp->sma[2].mode = SMA_MODE_OUT; in ptp_ocp_sma_fb_init()
2107 bp->sma[3].mode = SMA_MODE_OUT; in ptp_ocp_sma_fb_init()
2109 bp->sma[i].default_fcn = i & 1; in ptp_ocp_sma_fb_init()
2112 if (!bp->sma_map1) { in ptp_ocp_sma_fb_init()
2114 bp->sma[i].fixed_fcn = true; in ptp_ocp_sma_fb_init()
2115 bp->sma[i].fixed_dir = true; in ptp_ocp_sma_fb_init()
2120 /* If SMA2 GPIO output map is all 1, it is not present. in ptp_ocp_sma_fb_init()
2123 reg = ioread32(&bp->sma_map2->gpio2); in ptp_ocp_sma_fb_init()
2126 bp->sma[i].fixed_dir = true; in ptp_ocp_sma_fb_init()
2128 reg = ioread32(&bp->sma_map1->gpio1); in ptp_ocp_sma_fb_init()
2129 bp->sma[0].mode = reg & BIT(15) ? SMA_MODE_IN : SMA_MODE_OUT; in ptp_ocp_sma_fb_init()
2130 bp->sma[1].mode = reg & BIT(31) ? SMA_MODE_IN : SMA_MODE_OUT; in ptp_ocp_sma_fb_init()
2132 reg = ioread32(&bp->sma_map1->gpio2); in ptp_ocp_sma_fb_init()
2133 bp->sma[2].mode = reg & BIT(15) ? SMA_MODE_OUT : SMA_MODE_IN; in ptp_ocp_sma_fb_init()
2134 bp->sma[3].mode = reg & BIT(31) ? SMA_MODE_OUT : SMA_MODE_IN; in ptp_ocp_sma_fb_init()
2154 return -ENOMEM; in ptp_ocp_fb_set_pins()
2161 bp->ptp_info.n_pins = 4; in ptp_ocp_fb_set_pins()
2162 bp->ptp_info.pin_config = config; in ptp_ocp_fb_set_pins()
2173 version = ioread32(&bp->image->version); in ptp_ocp_fb_set_version()
2178 bp->fw_loader = true; in ptp_ocp_fb_set_version()
2181 bp->fw_tag = version >> 15; in ptp_ocp_fb_set_version()
2182 bp->fw_version = version & 0x7fff; in ptp_ocp_fb_set_version()
2184 if (bp->fw_tag) { in ptp_ocp_fb_set_version()
2196 bp->fw_cap = cap; in ptp_ocp_fb_set_version()
2205 bp->flash_start = 1024 * 4096; in ptp_ocp_fb_board_init()
2206 bp->eeprom_map = fb_eeprom_map; in ptp_ocp_fb_board_init()
2207 bp->fw_version = ioread32(&bp->image->version); in ptp_ocp_fb_board_init()
2208 bp->sma_op = &ocp_fb_sma_op; in ptp_ocp_fb_board_init()
2231 bool allow = !r->irq_vec || r->irq_vec < bp->n_irqs; in ptp_ocp_allow_irq()
2234 dev_err(&bp->pdev->dev, "irq %d out of range, skipping %s\n", in ptp_ocp_allow_irq()
2235 r->irq_vec, r->name); in ptp_ocp_allow_irq()
2246 for (r = table; r->setup; r++) { in ptp_ocp_register_resources()
2249 err = r->setup(bp, r); in ptp_ocp_register_resources()
2251 dev_err(&bp->pdev->dev, in ptp_ocp_register_resources()
2253 r->name, err); in ptp_ocp_register_resources()
2267 count = sysfs_emit(buf, "OUT: "); in ptp_ocp_show_output()
2295 count--; in ptp_ocp_show_inputs()
2310 return -ENOMEM; in sma_parse_inputs()
2312 ret = -EINVAL; in sma_parse_inputs()
2314 goto out; in sma_parse_inputs()
2322 if (!strcasecmp("OUT:", argv[0])) { in sma_parse_inputs()
2332 ret = -EINVAL; in sma_parse_inputs()
2334 out: in sma_parse_inputs()
2343 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; in ptp_ocp_sma_show()
2347 tbl = bp->sma_op->tbl; in ptp_ocp_sma_show()
2350 if (sma->mode == SMA_MODE_IN) { in ptp_ocp_sma_show()
2351 if (sma->disabled) in ptp_ocp_sma_show()
2372 return ptp_ocp_sma_show(bp, 2, buf, -1, 1); in sma2_show()
2380 return ptp_ocp_sma_show(bp, 3, buf, -1, 0); in sma3_show()
2388 return ptp_ocp_sma_show(bp, 4, buf, -1, 1); in sma4_show()
2394 struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1]; in ptp_ocp_sma_store()
2398 mode = sma->mode; in ptp_ocp_sma_store()
2399 val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode); in ptp_ocp_sma_store()
2403 if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) in ptp_ocp_sma_store()
2404 return -EOPNOTSUPP; in ptp_ocp_sma_store()
2406 if (sma->fixed_fcn) { in ptp_ocp_sma_store()
2407 if (val != sma->default_fcn) in ptp_ocp_sma_store()
2408 return -EOPNOTSUPP; in ptp_ocp_sma_store()
2412 sma->disabled = !!(val & SMA_DISABLE); in ptp_ocp_sma_store()
2414 if (mode != sma->mode) { in ptp_ocp_sma_store()
2419 sma->mode = mode; in ptp_ocp_sma_store()
2422 if (!sma->fixed_dir) in ptp_ocp_sma_store()
2425 if (sma->disabled) in ptp_ocp_sma_store()
2490 return ptp_ocp_select_table_show(bp->sma_op->tbl[0], buf); in available_sma_inputs_show()
2500 return ptp_ocp_select_table_show(bp->sma_op->tbl[1], buf); in available_sma_outputs_show()
2520 int gen = (uintptr_t)ea->var; in signal_store()
2526 return -ENOMEM; in signal_store()
2528 err = -EINVAL; in signal_store()
2529 s.duty = bp->signal[gen].duty; in signal_store()
2530 s.phase = bp->signal[gen].phase; in signal_store()
2531 s.period = bp->signal[gen].period; in signal_store()
2532 s.polarity = bp->signal[gen].polarity; in signal_store()
2536 argc--; in signal_store()
2539 goto out; in signal_store()
2542 argc--; in signal_store()
2545 goto out; in signal_store()
2548 argc--; in signal_store()
2551 goto out; in signal_store()
2554 argc--; in signal_store()
2557 goto out; in signal_store()
2560 goto out; in signal_store()
2565 goto out; in signal_store()
2567 err = ptp_ocp_signal_enable(bp->signal_out[gen], gen, s.period != 0); in signal_store()
2569 out: in signal_store()
2584 i = (uintptr_t)ea->var; in signal_show()
2585 signal = &bp->signal[i]; in signal_show()
2587 count = sysfs_emit(buf, "%llu %d %llu %d", signal->period, in signal_show()
2588 signal->duty, signal->phase, signal->polarity); in signal_show()
2590 ts = ktime_to_timespec64(signal->start); in signal_show()
2605 int i = (uintptr_t)ea->var; in duty_show()
2607 return sysfs_emit(buf, "%d\n", bp->signal[i].duty); in duty_show()
2619 int i = (uintptr_t)ea->var; in period_show()
2621 return sysfs_emit(buf, "%llu\n", bp->signal[i].period); in period_show()
2633 int i = (uintptr_t)ea->var; in phase_show()
2635 return sysfs_emit(buf, "%llu\n", bp->signal[i].phase); in phase_show()
2648 int i = (uintptr_t)ea->var; in polarity_show()
2650 return sysfs_emit(buf, "%d\n", bp->signal[i].polarity); in polarity_show()
2662 int i = (uintptr_t)ea->var; in running_show()
2664 return sysfs_emit(buf, "%d\n", bp->signal[i].running); in running_show()
2676 int i = (uintptr_t)ea->var; in start_show()
2679 ts = ktime_to_timespec64(bp->signal[i].start); in start_show()
2693 int idx = (uintptr_t)ea->var; in seconds_store()
2701 return -EINVAL; in seconds_store()
2706 iowrite32(val, &bp->freq_in[idx]->ctrl); in seconds_store()
2716 int idx = (uintptr_t)ea->var; in seconds_show()
2719 val = ioread32(&bp->freq_in[idx]->ctrl); in seconds_show()
2737 int idx = (uintptr_t)ea->var; in frequency_show()
2740 val = ioread32(&bp->freq_in[idx]->status); in frequency_show()
2759 if (!bp->has_eeprom_data) in serialnum_show()
2762 return sysfs_emit(buf, "%pM\n", bp->serial); in serialnum_show()
2772 if (bp->gnss_lost) in gnss_sync_show()
2773 ret = sysfs_emit(buf, "LOST @ %ptT\n", &bp->gnss_lost); in gnss_sync_show()
2787 return sysfs_emit(buf, "%d\n", bp->utc_tai_offset); in utc_tai_offset_show()
2815 return sysfs_emit(buf, "%d\n", bp->ts_window_adjust); in ts_window_adjust_show()
2831 bp->ts_window_adjust = val; in ts_window_adjust_store()
2843 val = ioread32(&bp->irig_out->ctrl); in irig_b_mode_show()
2863 return -EINVAL; in irig_b_mode_store()
2867 spin_lock_irqsave(&bp->lock, flags); in irig_b_mode_store()
2868 iowrite32(0, &bp->irig_out->ctrl); /* disable */ in irig_b_mode_store()
2869 iowrite32(reg, &bp->irig_out->ctrl); /* change mode */ in irig_b_mode_store()
2870 iowrite32(reg | IRIG_M_CTRL_ENABLE, &bp->irig_out->ctrl); in irig_b_mode_store()
2871 spin_unlock_irqrestore(&bp->lock, flags); in irig_b_mode_store()
2884 select = ioread32(&bp->reg->select); in clock_source_show()
2902 spin_lock_irqsave(&bp->lock, flags); in clock_source_store()
2903 iowrite32(val, &bp->reg->select); in clock_source_store()
2904 spin_unlock_irqrestore(&bp->lock, flags); in clock_source_store()
2926 val = ioread32(&bp->reg->status_drift); in clock_status_drift_show()
2927 res = (val & ~INT_MAX) ? -1 : 1; in clock_status_drift_show()
2941 val = ioread32(&bp->reg->status_offset); in clock_status_offset_show()
2942 res = (val & ~INT_MAX) ? -1 : 1; in clock_status_offset_show()
2956 val = ioread32(&bp->tod->adj_sec); in tod_correction_show()
2957 res = (val & ~INT_MAX) ? -1 : 1; in tod_correction_show()
2975 res *= -1; in tod_correction_store()
2980 spin_lock_irqsave(&bp->lock, flags); in tod_correction_store()
2981 iowrite32(val, &bp->tod->adj_sec); in tod_correction_store()
2982 spin_unlock_irqrestore(&bp->lock, flags); in tod_correction_store()
3075 if (bp->sma[i].mode != SMA_MODE_IN) in gpio_input_map()
3083 def = "----"; in gpio_input_map()
3093 strcpy(ans, "----"); in gpio_output_map()
3095 if (bp->sma[i].mode != SMA_MODE_OUT) in gpio_output_map()
3105 struct signal_reg __iomem *reg = bp->signal_out[nr]->mem; in _signal_summary_show()
3106 struct ptp_ocp_signal *signal = &bp->signal[nr]; in _signal_summary_show()
3114 on = signal->running; in _signal_summary_show()
3116 seq_printf(s, "%7s: %s, period:%llu duty:%d%% phase:%llu pol:%d", in _signal_summary_show()
3118 signal->period, signal->duty, signal->phase, in _signal_summary_show()
3119 signal->polarity); in _signal_summary_show()
3121 val = ioread32(®->enable); in _signal_summary_show()
3123 val = ioread32(®->status); in _signal_summary_show()
3126 seq_printf(s, " start:%llu\n", signal->start); in _signal_summary_show()
3141 val = ioread32(®->ctrl); in _frequency_summary_show()
3149 val = ioread32(®->status); in _frequency_summary_show()
3162 struct device *dev = s->private; in ptp_ocp_summary_show()
3175 return -ENOMEM; in ptp_ocp_summary_show()
3179 seq_printf(s, "%7s: /dev/ptp%d\n", "PTP", ptp_clock_index(bp->ptp)); in ptp_ocp_summary_show()
3180 if (bp->gnss_port != -1) in ptp_ocp_summary_show()
3181 seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS1", bp->gnss_port); in ptp_ocp_summary_show()
3182 if (bp->gnss2_port != -1) in ptp_ocp_summary_show()
3183 seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS2", bp->gnss2_port); in ptp_ocp_summary_show()
3184 if (bp->mac_port != -1) in ptp_ocp_summary_show()
3185 seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp->mac_port); in ptp_ocp_summary_show()
3186 if (bp->nmea_port != -1) in ptp_ocp_summary_show()
3187 seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp->nmea_port); in ptp_ocp_summary_show()
3190 if (bp->sma_map1) { in ptp_ocp_summary_show()
3193 reg = ioread32(&bp->sma_map1->gpio1); in ptp_ocp_summary_show()
3197 reg = ioread32(&bp->sma_map1->gpio2); in ptp_ocp_summary_show()
3201 reg = ioread32(&bp->sma_map2->gpio1); in ptp_ocp_summary_show()
3205 reg = ioread32(&bp->sma_map2->gpio2); in ptp_ocp_summary_show()
3226 if (bp->ts0) { in ptp_ocp_summary_show()
3227 ts_reg = bp->ts0->mem; in ptp_ocp_summary_show()
3228 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
3234 if (bp->ts1) { in ptp_ocp_summary_show()
3235 ts_reg = bp->ts1->mem; in ptp_ocp_summary_show()
3236 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
3242 if (bp->ts2) { in ptp_ocp_summary_show()
3243 ts_reg = bp->ts2->mem; in ptp_ocp_summary_show()
3244 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
3250 if (bp->ts3) { in ptp_ocp_summary_show()
3251 ts_reg = bp->ts3->mem; in ptp_ocp_summary_show()
3252 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
3258 if (bp->ts4) { in ptp_ocp_summary_show()
3259 ts_reg = bp->ts4->mem; in ptp_ocp_summary_show()
3260 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
3266 if (bp->pps) { in ptp_ocp_summary_show()
3267 ts_reg = bp->pps->mem; in ptp_ocp_summary_show()
3269 on = ioread32(&ts_reg->enable); in ptp_ocp_summary_show()
3270 map = !!(bp->pps_req_map & OCP_REQ_TIMESTAMP); in ptp_ocp_summary_show()
3274 map = !!(bp->pps_req_map & OCP_REQ_PPS); in ptp_ocp_summary_show()
3279 if (bp->fw_cap & OCP_CAP_SIGNAL) in ptp_ocp_summary_show()
3283 if (bp->fw_cap & OCP_CAP_FREQ) in ptp_ocp_summary_show()
3285 _frequency_summary_show(s, i, bp->freq_in[i]); in ptp_ocp_summary_show()
3287 if (bp->irig_out) { in ptp_ocp_summary_show()
3288 ctrl = ioread32(&bp->irig_out->ctrl); in ptp_ocp_summary_show()
3290 val = ioread32(&bp->irig_out->status); in ptp_ocp_summary_show()
3292 seq_printf(s, "%7s: %s, error: %d, mode %d, out: %s\n", "IRIG", in ptp_ocp_summary_show()
3296 if (bp->irig_in) { in ptp_ocp_summary_show()
3297 on = ioread32(&bp->irig_in->ctrl) & IRIG_S_CTRL_ENABLE; in ptp_ocp_summary_show()
3298 val = ioread32(&bp->irig_in->status); in ptp_ocp_summary_show()
3304 if (bp->dcf_out) { in ptp_ocp_summary_show()
3305 on = ioread32(&bp->dcf_out->ctrl) & DCF_M_CTRL_ENABLE; in ptp_ocp_summary_show()
3306 val = ioread32(&bp->dcf_out->status); in ptp_ocp_summary_show()
3308 seq_printf(s, "%7s: %s, error: %d, out: %s\n", "DCF", in ptp_ocp_summary_show()
3312 if (bp->dcf_in) { in ptp_ocp_summary_show()
3313 on = ioread32(&bp->dcf_in->ctrl) & DCF_S_CTRL_ENABLE; in ptp_ocp_summary_show()
3314 val = ioread32(&bp->dcf_in->status); in ptp_ocp_summary_show()
3320 if (bp->nmea_out) { in ptp_ocp_summary_show()
3321 on = ioread32(&bp->nmea_out->ctrl) & 1; in ptp_ocp_summary_show()
3322 val = ioread32(&bp->nmea_out->status); in ptp_ocp_summary_show()
3328 if (bp->pps_select) { in ptp_ocp_summary_show()
3329 val = ioread32(&bp->pps_select->gpio1); in ptp_ocp_summary_show()
3340 src = "----"; in ptp_ocp_summary_show()
3353 val = ioread32(&bp->reg->select); in ptp_ocp_summary_show()
3356 sprintf(buf, "----"); in ptp_ocp_summary_show()
3371 val = ioread32(&bp->reg->status); in ptp_ocp_summary_show()
3375 if (!ptp_ocp_gettimex(&bp->ptp_info, &ts, &sts)) { in ptp_ocp_summary_show()
3382 ns += (s64)bp->utc_tai_offset * NSEC_PER_SEC; in ptp_ocp_summary_show()
3389 bp->utc_tai_offset); in ptp_ocp_summary_show()
3391 timespec64_to_ns(&ts) - ns, in ptp_ocp_summary_show()
3392 post_ns - pre_ns); in ptp_ocp_summary_show()
3403 struct device *dev = s->private; in ptp_ocp_tod_status_show()
3410 val = ioread32(&bp->tod->ctrl); in ptp_ocp_tod_status_show()
3424 val = ioread32(&bp->tod->version); in ptp_ocp_tod_status_show()
3428 val = ioread32(&bp->tod->status); in ptp_ocp_tod_status_show()
3431 val = ioread32(&bp->tod->adj_sec); in ptp_ocp_tod_status_show()
3432 idx = (val & ~INT_MAX) ? -1 : 1; in ptp_ocp_tod_status_show()
3436 val = ioread32(&bp->tod->utc_status); in ptp_ocp_tod_status_show()
3444 val = ioread32(&bp->tod->leap); in ptp_ocp_tod_status_show()
3458 d = debugfs_create_dir(dev_name(&bp->dev), ptp_ocp_debugfs_root); in ptp_ocp_debugfs_add_device()
3459 bp->debug_root = d; in ptp_ocp_debugfs_add_device()
3460 debugfs_create_file("summary", 0444, bp->debug_root, in ptp_ocp_debugfs_add_device()
3461 &bp->dev, &ptp_ocp_summary_fops); in ptp_ocp_debugfs_add_device()
3462 if (bp->tod) in ptp_ocp_debugfs_add_device()
3463 debugfs_create_file("tod_status", 0444, bp->debug_root, in ptp_ocp_debugfs_add_device()
3464 &bp->dev, &ptp_ocp_tod_status_fops); in ptp_ocp_debugfs_add_device()
3470 debugfs_remove_recursive(bp->debug_root); in ptp_ocp_debugfs_remove_device()
3491 idr_remove(&ptp_ocp_idr, bp->id); in ptp_ocp_dev_release()
3504 dev_err(&pdev->dev, "idr_alloc failed: %d\n", err); in ptp_ocp_device_init()
3507 bp->id = err; in ptp_ocp_device_init()
3509 bp->ptp_info = ptp_ocp_clock_info; in ptp_ocp_device_init()
3510 spin_lock_init(&bp->lock); in ptp_ocp_device_init()
3511 bp->gnss_port = -1; in ptp_ocp_device_init()
3512 bp->gnss2_port = -1; in ptp_ocp_device_init()
3513 bp->mac_port = -1; in ptp_ocp_device_init()
3514 bp->nmea_port = -1; in ptp_ocp_device_init()
3515 bp->pdev = pdev; in ptp_ocp_device_init()
3517 device_initialize(&bp->dev); in ptp_ocp_device_init()
3518 dev_set_name(&bp->dev, "ocp%d", bp->id); in ptp_ocp_device_init()
3519 bp->dev.class = &timecard_class; in ptp_ocp_device_init()
3520 bp->dev.parent = &pdev->dev; in ptp_ocp_device_init()
3521 bp->dev.release = ptp_ocp_dev_release; in ptp_ocp_device_init()
3522 dev_set_drvdata(&bp->dev, bp); in ptp_ocp_device_init()
3524 err = device_add(&bp->dev); in ptp_ocp_device_init()
3526 dev_err(&bp->dev, "device add failed: %d\n", err); in ptp_ocp_device_init()
3527 goto out; in ptp_ocp_device_init()
3534 out: in ptp_ocp_device_init()
3535 ptp_ocp_dev_release(&bp->dev); in ptp_ocp_device_init()
3536 put_device(&bp->dev); in ptp_ocp_device_init()
3543 struct device *dev = &bp->dev; in ptp_ocp_symlink()
3545 if (sysfs_create_link(&dev->kobj, &child->kobj, link)) in ptp_ocp_symlink()
3554 dev = &bp->pdev->dev; in ptp_ocp_link_child()
3572 if (bp->gnss_port != -1) { in ptp_ocp_complete()
3573 sprintf(buf, "ttyS%d", bp->gnss_port); in ptp_ocp_complete()
3576 if (bp->gnss2_port != -1) { in ptp_ocp_complete()
3577 sprintf(buf, "ttyS%d", bp->gnss2_port); in ptp_ocp_complete()
3580 if (bp->mac_port != -1) { in ptp_ocp_complete()
3581 sprintf(buf, "ttyS%d", bp->mac_port); in ptp_ocp_complete()
3584 if (bp->nmea_port != -1) { in ptp_ocp_complete()
3585 sprintf(buf, "ttyS%d", bp->nmea_port); in ptp_ocp_complete()
3588 sprintf(buf, "ptp%d", ptp_clock_index(bp->ptp)); in ptp_ocp_complete()
3591 pps = pps_lookup_dev(bp->ptp); in ptp_ocp_complete()
3593 ptp_ocp_symlink(bp, pps->dev, "pps"); in ptp_ocp_complete()
3607 version = ioread32(&bp->reg->version); in ptp_ocp_phc_info()
3608 select = ioread32(&bp->reg->select); in ptp_ocp_phc_info()
3609 dev_info(&bp->pdev->dev, "Version %d.%d.%d, clock %s, device ptp%d\n", in ptp_ocp_phc_info()
3612 ptp_clock_index(bp->ptp)); in ptp_ocp_phc_info()
3614 sync = ioread32(&bp->reg->status) & OCP_STATUS_IN_SYNC; in ptp_ocp_phc_info()
3615 if (!ptp_ocp_gettimex(&bp->ptp_info, &ts, NULL)) in ptp_ocp_phc_info()
3616 dev_info(&bp->pdev->dev, "Time: %lld.%ld, %s\n", in ptp_ocp_phc_info()
3618 sync ? "in-sync" : "UNSYNCED"); in ptp_ocp_phc_info()
3624 if (port != -1) in ptp_ocp_serial_info()
3625 dev_info(dev, "%5s: /dev/ttyS%-2d @ %6d\n", name, port, baud); in ptp_ocp_serial_info()
3636 struct device *dev = &bp->pdev->dev; in ptp_ocp_info()
3641 ptp_ocp_serial_info(dev, "GNSS", bp->gnss_port, 115200); in ptp_ocp_info()
3642 ptp_ocp_serial_info(dev, "GNSS2", bp->gnss2_port, 115200); in ptp_ocp_info()
3643 ptp_ocp_serial_info(dev, "MAC", bp->mac_port, 57600); in ptp_ocp_info()
3644 if (bp->nmea_out && bp->nmea_port != -1) { in ptp_ocp_info()
3645 int baud = -1; in ptp_ocp_info()
3647 reg = ioread32(&bp->nmea_out->uart_baud); in ptp_ocp_info()
3650 ptp_ocp_serial_info(dev, "NMEA", bp->nmea_port, baud); in ptp_ocp_info()
3657 struct device *dev = &bp->dev; in ptp_ocp_detach_sysfs()
3659 sysfs_remove_link(&dev->kobj, "ttyGNSS"); in ptp_ocp_detach_sysfs()
3660 sysfs_remove_link(&dev->kobj, "ttyGNSS2"); in ptp_ocp_detach_sysfs()
3661 sysfs_remove_link(&dev->kobj, "ttyMAC"); in ptp_ocp_detach_sysfs()
3662 sysfs_remove_link(&dev->kobj, "ptp"); in ptp_ocp_detach_sysfs()
3663 sysfs_remove_link(&dev->kobj, "pps"); in ptp_ocp_detach_sysfs()
3674 if (timer_pending(&bp->watchdog)) in ptp_ocp_detach()
3675 del_timer_sync(&bp->watchdog); in ptp_ocp_detach()
3676 if (bp->ts0) in ptp_ocp_detach()
3677 ptp_ocp_unregister_ext(bp->ts0); in ptp_ocp_detach()
3678 if (bp->ts1) in ptp_ocp_detach()
3679 ptp_ocp_unregister_ext(bp->ts1); in ptp_ocp_detach()
3680 if (bp->ts2) in ptp_ocp_detach()
3681 ptp_ocp_unregister_ext(bp->ts2); in ptp_ocp_detach()
3682 if (bp->ts3) in ptp_ocp_detach()
3683 ptp_ocp_unregister_ext(bp->ts3); in ptp_ocp_detach()
3684 if (bp->ts4) in ptp_ocp_detach()
3685 ptp_ocp_unregister_ext(bp->ts4); in ptp_ocp_detach()
3686 if (bp->pps) in ptp_ocp_detach()
3687 ptp_ocp_unregister_ext(bp->pps); in ptp_ocp_detach()
3689 if (bp->signal_out[i]) in ptp_ocp_detach()
3690 ptp_ocp_unregister_ext(bp->signal_out[i]); in ptp_ocp_detach()
3691 if (bp->gnss_port != -1) in ptp_ocp_detach()
3692 serial8250_unregister_port(bp->gnss_port); in ptp_ocp_detach()
3693 if (bp->gnss2_port != -1) in ptp_ocp_detach()
3694 serial8250_unregister_port(bp->gnss2_port); in ptp_ocp_detach()
3695 if (bp->mac_port != -1) in ptp_ocp_detach()
3696 serial8250_unregister_port(bp->mac_port); in ptp_ocp_detach()
3697 if (bp->nmea_port != -1) in ptp_ocp_detach()
3698 serial8250_unregister_port(bp->nmea_port); in ptp_ocp_detach()
3699 platform_device_unregister(bp->spi_flash); in ptp_ocp_detach()
3700 platform_device_unregister(bp->i2c_ctrl); in ptp_ocp_detach()
3701 if (bp->i2c_clk) in ptp_ocp_detach()
3702 clk_hw_unregister_fixed_rate(bp->i2c_clk); in ptp_ocp_detach()
3703 if (bp->n_irqs) in ptp_ocp_detach()
3704 pci_free_irq_vectors(bp->pdev); in ptp_ocp_detach()
3705 if (bp->ptp) in ptp_ocp_detach()
3706 ptp_clock_unregister(bp->ptp); in ptp_ocp_detach()
3707 kfree(bp->ptp_info.pin_config); in ptp_ocp_detach()
3708 device_unregister(&bp->dev); in ptp_ocp_detach()
3718 devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); in ptp_ocp_probe()
3720 dev_err(&pdev->dev, "devlink_alloc failed\n"); in ptp_ocp_probe()
3721 return -ENOMEM; in ptp_ocp_probe()
3726 dev_err(&pdev->dev, "pci_enable_device\n"); in ptp_ocp_probe()
3737 * allow this - if not all of the IRQ's are returned, skip the in ptp_ocp_probe()
3742 dev_err(&pdev->dev, "alloc_irq_vectors err: %d\n", err); in ptp_ocp_probe()
3743 goto out; in ptp_ocp_probe()
3745 bp->n_irqs = err; in ptp_ocp_probe()
3748 err = ptp_ocp_register_resources(bp, id->driver_data); in ptp_ocp_probe()
3750 goto out; in ptp_ocp_probe()
3752 bp->ptp = ptp_clock_register(&bp->ptp_info, &pdev->dev); in ptp_ocp_probe()
3753 if (IS_ERR(bp->ptp)) { in ptp_ocp_probe()
3754 err = PTR_ERR(bp->ptp); in ptp_ocp_probe()
3755 dev_err(&pdev->dev, "ptp_clock_register: %d\n", err); in ptp_ocp_probe()
3756 bp->ptp = NULL; in ptp_ocp_probe()
3757 goto out; in ptp_ocp_probe()
3762 goto out; in ptp_ocp_probe()
3768 out: in ptp_ocp_probe()
3818 while ((dev = dev->parent)) in ptp_ocp_i2c_notifier_call()
3819 if (dev->driver && !strcmp(dev->driver->name, KBUILD_MODNAME)) in ptp_ocp_i2c_notifier_call()
3828 sysfs_remove_link(&bp->dev.kobj, "i2c"); in ptp_ocp_i2c_notifier_call()
3848 goto out; in ptp_ocp_init()
3866 out: in ptp_ocp_init()