浏览代码

Embedded GPLv2 license in drivers

yiyue.fang 12 年之前
父节点
当前提交
621fbdb90c
共有 49 个文件被更改,包括 3329 次插入2689 次删除
  1. 13 3
      components/drivers/i2c/i2c-bit-ops.c
  2. 13 3
      components/drivers/i2c/i2c_core.c
  3. 13 3
      components/drivers/i2c/i2c_dev.c
  4. 13 3
      components/drivers/include/drivers/alarm.h
  5. 13 3
      components/drivers/include/drivers/i2c-bit-ops.h
  6. 13 3
      components/drivers/include/drivers/i2c.h
  7. 13 3
      components/drivers/include/drivers/i2c_dev.h
  8. 13 3
      components/drivers/include/drivers/mmcsd_card.h
  9. 13 3
      components/drivers/include/drivers/mmcsd_cmd.h
  10. 13 3
      components/drivers/include/drivers/mmcsd_core.h
  11. 13 3
      components/drivers/include/drivers/mmcsd_host.h
  12. 13 3
      components/drivers/include/drivers/mtd_nand.h
  13. 13 3
      components/drivers/include/drivers/mtd_nor.h
  14. 13 3
      components/drivers/include/drivers/rtc.h
  15. 18 7
      components/drivers/include/drivers/sd.h
  16. 132 95
      components/drivers/include/drivers/sdio.h
  17. 24 15
      components/drivers/include/drivers/sdio_func_ids.h
  18. 13 3
      components/drivers/include/drivers/serial.h
  19. 13 3
      components/drivers/include/drivers/spi.h
  20. 35 12
      components/drivers/include/drivers/usb_device.h
  21. 87 43
      components/drivers/include/drivers/usb_host.h
  22. 13 3
      components/drivers/include/rtdevice.h
  23. 13 3
      components/drivers/mtd/mtd_nand.c
  24. 13 3
      components/drivers/mtd/mtd_nor.c
  25. 13 3
      components/drivers/rtc/alarm.c
  26. 13 3
      components/drivers/rtc/rtc.c
  27. 384 358
      components/drivers/sdio/block_dev.c
  28. 486 464
      components/drivers/sdio/mmcsd_core.c
  29. 561 534
      components/drivers/sdio/sd.c
  30. 1082 1041
      components/drivers/sdio/sdio.c
  31. 13 3
      components/drivers/serial/serial.c
  32. 13 3
      components/drivers/spi/spi_core.c
  33. 13 3
      components/drivers/spi/spi_dev.c
  34. 13 3
      components/drivers/src/completion.c
  35. 13 3
      components/drivers/src/dataqueue.c
  36. 13 3
      components/drivers/src/pipe.c
  37. 13 3
      components/drivers/src/ringbuffer.c
  38. 13 3
      components/drivers/usb/usbdevice/class/cdc.h
  39. 13 3
      components/drivers/usb/usbdevice/class/cdc_vcom.c
  40. 13 3
      components/drivers/usb/usbdevice/class/mstorage.c
  41. 13 3
      components/drivers/usb/usbdevice/class/mstorage.h
  42. 13 3
      components/drivers/usb/usbdevice/core/core.c
  43. 13 3
      components/drivers/usb/usbdevice/core/usbdevice.c
  44. 13 3
      components/drivers/usb/usbhost/class/adk.c
  45. 13 3
      components/drivers/usb/usbhost/class/adk.h
  46. 13 3
      components/drivers/usb/usbhost/core/core.c
  47. 13 3
      components/drivers/usb/usbhost/core/driver.c
  48. 13 3
      components/drivers/usb/usbhost/core/hub.c
  49. 13 3
      components/drivers/usb/usbhost/core/usbhost.c

+ 13 - 3
components/drivers/i2c/i2c-bit-ops.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author        Notes

+ 13 - 3
components/drivers/i2c/i2c_core.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author        Notes

+ 13 - 3
components/drivers/i2c/i2c_dev.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author        Notes

+ 13 - 3
components/drivers/include/drivers/alarm.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author            Notes

+ 13 - 3
components/drivers/include/drivers/i2c-bit-ops.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author        Notes

+ 13 - 3
components/drivers/include/drivers/i2c.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author        Notes

+ 13 - 3
components/drivers/include/drivers/i2c_dev.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author        Notes

+ 13 - 3
components/drivers/include/drivers/mmcsd_card.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author		Notes

+ 13 - 3
components/drivers/include/drivers/mmcsd_cmd.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author		Notes

+ 13 - 3
components/drivers/include/drivers/mmcsd_core.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author		Notes

+ 13 - 3
components/drivers/include/drivers/mmcsd_host.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author		Notes

+ 13 - 3
components/drivers/include/drivers/mtd_nand.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/include/drivers/mtd_nor.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, Shanghai Real-Thread Technology Co., Ltd
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/include/drivers/rtc.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 18 - 7
components/drivers/include/drivers/sd.h

@@ -1,19 +1,30 @@
-#ifndef __SD_H__
-#define __SD_H__
 /*
  * File      : sd.h
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
- * Date           Author		Notes
- * 2011-07-25     weety		first version
+ * Date           Author        Notes
+ * 2011-07-25     weety         first version
  */
 
+#ifndef __SD_H__
+#define __SD_H__
+
 #include <rtthread.h>
 #include <drivers/mmcsd_host.h>
 

+ 132 - 95
components/drivers/include/drivers/sdio.h

@@ -3,20 +3,28 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
- * Date           Author		Notes
- * 2012-01-15     weety		first version
+ * Date           Author        Notes
+ * 2012-01-15     weety         first version
  */
 
-
 #ifndef __SDIO_H__
 #define __SDIO_H__
 
-
 #include <rtthread.h>
 #include <drivers/mmcsd_host.h>
 #include <drivers/mmcsd_card.h>
@@ -30,100 +38,99 @@ extern "C" {
  * Card Common Control Registers (CCCR)
  */
 
-#define SDIO_REG_CCCR_CCCR_REV		0x00
+#define SDIO_REG_CCCR_CCCR_REV      0x00
 
-#define  SDIO_CCCR_REV_1_00	0	/* CCCR/FBR Version 1.00 */
-#define  SDIO_CCCR_REV_1_10	1	/* CCCR/FBR Version 1.10 */
-#define  SDIO_CCCR_REV_1_20	2	/* CCCR/FBR Version 1.20 */
+#define  SDIO_CCCR_REV_1_00 0   /* CCCR/FBR Version 1.00 */
+#define  SDIO_CCCR_REV_1_10 1   /* CCCR/FBR Version 1.10 */
+#define  SDIO_CCCR_REV_1_20 2   /* CCCR/FBR Version 1.20 */
 
-#define  SDIO_SDIO_REV_1_00	0	/* SDIO Spec Version 1.00 */
-#define  SDIO_SDIO_REV_1_10	1	/* SDIO Spec Version 1.10 */
-#define  SDIO_SDIO_REV_1_20	2	/* SDIO Spec Version 1.20 */
-#define  SDIO_SDIO_REV_2_00	3	/* SDIO Spec Version 2.00 */
+#define  SDIO_SDIO_REV_1_00 0   /* SDIO Spec Version 1.00 */
+#define  SDIO_SDIO_REV_1_10 1   /* SDIO Spec Version 1.10 */
+#define  SDIO_SDIO_REV_1_20 2   /* SDIO Spec Version 1.20 */
+#define  SDIO_SDIO_REV_2_00 3   /* SDIO Spec Version 2.00 */
 
-#define SDIO_REG_CCCR_SD_REV		0x01
+#define SDIO_REG_CCCR_SD_REV        0x01
 
-#define  SDIO_SD_REV_1_01	0	/* SD Physical Spec Version 1.01 */
-#define  SDIO_SD_REV_1_10	1	/* SD Physical Spec Version 1.10 */
-#define  SDIO_SD_REV_2_00	2	/* SD Physical Spec Version 2.00 */
+#define  SDIO_SD_REV_1_01   0   /* SD Physical Spec Version 1.01 */
+#define  SDIO_SD_REV_1_10   1   /* SD Physical Spec Version 1.10 */
+#define  SDIO_SD_REV_2_00   2   /* SD Physical Spec Version 2.00 */
 
-#define SDIO_REG_CCCR_IO_EN		0x02
-#define SDIO_REG_CCCR_IO_RDY		0x03
+#define SDIO_REG_CCCR_IO_EN         0x02
+#define SDIO_REG_CCCR_IO_RDY        0x03
 
-#define SDIO_REG_CCCR_INT_EN		0x04	/* Function/Master Interrupt Enable */
-#define SDIO_REG_CCCR_INT_PEND		0x05	/* Function Interrupt Pending */
+#define SDIO_REG_CCCR_INT_EN        0x04    /* Function/Master Interrupt Enable */
+#define SDIO_REG_CCCR_INT_PEND      0x05    /* Function Interrupt Pending */
 
-#define SDIO_REG_CCCR_IO_ABORT		0x06	/* function abort/card reset */
+#define SDIO_REG_CCCR_IO_ABORT      0x06    /* function abort/card reset */
 
-#define SDIO_REG_CCCR_BUS_IF		0x07	/* bus interface controls */
+#define SDIO_REG_CCCR_BUS_IF        0x07    /* bus interface controls */
 
-#define  SDIO_BUS_WIDTH_1BIT	0x00
-#define  SDIO_BUS_WIDTH_4BIT	0x02
-#define  SDIO_BUS_ECSI		0x20	/* Enable continuous SPI interrupt */
-#define  SDIO_BUS_SCSI		0x40	/* Support continuous SPI interrupt */
+#define  SDIO_BUS_WIDTH_1BIT        0x00
+#define  SDIO_BUS_WIDTH_4BIT        0x02
+#define  SDIO_BUS_ECSI              0x20    /* Enable continuous SPI interrupt */
+#define  SDIO_BUS_SCSI              0x40    /* Support continuous SPI interrupt */
 
-#define  SDIO_BUS_ASYNC_INT	0x20
+#define  SDIO_BUS_ASYNC_INT         0x20
 
-#define  SDIO_BUS_CD_DISABLE     0x80	/* disable pull-up on DAT3 (pin 1) */
+#define  SDIO_BUS_CD_DISABLE        0x80   /* disable pull-up on DAT3 (pin 1) */
 
-#define SDIO_REG_CCCR_CARD_CAPS		0x08
+#define SDIO_REG_CCCR_CARD_CAPS     0x08
 
-#define  SDIO_CCCR_CAP_SDC	0x01	/* can do CMD52 while data transfer */
-#define  SDIO_CCCR_CAP_SMB	0x02	/* can do multi-block xfers (CMD53) */
-#define  SDIO_CCCR_CAP_SRW	0x04	/* supports read-wait protocol */
-#define  SDIO_CCCR_CAP_SBS	0x08	/* supports suspend/resume */
-#define  SDIO_CCCR_CAP_S4MI	0x10	/* interrupt during 4-bit CMD53 */
-#define  SDIO_CCCR_CAP_E4MI	0x20	/* enable ints during 4-bit CMD53 */
-#define  SDIO_CCCR_CAP_LSC	0x40	/* low speed card */
-#define  SDIO_CCCR_CAP_4BLS	0x80	/* 4 bit low speed card */
+#define  SDIO_CCCR_CAP_SDC  0x01    /* can do CMD52 while data transfer */
+#define  SDIO_CCCR_CAP_SMB  0x02    /* can do multi-block xfers (CMD53) */
+#define  SDIO_CCCR_CAP_SRW  0x04    /* supports read-wait protocol */
+#define  SDIO_CCCR_CAP_SBS  0x08    /* supports suspend/resume */
+#define  SDIO_CCCR_CAP_S4MI 0x10    /* interrupt during 4-bit CMD53 */
+#define  SDIO_CCCR_CAP_E4MI 0x20    /* enable ints during 4-bit CMD53 */
+#define  SDIO_CCCR_CAP_LSC  0x40    /* low speed card */
+#define  SDIO_CCCR_CAP_4BLS 0x80    /* 4 bit low speed card */
 
-#define SDIO_REG_CCCR_CIS_PTR		0x09	/* common CIS pointer (3 bytes) */
+#define SDIO_REG_CCCR_CIS_PTR       0x09    /* common CIS pointer (3 bytes) */
 
 /* Following 4 regs are valid only if SBS is set */
-#define SDIO_REG_CCCR_BUS_SUSPEND	0x0c
-#define SDIO_REG_CCCR_FUNC_SEL		0x0d
-#define SDIO_REG_CCCR_EXEC_FLAG		0x0e
-#define SDIO_REG_CCCR_READY_FLAG	0x0f
+#define SDIO_REG_CCCR_BUS_SUSPEND   0x0c
+#define SDIO_REG_CCCR_FUNC_SEL      0x0d
+#define SDIO_REG_CCCR_EXEC_FLAG     0x0e
+#define SDIO_REG_CCCR_READY_FLAG    0x0f
 
-#define SDIO_REG_CCCR_FN0_BLKSIZE	0x10 /* 2bytes, 0x10~0x11 */
+#define SDIO_REG_CCCR_FN0_BLKSIZE   0x10 /* 2bytes, 0x10~0x11 */
 
-#define SDIO_REG_CCCR_POWER_CTRL		0x12
+#define SDIO_REG_CCCR_POWER_CTRL    0x12
 
-#define  SDIO_POWER_SMPC	0x01	/* Supports Master Power Control */
-#define  SDIO_POWER_EMPC	0x02	/* Enable Master Power Control */
+#define  SDIO_POWER_SMPC            0x01    /* Supports Master Power Control */
+#define  SDIO_POWER_EMPC            0x02    /* Enable Master Power Control */
 
-#define SDIO_REG_CCCR_SPEED		0x13
+#define SDIO_REG_CCCR_SPEED         0x13
 
-#define  SDIO_SPEED_SHS		0x01	/* Supports High-Speed mode */
-#define  SDIO_SPEED_EHS		0x02	/* Enable High-Speed mode */
+#define  SDIO_SPEED_SHS             0x01    /* Supports High-Speed mode */
+#define  SDIO_SPEED_EHS             0x02    /* Enable High-Speed mode */
 
 /*
  * Function Basic Registers (FBR)
  */
 
-#define SDIO_REG_FBR_BASE(f)	((f) * 0x100) /* base of function f's FBRs */
+#define SDIO_REG_FBR_BASE(f)    ((f) * 0x100) /* base of function f's FBRs */
 
-#define SDIO_REG_FBR_STD_FUNC_IF		0x00
+#define SDIO_REG_FBR_STD_FUNC_IF    0x00
 
-#define  SDIO_FBR_SUPPORTS_CSA	0x40	/* supports Code Storage Area */
-#define  SDIO_FBR_ENABLE_CSA	0x80	/* enable Code Storage Area */
+#define  SDIO_FBR_SUPPORTS_CSA      0x40    /* supports Code Storage Area */
+#define  SDIO_FBR_ENABLE_CSA        0x80    /* enable Code Storage Area */
 
-#define SDIO_REG_FBR_STD_IF_EXT	0x01
+#define SDIO_REG_FBR_STD_IF_EXT     0x01
 
-#define SDIO_REG_FBR_POWER		0x02
+#define SDIO_REG_FBR_POWER          0x02
 
-#define  SDIO_FBR_POWER_SPS	0x01	/* Supports Power Selection */
-#define  SDIO_FBR_POWER_EPS	0x02	/* Enable (low) Power Selection */
+#define  SDIO_FBR_POWER_SPS         0x01    /* Supports Power Selection */
+#define  SDIO_FBR_POWER_EPS         0x02    /* Enable (low) Power Selection */
 
-#define SDIO_REG_FBR_CIS		0x09	/* CIS pointer (3 bytes) */
+#define SDIO_REG_FBR_CIS            0x09    /* CIS pointer (3 bytes) */
 
 
-#define SDIO_REG_FBR_CSA		0x0C	/* CSA pointer (3 bytes) */
+#define SDIO_REG_FBR_CSA            0x0C    /* CSA pointer (3 bytes) */
 
-#define SDIO_REG_FBR_CSA_DATA	0x0F
-
-#define SDIO_REG_FBR_BLKSIZE	0x10	/* block size (2 bytes) */
+#define SDIO_REG_FBR_CSA_DATA       0x0F
 
+#define SDIO_REG_FBR_BLKSIZE        0x10    /* block size (2 bytes) */
 
 /* SDIO CIS Tuple code */
 #define CISTPL_NULL      0x00
@@ -142,55 +149,85 @@ extern "C" {
 #define SDIO_ANY_MAN_ID     0xffff
 #define SDIO_ANY_PROD_ID    0xffff
 
-struct rt_sdio_device_id {
-	rt_uint8_t   func_code;
-	rt_uint16_t  manufacturer;
-	rt_uint16_t  product;
+struct rt_sdio_device_id
+{
+    rt_uint8_t   func_code;
+    rt_uint16_t  manufacturer;
+    rt_uint16_t  product;
 };
 
-struct rt_sdio_driver {
-	char *name;
-	rt_int32_t (*probe)(struct rt_mmcsd_card *card);
-	rt_int32_t (*remove)(struct rt_mmcsd_card *card);
-	struct rt_sdio_device_id *id;
+struct rt_sdio_driver
+{
+    char *name;
+    rt_int32_t (*probe)(struct rt_mmcsd_card *card);
+    rt_int32_t (*remove)(struct rt_mmcsd_card *card);
+    struct rt_sdio_device_id *id;
 };
 
-
-
-rt_int32_t sdio_io_send_op_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr, rt_uint32_t 
-*cmd5_resp);
-rt_int32_t sdio_io_rw_direct(struct rt_mmcsd_card *card, rt_int32_t rw, rt_uint32_t fn,
-	rt_uint32_t reg_addr, rt_uint8_t *pdata, rt_uint8_t raw);
-rt_int32_t sdio_io_rw_extended(struct rt_mmcsd_card *card, rt_int32_t rw, rt_uint32_t fn,
-	rt_uint32_t addr, rt_int32_t op_code, rt_uint8_t *buf, rt_uint32_t blocks, rt_uint32_t blksize);
+rt_int32_t sdio_io_send_op_cond(struct rt_mmcsd_host *host,
+                                rt_uint32_t           ocr,
+                                rt_uint32_t          *cmd5_resp);
+rt_int32_t sdio_io_rw_direct(struct rt_mmcsd_card *card,
+                             rt_int32_t            rw,
+                             rt_uint32_t           fn,
+                             rt_uint32_t           reg_addr,
+                             rt_uint8_t           *pdata,
+                             rt_uint8_t            raw);
+rt_int32_t sdio_io_rw_extended(struct rt_mmcsd_card *card,
+                               rt_int32_t            rw,
+                               rt_uint32_t           fn,
+                               rt_uint32_t           addr,
+                               rt_int32_t            op_code,
+                               rt_uint8_t           *buf,
+                               rt_uint32_t           blocks,
+                               rt_uint32_t           blksize);
 rt_uint8_t sdio_io_readb(struct rt_sdio_function *func, 
-			 rt_uint32_t reg, rt_int32_t *err);
+                         rt_uint32_t              reg,
+                         rt_int32_t              *err);
 rt_int32_t sdio_io_writeb(struct rt_sdio_function *func, 
-			  rt_uint32_t reg, rt_uint8_t data);
-rt_uint16_t sdio_io_readw(struct rt_sdio_function *func, rt_uint32_t addr, rt_int32_t *err);
-rt_int32_t sdio_io_writew(struct rt_sdio_function *func, rt_uint16_t data, rt_uint32_t addr);
-rt_uint32_t sdio_io_readl(struct rt_sdio_function *func, rt_uint32_t addr, rt_int32_t *err);
-rt_int32_t sdio_io_writel(struct rt_sdio_function *func, rt_uint32_t data, rt_uint32_t addr);
+                          rt_uint32_t              reg,
+                          rt_uint8_t               data);
+rt_uint16_t sdio_io_readw(struct rt_sdio_function *func,
+                          rt_uint32_t              addr,
+                          rt_int32_t              *err);
+rt_int32_t sdio_io_writew(struct rt_sdio_function *func,
+                          rt_uint16_t              data,
+                          rt_uint32_t              addr);
+rt_uint32_t sdio_io_readl(struct rt_sdio_function *func,
+                          rt_uint32_t              addr,
+                          rt_int32_t              *err);
+rt_int32_t sdio_io_writel(struct rt_sdio_function *func,
+                          rt_uint32_t              data,
+                          rt_uint32_t              addr);
 rt_int32_t sdio_io_read_multi_fifo_b(struct rt_sdio_function *func, 
-				     rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t len);
+                                     rt_uint32_t              addr,
+                                     rt_uint8_t              *buf,
+                                     rt_uint32_t              len);
 rt_int32_t sdio_io_write_multi_fifo_b(struct rt_sdio_function *func, 
-				      rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t len);
+                                      rt_uint32_t              addr,
+                                      rt_uint8_t              *buf,
+                                      rt_uint32_t              len);
 rt_int32_t sdio_io_read_multi_incr_b(struct rt_sdio_function *func, 
-				     rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t len);
+                                     rt_uint32_t              addr,
+                                     rt_uint8_t              *buf,
+                                     rt_uint32_t              len);
 rt_int32_t sdio_io_write_multi_incr_b(struct rt_sdio_function *func, 
-				      rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t len);
+                                      rt_uint32_t              addr,
+                                      rt_uint8_t              *buf,
+                                      rt_uint32_t              len);
 rt_int32_t init_sdio(struct rt_mmcsd_host *host, rt_uint32_t ocr);
-rt_int32_t sdio_attach_irq(struct rt_sdio_function *func, rt_sdio_irq_handler_t *handler);
+rt_int32_t sdio_attach_irq(struct rt_sdio_function *func,
+                           rt_sdio_irq_handler_t   *handler);
 rt_int32_t sdio_detach_irq(struct rt_sdio_function *func);
 void sdio_irq_wakeup(struct rt_mmcsd_host *host);
 rt_int32_t sdio_enable_func(struct rt_sdio_function *func);
 rt_int32_t sdio_disable_func(struct rt_sdio_function *func);
-rt_int32_t sdio_set_block_size(struct rt_sdio_function *func, rt_uint32_t blksize);
+rt_int32_t sdio_set_block_size(struct rt_sdio_function *func,
+                               rt_uint32_t              blksize);
 rt_int32_t sdio_register_driver(struct rt_sdio_driver *driver);
 rt_int32_t sdio_unregister_driver(struct rt_sdio_driver *driver);
 void rt_sdio_init(void);
 
-
 #ifdef __cplusplus
 }
 #endif

+ 24 - 15
components/drivers/include/drivers/sdio_func_ids.h

@@ -3,34 +3,43 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
- * Date           Author		Notes
- * 2012-02-26     weety		first version
+ * Date           Author        Notes
+ * 2012-02-26     weety         first version
  */
  
 #ifndef __SDIO_FUNC_IDS_H__
 #define __SDIO_FUNC_IDS_H__
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* Standard SDIO Function Interfaces */
 
-#define SDIO_FUNC_CODE_NONE        0x00	/* Not a SDIO standard interface */
-#define SDIO_FUNC_CODE_UART        0x01	/* SDIO Standard UART */
-#define SDIO_FUNC_CODE_BT_A        0x02	/* SDIO Type-A for Bluetooth standard interface */
-#define SDIO_FUNC_CODE_BT_B        0x03	/* SDIO Type-B for Bluetooth standard interface */
-#define SDIO_FUNC_CODE_GPS         0x04	/* SDIO GPS standard interface */
-#define SDIO_FUNC_CODE_CAMERA      0x05	/* SDIO Camera standard interface */
-#define SDIO_FUNC_CODE_PHS         0x06	/* SDIO PHS standard interface */
-#define SDIO_FUNC_CODE_WLAN        0x07	/* SDIO WLAN interface */
-#define SDIO_FUNC_CODE_ATA         0x08	/* Embedded SDIO-ATA standard interface */
+#define SDIO_FUNC_CODE_NONE        0x00 /* Not a SDIO standard interface */
+#define SDIO_FUNC_CODE_UART        0x01 /* SDIO Standard UART */
+#define SDIO_FUNC_CODE_BT_A        0x02 /* SDIO Type-A for Bluetooth standard interface */
+#define SDIO_FUNC_CODE_BT_B        0x03 /* SDIO Type-B for Bluetooth standard interface */
+#define SDIO_FUNC_CODE_GPS         0x04 /* SDIO GPS standard interface */
+#define SDIO_FUNC_CODE_CAMERA      0x05 /* SDIO Camera standard interface */
+#define SDIO_FUNC_CODE_PHS         0x06 /* SDIO PHS standard interface */
+#define SDIO_FUNC_CODE_WLAN        0x07 /* SDIO WLAN interface */
+#define SDIO_FUNC_CODE_ATA         0x08 /* Embedded SDIO-ATA standard interface */
 
 /* manufacturer id, product io */
 

+ 13 - 3
components/drivers/include/drivers/serial.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/include/drivers/spi.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 35 - 12
components/drivers/include/drivers/usb_device.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes
@@ -175,15 +185,16 @@ typedef struct udev_msg* udev_msg_t;
 
 udevice_t rt_usbd_device_create(void);
 uconfig_t rt_usbd_config_create(void);
-uclass_t rt_usbd_class_create(udevice_t device, udev_desc_t dev_desc,
+uclass_t rt_usbd_class_create(udevice_t    device,
+                              udev_desc_t  dev_desc,
                               uclass_ops_t ops);
 uintf_t rt_usbd_interface_create(udevice_t device, uintf_handler_t handler);
 uep_t rt_usbd_endpoint_create(uep_desc_t ep_desc, udep_handler_t handler);
 ualtsetting_t rt_usbd_altsetting_create(rt_size_t desc_size);
 
 rt_err_t rt_usbd_core_init(void);
-rt_err_t rt_usb_device_init(const char* udc_name);
-rt_err_t rt_usbd_post_event(struct udev_msg* msg, rt_size_t size);
+rt_err_t rt_usb_device_init(const char *udc_name);
+rt_err_t rt_usbd_post_event(struct udev_msg *msg, rt_size_t size);
 rt_err_t rt_usbd_free_device(udevice_t device);
 rt_err_t rt_usbd_device_set_controller(udevice_t device, udcd_t dcd);
 rt_err_t rt_usbd_device_set_descriptor(udevice_t device, udev_desc_t dev_desc);
@@ -193,14 +204,20 @@ rt_err_t rt_usbd_config_add_class(uconfig_t cfg, uclass_t cls);
 rt_err_t rt_usbd_class_add_interface(uclass_t cls, uintf_t intf);
 rt_err_t rt_usbd_interface_add_altsetting(uintf_t intf, ualtsetting_t setting);
 rt_err_t rt_usbd_altsetting_add_endpoint(ualtsetting_t setting, uep_t ep);
-rt_err_t rt_usbd_altsetting_config_descriptor(ualtsetting_t setting, const void* desc, rt_off_t intf_pos);
+rt_err_t rt_usbd_altsetting_config_descriptor(ualtsetting_t setting,
+                                              const void   *desc,
+                                              rt_off_t      intf_pos);
 rt_err_t rt_usbd_set_config(udevice_t device, rt_uint8_t value);
 rt_err_t rt_usbd_set_altsetting(uintf_t intf, rt_uint8_t value);
 
 udevice_t rt_usbd_find_device(udcd_t dcd);
 uconfig_t rt_usbd_find_config(udevice_t device, rt_uint8_t value);
-uintf_t rt_usbd_find_interface(udevice_t device, rt_uint8_t value, uclass_t *pcls);
-uep_t rt_usbd_find_endpoint(udevice_t device, uclass_t* pcls, rt_uint8_t ep_addr);
+uintf_t rt_usbd_find_interface(udevice_t  device,
+                               rt_uint8_t value,
+                               uclass_t  *pcls);
+uep_t rt_usbd_find_endpoint(udevice_t  device,
+                            uclass_t  *pcls,
+                            rt_uint8_t ep_addr);
 
 uclass_t rt_usbd_class_mstorage_create(udevice_t device);
 uclass_t rt_usbd_class_cdc_create(udevice_t device);
@@ -218,14 +235,18 @@ rt_inline rt_err_t dcd_set_address(udcd_t dcd, rt_uint8_t value)
     return dcd->ops->set_address(value);
 }
 
-rt_inline rt_err_t dcd_clear_feature(udcd_t dcd, rt_uint16_t value, rt_uint16_t index)
+rt_inline rt_err_t dcd_clear_feature(udcd_t      dcd,
+                                     rt_uint16_t value,
+                                     rt_uint16_t index)
 {
     RT_ASSERT(dcd != RT_NULL);
 
     return dcd->ops->clear_feature(value, index);
 }
 
-rt_inline rt_err_t dcd_set_feature(udcd_t dcd, rt_uint8_t value, rt_uint16_t index)
+rt_inline rt_err_t dcd_set_feature(udcd_t      dcd,
+                                   rt_uint8_t  value,
+                                   rt_uint16_t index)
 {
     RT_ASSERT(dcd != RT_NULL);
 
@@ -275,7 +296,9 @@ rt_inline rt_err_t dcd_ep_read(udcd_t dcd, uep_t ep, void *buffer,
     return dcd->ops->ep_read(ep, buffer, size);
 }
 
-rt_inline rt_size_t dcd_ep_write(udcd_t dcd, uep_t ep, void *buffer,
+rt_inline rt_size_t dcd_ep_write(udcd_t    dcd,
+                                 uep_t     ep,
+                                 void     *buffer,
                                  rt_size_t size)
 {
     RT_ASSERT(dcd != RT_NULL);

+ 87 - 43
components/drivers/include/drivers/usb_host.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2011, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes
@@ -167,23 +177,27 @@ void rt_usb_hub_thread(void);
 uinst_t rt_usb_alloc_instance(void);
 rt_err_t rt_usb_attatch_instance(uinst_t uinst);
 rt_err_t rt_usb_detach_instance(uinst_t uinst);
-rt_err_t rt_usb_get_descriptor(uinst_t uinst, rt_uint8_t type, void* buffer, 
-    int nbytes);
+rt_err_t rt_usb_get_descriptor(uinst_t    uinst,
+                               rt_uint8_t type,
+                               void      *buffer, 
+                               int        nbytes);
 rt_err_t rt_usb_set_configure(uinst_t uinst, int config);
 rt_err_t rt_usb_set_address(uinst_t uinst);
 rt_err_t rt_usb_set_interface(uinst_t uinst, int intf);
 rt_err_t rt_usb_clear_feature(uinst_t uinst, int endpoint, int feature);
-rt_err_t rt_usb_get_interface_descriptor(ucfg_desc_t cfg_desc, int num, 
-    uintf_desc_t* intf_desc);
-rt_err_t rt_usb_get_endpoint_descriptor(uintf_desc_t intf_desc, int num, 
-    uep_desc_t* ep_desc);
+rt_err_t rt_usb_get_interface_descriptor(ucfg_desc_t   cfg_desc,
+                                         int           num,
+                                         uintf_desc_t *intf_desc);
+rt_err_t rt_usb_get_endpoint_descriptor(uintf_desc_t intf_desc,
+                                        int          num, 
+                                        uep_desc_t  *ep_desc);
 
 /* usb class driver interface */
 rt_err_t rt_usb_class_driver_init(void);
 rt_err_t rt_usb_class_driver_register(ucd_t drv);
 rt_err_t rt_usb_class_driver_unregister(ucd_t drv);
-rt_err_t rt_usb_class_driver_run(ucd_t drv, void* args);
-rt_err_t rt_usb_class_driver_stop(ucd_t drv, void* args);
+rt_err_t rt_usb_class_driver_run(ucd_t drv, void *args);
+rt_err_t rt_usb_class_driver_stop(ucd_t drv, void *args);
 ucd_t rt_usb_class_driver_find(int class_code, int subclass_code);
 
 /* usb class driver implement */
@@ -197,28 +211,39 @@ uprotocal_t rt_usb_hid_protocal_kbd(void);
 uprotocal_t rt_usb_hid_protocal_mouse(void);
 
 /* usb adk class driver interface */
-rt_err_t rt_usb_adk_set_string(const char* manufacturer, const char* model,
-    const char* description, const char* version, const char* uri, 
-    const char* serial);
+rt_err_t rt_usb_adk_set_string(const char *manufacturer,
+                               const char *model,
+                               const char *description,
+                               const char *version,
+                               const char *uri, 
+                               const char *serial);
 
 /* usb hub interface */
-rt_err_t rt_usb_hub_get_descriptor(uinst_t uinst, rt_uint8_t *buffer, 
-    rt_size_t size);
-rt_err_t rt_usb_hub_get_status(uinst_t uinst, rt_uint8_t* buffer);
-rt_err_t rt_usb_hub_get_port_status(uhubinst_t uhub, rt_uint16_t port, 
-    rt_uint8_t* buffer);
-rt_err_t rt_usb_hub_clear_port_feature(uhubinst_t uhub, rt_uint16_t port, 
-    rt_uint16_t feature);
-rt_err_t rt_usb_hub_set_port_feature(uhubinst_t uhub, rt_uint16_t port, 
-    rt_uint16_t feature);
+rt_err_t rt_usb_hub_get_descriptor(uinst_t     uinst,
+                                   rt_uint8_t *buffer, 
+                                   rt_size_t   size);
+rt_err_t rt_usb_hub_get_status(uinst_t uinst, rt_uint8_t *buffer);
+rt_err_t rt_usb_hub_get_port_status(uhubinst_t  uhub,
+                                    rt_uint16_t port, 
+                                    rt_uint8_t *buffer);
+rt_err_t rt_usb_hub_clear_port_feature(uhubinst_t  uhub,
+                                       rt_uint16_t port, 
+                                       rt_uint16_t feature);
+rt_err_t rt_usb_hub_set_port_feature(uhubinst_t  uhub,
+                                     rt_uint16_t port, 
+                                     rt_uint16_t feature);
 rt_err_t rt_usb_hub_reset_port(uhubinst_t uhub, rt_uint16_t port);
 rt_err_t rt_usb_post_event(struct uhost_msg* msg, rt_size_t size);
 
 /* usb host controller driver interface */
-rt_inline rt_err_t rt_usb_hcd_alloc_pipe(uhcd_t hcd, upipe_t* pipe, 
-    uifinst_t ifinst, uep_desc_t ep, func_callback callback)
+rt_inline rt_err_t rt_usb_hcd_alloc_pipe(uhcd_t        hcd,
+                                         upipe_t      *pipe, 
+                                         uifinst_t     ifinst,
+                                         uep_desc_t    ep,
+                                         func_callback callback)
 {
-    if(ifinst == RT_NULL) return -RT_EIO;
+    if (ifinst == RT_NULL)
+        return -RT_EIO;
 
     return hcd->ops->alloc_pipe(pipe, ifinst, ep, callback);
 }
@@ -230,40 +255,59 @@ rt_inline rt_err_t rt_usb_hcd_free_pipe(uhcd_t hcd, upipe_t pipe)
     return hcd->ops->free_pipe(pipe);
 }
 
-rt_inline int rt_usb_hcd_bulk_xfer(uhcd_t hcd, upipe_t pipe, void* buffer, 
-    int nbytes, int timeout)
+rt_inline int rt_usb_hcd_bulk_xfer(uhcd_t  hcd,
+                                   upipe_t pipe,
+                                   void   *buffer, 
+                                   int     nbytes,
+                                   int     timeout)
 {
-    if(pipe == RT_NULL) return -1;
-    if(pipe->ifinst == RT_NULL) return -1;
-    if(pipe->ifinst->uinst == RT_NULL) return -1;    
-    if(pipe->ifinst->uinst->status == UINST_STATUS_IDLE) 
+    if (pipe == RT_NULL)
+        return -1;
+    if (pipe->ifinst == RT_NULL)
+        return -1;
+    if (pipe->ifinst->uinst == RT_NULL)
+        return -1;    
+    if (pipe->ifinst->uinst->status == UINST_STATUS_IDLE) 
         return -1;
 
     return hcd->ops->bulk_xfer(pipe, buffer, nbytes, timeout);
 }
 
-rt_inline int rt_usb_hcd_control_xfer(uhcd_t hcd, uinst_t uinst, ureq_t setup, 
-    void* buffer, int nbytes, int timeout)
+rt_inline int rt_usb_hcd_control_xfer(uhcd_t  hcd,
+                                      uinst_t uinst,
+                                      ureq_t  setup, 
+                                      void   *buffer,
+                                      int     nbytes,
+                                      int     timeout)
 {
-    if(uinst->status == UINST_STATUS_IDLE) return -1;
+    if (uinst->status == UINST_STATUS_IDLE)
+        return -1;
 
     return hcd->ops->ctl_xfer(uinst, setup, buffer, nbytes, timeout);
 }
 
-rt_inline int rt_usb_hcd_int_xfer(uhcd_t hcd, upipe_t pipe, void* buffer, 
-    int nbytes, int timeout)
+rt_inline int rt_usb_hcd_int_xfer(uhcd_t  hcd,
+                                  upipe_t pipe,
+                                  void   *buffer, 
+                                  int     nbytes,
+                                  int     timeout)
 {    
-    if(pipe == RT_NULL) return -1;
-    if(pipe->ifinst == RT_NULL) return -1;
-    if(pipe->ifinst->uinst == RT_NULL) return -1;    
-    if(pipe->ifinst->uinst->status == UINST_STATUS_IDLE) 
+    if (pipe == RT_NULL)
+        return -1;
+    if (pipe->ifinst == RT_NULL)
+        return -1;
+    if (pipe->ifinst->uinst == RT_NULL)
+        return -1;    
+    if (pipe->ifinst->uinst->status == UINST_STATUS_IDLE) 
         return -1;
 
     return hcd->ops->int_xfer(pipe, buffer, nbytes, timeout);
 }
 
-rt_inline rt_err_t rt_usb_hcd_hub_control(uhcd_t hcd, rt_uint16_t port, 
-    rt_uint8_t cmd, void *args)
+rt_inline rt_err_t rt_usb_hcd_hub_control(uhcd_t      hcd,
+                                          rt_uint16_t port, 
+                                          rt_uint8_t  cmd,
+                                          void       *args)
 {    
     return hcd->ops->hub_ctrl(port, cmd, args);
 }

+ 13 - 3
components/drivers/include/rtdevice.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/mtd/mtd_nand.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/mtd/mtd_nor.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, Shanghai Real-Thread Technology Co., Ltd
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/rtc/alarm.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author            Notes

+ 13 - 3
components/drivers/rtc/rtc.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 384 - 358
components/drivers/sdio/block_dev.c

@@ -3,13 +3,23 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
- * Date           Author		Notes
- * 2011-07-25     weety		first version
+ * Date           Author        Notes
+ * 2011-07-25     weety     first version
  */
 
 #include <rtthread.h>
@@ -21,11 +31,11 @@ static rt_list_t blk_devices;
 
 struct mmcsd_blk_device
 {
-	struct rt_mmcsd_card *card;
-	rt_list_t list;
-	struct rt_device dev;
-	struct dfs_partition part;
-	struct rt_device_blk_geometry geometry;
+    struct rt_mmcsd_card *card;
+    rt_list_t list;
+    struct rt_device dev;
+    struct dfs_partition part;
+    struct rt_device_blk_geometry geometry;
 };
 
 #ifndef RT_MMCSD_MAX_PARTITION
@@ -34,409 +44,425 @@ struct mmcsd_blk_device
 
 static rt_int32_t mmcsd_num_wr_blocks(struct rt_mmcsd_card *card)
 {
-	rt_int32_t err;
-	rt_uint32_t blocks;
+    rt_int32_t err;
+    rt_uint32_t blocks;
 
-	struct rt_mmcsd_req req;
-	struct rt_mmcsd_cmd cmd;
-	struct rt_mmcsd_data data;
-	rt_uint32_t timeout_us;
+    struct rt_mmcsd_req req;
+    struct rt_mmcsd_cmd cmd;
+    struct rt_mmcsd_data data;
+    rt_uint32_t timeout_us;
 
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
 
-	cmd.cmd_code = APP_CMD;
-	cmd.arg = card->rca << 16;
-	cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_AC;
+    cmd.cmd_code = APP_CMD;
+    cmd.arg = card->rca << 16;
+    cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_AC;
 
-	err = mmcsd_send_cmd(card->host, &cmd, 0);
-	if (err)
-		return -RT_ERROR;
-	if (!controller_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
-		return -RT_ERROR;
+    err = mmcsd_send_cmd(card->host, &cmd, 0);
+    if (err)
+        return -RT_ERROR;
+    if (!controller_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
+        return -RT_ERROR;
 
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
 
-	cmd.cmd_code = SD_APP_SEND_NUM_WR_BLKS;
-	cmd.arg = 0;
-	cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
+    cmd.cmd_code = SD_APP_SEND_NUM_WR_BLKS;
+    cmd.arg = 0;
+    cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
 
-	rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
+    rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
 
-	data.timeout_ns = card->tacc_ns * 100;
-	data.timeout_clks = card->tacc_clks * 100;
+    data.timeout_ns = card->tacc_ns * 100;
+    data.timeout_clks = card->tacc_clks * 100;
 
-	timeout_us = data.timeout_ns / 1000;
-	timeout_us += data.timeout_clks * 1000 /
-		(card->host->io_cfg.clock / 1000);
+    timeout_us = data.timeout_ns / 1000;
+    timeout_us += data.timeout_clks * 1000 /
+        (card->host->io_cfg.clock / 1000);
 
-	if (timeout_us > 100000) 
-	{
-		data.timeout_ns = 100000000;
-		data.timeout_clks = 0;
-	}
+    if (timeout_us > 100000) 
+    {
+        data.timeout_ns = 100000000;
+        data.timeout_clks = 0;
+    }
 
-	data.blksize = 4;
-	data.blks = 1;
-	data.flags = DATA_DIR_READ;
-	data.buf = &blocks;
+    data.blksize = 4;
+    data.blks = 1;
+    data.flags = DATA_DIR_READ;
+    data.buf = &blocks;
 
-	rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
+    rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
 
-	req.cmd = &cmd;
-	req.data = &data;
+    req.cmd = &cmd;
+    req.data = &data;
 
-	mmcsd_send_request(card->host, &req);
+    mmcsd_send_request(card->host, &req);
 
-	if (cmd.err || data.err)
-		return -RT_ERROR;
+    if (cmd.err || data.err)
+        return -RT_ERROR;
 
-	return blocks;
+    return blocks;
 }
 
-static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card, rt_uint32_t sector, void *buf, rt_size_t blks, rt_uint8_t dir)
+static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card,
+                                 rt_uint32_t           sector,
+                                 void                 *buf,
+                                 rt_size_t             blks,
+                                 rt_uint8_t            dir)
 {
-	void *aligned_buf;
-	
-	struct rt_mmcsd_cmd  cmd, stop;
-	struct rt_mmcsd_data  data;
-	struct rt_mmcsd_req  req;
-	struct rt_mmcsd_host *host = card->host;
-	rt_uint32_t r_cmd, w_cmd;
-
-	mmcsd_host_lock(host);
-	rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
-	rt_memset(&stop, 0, sizeof(struct rt_mmcsd_cmd));
-	rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
-	req.cmd = &cmd;
-	req.data = &data;
-	
-	cmd.arg = sector;
-	if (!(card->flags & CARD_FLAG_SDHC)) 
-	{
-		cmd.arg <<= 9;
-	}
-	cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
-
-	data.blksize = SECTOR_SIZE;
-	data.blks  = blks;
-
-	if (blks > 1) 
-	{
-		if (!controller_is_spi(card->host) || !dir)
-		{
-			req.stop = &stop;
-			stop.cmd_code = STOP_TRANSMISSION;
-			stop.arg = 0;
-			stop.flags = RESP_SPI_R1B | RESP_R1B | CMD_AC;
-		}
-		r_cmd = READ_MULTIPLE_BLOCK;
-		w_cmd = WRITE_MULTIPLE_BLOCK;
-	}
-	else
-	{
-		req.stop = NULL;
-		r_cmd = READ_SINGLE_BLOCK;
-		w_cmd = WRITE_BLOCK;
-	}
-
-	if (!dir) 
-	{
-		cmd.cmd_code = r_cmd;
-		data.flags |= DATA_DIR_READ;
-	}
-	else
-	{
-		cmd.cmd_code = w_cmd;
-		data.flags |= DATA_DIR_WRITE;
-	}
-
-	mmcsd_set_data_timeout(&data, card);
-	data.buf = buf;
-	mmcsd_send_request(host, &req);
-
-	if (!controller_is_spi(card->host) && dir != 0) 
-	{
-		do 
-		{
-			rt_int32_t err;
-
-			cmd.cmd_code = SEND_STATUS;
-			cmd.arg = card->rca << 16;
-			cmd.flags = RESP_R1 | CMD_AC;
-			err = mmcsd_send_cmd(card->host, &cmd, 5);
-			if (err) 
-			{
-				rt_kprintf("error %d requesting status\n", err);
-				break;
-			}
-			/*
-			 * Some cards mishandle the status bits,
-			 * so make sure to check both the busy
-			 * indication and the card state.
-			 */
-		 } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
-			(R1_CURRENT_STATE(cmd.resp[0]) == 7));
-	}
-
-	mmcsd_host_unlock(host);
-
-	if (cmd.err || data.err || stop.err) 
-	{
-		rt_kprintf("mmcsd request blocks error\n");
-		rt_kprintf("%d,%d,%d, 0x%08x,0x%08x\n", cmd.err, data.err, stop.err, data.flags, sector);
-
-		return -RT_ERROR;
-	}
-
-	return RT_EOK;
+    void *aligned_buf;
+    
+    struct rt_mmcsd_cmd  cmd, stop;
+    struct rt_mmcsd_data  data;
+    struct rt_mmcsd_req  req;
+    struct rt_mmcsd_host *host = card->host;
+    rt_uint32_t r_cmd, w_cmd;
+
+    mmcsd_host_lock(host);
+    rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&stop, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
+    req.cmd = &cmd;
+    req.data = &data;
+    
+    cmd.arg = sector;
+    if (!(card->flags & CARD_FLAG_SDHC)) 
+    {
+        cmd.arg <<= 9;
+    }
+    cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
+
+    data.blksize = SECTOR_SIZE;
+    data.blks  = blks;
+
+    if (blks > 1) 
+    {
+        if (!controller_is_spi(card->host) || !dir)
+        {
+            req.stop = &stop;
+            stop.cmd_code = STOP_TRANSMISSION;
+            stop.arg = 0;
+            stop.flags = RESP_SPI_R1B | RESP_R1B | CMD_AC;
+        }
+        r_cmd = READ_MULTIPLE_BLOCK;
+        w_cmd = WRITE_MULTIPLE_BLOCK;
+    }
+    else
+    {
+        req.stop = NULL;
+        r_cmd = READ_SINGLE_BLOCK;
+        w_cmd = WRITE_BLOCK;
+    }
+
+    if (!dir) 
+    {
+        cmd.cmd_code = r_cmd;
+        data.flags |= DATA_DIR_READ;
+    }
+    else
+    {
+        cmd.cmd_code = w_cmd;
+        data.flags |= DATA_DIR_WRITE;
+    }
+
+    mmcsd_set_data_timeout(&data, card);
+    data.buf = buf;
+    mmcsd_send_request(host, &req);
+
+    if (!controller_is_spi(card->host) && dir != 0) 
+    {
+        do 
+        {
+            rt_int32_t err;
+
+            cmd.cmd_code = SEND_STATUS;
+            cmd.arg = card->rca << 16;
+            cmd.flags = RESP_R1 | CMD_AC;
+            err = mmcsd_send_cmd(card->host, &cmd, 5);
+            if (err) 
+            {
+                rt_kprintf("error %d requesting status\n", err);
+                break;
+            }
+            /*
+             * Some cards mishandle the status bits,
+             * so make sure to check both the busy
+             * indication and the card state.
+             */
+         } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
+            (R1_CURRENT_STATE(cmd.resp[0]) == 7));
+    }
+
+    mmcsd_host_unlock(host);
+
+    if (cmd.err || data.err || stop.err) 
+    {
+        rt_kprintf("mmcsd request blocks error\n");
+        rt_kprintf("%d,%d,%d, 0x%08x,0x%08x\n",
+                   cmd.err, data.err, stop.err, data.flags, sector);
+
+        return -RT_ERROR;
+    }
+
+    return RT_EOK;
 }
 
 static rt_err_t rt_mmcsd_init(rt_device_t dev)
 {
-	return RT_EOK;
+    return RT_EOK;
 }
 
 static rt_err_t rt_mmcsd_open(rt_device_t dev, rt_uint16_t oflag)
 {
-	return RT_EOK;
+    return RT_EOK;
 }
 
 static rt_err_t rt_mmcsd_close(rt_device_t dev)
 {
-	return RT_EOK;
+    return RT_EOK;
 }
 
 static rt_err_t rt_mmcsd_control(rt_device_t dev, rt_uint8_t cmd, void *args)
 {
-	struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data;
-	switch (cmd)
-	{
-	case RT_DEVICE_CTRL_BLK_GETGEOME:
-		rt_memcpy(args, &blk_dev->geometry, sizeof(struct rt_device_blk_geometry));
-		break;
-	default:
-		break;
-	}
-	return RT_EOK;
+    struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data;
+    switch (cmd)
+    {
+    case RT_DEVICE_CTRL_BLK_GETGEOME:
+        rt_memcpy(args, &blk_dev->geometry, sizeof(struct rt_device_blk_geometry));
+        break;
+    default:
+        break;
+    }
+    return RT_EOK;
 }
 
