Lines Matching +full:input +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support.
45 static inline int zmii_valid_mode(int mode) in zmii_valid_mode() argument
47 return mode == PHY_INTERFACE_MODE_MII || in zmii_valid_mode()
48 mode == PHY_INTERFACE_MODE_RMII || in zmii_valid_mode()
49 mode == PHY_INTERFACE_MODE_SMII || in zmii_valid_mode()
50 mode == PHY_INTERFACE_MODE_NA; in zmii_valid_mode()
53 static inline const char *zmii_mode_name(int mode) in zmii_mode_name() argument
55 switch (mode) { in zmii_mode_name()
67 static inline u32 zmii_mode_mask(int mode, int input) in zmii_mode_mask() argument
69 switch (mode) { in zmii_mode_mask()
71 return ZMII_FER_MII(input); in zmii_mode_mask()
73 return ZMII_FER_RMII(input); in zmii_mode_mask()
75 return ZMII_FER_SMII(input); in zmii_mode_mask()
81 int zmii_attach(struct platform_device *ofdev, int input, in zmii_attach() argument
82 phy_interface_t *mode) in zmii_attach() argument
85 struct zmii_regs __iomem *p = dev->base; in zmii_attach()
87 ZMII_DBG(dev, "init(%d, %d)" NL, input, *mode); in zmii_attach()
89 if (!zmii_valid_mode(*mode)) { in zmii_attach()
94 dev->users++; in zmii_attach()
98 mutex_lock(&dev->lock); in zmii_attach()
100 /* Autodetect ZMII mode if not specified. in zmii_attach()
102 * Please, always specify PHY mode in your board port to avoid in zmii_attach()
105 if (dev->mode == PHY_INTERFACE_MODE_NA) { in zmii_attach()
106 if (*mode == PHY_INTERFACE_MODE_NA) { in zmii_attach()
107 u32 r = dev->fer_save; in zmii_attach()
109 ZMII_DBG(dev, "autodetecting mode, FER = 0x%08x" NL, r); in zmii_attach()
112 dev->mode = PHY_INTERFACE_MODE_MII; in zmii_attach()
114 dev->mode = PHY_INTERFACE_MODE_RMII; in zmii_attach()
116 dev->mode = PHY_INTERFACE_MODE_SMII; in zmii_attach()
118 dev->mode = *mode; in zmii_attach()
120 printk(KERN_NOTICE "%pOF: bridge in %s mode\n", in zmii_attach()
121 ofdev->dev.of_node, in zmii_attach()
122 zmii_mode_name(dev->mode)); in zmii_attach()
124 /* All inputs must use the same mode */ in zmii_attach()
125 if (*mode != PHY_INTERFACE_MODE_NA && *mode != dev->mode) { in zmii_attach()
127 "%pOF: invalid mode %d specified for input %d\n", in zmii_attach()
128 ofdev->dev.of_node, *mode, input); in zmii_attach()
129 mutex_unlock(&dev->lock); in zmii_attach()
130 return -EINVAL; in zmii_attach()
134 /* Report back correct PHY mode, in zmii_attach()
137 *mode = dev->mode; in zmii_attach()
139 /* Enable this input */ in zmii_attach()
140 out_be32(&p->fer, in_be32(&p->fer) | zmii_mode_mask(dev->mode, input)); in zmii_attach()
141 ++dev->users; in zmii_attach()
143 mutex_unlock(&dev->lock); in zmii_attach()
148 void zmii_get_mdio(struct platform_device *ofdev, int input) in zmii_get_mdio() argument
153 ZMII_DBG2(dev, "get_mdio(%d)" NL, input); in zmii_get_mdio()
155 mutex_lock(&dev->lock); in zmii_get_mdio()
157 fer = in_be32(&dev->base->fer) & ~ZMII_FER_MDI_ALL; in zmii_get_mdio()
158 out_be32(&dev->base->fer, fer | ZMII_FER_MDI(input)); in zmii_get_mdio()
161 void zmii_put_mdio(struct platform_device *ofdev, int input) in zmii_put_mdio() argument
165 ZMII_DBG2(dev, "put_mdio(%d)" NL, input); in zmii_put_mdio()
166 mutex_unlock(&dev->lock); in zmii_put_mdio()
170 void zmii_set_speed(struct platform_device *ofdev, int input, int speed) in zmii_set_speed() argument
175 mutex_lock(&dev->lock); in zmii_set_speed()
177 ssr = in_be32(&dev->base->ssr); in zmii_set_speed()
179 ZMII_DBG(dev, "speed(%d, %d)" NL, input, speed); in zmii_set_speed()
182 ssr |= ZMII_SSR_SP(input); in zmii_set_speed()
184 ssr &= ~ZMII_SSR_SP(input); in zmii_set_speed()
186 out_be32(&dev->base->ssr, ssr); in zmii_set_speed()
188 mutex_unlock(&dev->lock); in zmii_set_speed()
191 void zmii_detach(struct platform_device *ofdev, int input) in zmii_detach() argument
195 BUG_ON(!dev || dev->users == 0); in zmii_detach()
197 mutex_lock(&dev->lock); in zmii_detach()
199 ZMII_DBG(dev, "detach(%d)" NL, input); in zmii_detach()
201 /* Disable this input */ in zmii_detach()
202 out_be32(&dev->base->fer, in zmii_detach()
203 in_be32(&dev->base->fer) & ~zmii_mode_mask(dev->mode, input)); in zmii_detach()
205 --dev->users; in zmii_detach()
207 mutex_unlock(&dev->lock); in zmii_detach()
222 hdr->version = 0; in zmii_dump_regs()
223 hdr->index = 0; /* for now, are there chips with more than one in zmii_dump_regs()
227 memcpy_fromio(regs, dev->base, sizeof(struct zmii_regs)); in zmii_dump_regs()
233 struct device_node *np = ofdev->dev.of_node; in zmii_probe()
238 rc = -ENOMEM; in zmii_probe()
243 mutex_init(&dev->lock); in zmii_probe()
244 dev->ofdev = ofdev; in zmii_probe()
245 dev->mode = PHY_INTERFACE_MODE_NA; in zmii_probe()
247 rc = -ENXIO; in zmii_probe()
253 rc = -ENOMEM; in zmii_probe()
254 dev->base = (struct zmii_regs __iomem *)ioremap(regs.start, in zmii_probe()
256 if (dev->base == NULL) { in zmii_probe()
262 dev->fer_save = in_be32(&dev->base->fer); in zmii_probe()
265 out_be32(&dev->base->fer, 0); in zmii_probe()
267 printk(KERN_INFO "ZMII %pOF initialized\n", ofdev->dev.of_node); in zmii_probe()
283 WARN_ON(dev->users != 0); in zmii_remove()
285 iounmap(dev->base); in zmii_remove()
298 .type = "emac-zmii",
305 .name = "emac-zmii",