Skip to contentSkip to conversation

AT91SAM9260: How to output PCK0 clock on a GPIO pin

DISCUSSION Pedro I. Sanchez 4 participants 17 messages Aug 31, 2009

lore
Share & tools
lore
#0 lore raw

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,

Signature · 6 lines
Pedro



-- 
Pedro I. Sanchez
#1 lore raw
Quoted 42 lines · Pedro I. Sanchez

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

Quoted 9 lines

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

#2 lore raw
Quoted 71 lines · Stephen Munnings
Quoted 50 lines · Pedro I. Sanchez

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.

Quoted 5 lines

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

Quoted 7 lines

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.

Quoted 5 lines

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?

Signature · 1 line
Pedro I. Sanchez
#3 lore raw
Quoted 9 lines · Pedro I. Sanchez
Quoted 9 lines

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.

Quoted 8 lines
Quoted 2 lines

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.

#4 lore raw
Quoted 20 lines · Stephen Munnings
Quoted 11 lines · Pedro I. Sanchez
Quoted 11 lines

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.

Quoted 8 lines
Quoted 2 lines

Stephen Munnings

Thanks Stephen,

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

Quoted 7 lines

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,

Signature · 1 line
Pedro
#5 lore raw
Quoted 8 lines · Pedro I. Sanchez

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

#6 lore raw
Quoted 11 lines · Stephen Munnings
Quoted 9 lines · Pedro I. Sanchez

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,

Quoted 8 lines

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.

Signature · 1 line
Pedro
#7 lore raw
In reply to Pedro I. Sanchez

Hi,

Quoted 1 line

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

#8 lore raw
Quoted 13 lines · Sergey Matyukevich

Hi,

Quoted 2 lines

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.

Quoted 3 lines

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)

#9 lore raw
Quoted 27 lines · Stephen Munnings
Quoted 10 lines · Sergey Matyukevich

Hi,

Quoted 2 lines

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.

Quoted 7 lines

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.

Quoted 5 lines

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?

Signature · 1 line
Pedro
#10 lore raw
Quoted 53 lines · Pedro I. Sanchez
Quoted 32 lines · Stephen Munnings
Quoted 13 lines · Sergey Matyukevich

Hi,

Quoted 3 lines

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.

Quoted 8 lines

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.

Quoted 6 lines

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

Quoted 7 lines

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.

#11 lore raw
Quoted 24 lines · Stephen Munnings
Quoted 23 lines · Pedro I. Sanchez
Quoted 20 lines · Stephen Munnings
Quoted 18 lines · Sergey Matyukevich

Hi,

Quoted 3 lines

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.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Thanks,
Sergey

hmmmm....

PCK0 is *not* a TC pin - it is a clock output from the Power

Management

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

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:

Quoted 8 lines
Quoted 8 lines

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

Quoted 17 lines
Quoted 7 lines

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,

Quoted 8 lines

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!

Signature · 1 line
Pedro
#12 lore raw
In reply to Sergey Matyukevich
Quoted 11 lines · Sergey Matyukevich

Hi,

Quoted 1 line

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.

Quoted 2 lines

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,

Signature · 1 line
Pedro
#13 lore raw
Quoted 19 lines · Pedro I. Sanchez
Quoted 10 lines · Sergey Matyukevich

Hi,

Quoted 1 line

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.

Quoted 2 lines

Thanks,
Sergey

Thanks Sergey,

So are the following statements correct?

Quoted 8 lines

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

Signature · 29 lines
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>
#14 lore raw
Quoted 10 lines · Ryan Mallon
Quoted 9 lines · Pedro I. Sanchez
Quoted 6 lines · Sergey Matyukevich

Hi,

Quoted 1 line

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.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

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

Quoted 31 lines
Quoted 9 lines

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:

Quoted 7 lines

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.

Signature · 1 line
Pedro
#15 lore raw
In reply to Pedro I. Sanchez
Quoted 6 lines

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.

Quoted 2 lines

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

Yes

Quoted 2 lines

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

#16 lore raw
Quoted 20 lines · Sergey Matyukevich
Quoted 4 lines

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.

Quoted 2 lines

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

Yes

Quoted 2 lines

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.

Quoted 7 lines

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.

Signature · 1 line
Pedro