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