📄 sa1100_generic.c
字号:
/*====================================================================== Device driver for the PCMCIA control functionality of StrongARM SA-1100 microprocessors. The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The initial developer of the original code is John G. Dorsey <john+@cs.cmu.edu>. Portions created by John G. Dorsey are Copyright (C) 1999 John G. Dorsey. All Rights Reserved. Alternatively, the contents of this file may be used under the terms of the GNU Public License version 2 (the "GPL"), in which case the provisions of the GPL are applicable instead of the above. If you wish to allow the use of your version of this file only under the terms of the GPL and not to allow others to use your version of this file under the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under either the MPL or the GPL. ======================================================================*/#include <linux/module.h>#include <linux/init.h>#include <linux/config.h>#include <linux/cpufreq.h>#include <linux/delay.h>#include <linux/ioport.h>#include <linux/kernel.h>#include <linux/tqueue.h>#include <linux/timer.h>#include <linux/mm.h>#include <linux/notifier.h>#include <linux/proc_fs.h>#include <linux/version.h>#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/ss.h>#include <pcmcia/bus_ops.h>#include <asm/hardware.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/system.h>#include <asm/arch/assabet.h>#include "sa1100.h"#ifdef PCMCIA_DEBUGstatic int pc_debug;#endifMODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-1100 Socket Controller");/* This structure maintains housekeeping state for each socket, such * as the last known values of the card detect pins, or the Card Services * callback value associated with the socket: */static struct sa1100_pcmcia_socket sa1100_pcmcia_socket[SA1100_PCMCIA_MAX_SOCK];static int sa1100_pcmcia_socket_count;/* Returned by the low-level PCMCIA interface: */static struct pcmcia_low_level *pcmcia_low_level;/* Event poll timer structure */static struct timer_list poll_timer;/* Prototypes for routines which are used internally: */static int sa1100_pcmcia_driver_init(void);static void sa1100_pcmcia_driver_shutdown(void);static void sa1100_pcmcia_task_handler(void *data);static void sa1100_pcmcia_poll_event(unsigned long data);static void sa1100_pcmcia_interrupt(int irq, void *dev, struct pt_regs *regs);static struct tq_struct sa1100_pcmcia_task;#ifdef CONFIG_PROC_FSstatic int sa1100_pcmcia_proc_status(char *buf, char **start, off_t pos, int count, int *eof, void *data);#endif/* Prototypes for operations which are exported to the * new-and-impr^H^H^H^H^H^H^H^H^H^H in-kernel PCMCIA core: */static int sa1100_pcmcia_init(unsigned int sock);static int sa1100_pcmcia_suspend(unsigned int sock);static int sa1100_pcmcia_register_callback(unsigned int sock, void (*handler)(void *, unsigned int), void *info);static int sa1100_pcmcia_inquire_socket(unsigned int sock, socket_cap_t *cap);static int sa1100_pcmcia_get_status(unsigned int sock, u_int *value);static int sa1100_pcmcia_get_socket(unsigned int sock, socket_state_t *state);static int sa1100_pcmcia_set_socket(unsigned int sock, socket_state_t *state);static int sa1100_pcmcia_get_io_map(unsigned int sock, struct pccard_io_map *io);static int sa1100_pcmcia_set_io_map(unsigned int sock, struct pccard_io_map *io);static int sa1100_pcmcia_get_mem_map(unsigned int sock, struct pccard_mem_map *mem);static int sa1100_pcmcia_set_mem_map(unsigned int sock, struct pccard_mem_map *mem);#ifdef CONFIG_PROC_FSstatic void sa1100_pcmcia_proc_setup(unsigned int sock, struct proc_dir_entry *base);#endifstatic struct pccard_operations sa1100_pcmcia_operations = { sa1100_pcmcia_init, sa1100_pcmcia_suspend, sa1100_pcmcia_register_callback, sa1100_pcmcia_inquire_socket, sa1100_pcmcia_get_status, sa1100_pcmcia_get_socket, sa1100_pcmcia_set_socket, sa1100_pcmcia_get_io_map, sa1100_pcmcia_set_io_map, sa1100_pcmcia_get_mem_map, sa1100_pcmcia_set_mem_map,#ifdef CONFIG_PROC_FS sa1100_pcmcia_proc_setup#endif};#ifdef CONFIG_CPU_FREQ/* forward declaration */static struct notifier_block sa1100_pcmcia_notifier_block;#endif/* sa1100_pcmcia_driver_init() * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ * * This routine performs a basic sanity check to ensure that this * kernel has been built with the appropriate board-specific low-level * PCMCIA support, performs low-level PCMCIA initialization, registers * this socket driver with Card Services, and then spawns the daemon * thread which is the real workhorse of the socket driver. * * Please see linux/Documentation/arm/SA1100/PCMCIA for more information * on the low-level kernel interface. * * Returns: 0 on success, -1 on error */static int __init sa1100_pcmcia_driver_init(void){ servinfo_t info; struct pcmcia_init pcmcia_init; struct pcmcia_state state[SA1100_PCMCIA_MAX_SOCK]; struct pcmcia_state_array state_array; unsigned int i, clock; unsigned long mecr; printk(KERN_INFO "SA-1100 PCMCIA (CS release %s)\n", CS_RELEASE); CardServices(GetCardServicesInfo, &info); if(info.Revision!=CS_RELEASE_CODE){ printk(KERN_ERR "Card Services release codes do not match\n"); return -1; } if(machine_is_assabet()){#ifdef CONFIG_SA1100_ASSABET if(machine_has_neponset()){#ifdef CONFIG_ASSABET_NEPONSET pcmcia_low_level=&neponset_pcmcia_ops;#else printk(KERN_ERR "Card Services disabled: missing Neponset support\n"); return -1;#endif }else{ pcmcia_low_level=&assabet_pcmcia_ops; }#endif } else if (machine_is_freebird()) {#ifdef CONFIG_SA1100_FREEBIRD pcmcia_low_level = &freebird_pcmcia_ops;#endif } else if (machine_is_h3600()) {#ifdef CONFIG_SA1100_H3600 pcmcia_low_level = &h3600_pcmcia_ops;#endif } else if (machine_is_cerf()) {#ifdef CONFIG_SA1100_CERF pcmcia_low_level = &cerf_pcmcia_ops;#endif } else if (machine_is_graphicsclient()) {#ifdef CONFIG_SA1100_GRAPHICSCLIENT pcmcia_low_level = &gcplus_pcmcia_ops;#endif } else if (machine_is_xp860()) {#ifdef CONFIG_SA1100_XP860 pcmcia_low_level = &xp860_pcmcia_ops;#endif } else if (machine_is_yopy()) {#ifdef CONFIG_SA1100_YOPY pcmcia_low_level = &yopy_pcmcia_ops;#endif } else if (machine_is_pangolin()) {#ifdef CONFIG_SA1100_PANGOLIN pcmcia_low_level = &pangolin_pcmcia_ops;#endif } else if (machine_is_jornada720()) {#ifdef CONFIG_SA1100_JORNADA720 pcmcia_low_level = &jornada720_pcmcia_ops;#endif } else if(machine_is_pfs168()){#ifdef CONFIG_SA1100_PFS168 pcmcia_low_level=&pfs168_pcmcia_ops;#endif } else if(machine_is_flexanet()){#ifdef CONFIG_SA1100_FLEXANET pcmcia_low_level=&flexanet_pcmcia_ops;#endif } else if(machine_is_simpad()){#ifdef CONFIG_SA1100_SIMPAD pcmcia_low_level=&simpad_pcmcia_ops;#endif } else if(machine_is_graphicsmaster()) {#ifdef CONFIG_SA1100_GRAPHICSMASTER pcmcia_low_level=&graphicsmaster_pcmcia_ops;#endif } else if(machine_is_adsbitsy()) {#ifdef CONFIG_SA1100_ADSBITSY pcmcia_low_level=&adsbitsy_pcmcia_ops;#endif } else if(machine_is_stork()) {#ifdef CONFIG_SA1100_STORK pcmcia_low_level=&stork_pcmcia_ops;#endif } if (!pcmcia_low_level) { printk(KERN_ERR "This hardware is not supported by the SA1100 Card Service driver\n"); return -ENODEV; } pcmcia_init.handler=sa1100_pcmcia_interrupt; if((sa1100_pcmcia_socket_count=pcmcia_low_level->init(&pcmcia_init))<0){ printk(KERN_ERR "Unable to initialize kernel PCMCIA service.\n"); return -EIO; } state_array.size=sa1100_pcmcia_socket_count; state_array.state=state; if(pcmcia_low_level->socket_state(&state_array)<0){ printk(KERN_ERR "Unable to get PCMCIA status from kernel.\n"); return -EIO; } /* We initialize the MECR to default values here, because we are * not guaranteed to see a SetIOMap operation at runtime. */ mecr=0; clock = get_cclk_frequency() * 100; for(i=0; i<sa1100_pcmcia_socket_count; ++i){ sa1100_pcmcia_socket[i].k_state=state[i]; /* This is an interim fix. Apparently, SetSocket is no longer * called to initialize each socket (prior to the first detect * event). For now, we'll just manually set up the mask. */ sa1100_pcmcia_socket[i].cs_state.csc_mask=SS_DETECT; sa1100_pcmcia_socket[i].virt_io=(i==0)?PCMCIA_IO_0_BASE:PCMCIA_IO_1_BASE; sa1100_pcmcia_socket[i].phys_attr=_PCMCIAAttr(i); sa1100_pcmcia_socket[i].phys_mem=_PCMCIAMem(i); MECR_FAST_SET(mecr, i, 0); MECR_BSIO_SET(mecr, i, sa1100_pcmcia_mecr_bs(SA1100_PCMCIA_IO_ACCESS, clock)); MECR_BSA_SET(mecr, i, sa1100_pcmcia_mecr_bs(SA1100_PCMCIA_5V_MEM_ACCESS, clock)); MECR_BSM_SET(mecr, i, sa1100_pcmcia_mecr_bs(SA1100_PCMCIA_5V_MEM_ACCESS, clock)); sa1100_pcmcia_socket[i].speed_io=SA1100_PCMCIA_IO_ACCESS; sa1100_pcmcia_socket[i].speed_attr=SA1100_PCMCIA_5V_MEM_ACCESS; sa1100_pcmcia_socket[i].speed_mem=SA1100_PCMCIA_5V_MEM_ACCESS; } MECR=mecr;#ifdef CONFIG_CPU_FREQ if(cpufreq_register_notifier(&sa1100_pcmcia_notifier_block) < 0){ printk(KERN_ERR "Unable to register CPU frequency change notifier\n"); return -ENXIO; }#endif /* Only advertise as many sockets as we can detect: */ if(register_ss_entry(sa1100_pcmcia_socket_count, &sa1100_pcmcia_operations)<0){ printk(KERN_ERR "Unable to register socket service routine\n"); return -ENXIO; } /* Start the event poll timer. It will reschedule by itself afterwards. */ sa1100_pcmcia_poll_event(0); DEBUG(1, "sa1100: initialization complete\n"); return 0;} /* sa1100_pcmcia_driver_init() */module_init(sa1100_pcmcia_driver_init);/* sa1100_pcmcia_driver_shutdown() * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * Invokes the low-level kernel service to free IRQs associated with this * socket controller and reset GPIO edge detection. */static void __exit sa1100_pcmcia_driver_shutdown(void){ del_timer_sync(&poll_timer); unregister_ss_entry(&sa1100_pcmcia_operations);#ifdef CONFIG_CPU_FREQ cpufreq_unregister_notifier(&sa1100_pcmcia_notifier_block);#endif pcmcia_low_level->shutdown(); flush_scheduled_tasks(); DEBUG(1, "sa1100: shutdown complete\n");}module_exit(sa1100_pcmcia_driver_shutdown);/* sa1100_pcmcia_init() * ^^^^^^^^^^^^^^^^^^^^ * We perform all of the interesting initialization tasks in * sa1100_pcmcia_driver_init(). * * Returns: 0 */static int sa1100_pcmcia_init(unsigned int sock){ DEBUG(2, "%s(): initializing socket %u\n", __FUNCTION__, sock); return 0;}/* sa1100_pcmcia_suspend() * ^^^^^^^^^^^^^^^^^^^^^^^ * We don't currently perform any actions on a suspend. * * Returns: 0 */static int sa1100_pcmcia_suspend(unsigned int sock){ struct pcmcia_configure conf; int ret; DEBUG(2, "%s(): suspending socket %u\n", __FUNCTION__, sock); conf.sock = sock; conf.vcc = 0; conf.vpp = 0; conf.output = 0; conf.speaker = 0; conf.reset = 1; ret = pcmcia_low_level->configure_socket(&conf); if (ret == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -