Commit b06b3992 authored by David S. Miller's avatar David S. Miller

Merge tag 'linux-can-next-for-5.4-20190903' of...

Merge tag 'linux-can-next-for-5.4-20190903' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next

Marc Kleine-Budde says:

====================
pull-request: can-next 2019-09-03

this is a pull request for net-next/master consisting of 15 patches.

The first patch is by Christer Beskow, targets the kvaser_pciefd driver
and fixes the PWM generator's frequency.

The next three patches are by Dan Murphy, the tcan4x5x is updated to use
a proper interrupts/interrupt-parent DT binding to specify the devices
IRQ line. Further the unneeded wake ups of the device is removed from
the driver.

A patch by me for the mcp25xx driver removes the deprecated board file
setup example. Three patches by Andy Shevchenko simplify clock handling,
update the driver from OF to device property API and simplify the
mcp251x_can_suspend() function.

The remaining 7 patches are by me and clean up checkpatch warnings in
the generic CAN device infrastructure.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f4d7c8e3 13ecee77
...@@ -10,8 +10,10 @@ Required properties: ...@@ -10,8 +10,10 @@ Required properties:
- #size-cells: 0 - #size-cells: 0
- spi-max-frequency: Maximum frequency of the SPI bus the chip can - spi-max-frequency: Maximum frequency of the SPI bus the chip can
operate at should be less than or equal to 18 MHz. operate at should be less than or equal to 18 MHz.
- data-ready-gpios: Interrupt GPIO for data and error reporting.
- device-wake-gpios: Wake up GPIO to wake up the TCAN device. - device-wake-gpios: Wake up GPIO to wake up the TCAN device.
- interrupt-parent: the phandle to the interrupt controller which provides
the interrupt.
- interrupts: interrupt specification for data-ready.
See Documentation/devicetree/bindings/net/can/m_can.txt for additional See Documentation/devicetree/bindings/net/can/m_can.txt for additional
required property details. required property details.
...@@ -30,7 +32,8 @@ tcan4x5x: tcan4x5x@0 { ...@@ -30,7 +32,8 @@ tcan4x5x: tcan4x5x@0 {
#size-cells = <1>; #size-cells = <1>;
spi-max-frequency = <10000000>; spi-max-frequency = <10000000>;
bosch,mram-cfg = <0x0 0 0 32 0 0 1 1>; bosch,mram-cfg = <0x0 0 0 32 0 0 1 1>;
data-ready-gpios = <&gpio1 14 GPIO_ACTIVE_LOW>; interrupt-parent = <&gpio1>;
interrupts = <14 GPIO_ACTIVE_LOW>;
device-state-gpios = <&gpio3 21 GPIO_ACTIVE_HIGH>; device-state-gpios = <&gpio3 21 GPIO_ACTIVE_HIGH>;
device-wake-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>; device-wake-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
reset-gpios = <&gpio1 27 GPIO_ACTIVE_LOW>; reset-gpios = <&gpio1 27 GPIO_ACTIVE_LOW>;
......
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
/* /* Copyright (C) 2005 Marc Kleine-Budde, Pengutronix
* Copyright (C) 2005 Marc Kleine-Budde, Pengutronix
* Copyright (C) 2006 Andrey Volkov, Varma Electronics * Copyright (C) 2006 Andrey Volkov, Varma Electronics
* Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com> * Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com>
*/ */
...@@ -62,8 +61,7 @@ EXPORT_SYMBOL_GPL(can_len2dlc); ...@@ -62,8 +61,7 @@ EXPORT_SYMBOL_GPL(can_len2dlc);
#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */ #define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
#define CAN_CALC_SYNC_SEG 1 #define CAN_CALC_SYNC_SEG 1
/* /* Bit-timing calculation derived from:
* Bit-timing calculation derived from:
* *
* Code based on LinCAN sources and H8S2638 project * Code based on LinCAN sources and H8S2638 project
* Copyright 2004-2006 Pavel Pisa - DCE FELK CVUT cz * Copyright 2004-2006 Pavel Pisa - DCE FELK CVUT cz
...@@ -75,7 +73,8 @@ EXPORT_SYMBOL_GPL(can_len2dlc); ...@@ -75,7 +73,8 @@ EXPORT_SYMBOL_GPL(can_len2dlc);
* registers of the CAN controller. You can find more information * registers of the CAN controller. You can find more information
* in the header file linux/can/netlink.h. * in the header file linux/can/netlink.h.
*/ */
static int can_update_sample_point(const struct can_bittiming_const *btc, static int
can_update_sample_point(const struct can_bittiming_const *btc,
unsigned int sample_point_nominal, unsigned int tseg, unsigned int sample_point_nominal, unsigned int tseg,
unsigned int *tseg1_ptr, unsigned int *tseg2_ptr, unsigned int *tseg1_ptr, unsigned int *tseg2_ptr,
unsigned int *sample_point_error_ptr) unsigned int *sample_point_error_ptr)
...@@ -86,7 +85,9 @@ static int can_update_sample_point(const struct can_bittiming_const *btc, ...@@ -86,7 +85,9 @@ static int can_update_sample_point(const struct can_bittiming_const *btc,
int i; int i;
for (i = 0; i <= 1; i++) { for (i = 0; i <= 1; i++) {
tseg2 = tseg + CAN_CALC_SYNC_SEG - (sample_point_nominal * (tseg + CAN_CALC_SYNC_SEG)) / 1000 - i; tseg2 = tseg + CAN_CALC_SYNC_SEG -
(sample_point_nominal * (tseg + CAN_CALC_SYNC_SEG)) /
1000 - i;
tseg2 = clamp(tseg2, btc->tseg2_min, btc->tseg2_max); tseg2 = clamp(tseg2, btc->tseg2_min, btc->tseg2_max);
tseg1 = tseg - tseg2; tseg1 = tseg - tseg2;
if (tseg1 > btc->tseg1_max) { if (tseg1 > btc->tseg1_max) {
...@@ -94,10 +95,12 @@ static int can_update_sample_point(const struct can_bittiming_const *btc, ...@@ -94,10 +95,12 @@ static int can_update_sample_point(const struct can_bittiming_const *btc,
tseg2 = tseg - tseg1; tseg2 = tseg - tseg1;
} }
sample_point = 1000 * (tseg + CAN_CALC_SYNC_SEG - tseg2) / (tseg + CAN_CALC_SYNC_SEG); sample_point = 1000 * (tseg + CAN_CALC_SYNC_SEG - tseg2) /
(tseg + CAN_CALC_SYNC_SEG);
sample_point_error = abs(sample_point_nominal - sample_point); sample_point_error = abs(sample_point_nominal - sample_point);
if ((sample_point <= sample_point_nominal) && (sample_point_error < best_sample_point_error)) { if (sample_point <= sample_point_nominal &&
sample_point_error < best_sample_point_error) {
best_sample_point = sample_point; best_sample_point = sample_point;
best_sample_point_error = sample_point_error; best_sample_point_error = sample_point_error;
*tseg1_ptr = tseg1; *tseg1_ptr = tseg1;
...@@ -148,7 +151,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -148,7 +151,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
/* choose brp step which is possible in system */ /* choose brp step which is possible in system */
brp = (brp / btc->brp_inc) * btc->brp_inc; brp = (brp / btc->brp_inc) * btc->brp_inc;
if ((brp < btc->brp_min) || (brp > btc->brp_max)) if (brp < btc->brp_min || brp > btc->brp_max)
continue; continue;
bitrate = priv->clock.freq / (brp * tsegall); bitrate = priv->clock.freq / (brp * tsegall);
...@@ -162,7 +165,8 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -162,7 +165,8 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
if (bitrate_error < best_bitrate_error) if (bitrate_error < best_bitrate_error)
best_sample_point_error = UINT_MAX; best_sample_point_error = UINT_MAX;
can_update_sample_point(btc, sample_point_nominal, tseg / 2, &tseg1, &tseg2, &sample_point_error); can_update_sample_point(btc, sample_point_nominal, tseg / 2,
&tseg1, &tseg2, &sample_point_error);
if (sample_point_error > best_sample_point_error) if (sample_point_error > best_sample_point_error)
continue; continue;
...@@ -191,8 +195,9 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -191,8 +195,9 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
} }
/* real sample point */ /* real sample point */
bt->sample_point = can_update_sample_point(btc, sample_point_nominal, best_tseg, bt->sample_point = can_update_sample_point(btc, sample_point_nominal,
&tseg1, &tseg2, NULL); best_tseg, &tseg1, &tseg2,
NULL);
v64 = (u64)best_brp * 1000 * 1000 * 1000; v64 = (u64)best_brp * 1000 * 1000 * 1000;
do_div(v64, priv->clock.freq); do_div(v64, priv->clock.freq);
...@@ -216,7 +221,8 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -216,7 +221,8 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
bt->brp = best_brp; bt->brp = best_brp;
/* real bitrate */ /* real bitrate */
bt->bitrate = priv->clock.freq / (bt->brp * (CAN_CALC_SYNC_SEG + tseg1 + tseg2)); bt->bitrate = priv->clock.freq /
(bt->brp * (CAN_CALC_SYNC_SEG + tseg1 + tseg2));
return 0; return 0;
} }
...@@ -229,8 +235,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -229,8 +235,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
} }
#endif /* CONFIG_CAN_CALC_BITTIMING */ #endif /* CONFIG_CAN_CALC_BITTIMING */
/* /* Checks the validity of the specified bit-timing parameters prop_seg,
* Checks the validity of the specified bit-timing parameters prop_seg,
* phase_seg1, phase_seg2 and sjw and tries to determine the bitrate * phase_seg1, phase_seg2 and sjw and tries to determine the bitrate
* prescaler value brp. You can find more information in the header * prescaler value brp. You can find more information in the header
* file linux/can/netlink.h. * file linux/can/netlink.h.
...@@ -270,7 +275,8 @@ static int can_fixup_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -270,7 +275,8 @@ static int can_fixup_bittiming(struct net_device *dev, struct can_bittiming *bt,
} }
/* Checks the validity of predefined bitrate settings */ /* Checks the validity of predefined bitrate settings */
static int can_validate_bitrate(struct net_device *dev, struct can_bittiming *bt, static int
can_validate_bitrate(struct net_device *dev, struct can_bittiming *bt,
const u32 *bitrate_const, const u32 *bitrate_const,
const unsigned int bitrate_const_cnt) const unsigned int bitrate_const_cnt)
{ {
...@@ -295,8 +301,7 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt, ...@@ -295,8 +301,7 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt,
{ {
int err; int err;
/* /* Depending on the given can_bittiming parameter structure the CAN
* Depending on the given can_bittiming parameter structure the CAN
* timing parameters are calculated based on the provided bitrate OR * timing parameters are calculated based on the provided bitrate OR
* alternatively the CAN timing parameters (tq, prop_seg, etc.) are * alternatively the CAN timing parameters (tq, prop_seg, etc.) are
* provided directly which are then checked and fixed up. * provided directly which are then checked and fixed up.
...@@ -397,8 +402,7 @@ void can_change_state(struct net_device *dev, struct can_frame *cf, ...@@ -397,8 +402,7 @@ void can_change_state(struct net_device *dev, struct can_frame *cf,
} }
EXPORT_SYMBOL_GPL(can_change_state); EXPORT_SYMBOL_GPL(can_change_state);
/* /* Local echo of CAN messages
* Local echo of CAN messages
* *
* CAN network devices *should* support a local echo functionality * CAN network devices *should* support a local echo functionality
* (see Documentation/networking/can.rst). To test the handling of CAN * (see Documentation/networking/can.rst). To test the handling of CAN
...@@ -423,8 +427,7 @@ static void can_flush_echo_skb(struct net_device *dev) ...@@ -423,8 +427,7 @@ static void can_flush_echo_skb(struct net_device *dev)
} }
} }
/* /* Put the skb on the stack to be looped backed locally lateron
* Put the skb on the stack to be looped backed locally lateron
* *
* The function is typically called in the start_xmit function * The function is typically called in the start_xmit function
* of the device driver. The driver must protect access to * of the device driver. The driver must protect access to
...@@ -446,7 +449,6 @@ void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, ...@@ -446,7 +449,6 @@ void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
} }
if (!priv->echo_skb[idx]) { if (!priv->echo_skb[idx]) {
skb = can_create_echo_skb(skb); skb = can_create_echo_skb(skb);
if (!skb) if (!skb)
return; return;
...@@ -466,7 +468,8 @@ void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, ...@@ -466,7 +468,8 @@ void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
} }
EXPORT_SYMBOL_GPL(can_put_echo_skb); EXPORT_SYMBOL_GPL(can_put_echo_skb);
struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr) struct sk_buff *
__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr)
{ {
struct can_priv *priv = netdev_priv(dev); struct can_priv *priv = netdev_priv(dev);
...@@ -493,8 +496,7 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 ...@@ -493,8 +496,7 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8
return NULL; return NULL;
} }
/* /* Get the skb from the stack and loop it back locally
* Get the skb from the stack and loop it back locally
* *
* The function is typically called when the TX done interrupt * The function is typically called when the TX done interrupt
* is handled in the device driver. The driver must protect * is handled in the device driver. The driver must protect
...@@ -515,8 +517,7 @@ unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx) ...@@ -515,8 +517,7 @@ unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx)
} }
EXPORT_SYMBOL_GPL(can_get_echo_skb); EXPORT_SYMBOL_GPL(can_get_echo_skb);
/* /* Remove the skb from the stack and free it.
* Remove the skb from the stack and free it.
* *
* The function is typically called when TX failed. * The function is typically called when TX failed.
*/ */
...@@ -533,9 +534,7 @@ void can_free_echo_skb(struct net_device *dev, unsigned int idx) ...@@ -533,9 +534,7 @@ void can_free_echo_skb(struct net_device *dev, unsigned int idx)
} }
EXPORT_SYMBOL_GPL(can_free_echo_skb); EXPORT_SYMBOL_GPL(can_free_echo_skb);
/* /* CAN device restart for bus-off recovery */
* CAN device restart for bus-off recovery
*/
static void can_restart(struct net_device *dev) static void can_restart(struct net_device *dev)
{ {
struct can_priv *priv = netdev_priv(dev); struct can_priv *priv = netdev_priv(dev);
...@@ -546,15 +545,14 @@ static void can_restart(struct net_device *dev) ...@@ -546,15 +545,14 @@ static void can_restart(struct net_device *dev)
BUG_ON(netif_carrier_ok(dev)); BUG_ON(netif_carrier_ok(dev));
/* /* No synchronization needed because the device is bus-off and
* No synchronization needed because the device is bus-off and
* no messages can come in or go out. * no messages can come in or go out.
*/ */
can_flush_echo_skb(dev); can_flush_echo_skb(dev);
/* send restart message upstream */ /* send restart message upstream */
skb = alloc_can_err_skb(dev, &cf); skb = alloc_can_err_skb(dev, &cf);
if (skb == NULL) { if (!skb) {
err = -ENOMEM; err = -ENOMEM;
goto restart; goto restart;
} }
...@@ -580,7 +578,8 @@ static void can_restart(struct net_device *dev) ...@@ -580,7 +578,8 @@ static void can_restart(struct net_device *dev)
static void can_restart_work(struct work_struct *work) static void can_restart_work(struct work_struct *work)
{ {
struct delayed_work *dwork = to_delayed_work(work); struct delayed_work *dwork = to_delayed_work(work);
struct can_priv *priv = container_of(dwork, struct can_priv, restart_work); struct can_priv *priv = container_of(dwork, struct can_priv,
restart_work);
can_restart(priv->dev); can_restart(priv->dev);
} }
...@@ -589,8 +588,7 @@ int can_restart_now(struct net_device *dev) ...@@ -589,8 +588,7 @@ int can_restart_now(struct net_device *dev)
{ {
struct can_priv *priv = netdev_priv(dev); struct can_priv *priv = netdev_priv(dev);
/* /* A manual restart is only permitted if automatic restart is
* A manual restart is only permitted if automatic restart is
* disabled and the device is in the bus-off state * disabled and the device is in the bus-off state
*/ */
if (priv->restart_ms) if (priv->restart_ms)
...@@ -604,8 +602,7 @@ int can_restart_now(struct net_device *dev) ...@@ -604,8 +602,7 @@ int can_restart_now(struct net_device *dev)
return 0; return 0;
} }
/* /* CAN bus-off
* CAN bus-off
* *
* This functions should be called when the device goes bus-off to * This functions should be called when the device goes bus-off to
* tell the netif layer that no more packets can be sent or received. * tell the netif layer that no more packets can be sent or received.
...@@ -708,9 +705,7 @@ struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf) ...@@ -708,9 +705,7 @@ struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf)
} }
EXPORT_SYMBOL_GPL(alloc_can_err_skb); EXPORT_SYMBOL_GPL(alloc_can_err_skb);
/* /* Allocate and setup space for the CAN network device */
* Allocate and setup space for the CAN network device
*/
struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
unsigned int txqs, unsigned int rxqs) unsigned int txqs, unsigned int rxqs)
{ {
...@@ -746,18 +741,14 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, ...@@ -746,18 +741,14 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
} }
EXPORT_SYMBOL_GPL(alloc_candev_mqs); EXPORT_SYMBOL_GPL(alloc_candev_mqs);
/* /* Free space of the CAN network device */
* Free space of the CAN network device
*/
void free_candev(struct net_device *dev) void free_candev(struct net_device *dev)
{ {
free_netdev(dev); free_netdev(dev);
} }
EXPORT_SYMBOL_GPL(free_candev); EXPORT_SYMBOL_GPL(free_candev);
/* /* changing MTU and control mode for CAN/CANFD devices */
* changing MTU and control mode for CAN/CANFD devices
*/
int can_change_mtu(struct net_device *dev, int new_mtu) int can_change_mtu(struct net_device *dev, int new_mtu)
{ {
struct can_priv *priv = netdev_priv(dev); struct can_priv *priv = netdev_priv(dev);
...@@ -794,8 +785,7 @@ int can_change_mtu(struct net_device *dev, int new_mtu) ...@@ -794,8 +785,7 @@ int can_change_mtu(struct net_device *dev, int new_mtu)
} }
EXPORT_SYMBOL_GPL(can_change_mtu); EXPORT_SYMBOL_GPL(can_change_mtu);
/* /* Common open function when the device gets opened.
* Common open function when the device gets opened.
* *
* This function should be called in the open function of the device * This function should be called in the open function of the device
* driver. * driver.
...@@ -812,7 +802,7 @@ int open_candev(struct net_device *dev) ...@@ -812,7 +802,7 @@ int open_candev(struct net_device *dev)
/* For CAN FD the data bitrate has to be >= the arbitration bitrate */ /* For CAN FD the data bitrate has to be >= the arbitration bitrate */
if ((priv->ctrlmode & CAN_CTRLMODE_FD) && if ((priv->ctrlmode & CAN_CTRLMODE_FD) &&
(!priv->data_bittiming.bitrate || (!priv->data_bittiming.bitrate ||
(priv->data_bittiming.bitrate < priv->bittiming.bitrate))) { priv->data_bittiming.bitrate < priv->bittiming.bitrate)) {
netdev_err(dev, "incorrect/missing data bit-timing\n"); netdev_err(dev, "incorrect/missing data bit-timing\n");
return -EINVAL; return -EINVAL;
} }
...@@ -848,8 +838,7 @@ void of_can_transceiver(struct net_device *dev) ...@@ -848,8 +838,7 @@ void of_can_transceiver(struct net_device *dev)
EXPORT_SYMBOL_GPL(of_can_transceiver); EXPORT_SYMBOL_GPL(of_can_transceiver);
#endif #endif
/* /* Common close function for cleanup before the device gets closed.
* Common close function for cleanup before the device gets closed.
* *
* This function should be called in the close function of the device * This function should be called in the close function of the device
* driver. * driver.
...@@ -863,9 +852,7 @@ void close_candev(struct net_device *dev) ...@@ -863,9 +852,7 @@ void close_candev(struct net_device *dev)
} }
EXPORT_SYMBOL_GPL(close_candev); EXPORT_SYMBOL_GPL(close_candev);
/* /* CAN netlink interface */
* CAN netlink interface
*/
static const struct nla_policy can_policy[IFLA_CAN_MAX + 1] = { static const struct nla_policy can_policy[IFLA_CAN_MAX + 1] = {
[IFLA_CAN_STATE] = { .type = NLA_U32 }, [IFLA_CAN_STATE] = { .type = NLA_U32 },
[IFLA_CAN_CTRLMODE] = { .len = sizeof(struct can_ctrlmode) }, [IFLA_CAN_CTRLMODE] = { .len = sizeof(struct can_ctrlmode) },
...@@ -1209,7 +1196,6 @@ static int can_newlink(struct net *src_net, struct net_device *dev, ...@@ -1209,7 +1196,6 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
static void can_dellink(struct net_device *dev, struct list_head *head) static void can_dellink(struct net_device *dev, struct list_head *head)
{ {
return;
} }
static struct rtnl_link_ops can_link_ops __read_mostly = { static struct rtnl_link_ops can_link_ops __read_mostly = {
...@@ -1227,9 +1213,7 @@ static struct rtnl_link_ops can_link_ops __read_mostly = { ...@@ -1227,9 +1213,7 @@ static struct rtnl_link_ops can_link_ops __read_mostly = {
.fill_xstats = can_fill_xstats, .fill_xstats = can_fill_xstats,
}; };
/* /* Register the CAN network device */
* Register the CAN network device
*/
int register_candev(struct net_device *dev) int register_candev(struct net_device *dev)
{ {
struct can_priv *priv = netdev_priv(dev); struct can_priv *priv = netdev_priv(dev);
...@@ -1255,22 +1239,19 @@ int register_candev(struct net_device *dev) ...@@ -1255,22 +1239,19 @@ int register_candev(struct net_device *dev)
} }
EXPORT_SYMBOL_GPL(register_candev); EXPORT_SYMBOL_GPL(register_candev);
/* /* Unregister the CAN network device */
* Unregister the CAN network device
*/
void unregister_candev(struct net_device *dev) void unregister_candev(struct net_device *dev)
{ {
unregister_netdev(dev); unregister_netdev(dev);
} }
EXPORT_SYMBOL_GPL(unregister_candev); EXPORT_SYMBOL_GPL(unregister_candev);
/* /* Test if a network device is a candev based device
* Test if a network device is a candev based device
* and return the can_priv* if so. * and return the can_priv* if so.
*/ */
struct can_priv *safe_candev_priv(struct net_device *dev) struct can_priv *safe_candev_priv(struct net_device *dev)
{ {
if ((dev->type != ARPHRD_CAN) || (dev->rtnl_link_ops != &can_link_ops)) if (dev->type != ARPHRD_CAN || dev->rtnl_link_ops != &can_link_ops)
return NULL; return NULL;
return netdev_priv(dev); return netdev_priv(dev);
...@@ -1285,7 +1266,7 @@ static __init int can_dev_init(void) ...@@ -1285,7 +1266,7 @@ static __init int can_dev_init(void)
err = rtnl_link_register(&can_link_ops); err = rtnl_link_register(&can_link_ops);
if (!err) if (!err)
printk(KERN_INFO MOD_DESC "\n"); pr_info(MOD_DESC "\n");
return err; return err;
} }
......
...@@ -65,6 +65,7 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices"); ...@@ -65,6 +65,7 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");
#define KVASER_PCIEFD_SYSID_BASE 0x1f020 #define KVASER_PCIEFD_SYSID_BASE 0x1f020
#define KVASER_PCIEFD_SYSID_VERSION_REG (KVASER_PCIEFD_SYSID_BASE + 0x8) #define KVASER_PCIEFD_SYSID_VERSION_REG (KVASER_PCIEFD_SYSID_BASE + 0x8)
#define KVASER_PCIEFD_SYSID_CANFREQ_REG (KVASER_PCIEFD_SYSID_BASE + 0xc) #define KVASER_PCIEFD_SYSID_CANFREQ_REG (KVASER_PCIEFD_SYSID_BASE + 0xc)
#define KVASER_PCIEFD_SYSID_BUSFREQ_REG (KVASER_PCIEFD_SYSID_BASE + 0x10)
#define KVASER_PCIEFD_SYSID_BUILD_REG (KVASER_PCIEFD_SYSID_BASE + 0x14) #define KVASER_PCIEFD_SYSID_BUILD_REG (KVASER_PCIEFD_SYSID_BASE + 0x14)
/* Shared receive buffer registers */ /* Shared receive buffer registers */
#define KVASER_PCIEFD_SRB_BASE 0x1f200 #define KVASER_PCIEFD_SRB_BASE 0x1f200
...@@ -268,6 +269,7 @@ struct kvaser_pciefd { ...@@ -268,6 +269,7 @@ struct kvaser_pciefd {
struct kvaser_pciefd_can *can[KVASER_PCIEFD_MAX_CAN_CHANNELS]; struct kvaser_pciefd_can *can[KVASER_PCIEFD_MAX_CAN_CHANNELS];
void *dma_data[KVASER_PCIEFD_DMA_COUNT]; void *dma_data[KVASER_PCIEFD_DMA_COUNT];
u8 nr_channels; u8 nr_channels;
u32 bus_freq;
u32 freq; u32 freq;
u32 freq_to_ticks_div; u32 freq_to_ticks_div;
}; };
...@@ -666,7 +668,7 @@ static void kvaser_pciefd_pwm_start(struct kvaser_pciefd_can *can) ...@@ -666,7 +668,7 @@ static void kvaser_pciefd_pwm_start(struct kvaser_pciefd_can *can)
spin_lock_irqsave(&can->lock, irq); spin_lock_irqsave(&can->lock, irq);
/* Set frequency to 500 KHz*/ /* Set frequency to 500 KHz*/
top = can->can.clock.freq / (2 * 500000) - 1; top = can->kv_pcie->bus_freq / (2 * 500000) - 1;
pwm_ctrl = top & 0xff; pwm_ctrl = top & 0xff;
pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT; pwm_ctrl |= (top & 0xff) << KVASER_PCIEFD_KCAN_PWM_TOP_SHIFT;
...@@ -1119,6 +1121,8 @@ static int kvaser_pciefd_setup_board(struct kvaser_pciefd *pcie) ...@@ -1119,6 +1121,8 @@ static int kvaser_pciefd_setup_board(struct kvaser_pciefd *pcie)
return -ENODEV; return -ENODEV;
} }
pcie->bus_freq = ioread32(pcie->reg_base +
KVASER_PCIEFD_SYSID_BUSFREQ_REG);
pcie->freq = ioread32(pcie->reg_base + KVASER_PCIEFD_SYSID_CANFREQ_REG); pcie->freq = ioread32(pcie->reg_base + KVASER_PCIEFD_SYSID_CANFREQ_REG);
pcie->freq_to_ticks_div = pcie->freq / 1000000; pcie->freq_to_ticks_div = pcie->freq / 1000000;
if (pcie->freq_to_ticks_div == 0) if (pcie->freq_to_ticks_div == 0)
......
...@@ -117,7 +117,6 @@ struct tcan4x5x_priv { ...@@ -117,7 +117,6 @@ struct tcan4x5x_priv {
struct m_can_classdev *mcan_dev; struct m_can_classdev *mcan_dev;
struct gpio_desc *reset_gpio; struct gpio_desc *reset_gpio;
struct gpio_desc *interrupt_gpio;
struct gpio_desc *device_wake_gpio; struct gpio_desc *device_wake_gpio;
struct gpio_desc *device_state_gpio; struct gpio_desc *device_state_gpio;
struct regulator *power; struct regulator *power;
...@@ -236,8 +235,6 @@ static u32 tcan4x5x_read_reg(struct m_can_classdev *cdev, int reg) ...@@ -236,8 +235,6 @@ static u32 tcan4x5x_read_reg(struct m_can_classdev *cdev, int reg)
struct tcan4x5x_priv *priv = cdev->device_data; struct tcan4x5x_priv *priv = cdev->device_data;
u32 val; u32 val;
tcan4x5x_check_wake(priv);
regmap_read(priv->regmap, priv->reg_offset + reg, &val); regmap_read(priv->regmap, priv->reg_offset + reg, &val);
return val; return val;
...@@ -248,8 +245,6 @@ static u32 tcan4x5x_read_fifo(struct m_can_classdev *cdev, int addr_offset) ...@@ -248,8 +245,6 @@ static u32 tcan4x5x_read_fifo(struct m_can_classdev *cdev, int addr_offset)
struct tcan4x5x_priv *priv = cdev->device_data; struct tcan4x5x_priv *priv = cdev->device_data;
u32 val; u32 val;
tcan4x5x_check_wake(priv);
regmap_read(priv->regmap, priv->mram_start + addr_offset, &val); regmap_read(priv->regmap, priv->mram_start + addr_offset, &val);
return val; return val;
...@@ -259,8 +254,6 @@ static int tcan4x5x_write_reg(struct m_can_classdev *cdev, int reg, int val) ...@@ -259,8 +254,6 @@ static int tcan4x5x_write_reg(struct m_can_classdev *cdev, int reg, int val)
{ {
struct tcan4x5x_priv *priv = cdev->device_data; struct tcan4x5x_priv *priv = cdev->device_data;
tcan4x5x_check_wake(priv);
return regmap_write(priv->regmap, priv->reg_offset + reg, val); return regmap_write(priv->regmap, priv->reg_offset + reg, val);
} }
...@@ -269,8 +262,6 @@ static int tcan4x5x_write_fifo(struct m_can_classdev *cdev, ...@@ -269,8 +262,6 @@ static int tcan4x5x_write_fifo(struct m_can_classdev *cdev,
{ {
struct tcan4x5x_priv *priv = cdev->device_data; struct tcan4x5x_priv *priv = cdev->device_data;
tcan4x5x_check_wake(priv);
return regmap_write(priv->regmap, priv->mram_start + addr_offset, val); return regmap_write(priv->regmap, priv->mram_start + addr_offset, val);
} }
...@@ -290,18 +281,13 @@ static int tcan4x5x_write_tcan_reg(struct m_can_classdev *cdev, ...@@ -290,18 +281,13 @@ static int tcan4x5x_write_tcan_reg(struct m_can_classdev *cdev,
{ {
struct tcan4x5x_priv *priv = cdev->device_data; struct tcan4x5x_priv *priv = cdev->device_data;
tcan4x5x_check_wake(priv);
return regmap_write(priv->regmap, reg, val); return regmap_write(priv->regmap, reg, val);
} }
static int tcan4x5x_clear_interrupts(struct m_can_classdev *cdev) static int tcan4x5x_clear_interrupts(struct m_can_classdev *cdev)
{ {
struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
int ret; int ret;
tcan4x5x_check_wake(tcan4x5x);
ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_STATUS, ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_STATUS,
TCAN4X5X_CLEAR_ALL_INT); TCAN4X5X_CLEAR_ALL_INT);
if (ret) if (ret)
...@@ -356,13 +342,6 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev) ...@@ -356,13 +342,6 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
{ {
struct tcan4x5x_priv *tcan4x5x = cdev->device_data; struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
tcan4x5x->interrupt_gpio = devm_gpiod_get(cdev->dev, "data-ready",
GPIOD_IN);
if (IS_ERR(tcan4x5x->interrupt_gpio)) {
dev_err(cdev->dev, "data-ready gpio not defined\n");
return -EINVAL;
}
tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake", tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake",
GPIOD_OUT_HIGH); GPIOD_OUT_HIGH);
if (IS_ERR(tcan4x5x->device_wake_gpio)) { if (IS_ERR(tcan4x5x->device_wake_gpio)) {
...@@ -381,8 +360,6 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev) ...@@ -381,8 +360,6 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
if (IS_ERR(tcan4x5x->device_state_gpio)) if (IS_ERR(tcan4x5x->device_state_gpio))
tcan4x5x->device_state_gpio = NULL; tcan4x5x->device_state_gpio = NULL;
cdev->net->irq = gpiod_to_irq(tcan4x5x->interrupt_gpio);
tcan4x5x->power = devm_regulator_get_optional(cdev->dev, tcan4x5x->power = devm_regulator_get_optional(cdev->dev,
"vsup"); "vsup");
if (PTR_ERR(tcan4x5x->power) == -EPROBE_DEFER) if (PTR_ERR(tcan4x5x->power) == -EPROBE_DEFER)
...@@ -447,6 +424,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -447,6 +424,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
mcan_class->is_peripheral = true; mcan_class->is_peripheral = true;
mcan_class->bit_timing = &tcan4x5x_bittiming_const; mcan_class->bit_timing = &tcan4x5x_bittiming_const;
mcan_class->data_timing = &tcan4x5x_data_bittiming_const; mcan_class->data_timing = &tcan4x5x_data_bittiming_const;
mcan_class->net->irq = spi->irq;
spi_set_drvdata(spi, priv); spi_set_drvdata(spi, priv);
......
...@@ -17,26 +17,6 @@ ...@@ -17,26 +17,6 @@
* - Sascha Hauer, Marc Kleine-Budde, Pengutronix * - Sascha Hauer, Marc Kleine-Budde, Pengutronix
* - Simon Kallweit, intefo AG * - Simon Kallweit, intefo AG
* Copyright 2007 * Copyright 2007
*
* Your platform definition file should specify something like:
*
* static struct mcp251x_platform_data mcp251x_info = {
* .oscillator_frequency = 8000000,
* };
*
* static struct spi_board_info spi_board_info[] = {
* {
* .modalias = "mcp2510",
* // "mcp2515" or "mcp25625" depending on your controller
* .platform_data = &mcp251x_info,
* .irq = IRQ_EINT13,
* .max_speed_hz = 2*1000*1000,
* .chip_select = 2,
* },
* };
*
* Please see mcp251x.h for a description of the fields in
* struct mcp251x_platform_data.
*/ */
#include <linux/can/core.h> #include <linux/can/core.h>
...@@ -53,8 +33,7 @@ ...@@ -53,8 +33,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/of.h> #include <linux/property.h>
#include <linux/of_device.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
...@@ -914,7 +893,7 @@ static int mcp251x_open(struct net_device *net) ...@@ -914,7 +893,7 @@ static int mcp251x_open(struct net_device *net)
priv->tx_skb = NULL; priv->tx_skb = NULL;
priv->tx_len = 0; priv->tx_len = 0;
if (!spi->dev.of_node) if (!dev_fwnode(&spi->dev))
flags = IRQF_TRIGGER_FALLING; flags = IRQF_TRIGGER_FALLING;
ret = request_threaded_irq(spi->irq, NULL, mcp251x_can_ist, ret = request_threaded_irq(spi->irq, NULL, mcp251x_can_ist,
...@@ -1006,23 +985,20 @@ MODULE_DEVICE_TABLE(spi, mcp251x_id_table); ...@@ -1006,23 +985,20 @@ MODULE_DEVICE_TABLE(spi, mcp251x_id_table);
static int mcp251x_can_probe(struct spi_device *spi) static int mcp251x_can_probe(struct spi_device *spi)
{ {
const struct of_device_id *of_id = of_match_device(mcp251x_of_match, const void *match = device_get_match_data(&spi->dev);
&spi->dev);
struct mcp251x_platform_data *pdata = dev_get_platdata(&spi->dev); struct mcp251x_platform_data *pdata = dev_get_platdata(&spi->dev);
struct net_device *net; struct net_device *net;
struct mcp251x_priv *priv; struct mcp251x_priv *priv;
struct clk *clk; struct clk *clk;
int freq, ret; int freq, ret;
clk = devm_clk_get(&spi->dev, NULL); clk = devm_clk_get_optional(&spi->dev, NULL);
if (IS_ERR(clk)) { if (IS_ERR(clk))
if (pdata)
freq = pdata->oscillator_frequency;
else
return PTR_ERR(clk); return PTR_ERR(clk);
} else {
freq = clk_get_rate(clk); freq = clk_get_rate(clk);
} if (freq == 0 && pdata)
freq = pdata->oscillator_frequency;
/* Sanity check */ /* Sanity check */
if (freq < 1000000 || freq > 25000000) if (freq < 1000000 || freq > 25000000)
...@@ -1033,11 +1009,9 @@ static int mcp251x_can_probe(struct spi_device *spi) ...@@ -1033,11 +1009,9 @@ static int mcp251x_can_probe(struct spi_device *spi)
if (!net) if (!net)
return -ENOMEM; return -ENOMEM;
if (!IS_ERR(clk)) {
ret = clk_prepare_enable(clk); ret = clk_prepare_enable(clk);
if (ret) if (ret)
goto out_free; goto out_free;
}
net->netdev_ops = &mcp251x_netdev_ops; net->netdev_ops = &mcp251x_netdev_ops;
net->flags |= IFF_ECHO; net->flags |= IFF_ECHO;
...@@ -1048,8 +1022,8 @@ static int mcp251x_can_probe(struct spi_device *spi) ...@@ -1048,8 +1022,8 @@ static int mcp251x_can_probe(struct spi_device *spi)
priv->can.clock.freq = freq / 2; priv->can.clock.freq = freq / 2;
priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY; CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY;
if (of_id) if (match)
priv->model = (enum mcp251x_model)of_id->data; priv->model = (enum mcp251x_model)match;
else else
priv->model = spi_get_device_id(spi)->driver_data; priv->model = spi_get_device_id(spi)->driver_data;
priv->net = net; priv->net = net;
...@@ -1122,7 +1096,6 @@ static int mcp251x_can_probe(struct spi_device *spi) ...@@ -1122,7 +1096,6 @@ static int mcp251x_can_probe(struct spi_device *spi)
mcp251x_power_enable(priv->power, 0); mcp251x_power_enable(priv->power, 0);
out_clk: out_clk:
if (!IS_ERR(clk))
clk_disable_unprepare(clk); clk_disable_unprepare(clk);
out_free: out_free:
...@@ -1141,7 +1114,6 @@ static int mcp251x_can_remove(struct spi_device *spi) ...@@ -1141,7 +1114,6 @@ static int mcp251x_can_remove(struct spi_device *spi)
mcp251x_power_enable(priv->power, 0); mcp251x_power_enable(priv->power, 0);
if (!IS_ERR(priv->clk))
clk_disable_unprepare(priv->clk); clk_disable_unprepare(priv->clk);
free_candev(net); free_candev(net);
...@@ -1170,10 +1142,8 @@ static int __maybe_unused mcp251x_can_suspend(struct device *dev) ...@@ -1170,10 +1142,8 @@ static int __maybe_unused mcp251x_can_suspend(struct device *dev)
priv->after_suspend = AFTER_SUSPEND_DOWN; priv->after_suspend = AFTER_SUSPEND_DOWN;
} }
if (!IS_ERR_OR_NULL(priv->power)) { mcp251x_power_enable(priv->power, 0);
regulator_disable(priv->power);
priv->after_suspend |= AFTER_SUSPEND_POWER; priv->after_suspend |= AFTER_SUSPEND_POWER;
}
return 0; return 0;
} }
......
...@@ -169,7 +169,8 @@ void can_change_state(struct net_device *dev, struct can_frame *cf, ...@@ -169,7 +169,8 @@ void can_change_state(struct net_device *dev, struct can_frame *cf,
void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
unsigned int idx); unsigned int idx);
struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr); struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx,
u8 *len_ptr);
unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx); unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx);
void can_free_echo_skb(struct net_device *dev, unsigned int idx); void can_free_echo_skb(struct net_device *dev, unsigned int idx);
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
struct can_rx_offload { struct can_rx_offload {
struct net_device *dev; struct net_device *dev;
unsigned int (*mailbox_read)(struct can_rx_offload *offload, struct can_frame *cf, unsigned int (*mailbox_read)(struct can_rx_offload *offload,
struct can_frame *cf,
u32 *timestamp, unsigned int mb); u32 *timestamp, unsigned int mb);
struct sk_buff_head skb_queue; struct sk_buff_head skb_queue;
...@@ -29,9 +30,13 @@ struct can_rx_offload { ...@@ -29,9 +30,13 @@ struct can_rx_offload {
bool inc; bool inc;
}; };
int can_rx_offload_add_timestamp(struct net_device *dev, struct can_rx_offload *offload); int can_rx_offload_add_timestamp(struct net_device *dev,
int can_rx_offload_add_fifo(struct net_device *dev, struct can_rx_offload *offload, unsigned int weight); struct can_rx_offload *offload);
int can_rx_offload_irq_offload_timestamp(struct can_rx_offload *offload, u64 reg); int can_rx_offload_add_fifo(struct net_device *dev,
struct can_rx_offload *offload,
unsigned int weight);
int can_rx_offload_irq_offload_timestamp(struct can_rx_offload *offload,
u64 reg);
int can_rx_offload_irq_offload_fifo(struct can_rx_offload *offload); int can_rx_offload_irq_offload_fifo(struct can_rx_offload *offload);
int can_rx_offload_queue_sorted(struct can_rx_offload *offload, int can_rx_offload_queue_sorted(struct can_rx_offload *offload,
struct sk_buff *skb, u32 timestamp); struct sk_buff *skb, u32 timestamp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment