From patchwork Tue Sep 6 13:50:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 603683 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A79C2C6FA86 for ; Tue, 6 Sep 2022 14:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241427AbiIFOW3 (ORCPT ); Tue, 6 Sep 2022 10:22:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241415AbiIFOU1 (ORCPT ); Tue, 6 Sep 2022 10:20:27 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 470CB8B99F; Tue, 6 Sep 2022 06:51:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662472305; x=1694008305; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jvEYSO7lW++ymJ0bBLH7ZRL0Q9IiAhclprxNUtYU6Os=; b=KLGWLfnHRuig99RWDZNPGKU2dL+zB2AEGaVtVh/ZEq6nDXUoop6a1BYf s2aMBtJxybALI9X1JddH6KkMZ0knE8VAHW2GT9MgN1jtdxYqe5tob+fo1 VBWwPheCLiQbTrvt3pi8VZw/EfYxdmJyGQLNrHgA4wl1dvZ/6v0ODyJZz IYyLlXXNS391QwUdAQKeo+DwrxPsLiVj1mOvU4cUSBxYY5I8KRIiVU8HL /s8fBGG7uKLq+pW3IqdN0TTPO1fOvs4nRju0SIjjrH6UR8B7XZQesR8fI fPdELs43FsoI+VGJb/mjuiG98veeGtqSSgcprWx59mWfyhuOZKAoIDS0O A==; X-IronPort-AV: E=McAfee;i="6500,9779,10462"; a="297380987" X-IronPort-AV: E=Sophos;i="5.93,294,1654585200"; d="scan'208";a="297380987" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2022 06:50:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,294,1654585200"; d="scan'208";a="859264825" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 06 Sep 2022 06:50:00 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id C9088725; Tue, 6 Sep 2022 16:50:10 +0300 (EEST) From: Andy Shevchenko To: Gene Chen , Andy Shevchenko , Andrew Jeffery , 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 , Matthias Brugger , Sean Wang , Kurt Kanzenbach , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lee Jones Subject: [PATCH v3 10/11] leds: syscon: Get rid of custom led_init_default_state_get() Date: Tue, 6 Sep 2022 16:50:03 +0300 Message-Id: <20220906135004.14885-11-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220906135004.14885-1-andriy.shevchenko@linux.intel.com> References: <20220906135004.14885-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@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 --- drivers/leds/leds-syscon.c | 49 ++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/drivers/leds/leds-syscon.c b/drivers/leds/leds-syscon.c index 7eddb8ecb44e..e38abb5e60c1 100644 --- a/drivers/leds/leds-syscon.c +++ b/drivers/leds/leds-syscon.c @@ -61,7 +61,8 @@ static int syscon_led_probe(struct platform_device *pdev) struct device *parent; struct regmap *map; struct syscon_led *sled; - const char *state; + enum led_default_state state; + u32 value; int ret; parent = dev->parent; @@ -86,34 +87,30 @@ static int syscon_led_probe(struct platform_device *pdev) if (of_property_read_u32(np, "mask", &sled->mask)) return -EINVAL; - state = of_get_property(np, "default-state", NULL); - if (state) { - if (!strcmp(state, "keep")) { - u32 val; - - ret = regmap_read(map, sled->offset, &val); - if (ret < 0) - return ret; - sled->state = !!(val & sled->mask); - } else if (!strcmp(state, "on")) { - sled->state = true; - ret = regmap_update_bits(map, sled->offset, - sled->mask, - sled->mask); - if (ret < 0) - return ret; - } else { - sled->state = false; - ret = regmap_update_bits(map, sled->offset, - sled->mask, 0); - if (ret < 0) - return ret; - } + init_data.fwnode = of_fwnode_handle(np); + + state = led_init_default_state_get(init_data.fwnode); + switch (state) { + case LEDS_DEFSTATE_ON: + ret = regmap_update_bits(map, sled->offset, sled->mask, sled->mask); + if (ret < 0) + return ret; + sled->state = true; + break; + case LEDS_DEFSTATE_KEEP: + ret = regmap_read(map, sled->offset, &value); + if (ret < 0) + return ret; + sled->state = !!(value & sled->mask); + break; + default: + ret = regmap_update_bits(map, sled->offset, sled->mask, 0); + if (ret < 0) + return ret; + sled->state = false; } sled->cdev.brightness_set = syscon_led_set; - init_data.fwnode = of_fwnode_handle(np); - ret = devm_led_classdev_register_ext(dev, &sled->cdev, &init_data); if (ret < 0) return ret;