aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Aring <alex.aring@gmail.com>2015-02-27 03:58:26 -0500
committerMarcel Holtmann <marcel@holtmann.org>2015-02-27 12:42:44 -0500
commitccdaeb2b176f7db491a6f8e8b1c51f9393525f7d (patch)
tree5c7b8e5af1c70b0008fe37257acdee8e3122db81
parentaaa1c4d226e4cd730075d3dac99a6d599a0190c7 (diff)
at86rf230: add support for external xtal trim
This patch adds support for setting the xtal trim register. Some at86rf2xx transceiver boards needs fine tuning the xtal capacitor. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt3
-rw-r--r--drivers/net/ieee802154/at86rf230.c54
-rw-r--r--include/linux/spi/at86rf230.h1
3 files changed, 54 insertions, 4 deletions
diff --git a/Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt b/Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt
index d3bbdded4cbe..1ae5100fea14 100644
--- a/Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt
+++ b/Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt
@@ -11,6 +11,8 @@ Required properties:
11Optional properties: 11Optional properties:
12 - reset-gpio: GPIO spec for the rstn pin 12 - reset-gpio: GPIO spec for the rstn pin
13 - sleep-gpio: GPIO spec for the slp_tr pin 13 - sleep-gpio: GPIO spec for the slp_tr pin
14 - xtal-trim: u8 value for fine tuning the internal capacitance
15 arrays of xtal pins: 0 = +0 pF, 0xf = +4.5 pF
14 16
15Example: 17Example:
16 18
@@ -20,4 +22,5 @@ Example:
20 reg = <0>; 22 reg = <0>;
21 interrupts = <19 1>; 23 interrupts = <19 1>;
22 interrupt-parent = <&gpio3>; 24 interrupt-parent = <&gpio3>;
25 xtal-trim = /bits/ 8 <0x06>;
23 }; 26 };
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 9888b7ff24bc..c1323e5cdd0c 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1315,7 +1315,7 @@ static struct at86rf2xx_chip_data at86rf212_data = {
1315 .get_desense_steps = at86rf212_get_desens_steps 1315 .get_desense_steps = at86rf212_get_desens_steps
1316}; 1316};
1317 1317
1318static int at86rf230_hw_init(struct at86rf230_local *lp) 1318static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)
1319{ 1319{
1320 int rc, irq_type, irq_pol = IRQ_ACTIVE_HIGH; 1320 int rc, irq_type, irq_pol = IRQ_ACTIVE_HIGH;
1321 unsigned int dvdd; 1321 unsigned int dvdd;
@@ -1362,6 +1362,45 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
1362 usleep_range(lp->data->t_sleep_cycle, 1362 usleep_range(lp->data->t_sleep_cycle,
1363 lp->data->t_sleep_cycle + 100); 1363 lp->data->t_sleep_cycle + 100);
1364 1364
1365 /* xtal_trim value is calculated by:
1366 * CL = 0.5 * (CX + CTRIM + CPAR)
1367 *
1368 * whereas:
1369 * CL = capacitor of used crystal
1370 * CX = connected capacitors at xtal pins
1371 * CPAR = in all at86rf2xx datasheets this is a constant value 3 pF,
1372 * but this is different on each board setup. You need to fine
1373 * tuning this value via CTRIM.
1374 * CTRIM = variable capacitor setting. Resolution is 0.3 pF range is
1375 * 0 pF upto 4.5 pF.
1376 *
1377 * Examples:
1378 * atben transceiver:
1379 *
1380 * CL = 8 pF
1381 * CX = 12 pF
1382 * CPAR = 3 pF (We assume the magic constant from datasheet)
1383 * CTRIM = 0.9 pF
1384 *
1385 * (12+0.9+3)/2 = 7.95 which is nearly at 8 pF
1386 *
1387 * xtal_trim = 0x3
1388 *
1389 * openlabs transceiver:
1390 *
1391 * CL = 16 pF
1392 * CX = 22 pF
1393 * CPAR = 3 pF (We assume the magic constant from datasheet)
1394 * CTRIM = 4.5 pF
1395 *
1396 * (22+4.5+3)/2 = 14.75 which is the nearest value to 16 pF
1397 *
1398 * xtal_trim = 0xf
1399 */
1400 rc = at86rf230_write_subreg(lp, SR_XTAL_TRIM, xtal_trim);
1401 if (rc)
1402 return rc;
1403
1365 rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd); 1404 rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd);
1366 if (rc) 1405 if (rc)
1367 return rc; 1406 return rc;
@@ -1378,9 +1417,11 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
1378} 1417}
1379 1418
1380static int 1419static int
1381at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr) 1420at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr,
1421 u8 *xtal_trim)
1382{ 1422{
1383 struct at86rf230_platform_data *pdata = spi->dev.platform_data; 1423 struct at86rf230_platform_data *pdata = spi->dev.platform_data;
1424 int ret;
1384 1425
1385 if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) { 1426 if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) {
1386 if (!pdata) 1427 if (!pdata)
@@ -1388,11 +1429,15 @@ at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr)
1388 1429
1389 *rstn = pdata->rstn; 1430 *rstn = pdata->rstn;
1390 *slp_tr = pdata->slp_tr; 1431 *slp_tr = pdata->slp_tr;
1432 *xtal_trim = pdata->xtal_trim;
1391 return 0; 1433 return 0;
1392 } 1434 }
1393 1435
1394 *rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); 1436 *rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
1395 *slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0); 1437 *slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
1438 ret = of_property_read_u8(spi->dev.of_node, "xtal-trim", xtal_trim);
1439 if (ret < 0 && ret != -EINVAL)
1440 return ret;
1396 1441
1397 return 0; 1442 return 0;
1398} 1443}
@@ -1505,13 +1550,14 @@ static int at86rf230_probe(struct spi_device *spi)
1505 struct at86rf230_local *lp; 1550 struct at86rf230_local *lp;
1506 unsigned int status; 1551 unsigned int status;
1507 int rc, irq_type, rstn, slp_tr; 1552 int rc, irq_type, rstn, slp_tr;
1553 u8 xtal_trim;
1508 1554
1509 if (!spi->irq) { 1555 if (!spi->irq) {
1510 dev_err(&spi->dev, "no IRQ specified\n"); 1556 dev_err(&spi->dev, "no IRQ specified\n");
1511 return -EINVAL; 1557 return -EINVAL;
1512 } 1558 }
1513 1559
1514 rc = at86rf230_get_pdata(spi, &rstn, &slp_tr); 1560 rc = at86rf230_get_pdata(spi, &rstn, &slp_tr, &xtal_trim);
1515 if (rc < 0) { 1561 if (rc < 0) {
1516 dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc); 1562 dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc);
1517 return rc; 1563 return rc;
@@ -1570,7 +1616,7 @@ static int at86rf230_probe(struct spi_device *spi)
1570 1616
1571 spi_set_drvdata(spi, lp); 1617 spi_set_drvdata(spi, lp);
1572 1618
1573 rc = at86rf230_hw_init(lp); 1619 rc = at86rf230_hw_init(lp, xtal_trim);
1574 if (rc) 1620 if (rc)
1575 goto free_dev; 1621 goto free_dev;
1576 1622
diff --git a/include/linux/spi/at86rf230.h b/include/linux/spi/at86rf230.h
index cd519a11c2c6..b63fe6f5fdc8 100644
--- a/include/linux/spi/at86rf230.h
+++ b/include/linux/spi/at86rf230.h
@@ -22,6 +22,7 @@ struct at86rf230_platform_data {
22 int rstn; 22 int rstn;
23 int slp_tr; 23 int slp_tr;
24 int dig2; 24 int dig2;
25 u8 xtal_trim;
25}; 26};
26 27
27#endif 28#endif