Adding DT support for TI HECC module
Subsystems (2)
v4 cover Adding DT support for TI HECC module
From: Yegor Yefremov <[email protected]>
This is an attempt to revive DT support for TI HECC that was started in 2015 [1].
Changes v3 -> v4:
- implement tranciever handling via regulator API (suggested by Marc Kleine-Budde)
- convert the driver to DT only driver, i.e. remove legacy platform struct and header (suggested by Marc Kleine-Budde)
Changes v2 -> v3:
- rename compatible property to "ti,am3517-hecc" (though there is a stipped device named 3505, EMAC driver already uses am3517-emac name, so keep this property consistent)
- use reg-names to specify different HECC I/O mapping (suggested by Tony Lindgren)
- provide fallback offsets and sizes for board files
- convert optional property ti,int_line to ti,use-hecc1int and add proper description
Changes v1 -> v2:
- change compatible to "ti,am3505
- remove CONFIG_OF
- don't set int_line to 0 explicitly
[1] http://comments.gmane.org/gmane.linux.can/8616
Yegor Yefremov (3):
ARM: dts: AM35x: Add hecc node
can: ti_hecc: Add TI HECC DT binding documentation
can: ti_hecc: Add DT support for TI HECC module
.../devicetree/bindings/net/can/ti_hecc.txt | 33 ++++ arch/arm/boot/dts/am3517.dtsi | 12 ++ drivers/net/can/ti_hecc.c | 166 +++++++++++---------- include/linux/can/platform/ti_hecc.h | 44 ------ 4 files changed, 133 insertions(+), 122 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/can/ti_hecc.txt delete mode 100644 include/linux/can/platform/ti_hecc.h
Signature · 1 line
2.1.4
A message that is not in the archive (sent off-list or not yet received): 1487339158-18809-1-git-send-email-yegorslists-gM/[email protected]
PATCH v4 1/3 ARM: dts: AM35x: Add hecc node
From: Yegor Yefremov <yegorslists-gM/[email protected]>
HECC node description for am35x SOCs
--- arch/arm/boot/dts/am3517.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/arm/boot/dts/am3517.dtsi +12 -0
@@ -13,6 +13,7 @@ / { aliases { serial3 = &uart4; + can = &hecc; }; ocp@68000000 {
@@ -72,6 +73,17 @@ pinctrl-single,register-width = <16>; pinctrl-single,function-mask = <0xff1f>; }; + + hecc: can@5c050000 { + compatible = "ti,am3517-hecc"; + status = "disabled"; + reg = <0x5c050000 0x80>, + <0x5c053000 0x180>, + <0x5c052000 0x200>; + reg-names = "hecc", "hecc-ram", "mbx"; + interrupts = <24>; + clocks = <&hecc_ck>; + }; }; };
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 3/3 can: ti_hecc: Add DT support for TI HECC module
In reply to a message not in the archiveFrom: Yegor Yefremov <yegorslists-gM/[email protected]>
This patch converts TI HECC driver to DT only driver. This results in removing ti_hecc.h containing now obsolete platform data.
Former transceiver_switch callback function will be now modelled via regulator API.
--- drivers/net/can/ti_hecc.c | 166 +++++++++++++++++++---------------- include/linux/can/platform/ti_hecc.h | 44 ---------- 2 files changed, 88 insertions(+), 122 deletions(-) delete mode 100644 include/linux/can/platform/ti_hecc.h
drivers/net/can/ti_hecc.c +88 -78
@@ -17,25 +17,6 @@* */ -/* -* Your platform definitions should specify module ram offsets and interrupt -* number to use as follows: -* -* static struct ti_hecc_platform_data am3517_evm_hecc_pdata = { -* .scc_hecc_offset = 0, -* .scc_ram_offset = 0x3000, -* .hecc_ram_offset = 0x3000, -* .mbx_offset = 0x2000, -* .int_line = 0, -* .revision = 1, -* .transceiver_switch = hecc_phy_control, -* }; -* -* Please see include/linux/can/platform/ti_hecc.h for description of -* above fields. -* -*/ -#include <linux/module.h> #include <linux/kernel.h> #include <linux/types.h>
@@ -46,11 +27,13 @@#include <linux/platform_device.h> #include <linux/clk.h> #include <linux/io.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/regulator/consumer.h> #include <linux/can/dev.h> #include <linux/can/error.h> #include <linux/can/led.h> -#include <linux/can/platform/ti_hecc.h> #define DRV_NAME "ti_hecc"#define HECC_MODULE_VERSION "0.7"
@@ -214,15 +197,14 @@ struct ti_hecc_priv {struct net_device *ndev;struct clk *clk;void __iomem *base; -u32 scc_ram_offset; -u32 hecc_ram_offset; -u32 mbx_offset; -u32 int_line; +void __iomem *hecc_ram; +void __iomem *mbx; +bool use_hecc1int;spinlock_t mbx_lock;/* CANME register needs protection */ u32 tx_head;u32 tx_tail;u32 rx_next; -void (*transceiver_switch)(int ); +struct regulator *reg_xceiver; };static inline int get_tx_head_mb (struct ti_hecc_priv *priv)
@@ -242,20 +224,18 @@ static inline int get_tx_head_prio(struct ti_hecc_priv *priv)static inline void hecc_write_lam (struct ti_hecc_priv *priv,u32 mbxno,u32 val) { -__raw_writel (val, priv->base + priv->hecc_ram_offset + mbxno *4 ); +__raw_writel (val, priv->hecc_ram + mbxno *4 ); }static inline void hecc_write_mbx (struct ti_hecc_priv *priv,u32 mbxno,u32 reg,u32 val) { -__raw_writel (val, priv->base + priv->mbx_offset + mbxno *0x10 + - reg); +__raw_writel (val, priv->mbx + mbxno *0x10 + reg); }static inline u32 hecc_read_mbx (struct ti_hecc_priv *priv,u32 mbxno,u32 reg) { -return __raw_readl (priv->base + priv->mbx_offset + mbxno *0x10 + - reg); +return __raw_readl (priv->mbx + mbxno *0x10 + reg); }static inline void hecc_write (struct ti_hecc_priv *priv,u32 reg,u32 val)
@@ -311,11 +291,16 @@ static int ti_hecc_set_btc(struct ti_hecc_priv *priv)return 0 ; } -static void ti_hecc_transceiver_switch (const struct ti_hecc_priv *priv, -int on) +static int ti_hecc_transceiver_switch (const struct ti_hecc_priv *priv, +int on) { -if (priv->transceiver_switch) - priv->transceiver_switch (on); +if (!priv->reg_xceiver) +return 0 ; + +if (on) +return regulator_enable (priv->reg_xceiver); +else +return regulator_disable (priv->reg_xceiver); }static void ti_hecc_reset (struct net_device *ndev)
@@ -409,7 +394,7 @@ static void ti_hecc_start(struct net_device *ndev)/* Prevent message over-write & Enable interrupts */ hecc_write (priv,HECC_CANOPC ,HECC_SET_REG ); -if (priv->int_line) { +if (priv->use_hecc1int) {hecc_write (priv,HECC_CANMIL ,HECC_SET_REG );hecc_write (priv,HECC_CANGIM ,HECC_CANGIM_DEF_MASK |HECC_CANGIM_I1EN |HECC_CANGIM_SIL );
@@ -760,7 +745,7 @@ static irqreturn_t ti_hecc_interrupt(int irq, void *dev_id)unsigned long ack, flags; int_status =hecc_read (priv, - (priv->int_line) ?HECC_CANGIF1 :HECC_CANGIF0 ); + (priv->use_hecc1int) ?HECC_CANGIF1 :HECC_CANGIF0 );if (!int_status)return IRQ_NONE ;
@@ -806,7 +791,7 @@ static irqreturn_t ti_hecc_interrupt(int irq, void *dev_id) }/* clear all interrupt conditions - read back to avoid spurious ints */ -if (priv->int_line) { +if (priv->use_hecc1int) {hecc_write (priv,HECC_CANGIF1 ,HECC_SET_REG ); int_status =hecc_read (priv,HECC_CANGIF1 ); }else {
@@ -872,58 +857,87 @@ static const struct net_device_ops ti_hecc_netdev_ops = { .ndo_change_mtu = can_change_mtu, }; +static const struct of_device_id ti_hecc_dt_ids[] = { + { + .compatible ="ti,am3517-hecc" , + }, + { } +}; +MODULE_DEVICE_TABLE (of, ti_hecc_dt_ids); +static int ti_hecc_probe (struct platform_device *pdev) {struct net_device *ndev = (struct net_device *)0 ;struct ti_hecc_priv *priv; -struct ti_hecc_platform_data *pdata; -struct resource *mem, *irq; -void __iomem *addr; +struct device_node *np = pdev->dev.of_node; +struct resource *res, *irq; +struct regulator *reg_xceiver;int err = -ENODEV ; - pdata =dev_get_platdata (&pdev->dev); -if (!pdata) { -dev_err (&pdev->dev,"No platform data\n" ); - goto probe_exit; +if (!IS_ENABLED (CONFIG_OF ) || !np) +return -EINVAL ; + + reg_xceiver =devm_regulator_get (&pdev->dev,"xceiver" ); +if (PTR_ERR (reg_xceiver) == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +else if (IS_ERR (reg_xceiver)) + reg_xceiver =NULL ; + + ndev =alloc_candev (sizeof (struct ti_hecc_priv ),HECC_MAX_TX_MBOX ); +if (!ndev) { +dev_err (&pdev->dev,"alloc_candev failed\n" ); +return -ENOMEM ; } + priv =netdev_priv (ndev); - mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!mem) { -dev_err (&pdev->dev,"No mem resources\n" ); - goto probe_exit; +/* handle hecc memory */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"hecc" ); +if (!res) { +dev_err (&pdev->dev,"can't get IORESOURCE_MEM hecc\n" ); +return -EINVAL ; } - irq =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); -if (!irq) { -dev_err (&pdev->dev,"No irq resource\n" ); - goto probe_exit; + + priv->base =devm_ioremap_resource (&pdev->dev, res); +if (!priv->base) { +dev_err (&pdev->dev,"hecc ioremap failed\n" ); +return -ENOMEM ; } -if (!request_mem_region (mem->start,resource_size (mem), pdev->name)) { -dev_err (&pdev->dev,"HECC region already claimed\n" ); - err = -EBUSY ; - goto probe_exit; + +/* handle hecc-ram memory */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"hecc-ram" ); +if (!res) { +dev_err (&pdev->dev,"can't get IORESOURCE_MEM hecc-ram\n" ); +return -EINVAL ; } - addr =ioremap (mem->start,resource_size (mem)); -if (!addr) { -dev_err (&pdev->dev,"ioremap failed\n" ); - err = -ENOMEM ; - goto probe_exit_free_region; + + priv->hecc_ram =devm_ioremap_resource (&pdev->dev, res); +if (!priv->hecc_ram) { +dev_err (&pdev->dev,"hecc-ram ioremap failed\n" ); +return -ENOMEM ; } - ndev =alloc_candev (sizeof (struct ti_hecc_priv ),HECC_MAX_TX_MBOX ); -if (!ndev) { -dev_err (&pdev->dev,"alloc_candev failed\n" ); - err = -ENOMEM ; - goto probe_exit_iounmap; +/* handle mbx memory */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"mbx" ); +if (!res) { +dev_err (&pdev->dev,"can't get IORESOURCE_MEM mbx\n" ); +return -EINVAL ; + } + + priv->mbx =devm_ioremap_resource (&pdev->dev, res); +if (!priv->mbx) { +dev_err (&pdev->dev,"mbx ioremap failed\n" ); +return -ENOMEM ; + } + + irq =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!irq) { +dev_err (&pdev->dev,"No irq resource\n" ); + goto probe_exit; } - priv =netdev_priv (ndev); priv->ndev = ndev; - priv->base = addr; - priv->scc_ram_offset = pdata->scc_ram_offset; - priv->hecc_ram_offset = pdata->hecc_ram_offset; - priv->mbx_offset = pdata->mbx_offset; - priv->int_line = pdata->int_line; - priv->transceiver_switch = pdata->transceiver_switch; + priv->reg_xceiver = reg_xceiver; + priv->use_hecc1int =of_property_read_bool (np,"ti,use-hecc1int" ); priv->can.bittiming_const = &ti_hecc_bittiming_const; priv->can.do_set_mode = ti_hecc_do_set_mode;
@@ -971,10 +985,6 @@ static int ti_hecc_probe(struct platform_device *pdev)clk_put (priv->clk); probe_exit_candev:free_candev (ndev); -probe_exit_iounmap: -iounmap (addr); -probe_exit_free_region: -release_mem_region (mem->start,resource_size (mem)); probe_exit:return err; }
@@ -996,7 +1006,6 @@ static int ti_hecc_remove(struct platform_device *pdev)return 0 ; } -#ifdef CONFIG_PM static int ti_hecc_suspend (struct platform_device *pdev,pm_message_t state) {
@@ -1045,6 +1054,7 @@ static int ti_hecc_resume(struct platform_device *pdev)static struct platform_driver ti_hecc_driver = { .driver = { .name =DRV_NAME , + .of_match_table = ti_hecc_dt_ids, }, .probe = ti_hecc_probe, .remove = ti_hecc_remove,
include/linux/can/platform/ti_hecc.h deleted +0 -44
44 lines not on this page · raw message
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1487339158-18809-4-git-send-email-yegorslists-gM/[email protected]
Re: [PATCH v4 3/3] can: ti_hecc: Add DT support for TI HECC module
Quoted 10 lines · On 02/17/2017 02:45 PM, yegorslists-gM/[email protected]…
From: Yegor Yefremov <yegorslists-gM/[email protected]>
This patch converts TI HECC driver to DT only driver. This results in removing
ti_hecc.hcontaining now obsolete platform data.Former
transceiver_switchcallback function will be now modelled via regulator API.Signed-off-by Anton Glukhov <[email protected]>Signed-off-by Yegor Yefremov <yegorslists-gM/[email protected]>
What about ti_hecc_remove(struct platform_device *pdev)? - As you now are using devm_ some manual deallocations will go away.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
PATCH v4 2/3 can: ti_hecc: Add TI HECC DT binding documentation
In reply to [email protected]From: Yegor Yefremov <[email protected]>
DT binding documentation for TI High End CAN Controller
--- .../devicetree/bindings/net/can/ti_hecc.txt | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/can/ti_hecc.txt
Documentation/devicetree/bindings/net/can/ti_hecc.txt new file +33 -0
@@ -0,0 +1,33 @@ +Texas Instruments High End CAN Controller (HECC) +================================================ + +This file provides information, what the device node +for the hecc interface contains. + +Required properties: +- compatible: "ti,am3517-hecc" +- reg: addresses and lengths of the register spaces for 'hecc', 'hecc-ram' + and 'mbx' +- reg-names :"hecc", "hecc-ram", "mbx" +- interrupts: interrupt mapping for the hecc interrupts sources +- clocks: clock phandles (see clock bindings for details) + +Optional properties: +- ti,use-hecc1int: if provided configures HECC to produce all interrupts + on HECC1INT interrupt line. By default HECC0INT interrupt + line will be used. +- xceiver-supply: regulator that powers the CAN transceiver + +Example: + +For am3517evm board: + hecc: can@0x5c050000 { + compatible = "ti,am3517-hecc"; + status = "disabled"; + reg = <0x5c050000 0x80>, + <0x5c053000 0x180>, + <0x5c052000 0x200>; + reg-names = "hecc", "hecc-ram", "mbx"; + interrupts = <24>; + clocks = <&hecc_ck>; + };
Signature · 1 line
2.1.4