Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptp_qoriq: add little enadian support

There is QorIQ 1588 timer IP block on the new ENETC Ethernet
controller. However it uses little endian mode which is different
with before. This patch is to add little endian support for the
driver by using "little-endian" dts node property.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Yangbo Lu and committed by
David S. Miller
f038ddf2 ff54571a

+60 -42
+39 -30
drivers/ptp/ptp_qoriq.c
··· 43 43 u64 ns; 44 44 u32 lo, hi; 45 45 46 - lo = qoriq_read(&regs->ctrl_regs->tmr_cnt_l); 47 - hi = qoriq_read(&regs->ctrl_regs->tmr_cnt_h); 46 + lo = ptp_qoriq->read(&regs->ctrl_regs->tmr_cnt_l); 47 + hi = ptp_qoriq->read(&regs->ctrl_regs->tmr_cnt_h); 48 48 ns = ((u64) hi) << 32; 49 49 ns |= lo; 50 50 return ns; ··· 57 57 u32 hi = ns >> 32; 58 58 u32 lo = ns & 0xffffffff; 59 59 60 - qoriq_write(&regs->ctrl_regs->tmr_cnt_l, lo); 61 - qoriq_write(&regs->ctrl_regs->tmr_cnt_h, hi); 60 + ptp_qoriq->write(&regs->ctrl_regs->tmr_cnt_l, lo); 61 + ptp_qoriq->write(&regs->ctrl_regs->tmr_cnt_h, hi); 62 62 } 63 63 64 64 /* Caller must hold ptp_qoriq->lock. */ ··· 73 73 ns -= ptp_qoriq->tclk_period; 74 74 hi = ns >> 32; 75 75 lo = ns & 0xffffffff; 76 - qoriq_write(&regs->alarm_regs->tmr_alarm1_l, lo); 77 - qoriq_write(&regs->alarm_regs->tmr_alarm1_h, hi); 76 + ptp_qoriq->write(&regs->alarm_regs->tmr_alarm1_l, lo); 77 + ptp_qoriq->write(&regs->alarm_regs->tmr_alarm1_h, hi); 78 78 } 79 79 80 80 /* Caller must hold ptp_qoriq->lock. */ ··· 83 83 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 84 84 85 85 set_alarm(ptp_qoriq); 86 - qoriq_write(&regs->fiper_regs->tmr_fiper1, ptp_qoriq->tmr_fiper1); 87 - qoriq_write(&regs->fiper_regs->tmr_fiper2, ptp_qoriq->tmr_fiper2); 86 + ptp_qoriq->write(&regs->fiper_regs->tmr_fiper1, ptp_qoriq->tmr_fiper1); 87 + ptp_qoriq->write(&regs->fiper_regs->tmr_fiper2, ptp_qoriq->tmr_fiper2); 88 88 } 89 89 90 90 static int extts_clean_up(struct ptp_qoriq *ptp_qoriq, int index, ··· 115 115 event.index = index; 116 116 117 117 do { 118 - lo = qoriq_read(reg_etts_l); 119 - hi = qoriq_read(reg_etts_h); 118 + lo = ptp_qoriq->read(reg_etts_l); 119 + hi = ptp_qoriq->read(reg_etts_h); 120 120 121 121 if (update_event) { 122 122 event.timestamp = ((u64) hi) << 32; ··· 124 124 ptp_clock_event(ptp_qoriq->clock, &event); 125 125 } 126 126 127 - stat = qoriq_read(&regs->ctrl_regs->tmr_stat); 127 + stat = ptp_qoriq->read(&regs->ctrl_regs->tmr_stat); 128 128 } while (ptp_qoriq->extts_fifo_support && (stat & valid)); 129 129 130 130 return 0; ··· 144 144 145 145 spin_lock(&ptp_qoriq->lock); 146 146 147 - val = qoriq_read(&regs->ctrl_regs->tmr_tevent); 148 - mask = qoriq_read(&regs->ctrl_regs->tmr_temask); 147 + val = ptp_qoriq->read(&regs->ctrl_regs->tmr_tevent); 148 + mask = ptp_qoriq->read(&regs->ctrl_regs->tmr_temask); 149 149 150 150 spin_unlock(&ptp_qoriq->lock); 151 151 ··· 173 173 ns = ptp_qoriq->alarm_value + ptp_qoriq->alarm_interval; 174 174 hi = ns >> 32; 175 175 lo = ns & 0xffffffff; 176 - qoriq_write(&regs->alarm_regs->tmr_alarm2_l, lo); 177 - qoriq_write(&regs->alarm_regs->tmr_alarm2_h, hi); 176 + ptp_qoriq->write(&regs->alarm_regs->tmr_alarm2_l, lo); 177 + ptp_qoriq->write(&regs->alarm_regs->tmr_alarm2_h, hi); 178 178 ptp_qoriq->alarm_value = ns; 179 179 } else { 180 180 spin_lock(&ptp_qoriq->lock); 181 - mask = qoriq_read(&regs->ctrl_regs->tmr_temask); 181 + mask = ptp_qoriq->read(&regs->ctrl_regs->tmr_temask); 182 182 mask &= ~ALM2EN; 183 - qoriq_write(&regs->ctrl_regs->tmr_temask, mask); 183 + ptp_qoriq->write(&regs->ctrl_regs->tmr_temask, mask); 184 184 spin_unlock(&ptp_qoriq->lock); 185 185 ptp_qoriq->alarm_value = 0; 186 186 ptp_qoriq->alarm_interval = 0; ··· 194 194 } 195 195 196 196 if (ack) { 197 - qoriq_write(&regs->ctrl_regs->tmr_tevent, ack); 197 + ptp_qoriq->write(&regs->ctrl_regs->tmr_tevent, ack); 198 198 return IRQ_HANDLED; 199 199 } else 200 200 return IRQ_NONE; ··· 229 229 230 230 tmr_add = neg_adj ? tmr_add - diff : tmr_add + diff; 231 231 232 - qoriq_write(&regs->ctrl_regs->tmr_add, tmr_add); 232 + ptp_qoriq->write(&regs->ctrl_regs->tmr_add, tmr_add); 233 233 234 234 return 0; 235 235 } ··· 326 326 327 327 spin_lock_irqsave(&ptp_qoriq->lock, flags); 328 328 329 - mask = qoriq_read(&regs->ctrl_regs->tmr_temask); 329 + mask = ptp_qoriq->read(&regs->ctrl_regs->tmr_temask); 330 330 if (on) { 331 331 mask |= bit; 332 - qoriq_write(&regs->ctrl_regs->tmr_tevent, bit); 332 + ptp_qoriq->write(&regs->ctrl_regs->tmr_tevent, bit); 333 333 } else { 334 334 mask &= ~bit; 335 335 } 336 336 337 - qoriq_write(&regs->ctrl_regs->tmr_temask, mask); 337 + ptp_qoriq->write(&regs->ctrl_regs->tmr_temask, mask); 338 338 339 339 spin_unlock_irqrestore(&ptp_qoriq->lock, flags); 340 340 return 0; ··· 496 496 return -ENODEV; 497 497 } 498 498 499 + if (of_property_read_bool(node, "little-endian")) { 500 + ptp_qoriq->read = qoriq_read_le; 501 + ptp_qoriq->write = qoriq_write_le; 502 + } else { 503 + ptp_qoriq->read = qoriq_read_be; 504 + ptp_qoriq->write = qoriq_write_be; 505 + } 506 + 499 507 if (of_device_is_compatible(node, "fsl,fman-ptp-timer")) { 500 508 ptp_qoriq->regs.ctrl_regs = base + FMAN_CTRL_REGS_OFFSET; 501 509 ptp_qoriq->regs.alarm_regs = base + FMAN_ALARM_REGS_OFFSET; ··· 527 519 spin_lock_irqsave(&ptp_qoriq->lock, flags); 528 520 529 521 regs = &ptp_qoriq->regs; 530 - qoriq_write(&regs->ctrl_regs->tmr_ctrl, tmr_ctrl); 531 - qoriq_write(&regs->ctrl_regs->tmr_add, ptp_qoriq->tmr_add); 532 - qoriq_write(&regs->ctrl_regs->tmr_prsc, ptp_qoriq->tmr_prsc); 533 - qoriq_write(&regs->fiper_regs->tmr_fiper1, ptp_qoriq->tmr_fiper1); 534 - qoriq_write(&regs->fiper_regs->tmr_fiper2, ptp_qoriq->tmr_fiper2); 522 + ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, tmr_ctrl); 523 + ptp_qoriq->write(&regs->ctrl_regs->tmr_add, ptp_qoriq->tmr_add); 524 + ptp_qoriq->write(&regs->ctrl_regs->tmr_prsc, ptp_qoriq->tmr_prsc); 525 + ptp_qoriq->write(&regs->fiper_regs->tmr_fiper1, ptp_qoriq->tmr_fiper1); 526 + ptp_qoriq->write(&regs->fiper_regs->tmr_fiper2, ptp_qoriq->tmr_fiper2); 535 527 set_alarm(ptp_qoriq); 536 - qoriq_write(&regs->ctrl_regs->tmr_ctrl, tmr_ctrl|FIPERST|RTPE|TE|FRD); 528 + ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, 529 + tmr_ctrl|FIPERST|RTPE|TE|FRD); 537 530 538 531 spin_unlock_irqrestore(&ptp_qoriq->lock, flags); 539 532 ··· 552 543 { 553 544 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 554 545 555 - qoriq_write(&regs->ctrl_regs->tmr_temask, 0); 556 - qoriq_write(&regs->ctrl_regs->tmr_ctrl, 0); 546 + ptp_qoriq->write(&regs->ctrl_regs->tmr_temask, 0); 547 + ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, 0); 557 548 558 549 ptp_qoriq_remove_debugfs(ptp_qoriq); 559 550 ptp_clock_unregister(ptp_qoriq->clock);
+6 -6
drivers/ptp/ptp_qoriq_debugfs.c
··· 11 11 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 12 12 u32 ctrl; 13 13 14 - ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl); 14 + ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl); 15 15 *val = ctrl & PP1L ? 1 : 0; 16 16 17 17 return 0; ··· 23 23 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 24 24 u32 ctrl; 25 25 26 - ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl); 26 + ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl); 27 27 if (val == 0) 28 28 ctrl &= ~PP1L; 29 29 else 30 30 ctrl |= PP1L; 31 31 32 - qoriq_write(&regs->ctrl_regs->tmr_ctrl, ctrl); 32 + ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl); 33 33 return 0; 34 34 } 35 35 ··· 42 42 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 43 43 u32 ctrl; 44 44 45 - ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl); 45 + ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl); 46 46 *val = ctrl & PP2L ? 1 : 0; 47 47 48 48 return 0; ··· 54 54 struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 55 55 u32 ctrl; 56 56 57 - ctrl = qoriq_read(&regs->ctrl_regs->tmr_ctrl); 57 + ctrl = ptp_qoriq->read(&regs->ctrl_regs->tmr_ctrl); 58 58 if (val == 0) 59 59 ctrl &= ~PP2L; 60 60 else 61 61 ctrl |= PP2L; 62 62 63 - qoriq_write(&regs->ctrl_regs->tmr_ctrl, ctrl); 63 + ptp_qoriq->write(&regs->ctrl_regs->tmr_ctrl, ctrl); 64 64 return 0; 65 65 } 66 66
+15 -6
include/linux/fsl/ptp_qoriq.h
··· 157 157 u32 cksel; 158 158 u32 tmr_fiper1; 159 159 u32 tmr_fiper2; 160 + u32 (*read)(unsigned __iomem *addr); 161 + void (*write)(unsigned __iomem *addr, u32 val); 160 162 }; 161 163 162 - static inline u32 qoriq_read(unsigned __iomem *addr) 164 + static inline u32 qoriq_read_be(unsigned __iomem *addr) 163 165 { 164 - u32 val; 165 - 166 - val = ioread32be(addr); 167 - return val; 166 + return ioread32be(addr); 168 167 } 169 168 170 - static inline void qoriq_write(unsigned __iomem *addr, u32 val) 169 + static inline void qoriq_write_be(unsigned __iomem *addr, u32 val) 171 170 { 172 171 iowrite32be(val, addr); 172 + } 173 + 174 + static inline u32 qoriq_read_le(unsigned __iomem *addr) 175 + { 176 + return ioread32(addr); 177 + } 178 + 179 + static inline void qoriq_write_le(unsigned __iomem *addr, u32 val) 180 + { 181 + iowrite32(val, addr); 173 182 } 174 183 175 184 irqreturn_t ptp_qoriq_isr(int irq, void *priv);