diff options
Diffstat (limited to 'drivers/pci/host/pci-tegra.c')
| -rw-r--r-- | drivers/pci/host/pci-tegra.c | 347 |
1 files changed, 283 insertions, 64 deletions
diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c index 083cf37ca047..0fb0fdb223d5 100644 --- a/drivers/pci/host/pci-tegra.c +++ b/drivers/pci/host/pci-tegra.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | */ | 25 | */ |
| 26 | 26 | ||
| 27 | #include <linux/clk.h> | 27 | #include <linux/clk.h> |
| 28 | #include <linux/debugfs.h> | ||
| 28 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
| 29 | #include <linux/export.h> | 30 | #include <linux/export.h> |
| 30 | #include <linux/interrupt.h> | 31 | #include <linux/interrupt.h> |
| @@ -41,11 +42,12 @@ | |||
| 41 | #include <linux/reset.h> | 42 | #include <linux/reset.h> |
| 42 | #include <linux/sizes.h> | 43 | #include <linux/sizes.h> |
| 43 | #include <linux/slab.h> | 44 | #include <linux/slab.h> |
| 44 | #include <linux/tegra-cpuidle.h> | ||
| 45 | #include <linux/tegra-powergate.h> | ||
| 46 | #include <linux/vmalloc.h> | 45 | #include <linux/vmalloc.h> |
| 47 | #include <linux/regulator/consumer.h> | 46 | #include <linux/regulator/consumer.h> |
| 48 | 47 | ||
| 48 | #include <soc/tegra/cpuidle.h> | ||
| 49 | #include <soc/tegra/pmc.h> | ||
| 50 | |||
| 49 | #include <asm/mach/irq.h> | 51 | #include <asm/mach/irq.h> |
| 50 | #include <asm/mach/map.h> | 52 | #include <asm/mach/map.h> |
| 51 | #include <asm/mach/pci.h> | 53 | #include <asm/mach/pci.h> |
| @@ -233,7 +235,6 @@ struct tegra_pcie_soc_data { | |||
| 233 | bool has_pex_clkreq_en; | 235 | bool has_pex_clkreq_en; |
| 234 | bool has_pex_bias_ctrl; | 236 | bool has_pex_bias_ctrl; |
| 235 | bool has_intr_prsnt_sense; | 237 | bool has_intr_prsnt_sense; |
| 236 | bool has_avdd_supply; | ||
| 237 | bool has_cml_clk; | 238 | bool has_cml_clk; |
| 238 | }; | 239 | }; |
| 239 | 240 | ||
| @@ -272,11 +273,11 @@ struct tegra_pcie { | |||
| 272 | unsigned int num_ports; | 273 | unsigned int num_ports; |
| 273 | u32 xbar_config; | 274 | u32 xbar_config; |
| 274 | 275 | ||
| 275 | struct regulator *pex_clk_supply; | 276 | struct regulator_bulk_data *supplies; |
| 276 | struct regulator *vdd_supply; | 277 | unsigned int num_supplies; |
| 277 | struct regulator *avdd_supply; | ||
| 278 | 278 | ||
| 279 | const struct tegra_pcie_soc_data *soc_data; | 279 | const struct tegra_pcie_soc_data *soc_data; |
| 280 | struct dentry *debugfs; | ||
| 280 | }; | 281 | }; |
| 281 | 282 | ||
| 282 | struct tegra_pcie_port { | 283 | struct tegra_pcie_port { |
| @@ -894,7 +895,6 @@ static int tegra_pcie_enable_controller(struct tegra_pcie *pcie) | |||
| 894 | 895 | ||
| 895 | static void tegra_pcie_power_off(struct tegra_pcie *pcie) | 896 | static void tegra_pcie_power_off(struct tegra_pcie *pcie) |
| 896 | { | 897 | { |
| 897 | const struct tegra_pcie_soc_data *soc = pcie->soc_data; | ||
| 898 | int err; | 898 | int err; |
| 899 | 899 | ||
| 900 | /* TODO: disable and unprepare clocks? */ | 900 | /* TODO: disable and unprepare clocks? */ |
| @@ -905,23 +905,9 @@ static void tegra_pcie_power_off(struct tegra_pcie *pcie) | |||
| 905 | 905 | ||
| 906 | tegra_powergate_power_off(TEGRA_POWERGATE_PCIE); | 906 | tegra_powergate_power_off(TEGRA_POWERGATE_PCIE); |
| 907 | 907 | ||
| 908 | if (soc->has_avdd_supply) { | 908 | err = regulator_bulk_disable(pcie->num_supplies, pcie->supplies); |
| 909 | err = regulator_disable(pcie->avdd_supply); | ||
| 910 | if (err < 0) | ||
| 911 | dev_warn(pcie->dev, | ||
| 912 | "failed to disable AVDD regulator: %d\n", | ||
| 913 | err); | ||
| 914 | } | ||
| 915 | |||
| 916 | err = regulator_disable(pcie->pex_clk_supply); | ||
| 917 | if (err < 0) | 909 | if (err < 0) |
| 918 | dev_warn(pcie->dev, "failed to disable pex-clk regulator: %d\n", | 910 | dev_warn(pcie->dev, "failed to disable regulators: %d\n", err); |
| 919 | err); | ||
| 920 | |||
| 921 | err = regulator_disable(pcie->vdd_supply); | ||
| 922 | if (err < 0) | ||
| 923 | dev_warn(pcie->dev, "failed to disable VDD regulator: %d\n", | ||
| 924 | err); | ||
| 925 | } | 911 | } |
| 926 | 912 | ||
| 927 | static int tegra_pcie_power_on(struct tegra_pcie *pcie) | 913 | static int tegra_pcie_power_on(struct tegra_pcie *pcie) |
| @@ -936,28 +922,9 @@ static int tegra_pcie_power_on(struct tegra_pcie *pcie) | |||
| 936 | tegra_powergate_power_off(TEGRA_POWERGATE_PCIE); | 922 | tegra_powergate_power_off(TEGRA_POWERGATE_PCIE); |
| 937 | 923 | ||
| 938 | /* enable regulators */ | 924 | /* enable regulators */ |
| 939 | err = regulator_enable(pcie->vdd_supply); | 925 | err = regulator_bulk_enable(pcie->num_supplies, pcie->supplies); |
| 940 | if (err < 0) { | 926 | if (err < 0) |
| 941 | dev_err(pcie->dev, "failed to enable VDD regulator: %d\n", err); | 927 | dev_err(pcie->dev, "failed to enable regulators: %d\n", err); |
| 942 | return err; | ||
| 943 | } | ||
| 944 | |||
| 945 | err = regulator_enable(pcie->pex_clk_supply); | ||
| 946 | if (err < 0) { | ||
| 947 | dev_err(pcie->dev, "failed to enable pex-clk regulator: %d\n", | ||
| 948 | err); | ||
| 949 | return err; | ||
| 950 | } | ||
| 951 | |||
| 952 | if (soc->has_avdd_supply) { | ||
| 953 | err = regulator_enable(pcie->avdd_supply); | ||
| 954 | if (err < 0) { | ||
| 955 | dev_err(pcie->dev, | ||
| 956 | "failed to enable AVDD regulator: %d\n", | ||
| 957 | err); | ||
| 958 | return err; | ||
| 959 | } | ||
| 960 | } | ||
| 961 | 928 | ||
| 962 | err = tegra_powergate_sequence_power_up(TEGRA_POWERGATE_PCIE, | 929 | err = tegra_powergate_sequence_power_up(TEGRA_POWERGATE_PCIE, |
| 963 | pcie->pex_clk, | 930 | pcie->pex_clk, |
| @@ -1394,14 +1361,157 @@ static int tegra_pcie_get_xbar_config(struct tegra_pcie *pcie, u32 lanes, | |||
| 1394 | return -EINVAL; | 1361 | return -EINVAL; |
| 1395 | } | 1362 | } |
| 1396 | 1363 | ||
| 1364 | /* | ||
| 1365 | * Check whether a given set of supplies is available in a device tree node. | ||
| 1366 | * This is used to check whether the new or the legacy device tree bindings | ||
| 1367 | * should be used. | ||
| 1368 | */ | ||
| 1369 | static bool of_regulator_bulk_available(struct device_node *np, | ||
| 1370 | struct regulator_bulk_data *supplies, | ||
| 1371 | unsigned int num_supplies) | ||
| 1372 | { | ||
| 1373 | char property[32]; | ||
| 1374 | unsigned int i; | ||
| 1375 | |||
| 1376 | for (i = 0; i < num_supplies; i++) { | ||
| 1377 | snprintf(property, 32, "%s-supply", supplies[i].supply); | ||
| 1378 | |||
| 1379 | if (of_find_property(np, property, NULL) == NULL) | ||
| 1380 | return false; | ||
| 1381 | } | ||
| 1382 | |||
| 1383 | return true; | ||
| 1384 | } | ||
| 1385 | |||
| 1386 | /* | ||
| 1387 | * Old versions of the device tree binding for this device used a set of power | ||
| 1388 | * supplies that didn't match the hardware inputs. This happened to work for a | ||
| 1389 | * number of cases but is not future proof. However to preserve backwards- | ||
| 1390 | * compatibility with old device trees, this function will try to use the old | ||
| 1391 | * set of supplies. | ||
| 1392 | */ | ||
| 1393 | static int tegra_pcie_get_legacy_regulators(struct tegra_pcie *pcie) | ||
| 1394 | { | ||
| 1395 | struct device_node *np = pcie->dev->of_node; | ||
| 1396 | |||
| 1397 | if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) | ||
| 1398 | pcie->num_supplies = 3; | ||
| 1399 | else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) | ||
| 1400 | pcie->num_supplies = 2; | ||
| 1401 | |||
| 1402 | if (pcie->num_supplies == 0) { | ||
| 1403 | dev_err(pcie->dev, "device %s not supported in legacy mode\n", | ||
| 1404 | np->full_name); | ||
| 1405 | return -ENODEV; | ||
| 1406 | } | ||
| 1407 | |||
| 1408 | pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, | ||
| 1409 | sizeof(*pcie->supplies), | ||
| 1410 | GFP_KERNEL); | ||
| 1411 | if (!pcie->supplies) | ||
| 1412 | return -ENOMEM; | ||
| 1413 | |||
| 1414 | pcie->supplies[0].supply = "pex-clk"; | ||
| 1415 | pcie->supplies[1].supply = "vdd"; | ||
| 1416 | |||
| 1417 | if (pcie->num_supplies > 2) | ||
| 1418 | pcie->supplies[2].supply = "avdd"; | ||
| 1419 | |||
| 1420 | return devm_regulator_bulk_get(pcie->dev, pcie->num_supplies, | ||
| 1421 | pcie->supplies); | ||
| 1422 | } | ||
| 1423 | |||
| 1424 | /* | ||
| 1425 | * Obtains the list of regulators required for a particular generation of the | ||
| 1426 | * IP block. | ||
| 1427 | * | ||
| 1428 | * This would've been nice to do simply by providing static tables for use | ||
| 1429 | * with the regulator_bulk_*() API, but unfortunately Tegra30 is a bit quirky | ||
| 1430 | * in that it has two pairs or AVDD_PEX and VDD_PEX supplies (PEXA and PEXB) | ||
| 1431 | * and either seems to be optional depending on which ports are being used. | ||
| 1432 | */ | ||
| 1433 | static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) | ||
| 1434 | { | ||
| 1435 | struct device_node *np = pcie->dev->of_node; | ||
| 1436 | unsigned int i = 0; | ||
| 1437 | |||
| 1438 | if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) { | ||
| 1439 | bool need_pexa = false, need_pexb = false; | ||
| 1440 | |||
| 1441 | /* VDD_PEXA and AVDD_PEXA supply lanes 0 to 3 */ | ||
| 1442 | if (lane_mask & 0x0f) | ||
| 1443 | need_pexa = true; | ||
| 1444 | |||
| 1445 | /* VDD_PEXB and AVDD_PEXB supply lanes 4 to 5 */ | ||
| 1446 | if (lane_mask & 0x30) | ||
| 1447 | need_pexb = true; | ||
| 1448 | |||
| 1449 | pcie->num_supplies = 4 + (need_pexa ? 2 : 0) + | ||
| 1450 | (need_pexb ? 2 : 0); | ||
| 1451 | |||
| 1452 | pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, | ||
| 1453 | sizeof(*pcie->supplies), | ||
| 1454 | GFP_KERNEL); | ||
| 1455 | if (!pcie->supplies) | ||
| 1456 | return -ENOMEM; | ||
| 1457 | |||
| 1458 | pcie->supplies[i++].supply = "avdd-pex-pll"; | ||
| 1459 | pcie->supplies[i++].supply = "hvdd-pex"; | ||
| 1460 | pcie->supplies[i++].supply = "vddio-pex-ctl"; | ||
| 1461 | pcie->supplies[i++].supply = "avdd-plle"; | ||
| 1462 | |||
| 1463 | if (need_pexa) { | ||
| 1464 | pcie->supplies[i++].supply = "avdd-pexa"; | ||
| 1465 | pcie->supplies[i++].supply = "vdd-pexa"; | ||
| 1466 | } | ||
| 1467 | |||
| 1468 | if (need_pexb) { | ||
| 1469 | pcie->supplies[i++].supply = "avdd-pexb"; | ||
| 1470 | pcie->supplies[i++].supply = "vdd-pexb"; | ||
| 1471 | } | ||
| 1472 | } else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) { | ||
| 1473 | pcie->num_supplies = 5; | ||
| 1474 | |||
| 1475 | pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, | ||
| 1476 | sizeof(*pcie->supplies), | ||
| 1477 | GFP_KERNEL); | ||
| 1478 | if (!pcie->supplies) | ||
| 1479 | return -ENOMEM; | ||
| 1480 | |||
| 1481 | pcie->supplies[0].supply = "avdd-pex"; | ||
| 1482 | pcie->supplies[1].supply = "vdd-pex"; | ||
| 1483 | pcie->supplies[2].supply = "avdd-pex-pll"; | ||
| 1484 | pcie->supplies[3].supply = "avdd-plle"; | ||
| 1485 | pcie->supplies[4].supply = "vddio-pex-clk"; | ||
| 1486 | } | ||
| 1487 | |||
| 1488 | if (of_regulator_bulk_available(pcie->dev->of_node, pcie->supplies, | ||
| 1489 | pcie->num_supplies)) | ||
| 1490 | return devm_regulator_bulk_get(pcie->dev, pcie->num_supplies, | ||
| 1491 | pcie->supplies); | ||
| 1492 | |||
| 1493 | /* | ||
| 1494 | * If not all regulators are available for this new scheme, assume | ||
| 1495 | * that the device tree complies with an older version of the device | ||
| 1496 | * tree binding. | ||
| 1497 | */ | ||
| 1498 | dev_info(pcie->dev, "using legacy DT binding for power supplies\n"); | ||
| 1499 | |||
| 1500 | devm_kfree(pcie->dev, pcie->supplies); | ||
| 1501 | pcie->num_supplies = 0; | ||
| 1502 | |||
| 1503 | return tegra_pcie_get_legacy_regulators(pcie); | ||
| 1504 | } | ||
| 1505 | |||
| 1397 | static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) | 1506 | static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) |
| 1398 | { | 1507 | { |
| 1399 | const struct tegra_pcie_soc_data *soc = pcie->soc_data; | 1508 | const struct tegra_pcie_soc_data *soc = pcie->soc_data; |
| 1400 | struct device_node *np = pcie->dev->of_node, *port; | 1509 | struct device_node *np = pcie->dev->of_node, *port; |
| 1401 | struct of_pci_range_parser parser; | 1510 | struct of_pci_range_parser parser; |
| 1402 | struct of_pci_range range; | 1511 | struct of_pci_range range; |
| 1512 | u32 lanes = 0, mask = 0; | ||
| 1513 | unsigned int lane = 0; | ||
| 1403 | struct resource res; | 1514 | struct resource res; |
| 1404 | u32 lanes = 0; | ||
| 1405 | int err; | 1515 | int err; |
| 1406 | 1516 | ||
| 1407 | if (of_pci_range_parser_init(&parser, np)) { | 1517 | if (of_pci_range_parser_init(&parser, np)) { |
| @@ -1409,20 +1519,6 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) | |||
| 1409 | return -EINVAL; | 1519 | return -EINVAL; |
| 1410 | } | 1520 | } |
| 1411 | 1521 | ||
| 1412 | pcie->vdd_supply = devm_regulator_get(pcie->dev, "vdd"); | ||
| 1413 | if (IS_ERR(pcie->vdd_supply)) | ||
| 1414 | return PTR_ERR(pcie->vdd_supply); | ||
| 1415 | |||
| 1416 | pcie->pex_clk_supply = devm_regulator_get(pcie->dev, "pex-clk"); | ||
| 1417 | if (IS_ERR(pcie->pex_clk_supply)) | ||
| 1418 | return PTR_ERR(pcie->pex_clk_supply); | ||
| 1419 | |||
| 1420 | if (soc->has_avdd_supply) { | ||
| 1421 | pcie->avdd_supply = devm_regulator_get(pcie->dev, "avdd"); | ||
| 1422 | if (IS_ERR(pcie->avdd_supply)) | ||
| 1423 | return PTR_ERR(pcie->avdd_supply); | ||
| 1424 | } | ||
| 1425 | |||
| 1426 | for_each_of_pci_range(&parser, &range) { | 1522 | for_each_of_pci_range(&parser, &range) { |
| 1427 | of_pci_range_to_resource(&range, np, &res); | 1523 | of_pci_range_to_resource(&range, np, &res); |
| 1428 | 1524 | ||
| @@ -1490,8 +1586,13 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) | |||
| 1490 | 1586 | ||
| 1491 | lanes |= value << (index << 3); | 1587 | lanes |= value << (index << 3); |
| 1492 | 1588 | ||
| 1493 | if (!of_device_is_available(port)) | 1589 | if (!of_device_is_available(port)) { |
| 1590 | lane += value; | ||
| 1494 | continue; | 1591 | continue; |
| 1592 | } | ||
| 1593 | |||
| 1594 | mask |= ((1 << value) - 1) << lane; | ||
| 1595 | lane += value; | ||
| 1495 | 1596 | ||
| 1496 | rp = devm_kzalloc(pcie->dev, sizeof(*rp), GFP_KERNEL); | 1597 | rp = devm_kzalloc(pcie->dev, sizeof(*rp), GFP_KERNEL); |
| 1497 | if (!rp) | 1598 | if (!rp) |
| @@ -1522,6 +1623,10 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) | |||
| 1522 | return err; | 1623 | return err; |
| 1523 | } | 1624 | } |
| 1524 | 1625 | ||
| 1626 | err = tegra_pcie_get_regulators(pcie, mask); | ||
| 1627 | if (err < 0) | ||
| 1628 | return err; | ||
| 1629 | |||
| 1525 | return 0; | 1630 | return 0; |
| 1526 | } | 1631 | } |
| 1527 | 1632 | ||
| @@ -1615,7 +1720,6 @@ static const struct tegra_pcie_soc_data tegra20_pcie_data = { | |||
| 1615 | .has_pex_clkreq_en = false, | 1720 | .has_pex_clkreq_en = false, |
| 1616 | .has_pex_bias_ctrl = false, | 1721 | .has_pex_bias_ctrl = false, |
| 1617 | .has_intr_prsnt_sense = false, | 1722 | .has_intr_prsnt_sense = false, |
| 1618 | .has_avdd_supply = false, | ||
| 1619 | .has_cml_clk = false, | 1723 | .has_cml_clk = false, |
| 1620 | }; | 1724 | }; |
| 1621 | 1725 | ||
| @@ -1627,7 +1731,6 @@ static const struct tegra_pcie_soc_data tegra30_pcie_data = { | |||
| 1627 | .has_pex_clkreq_en = true, | 1731 | .has_pex_clkreq_en = true, |
| 1628 | .has_pex_bias_ctrl = true, | 1732 | .has_pex_bias_ctrl = true, |
| 1629 | .has_intr_prsnt_sense = true, | 1733 | .has_intr_prsnt_sense = true, |
| 1630 | .has_avdd_supply = true, | ||
| 1631 | .has_cml_clk = true, | 1734 | .has_cml_clk = true, |
| 1632 | }; | 1735 | }; |
| 1633 | 1736 | ||
| @@ -1638,6 +1741,115 @@ static const struct of_device_id tegra_pcie_of_match[] = { | |||
| 1638 | }; | 1741 | }; |
| 1639 | MODULE_DEVICE_TABLE(of, tegra_pcie_of_match); | 1742 | MODULE_DEVICE_TABLE(of, tegra_pcie_of_match); |
| 1640 | 1743 | ||
| 1744 | static void *tegra_pcie_ports_seq_start(struct seq_file *s, loff_t *pos) | ||
| 1745 | { | ||
| 1746 | struct tegra_pcie *pcie = s->private; | ||
| 1747 | |||
| 1748 | if (list_empty(&pcie->ports)) | ||
| 1749 | return NULL; | ||
| 1750 | |||
| 1751 | seq_printf(s, "Index Status\n"); | ||
| 1752 | |||
| 1753 | return seq_list_start(&pcie->ports, *pos); | ||
| 1754 | } | ||
| 1755 | |||
| 1756 | static void *tegra_pcie_ports_seq_next(struct seq_file *s, void *v, loff_t *pos) | ||
| 1757 | { | ||
| 1758 | struct tegra_pcie *pcie = s->private; | ||
| 1759 | |||
| 1760 | return seq_list_next(v, &pcie->ports, pos); | ||
| 1761 | } | ||
| 1762 | |||
| 1763 | static void tegra_pcie_ports_seq_stop(struct seq_file *s, void *v) | ||
| 1764 | { | ||
| 1765 | } | ||
| 1766 | |||
| 1767 | static int tegra_pcie_ports_seq_show(struct seq_file *s, void *v) | ||
| 1768 | { | ||
| 1769 | bool up = false, active = false; | ||
| 1770 | struct tegra_pcie_port *port; | ||
| 1771 | unsigned int value; | ||
| 1772 | |||
| 1773 | port = list_entry(v, struct tegra_pcie_port, list); | ||
| 1774 | |||
| 1775 | value = readl(port->base + RP_VEND_XP); | ||
| 1776 | |||
| 1777 | if (value & RP_VEND_XP_DL_UP) | ||
| 1778 | up = true; | ||
| 1779 | |||
| 1780 | value = readl(port->base + RP_LINK_CONTROL_STATUS); | ||
| 1781 | |||
| 1782 | if (value & RP_LINK_CONTROL_STATUS_DL_LINK_ACTIVE) | ||
| 1783 | active = true; | ||
| 1784 | |||
| 1785 | seq_printf(s, "%2u ", port->index); | ||
| 1786 | |||
| 1787 | if (up) | ||
| 1788 | seq_printf(s, "up"); | ||
| 1789 | |||
| 1790 | if (active) { | ||
| 1791 | if (up) | ||
| 1792 | seq_printf(s, ", "); | ||
| 1793 | |||
| 1794 | seq_printf(s, "active"); | ||
| 1795 | } | ||
| 1796 | |||
| 1797 | seq_printf(s, "\n"); | ||
| 1798 | return 0; | ||
| 1799 | } | ||
| 1800 | |||
| 1801 | static const struct seq_operations tegra_pcie_ports_seq_ops = { | ||
| 1802 | .start = tegra_pcie_ports_seq_start, | ||
| 1803 | .next = tegra_pcie_ports_seq_next, | ||
| 1804 | .stop = tegra_pcie_ports_seq_stop, | ||
| 1805 | .show = tegra_pcie_ports_seq_show, | ||
| 1806 | }; | ||
| 1807 | |||
| 1808 | static int tegra_pcie_ports_open(struct inode *inode, struct file *file) | ||
| 1809 | { | ||
| 1810 | struct tegra_pcie *pcie = inode->i_private; | ||
| 1811 | struct seq_file *s; | ||
| 1812 | int err; | ||
| 1813 | |||
| 1814 | err = seq_open(file, &tegra_pcie_ports_seq_ops); | ||
| 1815 | if (err) | ||
| 1816 | return err; | ||
| 1817 | |||
| 1818 | s = file->private_data; | ||
| 1819 | s->private = pcie; | ||
| 1820 | |||
| 1821 | return 0; | ||
| 1822 | } | ||
| 1823 | |||
| 1824 | static const struct file_operations tegra_pcie_ports_ops = { | ||
| 1825 | .owner = THIS_MODULE, | ||
| 1826 | .open = tegra_pcie_ports_open, | ||
| 1827 | .read = seq_read, | ||
| 1828 | .llseek = seq_lseek, | ||
| 1829 | .release = seq_release, | ||
| 1830 | }; | ||
| 1831 | |||
| 1832 | static int tegra_pcie_debugfs_init(struct tegra_pcie *pcie) | ||
| 1833 | { | ||
| 1834 | struct dentry *file; | ||
| 1835 | |||
| 1836 | pcie->debugfs = debugfs_create_dir("pcie", NULL); | ||
| 1837 | if (!pcie->debugfs) | ||
| 1838 | return -ENOMEM; | ||
| 1839 | |||
| 1840 | file = debugfs_create_file("ports", S_IFREG | S_IRUGO, pcie->debugfs, | ||
| 1841 | pcie, &tegra_pcie_ports_ops); | ||
| 1842 | if (!file) | ||
| 1843 | goto remove; | ||
| 1844 | |||
| 1845 | return 0; | ||
| 1846 | |||
| 1847 | remove: | ||
| 1848 | debugfs_remove_recursive(pcie->debugfs); | ||
| 1849 | pcie->debugfs = NULL; | ||
| 1850 | return -ENOMEM; | ||
| 1851 | } | ||
| 1852 | |||
| 1641 | static int tegra_pcie_probe(struct platform_device *pdev) | 1853 | static int tegra_pcie_probe(struct platform_device *pdev) |
| 1642 | { | 1854 | { |
| 1643 | const struct of_device_id *match; | 1855 | const struct of_device_id *match; |
| @@ -1692,6 +1904,13 @@ static int tegra_pcie_probe(struct platform_device *pdev) | |||
| 1692 | goto disable_msi; | 1904 | goto disable_msi; |
| 1693 | } | 1905 | } |
| 1694 | 1906 | ||
| 1907 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { | ||
| 1908 | err = tegra_pcie_debugfs_init(pcie); | ||
| 1909 | if (err < 0) | ||
| 1910 | dev_err(&pdev->dev, "failed to setup debugfs: %d\n", | ||
| 1911 | err); | ||
| 1912 | } | ||
| 1913 | |||
| 1695 | platform_set_drvdata(pdev, pcie); | 1914 | platform_set_drvdata(pdev, pcie); |
| 1696 | return 0; | 1915 | return 0; |
| 1697 | 1916 | ||
| @@ -1716,4 +1935,4 @@ module_platform_driver(tegra_pcie_driver); | |||
| 1716 | 1935 | ||
| 1717 | MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>"); | 1936 | MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>"); |
| 1718 | MODULE_DESCRIPTION("NVIDIA Tegra PCIe driver"); | 1937 | MODULE_DESCRIPTION("NVIDIA Tegra PCIe driver"); |
| 1719 | MODULE_LICENSE("GPLv2"); | 1938 | MODULE_LICENSE("GPL v2"); |
