at86rf230: support for xtal trim and irq fixes
Subsystems (4)
Alexander Aring
maintainerv5 cover at86rf230: support for xtal trim and irq fixes
Hi,
I moved the xtal_trim calculation example of available free schematics hardware transceivers into the source code now.
While testing I experience some issues with interrupt handling. The reason was an edge triggered interrupt gpio. To protect the IRQ resources we have a disable_irq <-> enable_irq path in our irq handler. If edge triggered and we get an irq while the irq is disabled the transceiver stucks in a state. The solution was to change from edge triggered irq to high-level irq, this will solve the issue and the irq will fire after calling enable_irq.
That's the reason why we should prever a high-level triggered gpio irq type, our current implementation can't handle edge triggered irq right now. I added some patches to printout a warning if a edge triggered irq is set.
- Alex
changes since v5:
- move note about xtal_trim value to driver code
- add patch to remove tx_timeout
- add patch for irqmask mode setting
- add patch for handling low-level irq polarity
- add patch for adding warning for edge triggered irq types
changes since v4:
- remove platform data from at86rf230_local
- add note in cover-letter because at86rf2xx have different xtal_mode values
changes since v3:
- remove setting of xtal_mode. Instead we setting xtal_trim only.
changes since v2:
- copy platform data to driver allocated space
Alexander Aring (6):
at86rf230: copy pdata to driver allocated space
at86rf230: add support for external xtal trim
at86rf230: remove tx_timeout
at86rf230: add irqmask mode setting
at86rf230: add irq low-level for polarity
at86rf230: add warning if edge-triggered irq
.../bindings/net/ieee802154/at86rf230.txt | 8 +- drivers/net/ieee802154/at86rf230.c | 118 +++++++++++++++------ include/linux/spi/at86rf230.h | 1 + 3 files changed, 91 insertions(+), 36 deletions(-)
Signature · 1 line
2.3.0
Alexander Aring
maintainerPATCH v5 1/6 at86rf230: copy pdata to driver allocated space
This patch copies the platform data in driver allocated space at first. With this change we ensure that we access the allocated platform data as readonly space.
--- drivers/net/ieee802154/at86rf230.c | 51 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 26 deletions(-)
drivers/net/ieee802154/at86rf230.c +25 -26
@@ -1377,24 +1377,24 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)return at86rf230_write_subreg (lp,SR_SLOTTED_OPERATION ,0 ); } -static struct at86rf230_platform_data * -at86rf230_get_pdata (struct spi_device *spi) +static int +at86rf230_get_pdata (struct spi_device *spi,int *rstn,int *slp_tr) { -struct at86rf230_platform_data *pdata; +struct at86rf230_platform_data *pdata = spi->dev.platform_data; -if (!IS_ENABLED (CONFIG_OF ) || !spi->dev.of_node) -return spi->dev.platform_data; +if (!IS_ENABLED (CONFIG_OF ) || !spi->dev.of_node) { +if (!pdata) +return -ENOENT ; - pdata =devm_kzalloc (&spi->dev,sizeof (*pdata),GFP_KERNEL ); -if (!pdata) - goto done; + *rstn = pdata->rstn; + *slp_tr = pdata->slp_tr; +return 0 ; + } - pdata->rstn =of_get_named_gpio (spi->dev.of_node,"reset-gpio" ,0 ); - pdata->slp_tr =of_get_named_gpio (spi->dev.of_node,"sleep-gpio" ,0 ); + *rstn =of_get_named_gpio (spi->dev.of_node,"reset-gpio" ,0 ); + *slp_tr =of_get_named_gpio (spi->dev.of_node,"sleep-gpio" ,0 ); - spi->dev.platform_data = pdata; -done: -return pdata; +return 0 ; } static int
@@ -1501,43 +1501,42 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)static int at86rf230_probe (struct spi_device *spi) { -struct at86rf230_platform_data *pdata;struct ieee802154_hw *hw;struct at86rf230_local *lp;unsigned int status; -int rc, irq_type; +int rc, irq_type, rstn, slp_tr;if (!spi->irq) {dev_err (&spi->dev,"no IRQ specified\n" );return -EINVAL ; } - pdata =at86rf230_get_pdata (spi); -if (!pdata) { -dev_err (&spi->dev,"no platform_data\n" ); -return -EINVAL ; + rc =at86rf230_get_pdata (spi, &rstn, &slp_tr); +if (rc <0 ) { +dev_err (&spi->dev,"failed to parse platform_data: %d\n" , rc); +return rc; } -if (gpio_is_valid (pdata->rstn)) { - rc =devm_gpio_request_one (&spi->dev, pdata->rstn, +if (gpio_is_valid (rstn)) { + rc =devm_gpio_request_one (&spi->dev, rstn,GPIOF_OUT_INIT_HIGH ,"rstn" );if (rc)return rc; } -if (gpio_is_valid (pdata->slp_tr)) { - rc =devm_gpio_request_one (&spi->dev, pdata->slp_tr, +if (gpio_is_valid (slp_tr)) { + rc =devm_gpio_request_one (&spi->dev, slp_tr,GPIOF_OUT_INIT_LOW ,"slp_tr" );if (rc)return rc; }/* Reset */ -if (gpio_is_valid (pdata->rstn)) { +if (gpio_is_valid (rstn)) {udelay (1 ); -gpio_set_value (pdata->rstn,0 ); +gpio_set_value (rstn,0 );udelay (1 ); -gpio_set_value (pdata->rstn,1 ); +gpio_set_value (rstn,1 );usleep_range (120 ,240 ); }
Signature · 1 line
2.3.0
Alexander Aring
maintainerPATCH v5 2/6 at86rf230: add support for external xtal trim
In reply to Alexander AringThis patch adds support for setting the xtal trim register. Some at86rf2xx transceiver boards needs fine tuning the xtal capacitor.
--- .../bindings/net/ieee802154/at86rf230.txt | 3 ++ drivers/net/ieee802154/at86rf230.c | 54 ++++++++++++++++++++-- include/linux/spi/at86rf230.h | 1 + 3 files changed, 54 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt +3 -0
@@ -11,6 +11,8 @@ Required properties: Optional properties: - reset-gpio: GPIO spec for the rstn pin - sleep-gpio: GPIO spec for the slp_tr pin + - xtal-trim: u8 value for fine tuning the internal capacitance + arrays of xtal pins: 0 = +0 pF, 0xf = +4.5 pF Example:
@@ -20,4 +22,5 @@ Example: reg = <0>; interrupts = <19 1>; interrupt-parent = <&gpio3>; + xtal-trim = /bits/ 8 <0x06>; };
drivers/net/ieee802154/at86rf230.c +50 -4
103 lines not on this page · raw message
include/linux/spi/at86rf230.h +1 -0
@@ -22,6 +22,7 @@ struct at86rf230_platform_data {int rstn;int slp_tr;int dig2; + u8 xtal_trim; };#endif
Signature · 1 line
2.3.0
Alexander Aring
maintainerPATCH v5 3/6 at86rf230: remove tx_timeout
In reply to Alexander AringThis patch removes tx_timeout handling. We used it in sync xmit handling. Since we support async xmit handling a xmit timeout handling isn't easy to implement and should be implemented by netdev watchdog mechanism.
--- drivers/net/ieee802154/at86rf230.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/net/ieee802154/at86rf230.c +0 -5
@@ -46,8 +46,6 @@ struct at86rf2xx_chip_data {u16 t_off_to_tx_on;u16 t_frame;u16 t_p_ack; -/* completion timeout for tx in msecs */ -u16 t_tx_timeout;int rssi_base_val;int (*set_channel)(struct at86rf230_local *,u8 ,u8 );
@@ -1281,7 +1279,6 @@ static struct at86rf2xx_chip_data at86rf233_data = { .t_off_to_tx_on = 80, .t_frame = 4096, .t_p_ack = 545, - .t_tx_timeout = 2000, .rssi_base_val = -91, .set_channel = at86rf23x_set_channel, .get_desense_steps = at86rf23x_get_desens_steps
@@ -1295,7 +1292,6 @@ static struct at86rf2xx_chip_data at86rf231_data = { .t_off_to_tx_on = 110, .t_frame = 4096, .t_p_ack = 545, - .t_tx_timeout = 2000, .rssi_base_val = -91, .set_channel = at86rf23x_set_channel, .get_desense_steps = at86rf23x_get_desens_steps
@@ -1309,7 +1305,6 @@ static struct at86rf2xx_chip_data at86rf212_data = { .t_off_to_tx_on = 200, .t_frame = 4096, .t_p_ack = 545, - .t_tx_timeout = 2000, .rssi_base_val = -100, .set_channel = at86rf212_set_channel, .get_desense_steps = at86rf212_get_desens_steps
Signature · 1 line
2.3.0
Alexander Aring
maintainerPATCH v5 4/6 at86rf230: add irqmask mode setting
In reply to Alexander AringSince we support at86rf233 we need to ensure that basic operation default values are the same. This patch always sets IRQ_MASK_MODE to 0 which is after reset 1 at the at86rf233 and 0 at the at86rf231.
--- drivers/net/ieee802154/at86rf230.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ieee802154/at86rf230.c +5 -0
@@ -1336,6 +1336,11 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)if (rc)return rc; +/* reset values differs in at86rf231 and at86rf233 */ + rc =at86rf230_write_subreg (lp,SR_IRQ_MASK_MODE ,0 ); +if (rc) +return rc; +get_random_bytes (csma_seed,ARRAY_SIZE (csma_seed)); rc =at86rf230_write_subreg (lp,SR_CSMA_SEED_0 , csma_seed[0 ]);if (rc)
Signature · 1 line
2.3.0
Alexander Aring
maintainerPATCH v5 5/6 at86rf230: add irq low-level for polarity
In reply to Alexander AringThe at86rf2xx chips supports the setting of irq polarity if active low or active high. This patch adds a handling for IRQ_ACTIVE_LOW if the irq_type is IRQ_TYPE_LEVEL_LOW.
--- drivers/net/ieee802154/at86rf230.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ieee802154/at86rf230.c +2 -1
@@ -1321,7 +1321,8 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)return rc; irq_type =irq_get_trigger_type (lp->spi->irq); -if (irq_type ==IRQ_TYPE_EDGE_FALLING ) +if (irq_type ==IRQ_TYPE_EDGE_FALLING || + irq_type ==IRQ_TYPE_LEVEL_LOW ) irq_pol =IRQ_ACTIVE_LOW ; rc =at86rf230_write_subreg (lp,SR_IRQ_POLARITY , irq_pol);
Signature · 1 line
2.3.0
Alexander Aring
maintainerPATCH v5 6/6 at86rf230: add warning if edge-triggered irq
In reply to Alexander AringWhile testing I experience a deadlock while using the at86rf233 on a raspberry pi. The reason was an edge triggered gpio irq because the irq triggered while irq was disabled. This issue doesn't happend on a level triggered irq because the irq will hit after calling enable_irq.
This patch adds a warning that it's not recommended to use a edge-triggered irq type. Also change the examples to high-level irqtype.
--- Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt | 5 +++-- drivers/net/ieee802154/at86rf230.c | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt +3 -2
@@ -6,7 +6,8 @@ Required properties: - spi-max-frequency: maximal bus speed, should be set to 7500000 depends sync or async operation mode - reg: the chipselect index - - interrupts: the interrupt generated by the device + - interrupts: the interrupt generated by the device. Non high-level + can occur deadlocks while handling isr. Optional properties: - reset-gpio: GPIO spec for the rstn pin
@@ -20,7 +21,7 @@ Example: compatible = "atmel,at86rf231"; spi-max-frequency = <7500000>; reg = <0>; - interrupts = <19 1>; + interrupts = <19 4>; interrupt-parent = <&gpio3>; xtal-trim = /bits/ 8 <0x06>; };
drivers/net/ieee802154/at86rf230.c +4 -0
@@ -1321,6 +1321,10 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)return rc; irq_type =irq_get_trigger_type (lp->spi->irq); +if (irq_type ==IRQ_TYPE_EDGE_RISING || + irq_type ==IRQ_TYPE_EDGE_FALLING ) +dev_warn (&lp->spi->dev, +"Using edge triggered irq's are not recommended!\n" );if (irq_type ==IRQ_TYPE_EDGE_FALLING || irq_type ==IRQ_TYPE_LEVEL_LOW ) irq_pol =IRQ_ACTIVE_LOW ;
Signature · 1 line
2.3.0
Hi Alex,
Quoted 44 lines
I moved the
xtal_trimcalculation example of available free schematics hardware transceivers into the source code now.While testing I experience some issues with interrupt handling. The reason was an edge triggered interrupt gpio. To protect the IRQ resources we have a
disable_irq<->enable_irqpath in our irq handler. If edge triggered and we get an irq while the irq is disabled the transceiver stucks in a state. The solution was to change from edge triggered irq to high-level irq, this will solve the issue and the irq will fire after callingenable_irq.That's the reason why we should prever a high-level triggered gpio irq type, our current implementation can't handle edge triggered irq right now. I added some patches to printout a warning if a edge triggered irq is set.
- Alex
changes since v5:
- move note aboutxtal_trimvalue to driver code
- add patch to removetx_timeout
- add patch for irqmask mode setting
- add patch for handling low-level irq polarity
- add patch for adding warning for edge triggered irq typeschanges since v4:
- remove platform data fromat86rf230_local
- add note in cover-letter because at86rf2xx have differentxtal_modevalueschanges since v3:
- remove setting ofxtal_mode. Instead we settingxtal_trimonly.changes since v2:
- copy platform data to driver allocated spaceCc Werner Almesberger <[email protected]>Cc Thomas Stilwell <[email protected]>Alexander Aring (6):
at86rf230: copy pdata to driver allocated space
at86rf230: add support for external xtal trim
at86rf230: removetx_timeout
at86rf230: add irqmask mode setting
at86rf230: add irq low-level for polarity
at86rf230: add warning if edge-triggered irq
Quoted 4 lines
.../bindings/net/ieee802154/at86rf230.txt | 8 +- drivers/net/ieee802154/at86rf230.c | 118 +++++++++++++++------ include/linux/spi/at86rf230.h | 1 + 3 files changed, 91 insertions(+), 36 deletions(-)
all 6 patches have been applied to bluetooth-next tree.
Regards
Marcel