Commit 16604a3c authored by Fabio Baltieri's avatar Fabio Baltieri Committed by Felipe Balbi

usb: phy: ab8500-usb: move phy tuning values on separate functions

Move each chip's PHY tuning value set code to a separate function to
improve code readability.
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarMaxime Coquelin <maxime.coquelin@st.com>
Signed-off-by: default avatarFabio Baltieri <fabio.baltieri@linaro.org>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent b3affc39
...@@ -771,72 +771,10 @@ static int ab8500_usb_irq_setup(struct platform_device *pdev, ...@@ -771,72 +771,10 @@ static int ab8500_usb_irq_setup(struct platform_device *pdev,
return 0; return 0;
} }
static int ab8500_usb_probe(struct platform_device *pdev) static void ab8500_usb_set_ab8500_tuning_values(struct ab8500_usb *ab)
{ {
struct ab8500_usb *ab;
struct ab8500 *ab8500;
struct usb_otg *otg;
int err; int err;
int rev;
ab8500 = dev_get_drvdata(pdev->dev.parent);
rev = abx500_get_chip_id(&pdev->dev);
if (is_ab8500_1p1_or_earlier(ab8500)) {
dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev);
return -ENODEV;
}
ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL);
if (!ab)
return -ENOMEM;
otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
if (!otg)
return -ENOMEM;
ab->dev = &pdev->dev;
ab->ab8500 = ab8500;
ab->phy.dev = ab->dev;
ab->phy.otg = otg;
ab->phy.label = "ab8500";
ab->phy.set_suspend = ab8500_usb_set_suspend;
ab->phy.set_power = ab8500_usb_set_power;
ab->phy.state = OTG_STATE_UNDEFINED;
otg->phy = &ab->phy;
otg->set_host = ab8500_usb_set_host;
otg->set_peripheral = ab8500_usb_set_peripheral;
platform_set_drvdata(pdev, ab);
ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
/* all: Disable phy when called from set_host and set_peripheral */
INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
err = ab8500_usb_regulator_get(ab);
if (err)
return err;
ab->sysclk = devm_clk_get(ab->dev, "sysclk");
if (IS_ERR(ab->sysclk)) {
dev_err(ab->dev, "Could not get sysclk.\n");
return PTR_ERR(ab->sysclk);
}
err = ab8500_usb_irq_setup(pdev, ab);
if (err < 0)
return err;
err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
if (err) {
dev_err(&pdev->dev, "Can't register transceiver\n");
return err;
}
/* Phy tuning values for AB8500 > v2.0 */
if (is_ab8500(ab->ab8500) && !is_ab8500_2p0_or_earlier(ab->ab8500)) {
/* Enable the PBT/Bank 0x12 access */ /* Enable the PBT/Bank 0x12 access */
err = abx500_set_register_interruptible(ab->dev, err = abx500_set_register_interruptible(ab->dev,
AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01); AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01);
...@@ -868,10 +806,12 @@ static int ab8500_usb_probe(struct platform_device *pdev) ...@@ -868,10 +806,12 @@ static int ab8500_usb_probe(struct platform_device *pdev)
if (err < 0) if (err < 0)
dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
err); err);
} }
static void ab8500_usb_set_ab8505_tuning_values(struct ab8500_usb *ab)
{
int err;
/* Phy tuning values for AB8505 */
if (is_ab8505(ab->ab8500)) {
/* Enable the PBT/Bank 0x12 access */ /* Enable the PBT/Bank 0x12 access */
err = abx500_mask_and_set_register_interruptible(ab->dev, err = abx500_mask_and_set_register_interruptible(ab->dev,
AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
...@@ -909,8 +849,79 @@ static int ab8500_usb_probe(struct platform_device *pdev) ...@@ -909,8 +849,79 @@ static int ab8500_usb_probe(struct platform_device *pdev)
if (err < 0) if (err < 0)
dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
err); err);
}
static int ab8500_usb_probe(struct platform_device *pdev)
{
struct ab8500_usb *ab;
struct ab8500 *ab8500;
struct usb_otg *otg;
int err;
int rev;
ab8500 = dev_get_drvdata(pdev->dev.parent);
rev = abx500_get_chip_id(&pdev->dev);
if (is_ab8500_1p1_or_earlier(ab8500)) {
dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev);
return -ENODEV;
} }
ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL);
if (!ab)
return -ENOMEM;
otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
if (!otg)
return -ENOMEM;
ab->dev = &pdev->dev;
ab->ab8500 = ab8500;
ab->phy.dev = ab->dev;
ab->phy.otg = otg;
ab->phy.label = "ab8500";
ab->phy.set_suspend = ab8500_usb_set_suspend;
ab->phy.set_power = ab8500_usb_set_power;
ab->phy.state = OTG_STATE_UNDEFINED;
otg->phy = &ab->phy;
otg->set_host = ab8500_usb_set_host;
otg->set_peripheral = ab8500_usb_set_peripheral;
platform_set_drvdata(pdev, ab);
ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
/* all: Disable phy when called from set_host and set_peripheral */
INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
err = ab8500_usb_regulator_get(ab);
if (err)
return err;
ab->sysclk = devm_clk_get(ab->dev, "sysclk");
if (IS_ERR(ab->sysclk)) {
dev_err(ab->dev, "Could not get sysclk.\n");
return PTR_ERR(ab->sysclk);
}
err = ab8500_usb_irq_setup(pdev, ab);
if (err < 0)
return err;
err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
if (err) {
dev_err(&pdev->dev, "Can't register transceiver\n");
return err;
}
if (is_ab8500(ab->ab8500) && !is_ab8500_2p0_or_earlier(ab->ab8500))
/* Phy tuning values for AB8500 > v2.0 */
ab8500_usb_set_ab8500_tuning_values(ab);
else if (is_ab8505(ab->ab8500))
/* Phy tuning values for AB8505 */
ab8500_usb_set_ab8505_tuning_values(ab);
/* Needed to enable ID detection. */ /* Needed to enable ID detection. */
ab8500_usb_wd_workaround(ab); ab8500_usb_wd_workaround(ab);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment