linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 0/2] Enable wifi on pandaboard
@ 2014-07-14 11:50 Stefan Assmann
  2014-07-14 11:50 ` [PATCH RFC 1/2] dts: regulator-clk32kg should always be enabled Stefan Assmann
  2014-07-14 11:50 ` [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working Stefan Assmann
  0 siblings, 2 replies; 13+ messages in thread
From: Stefan Assmann @ 2014-07-14 11:50 UTC (permalink / raw)
  To: linux-arm-kernel

On the pandaboard the wifi isn't recognized because clk32kg was never enabled.
The code to handle the clock got removed successively because it was not used.
For now I've reverted the respective commits although I'm not sure if this is
acceptable. If it needs to be converted to the clock API some pointers in the
right direction would be appreciated, as I'm not familiar with it.
Thanks!

Stefan Assmann (2):
  dts: regulator-clk32kg should always be enabled
  regulator: twl: Re-add clk32kg to get wifi working

 .../bindings/regulator/twl-regulator.txt           |  1 +
 arch/arm/boot/dts/twl6030.dtsi                     |  1 +
 drivers/regulator/twl-regulator.c                  | 23 ++++++++++++++++++++++
 3 files changed, 25 insertions(+)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 1/2] dts: regulator-clk32kg should always be enabled
  2014-07-14 11:50 [PATCH RFC 0/2] Enable wifi on pandaboard Stefan Assmann
