From patchwork Fri May 31 16:56:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13681952 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83105C25B75 for ; Fri, 31 May 2024 17:09:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6CA4010E7F1; Fri, 31 May 2024 17:09:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="nDuQIY8y"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id CD05B10E597 for ; Fri, 31 May 2024 17:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717175333; x=1748711333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2q9QlVI/f03rYQOTivHmu7hY6K+c4OWLLJUjCRQkbws=; b=nDuQIY8y8gDssppzYDEwpzUduB8uzK1OO6h6EhllpNlcuanITXV+IB1c xd7B7yZkHBI4fpxNsc5zpM4Sar7uBk7VEaXkSIrcioGvcEU/osieUaPcu +JvDoVslpLbcNo7u4STHrNsr29IGZBIFnl+u19kFcrsD21jpR6IaJBDUJ BTGDpt9feqdgPUUILzPAdUeGpwjltWfKwie8vXlKKODYcyaScZPmxqr62 nYRdTduhOnua/GHQc6OJWyE1443K80AZexy15JD3k9yHeuxi+yiFbQ1JI 6VOOuSe/bXhZGx+FajL1dUbe1vsWwWM3XBCX2TX9iPEHOj3Jfl0w/nQHi g==; X-CSE-ConnectionGUID: Wp60f4OeTkWSCJPFpKcuPA== X-CSE-MsgGUID: E3u/zG53RU+iN73EruogvQ== X-IronPort-AV: E=McAfee;i="6600,9927,11089"; a="31224221" X-IronPort-AV: E=Sophos;i="6.08,204,1712646000"; d="scan'208";a="31224221" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2024 10:08:52 -0700 X-CSE-ConnectionGUID: 6bL+POsfQ1erow9TF+gXiQ== X-CSE-MsgGUID: EY23vCM3TpKv+kpk32iFsA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,204,1712646000"; d="scan'208";a="36163155" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa010.jf.intel.com with ESMTP; 31 May 2024 10:08:49 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7EAE0136; Fri, 31 May 2024 20:08:46 +0300 (EEST) From: Andy Shevchenko To: Jonathan Cameron , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , Lee Jones , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Pavel Machek , Daniel Thompson , Jingoo Han , Helge Deller , Johan Hovold Subject: [PATCH v1 1/4] backlight: lm3533_bl: Remove the driver Date: Fri, 31 May 2024 19:56:13 +0300 Message-ID: <20240531170844.1595468-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240531170844.1595468-1-andriy.shevchenko@linux.intel.com> References: <20240531170844.1595468-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The driver has no in kernel users and requires a board file to be instantiated. Remove basically a dead code. If ever needed, it can be reinstantiated and converted to one that uses firmware node interfaces. Signed-off-by: Andy Shevchenko --- drivers/video/backlight/Kconfig | 11 - drivers/video/backlight/Makefile | 1 - drivers/video/backlight/lm3533_bl.c | 399 ---------------------------- 3 files changed, 411 deletions(-) delete mode 100644 drivers/video/backlight/lm3533_bl.c diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index 230bca07b09d..91d6618d69a0 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig @@ -198,17 +198,6 @@ config BACKLIGHT_KTZ8866 Say Y to enable the backlight driver for the Kinetic KTZ8866 found in Xiaomi Mi Pad 5 series. -config BACKLIGHT_LM3533 - tristate "Backlight Driver for LM3533" - depends on MFD_LM3533 - help - Say Y to enable the backlight driver for National Semiconductor / TI - LM3533 Lighting Power chips. - - The backlights can be controlled directly, through PWM input, or by - the ambient-light-sensor interface. The chip supports 256 brightness - levels. - config BACKLIGHT_LOCOMO tristate "Sharp LOCOMO LCD/Backlight Driver" depends on SHARP_LOCOMO diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index 8d2cb252042d..fc75b9f059f9 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile @@ -36,7 +36,6 @@ obj-$(CONFIG_BACKLIGHT_IPAQ_MICRO) += ipaq_micro_bl.o obj-$(CONFIG_BACKLIGHT_KTD253) += ktd253-backlight.o obj-$(CONFIG_BACKLIGHT_KTD2801) += ktd2801-backlight.o obj-$(CONFIG_BACKLIGHT_KTZ8866) += ktz8866.o -obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_bl.o obj-$(CONFIG_BACKLIGHT_LM3630A) += lm3630a_bl.o obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o diff --git a/drivers/video/backlight/lm3533_bl.c b/drivers/video/backlight/lm3533_bl.c deleted file mode 100644 index 3e10d480cb7f..000000000000 --- a/drivers/video/backlight/lm3533_bl.c +++ /dev/null @@ -1,399 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * lm3533-bl.c -- LM3533 Backlight driver - * - * Copyright (C) 2011-2012 Texas Instruments - * - * Author: Johan Hovold - */ - -#include -#include -#include -#include -#include -#include - -#include - - -#define LM3533_HVCTRLBANK_COUNT 2 -#define LM3533_BL_MAX_BRIGHTNESS 255 - -#define LM3533_REG_CTRLBANK_AB_BCONF 0x1a - - -struct lm3533_bl { - struct lm3533 *lm3533; - struct lm3533_ctrlbank cb; - struct backlight_device *bd; - int id; -}; - - -static inline int lm3533_bl_get_ctrlbank_id(struct lm3533_bl *bl) -{ - return bl->id; -} - -static int lm3533_bl_update_status(struct backlight_device *bd) -{ - struct lm3533_bl *bl = bl_get_data(bd); - - return lm3533_ctrlbank_set_brightness(&bl->cb, backlight_get_brightness(bd)); -} - -static int lm3533_bl_get_brightness(struct backlight_device *bd) -{ - struct lm3533_bl *bl = bl_get_data(bd); - u8 val; - int ret; - - ret = lm3533_ctrlbank_get_brightness(&bl->cb, &val); - if (ret) - return ret; - - return val; -} - -static const struct backlight_ops lm3533_bl_ops = { - .get_brightness = lm3533_bl_get_brightness, - .update_status = lm3533_bl_update_status, -}; - -static ssize_t show_id(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - - return scnprintf(buf, PAGE_SIZE, "%d\n", bl->id); -} - -static ssize_t show_als_channel(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - unsigned channel = lm3533_bl_get_ctrlbank_id(bl); - - return scnprintf(buf, PAGE_SIZE, "%u\n", channel); -} - -static ssize_t show_als_en(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - int ctrlbank = lm3533_bl_get_ctrlbank_id(bl); - u8 val; - u8 mask; - bool enable; - int ret; - - ret = lm3533_read(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, &val); - if (ret) - return ret; - - mask = 1 << (2 * ctrlbank); - enable = val & mask; - - return scnprintf(buf, PAGE_SIZE, "%d\n", enable); -} - -static ssize_t store_als_en(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - int ctrlbank = lm3533_bl_get_ctrlbank_id(bl); - int enable; - u8 val; - u8 mask; - int ret; - - if (kstrtoint(buf, 0, &enable)) - return -EINVAL; - - mask = 1 << (2 * ctrlbank); - - if (enable) - val = mask; - else - val = 0; - - ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, val, - mask); - if (ret) - return ret; - - return len; -} - -static ssize_t show_linear(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - u8 val; - u8 mask; - int linear; - int ret; - - ret = lm3533_read(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, &val); - if (ret) - return ret; - - mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1); - - if (val & mask) - linear = 1; - else - linear = 0; - - return scnprintf(buf, PAGE_SIZE, "%x\n", linear); -} - -static ssize_t store_linear(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - unsigned long linear; - u8 mask; - u8 val; - int ret; - - if (kstrtoul(buf, 0, &linear)) - return -EINVAL; - - mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1); - - if (linear) - val = mask; - else - val = 0; - - ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, val, - mask); - if (ret) - return ret; - - return len; -} - -static ssize_t show_pwm(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - u8 val; - int ret; - - ret = lm3533_ctrlbank_get_pwm(&bl->cb, &val); - if (ret) - return ret; - - return scnprintf(buf, PAGE_SIZE, "%u\n", val); -} - -static ssize_t store_pwm(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - u8 val; - int ret; - - if (kstrtou8(buf, 0, &val)) - return -EINVAL; - - ret = lm3533_ctrlbank_set_pwm(&bl->cb, val); - if (ret) - return ret; - - return len; -} - -static LM3533_ATTR_RO(als_channel); -static LM3533_ATTR_RW(als_en); -static LM3533_ATTR_RO(id); -static LM3533_ATTR_RW(linear); -static LM3533_ATTR_RW(pwm); - -static struct attribute *lm3533_bl_attributes[] = { - &dev_attr_als_channel.attr, - &dev_attr_als_en.attr, - &dev_attr_id.attr, - &dev_attr_linear.attr, - &dev_attr_pwm.attr, - NULL, -}; - -static umode_t lm3533_bl_attr_is_visible(struct kobject *kobj, - struct attribute *attr, int n) -{ - struct device *dev = kobj_to_dev(kobj); - struct lm3533_bl *bl = dev_get_drvdata(dev); - umode_t mode = attr->mode; - - if (attr == &dev_attr_als_channel.attr || - attr == &dev_attr_als_en.attr) { - if (!bl->lm3533->have_als) - mode = 0; - } - - return mode; -}; - -static struct attribute_group lm3533_bl_attribute_group = { - .is_visible = lm3533_bl_attr_is_visible, - .attrs = lm3533_bl_attributes -}; - -static int lm3533_bl_setup(struct lm3533_bl *bl, - struct lm3533_bl_platform_data *pdata) -{ - int ret; - - ret = lm3533_ctrlbank_set_max_current(&bl->cb, pdata->max_current); - if (ret) - return ret; - - return lm3533_ctrlbank_set_pwm(&bl->cb, pdata->pwm); -} - -static int lm3533_bl_probe(struct platform_device *pdev) -{ - struct lm3533 *lm3533; - struct lm3533_bl_platform_data *pdata; - struct lm3533_bl *bl; - struct backlight_device *bd; - struct backlight_properties props; - int ret; - - dev_dbg(&pdev->dev, "%s\n", __func__); - - lm3533 = dev_get_drvdata(pdev->dev.parent); - if (!lm3533) - return -EINVAL; - - pdata = dev_get_platdata(&pdev->dev); - if (!pdata) { - dev_err(&pdev->dev, "no platform data\n"); - return -EINVAL; - } - - if (pdev->id < 0 || pdev->id >= LM3533_HVCTRLBANK_COUNT) { - dev_err(&pdev->dev, "illegal backlight id %d\n", pdev->id); - return -EINVAL; - } - - bl = devm_kzalloc(&pdev->dev, sizeof(*bl), GFP_KERNEL); - if (!bl) - return -ENOMEM; - - bl->lm3533 = lm3533; - bl->id = pdev->id; - - bl->cb.lm3533 = lm3533; - bl->cb.id = lm3533_bl_get_ctrlbank_id(bl); - bl->cb.dev = NULL; /* until registered */ - - memset(&props, 0, sizeof(props)); - props.type = BACKLIGHT_RAW; - props.max_brightness = LM3533_BL_MAX_BRIGHTNESS; - props.brightness = pdata->default_brightness; - bd = devm_backlight_device_register(&pdev->dev, pdata->name, - pdev->dev.parent, bl, &lm3533_bl_ops, - &props); - if (IS_ERR(bd)) { - dev_err(&pdev->dev, "failed to register backlight device\n"); - return PTR_ERR(bd); - } - - bl->bd = bd; - bl->cb.dev = &bl->bd->dev; - - platform_set_drvdata(pdev, bl); - - ret = sysfs_create_group(&bd->dev.kobj, &lm3533_bl_attribute_group); - if (ret < 0) { - dev_err(&pdev->dev, "failed to create sysfs attributes\n"); - return ret; - } - - backlight_update_status(bd); - - ret = lm3533_bl_setup(bl, pdata); - if (ret) - goto err_sysfs_remove; - - ret = lm3533_ctrlbank_enable(&bl->cb); - if (ret) - goto err_sysfs_remove; - - return 0; - -err_sysfs_remove: - sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group); - - return ret; -} - -static void lm3533_bl_remove(struct platform_device *pdev) -{ - struct lm3533_bl *bl = platform_get_drvdata(pdev); - struct backlight_device *bd = bl->bd; - - dev_dbg(&bd->dev, "%s\n", __func__); - - bd->props.power = FB_BLANK_POWERDOWN; - bd->props.brightness = 0; - - lm3533_ctrlbank_disable(&bl->cb); - sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group); -} - -#ifdef CONFIG_PM_SLEEP -static int lm3533_bl_suspend(struct device *dev) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - - dev_dbg(dev, "%s\n", __func__); - - return lm3533_ctrlbank_disable(&bl->cb); -} - -static int lm3533_bl_resume(struct device *dev) -{ - struct lm3533_bl *bl = dev_get_drvdata(dev); - - dev_dbg(dev, "%s\n", __func__); - - return lm3533_ctrlbank_enable(&bl->cb); -} -#endif - -static SIMPLE_DEV_PM_OPS(lm3533_bl_pm_ops, lm3533_bl_suspend, lm3533_bl_resume); - -static void lm3533_bl_shutdown(struct platform_device *pdev) -{ - struct lm3533_bl *bl = platform_get_drvdata(pdev); - - dev_dbg(&pdev->dev, "%s\n", __func__); - - lm3533_ctrlbank_disable(&bl->cb); -} - -static struct platform_driver lm3533_bl_driver = { - .driver = { - .name = "lm3533-backlight", - .pm = &lm3533_bl_pm_ops, - }, - .probe = lm3533_bl_probe, - .remove_new = lm3533_bl_remove, - .shutdown = lm3533_bl_shutdown, -}; -module_platform_driver(lm3533_bl_driver); - -MODULE_AUTHOR("Johan Hovold "); -MODULE_DESCRIPTION("LM3533 Backlight driver"); -MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:lm3533-backlight"); From patchwork Fri May 31 16:56:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13681951 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF3D4C25B7E for ; Fri, 31 May 2024 17:09:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0520510E3BC; Fri, 31 May 2024 17:08:55 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="OWKiGAQ+"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5924E10E662 for ; Fri, 31 May 2024 17:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717175333; x=1748711333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FS60TBEE/wruQULKObXrlgrM94WKm93IKkchS2QxQho=; b=OWKiGAQ+HWdrzrzy2Mh0e85m8YxBhY6TIb0VQuGjDlNwTlP+kMeosZES lkPSMDXRkcawo6ZHjFwxH8vHNTefvdHnEjtr+hR9YyTtvhFOYWv4+WBGJ 4t1fn7CeLTeXxolhMzc1Yg7MpcORHR1nxQ9GQV2Zl48vsPpOWe+1QhTcw mbGzehaIutQ42dMMvzOmGgl+QH2q79Ag+J32EJdNOibmD5y4q3QOxI+RB 3errszzDf9+b7+sbrS23jupUixHQbLVe6gC5k4aqRa+824Mamjfrtd4O0 eVOvgYyhzA7XgBBy+rY2Nn+WHgEKwA9jnLn7Xt13LaLfk9wG55/S6uft/ Q==; X-CSE-ConnectionGUID: jPUUvifjQwyse7boMNvTBQ== X-CSE-MsgGUID: JOioIw99TH2yH9/5xMvWWw== X-IronPort-AV: E=McAfee;i="6600,9927,11089"; a="25131919" X-IronPort-AV: E=Sophos;i="6.08,204,1712646000"; d="scan'208";a="25131919" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2024 10:08:52 -0700 X-CSE-ConnectionGUID: cvEFmdX4So6HAMsOyfD9HA== X-CSE-MsgGUID: 0Ps6g+LnRyuqFBdTbcOLLg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,204,1712646000"; d="scan'208";a="36147844" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa007.fm.intel.com with ESMTP; 31 May 2024 10:08:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8FB0641D; Fri, 31 May 2024 20:08:46 +0300 (EEST) From: Andy Shevchenko To: Jonathan Cameron , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , Lee Jones , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Pavel Machek , Daniel Thompson , Jingoo Han , Helge Deller , Johan Hovold Subject: [PATCH v1 2/4] iio: light: lm3533-als: Remove the driver Date: Fri, 31 May 2024 19:56:14 +0300 Message-ID: <20240531170844.1595468-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240531170844.1595468-1-andriy.shevchenko@linux.intel.com> References: <20240531170844.1595468-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The driver has no in kernel users and requires a board file to be instantiated. Remove basically a dead code. If ever needed, it can be reinstantiated and converted to one that uses firmware node interfaces. Signed-off-by: Andy Shevchenko Acked-by: Jonathan Cameron --- drivers/iio/light/Kconfig | 17 - drivers/iio/light/Makefile | 1 - drivers/iio/light/lm3533-als.c | 922 --------------------------------- 3 files changed, 940 deletions(-) delete mode 100644 drivers/iio/light/lm3533-als.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 9a587d403118..827eee527a62 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -358,23 +358,6 @@ config RPR0521 To compile this driver as a module, choose M here: the module will be called rpr0521. -config SENSORS_LM3533 - tristate "LM3533 ambient light sensor" - depends on MFD_LM3533 - help - If you say yes here you get support for the ambient light sensor - interface on National Semiconductor / TI LM3533 Lighting Power - chips. - - The sensor interface can be used to control the LEDs and backlights - of the chip through defining five light zones and three sets of - corresponding output-current values. - - The driver provides raw and mean adc readings along with the current - light zone through sysfs. A threshold event can be generated on zone - changes. The ALS-control output values can be set per zone for the - three current output channels. - config LTR390 tristate "LTR-390UV-01 ambient light and UV sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index a30f906e91ba..6fd7b6f95d1d 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -31,7 +31,6 @@ obj-$(CONFIG_SENSORS_ISL29028) += isl29028.o obj-$(CONFIG_ISL29125) += isl29125.o obj-$(CONFIG_ISL76682) += isl76682.o obj-$(CONFIG_JSA1212) += jsa1212.o -obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o obj-$(CONFIG_LTR390) += ltr390.o obj-$(CONFIG_LTR501) += ltr501.o obj-$(CONFIG_LTRF216A) += ltrf216a.o diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c deleted file mode 100644 index 7800f7fa51b7..000000000000 --- a/drivers/iio/light/lm3533-als.c +++ /dev/null @@ -1,922 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * lm3533-als.c -- LM3533 Ambient Light Sensor driver - * - * Copyright (C) 2011-2012 Texas Instruments - * - * Author: Johan Hovold - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -#define LM3533_ALS_RESISTOR_MIN 1 -#define LM3533_ALS_RESISTOR_MAX 127 -#define LM3533_ALS_CHANNEL_CURRENT_MAX 2 -#define LM3533_ALS_THRESH_MAX 3 -#define LM3533_ALS_ZONE_MAX 4 - -#define LM3533_REG_ALS_RESISTOR_SELECT 0x30 -#define LM3533_REG_ALS_CONF 0x31 -#define LM3533_REG_ALS_ZONE_INFO 0x34 -#define LM3533_REG_ALS_READ_ADC_RAW 0x37 -#define LM3533_REG_ALS_READ_ADC_AVERAGE 0x38 -#define LM3533_REG_ALS_BOUNDARY_BASE 0x50 -#define LM3533_REG_ALS_TARGET_BASE 0x60 - -#define LM3533_ALS_ENABLE_MASK 0x01 -#define LM3533_ALS_INPUT_MODE_MASK 0x02 -#define LM3533_ALS_INT_ENABLE_MASK 0x01 - -#define LM3533_ALS_ZONE_SHIFT 2 -#define LM3533_ALS_ZONE_MASK 0x1c - -#define LM3533_ALS_FLAG_INT_ENABLED 1 - - -struct lm3533_als { - struct lm3533 *lm3533; - struct platform_device *pdev; - - unsigned long flags; - int irq; - - atomic_t zone; - struct mutex thresh_mutex; -}; - - -static int lm3533_als_get_adc(struct iio_dev *indio_dev, bool average, - int *adc) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 reg; - u8 val; - int ret; - - if (average) - reg = LM3533_REG_ALS_READ_ADC_AVERAGE; - else - reg = LM3533_REG_ALS_READ_ADC_RAW; - - ret = lm3533_read(als->lm3533, reg, &val); - if (ret) { - dev_err(&indio_dev->dev, "failed to read adc\n"); - return ret; - } - - *adc = val; - - return 0; -} - -static int _lm3533_als_get_zone(struct iio_dev *indio_dev, u8 *zone) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 val; - int ret; - - ret = lm3533_read(als->lm3533, LM3533_REG_ALS_ZONE_INFO, &val); - if (ret) { - dev_err(&indio_dev->dev, "failed to read zone\n"); - return ret; - } - - val = (val & LM3533_ALS_ZONE_MASK) >> LM3533_ALS_ZONE_SHIFT; - *zone = min_t(u8, val, LM3533_ALS_ZONE_MAX); - - return 0; -} - -static int lm3533_als_get_zone(struct iio_dev *indio_dev, u8 *zone) -{ - struct lm3533_als *als = iio_priv(indio_dev); - int ret; - - if (test_bit(LM3533_ALS_FLAG_INT_ENABLED, &als->flags)) { - *zone = atomic_read(&als->zone); - } else { - ret = _lm3533_als_get_zone(indio_dev, zone); - if (ret) - return ret; - } - - return 0; -} - -/* - * channel output channel 0..2 - * zone zone 0..4 - */ -static inline u8 lm3533_als_get_target_reg(unsigned channel, unsigned zone) -{ - return LM3533_REG_ALS_TARGET_BASE + 5 * channel + zone; -} - -static int lm3533_als_get_target(struct iio_dev *indio_dev, unsigned channel, - unsigned zone, u8 *val) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 reg; - int ret; - - if (channel > LM3533_ALS_CHANNEL_CURRENT_MAX) - return -EINVAL; - - if (zone > LM3533_ALS_ZONE_MAX) - return -EINVAL; - - reg = lm3533_als_get_target_reg(channel, zone); - ret = lm3533_read(als->lm3533, reg, val); - if (ret) - dev_err(&indio_dev->dev, "failed to get target current\n"); - - return ret; -} - -static int lm3533_als_set_target(struct iio_dev *indio_dev, unsigned channel, - unsigned zone, u8 val) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 reg; - int ret; - - if (channel > LM3533_ALS_CHANNEL_CURRENT_MAX) - return -EINVAL; - - if (zone > LM3533_ALS_ZONE_MAX) - return -EINVAL; - - reg = lm3533_als_get_target_reg(channel, zone); - ret = lm3533_write(als->lm3533, reg, val); - if (ret) - dev_err(&indio_dev->dev, "failed to set target current\n"); - - return ret; -} - -static int lm3533_als_get_current(struct iio_dev *indio_dev, unsigned channel, - int *val) -{ - u8 zone; - u8 target; - int ret; - - ret = lm3533_als_get_zone(indio_dev, &zone); - if (ret) - return ret; - - ret = lm3533_als_get_target(indio_dev, channel, zone, &target); - if (ret) - return ret; - - *val = target; - - return 0; -} - -static int lm3533_als_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) -{ - int ret; - - switch (mask) { - case IIO_CHAN_INFO_RAW: - switch (chan->type) { - case IIO_LIGHT: - ret = lm3533_als_get_adc(indio_dev, false, val); - break; - case IIO_CURRENT: - ret = lm3533_als_get_current(indio_dev, chan->channel, - val); - break; - default: - return -EINVAL; - } - break; - case IIO_CHAN_INFO_AVERAGE_RAW: - ret = lm3533_als_get_adc(indio_dev, true, val); - break; - default: - return -EINVAL; - } - - if (ret) - return ret; - - return IIO_VAL_INT; -} - -#define CHANNEL_CURRENT(_channel) \ - { \ - .type = IIO_CURRENT, \ - .channel = _channel, \ - .indexed = true, \ - .output = true, \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - } - -static const struct iio_chan_spec lm3533_als_channels[] = { - { - .type = IIO_LIGHT, - .channel = 0, - .indexed = true, - .info_mask_separate = BIT(IIO_CHAN_INFO_AVERAGE_RAW) | - BIT(IIO_CHAN_INFO_RAW), - }, - CHANNEL_CURRENT(0), - CHANNEL_CURRENT(1), - CHANNEL_CURRENT(2), -}; - -static irqreturn_t lm3533_als_isr(int irq, void *dev_id) -{ - - struct iio_dev *indio_dev = dev_id; - struct lm3533_als *als = iio_priv(indio_dev); - u8 zone; - int ret; - - /* Clear interrupt by reading the ALS zone register. */ - ret = _lm3533_als_get_zone(indio_dev, &zone); - if (ret) - goto out; - - atomic_set(&als->zone, zone); - - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE(IIO_LIGHT, - 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_EITHER), - iio_get_time_ns(indio_dev)); -out: - return IRQ_HANDLED; -} - -static int lm3533_als_set_int_mode(struct iio_dev *indio_dev, int enable) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 mask = LM3533_ALS_INT_ENABLE_MASK; - u8 val; - int ret; - - if (enable) - val = mask; - else - val = 0; - - ret = lm3533_update(als->lm3533, LM3533_REG_ALS_ZONE_INFO, val, mask); - if (ret) { - dev_err(&indio_dev->dev, "failed to set int mode %d\n", - enable); - return ret; - } - - return 0; -} - -static int lm3533_als_get_int_mode(struct iio_dev *indio_dev, int *enable) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 mask = LM3533_ALS_INT_ENABLE_MASK; - u8 val; - int ret; - - ret = lm3533_read(als->lm3533, LM3533_REG_ALS_ZONE_INFO, &val); - if (ret) { - dev_err(&indio_dev->dev, "failed to get int mode\n"); - return ret; - } - - *enable = !!(val & mask); - - return 0; -} - -static inline u8 lm3533_als_get_threshold_reg(unsigned nr, bool raising) -{ - u8 offset = !raising; - - return LM3533_REG_ALS_BOUNDARY_BASE + 2 * nr + offset; -} - -static int lm3533_als_get_threshold(struct iio_dev *indio_dev, unsigned nr, - bool raising, u8 *val) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 reg; - int ret; - - if (nr > LM3533_ALS_THRESH_MAX) - return -EINVAL; - - reg = lm3533_als_get_threshold_reg(nr, raising); - ret = lm3533_read(als->lm3533, reg, val); - if (ret) - dev_err(&indio_dev->dev, "failed to get threshold\n"); - - return ret; -} - -static int lm3533_als_set_threshold(struct iio_dev *indio_dev, unsigned nr, - bool raising, u8 val) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 val2; - u8 reg, reg2; - int ret; - - if (nr > LM3533_ALS_THRESH_MAX) - return -EINVAL; - - reg = lm3533_als_get_threshold_reg(nr, raising); - reg2 = lm3533_als_get_threshold_reg(nr, !raising); - - mutex_lock(&als->thresh_mutex); - ret = lm3533_read(als->lm3533, reg2, &val2); - if (ret) { - dev_err(&indio_dev->dev, "failed to get threshold\n"); - goto out; - } - /* - * This device does not allow negative hysteresis (in fact, it uses - * whichever value is smaller as the lower bound) so we need to make - * sure that thresh_falling <= thresh_raising. - */ - if ((raising && (val < val2)) || (!raising && (val > val2))) { - ret = -EINVAL; - goto out; - } - - ret = lm3533_write(als->lm3533, reg, val); - if (ret) { - dev_err(&indio_dev->dev, "failed to set threshold\n"); - goto out; - } -out: - mutex_unlock(&als->thresh_mutex); - - return ret; -} - -static int lm3533_als_get_hysteresis(struct iio_dev *indio_dev, unsigned nr, - u8 *val) -{ - struct lm3533_als *als = iio_priv(indio_dev); - u8 falling; - u8 raising; - int ret; - - if (nr > LM3533_ALS_THRESH_MAX) - return -EINVAL; - - mutex_lock(&als->thresh_mutex); - ret = lm3533_als_get_threshold(indio_dev, nr, false, &falling); - if (ret) - goto out; - ret = lm3533_als_get_threshold(indio_dev, nr, true, &raising); - if (ret) - goto out; - - *val = raising - falling; -out: - mutex_unlock(&als->thresh_mutex); - - return ret; -} - -static ssize_t show_thresh_either_en(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct lm3533_als *als = iio_priv(indio_dev); - int enable; - int ret; - - if (als->irq) { - ret = lm3533_als_get_int_mode(indio_dev, &enable); - if (ret) - return ret; - } else { - enable = 0; - } - - return sysfs_emit(buf, "%u\n", enable); -} - -static ssize_t store_thresh_either_en(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct lm3533_als *als = iio_priv(indio_dev); - unsigned long enable; - bool int_enabled; - u8 zone; - int ret; - - if (!als->irq) - return -EBUSY; - - if (kstrtoul(buf, 0, &enable)) - return -EINVAL; - - int_enabled = test_bit(LM3533_ALS_FLAG_INT_ENABLED, &als->flags); - - if (enable && !int_enabled) { - ret = lm3533_als_get_zone(indio_dev, &zone); - if (ret) - return ret; - - atomic_set(&als->zone, zone); - - set_bit(LM3533_ALS_FLAG_INT_ENABLED, &als->flags); - } - - ret = lm3533_als_set_int_mode(indio_dev, enable); - if (ret) { - if (!int_enabled) - clear_bit(LM3533_ALS_FLAG_INT_ENABLED, &als->flags); - - return ret; - } - - if (!enable) - clear_bit(LM3533_ALS_FLAG_INT_ENABLED, &als->flags); - - return len; -} - -static ssize_t show_zone(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - u8 zone; - int ret; - - ret = lm3533_als_get_zone(indio_dev, &zone); - if (ret) - return ret; - - return sysfs_emit(buf, "%u\n", zone); -} - -enum lm3533_als_attribute_type { - LM3533_ATTR_TYPE_HYSTERESIS, - LM3533_ATTR_TYPE_TARGET, - LM3533_ATTR_TYPE_THRESH_FALLING, - LM3533_ATTR_TYPE_THRESH_RAISING, -}; - -struct lm3533_als_attribute { - struct device_attribute dev_attr; - enum lm3533_als_attribute_type type; - u8 val1; - u8 val2; -}; - -static inline struct lm3533_als_attribute * -to_lm3533_als_attr(struct device_attribute *attr) -{ - return container_of(attr, struct lm3533_als_attribute, dev_attr); -} - -static ssize_t show_als_attr(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct lm3533_als_attribute *als_attr = to_lm3533_als_attr(attr); - u8 val; - int ret; - - switch (als_attr->type) { - case LM3533_ATTR_TYPE_HYSTERESIS: - ret = lm3533_als_get_hysteresis(indio_dev, als_attr->val1, - &val); - break; - case LM3533_ATTR_TYPE_TARGET: - ret = lm3533_als_get_target(indio_dev, als_attr->val1, - als_attr->val2, &val); - break; - case LM3533_ATTR_TYPE_THRESH_FALLING: - ret = lm3533_als_get_threshold(indio_dev, als_attr->val1, - false, &val); - break; - case LM3533_ATTR_TYPE_THRESH_RAISING: - ret = lm3533_als_get_threshold(indio_dev, als_attr->val1, - true, &val); - break; - default: - ret = -ENXIO; - } - - if (ret) - return ret; - - return sysfs_emit(buf, "%u\n", val); -} - -static ssize_t store_als_attr(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct lm3533_als_attribute *als_attr = to_lm3533_als_attr(attr); - u8 val; - int ret; - - if (kstrtou8(buf, 0, &val)) - return -EINVAL; - - switch (als_attr->type) { - case LM3533_ATTR_TYPE_TARGET: - ret = lm3533_als_set_target(indio_dev, als_attr->val1, - als_attr->val2, val); - break; - case LM3533_ATTR_TYPE_THRESH_FALLING: - ret = lm3533_als_set_threshold(indio_dev, als_attr->val1, - false, val); - break; - case LM3533_ATTR_TYPE_THRESH_RAISING: - ret = lm3533_als_set_threshold(indio_dev, als_attr->val1, - true, val); - break; - default: - ret = -ENXIO; - } - - if (ret) - return ret; - - return len; -} - -#define ALS_ATTR(_name, _mode, _show, _store, _type, _val1, _val2) \ - { .dev_attr = __ATTR(_name, _mode, _show, _store), \ - .type = _type, \ - .val1 = _val1, \ - .val2 = _val2 } - -#define LM3533_ALS_ATTR(_name, _mode, _show, _store, _type, _val1, _val2) \ - struct lm3533_als_attribute lm3533_als_attr_##_name = \ - ALS_ATTR(_name, _mode, _show, _store, _type, _val1, _val2) - -#define ALS_TARGET_ATTR_RW(_channel, _zone) \ - LM3533_ALS_ATTR(out_current##_channel##_current##_zone##_raw, \ - S_IRUGO | S_IWUSR, \ - show_als_attr, store_als_attr, \ - LM3533_ATTR_TYPE_TARGET, _channel, _zone) -/* - * ALS output current values (ALS mapper targets) - * - * out_current[0-2]_current[0-4]_raw 0-255 - */ -static ALS_TARGET_ATTR_RW(0, 0); -static ALS_TARGET_ATTR_RW(0, 1); -static ALS_TARGET_ATTR_RW(0, 2); -static ALS_TARGET_ATTR_RW(0, 3); -static ALS_TARGET_ATTR_RW(0, 4); - -static ALS_TARGET_ATTR_RW(1, 0); -static ALS_TARGET_ATTR_RW(1, 1); -static ALS_TARGET_ATTR_RW(1, 2); -static ALS_TARGET_ATTR_RW(1, 3); -static ALS_TARGET_ATTR_RW(1, 4); - -static ALS_TARGET_ATTR_RW(2, 0); -static ALS_TARGET_ATTR_RW(2, 1); -static ALS_TARGET_ATTR_RW(2, 2); -static ALS_TARGET_ATTR_RW(2, 3); -static ALS_TARGET_ATTR_RW(2, 4); - -#define ALS_THRESH_FALLING_ATTR_RW(_nr) \ - LM3533_ALS_ATTR(in_illuminance0_thresh##_nr##_falling_value, \ - S_IRUGO | S_IWUSR, \ - show_als_attr, store_als_attr, \ - LM3533_ATTR_TYPE_THRESH_FALLING, _nr, 0) - -#define ALS_THRESH_RAISING_ATTR_RW(_nr) \ - LM3533_ALS_ATTR(in_illuminance0_thresh##_nr##_raising_value, \ - S_IRUGO | S_IWUSR, \ - show_als_attr, store_als_attr, \ - LM3533_ATTR_TYPE_THRESH_RAISING, _nr, 0) -/* - * ALS Zone thresholds (boundaries) - * - * in_illuminance0_thresh[0-3]_falling_value 0-255 - * in_illuminance0_thresh[0-3]_raising_value 0-255 - */ -static ALS_THRESH_FALLING_ATTR_RW(0); -static ALS_THRESH_FALLING_ATTR_RW(1); -static ALS_THRESH_FALLING_ATTR_RW(2); -static ALS_THRESH_FALLING_ATTR_RW(3); - -static ALS_THRESH_RAISING_ATTR_RW(0); -static ALS_THRESH_RAISING_ATTR_RW(1); -static ALS_THRESH_RAISING_ATTR_RW(2); -static ALS_THRESH_RAISING_ATTR_RW(3); - -#define ALS_HYSTERESIS_ATTR_RO(_nr) \ - LM3533_ALS_ATTR(in_illuminance0_thresh##_nr##_hysteresis, \ - S_IRUGO, show_als_attr, NULL, \ - LM3533_ATTR_TYPE_HYSTERESIS, _nr, 0) -/* - * ALS Zone threshold hysteresis - * - * threshY_hysteresis = threshY_raising - threshY_falling - * - * in_illuminance0_thresh[0-3]_hysteresis 0-255 - * in_illuminance0_thresh[0-3]_hysteresis 0-255 - */ -static ALS_HYSTERESIS_ATTR_RO(0); -static ALS_HYSTERESIS_ATTR_RO(1); -static ALS_HYSTERESIS_ATTR_RO(2); -static ALS_HYSTERESIS_ATTR_RO(3); - -#define ILLUMINANCE_ATTR_RO(_name) \ - DEVICE_ATTR(in_illuminance0_##_name, S_IRUGO, show_##_name, NULL) -#define ILLUMINANCE_ATTR_RW(_name) \ - DEVICE_ATTR(in_illuminance0_##_name, S_IRUGO | S_IWUSR, \ - show_##_name, store_##_name) -/* - * ALS Zone threshold-event enable - * - * in_illuminance0_thresh_either_en 0,1 - */ -static ILLUMINANCE_ATTR_RW(thresh_either_en); - -/* - * ALS Current Zone - * - * in_illuminance0_zone 0-4 - */ -static ILLUMINANCE_ATTR_RO(zone); - -static struct attribute *lm3533_als_event_attributes[] = { - &dev_attr_in_illuminance0_thresh_either_en.attr, - &lm3533_als_attr_in_illuminance0_thresh0_falling_value.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh0_hysteresis.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh0_raising_value.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh1_falling_value.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh1_hysteresis.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh1_raising_value.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh2_falling_value.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh2_hysteresis.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh2_raising_value.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh3_falling_value.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh3_hysteresis.dev_attr.attr, - &lm3533_als_attr_in_illuminance0_thresh3_raising_value.dev_attr.attr, - NULL -}; - -static const struct attribute_group lm3533_als_event_attribute_group = { - .attrs = lm3533_als_event_attributes -}; - -static struct attribute *lm3533_als_attributes[] = { - &dev_attr_in_illuminance0_zone.attr, - &lm3533_als_attr_out_current0_current0_raw.dev_attr.attr, - &lm3533_als_attr_out_current0_current1_raw.dev_attr.attr, - &lm3533_als_attr_out_current0_current2_raw.dev_attr.attr, - &lm3533_als_attr_out_current0_current3_raw.dev_attr.attr, - &lm3533_als_attr_out_current0_current4_raw.dev_attr.attr, - &lm3533_als_attr_out_current1_current0_raw.dev_attr.attr, - &lm3533_als_attr_out_current1_current1_raw.dev_attr.attr, - &lm3533_als_attr_out_current1_current2_raw.dev_attr.attr, - &lm3533_als_attr_out_current1_current3_raw.dev_attr.attr, - &lm3533_als_attr_out_current1_current4_raw.dev_attr.attr, - &lm3533_als_attr_out_current2_current0_raw.dev_attr.attr, - &lm3533_als_attr_out_current2_current1_raw.dev_attr.attr, - &lm3533_als_attr_out_current2_current2_raw.dev_attr.attr, - &lm3533_als_attr_out_current2_current3_raw.dev_attr.attr, - &lm3533_als_attr_out_current2_current4_raw.dev_attr.attr, - NULL -}; - -static const struct attribute_group lm3533_als_attribute_group = { - .attrs = lm3533_als_attributes -}; - -static int lm3533_als_set_input_mode(struct lm3533_als *als, bool pwm_mode) -{ - u8 mask = LM3533_ALS_INPUT_MODE_MASK; - u8 val; - int ret; - - if (pwm_mode) - val = mask; /* pwm input */ - else - val = 0; /* analog input */ - - ret = lm3533_update(als->lm3533, LM3533_REG_ALS_CONF, val, mask); - if (ret) { - dev_err(&als->pdev->dev, "failed to set input mode %d\n", - pwm_mode); - return ret; - } - - return 0; -} - -static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val) -{ - int ret; - - if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) { - dev_err(&als->pdev->dev, "invalid resistor value\n"); - return -EINVAL; - } - - ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val); - if (ret) { - dev_err(&als->pdev->dev, "failed to set resistor\n"); - return ret; - } - - return 0; -} - -static int lm3533_als_setup(struct lm3533_als *als, - struct lm3533_als_platform_data *pdata) -{ - int ret; - - ret = lm3533_als_set_input_mode(als, pdata->pwm_mode); - if (ret) - return ret; - - /* ALS input is always high impedance in PWM-mode. */ - if (!pdata->pwm_mode) { - ret = lm3533_als_set_resistor(als, pdata->r_select); - if (ret) - return ret; - } - - return 0; -} - -static int lm3533_als_setup_irq(struct lm3533_als *als, void *dev) -{ - u8 mask = LM3533_ALS_INT_ENABLE_MASK; - int ret; - - /* Make sure interrupts are disabled. */ - ret = lm3533_update(als->lm3533, LM3533_REG_ALS_ZONE_INFO, 0, mask); - if (ret) { - dev_err(&als->pdev->dev, "failed to disable interrupts\n"); - return ret; - } - - ret = request_threaded_irq(als->irq, NULL, lm3533_als_isr, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, - dev_name(&als->pdev->dev), dev); - if (ret) { - dev_err(&als->pdev->dev, "failed to request irq %d\n", - als->irq); - return ret; - } - - return 0; -} - -static int lm3533_als_enable(struct lm3533_als *als) -{ - u8 mask = LM3533_ALS_ENABLE_MASK; - int ret; - - ret = lm3533_update(als->lm3533, LM3533_REG_ALS_CONF, mask, mask); - if (ret) - dev_err(&als->pdev->dev, "failed to enable ALS\n"); - - return ret; -} - -static int lm3533_als_disable(struct lm3533_als *als) -{ - u8 mask = LM3533_ALS_ENABLE_MASK; - int ret; - - ret = lm3533_update(als->lm3533, LM3533_REG_ALS_CONF, 0, mask); - if (ret) - dev_err(&als->pdev->dev, "failed to disable ALS\n"); - - return ret; -} - -static const struct iio_info lm3533_als_info = { - .attrs = &lm3533_als_attribute_group, - .event_attrs = &lm3533_als_event_attribute_group, - .read_raw = &lm3533_als_read_raw, -}; - -static int lm3533_als_probe(struct platform_device *pdev) -{ - struct lm3533 *lm3533; - struct lm3533_als_platform_data *pdata; - struct lm3533_als *als; - struct iio_dev *indio_dev; - int ret; - - lm3533 = dev_get_drvdata(pdev->dev.parent); - if (!lm3533) - return -EINVAL; - - pdata = pdev->dev.platform_data; - if (!pdata) { - dev_err(&pdev->dev, "no platform data\n"); - return -EINVAL; - } - - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*als)); - if (!indio_dev) - return -ENOMEM; - - indio_dev->info = &lm3533_als_info; - indio_dev->channels = lm3533_als_channels; - indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels); - indio_dev->name = dev_name(&pdev->dev); - iio_device_set_parent(indio_dev, pdev->dev.parent); - indio_dev->modes = INDIO_DIRECT_MODE; - - als = iio_priv(indio_dev); - als->lm3533 = lm3533; - als->pdev = pdev; - als->irq = lm3533->irq; - atomic_set(&als->zone, 0); - mutex_init(&als->thresh_mutex); - - platform_set_drvdata(pdev, indio_dev); - - if (als->irq) { - ret = lm3533_als_setup_irq(als, indio_dev); - if (ret) - return ret; - } - - ret = lm3533_als_setup(als, pdata); - if (ret) - goto err_free_irq; - - ret = lm3533_als_enable(als); - if (ret) - goto err_free_irq; - - ret = iio_device_register(indio_dev); - if (ret) { - dev_err(&pdev->dev, "failed to register ALS\n"); - goto err_disable; - } - - return 0; - -err_disable: - lm3533_als_disable(als); -err_free_irq: - if (als->irq) - free_irq(als->irq, indio_dev); - - return ret; -} - -static void lm3533_als_remove(struct platform_device *pdev) -{ - struct iio_dev *indio_dev = platform_get_drvdata(pdev); - struct lm3533_als *als = iio_priv(indio_dev); - - lm3533_als_set_int_mode(indio_dev, false); - iio_device_unregister(indio_dev); - lm3533_als_disable(als); - if (als->irq) - free_irq(als->irq, indio_dev); -} - -static struct platform_driver lm3533_als_driver = { - .driver = { - .name = "lm3533-als", - }, - .probe = lm3533_als_probe, - .remove_new = lm3533_als_remove, -}; -module_platform_driver(lm3533_als_driver); - -MODULE_AUTHOR("Johan Hovold "); -MODULE_DESCRIPTION("LM3533 Ambient Light Sensor driver"); -MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:lm3533-als"); From patchwork Fri May 31 16:56:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13681954 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2B5B7C25B75 for ; Fri, 31 May 2024 17:09:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D2D9510E136; Fri, 31 May 2024 17:09:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Hhb9nq7v"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8B4BD10E3BC for ; Fri, 31 May 2024 17:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717175333; x=1748711333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dlLwge4maMD5cCoCfHiqrG474Js9Ny8k6wcSKnYkycU=; b=Hhb9nq7v4j5lryuMRfNcCl1dv22oZJPaw1RCqCSYZ/2oYnYLinuFSrHQ GI8D6Z2q78KB6J5rPv3sBWhGFtrTt0F7nMAALttIcyHpojhfvwhm5oxOy 017ywil9zhSLHjUf+tYc/JZeRoGqfT9azcN9WFYdDkUtJeSovh1IpV+EB v0822qlqT3qpiyzihx857QCnUAs1aFc4bSCanWZdbTntkU/bqBQTtc2B8 lN3FYJ5aj6tCPUhGc7JINMNFt+iKmU7HkusTxz4m+9psLjARbMDTIa770 HKejVGGniiC7PjgSmdId2j+mKIqb+Dbi+u28AD9qABWkuowOtAOf0b0XO Q==; X-CSE-ConnectionGUID: Mi7R0i+ZT+yN6DpNJNZ4Gg== X-CSE-MsgGUID: 9kruRv5HTdCNEe5iuhnP+Q== X-IronPort-AV: E=McAfee;i="6600,9927,11089"; a="25131909" X-IronPort-AV: E=Sophos;i="6.08,204,1712646000"; d="scan'208";a="25131909" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2024 10:08:51 -0700 X-CSE-ConnectionGUID: ruC/MblIT8OM1eyfSLXHdQ== X-CSE-MsgGUID: qMFVlju+RR2+imotfPv6Yg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,204,1712646000"; d="scan'208";a="36147846" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa007.fm.intel.com with ESMTP; 31 May 2024 10:08:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 9B4A2650; Fri, 31 May 2024 20:08:46 +0300 (EEST) From: Andy Shevchenko To: Jonathan Cameron , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , Lee Jones , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Pavel Machek , Daniel Thompson , Jingoo Han , Helge Deller , Johan Hovold Subject: [PATCH v1 3/4] leds: lm3533: Remove the driver Date: Fri, 31 May 2024 19:56:15 +0300 Message-ID: <20240531170844.1595468-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240531170844.1595468-1-andriy.shevchenko@linux.intel.com> References: <20240531170844.1595468-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The driver has no in kernel users and requires a board file to be instantiated. Remove basically a dead code. If ever needed, it can be reinstantiated and converted to one that uses firmware node interfaces. Signed-off-by: Andy Shevchenko --- drivers/leds/Kconfig | 13 - drivers/leds/Makefile | 1 - drivers/leds/leds-lm3533.c | 755 ------------------------------------- 3 files changed, 769 deletions(-) delete mode 100644 drivers/leds/leds-lm3533.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 05e6af88b88c..4cdc3a687421 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -229,19 +229,6 @@ config LEDS_LM3532 controlled manually or using PWM input or using ambient light automatically. -config LEDS_LM3533 - tristate "LED support for LM3533" - depends on LEDS_CLASS - depends on MFD_LM3533 - help - This option enables support for the LEDs on National Semiconductor / - TI LM3533 Lighting Power chips. - - The LEDs can be controlled directly, through PWM input, or by the - ambient-light-sensor interface. The chip supports - hardware-accelerated blinking with maximum on and off periods of 9.8 - and 77 seconds respectively. - config LEDS_LM3642 tristate "LED support for LM3642 Chip" depends on LEDS_CLASS && I2C diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index effdfc6f1e95..6bc8c412d3ac 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -38,7 +38,6 @@ obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.o obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o obj-$(CONFIG_LEDS_LM3530) += leds-lm3530.o obj-$(CONFIG_LEDS_LM3532) += leds-lm3532.o -obj-$(CONFIG_LEDS_LM3533) += leds-lm3533.o obj-$(CONFIG_LEDS_LM355x) += leds-lm355x.o obj-$(CONFIG_LEDS_LM36274) += leds-lm36274.o obj-$(CONFIG_LEDS_LM3642) += leds-lm3642.o diff --git a/drivers/leds/leds-lm3533.c b/drivers/leds/leds-lm3533.c deleted file mode 100644 index a3d33165d262..000000000000 --- a/drivers/leds/leds-lm3533.c +++ /dev/null @@ -1,755 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * leds-lm3533.c -- LM3533 LED driver - * - * Copyright (C) 2011-2012 Texas Instruments - * - * Author: Johan Hovold - */ - -#include -#include -#include -#include -#include -#include - -#include - - -#define LM3533_LVCTRLBANK_MIN 2 -#define LM3533_LVCTRLBANK_MAX 5 -#define LM3533_LVCTRLBANK_COUNT 4 -#define LM3533_RISEFALLTIME_MAX 7 -#define LM3533_ALS_CHANNEL_LV_MIN 1 -#define LM3533_ALS_CHANNEL_LV_MAX 2 - -#define LM3533_REG_CTRLBANK_BCONF_BASE 0x1b -#define LM3533_REG_PATTERN_ENABLE 0x28 -#define LM3533_REG_PATTERN_LOW_TIME_BASE 0x71 -#define LM3533_REG_PATTERN_HIGH_TIME_BASE 0x72 -#define LM3533_REG_PATTERN_RISETIME_BASE 0x74 -#define LM3533_REG_PATTERN_FALLTIME_BASE 0x75 - -#define LM3533_REG_PATTERN_STEP 0x10 - -#define LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK 0x04 -#define LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK 0x02 -#define LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK 0x01 - -#define LM3533_LED_FLAG_PATTERN_ENABLE 1 - - -struct lm3533_led { - struct lm3533 *lm3533; - struct lm3533_ctrlbank cb; - struct led_classdev cdev; - int id; - - struct mutex mutex; - unsigned long flags; -}; - - -static inline struct lm3533_led *to_lm3533_led(struct led_classdev *cdev) -{ - return container_of(cdev, struct lm3533_led, cdev); -} - -static inline int lm3533_led_get_ctrlbank_id(struct lm3533_led *led) -{ - return led->id + 2; -} - -static inline u8 lm3533_led_get_lv_reg(struct lm3533_led *led, u8 base) -{ - return base + led->id; -} - -static inline u8 lm3533_led_get_pattern(struct lm3533_led *led) -{ - return led->id; -} - -static inline u8 lm3533_led_get_pattern_reg(struct lm3533_led *led, - u8 base) -{ - return base + lm3533_led_get_pattern(led) * LM3533_REG_PATTERN_STEP; -} - -static int lm3533_led_pattern_enable(struct lm3533_led *led, int enable) -{ - u8 mask; - u8 val; - int pattern; - int state; - int ret = 0; - - dev_dbg(led->cdev.dev, "%s - %d\n", __func__, enable); - - mutex_lock(&led->mutex); - - state = test_bit(LM3533_LED_FLAG_PATTERN_ENABLE, &led->flags); - if ((enable && state) || (!enable && !state)) - goto out; - - pattern = lm3533_led_get_pattern(led); - mask = 1 << (2 * pattern); - - if (enable) - val = mask; - else - val = 0; - - ret = lm3533_update(led->lm3533, LM3533_REG_PATTERN_ENABLE, val, mask); - if (ret) { - dev_err(led->cdev.dev, "failed to enable pattern %d (%d)\n", - pattern, enable); - goto out; - } - - __change_bit(LM3533_LED_FLAG_PATTERN_ENABLE, &led->flags); -out: - mutex_unlock(&led->mutex); - - return ret; -} - -static int lm3533_led_set(struct led_classdev *cdev, - enum led_brightness value) -{ - struct lm3533_led *led = to_lm3533_led(cdev); - - dev_dbg(led->cdev.dev, "%s - %d\n", __func__, value); - - if (value == 0) - lm3533_led_pattern_enable(led, 0); /* disable blink */ - - return lm3533_ctrlbank_set_brightness(&led->cb, value); -} - -static enum led_brightness lm3533_led_get(struct led_classdev *cdev) -{ - struct lm3533_led *led = to_lm3533_led(cdev); - u8 val; - int ret; - - ret = lm3533_ctrlbank_get_brightness(&led->cb, &val); - if (ret) - return ret; - - dev_dbg(led->cdev.dev, "%s - %u\n", __func__, val); - - return val; -} - -/* Pattern generator defines (delays in us). */ -#define LM3533_LED_DELAY1_VMIN 0x00 -#define LM3533_LED_DELAY2_VMIN 0x3d -#define LM3533_LED_DELAY3_VMIN 0x80 - -#define LM3533_LED_DELAY1_VMAX (LM3533_LED_DELAY2_VMIN - 1) -#define LM3533_LED_DELAY2_VMAX (LM3533_LED_DELAY3_VMIN - 1) -#define LM3533_LED_DELAY3_VMAX 0xff - -#define LM3533_LED_DELAY1_TMIN 16384U -#define LM3533_LED_DELAY2_TMIN 1130496U -#define LM3533_LED_DELAY3_TMIN 10305536U - -#define LM3533_LED_DELAY1_TMAX 999424U -#define LM3533_LED_DELAY2_TMAX 9781248U -#define LM3533_LED_DELAY3_TMAX 76890112U - -/* t_step = (t_max - t_min) / (v_max - v_min) */ -#define LM3533_LED_DELAY1_TSTEP 16384 -#define LM3533_LED_DELAY2_TSTEP 131072 -#define LM3533_LED_DELAY3_TSTEP 524288 - -/* Delay limits for hardware accelerated blinking (in ms). */ -#define LM3533_LED_DELAY_ON_MAX \ - ((LM3533_LED_DELAY2_TMAX + LM3533_LED_DELAY2_TSTEP / 2) / 1000) -#define LM3533_LED_DELAY_OFF_MAX \ - ((LM3533_LED_DELAY3_TMAX + LM3533_LED_DELAY3_TSTEP / 2) / 1000) - -/* - * Returns linear map of *t from [t_min,t_max] to [v_min,v_max] with a step - * size of t_step, where - * - * t_step = (t_max - t_min) / (v_max - v_min) - * - * and updates *t to reflect the mapped value. - */ -static u8 time_to_val(unsigned *t, unsigned t_min, unsigned t_step, - u8 v_min, u8 v_max) -{ - unsigned val; - - val = (*t + t_step / 2 - t_min) / t_step + v_min; - - *t = t_step * (val - v_min) + t_min; - - return (u8)val; -} - -/* - * Returns time code corresponding to *delay (in ms) and updates *delay to - * reflect actual hardware delay. - * - * Hardware supports 256 discrete delay times, divided into three groups with - * the following ranges and step-sizes: - * - * [ 16, 999] [0x00, 0x3e] step 16 ms - * [ 1130, 9781] [0x3d, 0x7f] step 131 ms - * [10306, 76890] [0x80, 0xff] step 524 ms - * - * Note that delay group 3 is only available for delay_off. - */ -static u8 lm3533_led_get_hw_delay(unsigned *delay) -{ - unsigned t; - u8 val; - - t = *delay * 1000; - - if (t >= (LM3533_LED_DELAY2_TMAX + LM3533_LED_DELAY3_TMIN) / 2) { - t = clamp(t, LM3533_LED_DELAY3_TMIN, LM3533_LED_DELAY3_TMAX); - val = time_to_val(&t, LM3533_LED_DELAY3_TMIN, - LM3533_LED_DELAY3_TSTEP, - LM3533_LED_DELAY3_VMIN, - LM3533_LED_DELAY3_VMAX); - } else if (t >= (LM3533_LED_DELAY1_TMAX + LM3533_LED_DELAY2_TMIN) / 2) { - t = clamp(t, LM3533_LED_DELAY2_TMIN, LM3533_LED_DELAY2_TMAX); - val = time_to_val(&t, LM3533_LED_DELAY2_TMIN, - LM3533_LED_DELAY2_TSTEP, - LM3533_LED_DELAY2_VMIN, - LM3533_LED_DELAY2_VMAX); - } else { - t = clamp(t, LM3533_LED_DELAY1_TMIN, LM3533_LED_DELAY1_TMAX); - val = time_to_val(&t, LM3533_LED_DELAY1_TMIN, - LM3533_LED_DELAY1_TSTEP, - LM3533_LED_DELAY1_VMIN, - LM3533_LED_DELAY1_VMAX); - } - - *delay = (t + 500) / 1000; - - return val; -} - -/* - * Set delay register base to *delay (in ms) and update *delay to reflect - * actual hardware delay used. - */ -static u8 lm3533_led_delay_set(struct lm3533_led *led, u8 base, - unsigned long *delay) -{ - unsigned t; - u8 val; - u8 reg; - int ret; - - t = (unsigned)*delay; - - /* Delay group 3 is only available for low time (delay off). */ - if (base != LM3533_REG_PATTERN_LOW_TIME_BASE) - t = min(t, LM3533_LED_DELAY2_TMAX / 1000); - - val = lm3533_led_get_hw_delay(&t); - - dev_dbg(led->cdev.dev, "%s - %lu: %u (0x%02x)\n", __func__, - *delay, t, val); - reg = lm3533_led_get_pattern_reg(led, base); - ret = lm3533_write(led->lm3533, reg, val); - if (ret) - dev_err(led->cdev.dev, "failed to set delay (%02x)\n", reg); - - *delay = t; - - return ret; -} - -static int lm3533_led_delay_on_set(struct lm3533_led *led, unsigned long *t) -{ - return lm3533_led_delay_set(led, LM3533_REG_PATTERN_HIGH_TIME_BASE, t); -} - -static int lm3533_led_delay_off_set(struct lm3533_led *led, unsigned long *t) -{ - return lm3533_led_delay_set(led, LM3533_REG_PATTERN_LOW_TIME_BASE, t); -} - -static int lm3533_led_blink_set(struct led_classdev *cdev, - unsigned long *delay_on, - unsigned long *delay_off) -{ - struct lm3533_led *led = to_lm3533_led(cdev); - int ret; - - dev_dbg(led->cdev.dev, "%s - on = %lu, off = %lu\n", __func__, - *delay_on, *delay_off); - - if (*delay_on > LM3533_LED_DELAY_ON_MAX || - *delay_off > LM3533_LED_DELAY_OFF_MAX) - return -EINVAL; - - if (*delay_on == 0 && *delay_off == 0) { - *delay_on = 500; - *delay_off = 500; - } - - ret = lm3533_led_delay_on_set(led, delay_on); - if (ret) - return ret; - - ret = lm3533_led_delay_off_set(led, delay_off); - if (ret) - return ret; - - return lm3533_led_pattern_enable(led, 1); -} - -static ssize_t show_id(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - - return sysfs_emit(buf, "%d\n", led->id); -} - -/* - * Pattern generator rise/fall times: - * - * 0 - 2048 us (default) - * 1 - 262 ms - * 2 - 524 ms - * 3 - 1.049 s - * 4 - 2.097 s - * 5 - 4.194 s - * 6 - 8.389 s - * 7 - 16.78 s - */ -static ssize_t show_risefalltime(struct device *dev, - struct device_attribute *attr, - char *buf, u8 base) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - ssize_t ret; - u8 reg; - u8 val; - - reg = lm3533_led_get_pattern_reg(led, base); - ret = lm3533_read(led->lm3533, reg, &val); - if (ret) - return ret; - - return sysfs_emit(buf, "%x\n", val); -} - -static ssize_t show_risetime(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return show_risefalltime(dev, attr, buf, - LM3533_REG_PATTERN_RISETIME_BASE); -} - -static ssize_t show_falltime(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return show_risefalltime(dev, attr, buf, - LM3533_REG_PATTERN_FALLTIME_BASE); -} - -static ssize_t store_risefalltime(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len, u8 base) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - u8 val; - u8 reg; - int ret; - - if (kstrtou8(buf, 0, &val) || val > LM3533_RISEFALLTIME_MAX) - return -EINVAL; - - reg = lm3533_led_get_pattern_reg(led, base); - ret = lm3533_write(led->lm3533, reg, val); - if (ret) - return ret; - - return len; -} - -static ssize_t store_risetime(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - return store_risefalltime(dev, attr, buf, len, - LM3533_REG_PATTERN_RISETIME_BASE); -} - -static ssize_t store_falltime(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - return store_risefalltime(dev, attr, buf, len, - LM3533_REG_PATTERN_FALLTIME_BASE); -} - -static ssize_t show_als_channel(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - unsigned channel; - u8 reg; - u8 val; - int ret; - - reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE); - ret = lm3533_read(led->lm3533, reg, &val); - if (ret) - return ret; - - channel = (val & LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK) + 1; - - return sysfs_emit(buf, "%u\n", channel); -} - -static ssize_t store_als_channel(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - unsigned channel; - u8 reg; - u8 val; - u8 mask; - int ret; - - if (kstrtouint(buf, 0, &channel)) - return -EINVAL; - - if (channel < LM3533_ALS_CHANNEL_LV_MIN || - channel > LM3533_ALS_CHANNEL_LV_MAX) - return -EINVAL; - - reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE); - mask = LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK; - val = channel - 1; - - ret = lm3533_update(led->lm3533, reg, val, mask); - if (ret) - return ret; - - return len; -} - -static ssize_t show_als_en(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - bool enable; - u8 reg; - u8 val; - int ret; - - reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE); - ret = lm3533_read(led->lm3533, reg, &val); - if (ret) - return ret; - - enable = val & LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK; - - return sysfs_emit(buf, "%d\n", enable); -} - -static ssize_t store_als_en(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - unsigned enable; - u8 reg; - u8 mask; - u8 val; - int ret; - - if (kstrtouint(buf, 0, &enable)) - return -EINVAL; - - reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE); - mask = LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK; - - if (enable) - val = mask; - else - val = 0; - - ret = lm3533_update(led->lm3533, reg, val, mask); - if (ret) - return ret; - - return len; -} - -static ssize_t show_linear(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - u8 reg; - u8 val; - int linear; - int ret; - - reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE); - ret = lm3533_read(led->lm3533, reg, &val); - if (ret) - return ret; - - if (val & LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK) - linear = 1; - else - linear = 0; - - return sysfs_emit(buf, "%x\n", linear); -} - -static ssize_t store_linear(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - unsigned long linear; - u8 reg; - u8 mask; - u8 val; - int ret; - - if (kstrtoul(buf, 0, &linear)) - return -EINVAL; - - reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE); - mask = LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK; - - if (linear) - val = mask; - else - val = 0; - - ret = lm3533_update(led->lm3533, reg, val, mask); - if (ret) - return ret; - - return len; -} - -static ssize_t show_pwm(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - u8 val; - int ret; - - ret = lm3533_ctrlbank_get_pwm(&led->cb, &val); - if (ret) - return ret; - - return sysfs_emit(buf, "%u\n", val); -} - -static ssize_t store_pwm(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - u8 val; - int ret; - - if (kstrtou8(buf, 0, &val)) - return -EINVAL; - - ret = lm3533_ctrlbank_set_pwm(&led->cb, val); - if (ret) - return ret; - - return len; -} - -static LM3533_ATTR_RW(als_channel); -static LM3533_ATTR_RW(als_en); -static LM3533_ATTR_RW(falltime); -static LM3533_ATTR_RO(id); -static LM3533_ATTR_RW(linear); -static LM3533_ATTR_RW(pwm); -static LM3533_ATTR_RW(risetime); - -static struct attribute *lm3533_led_attributes[] = { - &dev_attr_als_channel.attr, - &dev_attr_als_en.attr, - &dev_attr_falltime.attr, - &dev_attr_id.attr, - &dev_attr_linear.attr, - &dev_attr_pwm.attr, - &dev_attr_risetime.attr, - NULL, -}; - -static umode_t lm3533_led_attr_is_visible(struct kobject *kobj, - struct attribute *attr, int n) -{ - struct device *dev = kobj_to_dev(kobj); - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct lm3533_led *led = to_lm3533_led(led_cdev); - umode_t mode = attr->mode; - - if (attr == &dev_attr_als_channel.attr || - attr == &dev_attr_als_en.attr) { - if (!led->lm3533->have_als) - mode = 0; - } - - return mode; -}; - -static const struct attribute_group lm3533_led_attribute_group = { - .is_visible = lm3533_led_attr_is_visible, - .attrs = lm3533_led_attributes -}; - -static const struct attribute_group *lm3533_led_attribute_groups[] = { - &lm3533_led_attribute_group, - NULL -}; - -static int lm3533_led_setup(struct lm3533_led *led, - struct lm3533_led_platform_data *pdata) -{ - int ret; - - ret = lm3533_ctrlbank_set_max_current(&led->cb, pdata->max_current); - if (ret) - return ret; - - return lm3533_ctrlbank_set_pwm(&led->cb, pdata->pwm); -} - -static int lm3533_led_probe(struct platform_device *pdev) -{ - struct lm3533 *lm3533; - struct lm3533_led_platform_data *pdata; - struct lm3533_led *led; - int ret; - - dev_dbg(&pdev->dev, "%s\n", __func__); - - lm3533 = dev_get_drvdata(pdev->dev.parent); - if (!lm3533) - return -EINVAL; - - pdata = dev_get_platdata(&pdev->dev); - if (!pdata) { - dev_err(&pdev->dev, "no platform data\n"); - return -EINVAL; - } - - if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) { - dev_err(&pdev->dev, "illegal LED id %d\n", pdev->id); - return -EINVAL; - } - - led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); - if (!led) - return -ENOMEM; - - led->lm3533 = lm3533; - led->cdev.name = pdata->name; - led->cdev.default_trigger = pdata->default_trigger; - led->cdev.brightness_set_blocking = lm3533_led_set; - led->cdev.brightness_get = lm3533_led_get; - led->cdev.blink_set = lm3533_led_blink_set; - led->cdev.brightness = LED_OFF; - led->cdev.groups = lm3533_led_attribute_groups; - led->id = pdev->id; - - mutex_init(&led->mutex); - - /* The class framework makes a callback to get brightness during - * registration so use parent device (for error reporting) until - * registered. - */ - led->cb.lm3533 = lm3533; - led->cb.id = lm3533_led_get_ctrlbank_id(led); - led->cb.dev = lm3533->dev; - - platform_set_drvdata(pdev, led); - - ret = led_classdev_register(pdev->dev.parent, &led->cdev); - if (ret) { - dev_err(&pdev->dev, "failed to register LED %d\n", pdev->id); - return ret; - } - - led->cb.dev = led->cdev.dev; - - ret = lm3533_led_setup(led, pdata); - if (ret) - goto err_deregister; - - ret = lm3533_ctrlbank_enable(&led->cb); - if (ret) - goto err_deregister; - - return 0; - -err_deregister: - led_classdev_unregister(&led->cdev); - - return ret; -} - -static void lm3533_led_remove(struct platform_device *pdev) -{ - struct lm3533_led *led = platform_get_drvdata(pdev); - - dev_dbg(&pdev->dev, "%s\n", __func__); - - lm3533_ctrlbank_disable(&led->cb); - led_classdev_unregister(&led->cdev); -} - -static void lm3533_led_shutdown(struct platform_device *pdev) -{ - - struct lm3533_led *led = platform_get_drvdata(pdev); - - dev_dbg(&pdev->dev, "%s\n", __func__); - - lm3533_ctrlbank_disable(&led->cb); - lm3533_led_set(&led->cdev, LED_OFF); /* disable blink */ -} - -static struct platform_driver lm3533_led_driver = { - .driver = { - .name = "lm3533-leds", - }, - .probe = lm3533_led_probe, - .remove_new = lm3533_led_remove, - .shutdown = lm3533_led_shutdown, -}; -module_platform_driver(lm3533_led_driver); - -MODULE_AUTHOR("Johan Hovold "); -MODULE_DESCRIPTION("LM3533 LED driver"); -MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:lm3533-leds"); From patchwork Fri May 31 16:56:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13681950 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A883CC25B7E for ; Fri, 31 May 2024 17:09:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0836010E597; Fri, 31 May 2024 17:08:55 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="NBrCSbBa"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id 500F910E634 for ; Fri, 31 May 2024 17:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717175333; x=1748711333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3PIKjX4C8x631MS4CKk45aCDtHEPJ9w4WNa6zwbGgDg=; b=NBrCSbBaTnZHUmeUzU/XBbske1sWYQGRkD8SxAJq33PGPtasQh8R3oDh 742Q5KzDIaI5MIdirV6FaCzrYsKL9nCk6+9grOlMUmF3X2OnD+PWG9EQQ jom1fqqawE0U3+hdpedcORBy/m73spizcAh84fw/oltjaVX9l3zPge1dY HXRziix5oaK1b2H4BJj0oEfbVHv4TCALbnrMhh1aR34sQAOUYpLSHrg+1 CIygSZOuOlEbsyOFqWKWv9ObfWyAtrMWz+4a7CylAlI8uUyINR6p/J3HG pZ6o1+T4/p0rv/uwZ/bqM//snxm5/F5KFtiFQwAbdXz21tGuo9nHhcMqZ Q==; X-CSE-ConnectionGUID: nNZ2pf+/SHufPAGgdnuzkQ== X-CSE-MsgGUID: lwT06aKITuivgCt7dHRh+g== X-IronPort-AV: E=McAfee;i="6600,9927,11089"; a="31224230" X-IronPort-AV: E=Sophos;i="6.08,204,1712646000"; d="scan'208";a="31224230" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2024 10:08:52 -0700 X-CSE-ConnectionGUID: mHQrX2IWRVa5+r7AUEnNXw== X-CSE-MsgGUID: wQSkJeloQSqgY/IxW9qV6A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,204,1712646000"; d="scan'208";a="36163156" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa010.jf.intel.com with ESMTP; 31 May 2024 10:08:49 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id A6D02668; Fri, 31 May 2024 20:08:46 +0300 (EEST) From: Andy Shevchenko To: Jonathan Cameron , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , Lee Jones , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Pavel Machek , Daniel Thompson , Jingoo Han , Helge Deller , Johan Hovold Subject: [PATCH v1 4/4] mfd: lm3533: Remove the driver Date: Fri, 31 May 2024 19:56:16 +0300 Message-ID: <20240531170844.1595468-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240531170844.1595468-1-andriy.shevchenko@linux.intel.com> References: <20240531170844.1595468-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The driver has no in kernel users and requires a board file to be instantiated. Remove basically a dead code. If ever needed, it can be reinstantiated and converted to one that uses firmware node interfaces. Signed-off-by: Andy Shevchenko --- drivers/mfd/lm3533-core.c | 645 ------------------------------------- include/linux/mfd/lm3533.h | 100 ------ 2 files changed, 745 deletions(-) delete mode 100644 drivers/mfd/lm3533-core.c delete mode 100644 include/linux/mfd/lm3533.h diff --git a/drivers/mfd/lm3533-core.c b/drivers/mfd/lm3533-core.c deleted file mode 100644 index c211183cecb2..000000000000 --- a/drivers/mfd/lm3533-core.c +++ /dev/null @@ -1,645 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * lm3533-core.c -- LM3533 Core - * - * Copyright (C) 2011-2012 Texas Instruments - * - * Author: Johan Hovold - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -#define LM3533_BOOST_OVP_MASK 0x06 -#define LM3533_BOOST_OVP_SHIFT 1 - -#define LM3533_BOOST_FREQ_MASK 0x01 -#define LM3533_BOOST_FREQ_SHIFT 0 - -#define LM3533_BL_ID_MASK 1 -#define LM3533_LED_ID_MASK 3 -#define LM3533_BL_ID_MAX 1 -#define LM3533_LED_ID_MAX 3 - -#define LM3533_HVLED_ID_MAX 2 -#define LM3533_LVLED_ID_MAX 5 - -#define LM3533_REG_OUTPUT_CONF1 0x10 -#define LM3533_REG_OUTPUT_CONF2 0x11 -#define LM3533_REG_BOOST_PWM 0x2c - -#define LM3533_REG_MAX 0xb2 - - -static struct mfd_cell lm3533_als_devs[] = { - { - .name = "lm3533-als", - .id = -1, - }, -}; - -static struct mfd_cell lm3533_bl_devs[] = { - { - .name = "lm3533-backlight", - .id = 0, - }, - { - .name = "lm3533-backlight", - .id = 1, - }, -}; - -static struct mfd_cell lm3533_led_devs[] = { - { - .name = "lm3533-leds", - .id = 0, - }, - { - .name = "lm3533-leds", - .id = 1, - }, - { - .name = "lm3533-leds", - .id = 2, - }, - { - .name = "lm3533-leds", - .id = 3, - }, -}; - -int lm3533_read(struct lm3533 *lm3533, u8 reg, u8 *val) -{ - int tmp; - int ret; - - ret = regmap_read(lm3533->regmap, reg, &tmp); - if (ret < 0) { - dev_err(lm3533->dev, "failed to read register %02x: %d\n", - reg, ret); - return ret; - } - - *val = tmp; - - dev_dbg(lm3533->dev, "read [%02x]: %02x\n", reg, *val); - - return ret; -} -EXPORT_SYMBOL_GPL(lm3533_read); - -int lm3533_write(struct lm3533 *lm3533, u8 reg, u8 val) -{ - int ret; - - dev_dbg(lm3533->dev, "write [%02x]: %02x\n", reg, val); - - ret = regmap_write(lm3533->regmap, reg, val); - if (ret < 0) { - dev_err(lm3533->dev, "failed to write register %02x: %d\n", - reg, ret); - } - - return ret; -} -EXPORT_SYMBOL_GPL(lm3533_write); - -int lm3533_update(struct lm3533 *lm3533, u8 reg, u8 val, u8 mask) -{ - int ret; - - dev_dbg(lm3533->dev, "update [%02x]: %02x/%02x\n", reg, val, mask); - - ret = regmap_update_bits(lm3533->regmap, reg, mask, val); - if (ret < 0) { - dev_err(lm3533->dev, "failed to update register %02x: %d\n", - reg, ret); - } - - return ret; -} -EXPORT_SYMBOL_GPL(lm3533_update); - -static int lm3533_set_boost_freq(struct lm3533 *lm3533, - enum lm3533_boost_freq freq) -{ - int ret; - - ret = lm3533_update(lm3533, LM3533_REG_BOOST_PWM, - freq << LM3533_BOOST_FREQ_SHIFT, - LM3533_BOOST_FREQ_MASK); - if (ret) - dev_err(lm3533->dev, "failed to set boost frequency\n"); - - return ret; -} - - -static int lm3533_set_boost_ovp(struct lm3533 *lm3533, - enum lm3533_boost_ovp ovp) -{ - int ret; - - ret = lm3533_update(lm3533, LM3533_REG_BOOST_PWM, - ovp << LM3533_BOOST_OVP_SHIFT, - LM3533_BOOST_OVP_MASK); - if (ret) - dev_err(lm3533->dev, "failed to set boost ovp\n"); - - return ret; -} - -/* - * HVLED output config -- output hvled controlled by backlight bl - */ -static int lm3533_set_hvled_config(struct lm3533 *lm3533, u8 hvled, u8 bl) -{ - u8 val; - u8 mask; - int shift; - int ret; - - if (hvled == 0 || hvled > LM3533_HVLED_ID_MAX) - return -EINVAL; - - if (bl > LM3533_BL_ID_MAX) - return -EINVAL; - - shift = hvled - 1; - mask = LM3533_BL_ID_MASK << shift; - val = bl << shift; - - ret = lm3533_update(lm3533, LM3533_REG_OUTPUT_CONF1, val, mask); - if (ret) - dev_err(lm3533->dev, "failed to set hvled config\n"); - - return ret; -} - -/* - * LVLED output config -- output lvled controlled by LED led - */ -static int lm3533_set_lvled_config(struct lm3533 *lm3533, u8 lvled, u8 led) -{ - u8 reg; - u8 val; - u8 mask; - int shift; - int ret; - - if (lvled == 0 || lvled > LM3533_LVLED_ID_MAX) - return -EINVAL; - - if (led > LM3533_LED_ID_MAX) - return -EINVAL; - - if (lvled < 4) { - reg = LM3533_REG_OUTPUT_CONF1; - shift = 2 * lvled; - } else { - reg = LM3533_REG_OUTPUT_CONF2; - shift = 2 * (lvled - 4); - } - - mask = LM3533_LED_ID_MASK << shift; - val = led << shift; - - ret = lm3533_update(lm3533, reg, val, mask); - if (ret) - dev_err(lm3533->dev, "failed to set lvled config\n"); - - return ret; -} - -static void lm3533_enable(struct lm3533 *lm3533) -{ - if (gpio_is_valid(lm3533->gpio_hwen)) - gpio_set_value(lm3533->gpio_hwen, 1); -} - -static void lm3533_disable(struct lm3533 *lm3533) -{ - if (gpio_is_valid(lm3533->gpio_hwen)) - gpio_set_value(lm3533->gpio_hwen, 0); -} - -enum lm3533_attribute_type { - LM3533_ATTR_TYPE_BACKLIGHT, - LM3533_ATTR_TYPE_LED, -}; - -struct lm3533_device_attribute { - struct device_attribute dev_attr; - enum lm3533_attribute_type type; - union { - struct { - u8 id; - } output; - } u; -}; - -#define to_lm3533_dev_attr(_attr) \ - container_of(_attr, struct lm3533_device_attribute, dev_attr) - -static ssize_t show_output(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct lm3533 *lm3533 = dev_get_drvdata(dev); - struct lm3533_device_attribute *lattr = to_lm3533_dev_attr(attr); - int id = lattr->u.output.id; - u8 reg; - u8 val; - u8 mask; - int shift; - int ret; - - if (lattr->type == LM3533_ATTR_TYPE_BACKLIGHT) { - reg = LM3533_REG_OUTPUT_CONF1; - shift = id - 1; - mask = LM3533_BL_ID_MASK << shift; - } else { - if (id < 4) { - reg = LM3533_REG_OUTPUT_CONF1; - shift = 2 * id; - } else { - reg = LM3533_REG_OUTPUT_CONF2; - shift = 2 * (id - 4); - } - mask = LM3533_LED_ID_MASK << shift; - } - - ret = lm3533_read(lm3533, reg, &val); - if (ret) - return ret; - - val = (val & mask) >> shift; - - return sysfs_emit(buf, "%u\n", val); -} - -static ssize_t store_output(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct lm3533 *lm3533 = dev_get_drvdata(dev); - struct lm3533_device_attribute *lattr = to_lm3533_dev_attr(attr); - int id = lattr->u.output.id; - u8 val; - int ret; - - if (kstrtou8(buf, 0, &val)) - return -EINVAL; - - if (lattr->type == LM3533_ATTR_TYPE_BACKLIGHT) - ret = lm3533_set_hvled_config(lm3533, id, val); - else - ret = lm3533_set_lvled_config(lm3533, id, val); - - if (ret) - return ret; - - return len; -} - -#define LM3533_OUTPUT_ATTR(_name, _mode, _show, _store, _type, _id) \ - struct lm3533_device_attribute lm3533_dev_attr_##_name = \ - { .dev_attr = __ATTR(_name, _mode, _show, _store), \ - .type = _type, \ - .u.output = { .id = _id }, } - -#define LM3533_OUTPUT_ATTR_RW(_name, _type, _id) \ - LM3533_OUTPUT_ATTR(output_##_name, S_IRUGO | S_IWUSR, \ - show_output, store_output, _type, _id) - -#define LM3533_OUTPUT_HVLED_ATTR_RW(_nr) \ - LM3533_OUTPUT_ATTR_RW(hvled##_nr, LM3533_ATTR_TYPE_BACKLIGHT, _nr) -#define LM3533_OUTPUT_LVLED_ATTR_RW(_nr) \ - LM3533_OUTPUT_ATTR_RW(lvled##_nr, LM3533_ATTR_TYPE_LED, _nr) -/* - * Output config: - * - * output_hvled 0-1 - * output_lvled 0-3 - */ -static LM3533_OUTPUT_HVLED_ATTR_RW(1); -static LM3533_OUTPUT_HVLED_ATTR_RW(2); -static LM3533_OUTPUT_LVLED_ATTR_RW(1); -static LM3533_OUTPUT_LVLED_ATTR_RW(2); -static LM3533_OUTPUT_LVLED_ATTR_RW(3); -static LM3533_OUTPUT_LVLED_ATTR_RW(4); -static LM3533_OUTPUT_LVLED_ATTR_RW(5); - -static struct attribute *lm3533_attributes[] = { - &lm3533_dev_attr_output_hvled1.dev_attr.attr, - &lm3533_dev_attr_output_hvled2.dev_attr.attr, - &lm3533_dev_attr_output_lvled1.dev_attr.attr, - &lm3533_dev_attr_output_lvled2.dev_attr.attr, - &lm3533_dev_attr_output_lvled3.dev_attr.attr, - &lm3533_dev_attr_output_lvled4.dev_attr.attr, - &lm3533_dev_attr_output_lvled5.dev_attr.attr, - NULL, -}; - -#define to_dev_attr(_attr) \ - container_of(_attr, struct device_attribute, attr) - -static umode_t lm3533_attr_is_visible(struct kobject *kobj, - struct attribute *attr, int n) -{ - struct device *dev = kobj_to_dev(kobj); - struct lm3533 *lm3533 = dev_get_drvdata(dev); - struct device_attribute *dattr = to_dev_attr(attr); - struct lm3533_device_attribute *lattr = to_lm3533_dev_attr(dattr); - enum lm3533_attribute_type type = lattr->type; - umode_t mode = attr->mode; - - if (!lm3533->have_backlights && type == LM3533_ATTR_TYPE_BACKLIGHT) - mode = 0; - else if (!lm3533->have_leds && type == LM3533_ATTR_TYPE_LED) - mode = 0; - - return mode; -}; - -static struct attribute_group lm3533_attribute_group = { - .is_visible = lm3533_attr_is_visible, - .attrs = lm3533_attributes -}; - -static int lm3533_device_als_init(struct lm3533 *lm3533) -{ - struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev); - int ret; - - if (!pdata->als) - return 0; - - lm3533_als_devs[0].platform_data = pdata->als; - lm3533_als_devs[0].pdata_size = sizeof(*pdata->als); - - ret = mfd_add_devices(lm3533->dev, 0, lm3533_als_devs, 1, NULL, - 0, NULL); - if (ret) { - dev_err(lm3533->dev, "failed to add ALS device\n"); - return ret; - } - - lm3533->have_als = 1; - - return 0; -} - -static int lm3533_device_bl_init(struct lm3533 *lm3533) -{ - struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev); - int i; - int ret; - - if (!pdata->backlights || pdata->num_backlights == 0) - return 0; - - if (pdata->num_backlights > ARRAY_SIZE(lm3533_bl_devs)) - pdata->num_backlights = ARRAY_SIZE(lm3533_bl_devs); - - for (i = 0; i < pdata->num_backlights; ++i) { - lm3533_bl_devs[i].platform_data = &pdata->backlights[i]; - lm3533_bl_devs[i].pdata_size = sizeof(pdata->backlights[i]); - } - - ret = mfd_add_devices(lm3533->dev, 0, lm3533_bl_devs, - pdata->num_backlights, NULL, 0, NULL); - if (ret) { - dev_err(lm3533->dev, "failed to add backlight devices\n"); - return ret; - } - - lm3533->have_backlights = 1; - - return 0; -} - -static int lm3533_device_led_init(struct lm3533 *lm3533) -{ - struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev); - int i; - int ret; - - if (!pdata->leds || pdata->num_leds == 0) - return 0; - - if (pdata->num_leds > ARRAY_SIZE(lm3533_led_devs)) - pdata->num_leds = ARRAY_SIZE(lm3533_led_devs); - - for (i = 0; i < pdata->num_leds; ++i) { - lm3533_led_devs[i].platform_data = &pdata->leds[i]; - lm3533_led_devs[i].pdata_size = sizeof(pdata->leds[i]); - } - - ret = mfd_add_devices(lm3533->dev, 0, lm3533_led_devs, - pdata->num_leds, NULL, 0, NULL); - if (ret) { - dev_err(lm3533->dev, "failed to add LED devices\n"); - return ret; - } - - lm3533->have_leds = 1; - - return 0; -} - -static int lm3533_device_setup(struct lm3533 *lm3533, - struct lm3533_platform_data *pdata) -{ - int ret; - - ret = lm3533_set_boost_freq(lm3533, pdata->boost_freq); - if (ret) - return ret; - - return lm3533_set_boost_ovp(lm3533, pdata->boost_ovp); -} - -static int lm3533_device_init(struct lm3533 *lm3533) -{ - struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev); - int ret; - - dev_dbg(lm3533->dev, "%s\n", __func__); - - if (!pdata) { - dev_err(lm3533->dev, "no platform data\n"); - return -EINVAL; - } - - lm3533->gpio_hwen = pdata->gpio_hwen; - - if (gpio_is_valid(lm3533->gpio_hwen)) { - ret = devm_gpio_request_one(lm3533->dev, lm3533->gpio_hwen, - GPIOF_OUT_INIT_LOW, "lm3533-hwen"); - if (ret < 0) { - dev_err(lm3533->dev, - "failed to request HWEN GPIO %d\n", - lm3533->gpio_hwen); - return ret; - } - } - - lm3533_enable(lm3533); - - ret = lm3533_device_setup(lm3533, pdata); - if (ret) - goto err_disable; - - lm3533_device_als_init(lm3533); - lm3533_device_bl_init(lm3533); - lm3533_device_led_init(lm3533); - - ret = sysfs_create_group(&lm3533->dev->kobj, &lm3533_attribute_group); - if (ret < 0) { - dev_err(lm3533->dev, "failed to create sysfs attributes\n"); - goto err_unregister; - } - - return 0; - -err_unregister: - mfd_remove_devices(lm3533->dev); -err_disable: - lm3533_disable(lm3533); - - return ret; -} - -static void lm3533_device_exit(struct lm3533 *lm3533) -{ - dev_dbg(lm3533->dev, "%s\n", __func__); - - sysfs_remove_group(&lm3533->dev->kobj, &lm3533_attribute_group); - - mfd_remove_devices(lm3533->dev); - lm3533_disable(lm3533); -} - -static bool lm3533_readable_register(struct device *dev, unsigned int reg) -{ - switch (reg) { - case 0x10 ... 0x2c: - case 0x30 ... 0x38: - case 0x40 ... 0x45: - case 0x50 ... 0x57: - case 0x60 ... 0x6e: - case 0x70 ... 0x75: - case 0x80 ... 0x85: - case 0x90 ... 0x95: - case 0xa0 ... 0xa5: - case 0xb0 ... 0xb2: - return true; - default: - return false; - } -} - -static bool lm3533_volatile_register(struct device *dev, unsigned int reg) -{ - switch (reg) { - case 0x34 ... 0x36: /* zone */ - case 0x37 ... 0x38: /* adc */ - case 0xb0 ... 0xb1: /* fault */ - return true; - default: - return false; - } -} - -static bool lm3533_precious_register(struct device *dev, unsigned int reg) -{ - switch (reg) { - case 0x34: /* zone */ - return true; - default: - return false; - } -} - -static const struct regmap_config regmap_config = { - .reg_bits = 8, - .val_bits = 8, - .max_register = LM3533_REG_MAX, - .readable_reg = lm3533_readable_register, - .volatile_reg = lm3533_volatile_register, - .precious_reg = lm3533_precious_register, -}; - -static int lm3533_i2c_probe(struct i2c_client *i2c) -{ - struct lm3533 *lm3533; - - dev_dbg(&i2c->dev, "%s\n", __func__); - - lm3533 = devm_kzalloc(&i2c->dev, sizeof(*lm3533), GFP_KERNEL); - if (!lm3533) - return -ENOMEM; - - i2c_set_clientdata(i2c, lm3533); - - lm3533->regmap = devm_regmap_init_i2c(i2c, ®map_config); - if (IS_ERR(lm3533->regmap)) - return PTR_ERR(lm3533->regmap); - - lm3533->dev = &i2c->dev; - lm3533->irq = i2c->irq; - - return lm3533_device_init(lm3533); -} - -static void lm3533_i2c_remove(struct i2c_client *i2c) -{ - struct lm3533 *lm3533 = i2c_get_clientdata(i2c); - - dev_dbg(&i2c->dev, "%s\n", __func__); - - lm3533_device_exit(lm3533); -} - -static const struct i2c_device_id lm3533_i2c_ids[] = { - { "lm3533", 0 }, - { }, -}; -MODULE_DEVICE_TABLE(i2c, lm3533_i2c_ids); - -static struct i2c_driver lm3533_i2c_driver = { - .driver = { - .name = "lm3533", - }, - .id_table = lm3533_i2c_ids, - .probe = lm3533_i2c_probe, - .remove = lm3533_i2c_remove, -}; - -static int __init lm3533_i2c_init(void) -{ - return i2c_add_driver(&lm3533_i2c_driver); -} -subsys_initcall(lm3533_i2c_init); - -static void __exit lm3533_i2c_exit(void) -{ - i2c_del_driver(&lm3533_i2c_driver); -} -module_exit(lm3533_i2c_exit); - -MODULE_AUTHOR("Johan Hovold "); -MODULE_DESCRIPTION("LM3533 Core"); -MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/lm3533.h b/include/linux/mfd/lm3533.h deleted file mode 100644 index 77092f6363ad..000000000000 --- a/include/linux/mfd/lm3533.h +++ /dev/null @@ -1,100 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * lm3533.h -- LM3533 interface - * - * Copyright (C) 2011-2012 Texas Instruments - * - * Author: Johan Hovold - */ - -#ifndef __LINUX_MFD_LM3533_H -#define __LINUX_MFD_LM3533_H - -#define LM3533_ATTR_RO(_name) \ - DEVICE_ATTR(_name, S_IRUGO, show_##_name, NULL) -#define LM3533_ATTR_RW(_name) \ - DEVICE_ATTR(_name, S_IRUGO | S_IWUSR , show_##_name, store_##_name) - -struct device; -struct regmap; - -struct lm3533 { - struct device *dev; - - struct regmap *regmap; - - int gpio_hwen; - int irq; - - unsigned have_als:1; - unsigned have_backlights:1; - unsigned have_leds:1; -}; - -struct lm3533_ctrlbank { - struct lm3533 *lm3533; - struct device *dev; - int id; -}; - -struct lm3533_als_platform_data { - unsigned pwm_mode:1; /* PWM input mode (default analog) */ - u8 r_select; /* 1 - 127 (ignored in PWM-mode) */ -}; - -struct lm3533_bl_platform_data { - char *name; - u16 max_current; /* 5000 - 29800 uA (800 uA step) */ - u8 default_brightness; /* 0 - 255 */ - u8 pwm; /* 0 - 0x3f */ -}; - -struct lm3533_led_platform_data { - char *name; - const char *default_trigger; - u16 max_current; /* 5000 - 29800 uA (800 uA step) */ - u8 pwm; /* 0 - 0x3f */ -}; - -enum lm3533_boost_freq { - LM3533_BOOST_FREQ_500KHZ, - LM3533_BOOST_FREQ_1000KHZ, -}; - -enum lm3533_boost_ovp { - LM3533_BOOST_OVP_16V, - LM3533_BOOST_OVP_24V, - LM3533_BOOST_OVP_32V, - LM3533_BOOST_OVP_40V, -}; - -struct lm3533_platform_data { - int gpio_hwen; - - enum lm3533_boost_ovp boost_ovp; - enum lm3533_boost_freq boost_freq; - - struct lm3533_als_platform_data *als; - - struct lm3533_bl_platform_data *backlights; - int num_backlights; - - struct lm3533_led_platform_data *leds; - int num_leds; -}; - -extern int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb); -extern int lm3533_ctrlbank_disable(struct lm3533_ctrlbank *cb); - -extern int lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u8 val); -extern int lm3533_ctrlbank_get_brightness(struct lm3533_ctrlbank *cb, u8 *val); -extern int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, - u16 imax); -extern int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u8 val); -extern int lm3533_ctrlbank_get_pwm(struct lm3533_ctrlbank *cb, u8 *val); - -extern int lm3533_read(struct lm3533 *lm3533, u8 reg, u8 *val); -extern int lm3533_write(struct lm3533 *lm3533, u8 reg, u8 val); -extern int lm3533_update(struct lm3533 *lm3533, u8 reg, u8 val, u8 mask); - -#endif /* __LINUX_MFD_LM3533_H */