On Fri, Dec 20, 2019 at 03:28:28PM +0800, Dilip Kota wrote:Yes, but i think not required to add explicitly.
Combo phy subsystem provides PHYs for various...
controllers like PCIe, SATA and EMAC.
+#define REG_COMBO_MODE(x) ((x) * 0x200)Perhaps + 0x000
Ok, will correct it to rates.
+#define REG_CLK_DISABLE(x) ((x) * 0x200 + 0x124)...
+static const char *const intel_iphy_names[] = {"pcie", "xpcs", "sata"};names (note S)
+static const unsigned long intel_iphy_clk_rate[] = {
rate -> rates
For debug purpose only... can be removed in upstream. I will clean it up in next patch version.
+ CLK_100MHZ, CLK_156_25MHZ, CLK_100MHZ...
+};
+static ssize_t intel_cbphy_info_show(struct device *dev,Can't you do
+ struct device_attribute *attr, char *buf)
+{
+ struct intel_combo_phy *cbphy;
+ int i, off;
+
+ cbphy = dev_get_drvdata(dev);
+
+ off = sprintf(buf, "mode: %u\n", cbphy->mode);
+
+ off += sprintf(buf + off, "aggr mode: %s\n",
+ cbphy->aggr_mode == PHY_DL_MODE ? "Yes" : "No");
static inline const char *yesno(bool choice)
{
return choice ? "Yes" : "No";
}
and use it here and below?
Somebody already shared the idea that the above helper should be available
globally.
+...
+ off += sprintf(buf + off, "capability: ");
+ for (i = PHY_PCIE_MODE; i < PHY_MAX_MODE; i++) {
+ if (BIT(i) & cbphy->phy_cap)
+ off += sprintf(buf + off, "%s ", intel_iphy_names[i]);
+ }
+
+ off += sprintf(buf + off, "\n");
+
+ for (i = 0; i < PHY_MAX_NUM; i++) {
+ off += sprintf(buf + off, "PHY%d mode: %s, enable: %s\n",
+ i, intel_iphy_names[cbphy->iphy[i].phy_mode],
+ cbphy->iphy[i].enable ? "Yes" : "No");
+ }
+
+ return off;
+}
+static struct attribute *intel_cbphy_attrs[] = {Comma is redundant for terminator lines.
+ &dev_attr_intel_cbphy_info.attr,
+ NULL,
+};
+static int intel_cbphy_sysfs_init(struct intel_combo_phy *cbphy)What the point?
+{
+ return devm_device_add_groups(cbphy->dev, intel_cbphy_groups);
+}
Moreover, can't you use .dev_groups member of struct device_driver?Sure, will fix at all the places.
...
+ ret = phy_cfg(sphy);In several places you have extra unneeded white spaces.
...
+ combo_phy_w32_off_mask(iphy->app_base, PCIE_PHY_CLK_PAD,Configure your editor properly! There is plenty of room on the previous line.
+ 0, PCIE_PHY_GEN_CTRL);
Sure, will fix it.
...
+ combo_phy_w32_off_mask(iphy->app_base, PCIE_PHY_CLK_PAD,Ditto.
+ 1, PCIE_PHY_GEN_CTRL);
...
+static int intel_cbphy_init(struct phy *phy)
+{
+ struct intel_cbphy_iphy *iphy;
+ int ret = 0;Redundant assignment. See below.
Looks good, i will update.
+Why not to simple do
+ iphy = phy_get_drvdata(phy);
+
+ if (iphy->phy_mode == PHY_PCIE_MODE) {
+ ret = intel_cbphy_iphy_cfg(iphy,
+ intel_cbphy_pcie_en_pad_refclk);
+ }
+
+ if (!ret)
+ ret = intel_cbphy_iphy_cfg(iphy, intel_cbphy_iphy_power_on);
+
+ return ret;
if (A) {
ret = ...;
if (ret)
return ret;
}
return intel_...;
Ok
?
+}Ditto.
+
+static int intel_cbphy_exit(struct phy *phy)
+{
+ struct intel_cbphy_iphy *iphy;
+ int ret = 0;
+
+ iphy = phy_get_drvdata(phy);
+
+ if (iphy->power_en)
+ ret = intel_cbphy_iphy_cfg(iphy, intel_cbphy_iphy_power_off);
+
+ if (!ret && iphy->phy_mode == PHY_PCIE_MODE)
+ ret = intel_cbphy_iphy_cfg(iphy,
+ intel_cbphy_pcie_dis_pad_refclk);
+
+ return ret;
Defined as separate function for traversing memory entry from DT.
+}...
+static int intel_cbphy_iphy_mem_resource(struct intel_cbphy_iphy *iphy)What's the point of this helper?
+{
+ void __iomem *base;
+
+ base = devm_platform_ioremap_resource(iphy->pdev, 0);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ iphy->app_base = base;
+
+ return 0;
+}
Ok, i will fix at all the places.
...
+static int intel_cbphy_iphy_get_clks(struct intel_cbphy_iphy *iphy)Redundant. Simple return 0 explicitly at the end.
+{
+ enum intel_phy_mode mode = iphy->phy_mode;
+ struct device *dev = iphy->dev;
+ int ret = 0;
Ditto for other places in this patch.
Sure, i will replace it.
+ if (IS_ERR(iphy->freq_clk)) {...
+ ret = PTR_ERR(iphy->freq_clk);
+ if (ret != -EPROBE_DEFER) {
+ dev_err(dev, "PHY[%u:%u] No %s freq clock\n",
+ COMBO_PHY_ID(iphy), PHY_ID(iphy),
+ intel_iphy_names[mode]);
+ }
+
+ return ret;
+ }
+
+ iphy->clk_rate = intel_iphy_clk_rate[mode];
+
+ return ret;
+}
+static int intel_cbphy_iphy_dt_parse(struct intel_combo_phy *cbphy,fwn -> fwnode.
+ struct fwnode_handle *fwn, int idx)
There is no direct helper function to get platform device from fwnode,
+{Why? Can't it be done simpler?
+ struct intel_cbphy_iphy *iphy = &cbphy->iphy[idx];
+ struct platform_device *pdev;
+ struct device *dev;
+ int ret = 0;
+ u32 prop;
+
+ iphy->id = idx;
+ iphy->enable = false;
+ iphy->power_en = false;
+ iphy->parent = cbphy;
+ iphy->np = to_of_node(fwn);
+ pdev = of_find_device_by_node(iphy->np);
+ if (!pdev) {Yoda style?
+ dev_warn(cbphy->dev, "Combo-PHY%u: PHY device: %d disabled!\n",
+ cbphy->id, idx);
+ return 0;
+ }
+ if (!(BIT(iphy->phy_mode) & cbphy->phy_cap)) {
Sure, i will fix it.
...
+ " Mode mismatch lane0 : %u, lane1 : %u\n",Extra leading space.
Used during syscon_regmap call.
...
+static int intel_cbphy_dt_parse(struct intel_combo_phy *cbphy)Why do you need this one? You have to device if it's OF centric driver or not.
+{
+ struct device *dev = cbphy->dev;
+ struct device_node *np = dev->of_node;
Sure will fix it.
+ struct fwnode_handle *fwn;Better name is fwnode as done in plenty other drivers.
Sure, will fix it.
+ int i = 0, ret = 0;i = 0 better to have near to its user.
ret = 0 is redundant assignment.
Sure, will add it.
+ ret = device_property_read_u32(dev, "intel,bid", &cbphy->bid);...
+ if (ret) {
+ dev_err(dev, "NO intel,bid provided!\n");
+ return ret;
+ }
+
+ device_for_each_child_node(dev, fwn) {
+ if (i >= PHY_MAX_NUM) {
+ fwnode_handle_put(fwn);
+ dev_err(dev, "Error: DT child number larger than %d\n",
+ PHY_MAX_NUM);
+ return -EINVAL;
+ }
+
+ ret = intel_cbphy_iphy_dt_parse(cbphy, fwn, i);
+ if (ret) {
+ fwnode_handle_put(fwn);
+ return ret;
+ }
+
+ i++;
+ }
+
+ return intel_cbphy_dt_sanity_check(cbphy);
+}
+ regmap_write(cbphy->hsiocfg, REG_COMBO_MODE(cbphy->bid), cb_mode);No error check?
I will update it.
+...
+ return 0;
+ phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);return PTR_ERR_OR_ZERO(...);
+ if (IS_ERR(phy_provider)) {
+ dev_err(dev, "PHY[%u:%u]: register phy provider failed!\n",
+ COMBO_PHY_ID(iphy), PHY_ID(iphy));
+ return PTR_ERR(phy_provider);
+ }
+
+ return 0;
...
+ ret = of_property_read_u32(dev->of_node, "cell-index", &id);You should decide either you go with OF centric API(s) or with device property
one as below.
Sure, will update it.
+ if (!device_property_read_bool(dev, "intel,cap-pcie-only"))...
+ cbphy->phy_cap |= PHY_XPCS_CAP | PHY_SATA_CAP;
+ ret = intel_cbphy_sysfs_init(cbphy);return intel_...();
+
+ return ret;
...
+static struct platform_driver intel_cbphy_driver = {Can we unbound it? Is it okay to do unbind/bind cycle? Had it been tested for
+ .probe = intel_cbphy_probe,
+ .driver = {
+ .name = "intel-combo-phy",
+ .of_match_table = of_intel_cbphy_match,
+ }
+};
+
+builtin_platform_driver(intel_cbphy_driver);
that?