1*e6fd0181SMario Six // SPDX-License-Identifier: GPL-2.0+ 2*e6fd0181SMario Six /* 3*e6fd0181SMario Six * (C) Copyright 2018 4*e6fd0181SMario Six * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc 5*e6fd0181SMario Six */ 6*e6fd0181SMario Six 7*e6fd0181SMario Six #include <common.h> 8*e6fd0181SMario Six #include <dm.h> 9*e6fd0181SMario Six #include <board.h> 10*e6fd0181SMario Six 11*e6fd0181SMario Six #include "sandbox.h" 12*e6fd0181SMario Six 13*e6fd0181SMario Six struct board_sandbox_priv { 14*e6fd0181SMario Six bool called_detect; 15*e6fd0181SMario Six int test_i1; 16*e6fd0181SMario Six int test_i2; 17*e6fd0181SMario Six }; 18*e6fd0181SMario Six 19*e6fd0181SMario Six char vacation_spots[][64] = {"R'lyeh", "Dreamlands", "Plateau of Leng", 20*e6fd0181SMario Six "Carcosa", "Yuggoth", "The Nameless City"}; 21*e6fd0181SMario Six 22*e6fd0181SMario Six int board_sandbox_detect(struct udevice *dev) 23*e6fd0181SMario Six { 24*e6fd0181SMario Six struct board_sandbox_priv *priv = dev_get_priv(dev); 25*e6fd0181SMario Six 26*e6fd0181SMario Six priv->called_detect = true; 27*e6fd0181SMario Six priv->test_i2 = 100; 28*e6fd0181SMario Six 29*e6fd0181SMario Six return 0; 30*e6fd0181SMario Six } 31*e6fd0181SMario Six 32*e6fd0181SMario Six int board_sandbox_get_bool(struct udevice *dev, int id, bool *val) 33*e6fd0181SMario Six { 34*e6fd0181SMario Six struct board_sandbox_priv *priv = dev_get_priv(dev); 35*e6fd0181SMario Six 36*e6fd0181SMario Six switch (id) { 37*e6fd0181SMario Six case BOOL_CALLED_DETECT: 38*e6fd0181SMario Six /* Checks if the dectect method has been called */ 39*e6fd0181SMario Six *val = priv->called_detect; 40*e6fd0181SMario Six return 0; 41*e6fd0181SMario Six } 42*e6fd0181SMario Six 43*e6fd0181SMario Six return -ENOENT; 44*e6fd0181SMario Six } 45*e6fd0181SMario Six 46*e6fd0181SMario Six int board_sandbox_get_int(struct udevice *dev, int id, int *val) 47*e6fd0181SMario Six { 48*e6fd0181SMario Six struct board_sandbox_priv *priv = dev_get_priv(dev); 49*e6fd0181SMario Six 50*e6fd0181SMario Six switch (id) { 51*e6fd0181SMario Six case INT_TEST1: 52*e6fd0181SMario Six *val = priv->test_i1; 53*e6fd0181SMario Six /* Increments with every call */ 54*e6fd0181SMario Six priv->test_i1++; 55*e6fd0181SMario Six return 0; 56*e6fd0181SMario Six case INT_TEST2: 57*e6fd0181SMario Six *val = priv->test_i2; 58*e6fd0181SMario Six /* Decrements with every call */ 59*e6fd0181SMario Six priv->test_i2--; 60*e6fd0181SMario Six return 0; 61*e6fd0181SMario Six } 62*e6fd0181SMario Six 63*e6fd0181SMario Six return -ENOENT; 64*e6fd0181SMario Six } 65*e6fd0181SMario Six 66*e6fd0181SMario Six int board_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val) 67*e6fd0181SMario Six { 68*e6fd0181SMario Six struct board_sandbox_priv *priv = dev_get_priv(dev); 69*e6fd0181SMario Six int i1 = priv->test_i1; 70*e6fd0181SMario Six int i2 = priv->test_i2; 71*e6fd0181SMario Six int index = (i1 * i2) % ARRAY_SIZE(vacation_spots); 72*e6fd0181SMario Six 73*e6fd0181SMario Six switch (id) { 74*e6fd0181SMario Six case STR_VACATIONSPOT: 75*e6fd0181SMario Six /* Picks a vacation spot depending on i1 and i2 */ 76*e6fd0181SMario Six snprintf(val, size, vacation_spots[index]); 77*e6fd0181SMario Six return 0; 78*e6fd0181SMario Six } 79*e6fd0181SMario Six 80*e6fd0181SMario Six return -ENOENT; 81*e6fd0181SMario Six } 82*e6fd0181SMario Six 83*e6fd0181SMario Six static const struct udevice_id board_sandbox_ids[] = { 84*e6fd0181SMario Six { .compatible = "sandbox,board_sandbox" }, 85*e6fd0181SMario Six { /* sentinel */ } 86*e6fd0181SMario Six }; 87*e6fd0181SMario Six 88*e6fd0181SMario Six static const struct board_ops board_sandbox_ops = { 89*e6fd0181SMario Six .detect = board_sandbox_detect, 90*e6fd0181SMario Six .get_bool = board_sandbox_get_bool, 91*e6fd0181SMario Six .get_int = board_sandbox_get_int, 92*e6fd0181SMario Six .get_str = board_sandbox_get_str, 93*e6fd0181SMario Six }; 94*e6fd0181SMario Six 95*e6fd0181SMario Six int board_sandbox_probe(struct udevice *dev) 96*e6fd0181SMario Six { 97*e6fd0181SMario Six return 0; 98*e6fd0181SMario Six } 99*e6fd0181SMario Six 100*e6fd0181SMario Six U_BOOT_DRIVER(board_sandbox) = { 101*e6fd0181SMario Six .name = "board_sandbox", 102*e6fd0181SMario Six .id = UCLASS_BOARD, 103*e6fd0181SMario Six .of_match = board_sandbox_ids, 104*e6fd0181SMario Six .ops = &board_sandbox_ops, 105*e6fd0181SMario Six .priv_auto_alloc_size = sizeof(struct board_sandbox_priv), 106*e6fd0181SMario Six .probe = board_sandbox_probe, 107*e6fd0181SMario Six }; 108