Pokouším se vytvořit pokusný ovladač pro zařízení, vycházel jsem z kmod-hwmon-sht21. V build_dir/toolchain-powerpc_8540_gcc-4.8-linaro_uClibc-0.9.33.2/linux-3.18.21/drivers/hwmon/ jsem vytvořil soubor pokus.c s následujícím obsahem. Očekávám, že by měl ovladač vracet dvě čísla, která budou po přečtení inkrementována. Poradíte někdo prosím, kde bych si mohl uvedenou problematiku více nastudovat? Balíček vznikne ale je bohužel prázdný, což se u originálního kmod-hwmon-sht21 nestane (vznikne kmod-hwmon-sht21.ko, který modu zavést na Turris), kde dělám chybu?
Jak vlastně přeložím například jen kmod-hwmon-sht21? (obvyklé make package/<nazev_balicku>/compile logicky nefunguje)
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/device.h>
#include <linux/jiffies.h>
/**
* struct pokus - pokus device specific data
* @hwmon_dev: device registered with hwmon
* @lock: mutex to protect measurement values
* @valid: only 0 before first measurement is taken
* @last_update: time of last update (jiffies)
* @number1:
* @number2:
*/
struct pokus
{
struct i2c_client *client;
struct mutex lock;
char valid;
unsigned long last_update;
int number1;
int number2;
};
/**
* pokus_show_number1() - return value in sysfs
* @dev: device
* @attr: device attribute
* @buf: sysfs buffer (PAGE_SIZE) where measurement values are written to
*
* Will be called on read access to number1 sysfs attribute.
* Returns number of bytes written into buffer, negative errno on error.
*/
static ssize_t pokus_show_number1(struct device *dev, struct device_attribute *attr, char *buf)
{
struct pokus *pokus = dev_get_drvdata(dev);
/*int ret;
ret = pokus_update_measurements(dev);
if (ret < 0) return ret;*/
return sprintf(buf, "%d\n", pokus->number1++);
}
/**
* pokus_show_number2() - return value in sysfs
* @dev: device
* @attr: device attribute
* @buf: sysfs buffer (PAGE_SIZE) where measurement values are written to
*
* Will be called on read access to number1 sysfs attribute.
* Returns number of bytes written into buffer, negative errno on error.
*/
static ssize_t pokus_show_number2(struct device *dev, struct device_attribute *attr, char *buf)
{
struct pokus *pokus = dev_get_drvdata(dev);
/*int ret;
ret = pokus_update_measurements(dev);
if (ret < 0) return ret;*/
return sprintf(buf, "%d\n", pokus->number2++);
}
/* sysfs attributes */
static SENSOR_DEVICE_ATTR(number1, S_IRUGO, pokus_show_number1,
NULL, 0);
static SENSOR_DEVICE_ATTR(number2, S_IRUGO, pokus_show_number2,
NULL, 0);
static struct attribute *pokus_attrs[] =
{
&sensor_dev_attr_number1.dev_attr.attr,
&sensor_dev_attr_number2.dev_attr.attr,
NULL
};
ATTRIBUTE_GROUPS(pokus);
static int pokus_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct device *dev = &client->dev;
struct device *hwmon_dev;
struct pokus *pokus;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
{
dev_err(&client->dev, "adapter does not support SMBus word transactions\n");
return -ENODEV;
}
pokus = devm_kzalloc(dev, sizeof(*pokus), GFP_KERNEL);
if (!pokus) return -ENOMEM;
pokus->client = client;
mutex_init(&pokus->lock);
hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, pokus, pokus_groups);
return PTR_ERR_OR_ZERO(hwmon_dev);
}
/* Device ID table */
static const struct i2c_device_id pokus_id[] =
{
{ "pokus", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, pokus_id);
static struct i2c_driver pokus_driver =
{
.driver.name = "pokus",
.probe = pokus_probe,
.id_table = pokus_id,
};
module_i2c_driver(pokus_driver);
MODULE_AUTHOR("Jenda <mai@nic.com>");
MODULE_DESCRIPTION("Pokus driver");
MODULE_LICENSE("GPL");
A do package/kernel/linux/modules/hwmon.mk jsem doplnil toto (a povolil v menuconfig):
$(eval $(call KernelPackage,hwmon-k10temp))
define KernelPackage/hwmon-pokus
TITLE:=pokus device for test
KCONFIG:=CONFIG_SENSORS_POKUS
FILES:=$(LINUX_DIR)/drivers/hwmon/pokus.ko
AUTOLOAD:=$(call AutoProbe,pokus)
$(call AddDepends/hwmon,+kmod-i2c-core)
endef
define KernelPackage/hwmon-pokus/description
Kernel module for pokus device (for test only)
endef
$(eval $(call KernelPackage,hwmon-pokus))
Edit:
A ještě je třeba definovat CONFIG_SENSORS_POKUS v souboru build_dir/target-powerpc_8540_uClibc-0.9.33.2/linux-mpc85xx_p2020-nand/linux-3.18.21/drivers/hwmon/Kconfig
config SENSORS_POKUS
tristate "JFíla pokus driver."
depends on GPIOLIB
help