Howto set DIO on MPC-5200 Lite

Matthias Fechner idefix at fechner.net
Fri Mar 23 07:04:53 EST 2007


Hello Josu,

* Josu Onandia <jonandia at aotek.es> [19-03-07 14:18]:
> Some sample code. Hope this helps.

thx a lot for all your help I love that mailinglist :)

Here is a very small kernel module for the icecube board.
It activates the LED 1 and 3 after module has been loaded
and off again if module has been removed.
Maybe that helps someone else:

#include <linux/module.h>
#include <asm/mpc52xx.h>

#define MPC5xxx_GPIO MPC52xx_VA(MPC52xx_GPIO_OFFSET)

static void psc6_configure_pins(void)
{
   struct mpc52xx_gpio *config;
   config = (struct mpc52xx_gpio*) MPC5xxx_GPIO;
         
   printk("Address: %X\n",(u32)&config->port_config);
   printk("Configure port\n");
   config->port_config &= ~(0x00700000);
		     
   printk("Set IRDA to GPIO\n");
   config->simple_gpioe |= 0x30000000;
			      
   printk("Set pins to CMOS output\n");
   config->simple_ode &= ~(0x30000000);
				       
   printk("Set simple GPIO data direction register\n");
   config->simple_ddr |= 0x30000000;
 }
   
// the pins are active low, so we invert it
static void psc6_pin_on(unsigned int pin)
{
   struct mpc52xx_gpio *config;
   config = (struct mpc52xx_gpio*) MPC5xxx_GPIO;
   printk("Set LEDs %i\n",pin);
   config->simple_dvo &= ~(1 << (pin+28));
}
	       
// the pins are active low, so we invert it
static void psc6_pin_off(unsigned int pin)
{
   struct mpc52xx_gpio *config;
   config = (struct mpc52xx_gpio*) MPC5xxx_GPIO;
   printk("Clear LED %i\n",pin);
   config->simple_dvo |= (1 << (pin+28));
}
			   
static int icecube_led_init(void)
{
   printk("Module Blink LED loaded\n");
   printk("Set LEDs on\n");
   psc6_configure_pins();
   psc6_pin_on(0);
   psc6_pin_on(1);
   return 0;
}
						
static void icecube_led_cleanup(void)
{
   printk("Module Blink LED unloaded\n");
   psc6_pin_off(0);
   psc6_pin_off(1);
}
      
MODULE_AUTHOR("Matthias Fechner <idefix at fechner.net>");
MODULE_DESCRIPTION("Driver to switch LED on icecube board after driver loaded successfully and switch LEDs of after driver unloaded successfully.");
MODULE_LICENSE("GPL");

module_init(icecube_led_init);
module_exit(icecube_led_cleanup);



Best regards,
Matthias

-- 

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying to
produce bigger and better idiots. So far, the universe is winning." --
Rich Cook



More information about the Linuxppc-embedded mailing list