-static rt_size_t rt_mmcsd_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
+static rt_size_t rt_mmcsd_read(rt_device_t dev,
+                               rt_off_t    pos,
+                               void       *buffer,
+                               rt_size_t   size)
 {
-	rt_err_t err;
-	struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data;
-	struct dfs_partition *part = &blk_dev->part;
-
-	if (dev == RT_NULL)
-	{
-		rt_set_errno(-DFS_STATUS_EINVAL);
-		return 0;
-	}
-
-	rt_sem_take(part->lock, RT_WAITING_FOREVER);
-	err = rt_mmcsd_req_blk(blk_dev->card, part->offset + pos, buffer, size, 0);
-	rt_sem_release(part->lock);
-
-	/* the length of reading must align to SECTOR SIZE */
-	if (err) 
-	{
-		rt_set_errno(-DFS_STATUS_EIO);
-		return 0;
-	}
-	return size;
+    rt_err_t err;
+    struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data;
+    struct dfs_partition *part = &blk_dev->part;
+
+    if (dev == RT_NULL)
+    {
+        rt_set_errno(-DFS_STATUS_EINVAL);
+
+        return 0;
+    }
+
+    rt_sem_take(part->lock, RT_WAITING_FOREVER);
+    err = rt_mmcsd_req_blk(blk_dev->card, part->offset + pos, buffer, size, 0);
+    rt_sem_release(part->lock);
+
+    /* the length of reading must align to SECTOR SIZE */
+    if (err) 
+    {
+        rt_set_errno(-DFS_STATUS_EIO);
+        return 0;
+    }
+    return size;
 }
 
-static rt_size_t rt_mmcsd_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
+static rt_size_t rt_mmcsd_write(rt_device_t dev,
+                                rt_off_t    pos,
+                                const void *buffer,
+                                rt_size_t   size)
 {
-	rt_err_t err;
-	struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data;
-	struct dfs_partition *part = &blk_dev->part;
-
-	if (dev == RT_NULL)
-	{
-		rt_set_errno(-DFS_STATUS_EINVAL);
-		return 0;
-	}
-
-	rt_sem_take(part->lock, RT_WAITING_FOREVER);
-	err = rt_mmcsd_req_blk(blk_dev->card, part->offset + pos, (void *)buffer, size, 1);
-	rt_sem_release(part->lock);
-
-	/* the length of reading must align to SECTOR SIZE */
-	if (err) 
-	{
-		rt_set_errno(-DFS_STATUS_EIO);
-		return 0;
-	}
-	return size;
+    rt_err_t err;
+    struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data;
+    struct dfs_partition *part = &blk_dev->part;
+
+    if (dev == RT_NULL)
+    {
+        rt_set_errno(-DFS_STATUS_EINVAL);
+
+        return 0;
+    }
+
+    rt_sem_take(part->lock, RT_WAITING_FOREVER);
+    err = rt_mmcsd_req_blk(blk_dev->card, part->offset + pos, (void *)buffer, size, 1);
+    rt_sem_release(part->lock);
+
+    /* the length of reading must align to SECTOR SIZE */
+    if (err) 
+    {
+        rt_set_errno(-DFS_STATUS_EIO);
+
+        return 0;
+    }
+    return size;
 }
 
 static rt_int32_t mmcsd_set_blksize(struct rt_mmcsd_card *card)
 {
-	struct rt_mmcsd_cmd cmd;
-	int err;
-
-	/* Block-addressed cards ignore MMC_SET_BLOCKLEN. */
-	if (card->flags & CARD_FLAG_SDHC)
-		return 0;
-
-	mmcsd_host_lock(card->host);
-	cmd.cmd_code = SET_BLOCKLEN;
-	cmd.arg = 512;
-	cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_AC;
-	err = mmcsd_send_cmd(card->host, &cmd, 5);
-	mmcsd_host_unlock(card->host);
-
-	if (err) 
-	{
-		rt_kprintf("MMCSD: unable to set block size to %d: %d\n", cmd.arg, err);
-		return -RT_ERROR;
-	}
-
-	return 0;
+    struct rt_mmcsd_cmd cmd;
+    int err;
+
+    /* Block-addressed cards ignore MMC_SET_BLOCKLEN. */
+    if (card->flags & CARD_FLAG_SDHC)
+        return 0;
+
+    mmcsd_host_lock(card->host);
+    cmd.cmd_code = SET_BLOCKLEN;
+    cmd.arg = 512;
+    cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_AC;
+    err = mmcsd_send_cmd(card->host, &cmd, 5);
+    mmcsd_host_unlock(card->host);
+
+    if (err) 
+    {
+        rt_kprintf("MMCSD: unable to set block size to %d: %d\n", cmd.arg, err);
+
+        return -RT_ERROR;
+    }
+
+    return 0;
 }
 
 rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
 {
-	rt_int32_t err = 0;
-	rt_uint8_t i, status;
-	rt_uint8_t *sector;
-	char dname[4];
-	char sname[8];
-	struct mmcsd_blk_device *blk_dev = RT_NULL;
-
-	err = mmcsd_set_blksize(card);
-	if(err) 
-	{
-		return err;
-	}
-
-	/* get the first sector to read partition table */
-	sector = (rt_uint8_t *) rt_malloc(SECTOR_SIZE);
-	if (sector == RT_NULL)
-	{
-		rt_kprintf("allocate partition sector buffer failed\n");
-		return -RT_ENOMEM;
-	}
-
-	status = rt_mmcsd_req_blk(card, 0, sector, 1, 0);
-	if (status == RT_EOK)
-	{
-		for(i=0; i < RT_MMCSD_MAX_PARTITION; i++)
-		{
-			blk_dev = rt_malloc(sizeof(struct mmcsd_blk_device));
-			if (!blk_dev) 
-			{
-				rt_kprintf("mmcsd:malloc mem failde\n");
-				break;
-			}
-			rt_memset((void *)blk_dev, 0, sizeof(struct mmcsd_blk_device));
-			/* get the first partition */
-			status = dfs_filesystem_get_partition(&blk_dev->part, sector, i);
-			if (status == RT_EOK)
-			{
-				rt_snprintf(dname, 4, "sd%d",  i);
-				rt_snprintf(sname, 8, "sem_sd%d",  i);
-				blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
-	
-				/* register mmcsd device */
-				blk_dev->dev.type = RT_Device_Class_Block;					
-				blk_dev->dev.init = rt_mmcsd_init;
-				blk_dev->dev.open = rt_mmcsd_open;
-				blk_dev->dev.close = rt_mmcsd_close;
-				blk_dev->dev.read = rt_mmcsd_read;
-				blk_dev->dev.write = rt_mmcsd_write;
-				blk_dev->dev.control = rt_mmcsd_control;
-				blk_dev->dev.user_data = blk_dev;
-
-				blk_dev->card = card;
-				
-				blk_dev->geometry.bytes_per_sector = 1<<9;
-				blk_dev->geometry.block_size = card->card_blksize;
-				blk_dev->geometry.sector_count = blk_dev->part.size;
-	
-				rt_device_register(&blk_dev->dev, dname,
-					RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
-				rt_list_insert_after(&blk_devices, &blk_dev->list);
-			}
-			else
-			{
-				if(i == 0)
-				{
-					/* there is no partition table */
-					blk_dev->part.offset = 0;
-					blk_dev->part.size   = 0;
-					blk_dev->part.lock = rt_sem_create("sem_sd0", 1, RT_IPC_FLAG_FIFO);
-	
-					/* register mmcsd device */
-					blk_dev->dev.type  = RT_Device_Class_Block;								
-					blk_dev->dev.init = rt_mmcsd_init;
-					blk_dev->dev.open = rt_mmcsd_open;
-					blk_dev->dev.close = rt_mmcsd_close;
-					blk_dev->dev.read = rt_mmcsd_read;
-					blk_dev->dev.write = rt_mmcsd_write;
-					blk_dev->dev.control = rt_mmcsd_control;
-					blk_dev->dev.user_data = blk_dev;
-
-					blk_dev->card = card;
-
-					blk_dev->geometry.bytes_per_sector = 1<<9;
-					blk_dev->geometry.block_size = card->card_blksize;
-					if (card->flags & CARD_FLAG_SDHC) 
-					{
-						blk_dev->geometry.sector_count = (card->csd.c_size + 1) * 1024;
-					}
-					else
-					{
-						blk_dev->geometry.sector_count = 
-							card->card_capacity * 1024 / 512;
-					}
-	
-					rt_device_register(&blk_dev->dev, "sd0",
-						RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
-					rt_list_insert_after(&blk_devices, &blk_dev->list);
-	
-					break;
-				}
-				else
-				{
-					rt_free(blk_dev);
-					blk_dev = RT_NULL;
-					break;
-				}
-			}
-		}
-	}
-	else
-	{
-		rt_kprintf("read mmcsd first sector failed\n");
-		err = -RT_ERROR;
-	}
-	
-	/* release sector buffer */
-	rt_free(sector);
-	
-	return err;
+    rt_int32_t err = 0;
+    rt_uint8_t i, status;
+    rt_uint8_t *sector;
+    char dname[4];
+    char sname[8];
+    struct mmcsd_blk_device *blk_dev = RT_NULL;
+
+    err = mmcsd_set_blksize(card);
+    if(err) 
+    {
+        return err;
+    }
+
+    /* get the first sector to read partition table */
+    sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE);
+    if (sector == RT_NULL)
+    {
+        rt_kprintf("allocate partition sector buffer failed\n");
+
+        return -RT_ENOMEM;
+    }
+
+    status = rt_mmcsd_req_blk(card, 0, sector, 1, 0);
+    if (status == RT_EOK)
+    {
+        for (i = 0; i < RT_MMCSD_MAX_PARTITION; i++)
+        {
+            blk_dev = rt_malloc(sizeof(struct mmcsd_blk_device));
+            if (!blk_dev) 
+            {
+                rt_kprintf("mmcsd:malloc mem failde\n");
+                break;
+            }
+            rt_memset((void *)blk_dev, 0, sizeof(struct mmcsd_blk_device));
+            /* get the first partition */
+            status = dfs_filesystem_get_partition(&blk_dev->part, sector, i);
+            if (status == RT_EOK)
+            {
+                rt_snprintf(dname, 4, "sd%d",  i);
+                rt_snprintf(sname, 8, "sem_sd%d",  i);
+                blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
+    
+                /* register mmcsd device */
+                blk_dev->dev.type = RT_Device_Class_Block;                  
+                blk_dev->dev.init = rt_mmcsd_init;
+                blk_dev->dev.open = rt_mmcsd_open;
+                blk_dev->dev.close = rt_mmcsd_close;
+                blk_dev->dev.read = rt_mmcsd_read;
+                blk_dev->dev.write = rt_mmcsd_write;
+                blk_dev->dev.control = rt_mmcsd_control;
+                blk_dev->dev.user_data = blk_dev;
+
+                blk_dev->card = card;
+                
+                blk_dev->geometry.bytes_per_sector = 1<<9;
+                blk_dev->geometry.block_size = card->card_blksize;
+                blk_dev->geometry.sector_count = blk_dev->part.size;
+    
+                rt_device_register(&blk_dev->dev, dname,
+                    RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
+                rt_list_insert_after(&blk_devices, &blk_dev->list);
+            }
+            else
+            {
+                if (i == 0)
+                {
+                    /* there is no partition table */
+                    blk_dev->part.offset = 0;
+                    blk_dev->part.size   = 0;
+                    blk_dev->part.lock = rt_sem_create("sem_sd0", 1, RT_IPC_FLAG_FIFO);
+    
+                    /* register mmcsd device */
+                    blk_dev->dev.type  = RT_Device_Class_Block;
+                    blk_dev->dev.init = rt_mmcsd_init;
+                    blk_dev->dev.open = rt_mmcsd_open;
+                    blk_dev->dev.close = rt_mmcsd_close;
+                    blk_dev->dev.read = rt_mmcsd_read;
+                    blk_dev->dev.write = rt_mmcsd_write;
+                    blk_dev->dev.control = rt_mmcsd_control;
+                    blk_dev->dev.user_data = blk_dev;
+
+                    blk_dev->card = card;
+
+                    blk_dev->geometry.bytes_per_sector = 1<<9;
+                    blk_dev->geometry.block_size = card->card_blksize;
+                    if (card->flags & CARD_FLAG_SDHC) 
+                    {
+                        blk_dev->geometry.sector_count = (card->csd.c_size + 1) * 1024;
+                    }
+                    else
+                    {
+                        blk_dev->geometry.sector_count = 
+                            card->card_capacity * 1024 / 512;
+                    }
+    
+                    rt_device_register(&blk_dev->dev, "sd0",
+                        RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
+                    rt_list_insert_after(&blk_devices, &blk_dev->list);
+    
+                    break;
+                }
+                else
+                {
+                    rt_free(blk_dev);
+                    blk_dev = RT_NULL;
+                    break;
+                }
+            }
+        }
+    }
+    else
+    {
+        rt_kprintf("read mmcsd first sector failed\n");
+        err = -RT_ERROR;
+    }
+    
+    /* release sector buffer */
+    rt_free(sector);
+    
+    return err;
 }
 
 void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
 {
-	rt_list_t *l;
-	struct mmcsd_blk_device *blk_dev;
-	
-	for (l = (&blk_devices)->next; l != &blk_devices; l = l->next)
-	{
-		blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list);
-		if (blk_dev->card == card) 
-		{
-			rt_device_unregister(&blk_dev->dev);
-			rt_list_remove(&blk_dev->list);
-			rt_free(blk_dev);
-		}
-	}
+    rt_list_t *l;
+    struct mmcsd_blk_device *blk_dev;
+    
+    for (l = (&blk_devices)->next; l != &blk_devices; l = l->next)
+    {
+        blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list);
+        if (blk_dev->card == card) 
+        {
+            rt_device_unregister(&blk_dev->dev);
+            rt_list_remove(&blk_dev->list);
+            rt_free(blk_dev);
+        }
+    }
 }
 
 void rt_mmcsd_blk_init(void)
 {
-	rt_list_init(&blk_devices);
+    rt_list_init(&blk_devices);
 }

+ 486 - 464
components/drivers/sdio/mmcsd_core.c

@@ -3,13 +3,23 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
- * Date           Author		Notes
- * 2011-07-25     weety		first version
+ * Date           Author        Notes
+ * 2011-07-25     weety         first version
  */
 
 #include <rtthread.h>
@@ -35,338 +45,348 @@ static rt_uint32_t mmcsd_detect_mb_pool[4];
 
 void mmcsd_host_lock(struct rt_mmcsd_host *host)
 {
-	rt_sem_take(&host->bus_lock, RT_WAITING_FOREVER);
+    rt_sem_take(&host->bus_lock, RT_WAITING_FOREVER);
 }
 
 void mmcsd_host_unlock(struct rt_mmcsd_host *host)
 {
-	rt_sem_release(&host->bus_lock);
+    rt_sem_release(&host->bus_lock);
 }
 
 void mmcsd_req_complete(struct rt_mmcsd_host *host)
 {
-	rt_sem_release(&host->sem_ack);
+    rt_sem_release(&host->sem_ack);
 }
 
 void mmcsd_send_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
 {
     req->cmd->err = 0;
-	req->cmd->mrq = req;
-	if (req->data)
+    req->cmd->mrq = req;
+    if (req->data)
     {   
         req->cmd->data = req->data;
         req->data->err = 0;
-    	req->data->mrq = req;
-		if (req->stop)
-		{
-			req->data->stop = req->stop;
-			req->stop->err = 0;
-			req->stop->mrq = req;
-		}    	
+        req->data->mrq = req;
+        if (req->stop)
+        {
+            req->data->stop = req->stop;
+            req->stop->err = 0;
+            req->stop->mrq = req;
+        }       
    }
-	host->ops->request(host, req);
-	rt_sem_take(&host->sem_ack, RT_WAITING_FOREVER);
+    host->ops->request(host, req);
+    rt_sem_take(&host->sem_ack, RT_WAITING_FOREVER);
 }
 
-rt_int32_t mmcsd_send_cmd(struct rt_mmcsd_host *host, struct rt_mmcsd_cmd *cmd, int retries)
+rt_int32_t mmcsd_send_cmd(struct rt_mmcsd_host *host,
+                          struct rt_mmcsd_cmd  *cmd,
+                          int                   retries)
 {
-	struct rt_mmcsd_req req;
+    struct rt_mmcsd_req req;
 
-	rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
-	rt_memset(cmd->resp, 0, sizeof(cmd->resp));
+    rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
+    rt_memset(cmd->resp, 0, sizeof(cmd->resp));
 
-	req.cmd = cmd;
-	cmd->data = RT_NULL;
+    req.cmd = cmd;
+    cmd->data = RT_NULL;
 
-	mmcsd_send_request(host, &req);
+    mmcsd_send_request(host, &req);
 
-	return cmd->err;
+    return cmd->err;
 }
 
 rt_int32_t mmcsd_go_idle(struct rt_mmcsd_host *host)
 {
-	rt_int32_t err;
-	struct rt_mmcsd_cmd cmd;
-
-	if (!controller_is_spi(host)) {
-		mmcsd_set_chip_select(host, MMCSD_CS_HIGH);
-		mmcsd_delay_ms(1);
-	}
+    rt_int32_t err;
+    struct rt_mmcsd_cmd cmd;
 
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    if (!controller_is_spi(host))
+    {
+        mmcsd_set_chip_select(host, MMCSD_CS_HIGH);
+        mmcsd_delay_ms(1);
+    }
 
-	cmd.cmd_code = GO_IDLE_STATE;
-	cmd.arg = 0;
-	cmd.flags = RESP_SPI_R1 | RESP_NONE | CMD_BC;
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
 
-	err = mmcsd_send_cmd(host, &cmd, 0);
+    cmd.cmd_code = GO_IDLE_STATE;
+    cmd.arg = 0;
+    cmd.flags = RESP_SPI_R1 | RESP_NONE | CMD_BC;
 
-	mmcsd_delay_ms(1);
+    err = mmcsd_send_cmd(host, &cmd, 0);
 
-	if (!controller_is_spi(host)) 
-	{
-		mmcsd_set_chip_select(host, MMCSD_CS_IGNORE);
-		mmcsd_delay_ms(1);
-	}
+    mmcsd_delay_ms(1);
 
+    if (!controller_is_spi(host)) 
+    {
+        mmcsd_set_chip_select(host, MMCSD_CS_IGNORE);
+        mmcsd_delay_ms(1);
+    }
 
-	return err;
+    return err;
 }
 
-rt_int32_t mmcsd_spi_read_ocr(struct rt_mmcsd_host *host, rt_int32_t high_capacity, rt_uint32_t *ocr)
+rt_int32_t mmcsd_spi_read_ocr(struct rt_mmcsd_host *host,
+                              rt_int32_t            high_capacity,
+                              rt_uint32_t          *ocr)
 {
-	struct rt_mmcsd_cmd cmd;
-	rt_int32_t err;
+    struct rt_mmcsd_cmd cmd;
+    rt_int32_t err;
 
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
 
-	cmd.cmd_code = SPI_READ_OCR;
-	cmd.arg = high_capacity ? (1 << 30) : 0;
-	cmd.flags = RESP_SPI_R3;
+    cmd.cmd_code = SPI_READ_OCR;
+    cmd.arg = high_capacity ? (1 << 30) : 0;
+    cmd.flags = RESP_SPI_R3;
 
-	err = mmcsd_send_cmd(host, &cmd, 0);
+    err = mmcsd_send_cmd(host, &cmd, 0);
 
-	*ocr = cmd.resp[1];
-	return err;
-}
+    *ocr = cmd.resp[1];
 
+    return err;
+}
 
 rt_int32_t mmcsd_all_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid)
 {
-	rt_int32_t err;
-	struct rt_mmcsd_cmd cmd;
+    rt_int32_t err;
+    struct rt_mmcsd_cmd cmd;
 
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
 
-	cmd.cmd_code = ALL_SEND_CID;
-	cmd.arg = 0;
-	cmd.flags = RESP_R2 | CMD_BCR;
+    cmd.cmd_code = ALL_SEND_CID;
+    cmd.arg = 0;
+    cmd.flags = RESP_R2 | CMD_BCR;
 
-	err = mmcsd_send_cmd(host, &cmd, 3);
-	if (err)
-		return err;
+    err = mmcsd_send_cmd(host, &cmd, 3);
+    if (err)
+        return err;
 
-	rt_memcpy(cid, cmd.resp, sizeof(rt_uint32_t) * 4);
+    rt_memcpy(cid, cmd.resp, sizeof(rt_uint32_t) * 4);
 
-	return 0;
+    return 0;
 }
 
