Skip to content

Commit

Permalink
bsp/beagle: Ported Beagle Clock driver
Browse files Browse the repository at this point in the history
The following files have been ported:
1) ti_hwmods.h
2) ti_hwmods.c
3) ti_prcm.h
4) ti_prcm.c
5) ti_scm.h
6) ti_scm.c
7) am335x_prcm.c

Update #3784
  • Loading branch information
gs-niteesh committed Aug 23, 2020
1 parent 915ad17 commit 0ace491
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 5 deletions.
4 changes: 4 additions & 0 deletions bsps/arm/beagle/start/bspstart.c
Expand Up @@ -22,6 +22,8 @@
#include "bsp-soc-detect.h"
#include <arm/ti/ti_cpuid.h>
#include <arm/ti/ti_pinmux.h>
#include <arm/ti/ti_prcm.h>
#include <arm/ti/ti_scm.h>
#include <ofw/ofw.h>

#include "bspdebug.h"
Expand Down Expand Up @@ -71,6 +73,8 @@ static void traverse_fdt_nodes( phandle_t node )
* Put all driver initialization functions here
*/
beagle_pinmux_init(node);
am335x_prcm_init(node);
beagle_scm_init(node);
}
}

Expand Down
10 changes: 9 additions & 1 deletion bsps/include/arm/ti/ti_hwmods.h
Expand Up @@ -27,11 +27,19 @@
*/
#ifndef _TI_HWMODS_H_
#define _TI_HWMODS_H_
#ifdef __rtems__
#include <ofw/ofw_compat.h>
#include <arm/ti/ti_prcm.h>
#endif /* __rtems__ */

#ifndef __rtems__
clk_ident_t ti_hwmods_get_clock(device_t dev);
int ti_hwmods_contains(device_t dev, const char *hwmod);

/* Returns the N from "hwmodN" in the ti,hwmods property; 0 on failure. */
int ti_hwmods_get_unit(device_t dev, const char *hwmod);
#else /* __rtems__ */
clk_ident_t ti_hwmods_get_clock(phandle_t dev);
#endif /* __rtems__ */

#endif /* _TI_HWMODS_H_ */
#endif /* _TI_HWMODS_H_ */
7 changes: 7 additions & 0 deletions bsps/include/arm/ti/ti_prcm.h
Expand Up @@ -45,6 +45,9 @@
*/
#ifndef _TI_PRCM_H_
#define _TI_PRCM_H_
#ifdef __rtems__
#include <ofw/ofw.h>
#endif /* __rtems__ */

typedef enum {

Expand Down Expand Up @@ -196,6 +199,10 @@ struct ti_clock_dev {
unsigned int *freq);
};

#ifdef __rtems__
void am335x_prcm_init(phandle_t node);
#endif /* __rtems__ */

int ti_prcm_clk_valid(clk_ident_t clk);
int ti_prcm_clk_enable(clk_ident_t clk);
int ti_prcm_clk_disable(clk_ident_t clk);
Expand Down
10 changes: 9 additions & 1 deletion bsps/include/arm/ti/ti_scm.h
Expand Up @@ -44,15 +44,23 @@
*/
#ifndef _TI_SCM_H_
#define _TI_SCM_H_
#ifdef __rtems__
#include <ofw/ofw.h>
#include <stdint.h>
#endif /* __rtems__ */

#ifndef __rtems__
struct ti_scm_softc {
device_t sc_dev;
struct resource * sc_res[4];
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
};
#else /* __rtems__ */
void beagle_scm_init(phandle_t node);
#endif /* __rtems__ */

int ti_scm_reg_read_4(uint32_t reg, uint32_t *val);
int ti_scm_reg_write_4(uint32_t reg, uint32_t val);

#endif /* _TI_SCM_H_ */
#endif /* _TI_SCM_H_ */
51 changes: 50 additions & 1 deletion bsps/shared/freebsd/sys/arm/ti/am335x/am335x_prcm.c
Expand Up @@ -27,9 +27,12 @@
*/

#include <sys/cdefs.h>
#ifndef __rtems__
__FBSDID("$FreeBSD$");
#endif /* __rtems__ */

#include <sys/param.h>
#ifndef __rtems__
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
Expand All @@ -44,16 +47,31 @@ __FBSDID("$FreeBSD$");
#include <machine/intr.h>

#include <arm/ti/tivar.h>
#endif /* __rtems__ */
#include <arm/ti/ti_scm.h>
#include <arm/ti/ti_prcm.h>

#ifndef __rtems__
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>

#include <machine/bus.h>

