From patchwork Tue Mar 7 17:00:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13164874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B15EBC6FA99 for ; Tue, 7 Mar 2023 22:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=I3/YCh8FvwuUQUdHiFuT1eFPd9aYYnfoA492mY1f0OE=; b=Cf+7MLCD6hyNAQ QoMjesbuKy737EyQjUqpnut8ck7h3jkVf/8+ZnGNjZKiBKSXoiD2lBdhE9EHHyFswzkEbT0/Qsf8U kr2nRPGCuVOqE4DrQlL2UXVSwU7wTZieUqrGYgwiE+eKOeuAaVAmHVz8iMldD1ygQ5lmGsJEATiiD 5OpWw5WbeU8Bz96J49p/IEymNQ3YKPEg6OprYeQuqI1Lwk+H9CarRltTsNx0gunS0TwGwfJAh3SS4 dgcvPLls3FRLmEy2QevfLELT4zCKI4y1X6fay98jGpcJ3yFlRC0J/P3ANc3FAL4bo2FteHjCfzVUu oJcAQk/ga+ATTGMj1FxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZfsn-002h5s-Db; Tue, 07 Mar 2023 22:34:09 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZfsC-002gmh-By for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 22:33:35 +0000 Received: by mail-wm1-x334.google.com with SMTP id o11-20020a05600c4fcb00b003eb33ea29a8so88682wmq.1 for ; Tue, 07 Mar 2023 14:33:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678228408; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=PNA75+ffAuv7QuOxp1Cc8LTrOxCzACAVhyEOObz9ATQ=; b=Ous/JScFrx1dSu9x6+tQiT/MLYKi3xMjoh/2zzApSkvb/hTI3pwPN0Iv5VWQ/6kcLz uw/bNtz9yrxt1Dm+77uj2Hij9B9Ilt/yncfd0KzeZmFqicT+I+Oml35h10/7rs+QtTig f1znzcLnWi71teXhkEEhYaezDTos9OtE3JkbwXxBofL00/PYxjuyWOn2c2Pi0IEylKPd CGjZaa0YCGiRVy/XrsSuX3hua0ywvkQMwFYfI9y1+I9JrcgqXZhfAnm2xp5WmjPfHO9e BMj9jwEDNbPTctxTPqcfYdQRl3W3HIRXf1oDa045h9Vs81BlCdE1nQKH8V92P9TblByl /SQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678228408; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PNA75+ffAuv7QuOxp1Cc8LTrOxCzACAVhyEOObz9ATQ=; b=Hf++rO1XqRgTTwJPisYAMWPimE3XLodMg+Dz3JMsUv2jchWdPije7bQPQIm2vgYc39 IURaUKfuSWDT8OgR6jW5s/P//kUN3ptylscGi+BgZMwyY1I6cjyIbuZ2SgUBBPzUd1e5 l3Het06ZvDCDydMPgQM/4ffRAZQ81J3KA4kyB+eUGKY+E68Jl7BIk5iNQFamtp94auWt vGAGFN4SkaaZU/WTnccNNvsIj6O+JfZMMjX0Qh62UVCeeQHKIi2Rfb2/4hcsECellVQT 3w7nitKZ+ANLnFIVe2WkBXyMQWNUuZ4wIrL3xTu7uPv68Ha3u0bgDNNHKkN89dyBGiRE aJGQ== X-Gm-Message-State: AO0yUKVYuurlV0RqPxKOcDaO07LyEOzQFqOThInaRMgTVyy/zlLS49hl B8dwSkMUZMHfmO4jElbFWpEEEkPX+g0= X-Google-Smtp-Source: AK7set9RLmmfjOKKC2D+hLDppQ5/16MJZhaGu25c4q4km1PSZeLZ3CPqlu+9ygLhvoGX1Olx6hwHgw== X-Received: by 2002:a05:600c:a09:b0:3ea:c100:e974 with SMTP id z9-20020a05600c0a0900b003eac100e974mr15119103wmp.26.1678228408515; Tue, 07 Mar 2023 14:33:28 -0800 (PST) Received: from localhost.localdomain (93-34-89-197.ip49.fastwebnet.it. [93.34.89.197]) by smtp.googlemail.com with ESMTPSA id q11-20020a05600c46cb00b003dc1d668866sm19233101wmo.10.2023.03.07.14.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 14:33:28 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Heiner Kallweit , Russell King , Gregory Clement , Sebastian Hesselbarth , Christian Marangi , John Crispin , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lee Jones , linux-leds@vger.kernel.org Subject: [net-next PATCH 03/11] net: phy: Add a binding for PHY LEDs Date: Tue, 7 Mar 2023 18:00:38 +0100 Message-Id: <20230307170046.28917-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307170046.28917-1-ansuelsmth@gmail.com> References: <20230307170046.28917-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230307_143332_434830_D8468B32 X-CRM114-Status: GOOD ( 22.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Andrew Lunn Define common binding parsing for all PHY drivers with LEDs using phylib. Parse the DT as part of the phy_probe and add LEDs to the linux LED class infrastructure. For the moment, provide a dummy brightness function, which will later be replaced with a call into the PHY driver. Signed-off-by: Andrew Lunn --- drivers/net/phy/phy_device.c | 89 ++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 16 +++++++ 2 files changed, 105 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 9ba8f973f26f..8acade42615c 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -19,10 +19,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -658,6 +660,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, device_initialize(&mdiodev->dev); dev->state = PHY_DOWN; + INIT_LIST_HEAD(&dev->led_list); mutex_init(&dev->lock); INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); @@ -2964,6 +2967,85 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv) return phydrv->config_intr && phydrv->handle_interrupt; } +/* Dummy implementation until calls into PHY driver are added */ +static int phy_led_set_brightness(struct led_classdev *led_cdev, + enum led_brightness value) +{ + return 0; +} + +static int of_phy_led(struct phy_device *phydev, + struct device_node *led) +{ + struct device *dev = &phydev->mdio.dev; + struct led_init_data init_data = {}; + struct led_classdev *cdev; + struct phy_led *phyled; + int err; + + phyled = devm_kzalloc(dev, sizeof(*phyled), GFP_KERNEL); + if (!phyled) + return -ENOMEM; + + phyled->phydev = phydev; + cdev = &phyled->led_cdev; + INIT_LIST_HEAD(&phyled->led_list); + + err = of_property_read_u32(led, "reg", &phyled->index); + if (err) + return err; + + cdev->brightness_set_blocking = phy_led_set_brightness; + cdev->max_brightness = 1; + init_data.devicename = dev_name(&phydev->mdio.dev); + init_data.fwnode = of_fwnode_handle(led); + + err = devm_led_classdev_register_ext(dev, cdev, &init_data); + if (err) + return err; + + list_add(&phyled->led_list, &phydev->led_list); + + return 0; +} + +static int of_phy_leds(struct phy_device *phydev) +{ + struct device_node *node = phydev->mdio.dev.of_node; + struct device_node *leds, *led; + int err; + + if (!IS_ENABLED(CONFIG_OF_MDIO)) + return 0; + + if (!node) + return 0; + + leds = of_get_child_by_name(node, "leds"); + if (!leds) + return 0; + + for_each_available_child_of_node(leds, led) { + err = of_phy_led(phydev, led); + if (err) + return err; + } + + return 0; +} + +static void phy_leds_remove(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + struct led_classdev *cdev; + struct phy_led *phyled; + + list_for_each_entry(phyled, &phydev->led_list, led_list) { + cdev = &phyled->led_cdev; + devm_led_classdev_unregister(dev, cdev); + } +} + /** * fwnode_mdio_find_device - Given a fwnode, find the mdio_device * @fwnode: pointer to the mdio_device's fwnode @@ -3142,6 +3224,11 @@ static int phy_probe(struct device *dev) /* Set the state to READY by default */ phydev->state = PHY_READY; + /* Get the LEDs from the device tree, and instantiate standard + * LEDs for them. + */ + of_phy_leds(phydev); + out: /* Assert the reset signal */ if (err) @@ -3156,6 +3243,8 @@ static int phy_remove(struct device *dev) { struct phy_device *phydev = to_phy_device(dev); + phy_leds_remove(phydev); + cancel_delayed_work_sync(&phydev->state_queue); mutex_lock(&phydev->lock); diff --git a/include/linux/phy.h b/include/linux/phy.h index fbeba4fee8d4..1b1efe120f0f 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -595,6 +596,7 @@ struct macsec_ops; * @phy_num_led_triggers: Number of triggers in @phy_led_triggers * @led_link_trigger: LED trigger for link up/down * @last_triggered: last LED trigger for link speed + * @led_list: list of PHY LED structures * @master_slave_set: User requested master/slave configuration * @master_slave_get: Current master/slave advertisement * @master_slave_state: Current master/slave configuration @@ -690,6 +692,7 @@ struct phy_device { struct phy_led_trigger *led_link_trigger; #endif + struct list_head led_list; /* * Interrupt number for this PHY @@ -825,6 +828,19 @@ struct phy_plca_status { bool pst; }; +/* phy_led: An LED driven by the PHY + * + * phydev: Pointer to the PHY this LED belongs to + * led_cdev: Standard LED class structure + * index: Number of the LED + */ +struct phy_led { + struct list_head led_list; + struct phy_device *phydev; + struct led_classdev led_cdev; + u32 index; +}; + /** * struct phy_driver - Driver structure for a particular PHY type *