Skip to contentSkip to conversation

Crystalcove (CRC) PMIC based panel and pwm control

PATCH Superseded Shobhit Kumar 8 participants 20 messages Jun 22, 2015 – Jul 15, 2015

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Crystalcove (CRC) PMIC based panel and pwm control

Hi All,
On some of the BYT devices, for DSI panels, the panel enable/disable signals and backlight control are done using the Crystalcove PMIC. This series provides support for the same and has been reviewed earlier on -
https://lkml.org/lkml/2015/4/29/301

This series addresses the review comments with one patch from last set already merged as -
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id=efb0de55b6a2ec15fc424e660601f22ae2fa487a

Basically following are implemented -

1. GPIO control for panel enable/disable with GFX device as consumer
2. New PWM chip driver added for CRC PMIC based backlight control
3. i915 is modified to use the CRC gpio chip and the CRC PWM chip to do backlight control. This is now added in the generic panel backlight control infrastructure

All these patches have been tested on AsusT100 and working fine using /sys/class/backlight/intel_backlight interface.

Patches were also verified on android-x86 tree for AsusT100.

Regards
Shobhit

Shobhit Kumar (7):
gpiolib: Add support for removing registered consumer lookup table
mfd: intel_soc_pmic_core: Add lookup table for Panel Control as GPIO
signal
mfd: intel_soc_pmic_crc: Add PWM cell device for Crystalcove PMIC
mfd: intel_soc_pmic_core: ADD PWM lookup table for CRC PMIC based PWM
pwm: crc: Add Crystalcove (CRC) PWM driver
drm/i915: Use the CRC gpio for panel enable/disable drm/i915: Backlight control using CRC PMIC based PWM driver

 drivers/gpio/gpiolib.c             |  13 ++++
 drivers/gpu/drm/i915/intel_bios.h  |   7 ++
 drivers/gpu/drm/i915/intel_drv.h   |   4 +
 drivers/gpu/drm/i915/intel_dsi.c   |  38 ++++++++-
 drivers/gpu/drm/i915/intel_dsi.h   |   3 +
 drivers/gpu/drm/i915/intel_panel.c |  95 +++++++++++++++++++++--
 drivers/mfd/intel_soc_pmic_core.c  |  29 +++++++
 drivers/mfd/intel_soc_pmic_crc.c   |   3 +
 drivers/pwm/Kconfig                |   7 ++
 drivers/pwm/Makefile               |   1 +
 drivers/pwm/pwm-crc.c              | 155 +++++++++++++++++++++++++++++++++++++
 include/linux/gpio/machine.h       |   1 +
 12 files changed, 349 insertions(+), 7 deletions(-)
 create mode 100644 drivers/pwm/pwm-crc.c
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH v2 1/7 gpiolib: Add support for removing registered consumer lookup table

In case we unload and load a driver module again that is registering a lookup table, without this it will result in multiple entries. Provide an option to remove the lookup table on driver unload

v2: Ccing maintainers
v3: Correct the subject line (Lee jones)

---
 drivers/gpio/gpiolib.c       | 13 +++++++++++++
 include/linux/gpio/machine.h |  1 +
 2 files changed, 14 insertions(+)
drivers/gpio/gpiolib.c +13 -0
index 957ede5..9d3ea4e 100644
@@ -1675,6 +1675,19 @@ void gpiod_add_lookup_table(struct gpiod_lookup_table *table)
 	mutex_unlock(&gpio_lookup_lock);
 }
 
+/**
+ * gpiod_remove_lookup_table() - unregister GPIO device consumers
+ * @table: table of consumers to unregister
+ */
+void gpiod_remove_lookup_table(struct gpiod_lookup_table *table)
+{
+	mutex_lock(&gpio_lookup_lock);
+
+	list_del(&table->list);
+
+	mutex_unlock(&gpio_lookup_lock);
+}
+
 static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
 				      unsigned int idx,
 				      enum gpio_lookup_flags *flags)
include/linux/gpio/machine.h +1 -0
index e270614..c0d712d 100644
@@ -57,5 +57,6 @@ struct gpiod_lookup_table {
 }
 
 void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
+void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
 
 #endif /* __LINUX_GPIO_MACHINE_H */
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH v2 2/7 mfd: intel_soc_pmic_core: Add lookup table for Panel Control as GPIO signal

In reply to Shobhit Kumar

On some Intel SoC platforms, the panel enable/disable signals are controlled by CRC PMIC. Add those control as a new GPIO in a lookup table for gpio-crystalcove chip during CRC driver load

v2: Make the lookup table static (Thierry)
Remove the lookup table during driver remove (Thierry)

v3: Correct the subject line (Lee jones)

---
 drivers/mfd/intel_soc_pmic_core.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/mfd/intel_soc_pmic_core.c +17 -0
index 7b50b6b..f3d918e 100644
@@ -24,8 +24,19 @@
 #include <linux/acpi.h>
 #include <linux/regmap.h>
 #include <linux/mfd/intel_soc_pmic.h>
+#include <linux/gpio/machine.h>
 #include "intel_soc_pmic_core.h"
 
+/* Lookup table for the Panel Enable/Disable line as GPIO signals */
+static struct gpiod_lookup_table panel_gpio_table = {
+	/* Intel GFX is consumer */
+	.dev_id = "0000:00:02.0",
+	.table = {
+		/* Panel EN/DISABLE */
+		GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH),
+	},
+};
+
 static int intel_soc_pmic_find_gpio_irq(struct device *dev)
 {
 	struct gpio_desc *desc;
@@ -85,6 +96,9 @@ static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c,
 	if (ret)
 		dev_warn(dev, "Can't enable IRQ as wake source: %d\n", ret);
 
+	/* Add lookup table binding for Panel Control to the GPIO Chip */
+	gpiod_add_lookup_table(&panel_gpio_table);
+
 	ret = mfd_add_devices(dev, -1, config->cell_dev,
 			      config->n_cell_devs, NULL, 0,
 			      regmap_irq_get_domain(pmic->irq_chip_data));
@@ -104,6 +118,9 @@ static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c)
 
 	regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
 
+	/* Remove lookup table for Panel Control from the GPIO Chip */
+	gpiod_remove_lookup_table(&panel_gpio_table);
+
 	mfd_remove_devices(&i2c->dev);
 
 	return 0;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH v2 3/7 mfd: intel_soc_pmic_crc: Add PWM cell device for Crystalcove PMIC

In reply to Shobhit Kumar

Needed for PWM control suuported by the PMIC

v2: Correct the subject line (Lee jones)

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/mfd/intel_soc_pmic_crc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mfd/intel_soc_pmic_crc.c +3 -0
index 7436075..4a74948 100644
@@ -109,6 +109,9 @@ static struct mfd_cell crystal_cove_dev[] = {
 	{
 		.name = "crystal_cove_pmic",
 	},
+	{
+		.name = "crystal_cove_pwm",
+	},
 };
 
 static const struct regmap_config crystal_cove_regmap_config = {
Signature · 4 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
#5 lore raw

PATCH v2 4/7 mfd: intel_soc_pmic_core: ADD PWM lookup table for CRC PMIC based PWM

In reply to Shobhit Kumar

On some BYT PLatform the PWM is controlled using CRC PMIC. Add a lookup entry for the same to be used by the consumer (Intel GFX)

v2: Remove the lookup table on driver unload (Thierry)

v3: Correct the subject line (Lee jones)

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/mfd/intel_soc_pmic_core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/mfd/intel_soc_pmic_core.c +12 -0
index f3d918e..a00ddd9 100644
@@ -25,6 +25,7 @@
 #include <linux/regmap.h>
 #include <linux/mfd/intel_soc_pmic.h>
 #include <linux/gpio/machine.h>
+#include <linux/pwm.h>
 #include "intel_soc_pmic_core.h"
 
 /* Lookup table for the Panel Enable/Disable line as GPIO signals */
@@ -37,6 +38,11 @@ static struct gpiod_lookup_table panel_gpio_table = {
 	},
 };
 
+/* PWM consumed by the Intel GFX */
+static struct pwm_lookup crc_pwm_lookup[] = {
+	PWM_LOOKUP("crystal_cove_pwm", 0, "0000:00:02.0", "pwm_backlight", 0, PWM_POLARITY_NORMAL),
+};
+
 static int intel_soc_pmic_find_gpio_irq(struct device *dev)
 {
 	struct gpio_desc *desc;
@@ -99,6 +105,9 @@ static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c,
 	/* Add lookup table binding for Panel Control to the GPIO Chip */
 	gpiod_add_lookup_table(&panel_gpio_table);
 
+	/* Add lookup table for crc-pwm */
+	pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
+
 	ret = mfd_add_devices(dev, -1, config->cell_dev,
 			      config->n_cell_devs, NULL, 0,
 			      regmap_irq_get_domain(pmic->irq_chip_data));
@@ -121,6 +130,9 @@ static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c)
 	/* Remove lookup table for Panel Control from the GPIO Chip */
 	gpiod_remove_lookup_table(&panel_gpio_table);
 
