153d7776eSDmitry Baryshkov /* SPDX-License-Identifier: GPL-2.0 */
253d7776eSDmitry Baryshkov /*
353d7776eSDmitry Baryshkov * Copyright (c) 2017, The Linux Foundation. All rights reserved.
453d7776eSDmitry Baryshkov */
553d7776eSDmitry Baryshkov
653d7776eSDmitry Baryshkov #ifndef QCOM_PHY_QMP_COMMON_H_
753d7776eSDmitry Baryshkov #define QCOM_PHY_QMP_COMMON_H_
853d7776eSDmitry Baryshkov
953d7776eSDmitry Baryshkov struct qmp_phy_init_tbl {
1053d7776eSDmitry Baryshkov unsigned int offset;
1153d7776eSDmitry Baryshkov unsigned int val;
12*4e92d504SManivannan Sadhasivam char *name;
1353d7776eSDmitry Baryshkov /*
1453d7776eSDmitry Baryshkov * mask of lanes for which this register is written
1553d7776eSDmitry Baryshkov * for cases when second lane needs different values
1653d7776eSDmitry Baryshkov */
1753d7776eSDmitry Baryshkov u8 lane_mask;
1853d7776eSDmitry Baryshkov };
1953d7776eSDmitry Baryshkov
2053d7776eSDmitry Baryshkov #define QMP_PHY_INIT_CFG(o, v) \
2153d7776eSDmitry Baryshkov { \
2253d7776eSDmitry Baryshkov .offset = o, \
2353d7776eSDmitry Baryshkov .val = v, \
24*4e92d504SManivannan Sadhasivam .name = #o, \
2553d7776eSDmitry Baryshkov .lane_mask = 0xff, \
2653d7776eSDmitry Baryshkov }
2753d7776eSDmitry Baryshkov
2853d7776eSDmitry Baryshkov #define QMP_PHY_INIT_CFG_LANE(o, v, l) \
2953d7776eSDmitry Baryshkov { \
3053d7776eSDmitry Baryshkov .offset = o, \
3153d7776eSDmitry Baryshkov .val = v, \
32*4e92d504SManivannan Sadhasivam .name = #o, \
3353d7776eSDmitry Baryshkov .lane_mask = l, \
3453d7776eSDmitry Baryshkov }
3553d7776eSDmitry Baryshkov
qmp_configure_lane(struct device * dev,void __iomem * base,const struct qmp_phy_init_tbl tbl[],int num,u8 lane_mask)36*4e92d504SManivannan Sadhasivam static inline void qmp_configure_lane(struct device *dev, void __iomem *base,
3753d7776eSDmitry Baryshkov const struct qmp_phy_init_tbl tbl[],
38*4e92d504SManivannan Sadhasivam int num, u8 lane_mask)
3953d7776eSDmitry Baryshkov {
4053d7776eSDmitry Baryshkov int i;
4153d7776eSDmitry Baryshkov const struct qmp_phy_init_tbl *t = tbl;
4253d7776eSDmitry Baryshkov
4353d7776eSDmitry Baryshkov if (!t)
4453d7776eSDmitry Baryshkov return;
4553d7776eSDmitry Baryshkov
4653d7776eSDmitry Baryshkov for (i = 0; i < num; i++, t++) {
4753d7776eSDmitry Baryshkov if (!(t->lane_mask & lane_mask))
4853d7776eSDmitry Baryshkov continue;
4953d7776eSDmitry Baryshkov
50*4e92d504SManivannan Sadhasivam dev_dbg(dev, "Writing Reg: %s Offset: 0x%04x Val: 0x%02x\n",
51*4e92d504SManivannan Sadhasivam t->name, t->offset, t->val);
5253d7776eSDmitry Baryshkov writel(t->val, base + t->offset);
5353d7776eSDmitry Baryshkov }
5453d7776eSDmitry Baryshkov }
5553d7776eSDmitry Baryshkov
qmp_configure(struct device * dev,void __iomem * base,const struct qmp_phy_init_tbl tbl[],int num)56*4e92d504SManivannan Sadhasivam static inline void qmp_configure(struct device *dev, void __iomem *base,
57*4e92d504SManivannan Sadhasivam const struct qmp_phy_init_tbl tbl[], int num)
5853d7776eSDmitry Baryshkov {
59*4e92d504SManivannan Sadhasivam qmp_configure_lane(dev, base, tbl, num, 0xff);
6053d7776eSDmitry Baryshkov }
6153d7776eSDmitry Baryshkov
6253d7776eSDmitry Baryshkov #endif
63