From patchwork Mon Jan 21 21:56:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 156255 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6848706jaa; Mon, 21 Jan 2019 13:57:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN4fK/yeJdk+wQbZUPWnX8o/hxfWqmhLDE1rVVIgyjoOOitjcKZanJgHhRb5BKNTN+9GHM5W X-Received: by 2002:a17:902:82c2:: with SMTP id u2mr31684271plz.110.1548107829673; Mon, 21 Jan 2019 13:57:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548107829; cv=none; d=google.com; s=arc-20160816; b=wlgtbox4HwYKKP0wwHULMRKukiHjehrARs1s3Sn+EU2CnC05mJdqBdYcgqWAQTAWD1 oludySnxPX+pwtzKCqbm0rupGviG3LLpNKipDxiuWujGoCuHxIjOYJFMWwCSFPEDV9ZK mTjhcZjJgE6CBqsBh+lOI/jS2JDhW14ZNqitC+iE3B+rBQwUqjuQPPWTqjs+uylv+dqQ 6ZW+pldDFPRaZ86E5erwk74+jWBiZ1bSTgqwBx9xd6seS/YMPziLQNvgxANBSHiAwsXC /n2nHQ0xl8b3K29a60Jn8Ign9MIJiXRxTsa+KBkiQe58bKTiQtG3pxVPcX3sDxk+8aev fyyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=IuIpqXWRHwXTk1fmAHaVMVRJZ83QSYHuTBY9toToh1Q=; b=xmmcTc01oskJqY2gPu8UDig4WgJfNHZrYSOTETpgXx3dDXdyIXNWW3s+jP0TZYQOTP oXmknYJbPPSlMpq1hYjFme1Sifhi5DhkvDTxFJx2+Ks7Y9M0qOVlnYE5/7O6wndlq2fr lTeLtB9U+n5uD1dsj+pkZumygKXBvuiEXgLDDFJa2q5eRHhw7uDtFhgzp/JBpimKM+sk dk+TDZo+See4Ji64TIOUnp2siJwQRRjh1/PRCOKv8CR/xdxfQlj94miyAZemi3jaN8Q+ beLrgq054Fph7+kfegYpM64OcTRK5RKm59QwWXX4oqxJbgdssmfein+O4bOAVaJMAHKL XIaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Cl5IMrgM; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si14124932plc.40.2019.01.21.13.57.09; Mon, 21 Jan 2019 13:57:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Cl5IMrgM; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727785AbfAUV5I (ORCPT + 1 other); Mon, 21 Jan 2019 16:57:08 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:39652 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727761AbfAUV5I (ORCPT ); Mon, 21 Jan 2019 16:57:08 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0LLv4Ok089726; Mon, 21 Jan 2019 15:57:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548107824; bh=IuIpqXWRHwXTk1fmAHaVMVRJZ83QSYHuTBY9toToh1Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Cl5IMrgMdGtHKj95q0KnVxBLfMcbb8ZKuswwiZu4gVHVwcKybXlCKHGIZKFpP33ac gq8/AExxlbXbjpLl6/xxctQKpGOSG82AH5Qa0DnpdodxLb9HCz1ksZvvLEFGoRqpJg oK24WZmsqUUZUxPgzW29Aeo5Sdncfr8hfYCZtNbk= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0LLv3Tf081620 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 21 Jan 2019 15:57:04 -0600 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 21 Jan 2019 15:57:03 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 21 Jan 2019 15:57:03 -0600 Received: from legion.dal.desgin.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0LLv3cN002274; Mon, 21 Jan 2019 15:57:03 -0600 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.78.123]) by legion.dal.desgin.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id x0LLv3U20732; Mon, 21 Jan 2019 15:57:03 -0600 (CST) From: Dan Murphy To: CC: , , , Dan Murphy Subject: [RFC PATCH 3/6] leds: rgb: Add a dummy test file to test the RGB framework Date: Mon, 21 Jan 2019 15:56:56 -0600 Message-ID: <20190121215659.31125-4-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20190121215659.31125-1-dmurphy@ti.com> References: <20190121215659.31125-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Signed-off-by: Dan Murphy --- drivers/leds/Kconfig | 4 + drivers/leds/Makefile | 1 + drivers/leds/leds-rgb-fw-test.c | 177 ++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 drivers/leds/leds-rgb-fw-test.c -- 2.20.1.98.gecbdaf0899 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index f2d8bb7f4a6d..4369f287ec32 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -775,6 +775,10 @@ config LEDS_NIC78BX To compile this driver as a module, choose M here: the module will be called leds-nic78bx. +config LEDS_RGB_TEST + tristate "RGB Class Test file" + depends on LEDS_CLASS_RGB + comment "LED Triggers" source "drivers/leds/trigger/Kconfig" diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 5806760f00cb..4ec8f2c6e1f3 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -80,6 +80,7 @@ obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o obj-$(CONFIG_LEDS_LM3692X) += leds-lm3692x.o obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o +obj-$(CONFIG_LEDS_RGB_TEST) += leds-rgb-fw-test.o # LED SPI Drivers obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o diff --git a/drivers/leds/leds-rgb-fw-test.c b/drivers/leds/leds-rgb-fw-test.c new file mode 100644 index 000000000000..d9f8335372d5 --- /dev/null +++ b/drivers/leds/leds-rgb-fw-test.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0 +// LED RGB class interface +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct rgb_fw_test_led { + struct led_classdev_rgb rgbled_cdev; + struct i2c_client *client; + + u32 white_setting[3]; + + u32 led_strings[3]; + + char led_name[LED_MAX_NAME_SIZE]; + u8 available_rgbs; +}; + +static struct rgb_fw_test_led *rgbled_cdev_to_led(struct led_classdev_rgb *rgbled_cdev) +{ + return container_of(rgbled_cdev, struct rgb_fw_test_led, rgbled_cdev); +} + +static int rgb_fw_set_red(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + printk("%s: Brightness is 0x%X\n", __func__, brightness); + return 0; +} + +static int rgb_fw_set_green(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + + printk("%s: Brightness is 0x%X\n", __func__, brightness); + return 0; +} + +static int rgb_fw_set_blue(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + + printk("%s: Brightness is 0x%X\n", __func__, brightness); + return 0; +} + +static int rgb_fw_set_color(struct led_classdev_rgb *rgbled_cdev) +{ +// struct rgb_fw_test_led *led = rgbled_cdev_to_led(rgbled_cdev); + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + + printk("%s: Would set red to %d\n", __func__, colors->red); + printk("%s: Would set green to %d\n", __func__, colors->green); + printk("%s: Would set blue to %d\n", __func__, colors->blue); + + return 0; +} + +static struct led_rgb_ops rgb_test_ops = { + .set_color = rgb_fw_set_color, +/* Need to do get functions */ +// .get_color = rgb_fw_get_color, +}; +static int rgb_fw_test_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + + printk("%s: Brightness is 0x%X\n", __func__, brightness); + return 0; +} + +static int rgb_fw_test_register_leds(struct rgb_fw_test_led *led) +{ + struct led_classdev *led_cdev; + + led->rgbled_cdev.ops = &rgb_test_ops; + + if (led->led_strings[0] != 0xff) + led->rgbled_cdev.ops->set_red_brightness = rgb_fw_set_red; + if (led->led_strings[1] != 0xff) + led->rgbled_cdev.ops->set_green_brightness = rgb_fw_set_green; + if (led->led_strings[2] != 0xff) + led->rgbled_cdev.ops->set_blue_brightness = rgb_fw_set_blue; + + led_cdev = &led->rgbled_cdev.led_cdev; + led_cdev->brightness_set_blocking = rgb_fw_test_brightness_set; + led_cdev->name = led->led_name; + + return led_classdev_rgb_register(&led->client->dev, &led->rgbled_cdev); +} + +static int rgb_fw_test_probe_node(struct rgb_fw_test_led *led) +{ + + struct fwnode_handle *child = NULL; + const char *name; + int ret; + +/* Need to set this up for multiple nodes this is not working since we reuse +the same led node. Need to fix that to continue */ + device_for_each_child_node(&led->client->dev, child) { + ret = fwnode_property_read_string(child, "label", &name); + + snprintf(led->led_name, sizeof(led->led_name), + "%s:%s", led->client->name, name); + + ret = fwnode_property_read_u32_array(child, "rgb-sources", + NULL, 0); + ret = fwnode_property_read_u32_array(child, "rgb-sources", + led->led_strings, ret); + + ret = rgb_fw_test_register_leds(led); + } + return 0; +} + +static int rgb_fw_test_probe(struct i2c_client *client) +{ + struct rgb_fw_test_led *led; + int ret; + + led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + led->client = client; + i2c_set_clientdata(client, led); + + ret = rgb_fw_test_probe_node(led); + if (ret) + return -ENODEV; + + return ret; +} + +static int rgb_fw_test_remove(struct i2c_client *client) +{ + struct rgb_fw_test_led *led = i2c_get_clientdata(client); + + led_classdev_rgb_unregister(&led->rgbled_cdev); + + return 0; +} + +static const struct i2c_device_id rgb_fw_test_id[] = { + { "RGBNONE", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, lm3601x_id); + +static const struct of_device_id of_rgb_fw_test_leds_match[] = { + { .compatible = "rgb,framework_test", }, + { } +}; +MODULE_DEVICE_TABLE(of, of_rgb_fw_test_leds_match); + +static struct i2c_driver rgb_fw_test_i2c_driver = { + .driver = { + .name = "rgb_framework_test", + .of_match_table = of_rgb_fw_test_leds_match, + }, + .probe_new = rgb_fw_test_probe, + .remove = rgb_fw_test_remove, + .id_table = rgb_fw_test_id, +}; +module_i2c_driver(rgb_fw_test_i2c_driver); + +MODULE_AUTHOR("Dan Murphy "); +MODULE_DESCRIPTION("RGB LED class interface"); +MODULE_LICENSE("GPL v2");