Skip to contentSkip to conversation

pinctrl: palmas: add pincontrol driver

PATCH Superseded Laxman Dewangan 4 participants 14 messages Jul 26, 2013 – Aug 8, 2013

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover pinctrl: palmas: add pincontrol driver

This series add the pin control driver for palam device. It add some common utility APIs in generic pinconf driver.

Laxman Dewangan (2):
pinctrl: pinconf_generic: add utility functions for add map/configs
pinctrl: palmas: add pincontrol driver

 .../devicetree/bindings/pinctrl/pinctrl-palmas.txt |   91 ++
 drivers/pinctrl/Kconfig                            |    9 +
 drivers/pinctrl/Makefile                           |    1 +
 drivers/pinctrl/pinconf-generic.c                  |  105 ++
 drivers/pinctrl/pinctrl-palmas.c                   | 1211 ++++++++++++++++++++
 include/linux/mfd/palmas.h                         |   35 +-
 include/linux/pinctrl/pinconf-generic.h            |   52 +
 7 files changed, 1493 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt
 create mode 100644 drivers/pinctrl/pinctrl-palmas.c
#1 lore raw

PATCH 1/2 pinctrl: pinconf_generic: add utility functions for add map/configs

Some of pincontrol driver needs the utility function to create map list. The utility function needed for adding mux, configs etc.

In place of duplicating this in each driver, add the common utility function in pin_conf and use from device specific driver. This will reduce the duplicating of code across drivers.

---
 drivers/pinctrl/pinconf-generic.c       |  105 +++++++++++++++++++++++++++++++
 include/linux/pinctrl/pinconf-generic.h |   52 +++++++++++++++
 2 files changed, 157 insertions(+), 0 deletions(-)
drivers/pinctrl/pinconf-generic.c +105 -0
index 8594f03..d9eae95 100644
@@ -236,4 +236,109 @@ out:
 	kfree(cfg);
 	return ret;
 }
+
+int pinconf_generic_reserve_map(struct device *dev,
+		struct pinctrl_map **map, unsigned *reserved_maps,
+		unsigned *num_maps, unsigned reserve)
+{
+	unsigned old_num = *reserved_maps;
+	unsigned new_num = *num_maps + reserve;
+	struct pinctrl_map *new_map;
+
+	if (old_num >= new_num)
+		return 0;
+
+	new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
+	if (!new_map) {
+		dev_err(dev, "krealloc(map) failed\n");
+		return -ENOMEM;
+	}
+
+	memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map));
+
+	*map = new_map;
+	*reserved_maps = new_num;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_reserve_map);
+
+int pinconf_generic_add_map_mux(struct pinctrl_map **map,
+		unsigned *reserved_maps, unsigned *num_maps,
+		const char *group, const char *function)
+{
+	if (WARN_ON(*num_maps == *reserved_maps))
+		return -ENOSPC;
+
+	(*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
+	(*map)[*num_maps].data.mux.group = group;
+	(*map)[*num_maps].data.mux.function = function;
+	(*num_maps)++;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_add_map_mux);
+
+int pinconf_generic_add_map_configs(struct device *dev,
+		struct pinctrl_map **map, unsigned *reserved_maps,
+		unsigned *num_maps, const char *group,
+		unsigned long *configs, unsigned num_configs)
+{
+	unsigned long *dup_configs;
+
+	if (WARN_ON(*num_maps == *reserved_maps))
+		return -ENOSPC;
+
+	dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
+			      GFP_KERNEL);
+	if (!dup_configs) {
+		dev_err(dev, "kmemdup(configs) failed\n");
+		return -ENOMEM;
+	}
+
+	(*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_GROUP;
+	(*map)[*num_maps].data.configs.group_or_pin = group;
+	(*map)[*num_maps].data.configs.configs = dup_configs;
+	(*map)[*num_maps].data.configs.num_configs = num_configs;
+	(*num_maps)++;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_add_map_configs);
+
+int pinconf_generic_add_config(struct device *dev, unsigned long **configs,
+		      unsigned *num_configs, unsigned long config)
+{
+	unsigned old_num = *num_configs;
+	unsigned new_num = old_num + 1;
+	unsigned long *new_configs;
+
+	new_configs = krealloc(*configs, sizeof(*new_configs) * new_num,
+			       GFP_KERNEL);
+	if (!new_configs) {
+		dev_err(dev, "krealloc(configs) failed\n");
+		return -ENOMEM;
+	}
+
+	new_configs[old_num] = config;
+
+	*configs = new_configs;
+	*num_configs = new_num;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_add_config);
+
+void pinconf_generic_dt_free_map(struct pinctrl_dev *pctldev,
+		      struct pinctrl_map *map, unsigned num_maps)
+{
+	int i;
+
+	for (i = 0; i < num_maps; i++)
+		if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP)
+			kfree(map[i].data.configs.configs);
+
+	kfree(map);
+}
+EXPORT_SYMBOL_GPL(pinconf_generic_dt_free_map);
+
 #endif
include/linux/pinctrl/pinconf-generic.h +52 -0

58 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#7 lore raw

PATCH 2/2 pinctrl: palmas: add pincontrol driver

In reply to Laxman Dewangan

TI Palam series Power Management IC have multiple pins which can be configured for different functionality. This pins can be configured for different function. Also their properties like pull up/down, open drain enable/disable are configurable.

Add support for pincontrol driver Palmas series device like TPS65913, TPS80036. The driver supports to be register from DT only.

