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 __FBSDID("$FreeBSD$"); 31 32 #include <sys/ioctl.h> 33 #include <sys/stdint.h> 34 #include <sys/types.h> 35 #include <sys/stat.h> 36 #include <sys/endian.h> 37 #include <sys/sbuf.h> 38 #include <sys/mman.h> 39 40 #include <stdio.h> 41 #include <stdlib.h> 42 #include <string.h> 43 #include <unistd.h> 44 #include <inttypes.h> 45 #include <limits.h> 46 #include <fcntl.h> 47 #include <ctype.h> 48 #include <err.h> 49 #include <libutil.h> 50 #include <unistd.h> 51 52 #include <cam/cam.h> 53 #include <cam/cam_debug.h> 54 #include <cam/cam_ccb.h> 55 #include <cam/mmc/mmc_all.h> 56 #include <camlib.h> 57 58 struct cis_info { 59 uint16_t man_id; 60 uint16_t prod_id; 61 uint16_t max_block_size; 62 }; 63 64 int sdio_rw_direct(struct cam_device *dev, 65 uint8_t func_number, 66 uint32_t addr, 67 uint8_t is_write, 68 uint8_t *data, 69 uint8_t *resp); 70 int 71 sdio_rw_extended(struct cam_device *dev, 72 uint8_t func_number, 73 uint32_t addr, 74 uint8_t is_write, 75 caddr_t data, size_t datalen, 76 uint8_t is_increment, 77 uint16_t blk_count); 78 uint8_t sdio_read_1(struct cam_device *dev, uint8_t func_number, uint32_t addr, int *ret); 79 int sdio_write_1(struct cam_device *dev, uint8_t func_number, uint32_t addr, uint8_t val); 80 uint16_t sdio_read_2(struct cam_device *dev, uint8_t func_number, uint32_t addr, int *ret); 81 int sdio_write_2(struct cam_device *dev, uint8_t func_number, uint32_t addr, uint16_t val); 82 uint32_t sdio_read_4(struct cam_device *dev, uint8_t func_number, uint32_t addr, int *ret); 83 int sdio_write_4(struct cam_device *dev, uint8_t func_number, uint32_t addr, uint32_t val); 84 int sdio_read_bool_for_func(struct cam_device *dev, uint32_t addr, uint8_t func_number, uint8_t *is_enab); 85 int sdio_set_bool_for_func(struct cam_device *dev, uint32_t addr, uint8_t func_number, int enable); 86 int sdio_is_func_ready(struct cam_device *dev, uint8_t func_number, uint8_t *is_enab); 87 int sdio_is_func_enabled(struct cam_device *dev, uint8_t func_number, uint8_t *is_enab); 88 int sdio_func_enable(struct cam_device *dev, uint8_t func_number, int enable); 89 int sdio_is_func_intr_enabled(struct cam_device *dev, uint8_t func_number, uint8_t *is_enab); 90 int sdio_func_intr_enable(struct cam_device *dev, uint8_t func_number, int enable); 91 void sdio_card_reset(struct cam_device *dev); 92 uint32_t sdio_get_common_cis_addr(struct cam_device *dev); 93 int sdio_func_read_cis(struct cam_device *dev, uint8_t func_number, 94 uint32_t cis_addr, struct cis_info *info); 95 int sdio_card_set_bus_width(struct cam_device *dev, enum mmc_bus_width bw); 96