linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* AT91SAM9260: How to output PCK0 clock on a GPIO pin
@ 2009-08-31 15:32 Pedro I. Sanchez
  2009-08-31 16:58 ` Stephen Munnings
  0 siblings, 1 reply; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 15:32 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

I'm trying to get a clock on pin PC6 of my AT1SAM9260-based board and I
would like some advice on how to do it. For all purposes this board can be
considered to be a clone of the sam9260ek evaluation board.

I see doing this as a two-step process: First, link pin PC6 to the PCK0
clock. Second, program and enable the clock. My kernel module has the
following code (I'm using kernel 2.26.29.3):

Step 1:

at91_set_A_periph(AT91_PIN_PC6, 0);

I'm taking this piece of code from somewhere else. is this all I need to do
for step 1?


Step 2:

pck0 = clk_get(NULL, "pck0");
if (IS_ERR(pck0)) {
pr_err("%s: Failed to get PCK0\n", __func__);
ret = PTR_ERR(pck0);
goto err;
}
pllb = clk_get(NULL, "pllb");
if (IS_ERR(pllb)) {
pr_err("%s: Failed to get PLLB\n", __func__);
ret = PTR_ERR(pllb);
goto err_pllb;
}
ret = clk_set_parent(pck0, pllb);
if (ret != 0) {
pr_err("%s: Failed to set PCK0 parent\n", __func__);
goto err_parent;
}
clk_set_rate(pck0, 11289600);
clk_enable(pck0);
clk_put(pllb);


Neither step fails. Step 2 gives me a printout "PCK0 rate 6000000Hz" which
is not what I expected, some clock divisor must be in the way, but at least
it is a clock of some kind. Unfortunately nothing is output on pin PC6.

Could you provide me with some advice on how to do this properly?

Thank you,

-- 
Pedro



-- 
Pedro I. Sanchez

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 15:32 AT91SAM9260: How to output PCK0 clock on a GPIO pin Pedro I. Sanchez
@ 2009-08-31 16:58 ` Stephen Munnings
  2009-08-31 18:27   ` Pedro I. Sanchez
  0 siblings, 1 reply; 17+ messages in thread
From: Stephen Munnings @ 2009-08-31 16:58 UTC (permalink / raw)
  To: linux-arm-kernel

Pedro I. Sanchez wrote:
> Hello,
>
> I'm trying to get a clock on pin PC6 of my AT1SAM9260-based board and I
> would like some advice on how to do it. For all purposes this board can be
> considered to be a clone of the sam9260ek evaluation board.
>
> I see doing this as a two-step process: First, link pin PC6 to the PCK0
> clock. Second, program and enable the clock. My kernel module has the
> following code (I'm using kernel 2.26.29.3):
>
> Step 1:
>
> at91_set_A_periph(AT91_PIN_PC6, 0);
>
> I'm taking this piece of code from somewhere else. is this all I need to do
> for step 1?
>
>
> Step 2:
>
> pck0 = clk_get(NULL, "pck0");
> if (IS_ERR(pck0)) {
> pr_err("%s: Failed to get PCK0\n", __func__);
> ret = PTR_ERR(pck0);
> goto err;
> }
> pllb = clk_get(NULL, "pllb");
> if (IS_ERR(pllb)) {
> pr_err("%s: Failed to get PLLB\n", __func__);
> ret = PTR_ERR(pllb);
> goto err_pllb;
> }
> ret = clk_set_parent(pck0, pllb);
> if (ret != 0) {
> pr_err("%s: Failed to set PCK0 parent\n", __func__);
> goto err_parent;
> }
> clk_set_rate(pck0, 11289600);
> clk_enable(pck0);
> clk_put(pllb);
>
>
> Neither step fails. Step 2 gives me a printout "PCK0 rate 6000000Hz" which
> is not what I expected, some clock divisor must be in the way, but at least
> it is a clock of some kind. Unfortunately nothing is output on pin PC6.
>
> Could you provide me with some advice on how to do this properly?
>
> Thank you,
>
>   
Here is the code I use to get PC1 to be 50Mhz (from PLLA which is 
running at 800Mhz - this is actually on a 9G20, not a 9620)

    pck0 = clk_get(NULL, "pck0");
    plla = clk_get(NULL, "plla");

    at91_set_B_periph(AT91_PIN_PC1, 0);    /* PCK0 */

    clk_set_parent(pck0, plla);
    clk_set_rate(pck0, 50000000);
    clk_enable(pck0);

There are some differences (I use PC1, not PC6; I use PLLA, not PLLB, etc.,)

I am not sure what the "clk_put(pllb)" does for you.  I certainly did 
not need something like that. (PLLA was already running just fine)

But, I also found that you must have the PMC clock for the GPIOC bank 
running before GPIO (even the configuration, it seems) will work.
I am not sure if I had this issue in Linux, or only in the loaders, but 
I did have to turn on the PMC clocks to get any GPIO based things working.
The standard boot loader only seems to turn on GPIOA, but I am also 
using GPIOB and GPIOC, and I had to turn on the PMC clocks for those
also before I could get very far.

Stephen Munnings

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 16:58 ` Stephen Munnings
@ 2009-08-31 18:27   ` Pedro I. Sanchez
  2009-08-31 18:44     ` Stephen Munnings
  2009-08-31 19:33     ` Sergey Matyukevich
  0 siblings, 2 replies; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 18:27 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 31 Aug 2009 12:58:30 -0400, Stephen Munnings
<smunnings@gabaedevelopment.com> wrote:
> Pedro I. Sanchez wrote:
>> Hello,
>>
>> I'm trying to get a clock on pin PC6 of my AT1SAM9260-based board and I
>> would like some advice on how to do it. For all purposes this board can
>> be
>> considered to be a clone of the sam9260ek evaluation board.
>>
>> I see doing this as a two-step process: First, link pin PC6 to the PCK0
>> clock. Second, program and enable the clock. My kernel module has the
>> following code (I'm using kernel 2.26.29.3):
>>
>> Step 1:
>>
>> at91_set_A_periph(AT91_PIN_PC6, 0);
>>
>> I'm taking this piece of code from somewhere else. is this all I need to
>> do
>> for step 1?
>>
>>
>> Step 2:
>>
>> pck0 = clk_get(NULL, "pck0");
>> if (IS_ERR(pck0)) {
>> pr_err("%s: Failed to get PCK0\n", __func__);
>> ret = PTR_ERR(pck0);
>> goto err;
>> }
>> pllb = clk_get(NULL, "pllb");
>> if (IS_ERR(pllb)) {
>> pr_err("%s: Failed to get PLLB\n", __func__);
>> ret = PTR_ERR(pllb);
>> goto err_pllb;
>> }
>> ret = clk_set_parent(pck0, pllb);
>> if (ret != 0) {
>> pr_err("%s: Failed to set PCK0 parent\n", __func__);
>> goto err_parent;
>> }
>> clk_set_rate(pck0, 11289600);
>> clk_enable(pck0);
>> clk_put(pllb);
>>
>>
>> Neither step fails. Step 2 gives me a printout "PCK0 rate 6000000Hz"
>> which
>> is not what I expected, some clock divisor must be in the way, but at
>> least
>> it is a clock of some kind. Unfortunately nothing is output on pin PC6.
>>
>> Could you provide me with some advice on how to do this properly?
>>
>> Thank you,
>>
>>   
> Here is the code I use to get PC1 to be 50Mhz (from PLLA which is 
> running at 800Mhz - this is actually on a 9G20, not a 9620)
> 
>     pck0 = clk_get(NULL, "pck0");
>     plla = clk_get(NULL, "plla");
> 
>     at91_set_B_periph(AT91_PIN_PC1, 0);    /* PCK0 */
> 
>     clk_set_parent(pck0, plla);
>     clk_set_rate(pck0, 50000000);
>     clk_enable(pck0);
> 
> There are some differences (I use PC1, not PC6; I use PLLA, not PLLB,
> etc.,)
> 
> I am not sure what the "clk_put(pllb)" does for you.  I certainly did 
> not need something like that. (PLLA was already running just fine)
> 
> But, I also found that you must have the PMC clock for the GPIOC bank 
> running before GPIO (even the configuration, it seems) will work.
> I am not sure if I had this issue in Linux, or only in the loaders, but 
> I did have to turn on the PMC clocks to get any GPIO based things
working.
> The standard boot loader only seems to turn on GPIOA, but I am also 
> using GPIOB and GPIOC, and I had to turn on the PMC clocks for those
> also before I could get very far.
> 
> Stephen Munnings

Thanks Stephen,

And how do I turn on the PMC clocks for the GPIO?

-- 
Pedro I. Sanchez

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 18:27   ` Pedro I. Sanchez
@ 2009-08-31 18:44     ` Stephen Munnings
  2009-08-31 19:02       ` Pedro I. Sanchez
  2009-08-31 19:33     ` Sergey Matyukevich
  1 sibling, 1 reply; 17+ messages in thread
From: Stephen Munnings @ 2009-08-31 18:44 UTC (permalink / raw)
  To: linux-arm-kernel

Pedro I. Sanchez wrote:
>> But, I also found that you must have the PMC clock for the GPIOC bank 
>> running before GPIO (even the configuration, it seems) will work.
>> I am not sure if I had this issue in Linux, or only in the loaders, but 
>> I did have to turn on the PMC clocks to get any GPIO based things working.
>>     
>> The standard boot loader only seems to turn on GPIOA, but I am also 
>> using GPIOB and GPIOC, and I had to turn on the PMC clocks for those
>> also before I could get very far.
>>
>> Stephen Munnings
>>     
>
> Thanks Stephen,
>
> And how do I turn on the PMC clocks for the GPIO?
>
>   
I did some more searching, and it appears that Linux for at91 turns on 
all the GPIO PMC clocks as part
of its initialization.  So, the problem appears to not be the PMC clocks.
(It does it in /arch/arm/mach-at91/gpio.c in function at91_gpio_init() )

I do presume that you have the appropriate support configured into your 
kernel when you compiled it.

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 18:44     ` Stephen Munnings
@ 2009-08-31 19:02       ` Pedro I. Sanchez
  2009-08-31 19:13         ` Stephen Munnings
  0 siblings, 1 reply; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 19:02 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 31 Aug 2009 14:44:19 -0400, Stephen Munnings
<smunnings@gabaedevelopment.com> wrote:
> Pedro I. Sanchez wrote:
>>> But, I also found that you must have the PMC clock for the GPIOC bank 
>>> running before GPIO (even the configuration, it seems) will work.
>>> I am not sure if I had this issue in Linux, or only in the loaders, but

>>> I did have to turn on the PMC clocks to get any GPIO based things
>>> working.
>>>     
>>> The standard boot loader only seems to turn on GPIOA, but I am also 
>>> using GPIOB and GPIOC, and I had to turn on the PMC clocks for those
>>> also before I could get very far.
>>>
>>> Stephen Munnings
>>>     
>>
>> Thanks Stephen,
>>
>> And how do I turn on the PMC clocks for the GPIO?
>>
>>   
> I did some more searching, and it appears that Linux for at91 turns on 
> all the GPIO PMC clocks as part
> of its initialization.  So, the problem appears to not be the PMC clocks.
> (It does it in /arch/arm/mach-at91/gpio.c in function at91_gpio_init() )
> 
> I do presume that you have the appropriate support configured into your 
> kernel when you compiled it.

$ grep -i clocks .config
CONFIG_AT91_PROGRAMMABLE_CLOCKS=y

$ grep -i gpio .config
CONFIG_GENERIC_GPIO=y
# CONFIG_MTD_NAND_GPIO is not set
CONFIG_I2C_GPIO=m
CONFIG_SPI_GPIO=m
CONFIG_ARCH_REQUIRE_GPIOLIB=y
CONFIG_GPIOLIB=y
CONFIG_GPIO_SYSFS=y
# Memory mapped GPIO expanders:
# I2C GPIO expanders:
CONFIG_GPIO_MAX732X=m
CONFIG_GPIO_PCA953X=m
CONFIG_GPIO_PCF857X=m
# PCI GPIO expanders:
# SPI GPIO expanders:
CONFIG_GPIO_MAX7301=m
CONFIG_GPIO_MCP23S08=m
# CONFIG_HTC_EGPIO is not set
CONFIG_LEDS_GPIO=y

