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
730bc8b
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
comedi
connector
counter
cpufreq
cpuidle
crypto
cxl
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fpga
fsi
gnss
gpio
gpu
greybus
hid
hsi
hte
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
most
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
parisc
parport
pci
pcmcia
peci
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sh
siox
slimbus
soc
soundwire
spi
Kconfig
Makefile
atmel-quadspi.c
internals.h
spi-altera-core.c
spi-altera-dfl.c
spi-altera-platform.c
spi-amd.c
spi-ar934x.c
spi-armada-3700.c
spi-aspeed-smc.c
spi-at91-usart.c
spi-ath79.c
spi-atmel.c
spi-au1550.c
spi-axi-spi-engine.c
spi-bcm-qspi.c
spi-bcm-qspi.h
spi-bcm2835.c
spi-bcm2835aux.c
spi-bcm63xx-hsspi.c
spi-bcm63xx.c
spi-bitbang-txrx.h
spi-bitbang.c
spi-brcmstb-qspi.c
spi-butterfly.c
spi-cadence-quadspi.c
spi-cadence-xspi.c
spi-cadence.c
spi-cavium-octeon.c
spi-cavium-thunderx.c
spi-cavium.c
spi-cavium.h
spi-clps711x.c
spi-coldfire-qspi.c
spi-davinci.c
spi-dln2.c
spi-dw-bt1.c
spi-dw-core.c
spi-dw-dma.c
spi-dw-mmio.c
spi-dw-pci.c
spi-dw.h
spi-ep93xx.c
spi-falcon.c
spi-fsi.c
spi-fsl-cpm.c
spi-fsl-cpm.h
spi-fsl-dspi.c
spi-fsl-espi.c
spi-fsl-lib.c
spi-fsl-lib.h
spi-fsl-lpspi.c
spi-fsl-qspi.c
spi-fsl-spi.c
spi-fsl-spi.h
spi-geni-qcom.c
spi-gpio.c
spi-gxp.c
spi-hisi-kunpeng.c
spi-hisi-sfc-v3xx.c
spi-img-spfi.c
spi-imx.c
spi-ingenic.c
spi-intel-pci.c
spi-intel-platform.c
spi-intel.c
spi-intel.h
spi-iproc-qspi.c
spi-jcore.c
spi-lantiq-ssc.c
spi-lm70llp.c
spi-loopback-test.c
spi-lp8841-rtc.c
spi-mem.c
spi-meson-spicc.c
spi-meson-spifc.c
spi-microchip-core.c
spi-mpc512x-psc.c
spi-mpc52xx-psc.c
spi-mpc52xx.c
spi-mt65xx.c
spi-mt7621.c
spi-mtk-nor.c
spi-mtk-snfi.c
spi-mux.c
spi-mxic.c
spi-mxs.c
spi-npcm-fiu.c
spi-npcm-pspi.c
spi-nxp-fspi.c
spi-oc-tiny.c
spi-omap-100k.c
spi-omap-uwire.c
spi-omap2-mcspi.c
spi-orion.c
spi-pic32-sqi.c
spi-pic32.c
spi-pl022.c
spi-ppc4xx.c
spi-pxa2xx-dma.c
spi-pxa2xx-pci.c
spi-pxa2xx.c
spi-pxa2xx.h
spi-qcom-qspi.c
spi-qup.c
spi-rb4xx.c
spi-realtek-rtl.c
spi-rockchip-sfc.c
spi-rockchip.c
spi-rpc-if.c
spi-rspi.c
spi-s3c24xx-regs.h
spi-s3c24xx.c
spi-s3c64xx.c
spi-sc18is602.c
spi-sh-hspi.c
spi-sh-msiof.c
spi-sh-sci.c
spi-sh.c
spi-sifive.c
spi-slave-mt27xx.c
spi-slave-system-control.c
spi-slave-time.c
spi-sprd-adi.c
spi-sprd.c
spi-st-ssc4.c
spi-stm32-qspi.c
spi-stm32.c
spi-sun4i.c
spi-sun6i.c
spi-sunplus-sp7021.c
spi-synquacer.c
spi-tegra114.c
spi-tegra20-sflash.c
spi-tegra20-slink.c
spi-tegra210-quad.c
spi-test.h
spi-ti-qspi.c
spi-tle62x0.c
spi-topcliff-pch.c
spi-uniphier.c
spi-xcomm.c
spi-xilinx.c
spi-xlp.c
spi-xtensa-xtfpga.c
spi-zynq-qspi.c
spi-zynqmp-gqspi.c
spi.c
spidev.c
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
ufs
uio
usb
vdpa
vfio
vhost
video
virt
virtio
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
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
/
spi
/
spi-gxp.c
Blame
Blame
Latest commit
History
History
325 lines (253 loc) · 7.64 KB
Breadcrumbs
linux
/
drivers
/
spi
/
spi-gxp.c
Top
File metadata and controls
Code
Blame
325 lines (253 loc) · 7.64 KB
Raw
// SPDX-License-Identifier: GPL-2.0=or-later /* Copyright (C) 2022 Hewlett-Packard Development Company, L.P. */ #include <linux/iopoll.h> #include <linux/of.h> #include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/spi/spi.h> #include <linux/spi/spi-mem.h> #define GXP_SPI0_MAX_CHIPSELECT 2 #define GXP_SPI_SLEEP_TIME 1 #define GXP_SPI_TIMEOUT (130 * 1000000 / GXP_SPI_SLEEP_TIME) #define MANUAL_MODE 0 #define DIRECT_MODE 1 #define SPILDAT_LEN 256 #define OFFSET_SPIMCFG 0x0 #define OFFSET_SPIMCTRL 0x4 #define OFFSET_SPICMD 0x5 #define OFFSET_SPIDCNT 0x6 #define OFFSET_SPIADDR 0x8 #define OFFSET_SPIINTSTS 0xc #define SPIMCTRL_START 0x01 #define SPIMCTRL_BUSY 0x02 #define SPIMCTRL_DIR 0x08 struct gxp_spi; struct gxp_spi_chip { struct gxp_spi *spifi; u32 cs; }; struct gxp_spi_data { u32 max_cs; u32 mode_bits; }; struct gxp_spi { const struct gxp_spi_data *data; void __iomem *reg_base; void __iomem *dat_base; void __iomem *dir_base; struct device *dev; struct gxp_spi_chip chips[GXP_SPI0_MAX_CHIPSELECT]; }; static void gxp_spi_set_mode(struct gxp_spi *spifi, int mode) { u8 value; void __iomem *reg_base = spifi->reg_base; value = readb(reg_base + OFFSET_SPIMCTRL); if (mode == MANUAL_MODE) { writeb(0x55, reg_base + OFFSET_SPICMD); writeb(0xaa, reg_base + OFFSET_SPICMD); value &= ~0x30; } else { value |= 0x30; } writeb(value, reg_base + OFFSET_SPIMCTRL); } static int gxp_spi_read_reg(struct gxp_spi_chip *chip, const struct spi_mem_op *op) { int ret; struct gxp_spi *spifi = chip->spifi; void __iomem *reg_base = spifi->reg_base; u32 value; value = readl(reg_base + OFFSET_SPIMCFG); value &= ~(1 << 24); value |= (chip->cs << 24); value &= ~(0x07 << 16); value &= ~(0x1f << 19); writel(value, reg_base + OFFSET_SPIMCFG); writel(0, reg_base + OFFSET_SPIADDR); writeb(op->cmd.opcode, reg_base + OFFSET_SPICMD); writew(op->data.nbytes, reg_base + OFFSET_SPIDCNT); value = readb(reg_base + OFFSET_SPIMCTRL); value &= ~SPIMCTRL_DIR; value |= SPIMCTRL_START; writeb(value, reg_base + OFFSET_SPIMCTRL); ret = readb_poll_timeout(reg_base + OFFSET_SPIMCTRL, value, !(value & SPIMCTRL_BUSY), GXP_SPI_SLEEP_TIME, GXP_SPI_TIMEOUT); if (ret) { dev_warn(spifi->dev, "read reg busy time out\n"); return ret; } memcpy_fromio(op->data.buf.in, spifi->dat_base, op->data.nbytes); return ret; } static int gxp_spi_write_reg(struct gxp_spi_chip *chip, const struct spi_mem_op *op) { int ret; struct gxp_spi *spifi = chip->spifi; void __iomem *reg_base = spifi->reg_base; u32 value; value = readl(reg_base + OFFSET_SPIMCFG); value &= ~(1 << 24); value |= (chip->cs << 24); value &= ~(0x07 << 16); value &= ~(0x1f << 19); writel(value, reg_base + OFFSET_SPIMCFG); writel(0, reg_base + OFFSET_SPIADDR); writeb(op->cmd.opcode, reg_base + OFFSET_SPICMD); memcpy_toio(spifi->dat_base, op->data.buf.in, op->data.nbytes); writew(op->data.nbytes, reg_base + OFFSET_SPIDCNT); value = readb(reg_base + OFFSET_SPIMCTRL); value |= SPIMCTRL_DIR; value |= SPIMCTRL_START; writeb(value, reg_base + OFFSET_SPIMCTRL); ret = readb_poll_timeout(reg_base + OFFSET_SPIMCTRL, value, !(value & SPIMCTRL_BUSY), GXP_SPI_SLEEP_TIME, GXP_SPI_TIMEOUT); if (ret) dev_warn(spifi->dev, "write reg busy time out\n"); return ret; } static ssize_t gxp_spi_read(struct gxp_spi_chip *chip, const struct spi_mem_op *op) { struct gxp_spi *spifi = chip->spifi; u32 offset = op->addr.val; if (chip->cs == 0) offset += 0x4000000; memcpy_fromio(op->data.buf.in, spifi->dir_base + offset, op->data.nbytes); return 0; } static ssize_t gxp_spi_write(struct gxp_spi_chip *chip, const struct spi_mem_op *op) { struct gxp_spi *spifi = chip->spifi; void __iomem *reg_base = spifi->reg_base; u32 write_len; u32 value; int ret; write_len = op->data.nbytes; if (write_len > SPILDAT_LEN) write_len = SPILDAT_LEN; value = readl(reg_base + OFFSET_SPIMCFG); value &= ~(1 << 24); value |= (chip->cs << 24); value &= ~(0x07 << 16); value |= (op->addr.nbytes << 16); value &= ~(0x1f << 19); writel(value, reg_base + OFFSET_SPIMCFG); writel(op->addr.val, reg_base + OFFSET_SPIADDR); writeb(op->cmd.opcode, reg_base + OFFSET_SPICMD); writew(write_len, reg_base + OFFSET_SPIDCNT); memcpy_toio(spifi->dat_base, op->data.buf.in, write_len); value = readb(reg_base + OFFSET_SPIMCTRL); value |= SPIMCTRL_DIR; value |= SPIMCTRL_START; writeb(value, reg_base + OFFSET_SPIMCTRL); ret = readb_poll_timeout(reg_base + OFFSET_SPIMCTRL, value, !(value & SPIMCTRL_BUSY), GXP_SPI_SLEEP_TIME, GXP_SPI_TIMEOUT); if (ret) { dev_warn(spifi->dev, "write busy time out\n"); return ret; } return write_len; } static int do_gxp_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) { struct gxp_spi *spifi = spi_controller_get_devdata(mem->spi->master); struct gxp_spi_chip *chip = &spifi->chips[mem->spi->chip_select]; int ret; if (op->data.dir == SPI_MEM_DATA_IN) { if (!op->addr.nbytes) ret = gxp_spi_read_reg(chip, op); else ret = gxp_spi_read(chip, op); } else { if (!op->addr.nbytes) ret = gxp_spi_write_reg(chip, op); else ret = gxp_spi_write(chip, op); } return ret; } static int gxp_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) { int ret; ret = do_gxp_exec_mem_op(mem, op); if (ret) dev_err(&mem->spi->dev, "operation failed: %d", ret); return ret; } static const struct spi_controller_mem_ops gxp_spi_mem_ops = { .exec_op = gxp_exec_mem_op, }; static int gxp_spi_setup(struct spi_device *spi) { struct gxp_spi *spifi = spi_controller_get_devdata(spi->master); unsigned int cs = spi->chip_select; struct gxp_spi_chip *chip = &spifi->chips[cs]; chip->spifi = spifi; chip->cs = cs; gxp_spi_set_mode(spifi, MANUAL_MODE); return 0; } static int gxp_spifi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; const struct gxp_spi_data *data; struct spi_controller *ctlr; struct gxp_spi *spifi; struct resource *res; int ret; data = of_device_get_match_data(&pdev->dev); ctlr = devm_spi_alloc_master(dev, sizeof(*spifi)); if (!ctlr) return -ENOMEM; spifi = spi_controller_get_devdata(ctlr); platform_set_drvdata(pdev, spifi); spifi->data = data; spifi->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); spifi->reg_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(spifi->reg_base)) return PTR_ERR(spifi->reg_base); res = platform_get_resource(pdev, IORESOURCE_MEM, 1); spifi->dat_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(spifi->dat_base)) return PTR_ERR(spifi->dat_base); res = platform_get_resource(pdev, IORESOURCE_MEM, 2); spifi->dir_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(spifi->dir_base)) return PTR_ERR(spifi->dir_base); ctlr->mode_bits = data->mode_bits; ctlr->bus_num = pdev->id; ctlr->mem_ops = &gxp_spi_mem_ops; ctlr->setup = gxp_spi_setup; ctlr->num_chipselect = data->max_cs; ctlr->dev.of_node = dev->of_node; ret = devm_spi_register_controller(dev, ctlr); if (ret) { return dev_err_probe(&pdev->dev, ret, "failed to register spi controller\n"); } return 0; } static const struct gxp_spi_data gxp_spifi_data = { .max_cs = 2, .mode_bits = 0, }; static const struct of_device_id gxp_spifi_match[] = { {.compatible = "hpe,gxp-spifi", .data = &gxp_spifi_data }, { /* null */ } }; MODULE_DEVICE_TABLE(of, gxp_spifi_match); static struct platform_driver gxp_spifi_driver = { .probe = gxp_spifi_probe, .driver = { .name = "gxp-spifi", .of_match_table = gxp_spifi_match, }, }; module_platform_driver(gxp_spifi_driver); MODULE_DESCRIPTION("HPE GXP SPI Flash Interface driver"); MODULE_AUTHOR("Nick Hawkins <nick.hawkins@hpe.com>"); MODULE_LICENSE("GPL");
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
You can’t perform that action at this time.