---
 .../devicetree/bindings/pinctrl/pinctrl-palmas.txt |   91 ++
 drivers/pinctrl/Kconfig                            |   10 +
 drivers/pinctrl/Makefile                           |    1 +
 drivers/pinctrl/pinctrl-palmas.c                   | 1211 ++++++++++++++++++++
 include/linux/mfd/palmas.h                         |   35 +-
 5 files changed, 1337 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt
 create mode 100644 drivers/pinctrl/pinctrl-palmas.c
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt new file +91 -0
new file mode 100644
index 0000000..20b4527
@@ -0,0 +1,91 @@
+Palmas Pincontrol bindings
+
+The pins of palmas device can be set on different option and provides
+the configuration for Pull UP/DOWN, open drain etc.
+
+Required properties:
+- compatible: It must be one of following:
+  - "ti,palams-pinctrl" for palma series of the pincontrol.
+  - "ti,tps65913-pinctrl" for Palma series device TPS65913.
+  - "ti,tps80036-pinctrl" for palma series device TPS80036.
+
+Please refer to pinctrl-bindings.txt in this directory for details of the
+common pinctrl bindings used by client devices, including the meaning of the
+phrase "pin configuration node".
+
+Palmas's pin configuration nodes act as a container for an abitrary number of
+subnodes. Each of these subnodes represents some desired configuration for a
+pin, a group, or a list of pins or groups. This configuration can include the
+mux function to select on those pin(s)/group(s), and various pin configuration
+parameters, such as pull-up, open drain.
+
+The name of each subnode is not important; all subnodes should be enumerated
+and processed purely based on their content.
+
+Each subnode only affects those parameters that are explicitly listed. In
+other words, a subnode that lists a mux function but no pin configuration
+parameters implies no information about any pin configuration parameters.
+Similarly, a pin subnode that describes a pullup parameter implies no
+information about e.g. the mux function.
+
+Optional properties:
+- ti,palams-enable-dvfs1: Enable DVFS1. Configure pins for DVFS1 mode.
+- ti,palams-enable-dvfs2: Enable DVFS2. Configure pins for DVFS2 mode.
+
+Required subnode-properties:
+- ti,pins: An array of strings. Each string contains the name of a pin or
+    group. Valid values for these names are listed below.
+
+Optional subnode-properties:
+- ti,function:  string containing the name of the function to mux to the
+  pin or group. Valid values for function names are listed below. Please
+  refer the datasheet of the device to determine which are valid for each
+  pin or group.
+- ti,pull: Integer, representing the pull-down/up to apply to the pin.
+    0: none, 1: up, 2: down.
+- ti,open-drain" Integer, representing the open drain to be enable/disable
+  to the pin.
+    0: Disable, 1: Enable.
+
+
+Note that many of these properties are only valid for certain specific pins
+or groups. See the Palma device datasheet for complete details regarding which
+groups support which functionality.
+
+Valid values for pin and group names are:
+pins: gpio0_id, gpio1_vbus_det_led1_pwm1, gpio2_regen_led2_pwm2, gpio3_chrg_det,
+	gpio4_sysen1, gpio5_clk32kgaudio_usb_psel, gpio6_sysen2,
+	gpio7_msecure_pwrhold, gpio8_sim1rsti, gpio9_low_vbat,
+	gpio10_wireless_chrg1, gpio11_rcm, gpio12_sim2rsto, gpio13, gpio14,
+	gpio15_sim2rsti, vac, powergood_usb_psel, nreswarm, pwrdown,
+	gpadc_start, reset_in, nsleep, enable1, enable2, int.
+
+function: gpio, led, pwm, regen, sysen, clk32kgaudio, id, vbus_det, chrg_det,
+	vac, vacok, powergood, usb_psel, msecure, pwrhold, int, nreswarm,
+	simrsto, simrsti, low_vbat, wireless_chrg1, rcm, pwrdown, gpadc_start,
+	reset_in, nsleep, enable.
+
+Example:
+	palmas: tps65913@58 {
+		:::::::::::
+
+		pinctrl {
+			compatible = "ti,tps65913-pinctrl";
+			ti,palams-enable-dvfs1;
+			pinctrl-names = "default";
+			pinctrl-0 = <&palmas_pins_state>;
+
+			palmas_pins_state: pinmux {
+				gpio0_id {
+					ti,pins = "gpio0_id";
+					ti,function = "id";
+				};
+
+				vac {
+					ti,pins = "vac";
+					ti,function = "vacok";
+				};
+			};
+		};
+		:::::::::::
+	};
drivers/pinctrl/Kconfig +10 -0
index 5a8ad51..b62c331 100644
@@ -261,6 +261,16 @@ config PINCTRL_EXYNOS5440
 	select PINMUX
 	select PINCONF
 
+config PINCTRL_PALMAS
+	bool "Pinctrl driver for the PALMA Series MFD devices"
+	depends on OF && MFD_PALMAS
+	select GENERIC_PINCONF
+	help
+	  Palma device suppots the configuration of pins  for different
+	  functionality. This driver supports the pinmux, pushpull and
+	  open drain configuration for the palmas series devices like
+	  TPS65913, TPS80036 etc.
+
 config PINCTRL_S3C24XX
 	bool "Samsung S3C24XX SoC pinctrl driver"
 	depends on ARCH_S3C24XX
drivers/pinctrl/Makefile +1 -0
index d64563b..2251b30 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_PINCTRL_NOMADIK)	+= pinctrl-nomadik.o
 obj-$(CONFIG_PINCTRL_STN8815)	+= pinctrl-nomadik-stn8815.o
 obj-$(CONFIG_PINCTRL_DB8500)	+= pinctrl-nomadik-db8500.o
 obj-$(CONFIG_PINCTRL_DB8540)	+= pinctrl-nomadik-db8540.o
