OpenWrt – Diff between revs 2 and 3
?pathlinks?
Rev 2 | Rev 3 | |||
---|---|---|---|---|
Line 197... | Line 197... | |||
197 | rtl8366_smi_write_bits(smi, 0x01, 1); |
197 | rtl8366_smi_write_bits(smi, 0x01, 1); |
|
Line 198... | Line 198... | |||
198 | |
198 | |
|
199 | return 0; |
199 | return 0; |
|
Line 200... | Line 200... | |||
200 | } |
200 | } |
|
201 | |
201 | |
|
202 | static int __rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data) |
202 | int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data) |
|
203 | { |
203 | { |
|
204 | unsigned long flags; |
204 | unsigned long flags; |
|
205 | u8 lo = 0; |
205 | u8 lo = 0; |
|
Line 238... | Line 238... | |||
238 | rtl8366_smi_stop(smi); |
238 | rtl8366_smi_stop(smi); |
|
239 | spin_unlock_irqrestore(&smi->lock, flags); |
239 | spin_unlock_irqrestore(&smi->lock, flags); |
|
Line 240... | Line 240... | |||
240 | |
240 | |
|
241 | return ret; |
241 | return ret; |
|
242 | } |
- | ||
243 | /* Read/write via mdiobus */ |
- | ||
244 | #define MDC_MDIO_CTRL0_REG 31 |
- | ||
245 | #define MDC_MDIO_START_REG 29 |
- | ||
246 | #define MDC_MDIO_CTRL1_REG 21 |
- | ||
247 | #define MDC_MDIO_ADDRESS_REG 23 |
- | ||
248 | #define MDC_MDIO_DATA_WRITE_REG 24 |
- | ||
249 | #define MDC_MDIO_DATA_READ_REG 25 |
- | ||
250 | |
- | ||
251 | #define MDC_MDIO_START_OP 0xFFFF |
- | ||
252 | #define MDC_MDIO_ADDR_OP 0x000E |
- | ||
253 | #define MDC_MDIO_READ_OP 0x0001 |
- | ||
254 | #define MDC_MDIO_WRITE_OP 0x0003 |
- | ||
255 | #define MDC_REALTEK_PHY_ADDR 0x0 |
- | ||
256 | |
- | ||
257 | int __rtl8366_mdio_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data) |
- | ||
258 | { |
- | ||
259 | u32 phy_id = MDC_REALTEK_PHY_ADDR; |
- | ||
260 | struct mii_bus *mbus = smi->ext_mbus; |
- | ||
261 | |
- | ||
262 | BUG_ON(in_interrupt()); |
- | ||
263 | |
- | ||
264 | mutex_lock(&mbus->mdio_lock); |
- | ||
265 | /* Write Start command to register 29 */ |
- | ||
266 | mbus->write(mbus, phy_id, MDC_MDIO_START_REG, MDC_MDIO_START_OP); |
- | ||
267 | |
- | ||
268 | /* Write address control code to register 31 */ |
- | ||
269 | mbus->write(mbus, phy_id, MDC_MDIO_CTRL0_REG, MDC_MDIO_ADDR_OP); |
- | ||
270 | |
- | ||
271 | /* Write Start command to register 29 */ |
- | ||
272 | mbus->write(mbus, phy_id, MDC_MDIO_START_REG, MDC_MDIO_START_OP); |
- | ||
273 | |
- | ||
274 | /* Write address to register 23 */ |
- | ||
275 | mbus->write(mbus, phy_id, MDC_MDIO_ADDRESS_REG, addr); |
- | ||
276 | |
- | ||
277 | /* Write Start command to register 29 */ |
- | ||
278 | mbus->write(mbus, phy_id, MDC_MDIO_START_REG, MDC_MDIO_START_OP); |
- | ||
279 | |
- | ||
280 | /* Write read control code to register 21 */ |
- | ||
281 | mbus->write(mbus, phy_id, MDC_MDIO_CTRL1_REG, MDC_MDIO_READ_OP); |
- | ||
282 | |
- | ||
283 | /* Write Start command to register 29 */ |
- | ||
284 | mbus->write(smi->ext_mbus, phy_id, MDC_MDIO_START_REG, MDC_MDIO_START_OP); |
- | ||
285 | |
- | ||
286 | /* Read data from register 25 */ |
- | ||
287 | *data = mbus->read(mbus, phy_id, MDC_MDIO_DATA_READ_REG); |
- | ||
288 | |
- | ||
289 | mutex_unlock(&mbus->mdio_lock); |
- | ||
290 | |
- | ||
291 | return 0; |
- | ||
292 | } |
- | ||
293 | |
- | ||
294 | static int __rtl8366_mdio_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data) |
- | ||
295 | { |
- | ||
296 | u32 phy_id = MDC_REALTEK_PHY_ADDR; |
- | ||
297 | struct mii_bus *mbus = smi->ext_mbus; |
- | ||
298 | |
- | ||
299 | BUG_ON(in_interrupt()); |
- | ||
300 | |
- | ||
301 | mutex_lock(&mbus->mdio_lock); |
- | ||
302 | |
- | ||
303 | /* Write Start command to register 29 */ |
- | ||
304 | mbus->write(mbus, phy_id, MDC_MDIO_START_REG, MDC_MDIO_START_OP); |
- | ||
305 | |
- | ||
306 | /* Write address control code to register 31 */ |
- | ||
307 | mbus->write(mbus, phy_id, MDC_MDIO_CTRL0_REG, MDC_MDIO_ADDR_OP); |
- | ||
308 | |
- | ||
309 | /* Write Start command to register 29 */ |
- | ||
310 | mbus->write(mbus, phy_id, MDC_MDIO_START_REG, MDC_MDIO_START_OP); |
- | ||
311 | |
- | ||
312 | /* Write address to register 23 */ |
- | ||
313 | mbus->write(mbus, phy_id, MDC_MDIO_ADDRESS_REG, addr); |
- | ||
314 | |
- | ||
315 | /* Write Start command to register 29 */ |
- | ||
316 | mbus->write(mbus, phy_id, MDC_MDIO_START_REG, MDC_MDIO_START_OP); |
- | ||
317 | |
- | ||
318 | /* Write data to register 24 */ |
- | ||
319 | mbus->write(mbus, phy_id, MDC_MDIO_DATA_WRITE_REG, data); |
- | ||
320 | |
- | ||
321 | /* Write Start command to register 29 */ |
- | ||
322 | mbus->write(mbus, phy_id, MDC_MDIO_START_REG, MDC_MDIO_START_OP); |
- | ||
323 | |
- | ||
324 | /* Write data control code to register 21 */ |
- | ||
325 | mbus->write(mbus, phy_id, MDC_MDIO_CTRL1_REG, MDC_MDIO_WRITE_OP); |
- | ||
326 | |
- | ||
327 | mutex_unlock(&mbus->mdio_lock); |
- | ||
328 | return 0; |
- | ||
329 | } |
- | ||
330 | |
- | ||
331 | int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data) |
- | ||
332 | { |
- | ||
333 | if (smi->ext_mbus) |
- | ||
334 | return __rtl8366_mdio_read_reg(smi, addr, data); |
- | ||
335 | else |
- | ||
336 | return __rtl8366_smi_read_reg(smi, addr, data); |
- | ||
337 | } |
242 | } |
|
Line 338... | Line 243... | |||
338 | EXPORT_SYMBOL_GPL(rtl8366_smi_read_reg); |
243 | EXPORT_SYMBOL_GPL(rtl8366_smi_read_reg); |
|
339 | |
244 | |
|
340 | static int __rtl8366_smi_write_reg(struct rtl8366_smi *smi, |
245 | static int __rtl8366_smi_write_reg(struct rtl8366_smi *smi, |
|
Line 384... | Line 289... | |||
384 | return ret; |
289 | return ret; |
|
385 | } |
290 | } |
|
Line 386... | Line 291... | |||
386 | |
291 | |
|
387 | int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data) |
292 | int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data) |
|
388 | { |
- | ||
389 | if (smi->ext_mbus) |
- | ||
390 | return __rtl8366_mdio_write_reg(smi, addr, data); |
- | ||
391 | else |
293 | { |
|
392 | return __rtl8366_smi_write_reg(smi, addr, data, true); |
294 | return __rtl8366_smi_write_reg(smi, addr, data, true); |
|
393 | } |
295 | } |
|
Line 394... | Line 296... | |||
394 | EXPORT_SYMBOL_GPL(rtl8366_smi_write_reg); |
296 | EXPORT_SYMBOL_GPL(rtl8366_smi_write_reg); |
|
395 | |
297 | |
|
Line 415... | Line 317... | |||
415 | EXPORT_SYMBOL_GPL(rtl8366_smi_rmwr); |
317 | EXPORT_SYMBOL_GPL(rtl8366_smi_rmwr); |
|
Line 416... | Line 318... | |||
416 | |
318 | |
|
417 | static int rtl8366_reset(struct rtl8366_smi *smi) |
319 | static int rtl8366_reset(struct rtl8366_smi *smi) |
|
418 | { |
320 | { |
|
419 | if (smi->hw_reset) { |
321 | if (smi->hw_reset) { |
|
420 | smi->hw_reset(smi, true); |
322 | smi->hw_reset(true); |
|
421 | msleep(RTL8366_SMI_HW_STOP_DELAY); |
323 | msleep(RTL8366_SMI_HW_STOP_DELAY); |
|
422 | smi->hw_reset(smi, false); |
324 | smi->hw_reset(false); |
|
423 | msleep(RTL8366_SMI_HW_START_DELAY); |
325 | msleep(RTL8366_SMI_HW_START_DELAY); |
|
424 | return 0; |
326 | return 0; |
|
Line 425... | Line 327... | |||
425 | } |
327 | } |
|
Line 1378... | Line 1280... | |||
1378 | |
1280 | |
|
1379 | static int __rtl8366_smi_init(struct rtl8366_smi *smi, const char *name) |
1281 | static int __rtl8366_smi_init(struct rtl8366_smi *smi, const char *name) |
|
1380 | { |
1282 | { |
|
Line 1381... | Line -... | |||
1381 | int err; |
- | ||
1382 | |
1283 | int err; |
|
1383 | if (!smi->ext_mbus) { |
1284 | |
|
1384 | err = gpio_request(smi->gpio_sda, name); |
1285 | err = gpio_request(smi->gpio_sda, name); |
|
1385 | if (err) { |
1286 | if (err) { |
|
1386 | printk(KERN_ERR "rtl8366_smi: gpio_request failed for %u, err=%d\n", |
1287 | printk(KERN_ERR "rtl8366_smi: gpio_request failed for %u, err=%d\n", |
|
1387 | smi->gpio_sda, err); |
1288 | smi->gpio_sda, err); |
|
Line 1388... | Line 1289... | |||
1388 | goto err_out; |
1289 | goto err_out; |
|
1389 | } |
1290 | } |
|
1390 | |
1291 | |
|
1391 | err = gpio_request(smi->gpio_sck, name); |
1292 | err = gpio_request(smi->gpio_sck, name); |
|
1392 | if (err) { |
1293 | if (err) { |
|
1393 | printk(KERN_ERR "rtl8366_smi: gpio_request failed for %u, err=%d\n", |
- | ||
1394 | smi->gpio_sck, err); |
1294 | printk(KERN_ERR "rtl8366_smi: gpio_request failed for %u, err=%d\n", |
|
Line 1395... | Line 1295... | |||
1395 | goto err_free_sda; |
1295 | smi->gpio_sck, err); |
|
Line 1396... | Line 1296... | |||
1396 | } |
1296 | goto err_free_sda; |
|
1397 | } |
1297 | } |
|
1398 | |
1298 | |
|
1399 | spin_lock_init(&smi->lock); |
1299 | spin_lock_init(&smi->lock); |
|
1400 | |
1300 | |
|
Line 1401... | Line 1301... | |||
1401 | /* start the switch */ |
1301 | /* start the switch */ |
|
Line 1413... | Line 1313... | |||
1413 | } |
1313 | } |
|
Line 1414... | Line 1314... | |||
1414 | |
1314 | |
|
1415 | static void __rtl8366_smi_cleanup(struct rtl8366_smi *smi) |
1315 | static void __rtl8366_smi_cleanup(struct rtl8366_smi *smi) |
|
1416 | { |
1316 | { |
|
1417 | if (smi->hw_reset) |
1317 | if (smi->hw_reset) |
|
Line 1418... | Line -... | |||
1418 | smi->hw_reset(smi, true); |
- | ||
1419 | |
1318 | smi->hw_reset(true); |
|
1420 | if (!smi->ext_mbus) { |
1319 | |
|
1421 | gpio_free(smi->gpio_sck); |
- | ||
1422 | gpio_free(smi->gpio_sda); |
1320 | gpio_free(smi->gpio_sck); |
|
Line 1423... | Line 1321... | |||
1423 | } |
1321 | gpio_free(smi->gpio_sda); |
|
1424 | } |
1322 | } |
|
1425 | |
1323 | |
|
Line 1471... | Line 1369... | |||
1471 | |
1369 | |
|
1472 | err = __rtl8366_smi_init(smi, dev_name(smi->parent)); |
1370 | err = __rtl8366_smi_init(smi, dev_name(smi->parent)); |
|
1473 | if (err) |
1371 | if (err) |
|
Line 1474... | Line -... | |||
1474 | goto err_out; |
- | ||
1475 | |
1372 | goto err_out; |
|
1476 | if (!smi->ext_mbus) |
1373 | |
|
1477 | dev_info(smi->parent, "using GPIO pins %u (SDA) and %u (SCK)\n", |
- | ||
1478 | smi->gpio_sda, smi->gpio_sck); |
- | ||
Line 1479... | Line 1374... | |||
1479 | else |
1374 | dev_info(smi->parent, "using GPIO pins %u (SDA) and %u (SCK)\n", |
|
1480 | dev_info(smi->parent, "using MDIO bus '%s'\n", smi->ext_mbus->name); |
1375 | smi->gpio_sda, smi->gpio_sck); |
|
1481 | |
1376 | |
|
1482 | err = smi->ops->detect(smi); |
1377 | err = smi->ops->detect(smi); |
|
Line 1528... | Line 1423... | |||
1528 | __rtl8366_smi_cleanup(smi); |
1423 | __rtl8366_smi_cleanup(smi); |
|
1529 | } |
1424 | } |
|
1530 | EXPORT_SYMBOL_GPL(rtl8366_smi_cleanup); |
1425 | EXPORT_SYMBOL_GPL(rtl8366_smi_cleanup); |
|
Line 1531... | Line 1426... | |||
1531 | |
1426 | |
|
1532 | #ifdef CONFIG_OF |
- | ||
1533 | static void rtl8366_smi_reset(struct rtl8366_smi *smi, bool active) |
- | ||
1534 | { |
- | ||
1535 | if (active) |
- | ||
1536 | reset_control_assert(smi->reset); |
- | ||
1537 | else |
- | ||
1538 | reset_control_deassert(smi->reset); |
- | ||
1539 | } |
- | ||
1540 | |
1427 | #ifdef CONFIG_OF |
|
1541 | int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi) |
1428 | int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi) |
|
1542 | { |
1429 | { |
|
1543 | int sck = of_get_named_gpio(pdev->dev.of_node, "gpio-sck", 0); |
1430 | int sck = of_get_named_gpio(pdev->dev.of_node, "gpio-sck", 0); |
|
1544 | int sda = of_get_named_gpio(pdev->dev.of_node, "gpio-sda", 0); |
- | ||
1545 | struct device_node *np = pdev->dev.of_node; |
- | ||
Line 1546... | Line -... | |||
1546 | struct device_node *mdio_node; |
- | ||
1547 | |
- | ||
1548 | mdio_node = of_parse_phandle(np, "mii-bus", 0); |
- | ||
1549 | if (!mdio_node) { |
- | ||
1550 | dev_err(&pdev->dev, "cannot find mdio node phandle"); |
- | ||
1551 | goto try_gpio; |
- | ||
1552 | } |
- | ||
1553 | |
- | ||
1554 | smi->ext_mbus = of_mdio_find_bus(mdio_node); |
- | ||
1555 | if (!smi->ext_mbus) { |
- | ||
1556 | dev_info(&pdev->dev, |
- | ||
1557 | "cannot find mdio bus from bus handle (yet)"); |
- | ||
1558 | goto try_gpio; |
- | ||
1559 | } |
- | ||
1560 | |
- | ||
1561 | return 0; |
- | ||
1562 | |
1431 | int sda = of_get_named_gpio(pdev->dev.of_node, "gpio-sda", 0); |
|
1563 | try_gpio: |
- | ||
1564 | if (!gpio_is_valid(sck) || !gpio_is_valid(sda)) { |
1432 | |
|
1565 | if (!mdio_node) { |
1433 | if (!gpio_is_valid(sck) || !gpio_is_valid(sda)) { |
|
1566 | dev_err(&pdev->dev, "gpios missing in devictree\n"); |
- | ||
1567 | return -EINVAL; |
- | ||
1568 | } else { |
- | ||
1569 | return -EPROBE_DEFER; |
1434 | dev_err(&pdev->dev, "gpios missing in devictree\n"); |
|
Line 1570... | Line 1435... | |||
1570 | } |
1435 | return -EINVAL; |
|
1571 | } |
1436 | } |
|
1572 | |
- | ||
1573 | smi->gpio_sda = sda; |
- | ||
1574 | smi->gpio_sck = sck; |
- | ||
Line 1575... | Line 1437... | |||
1575 | smi->reset = devm_reset_control_get(&pdev->dev, "switch"); |
1437 | |
|
1576 | if (!IS_ERR(smi->reset)) |
1438 | smi->gpio_sda = sda; |
|
1577 | smi->hw_reset = rtl8366_smi_reset; |
1439 | smi->gpio_sck = sck; |
|
1578 | |
1440 | |
|
Line 1621... | Line 1483... | |||
1621 | |
1483 | |
|
Line 1622... | Line 1484... | |||
1622 | return smi; |
1484 | return smi; |
|
1623 | |
1485 | |
|
1624 | free_smi: |
1486 | free_smi: |
|
1625 | kfree(smi); |
1487 | kfree(smi); |
|
1626 | return ERR_PTR(err); |
1488 | return NULL; |
|
Line 1627... | Line 1489... | |||
1627 | } |
1489 | } |
|
1628 | EXPORT_SYMBOL_GPL(rtl8366_smi_probe); |
1490 | EXPORT_SYMBOL_GPL(rtl8366_smi_probe); |