#include "am335x_scm.h"
#else /* __rtems__ */
#include <ofw/ofw_compat.h>
#include <arm/ti/am335x/am335x_scm.h>
#include <rtems/sysinit.h>
#include <rtems/counter.h>
#include <rtems/bspIo.h>
#include <rtems/freebsd-compat/bus.h>
#include <rtems/freebsd-compat/resource.h>
#include <rtems/freebsd-compat/rman.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#endif /* __rtems__ */

#define CM_PER 0
#define CM_PER_L4LS_CLKSTCTRL (CM_PER + 0x000)
Expand Down Expand Up @@ -132,6 +150,10 @@ __FBSDID("$FreeBSD$");
#define PRM_DEVICE_OFFSET 0xF00
#define PRM_RSTCTRL (PRM_DEVICE_OFFSET + 0x00)

#ifdef __rtems__
#define DELAY(x) rtems_counter_delay_nanoseconds(((x) * 1000))
#endif /* __rtems__ */

struct am335x_prcm_softc {
struct resource * res[2];
bus_space_tag_t bst;
Expand All @@ -158,7 +180,9 @@ static int am335x_clk_get_sysclk_freq(struct ti_clock_dev *clkdev, unsigned int
static int am335x_clk_get_arm_fclk_freq(struct ti_clock_dev *clkdev, unsigned int *freq);
static int am335x_clk_get_arm_disp_freq(struct ti_clock_dev *clkdev, unsigned int *freq);
static int am335x_clk_set_arm_disp_freq(struct ti_clock_dev *clkdev, unsigned int freq);
#ifndef __rtems__
static void am335x_prcm_reset(void);
#endif /* __rtems__ */
static int am335x_clk_cpsw_activate(struct ti_clock_dev *clkdev);
static int am335x_clk_musb0_activate(struct ti_clock_dev *clkdev);
static int am335x_clk_lcdc_activate(struct ti_clock_dev *clkdev);
Expand Down Expand Up @@ -406,6 +430,7 @@ static struct am335x_clk_details g_am335x_clk_details[] = {

void am335x_prcm_setup_dmtimer(int);

#ifndef __rtems__
static int
am335x_prcm_probe(device_t dev)
{
Expand All @@ -420,6 +445,7 @@ am335x_prcm_probe(device_t dev)

return (ENXIO);
}
#endif /* __rtems__ */

static int
am335x_prcm_attach(device_t dev)
Expand All @@ -430,19 +456,39 @@ am335x_prcm_attach(device_t dev)
return (ENXIO);

if (bus_alloc_resources(dev, am335x_prcm_spec, sc->res)) {
#ifndef __rtems__
device_printf(dev, "could not allocate resources\n");
#else /* __rtems__ */
printk("am335x_prcm: could not allocated resources\n");
#endif /* __rtems__ */
return (ENXIO);
}

sc->bst = rman_get_bustag(sc->res[0]);
sc->bsh = rman_get_bushandle(sc->res[0]);

am335x_prcm_sc = sc;
#ifndef __rtems__
ti_cpu_reset = am335x_prcm_reset;
#endif /* __rtems__ */

return (0);
}

void am335x_prcm_init(phandle_t node)
{
static struct device am335x_prcm_dev;
static struct am335x_prcm_softc am335x_prcm_sc;

if (!rtems_ofw_is_node_compatible(node, "ti,am3-prcm"))
return ;

am335x_prcm_dev.softc = &am335x_prcm_sc;
am335x_prcm_dev.node = node;
am335x_prcm_attach(&am335x_prcm_dev);
}

#ifndef __rtems__
static void
am335x_prcm_new_pass(device_t dev)
{
Expand Down Expand Up @@ -498,6 +544,7 @@ EARLY_DRIVER_MODULE(am335x_prcm, simplebus, am335x_prcm_driver,
am335x_prcm_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
MODULE_VERSION(am335x_prcm, 1);
MODULE_DEPEND(am335x_prcm, ti_scm, 1, 1, 1);
#endif /* __rtems__ */

static struct am335x_clk_details*
am335x_clk_details(clk_ident_t id)
Expand Down Expand Up @@ -761,11 +808,13 @@ am335x_clk_set_arm_disp_freq(struct ti_clock_dev *clkdev, unsigned int freq)
return(0);
}

#ifndef __rtems__
static void
am335x_prcm_reset(void)
{
prcm_write_4(PRM_RSTCTRL, (1<<1));
}
#endif /* __rtems__ */

static int
am335x_clk_cpsw_activate(struct ti_clock_dev *clkdev)
Expand Down Expand Up @@ -881,4 +930,4 @@ am335x_clk_pruss_activate(struct ti_clock_dev *clkdev)
prcm_write_4(PRM_PER_RSTCTRL, prcm_read_4(PRM_PER_RSTCTRL) & ~2);

return (0);
}
}
25 changes: 24 additions & 1 deletion bsps/shared/freebsd/sys/arm/ti/ti_hwmods.c
Expand Up @@ -27,9 +27,12 @@
*/

#include <sys/cdefs.h>
#ifndef __rtems__
__FBSDID("$FreeBSD$");
#endif /* __rtems__ */

#include <sys/param.h>
#ifndef __rtems__
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/kernel.h>
Expand All @@ -40,6 +43,11 @@ __FBSDID("$FreeBSD$");

#include <machine/bus.h>
#include <machine/fdt.h>
#else /* __rtems__ */
#include <ofw/ofw_compat.h>
#include <rtems/bspIo.h>
#include <string.h>
#endif /* __rtems__ */

#include <arm/ti/ti_prcm.h>
#include <arm/ti/ti_hwmods.h>
Expand Down Expand Up @@ -108,7 +116,11 @@ ti_get_hwmods_prop(phandle_t node, void **name)
}

