From patchwork Mon Oct 21 14:18:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 3078131 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2DC70BF924 for ; Mon, 21 Oct 2013 14:23:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0621A202F9 for ; Mon, 21 Oct 2013 14:23:22 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 4592E2014A for ; Mon, 21 Oct 2013 14:23:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2348DE6EC5 for ; Mon, 21 Oct 2013 07:23:20 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by gabe.freedesktop.org (Postfix) with ESMTP id 6A640E6FFA for ; Mon, 21 Oct 2013 07:19:09 -0700 (PDT) Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MV000HV7VRR2QN0@mailout2.samsung.com> for dri-devel@lists.freedesktop.org; Mon, 21 Oct 2013 23:19:08 +0900 (KST) X-AuditID: cbfee61a-b7f836d0000025d7-17-526537dca08e Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 9A.0F.09687.CD735625; Mon, 21 Oct 2013 23:19:08 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MV000F8PVR0T800@mmp1.samsung.com>; Mon, 21 Oct 2013 23:19:08 +0900 (KST) From: Tomasz Stanislawski To: devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC 04/12] phy: Add simple-phy driver Date: Mon, 21 Oct 2013 16:18:23 +0200 Message-id: <1382365111-6533-5-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1382365111-6533-1-git-send-email-t.stanislaws@samsung.com> References: <1382365111-6533-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDLMWRmVeSWpSXmKPExsVy+t9jAd075qlBBjMW6FnMP3KO1eLK1/ds FpPuT2Cx6F1wlc3iwtMeNouzTW/YLS7vmsNmMeP8PiaLpxMusllMWXSY1eLwm3ZWixmTX7JZ rJ/xmsViXvtLVotjM5YwOvB73Lm2h83jfvdxJo++LasYPY7f2M7k8XmTXABrFJdNSmpOZllq kb5dAlfGkyM/WQquKVfsvPmcuYHximwXIweHhICJxPrr9V2MnECmmMSFe+vZuhi5OIQEFjFK XPp7lxHC6WKS6L7WwARSxQbUcGzJZ0YQW0QgUeJX811mkCJmgUNMErtbpjCDJIQF9CWOTPvP BmKzCKhKnFg0AayZV8BdYtW9a0wQ6+Qlnt7vA6vhFPCQOPVyLdhQIaCad9/msUxg5F3AyLCK UTS1ILmgOCk911CvODG3uDQvXS85P3cTIzhMn0ntYFzZYHGIUYCDUYmHN8AlJUiINbGsuDL3 EKMEB7OSCG+VaWqQEG9KYmVValF+fFFpTmrxIUZpDhYlcd4DrdaBQgLpiSWp2ampBalFMFkm Dk6pBsYM7YUtl/wm3GMz86v3MV3+oNbp+rFJ+qsZZid8PRxjflRPJtq6Xsr0bvVj7QXLLuzP i1Tr3KHFvty17p1ydtAXV40kLenc76rskruC2+R28XR6FQa7/VigEzlTVetDwv+j9udm9qhI /6g8a8PEdt61Vrt60/s21ivH1z848fLm9GqF03f371NiKc5INNRiLipOBADkLgagTwIAAA== Cc: Tomasz Stanislawski , kgene.kim@samsung.com, mturquette@linaro.org, sw0312.kim@samsung.com, dri-devel@lists.freedesktop.org, kishon@ti.com, kyungmin.park@samsung.com, s.nawrocki@samsung.com, rahul.sharma@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add simple-phy driver to support a single register PHY interfaces present on Exynos4 SoC. Signed-off-by: Tomasz Stanislawski --- 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" + 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 + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +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); + + 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); + 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); + 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"); + + return 0; +} + +static const struct of_device_id simple_phy_of_match[] = { + { .compatible = "simple-phy" }, + { }, +}; +MODULE_DEVICE_TABLE(of, simple_phy_of_match); + +static struct platform_driver simple_phy_driver = { + .probe = simple_phy_probe, + .driver = { + .of_match_table = simple_phy_of_match, + .name = "simple-phy", + .owner = THIS_MODULE, + } +}; +module_platform_driver(simple_phy_driver); + +MODULE_DESCRIPTION("Simple PHY driver"); +MODULE_AUTHOR("Tomasz Stanislawski "); +MODULE_LICENSE("GPL v2");