diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2014-06-24 06:19:37 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-07-01 17:24:40 -0400 |
commit | 29e69413666f085d9eb79b29ebfedb163e0e8ef2 (patch) | |
tree | 4299a0f37b33c61f66d9d10388944ca57c6a2db2 /drivers/ata | |
parent | 23a7c31e4a1c2e0acfa91c6360636e4ac6d8dd40 (diff) |
ata: ahci_imx: allow hardware parameters to be specified in DT
Various SATA phy parameters are board specific, and therefore need to
be configured.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Reviewed-by: Shawn Guo <shawn.guo@freescale.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'drivers/ata')
-rw-r--r-- | drivers/ata/ahci_imx.c | 168 |
1 files changed, 160 insertions, 8 deletions
diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c index 3a901520c62b..e032e95ddee3 100644 --- a/drivers/ata/ahci_imx.c +++ b/drivers/ata/ahci_imx.c | |||
@@ -62,6 +62,7 @@ struct imx_ahci_priv { | |||
62 | struct regmap *gpr; | 62 | struct regmap *gpr; |
63 | bool no_device; | 63 | bool no_device; |
64 | bool first_time; | 64 | bool first_time; |
65 | u32 phy_params; | ||
65 | }; | 66 | }; |
66 | 67 | ||
67 | static int ahci_imx_hotplug; | 68 | static int ahci_imx_hotplug; |
@@ -246,14 +247,7 @@ static int imx_sata_enable(struct ahci_host_priv *hpriv) | |||
246 | IMX6Q_GPR13_SATA_TX_LVL_MASK | | 247 | IMX6Q_GPR13_SATA_TX_LVL_MASK | |
247 | IMX6Q_GPR13_SATA_MPLL_CLK_EN | | 248 | IMX6Q_GPR13_SATA_MPLL_CLK_EN | |
248 | IMX6Q_GPR13_SATA_TX_EDGE_RATE, | 249 | IMX6Q_GPR13_SATA_TX_EDGE_RATE, |
249 | IMX6Q_GPR13_SATA_RX_EQ_VAL_3_0_DB | | 250 | imxpriv->phy_params); |
250 | IMX6Q_GPR13_SATA_RX_LOS_LVL_SATA2M | | ||
251 | IMX6Q_GPR13_SATA_RX_DPLL_MODE_2P_4F | | ||
252 | IMX6Q_GPR13_SATA_SPD_MODE_3P0G | | ||
253 | IMX6Q_GPR13_SATA_MPLL_SS_EN | | ||
254 | IMX6Q_GPR13_SATA_TX_ATTEN_9_16 | | ||
255 | IMX6Q_GPR13_SATA_TX_BOOST_3_33_DB | | ||
256 | IMX6Q_GPR13_SATA_TX_LVL_1_025_V); | ||
257 | regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13, | 251 | regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13, |
258 | IMX6Q_GPR13_SATA_MPLL_CLK_EN, | 252 | IMX6Q_GPR13_SATA_MPLL_CLK_EN, |
259 | IMX6Q_GPR13_SATA_MPLL_CLK_EN); | 253 | IMX6Q_GPR13_SATA_MPLL_CLK_EN); |
@@ -364,6 +358,152 @@ static const struct of_device_id imx_ahci_of_match[] = { | |||
364 | }; | 358 | }; |
365 | MODULE_DEVICE_TABLE(of, imx_ahci_of_match); | 359 | MODULE_DEVICE_TABLE(of, imx_ahci_of_match); |
366 | 360 | ||
361 | struct reg_value { | ||
362 | u32 of_value; | ||
363 | u32 reg_value; | ||
364 | }; | ||
365 | |||
366 | struct reg_property { | ||
367 | const char *name; | ||
368 | const struct reg_value *values; | ||
369 | size_t num_values; | ||
370 | u32 def_value; | ||
371 | }; | ||
372 | |||
373 | static const struct reg_value gpr13_tx_level[] = { | ||
374 | { 937, IMX6Q_GPR13_SATA_TX_LVL_0_937_V }, | ||
375 | { 947, IMX6Q_GPR13_SATA_TX_LVL_0_947_V }, | ||
376 | { 957, IMX6Q_GPR13_SATA_TX_LVL_0_957_V }, | ||
377 | { 966, IMX6Q_GPR13_SATA_TX_LVL_0_966_V }, | ||
378 | { 976, IMX6Q_GPR13_SATA_TX_LVL_0_976_V }, | ||
379 | { 986, IMX6Q_GPR13_SATA_TX_LVL_0_986_V }, | ||
380 | { 996, IMX6Q_GPR13_SATA_TX_LVL_0_996_V }, | ||
381 | { 1005, IMX6Q_GPR13_SATA_TX_LVL_1_005_V }, | ||
382 | { 1015, IMX6Q_GPR13_SATA_TX_LVL_1_015_V }, | ||
383 | { 1025, IMX6Q_GPR13_SATA_TX_LVL_1_025_V }, | ||
384 | { 1035, IMX6Q_GPR13_SATA_TX_LVL_1_035_V }, | ||
385 | { 1045, IMX6Q_GPR13_SATA_TX_LVL_1_045_V }, | ||
386 | { 1054, IMX6Q_GPR13_SATA_TX_LVL_1_054_V }, | ||
387 | { 1064, IMX6Q_GPR13_SATA_TX_LVL_1_064_V }, | ||
388 | { 1074, IMX6Q_GPR13_SATA_TX_LVL_1_074_V }, | ||
389 | { 1084, IMX6Q_GPR13_SATA_TX_LVL_1_084_V }, | ||
390 | { 1094, IMX6Q_GPR13_SATA_TX_LVL_1_094_V }, | ||
391 | { 1104, IMX6Q_GPR13_SATA_TX_LVL_1_104_V }, | ||
392 | { 1113, IMX6Q_GPR13_SATA_TX_LVL_1_113_V }, | ||
393 | { 1123, IMX6Q_GPR13_SATA_TX_LVL_1_123_V }, | ||
394 | { 1133, IMX6Q_GPR13_SATA_TX_LVL_1_133_V }, | ||
395 | { 1143, IMX6Q_GPR13_SATA_TX_LVL_1_143_V }, | ||
396 | { 1152, IMX6Q_GPR13_SATA_TX_LVL_1_152_V }, | ||
397 | { 1162, IMX6Q_GPR13_SATA_TX_LVL_1_162_V }, | ||
398 | { 1172, IMX6Q_GPR13_SATA_TX_LVL_1_172_V }, | ||
399 | { 1182, IMX6Q_GPR13_SATA_TX_LVL_1_182_V }, | ||
400 | { 1191, IMX6Q_GPR13_SATA_TX_LVL_1_191_V }, | ||
401 | { 1201, IMX6Q_GPR13_SATA_TX_LVL_1_201_V }, | ||
402 | { 1211, IMX6Q_GPR13_SATA_TX_LVL_1_211_V }, | ||
403 | { 1221, IMX6Q_GPR13_SATA_TX_LVL_1_221_V }, | ||
404 | { 1230, IMX6Q_GPR13_SATA_TX_LVL_1_230_V }, | ||
405 | { 1240, IMX6Q_GPR13_SATA_TX_LVL_1_240_V } | ||
406 | }; | ||
407 | |||
408 | static const struct reg_value gpr13_tx_boost[] = { | ||
409 | { 0, IMX6Q_GPR13_SATA_TX_BOOST_0_00_DB }, | ||
410 | { 370, IMX6Q_GPR13_SATA_TX_BOOST_0_37_DB }, | ||
411 | { 740, IMX6Q_GPR13_SATA_TX_BOOST_0_74_DB }, | ||
412 | { 1110, IMX6Q_GPR13_SATA_TX_BOOST_1_11_DB }, | ||
413 | { 1480, IMX6Q_GPR13_SATA_TX_BOOST_1_48_DB }, | ||
414 | { 1850, IMX6Q_GPR13_SATA_TX_BOOST_1_85_DB }, | ||
415 | { 2220, IMX6Q_GPR13_SATA_TX_BOOST_2_22_DB }, | ||
416 | { 2590, IMX6Q_GPR13_SATA_TX_BOOST_2_59_DB }, | ||
417 | { 2960, IMX6Q_GPR13_SATA_TX_BOOST_2_96_DB }, | ||
418 | { 3330, IMX6Q_GPR13_SATA_TX_BOOST_3_33_DB }, | ||
419 | { 3700, IMX6Q_GPR13_SATA_TX_BOOST_3_70_DB }, | ||
420 | { 4070, IMX6Q_GPR13_SATA_TX_BOOST_4_07_DB }, | ||
421 | { 4440, IMX6Q_GPR13_SATA_TX_BOOST_4_44_DB }, | ||
422 | { 4810, IMX6Q_GPR13_SATA_TX_BOOST_4_81_DB }, | ||
423 | { 5280, IMX6Q_GPR13_SATA_TX_BOOST_5_28_DB }, | ||
424 | { 5750, IMX6Q_GPR13_SATA_TX_BOOST_5_75_DB } | ||
425 | }; | ||
426 | |||
427 | static const struct reg_value gpr13_tx_atten[] = { | ||
428 | { 8, IMX6Q_GPR13_SATA_TX_ATTEN_8_16 }, | ||
429 | { 9, IMX6Q_GPR13_SATA_TX_ATTEN_9_16 }, | ||
430 | { 10, IMX6Q_GPR13_SATA_TX_ATTEN_10_16 }, | ||
431 | { 12, IMX6Q_GPR13_SATA_TX_ATTEN_12_16 }, | ||
432 | { 14, IMX6Q_GPR13_SATA_TX_ATTEN_14_16 }, | ||
433 | { 16, IMX6Q_GPR13_SATA_TX_ATTEN_16_16 }, | ||
434 | }; | ||
435 | |||
436 | static const struct reg_value gpr13_rx_eq[] = { | ||
437 | { 500, IMX6Q_GPR13_SATA_RX_EQ_VAL_0_5_DB }, | ||
438 | { 1000, IMX6Q_GPR13_SATA_RX_EQ_VAL_1_0_DB }, | ||
439 | { 1500, IMX6Q_GPR13_SATA_RX_EQ_VAL_1_5_DB }, | ||
440 | { 2000, IMX6Q_GPR13_SATA_RX_EQ_VAL_2_0_DB }, | ||
441 | { 2500, IMX6Q_GPR13_SATA_RX_EQ_VAL_2_5_DB }, | ||
442 | { 3000, IMX6Q_GPR13_SATA_RX_EQ_VAL_3_0_DB }, | ||
443 | { 3500, IMX6Q_GPR13_SATA_RX_EQ_VAL_3_5_DB }, | ||
444 | { 4000, IMX6Q_GPR13_SATA_RX_EQ_VAL_4_0_DB }, | ||
445 | }; | ||
446 | |||
447 | static const struct reg_property gpr13_props[] = { | ||
448 | { | ||
449 | .name = "fsl,transmit-level-mV", | ||
450 | .values = gpr13_tx_level, | ||
451 | .num_values = ARRAY_SIZE(gpr13_tx_level), | ||
452 | .def_value = IMX6Q_GPR13_SATA_TX_LVL_1_025_V, | ||
453 | }, { | ||
454 | .name = "fsl,transmit-boost-mdB", | ||
455 | .values = gpr13_tx_boost, | ||
456 | .num_values = ARRAY_SIZE(gpr13_tx_boost), | ||
457 | .def_value = IMX6Q_GPR13_SATA_TX_BOOST_3_33_DB, | ||
458 | }, { | ||
459 | .name = "fsl,transmit-atten-16ths", | ||
460 | .values = gpr13_tx_atten, | ||
461 | .num_values = ARRAY_SIZE(gpr13_tx_atten), | ||
462 | .def_value = IMX6Q_GPR13_SATA_TX_ATTEN_9_16, | ||
463 | }, { | ||
464 | .name = "fsl,receive-eq-mdB", | ||
465 | .values = gpr13_rx_eq, | ||
466 | .num_values = ARRAY_SIZE(gpr13_rx_eq), | ||
467 | .def_value = IMX6Q_GPR13_SATA_RX_EQ_VAL_3_0_DB, | ||
468 | }, | ||
469 | }; | ||
470 | |||
471 | static u32 imx_ahci_parse_props(struct device *dev, | ||
472 | const struct reg_property *prop, size_t num) | ||
473 | { | ||
474 | struct device_node *np = dev->of_node; | ||
475 | u32 reg_value = 0; | ||
476 | int i, j; | ||
477 | |||
478 | for (i = 0; i < num; i++, prop++) { | ||
479 | u32 of_val; | ||
480 | |||
481 | if (of_property_read_u32(np, prop->name, &of_val)) { | ||
482 | dev_info(dev, "%s not specified, using %08x\n", | ||
483 | prop->name, prop->def_value); | ||
484 | reg_value |= prop->def_value; | ||
485 | continue; | ||
486 | } | ||
487 | |||
488 | for (j = 0; j < prop->num_values; j++) { | ||
489 | if (prop->values[j].of_value == of_val) { | ||
490 | dev_info(dev, "%s value %u, using %08x\n", | ||
491 | prop->name, of_val, prop->values[j].reg_value); | ||
492 | reg_value |= prop->values[j].reg_value; | ||
493 | break; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | if (j == prop->num_values) { | ||
498 | dev_err(dev, "DT property %s is not a valid value\n", | ||
499 | prop->name); | ||
500 | reg_value |= prop->def_value; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | return reg_value; | ||
505 | } | ||
506 | |||
367 | static int imx_ahci_probe(struct platform_device *pdev) | 507 | static int imx_ahci_probe(struct platform_device *pdev) |
368 | { | 508 | { |
369 | struct device *dev = &pdev->dev; | 509 | struct device *dev = &pdev->dev; |
@@ -392,6 +532,8 @@ static int imx_ahci_probe(struct platform_device *pdev) | |||
392 | } | 532 | } |
393 | 533 | ||
394 | if (imxpriv->type == AHCI_IMX6Q) { | 534 | if (imxpriv->type == AHCI_IMX6Q) { |
535 | u32 reg_value; | ||
536 | |||
395 | imxpriv->gpr = syscon_regmap_lookup_by_compatible( | 537 | imxpriv->gpr = syscon_regmap_lookup_by_compatible( |
396 | "fsl,imx6q-iomuxc-gpr"); | 538 | "fsl,imx6q-iomuxc-gpr"); |
397 | if (IS_ERR(imxpriv->gpr)) { | 539 | if (IS_ERR(imxpriv->gpr)) { |
@@ -399,6 +541,16 @@ static int imx_ahci_probe(struct platform_device *pdev) | |||
399 | "failed to find fsl,imx6q-iomux-gpr regmap\n"); | 541 | "failed to find fsl,imx6q-iomux-gpr regmap\n"); |
400 | return PTR_ERR(imxpriv->gpr); | 542 | return PTR_ERR(imxpriv->gpr); |
401 | } | 543 | } |
544 | |||
545 | reg_value = imx_ahci_parse_props(dev, gpr13_props, | ||
546 | ARRAY_SIZE(gpr13_props)); | ||
547 | |||
548 | imxpriv->phy_params = | ||
549 | IMX6Q_GPR13_SATA_RX_LOS_LVL_SATA2M | | ||
550 | IMX6Q_GPR13_SATA_RX_DPLL_MODE_2P_4F | | ||
551 | IMX6Q_GPR13_SATA_SPD_MODE_3P0G | | ||
552 | IMX6Q_GPR13_SATA_MPLL_SS_EN | | ||
553 | reg_value; | ||
402 | } | 554 | } |
403 | 555 | ||
404 | hpriv = ahci_platform_get_resources(pdev); | 556 | hpriv = ahci_platform_get_resources(pdev); |