I presume I don't need any to modprobe any of these available gpio modules.
Certainly the gpio user space interface via /sys/class/gpio works well.

Any other suggestions?

Thanks,

-- 
Pedro

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 19:02       ` Pedro I. Sanchez
@ 2009-08-31 19:13         ` Stephen Munnings
  2009-08-31 19:21           ` Pedro I. Sanchez
  0 siblings, 1 reply; 17+ messages in thread
From: Stephen Munnings @ 2009-08-31 19:13 UTC (permalink / raw)
  To: linux-arm-kernel

Pedro I. Sanchez wrote:
> I presume I don't need any to modprobe any of these available gpio modules.
> Certainly the gpio user space interface via /sys/class/gpio works well.
>
> Any other suggestions?
>
> Thanks,
>
>   

No, sorry.
I have run out of suggestions that I can make remotely.
This is when I haul out the debugger, or otherwise start digging deep 
into what is not working here.
Can't really do that for you, sorry.    :)

Good Luck

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 19:13         ` Stephen Munnings
@ 2009-08-31 19:21           ` Pedro I. Sanchez
  0 siblings, 0 replies; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 19:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 31 Aug 2009 15:13:01 -0400, Stephen Munnings
<smunnings@gabaedevelopment.com> wrote:
> Pedro I. Sanchez wrote:
>> I presume I don't need any to modprobe any of these available gpio
>> modules.
>> Certainly the gpio user space interface via /sys/class/gpio works well.
>>
>> Any other suggestions?
>>
>> Thanks,
>>
>>   
> 
> No, sorry.
> I have run out of suggestions that I can make remotely.
> This is when I haul out the debugger, or otherwise start digging deep 
> into what is not working here.
> Can't really do that for you, sorry.    :)
> 
> Good Luck
> 

Thanks anyway. I'll post my results if I ever get this going.

-- 
Pedro

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 18:27   ` Pedro I. Sanchez
  2009-08-31 18:44     ` Stephen Munnings
@ 2009-08-31 19:33     ` Sergey Matyukevich
  2009-08-31 19:58       ` Stephen Munnings
  2009-08-31 20:03       ` Pedro I. Sanchez
  1 sibling, 2 replies; 17+ messages in thread