+obj-$(CONFIG_PINCTRL_PALMAS)	+= pinctrl-palmas.o
 obj-$(CONFIG_PINCTRL_ROCKCHIP)	+= pinctrl-rockchip.o
 obj-$(CONFIG_PINCTRL_SINGLE)	+= pinctrl-single.o
 obj-$(CONFIG_PINCTRL_SIRF)	+= sirf/
drivers/pinctrl/pinctrl-palmas.c new file +1211 -0

1,211 lines not on this page · raw message

include/linux/mfd/palmas.h +24 -11
index 1a8dd7a..2891f7c 100644
@@ -449,7 +449,7 @@ enum usb_irq_events {
 #define PALMAS_DVFS_BASE					0x180
 #define PALMAS_PMU_CONTROL_BASE					0x1A0
 #define PALMAS_RESOURCE_BASE					0x1D4
-#define PALMAS_PU_PD_OD_BASE					0x1F4
+#define PALMAS_PU_PD_OD_BASE					0x1F0
 #define PALMAS_LED_BASE						0x200
 #define PALMAS_INTERRUPT_BASE					0x210
 #define PALMAS_USB_OTG_BASE					0x250
@@ -1734,16 +1734,20 @@ enum usb_irq_events {
 #define PALMAS_REGEN3_CTRL_MODE_ACTIVE_SHIFT			0
 
 /* Registers for function PAD_CONTROL */
-#define PALMAS_PU_PD_INPUT_CTRL1				0x0
-#define PALMAS_PU_PD_INPUT_CTRL2				0x1
-#define PALMAS_PU_PD_INPUT_CTRL3				0x2
-#define PALMAS_OD_OUTPUT_CTRL					0x4
-#define PALMAS_POLARITY_CTRL					0x5
-#define PALMAS_PRIMARY_SECONDARY_PAD1				0x6
-#define PALMAS_PRIMARY_SECONDARY_PAD2				0x7
-#define PALMAS_I2C_SPI						0x8
-#define PALMAS_PU_PD_INPUT_CTRL4				0x9
-#define PALMAS_PRIMARY_SECONDARY_PAD3				0xA
+#define PALMAS_OD_OUTPUT_CTRL2					0x2
+#define PALMAS_POLARITY_CTRL2					0x3
+#define PALMAS_PU_PD_INPUT_CTRL1				0x4
+#define PALMAS_PU_PD_INPUT_CTRL2				0x5
+#define PALMAS_PU_PD_INPUT_CTRL3				0x6
+#define PALMAS_PU_PD_INPUT_CTRL5				0x7
+#define PALMAS_OD_OUTPUT_CTRL					0x8
+#define PALMAS_POLARITY_CTRL					0x9
+#define PALMAS_PRIMARY_SECONDARY_PAD1				0xA
+#define PALMAS_PRIMARY_SECONDARY_PAD2				0xB
+#define PALMAS_I2C_SPI						0xC
+#define PALMAS_PU_PD_INPUT_CTRL4				0xD
+#define PALMAS_PRIMARY_SECONDARY_PAD3				0xE
+#define PALMAS_PRIMARY_SECONDARY_PAD4				0xF
 
 /* Bit definitions for PU_PD_INPUT_CTRL1 */
 #define PALMAS_PU_PD_INPUT_CTRL1_RESET_IN_PD			0x40
@@ -2501,6 +2505,15 @@ enum usb_irq_events {
 #define PALMAS_PU_PD_GPIO_CTRL1					0x6
 #define PALMAS_PU_PD_GPIO_CTRL2					0x7
 #define PALMAS_OD_OUTPUT_GPIO_CTRL				0x8
+#define PALMAS_GPIO_DATA_IN2					0x9
+#define PALMAS_GPIO_DATA_DIR2					0x0A
+#define PALMAS_GPIO_DATA_OUT2					0x0B
+#define PALMAS_GPIO_DEBOUNCE_EN2				0x0C
+#define PALMAS_GPIO_CLEAR_DATA_OUT2				0x0D
+#define PALMAS_GPIO_SET_DATA_OUT2				0x0E
+#define PALMAS_PU_PD_GPIO_CTRL3					0x0F
+#define PALMAS_PU_PD_GPIO_CTRL4					0x10
+#define PALMAS_OD_OUTPUT_GPIO_CTRL2				0x11
 
 /* Bit definitions for GPIO_DATA_IN */
 #define PALMAS_GPIO_DATA_IN_GPIO_7_IN				0x80
Signature · 1 line
1.7.1.1
#8 lore raw

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 61

Quoted 6 lines · Laxman Dewangan
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt new file +6 -0
+pins: gpio0_id, gpio1_vbus_det_led1_pwm1, gpio2_regen_led2_pwm2, gpio3_chrg_det,
+	gpio4_sysen1, gpio5_clk32kgaudio_usb_psel, gpio6_sysen2,
+	gpio7_msecure_pwrhold, gpio8_sim1rsti, gpio9_low_vbat,
+	gpio10_wireless_chrg1, gpio11_rcm, gpio12_sim2rsto, gpio13, gpio14,
+	gpio15_sim2rsti, vac, powergood_usb_psel, nreswarm, pwrdown,
+	gpadc_start, reset_in, nsleep, enable1, enable2, int.

Would it not be easier to just name the GPIOs gpioN rather than using the full names with the possible functions?

#2 lore raw

Re: [PATCH 1/2] pinctrl: pinconf_generic: add utility functions for add map/configs

In reply to Laxman Dewangan
Quoted 2 lines · Laxman Dewangan

Some of pincontrol driver needs the utility function to create map list. The utility function needed for adding mux, configs etc.

Which other drivers already contain this code? Are you planning on converting them over to use these new functions? The code looks familiar, so I assume it's just cut/paste from Tegra with some renames, so I didn't read it through in detail.

Quoted 2 lines
 drivers/pinctrl/pinconf-generic.c       |  105 +++++++++++++++++++++++++++++++
 include/linux/pinctrl/pinconf-generic.h |   52 +++++++++++++++

I don't think those are the correct files for this code. Presumably there's no reason at all why a pinctrl driver that doesn't require CONFIG_GENERIC_PINCONF can't use these basic utility functions. Perhaps add a new pinctrl-utils file?

#11 lore raw
In reply to Laxman Dewangan

(Also CC'ing in the DT bindings maintainers, hence quoting all of the binding.)

Quoted 1 line · Laxman Dewangan

TI Palam series Power Management IC have multiple pins which can be

S/Palam/Palmas/ right? This name seems to get typo'd an awful lot, both in this patch and others... I suggest a thorough search/replace.

Quoted 15 lines

configured for different functionality. This pins can be configured for different function. Also their properties like pull up/down, open drain enable/disable are configurable.

Add support for pincontrol driver Palmas series device like TPS65913, TPS80036. The driver supports to be register from DT only.

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +6 -0
 
+Palmas Pincontrol bindings
+
+The pins of palmas device can be set on different option and provides
+the configuration for Pull UP/DOWN, open drain etc.
+
+Required properties:

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 16

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +10 -0
+- compatible: It must be one of following:
+  - "ti,palams-pinctrl" for palma series of the pincontrol.
+  - "ti,tps65913-pinctrl" for Palma series device TPS65913.
+  - "ti,tps80036-pinctrl" for palma series device TPS80036.
+
+Please refer to pinctrl-bindings.txt in this directory for details of the
+common pinctrl bindings used by client devices, including the meaning of the
+phrase "pin configuration node".
+
+Palmas's pin configuration nodes act as a container for an abitrary number of

s/abitrary/arbitrary/

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 18

Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +2 -0
+subnodes. Each of these subnodes represents some desired configuration for a
+pin, a group, or a list of pins or groups. This configuration can include the

I think this text was copied from an existing binding that describe HW that actually does mux pin groups not pins. Given the list of valid values for this field below, I think this HW muxes per-pin not per-group, so you may want to simplify this text; replace "a pin, a group, or a list of pins or groups" with "a pin or list of pins", or even just "a list of pins".

Quoted 1 line

+mux function to select on those pin(s)/group(s), and various pin configuration

And similarly, remove all mentions of "groups" elsewhere in the document, e.g. in the line above.

Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +4 -0
+parameters, such as pull-up, open drain.
+
+The name of each subnode is not important; all subnodes should be enumerated
+and processed purely based on their content.

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 33

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +10 -0
+
+Each subnode only affects those parameters that are explicitly listed. In
+other words, a subnode that lists a mux function but no pin configuration
+parameters implies no information about any pin configuration parameters.
+Similarly, a pin subnode that describes a pullup parameter implies no
+information about e.g. the mux function.
+
+Optional properties:
+- ti,palams-enable-dvfs1: Enable DVFS1. Configure pins for DVFS1 mode.
+- ti,palams-enable-dvfs2: Enable DVFS2. Configure pins for DVFS2 mode.

What do those options do? I see from the driver that they do directly control HW, so the options are fine from that perspective. I'm just wondering how they would impact the pinctrl semantics; does enabling those options mean that the pinctrl properties won't work for some pins? If so, it /might/ be worth at least briefly mentioning that here, although presumably it's already well-covered in the manual for the HW.

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 37

Quoted 3 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +3 -0
+Required subnode-properties:
+- ti,pins: An array of strings. Each string contains the name of a pin or
+    group. Valid values for these names are listed below.

(remove "or group")

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 41

Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +4 -0
+
+Optional subnode-properties:
+- ti,function:  string containing the name of the function to mux to the
+  pin or group. Valid values for function names are listed below. Please

(remove "or group")

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 43

Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +2 -0
+  refer the datasheet of the device to determine which are valid for each
+  pin or group.

(remove "or group")

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 48

Quoted 5 lines

+- ti,pull: Integer, representing the pull-down/up to apply to the pin.

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +4 -0
+    0: none, 1: up, 2: down.
+- ti,open-drain" Integer, representing the open drain to be enable/disable
+  to the pin.
+    0: Disable, 1: Enable.

Weren't DT bindings already defined for standard properties? I can't remember if that patch went through. If so, it might be worth using standard properties instead.

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 52

Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +2 -0
+Note that many of these properties are only valid for certain specific pins
+or groups. See the Palma device datasheet for complete details regarding which

(remove "or groups")

Quoted 1 line

+groups support which functionality.

s/groups/pins/

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt

Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +2 -0
+
+Valid values for pin and group names are:

(remove "and groups")

Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +6 -0
+pins: gpio0_id, gpio1_vbus_det_led1_pwm1, gpio2_regen_led2_pwm2, gpio3_chrg_det,
+	gpio4_sysen1, gpio5_clk32kgaudio_usb_psel, gpio6_sysen2,
+	gpio7_msecure_pwrhold, gpio8_sim1rsti, gpio9_low_vbat,
+	gpio10_wireless_chrg1, gpio11_rcm, gpio12_sim2rsto, gpio13, gpio14,
+	gpio15_sim2rsti, vac, powergood_usb_psel, nreswarm, pwrdown,
+	gpadc_start, reset_in, nsleep, enable1, enable2, int.

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 71

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +10 -0
+
+function: gpio, led, pwm, regen, sysen, clk32kgaudio, id, vbus_det, chrg_det,
+	vac, vacok, powergood, usb_psel, msecure, pwrhold, int, nreswarm,
+	simrsto, simrsti, low_vbat, wireless_chrg1, rcm, pwrdown, gpadc_start,
+	reset_in, nsleep, enable.
+
+Example:
+	palmas: tps65913@58 {
+		:::::::::::
+

Nit: Just deleting those two lines might easier. ... is more common than ::::: I think.

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 73

Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +2 -0
+		pinctrl {
+			compatible = "ti,tps65913-pinctrl";

Don't you need to add "ti,palams-pinctrl" to the end of that list?

Quoted 24 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt +18 -0
+			ti,palams-enable-dvfs1;
+			pinctrl-names = "default";
+			pinctrl-0 = <&palmas_pins_state>;
+
+			palmas_pins_state: pinmux {
+				gpio0_id {
+					ti,pins = "gpio0_id";
+					ti,function = "id";
+				};
+
+				vac {
+					ti,pins = "vac";
+					ti,function = "vacok";
+				};
+			};
+		};
+		:::::::::::
+	};
drivers/pinctrl/Kconfig +0 -0
index 5a8ad51..b62c331 100644

drivers/pinctrl/Kconfig config PINCTRL_EXYNOS5440 · line 269

Quoted 9 lines
drivers/pinctrl/Kconfig +6 -0
@@ -261,6 +261,16 @@ config PINCTRL_EXYNOS5440
 	select PINMUX
 	select PINCONF
 
+config PINCTRL_PALMAS
+	bool "Pinctrl driver for the PALMA Series MFD devices"
+	depends on OF && MFD_PALMAS
+	select GENERIC_PINCONF
+	help
+	  Palma device suppots the configuration of pins  for different

s/suppots/supports/. There are also two spaces there.

drivers/pinctrl/Kconfig config PINCTRL_EXYNOS5440 · line 270

Quoted 1 line
drivers/pinctrl/Kconfig +1 -0
+	  functionality. This driver supports the pinmux, pushpull and

Usually push-pull not pushpull.

drivers/pinctrl/Kconfig config PINCTRL_EXYNOS5440 · line 271

Quoted 1 line
drivers/pinctrl/Kconfig +1 -0
+	  open drain configuration for the palmas series devices like

I assume Palmas should be capitalized since it's a name.

drivers/pinctrl/pinctrl-palmas.c line 75

Quoted 10 lines
drivers/pinctrl/pinctrl-palmas.c +8 -0
 
+#define PALMAS_PINCONF_PACK(p, a)		(((p) << 16) | (a))
+#define PALMAS_PINCONF_UNPACK_PARAM(c)		(((c) >> 16) & 0xFFFFUL)
+#define PALMAS_PINCONF_UNPACK_ARG(c)		((c) & 0xFFFFUL)
+
+enum palmas_pinconf_param {
+	PALMAS_PINCONF_PARAM_PULL,
+	PALMAS_PINCONF_PARAM_OPEN_DRAIN,
+};

If you're relying on CONFIG_GENERIC_PINCONF, I think there's a generic version of those macros/enums you could use.

drivers/pinctrl/pinctrl-palmas.c line 92

Quoted 5 lines
drivers/pinctrl/pinctrl-palmas.c +5 -0
+struct palmas_pctrl_chip_info {
+	struct device *dev;
+	struct pinctrl_dev *pctl;
+	struct palmas *palmas;
+	int pins_current_opt[PALMAS_PIN_NUM];

That field looks odd. From what I can tell in the code, the location of the pull-up/down/... registers/bits varies depending on which mux function is selected for a particular pin? That's a very strange HW design. Are you sure the set of pins/functions this driver exposes is the correct way to represent the HW?

Quoted 1 line

+static const char * const gpio_group[] = {

I think all of these arrays should be named something_groups not something_group; they don't define a "pin group" but rather the list of pin groups upon which a particular function may be selected.

Quoted 1 line

+enum palmas_pinmux {

...

drivers/pinctrl/pinctrl-palmas.c line 415

Quoted 2 lines
drivers/pinctrl/pinctrl-palmas.c +2 -0
+	PALMAS_PINMUX_INVALID = 0xFFFF,
+	PALMAS_PINMUX_NA = PALMAS_PINMUX_INVALID,

I don't think you need to define two values for that; only one of them is used, right?

Quoted 1 line

+struct palmas_pins_pullup_dn_info {

...

Quoted 3 lines
drivers/pinctrl/pinctrl-palmas.c +2 -0
+struct palmas_pins_od_info {
 
+struct palmas_pingroup {

...

drivers/pinctrl/pinctrl-palmas.c line 446

Quoted 2 lines
drivers/pinctrl/pinctrl-palmas.c +2 -0
+	unsigned mux_reg_base;
+	unsigned mux_reg_add;

This isn't an issue with this patch, but more with the way palmas_read() works. Here, the MFD component is telling the MFD top-level object where the MFD component exists within the top-level address space. That's backwards. The top-level MFD is what know how the components are put together to create the whole particular chip, and it's entirely possible this could vary chip-to-chip. :-(

drivers/pinctrl/pinctrl-palmas.c line 665

Quoted 3 lines
drivers/pinctrl/pinctrl-palmas.c +2 -0
+static int palmas_pinctrl_set_dvfs1(struct palmas_pctrl_chip_info *pci,
 
+	val = (enable) ? PALMAS_PRIMARY_SECONDARY_PAD3_DVFS1 : 0;

No need for the ().

drivers/pinctrl/pinctrl-palmas.c line 733

Quoted 8 lines
drivers/pinctrl/pinctrl-palmas.c +7 -0
+static int palmas_pinctrl_dt_subnode_to_map(struct device *dev,
 
+	ret = of_property_read_string(np, "ti,function", &function);
+	if (ret < 0) {
+		/* EINVAL=missing, which is fine since it's optional */
+		if (ret != -EINVAL)
+			dev_err(dev,
+				"could not parse property nvidia,function\n");

nvidia? The same problem exists in other places.

I wonder if most/all of this function couldn't be factored out (just like your patch 1/2), by passing palams_cfg_params to the common function, and possibly adding callback functions to that array so the common code doesn't have to know how to interpret the parameters themselves, just how to interpret the top-level structure of parsing.

BTW, there's a typo in the name "palams_cfg_params".

Quoted 1 line

+static int palmas_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,

If the previous function can be shared, this can too.

drivers/pinctrl/pinctrl-palmas.c line 865

Quoted 6 lines
drivers/pinctrl/pinctrl-palmas.c +5 -0
+static int palmas_pinctrl_enable(struct pinctrl_dev *pctldev, unsigned function,
+		unsigned group)
 
+	if (g->mux_reg_base == PALMAS_NONE_BASE) {
+		if (WARN_ON(function != 0))
+			return -EINVAL;

What does "0" mean here? Perhaps s/0/GPIO/ ?

drivers/pinctrl/pinctrl-palmas.c line 872

Quoted 4 lines
drivers/pinctrl/pinctrl-palmas.c +4 -0
+	for (i = 0; i < ARRAY_SIZE(g->opt); i++) {
+		if (g->opt[i]->mux_opt == function)
+			break;
+	}

So, when I create the Tegra bindings, I created the list of mux functions by looking at the logical meaning of each register value (0..3) for each pin, and then made the list of functions have a value for each logical meaning. This requires a mapping table between the pinctrl subsystem's mux function values and the HW mux function values, which is what the loop above implements. Instead, if might be simpler to just have functions named "0", "1", "2", ... and have all pins support those functions. This simplifies the driver, and the DT bindings. Whether doing so would make the DT bindings better probably depends on exactly how the HW's documentation is written...

drivers/pinctrl/pinctrl-palmas.c line 898

Quoted 6 lines
drivers/pinctrl/pinctrl-palmas.c +6 -0
+static int palmas_pinconf_get(struct pinctrl_dev *pctldev,
+			unsigned pin, unsigned long *config)
+{
+	dev_err(pctldev->dev, "pin_config_get op not supported\n");
+	return -ENOTSUPP;
+}

Are the pin configuration values applied per pin in HW? If so, you should probably implement palmas_pinconf_get/set() rather than palmas_pinconf_group_get/set(). You'd also need to change the DT->map conversion function to use PIN_MAP_TYPE_CONFIGS_PIN rather than PIN_MAP_TYPE_CONFIGS_GROUP.

Quoted 4 lines
drivers/pinctrl/pinctrl-palmas.c +3 -0
+static int palmas_pinconf_group_get(struct pinctrl_dev *pctldev,
+				unsigned group, unsigned long *config)
 
+	if (param == PALMAS_PINCONF_PARAM_PULL) {

...

Quoted 4 lines
drivers/pinctrl/pinctrl-palmas.c +4 -0
+		valid_param = true;
+	}
+
+	if (param == PALMAS_PINCONF_PARAM_OPEN_DRAIN) {

...

drivers/pinctrl/pinctrl-palmas.c line 997

Quoted 5 lines
drivers/pinctrl/pinctrl-palmas.c +5 -0
+		valid_param = true;
+	}
+
+	if (!valid_param) {
+		dev_err(pci->dev, "Invalid Parameter\n");

Wouldn't that be simpler as a switch?

drivers/pinctrl/pinctrl-palmas.c line 1200

Quoted 5 lines
drivers/pinctrl/pinctrl-palmas.c +5 -0
+static int __init palmas_pinctrl_init(void)
+{
+	return platform_driver_register(&palmas_pinctrl_driver);
+}
+subsys_initcall(palmas_pinctrl_init);

I think that should be module_initcall(), ...

drivers/pinctrl/pinctrl-palmas.c line 1206

Quoted 6 lines
drivers/pinctrl/pinctrl-palmas.c +6 -0
+
+static void __exit palmas_pinctrl_exit(void)
+{
+	platform_driver_unregister(&palmas_pinctrl_driver);
+}
+module_exit(palmas_pinctrl_exit);

... If so, both those functions and macros could be replaced with:

module_platform_driver(palmas_pinctrl_driver);

#3 lore raw

Re: [PATCH 1/2] pinctrl: pinconf_generic: add utility functions for add map/configs

In reply to Stephen Warren
Quoted 7 lines · Stephen Warren
Quoted 2 lines · Laxman Dewangan

Some of pincontrol driver needs the utility function to create map list. The utility function needed for adding mux, configs etc.

Which other drivers already contain this code? Are you planning on converting them over to use these new functions? The code looks familiar, so I assume it's just cut/paste from Tegra with some renames, so I didn't read it through in detail.

Yes, these functions are taken from the pinctrl-tegra driver. Other drivers which have similar implementation are nomadik, tegra, abx500, tz1090, tz1090-pdc. So All can use these utility function to avoid duplication and reduce code size.
Yes, I have plan to use this in Tegra atleast but once this patch get accepted.

Quoted 7 lines
Quoted 3 lines
  drivers/pinctrl/pinconf-generic.c       |  105 +++++++++++++++++++++++++++++++
  include/linux/pinctrl/pinconf-generic.h |   52 +++++++++++++++

I don't think those are the correct files for this code. Presumably there's no reason at all why a pinctrl driver that doesn't require CONFIG_GENERIC_PINCONF can't use these basic utility functions. Perhaps add a new pinctrl-utils file?

I thought generic implementation of parsing of dt is pinctrl-generic file and as these newly added APIs are require for the parsing the DT node, I added here. I can move this to pinctrl-util.c/h also.

#9 lore raw
In reply to Mark Brown
Quoted 4 lines · Mark Brown

* PGP Signed by an unknown key

On Fri, Jul 26, 2013 at 03:45:54PM +0530, Laxman Dewangan wrote:

Quoted 9 lines

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 61

Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt new file +6 -0
+pins: gpio0_id, gpio1_vbus_det_led1_pwm1, gpio2_regen_led2_pwm2, gpio3_chrg_det,
+	gpio4_sysen1, gpio5_clk32kgaudio_usb_psel, gpio6_sysen2,
+	gpio7_msecure_pwrhold, gpio8_sim1rsti, gpio9_low_vbat,
+	gpio10_wireless_chrg1, gpio11_rcm, gpio12_sim2rsto, gpio13, gpio14,
+	gpio15_sim2rsti, vac, powergood_usb_psel, nreswarm, pwrdown,
+	gpadc_start, reset_in, nsleep, enable1, enable2, int.

Would it not be easier to just name the GPIOs gpioN rather than using the full names with the possible functions?

I took the name approach as what we have on Tegra.
But I think I can put the name of the pins same as what we have in datasheet. So pin name will be exact same as what we have in datasheet. That will be easy to interpret.

#12 lore raw
In reply to Stephen Warren

Hi Stephen,
Thanks for detail review.
Agree on most of review. Some info/answer on some of query.

Quoted 10 lines · Stephen Warren

(Also CC'ing in the DT bindings maintainers, hence quoting all of the binding.)

On 07/26/2013 04:15 AM, Laxman Dewangan wrote:

That field looks odd. From what I can tell in the code, the location of the pull-up/down/... registers/bits varies depending on which mux function is selected for a particular pin? That's a very strange HW design. Are you sure the set of pins/functions this driver exposes is the correct way to represent the HW?

Yes, the pull up/down register is different for different mux/function. It is not for pin specific.

Quoted 8 lines

drivers/pinctrl/pinctrl-palmas.c line 446

Quoted 2 lines
drivers/pinctrl/pinctrl-palmas.c new file +2 -0
+     unsigned mux_reg_base;
+     unsigned mux_reg_add;

This isn't an issue with this patch, but more with the way palmas_read() works. Here, the MFD component is telling the MFD top-level object where the MFD component exists within the top-level address space. That's backwards. The top-level MFD is what know how the components are put together to create the whole particular chip, and it's entirely possible this could vary chip-to-chip. :-(

I think this was original Idea when Graeme thought of the Palmas DT. But unfortunately this was not written.
The base address or the address space should be provided from the DT and the address of particular register should be in offset to that base. But not fully hardware support this neither the framework is written like this for the palmas.

Quoted 4 lines

drivers/pinctrl/pinctrl-palmas.c line 872

Quoted 4 lines
drivers/pinctrl/pinctrl-palmas.c new file +4 -0
+     for (i = 0; i < ARRAY_SIZE(g->opt); i++) {
+             if (g->opt[i]->mux_opt == function)
+                     break;
+     }
Quoted 10 lines

So, when I create the Tegra bindings, I created the list of mux functions by looking at the logical meaning of each register value (0..3) for each pin, and then made the list of functions have a value for each logical meaning. This requires a mapping table between the pinctrl subsystem's mux function values and the HW mux function values, which is what the loop above implements. Instead, if might be simpler to just have functions named "0", "1", "2", ... and have all pins support those functions. This simplifies the driver, and the DT bindings. Whether doing so would make the DT bindings better probably depends on exactly how the HW's documentation is written...

I am not sure I got it completely or not. Let me try out this and get reviewed by you.

Quoted 12 lines

drivers/pinctrl/pinctrl-palmas.c line 898

Quoted 7 lines
drivers/pinctrl/pinctrl-palmas.c new file +6 -0
+static int palmas_pinconf_get(struct pinctrl_dev *pctldev,
+                     unsigned pin, unsigned long *config)
+{
+     dev_err(pctldev->dev, "pin_config_get op not supported\n");
+     return -ENOTSUPP;
+}

Are the pin configuration values applied per pin in HW? If so, you should probably implement palmas_pinconf_get/set() rather than palmas_pinconf_group_get/set(). You'd also need to change the DT->map conversion function to use PIN_MAP_TYPE_CONFIGS_PIN rather than PIN_MAP_TYPE_CONFIGS_GROUP.

Yes, this is applied per pin in HW.

#10 lore raw
In reply to Laxman Dewangan
Quoted 11 lines · Laxman Dewangan
Quoted 4 lines · Mark Brown

Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt line 57

Quoted 1 line
Documentation/devicetree/bindings/pinctrl/pinctrl-palmas.txt new file +1 -0
+	gpio4_sysen1, gpio5_clk32kgaudio_usb_psel, gpio6_sysen2,

Would it not be easier to just name the GPIOs gpioN rather than using the full names with the possible functions?

I took the name approach as what we have on Tegra.
But I think I can put the name of the pins same as what we have in datasheet. So pin name will be exact same as what we have in datasheet. That will be easy to interpret.

I was thinking more about ease of typing than ease of understanding here!

#4 lore raw

Re: [PATCH 1/2] pinctrl: pinconf_generic: add utility functions for add map/configs

In reply to Laxman Dewangan
Quoted 27 lines · Laxman Dewangan
Quoted 7 lines · Stephen Warren
Quoted 2 lines · Laxman Dewangan

Some of pincontrol driver needs the utility function to create map list. The utility function needed for adding mux, configs etc.

Which other drivers already contain this code? Are you planning on converting them over to use these new functions? The code looks familiar, so I assume it's just cut/paste from Tegra with some renames, so I didn't read it through in detail.

Yes, these functions are taken from the pinctrl-tegra driver. Other drivers which have similar implementation are nomadik, tegra, abx500, tz1090, tz1090-pdc.
So All can use these utility function to avoid duplication and reduce code size.
Yes, I have plan to use this in Tegra atleast but once this patch get accepted.

Quoted 8 lines
Quoted 4 lines
  drivers/pinctrl/pinconf-generic.c       |  105
+++++++++++++++++++++++++++++++
  include/linux/pinctrl/pinconf-generic.h |   52 +++++++++++++++

I don't think those are the correct files for this code. Presumably there's no reason at all why a pinctrl driver that doesn't require CONFIG_GENERIC_PINCONF can't use these basic utility functions. Perhaps add a new pinctrl-utils file?

Quoted 4 lines

I thought generic implementation of parsing of dt is pinctrl-generic file and as these newly added APIs are require for the parsing the DT node, I added here.
I can move this to pinctrl-util.c/h also.

pinctrl-generic isn't about DT, it's about defining generic options for pin configuration rather than SoC-/driver-specific options for pin configuration. (pin configuration being e.g. pull-up/down, bias direction/strength, slew rate, etc.)

#13 lore raw
In reply to Laxman Dewangan
Quoted 26 lines · Laxman Dewangan

Hi Stephen,
Thanks for detail review.
Agree on most of review. Some info/answer on some of query.

Quoted 10 lines · Stephen Warren

(Also CC'ing in the DT bindings maintainers, hence quoting all of the binding.)

drivers/pinctrl/pinctrl-palmas.c line 872

Quoted 4 lines · Laxman Dewangan
drivers/pinctrl/pinctrl-palmas.c new file +4 -0
+     for (i = 0; i < ARRAY_SIZE(g->opt); i++) {
+             if (g->opt[i]->mux_opt == function)
+                     break;
+     }
Quoted 10 lines

So, when I create the Tegra bindings, I created the list of mux functions by looking at the logical meaning of each register value (0..3) for each pin, and then made the list of functions have a value for each logical meaning. This requires a mapping table between the pinctrl subsystem's mux function values and the HW mux function values, which is what the loop above implements. Instead, if might be simpler to just have functions named "0", "1", "2", ... and have all pins support those functions. This simplifies the driver, and the DT bindings. Whether doing so would make the DT bindings better probably depends on exactly how the HW's documentation is written...

Quoted 2 lines

I am not sure I got it completely or not. Let me try out this and get reviewed by you.

Just to provide some more details, let's say we have two pins A/B/C/D, each with mux options 0, 1, 2, 3, with the following meaning:

A 0=GPIO 1=SPI1 2=I2C1 3=xxx
B 0=GPIO 1=SPI1 2=I2C1 3=yyy
C 0=GPIO 1=SPI2 2=I2C2 3=yyy
D 0=GPIO 1=SPI2 2=I2C2 3=zzz

The four physical mux options are 0, 1, 2, 3. They will apply to any and all pins, irrespective of the meaning of those options. It may be reasonable to use 0/1/2/3 directly in the DT bindings as the mux options, since their meaning can be looked up in the SoC's data sheet.

The logical mux options are: GPIO, SPI1, SPI2, I2C1, I2C2, xxx, yyy, zzz. Those indicate which HW blocks are connected to the pins, i.e. the pins' logical use-cases. It may also be reaonsable to use those logical options in the DT rather than the physical options since it's more descriptive. However, the driver would need a table to map from the logical options to the physical options so that the register could be programmed. Equally, these logical options are slightly less a direct representation of HW.

Different people may prefer a different answer to the question of which of those two options to use. The structure of the SoC documentation may provide a hint; it would probably be best to use whichever option makes matching the DT to the documentation easiest.

#5 lore raw

Re: [PATCH 1/2] pinctrl: pinconf_generic: add utility functions for add map/configs

In reply to Stephen Warren
Quoted 3 lines · Stephen Warren
Quoted 2 lines · Laxman Dewangan

Some of pincontrol driver needs the utility function to create map list. The utility function needed for adding mux, configs etc.

It is a noble goal to unify this and thank you *very* much for taking it on.

Quoted 5 lines

Which other drivers already contain this code? Are you planning on converting them over to use these new functions? The code looks familiar, so I assume it's just cut/paste from Tegra with some renames, so I didn't read it through in detail.

Quoted 7 lines
Quoted 2 lines
 drivers/pinctrl/pinconf-generic.c       |  105 +++++++++++++++++++++++++++++++
 include/linux/pinctrl/pinconf-generic.h |   52 +++++++++++++++

I don't think those are the correct files for this code. Presumably there's no reason at all why a pinctrl driver that doesn't require CONFIG_GENERIC_PINCONF can't use these basic utility functions. Perhaps add a new pinctrl-utils file?

Agree with Stephen, we need to put this in a separate file, such at pinctrl-dt.c or just put it into core.c.

Yours,
Linus Walleij

#6 lore raw

Re: [PATCH 1/2] pinctrl: pinconf_generic: add utility functions for add map/configs

Quoted 6 lines · Linus Walleij
Quoted 3 lines · Stephen Warren
Quoted 2 lines · Laxman Dewangan

Some of pincontrol driver needs the utility function to create map list. The utility function needed for adding mux, configs etc.

It is a noble goal to unify this and thank you *very* much for taking it on.

Thanks Linus,
There is 3 patches of version 3 of same series, if it gets concluded/applied then I will have some more patches for removing duplicate code from individual driver.

Quoted 8 lines
Quoted 5 lines

I don't think those are the correct files for this code. Presumably there's no reason at all why a pinctrl driver that doesn't require CONFIG_GENERIC_PINCONF can't use these basic utility functions. Perhaps add a new pinctrl-utils file?

Agree with Stephen, we need to put this in a separate file, such at pinctrl-dt.c or just put it into core.c.

Version 3 address all these.
Thanks,,
Laxman