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: 65900 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3110wrd; Tue, 7 Mar 2023 14:45:36 -0800 (PST) X-Google-Smtp-Source: AK7set9RNljkAAHVuBMXavd9/Yy48U+qY4ppKdVY+75YfVl8KdHB8W+9pKfdlHqK9nsX6cfbqPpl X-Received: by 2002:a17:902:f80f:b0:19c:df17:b724 with SMTP id ix15-20020a170902f80f00b0019cdf17b724mr14014101plb.58.1678229135720; Tue, 07 Mar 2023 14:45:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678229135; cv=none; d=google.com; s=arc-20160816; b=bI4TGc36xXQy4v+bL/TM+lLqYAe9Hoh0km9bMfnv4KJRmDl7ZNYAlSUdap/obl/H/+ zr9+YHF/vvObY/Chn81jNVmJ0cucTvn+FTX1yknRWslSIMEET8GQ0HAFFfeO8E+ALe0R Enq7n72w0AIFV6S8V+MMjsQr9iaKUmZc+fg0BR7RtqZ2xjbT9bNM9p27bCSObGhQ0yAN cgyvtyjuHzf5vJ+0tIrLuPLsHGpSpD/jpYxuYj54eIqnP2U2x54OI3ntON1cPuSVPWxi OmqrgwsgMjA0GqazIDxQQftw09w45kOPgGG3PFQuGA5odgSQVCkeBV7shD4q8X129cLl +Q0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=PNA75+ffAuv7QuOxp1Cc8LTrOxCzACAVhyEOObz9ATQ=; b=HEULhPZcuioInnJ3fsBXICCS9ZUajdInTNUgtQxwnhoA0yco+lDj2X+Q2kj2Hxapzs c2gxEvAQDuXabGIFG6w0jcBfXcXBYE+f8NmXbb3Gi3Fow9wPl4riNIciVSq2d5OaB76n 6uPhtpkc+fBHTIehwKsCfmwd7yHmjESxYZj8biTfEwnWoAMjHO7G8E/5UajxwuwX3Bgp g+KYnl7i5UAD9NonztlzOCHUz65eVz1kQDY0OdV9hxTdWkPBMNMHfwYHUEzKLA81D4L9 08DtYVbKq15Fq4392364VQhDPsLBYfaFhLeIx4k34DltwNyv3eROpqZXMtcn+3v497g9 d3YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Ous/JScF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ke13-20020a170903340d00b0019cb21ef999si12498625plb.152.2023.03.07.14.45.22; Tue, 07 Mar 2023 14:45:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Ous/JScF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230457AbjCGWdu (ORCPT + 99 others); Tue, 7 Mar 2023 17:33:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230025AbjCGWdb (ORCPT ); Tue, 7 Mar 2023 17:33:31 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 298B89AA35; Tue, 7 Mar 2023 14:33:30 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id m25-20020a7bcb99000000b003e7842b75f2so85150wmi.3; Tue, 07 Mar 2023 14:33:30 -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=w6MhwfQt/IvZupmv/UZBP97joijAnw1e1YFcxmUo2GlCtcxDQ5dhtSY5ICCQmOVHm7 H5dielbJN9punkIllVAqzpPUJLTJu2VVJcdyaQZCYH9q/Zuz4NqT97u4bI0nuHnNgtVK +QLPs7PlmvjMsCs59hK0gp0TbOXomOhM3ZIQrIvcLBv3u3o1PLgvHaU/ha1xxtpRzt86 HrKJVdq4KxasypKOHsGKDpk0yBlfYMIi0WVm5U2xjf5sWgNAe6Uf6NscXW+SMmMIZyw0 gmkfgEGMwCuyN4U6OSx6NUBGP7XuNgj1MWglFaHZJovDc06VLXIhPwQN4EifAdv+bDZW vAcg== X-Gm-Message-State: AO0yUKXoEvAMu/31pzHvhvcjpZCuvTrXkmkXSvKzERmdhvgh0loY0kuT 8GSuAytNCBvNuV/9i/rNEv8= 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-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759750794202980389?= X-GMAIL-MSGID: =?utf-8?q?1759750794202980389?= 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 *