+	/* remove crc-pwm lookup table */
+	pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
+
 	mfd_remove_devices(&i2c->dev);
 
 	return 0;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw

PATCH v2 5/7 pwm: crc: Add Crystalcove (CRC) PWM driver

In reply to Shobhit Kumar

The Crystalcove PMIC provides three PWM signals and this driver exports one of them on the BYT platform which is used to control backlight for DSI panel. This is platform device implementation of the drivers/mfd cell device for CRC PMIC.

v2: Use the existing config callback with duty_ns and period_ns(Thierry)

v3: Correct the subject line (Lee jones)

v4: Address comment by Thierry & Paul
- Commit message update and fixes for few syntax errors
- Add PWM_CRC in Kconfig and Makefile sorted alphabetically
- Use the PWM_BASE_CLK as 6000000 for better code readability
- Remove the redundant rule of three while calculating pwm level
- Use the platform_device in pwm_chip
- Use builin_platform_driver

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Paul Bolle <[email protected]>
Cc Paul Gortmaker <[email protected]>
---
 drivers/pwm/Kconfig   |   7 +++
 drivers/pwm/Makefile  |   1 +
 drivers/pwm/pwm-crc.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+)
 create mode 100644 drivers/pwm/pwm-crc.c
drivers/pwm/Kconfig +7 -0
index b1541f4..948d9ab 100644
@@ -111,6 +111,13 @@ config PWM_CLPS711X
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-clps711x.
 
+config PWM_CRC
+	bool "Intel Crystalcove (CRC) PWM support"
+	depends on X86 && INTEL_SOC_PMIC
+	help
+	  Generic PWM framework driver for Crystalcove (CRC) PMIC based PWM
+	  control.
+
 config PWM_EP93XX
 	tristate "Cirrus Logic EP93xx PWM support"
 	depends on ARCH_EP93XX
drivers/pwm/Makefile +1 -0
index ec50eb5..d186f35 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_PWM_BCM_KONA)	+= pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BCM2835)	+= pwm-bcm2835.o
 obj-$(CONFIG_PWM_BFIN)		+= pwm-bfin.o
 obj-$(CONFIG_PWM_CLPS711X)	+= pwm-clps711x.o
+obj-$(CONFIG_PWM_CRC)		+= pwm-crc.o
 obj-$(CONFIG_PWM_EP93XX)	+= pwm-ep93xx.o
 obj-$(CONFIG_PWM_FSL_FTM)	+= pwm-fsl-ftm.o
 obj-$(CONFIG_PWM_IMG)		+= pwm-img.o
drivers/pwm/pwm-crc.c new file +155 -0

155 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw

PATCH v2 6/7 drm/i915: Use the CRC gpio for panel enable/disable

In reply to Shobhit Kumar

The CRC (Crystal Cove) PMIC, controls the panel enable and disable signals for BYT for dsi panels. This is indicated in the VBT fields. Use that to initialize and use GPIO based control for these signals.

v2: Use the newer gpiod interface(Alexandre)
v3: Remove the redundant checks and unused code (Ville)
v4: Moved PWM vs SoC backlight #defines to intel_bios.h (Jani)

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/gpu/drm/i915/intel_bios.h |  7 +++++++
 drivers/gpu/drm/i915/intel_dsi.c  | 32 ++++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/intel_dsi.h  |  3 +++
 3 files changed, 40 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_bios.h +7 -0
index af0b476..f7ad6a5 100644
@@ -778,6 +778,13 @@ int intel_parse_bios(struct drm_device *dev);
 #define MIPI_DSI_UNDEFINED_PANEL_ID	0
 #define MIPI_DSI_GENERIC_PANEL_ID	1
 
+/*
+ * PMIC vs SoC Backlight support specified in pwm_blc
+ * field in mipi_config block below.
+*/
+#define PPS_BLC_PMIC   0
+#define PPS_BLC_SOC    1
+
 struct mipi_config {
 	u16 panel_id;
 
drivers/gpu/drm/i915/intel_dsi.c +30 -2
index b5a5558..c4db74a 100644
@@ -31,6 +31,7 @@
 #include <drm/drm_panel.h>
 #include <drm/drm_mipi_dsi.h>
 #include <linux/slab.h>
+#include <linux/gpio/consumer.h>
 #include "i915_drv.h"
 #include "intel_drv.h"
 #include "intel_dsi.h"
@@ -415,6 +416,12 @@ static void intel_dsi_pre_enable(struct intel_encoder *encoder)
 
 	DRM_DEBUG_KMS("\n");
 
+	/* Panel Enable over CRC PMIC */
+	if (intel_dsi->gpio_panel)
+		gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
+
+	msleep(intel_dsi->panel_on_delay);
+
 	/* Disable DPOunit clock gating, can stall pipe
 	 * and we need DPLL REFA always enabled */
 	tmp = I915_READ(DPLL(pipe));
@@ -432,8 +439,6 @@ static void intel_dsi_pre_enable(struct intel_encoder *encoder)
 	/* put device in ready state */
 	intel_dsi_device_ready(encoder);
 
-	msleep(intel_dsi->panel_on_delay);
-
 	drm_panel_prepare(intel_dsi->panel);
 
 	for_each_dsi_port(port, intel_dsi->ports)
@@ -576,6 +581,10 @@ static void intel_dsi_post_disable(struct intel_encoder *encoder)
 
 	msleep(intel_dsi->panel_off_delay);
 	msleep(intel_dsi->panel_pwr_cycle_delay);
+
+	/* Panel Disable over CRC PMIC */
+	if (intel_dsi->gpio_panel)
+		gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
 }
 
 static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
@@ -955,6 +964,11 @@ static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
 		/* XXX: Logically this call belongs in the panel driver. */
 		drm_panel_remove(intel_dsi->panel);
 	}
+
+	/* dispose of the gpios */
+	if (intel_dsi->gpio_panel)
+		gpiod_put(intel_dsi->gpio_panel);
+
 	intel_encoder_destroy(encoder);
 }
 
@@ -1071,6 +1085,20 @@ void intel_dsi_init(struct drm_device *dev)
 		goto err;
 	}
 
+	/*
+	 * In case of BYT with CRC PMIC, we need to use GPIO for
+	 * Panel control.
+	 */
+	if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
+		intel_dsi->gpio_panel =
+			gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
+
+		if (IS_ERR(intel_dsi->gpio_panel)) {
+			DRM_ERROR("Failed to own gpio for panel control\n");
+			intel_dsi->gpio_panel = NULL;
+		}
+	}
+
 	intel_encoder->type = INTEL_OUTPUT_DSI;
 	intel_encoder->cloneable = 0;
 	drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
drivers/gpu/drm/i915/intel_dsi.h +3 -0
index 2784ac4..42a6859 100644
@@ -42,6 +42,9 @@ struct intel_dsi {
 	struct drm_panel *panel;
 	struct intel_dsi_host *dsi_hosts[I915_MAX_PORTS];
 
+	/* GPIO Desc for CRC based Panel control */
+	struct gpio_desc *gpio_panel;
+
 	struct intel_connector *attached_connector;
 
 	/* bit mask of ports being driven */
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#14 lore raw

PATCH v2 7/7 drm/i915: Backlight control using CRC PMIC based PWM driver

In reply to Shobhit Kumar

Use the CRC PWM device in intel_panel.c and add new MIPI backlight specififc callbacks

v2: Modify to use pwm_config callback
v3: Addressed Jani's comments
- Renamed all function as pwm_* instead of vlv_*
- Call intel_panel_actually_set_backlight in enable function
- Return -ENODEV in case pwm_get fails
- in case pwm_config error return error cdoe from pwm_config
- Cleanup pwm in intel_panel_destroy_backlight

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/gpu/drm/i915/intel_drv.h   |  4 ++
 drivers/gpu/drm/i915/intel_dsi.c   |  6 +++
 drivers/gpu/drm/i915/intel_panel.c | 95 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/intel_drv.h +4 -0
index 2afb31a..561c17f 100644
@@ -182,6 +182,10 @@ struct intel_panel {
 		bool enabled;
 		bool combination_mode;	/* gen 2/4 only */
 		bool active_low_pwm;
+
+		/* PWM chip */
+		struct pwm_device *pwm;
+
 		struct backlight_device *device;
 	} backlight;
 
drivers/gpu/drm/i915/intel_dsi.c +6 -0
index c4db74a..be8722c 100644
@@ -402,6 +402,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder)
 
 		intel_dsi_port_enable(encoder);
 	}
+
+	intel_panel_enable_backlight(intel_dsi->attached_connector);
 }
 
 static void intel_dsi_pre_enable(struct intel_encoder *encoder)
@@ -466,6 +468,8 @@ static void intel_dsi_pre_disable(struct intel_encoder *encoder)
 
 	DRM_DEBUG_KMS("\n");
 
+	intel_panel_disable_backlight(intel_dsi->attached_connector);
+
 	if (is_vid_mode(intel_dsi)) {
 		/* Send Shutdown command to the panel in LP mode */
 		for_each_dsi_port(port, intel_dsi->ports)
@@ -1132,6 +1136,8 @@ void intel_dsi_init(struct drm_device *dev)
 	}
 
 	intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