-
 rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid)
 {
-	rt_int32_t err, i;
-	struct rt_mmcsd_req req;
-	struct rt_mmcsd_cmd cmd;
-	struct rt_mmcsd_data data;
-	rt_uint32_t *buf = RT_NULL;
-
-	if (!controller_is_spi(host)) 
-	{
-		if (!host->card)
-			return -RT_ERROR;
-		rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
-
-		cmd.cmd_code = SEND_CID;
-		cmd.arg = host->card->rca << 16;
-		cmd.flags = RESP_R2 | CMD_AC;
-		err = mmcsd_send_cmd(host, &cmd, 3);
-		if (err)
-			return err;
-
-		rt_memcpy(cid, cmd.resp, sizeof(rt_uint32_t) * 4);
-		return 0;
-	}
-
-	buf = (rt_uint32_t *)rt_malloc(16);
-	if (!buf) 
-	{
-		rt_kprintf("allocate memory failed\n");
-		return -RT_ENOMEM;
-	}
-
-	rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
-	rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
-
-	req.cmd = &cmd;
-	req.data = &data;
-
-	cmd.cmd_code = SEND_CID;
-	cmd.arg = 0;
-
-	/* NOTE HACK:  the RESP_SPI_R1 is always correct here, but we
-	 * rely on callers to never use this with "native" calls for reading
-	 * CSD or CID.  Native versions of those commands use the R2 type,
-	 * not R1 plus a data block.
-	 */
-	cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
-
-	data.blksize = 16;
-	data.blks = 1;
-	data.flags = DATA_DIR_READ;
-	data.buf = buf;
-	/*
-	 * The spec states that CSR and CID accesses have a timeout
-	 * of 64 clock cycles.
-	 */
-	data.timeout_ns = 0;
-	data.timeout_clks = 64;
-
-	mmcsd_send_request(host, &req);
-
-	if (cmd.err || data.err)
-	{
-		rt_free(buf);
-		return -RT_ERROR;
-	}
-
-	for (i = 0;i < 4;i++)
-		cid[i] = buf[i];
-	rt_free(buf);
-
-	return 0;
+    rt_int32_t err, i;
+    struct rt_mmcsd_req req;
+    struct rt_mmcsd_cmd cmd;
+    struct rt_mmcsd_data data;
+    rt_uint32_t *buf = RT_NULL;
+
+    if (!controller_is_spi(host)) 
+    {
+        if (!host->card)
+            return -RT_ERROR;
+        rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+
+        cmd.cmd_code = SEND_CID;
+        cmd.arg = host->card->rca << 16;
+        cmd.flags = RESP_R2 | CMD_AC;
+        err = mmcsd_send_cmd(host, &cmd, 3);
+        if (err)
+            return err;
+
+        rt_memcpy(cid, cmd.resp, sizeof(rt_uint32_t) * 4);
+
+        return 0;
+    }
+
+    buf = (rt_uint32_t *)rt_malloc(16);
+    if (!buf) 
+    {
+        rt_kprintf("allocate memory failed\n");
+
+        return -RT_ENOMEM;
+    }
+
+    rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
+
+    req.cmd = &cmd;
+    req.data = &data;
+
+    cmd.cmd_code = SEND_CID;
+    cmd.arg = 0;
+
+    /* NOTE HACK:  the RESP_SPI_R1 is always correct here, but we
+     * rely on callers to never use this with "native" calls for reading
+     * CSD or CID.  Native versions of those commands use the R2 type,
+     * not R1 plus a data block.
+     */
+    cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
+
+    data.blksize = 16;
+    data.blks = 1;
+    data.flags = DATA_DIR_READ;
+    data.buf = buf;
+    /*
+     * The spec states that CSR and CID accesses have a timeout
+     * of 64 clock cycles.
+     */
+    data.timeout_ns = 0;
+    data.timeout_clks = 64;
+
+    mmcsd_send_request(host, &req);
+
+    if (cmd.err || data.err)
+    {
+        rt_free(buf);
+
+        return -RT_ERROR;
+    }
+
+    for (i = 0;i < 4;i++)
+        cid[i] = buf[i];
+    rt_free(buf);
+
+    return 0;
 }
 
 rt_int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, rt_uint32_t *csd)
 {
-	rt_int32_t err, i;
-	struct rt_mmcsd_req req;
-	struct rt_mmcsd_cmd cmd;
-	struct rt_mmcsd_data data;
-	rt_uint32_t *buf = RT_NULL;
-
-	if (!controller_is_spi(card->host))
-	{
-		rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
-
-		cmd.cmd_code = SEND_CSD;
-		cmd.arg = card->rca << 16;
-		cmd.flags = RESP_R2 | CMD_AC;
-		err = mmcsd_send_cmd(card->host, &cmd, 3);
-		if (err)
-			return err;
-
-		rt_memcpy(csd, cmd.resp, sizeof(rt_uint32_t) * 4);
-		return 0;
-	}
-
-	buf = (rt_uint32_t*)rt_malloc(16);
-	if (!buf) 
-	{
-		rt_kprintf("allocate memory failed\n");
-		return -RT_ENOMEM;
-	}
-
-	rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
-	rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
-
-	req.cmd = &cmd;
-	req.data = &data;
-
-	cmd.cmd_code = SEND_CSD;
-	cmd.arg = 0;
-
-	/* NOTE HACK:  the RESP_SPI_R1 is always correct here, but we
-	 * rely on callers to never use this with "native" calls for reading
-	 * CSD or CID.  Native versions of those commands use the R2 type,
-	 * not R1 plus a data block.
-	 */
-	cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
-
-	data.blksize = 16;
-	data.blks = 1;
-	data.flags = DATA_DIR_READ;
-	data.buf = buf;
-
-	/*
-	 * The spec states that CSR and CID accesses have a timeout
-	 * of 64 clock cycles.
-	 */
-	data.timeout_ns = 0;
-	data.timeout_clks = 64;
-
-	mmcsd_send_request(card->host, &req);
-
-	if (cmd.err || data.err)
-	{
-		rt_free(buf);
-		return -RT_ERROR;
-	}
-
-	for (i = 0;i < 4;i++)
-		csd[i] = buf[i];
-	rt_free(buf);
-
-	return 0;
+    rt_int32_t err, i;
+    struct rt_mmcsd_req req;
+    struct rt_mmcsd_cmd cmd;
+    struct rt_mmcsd_data data;
+    rt_uint32_t *buf = RT_NULL;
+
+    if (!controller_is_spi(card->host))
+    {
+        rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+
+        cmd.cmd_code = SEND_CSD;
+        cmd.arg = card->rca << 16;
+        cmd.flags = RESP_R2 | CMD_AC;
+        err = mmcsd_send_cmd(card->host, &cmd, 3);
+        if (err)
+            return err;
+
+        rt_memcpy(csd, cmd.resp, sizeof(rt_uint32_t) * 4);
+
+        return 0;
+    }
+
+    buf = (rt_uint32_t*)rt_malloc(16);
+    if (!buf) 
+    {
+        rt_kprintf("allocate memory failed\n");
+
+        return -RT_ENOMEM;
+    }
+
+    rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
+
+    req.cmd = &cmd;
+    req.data = &data;
+
+    cmd.cmd_code = SEND_CSD;
+    cmd.arg = 0;
+
+    /* NOTE HACK:  the RESP_SPI_R1 is always correct here, but we
+     * rely on callers to never use this with "native" calls for reading
+     * CSD or CID.  Native versions of those commands use the R2 type,
+     * not R1 plus a data block.
+     */
+    cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
+
+    data.blksize = 16;
+    data.blks = 1;
+    data.flags = DATA_DIR_READ;
+    data.buf = buf;
+
+    /*
+     * The spec states that CSR and CID accesses have a timeout
+     * of 64 clock cycles.
+     */
+    data.timeout_ns = 0;
+    data.timeout_clks = 64;
+
+    mmcsd_send_request(card->host, &req);
+
+    if (cmd.err || data.err)
+    {
+        rt_free(buf);
+
+        return -RT_ERROR;
+    }
+
+    for (i = 0;i < 4;i++)
+        csd[i] = buf[i];
+    rt_free(buf);
+
+    return 0;
 }
 
-static rt_int32_t _mmcsd_select_card(struct rt_mmcsd_host *host, struct rt_mmcsd_card *card)
+static rt_int32_t _mmcsd_select_card(struct rt_mmcsd_host *host,
+                                     struct rt_mmcsd_card *card)
 {
-	rt_int32_t err;
-	struct rt_mmcsd_cmd cmd;
+    rt_int32_t err;
+    struct rt_mmcsd_cmd cmd;
 
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
 
-	cmd.cmd_code = SELECT_CARD;
+    cmd.cmd_code = SELECT_CARD;
 
-	if (card) 
-	{
-		cmd.arg = card->rca << 16;
-		cmd.flags = RESP_R1 | CMD_AC;
-	} 
-	else 
-	{
-		cmd.arg = 0;
-		cmd.flags = RESP_NONE | CMD_AC;
-	}
+    if (card) 
+    {
+        cmd.arg = card->rca << 16;
+        cmd.flags = RESP_R1 | CMD_AC;
+    } 
+    else 
+    {
+        cmd.arg = 0;
+        cmd.flags = RESP_NONE | CMD_AC;
+    }
 
-	err = mmcsd_send_cmd(host, &cmd, 3);
-	if (err)
-		return err;
+    err = mmcsd_send_cmd(host, &cmd, 3);
+    if (err)
+        return err;
 
-	return 0;
+    return 0;
 }
 
 rt_int32_t mmcsd_select_card(struct rt_mmcsd_card *card)
 {
-	return _mmcsd_select_card(card->host, card);
+    return _mmcsd_select_card(card->host, card);
 }
 
 rt_int32_t mmcsd_deselect_cards(struct rt_mmcsd_card *card)
 {
-	return _mmcsd_select_card(card->host, RT_NULL);
+    return _mmcsd_select_card(card->host, RT_NULL);
 }
 
 rt_int32_t mmcsd_spi_use_crc(struct rt_mmcsd_host *host, rt_int32_t use_crc)
 {
-	struct rt_mmcsd_cmd cmd;
-	rt_int32_t err;
+    struct rt_mmcsd_cmd cmd;
+    rt_int32_t err;
 
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
 
-	cmd.cmd_code = SPI_CRC_ON_OFF;
-	cmd.flags = RESP_SPI_R1;
-	cmd.arg = use_crc;
+    cmd.cmd_code = SPI_CRC_ON_OFF;
+    cmd.flags = RESP_SPI_R1;
+    cmd.arg = use_crc;
 
-	err = mmcsd_send_cmd(host, &cmd, 0);
-	if (!err)
-		host->spi_use_crc = use_crc;
-	return err;
-}
+    err = mmcsd_send_cmd(host, &cmd, 0);
+    if (!err)
+        host->spi_use_crc = use_crc;
 
+    return err;
+}
 
 rt_inline void mmcsd_set_iocfg(struct rt_mmcsd_host *host)
 {
-	struct rt_mmcsd_io_cfg *io_cfg = &host->io_cfg;
+    struct rt_mmcsd_io_cfg *io_cfg = &host->io_cfg;
 
-	mmcsd_dbg("clock %uHz busmode %u powermode %u cs %u Vdd %u "
-		"width %u \n",
-		 io_cfg->clock, io_cfg->bus_mode,
-		 io_cfg->power_mode, io_cfg->chip_select, io_cfg->vdd,
-		 io_cfg->bus_width);
+    mmcsd_dbg("clock %uHz busmode %u powermode %u cs %u Vdd %u "
+        "width %u \n",
+         io_cfg->clock, io_cfg->bus_mode,
+         io_cfg->power_mode, io_cfg->chip_select, io_cfg->vdd,
+         io_cfg->bus_width);
 
-	host->ops->set_iocfg(host, io_cfg);
+    host->ops->set_iocfg(host, io_cfg);
 }
 
 /*
@@ -374,8 +394,8 @@ rt_inline void mmcsd_set_iocfg(struct rt_mmcsd_host *host)
  */
 void mmcsd_set_chip_select(struct rt_mmcsd_host *host, rt_int32_t mode)
 {
-	host->io_cfg.chip_select = mode;
-	mmcsd_set_iocfg(host);
+    host->io_cfg.chip_select = mode;
+    mmcsd_set_iocfg(host);
 }
 
 /*
@@ -384,13 +404,13 @@ void mmcsd_set_chip_select(struct rt_mmcsd_host *host, rt_int32_t mode)
  */
 void mmcsd_set_clock(struct rt_mmcsd_host *host, rt_uint32_t clk)
 {
-	if (clk < host->freq_min)
-	{
-		rt_kprintf("clock too low\n");
-	}
+    if (clk < host->freq_min)
+    {
+        rt_kprintf("clock too low\n");
+    }
 
-	host->io_cfg.clock = clk;
-	mmcsd_set_iocfg(host);
+    host->io_cfg.clock = clk;
+    mmcsd_set_iocfg(host);
 }
 
 /*
@@ -398,8 +418,8 @@ void mmcsd_set_clock(struct rt_mmcsd_host *host, rt_uint32_t clk)
  */
 void mmcsd_set_bus_mode(struct rt_mmcsd_host *host, rt_uint32_t mode)
 {
-	host->io_cfg.bus_mode = mode;
-	mmcsd_set_iocfg(host);
+    host->io_cfg.bus_mode = mode;
+    mmcsd_set_iocfg(host);
 }
 
 /*
@@ -407,258 +427,260 @@ void mmcsd_set_bus_mode(struct rt_mmcsd_host *host, rt_uint32_t mode)
  */
 void mmcsd_set_bus_width(struct rt_mmcsd_host *host, rt_uint32_t width)
 {
-	host->io_cfg.bus_width = width;
-	mmcsd_set_iocfg(host);
+    host->io_cfg.bus_width = width;
+    mmcsd_set_iocfg(host);
 }
 
-void mmcsd_set_data_timeout(struct rt_mmcsd_data *data, const struct rt_mmcsd_card *card)
+void mmcsd_set_data_timeout(struct rt_mmcsd_data       *data,
+                            const struct rt_mmcsd_card *card)
 {
-	rt_uint32_t mult;
-
-	if (card->card_type == CARD_TYPE_SDIO) 
-	{
-		data->timeout_ns = 1000000000;	/* SDIO card 1s */
-		data->timeout_clks = 0;
-		return;
-	}
-
-	/*
-	 * SD cards use a 100 multiplier rather than 10
-	 */
-	mult = (card->card_type == CARD_TYPE_SD) ? 100 : 10;
-
-	/*
-	 * Scale up the multiplier (and therefore the timeout) by
-	 * the r2w factor for writes.
-	 */
-	if (data->flags & DATA_DIR_WRITE)
-		mult <<= card->csd.r2w_factor;
-
-	data->timeout_ns = card->tacc_ns * mult;
-	data->timeout_clks = card->tacc_clks * mult;
-
-	/*
-	 * SD cards also have an upper limit on the timeout.
-	 */
-	if (card->card_type == CARD_TYPE_SD) 
-	{
-		rt_uint32_t timeout_us, limit_us;
-
-		timeout_us = data->timeout_ns / 1000;
-		timeout_us += data->timeout_clks * 1000 /
-			(card->host->io_cfg.clock / 1000);
-
-		if (data->flags & DATA_DIR_WRITE)
-			/*
-			 * The limit is really 250 ms, but that is
-			 * insufficient for some crappy cards.
-			 */
-			limit_us = 300000;
-		else
-			limit_us = 100000;
-
-		/*
-		 * SDHC cards always use these fixed values.
-		 */
-		if (timeout_us > limit_us || card->flags & CARD_FLAG_SDHC) 
-		{
-			data->timeout_ns = limit_us * 1000;	/* SDHC card fixed 250ms */
-			data->timeout_clks = 0;
-		}
-	}
-
-	if (controller_is_spi(card->host)) 
-	{
-		if (data->flags & DATA_DIR_WRITE) 
-		{
-			if (data->timeout_ns < 1000000000)
-				data->timeout_ns = 1000000000;	/* 1s */
-		} 
-		else 
-		{
-			if (data->timeout_ns < 100000000)
-				data->timeout_ns =  100000000;	/* 100ms */
-		}
-	}
+    rt_uint32_t mult;
+
+    if (card->card_type == CARD_TYPE_SDIO) 
+    {
+        data->timeout_ns = 1000000000;  /* SDIO card 1s */
+        data->timeout_clks = 0;
+
+        return;
+    }
+
+    /*
+     * SD cards use a 100 multiplier rather than 10
+     */
+    mult = (card->card_type == CARD_TYPE_SD) ? 100 : 10;
+
+    /*
+     * Scale up the multiplier (and therefore the timeout) by
+     * the r2w factor for writes.
+     */
+    if (data->flags & DATA_DIR_WRITE)
+        mult <<= card->csd.r2w_factor;
+
+    data->timeout_ns = card->tacc_ns * mult;
+    data->timeout_clks = card->tacc_clks * mult;
+
+    /*
+     * SD cards also have an upper limit on the timeout.
+     */
+    if (card->card_type == CARD_TYPE_SD) 
+    {
+        rt_uint32_t timeout_us, limit_us;
+
+        timeout_us = data->timeout_ns / 1000;
+        timeout_us += data->timeout_clks * 1000 /
+            (card->host->io_cfg.clock / 1000);
+
+        if (data->flags & DATA_DIR_WRITE)
+            /*
+             * The limit is really 250 ms, but that is
+             * insufficient for some crappy cards.
+             */
+            limit_us = 300000;
+        else
+            limit_us = 100000;
+
+        /*
+         * SDHC cards always use these fixed values.
+         */
+        if (timeout_us > limit_us || card->flags & CARD_FLAG_SDHC) 
+        {
+            data->timeout_ns = limit_us * 1000; /* SDHC card fixed 250ms */
+            data->timeout_clks = 0;
+        }
+    }
+
+    if (controller_is_spi(card->host)) 
+    {
+        if (data->flags & DATA_DIR_WRITE) 
+        {
+            if (data->timeout_ns < 1000000000)
+                data->timeout_ns = 1000000000;  /* 1s */
+        } 
+        else 
+        {
+            if (data->timeout_ns < 100000000)
+                data->timeout_ns =  100000000;  /* 100ms */
+        }
+    }
 }
 
-
 /*
  * Mask off any voltages we don't support and select
  * the lowest voltage
  */
 rt_uint32_t mmcsd_select_voltage(struct rt_mmcsd_host *host, rt_uint32_t ocr)
 {
-	int bit;
+    int bit;
 
-	ocr &= host->valid_ocr;
+    ocr &= host->valid_ocr;
 
-	bit = __rt_ffs(ocr);
-	if (bit) 
-	{
-		bit -= 1;
+    bit = __rt_ffs(ocr);
+    if (bit) 
+    {
+        bit -= 1;
 
-		ocr &= 3 << bit;
+        ocr &= 3 << bit;
 
-		host->io_cfg.vdd = bit;
-		mmcsd_set_iocfg(host);
-	} 
-	else 
-	{
-		rt_kprintf("host doesn't support card's voltages\n");
-		ocr = 0;
-	}
+        host->io_cfg.vdd = bit;
+        mmcsd_set_iocfg(host);
+    } 
+    else 
+    {
+        rt_kprintf("host doesn't support card's voltages\n");
+        ocr = 0;
+    }
 
-	return ocr;
+    return ocr;
 }
 