@ 2014-07-14 11:50 ` Stefan Assmann
  2014-07-14 11:50 ` [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working Stefan Assmann
  1 sibling, 0 replies; 13+ messages in thread
From: Stefan Assmann @ 2014-07-14 11:50 UTC (permalink / raw)
  To: linux-arm-kernel

This clock needs to be turned on for the wifi to work properly.

Signed-off-by: Stefan Assmann <sassmann@kpanic.de>
---
 arch/arm/boot/dts/twl6030.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..e91e507 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -85,6 +85,7 @@
 
 	clk32kg: regulator-clk32kg {
 		compatible = "ti,twl6030-clk32kg";
+		regulator-always-on;
 	};
 
 	twl_usb_comparator: usb-comparator {
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-14 11:50 [PATCH RFC 0/2] Enable wifi on pandaboard Stefan Assmann
  2014-07-14 11:50 ` [PATCH RFC 1/2] dts: regulator-clk32kg should always be enabled Stefan Assmann
@ 2014-07-14 11:50 ` Stefan Assmann
  2014-07-14 12:00   ` Mark Brown
  1 sibling, 1 reply; 13+ messages in thread
From: Stefan Assmann @ 2014-07-14 11:50 UTC (permalink / raw)
  To: linux-arm-kernel

This partly reverts the following commits to get the wifi working on
the Pandaboard OMAP4430 ES2.2.

0e8e5c34cf1a8beaaf0a6a05c053592693bf8cb4 regulator: twl: Remove references to 32kHz clock from DT bindings
d1924519fe1dada0cfd9a228bf2ff1ea15840c84 regulator: twl: Remove TWL6030_FIXED_RESOURCE
029dd3cefa46ecdd879f9b4e2df3bdf4371cc22c regulator: twl: Remove another unused variable warning
e76ab829cc2d8b6350a3f01fffb208df4d7d8c1b regulator: twl: Remove references to the twl4030 regulator

Signed-off-by: Stefan Assmann <sassmann@kpanic.de>
---
 .../bindings/regulator/twl-regulator.txt           |  1 +
 drivers/regulator/twl-regulator.c                  | 23 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/Documentation/devicetree/bindings/regulator/twl-regulator.txt b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
index 75b0c16..e627860 100644
--- a/Documentation/devicetree/bindings/regulator/twl-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
@@ -15,6 +15,7 @@ For twl6030 regulators/LDOs
   - "ti,twl6030-vusb" for VUSB LDO
   - "ti,twl6030-v1v8" for V1V8 LDO
   - "ti,twl6030-v2v1" for V2V1 LDO
+  - "ti,twl6030-clk32kg" for CLK32KG RESOURCE
   - "ti,twl6030-vdd1" for VDD1 SMPS
   - "ti,twl6030-vdd2" for VDD2 SMPS
   - "ti,twl6030-vdd3" for VDD3 SMPS
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index fed28ab..c745d96 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -633,6 +633,13 @@ static struct regulator_ops twl6030fixed_ops = {
 	.get_status	= twl6030reg_get_status,
 };
 
+static struct regulator_ops twl6030_fixed_resource = {
+	.enable		= twl6030reg_enable,
+	.disable	= twl6030reg_disable,
+	.is_enabled	= twl6030reg_is_enabled,
+	.get_status	= twl6030reg_get_status,
+};
+
 /*
  * SMPS status and control
  */
@@ -948,6 +955,19 @@ static const struct twlreg_info TWLSMPS_INFO_##label = { \
 		}, \
 	}
 
+#define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
+static struct twlreg_info TWLRES_INFO_##label = { \
+	.base = offset, \
+	.desc = { \
+		.name = #label, \
+		.id = TWL6030_REG_##label, \
+		.ops = &twl6030_fixed_resource, \
+		.type = REGULATOR_VOLTAGE, \
+		.owner = THIS_MODULE, \
+		.enable_time = turnon_delay, \
+		}, \
+	}
+
 /*
  * We list regulators here if systems need some level of
  * software control over them after boot.
@@ -1001,6 +1021,7 @@ TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0);
 TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0);
 TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0);
 TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0);
+TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0);
 TWL6032_ADJUSTABLE_SMPS(SMPS3, 0x34);
 TWL6032_ADJUSTABLE_SMPS(SMPS4, 0x10);
 TWL6032_ADJUSTABLE_SMPS(VIO, 0x16);
@@ -1033,6 +1054,7 @@ static u8 twl_get_smps_mult(void)
 #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
 #define TWL6032_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6032, label)
 #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
+#define TWLRES_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLRES, label)
 #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
 
 static const struct of_device_id twl_of_match[] = {
@@ -1080,6 +1102,7 @@ static const struct of_device_id twl_of_match[] = {
 	TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB),
 	TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8),
 	TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1),
+	TWLRES_OF_MATCH("ti,twl6030-clk32kg", CLK32KG),
 	TWLSMPS_OF_MATCH("ti,twl6032-smps3", SMPS3),
 	TWLSMPS_OF_MATCH("ti,twl6032-smps4", SMPS4),
 	TWLSMPS_OF_MATCH("ti,twl6032-vio", VIO),
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-14 11:50 ` [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working Stefan Assmann
@ 2014-07-14 12:00   ` Mark Brown
  2014-07-14 12:05     ` Stefan Assmann
  0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2014-07-14 12:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jul 14, 2014 at 01:50:55PM +0200, Stefan Assmann wrote:
> This partly reverts the following commits to get the wifi working on
> the Pandaboard OMAP4430 ES2.2.

> 0e8e5c34cf1a8beaaf0a6a05c053592693bf8cb4 regulator: twl: Remove references to 32kHz clock from DT bindings
> d1924519fe1dada0cfd9a228bf2ff1ea15840c84 regulator: twl: Remove TWL6030_FIXED_RESOURCE
> 029dd3cefa46ecdd879f9b4e2df3bdf4371cc22c regulator: twl: Remove another unused variable warning
> e76ab829cc2d8b6350a3f01fffb208df4d7d8c1b regulator: twl: Remove references to the twl4030 regulator

No, you need to implement clocks using the clock API.  Please read the
changelogs for the above commits...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140714/9c610af0/attachment.sig>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-14 12:00   ` Mark Brown
@ 2014-07-14 12:05     ` Stefan Assmann
  2014-07-14 18:13       ` Mark Brown
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Assmann @ 2014-07-14 12:05 UTC (permalink / raw)
  To: linux-arm-kernel

On 14.07.2014 14:00, Mark Brown wrote:
> On Mon, Jul 14, 2014 at 01:50:55PM +0200, Stefan Assmann wrote:
>> This partly reverts the following commits to get the wifi working on
>> the Pandaboard OMAP4430 ES2.2.
>
>> 0e8e5c34cf1a8beaaf0a6a05c053592693bf8cb4 regulator: twl: Remove references to 32kHz clock from DT bindings
>> d1924519fe1dada0cfd9a228bf2ff1ea15840c84 regulator: twl: Remove TWL6030_FIXED_RESOURCE
>> 029dd3cefa46ecdd879f9b4e2df3bdf4371cc22c regulator: twl: Remove another unused variable warning
>> e76ab829cc2d8b6350a3f01fffb208df4d7d8c1b regulator: twl: Remove references to the twl4030 regulator
>
> No, you need to implement clocks using the clock API.  Please read the
> changelogs for the above commits...
>

Yes, that's what I expected. Got any pointers for me how to do this?
Never done that before, a little help would be appreciated.

   Stefan

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-14 12:05     ` Stefan Assmann
@ 2014-07-14 18:13       ` Mark Brown
  2014-07-15 12:59         ` Stefan Assmann
  0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2014-07-14 18:13 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jul 14, 2014 at 02:05:19PM +0200, Stefan Assmann wrote:
> On 14.07.2014 14:00, Mark Brown wrote:

> >No, you need to implement clocks using the clock API.  Please read the
> >changelogs for the above commits...

> Yes, that's what I expected. Got any pointers for me how to do this?
> Never done that before, a little help would be appreciated.

There should be plenty of examples in drivers/clk?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140714/5fda622a/attachment.sig>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-14 18:13       ` Mark Brown
@ 2014-07-15 12:59         ` Stefan Assmann
  2014-07-16 21:23           ` Mark Brown
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Assmann @ 2014-07-15 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

On 14.07.2014 20:13, Mark Brown wrote:
> On Mon, Jul 14, 2014 at 02:05:19PM +0200, Stefan Assmann wrote:
>> On 14.07.2014 14:00, Mark Brown wrote:
>
>>> No, you need to implement clocks using the clock API.  Please read the
>>> changelogs for the above commits...
>
>> Yes, that's what I expected. Got any pointers for me how to do this?
>> Never done that before, a little help would be appreciated.
>
> There should be plenty of examples in drivers/clk?

Looking at this more closely it seems to me that it's a regulator thing
after all. In the end it all boils down to a single register write.
twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0x41, 0x8e);
This is a write to the CLK32KG_CFG_STATE [1] register to power on the
device.

I tried moving that to omap4xxx_dt_clk_init() but that won't work
because the twl core structures aren't initialized yet.

Any suggestions?

   Stefan

[1] http://www.cjemicros.f2s.com/public/datasheets/TWL6030_Register_Map.pdf page 196

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-15 12:59         ` Stefan Assmann
@ 2014-07-16 21:23           ` Mark Brown
  2014-07-17  8:36             ` Stefan Assmann
  2014-07-24 15:03             ` Stefan Assmann
  0 siblings, 2 replies; 13+ messages in thread
From: Mark Brown @ 2014-07-16 21:23 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Jul 15, 2014 at 02:59:14PM +0200, Stefan Assmann wrote:

> Looking at this more closely it seems to me that it's a regulator thing
> after all. In the end it all boils down to a single register write.
> twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0x41, 0x8e);
> This is a write to the CLK32KG_CFG_STATE [1] register to power on the
> device.

The register description happening to mention power doesn't mean it's
not functionally an enable for a clock.

> I tried moving that to omap4xxx_dt_clk_init() but that won't work
> because the twl core structures aren't initialized yet.

> Any suggestions?

Why not just add this to (or create a new) clock driver for the chip?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140716/8e470177/attachment.sig>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-16 21:23           ` Mark Brown
@ 2014-07-17  8:36             ` Stefan Assmann
  2014-07-17  9:58               ` Mark Brown
  2014-07-24 15:03             ` Stefan Assmann
  1 sibling, 1 reply; 13+ messages in thread
From: Stefan Assmann @ 2014-07-17  8:36 UTC (permalink / raw)
  To: linux-arm-kernel

On 16.07.2014 23:23, Mark Brown wrote:
> On Tue, Jul 15, 2014 at 02:59:14PM +0200, Stefan Assmann wrote:
>
>> Looking at this more closely it seems to me that it's a regulator thing
>> after all. In the end it all boils down to a single register write.
>> twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0x41, 0x8e);
>> This is a write to the CLK32KG_CFG_STATE [1] register to power on the
>> device.
>
> The register description happening to mention power doesn't mean it's
> not functionally an enable for a clock.
>
>> I tried moving that to omap4xxx_dt_clk_init() but that won't work
>> because the twl core structures aren't initialized yet.
>
>> Any suggestions?
>
> Why not just add this to (or create a new) clock driver for the chip?
>

Problem is that twl_i2c_write_u8() calls twl_get_regmap() to get the
regmap. This requires struct twl_priv to be populated which does not
happen until twl_probe has run. That hasn't happened at the point when
omap4xxx_dt_clk_init() gets called.
Is there a way to defer a clock driver until twl_probe() has run?

   Stefan

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-17  8:36             ` Stefan Assmann
@ 2014-07-17  9:58               ` Mark Brown
  0 siblings, 0 replies; 13+ messages in thread
From: Mark Brown @ 2014-07-17  9:58 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Jul 17, 2014 at 10:36:48AM +0200, Stefan Assmann wrote:
> On 16.07.2014 23:23, Mark Brown wrote:

> >Why not just add this to (or create a new) clock driver for the chip?

> Problem is that twl_i2c_write_u8() calls twl_get_regmap() to get the
> regmap. This requires struct twl_priv to be populated which does not
> happen until twl_probe has run. That hasn't happened at the point when
> omap4xxx_dt_clk_init() gets called.
> Is there a way to defer a clock driver until twl_probe() has run?

Why would probe deferral not work the same way as it does for
everything, and what does the core SoC clocking have to do with this?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140717/26c50cd8/attachment.sig>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-16 21:23           ` Mark Brown
  2014-07-17  8:36             ` Stefan Assmann
@ 2014-07-24 15:03             ` Stefan Assmann
  2014-07-24 17:39               ` Mark Brown
  2014-07-29  1:27               ` Mike Turquette
  1 sibling, 2 replies; 13+ messages in thread
From: Stefan Assmann @ 2014-07-24 15:03 UTC (permalink / raw)
  To: linux-arm-kernel

On 16.07.2014 23:23, Mark Brown wrote:
> On Tue, Jul 15, 2014 at 02:59:14PM +0200, Stefan Assmann wrote:
>
>> Looking at this more closely it seems to me that it's a regulator thing
>> after all. In the end it all boils down to a single register write.
>> twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0x41, 0x8e);
>> This is a write to the CLK32KG_CFG_STATE [1] register to power on the
>> device.
>
> The register description happening to mention power doesn't mean it's
> not functionally an enable for a clock.
>
>> I tried moving that to omap4xxx_dt_clk_init() but that won't work
>> because the twl core structures aren't initialized yet.
>
>> Any suggestions?
>
> Why not just add this to (or create a new) clock driver for the chip?
>

OK, here's a first attempt to add a clock driver for the twl6030. Let
me know if this is going the right direction and I'll post a proper
patchset.
Thanks!

   Stefan

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 9f9c5ae..4e89e8b 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -65,6 +65,13 @@ config COMMON_CLK_S2MPS11
  	  clock. These multi-function devices have two (S2MPS14) or three
  	  (S2MPS11, S5M8767) fixed-rate oscillators, clocked at 32KHz each.

+config CLK_TWL6030
+	tristate "Clock driver for twl6030"
+	depends on TWL4030_CORE
+	---help---
+	  Enable the TWL6030 clock CLK32KG which is disabled by default.
+	  Needed on the Pandaboard for the wireless LAN.
+
  config CLK_TWL6040
  	tristate "External McPDM functional clock from twl6040"
  	depends on TWL6040_CORE
diff --git a/drivers/clk/ti/Makefile b/drivers/clk/ti/Makefile
index ed4d0aa..04f25ea 100644
--- a/drivers/clk/ti/Makefile
+++ b/drivers/clk/ti/Makefile
@@ -10,4 +10,5 @@ obj-$(CONFIG_SOC_OMAP5)			+= $(clk-common) clk-54xx.o
  obj-$(CONFIG_SOC_DRA7XX)		+= $(clk-common) clk-7xx.o \
  					   clk-dra7-atl.o
  obj-$(CONFIG_SOC_AM43XX)		+= $(clk-common) clk-43xx.o
+obj-$(CONFIG_CLK_TWL6030)		+= $(clk-common) clk-6030.o
  endif
diff --git a/drivers/clk/ti/clk-6030.c b/drivers/clk/ti/clk-6030.c
new file mode 100644
index 0000000..3eb0f1a
--- /dev/null
+++ b/drivers/clk/ti/clk-6030.c
@@ -0,0 +1,147 @@
+/*
+ * drivers/clk/ti/clk-6030.c
+ *
+ *  Copyright (C) 2014 Stefan Assmann <sassmann@kpanic.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Clock driver for ti twl6030.
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
+#include <linux/i2c/twl.h>
+#include <linux/platform_device.h>
+
+struct twl6030_desc {
+	struct clk *clk;
+	struct clk_hw hw;
+	bool enabled;
+};
+
+#define to_twl6030_desc(_hw) container_of(_hw, struct twl6030_desc, hw)
+
+static int twl6030_clk32kg_enable(struct clk_hw *hw)
+{
+	struct twl6030_desc *desc = to_twl6030_desc(hw);
+	int ret;
+
+	ret = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER,
+			       TWL6030_GRP_CON << TWL6030_CFG_STATE_GRP_SHIFT |
+			       TWL6030_CFG_STATE_ON,
+			       TWL6030_PM_RECEIVER_CLK32KG_CFG_STATE);
+	if (ret == 0)
+		desc->enabled = true;
+
+	return ret;
+}
+void twl6030_clk32kg_disable(struct clk_hw *hw)
+{
+	struct twl6030_desc *desc = to_twl6030_desc(hw);
+
+	twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER,
+			 TWL6030_GRP_CON << TWL6030_CFG_STATE_GRP_SHIFT |
+			 TWL6030_CFG_STATE_OFF,
+			 TWL6030_PM_RECEIVER_CLK32KG_CFG_STATE);
+	desc->enabled = false;
+}
+
+static int twl6030_clk32kg_is_enabled(struct clk_hw *hw)
+{
+	struct twl6030_desc *desc = to_twl6030_desc(hw);
+
+	return desc->enabled;
+}
+
+static const struct clk_ops twl6030_clk32kg_ops = {
+	.enable		= twl6030_clk32kg_enable,
+	.disable	= twl6030_clk32kg_disable,
+	.is_enabled	= twl6030_clk32kg_is_enabled,
+};
+
+static void __init of_ti_twl6030_clk32kg_setup(struct device_node *node)
+{
+	struct twl6030_desc *clk_hw = NULL;
+	struct clk_init_data init = { 0 };
+	struct clk_lookup *clookup;
+	struct clk *clk;
+
+	clookup = kzalloc(sizeof(*clookup), GFP_KERNEL);
+	if (!clookup) {
+		pr_err("%s: could not allocate clookup\n", __func__);
+		return;
+	}
+	clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
+	if (!clk_hw) {
+		pr_err("%s: could not allocate clk_hw\n", __func__);
+		goto err_clk_hw;
+	}
+
+	clk_hw->hw.init = &init;
+
+	init.name = node->name;
+	init.ops = &twl6030_clk32kg_ops;
+	init.flags = CLK_IS_ROOT;
+
+	clk = clk_register(NULL, &clk_hw->hw);
+	if (!IS_ERR(clk)) {
+		clookup->con_id = kstrdup("clk32kg", GFP_KERNEL);
+		clookup->clk = clk;
+		clkdev_add(clookup);
+
+		return;
+	}
+
+	kfree(clookup);
+err_clk_hw:
+	kfree(clk_hw);
+}
+CLK_OF_DECLARE(of_ti_twl6030_clk32kg, "ti,twl6030-clk32kg", of_ti_twl6030_clk32kg_setup);
+
+static int of_twl6030_clk32kg_probe(struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+	struct clk *clk;
+	int ret = 0;
+
+	if (!node)
+		return -ENODEV;
+
+	clk = clk_get(&pdev->dev, "clk32kg");
+	if (IS_ERR(clk))
+		ret = -EPROBE_DEFER;
+	else
+		clk_prepare_enable(clk);
+
+	return ret;
+}
+
+static int of_twl6030_clk32kg_remove(struct platform_device *pdev)
+{
+	return 0;
+}
+
+static struct of_device_id of_twl6030_clk32kg_match_tbl[] = {
+	{ .compatible = "ti,twl6030-clk32kg", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, of_twl6030_clk32kg_match_tbl);
+
+static struct platform_driver dra7_atl_clk_driver = {
+	.driver = {
+		.name = "twl6030-clk32kg",
+		.owner = THIS_MODULE,
+		.of_match_table = of_twl6030_clk32kg_match_tbl,
+	},
+	.probe = of_twl6030_clk32kg_probe,
+	.remove = of_twl6030_clk32kg_remove,
+};
+module_platform_driver(dra7_atl_clk_driver);
+
+MODULE_AUTHOR("Stefan Assmann <sassmann@kpanic.de>");
+MODULE_DESCRIPTION("clock driver for TI SoC based boards with twl6030");
+MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index db11b4f..fd332d6 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -34,6 +34,7 @@
  #include <linux/platform_device.h>
  #include <linux/regmap.h>
  #include <linux/clk.h>
+#include <linux/clk-provider.h>
  #include <linux/err.h>
  #include <linux/device.h>
  #include <linux/of.h>
@@ -459,9 +460,15 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
  	if (!regmap)
  		return -EPERM;

-	ret = regmap_bulk_write(regmap, twl_priv->twl_map[mod_no].base + reg,
-				value, num_bytes);
-
+	if (num_bytes == 1) {
+		ret = regmap_write(regmap,
+				   twl_priv->twl_map[mod_no].base + reg,
+				   *value);
+	} else {
+		ret = regmap_bulk_write(regmap,
+					twl_priv->twl_map[mod_no].base + reg,
+					value, num_bytes);
+	}
  	if (ret)
  		pr_err("%s: Write failed (mod %d, reg 0x%02x count %d)\n",
  		       DRIVER_NAME, mod_no, reg, num_bytes);
@@ -482,14 +489,22 @@ EXPORT_SYMBOL(twl_i2c_write);
  int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
  {
  	struct regmap *regmap = twl_get_regmap(mod_no);
+	unsigned int val;
  	int ret;

  	if (!regmap)
  		return -EPERM;

-	ret = regmap_bulk_read(regmap, twl_priv->twl_map[mod_no].base + reg,
-			       value, num_bytes);
-
+	if (num_bytes == 1) {
+		ret = regmap_read(regmap,
+				  twl_priv->twl_map[mod_no].base + reg,
+				  &val);
+		*value = val;
+	} else {
+		ret = regmap_bulk_read(regmap,
+				       twl_priv->twl_map[mod_no].base + reg,
+				       value, num_bytes);
+	}
  	if (ret)
  		pr_err("%s: Read failed (mod %d, reg 0x%02x count %d)\n",
  		       DRIVER_NAME, mod_no, reg, num_bytes);
@@ -1012,6 +1027,8 @@ static void clocks_init(struct device *dev,
  	u32 rate;
  	u8 ctrl = HFCLK_FREQ_26_MHZ;

+	of_clk_init(NULL);
+
  	osc = clk_get(dev, "fck");
  	if (IS_ERR(osc)) {
  		printk(KERN_WARNING "Skipping twl internal clock init and "
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index fed28ab..ad0dd22 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -94,17 +94,6 @@ struct twlreg_info {
  #define VREG_BC_PROC		3
  #define VREG_BC_CLK_RST		4

-/* TWL6030 LDO register values for CFG_STATE */
-#define TWL6030_CFG_STATE_OFF	0x00
-#define TWL6030_CFG_STATE_ON	0x01
-#define TWL6030_CFG_STATE_OFF2	0x02
-#define TWL6030_CFG_STATE_SLEEP	0x03
-#define TWL6030_CFG_STATE_GRP_SHIFT	5
-#define TWL6030_CFG_STATE_APP_SHIFT	2
-#define TWL6030_CFG_STATE_APP_MASK	(0x03 << TWL6030_CFG_STATE_APP_SHIFT)
-#define TWL6030_CFG_STATE_APP(v)	(((v) & TWL6030_CFG_STATE_APP_MASK) >>\
-						TWL6030_CFG_STATE_APP_SHIFT)
-
  /* Flags for SMPS Voltage reading */
  #define SMPS_OFFSET_EN		BIT(0)
  #define SMPS_EXTENDED_EN	BIT(1)
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 8cfb50f..8ad63a2 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -127,6 +127,20 @@ enum twl6030_module_ids {
  #define REG_INT_MSK_STS_B		0x07
  #define REG_INT_MSK_STS_C		0x08

+/* TWL6030 register values for CFG_STATE */
+#define TWL6030_GRP_APP			(1 << 0)
+#define TWL6030_GRP_CON			(1 << 1)
+#define TWL6030_GRP_MOD			(1 << 2)
+#define TWL6030_CFG_STATE_OFF		0x00
+#define TWL6030_CFG_STATE_ON		0x01
+#define TWL6030_CFG_STATE_OFF2		0x02
+#define TWL6030_CFG_STATE_SLEEP		0x03
+#define TWL6030_CFG_STATE_GRP_SHIFT	5
+#define TWL6030_CFG_STATE_APP_SHIFT	2
+#define TWL6030_CFG_STATE_APP_MASK	(0x03 << TWL6030_CFG_STATE_APP_SHIFT)
+#define TWL6030_CFG_STATE_APP(v)	(((v) & TWL6030_CFG_STATE_APP_MASK) >>\
+						TWL6030_CFG_STATE_APP_SHIFT)
+
  /* MASK INT REG GROUP A */
  #define TWL6030_PWR_INT_MASK 		0x07
  #define TWL6030_RTC_INT_MASK 		0x18
@@ -470,6 +484,12 @@ static inline int twl6030_mmc_card_detect(struct device *dev, int slot)

  #define TWL4030_PM_MASTER_GLOBAL_TST		0xb6

+/*
+ * PM Receiver module register offsets (use TWL_MODULE_PM_RECEIVER)
+ */
+
+#define TWL6030_PM_RECEIVER_CLK32KG_CFG_STATE	0x8e
+
  /*----------------------------------------------------------------------*/

  /* Power bus message definitions */
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-24 15:03             ` Stefan Assmann
@ 2014-07-24 17:39               ` Mark Brown
  2014-07-29  1:27               ` Mike Turquette
  1 sibling, 0 replies; 13+ messages in thread
From: Mark Brown @ 2014-07-24 17:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Jul 24, 2014 at 05:03:32PM +0200, Stefan Assmann wrote:

> OK, here's a first attempt to add a clock driver for the twl6030. Let
> me know if this is going the right direction and I'll post a proper
> patchset.

Looks reasonable to me, though I'm not a clock expert.  Few comments...

> +static int of_twl6030_clk32kg_remove(struct platform_device *pdev)
> +{
> +	return 0;
> +}

Shouldn't need empty functions.

> -	ret = regmap_bulk_write(regmap, twl_priv->twl_map[mod_no].base + reg,
> -				value, num_bytes);
> -
> +	if (num_bytes == 1) {
> +		ret = regmap_write(regmap,
> +				   twl_priv->twl_map[mod_no].base + reg,
> +				   *value);
> +	} else {
> +		ret = regmap_bulk_write(regmap,
> +					twl_priv->twl_map[mod_no].base + reg,
> +					value, num_bytes);
> +	}

Just always use regmap_raw_write() - for single byte values there is no
difference anyway, bulk_write() only makes a difference if the values
are multi-byte.

> -	ret = regmap_bulk_read(regmap, twl_priv->twl_map[mod_no].base + reg,
> -			       value, num_bytes);
> -
> +	if (num_bytes == 1) {

Similarly here.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140724/628077f5/attachment.sig>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working
  2014-07-24 15:03             ` Stefan Assmann
  2014-07-24 17:39               ` Mark Brown
@ 2014-07-29  1:27               ` Mike Turquette
  1 sibling, 0 replies; 13+ messages in thread
From: Mike Turquette @ 2014-07-29  1:27 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Stefan Assmann (2014-07-24 08:03:32)
> +#define to_twl6030_desc(_hw) container_of(_hw, struct twl6030_desc, hw)
> +
> +static int twl6030_clk32kg_enable(struct clk_hw *hw)
> +{
> +       struct twl6030_desc *desc = to_twl6030_desc(hw);
> +       int ret;
> +
> +       ret = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER,
> +                              TWL6030_GRP_CON << TWL6030_CFG_STATE_GRP_SHIFT |
> +                              TWL6030_CFG_STATE_ON,
> +                              TWL6030_PM_RECEIVER_CLK32KG_CFG_STATE);
> +       if (ret == 0)
> +               desc->enabled = true;
> +
> +       return ret;
> +}
> +void twl6030_clk32kg_disable(struct clk_hw *hw)
> +{
> +       struct twl6030_desc *desc = to_twl6030_desc(hw);
> +
> +       twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER,
> +                        TWL6030_GRP_CON << TWL6030_CFG_STATE_GRP_SHIFT |
> +                        TWL6030_CFG_STATE_OFF,
> +                        TWL6030_PM_RECEIVER_CLK32KG_CFG_STATE);
> +       desc->enabled = false;
> +}
> +
> +static int twl6030_clk32kg_is_enabled(struct clk_hw *hw)
> +{
> +       struct twl6030_desc *desc = to_twl6030_desc(hw);
> +
> +       return desc->enabled;
> +}
> +
> +static const struct clk_ops twl6030_clk32kg_ops = {
> +       .enable         = twl6030_clk32kg_enable,
> +       .disable        = twl6030_clk32kg_disable,
> +       .is_enabled     = twl6030_clk32kg_is_enabled,
> +};

All three above need to be converted from {en|dis}able to {un}prepare.
The reason is that clk_enable/clk_disable must not sleep and of course
i2c transactions might do just that.

Please Cc me on the next version :-)

Regards,
Mike

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-07-29  1:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-14 11:50 [PATCH RFC 0/2] Enable wifi on pandaboard Stefan Assmann
2014-07-14 11:50 ` [PATCH RFC 1/2] dts: regulator-clk32kg should always be enabled Stefan Assmann
2014-07-14 11:50 ` [PATCH RFC 2/2] regulator: twl: Re-add clk32kg to get wifi working Stefan Assmann
2014-07-14 12:00   ` Mark Brown
2014-07-14 12:05     ` Stefan Assmann
2014-07-14 18:13       ` Mark Brown
2014-07-15 12:59         ` Stefan Assmann
2014-07-16 21:23           ` Mark Brown
2014-07-17  8:36             ` Stefan Assmann
2014-07-17  9:58               ` Mark Brown
2014-07-24 15:03             ` Stefan Assmann
2014-07-24 17:39               ` Mark Brown
2014-07-29  1:27               ` Mike Turquette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).