+	intel_panel_setup_backlight(connector,
+		(intel_encoder->crtc_mask = (1 << PIPE_A)) ? PIPE_A : PIPE_B);
 
 	return;
 
drivers/gpu/drm/i915/intel_panel.c +90 -5

145 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

Re: [v2 4/7] mfd: intel_soc_pmic_core: ADD PWM lookup table for CRC PMIC based PWM

In reply to Shobhit Kumar

Hi Shobhit Kumar,

Quoted 6 lines · Shobhit Kumar

On some BYT PLatform the PWM is controlled using CRC PMIC. Add a lookup entry for the same to be used by the consumer (Intel GFX)

v2: Remove the lookup table on driver unload (Thierry)

v3: Correct the subject line (Lee jones)

This part should only describe what this is about..

Don't put this patch change history over here.
Include this change history after
...
Signed-off-by: Author <email>
---

Quoted 7 lines
CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>

---

Here you add this change history so that after applying this will not be the part of your commit description.

This comment is applicable for all of your patches.

Signature · 5 lines
Best regards,
Varka Bhadram.

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
#11 lore raw

Re: [v2 5/7] pwm: crc: Add Crystalcove (CRC) PWM driver

In reply to Shobhit Kumar

Hi Shobhit Kumar,

Quoted 24 lines · Shobhit Kumar

The Crystalcove PMIC provides three PWM signals and this driver exports one of them on the BYT platform which is used to control backlight for DSI panel. This is platform device implementation of the drivers/mfd cell device for CRC PMIC.

v2: Use the existing config callback with duty_ns and period_ns(Thierry)

v3: Correct the subject line (Lee jones)

v4: Address comment by Thierry & Paul
- Commit message update and fixes for few syntax errors
- Add PWM_CRC in Kconfig and Makefile sorted alphabetically
- Use the PWM_BASE_CLK as 6000000 for better code readability
- Remove the redundant rule of three while calculating pwm level
- Use the platform_device in pwm_chip
- Use builin_platform_driver

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Paul Bolle <[email protected]>
Cc Paul Gortmaker <[email protected]>

(...)

drivers/pwm/pwm-crc.c line 22

Quoted 8 lines
drivers/pwm/pwm-crc.c new file +8 -0
+
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/mfd/intel_soc_pmic.h>
+#include <linux/pwm.h>
+
+#define PWM0_CLK_DIV		0x4B
+#define  PWM_OUTPUT_ENABLE	(1 << 7)

Can't be BIT() macro ?

Quoted 6 lines
drivers/pwm/pwm-crc.c new file +6 -0
+#define  PWM_DIV_CLK_0		0x00 /* DIVIDECLK = BASECLK */
+#define  PWM_DIV_CLK_100	0x63 /* DIVIDECLK = BASECLK/100 */
+#define  PWM_DIV_CLK_128	0x7F /* DIVIDECLK = BASECLK/128 */
+
+#define PWM0_DUTY_CYCLE		0x4E
+#define BACKLIGHT_EN		0x51

(...)

Quoted 15 lines
drivers/pwm/pwm-crc.c new file +15 -0
+static int crystalcove_pwm_probe(struct platform_device *pdev)
+{
+	struct crystalcove_pwm *pwm;
+	int retval;
+	struct device *dev = pdev->dev.parent;
+	struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
+
+	pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
+	if (!pwm)
+		return -ENOMEM;
+
+	pwm->chip.dev = &pdev->dev;
+	pwm->chip.ops = &crc_pwm_ops;
+	pwm->chip.base = -1;
+	pwm->chip.npwm = 1;

drivers/pwm/pwm-crc.c line 129

Quoted 10 lines
drivers/pwm/pwm-crc.c new file +10 -0
+
+	/* get the PMIC regmap */
+	pwm->regmap = pmic->regmap;
+
+	retval = pwmchip_add(&pwm->chip);
+	if (retval < 0)
+		return retval;
+
+	platform_set_drvdata(pdev, pwm);
+

If you can change this oder we can simply do something like this:

	platform_set_drvdata(pdev, pwm);
	
	return pwmchip_add(&pwm->chip);

drivers/pwm/pwm-crc.c line 142

Quoted 13 lines
drivers/pwm/pwm-crc.c new file +13 -0
+	return 0;
+}
+
+static int crystalcove_pwm_remove(struct platform_device *pdev)
+{
+	struct crystalcove_pwm *pwm = platform_get_drvdata(pdev);
+	int retval;
+
+	retval = pwmchip_remove(&pwm->chip);
+	if (retval < 0)
+		return retval;
+
+	dev_dbg(&pdev->dev, "crc-pwm driver removed\n");

This debug message may not be required :-)

you can directly do:

	return pwmchip_remove(&pwm->chip);
Quoted 13 lines
drivers/pwm/pwm-crc.c new file +13 -0
+
+	return 0;
+}
+
+static struct platform_driver crystalcove_pwm_driver = {
+	.probe = crystalcove_pwm_probe,
+	.remove = crystalcove_pwm_remove,
+	.driver = {
+		.name = "crystal_cove_pwm",
+	},
+};
+
+builtin_platform_driver(crystalcove_pwm_driver);
Signature · 5 lines
Best regards,
Varka Bhadram.

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
#7 lore raw

Re: [Intel-gfx] [v2 4/7] mfd: intel_soc_pmic_core: ADD PWM lookup table for CRC PMIC based PWM

In reply to Varka Bhadram
Quoted 27 lines · Varka Bhadram

Hi Shobhit Kumar,

Quoted 6 lines · Shobhit Kumar

On some BYT PLatform the PWM is controlled using CRC PMIC. Add a lookup entry for the same to be used by the consumer (Intel GFX)

v2: Remove the lookup table on driver unload (Thierry)

v3: Correct the subject line (Lee jones)

This part should only describe what this is about..

Don't put this patch change history over here.
Include this change history after
...
Signed-off-by: Author <email>
---

Quoted 7 lines
CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>

---

Quoted 4 lines

Here you add this change history so that after applying this will not be the part of your commit description.

This comment is applicable for all of your patches.

It's honestly a per-maintainer thing and hard to tell who wants what ... Personally I do want to include the patch changelog in the commit message. -Daniel

Quoted 10 lines
Signature · 8 lines
-- 
Best regards,
Varka Bhadram.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

Re: [Intel-gfx] [v2 4/7] mfd: intel_soc_pmic_core: ADD PWM lookup table for CRC PMIC based PWM

Quoted 28 lines · Daniel Vetter
Quoted 27 lines · Varka Bhadram

Hi Shobhit Kumar,

Quoted 6 lines · Shobhit Kumar

On some BYT PLatform the PWM is controlled using CRC PMIC. Add a lookup entry for the same to be used by the consumer (Intel GFX)

v2: Remove the lookup table on driver unload (Thierry)

v3: Correct the subject line (Lee jones)

This part should only describe what this is about..

Don't put this patch change history over here.
Include this change history after
...
Signed-off-by: Author <email>
---

Quoted 7 lines
CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>

---

Quoted 7 lines
Quoted 4 lines

Here you add this change history so that after applying this will not be the part of your commit description.

This comment is applicable for all of your patches.

It's honestly a per-maintainer thing and hard to tell who wants what ... Personally I do want to include the patch changelog in the commit message.

The patch change-log should go below the '---'. There are very few (weird ;) ) Maintainers who like to see them in the commit log.

Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw

Re: [Intel-gfx] [v2 5/7] pwm: crc: Add Crystalcove (CRC) PWM driver

In reply to Varka Bhadram
Quoted 32 lines · Varka Bhadram

Hi Shobhit Kumar,

Quoted 24 lines · Shobhit Kumar

The Crystalcove PMIC provides three PWM signals and this driver exports one of them on the BYT platform which is used to control backlight for DSI panel. This is platform device implementation of the drivers/mfd cell device for CRC PMIC.

v2: Use the existing config callback with duty_ns and period_ns(Thierry)

v3: Correct the subject line (Lee jones)

v4: Address comment by Thierry & Paul
- Commit message update and fixes for few syntax errors
- Add PWM_CRC in Kconfig and Makefile sorted alphabetically
- Use the PWM_BASE_CLK as 6000000 for better code readability
- Remove the redundant rule of three while calculating pwm level
- Use the platform_device in pwm_chip
- Use builin_platform_driver

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Paul Bolle <[email protected]>
Cc Paul Gortmaker <[email protected]>

(...)

Quoted 12 lines

drivers/pwm/pwm-crc.c line 22

Quoted 8 lines
drivers/pwm/pwm-crc.c new file +8 -0
+
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/mfd/intel_soc_pmic.h>
+#include <linux/pwm.h>
+
+#define PWM0_CLK_DIV           0x4B
+#define  PWM_OUTPUT_ENABLE     (1 << 7)

Can't be BIT() macro ?

Can be done.