-
 static void mmcsd_power_up(struct rt_mmcsd_host *host)
 {
-	int bit = fls(host->valid_ocr) - 1;
-
-	host->io_cfg.vdd = bit;
-	if (controller_is_spi(host))
-	{
-		host->io_cfg.chip_select = MMCSD_CS_HIGH;
-		host->io_cfg.bus_mode = MMCSD_BUSMODE_PUSHPULL;
-	} 
-	else
-	{
-		host->io_cfg.chip_select = MMCSD_CS_IGNORE;
-		host->io_cfg.bus_mode = MMCSD_BUSMODE_OPENDRAIN;
-	}
-	host->io_cfg.power_mode = MMCSD_POWER_UP;
-	host->io_cfg.bus_width = MMCSD_BUS_WIDTH_1;
-	mmcsd_set_iocfg(host);
-
-	/*
-	 * This delay should be sufficient to allow the power supply
-	 * to reach the minimum voltage.
-	 */
-	mmcsd_delay_ms(10);
-
-	host->io_cfg.clock = host->freq_min;
-	host->io_cfg.power_mode = MMCSD_POWER_ON;
-	mmcsd_set_iocfg(host);
-
-	/*
-	 * This delay must be at least 74 clock sizes, or 1 ms, or the
-	 * time required to reach a stable voltage.
-	 */
-	mmcsd_delay_ms(10);
+    int bit = fls(host->valid_ocr) - 1;
+
+    host->io_cfg.vdd = bit;
+    if (controller_is_spi(host))
+    {
+        host->io_cfg.chip_select = MMCSD_CS_HIGH;
+        host->io_cfg.bus_mode = MMCSD_BUSMODE_PUSHPULL;
+    } 
+    else
+    {
+        host->io_cfg.chip_select = MMCSD_CS_IGNORE;
+        host->io_cfg.bus_mode = MMCSD_BUSMODE_OPENDRAIN;
+    }
+    host->io_cfg.power_mode = MMCSD_POWER_UP;
+    host->io_cfg.bus_width = MMCSD_BUS_WIDTH_1;
+    mmcsd_set_iocfg(host);
+
+    /*
+     * This delay should be sufficient to allow the power supply
+     * to reach the minimum voltage.
+     */
+    mmcsd_delay_ms(10);
+
+    host->io_cfg.clock = host->freq_min;
+    host->io_cfg.power_mode = MMCSD_POWER_ON;
+    mmcsd_set_iocfg(host);
+
+    /*
+     * This delay must be at least 74 clock sizes, or 1 ms, or the
+     * time required to reach a stable voltage.
+     */
+    mmcsd_delay_ms(10);
 }
 
 static void mmcsd_power_off(struct rt_mmcsd_host *host)
 {
-	host->io_cfg.clock = 0;
-	host->io_cfg.vdd = 0;
-	if (!controller_is_spi(host)) 
-	{
-		host->io_cfg.bus_mode = MMCSD_BUSMODE_OPENDRAIN;
-		host->io_cfg.chip_select = MMCSD_CS_IGNORE;
-	}
-	host->io_cfg.power_mode = MMCSD_POWER_OFF;
-	host->io_cfg.bus_width = MMCSD_BUS_WIDTH_1;
-	mmcsd_set_iocfg(host);
+    host->io_cfg.clock = 0;
+    host->io_cfg.vdd = 0;
+    if (!controller_is_spi(host)) 
+    {
+        host->io_cfg.bus_mode = MMCSD_BUSMODE_OPENDRAIN;
+        host->io_cfg.chip_select = MMCSD_CS_IGNORE;
+    }
+    host->io_cfg.power_mode = MMCSD_POWER_OFF;
+    host->io_cfg.bus_width = MMCSD_BUS_WIDTH_1;
+    mmcsd_set_iocfg(host);
 }
 
 void mmcsd_change(struct rt_mmcsd_host *host)
 {
-	rt_mb_send(&mmcsd_detect_mb, (rt_uint32_t)host);
+    rt_mb_send(&mmcsd_detect_mb, (rt_uint32_t)host);
 }
 
 void mmcsd_detect(void *param)
 {
-	struct rt_mmcsd_host *host;
-	rt_uint32_t  ocr;
-	rt_int32_t  err;
-
-	while (1) 
-	{
-		if (rt_mb_recv(&mmcsd_detect_mb, (rt_uint32_t*)&host, RT_WAITING_FOREVER) == RT_EOK)
-		{
-			if (host->card == RT_NULL)
-			{
-				mmcsd_host_lock(host);
-				mmcsd_power_up(host);
-				mmcsd_go_idle(host);
-
-				mmcsd_send_if_cond(host, host->valid_ocr);
-
-				err = sdio_io_send_op_cond(host, 0, &ocr);
-				if (!err) {
-					if (init_sdio(host, ocr))
-						mmcsd_power_off(host);
-					mmcsd_host_unlock(host);
-					continue;
-				}
-
-				/*
-				 * detect SD card
-				 */
-				err = mmcsd_send_app_op_cond(host, 0, &ocr);
-				if (!err) 
-				{
-					if (init_sd(host, ocr))
-						mmcsd_power_off(host);
-					mmcsd_host_unlock(host);
-					continue;
-				}
-				mmcsd_host_unlock(host);
-			}
-		}
-	}
+    struct rt_mmcsd_host *host;
+    rt_uint32_t  ocr;
+    rt_int32_t  err;
+
+    while (1) 
+    {
+        if (rt_mb_recv(&mmcsd_detect_mb, (rt_uint32_t*)&host, RT_WAITING_FOREVER) == RT_EOK)
+        {
+            if (host->card == RT_NULL)
+            {
+                mmcsd_host_lock(host);
+                mmcsd_power_up(host);
+                mmcsd_go_idle(host);
+
+                mmcsd_send_if_cond(host, host->valid_ocr);
+
+                err = sdio_io_send_op_cond(host, 0, &ocr);
+                if (!err)
+                {
+                    if (init_sdio(host, ocr))
+                        mmcsd_power_off(host);
+                    mmcsd_host_unlock(host);
+                    continue;
+                }
+
+                /*
+                 * detect SD card
+                 */
+                err = mmcsd_send_app_op_cond(host, 0, &ocr);
+                if (!err) 
+                {
+                    if (init_sd(host, ocr))
+                        mmcsd_power_off(host);
+                    mmcsd_host_unlock(host);
+                    continue;
+                }
+                mmcsd_host_unlock(host);
+            }
+        }
+    }
 }
 
 struct rt_mmcsd_host *mmcsd_alloc_host(void)
 {
-	struct rt_mmcsd_host *host;
+    struct rt_mmcsd_host *host;
+
+    host = rt_malloc(sizeof(struct rt_mmcsd_host));
+    if (!host) 
+    {
+        rt_kprintf("alloc host failed\n");
 
-	host = rt_malloc(sizeof(struct rt_mmcsd_host));
-	if (!host) 
-	{
-		rt_kprintf("alloc host failed\n");
-		return RT_NULL;
-	}
+        return RT_NULL;
+    }
 
-	rt_memset(host, 0, sizeof(struct rt_mmcsd_host));
+    rt_memset(host, 0, sizeof(struct rt_mmcsd_host));
 
-	host->max_seg_size = 65535;
-	host->max_dma_segs = 1;
-	host->max_blk_size = 512;
-	host->max_blk_count = 4096;
+    host->max_seg_size = 65535;
+    host->max_dma_segs = 1;
+    host->max_blk_size = 512;
+    host->max_blk_count = 4096;
 
-	rt_sem_init(&host->bus_lock, "sd_bus_lock", 1, RT_IPC_FLAG_FIFO);
-	rt_sem_init(&host->sem_ack, "sd_ack", 0, RT_IPC_FLAG_FIFO);
+    rt_sem_init(&host->bus_lock, "sd_bus_lock", 1, RT_IPC_FLAG_FIFO);
+    rt_sem_init(&host->sem_ack, "sd_ack", 0, RT_IPC_FLAG_FIFO);
 
-	return host;
+    return host;
 }
 
 void mmcsd_free_host(struct rt_mmcsd_host *host)
 {
-	rt_sem_detach(&host->bus_lock);
-	rt_sem_detach(&host->sem_ack);
-	rt_free(host);
+    rt_sem_detach(&host->bus_lock);
+    rt_sem_detach(&host->sem_ack);
+    rt_free(host);
 }
 
 void rt_mmcsd_core_init(void)
 {
-	rt_err_t ret;
-
-	/* init detect sd cart thread */
-	/* init mailbox and create detect sd card thread */
-	ret = rt_mb_init(&mmcsd_detect_mb, "mmcsdmb",
-		&mmcsd_detect_mb_pool[0], sizeof(mmcsd_detect_mb_pool),
-		RT_IPC_FLAG_FIFO);
-	RT_ASSERT(ret == RT_EOK);
-
-	ret = rt_thread_init(&mmcsd_detect_thread, "mmcsd_detect", mmcsd_detect, RT_NULL, 
-			     &mmcsd_stack[0], RT_MMCSD_STACK_SIZE, RT_MMCSD_THREAD_PREORITY, 20);
-	if (ret == RT_EOK) 
-	{
-		rt_thread_startup(&mmcsd_detect_thread);
-	}
-
-	rt_sdio_init();
+    rt_err_t ret;
+
+    /* init detect sd cart thread */
+    /* init mailbox and create detect sd card thread */
+    ret = rt_mb_init(&mmcsd_detect_mb, "mmcsdmb",
+        &mmcsd_detect_mb_pool[0], sizeof(mmcsd_detect_mb_pool),
+        RT_IPC_FLAG_FIFO);
+    RT_ASSERT(ret == RT_EOK);
+
+    ret = rt_thread_init(&mmcsd_detect_thread, "mmcsd_detect", mmcsd_detect, RT_NULL, 
+                 &mmcsd_stack[0], RT_MMCSD_STACK_SIZE, RT_MMCSD_THREAD_PREORITY, 20);
+    if (ret == RT_EOK) 
+    {
+        rt_thread_startup(&mmcsd_detect_thread);
+    }
+
+    rt_sdio_init();
 }

文件差异内容过多而无法显示
+ 561 - 534
components/drivers/sdio/sd.c


+ 1082 - 1041
components/drivers/sdio/sdio.c

@@ -3,13 +3,23 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
- * Date           Author		Notes
- * 2012-01-13     weety		first version
+ * Date           Author        Notes
+ * 2012-01-13     weety         first version
  */
 
 #include <drivers/mmcsd_core.h>
@@ -25,1320 +35,1351 @@
 static rt_list_t sdio_cards;
 static rt_list_t sdio_drivers;
 
-struct sdio_card {
-	struct rt_mmcsd_card *card;
-	rt_list_t  list;
+struct sdio_card
+{
+    struct rt_mmcsd_card *card;
+    rt_list_t  list;
 };
 
-struct sdio_driver {
-	struct rt_sdio_driver *drv;
-	rt_list_t  list;
+struct sdio_driver
+{
+    struct rt_sdio_driver *drv;
+    rt_list_t  list;
 };
 
 #define MIN(a, b) (a < b ? a : b)
 
 static const rt_uint8_t speed_value[16] =
-	{ 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
+{
+    0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80
+};
 
 static const rt_uint32_t speed_unit[8] =
-	{ 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 };
+{
+    10000, 100000, 1000000, 10000000, 0, 0, 0, 0
+};
 
-rt_inline rt_int32_t sdio_match_card(struct rt_mmcsd_card *card,
-	const struct rt_sdio_device_id *id);
+rt_inline rt_int32_t sdio_match_card(struct rt_mmcsd_card           *card,
+                                     const struct rt_sdio_device_id *id);
 
 
-rt_int32_t sdio_io_send_op_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr, rt_uint32_t 
-*cmd5_resp)
+rt_int32_t sdio_io_send_op_cond(struct rt_mmcsd_host *host,
+                                rt_uint32_t           ocr,
+                                rt_uint32_t          *cmd5_resp)
 {
-	struct rt_mmcsd_cmd cmd;
-	rt_int32_t i, err = 0;
-
-	RT_ASSERT(host != RT_NULL);
-
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
-
-	cmd.cmd_code = SD_IO_SEND_OP_COND;
-	cmd.arg = ocr;
-	cmd.flags = RESP_SPI_R4 | RESP_R4 | CMD_BCR;
-
-	for (i = 100; i; i--) 
-	{
-		err = mmcsd_send_cmd(host, &cmd, 0);
-		if (err)
-			break;
-
-		/* if we're just probing, do a single pass */
-		if (ocr == 0)
-			break;
-
-		/* otherwise wait until reset completes */
-		if (controller_is_spi(host)) 
-		{
-			/*
-			 * Both R1_SPI_IDLE and MMC_CARD_BUSY indicate
-			 * an initialized card under SPI, but some cards
-			 * (Marvell's) only behave when looking at this
-			 * one.
-			 */
-			if (cmd.resp[1] & CARD_BUSY)
-				break;
-		} 
-		else 
-		{
-			if (cmd.resp[0] & CARD_BUSY)
-				break;
-		}
-
-		err = -RT_ETIMEOUT;
-
-		mmcsd_delay_ms(10);
-	}
-
-	if (cmd5_resp)
-		*cmd5_resp = cmd.resp[controller_is_spi(host) ? 1 : 0];
-
-	return err;
+    struct rt_mmcsd_cmd cmd;
+    rt_int32_t i, err = 0;
+
+    RT_ASSERT(host != RT_NULL);
+
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+
+    cmd.cmd_code = SD_IO_SEND_OP_COND;
+    cmd.arg = ocr;
+    cmd.flags = RESP_SPI_R4 | RESP_R4 | CMD_BCR;
+
+    for (i = 100; i; i--) 
+    {
+        err = mmcsd_send_cmd(host, &cmd, 0);
+        if (err)
+            break;
+
+        /* if we're just probing, do a single pass */
+        if (ocr == 0)
+            break;
+
+        /* otherwise wait until reset completes */
+        if (controller_is_spi(host)) 
+        {
+            /*
+             * Both R1_SPI_IDLE and MMC_CARD_BUSY indicate
+             * an initialized card under SPI, but some cards
+             * (Marvell's) only behave when looking at this
+             * one.
+             */
+            if (cmd.resp[1] & CARD_BUSY)
+                break;
+        } 
+        else 
+        {
+            if (cmd.resp[0] & CARD_BUSY)
+                break;
+        }
+
+        err = -RT_ETIMEOUT;
+
+        mmcsd_delay_ms(10);
+    }
+
+    if (cmd5_resp)
+        *cmd5_resp = cmd.resp[controller_is_spi(host) ? 1 : 0];
+
+    return err;
 }
 
-
-rt_int32_t sdio_io_rw_direct(struct rt_mmcsd_card *card, rt_int32_t rw, rt_uint32_t fn,
-	rt_uint32_t reg_addr, rt_uint8_t *pdata, rt_uint8_t raw)
+rt_int32_t sdio_io_rw_direct(struct rt_mmcsd_card *card,
+                             rt_int32_t            rw,
+                             rt_uint32_t           fn,
+                             rt_uint32_t           reg_addr,
+                             rt_uint8_t           *pdata,
+                             rt_uint8_t            raw)
 {
-	struct rt_mmcsd_cmd cmd;
-	rt_int32_t err;
-
-	RT_ASSERT(card != RT_NULL);
-	RT_ASSERT(fn <= SDIO_MAX_FUNCTIONS);
-
-	if (reg_addr & ~SDIO_ARG_CMD53_REG_MASK)
-		return -RT_ERROR;
-
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
-
-	cmd.cmd_code = SD_IO_RW_DIRECT;
-	cmd.arg = rw ? SDIO_ARG_CMD52_WRITE : SDIO_ARG_CMD52_READ;
-	cmd.arg |= fn << SDIO_ARG_CMD52_FUNC_SHIFT;
-	cmd.arg |= raw ? SDIO_ARG_CMD52_RAW_FLAG : 0x00000000;
-	cmd.arg |= reg_addr << SDIO_ARG_CMD52_REG_SHIFT;
-	cmd.arg |= *pdata;
-	cmd.flags = RESP_SPI_R5 | RESP_R5 | CMD_AC;
-
-	err = mmcsd_send_cmd(card->host, &cmd, 0);
-	if (err)
-		return err;
-
-	if (!controller_is_spi(card->host)) 
-	{
-		if (cmd.resp[0] & R5_ERROR)
-			return -RT_EIO;
-		if (cmd.resp[0] & R5_FUNCTION_NUMBER)
-			return -RT_ERROR;
-		if (cmd.resp[0] & R5_OUT_OF_RANGE)
-			return -RT_ERROR;
-	}
-
-	if (!rw || raw) 
-	{
-		if (controller_is_spi(card->host))
-			*pdata = (cmd.resp[0] >> 8) & 0xFF;
-		else
-			*pdata = cmd.resp[0] & 0xFF;
-	}
-
-	return 0;
+    struct rt_mmcsd_cmd cmd;
+    rt_int32_t err;
+
+    RT_ASSERT(card != RT_NULL);
+    RT_ASSERT(fn <= SDIO_MAX_FUNCTIONS);
+
+    if (reg_addr & ~SDIO_ARG_CMD53_REG_MASK)
+        return -RT_ERROR;
+
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+
+    cmd.cmd_code = SD_IO_RW_DIRECT;
+    cmd.arg = rw ? SDIO_ARG_CMD52_WRITE : SDIO_ARG_CMD52_READ;
+    cmd.arg |= fn << SDIO_ARG_CMD52_FUNC_SHIFT;
+    cmd.arg |= raw ? SDIO_ARG_CMD52_RAW_FLAG : 0x00000000;
+    cmd.arg |= reg_addr << SDIO_ARG_CMD52_REG_SHIFT;
+    cmd.arg |= *pdata;
+    cmd.flags = RESP_SPI_R5 | RESP_R5 | CMD_AC;
+
+    err = mmcsd_send_cmd(card->host, &cmd, 0);
+    if (err)
+        return err;
+
+    if (!controller_is_spi(card->host)) 
+    {
+        if (cmd.resp[0] & R5_ERROR)
+            return -RT_EIO;
+        if (cmd.resp[0] & R5_FUNCTION_NUMBER)
+            return -RT_ERROR;
+        if (cmd.resp[0] & R5_OUT_OF_RANGE)
+            return -RT_ERROR;
+    }
+
+    if (!rw || raw) 
+    {
+        if (controller_is_spi(card->host))
+            *pdata = (cmd.resp[0] >> 8) & 0xFF;
+        else
+            *pdata = cmd.resp[0] & 0xFF;
+    }
+
+    return 0;
 }
 
-rt_int32_t sdio_io_rw_extended(struct rt_mmcsd_card *card, rt_int32_t rw, rt_uint32_t fn,
-	rt_uint32_t addr, rt_int32_t op_code, rt_uint8_t *buf, rt_uint32_t blocks, rt_uint32_t blksize)
+rt_int32_t sdio_io_rw_extended(struct rt_mmcsd_card *card,
+                               rt_int32_t            rw,
+                               rt_uint32_t           fn,
+                               rt_uint32_t           addr,
+                               rt_int32_t            op_code,
+                               rt_uint8_t           *buf,
+                               rt_uint32_t           blocks,
+                               rt_uint32_t           blksize)
 {
-	struct rt_mmcsd_req req;
-	struct rt_mmcsd_cmd cmd;
-	struct rt_mmcsd_data data;
-
-	RT_ASSERT(card != RT_NULL);
-	RT_ASSERT(fn <= SDIO_MAX_FUNCTIONS);
-	RT_ASSERT(blocks != 1 || blksize <= 512);
-	RT_ASSERT(blocks != 0);
-	RT_ASSERT(blksize != 0);
-
-	if (addr & ~SDIO_ARG_CMD53_REG_MASK)
-		return -RT_ERROR;
-
-	rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
-	rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
-	rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
-
-	req.cmd = &cmd;
-	req.data = &data;
-
-	cmd.cmd_code = SD_IO_RW_EXTENDED;
-	cmd.arg = rw ? SDIO_ARG_CMD53_WRITE : SDIO_ARG_CMD53_READ;
-	cmd.arg |= fn << SDIO_ARG_CMD53_FUNC_SHIFT;
-	cmd.arg |= op_code ? SDIO_ARG_CMD53_INCREMENT : 0x00000000;
-	cmd.arg |= addr << SDIO_ARG_CMD53_REG_SHIFT;
-	if (blocks == 1 && blksize <= 512)
-		cmd.arg |= (blksize == 512) ? 0 : blksize;      /* byte mode */
-	else
-		cmd.arg |= SDIO_ARG_CMD53_BLOCK_MODE | blocks;  /* block mode */
-	cmd.flags = RESP_SPI_R5 | RESP_R5 | CMD_ADTC;
-
-	data.blksize = blksize;
-	data.blks = blocks;
-	data.flags = rw ? DATA_DIR_WRITE : DATA_DIR_READ;
-	data.buf = (rt_uint32_t *)buf;
-
-	mmcsd_set_data_timeout(&data, card);
-
-	mmcsd_send_request(card->host, &req);
-
-	if (cmd.err)
-		return cmd.err;
-	if (data.err)
-		return data.err;
-
-	if (!controller_is_spi(card->host)) 
-	{
-		if (cmd.resp[0] & R5_ERROR)
-			return -RT_EIO;
-		if (cmd.resp[0] & R5_FUNCTION_NUMBER)
-			return -RT_ERROR;
-		if (cmd.resp[0] & R5_OUT_OF_RANGE)
-			return -RT_ERROR;
-	}
-
-	return 0;
+    struct rt_mmcsd_req req;
+    struct rt_mmcsd_cmd cmd;
+    struct rt_mmcsd_data data;
+
+    RT_ASSERT(card != RT_NULL);
+    RT_ASSERT(fn <= SDIO_MAX_FUNCTIONS);
+    RT_ASSERT(blocks != 1 || blksize <= 512);
+    RT_ASSERT(blocks != 0);
+    RT_ASSERT(blksize != 0);
+
+    if (addr & ~SDIO_ARG_CMD53_REG_MASK)
+        return -RT_ERROR;
+
+    rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
+    rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
+    rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
+
+    req.cmd = &cmd;
+    req.data = &data;
+
+    cmd.cmd_code = SD_IO_RW_EXTENDED;
+    cmd.arg = rw ? SDIO_ARG_CMD53_WRITE : SDIO_ARG_CMD53_READ;
+    cmd.arg |= fn << SDIO_ARG_CMD53_FUNC_SHIFT;
+    cmd.arg |= op_code ? SDIO_ARG_CMD53_INCREMENT : 0x00000000;
+    cmd.arg |= addr << SDIO_ARG_CMD53_REG_SHIFT;
+    if (blocks == 1 && blksize <= 512)
+        cmd.arg |= (blksize == 512) ? 0 : blksize;      /* byte mode */
+    else
+        cmd.arg |= SDIO_ARG_CMD53_BLOCK_MODE | blocks;  /* block mode */
+    cmd.flags = RESP_SPI_R5 | RESP_R5 | CMD_ADTC;
+
+    data.blksize = blksize;
+    data.blks = blocks;
+    data.flags = rw ? DATA_DIR_WRITE : DATA_DIR_READ;
+    data.buf = (rt_uint32_t *)buf;
+
+    mmcsd_set_data_timeout(&data, card);
+
+    mmcsd_send_request(card->host, &req);
+
+    if (cmd.err)
+        return cmd.err;
+    if (data.err)
+        return data.err;
+
+    if (!controller_is_spi(card->host)) 
+    {
+        if (cmd.resp[0] & R5_ERROR)
+            return -RT_EIO;
+        if (cmd.resp[0] & R5_FUNCTION_NUMBER)
+            return -RT_ERROR;
+        if (cmd.resp[0] & R5_OUT_OF_RANGE)
+            return -RT_ERROR;
+    }
+
+    return 0;
 }
 
 rt_inline rt_uint32_t sdio_max_block_size(struct rt_sdio_function *func)
 {
-	rt_uint32_t size = MIN(func->card->host->max_seg_size,
-			    func->card->host->max_blk_size);
-	size = MIN(size, func->max_blk_size);
-	return MIN(size, 512u); /* maximum size for byte mode */
+    rt_uint32_t size = MIN(func->card->host->max_seg_size,
+                           func->card->host->max_blk_size);
+    size = MIN(size, func->max_blk_size);
+
+    return MIN(size, 512u); /* maximum size for byte mode */
 }
 
-static rt_int32_t sdio_io_rw_extended_block(struct rt_sdio_function *func, rt_int32_t rw,
-	rt_uint32_t addr, rt_int32_t op_code, rt_uint8_t *buf, rt_uint32_t len)
+static rt_int32_t sdio_io_rw_extended_block(struct rt_sdio_function *func,
+                                            rt_int32_t               rw,
+                                            rt_uint32_t              addr,
+                                            rt_int32_t               op_code,
+                                            rt_uint8_t              *buf,
+                                            rt_uint32_t              len)
 {
-	rt_int32_t  ret;
-	rt_uint32_t left_size;
-	rt_uint32_t max_blks, blks;
-	
-	left_size = len;
-
-	/* Do the bulk of the transfer using block mode (if supported). */
-	if (func->card->cccr.multi_block && (len > sdio_max_block_size(func))) {
-		max_blks = MIN(func->card->host->max_blk_count,
-			func->card->host->max_seg_size / func->cur_blk_size);
-		max_blks = MIN(max_blks, 511u);
-
-		while (left_size > func->cur_blk_size) {
-
-			blks = left_size / func->cur_blk_size;
-			if (blks > max_blks)
-				blks = max_blks;
-			len = blks * func->cur_blk_size;
-
-			ret = sdio_io_rw_extended(func->card, rw, func->num, 
-				  addr, op_code, buf, blks, func->cur_blk_size);
-			if (ret)
-				return ret;
-
-			left_size -= len;
-			buf += len;
-			if (op_code)
-				addr += len;
-		}
-	}
-
-	while (left_size > 0) {
-		len = MIN(left_size, sdio_max_block_size(func));
-
-		ret = sdio_io_rw_extended(func->card, rw, func->num, 
-				  addr, op_code, buf, 1, len);
-		if (ret)
-			return ret;
-
-		left_size -= len;
-		buf += len;
-		if (op_code)
-			addr += len;
-	}
-
-	return 0;
+    rt_int32_t  ret;
+    rt_uint32_t left_size;
+    rt_uint32_t max_blks, blks;
+    
+    left_size = len;
+
+    /* Do the bulk of the transfer using block mode (if supported). */
+    if (func->card->cccr.multi_block && (len > sdio_max_block_size(func)))
+    {
+        max_blks = MIN(func->card->host->max_blk_count,
+                       func->card->host->max_seg_size / func->cur_blk_size);
+        max_blks = MIN(max_blks, 511u);
+
+        while (left_size > func->cur_blk_size)
+        {
+            blks = left_size / func->cur_blk_size;
+            if (blks > max_blks)
+                blks = max_blks;
+            len = blks * func->cur_blk_size;
+
+            ret = sdio_io_rw_extended(func->card, rw, func->num, 
+                  addr, op_code, buf, blks, func->cur_blk_size);
+            if (ret)
+                return ret;
+
+            left_size -= len;
+            buf += len;
+            if (op_code)
+                addr += len;
+        }
+    }
+
+    while (left_size > 0)
+    {
+        len = MIN(left_size, sdio_max_block_size(func));
+
+        ret = sdio_io_rw_extended(func->card, rw, func->num, 
+                  addr, op_code, buf, 1, len);
+        if (ret)
+            return ret;
+
+        left_size -= len;
+        buf += len;
+        if (op_code)
+            addr += len;
+    }
+
+    return 0;
 }
 
-
 rt_uint8_t sdio_io_readb(struct rt_sdio_function *func, 
-			 rt_uint32_t reg, rt_int32_t *err)
+                         rt_uint32_t              reg,
+                         rt_int32_t              *err)
 {
-	rt_uint8_t data;
-	rt_int32_t ret;
+    rt_uint8_t data;
+    rt_int32_t ret;
 
- 	ret = sdio_io_rw_direct(func->card, 0, func->num, reg, &data, 0);
+    ret = sdio_io_rw_direct(func->card, 0, func->num, reg, &data, 0);
 
-	if (err)
-	{
-		*err = ret;
-	}
+    if (err)
+    {
+        *err = ret;
+    }
 
-	return data;
+    return data;
 }
 
 rt_int32_t sdio_io_writeb(struct rt_sdio_function *func, 
-			  rt_uint32_t reg, rt_uint8_t data)
+                          rt_uint32_t              reg,
+                          rt_uint8_t               data)
 {
- 	return sdio_io_rw_direct(func->card, 1, func->num, reg, &data, 0);
+    return sdio_io_rw_direct(func->card, 1, func->num, reg, &data, 0);
 }
 
