aboutsummaryrefslogtreecommitdiff
path: root/driver/platform.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-20 15:41:29 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-20 15:41:29 +0200
commit8de1733ca506dc7b7d4b66dca1b33c22e76dc855 (patch)
tree8a4eb4529f580adc2e62b5182ecc7df40b35aff3 /driver/platform.c
parentf8d802918da5f898f6466bd59bc15f6a4157d514 (diff)
add device class attributes (9.6)week-4
Diffstat (limited to 'driver/platform.c')
-rw-r--r--driver/platform.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/driver/platform.c b/driver/platform.c
index 73d691f..b177474 100644
--- a/driver/platform.c
+++ b/driver/platform.c
@@ -42,27 +42,6 @@ int lork_probe(struct platform_device* dev) {
}
if (am33xx_pinmux == NULL) return EINVAL;
- // TODO: ???
-
- // // configure gpio mux
- // uint32_t* conf_gpmc_a3 = ioremap(TI_AM335X_CM_GPMC_A3_ADDR, sizeof(ti_am335x_word_t));
- // if (conf_gpmc_a3 == NULL)
- // return -EINVAL;
- // barrier();
- // uint32_t val = ioread32(conf_gpmc_a3); rmb();
- // val &= ~0x7;
- // val |= 0x7;
- // iowrite32(val, conf_gpmc_a3); wmb();
- // iounmap(conf_gpmc_a3);
-
- // // configure output pin
- // ti_am335x_word_t* gpio1 = ioremap(TI_AM335X_GPIO1_ADDR, GPIO_REG_SIZE);
- // barrier();
- // ti_am335x_word_t oe_reg = ioread32(gpio1 + GPIO_OE); rmb();
- // oe_reg &= ~(1<<PIN); // 0=output
- // iowrite32(oe_reg, gpio1 + GPIO_OE); wmb();
- // iounmap(gpio1);
-
printk("%s(%s)\n", __PRETTY_FUNCTION__, dev->name);
return 0;
}
@@ -73,11 +52,34 @@ int lork_remove(struct platform_device* dev) {
}
unsigned int val = 0;
-ssize_t attr_show(struct device_driver* drv, char* buf) {
+ssize_t drv_attr_int_show(struct device_driver* drv, char* buf) {
return sprintf(buf, "%u\n", val);
}
-ssize_t attr_store(struct device_driver* drv, const char* buf, size_t count) {
+ssize_t drv_attr_int_store(struct device_driver* drv, const char* buf, size_t count) {
sscanf(buf, "%u", &val);
return count;
}
+ssize_t dev_attr_int_show(struct device* dev, struct device_attribute* _attr, char* buf) {
+ return sprintf(buf, "%u\n", val);
+}
+ssize_t dev_attr_int_store(struct device* dev, struct device_attribute* _attr, const char* buf, size_t count) {
+ sscanf(buf, "%u", &val);
+ return count;
+}
+
+char* str = NULL;
+size_t str_len = 0;
+ssize_t dev_attr_str_show(struct device* dev, struct device_attribute* _attr, char* buf) {
+ if (str == NULL) return 0;
+ strncpy(buf, str, str_len);
+ return str_len;
+}
+ssize_t dev_attr_str_store(struct device* dev, struct device_attribute* _attr, const char* buf, size_t count) {
+ if (str != NULL) kfree(str);
+ str = kmalloc(count, 0);
+ str_len = count;
+ strncpy(str, buf, str_len);
+ return count;
+}
+