diff --git a/components/drivers/i2c/i2c-bit-ops.c b/components/drivers/i2c/i2c-bit-ops.c index e41422a023..0d82d55fd4 100644 --- a/components/drivers/i2c/i2c-bit-ops.c +++ b/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 diff --git a/components/drivers/i2c/i2c_core.c b/components/drivers/i2c/i2c_core.c index 598b63cc93..0449cc723c 100644 --- a/components/drivers/i2c/i2c_core.c +++ b/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 diff --git a/components/drivers/i2c/i2c_dev.c b/components/drivers/i2c/i2c_dev.c index dff21d8e67..cce53d5c92 100644 --- a/components/drivers/i2c/i2c_dev.c +++ b/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 diff --git a/components/drivers/include/drivers/alarm.h b/components/drivers/include/drivers/alarm.h index 546b765a60..010e954810 100644 --- a/components/drivers/include/drivers/alarm.h +++ b/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 diff --git a/components/drivers/include/drivers/i2c-bit-ops.h b/components/drivers/include/drivers/i2c-bit-ops.h index c7cd6c31db..6360b99a92 100644 --- a/components/drivers/include/drivers/i2c-bit-ops.h +++ b/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 diff --git a/components/drivers/include/drivers/i2c.h b/components/drivers/include/drivers/i2c.h index 098d50232a..e2bdcb06bb 100644 --- a/components/drivers/include/drivers/i2c.h +++ b/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 diff --git a/components/drivers/include/drivers/i2c_dev.h b/components/drivers/include/drivers/i2c_dev.h index ea08751db3..81e9896bcf 100644 --- a/components/drivers/include/drivers/i2c_dev.h +++ b/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 diff --git a/components/drivers/include/drivers/mmcsd_card.h b/components/drivers/include/drivers/mmcsd_card.h index 20bb7dca7a..f5c1a4c91f 100644 --- a/components/drivers/include/drivers/mmcsd_card.h +++ b/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 diff --git a/components/drivers/include/drivers/mmcsd_cmd.h b/components/drivers/include/drivers/mmcsd_cmd.h index 1b12f6b448..2700771531 100644 --- a/components/drivers/include/drivers/mmcsd_cmd.h +++ b/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 diff --git a/components/drivers/include/drivers/mmcsd_core.h b/components/drivers/include/drivers/mmcsd_core.h index 5326425bfd..1e5560b893 100644 --- a/components/drivers/include/drivers/mmcsd_core.h +++ b/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 diff --git a/components/drivers/include/drivers/mmcsd_host.h b/components/drivers/include/drivers/mmcsd_host.h index 9cbbb51a76..3b68058ba4 100644 --- a/components/drivers/include/drivers/mmcsd_host.h +++ b/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 diff --git a/components/drivers/include/drivers/mtd_nand.h b/components/drivers/include/drivers/mtd_nand.h index fdcece3a57..020c006eea 100644 --- a/components/drivers/include/drivers/mtd_nand.h +++ b/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 diff --git a/components/drivers/include/drivers/mtd_nor.h b/components/drivers/include/drivers/mtd_nor.h index 9797b167de..c51ce87f41 100644 --- a/components/drivers/include/drivers/mtd_nor.h +++ b/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 diff --git a/components/drivers/include/drivers/rtc.h b/components/drivers/include/drivers/rtc.h index f983a803b0..18108091c8 100644 --- a/components/drivers/include/drivers/rtc.h +++ b/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 diff --git a/components/drivers/include/drivers/sd.h b/components/drivers/include/drivers/sd.h index a2a330d6dd..fb29c8e774 100644 --- a/components/drivers/include/drivers/sd.h +++ b/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 #include diff --git a/components/drivers/include/drivers/sdio.h b/components/drivers/include/drivers/sdio.h index d61bcfa392..6533ec3cbb 100644 --- a/components/drivers/include/drivers/sdio.h +++ b/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 #include #include @@ -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 diff --git a/components/drivers/include/drivers/sdio_func_ids.h b/components/drivers/include/drivers/sdio_func_ids.h index 1885533544..9fee7c238a 100644 --- a/components/drivers/include/drivers/sdio_func_ids.h +++ b/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 */ diff --git a/components/drivers/include/drivers/serial.h b/components/drivers/include/drivers/serial.h index edf05cfa1d..3d118fb45b 100644 --- a/components/drivers/include/drivers/serial.h +++ b/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 diff --git a/components/drivers/include/drivers/spi.h b/components/drivers/include/drivers/spi.h index a9faf933ad..cfa4b73ca3 100644 --- a/components/drivers/include/drivers/spi.h +++ b/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 diff --git a/components/drivers/include/drivers/usb_device.h b/components/drivers/include/drivers/usb_device.h index 2f464def3f..db03ee36ef 100644 --- a/components/drivers/include/drivers/usb_device.h +++ b/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); diff --git a/components/drivers/include/drivers/usb_host.h b/components/drivers/include/drivers/usb_host.h index 8803d5236b..a5a850d4cf 100644 --- a/components/drivers/include/drivers/usb_host.h +++ b/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); } diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h index a50ceb6b34..cf74ce2529 100644 --- a/components/drivers/include/rtdevice.h +++ b/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 diff --git a/components/drivers/mtd/mtd_nand.c b/components/drivers/mtd/mtd_nand.c index 7eb1b3593b..ff2ec8e54c 100644 --- a/components/drivers/mtd/mtd_nand.c +++ b/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 diff --git a/components/drivers/mtd/mtd_nor.c b/components/drivers/mtd/mtd_nor.c index 7930bef5f7..3b4a0adf18 100644 --- a/components/drivers/mtd/mtd_nor.c +++ b/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 diff --git a/components/drivers/rtc/alarm.c b/components/drivers/rtc/alarm.c index 6d8e19f603..0cb0362504 100644 --- a/components/drivers/rtc/alarm.c +++ b/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 diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index af67f40a48..f87df754e7 100644 --- a/components/drivers/rtc/rtc.c +++ b/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 diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c index 3bb2736d05..12986ae1de 100644 --- a/components/drivers/sdio/block_dev.c +++ b/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 @@ -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; + 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; + 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; + 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 (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; - } + 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); + 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; + 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)); - } + 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); + 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); + 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_ERROR; + } - return RT_EOK; + 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; + 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; - } + if (dev == RT_NULL) + { + rt_set_errno(-DFS_STATUS_EINVAL); - 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); + return 0; + } - /* the length of reading must align to SECTOR SIZE */ - if (err) - { - rt_set_errno(-DFS_STATUS_EIO); - return 0; - } - return size; + 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; + 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; - } + if (dev == RT_NULL) + { + rt_set_errno(-DFS_STATUS_EINVAL); - 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); + return 0; + } - /* the length of reading must align to SECTOR SIZE */ - if (err) - { - rt_set_errno(-DFS_STATUS_EIO); - return 0; - } - return size; + 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; + struct rt_mmcsd_cmd cmd; + int err; - /* Block-addressed cards ignore MMC_SET_BLOCKLEN. */ - if (card->flags & CARD_FLAG_SDHC) - return 0; + /* 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); + 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; - } + if (err) + { + rt_kprintf("MMCSD: unable to set block size to %d: %d\n", cmd.arg, err); - return 0; + 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; + 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; - } + 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; - } + /* 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"); - 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; + return -RT_ENOMEM; + } - 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; + 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->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->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; + 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); } diff --git a/components/drivers/sdio/mmcsd_core.c b/components/drivers/sdio/mmcsd_core.c index db93cdb10c..816782f68c 100644 --- a/components/drivers/sdio/mmcsd_core.c +++ b/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 @@ -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; + 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); - } + if (!controller_is_spi(host)) + { + mmcsd_set_chip_select(host, MMCSD_CS_HIGH); + mmcsd_delay_ms(1); + } - rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); - cmd.cmd_code = GO_IDLE_STATE; - cmd.arg = 0; - cmd.flags = RESP_SPI_R1 | RESP_NONE | CMD_BC; + cmd.cmd_code = GO_IDLE_STATE; + cmd.arg = 0; + cmd.flags = RESP_SPI_R1 | RESP_NONE | CMD_BC; - err = mmcsd_send_cmd(host, &cmd, 0); + err = mmcsd_send_cmd(host, &cmd, 0); - 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); - } + 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; + 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)); + 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; + 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; - } + rt_memcpy(cid, cmd.resp, sizeof(rt_uint32_t) * 4); - buf = (rt_uint32_t *)rt_malloc(16); - if (!buf) - { - rt_kprintf("allocate memory failed\n"); - return -RT_ENOMEM; - } + return 0; + } - 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)); + buf = (rt_uint32_t *)rt_malloc(16); + if (!buf) + { + rt_kprintf("allocate memory failed\n"); - req.cmd = &cmd; - req.data = &data; + return -RT_ENOMEM; + } - cmd.cmd_code = SEND_CID; - cmd.arg = 0; + 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)); - /* 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; + req.cmd = &cmd; + req.data = &data; - 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; + cmd.cmd_code = SEND_CID; + cmd.arg = 0; - mmcsd_send_request(host, &req); + /* 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; - if (cmd.err || data.err) - { - rt_free(buf); - return -RT_ERROR; - } + 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; - for (i = 0;i < 4;i++) - cid[i] = buf[i]; - rt_free(buf); + mmcsd_send_request(host, &req); - return 0; + 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; + 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)); + 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; + 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; - } + rt_memcpy(csd, cmd.resp, sizeof(rt_uint32_t) * 4); - buf = (rt_uint32_t*)rt_malloc(16); - if (!buf) - { - rt_kprintf("allocate memory failed\n"); - return -RT_ENOMEM; - } + return 0; + } - 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)); + buf = (rt_uint32_t*)rt_malloc(16); + if (!buf) + { + rt_kprintf("allocate memory failed\n"); - req.cmd = &cmd; - req.data = &data; + return -RT_ENOMEM; + } - cmd.cmd_code = SEND_CSD; - cmd.arg = 0; + 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)); - /* 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; + req.cmd = &cmd; + req.data = &data; - data.blksize = 16; - data.blks = 1; - data.flags = DATA_DIR_READ; - data.buf = buf; + cmd.cmd_code = SEND_CSD; + cmd.arg = 0; - /* - * The spec states that CSR and CID accesses have a timeout - * of 64 clock cycles. - */ - data.timeout_ns = 0; - data.timeout_clks = 64; + /* 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; - mmcsd_send_request(card->host, &req); + data.blksize = 16; + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = buf; - if (cmd.err || data.err) - { - rt_free(buf); - return -RT_ERROR; - } + /* + * The spec states that CSR and CID accesses have a timeout + * of 64 clock cycles. + */ + data.timeout_ns = 0; + data.timeout_clks = 64; - for (i = 0;i < 4;i++) - csd[i] = buf[i]; - rt_free(buf); + mmcsd_send_request(card->host, &req); - return 0; + 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; + rt_uint32_t mult; - if (card->card_type == CARD_TYPE_SDIO) - { - data->timeout_ns = 1000000000; /* SDIO card 1s */ - data->timeout_clks = 0; - return; - } + if (card->card_type == CARD_TYPE_SDIO) + { + data->timeout_ns = 1000000000; /* SDIO card 1s */ + data->timeout_clks = 0; - /* - * SD cards use a 100 multiplier rather than 10 - */ - mult = (card->card_type == CARD_TYPE_SD) ? 100 : 10; + return; + } - /* - * 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; + /* + * SD cards use a 100 multiplier rather than 10 + */ + mult = (card->card_type == CARD_TYPE_SD) ? 100 : 10; - data->timeout_ns = card->tacc_ns * mult; - data->timeout_clks = card->tacc_clks * mult; + /* + * 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; - /* - * SD cards also have an upper limit on the timeout. - */ - if (card->card_type == CARD_TYPE_SD) - { - rt_uint32_t timeout_us, limit_us; + data->timeout_ns = card->tacc_ns * mult; + data->timeout_clks = card->tacc_clks * mult; - timeout_us = data->timeout_ns / 1000; - timeout_us += data->timeout_clks * 1000 / - (card->host->io_cfg.clock / 1000); + /* + * SD cards also have an upper limit on the timeout. + */ + if (card->card_type == CARD_TYPE_SD) + { + rt_uint32_t timeout_us, limit_us; - 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; + timeout_us = data->timeout_ns / 1000; + timeout_us += data->timeout_clks * 1000 / + (card->host->io_cfg.clock / 1000); - /* - * 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 (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; - 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 */ - } - } + /* + * 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; + 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); + 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); + /* + * 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); + 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); + /* + * 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; + 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); + 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); + 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; - } + 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); - } - } - } + /* + * 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"); - return RT_NULL; - } + host = rt_malloc(sizeof(struct rt_mmcsd_host)); + if (!host) + { + rt_kprintf("alloc host failed\n"); - rt_memset(host, 0, sizeof(struct rt_mmcsd_host)); + return RT_NULL; + } - host->max_seg_size = 65535; - host->max_dma_segs = 1; - host->max_blk_size = 512; - host->max_blk_count = 4096; + rt_memset(host, 0, sizeof(struct rt_mmcsd_host)); - 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); + host->max_seg_size = 65535; + host->max_dma_segs = 1; + host->max_blk_size = 512; + host->max_blk_count = 4096; - return host; + 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; } 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; + 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); + /* 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); - } + 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_sdio_init(); } diff --git a/components/drivers/sdio/sd.c b/components/drivers/sdio/sd.c index da71d40310..a42aa17531 100644 --- a/components/drivers/sdio/sd.c +++ b/components/drivers/sdio/sd.c @@ -3,430 +3,456 @@ * 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 #include -static const rt_uint32_t tran_unit[] = { - 10000, 100000, 1000000, 10000000, - 0, 0, 0, 0 +static const rt_uint32_t tran_unit[] = +{ + 10000, 100000, 1000000, 10000000, + 0, 0, 0, 0 }; -static const rt_uint8_t tran_value[] = { - 0, 10, 12, 13, 15, 20, 25, 30, - 35, 40, 45, 50, 55, 60, 70, 80, +static const rt_uint8_t tran_value[] = +{ + 0, 10, 12, 13, 15, 20, 25, 30, + 35, 40, 45, 50, 55, 60, 70, 80, }; -static const rt_uint32_t tacc_uint[] = { - 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, +static const rt_uint32_t tacc_uint[] = +{ + 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, }; -static const rt_uint8_t tacc_value[] = { - 0, 10, 12, 13, 15, 20, 25, 30, - 35, 40, 45, 50, 55, 60, 70, 80, +static const rt_uint8_t tacc_value[] = +{ + 0, 10, 12, 13, 15, 20, 25, 30, + 35, 40, 45, 50, 55, 60, 70, 80, }; -rt_inline rt_uint32_t GET_BITS(rt_uint32_t *resp, rt_uint32_t start, rt_uint32_t size) -{ - const rt_int32_t __size = size; - const rt_uint32_t __mask = (__size < 32 ? 1 << __size : 0) - 1; - const rt_int32_t __off = 3 - ((start) / 32); - const rt_int32_t __shft = (start) & 31; - rt_uint32_t __res; - - __res = resp[__off] >> __shft; - if (__size + __shft > 32) - __res |= resp[__off-1] << ((32 - __shft) % 32); - return __res & __mask; +rt_inline rt_uint32_t GET_BITS(rt_uint32_t *resp, + rt_uint32_t start, + rt_uint32_t size) +{ + const rt_int32_t __size = size; + const rt_uint32_t __mask = (__size < 32 ? 1 << __size : 0) - 1; + const rt_int32_t __off = 3 - ((start) / 32); + const rt_int32_t __shft = (start) & 31; + rt_uint32_t __res; + + __res = resp[__off] >> __shft; + if (__size + __shft > 32) + __res |= resp[__off-1] << ((32 - __shft) % 32); + + return __res & __mask; } static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card) { - struct rt_mmcsd_csd *csd = &card->csd; - rt_uint32_t *resp = card->resp_csd; + struct rt_mmcsd_csd *csd = &card->csd; + rt_uint32_t *resp = card->resp_csd; - csd->csd_structure = GET_BITS(resp, 126, 2); + csd->csd_structure = GET_BITS(resp, 126, 2); - switch (csd->csd_structure) { - case 0: - csd->taac = GET_BITS(resp, 112, 8); - csd->nsac = GET_BITS(resp, 104, 8); - csd->tran_speed = GET_BITS(resp, 96, 8); - csd->card_cmd_class = GET_BITS(resp, 84, 12); - csd->rd_blk_len = GET_BITS(resp, 80, 4); - csd->rd_blk_part = GET_BITS(resp, 79, 1); - csd->wr_blk_misalign = GET_BITS(resp, 78, 1); - csd->rd_blk_misalign = GET_BITS(resp, 77, 1); - csd->dsr_imp = GET_BITS(resp, 76, 1); - csd->c_size = GET_BITS(resp, 62, 12); - csd->c_size_mult = GET_BITS(resp, 47, 3); - csd->r2w_factor = GET_BITS(resp, 26, 3); - csd->wr_blk_len = GET_BITS(resp, 22, 4); - csd->wr_blk_partial = GET_BITS(resp, 21, 1); - csd->csd_crc = GET_BITS(resp, 1, 7); + switch (csd->csd_structure) + { + case 0: + csd->taac = GET_BITS(resp, 112, 8); + csd->nsac = GET_BITS(resp, 104, 8); + csd->tran_speed = GET_BITS(resp, 96, 8); + csd->card_cmd_class = GET_BITS(resp, 84, 12); + csd->rd_blk_len = GET_BITS(resp, 80, 4); + csd->rd_blk_part = GET_BITS(resp, 79, 1); + csd->wr_blk_misalign = GET_BITS(resp, 78, 1); + csd->rd_blk_misalign = GET_BITS(resp, 77, 1); + csd->dsr_imp = GET_BITS(resp, 76, 1); + csd->c_size = GET_BITS(resp, 62, 12); + csd->c_size_mult = GET_BITS(resp, 47, 3); + csd->r2w_factor = GET_BITS(resp, 26, 3); + csd->wr_blk_len = GET_BITS(resp, 22, 4); + csd->wr_blk_partial = GET_BITS(resp, 21, 1); + csd->csd_crc = GET_BITS(resp, 1, 7); - card->card_blksize = 1 << csd->rd_blk_len; - card->card_capacity = (csd->c_size + 1) << (csd->c_size_mult + 2); - card->card_capacity *= card->card_blksize; - card->card_capacity >>= 10; /* unit:KB */ - card->tacc_clks = csd->nsac * 100; - card->tacc_ns = (tacc_uint[csd->taac&0x07] * tacc_value[(csd->taac&0x78)>>3] + 9) / 10; - card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; + card->card_blksize = 1 << csd->rd_blk_len; + card->card_capacity = (csd->c_size + 1) << (csd->c_size_mult + 2); + card->card_capacity *= card->card_blksize; + card->card_capacity >>= 10; /* unit:KB */ + card->tacc_clks = csd->nsac * 100; + card->tacc_ns = (tacc_uint[csd->taac&0x07] * tacc_value[(csd->taac&0x78)>>3] + 9) / 10; + card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; - #if 0 - val = GET_BITS(resp, 115, 4); - unit = GET_BITS(resp, 112, 3); - csd->tacc_ns = (tacc_uint[unit] * tacc_value[val] + 9) / 10; - csd->tacc_clks = GET_BITS(resp, 104, 8) * 100; + #if 0 + val = GET_BITS(resp, 115, 4); + unit = GET_BITS(resp, 112, 3); + csd->tacc_ns = (tacc_uint[unit] * tacc_value[val] + 9) / 10; + csd->tacc_clks = GET_BITS(resp, 104, 8) * 100; - val = GET_BITS(resp, 99, 4); - unit = GET_BITS(resp, 96, 3); - csd->max_data_rate = tran_unit[unit] * tran_value[val]; - csd->ccc = GET_BITS(resp, 84, 12); + val = GET_BITS(resp, 99, 4); + unit = GET_BITS(resp, 96, 3); + csd->max_data_rate = tran_unit[unit] * tran_value[val]; + csd->ccc = GET_BITS(resp, 84, 12); - unit = GET_BITS(resp, 47, 3); - val = GET_BITS(resp, 62, 12); - csd->device_size = (1 + val) << (unit + 2); + unit = GET_BITS(resp, 47, 3); + val = GET_BITS(resp, 62, 12); + csd->device_size = (1 + val) << (unit + 2); - csd->read_bl_len = GET_BITS(resp, 80, 4); - csd->write_bl_len = GET_BITS(resp, 22, 4); - csd->r2w_factor = GET_BITS(resp, 26, 3); - #endif - break; - case 1: - card->flags |= CARD_FLAG_SDHC; + csd->read_bl_len = GET_BITS(resp, 80, 4); + csd->write_bl_len = GET_BITS(resp, 22, 4); + csd->r2w_factor = GET_BITS(resp, 26, 3); + #endif + break; + case 1: + card->flags |= CARD_FLAG_SDHC; - /*This field is fixed to 0Eh, which indicates 1 ms. - The host should not use TAAC, NSAC, and R2W_FACTOR - to calculate timeout and should uses fixed timeout - values for read and write operations*/ - csd->taac = GET_BITS(resp, 112, 8); - csd->nsac = GET_BITS(resp, 104, 8); - csd->tran_speed = GET_BITS(resp, 96, 8); - csd->card_cmd_class = GET_BITS(resp, 84, 12); - csd->rd_blk_len = GET_BITS(resp, 80, 4); - csd->rd_blk_part = GET_BITS(resp, 79, 1); - csd->wr_blk_misalign = GET_BITS(resp, 78, 1); - csd->rd_blk_misalign = GET_BITS(resp, 77, 1); - csd->dsr_imp = GET_BITS(resp, 76, 1); - csd->c_size = GET_BITS(resp, 48, 22); + /*This field is fixed to 0Eh, which indicates 1 ms. + The host should not use TAAC, NSAC, and R2W_FACTOR + to calculate timeout and should uses fixed timeout + values for read and write operations*/ + csd->taac = GET_BITS(resp, 112, 8); + csd->nsac = GET_BITS(resp, 104, 8); + csd->tran_speed = GET_BITS(resp, 96, 8); + csd->card_cmd_class = GET_BITS(resp, 84, 12); + csd->rd_blk_len = GET_BITS(resp, 80, 4); + csd->rd_blk_part = GET_BITS(resp, 79, 1); + csd->wr_blk_misalign = GET_BITS(resp, 78, 1); + csd->rd_blk_misalign = GET_BITS(resp, 77, 1); + csd->dsr_imp = GET_BITS(resp, 76, 1); + csd->c_size = GET_BITS(resp, 48, 22); - csd->r2w_factor = GET_BITS(resp, 26, 3); - csd->wr_blk_len = GET_BITS(resp, 22, 4); - csd->wr_blk_partial = GET_BITS(resp, 21, 1); - csd->csd_crc = GET_BITS(resp, 1, 7); + csd->r2w_factor = GET_BITS(resp, 26, 3); + csd->wr_blk_len = GET_BITS(resp, 22, 4); + csd->wr_blk_partial = GET_BITS(resp, 21, 1); + csd->csd_crc = GET_BITS(resp, 1, 7); - card->card_blksize = 512; - card->card_capacity = (csd->c_size + 1) * 512; /* unit:KB */ - card->tacc_clks = 0; - card->tacc_ns = 0; - card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; + card->card_blksize = 512; + card->card_capacity = (csd->c_size + 1) * 512; /* unit:KB */ + card->tacc_clks = 0; + card->tacc_ns = 0; + card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; - #if 0 - csd->tacc_ns = 0; - csd->tacc_clks = 0; + #if 0 + csd->tacc_ns = 0; + csd->tacc_clks = 0; - val = GET_BITS(resp, 99, 4); - unit = GET_BITS(resp, 96, 3); - csd->max_data_rate = tran_unit[unit] * tran_value[val]; - csd->ccc = GET_BITS(resp, 84, 12); + val = GET_BITS(resp, 99, 4); + unit = GET_BITS(resp, 96, 3); + csd->max_data_rate = tran_unit[unit] * tran_value[val]; + csd->ccc = GET_BITS(resp, 84, 12); - val = GET_BITS(resp, 48, 22); - csd->device_size = (1 + val) << 10; + val = GET_BITS(resp, 48, 22); + csd->device_size = (1 + val) << 10; - csd->read_bl_len = 9; - csd->write_bl_len = 9; - /* host should not use this factor and should use 250ms for write timeout */ - csd->r2w_factor = 2; - #endif - break; - default: - rt_kprintf("unrecognised CSD structure version %d\n", csd->csd_structure); - return -RT_ERROR; - } - rt_kprintf("SD card capacity %d KB\n", card->card_capacity); + csd->read_bl_len = 9; + csd->write_bl_len = 9; + /* host should not use this factor and should use 250ms for write timeout */ + csd->r2w_factor = 2; + #endif + break; + default: + rt_kprintf("unrecognised CSD structure version %d\n", csd->csd_structure); - return 0; + return -RT_ERROR; + } + rt_kprintf("SD card capacity %d KB\n", card->card_capacity); + + return 0; } static rt_int32_t mmcsd_parse_scr(struct rt_mmcsd_card *card) { - struct rt_sd_scr *scr = &card->scr; - rt_uint32_t resp[4]; + struct rt_sd_scr *scr = &card->scr; + rt_uint32_t resp[4]; - resp[3] = card->resp_scr[1]; - resp[2] = card->resp_scr[0]; - scr->sd_version = GET_BITS(resp, 56, 4); - scr->sd_bus_widths = GET_BITS(resp, 48, 4); + resp[3] = card->resp_scr[1]; + resp[2] = card->resp_scr[0]; + scr->sd_version = GET_BITS(resp, 56, 4); + scr->sd_bus_widths = GET_BITS(resp, 48, 4); - return 0; + return 0; } static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card) { - rt_int32_t err; - struct rt_mmcsd_host *host = card->host; - struct rt_mmcsd_req req; - struct rt_mmcsd_cmd cmd; - struct rt_mmcsd_data data; - rt_uint8_t *buf; + rt_int32_t err; + struct rt_mmcsd_host *host = card->host; + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + rt_uint8_t *buf; - buf = (rt_uint8_t*)rt_malloc(64); - if (!buf) - { - rt_kprintf("alloc memory failed\n"); - return -RT_ENOMEM; - } - - if (card->card_type != CARD_TYPE_SD) - goto err; - if (card->scr.sd_version < SCR_SPEC_VER_1) - goto err; + buf = (rt_uint8_t*)rt_malloc(64); + if (!buf) + { + rt_kprintf("alloc memory failed\n"); - rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + return -RT_ENOMEM; + } + + if (card->card_type != CARD_TYPE_SD) + goto err; + if (card->scr.sd_version < SCR_SPEC_VER_1) + goto err; - cmd.cmd_code = SD_SWITCH; - cmd.arg = 0x00FFFFF1; - cmd.flags = RESP_R1 | CMD_ADTC; + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); - rt_memset(&data, 0, sizeof(struct rt_mmcsd_data)); + cmd.cmd_code = SD_SWITCH; + cmd.arg = 0x00FFFFF1; + cmd.flags = RESP_R1 | CMD_ADTC; - mmcsd_set_data_timeout(&data, card); + rt_memset(&data, 0, sizeof(struct rt_mmcsd_data)); - data.blksize = 64; - data.blks = 1; - data.flags = DATA_DIR_READ; - data.buf = (rt_uint32_t *)buf; + mmcsd_set_data_timeout(&data, card); - rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + data.blksize = 64; + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = (rt_uint32_t *)buf; - req.cmd = &cmd; - req.data = &data; + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); - mmcsd_send_request(host, &req); + req.cmd = &cmd; + req.data = &data; - if (cmd.err || data.err) - { - goto err1; - } + mmcsd_send_request(host, &req); - if (buf[13] & 0x02) - card->hs_max_data_rate = 50000000; + if (cmd.err || data.err) + { + goto err1; + } - rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + if (buf[13] & 0x02) + card->hs_max_data_rate = 50000000; - cmd.cmd_code = SD_SWITCH; - cmd.arg = 0x80FFFFF1; - cmd.flags = RESP_R1 | CMD_ADTC; + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); - rt_memset(&data, 0, sizeof(struct rt_mmcsd_data)); + cmd.cmd_code = SD_SWITCH; + cmd.arg = 0x80FFFFF1; + cmd.flags = RESP_R1 | CMD_ADTC; - mmcsd_set_data_timeout(&data, card); + rt_memset(&data, 0, sizeof(struct rt_mmcsd_data)); - data.blksize = 64; - data.blks = 1; - data.flags = DATA_DIR_READ; - data.buf = (rt_uint32_t *)buf; + mmcsd_set_data_timeout(&data, card); - rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + data.blksize = 64; + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = (rt_uint32_t *)buf; - req.cmd = &cmd; - req.data = &data; + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); - mmcsd_send_request(host, &req); + req.cmd = &cmd; + req.data = &data; - if (cmd.err || data.err) - { - goto err1; - } + mmcsd_send_request(host, &req); - if ((buf[16] & 0xF) != 1) - { - rt_kprintf("switching card to high speed failed\n"); - goto err; - } + if (cmd.err || data.err) + { + goto err1; + } - card->flags |= CARD_FLAG_HIGHSPEED; + if ((buf[16] & 0xF) != 1) + { + rt_kprintf("switching card to high speed failed\n"); + goto err; + } + + card->flags |= CARD_FLAG_HIGHSPEED; err: - rt_free(buf); - return 0; + rt_free(buf); + return 0; err1: - if (cmd.err) err = cmd.err; - if (data.err) err = data.err; + if (cmd.err) + err = cmd.err; + if (data.err) + err = data.err; - return err; + return err; } -static rt_err_t mmcsd_app_cmd(struct rt_mmcsd_host *host, struct rt_mmcsd_card *card) +static rt_err_t mmcsd_app_cmd(struct rt_mmcsd_host *host, + struct rt_mmcsd_card *card) { - rt_err_t err; - struct rt_mmcsd_cmd cmd = {0}; + rt_err_t err; + struct rt_mmcsd_cmd cmd = {0}; - cmd.cmd_code = APP_CMD; + cmd.cmd_code = APP_CMD; - if (card) - { - cmd.arg = card->rca << 16; - cmd.flags = RESP_R1 | CMD_AC; - } - else - { - cmd.arg = 0; - cmd.flags = RESP_R1 | CMD_BCR; - } + if (card) + { + cmd.arg = card->rca << 16; + cmd.flags = RESP_R1 | CMD_AC; + } + else + { + cmd.arg = 0; + cmd.flags = RESP_R1 | CMD_BCR; + } - err = mmcsd_send_cmd(host, &cmd, 0); - if (err) - return err; + err = mmcsd_send_cmd(host, &cmd, 0); + if (err) + return err; - /* Check that card supported application commands */ - if (!controller_is_spi(host) && !(cmd.resp[0] & R1_APP_CMD)) - return -RT_ERROR; + /* Check that card supported application commands */ + if (!controller_is_spi(host) && !(cmd.resp[0] & R1_APP_CMD)) + return -RT_ERROR; - return RT_EOK; + return RT_EOK; } -rt_err_t mmcsd_send_app_cmd(struct rt_mmcsd_host *host, struct rt_mmcsd_card *card, - struct rt_mmcsd_cmd *cmd, int retry) +rt_err_t mmcsd_send_app_cmd(struct rt_mmcsd_host *host, + struct rt_mmcsd_card *card, + struct rt_mmcsd_cmd *cmd, + int retry) { - struct rt_mmcsd_req req; + struct rt_mmcsd_req req; - rt_uint32_t i; - rt_err_t err; + rt_uint32_t i; + rt_err_t err; - err = -RT_ERROR; + err = -RT_ERROR; - /* - * We have to resend MMC_APP_CMD for each attempt so - * we cannot use the retries field in mmc_command. - */ - for (i = 0;i <= retry;i++) - { - rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + /* + * We have to resend MMC_APP_CMD for each attempt so + * we cannot use the retries field in mmc_command. + */ + for (i = 0;i <= retry;i++) + { + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); - err = mmcsd_app_cmd(host, card); - if (err) - { - /* no point in retrying; no APP commands allowed */ - if (controller_is_spi(host)) - { - if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND) - break; - } - continue; - } + err = mmcsd_app_cmd(host, card); + if (err) + { + /* no point in retrying; no APP commands allowed */ + if (controller_is_spi(host)) + { + if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND) + break; + } + continue; + } - rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); - rt_memset(cmd->resp, 0, sizeof(cmd->resp)); + rt_memset(cmd->resp, 0, sizeof(cmd->resp)); - req.cmd = cmd; - //cmd->data = NULL; + req.cmd = cmd; + //cmd->data = NULL; - mmcsd_send_request(host, &req); + mmcsd_send_request(host, &req); - err = cmd->err; - if (!cmd->err) - break; + err = cmd->err; + if (!cmd->err) + break; - /* no point in retrying illegal APP commands */ - if (controller_is_spi(host)) - { - if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND) - break; - } - } + /* no point in retrying illegal APP commands */ + if (controller_is_spi(host)) + { + if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND) + break; + } + } - return err; + return err; } - rt_err_t mmcsd_app_set_bus_width(struct rt_mmcsd_card *card, rt_int32_t width) { - rt_err_t err; - struct rt_mmcsd_cmd cmd; + rt_err_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 = SD_APP_SET_BUS_WIDTH; - cmd.flags = RESP_R1 | CMD_AC; + cmd.cmd_code = SD_APP_SET_BUS_WIDTH; + cmd.flags = RESP_R1 | CMD_AC; - switch (width) - { - case MMCSD_BUS_WIDTH_1: - cmd.arg = MMCSD_BUS_WIDTH_1; - break; - case MMCSD_BUS_WIDTH_4: - cmd.arg = MMCSD_BUS_WIDTH_4; - break; - default: - return -RT_ERROR; - } + switch (width) + { + case MMCSD_BUS_WIDTH_1: + cmd.arg = MMCSD_BUS_WIDTH_1; + break; + case MMCSD_BUS_WIDTH_4: + cmd.arg = MMCSD_BUS_WIDTH_4; + break; + default: + return -RT_ERROR; + } - err = mmcsd_send_app_cmd(card->host, card, &cmd, 3); - if (err) - return err; + err = mmcsd_send_app_cmd(card->host, card, &cmd, 3); + if (err) + return err; - return RT_EOK; + return RT_EOK; } -rt_err_t mmcsd_send_app_op_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr, rt_uint32_t *rocr) +rt_err_t mmcsd_send_app_op_cond(struct rt_mmcsd_host *host, + rt_uint32_t ocr, + rt_uint32_t *rocr) { - struct rt_mmcsd_cmd cmd; - rt_uint32_t i; - rt_err_t err = RT_EOK; + struct rt_mmcsd_cmd cmd; + rt_uint32_t i; + rt_err_t err = RT_EOK; - rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); - cmd.cmd_code = SD_APP_OP_COND; - if (controller_is_spi(host)) - cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */ - else - cmd.arg = ocr; - cmd.flags = RESP_SPI_R1 | RESP_R3 | CMD_BCR; + cmd.cmd_code = SD_APP_OP_COND; + if (controller_is_spi(host)) + cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */ + else + cmd.arg = ocr; + cmd.flags = RESP_SPI_R1 | RESP_R3 | CMD_BCR; - for (i = 100; i; i--) - { - err = mmcsd_send_app_cmd(host, RT_NULL, &cmd, 3); - if (err) - break; + for (i = 100; i; i--) + { + err = mmcsd_send_app_cmd(host, RT_NULL, &cmd, 3); + if (err) + break; - /* if we're just probing, do a single pass */ - if (ocr == 0) - break; + /* if we're just probing, do a single pass */ + if (ocr == 0) + break; - /* otherwise wait until reset completes */ - if (controller_is_spi(host)) - { - if (!(cmd.resp[0] & R1_SPI_IDLE)) - break; - } - else - { - if (cmd.resp[0] & CARD_BUSY) - break; - } + /* otherwise wait until reset completes */ + if (controller_is_spi(host)) + { + if (!(cmd.resp[0] & R1_SPI_IDLE)) + break; + } + else + { + if (cmd.resp[0] & CARD_BUSY) + break; + } - err = -RT_ETIMEOUT; + err = -RT_ETIMEOUT; - mmcsd_delay_ms(10); //delay 10ms - } + mmcsd_delay_ms(10); //delay 10ms + } - if (rocr && !controller_is_spi(host)) - *rocr = cmd.resp[0]; + if (rocr && !controller_is_spi(host)) + *rocr = cmd.resp[0]; - return err; + return err; } /* @@ -436,223 +462,224 @@ rt_err_t mmcsd_send_app_op_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr, rt_ */ rt_err_t mmcsd_send_if_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr) { - struct rt_mmcsd_cmd cmd; - rt_err_t err; - rt_uint8_t pattern; + struct rt_mmcsd_cmd cmd; + rt_err_t err; + rt_uint8_t pattern; - cmd.cmd_code = SD_SEND_IF_COND; - cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | 0xAA; - cmd.flags = RESP_SPI_R7 | RESP_R7 | CMD_BCR; + cmd.cmd_code = SD_SEND_IF_COND; + cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | 0xAA; + cmd.flags = RESP_SPI_R7 | RESP_R7 | CMD_BCR; - err = mmcsd_send_cmd(host, &cmd, 0); - if (err) - return err; + err = mmcsd_send_cmd(host, &cmd, 0); + if (err) + return err; - if (controller_is_spi(host)) - pattern = cmd.resp[1] & 0xFF; - else - pattern = cmd.resp[0] & 0xFF; + if (controller_is_spi(host)) + pattern = cmd.resp[1] & 0xFF; + else + pattern = cmd.resp[0] & 0xFF; - if (pattern != 0xAA) - return -RT_ERROR; + if (pattern != 0xAA) + return -RT_ERROR; - return RT_EOK; + return RT_EOK; } rt_err_t mmcsd_get_card_addr(struct rt_mmcsd_host *host, rt_uint32_t *rca) { - rt_err_t err; - struct rt_mmcsd_cmd cmd; + rt_err_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 = SD_SEND_RELATIVE_ADDR; - cmd.arg = 0; - cmd.flags = RESP_R6 | CMD_BCR; + cmd.cmd_code = SD_SEND_RELATIVE_ADDR; + cmd.arg = 0; + cmd.flags = RESP_R6 | CMD_BCR; - err = mmcsd_send_cmd(host, &cmd, 3); - if (err) - return err; + err = mmcsd_send_cmd(host, &cmd, 3); + if (err) + return err; - *rca = cmd.resp[0] >> 16; + *rca = cmd.resp[0] >> 16; - return RT_EOK; + return RT_EOK; } -#define be32_to_cpu(x) ((rt_uint32_t)( \ - (((rt_uint32_t)(x) & (rt_uint32_t)0x000000ffUL) << 24) | \ - (((rt_uint32_t)(x) & (rt_uint32_t)0x0000ff00UL) << 8) | \ - (((rt_uint32_t)(x) & (rt_uint32_t)0x00ff0000UL) >> 8) | \ - (((rt_uint32_t)(x) & (rt_uint32_t)0xff000000UL) >> 24))) +#define be32_to_cpu(x) ((rt_uint32_t)( \ + (((rt_uint32_t)(x) & (rt_uint32_t)0x000000ffUL) << 24) | \ + (((rt_uint32_t)(x) & (rt_uint32_t)0x0000ff00UL) << 8) | \ + (((rt_uint32_t)(x) & (rt_uint32_t)0x00ff0000UL) >> 8) | \ + (((rt_uint32_t)(x) & (rt_uint32_t)0xff000000UL) >> 24))) rt_int32_t mmcsd_get_scr(struct rt_mmcsd_card *card, rt_uint32_t *scr) { - rt_int32_t err; - struct rt_mmcsd_req req; - struct rt_mmcsd_cmd cmd; - struct rt_mmcsd_data data; + rt_int32_t err; + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; - err = mmcsd_app_cmd(card->host, card); - if (err) - return err; + err = mmcsd_app_cmd(card->host, card); + if (err) + return err; - 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)); + 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; + req.cmd = &cmd; + req.data = &data; - cmd.cmd_code = SD_APP_SEND_SCR; - cmd.arg = 0; - cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC; + cmd.cmd_code = SD_APP_SEND_SCR; + cmd.arg = 0; + cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC; - data.blksize = 8; - data.blks = 1; - data.flags = DATA_DIR_READ; - data.buf = scr; + data.blksize = 8; + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = scr; - mmcsd_set_data_timeout(&data, card); + mmcsd_set_data_timeout(&data, card); - mmcsd_send_request(card->host, &req); + mmcsd_send_request(card->host, &req); - if (cmd.err) - return cmd.err; - if (data.err) - return data.err; + if (cmd.err) + return cmd.err; + if (data.err) + return data.err; - scr[0] = be32_to_cpu(scr[0]); - scr[1] = be32_to_cpu(scr[1]); + scr[0] = be32_to_cpu(scr[0]); + scr[1] = be32_to_cpu(scr[1]); - return 0; + return 0; } -static rt_int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr) +static rt_int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host, + rt_uint32_t ocr) { - struct rt_mmcsd_card *card; - rt_int32_t err; - rt_uint32_t resp[4]; - rt_uint32_t max_data_rate; + struct rt_mmcsd_card *card; + rt_int32_t err; + rt_uint32_t resp[4]; + rt_uint32_t max_data_rate; - mmcsd_go_idle(host); + mmcsd_go_idle(host); - /* - * If SD_SEND_IF_COND indicates an SD 2.0 - * compliant card and we should set bit 30 - * of the ocr to indicate that we can handle - * block-addressed SDHC cards. - */ - err = mmcsd_send_if_cond(host, ocr); - if (!err) - ocr |= 1 << 30; + /* + * If SD_SEND_IF_COND indicates an SD 2.0 + * compliant card and we should set bit 30 + * of the ocr to indicate that we can handle + * block-addressed SDHC cards. + */ + err = mmcsd_send_if_cond(host, ocr); + if (!err) + ocr |= 1 << 30; - err = mmcsd_send_app_op_cond(host, ocr, RT_NULL); - if (err) - goto err; + err = mmcsd_send_app_op_cond(host, ocr, RT_NULL); + if (err) + goto err; - if (controller_is_spi(host)) - err = mmcsd_get_cid(host, resp); - else - err = mmcsd_all_get_cid(host, resp); - if (err) - goto err; + if (controller_is_spi(host)) + err = mmcsd_get_cid(host, resp); + else + err = mmcsd_all_get_cid(host, resp); + if (err) + goto err; - 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 = 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_SD; - card->host = host; - rt_memcpy(card->resp_cid, resp, sizeof(card->resp_cid)); + card->card_type = CARD_TYPE_SD; + card->host = host; + rt_memcpy(card->resp_cid, resp, sizeof(card->resp_cid)); - /* - * For native busses: get card RCA and quit open drain mode. - */ - if (!controller_is_spi(host)) - { - err = mmcsd_get_card_addr(host, &card->rca); - if (err) - goto err1; + /* + * For native busses: get card RCA and quit open drain mode. + */ + if (!controller_is_spi(host)) + { + err = mmcsd_get_card_addr(host, &card->rca); + if (err) + goto err1; - mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL); - } + mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL); + } - err = mmcsd_get_csd(card, card->resp_csd); - if (err) - goto err1; + err = mmcsd_get_csd(card, card->resp_csd); + if (err) + goto err1; - err = mmcsd_parse_csd(card); - if (err) - goto err1; + err = mmcsd_parse_csd(card); + if (err) + goto err1; - if (!controller_is_spi(host)) - { - err = mmcsd_select_card(card); - if (err) - goto err1; - } + if (!controller_is_spi(host)) + { + err = mmcsd_select_card(card); + if (err) + goto err1; + } - err = mmcsd_get_scr(card, card->resp_scr); - if (err) - goto err1; + err = mmcsd_get_scr(card, card->resp_scr); + if (err) + goto err1; - mmcsd_parse_scr(card); + mmcsd_parse_scr(card); - if (controller_is_spi(host)) - { - err = mmcsd_spi_use_crc(host, 1); - if (err) - goto err1; - } + if (controller_is_spi(host)) + { + err = mmcsd_spi_use_crc(host, 1); + if (err) + goto err1; + } - /* - * change SD card to high-speed, only SD2.0 spec - */ - err = mmcsd_switch(card); - if (err) - goto err1; + /* + * change SD card to high-speed, only SD2.0 spec + */ + err = mmcsd_switch(card); + if (err) + goto err1; - /* set bus speed */ - max_data_rate = (unsigned int)-1; + /* set bus speed */ + max_data_rate = (unsigned int)-1; - if (card->flags & CARD_FLAG_HIGHSPEED) - { - if (max_data_rate > card->hs_max_data_rate) - max_data_rate = card->hs_max_data_rate; - } - else if (max_data_rate > card->max_data_rate) - { - max_data_rate = card->max_data_rate; - } + if (card->flags & CARD_FLAG_HIGHSPEED) + { + if (max_data_rate > card->hs_max_data_rate) + max_data_rate = card->hs_max_data_rate; + } + else if (max_data_rate > card->max_data_rate) + { + max_data_rate = card->max_data_rate; + } - mmcsd_set_clock(host, max_data_rate); + mmcsd_set_clock(host, max_data_rate); - /*switch bus width*/ - if ((host->flags & MMCSD_BUSWIDTH_4) && - (card->scr.sd_bus_widths & SD_SCR_BUS_WIDTH_4)) - { - err = mmcsd_app_set_bus_width(card, MMCSD_BUS_WIDTH_4); - if (err) - goto err1; + /*switch bus width*/ + if ((host->flags & MMCSD_BUSWIDTH_4) && + (card->scr.sd_bus_widths & SD_SCR_BUS_WIDTH_4)) + { + err = mmcsd_app_set_bus_width(card, MMCSD_BUS_WIDTH_4); + if (err) + goto err1; - mmcsd_set_bus_width(host, MMCSD_BUS_WIDTH_4); - } + mmcsd_set_bus_width(host, MMCSD_BUS_WIDTH_4); + } - host->card = card; + host->card = card; - return 0; + return 0; err1: - rt_free(card); + rt_free(card); err: - return err; + return err; } /* @@ -660,60 +687,63 @@ err: */ rt_int32_t init_sd(struct rt_mmcsd_host *host, rt_uint32_t ocr) { - rt_int32_t err; - rt_uint32_t current_ocr; - /* - * We need to get OCR a different way for SPI. - */ - if (controller_is_spi(host)) { - mmcsd_go_idle(host); + rt_int32_t err; + rt_uint32_t current_ocr; + /* + * We need to get OCR a different way for SPI. + */ + if (controller_is_spi(host)) + { + mmcsd_go_idle(host); - err = mmcsd_spi_read_ocr(host, 0, &ocr); - if (err) - goto err; - } + err = mmcsd_spi_read_ocr(host, 0, &ocr); + if (err) + goto err; + } - if (ocr & VDD_165_195) { - rt_kprintf(" SD card claims to support the " - "incompletely defined 'low voltage range'. This " - "will be ignored.\n"); - ocr &= ~VDD_165_195; - } + if (ocr & VDD_165_195) + { + rt_kprintf(" SD card claims to support the " + "incompletely defined 'low voltage range'. This " + "will be ignored.\n"); + ocr &= ~VDD_165_195; + } - current_ocr = mmcsd_select_voltage(host, ocr); + current_ocr = mmcsd_select_voltage(host, ocr); - /* - * Can we support the voltage(s) of the card(s)? - */ - if (!current_ocr) { - err = -RT_ERROR; - goto err; - } + /* + * Can we support the voltage(s) of the card(s)? + */ + if (!current_ocr) + { + err = -RT_ERROR; + goto err; + } - /* - * Detect and init the card. - */ - err = mmcsd_sd_init_card(host, current_ocr); - if (err) - goto err; + /* + * Detect and init the card. + */ + err = mmcsd_sd_init_card(host, current_ocr); + if (err) + goto err; - mmcsd_host_unlock(host); + mmcsd_host_unlock(host); - err = rt_mmcsd_blk_probe(host->card); - if (err) - goto remove_card; - mmcsd_host_lock(host); + err = rt_mmcsd_blk_probe(host->card); + if (err) + goto remove_card; + mmcsd_host_lock(host); - return 0; + return 0; remove_card: - mmcsd_host_lock(host); - rt_mmcsd_blk_remove(host->card); - rt_free(host->card); - host->card = RT_NULL; + mmcsd_host_lock(host); + rt_mmcsd_blk_remove(host->card); + rt_free(host->card); + host->card = RT_NULL; err: - rt_kprintf("init SD card failed\n"); + rt_kprintf("init SD card failed\n"); - return err; + return err; } diff --git a/components/drivers/sdio/sdio.c b/components/drivers/sdio/sdio.c index 1b472c5c56..7817ae5c50 100644 --- a/components/drivers/sdio/sdio.c +++ b/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 @@ -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 }; - -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) { - struct rt_mmcsd_cmd cmd; - rt_int32_t i, err = 0; + 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 +}; - RT_ASSERT(host != RT_NULL); +rt_inline rt_int32_t sdio_match_card(struct rt_mmcsd_card *card, + const struct rt_sdio_device_id *id); - 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; +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; - for (i = 100; i; i--) - { - err = mmcsd_send_cmd(host, &cmd, 0); - if (err) - break; + RT_ASSERT(host != RT_NULL); - /* if we're just probing, do a single pass */ - if (ocr == 0) - break; + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); - /* 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; - } + cmd.cmd_code = SD_IO_SEND_OP_COND; + cmd.arg = ocr; + cmd.flags = RESP_SPI_R4 | RESP_R4 | CMD_BCR; - err = -RT_ETIMEOUT; + for (i = 100; i; i--) + { + err = mmcsd_send_cmd(host, &cmd, 0); + if (err) + break; - mmcsd_delay_ms(10); - } + /* if we're just probing, do a single pass */ + if (ocr == 0) + break; - if (cmd5_resp) - *cmd5_resp = cmd.resp[controller_is_spi(host) ? 1 : 0]; + /* 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; + } - return err; + 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; + struct rt_mmcsd_cmd cmd; + rt_int32_t err; - RT_ASSERT(card != RT_NULL); - RT_ASSERT(fn <= SDIO_MAX_FUNCTIONS); + RT_ASSERT(card != RT_NULL); + RT_ASSERT(fn <= SDIO_MAX_FUNCTIONS); - if (reg_addr & ~SDIO_ARG_CMD53_REG_MASK) - return -RT_ERROR; + if (reg_addr & ~SDIO_ARG_CMD53_REG_MASK) + 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_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; + 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; + 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 (!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; - } + if (!rw || raw) + { + if (controller_is_spi(card->host)) + *pdata = (cmd.resp[0] >> 8) & 0xFF; + else + *pdata = cmd.resp[0] & 0xFF; + } - return 0; + 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; + 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); + 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; + 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)); + 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; + 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; + 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; + 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_set_data_timeout(&data, card); - mmcsd_send_request(card->host, &req); + mmcsd_send_request(card->host, &req); - if (cmd.err) - return cmd.err; - if (data.err) - return data.err; + 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; - } + 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; + 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; + 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); + /* 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) { + 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; - 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; - 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; + } + } - left_size -= len; - buf += len; - if (op_code) - addr += len; - } - } + while (left_size > 0) + { + len = MIN(left_size, sdio_max_block_size(func)); - 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; - 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; + } - left_size -= len; - buf += len; - if (op_code) - addr += len; - } - - return 0; + 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_int32_t ret; + rt_int32_t cccr_version; + rt_uint8_t data; - rt_memset(&card->cccr, 0, sizeof(struct rt_sdio_cccr)); + 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; + data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CCCR_REV, &ret); + if (ret) + goto out; - cccr_version = data & 0x0f; + 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; - } + if (cccr_version > SDIO_CCCR_REV_1_20) + { + rt_kprintf("unrecognised CCCR structure version %d\n", cccr_version); - card->cccr.sdio_version = (data & 0xf0) >> 4; + return -RT_ERROR; + } - data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CARD_CAPS, &ret); - if (ret) - goto out; + card->cccr.sdio_version = (data & 0xf0) >> 4; - 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; + data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CARD_CAPS, &ret); + if (ret) + goto out; - 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_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 (data & SDIO_POWER_SMPC) - card->cccr.power_ctrl = 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 (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_POWER_SMPC) + card->cccr.power_ctrl = 1; + } - if (data & SDIO_SPEED_SHS) - card->cccr.high_speed = 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; + 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]; + struct rt_mmcsd_card *card = func->card; + struct rt_sdio_function *func0 = card->sdio_function[0]; - RT_ASSERT(func0 != RT_NULL); + 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); - } + 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; + 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; + 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_END) || (tpl_link == 0xff)) + break; - if (tpl_code == CISTPL_NULL) - continue; + 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); + 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; - } + 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); + 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]); - } + 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; - } + 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); + 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; + /* + * 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; + 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; + 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 = 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); + sc->card = card; + rt_list_insert_after(&sdio_cards, &sc->list); - if (rt_list_isempty(&sdio_drivers)) - { - goto out; - } + 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); - } - } + 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; + 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; + 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; - } + 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; + 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 = 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->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; + 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; + 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); - } + mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL); + } - if (!controller_is_spi(host)) - { - err = mmcsd_select_card(card); - if (err) - goto err2; - } + 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_cccr(card); + if (err) + goto err2; - err = sdio_read_cis(card->sdio_function[0]); - 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; + 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); - } + 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; + 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; - } + 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; - } + /* register sdio card */ + err = sdio_register_card(card); + if (err) + { + goto err3; + } - return 0; + 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); + 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; - } + 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; - } - } - } + 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; - } - } + 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; + 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); + /* 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); - } - } + 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; + return 0; } static rt_int32_t sdio_irq_thread_delete(struct rt_mmcsd_card *card) { - struct rt_mmcsd_host *host = card->host; + struct rt_mmcsd_host *host = card->host; - RT_ASSERT(host->sdio_irq_num > 0); + 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; - } + 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; + 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"); - return -RT_EBUSY; - } + if (func->irq_handler) + { + mmcsd_dbg("SDIO: IRQ for already in use.\n"); - reg = sdio_io_readb(func0, SDIO_REG_CCCR_INT_EN, &ret); - if (ret) - return ret; + return -RT_EBUSY; + } - reg |= 1 << func->num; + reg = sdio_io_readb(func0, SDIO_REG_CCCR_INT_EN, &ret); + if (ret) + return ret; - reg |= 1; /* Master interrupt enable */ + reg |= 1 << func->num; - ret = sdio_io_writeb(func0, SDIO_REG_CCCR_INT_EN, reg); - if (ret) - return ret; + reg |= 1; /* Master interrupt enable */ - func->irq_handler = handler; + ret = sdio_io_writeb(func0, SDIO_REG_CCCR_INT_EN, reg); + if (ret) + return ret; - ret = sdio_irq_thread_create(func->card); - if (ret) - func->irq_handler = RT_NULL; + func->irq_handler = handler; - return ret; + ret = sdio_irq_thread_create(func->card); + if (ret) + func->irq_handler = RT_NULL; + + 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]; + 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 > 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); - } + 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; + 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; + 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; + 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; + 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; + 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; + 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; - } - } + if (sdio_match_card(card, id)) + { + return card; + } + } - return RT_NULL; + return RT_NULL; } rt_int32_t sdio_register_driver(struct rt_sdio_driver *driver) { - struct sdio_driver *sd; - struct rt_mmcsd_card *card; + 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; - } + sd = rt_malloc(sizeof(struct sdio_driver)); + if (sd == RT_NULL) + { + rt_kprintf("malloc sdio driver failed\n"); - rt_list_insert_after(&sdio_drivers, &sd->list); + return -RT_ENOMEM; + } - if (!rt_list_isempty(&sdio_cards)) - { - card = sdio_match_driver(driver->id); - if (card != RT_NULL) - { - driver->probe(card); - } - } + rt_list_insert_after(&sdio_drivers, &sd->list); - return 0; + 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_t *l; + struct sdio_driver *sd = RT_NULL; + struct rt_mmcsd_card *card; - rt_list_insert_after(&sdio_drivers, &sd->list); + 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; - } - } + 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 (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); - } - } + 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; + 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); } diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index d202dcc565..1f6b29e261 100644 --- a/components/drivers/serial/serial.c +++ b/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 diff --git a/components/drivers/spi/spi_core.c b/components/drivers/spi/spi_core.c index 65d99b887e..4ab843a9fd 100644 --- a/components/drivers/spi/spi_core.c +++ b/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 diff --git a/components/drivers/spi/spi_dev.c b/components/drivers/spi/spi_dev.c index 4d113a8b40..b1f6e41a86 100644 --- a/components/drivers/spi/spi_dev.c +++ b/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 diff --git a/components/drivers/src/completion.c b/components/drivers/src/completion.c index 8fd52e1bba..f49e44c48f 100644 --- a/components/drivers/src/completion.c +++ b/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 diff --git a/components/drivers/src/dataqueue.c b/components/drivers/src/dataqueue.c index 5910e1010c..1702d20710 100644 --- a/components/drivers/src/dataqueue.c +++ b/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 diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index 0d2027a83a..c10cceb9b4 100644 --- a/components/drivers/src/pipe.c +++ b/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 diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index 0ae8abfb54..8e7e8c7895 100644 --- a/components/drivers/src/ringbuffer.c +++ b/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 diff --git a/components/drivers/usb/usbdevice/class/cdc.h b/components/drivers/usb/usbdevice/class/cdc.h index f82e7ac2a2..66b4c602a0 100644 --- a/components/drivers/usb/usbdevice/class/cdc.h +++ b/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 diff --git a/components/drivers/usb/usbdevice/class/cdc_vcom.c b/components/drivers/usb/usbdevice/class/cdc_vcom.c index 13df7f598e..1dee3a4d79 100644 --- a/components/drivers/usb/usbdevice/class/cdc_vcom.c +++ b/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 diff --git a/components/drivers/usb/usbdevice/class/mstorage.c b/components/drivers/usb/usbdevice/class/mstorage.c index f43a7525f9..b0351f63e5 100644 --- a/components/drivers/usb/usbdevice/class/mstorage.c +++ b/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 diff --git a/components/drivers/usb/usbdevice/class/mstorage.h b/components/drivers/usb/usbdevice/class/mstorage.h index 951cbdfef8..4d53222a00 100644 --- a/components/drivers/usb/usbdevice/class/mstorage.h +++ b/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 diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c index 2be6bd76a9..12e9f1580b 100644 --- a/components/drivers/usb/usbdevice/core/core.c +++ b/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 diff --git a/components/drivers/usb/usbdevice/core/usbdevice.c b/components/drivers/usb/usbdevice/core/usbdevice.c index e4f5097045..f5b2b9beac 100644 --- a/components/drivers/usb/usbdevice/core/usbdevice.c +++ b/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 diff --git a/components/drivers/usb/usbhost/class/adk.c b/components/drivers/usb/usbhost/class/adk.c index ff9bef92dd..0b470f6884 100644 --- a/components/drivers/usb/usbhost/class/adk.c +++ b/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 diff --git a/components/drivers/usb/usbhost/class/adk.h b/components/drivers/usb/usbhost/class/adk.h index ef18ab2714..95140ceb7d 100644 --- a/components/drivers/usb/usbhost/class/adk.h +++ b/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 diff --git a/components/drivers/usb/usbhost/core/core.c b/components/drivers/usb/usbhost/core/core.c index d689f7a249..e7da42f7e4 100644 --- a/components/drivers/usb/usbhost/core/core.c +++ b/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 diff --git a/components/drivers/usb/usbhost/core/driver.c b/components/drivers/usb/usbhost/core/driver.c index 7aeb4cef58..52457d7cfc 100644 --- a/components/drivers/usb/usbhost/core/driver.c +++ b/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 diff --git a/components/drivers/usb/usbhost/core/hub.c b/components/drivers/usb/usbhost/core/hub.c index 05016cb6f7..c907defcf6 100644 --- a/components/drivers/usb/usbhost/core/hub.c +++ b/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 diff --git a/components/drivers/usb/usbhost/core/usbhost.c b/components/drivers/usb/usbhost/core/usbhost.c index 649fa0b20c..9c0665d28c 100644 --- a/components/drivers/usb/usbhost/core/usbhost.c +++ b/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