14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/types.h>
17 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/device.h>
25 #define DRV_VERSION "0.1.1"
26 #define DRV_DESC "Micrel KS8995 Ethernet switch SPI driver"
30 #define KS8995_REG_ID0 0x00
31 #define KS8995_REG_ID1 0x01
33 #define KS8995_REG_GC0 0x02
34 #define KS8995_REG_GC1 0x03
35 #define KS8995_REG_GC2 0x04
36 #define KS8995_REG_GC3 0x05
37 #define KS8995_REG_GC4 0x06
38 #define KS8995_REG_GC5 0x07
39 #define KS8995_REG_GC6 0x08
40 #define KS8995_REG_GC7 0x09
41 #define KS8995_REG_GC8 0x0a
42 #define KS8995_REG_GC9 0x0b
44 #define KS8995_REG_PC(p, r) ((0x10 * p) + r)
45 #define KS8995_REG_PS(p, r) ((0x10 * p) + r + 0xe)
47 #define KS8995_REG_TPC0 0x60
48 #define KS8995_REG_TPC1 0x61
49 #define KS8995_REG_TPC2 0x62
50 #define KS8995_REG_TPC3 0x63
51 #define KS8995_REG_TPC4 0x64
52 #define KS8995_REG_TPC5 0x65
53 #define KS8995_REG_TPC6 0x66
54 #define KS8995_REG_TPC7 0x67
56 #define KS8995_REG_MAC0 0x68
57 #define KS8995_REG_MAC1 0x69
58 #define KS8995_REG_MAC2 0x6a
59 #define KS8995_REG_MAC3 0x6b
60 #define KS8995_REG_MAC4 0x6c
61 #define KS8995_REG_MAC5 0x6d
63 #define KS8995_REG_IAC0 0x6e
64 #define KS8995_REG_IAC1 0x6f
65 #define KS8995_REG_IAD7 0x70
66 #define KS8995_REG_IAD6 0x71
67 #define KS8995_REG_IAD5 0x72
68 #define KS8995_REG_IAD4 0x73
69 #define KS8995_REG_IAD3 0x74
70 #define KS8995_REG_IAD2 0x75
71 #define KS8995_REG_IAD1 0x76
72 #define KS8995_REG_IAD0 0x77
74 #define KS8995_REGS_SIZE 0x80
76 #define ID1_CHIPID_M 0xf
77 #define ID1_CHIPID_S 4
78 #define ID1_REVISION_M 0x7
79 #define ID1_REVISION_S 1
80 #define ID1_START_SW 1
82 #define FAMILY_KS8995 0x95
85 #define KS8995_CMD_WRITE 0x02U
86 #define KS8995_CMD_READ 0x03U
88 #define KS8995_RESET_DELAY 10
100 static inline u8 get_chip_id(
u8 val)
105 static inline u8 get_chip_rev(
u8 val)
119 spi_message_init(&
m);
124 t[0].len =
sizeof(
cmd);
125 spi_message_add_tail(&
t[0], &
m);
129 spi_message_add_tail(&
t[1], &
m);
138 return err ? err :
count;
143 unsigned offset,
size_t count)
150 spi_message_init(&
m);
155 t[0].len =
sizeof(
cmd);
156 spi_message_add_tail(&
t[0], &
m);
160 spi_message_add_tail(&
t[1], &
m);
169 return err ? err :
count;
174 return (ks8995_read(ks, buf, addr, 1) != 1);
181 return (ks8995_write(ks, &buf, addr, 1) != 1);
200 err = ks8995_stop(ks);
206 return ks8995_start(ks);
212 struct bin_attribute *bin_attr,
char *buf, loff_t off,
size_t count)
229 return ks8995_read(ks8995, buf, off, count);
234 struct bin_attribute *bin_attr,
char *buf, loff_t off,
size_t count)
251 return ks8995_write(ks8995, buf, off, count);
261 .read = ks8995_registers_read,
262 .write = ks8995_registers_write,
275 pdata = spi->
dev.platform_data;
279 dev_err(&spi->
dev,
"no memory for private data\n");
285 ks->
spi = spi_dev_get(spi);
292 dev_err(&spi->
dev,
"spi_setup failed, err=%d\n", err);
298 dev_err(&spi->
dev,
"unable to read id registers, err=%d\n",
307 dev_err(&spi->
dev,
"unknown family id:%02x\n", ids[0]);
312 err = ks8995_reset(ks);
318 dev_err(&spi->
dev,
"unable to create sysfs file, err=%d\n",
323 dev_info(&spi->
dev,
"KS89%02X device found, Chip ID:%01x, "
324 "Revision:%01x\n", ids[0],
325 get_chip_id(ids[1]), get_chip_rev(ids[1]));
337 struct ks8995_data *ks8995;
352 .name =
"spi-ks8995",
355 .probe = ks8995_probe,
359 static int __init ks8995_init(
void)
367 static void __exit ks8995_exit(
void)
369 spi_unregister_driver(&ks8995_driver);