1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2017 Ilya Bakulin 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 #include <sys/ioctl.h> 31 #include <sys/stdint.h> 32 #include <sys/types.h> 33 #include <sys/stat.h> 34 #include <sys/endian.h> 35 #include <sys/sbuf.h> 36 #include <sys/mman.h> 37 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <string.h> 41 #include <unistd.h> 42 #include <inttypes.h> 43 #include <limits.h> 44 #include <fcntl.h> 45 #include <ctype.h> 46 #include <err.h> 47 #include <libutil.h> 48 #include <unistd.h> 49 50 #include <cam/cam.h> 51 #include <cam/cam_debug.h> 52 #include <cam/cam_ccb.h> 53 #include <cam/mmc/mmc_all.h> 54 #include <camlib.h> 55 56 struct cis_info { 57 uint16_t man_id; 58 uint16_t prod_id; 59 uint16_t max_block_size; 60 }; 61 62 int sdio_rw_direct(struct cam_device *dev, 63 uint8_t func_number, 64 uint32_t addr, 65 uint8_t is_write, 66 uint8_t *data, 67 uint8_t *resp); 68 int 69 sdio_rw_extended(struct cam_device *dev, 70 uint8_t func_number, 71 uint32_t addr, 72 uint8_t is_write, 73 caddr_t data, size_t datalen, 74 uint8_t is_increment, 75 uint16_t blk_count); 76 uint8_t sdio_read_1(struct cam_device *dev, uint8_t func_number, uint32_t addr, int *ret); 77 int sdio_write_1(struct cam_device *dev, uint8_t func_number, uint32_t addr, uint8_t val); 78 uint16_t sdio_read_2(struct cam_device *dev, uint8_t func_number, uint32_t addr, int *ret); 79 int sdio_write_2(struct cam_device *dev, uint8_t func_number, uint32_t addr, uint16_t val); 80 uint32_t sdio_read_4(struct cam_device *dev, uint8_t func_number, uint32_t addr, int *ret); 81 int sdio_write_4(struct cam_device *dev, uint8_t func_number, uint32_t addr, uint32_t val); 82 int sdio_read_bool_for_func(struct cam_device *dev, uint32_t addr, uint8_t func_number, uint8_t *is_enab); 83 int sdio_set_bool_for_func(struct cam_device *dev, uint32_t addr, uint8_t func_number, int enable); 84 int sdio_is_func_ready(struct cam_device *dev, uint8_t func_number, uint8_t *is_enab); 85 int sdio_is_func_enabled(struct cam_device *dev, uint8_t func_number, uint8_t *is_enab); 86 int sdio_func_enable(struct cam_device *dev, uint8_t func_number, int enable); 87 int sdio_is_func_intr_enabled(struct cam_device *dev, uint8_t func_number, uint8_t *is_enab); 88 int sdio_func_intr_enable(struct cam_device *dev, uint8_t func_number, int enable); 89 void sdio_card_reset(struct cam_device *dev); 90 uint32_t sdio_get_common_cis_addr(struct cam_device *dev); 91 int sdio_func_read_cis(struct cam_device *dev, uint8_t func_number, 92 uint32_t cis_addr, struct cis_info *info); 93 int sdio_card_set_bus_width(struct cam_device *dev, enum mmc_bus_width bw); 94