Quoted 40 lines
Quoted 6 lines
drivers/pwm/pwm-crc.c new file +6 -0
+#define  PWM_DIV_CLK_0         0x00 /* DIVIDECLK = BASECLK */
+#define  PWM_DIV_CLK_100       0x63 /* DIVIDECLK = BASECLK/100 */
+#define  PWM_DIV_CLK_128       0x7F /* DIVIDECLK = BASECLK/128 */
+
+#define PWM0_DUTY_CYCLE                0x4E
+#define BACKLIGHT_EN           0x51

(...)

Quoted 15 lines
drivers/pwm/pwm-crc.c new file +15 -0
+static int crystalcove_pwm_probe(struct platform_device *pdev)
+{
+       struct crystalcove_pwm *pwm;
+       int retval;
+       struct device *dev = pdev->dev.parent;
+       struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
+
+       pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
+       if (!pwm)
+               return -ENOMEM;
+
+       pwm->chip.dev = &pdev->dev;
+       pwm->chip.ops = &crc_pwm_ops;
+       pwm->chip.base = -1;
+       pwm->chip.npwm = 1;

drivers/pwm/pwm-crc.c line 129

Quoted 10 lines
drivers/pwm/pwm-crc.c new file +10 -0
+
+       /* get the PMIC regmap */
+       pwm->regmap = pmic->regmap;
+
+       retval = pwmchip_add(&pwm->chip);
+       if (retval < 0)
+               return retval;
+
+       platform_set_drvdata(pdev, pwm);
+

If you can change this oder we can simply do something like this:

Quoted 4 lines
        platform_set_drvdata(pdev, pwm);

        return pwmchip_add(&pwm->chip);

Okay. seems better.

Quoted 17 lines

drivers/pwm/pwm-crc.c line 142

Quoted 13 lines
drivers/pwm/pwm-crc.c new file +13 -0
+       return 0;
+}
+
+static int crystalcove_pwm_remove(struct platform_device *pdev)
+{
+       struct crystalcove_pwm *pwm = platform_get_drvdata(pdev);
+       int retval;
+
+       retval = pwmchip_remove(&pwm->chip);
+       if (retval < 0)
+               return retval;
+
+       dev_dbg(&pdev->dev, "crc-pwm driver removed\n");

This debug message may not be required :-)

Quoted 3 lines

you can directly do:

        return pwmchip_remove(&pwm->chip);

Yeah, will update.

Regards
Shobhit

Quoted 22 lines
Quoted 4 lines
drivers/pwm/pwm-crc.c new file +3 -0
+
+       return 0;
+}

drivers/pwm/pwm-crc.c line 155

Quoted 10 lines
drivers/pwm/pwm-crc.c new file +10 -0
+
+static struct platform_driver crystalcove_pwm_driver = {
+       .probe = crystalcove_pwm_probe,
+       .remove = crystalcove_pwm_remove,
+       .driver = {
+               .name = "crystal_cove_pwm",
+       },
+};
+
+builtin_platform_driver(crystalcove_pwm_driver);

--
Best regards,
Varka Bhadram.

Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by Tested-by on v2 7/7
#15 lore raw

Re: [Intel-gfx] [v2 7/7] drm/i915: Backlight control using CRC PMIC based PWM driver

In reply to Shobhit Kumar
Quoted 60 lines · Shobhit Kumar

Use the CRC PWM device in intel_panel.c and add new MIPI backlight specififc callbacks

v2: Modify to use pwm_config callback
v3: Addressed Jani's comments
- Renamed all function as pwm_* instead of vlv_*
- Call intel_panel_actually_set_backlight in enable function
- Return -ENODEV in case pwm_get fails
- in case pwm_config error return error cdoe from pwm_config
- Cleanup pwm in intel_panel_destroy_backlight

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/gpu/drm/i915/intel_drv.h   |  4 ++
 drivers/gpu/drm/i915/intel_dsi.c   |  6 +++
 drivers/gpu/drm/i915/intel_panel.c | 95 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/intel_drv.h +4 -0
index 2afb31a..561c17f 100644
@@ -182,6 +182,10 @@ struct intel_panel {
 		bool enabled;
 		bool combination_mode;	/* gen 2/4 only */
 		bool active_low_pwm;
+
+		/* PWM chip */
+		struct pwm_device *pwm;
+
 		struct backlight_device *device;
 	} backlight;
 
drivers/gpu/drm/i915/intel_dsi.c +4 -0
index c4db74a..be8722c 100644
@@ -402,6 +402,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder)
 
 		intel_dsi_port_enable(encoder);
 	}
+
+	intel_panel_enable_backlight(intel_dsi->attached_connector);
 }
 
 static void intel_dsi_pre_enable(struct intel_encoder *encoder)
@@ -466,6 +468,8 @@ static void intel_dsi_pre_disable(struct intel_encoder *encoder)
 
 	DRM_DEBUG_KMS("\n");
 
+	intel_panel_disable_backlight(intel_dsi->attached_connector);
+
 	if (is_vid_mode(intel_dsi)) {
 		/* Send Shutdown command to the panel in LP mode */
 		for_each_dsi_port(port, intel_dsi->ports)

drivers/gpu/drm/i915/intel_dsi.c void intel_dsi_init(struct drm_device *dev) · line 1140

Quoted 5 lines
drivers/gpu/drm/i915/intel_dsi.c +2 -0
@@ -1132,6 +1136,8 @@ void intel_dsi_init(struct drm_device *dev)
 	}
 
 	intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
+	intel_panel_setup_backlight(connector,
+		(intel_encoder->crtc_mask = (1 << PIPE_A)) ? PIPE_A : PIPE_B);
                                          ^

Whoops. But since the PWM backlight doesn't need the initial pipe for anything you can actually just pass INVALID_PIPE here.

Quoted 8 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
 	return;
 
drivers/gpu/drm/i915/intel_panel.c +0 -0
index 7d83527..2aa30db 100644

drivers/gpu/drm/i915/intel_panel.c line 39

Quoted 8 lines
drivers/gpu/drm/i915/intel_panel.c +3 -0
@@ -32,8 +32,12 @@
 
 #include <linux/kernel.h>
 #include <linux/moduleparam.h>
+#include <linux/pwm.h>
 #include "intel_drv.h"
 
+#define CRC_PMIC_PWM_PERIOD_NS	21333
+#define CRC_PMIC_PWM_STEPS	255

This define appears to be unused.

Quoted 68 lines
drivers/gpu/drm/i915/intel_panel.c +36 -0
+
 void
 intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
 		       struct drm_display_mode *adjusted_mode)
@@ -544,6 +548,15 @@ static u32 bxt_get_backlight(struct intel_connector *connector)
 	return I915_READ(BXT_BLC_PWM_DUTY1);
 }
 
+static u32 pwm_get_backlight(struct intel_connector *connector)
+{
+	struct intel_panel *panel = &connector->panel;
+	int duty_ns;
+
+	duty_ns = pwm_get_duty_cycle(panel->backlight.pwm);
+	return DIV_ROUND_UP(duty_ns * 100, CRC_PMIC_PWM_PERIOD_NS);
+}
+
 static u32 intel_panel_get_backlight(struct intel_connector *connector)
 {
 	struct drm_device *dev = connector->base.dev;
@@ -632,6 +645,14 @@ static void bxt_set_backlight(struct intel_connector *connector, u32 level)
 	I915_WRITE(BXT_BLC_PWM_DUTY1, level);
 }
 
+static void pwm_set_backlight(struct intel_connector *connector, u32 level)
+{
+	struct intel_panel *panel = &connector->panel;
+	int duty_ns = DIV_ROUND_UP(level * CRC_PMIC_PWM_PERIOD_NS, 100);
+
+	pwm_config(panel->backlight.pwm, duty_ns, CRC_PMIC_PWM_PERIOD_NS);
+}
+
 static void
 intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level)
 {
@@ -769,6 +790,16 @@ static void bxt_disable_backlight(struct intel_connector *connector)
 	I915_WRITE(BXT_BLC_PWM_CTL1, tmp & ~BXT_BLC_PWM_ENABLE);
 }
 
+static void pwm_disable_backlight(struct intel_connector *connector)
+{
+	struct intel_panel *panel = &connector->panel;
+
+	/* Disable the backlight */
+	pwm_config(panel->backlight.pwm, 0, CRC_PMIC_PWM_PERIOD_NS);
+	usleep_range(2000, 3000);
+	pwm_disable(panel->backlight.pwm);
+}
+
 void intel_panel_disable_backlight(struct intel_connector *connector)
 {
 	struct drm_device *dev = connector->base.dev;
@@ -1002,6 +1033,14 @@ static void bxt_enable_backlight(struct intel_connector *connector)
 	I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl | BXT_BLC_PWM_ENABLE);
 }
 
+static void pwm_enable_backlight(struct intel_connector *connector)
+{
+	struct intel_panel *panel = &connector->panel;
+
+	pwm_enable(panel->backlight.pwm);
+	intel_panel_actually_set_backlight(connector, panel->backlight.level);
+}
+
 void intel_panel_enable_backlight(struct intel_connector *connector)
 {
 	struct drm_device *dev = connector->base.dev;

drivers/gpu/drm/i915/intel_panel.c bxt_setup_backlight(struct intel_connector *connector, enum pipe unused) · line 1425

Quoted 9 lines
drivers/gpu/drm/i915/intel_panel.c +6 -0
@@ -1378,6 +1417,40 @@ bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
 	return 0;
 }
 
