Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright 2013-2016 Freescale Semiconductor Inc. |
| 4 | * Copyright 2016-2018 NXP |
| 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 8 | #include <linux/of.h> |
| 9 | #include <linux/of_address.h> |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 10 | #include <linux/fsl/mc.h> |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 11 | #include <linux/fsl/ptp_qoriq.h> |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 12 | |
Yangbo Lu | 0a006a2 | 2018-10-08 15:44:25 +0800 | [diff] [blame] | 13 | #include "dpaa2-ptp.h" |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 14 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 15 | static const struct ptp_clock_info dpaa2_ptp_caps = { |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 16 | .owner = THIS_MODULE, |
| 17 | .name = "DPAA2 PTP Clock", |
| 18 | .max_adj = 512000, |
| 19 | .n_alarm = 2, |
| 20 | .n_ext_ts = 2, |
| 21 | .n_per_out = 3, |
| 22 | .n_pins = 0, |
| 23 | .pps = 1, |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 24 | .adjfine = ptp_qoriq_adjfine, |
| 25 | .adjtime = ptp_qoriq_adjtime, |
| 26 | .gettime64 = ptp_qoriq_gettime, |
| 27 | .settime64 = ptp_qoriq_settime, |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 28 | }; |
| 29 | |
Yangbo Lu | 180f539 | 2018-10-08 15:44:28 +0800 | [diff] [blame] | 30 | static int dpaa2_ptp_probe(struct fsl_mc_device *mc_dev) |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 31 | { |
| 32 | struct device *dev = &mc_dev->dev; |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 33 | struct ptp_qoriq *ptp_qoriq; |
| 34 | struct device_node *node; |
| 35 | void __iomem *base; |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 36 | int err; |
| 37 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 38 | ptp_qoriq = devm_kzalloc(dev, sizeof(*ptp_qoriq), GFP_KERNEL); |
| 39 | if (!ptp_qoriq) |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 40 | return -ENOMEM; |
| 41 | |
| 42 | err = fsl_mc_portal_allocate(mc_dev, 0, &mc_dev->mc_io); |
| 43 | if (err) { |
Ioana Ciornei | 5500598 | 2018-11-09 15:26:46 +0000 | [diff] [blame] | 44 | if (err == -ENXIO) |
| 45 | err = -EPROBE_DEFER; |
| 46 | else |
| 47 | dev_err(dev, "fsl_mc_portal_allocate err %d\n", err); |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 48 | goto err_exit; |
| 49 | } |
| 50 | |
| 51 | err = dprtc_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id, |
| 52 | &mc_dev->mc_handle); |
| 53 | if (err) { |
| 54 | dev_err(dev, "dprtc_open err %d\n", err); |
| 55 | goto err_free_mcp; |
| 56 | } |
| 57 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 58 | ptp_qoriq->dev = dev; |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 59 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 60 | node = of_find_compatible_node(NULL, NULL, "fsl,dpaa2-ptp"); |
| 61 | if (!node) { |
| 62 | err = -ENODEV; |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 63 | goto err_close; |
| 64 | } |
| 65 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 66 | dev->of_node = node; |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 67 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 68 | base = of_iomap(node, 0); |
| 69 | if (!base) { |
| 70 | err = -ENOMEM; |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 71 | goto err_close; |
| 72 | } |
| 73 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 74 | err = ptp_qoriq_init(ptp_qoriq, base, &dpaa2_ptp_caps); |
| 75 | if (err) |
| 76 | goto err_unmap; |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 77 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 78 | dpaa2_phc_index = ptp_qoriq->phc_index; |
| 79 | dev_set_drvdata(dev, ptp_qoriq); |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 80 | |
| 81 | return 0; |
| 82 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 83 | err_unmap: |
| 84 | iounmap(base); |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 85 | err_close: |
| 86 | dprtc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); |
| 87 | err_free_mcp: |
| 88 | fsl_mc_portal_free(mc_dev->mc_io); |
| 89 | err_exit: |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 90 | return err; |
| 91 | } |
| 92 | |
Yangbo Lu | 180f539 | 2018-10-08 15:44:28 +0800 | [diff] [blame] | 93 | static int dpaa2_ptp_remove(struct fsl_mc_device *mc_dev) |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 94 | { |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 95 | struct device *dev = &mc_dev->dev; |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 96 | struct ptp_qoriq *ptp_qoriq; |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 97 | |
Yangbo Lu | d346c9e | 2019-06-14 18:40:51 +0800 | [diff] [blame^] | 98 | ptp_qoriq = dev_get_drvdata(dev); |
| 99 | |
| 100 | dpaa2_phc_index = -1; |
| 101 | ptp_qoriq_free(ptp_qoriq); |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 102 | |
| 103 | dprtc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); |
| 104 | fsl_mc_portal_free(mc_dev->mc_io); |
| 105 | |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
Yangbo Lu | 180f539 | 2018-10-08 15:44:28 +0800 | [diff] [blame] | 109 | static const struct fsl_mc_device_id dpaa2_ptp_match_id_table[] = { |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 110 | { |
| 111 | .vendor = FSL_MC_VENDOR_FREESCALE, |
| 112 | .obj_type = "dprtc", |
| 113 | }, |
| 114 | {} |
| 115 | }; |
Yangbo Lu | 180f539 | 2018-10-08 15:44:28 +0800 | [diff] [blame] | 116 | MODULE_DEVICE_TABLE(fslmc, dpaa2_ptp_match_id_table); |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 117 | |
Yangbo Lu | 180f539 | 2018-10-08 15:44:28 +0800 | [diff] [blame] | 118 | static struct fsl_mc_driver dpaa2_ptp_drv = { |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 119 | .driver = { |
| 120 | .name = KBUILD_MODNAME, |
| 121 | .owner = THIS_MODULE, |
| 122 | }, |
Yangbo Lu | 180f539 | 2018-10-08 15:44:28 +0800 | [diff] [blame] | 123 | .probe = dpaa2_ptp_probe, |
| 124 | .remove = dpaa2_ptp_remove, |
| 125 | .match_id_table = dpaa2_ptp_match_id_table, |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 126 | }; |
| 127 | |
Yangbo Lu | 180f539 | 2018-10-08 15:44:28 +0800 | [diff] [blame] | 128 | module_fsl_mc_driver(dpaa2_ptp_drv); |
Yangbo Lu | 9bdf43b | 2018-04-23 11:55:00 +0800 | [diff] [blame] | 129 | |
| 130 | MODULE_LICENSE("GPL v2"); |
| 131 | MODULE_DESCRIPTION("DPAA2 PTP Clock Driver"); |