From: Sergey Matyukevich @ 2009-08-31 19:33 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,
 
> And how do I turn on the PMC clocks for the GPIO?

Assigning gpio pin PC6 to TIOB2 peripheral is only a part of the work.
Timer counters may operate in different modes. Take a look at
the datasheet for at91sam9260, timer counters are covered in chapter 34. 
It looks like 'waveform mode' is what you need (see 34.5.10, 34.5.11).
Before you get desired output on PC6 pin you will have to turn on
waveform operating mode for TIOB2 and to configure its wave shapes.
 
Thanks,
Sergey

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 19:33     ` Sergey Matyukevich
@ 2009-08-31 19:58       ` Stephen Munnings
  2009-08-31 20:37         ` Pedro I. Sanchez
  2009-08-31 20:03       ` Pedro I. Sanchez
  1 sibling, 1 reply; 17+ messages in thread
From: Stephen Munnings @ 2009-08-31 19:58 UTC (permalink / raw)
  To: linux-arm-kernel

Sergey Matyukevich wrote:
> Hi,
>  
>   
>> And how do I turn on the PMC clocks for the GPIO?
>>     
>
> Assigning gpio pin PC6 to TIOB2 peripheral is only a part of the work.
> Timer counters may operate in different modes. Take a look at
> the datasheet for at91sam9260, timer counters are covered in chapter 34. 
> It looks like 'waveform mode' is what you need (see 34.5.10, 34.5.11).
> Before you get desired output on PC6 pin you will have to turn on
> waveform operating mode for TIOB2 and to configure its wave shapes.
>  
> Thanks,
> Sergey
>   
hmmmm....

PCK0 is *not*  a TC pin - it is a clock output from the Power Management 
Controller.
(Section 25.6)
It should be as easy as dividing down one of the primary clock sources 
and then enabling
the appropriate GPIO pin as the appropriate peripheral.

Ahah - there is the problem.....  PCK0 is not available on PC6 - it must 
be set as peripheral B
on pin PC1 or PB30 as Peripheral A - no other choices available...

PC6 is indeed TIOB2 (one of the counter timers)

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 19:33     ` Sergey Matyukevich
  2009-08-31 19:58       ` Stephen Munnings
