rpi: platform code improvements
Subsystems (5)
cover rpi: platform code improvements
This series focuses mainly on init handling of rpi board variants. Init of ethernet, usb and leds for known variants is generalized and serial number and machin-id support is added. This series also allows bcmgenet ethernet driver to use the hw-assigned mac address on bcm2711 based boards.
Daniel Brát (5):
ARM: rpi: rename function getting mac address
ARM: rpi: add serial number readout
ARM: rpi: rework rpi board init code
ARM: rpi: add machine-id support
ARM: rpi: enable reset source detection in defconfig
arch/arm/boards/raspberry-pi/lowlevel.h | 3 +- arch/arm/boards/raspberry-pi/mbox-helpers.c | 29 +- arch/arm/boards/raspberry-pi/rpi-common.c | 439 +++++++++----------- arch/arm/configs/rpi_defconfig | 2 + arch/arm/configs/rpi_v8a_defconfig | 2 + arch/arm/dts/bcm2711-rpi-4.dts | 5 + arch/arm/dts/bcm2835-rpi.dts | 1 + arch/arm/dts/bcm2836-rpi-2.dts | 4 + arch/arm/dts/bcm2837-rpi-3.dts | 5 + arch/arm/mach-bcm283x/include/mach/mbox.h | 13 + 10 files changed, 265 insertions(+), 238 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/5 ARM: rpi: rename function getting mac address
Rename 'rpi_set_usbethaddr' and 'rpi_get_usbethaddr' to more generic 'rpi_set_ethaddr' and 'rpi_get_ethaddr', since they can also be used to obtain factory assigned mac address on bcm2711 (rpi4), which uses bcmgenet nic instead of usb ethernet nic.
--- arch/arm/boards/raspberry-pi/lowlevel.h | 2 +- arch/arm/boards/raspberry-pi/mbox-helpers.c | 2 +- arch/arm/boards/raspberry-pi/rpi-common.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-)
arch/arm/boards/raspberry-pi/lowlevel.h +1 -1
@@ -10,7 +10,7 @@#define VIDEOCORE_FDT_ERROR 0xdeadfeedssize_t rpi_get_arm_mem (void ); -int rpi_get_usbethaddr (u8 mac[6 ]); +int rpi_get_ethaddr (u8 mac[6 ]);int rpi_get_board_rev (void );#endif /* __ARCH_ARM_BOARDS_LOWLEVEL_H__ */
arch/arm/boards/raspberry-pi/mbox-helpers.c +1 -1
@@ -37,7 +37,7 @@ ssize_t rpi_get_arm_mem(void)return msg->get_arm_mem.body.resp.mem_size; } -int rpi_get_usbethaddr (u8 mac[6 ]) +int rpi_get_ethaddr (u8 mac[6 ]) { BCM2835_MBOX_STACK_ALIGN(struct msg_get_mac_address, msg);int ret;
arch/arm/boards/raspberry-pi/rpi-common.c +4 -4
@@ -60,11 +60,11 @@ struct rpi_priv {const char *name; }; -static void rpi_set_usbethaddr (void ) +static void rpi_set_ethaddr (void ) {u8 mac[ETH_ALEN ]; -if (rpi_get_usbethaddr (mac)) +if (rpi_get_ethaddr (mac))return ;/* Ignore error; not critical */ eth_register_ethaddr (0 , mac);
@@ -114,7 +114,7 @@ static int rpi_b_init(struct rpi_priv *priv) { rpi_leds[0 ].gpio =16 ; rpi_leds[0 ].active_low =1 ; -rpi_set_usbethaddr (); +rpi_set_ethaddr ();return 0 ; }
@@ -123,7 +123,7 @@ static int rpi_b_plus_init(struct rpi_priv *priv) { rpi_leds[0 ].gpio =47 ; rpi_leds[1 ].gpio =35 ; -rpi_set_usbethaddr (); +rpi_set_ethaddr ();return 0 ; }
Signature · 1 line
2.34.1
PATCH 2/5 ARM: rpi: add serial number readout
In reply to Daniel BrátRemove querying for serial-number node from vc fdt, since it's not guaranteed to always be there (older firmwares dont provide it). Instead, retrieve board's serial number via the mbox api.
--- arch/arm/boards/raspberry-pi/lowlevel.h | 1 + arch/arm/boards/raspberry-pi/mbox-helpers.c | 27 +++++++++++++++++++++ arch/arm/boards/raspberry-pi/rpi-common.c | 21 +++++++++++----- arch/arm/mach-bcm283x/include/mach/mbox.h | 13 ++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-)
arch/arm/boards/raspberry-pi/lowlevel.h +1 -0
@@ -12,5 +12,6 @@ssize_t rpi_get_arm_mem (void );int rpi_get_ethaddr (u8 mac[6 ]);int rpi_get_board_rev (void ); +int rpi_get_board_serial (u64 *serial);#endif /* __ARCH_ARM_BOARDS_LOWLEVEL_H__ */
arch/arm/boards/raspberry-pi/mbox-helpers.c +27 -0
@@ -16,6 +16,12 @@ struct msg_get_board_rev {u32 end_tag; }; +struct msg_get_board_serial { +struct bcm2835_mbox_hdr hdr; +struct bcm2835_mbox_tag_get_board_serial get_board_serial; +u32 end_tag; +}; +struct msg_get_mac_address {struct bcm2835_mbox_hdr hdr;struct bcm2835_mbox_tag_get_mac_address get_mac_address;
@@ -71,3 +77,24 @@ int rpi_get_board_rev(void)return msg->get_board_rev.body.resp.rev; } + +int rpi_get_board_serial (u64 *serial) +{ +int ret; + + BCM2835_MBOX_STACK_ALIGN(struct msg_get_board_serial, msg); +BCM2835_MBOX_INIT_HDR (msg); +BCM2835_MBOX_INIT_TAG (&msg->get_board_serial,GET_BOARD_SERIAL ); + +if (!serial) +return -EINVAL ; + + ret =bcm2835_mbox_call_prop (BCM2835_MBOX_PROP_CHAN , &msg->hdr); +if (ret) { +pr_err ("Could not query board serial\n" ); +return ret; + } + + *serial = msg->get_board_serial.body.resp.serial; +return 0 ; +}
arch/arm/boards/raspberry-pi/rpi-common.c +15 -6
@@ -60,6 +60,19 @@ struct rpi_priv {const char *name; }; +static void rpi_set_serial_number (void ) +{ +u64 serial; +char *serial_str; + +if (rpi_get_board_serial (&serial)) +return ; + + serial_str =basprintf ("%016llx" , serial); +barebox_set_serial_number (serial_str); +free (serial_str); +} +static void rpi_set_ethaddr (void ) {u8 mac[ETH_ALEN ];
@@ -265,12 +278,6 @@ static void rpi_vc_fdt_parse(void *fdt)if (IS_ERR (root))return ; - str =of_read_vc_string (root,"serial-number" ); -if (str) { -barebox_set_serial_number (str); -free (str); - } - str =of_read_vc_string (root,"model" );if (str) {barebox_set_model (str);
@@ -446,6 +453,8 @@ static int rpi_devices_probe(struct device *dev)if (IS_ERR (dcfg)) goto free_priv; +rpi_set_serial_number (); +/* construct short recognizable host name */ name =of_device_get_match_compatible (priv->dev); ptr =strchr (name,',' );
arch/arm/mach-bcm283x/include/mach/mbox.h +13 -0
@@ -201,6 +201,19 @@ struct bcm2835_mbox_tag_get_mac_address { } body; }; +#define BCM2835_MBOX_TAG_GET_BOARD_SERIAL 0x00010004 + +struct bcm2835_mbox_tag_get_board_serial { +struct bcm2835_mbox_tag_hdr tag_hdr; +union { +struct { + } req; +struct __packed { +u64 serial; + } resp; + } body; +}; +#define BCM2835_MBOX_TAG_GET_ARM_MEMORY 0x00010005struct bcm2835_mbox_tag_get_arm_mem {
Signature · 1 line
2.34.1
Re: [PATCH 2/5] ARM: rpi: add serial number readout
Hi Daniel,
thanks for the patch.
Quoted 3 lines · Daniel Brát
Remove querying for serial-number node from vc fdt, since it's not guaranteed to always be there (older firmwares dont provide it). Instead, retrieve board's serial number via the mbox api.
Is this possible for all RPi's out there?
Quoted 115 lines
Signed-off-by Daniel Brát <[email protected]>--- arch/arm/boards/raspberry-pi/lowlevel.h | 1 + arch/arm/boards/raspberry-pi/mbox-helpers.c | 27 +++++++++++++++++++++ arch/arm/boards/raspberry-pi/rpi-common.c | 21 +++++++++++----- arch/arm/mach-bcm283x/include/mach/mbox.h | 13 ++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-)arch/arm/boards/raspberry-pi/lowlevel.h +1
-0@@ -12,5 +12,6 @@ssize_t rpi_get_arm_mem (void );int rpi_get_ethaddr (u8 mac[6 ]);int rpi_get_board_rev (void ); +int rpi_get_board_serial (u64 *serial);#endif /* __ARCH_ARM_BOARDS_LOWLEVEL_H__ */ arch/arm/boards/raspberry-pi/mbox-helpers.c +27
-0@@ -16,6 +16,12 @@ struct msg_get_board_rev {u32 end_tag; }; +struct msg_get_board_serial { +struct bcm2835_mbox_hdr hdr; +struct bcm2835_mbox_tag_get_board_serial get_board_serial; +u32 end_tag; +}; +struct msg_get_mac_address {struct bcm2835_mbox_hdr hdr;struct bcm2835_mbox_tag_get_mac_address get_mac_address;@@ -71,3 +77,24 @@ int rpi_get_board_rev(void)return msg->get_board_rev.body.resp.rev; } + +int rpi_get_board_serial (u64 *serial) +{ +int ret; + + BCM2835_MBOX_STACK_ALIGN(struct msg_get_board_serial, msg); +BCM2835_MBOX_INIT_HDR (msg); +BCM2835_MBOX_INIT_TAG (&msg->get_board_serial,GET_BOARD_SERIAL ); + +if (!serial) +return -EINVAL ; + + ret =bcm2835_mbox_call_prop (BCM2835_MBOX_PROP_CHAN , &msg->hdr); +if (ret) { +pr_err ("Could not query board serial\n" ); +return ret; + } + + *serial = msg->get_board_serial.body.resp.serial; +return 0 ; +}arch/arm/boards/raspberry-pi/rpi-common.c +15
-6@@ -60,6 +60,19 @@ struct rpi_priv {const char *name; }; +static void rpi_set_serial_number (void ) +{ +u64 serial; +char *serial_str; + +if (rpi_get_board_serial (&serial)) +return ; + + serial_str =basprintf ("%016llx" , serial); +barebox_set_serial_number (serial_str); +free (serial_str); +} +static void rpi_set_ethaddr (void ) {u8 mac[ETH_ALEN ];@@ -265,12 +278,6 @@ static void rpi_vc_fdt_parse(void *fdt)if (IS_ERR (root))return ; - str =of_read_vc_string (root,"serial-number" ); -if (str) { -barebox_set_serial_number (str); -free (str); - } - str =of_read_vc_string (root,"model" );if (str) {barebox_set_model (str);@@ -446,6 +453,8 @@ static int rpi_devices_probe(struct device *dev)if (IS_ERR (dcfg)) goto free_priv; +rpi_set_serial_number (); +/* construct short recognizable host name */ name =of_device_get_match_compatible (priv->dev); ptr =strchr (name,',' );arch/arm/mach-bcm283x/include/mach/mbox.h +0
-0@@ -201,6 +201,19 @@ struct bcm2835_mbox_tag_get_mac_address { } body; };
arch/arm/mach-bcm283x/include/mach/mbox.h struct bcm2835_mbox_tag_get_mac_address { · line 213
Quoted 10 lines
arch/arm/mach-bcm283x/include/mach/mbox.h +10
-0+#define BCM2835_MBOX_TAG_GET_BOARD_SERIAL 0x00010004 + +struct bcm2835_mbox_tag_get_board_serial { +struct bcm2835_mbox_tag_hdr tag_hdr; +union { +struct { + } req; +struct __packed { +u64 serial; + } resp;
Why do we need the __packed here?
Regards,
Marco
Quoted 11 lines
arch/arm/mach-bcm283x/include/mach/mbox.h +3
-0+ } body; +}; +#define BCM2835_MBOX_TAG_GET_ARM_MEMORY 0x00010005struct bcm2835_mbox_tag_get_arm_mem {Signature · 1 line
2.34.1
PATCH 3/5 ARM: rpi: rework rpi board init code
In reply to Daniel BrátRework of init for various rpi board variants. Primarily, ethernet and usb init have been generalized to better cover different variations and handling of board leds changed from adding and registering 'gpio_led' structures to fixing them in the device tree. This change also required moving the board init code from 'late_platform_driver' to 'coredevice_platform_driver' which in turn ment calling 'rpi_env_init' from separate late_initcall.
--- arch/arm/boards/raspberry-pi/rpi-common.c | 414 ++++++++++------------ arch/arm/dts/bcm2711-rpi-4.dts | 5 + arch/arm/dts/bcm2835-rpi.dts | 1 + arch/arm/dts/bcm2836-rpi-2.dts | 4 + arch/arm/dts/bcm2837-rpi-3.dts | 5 + 5 files changed, 199 insertions(+), 230 deletions(-)
arch/arm/boards/raspberry-pi/rpi-common.c +184 -230
@@ -24,6 +24,7 @@#include <globalvar.h> #include <asm/system_info.h> #include <reset_source.h> +#include <dt-bindings/gpio/gpio.h> #include <mach/core.h> #include <mach/mbox.h>
@@ -45,19 +46,21 @@ static const char * const boot_mode_names[] = { [0x7] = "http", }; -struct rpi_priv ;struct rpi_machine_data { -int (*init)(struct rpi_priv *priv);u8 hw_id;#define RPI_OLD_SCHEMA BIT(0) +#define RPI_SET_ETHADDR BIT(1) +#define RPI_SET_USB_OTG BIT(2) +#define RPI_LED_PWR_INV BIT(3) +#define RPI_LED_PWR_EXP BIT(4) +#define RPI_LED_ACT_INV BIT(5) +#define RPI_LED_ACT_EXP BIT(6) +#define RPI_LED_ANY_EXP (RPI_LED_PWR_EXP | RPI_LED_ACT_EXP) +#define RPI_LED_PWR_EXP_INV (RPI_LED_PWR_EXP | RPI_LED_PWR_INV) +#define RPI_LED_ACT_EXP_INV (RPI_LED_ACT_EXP | RPI_LED_ACT_INV)u8 flags; -}; - -struct rpi_priv { -struct device *dev; -const struct rpi_machine_data *dcfg; -unsigned int hw_id; -const char *name; +int pwr_led_gpio; +int act_led_gpio; };static void rpi_set_serial_number (void )
@@ -83,91 +86,74 @@ static void rpi_set_ethaddr(void)eth_register_ethaddr (0 , mac); } -static void rpi_set_usbotg (const char *alias) +static void rpi_set_usbotg (void ) {struct device_node *usb; - usb =of_find_node_by_alias (NULL , alias); + usb =of_find_node_by_alias (NULL ,"usb0" );if (usb)of_property_write_string (usb,"dr_mode" ,"otg" ); } -static struct gpio_led rpi_leds[] = { - { - .gpio = -EINVAL , - .led = { - .name ="ACT" , - }, - }, { - .gpio = -EINVAL , - .led = { - .name ="PWR" , - }, - }, -}; - -static void rpi_add_led (void ) +static int of_rpi_led_set_gpio (struct device_node *led,u32 pin, +bool exp,bool inv) { -int i; -struct gpio_led *l; - -for (i =0 ; i <ARRAY_SIZE (rpi_leds); i++) { - l = &rpi_leds[i]; - -if (gpio_is_valid (l->gpio)) -led_gpio_register (l); - } - - l = &rpi_leds[0 ]; -if (gpio_is_valid (l->gpio)) -led_set_trigger (LED_TRIGGER_HEARTBEAT , &l->led); -} +u32 gpios_prop[3 ]; +struct device_node *gpio; -static int rpi_b_init (struct rpi_priv *priv) -{ - rpi_leds[0 ].gpio =16 ; - rpi_leds[0 ].active_low =1 ; -rpi_set_ethaddr (); - -return 0 ; -} - -static int rpi_b_plus_init (struct rpi_priv *priv) -{ - rpi_leds[0 ].gpio =47 ; - rpi_leds[1 ].gpio =35 ; -rpi_set_ethaddr (); +if (!led) +return -ENODEV ; -return 0 ; -} + gpio =of_find_node_by_alias (NULL , exp ?"expgpio0" :"gpio0" ); +if (!gpio) +return -ENODEV ; -static int rpi_0_init (struct rpi_priv *priv) -{ - rpi_leds[0 ].gpio =47 ; -rpi_set_usbotg ("usb0" ); + gpios_prop[0 ] = gpio->phandle; + gpios_prop[1 ] = pin; + gpios_prop[2 ] = inv ?GPIO_ACTIVE_LOW :GPIO_ACTIVE_HIGH ; -return 0 ; +return of_property_write_u32_array (led,"gpios" , gpios_prop,3 ); } -static int rpi_0_w_init (struct rpi_priv *priv) +static void rpi_add_leds (const struct rpi_machine_data *dcfg) { -struct device_node *np; -int ret; +int flags, led_pwr, led_act, led_cnt; +struct device_node *leds, *l; -rpi_0_init (priv); +if (!IS_ENABLED (CONFIG_OFDEVICE ) || !IS_ENABLED (CONFIG_LED_GPIO_OF )) +return ; - np =of_find_node_by_path ("/chosen" ); -if (!np) -return -ENODEV ; + leds =of_find_node_by_path ("/leds" ); +if (!leds) +return ; -if (!of_device_enable_and_register_by_alias ("serial1" )) -return -ENODEV ; + led_cnt =0 ; + flags = dcfg->flags; + led_pwr = dcfg->pwr_led_gpio; + led_act = dcfg->act_led_gpio; + + l =of_get_child_by_name (leds,"led-pwr" ); +if (l) { +if (led_pwr >=0 && !of_rpi_led_set_gpio (l, led_pwr, + flags &RPI_LED_PWR_EXP , + flags &RPI_LED_PWR_INV )) + led_cnt++; +else +of_delete_node (l); + } - ret =of_property_write_string (np,"stdout-path" ,"serial1:115200n8" ); -if (ret) -return ret; + l =of_get_child_by_name (leds,"led-act" ); +if (l) { +if (led_act >=0 && !of_rpi_led_set_gpio (l, led_act, + flags &RPI_LED_ACT_EXP , + flags &RPI_LED_ACT_INV )) + led_cnt++; +else +of_delete_node (l); + } -return of_device_disable_by_alias ("serial0" ); +if (led_cnt) +of_device_enable_and_register (leds); }static int rpi_mem_init (void )
@@ -213,6 +199,7 @@ static int rpi_env_init(void)return 0 ; } +late_initcall (rpi_env_init);/* Some string properties in fdt passed to us from vc may be * malformed by not being null terminated, so just create and
@@ -390,15 +377,22 @@ static void rpi_set_kernel_name(void) { } } -static const struct rpi_machine_data *rpi_get_dcfg (struct rpi_priv *priv) +static void rpi_set_hostname (struct device_d *dev) { -const struct rpi_machine_data *dcfg; +const char *name, *ptr; +char *hostname; - dcfg =of_device_get_match_data (priv->dev); -if (!dcfg) { -dev_err (priv->dev,"Unknown board. Not applying fixups\n" ); -return NULL ; - } + name =of_device_get_match_compatible (dev); + ptr =strchr (name,',' ); + hostname =basprintf ("rpi-%s" , ptr ? ptr +1 : name); +barebox_set_hostname (hostname); +free (hostname); +} + +static const struct rpi_machine_data *rpi_get_dcfg (const struct rpi_machine_data *dcfg) +{ +int ret; +u32 board_rev;/* Comments from u-boot: * For details of old-vs-new scheme, see:
@@ -412,22 +406,26 @@ static const struct rpi_machine_data *rpi_get_dcfg(struct rpi_priv *priv)* http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594 */ + ret =rpi_get_board_rev (); +if (ret <0 ) +return ERR_PTR (ret); + board_rev = ret; +for (; dcfg->hw_id !=U8_MAX ; dcfg++) { -if (priv->hw_id &0x800000 ) { -if (dcfg->hw_id != ((priv->hw_id >>4 ) &0xff )) +if (board_rev &BIT (23 )) { +if (dcfg->hw_id != ((board_rev >>4 ) &0xff ))continue ; }else {if (!(dcfg->flags &RPI_OLD_SCHEMA ))continue ; -if (dcfg->hw_id != (priv->hw_id &0xff )) +if (dcfg->hw_id != (board_rev &0xff ))continue ; }return dcfg; } -dev_err (priv->dev,"dcfg 0x%x for board_id doesn't match DT compatible\n" , - priv->hw_id); +pr_err ("dcfg 0x%x for board_id doesn't match DT compatible\n" , board_rev);return ERR_PTR (-ENODEV ); }
@@ -435,42 +433,32 @@ static int rpi_devices_probe(struct device *dev) {const struct rpi_machine_data *dcfg;struct regulator *reg; -struct rpi_priv *priv; -const char *name, *ptr; -char *hostname; -int ret; - priv =xzalloc (sizeof (*priv)); - priv->dev = dev; + dcfg =of_device_get_match_data (dev); +if (!dcfg) +dev_err (dev,"Unknown board, not applying fixups\n" ); +else { + dcfg =rpi_get_dcfg (dcfg); +if (IS_ERR (dcfg)) +return PTR_ERR (dcfg); - ret =rpi_get_board_rev (); -if (ret <0 ) - goto free_priv; +rpi_add_leds (dcfg); - priv->hw_id = ret; +if (dcfg->flags &RPI_SET_ETHADDR ) +rpi_set_ethaddr (); - dcfg =rpi_get_dcfg (priv); -if (IS_ERR (dcfg)) - goto free_priv; +if (dcfg->flags &RPI_SET_USB_OTG ) +rpi_set_usbotg (); + } -rpi_set_serial_number (); -/* construct short recognizable host name */ - name =of_device_get_match_compatible (priv->dev); - ptr =strchr (name,',' ); - hostname =basprintf ("rpi-%s" , ptr ? ptr +1 : name); -barebox_set_hostname (hostname); -free (hostname); +rpi_set_serial_number (); +rpi_set_hostname (dev); +rpi_set_kernel_name (); -rpi_add_led ();bcm2835_register_fb ();armlinux_set_architecture (MACH_TYPE_BCM2708 ); -rpi_env_init ();rpi_vc_fdt (); -rpi_set_kernel_name (); - -if (dcfg && dcfg->init) - dcfg->init (priv); reg =regulator_get_name ("bcm2835_usb" );if (IS_ERR (reg))
@@ -479,134 +467,95 @@ static int rpi_devices_probe(struct device *dev)regulator_enable (reg);return 0 ; - -free_priv: -kfree (priv); -return ret; } +#define RPI_ENTRY (_id, _pwr, _act, _flags) \ + { \ + .hw_id = _id, \ + .pwr_led_gpio = _pwr, \ + .act_led_gpio = _act, \ + .flags = _flags, \ + } + +#define RPI_ENTRY_OLD (_id, _pwr, _act, _flags) \ + RPI_ENTRY(_id, _pwr, _act, (_flags) | RPI_OLD_SCHEMA) + +#if IS_ENABLED (CONFIG_MACH_RPI )static const struct rpi_machine_data rpi_1_ids[] = { - { - .hw_id =BCM2835_BOARD_REV_A_7 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A_8 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A_9 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A , - }, { - .hw_id =BCM2835_BOARD_REV_A_PLUS_12 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A_PLUS_15 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A_PLUS , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C1_4 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C1_5 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C1_6 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_B , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C0_2 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C0_3 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id = BCM2835_BOARD_REV_B_REV2_d, - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_init, - }, { - .hw_id = BCM2835_BOARD_REV_B_REV2_e, - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_init, - }, { - .hw_id = BCM2835_BOARD_REV_B_REV2_f, - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_init, - }, { - .hw_id =BCM2835_BOARD_REV_B_PLUS_10 , - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2835_BOARD_REV_B_PLUS_13 , - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2835_BOARD_REV_B_PLUS , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2835_BOARD_REV_CM_11 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_CM_14 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_CM1 , - }, { - .hw_id =BCM2835_BOARD_REV_ZERO , - .init = rpi_0_init, - }, { - .hw_id =BCM2835_BOARD_REV_ZERO_W , - .init = rpi_0_w_init, - }, { - .hw_id =U8_MAX - }, +/* +* New style of revision codes schemas +* Let's keep those first since they are probably more common +*/ +RPI_ENTRY (BCM2835_BOARD_REV_A ,-1 ,16 ,RPI_LED_ACT_INV ), +RPI_ENTRY (BCM2835_BOARD_REV_A_PLUS ,35 ,47 ,RPI_LED_ACT_INV ), +RPI_ENTRY (BCM2835_BOARD_REV_B ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY (BCM2835_BOARD_REV_B_PLUS ,35 ,47 ,RPI_SET_ETHADDR ), +RPI_ENTRY (BCM2835_BOARD_REV_CM1 ,-1 ,47 ,RPI_LED_ACT_INV ), +RPI_ENTRY (BCM2835_BOARD_REV_ZERO ,-1 ,47 ,RPI_SET_USB_OTG ), +RPI_ENTRY (BCM2835_BOARD_REV_ZERO_W ,-1 ,47 ,RPI_SET_USB_OTG |RPI_LED_ACT_INV ), +/* +* Old style of revision codes +*/ +/* Raspberry Pi A */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_7 ,-1 ,16 ,RPI_LED_ACT_INV ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_8 ,-1 ,16 ,RPI_LED_ACT_INV ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_9 ,-1 ,16 ,RPI_LED_ACT_INV ), +/* Raspberry Pi A+ */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_PLUS_12 ,35 ,47 ,RPI_LED_ACT_INV ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_PLUS_15 ,35 ,47 ,RPI_LED_ACT_INV ), +/* Raspberry Pi B */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C1_4 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C1_5 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C1_6 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C0_2 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C0_3 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_REV2_d,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_REV2_e,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_REV2_f,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +/* Raspberry Pi B+ */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_PLUS_10 ,35 ,47 ,RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_PLUS_13 ,35 ,47 ,RPI_SET_ETHADDR ), +/* Raspberry Pi CM1 */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_CM_11 ,-1 ,47 ,RPI_LED_ACT_INV ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_CM_14 ,-1 ,47 ,RPI_LED_ACT_INV ), +/* sentinel */ + { .hw_id =U8_MAX } }; +#endif +#if IS_ENABLED (CONFIG_MACH_RPI2 )static const struct rpi_machine_data rpi_2_ids[] = { - { - .hw_id =BCM2836_BOARD_REV_2_B , - .init = rpi_b_plus_init, - }, { - .hw_id =U8_MAX - }, +RPI_ENTRY (BCM2836_BOARD_REV_2_B ,35 ,47 ,RPI_SET_ETHADDR ), +/* sentinel */ + { .hw_id =U8_MAX } }; +#endif +#if IS_ENABLED (CONFIG_MACH_RPI3 ) |IS_ENABLED (CONFIG_MACH_RPI_CM3 )static const struct rpi_machine_data rpi_3_ids[] = { - { - .hw_id =BCM2837B0_BOARD_REV_3A_PLUS , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2837_BOARD_REV_3_B , - .init = rpi_b_init, - }, { - .hw_id =BCM2837B0_BOARD_REV_3B_PLUS , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2837_BOARD_REV_CM3 , - }, { - .hw_id =BCM2837B0_BOARD_REV_CM3_PLUS , - }, { - .hw_id =BCM2837B0_BOARD_REV_ZERO_2 , - }, { - .hw_id =U8_MAX - }, +RPI_ENTRY (BCM2837B0_BOARD_REV_3A_PLUS ,2 ,29 ,RPI_LED_PWR_EXP_INV ), +RPI_ENTRY (BCM2837_BOARD_REV_3_B ,-1 ,2 ,RPI_SET_ETHADDR |RPI_LED_ACT_EXP ), +RPI_ENTRY (BCM2837B0_BOARD_REV_3B_PLUS ,2 ,29 ,RPI_SET_ETHADDR |RPI_LED_PWR_EXP_INV ), +RPI_ENTRY (BCM2837_BOARD_REV_CM3 ,-1 ,-1 ,0 ), +RPI_ENTRY (BCM2837B0_BOARD_REV_CM3_PLUS ,-1 ,-1 ,0 ), +RPI_ENTRY (BCM2837B0_BOARD_REV_ZERO_2 ,-1 ,29 ,RPI_LED_ACT_INV |RPI_SET_USB_OTG ), +/* sentinel */ + { .hw_id =U8_MAX } }; +#endif +#if IS_ENABLED (CONFIG_MACH_RPI4 )static const struct rpi_machine_data rpi_4_ids[] = { - { - .hw_id =BCM2711_BOARD_REV_4_B , - }, { - .hw_id =BCM2711_BOARD_REV_400 , - }, { - .hw_id =BCM2711_BOARD_REV_CM4 , - }, { - .hw_id =U8_MAX - }, +RPI_ENTRY (BCM2711_BOARD_REV_4_B ,2 ,42 ,RPI_LED_PWR_EXP_INV |RPI_SET_ETHADDR ), +RPI_ENTRY (BCM2711_BOARD_REV_400 ,42 ,-1 ,RPI_SET_ETHADDR ), +RPI_ENTRY (BCM2711_BOARD_REV_CM4 ,2 ,42 ,RPI_LED_PWR_EXP_INV |RPI_SET_ETHADDR ), +/* sentinel */ + { .hw_id =U8_MAX } }; +#endif static const struct of_device_id rpi_of_match[] = { +#if IS_ENABLED(CONFIG_MACH_RPI)/* BCM2835 based Boards */ { .compatible ="raspberrypi,model-a" , .data = rpi_1_ids }, { .compatible = "raspberrypi,model-a-plus", .data = rpi_1_ids },
@@ -618,23 +567,28 @@ static const struct of_device_id rpi_of_match[] = { { .compatible = "raspberrypi,compute-module", .data = rpi_1_ids }, { .compatible = "raspberrypi,model-zero", .data = rpi_1_ids }, { .compatible = "raspberrypi,model-zero-w", .data = rpi_1_ids }, - +#endif +#if IS_ENABLED(CONFIG_MACH_RPI2) /* BCM2836 based Boards */ { .compatible = "raspberrypi,2-model-b", .data = rpi_2_ids }, - +#endif +#if IS_ENABLED(CONFIG_MACH_RPI3) /* BCM2837 based Boards */ { .compatible = "raspberrypi,3-model-a-plus", .data = rpi_3_ids }, { .compatible = "raspberrypi,3-model-b", .data = rpi_3_ids }, { .compatible = "raspberrypi,3-model-b-plus", .data = rpi_3_ids }, { .compatible = "raspberrypi,model-zero-2-w", .data = rpi_3_ids }, +#endif +#if IS_ENABLED(CONFIG_MACH_RPI_CM3) { .compatible = "raspberrypi,3-compute-module", .data = rpi_3_ids }, { .compatible = "raspberrypi,3-compute-module-lite", .data = rpi_3_ids }, - +#endif +#if IS_ENABLED(CONFIG_MACH_RPI4) /* BCM2711 based Boards */ { .compatible = "raspberrypi,4-model-b", .data = rpi_4_ids }, { .compatible = "raspberrypi,4-compute-module", .data = rpi_4_ids }, { .compatible = "raspberrypi,400", .data = rpi_4_ids }, - +#endif { /* sentinel */ }, }; BAREBOX_DEEP_PROBE_ENABLE(rpi_of_match);
@@ -644,4 +598,4 @@ static struct driver rpi_board_driver = { .probe = rpi_devices_probe, .of_compatible = DRV_OF_COMPAT(rpi_of_match), }; -late_platform_driver (rpi_board_driver); +coredevice_platform_driver (rpi_board_driver);
arch/arm/dts/bcm2711-rpi-4.dts +5 -0
@@ -1,5 +1,10 @@ #include <arm64/broadcom/bcm2711-rpi-4-b.dts> +&{/aliases} { + gpio0 = &gpio; + expgpio0 = &expgpio; +}; + &{/memory@0} { reg = <0x0 0x0 0x0>; };
arch/arm/dts/bcm2835-rpi.dts +1 -0
@@ -2,6 +2,7 @@ &{/aliases} { usb0 = &usb; + gpio0 = &gpio; }; &{/memory@0} {
arch/arm/dts/bcm2836-rpi-2.dts +4 -0
@@ -1,5 +1,9 @@ #include <arm/bcm2836-rpi-2-b.dts> +&{/aliases} { + gpio0 = &gpio; +}; + &{/memory@0} { reg = <0x0 0x0>; };
arch/arm/dts/bcm2837-rpi-3.dts +5 -0
@@ -1,5 +1,10 @@ #include <arm64/broadcom/bcm2837-rpi-3-b.dts> +&{/aliases} { + gpio0 = &gpio; + expgpio0 = &expgpio; +}; + &{/memory@0} { reg = <0x0 0x0>; };
Signature · 1 line
2.34.1
Re: [PATCH 3/5] ARM: rpi: rework rpi board init code
Hi Daniel,
thanks for your patch.
Quoted 7 lines · Daniel Brát
Rework of init for various rpi board variants. Primarily, ethernet and usb init have been generalized to better cover different variations and handling of board leds changed from adding and registering '
gpio_led' structures to fixing them in the device tree. This change also required moving the board init code from 'late_platform_driver' to 'coredevice_platform_driver' which in turn ment calling 'rpi_env_init' from separatelate_initcall.
Is it possible to split that patch into smaller ones?
Regards,
Marco
Quoted 631 lines
Signed-off-by Daniel Brát <[email protected]>--- arch/arm/boards/raspberry-pi/rpi-common.c | 414 ++++++++++------------ arch/arm/dts/bcm2711-rpi-4.dts | 5 + arch/arm/dts/bcm2835-rpi.dts | 1 + arch/arm/dts/bcm2836-rpi-2.dts | 4 + arch/arm/dts/bcm2837-rpi-3.dts | 5 + 5 files changed, 199 insertions(+), 230 deletions(-)arch/arm/boards/raspberry-pi/rpi-common.c +184
-230@@ -24,6 +24,7 @@#include <globalvar.h> #include <asm/system_info.h> #include <reset_source.h> +#include <dt-bindings/gpio/gpio.h> #include <mach/core.h> #include <mach/mbox.h> @@ -45,19 +46,21 @@ static const char * const boot_mode_names[] = { [0x7] = "http", }; -struct rpi_priv ;struct rpi_machine_data { -int (*init)(struct rpi_priv *priv);u8 hw_id;#define RPI_OLD_SCHEMA BIT(0) +#define RPI_SET_ETHADDR BIT(1) +#define RPI_SET_USB_OTG BIT(2) +#define RPI_LED_PWR_INV BIT(3) +#define RPI_LED_PWR_EXP BIT(4) +#define RPI_LED_ACT_INV BIT(5) +#define RPI_LED_ACT_EXP BIT(6) +#define RPI_LED_ANY_EXP (RPI_LED_PWR_EXP | RPI_LED_ACT_EXP) +#define RPI_LED_PWR_EXP_INV (RPI_LED_PWR_EXP | RPI_LED_PWR_INV) +#define RPI_LED_ACT_EXP_INV (RPI_LED_ACT_EXP | RPI_LED_ACT_INV)u8 flags; -}; - -struct rpi_priv { -struct device *dev; -const struct rpi_machine_data *dcfg; -unsigned int hw_id; -const char *name; +int pwr_led_gpio; +int act_led_gpio; };static void rpi_set_serial_number (void )@@ -83,91 +86,74 @@ static void rpi_set_ethaddr(void)eth_register_ethaddr (0 , mac); } -static void rpi_set_usbotg (const char *alias) +static void rpi_set_usbotg (void ) {struct device_node *usb; - usb =of_find_node_by_alias (NULL , alias); + usb =of_find_node_by_alias (NULL ,"usb0" );if (usb)of_property_write_string (usb,"dr_mode" ,"otg" ); } -static struct gpio_led rpi_leds[] = { - { - .gpio = -EINVAL , - .led = { - .name ="ACT" , - }, - }, { - .gpio = -EINVAL , - .led = { - .name ="PWR" , - }, - }, -}; - -static void rpi_add_led (void ) +static int of_rpi_led_set_gpio (struct device_node *led,u32 pin, +bool exp,bool inv) { -int i; -struct gpio_led *l; - -for (i =0 ; i <ARRAY_SIZE (rpi_leds); i++) { - l = &rpi_leds[i]; - -if (gpio_is_valid (l->gpio)) -led_gpio_register (l); - } - - l = &rpi_leds[0 ]; -if (gpio_is_valid (l->gpio)) -led_set_trigger (LED_TRIGGER_HEARTBEAT , &l->led); -} +u32 gpios_prop[3 ]; +struct device_node *gpio; -static int rpi_b_init (struct rpi_priv *priv) -{ - rpi_leds[0 ].gpio =16 ; - rpi_leds[0 ].active_low =1 ; -rpi_set_ethaddr (); - -return 0 ; -} - -static int rpi_b_plus_init (struct rpi_priv *priv) -{ - rpi_leds[0 ].gpio =47 ; - rpi_leds[1 ].gpio =35 ; -rpi_set_ethaddr (); +if (!led) +return -ENODEV ; -return 0 ; -} + gpio =of_find_node_by_alias (NULL , exp ?"expgpio0" :"gpio0" ); +if (!gpio) +return -ENODEV ; -static int rpi_0_init (struct rpi_priv *priv) -{ - rpi_leds[0 ].gpio =47 ; -rpi_set_usbotg ("usb0" ); + gpios_prop[0 ] = gpio->phandle; + gpios_prop[1 ] = pin; + gpios_prop[2 ] = inv ?GPIO_ACTIVE_LOW :GPIO_ACTIVE_HIGH ; -return 0 ; +return of_property_write_u32_array (led,"gpios" , gpios_prop,3 ); } -static int rpi_0_w_init (struct rpi_priv *priv) +static void rpi_add_leds (const struct rpi_machine_data *dcfg) { -struct device_node *np; -int ret; +int flags, led_pwr, led_act, led_cnt; +struct device_node *leds, *l; -rpi_0_init (priv); +if (!IS_ENABLED (CONFIG_OFDEVICE ) || !IS_ENABLED (CONFIG_LED_GPIO_OF )) +return ; - np =of_find_node_by_path ("/chosen" ); -if (!np) -return -ENODEV ; + leds =of_find_node_by_path ("/leds" ); +if (!leds) +return ; -if (!of_device_enable_and_register_by_alias ("serial1" )) -return -ENODEV ; + led_cnt =0 ; + flags = dcfg->flags; + led_pwr = dcfg->pwr_led_gpio; + led_act = dcfg->act_led_gpio; + + l =of_get_child_by_name (leds,"led-pwr" ); +if (l) { +if (led_pwr >=0 && !of_rpi_led_set_gpio (l, led_pwr, + flags &RPI_LED_PWR_EXP , + flags &RPI_LED_PWR_INV )) + led_cnt++; +else +of_delete_node (l); + } - ret =of_property_write_string (np,"stdout-path" ,"serial1:115200n8" ); -if (ret) -return ret; + l =of_get_child_by_name (leds,"led-act" ); +if (l) { +if (led_act >=0 && !of_rpi_led_set_gpio (l, led_act, + flags &RPI_LED_ACT_EXP , + flags &RPI_LED_ACT_INV )) + led_cnt++; +else +of_delete_node (l); + } -return of_device_disable_by_alias ("serial0" ); +if (led_cnt) +of_device_enable_and_register (leds); }static int rpi_mem_init (void )@@ -213,6 +199,7 @@ static int rpi_env_init(void)return 0 ; } +late_initcall (rpi_env_init);/* Some string properties in fdt passed to us from vc may be * malformed by not being null terminated, so just create and @@ -390,15 +377,22 @@ static void rpi_set_kernel_name(void) { } } -static const struct rpi_machine_data *rpi_get_dcfg (struct rpi_priv *priv) +static void rpi_set_hostname (struct device_d *dev) { -const struct rpi_machine_data *dcfg; +const char *name, *ptr; +char *hostname; - dcfg =of_device_get_match_data (priv->dev); -if (!dcfg) { -dev_err (priv->dev,"Unknown board. Not applying fixups\n" ); -return NULL ; - } + name =of_device_get_match_compatible (dev); + ptr =strchr (name,',' ); + hostname =basprintf ("rpi-%s" , ptr ? ptr +1 : name); +barebox_set_hostname (hostname); +free (hostname); +} + +static const struct rpi_machine_data *rpi_get_dcfg (const struct rpi_machine_data *dcfg) +{ +int ret; +u32 board_rev;/* Comments from u-boot: * For details of old-vs-new scheme, see: @@ -412,22 +406,26 @@ static const struct rpi_machine_data *rpi_get_dcfg(struct rpi_priv *priv)* http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594 */ + ret =rpi_get_board_rev (); +if (ret <0 ) +return ERR_PTR (ret); + board_rev = ret; +for (; dcfg->hw_id !=U8_MAX ; dcfg++) { -if (priv->hw_id &0x800000 ) { -if (dcfg->hw_id != ((priv->hw_id >>4 ) &0xff )) +if (board_rev &BIT (23 )) { +if (dcfg->hw_id != ((board_rev >>4 ) &0xff ))continue ; }else {if (!(dcfg->flags &RPI_OLD_SCHEMA ))continue ; -if (dcfg->hw_id != (priv->hw_id &0xff )) +if (dcfg->hw_id != (board_rev &0xff ))continue ; }return dcfg; } -dev_err (priv->dev,"dcfg 0x%x for board_id doesn't match DT compatible\n" , - priv->hw_id); +pr_err ("dcfg 0x%x for board_id doesn't match DT compatible\n" , board_rev);return ERR_PTR (-ENODEV ); }@@ -435,42 +433,32 @@ static int rpi_devices_probe(struct device *dev) {const struct rpi_machine_data *dcfg;struct regulator *reg; -struct rpi_priv *priv; -const char *name, *ptr; -char *hostname; -int ret; - priv =xzalloc (sizeof (*priv)); - priv->dev = dev; + dcfg =of_device_get_match_data (dev); +if (!dcfg) +dev_err (dev,"Unknown board, not applying fixups\n" ); +else { + dcfg =rpi_get_dcfg (dcfg); +if (IS_ERR (dcfg)) +return PTR_ERR (dcfg); - ret =rpi_get_board_rev (); -if (ret <0 ) - goto free_priv; +rpi_add_leds (dcfg); - priv->hw_id = ret; +if (dcfg->flags &RPI_SET_ETHADDR ) +rpi_set_ethaddr (); - dcfg =rpi_get_dcfg (priv); -if (IS_ERR (dcfg)) - goto free_priv; +if (dcfg->flags &RPI_SET_USB_OTG ) +rpi_set_usbotg (); + } -rpi_set_serial_number (); -/* construct short recognizable host name */ - name =of_device_get_match_compatible (priv->dev); - ptr =strchr (name,',' ); - hostname =basprintf ("rpi-%s" , ptr ? ptr +1 : name); -barebox_set_hostname (hostname); -free (hostname); +rpi_set_serial_number (); +rpi_set_hostname (dev); +rpi_set_kernel_name (); -rpi_add_led ();bcm2835_register_fb ();armlinux_set_architecture (MACH_TYPE_BCM2708 ); -rpi_env_init ();rpi_vc_fdt (); -rpi_set_kernel_name (); - -if (dcfg && dcfg->init) - dcfg->init (priv); reg =regulator_get_name ("bcm2835_usb" );if (IS_ERR (reg))@@ -479,134 +467,95 @@ static int rpi_devices_probe(struct device *dev)regulator_enable (reg);return 0 ; - -free_priv: -kfree (priv); -return ret; } +#define RPI_ENTRY (_id, _pwr, _act, _flags) \ + { \ + .hw_id = _id, \ + .pwr_led_gpio = _pwr, \ + .act_led_gpio = _act, \ + .flags = _flags, \ + } + +#define RPI_ENTRY_OLD (_id, _pwr, _act, _flags) \ + RPI_ENTRY(_id, _pwr, _act, (_flags) | RPI_OLD_SCHEMA) + +#if IS_ENABLED (CONFIG_MACH_RPI )static const struct rpi_machine_data rpi_1_ids[] = { - { - .hw_id =BCM2835_BOARD_REV_A_7 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A_8 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A_9 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A , - }, { - .hw_id =BCM2835_BOARD_REV_A_PLUS_12 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A_PLUS_15 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_A_PLUS , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C1_4 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C1_5 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C1_6 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_B , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C0_2 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_B_I2C0_3 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id = BCM2835_BOARD_REV_B_REV2_d, - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_init, - }, { - .hw_id = BCM2835_BOARD_REV_B_REV2_e, - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_init, - }, { - .hw_id = BCM2835_BOARD_REV_B_REV2_f, - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_init, - }, { - .hw_id =BCM2835_BOARD_REV_B_PLUS_10 , - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2835_BOARD_REV_B_PLUS_13 , - .flags =RPI_OLD_SCHEMA , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2835_BOARD_REV_B_PLUS , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2835_BOARD_REV_CM_11 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_CM_14 , - .flags =RPI_OLD_SCHEMA , - }, { - .hw_id =BCM2835_BOARD_REV_CM1 , - }, { - .hw_id =BCM2835_BOARD_REV_ZERO , - .init = rpi_0_init, - }, { - .hw_id =BCM2835_BOARD_REV_ZERO_W , - .init = rpi_0_w_init, - }, { - .hw_id =U8_MAX - }, +/* +* New style of revision codes schemas +* Let's keep those first since they are probably more common +*/ +RPI_ENTRY (BCM2835_BOARD_REV_A ,-1 ,16 ,RPI_LED_ACT_INV ), +RPI_ENTRY (BCM2835_BOARD_REV_A_PLUS ,35 ,47 ,RPI_LED_ACT_INV ), +RPI_ENTRY (BCM2835_BOARD_REV_B ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY (BCM2835_BOARD_REV_B_PLUS ,35 ,47 ,RPI_SET_ETHADDR ), +RPI_ENTRY (BCM2835_BOARD_REV_CM1 ,-1 ,47 ,RPI_LED_ACT_INV ), +RPI_ENTRY (BCM2835_BOARD_REV_ZERO ,-1 ,47 ,RPI_SET_USB_OTG ), +RPI_ENTRY (BCM2835_BOARD_REV_ZERO_W ,-1 ,47 ,RPI_SET_USB_OTG |RPI_LED_ACT_INV ), +/* +* Old style of revision codes +*/ +/* Raspberry Pi A */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_7 ,-1 ,16 ,RPI_LED_ACT_INV ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_8 ,-1 ,16 ,RPI_LED_ACT_INV ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_9 ,-1 ,16 ,RPI_LED_ACT_INV ), +/* Raspberry Pi A+ */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_PLUS_12 ,35 ,47 ,RPI_LED_ACT_INV ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_A_PLUS_15 ,35 ,47 ,RPI_LED_ACT_INV ), +/* Raspberry Pi B */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C1_4 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C1_5 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C1_6 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C0_2 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_I2C0_3 ,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_REV2_d,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_REV2_e,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_REV2_f,-1 ,16 ,RPI_LED_ACT_INV |RPI_SET_ETHADDR ), +/* Raspberry Pi B+ */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_PLUS_10 ,35 ,47 ,RPI_SET_ETHADDR ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_B_PLUS_13 ,35 ,47 ,RPI_SET_ETHADDR ), +/* Raspberry Pi CM1 */ +RPI_ENTRY_OLD (BCM2835_BOARD_REV_CM_11 ,-1 ,47 ,RPI_LED_ACT_INV ), +RPI_ENTRY_OLD (BCM2835_BOARD_REV_CM_14 ,-1 ,47 ,RPI_LED_ACT_INV ), +/* sentinel */ + { .hw_id =U8_MAX } }; +#endif +#if IS_ENABLED (CONFIG_MACH_RPI2 )static const struct rpi_machine_data rpi_2_ids[] = { - { - .hw_id =BCM2836_BOARD_REV_2_B , - .init = rpi_b_plus_init, - }, { - .hw_id =U8_MAX - }, +RPI_ENTRY (BCM2836_BOARD_REV_2_B ,35 ,47 ,RPI_SET_ETHADDR ), +/* sentinel */ + { .hw_id =U8_MAX } }; +#endif +#if IS_ENABLED (CONFIG_MACH_RPI3 ) |IS_ENABLED (CONFIG_MACH_RPI_CM3 )static const struct rpi_machine_data rpi_3_ids[] = { - { - .hw_id =BCM2837B0_BOARD_REV_3A_PLUS , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2837_BOARD_REV_3_B , - .init = rpi_b_init, - }, { - .hw_id =BCM2837B0_BOARD_REV_3B_PLUS , - .init = rpi_b_plus_init, - }, { - .hw_id =BCM2837_BOARD_REV_CM3 , - }, { - .hw_id =BCM2837B0_BOARD_REV_CM3_PLUS , - }, { - .hw_id =BCM2837B0_BOARD_REV_ZERO_2 , - }, { - .hw_id =U8_MAX - }, +RPI_ENTRY (BCM2837B0_BOARD_REV_3A_PLUS ,2 ,29 ,RPI_LED_PWR_EXP_INV ), +RPI_ENTRY (BCM2837_BOARD_REV_3_B ,-1 ,2 ,RPI_SET_ETHADDR |RPI_LED_ACT_EXP ), +RPI_ENTRY (BCM2837B0_BOARD_REV_3B_PLUS ,2 ,29 ,RPI_SET_ETHADDR |RPI_LED_PWR_EXP_INV ), +RPI_ENTRY (BCM2837_BOARD_REV_CM3 ,-1 ,-1 ,0 ), +RPI_ENTRY (BCM2837B0_BOARD_REV_CM3_PLUS ,-1 ,-1 ,0 ), +RPI_ENTRY (BCM2837B0_BOARD_REV_ZERO_2 ,-1 ,29 ,RPI_LED_ACT_INV |RPI_SET_USB_OTG ), +/* sentinel */ + { .hw_id =U8_MAX } }; +#endif +#if IS_ENABLED (CONFIG_MACH_RPI4 )static const struct rpi_machine_data rpi_4_ids[] = { - { - .hw_id =BCM2711_BOARD_REV_4_B , - }, { - .hw_id =BCM2711_BOARD_REV_400 , - }, { - .hw_id =BCM2711_BOARD_REV_CM4 , - }, { - .hw_id =U8_MAX - }, +RPI_ENTRY (BCM2711_BOARD_REV_4_B ,2 ,42 ,RPI_LED_PWR_EXP_INV |RPI_SET_ETHADDR ), +RPI_ENTRY (BCM2711_BOARD_REV_400 ,42 ,-1 ,RPI_SET_ETHADDR ), +RPI_ENTRY (BCM2711_BOARD_REV_CM4 ,2 ,42 ,RPI_LED_PWR_EXP_INV |RPI_SET_ETHADDR ), +/* sentinel */ + { .hw_id =U8_MAX } }; +#endif static const struct of_device_id rpi_of_match[] = { +#if IS_ENABLED(CONFIG_MACH_RPI)/* BCM2835 based Boards */ { .compatible ="raspberrypi,model-a" , .data = rpi_1_ids }, { .compatible = "raspberrypi,model-a-plus", .data = rpi_1_ids },@@ -618,23 +567,28 @@ static const struct of_device_id rpi_of_match[] = { { .compatible = "raspberrypi,compute-module", .data = rpi_1_ids }, { .compatible = "raspberrypi,model-zero", .data = rpi_1_ids }, { .compatible = "raspberrypi,model-zero-w", .data = rpi_1_ids }, - +#endif +#if IS_ENABLED(CONFIG_MACH_RPI2) /* BCM2836 based Boards */ { .compatible = "raspberrypi,2-model-b", .data = rpi_2_ids }, - +#endif +#if IS_ENABLED(CONFIG_MACH_RPI3) /* BCM2837 based Boards */ { .compatible = "raspberrypi,3-model-a-plus", .data = rpi_3_ids }, { .compatible = "raspberrypi,3-model-b", .data = rpi_3_ids }, { .compatible = "raspberrypi,3-model-b-plus", .data = rpi_3_ids }, { .compatible = "raspberrypi,model-zero-2-w", .data = rpi_3_ids }, +#endif +#if IS_ENABLED(CONFIG_MACH_RPI_CM3) { .compatible = "raspberrypi,3-compute-module", .data = rpi_3_ids }, { .compatible = "raspberrypi,3-compute-module-lite", .data = rpi_3_ids }, - +#endif +#if IS_ENABLED(CONFIG_MACH_RPI4) /* BCM2711 based Boards */ { .compatible = "raspberrypi,4-model-b", .data = rpi_4_ids }, { .compatible = "raspberrypi,4-compute-module", .data = rpi_4_ids }, { .compatible = "raspberrypi,400", .data = rpi_4_ids }, - +#endif { /* sentinel */ }, }; BAREBOX_DEEP_PROBE_ENABLE(rpi_of_match);@@ -644,4 +598,4 @@ static struct driver rpi_board_driver = { .probe = rpi_devices_probe, .of_compatible = DRV_OF_COMPAT(rpi_of_match), }; -late_platform_driver (rpi_board_driver); +coredevice_platform_driver (rpi_board_driver);arch/arm/dts/bcm2711-rpi-4.dts +5
-0@@ -1,5 +1,10 @@ #include <arm64/broadcom/bcm2711-rpi-4-b.dts> +&{/aliases} { + gpio0 = &gpio; + expgpio0 = &expgpio; +}; + &{/memory@0} { reg = <0x0 0x0 0x0>; };arch/arm/dts/bcm2835-rpi.dts +1
-0@@ -2,6 +2,7 @@ &{/aliases} { usb0 = &usb; + gpio0 = &gpio; }; &{/memory@0} {arch/arm/dts/bcm2836-rpi-2.dts +4
-0@@ -1,5 +1,9 @@ #include <arm/bcm2836-rpi-2-b.dts> +&{/aliases} { + gpio0 = &gpio; +}; + &{/memory@0} { reg = <0x0 0x0>; };arch/arm/dts/bcm2837-rpi-3.dts +5
-0@@ -1,5 +1,10 @@ #include <arm64/broadcom/bcm2837-rpi-3-b.dts> +&{/aliases} { + gpio0 = &gpio; + expgpio0 = &expgpio; +}; + &{/memory@0} { reg = <0x0 0x0>; };Signature · 1 line
2.34.1
PATCH 4/5 ARM: rpi: add machine-id support
In reply to Daniel BrátPass board's serial number as hashable for machine-id generation and enable machine-id support for rpi platform by default.
--- arch/arm/boards/raspberry-pi/rpi-common.c | 4 ++++ arch/arm/configs/rpi_defconfig | 1 + arch/arm/configs/rpi_v8a_defconfig | 1 + 3 files changed, 6 insertions(+)
arch/arm/boards/raspberry-pi/rpi-common.c +4 -0
@@ -24,6 +24,7 @@#include <globalvar.h> #include <asm/system_info.h> #include <reset_source.h> +#include <machine_id.h> #include <dt-bindings/gpio/gpio.h> #include <mach/core.h>
@@ -74,6 +75,9 @@ static void rpi_set_serial_number(void) serial_str =basprintf ("%016llx" , serial);barebox_set_serial_number (serial_str);free (serial_str); + +if (IS_ENABLED (CONFIG_MACHINE_ID )) +machine_id_set_hashable (&serial,sizeof (serial)); }static void rpi_set_ethaddr (void )
arch/arm/configs/rpi_defconfig +1 -0
@@ -24,6 +24,7 @@ CONFIG_BOOTM_OFTREE=y CONFIG_BLSPEC=y CONFIG_CONSOLE_ALLOW_COLOR=y CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y +CONFIG_MACHINE_ID=y CONFIG_CMD_DMESG=y CONFIG_LONGHELP=y CONFIG_CMD_IOMEM=y
arch/arm/configs/rpi_v8a_defconfig +1 -0
@@ -23,6 +23,7 @@ CONFIG_CONSOLE_ACTIVATE_ALL=y CONFIG_CONSOLE_ALLOW_COLOR=y CONFIG_PBL_CONSOLE=y CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y +CONFIG_MACHINE_ID=y CONFIG_CMD_DMESG=y CONFIG_LONGHELP=y CONFIG_CMD_IOMEM=y
Signature · 1 line
2.34.1
PATCH 5/5 ARM: rpi: enable reset source detection in defconfig
In reply to Daniel BrátRaspberry pi platform code added reset cause readout several patches back, so enable it in the rpi defconfigs.
--- arch/arm/configs/rpi_defconfig | 1 + arch/arm/configs/rpi_v8a_defconfig | 1 + 2 files changed, 2 insertions(+)
arch/arm/configs/rpi_defconfig +1 -0
@@ -24,6 +24,7 @@ CONFIG_BOOTM_OFTREE=y CONFIG_BLSPEC=y CONFIG_CONSOLE_ALLOW_COLOR=y CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y +CONFIG_RESET_SOURCE=y CONFIG_MACHINE_ID=y CONFIG_CMD_DMESG=y CONFIG_LONGHELP=y
arch/arm/configs/rpi_v8a_defconfig +1 -0
@@ -23,6 +23,7 @@ CONFIG_CONSOLE_ACTIVATE_ALL=y CONFIG_CONSOLE_ALLOW_COLOR=y CONFIG_PBL_CONSOLE=y CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y +CONFIG_RESET_SOURCE=y CONFIG_MACHINE_ID=y CONFIG_CMD_DMESG=y CONFIG_LONGHELP=y
Signature · 1 line
2.34.1