WikiStart: zipit2-kernel.patch

File zipit2-kernel.patch, 184.1 kB (added by ethicalclone, 6 months ago)

A much cleaner Zipit2 kernel patch with auto-gen stuff and whitespace errors removed

  • a/arch/arm/Kconfig

    old new  
    997997 
    998998source "drivers/rtc/Kconfig" 
    999999 
     1000source "drivers/gpio/Kconfig" 
     1001 
     1002source "drivers/audiodrv/Kconfig" 
     1003 
    10001004endmenu 
    10011005 
    10021006source "fs/Kconfig" 
  • a/arch/arm/Makefile

    old new  
    180180drivers-$(CONFIG_OPROFILE)      += arch/arm/oprofile/ 
    181181drivers-$(CONFIG_ARCH_CLPS7500) += drivers/acorn/char/ 
    182182drivers-$(CONFIG_ARCH_L7200)    += drivers/acorn/char/ 
     183drivers-$(CONFIG_GPIO)          += drivers/gpio/ 
     184drivers-$(CONFIG_AUDIODRV)      += drivers/audiodrv/ 
    183185 
    184186libs-y                          := arch/arm/lib/ $(libs-y) 
    185187 
  • a/arch/arm/kernel/process.c

    old new  
    131131                local_irq_disable(); 
    132132                if (!need_resched()) { 
    133133                        timer_dyn_reprogram(); 
     134                        //GPSR2 = 0x02000000; 
    134135                        arch_idle(); 
     136                        //GPCR2 = 0x02000000; 
    135137                } 
    136138                local_irq_enable(); 
    137139        } 
  • a/arch/arm/mach-pxa/mainstone.c

    old new  
    108108 
    109109        set_irq_chained_handler(IRQ_GPIO(0), mainstone_irq_handler); 
    110110        set_irq_type(IRQ_GPIO(0), IRQT_FALLING); 
     111 
    111112} 
    112113 
    113114#ifdef CONFIG_PM 
     
    262263        }, 
    263264}; 
    264265 
     266 
     267#ifdef ZIPIT2 
     268static void Zipit2_lcd_power(int on, struct fb_var_screeninfo *var) 
     269{ 
     270        printk(KERN_NOTICE "Set Zipit2 lcd power %d...\n",on); 
     271#if 0 
     272        if (on) { 
     273                IDP_CPLD_LCD |= (1<<0); 
     274        } else { 
     275                IDP_CPLD_LCD &= ~(1<<0); 
     276        } 
     277 
     278        /* call idp_vlcd for now as core driver does not support 
     279         * both power and vlcd hooks.  Note, this is not technically 
     280         * the correct sequence, but seems to work.  Disclaimer: 
     281         * this may eventually damage the display. 
     282         */ 
     283 
     284        idp_vlcd(on); 
     285#endif 
     286} 
     287 
     288static void Zipit2_backlight_power(int on) 
     289{ 
     290        printk(KERN_NOTICE "Set Zipit2 backlight %d...\n",on); 
     291#if 0 
     292        if (on) { 
     293                pxa_gpio_mode(GPIO16_PWM0_MD); 
     294                pxa_set_cken(CKEN0_PWM0, 1); 
     295                PWM_CTRL0 = 0x30; 
     296                PWM_PWDUTY0 = (0x80 << 2); 
     297                PWM_PERVAL0 = 0x3FC; 
     298        } else { 
     299                PWM_CTRL0 = 0; 
     300                PWM_PWDUTY0 = 0x0; 
     301                PWM_PERVAL0 = 0x3FF; 
     302                pxa_set_cken(CKEN0_PWM0, 0); 
     303        } 
     304#endif 
     305} 
     306 
     307static struct pxafb_mode_info Zipit2_lcd_mode = { 
     308        .pixclock               = LCD_PIXCLOCK, 
     309        .xres                   = LCD_XRES, 
     310        .yres                   = LCD_YRES, 
     311        .bpp                    = LCD_BPP, 
     312        .hsync_len              = LCD_HORIZONTAL_SYNC_PULSE_WIDTH, 
     313        .left_margin    = LCD_BEGIN_OF_LINE_WAIT_COUNT, 
     314        .right_margin   = LCD_END_OF_LINE_WAIT_COUNT, 
     315        .vsync_len              = LCD_VERTICAL_SYNC_PULSE_WIDTH, 
     316        .upper_margin   = LCD_BEGIN_FRAME_WAIT_COUNT, 
     317        .lower_margin   = LCD_END_OF_FRAME_WAIT_COUNT, 
     318        .sync                   = LCD_SYNC, 
     319}; 
     320 
     321static struct pxafb_mach_info Zipit2_pxafb_info = { 
     322        .num_modes              = 1, 
     323        .lccr0                  = LCD_LCCR0, 
     324        .lccr3                  = LCD_LCCR3, 
     325        .pxafb_backlight_power  = Zipit2_backlight_power, 
     326        .pxafb_lcd_power = &Zipit2_lcd_power 
     327}; 
     328#else 
    265329static void mainstone_backlight_power(int on) 
    266330{ 
    267331        if (on) { 
     
    277341                pxa_set_cken(CKEN0_PWM0, 0); 
    278342        } 
    279343} 
    280  
    281344static struct pxafb_mode_info toshiba_ltm04c380k_mode = { 
    282345        .pixclock               = 50000, 
    283346        .xres                   = 640, 
     
    311374        .lccr0                  = LCCR0_Act, 
    312375        .lccr3                  = LCCR3_PCP, 
    313376        .pxafb_backlight_power  = mainstone_backlight_power, 
     377 
    314378}; 
     379#endif //end check for ZIPIT2 
    315380 
    316381static int mainstone_mci_init(struct device *dev, irq_handler_t mstone_detect_int, void *data) 
    317382{ 
     
    332397         */ 
    333398        MST_MSCWR1 &= ~MST_MSCWR1_MS_SEL; 
    334399 
    335         err = request_irq(MAINSTONE_MMC_IRQ, mstone_detect_int, IRQF_DISABLED, 
    336                              "MMC card detect", data); 
     400        set_irq_type(IRQ_GPIO(96), IRQT_BOTHEDGE); 
     401 
     402        err = request_irq(IRQ_GPIO(96), mstone_detect_int, IRQF_DISABLED,"MMC card detect", data); 
     403 
    337404        if (err) { 
    338405                printk(KERN_ERR "mainstone_mci_init: MMC/SD: can't request MMC card detect IRQ\n"); 
    339406                return -1; 
     
    366433        .init           = mainstone_mci_init, 
    367434        .setpower       = mainstone_mci_setpower, 
    368435        .exit           = mainstone_mci_exit, 
     436        .detect_delay = 100, 
    369437}; 
    370438 
    371439static void mainstone_irda_transceiver_mode(struct device *dev, int mode) 
     
    417485        .init           = mainstone_ohci_init, 
    418486}; 
    419487 
     488static void mainstone_poweroff(void) 
     489{ 
     490        int nUserArg = 7;               // deep sleep 
     491        asm( "mcr p14, 0, %0, c7, c0, 0" :: "r" (nUserArg) ); 
     492} 
     493 
     494static void mainstone_restart(char mode) 
     495{ 
     496        // write the PMSR with a special value to make BLOB come on up 
     497        arm_machine_restart('h'); 
     498} 
    420499static void __init mainstone_init(void) 
    421500{ 
    422501        int SW7 = 0;  /* FIXME: get from SCR (Mst doc section 3.2.1.1) */ 
     
    441520         * On Mainstone, we route AC97_SYSCLK via GPIO45 to 
    442521         * the audio daughter card 
    443522         */ 
     523#ifndef ZIPIT2 
    444524        pxa_gpio_mode(GPIO45_SYSCLK_AC97_MD); 
    445  
     525#endif 
    446526        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices)); 
    447527 
     528#ifdef ZIPIT2 
     529        printk(KERN_NOTICE "Set Zipit2 lcd paramaters...\n"); 
     530 
     531        Zipit2_pxafb_info.modes = &Zipit2_lcd_mode; 
     532 
     533        set_pxa_fb_info(&Zipit2_pxafb_info); 
     534#else 
    448535        /* reading Mainstone's "Virtual Configuration Register" 
    449536           might be handy to select LCD type here */ 
    450537        if (0) 
     
    453540                mainstone_pxafb_info.modes = &toshiba_ltm035a776c_mode; 
    454541 
    455542        set_pxa_fb_info(&mainstone_pxafb_info); 
     543#endif 
    456544 
    457545        pxa_set_mci_info(&mainstone_mci_platform_data); 
    458546        pxa_set_ficp_info(&mainstone_ficp_platform_data); 
    459547        pxa_set_ohci_info(&mainstone_ohci_platform_data); 
     548 
     549        pm_power_off = mainstone_poweroff; 
     550        arm_pm_restart = mainstone_restart; 
     551 
    460552} 
    461553 
    462554 
     
    474566        pxa_map_io(); 
    475567        iotable_init(mainstone_io_desc, ARRAY_SIZE(mainstone_io_desc)); 
    476568 
     569#ifdef JWK 
    477570        /* initialize sleep mode regs (wake-up sources, etc) */ 
    478571        PGSR0 = 0x00008800; 
    479572        PGSR1 = 0x00000002; 
     
    491584        PKWR  = 0x000FD000; 
    492585        /*      Need read PKWR back after set it.       */ 
    493586        PKWR; 
     587#endif 
    494588} 
    495589 
    496590MACHINE_START(MAINSTONE, "Intel HCDDBBVA0 Development Platform (aka Mainstone)") 
  • a/drivers/Makefile

    old new  
    44# 15 Sep 2000, Christoph Hellwig <hch@infradead.org> 
    55# Rewritten to use lists instead of if-statements. 
    66# 
    7  
    87obj-$(CONFIG_PCI)               += pci/ 
    98obj-$(CONFIG_PARISC)            += parisc/ 
    109obj-$(CONFIG_RAPIDIO)           += rapidio/ 
     
    8180obj-$(CONFIG_DMA_ENGINE)        += dma/ 
    8281obj-$(CONFIG_HID)               += hid/ 
    8382obj-$(CONFIG_PPC_PS3)           += ps3/ 
     83 
  • /dev/null

    old new  
     1# 
     2# Misc strange devices 
     3# 
     4 
     5menu "PXA audio driver" 
     6 
     7config AUDIODRV 
     8        tristate "Device driver for PXA audio" 
     9        depends on ARCH_PXA 
     10        ---help--- 
     11          This option enables device driver support for PXA gpio. 
     12 
     13          If unsure, say N. 
     14 
     15endmenu 
  • /dev/null

    old new  
     1# 
     2# Makefile for gpio driver. 
     3# 
     4 
     5obj-$(CONFIG_AUDIODRV)  := audio_pxa.o 
  • /dev/null

    old new  
     1/* 
     2 *      PXA Audio Driver 
     3 * 
     4 *      Copyright (C) 2007 Aeronix 
     5 * 
     6 *      This driver allows controls the audio on the PXA processor 
     7 * 
     8 *      This program is free software; you can redistribute it and/or 
     9 *      modify it under the terms of the GNU General Public License 
     10 *      as published by the Free Software Foundation; either version 
     11 *      2 of the License, or (at your option) any later version. 
     12 * 
     13 */ 
     14 
     15#include <linux/module.h> 
     16#include <linux/kernel.h> 
     17#include <linux/proc_fs.h> 
     18#include <linux/fs.h> 
     19#include <asm/uaccess.h> 
     20#include <linux/ioport.h> 
     21#include <asm/io.h> 
     22#include <asm/arch/pxa-regs.h> 
     23#include "audio_pxa.h" 
     24 
     25extern void* dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp); 
     26extern void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle); 
     27 
     28static struct file_operations audio_driver_fops = { 
     29                owner:                  THIS_MODULE, 
     30                llseek:                 no_llseek, 
     31                read:                   audio_read_method, 
     32                write:          audio_write_method, 
     33        ioctl:          audio_ioctl_method, 
     34        open:           audio_open_method, 
     35        release:        audio_release_method, 
     36}; 
     37 
     38 
     39static void mcp_enable(void) 
     40{ 
     41        int i; 
     42        int nGpioMode; 
     43 
     44        pBuffer = (char *) dma_alloc_coherent(NULL, BUFFSIZE, (dma_addr_t *)&pBufferPhys,GFP_KERNEL); 
     45 
     46        pDescs = (char *) dma_alloc_coherent(NULL, sizeof(DmaDesc) * 16, (dma_addr_t *)&pDescsPhys,GFP_KERNEL); 
     47 
     48        memset(pBuffer, 0, BUFFSIZE); 
     49 
     50//      printk(KERN_INFO "Buffer Address: virt(0x%08lX), phys(0x%08lX)\n", (long unsigned int)pBuffer, (long unsigned int)pBufferPhys); 
     51//      printk(KERN_INFO  "Descriptor Address: virt(0x%08lX), phys(0x%08lX)\n", (long unsigned int)pDescs, (long unsigned int)pDescsPhys); 
     52 
     53        // configure the descriptors 
     54        for(i = 0; i < 16; i++) 
     55        { 
     56                pDescs[i].DDADR = &pDescsPhys[i + 1]; 
     57                pDescs[i].DSADR = &pBufferPhys[i * 6 * 1024]; 
     58                pDescs[i].DTADR = 0x40400080; 
     59                pDescs[i].DCMD = 0x9003D800;            // src inc, target flow, size 32 bytes, width 4 bytes, 6K length 
     60 
     61        } 
     62 
     63        pDescs[15].DDADR = &pDescsPhys[0];              // reloop DMA descriptors 
     64 
     65#if 0 
     66        for(i = 0; i < 16; i++) 
     67        { 
     68                printk(KERN_INFO "DDADR[%d]: 0x%08lX\n", i, pDescs[i].DDADR); 
     69                printk(KERN_INFO "DSADR[%d]: 0x%08lX\n", i, pDescs[i].DSADR); 
     70                printk(KERN_INFO "DTADR[%d]: 0x%08lX\n", i, pDescs[i].DTADR); 
     71                printk(KERN_INFO " DCMD[%d]: 0x%08lX\n", i, pDescs[i].DCMD); 
     72                printk(KERN_INFO "\n"); 
     73        } 
     74#endif 
     75        // configure the DMA channel 
     76 
     77        DRCMR3 = 0x8F;          // I2S DMA Channel Map (Channel 15) 
     78        DCSR15 = 0x00000000;    // DMA Control/Status15 (Descriptors used) 
     79 
     80        DDADR15 = &pDescsPhys[0];       // DMA Descriptor Address (Channel 15) 
     81        DCSR15 = 0x80000000;            // DMA Control/Status15 (Start the DMA) 
     82 
     83        // configure I2S 
     84    nGpioMode = 113 | GPIO_ALT_FN_1_OUT; 
     85        pxa_gpio_mode(nGpioMode); 
     86 
     87    nGpioMode = 28 | GPIO_ALT_FN_1_OUT; 
     88        pxa_gpio_mode(nGpioMode); 
     89 
     90    nGpioMode = 29 | GPIO_ALT_FN_1_IN; 
     91        pxa_gpio_mode(nGpioMode); 
     92 
     93    nGpioMode = 30 | GPIO_ALT_FN_1_OUT; 
     94        pxa_gpio_mode(nGpioMode); 
     95 
     96    nGpioMode = 31 | GPIO_ALT_FN_1_OUT; 
     97        pxa_gpio_mode(nGpioMode); 
     98 
     99    nGpioMode = 37 | GPIO_IN; 
     100    pxa_gpio_mode(nGpioMode); 
     101 
     102//      printk(KERN_INFO "CKEN: 0x%08lX\n", CKEN); 
     103        CKEN |= 0x100;                  // clk to I2S 
     104//      printk(KERN_INFO "CKEN: 0x%08lX\n", CKEN); 
     105        SACR1 |= 0x9;                           // Disable record and MSB format 
     106        SADIV = 0xD;                            // BITCLK divisor to 44.1KHz 
     107        SACR0 |= 0x7705;                        // BITCLK output and Enable I2S 
     108 
     109        pWriteAddress = pBuffer; 
     110 
     111//      printk(KERN_INFO "mcp_enable - exit\n"); 
     112} 
     113 
     114static int __init audio_driver_init(void) 
     115{ 
     116        int rc; 
     117 
     118        if ( (rc = register_chrdev(MCP_MAJOR,"audio",&audio_driver_fops)) ) 
     119                printk(KERN_WARNING "DAI: Unable to get major %d for MCP\n",MCP_MAJOR); 
     120        else 
     121                printk(KERN_INFO "DAI: DAI Enable with major = %d\n", MCP_MAJOR); 
     122 
     123        return rc; 
     124} 
     125 
     126static void __exit audio_driver_exit(void) 
     127{ 
     128        printk(KERN_NOTICE "Remove Audio driver...\n"); 
     129        unregister_chrdev(MCP_MAJOR, "audio"); 
     130 
     131 
     132} 
     133 
     134/* FILE FOPS */ 
     135static ssize_t audio_read_method (struct file *file, char *buf, size_t count, loff_t *offset) 
     136{ 
     137  int ret = 0; 
     138 
     139  return ret; 
     140} 
     141 
     142static ssize_t audio_write_method (struct file *file, const char *buf, size_t count, loff_t *offset) 
     143{ 
     144        char *pFirstWrite; 
     145        char *pSecondWrite; 
     146        unsigned long ulFirstAmount; 
     147        unsigned long ulSecondAmount; 
     148        unsigned long ulAvailable; 
     149        unsigned long ulWritten; 
     150        unsigned long ulToWrite; 
     151 
     152        char * pReadAddress = (char *) DSADR15 - pBufferPhys + pBuffer;         // get current processing address 
     153 
     154//      printk(KERN_INFO "count: 0x%08lX, pRead: 0x%08lX, pWrite: 0x%08lX\n", count, pReadAddress, pWriteAddress ); 
     155        if(buf == 0) 
     156        { 
     157//              printk(KERN_INFO "count: 0x%08lX, buf: 0x%08lX\n", count, buf ); 
     158 
     159                if(count == 0) 
     160                { 
     161//                      printk(KERN_INFO "Initialize playback\n"); 
     162 
     163                        DCSR15 = 0x00000000;                                            // DMA Control/Status15 (Stop the DMA) 
     164 
     165                        memset(pBuffer, 0, BUFFSIZE); 
     166 
     167                        DDADR15 = DDADR15; 
     168                        DCSR15 = 0x80000000;                                            // DMA Control/Status15 (Start the DMA) 
     169                } 
     170                else 
     171                if(count == 1) 
     172                { 
     173//                      printk(KERN_INFO "Stop playback\n"); 
     174 
     175                        DCSR15 = 0x00000000;                                            // DMA Control/Status15 (Stop the DMA) 
     176                } 
     177                else 
     178                if(count == 2) 
     179                { 
     180//                      printk(KERN_INFO "Resume playback: 0x%08lX, 0x%08lX\n", AccessReg(0x03C), AccessReg(0x2F0)); 
     181 
     182                        DDADR15 = DDADR15; 
     183                        DCSR15 = 0x80000000;                                            // DMA Control/Status15 (Start the DMA) 
     184                } 
     185 
     186                return 0; 
     187        } 
     188 
     189        if(pWriteAddress > pReadAddress) 
     190        { 
     191                ulAvailable = BUFFSIZE - (pWriteAddress - pReadAddress); 
     192 
     193                pFirstWrite = pWriteAddress; 
     194                ulFirstAmount = BUFFSIZE - (pWriteAddress - &pBuffer[0]); 
     195 
     196                ulSecondAmount = ulAvailable - ulFirstAmount; 
     197                pSecondWrite = &pBuffer[0]; 
     198        } 
     199        else 
     200        { 
     201                ulAvailable = pReadAddress - pWriteAddress; 
     202 
     203                pFirstWrite = pWriteAddress; 
     204                ulFirstAmount = ulAvailable; 
     205 
     206                pSecondWrite = 0; 
     207                ulSecondAmount = 0; 
     208        } 
     209 
     210//      printk(KERN_INFO "1st: 0x%08lX, 0x%08lX, 2nd: 0x%08lX, 0x%08lX\n", pFirstWrite, ulFirstAmount, pSecondWrite, ulSecondAmount ); 
     211 
     212        if((ulAvailable < count) && (ulAvailable < (BUFFSIZE / 2))) 
     213        { 
     214//              printk(KERN_INFO "mcp_write:QUEUE_FULL\n"); 
     215                return 0; 
     216        } 
     217 
     218        ulWritten = 0; 
     219        ulToWrite = count - ulWritten; 
     220        if (ulToWrite > ulFirstAmount) 
     221                ulToWrite = ulFirstAmount; 
     222 
     223//      printk(KERN_INFO "1st: 0x%08lX, 0x%08lX\n", pFirstWrite, ulToWrite ); 
     224        copy_from_user(pFirstWrite, buf, ulToWrite); 
     225        pWriteAddress += ulToWrite; 
     226        ulWritten += ulToWrite; 
     227 
     228        if(pWriteAddress >= (&pBuffer[0] + BUFFSIZE)) 
     229        { 
     230                pWriteAddress = &pBuffer[0]; 
     231        } 
     232 
     233        if((ulWritten < count) && pSecondWrite) 
     234        { 
     235                ulToWrite = count - ulWritten; 
     236 
     237                if (ulToWrite > ulSecondAmount) 
     238                        ulToWrite = ulSecondAmount; 
     239 
     240//              printk(KERN_INFO "2nd: 0x%08lX, 0x%08lX\n", pSecondWrite, ulToWrite ); 
     241                copy_from_user(pSecondWrite, &buf[ulWritten], ulToWrite); 
     242                pWriteAddress = pSecondWrite + ulToWrite; 
     243                ulWritten += ulToWrite; 
     244        } 
     245 
     246        if(pWriteAddress >= (&pBuffer[0] + BUFFSIZE)) 
     247        { 
     248                pWriteAddress = &pBuffer[0]; 
     249        } 
     250 
     251        return (ssize_t)ulWritten; 
     252} 
     253 
     254static int audio_ioctl_method (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 
     255{ 
     256        return 0; 
     257} 
     258 
     259static int audio_open_method (struct inode *inode, struct file *file) 
     260{ 
     261        int nRtnValue = 0; 
     262        int minor; 
     263        dev_t device = inode->i_rdev; 
     264 
     265        minor = MINOR(device); 
     266        printk(KERN_INFO "audio_open_method: MINOR=%d\n", minor); 
     267 
     268        mcp_enable(); 
     269 
     270        return nRtnValue; 
     271} 
     272 
     273static int audio_release_method (struct inode *inode, struct file *file) 
     274{ 
     275        DCSR15 = 0x00000000;                                            // DMA Control/Status15 (Stop the DMA) 
     276 
     277        printk(KERN_INFO "audio_release\n"); 
     278 
     279 
     280        dma_free_coherent(NULL, sizeof(DmaDesc) * 16, (void*)pDescs, (dma_addr_t)pDescsPhys); 
     281        dma_free_coherent(NULL, BUFFSIZE, (void*)pBuffer, (dma_addr_t)pBufferPhys); 
     282 
     283        return 0; 
     284} 
     285 
     286module_init(audio_driver_init); 
     287module_exit(audio_driver_exit); 
     288 
     289MODULE_AUTHOR("Aeronix"); 
     290MODULE_LICENSE("GPL"); 
  • /dev/null

    old new  
     1#ifndef __AUDIO_PXA_H_ 
     2#define __AUDIO_PXA_H_ 
     3 
     4 
     5#define MCP_MAJOR 14 
     6 
     7static void mcp_enable(void); 
     8 
     9const unsigned long PxaRegsOffset = 0x40000000; 
     10 
     11#define AccessReg(offset) *((volatile unsigned long *)(PxaRegsOffset + offset)) 
     12 
     13char * pWriteAddress; 
     14 
     15typedef struct tagDmaDesc 
     16{ 
     17        unsigned long DDADR; 
     18        unsigned long DSADR; 
     19        unsigned long DTADR; 
     20        unsigned long DCMD; 
     21} DmaDesc; 
     22 
     23#define BUFFSIZE (16 * 6 * 1024) 
     24 
     25char *pBuffer; 
     26char *pBufferPhys; 
     27 
     28DmaDesc *pDescs; 
     29DmaDesc * pDescsPhys; 
     30 
     31/* FILE FOPS */ 
     32static ssize_t audio_read_method (struct file *file, char *buf, size_t count, loff_t *offset); 
     33static ssize_t audio_write_method (struct file *file, const char *buf, size_t count, loff_t *offset); 
     34static int audio_ioctl_method (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg); 
     35static int audio_open_method (struct inode *inode, struct file *file); 
     36static int audio_release_method (struct inode *inode, struct file *file); 
     37 
     38 
     39#endif //__AUDIO_PXA_H_ 
     40 
  • /dev/null

    old new  
     1# 
     2# Misc strange devices 
     3# 
     4 
     5menu "PXA gpio driver" 
     6 
     7config GPIO 
     8        tristate "Device driver for PXA gpio" 
     9        depends on ARCH_PXA 
     10        ---help--- 
     11          This option enables device driver support for PXA gpio. 
     12 
     13          If unsure, say N. 
     14 
     15endmenu 
  • /dev/null

    old new  
     1# 
     2# Makefile for gpio driver. 
     3# 
     4 
     5obj-$(CONFIG_GPIO)      := gpio_driver.o 
  • /dev/null

    old new  
     1/* 
     2 *      PXA GPIO Driver 
     3 * 
     4 *      Copyright (C) 2007 Aeronix 
     5 * 
     6 *      This driver allows controls the gpios on the PXA processor 
     7 * 
     8 *      This program is free software; you can redistribute it and/or 
     9 *      modify it under the terms of the GNU General Public License 
     10 *      as published by the Free Software Foundation; either version 
     11 *      2 of the License, or (at your option) any later version. 
     12 * 
     13 */ 
     14 
     15#include <linux/module.h> 
     16#include <linux/kernel.h> 
     17#include <linux/proc_fs.h> 
     18#include <linux/fs.h> 
     19#include <linux/gpio-ioctl.h> 
     20#include <asm/uaccess.h> 
     21#include <linux/ioport.h> 
     22#include <asm/io.h> 
     23#include <asm/arch/pxa-regs.h> 
     24#include "gpio_driver.h" 
     25 
     26extern void kernel_restart(char *cmd); 
     27 
     28extern int pxa_gpio_mode( int gpio_mode ); 
     29extern int pxa_gpio_get_value(unsigned gpio); 
     30extern void pxa_gpio_set_value(unsigned gpio, int value); 
     31//extern void pxa_set_pwrmode(unsigned int nPwrMode); 
     32 
     33static void HandleWriteCameraFrameData(int nFrameBufferAddress) 
     34{ 
     35        unsigned long * pulStartOfFrameBufferLine = (unsigned long*)nFrameBufferAddress; 
     36        unsigned long * pulCurrentFrameBufferPosistion = pulStartOfFrameBufferLine; 
     37 
     38        unsigned long ulCICR0data = CICR0; 
     39        unsigned long ulCISRdata; 
     40        unsigned long ulCIBR0data; 
     41        unsigned long ulCIFRdata; 
     42 
     43        unsigned long ulPixelData; 
     44        unsigned int ulPrintCount = 0; 
     45 
     46        int nIgnore; 
     47 
     48        int nNumberOfLines = 0; 
     49        int nNumberOfPixels = 0; 
     50 
     51        printk(KERN_INFO "HandleWriteCameraFrameData 0x%lX:0x%lX\n",(unsigned long) pulStartOfFrameBufferLine,(unsigned long) CICR1); 
     52        ulCICR0data |= 0x10000000; 
     53 
     54        CICR0 = ulCICR0data; 
     55 
     56        //find start of frame 
     57        do 
     58        { 
     59                ulCISRdata = CISR; 
     60 
     61        }while((ulCISRdata & 0x10) == 0); 
     62 
     63        //writeback to clear sticky bit 
     64        CISR = ulCISRdata; 
     65 
     66 
     67        //find start of frame 
     68        do 
     69        { 
     70                ulCISRdata = CISR; 
     71 
     72                ulCIBR0data = CIBR0; 
     73 
     74        }while((ulCISRdata & 0x1000) == 0); 
     75 
     76        //writeback to clear sticky bit 
     77        CISR = ulCISRdata; 
     78 
     79 
     80        printk(KERN_INFO "Camera get frame data.\n"); 
     81 
     82 
     83        do 
     84        { 
     85                nNumberOfPixels = 0; 
     86 
     87                do 
     88                { 
     89                        do 
     90                        { 
     91                                ulCIFRdata = CIFR; 
     92 
     93                        }while((ulCIFRdata & 0xfc00) == 0); 
     94 
     95 
     96                        ulCIBR0data = CIBR0; 
     97 
     98                        ulPixelData = ((ulCIBR0data & 0xffff0000) >> 16) | ((ulCIBR0data & 0x0000ffff) << 16); 
     99 
     100                        ulPrintCount++; 
     101 
     102                        nIgnore = copy_to_user((u32 *) pulCurrentFrameBufferPosistion, &ulPixelData, sizeof(u32)); 
     103                        pulCurrentFrameBufferPosistion++; 
     104 
     105                        nNumberOfPixels += 2; 
     106 
     107                        ulCISRdata = CISR; 
     108 
     109                }while((ulCISRdata & 0x100) == 0); 
     110 
     111                //writeback to clear sticky bit 
     112                CISR = ulCISRdata & 0x100; 
     113 
     114                ulCISRdata = CISR; 
     115 
     116                nNumberOfLines++; 
     117 
     118        }while((ulCISRdata & 0x8) == 0); 
     119 
     120        printk(KERN_INFO "Camera %d:%d \n",nNumberOfPixels,nNumberOfLines); 
     121 
     122} 
     123 
     124static void SetPwmClockEnable(int nEnable) 
     125{ 
     126  pxa_set_cken(CKEN0_PWM0, nEnable); 
     127} 
     128 
     129static void SetPwmPrescale(int nPWM, int nPrescaleValue) 
     130{ 
     131   switch(nPWM) 
     132   { 
     133      case 0: 
     134       PWM_CTRL0 = (nPrescaleValue & 0x7F); 
     135       break; 
     136      case 1: 
     137       PWM_CTRL1 = (nPrescaleValue & 0x7F); 
     138       break; 
     139      case 2: 
     140       PWM_CTRL2 = (nPrescaleValue & 0x7F); 
     141       break; 
     142   } 
     143} 
     144 
     145static void SetPwmDutyCycle(int nPWM, int nDutyCycle) 
     146{ 
     147   switch(nPWM) 
     148   { 
     149     case 0: 
     150      PWM_PWDUTY0 = nDutyCycle & 0x7FF; 
     151      break; 
     152     case 1: 
     153      PWM_PWDUTY1 = nDutyCycle & 0x7FF; 
     154      break; 
     155     case 2: 
     156      PWM_PWDUTY2 = nDutyCycle & 0x7FF; 
     157      break; 
     158   } 
     159} 
     160 
     161static void SetPwmPeriod(int nPWM, int nPeriod) 
     162{ 
     163  switch(nPWM) 
     164  { 
     165    case 0: 
     166     PWM_PERVAL0 = nPeriod & 0x3FF; 
     167     break; 
     168    case 1: 
     169     PWM_PERVAL1 = nPeriod & 0x3FF; 
     170     break; 
     171    case 2: 
     172     PWM_PERVAL2 = nPeriod & 0x3FF; 
     173     break; 
     174  } 
     175} 
     176 
     177static void SetGpioMode(int nGpio, gpioMode gmMode) 
     178{ 
     179     int nGpioMode = nGpio; 
     180 
     181     switch(gmMode) 
     182     { 
     183       case GPIO_MODE_INPUT: 
     184                    nGpioMode |= GPIO_IN; 
     185                    pxa_gpio_mode(nGpioMode); 
     186 
     187                    if(nGpio < 32) 
     188                                GPDR0 &= ~GPIO_bit(nGpio); 
     189                        else if(nGpio < 64) 
     190                                GPDR1 &= ~GPIO_bit(nGpio); 
     191                        else if(nGpio < 96) 
     192                                GPDR2 &= ~GPIO_bit(nGpio); 
     193                        else if(nGpio < 128) 
     194                                GPDR3 &= ~GPIO_bit(nGpio); 
     195 
     196            break; 
     197 
     198       case GPIO_MODE_OUTPUT: 
     199                    nGpioMode |= GPIO_OUT; 
     200                    pxa_gpio_mode(nGpioMode); 
     201 
     202                    if(nGpio < 32) 
     203                                GPDR0 |= GPIO_bit(nGpio); 
     204                        else if(nGpio < 64) 
     205                                GPDR1 |= GPIO_bit(nGpio); 
     206                        else if(nGpio < 96) 
     207                                GPDR2 |= GPIO_bit(nGpio); 
     208                        else if(nGpio < 128) 
     209                                GPDR3 |= GPIO_bit(nGpio); 
     210 
     211            break; 
     212 
     213       case GPIO_MODE_ALT_FUNC_1_IN: 
     214            nGpioMode |= GPIO_ALT_FN_1_IN; 
     215                        pxa_gpio_mode(nGpioMode); 
     216            break; 
     217 
     218       case GPIO_MODE_ALT_FUNC_1_OUT: 
     219            nGpioMode |= GPIO_ALT_FN_1_OUT; 
     220                        pxa_gpio_mode(nGpioMode); 
     221            break; 
     222 
     223       case GPIO_MODE_ALT_FUNC_2_IN: 
     224            nGpioMode |= GPIO_ALT_FN_2_IN; 
     225                        pxa_gpio_mode(nGpioMode); 
     226            break; 
     227 
     228       case GPIO_MODE_ALT_FUNC_2_OUT: 
     229            nGpioMode |= GPIO_ALT_FN_2_OUT; 
     230                        pxa_gpio_mode(nGpioMode); 
     231            break; 
     232 
     233       case GPIO_MODE_ALT_FUNC_3_IN: 
     234            nGpioMode |= GPIO_ALT_FN_3_IN; 
     235                        pxa_gpio_mode(nGpioMode); 
     236            break; 
     237 
     238       case GPIO_MODE_ALT_FUNC_3_OUT: 
     239            nGpioMode |= GPIO_ALT_FN_3_OUT; 
     240                        pxa_gpio_mode(nGpioMode); 
     241          break; 
     242     }//end switch statement 
     243#if 0 
     244         printk(KERN_NOTICE "nGpioMode 0x%x \n",nGpioMode); 
     245 
     246         nRegData = GAFR0_L; 
     247         printk(KERN_NOTICE "GAFR0_L 0x%x \n",nRegData); 
     248         nRegData = GAFR0_U; 
     249         printk(KERN_NOTICE "GAFR0_U 0x%x \n",nRegData); 
     250 
     251         nRegData = GAFR1_L; 
     252         printk(KERN_NOTICE "GAFR1_L 0x%x \n",nRegData); 
     253         nRegData = GAFR1_U; 
     254         printk(KERN_NOTICE "GAFR1_U 0x%x \n",nRegData); 
     255 
     256         nRegData = GAFR2_L; 
     257         printk(KERN_NOTICE "GAFR2_L 0x%x \n",nRegData); 
     258         nRegData = GAFR2_U; 
     259         printk(KERN_NOTICE "GAFR2_U 0x%x \n",nRegData); 
     260 
     261         nRegData = GAFR3_L; 
     262         printk(KERN_NOTICE "GAFR3_L 0x%x \n",nRegData); 
     263         nRegData = GAFR3_U; 
     264         printk(KERN_NOTICE "GAFR3_U 0x%x \n",nRegData); 
     265 
     266     nRegData = GPDR0; 
     267         printk(KERN_NOTICE "GPDR0 0x%x \n",nRegData); 
     268 
     269     nRegData = GPDR1; 
     270         printk(KERN_NOTICE "GPDR1 0x%x \n",nRegData); 
     271 
     272         nRegData = GPDR2; 
     273         printk(KERN_NOTICE "GPDR2 0x%x \n",nRegData); 
     274 
     275         nRegData = GPDR3; 
     276         printk(KERN_NOTICE "GPDR3 0x%x \n",nRegData); 
     277#endif 
     278} 
     279 
     280 
     281static struct file_operations gpio_driver_fops = { 
     282                owner:                  THIS_MODULE, 
     283                llseek:                 no_llseek, 
     284                read:                   gpio_read_method, 
     285                write:          gpio_write_method, 
     286        ioctl:          gpio_ioctl_method, 
     287        open:           gpio_open_method, 
     288        release:        gpio_release_method, 
     289}; 
     290 
     291 
     292static int __init gpio_driver_init(void) 
     293{ 
     294        int rc; 
     295 
     296        printk(KERN_NOTICE "Register GPIO driver...\n"); 
     297        rc = register_chrdev(GPIO_MAJOR,"gpio",&gpio_driver_fops); 
     298 
     299        return rc; 
     300} 
     301 
     302static void __exit gpio_driver_exit(void) 
     303{ 
     304        printk(KERN_NOTICE "Remove GPIO driver...\n"); 
     305    unregister_chrdev(GPIO_MAJOR,"gpio"); 
     306 
     307 
     308} 
     309 
     310/* FILE FOPS */ 
     311static ssize_t gpio_read_method (struct file *file, char *buf, size_t count, loff_t *offset) 
     312{ 
     313  int ret = 0; 
     314 
     315  return ret; 
     316} 
     317 
     318static ssize_t gpio_write_method (struct file *file, const char *buf, size_t count, loff_t *offset) 
     319{ 
     320        int ret = 0; 
     321 
     322        return ret; 
     323} 
     324 
     325static unsigned long ulIoWriteAddress = 0; 
     326 
     327static int gpio_ioctl_method (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 
     328{ 
     329        int nRtnValue = 0; 
     330        int nVersion = GPIO_IOCTL_API_VERSION; 
     331        int nUserArg; 
     332 
     333        int nGpio; 
     334        int nValue; 
     335 
     336        int nIgnore; 
     337 
     338        nIgnore = copy_from_user(&nUserArg, (u32 *) arg, sizeof(int)); 
     339 
     340        switch(cmd) 
     341        { 
     342                case GPIO_DRV_GETVERSION: 
     343                        nIgnore = copy_to_user((u32 *) arg, &nVersion, sizeof(u32)); 
     344                        break; 
     345 
     346                case GPIO_DRV_SET_GPIO: 
     347                        nGpio = (nUserArg & 0xffff0000) >> 16; 
     348                        nValue  = (nUserArg & 0x00000001); 
     349 
     350                        //printk(KERN_NOTICE "gpio_ioctl_method pxa_gpio_set_value GPIO=%d, Value=0x%x...\n",nGpio,nValue); 
     351 
     352                        pxa_gpio_set_value(nGpio,nValue); 
     353 
     354                        break; 
     355                case GPIO_DRV_GET_GPIO: 
     356                        nGpio = (nUserArg & 0xffff0000) >> 16; 
     357 
     358                        nUserArg = (int)pxa_gpio_get_value(nGpio); 
     359 
     360//                      printk(KERN_NOTICE "gpio_ioctl_method pxa_gpio_get_value GPIO=%d, Value=0x%x...\n",nGpio,nUserArg); 
     361 
     362                        nIgnore = copy_to_user((u32 *) arg, &nUserArg, sizeof(u32)); 
     363                        break; 
     364 
     365                case GPIO_DRV_SET_MODE: 
     366                        nGpio = (nUserArg & 0xffff0000) >> 16; 
     367                        nValue  = (nUserArg & 0x0000ffff); 
     368 
     369                        //printk(KERN_NOTICE "gpio_ioctl_method pxa_gpio_mode GPIO=%d, Value=0x%x...\n",nGpio,nValue); 
     370 
     371                        SetGpioMode(nGpio, (gpioMode)nValue); 
     372                        break; 
     373 
     374        case GPIO_DRV_SET_PWM_PRESCALE: 
     375            nGpio = (nUserArg & 0xffff0000) >> 16; 
     376            nValue = (nUserArg & 0x0000ffff); 
     377            SetPwmPrescale(nGpio, nValue); 
     378            break; 
     379 
     380        case GPIO_DRV_SET_PWM_DUTYCYCLE: 
     381            nGpio = (nUserArg & 0xffff0000) >> 16; 
     382            nValue = (nUserArg & 0x0000ffff); 
     383            SetPwmDutyCycle(nGpio, nValue); 
     384            break; 
     385 
     386        case GPIO_DRV_SET_PWM_PERIOD: 
     387            nGpio = (nUserArg & 0xffff0000) >> 16; 
     388            nValue = (nUserArg & 0x0000ffff); 
     389            SetPwmPeriod(nGpio, nValue); 
     390            break; 
     391 
     392        case GPIO_DRV_SET_PWM_CLK_ENABLE: 
     393            SetPwmClockEnable(nUserArg); 
     394             break; 
     395 
     396                case GPIO_DRV_SET_PWRMODE: 
     397                        nUserArg &= 0x0f; 
     398 
     399                        printk(KERN_NOTICE "gpio_ioctl_method GPIO_DRV_SET_PWRMODE mode=0x%x...\n",nUserArg); 
     400 
     401                        asm( "mcr p14, 0, %0, c7, c0, 0" :: "r" (nUserArg) ); 
     402                        break; 
     403 
     404                case GPIO_DRV_SET_CLKCFG: 
     405                        nUserArg &= 0x0f; 
     406 
     407                        printk(KERN_NOTICE "gpio_ioctl_method GPIO_DRV_SET_CLKCFG mode=0x%x...\n",nUserArg); 
     408 
     409                        asm( "mcr p14, 0, %0, c6, c0, 0" :: "r" (nUserArg) ); 
     410                        break; 
     411 
     412                case GPIO_DRV_IO_READ: 
     413 
     414                        if(nUserArg < 0x80000000) 
     415                                nUserArg = __REG(nUserArg); 
     416 
     417                        nIgnore = copy_to_user((u32 *) arg, &nUserArg, sizeof(u32)); 
     418                        break; 
     419 
     420                case GPIO_DRV_SET_IO_WRITE_ADDRESS: 
     421                        if(nUserArg < 0x80000000)<