@ 2009-08-31 20:03       ` Pedro I. Sanchez
  2009-08-31 20:33         ` Ryan Mallon
  2009-08-31 20:35         ` Sergey Matyukevich
  1 sibling, 2 replies; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 20:03 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 31 Aug 2009 23:33:12 +0400, Sergey Matyukevich <geomatsi@gmail.com>
wrote:
> Hi,
>  
>> And how do I turn on the PMC clocks for the GPIO?
> 
> Assigning gpio pin PC6 to TIOB2 peripheral is only a part of the work.
> Timer counters may operate in different modes. Take a look at
> the datasheet for at91sam9260, timer counters are covered in chapter 34. 
> It looks like 'waveform mode' is what you need (see 34.5.10, 34.5.11).
> Before you get desired output on PC6 pin you will have to turn on
> waveform operating mode for TIOB2 and to configure its wave shapes.
>  
> Thanks,
> Sergey

Thanks Sergey,

So are the following statements correct?

1. The pck0 clock I've been playing with has nothing to do with the clock I
want on PC6 (TIOB2).

2. I have to use instead the "tc2_clk" as defined in
arch/arm/mach-at-91/at91sam9260.c.

3. I have to access the TC_CMR register directly to set things up. I mean,
there are no macros already defined to access these structures.


Thanks,

-- 
Pedro

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 20:03       ` Pedro I. Sanchez
@ 2009-08-31 20:33         ` Ryan Mallon
  2009-08-31 20:46           ` Pedro I. Sanchez
  2009-08-31 20:35         ` Sergey Matyukevich
  1 sibling, 1 reply; 17+ messages in thread
From: Ryan Mallon @ 2009-08-31 20:33 UTC (permalink / raw)
  To: linux-arm-kernel

Pedro I. Sanchez wrote:
> On Mon, 31 Aug 2009 23:33:12 +0400, Sergey Matyukevich <geomatsi@gmail.com>
> wrote:
>> Hi,
>>  
>>> And how do I turn on the PMC clocks for the GPIO?
>> Assigning gpio pin PC6 to TIOB2 peripheral is only a part of the work.
>> Timer counters may operate in different modes. Take a look at
>> the datasheet for at91sam9260, timer counters are covered in chapter 34. 
>> It looks like 'waveform mode' is what you need (see 34.5.10, 34.5.11).
>> Before you get desired output on PC6 pin you will have to turn on
>> waveform operating mode for TIOB2 and to configure its wave shapes.
>>  
>> Thanks,
>> Sergey
> 
> Thanks Sergey,
> 
> So are the following statements correct?
> 
> 1. The pck0 clock I've been playing with has nothing to do with the clock I
> want on PC6 (TIOB2).
> 
> 2. I have to use instead the "tc2_clk" as defined in
> arch/arm/mach-at-91/at91sam9260.c.
> 
> 3. I have to access the TC_CMR register directly to set things up. I mean,
> there are no macros already defined to access these structures.

Attached is a driver for outputting pwm's using the timer counters on
the at91 (sorry its not a proper patch, but this is just hauled out of
an old kernel we have). The driver is written for the 2.6.20 and does
not use the new at91 timer counter library. I think it should be
reasonably easy to port  to the mainline kernel (if you want to do this
for mainline inclusion, I'm happy to lend a hand).

To output a pwm on PC6, add the following code to your board file:

static struct at91_pwm_data pwm_data[] = {
	{
		.channel	= 2,
		.clock_div	= AT91_TC_SCLK,
		.period		= 500000,	/* Milliseconds */
		.tiob_duty	= 50,		/* Percentage */
		.tio		= AT91_TIOB,
	},
};

and in your board init function:

at91_add_device_pwm(pwm_data, ARRAY_SIZE(pwm_data));

The driver also exports the period, duty and raw ra, rb and rc counter
values via sysfs.

HTH,
~Ryan

-- 
Bluewater Systems Ltd - ARM Technology Solution Centre

       Ryan Mallon                              Unit 5, Amuri Park
       Phone: +64 3 3779127                     404 Barbadoes St
       Fax:   +64 3 3779135                     PO Box 13 889
       Email: ryan at bluewatersys.com             Christchurch, 8013
       Web:   http://www.bluewatersys.com       New Zealand
       Freecall Australia  1800 148 751         USA 1800 261 2934
-------------- next part --------------
A non-text attachment was scrubbed...
Name: at91_pwm.c
Type: text/x-csrc
Size: 13254 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20090901/973113b0/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: at91sam9260_devices.c
Type: text/x-csrc
Size: 3307 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20090901/973113b0/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: board.h
Type: text/x-chdr
Size: 587 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20090901/973113b0/attachment-0002.bin>

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 20:03       ` Pedro I. Sanchez
  2009-08-31 20:33         ` Ryan Mallon
@ 2009-08-31 20:35         ` Sergey Matyukevich
  2009-08-31 21:06           ` Pedro I. Sanchez
  1 sibling, 1 reply; 17+ messages in thread
From: Sergey Matyukevich @ 2009-08-31 20:35 UTC (permalink / raw)
  To: linux-arm-kernel



> So are the following statements correct?
> 
> 1. The pck0 clock I've been playing with has nothing to do with the
> clock I want on PC6 (TIOB2).

Yes. PCK's (programmable clocks) are assigned to different pins:  
PB30, PC1 for PCK0 and to  PB31, PC2 for PCK1. 
For PCK see ch. 26 of at91sam9260 datasheet.

> 2. I have to use instead the "tc2_clk" as defined in
> arch/arm/mach-at-91/at91sam9260.c.

Yes

> 3. I have to access the TC_CMR register directly to set things up. I
> mean, there are no macros already defined to access these structures.

You have to 'ioremap' required registers and write to those
registers directly using memory-writing macroses iowriteXX.

But at first decide what you need, TIOB or PCK. If you don't need all
the power of Ryan Mallon's pwm driver (see below in the thread) and
all you need is clocking output on GPIO pin, then you might be happy
with PCK. Note that PMC_PCK registers allows several dividers, if
original clock is too high.

Sergey 

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 19:58       ` Stephen Munnings
@ 2009-08-31 20:37         ` Pedro I. Sanchez
  2009-08-31 20:44           ` Stephen Munnings
  0 siblings, 1 reply; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 20:37 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 31 Aug 2009 15:58:50 -0400, Stephen Munnings
