Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11829570rwl; Tue, 3 Jan 2023 05:28:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXs8yoY6eh2wwUYg3NucDmSqkmOez1reBMBJP6gw7YNiqQZ2gIO/Z+y9AUtVGL9vS0srt1Lw X-Received: by 2002:a05:6a20:bf29:b0:a5:df86:f2b4 with SMTP id gc41-20020a056a20bf2900b000a5df86f2b4mr46139618pzb.58.1672752482176; Tue, 03 Jan 2023 05:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672752482; cv=none; d=google.com; s=arc-20160816; b=kZy8EnI7xPl6c2l9aqtBxAhQlb5lrDUZtREVy7XqthikA5o3CoBwq6WpLIyWaQuwdx UAlsNKa3q+ulMXANIG4hI78TLREHJAtfiyrMP7Sarl+Md5C2REqGnTU1MqF3gjsJwbbU 4TPW+ZDCVferELkM0mL5K8Gr6b7GarKGtzSFPrRlHO5xho86gsoJpFFjs6T9zzOwZurG 4d+Nm7XjKYXOxwK+/LG5qFWrh0aLejlohVKa7/rjlqdSgEnl7ai46iBdde2Bvu+xathd 7Uaw6qdjhlUHzcynN80W8ePRy1G4uNBMC3xB41f4I8tDM1A3oJY4w+jO0jtq8ARKvnMe ZZoA== 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:cc:to:from :dkim-signature; bh=0ZIENcKeaf489uFWiNYo7yRg+Cgbsq5yoCtVjXncWKc=; b=Njim237Z26sA831HqzAxzyYDAXxhl2fXqq0OxMkyp1o/P+c2GL+jSyHErLK3Aj/T1y lvFQNUXbj/K1pWHK7wL4lxCZpUmzDGPSXAnny/bLwUuEyNjx0ZbXHMI5gvMwSveE4sWQ x+gJsljRo5xf2MNBHxtQxQb9lKBVXckqigWEbmRqz9q8N0dnfkw1uFQwWzFpBIHZ/waK t4Cb+htJuA+Zvaj7rm/hFYPpMeOnYAhdNFy4f2mICHLI77s7kL6PjyQ00hDPf5wsE5Bn XkTVwRnNT49XP94A5RJk6tCay0RHKS6j1PC8UvOf+yiUYyN7Ow+7U9UVOsjuLDiJ9i5E mY2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UMfWs+fa; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a24-20020a63e418000000b0045b22d763a3si31782090pgi.483.2023.01.03.05.27.54; Tue, 03 Jan 2023 05:28:02 -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=@intel.com header.s=Intel header.b=UMfWs+fa; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237532AbjACNMr (ORCPT + 60 others); Tue, 3 Jan 2023 08:12:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237660AbjACNMh (ORCPT ); Tue, 3 Jan 2023 08:12:37 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B04D2FAFD; Tue, 3 Jan 2023 05:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672751556; x=1704287556; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fLglo+upgf8/JpSJNXXF1To0jqbOVKWrlAOKnDglss8=; b=UMfWs+faQ2yM3oIhVCeufdqzQA7CpsYpDrtbXyI2x09eh5xZ6gUUHIex Nqm/tiCW+YkdkYLQDOIANhJw2Wc5xI6BOfVt+9RTeFUAyiodh8YjyQFvr hQ8/L+Wq6eUPIrgyjsAQIBhajpvwtBMMmu96iG/Ol4Tundnvv1Y+wJUln Ij3J2EiD+CJlbuJ49Cd+xY+EaIeogBhPbaiL53vopUdoioKP5+Xi9Bje4 r2m9YXKfiso7nLI4qfjwaWPFUZRIRKSm70gbheVmEWO4uDENf4gvc8IIl Vt6urdkrswn7KhTcbB4Sb5hG/hoDMIMCpBiQGiBoM4mxuxxb4PwPdf8YP A==; X-IronPort-AV: E=McAfee;i="6500,9779,10579"; a="322887912" X-IronPort-AV: E=Sophos;i="5.96,297,1665471600"; d="scan'208";a="322887912" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 05:12:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10579"; a="685397924" X-IronPort-AV: E=Sophos;i="5.96,297,1665471600"; d="scan'208";a="685397924" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 03 Jan 2023 05:12:28 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 9B761252; Tue, 3 Jan 2023 15:13:00 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Gene Chen , linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Pavel Machek , Lee Jones , Matthias Brugger , Sean Wang , Kurt Kanzenbach , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v4 04/11] leds: bcm6328: Get rid of custom led_init_default_state_get() Date: Tue, 3 Jan 2023 15:12:49 +0200 Message-Id: <20230103131256.33894-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230103131256.33894-1-andriy.shevchenko@linux.intel.com> References: <20230103131256.33894-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 LED core provides a helper to parse default state from firmware node. Use it instead of custom implementation. Signed-off-by: Andy Shevchenko Reviewed-by: Florian Fainelli --- drivers/leds/leds-bcm6328.c | 49 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c index 2d4d87957a30..246f1296ab09 100644 --- a/drivers/leds/leds-bcm6328.c +++ b/drivers/leds/leds-bcm6328.c @@ -330,7 +330,9 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, { struct led_init_data init_data = {}; struct bcm6328_led *led; - const char *state; + enum led_default_state state; + unsigned long val, shift; + void __iomem *mode; int rc; led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); @@ -346,31 +348,29 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, if (of_property_read_bool(nc, "active-low")) led->active_low = true; - if (!of_property_read_string(nc, "default-state", &state)) { - if (!strcmp(state, "on")) { + init_data.fwnode = of_fwnode_handle(nc); + + state = led_init_default_state_get(init_data.fwnode); + switch (state) { + case LEDS_DEFSTATE_ON: + led->cdev.brightness = LED_FULL; + break; + case LEDS_DEFSTATE_KEEP: + shift = bcm6328_pin2shift(led->pin); + if (shift / 16) + mode = mem + BCM6328_REG_MODE_HI; + else + mode = mem + BCM6328_REG_MODE_LO; + + val = bcm6328_led_read(mode) >> BCM6328_LED_SHIFT(shift % 16); + val &= BCM6328_LED_MODE_MASK; + if ((led->active_low && val == BCM6328_LED_MODE_OFF) || + (!led->active_low && val == BCM6328_LED_MODE_ON)) led->cdev.brightness = LED_FULL; - } else if (!strcmp(state, "keep")) { - void __iomem *mode; - unsigned long val, shift; - - shift = bcm6328_pin2shift(led->pin); - if (shift / 16) - mode = mem + BCM6328_REG_MODE_HI; - else - mode = mem + BCM6328_REG_MODE_LO; - - val = bcm6328_led_read(mode) >> - BCM6328_LED_SHIFT(shift % 16); - val &= BCM6328_LED_MODE_MASK; - if ((led->active_low && val == BCM6328_LED_MODE_OFF) || - (!led->active_low && val == BCM6328_LED_MODE_ON)) - led->cdev.brightness = LED_FULL; - else - led->cdev.brightness = LED_OFF; - } else { + else led->cdev.brightness = LED_OFF; - } - } else { + break; + default: led->cdev.brightness = LED_OFF; } @@ -378,7 +378,6 @@ static int bcm6328_led(struct device *dev, struct device_node *nc, u32 reg, led->cdev.brightness_set = bcm6328_led_set; led->cdev.blink_set = bcm6328_blink_set; - init_data.fwnode = of_fwnode_handle(nc); rc = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); if (rc < 0) -- 2.35.1