dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Kishon Vijay Abraham I <kishon@ti.com>
To: Tomasz Stanislawski <t.stanislaws@samsung.com>
Cc: devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	kyungmin.park@samsung.com, t.figa@samsung.com,
	sw0312.kim@samsung.com, inki.dae@samsung.com,
	rahul.sharma@samsung.com, kgene.kim@samsung.com,
	s.nawrocki@samsung.com, thomas.abraham@linaro.org,
	mturquette@linaro.org
Subject: Re: [RFC 04/12] phy: Add simple-phy driver
Date: Thu, 24 Oct 2013 21:22:24 +0530	[thread overview]
Message-ID: <52694238.7050607@ti.com> (raw)
In-Reply-To: <1382365111-6533-5-git-send-email-t.stanislaws@samsung.com>

Hi,

On Monday 21 October 2013 07:48 PM, Tomasz Stanislawski wrote:
> Add simple-phy driver to support a single register
> PHY interfaces present on Exynos4 SoC.

How are these PHY interfaces modelled in the SoC? Where does the register
actually reside?
> 
> Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com>
> ---
>  drivers/phy/Kconfig      |    5 ++
>  drivers/phy/Makefile     |    1 +
>  drivers/phy/phy-simple.c |  128 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 134 insertions(+)
>  create mode 100644 drivers/phy/phy-simple.c
> 
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index ac239ac..619c657 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -38,4 +38,9 @@ config TWL4030_USB
>  	  This transceiver supports high and full speed devices plus,
>  	  in host mode, low speed.
>  
> +config PHY_SIMPLE
> +	tristate "Simple PHY driver"