<smunnings@gabaedevelopment.com> wrote:
> Sergey Matyukevich wrote:
>> Hi,
>>  
>>   
>>> And how do I turn on the PMC clocks for the GPIO?
>>>     
>>
>> Assigning gpio pin PC6 to TIOB2 peripheral is only a part of the work.
>> Timer counters may operate in different modes. Take a look at
>> the datasheet for at91sam9260, timer counters are covered in chapter 34.

>> It looks like 'waveform mode' is what you need (see 34.5.10, 34.5.11).
>> Before you get desired output on PC6 pin you will have to turn on
>> waveform operating mode for TIOB2 and to configure its wave shapes.
>>  
>> Thanks,
>> Sergey
>>   
> hmmmm....
> 
> PCK0 is *not*  a TC pin - it is a clock output from the Power Management 
> Controller.
> (Section 25.6)
> It should be as easy as dividing down one of the primary clock sources 
> and then enabling
> the appropriate GPIO pin as the appropriate peripheral.
> 
> Ahah - there is the problem.....  PCK0 is not available on PC6 - it must 
> be set as peripheral B
> on pin PC1 or PB30 as Peripheral A - no other choices available...
> 
> PC6 is indeed TIOB2 (one of the counter timers)

OK, I see this thread unfolding, thank you!

This is what I have now to test pck0 on PC1:

at91_set_B_periph(AT91_PIN_PC1, 0);
pck0=clk_get(NULL, "pck0");
pll=clk_get(NULL, "plla");
clk_set_parent(pck0, pll);
clk_set_rate(pck0, 50000000);
clk_enable(pck0);

But I don't get a clean clock on PC1. In the end I will still need to get
the TC clock on PC6 but I for the time being I want to be able to generate
any clock out first!

Is there something else to do?