clk_ident_t
#ifndef __rtems__
ti_hwmods_get_clock(device_t dev)
#else /* __rtems__ */
ti_hwmods_get_clock(phandle_t dev)
#endif /* __rtems__ */
{
phandle_t node;
int len, l;
Expand All @@ -117,8 +129,13 @@ ti_hwmods_get_clock(device_t dev)
int clk;
struct hwmod *hw;

#ifndef __rtems__
if ((node = ofw_bus_get_node(dev)) == 0)
return (INVALID_CLK_IDENT);
#else /* __rtems__ */
if ((node = dev) == 0)
return (INVALID_CLK_IDENT);
#endif /* __rtems__ */

if ((len = ti_get_hwmods_prop(node, (void **)&name)) <= 0)
return (INVALID_CLK_IDENT);
Expand All @@ -141,12 +158,17 @@ ti_hwmods_get_clock(device_t dev)
}

if (len > 0)
#ifndef __rtems__
device_printf(dev, "WARNING: more than one ti,hwmod \n");
#else /* __rtems__ */
printk("ti_hwmods: WARNING more than one ti,hwmods\n");
#endif /* __rtems__ */

OF_prop_free(buf);
return (clk);
}

#ifndef __rtems__
int ti_hwmods_contains(device_t dev, const char *hwmod)
{
phandle_t node;
Expand Down Expand Up @@ -211,4 +233,5 @@ ti_hwmods_get_unit(device_t dev, const char *hwmod)

OF_prop_free(buf);
return (result);
}
}
#endif /* __rtems__ */
17 changes: 17 additions & 0 deletions bsps/shared/freebsd/sys/arm/ti/ti_prcm.c
Expand Up @@ -41,9 +41,12 @@
*
*/
#include <sys/cdefs.h>
#ifndef __rtems__
__FBSDID("$FreeBSD$");
#endif /* __rtems__ */

#include <sys/param.h>
#ifndef __rtems__
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
Expand All @@ -56,6 +59,12 @@ __FBSDID("$FreeBSD$");
#include <machine/bus.h>
#include <machine/resource.h>
#include <machine/intr.h>
#else /* __rtems__ */
#include <rtems/bspIo.h>
#include <rtems/freebsd-compat/bus.h>
#include <assert.h>
#include <errno.h>
#endif /* __rtems__ */

#include <arm/ti/ti_cpuid.h>
#include <arm/ti/ti_prcm.h>
Expand Down Expand Up @@ -105,8 +114,12 @@ ti_prcm_clk_dev(clk_ident_t clk)
break;
#endif
}
#ifndef __rtems__
if (clk_dev == NULL)
panic("No clock devmap found");
#else /* __rtems__ */
assert(clk_dev != NULL);
#endif /* __rtems__ */
while (clk_dev->id != INVALID_CLK_IDENT) {
if (clk_dev->id == clk) {
return (clk_dev);
Expand All @@ -115,7 +128,11 @@ ti_prcm_clk_dev(clk_ident_t clk)
}

/* Sanity check we managed to find the clock */
#ifndef __rtems__
printf("ti_prcm: Failed to find clock device (%d)\n", clk);
#else /* __rtems__ */
printk("ti_prcm: Failed to find clock device (%d)\n", clk);
#endif /* __rtems__ */
return (NULL);
}

Expand Down

0 comments on commit 0ace491

Please sign in to comment.