-rt_uint16_t sdio_io_readw(struct rt_sdio_function *func, rt_uint32_t addr, rt_int32_t *err)
+rt_uint16_t sdio_io_readw(struct rt_sdio_function *func,
+                          rt_uint32_t              addr,
+                          rt_int32_t              *err)
 {
-	rt_int32_t ret;
-	rt_uint32_t dmabuf;
+    rt_int32_t ret;
+    rt_uint32_t dmabuf;
 
-	if (err)
-		*err = 0;
+    if (err)
+        *err = 0;
 
-	ret = sdio_io_rw_extended_block(func, 0, addr, 1, (rt_uint8_t *)&dmabuf, 2);
-	if (ret) 
-	{
-		if (err)
-			*err = ret;
-	}
+    ret = sdio_io_rw_extended_block(func, 0, addr, 1, (rt_uint8_t *)&dmabuf, 2);
+    if (ret) 
+    {
+        if (err)
+            *err = ret;
+    }
 
-	return (rt_uint16_t)dmabuf;
+    return (rt_uint16_t)dmabuf;
 }
 
-rt_int32_t sdio_io_writew(struct rt_sdio_function *func, rt_uint16_t data, rt_uint32_t addr)
+rt_int32_t sdio_io_writew(struct rt_sdio_function *func,
+                          rt_uint16_t              data,
+                          rt_uint32_t              addr)
 {
-	rt_uint32_t dmabuf = data;
+    rt_uint32_t dmabuf = data;
 
-	return sdio_io_rw_extended_block(func, 1, addr, 1, (rt_uint8_t *)&dmabuf, 2);
+    return sdio_io_rw_extended_block(func, 1, addr, 1, (rt_uint8_t *)&dmabuf, 2);
 }
 
-rt_uint32_t sdio_io_readl(struct rt_sdio_function *func, rt_uint32_t addr, rt_int32_t *err)
+rt_uint32_t sdio_io_readl(struct rt_sdio_function *func,
+                          rt_uint32_t              addr,
+                          rt_int32_t              *err)
 {
-	rt_int32_t ret;
-	rt_uint32_t dmabuf;
+    rt_int32_t ret;
+    rt_uint32_t dmabuf;
 
-	if (err)
-		*err = 0;
+    if (err)
+        *err = 0;
 
-	ret = sdio_io_rw_extended_block(func, 0, addr, 1, (rt_uint8_t *)&dmabuf, 4);
-	if (ret) 
-	{
-		if (err)
-			*err = ret;
-	}
+    ret = sdio_io_rw_extended_block(func, 0, addr, 1, (rt_uint8_t *)&dmabuf, 4);
+    if (ret) 
+    {
+        if (err)
+            *err = ret;
+    }
 
-	return dmabuf;
+    return dmabuf;
 }
 
-rt_int32_t sdio_io_writel(struct rt_sdio_function *func, rt_uint32_t data, rt_uint32_t addr)
+rt_int32_t sdio_io_writel(struct rt_sdio_function *func,
+                          rt_uint32_t              data,
+                          rt_uint32_t              addr)
 {
-	rt_uint32_t dmabuf = data;
+    rt_uint32_t dmabuf = data;
 
-	return sdio_io_rw_extended_block(func, 1, addr, 1, (rt_uint8_t *)&dmabuf, 4);
+    return sdio_io_rw_extended_block(func, 1, addr, 1, (rt_uint8_t *)&dmabuf, 4);
 }
 
 rt_int32_t sdio_io_read_multi_fifo_b(struct rt_sdio_function *func, 
-				     rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t len)
+                                     rt_uint32_t              addr,
+                                     rt_uint8_t              *buf,
+                                     rt_uint32_t              len)
 {
-	return sdio_io_rw_extended_block(func, 0, addr, 0, buf, len);
+    return sdio_io_rw_extended_block(func, 0, addr, 0, buf, len);
 }
 
 rt_int32_t sdio_io_write_multi_fifo_b(struct rt_sdio_function *func, 
-				      rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t len)
+                                      rt_uint32_t              addr,
+                                      rt_uint8_t              *buf,
+                                      rt_uint32_t              len)
 {
-	return sdio_io_rw_extended_block(func, 1, addr, 0, buf, len);
+    return sdio_io_rw_extended_block(func, 1, addr, 0, buf, len);
 }
 
 rt_int32_t sdio_io_read_multi_incr_b(struct rt_sdio_function *func, 
-				     rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t len)
+                                     rt_uint32_t              addr,
+                                     rt_uint8_t              *buf,
+                                     rt_uint32_t              len)
 {
-	return sdio_io_rw_extended_block(func, 0, addr, 1, buf, len);
+    return sdio_io_rw_extended_block(func, 0, addr, 1, buf, len);
 }
 
 rt_int32_t sdio_io_write_multi_incr_b(struct rt_sdio_function *func, 
-				      rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t len)
+                                      rt_uint32_t              addr,
+                                      rt_uint8_t              *buf,
+                                      rt_uint32_t              len)
 {
-	return sdio_io_rw_extended_block(func, 1, addr, 1, buf, len);
+    return sdio_io_rw_extended_block(func, 1, addr, 1, buf, len);
 }
 
 static rt_int32_t sdio_read_cccr(struct rt_mmcsd_card *card)
 {
-	rt_int32_t ret;
-	rt_int32_t cccr_version;
-	rt_uint8_t data;
-
-	rt_memset(&card->cccr, 0, sizeof(struct rt_sdio_cccr));
-
-	data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CCCR_REV, &ret);
-	if (ret)
-		goto out;
-
-	cccr_version = data & 0x0f;
-
-	if (cccr_version > SDIO_CCCR_REV_1_20) 
-	{
-		rt_kprintf("unrecognised CCCR structure version %d\n", cccr_version);
-		return -RT_ERROR;
-	}
-
-	card->cccr.sdio_version = (data & 0xf0) >> 4;
-
-	data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CARD_CAPS, &ret);
-	if (ret)
-		goto out;
-
-	if (data & SDIO_CCCR_CAP_SMB)
-		card->cccr.multi_block = 1;
-	if (data & SDIO_CCCR_CAP_LSC)
-		card->cccr.low_speed = 1;
-	if (data & SDIO_CCCR_CAP_4BLS)
-		card->cccr.low_speed_4 = 1;
-	if (data & SDIO_CCCR_CAP_4BLS)
-		card->cccr.bus_width = 1;
-
-	if (cccr_version >= SDIO_CCCR_REV_1_10) 
-	{
-		data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_POWER_CTRL, &ret);
-		if (ret)
-			goto out;
-
-		if (data & SDIO_POWER_SMPC)
-			card->cccr.power_ctrl = 1;
-	}
-
-	if (cccr_version >= SDIO_CCCR_REV_1_20) 
-	{
-		data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, &ret);
-		if (ret)
-			goto out;
-
-		if (data & SDIO_SPEED_SHS)
-			card->cccr.high_speed = 1;
-	}
+    rt_int32_t ret;
+    rt_int32_t cccr_version;
+    rt_uint8_t data;
+
+    rt_memset(&card->cccr, 0, sizeof(struct rt_sdio_cccr));
+
+    data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CCCR_REV, &ret);
+    if (ret)
+        goto out;
+
+    cccr_version = data & 0x0f;
+
+    if (cccr_version > SDIO_CCCR_REV_1_20) 
+    {
+        rt_kprintf("unrecognised CCCR structure version %d\n", cccr_version);
+
+        return -RT_ERROR;
+    }
+
+    card->cccr.sdio_version = (data & 0xf0) >> 4;
+
+    data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CARD_CAPS, &ret);
+    if (ret)
+        goto out;
+
+    if (data & SDIO_CCCR_CAP_SMB)
+        card->cccr.multi_block = 1;
+    if (data & SDIO_CCCR_CAP_LSC)
+        card->cccr.low_speed = 1;
+    if (data & SDIO_CCCR_CAP_4BLS)
+        card->cccr.low_speed_4 = 1;
+    if (data & SDIO_CCCR_CAP_4BLS)
+        card->cccr.bus_width = 1;
+
+    if (cccr_version >= SDIO_CCCR_REV_1_10) 
+    {
+        data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_POWER_CTRL, &ret);
+        if (ret)
+            goto out;
+
+        if (data & SDIO_POWER_SMPC)
+            card->cccr.power_ctrl = 1;
+    }
+
+    if (cccr_version >= SDIO_CCCR_REV_1_20) 
+    {
+        data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, &ret);
+        if (ret)
+            goto out;
+
+        if (data & SDIO_SPEED_SHS)
+            card->cccr.high_speed = 1;
+    }
 
 out:
-	return ret;
+    return ret;
 }
 
 static rt_int32_t cistpl_funce_func0(struct rt_mmcsd_card *card,
-			       const rt_uint8_t *buf, rt_uint32_t size)
+                                     const rt_uint8_t     *buf,
+                                     rt_uint32_t           size)
 {
-	if (size < 0x04 || buf[0] != 0)
-		return -RT_ERROR;
+    if (size < 0x04 || buf[0] != 0)
+        return -RT_ERROR;
 
-	/* TPLFE_FN0_BLK_SIZE */
-	card->cis.func0_blk_size = buf[1] | (buf[2] << 8);
+    /* TPLFE_FN0_BLK_SIZE */
+    card->cis.func0_blk_size = buf[1] | (buf[2] << 8);
 
-	/* TPLFE_MAX_TRAN_SPEED */
-	card->cis.max_tran_speed = speed_value[(buf[3] >> 3) & 15] *
-			    speed_unit[buf[3] & 7];
+    /* TPLFE_MAX_TRAN_SPEED */
+    card->cis.max_tran_speed = speed_value[(buf[3] >> 3) & 15] *
+                speed_unit[buf[3] & 7];
 
-	return 0;
+    return 0;
 }
 
 static rt_int32_t cistpl_funce_func(struct rt_sdio_function *func,
-			     const rt_uint8_t *buf, rt_uint32_t size)
+                                    const rt_uint8_t        *buf,
+                                    rt_uint32_t              size)
 {
-	rt_uint32_t version;
-	rt_uint32_t min_size;
+    rt_uint32_t version;
+    rt_uint32_t min_size;
 
-	version = func->card->cccr.sdio_version;
-	min_size = (version == SDIO_SDIO_REV_1_00) ? 28 : 42;
+    version = func->card->cccr.sdio_version;
+    min_size = (version == SDIO_SDIO_REV_1_00) ? 28 : 42;
 
-	if (size < min_size || buf[0] != 1)
-		return -RT_ERROR;
+    if (size < min_size || buf[0] != 1)
+        return -RT_ERROR;
 
-	/* TPLFE_MAX_BLK_SIZE */
-	func->max_blk_size = buf[12] | (buf[13] << 8);
+    /* TPLFE_MAX_BLK_SIZE */
+    func->max_blk_size = buf[12] | (buf[13] << 8);
 
-	/* TPLFE_ENABLE_TIMEOUT_VAL, present in ver 1.1 and above */
-	if (version > SDIO_SDIO_REV_1_00)
-		func->enable_timeout_val = (buf[28] | (buf[29] << 8)) * 10;
-	else
-		func->enable_timeout_val = 1000; /* 1000ms */
+    /* TPLFE_ENABLE_TIMEOUT_VAL, present in ver 1.1 and above */
+    if (version > SDIO_SDIO_REV_1_00)
+        func->enable_timeout_val = (buf[28] | (buf[29] << 8)) * 10;
+    else
+        func->enable_timeout_val = 1000; /* 1000ms */
 
-	return 0;
+    return 0;
 }
 
 static rt_int32_t sdio_read_cis(struct rt_sdio_function *func)
 {
-	rt_int32_t ret;
-	struct rt_sdio_function_tuple *curr, **prev;
-	rt_uint32_t i, cisptr = 0;
-	rt_uint8_t data;
-	rt_uint8_t tpl_code, tpl_link;
-
-	struct rt_mmcsd_card *card = func->card;
-	struct rt_sdio_function *func0 = card->sdio_function[0];
-
-	RT_ASSERT(func0 != RT_NULL);
-
-	for (i = 0; i < 3; i++)
-	{
-		data = sdio_io_readb(func0, 
-			SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_CIS + i, &ret);
-		if (ret)
-			return ret;
-		cisptr |= data << (i * 8);
-	}
-
-	prev = &func->tuples;
-
-	do {
-		tpl_code = sdio_io_readb(func0, cisptr++, &ret);
-		if (ret)
-			break;
-		tpl_link = sdio_io_readb(func0, cisptr++, &ret);
-		if (ret)
-			break;
-
-		if ((tpl_code == CISTPL_END) || (tpl_link == 0xff))
-			break;
-
-		if (tpl_code == CISTPL_NULL)
-			continue;
-
-
-		curr = rt_malloc(sizeof(struct rt_sdio_function_tuple) + tpl_link);
-		if (!curr)
-			return -RT_ENOMEM;
-		curr->data = (rt_uint8_t *)curr + sizeof(struct rt_sdio_function_tuple);
-
-		for (i = 0; i < tpl_link; i++) 
-		{
-			curr->data[i] = sdio_io_readb(func0, cisptr + i, &ret);
-			if (ret)
-				break;
-		}
-		if (ret) 
-		{
-			rt_free(curr);
-			break;
-		}
-
-		switch (tpl_code)
-		{
-		case CISTPL_MANFID:
-			if (tpl_link < 4)
-			{
-				rt_kprintf("bad CISTPL_MANFID length\n");
-				break;
-			}
-			if (func->num != 0)
-			{
-				func->manufacturer = curr->data[0];
-				func->manufacturer |= curr->data[1] << 8;
-				func->product = curr->data[2];
-				func->product |= curr->data[3] << 8;
-			}
-			else
-			{
-				card->cis.manufacturer = curr->data[0];
-				card->cis.manufacturer |= curr->data[1] << 8;
-				card->cis.product = curr->data[2];
-				card->cis.product |= curr->data[3] << 8;
-			}
-			break;
-		case CISTPL_FUNCE:
-			if (func->num != 0)
-				ret = cistpl_funce_func(func, curr->data, tpl_link);
-			else
-				ret = cistpl_funce_func0(card, curr->data, tpl_link);
-
-			if (ret)
-			{
-				rt_kprintf("bad CISTPL_FUNCE size %u "
-				       "type %u\n", tpl_link, curr->data[0]);
-			}
-
-			break;
-		case CISTPL_VERS_1:
-			if (tpl_link < 2)
-			{
-				rt_kprintf("CISTPL_VERS_1 too short\n");
-			}
-			break;
-		default: 
-			/* this tuple is unknown to the core */
-			curr->next = RT_NULL;
-			curr->code = tpl_code;
-			curr->size = tpl_link;
-			*prev = curr;
-			prev = &curr->next;
-			rt_kprintf( "function %d, CIS tuple code %#x, length %d\n",
-			    func->num, tpl_code, tpl_link);
-			break;
-		}
-
-		cisptr += tpl_link;
-	} while (1);
-
-	/*
-	 * Link in all unknown tuples found in the common CIS so that
-	 * drivers don't have to go digging in two places.
-	 */
-	if (func->num != 0)
-		*prev = func0->tuples;
-
-	return ret;
+    rt_int32_t ret;
+    struct rt_sdio_function_tuple *curr, **prev;
+    rt_uint32_t i, cisptr = 0;
+    rt_uint8_t data;
+    rt_uint8_t tpl_code, tpl_link;
+
+    struct rt_mmcsd_card *card = func->card;
+    struct rt_sdio_function *func0 = card->sdio_function[0];
+
+    RT_ASSERT(func0 != RT_NULL);
+
+    for (i = 0; i < 3; i++)
+    {
+        data = sdio_io_readb(func0, 
+            SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_CIS + i, &ret);
+        if (ret)
+            return ret;
+        cisptr |= data << (i * 8);
+    }
+
+    prev = &func->tuples;
+
+    do {
+        tpl_code = sdio_io_readb(func0, cisptr++, &ret);
+        if (ret)
+            break;
+        tpl_link = sdio_io_readb(func0, cisptr++, &ret);
+        if (ret)
+            break;
+
+        if ((tpl_code == CISTPL_END) || (tpl_link == 0xff))
+            break;
+
+        if (tpl_code == CISTPL_NULL)
+            continue;
+
+
+        curr = rt_malloc(sizeof(struct rt_sdio_function_tuple) + tpl_link);
+        if (!curr)
+            return -RT_ENOMEM;
+        curr->data = (rt_uint8_t *)curr + sizeof(struct rt_sdio_function_tuple);
+
+        for (i = 0; i < tpl_link; i++) 
+        {
+            curr->data[i] = sdio_io_readb(func0, cisptr + i, &ret);
+            if (ret)
+                break;
+        }
+        if (ret) 
+        {
+            rt_free(curr);
+            break;
+        }
+
+        switch (tpl_code)
+        {
+        case CISTPL_MANFID:
+            if (tpl_link < 4)
+            {
+                rt_kprintf("bad CISTPL_MANFID length\n");
+                break;
+            }
+            if (func->num != 0)
+            {
+                func->manufacturer = curr->data[0];
+                func->manufacturer |= curr->data[1] << 8;
+                func->product = curr->data[2];
+                func->product |= curr->data[3] << 8;
+            }
+            else
+            {
+                card->cis.manufacturer = curr->data[0];
+                card->cis.manufacturer |= curr->data[1] << 8;
+                card->cis.product = curr->data[2];
+                card->cis.product |= curr->data[3] << 8;
+            }
+            break;
+        case CISTPL_FUNCE:
+            if (func->num != 0)
+                ret = cistpl_funce_func(func, curr->data, tpl_link);
+            else
+                ret = cistpl_funce_func0(card, curr->data, tpl_link);
+
+            if (ret)
+            {
+                rt_kprintf("bad CISTPL_FUNCE size %u "
+                       "type %u\n", tpl_link, curr->data[0]);
+            }
+
+            break;
+        case CISTPL_VERS_1:
+            if (tpl_link < 2)
+            {
+                rt_kprintf("CISTPL_VERS_1 too short\n");
+            }
+            break;
+        default: 
+            /* this tuple is unknown to the core */
+            curr->next = RT_NULL;
+            curr->code = tpl_code;
+            curr->size = tpl_link;
+            *prev = curr;
+            prev = &curr->next;
+            rt_kprintf( "function %d, CIS tuple code %#x, length %d\n",
+                func->num, tpl_code, tpl_link);
+            break;
+        }
+
+        cisptr += tpl_link;
+    } while (1);
+
+    /*
+     * Link in all unknown tuples found in the common CIS so that
+     * drivers don't have to go digging in two places.
+     */
+    if (func->num != 0)
+        *prev = func0->tuples;
+
+    return ret;
 }
 
 
 void sdio_free_cis(struct rt_sdio_function *func)
 {
-	struct rt_sdio_function_tuple *tuple, *tmp;
-	struct rt_mmcsd_card *card = func->card;
+    struct rt_sdio_function_tuple *tuple, *tmp;
+    struct rt_mmcsd_card *card = func->card;
 
-	tuple = func->tuples;
+    tuple = func->tuples;
 
-	while (tuple && ((tuple != card->sdio_function[0]->tuples) || (!func->num))) 
-	{
-		tmp = tuple;
-		tuple = tuple->next;
-		rt_free(tmp);
-	}
+    while (tuple && ((tuple != card->sdio_function[0]->tuples) || (!func->num))) 
+    {
+        tmp = tuple;
+        tuple = tuple->next;
+        rt_free(tmp);
+    }
 
-	func->tuples = RT_NULL;
+    func->tuples = RT_NULL;
 }
 