-- 
Pedro

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 20:37         ` Pedro I. Sanchez
@ 2009-08-31 20:44           ` Stephen Munnings
  2009-08-31 21:09             ` Pedro I. Sanchez
  0 siblings, 1 reply; 17+ messages in thread
From: Stephen Munnings @ 2009-08-31 20:44 UTC (permalink / raw)
  To: linux-arm-kernel

Pedro I. Sanchez wrote:
> On Mon, 31 Aug 2009 15:58:50 -0400, Stephen Munnings
> <smunnings@gabaedevelopment.com> wrote:
>   
>> Sergey Matyukevich wrote:
>>     
>>> Hi,
>>>  
>>>   
>>>       
>>>> And how do I turn on the PMC clocks for the GPIO?
>>>>     
>>>>         
>>> Assigning gpio pin PC6 to TIOB2 peripheral is only a part of the work.
>>> Timer counters may operate in different modes. Take a look at
>>> the datasheet for at91sam9260, timer counters are covered in chapter 34.
>>>       
>
>   
>>> It looks like 'waveform mode' is what you need (see 34.5.10, 34.5.11).
>>> Before you get desired output on PC6 pin you will have to turn on
>>> waveform operating mode for TIOB2 and to configure its wave shapes.
>>>  
>>> Thanks,
>>> Sergey
>>>   
>>>       
>> hmmmm....
>>
>> PCK0 is *not*  a TC pin - it is a clock output from the Power Management 
>> Controller.
>> (Section 25.6)
>> It should be as easy as dividing down one of the primary clock sources 
>> and then enabling
>> the appropriate GPIO pin as the appropriate peripheral.
>>
>> Ahah - there is the problem.....  PCK0 is not available on PC6 - it must 
>> be set as peripheral B
>> on pin PC1 or PB30 as Peripheral A - no other choices available...
>>
>> PC6 is indeed TIOB2 (one of the counter timers)
>>     
>
> OK, I see this thread unfolding, thank you!
>
> This is what I have now to test pck0 on PC1:
>
> at91_set_B_periph(AT91_PIN_PC1, 0);
> pck0=clk_get(NULL, "pck0");
> pll=clk_get(NULL, "plla");
> clk_set_parent(pck0, pll);
> clk_set_rate(pck0, 50000000);
> clk_enable(pck0);
>
> But I don't get a clean clock on PC1. In the end I will still need to get
> the TC clock on PC6 but I for the time being I want to be able to generate
> any clock out first!
>
> Is there something else to do?
>
>   
The code here will try to give you a 50Mhz signal.
That might not be feasible on a 9260.
This might be the source of not getting a "clean" clock on PC1.
Try adjusting it for something that your chip (9260) can reasonably 
generate.
Also, at 50Mhz, there can be all kinds of termination, ringing, and 
other problems.
To get "just any clean signal", try a frequency much lower.
Depending on which pll you use as parent, and what frequency it is 
already running at,
try for around 1Mhz to get a "nice clean signal".
The signal of PCK will try to be a "square wave".
You will find that the PCK signal programming is easier (but much more 
limited) than
programming the TC signals.
The TC signals are much more flexible in their range, etc., but take 
more work to set up.
This is a pretty common trade off.

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 20:33         ` Ryan Mallon
@ 2009-08-31 20:46           ` Pedro I. Sanchez
  0 siblings, 0 replies; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 20:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 01 Sep 2009 08:33:54 +1200, Ryan Mallon <ryan@bluewatersys.com>
wrote:
> Pedro I. Sanchez wrote:
>> On Mon, 31 Aug 2009 23:33:12 +0400, Sergey Matyukevich
>> <geomatsi@gmail.com>
>> wrote:
>>> Hi,
>>>  
>>>> And how do I turn on the PMC clocks for the GPIO?
>>> Assigning gpio pin PC6 to TIOB2 peripheral is only a part of the work.
>>> Timer counters may operate in different modes. Take a look at
>>> the datasheet for at91sam9260, timer counters are covered in chapter
34.
>>>
>>> It looks like 'waveform mode' is what you need (see 34.5.10, 34.5.11).
>>> Before you get desired output on PC6 pin you will have to turn on
>>> waveform operating mode for TIOB2 and to configure its wave shapes.
>>>  
>>> Thanks,
>>> Sergey
>> 
>> Thanks Sergey,
>> 
>> So are the following statements correct?
>> 
>> 1. The pck0 clock I've been playing with has nothing to do with the
clock
>> I
>> want on PC6 (TIOB2).
>> 
>> 2. I have to use instead the "tc2_clk" as defined in
>> arch/arm/mach-at-91/at91sam9260.c.
>> 
>> 3. I have to access the TC_CMR register directly to set things up. I
>> mean,
>> there are no macros already defined to access these structures.
> 
> Attached is a driver for outputting pwm's using the timer counters on
> the at91 (sorry its not a proper patch, but this is just hauled out of
> an old kernel we have). The driver is written for the 2.6.20 and does
> not use the new at91 timer counter library. I think it should be
> reasonably easy to port  to the mainline kernel (if you want to do this
> for mainline inclusion, I'm happy to lend a hand).
> 
> To output a pwm on PC6, add the following code to your board file:
> 
> static struct at91_pwm_data pwm_data[] = {
> 	{
> 		.channel	= 2,
> 		.clock_div	= AT91_TC_SCLK,
> 		.period		= 500000,	/* Milliseconds */
> 		.tiob_duty	= 50,		/* Percentage */
> 		.tio		= AT91_TIOB,
> 	},
> };
> 
> and in your board init function:
> 
> at91_add_device_pwm(pwm_data, ARRAY_SIZE(pwm_data));
> 
> The driver also exports the period, duty and raw ra, rb and rc counter
> values via sysfs.
> 
> HTH,
> ~Ryan

Thank you Ryan! I'll take a look at this as I move into the TC world.

BTW, I found this thread that talks about setting a pulse signal on the TC
pins:

http://www.at91.com/samphpbb/viewtopic.php?f=12&t=18294

This is going to help me as well.


-- 
Pedro

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 20:35         ` Sergey Matyukevich
@ 2009-08-31 21:06           ` Pedro I. Sanchez
  0 siblings, 0 replies; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 21:06 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 1 Sep 2009 00:35:46 +0400, Sergey Matyukevich <geomatsi@gmail.com>
wrote:
>> So are the following statements correct?
>> 
>> 1. The pck0 clock I've been playing with has nothing to do with the
>> clock I want on PC6 (TIOB2).
> 
> Yes. PCK's (programmable clocks) are assigned to different pins:  
> PB30, PC1 for PCK0 and to  PB31, PC2 for PCK1. 
> For PCK see ch. 26 of at91sam9260 datasheet.
> 
>> 2. I have to use instead the "tc2_clk" as defined in
>> arch/arm/mach-at-91/at91sam9260.c.
> 
> Yes
> 
>> 3. I have to access the TC_CMR register directly to set things up. I
>> mean, there are no macros already defined to access these structures.
> 
> You have to 'ioremap' required registers and write to those
> registers directly using memory-writing macroses iowriteXX.
> 
> But at first decide what you need, TIOB or PCK. If you don't need all
> the power of Ryan Mallon's pwm driver (see below in the thread) and
> all you need is clocking output on GPIO pin, then you might be happy
> with PCK. Note that PMC_PCK registers allows several dividers, if
> original clock is too high.
> 
> Sergey

Well, the board I'm working on, as well several others already on my shelf
:-(, is already wired to use PC6 so I have to go the TC way. So this is the
way to go for me.

-- 
Pedro

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

* AT91SAM9260: How to output PCK0 clock on a GPIO pin
  2009-08-31 20:44           ` Stephen Munnings
