Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
fe13ae0
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
cpufreq
cpuidle
crypto
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fmc
fpga
fsi
gpio
gpu
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
ide
idle
iio
infiniband
input
iommu
ipack
irqchip
isdn
leds
lightnvm
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
mtd
chips
devices
lpddr
maps
nand
onenand
raw
atmel
bcm47xxnflash
brcmnand
gpmi-nand
Kconfig
Makefile
ams-delta.c
au1550nd.c
cafe_nand.c
cmx270_nand.c
cs553x_nand.c
davinci_nand.c
denali.c
denali.h
denali_dt.c
denali_pci.c
diskonchip.c
docg4.c
fsl_elbc_nand.c
fsl_ifc_nand.c
fsl_upm.c
fsmc_nand.c
gpio.c
hisi504_nand.c
jz4740_nand.c
jz4780_bch.c
jz4780_bch.h
jz4780_nand.c
lpc32xx_mlc.c
lpc32xx_slc.c
marvell_nand.c
mpc5121_nfc.c
mtk_ecc.c
mtk_ecc.h
mtk_nand.c
mxc_nand.c
nand_amd.c
nand_base.c
nand_bbt.c
nand_bch.c
nand_ecc.c
nand_hynix.c
nand_ids.c
nand_macronix.c
nand_micron.c
nand_samsung.c
nand_timings.c
nand_toshiba.c
nandsim.c
ndfc.c
nuc900_nand.c
omap2.c
omap_elm.c
orion_nand.c
oxnas_nand.c
pasemi_nand.c
plat_nand.c
qcom_nandc.c
r852.c
r852.h
s3c2410.c
sh_flctl.c
sharpsl.c
sm_common.c
sm_common.h
socrates_nand.c
sunxi_nand.c
tango_nand.c
tegra_nand.c
tmio_nand.c
txx9ndfmc.c
vf610_nfc.c
xway_nand.c
spi
Kconfig
Makefile
bbt.c
core.c
parsers
spi-nor
tests
ubi
Kconfig
Makefile
afs.c
ar7part.c
bcm47xxpart.c
bcm63xxpart.c
cmdlinepart.c
ftl.c
inftlcore.c
inftlmount.c
mtd_blkdevs.c
mtdblock.c
mtdblock_ro.c
mtdchar.c
mtdconcat.c
mtdcore.c
mtdcore.h
mtdoops.c
mtdpart.c
mtdsuper.c
mtdswap.c
nftlcore.c
nftlmount.c
ofpart.c
redboot.c
rfd_ftl.c
sm_ftl.c
sm_ftl.h
ssfdc.c
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
oprofile
parisc
parport
pci
pcmcia
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sfi
sh
siox
slimbus
sn
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
uwb
vfio
vhost
video
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
mtd
/
nand
/
raw
/
sm_common.c
Blame
Blame
Latest commit
History
History
212 lines (180 loc) · 5.77 KB
Breadcrumbs
linux
/
drivers
/
mtd
/
nand
/
raw
/
sm_common.c
Top
File metadata and controls
Code
Blame
212 lines (180 loc) · 5.77 KB
Raw
/* * Copyright © 2009 - Maxim Levitsky * Common routines & support for xD format * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/kernel.h> #include <linux/mtd/rawnand.h> #include <linux/module.h> #include <linux/sizes.h> #include "sm_common.h" static int oob_sm_ooblayout_ecc(struct mtd_info *mtd, int section, struct mtd_oob_region *oobregion) { if (section > 1) return -ERANGE; oobregion->length = 3; oobregion->offset = ((section + 1) * 8) - 3; return 0; } static int oob_sm_ooblayout_free(struct mtd_info *mtd, int section, struct mtd_oob_region *oobregion) { switch (section) { case 0: /* reserved */ oobregion->offset = 0; oobregion->length = 4; break; case 1: /* LBA1 */ oobregion->offset = 6; oobregion->length = 2; break; case 2: /* LBA2 */ oobregion->offset = 11; oobregion->length = 2; break; default: return -ERANGE; } return 0; } static const struct mtd_ooblayout_ops oob_sm_ops = { .ecc = oob_sm_ooblayout_ecc, .free = oob_sm_ooblayout_free, }; /* NOTE: This layout is is not compatabable with SmartMedia, */ /* because the 256 byte devices have page depenent oob layout */ /* However it does preserve the bad block markers */ /* If you use smftl, it will bypass this and work correctly */ /* If you not, then you break SmartMedia compliance anyway */ static int oob_sm_small_ooblayout_ecc(struct mtd_info *mtd, int section, struct mtd_oob_region *oobregion) { if (section) return -ERANGE; oobregion->length = 3; oobregion->offset = 0; return 0; } static int oob_sm_small_ooblayout_free(struct mtd_info *mtd, int section, struct mtd_oob_region *oobregion) { switch (section) { case 0: /* reserved */ oobregion->offset = 3; oobregion->length = 2; break; case 1: /* LBA1 */ oobregion->offset = 6; oobregion->length = 2; break; default: return -ERANGE; } return 0; } static const struct mtd_ooblayout_ops oob_sm_small_ops = { .ecc = oob_sm_small_ooblayout_ecc, .free = oob_sm_small_ooblayout_free, }; static int sm_block_markbad(struct mtd_info *mtd, loff_t ofs) { struct mtd_oob_ops ops; struct sm_oob oob; int ret; memset(&oob, -1, SM_OOB_SIZE); oob.block_status = 0x0F; /* As long as this function is called on erase block boundaries it will work correctly for 256 byte nand */ ops.mode = MTD_OPS_PLACE_OOB; ops.ooboffs = 0; ops.ooblen = mtd->oobsize; ops.oobbuf = (void *)&oob; ops.datbuf = NULL; ret = mtd_write_oob(mtd, ofs, &ops); if (ret < 0 || ops.oobretlen != SM_OOB_SIZE) { pr_notice("sm_common: can't mark sector at %i as bad\n", (int)ofs); return -EIO; } return 0; } static struct nand_flash_dev nand_smartmedia_flash_ids[] = { LEGACY_ID_NAND("SmartMedia 2MiB 3,3V ROM", 0x5d, 2, SZ_8K, NAND_ROM), LEGACY_ID_NAND("SmartMedia 4MiB 3,3V", 0xe3, 4, SZ_8K, 0), LEGACY_ID_NAND("SmartMedia 4MiB 3,3/5V", 0xe5, 4, SZ_8K, 0), LEGACY_ID_NAND("SmartMedia 4MiB 5V", 0x6b, 4, SZ_8K, 0), LEGACY_ID_NAND("SmartMedia 4MiB 3,3V ROM", 0xd5, 4, SZ_8K, NAND_ROM), LEGACY_ID_NAND("SmartMedia 8MiB 3,3V", 0xe6, 8, SZ_8K, 0), LEGACY_ID_NAND("SmartMedia 8MiB 3,3V ROM", 0xd6, 8, SZ_8K, NAND_ROM), LEGACY_ID_NAND("SmartMedia 16MiB 3,3V", 0x73, 16, SZ_16K, 0), LEGACY_ID_NAND("SmartMedia 16MiB 3,3V ROM", 0x57, 16, SZ_16K, NAND_ROM), LEGACY_ID_NAND("SmartMedia 32MiB 3,3V", 0x75, 32, SZ_16K, 0), LEGACY_ID_NAND("SmartMedia 32MiB 3,3V ROM", 0x58, 32, SZ_16K, NAND_ROM), LEGACY_ID_NAND("SmartMedia 64MiB 3,3V", 0x76, 64, SZ_16K, 0), LEGACY_ID_NAND("SmartMedia 64MiB 3,3V ROM", 0xd9, 64, SZ_16K, NAND_ROM), LEGACY_ID_NAND("SmartMedia 128MiB 3,3V", 0x79, 128, SZ_16K, 0), LEGACY_ID_NAND("SmartMedia 128MiB 3,3V ROM", 0xda, 128, SZ_16K, NAND_ROM), LEGACY_ID_NAND("SmartMedia 256MiB 3, 3V", 0x71, 256, SZ_16K, 0), LEGACY_ID_NAND("SmartMedia 256MiB 3,3V ROM", 0x5b, 256, SZ_16K, NAND_ROM), {NULL} }; static struct nand_flash_dev nand_xd_flash_ids[] = { LEGACY_ID_NAND("xD 16MiB 3,3V", 0x73, 16, SZ_16K, 0), LEGACY_ID_NAND("xD 32MiB 3,3V", 0x75, 32, SZ_16K, 0), LEGACY_ID_NAND("xD 64MiB 3,3V", 0x76, 64, SZ_16K, 0), LEGACY_ID_NAND("xD 128MiB 3,3V", 0x79, 128, SZ_16K, 0), LEGACY_ID_NAND("xD 256MiB 3,3V", 0x71, 256, SZ_16K, NAND_BROKEN_XD), LEGACY_ID_NAND("xD 512MiB 3,3V", 0xdc, 512, SZ_16K, NAND_BROKEN_XD), LEGACY_ID_NAND("xD 1GiB 3,3V", 0xd3, 1024, SZ_16K, NAND_BROKEN_XD), LEGACY_ID_NAND("xD 2GiB 3,3V", 0xd5, 2048, SZ_16K, NAND_BROKEN_XD), {NULL} }; static int sm_attach_chip(struct nand_chip *chip) { struct mtd_info *mtd = nand_to_mtd(chip); /* Bad block marker position */ chip->badblockpos = 0x05; chip->badblockbits = 7; chip->block_markbad = sm_block_markbad; /* ECC layout */ if (mtd->writesize == SM_SECTOR_SIZE) mtd_set_ooblayout(mtd, &oob_sm_ops); else if (mtd->writesize == SM_SMALL_PAGE) mtd_set_ooblayout(mtd, &oob_sm_small_ops); else return -ENODEV; return 0; } static const struct nand_controller_ops sm_controller_ops = { .attach_chip = sm_attach_chip, }; int sm_register_device(struct mtd_info *mtd, int smartmedia) { struct nand_chip *chip = mtd_to_nand(mtd); struct nand_flash_dev *flash_ids; int ret; chip->options |= NAND_SKIP_BBTSCAN; /* Scan for card properties */ chip->dummy_controller.ops = &sm_controller_ops; flash_ids = smartmedia ? nand_smartmedia_flash_ids : nand_xd_flash_ids; ret = nand_scan_with_ids(mtd, 1, flash_ids); if (ret) return ret; ret = mtd_device_register(mtd, NULL, 0); if (ret) nand_cleanup(chip); return ret; } EXPORT_SYMBOL_GPL(sm_register_device); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Maxim Levitsky <maximlevitsky@gmail.com>"); MODULE_DESCRIPTION("Common SmartMedia/xD functions");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
You can’t perform that action at this time.