From nobody Mon Feb 9 01:27:17 2026 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B1CE73445; Sun, 16 Jun 2024 21:55:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574955; cv=none; b=gFlGP8flCRX2ZvXP1nRcA/buHYGZ/3iYyR+cqfimMRTvbXZiq0B+Ek93eXpRzRFLw7Xm3C9EHivmKgE3gdIVj03do6W4df/ABg7oTstsSGUH6rDArfAyOXEi7tECcH7R6HKnt8OifSHFnpUG9CaFkiUHkr1O7larUNYr91WFxxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718574955; c=relaxed/simple; bh=D+m1L5PapfPb0QEhBfL/fexXfSyHs0tFiyCyLseC7d4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Feqx3l45PzS1OHFCfdWdzIauM45gwvvohyV8YudzG58Ul9cOtBrrAmUVTjjd2crJysyXbpX1eeMw5r1GpoKFPQ99WmisSrQvk45zgF3vAePFfwDmHbEyYn5ostmYehpyShdN3TsZbciTM/31iAGmC8rBtRew6TPWfzl62ks0kA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PI4729fP; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PI4729fP" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-35f1c209842so2861779f8f.3; Sun, 16 Jun 2024 14:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718574951; x=1719179751; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nzWmmV5lLGO/kDDsghSyyH6GIF1fBoQT5IQ42I5GYNY=; b=PI4729fPUGw37cakY5mZ+b5J3GMFNcw0lUmIGUJyhdPATKY2hTyZV4EBwJPj44Obel dLz6+i99HQE/PYsCUsiJVaDnsDeCDIL0PkcKiAb49x3Goc67UidF/GYtjU4sfKQeCjY3 MgfyRk6Z3BEO83Wb8x0kc8vt/K+TYvOlwqIZ7n/rhCNc/Z88lqfphYVSse2PNHrrgmTh Vdt3BABgLQlWyNXFGv+B6FZoqr4X0LaWkvyDViUIDl8vA/rYaQDziy4QeqTmAN+8n/JB FYxj3hynX+5LoPedVjqNEZainnIwUlvzLgJqhOKm5sEAhWW6ANBiYZnMrJ2VnMMi1P24 9nng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718574951; x=1719179751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nzWmmV5lLGO/kDDsghSyyH6GIF1fBoQT5IQ42I5GYNY=; b=gSXEo8vm3hboiRD1gaWBW0XnkzF/yDsoskDE3GhXJkoec1TZA5XR6d7S2cbFCvXSrG fGkGtqBLm6+7vsWKMq05VxnpVBjdU8BFBGgOeAZLRGp5shKtILP9kxbdP2YisqoE/Tzx h0cc3P86fpO2vF8jmHD8SAyroccaEDvHNz3WgZ89YNzR3bGX3sAK3kAsFomUIP16Podf QP1UxkTfC99kTVLRUCVzaT7QEmwMjksQKdEdXI9EzoJxDiIK2MdLOSqLn0wBw6+0eJz9 0VsPkAn4R41OBr/CbN44RMW1R/+2bffkhZPBKxSEkypeYIM9ILM6k3yKWz1I+6LUll6a JRTw== X-Forwarded-Encrypted: i=1; AJvYcCUqd/PEAdqIeS/c+2SJTnvd3UDVmSYA/N+UQAlTczEgoeCE2U0R23UxotqJ5Kz5ukMg7s3ebT/kjbo9ipUQ+4+lLy4WTJqU8eMtHCmMeitUIeAfSQ6u/t+gNdHmg/rD43d+AICkGGdQBLuVDDzQZi4QSJK8QPJeDx+q+ygMA0ZEFWcdoHw= X-Gm-Message-State: AOJu0Yw74gbl2xKwBK50sXuYyGC8dwOrKf6BXPtOikr0J4AuPUAwuUL/ CgqnjuS7EpXA+kZwikpJZIG3LCjW6NOTeHHRX6YtCGkrFHLMhr09 X-Google-Smtp-Source: AGHT+IFb4jmTzPLeORZUwEaD95ny3WMX/WHU5M5q/TLFkTF9pMQxCRBr+cziJ7Fu8BJAwLs4CjlsYA== X-Received: by 2002:a5d:528b:0:b0:35f:488:6d3d with SMTP id ffacd0b85a97d-3607a781081mr5222801f8f.58.1718574951397; Sun, 16 Jun 2024 14:55:51 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-36075104b74sm10362879f8f.107.2024.06.16.14.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 14:55:50 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jacek Anaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v6 04/20] leds: leds-lp55xx: generalize probe/remove functions Date: Sun, 16 Jun 2024 23:52:03 +0200 Message-ID: <20240616215226.2112-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com> References: <20240616215226.2112-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that stop_all_engine is generalized, probe and remove function are the same across every lp55xx based LED driver and can be generalized. To permit to use a common probe, make use of the OF match_data and i2c driver_data value to store the device_config struct specific for the LED. Also drop the now unused exported symbol in lp55xx-common and make them static. Update any lp55xx based LED driver to use the new generic probe/remove. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 81 +------------------- drivers/leds/leds-lp5523.c | 85 ++------------------- drivers/leds/leds-lp5562.c | 80 +------------------ drivers/leds/leds-lp55xx-common.c | 123 +++++++++++++++++++++++------- drivers/leds/leds-lp55xx-common.h | 21 +---- drivers/leds/leds-lp8501.c | 81 +------------------- 6 files changed, 119 insertions(+), 352 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 15ef5ae58623..5015f385cc17 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -514,87 +514,14 @@ static struct lp55xx_device_config lp5521_cfg =3D { .dev_attr_group =3D &lp5521_group, }; =20 -static int lp5521_probe(struct i2c_client *client) -{ - const struct i2c_device_id *id =3D i2c_client_get_device_id(client); - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata =3D dev_get_platdata(&client->dev); - struct device_node *np =3D dev_of_node(&client->dev); - - chip =3D devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg =3D &lp5521_cfg; - - if (!pdata) { - if (np) { - pdata =3D lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - led =3D devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl =3D client; - chip->pdata =3D pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret =3D lp55xx_init_device(chip); - if (ret) - goto err_init; - - dev_info(&client->dev, "%s programmable led chip found\n", id->name); - - ret =3D lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret =3D lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5521_remove(struct i2c_client *client) -{ - struct lp55xx_led *led =3D i2c_get_clientdata(client); - struct lp55xx_chip *chip =3D led->chip; - - lp55xx_stop_all_engine(chip); - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5521_id[] =3D { - { "lp5521", 0 }, /* Three channel chip */ + { "lp5521", .driver_data =3D (kernel_ulong_t)&lp5521_cfg, }, /* Three cha= nnel chip */ { } }; MODULE_DEVICE_TABLE(i2c, lp5521_id); =20 static const struct of_device_id of_lp5521_leds_match[] =3D { - { .compatible =3D "national,lp5521", }, + { .compatible =3D "national,lp5521", .data =3D &lp5521_cfg, }, {}, }; =20 @@ -605,8 +532,8 @@ static struct i2c_driver lp5521_driver =3D { .name =3D "lp5521", .of_match_table =3D of_lp5521_leds_match, }, - .probe =3D lp5521_probe, - .remove =3D lp5521_remove, + .probe =3D lp55xx_probe, + .remove =3D lp55xx_remove, .id_table =3D lp5521_id, }; =20 diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 79931555eddd..bd0209e2ee42 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -895,90 +895,17 @@ static struct lp55xx_device_config lp5523_cfg =3D { .dev_attr_group =3D &lp5523_group, }; =20 -static int lp5523_probe(struct i2c_client *client) -{ - const struct i2c_device_id *id =3D i2c_client_get_device_id(client); - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata =3D dev_get_platdata(&client->dev); - struct device_node *np =3D dev_of_node(&client->dev); - - chip =3D devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg =3D &lp5523_cfg; - - if (!pdata) { - if (np) { - pdata =3D lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - led =3D devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl =3D client; - chip->pdata =3D pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret =3D lp55xx_init_device(chip); - if (ret) - goto err_init; - - dev_info(&client->dev, "%s Programmable led chip found\n", id->name); - - ret =3D lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret =3D lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5523_remove(struct i2c_client *client) -{ - struct lp55xx_led *led =3D i2c_get_clientdata(client); - struct lp55xx_chip *chip =3D led->chip; - - lp55xx_stop_all_engine(chip); - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5523_id[] =3D { - { "lp5523", LP5523 }, - { "lp55231", LP55231 }, + { "lp5523", .driver_data =3D (kernel_ulong_t)&lp5523_cfg, }, + { "lp55231", .driver_data =3D (kernel_ulong_t)&lp5523_cfg, }, { } }; =20 MODULE_DEVICE_TABLE(i2c, lp5523_id); =20 static const struct of_device_id of_lp5523_leds_match[] =3D { - { .compatible =3D "national,lp5523", }, - { .compatible =3D "ti,lp55231", }, + { .compatible =3D "national,lp5523", .data =3D &lp5523_cfg, }, + { .compatible =3D "ti,lp55231", .data =3D &lp5523_cfg, }, {}, }; =20 @@ -989,8 +916,8 @@ static struct i2c_driver lp5523_driver =3D { .name =3D "lp5523x", .of_match_table =3D of_lp5523_leds_match, }, - .probe =3D lp5523_probe, - .remove =3D lp5523_remove, + .probe =3D lp55xx_probe, + .remove =3D lp55xx_remove, .id_table =3D lp5523_id, }; =20 diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 28469bd2c75b..65a6a05c3848 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -508,86 +508,14 @@ static struct lp55xx_device_config lp5562_cfg =3D { .dev_attr_group =3D &lp5562_group, }; =20 -static int lp5562_probe(struct i2c_client *client) -{ - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata =3D dev_get_platdata(&client->dev); - struct device_node *np =3D dev_of_node(&client->dev); - - chip =3D devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg =3D &lp5562_cfg; - - if (!pdata) { - if (np) { - pdata =3D lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - - led =3D devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl =3D client; - chip->pdata =3D pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret =3D lp55xx_init_device(chip); - if (ret) - goto err_init; - - ret =3D lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret =3D lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp5562_remove(struct i2c_client *client) -{ - struct lp55xx_led *led =3D i2c_get_clientdata(client); - struct lp55xx_chip *chip =3D led->chip; - - lp55xx_stop_all_engine(chip); - - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp5562_id[] =3D { - { "lp5562", 0 }, + { "lp5562", .driver_data =3D (kernel_ulong_t)&lp5562_cfg, }, { } }; MODULE_DEVICE_TABLE(i2c, lp5562_id); =20 static const struct of_device_id of_lp5562_leds_match[] =3D { - { .compatible =3D "ti,lp5562", }, + { .compatible =3D "ti,lp5562", .data =3D &lp5562_cfg, }, {}, }; =20 @@ -598,8 +526,8 @@ static struct i2c_driver lp5562_driver =3D { .name =3D "lp5562", .of_match_table =3D of_lp5562_leds_match, }, - .probe =3D lp5562_probe, - .remove =3D lp5562_remove, + .probe =3D lp55xx_probe, + .remove =3D lp55xx_remove, .id_table =3D lp5562_id, }; =20 diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-c= ommon.c index 2cbc5b302fd4..7e623e4e565c 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -32,6 +32,8 @@ /* External clock rate */ #define LP55XX_CLK_32K 32768 =20 +static void lp55xx_deinit_device(struct lp55xx_chip *chip); + static struct lp55xx_led *cdev_to_lp55xx_led(struct led_classdev *cdev) { return container_of(cdev, struct lp55xx_led, cdev); @@ -49,7 +51,7 @@ static struct lp55xx_led *mcled_cdev_to_led(struct led_cl= assdev_mc *mc_cdev) =20 static void lp55xx_wait_opmode_done(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; int __always_unused ret; u8 val; =20 @@ -69,7 +71,7 @@ static void lp55xx_wait_opmode_done(struct lp55xx_chip *c= hip) =20 void lp55xx_stop_all_engine(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; =20 lp55xx_write(chip, cfg->reg_op_mode.addr, LP55xx_MODE_DISABLE_ALL_ENG); lp55xx_wait_opmode_done(chip); @@ -78,7 +80,7 @@ EXPORT_SYMBOL_GPL(lp55xx_stop_all_engine); =20 static void lp55xx_reset_device(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; u8 addr =3D cfg->reset.addr; u8 val =3D cfg->reset.val; =20 @@ -88,7 +90,7 @@ static void lp55xx_reset_device(struct lp55xx_chip *chip) =20 static int lp55xx_detect_device(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; u8 addr =3D cfg->enable.addr; u8 val =3D cfg->enable.val; int ret; @@ -111,7 +113,7 @@ static int lp55xx_detect_device(struct lp55xx_chip *chi= p) =20 static int lp55xx_post_init_device(struct lp55xx_chip *chip) { - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; =20 if (!cfg->post_init_device) return 0; @@ -176,7 +178,7 @@ static int lp55xx_set_mc_brightness(struct led_classdev= *cdev, { struct led_classdev_mc *mc_dev =3D lcdev_to_mccdev(cdev); struct lp55xx_led *led =3D mcled_cdev_to_led(mc_dev); - struct lp55xx_device_config *cfg =3D led->chip->cfg; + const struct lp55xx_device_config *cfg =3D led->chip->cfg; =20 led_mc_calc_color_components(&led->mc_cdev, brightness); return cfg->multicolor_brightness_fn(led); @@ -187,7 +189,7 @@ static int lp55xx_set_brightness(struct led_classdev *c= dev, enum led_brightness brightness) { struct lp55xx_led *led =3D cdev_to_lp55xx_led(cdev); - struct lp55xx_device_config *cfg =3D led->chip->cfg; + const struct lp55xx_device_config *cfg =3D led->chip->cfg; =20 led->brightness =3D (u8)brightness; return cfg->brightness_fn(led); @@ -197,7 +199,7 @@ static int lp55xx_init_led(struct lp55xx_led *led, struct lp55xx_chip *chip, int chan) { struct lp55xx_platform_data *pdata =3D chip->pdata; - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; struct device *dev =3D &chip->cl->dev; int max_channel =3D cfg->max_channel; struct mc_subled *mc_led_info; @@ -459,10 +461,10 @@ bool lp55xx_is_extclk_used(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_is_extclk_used); =20 -int lp55xx_init_device(struct lp55xx_chip *chip) +static int lp55xx_init_device(struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata; - struct lp55xx_device_config *cfg; + const struct lp55xx_device_config *cfg; struct device *dev =3D &chip->cl->dev; int ret =3D 0; =20 @@ -512,9 +514,8 @@ int lp55xx_init_device(struct lp55xx_chip *chip) err: return ret; } -EXPORT_SYMBOL_GPL(lp55xx_init_device); =20 -void lp55xx_deinit_device(struct lp55xx_chip *chip) +static void lp55xx_deinit_device(struct lp55xx_chip *chip) { struct lp55xx_platform_data *pdata =3D chip->pdata; =20 @@ -524,12 +525,11 @@ void lp55xx_deinit_device(struct lp55xx_chip *chip) if (pdata->enable_gpiod) gpiod_set_value(pdata->enable_gpiod, 0); } -EXPORT_SYMBOL_GPL(lp55xx_deinit_device); =20 -int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) +static int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip= *chip) { struct lp55xx_platform_data *pdata =3D chip->pdata; - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; int num_channels =3D pdata->num_channels; struct lp55xx_led *each; u8 led_current; @@ -566,12 +566,11 @@ int lp55xx_register_leds(struct lp55xx_led *led, stru= ct lp55xx_chip *chip) err_init_led: return ret; } -EXPORT_SYMBOL_GPL(lp55xx_register_leds); =20 -int lp55xx_register_sysfs(struct lp55xx_chip *chip) +static int lp55xx_register_sysfs(struct lp55xx_chip *chip) { struct device *dev =3D &chip->cl->dev; - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; int ret; =20 if (!cfg->run_engine || !cfg->firmware_cb) @@ -585,19 +584,17 @@ int lp55xx_register_sysfs(struct lp55xx_chip *chip) return cfg->dev_attr_group ? sysfs_create_group(&dev->kobj, cfg->dev_attr_group) : 0; } -EXPORT_SYMBOL_GPL(lp55xx_register_sysfs); =20 -void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) +static void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) { struct device *dev =3D &chip->cl->dev; - struct lp55xx_device_config *cfg =3D chip->cfg; + const struct lp55xx_device_config *cfg =3D chip->cfg; =20 if (cfg->dev_attr_group) sysfs_remove_group(&dev->kobj, cfg->dev_attr_group); =20 sysfs_remove_group(&dev->kobj, &lp55xx_engine_attr_group); } -EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs); =20 static int lp55xx_parse_common_child(struct device_node *np, struct lp55xx_led_config *cfg, @@ -690,9 +687,9 @@ static int lp55xx_parse_logical_led(struct device_node = *np, return ret; } =20 -struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, - struct device_node *np, - struct lp55xx_chip *chip) +static struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device= *dev, + struct device_node *np, + struct lp55xx_chip *chip) { struct device_node *child; struct lp55xx_platform_data *pdata; @@ -749,7 +746,81 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(= struct device *dev, =20 return pdata; } -EXPORT_SYMBOL_GPL(lp55xx_of_populate_pdata); + +int lp55xx_probe(struct i2c_client *client) +{ + const struct i2c_device_id *id =3D i2c_client_get_device_id(client); + int ret; + struct lp55xx_chip *chip; + struct lp55xx_led *led; + struct lp55xx_platform_data *pdata =3D dev_get_platdata(&client->dev); + struct device_node *np =3D dev_of_node(&client->dev); + + chip =3D devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->cfg =3D i2c_get_match_data(client); + + if (!pdata) { + if (np) { + pdata =3D lp55xx_of_populate_pdata(&client->dev, np, + chip); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + } else { + dev_err(&client->dev, "no platform data\n"); + return -EINVAL; + } + } + + led =3D devm_kcalloc(&client->dev, + pdata->num_channels, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + chip->cl =3D client; + chip->pdata =3D pdata; + + mutex_init(&chip->lock); + + i2c_set_clientdata(client, led); + + ret =3D lp55xx_init_device(chip); + if (ret) + goto err_init; + + dev_info(&client->dev, "%s Programmable led chip found\n", id->name); + + ret =3D lp55xx_register_leds(led, chip); + if (ret) + goto err_out; + + ret =3D lp55xx_register_sysfs(chip); + if (ret) { + dev_err(&client->dev, "registering sysfs failed\n"); + goto err_out; + } + + return 0; + +err_out: + lp55xx_deinit_device(chip); +err_init: + return ret; +} +EXPORT_SYMBOL_GPL(lp55xx_probe); + +void lp55xx_remove(struct i2c_client *client) +{ + struct lp55xx_led *led =3D i2c_get_clientdata(client); + struct lp55xx_chip *chip =3D led->chip; + + lp55xx_stop_all_engine(chip); + lp55xx_unregister_sysfs(chip); + lp55xx_deinit_device(chip); +} +EXPORT_SYMBOL_GPL(lp55xx_remove); =20 MODULE_AUTHOR("Milo Kim "); MODULE_DESCRIPTION("LP55xx Common Driver"); diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-c= ommon.h index c7c8a77ddb1a..26a724acac16 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -164,7 +164,7 @@ struct lp55xx_chip { struct lp55xx_platform_data *pdata; struct mutex lock; /* lock for user-space interface */ int num_leds; - struct lp55xx_device_config *cfg; + const struct lp55xx_device_config *cfg; enum lp55xx_engine_index engine_idx; struct lp55xx_engine engines[LP55XX_ENGINE_MAX]; const struct firmware *fw; @@ -203,21 +203,8 @@ extern bool lp55xx_is_extclk_used(struct lp55xx_chip *= chip); /* common chip functions */ extern void lp55xx_stop_all_engine(struct lp55xx_chip *chip); =20 -/* common device init/deinit functions */ -extern int lp55xx_init_device(struct lp55xx_chip *chip); -extern void lp55xx_deinit_device(struct lp55xx_chip *chip); - -/* common LED class device functions */ -extern int lp55xx_register_leds(struct lp55xx_led *led, - struct lp55xx_chip *chip); - -/* common device attributes functions */ -extern int lp55xx_register_sysfs(struct lp55xx_chip *chip); -extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip); - -/* common device tree population function */ -extern struct lp55xx_platform_data -*lp55xx_of_populate_pdata(struct device *dev, struct device_node *np, - struct lp55xx_chip *chip); +/* common probe/remove function */ +extern int lp55xx_probe(struct i2c_client *client); +extern void lp55xx_remove(struct i2c_client *client); =20 #endif /* _LEDS_LP55XX_COMMON_H */ diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 57e184dda490..d3c718bb8275 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -305,87 +305,14 @@ static struct lp55xx_device_config lp8501_cfg =3D { .run_engine =3D lp8501_run_engine, }; =20 -static int lp8501_probe(struct i2c_client *client) -{ - const struct i2c_device_id *id =3D i2c_client_get_device_id(client); - int ret; - struct lp55xx_chip *chip; - struct lp55xx_led *led; - struct lp55xx_platform_data *pdata =3D dev_get_platdata(&client->dev); - struct device_node *np =3D dev_of_node(&client->dev); - - chip =3D devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->cfg =3D &lp8501_cfg; - - if (!pdata) { - if (np) { - pdata =3D lp55xx_of_populate_pdata(&client->dev, np, - chip); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; - } - } - - led =3D devm_kcalloc(&client->dev, - pdata->num_channels, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - chip->cl =3D client; - chip->pdata =3D pdata; - - mutex_init(&chip->lock); - - i2c_set_clientdata(client, led); - - ret =3D lp55xx_init_device(chip); - if (ret) - goto err_init; - - dev_info(&client->dev, "%s Programmable led chip found\n", id->name); - - ret =3D lp55xx_register_leds(led, chip); - if (ret) - goto err_out; - - ret =3D lp55xx_register_sysfs(chip); - if (ret) { - dev_err(&client->dev, "registering sysfs failed\n"); - goto err_out; - } - - return 0; - -err_out: - lp55xx_deinit_device(chip); -err_init: - return ret; -} - -static void lp8501_remove(struct i2c_client *client) -{ - struct lp55xx_led *led =3D i2c_get_clientdata(client); - struct lp55xx_chip *chip =3D led->chip; - - lp55xx_stop_all_engine(chip); - lp55xx_unregister_sysfs(chip); - lp55xx_deinit_device(chip); -} - static const struct i2c_device_id lp8501_id[] =3D { - { "lp8501", 0 }, + { "lp8501", .driver_data =3D (kernel_ulong_t)&lp8501_cfg, }, { } }; MODULE_DEVICE_TABLE(i2c, lp8501_id); =20 static const struct of_device_id of_lp8501_leds_match[] =3D { - { .compatible =3D "ti,lp8501", }, + { .compatible =3D "ti,lp8501", .data =3D &lp8501_cfg, }, {}, }; =20 @@ -396,8 +323,8 @@ static struct i2c_driver lp8501_driver =3D { .name =3D "lp8501", .of_match_table =3D of_lp8501_leds_match, }, - .probe =3D lp8501_probe, - .remove =3D lp8501_remove, + .probe =3D lp55xx_probe, + .remove =3D lp55xx_remove, .id_table =3D lp8501_id, }; =20 --=20 2.43.0