+static int pwm_setup_backlight(struct intel_connector *connector,
+			       enum pipe pipe)
+{
+	struct drm_device *dev = connector->base.dev;
+	struct intel_panel *panel = &connector->panel;
+	int retval = -1;

No need to initialize it.

Quoted 43 lines
drivers/gpu/drm/i915/intel_panel.c +32 -0
+
+	/* Get the PWM chip for backlight control */
+	panel->backlight.pwm = pwm_get(dev->dev, "pwm_backlight");
+	if (IS_ERR(panel->backlight.pwm)) {
+		DRM_ERROR("Failed to own the pwm chip\n");
+		panel->backlight.pwm = NULL;
+		return -ENODEV;
+	}
+
+	retval = pwm_config(panel->backlight.pwm, CRC_PMIC_PWM_PERIOD_NS,
+			    CRC_PMIC_PWM_PERIOD_NS);
+	if (retval < 0) {
+		DRM_ERROR("Failed to configure the pwm chip\n");
+		pwm_put(panel->backlight.pwm);
+		panel->backlight.pwm = NULL;
+		return retval;
+	}
+
+	panel->backlight.min = 0; /* 0% */
+	panel->backlight.max = 100; /* 100% */
+	panel->backlight.level = DIV_ROUND_UP(
+				 pwm_get_duty_cycle(panel->backlight.pwm) * 100,
+				 CRC_PMIC_PWM_PERIOD_NS);
+	panel->backlight.enabled = panel->backlight.level != 0;
+
+	return 0;
+}
+
 int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe)
 {
 	struct drm_device *dev = connector->dev;
@@ -1421,6 +1494,10 @@ void intel_panel_destroy_backlight(struct drm_connector *connector)
 	struct intel_connector *intel_connector = to_intel_connector(connector);
 	struct intel_panel *panel = &intel_connector->panel;
 
+	/* dispose of the pwm */
+	if (panel->backlight.pwm)
+		pwm_put(panel->backlight.pwm);
+
 	panel->backlight.present = false;
 }
 

drivers/gpu/drm/i915/intel_panel.c void intel_panel_init_backlight_funcs(struct drm_device *dev) · line 1528

Quoted 9 lines
drivers/gpu/drm/i915/intel_panel.c +1 -5
@@ -1448,11 +1525,19 @@ void intel_panel_init_backlight_funcs(struct drm_device *dev)
 		dev_priv->display.set_backlight = pch_set_backlight;
 		dev_priv->display.get_backlight = pch_get_backlight;
 	} else if (IS_VALLEYVIEW(dev)) {
-		dev_priv->display.setup_backlight = vlv_setup_backlight;
-		dev_priv->display.enable_backlight = vlv_enable_backlight;
-		dev_priv->display.disable_backlight = vlv_disable_backlight;
-		dev_priv->display.set_backlight = vlv_set_backlight;
-		dev_priv->display.get_backlight = vlv_get_backlight;
+		if (dev_priv->vbt.has_mipi) {

Do all VLV DSI desins use the PMIC for backlight, or is there something more specific in VBT we could look at?

And what about CHT?

Othwerwise things seem reasonable, so with the the intel_panel_setup_backlight() pipe thing fixed this patch is

I also gave the entire series a go on my FFRD8 and it appears to work just fine, so you can also add

to all the patches if you want.

Quoted 22 lines
drivers/gpu/drm/i915/intel_panel.c +12 -0
+			dev_priv->display.setup_backlight = pwm_setup_backlight;
+			dev_priv->display.enable_backlight = pwm_enable_backlight;
+			dev_priv->display.disable_backlight = pwm_disable_backlight;
+			dev_priv->display.set_backlight = pwm_set_backlight;
+			dev_priv->display.get_backlight = pwm_get_backlight;
+		} else {
+			dev_priv->display.setup_backlight = vlv_setup_backlight;
+			dev_priv->display.enable_backlight = vlv_enable_backlight;
+			dev_priv->display.disable_backlight = vlv_disable_backlight;
+			dev_priv->display.set_backlight = vlv_set_backlight;
+			dev_priv->display.get_backlight = vlv_get_backlight;
+		}
 	} else if (IS_GEN4(dev)) {
 		dev_priv->display.setup_backlight = i965_setup_backlight;
 		dev_priv->display.enable_backlight = i965_enable_backlight;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#16 lore raw

Re: [Intel-gfx] [v2 7/7] drm/i915: Backlight control using CRC PMIC based PWM driver

Quoted 63 lines · Ville Syrjälä
Quoted 62 lines · Shobhit Kumar

Use the CRC PWM device in intel_panel.c and add new MIPI backlight specififc callbacks

v2: Modify to use pwm_config callback
v3: Addressed Jani's comments
- Renamed all function as pwm_* instead of vlv_*
- Call intel_panel_actually_set_backlight in enable function
- Return -ENODEV in case pwm_get fails
- in case pwm_config error return error cdoe from pwm_config
- Cleanup pwm in intel_panel_destroy_backlight

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/gpu/drm/i915/intel_drv.h   |  4 ++
 drivers/gpu/drm/i915/intel_dsi.c   |  6 +++
 drivers/gpu/drm/i915/intel_panel.c | 95 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/intel_drv.h +4 -0
index 2afb31a..561c17f 100644
@@ -182,6 +182,10 @@ struct intel_panel {
              bool enabled;
              bool combination_mode;  /* gen 2/4 only */
              bool active_low_pwm;
+
+             /* PWM chip */
+             struct pwm_device *pwm;
+
              struct backlight_device *device;
      } backlight;
 
drivers/gpu/drm/i915/intel_dsi.c +4 -0
index c4db74a..be8722c 100644
@@ -402,6 +402,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder)
 
              intel_dsi_port_enable(encoder);
      }
+
+     intel_panel_enable_backlight(intel_dsi->attached_connector);
 }
 
 static void intel_dsi_pre_enable(struct intel_encoder *encoder)
@@ -466,6 +468,8 @@ static void intel_dsi_pre_disable(struct intel_encoder *encoder)
 
      DRM_DEBUG_KMS("\n");
 
+     intel_panel_disable_backlight(intel_dsi->attached_connector);
+
      if (is_vid_mode(intel_dsi)) {
              /* Send Shutdown command to the panel in LP mode */
              for_each_dsi_port(port, intel_dsi->ports)
@@ -1132,6 +1136,8 @@ void intel_dsi_init(struct drm_device *dev)
      }
 
Quoted 8 lines

drivers/gpu/drm/i915/intel_dsi.c void intel_dsi_init(struct drm_device *dev) · line 1140

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +2 -0
      intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
+     intel_panel_setup_backlight(connector,
+             (intel_encoder->crtc_mask = (1 << PIPE_A)) ? PIPE_A : PIPE_B);
                                          ^

Whoops. But since the PWM backlight doesn't need the initial pipe for anything you can actually just pass INVALID_PIPE here.

You are right, its unused, but I thought passing right value still made sense. Otherwise it makes it look like I am setting up back-light for invalid pipe, when the real meaning is something like DONTCARE_PIPE

Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
      return;
 
drivers/gpu/drm/i915/intel_panel.c +1 -0
index 7d83527..2aa30db 100644
@@ -32,8 +32,12 @@
 
 #include <linux/kernel.h>
 #include <linux/moduleparam.h>
+#include <linux/pwm.h>
 #include "intel_drv.h"
 
Quoted 5 lines

drivers/gpu/drm/i915/intel_panel.c line 39

Quoted 2 lines
drivers/gpu/drm/i915/intel_panel.c +2 -0
+#define CRC_PMIC_PWM_PERIOD_NS       21333
+#define CRC_PMIC_PWM_STEPS   255

This define appears to be unused.

Yeah, missed removing it.

Quoted 122 lines
Quoted 68 lines
drivers/gpu/drm/i915/intel_panel.c +36 -0
+
 void
 intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
                     struct drm_display_mode *adjusted_mode)
@@ -544,6 +548,15 @@ static u32 bxt_get_backlight(struct intel_connector *connector)
      return I915_READ(BXT_BLC_PWM_DUTY1);
 }
 
+static u32 pwm_get_backlight(struct intel_connector *connector)
+{
+     struct intel_panel *panel = &connector->panel;
+     int duty_ns;
+
+     duty_ns = pwm_get_duty_cycle(panel->backlight.pwm);
+     return DIV_ROUND_UP(duty_ns * 100, CRC_PMIC_PWM_PERIOD_NS);
+}
+
 static u32 intel_panel_get_backlight(struct intel_connector *connector)
 {
      struct drm_device *dev = connector->base.dev;
@@ -632,6 +645,14 @@ static void bxt_set_backlight(struct intel_connector *connector, u32 level)
      I915_WRITE(BXT_BLC_PWM_DUTY1, level);
 }
 
