From patchwork Thu Feb 7 20:14:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moritz Fischer X-Patchwork-Id: 1038334 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43wV0x0ms1z9sDr for ; Fri, 8 Feb 2019 07:15:13 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727447AbfBGUPK (ORCPT ); Thu, 7 Feb 2019 15:15:10 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:35201 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726707AbfBGUPJ (ORCPT ); Thu, 7 Feb 2019 15:15:09 -0500 Received: by mail-ot1-f65.google.com with SMTP id 81so2116338otj.2 for ; Thu, 07 Feb 2019 12:15:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=E0m8E4W3EbjxDKWEYI2e0ISoeX38gi4ZsTr/7fRHC3E=; b=BM9GS/UgZRW6Umdkgshib4XAZHJqnonZ3RJAZQsf+ULLGJB1L/8C5YRrMWLFA1xcPM ZCW0IOqBlE/A4r2NfYu6UENKl5SZ3QDA+q+BTZBdbHE2HEGo5SRsSdt/Ke3Lngla8bdw i9FvDuCECz8FfcGRle4zxY14LrL/LVkCz7cG0xRArCD0+QFdhDW7XelmfOz4lKIYF6Rk SZHw0675TAB8Qd/hkbNQcEFKwBzDKsm/+sVHX+VHK8LubKDU09h34HUngZ6DLyx0qidi lQJ+WVvBuv7cfu51D20+TSqH7Mk60WDVhP5pU9pZ3EczC3wrdT7QJhuZBOlAYK0K6L+4 2Dww== X-Gm-Message-State: AHQUAuY6XTJ9j8mrMZTMF122G/Tl91Z9e4UH8le1zs5uz6HEgguDXCIE p8AlAf3EIkFnOWYZjYuVwPS3z5yCnRQ= X-Google-Smtp-Source: AHgI3IZB+5McvwO+deN0U07MwwGILByt+8je6f4tx+5eh7UjCP2Xt37PryRBaukfTkBwKCS+EOtgRQ== X-Received: by 2002:a9d:2062:: with SMTP id n89mr1994734ota.244.1549570508481; Thu, 07 Feb 2019 12:15:08 -0800 (PST) Received: from localhost ([130.164.62.200]) by smtp.gmail.com with ESMTPSA id 187sm13064637oic.12.2019.02.07.12.15.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Feb 2019 12:15:07 -0800 (PST) From: Moritz Fischer To: netdev@vger.kernel.org Cc: andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com, davem@davemloft.net, linux-kernel@vger.kernel.org, Moritz Fischer Subject: [PATCH v2 net-next] net: fixed-phy: Add fixed_phy_register_with_gpiod() API Date: Thu, 7 Feb 2019 12:14:55 -0800 Message-Id: <20190207201455.25071-1-mdf@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add fixed_phy_register_with_gpiod() API. It lets users create a fixed_phy instance that uses a GPIO descriptor which was obtained externally e.g. through platform data. This enables platform devices (non-DT based) to use GPIOs for link status. Reviewed-by: Florian Fainelli Signed-off-by: Moritz Fischer --- Changes from v1: - Added Florian's Reviewed-by: tag Changes from RFC: - Implemented Andrew's/Florians suggestion to add new API instead of changing old API --- drivers/net/phy/fixed_phy.c | 32 +++++++++++++++++++++++++------- include/linux/phy_fixed.h | 15 +++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c index d810f914aaa4..b0d1368c3400 100644 --- a/drivers/net/phy/fixed_phy.c +++ b/drivers/net/phy/fixed_phy.c @@ -229,12 +229,12 @@ static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) } #endif -struct phy_device *fixed_phy_register(unsigned int irq, - struct fixed_phy_status *status, - struct device_node *np) +static struct phy_device *__fixed_phy_register(unsigned int irq, + struct fixed_phy_status *status, + struct device_node *np, + struct gpio_desc *gpiod) { struct fixed_mdio_bus *fmb = &platform_fmb; - struct gpio_desc *gpiod = NULL; struct phy_device *phy; int phy_addr; int ret; @@ -243,9 +243,11 @@ struct phy_device *fixed_phy_register(unsigned int irq, return ERR_PTR(-EPROBE_DEFER); /* Check if we have a GPIO associated with this fixed phy */ - gpiod = fixed_phy_get_gpiod(np); - if (IS_ERR(gpiod)) - return ERR_CAST(gpiod); + if (!gpiod) { + gpiod = fixed_phy_get_gpiod(np); + if (IS_ERR(gpiod)) + return ERR_CAST(gpiod); + } /* Get the next available PHY address, up to PHY_MAX_ADDR */ phy_addr = ida_simple_get(&phy_fixed_ida, 0, PHY_MAX_ADDR, GFP_KERNEL); @@ -308,8 +310,24 @@ struct phy_device *fixed_phy_register(unsigned int irq, return phy; } + +struct phy_device *fixed_phy_register(unsigned int irq, + struct fixed_phy_status *status, + struct device_node *np) +{ + return __fixed_phy_register(irq, status, np, NULL); +} EXPORT_SYMBOL_GPL(fixed_phy_register); +struct phy_device * +fixed_phy_register_with_gpiod(unsigned int irq, + struct fixed_phy_status *status, + struct gpio_desc *gpiod) +{ + return __fixed_phy_register(irq, status, NULL, gpiod); +} +EXPORT_SYMBOL_GPL(fixed_phy_register_with_gpiod); + void fixed_phy_unregister(struct phy_device *phy) { phy_device_remove(phy); diff --git a/include/linux/phy_fixed.h b/include/linux/phy_fixed.h index c78fc203db43..1e5d86ebdaeb 100644 --- a/include/linux/phy_fixed.h +++ b/include/linux/phy_fixed.h @@ -19,6 +19,12 @@ extern int fixed_phy_add(unsigned int irq, int phy_id, extern struct phy_device *fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, struct device_node *np); + +extern struct phy_device * +fixed_phy_register_with_gpiod(unsigned int irq, + struct fixed_phy_status *status, + struct gpio_desc *gpiod); + extern void fixed_phy_unregister(struct phy_device *phydev); extern int fixed_phy_set_link_update(struct phy_device *phydev, int (*link_update)(struct net_device *, @@ -35,6 +41,15 @@ static inline struct phy_device *fixed_phy_register(unsigned int irq, { return ERR_PTR(-ENODEV); } + +static inline struct phy_device * +fixed_phy_register_with_gpiod(unsigned int irq, + struct fixed_phy_status *status, + struct gpio_desc *gpiod) +{ + return ERR_PTR(-ENODEV); +} + static inline void fixed_phy_unregister(struct phy_device *phydev) { }