-
-
 static rt_int32_t sdio_read_fbr(struct rt_sdio_function *func)
 {
-	rt_int32_t ret;
-	rt_uint8_t data;
-	struct rt_sdio_function *func0 = func->card->sdio_function[0];
+    rt_int32_t ret;
+    rt_uint8_t data;
+    struct rt_sdio_function *func0 = func->card->sdio_function[0];
 
-	data = sdio_io_readb(func0, 
-		SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_STD_FUNC_IF, &ret);
-	if (ret)
-		goto err;
+    data = sdio_io_readb(func0, 
+        SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_STD_FUNC_IF, &ret);
+    if (ret)
+        goto err;
 
-	data &= 0x0f;
+    data &= 0x0f;
 
-	if (data == 0x0f) 
-	{
-		data = sdio_io_readb(func0, 
-			SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_STD_IF_EXT, &ret);
-		if (ret)
-			goto err;
-	}
+    if (data == 0x0f) 
+    {
+        data = sdio_io_readb(func0, 
+            SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_STD_IF_EXT, &ret);
+        if (ret)
+            goto err;
+    }
 
-	func->func_code = data;
+    func->func_code = data;
 
 err:
-	return ret;
+    return ret;
 }
 
 
-static rt_int32_t sdio_initialize_function(struct rt_mmcsd_card *card, rt_uint32_t func_num)
+static rt_int32_t sdio_initialize_function(struct rt_mmcsd_card *card,
+                                           rt_uint32_t           func_num)
 {
-	rt_int32_t ret;
-	struct rt_sdio_function *func;
+    rt_int32_t ret;
+    struct rt_sdio_function *func;
 
-	RT_ASSERT(func_num <= SDIO_MAX_FUNCTIONS);
+    RT_ASSERT(func_num <= SDIO_MAX_FUNCTIONS);
 
-	func = rt_malloc(sizeof(struct rt_sdio_function));
-	if (!func)
-	{
-		rt_kprintf("malloc rt_sdio_function failed\n");
-		ret = -RT_ENOMEM;
-		goto err;
-	}
-	rt_memset(func, 0, sizeof(struct rt_sdio_function));
+    func = rt_malloc(sizeof(struct rt_sdio_function));
+    if (!func)
+    {
+        rt_kprintf("malloc rt_sdio_function failed\n");
+        ret = -RT_ENOMEM;
+        goto err;
+    }
+    rt_memset(func, 0, sizeof(struct rt_sdio_function));
 
-	func->card = card;
-	func->num = func_num;
+    func->card = card;
+    func->num = func_num;
 
-	ret = sdio_read_fbr(func);
-	if (ret)
-		goto err1;
+    ret = sdio_read_fbr(func);
+    if (ret)
+        goto err1;
 
-	ret = sdio_read_cis(func);
-	if (ret)
-		goto err1;
+    ret = sdio_read_cis(func);
+    if (ret)
+        goto err1;
 
-	card->sdio_function[func_num] = func;
+    card->sdio_function[func_num] = func;
 
-	return 0;
+    return 0;
 
 err1:
-	sdio_free_cis(func);
-	rt_free(func);
-	card->sdio_function[func_num] = RT_NULL;
+    sdio_free_cis(func);
+    rt_free(func);
+    card->sdio_function[func_num] = RT_NULL;
 err:
-	return ret;
+    return ret;
 }
 
-
 static rt_int32_t sdio_set_highspeed(struct rt_mmcsd_card *card)
 {
-	rt_int32_t ret;
-	rt_uint8_t speed;
+    rt_int32_t ret;
+    rt_uint8_t speed;
 
-	if (!(card->host->flags & MMCSD_SUP_HIGHSPEED))
-		return 0;
+    if (!(card->host->flags & MMCSD_SUP_HIGHSPEED))
+        return 0;
 
-	if (!card->cccr.high_speed)
-		return 0;
+    if (!card->cccr.high_speed)
+        return 0;
 
-	speed = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, &ret);
-	if (ret)
-		return ret;
+    speed = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, &ret);
+    if (ret)
+        return ret;
 
-	speed |= SDIO_SPEED_EHS;
+    speed |= SDIO_SPEED_EHS;
 
-	ret = sdio_io_writeb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, speed);
-	if (ret)
-		return ret;
+    ret = sdio_io_writeb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, speed);
+    if (ret)
+        return ret;
 
-	card->flags |= CARD_FLAG_HIGHSPEED;
+    card->flags |= CARD_FLAG_HIGHSPEED;
 
-	return 0;
+    return 0;
 }
 
 static rt_int32_t sdio_set_bus_wide(struct rt_mmcsd_card *card)
 {
-	rt_int32_t ret;
-	rt_uint8_t busif;
+    rt_int32_t ret;
+    rt_uint8_t busif;
 
-	if (!(card->host->flags & MMCSD_BUSWIDTH_4))
-		return 0;
+    if (!(card->host->flags & MMCSD_BUSWIDTH_4))
+        return 0;
 
-	if (card->cccr.low_speed && !card->cccr.bus_width)
-		return 0;
+    if (card->cccr.low_speed && !card->cccr.bus_width)
+        return 0;
 
-	busif = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_BUS_IF, &ret);
-	if (ret)
-		return ret;
+    busif = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_BUS_IF, &ret);
+    if (ret)
+        return ret;
 
-	busif |= SDIO_BUS_WIDTH_4BIT;
+    busif |= SDIO_BUS_WIDTH_4BIT;
 
-	ret = sdio_io_writeb(card->sdio_function[0], SDIO_REG_CCCR_BUS_IF, busif);
-	if (ret)
-		return ret;
+    ret = sdio_io_writeb(card->sdio_function[0], SDIO_REG_CCCR_BUS_IF, busif);
+    if (ret)
+        return ret;
 
-	mmcsd_set_bus_width(card->host, MMCSD_BUS_WIDTH_4);
+    mmcsd_set_bus_width(card->host, MMCSD_BUS_WIDTH_4);
 
-	return 0;
+    return 0;
 }
 
-
 static rt_int32_t sdio_register_card(struct rt_mmcsd_card *card)
 {
-	struct sdio_card *sc;
-	struct sdio_driver *sd;
-	rt_list_t *l;
-
-	sc = rt_malloc(sizeof(struct sdio_card));
-	if (sc == RT_NULL)
-	{
-		rt_kprintf("malloc sdio card failed\n");
-		return -RT_ENOMEM;
-	}
-
-	sc->card = card;
-	rt_list_insert_after(&sdio_cards, &sc->list);
-
-	if (rt_list_isempty(&sdio_drivers))
-	{
-		goto out;
-	}
-
-	for (l = (&sdio_drivers)->next; l != &sdio_drivers; l = l->next)
-	{
-		sd = (struct sdio_driver *)rt_list_entry(l, struct sdio_driver, list);
-		if (sdio_match_card(card, sd->drv->id))
-		{
-			sd->drv->probe(card);
-		}
-	}
+    struct sdio_card *sc;
+    struct sdio_driver *sd;
+    rt_list_t *l;
+
+    sc = rt_malloc(sizeof(struct sdio_card));
+    if (sc == RT_NULL)
+    {
+        rt_kprintf("malloc sdio card failed\n");
+        return -RT_ENOMEM;
+    }
+
+    sc->card = card;
+    rt_list_insert_after(&sdio_cards, &sc->list);
+
+    if (rt_list_isempty(&sdio_drivers))
+    {
+        goto out;
+    }
+
+    for (l = (&sdio_drivers)->next; l != &sdio_drivers; l = l->next)
+    {
+        sd = (struct sdio_driver *)rt_list_entry(l, struct sdio_driver, list);
+        if (sdio_match_card(card, sd->drv->id))
+        {
+            sd->drv->probe(card);
+        }
+    }
 
 out:
-	return 0;
+    return 0;
 }
 
-
 static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr)
 {
-	rt_int32_t err = 0;
-	rt_int32_t i, function_num;
-	rt_uint32_t  cmd5_resp;
-	struct rt_mmcsd_card *card;
-
-	err = sdio_io_send_op_cond(host, ocr, &cmd5_resp);
-	if (err)
-		goto err;
-
-	if (controller_is_spi(host)) 
-	{
-		err = mmcsd_spi_use_crc(host, host->spi_use_crc);
-		if (err)
-			goto err;
-	}
-
-	function_num = (cmd5_resp & 0x70000000) >> 28;
-
-	card = rt_malloc(sizeof(struct rt_mmcsd_card));
-	if (!card) 
-	{
-		rt_kprintf("malloc card failed\n");
-		err = -RT_ENOMEM;
-		goto err;
-	}
-	rt_memset(card, 0, sizeof(struct rt_mmcsd_card));
-
-	card->card_type = CARD_TYPE_SDIO;
-	card->sdio_function_num = function_num;
-	card->host = host;
-	host->card = card;
-
-	card->sdio_function[0] = rt_malloc(sizeof(struct rt_sdio_function));
-	if (!card->sdio_function[0])
-	{
-		rt_kprintf("malloc sdio_func0 failed\n");
-		err = -RT_ENOMEM;
-		goto err1;
-	}
-	rt_memset(card->sdio_function[0], 0, sizeof(struct rt_sdio_function));
-	card->sdio_function[0]->card = card;
-	card->sdio_function[0]->num = 0;
-
-	if (!controller_is_spi(host)) 
-	{
-		err = mmcsd_get_card_addr(host, &card->rca);
-		if (err)
-			goto err2;
-
-		mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL);
-	}
-
-	if (!controller_is_spi(host)) 
-	{
-		err = mmcsd_select_card(card);
-		if (err)
-			goto err2;
-	}
-
-	err = sdio_read_cccr(card);
-	if (err)
-		goto err2;
-
-	err = sdio_read_cis(card->sdio_function[0]);
-	if (err)
-		goto err2;
-
-	err = sdio_set_highspeed(card);
-	if (err)
-		goto err2;
-
-	if (card->flags & CARD_FLAG_HIGHSPEED) 
-	{
-		mmcsd_set_clock(host, 50000000);
-	} 
-	else 
-	{
-		mmcsd_set_clock(host, card->cis.max_tran_speed);
-	}
-
-	err = sdio_set_bus_wide(card);
-	if (err)
-		goto err2;
-
-	for (i = 1; i < function_num + 1; i++) 
-	{
-		err = sdio_initialize_function(card, i);
-		if (err)
-			goto err3;
-	}
-
-
-	/* register sdio card */
-	err = sdio_register_card(card);
-	if (err)
-	{
-		goto err3;
-	}
-
-	return 0;
+    rt_int32_t err = 0;
+    rt_int32_t i, function_num;
+    rt_uint32_t  cmd5_resp;
+    struct rt_mmcsd_card *card;
+
+    err = sdio_io_send_op_cond(host, ocr, &cmd5_resp);
+    if (err)
+        goto err;
+
+    if (controller_is_spi(host)) 
+    {
+        err = mmcsd_spi_use_crc(host, host->spi_use_crc);
+        if (err)
+            goto err;
+    }
+
+    function_num = (cmd5_resp & 0x70000000) >> 28;
+
+    card = rt_malloc(sizeof(struct rt_mmcsd_card));
+    if (!card) 
+    {
+        rt_kprintf("malloc card failed\n");
+        err = -RT_ENOMEM;
+        goto err;
+    }
+    rt_memset(card, 0, sizeof(struct rt_mmcsd_card));
+
+    card->card_type = CARD_TYPE_SDIO;
+    card->sdio_function_num = function_num;
+    card->host = host;
+    host->card = card;
+
+    card->sdio_function[0] = rt_malloc(sizeof(struct rt_sdio_function));
+    if (!card->sdio_function[0])
+    {
+        rt_kprintf("malloc sdio_func0 failed\n");
+        err = -RT_ENOMEM;
+        goto err1;
+    }
+    rt_memset(card->sdio_function[0], 0, sizeof(struct rt_sdio_function));
+    card->sdio_function[0]->card = card;
+    card->sdio_function[0]->num = 0;
+
+    if (!controller_is_spi(host)) 
+    {
+        err = mmcsd_get_card_addr(host, &card->rca);
+        if (err)
+            goto err2;
+
+        mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL);
+    }
+
+    if (!controller_is_spi(host)) 
+    {
+        err = mmcsd_select_card(card);
+        if (err)
+            goto err2;
+    }
+
+    err = sdio_read_cccr(card);
+    if (err)
+        goto err2;
+
+    err = sdio_read_cis(card->sdio_function[0]);
+    if (err)
+        goto err2;
+
+    err = sdio_set_highspeed(card);
+    if (err)
+        goto err2;
+
+    if (card->flags & CARD_FLAG_HIGHSPEED) 
+    {
+        mmcsd_set_clock(host, 50000000);
+    } 
+    else 
+    {
+        mmcsd_set_clock(host, card->cis.max_tran_speed);
+    }
+
+    err = sdio_set_bus_wide(card);
+    if (err)
+        goto err2;
+
+    for (i = 1; i < function_num + 1; i++) 
+    {
+        err = sdio_initialize_function(card, i);
+        if (err)
+            goto err3;
+    }
+
+
+    /* register sdio card */
+    err = sdio_register_card(card);
+    if (err)
+    {
+        goto err3;
+    }
+
+    return 0;
 
 err3:
-	if (host->card)
-	{
-		for (i = 1; i < host->card->sdio_function_num + 1; i++)
-		{
-			if (host->card->sdio_function[i])
-			{
-				sdio_free_cis(host->card->sdio_function[i]);
-				rt_free(host->card->sdio_function[i]);
-				host->card->sdio_function[i] = RT_NULL;
-				rt_free(host->card);
-				host->card = RT_NULL;
-
-			}
-		}
-	}
+    if (host->card)
+    {
+        for (i = 1; i < host->card->sdio_function_num + 1; i++)
+        {
+            if (host->card->sdio_function[i])
+            {
+                sdio_free_cis(host->card->sdio_function[i]);
+                rt_free(host->card->sdio_function[i]);
+                host->card->sdio_function[i] = RT_NULL;
+                rt_free(host->card);
+                host->card = RT_NULL;
+            }
+        }
+    }
 err2:
-	if (host->card && host->card->sdio_function[0])
-	{
-		sdio_free_cis(host->card->sdio_function[0]);
-		rt_free(host->card->sdio_function[0]);
-		host->card->sdio_function[0] = RT_NULL;
-	}
+    if (host->card && host->card->sdio_function[0])
+    {
+        sdio_free_cis(host->card->sdio_function[0]);
+        rt_free(host->card->sdio_function[0]);
+        host->card->sdio_function[0] = RT_NULL;
+    }
 err1:
-	if (host->card)
-	{
-		rt_free(host->card);
-	}
+    if (host->card)
+    {
+        rt_free(host->card);
+    }
 err:
- 	rt_kprintf("error %d while initialising SDIO card\n", err);
-	
-	return err;
+    rt_kprintf("error %d while initialising SDIO card\n", err);
+    
+    return err;
 }
 
-
-
 rt_int32_t init_sdio(struct rt_mmcsd_host *host, rt_uint32_t ocr)
 {
-	rt_int32_t err;
-	rt_uint32_t  current_ocr;
+    rt_int32_t err;
+    rt_uint32_t  current_ocr;
 
-	RT_ASSERT(host != RT_NULL);
+    RT_ASSERT(host != RT_NULL);
 
-	if (ocr & 0x7F) 
-	{
-		rt_kprintf("Card ocr below the defined voltage rang.\n");
-		ocr &= ~0x7F;
-	}
+    if (ocr & 0x7F) 
+    {
+        rt_kprintf("Card ocr below the defined voltage rang.\n");
+        ocr &= ~0x7F;
+    }
 
-	if (ocr & VDD_165_195) 
-	{
-		rt_kprintf("Can't support the low voltage SDIO card.\n");
-		ocr &= ~VDD_165_195;
-	}
+    if (ocr & VDD_165_195) 
+    {
+        rt_kprintf("Can't support the low voltage SDIO card.\n");
+        ocr &= ~VDD_165_195;
+    }
 
-	current_ocr = mmcsd_select_voltage(host, ocr);
+    current_ocr = mmcsd_select_voltage(host, ocr);
 
-	if (!current_ocr) 
-	{
-		err = -RT_ERROR;
-		goto err;
-	}
+    if (!current_ocr) 
+    {
+        err = -RT_ERROR;
+        goto err;
+    }
 
-	err = sdio_init_card(host, current_ocr);
-	if (err)
-		goto remove_card;
+    err = sdio_init_card(host, current_ocr);
+    if (err)
+        goto remove_card;
 
-	return 0;
+    return 0;
 
 remove_card:
-	rt_free(host->card);
-	host->card = RT_NULL;
+    rt_free(host->card);
+    host->card = RT_NULL;
 err:
 
-	rt_kprintf("init SDIO card failed\n");
-
-	return err;
-
-	
+    rt_kprintf("init SDIO card failed\n");
 
+    return err;
 }
 
-
 static void sdio_irq_thread(void *param)
 {
-	rt_int32_t i, ret;
-	rt_uint8_t pending;
-	struct rt_mmcsd_card *card;
-	struct rt_mmcsd_host *host = (struct rt_mmcsd_host *)param;
-	RT_ASSERT(host != RT_NULL);
-	card = host->card;
-	RT_ASSERT(card != RT_NULL);
-
-	while (1) 
-	{
-		if (rt_sem_take(host->sdio_irq_sem, RT_WAITING_FOREVER) == RT_EOK)
-		{
-			mmcsd_host_lock(host);
-			pending = sdio_io_readb(host->card->sdio_function[0], 
-						SDIO_REG_CCCR_INT_PEND, &ret);
-			if (ret) 
-			{
-				mmcsd_dbg("error %d reading SDIO_REG_CCCR_INT_PEND\n", ret);
-				goto out;
-			}
-
-			for (i = 1; i <= 7; i++) 
-			{
-				if (pending & (1 << i)) 
-				{
-					struct rt_sdio_function *func = card->sdio_function[i];
-					if (!func) 
-					{
-						mmcsd_dbg("pending IRQ for "
-							"non-existant function %d\n", func->num);
-						goto out;
-					} 
-					else if (func->irq_handler) 
-					{
-						func->irq_handler(func);
-					} 
-					else 
-					{
-						mmcsd_dbg("pending IRQ with no register handler\n");
-						goto out;
-					}
-				}
-			}
-
-		out:
-			mmcsd_host_unlock(host);
-			if (host->flags & MMCSD_SUP_SDIO_IRQ)
-				host->ops->enable_sdio_irq(host, 1);
-			continue;
-		}
-	}
+    rt_int32_t i, ret;
+    rt_uint8_t pending;
+    struct rt_mmcsd_card *card;
+    struct rt_mmcsd_host *host = (struct rt_mmcsd_host *)param;
+    RT_ASSERT(host != RT_NULL);
+    card = host->card;
+    RT_ASSERT(card != RT_NULL);
+
+    while (1) 
+    {
+        if (rt_sem_take(host->sdio_irq_sem, RT_WAITING_FOREVER) == RT_EOK)
+        {
+            mmcsd_host_lock(host);
+            pending = sdio_io_readb(host->card->sdio_function[0], 
+                        SDIO_REG_CCCR_INT_PEND, &ret);
+            if (ret) 
+            {
+                mmcsd_dbg("error %d reading SDIO_REG_CCCR_INT_PEND\n", ret);
+                goto out;
+            }
+
+            for (i = 1; i <= 7; i++) 
+            {
+                if (pending & (1 << i)) 
+                {
+                    struct rt_sdio_function *func = card->sdio_function[i];
+                    if (!func) 
+                    {
+                        mmcsd_dbg("pending IRQ for "
+                            "non-existant function %d\n", func->num);
+                        goto out;
+                    } 
+                    else if (func->irq_handler) 
+                    {
+                        func->irq_handler(func);
+                    } 
+                    else 
+                    {
+                        mmcsd_dbg("pending IRQ with no register handler\n");
+                        goto out;
+                    }
+                }
+            }
+
+        out:
+            mmcsd_host_unlock(host);
+            if (host->flags & MMCSD_SUP_SDIO_IRQ)
+                host->ops->enable_sdio_irq(host, 1);
+            continue;
+        }
+    }
 }
 
 static rt_int32_t sdio_irq_thread_create(struct rt_mmcsd_card *card)
 {
-	struct rt_mmcsd_host *host = card->host;
-
-	/* init semaphore and create sdio irq processing thread */
-	if (!host->sdio_irq_num)
-	{
-		host->sdio_irq_num++;
-		host->sdio_irq_sem = rt_sem_create("sdio_irq", 0, RT_IPC_FLAG_FIFO);
-		RT_ASSERT(host->sdio_irq_sem != RT_NULL);
-
-		host->sdio_irq_thread = rt_thread_create("sdio_irq", sdio_irq_thread, host, 
-							 RT_SDIO_STACK_SIZE, RT_SDIO_THREAD_PREORITY, 20);
-		if (host->sdio_irq_thread != RT_NULL) 
-		{
-			rt_thread_startup(host->sdio_irq_thread);
-		}
-	}
-
-	return 0;
+    struct rt_mmcsd_host *host = card->host;
+
+    /* init semaphore and create sdio irq processing thread */
+    if (!host->sdio_irq_num)
+    {
+        host->sdio_irq_num++;
+        host->sdio_irq_sem = rt_sem_create("sdio_irq", 0, RT_IPC_FLAG_FIFO);
+        RT_ASSERT(host->sdio_irq_sem != RT_NULL);
+
+        host->sdio_irq_thread = rt_thread_create("sdio_irq", sdio_irq_thread, host, 
+                             RT_SDIO_STACK_SIZE, RT_SDIO_THREAD_PREORITY, 20);
+        if (host->sdio_irq_thread != RT_NULL) 
+        {
+            rt_thread_startup(host->sdio_irq_thread);
+        }
+    }
+
+    return 0;
 }
 
 static rt_int32_t sdio_irq_thread_delete(struct rt_mmcsd_card *card)
 {
-	struct rt_mmcsd_host *host = card->host;
-
-	RT_ASSERT(host->sdio_irq_num > 0);
-
-	host->sdio_irq_num--;
-	if (!host->sdio_irq_num) 
-	{
-		if (host->flags & MMCSD_SUP_SDIO_IRQ)
-				host->ops->enable_sdio_irq(host, 0);
-		rt_sem_delete(host->sdio_irq_sem);
-		host->sdio_irq_sem = RT_NULL;
-		rt_thread_delete(host->sdio_irq_thread);
-		host->sdio_irq_thread = RT_NULL;
-	}
-
-	return 0;
+    struct rt_mmcsd_host *host = card->host;
+
+    RT_ASSERT(host->sdio_irq_num > 0);
+
+    host->sdio_irq_num--;
+    if (!host->sdio_irq_num) 
+    {
+        if (host->flags & MMCSD_SUP_SDIO_IRQ)
+                host->ops->enable_sdio_irq(host, 0);
+        rt_sem_delete(host->sdio_irq_sem);
+        host->sdio_irq_sem = RT_NULL;
+        rt_thread_delete(host->sdio_irq_thread);
+        host->sdio_irq_thread = RT_NULL;
+    }
+
+    return 0;
 }
 
-
-rt_int32_t sdio_attach_irq(struct rt_sdio_function *func, rt_sdio_irq_handler_t *handler)
+rt_int32_t sdio_attach_irq(struct rt_sdio_function *func,
+                           rt_sdio_irq_handler_t   *handler)
 {
-	rt_int32_t ret;
-	rt_uint8_t reg;
-	struct rt_sdio_function *func0;
+    rt_int32_t ret;
+    rt_uint8_t reg;
+    struct rt_sdio_function *func0;
+
+    RT_ASSERT(func != RT_NULL);
+    RT_ASSERT(func->card != RT_NULL);
 
-	RT_ASSERT(func != RT_NULL);
-	RT_ASSERT(func->card != RT_NULL);
+    func0 = func->card->sdio_function[0];
 
-	func0 = func->card->sdio_function[0];
+    mmcsd_dbg("SDIO: enabling IRQ for function %d\n", func->num);
 
-	mmcsd_dbg("SDIO: enabling IRQ for function %d\n", func->num);
+    if (func->irq_handler) 
+    {
+        mmcsd_dbg("SDIO: IRQ for already in use.\n");
 
-	if (func->irq_handler) 
-	{
-		mmcsd_dbg("SDIO: IRQ for already in use.\n");
-		return -RT_EBUSY;
-	}
+        return -RT_EBUSY;
+    }
 
-	reg = sdio_io_readb(func0, SDIO_REG_CCCR_INT_EN, &ret);
-	if (ret)
-		return ret;
+    reg = sdio_io_readb(func0, SDIO_REG_CCCR_INT_EN, &ret);
+    if (ret)
+        return ret;
 
-	reg |= 1 << func->num;
+    reg |= 1 << func->num;
 
-	reg |= 1; /* Master interrupt enable */
+    reg |= 1; /* Master interrupt enable */
 
-	ret = sdio_io_writeb(func0, SDIO_REG_CCCR_INT_EN, reg);
-	if (ret)
-		return ret;
+    ret = sdio_io_writeb(func0, SDIO_REG_CCCR_INT_EN, reg);
+    if (ret)
+        return ret;
 
-	func->irq_handler = handler;
+    func->irq_handler = handler;
 
-	ret = sdio_irq_thread_create(func->card);
-	if (ret)
-		func->irq_handler = RT_NULL;
+    ret = sdio_irq_thread_create(func->card);
+    if (ret)
+        func->irq_handler = RT_NULL;
 
-	return ret;
+    return ret;
 }
 
 rt_int32_t sdio_detach_irq(struct rt_sdio_function *func)
 {
-	rt_int32_t ret;
-	rt_uint8_t reg;
-	struct rt_sdio_function *func0;
+    rt_int32_t ret;
+    rt_uint8_t reg;
+    struct rt_sdio_function *func0;
 
-	RT_ASSERT(func != RT_NULL);
-	RT_ASSERT(func->card != RT_NULL);
+    RT_ASSERT(func != RT_NULL);
+    RT_ASSERT(func->card != RT_NULL);
 
-	func0 = func->card->sdio_function[0];
+    func0 = func->card->sdio_function[0];
 
-	mmcsd_dbg("SDIO: disabling IRQ for function %d\n", func->num);
+    mmcsd_dbg("SDIO: disabling IRQ for function %d\n", func->num);
 
-	if (func->irq_handler) 
-	{
-		func->irq_handler = RT_NULL;
-		sdio_irq_thread_delete(func->card);
-	}
+    if (func->irq_handler) 
+    {
+        func->irq_handler = RT_NULL;
+        sdio_irq_thread_delete(func->card);
+    }
 
-	reg = sdio_io_readb(func0, SDIO_REG_CCCR_INT_EN, &ret);
-	if (ret)
-		return ret;
+    reg = sdio_io_readb(func0, SDIO_REG_CCCR_INT_EN, &ret);
+    if (ret)
+        return ret;
 
-	reg &= ~(1 << func->num);
+    reg &= ~(1 << func->num);
 
-	/* Disable master interrupt with the last function interrupt */
-	if (!(reg & 0xFE))
-		reg = 0;
+    /* Disable master interrupt with the last function interrupt */
+    if (!(reg & 0xFE))
+        reg = 0;
 
-	ret = sdio_io_writeb(func0, SDIO_REG_CCCR_INT_EN, reg);
-	if (ret)
-		return ret;
+    ret = sdio_io_writeb(func0, SDIO_REG_CCCR_INT_EN, reg);
+    if (ret)
+        return ret;
 
-	return 0;
+    return 0;
 }
 
 void sdio_irq_wakeup(struct rt_mmcsd_host *host)
 {
-	host->ops->enable_sdio_irq(host, 0);
-	rt_sem_release(host->sdio_irq_sem);
+    host->ops->enable_sdio_irq(host, 0);
+    rt_sem_release(host->sdio_irq_sem);
 }
 
-
 rt_int32_t sdio_enable_func(struct rt_sdio_function *func)
 {
-	rt_int32_t ret;
-	rt_uint8_t reg;
-	rt_uint32_t timeout;
-	struct rt_sdio_function *func0;
+    rt_int32_t ret;
+    rt_uint8_t reg;
+    rt_uint32_t timeout;
+    struct rt_sdio_function *func0;
 
-	RT_ASSERT(func != RT_NULL);
-	RT_ASSERT(func->card != RT_NULL);
+    RT_ASSERT(func != RT_NULL);
+    RT_ASSERT(func->card != RT_NULL);
 
-	func0 = func->card->sdio_function[0];
+    func0 = func->card->sdio_function[0];
 
-	mmcsd_dbg("SDIO: enabling function %d\n", func->num);
+    mmcsd_dbg("SDIO: enabling function %d\n", func->num);
 
-	reg = sdio_io_readb(func0, SDIO_REG_CCCR_IO_EN, &ret);
-	if (ret)
-		goto err;
+    reg = sdio_io_readb(func0, SDIO_REG_CCCR_IO_EN, &ret);
+    if (ret)
+        goto err;
 
-	reg |= 1 << func->num;
+    reg |= 1 << func->num;
 
-	ret = sdio_io_writeb(func0, SDIO_REG_CCCR_IO_EN, reg);
-	if (ret)
-		goto err;
+    ret = sdio_io_writeb(func0, SDIO_REG_CCCR_IO_EN, reg);
+    if (ret)
+        goto err;
 
-	timeout = rt_tick_get() + func->enable_timeout_val * 1000 / RT_TICK_PER_SECOND;
+    timeout = rt_tick_get() + func->enable_timeout_val * 1000 / RT_TICK_PER_SECOND;
 
-	while (1) 
-	{
-		reg = sdio_io_readb(func0, SDIO_REG_CCCR_IO_RDY, &ret);
-		if (ret)
-			goto err;
-		if (reg & (1 << func->num))
-			break;
-		ret = -RT_ETIMEOUT;
-		if (rt_tick_get() > timeout)
-			goto err;
-	}
+    while (1) 
+    {
+        reg = sdio_io_readb(func0, SDIO_REG_CCCR_IO_RDY, &ret);
+        if (ret)
+            goto err;
+        if (reg & (1 << func->num))
+            break;
+        ret = -RT_ETIMEOUT;
+        if (rt_tick_get() > timeout)
+            goto err;
+    }
 
-	mmcsd_dbg("SDIO: enabled function successfull\n");
+    mmcsd_dbg("SDIO: enabled function successfull\n");
 
-	return 0;
+    return 0;
 
 err:
-	mmcsd_dbg("SDIO: failed to enable function %d\n", func->num);
-	return ret;
+    mmcsd_dbg("SDIO: failed to enable function %d\n", func->num);
+    return ret;
 }
 
-
 rt_int32_t sdio_disable_func(struct rt_sdio_function *func)
 {
-	rt_int32_t ret;
-	rt_uint8_t reg;
-	struct rt_sdio_function *func0;
+    rt_int32_t ret;
+    rt_uint8_t reg;
+    struct rt_sdio_function *func0;
 
-	RT_ASSERT(func != RT_NULL);
-	RT_ASSERT(func->card != RT_NULL);
+    RT_ASSERT(func != RT_NULL);
+    RT_ASSERT(func->card != RT_NULL);
 
-	func0 = func->card->sdio_function[0];
+    func0 = func->card->sdio_function[0];
 
-	mmcsd_dbg("SDIO: disabling function %d\n", func->num);
+    mmcsd_dbg("SDIO: disabling function %d\n", func->num);
 
-	reg =  sdio_io_readb(func0, SDIO_REG_CCCR_IO_EN, &ret);
-	if (ret)
-		goto err;
+    reg =  sdio_io_readb(func0, SDIO_REG_CCCR_IO_EN, &ret);
+    if (ret)
+        goto err;
 
-	reg &= ~(1 << func->num);
+    reg &= ~(1 << func->num);
 
-	ret = sdio_io_writeb(func0, SDIO_REG_CCCR_IO_EN, reg);
-	if (ret)
-		goto err;
+    ret = sdio_io_writeb(func0, SDIO_REG_CCCR_IO_EN, reg);
+    if (ret)
+        goto err;
 
-	mmcsd_dbg("SDIO: disabled function successfull\n");
+    mmcsd_dbg("SDIO: disabled function successfull\n");
 
-	return 0;
+    return 0;
 
 err:
-	mmcsd_dbg("SDIO: failed to disable function %d\n", func->num);
-	return -RT_EIO;
+    mmcsd_dbg("SDIO: failed to disable function %d\n", func->num);
+    return -RT_EIO;
 }
 
-rt_int32_t sdio_set_block_size(struct rt_sdio_function *func, rt_uint32_t blksize)
+rt_int32_t sdio_set_block_size(struct rt_sdio_function *func,
+                               rt_uint32_t              blksize)
 {
-	rt_int32_t ret;
-	struct rt_sdio_function *func0 = func->card->sdio_function[0];
-
-	if (blksize > func->card->host->max_blk_size)
-		return -RT_ERROR;
-
-	if (blksize == 0) 
-	{
-		blksize = MIN(func->max_blk_size, func->card->host->max_blk_size);
-		blksize = MIN(blksize, 512u);
-	}
-
-	ret = sdio_io_writeb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_BLKSIZE, 
-			     blksize & 0xff);
-	if (ret)
-		return ret;
-	ret = sdio_io_writeb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_BLKSIZE + 1, 
-			     (blksize >> 8) & 0xff);
-	if (ret)
-		return ret;
-	func->cur_blk_size = blksize;
-
-	return 0;
+    rt_int32_t ret;
+    struct rt_sdio_function *func0 = func->card->sdio_function[0];
+
+    if (blksize > func->card->host->max_blk_size)
+        return -RT_ERROR;
+
+    if (blksize == 0) 
+    {
+        blksize = MIN(func->max_blk_size, func->card->host->max_blk_size);
+        blksize = MIN(blksize, 512u);
+    }
+
+    ret = sdio_io_writeb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_BLKSIZE, 
+                 blksize & 0xff);
+    if (ret)
+        return ret;
+    ret = sdio_io_writeb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_BLKSIZE + 1, 
+                 (blksize >> 8) & 0xff);
+    if (ret)
+        return ret;
+    func->cur_blk_size = blksize;
+
+    return 0;
 }
 
-
-rt_inline rt_int32_t sdio_match_card(struct rt_mmcsd_card *card,
-	const struct rt_sdio_device_id *id)
+rt_inline rt_int32_t sdio_match_card(struct rt_mmcsd_card           *card,
+                                     const struct rt_sdio_device_id *id)
 {
-	if ((id->manufacturer != SDIO_ANY_MAN_ID) && 
-	    (id->manufacturer != card->cis.manufacturer))
-		return 0;
-	if ((id->product != SDIO_ANY_PROD_ID) && 
-	    (id->product != card->cis.product))
-		return 0;
-
-	return 1;
+    if ((id->manufacturer != SDIO_ANY_MAN_ID) && 
+        (id->manufacturer != card->cis.manufacturer))
+        return 0;
+    if ((id->product != SDIO_ANY_PROD_ID) && 
+        (id->product != card->cis.product))
+        return 0;
+
+    return 1;
 }
 
 static struct rt_mmcsd_card *sdio_match_driver(struct rt_sdio_device_id *id)
 {
-	rt_list_t *l;
-	struct sdio_card *sc;
-	struct rt_mmcsd_card *card;
-
-	for (l = (&sdio_cards)->next; l != &sdio_cards; l = l->next)
-	{
-		sc = (struct sdio_card *)rt_list_entry(l, struct sdio_card, list);
-		card = sc->card;
-
-		if (sdio_match_card(card, id))
-		{
-			return card;
-		}
-	}
-
-	return RT_NULL;
+    rt_list_t *l;
+    struct sdio_card *sc;
+    struct rt_mmcsd_card *card;
+
+    for (l = (&sdio_cards)->next; l != &sdio_cards; l = l->next)
+    {
+        sc = (struct sdio_card *)rt_list_entry(l, struct sdio_card, list);
+        card = sc->card;
+
+        if (sdio_match_card(card, id))
+        {
+            return card;
+        }
+    }
+
+    return RT_NULL;
 }
 
 rt_int32_t sdio_register_driver(struct rt_sdio_driver *driver)
 {
-	struct sdio_driver *sd;
-	struct rt_mmcsd_card *card;
-
-	sd = rt_malloc(sizeof(struct sdio_driver));
-	if (sd == RT_NULL)
-	{
-		rt_kprintf("malloc sdio driver failed\n");
-		return -RT_ENOMEM;
-	}
-
-	rt_list_insert_after(&sdio_drivers, &sd->list);
-
-	if (!rt_list_isempty(&sdio_cards))
-	{
-		card = sdio_match_driver(driver->id);
-		if (card != RT_NULL)
-		{
-			driver->probe(card);
-		}
-	}
-
-	return 0;
+    struct sdio_driver *sd;
+    struct rt_mmcsd_card *card;
+
+    sd = rt_malloc(sizeof(struct sdio_driver));
+    if (sd == RT_NULL)
+    {
+        rt_kprintf("malloc sdio driver failed\n");
+
+        return -RT_ENOMEM;
+    }
+
+    rt_list_insert_after(&sdio_drivers, &sd->list);
+
+    if (!rt_list_isempty(&sdio_cards))
+    {
+        card = sdio_match_driver(driver->id);
+        if (card != RT_NULL)
+        {
+            driver->probe(card);
+        }
+    }
+
+    return 0;
 }
 
 rt_int32_t sdio_unregister_driver(struct rt_sdio_driver *driver)
 {
-	rt_list_t *l;
-	struct sdio_driver *sd = RT_NULL;
-	struct rt_mmcsd_card *card;
-
-
-	rt_list_insert_after(&sdio_drivers, &sd->list);
-
-	for (l = (&sdio_drivers)->next; l != &sdio_drivers; l = l->next)
-	{
-		sd = (struct sdio_driver *)rt_list_entry(l, struct sdio_driver, list);
-		if (sd->drv != driver)
-		{
-			sd = RT_NULL;
-		}
-	}
-
-	if (sd == RT_NULL)
-	{
-		rt_kprintf("SDIO driver %s not register\n", driver->name);
-		return -RT_ERROR;
-	}
-
-	if (!rt_list_isempty(&sdio_cards))
-	{
-		card = sdio_match_driver(driver->id);
-		if (card != RT_NULL)
-		{
-			driver->remove(card);
-			rt_list_remove(&sd->list);
-			rt_free(sd);
-		}
-	}
-
-	return 0;
+    rt_list_t *l;
+    struct sdio_driver *sd = RT_NULL;
+    struct rt_mmcsd_card *card;
+
+
+    rt_list_insert_after(&sdio_drivers, &sd->list);
+
+    for (l = (&sdio_drivers)->next; l != &sdio_drivers; l = l->next)
+    {
+        sd = (struct sdio_driver *)rt_list_entry(l, struct sdio_driver, list);
+        if (sd->drv != driver)
+        {
+            sd = RT_NULL;
+        }
+    }
+
+    if (sd == RT_NULL)
+    {
+        rt_kprintf("SDIO driver %s not register\n", driver->name);
+        return -RT_ERROR;
+    }
+
+    if (!rt_list_isempty(&sdio_cards))
+    {
+        card = sdio_match_driver(driver->id);
+        if (card != RT_NULL)
+        {
+            driver->remove(card);
+            rt_list_remove(&sd->list);
+            rt_free(sd);
+        }
+    }
+
+    return 0;
 }
 
-
 void rt_sdio_init(void)
 {
-	rt_list_init(&sdio_cards);
-	rt_list_init(&sdio_drivers);
+    rt_list_init(&sdio_cards);
+    rt_list_init(&sdio_drivers);
 }
 

+ 13 - 3
components/drivers/serial/serial.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/spi/spi_core.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/spi/spi_dev.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/src/completion.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/src/dataqueue.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/src/pipe.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/src/ringbuffer.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbdevice/class/cdc.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbdevice/class/cdc_vcom.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbdevice/class/mstorage.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbdevice/class/mstorage.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbdevice/core/core.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbdevice/core/usbdevice.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2012, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbhost/class/adk.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2011, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbhost/class/adk.h

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2011, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbhost/core/core.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2011, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbhost/core/driver.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2011, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbhost/core/hub.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2011, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

+ 13 - 3
components/drivers/usb/usbhost/core/usbhost.c

@@ -3,9 +3,19 @@
  * This file is part of RT-Thread RTOS
  * COPYRIGHT (C) 2011, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Change Logs:
  * Date           Author       Notes

部分文件因为文件数量过多而无法显示