+static void pwm_set_backlight(struct intel_connector *connector, u32 level)
+{
+     struct intel_panel *panel = &connector->panel;
+     int duty_ns = DIV_ROUND_UP(level * CRC_PMIC_PWM_PERIOD_NS, 100);
+
+     pwm_config(panel->backlight.pwm, duty_ns, CRC_PMIC_PWM_PERIOD_NS);
+}
+
 static void
 intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level)
 {
@@ -769,6 +790,16 @@ static void bxt_disable_backlight(struct intel_connector *connector)
      I915_WRITE(BXT_BLC_PWM_CTL1, tmp & ~BXT_BLC_PWM_ENABLE);
 }
 
+static void pwm_disable_backlight(struct intel_connector *connector)
+{
+     struct intel_panel *panel = &connector->panel;
+
+     /* Disable the backlight */
+     pwm_config(panel->backlight.pwm, 0, CRC_PMIC_PWM_PERIOD_NS);
+     usleep_range(2000, 3000);
+     pwm_disable(panel->backlight.pwm);
+}
+
 void intel_panel_disable_backlight(struct intel_connector *connector)
 {
      struct drm_device *dev = connector->base.dev;
@@ -1002,6 +1033,14 @@ static void bxt_enable_backlight(struct intel_connector *connector)
      I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl | BXT_BLC_PWM_ENABLE);
 }
 
+static void pwm_enable_backlight(struct intel_connector *connector)
+{
+     struct intel_panel *panel = &connector->panel;
+
+     pwm_enable(panel->backlight.pwm);
+     intel_panel_actually_set_backlight(connector, panel->backlight.level);
+}
+
 void intel_panel_enable_backlight(struct intel_connector *connector)
 {
      struct drm_device *dev = connector->base.dev;

drivers/gpu/drm/i915/intel_panel.c bxt_setup_backlight(struct intel_connector *connector, enum pipe unused) · line 1425

Quoted 9 lines
drivers/gpu/drm/i915/intel_panel.c +6 -0
@@ -1378,6 +1417,40 @@ bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
      return 0;
 }
 
+static int pwm_setup_backlight(struct intel_connector *connector,
+                            enum pipe pipe)
+{
+     struct drm_device *dev = connector->base.dev;
+     struct intel_panel *panel = &connector->panel;
+     int retval = -1;

No need to initialize it.

Quoted 42 lines
drivers/gpu/drm/i915/intel_panel.c +32 -0
+
+     /* Get the PWM chip for backlight control */
+     panel->backlight.pwm = pwm_get(dev->dev, "pwm_backlight");
+     if (IS_ERR(panel->backlight.pwm)) {
+             DRM_ERROR("Failed to own the pwm chip\n");
+             panel->backlight.pwm = NULL;
+             return -ENODEV;
+     }
+
+     retval = pwm_config(panel->backlight.pwm, CRC_PMIC_PWM_PERIOD_NS,
+                         CRC_PMIC_PWM_PERIOD_NS);
+     if (retval < 0) {
+             DRM_ERROR("Failed to configure the pwm chip\n");
+             pwm_put(panel->backlight.pwm);
+             panel->backlight.pwm = NULL;
+             return retval;
+     }
+
+     panel->backlight.min = 0; /* 0% */
+     panel->backlight.max = 100; /* 100% */
+     panel->backlight.level = DIV_ROUND_UP(
+                              pwm_get_duty_cycle(panel->backlight.pwm) * 100,
+                              CRC_PMIC_PWM_PERIOD_NS);
+     panel->backlight.enabled = panel->backlight.level != 0;
+
+     return 0;
+}
+
 int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe)
 {
      struct drm_device *dev = connector->dev;
@@ -1421,6 +1494,10 @@ void intel_panel_destroy_backlight(struct drm_connector *connector)
      struct intel_connector *intel_connector = to_intel_connector(connector);
      struct intel_panel *panel = &intel_connector->panel;
 
+     /* dispose of the pwm */
+     if (panel->backlight.pwm)
+             pwm_put(panel->backlight.pwm);
+
      panel->backlight.present = false;
 }
 
Quoted 14 lines

drivers/gpu/drm/i915/intel_panel.c void intel_panel_init_backlight_funcs(struct drm_device *dev) · line 1528

Quoted 10 lines
drivers/gpu/drm/i915/intel_panel.c +1 -5
@@ -1448,11 +1525,19 @@ void intel_panel_init_backlight_funcs(struct drm_device *dev)
              dev_priv->display.set_backlight = pch_set_backlight;
              dev_priv->display.get_backlight = pch_get_backlight;
      } else if (IS_VALLEYVIEW(dev)) {
-             dev_priv->display.setup_backlight = vlv_setup_backlight;
-             dev_priv->display.enable_backlight = vlv_enable_backlight;
-             dev_priv->display.disable_backlight = vlv_disable_backlight;
-             dev_priv->display.set_backlight = vlv_set_backlight;
-             dev_priv->display.get_backlight = vlv_get_backlight;
+             if (dev_priv->vbt.has_mipi) {

Do all VLV DSI desins use the PMIC for backlight, or is there something more specific in VBT we could look at?

No, VLV designs can actually also use LPSS PWM as well as DISPLAY_PWM. Infact we had a case where even for eDP, customer design used LPSS. So this flag in VBT for mipi_config block "pwm_blc" indicate the same for now. But today this is only PMIC Vs LPSS. There is another update pending where we have full flexibility in VBT to define PMIC or LPSS or DISPLAY_PWM to handle the eDP case that I mentioned above.

Quoted 1 line

And what about CHT?

Its the same as I described above. But then beyond CHT, there is effort to unify this all as only one SoC PWM.

Quoted 9 lines

Othwerwise things seem reasonable, so with the the intel_panel_setup_backlight() pipe thing fixed this patch is

I also gave the entire series a go on my FFRD8 and it appears to work just fine, so you can also add

to all the patches if you want.

Thanks a lot for testing it out.

Regards
Shobhit

Quoted 24 lines
Quoted 19 lines
drivers/gpu/drm/i915/intel_panel.c +12 -1
+                     dev_priv->display.setup_backlight = pwm_setup_backlight;
+                     dev_priv->display.enable_backlight = pwm_enable_backlight;
+                     dev_priv->display.disable_backlight = pwm_disable_backlight;
+                     dev_priv->display.set_backlight = pwm_set_backlight;
+                     dev_priv->display.get_backlight = pwm_get_backlight;
+             } else {
+                     dev_priv->display.setup_backlight = vlv_setup_backlight;
+                     dev_priv->display.enable_backlight = vlv_enable_backlight;
+                     dev_priv->display.disable_backlight = vlv_disable_backlight;
+                     dev_priv->display.set_backlight = vlv_set_backlight;
+                     dev_priv->display.get_backlight = vlv_get_backlight;
+             }
      } else if (IS_GEN4(dev)) {
              dev_priv->display.setup_backlight = i965_setup_backlight;
              dev_priv->display.enable_backlight = i965_enable_backlight;
--

1.9.1

Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Quoted 7 lines

--
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw

Re: [Intel-gfx] [v2 4/7] mfd: intel_soc_pmic_core: ADD PWM lookup table for CRC PMIC based PWM

In reply to Lee Jones
Quoted 33 lines · Lee Jones
Quoted 31 lines · Daniel Vetter
Quoted 30 lines · Varka Bhadram

Hi Shobhit Kumar,

Quoted 6 lines · Shobhit Kumar

On some BYT PLatform the PWM is controlled using CRC PMIC. Add a lookup entry for the same to be used by the consumer (Intel GFX)

v2: Remove the lookup table on driver unload (Thierry)

v3: Correct the subject line (Lee jones)

This part should only describe what this is about..

Don't put this patch change history over here.
Include this change history after
...
Signed-off-by: Author <email>
---

Quoted 7 lines
CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>

---

Here you add this change history so that after applying this will not be the part of your commit description.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

This comment is applicable for all of your patches.

It's honestly a per-maintainer thing and hard to tell who wants what ... Personally I do want to include the patch changelog in the commit message.

The patch change-log should go below the '---'. There are very few (weird ;) ) Maintainers who like to see them in the commit log.

To satisfy everybody, for the last two patches for intel-gfx, I will keep the version history as is, for others, I will move it down as suggested. Will push all again as new series after addressing all comments.

Regards
Shobhit

Quoted 10 lines

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead

Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#17 lore raw

Re: [Intel-gfx] [v2 7/7] drm/i915: Backlight control using CRC PMIC based PWM driver

In reply to Shobhit Kumar
Quoted 70 lines · Shobhit Kumar
Quoted 68 lines · Ville Syrjälä
Quoted 60 lines · Shobhit Kumar

Use the CRC PWM device in intel_panel.c and add new MIPI backlight specififc callbacks

v2: Modify to use pwm_config callback
v3: Addressed Jani's comments
- Renamed all function as pwm_* instead of vlv_*
- Call intel_panel_actually_set_backlight in enable function
- Return -ENODEV in case pwm_get fails
- in case pwm_config error return error cdoe from pwm_config
- Cleanup pwm in intel_panel_destroy_backlight

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/gpu/drm/i915/intel_drv.h   |  4 ++
 drivers/gpu/drm/i915/intel_dsi.c   |  6 +++
 drivers/gpu/drm/i915/intel_panel.c | 95 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/intel_drv.h +4 -0
index 2afb31a..561c17f 100644
@@ -182,6 +182,10 @@ struct intel_panel {
              bool enabled;
              bool combination_mode;  /* gen 2/4 only */
              bool active_low_pwm;
+
+             /* PWM chip */
+             struct pwm_device *pwm;
+
              struct backlight_device *device;
      } backlight;
 
drivers/gpu/drm/i915/intel_dsi.c +4 -0
index c4db74a..be8722c 100644
@@ -402,6 +402,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder)
 
              intel_dsi_port_enable(encoder);
      }
+
+     intel_panel_enable_backlight(intel_dsi->attached_connector);
 }
 
 static void intel_dsi_pre_enable(struct intel_encoder *encoder)
@@ -466,6 +468,8 @@ static void intel_dsi_pre_disable(struct intel_encoder *encoder)
 
      DRM_DEBUG_KMS("\n");
 
+     intel_panel_disable_backlight(intel_dsi->attached_connector);
+
      if (is_vid_mode(intel_dsi)) {
              /* Send Shutdown command to the panel in LP mode */
              for_each_dsi_port(port, intel_dsi->ports)

drivers/gpu/drm/i915/intel_dsi.c void intel_dsi_init(struct drm_device *dev) · line 1140

Quoted 5 lines
drivers/gpu/drm/i915/intel_dsi.c +2 -0
@@ -1132,6 +1136,8 @@ void intel_dsi_init(struct drm_device *dev)
      }
 
      intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
+     intel_panel_setup_backlight(connector,
+             (intel_encoder->crtc_mask = (1 << PIPE_A)) ? PIPE_A : PIPE_B);
                                          ^
Quoted 8 lines
Quoted 3 lines

Whoops. But since the PWM backlight doesn't need the initial pipe for anything you can actually just pass INVALID_PIPE here.

You are right, its unused, but I thought passing right value still made sense. Otherwise it makes it look like I am setting up back-light for invalid pipe, when the real meaning is something like DONTCARE_PIPE

Well it's not really about the pipe. It's about which set of BLC registers we're supoosed to use when using the BLC built into the display engine. And that's only done so that we take over the hardware state correctly. So INVALID_PIPE is just fine in this case since the backlight control has nothing to do with the pipe.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#18 lore raw

Re: [Intel-gfx] [v2 7/7] drm/i915: Backlight control using CRC PMIC based PWM driver

Quoted 80 lines · Ville Syrjälä
Quoted 70 lines · Shobhit Kumar
Quoted 68 lines · Ville Syrjälä
Quoted 60 lines · Shobhit Kumar

Use the CRC PWM device in intel_panel.c and add new MIPI backlight specififc callbacks

v2: Modify to use pwm_config callback
v3: Addressed Jani's comments
- Renamed all function as pwm_* instead of vlv_*
- Call intel_panel_actually_set_backlight in enable function
- Return -ENODEV in case pwm_get fails
- in case pwm_config error return error cdoe from pwm_config
- Cleanup pwm in intel_panel_destroy_backlight

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/gpu/drm/i915/intel_drv.h   |  4 ++
 drivers/gpu/drm/i915/intel_dsi.c   |  6 +++
 drivers/gpu/drm/i915/intel_panel.c | 95 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/intel_drv.h +4 -0
index 2afb31a..561c17f 100644
@@ -182,6 +182,10 @@ struct intel_panel {
              bool enabled;
              bool combination_mode;  /* gen 2/4 only */
              bool active_low_pwm;
+
+             /* PWM chip */
+             struct pwm_device *pwm;
+
              struct backlight_device *device;
      } backlight;
 
drivers/gpu/drm/i915/intel_dsi.c +4 -0
index c4db74a..be8722c 100644
@@ -402,6 +402,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder)
 
              intel_dsi_port_enable(encoder);
      }
+
+     intel_panel_enable_backlight(intel_dsi->attached_connector);
 }
 
 static void intel_dsi_pre_enable(struct intel_encoder *encoder)
@@ -466,6 +468,8 @@ static void intel_dsi_pre_disable(struct intel_encoder *encoder)
 
      DRM_DEBUG_KMS("\n");
 
+     intel_panel_disable_backlight(intel_dsi->attached_connector);
+
      if (is_vid_mode(intel_dsi)) {
              /* Send Shutdown command to the panel in LP mode */
              for_each_dsi_port(port, intel_dsi->ports)

drivers/gpu/drm/i915/intel_dsi.c void intel_dsi_init(struct drm_device *dev) · line 1140

Quoted 5 lines
drivers/gpu/drm/i915/intel_dsi.c +2 -0
@@ -1132,6 +1136,8 @@ void intel_dsi_init(struct drm_device *dev)
      }
 
      intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
+     intel_panel_setup_backlight(connector,
+             (intel_encoder->crtc_mask = (1 << PIPE_A)) ? PIPE_A : PIPE_B);
                                          ^
Quoted 8 lines
Quoted 3 lines

Whoops. But since the PWM backlight doesn't need the initial pipe for anything you can actually just pass INVALID_PIPE here.

You are right, its unused, but I thought passing right value still made sense. Otherwise it makes it look like I am setting up back-light for invalid pipe, when the real meaning is something like DONTCARE_PIPE

Quoted 6 lines

Well it's not really about the pipe. It's about which set of BLC registers we're supoosed to use when using the BLC built into the display engine. And that's only done so that we take over the hardware state correctly. So INVALID_PIPE is just fine in this case since the backlight control has nothing to do with the pipe.

Ok, will update.

Regards
Shobhit
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#19 lore raw

Re: [Intel-gfx] [v2 7/7] drm/i915: Backlight control using CRC PMIC based PWM driver

In reply to Shobhit Kumar
Quoted 238 lines · Shobhit Kumar
Quoted 63 lines · Ville Syrjälä
Quoted 62 lines · Shobhit Kumar

Use the CRC PWM device in intel_panel.c and add new MIPI backlight specififc callbacks

v2: Modify to use pwm_config callback
v3: Addressed Jani's comments
- Renamed all function as pwm_* instead of vlv_*
- Call intel_panel_actually_set_backlight in enable function
- Return -ENODEV in case pwm_get fails
- in case pwm_config error return error cdoe from pwm_config
- Cleanup pwm in intel_panel_destroy_backlight

CC Samuel Ortiz <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Thierry Reding <[email protected]>
---
 drivers/gpu/drm/i915/intel_drv.h   |  4 ++
 drivers/gpu/drm/i915/intel_dsi.c   |  6 +++
 drivers/gpu/drm/i915/intel_panel.c | 95 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/intel_drv.h +4 -0
index 2afb31a..561c17f 100644
@@ -182,6 +182,10 @@ struct intel_panel {
              bool enabled;
              bool combination_mode;  /* gen 2/4 only */
              bool active_low_pwm;
+
+             /* PWM chip */
+             struct pwm_device *pwm;
+
              struct backlight_device *device;
      } backlight;
 
drivers/gpu/drm/i915/intel_dsi.c +4 -0
index c4db74a..be8722c 100644
@@ -402,6 +402,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder)
 
              intel_dsi_port_enable(encoder);
      }
+
+     intel_panel_enable_backlight(intel_dsi->attached_connector);
 }
 
 static void intel_dsi_pre_enable(struct intel_encoder *encoder)
@@ -466,6 +468,8 @@ static void intel_dsi_pre_disable(struct intel_encoder *encoder)
 
      DRM_DEBUG_KMS("\n");
 
+     intel_panel_disable_backlight(intel_dsi->attached_connector);
+
      if (is_vid_mode(intel_dsi)) {
              /* Send Shutdown command to the panel in LP mode */
              for_each_dsi_port(port, intel_dsi->ports)
@@ -1132,6 +1136,8 @@ void intel_dsi_init(struct drm_device *dev)
      }
 
Quoted 8 lines

drivers/gpu/drm/i915/intel_dsi.c void intel_dsi_init(struct drm_device *dev) · line 1140

Quoted 3 lines
drivers/gpu/drm/i915/intel_dsi.c +2 -0
      intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
+     intel_panel_setup_backlight(connector,
+             (intel_encoder->crtc_mask = (1 << PIPE_A)) ? PIPE_A : PIPE_B);
                                          ^

Whoops. But since the PWM backlight doesn't need the initial pipe for anything you can actually just pass INVALID_PIPE here.

You are right, its unused, but I thought passing right value still made sense. Otherwise it makes it look like I am setting up back-light for invalid pipe, when the real meaning is something like DONTCARE_PIPE

Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/i915/intel_dsi.c +0 -0
      return;
 
drivers/gpu/drm/i915/intel_panel.c +1 -0
index 7d83527..2aa30db 100644
@@ -32,8 +32,12 @@
 
 #include <linux/kernel.h>
 #include <linux/moduleparam.h>
+#include <linux/pwm.h>
 #include "intel_drv.h"
 
Quoted 5 lines

drivers/gpu/drm/i915/intel_panel.c line 39

