From patchwork Sun Mar 19 19:18:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 71860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp845904wrt; Sun, 19 Mar 2023 12:30:20 -0700 (PDT) X-Google-Smtp-Source: AK7set/VrRKNfryWYaD7UxpJIC8wQROGNaQjuVNw1j3mBaJBopTKy63g7ifwpIKkv2ZFryz4VDUj X-Received: by 2002:a05:6a20:3b8f:b0:d9:a38d:3ec7 with SMTP id b15-20020a056a203b8f00b000d9a38d3ec7mr784043pzh.29.1679254219788; Sun, 19 Mar 2023 12:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679254219; cv=none; d=google.com; s=arc-20160816; b=t9OeoUUb5oXwBzGVY7tvSmvkdfAvtBAEe55+iYflrbB78l7HObDtytOXQbgMoGwglF 7Qrr2WSXHc0AIzhhdLReuh5r5lQ16jtbKF5rWQ0eqooJRA+1TBKkytWRNHYWTJYawwiK gxtac6c9VpxChOd5r8UmaSI4OahjYSiHDXimtjDK30TAyOPYN82X4kVXQcPyh6MZ7HXf HQZhuLeoZ+1ZaOSmH0FafWBjEr5jgQ95KswYSKtWf6smbaPbsnN0kv3Zg3o5ikSu1XOO gCcXuOAJjuqKxVlgz/Hwhpm21Dm0lBuzhyPVtwN3NPiUCYtBXppy5PHV+JaOVBdxY6Tl CFfg== 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=0MakyRcFEWBZQiWEXykX8ky94BsPvBnh7BhgiO6dB5k=; b=a+CkzQDstj1DUtEb+ZC1x3YJzo7TL4bnTTgVJKMGQ3fDsfEEq73OdwkTqua+Zh1VXs 60HjatXvm4ZL/XEChIHxsGyOKYQGrjCNVgjyXKcHgGmLGmgLhMAUiigWfpQ6E388eFhT nRJr96x2ee7C5GNzURAhr+mvnX0GWUwhkkw0CefhuGqL1nVB46dmx2imMX86urxJ9Car o9yxuCdxPLrzq3MPqOMboF47eIdznrUJ4CWY/PiiV2p/TQ0tWLwtSJdbi4E1P6RwsYQL RCxH1O3+UvBAoPTbWkjVIQ8QL+z83SPGJBOioxmsD0Gn3jXeXOHEoC3ZBNfrTX2/lmWO 2Xrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ktTQb++o; 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 n3-20020a654883000000b004fb12ee7cb9si8507364pgs.354.2023.03.19.12.30.06; Sun, 19 Mar 2023 12:30:19 -0700 (PDT) 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=ktTQb++o; 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 S230034AbjCSTTS (ORCPT + 99 others); Sun, 19 Mar 2023 15:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbjCSTSp (ORCPT ); Sun, 19 Mar 2023 15:18:45 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768921FF6; Sun, 19 Mar 2023 12:18:43 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id t15so8515811wrz.7; Sun, 19 Mar 2023 12:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679253522; 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=0MakyRcFEWBZQiWEXykX8ky94BsPvBnh7BhgiO6dB5k=; b=ktTQb++or6bxcgenSg9H3uoy0NKlIdMXs5VyshZ2T5aAYD4JsGyFowKAH6XptpbzDa 5mwPrtZByvjEQzuu1a0c/qe4LD0B1dGj6MUrT1vw0v37COG7s6NPM1bqXPCq3NA4V15i 5renmpPDNmI1nPnAJkpkwyLv+tMOxrh3yu26F75vWkt96xMbHYDVSznmXg/bPDBebhUA f0Giu6187l9uRPTizN57xJsBVcxqOoUAfwhGXu3iH6vH8N/q9BEVtw4fMK23T8XPnbzc GVQWILvN8dllu33YCISqbqYeroLHCFSkrUTHcnnd/H8779a9lvqkSIwJOQa7i5QaVKsp RjMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679253522; 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=0MakyRcFEWBZQiWEXykX8ky94BsPvBnh7BhgiO6dB5k=; b=aXFdK8LMwr/SpWz6DLp3Xl2wpwKb9WvMW0DGEE3KDmVL8JdatPnqhZWOJGsYivYDBl ghcw/9rSIr9xzk3i1qG9/hvJXP+8xZR60mRm32vQQ51UpLKMGnujBLMABz6GvA9ev4ow qhwY2KsbYPUiE2lIVHOSihM+5F0M0xS9WheliI+zPRS2vWVdReJpSej73DvbZddMYBVY OiXuqSpGdB1qg6ojf70D6MEJ6CGoJm5tiJyBL9slrJR6YjgSRZEqwzaevZUO+/R4Tn1p 4afG42Mmeh7IYl0KdzCSbNPGhKkQ6/JVBdJ6bLVxd6DCiZkmi1Y8pAZqPJEI9O/1ADO8 Nveg== X-Gm-Message-State: AO0yUKXeyG7ImhdOUGvXxq44cMJqHo5sbA7SAz+Gaam2IUgJ4uOejdvP ATgM4oKkn4+EsXrSOZOUsTU= X-Received: by 2002:a5d:6511:0:b0:2d1:6104:76ab with SMTP id x17-20020a5d6511000000b002d1610476abmr9730929wru.2.1679253521860; Sun, 19 Mar 2023 12:18:41 -0700 (PDT) Received: from localhost.localdomain (93-34-89-197.ip49.fastwebnet.it. [93.34.89.197]) by smtp.googlemail.com with ESMTPSA id b7-20020a5d4b87000000b002cfe0ab1246sm7165167wrt.20.2023.03.19.12.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 12:18:41 -0700 (PDT) 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 , Andy Gross , Bjorn Andersson , Konrad Dybcio , Pavel Machek , Lee Jones , Christian Marangi , John Crispin , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-leds@vger.kernel.org Subject: [net-next PATCH v5 05/15] net: phy: Add a binding for PHY LEDs Date: Sun, 19 Mar 2023 20:18:04 +0100 Message-Id: <20230319191814.22067-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230319191814.22067-1-ansuelsmth@gmail.com> References: <20230319191814.22067-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1760825672312786960?= X-GMAIL-MSGID: =?utf-8?q?1760825672312786960?= 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 Signed-off-by: Christian Marangi Reviewed-by: Michal Kubiak --- drivers/net/phy/phy_device.c | 75 ++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 16 ++++++++ 2 files changed, 91 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index c0760cbf534b..39af989947f9 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 @@ -674,6 +676,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->leds); mutex_init(&dev->lock); INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); @@ -2988,6 +2991,73 @@ 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; + + cdev = &phyled->led_cdev; + + 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->list, &phydev->leds); + + 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) { + of_node_put(led); + return err; + } + } + + return 0; +} + /** * fwnode_mdio_find_device - Given a fwnode, find the mdio_device * @fwnode: pointer to the mdio_device's fwnode @@ -3183,6 +3253,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. + */ + err = of_phy_leds(phydev); + out: /* Re-assert the reset signal on error */ if (err) diff --git a/include/linux/phy.h b/include/linux/phy.h index fefd5091bc24..11fb76a1c507 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -600,6 +601,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 + * @leds: 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 @@ -699,6 +701,7 @@ struct phy_device { struct phy_led_trigger *led_link_trigger; #endif + struct list_head leds; /* * Interrupt number for this PHY @@ -834,6 +837,19 @@ struct phy_plca_status { bool pst; }; +/** + * struct phy_led: An LED driven by the PHY + * + * @list: List of LEDs + * @led_cdev: Standard LED class structure + * @index: Number of the LED + */ +struct phy_led { + struct list_head list; + struct led_classdev led_cdev; + u32 index; +}; + /** * struct phy_driver - Driver structure for a particular PHY type *