mmcsd.c (224868) | mmcsd.c (234524) |
---|---|
1/*- 2 * Copyright (c) 2006 Bernd Walter. All rights reserved. 3 * Copyright (c) 2006 M. Warner Losh. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 37 unchanged lines hidden (view full) --- 46 * implication, estoppel or otherwise under any patent or other rights of the 47 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing 48 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC 49 * or the SD Card Association to disclose or distribute any technical 50 * information, know-how or other confidential information to any third party. 51 */ 52 53#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 Bernd Walter. All rights reserved. 3 * Copyright (c) 2006 M. Warner Losh. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 37 unchanged lines hidden (view full) --- 46 * implication, estoppel or otherwise under any patent or other rights of the 47 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing 48 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC 49 * or the SD Card Association to disclose or distribute any technical 50 * information, know-how or other confidential information to any third party. 51 */ 52 53#include <sys/cdefs.h> |
54__FBSDID("$FreeBSD: head/sys/dev/mmc/mmcsd.c 224868 2011-08-14 16:17:00Z mav $"); | 54__FBSDID("$FreeBSD: head/sys/dev/mmc/mmcsd.c 234524 2012-04-21 01:51:16Z marius $"); |
55 56#include <sys/param.h> 57#include <sys/systm.h> 58#include <sys/bio.h> 59#include <sys/bus.h> 60#include <sys/conf.h> 61#include <sys/kernel.h> 62#include <sys/kthread.h> 63#include <sys/lock.h> 64#include <sys/malloc.h> 65#include <sys/module.h> 66#include <sys/mutex.h> 67#include <geom/geom_disk.h> 68 | 55 56#include <sys/param.h> 57#include <sys/systm.h> 58#include <sys/bio.h> 59#include <sys/bus.h> 60#include <sys/conf.h> 61#include <sys/kernel.h> 62#include <sys/kthread.h> 63#include <sys/lock.h> 64#include <sys/malloc.h> 65#include <sys/module.h> 66#include <sys/mutex.h> 67#include <geom/geom_disk.h> 68 |
69#include | 69#include <dev/mmc/mmcbrvar.h> |
70#include <dev/mmc/mmcreg.h> | 70#include <dev/mmc/mmcreg.h> |
71#include <dev/mmc/mmcvar.h> |
|
71 72#include "mmcbus_if.h" 73 | 72 73#include "mmcbus_if.h" 74 |
75#if __FreeBSD_version < 800002 76#define kproc_create kthread_create 77#define kproc_exit kthread_exit 78#endif 79 |
|
74struct mmcsd_softc { 75 device_t dev; 76 struct mtx sc_mtx; 77 struct disk *disk; 78 struct proc *p; 79 struct bio_queue_head bio_queue; 80 daddr_t eblock, eend; /* Range remaining after the last erase. */ 81 int running; --- 8 unchanged lines hidden (view full) --- 90/* disk routines */ 91static int mmcsd_open(struct disk *dp); 92static int mmcsd_close(struct disk *dp); 93static void mmcsd_strategy(struct bio *bp); 94static int mmcsd_dump(void *arg, void *virtual, vm_offset_t physical, 95 off_t offset, size_t length); 96static void mmcsd_task(void *arg); 97 | 80struct mmcsd_softc { 81 device_t dev; 82 struct mtx sc_mtx; 83 struct disk *disk; 84 struct proc *p; 85 struct bio_queue_head bio_queue; 86 daddr_t eblock, eend; /* Range remaining after the last erase. */ 87 int running; --- 8 unchanged lines hidden (view full) --- 96/* disk routines */ 97static int mmcsd_open(struct disk *dp); 98static int mmcsd_close(struct disk *dp); 99static void mmcsd_strategy(struct bio *bp); 100static int mmcsd_dump(void *arg, void *virtual, vm_offset_t physical, 101 off_t offset, size_t length); 102static void mmcsd_task(void *arg); 103 |
98static const char *mmcsd_card_name(device_t dev); | |
99static int mmcsd_bus_bit_width(device_t dev); 100 101#define MMCSD_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 102#define MMCSD_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 103#define MMCSD_LOCK_INIT(_sc) \ 104 mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->dev), \ 105 "mmcsd", MTX_DEF) 106#define MMCSD_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); --- 10 unchanged lines hidden (view full) --- 117} 118 119static int 120mmcsd_attach(device_t dev) 121{ 122 struct mmcsd_softc *sc; 123 struct disk *d; 124 intmax_t mb; | 104static int mmcsd_bus_bit_width(device_t dev); 105 106#define MMCSD_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 107#define MMCSD_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 108#define MMCSD_LOCK_INIT(_sc) \ 109 mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->dev), \ 110 "mmcsd", MTX_DEF) 111#define MMCSD_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); --- 10 unchanged lines hidden (view full) --- 122} 123 124static int 125mmcsd_attach(device_t dev) 126{ 127 struct mmcsd_softc *sc; 128 struct disk *d; 129 intmax_t mb; |
130 uint32_t speed; 131 uint32_t maxblocks; |
|
125 char unit; 126 127 sc = device_get_softc(dev); 128 sc->dev = dev; 129 MMCSD_LOCK_INIT(sc); 130 131 d = sc->disk = disk_alloc(); 132 d->d_open = mmcsd_open; --- 19 unchanged lines hidden (view full) --- 152 * code to print TiB). 153 */ 154 mb = d->d_mediasize >> 20; /* 1MiB == 1 << 20 */ 155 unit = 'M'; 156 if (mb >= 10240) { /* 1GiB = 1024 MiB */ 157 unit = 'G'; 158 mb /= 1024; 159 } | 132 char unit; 133 134 sc = device_get_softc(dev); 135 sc->dev = dev; 136 MMCSD_LOCK_INIT(sc); 137 138 d = sc->disk = disk_alloc(); 139 d->d_open = mmcsd_open; --- 19 unchanged lines hidden (view full) --- 159 * code to print TiB). 160 */ 161 mb = d->d_mediasize >> 20; /* 1MiB == 1 << 20 */ 162 unit = 'M'; 163 if (mb >= 10240) { /* 1GiB = 1024 MiB */ 164 unit = 'G'; 165 mb /= 1024; 166 } |
160 device_printf(dev, "%ju%cB <%s Memory Card>%s at %s %dMHz/%dbit\n", 161 mb, unit, mmcsd_card_name(dev), | 167 /* 168 * Report the clock speed of the underlying hardware, which might be 169 * different than what the card reports due to hardware limitations. 170 * Report how many blocks the hardware transfers at once, but clip the 171 * number to MAXPHYS since the system won't initiate larger transfers. 172 */ 173 speed = mmcbr_get_clock(device_get_parent(dev)); 174 maxblocks = mmc_get_max_data(dev); 175 if (maxblocks > MAXPHYS) 176 maxblocks = MAXPHYS; 177 device_printf(dev, "%ju%cB <%s>%s at %s %d.%01dMHz/%dbit/%d-block\n", 178 mb, unit, mmc_get_card_id_string(dev), |
162 mmc_get_read_only(dev) ? " (read-only)" : "", 163 device_get_nameunit(device_get_parent(dev)), | 179 mmc_get_read_only(dev) ? " (read-only)" : "", 180 device_get_nameunit(device_get_parent(dev)), |
164 mmc_get_tran_speed(dev) / 1000000, mmcsd_bus_bit_width(dev)); | 181 speed / 1000000, (speed / 100000) % 10, 182 mmcsd_bus_bit_width(dev), maxblocks); |
165 disk_create(d, DISK_VERSION); 166 bioq_init(&sc->bio_queue); 167 168 sc->running = 1; 169 sc->suspend = 0; 170 sc->eblock = sc->eend = 0; 171 kproc_create(&mmcsd_task, sc, &sc->p, 0, 0, "task: mmc/sd card"); 172 --- 322 unchanged lines hidden (view full) --- 495 /* tell parent we're done */ 496 sc->running = -1; 497 MMCSD_UNLOCK(sc); 498 wakeup(sc); 499 500 kproc_exit(0); 501} 502 | 183 disk_create(d, DISK_VERSION); 184 bioq_init(&sc->bio_queue); 185 186 sc->running = 1; 187 sc->suspend = 0; 188 sc->eblock = sc->eend = 0; 189 kproc_create(&mmcsd_task, sc, &sc->p, 0, 0, "task: mmc/sd card"); 190 --- 322 unchanged lines hidden (view full) --- 513 /* tell parent we're done */ 514 sc->running = -1; 515 MMCSD_UNLOCK(sc); 516 wakeup(sc); 517 518 kproc_exit(0); 519} 520 |
503static const char * 504mmcsd_card_name(device_t dev) 505{ 506 if (mmc_get_card_type(dev) == mode_mmc) 507 return ("MMC"); 508 if (mmc_get_high_cap(dev)) 509 return ("SDHC"); 510 return ("SD"); 511} 512 | |
513static int 514mmcsd_bus_bit_width(device_t dev) 515{ 516 if (mmc_get_bus_width(dev) == bus_width_1) 517 return (1); 518 if (mmc_get_bus_width(dev) == bus_width_4) 519 return (4); 520 return (8); 521} 522 523static device_method_t mmcsd_methods[] = { 524 DEVMETHOD(device_probe, mmcsd_probe), 525 DEVMETHOD(device_attach, mmcsd_attach), 526 DEVMETHOD(device_detach, mmcsd_detach), 527 DEVMETHOD(device_suspend, mmcsd_suspend), 528 DEVMETHOD(device_resume, mmcsd_resume), | 521static int 522mmcsd_bus_bit_width(device_t dev) 523{ 524 if (mmc_get_bus_width(dev) == bus_width_1) 525 return (1); 526 if (mmc_get_bus_width(dev) == bus_width_4) 527 return (4); 528 return (8); 529} 530 531static device_method_t mmcsd_methods[] = { 532 DEVMETHOD(device_probe, mmcsd_probe), 533 DEVMETHOD(device_attach, mmcsd_attach), 534 DEVMETHOD(device_detach, mmcsd_detach), 535 DEVMETHOD(device_suspend, mmcsd_suspend), 536 DEVMETHOD(device_resume, mmcsd_resume), |
529 {0, 0}, | 537 DEVMETHOD_END |
530}; 531 532static driver_t mmcsd_driver = { 533 "mmcsd", 534 mmcsd_methods, 535 sizeof(struct mmcsd_softc), 536}; 537static devclass_t mmcsd_devclass; 538 | 538}; 539 540static driver_t mmcsd_driver = { 541 "mmcsd", 542 mmcsd_methods, 543 sizeof(struct mmcsd_softc), 544}; 545static devclass_t mmcsd_devclass; 546 |
539DRIVER_MODULE(mmcsd, mmc, mmcsd_driver, mmcsd_devclass, 0, 0); | 547DRIVER_MODULE(mmcsd, mmc, mmcsd_driver, mmcsd_devclass, NULL, NULL); |