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
c9cd961
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
appletalk
arcnet
bonding
caif
can
dsa
b53
hirschmann
microchip
Kconfig
Makefile
ksz8.h
ksz8795.c
ksz8795_reg.h
ksz8863_smi.c
ksz9477.c
ksz9477.h
ksz9477_i2c.c
ksz9477_reg.h
ksz_common.c
ksz_common.h
ksz_spi.c
lan937x.h
lan937x_main.c
lan937x_reg.h
mv88e6xxx
ocelot
qca
realtek
sja1105
xrs700x
Kconfig
Makefile
bcm_sf2.c
bcm_sf2.h
bcm_sf2_cfp.c
bcm_sf2_regs.h
dsa_loop.c
dsa_loop.h
dsa_loop_bdinfo.c
lan9303-core.c
lan9303.h
lan9303_i2c.c
lan9303_mdio.c
lantiq_gswip.c
lantiq_pce.h
mt7530.c
mt7530.h
mv88e6060.c
mv88e6060.h
rzn1_a5psw.c
rzn1_a5psw.h
vitesse-vsc73xx-core.c
vitesse-vsc73xx-platform.c
vitesse-vsc73xx-spi.c
vitesse-vsc73xx.h
ethernet
fddi
fjes
hamradio
hippi
hyperv
ieee802154
ipa
ipvlan
mctp
mdio
netdevsim
pcs
phy
plip
ppp
slip
team
usb
vmxnet3
vxlan
wan
wireguard
wireless
wwan
xen-netback
Kconfig
LICENSE.SRC
Makefile
Space.c
amt.c
bareudp.c
dummy.c
eql.c
geneve.c
gtp.c
ifb.c
loopback.c
macsec.c
macvlan.c
macvtap.c
mdio.c
mhi_net.c
mii.c
net_failover.c
netconsole.c
nlmon.c
ntb_netdev.c
rionet.c
sb1000.c
sungem_phy.c
tap.c
thunderbolt.c
tun.c
veth.c
virtio_net.c
vrf.c
vsockmon.c
xen-netfront.c
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
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
ufs
uio
usb
vdpa
vfio
vhost
video
virt
virtio
vlynq
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
io_uring
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
/
net
/
dsa
/
microchip
/
ksz_spi.c
Blame
Blame
Latest commit
History
History
242 lines (207 loc) · 5.16 KB
Breadcrumbs
linux
/
drivers
/
net
/
dsa
/
microchip
/
ksz_spi.c
Top
File metadata and controls
Code
Blame
242 lines (207 loc) · 5.16 KB
Raw
// SPDX-License-Identifier: GPL-2.0-or-later /* * Microchip ksz series register access through SPI * * Copyright (C) 2017 Microchip Technology Inc. * Tristram Ha <Tristram.Ha@microchip.com> */ #include <asm/unaligned.h> #include <linux/delay.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/regmap.h> #include <linux/spi/spi.h> #include "ksz_common.h" #define KSZ8795_SPI_ADDR_SHIFT 12 #define KSZ8795_SPI_ADDR_ALIGN 3 #define KSZ8795_SPI_TURNAROUND_SHIFT 1 #define KSZ8863_SPI_ADDR_SHIFT 8 #define KSZ8863_SPI_ADDR_ALIGN 8 #define KSZ8863_SPI_TURNAROUND_SHIFT 0 #define KSZ9477_SPI_ADDR_SHIFT 24 #define KSZ9477_SPI_ADDR_ALIGN 3 #define KSZ9477_SPI_TURNAROUND_SHIFT 5 KSZ_REGMAP_TABLE(ksz8795, 16, KSZ8795_SPI_ADDR_SHIFT, KSZ8795_SPI_TURNAROUND_SHIFT, KSZ8795_SPI_ADDR_ALIGN); KSZ_REGMAP_TABLE(ksz8863, 16, KSZ8863_SPI_ADDR_SHIFT, KSZ8863_SPI_TURNAROUND_SHIFT, KSZ8863_SPI_ADDR_ALIGN); KSZ_REGMAP_TABLE(ksz9477, 32, KSZ9477_SPI_ADDR_SHIFT, KSZ9477_SPI_TURNAROUND_SHIFT, KSZ9477_SPI_ADDR_ALIGN); static int ksz_spi_probe(struct spi_device *spi) { const struct regmap_config *regmap_config; const struct ksz_chip_data *chip; struct device *ddev = &spi->dev; struct regmap_config rc; struct ksz_device *dev; int i, ret = 0; dev = ksz_switch_alloc(&spi->dev, spi); if (!dev) return -ENOMEM; chip = device_get_match_data(ddev); if (!chip) return -EINVAL; if (chip->chip_id == KSZ8830_CHIP_ID) regmap_config = ksz8863_regmap_config; else if (chip->chip_id == KSZ8795_CHIP_ID || chip->chip_id == KSZ8794_CHIP_ID || chip->chip_id == KSZ8765_CHIP_ID) regmap_config = ksz8795_regmap_config; else regmap_config = ksz9477_regmap_config; for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) { rc = regmap_config[i]; rc.lock_arg = &dev->regmap_mutex; rc.wr_table = chip->wr_table; rc.rd_table = chip->rd_table; dev->regmap[i] = devm_regmap_init_spi(spi, &rc); if (IS_ERR(dev->regmap[i])) { ret = PTR_ERR(dev->regmap[i]); dev_err(&spi->dev, "Failed to initialize regmap%i: %d\n", regmap_config[i].val_bits, ret); return ret; } } if (spi->dev.platform_data) dev->pdata = spi->dev.platform_data; /* setup spi */ spi->mode = SPI_MODE_3; ret = spi_setup(spi); if (ret) return ret; dev->irq = spi->irq; ret = ksz_switch_register(dev); /* Main DSA driver may not be started yet. */ if (ret) return ret; spi_set_drvdata(spi, dev); return 0; } static void ksz_spi_remove(struct spi_device *spi) { struct ksz_device *dev = spi_get_drvdata(spi); if (dev) ksz_switch_remove(dev); spi_set_drvdata(spi, NULL); } static void ksz_spi_shutdown(struct spi_device *spi) { struct ksz_device *dev = spi_get_drvdata(spi); if (!dev) return; if (dev->dev_ops->reset) dev->dev_ops->reset(dev); dsa_switch_shutdown(dev->ds); spi_set_drvdata(spi, NULL); } static const struct of_device_id ksz_dt_ids[] = { { .compatible = "microchip,ksz8765", .data = &ksz_switch_chips[KSZ8765] }, { .compatible = "microchip,ksz8794", .data = &ksz_switch_chips[KSZ8794] }, { .compatible = "microchip,ksz8795", .data = &ksz_switch_chips[KSZ8795] }, { .compatible = "microchip,ksz8863", .data = &ksz_switch_chips[KSZ8830] }, { .compatible = "microchip,ksz8873", .data = &ksz_switch_chips[KSZ8830] }, { .compatible = "microchip,ksz9477", .data = &ksz_switch_chips[KSZ9477] }, { .compatible = "microchip,ksz9897", .data = &ksz_switch_chips[KSZ9897] }, { .compatible = "microchip,ksz9893", .data = &ksz_switch_chips[KSZ9893] }, { .compatible = "microchip,ksz9563", .data = &ksz_switch_chips[KSZ9893] }, { .compatible = "microchip,ksz8563", .data = &ksz_switch_chips[KSZ8563] }, { .compatible = "microchip,ksz9567", .data = &ksz_switch_chips[KSZ9567] }, { .compatible = "microchip,lan9370", .data = &ksz_switch_chips[LAN9370] }, { .compatible = "microchip,lan9371", .data = &ksz_switch_chips[LAN9371] }, { .compatible = "microchip,lan9372", .data = &ksz_switch_chips[LAN9372] }, { .compatible = "microchip,lan9373", .data = &ksz_switch_chips[LAN9373] }, { .compatible = "microchip,lan9374", .data = &ksz_switch_chips[LAN9374] }, {}, }; MODULE_DEVICE_TABLE(of, ksz_dt_ids); static const struct spi_device_id ksz_spi_ids[] = { { "ksz8765" }, { "ksz8794" }, { "ksz8795" }, { "ksz8863" }, { "ksz8873" }, { "ksz9477" }, { "ksz9897" }, { "ksz9893" }, { "ksz9563" }, { "ksz8563" }, { "ksz9567" }, { "lan9370" }, { "lan9371" }, { "lan9372" }, { "lan9373" }, { "lan9374" }, { }, }; MODULE_DEVICE_TABLE(spi, ksz_spi_ids); static struct spi_driver ksz_spi_driver = { .driver = { .name = "ksz-switch", .owner = THIS_MODULE, .of_match_table = ksz_dt_ids, }, .id_table = ksz_spi_ids, .probe = ksz_spi_probe, .remove = ksz_spi_remove, .shutdown = ksz_spi_shutdown, }; module_spi_driver(ksz_spi_driver); MODULE_ALIAS("spi:ksz9477"); MODULE_ALIAS("spi:ksz9897"); MODULE_ALIAS("spi:ksz9893"); MODULE_ALIAS("spi:ksz9563"); MODULE_ALIAS("spi:ksz8563"); MODULE_ALIAS("spi:ksz9567"); MODULE_ALIAS("spi:lan937x"); MODULE_AUTHOR("Tristram Ha <Tristram.Ha@microchip.com>"); MODULE_DESCRIPTION("Microchip ksz Series Switch SPI Driver"); 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
You can’t perform that action at this time.