Quoted 2 lines
drivers/gpu/drm/i915/intel_panel.c +2 -0
+#define CRC_PMIC_PWM_PERIOD_NS       21333
+#define CRC_PMIC_PWM_STEPS   255

This define appears to be unused.

Yeah, missed removing it.

Quoted 122 lines
Quoted 68 lines
drivers/gpu/drm/i915/intel_panel.c +36 -0
+
 void
 intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
                     struct drm_display_mode *adjusted_mode)
@@ -544,6 +548,15 @@ static u32 bxt_get_backlight(struct intel_connector *connector)
      return I915_READ(BXT_BLC_PWM_DUTY1);
 }
 
+static u32 pwm_get_backlight(struct intel_connector *connector)
+{
+     struct intel_panel *panel = &connector->panel;
+     int duty_ns;
+
+     duty_ns = pwm_get_duty_cycle(panel->backlight.pwm);
+     return DIV_ROUND_UP(duty_ns * 100, CRC_PMIC_PWM_PERIOD_NS);
+}
+
 static u32 intel_panel_get_backlight(struct intel_connector *connector)
 {
      struct drm_device *dev = connector->base.dev;
@@ -632,6 +645,14 @@ static void bxt_set_backlight(struct intel_connector *connector, u32 level)
      I915_WRITE(BXT_BLC_PWM_DUTY1, level);
 }
 
+static void pwm_set_backlight(struct intel_connector *connector, u32 level)
+{
+     struct intel_panel *panel = &connector->panel;
+     int duty_ns = DIV_ROUND_UP(level * CRC_PMIC_PWM_PERIOD_NS, 100);
+
+     pwm_config(panel->backlight.pwm, duty_ns, CRC_PMIC_PWM_PERIOD_NS);
+}
+
 static void
 intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level)
 {
@@ -769,6 +790,16 @@ static void bxt_disable_backlight(struct intel_connector *connector)
      I915_WRITE(BXT_BLC_PWM_CTL1, tmp & ~BXT_BLC_PWM_ENABLE);
 }
 
+static void pwm_disable_backlight(struct intel_connector *connector)
+{
+     struct intel_panel *panel = &connector->panel;
+
+     /* Disable the backlight */
+     pwm_config(panel->backlight.pwm, 0, CRC_PMIC_PWM_PERIOD_NS);
+     usleep_range(2000, 3000);
+     pwm_disable(panel->backlight.pwm);
+}
+
 void intel_panel_disable_backlight(struct intel_connector *connector)
 {
      struct drm_device *dev = connector->base.dev;
@@ -1002,6 +1033,14 @@ static void bxt_enable_backlight(struct intel_connector *connector)
      I915_WRITE(BXT_BLC_PWM_CTL1, pwm_ctl | BXT_BLC_PWM_ENABLE);
 }
 
+static void pwm_enable_backlight(struct intel_connector *connector)
+{
+     struct intel_panel *panel = &connector->panel;
+
+     pwm_enable(panel->backlight.pwm);
+     intel_panel_actually_set_backlight(connector, panel->backlight.level);
+}
+
 void intel_panel_enable_backlight(struct intel_connector *connector)
 {
      struct drm_device *dev = connector->base.dev;

drivers/gpu/drm/i915/intel_panel.c bxt_setup_backlight(struct intel_connector *connector, enum pipe unused) · line 1425

Quoted 9 lines
drivers/gpu/drm/i915/intel_panel.c +6 -0
@@ -1378,6 +1417,40 @@ bxt_setup_backlight(struct intel_connector *connector, enum pipe unused)
      return 0;
 }
 
+static int pwm_setup_backlight(struct intel_connector *connector,
+                            enum pipe pipe)
+{
+     struct drm_device *dev = connector->base.dev;
+     struct intel_panel *panel = &connector->panel;
+     int retval = -1;

No need to initialize it.

Quoted 42 lines
drivers/gpu/drm/i915/intel_panel.c +32 -0
+
+     /* Get the PWM chip for backlight control */
+     panel->backlight.pwm = pwm_get(dev->dev, "pwm_backlight");
+     if (IS_ERR(panel->backlight.pwm)) {
+             DRM_ERROR("Failed to own the pwm chip\n");
+             panel->backlight.pwm = NULL;
+             return -ENODEV;
+     }
+
+     retval = pwm_config(panel->backlight.pwm, CRC_PMIC_PWM_PERIOD_NS,
+                         CRC_PMIC_PWM_PERIOD_NS);
+     if (retval < 0) {
+             DRM_ERROR("Failed to configure the pwm chip\n");
+             pwm_put(panel->backlight.pwm);
+             panel->backlight.pwm = NULL;
+             return retval;
+     }
+
+     panel->backlight.min = 0; /* 0% */
+     panel->backlight.max = 100; /* 100% */
+     panel->backlight.level = DIV_ROUND_UP(
+                              pwm_get_duty_cycle(panel->backlight.pwm) * 100,
+                              CRC_PMIC_PWM_PERIOD_NS);
+     panel->backlight.enabled = panel->backlight.level != 0;
+
+     return 0;
+}
+
 int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe)
 {
      struct drm_device *dev = connector->dev;
@@ -1421,6 +1494,10 @@ void intel_panel_destroy_backlight(struct drm_connector *connector)
      struct intel_connector *intel_connector = to_intel_connector(connector);
      struct intel_panel *panel = &intel_connector->panel;
 
+     /* dispose of the pwm */
+     if (panel->backlight.pwm)
+             pwm_put(panel->backlight.pwm);
+
      panel->backlight.present = false;
 }
 
Quoted 14 lines

drivers/gpu/drm/i915/intel_panel.c void intel_panel_init_backlight_funcs(struct drm_device *dev) · line 1528

Quoted 10 lines
drivers/gpu/drm/i915/intel_panel.c +1 -5
@@ -1448,11 +1525,19 @@ void intel_panel_init_backlight_funcs(struct drm_device *dev)
              dev_priv->display.set_backlight = pch_set_backlight;
              dev_priv->display.get_backlight = pch_get_backlight;
      } else if (IS_VALLEYVIEW(dev)) {
-             dev_priv->display.setup_backlight = vlv_setup_backlight;
-             dev_priv->display.enable_backlight = vlv_enable_backlight;
-             dev_priv->display.disable_backlight = vlv_disable_backlight;
-             dev_priv->display.set_backlight = vlv_set_backlight;
-             dev_priv->display.get_backlight = vlv_get_backlight;
+             if (dev_priv->vbt.has_mipi) {

Do all VLV DSI desins use the PMIC for backlight, or is there something more specific in VBT we could look at?

Quoted 6 lines

No, VLV designs can actually also use LPSS PWM as well as DISPLAY_PWM. Infact we had a case where even for eDP, customer design used LPSS. So this flag in VBT for mipi_config block "pwm_blc" indicate the same for now. But today this is only PMIC Vs LPSS. There is another update pending where we have full flexibility in VBT to define PMIC or LPSS or DISPLAY_PWM to handle the eDP case that I mentioned above.

Side note, we may need to move the hooks from dev_priv->display to connector->panel in the future.

BR,
Jani.

Quoted 52 lines
Quoted 2 lines

And what about CHT?

Its the same as I described above. But then beyond CHT, there is effort to unify this all as only one SoC PWM.

Quoted 9 lines

Othwerwise things seem reasonable, so with the the intel_panel_setup_backlight() pipe thing fixed this patch is

I also gave the entire series a go on my FFRD8 and it appears to work just fine, so you can also add

to all the patches if you want.

Thanks a lot for testing it out.

Regards
Shobhit

Quoted 31 lines
Quoted 19 lines
drivers/gpu/drm/i915/intel_panel.c +12 -1
+                     dev_priv->display.setup_backlight = pwm_setup_backlight;
+                     dev_priv->display.enable_backlight = pwm_enable_backlight;
+                     dev_priv->display.disable_backlight = pwm_disable_backlight;
+                     dev_priv->display.set_backlight = pwm_set_backlight;
+                     dev_priv->display.get_backlight = pwm_get_backlight;
+             } else {
+                     dev_priv->display.setup_backlight = vlv_setup_backlight;
+                     dev_priv->display.enable_backlight = vlv_enable_backlight;
+                     dev_priv->display.disable_backlight = vlv_disable_backlight;
+                     dev_priv->display.set_backlight = vlv_set_backlight;
+                     dev_priv->display.get_backlight = vlv_get_backlight;
+             }
      } else if (IS_GEN4(dev)) {
              dev_priv->display.setup_backlight = i965_setup_backlight;
              dev_priv->display.enable_backlight = i965_enable_backlight;
--

1.9.1

Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Re: [v2 1/7] gpiolib: Add support for removing registered consumer lookup table

In reply to Shobhit Kumar
Quoted 7 lines · Shobhit Kumar

In case we unload and load a driver module again that is registering a lookup table, without this it will result in multiple entries. Provide an option to remove the lookup table on driver unload

v2: Ccing maintainers
v3: Correct the subject line (Lee jones)

Quoted 7 lines

Do you plan to take this upstream for the next merge window or should I just merge this patch?

Yours,
Linus Walleij
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel