2 * Broadcom SATA3 AHCI Controller PHY Driver
4 * Copyright © 2009-2015 Broadcom Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/device.h>
18 #include <linux/init.h>
19 #include <linux/interrupt.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include <linux/phy/phy.h>
25 #include <linux/platform_device.h>
27 #define SATA_MDIO_BANK_OFFSET 0x23c
28 #define SATA_MDIO_REG_OFFSET(ofs) ((ofs) * 4)
29 #define SATA_MDIO_REG_SPACE_SIZE 0x1000
30 #define SATA_MDIO_REG_LENGTH 0x1f00
34 /* Register offset between PHYs in PCB space */
35 #define SATA_MDIO_REG_SPACE_SIZE 0x1000
37 struct brcm_sata_port
{
40 struct brcm_sata_phy
*phy_priv
;
44 struct brcm_sata_phy
{
46 void __iomem
*phy_base
;
48 struct brcm_sata_port phys
[MAX_PORTS
];
51 enum sata_mdio_phy_regs_28nm
{
52 PLL_REG_BANK_0
= 0x50,
53 PLL_REG_BANK_0_PLLCONTROL_0
= 0x81,
55 TXPMD_REG_BANK
= 0x1a0,
56 TXPMD_CONTROL1
= 0x81,
57 TXPMD_CONTROL1_TX_SSC_EN_FRC
= BIT(0),
58 TXPMD_CONTROL1_TX_SSC_EN_FRC_VAL
= BIT(1),
59 TXPMD_TX_FREQ_CTRL_CONTROL1
= 0x82,
60 TXPMD_TX_FREQ_CTRL_CONTROL2
= 0x83,
61 TXPMD_TX_FREQ_CTRL_CONTROL2_FMIN_MASK
= 0x3ff,
62 TXPMD_TX_FREQ_CTRL_CONTROL3
= 0x84,
63 TXPMD_TX_FREQ_CTRL_CONTROL3_FMAX_MASK
= 0x3ff,
66 static inline void __iomem
*brcm_sata_phy_base(struct brcm_sata_port
*port
)
68 struct brcm_sata_phy
*priv
= port
->phy_priv
;
70 return priv
->phy_base
+ (port
->portnum
* SATA_MDIO_REG_SPACE_SIZE
);
73 static void brcm_sata_mdio_wr(void __iomem
*addr
, u32 bank
, u32 ofs
,
78 writel(bank
, addr
+ SATA_MDIO_BANK_OFFSET
);
79 tmp
= readl(addr
+ SATA_MDIO_REG_OFFSET(ofs
));
80 tmp
= (tmp
& msk
) | value
;
81 writel(tmp
, addr
+ SATA_MDIO_REG_OFFSET(ofs
));
84 /* These defaults were characterized by H/W group */
85 #define FMIN_VAL_DEFAULT 0x3df
86 #define FMAX_VAL_DEFAULT 0x3df
87 #define FMAX_VAL_SSC 0x83
89 static void brcm_sata_cfg_ssc_28nm(struct brcm_sata_port
*port
)
91 void __iomem
*base
= brcm_sata_phy_base(port
);
92 struct brcm_sata_phy
*priv
= port
->phy_priv
;
95 /* override the TX spread spectrum setting */
96 tmp
= TXPMD_CONTROL1_TX_SSC_EN_FRC_VAL
| TXPMD_CONTROL1_TX_SSC_EN_FRC
;
97 brcm_sata_mdio_wr(base
, TXPMD_REG_BANK
, TXPMD_CONTROL1
, ~tmp
, tmp
);
99 /* set fixed min freq */
100 brcm_sata_mdio_wr(base
, TXPMD_REG_BANK
, TXPMD_TX_FREQ_CTRL_CONTROL2
,
101 ~TXPMD_TX_FREQ_CTRL_CONTROL2_FMIN_MASK
,
104 /* set fixed max freq depending on SSC config */
106 dev_info(priv
->dev
, "enabling SSC on port %d\n", port
->portnum
);
109 tmp
= FMAX_VAL_DEFAULT
;
112 brcm_sata_mdio_wr(base
, TXPMD_REG_BANK
, TXPMD_TX_FREQ_CTRL_CONTROL3
,
113 ~TXPMD_TX_FREQ_CTRL_CONTROL3_FMAX_MASK
, tmp
);
116 static int brcm_sata_phy_init(struct phy
*phy
)
118 struct brcm_sata_port
*port
= phy_get_drvdata(phy
);
120 brcm_sata_cfg_ssc_28nm(port
);
125 static const struct phy_ops phy_ops_28nm
= {
126 .init
= brcm_sata_phy_init
,
127 .owner
= THIS_MODULE
,
130 static const struct of_device_id brcm_sata_phy_of_match
[] = {
131 { .compatible
= "brcm,bcm7445-sata-phy" },
134 MODULE_DEVICE_TABLE(of
, brcm_sata_phy_of_match
);
136 static int brcm_sata_phy_probe(struct platform_device
*pdev
)
138 struct device
*dev
= &pdev
->dev
;
139 struct device_node
*dn
= dev
->of_node
, *child
;
140 struct brcm_sata_phy
*priv
;
141 struct resource
*res
;
142 struct phy_provider
*provider
;
145 if (of_get_child_count(dn
) == 0)
148 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
151 dev_set_drvdata(dev
, priv
);
154 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "phy");
155 priv
->phy_base
= devm_ioremap_resource(dev
, res
);
156 if (IS_ERR(priv
->phy_base
))
157 return PTR_ERR(priv
->phy_base
);
159 for_each_available_child_of_node(dn
, child
) {
161 struct brcm_sata_port
*port
;
163 if (of_property_read_u32(child
, "reg", &id
)) {
164 dev_err(dev
, "missing reg property in node %s\n",
170 if (id
>= MAX_PORTS
) {
171 dev_err(dev
, "invalid reg: %u\n", id
);
175 if (priv
->phys
[id
].phy
) {
176 dev_err(dev
, "already registered port %u\n", id
);
181 port
= &priv
->phys
[id
];
183 port
->phy_priv
= priv
;
184 port
->phy
= devm_phy_create(dev
, child
, &phy_ops_28nm
);
185 port
->ssc_en
= of_property_read_bool(child
, "brcm,enable-ssc");
186 if (IS_ERR(port
->phy
)) {
187 dev_err(dev
, "failed to create PHY\n");
188 ret
= PTR_ERR(port
->phy
);
192 phy_set_drvdata(port
->phy
, port
);
196 provider
= devm_of_phy_provider_register(dev
, of_phy_simple_xlate
);
197 if (IS_ERR(provider
)) {
198 dev_err(dev
, "could not register PHY provider\n");
199 return PTR_ERR(provider
);
202 dev_info(dev
, "registered %d port(s)\n", count
);
210 static struct platform_driver brcm_sata_phy_driver
= {
211 .probe
= brcm_sata_phy_probe
,
213 .of_match_table
= brcm_sata_phy_of_match
,
214 .name
= "brcmstb-sata-phy",
217 module_platform_driver(brcm_sata_phy_driver
);
219 MODULE_DESCRIPTION("Broadcom STB SATA PHY driver");
220 MODULE_LICENSE("GPL");
221 MODULE_AUTHOR("Marc Carino");
222 MODULE_AUTHOR("Brian Norris");
223 MODULE_ALIAS("platform:phy-brcmstb-sata");