@ 2009-08-31 21:09             ` Pedro I. Sanchez
  0 siblings, 0 replies; 17+ messages in thread
From: Pedro I. Sanchez @ 2009-08-31 21:09 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 31 Aug 2009 16:44:39 -0400, Stephen Munnings
<smunnings@gabaedevelopment.com> wrote:
> Pedro I. Sanchez wrote:
>> On Mon, 31 Aug 2009 15:58:50 -0400, Stephen Munnings
>> <smunnings@gabaedevelopment.com> wrote:
>>   
>>> Sergey Matyukevich wrote:
>>>     
>>>> Hi,
>>>>  
>>>>   
>>>>       
>>>>> And how do I turn on the PMC clocks for the GPIO?
>>>>>     
>>>>>         
>>>> Assigning gpio pin PC6 to TIOB2 peripheral is only a part of the work.
>>>> Timer counters may operate in different modes. Take a look at
>>>> the datasheet for at91sam9260, timer counters are covered in chapter
>>>> 34.
>>>>       
>>
>>   
>>>> It looks like 'waveform mode' is what you need (see 34.5.10, 34.5.11).
>>>> Before you get desired output on PC6 pin you will have to turn on
>>>> waveform operating mode for TIOB2 and to configure its wave shapes.
>>>>  
>>>> Thanks,
>>>> Sergey
>>>>   
>>>>       
>>> hmmmm....
>>>
>>> PCK0 is *not*  a TC pin - it is a clock output from the Power
Management
>>>
>>> Controller.
>>> (Section 25.6)
>>> It should be as easy as dividing down one of the primary clock sources 
>>> and then enabling
>>> the appropriate GPIO pin as the appropriate peripheral.
>>>
>>> Ahah - there is the problem.....  PCK0 is not available on PC6 - it
must
>>>
>>> be set as peripheral B
>>> on pin PC1 or PB30 as Peripheral A - no other choices available...
>>>
>>> PC6 is indeed TIOB2 (one of the counter timers)
>>>     
>>
>> OK, I see this thread unfolding, thank you!
>>
>> This is what I have now to test pck0 on PC1:
>>
>> at91_set_B_periph(AT91_PIN_PC1, 0);
>> pck0=clk_get(NULL, "pck0");
>> pll=clk_get(NULL, "plla");
>> clk_set_parent(pck0, pll);
>> clk_set_rate(pck0, 50000000);
>> clk_enable(pck0);
>>
>> But I don't get a clean clock on PC1. In the end I will still need to
get
>> the TC clock on PC6 but I for the time being I want to be able to
>> generate
>> any clock out first!
>>
>> Is there something else to do?
>>
>>   
> The code here will try to give you a 50Mhz signal.
> That might not be feasible on a 9260.
> This might be the source of not getting a "clean" clock on PC1.
> Try adjusting it for something that your chip (9260) can reasonably 
> generate.
> Also, at 50Mhz, there can be all kinds of termination, ringing, and 
> other problems.
> To get "just any clean signal", try a frequency much lower.
> Depending on which pll you use as parent, and what frequency it is 
> already running at,
> try for around 1Mhz to get a "nice clean signal".
> The signal of PCK will try to be a "square wave".
> You will find that the PCK signal programming is easier (but much more 
> limited) than
> programming the TC signals.
> The TC signals are much more flexible in their range, etc., but take 
> more work to set up.
> This is a pretty common trade off.

Well, good news! I got the clean clock on PC1 (3.014 MHz), not at the rate
I requested (1 MHz), but very clean. I'll have to figure out the clock
divider thing now to get the right values.

Anyway, this is a big step for me. Thanks once more!

-- 
Pedro

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

end of thread, other threads:[~2009-08-31 21:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-31 15:32 AT91SAM9260: How to output PCK0 clock on a GPIO pin Pedro I. Sanchez
2009-08-31 16:58 ` Stephen Munnings
2009-08-31 18:27   ` Pedro I. Sanchez
2009-08-31 18:44     ` Stephen Munnings
2009-08-31 19:02       ` Pedro I. Sanchez
2009-08-31 19:13         ` Stephen Munnings
2009-08-31 19:21           ` Pedro I. Sanchez
2009-08-31 19:33     ` Sergey Matyukevich
2009-08-31 19:58       ` Stephen Munnings
2009-08-31 20:37         ` Pedro I. Sanchez
2009-08-31 20:44           ` Stephen Munnings
2009-08-31 21:09             ` Pedro I. Sanchez
2009-08-31 20:03       ` Pedro I. Sanchez
2009-08-31 20:33         ` Ryan Mallon
2009-08-31 20:46           ` Pedro I. Sanchez
2009-08-31 20:35         ` Sergey Matyukevich
2009-08-31 21:06           ` Pedro I. Sanchez

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).