This is too generic a name to be used. Lets name it something specific to what
it is used for (EXYNOS/HDMI.. ?).
> +	help
> +	  Support for PHY controllers configured using single register.
> +
>  endmenu
> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> index 0dd8a98..3d68e19 100644
> --- a/drivers/phy/Makefile
> +++ b/drivers/phy/Makefile
> @@ -5,3 +5,4 @@
>  obj-$(CONFIG_GENERIC_PHY)	+= phy-core.o
>  obj-$(CONFIG_OMAP_USB2)		+= phy-omap-usb2.o
>  obj-$(CONFIG_TWL4030_USB)	+= phy-twl4030-usb.o
> +obj-$(CONFIG_PHY_SIMPLE)	+= phy-simple.o
> diff --git a/drivers/phy/phy-simple.c b/drivers/phy/phy-simple.c
> new file mode 100644
> index 0000000..4a28af7
> --- /dev/null
> +++ b/drivers/phy/phy-simple.c
> @@ -0,0 +1,128 @@
> +/*
> + * Simple PHY driver
> + *
> + * Copyright (C) 2013 Samsung Electronics Co., Ltd.
> + * Author: Tomasz Stanislawski <t.stanislaws@samsung.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/phy/phy.h>
> +#include <linux/platform_device.h>
> +#include <linux/spinlock.h>
> +
> +struct simple_phy {
> +	spinlock_t slock;
> +	u32 on_value;
> +	u32 off_value;
> +	u32 mask;
> +	void __iomem *regs;
> +};
> +
> +static int sphy_set(struct simple_phy *sphy, bool on)
> +{
> +	u32 reg;
> +
> +	spin_lock(&sphy->slock);

Lets add spin_lock only when it is absolutely necessary. When your PHY provider
implements only a single PHY, it is not needed. phy_power_on and phy_power_off
is already protected by the framework.
> +
> +	reg = readl(sphy->regs);
> +	reg &= ~sphy->mask;
> +	reg |= sphy->mask & (on ? sphy->on_value : sphy->off_value);
> +	writel(reg, sphy->regs);
> +
> +	spin_unlock(&sphy->slock);
> +
> +	return 0;
> +}
> +
> +static int simple_phy_power_on(struct phy *phy)
> +{
> +	return sphy_set(phy_get_drvdata(phy), 1);
> +}
> +
> +static int simple_phy_power_off(struct phy *phy)
> +{
> +	return sphy_set(phy_get_drvdata(phy), 0);
> +}
> +
> +static struct phy_ops simple_phy_ops = {
> +	.power_on	= simple_phy_power_on,
> +	.power_off	= simple_phy_power_off,
> +	.owner		= THIS_MODULE,
> +};
> +
> +static int simple_phy_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct simple_phy *sphy;
> +	struct resource *res;
> +	struct phy_provider *phy_provider;
> +	struct phy *phy;
> +
> +	sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL);
> +	if (!sphy)
> +		return -ENOMEM;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +
> +	sphy->regs = devm_ioremap_resource(dev, res);
> +	if (IS_ERR(sphy->regs)) {
> +		dev_err(dev, "failed to ioremap registers\n");
> +		return PTR_ERR(sphy->regs);
> +	}
> +
> +	spin_lock_init(&sphy->slock);
> +
> +	phy_provider = devm_of_phy_provider_register(dev, NULL);

pass 'of_phy_simple_xlate' instead of NULL.
> +	if (IS_ERR(phy_provider)) {
> +		dev_err(dev, "failed to register PHY provider\n");
> +		return PTR_ERR(phy_provider);
> +	}
> +
> +	phy = devm_phy_create(dev, &simple_phy_ops, NULL);
> +	if (IS_ERR(phy)) {
> +		dev_err(dev, "failed to create PHY\n");
> +		return PTR_ERR(phy);
> +	}
> +
> +	sphy->mask = 1;
> +	sphy->on_value = ~0;
> +	sphy->off_value = 0;
> +
> +	of_property_read_u32(dev->of_node, "mask", &sphy->mask);

This means your driver will depend on dt data to describe how the register
should look like. Not a good idea.
> +	of_property_read_u32(dev->of_node, "on-value", &sphy->on_value);
> +	of_property_read_u32(dev->of_node, "off-value", &sphy->off_value);
> +
> +	phy_set_drvdata(phy, sphy);
> +
> +	dev_info(dev, "probe successful\n");
Lets not make the boot noisy.

Thanks
Kishon

  reply	other threads:[~2013-10-24 15:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 14:18 [RFC 00/12] Add DRM Exynos HDMI on SoCs from Exynos4 family Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 01/12] clk: propagate parent change up one level Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 02/12] clk: exynos4: export sclk_hdmiphy clock Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 03/12] clk: exynos4: enable clk_set_parent() propagation for sclk_hdmi and sclk_mixer clocks Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 04/12] phy: Add simple-phy driver Tomasz Stanislawski
2013-10-24 15:52   ` Kishon Vijay Abraham I [this message]
2013-10-25  7:51     ` Tomasz Stanislawski
2013-11-04  7:08       ` Kishon Vijay Abraham I
2013-10-21 14:18 ` [RFC 05/12] phy: use of_phy_simple_xlate for NULL xlate function Tomasz Stanislawski
2013-10-24 15:33   ` Kishon Vijay Abraham I
2013-10-21 14:18 ` [RFC 06/12] Revert "drm/exynos: add mout_hdmi clock in hdmi driver to change parent" Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 07/12] drm: exynos: hdmi: use hdmiphy as PHY Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 08/12] drm: exynos: hdmi: simplify extracting hpd-gpio from DT Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 09/12] drm: exynos: add compatibles for HDMI and Mixer chips and exynos4210 SoC Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 10/12] arm: dts: exynos4: add i2c controller for HDMIPHY Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 11/12] arm: dts: exynos4: add HDMI devices Tomasz Stanislawski
2013-10-21 14:18 ` [RFC 12/12] arm: dts: universal_c210: " Tomasz Stanislawski
2013-10-28 13:42 ` [RFC 00/12] Add DRM Exynos HDMI on SoCs from Exynos4 family Inki Dae
2013-10-28 16:00   ` Kukjin Kim
2013-10-28 17:19     ` Inki Dae

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52694238.7050607@ti.com \
    --to=kishon@ti.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=inki.dae@samsung.com \
    --cc=kgene.kim@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=mturquette@linaro.org \
    --cc=rahul.sharma@samsung.com \
    --cc=s.nawrocki@samsung.com \
    --cc=sw0312.kim@samsung.com \
    --cc=t.figa@samsung.com \
    --cc=t.stanislaws@samsung.com \
    --cc=thomas.abraham@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).