1 /* $OpenBSD: simplepanel.c,v 1.1 2020/01/26 06:20:30 patrick Exp $ */ 2 /* 3 * Copyright (c) 2020 Patrick Wildt <patrick@blueri.se> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/param.h> 19 #include <sys/systm.h> 20 #include <sys/device.h> 21 #include <sys/malloc.h> 22 23 #include <machine/fdt.h> 24 25 #include <dev/ofw/openfirm.h> 26 #include <dev/ofw/ofw_gpio.h> 27 #include <dev/ofw/ofw_misc.h> 28 #include <dev/ofw/ofw_pinctrl.h> 29 #include <dev/ofw/ofw_regulator.h> 30 31 int simplepanel_match(struct device *, void *, void *); 32 void simplepanel_attach(struct device *, struct device *, void *); 33 34 struct cfattach simplepanel_ca = { 35 sizeof (struct device), simplepanel_match, simplepanel_attach 36 }; 37 38 struct cfdriver simplepanel_cd = { 39 NULL, "simplepanel", DV_DULL 40 }; 41 42 int 43 simplepanel_match(struct device *parent, void *match, void *aux) 44 { 45 struct fdt_attach_args *faa = aux; 46 47 return OF_is_compatible(faa->fa_node, "simple-panel"); 48 } 49 50 void 51 simplepanel_attach(struct device *parent, struct device *self, void *aux) 52 { 53 struct fdt_attach_args *faa = aux; 54 uint32_t power_supply; 55 uint32_t *gpios; 56 int len; 57 58 printf("\n"); 59 60 pinctrl_byname(faa->fa_node, "default"); 61 62 power_supply = OF_getpropint(faa->fa_node, "power-supply", 0); 63 if (power_supply) 64 regulator_enable(power_supply); 65 66 len = OF_getproplen(faa->fa_node, "enable-gpios"); 67 if (len > 0) { 68 gpios = malloc(len, M_TEMP, M_WAITOK); 69 OF_getpropintarray(faa->fa_node, "enable-gpios", gpios, len); 70 gpio_controller_config_pin(&gpios[0], GPIO_CONFIG_OUTPUT); 71 gpio_controller_set_pin(&gpios[0], 1); 72 free(gpios, M_TEMP, len); 73 } 74 } 75