Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Reaching DT, from driver attached to i2c/spi.



Hi Artturi --

To read a single cell value, you can use of_getprop_uint32, which takes care of byteswapping as needed. Example:

	if (of_getprop_uint32(sc->sc_node, "netbsd,bmx-period", &period) != 0)
		period = BMX_DEFAULT_PERIOD;

For boolean properties, you don't need to provide a value, so in the DT:

	netbsd,bmx-forced;

Means "forced = true", which you can set in code like this:

	forced = of_hasprop(sc->sc_node, "netbsd,bmx-forced");

As far as using non-standard bindings, it is generally discouraged but it is understood that exceptions sometimes need to be made. Can you describe what these properties are for and why the standard bindings aren't sufficient?

Cheers,
Jared


On Thu, 24 Jan 2019, Artturi Alm wrote:

Hi,

how should/could this be done?
if bindings like "netbsd,..." are unwanted, i'll just hardcode and be
done with this, np. :]

use-case example called from _attach() below, see /* XXX .. */.
-Artturi


/*
* node examples for i2c controllers in DT:
* 			pressure@76 {
*				compatible = "bosch,bme280";
*				reg = <0x76>;
*				netbsd,bmx-forced = < 0x01 >;
*				netbsd,bmx-period = < 0x08 >;
*				netbsd,bmx-standby = < 0x3d090 >;
*				netbsd,bmx-oversample-temp = < 0x01 >;
*				netbsd,bmx-oversample-pres = < 0x00 >;
*				netbsd,bmx-oversample-humi = < 0x01 >;
*			};
*			pressure@77 {
*				compatible = "bosch,bmp280";
*				reg = <0x77>;
*				netbsd,bmx-period = < 0x04 >;
*				netbsd,bmx-standby = < 0x3d0900 >;
*				netbsd,bmx-oversample-temp = < 0x01 >;
*				netbsd,bmx-oversample-pres = < 0x01 >;
*			};
*/
void
bmx_getconfig(struct bmx_softc *sc)
{
	int ph = sc->sc_node;
	/* XXX OF_getpropint ... */
#define	OF_getpropint(x,y,z)	((z))	/* XXX replace with ? z == default */
	int forced = OF_getpropint(ph, "netbsd,bmx-forced", 0);
	int period = OF_getpropint(ph, "netbsd,bmx-period", 1);
	uint32_t iirfilt = OF_getpropint(ph, "netbsd,bmx-filter", 0);
	uint32_t standby = OF_getpropint(ph, "netbsd,bmx-standby", 1000000);
	uint32_t os_temp = OF_getpropint(ph, "netbsd,bmx-oversample-temp", 1);
	uint32_t os_pres = OF_getpropint(ph, "netbsd,bmx-oversample-pres", 1);
	uint32_t os_humi = OF_getpropint(ph, "netbsd,bmx-oversample-humi", 1);

	sc->sc_node = ph; /* because __unused for now.. */

	if (sc->sc_state & BMX_S_GOTPARAMS)
		return;
	sc->sc_state |= BMX_S_GOTPARAMS;

	sc->sc_mode =
	    forced ? BMX280_CTRL_MEAS_FORCED : BMX280_CTRL_MEAS_NORMAL;

	iirfilt = bmx_config_filter(iirfilt);
	standby = bmx_config_standby(standby, BMX_W_HUMI(sc));
	sc->sc_config[0] = iirfilt | standby;

	os_humi = bmx_oversample(os_humi, BMX_HUMI);
	sc->sc_config[1] = os_humi;

	os_temp = bmx_oversample(os_temp, BMX_TEMP);
	os_pres = bmx_oversample(os_pres, BMX_PRES);
	sc->sc_config[2] = os_temp | os_pres;
}





Home | Main Index | Thread Index | Old Index